@magic-sdk/react-native-expo 30.0.4-canary.870.14203885986.0 → 30.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var Te=Object.create;var D=Object.defineProperty,Ne=Object.defineProperties,De=Object.getOwnPropertyDescriptor,Ce=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertyNames,pe=Object.getOwnPropertySymbols,Ge=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var me=(n,a,o)=>a in n?D(n,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[a]=o,oe=(n,a)=>{for(var o in a||(a={}))ve.call(a,o)&&me(n,o,a[o]);if(pe)for(var o of pe(a))ke.call(a,o)&&me(n,o,a[o]);return n},ie=(n,a)=>Ne(n,Ce(a));var We=(n,a)=>()=>(a||n((a={exports:{}}).exports,a),a.exports),je=(n,a)=>{for(var o in a)D(n,o,{get:a[o],enumerable:!0})},F=(n,a,o,h)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Ve(a))!ve.call(n,c)&&c!==o&&D(n,c,{get:()=>a[c],enumerable:!(h=De(a,c))||h.enumerable});return n},l=(n,a,o)=>(F(n,a,"default"),o&&F(o,a,"default")),I=(n,a,o)=>(o=n!=null?Te(Ge(n)):{},F(a||!n||!n.__esModule?D(o,"default",{value:n,enumerable:!0}):o,n)),Fe=n=>F(D({},"__esModule",{value:!0}),n);var M=(n,a,o)=>new Promise((h,c)=>{var d=S=>{try{L(o.next(S))}catch(v){c(v)}},p=S=>{try{L(o.throw(S))}catch(v){c(v)}},L=S=>S.done?h(S.value):Promise.resolve(S.value).then(d,p);L((o=o.apply(n,a)).next())});var de=We((xe,se)=>{var ae=function(n){"use strict";var a=Object.prototype,o=a.hasOwnProperty,h=Object.defineProperty||function(t,e,r){t[e]=r.value},c,d=typeof Symbol=="function"?Symbol:{},p=d.iterator||"@@iterator",L=d.asyncIterator||"@@asyncIterator",S=d.toStringTag||"@@toStringTag";function v(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{v({},"")}catch{v=function(e,r,s){return e[r]=s}}function V(t,e,r,s){var i=e&&e.prototype instanceof X?e:X,u=Object.create(i.prototype),g=new te(s||[]);return h(u,"_invoke",{value:Me(t,r,g)}),u}n.wrap=V;function P(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(s){return{type:"throw",arg:s}}}var G="suspendedStart",H="suspendedYield",y="executing",T="completed",E={};function X(){}function k(){}function O(){}var Q={};v(Q,p,function(){return this});var Z=Object.getPrototypeOf,W=Z&&Z(Z(re([])));W&&W!==a&&o.call(W,p)&&(Q=W);var A=O.prototype=X.prototype=Object.create(Q);k.prototype=O,h(A,"constructor",{value:O,configurable:!0}),h(O,"constructor",{value:k,configurable:!0}),k.displayName=v(O,S,"GeneratorFunction");function fe(t){["next","throw","return"].forEach(function(e){v(t,e,function(r){return this._invoke(e,r)})})}n.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===k||(e.displayName||e.name)==="GeneratorFunction":!1},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,O):(t.__proto__=O,v(t,S,"GeneratorFunction")),t.prototype=Object.create(A),t},n.awrap=function(t){return{__await:t}};function j(t,e){function r(u,g,w,_){var b=P(t[u],t,g);if(b.type==="throw")_(b.arg);else{var ne=b.arg,N=ne.value;return N&&typeof N=="object"&&o.call(N,"__await")?e.resolve(N.__await).then(function(R){r("next",R,w,_)},function(R){r("throw",R,w,_)}):e.resolve(N).then(function(R){ne.value=R,w(ne)},function(R){return r("throw",R,w,_)})}}var s;function i(u,g){function w(){return new e(function(_,b){r(u,g,_,b)})}return s=s?s.then(w,w):w()}h(this,"_invoke",{value:i})}fe(j.prototype),v(j.prototype,L,function(){return this}),n.AsyncIterator=j,n.async=function(t,e,r,s,i){i===void 0&&(i=Promise);var u=new j(V(t,e,r,s),i);return n.isGeneratorFunction(e)?u:u.next().then(function(g){return g.done?g.value:u.next()})};function Me(t,e,r){var s=G;return function(u,g){if(s===y)throw new Error("Generator is already running");if(s===T){if(u==="throw")throw g;return he()}for(r.method=u,r.arg=g;;){var w=r.delegate;if(w){var _=le(w,r);if(_){if(_===E)continue;return _}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(s===G)throw s=T,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);s=y;var b=P(t,e,r);if(b.type==="normal"){if(s=r.done?T:H,b.arg===E)continue;return{value:b.arg,done:r.done}}else b.type==="throw"&&(s=T,r.method="throw",r.arg=b.arg)}}}function le(t,e){var r=e.method,s=t.iterator[r];if(s===c)return e.delegate=null,r==="throw"&&t.iterator.return&&(e.method="return",e.arg=c,le(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),E;var i=P(s,t.iterator,e.arg);if(i.type==="throw")return e.method="throw",e.arg=i.arg,e.delegate=null,E;var u=i.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,E;if(u.done)e[t.resultName]=u.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return u;return e.delegate=null,E}fe(A),v(A,S,"Generator"),v(A,p,function(){return this}),v(A,"toString",function(){return"[object Generator]"});function Pe(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function ee(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function te(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Pe,this),this.reset(!0)}n.keys=function(t){var e=Object(t),r=[];for(var s in e)r.push(s);return r.reverse(),function i(){for(;r.length;){var u=r.pop();if(u in e)return i.value=u,i.done=!1,i}return i.done=!0,i}};function re(t){if(t){var e=t[p];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,s=function i(){for(;++r<t.length;)if(o.call(t,r))return i.value=t[r],i.done=!1,i;return i.value=c,i.done=!0,i};return s.next=s}}return{next:he}}n.values=re;function he(){return{value:c,done:!0}}return te.prototype={constructor:te,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(ee),!t)for(var e in this)e.charAt(0)==="t"&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0],e=t.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(_,b){return u.type="throw",u.arg=t,e.next=_,b&&(e.method="next",e.arg=c),!!b}for(var s=this.tryEntries.length-1;s>=0;--s){var i=this.tryEntries[s],u=i.completion;if(i.tryLoc==="root")return r("end");if(i.tryLoc<=this.prev){var g=o.call(i,"catchLoc"),w=o.call(i,"finallyLoc");if(g&&w){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(g){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else if(w){if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var s=this.tryEntries[r];if(s.tryLoc<=this.prev&&o.call(s,"finallyLoc")&&this.prev<s.finallyLoc){var i=s;break}}i&&(t==="break"||t==="continue")&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,E):this.complete(u)},complete:function(t,e){if(t.type==="throw")throw t.arg;return t.type==="break"||t.type==="continue"?this.next=t.arg:t.type==="return"?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):t.type==="normal"&&e&&(this.next=e),E},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),ee(r),E}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var s=r.completion;if(s.type==="throw"){var i=s.arg;ee(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:re(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),E}},n}(typeof se=="object"?se.exports:{});try{regeneratorRuntime=ae}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=ae:Function("r","regeneratorRuntime = r")(ae)}});var f={};je(f,{Magic:()=>$e,useInternetConnection:()=>B});module.exports=Fe(f);var et=I(de()),Le=require("@magic-sdk/provider"),Ke=I(require("process")),Ie=I(require("localforage")),z=require("whatwg-url"),J=require("buffer"),Oe=I(require("lodash")),Re=I(require("expo-application")),Ae=require("@aveq-research/localforage-asyncstorage-driver"),ue=I(require("localforage-driver-memory"));var m=I(require("react")),$=require("react-native"),be=require("react-native-webview"),Se=require("react-native-safe-area-context"),q=require("@magic-sdk/provider"),Ee=require("lodash"),C=I(require("@react-native-async-storage/async-storage")),ce=require("react-native-event-listeners");var U=require("react"),ye=I(require("@react-native-community/netinfo")),B=()=>{let[n,a]=(0,U.useState)(!0);return(0,U.useEffect)(()=>{let o=h=>{a(!!h.isConnected)};return ye.default.addEventListener(o)},[]),n};var ge="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Ue="open_in_device_browser",Be="#FFFFFF",we="msg_posted_after_inactivity_event",Y="lastMessageTime";function Ye(){return $.StyleSheet.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var K=class extends q.ViewController{constructor(){super(...arguments);this.Relayer=o=>{let[h,c]=(0,m.useState)(!1),[d,p]=(0,m.useState)(!0),L=B();(0,m.useEffect)(()=>{this.isConnectedToInternet=L},[L]),(0,m.useEffect)(()=>(C.default.setItem(Y,""),()=>{this.isReadyForRequest=!1}),[]),(0,m.useEffect)(()=>{ce.EventRegister.addEventListener(we,y=>M(this,null,function*(){this.isReadyForRequest=!1,p(!1),this.post(y.msgType,y.payload),yield C.default.setItem(Y,new Date().toISOString())}))},[]),(0,m.useEffect)(()=>{d||setTimeout(()=>p(!0),10)},[d]);let S=(0,m.useCallback)(y=>{this.webView=y},[]),v=(0,m.useCallback)(y=>{this.container=ie(oe({},y),{showOverlay:V,hideOverlay:P})},[]),V=(0,m.useCallback)(()=>{c(!0)},[]),P=(0,m.useCallback)(()=>{c(!1)},[]),G=(0,m.useMemo)(()=>[this.styles["webview-container"],h?ie(oe({},this.styles.show),{backgroundColor:o!=null?o:Be}):this.styles.hide],[h]),H=(0,m.useCallback)(y=>{this.handleReactNativeWebViewMessage(y)},[]);return d?m.default.createElement(Se.SafeAreaView,{ref:v,style:G},m.default.createElement(be.WebView,{ref:S,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:H,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:y=>new URLSearchParams(y.url.split("?")[1]).get(Ue)?($.Linking.openURL(y.url),!1):!0})):null}}init(){this.webView=null,this.container=null,this.styles=Ye()}handleReactNativeWebViewMessage(o){var h;if(o.nativeEvent&&typeof o.nativeEvent.data=="string"&&(o.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||o.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(o.nativeEvent.data,(d,p)=>{try{if(p&&typeof p=="object"&&p.flag&&p.flag===ge)return new global[p.constructor](p.data.split(","))}catch(L){}return p});if(c&&c.msgType&&this.messageHandlers.size){c.response=(h=c.response)!=null?h:{};let d={data:c};for(let p of this.messageHandlers.values())p(d)}}}msgPostedAfterInactivity(){return M(this,null,function*(){let o=yield C.default.getItem(Y);if(o){let h=new Date(o).getTime(),c=new Date().getTime(),d=5*60*1e3;return c-h>d}return!1})}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(o){return M(this,null,function*(){if(yield this.msgPostedAfterInactivity()){ce.EventRegister.emit(we,o);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(o,(h,c)=>(0,Ee.isTypedArray)(c)?{constructor:c.constructor.name,data:c.toString(),flag:ge}:c),this.endpoint),C.default.setItem(Y,new Date().toISOString());else throw(0,q.createModalNotReadyError)()})}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var _e=require("@magic-sdk/provider"),x=class extends _e.SDKBase{get Relayer(){return this.overlay.Relayer}};l(f,require("@magic-sdk/commons"),module.exports);global.process=Oe.merge(global.process,Ke);global.process.browser=!1;global.Buffer=J.Buffer;global.URL=z.URL;global.URLSearchParams=z.URLSearchParams;global.btoa=n=>J.Buffer.from(n,"binary").toString("base64");global.atob=n=>J.Buffer.from(n,"base64").toString("binary");var $e=(0,Le.createSDK)(x,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.3",bundleId:Re.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:K,configureStorage:()=>M(void 0,null,function*(){let n=Ie.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),a=(0,Ae.driverWithoutSerialization)();return yield Promise.all([n.defineDriver(a),n.defineDriver(ue)]),yield n.setDriver([a._driver,ue._driver]),n})});0&&(module.exports={Magic,useInternetConnection});
1
+ "use strict";var Te=Object.create;var D=Object.defineProperty,Ne=Object.defineProperties,De=Object.getOwnPropertyDescriptor,Ce=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertyNames,pe=Object.getOwnPropertySymbols,Ge=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var me=(n,a,o)=>a in n?D(n,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[a]=o,oe=(n,a)=>{for(var o in a||(a={}))ve.call(a,o)&&me(n,o,a[o]);if(pe)for(var o of pe(a))ke.call(a,o)&&me(n,o,a[o]);return n},ie=(n,a)=>Ne(n,Ce(a));var We=(n,a)=>()=>(a||n((a={exports:{}}).exports,a),a.exports),je=(n,a)=>{for(var o in a)D(n,o,{get:a[o],enumerable:!0})},F=(n,a,o,h)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Ve(a))!ve.call(n,c)&&c!==o&&D(n,c,{get:()=>a[c],enumerable:!(h=De(a,c))||h.enumerable});return n},l=(n,a,o)=>(F(n,a,"default"),o&&F(o,a,"default")),I=(n,a,o)=>(o=n!=null?Te(Ge(n)):{},F(a||!n||!n.__esModule?D(o,"default",{value:n,enumerable:!0}):o,n)),Fe=n=>F(D({},"__esModule",{value:!0}),n);var M=(n,a,o)=>new Promise((h,c)=>{var d=S=>{try{L(o.next(S))}catch(v){c(v)}},p=S=>{try{L(o.throw(S))}catch(v){c(v)}},L=S=>S.done?h(S.value):Promise.resolve(S.value).then(d,p);L((o=o.apply(n,a)).next())});var de=We((xe,se)=>{var ae=function(n){"use strict";var a=Object.prototype,o=a.hasOwnProperty,h=Object.defineProperty||function(t,e,r){t[e]=r.value},c,d=typeof Symbol=="function"?Symbol:{},p=d.iterator||"@@iterator",L=d.asyncIterator||"@@asyncIterator",S=d.toStringTag||"@@toStringTag";function v(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{v({},"")}catch{v=function(e,r,s){return e[r]=s}}function V(t,e,r,s){var i=e&&e.prototype instanceof X?e:X,u=Object.create(i.prototype),g=new te(s||[]);return h(u,"_invoke",{value:Me(t,r,g)}),u}n.wrap=V;function P(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(s){return{type:"throw",arg:s}}}var G="suspendedStart",H="suspendedYield",y="executing",T="completed",E={};function X(){}function k(){}function O(){}var Q={};v(Q,p,function(){return this});var Z=Object.getPrototypeOf,W=Z&&Z(Z(re([])));W&&W!==a&&o.call(W,p)&&(Q=W);var A=O.prototype=X.prototype=Object.create(Q);k.prototype=O,h(A,"constructor",{value:O,configurable:!0}),h(O,"constructor",{value:k,configurable:!0}),k.displayName=v(O,S,"GeneratorFunction");function fe(t){["next","throw","return"].forEach(function(e){v(t,e,function(r){return this._invoke(e,r)})})}n.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===k||(e.displayName||e.name)==="GeneratorFunction":!1},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,O):(t.__proto__=O,v(t,S,"GeneratorFunction")),t.prototype=Object.create(A),t},n.awrap=function(t){return{__await:t}};function j(t,e){function r(u,g,w,_){var b=P(t[u],t,g);if(b.type==="throw")_(b.arg);else{var ne=b.arg,N=ne.value;return N&&typeof N=="object"&&o.call(N,"__await")?e.resolve(N.__await).then(function(R){r("next",R,w,_)},function(R){r("throw",R,w,_)}):e.resolve(N).then(function(R){ne.value=R,w(ne)},function(R){return r("throw",R,w,_)})}}var s;function i(u,g){function w(){return new e(function(_,b){r(u,g,_,b)})}return s=s?s.then(w,w):w()}h(this,"_invoke",{value:i})}fe(j.prototype),v(j.prototype,L,function(){return this}),n.AsyncIterator=j,n.async=function(t,e,r,s,i){i===void 0&&(i=Promise);var u=new j(V(t,e,r,s),i);return n.isGeneratorFunction(e)?u:u.next().then(function(g){return g.done?g.value:u.next()})};function Me(t,e,r){var s=G;return function(u,g){if(s===y)throw new Error("Generator is already running");if(s===T){if(u==="throw")throw g;return he()}for(r.method=u,r.arg=g;;){var w=r.delegate;if(w){var _=le(w,r);if(_){if(_===E)continue;return _}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(s===G)throw s=T,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);s=y;var b=P(t,e,r);if(b.type==="normal"){if(s=r.done?T:H,b.arg===E)continue;return{value:b.arg,done:r.done}}else b.type==="throw"&&(s=T,r.method="throw",r.arg=b.arg)}}}function le(t,e){var r=e.method,s=t.iterator[r];if(s===c)return e.delegate=null,r==="throw"&&t.iterator.return&&(e.method="return",e.arg=c,le(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),E;var i=P(s,t.iterator,e.arg);if(i.type==="throw")return e.method="throw",e.arg=i.arg,e.delegate=null,E;var u=i.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,E;if(u.done)e[t.resultName]=u.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return u;return e.delegate=null,E}fe(A),v(A,S,"Generator"),v(A,p,function(){return this}),v(A,"toString",function(){return"[object Generator]"});function Pe(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function ee(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function te(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Pe,this),this.reset(!0)}n.keys=function(t){var e=Object(t),r=[];for(var s in e)r.push(s);return r.reverse(),function i(){for(;r.length;){var u=r.pop();if(u in e)return i.value=u,i.done=!1,i}return i.done=!0,i}};function re(t){if(t){var e=t[p];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,s=function i(){for(;++r<t.length;)if(o.call(t,r))return i.value=t[r],i.done=!1,i;return i.value=c,i.done=!0,i};return s.next=s}}return{next:he}}n.values=re;function he(){return{value:c,done:!0}}return te.prototype={constructor:te,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(ee),!t)for(var e in this)e.charAt(0)==="t"&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0],e=t.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(_,b){return u.type="throw",u.arg=t,e.next=_,b&&(e.method="next",e.arg=c),!!b}for(var s=this.tryEntries.length-1;s>=0;--s){var i=this.tryEntries[s],u=i.completion;if(i.tryLoc==="root")return r("end");if(i.tryLoc<=this.prev){var g=o.call(i,"catchLoc"),w=o.call(i,"finallyLoc");if(g&&w){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(g){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else if(w){if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var s=this.tryEntries[r];if(s.tryLoc<=this.prev&&o.call(s,"finallyLoc")&&this.prev<s.finallyLoc){var i=s;break}}i&&(t==="break"||t==="continue")&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,E):this.complete(u)},complete:function(t,e){if(t.type==="throw")throw t.arg;return t.type==="break"||t.type==="continue"?this.next=t.arg:t.type==="return"?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):t.type==="normal"&&e&&(this.next=e),E},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),ee(r),E}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var s=r.completion;if(s.type==="throw"){var i=s.arg;ee(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:re(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),E}},n}(typeof se=="object"?se.exports:{});try{regeneratorRuntime=ae}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=ae:Function("r","regeneratorRuntime = r")(ae)}});var f={};je(f,{Magic:()=>$e,useInternetConnection:()=>B});module.exports=Fe(f);var et=I(de()),Le=require("@magic-sdk/provider"),Ke=I(require("process")),Ie=I(require("localforage")),z=require("whatwg-url"),J=require("buffer"),Oe=I(require("lodash")),Re=I(require("expo-application")),Ae=require("@aveq-research/localforage-asyncstorage-driver"),ue=I(require("localforage-driver-memory"));var m=I(require("react")),$=require("react-native"),be=require("react-native-webview"),Se=require("react-native-safe-area-context"),q=require("@magic-sdk/provider"),Ee=require("lodash"),C=I(require("@react-native-async-storage/async-storage")),ce=require("react-native-event-listeners");var U=require("react"),ye=I(require("@react-native-community/netinfo")),B=()=>{let[n,a]=(0,U.useState)(!0);return(0,U.useEffect)(()=>{let o=h=>{a(!!h.isConnected)};return ye.default.addEventListener(o)},[]),n};var ge="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Ue="open_in_device_browser",Be="#FFFFFF",we="msg_posted_after_inactivity_event",Y="lastMessageTime";function Ye(){return $.StyleSheet.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var K=class extends q.ViewController{constructor(){super(...arguments);this.Relayer=o=>{let[h,c]=(0,m.useState)(!1),[d,p]=(0,m.useState)(!0),L=B();(0,m.useEffect)(()=>{this.isConnectedToInternet=L},[L]),(0,m.useEffect)(()=>(C.default.setItem(Y,""),()=>{this.isReadyForRequest=!1}),[]),(0,m.useEffect)(()=>{ce.EventRegister.addEventListener(we,y=>M(this,null,function*(){this.isReadyForRequest=!1,p(!1),this.post(y.msgType,y.payload),yield C.default.setItem(Y,new Date().toISOString())}))},[]),(0,m.useEffect)(()=>{d||setTimeout(()=>p(!0),10)},[d]);let S=(0,m.useCallback)(y=>{this.webView=y},[]),v=(0,m.useCallback)(y=>{this.container=ie(oe({},y),{showOverlay:V,hideOverlay:P})},[]),V=(0,m.useCallback)(()=>{c(!0)},[]),P=(0,m.useCallback)(()=>{c(!1)},[]),G=(0,m.useMemo)(()=>[this.styles["webview-container"],h?ie(oe({},this.styles.show),{backgroundColor:o!=null?o:Be}):this.styles.hide],[h]),H=(0,m.useCallback)(y=>{this.handleReactNativeWebViewMessage(y)},[]);return d?m.default.createElement(Se.SafeAreaView,{ref:v,style:G},m.default.createElement(be.WebView,{ref:S,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:H,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:y=>new URLSearchParams(y.url.split("?")[1]).get(Ue)?($.Linking.openURL(y.url),!1):!0})):null}}init(){this.webView=null,this.container=null,this.styles=Ye()}handleReactNativeWebViewMessage(o){var h;if(o.nativeEvent&&typeof o.nativeEvent.data=="string"&&(o.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||o.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(o.nativeEvent.data,(d,p)=>{try{if(p&&typeof p=="object"&&p.flag&&p.flag===ge)return new global[p.constructor](p.data.split(","))}catch(L){}return p});if(c&&c.msgType&&this.messageHandlers.size){c.response=(h=c.response)!=null?h:{};let d={data:c};for(let p of this.messageHandlers.values())p(d)}}}msgPostedAfterInactivity(){return M(this,null,function*(){let o=yield C.default.getItem(Y);if(o){let h=new Date(o).getTime(),c=new Date().getTime(),d=5*60*1e3;return c-h>d}return!1})}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(o){return M(this,null,function*(){if(yield this.msgPostedAfterInactivity()){ce.EventRegister.emit(we,o);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(o,(h,c)=>(0,Ee.isTypedArray)(c)?{constructor:c.constructor.name,data:c.toString(),flag:ge}:c),this.endpoint),C.default.setItem(Y,new Date().toISOString());else throw(0,q.createModalNotReadyError)()})}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var _e=require("@magic-sdk/provider"),x=class extends _e.SDKBase{get Relayer(){return this.overlay.Relayer}};l(f,require("@magic-sdk/commons"),module.exports);global.process=Oe.merge(global.process,Ke);global.process.browser=!1;global.Buffer=J.Buffer;global.URL=z.URL;global.URLSearchParams=z.URLSearchParams;global.btoa=n=>J.Buffer.from(n,"binary").toString("base64");global.atob=n=>J.Buffer.from(n,"base64").toString("binary");var $e=(0,Le.createSDK)(x,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.4",bundleId:Re.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:K,configureStorage:()=>M(void 0,null,function*(){let n=Ie.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),a=(0,Ae.driverWithoutSerialization)();return yield Promise.all([n.defineDriver(a),n.defineDriver(ue)]),yield n.setDriver([a._driver,ue._driver]),n})});0&&(module.exports={Magic,useInternetConnection});
2
2
  //# sourceMappingURL=index.js.map
package/dist/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var ge=Object.create;var z=Object.defineProperty,we=Object.defineProperties,be=Object.getOwnPropertyDescriptor,Se=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var ae=(o,s,i)=>s in o?z(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,J=(o,s)=>{for(var i in s||(s={}))se.call(s,i)&&ae(o,i,s[i]);if(ie)for(var i of ie(s))Le.call(s,i)&&ae(o,i,s[i]);return o},H=(o,s)=>we(o,Se(s));var Ie=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var Oe=(o,s,i,f)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of Ee(s))!se.call(o,c)&&c!==i&&z(o,c,{get:()=>s[c],enumerable:!(f=be(s,c))||f.enumerable});return o};var Re=(o,s,i)=>(i=o!=null?ge(_e(o)):{},Oe(s||!o||!o.__esModule?z(i,"default",{value:o,enumerable:!0}):i,o));var I=(o,s,i)=>new Promise((f,c)=>{var p=g=>{try{S(i.next(g))}catch(h){c(h)}},l=g=>{try{S(i.throw(g))}catch(h){c(h)}},S=g=>g.done?f(g.value):Promise.resolve(g.value).then(p,l);S((i=i.apply(o,s)).next())});var ce=Ie((He,Q)=>{var X=function(o){"use strict";var s=Object.prototype,i=s.hasOwnProperty,f=Object.defineProperty||function(t,e,r){t[e]=r.value},c,p=typeof Symbol=="function"?Symbol:{},l=p.iterator||"@@iterator",S=p.asyncIterator||"@@asyncIterator",g=p.toStringTag||"@@toStringTag";function h(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch{h=function(e,r,a){return e[r]=a}}function P(t,e,r,a){var n=e&&e.prototype instanceof U?e:U,u=Object.create(n.prototype),v=new $(a||[]);return f(u,"_invoke",{value:de(t,r,v)}),u}o.wrap=P;function O(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var T="suspendedStart",F="suspendedYield",m="executing",R="completed",w={};function U(){}function N(){}function E(){}var B={};h(B,l,function(){return this});var Y=Object.getPrototypeOf,D=Y&&Y(Y(q([])));D&&D!==s&&i.call(D,l)&&(B=D);var L=E.prototype=U.prototype=Object.create(B);N.prototype=E,f(L,"constructor",{value:E,configurable:!0}),f(E,"constructor",{value:N,configurable:!0}),N.displayName=h(E,g,"GeneratorFunction");function re(t){["next","throw","return"].forEach(function(e){h(t,e,function(r){return this._invoke(e,r)})})}o.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===N||(e.displayName||e.name)==="GeneratorFunction":!1},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,h(t,g,"GeneratorFunction")),t.prototype=Object.create(L),t},o.awrap=function(t){return{__await:t}};function C(t,e){function r(u,v,d,b){var y=O(t[u],t,v);if(y.type==="throw")b(y.arg);else{var x=y.arg,A=x.value;return A&&typeof A=="object"&&i.call(A,"__await")?e.resolve(A.__await).then(function(_){r("next",_,d,b)},function(_){r("throw",_,d,b)}):e.resolve(A).then(function(_){x.value=_,d(x)},function(_){return r("throw",_,d,b)})}}var a;function n(u,v){function d(){return new e(function(b,y){r(u,v,b,y)})}return a=a?a.then(d,d):d()}f(this,"_invoke",{value:n})}re(C.prototype),h(C.prototype,S,function(){return this}),o.AsyncIterator=C,o.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var u=new C(P(t,e,r,a),n);return o.isGeneratorFunction(e)?u:u.next().then(function(v){return v.done?v.value:u.next()})};function de(t,e,r){var a=T;return function(u,v){if(a===m)throw new Error("Generator is already running");if(a===R){if(u==="throw")throw v;return oe()}for(r.method=u,r.arg=v;;){var d=r.delegate;if(d){var b=ne(d,r);if(b){if(b===w)continue;return b}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(a===T)throw a=R,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=m;var y=O(t,e,r);if(y.type==="normal"){if(a=r.done?R:F,y.arg===w)continue;return{value:y.arg,done:r.done}}else y.type==="throw"&&(a=R,r.method="throw",r.arg=y.arg)}}}function ne(t,e){var r=e.method,a=t.iterator[r];if(a===c)return e.delegate=null,r==="throw"&&t.iterator.return&&(e.method="return",e.arg=c,ne(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),w;var n=O(a,t.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,w;var u=n.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,w;if(u.done)e[t.resultName]=u.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return u;return e.delegate=null,w}re(L),h(L,g,"Generator"),h(L,l,function(){return this}),h(L,"toString",function(){return"[object Generator]"});function ye(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function K(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function $(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(ye,this),this.reset(!0)}o.keys=function(t){var e=Object(t),r=[];for(var a in e)r.push(a);return r.reverse(),function n(){for(;r.length;){var u=r.pop();if(u in e)return n.value=u,n.done=!1,n}return n.done=!0,n}};function q(t){if(t){var e=t[l];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,a=function n(){for(;++r<t.length;)if(i.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=c,n.done=!0,n};return a.next=a}}return{next:oe}}o.values=q;function oe(){return{value:c,done:!0}}return $.prototype={constructor:$,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(K),!t)for(var e in this)e.charAt(0)==="t"&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0],e=t.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(b,y){return u.type="throw",u.arg=t,e.next=b,y&&(e.method="next",e.arg=c),!!y}for(var a=this.tryEntries.length-1;a>=0;--a){var n=this.tryEntries[a],u=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var v=i.call(n,"catchLoc"),d=i.call(n,"finallyLoc");if(v&&d){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(v){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(d){if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&i.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var n=a;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var u=n?n.completion:{};return u.type=t,u.arg=e,n?(this.method="next",this.next=n.finallyLoc,w):this.complete(u)},complete:function(t,e){if(t.type==="throw")throw t.arg;return t.type==="break"||t.type==="continue"?this.next=t.arg:t.type==="return"?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):t.type==="normal"&&e&&(this.next=e),w},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),K(r),w}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var a=r.completion;if(a.type==="throw"){var n=a.arg;K(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:q(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),w}},o}(typeof Q=="object"?Q.exports:{});try{regeneratorRuntime=X}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=X:Function("r","regeneratorRuntime = r")(X)}});var mt=Re(ce());import{createSDK as Ye}from"@magic-sdk/provider";import*as Ke from"process";import $e from"localforage";import{URL as qe,URLSearchParams as xe}from"whatwg-url";import{Buffer as ee}from"buffer";import*as me from"lodash";import*as ve from"expo-application";import{driverWithoutSerialization as ze}from"@aveq-research/localforage-asyncstorage-driver";import*as te from"localforage-driver-memory";import ue,{useState as fe,useCallback as M,useMemo as Te,useEffect as V}from"react";import{Linking as Ne,StyleSheet as De}from"react-native";import{WebView as Ce}from"react-native-webview";import{SafeAreaView as Ve}from"react-native-safe-area-context";import{ViewController as Ge,createModalNotReadyError as ke}from"@magic-sdk/provider";import{isTypedArray as We}from"lodash";import G from"@react-native-async-storage/async-storage";import{EventRegister as le}from"react-native-event-listeners";import{useEffect as Ae,useState as Me}from"react";import Pe from"@react-native-community/netinfo";var Z=()=>{let[o,s]=Me(!0);return Ae(()=>{let i=f=>{s(!!f.isConnected)};return Pe.addEventListener(i)},[]),o};var he="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",je="open_in_device_browser",Fe="#FFFFFF",pe="msg_posted_after_inactivity_event",k="lastMessageTime";function Ue(){return De.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var W=class extends Ge{constructor(){super(...arguments);this.Relayer=i=>{let[f,c]=fe(!1),[p,l]=fe(!0),S=Z();V(()=>{this.isConnectedToInternet=S},[S]),V(()=>(G.setItem(k,""),()=>{this.isReadyForRequest=!1}),[]),V(()=>{le.addEventListener(pe,m=>I(this,null,function*(){this.isReadyForRequest=!1,l(!1),this.post(m.msgType,m.payload),yield G.setItem(k,new Date().toISOString())}))},[]),V(()=>{p||setTimeout(()=>l(!0),10)},[p]);let g=M(m=>{this.webView=m},[]),h=M(m=>{this.container=H(J({},m),{showOverlay:P,hideOverlay:O})},[]),P=M(()=>{c(!0)},[]),O=M(()=>{c(!1)},[]),T=Te(()=>[this.styles["webview-container"],f?H(J({},this.styles.show),{backgroundColor:i!=null?i:Fe}):this.styles.hide],[f]),F=M(m=>{this.handleReactNativeWebViewMessage(m)},[]);return p?ue.createElement(Ve,{ref:h,style:T},ue.createElement(Ce,{ref:g,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:F,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:m=>new URLSearchParams(m.url.split("?")[1]).get(je)?(Ne.openURL(m.url),!1):!0})):null}}init(){this.webView=null,this.container=null,this.styles=Ue()}handleReactNativeWebViewMessage(i){var f;if(i.nativeEvent&&typeof i.nativeEvent.data=="string"&&(i.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||i.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(i.nativeEvent.data,(p,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===he)return new global[l.constructor](l.data.split(","))}catch(S){}return l});if(c&&c.msgType&&this.messageHandlers.size){c.response=(f=c.response)!=null?f:{};let p={data:c};for(let l of this.messageHandlers.values())l(p)}}}msgPostedAfterInactivity(){return I(this,null,function*(){let i=yield G.getItem(k);if(i){let f=new Date(i).getTime(),c=new Date().getTime(),p=5*60*1e3;return c-f>p}return!1})}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(i){return I(this,null,function*(){if(yield this.msgPostedAfterInactivity()){le.emit(pe,i);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(i,(f,c)=>We(c)?{constructor:c.constructor.name,data:c.toString(),flag:he}:c),this.endpoint),G.setItem(k,new Date().toISOString());else throw ke()})}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as Be}from"@magic-sdk/provider";var j=class extends Be{get Relayer(){return this.overlay.Relayer}};export*from"@magic-sdk/commons";global.process=me.merge(global.process,Ke);global.process.browser=!1;global.Buffer=ee;global.URL=qe;global.URLSearchParams=xe;global.btoa=o=>ee.from(o,"binary").toString("base64");global.atob=o=>ee.from(o,"base64").toString("binary");var Lt=Ye(j,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.3",bundleId:ve.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:W,configureStorage:()=>I(void 0,null,function*(){let o=$e.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),s=ze();return yield Promise.all([o.defineDriver(s),o.defineDriver(te)]),yield o.setDriver([s._driver,te._driver]),o})});export{Lt as Magic,Z as useInternetConnection};
1
+ var ge=Object.create;var z=Object.defineProperty,we=Object.defineProperties,be=Object.getOwnPropertyDescriptor,Se=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,_e=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var ae=(o,s,i)=>s in o?z(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,J=(o,s)=>{for(var i in s||(s={}))se.call(s,i)&&ae(o,i,s[i]);if(ie)for(var i of ie(s))Le.call(s,i)&&ae(o,i,s[i]);return o},H=(o,s)=>we(o,Se(s));var Ie=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var Oe=(o,s,i,f)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of Ee(s))!se.call(o,c)&&c!==i&&z(o,c,{get:()=>s[c],enumerable:!(f=be(s,c))||f.enumerable});return o};var Re=(o,s,i)=>(i=o!=null?ge(_e(o)):{},Oe(s||!o||!o.__esModule?z(i,"default",{value:o,enumerable:!0}):i,o));var I=(o,s,i)=>new Promise((f,c)=>{var p=g=>{try{S(i.next(g))}catch(h){c(h)}},l=g=>{try{S(i.throw(g))}catch(h){c(h)}},S=g=>g.done?f(g.value):Promise.resolve(g.value).then(p,l);S((i=i.apply(o,s)).next())});var ce=Ie((He,Q)=>{var X=function(o){"use strict";var s=Object.prototype,i=s.hasOwnProperty,f=Object.defineProperty||function(t,e,r){t[e]=r.value},c,p=typeof Symbol=="function"?Symbol:{},l=p.iterator||"@@iterator",S=p.asyncIterator||"@@asyncIterator",g=p.toStringTag||"@@toStringTag";function h(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch{h=function(e,r,a){return e[r]=a}}function P(t,e,r,a){var n=e&&e.prototype instanceof U?e:U,u=Object.create(n.prototype),v=new $(a||[]);return f(u,"_invoke",{value:de(t,r,v)}),u}o.wrap=P;function O(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var T="suspendedStart",F="suspendedYield",m="executing",R="completed",w={};function U(){}function N(){}function E(){}var B={};h(B,l,function(){return this});var Y=Object.getPrototypeOf,D=Y&&Y(Y(q([])));D&&D!==s&&i.call(D,l)&&(B=D);var L=E.prototype=U.prototype=Object.create(B);N.prototype=E,f(L,"constructor",{value:E,configurable:!0}),f(E,"constructor",{value:N,configurable:!0}),N.displayName=h(E,g,"GeneratorFunction");function re(t){["next","throw","return"].forEach(function(e){h(t,e,function(r){return this._invoke(e,r)})})}o.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===N||(e.displayName||e.name)==="GeneratorFunction":!1},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,h(t,g,"GeneratorFunction")),t.prototype=Object.create(L),t},o.awrap=function(t){return{__await:t}};function C(t,e){function r(u,v,d,b){var y=O(t[u],t,v);if(y.type==="throw")b(y.arg);else{var x=y.arg,A=x.value;return A&&typeof A=="object"&&i.call(A,"__await")?e.resolve(A.__await).then(function(_){r("next",_,d,b)},function(_){r("throw",_,d,b)}):e.resolve(A).then(function(_){x.value=_,d(x)},function(_){return r("throw",_,d,b)})}}var a;function n(u,v){function d(){return new e(function(b,y){r(u,v,b,y)})}return a=a?a.then(d,d):d()}f(this,"_invoke",{value:n})}re(C.prototype),h(C.prototype,S,function(){return this}),o.AsyncIterator=C,o.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var u=new C(P(t,e,r,a),n);return o.isGeneratorFunction(e)?u:u.next().then(function(v){return v.done?v.value:u.next()})};function de(t,e,r){var a=T;return function(u,v){if(a===m)throw new Error("Generator is already running");if(a===R){if(u==="throw")throw v;return oe()}for(r.method=u,r.arg=v;;){var d=r.delegate;if(d){var b=ne(d,r);if(b){if(b===w)continue;return b}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(a===T)throw a=R,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=m;var y=O(t,e,r);if(y.type==="normal"){if(a=r.done?R:F,y.arg===w)continue;return{value:y.arg,done:r.done}}else y.type==="throw"&&(a=R,r.method="throw",r.arg=y.arg)}}}function ne(t,e){var r=e.method,a=t.iterator[r];if(a===c)return e.delegate=null,r==="throw"&&t.iterator.return&&(e.method="return",e.arg=c,ne(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),w;var n=O(a,t.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,w;var u=n.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,w;if(u.done)e[t.resultName]=u.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return u;return e.delegate=null,w}re(L),h(L,g,"Generator"),h(L,l,function(){return this}),h(L,"toString",function(){return"[object Generator]"});function ye(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function K(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function $(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(ye,this),this.reset(!0)}o.keys=function(t){var e=Object(t),r=[];for(var a in e)r.push(a);return r.reverse(),function n(){for(;r.length;){var u=r.pop();if(u in e)return n.value=u,n.done=!1,n}return n.done=!0,n}};function q(t){if(t){var e=t[l];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,a=function n(){for(;++r<t.length;)if(i.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=c,n.done=!0,n};return a.next=a}}return{next:oe}}o.values=q;function oe(){return{value:c,done:!0}}return $.prototype={constructor:$,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(K),!t)for(var e in this)e.charAt(0)==="t"&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0],e=t.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(b,y){return u.type="throw",u.arg=t,e.next=b,y&&(e.method="next",e.arg=c),!!y}for(var a=this.tryEntries.length-1;a>=0;--a){var n=this.tryEntries[a],u=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var v=i.call(n,"catchLoc"),d=i.call(n,"finallyLoc");if(v&&d){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(v){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(d){if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&i.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var n=a;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var u=n?n.completion:{};return u.type=t,u.arg=e,n?(this.method="next",this.next=n.finallyLoc,w):this.complete(u)},complete:function(t,e){if(t.type==="throw")throw t.arg;return t.type==="break"||t.type==="continue"?this.next=t.arg:t.type==="return"?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):t.type==="normal"&&e&&(this.next=e),w},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),K(r),w}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var a=r.completion;if(a.type==="throw"){var n=a.arg;K(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:q(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),w}},o}(typeof Q=="object"?Q.exports:{});try{regeneratorRuntime=X}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=X:Function("r","regeneratorRuntime = r")(X)}});var mt=Re(ce());import{createSDK as Ye}from"@magic-sdk/provider";import*as Ke from"process";import $e from"localforage";import{URL as qe,URLSearchParams as xe}from"whatwg-url";import{Buffer as ee}from"buffer";import*as me from"lodash";import*as ve from"expo-application";import{driverWithoutSerialization as ze}from"@aveq-research/localforage-asyncstorage-driver";import*as te from"localforage-driver-memory";import ue,{useState as fe,useCallback as M,useMemo as Te,useEffect as V}from"react";import{Linking as Ne,StyleSheet as De}from"react-native";import{WebView as Ce}from"react-native-webview";import{SafeAreaView as Ve}from"react-native-safe-area-context";import{ViewController as Ge,createModalNotReadyError as ke}from"@magic-sdk/provider";import{isTypedArray as We}from"lodash";import G from"@react-native-async-storage/async-storage";import{EventRegister as le}from"react-native-event-listeners";import{useEffect as Ae,useState as Me}from"react";import Pe from"@react-native-community/netinfo";var Z=()=>{let[o,s]=Me(!0);return Ae(()=>{let i=f=>{s(!!f.isConnected)};return Pe.addEventListener(i)},[]),o};var he="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",je="open_in_device_browser",Fe="#FFFFFF",pe="msg_posted_after_inactivity_event",k="lastMessageTime";function Ue(){return De.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var W=class extends Ge{constructor(){super(...arguments);this.Relayer=i=>{let[f,c]=fe(!1),[p,l]=fe(!0),S=Z();V(()=>{this.isConnectedToInternet=S},[S]),V(()=>(G.setItem(k,""),()=>{this.isReadyForRequest=!1}),[]),V(()=>{le.addEventListener(pe,m=>I(this,null,function*(){this.isReadyForRequest=!1,l(!1),this.post(m.msgType,m.payload),yield G.setItem(k,new Date().toISOString())}))},[]),V(()=>{p||setTimeout(()=>l(!0),10)},[p]);let g=M(m=>{this.webView=m},[]),h=M(m=>{this.container=H(J({},m),{showOverlay:P,hideOverlay:O})},[]),P=M(()=>{c(!0)},[]),O=M(()=>{c(!1)},[]),T=Te(()=>[this.styles["webview-container"],f?H(J({},this.styles.show),{backgroundColor:i!=null?i:Fe}):this.styles.hide],[f]),F=M(m=>{this.handleReactNativeWebViewMessage(m)},[]);return p?ue.createElement(Ve,{ref:h,style:T},ue.createElement(Ce,{ref:g,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:F,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:m=>new URLSearchParams(m.url.split("?")[1]).get(je)?(Ne.openURL(m.url),!1):!0})):null}}init(){this.webView=null,this.container=null,this.styles=Ue()}handleReactNativeWebViewMessage(i){var f;if(i.nativeEvent&&typeof i.nativeEvent.data=="string"&&(i.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||i.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(i.nativeEvent.data,(p,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===he)return new global[l.constructor](l.data.split(","))}catch(S){}return l});if(c&&c.msgType&&this.messageHandlers.size){c.response=(f=c.response)!=null?f:{};let p={data:c};for(let l of this.messageHandlers.values())l(p)}}}msgPostedAfterInactivity(){return I(this,null,function*(){let i=yield G.getItem(k);if(i){let f=new Date(i).getTime(),c=new Date().getTime(),p=5*60*1e3;return c-f>p}return!1})}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(i){return I(this,null,function*(){if(yield this.msgPostedAfterInactivity()){le.emit(pe,i);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(i,(f,c)=>We(c)?{constructor:c.constructor.name,data:c.toString(),flag:he}:c),this.endpoint),G.setItem(k,new Date().toISOString());else throw ke()})}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as Be}from"@magic-sdk/provider";var j=class extends Be{get Relayer(){return this.overlay.Relayer}};export*from"@magic-sdk/commons";global.process=me.merge(global.process,Ke);global.process.browser=!1;global.Buffer=ee;global.URL=qe;global.URLSearchParams=xe;global.btoa=o=>ee.from(o,"binary").toString("base64");global.atob=o=>ee.from(o,"base64").toString("binary");var Lt=Ye(j,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.4",bundleId:ve.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:W,configureStorage:()=>I(void 0,null,function*(){let o=$e.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),s=ze();return yield Promise.all([o.defineDriver(s),o.defineDriver(te)]),yield o.setDriver([s._driver,te._driver]),o})});export{Lt as Magic,Z as useInternetConnection};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic-sdk/react-native-expo",
3
- "version": "30.0.4-canary.870.14203885986.0",
3
+ "version": "30.0.4",
4
4
  "description": "Passwordless authentication for React Native (Expo).",
5
5
  "author": "Magic Labs <team@magic.link> (https://magic.link/)",
6
6
  "license": "MIT",
@@ -18,8 +18,8 @@
18
18
  "types": "./dist/types/index.d.ts",
19
19
  "dependencies": {
20
20
  "@aveq-research/localforage-asyncstorage-driver": "^3.0.1",
21
- "@magic-sdk/commons": "25.0.4-canary.870.14203885986.0",
22
- "@magic-sdk/provider": "29.0.4-canary.870.14203885986.0",
21
+ "@magic-sdk/commons": "^25.0.4",
22
+ "@magic-sdk/provider": "^29.0.4",
23
23
  "@magic-sdk/types": "^24.18.1",
24
24
  "@react-native-async-storage/async-storage": "^1.15.5",
25
25
  "@types/lodash": "^4.14.158",
@@ -55,5 +55,5 @@
55
55
  "react-native-safe-area-context": ">=4.4.1",
56
56
  "react-native-webview": ">=12.4.0"
57
57
  },
58
- "gitHead": "4aa3793d7b80cdbeed25430b683f78f0994cdd60"
58
+ "gitHead": "0ce3045bf26cc8d2d7c89edee475818b4668ec5b"
59
59
  }