@tiun/react-native-sdk 0.5.0-staging.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,22 @@ snippet without reloading:
48
48
  >
49
49
  ```
50
50
 
51
+ ### Events
52
+
53
+ `useTiunEvent('userChange', …)` receives the same payload as the web SDK:
54
+ `{ event, isAuthenticated, user }`. `event` is `'init'`, `'login'`, `'logout'`,
55
+ `'checkout'` (access gained or lost, for any product type — including a
56
+ repeatable product bought with a new reference) or `'update'`. Re-check access
57
+ there:
58
+
59
+ ```tsx
60
+ useTiunEvent('userChange', async ({ isAuthenticated, user }) => {
61
+ setHasPro(isAuthenticated && !!user?.productAccess.includes('prod_pro'));
62
+ const { hasAccess } = await checkProductAccess('prod_ticket', { referenceId: 'order-1042' });
63
+ setHasTicket(hasAccess);
64
+ });
65
+ ```
66
+
51
67
  ### Products
52
68
 
53
69
  `useTiun()` exposes the same product methods as the web SDK. Each returns a
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare type Appearance = 'light' | 'dark' | 'auto';
6
6
 
7
7
  export declare interface CheckoutOptions {
8
8
  /**
9
- * Specific product ID to checkout (optional, for future use)
9
+ * The product to check out, from your tiun dashboard.
10
10
  */
11
11
  productId?: string;
12
12
  /**
@@ -136,10 +136,8 @@ export declare type TiunEventName = 'ready' | 'userChange' | 'login' | 'logout'
136
136
 
137
137
  export declare type TiunEventPayload = {
138
138
  ready: void;
139
- userChange: {
140
- isAuthenticated: boolean;
141
- user: TiunUser | null;
142
- };
139
+ /** Same shape as the web SDK: `event` says what changed ('checkout' = access). */
140
+ userChange: UserChangeEvent;
143
141
  login: {
144
142
  user: TiunUser | null;
145
143
  };
@@ -161,11 +159,31 @@ export declare function TiunProvider({ config, children }: {
161
159
  /** The authenticated user (alias of the web SDK's `UserInfo`). */
162
160
  export declare type TiunUser = UserInfo;
163
161
 
162
+ export declare interface UserChangeEvent {
163
+ /**
164
+ * What changed:
165
+ * - 'init': first state after the snippet loads
166
+ * - 'login' / 'logout': the user signed in or out
167
+ * - 'checkout': the user's access changed — gained or lost, for any product
168
+ * type, including a repeatable product bought with a new reference
169
+ * (which doesn't change `productAccess`). Not only after a checkout.
170
+ * - 'update': profile details changed (email, newsletter opt-in)
171
+ */
172
+ event: 'init' | 'login' | 'checkout' | 'logout' | 'update';
173
+ isAuthenticated: boolean;
174
+ user: UserInfo | null;
175
+ }
176
+
164
177
  declare interface UserInfo {
165
178
  userId: string;
166
179
  email: string;
167
180
  /** Whether the user has opted in to the newsletter. */
168
181
  hasNewsletterOptIn: boolean;
182
+ /**
183
+ * IDs of the products the user has access to. Product IDs only, so it can't
184
+ * tell which references of a repeatable product were bought — use
185
+ * `checkProductAccess(productId, { referenceId })` for those.
186
+ */
169
187
  productAccess: string[];
170
188
  }
171
189
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Se=Object.defineProperty;var we=(r,n,i)=>n in r?Se(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i;var fe=(r,n,i)=>(we(r,typeof n!="symbol"?n+"":n,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),v=require("react-native"),ve=require("react-native-webview"),Q=require("react-native-inappbrowser-nitro"),ne=require("react-native-secure-sign"),Re=require("react-native-keychain");function me(r){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const i in r)if(i!=="default"){const l=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(n,i,l.get?l:{enumerable:!0,get:()=>r[i]})}}return n.default=r,Object.freeze(n)}const ae=me(Re);var se={exports:{}},Z={};/**
1
+ "use strict";var Se=Object.defineProperty;var ve=(r,n,i)=>n in r?Se(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i;var fe=(r,n,i)=>(ve(r,typeof n!="symbol"?n+"":n,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),w=require("react-native"),we=require("react-native-webview"),Z=require("react-native-inappbrowser-nitro"),oe=require("react-native-secure-sign"),Re=require("react-native-keychain");function me(r){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const i in r)if(i!=="default"){const l=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(n,i,l.get?l:{enumerable:!0,get:()=>r[i]})}}return n.default=r,Object.freeze(n)}const ie=me(Re);var se={exports:{}},ee={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var pe;function ke(){if(pe)return Z;pe=1;var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function i(l,o,E){var S=null;if(E!==void 0&&(S=""+E),o.key!==void 0&&(S=""+o.key),"key"in o){E={};for(var T in o)T!=="key"&&(E[T]=o[T])}else E=o;return o=E.ref,{$$typeof:r,type:l,key:S,ref:o!==void 0?o:null,props:E}}return Z.Fragment=n,Z.jsx=i,Z.jsxs=i,Z}var ee={};/**
9
+ */var pe;function ke(){if(pe)return ee;pe=1;var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function i(l,o,h){var y=null;if(h!==void 0&&(y=""+h),o.key!==void 0&&(y=""+o.key),"key"in o){h={};for(var p in o)p!=="key"&&(h[p]=o[p])}else h=o;return o=h.ref,{$$typeof:r,type:l,key:y,ref:o!==void 0?o:null,props:h}}return ee.Fragment=n,ee.jsx=i,ee.jsxs=i,ee}var te={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,9 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Te;function ge(){return Te||(Te=1,process.env.NODE_ENV!=="production"&&function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===B?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case L:return"Fragment";case D:return"Profiler";case y:return"StrictMode";case q:return"Suspense";case g:return"SuspenseList";case H:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case W:return"Portal";case V:return(t.displayName||"Context")+".Provider";case x:return(t._context.displayName||"Context")+".Consumer";case Y:var c=t.render;return t=t.displayName,t||(t=c.displayName||c.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case G:return c=t.displayName||null,c!==null?c:r(t.type)||"Memo";case F:c=t._payload,t=t._init;try{return r(t(c))}catch{}}return null}function n(t){return""+t}function i(t){try{n(t);var c=!1}catch{c=!0}if(c){c=console;var h=c.error,w=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return h.call(c,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",w),n(t)}}function l(t){if(t===L)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===F)return"<...>";try{var c=r(t);return c?"<"+c+">":"<...>"}catch{return"<...>"}}function o(){var t=a.A;return t===null?null:t.getOwner()}function E(){return Error("react-stack-top-frame")}function S(t){if(e.call(t,"key")){var c=Object.getOwnPropertyDescriptor(t,"key").get;if(c&&c.isReactWarning)return!1}return t.key!==void 0}function T(t,c){function h(){d||(d=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",c))}h.isReactWarning=!0,Object.defineProperty(t,"key",{get:h,configurable:!0})}function U(){var t=r(this.type);return b[t]||(b[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function j(t,c,h,w,P,C,K,M){return h=C.ref,t={$$typeof:$,type:t,key:c,props:C,_owner:P},(h!==void 0?h:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:U}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function I(t,c,h,w,P,C,K,M){var p=c.children;if(p!==void 0)if(w)if(u(p)){for(w=0;w<p.length;w++)N(p[w]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else N(p);if(e.call(c,"key")){p=r(t);var _=Object.keys(c).filter(function(_e){return _e!=="key"});w=0<_.length?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}",X[p+w]||(_=0<_.length?"{"+_.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var Te;function ge(){return Te||(Te=1,process.env.NODE_ENV!=="production"&&function(){function r(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===K?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case q:return"Fragment";case V:return"Profiler";case b:return"StrictMode";case F:return"Suspense";case C:return"SuspenseList";case B:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case D:return"Portal";case Y:return(t.displayName||"Context")+".Provider";case A:return(t._context.displayName||"Context")+".Consumer";case G:var c=t.render;return t=t.displayName,t||(t=c.displayName||c.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case H:return c=t.displayName||null,c!==null?c:r(t.type)||"Memo";case W:c=t._payload,t=t._init;try{return r(t(c))}catch{}}return null}function n(t){return""+t}function i(t){try{n(t);var c=!1}catch{c=!0}if(c){c=console;var T=c.error,_=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return T.call(c,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",_),n(t)}}function l(t){if(t===q)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===W)return"<...>";try{var c=r(t);return c?"<"+c+">":"<...>"}catch{return"<...>"}}function o(){var t=a.A;return t===null?null:t.getOwner()}function h(){return Error("react-stack-top-frame")}function y(t){if(e.call(t,"key")){var c=Object.getOwnPropertyDescriptor(t,"key").get;if(c&&c.isReactWarning)return!1}return t.key!==void 0}function p(t,c){function T(){d||(d=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",c))}T.isReactWarning=!0,Object.defineProperty(t,"key",{get:T,configurable:!0})}function j(){var t=r(this.type);return E[t]||(E[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function $(t,c,T,_,N,P,M,J){return T=P.ref,t={$$typeof:L,type:t,key:c,props:P,_owner:N},(T!==void 0?T:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:j}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function x(t,c,T,_,N,P,M,J){var S=c.children;if(S!==void 0)if(_)if(u(S)){for(_=0;_<S.length;_++)O(S[_]);Object.freeze&&Object.freeze(S)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else O(S);if(e.call(c,"key")){S=r(t);var R=Object.keys(c).filter(function(_e){return _e!=="key"});_=0<R.length?"{key: someKey, "+R.join(": ..., ")+": ...}":"{key: someKey}",Q[S+_]||(R=0<R.length?"{"+R.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,w,p,_,p),X[p+w]=!0)}if(p=null,h!==void 0&&(i(h),p=""+h),S(c)&&(i(c.key),p=""+c.key),"key"in c){h={};for(var ie in c)ie!=="key"&&(h[ie]=c[ie])}else h=c;return p&&T(h,typeof t=="function"?t.displayName||t.name||"Unknown":t),j(t,p,C,P,o(),h,K,M)}function N(t){typeof t=="object"&&t!==null&&t.$$typeof===$&&t._store&&(t._store.validated=1)}var k=s,$=Symbol.for("react.transitional.element"),W=Symbol.for("react.portal"),L=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),x=Symbol.for("react.consumer"),V=Symbol.for("react.context"),Y=Symbol.for("react.forward_ref"),q=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),G=Symbol.for("react.memo"),F=Symbol.for("react.lazy"),H=Symbol.for("react.activity"),B=Symbol.for("react.client.reference"),a=k.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,e=Object.prototype.hasOwnProperty,u=Array.isArray,f=console.createTask?console.createTask:function(){return null};k={"react-stack-bottom-frame":function(t){return t()}};var d,b={},R=k["react-stack-bottom-frame"].bind(k,E)(),O=f(l(E)),X={};ee.Fragment=L,ee.jsx=function(t,c,h,w,P){var C=1e4>a.recentlyCreatedOwnerStacks++;return I(t,c,h,!1,w,P,C?Error("react-stack-top-frame"):R,C?f(l(t)):O)},ee.jsxs=function(t,c,h,w,P){var C=1e4>a.recentlyCreatedOwnerStacks++;return I(t,c,h,!0,w,P,C?Error("react-stack-top-frame"):R,C?f(l(t)):O)}}()),ee}process.env.NODE_ENV==="production"?se.exports=ke():se.exports=ge();var m=se.exports;const Ce={errorPillText:"Technical Error",errorNotificationTitle:"Technical error",errorNotificationSubtitle:"Please reload the page or contact our support.",errorTitle:"Technical error",errorTextBeforeEmail:"Try reloading the page. If the error persists, please contact ",errorTextAfterEmail:" and we’ll help you right away.",connectionErrorTitle:"No connection",connectionErrorText:"We couldn’t reach tiun. Check your internet connection and try again.",connectionErrorCta:"Try again"},Pe={errorPillText:"Erreur Technique",errorNotificationTitle:"Erreur technique",errorNotificationSubtitle:"Veuillez recharger la page ou contacter notre support.",errorTitle:"Erreur technique",errorTextBeforeEmail:"Veuillez recharger la page. Si l’erreur persiste, contactez ",errorTextAfterEmail:" et nous vous aiderons immédiatement.",connectionErrorTitle:"Pas de connexion",connectionErrorText:"Impossible de joindre tiun. Vérifiez votre connexion Internet et réessayez.",connectionErrorCta:"Réessayer"},Ne={errorPillText:"Technischer Fehler",errorNotificationTitle:"Technischer Fehler",errorNotificationSubtitle:"Bitte lade die Seite neu, oder kontaktiere unseren Support.",errorTitle:"Technischer Fehler",errorTextBeforeEmail:"Bitte lade die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktiere ",errorTextAfterEmail:" und wir helfen Dir sofort weiter.",connectionErrorTitle:"Keine Verbindung",connectionErrorText:"tiun konnte nicht erreicht werden. Überprüfe deine Internetverbindung und versuche es erneut.",connectionErrorCta:"Erneut versuchen"},Oe={errorPillText:"Technischer Fehler",errorNotificationTitle:"Technischer Fehler",errorNotificationSubtitle:"Bitte laden Sie die Seite neu, oder kontaktieren Sie unseren Support.",errorTitle:"Technischer Fehler",errorTextBeforeEmail:"Bitte laden Sie die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktieren Sie ",errorTextAfterEmail:" und wir helfen Ihnen sofort weiter.",connectionErrorTitle:"Keine Verbindung",connectionErrorText:"tiun konnte nicht erreicht werden. Überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",connectionErrorCta:"Erneut versuchen"};function Ie(r,n="informal"){switch((r??"en").trim().toLowerCase()){case"de":return n==="formal"?Oe:Ne;case"fr":return Pe;default:return Ce}}const J={start:"TIUN_START",checkout:"TIUN_CHECKOUT",updateContent:"TIUN_UPDATE_CONTENT",login:"TIUN_LOGIN",logout:"TIUN_LOGOUT",getVerificationToken:"TIUN_GET_VERIFICATION_TOKEN",setAppearance:"TIUN_SET_APPEARANCE",listProducts:"TIUN_LIST_PRODUCTS",getProduct:"TIUN_GET_PRODUCT",listProductAccess:"TIUN_LIST_PRODUCT_ACCESS",checkProductAccess:"TIUN_CHECK_PRODUCT_ACCESS",productResult:"TIUN_PRODUCT_RESULT",overlayChange:"TIUN_OVERLAY_CHANGE",popPubKeyRequest:"TIUN_POP_PUBKEY_REQUEST",popSignRequest:"TIUN_POP_SIGN_REQUEST",tokenGet:"TIUN_TOKEN_GET",tokenPersist:"TIUN_TOKEN_PERSIST",nativeReset:"TIUN_NATIVE_RESET",popPubKey:"TIUN_POP_PUBKEY",restoreToken:"TIUN_RESTORE_TOKEN",popSignResult:"TIUN_POP_SIGN_RESULT",resolveCheckout:"TIUN_RESOLVE_CHECKOUT"},xe="__TIUN_NATIVE_CRYPTO__",Ae="https://api.tiun.live";function ue(r){return(r.host??Ae).replace(/\/$/,"")}function oe(r){return`app.tiun.pop.${r.snippetId||"default"}`}function te(r){return`app.tiun.token.${r.snippetId||"default"}`}function Ue(r){return`${`${ue(r)}/live_api/v2/snippets/${encodeURIComponent(r.snippetId)}/webview_return`}?to=${encodeURIComponent(r.returnUrl)}`}function je(r){const n={language:r.language??"en"},i=Object.entries(n).map(([o,E])=>`${encodeURIComponent(o)}=${encodeURIComponent(E)}`).join("&"),l=`${ue(r)}/live_api/v2/snippets/${encodeURIComponent(r.snippetId)}/webview_host`;return i?`${l}?${i}`:l}function Ee(r){const n=r.indexOf("?");if(!(n<0))for(const i of r.slice(n+1).split("&")){const l=i.indexOf("=");if((l<0?i:i.slice(0,l))==="status"){const E=l<0?"":i.slice(l+1);return E?decodeURIComponent(E):void 0}}}function $e(r,n){const i=r.returnUrl.split("?")[0];return n.startsWith(i)}const le="1005";function de(r){return r==null?void 0:r.code}async function Le(r){try{return await ne.getPublicKey(r)}catch(n){if(de(n)===le)return ne.generate(r,{requireUserAuthentication:!1});throw n}}async function qe(r){try{return await ne.getPublicKey(r)}catch(n){if(de(n)===le)return null;throw n}}function Fe(r,n){return ne.sign(r,n)}async function We(r){try{await ne.removeKey(r)}catch(n){if(de(n)!==le)throw n}}const De="tiun_auth_token";async function Ve(r){const n=await ae.getGenericPassword({service:r});return n?n.password:null}async function Ye(r,n){await ae.setGenericPassword(De,n,{service:r,accessible:ae.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY})}async function ce(r){await ae.resetGenericPassword({service:r})}function Ge(r){const n=Ie(r);return{title:n.connectionErrorTitle,text:n.connectionErrorText,cta:n.connectionErrorCta}}function He({language:r,dark:n,onRetry:i}){const l=Ge(r),o=n?Be:null;return m.jsxs(v.View,{style:[A.container,o==null?void 0:o.container],children:[m.jsxs(v.View,{style:A.content,children:[m.jsx(v.Text,{style:[A.title,o==null?void 0:o.title],children:l.title}),m.jsx(v.View,{style:[A.iconBadge,o==null?void 0:o.iconBadge],children:m.jsx(v.Text,{style:[A.iconGlyph,o==null?void 0:o.iconGlyph],children:"!"})}),m.jsx(v.Text,{style:[A.text,o==null?void 0:o.text],children:l.text})]}),m.jsx(v.Pressable,{accessibilityRole:"button",onPress:i,style:({pressed:E})=>[A.button,o==null?void 0:o.button,E&&A.buttonPressed],children:m.jsx(v.Text,{style:[A.buttonText,o==null?void 0:o.buttonText],children:l.cta})})]})}const A=v.StyleSheet.create({container:{...v.StyleSheet.absoluteFillObject,backgroundColor:"#fff",padding:24,justifyContent:"space-between"},content:{flex:1,alignItems:"center",justifyContent:"center",gap:24},title:{fontSize:20,fontWeight:"600",color:"#000",textAlign:"center"},iconBadge:{width:40,height:40,borderRadius:20,backgroundColor:"#FCE7F3",alignItems:"center",justifyContent:"center"},iconGlyph:{color:"#DB2777",fontSize:22,fontWeight:"700",lineHeight:26},text:{fontSize:16,fontWeight:"500",color:"#4B5563",textAlign:"center"},button:{backgroundColor:"#000",borderRadius:999,minHeight:56,alignItems:"center",justifyContent:"center",alignSelf:"stretch"},buttonPressed:{opacity:.9},buttonText:{color:"#fff",fontSize:16,fontWeight:"500"}}),Be=v.StyleSheet.create({container:{backgroundColor:"#0a0a0a"},title:{color:"#fafafa"},iconBadge:{backgroundColor:"#500724"},iconGlyph:{color:"#F472B6"},text:{color:"#A1A1AA"},button:{backgroundColor:"#fafafa"},buttonText:{color:"#000"}}),Ke=ve.WebView;function z(r){return`try{window.tiunHost&&${r};}catch(e){}; true;`}const Me=s.forwardRef(function({config:n,onEvent:i},l){const o=!!n.debug,E=v.useColorScheme(),S=n.appearance==="dark"||n.appearance==="auto"&&E==="dark"?"dark":"light",T=s.useRef(null),[U,j]=s.useState(!1),[I,N]=s.useState(!1),k=s.useRef(!1),$=s.useRef(!1),W=()=>{var a;N(!1),(a=T.current)==null||a.reload()};s.useEffect(()=>{if(!I)return;const a=v.AppState.addEventListener("change",e=>{var u;e==="active"&&(N(!1),(u=T.current)==null||u.reload())});return()=>a.remove()},[I]);const L=`window.${xe} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(Ue(n))}, appearance: ${JSON.stringify(S)} });true;`,y=(a,...e)=>{var u;return(u=T.current)==null?void 0:u.injectJavaScript(z(`window.tiunHost.${a}(${e.map(f=>JSON.stringify(f)??"null").join(",")})`))},D=s.useRef(S);s.useEffect(()=>{S!==D.current&&(D.current=S,y("setAppearance",S))},[S]);const x=a=>{var e;$.current||($.current=!0,Q.close().catch(()=>{}),Q.closeAuth().catch(()=>{}),j(!0),(e=T.current)==null||e.injectJavaScript(z(`window.tiunHost.resolveCheckout(${a?JSON.stringify(a):""})`)))},V=a=>{var e,u,f;switch(a.type){case J.popPubKeyRequest:return Le(oe(n)).then(d=>y("popPubKey",d)).catch(d=>{o&&console.warn("[tiun] ensurePopKey failed:",d),y("popPubKey",null)}),!0;case J.tokenGet:return(async()=>{try{const d=await Ve(te(n));if(d&&!await qe(oe(n))){await ce(te(n)),y("restoreToken",null);return}y("restoreToken",d)}catch{y("restoreToken",null)}})(),!0;case J.popSignRequest:{const d=(e=a.payload)==null?void 0:e.requestId,b=(u=a.payload)==null?void 0:u.information;return Fe(oe(n),b).then(R=>y("popSignResult",d,R,null)).catch(R=>{const O=(R==null?void 0:R.code)??"sign_failed";o&&console.warn("[tiun] popSign failed:",R),y("popSignResult",d,null,String(O))}),!0}case J.tokenPersist:{const d=((f=a.payload)==null?void 0:f.token)??null;return(d?Ye(te(n),d):ce(te(n))).catch(b=>o&&console.warn("[tiun] token persist failed:",b)),!0}case J.nativeReset:return Promise.allSettled([We(oe(n)),ce(te(n))]),!0;default:return!1}};s.useImperativeHandle(l,()=>({login:()=>{var a;j(!0),(a=T.current)==null||a.injectJavaScript(z("window.tiunHost.login()"))},checkout:(a,e)=>{var f;j(!0),k.current=!0,$.current=!1;const u=e?[a||null,e]:a?[a]:[];(f=T.current)==null||f.injectJavaScript(z(`window.tiunHost.checkout(${u.map(d=>JSON.stringify(d)).join(",")})`))},logout:()=>{var a;return(a=T.current)==null?void 0:a.injectJavaScript(z("window.tiunHost.logout()"))},getVerificationToken:a=>{var e;return(e=T.current)==null?void 0:e.injectJavaScript(z(`window.tiunHost.getVerificationToken(${a?JSON.stringify(a):""})`))},productRequest:(a,e,...u)=>y(a,e,...u),resolveCheckout:x,reload:()=>{var a;return(a=T.current)==null?void 0:a.reload()}}),[]);const Y=a=>{var u,f,d;let e=null;try{e=JSON.parse(a.nativeEvent.data)}catch{o&&console.warn("[tiun] non-JSON bridge message:",a.nativeEvent.data);return}if(!(!e||typeof e.type!="string")){if(e.type==="console"){o&&console.log("[tiun webview]",(u=e.payload)==null?void 0:u.level,(f=e.payload)==null?void 0:f.message);return}if((e.type==="cryptoCheck"||e.type==="hostBridgeReady")&&N(!1),o&&console.log("[tiun] <-",e.type,e.payload),!V(e)){if(e.type===J.overlayChange){const b=!!((d=e.payload)!=null&&d.overlay);j(b),b||(k.current=!1)}i(e)}}},q=a=>{if(k.current=!1,v.Platform.OS==="ios"){Q.openAuth(a,n.returnUrl).then(e=>{e.type==="success"&&e.url?x(Ee(e.url)):e.type==="cancel"&&x("cancelled")}).catch(e=>o&&console.warn("[tiun] openAuth error:",e));return}Q.open(a,{showTitle:!1,enableUrlBarHiding:!1,enableDefaultShare:!1,forceCloseOnRedirection:!1}).then(e=>{e.type==="cancel"&&x("cancelled")}).catch(e=>o&&console.warn("[tiun] in-app browser open error:",e))},g=a=>{Q.open(a,{modalPresentationStyle:"fullScreen",modalEnabled:!0,animated:!0,enableBarCollapsing:!0}).catch(e=>o&&console.warn("[tiun] in-app browser open failed:",e))},G=a=>{var u;const e=(u=a.nativeEvent)==null?void 0:u.targetUrl;e&&(k.current?q(e):g(e))},F=a=>{const e=a.url;return e.startsWith(ue(n))||e.startsWith("about:")||e.startsWith("data:")||e==="about:blank"?!0:e.startsWith("http://")||e.startsWith("https://")?(k.current&&a.isTopFrame!==!1?q(e):g(e),!1):!0},{width:H,height:B}=v.useWindowDimensions();return m.jsxs(v.View,{pointerEvents:U?"auto":"none",style:[re.container,{width:H,height:B},U?re.visible:re.hidden],children:[m.jsx(Ke,{ref:T,source:{uri:je(n)},originWhitelist:["*"],onMessage:Y,onShouldStartLoadWithRequest:F,onOpenWindow:G,injectedJavaScriptBeforeContentLoaded:L,javaScriptEnabled:!0,domStorageEnabled:!0,style:re.webview,containerStyle:re.webview,onError:a=>{o&&console.warn("[tiun] webview load error:",a.nativeEvent),N(!0)},onHttpError:a=>{o&&console.warn("[tiun] webview http error:",a.nativeEvent),N(!0)}}),I&&U?m.jsx(He,{language:n.language,dark:S==="dark",onRetry:W}):null]})}),re=v.StyleSheet.create({container:{position:"absolute",top:0,left:0,zIndex:9999,elevation:9999},webview:{flex:1,backgroundColor:"transparent"},visible:{opacity:1},hidden:{opacity:0}});class Je{constructor(){fe(this,"listeners",new Map)}on(n,i){let l=this.listeners.get(n);return l||(l=new Set,this.listeners.set(n,l)),l.add(i),()=>{var o;(o=this.listeners.get(n))==null||o.delete(i)}}emit(n,i){const l=this.listeners.get(n);if(l)for(const o of l)try{o(i)}catch{}}}const ze=1e4,he=()=>Promise.reject({code:"invalid_argument",message:"productId is required"}),be=s.createContext(null),ye=s.createContext(null);function Xe({config:r,children:n}){const i=s.useRef(null),l=s.useRef(!1),o=s.useRef([]),E=s.useRef(new Map),S=s.useRef(new Map),T=s.useRef(new Je).current,[U,j]=s.useState(!1),[I,N]=s.useState(null),[k,$]=s.useState(!1),[W,L]=s.useState(null),y=s.useCallback(e=>{l.current?e():o.current.push(e)},[]),D=s.useCallback(e=>{var u,f,d,b,R,O,X,t,c,h,w,P,C,K,M;switch(e.type){case"cryptoCheck":L(!!((u=e.payload)!=null&&u.subtle&&((f=e.payload)!=null&&f.secureContext)));break;case"TIUN_SNIPPET_INITIALIZED":{l.current=!0,$(!0),T.emit("ready",void 0);const p=o.current;o.current=[],p.forEach(_=>_());break}case"TIUN_USER_CHANGE":{const p=!!((d=e.payload)!=null&&d.isAuthenticated),_=((b=e.payload)==null?void 0:b.user)??null;j(p),N(_),T.emit("userChange",{isAuthenticated:p,user:_}),((R=e.payload)==null?void 0:R.userEvent)==="login"&&T.emit("login",{user:_}),((O=e.payload)==null?void 0:O.userEvent)==="logout"&&T.emit("logout",void 0);break}case"TIUN_VERIFICATION_TOKEN":{const p=((X=e.payload)==null?void 0:X.token)??null,_=(t=e.payload)==null?void 0:t.requestId;_&&E.current.has(_)&&(E.current.get(_)(p),E.current.delete(_));break}case"TIUN_PRODUCT_RESULT":{const p=(c=e.payload)==null?void 0:c.requestId,_=p?S.current.get(p):void 0;if(!_)break;clearTimeout(_.timer),S.current.delete(p),(h=e.payload)!=null&&h.error?_.reject(e.payload.error):_.resolve((w=e.payload)==null?void 0:w.result);break}case"TIUN_SHOW_PAYWALL":T.emit("paywallShow",{isConnected:!!((P=e.payload)!=null&&P.isConnected)});break;case"TIUN_HIDE_PAYWALL":T.emit("paywallHide",{sessionId:((C=e.payload)==null?void 0:C.sessionId)??"",isConnected:((K=e.payload)==null?void 0:K.isConnected)??!0});break;case"TIUN_ERROR":T.emit("error",((M=e.payload)==null?void 0:M.error)??e.payload??{});break}},[T]);s.useEffect(()=>{const e=f=>{if(!f||!$e(r,f))return;const d=Ee(f);y(()=>{var b;return(b=i.current)==null?void 0:b.resolveCheckout(d)})},u=v.Linking.addEventListener("url",({url:f})=>e(f));return v.Linking.getInitialURL().then(e).catch(()=>{}),()=>u.remove()},[r,y]);const x=s.useCallback(()=>y(()=>{var e;return(e=i.current)==null?void 0:e.login()}),[y]),V=s.useCallback(()=>y(()=>{var e;return(e=i.current)==null?void 0:e.logout()}),[y]),Y=s.useCallback(e=>y(()=>{var u;return(u=i.current)==null?void 0:u.checkout(e==null?void 0:e.productId,e==null?void 0:e.referenceId)}),[y]),q=s.useCallback(()=>new Promise(e=>{const u=`vt_${Math.random().toString(36).slice(2)}_${Date.now()}`;let f=!1;const d=b=>{f||(f=!0,E.current.delete(u),e(b))};E.current.set(u,d),y(()=>{var b;return(b=i.current)==null?void 0:b.getVerificationToken(u)}),setTimeout(()=>d(null),5e3)}),[y]),g=s.useCallback((e,...u)=>new Promise((f,d)=>{const b=`pr_${Math.random().toString(36).slice(2)}_${Date.now()}`,R={resolve:f,reject:d};S.current.set(b,R),y(()=>{var O;S.current.get(b)===R&&(R.timer=setTimeout(()=>{S.current.delete(b),d({code:"timeout",message:`${e} timed out`})},ze),(O=i.current)==null||O.productRequest(e,b,...u))})}),[y]);s.useEffect(()=>{const e=S.current;return()=>{e.forEach(({reject:u,timer:f})=>{clearTimeout(f),u({code:"destroyed",message:"TiunProvider was unmounted"})}),e.clear()}},[]);const G=s.useCallback(()=>g("listProducts"),[g]),F=s.useCallback(e=>e?g("getProduct",e):he(),[g]),H=s.useCallback(()=>g("listProductAccess"),[g]),B=s.useCallback((e,u)=>e?g("checkProductAccess",e,(u==null?void 0:u.referenceId)||void 0):he(),[g]),a=s.useMemo(()=>({isAuthenticated:U,user:I,ready:k,cryptoOk:W,login:x,logout:V,checkout:Y,getUserVerificationToken:q,listProducts:G,getProduct:F,listProductAccess:H,checkProductAccess:B}),[U,I,k,W,x,V,Y,q,G,F,H,B]);return m.jsx(be.Provider,{value:a,children:m.jsxs(ye.Provider,{value:T,children:[n,m.jsx(Me,{ref:i,config:r,onEvent:D})]})})}function Qe(){const r=s.useContext(be);if(!r)throw new Error("useTiun must be used within a <TiunProvider>");return r}function Ze(r,n){const i=s.useContext(ye),l=s.useRef(n);l.current=n,s.useEffect(()=>{if(!i)throw new Error("useTiunEvent must be used within a <TiunProvider>");return i.on(r,o=>l.current(o))},[i,r])}exports.TiunProvider=Xe;exports.useTiun=Qe;exports.useTiunEvent=Ze;
22
+ <%s key={someKey} {...props} />`,_,S,R,S),Q[S+_]=!0)}if(S=null,T!==void 0&&(i(T),S=""+T),y(c)&&(i(c.key),S=""+c.key),"key"in c){T={};for(var v in c)v!=="key"&&(T[v]=c[v])}else T=c;return S&&p(T,typeof t=="function"?t.displayName||t.name||"Unknown":t),$(t,S,P,N,o(),T,M,J)}function O(t){typeof t=="object"&&t!==null&&t.$$typeof===L&&t._store&&(t._store.validated=1)}var g=s,L=Symbol.for("react.transitional.element"),D=Symbol.for("react.portal"),q=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),A=Symbol.for("react.consumer"),Y=Symbol.for("react.context"),G=Symbol.for("react.forward_ref"),F=Symbol.for("react.suspense"),C=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),W=Symbol.for("react.lazy"),B=Symbol.for("react.activity"),K=Symbol.for("react.client.reference"),a=g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,e=Object.prototype.hasOwnProperty,u=Array.isArray,f=console.createTask?console.createTask:function(){return null};g={"react-stack-bottom-frame":function(t){return t()}};var d,E={},m=g["react-stack-bottom-frame"].bind(g,h)(),I=f(l(h)),Q={};te.Fragment=q,te.jsx=function(t,c,T,_,N){var P=1e4>a.recentlyCreatedOwnerStacks++;return x(t,c,T,!1,_,N,P?Error("react-stack-top-frame"):m,P?f(l(t)):I)},te.jsxs=function(t,c,T,_,N){var P=1e4>a.recentlyCreatedOwnerStacks++;return x(t,c,T,!0,_,N,P?Error("react-stack-top-frame"):m,P?f(l(t)):I)}}()),te}process.env.NODE_ENV==="production"?se.exports=ke():se.exports=ge();var k=se.exports;const Ce={errorPillText:"Technical Error",errorNotificationTitle:"Technical error",errorNotificationSubtitle:"Please reload the page or contact our support.",errorTitle:"Technical error",errorTextBeforeEmail:"Try reloading the page. If the error persists, please contact ",errorTextAfterEmail:" and we’ll help you right away.",connectionErrorTitle:"No connection",connectionErrorText:"We couldn’t reach tiun. Check your internet connection and try again.",connectionErrorCta:"Try again"},Pe={errorPillText:"Erreur Technique",errorNotificationTitle:"Erreur technique",errorNotificationSubtitle:"Veuillez recharger la page ou contacter notre support.",errorTitle:"Erreur technique",errorTextBeforeEmail:"Veuillez recharger la page. Si l’erreur persiste, contactez ",errorTextAfterEmail:" et nous vous aiderons immédiatement.",connectionErrorTitle:"Pas de connexion",connectionErrorText:"Impossible de joindre tiun. Vérifiez votre connexion Internet et réessayez.",connectionErrorCta:"Réessayer"},Ne={errorPillText:"Technischer Fehler",errorNotificationTitle:"Technischer Fehler",errorNotificationSubtitle:"Bitte lade die Seite neu, oder kontaktiere unseren Support.",errorTitle:"Technischer Fehler",errorTextBeforeEmail:"Bitte lade die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktiere ",errorTextAfterEmail:" und wir helfen Dir sofort weiter.",connectionErrorTitle:"Keine Verbindung",connectionErrorText:"tiun konnte nicht erreicht werden. Überprüfe deine Internetverbindung und versuche es erneut.",connectionErrorCta:"Erneut versuchen"},Oe={errorPillText:"Technischer Fehler",errorNotificationTitle:"Technischer Fehler",errorNotificationSubtitle:"Bitte laden Sie die Seite neu, oder kontaktieren Sie unseren Support.",errorTitle:"Technischer Fehler",errorTextBeforeEmail:"Bitte laden Sie die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktieren Sie ",errorTextAfterEmail:" und wir helfen Ihnen sofort weiter.",connectionErrorTitle:"Keine Verbindung",connectionErrorText:"tiun konnte nicht erreicht werden. Überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",connectionErrorCta:"Erneut versuchen"};function Ie(r,n="informal"){switch((r??"en").trim().toLowerCase()){case"de":return n==="formal"?Oe:Ne;case"fr":return Pe;default:return Ce}}const z={start:"TIUN_START",checkout:"TIUN_CHECKOUT",updateContent:"TIUN_UPDATE_CONTENT",login:"TIUN_LOGIN",logout:"TIUN_LOGOUT",getVerificationToken:"TIUN_GET_VERIFICATION_TOKEN",setAppearance:"TIUN_SET_APPEARANCE",listProducts:"TIUN_LIST_PRODUCTS",getProduct:"TIUN_GET_PRODUCT",listProductAccess:"TIUN_LIST_PRODUCT_ACCESS",checkProductAccess:"TIUN_CHECK_PRODUCT_ACCESS",productResult:"TIUN_PRODUCT_RESULT",overlayChange:"TIUN_OVERLAY_CHANGE",popPubKeyRequest:"TIUN_POP_PUBKEY_REQUEST",popSignRequest:"TIUN_POP_SIGN_REQUEST",tokenGet:"TIUN_TOKEN_GET",tokenPersist:"TIUN_TOKEN_PERSIST",nativeReset:"TIUN_NATIVE_RESET",popPubKey:"TIUN_POP_PUBKEY",restoreToken:"TIUN_RESTORE_TOKEN",popSignResult:"TIUN_POP_SIGN_RESULT",resolveCheckout:"TIUN_RESOLVE_CHECKOUT"},xe="__TIUN_NATIVE_CRYPTO__",Ae="https://api.tiun.live";function ue(r){return(r.host??Ae).replace(/\/$/,"")}function ae(r){return`app.tiun.pop.${r.snippetId||"default"}`}function re(r){return`app.tiun.token.${r.snippetId||"default"}`}function Ue(r){return`${`${ue(r)}/live_api/v2/snippets/${encodeURIComponent(r.snippetId)}/webview_return`}?to=${encodeURIComponent(r.returnUrl)}`}function je(r){const n={language:r.language??"en"},i=Object.entries(n).map(([o,h])=>`${encodeURIComponent(o)}=${encodeURIComponent(h)}`).join("&"),l=`${ue(r)}/live_api/v2/snippets/${encodeURIComponent(r.snippetId)}/webview_host`;return i?`${l}?${i}`:l}function Ee(r){const n=r.indexOf("?");if(!(n<0))for(const i of r.slice(n+1).split("&")){const l=i.indexOf("=");if((l<0?i:i.slice(0,l))==="status"){const h=l<0?"":i.slice(l+1);return h?decodeURIComponent(h):void 0}}}function $e(r,n){const i=r.returnUrl.split("?")[0];return n.startsWith(i)}const le="1005";function de(r){return r==null?void 0:r.code}async function Le(r){try{return await oe.getPublicKey(r)}catch(n){if(de(n)===le)return oe.generate(r,{requireUserAuthentication:!1});throw n}}async function qe(r){try{return await oe.getPublicKey(r)}catch(n){if(de(n)===le)return null;throw n}}function Fe(r,n){return oe.sign(r,n)}async function We(r){try{await oe.removeKey(r)}catch(n){if(de(n)!==le)throw n}}const De="tiun_auth_token";async function Ve(r){const n=await ie.getGenericPassword({service:r});return n?n.password:null}async function Ye(r,n){await ie.setGenericPassword(De,n,{service:r,accessible:ie.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY})}async function ce(r){await ie.resetGenericPassword({service:r})}function Ge(r){const n=Ie(r);return{title:n.connectionErrorTitle,text:n.connectionErrorText,cta:n.connectionErrorCta}}function He({language:r,dark:n,onRetry:i}){const l=Ge(r),o=n?Be:null;return k.jsxs(w.View,{style:[U.container,o==null?void 0:o.container],children:[k.jsxs(w.View,{style:U.content,children:[k.jsx(w.Text,{style:[U.title,o==null?void 0:o.title],children:l.title}),k.jsx(w.View,{style:[U.iconBadge,o==null?void 0:o.iconBadge],children:k.jsx(w.Text,{style:[U.iconGlyph,o==null?void 0:o.iconGlyph],children:"!"})}),k.jsx(w.Text,{style:[U.text,o==null?void 0:o.text],children:l.text})]}),k.jsx(w.Pressable,{accessibilityRole:"button",onPress:i,style:({pressed:h})=>[U.button,o==null?void 0:o.button,h&&U.buttonPressed],children:k.jsx(w.Text,{style:[U.buttonText,o==null?void 0:o.buttonText],children:l.cta})})]})}const U=w.StyleSheet.create({container:{...w.StyleSheet.absoluteFillObject,backgroundColor:"#fff",padding:24,justifyContent:"space-between"},content:{flex:1,alignItems:"center",justifyContent:"center",gap:24},title:{fontSize:20,fontWeight:"600",color:"#000",textAlign:"center"},iconBadge:{width:40,height:40,borderRadius:20,backgroundColor:"#FCE7F3",alignItems:"center",justifyContent:"center"},iconGlyph:{color:"#DB2777",fontSize:22,fontWeight:"700",lineHeight:26},text:{fontSize:16,fontWeight:"500",color:"#4B5563",textAlign:"center"},button:{backgroundColor:"#000",borderRadius:999,minHeight:56,alignItems:"center",justifyContent:"center",alignSelf:"stretch"},buttonPressed:{opacity:.9},buttonText:{color:"#fff",fontSize:16,fontWeight:"500"}}),Be=w.StyleSheet.create({container:{backgroundColor:"#0a0a0a"},title:{color:"#fafafa"},iconBadge:{backgroundColor:"#500724"},iconGlyph:{color:"#F472B6"},text:{color:"#A1A1AA"},button:{backgroundColor:"#fafafa"},buttonText:{color:"#000"}}),Ke=we.WebView;function X(r){return`try{window.tiunHost&&${r};}catch(e){}; true;`}const Me=s.forwardRef(function({config:n,onEvent:i},l){const o=!!n.debug,h=w.useColorScheme(),y=n.appearance==="dark"||n.appearance==="auto"&&h==="dark"?"dark":"light",p=s.useRef(null),[j,$]=s.useState(!1),[x,O]=s.useState(!1),g=s.useRef(!1),L=s.useRef(!1),D=()=>{var a;O(!1),(a=p.current)==null||a.reload()};s.useEffect(()=>{if(!x)return;const a=w.AppState.addEventListener("change",e=>{var u;e==="active"&&(O(!1),(u=p.current)==null||u.reload())});return()=>a.remove()},[x]);const q=`window.${xe} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(Ue(n))}, appearance: ${JSON.stringify(y)} });true;`,b=(a,...e)=>{var u;return(u=p.current)==null?void 0:u.injectJavaScript(X(`window.tiunHost.${a}(${e.map(f=>JSON.stringify(f)??"null").join(",")})`))},V=s.useRef(y);s.useEffect(()=>{y!==V.current&&(V.current=y,b("setAppearance",y))},[y]);const A=a=>{var e;L.current||(L.current=!0,Z.close().catch(()=>{}),Z.closeAuth().catch(()=>{}),$(!0),(e=p.current)==null||e.injectJavaScript(X(`window.tiunHost.resolveCheckout(${a?JSON.stringify(a):""})`)))},Y=a=>{var e,u,f;switch(a.type){case z.popPubKeyRequest:return Le(ae(n)).then(d=>b("popPubKey",d)).catch(d=>{o&&console.warn("[tiun] ensurePopKey failed:",d),b("popPubKey",null)}),!0;case z.tokenGet:return(async()=>{try{const d=await Ve(re(n));if(d&&!await qe(ae(n))){await ce(re(n)),b("restoreToken",null);return}b("restoreToken",d)}catch{b("restoreToken",null)}})(),!0;case z.popSignRequest:{const d=(e=a.payload)==null?void 0:e.requestId,E=(u=a.payload)==null?void 0:u.information;return Fe(ae(n),E).then(m=>b("popSignResult",d,m,null)).catch(m=>{const I=(m==null?void 0:m.code)??"sign_failed";o&&console.warn("[tiun] popSign failed:",m),b("popSignResult",d,null,String(I))}),!0}case z.tokenPersist:{const d=((f=a.payload)==null?void 0:f.token)??null;return(d?Ye(re(n),d):ce(re(n))).catch(E=>o&&console.warn("[tiun] token persist failed:",E)),!0}case z.nativeReset:return Promise.allSettled([We(ae(n)),ce(re(n))]),!0;default:return!1}};s.useImperativeHandle(l,()=>({login:()=>{var a;$(!0),(a=p.current)==null||a.injectJavaScript(X("window.tiunHost.login()"))},checkout:(a,e)=>{var f;$(!0),g.current=!0,L.current=!1;const u=e?[a||null,e]:a?[a]:[];(f=p.current)==null||f.injectJavaScript(X(`window.tiunHost.checkout(${u.map(d=>JSON.stringify(d)).join(",")})`))},logout:()=>{var a;return(a=p.current)==null?void 0:a.injectJavaScript(X("window.tiunHost.logout()"))},getVerificationToken:a=>{var e;return(e=p.current)==null?void 0:e.injectJavaScript(X(`window.tiunHost.getVerificationToken(${a?JSON.stringify(a):""})`))},productRequest:(a,e,...u)=>b(a,e,...u),resolveCheckout:A,reload:()=>{var a;return(a=p.current)==null?void 0:a.reload()}}),[]);const G=a=>{var u,f,d;let e=null;try{e=JSON.parse(a.nativeEvent.data)}catch{o&&console.warn("[tiun] non-JSON bridge message:",a.nativeEvent.data);return}if(!(!e||typeof e.type!="string")){if(e.type==="console"){o&&console.log("[tiun webview]",(u=e.payload)==null?void 0:u.level,(f=e.payload)==null?void 0:f.message);return}if((e.type==="cryptoCheck"||e.type==="hostBridgeReady")&&O(!1),o&&console.log("[tiun] <-",e.type,e.payload),!Y(e)){if(e.type===z.overlayChange){const E=!!((d=e.payload)!=null&&d.overlay);$(E),E||(g.current=!1)}i(e)}}},F=a=>{if(g.current=!1,w.Platform.OS==="ios"){Z.openAuth(a,n.returnUrl).then(e=>{e.type==="success"&&e.url?A(Ee(e.url)):e.type==="cancel"&&A("cancelled")}).catch(e=>o&&console.warn("[tiun] openAuth error:",e));return}Z.open(a,{showTitle:!1,enableUrlBarHiding:!1,enableDefaultShare:!1,forceCloseOnRedirection:!1}).then(e=>{e.type==="cancel"&&A("cancelled")}).catch(e=>o&&console.warn("[tiun] in-app browser open error:",e))},C=a=>{Z.open(a,{modalPresentationStyle:"fullScreen",modalEnabled:!0,animated:!0,enableBarCollapsing:!0}).catch(e=>o&&console.warn("[tiun] in-app browser open failed:",e))},H=a=>{var u;const e=(u=a.nativeEvent)==null?void 0:u.targetUrl;e&&(g.current?F(e):C(e))},W=a=>{const e=a.url;return e.startsWith(ue(n))||e.startsWith("about:")||e.startsWith("data:")||e==="about:blank"?!0:e.startsWith("http://")||e.startsWith("https://")?(g.current&&a.isTopFrame!==!1?F(e):C(e),!1):!0},{width:B,height:K}=w.useWindowDimensions();return k.jsxs(w.View,{pointerEvents:j?"auto":"none",style:[ne.container,{width:B,height:K},j?ne.visible:ne.hidden],children:[k.jsx(Ke,{ref:p,source:{uri:je(n)},originWhitelist:["*"],onMessage:G,onShouldStartLoadWithRequest:W,onOpenWindow:H,injectedJavaScriptBeforeContentLoaded:q,javaScriptEnabled:!0,domStorageEnabled:!0,style:ne.webview,containerStyle:ne.webview,onError:a=>{o&&console.warn("[tiun] webview load error:",a.nativeEvent),O(!0)},onHttpError:a=>{o&&console.warn("[tiun] webview http error:",a.nativeEvent),O(!0)}}),x&&j?k.jsx(He,{language:n.language,dark:y==="dark",onRetry:D}):null]})}),ne=w.StyleSheet.create({container:{position:"absolute",top:0,left:0,zIndex:9999,elevation:9999},webview:{flex:1,backgroundColor:"transparent"},visible:{opacity:1},hidden:{opacity:0}});class Je{constructor(){fe(this,"listeners",new Map)}on(n,i){let l=this.listeners.get(n);return l||(l=new Set,this.listeners.set(n,l)),l.add(i),()=>{var o;(o=this.listeners.get(n))==null||o.delete(i)}}emit(n,i){const l=this.listeners.get(n);if(l)for(const o of l)try{o(i)}catch{}}}const ze=1e4,he=()=>Promise.reject({code:"invalid_argument",message:"productId is required"}),be=s.createContext(null),ye=s.createContext(null);function Xe({config:r,children:n}){const i=s.useRef(null),l=s.useRef(!1),o=s.useRef([]),h=s.useRef(new Map),y=s.useRef(new Map),p=s.useRef(new Je).current,[j,$]=s.useState(!1),[x,O]=s.useState(null),[g,L]=s.useState(!1),[D,q]=s.useState(null),b=s.useCallback(e=>{l.current?e():o.current.push(e)},[]),V=s.useCallback(e=>{var u,f,d,E,m,I,Q,t,c,T,_,N,P,M,J,S;switch(e.type){case"cryptoCheck":q(!!((u=e.payload)!=null&&u.subtle&&((f=e.payload)!=null&&f.secureContext)));break;case"TIUN_SNIPPET_INITIALIZED":{l.current=!0,L(!0),p.emit("ready",void 0);const R=o.current;o.current=[],R.forEach(v=>v());break}case"TIUN_USER_CHANGE":{const R=!!((d=e.payload)!=null&&d.isAuthenticated),v=((E=e.payload)==null?void 0:E.user)??null;$(R),O(v),p.emit("userChange",{event:((m=e.payload)==null?void 0:m.userEvent)??"update",isAuthenticated:R,user:v}),((I=e.payload)==null?void 0:I.userEvent)==="login"&&p.emit("login",{user:v}),((Q=e.payload)==null?void 0:Q.userEvent)==="logout"&&p.emit("logout",void 0);break}case"TIUN_VERIFICATION_TOKEN":{const R=((t=e.payload)==null?void 0:t.token)??null,v=(c=e.payload)==null?void 0:c.requestId;v&&h.current.has(v)&&(h.current.get(v)(R),h.current.delete(v));break}case"TIUN_PRODUCT_RESULT":{const R=(T=e.payload)==null?void 0:T.requestId,v=R?y.current.get(R):void 0;if(!v)break;clearTimeout(v.timer),y.current.delete(R),(_=e.payload)!=null&&_.error?v.reject(e.payload.error):v.resolve((N=e.payload)==null?void 0:N.result);break}case"TIUN_SHOW_PAYWALL":p.emit("paywallShow",{isConnected:!!((P=e.payload)!=null&&P.isConnected)});break;case"TIUN_HIDE_PAYWALL":p.emit("paywallHide",{sessionId:((M=e.payload)==null?void 0:M.sessionId)??"",isConnected:((J=e.payload)==null?void 0:J.isConnected)??!0});break;case"TIUN_ERROR":p.emit("error",((S=e.payload)==null?void 0:S.error)??e.payload??{});break}},[p]);s.useEffect(()=>{const e=f=>{if(!f||!$e(r,f))return;const d=Ee(f);b(()=>{var E;return(E=i.current)==null?void 0:E.resolveCheckout(d)})},u=w.Linking.addEventListener("url",({url:f})=>e(f));return w.Linking.getInitialURL().then(e).catch(()=>{}),()=>u.remove()},[r,b]);const A=s.useCallback(()=>b(()=>{var e;return(e=i.current)==null?void 0:e.login()}),[b]),Y=s.useCallback(()=>b(()=>{var e;return(e=i.current)==null?void 0:e.logout()}),[b]),G=s.useCallback(e=>b(()=>{var u;return(u=i.current)==null?void 0:u.checkout(e==null?void 0:e.productId,e==null?void 0:e.referenceId)}),[b]),F=s.useCallback(()=>new Promise(e=>{const u=`vt_${Math.random().toString(36).slice(2)}_${Date.now()}`;let f=!1;const d=E=>{f||(f=!0,h.current.delete(u),e(E))};h.current.set(u,d),b(()=>{var E;return(E=i.current)==null?void 0:E.getVerificationToken(u)}),setTimeout(()=>d(null),5e3)}),[b]),C=s.useCallback((e,...u)=>new Promise((f,d)=>{const E=`pr_${Math.random().toString(36).slice(2)}_${Date.now()}`,m={resolve:f,reject:d};y.current.set(E,m),b(()=>{var I;y.current.get(E)===m&&(m.timer=setTimeout(()=>{y.current.delete(E),d({code:"timeout",message:`${e} timed out`})},ze),(I=i.current)==null||I.productRequest(e,E,...u))})}),[b]);s.useEffect(()=>{const e=y.current;return()=>{e.forEach(({reject:u,timer:f})=>{clearTimeout(f),u({code:"destroyed",message:"TiunProvider was unmounted"})}),e.clear()}},[]);const H=s.useCallback(()=>C("listProducts"),[C]),W=s.useCallback(e=>e?C("getProduct",e):he(),[C]),B=s.useCallback(()=>C("listProductAccess"),[C]),K=s.useCallback((e,u)=>e?C("checkProductAccess",e,(u==null?void 0:u.referenceId)||void 0):he(),[C]),a=s.useMemo(()=>({isAuthenticated:j,user:x,ready:g,cryptoOk:D,login:A,logout:Y,checkout:G,getUserVerificationToken:F,listProducts:H,getProduct:W,listProductAccess:B,checkProductAccess:K}),[j,x,g,D,A,Y,G,F,H,W,B,K]);return k.jsx(be.Provider,{value:a,children:k.jsxs(ye.Provider,{value:p,children:[n,k.jsx(Me,{ref:i,config:r,onEvent:V})]})})}function Qe(){const r=s.useContext(be);if(!r)throw new Error("useTiun must be used within a <TiunProvider>");return r}function Ze(r,n){const i=s.useContext(ye),l=s.useRef(n);l.current=n,s.useEffect(()=>{if(!i)throw new Error("useTiunEvent must be used within a <TiunProvider>");return i.on(r,o=>l.current(o))},[i,r])}exports.TiunProvider=Xe;exports.useTiun=Qe;exports.useTiunEvent=Ze;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  var Ce = Object.defineProperty;
2
2
  var Ie = (n, r, a) => r in n ? Ce(n, r, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[r] = a;
3
3
  var he = (n, r, a) => (Ie(n, typeof r != "symbol" ? r + "" : r, a), a);
4
- import Ne, { forwardRef as Oe, useRef as C, useState as X, useEffect as ne, useImperativeHandle as Ae, createContext as me, useCallback as P, useMemo as xe, useContext as ve } from "react";
5
- import { StyleSheet as ce, View as ae, Text as oe, Pressable as Ue, useColorScheme as je, AppState as $e, useWindowDimensions as Le, Platform as Fe, Linking as Ee } from "react-native";
4
+ import Ne, { forwardRef as Oe, useRef as I, useState as Q, useEffect as oe, useImperativeHandle as Ae, createContext as me, useCallback as C, useMemo as xe, useContext as ve } from "react";
5
+ import { StyleSheet as se, View as ce, Text as ie, Pressable as Ue, useColorScheme as je, AppState as $e, useWindowDimensions as Le, Platform as Fe, Linking as Ee } from "react-native";
6
6
  import { WebView as We } from "react-native-webview";
7
7
  import { close as qe, closeAuth as De, openAuth as Ve, open as be } from "react-native-inappbrowser-nitro";
8
8
  import { getPublicKey as Se, generate as Ye, sign as Ge, removeKey as He } from "react-native-secure-sign";
9
- import * as se from "react-native-keychain";
10
- var de = { exports: {} }, Z = {};
9
+ import * as ue from "react-native-keychain";
10
+ var de = { exports: {} }, ee = {};
11
11
  /**
12
12
  * @license React
13
13
  * react-jsx-runtime.production.js
@@ -20,28 +20,28 @@ var de = { exports: {} }, Z = {};
20
20
  var _e;
21
21
  function Be() {
22
22
  if (_e)
23
- return Z;
23
+ return ee;
24
24
  _e = 1;
25
25
  var n = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
26
- function a(u, o, h) {
27
- var y = null;
28
- if (h !== void 0 && (y = "" + h), o.key !== void 0 && (y = "" + o.key), "key" in o) {
29
- h = {};
30
- for (var p in o)
31
- p !== "key" && (h[p] = o[p]);
26
+ function a(u, o, T) {
27
+ var b = null;
28
+ if (T !== void 0 && (b = "" + T), o.key !== void 0 && (b = "" + o.key), "key" in o) {
29
+ T = {};
30
+ for (var f in o)
31
+ f !== "key" && (T[f] = o[f]);
32
32
  } else
33
- h = o;
34
- return o = h.ref, {
33
+ T = o;
34
+ return o = T.ref, {
35
35
  $$typeof: n,
36
36
  type: u,
37
- key: y,
37
+ key: b,
38
38
  ref: o !== void 0 ? o : null,
39
- props: h
39
+ props: T
40
40
  };
41
41
  }
42
- return Z.Fragment = r, Z.jsx = a, Z.jsxs = a, Z;
42
+ return ee.Fragment = r, ee.jsx = a, ee.jsxs = a, ee;
43
43
  }
44
- var ee = {};
44
+ var te = {};
45
45
  /**
46
46
  * @license React
47
47
  * react-jsx-runtime.development.js
@@ -58,39 +58,39 @@ function Ke() {
58
58
  if (t == null)
59
59
  return null;
60
60
  if (typeof t == "function")
61
- return t.$$typeof === B ? null : t.displayName || t.name || null;
61
+ return t.$$typeof === K ? null : t.displayName || t.name || null;
62
62
  if (typeof t == "string")
63
63
  return t;
64
64
  switch (t) {
65
- case L:
65
+ case F:
66
66
  return "Fragment";
67
- case D:
67
+ case V:
68
68
  return "Profiler";
69
- case b:
69
+ case E:
70
70
  return "StrictMode";
71
- case F:
71
+ case W:
72
72
  return "Suspense";
73
- case R:
73
+ case k:
74
74
  return "SuspenseList";
75
- case H:
75
+ case B:
76
76
  return "Activity";
77
77
  }
78
78
  if (typeof t == "object")
79
79
  switch (typeof t.tag == "number" && console.error(
80
80
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
81
81
  ), t.$$typeof) {
82
- case q:
82
+ case D:
83
83
  return "Portal";
84
- case V:
84
+ case Y:
85
85
  return (t.displayName || "Context") + ".Provider";
86
- case A:
86
+ case x:
87
87
  return (t._context.displayName || "Context") + ".Consumer";
88
- case Y:
88
+ case G:
89
89
  var c = t.render;
90
90
  return t = t.displayName, t || (t = c.displayName || c.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
91
- case G:
91
+ case H:
92
92
  return c = t.displayName || null, c !== null ? c : n(t.type) || "Memo";
93
- case W:
93
+ case q:
94
94
  c = t._payload, t = t._init;
95
95
  try {
96
96
  return n(t(c));
@@ -111,18 +111,18 @@ function Ke() {
111
111
  }
112
112
  if (c) {
113
113
  c = console;
114
- var T = c.error, w = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
115
- return T.call(
114
+ var p = c.error, _ = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
115
+ return p.call(
116
116
  c,
117
117
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
118
- w
118
+ _
119
119
  ), r(t);
120
120
  }
121
121
  }
122
122
  function u(t) {
123
- if (t === L)
123
+ if (t === F)
124
124
  return "<>";
125
- if (typeof t == "object" && t !== null && t.$$typeof === W)
125
+ if (typeof t == "object" && t !== null && t.$$typeof === q)
126
126
  return "<...>";
127
127
  try {
128
128
  var c = n(t);
@@ -135,10 +135,10 @@ function Ke() {
135
135
  var t = i.A;
136
136
  return t === null ? null : t.getOwner();
137
137
  }
138
- function h() {
138
+ function T() {
139
139
  return Error("react-stack-top-frame");
140
140
  }
141
- function y(t) {
141
+ function b(t) {
142
142
  if (e.call(t, "key")) {
143
143
  var c = Object.getOwnPropertyDescriptor(t, "key").get;
144
144
  if (c && c.isReactWarning)
@@ -146,34 +146,34 @@ function Ke() {
146
146
  }
147
147
  return t.key !== void 0;
148
148
  }
149
- function p(t, c) {
150
- function T() {
149
+ function f(t, c) {
150
+ function p() {
151
151
  l || (l = !0, console.error(
152
152
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
153
153
  c
154
154
  ));
155
155
  }
156
- T.isReactWarning = !0, Object.defineProperty(t, "key", {
157
- get: T,
156
+ p.isReactWarning = !0, Object.defineProperty(t, "key", {
157
+ get: p,
158
158
  configurable: !0
159
159
  });
160
160
  }
161
- function U() {
161
+ function j() {
162
162
  var t = n(this.type);
163
- return E[t] || (E[t] = !0, console.error(
163
+ return h[t] || (h[t] = !0, console.error(
164
164
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
165
165
  )), t = this.props.ref, t !== void 0 ? t : null;
166
166
  }
167
- function j(t, c, T, w, k, g, K, J) {
168
- return T = g.ref, t = {
169
- $$typeof: $,
167
+ function $(t, c, p, _, P, g, J, M) {
168
+ return p = g.ref, t = {
169
+ $$typeof: L,
170
170
  type: t,
171
171
  key: c,
172
172
  props: g,
173
- _owner: k
174
- }, (T !== void 0 ? T : null) !== null ? Object.defineProperty(t, "ref", {
173
+ _owner: P
174
+ }, (p !== void 0 ? p : null) !== null ? Object.defineProperty(t, "ref", {
175
175
  enumerable: !1,
176
- get: U
176
+ get: j
177
177
  }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
178
178
  configurable: !1,
179
179
  enumerable: !1,
@@ -188,110 +188,110 @@ function Ke() {
188
188
  configurable: !1,
189
189
  enumerable: !1,
190
190
  writable: !0,
191
- value: K
191
+ value: J
192
192
  }), Object.defineProperty(t, "_debugTask", {
193
193
  configurable: !1,
194
194
  enumerable: !1,
195
195
  writable: !0,
196
- value: J
196
+ value: M
197
197
  }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
198
198
  }
199
- function O(t, c, T, w, k, g, K, J) {
200
- var f = c.children;
201
- if (f !== void 0)
202
- if (w)
203
- if (s(f)) {
204
- for (w = 0; w < f.length; w++)
205
- I(f[w]);
206
- Object.freeze && Object.freeze(f);
199
+ function A(t, c, p, _, P, g, J, M) {
200
+ var y = c.children;
201
+ if (y !== void 0)
202
+ if (_)
203
+ if (s(y)) {
204
+ for (_ = 0; _ < y.length; _++)
205
+ N(y[_]);
206
+ Object.freeze && Object.freeze(y);
207
207
  } else
208
208
  console.error(
209
209
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
210
210
  );
211
211
  else
212
- I(f);
212
+ N(y);
213
213
  if (e.call(c, "key")) {
214
- f = n(t);
215
- var _ = Object.keys(c).filter(function(Pe) {
214
+ y = n(t);
215
+ var m = Object.keys(c).filter(function(Pe) {
216
216
  return Pe !== "key";
217
217
  });
218
- w = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", Q[f + w] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
218
+ _ = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", Z[y + _] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error(
219
219
  `A props object containing a "key" prop is being spread into JSX:
220
220
  let props = %s;
221
221
  <%s {...props} />
222
222
  React keys must be passed directly to JSX without using spread:
223
223
  let props = %s;
224
224
  <%s key={someKey} {...props} />`,
225
- w,
226
- f,
227
225
  _,
228
- f
229
- ), Q[f + w] = !0);
226
+ y,
227
+ m,
228
+ y
229
+ ), Z[y + _] = !0);
230
230
  }
231
- if (f = null, T !== void 0 && (a(T), f = "" + T), y(c) && (a(c.key), f = "" + c.key), "key" in c) {
232
- T = {};
233
- for (var ue in c)
234
- ue !== "key" && (T[ue] = c[ue]);
231
+ if (y = null, p !== void 0 && (a(p), y = "" + p), b(c) && (a(c.key), y = "" + c.key), "key" in c) {
232
+ p = {};
233
+ for (var w in c)
234
+ w !== "key" && (p[w] = c[w]);
235
235
  } else
236
- T = c;
237
- return f && p(
238
- T,
236
+ p = c;
237
+ return y && f(
238
+ p,
239
239
  typeof t == "function" ? t.displayName || t.name || "Unknown" : t
240
- ), j(
240
+ ), $(
241
241
  t,
242
- f,
242
+ y,
243
243
  g,
244
- k,
244
+ P,
245
245
  o(),
246
- T,
247
- K,
248
- J
246
+ p,
247
+ J,
248
+ M
249
249
  );
250
250
  }
251
- function I(t) {
252
- typeof t == "object" && t !== null && t.$$typeof === $ && t._store && (t._store.validated = 1);
251
+ function N(t) {
252
+ typeof t == "object" && t !== null && t.$$typeof === L && t._store && (t._store.validated = 1);
253
253
  }
254
- var S = Ne, $ = Symbol.for("react.transitional.element"), q = Symbol.for("react.portal"), L = Symbol.for("react.fragment"), b = Symbol.for("react.strict_mode"), D = Symbol.for("react.profiler"), A = Symbol.for("react.consumer"), V = Symbol.for("react.context"), Y = Symbol.for("react.forward_ref"), F = Symbol.for("react.suspense"), R = Symbol.for("react.suspense_list"), G = Symbol.for("react.memo"), W = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), B = Symbol.for("react.client.reference"), i = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, e = Object.prototype.hasOwnProperty, s = Array.isArray, d = console.createTask ? console.createTask : function() {
254
+ var R = Ne, L = Symbol.for("react.transitional.element"), D = Symbol.for("react.portal"), F = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), V = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), Y = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), W = Symbol.for("react.suspense"), k = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), q = Symbol.for("react.lazy"), B = Symbol.for("react.activity"), K = Symbol.for("react.client.reference"), i = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, e = Object.prototype.hasOwnProperty, s = Array.isArray, d = console.createTask ? console.createTask : function() {
255
255
  return null;
256
256
  };
257
- S = {
257
+ R = {
258
258
  "react-stack-bottom-frame": function(t) {
259
259
  return t();
260
260
  }
261
261
  };
262
- var l, E = {}, m = S["react-stack-bottom-frame"].bind(
263
- S,
264
- h
265
- )(), N = d(u(h)), Q = {};
266
- ee.Fragment = L, ee.jsx = function(t, c, T, w, k) {
262
+ var l, h = {}, v = R["react-stack-bottom-frame"].bind(
263
+ R,
264
+ T
265
+ )(), O = d(u(T)), Z = {};
266
+ te.Fragment = F, te.jsx = function(t, c, p, _, P) {
267
267
  var g = 1e4 > i.recentlyCreatedOwnerStacks++;
268
- return O(
268
+ return A(
269
269
  t,
270
270
  c,
271
- T,
271
+ p,
272
272
  !1,
273
- w,
274
- k,
275
- g ? Error("react-stack-top-frame") : m,
276
- g ? d(u(t)) : N
273
+ _,
274
+ P,
275
+ g ? Error("react-stack-top-frame") : v,
276
+ g ? d(u(t)) : O
277
277
  );
278
- }, ee.jsxs = function(t, c, T, w, k) {
278
+ }, te.jsxs = function(t, c, p, _, P) {
279
279
  var g = 1e4 > i.recentlyCreatedOwnerStacks++;
280
- return O(
280
+ return A(
281
281
  t,
282
282
  c,
283
- T,
283
+ p,
284
284
  !0,
285
- w,
286
- k,
287
- g ? Error("react-stack-top-frame") : m,
288
- g ? d(u(t)) : N
285
+ _,
286
+ P,
287
+ g ? Error("react-stack-top-frame") : v,
288
+ g ? d(u(t)) : O
289
289
  );
290
290
  };
291
- }()), ee;
291
+ }()), te;
292
292
  }
293
293
  process.env.NODE_ENV === "production" ? de.exports = Be() : de.exports = Ke();
294
- var v = de.exports;
294
+ var S = de.exports;
295
295
  const Je = {
296
296
  errorPillText: "Technical Error",
297
297
  errorNotificationTitle: "Technical error",
@@ -343,7 +343,7 @@ function Qe(n, r = "informal") {
343
343
  return Je;
344
344
  }
345
345
  }
346
- const M = {
346
+ const z = {
347
347
  // Web protocol (TIUN_EVENT) — consumer → snippet commands.
348
348
  start: "TIUN_START",
349
349
  checkout: "TIUN_CHECKOUT",
@@ -375,10 +375,10 @@ const M = {
375
375
  function fe(n) {
376
376
  return (n.host ?? et).replace(/\/$/, "");
377
377
  }
378
- function ie(n) {
378
+ function ae(n) {
379
379
  return `app.tiun.pop.${n.snippetId || "default"}`;
380
380
  }
381
- function te(n) {
381
+ function re(n) {
382
382
  return `app.tiun.token.${n.snippetId || "default"}`;
383
383
  }
384
384
  function tt(n) {
@@ -387,7 +387,7 @@ function tt(n) {
387
387
  function rt(n) {
388
388
  const r = {
389
389
  language: n.language ?? "en"
390
- }, a = Object.entries(r).map(([o, h]) => `${encodeURIComponent(o)}=${encodeURIComponent(h)}`).join("&"), u = `${fe(n)}/live_api/v2/snippets/${encodeURIComponent(n.snippetId)}/webview_host`;
390
+ }, a = Object.entries(r).map(([o, T]) => `${encodeURIComponent(o)}=${encodeURIComponent(T)}`).join("&"), u = `${fe(n)}/live_api/v2/snippets/${encodeURIComponent(n.snippetId)}/webview_host`;
391
391
  return a ? `${u}?${a}` : u;
392
392
  }
393
393
  function Re(n) {
@@ -396,8 +396,8 @@ function Re(n) {
396
396
  for (const a of n.slice(r + 1).split("&")) {
397
397
  const u = a.indexOf("=");
398
398
  if ((u < 0 ? a : a.slice(0, u)) === "status") {
399
- const h = u < 0 ? "" : a.slice(u + 1);
400
- return h ? decodeURIComponent(h) : void 0;
399
+ const T = u < 0 ? "" : a.slice(u + 1);
400
+ return T ? decodeURIComponent(T) : void 0;
401
401
  }
402
402
  }
403
403
  }
@@ -440,17 +440,17 @@ async function ct(n) {
440
440
  }
441
441
  const st = "tiun_auth_token";
442
442
  async function ut(n) {
443
- const r = await se.getGenericPassword({ service: n });
443
+ const r = await ue.getGenericPassword({ service: n });
444
444
  return r ? r.password : null;
445
445
  }
446
446
  async function lt(n, r) {
447
- await se.setGenericPassword(st, r, {
447
+ await ue.setGenericPassword(st, r, {
448
448
  service: n,
449
- accessible: se.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY
449
+ accessible: ue.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY
450
450
  });
451
451
  }
452
452
  async function le(n) {
453
- await se.resetGenericPassword({ service: n });
453
+ await ue.resetGenericPassword({ service: n });
454
454
  }
455
455
  function dt(n) {
456
456
  const r = Qe(n);
@@ -462,30 +462,30 @@ function dt(n) {
462
462
  }
463
463
  function ft({ language: n, dark: r, onRetry: a }) {
464
464
  const u = dt(n), o = r ? pt : null;
465
- return /* @__PURE__ */ v.jsxs(ae, { style: [x.container, o == null ? void 0 : o.container], children: [
466
- /* @__PURE__ */ v.jsxs(ae, { style: x.content, children: [
467
- /* @__PURE__ */ v.jsx(oe, { style: [x.title, o == null ? void 0 : o.title], children: u.title }),
468
- /* @__PURE__ */ v.jsx(ae, { style: [x.iconBadge, o == null ? void 0 : o.iconBadge], children: /* @__PURE__ */ v.jsx(oe, { style: [x.iconGlyph, o == null ? void 0 : o.iconGlyph], children: "!" }) }),
469
- /* @__PURE__ */ v.jsx(oe, { style: [x.text, o == null ? void 0 : o.text], children: u.text })
465
+ return /* @__PURE__ */ S.jsxs(ce, { style: [U.container, o == null ? void 0 : o.container], children: [
466
+ /* @__PURE__ */ S.jsxs(ce, { style: U.content, children: [
467
+ /* @__PURE__ */ S.jsx(ie, { style: [U.title, o == null ? void 0 : o.title], children: u.title }),
468
+ /* @__PURE__ */ S.jsx(ce, { style: [U.iconBadge, o == null ? void 0 : o.iconBadge], children: /* @__PURE__ */ S.jsx(ie, { style: [U.iconGlyph, o == null ? void 0 : o.iconGlyph], children: "!" }) }),
469
+ /* @__PURE__ */ S.jsx(ie, { style: [U.text, o == null ? void 0 : o.text], children: u.text })
470
470
  ] }),
471
- /* @__PURE__ */ v.jsx(
471
+ /* @__PURE__ */ S.jsx(
472
472
  Ue,
473
473
  {
474
474
  accessibilityRole: "button",
475
475
  onPress: a,
476
- style: ({ pressed: h }) => [
477
- x.button,
476
+ style: ({ pressed: T }) => [
477
+ U.button,
478
478
  o == null ? void 0 : o.button,
479
- h && x.buttonPressed
479
+ T && U.buttonPressed
480
480
  ],
481
- children: /* @__PURE__ */ v.jsx(oe, { style: [x.buttonText, o == null ? void 0 : o.buttonText], children: u.cta })
481
+ children: /* @__PURE__ */ S.jsx(ie, { style: [U.buttonText, o == null ? void 0 : o.buttonText], children: u.cta })
482
482
  }
483
483
  )
484
484
  ] });
485
485
  }
486
- const x = ce.create({
486
+ const U = se.create({
487
487
  container: {
488
- ...ce.absoluteFillObject,
488
+ ...se.absoluteFillObject,
489
489
  backgroundColor: "#fff",
490
490
  padding: 24,
491
491
  justifyContent: "space-between"
@@ -539,7 +539,7 @@ const x = ce.create({
539
539
  fontSize: 16,
540
540
  fontWeight: "500"
541
541
  }
542
- }), pt = ce.create({
542
+ }), pt = se.create({
543
543
  container: { backgroundColor: "#0a0a0a" },
544
544
  title: { color: "#fafafa" },
545
545
  iconBadge: { backgroundColor: "#500724" },
@@ -551,81 +551,81 @@ const x = ce.create({
551
551
  button: { backgroundColor: "#fafafa" },
552
552
  buttonText: { color: "#000" }
553
553
  }), Tt = We;
554
- function z(n) {
554
+ function X(n) {
555
555
  return `try{window.tiunHost&&${n};}catch(e){}; true;`;
556
556
  }
557
557
  const ht = Oe(
558
558
  function({ config: r, onEvent: a }, u) {
559
- const o = !!r.debug, h = je(), y = r.appearance === "dark" || r.appearance === "auto" && h === "dark" ? "dark" : "light", p = C(null), [U, j] = X(!1), [O, I] = X(!1), S = C(!1), $ = C(!1), q = () => {
559
+ const o = !!r.debug, T = je(), b = r.appearance === "dark" || r.appearance === "auto" && T === "dark" ? "dark" : "light", f = I(null), [j, $] = Q(!1), [A, N] = Q(!1), R = I(!1), L = I(!1), D = () => {
560
560
  var i;
561
- I(!1), (i = p.current) == null || i.reload();
561
+ N(!1), (i = f.current) == null || i.reload();
562
562
  };
563
- ne(() => {
564
- if (!O)
563
+ oe(() => {
564
+ if (!A)
565
565
  return;
566
566
  const i = $e.addEventListener("change", (e) => {
567
567
  var s;
568
- e === "active" && (I(!1), (s = p.current) == null || s.reload());
568
+ e === "active" && (N(!1), (s = f.current) == null || s.reload());
569
569
  });
570
570
  return () => i.remove();
571
- }, [O]);
572
- const L = `window.${Ze} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(tt(r))}, appearance: ${JSON.stringify(y)} });true;`, b = (i, ...e) => {
571
+ }, [A]);
572
+ const F = `window.${Ze} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(tt(r))}, appearance: ${JSON.stringify(b)} });true;`, E = (i, ...e) => {
573
573
  var s;
574
- return (s = p.current) == null ? void 0 : s.injectJavaScript(
575
- z(
574
+ return (s = f.current) == null ? void 0 : s.injectJavaScript(
575
+ X(
576
576
  `window.tiunHost.${i}(${e.map((d) => JSON.stringify(d) ?? "null").join(",")})`
577
577
  )
578
578
  );
579
- }, D = C(y);
580
- ne(() => {
581
- y !== D.current && (D.current = y, b("setAppearance", y));
582
- }, [y]);
583
- const A = (i) => {
579
+ }, V = I(b);
580
+ oe(() => {
581
+ b !== V.current && (V.current = b, E("setAppearance", b));
582
+ }, [b]);
583
+ const x = (i) => {
584
584
  var e;
585
- $.current || ($.current = !0, qe().catch(() => {
585
+ L.current || (L.current = !0, qe().catch(() => {
586
586
  }), De().catch(() => {
587
- }), j(!0), (e = p.current) == null || e.injectJavaScript(
588
- z(
587
+ }), $(!0), (e = f.current) == null || e.injectJavaScript(
588
+ X(
589
589
  `window.tiunHost.resolveCheckout(${i ? JSON.stringify(i) : ""})`
590
590
  )
591
591
  ));
592
- }, V = (i) => {
592
+ }, Y = (i) => {
593
593
  var e, s, d;
594
594
  switch (i.type) {
595
- case M.popPubKeyRequest:
596
- return ot(ie(r)).then((l) => b("popPubKey", l)).catch((l) => {
597
- o && console.warn("[tiun] ensurePopKey failed:", l), b("popPubKey", null);
595
+ case z.popPubKeyRequest:
596
+ return ot(ae(r)).then((l) => E("popPubKey", l)).catch((l) => {
597
+ o && console.warn("[tiun] ensurePopKey failed:", l), E("popPubKey", null);
598
598
  }), !0;
599
- case M.tokenGet:
599
+ case z.tokenGet:
600
600
  return (async () => {
601
601
  try {
602
- const l = await ut(te(r));
603
- if (l && !await it(ie(r))) {
604
- await le(te(r)), b("restoreToken", null);
602
+ const l = await ut(re(r));
603
+ if (l && !await it(ae(r))) {
604
+ await le(re(r)), E("restoreToken", null);
605
605
  return;
606
606
  }
607
- b("restoreToken", l);
607
+ E("restoreToken", l);
608
608
  } catch {
609
- b("restoreToken", null);
609
+ E("restoreToken", null);
610
610
  }
611
611
  })(), !0;
612
- case M.popSignRequest: {
613
- const l = (e = i.payload) == null ? void 0 : e.requestId, E = (s = i.payload) == null ? void 0 : s.information;
614
- return at(ie(r), E).then((m) => b("popSignResult", l, m, null)).catch((m) => {
615
- const N = (m == null ? void 0 : m.code) ?? "sign_failed";
616
- o && console.warn("[tiun] popSign failed:", m), b("popSignResult", l, null, String(N));
612
+ case z.popSignRequest: {
613
+ const l = (e = i.payload) == null ? void 0 : e.requestId, h = (s = i.payload) == null ? void 0 : s.information;
614
+ return at(ae(r), h).then((v) => E("popSignResult", l, v, null)).catch((v) => {
615
+ const O = (v == null ? void 0 : v.code) ?? "sign_failed";
616
+ o && console.warn("[tiun] popSign failed:", v), E("popSignResult", l, null, String(O));
617
617
  }), !0;
618
618
  }
619
- case M.tokenPersist: {
619
+ case z.tokenPersist: {
620
620
  const l = ((d = i.payload) == null ? void 0 : d.token) ?? null;
621
- return (l ? lt(te(r), l) : le(te(r))).catch(
622
- (E) => o && console.warn("[tiun] token persist failed:", E)
621
+ return (l ? lt(re(r), l) : le(re(r))).catch(
622
+ (h) => o && console.warn("[tiun] token persist failed:", h)
623
623
  ), !0;
624
624
  }
625
- case M.nativeReset:
625
+ case z.nativeReset:
626
626
  return Promise.allSettled([
627
- ct(ie(r)),
628
- le(te(r))
627
+ ct(ae(r)),
628
+ le(re(r))
629
629
  ]), !0;
630
630
  default:
631
631
  return !1;
@@ -636,45 +636,45 @@ const ht = Oe(
636
636
  () => ({
637
637
  login: () => {
638
638
  var i;
639
- j(!0), (i = p.current) == null || i.injectJavaScript(
640
- z("window.tiunHost.login()")
639
+ $(!0), (i = f.current) == null || i.injectJavaScript(
640
+ X("window.tiunHost.login()")
641
641
  );
642
642
  },
643
643
  checkout: (i, e) => {
644
644
  var d;
645
- j(!0), S.current = !0, $.current = !1;
645
+ $(!0), R.current = !0, L.current = !1;
646
646
  const s = e ? [i || null, e] : i ? [i] : [];
647
- (d = p.current) == null || d.injectJavaScript(
648
- z(
647
+ (d = f.current) == null || d.injectJavaScript(
648
+ X(
649
649
  `window.tiunHost.checkout(${s.map((l) => JSON.stringify(l)).join(",")})`
650
650
  )
651
651
  );
652
652
  },
653
653
  logout: () => {
654
654
  var i;
655
- return (i = p.current) == null ? void 0 : i.injectJavaScript(
656
- z("window.tiunHost.logout()")
655
+ return (i = f.current) == null ? void 0 : i.injectJavaScript(
656
+ X("window.tiunHost.logout()")
657
657
  );
658
658
  },
659
659
  getVerificationToken: (i) => {
660
660
  var e;
661
- return (e = p.current) == null ? void 0 : e.injectJavaScript(
662
- z(
661
+ return (e = f.current) == null ? void 0 : e.injectJavaScript(
662
+ X(
663
663
  `window.tiunHost.getVerificationToken(${i ? JSON.stringify(i) : ""})`
664
664
  )
665
665
  );
666
666
  },
667
- productRequest: (i, e, ...s) => b(i, e, ...s),
668
- resolveCheckout: A,
667
+ productRequest: (i, e, ...s) => E(i, e, ...s),
668
+ resolveCheckout: x,
669
669
  reload: () => {
670
670
  var i;
671
- return (i = p.current) == null ? void 0 : i.reload();
671
+ return (i = f.current) == null ? void 0 : i.reload();
672
672
  }
673
673
  }),
674
674
  // eslint-disable-next-line react-hooks/exhaustive-deps
675
675
  []
676
676
  );
677
- const Y = (i) => {
677
+ const G = (i) => {
678
678
  var s, d, l;
679
679
  let e = null;
680
680
  try {
@@ -695,18 +695,18 @@ const ht = Oe(
695
695
  );
696
696
  return;
697
697
  }
698
- if ((e.type === "cryptoCheck" || e.type === "hostBridgeReady") && I(!1), o && console.log("[tiun] <-", e.type, e.payload), !V(e)) {
699
- if (e.type === M.overlayChange) {
700
- const E = !!((l = e.payload) != null && l.overlay);
701
- j(E), E || (S.current = !1);
698
+ if ((e.type === "cryptoCheck" || e.type === "hostBridgeReady") && N(!1), o && console.log("[tiun] <-", e.type, e.payload), !Y(e)) {
699
+ if (e.type === z.overlayChange) {
700
+ const h = !!((l = e.payload) != null && l.overlay);
701
+ $(h), h || (R.current = !1);
702
702
  }
703
703
  a(e);
704
704
  }
705
705
  }
706
- }, F = (i) => {
707
- if (S.current = !1, Fe.OS === "ios") {
706
+ }, W = (i) => {
707
+ if (R.current = !1, Fe.OS === "ios") {
708
708
  Ve(i, r.returnUrl).then((e) => {
709
- e.type === "success" && e.url ? A(Re(e.url)) : e.type === "cancel" && A("cancelled");
709
+ e.type === "success" && e.url ? x(Re(e.url)) : e.type === "cancel" && x("cancelled");
710
710
  }).catch((e) => o && console.warn("[tiun] openAuth error:", e));
711
711
  return;
712
712
  }
@@ -716,11 +716,11 @@ const ht = Oe(
716
716
  enableDefaultShare: !1,
717
717
  forceCloseOnRedirection: !1
718
718
  }).then((e) => {
719
- e.type === "cancel" && A("cancelled");
719
+ e.type === "cancel" && x("cancelled");
720
720
  }).catch(
721
721
  (e) => o && console.warn("[tiun] in-app browser open error:", e)
722
722
  );
723
- }, R = (i) => {
723
+ }, k = (i) => {
724
724
  be(i, {
725
725
  modalPresentationStyle: "fullScreen",
726
726
  modalEnabled: !0,
@@ -729,59 +729,59 @@ const ht = Oe(
729
729
  }).catch(
730
730
  (e) => o && console.warn("[tiun] in-app browser open failed:", e)
731
731
  );
732
- }, G = (i) => {
732
+ }, H = (i) => {
733
733
  var s;
734
734
  const e = (s = i.nativeEvent) == null ? void 0 : s.targetUrl;
735
- e && (S.current ? F(e) : R(e));
736
- }, W = (i) => {
735
+ e && (R.current ? W(e) : k(e));
736
+ }, q = (i) => {
737
737
  const e = i.url;
738
- return e.startsWith(fe(r)) || e.startsWith("about:") || e.startsWith("data:") || e === "about:blank" ? !0 : e.startsWith("http://") || e.startsWith("https://") ? (S.current && i.isTopFrame !== !1 ? F(e) : R(e), !1) : !0;
739
- }, { width: H, height: B } = Le();
740
- return /* @__PURE__ */ v.jsxs(
741
- ae,
738
+ return e.startsWith(fe(r)) || e.startsWith("about:") || e.startsWith("data:") || e === "about:blank" ? !0 : e.startsWith("http://") || e.startsWith("https://") ? (R.current && i.isTopFrame !== !1 ? W(e) : k(e), !1) : !0;
739
+ }, { width: B, height: K } = Le();
740
+ return /* @__PURE__ */ S.jsxs(
741
+ ce,
742
742
  {
743
- pointerEvents: U ? "auto" : "none",
743
+ pointerEvents: j ? "auto" : "none",
744
744
  style: [
745
- re.container,
746
- { width: H, height: B },
747
- U ? re.visible : re.hidden
745
+ ne.container,
746
+ { width: B, height: K },
747
+ j ? ne.visible : ne.hidden
748
748
  ],
749
749
  children: [
750
- /* @__PURE__ */ v.jsx(
750
+ /* @__PURE__ */ S.jsx(
751
751
  Tt,
752
752
  {
753
- ref: p,
753
+ ref: f,
754
754
  source: { uri: rt(r) },
755
755
  originWhitelist: ["*"],
756
- onMessage: Y,
757
- onShouldStartLoadWithRequest: W,
758
- onOpenWindow: G,
759
- injectedJavaScriptBeforeContentLoaded: L,
756
+ onMessage: G,
757
+ onShouldStartLoadWithRequest: q,
758
+ onOpenWindow: H,
759
+ injectedJavaScriptBeforeContentLoaded: F,
760
760
  javaScriptEnabled: !0,
761
761
  domStorageEnabled: !0,
762
- style: re.webview,
763
- containerStyle: re.webview,
762
+ style: ne.webview,
763
+ containerStyle: ne.webview,
764
764
  onError: (i) => {
765
- o && console.warn("[tiun] webview load error:", i.nativeEvent), I(!0);
765
+ o && console.warn("[tiun] webview load error:", i.nativeEvent), N(!0);
766
766
  },
767
767
  onHttpError: (i) => {
768
- o && console.warn("[tiun] webview http error:", i.nativeEvent), I(!0);
768
+ o && console.warn("[tiun] webview http error:", i.nativeEvent), N(!0);
769
769
  }
770
770
  }
771
771
  ),
772
- O && U ? /* @__PURE__ */ v.jsx(
772
+ A && j ? /* @__PURE__ */ S.jsx(
773
773
  ft,
774
774
  {
775
775
  language: r.language,
776
- dark: y === "dark",
777
- onRetry: q
776
+ dark: b === "dark",
777
+ onRetry: D
778
778
  }
779
779
  ) : null
780
780
  ]
781
781
  }
782
782
  );
783
783
  }
784
- ), re = ce.create({
784
+ ), ne = se.create({
785
785
  container: {
786
786
  position: "absolute",
787
787
  top: 0,
@@ -817,178 +817,182 @@ class Et {
817
817
  }
818
818
  }
819
819
  }
820
- const bt = 1e4, we = () => Promise.reject({ code: "invalid_argument", message: "productId is required" }), ge = me(null), ke = me(null);
820
+ const bt = 1e4, we = () => Promise.reject({ code: "invalid_argument", message: "productId is required" }), ke = me(null), ge = me(null);
821
821
  function Rt({ config: n, children: r }) {
822
- const a = C(null), u = C(!1), o = C([]), h = C(/* @__PURE__ */ new Map()), y = C(/* @__PURE__ */ new Map()), p = C(new Et()).current, [U, j] = X(!1), [O, I] = X(null), [S, $] = X(!1), [q, L] = X(null), b = P((e) => {
822
+ const a = I(null), u = I(!1), o = I([]), T = I(/* @__PURE__ */ new Map()), b = I(/* @__PURE__ */ new Map()), f = I(new Et()).current, [j, $] = Q(!1), [A, N] = Q(null), [R, L] = Q(!1), [D, F] = Q(null), E = C((e) => {
823
823
  u.current ? e() : o.current.push(e);
824
- }, []), D = P(
824
+ }, []), V = C(
825
825
  (e) => {
826
- var s, d, l, E, m, N, Q, t, c, T, w, k, g, K, J;
826
+ var s, d, l, h, v, O, Z, t, c, p, _, P, g, J, M, y;
827
827
  switch (e.type) {
828
828
  case "cryptoCheck":
829
- L(!!((s = e.payload) != null && s.subtle && ((d = e.payload) != null && d.secureContext)));
829
+ F(!!((s = e.payload) != null && s.subtle && ((d = e.payload) != null && d.secureContext)));
830
830
  break;
831
831
  case "TIUN_SNIPPET_INITIALIZED": {
832
- u.current = !0, $(!0), p.emit("ready", void 0);
833
- const f = o.current;
834
- o.current = [], f.forEach((_) => _());
832
+ u.current = !0, L(!0), f.emit("ready", void 0);
833
+ const m = o.current;
834
+ o.current = [], m.forEach((w) => w());
835
835
  break;
836
836
  }
837
837
  case "TIUN_USER_CHANGE": {
838
- const f = !!((l = e.payload) != null && l.isAuthenticated), _ = ((E = e.payload) == null ? void 0 : E.user) ?? null;
839
- j(f), I(_), p.emit("userChange", { isAuthenticated: f, user: _ }), ((m = e.payload) == null ? void 0 : m.userEvent) === "login" && p.emit("login", { user: _ }), ((N = e.payload) == null ? void 0 : N.userEvent) === "logout" && p.emit("logout", void 0);
838
+ const m = !!((l = e.payload) != null && l.isAuthenticated), w = ((h = e.payload) == null ? void 0 : h.user) ?? null;
839
+ $(m), N(w), f.emit("userChange", {
840
+ event: ((v = e.payload) == null ? void 0 : v.userEvent) ?? "update",
841
+ isAuthenticated: m,
842
+ user: w
843
+ }), ((O = e.payload) == null ? void 0 : O.userEvent) === "login" && f.emit("login", { user: w }), ((Z = e.payload) == null ? void 0 : Z.userEvent) === "logout" && f.emit("logout", void 0);
840
844
  break;
841
845
  }
842
846
  case "TIUN_VERIFICATION_TOKEN": {
843
- const f = ((Q = e.payload) == null ? void 0 : Q.token) ?? null, _ = (t = e.payload) == null ? void 0 : t.requestId;
844
- _ && h.current.has(_) && (h.current.get(_)(f), h.current.delete(_));
847
+ const m = ((t = e.payload) == null ? void 0 : t.token) ?? null, w = (c = e.payload) == null ? void 0 : c.requestId;
848
+ w && T.current.has(w) && (T.current.get(w)(m), T.current.delete(w));
845
849
  break;
846
850
  }
847
851
  case "TIUN_PRODUCT_RESULT": {
848
- const f = (c = e.payload) == null ? void 0 : c.requestId, _ = f ? y.current.get(f) : void 0;
849
- if (!_)
852
+ const m = (p = e.payload) == null ? void 0 : p.requestId, w = m ? b.current.get(m) : void 0;
853
+ if (!w)
850
854
  break;
851
- clearTimeout(_.timer), y.current.delete(f), (T = e.payload) != null && T.error ? _.reject(e.payload.error) : _.resolve((w = e.payload) == null ? void 0 : w.result);
855
+ clearTimeout(w.timer), b.current.delete(m), (_ = e.payload) != null && _.error ? w.reject(e.payload.error) : w.resolve((P = e.payload) == null ? void 0 : P.result);
852
856
  break;
853
857
  }
854
858
  case "TIUN_SHOW_PAYWALL":
855
- p.emit("paywallShow", { isConnected: !!((k = e.payload) != null && k.isConnected) });
859
+ f.emit("paywallShow", { isConnected: !!((g = e.payload) != null && g.isConnected) });
856
860
  break;
857
861
  case "TIUN_HIDE_PAYWALL":
858
- p.emit("paywallHide", {
859
- sessionId: ((g = e.payload) == null ? void 0 : g.sessionId) ?? "",
860
- isConnected: ((K = e.payload) == null ? void 0 : K.isConnected) ?? !0
862
+ f.emit("paywallHide", {
863
+ sessionId: ((J = e.payload) == null ? void 0 : J.sessionId) ?? "",
864
+ isConnected: ((M = e.payload) == null ? void 0 : M.isConnected) ?? !0
861
865
  });
862
866
  break;
863
867
  case "TIUN_ERROR":
864
- p.emit("error", ((J = e.payload) == null ? void 0 : J.error) ?? e.payload ?? {});
868
+ f.emit("error", ((y = e.payload) == null ? void 0 : y.error) ?? e.payload ?? {});
865
869
  break;
866
870
  }
867
871
  },
868
- [p]
872
+ [f]
869
873
  );
870
- ne(() => {
874
+ oe(() => {
871
875
  const e = (d) => {
872
876
  if (!d || !nt(n, d))
873
877
  return;
874
878
  const l = Re(d);
875
- b(() => {
876
- var E;
877
- return (E = a.current) == null ? void 0 : E.resolveCheckout(l);
879
+ E(() => {
880
+ var h;
881
+ return (h = a.current) == null ? void 0 : h.resolveCheckout(l);
878
882
  });
879
883
  }, s = Ee.addEventListener("url", ({ url: d }) => e(d));
880
884
  return Ee.getInitialURL().then(e).catch(() => {
881
885
  }), () => s.remove();
882
- }, [n, b]);
883
- const A = P(() => b(() => {
886
+ }, [n, E]);
887
+ const x = C(() => E(() => {
884
888
  var e;
885
889
  return (e = a.current) == null ? void 0 : e.login();
886
- }), [b]), V = P(() => b(() => {
890
+ }), [E]), Y = C(() => E(() => {
887
891
  var e;
888
892
  return (e = a.current) == null ? void 0 : e.logout();
889
- }), [b]), Y = P(
890
- (e) => b(() => {
893
+ }), [E]), G = C(
894
+ (e) => E(() => {
891
895
  var s;
892
896
  return (s = a.current) == null ? void 0 : s.checkout(e == null ? void 0 : e.productId, e == null ? void 0 : e.referenceId);
893
897
  }),
894
- [b]
895
- ), F = P(
898
+ [E]
899
+ ), W = C(
896
900
  () => new Promise((e) => {
897
901
  const s = `vt_${Math.random().toString(36).slice(2)}_${Date.now()}`;
898
902
  let d = !1;
899
- const l = (E) => {
900
- d || (d = !0, h.current.delete(s), e(E));
903
+ const l = (h) => {
904
+ d || (d = !0, T.current.delete(s), e(h));
901
905
  };
902
- h.current.set(s, l), b(() => {
903
- var E;
904
- return (E = a.current) == null ? void 0 : E.getVerificationToken(s);
906
+ T.current.set(s, l), E(() => {
907
+ var h;
908
+ return (h = a.current) == null ? void 0 : h.getVerificationToken(s);
905
909
  }), setTimeout(() => l(null), 5e3);
906
910
  }),
907
- [b]
908
- ), R = P(
911
+ [E]
912
+ ), k = C(
909
913
  (e, ...s) => new Promise((d, l) => {
910
- const E = `pr_${Math.random().toString(36).slice(2)}_${Date.now()}`, m = {
914
+ const h = `pr_${Math.random().toString(36).slice(2)}_${Date.now()}`, v = {
911
915
  resolve: d,
912
916
  reject: l
913
917
  };
914
- y.current.set(E, m), b(() => {
915
- var N;
916
- y.current.get(E) === m && (m.timer = setTimeout(() => {
917
- y.current.delete(E), l({ code: "timeout", message: `${e} timed out` });
918
- }, bt), (N = a.current) == null || N.productRequest(e, E, ...s));
918
+ b.current.set(h, v), E(() => {
919
+ var O;
920
+ b.current.get(h) === v && (v.timer = setTimeout(() => {
921
+ b.current.delete(h), l({ code: "timeout", message: `${e} timed out` });
922
+ }, bt), (O = a.current) == null || O.productRequest(e, h, ...s));
919
923
  });
920
924
  }),
921
- [b]
925
+ [E]
922
926
  );
923
- ne(() => {
924
- const e = y.current;
927
+ oe(() => {
928
+ const e = b.current;
925
929
  return () => {
926
930
  e.forEach(({ reject: s, timer: d }) => {
927
931
  clearTimeout(d), s({ code: "destroyed", message: "TiunProvider was unmounted" });
928
932
  }), e.clear();
929
933
  };
930
934
  }, []);
931
- const G = P(
932
- () => R("listProducts"),
933
- [R]
934
- ), W = P(
935
- (e) => e ? R("getProduct", e) : we(),
936
- [R]
937
- ), H = P(
938
- () => R("listProductAccess"),
939
- [R]
940
- ), B = P(
941
- (e, s) => e ? R(
935
+ const H = C(
936
+ () => k("listProducts"),
937
+ [k]
938
+ ), q = C(
939
+ (e) => e ? k("getProduct", e) : we(),
940
+ [k]
941
+ ), B = C(
942
+ () => k("listProductAccess"),
943
+ [k]
944
+ ), K = C(
945
+ (e, s) => e ? k(
942
946
  "checkProductAccess",
943
947
  e,
944
948
  // Empty string means "no reference" — don't send a value the BE rejects.
945
949
  (s == null ? void 0 : s.referenceId) || void 0
946
950
  ) : we(),
947
- [R]
951
+ [k]
948
952
  ), i = xe(
949
953
  () => ({
950
- isAuthenticated: U,
951
- user: O,
952
- ready: S,
953
- cryptoOk: q,
954
- login: A,
955
- logout: V,
956
- checkout: Y,
957
- getUserVerificationToken: F,
958
- listProducts: G,
959
- getProduct: W,
960
- listProductAccess: H,
961
- checkProductAccess: B
954
+ isAuthenticated: j,
955
+ user: A,
956
+ ready: R,
957
+ cryptoOk: D,
958
+ login: x,
959
+ logout: Y,
960
+ checkout: G,
961
+ getUserVerificationToken: W,
962
+ listProducts: H,
963
+ getProduct: q,
964
+ listProductAccess: B,
965
+ checkProductAccess: K
962
966
  }),
963
967
  [
964
- U,
965
- O,
966
- S,
967
- q,
968
+ j,
968
969
  A,
969
- V,
970
+ R,
971
+ D,
972
+ x,
970
973
  Y,
971
- F,
972
974
  G,
973
975
  W,
974
976
  H,
975
- B
977
+ q,
978
+ B,
979
+ K
976
980
  ]
977
981
  );
978
- return /* @__PURE__ */ v.jsx(ge.Provider, { value: i, children: /* @__PURE__ */ v.jsxs(ke.Provider, { value: p, children: [
982
+ return /* @__PURE__ */ S.jsx(ke.Provider, { value: i, children: /* @__PURE__ */ S.jsxs(ge.Provider, { value: f, children: [
979
983
  r,
980
- /* @__PURE__ */ v.jsx(ht, { ref: a, config: n, onEvent: D })
984
+ /* @__PURE__ */ S.jsx(ht, { ref: a, config: n, onEvent: V })
981
985
  ] }) });
982
986
  }
983
- function gt() {
984
- const n = ve(ge);
987
+ function kt() {
988
+ const n = ve(ke);
985
989
  if (!n)
986
990
  throw new Error("useTiun must be used within a <TiunProvider>");
987
991
  return n;
988
992
  }
989
- function kt(n, r) {
990
- const a = ve(ke), u = C(r);
991
- u.current = r, ne(() => {
993
+ function gt(n, r) {
994
+ const a = ve(ge), u = I(r);
995
+ u.current = r, oe(() => {
992
996
  if (!a)
993
997
  throw new Error("useTiunEvent must be used within a <TiunProvider>");
994
998
  return a.on(n, (o) => u.current(o));
@@ -996,6 +1000,6 @@ function kt(n, r) {
996
1000
  }
997
1001
  export {
998
1002
  Rt as TiunProvider,
999
- gt as useTiun,
1000
- kt as useTiunEvent
1003
+ kt as useTiun,
1004
+ gt as useTiunEvent
1001
1005
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiun/react-native-sdk",
3
- "version": "0.5.0-staging.0",
3
+ "version": "0.5.0",
4
4
  "description": "tiun SDK for React Native — payments and subscriptions",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",