@magic-sdk/react-native-expo 34.8.1-canary.1106.28906316739.0 → 34.8.1

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 F=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Me=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Ae=(s,c)=>()=>(c||s((c={exports:{}}).exports,c),c.exports),Pe=(s,c)=>{for(var u in c)F(s,u,{get:c[u],enumerable:!0})},W=(s,c,u,l)=>{if(c&&typeof c=="object"||typeof c=="function")for(let p of Oe(c))!Ce.call(s,p)&&p!==u&&F(s,p,{get:()=>c[p],enumerable:!(l=_e(c,p))||l.enumerable});return s},i=(s,c,u)=>(W(s,c,"default"),u&&W(u,c,"default")),S=(s,c,u)=>(u=s!=null?Re(Me(s)):{},W(c||!s||!s.__esModule?F(u,"default",{value:s,enumerable:!0}):u,s)),Te=s=>W(F({},"__esModule",{value:!0}),s);var fe=Ae((We,ie)=>{"use strict";var oe=function(s){"use strict";var c=Object.prototype,u=c.hasOwnProperty,l,p=typeof Symbol=="function"?Symbol:{},m=p.iterator||"@@iterator",C=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 N(t,e,r,a){var n=e&&e.prototype instanceof X?e:X,f=Object.create(n.prototype),g=new te(a||[]);return f._invoke=Ie(t,r,g),f}s.wrap=N;function P(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var G="suspendedStart",J="suspendedYield",d="executing",I="completed",v={};function X(){}function V(){}function L(){}var Q={};y(Q,m,function(){return this});var Z=Object.getPrototypeOf,D=Z&&Z(Z(re([])));D&&D!==c&&u.call(D,m)&&(Q=D);var _=L.prototype=X.prototype=Object.create(Q);V.prototype=L,y(_,"constructor",L),y(L,"constructor",V),V.displayName=y(L,A,"GeneratorFunction");function ce(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===V||(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 U(t,e){function r(f,g,w,E){var b=P(t[f],t,g);if(b.type==="throw")E(b.arg);else{var ne=b.arg,T=ne.value;return T&&typeof T=="object"&&u.call(T,"__await")?e.resolve(T.__await).then(function(R){r("next",R,w,E)},function(R){r("throw",R,w,E)}):e.resolve(T).then(function(R){ne.value=R,w(ne)},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}ce(U.prototype),y(U.prototype,C,function(){return this}),s.AsyncIterator=U,s.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var f=new U(N(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=G;return function(f,g){if(a===d)throw new Error("Generator is already running");if(a===I){if(f==="throw")throw g;return ue()}for(r.method=f,r.arg=g;;){var w=r.delegate;if(w){var E=le(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===G)throw a=I,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=d;var b=P(t,e,r);if(b.type==="normal"){if(a=r.done?I:J,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 le(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,le(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=P(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}ce(_),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 ee(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function te(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 re(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:ue}}s.values=re;function ue(){return{value:l,done:!0}}return te.prototype={constructor:te,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(ee),!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),ee(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;ee(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:re(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=l),v}},s}(typeof ie=="object"?ie.exports:{});try{regeneratorRuntime=oe}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=oe:Function("r","regeneratorRuntime = r")(oe)}});var o={};Pe(o,{Magic:()=>De,useInternetConnection:()=>$});module.exports=Te(o);var ze=S(fe()),be=require("@magic-sdk/provider"),Ve=S(require("process")),H=require("whatwg-url"),z=require("buffer"),Ee=S(require("lodash")),Se=S(require("expo-application"));var h=S(require("react")),K=require("react-native"),ve=require("react-native-webview"),ye=require("react-native-safe-area-context"),O=require("@magic-sdk/provider"),q=require("@magic-sdk/types"),ge=require("lodash"),k=S(require("@react-native-async-storage/async-storage")),se=require("react-native-event-listeners");var B=require("react"),he=S(require("@react-native-community/netinfo")),$=()=>{let[s,c]=(0,B.useState)(!0);return(0,B.useEffect)(()=>{let u=l=>{c(!!l.isConnected)};return he.default.addEventListener(u)},[]),s};var ae=require("react-native"),pe=async s=>{await ae.Linking.canOpenURL(s)?await ae.Linking.openURL(s):console.warn(`Cannot open URL: ${s}`)};var me="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",ke="open_in_device_browser",Ne="#FFFFFF",de="msg_posted_after_inactivity_event",Y="lastMessageTime";function Ge(){return K.StyleSheet.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var j=class extends O.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),C=$();(0,h.useEffect)(()=>{this.isConnectedToInternet=C},[C]),(0,h.useEffect)(()=>this.on(q.MagicIncomingWindowMessage.MAGIC_OPEN_MOBILE_URL,I=>{let v=I.data.response.result?.url;v&&pe(v)}),[]),(0,h.useEffect)(()=>(k.default.setItem(Y,""),()=>{this.isReadyForRequest=!1}),[]),(0,h.useEffect)(()=>{se.EventRegister.addEventListener(de,async d=>{this.isReadyForRequest=!1,m(!1),this.post(d.msgType,d.payload),await k.default.setItem(Y,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:N,hideOverlay:P}},[]),N=(0,h.useCallback)(()=>{l(!0)},[]),P=(0,h.useCallback)(()=>{l(!1)},[]),G=(0,h.useMemo)(()=>[this.styles["webview-container"],u?{...this.styles.show,backgroundColor:c??Ne}:this.styles.hide],[u]),J=(0,h.useCallback)(d=>{this.handleReactNativeWebViewMessage(d)},[]);return p?h.default.createElement(ye.SafeAreaView,{ref:y,style:G},h.default.createElement(ve.WebView,{ref:A,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:J,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:d=>new URLSearchParams(d.url.split("?")[1]).get(ke)?(K.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===me)return new global[m.constructor](m.data.split(","))}catch{}return m});if(l&&l.msgType&&this.messageHandlers.size){l.response=l.response??{},l.response?.error?.code===q.RPCErrorCode.DpopInvalidated&&(0,O.clearKeys)();let p={data:l};for(let m of this.messageHandlers.values())m(p)}}}async msgPostedAfterInactivity(){let c=await k.default.getItem(Y);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()){se.EventRegister.emit(de,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:me}:l)),k.default.setItem(Y,new Date().toISOString());else throw(0,O.createModalNotReadyError)()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var we=require("@magic-sdk/provider"),x=class extends we.SDKBase{get Relayer(){return this.overlay.Relayer}};var M=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=z.Buffer;global.URL=H.URL;global.URLSearchParams=H.URLSearchParams;global.btoa=s=>z.Buffer.from(s,"binary").toString("base64");global.atob=s=>z.Buffer.from(s,"base64").toString("binary");var De=(0,be.createSDK)(x,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"34.8.0",bundleId:Se.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:j,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:M.default.getItem,setItem:M.default.setItem,removeItem:M.default.removeItem,clear:M.default.clear,length:()=>{},key:()=>{},keys:M.default.getAllKeys,iterate:()=>{}})});0&&(module.exports={Magic,useInternetConnection,...require("@magic-sdk/provider"),...require("@magic-sdk/types")});
1
+ "use strict";var Re=Object.create;var F=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Me=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Ae=(s,c)=>()=>(c||s((c={exports:{}}).exports,c),c.exports),Pe=(s,c)=>{for(var u in c)F(s,u,{get:c[u],enumerable:!0})},W=(s,c,u,l)=>{if(c&&typeof c=="object"||typeof c=="function")for(let p of Oe(c))!Ce.call(s,p)&&p!==u&&F(s,p,{get:()=>c[p],enumerable:!(l=_e(c,p))||l.enumerable});return s},i=(s,c,u)=>(W(s,c,"default"),u&&W(u,c,"default")),S=(s,c,u)=>(u=s!=null?Re(Me(s)):{},W(c||!s||!s.__esModule?F(u,"default",{value:s,enumerable:!0}):u,s)),Te=s=>W(F({},"__esModule",{value:!0}),s);var fe=Ae((We,ie)=>{"use strict";var oe=function(s){"use strict";var c=Object.prototype,u=c.hasOwnProperty,l,p=typeof Symbol=="function"?Symbol:{},m=p.iterator||"@@iterator",C=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 N(t,e,r,a){var n=e&&e.prototype instanceof X?e:X,f=Object.create(n.prototype),g=new te(a||[]);return f._invoke=Ie(t,r,g),f}s.wrap=N;function P(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var G="suspendedStart",J="suspendedYield",d="executing",I="completed",v={};function X(){}function V(){}function L(){}var Q={};y(Q,m,function(){return this});var Z=Object.getPrototypeOf,D=Z&&Z(Z(re([])));D&&D!==c&&u.call(D,m)&&(Q=D);var _=L.prototype=X.prototype=Object.create(Q);V.prototype=L,y(_,"constructor",L),y(L,"constructor",V),V.displayName=y(L,A,"GeneratorFunction");function ce(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===V||(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 U(t,e){function r(f,g,w,E){var b=P(t[f],t,g);if(b.type==="throw")E(b.arg);else{var ne=b.arg,T=ne.value;return T&&typeof T=="object"&&u.call(T,"__await")?e.resolve(T.__await).then(function(R){r("next",R,w,E)},function(R){r("throw",R,w,E)}):e.resolve(T).then(function(R){ne.value=R,w(ne)},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}ce(U.prototype),y(U.prototype,C,function(){return this}),s.AsyncIterator=U,s.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var f=new U(N(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=G;return function(f,g){if(a===d)throw new Error("Generator is already running");if(a===I){if(f==="throw")throw g;return ue()}for(r.method=f,r.arg=g;;){var w=r.delegate;if(w){var E=le(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===G)throw a=I,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=d;var b=P(t,e,r);if(b.type==="normal"){if(a=r.done?I:J,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 le(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,le(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=P(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}ce(_),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 ee(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function te(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 re(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:ue}}s.values=re;function ue(){return{value:l,done:!0}}return te.prototype={constructor:te,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(ee),!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),ee(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;ee(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:re(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=l),v}},s}(typeof ie=="object"?ie.exports:{});try{regeneratorRuntime=oe}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=oe:Function("r","regeneratorRuntime = r")(oe)}});var o={};Pe(o,{Magic:()=>De,useInternetConnection:()=>$});module.exports=Te(o);var ze=S(fe()),be=require("@magic-sdk/provider"),Ve=S(require("process")),H=require("whatwg-url"),z=require("buffer"),Ee=S(require("lodash")),Se=S(require("expo-application"));var h=S(require("react")),K=require("react-native"),ve=require("react-native-webview"),ye=require("react-native-safe-area-context"),O=require("@magic-sdk/provider"),q=require("@magic-sdk/types"),ge=require("lodash"),k=S(require("@react-native-async-storage/async-storage")),se=require("react-native-event-listeners");var B=require("react"),he=S(require("@react-native-community/netinfo")),$=()=>{let[s,c]=(0,B.useState)(!0);return(0,B.useEffect)(()=>{let u=l=>{c(!!l.isConnected)};return he.default.addEventListener(u)},[]),s};var ae=require("react-native"),pe=async s=>{await ae.Linking.canOpenURL(s)?await ae.Linking.openURL(s):console.warn(`Cannot open URL: ${s}`)};var me="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",ke="open_in_device_browser",Ne="#FFFFFF",de="msg_posted_after_inactivity_event",Y="lastMessageTime";function Ge(){return K.StyleSheet.create({"magic-webview":{flex:1,backgroundColor:"transparent"},"webview-container":{flex:1,width:"100%",backgroundColor:"transparent",position:"absolute",top:0,left:0,right:0,bottom:0},show:{zIndex:1e4,elevation:1e4},hide:{zIndex:-1e4,elevation:0}})}var j=class extends O.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),C=$();(0,h.useEffect)(()=>{this.isConnectedToInternet=C},[C]),(0,h.useEffect)(()=>this.on(q.MagicIncomingWindowMessage.MAGIC_OPEN_MOBILE_URL,I=>{let v=I.data.response.result?.url;v&&pe(v)}),[]),(0,h.useEffect)(()=>(k.default.setItem(Y,""),()=>{this.isReadyForRequest=!1}),[]),(0,h.useEffect)(()=>{se.EventRegister.addEventListener(de,async d=>{this.isReadyForRequest=!1,m(!1),this.post(d.msgType,d.payload),await k.default.setItem(Y,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:N,hideOverlay:P}},[]),N=(0,h.useCallback)(()=>{l(!0)},[]),P=(0,h.useCallback)(()=>{l(!1)},[]),G=(0,h.useMemo)(()=>[this.styles["webview-container"],u?{...this.styles.show,backgroundColor:c??Ne}:this.styles.hide],[u]),J=(0,h.useCallback)(d=>{this.handleReactNativeWebViewMessage(d)},[]);return p?h.default.createElement(ye.SafeAreaView,{ref:y,style:G},h.default.createElement(ve.WebView,{ref:A,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:J,style:this.styles["magic-webview"],autoManageStatusBarEnabled:!1,webviewDebuggingEnabled:!0,onShouldStartLoadWithRequest:d=>new URLSearchParams(d.url.split("?")[1]).get(ke)?(K.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===me)return new global[m.constructor](m.data.split(","))}catch{}return m});if(l&&l.msgType&&this.messageHandlers.size){l.response=l.response??{},l.response?.error?.code===q.RPCErrorCode.DpopInvalidated&&(0,O.clearKeys)();let p={data:l};for(let m of this.messageHandlers.values())m(p)}}}async msgPostedAfterInactivity(){let c=await k.default.getItem(Y);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()){se.EventRegister.emit(de,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:me}:l)),k.default.setItem(Y,new Date().toISOString());else throw(0,O.createModalNotReadyError)()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};var we=require("@magic-sdk/provider"),x=class extends we.SDKBase{get Relayer(){return this.overlay.Relayer}};var M=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=z.Buffer;global.URL=H.URL;global.URLSearchParams=H.URLSearchParams;global.btoa=s=>z.Buffer.from(s,"binary").toString("base64");global.atob=s=>z.Buffer.from(s,"base64").toString("binary");var De=(0,be.createSDK)(x,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"34.8.1",bundleId:Se.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:j,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:M.default.getItem,setItem:M.default.setItem,removeItem:M.default.removeItem,clear:M.default.clear,length:()=>{},key:()=>{},keys:M.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((je,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 A(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=A;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(A(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 pt=we(te());import{createSDK as Ue}from"@magic-sdk/provider";import*as We from"process";import{URL as Fe,URLSearchParams as Be}from"whatwg-url";import{Buffer as J}from"buffer";import $e 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 Ce,clearKeys as Ae}from"@magic-sdk/provider";import{MagicIncomingWindowMessage as Pe,RPCErrorCode as Te}from"@magic-sdk/types";import{isTypedArray as ke}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",Ne="open_in_device_browser",Ge="#FFFFFF",ce="msg_posted_after_inactivity_event",V="lastMessageTime";function Ve(){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=Ve()}Relayer=a=>{let[c,s]=ie(!1),[u,f]=ie(!0),I=z();M(()=>{this.isConnectedToInternet=I},[I]),M(()=>this.on(Pe.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:A,hideOverlay:R}},[]),A=O(()=>{s(!0)},[]),R=O(()=>{s(!1)},[]),P=Ie(()=>[this.styles["webview-container"],c?{...this.styles.show,backgroundColor:a??Ge}: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(Ne)?(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??{},s.response?.error?.code===Te.DpopInvalidated&&Ae();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)=>ke(s)?{constructor:s.constructor.name,data:s.toString(),flag:se}:s)),G.setItem(V,new Date().toISOString());else throw Ce()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as De}from"@magic-sdk/provider";var U=class extends De{get Relayer(){return this.overlay.Relayer}};import C from"@react-native-async-storage/async-storage";export*from"@magic-sdk/provider";export*from"@magic-sdk/types";global.process=$e.merge(global.process,We);global.process.browser=!1;global.Buffer=J;global.URL=Fe;global.URLSearchParams=Be;global.btoa=i=>J.from(i,"binary").toString("base64");global.atob=i=>J.from(i,"base64").toString("binary");var It=Ue(U,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"34.8.0",bundleId:le.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:C.getItem,setItem:C.setItem,removeItem:C.removeItem,clear:C.clear,length:()=>{},key:()=>{},keys:C.getAllKeys,iterate:()=>{}})});export{It 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((je,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 A(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=A;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(A(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 pt=we(te());import{createSDK as Ue}from"@magic-sdk/provider";import*as We from"process";import{URL as Fe,URLSearchParams as Be}from"whatwg-url";import{Buffer as J}from"buffer";import $e 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 Ce,clearKeys as Ae}from"@magic-sdk/provider";import{MagicIncomingWindowMessage as Pe,RPCErrorCode as Te}from"@magic-sdk/types";import{isTypedArray as ke}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",Ne="open_in_device_browser",Ge="#FFFFFF",ce="msg_posted_after_inactivity_event",V="lastMessageTime";function Ve(){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=Ve()}Relayer=a=>{let[c,s]=ie(!1),[u,f]=ie(!0),I=z();M(()=>{this.isConnectedToInternet=I},[I]),M(()=>this.on(Pe.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:A,hideOverlay:R}},[]),A=O(()=>{s(!0)},[]),R=O(()=>{s(!1)},[]),P=Ie(()=>[this.styles["webview-container"],c?{...this.styles.show,backgroundColor:a??Ge}: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(Ne)?(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??{},s.response?.error?.code===Te.DpopInvalidated&&Ae();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)=>ke(s)?{constructor:s.constructor.name,data:s.toString(),flag:se}:s)),G.setItem(V,new Date().toISOString());else throw Ce()}checkRelayerExistsInDOM(){return Promise.resolve(!0)}reloadRelayer(){return Promise.resolve(void 0)}};import{SDKBase as De}from"@magic-sdk/provider";var U=class extends De{get Relayer(){return this.overlay.Relayer}};import C from"@react-native-async-storage/async-storage";export*from"@magic-sdk/provider";export*from"@magic-sdk/types";global.process=$e.merge(global.process,We);global.process.browser=!1;global.Buffer=J;global.URL=Fe;global.URLSearchParams=Be;global.btoa=i=>J.from(i,"binary").toString("base64");global.atob=i=>J.from(i,"base64").toString("binary");var It=Ue(U,{platform:"react-native",sdkName:"@magic-sdk/react-native-expo",version:"34.8.1",bundleId:le.applicationId,defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:async()=>({ready:async()=>Promise.resolve(!0),getItem:C.getItem,setItem:C.setItem,removeItem:C.removeItem,clear:C.clear,length:()=>{},key:()=>{},keys:C.getAllKeys,iterate:()=>{}})});export{It 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.8.1-canary.1106.28906316739.0",
3
+ "version": "34.8.1",
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": "5e57149d7faa99c7683445b0f9898623fb451929"
57
+ "gitHead": "403e9520db8297cb57f017ac63fb5946c7c86316"
58
58
  }