@onflow/fcl
Advanced tools
Comparing version 0.0.28 to 0.0.29
@@ -5,2 +5,15 @@ ### Unreleased | ||
### 0.0.29 -- 2020-04-20 | ||
- 2020-05-06 -- Fixed an issue with custom decoders | ||
- 2020-05-06 -- Leverage named imports to enable better tree shaking | ||
- 2020-05-06 -- Proxy `@onflow/sdk` through fcl to enable single import | ||
- 2020-05-06 -- VSN `@onflow/sdk` 0.0.16 -> 0.0.17 | ||
- 2020-05-05 -- VSN `@onflow/sdk` 0.0.15 -> 0.0.16 | ||
- 2020-05-05 -- Update resolvers based on sdk update | ||
- 2020-05-05 -- VSN `@onflow/sdk` 0.0.14 -> 0.0.15 Breaking Change | ||
- 2020-04-29 -- authn challenge response no longer locks to handshake origin | ||
- 2020-04-28 -- `fcl.user(addr).info()` does a `send([getAccount(addr)])` returning the `account` | ||
- 2020-04-23 -- `fcl.authenticate()` renders iframe for config: `challenge.handshake` | ||
### 0.0.28 -- 2020-04-20 | ||
@@ -7,0 +20,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e,r=(e=require("queue-microtask"))&&"object"==typeof e&&"default"in e?e.default:e,t=require("@onflow/sdk");function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}const i=function(){function e(){}return e.prototype.then=function(r,t){const n=new e,o=this.s;if(o){const e=1&o?r:t;if(e){try{u(n,1,e(this.v))}catch(e){u(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?u(n,1,r?r(o):o):t?u(n,1,t(o)):u(n,2,o)}catch(e){u(n,2,e)}},n},e}();function u(e,r,t){if(!e.s){if(t instanceof i){if(!t.s)return void(t.o=u.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(u.bind(null,e,r),u.bind(null,e,2));e.s=r,e.v=t;const n=e.o;n&&n(e)}}function c(e){return e instanceof i&&1&e.s}function s(e,r,t){for(var n;;){var o=e();if(c(o)&&(o=o.v),!o)return s;if(o.then){n=0;break}var s=t();if(s&&s.then){if(!c(s)){n=1;break}s=s.s}if(r){var a=r();if(a&&a.then&&!c(a)){n=2;break}}}var f=new i,l=u.bind(null,f,2);return(0===n?o.then(d):1===n?s.then(v):a.then(h)).then(void 0,l),f;function v(n){s=n;do{if(r&&(a=r())&&a.then&&!c(a))return void a.then(h).then(void 0,l);if(!(o=e())||c(o)&&!o.v)return void u(f,1,s);if(o.then)return void o.then(d).then(void 0,l);c(s=t())&&(s=s.v)}while(!s||!s.then);s.then(v).then(void 0,l)}function d(e){e?(s=t())&&s.then?s.then(v).then(void 0,l):v(s):u(f,1,s)}function h(){(o=e())?o.then?o.then(d).then(void 0,l):d(o):u(f,1,s)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a={},f=0,l=function(e,r,t,n){return void 0===n&&(n={}),new Promise(function(o,i){var u=n.expectReply||!1,c=null!=n.timeout?n.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:n.from,tag:r,data:t,timeout:c,reply:o,reject:i};try{a[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},v=function(e,t){if(void 0===t&&(t=null),null==t&&(t=++f),null!=a[t])return t;var n,i;a[t]={addr:t,mailbox:(i=[],{deliver:function(e){try{return i.push(e),n&&(n(i.shift()),n=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var r=i.shift();if(r)return e(r);n=e})}}),subs:new Set,kvs:{}};var u={self:function(){return t},receive:function(){return a[t].mailbox.receive()},send:function(e,r,n,o){return void 0===o&&(o={}),o.from=t,l(e,r,n,o)},broadcast:function(e,r,n){void 0===n&&(n={}),n.from=t;for(var i,u=function(e){var r=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,r){if(e){if("string"==typeof e)return o(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,void 0):void 0}}(e)))return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(a[t].subs);!(i=u()).done;)l(i.value,e,r,n)},subscribe:function(e){return null!=e&&a[t].subs.add(e)},unsubscribe:function(e){return null!=e&&a[t].subs.delete(e)},put:function(e,r){null!=e&&(a[t].kvs[e]=r)},get:function(e,r){var n=a[t].kvs[e];return null==n?r:n},delete:function(e){delete a[t].kvs[e]},update:function(e,r){null!=e&&(a[t].kvs[e]=r(a[t].kvs[e]))},keys:function(){return Object.keys(a[t].kvs)}};return r(function(){try{return Promise.resolve(e(u)).then(function(){!function(e){delete a[e]}(t)})}catch(e){return Promise.reject(e)}}),t},d="config",h="PUT_CONFIG",m="GET_CONFIG",y="CONFIG/UPDATED";v(function(e){try{var r=function(r){return r.reduce(function(r,t){var o;return n({},r,((o={})[t]=e.get(t),o))},{})},t=s(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(t){var n=t.data;try{switch(t.tag){case h:return void(null!=n.key&&(e.put(n.key,n.value),e.broadcast(y,r(e.keys()))));case m:return void(null!=n.key&&t.reply(e.get(n.key,n.fallback)));case"UPDATE_CONFIG":return void(null!=n.key&&(e.update(n.key,n.fn),e.broadcast(y,r(e.keys()))));case"DELETE_CONFIG":return void(null!=n.key&&(e.delete(n.key),e.broadcast(y,r(e.keys()))));case"WHERE_CONFIG":return void(null!=n.pattern&&t.reply(r(e.keys().filter(function(e){return n.pattern.test(e)}))));case"SUBSCRIBE":return e.subscribe(t.from),void e.send(t.from,y,r(e.keys()));case"UNSUBSCRIBE":return void e.unsubscribe(t.from);default:return}}catch(e){return void console.error("Config Error",t,e)}})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},d);var b=function(e){return e},p=function(){return{put:function(e,r){l(d,h,{key:e,value:r})},get:function(e,r){return l(d,m,{key:e,fallback:r},{expectReply:!0,timeout:10})},update:function(e,r){void 0===r&&(r=b),l(d,"UPDATE_CONFIG",{key:e,fn:r})},delete:function(e){l(d,"DELETE_CONFIG",{key:e})},where:function(e){return l(d,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})},subscribe:function(e){var r=v(function(r){try{var t=!1;return r.send(d,"SUBSCRIBE"),Promise.resolve(s(function(){return!t&&1},void 0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(d,"UNSUBSCRIBE"),void(t=!0);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l(r,"@EXIT")}}}};p().put("accessNode.api","http://localhost:8080");var P,k=function(e){return"https://avatars.onflow.org/avatar/"+e+".svg"},S=function(e,r){return r.reduce(function(r,t){var o;return n({},r,((o={})[t]=e.get(t),o))},{})},E=((P={}).SUBSCRIBE=function(e,r){e.subscribe(r.from),e.send(r.from,"USER/UPDATED",S(e,e.keys()))},P.UNSUBSCRIBE=function(e,r){e.unsubscribe(r.from)},P.SNAPSHOT=function(e,r){try{return r.reply(S(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},P),g=function(e){try{return Promise.resolve(function(e){try{return Promise.resolve((void 0===r&&(r=10),new Promise(function(e){return setTimeout(e,r)}))).then(function(){return{acct:e,name:"bob the builder",avatar:k(),bio:"Can he fix it, yes he can.",hooks:{}}})}catch(e){return Promise.reject(e)}var r}(e.self())).then(function(r){!function(e,r){for(var t=0,n=Object.keys(r);t<n.length;t++){var o=n[t];e.put(o,r[o])}}(e,r);var t=s(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(r){var t=function(t,n){try{var o=function(t,n){try{var o=Promise.resolve(E[r.tag](e,r)).then(function(){})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){console.error("User Error",r,e)})}catch(e){return}return o&&o.then?o.then(n.bind(null,!1),n.bind(null,!0)):void 0}(0,function(e,r){});if(t&&t.then)return t.then(function(){})})});return t&&t.then?t.then(function(){}):void 0})}catch(e){return Promise.reject(e)}},I=function(e){return v(g,e)};exports.authenticate=function(){return Promise.resolve()},exports.config=p,exports.currentUser=function(){return{subscribe:function(e){return function(){}},authorization:function(){return Promise.resolve()},payerAuthorization:function(){return Promise.resolve()},param:function(){return Promise.resolve()}}},exports.decode=function(e){return Promise.resolve()},exports.event=function(e,r){return{subscribe:function(e){return function(){}}}},exports.send=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var n=function(n){return r.node=n,Array.isArray(e)&&(e=t.build(e)),Promise.resolve(t.pipe(e,[t.resolve([t.resolveParams,t.resolveAuthorizations])])).then(function(e){return t.send(e,r)})},o=r.node;return Promise.resolve(o?n(o):Promise.resolve(p().get("accessNode.api")).then(n))}catch(e){return Promise.reject(e)}},exports.transaction=function(e){return{subscribe:function(e){return function(){}}}},exports.unauthenticate=function(){return Promise.resolve()},exports.user=function(e){return{authorization:function(){try{return I(e),Promise.resolve({acct:e,signFn:function(){try{throw new Error("fcl.user("+e+").payerAuthorization WIP error -- known missing functionality")}catch(e){return Promise.reject(e)}}})}catch(e){return Promise.reject(e)}},payerAuthorization:function(){try{return I(e),Promise.resolve({acct:e,signFn:function(){try{throw new Error("fcl.user("+e+").payerAuthorization WIP error -- known missing functionality")}catch(e){return Promise.reject(e)}}})}catch(e){return Promise.reject(e)}},snapshot:function(){try{return I(e),Promise.resolve(l(e,"SNAPSHOT",null,{expectReply:!0,timeout:0}))}catch(e){return Promise.reject(e)}},param:function(r){return{value:e,xform:{asParam:function(e){return e},asInjection:function(e){return e}}}},subscribe:function(r){I(e);var t=v(function(t){try{var n=!1;return t.send(e,"SUBSCRIBE"),Promise.resolve(s(function(){return!n&&1},void 0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(e,"UNSUBSCRIBE"),void(n=!0);r(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l(t,"@EXIT")}}}}; | ||
var e,t=(e=require("queue-microtask"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@onflow/sdk"),r=require("@onflow/types");function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}const u=function(){function e(){}return e.prototype.then=function(t,n){const r=new e,o=this.s;if(o){const e=1&o?t:n;if(e){try{c(r,1,e(this.v))}catch(e){c(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?c(r,1,t?t(o):o):n?c(r,1,n(o)):c(r,2,o)}catch(e){c(r,2,e)}},r},e}();function c(e,t,n){if(!e.s){if(n instanceof u){if(!n.s)return void(n.o=c.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(c.bind(null,e,t),c.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}function s(e){return e instanceof u&&1&e.s}function a(e,t,n){for(var r;;){var o=e();if(s(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!s(i)){r=1;break}i=i.s}if(t){var a=t();if(a&&a.then&&!s(a)){r=2;break}}}var f=new u,l=c.bind(null,f,2);return(0===r?o.then(h):1===r?i.then(d):a.then(m)).then(void 0,l),f;function d(r){i=r;do{if(t&&(a=t())&&a.then&&!s(a))return void a.then(m).then(void 0,l);if(!(o=e())||s(o)&&!o.v)return void c(f,1,i);if(o.then)return void o.then(h).then(void 0,l);s(i=n())&&(i=i.v)}while(!i||!i.then);i.then(d).then(void 0,l)}function h(e){e?(i=n())&&i.then?i.then(d).then(void 0,l):d(i):c(f,1,i)}function m(){(o=e())?o.then?o.then(h).then(void 0,l):h(o):c(f,1,i)}}function f(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function l(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var d,h={},m=0,v=function(e,t,n,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:r.from,tag:t,data:n,timeout:c,reply:o,reject:i};try{h[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},p=function(e,n){if(void 0===n&&(n=null),null==n&&(n=++m),null!=h[n])return n;var r,o;h[n]={addr:n,mailbox:(o=[],{deliver:function(e){try{return o.push(e),r&&(r(o.shift()),r=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var t=o.shift();if(t)return e(t);r=e})}}),subs:new Set,kvs:{}};var u={self:function(){return n},receive:function(){return h[n].mailbox.receive()},send:function(e,t,r,o){return void 0===o&&(o={}),o.from=n,v(e,t,r,o)},broadcast:function(e,t,r){void 0===r&&(r={}),r.from=n;for(var o,u=function(e){var t=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,t){if(e){if("string"==typeof e)return i(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,void 0):void 0}}(e)))return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}(h[n].subs);!(o=u()).done;)v(o.value,e,t,r)},subscribe:function(e){return null!=e&&h[n].subs.add(e)},unsubscribe:function(e){return null!=e&&h[n].subs.delete(e)},put:function(e,t){null!=e&&(h[n].kvs[e]=t)},get:function(e,t){var r=h[n].kvs[e];return null==r?t:r},delete:function(e){delete h[n].kvs[e]},update:function(e,t){null!=e&&(h[n].kvs[e]=t(h[n].kvs[e]))},keys:function(){return Object.keys(h[n].kvs)}};return t(function(){try{return Promise.resolve(e(u)).then(function(){!function(e){delete h[e]}(n)})}catch(e){return Promise.reject(e)}}),n},y="config",b="PUT_CONFIG",P="GET_CONFIG",g="CONFIG/UPDATED",E=function(e,t){return void 0===t&&(t=[]),t.reduce(function(t,n){var r;return o({},t,((r={})[n]=e.get(n),r))},{})},k=function(e){return e},j=((d={})[b]=function(e,t,n){var r=n.key,o=n.value;if(null==r)throw new Error("Missing 'key' for config/put.");e.put(r,o),e.broadcast(g,E(e,e.keys()))},d[P]=function(e,t,n){var r=n.key,o=n.fallback;if(null==r)throw new Error("Missing 'key' for config/get");t.reply(e.get(r,o))},d.UPDATE_CONFIG=function(e,t,n){var r=n.key,o=n.fn;if(null==r)throw new Error("Missing 'key' for config/update");e.update(r,o||k),e.broadcast(g,E(e,e.keys()))},d.DELETE_CONFIG=function(e,t,n){var r=n.key;if(null==r)throw new Error("Missing 'key' for config/delete");e.delete(r),e.broadcast(g,E(e,e.keys()))},d.WHERE_CONFIG=function(e,t,n){var r=n.pattern;if(null==r)throw new Error("Missing 'pattern' for config/where");t.reply(E(e,e.keys().filter(function(e){return r.test(e)})))},d.SUBSCRIBE=function(e,t){e.subscribe(t.from),e.send(t.from,g,E(e.keys()))},d.UNSUBSCRIBE=function(e,t){e.unsubscribe(t.from)},d);function S(e,t){return v(y,b,{key:e,value:t}),T()}function x(e,t){return v(y,P,{key:e,fallback:t},{expectReply:!0,timeout:10})}function w(e,t){return void 0===t&&(t=k),v(y,"UPDATE_CONFIG",{key:e,fn:t}),T()}function O(e){return v(y,"DELETE_CONFIG",{key:e}),T()}function I(e){return v(y,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})}function R(e){var t=p(function(t){try{var n=!1;return t.send(y,"SUBSCRIBE"),Promise.resolve(a(function(){return!n&&1},void 0,function(){return Promise.resolve(t.receive()).then(function(r){if("@EXIT"===r.tag)return t.send(y,"UNSUBSCRIBE"),void(n=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,"@EXIT")}}function T(){return{put:S,get:x,update:w,delete:O,where:I,subscribe:R}}p(function(e){try{var t=a(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(t){var n=l(function(){return f(function(){return Promise.resolve(j[t.tag](e,t,t.data||{})).then(function(){})},function(e){console.error("User Error",t,e)})},function(e,t){});if(n&&n.then)return n.then(function(){})})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},y),T().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var U,C=function(e,t){void 0===e&&(e=[]),void 0===t&&(t={});try{var r=function(r){return t.node=r,Array.isArray(e)&&(e=n.build(e)),Promise.resolve(n.resolve(e,[n.resolveParams,n.resolveAccounts,n.resolveSignatures])).then(function(e){return n.send(e,t)})},o=t.node;return Promise.resolve(o?r(o):Promise.resolve(T().get("accessNode.api")).then(r))}catch(e){return Promise.reject(e)}},N="FCL_IFRAME_CHALLENGE",A="FCL_IFRAME_AUTHZ",B=function(e){void 0===e&&(e={});var t=e.addr,n=e.pid;return null==t||null==n?null:t+"/"+n},_={"HTTP/POST":"POST","HTTP/GET":"GET"},L=function(e,t){try{for(var n=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];n.searchParams.append(i[0],i[1])}return t=t?JSON.stringify(t):void 0,Promise.resolve(fetch(n,{method:_[e.method],headers:{"Content-Type":"application/json"},body:t}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}},F=function(){try{return Z(),Promise.resolve(ee()).then(function(e){var t=e.addr;if(null==t)throw new Error("No Flow Address for Current User");return Promise.resolve(C([n.getAccount(t)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},G=function(e){try{return Z(),Promise.resolve(D()).then(function(){return Promise.resolve(ee()).then(function(t){function n(){return o({},e,{addr:t.addr,keyId:t.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ee()).then(function(t){return Promise.resolve(F()).then(function(n){return Promise.resolve(L(t.authorizations[0],e)).then(function(e){var t=function(){};return e.local&&e.local.length>0&&(console.log("RENDER LOCAL"),t=function(e){if(!document.getElementById(A)){for(var t=new URL(e.endpoint),n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=t.href,i.id=A,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(A)&&document.getElementById(A).remove()}}}(e.local[0])),Promise.resolve(function e(t){return new Promise(function(n,r){try{return Promise.resolve(L(t)).then(function(t){"APPROVED"===t.status?n(t.compositeSignature):"DECLINED"===t.status?r({status:t.status,reason:t.reason}):setTimeout(function(){n(e(t.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){return t(),e})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,i=function(){if(e.role.proposer)return Promise.resolve(F()).then(function(e){var n=e.keys.find(function(e){return e.index===t.keyId});r=n.sequenceNumber})}();return i&&i.then?i.then(n):n()})})}catch(e){return Promise.reject(e)}},D=function(){try{return Promise.resolve(new Promise(function(e){try{return Z(),Promise.resolve(ee()).then(function(t){return t.loggedIn?e(t):Promise.resolve(T().get("challenge.handshake")).then(function(t){return Promise.resolve(T().get("challenge.scope")).then(function(n){var r=function(e){var t=e.handshake,n=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(N)){var i=new URL(t);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),n&&i.searchParams.append("scope",n.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=N,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(N)&&document.getElementById(N).remove()}}}({handshake:t,scope:n,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(t){var n=t.data;try{if(n.type!==q)return Promise.resolve();r();var i=new URL(n.hks);return i.searchParams.append("code",n.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(t){return v(H,z,o({},t,{cid:B(t.provider),loggedIn:!0,verified:!0})),Promise.resolve(ee()).then(function(t){e(t)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},H="CURRENT_USER",M="CURRENT_USER/UPDATED",z="SET_CURRENT_USER",q="FCL::CHALLENGE::RESPONSE",X='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',W=function(e,t){return Object.fromEntries(t.map(function(t){return[t,e.get(t)]}))},J=function(e,t){Object.entries(t).forEach(function(t){return e.put(t[0],t[1])})},$=((U={}).SUBSCRIBE=function(e,t){e.subscribe(t.from),e.send(t.from,M,W(e,e.keys()))},U.UNSUBSCRIBE=function(e,t){e.unsubscribe(t.from)},U.SNAPSHOT=function(e,t){try{return t.reply(W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},U[z]=function(e,t,n){try{return J(e,n),e.broadcast(M,W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},U.DEL_CURRENT_USER=function(e,t){try{return J(e,JSON.parse(X)),e.broadcast(M,W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},U.GET_AS_PARAM=function(e,t,n){var o=n.key;try{return t.reply({key:o,value:e.get("addr",null),xform:r.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},U),V=function(e){try{J(e,JSON.parse(X));var t=a(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(t){var n=l(function(){return f(function(){return Promise.resolve($[t.tag](e,t,t.data||{})).then(function(){})},function(e){console.error("Current User Error",t,e)})},function(e,t){});if(n&&n.then)return n.then(function(){})})});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Z=function(){return p(V,H)};function K(){Z(),v(H,"DEL_CURRENT_USER")}function Q(e){return function(){try{return Z(),Promise.resolve(D()).then(function(){return v(H,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Y(e){Z();var t=p(function(t){try{var n=!1;return t.send(H,"SUBSCRIBE"),Promise.resolve(a(function(){return!n&&1},void 0,function(){return Promise.resolve(t.receive()).then(function(r){if("@EXIT"===r.tag)return t.send(H,"UNSUBSCRIBE"),void(n=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,"@EXIT")}}function ee(){return Z(),v(H,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var te=function(){return{authenticate:D,unauthenticate:K,authorization:G,param:Q,subscribe:Y,snapshot:ee}};Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),exports.authenticate=function(){return te().authenticate()},exports.config=T,exports.currentUser=te,exports.decode=function(e){try{return Promise.resolve(T().where(/^decoder\./)).then(function(t){var r=Object.fromEntries(Object.entries(t).map(function(e){var t=e[0],n=e[1];return[t="/"+t.replace(/^decoder\./,"")+"$/",n]}));return n.decodeResponse(e,r)})}catch(e){return Promise.reject(e)}},exports.send=C,exports.unauthenticate=function(){return te().unauthenticate()}; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import r from"queue-microtask";import{build as e,pipe as n,resolve as t,resolveParams as o,resolveAuthorizations as i,send as u}from"@onflow/sdk";function c(){return(c=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r}).apply(this,arguments)}function s(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}const a=function(){function r(){}return r.prototype.then=function(e,n){const t=new r,o=this.s;if(o){const r=1&o?e:n;if(r){try{f(t,1,r(this.v))}catch(r){f(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?f(t,1,e?e(o):o):n?f(t,1,n(o)):f(t,2,o)}catch(r){f(t,2,r)}},t},r}();function f(r,e,n){if(!r.s){if(n instanceof a){if(!n.s)return void(n.o=f.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(f.bind(null,r,e),f.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function l(r){return r instanceof a&&1&r.s}function v(r,e,n){for(var t;;){var o=r();if(l(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!l(i)){t=1;break}i=i.s}if(e){var u=e();if(u&&u.then&&!l(u)){t=2;break}}}var c=new a,s=f.bind(null,c,2);return(0===t?o.then(d):1===t?i.then(v):u.then(h)).then(void 0,s),c;function v(t){i=t;do{if(e&&(u=e())&&u.then&&!l(u))return void u.then(h).then(void 0,s);if(!(o=r())||l(o)&&!o.v)return void f(c,1,i);if(o.then)return void o.then(d).then(void 0,s);l(i=n())&&(i=i.v)}while(!i||!i.then);i.then(v).then(void 0,s)}function d(r){r?(i=n())&&i.then?i.then(v).then(void 0,s):v(i):f(c,1,i)}function h(){(o=r())?o.then?o.then(d).then(void 0,s):d(o):f(c,1,i)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var d={},h=0,m=function(r,e,n,t){return void 0===t&&(t={}),new Promise(function(o,i){var u=t.expectReply||!1,c=null!=t.timeout?t.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:r,from:t.from,tag:e,data:n,timeout:c,reply:o,reject:i};try{d[r].mailbox.deliver(s),u||o(!0)}catch(r){console.error("FCL.Actor -- Could Not Deliver Message",s,r)}})},y=function(e,n){if(void 0===n&&(n=null),null==n&&(n=++h),null!=d[n])return n;var t,o;d[n]={addr:n,mailbox:(o=[],{deliver:function(r){try{return o.push(r),t&&(t(o.shift()),t=void 0),Promise.resolve()}catch(r){return Promise.reject(r)}},receive:function(){return new Promise(function(r){var e=o.shift();if(e)return r(e);t=r})}}),subs:new Set,kvs:{}};var i={self:function(){return n},receive:function(){return d[n].mailbox.receive()},send:function(r,e,t,o){return void 0===o&&(o={}),o.from=n,m(r,e,t,o)},broadcast:function(r,e,t){void 0===t&&(t={}),t.from=n;for(var o,i=function(r){var e=0;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(r=function(r,e){if(r){if("string"==typeof r)return s(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(r,void 0):void 0}}(r)))return function(){return e>=r.length?{done:!0}:{done:!1,value:r[e++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(e=r[Symbol.iterator]()).next.bind(e)}(d[n].subs);!(o=i()).done;)m(o.value,r,e,t)},subscribe:function(r){return null!=r&&d[n].subs.add(r)},unsubscribe:function(r){return null!=r&&d[n].subs.delete(r)},put:function(r,e){null!=r&&(d[n].kvs[r]=e)},get:function(r,e){var t=d[n].kvs[r];return null==t?e:t},delete:function(r){delete d[n].kvs[r]},update:function(r,e){null!=r&&(d[n].kvs[r]=e(d[n].kvs[r]))},keys:function(){return Object.keys(d[n].kvs)}};return r(function(){try{return Promise.resolve(e(i)).then(function(){!function(r){delete d[r]}(n)})}catch(r){return Promise.reject(r)}}),n},b="config",p="PUT_CONFIG",P="GET_CONFIG",k="CONFIG/UPDATED";y(function(r){try{var e=function(e){return e.reduce(function(e,n){var t;return c({},e,((t={})[n]=r.get(n),t))},{})},n=v(function(){return 1},void 0,function(){return Promise.resolve(r.receive()).then(function(n){var t=n.data;try{switch(n.tag){case p:return void(null!=t.key&&(r.put(t.key,t.value),r.broadcast(k,e(r.keys()))));case P:return void(null!=t.key&&n.reply(r.get(t.key,t.fallback)));case"UPDATE_CONFIG":return void(null!=t.key&&(r.update(t.key,t.fn),r.broadcast(k,e(r.keys()))));case"DELETE_CONFIG":return void(null!=t.key&&(r.delete(t.key),r.broadcast(k,e(r.keys()))));case"WHERE_CONFIG":return void(null!=t.pattern&&n.reply(e(r.keys().filter(function(r){return t.pattern.test(r)}))));case"SUBSCRIBE":return r.subscribe(n.from),void r.send(n.from,k,e(r.keys()));case"UNSUBSCRIBE":return void r.unsubscribe(n.from);default:return}}catch(r){return void console.error("Config Error",n,r)}})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(r){return Promise.reject(r)}},b);var S=function(r){return r},E=function(){return{put:function(r,e){m(b,p,{key:r,value:e})},get:function(r,e){return m(b,P,{key:r,fallback:e},{expectReply:!0,timeout:10})},update:function(r,e){void 0===e&&(e=S),m(b,"UPDATE_CONFIG",{key:r,fn:e})},delete:function(r){m(b,"DELETE_CONFIG",{key:r})},where:function(r){return m(b,"WHERE_CONFIG",{pattern:r},{expectReply:!0,timeout:10})},subscribe:function(r){var e=y(function(e){try{var n=!1;return e.send(b,"SUBSCRIBE"),Promise.resolve(v(function(){return!n&&1},void 0,function(){return Promise.resolve(e.receive()).then(function(t){if("@EXIT"===t.tag)return e.send(b,"UNSUBSCRIBE"),void(n=!0);r(t.data)})}))}catch(r){return Promise.reject(r)}});return function(){return m(e,"@EXIT")}}}};E().put("accessNode.api","http://localhost:8080");var I,g=function(r,c){void 0===r&&(r=[]),void 0===c&&(c={});try{var s=function(s){return c.node=s,Array.isArray(r)&&(r=e(r)),Promise.resolve(n(r,[t([o,i])])).then(function(r){return u(r,c)})},a=c.node;return Promise.resolve(a?s(a):Promise.resolve(E().get("accessNode.api")).then(s))}catch(r){return Promise.reject(r)}},j=function(r){return"https://avatars.onflow.org/avatar/"+r+".svg"},w=function(r,e){return e.reduce(function(e,n){var t;return c({},e,((t={})[n]=r.get(n),t))},{})},C=((I={}).SUBSCRIBE=function(r,e){r.subscribe(e.from),r.send(e.from,"USER/UPDATED",w(r,r.keys()))},I.UNSUBSCRIBE=function(r,e){r.unsubscribe(e.from)},I.SNAPSHOT=function(r,e){try{return e.reply(w(r,r.keys())),Promise.resolve()}catch(r){return Promise.reject(r)}},I),U=function(r){try{return Promise.resolve(function(r){try{return Promise.resolve((void 0===e&&(e=10),new Promise(function(r){return setTimeout(r,e)}))).then(function(){return{acct:r,name:"bob the builder",avatar:j(),bio:"Can he fix it, yes he can.",hooks:{}}})}catch(r){return Promise.reject(r)}var e}(r.self())).then(function(e){!function(r,e){for(var n=0,t=Object.keys(e);n<t.length;n++){var o=t[n];r.put(o,e[o])}}(r,e);var n=v(function(){return 1},void 0,function(){return Promise.resolve(r.receive()).then(function(e){var n=function(n,t){try{var o=function(n,t){try{var o=Promise.resolve(C[e.tag](r,e)).then(function(){})}catch(r){return t(r)}return o&&o.then?o.then(void 0,t):o}(0,function(r){console.error("User Error",e,r)})}catch(r){return}return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):void 0}(0,function(r,e){});if(n&&n.then)return n.then(function(){})})});return n&&n.then?n.then(function(){}):void 0})}catch(r){return Promise.reject(r)}},A=function(r){return y(U,r)},N=function(r){return{authorization:function(){try{return A(r),Promise.resolve({acct:r,signFn:function(){try{throw new Error("fcl.user("+r+").payerAuthorization WIP error -- known missing functionality")}catch(r){return Promise.reject(r)}}})}catch(r){return Promise.reject(r)}},payerAuthorization:function(){try{return A(r),Promise.resolve({acct:r,signFn:function(){try{throw new Error("fcl.user("+r+").payerAuthorization WIP error -- known missing functionality")}catch(r){return Promise.reject(r)}}})}catch(r){return Promise.reject(r)}},snapshot:function(){try{return A(r),Promise.resolve(m(r,"SNAPSHOT",null,{expectReply:!0,timeout:0}))}catch(r){return Promise.reject(r)}},param:function(e){return{value:r,xform:{asParam:function(r){return r},asInjection:function(r){return r}}}},subscribe:function(e){A(r);var n=y(function(n){try{var t=!1;return n.send(r,"SUBSCRIBE"),Promise.resolve(v(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(r,"UNSUBSCRIBE"),void(t=!0);e(o.data)})}))}catch(r){return Promise.reject(r)}});return function(){return m(n,"@EXIT")}}}},O=function(){return Promise.resolve()},T=function(){return Promise.resolve()},B=function(){return{subscribe:function(r){return function(){}},authorization:function(){return Promise.resolve()},payerAuthorization:function(){return Promise.resolve()},param:function(){return Promise.resolve()}}},R=function(r){return{subscribe:function(r){return function(){}}}},F=function(r,e){return{subscribe:function(r){return function(){}}}},x=function(r){return Promise.resolve()};export{O as authenticate,E as config,B as currentUser,x as decode,F as event,g as send,R as transaction,T as unauthenticate,N as user}; | ||
import e from"queue-microtask";import{build as n,resolve as t,resolveParams as r,resolveAccounts as o,resolveSignatures as i,send as u,decodeResponse as c,getAccount as s}from"@onflow/sdk";export{authorization,authorizations,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,proposer,ref,script,transaction,why}from"@onflow/sdk";import{Identity as a}from"@onflow/types";function l(){return(l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function f(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}const d=function(){function e(){}return e.prototype.then=function(n,t){const r=new e,o=this.s;if(o){const e=1&o?n:t;if(e){try{h(r,1,e(this.v))}catch(e){h(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?h(r,1,n?n(o):o):t?h(r,1,t(o)):h(r,2,o)}catch(e){h(r,2,e)}},r},e}();function h(e,n,t){if(!e.s){if(t instanceof d){if(!t.s)return void(t.o=h.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(h.bind(null,e,n),h.bind(null,e,2));e.s=n,e.v=t;const r=e.o;r&&r(e)}}function v(e){return e instanceof d&&1&e.s}function m(e,n,t){for(var r;;){var o=e();if(v(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!v(i)){r=1;break}i=i.s}if(n){var u=n();if(u&&u.then&&!v(u)){r=2;break}}}var c=new d,s=h.bind(null,c,2);return(0===r?o.then(l):1===r?i.then(a):u.then(f)).then(void 0,s),c;function a(r){i=r;do{if(n&&(u=n())&&u.then&&!v(u))return void u.then(f).then(void 0,s);if(!(o=e())||v(o)&&!o.v)return void h(c,1,i);if(o.then)return void o.then(l).then(void 0,s);v(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function l(e){e?(i=t())&&i.then?i.then(a).then(void 0,s):a(i):h(c,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,s):l(o):h(c,1,i)}}function y(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}function p(e,n){try{var t=e()}catch(e){return n(!0,e)}return t&&t.then?t.then(n.bind(null,!1),n.bind(null,!0)):n(!1,t)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var P,b={},E=0,g=function(e,n,t,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:r.from,tag:n,data:t,timeout:c,reply:o,reject:i};try{b[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},k=function(n,t){if(void 0===t&&(t=null),null==t&&(t=++E),null!=b[t])return t;var r,o;b[t]={addr:t,mailbox:(o=[],{deliver:function(e){try{return o.push(e),r&&(r(o.shift()),r=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var n=o.shift();if(n)return e(n);r=e})}}),subs:new Set,kvs:{}};var i={self:function(){return t},receive:function(){return b[t].mailbox.receive()},send:function(e,n,r,o){return void 0===o&&(o={}),o.from=t,g(e,n,r,o)},broadcast:function(e,n,r){void 0===r&&(r={}),r.from=t;for(var o,i=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return f(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?f(e,void 0):void 0}}(e)))return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(b[t].subs);!(o=i()).done;)g(o.value,e,n,r)},subscribe:function(e){return null!=e&&b[t].subs.add(e)},unsubscribe:function(e){return null!=e&&b[t].subs.delete(e)},put:function(e,n){null!=e&&(b[t].kvs[e]=n)},get:function(e,n){var r=b[t].kvs[e];return null==r?n:r},delete:function(e){delete b[t].kvs[e]},update:function(e,n){null!=e&&(b[t].kvs[e]=n(b[t].kvs[e]))},keys:function(){return Object.keys(b[t].kvs)}};return e(function(){try{return Promise.resolve(n(i)).then(function(){!function(e){delete b[e]}(t)})}catch(e){return Promise.reject(e)}}),t},S="config",w="PUT_CONFIG",I="GET_CONFIG",R="CONFIG/UPDATED",j=function(e,n){return void 0===n&&(n=[]),n.reduce(function(n,t){var r;return l({},n,((r={})[t]=e.get(t),r))},{})},T=function(e){return e},U=((P={})[w]=function(e,n,t){var r=t.key,o=t.value;if(null==r)throw new Error("Missing 'key' for config/put.");e.put(r,o),e.broadcast(R,j(e,e.keys()))},P[I]=function(e,n,t){var r=t.key,o=t.fallback;if(null==r)throw new Error("Missing 'key' for config/get");n.reply(e.get(r,o))},P.UPDATE_CONFIG=function(e,n,t){var r=t.key,o=t.fn;if(null==r)throw new Error("Missing 'key' for config/update");e.update(r,o||T),e.broadcast(R,j(e,e.keys()))},P.DELETE_CONFIG=function(e,n,t){var r=t.key;if(null==r)throw new Error("Missing 'key' for config/delete");e.delete(r),e.broadcast(R,j(e,e.keys()))},P.WHERE_CONFIG=function(e,n,t){var r=t.pattern;if(null==r)throw new Error("Missing 'pattern' for config/where");n.reply(j(e,e.keys().filter(function(e){return r.test(e)})))},P.SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,R,j(e.keys()))},P.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},P);function C(e,n){return g(S,w,{key:e,value:n}),_()}function N(e,n){return g(S,I,{key:e,fallback:n},{expectReply:!0,timeout:10})}function O(e,n){return void 0===n&&(n=T),g(S,"UPDATE_CONFIG",{key:e,fn:n}),_()}function x(e){return g(S,"DELETE_CONFIG",{key:e}),_()}function A(e){return g(S,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})}function B(e){var n=k(function(n){try{var t=!1;return n.send(S,"SUBSCRIBE"),Promise.resolve(m(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(S,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(n,"@EXIT")}}function _(){return{put:C,get:N,update:O,delete:x,where:A,subscribe:B}}k(function(e){try{var n=m(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=p(function(){return y(function(){return Promise.resolve(U[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},S),_().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L,F=function(e,c){void 0===e&&(e=[]),void 0===c&&(c={});try{var s=function(s){return c.node=s,Array.isArray(e)&&(e=n(e)),Promise.resolve(t(e,[r,o,i])).then(function(e){return u(e,c)})},a=c.node;return Promise.resolve(a?s(a):Promise.resolve(_().get("accessNode.api")).then(s))}catch(e){return Promise.reject(e)}},G=function(e){try{return Promise.resolve(_().where(/^decoder\./)).then(function(n){var t=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return c(e,t)})}catch(e){return Promise.reject(e)}},D="FCL_IFRAME_CHALLENGE",H="FCL_IFRAME_AUTHZ",M=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},z={"HTTP/POST":"POST","HTTP/GET":"GET"},X=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:z[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}},W=function(){try{return re(),Promise.resolve(ce()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(F([s(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},q=function(e){try{return re(),Promise.resolve(J()).then(function(){return Promise.resolve(ce()).then(function(n){function t(){return l({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ce()).then(function(n){return Promise.resolve(W()).then(function(t){return Promise.resolve(X(n.authorizations[0],e)).then(function(e){var n=function(){};return e.local&&e.local.length>0&&(console.log("RENDER LOCAL"),n=function(e){if(!document.getElementById(H)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=H,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(H)&&document.getElementById(H).remove()}}}(e.local[0])),Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(X(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){return n(),e})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(W()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},J=function(){try{return Promise.resolve(new Promise(function(e){try{return re(),Promise.resolve(ce()).then(function(n){return n.loggedIn?e(n):Promise.resolve(_().get("challenge.handshake")).then(function(n){return Promise.resolve(_().get("challenge.scope")).then(function(t){var r=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(D)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=D,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(D)&&document.getElementById(D).remove()}}}({handshake:n,scope:t,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==K)return Promise.resolve();r();var o=new URL(t.hks);return o.searchParams.append("code",t.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){return g($,Z,l({},n,{cid:M(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(ce()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},$="CURRENT_USER",V="CURRENT_USER/UPDATED",Z="SET_CURRENT_USER",K="FCL::CHALLENGE::RESPONSE",Q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',Y=function(e,n){return Object.fromEntries(n.map(function(n){return[n,e.get(n)]}))},ee=function(e,n){Object.entries(n).forEach(function(n){return e.put(n[0],n[1])})},ne=((L={}).SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,V,Y(e,e.keys()))},L.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},L.SNAPSHOT=function(e,n){try{return n.reply(Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L[Z]=function(e,n,t){try{return ee(e,t),e.broadcast(V,Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L.DEL_CURRENT_USER=function(e,n){try{return ee(e,JSON.parse(Q)),e.broadcast(V,Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:a}),Promise.resolve()}catch(e){return Promise.reject(e)}},L),te=function(e){try{ee(e,JSON.parse(Q));var n=m(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=p(function(){return y(function(){return Promise.resolve(ne[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("Current User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},re=function(){return k(te,$)};function oe(){re(),g($,"DEL_CURRENT_USER")}function ie(e){return function(){try{return re(),Promise.resolve(J()).then(function(){return g($,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function ue(e){re();var n=k(function(n){try{var t=!1;return n.send($,"SUBSCRIBE"),Promise.resolve(m(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send($,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(n,"@EXIT")}}function ce(){return re(),g($,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var se=function(){return{authenticate:J,unauthenticate:oe,authorization:q,param:ie,subscribe:ue,snapshot:ce}},ae=function(){return se().authenticate()},le=function(){return se().unauthenticate()};export{ae as authenticate,_ as config,se as currentUser,G as decode,F as send,le as unauthenticate}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import r from"queue-microtask";import{build as e,pipe as n,resolve as t,resolveParams as o,resolveAuthorizations as i,send as u}from"@onflow/sdk";function c(){return(c=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r}).apply(this,arguments)}function s(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}const a=function(){function r(){}return r.prototype.then=function(e,n){const t=new r,o=this.s;if(o){const r=1&o?e:n;if(r){try{f(t,1,r(this.v))}catch(r){f(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?f(t,1,e?e(o):o):n?f(t,1,n(o)):f(t,2,o)}catch(r){f(t,2,r)}},t},r}();function f(r,e,n){if(!r.s){if(n instanceof a){if(!n.s)return void(n.o=f.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(f.bind(null,r,e),f.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function l(r){return r instanceof a&&1&r.s}function v(r,e,n){for(var t;;){var o=r();if(l(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!l(i)){t=1;break}i=i.s}if(e){var u=e();if(u&&u.then&&!l(u)){t=2;break}}}var c=new a,s=f.bind(null,c,2);return(0===t?o.then(d):1===t?i.then(v):u.then(h)).then(void 0,s),c;function v(t){i=t;do{if(e&&(u=e())&&u.then&&!l(u))return void u.then(h).then(void 0,s);if(!(o=r())||l(o)&&!o.v)return void f(c,1,i);if(o.then)return void o.then(d).then(void 0,s);l(i=n())&&(i=i.v)}while(!i||!i.then);i.then(v).then(void 0,s)}function d(r){r?(i=n())&&i.then?i.then(v).then(void 0,s):v(i):f(c,1,i)}function h(){(o=r())?o.then?o.then(d).then(void 0,s):d(o):f(c,1,i)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var d={},h=0,m=function(r,e,n,t){return void 0===t&&(t={}),new Promise(function(o,i){var u=t.expectReply||!1,c=null!=t.timeout?t.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:r,from:t.from,tag:e,data:n,timeout:c,reply:o,reject:i};try{d[r].mailbox.deliver(s),u||o(!0)}catch(r){console.error("FCL.Actor -- Could Not Deliver Message",s,r)}})},y=function(e,n){if(void 0===n&&(n=null),null==n&&(n=++h),null!=d[n])return n;var t,o;d[n]={addr:n,mailbox:(o=[],{deliver:function(r){try{return o.push(r),t&&(t(o.shift()),t=void 0),Promise.resolve()}catch(r){return Promise.reject(r)}},receive:function(){return new Promise(function(r){var e=o.shift();if(e)return r(e);t=r})}}),subs:new Set,kvs:{}};var i={self:function(){return n},receive:function(){return d[n].mailbox.receive()},send:function(r,e,t,o){return void 0===o&&(o={}),o.from=n,m(r,e,t,o)},broadcast:function(r,e,t){void 0===t&&(t={}),t.from=n;for(var o,i=function(r){var e=0;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(r=function(r,e){if(r){if("string"==typeof r)return s(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(r,void 0):void 0}}(r)))return function(){return e>=r.length?{done:!0}:{done:!1,value:r[e++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(e=r[Symbol.iterator]()).next.bind(e)}(d[n].subs);!(o=i()).done;)m(o.value,r,e,t)},subscribe:function(r){return null!=r&&d[n].subs.add(r)},unsubscribe:function(r){return null!=r&&d[n].subs.delete(r)},put:function(r,e){null!=r&&(d[n].kvs[r]=e)},get:function(r,e){var t=d[n].kvs[r];return null==t?e:t},delete:function(r){delete d[n].kvs[r]},update:function(r,e){null!=r&&(d[n].kvs[r]=e(d[n].kvs[r]))},keys:function(){return Object.keys(d[n].kvs)}};return r(function(){try{return Promise.resolve(e(i)).then(function(){!function(r){delete d[r]}(n)})}catch(r){return Promise.reject(r)}}),n},b="config",p="PUT_CONFIG",P="GET_CONFIG",k="CONFIG/UPDATED";y(function(r){try{var e=function(e){return e.reduce(function(e,n){var t;return c({},e,((t={})[n]=r.get(n),t))},{})},n=v(function(){return 1},void 0,function(){return Promise.resolve(r.receive()).then(function(n){var t=n.data;try{switch(n.tag){case p:return void(null!=t.key&&(r.put(t.key,t.value),r.broadcast(k,e(r.keys()))));case P:return void(null!=t.key&&n.reply(r.get(t.key,t.fallback)));case"UPDATE_CONFIG":return void(null!=t.key&&(r.update(t.key,t.fn),r.broadcast(k,e(r.keys()))));case"DELETE_CONFIG":return void(null!=t.key&&(r.delete(t.key),r.broadcast(k,e(r.keys()))));case"WHERE_CONFIG":return void(null!=t.pattern&&n.reply(e(r.keys().filter(function(r){return t.pattern.test(r)}))));case"SUBSCRIBE":return r.subscribe(n.from),void r.send(n.from,k,e(r.keys()));case"UNSUBSCRIBE":return void r.unsubscribe(n.from);default:return}}catch(r){return void console.error("Config Error",n,r)}})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(r){return Promise.reject(r)}},b);var S=function(r){return r},E=function(){return{put:function(r,e){m(b,p,{key:r,value:e})},get:function(r,e){return m(b,P,{key:r,fallback:e},{expectReply:!0,timeout:10})},update:function(r,e){void 0===e&&(e=S),m(b,"UPDATE_CONFIG",{key:r,fn:e})},delete:function(r){m(b,"DELETE_CONFIG",{key:r})},where:function(r){return m(b,"WHERE_CONFIG",{pattern:r},{expectReply:!0,timeout:10})},subscribe:function(r){var e=y(function(e){try{var n=!1;return e.send(b,"SUBSCRIBE"),Promise.resolve(v(function(){return!n&&1},void 0,function(){return Promise.resolve(e.receive()).then(function(t){if("@EXIT"===t.tag)return e.send(b,"UNSUBSCRIBE"),void(n=!0);r(t.data)})}))}catch(r){return Promise.reject(r)}});return function(){return m(e,"@EXIT")}}}};E().put("accessNode.api","http://localhost:8080");var I,g=function(r,c){void 0===r&&(r=[]),void 0===c&&(c={});try{var s=function(s){return c.node=s,Array.isArray(r)&&(r=e(r)),Promise.resolve(n(r,[t([o,i])])).then(function(r){return u(r,c)})},a=c.node;return Promise.resolve(a?s(a):Promise.resolve(E().get("accessNode.api")).then(s))}catch(r){return Promise.reject(r)}},j=function(r){return"https://avatars.onflow.org/avatar/"+r+".svg"},w=function(r,e){return e.reduce(function(e,n){var t;return c({},e,((t={})[n]=r.get(n),t))},{})},C=((I={}).SUBSCRIBE=function(r,e){r.subscribe(e.from),r.send(e.from,"USER/UPDATED",w(r,r.keys()))},I.UNSUBSCRIBE=function(r,e){r.unsubscribe(e.from)},I.SNAPSHOT=function(r,e){try{return e.reply(w(r,r.keys())),Promise.resolve()}catch(r){return Promise.reject(r)}},I),U=function(r){try{return Promise.resolve(function(r){try{return Promise.resolve((void 0===e&&(e=10),new Promise(function(r){return setTimeout(r,e)}))).then(function(){return{acct:r,name:"bob the builder",avatar:j(),bio:"Can he fix it, yes he can.",hooks:{}}})}catch(r){return Promise.reject(r)}var e}(r.self())).then(function(e){!function(r,e){for(var n=0,t=Object.keys(e);n<t.length;n++){var o=t[n];r.put(o,e[o])}}(r,e);var n=v(function(){return 1},void 0,function(){return Promise.resolve(r.receive()).then(function(e){var n=function(n,t){try{var o=function(n,t){try{var o=Promise.resolve(C[e.tag](r,e)).then(function(){})}catch(r){return t(r)}return o&&o.then?o.then(void 0,t):o}(0,function(r){console.error("User Error",e,r)})}catch(r){return}return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):void 0}(0,function(r,e){});if(n&&n.then)return n.then(function(){})})});return n&&n.then?n.then(function(){}):void 0})}catch(r){return Promise.reject(r)}},A=function(r){return y(U,r)},N=function(r){return{authorization:function(){try{return A(r),Promise.resolve({acct:r,signFn:function(){try{throw new Error("fcl.user("+r+").payerAuthorization WIP error -- known missing functionality")}catch(r){return Promise.reject(r)}}})}catch(r){return Promise.reject(r)}},payerAuthorization:function(){try{return A(r),Promise.resolve({acct:r,signFn:function(){try{throw new Error("fcl.user("+r+").payerAuthorization WIP error -- known missing functionality")}catch(r){return Promise.reject(r)}}})}catch(r){return Promise.reject(r)}},snapshot:function(){try{return A(r),Promise.resolve(m(r,"SNAPSHOT",null,{expectReply:!0,timeout:0}))}catch(r){return Promise.reject(r)}},param:function(e){return{value:r,xform:{asParam:function(r){return r},asInjection:function(r){return r}}}},subscribe:function(e){A(r);var n=y(function(n){try{var t=!1;return n.send(r,"SUBSCRIBE"),Promise.resolve(v(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(r,"UNSUBSCRIBE"),void(t=!0);e(o.data)})}))}catch(r){return Promise.reject(r)}});return function(){return m(n,"@EXIT")}}}},O=function(){return Promise.resolve()},T=function(){return Promise.resolve()},B=function(){return{subscribe:function(r){return function(){}},authorization:function(){return Promise.resolve()},payerAuthorization:function(){return Promise.resolve()},param:function(){return Promise.resolve()}}},R=function(r){return{subscribe:function(r){return function(){}}}},F=function(r,e){return{subscribe:function(r){return function(){}}}},x=function(r){return Promise.resolve()};export{O as authenticate,E as config,B as currentUser,x as decode,F as event,g as send,R as transaction,T as unauthenticate,N as user}; | ||
import e from"queue-microtask";import{build as n,resolve as t,resolveParams as r,resolveAccounts as o,resolveSignatures as i,send as u,decodeResponse as c,getAccount as s}from"@onflow/sdk";export{authorization,authorizations,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,proposer,ref,script,transaction,why}from"@onflow/sdk";import{Identity as a}from"@onflow/types";function l(){return(l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function f(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}const d=function(){function e(){}return e.prototype.then=function(n,t){const r=new e,o=this.s;if(o){const e=1&o?n:t;if(e){try{h(r,1,e(this.v))}catch(e){h(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?h(r,1,n?n(o):o):t?h(r,1,t(o)):h(r,2,o)}catch(e){h(r,2,e)}},r},e}();function h(e,n,t){if(!e.s){if(t instanceof d){if(!t.s)return void(t.o=h.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(h.bind(null,e,n),h.bind(null,e,2));e.s=n,e.v=t;const r=e.o;r&&r(e)}}function v(e){return e instanceof d&&1&e.s}function m(e,n,t){for(var r;;){var o=e();if(v(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!v(i)){r=1;break}i=i.s}if(n){var u=n();if(u&&u.then&&!v(u)){r=2;break}}}var c=new d,s=h.bind(null,c,2);return(0===r?o.then(l):1===r?i.then(a):u.then(f)).then(void 0,s),c;function a(r){i=r;do{if(n&&(u=n())&&u.then&&!v(u))return void u.then(f).then(void 0,s);if(!(o=e())||v(o)&&!o.v)return void h(c,1,i);if(o.then)return void o.then(l).then(void 0,s);v(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function l(e){e?(i=t())&&i.then?i.then(a).then(void 0,s):a(i):h(c,1,i)}function f(){(o=e())?o.then?o.then(l).then(void 0,s):l(o):h(c,1,i)}}function y(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}function p(e,n){try{var t=e()}catch(e){return n(!0,e)}return t&&t.then?t.then(n.bind(null,!1),n.bind(null,!0)):n(!1,t)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var P,b={},E=0,g=function(e,n,t,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:r.from,tag:n,data:t,timeout:c,reply:o,reject:i};try{b[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},k=function(n,t){if(void 0===t&&(t=null),null==t&&(t=++E),null!=b[t])return t;var r,o;b[t]={addr:t,mailbox:(o=[],{deliver:function(e){try{return o.push(e),r&&(r(o.shift()),r=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var n=o.shift();if(n)return e(n);r=e})}}),subs:new Set,kvs:{}};var i={self:function(){return t},receive:function(){return b[t].mailbox.receive()},send:function(e,n,r,o){return void 0===o&&(o={}),o.from=t,g(e,n,r,o)},broadcast:function(e,n,r){void 0===r&&(r={}),r.from=t;for(var o,i=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return f(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?f(e,void 0):void 0}}(e)))return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(b[t].subs);!(o=i()).done;)g(o.value,e,n,r)},subscribe:function(e){return null!=e&&b[t].subs.add(e)},unsubscribe:function(e){return null!=e&&b[t].subs.delete(e)},put:function(e,n){null!=e&&(b[t].kvs[e]=n)},get:function(e,n){var r=b[t].kvs[e];return null==r?n:r},delete:function(e){delete b[t].kvs[e]},update:function(e,n){null!=e&&(b[t].kvs[e]=n(b[t].kvs[e]))},keys:function(){return Object.keys(b[t].kvs)}};return e(function(){try{return Promise.resolve(n(i)).then(function(){!function(e){delete b[e]}(t)})}catch(e){return Promise.reject(e)}}),t},S="config",w="PUT_CONFIG",I="GET_CONFIG",R="CONFIG/UPDATED",j=function(e,n){return void 0===n&&(n=[]),n.reduce(function(n,t){var r;return l({},n,((r={})[t]=e.get(t),r))},{})},T=function(e){return e},U=((P={})[w]=function(e,n,t){var r=t.key,o=t.value;if(null==r)throw new Error("Missing 'key' for config/put.");e.put(r,o),e.broadcast(R,j(e,e.keys()))},P[I]=function(e,n,t){var r=t.key,o=t.fallback;if(null==r)throw new Error("Missing 'key' for config/get");n.reply(e.get(r,o))},P.UPDATE_CONFIG=function(e,n,t){var r=t.key,o=t.fn;if(null==r)throw new Error("Missing 'key' for config/update");e.update(r,o||T),e.broadcast(R,j(e,e.keys()))},P.DELETE_CONFIG=function(e,n,t){var r=t.key;if(null==r)throw new Error("Missing 'key' for config/delete");e.delete(r),e.broadcast(R,j(e,e.keys()))},P.WHERE_CONFIG=function(e,n,t){var r=t.pattern;if(null==r)throw new Error("Missing 'pattern' for config/where");n.reply(j(e,e.keys().filter(function(e){return r.test(e)})))},P.SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,R,j(e.keys()))},P.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},P);function C(e,n){return g(S,w,{key:e,value:n}),_()}function N(e,n){return g(S,I,{key:e,fallback:n},{expectReply:!0,timeout:10})}function O(e,n){return void 0===n&&(n=T),g(S,"UPDATE_CONFIG",{key:e,fn:n}),_()}function x(e){return g(S,"DELETE_CONFIG",{key:e}),_()}function A(e){return g(S,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})}function B(e){var n=k(function(n){try{var t=!1;return n.send(S,"SUBSCRIBE"),Promise.resolve(m(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(S,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(n,"@EXIT")}}function _(){return{put:C,get:N,update:O,delete:x,where:A,subscribe:B}}k(function(e){try{var n=m(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=p(function(){return y(function(){return Promise.resolve(U[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},S),_().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L,F=function(e,c){void 0===e&&(e=[]),void 0===c&&(c={});try{var s=function(s){return c.node=s,Array.isArray(e)&&(e=n(e)),Promise.resolve(t(e,[r,o,i])).then(function(e){return u(e,c)})},a=c.node;return Promise.resolve(a?s(a):Promise.resolve(_().get("accessNode.api")).then(s))}catch(e){return Promise.reject(e)}},G=function(e){try{return Promise.resolve(_().where(/^decoder\./)).then(function(n){var t=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return c(e,t)})}catch(e){return Promise.reject(e)}},D="FCL_IFRAME_CHALLENGE",H="FCL_IFRAME_AUTHZ",M=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},z={"HTTP/POST":"POST","HTTP/GET":"GET"},X=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:z[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}},W=function(){try{return re(),Promise.resolve(ce()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(F([s(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},q=function(e){try{return re(),Promise.resolve(J()).then(function(){return Promise.resolve(ce()).then(function(n){function t(){return l({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ce()).then(function(n){return Promise.resolve(W()).then(function(t){return Promise.resolve(X(n.authorizations[0],e)).then(function(e){var n=function(){};return e.local&&e.local.length>0&&(console.log("RENDER LOCAL"),n=function(e){if(!document.getElementById(H)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=H,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(H)&&document.getElementById(H).remove()}}}(e.local[0])),Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(X(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){return n(),e})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(W()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},J=function(){try{return Promise.resolve(new Promise(function(e){try{return re(),Promise.resolve(ce()).then(function(n){return n.loggedIn?e(n):Promise.resolve(_().get("challenge.handshake")).then(function(n){return Promise.resolve(_().get("challenge.scope")).then(function(t){var r=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(D)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=D,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(D)&&document.getElementById(D).remove()}}}({handshake:n,scope:t,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==K)return Promise.resolve();r();var o=new URL(t.hks);return o.searchParams.append("code",t.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){return g($,Z,l({},n,{cid:M(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(ce()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},$="CURRENT_USER",V="CURRENT_USER/UPDATED",Z="SET_CURRENT_USER",K="FCL::CHALLENGE::RESPONSE",Q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',Y=function(e,n){return Object.fromEntries(n.map(function(n){return[n,e.get(n)]}))},ee=function(e,n){Object.entries(n).forEach(function(n){return e.put(n[0],n[1])})},ne=((L={}).SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,V,Y(e,e.keys()))},L.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},L.SNAPSHOT=function(e,n){try{return n.reply(Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L[Z]=function(e,n,t){try{return ee(e,t),e.broadcast(V,Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L.DEL_CURRENT_USER=function(e,n){try{return ee(e,JSON.parse(Q)),e.broadcast(V,Y(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},L.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:a}),Promise.resolve()}catch(e){return Promise.reject(e)}},L),te=function(e){try{ee(e,JSON.parse(Q));var n=m(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=p(function(){return y(function(){return Promise.resolve(ne[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("Current User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},re=function(){return k(te,$)};function oe(){re(),g($,"DEL_CURRENT_USER")}function ie(e){return function(){try{return re(),Promise.resolve(J()).then(function(){return g($,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function ue(e){re();var n=k(function(n){try{var t=!1;return n.send($,"SUBSCRIBE"),Promise.resolve(m(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send($,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(n,"@EXIT")}}function ce(){return re(),g($,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var se=function(){return{authenticate:J,unauthenticate:oe,authorization:q,param:ie,subscribe:ue,snapshot:ce}},ae=function(){return se().authenticate()},le=function(){return se().unauthenticate()};export{ae as authenticate,_ as config,se as currentUser,G as decode,F as send,le as unauthenticate}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("queue-microtask"),require("@onflow/sdk")):"function"==typeof define&&define.amd?define(["exports","queue-microtask","@onflow/sdk"],r):r((e=e||self).fcl={},e.queueMicrotask,e.sdk)}(this,function(e,r,n){function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;const i=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{u(t,1,e(this.v))}catch(e){u(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?u(t,1,r?r(o):o):n?u(t,1,n(o)):u(t,2,o)}catch(e){u(t,2,e)}},t},e}();function u(e,r,n){if(!e.s){if(n instanceof i){if(!n.s)return void(n.o=u.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(u.bind(null,e,r),u.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function c(e){return e instanceof i&&1&e.s}function s(e,r,n){for(var t;;){var o=e();if(c(o)&&(o=o.v),!o)return s;if(o.then){t=0;break}var s=n();if(s&&s.then){if(!c(s)){t=1;break}s=s.s}if(r){var a=r();if(a&&a.then&&!c(a)){t=2;break}}}var f=new i,l=u.bind(null,f,2);return(0===t?o.then(d):1===t?s.then(v):a.then(h)).then(void 0,l),f;function v(t){s=t;do{if(r&&(a=r())&&a.then&&!c(a))return void a.then(h).then(void 0,l);if(!(o=e())||c(o)&&!o.v)return void u(f,1,s);if(o.then)return void o.then(d).then(void 0,l);c(s=n())&&(s=s.v)}while(!s||!s.then);s.then(v).then(void 0,l)}function d(e){e?(s=n())&&s.then?s.then(v).then(void 0,l):v(s):u(f,1,s)}function h(){(o=e())?o.then?o.then(d).then(void 0,l):d(o):u(f,1,s)}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a={},f=0,l=function(e,r,n,t){return void 0===t&&(t={}),new Promise(function(o,i){var u=t.expectReply||!1,c=null!=t.timeout?t.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:t.from,tag:r,data:n,timeout:c,reply:o,reject:i};try{a[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},v=function(e,n){if(void 0===n&&(n=null),null==n&&(n=++f),null!=a[n])return n;var t,i;a[n]={addr:n,mailbox:(i=[],{deliver:function(e){try{return i.push(e),t&&(t(i.shift()),t=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var r=i.shift();if(r)return e(r);t=e})}}),subs:new Set,kvs:{}};var u={self:function(){return n},receive:function(){return a[n].mailbox.receive()},send:function(e,r,t,o){return void 0===o&&(o={}),o.from=n,l(e,r,t,o)},broadcast:function(e,r,t){void 0===t&&(t={}),t.from=n;for(var i,u=function(e){var r=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,r){if(e){if("string"==typeof e)return o(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,void 0):void 0}}(e)))return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(a[n].subs);!(i=u()).done;)l(i.value,e,r,t)},subscribe:function(e){return null!=e&&a[n].subs.add(e)},unsubscribe:function(e){return null!=e&&a[n].subs.delete(e)},put:function(e,r){null!=e&&(a[n].kvs[e]=r)},get:function(e,r){var t=a[n].kvs[e];return null==t?r:t},delete:function(e){delete a[n].kvs[e]},update:function(e,r){null!=e&&(a[n].kvs[e]=r(a[n].kvs[e]))},keys:function(){return Object.keys(a[n].kvs)}};return r(function(){try{return Promise.resolve(e(u)).then(function(){!function(e){delete a[e]}(n)})}catch(e){return Promise.reject(e)}}),n},d="config",h="PUT_CONFIG",m="GET_CONFIG",y="CONFIG/UPDATED";v(function(e){try{var r=function(r){return r.reduce(function(r,n){var o;return t({},r,((o={})[n]=e.get(n),o))},{})},n=s(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=n.data;try{switch(n.tag){case h:return void(null!=t.key&&(e.put(t.key,t.value),e.broadcast(y,r(e.keys()))));case m:return void(null!=t.key&&n.reply(e.get(t.key,t.fallback)));case"UPDATE_CONFIG":return void(null!=t.key&&(e.update(t.key,t.fn),e.broadcast(y,r(e.keys()))));case"DELETE_CONFIG":return void(null!=t.key&&(e.delete(t.key),e.broadcast(y,r(e.keys()))));case"WHERE_CONFIG":return void(null!=t.pattern&&n.reply(r(e.keys().filter(function(e){return t.pattern.test(e)}))));case"SUBSCRIBE":return e.subscribe(n.from),void e.send(n.from,y,r(e.keys()));case"UNSUBSCRIBE":return void e.unsubscribe(n.from);default:return}}catch(e){return void console.error("Config Error",n,e)}})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},d);var b=function(e){return e},p=function(){return{put:function(e,r){l(d,h,{key:e,value:r})},get:function(e,r){return l(d,m,{key:e,fallback:r},{expectReply:!0,timeout:10})},update:function(e,r){void 0===r&&(r=b),l(d,"UPDATE_CONFIG",{key:e,fn:r})},delete:function(e){l(d,"DELETE_CONFIG",{key:e})},where:function(e){return l(d,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})},subscribe:function(e){var r=v(function(r){try{var n=!1;return r.send(d,"SUBSCRIBE"),Promise.resolve(s(function(){return!n&&1},void 0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(d,"UNSUBSCRIBE"),void(n=!0);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l(r,"@EXIT")}}}};p().put("accessNode.api","http://localhost:8080");var P,k=function(e){return"https://avatars.onflow.org/avatar/"+e+".svg"},S=function(e,r){return r.reduce(function(r,n){var o;return t({},r,((o={})[n]=e.get(n),o))},{})},E=((P={}).SUBSCRIBE=function(e,r){e.subscribe(r.from),e.send(r.from,"USER/UPDATED",S(e,e.keys()))},P.UNSUBSCRIBE=function(e,r){e.unsubscribe(r.from)},P.SNAPSHOT=function(e,r){try{return r.reply(S(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},P),g=function(e){try{return Promise.resolve(function(e){try{return Promise.resolve((void 0===r&&(r=10),new Promise(function(e){return setTimeout(e,r)}))).then(function(){return{acct:e,name:"bob the builder",avatar:k(),bio:"Can he fix it, yes he can.",hooks:{}}})}catch(e){return Promise.reject(e)}var r}(e.self())).then(function(r){!function(e,r){for(var n=0,t=Object.keys(r);n<t.length;n++){var o=t[n];e.put(o,r[o])}}(e,r);var n=s(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(r){var n=function(n,t){try{var o=function(n,t){try{var o=Promise.resolve(E[r.tag](e,r)).then(function(){})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){console.error("User Error",r,e)})}catch(e){return}return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):void 0}(0,function(e,r){});if(n&&n.then)return n.then(function(){})})});return n&&n.then?n.then(function(){}):void 0})}catch(e){return Promise.reject(e)}},I=function(e){return v(g,e)};e.authenticate=function(){return Promise.resolve()},e.config=p,e.currentUser=function(){return{subscribe:function(e){return function(){}},authorization:function(){return Promise.resolve()},payerAuthorization:function(){return Promise.resolve()},param:function(){return Promise.resolve()}}},e.decode=function(e){return Promise.resolve()},e.event=function(e,r){return{subscribe:function(e){return function(){}}}},e.send=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var t=function(t){return r.node=t,Array.isArray(e)&&(e=n.build(e)),Promise.resolve(n.pipe(e,[n.resolve([n.resolveParams,n.resolveAuthorizations])])).then(function(e){return n.send(e,r)})},o=r.node;return Promise.resolve(o?t(o):Promise.resolve(p().get("accessNode.api")).then(t))}catch(e){return Promise.reject(e)}},e.transaction=function(e){return{subscribe:function(e){return function(){}}}},e.unauthenticate=function(){return Promise.resolve()},e.user=function(e){return{authorization:function(){try{return I(e),Promise.resolve({acct:e,signFn:function(){try{throw new Error("fcl.user("+e+").payerAuthorization WIP error -- known missing functionality")}catch(e){return Promise.reject(e)}}})}catch(e){return Promise.reject(e)}},payerAuthorization:function(){try{return I(e),Promise.resolve({acct:e,signFn:function(){try{throw new Error("fcl.user("+e+").payerAuthorization WIP error -- known missing functionality")}catch(e){return Promise.reject(e)}}})}catch(e){return Promise.reject(e)}},snapshot:function(){try{return I(e),Promise.resolve(l(e,"SNAPSHOT",null,{expectReply:!0,timeout:0}))}catch(e){return Promise.reject(e)}},param:function(r){return{value:e,xform:{asParam:function(e){return e},asInjection:function(e){return e}}}},subscribe:function(r){I(e);var n=v(function(n){try{var t=!1;return n.send(e,"SUBSCRIBE"),Promise.resolve(s(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(e,"UNSUBSCRIBE"),void(t=!0);r(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l(n,"@EXIT")}}}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("queue-microtask"),require("@onflow/sdk"),require("@onflow/types")):"function"==typeof define&&define.amd?define(["exports","queue-microtask","@onflow/sdk","@onflow/types"],n):n((e=e||self).fcl={},e.queueMicrotask,e.sdk,e.types)}(this,function(e,n,t,r){function o(){return(o=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;const u=function(){function e(){}return e.prototype.then=function(n,t){const r=new e,o=this.s;if(o){const e=1&o?n:t;if(e){try{c(r,1,e(this.v))}catch(e){c(r,2,e)}return r}return this}return this.o=function(e){try{const o=e.v;1&e.s?c(r,1,n?n(o):o):t?c(r,1,t(o)):c(r,2,o)}catch(e){c(r,2,e)}},r},e}();function c(e,n,t){if(!e.s){if(t instanceof u){if(!t.s)return void(t.o=c.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(c.bind(null,e,n),c.bind(null,e,2));e.s=n,e.v=t;const r=e.o;r&&r(e)}}function s(e){return e instanceof u&&1&e.s}function a(e,n,t){for(var r;;){var o=e();if(s(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!s(i)){r=1;break}i=i.s}if(n){var a=n();if(a&&a.then&&!s(a)){r=2;break}}}var f=new u,l=c.bind(null,f,2);return(0===r?o.then(h):1===r?i.then(d):a.then(m)).then(void 0,l),f;function d(r){i=r;do{if(n&&(a=n())&&a.then&&!s(a))return void a.then(m).then(void 0,l);if(!(o=e())||s(o)&&!o.v)return void c(f,1,i);if(o.then)return void o.then(h).then(void 0,l);s(i=t())&&(i=i.v)}while(!i||!i.then);i.then(d).then(void 0,l)}function h(e){e?(i=t())&&i.then?i.then(d).then(void 0,l):d(i):c(f,1,i)}function m(){(o=e())?o.then?o.then(h).then(void 0,l):h(o):c(f,1,i)}}function f(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}function l(e,n){try{var t=e()}catch(e){return n(!0,e)}return t&&t.then?t.then(n.bind(null,!1),n.bind(null,!0)):n(!1,t)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var d,h={},m=0,v=function(e,n,t,r){return void 0===r&&(r={}),new Promise(function(o,i){var u=r.expectReply||!1,c=null!=r.timeout?r.timeout:5e3;u&&c&&setTimeout(function(){return i(new Error("Timeout: "+c+"ms passed without a response."))},c);var s={to:e,from:r.from,tag:n,data:t,timeout:c,reply:o,reject:i};try{h[e].mailbox.deliver(s),u||o(!0)}catch(e){console.error("FCL.Actor -- Could Not Deliver Message",s,e)}})},y=function(e,t){if(void 0===t&&(t=null),null==t&&(t=++m),null!=h[t])return t;var r,o;h[t]={addr:t,mailbox:(o=[],{deliver:function(e){try{return o.push(e),r&&(r(o.shift()),r=void 0),Promise.resolve()}catch(e){return Promise.reject(e)}},receive:function(){return new Promise(function(e){var n=o.shift();if(n)return e(n);r=e})}}),subs:new Set,kvs:{}};var u={self:function(){return t},receive:function(){return h[t].mailbox.receive()},send:function(e,n,r,o){return void 0===o&&(o={}),o.from=t,v(e,n,r,o)},broadcast:function(e,n,r){void 0===r&&(r={}),r.from=t;for(var o,u=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e)))return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(h[t].subs);!(o=u()).done;)v(o.value,e,n,r)},subscribe:function(e){return null!=e&&h[t].subs.add(e)},unsubscribe:function(e){return null!=e&&h[t].subs.delete(e)},put:function(e,n){null!=e&&(h[t].kvs[e]=n)},get:function(e,n){var r=h[t].kvs[e];return null==r?n:r},delete:function(e){delete h[t].kvs[e]},update:function(e,n){null!=e&&(h[t].kvs[e]=n(h[t].kvs[e]))},keys:function(){return Object.keys(h[t].kvs)}};return n(function(){try{return Promise.resolve(e(u)).then(function(){!function(e){delete h[e]}(t)})}catch(e){return Promise.reject(e)}}),t},p="config",b="PUT_CONFIG",P="GET_CONFIG",g="CONFIG/UPDATED",E=function(e,n){return void 0===n&&(n=[]),n.reduce(function(n,t){var r;return o({},n,((r={})[t]=e.get(t),r))},{})},k=function(e){return e},j=((d={})[b]=function(e,n,t){var r=t.key,o=t.value;if(null==r)throw new Error("Missing 'key' for config/put.");e.put(r,o),e.broadcast(g,E(e,e.keys()))},d[P]=function(e,n,t){var r=t.key,o=t.fallback;if(null==r)throw new Error("Missing 'key' for config/get");n.reply(e.get(r,o))},d.UPDATE_CONFIG=function(e,n,t){var r=t.key,o=t.fn;if(null==r)throw new Error("Missing 'key' for config/update");e.update(r,o||k),e.broadcast(g,E(e,e.keys()))},d.DELETE_CONFIG=function(e,n,t){var r=t.key;if(null==r)throw new Error("Missing 'key' for config/delete");e.delete(r),e.broadcast(g,E(e,e.keys()))},d.WHERE_CONFIG=function(e,n,t){var r=t.pattern;if(null==r)throw new Error("Missing 'pattern' for config/where");n.reply(E(e,e.keys().filter(function(e){return r.test(e)})))},d.SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,g,E(e.keys()))},d.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},d);function S(e,n){return v(p,b,{key:e,value:n}),U()}function w(e,n){return v(p,P,{key:e,fallback:n},{expectReply:!0,timeout:10})}function O(e,n){return void 0===n&&(n=k),v(p,"UPDATE_CONFIG",{key:e,fn:n}),U()}function I(e){return v(p,"DELETE_CONFIG",{key:e}),U()}function R(e){return v(p,"WHERE_CONFIG",{pattern:e},{expectReply:!0,timeout:10})}function T(e){var n=y(function(n){try{var t=!1;return n.send(p,"SUBSCRIBE"),Promise.resolve(a(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(p,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(n,"@EXIT")}}function U(){return{put:S,get:w,update:O,delete:I,where:R,subscribe:T}}y(function(e){try{var n=a(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=l(function(){return f(function(){return Promise.resolve(j[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},p),U().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var C,N=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var r=function(r){return n.node=r,Array.isArray(e)&&(e=t.build(e)),Promise.resolve(t.resolve(e,[t.resolveParams,t.resolveAccounts,t.resolveSignatures])).then(function(e){return t.send(e,n)})},o=n.node;return Promise.resolve(o?r(o):Promise.resolve(U().get("accessNode.api")).then(r))}catch(e){return Promise.reject(e)}},A="FCL_IFRAME_CHALLENGE",x="FCL_IFRAME_AUTHZ",B=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},_={"HTTP/POST":"POST","HTTP/GET":"GET"},L=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:_[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}},F=function(){try{return Z(),Promise.resolve(ee()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(N([t.getAccount(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},G=function(e){try{return Z(),Promise.resolve(D()).then(function(){return Promise.resolve(ee()).then(function(n){function t(){return o({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ee()).then(function(n){return Promise.resolve(F()).then(function(t){return Promise.resolve(L(n.authorizations[0],e)).then(function(e){var n=function(){};return e.local&&e.local.length>0&&(console.log("RENDER LOCAL"),n=function(e){if(!document.getElementById(x)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=x,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(x)&&document.getElementById(x).remove()}}}(e.local[0])),Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(L(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){return n(),e})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,i=function(){if(e.role.proposer)return Promise.resolve(F()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return i&&i.then?i.then(t):t()})})}catch(e){return Promise.reject(e)}},D=function(){try{return Promise.resolve(new Promise(function(e){try{return Z(),Promise.resolve(ee()).then(function(n){return n.loggedIn?e(n):Promise.resolve(U().get("challenge.handshake")).then(function(n){return Promise.resolve(U().get("challenge.scope")).then(function(t){var r=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(A)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=A,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(A)&&document.getElementById(A).remove()}}}({handshake:n,scope:t,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==q)return Promise.resolve();r();var i=new URL(t.hks);return i.searchParams.append("code",t.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){return v(M,z,o({},n,{cid:B(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(ee()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},M="CURRENT_USER",H="CURRENT_USER/UPDATED",z="SET_CURRENT_USER",q="FCL::CHALLENGE::RESPONSE",X='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',W=function(e,n){return Object.fromEntries(n.map(function(n){return[n,e.get(n)]}))},J=function(e,n){Object.entries(n).forEach(function(n){return e.put(n[0],n[1])})},$=((C={}).SUBSCRIBE=function(e,n){e.subscribe(n.from),e.send(n.from,H,W(e,e.keys()))},C.UNSUBSCRIBE=function(e,n){e.unsubscribe(n.from)},C.SNAPSHOT=function(e,n){try{return n.reply(W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},C[z]=function(e,n,t){try{return J(e,t),e.broadcast(H,W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},C.DEL_CURRENT_USER=function(e,n){try{return J(e,JSON.parse(X)),e.broadcast(H,W(e,e.keys())),Promise.resolve()}catch(e){return Promise.reject(e)}},C.GET_AS_PARAM=function(e,n,t){var o=t.key;try{return n.reply({key:o,value:e.get("addr",null),xform:r.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},C),V=function(e){try{J(e,JSON.parse(X));var n=a(function(){return 1},void 0,function(){return Promise.resolve(e.receive()).then(function(n){var t=l(function(){return f(function(){return Promise.resolve($[n.tag](e,n,n.data||{})).then(function(){})},function(e){console.error("Current User Error",n,e)})},function(e,n){});if(t&&t.then)return t.then(function(){})})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Z=function(){return y(V,M)};function K(){Z(),v(M,"DEL_CURRENT_USER")}function Q(e){return function(){try{return Z(),Promise.resolve(D()).then(function(){return v(M,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Y(e){Z();var n=y(function(n){try{var t=!1;return n.send(M,"SUBSCRIBE"),Promise.resolve(a(function(){return!t&&1},void 0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(M,"UNSUBSCRIBE"),void(t=!0);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(n,"@EXIT")}}function ee(){return Z(),v(M,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ne=function(){return{authenticate:D,unauthenticate:K,authorization:G,param:Q,subscribe:Y,snapshot:ee}};Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),e.authenticate=function(){return ne().authenticate()},e.config=U,e.currentUser=ne,e.decode=function(e){try{return Promise.resolve(U().where(/^decoder\./)).then(function(n){var r=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return t.decodeResponse(e,r)})}catch(e){return Promise.reject(e)}},e.send=N,e.unauthenticate=function(){return ne().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.28", | ||
"version": "0.0.29", | ||
"description": "Flow Client Library", | ||
@@ -37,5 +37,6 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@onflow/sdk": "0.0.14", | ||
"queue-microtask": "^1.1.2" | ||
"@onflow/sdk": "0.0.17", | ||
"@onflow/types": "0.0.1", | ||
"queue-microtask": "1.1.2" | ||
} | ||
} |
135
README.md
@@ -7,7 +7,16 @@ # @onflow/fcl | ||
- **Interface** Stable _(low risk of change)_ | ||
- **Realization** Unstable _(high risk of change)_ | ||
- **Last Updated:** May 5th 2020 | ||
- **Stable:** No | ||
- **Risk of Breaking Change:** Medium | ||
We are currently confident in how to consume this package and how to build it, but this module is currently in an incomplete state and not everything works yet. | ||
We are currently confident in how to consume this package and how to build it, but this module is currently in a very incomplete state and not everything works yet. | ||
- `config`, `decode` and `send` are in a working state. | ||
- `subscribe`, `snapshot` and `info` are in a working state. | ||
- `authenticate` and `unauthenticate` are working with the dev wallet, but do not yet persist a session | ||
- The authentication portion of `currentUser` is working with the dev wallet | ||
- We are waiting on some upstream changes before we can make the `currentUser` authorization portion work as expected | ||
- `user` is currently blocked by not storing public data on chain, we are working towards this, but its currently lower on our priority list | ||
- Work on `events` and `transactions` hasn't started yet, but should be straight forward once it has. | ||
# Install | ||
@@ -23,37 +32,39 @@ | ||
- [x] [`fcl.config()`](./src/config) _(done)_ | ||
- [x] `fcl.config().put(key, value)` _(done)_ | ||
- [x] `fcl.config().get(key)` _(done)_ | ||
- [x] `fcl.config().get(key, fallback)` _(done)_ | ||
- [x] `fcl.config().update(key, transform)` _(done)_ | ||
- [x] `fcl.config().delete(key)` _(done)_ | ||
- [x] `fcl.config().where(regexp)` _(done)_ | ||
- [x] `fcl.config().subscribe(callback)` _(done)_ | ||
- [ ] `fcl.authenticate()` _(wip)_ | ||
- [ ] `fcl.unauthenticate()` _(wip)_ | ||
- [ ] `fcl.currentUser()` _(wip)_ | ||
- [ ] `fcl.currentUser().snapshot()` _(wip)_ | ||
- [ ] `fcl.currentUser().subscribe(callback)` _(wip)_ | ||
- [x] [`fcl.config()`](./src/config) | ||
- [x] `fcl.config().put(key, value)` | ||
- [x] `fcl.config().get(key)` | ||
- [x] `fcl.config().get(key, fallback)` | ||
- [x] `fcl.config().update(key, transform)` | ||
- [x] `fcl.config().delete(key)` | ||
- [x] `fcl.config().where(regexp)` | ||
- [x] `fcl.config().subscribe(callback)` | ||
- [x] [`fcl.authenticate()`](./src/current-user) | ||
- [x] [`fcl.unauthenticate()`](./src/current-user) | ||
- [ ] [`fcl.currentUser()`](./src/current-user) _(wip)_ | ||
- [x] `fcl.currentUser().snapshot()` | ||
- [x] `fcl.currentUser().subscribe(callback)` | ||
- [x] `fcl.currentUser().authenticate()` | ||
- [ ] Current User Persistent Session | ||
- [x] `fcl.currentUser().unauthenticate()` | ||
- [ ] `fcl.currentUser().authorization` _(wip)_ | ||
- [ ] `fcl.currentUser().payerAuthorization` _(wip)_ | ||
- [ ] `fcl.currentUser().proposerAuthorization` _(wip)_ | ||
- [ ] `fcl.currentUser().param(key)` _(wip)_ | ||
- [ ] [`fcl.user(addr)`](./src/user) _(wip)_ | ||
- [ ] `fcl.user(addr).snapshot()` _(wip)_ | ||
- [ ] `fcl.user(addr).subscribe(callback)` _(wip)_ | ||
- [ ] `fcl.user(addr).authorization` _(wip)_ | ||
- [ ] `fcl.user(addr).payerAuthorization` _(wip)_ | ||
- [ ] `fcl.user(addr).proposerAuthorization` _(wip)_ | ||
- [ ] `fcl.user(addr).param(key)` _(wip)_ | ||
- [ ] `fcl.transaction(transactionId)` _(wip)_ | ||
- [ ] `fcl.transaction(transactionId).snapshot()` _(wip)_ | ||
- [ ] `fcl.transaction(transactionId).subscribe(callback)` _(wip)_ | ||
- [ ] `fcl.events(...)` _(EARLY VERY UNSTABLE)_ | ||
- [ ] `fcl.events(...).subscribe(callback)` _(EARLY VERY UNSTABLE)_ | ||
- [ ] [`fcl.send(builders)`](./src/send) _(WIP)_ | ||
- [ ] Configure `fcl.send` _(WIP)_ | ||
- [ ] `fcl.decode(response)` _(WIP)_ | ||
- [ ] Configure `fcl.decode` _(WIP)_ | ||
- [ ] Custom qualified decoders _(WIP)_ | ||
- [ ] Custom unqualified decoders _(WIP)_ | ||
- [ ] `fcl.currentUser().param(key)` _(Pending Dep Update)_ | ||
- [x] `fcl.currentUser().info()` | ||
- [ ] `fcl.transaction(transactionId)` _(not started)_ | ||
- [ ] `fcl.transaction(transactionId).snapshot()` _(not started)_ | ||
- [ ] `fcl.transaction(transactionId).subscribe(callback)` _(not started)_ | ||
- [ ] `fcl.transaction(transactionId).onceSealed()` _(not started)_ | ||
- [ ] `fcl.events(...)` _(not_started)_ | ||
- [ ] `fcl.events(...).subscribe(callback)` _(not started)_ | ||
- [x] [`fcl.send(builders)`](./src/send) | ||
- [x] Configure `fcl.send` | ||
- [x] [`fcl.decode(response)`](./src/decode) | ||
- [x] Configure `fcl.decode` | ||
- [x] Custom unqualified decoders | ||
- [ ] Custom qualified decoders _(Not MVP)_ | ||
- [ ] [`fcl.user(addr)`](./src/user) _(blocked)_ | ||
- [ ] `fcl.user(addr).snapshot()` _(blocked)_ | ||
- [ ] `fcl.user(addr).subscribe(callback)` _(blocked)_ | ||
- [ ] `fcl.user(addr).authorization` _(blocked)_ | ||
- [ ] `fcl.user(addr).param(key)` _(blocked)_ | ||
- [ ] `fcl.user(addr).info()` _(blocked)_ | ||
@@ -68,4 +79,3 @@ # Usage | ||
fcl.config() | ||
.put("challenge.scope", "email+publicKey") | ||
fcl.config().put("challenge.scope", "email") | ||
@@ -78,14 +88,20 @@ export const Profile = () => { | ||
return !user.loggedIn | ||
? <div> | ||
<button onClick={fcl.authenticate}>Sign In</button> | ||
<button onClick={fcl.authenticate}>Sign Up</button> | ||
return !user.loggedIn ? ( | ||
<div> | ||
<button onClick={fcl.authenticate}>Sign In</button> | ||
<button onClick={fcl.authenticate}>Sign Up</button> | ||
</div> | ||
) : ( | ||
<div> | ||
<div> | ||
<img | ||
src={user.avatar || "http://placekitten.com/g/100/100"} | ||
width="100" | ||
height="100" | ||
/> | ||
{user.name || "Anonymous"} | ||
</div> | ||
: <div> | ||
<div> | ||
<img src={user.avatar || "http://placekitten.com/g/100/100"} width="100" height="100"/> | ||
{user.name || "Anonymous"} | ||
</div> | ||
<button onClick={fcl.unauthenticate}>Sign Out</button> | ||
</div> | ||
<button onClick={fcl.unauthenticate}>Sign Out</button> | ||
</div> | ||
) | ||
} | ||
@@ -102,16 +118,10 @@ ``` | ||
fcl.config() | ||
.put("send.node", "https://accessNodeUrl") | ||
fcl.config().put("send.node", "https://accessNodeUrl") | ||
const response = await fcl.send([ | ||
sdk.transaction(six.SEND_FLOW_TOKENS), | ||
sdk.params([ | ||
fcl.user(toAddress).param(), | ||
sdk.param(amount, t.UFix64), | ||
]), | ||
sdk.params([fcl.user(toAddress).param(), sdk.param(amount, t.UFix64)]), | ||
sdk.payer(fcl.currentUser().payerAuthorization), | ||
sdk.proposer(fcl.currentUser().proposerAuthorization), | ||
sdk.authorizations([ | ||
fcl.currentUser().authorization | ||
]), | ||
sdk.authorizations([fcl.currentUser().authorization]), | ||
]) | ||
@@ -132,4 +142,3 @@ | ||
fcl.config() | ||
.put("decoder.SomeNFT", d => new SomeToken(d)) | ||
fcl.config().put("decoder.SomeNFT", d => new SomeToken(d)) | ||
@@ -146,5 +155,3 @@ // query for onchain nfts | ||
`, | ||
sdk.params([ | ||
fcl.currentUser().param() | ||
]) | ||
sdk.params([fcl.currentUser().param()]), | ||
]) | ||
@@ -151,0 +158,0 @@ |
@@ -13,97 +13,100 @@ import {spawn, send} from "../actor" | ||
const snapshot = (ctx, keys = []) => | ||
keys.reduce((acc, key) => ({...acc, [key]: ctx.get(key)}), {}) | ||
const identity = v => v | ||
const HANDLERS = { | ||
[PUT]: (ctx, _letter, {key, value}) => { | ||
if (key == null) throw new Error("Missing 'key' for config/put.") | ||
ctx.put(key, value) | ||
ctx.broadcast(UPDATED, snapshot(ctx, ctx.keys())) | ||
}, | ||
[GET]: (ctx, letter, {key, fallback}) => { | ||
if (key == null) throw new Error("Missing 'key' for config/get") | ||
letter.reply(ctx.get(key, fallback)) | ||
}, | ||
[UPDATE]: (ctx, letter, {key, fn}) => { | ||
if (key == null) throw new Error("Missing 'key' for config/update") | ||
ctx.update(key, fn || identity) | ||
ctx.broadcast(UPDATED, snapshot(ctx, ctx.keys())) | ||
}, | ||
[DELETE]: (ctx, letter, {key}) => { | ||
if (key == null) throw new Error("Missing 'key' for config/delete") | ||
ctx.delete(key) | ||
ctx.broadcast(UPDATED, snapshot(ctx, ctx.keys())) | ||
}, | ||
[WHERE]: (ctx, letter, {pattern}) => { | ||
if (pattern == null) throw new Error("Missing 'pattern' for config/where") | ||
letter.reply( | ||
snapshot( | ||
ctx, | ||
ctx.keys().filter(d => pattern.test(d)) | ||
) | ||
) | ||
}, | ||
[SUBSCRIBE]: (ctx, letter) => { | ||
ctx.subscribe(letter.from) | ||
ctx.send(letter.from, UPDATED, snapshot(ctx.keys())) | ||
}, | ||
[UNSUBSCRIBE]: (ctx, letter) => { | ||
ctx.unsubscribe(letter.from) | ||
}, | ||
} | ||
spawn(async ctx => { | ||
const snapshot = keys => | ||
keys.reduce((acc, key) => ({...acc, [key]: ctx.get(key)}), {}) | ||
__loop: while (1) { | ||
const letter = await ctx.receive() | ||
const data = letter.data | ||
try { | ||
switch (letter.tag) { | ||
case PUT: | ||
if (data.key != null) { | ||
ctx.put(data.key, data.value) | ||
ctx.broadcast(UPDATED, snapshot(ctx.keys())) | ||
} | ||
continue __loop | ||
await HANDLERS[letter.tag](ctx, letter, letter.data || {}) | ||
} catch (error) { | ||
console.error("User Error", letter, error) | ||
} finally { | ||
continue __loop | ||
} | ||
} | ||
}, NAME) | ||
case GET: | ||
if (data.key != null) { | ||
letter.reply(ctx.get(data.key, data.fallback)) | ||
} | ||
continue __loop | ||
function put(key, value) { | ||
send(NAME, PUT, {key, value}) | ||
return config() | ||
} | ||
case UPDATE: | ||
if (data.key != null) { | ||
ctx.update(data.key, data.fn) | ||
ctx.broadcast(UPDATED, snapshot(ctx.keys())) | ||
} | ||
continue __loop | ||
function get(key, fallback) { | ||
return send(NAME, GET, {key, fallback}, {expectReply: true, timeout: 10}) | ||
} | ||
case DELETE: | ||
if (data.key != null) { | ||
ctx.delete(data.key) | ||
ctx.broadcast(UPDATED, snapshot(ctx.keys())) | ||
} | ||
continue __loop | ||
function update(key, fn = identity) { | ||
send(NAME, UPDATE, {key, fn}) | ||
return config() | ||
} | ||
case WHERE: | ||
if (data.pattern != null) { | ||
letter.reply(snapshot(ctx.keys().filter(d => data.pattern.test(d)))) | ||
} | ||
continue __loop | ||
function _delete(key) { | ||
send(NAME, DELETE, {key}) | ||
return config() | ||
} | ||
case SUBSCRIBE: | ||
ctx.subscribe(letter.from) | ||
ctx.send(letter.from, UPDATED, snapshot(ctx.keys())) | ||
continue __loop | ||
function where(pattern) { | ||
return send(NAME, WHERE, {pattern}, {expectReply: true, timeout: 10}) | ||
} | ||
case UNSUBSCRIBE: | ||
ctx.unsubscribe(letter.from) | ||
continue __loop | ||
default: | ||
continue __loop | ||
function subscribe(callback) { | ||
const EXIT = "@EXIT" | ||
const self = spawn(async ctx => { | ||
ctx.send(NAME, SUBSCRIBE) | ||
while (1) { | ||
const letter = await ctx.receive() | ||
if (letter.tag === EXIT) { | ||
ctx.send(NAME, UNSUBSCRIBE) | ||
return | ||
} | ||
} catch (error) { | ||
console.error("Config Error", letter, error) | ||
continue __loop | ||
callback(letter.data) | ||
} | ||
} | ||
}, NAME) | ||
}) | ||
return () => send(self, EXIT) | ||
} | ||
const identity = v => v | ||
export const config = () => ({ | ||
put(key, value) { | ||
send(NAME, PUT, {key, value}) | ||
}, | ||
get(key, fallback) { | ||
return send(NAME, GET, {key, fallback}, {expectReply: true, timeout: 10}) | ||
}, | ||
update(key, fn = identity) { | ||
send(NAME, UPDATE, {key, fn}) | ||
}, | ||
delete(key) { | ||
send(NAME, DELETE, {key}) | ||
}, | ||
where(pattern) { | ||
return send(NAME, WHERE, {pattern}, {expectReply: true, timeout: 10}) | ||
}, | ||
subscribe(callback) { | ||
const EXIT = "@EXIT" | ||
const self = spawn(async ctx => { | ||
ctx.send(NAME, SUBSCRIBE) | ||
while (1) { | ||
const letter = await ctx.receive() | ||
if (letter.tag === EXIT) { | ||
ctx.send(NAME, UNSUBSCRIBE) | ||
return | ||
} | ||
callback(letter.data) | ||
} | ||
}) | ||
return () => send(self, EXIT) | ||
}, | ||
}) | ||
export function config() { | ||
return {put, get, update, delete: _delete, where, subscribe} | ||
} |
@@ -6,29 +6,31 @@ import {config} from "./" | ||
describe("config", () => { | ||
const $ = config() | ||
$.put("config.test.t", "t") | ||
$.put("config.test.z", "z") | ||
$.put("config.test.foo.bar", "bar") | ||
$.put("config.test.foo.baz", "baz") | ||
$.put("config.test.wat.bar", "foo") | ||
config() | ||
.put("config.test.t", "t") | ||
.put("config.test.z", "z") | ||
.put("config.test.foo.bar", "bar") | ||
.put("config.test.foo.baz", "baz") | ||
.put("config.test.wat.bar", "foo") | ||
test("get", async () => { | ||
expect(await $.get("config.test.foo.bar")).toBe("bar") | ||
expect(await config().get("config.test.foo.bar")).toBe("bar") | ||
}) | ||
test("get with fallback", async () => { | ||
expect(await $.get("config.test.not.a.thing", "fallback")).toBe("fallback") | ||
expect(await config().get("config.test.not.a.thing", "fallback")).toBe( | ||
"fallback" | ||
) | ||
}) | ||
test("update", async () => { | ||
$.update("config.test.t", v => v + v) | ||
expect(await $.get("config.test.t")).toBe("tt") | ||
config().update("config.test.t", v => v + v) | ||
expect(await config().get("config.test.t")).toBe("tt") | ||
}) | ||
test("delete", async () => { | ||
$.delete("config.test.z") | ||
expect(await $.get("config.test.z")).toBe(undefined) | ||
config().delete("config.test.z") | ||
expect(await config().get("config.test.z")).toBe(undefined) | ||
}) | ||
test("where", async () => { | ||
expect(await $.where(/^config.test.foo/)).toEqual({ | ||
expect(await config().where(/^config.test.foo/)).toEqual({ | ||
"config.test.foo.bar": "bar", | ||
@@ -41,7 +43,8 @@ "config.test.foo.baz": "baz", | ||
const fn1 = jest.fn() | ||
const unsub = $.subscribe(fn1) | ||
const unsub = config().subscribe(fn1) | ||
await idle() | ||
$.put("config.test.y", "y") | ||
$.put("config.test.x", "x") | ||
config() | ||
.put("config.test.y", "y") | ||
.put("config.test.x", "x") | ||
@@ -52,3 +55,3 @@ await idle() | ||
$.update("config.test.y", v => v + v) | ||
config().update("config.test.y", v => v + v) | ||
@@ -55,0 +58,0 @@ await idle() |
import {config} from "./config" | ||
const $ = config() | ||
$.put("accessNode.api", "http://localhost:8080") | ||
config() | ||
.put("accessNode.api", "http://localhost:8080") | ||
.put("challenge.handshake", "http://localhost:8700/authenticate") |
import "./default-config" | ||
export {config} from "./config" | ||
export {send} from "./send" | ||
export {user} from "./user" | ||
export {decode} from "./decode" | ||
export const authenticate = async () => {} | ||
export const unauthenticate = async () => {} | ||
import {currentUser} from "./current-user" | ||
export {currentUser} | ||
export const currentUser = () => { | ||
return { | ||
subscribe: callback => { | ||
return function unsubscribe() {} | ||
}, | ||
export const authenticate = () => currentUser().authenticate() | ||
export const unauthenticate = () => currentUser().unauthenticate() | ||
authorization: async () => {}, | ||
payerAuthorization: async () => {}, | ||
param: async () => {}, | ||
} | ||
} | ||
export const transaction = txId => { | ||
return { | ||
subscribe: callback => { | ||
return function unsubscribe() {} | ||
}, | ||
} | ||
} | ||
export const event = (eventType, start) => { | ||
return { | ||
subscribe: callback => { | ||
return function unsubscribe() {} | ||
}, | ||
} | ||
} | ||
export const decode = async _respones => {} | ||
// proxy sdk | ||
export {isOk, isBad, why} from "@onflow/sdk" | ||
export { | ||
transaction, | ||
script, | ||
ping, | ||
getAccount, | ||
getEvents, | ||
getLatestBlock, | ||
getTransactionStatus, | ||
} from "@onflow/sdk" | ||
export { | ||
authorizations, | ||
authorization, | ||
params, | ||
param, | ||
proposer, | ||
payer, | ||
limit, | ||
ref, | ||
} from "@onflow/sdk" |
@@ -1,17 +0,23 @@ | ||
import * as sdk from "@onflow/sdk" | ||
import { | ||
resolve, | ||
resolveParams, | ||
resolveAccounts, | ||
resolveSignatures, | ||
build, | ||
send as sdkSend, | ||
} from "@onflow/sdk" | ||
import {config} from "../config" | ||
export const send = async (args = [], opts = {}) => { | ||
opts.node = opts.node || await config().get("accessNode.api") | ||
opts.node = opts.node || (await config().get("accessNode.api")) | ||
if (Array.isArray(args)) args = sdk.build(args) | ||
if (Array.isArray(args)) args = build(args) | ||
const ix = await sdk.pipe(args, [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
const ix = await resolve(args, [ | ||
resolveParams, | ||
resolveAccounts, | ||
resolveSignatures, | ||
]) | ||
return sdk.send(ix, opts) | ||
return sdkSend(ix, opts) | ||
} |
@@ -0,3 +1,6 @@ | ||
import "../default-config" | ||
import {spawn, send} from "../actor" | ||
import {genUser} from "./__factories__/gen-user" | ||
import {send as fclSend} from "../send" | ||
import * as sdk from "@onflow/sdk" | ||
@@ -49,7 +52,7 @@ const SUBSCRIBE = "SUBSCRIBE" | ||
const spawnUser = acct => spawn(userLogic, acct) | ||
const spawnUser = addr => spawn(userLogic, addr) | ||
export const user = acct => ({ | ||
export const user = addr => ({ | ||
async authorization() { | ||
spawnUser(acct) | ||
spawnUser(addr) | ||
@@ -60,10 +63,10 @@ const signFn = async () => { | ||
throw new Error( | ||
`fcl.user(${acct}).payerAuthorization WIP error -- known missing functionality` | ||
`fcl.user(${addr}).payerAuthorization WIP error -- known missing functionality` | ||
) | ||
} | ||
return {acct, signFn} | ||
return {addr, signFn} | ||
}, | ||
async payerAuthorization() { | ||
spawnUser(acct) | ||
spawnUser(addr) | ||
@@ -74,11 +77,11 @@ const signFn = async () => { | ||
throw new Error( | ||
`fcl.user(${acct}).payerAuthorization WIP error -- known missing functionality` | ||
`fcl.user(${addr}).payerAuthorization WIP error -- known missing functionality` | ||
) | ||
} | ||
return {acct, signFn} | ||
return {addr, signFn} | ||
}, | ||
async snapshot() { | ||
spawnUser(acct) | ||
return send(acct, SNAPSHOT, null, {expectReply: true, timeout: 0}) | ||
spawnUser(addr) | ||
return send(addr, SNAPSHOT, null, {expectReply: true, timeout: 0}) | ||
}, | ||
@@ -88,3 +91,3 @@ | ||
return { | ||
value: acct, | ||
value: addr, | ||
xform: { | ||
@@ -98,10 +101,10 @@ asParam: v => v, | ||
subscribe(callback) { | ||
spawnUser(acct) | ||
spawnUser(addr) | ||
const EXIT = "@EXIT" | ||
const self = spawn(async ctx => { | ||
ctx.send(acct, SUBSCRIBE) | ||
ctx.send(addr, SUBSCRIBE) | ||
while (1) { | ||
const letter = await ctx.receive() | ||
if (letter.tag === EXIT) { | ||
ctx.send(acct, UNSUBSCRIBE) | ||
ctx.send(addr, UNSUBSCRIBE) | ||
return | ||
@@ -114,2 +117,7 @@ } | ||
}, | ||
async info() { | ||
const {account} = await fclSend([sdk.getAccount(addr)]) | ||
return account | ||
}, | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
313249
34
1202
154
3
11
+ Added@onflow/types@0.0.1
+ Added@onflow/decode@0.0.6(transitive)
+ Added@onflow/interaction@0.0.7(transitive)
+ Added@onflow/sdk@0.0.17(transitive)
+ Added@onflow/send@0.0.10(transitive)
+ Added@onflow/types@0.0.1(transitive)
+ Addedqueue-microtask@1.1.2(transitive)
- Removed@onflow/decode@0.0.5(transitive)
- Removed@onflow/interaction@0.0.5(transitive)
- Removed@onflow/sdk@0.0.14(transitive)
- Removed@onflow/send@0.0.8(transitive)
- Removedqueue-microtask@1.2.3(transitive)
Updated@onflow/sdk@0.0.17
Updatedqueue-microtask@1.1.2