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