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