zh-web-sdk 2.0.1 → 2.1.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/README.md CHANGED
@@ -8,8 +8,8 @@ using a single instance of `ZeroHashSDK`.
8
8
  On SDK v2 we added some new methods that will replace the ones marked with deprecated
9
9
  on future releases, if you update our SDK to v2 but don't do the below changes,
10
10
  your App should still work fine as we ensured everything is backwards compatible, but
11
- we highly recommend that when updating to v2 you follow the steps below to ensure your App
12
- is up to date with our SDK.
11
+ we recommend that when updating to v2 you follow the steps below to ensure your App
12
+ is kept up to date with our SDK.
13
13
  ### Instantiating the SDK
14
14
  - `zeroHashOnboardingURL` was renamed to `zeroHashAppsURL`. Please replace `zeroHashOnboardingURL` with `zeroHashAppsURL`.
15
15
  ### SDK Methods
@@ -48,7 +48,7 @@ const sdk = new ZeroHashSDK({
48
48
 
49
49
  // Set the JWT retrieved for a particular App (each App requires a specific JWT,
50
50
  // i.e. you should not use your Onboarding JWT for Crypto Witdhrawals)
51
- // before the user can proceed with the flow. Currently the Apps
51
+ // before the user can proceed with the flow.
52
52
  sdk.openModal({
53
53
  appIdentifier: AppIdentifier.ONBOARDING,
54
54
  jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." +
@@ -170,4 +170,4 @@ const App = () => {
170
170
  </SafeAreaProvider>
171
171
  )
172
172
  }
173
- ```
173
+ ```
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ Error generating stack: `+i.message+`
9
9
  The error may be correlated with this previous error:
10
10
  ${Bi.current.stack}
11
11
 
12
- `),He}Ln(()=>{Bi.current=void 0,jn.current=void 0,Ui.current=Wr});let Hi=(0,L.useMemo)(()=>L.default.createElement(O,st({},Wr,{ref:V})),[V,O,Wr]);return(0,L.useMemo)(()=>w?L.default.createElement(de.Provider,{value:Ws},Hi):Hi,[de,Hi,Ws])}let C=L.default.memo(y);if(C.WrappedComponent=O,C.displayName=y.displayName=a,s){let _=L.default.forwardRef(function(P,de){return L.default.createElement(C,st({},P,{reactReduxForwardedRef:de}))});return _.displayName=a,_.WrappedComponent=O,(0,Ts.default)(_,O)}return(0,Ts.default)(C,O)}}var Is=pv;var Lr=q(Oe());function mv({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",noopCheck:i="once"}){let l=(0,Lr.useMemo)(()=>{let c=Li(e);return{store:e,subscription:c,getServerState:r?()=>r:void 0,stabilityCheck:o,noopCheck:i}},[e,r,o,i]),u=(0,Lr.useMemo)(()=>e.getState(),[e]);Ln(()=>{let{subscription:c}=l;return c.onStateChange=c.notifyNestedSubs,c.trySubscribe(),u!==e.getState()&&c.notifyNestedSubs(),()=>{c.tryUnsubscribe(),c.onStateChange=void 0}},[l,u]);let s=t||ut;return Lr.default.createElement(s.Provider,{value:l},n)}var Mi=mv;Qd(vp.useSyncExternalStoreWithSelector);hp(yp.useSyncExternalStore);$d(gs.unstable_batchedUpdates);var vv=540,Dr=[{id:"MTE_SM",size:vv}],gp=()=>{for(let e=0;e<Dr.length;e++){let{id:t,size:n}=Dr[e];if(window.matchMedia(`(min-width: ${n}px`).matches)return t}return"ANY"},As={paddingRight:0,paddingLeft:0,marginRight:"auto",marginLeft:"auto",maxHeight:882},Sp={MTE_SM:{width:540},ANY:{width:"100%",height:"100%",maxWidth:"100%",borderRadius:0,maxHeight:"100%"}},wp={position:"absolute",zIndex:999999,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",width:"100vw",height:"100vh",background:"rgba(0,0,0,0.5)",cursor:"pointer"},Ep={display:"none",width:0,height:0},xp={padding:0,borderRadius:5,backgroundColor:"#FFF",height:"calc(100% - 100px)",maxWidth:"calc(100% - 30px)"},kp={width:"100%",height:"100%",border:"none",overflow:"hidden"},Cp={width:"100%",height:"100%",border:"none",margin:0,padding:0,overflow:"hidden",borderRadius:"0 0 15px 15px"};var gv=Ce.get("onboarding"),Sv=Ce.get("crypto-withdrawals"),_p=gv+"SEND_JWT_TOKEN",Op=Sv+"SEND_JWT_TOKEN";var Rs=e=>{In(e,Yt,{isAppActive:!0})},Gt=e=>{In(e,Yt,{isAppActive:!1})},Ls=e=>{In(e,Tn,{isAppLoaded:!0})};var zr=q(Mr()),Ov=Date.now(),Pv={onboarding:"Onboarding","crypto-withdrawals":"Crypto Withdrawals"},Nv=({isAppActive:e,isAppLoaded:t,jwt:n,zeroHashAppURL:r,appIdentifier:o})=>{let i=Pv[o],l=!!n,[u,s]=(0,Jt.useState)(As),c=()=>{let m=gp(),v=Sp[m];s({...As,...v})},p=(0,Jt.useRef)(null);(0,Jt.useEffect)(()=>{if(r&&t&&l&&p.current?.contentWindow)switch(o){case"crypto-withdrawals":p.current.contentWindow.postMessage({type:Op,cryptoWithdrawalsJWT:n},r);break;case"onboarding":p.current.contentWindow.postMessage({type:_p,userOnboardingJWT:n},r);break;default:break}},[o,l,t,n,r]),(0,Jt.useEffect)(()=>{if(c(),window)return Dr.forEach(({size:m})=>{window.matchMedia(`(min-width: ${m}px)`).addEventListener("change",c)}),()=>Dr.forEach(({size:m})=>{window.matchMedia(`(min-width: ${m}px)`).removeEventListener("change",c)})},[]);let h=new URL(r);return h.searchParams.set("name",Ov.toString()),window&&h.searchParams.set("origin",window.location.origin),(0,zr.jsx)("div",{style:e?wp:Ep,onClick:()=>Gt(o),children:(0,zr.jsx)("div",{style:{...xp,...u},children:(0,zr.jsx)("div",{style:{...kp},children:(0,zr.jsx)("iframe",{ref:p,title:i,src:h.toString(),allow:"camera *; fullscreen *; accelerometer *; gyroscope *; magnetometer *;",style:Cp})})})})},Tv=(e,t)=>({isAppActive:e[t.appIdentifier].isAppActive,isAppLoaded:e[t.appIdentifier].isAppLoaded,jwt:e[t.appIdentifier].jwt}),Ds=Is(Tv)(Nv);var jr=q(Mr()),ji=ds,Ap="",Ip={ONBOARDING_APP_LOADED:()=>{Ls("onboarding")},ONBOARDING_CLOSE_BUTTON_CLICKED:()=>{Gt("onboarding")},CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Gt("crypto-withdrawals")},CRYPTO_WITHDRAWALS_APP_LOADED:()=>{Ls("crypto-withdrawals")}},Iv=e=>{if(e.origin===Ap){let t=e.data;if(t&&t.type&&Ip[t.type])try{Ip[t.type](t.payload)}catch(n){console.error(n)}}},Wi=class{rootQuerySelector="";onboardingInitialized=!1;initializedApps=new Map([["crypto-withdrawals",!1],["onboarding",!1]]);constructor({zeroHashOnboardingURL:t=ds,rootQuerySelector:n,userOnboardingJWT:r,cryptoWithdrawalsJWT:o,zeroHashAppsURL:i}){ji=i||t,Ap=new URL(ji).origin,n&&(this.rootQuerySelector=n),window.addEventListener("message",Iv,!1),r&&this.setJWT({jwt:r,appIdentifier:"onboarding"}),o&&this.setJWT({jwt:o,appIdentifier:"crypto-withdrawals"})}setJWT({jwt:t,appIdentifier:n}){In(n,Nn,{jwt:t})}setUserOnboardingJWT(t){this.setJWT({jwt:t.userOnboardingJWT,appIdentifier:"onboarding"})}isOnboardingModalOpen(){return Kt.getState().onboarding.isAppActive}isModalOpen(t){return Kt.getState()[t].isAppActive}closeModal(t){Gt(t)}openModal({jwt:t,appIdentifier:n}){if(t&&this.setJWT({jwt:t,appIdentifier:n}),Rs(n),this.initializedApps.get(n))return;let r=null;if(this.rootQuerySelector&&(r=document.querySelector(this.rootQuerySelector)),!this.initializedApps.get(n)){r=document.createElement("div");let o=hs(n);r.id=o,r.style.position="absolute",r.style.top="0",r.style.left="0",this.rootQuerySelector=`#${o}`,document.querySelector("body").appendChild(r)}if(r){let o=r.attachShadow({mode:"closed"});Ms.default.createRoot(o).render((0,jr.jsx)(Mi,{store:Kt,children:(0,jr.jsx)(Ds,{appIdentifier:n,zeroHashAppURL:`${ji}/${n}`})})),this.initializedApps.set(n,!0)}else{let o="failed to append ZeroHash root to the page: root not found";throw console.error(o),new Error(o)}}openOnboardingModal(t){if(t.userOnboardingJWT&&this.setUserOnboardingJWT({userOnboardingJWT:t.userOnboardingJWT}),Rs("onboarding"),this.onboardingInitialized)return;let n=null;if(this.rootQuerySelector&&(n=document.querySelector(this.rootQuerySelector)),!n){n=document.createElement("div");let r=hs();n.id=r,n.style.position="absolute",n.style.top="0",n.style.left="0",this.rootQuerySelector=`#${r}`,document.querySelector("body").appendChild(n)}if(n){let r=n.attachShadow({mode:"closed"});Ms.default.createRoot(r).render((0,jr.jsx)(Mi,{store:Kt,children:(0,jr.jsx)(Ds,{appIdentifier:"onboarding",zeroHashAppURL:ji})})),this.onboardingInitialized=!0}else{let r="failed to append ZeroHash root to the page: root not found";throw console.error(r),new Error(r)}}closeOnboardingModal(){Gt("onboarding")}};window&&(window.zerohash=Wi);var Z1=Wi;export{Pn as AppIdentifier,kd as IncomingMessageType,Wi as ZeroHashSDK,Ce as appIdentifierToActionPrefixMap,Z1 as default};
12
+ `),He}Ln(()=>{Bi.current=void 0,jn.current=void 0,Ui.current=Wr});let Hi=(0,L.useMemo)(()=>L.default.createElement(O,st({},Wr,{ref:V})),[V,O,Wr]);return(0,L.useMemo)(()=>w?L.default.createElement(de.Provider,{value:Ws},Hi):Hi,[de,Hi,Ws])}let C=L.default.memo(y);if(C.WrappedComponent=O,C.displayName=y.displayName=a,s){let _=L.default.forwardRef(function(P,de){return L.default.createElement(C,st({},P,{reactReduxForwardedRef:de}))});return _.displayName=a,_.WrappedComponent=O,(0,Ts.default)(_,O)}return(0,Ts.default)(C,O)}}var Is=pv;var Lr=q(Oe());function mv({store:e,context:t,children:n,serverState:r,stabilityCheck:o="once",noopCheck:i="once"}){let l=(0,Lr.useMemo)(()=>{let c=Li(e);return{store:e,subscription:c,getServerState:r?()=>r:void 0,stabilityCheck:o,noopCheck:i}},[e,r,o,i]),u=(0,Lr.useMemo)(()=>e.getState(),[e]);Ln(()=>{let{subscription:c}=l;return c.onStateChange=c.notifyNestedSubs,c.trySubscribe(),u!==e.getState()&&c.notifyNestedSubs(),()=>{c.tryUnsubscribe(),c.onStateChange=void 0}},[l,u]);let s=t||ut;return Lr.default.createElement(s.Provider,{value:l},n)}var Mi=mv;Qd(vp.useSyncExternalStoreWithSelector);hp(yp.useSyncExternalStore);$d(gs.unstable_batchedUpdates);var vv=540,Dr=[{id:"MTE_SM",size:vv}],gp=()=>{for(let e=0;e<Dr.length;e++){let{id:t,size:n}=Dr[e];if(window.matchMedia(`(min-width: ${n}px`).matches)return t}return"ANY"},As={paddingRight:0,paddingLeft:0,marginRight:"auto",marginLeft:"auto",maxHeight:882},Sp={MTE_SM:{width:540},ANY:{width:"100%",height:"100%",maxWidth:"100%",borderRadius:0,maxHeight:"100%"}},wp={position:"absolute",zIndex:999999,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",width:"100vw",height:"100vh",background:"rgba(0,0,0,0.5)",cursor:"pointer"},Ep={display:"none",width:0,height:0},xp={padding:0,borderRadius:5,backgroundColor:"#FFF",height:"calc(100% - 100px)",maxWidth:"calc(100% - 30px)"},kp={width:"100%",height:"100%",border:"none",overflow:"hidden"},Cp={width:"100%",height:"100%",border:"none",margin:0,padding:0,overflow:"hidden",borderRadius:"0 0 15px 15px"};var gv=Ce.get("onboarding"),Sv=Ce.get("crypto-withdrawals"),_p=gv+"SEND_JWT_TOKEN",Op=Sv+"SEND_JWT_TOKEN";var Rs=e=>{In(e,Yt,{isAppActive:!0})},Gt=e=>{In(e,Yt,{isAppActive:!1})},Ls=e=>{In(e,Tn,{isAppLoaded:!0})};var zr=q(Mr()),Ov=Date.now(),Pv={onboarding:"Onboarding","crypto-withdrawals":"Crypto Withdrawals"},Nv=({isAppActive:e,isAppLoaded:t,jwt:n,zeroHashAppURL:r,appIdentifier:o})=>{let i=Pv[o],l=!!n,[u,s]=(0,Jt.useState)(As),c=()=>{let m=gp(),v=Sp[m];s({...As,...v})},p=(0,Jt.useRef)(null);(0,Jt.useEffect)(()=>{if(r&&t&&l&&p.current?.contentWindow)switch(o){case"crypto-withdrawals":p.current.contentWindow.postMessage({type:Op,cryptoWithdrawalsJWT:n},r);break;case"onboarding":p.current.contentWindow.postMessage({type:_p,userOnboardingJWT:n},r);break;default:break}},[o,l,t,n,r]),(0,Jt.useEffect)(()=>{if(c(),window)return Dr.forEach(({size:m})=>{window.matchMedia(`(min-width: ${m}px)`).addEventListener("change",c)}),()=>Dr.forEach(({size:m})=>{window.matchMedia(`(min-width: ${m}px)`).removeEventListener("change",c)})},[]);let h=new URL(r);return h.searchParams.set("name",Ov.toString()),window&&h.searchParams.set("origin",window.location.origin),(0,zr.jsx)("div",{style:e?wp:Ep,onClick:()=>Gt(o),children:(0,zr.jsx)("div",{style:{...xp,...u},children:(0,zr.jsx)("div",{style:{...kp},children:(0,zr.jsx)("iframe",{ref:p,title:i,src:h.toString(),allow:"camera *; fullscreen *; accelerometer *; gyroscope *; magnetometer *;",sandbox:"allow-downloads allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation",style:Cp})})})})},Tv=(e,t)=>({isAppActive:e[t.appIdentifier].isAppActive,isAppLoaded:e[t.appIdentifier].isAppLoaded,jwt:e[t.appIdentifier].jwt}),Ds=Is(Tv)(Nv);var jr=q(Mr()),ji=ds,Ap="",Ip={ONBOARDING_APP_LOADED:()=>{Ls("onboarding")},ONBOARDING_CLOSE_BUTTON_CLICKED:()=>{Gt("onboarding")},CRYPTO_WITHDRAWALS_CLOSE_BUTTON_CLICKED:()=>{Gt("crypto-withdrawals")},CRYPTO_WITHDRAWALS_APP_LOADED:()=>{Ls("crypto-withdrawals")}},Iv=e=>{if(e.origin===Ap){let t=e.data;if(t&&t.type&&Ip[t.type])try{Ip[t.type](t.payload)}catch(n){console.error(n)}}},Wi=class{rootQuerySelector="";onboardingInitialized=!1;initializedApps=new Map([["crypto-withdrawals",!1],["onboarding",!1]]);constructor({zeroHashOnboardingURL:t=ds,rootQuerySelector:n,userOnboardingJWT:r,cryptoWithdrawalsJWT:o,zeroHashAppsURL:i}){ji=i||t,Ap=new URL(ji).origin,n&&(this.rootQuerySelector=n),window.addEventListener("message",Iv,!1),r&&this.setJWT({jwt:r,appIdentifier:"onboarding"}),o&&this.setJWT({jwt:o,appIdentifier:"crypto-withdrawals"})}setJWT({jwt:t,appIdentifier:n}){In(n,Nn,{jwt:t})}setUserOnboardingJWT(t){this.setJWT({jwt:t.userOnboardingJWT,appIdentifier:"onboarding"})}isOnboardingModalOpen(){return Kt.getState().onboarding.isAppActive}isModalOpen(t){return Kt.getState()[t].isAppActive}closeModal(t){Gt(t)}openModal({jwt:t,appIdentifier:n}){if(t&&this.setJWT({jwt:t,appIdentifier:n}),Rs(n),this.initializedApps.get(n))return;let r=null;if(this.rootQuerySelector&&(r=document.querySelector(this.rootQuerySelector)),!this.initializedApps.get(n)){r=document.createElement("div");let o=hs(n);r.id=o,r.style.position="absolute",r.style.top="0",r.style.left="0",this.rootQuerySelector=`#${o}`,document.querySelector("body").appendChild(r)}if(r){let o=r.attachShadow({mode:"closed"});Ms.default.createRoot(o).render((0,jr.jsx)(Mi,{store:Kt,children:(0,jr.jsx)(Ds,{appIdentifier:n,zeroHashAppURL:`${ji}/${n}`})})),this.initializedApps.set(n,!0)}else{let o="failed to append ZeroHash root to the page: root not found";throw console.error(o),new Error(o)}}openOnboardingModal(t){if(t.userOnboardingJWT&&this.setUserOnboardingJWT({userOnboardingJWT:t.userOnboardingJWT}),Rs("onboarding"),this.onboardingInitialized)return;let n=null;if(this.rootQuerySelector&&(n=document.querySelector(this.rootQuerySelector)),!n){n=document.createElement("div");let r=hs();n.id=r,n.style.position="absolute",n.style.top="0",n.style.left="0",this.rootQuerySelector=`#${r}`,document.querySelector("body").appendChild(n)}if(n){let r=n.attachShadow({mode:"closed"});Ms.default.createRoot(r).render((0,jr.jsx)(Mi,{store:Kt,children:(0,jr.jsx)(Ds,{appIdentifier:"onboarding",zeroHashAppURL:ji})})),this.onboardingInitialized=!0}else{let r="failed to append ZeroHash root to the page: root not found";throw console.error(r),new Error(r)}}closeOnboardingModal(){Gt("onboarding")}};window&&(window.zerohash=Wi);var Z1=Wi;export{Pn as AppIdentifier,kd as IncomingMessageType,Wi as ZeroHashSDK,Ce as appIdentifierToActionPrefixMap,Z1 as default};
13
13
  /*! Bundled license information:
14
14
 
15
15
  react/cjs/react.production.min.js: