@tiun/react-native-sdk 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +22 -0
- package/dist/index.mjs +901 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tiun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @tiun/react-native-sdk
|
|
2
|
+
|
|
3
|
+
tiun SDK for React Native. Renders the tiun web snippet inside a `WebView` and
|
|
4
|
+
bridges its login/checkout overlays to native, with device-bound auth backed by
|
|
5
|
+
the native keystore/keychain.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tiun/react-native-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { TiunProvider, useTiun, useTiunEvent } from '@tiun/react-native-sdk';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<TiunProvider
|
|
21
|
+
config={{
|
|
22
|
+
snippetId: 'your-snippet-id',
|
|
23
|
+
returnUrl: 'myapp://tiun/return'
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<Screen />
|
|
27
|
+
</TiunProvider>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The app must register the `returnUrl` deep-link scheme in its native config; the
|
|
33
|
+
SDK only consumes the URL.
|
|
34
|
+
|
|
35
|
+
## Peer dependencies
|
|
36
|
+
|
|
37
|
+
`react`, `react-native`, `react-native-webview`, `react-native-secure-sign`,
|
|
38
|
+
`react-native-keychain`, `react-native-inappbrowser-nitro`, `react-native-nitro-modules`
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export declare interface CheckoutOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Specific product ID to checkout (optional, for future use)
|
|
7
|
+
*/
|
|
8
|
+
productId?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare interface PaywallHideEvent {
|
|
12
|
+
/**
|
|
13
|
+
* Active session ID
|
|
14
|
+
*/
|
|
15
|
+
sessionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether user is connected
|
|
18
|
+
*/
|
|
19
|
+
isConnected: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare interface PaywallShowEvent {
|
|
23
|
+
/**
|
|
24
|
+
* Whether user has connected a payment method
|
|
25
|
+
*/
|
|
26
|
+
isConnected: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare type TiunConfig = {
|
|
30
|
+
/** tiun snippet id (goes in the asset route). */
|
|
31
|
+
snippetId: string;
|
|
32
|
+
/**
|
|
33
|
+
* Snippet-service origin (no trailing slash). Defaults to production.
|
|
34
|
+
* Override for staging/sandbox, e.g. `https://api-staging.tiun.live`.
|
|
35
|
+
*/
|
|
36
|
+
host?: string;
|
|
37
|
+
/** Snippet UI language; defaults to 'en'. */
|
|
38
|
+
language?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The app's deep link the in-app browser returns to after payment, e.g.
|
|
41
|
+
* `myapp://tiun/return`. The app must register this scheme in its native
|
|
42
|
+
* config (an app concern); the SDK only consumes the URL. Required for checkout.
|
|
43
|
+
*/
|
|
44
|
+
returnUrl: string;
|
|
45
|
+
/** Verbose bridge logging. */
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Reactive state + actions returned by `useTiun()`. */
|
|
50
|
+
export declare type TiunContextValue = {
|
|
51
|
+
isAuthenticated: boolean;
|
|
52
|
+
user: TiunUser | null;
|
|
53
|
+
/** Snippet has initialized inside the WebView and is ready for commands. */
|
|
54
|
+
ready: boolean;
|
|
55
|
+
/** GO/NO-GO crypto gate: crypto.subtle usable in the WebView (null until reported). */
|
|
56
|
+
cryptoOk: boolean | null;
|
|
57
|
+
login: () => void;
|
|
58
|
+
logout: () => void;
|
|
59
|
+
checkout: (options?: CheckoutOptions) => void;
|
|
60
|
+
getUserVerificationToken: () => Promise<string | null>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Events surfaced via `useTiunEvent` (names mirror the web SDK). */
|
|
64
|
+
export declare type TiunEventName = 'ready' | 'userChange' | 'login' | 'logout' | 'paywallShow' | 'paywallHide' | 'error';
|
|
65
|
+
|
|
66
|
+
export declare type TiunEventPayload = {
|
|
67
|
+
ready: void;
|
|
68
|
+
userChange: {
|
|
69
|
+
isAuthenticated: boolean;
|
|
70
|
+
user: TiunUser | null;
|
|
71
|
+
};
|
|
72
|
+
login: {
|
|
73
|
+
user: TiunUser | null;
|
|
74
|
+
};
|
|
75
|
+
logout: void;
|
|
76
|
+
paywallShow: PaywallShowEvent;
|
|
77
|
+
paywallHide: PaywallHideEvent;
|
|
78
|
+
error: {
|
|
79
|
+
code?: string;
|
|
80
|
+
message?: string;
|
|
81
|
+
details?: unknown;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export declare function TiunProvider({ config, children }: {
|
|
86
|
+
config: TiunConfig;
|
|
87
|
+
children: ReactNode;
|
|
88
|
+
}): JSX.Element;
|
|
89
|
+
|
|
90
|
+
/** The authenticated user (alias of the web SDK's `UserInfo`). */
|
|
91
|
+
export declare type TiunUser = UserInfo;
|
|
92
|
+
|
|
93
|
+
declare interface UserInfo {
|
|
94
|
+
userId: string;
|
|
95
|
+
email: string;
|
|
96
|
+
productAccess: string[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Reactive tiun state + actions. Must be used within <TiunProvider>. */
|
|
100
|
+
export declare function useTiun(): TiunContextValue;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to a tiun event (mirrors the web SDK's `on`). The handler is kept in
|
|
104
|
+
* a ref so re-renders don't churn the subscription; it auto-unsubscribes on
|
|
105
|
+
* unmount. Must be used within <TiunProvider>.
|
|
106
|
+
*/
|
|
107
|
+
export declare function useTiunEvent<T extends TiunEventName>(event: T, handler: (payload: TiunEventPayload[T]) => void): void;
|
|
108
|
+
|
|
109
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";var we=Object.defineProperty;var ve=(t,r,i)=>r in t?we(t,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[r]=i;var fe=(t,r,i)=>(ve(t,typeof r!="symbol"?r+"":r,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),b=require("react-native"),_e=require("react-native-webview"),M=require("react-native-inappbrowser-nitro"),te=require("react-native-secure-sign"),Se=require("react-native-keychain");function me(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const u=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(r,i,u.get?u:{enumerable:!0,get:()=>t[i]})}}return r.default=t,Object.freeze(r)}const ne=me(Se);var se={exports:{}},X={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var pe;function Re(){if(pe)return X;pe=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function i(u,c,l){var T=null;if(l!==void 0&&(T=""+l),c.key!==void 0&&(T=""+c.key),"key"in c){l={};for(var m in c)m!=="key"&&(l[m]=c[m])}else l=c;return c=l.ref,{$$typeof:t,type:u,key:T,ref:c!==void 0?c:null,props:l}}return X.Fragment=r,X.jsx=i,X.jsxs=i,X}var Q={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var he;function ge(){return he||(he=1,process.env.NODE_ENV!=="production"&&function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===f?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case E:return"Fragment";case V:return"Profiler";case K:return"StrictMode";case G:return"Suspense";case s:return"SuspenseList";case n:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case g:return"Portal";case L:return(e.displayName||"Context")+".Provider";case F:return(e._context.displayName||"Context")+".Consumer";case q:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case v:return a=e.displayName||null,a!==null?a:t(e.type)||"Memo";case o:a=e._payload,e=e._init;try{return t(e(a))}catch{}}return null}function r(e){return""+e}function i(e){try{r(e);var a=!1}catch{a=!0}if(a){a=console;var p=a.error,y=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return p.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",y),r(e)}}function u(e){if(e===E)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===o)return"<...>";try{var a=t(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function c(){var e=_.A;return e===null?null:e.getOwner()}function l(){return Error("react-stack-top-frame")}function T(e){if(h.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function m(e,a){function p(){W||(W=!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)",a))}p.isReactWarning=!0,Object.defineProperty(e,"key",{get:p,configurable:!0})}function U(){var e=t(this.type);return B[e]||(B[e]=!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.")),e=this.props.ref,e!==void 0?e:null}function N(e,a,p,y,j,C,oe,ie){return p=C.ref,e={$$typeof:$,type:e,key:a,props:C,_owner:j},(p!==void 0?p:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:U}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:oe}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ie}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function O(e,a,p,y,j,C,oe,ie){var w=a.children;if(w!==void 0)if(y)if(k(w)){for(y=0;y<w.length;y++)I(w[y]);Object.freeze&&Object.freeze(w)}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 I(w);if(h.call(a,"key")){w=t(e);var Y=Object.keys(a).filter(function(ye){return ye!=="key"});y=0<Y.length?"{key: someKey, "+Y.join(": ..., ")+": ...}":"{key: someKey}",P[w+y]||(Y=0<Y.length?"{"+Y.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
+
let props = %s;
|
|
19
|
+
<%s {...props} />
|
|
20
|
+
React keys must be passed directly to JSX without using spread:
|
|
21
|
+
let props = %s;
|
|
22
|
+
<%s key={someKey} {...props} />`,y,w,Y,w),P[w+y]=!0)}if(w=null,p!==void 0&&(i(p),w=""+p),T(a)&&(i(a.key),w=""+a.key),"key"in a){p={};for(var ae in a)ae!=="key"&&(p[ae]=a[ae])}else p=a;return w&&m(p,typeof e=="function"?e.displayName||e.name||"Unknown":e),N(e,w,C,j,c(),p,oe,ie)}function I(e){typeof e=="object"&&e!==null&&e.$$typeof===$&&e._store&&(e._store.validated=1)}var A=d,$=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),K=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),F=Symbol.for("react.consumer"),L=Symbol.for("react.context"),q=Symbol.for("react.forward_ref"),G=Symbol.for("react.suspense"),s=Symbol.for("react.suspense_list"),v=Symbol.for("react.memo"),o=Symbol.for("react.lazy"),n=Symbol.for("react.activity"),f=Symbol.for("react.client.reference"),_=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,h=Object.prototype.hasOwnProperty,k=Array.isArray,R=console.createTask?console.createTask:function(){return null};A={"react-stack-bottom-frame":function(e){return e()}};var W,B={},J=A["react-stack-bottom-frame"].bind(A,l)(),z=R(u(l)),P={};Q.Fragment=E,Q.jsx=function(e,a,p,y,j){var C=1e4>_.recentlyCreatedOwnerStacks++;return O(e,a,p,!1,y,j,C?Error("react-stack-top-frame"):J,C?R(u(e)):z)},Q.jsxs=function(e,a,p,y,j){var C=1e4>_.recentlyCreatedOwnerStacks++;return O(e,a,p,!0,y,j,C?Error("react-stack-top-frame"):J,C?R(u(e)):z)}}()),Q}process.env.NODE_ENV==="production"?se.exports=Re():se.exports=ge();var S=se.exports;const ke={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"},Ne={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"},Oe={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"},Ce={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(t,r="informal"){switch((t??"en").trim().toLowerCase()){case"de":return r==="formal"?Ce:Oe;case"fr":return Ne;default:return ke}}const D={start:"TIUN_START",checkout:"TIUN_CHECKOUT",updateContent:"TIUN_UPDATE_CONTENT",login:"TIUN_LOGIN",logout:"TIUN_LOGOUT",getVerificationToken:"TIUN_GET_VERIFICATION_TOKEN",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"},Pe="__TIUN_NATIVE_CRYPTO__",xe="https://api.tiun.live";function ue(t){return(t.host??xe).replace(/\/$/,"")}function re(t){return`app.tiun.pop.${t.snippetId||"default"}`}function Z(t){return`app.tiun.token.${t.snippetId||"default"}`}function Ae(t){return`${`${ue(t)}/live_api/v2/snippets/${encodeURIComponent(t.snippetId)}/webview_return`}?to=${encodeURIComponent(t.returnUrl)}`}function je(t){const r={language:t.language??"en"},i=Object.entries(r).map(([c,l])=>`${encodeURIComponent(c)}=${encodeURIComponent(l)}`).join("&"),u=`${ue(t)}/live_api/v2/snippets/${encodeURIComponent(t.snippetId)}/webview_host`;return i?`${u}?${i}`:u}function Te(t){const r=t.indexOf("?");if(!(r<0))for(const i of t.slice(r+1).split("&")){const u=i.indexOf("=");if((u<0?i:i.slice(0,u))==="status"){const l=u<0?"":i.slice(u+1);return l?decodeURIComponent(l):void 0}}}function Ue(t,r){const i=t.returnUrl.split("?")[0];return r.startsWith(i)}const le="1005";function de(t){return t==null?void 0:t.code}async function $e(t){try{return await te.getPublicKey(t)}catch(r){if(de(r)===le)return te.generate(t,{requireUserAuthentication:!1});throw r}}async function Fe(t){try{return await te.getPublicKey(t)}catch(r){if(de(r)===le)return null;throw r}}function Le(t,r){return te.sign(t,r)}async function We(t){try{await te.removeKey(t)}catch(r){if(de(r)!==le)throw r}}const Ve="tiun_auth_token";async function qe(t){const r=await ne.getGenericPassword({service:t});return r?r.password:null}async function Ye(t,r){await ne.setGenericPassword(Ve,r,{service:t,accessible:ne.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY})}async function ce(t){await ne.resetGenericPassword({service:t})}function De(t){const r=Ie(t);return{title:r.connectionErrorTitle,text:r.connectionErrorText,cta:r.connectionErrorCta}}function He({language:t,onRetry:r}){const i=De(t);return S.jsxs(b.View,{style:x.container,children:[S.jsxs(b.View,{style:x.content,children:[S.jsx(b.Text,{style:x.title,children:i.title}),S.jsx(b.View,{style:x.iconBadge,children:S.jsx(b.Text,{style:x.iconGlyph,children:"!"})}),S.jsx(b.Text,{style:x.text,children:i.text})]}),S.jsx(b.Pressable,{accessibilityRole:"button",onPress:r,style:({pressed:u})=>[x.button,u&&x.buttonPressed],children:S.jsx(b.Text,{style:x.buttonText,children:i.cta})})]})}const x=b.StyleSheet.create({container:{...b.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"}}),Ke=_e.WebView;function H(t){return`try{window.tiunHost&&${t};}catch(e){}; true;`}const Ge=d.forwardRef(function({config:r,onEvent:i},u){const c=!!r.debug,l=d.useRef(null),[T,m]=d.useState(!1),[U,N]=d.useState(!1),O=d.useRef(!1),I=d.useRef(!1),A=()=>{var o;N(!1),(o=l.current)==null||o.reload()};d.useEffect(()=>{if(!U)return;const o=b.AppState.addEventListener("change",n=>{var f;n==="active"&&(N(!1),(f=l.current)==null||f.reload())});return()=>o.remove()},[U]);const $=`window.${Pe} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(Ae(r))} });true;`,g=(o,...n)=>{var f;return(f=l.current)==null?void 0:f.injectJavaScript(H(`window.tiunHost.${o}(${n.map(_=>JSON.stringify(_)??"null").join(",")})`))},E=o=>{var n;I.current||(I.current=!0,M.close().catch(()=>{}),M.closeAuth().catch(()=>{}),m(!0),(n=l.current)==null||n.injectJavaScript(H(`window.tiunHost.resolveCheckout(${o?JSON.stringify(o):""})`)))},K=o=>{var n,f,_;switch(o.type){case D.popPubKeyRequest:return $e(re(r)).then(h=>g("popPubKey",h)).catch(h=>{c&&console.warn("[tiun] ensurePopKey failed:",h),g("popPubKey",null)}),!0;case D.tokenGet:return(async()=>{try{const h=await qe(Z(r));if(h&&!await Fe(re(r))){await ce(Z(r)),g("restoreToken",null);return}g("restoreToken",h)}catch{g("restoreToken",null)}})(),!0;case D.popSignRequest:{const h=(n=o.payload)==null?void 0:n.requestId,k=(f=o.payload)==null?void 0:f.information;return Le(re(r),k).then(R=>g("popSignResult",h,R,null)).catch(R=>{const W=(R==null?void 0:R.code)??"sign_failed";c&&console.warn("[tiun] popSign failed:",R),g("popSignResult",h,null,String(W))}),!0}case D.tokenPersist:{const h=((_=o.payload)==null?void 0:_.token)??null;return(h?Ye(Z(r),h):ce(Z(r))).catch(k=>c&&console.warn("[tiun] token persist failed:",k)),!0}case D.nativeReset:return Promise.allSettled([We(re(r)),ce(Z(r))]),!0;default:return!1}};d.useImperativeHandle(u,()=>({login:()=>{var o;m(!0),(o=l.current)==null||o.injectJavaScript(H("window.tiunHost.login()"))},checkout:o=>{var n;m(!0),O.current=!0,I.current=!1,(n=l.current)==null||n.injectJavaScript(H(`window.tiunHost.checkout(${o?JSON.stringify(o):""})`))},logout:()=>{var o;return(o=l.current)==null?void 0:o.injectJavaScript(H("window.tiunHost.logout()"))},getVerificationToken:o=>{var n;return(n=l.current)==null?void 0:n.injectJavaScript(H(`window.tiunHost.getVerificationToken(${o?JSON.stringify(o):""})`))},resolveCheckout:E,reload:()=>{var o;return(o=l.current)==null?void 0:o.reload()}}),[]);const V=o=>{var f,_,h;let n=null;try{n=JSON.parse(o.nativeEvent.data)}catch{c&&console.warn("[tiun] non-JSON bridge message:",o.nativeEvent.data);return}if(!(!n||typeof n.type!="string")){if(n.type==="console"){c&&console.log("[tiun webview]",(f=n.payload)==null?void 0:f.level,(_=n.payload)==null?void 0:_.message);return}if((n.type==="cryptoCheck"||n.type==="hostBridgeReady")&&N(!1),c&&console.log("[tiun] <-",n.type,n.payload),!K(n)){if(n.type===D.overlayChange){const k=!!((h=n.payload)!=null&&h.overlay);m(k),k||(O.current=!1)}i(n)}}},F=o=>{if(O.current=!1,b.Platform.OS==="ios"){M.openAuth(o,r.returnUrl).then(n=>{n.type==="success"&&n.url?E(Te(n.url)):n.type==="cancel"&&E("cancelled")}).catch(n=>c&&console.warn("[tiun] openAuth error:",n));return}M.open(o,{showTitle:!1,enableUrlBarHiding:!1,enableDefaultShare:!1,forceCloseOnRedirection:!1}).then(n=>{n.type==="cancel"&&E("cancelled")}).catch(n=>c&&console.warn("[tiun] in-app browser open error:",n))},L=o=>{M.open(o,{modalPresentationStyle:"fullScreen",modalEnabled:!0,animated:!0,enableBarCollapsing:!0}).catch(n=>c&&console.warn("[tiun] in-app browser open failed:",n))},q=o=>{var f;const n=(f=o.nativeEvent)==null?void 0:f.targetUrl;n&&(O.current?F(n):L(n))},G=o=>{const n=o.url;return n.startsWith(ue(r))||n.startsWith("about:")||n.startsWith("data:")||n==="about:blank"?!0:n.startsWith("http://")||n.startsWith("https://")?(O.current&&o.isTopFrame!==!1?F(n):L(n),!1):!0},{width:s,height:v}=b.useWindowDimensions();return S.jsxs(b.View,{pointerEvents:T?"auto":"none",style:[ee.container,{width:s,height:v},T?ee.visible:ee.hidden],children:[S.jsx(Ke,{ref:l,source:{uri:je(r)},originWhitelist:["*"],onMessage:V,onShouldStartLoadWithRequest:G,onOpenWindow:q,injectedJavaScriptBeforeContentLoaded:$,javaScriptEnabled:!0,domStorageEnabled:!0,style:ee.webview,containerStyle:ee.webview,onError:o=>{c&&console.warn("[tiun] webview load error:",o.nativeEvent),N(!0)},onHttpError:o=>{c&&console.warn("[tiun] webview http error:",o.nativeEvent),N(!0)}}),U&&T?S.jsx(He,{language:r.language,onRetry:A}):null]})}),ee=b.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 Be{constructor(){fe(this,"listeners",new Map)}on(r,i){let u=this.listeners.get(r);return u||(u=new Set,this.listeners.set(r,u)),u.add(i),()=>{var c;(c=this.listeners.get(r))==null||c.delete(i)}}emit(r,i){const u=this.listeners.get(r);if(u)for(const c of u)try{c(i)}catch{}}}const Ee=d.createContext(null),be=d.createContext(null);function Je({config:t,children:r}){const i=d.useRef(null),u=d.useRef(!1),c=d.useRef([]),l=d.useRef(new Map),T=d.useRef(new Be).current,[m,U]=d.useState(!1),[N,O]=d.useState(null),[I,A]=d.useState(!1),[$,g]=d.useState(null),E=d.useCallback(s=>{u.current?s():c.current.push(s)},[]),K=d.useCallback(s=>{var v,o,n,f,_,h,k,R,W,B,J,z;switch(s.type){case"cryptoCheck":g(!!((v=s.payload)!=null&&v.subtle&&((o=s.payload)!=null&&o.secureContext)));break;case"TIUN_SNIPPET_INITIALIZED":{u.current=!0,A(!0),T.emit("ready",void 0);const P=c.current;c.current=[],P.forEach(e=>e());break}case"TIUN_USER_CHANGE":{const P=!!((n=s.payload)!=null&&n.isAuthenticated),e=((f=s.payload)==null?void 0:f.user)??null;U(P),O(e),T.emit("userChange",{isAuthenticated:P,user:e}),((_=s.payload)==null?void 0:_.userEvent)==="login"&&T.emit("login",{user:e}),((h=s.payload)==null?void 0:h.userEvent)==="logout"&&T.emit("logout",void 0);break}case"TIUN_VERIFICATION_TOKEN":{const P=((k=s.payload)==null?void 0:k.token)??null,e=(R=s.payload)==null?void 0:R.requestId;e&&l.current.has(e)&&(l.current.get(e)(P),l.current.delete(e));break}case"TIUN_SHOW_PAYWALL":T.emit("paywallShow",{isConnected:!!((W=s.payload)!=null&&W.isConnected)});break;case"TIUN_HIDE_PAYWALL":T.emit("paywallHide",{sessionId:((B=s.payload)==null?void 0:B.sessionId)??"",isConnected:((J=s.payload)==null?void 0:J.isConnected)??!0});break;case"TIUN_ERROR":T.emit("error",((z=s.payload)==null?void 0:z.error)??s.payload??{});break}},[T]);d.useEffect(()=>{const s=o=>{if(!o||!Ue(t,o))return;const n=Te(o);E(()=>{var f;return(f=i.current)==null?void 0:f.resolveCheckout(n)})},v=b.Linking.addEventListener("url",({url:o})=>s(o));return b.Linking.getInitialURL().then(s).catch(()=>{}),()=>v.remove()},[t,E]);const V=d.useCallback(()=>E(()=>{var s;return(s=i.current)==null?void 0:s.login()}),[E]),F=d.useCallback(()=>E(()=>{var s;return(s=i.current)==null?void 0:s.logout()}),[E]),L=d.useCallback(s=>E(()=>{var v;return(v=i.current)==null?void 0:v.checkout(s==null?void 0:s.productId)}),[E]),q=d.useCallback(()=>new Promise(s=>{const v=`vt_${Math.random().toString(36).slice(2)}_${Date.now()}`;let o=!1;const n=f=>{o||(o=!0,l.current.delete(v),s(f))};l.current.set(v,n),E(()=>{var f;return(f=i.current)==null?void 0:f.getVerificationToken(v)}),setTimeout(()=>n(null),5e3)}),[E]),G=d.useMemo(()=>({isAuthenticated:m,user:N,ready:I,cryptoOk:$,login:V,logout:F,checkout:L,getUserVerificationToken:q}),[m,N,I,$,V,F,L,q]);return S.jsx(Ee.Provider,{value:G,children:S.jsxs(be.Provider,{value:T,children:[r,S.jsx(Ge,{ref:i,config:t,onEvent:K})]})})}function ze(){const t=d.useContext(Ee);if(!t)throw new Error("useTiun must be used within a <TiunProvider>");return t}function Me(t,r){const i=d.useContext(be),u=d.useRef(r);u.current=r,d.useEffect(()=>{if(!i)throw new Error("useTiunEvent must be used within a <TiunProvider>");return i.on(t,c=>u.current(c))},[i,t])}exports.TiunProvider=Je;exports.useTiun=ze;exports.useTiunEvent=Me;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
var Ne = Object.defineProperty;
|
|
2
|
+
var Ie = (t, r, i) => r in t ? Ne(t, r, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[r] = i;
|
|
3
|
+
var Te = (t, r, i) => (Ie(t, typeof r != "symbol" ? r + "" : r, i), i);
|
|
4
|
+
import Oe, { forwardRef as Ce, useRef as P, useState as B, useEffect as de, useImperativeHandle as Pe, createContext as ve, useCallback as H, useMemo as xe, useContext as _e } from "react";
|
|
5
|
+
import { StyleSheet as ue, View as ne, Text as te, Pressable as Ae, AppState as Ue, useWindowDimensions as je, Platform as $e, Linking as Ee } from "react-native";
|
|
6
|
+
import { WebView as Fe } from "react-native-webview";
|
|
7
|
+
import { close as Le, closeAuth as We, openAuth as Ve, open as be } from "react-native-inappbrowser-nitro";
|
|
8
|
+
import { getPublicKey as me, generate as Ye, sign as He, removeKey as De } from "react-native-secure-sign";
|
|
9
|
+
import * as oe from "react-native-keychain";
|
|
10
|
+
var le = { exports: {} }, X = {};
|
|
11
|
+
/**
|
|
12
|
+
* @license React
|
|
13
|
+
* react-jsx-runtime.production.js
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*/
|
|
20
|
+
var ye;
|
|
21
|
+
function Ge() {
|
|
22
|
+
if (ye)
|
|
23
|
+
return X;
|
|
24
|
+
ye = 1;
|
|
25
|
+
var t = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
26
|
+
function i(l, c, u) {
|
|
27
|
+
var h = null;
|
|
28
|
+
if (u !== void 0 && (h = "" + u), c.key !== void 0 && (h = "" + c.key), "key" in c) {
|
|
29
|
+
u = {};
|
|
30
|
+
for (var _ in c)
|
|
31
|
+
_ !== "key" && (u[_] = c[_]);
|
|
32
|
+
} else
|
|
33
|
+
u = c;
|
|
34
|
+
return c = u.ref, {
|
|
35
|
+
$$typeof: t,
|
|
36
|
+
type: l,
|
|
37
|
+
key: h,
|
|
38
|
+
ref: c !== void 0 ? c : null,
|
|
39
|
+
props: u
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return X.Fragment = r, X.jsx = i, X.jsxs = i, X;
|
|
43
|
+
}
|
|
44
|
+
var Q = {};
|
|
45
|
+
/**
|
|
46
|
+
* @license React
|
|
47
|
+
* react-jsx-runtime.development.js
|
|
48
|
+
*
|
|
49
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
50
|
+
*
|
|
51
|
+
* This source code is licensed under the MIT license found in the
|
|
52
|
+
* LICENSE file in the root directory of this source tree.
|
|
53
|
+
*/
|
|
54
|
+
var we;
|
|
55
|
+
function Be() {
|
|
56
|
+
return we || (we = 1, process.env.NODE_ENV !== "production" && function() {
|
|
57
|
+
function t(e) {
|
|
58
|
+
if (e == null)
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof e == "function")
|
|
61
|
+
return e.$$typeof === d ? null : e.displayName || e.name || null;
|
|
62
|
+
if (typeof e == "string")
|
|
63
|
+
return e;
|
|
64
|
+
switch (e) {
|
|
65
|
+
case T:
|
|
66
|
+
return "Fragment";
|
|
67
|
+
case W:
|
|
68
|
+
return "Profiler";
|
|
69
|
+
case K:
|
|
70
|
+
return "StrictMode";
|
|
71
|
+
case q:
|
|
72
|
+
return "Suspense";
|
|
73
|
+
case s:
|
|
74
|
+
return "SuspenseList";
|
|
75
|
+
case n:
|
|
76
|
+
return "Activity";
|
|
77
|
+
}
|
|
78
|
+
if (typeof e == "object")
|
|
79
|
+
switch (typeof e.tag == "number" && console.error(
|
|
80
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
81
|
+
), e.$$typeof) {
|
|
82
|
+
case S:
|
|
83
|
+
return "Portal";
|
|
84
|
+
case F:
|
|
85
|
+
return (e.displayName || "Context") + ".Provider";
|
|
86
|
+
case $:
|
|
87
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
88
|
+
case V:
|
|
89
|
+
var a = e.render;
|
|
90
|
+
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
91
|
+
case y:
|
|
92
|
+
return a = e.displayName || null, a !== null ? a : t(e.type) || "Memo";
|
|
93
|
+
case o:
|
|
94
|
+
a = e._payload, e = e._init;
|
|
95
|
+
try {
|
|
96
|
+
return t(e(a));
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
function r(e) {
|
|
103
|
+
return "" + e;
|
|
104
|
+
}
|
|
105
|
+
function i(e) {
|
|
106
|
+
try {
|
|
107
|
+
r(e);
|
|
108
|
+
var a = !1;
|
|
109
|
+
} catch {
|
|
110
|
+
a = !0;
|
|
111
|
+
}
|
|
112
|
+
if (a) {
|
|
113
|
+
a = console;
|
|
114
|
+
var f = a.error, E = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
115
|
+
return f.call(
|
|
116
|
+
a,
|
|
117
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
118
|
+
E
|
|
119
|
+
), r(e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function l(e) {
|
|
123
|
+
if (e === T)
|
|
124
|
+
return "<>";
|
|
125
|
+
if (typeof e == "object" && e !== null && e.$$typeof === o)
|
|
126
|
+
return "<...>";
|
|
127
|
+
try {
|
|
128
|
+
var a = t(e);
|
|
129
|
+
return a ? "<" + a + ">" : "<...>";
|
|
130
|
+
} catch {
|
|
131
|
+
return "<...>";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function c() {
|
|
135
|
+
var e = w.A;
|
|
136
|
+
return e === null ? null : e.getOwner();
|
|
137
|
+
}
|
|
138
|
+
function u() {
|
|
139
|
+
return Error("react-stack-top-frame");
|
|
140
|
+
}
|
|
141
|
+
function h(e) {
|
|
142
|
+
if (p.call(e, "key")) {
|
|
143
|
+
var a = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
144
|
+
if (a && a.isReactWarning)
|
|
145
|
+
return !1;
|
|
146
|
+
}
|
|
147
|
+
return e.key !== void 0;
|
|
148
|
+
}
|
|
149
|
+
function _(e, a) {
|
|
150
|
+
function f() {
|
|
151
|
+
L || (L = !0, console.error(
|
|
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
|
+
a
|
|
154
|
+
));
|
|
155
|
+
}
|
|
156
|
+
f.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
157
|
+
get: f,
|
|
158
|
+
configurable: !0
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function U() {
|
|
162
|
+
var e = t(this.type);
|
|
163
|
+
return J[e] || (J[e] = !0, console.error(
|
|
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
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
166
|
+
}
|
|
167
|
+
function g(e, a, f, E, A, N, ie, ae) {
|
|
168
|
+
return f = N.ref, e = {
|
|
169
|
+
$$typeof: j,
|
|
170
|
+
type: e,
|
|
171
|
+
key: a,
|
|
172
|
+
props: N,
|
|
173
|
+
_owner: A
|
|
174
|
+
}, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
|
|
175
|
+
enumerable: !1,
|
|
176
|
+
get: U
|
|
177
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
178
|
+
configurable: !1,
|
|
179
|
+
enumerable: !1,
|
|
180
|
+
writable: !0,
|
|
181
|
+
value: 0
|
|
182
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
183
|
+
configurable: !1,
|
|
184
|
+
enumerable: !1,
|
|
185
|
+
writable: !0,
|
|
186
|
+
value: null
|
|
187
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
188
|
+
configurable: !1,
|
|
189
|
+
enumerable: !1,
|
|
190
|
+
writable: !0,
|
|
191
|
+
value: ie
|
|
192
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
193
|
+
configurable: !1,
|
|
194
|
+
enumerable: !1,
|
|
195
|
+
writable: !0,
|
|
196
|
+
value: ae
|
|
197
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
198
|
+
}
|
|
199
|
+
function k(e, a, f, E, A, N, ie, ae) {
|
|
200
|
+
var b = a.children;
|
|
201
|
+
if (b !== void 0)
|
|
202
|
+
if (E)
|
|
203
|
+
if (R(b)) {
|
|
204
|
+
for (E = 0; E < b.length; E++)
|
|
205
|
+
I(b[E]);
|
|
206
|
+
Object.freeze && Object.freeze(b);
|
|
207
|
+
} else
|
|
208
|
+
console.error(
|
|
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
|
+
);
|
|
211
|
+
else
|
|
212
|
+
I(b);
|
|
213
|
+
if (p.call(a, "key")) {
|
|
214
|
+
b = t(e);
|
|
215
|
+
var Y = Object.keys(a).filter(function(ke) {
|
|
216
|
+
return ke !== "key";
|
|
217
|
+
});
|
|
218
|
+
E = 0 < Y.length ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}", O[b + E] || (Y = 0 < Y.length ? "{" + Y.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
219
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
220
|
+
let props = %s;
|
|
221
|
+
<%s {...props} />
|
|
222
|
+
React keys must be passed directly to JSX without using spread:
|
|
223
|
+
let props = %s;
|
|
224
|
+
<%s key={someKey} {...props} />`,
|
|
225
|
+
E,
|
|
226
|
+
b,
|
|
227
|
+
Y,
|
|
228
|
+
b
|
|
229
|
+
), O[b + E] = !0);
|
|
230
|
+
}
|
|
231
|
+
if (b = null, f !== void 0 && (i(f), b = "" + f), h(a) && (i(a.key), b = "" + a.key), "key" in a) {
|
|
232
|
+
f = {};
|
|
233
|
+
for (var ce in a)
|
|
234
|
+
ce !== "key" && (f[ce] = a[ce]);
|
|
235
|
+
} else
|
|
236
|
+
f = a;
|
|
237
|
+
return b && _(
|
|
238
|
+
f,
|
|
239
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
240
|
+
), g(
|
|
241
|
+
e,
|
|
242
|
+
b,
|
|
243
|
+
N,
|
|
244
|
+
A,
|
|
245
|
+
c(),
|
|
246
|
+
f,
|
|
247
|
+
ie,
|
|
248
|
+
ae
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
function I(e) {
|
|
252
|
+
typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._store.validated = 1);
|
|
253
|
+
}
|
|
254
|
+
var x = Oe, j = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), T = Symbol.for("react.fragment"), K = Symbol.for("react.strict_mode"), W = Symbol.for("react.profiler"), $ = Symbol.for("react.consumer"), F = Symbol.for("react.context"), V = Symbol.for("react.forward_ref"), q = Symbol.for("react.suspense"), s = Symbol.for("react.suspense_list"), y = Symbol.for("react.memo"), o = Symbol.for("react.lazy"), n = Symbol.for("react.activity"), d = Symbol.for("react.client.reference"), w = x.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, p = Object.prototype.hasOwnProperty, R = Array.isArray, m = console.createTask ? console.createTask : function() {
|
|
255
|
+
return null;
|
|
256
|
+
};
|
|
257
|
+
x = {
|
|
258
|
+
"react-stack-bottom-frame": function(e) {
|
|
259
|
+
return e();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var L, J = {}, z = x["react-stack-bottom-frame"].bind(
|
|
263
|
+
x,
|
|
264
|
+
u
|
|
265
|
+
)(), M = m(l(u)), O = {};
|
|
266
|
+
Q.Fragment = T, Q.jsx = function(e, a, f, E, A) {
|
|
267
|
+
var N = 1e4 > w.recentlyCreatedOwnerStacks++;
|
|
268
|
+
return k(
|
|
269
|
+
e,
|
|
270
|
+
a,
|
|
271
|
+
f,
|
|
272
|
+
!1,
|
|
273
|
+
E,
|
|
274
|
+
A,
|
|
275
|
+
N ? Error("react-stack-top-frame") : z,
|
|
276
|
+
N ? m(l(e)) : M
|
|
277
|
+
);
|
|
278
|
+
}, Q.jsxs = function(e, a, f, E, A) {
|
|
279
|
+
var N = 1e4 > w.recentlyCreatedOwnerStacks++;
|
|
280
|
+
return k(
|
|
281
|
+
e,
|
|
282
|
+
a,
|
|
283
|
+
f,
|
|
284
|
+
!0,
|
|
285
|
+
E,
|
|
286
|
+
A,
|
|
287
|
+
N ? Error("react-stack-top-frame") : z,
|
|
288
|
+
N ? m(l(e)) : M
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
}()), Q;
|
|
292
|
+
}
|
|
293
|
+
process.env.NODE_ENV === "production" ? le.exports = Ge() : le.exports = Be();
|
|
294
|
+
var v = le.exports;
|
|
295
|
+
const Ke = {
|
|
296
|
+
errorPillText: "Technical Error",
|
|
297
|
+
errorNotificationTitle: "Technical error",
|
|
298
|
+
errorNotificationSubtitle: "Please reload the page or contact our support.",
|
|
299
|
+
errorTitle: "Technical error",
|
|
300
|
+
errorTextBeforeEmail: "Try reloading the page. If the error persists, please contact ",
|
|
301
|
+
errorTextAfterEmail: " and we’ll help you right away.",
|
|
302
|
+
connectionErrorTitle: "No connection",
|
|
303
|
+
connectionErrorText: "We couldn’t reach tiun. Check your internet connection and try again.",
|
|
304
|
+
connectionErrorCta: "Try again"
|
|
305
|
+
}, qe = {
|
|
306
|
+
errorPillText: "Erreur Technique",
|
|
307
|
+
errorNotificationTitle: "Erreur technique",
|
|
308
|
+
errorNotificationSubtitle: "Veuillez recharger la page ou contacter notre support.",
|
|
309
|
+
errorTitle: "Erreur technique",
|
|
310
|
+
errorTextBeforeEmail: "Veuillez recharger la page. Si l’erreur persiste, contactez ",
|
|
311
|
+
errorTextAfterEmail: " et nous vous aiderons immédiatement.",
|
|
312
|
+
connectionErrorTitle: "Pas de connexion",
|
|
313
|
+
connectionErrorText: "Impossible de joindre tiun. Vérifiez votre connexion Internet et réessayez.",
|
|
314
|
+
connectionErrorCta: "Réessayer"
|
|
315
|
+
}, Je = {
|
|
316
|
+
errorPillText: "Technischer Fehler",
|
|
317
|
+
errorNotificationTitle: "Technischer Fehler",
|
|
318
|
+
errorNotificationSubtitle: "Bitte lade die Seite neu, oder kontaktiere unseren Support.",
|
|
319
|
+
errorTitle: "Technischer Fehler",
|
|
320
|
+
errorTextBeforeEmail: "Bitte lade die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktiere ",
|
|
321
|
+
errorTextAfterEmail: " und wir helfen Dir sofort weiter.",
|
|
322
|
+
connectionErrorTitle: "Keine Verbindung",
|
|
323
|
+
connectionErrorText: "tiun konnte nicht erreicht werden. Überprüfe deine Internetverbindung und versuche es erneut.",
|
|
324
|
+
connectionErrorCta: "Erneut versuchen"
|
|
325
|
+
}, ze = {
|
|
326
|
+
errorPillText: "Technischer Fehler",
|
|
327
|
+
errorNotificationTitle: "Technischer Fehler",
|
|
328
|
+
errorNotificationSubtitle: "Bitte laden Sie die Seite neu, oder kontaktieren Sie unseren Support.",
|
|
329
|
+
errorTitle: "Technischer Fehler",
|
|
330
|
+
errorTextBeforeEmail: "Bitte laden Sie die Seite neu. Sollte der Fehler weiterhin auftreten, kontaktieren Sie ",
|
|
331
|
+
errorTextAfterEmail: " und wir helfen Ihnen sofort weiter.",
|
|
332
|
+
connectionErrorTitle: "Keine Verbindung",
|
|
333
|
+
connectionErrorText: "tiun konnte nicht erreicht werden. Überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
|
334
|
+
connectionErrorCta: "Erneut versuchen"
|
|
335
|
+
};
|
|
336
|
+
function Me(t, r = "informal") {
|
|
337
|
+
switch ((t ?? "en").trim().toLowerCase()) {
|
|
338
|
+
case "de":
|
|
339
|
+
return r === "formal" ? ze : Je;
|
|
340
|
+
case "fr":
|
|
341
|
+
return qe;
|
|
342
|
+
default:
|
|
343
|
+
return Ke;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const D = {
|
|
347
|
+
// Web protocol (TIUN_EVENT) — consumer → snippet commands.
|
|
348
|
+
start: "TIUN_START",
|
|
349
|
+
checkout: "TIUN_CHECKOUT",
|
|
350
|
+
updateContent: "TIUN_UPDATE_CONTENT",
|
|
351
|
+
login: "TIUN_LOGIN",
|
|
352
|
+
logout: "TIUN_LOGOUT",
|
|
353
|
+
getVerificationToken: "TIUN_GET_VERIFICATION_TOKEN",
|
|
354
|
+
// Overlay (TIUN_OVERLAY) — snippet → native footprint signal.
|
|
355
|
+
overlayChange: "TIUN_OVERLAY_CHANGE",
|
|
356
|
+
// Native device bridge (TIUN_NATIVE) — snippet → native requests.
|
|
357
|
+
popPubKeyRequest: "TIUN_POP_PUBKEY_REQUEST",
|
|
358
|
+
popSignRequest: "TIUN_POP_SIGN_REQUEST",
|
|
359
|
+
tokenGet: "TIUN_TOKEN_GET",
|
|
360
|
+
tokenPersist: "TIUN_TOKEN_PERSIST",
|
|
361
|
+
nativeReset: "TIUN_NATIVE_RESET",
|
|
362
|
+
// Native device bridge (TIUN_NATIVE) — native → snippet responses (host-injected).
|
|
363
|
+
popPubKey: "TIUN_POP_PUBKEY",
|
|
364
|
+
restoreToken: "TIUN_RESTORE_TOKEN",
|
|
365
|
+
popSignResult: "TIUN_POP_SIGN_RESULT",
|
|
366
|
+
resolveCheckout: "TIUN_RESOLVE_CHECKOUT"
|
|
367
|
+
}, Xe = "__TIUN_NATIVE_CRYPTO__", Qe = "https://api.tiun.live";
|
|
368
|
+
function fe(t) {
|
|
369
|
+
return (t.host ?? Qe).replace(/\/$/, "");
|
|
370
|
+
}
|
|
371
|
+
function re(t) {
|
|
372
|
+
return `app.tiun.pop.${t.snippetId || "default"}`;
|
|
373
|
+
}
|
|
374
|
+
function Z(t) {
|
|
375
|
+
return `app.tiun.token.${t.snippetId || "default"}`;
|
|
376
|
+
}
|
|
377
|
+
function Ze(t) {
|
|
378
|
+
return `${`${fe(t)}/live_api/v2/snippets/${encodeURIComponent(t.snippetId)}/webview_return`}?to=${encodeURIComponent(t.returnUrl)}`;
|
|
379
|
+
}
|
|
380
|
+
function et(t) {
|
|
381
|
+
const r = {
|
|
382
|
+
language: t.language ?? "en"
|
|
383
|
+
}, i = Object.entries(r).map(([c, u]) => `${encodeURIComponent(c)}=${encodeURIComponent(u)}`).join("&"), l = `${fe(t)}/live_api/v2/snippets/${encodeURIComponent(t.snippetId)}/webview_host`;
|
|
384
|
+
return i ? `${l}?${i}` : l;
|
|
385
|
+
}
|
|
386
|
+
function Se(t) {
|
|
387
|
+
const r = t.indexOf("?");
|
|
388
|
+
if (!(r < 0))
|
|
389
|
+
for (const i of t.slice(r + 1).split("&")) {
|
|
390
|
+
const l = i.indexOf("=");
|
|
391
|
+
if ((l < 0 ? i : i.slice(0, l)) === "status") {
|
|
392
|
+
const u = l < 0 ? "" : i.slice(l + 1);
|
|
393
|
+
return u ? decodeURIComponent(u) : void 0;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function tt(t, r) {
|
|
398
|
+
const i = t.returnUrl.split("?")[0];
|
|
399
|
+
return r.startsWith(i);
|
|
400
|
+
}
|
|
401
|
+
const pe = "1005";
|
|
402
|
+
function he(t) {
|
|
403
|
+
return t == null ? void 0 : t.code;
|
|
404
|
+
}
|
|
405
|
+
async function rt(t) {
|
|
406
|
+
try {
|
|
407
|
+
return await me(t);
|
|
408
|
+
} catch (r) {
|
|
409
|
+
if (he(r) === pe)
|
|
410
|
+
return Ye(t, { requireUserAuthentication: !1 });
|
|
411
|
+
throw r;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function nt(t) {
|
|
415
|
+
try {
|
|
416
|
+
return await me(t);
|
|
417
|
+
} catch (r) {
|
|
418
|
+
if (he(r) === pe)
|
|
419
|
+
return null;
|
|
420
|
+
throw r;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function ot(t, r) {
|
|
424
|
+
return He(t, r);
|
|
425
|
+
}
|
|
426
|
+
async function it(t) {
|
|
427
|
+
try {
|
|
428
|
+
await De(t);
|
|
429
|
+
} catch (r) {
|
|
430
|
+
if (he(r) !== pe)
|
|
431
|
+
throw r;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const at = "tiun_auth_token";
|
|
435
|
+
async function ct(t) {
|
|
436
|
+
const r = await oe.getGenericPassword({ service: t });
|
|
437
|
+
return r ? r.password : null;
|
|
438
|
+
}
|
|
439
|
+
async function st(t, r) {
|
|
440
|
+
await oe.setGenericPassword(at, r, {
|
|
441
|
+
service: t,
|
|
442
|
+
accessible: oe.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
async function se(t) {
|
|
446
|
+
await oe.resetGenericPassword({ service: t });
|
|
447
|
+
}
|
|
448
|
+
function ut(t) {
|
|
449
|
+
const r = Me(t);
|
|
450
|
+
return {
|
|
451
|
+
title: r.connectionErrorTitle,
|
|
452
|
+
text: r.connectionErrorText,
|
|
453
|
+
cta: r.connectionErrorCta
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
function lt({ language: t, onRetry: r }) {
|
|
457
|
+
const i = ut(t);
|
|
458
|
+
return /* @__PURE__ */ v.jsxs(ne, { style: C.container, children: [
|
|
459
|
+
/* @__PURE__ */ v.jsxs(ne, { style: C.content, children: [
|
|
460
|
+
/* @__PURE__ */ v.jsx(te, { style: C.title, children: i.title }),
|
|
461
|
+
/* @__PURE__ */ v.jsx(ne, { style: C.iconBadge, children: /* @__PURE__ */ v.jsx(te, { style: C.iconGlyph, children: "!" }) }),
|
|
462
|
+
/* @__PURE__ */ v.jsx(te, { style: C.text, children: i.text })
|
|
463
|
+
] }),
|
|
464
|
+
/* @__PURE__ */ v.jsx(
|
|
465
|
+
Ae,
|
|
466
|
+
{
|
|
467
|
+
accessibilityRole: "button",
|
|
468
|
+
onPress: r,
|
|
469
|
+
style: ({ pressed: l }) => [C.button, l && C.buttonPressed],
|
|
470
|
+
children: /* @__PURE__ */ v.jsx(te, { style: C.buttonText, children: i.cta })
|
|
471
|
+
}
|
|
472
|
+
)
|
|
473
|
+
] });
|
|
474
|
+
}
|
|
475
|
+
const C = ue.create({
|
|
476
|
+
container: {
|
|
477
|
+
...ue.absoluteFillObject,
|
|
478
|
+
backgroundColor: "#fff",
|
|
479
|
+
padding: 24,
|
|
480
|
+
justifyContent: "space-between"
|
|
481
|
+
},
|
|
482
|
+
content: {
|
|
483
|
+
flex: 1,
|
|
484
|
+
alignItems: "center",
|
|
485
|
+
justifyContent: "center",
|
|
486
|
+
gap: 24
|
|
487
|
+
},
|
|
488
|
+
title: {
|
|
489
|
+
fontSize: 20,
|
|
490
|
+
fontWeight: "600",
|
|
491
|
+
color: "#000",
|
|
492
|
+
textAlign: "center"
|
|
493
|
+
},
|
|
494
|
+
iconBadge: {
|
|
495
|
+
width: 40,
|
|
496
|
+
height: 40,
|
|
497
|
+
borderRadius: 20,
|
|
498
|
+
backgroundColor: "#FCE7F3",
|
|
499
|
+
// pink-100, matches errorCircleIcon
|
|
500
|
+
alignItems: "center",
|
|
501
|
+
justifyContent: "center"
|
|
502
|
+
},
|
|
503
|
+
iconGlyph: {
|
|
504
|
+
color: "#DB2777",
|
|
505
|
+
// pink-600
|
|
506
|
+
fontSize: 22,
|
|
507
|
+
fontWeight: "700",
|
|
508
|
+
lineHeight: 26
|
|
509
|
+
},
|
|
510
|
+
text: {
|
|
511
|
+
fontSize: 16,
|
|
512
|
+
fontWeight: "500",
|
|
513
|
+
color: "#4B5563",
|
|
514
|
+
// gray-600
|
|
515
|
+
textAlign: "center"
|
|
516
|
+
},
|
|
517
|
+
button: {
|
|
518
|
+
backgroundColor: "#000",
|
|
519
|
+
borderRadius: 999,
|
|
520
|
+
minHeight: 56,
|
|
521
|
+
alignItems: "center",
|
|
522
|
+
justifyContent: "center",
|
|
523
|
+
alignSelf: "stretch"
|
|
524
|
+
},
|
|
525
|
+
buttonPressed: { opacity: 0.9 },
|
|
526
|
+
buttonText: {
|
|
527
|
+
color: "#fff",
|
|
528
|
+
fontSize: 16,
|
|
529
|
+
fontWeight: "500"
|
|
530
|
+
}
|
|
531
|
+
}), dt = Fe;
|
|
532
|
+
function G(t) {
|
|
533
|
+
return `try{window.tiunHost&&${t};}catch(e){}; true;`;
|
|
534
|
+
}
|
|
535
|
+
const ft = Ce(
|
|
536
|
+
function({ config: r, onEvent: i }, l) {
|
|
537
|
+
const c = !!r.debug, u = P(null), [h, _] = B(!1), [U, g] = B(!1), k = P(!1), I = P(!1), x = () => {
|
|
538
|
+
var o;
|
|
539
|
+
g(!1), (o = u.current) == null || o.reload();
|
|
540
|
+
};
|
|
541
|
+
de(() => {
|
|
542
|
+
if (!U)
|
|
543
|
+
return;
|
|
544
|
+
const o = Ue.addEventListener("change", (n) => {
|
|
545
|
+
var d;
|
|
546
|
+
n === "active" && (g(!1), (d = u.current) == null || d.reload());
|
|
547
|
+
});
|
|
548
|
+
return () => o.remove();
|
|
549
|
+
}, [U]);
|
|
550
|
+
const j = `window.${Xe} = true;window.__TIUN_CONFIG__ = Object.assign({}, window.__TIUN_CONFIG__, { returnUrl: ${JSON.stringify(Ze(r))} });true;`, S = (o, ...n) => {
|
|
551
|
+
var d;
|
|
552
|
+
return (d = u.current) == null ? void 0 : d.injectJavaScript(
|
|
553
|
+
G(
|
|
554
|
+
`window.tiunHost.${o}(${n.map((w) => JSON.stringify(w) ?? "null").join(",")})`
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
}, T = (o) => {
|
|
558
|
+
var n;
|
|
559
|
+
I.current || (I.current = !0, Le().catch(() => {
|
|
560
|
+
}), We().catch(() => {
|
|
561
|
+
}), _(!0), (n = u.current) == null || n.injectJavaScript(
|
|
562
|
+
G(
|
|
563
|
+
`window.tiunHost.resolveCheckout(${o ? JSON.stringify(o) : ""})`
|
|
564
|
+
)
|
|
565
|
+
));
|
|
566
|
+
}, K = (o) => {
|
|
567
|
+
var n, d, w;
|
|
568
|
+
switch (o.type) {
|
|
569
|
+
case D.popPubKeyRequest:
|
|
570
|
+
return rt(re(r)).then((p) => S("popPubKey", p)).catch((p) => {
|
|
571
|
+
c && console.warn("[tiun] ensurePopKey failed:", p), S("popPubKey", null);
|
|
572
|
+
}), !0;
|
|
573
|
+
case D.tokenGet:
|
|
574
|
+
return (async () => {
|
|
575
|
+
try {
|
|
576
|
+
const p = await ct(Z(r));
|
|
577
|
+
if (p && !await nt(re(r))) {
|
|
578
|
+
await se(Z(r)), S("restoreToken", null);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
S("restoreToken", p);
|
|
582
|
+
} catch {
|
|
583
|
+
S("restoreToken", null);
|
|
584
|
+
}
|
|
585
|
+
})(), !0;
|
|
586
|
+
case D.popSignRequest: {
|
|
587
|
+
const p = (n = o.payload) == null ? void 0 : n.requestId, R = (d = o.payload) == null ? void 0 : d.information;
|
|
588
|
+
return ot(re(r), R).then((m) => S("popSignResult", p, m, null)).catch((m) => {
|
|
589
|
+
const L = (m == null ? void 0 : m.code) ?? "sign_failed";
|
|
590
|
+
c && console.warn("[tiun] popSign failed:", m), S("popSignResult", p, null, String(L));
|
|
591
|
+
}), !0;
|
|
592
|
+
}
|
|
593
|
+
case D.tokenPersist: {
|
|
594
|
+
const p = ((w = o.payload) == null ? void 0 : w.token) ?? null;
|
|
595
|
+
return (p ? st(Z(r), p) : se(Z(r))).catch(
|
|
596
|
+
(R) => c && console.warn("[tiun] token persist failed:", R)
|
|
597
|
+
), !0;
|
|
598
|
+
}
|
|
599
|
+
case D.nativeReset:
|
|
600
|
+
return Promise.allSettled([
|
|
601
|
+
it(re(r)),
|
|
602
|
+
se(Z(r))
|
|
603
|
+
]), !0;
|
|
604
|
+
default:
|
|
605
|
+
return !1;
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
Pe(
|
|
609
|
+
l,
|
|
610
|
+
() => ({
|
|
611
|
+
login: () => {
|
|
612
|
+
var o;
|
|
613
|
+
_(!0), (o = u.current) == null || o.injectJavaScript(
|
|
614
|
+
G("window.tiunHost.login()")
|
|
615
|
+
);
|
|
616
|
+
},
|
|
617
|
+
checkout: (o) => {
|
|
618
|
+
var n;
|
|
619
|
+
_(!0), k.current = !0, I.current = !1, (n = u.current) == null || n.injectJavaScript(
|
|
620
|
+
G(
|
|
621
|
+
`window.tiunHost.checkout(${o ? JSON.stringify(o) : ""})`
|
|
622
|
+
)
|
|
623
|
+
);
|
|
624
|
+
},
|
|
625
|
+
logout: () => {
|
|
626
|
+
var o;
|
|
627
|
+
return (o = u.current) == null ? void 0 : o.injectJavaScript(
|
|
628
|
+
G("window.tiunHost.logout()")
|
|
629
|
+
);
|
|
630
|
+
},
|
|
631
|
+
getVerificationToken: (o) => {
|
|
632
|
+
var n;
|
|
633
|
+
return (n = u.current) == null ? void 0 : n.injectJavaScript(
|
|
634
|
+
G(
|
|
635
|
+
`window.tiunHost.getVerificationToken(${o ? JSON.stringify(o) : ""})`
|
|
636
|
+
)
|
|
637
|
+
);
|
|
638
|
+
},
|
|
639
|
+
resolveCheckout: T,
|
|
640
|
+
reload: () => {
|
|
641
|
+
var o;
|
|
642
|
+
return (o = u.current) == null ? void 0 : o.reload();
|
|
643
|
+
}
|
|
644
|
+
}),
|
|
645
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
646
|
+
[]
|
|
647
|
+
);
|
|
648
|
+
const W = (o) => {
|
|
649
|
+
var d, w, p;
|
|
650
|
+
let n = null;
|
|
651
|
+
try {
|
|
652
|
+
n = JSON.parse(o.nativeEvent.data);
|
|
653
|
+
} catch {
|
|
654
|
+
c && console.warn(
|
|
655
|
+
"[tiun] non-JSON bridge message:",
|
|
656
|
+
o.nativeEvent.data
|
|
657
|
+
);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (!(!n || typeof n.type != "string")) {
|
|
661
|
+
if (n.type === "console") {
|
|
662
|
+
c && console.log(
|
|
663
|
+
"[tiun webview]",
|
|
664
|
+
(d = n.payload) == null ? void 0 : d.level,
|
|
665
|
+
(w = n.payload) == null ? void 0 : w.message
|
|
666
|
+
);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if ((n.type === "cryptoCheck" || n.type === "hostBridgeReady") && g(!1), c && console.log("[tiun] <-", n.type, n.payload), !K(n)) {
|
|
670
|
+
if (n.type === D.overlayChange) {
|
|
671
|
+
const R = !!((p = n.payload) != null && p.overlay);
|
|
672
|
+
_(R), R || (k.current = !1);
|
|
673
|
+
}
|
|
674
|
+
i(n);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}, $ = (o) => {
|
|
678
|
+
if (k.current = !1, $e.OS === "ios") {
|
|
679
|
+
Ve(o, r.returnUrl).then((n) => {
|
|
680
|
+
n.type === "success" && n.url ? T(Se(n.url)) : n.type === "cancel" && T("cancelled");
|
|
681
|
+
}).catch((n) => c && console.warn("[tiun] openAuth error:", n));
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
be(o, {
|
|
685
|
+
showTitle: !1,
|
|
686
|
+
enableUrlBarHiding: !1,
|
|
687
|
+
enableDefaultShare: !1,
|
|
688
|
+
forceCloseOnRedirection: !1
|
|
689
|
+
}).then((n) => {
|
|
690
|
+
n.type === "cancel" && T("cancelled");
|
|
691
|
+
}).catch(
|
|
692
|
+
(n) => c && console.warn("[tiun] in-app browser open error:", n)
|
|
693
|
+
);
|
|
694
|
+
}, F = (o) => {
|
|
695
|
+
be(o, {
|
|
696
|
+
modalPresentationStyle: "fullScreen",
|
|
697
|
+
modalEnabled: !0,
|
|
698
|
+
animated: !0,
|
|
699
|
+
enableBarCollapsing: !0
|
|
700
|
+
}).catch(
|
|
701
|
+
(n) => c && console.warn("[tiun] in-app browser open failed:", n)
|
|
702
|
+
);
|
|
703
|
+
}, V = (o) => {
|
|
704
|
+
var d;
|
|
705
|
+
const n = (d = o.nativeEvent) == null ? void 0 : d.targetUrl;
|
|
706
|
+
n && (k.current ? $(n) : F(n));
|
|
707
|
+
}, q = (o) => {
|
|
708
|
+
const n = o.url;
|
|
709
|
+
return n.startsWith(fe(r)) || n.startsWith("about:") || n.startsWith("data:") || n === "about:blank" ? !0 : n.startsWith("http://") || n.startsWith("https://") ? (k.current && o.isTopFrame !== !1 ? $(n) : F(n), !1) : !0;
|
|
710
|
+
}, { width: s, height: y } = je();
|
|
711
|
+
return /* @__PURE__ */ v.jsxs(
|
|
712
|
+
ne,
|
|
713
|
+
{
|
|
714
|
+
pointerEvents: h ? "auto" : "none",
|
|
715
|
+
style: [
|
|
716
|
+
ee.container,
|
|
717
|
+
{ width: s, height: y },
|
|
718
|
+
h ? ee.visible : ee.hidden
|
|
719
|
+
],
|
|
720
|
+
children: [
|
|
721
|
+
/* @__PURE__ */ v.jsx(
|
|
722
|
+
dt,
|
|
723
|
+
{
|
|
724
|
+
ref: u,
|
|
725
|
+
source: { uri: et(r) },
|
|
726
|
+
originWhitelist: ["*"],
|
|
727
|
+
onMessage: W,
|
|
728
|
+
onShouldStartLoadWithRequest: q,
|
|
729
|
+
onOpenWindow: V,
|
|
730
|
+
injectedJavaScriptBeforeContentLoaded: j,
|
|
731
|
+
javaScriptEnabled: !0,
|
|
732
|
+
domStorageEnabled: !0,
|
|
733
|
+
style: ee.webview,
|
|
734
|
+
containerStyle: ee.webview,
|
|
735
|
+
onError: (o) => {
|
|
736
|
+
c && console.warn("[tiun] webview load error:", o.nativeEvent), g(!0);
|
|
737
|
+
},
|
|
738
|
+
onHttpError: (o) => {
|
|
739
|
+
c && console.warn("[tiun] webview http error:", o.nativeEvent), g(!0);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
),
|
|
743
|
+
U && h ? /* @__PURE__ */ v.jsx(lt, { language: r.language, onRetry: x }) : null
|
|
744
|
+
]
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
), ee = ue.create({
|
|
749
|
+
container: {
|
|
750
|
+
position: "absolute",
|
|
751
|
+
top: 0,
|
|
752
|
+
left: 0,
|
|
753
|
+
zIndex: 9999,
|
|
754
|
+
elevation: 9999
|
|
755
|
+
},
|
|
756
|
+
webview: {
|
|
757
|
+
flex: 1,
|
|
758
|
+
backgroundColor: "transparent"
|
|
759
|
+
},
|
|
760
|
+
visible: { opacity: 1 },
|
|
761
|
+
hidden: { opacity: 0 }
|
|
762
|
+
});
|
|
763
|
+
class pt {
|
|
764
|
+
constructor() {
|
|
765
|
+
Te(this, "listeners", /* @__PURE__ */ new Map());
|
|
766
|
+
}
|
|
767
|
+
on(r, i) {
|
|
768
|
+
let l = this.listeners.get(r);
|
|
769
|
+
return l || (l = /* @__PURE__ */ new Set(), this.listeners.set(r, l)), l.add(i), () => {
|
|
770
|
+
var c;
|
|
771
|
+
(c = this.listeners.get(r)) == null || c.delete(i);
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
emit(r, i) {
|
|
775
|
+
const l = this.listeners.get(r);
|
|
776
|
+
if (l)
|
|
777
|
+
for (const c of l)
|
|
778
|
+
try {
|
|
779
|
+
c(i);
|
|
780
|
+
} catch {
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const Re = ve(null), ge = ve(null);
|
|
785
|
+
function vt({ config: t, children: r }) {
|
|
786
|
+
const i = P(null), l = P(!1), c = P([]), u = P(/* @__PURE__ */ new Map()), h = P(new pt()).current, [_, U] = B(!1), [g, k] = B(null), [I, x] = B(!1), [j, S] = B(null), T = H((s) => {
|
|
787
|
+
l.current ? s() : c.current.push(s);
|
|
788
|
+
}, []), K = H(
|
|
789
|
+
(s) => {
|
|
790
|
+
var y, o, n, d, w, p, R, m, L, J, z, M;
|
|
791
|
+
switch (s.type) {
|
|
792
|
+
case "cryptoCheck":
|
|
793
|
+
S(!!((y = s.payload) != null && y.subtle && ((o = s.payload) != null && o.secureContext)));
|
|
794
|
+
break;
|
|
795
|
+
case "TIUN_SNIPPET_INITIALIZED": {
|
|
796
|
+
l.current = !0, x(!0), h.emit("ready", void 0);
|
|
797
|
+
const O = c.current;
|
|
798
|
+
c.current = [], O.forEach((e) => e());
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
case "TIUN_USER_CHANGE": {
|
|
802
|
+
const O = !!((n = s.payload) != null && n.isAuthenticated), e = ((d = s.payload) == null ? void 0 : d.user) ?? null;
|
|
803
|
+
U(O), k(e), h.emit("userChange", { isAuthenticated: O, user: e }), ((w = s.payload) == null ? void 0 : w.userEvent) === "login" && h.emit("login", { user: e }), ((p = s.payload) == null ? void 0 : p.userEvent) === "logout" && h.emit("logout", void 0);
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
case "TIUN_VERIFICATION_TOKEN": {
|
|
807
|
+
const O = ((R = s.payload) == null ? void 0 : R.token) ?? null, e = (m = s.payload) == null ? void 0 : m.requestId;
|
|
808
|
+
e && u.current.has(e) && (u.current.get(e)(O), u.current.delete(e));
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
case "TIUN_SHOW_PAYWALL":
|
|
812
|
+
h.emit("paywallShow", { isConnected: !!((L = s.payload) != null && L.isConnected) });
|
|
813
|
+
break;
|
|
814
|
+
case "TIUN_HIDE_PAYWALL":
|
|
815
|
+
h.emit("paywallHide", {
|
|
816
|
+
sessionId: ((J = s.payload) == null ? void 0 : J.sessionId) ?? "",
|
|
817
|
+
isConnected: ((z = s.payload) == null ? void 0 : z.isConnected) ?? !0
|
|
818
|
+
});
|
|
819
|
+
break;
|
|
820
|
+
case "TIUN_ERROR":
|
|
821
|
+
h.emit("error", ((M = s.payload) == null ? void 0 : M.error) ?? s.payload ?? {});
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
[h]
|
|
826
|
+
);
|
|
827
|
+
de(() => {
|
|
828
|
+
const s = (o) => {
|
|
829
|
+
if (!o || !tt(t, o))
|
|
830
|
+
return;
|
|
831
|
+
const n = Se(o);
|
|
832
|
+
T(() => {
|
|
833
|
+
var d;
|
|
834
|
+
return (d = i.current) == null ? void 0 : d.resolveCheckout(n);
|
|
835
|
+
});
|
|
836
|
+
}, y = Ee.addEventListener("url", ({ url: o }) => s(o));
|
|
837
|
+
return Ee.getInitialURL().then(s).catch(() => {
|
|
838
|
+
}), () => y.remove();
|
|
839
|
+
}, [t, T]);
|
|
840
|
+
const W = H(() => T(() => {
|
|
841
|
+
var s;
|
|
842
|
+
return (s = i.current) == null ? void 0 : s.login();
|
|
843
|
+
}), [T]), $ = H(() => T(() => {
|
|
844
|
+
var s;
|
|
845
|
+
return (s = i.current) == null ? void 0 : s.logout();
|
|
846
|
+
}), [T]), F = H(
|
|
847
|
+
(s) => T(() => {
|
|
848
|
+
var y;
|
|
849
|
+
return (y = i.current) == null ? void 0 : y.checkout(s == null ? void 0 : s.productId);
|
|
850
|
+
}),
|
|
851
|
+
[T]
|
|
852
|
+
), V = H(
|
|
853
|
+
() => new Promise((s) => {
|
|
854
|
+
const y = `vt_${Math.random().toString(36).slice(2)}_${Date.now()}`;
|
|
855
|
+
let o = !1;
|
|
856
|
+
const n = (d) => {
|
|
857
|
+
o || (o = !0, u.current.delete(y), s(d));
|
|
858
|
+
};
|
|
859
|
+
u.current.set(y, n), T(() => {
|
|
860
|
+
var d;
|
|
861
|
+
return (d = i.current) == null ? void 0 : d.getVerificationToken(y);
|
|
862
|
+
}), setTimeout(() => n(null), 5e3);
|
|
863
|
+
}),
|
|
864
|
+
[T]
|
|
865
|
+
), q = xe(
|
|
866
|
+
() => ({
|
|
867
|
+
isAuthenticated: _,
|
|
868
|
+
user: g,
|
|
869
|
+
ready: I,
|
|
870
|
+
cryptoOk: j,
|
|
871
|
+
login: W,
|
|
872
|
+
logout: $,
|
|
873
|
+
checkout: F,
|
|
874
|
+
getUserVerificationToken: V
|
|
875
|
+
}),
|
|
876
|
+
[_, g, I, j, W, $, F, V]
|
|
877
|
+
);
|
|
878
|
+
return /* @__PURE__ */ v.jsx(Re.Provider, { value: q, children: /* @__PURE__ */ v.jsxs(ge.Provider, { value: h, children: [
|
|
879
|
+
r,
|
|
880
|
+
/* @__PURE__ */ v.jsx(ft, { ref: i, config: t, onEvent: K })
|
|
881
|
+
] }) });
|
|
882
|
+
}
|
|
883
|
+
function _t() {
|
|
884
|
+
const t = _e(Re);
|
|
885
|
+
if (!t)
|
|
886
|
+
throw new Error("useTiun must be used within a <TiunProvider>");
|
|
887
|
+
return t;
|
|
888
|
+
}
|
|
889
|
+
function mt(t, r) {
|
|
890
|
+
const i = _e(ge), l = P(r);
|
|
891
|
+
l.current = r, de(() => {
|
|
892
|
+
if (!i)
|
|
893
|
+
throw new Error("useTiunEvent must be used within a <TiunProvider>");
|
|
894
|
+
return i.on(t, (c) => l.current(c));
|
|
895
|
+
}, [i, t]);
|
|
896
|
+
}
|
|
897
|
+
export {
|
|
898
|
+
vt as TiunProvider,
|
|
899
|
+
_t as useTiun,
|
|
900
|
+
mt as useTiunEvent
|
|
901
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiun/react-native-sdk",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "tiun SDK for React Native — payments and subscriptions",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"tiun",
|
|
20
|
+
"react-native",
|
|
21
|
+
"payments",
|
|
22
|
+
"subscriptions",
|
|
23
|
+
"paywall"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "vite build",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=18",
|
|
31
|
+
"react-native": ">=0.74",
|
|
32
|
+
"react-native-webview": ">=13",
|
|
33
|
+
"react-native-secure-sign": ">=0.0.2",
|
|
34
|
+
"react-native-keychain": ">=8",
|
|
35
|
+
"react-native-inappbrowser-nitro": "^3.0.2",
|
|
36
|
+
"react-native-nitro-modules": "^0.36.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tiun/contract": "*",
|
|
40
|
+
"@tiun/types": "*",
|
|
41
|
+
"@types/react": "~19.1.0",
|
|
42
|
+
"react": "19.1.0",
|
|
43
|
+
"react-native": "0.81.5",
|
|
44
|
+
"react-native-inappbrowser-nitro": "^3.0.2",
|
|
45
|
+
"react-native-nitro-modules": "^0.36.1",
|
|
46
|
+
"react-native-keychain": "^10.0.0",
|
|
47
|
+
"react-native-secure-sign": "^0.0.2",
|
|
48
|
+
"react-native-webview": "^13.15.0",
|
|
49
|
+
"typescript": "^5.0.2",
|
|
50
|
+
"vite": "^4.4.5",
|
|
51
|
+
"vite-plugin-dts": "^3.9.1"
|
|
52
|
+
},
|
|
53
|
+
"author": "tiun",
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/tiun-app/tiun-snippet.git"
|
|
57
|
+
},
|
|
58
|
+
"bugs": {
|
|
59
|
+
"email": "support@tiun.app"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://docs.tiun.io",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
}
|
|
66
|
+
}
|