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