@magic-sdk/react-native-bare 26.1.0-canary.721.8211087936.0 → 27.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.js +1 -1
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var Ie=Object.create;var P=Object.defineProperty,Ne=Object.defineProperties,Te=Object.getOwnPropertyDescriptor,Me=Object.getOwnPropertyDescriptors,Ae=Object.getOwnPropertyNames,fe=Object.getOwnPropertySymbols,Ce=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var le=(n,a,o)=>a in n?P(n,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[a]=o,re=(n,a)=>{for(var o in a||(a={}))he.call(a,o)&&le(n,o,a[o]);if(fe)for(var o of fe(a))Ve.call(a,o)&&le(n,o,a[o]);return n},ne=(n,a)=>Ne(n,Me(a));var Ge=(n,a)=>()=>(a||n((a={exports:{}}).exports,a),a.exports),Pe=(n,a)=>{for(var o in a)P(n,o,{get:a[o],enumerable:!0})},B=(n,a,o,p)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Ae(a))!he.call(n,c)&&c!==o&&P(n,c,{get:()=>a[c],enumerable:!(p=Te(a,c))||p.enumerable});return n},l=(n,a,o)=>(B(n,a,"default"),o&&B(o,a,"default")),T=(n,a,o)=>(o=n!=null?Ie(Ce(n)):{},B(a||!n||!n.__esModule?P(o,"default",{value:n,enumerable:!0}):o,n)),De=n=>B(P({},"__esModule",{value:!0}),n);var U=(n,a,o)=>new Promise((p,c)=>{var y=m=>{try{L(o.next(m))}catch(v){c(v)}},h=m=>{try{L(o.throw(m))}catch(v){c(v)}},L=m=>m.done?p(m.value):Promise.resolve(m.value).then(y,h);L((o=o.apply(n,a)).next())});var pe=Ge((Ye,ie)=>{var oe=function(n){"use strict";var a=Object.prototype,o=a.hasOwnProperty,p=Object.defineProperty||function(t,e,r){t[e]=r.value},c,y=typeof Symbol=="function"?Symbol:{},h=y.iterator||"@@iterator",L=y.asyncIterator||"@@asyncIterator",m=y.toStringTag||"@@toStringTag";function v(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{v({},"")}catch{v=function(e,r,s){return e[r]=s}}function D(t,e,r,s){var i=e&&e.prototype instanceof x?e:x,u=Object.create(i.prototype),g=new Z(s||[]);return p(u,"_invoke",{value:_e(t,r,g)}),u}n.wrap=D;function V(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(s){return{type:"throw",arg:s}}}var S="suspendedStart",O="suspendedYield",M="executing",_="completed",R={};function x(){}function k(){}function I(){}var H={};v(H,h,function(){return this});var Q=Object.getPrototypeOf,W=Q&&Q(Q(ee([])));W&&W!==a&&o.call(W,h)&&(H=W);var A=I.prototype=x.prototype=Object.create(H);k.prototype=I,p(A,"constructor",{value:I,configurable:!0}),p(I,"constructor",{value:k,configurable:!0}),k.displayName=v(I,m,"GeneratorFunction");function se(t){["next","throw","return"].forEach(function(e){v(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,I):(t.__proto__=I,v(t,m,"GeneratorFunction")),t.prototype=Object.create(A),t},n.awrap=function(t){return{__await:t}};function j(t,e){function r(u,g,w,E){var b=V(t[u],t,g);if(b.type==="throw")E(b.arg);else{var te=b.arg,G=te.value;return G&&typeof G=="object"&&o.call(G,"__await")?e.resolve(G.__await).then(function(N){r("next",N,w,E)},function(N){r("throw",N,w,E)}):e.resolve(G).then(function(N){te.value=N,w(te)},function(N){return r("throw",N,w,E)})}}var s;function i(u,g){function w(){return new e(function(E,b){r(u,g,E,b)})}return s=s?s.then(w,w):w()}p(this,"_invoke",{value:i})}se(j.prototype),v(j.prototype,L,function(){return this}),n.AsyncIterator=j,n.async=function(t,e,r,s,i){i===void 0&&(i=Promise);var u=new j(D(t,e,r,s),i);return n.isGeneratorFunction(e)?u:u.next().then(function(g){return g.done?g.value:u.next()})};function _e(t,e,r){var s=S;return function(u,g){if(s===M)throw new Error("Generator is already running");if(s===_){if(u==="throw")throw g;return ue()}for(r.method=u,r.arg=g;;){var w=r.delegate;if(w){var E=ce(w,r);if(E){if(E===R)continue;return E}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(s===S)throw s=_,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);s=M;var b=V(t,e,r);if(b.type==="normal"){if(s=r.done?_:O,b.arg===R)continue;return{value:b.arg,done:r.done}}else b.type==="throw"&&(s=_,r.method="throw",r.arg=b.arg)}}}function ce(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,ce(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),R;var i=V(s,t.iterator,e.arg);if(i.type==="throw")return e.method="throw",e.arg=i.arg,e.delegate=null,R;var u=i.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,R;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,R}se(A),v(A,m,"Generator"),v(A,h,function(){return this}),v(A,"toString",function(){return"[object Generator]"});function Oe(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 X(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function Z(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Oe,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 ee(t){if(t){var e=t[h];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:ue}}n.values=ee;function ue(){return{value:c,done:!0}}return Z.prototype={constructor:Z,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(X),!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(E,b){return u.type="throw",u.arg=t,e.next=E,b&&(e.method="next",e.arg=c),!!b}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 g=o.call(i,"catchLoc"),w=o.call(i,"finallyLoc");if(g&&w){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(g){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else if(w){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,R):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),R},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),X(r),R}},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;X(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:ee(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),R}},n}(typeof ie=="object"?ie.exports:{});try{regeneratorRuntime=oe}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=oe:Function("r","regeneratorRuntime = r")(oe)}});var f={};Pe(f,{Magic:()=>Ue,useInternetConnection:()=>Y});module.exports=De(f);var He=T(pe()),be=require("@magic-sdk/provider"),Be=T(require("process")),Se=T(require("localforage")),z=require("whatwg-url"),J=require("buffer"),Ee=T(require("lodash")),Le=require("react-native-device-info"),Re=require("@aveq-research/localforage-asyncstorage-driver"),ae=T(require("localforage-driver-memory"));var d=T(require("react")),$=require("react-native"),de=require("react-native-webview"),ye=require("react-native-safe-area-context"),C=require("@magic-sdk/provider"),ge=require("lodash");var F=require("react"),me=T(require("@react-native-community/netinfo")),Y=()=>{let[n,a]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{let o=p=>{a(!!p.isConnected)};return me.default.addEventListener(o)},[]),n};var ve="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",ke="open_in_device_browser",We="#FFFFFF";function je(){return $.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 K=class extends C.ViewController{constructor(){super(...arguments);this.messageTimeouts=new Map;this.Relayer=o=>{let[p,c]=(0,d.useState)(!1),y=Y();(0,d.useEffect)(()=>{this.isConnectedToInternet=y},[y]),(0,d.useEffect)(()=>()=>{this.isReadyForRequest=!1},[]);let h=(0,d.useCallback)(S=>{this.webView=S},[]),L=(0,d.useCallback)(S=>{this.container=ne(re({},S),{showOverlay:m,hideOverlay:v})},[]),m=(0,d.useCallback)(()=>{c(!0)},[]),v=(0,d.useCallback)(()=>{c(!1)},[]),D=(0,d.useMemo)(()=>[this.styles["webview-container"],p?ne(re({},this.styles.show),{backgroundColor:o!=null?o:We}):this.styles.hide],[p]),V=(0,d.useCallback)(S=>{var M;let O=JSON.parse(S.nativeEvent.data);if((M=O==null?void 0:O.response)!=null&&M.id){let _=O.response.id;this.messageTimeouts.has(_)&&(clearTimeout(this.messageTimeouts.get(_)),this.messageTimeouts.delete(_))}this.handleReactNativeWebViewMessage(S)},[]);return d.default.createElement(ye.SafeAreaView,{ref:L,style:D},d.default.createElement(de.WebView,{ref:h,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:V,style:this.styles["magic-webview"],webviewDebuggingEnabled:!0,autoManageStatusBarEnabled:!1,onShouldStartLoadWithRequest:S=>new URLSearchParams(S.url.split("?")[1]).get(ke)?($.Linking.openURL(S.url),!1):!0}))}}init(){this.webView=null,this.container=null,this.styles=je()}handleReactNativeWebViewMessage(o){var p;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}`)){let c=JSON.parse(o.nativeEvent.data,(y,h)=>{try{if(h&&typeof h=="object"&&h.flag&&h.flag===ve)return new global[h.constructor](h.data.split(","))}catch(L){}return h});if(c&&c.msgType&&this.messageHandlers.size){c.response=(p=c.response)!=null?p:{};let y={data:c};for(let h of this.messageHandlers.values())h(y)}}}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(o){return U(this,null,function*(){var y,h;let p=(y=o.payload)==null?void 0:y.method,c=(h=o.payload)==null?void 0:h.id;if(this.webView&&this.webView.postMessage){if(p&&c){let L=setTimeout(()=>{throw this.messageTimeouts.delete(c),(0,C.createResponseTimeoutError)(p,c)},1e4);this.messageTimeouts.set(c,L)}this.webView.postMessage(JSON.stringify(o,(L,m)=>(0,ge.isTypedArray)(m)?{constructor:m.constructor.name,data:m.toString(),flag:ve}:m),this.endpoint)}else throw(0,C.createModalNotReadyError)()})}};var we=require("@magic-sdk/provider"),q=class extends we.SDKBase{get Relayer(){return this.overlay.Relayer}};l(f,require("@magic-sdk/commons"),module.exports);global.process=Ee.merge(global.process,Be);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 Ue=(0,be.createSDK)(q,{platform:"react-native",sdkName:"@magic-sdk/react-native-bare",version:"26.0.0",bundleId:(0,Le.getBundleId)(),defaultEndpoint:"https://box.magic.link/",ViewController:K,configureStorage:()=>U(void 0,null,function*(){let n=Se.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),a=(0,Re.driverWithoutSerialization)();return yield Promise.all([n.defineDriver(a),n.defineDriver(ae)]),yield n.setDriver([a._driver,ae._driver]),n})});0&&(module.exports={Magic,useInternetConnection});
|
1
|
+
"use strict";var Ie=Object.create;var P=Object.defineProperty,Ne=Object.defineProperties,Te=Object.getOwnPropertyDescriptor,Me=Object.getOwnPropertyDescriptors,Ae=Object.getOwnPropertyNames,fe=Object.getOwnPropertySymbols,Ce=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var le=(n,a,o)=>a in n?P(n,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[a]=o,re=(n,a)=>{for(var o in a||(a={}))he.call(a,o)&&le(n,o,a[o]);if(fe)for(var o of fe(a))Ve.call(a,o)&&le(n,o,a[o]);return n},ne=(n,a)=>Ne(n,Me(a));var Ge=(n,a)=>()=>(a||n((a={exports:{}}).exports,a),a.exports),Pe=(n,a)=>{for(var o in a)P(n,o,{get:a[o],enumerable:!0})},B=(n,a,o,p)=>{if(a&&typeof a=="object"||typeof a=="function")for(let c of Ae(a))!he.call(n,c)&&c!==o&&P(n,c,{get:()=>a[c],enumerable:!(p=Te(a,c))||p.enumerable});return n},l=(n,a,o)=>(B(n,a,"default"),o&&B(o,a,"default")),T=(n,a,o)=>(o=n!=null?Ie(Ce(n)):{},B(a||!n||!n.__esModule?P(o,"default",{value:n,enumerable:!0}):o,n)),De=n=>B(P({},"__esModule",{value:!0}),n);var U=(n,a,o)=>new Promise((p,c)=>{var y=m=>{try{L(o.next(m))}catch(v){c(v)}},h=m=>{try{L(o.throw(m))}catch(v){c(v)}},L=m=>m.done?p(m.value):Promise.resolve(m.value).then(y,h);L((o=o.apply(n,a)).next())});var pe=Ge((Ye,ie)=>{var oe=function(n){"use strict";var a=Object.prototype,o=a.hasOwnProperty,p=Object.defineProperty||function(t,e,r){t[e]=r.value},c,y=typeof Symbol=="function"?Symbol:{},h=y.iterator||"@@iterator",L=y.asyncIterator||"@@asyncIterator",m=y.toStringTag||"@@toStringTag";function v(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{v({},"")}catch{v=function(e,r,s){return e[r]=s}}function D(t,e,r,s){var i=e&&e.prototype instanceof x?e:x,u=Object.create(i.prototype),g=new Z(s||[]);return p(u,"_invoke",{value:_e(t,r,g)}),u}n.wrap=D;function V(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(s){return{type:"throw",arg:s}}}var S="suspendedStart",O="suspendedYield",M="executing",_="completed",R={};function x(){}function k(){}function I(){}var H={};v(H,h,function(){return this});var Q=Object.getPrototypeOf,W=Q&&Q(Q(ee([])));W&&W!==a&&o.call(W,h)&&(H=W);var A=I.prototype=x.prototype=Object.create(H);k.prototype=I,p(A,"constructor",{value:I,configurable:!0}),p(I,"constructor",{value:k,configurable:!0}),k.displayName=v(I,m,"GeneratorFunction");function se(t){["next","throw","return"].forEach(function(e){v(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,I):(t.__proto__=I,v(t,m,"GeneratorFunction")),t.prototype=Object.create(A),t},n.awrap=function(t){return{__await:t}};function j(t,e){function r(u,g,w,E){var b=V(t[u],t,g);if(b.type==="throw")E(b.arg);else{var te=b.arg,G=te.value;return G&&typeof G=="object"&&o.call(G,"__await")?e.resolve(G.__await).then(function(N){r("next",N,w,E)},function(N){r("throw",N,w,E)}):e.resolve(G).then(function(N){te.value=N,w(te)},function(N){return r("throw",N,w,E)})}}var s;function i(u,g){function w(){return new e(function(E,b){r(u,g,E,b)})}return s=s?s.then(w,w):w()}p(this,"_invoke",{value:i})}se(j.prototype),v(j.prototype,L,function(){return this}),n.AsyncIterator=j,n.async=function(t,e,r,s,i){i===void 0&&(i=Promise);var u=new j(D(t,e,r,s),i);return n.isGeneratorFunction(e)?u:u.next().then(function(g){return g.done?g.value:u.next()})};function _e(t,e,r){var s=S;return function(u,g){if(s===M)throw new Error("Generator is already running");if(s===_){if(u==="throw")throw g;return ue()}for(r.method=u,r.arg=g;;){var w=r.delegate;if(w){var E=ce(w,r);if(E){if(E===R)continue;return E}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(s===S)throw s=_,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);s=M;var b=V(t,e,r);if(b.type==="normal"){if(s=r.done?_:O,b.arg===R)continue;return{value:b.arg,done:r.done}}else b.type==="throw"&&(s=_,r.method="throw",r.arg=b.arg)}}}function ce(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,ce(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),R;var i=V(s,t.iterator,e.arg);if(i.type==="throw")return e.method="throw",e.arg=i.arg,e.delegate=null,R;var u=i.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,R;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,R}se(A),v(A,m,"Generator"),v(A,h,function(){return this}),v(A,"toString",function(){return"[object Generator]"});function Oe(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 X(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function Z(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(Oe,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 ee(t){if(t){var e=t[h];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:ue}}n.values=ee;function ue(){return{value:c,done:!0}}return Z.prototype={constructor:Z,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(X),!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(E,b){return u.type="throw",u.arg=t,e.next=E,b&&(e.method="next",e.arg=c),!!b}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 g=o.call(i,"catchLoc"),w=o.call(i,"finallyLoc");if(g&&w){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(g){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else if(w){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,R):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),R},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),X(r),R}},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;X(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:ee(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),R}},n}(typeof ie=="object"?ie.exports:{});try{regeneratorRuntime=oe}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=oe:Function("r","regeneratorRuntime = r")(oe)}});var f={};Pe(f,{Magic:()=>Ue,useInternetConnection:()=>Y});module.exports=De(f);var He=T(pe()),be=require("@magic-sdk/provider"),Be=T(require("process")),Se=T(require("localforage")),z=require("whatwg-url"),J=require("buffer"),Ee=T(require("lodash")),Le=require("react-native-device-info"),Re=require("@aveq-research/localforage-asyncstorage-driver"),ae=T(require("localforage-driver-memory"));var d=T(require("react")),$=require("react-native"),de=require("react-native-webview"),ye=require("react-native-safe-area-context"),C=require("@magic-sdk/provider"),ge=require("lodash");var F=require("react"),me=T(require("@react-native-community/netinfo")),Y=()=>{let[n,a]=(0,F.useState)(!0);return(0,F.useEffect)(()=>{let o=p=>{a(!!p.isConnected)};return me.default.addEventListener(o)},[]),n};var ve="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",ke="open_in_device_browser",We="#FFFFFF";function je(){return $.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 K=class extends C.ViewController{constructor(){super(...arguments);this.messageTimeouts=new Map;this.Relayer=o=>{let[p,c]=(0,d.useState)(!1),y=Y();(0,d.useEffect)(()=>{this.isConnectedToInternet=y},[y]),(0,d.useEffect)(()=>()=>{this.isReadyForRequest=!1},[]);let h=(0,d.useCallback)(S=>{this.webView=S},[]),L=(0,d.useCallback)(S=>{this.container=ne(re({},S),{showOverlay:m,hideOverlay:v})},[]),m=(0,d.useCallback)(()=>{c(!0)},[]),v=(0,d.useCallback)(()=>{c(!1)},[]),D=(0,d.useMemo)(()=>[this.styles["webview-container"],p?ne(re({},this.styles.show),{backgroundColor:o!=null?o:We}):this.styles.hide],[p]),V=(0,d.useCallback)(S=>{var M;let O=JSON.parse(S.nativeEvent.data);if((M=O==null?void 0:O.response)!=null&&M.id){let _=O.response.id;this.messageTimeouts.has(_)&&(clearTimeout(this.messageTimeouts.get(_)),this.messageTimeouts.delete(_))}this.handleReactNativeWebViewMessage(S)},[]);return d.default.createElement(ye.SafeAreaView,{ref:L,style:D},d.default.createElement(de.WebView,{ref:h,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:V,style:this.styles["magic-webview"],webviewDebuggingEnabled:!0,autoManageStatusBarEnabled:!1,onShouldStartLoadWithRequest:S=>new URLSearchParams(S.url.split("?")[1]).get(ke)?($.Linking.openURL(S.url),!1):!0}))}}init(){this.webView=null,this.container=null,this.styles=je()}handleReactNativeWebViewMessage(o){var p;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}`)){let c=JSON.parse(o.nativeEvent.data,(y,h)=>{try{if(h&&typeof h=="object"&&h.flag&&h.flag===ve)return new global[h.constructor](h.data.split(","))}catch(L){}return h});if(c&&c.msgType&&this.messageHandlers.size){c.response=(p=c.response)!=null?p:{};let y={data:c};for(let h of this.messageHandlers.values())h(y)}}}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(o){return U(this,null,function*(){var y,h;let p=(y=o.payload)==null?void 0:y.method,c=(h=o.payload)==null?void 0:h.id;if(this.webView&&this.webView.postMessage){if(p&&c){let L=setTimeout(()=>{throw this.messageTimeouts.delete(c),(0,C.createResponseTimeoutError)(p,c)},1e4);this.messageTimeouts.set(c,L)}this.webView.postMessage(JSON.stringify(o,(L,m)=>(0,ge.isTypedArray)(m)?{constructor:m.constructor.name,data:m.toString(),flag:ve}:m),this.endpoint)}else throw(0,C.createModalNotReadyError)()})}};var we=require("@magic-sdk/provider"),q=class extends we.SDKBase{get Relayer(){return this.overlay.Relayer}};l(f,require("@magic-sdk/commons"),module.exports);global.process=Ee.merge(global.process,Be);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 Ue=(0,be.createSDK)(q,{platform:"react-native",sdkName:"@magic-sdk/react-native-bare",version:"27.0.0",bundleId:(0,Le.getBundleId)(),defaultEndpoint:"https://box.magic.link/",ViewController:K,configureStorage:()=>U(void 0,null,function*(){let n=Se.default.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),a=(0,Re.driverWithoutSerialization)();return yield Promise.all([n.defineDriver(a),n.defineDriver(ae)]),yield n.setDriver([a._driver,ae._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 he=Object.create;var $=Object.defineProperty,pe=Object.defineProperties,me=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,re=Object.getOwnPropertySymbols,ye=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var ne=(o,s,i)=>s in o?$(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,q=(o,s)=>{for(var i in s||(s={}))oe.call(s,i)&&ne(o,i,s[i]);if(re)for(var i of re(s))ge.call(s,i)&&ne(o,i,s[i]);return o},z=(o,s)=>pe(o,ve(s));var we=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var be=(o,s,i,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of de(s))!oe.call(o,c)&&c!==i&&$(o,c,{get:()=>s[c],enumerable:!(l=me(s,c))||l.enumerable});return o};var Se=(o,s,i)=>(i=o!=null?he(ye(o)):{},be(s||!o||!o.__esModule?$(i,"default",{value:o,enumerable:!0}):i,o));var P=(o,s,i)=>new Promise((l,c)=>{var m=h=>{try{b(i.next(h))}catch(p){c(p)}},f=h=>{try{b(i.throw(h))}catch(p){c(p)}},b=h=>h.done?l(h.value):Promise.resolve(h.value).then(m,f);b((i=i.apply(o,s)).next())});var ie=we((ze,x)=>{var J=function(o){"use strict";var s=Object.prototype,i=s.hasOwnProperty,l=Object.defineProperty||function(t,e,r){t[e]=r.value},c,m=typeof Symbol=="function"?Symbol:{},f=m.iterator||"@@iterator",b=m.asyncIterator||"@@asyncIterator",h=m.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 A(t,e,r,a){var n=e&&e.prototype instanceof W?e:W,u=Object.create(n.prototype),v=new F(a||[]);return l(u,"_invoke",{value:fe(t,r,v)}),u}o.wrap=A;function N(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var g="suspendedStart",L="suspendedYield",O="executing",E="completed",S={};function W(){}function C(){}function R(){}var j={};p(j,f,function(){return this});var B=Object.getPrototypeOf,V=B&&B(B(Y([])));V&&V!==s&&i.call(V,f)&&(j=V);var I=R.prototype=W.prototype=Object.create(j);C.prototype=R,l(I,"constructor",{value:R,configurable:!0}),l(R,"constructor",{value:C,configurable:!0}),C.displayName=p(R,h,"GeneratorFunction");function Z(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===C||(e.displayName||e.name)==="GeneratorFunction":!1},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,R):(t.__proto__=R,p(t,h,"GeneratorFunction")),t.prototype=Object.create(I),t},o.awrap=function(t){return{__await:t}};function G(t,e){function r(u,v,d,w){var y=N(t[u],t,v);if(y.type==="throw")w(y.arg);else{var K=y.arg,T=K.value;return T&&typeof T=="object"&&i.call(T,"__await")?e.resolve(T.__await).then(function(_){r("next",_,d,w)},function(_){r("throw",_,d,w)}):e.resolve(T).then(function(_){K.value=_,d(K)},function(_){return r("throw",_,d,w)})}}var a;function n(u,v){function d(){return new e(function(w,y){r(u,v,w,y)})}return a=a?a.then(d,d):d()}l(this,"_invoke",{value:n})}Z(G.prototype),p(G.prototype,b,function(){return this}),o.AsyncIterator=G,o.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var u=new G(A(t,e,r,a),n);return o.isGeneratorFunction(e)?u:u.next().then(function(v){return v.done?v.value:u.next()})};function fe(t,e,r){var a=g;return function(u,v){if(a===O)throw new Error("Generator is already running");if(a===E){if(u==="throw")throw v;return te()}for(r.method=u,r.arg=v;;){var d=r.delegate;if(d){var w=ee(d,r);if(w){if(w===S)continue;return w}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(a===g)throw a=E,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=O;var y=N(t,e,r);if(y.type==="normal"){if(a=r.done?E:L,y.arg===S)continue;return{value:y.arg,done:r.done}}else y.type==="throw"&&(a=E,r.method="throw",r.arg=y.arg)}}}function ee(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,ee(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),S;var n=N(a,t.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,S;var u=n.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,S;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,S}Z(I),p(I,h,"Generator"),p(I,f,function(){return this}),p(I,"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 U(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function F(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(le,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 Y(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,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:te}}o.values=Y;function te(){return{value:c,done:!0}}return F.prototype={constructor:F,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(U),!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(w,y){return u.type="throw",u.arg=t,e.next=w,y&&(e.method="next",e.arg=c),!!y}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 v=i.call(n,"catchLoc"),d=i.call(n,"finallyLoc");if(v&&d){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(v){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(d){if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var 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,S):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),S},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),U(r),S}},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;U(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:Y(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),S}},o}(typeof x=="object"?x.exports:{});try{regeneratorRuntime=J}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=J:Function("r","regeneratorRuntime = r")(J)}});var ut=Se(ie());import{createSDK as je}from"@magic-sdk/provider";import*as Be from"process";import Ue from"localforage";import{URL as Fe,URLSearchParams as Ye}from"whatwg-url";import{Buffer as Q}from"buffer";import*as ue from"lodash";import{getBundleId as Ke}from"react-native-device-info";import{driverWithoutSerialization as $e}from"@aveq-research/localforage-asyncstorage-driver";import*as X from"localforage-driver-memory";import ae,{useState as _e,useCallback as M,useMemo as Oe,useEffect as se}from"react";import{Linking as Ie,StyleSheet as Ne}from"react-native";import{WebView as Te}from"react-native-webview";import{SafeAreaView as Me}from"react-native-safe-area-context";import{ViewController as Ae,createModalNotReadyError as Ce,createResponseTimeoutError as Ve}from"@magic-sdk/provider";import{isTypedArray as Ge}from"lodash";import{useEffect as Ee,useState as Le}from"react";import Re from"@react-native-community/netinfo";var H=()=>{let[o,s]=Le(!0);return Ee(()=>{let i=l=>{s(!!l.isConnected)};return Re.addEventListener(i)},[]),o};var ce="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Pe="open_in_device_browser",De="#FFFFFF";function ke(){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 D=class extends Ae{constructor(){super(...arguments);this.messageTimeouts=new Map;this.Relayer=i=>{let[l,c]=_e(!1),m=H();se(()=>{this.isConnectedToInternet=m},[m]),se(()=>()=>{this.isReadyForRequest=!1},[]);let f=M(g=>{this.webView=g},[]),b=M(g=>{this.container=z(q({},g),{showOverlay:h,hideOverlay:p})},[]),h=M(()=>{c(!0)},[]),p=M(()=>{c(!1)},[]),A=Oe(()=>[this.styles["webview-container"],l?z(q({},this.styles.show),{backgroundColor:i!=null?i:De}):this.styles.hide],[l]),N=M(g=>{var O;let L=JSON.parse(g.nativeEvent.data);if((O=L==null?void 0:L.response)!=null&&O.id){let E=L.response.id;this.messageTimeouts.has(E)&&(clearTimeout(this.messageTimeouts.get(E)),this.messageTimeouts.delete(E))}this.handleReactNativeWebViewMessage(g)},[]);return ae.createElement(Me,{ref:b,style:A},ae.createElement(Te,{ref:f,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:N,style:this.styles["magic-webview"],webviewDebuggingEnabled:!0,autoManageStatusBarEnabled:!1,onShouldStartLoadWithRequest:g=>new URLSearchParams(g.url.split("?")[1]).get(Pe)?(Ie.openURL(g.url),!1):!0}))}}init(){this.webView=null,this.container=null,this.styles=ke()}handleReactNativeWebViewMessage(i){var l;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}`)){let c=JSON.parse(i.nativeEvent.data,(m,f)=>{try{if(f&&typeof f=="object"&&f.flag&&f.flag===ce)return new global[f.constructor](f.data.split(","))}catch(b){}return f});if(c&&c.msgType&&this.messageHandlers.size){c.response=(l=c.response)!=null?l:{};let m={data:c};for(let f of this.messageHandlers.values())f(m)}}}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(i){return P(this,null,function*(){var m,f;let l=(m=i.payload)==null?void 0:m.method,c=(f=i.payload)==null?void 0:f.id;if(this.webView&&this.webView.postMessage){if(l&&c){let b=setTimeout(()=>{throw this.messageTimeouts.delete(c),Ve(l,c)},1e4);this.messageTimeouts.set(c,b)}this.webView.postMessage(JSON.stringify(i,(b,h)=>Ge(h)?{constructor:h.constructor.name,data:h.toString(),flag:ce}:h),this.endpoint)}else throw Ce()})}};import{SDKBase as We}from"@magic-sdk/provider";var k=class extends We{get Relayer(){return this.overlay.Relayer}};export*from"@magic-sdk/commons";global.process=ue.merge(global.process,Be);global.process.browser=!1;global.Buffer=Q;global.URL=Fe;global.URLSearchParams=Ye;global.btoa=o=>Q.from(o,"binary").toString("base64");global.atob=o=>Q.from(o,"base64").toString("binary");var bt=je(k,{platform:"react-native",sdkName:"@magic-sdk/react-native-bare",version:"26.0.0",bundleId:Ke(),defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:()=>P(void 0,null,function*(){let o=Ue.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),s=$e();return yield Promise.all([o.defineDriver(s),o.defineDriver(X)]),yield o.setDriver([s._driver,X._driver]),o})});export{bt as Magic,H as useInternetConnection};
|
1
|
+
var he=Object.create;var $=Object.defineProperty,pe=Object.defineProperties,me=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,re=Object.getOwnPropertySymbols,ye=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var ne=(o,s,i)=>s in o?$(o,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[s]=i,q=(o,s)=>{for(var i in s||(s={}))oe.call(s,i)&&ne(o,i,s[i]);if(re)for(var i of re(s))ge.call(s,i)&&ne(o,i,s[i]);return o},z=(o,s)=>pe(o,ve(s));var we=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports);var be=(o,s,i,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of de(s))!oe.call(o,c)&&c!==i&&$(o,c,{get:()=>s[c],enumerable:!(l=me(s,c))||l.enumerable});return o};var Se=(o,s,i)=>(i=o!=null?he(ye(o)):{},be(s||!o||!o.__esModule?$(i,"default",{value:o,enumerable:!0}):i,o));var P=(o,s,i)=>new Promise((l,c)=>{var m=h=>{try{b(i.next(h))}catch(p){c(p)}},f=h=>{try{b(i.throw(h))}catch(p){c(p)}},b=h=>h.done?l(h.value):Promise.resolve(h.value).then(m,f);b((i=i.apply(o,s)).next())});var ie=we((ze,x)=>{var J=function(o){"use strict";var s=Object.prototype,i=s.hasOwnProperty,l=Object.defineProperty||function(t,e,r){t[e]=r.value},c,m=typeof Symbol=="function"?Symbol:{},f=m.iterator||"@@iterator",b=m.asyncIterator||"@@asyncIterator",h=m.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 A(t,e,r,a){var n=e&&e.prototype instanceof W?e:W,u=Object.create(n.prototype),v=new F(a||[]);return l(u,"_invoke",{value:fe(t,r,v)}),u}o.wrap=A;function N(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(a){return{type:"throw",arg:a}}}var g="suspendedStart",L="suspendedYield",O="executing",E="completed",S={};function W(){}function C(){}function R(){}var j={};p(j,f,function(){return this});var B=Object.getPrototypeOf,V=B&&B(B(Y([])));V&&V!==s&&i.call(V,f)&&(j=V);var I=R.prototype=W.prototype=Object.create(j);C.prototype=R,l(I,"constructor",{value:R,configurable:!0}),l(R,"constructor",{value:C,configurable:!0}),C.displayName=p(R,h,"GeneratorFunction");function Z(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===C||(e.displayName||e.name)==="GeneratorFunction":!1},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,R):(t.__proto__=R,p(t,h,"GeneratorFunction")),t.prototype=Object.create(I),t},o.awrap=function(t){return{__await:t}};function G(t,e){function r(u,v,d,w){var y=N(t[u],t,v);if(y.type==="throw")w(y.arg);else{var K=y.arg,T=K.value;return T&&typeof T=="object"&&i.call(T,"__await")?e.resolve(T.__await).then(function(_){r("next",_,d,w)},function(_){r("throw",_,d,w)}):e.resolve(T).then(function(_){K.value=_,d(K)},function(_){return r("throw",_,d,w)})}}var a;function n(u,v){function d(){return new e(function(w,y){r(u,v,w,y)})}return a=a?a.then(d,d):d()}l(this,"_invoke",{value:n})}Z(G.prototype),p(G.prototype,b,function(){return this}),o.AsyncIterator=G,o.async=function(t,e,r,a,n){n===void 0&&(n=Promise);var u=new G(A(t,e,r,a),n);return o.isGeneratorFunction(e)?u:u.next().then(function(v){return v.done?v.value:u.next()})};function fe(t,e,r){var a=g;return function(u,v){if(a===O)throw new Error("Generator is already running");if(a===E){if(u==="throw")throw v;return te()}for(r.method=u,r.arg=v;;){var d=r.delegate;if(d){var w=ee(d,r);if(w){if(w===S)continue;return w}}if(r.method==="next")r.sent=r._sent=r.arg;else if(r.method==="throw"){if(a===g)throw a=E,r.arg;r.dispatchException(r.arg)}else r.method==="return"&&r.abrupt("return",r.arg);a=O;var y=N(t,e,r);if(y.type==="normal"){if(a=r.done?E:L,y.arg===S)continue;return{value:y.arg,done:r.done}}else y.type==="throw"&&(a=E,r.method="throw",r.arg=y.arg)}}}function ee(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,ee(t,e),e.method==="throw")||r!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),S;var n=N(a,t.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,S;var u=n.arg;if(!u)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,S;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,S}Z(I),p(I,h,"Generator"),p(I,f,function(){return this}),p(I,"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 U(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function F(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(le,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 Y(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,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:te}}o.values=Y;function te(){return{value:c,done:!0}}return F.prototype={constructor:F,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(U),!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(w,y){return u.type="throw",u.arg=t,e.next=w,y&&(e.method="next",e.arg=c),!!y}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 v=i.call(n,"catchLoc"),d=i.call(n,"finallyLoc");if(v&&d){if(this.prev<n.catchLoc)return r(n.catchLoc,!0);if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else if(v){if(this.prev<n.catchLoc)return r(n.catchLoc,!0)}else if(d){if(this.prev<n.finallyLoc)return r(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var 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,S):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),S},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),U(r),S}},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;U(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:Y(t),resultName:e,nextLoc:r},this.method==="next"&&(this.arg=c),S}},o}(typeof x=="object"?x.exports:{});try{regeneratorRuntime=J}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=J:Function("r","regeneratorRuntime = r")(J)}});var ut=Se(ie());import{createSDK as je}from"@magic-sdk/provider";import*as Be from"process";import Ue from"localforage";import{URL as Fe,URLSearchParams as Ye}from"whatwg-url";import{Buffer as Q}from"buffer";import*as ue from"lodash";import{getBundleId as Ke}from"react-native-device-info";import{driverWithoutSerialization as $e}from"@aveq-research/localforage-asyncstorage-driver";import*as X from"localforage-driver-memory";import ae,{useState as _e,useCallback as M,useMemo as Oe,useEffect as se}from"react";import{Linking as Ie,StyleSheet as Ne}from"react-native";import{WebView as Te}from"react-native-webview";import{SafeAreaView as Me}from"react-native-safe-area-context";import{ViewController as Ae,createModalNotReadyError as Ce,createResponseTimeoutError as Ve}from"@magic-sdk/provider";import{isTypedArray as Ge}from"lodash";import{useEffect as Ee,useState as Le}from"react";import Re from"@react-native-community/netinfo";var H=()=>{let[o,s]=Le(!0);return Ee(()=>{let i=l=>{s(!!l.isConnected)};return Re.addEventListener(i)},[]),o};var ce="MAGIC_PAYLOAD_FLAG_TYPED_ARRAY",Pe="open_in_device_browser",De="#FFFFFF";function ke(){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 D=class extends Ae{constructor(){super(...arguments);this.messageTimeouts=new Map;this.Relayer=i=>{let[l,c]=_e(!1),m=H();se(()=>{this.isConnectedToInternet=m},[m]),se(()=>()=>{this.isReadyForRequest=!1},[]);let f=M(g=>{this.webView=g},[]),b=M(g=>{this.container=z(q({},g),{showOverlay:h,hideOverlay:p})},[]),h=M(()=>{c(!0)},[]),p=M(()=>{c(!1)},[]),A=Oe(()=>[this.styles["webview-container"],l?z(q({},this.styles.show),{backgroundColor:i!=null?i:De}):this.styles.hide],[l]),N=M(g=>{var O;let L=JSON.parse(g.nativeEvent.data);if((O=L==null?void 0:L.response)!=null&&O.id){let E=L.response.id;this.messageTimeouts.has(E)&&(clearTimeout(this.messageTimeouts.get(E)),this.messageTimeouts.delete(E))}this.handleReactNativeWebViewMessage(g)},[]);return ae.createElement(Me,{ref:b,style:A},ae.createElement(Te,{ref:f,source:{uri:`${this.endpoint}/send/?params=${encodeURIComponent(this.parameters)}`},onMessage:N,style:this.styles["magic-webview"],webviewDebuggingEnabled:!0,autoManageStatusBarEnabled:!1,onShouldStartLoadWithRequest:g=>new URLSearchParams(g.url.split("?")[1]).get(Pe)?(Ie.openURL(g.url),!1):!0}))}}init(){this.webView=null,this.container=null,this.styles=ke()}handleReactNativeWebViewMessage(i){var l;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}`)){let c=JSON.parse(i.nativeEvent.data,(m,f)=>{try{if(f&&typeof f=="object"&&f.flag&&f.flag===ce)return new global[f.constructor](f.data.split(","))}catch(b){}return f});if(c&&c.msgType&&this.messageHandlers.size){c.response=(l=c.response)!=null?l:{};let m={data:c};for(let f of this.messageHandlers.values())f(m)}}}hideOverlay(){this.container&&this.container.hideOverlay()}showOverlay(){this.container&&this.container.showOverlay()}_post(i){return P(this,null,function*(){var m,f;let l=(m=i.payload)==null?void 0:m.method,c=(f=i.payload)==null?void 0:f.id;if(this.webView&&this.webView.postMessage){if(l&&c){let b=setTimeout(()=>{throw this.messageTimeouts.delete(c),Ve(l,c)},1e4);this.messageTimeouts.set(c,b)}this.webView.postMessage(JSON.stringify(i,(b,h)=>Ge(h)?{constructor:h.constructor.name,data:h.toString(),flag:ce}:h),this.endpoint)}else throw Ce()})}};import{SDKBase as We}from"@magic-sdk/provider";var k=class extends We{get Relayer(){return this.overlay.Relayer}};export*from"@magic-sdk/commons";global.process=ue.merge(global.process,Be);global.process.browser=!1;global.Buffer=Q;global.URL=Fe;global.URLSearchParams=Ye;global.btoa=o=>Q.from(o,"binary").toString("base64");global.atob=o=>Q.from(o,"base64").toString("binary");var bt=je(k,{platform:"react-native",sdkName:"@magic-sdk/react-native-bare",version:"27.0.0",bundleId:Ke(),defaultEndpoint:"https://box.magic.link/",ViewController:D,configureStorage:()=>P(void 0,null,function*(){let o=Ue.createInstance({name:"MagicAuthLocalStorageDB",storeName:"MagicAuthLocalStorage"}),s=$e();return yield Promise.all([o.defineDriver(s),o.defineDriver(X)]),yield o.setDriver([s._driver,X._driver]),o})});export{bt as Magic,H 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": "
|
3
|
+
"version": "27.0.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,9 +18,9 @@
|
|
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": "
|
22
|
-
"@magic-sdk/provider": "
|
23
|
-
"@magic-sdk/types": "
|
21
|
+
"@magic-sdk/commons": "^22.0.0",
|
22
|
+
"@magic-sdk/provider": "^26.0.0",
|
23
|
+
"@magic-sdk/types": "^22.0.0",
|
24
24
|
"@react-native-async-storage/async-storage": "^1.15.5",
|
25
25
|
"@types/lodash": "^4.14.158",
|
26
26
|
"buffer": "~5.6.0",
|
@@ -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": "
|
59
|
+
"gitHead": "72a3d439ca96130d9e5a46a2decfbbf37d26580a"
|
60
60
|
}
|