@tiquo/dom-package 1.0.0 → 1.0.1
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 +76 -6
- package/dist/index.d.mts +64 -29
- package/dist/index.d.ts +64 -29
- package/dist/index.js +274 -103
- package/dist/index.mjs +274 -103
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,8 +5,9 @@ Tiquo SDK for third-party websites. Integrate authentication, customer profiles,
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **Email OTP Authentication** - Secure passwordless login using email verification codes
|
|
8
|
-
- **
|
|
8
|
+
- **JWT-Based Tokens** - Secure access and refresh tokens with automatic refresh
|
|
9
9
|
- **Multi-Tab Sync** - Auth state automatically syncs across all browser tabs
|
|
10
|
+
- **Native App Integration** - WebView token injection for iOS/Android hybrid apps
|
|
10
11
|
- **Customer Flow Integration** - Embed authenticated customer flows with one line of code
|
|
11
12
|
- **Framework Agnostic** - Works with React, Vue, Svelte, or vanilla JavaScript
|
|
12
13
|
- **TypeScript Support** - Full type definitions included
|
|
@@ -85,8 +86,10 @@ Verify the OTP code and authenticate the user.
|
|
|
85
86
|
const result = await auth.verifyOTP('user@example.com', '123456');
|
|
86
87
|
// {
|
|
87
88
|
// success: true,
|
|
88
|
-
//
|
|
89
|
-
//
|
|
89
|
+
// accessToken: 'eyJhbGciOiJSUzI1NiJ9...',
|
|
90
|
+
// refreshToken: 'rt_xxx...',
|
|
91
|
+
// expiresIn: 3600,
|
|
92
|
+
// expiresAt: 1234567890000,
|
|
90
93
|
// isNewUser: false,
|
|
91
94
|
// hasCustomer: true
|
|
92
95
|
// }
|
|
@@ -480,18 +483,85 @@ try {
|
|
|
480
483
|
}
|
|
481
484
|
```
|
|
482
485
|
|
|
486
|
+
## Native App WebView Integration
|
|
487
|
+
|
|
488
|
+
When building hybrid apps with iOS/Android native + WebView, you can pass authentication tokens from the native app to the DOM package.
|
|
489
|
+
|
|
490
|
+
### Method 1: Config Parameters
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
const auth = new TiquoAuth({
|
|
494
|
+
publicKey: 'pk_dom_xxx',
|
|
495
|
+
accessToken: 'eyJhbGciOiJSUzI1NiJ9...', // From OAuth flow
|
|
496
|
+
refreshToken: 'rt_xxx...'
|
|
497
|
+
});
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Method 2: Global Variable (Native App Injects JS)
|
|
501
|
+
|
|
502
|
+
**iOS (Swift):**
|
|
503
|
+
```swift
|
|
504
|
+
let script = """
|
|
505
|
+
window.__TIQUO_INIT_TOKEN__ = {
|
|
506
|
+
accessToken: '\(accessToken)',
|
|
507
|
+
refreshToken: '\(refreshToken)'
|
|
508
|
+
};
|
|
509
|
+
"""
|
|
510
|
+
let userScript = WKUserScript(source: script, injectionTime: .atDocumentStart, forMainFrameOnly: true)
|
|
511
|
+
webView.configuration.userContentController.addUserScript(userScript)
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Android (Kotlin):**
|
|
515
|
+
```kotlin
|
|
516
|
+
webView.evaluateJavascript("""
|
|
517
|
+
window.__TIQUO_INIT_TOKEN__ = {
|
|
518
|
+
accessToken: '$accessToken',
|
|
519
|
+
refreshToken: '$refreshToken'
|
|
520
|
+
};
|
|
521
|
+
""".trimIndent(), null)
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Method 3: URL Fragment
|
|
525
|
+
|
|
526
|
+
```
|
|
527
|
+
https://yoursite.com/page#access_token=eyJ...&refresh_token=rt_...
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
The DOM package automatically detects and consumes tokens from all three methods. The user will be immediately authenticated in the WebView without needing to log in again.
|
|
531
|
+
|
|
532
|
+
For complete integration examples, see the [Client API documentation](https://github.com/tiquo/tiquo-dashboard/blob/main/apps/web/docs/CLIENT_API.md).
|
|
533
|
+
|
|
534
|
+
## Token Management
|
|
535
|
+
|
|
536
|
+
The SDK uses JWT tokens for authentication:
|
|
537
|
+
|
|
538
|
+
- **Access Token**: Short-lived (1 hour), used for API requests
|
|
539
|
+
- **Refresh Token**: Long-lived (30 days), used to obtain new access tokens
|
|
540
|
+
- **Automatic Refresh**: Tokens are automatically refreshed before expiration
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
// Get tokens for manual use (advanced)
|
|
544
|
+
const accessToken = auth.getAccessToken();
|
|
545
|
+
const refreshToken = auth.getRefreshToken();
|
|
546
|
+
|
|
547
|
+
// Initialize with external tokens
|
|
548
|
+
auth.initWithTokens(accessToken, refreshToken);
|
|
549
|
+
```
|
|
550
|
+
|
|
483
551
|
## Security Considerations
|
|
484
552
|
|
|
485
553
|
- The public key is safe to expose in client-side code
|
|
486
|
-
-
|
|
554
|
+
- Tokens are stored in localStorage with automatic refresh
|
|
555
|
+
- Access tokens expire after 1 hour (automatically refreshed)
|
|
556
|
+
- Refresh tokens expire after 30 days
|
|
487
557
|
- OTP codes expire after 10 minutes
|
|
488
558
|
- Failed OTP attempts are rate limited (max 5 attempts per code)
|
|
489
559
|
|
|
490
560
|
## Support
|
|
491
561
|
|
|
492
|
-
- [Documentation](https://docs.tiquo.
|
|
562
|
+
- [Documentation](https://docs.tiquo.co/dom-package)
|
|
493
563
|
- [GitHub Issues](https://github.com/tiquo/dom-package/issues)
|
|
494
|
-
- [Support Email](mailto:support@tiquo.
|
|
564
|
+
- [Support Email](mailto:support@tiquo.co)
|
|
495
565
|
|
|
496
566
|
## License
|
|
497
567
|
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Customer authentication SDK for third-party websites using Tiquo.
|
|
5
5
|
* Enables email OTP authentication without passwords.
|
|
6
|
+
* Now uses JWT tokens for authentication with automatic refresh.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
@@ -24,6 +25,22 @@
|
|
|
24
25
|
* // Logout
|
|
25
26
|
* await auth.logout();
|
|
26
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* For native app WebView integration:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Method 1: Pass token via config
|
|
32
|
+
* const auth = new TiquoAuth({
|
|
33
|
+
* publicKey: 'pk_dom_xxxxx',
|
|
34
|
+
* accessToken: 'eyJ...',
|
|
35
|
+
* refreshToken: 'rt_...'
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Method 2: Inject via global variable (native app injects JS)
|
|
39
|
+
* // window.__TIQUO_INIT_TOKEN__ = { accessToken: 'eyJ...', refreshToken: 'rt_...' };
|
|
40
|
+
*
|
|
41
|
+
* // Method 3: Pass via URL fragment
|
|
42
|
+
* // https://yoursite.com/#access_token=eyJ...&refresh_token=rt_...
|
|
43
|
+
* ```
|
|
27
44
|
*/
|
|
28
45
|
interface TiquoAuthConfig {
|
|
29
46
|
/** Public key from your Tiquo Auth DOM settings */
|
|
@@ -36,6 +53,18 @@ interface TiquoAuthConfig {
|
|
|
36
53
|
debug?: boolean;
|
|
37
54
|
/** Enable multi-tab session sync via BroadcastChannel (default: true) */
|
|
38
55
|
enableTabSync?: boolean;
|
|
56
|
+
/** Pre-authenticated access token (for WebView injection from native apps) */
|
|
57
|
+
accessToken?: string;
|
|
58
|
+
/** Pre-authenticated refresh token (for WebView injection from native apps) */
|
|
59
|
+
refreshToken?: string;
|
|
60
|
+
}
|
|
61
|
+
declare global {
|
|
62
|
+
interface Window {
|
|
63
|
+
__TIQUO_INIT_TOKEN__?: {
|
|
64
|
+
accessToken: string;
|
|
65
|
+
refreshToken?: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
39
68
|
}
|
|
40
69
|
interface TiquoUser {
|
|
41
70
|
id: string;
|
|
@@ -61,7 +90,9 @@ interface SendOTPResult {
|
|
|
61
90
|
}
|
|
62
91
|
interface VerifyOTPResult {
|
|
63
92
|
success: boolean;
|
|
64
|
-
|
|
93
|
+
accessToken: string;
|
|
94
|
+
refreshToken: string;
|
|
95
|
+
expiresIn: number;
|
|
65
96
|
expiresAt: number;
|
|
66
97
|
isNewUser: boolean;
|
|
67
98
|
hasCustomer: boolean;
|
|
@@ -181,10 +212,12 @@ declare class TiquoAuthError extends Error {
|
|
|
181
212
|
}
|
|
182
213
|
declare class TiquoAuth {
|
|
183
214
|
private config;
|
|
184
|
-
private
|
|
215
|
+
private accessToken;
|
|
216
|
+
private refreshToken;
|
|
185
217
|
private session;
|
|
186
218
|
private listeners;
|
|
187
219
|
private refreshTimer;
|
|
220
|
+
private isRefreshing;
|
|
188
221
|
private broadcastChannel;
|
|
189
222
|
private tabId;
|
|
190
223
|
private isProcessingTabSync;
|
|
@@ -251,14 +284,38 @@ declare class TiquoAuth {
|
|
|
251
284
|
onError?: (error: Error) => void;
|
|
252
285
|
}): Promise<HTMLIFrameElement>;
|
|
253
286
|
/**
|
|
254
|
-
* Get the current
|
|
287
|
+
* Get the current access token (for advanced use cases)
|
|
288
|
+
*/
|
|
289
|
+
getAccessToken(): string | null;
|
|
290
|
+
/**
|
|
291
|
+
* Get the current refresh token (for advanced use cases)
|
|
292
|
+
*/
|
|
293
|
+
getRefreshToken(): string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Initialize with external tokens (for WebView integration)
|
|
296
|
+
*/
|
|
297
|
+
initWithTokens(accessToken: string, refreshToken?: string): void;
|
|
298
|
+
/**
|
|
299
|
+
* Check for tokens injected by native apps (WebView integration)
|
|
255
300
|
*/
|
|
256
|
-
|
|
301
|
+
private checkForInjectedTokens;
|
|
257
302
|
private request;
|
|
303
|
+
/**
|
|
304
|
+
* Ensure we have a valid access token, refreshing if necessary
|
|
305
|
+
*/
|
|
306
|
+
private ensureValidToken;
|
|
307
|
+
/**
|
|
308
|
+
* Refresh the access token if it's expired or about to expire
|
|
309
|
+
*/
|
|
310
|
+
private refreshTokenIfNeeded;
|
|
311
|
+
/**
|
|
312
|
+
* Perform the actual token refresh
|
|
313
|
+
*/
|
|
314
|
+
private performTokenRefresh;
|
|
258
315
|
private refreshSession;
|
|
259
|
-
private
|
|
260
|
-
private
|
|
261
|
-
private
|
|
316
|
+
private saveTokens;
|
|
317
|
+
private restoreTokens;
|
|
318
|
+
private clearTokens;
|
|
262
319
|
private notifyListeners;
|
|
263
320
|
private scheduleRefresh;
|
|
264
321
|
private log;
|
|
@@ -274,28 +331,6 @@ declare class TiquoAuth {
|
|
|
274
331
|
/**
|
|
275
332
|
* React hook for using TiquoAuth
|
|
276
333
|
* Note: Requires a TiquoAuth instance to be passed in
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```tsx
|
|
280
|
-
* const auth = new TiquoAuth({ publicKey: 'pk_dom_xxx' });
|
|
281
|
-
*
|
|
282
|
-
* function App() {
|
|
283
|
-
* const { user, isLoading, isAuthenticated, logout } = useTiquoAuth(auth);
|
|
284
|
-
*
|
|
285
|
-
* if (isLoading) return <div>Loading...</div>;
|
|
286
|
-
*
|
|
287
|
-
* if (!isAuthenticated) {
|
|
288
|
-
* return <LoginForm auth={auth} />;
|
|
289
|
-
* }
|
|
290
|
-
*
|
|
291
|
-
* return (
|
|
292
|
-
* <div>
|
|
293
|
-
* Welcome, {user?.email}
|
|
294
|
-
* <button onClick={logout}>Logout</button>
|
|
295
|
-
* </div>
|
|
296
|
-
* );
|
|
297
|
-
* }
|
|
298
|
-
* ```
|
|
299
334
|
*/
|
|
300
335
|
declare function useTiquoAuth(auth: TiquoAuth): {
|
|
301
336
|
readonly user: TiquoUser | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Customer authentication SDK for third-party websites using Tiquo.
|
|
5
5
|
* Enables email OTP authentication without passwords.
|
|
6
|
+
* Now uses JWT tokens for authentication with automatic refresh.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
9
|
* ```typescript
|
|
@@ -24,6 +25,22 @@
|
|
|
24
25
|
* // Logout
|
|
25
26
|
* await auth.logout();
|
|
26
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* For native app WebView integration:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Method 1: Pass token via config
|
|
32
|
+
* const auth = new TiquoAuth({
|
|
33
|
+
* publicKey: 'pk_dom_xxxxx',
|
|
34
|
+
* accessToken: 'eyJ...',
|
|
35
|
+
* refreshToken: 'rt_...'
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Method 2: Inject via global variable (native app injects JS)
|
|
39
|
+
* // window.__TIQUO_INIT_TOKEN__ = { accessToken: 'eyJ...', refreshToken: 'rt_...' };
|
|
40
|
+
*
|
|
41
|
+
* // Method 3: Pass via URL fragment
|
|
42
|
+
* // https://yoursite.com/#access_token=eyJ...&refresh_token=rt_...
|
|
43
|
+
* ```
|
|
27
44
|
*/
|
|
28
45
|
interface TiquoAuthConfig {
|
|
29
46
|
/** Public key from your Tiquo Auth DOM settings */
|
|
@@ -36,6 +53,18 @@ interface TiquoAuthConfig {
|
|
|
36
53
|
debug?: boolean;
|
|
37
54
|
/** Enable multi-tab session sync via BroadcastChannel (default: true) */
|
|
38
55
|
enableTabSync?: boolean;
|
|
56
|
+
/** Pre-authenticated access token (for WebView injection from native apps) */
|
|
57
|
+
accessToken?: string;
|
|
58
|
+
/** Pre-authenticated refresh token (for WebView injection from native apps) */
|
|
59
|
+
refreshToken?: string;
|
|
60
|
+
}
|
|
61
|
+
declare global {
|
|
62
|
+
interface Window {
|
|
63
|
+
__TIQUO_INIT_TOKEN__?: {
|
|
64
|
+
accessToken: string;
|
|
65
|
+
refreshToken?: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
39
68
|
}
|
|
40
69
|
interface TiquoUser {
|
|
41
70
|
id: string;
|
|
@@ -61,7 +90,9 @@ interface SendOTPResult {
|
|
|
61
90
|
}
|
|
62
91
|
interface VerifyOTPResult {
|
|
63
92
|
success: boolean;
|
|
64
|
-
|
|
93
|
+
accessToken: string;
|
|
94
|
+
refreshToken: string;
|
|
95
|
+
expiresIn: number;
|
|
65
96
|
expiresAt: number;
|
|
66
97
|
isNewUser: boolean;
|
|
67
98
|
hasCustomer: boolean;
|
|
@@ -181,10 +212,12 @@ declare class TiquoAuthError extends Error {
|
|
|
181
212
|
}
|
|
182
213
|
declare class TiquoAuth {
|
|
183
214
|
private config;
|
|
184
|
-
private
|
|
215
|
+
private accessToken;
|
|
216
|
+
private refreshToken;
|
|
185
217
|
private session;
|
|
186
218
|
private listeners;
|
|
187
219
|
private refreshTimer;
|
|
220
|
+
private isRefreshing;
|
|
188
221
|
private broadcastChannel;
|
|
189
222
|
private tabId;
|
|
190
223
|
private isProcessingTabSync;
|
|
@@ -251,14 +284,38 @@ declare class TiquoAuth {
|
|
|
251
284
|
onError?: (error: Error) => void;
|
|
252
285
|
}): Promise<HTMLIFrameElement>;
|
|
253
286
|
/**
|
|
254
|
-
* Get the current
|
|
287
|
+
* Get the current access token (for advanced use cases)
|
|
288
|
+
*/
|
|
289
|
+
getAccessToken(): string | null;
|
|
290
|
+
/**
|
|
291
|
+
* Get the current refresh token (for advanced use cases)
|
|
292
|
+
*/
|
|
293
|
+
getRefreshToken(): string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Initialize with external tokens (for WebView integration)
|
|
296
|
+
*/
|
|
297
|
+
initWithTokens(accessToken: string, refreshToken?: string): void;
|
|
298
|
+
/**
|
|
299
|
+
* Check for tokens injected by native apps (WebView integration)
|
|
255
300
|
*/
|
|
256
|
-
|
|
301
|
+
private checkForInjectedTokens;
|
|
257
302
|
private request;
|
|
303
|
+
/**
|
|
304
|
+
* Ensure we have a valid access token, refreshing if necessary
|
|
305
|
+
*/
|
|
306
|
+
private ensureValidToken;
|
|
307
|
+
/**
|
|
308
|
+
* Refresh the access token if it's expired or about to expire
|
|
309
|
+
*/
|
|
310
|
+
private refreshTokenIfNeeded;
|
|
311
|
+
/**
|
|
312
|
+
* Perform the actual token refresh
|
|
313
|
+
*/
|
|
314
|
+
private performTokenRefresh;
|
|
258
315
|
private refreshSession;
|
|
259
|
-
private
|
|
260
|
-
private
|
|
261
|
-
private
|
|
316
|
+
private saveTokens;
|
|
317
|
+
private restoreTokens;
|
|
318
|
+
private clearTokens;
|
|
262
319
|
private notifyListeners;
|
|
263
320
|
private scheduleRefresh;
|
|
264
321
|
private log;
|
|
@@ -274,28 +331,6 @@ declare class TiquoAuth {
|
|
|
274
331
|
/**
|
|
275
332
|
* React hook for using TiquoAuth
|
|
276
333
|
* Note: Requires a TiquoAuth instance to be passed in
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```tsx
|
|
280
|
-
* const auth = new TiquoAuth({ publicKey: 'pk_dom_xxx' });
|
|
281
|
-
*
|
|
282
|
-
* function App() {
|
|
283
|
-
* const { user, isLoading, isAuthenticated, logout } = useTiquoAuth(auth);
|
|
284
|
-
*
|
|
285
|
-
* if (isLoading) return <div>Loading...</div>;
|
|
286
|
-
*
|
|
287
|
-
* if (!isAuthenticated) {
|
|
288
|
-
* return <LoginForm auth={auth} />;
|
|
289
|
-
* }
|
|
290
|
-
*
|
|
291
|
-
* return (
|
|
292
|
-
* <div>
|
|
293
|
-
* Welcome, {user?.email}
|
|
294
|
-
* <button onClick={logout}>Logout</button>
|
|
295
|
-
* </div>
|
|
296
|
-
* );
|
|
297
|
-
* }
|
|
298
|
-
* ```
|
|
299
334
|
*/
|
|
300
335
|
declare function useTiquoAuth(auth: TiquoAuth): {
|
|
301
336
|
readonly user: TiquoUser | null;
|