@magic-sdk/react-native-expo 31.0.0-canary.879.14785467837.0 → 31.0.0-canary.879.15572425449.0

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 Ee=Object.create;var F=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var Oe=(i,a)=>()=>(a||i((a={exports:{}}).exports,a),a.exports),Ae=(i,a)=>{for(var s in a)F(i,s,{get:a[s],enumerable:!0})},W=(i,a,s,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of Le(a))!Re.call(i,l)&&l!==s&&F(i,l,{get:()=>a[l],enumerable:!(c=Ie(a,l))||c.enumerable});return i},u=(i,a,s)=>(W(i,a,"default"),s&&W(s,a,"default")),E=(i,a,s)=>(s=i!=null?Ee(_e(i)):{},W(a||!i||!i.__esModule?F(s,"default",{value:i,enumerable:!0}):s,i)),Te=i=>W(F({},"__esModule",{value:!0}),i);var le=Oe((Ge,oe)=>{"use strict";var ne=function(i){"use strict";var a=Object.prototype,s=a.hasOwnProperty,c,l=typeof Symbol=="function"?Symbol:{},S=l.iterator||"@@iterator",P=l.asyncIterator||"@@asyncIterator",O=l.toStringTag||"@@toStringTag";function m(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{m({},"")}catch{m=function(e,r,o){return e[r]=o}}function k(t,e,r,o){var n=e&&e.prototype instanceof H?e:H,h=Object.create(n.prototype),v=new ee(o||[]);return h._invoke=be(t,r,v),h}i.wrap=k;function A(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(o){return{type:"throw",arg:o}}}var N="suspendedStart",J="suspendedYield",d="executing",T="completed",w={};function H(){}function V(){}function I(){}var X={};m(X,S,function(){return this});var Q=Object.getPrototypeOf,G=Q&&Q(Q(te([])));G&&G!==a&&s.call(G,S)&&(X=G);var _=I.prototype=H.prototype=Object.create(X);V.prototype=I,m(_,"constructor",I),m(I,"constructor",V),V.displayName=m(I,O,"GeneratorFunction");function ae(t){["next","throw","return"].forEach(function(e){m(t,e,function(r){return this._invoke(e,r)})})}i.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===V||(e.displayName||e.name)==="GeneratorFunction":!1},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,I):(t.__proto__=I,m(t,O,"GeneratorFunction")),t.prototype=Object.create(_),t},i.awrap=function(t){return{__await:t}};function D(t,e){function r(h,v,y,b){var g=A(t[h],t,v);if(g.type==="throw")b(g.arg);else{var re=g.arg,C=re.value;return C&&typeof C=="object"&&s.call(C,"__await")?e.resolve(C.__await).then(function(L){r("next",L,y,b)},function(L){r("throw",L,y,b)}):e.resolve(C).then(function(L){re.value=L,y(re)},function(L){return r("throw",L,y,b)})}}var o;function n(h,v){function y(){return new e(function(b,g){r(h,v,b,g)})}return o=o?o.then(y,y):y()}this._invoke=n}ae(D.prototype),m(D.prototype,P,function(){return this}),i.AsyncIterator=D,i.async=function(t,e,r,o,n){n===void 0&&(n=Promise);var h=new D(k(t,e,r,o),n);return i.isGeneratorFunction(e)?h:h.next().then(function(v){return v.done?v.value:h.next()})};function be(t,e,r){var o=N;return function(h,v){if(o===d)throw new Error("Generator is already running");if(o===T){if(h==="throw")throw v;return ce()}for(r.method=h,r.arg=v;;){var y=r.delegate;if(y){var b=se(y,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(o===N)throw o=T,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);o=d;var g=A(t,e,r);if(g.type==="normal"){if(o=r.done?T:J,g.arg===w)continue;return{value:g.arg,done:r.done}}else g.type==="throw"&&(o=T,r.method="throw",r.arg=g.arg)}}}function se(t,e){var r=t.iterator[e.method];if(r===c){if(e.delegate=null,e.method==="throw"){if(t.iterator.return&&(e.method="return",e.arg=c,se(t,e),e.method==="throw"))return w;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return w}var o=A(r,t.iterator,e.arg);if(o.type==="throw")return e.method="throw",e.arg=o.arg,e.delegate=null,w;var n=o.arg;if(!n)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,w;if(n.done)e[t.resultName]=n.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return n;return e.delegate=null,w}ae(_),m(_,O,"Generator"),m(_,S,function(){return this}),m(_,"toString",function(){return"[object Generator]"});function Se(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 Z(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function ee(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Se,this),this.reset(!0)}i.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function o(){for(;e.length;){var n=e.pop();if(n in t)return o.value=n,o.done=!1,o}return o.done=!0,o}};function te(t){if(t){var e=t[S];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(s.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=c,n.done=!0,n};return o.next=o}}return{next:ce}}i.values=te;function ce(){return{value:c,done:!0}}return ee.prototype={constructor:ee,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(Z),!t)for(var e in this)e.charAt(0)==="t"&&s.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,g){return h.type="throw",h.arg=t,e.next=b,g&&(e.method="next",e.arg=c),!!g}for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o],h=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var v=s.call(n,"catchLoc"),y=s.call(n,"finallyLoc");if(v&&y){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(y){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 o=this.tryEntries[r];if(o.tryLoc<=this.prev&&s.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var n=o;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var h=n?n.completion:{};return h.type=t,h.arg=e,n?(this.method="next",this.next=n.finallyLoc,w):this.complete(h)},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),Z(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 o=r.completion;if(o.type==="throw"){var n=o.arg;Z(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:te(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),w}},i}(typeof oe=="object"?oe.exports:{});try{regeneratorRuntime=ne}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=ne:Function("r","regeneratorRuntime = r")(ne)}});var f={};Ae(f,{Magic:()=>Ne,useInternetConnection:()=>Y});module.exports=Te(f);var Be=E(le()),ye=require("@magic-sdk/provider"),ke=E(require("process")),x=require("whatwg-url"),z=require("buffer"),ge=E(require("lodash")),we=E(require("expo-application"));var p=E(require("react")),K=require("react-native"),pe=require("react-native-webview"),me=require("react-native-safe-area-context"),$=require("@magic-sdk/provider"),de=require("lodash"),M=E(require("@react-native-async-storage/async-storage")),ie=require("react-native-event-listeners");var U=require("react"),fe=E(require("@react-native-community/netinfo")),Y=()=>{let[i,a]=(0,U.useState)(!0);return(0,U.useEffect)(()=>{let s=c=>{a(!!c.isConnected)};return fe.default.addEventListener(s)},[]),i};var ue="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Ce="open_in_device_browser",Me="#FFFFFF",he="msg_posted_after_inactivity_event",j="lastMessageTime";function Pe(){return K.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 B=class extends $.ViewController{webView;container;styles;init(){this.webView=null,this.container=null,this.styles=Pe()}Relayer=a=>{let[s,c]=(0,p.useState)(!1),[l,S]=(0,p.useState)(!0),P=Y();(0,p.useEffect)(()=>{this.isConnectedToInternet=P},[P]),(0,p.useEffect)(()=>(M.default.setItem(j,""),()=>{this.isReadyForRequest=!1}),[]),(0,p.useEffect)(()=>{ie.EventRegister.addEventListener(he,async d=>{this.isReadyForRequest=!1,S(!1),this.post(d.msgType,d.payload),await M.default.setItem(j,new Date().toISOString())})},[]),(0,p.useEffect)(()=>{l||setTimeout(()=>S(!0),10)},[l]);let O=(0,p.useCallback)(d=>{this.webView=d},[]),m=(0,p.useCallback)(d=>{this.container={...d,showOverlay:k,hideOverlay:A}},[]),k=(0,p.useCallback)(()=>{c(!0)},[]),A=(0,p.useCallback)(()=>{c(!1)},[]),N=(0,p.useMemo)(()=>[this.styles["webview-container"],s?{...this.styles.show,backgroundColor:a??Me}:this.styles.hide],[s]),J=(0,p.useCallback)(d=>{this.handleReactNativeWebViewMessage(d)},[]);return l?p.default.createElement(me.SafeAreaView,{ref:m,style:N},p.default.createElement(pe.WebView,{ref:O,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:J,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:d=>new URLSearchParams(d.url.split("?")[1]).get(Ce)?(K.Linking.openURL(d.url),!1):!0})):null};handleReactNativeWebViewMessage(a){if(a.nativeEvent&&typeof a.nativeEvent.data=="string"&&(a.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||a.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let s=JSON.parse(a.nativeEvent.data,(c,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===ue)return new global[l.constructor](l.data.split(","))}catch{}return l});if(s&&s.msgType&&this.messageHandlers.size){s.response=s.response??{};let c={data:s};for(let l of this.messageHandlers.values())l(c)}}}async msgPostedAfterInactivity(){let a=await M.default.getItem(j);if(a){let s=new Date(a).getTime(),c=new Date().getTime(),l=5*60*1e3;return c-s>l}return!1}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}async _post(a){if(await this.msgPostedAfterInactivity()){ie.EventRegister.emit(he,a);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(a,(s,c)=>(0,de.isTypedArray)(c)?{constructor:c.constructor.name,data:c.toString(),flag:ue}:c),this.endpoint),M.default.setItem(j,new Date().toISOString());else throw(0,$.createModalNotReadyError)()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var ve=require("@magic-sdk/provider"),q=class extends ve.SDKBase{get Relayer(){return this.overlay.Relayer}};var R=E(require("@react-native-async-storage/async-storage"));u(f,require("@magic-sdk/commons"),module.exports);global.process=ge.default.merge(global.process,ke);global.process.browser=!1;global.Buffer=z.Buffer;global.URL=x.URL;global.URLSearchParams=x.URLSearchParams;global.btoa=i=>z.Buffer.from(i,"binary").toString("base64");global.atob=i=>z.Buffer.from(i,"base64").toString("binary");var Ne=(0,ye.createSDK)(q,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.6",bundleId:we.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:B,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:R.default.getItem,setItem:R.default.setItem,removeItem:R.default.removeItem,clear:R.default.clear,length:()=>{},key:()=>{},keys:R.default.getAllKeys,iterate:()=>{}})});0&&(module.exports={Magic,useInternetConnection,...require("@magic-sdk/commons")});
1
+ "use strict";var Ee=Object.create;var F=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var Oe=(i,a)=>()=>(a||i((a={exports:{}}).exports,a),a.exports),Ae=(i,a)=>{for(var s in a)F(i,s,{get:a[s],enumerable:!0})},W=(i,a,s,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of Le(a))!Re.call(i,l)&&l!==s&&F(i,l,{get:()=>a[l],enumerable:!(c=Ie(a,l))||c.enumerable});return i},u=(i,a,s)=>(W(i,a,"default"),s&&W(s,a,"default")),E=(i,a,s)=>(s=i!=null?Ee(_e(i)):{},W(a||!i||!i.__esModule?F(s,"default",{value:i,enumerable:!0}):s,i)),Te=i=>W(F({},"__esModule",{value:!0}),i);var le=Oe((Ge,oe)=>{"use strict";var ne=function(i){"use strict";var a=Object.prototype,s=a.hasOwnProperty,c,l=typeof Symbol=="function"?Symbol:{},S=l.iterator||"@@iterator",P=l.asyncIterator||"@@asyncIterator",O=l.toStringTag||"@@toStringTag";function m(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{m({},"")}catch{m=function(e,r,o){return e[r]=o}}function k(t,e,r,o){var n=e&&e.prototype instanceof H?e:H,h=Object.create(n.prototype),v=new ee(o||[]);return h._invoke=be(t,r,v),h}i.wrap=k;function A(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(o){return{type:"throw",arg:o}}}var N="suspendedStart",J="suspendedYield",d="executing",T="completed",w={};function H(){}function V(){}function I(){}var X={};m(X,S,function(){return this});var Q=Object.getPrototypeOf,G=Q&&Q(Q(te([])));G&&G!==a&&s.call(G,S)&&(X=G);var _=I.prototype=H.prototype=Object.create(X);V.prototype=I,m(_,"constructor",I),m(I,"constructor",V),V.displayName=m(I,O,"GeneratorFunction");function ae(t){["next","throw","return"].forEach(function(e){m(t,e,function(r){return this._invoke(e,r)})})}i.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===V||(e.displayName||e.name)==="GeneratorFunction":!1},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,I):(t.__proto__=I,m(t,O,"GeneratorFunction")),t.prototype=Object.create(_),t},i.awrap=function(t){return{__await:t}};function D(t,e){function r(h,v,y,b){var g=A(t[h],t,v);if(g.type==="throw")b(g.arg);else{var re=g.arg,C=re.value;return C&&typeof C=="object"&&s.call(C,"__await")?e.resolve(C.__await).then(function(L){r("next",L,y,b)},function(L){r("throw",L,y,b)}):e.resolve(C).then(function(L){re.value=L,y(re)},function(L){return r("throw",L,y,b)})}}var o;function n(h,v){function y(){return new e(function(b,g){r(h,v,b,g)})}return o=o?o.then(y,y):y()}this._invoke=n}ae(D.prototype),m(D.prototype,P,function(){return this}),i.AsyncIterator=D,i.async=function(t,e,r,o,n){n===void 0&&(n=Promise);var h=new D(k(t,e,r,o),n);return i.isGeneratorFunction(e)?h:h.next().then(function(v){return v.done?v.value:h.next()})};function be(t,e,r){var o=N;return function(h,v){if(o===d)throw new Error("Generator is already running");if(o===T){if(h==="throw")throw v;return ce()}for(r.method=h,r.arg=v;;){var y=r.delegate;if(y){var b=se(y,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(o===N)throw o=T,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);o=d;var g=A(t,e,r);if(g.type==="normal"){if(o=r.done?T:J,g.arg===w)continue;return{value:g.arg,done:r.done}}else g.type==="throw"&&(o=T,r.method="throw",r.arg=g.arg)}}}function se(t,e){var r=t.iterator[e.method];if(r===c){if(e.delegate=null,e.method==="throw"){if(t.iterator.return&&(e.method="return",e.arg=c,se(t,e),e.method==="throw"))return w;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return w}var o=A(r,t.iterator,e.arg);if(o.type==="throw")return e.method="throw",e.arg=o.arg,e.delegate=null,w;var n=o.arg;if(!n)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,w;if(n.done)e[t.resultName]=n.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return n;return e.delegate=null,w}ae(_),m(_,O,"Generator"),m(_,S,function(){return this}),m(_,"toString",function(){return"[object Generator]"});function Se(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 Z(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function ee(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Se,this),this.reset(!0)}i.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function o(){for(;e.length;){var n=e.pop();if(n in t)return o.value=n,o.done=!1,o}return o.done=!0,o}};function te(t){if(t){var e=t[S];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(s.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=c,n.done=!0,n};return o.next=o}}return{next:ce}}i.values=te;function ce(){return{value:c,done:!0}}return ee.prototype={constructor:ee,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(Z),!t)for(var e in this)e.charAt(0)==="t"&&s.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,g){return h.type="throw",h.arg=t,e.next=b,g&&(e.method="next",e.arg=c),!!g}for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o],h=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var v=s.call(n,"catchLoc"),y=s.call(n,"finallyLoc");if(v&&y){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(y){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 o=this.tryEntries[r];if(o.tryLoc<=this.prev&&s.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var n=o;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var h=n?n.completion:{};return h.type=t,h.arg=e,n?(this.method="next",this.next=n.finallyLoc,w):this.complete(h)},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),Z(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 o=r.completion;if(o.type==="throw"){var n=o.arg;Z(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:te(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),w}},i}(typeof oe=="object"?oe.exports:{});try{regeneratorRuntime=ne}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=ne:Function("r","regeneratorRuntime = r")(ne)}});var f={};Ae(f,{Magic:()=>Ne,useInternetConnection:()=>Y});module.exports=Te(f);var Be=E(le()),ye=require("@magic-sdk/provider"),ke=E(require("process")),x=require("whatwg-url"),z=require("buffer"),ge=E(require("lodash")),we=E(require("expo-application"));var p=E(require("react")),K=require("react-native"),pe=require("react-native-webview"),me=require("react-native-safe-area-context"),$=require("@magic-sdk/provider"),de=require("lodash"),M=E(require("@react-native-async-storage/async-storage")),ie=require("react-native-event-listeners");var U=require("react"),fe=E(require("@react-native-community/netinfo")),Y=()=>{let[i,a]=(0,U.useState)(!0);return(0,U.useEffect)(()=>{let s=c=>{a(!!c.isConnected)};return fe.default.addEventListener(s)},[]),i};var ue="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Ce="open_in_device_browser",Me="#FFFFFF",he="msg_posted_after_inactivity_event",j="lastMessageTime";function Pe(){return K.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 B=class extends $.ViewController{webView;container;styles;init(){this.webView=null,this.container=null,this.styles=Pe()}Relayer=a=>{let[s,c]=(0,p.useState)(!1),[l,S]=(0,p.useState)(!0),P=Y();(0,p.useEffect)(()=>{this.isConnectedToInternet=P},[P]),(0,p.useEffect)(()=>(M.default.setItem(j,""),()=>{this.isReadyForRequest=!1}),[]),(0,p.useEffect)(()=>{ie.EventRegister.addEventListener(he,async d=>{this.isReadyForRequest=!1,S(!1),this.post(d.msgType,d.payload),await M.default.setItem(j,new Date().toISOString())})},[]),(0,p.useEffect)(()=>{l||setTimeout(()=>S(!0),10)},[l]);let O=(0,p.useCallback)(d=>{this.webView=d},[]),m=(0,p.useCallback)(d=>{this.container={...d,showOverlay:k,hideOverlay:A}},[]),k=(0,p.useCallback)(()=>{c(!0)},[]),A=(0,p.useCallback)(()=>{c(!1)},[]),N=(0,p.useMemo)(()=>[this.styles["webview-container"],s?{...this.styles.show,backgroundColor:a??Me}:this.styles.hide],[s]),J=(0,p.useCallback)(d=>{this.handleReactNativeWebViewMessage(d)},[]);return l?p.default.createElement(me.SafeAreaView,{ref:m,style:N},p.default.createElement(pe.WebView,{ref:O,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:J,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:d=>new URLSearchParams(d.url.split("?")[1]).get(Ce)?(K.Linking.openURL(d.url),!1):!0})):null};handleReactNativeWebViewMessage(a){if(a.nativeEvent&&typeof a.nativeEvent.data=="string"&&(a.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||a.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let s=JSON.parse(a.nativeEvent.data,(c,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===ue)return new global[l.constructor](l.data.split(","))}catch{}return l});if(s&&s.msgType&&this.messageHandlers.size){s.response=s.response??{};let c={data:s};for(let l of this.messageHandlers.values())l(c)}}}async msgPostedAfterInactivity(){let a=await M.default.getItem(j);if(a){let s=new Date(a).getTime(),c=new Date().getTime(),l=5*60*1e3;return c-s>l}return!1}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}async _post(a){if(await this.msgPostedAfterInactivity()){ie.EventRegister.emit(he,a);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(a,(s,c)=>(0,de.isTypedArray)(c)?{constructor:c.constructor.name,data:c.toString(),flag:ue}:c),this.endpoint),M.default.setItem(j,new Date().toISOString());else throw(0,$.createModalNotReadyError)()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var ve=require("@magic-sdk/provider"),q=class extends ve.SDKBase{get Relayer(){return this.overlay.Relayer}};var R=E(require("@react-native-async-storage/async-storage"));u(f,require("@magic-sdk/commons"),module.exports);global.process=ge.default.merge(global.process,ke);global.process.browser=!1;global.Buffer=z.Buffer;global.URL=x.URL;global.URLSearchParams=x.URLSearchParams;global.btoa=i=>z.Buffer.from(i,"binary").toString("base64");global.atob=i=>z.Buffer.from(i,"base64").toString("binary");var Ne=(0,ye.createSDK)(q,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.1.0",bundleId:we.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:B,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:R.default.getItem,setItem:R.default.setItem,removeItem:R.default.removeItem,clear:R.default.clear,length:()=>{},key:()=>{},keys:R.default.getAllKeys,iterate:()=>{}})});0&&(module.exports={Magic,useInternetConnection,...require("@magic-sdk/commons")});
2
2
  //# sourceMappingURL=index.js.map
package/dist/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var fe=Object.create;var ee=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var de=(i,a)=>()=>(a||i((a={exports:{}}).exports,a),a.exports);var ve=(i,a,c,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of he(a))!me.call(i,l)&&l!==c&&ee(i,l,{get:()=>a[l],enumerable:!(s=ue(a,l))||s.enumerable});return i};var ye=(i,a,c)=>(c=i!=null?fe(pe(i)):{},ve(a||!i||!i.__esModule?ee(c,"default",{value:i,enumerable:!0}):c,i));var te=de((Fe,z)=>{"use strict";var x=function(i){"use strict";var a=Object.prototype,c=a.hasOwnProperty,s,l=typeof Symbol=="function"?Symbol:{},g=l.iterator||"@@iterator",A=l.asyncIterator||"@@asyncIterator",E=l.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch{u=function(e,r,o){return e[r]=o}}function T(t,e,r,o){var n=e&&e.prototype instanceof U?e:U,f=Object.create(n.prototype),p=new K(o||[]);return f._invoke=ce(t,r,p),f}i.wrap=T;function I(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(o){return{type:"throw",arg:o}}}var C="suspendedStart",F="suspendedYield",h="executing",L="completed",v={};function U(){}function M(){}function w(){}var Y={};u(Y,g,function(){return this});var j=Object.getPrototypeOf,P=j&&j(j($([])));P&&P!==a&&c.call(P,g)&&(Y=P);var S=w.prototype=U.prototype=Object.create(Y);M.prototype=w,u(S,"constructor",w),u(w,"constructor",M),M.displayName=u(w,E,"GeneratorFunction");function X(t){["next","throw","return"].forEach(function(e){u(t,e,function(r){return this._invoke(e,r)})})}i.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===M||(e.displayName||e.name)==="GeneratorFunction":!1},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,u(t,E,"GeneratorFunction")),t.prototype=Object.create(S),t},i.awrap=function(t){return{__await:t}};function k(t,e){function r(f,p,m,y){var d=I(t[f],t,p);if(d.type==="throw")y(d.arg);else{var q=d.arg,_=q.value;return _&&typeof _=="object"&&c.call(_,"__await")?e.resolve(_.__await).then(function(b){r("next",b,m,y)},function(b){r("throw",b,m,y)}):e.resolve(_).then(function(b){q.value=b,m(q)},function(b){return r("throw",b,m,y)})}}var o;function n(f,p){function m(){return new e(function(y,d){r(f,p,y,d)})}return o=o?o.then(m,m):m()}this._invoke=n}X(k.prototype),u(k.prototype,A,function(){return this}),i.AsyncIterator=k,i.async=function(t,e,r,o,n){n===void 0&&(n=Promise);var f=new k(T(t,e,r,o),n);return i.isGeneratorFunction(e)?f:f.next().then(function(p){return p.done?p.value:f.next()})};function ce(t,e,r){var o=C;return function(f,p){if(o===h)throw new Error("Generator is already running");if(o===L){if(f==="throw")throw p;return Z()}for(r.method=f,r.arg=p;;){var m=r.delegate;if(m){var y=Q(m,r);if(y){if(y===v)continue;return y}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(o===C)throw o=L,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);o=h;var d=I(t,e,r);if(d.type==="normal"){if(o=r.done?L:F,d.arg===v)continue;return{value:d.arg,done:r.done}}else d.type==="throw"&&(o=L,r.method="throw",r.arg=d.arg)}}}function Q(t,e){var r=t.iterator[e.method];if(r===s){if(e.delegate=null,e.method==="throw"){if(t.iterator.return&&(e.method="return",e.arg=s,Q(t,e),e.method==="throw"))return v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=I(r,t.iterator,e.arg);if(o.type==="throw")return e.method="throw",e.arg=o.arg,e.delegate=null,v;var n=o.arg;if(!n)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v;if(n.done)e[t.resultName]=n.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=s);else return n;return e.delegate=null,v}X(S),u(S,E,"Generator"),u(S,g,function(){return this}),u(S,"toString",function(){return"[object Generator]"});function le(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 B(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function K(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(le,this),this.reset(!0)}i.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function o(){for(;e.length;){var n=e.pop();if(n in t)return o.value=n,o.done=!1,o}return o.done=!0,o}};function $(t){if(t){var e=t[g];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(c.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=s,n.done=!0,n};return o.next=o}}return{next:Z}}i.values=$;function Z(){return{value:s,done:!0}}return K.prototype={constructor:K,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(B),!t)for(var e in this)e.charAt(0)==="t"&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},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(y,d){return f.type="throw",f.arg=t,e.next=y,d&&(e.method="next",e.arg=s),!!d}for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o],f=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var p=c.call(n,"catchLoc"),m=c.call(n,"finallyLoc");if(p&&m){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(p){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(m){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 o=this.tryEntries[r];if(o.tryLoc<=this.prev&&c.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var n=o;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var f=n?n.completion:{};return f.type=t,f.arg=e,n?(this.method="next",this.next=n.finallyLoc,v):this.complete(f)},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),v},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),B(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var o=r.completion;if(o.type==="throw"){var n=o.arg;B(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:$(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=s),v}},i}(typeof z=="object"?z.exports:{});try{regeneratorRuntime=x}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=x:Function("r","regeneratorRuntime = r")(x)}});var nt=ye(te());import{createSDK as ke}from"@magic-sdk/provider";import*as Ne from"process";import{URL as Ve,URLSearchParams as Ge}from"whatwg-url";import{Buffer as H}from"buffer";import De from"lodash";import*as se from"expo-application";import re,{useState as ne,useCallback as R,useMemo as Se,useEffect as N}from"react";import{Linking as Ee,StyleSheet as Ie}from"react-native";import{WebView as Le}from"react-native-webview";import{SafeAreaView as _e}from"react-native-safe-area-context";import{ViewController as Re,createModalNotReadyError as Oe}from"@magic-sdk/provider";import{isTypedArray as Ae}from"lodash";import V from"@react-native-async-storage/async-storage";import{EventRegister as oe}from"react-native-event-listeners";import{useEffect as ge,useState as we}from"react";import be from"@react-native-community/netinfo";var J=()=>{let[i,a]=we(!0);return ge(()=>{let c=s=>{a(!!s.isConnected)};return be.addEventListener(c)},[]),i};var ie="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Te="open_in_device_browser",Ce="#FFFFFF",ae="msg_posted_after_inactivity_event",G="lastMessageTime";function Me(){return Ie.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 D=class extends Re{webView;container;styles;init(){this.webView=null,this.container=null,this.styles=Me()}Relayer=a=>{let[c,s]=ne(!1),[l,g]=ne(!0),A=J();N(()=>{this.isConnectedToInternet=A},[A]),N(()=>(V.setItem(G,""),()=>{this.isReadyForRequest=!1}),[]),N(()=>{oe.addEventListener(ae,async h=>{this.isReadyForRequest=!1,g(!1),this.post(h.msgType,h.payload),await V.setItem(G,new Date().toISOString())})},[]),N(()=>{l||setTimeout(()=>g(!0),10)},[l]);let E=R(h=>{this.webView=h},[]),u=R(h=>{this.container={...h,showOverlay:T,hideOverlay:I}},[]),T=R(()=>{s(!0)},[]),I=R(()=>{s(!1)},[]),C=Se(()=>[this.styles["webview-container"],c?{...this.styles.show,backgroundColor:a??Ce}:this.styles.hide],[c]),F=R(h=>{this.handleReactNativeWebViewMessage(h)},[]);return l?re.createElement(_e,{ref:u,style:C},re.createElement(Le,{ref:E,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:F,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:h=>new URLSearchParams(h.url.split("?")[1]).get(Te)?(Ee.openURL(h.url),!1):!0})):null};handleReactNativeWebViewMessage(a){if(a.nativeEvent&&typeof a.nativeEvent.data=="string"&&(a.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||a.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(a.nativeEvent.data,(s,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===ie)return new global[l.constructor](l.data.split(","))}catch{}return l});if(c&&c.msgType&&this.messageHandlers.size){c.response=c.response??{};let s={data:c};for(let l of this.messageHandlers.values())l(s)}}}async msgPostedAfterInactivity(){let a=await V.getItem(G);if(a){let c=new Date(a).getTime(),s=new Date().getTime(),l=5*60*1e3;return s-c>l}return!1}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}async _post(a){if(await this.msgPostedAfterInactivity()){oe.emit(ae,a);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(a,(c,s)=>Ae(s)?{constructor:s.constructor.name,data:s.toString(),flag:ie}:s),this.endpoint),V.setItem(G,new Date().toISOString());else throw Oe()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as Pe}from"@magic-sdk/provider";var W=class extends Pe{get Relayer(){return this.overlay.Relayer}};import O from"@react-native-async-storage/async-storage";export*from"@magic-sdk/commons";global.process=De.merge(global.process,Ne);global.process.browser=!1;global.Buffer=H;global.URL=Ve;global.URLSearchParams=Ge;global.btoa=i=>H.from(i,"binary").toString("base64");global.atob=i=>H.from(i,"base64").toString("binary");var pt=ke(W,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.0.6",bundleId:se.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:O.getItem,setItem:O.setItem,removeItem:O.removeItem,clear:O.clear,length:()=>{},key:()=>{},keys:O.getAllKeys,iterate:()=>{}})});export{pt as Magic,J as useInternetConnection};
1
+ var fe=Object.create;var ee=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var de=(i,a)=>()=>(a||i((a={exports:{}}).exports,a),a.exports);var ve=(i,a,c,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of he(a))!me.call(i,l)&&l!==c&&ee(i,l,{get:()=>a[l],enumerable:!(s=ue(a,l))||s.enumerable});return i};var ye=(i,a,c)=>(c=i!=null?fe(pe(i)):{},ve(a||!i||!i.__esModule?ee(c,"default",{value:i,enumerable:!0}):c,i));var te=de((Fe,z)=>{"use strict";var x=function(i){"use strict";var a=Object.prototype,c=a.hasOwnProperty,s,l=typeof Symbol=="function"?Symbol:{},g=l.iterator||"@@iterator",A=l.asyncIterator||"@@asyncIterator",E=l.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch{u=function(e,r,o){return e[r]=o}}function T(t,e,r,o){var n=e&&e.prototype instanceof U?e:U,f=Object.create(n.prototype),p=new K(o||[]);return f._invoke=ce(t,r,p),f}i.wrap=T;function I(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(o){return{type:"throw",arg:o}}}var C="suspendedStart",F="suspendedYield",h="executing",L="completed",v={};function U(){}function M(){}function w(){}var Y={};u(Y,g,function(){return this});var j=Object.getPrototypeOf,P=j&&j(j($([])));P&&P!==a&&c.call(P,g)&&(Y=P);var S=w.prototype=U.prototype=Object.create(Y);M.prototype=w,u(S,"constructor",w),u(w,"constructor",M),M.displayName=u(w,E,"GeneratorFunction");function X(t){["next","throw","return"].forEach(function(e){u(t,e,function(r){return this._invoke(e,r)})})}i.isGeneratorFunction=function(t){var e=typeof t=="function"&&t.constructor;return e?e===M||(e.displayName||e.name)==="GeneratorFunction":!1},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,u(t,E,"GeneratorFunction")),t.prototype=Object.create(S),t},i.awrap=function(t){return{__await:t}};function k(t,e){function r(f,p,m,y){var d=I(t[f],t,p);if(d.type==="throw")y(d.arg);else{var q=d.arg,_=q.value;return _&&typeof _=="object"&&c.call(_,"__await")?e.resolve(_.__await).then(function(b){r("next",b,m,y)},function(b){r("throw",b,m,y)}):e.resolve(_).then(function(b){q.value=b,m(q)},function(b){return r("throw",b,m,y)})}}var o;function n(f,p){function m(){return new e(function(y,d){r(f,p,y,d)})}return o=o?o.then(m,m):m()}this._invoke=n}X(k.prototype),u(k.prototype,A,function(){return this}),i.AsyncIterator=k,i.async=function(t,e,r,o,n){n===void 0&&(n=Promise);var f=new k(T(t,e,r,o),n);return i.isGeneratorFunction(e)?f:f.next().then(function(p){return p.done?p.value:f.next()})};function ce(t,e,r){var o=C;return function(f,p){if(o===h)throw new Error("Generator is already running");if(o===L){if(f==="throw")throw p;return Z()}for(r.method=f,r.arg=p;;){var m=r.delegate;if(m){var y=Q(m,r);if(y){if(y===v)continue;return y}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(o===C)throw o=L,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);o=h;var d=I(t,e,r);if(d.type==="normal"){if(o=r.done?L:F,d.arg===v)continue;return{value:d.arg,done:r.done}}else d.type==="throw"&&(o=L,r.method="throw",r.arg=d.arg)}}}function Q(t,e){var r=t.iterator[e.method];if(r===s){if(e.delegate=null,e.method==="throw"){if(t.iterator.return&&(e.method="return",e.arg=s,Q(t,e),e.method==="throw"))return v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=I(r,t.iterator,e.arg);if(o.type==="throw")return e.method="throw",e.arg=o.arg,e.delegate=null,v;var n=o.arg;if(!n)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v;if(n.done)e[t.resultName]=n.value,e.next=t.nextLoc,e.method!=="return"&&(e.method="next",e.arg=s);else return n;return e.delegate=null,v}X(S),u(S,E,"Generator"),u(S,g,function(){return this}),u(S,"toString",function(){return"[object Generator]"});function le(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 B(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function K(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(le,this),this.reset(!0)}i.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function o(){for(;e.length;){var n=e.pop();if(n in t)return o.value=n,o.done=!1,o}return o.done=!0,o}};function $(t){if(t){var e=t[g];if(e)return e.call(t);if(typeof t.next=="function")return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(c.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=s,n.done=!0,n};return o.next=o}}return{next:Z}}i.values=$;function Z(){return{value:s,done:!0}}return K.prototype={constructor:K,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(B),!t)for(var e in this)e.charAt(0)==="t"&&c.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=s)},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(y,d){return f.type="throw",f.arg=t,e.next=y,d&&(e.method="next",e.arg=s),!!d}for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o],f=n.completion;if(n.tryLoc==="root")return r("end");if(n.tryLoc<=this.prev){var p=c.call(n,"catchLoc"),m=c.call(n,"finallyLoc");if(p&&m){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(p){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(m){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 o=this.tryEntries[r];if(o.tryLoc<=this.prev&&c.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var n=o;break}}n&&(t==="break"||t==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var f=n?n.completion:{};return f.type=t,f.arg=e,n?(this.method="next",this.next=n.finallyLoc,v):this.complete(f)},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),v},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),B(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var o=r.completion;if(o.type==="throw"){var n=o.arg;B(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:$(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=s),v}},i}(typeof z=="object"?z.exports:{});try{regeneratorRuntime=x}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=x:Function("r","regeneratorRuntime = r")(x)}});var nt=ye(te());import{createSDK as ke}from"@magic-sdk/provider";import*as Ne from"process";import{URL as Ve,URLSearchParams as Ge}from"whatwg-url";import{Buffer as H}from"buffer";import De from"lodash";import*as se from"expo-application";import re,{useState as ne,useCallback as R,useMemo as Se,useEffect as N}from"react";import{Linking as Ee,StyleSheet as Ie}from"react-native";import{WebView as Le}from"react-native-webview";import{SafeAreaView as _e}from"react-native-safe-area-context";import{ViewController as Re,createModalNotReadyError as Oe}from"@magic-sdk/provider";import{isTypedArray as Ae}from"lodash";import V from"@react-native-async-storage/async-storage";import{EventRegister as oe}from"react-native-event-listeners";import{useEffect as ge,useState as we}from"react";import be from"@react-native-community/netinfo";var J=()=>{let[i,a]=we(!0);return ge(()=>{let c=s=>{a(!!s.isConnected)};return be.addEventListener(c)},[]),i};var ie="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Te="open_in_device_browser",Ce="#FFFFFF",ae="msg_posted_after_inactivity_event",G="lastMessageTime";function Me(){return Ie.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 D=class extends Re{webView;container;styles;init(){this.webView=null,this.container=null,this.styles=Me()}Relayer=a=>{let[c,s]=ne(!1),[l,g]=ne(!0),A=J();N(()=>{this.isConnectedToInternet=A},[A]),N(()=>(V.setItem(G,""),()=>{this.isReadyForRequest=!1}),[]),N(()=>{oe.addEventListener(ae,async h=>{this.isReadyForRequest=!1,g(!1),this.post(h.msgType,h.payload),await V.setItem(G,new Date().toISOString())})},[]),N(()=>{l||setTimeout(()=>g(!0),10)},[l]);let E=R(h=>{this.webView=h},[]),u=R(h=>{this.container={...h,showOverlay:T,hideOverlay:I}},[]),T=R(()=>{s(!0)},[]),I=R(()=>{s(!1)},[]),C=Se(()=>[this.styles["webview-container"],c?{...this.styles.show,backgroundColor:a??Ce}:this.styles.hide],[c]),F=R(h=>{this.handleReactNativeWebViewMessage(h)},[]);return l?re.createElement(_e,{ref:u,style:C},re.createElement(Le,{ref:E,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:F,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:h=>new URLSearchParams(h.url.split("?")[1]).get(Te)?(Ee.openURL(h.url),!1):!0})):null};handleReactNativeWebViewMessage(a){if(a.nativeEvent&&typeof a.nativeEvent.data=="string"&&(a.nativeEvent.url===`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`||a.nativeEvent.url===`${this.endpoint}/send/?params=${this.parameters}`)){let c=JSON.parse(a.nativeEvent.data,(s,l)=>{try{if(l&&typeof l=="object"&&l.flag&&l.flag===ie)return new global[l.constructor](l.data.split(","))}catch{}return l});if(c&&c.msgType&&this.messageHandlers.size){c.response=c.response??{};let s={data:c};for(let l of this.messageHandlers.values())l(s)}}}async msgPostedAfterInactivity(){let a=await V.getItem(G);if(a){let c=new Date(a).getTime(),s=new Date().getTime(),l=5*60*1e3;return s-c>l}return!1}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}async _post(a){if(await this.msgPostedAfterInactivity()){oe.emit(ae,a);return}if(this.webView&&this.webView.postMessage)this.webView.postMessage(JSON.stringify(a,(c,s)=>Ae(s)?{constructor:s.constructor.name,data:s.toString(),flag:ie}:s),this.endpoint),V.setItem(G,new Date().toISOString());else throw Oe()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as Pe}from"@magic-sdk/provider";var W=class extends Pe{get Relayer(){return this.overlay.Relayer}};import O from"@react-native-async-storage/async-storage";export*from"@magic-sdk/commons";global.process=De.merge(global.process,Ne);global.process.browser=!1;global.Buffer=H;global.URL=Ve;global.URLSearchParams=Ge;global.btoa=i=>H.from(i,"binary").toString("base64");global.atob=i=>H.from(i,"base64").toString("binary");var pt=ke(W,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"30.1.0",bundleId:se.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:O.getItem,setItem:O.setItem,removeItem:O.removeItem,clear:O.clear,length:()=>{},key:()=>{},keys:O.getAllKeys,iterate:()=>{}})});export{pt as Magic,J 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": "31.0.0-canary.879.14785467837.0",
3
+ "version": "31.0.0-canary.879.15572425449.0",
4
4
  "description": "Passwordless authentication for React Native (Expo).",
5
5
  "author": "Magic Labs <team@magic.link> (https://magic.link/)",
6
6
  "license": "MIT",
@@ -17,9 +17,9 @@
17
17
  "module": "./dist/es/index.js",
18
18
  "types": "./dist/types/index.d.ts",
19
19
  "dependencies": {
20
- "@magic-sdk/commons": "^25.0.6",
21
- "@magic-sdk/provider": "^29.0.6",
22
- "@magic-sdk/types": "^24.18.2",
20
+ "@magic-sdk/commons": "^25.1.0",
21
+ "@magic-sdk/provider": "^29.1.0",
22
+ "@magic-sdk/types": "^24.19.0",
23
23
  "@react-native-async-storage/async-storage": "^2.1.2",
24
24
  "@types/lodash": "^4.14.158",
25
25
  "buffer": "~5.6.0",
@@ -54,5 +54,5 @@
54
54
  "react-native-safe-area-context": ">=4.4.1",
55
55
  "react-native-webview": ">=12.4.0"
56
56
  },
57
- "gitHead": "8d2f488ba1e9d542d2933d76acd896caaecfd2f7"
57
+ "gitHead": "f4e203b24546fb5a3f8da588dff9f00a0c6a3291"
58
58
  }