@glideidentity/web-client-sdk 4.4.10 → 5.0.1-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/README.md +167 -19
- package/dist/adapters/angular/index.js +0 -1
- package/dist/adapters/angular/phone-auth.service.d.ts +0 -18
- package/dist/adapters/angular/phone-auth.service.js +0 -26
- package/dist/adapters/react/index.d.ts +1 -1
- package/dist/adapters/react/index.js +0 -3
- package/dist/adapters/react/useClient.js +0 -1
- package/dist/adapters/react/usePhoneAuth.js +1 -16
- package/dist/adapters/vanilla/client.js +0 -1
- package/dist/adapters/vanilla/index.js +0 -1
- package/dist/adapters/vanilla/phone-auth.js +0 -31
- package/dist/adapters/vue/index.d.ts +1 -1
- package/dist/adapters/vue/index.js +0 -4
- package/dist/adapters/vue/useClient.js +0 -5
- package/dist/adapters/vue/usePhoneAuth.js +1 -20
- package/dist/browser/web-client-sdk.min.js +1 -1
- package/dist/browser/web-client-sdk.min.js.LICENSE.txt +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +0 -6
- package/dist/core/client.js +0 -12
- package/dist/core/logger.js +1 -81
- package/dist/core/phone-auth/api-types.d.ts +0 -13
- package/dist/core/phone-auth/api-types.js +0 -83
- package/dist/core/phone-auth/client.js +27 -374
- package/dist/core/phone-auth/error-utils.js +1 -83
- package/dist/core/phone-auth/index.d.ts +1 -1
- package/dist/core/phone-auth/index.js +1 -3
- package/dist/core/phone-auth/status-types.d.ts +0 -78
- package/dist/core/phone-auth/status-types.js +0 -17
- package/dist/core/phone-auth/strategies/desktop.js +8 -126
- package/dist/core/phone-auth/strategies/index.d.ts +0 -4
- package/dist/core/phone-auth/strategies/index.js +0 -4
- package/dist/core/phone-auth/strategies/link.js +10 -88
- package/dist/core/phone-auth/strategies/ts43.d.ts +0 -19
- package/dist/core/phone-auth/strategies/ts43.js +2 -33
- package/dist/core/phone-auth/strategies/types.js +0 -4
- package/dist/core/phone-auth/type-guards.js +0 -131
- package/dist/core/phone-auth/types.js +0 -32
- package/dist/core/phone-auth/ui/mobile-debug-console.js +2 -28
- package/dist/core/phone-auth/ui/modal.d.ts +33 -55
- package/dist/core/phone-auth/ui/modal.js +889 -422
- package/dist/core/phone-auth/validation-utils.d.ts +0 -13
- package/dist/core/phone-auth/validation-utils.js +2 -81
- package/dist/core/version.js +1 -2
- package/dist/esm/adapters/angular/index.js +0 -1
- package/dist/esm/adapters/angular/phone-auth.service.d.ts +0 -18
- package/dist/esm/adapters/angular/phone-auth.service.js +0 -26
- package/dist/esm/adapters/react/index.d.ts +1 -1
- package/dist/esm/adapters/react/index.js +0 -3
- package/dist/esm/adapters/react/useClient.js +0 -1
- package/dist/esm/adapters/react/usePhoneAuth.js +1 -16
- package/dist/esm/adapters/vanilla/client.js +0 -1
- package/dist/esm/adapters/vanilla/index.js +0 -1
- package/dist/esm/adapters/vanilla/phone-auth.d.ts +0 -24
- package/dist/esm/adapters/vanilla/phone-auth.js +0 -31
- package/dist/esm/adapters/vue/index.d.ts +1 -1
- package/dist/esm/adapters/vue/index.js +0 -4
- package/dist/esm/adapters/vue/useClient.js +0 -5
- package/dist/esm/adapters/vue/usePhoneAuth.js +1 -20
- package/dist/esm/browser.d.ts +1 -1
- package/dist/esm/browser.js +0 -6
- package/dist/esm/core/client.d.ts +0 -10
- package/dist/esm/core/client.js +0 -12
- package/dist/esm/core/logger.d.ts +0 -53
- package/dist/esm/core/logger.js +1 -81
- package/dist/esm/core/phone-auth/api-types.d.ts +0 -328
- package/dist/esm/core/phone-auth/api-types.js +0 -83
- package/dist/esm/core/phone-auth/client.d.ts +0 -144
- package/dist/esm/core/phone-auth/client.js +28 -375
- package/dist/esm/core/phone-auth/error-utils.d.ts +0 -29
- package/dist/esm/core/phone-auth/error-utils.js +1 -83
- package/dist/esm/core/phone-auth/index.d.ts +1 -1
- package/dist/esm/core/phone-auth/index.js +2 -4
- package/dist/esm/core/phone-auth/status-types.d.ts +0 -78
- package/dist/esm/core/phone-auth/status-types.js +0 -17
- package/dist/esm/core/phone-auth/strategies/desktop.d.ts +0 -63
- package/dist/esm/core/phone-auth/strategies/desktop.js +8 -126
- package/dist/esm/core/phone-auth/strategies/index.d.ts +0 -4
- package/dist/esm/core/phone-auth/strategies/index.js +0 -4
- package/dist/esm/core/phone-auth/strategies/link.d.ts +0 -48
- package/dist/esm/core/phone-auth/strategies/link.js +10 -88
- package/dist/esm/core/phone-auth/strategies/ts43.d.ts +0 -19
- package/dist/esm/core/phone-auth/strategies/ts43.js +2 -33
- package/dist/esm/core/phone-auth/strategies/types.d.ts +0 -13
- package/dist/esm/core/phone-auth/strategies/types.js +0 -4
- package/dist/esm/core/phone-auth/type-guards.d.ts +0 -128
- package/dist/esm/core/phone-auth/type-guards.js +0 -131
- package/dist/esm/core/phone-auth/types.d.ts +0 -108
- package/dist/esm/core/phone-auth/types.js +0 -32
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.d.ts +0 -4
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.js +2 -28
- package/dist/esm/core/phone-auth/ui/modal.d.ts +27 -68
- package/dist/esm/core/phone-auth/ui/modal.js +889 -422
- package/dist/esm/core/phone-auth/validation-utils.d.ts +0 -44
- package/dist/esm/core/phone-auth/validation-utils.js +2 -80
- package/dist/esm/core/types.d.ts +0 -35
- package/dist/esm/core/version.js +1 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,9 +14,19 @@ The official web SDK for integrating Glide's carrier-grade phone verification in
|
|
|
14
14
|
- 🛡️ **Type Safe**: Full TypeScript support with type guards and IntelliSense
|
|
15
15
|
- 🎯 **Developer Friendly**: Clear error messages and browser compatibility checks
|
|
16
16
|
|
|
17
|
-
## What's New in
|
|
18
|
-
|
|
19
|
-
###
|
|
17
|
+
## What's New in v5.0
|
|
18
|
+
|
|
19
|
+
### 🎨 Redesigned Modal UI
|
|
20
|
+
- **Glass Morphism Design**: Modern frosted glass aesthetic with blur effects
|
|
21
|
+
- **Multiple View Modes**: Choose between `toggle`, `dual`, or `pre-step` layouts
|
|
22
|
+
- **Theme Support**: `dark`, `light`, or `auto` (follows system preference)
|
|
23
|
+
- **OS Icons**: Apple and Android icons in toggle and dual mode
|
|
24
|
+
- **Smooth Animations**: Fade-in/scale transitions and sliding toggle switch
|
|
25
|
+
- **Help Interaction**: Expandable help panel with smooth slide-out animation
|
|
26
|
+
- **Body Scroll Lock**: Background page no longer scrolls when modal is open
|
|
27
|
+
- **Improved Accessibility**: Keyboard support (Escape to close), proper ARIA labels
|
|
28
|
+
|
|
29
|
+
### 🎉 Enhanced Control & Better DX (v4.4)
|
|
20
30
|
- **Extended Mode**: More control with `executionMode: 'extended'` for granular authentication flow
|
|
21
31
|
- **Prevent Default UI**: Use `preventDefaultUI: true` to disable all SDK modals
|
|
22
32
|
- **Type Guards**: Helper functions for type-safe result handling
|
|
@@ -29,13 +39,16 @@ The official web SDK for integrating Glide's carrier-grade phone verification in
|
|
|
29
39
|
## Table of Contents
|
|
30
40
|
|
|
31
41
|
- [Installation](#installation)
|
|
42
|
+
- [Development](#development)
|
|
32
43
|
- [Quick Start](#quick-start)
|
|
44
|
+
- [Modal Customization](#modal-customization)
|
|
33
45
|
- [Extended Mode - Advanced Control](#extended-mode---advanced-control)
|
|
34
46
|
- [Authentication Strategies](#authentication-strategies)
|
|
35
47
|
- [Framework Examples](#framework-examples)
|
|
36
48
|
- [Error Handling](#error-handling)
|
|
37
49
|
- [Browser Support](#browser-support)
|
|
38
50
|
- [API Reference](#api-reference)
|
|
51
|
+
- [Documentation](#documentation)
|
|
39
52
|
|
|
40
53
|
## Installation
|
|
41
54
|
|
|
@@ -43,6 +56,34 @@ The official web SDK for integrating Glide's carrier-grade phone verification in
|
|
|
43
56
|
npm install @glideidentity/web-client-sdk
|
|
44
57
|
```
|
|
45
58
|
|
|
59
|
+
## Development
|
|
60
|
+
|
|
61
|
+
### Using Docker (Recommended)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Build the SDK
|
|
65
|
+
docker compose run --rm build
|
|
66
|
+
|
|
67
|
+
# Run tests
|
|
68
|
+
docker compose run --rm test
|
|
69
|
+
|
|
70
|
+
# Interactive development shell
|
|
71
|
+
docker compose run --rm dev
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Without Docker
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Install dependencies
|
|
78
|
+
npm install
|
|
79
|
+
|
|
80
|
+
# Build the SDK
|
|
81
|
+
npm run build
|
|
82
|
+
|
|
83
|
+
# Run tests
|
|
84
|
+
npm test
|
|
85
|
+
```
|
|
86
|
+
|
|
46
87
|
## Quick Start
|
|
47
88
|
|
|
48
89
|
### React Example
|
|
@@ -69,7 +110,7 @@ function PhoneVerification() {
|
|
|
69
110
|
const credential = await phoneAuth.invokeSecurePrompt(prepareResult);
|
|
70
111
|
|
|
71
112
|
// Process the credential
|
|
72
|
-
const result = await phoneAuth.
|
|
113
|
+
const result = await phoneAuth.getPhoneNumber(
|
|
73
114
|
credential,
|
|
74
115
|
prepareResult.session
|
|
75
116
|
);
|
|
@@ -92,7 +133,7 @@ function PhoneVerification() {
|
|
|
92
133
|
const credential = await phoneAuth.invokeSecurePrompt(prepareResult);
|
|
93
134
|
|
|
94
135
|
// Verify the number
|
|
95
|
-
const result = await phoneAuth.
|
|
136
|
+
const result = await phoneAuth.verifyPhoneNumber(
|
|
96
137
|
credential,
|
|
97
138
|
prepareResult.session
|
|
98
139
|
);
|
|
@@ -116,6 +157,84 @@ function PhoneVerification() {
|
|
|
116
157
|
}
|
|
117
158
|
```
|
|
118
159
|
|
|
160
|
+
## Modal Customization
|
|
161
|
+
|
|
162
|
+
The SDK provides a built-in modal for QR code display with extensive customization options.
|
|
163
|
+
|
|
164
|
+
### View Modes
|
|
165
|
+
|
|
166
|
+
Choose how the QR code is displayed to users:
|
|
167
|
+
|
|
168
|
+
| Mode | Description | Best For |
|
|
169
|
+
|------|-------------|----------|
|
|
170
|
+
| `toggle` | Single QR with iOS/Android sliding toggle switch | Default, clean UI |
|
|
171
|
+
| `dual` | Side-by-side QR codes for both platforms | When users might not know their OS |
|
|
172
|
+
| `pre-step` | OS selection screen before showing QR | Guided experience |
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
const credential = await phoneAuth.invokeSecurePrompt(prepareResult, {
|
|
176
|
+
modalOptions: {
|
|
177
|
+
viewMode: 'dual' // 'toggle' | 'dual' | 'pre-step'
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Theme Options
|
|
183
|
+
|
|
184
|
+
Control the modal's appearance:
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
const credential = await phoneAuth.invokeSecurePrompt(prepareResult, {
|
|
188
|
+
modalOptions: {
|
|
189
|
+
theme: 'auto', // 'dark' | 'light' | 'auto' (follows system preference)
|
|
190
|
+
title: 'Scan to Verify',
|
|
191
|
+
showCloseButton: true,
|
|
192
|
+
closeOnBackdrop: true,
|
|
193
|
+
closeOnEscape: true
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Full Modal Options
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
modalOptions: {
|
|
202
|
+
// View mode
|
|
203
|
+
viewMode?: 'toggle' | 'dual' | 'pre-step'; // Default: 'toggle'
|
|
204
|
+
|
|
205
|
+
// Theme
|
|
206
|
+
theme?: 'dark' | 'light' | 'auto'; // Default: 'auto'
|
|
207
|
+
|
|
208
|
+
// Content
|
|
209
|
+
title?: string; // Modal title
|
|
210
|
+
|
|
211
|
+
// Behavior
|
|
212
|
+
showCloseButton?: boolean; // Show X button (default: true)
|
|
213
|
+
closeOnBackdrop?: boolean; // Close when clicking outside (default: true)
|
|
214
|
+
closeOnEscape?: boolean; // Close on Escape key (default: true)
|
|
215
|
+
|
|
216
|
+
// Styling
|
|
217
|
+
className?: string; // Custom CSS class for modal
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### View Mode Examples
|
|
222
|
+
|
|
223
|
+
**Toggle Mode** (default) - Clean single QR with platform switcher:
|
|
224
|
+
```javascript
|
|
225
|
+
modalOptions: { viewMode: 'toggle' }
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Dual Mode** - Both QR codes visible at once:
|
|
229
|
+
```javascript
|
|
230
|
+
modalOptions: { viewMode: 'dual' }
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Pre-step Mode** - User selects platform first:
|
|
234
|
+
```javascript
|
|
235
|
+
modalOptions: { viewMode: 'pre-step' }
|
|
236
|
+
```
|
|
237
|
+
|
|
119
238
|
## Extended Mode - Advanced Control
|
|
120
239
|
|
|
121
240
|
The SDK supports an **Extended Mode** that provides granular control over the authentication flow. This mode returns an `ExtendedResponse` object with additional methods and data for custom implementations.
|
|
@@ -307,7 +426,7 @@ if (isExtendedResponse(result)) {
|
|
|
307
426
|
}
|
|
308
427
|
} else {
|
|
309
428
|
// Standard mode - got credential directly
|
|
310
|
-
const verified = await phoneAuth.
|
|
429
|
+
const verified = await phoneAuth.verifyPhoneNumber(result, session);
|
|
311
430
|
}
|
|
312
431
|
```
|
|
313
432
|
|
|
@@ -348,7 +467,7 @@ async function verifyPhone() {
|
|
|
348
467
|
});
|
|
349
468
|
|
|
350
469
|
const credential = await phoneAuth.invokeSecurePrompt(prepared);
|
|
351
|
-
result.value = await phoneAuth.
|
|
470
|
+
result.value = await phoneAuth.verifyPhoneNumber(
|
|
352
471
|
credential,
|
|
353
472
|
prepared.session
|
|
354
473
|
);
|
|
@@ -397,7 +516,7 @@ export class PhoneVerifyComponent {
|
|
|
397
516
|
});
|
|
398
517
|
|
|
399
518
|
const credential = await this.phoneAuth.invokeSecurePrompt(prepared);
|
|
400
|
-
this.result = await this.phoneAuth.
|
|
519
|
+
this.result = await this.phoneAuth.verifyPhoneNumber(
|
|
401
520
|
credential,
|
|
402
521
|
prepared.session
|
|
403
522
|
);
|
|
@@ -430,7 +549,7 @@ async function getPhoneNumber() {
|
|
|
430
549
|
|
|
431
550
|
const credential = await client.invokeSecurePrompt(prepareResult);
|
|
432
551
|
|
|
433
|
-
const result = await client.
|
|
552
|
+
const result = await client.getPhoneNumber(
|
|
434
553
|
credential,
|
|
435
554
|
prepareResult.session
|
|
436
555
|
);
|
|
@@ -546,11 +665,22 @@ interface InvokeOptions {
|
|
|
546
665
|
|
|
547
666
|
// UI customization (when preventDefaultUI is false)
|
|
548
667
|
modalOptions?: {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
668
|
+
// View mode
|
|
669
|
+
viewMode?: 'toggle' | 'dual' | 'pre-step'; // Default: 'toggle'
|
|
670
|
+
|
|
671
|
+
// Theme
|
|
672
|
+
theme?: 'dark' | 'light' | 'auto'; // Default: 'auto' (system preference)
|
|
673
|
+
|
|
674
|
+
// Content
|
|
675
|
+
title?: string; // Modal title text
|
|
676
|
+
|
|
677
|
+
// Behavior
|
|
678
|
+
showCloseButton?: boolean; // Show X button (default: true)
|
|
679
|
+
closeOnBackdrop?: boolean; // Close on backdrop click (default: true)
|
|
680
|
+
closeOnEscape?: boolean; // Close on Escape key (default: true)
|
|
681
|
+
|
|
682
|
+
// Styling
|
|
683
|
+
className?: string; // Custom CSS class
|
|
554
684
|
};
|
|
555
685
|
|
|
556
686
|
// Callbacks
|
|
@@ -567,19 +697,18 @@ interface InvokeOptions {
|
|
|
567
697
|
### Methods
|
|
568
698
|
|
|
569
699
|
```typescript
|
|
570
|
-
// Core methods
|
|
700
|
+
// Core methods (granular control)
|
|
571
701
|
preparePhoneRequest(options: PrepareRequest): Promise<PrepareResponse>
|
|
572
702
|
invokeSecurePrompt(response: PrepareResponse, options?: InvokeOptions): Promise<any>
|
|
573
|
-
|
|
574
|
-
|
|
703
|
+
getPhoneNumber(credential: any, session: SessionInfo): Promise<GetPhoneNumberResponse>
|
|
704
|
+
verifyPhoneNumber(credential: any, session: SessionInfo): Promise<VerifyPhoneNumberResponse>
|
|
575
705
|
|
|
576
|
-
// High-level convenience methods
|
|
706
|
+
// High-level convenience methods (full flow)
|
|
577
707
|
getPhoneNumberComplete(): Promise<GetPhoneNumberResponse>
|
|
578
708
|
verifyPhoneNumberComplete(phoneNumber: string): Promise<VerifyPhoneNumberResponse>
|
|
579
709
|
|
|
580
710
|
// Utility methods
|
|
581
711
|
isSupported(): boolean
|
|
582
|
-
cancelCurrentRequest(): void
|
|
583
712
|
```
|
|
584
713
|
|
|
585
714
|
### Response Types
|
|
@@ -609,6 +738,25 @@ interface VerifyPhoneNumberResponse {
|
|
|
609
738
|
}
|
|
610
739
|
```
|
|
611
740
|
|
|
741
|
+
## Documentation
|
|
742
|
+
|
|
743
|
+
For detailed documentation, see the [docs](./docs) folder:
|
|
744
|
+
|
|
745
|
+
| Document | Description |
|
|
746
|
+
|----------|-------------|
|
|
747
|
+
| [Architecture](./docs/architecture.md) | SDK architecture and design principles |
|
|
748
|
+
| [Phone Authentication](./docs/phone-auth.md) | Complete phone auth usage guide |
|
|
749
|
+
| [Desktop Authentication](./docs/desktop-auth.md) | QR code authentication flow |
|
|
750
|
+
| [Dual Platform QR](./docs/dual-platform-qr.md) | iOS/Android specific QR codes |
|
|
751
|
+
| [Error Handling](./docs/error-handling.md) | Error codes and handling strategies |
|
|
752
|
+
| [Trigger Pattern](./docs/trigger-pattern.md) | Consistent trigger API across strategies |
|
|
753
|
+
| [Implementation Notes](./docs/implementation-notes.md) | Technical implementation details |
|
|
754
|
+
| [Local Development](./docs/local-development.md) | Testing the SDK locally |
|
|
755
|
+
| [TS43 Data Flow](./docs/TS43_DATA_FLOW.md) | Digital Credentials API details |
|
|
756
|
+
| [Type Hierarchy](./docs/TYPE_HIERARCHY.md) | TypeScript type system |
|
|
757
|
+
| [Naming Conventions](./docs/NAMING_CONVENTIONS.md) | API naming standards |
|
|
758
|
+
| [Security Checklist](./docs/security-checklist.md) | NPM publishing security |
|
|
759
|
+
|
|
612
760
|
## Support
|
|
613
761
|
|
|
614
762
|
- [Documentation](https://docs.glideidentity.com)
|
|
@@ -5,7 +5,6 @@ var client_service_1 = require("./client.service");
|
|
|
5
5
|
Object.defineProperty(exports, "ClientService", { enumerable: true, get: function () { return client_service_1.ClientService; } });
|
|
6
6
|
var phone_auth_service_1 = require("./phone-auth.service");
|
|
7
7
|
Object.defineProperty(exports, "PhoneAuthService", { enumerable: true, get: function () { return phone_auth_service_1.PhoneAuthService; } });
|
|
8
|
-
// Export error utilities
|
|
9
8
|
var phone_auth_1 = require("../../core/phone-auth");
|
|
10
9
|
Object.defineProperty(exports, "PhoneAuthErrorCode", { enumerable: true, get: function () { return phone_auth_1.PhoneAuthErrorCode; } });
|
|
11
10
|
Object.defineProperty(exports, "isPhoneAuthError", { enumerable: true, get: function () { return phone_auth_1.isPhoneAuthError; } });
|
|
@@ -11,28 +11,10 @@ export declare class PhoneAuthService {
|
|
|
11
11
|
result$: Observable<PhoneAuthResult | null>;
|
|
12
12
|
currentStep$: Observable<AuthStep>;
|
|
13
13
|
constructor();
|
|
14
|
-
/**
|
|
15
|
-
* Configure the phone auth client
|
|
16
|
-
*/
|
|
17
14
|
configure(config: AuthConfig): void;
|
|
18
|
-
/**
|
|
19
|
-
* Check if browser supports secure phone authentication
|
|
20
|
-
*/
|
|
21
15
|
isSupported(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Verify phone number
|
|
24
|
-
*/
|
|
25
16
|
verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
|
|
26
|
-
/**
|
|
27
|
-
* Get phone number
|
|
28
|
-
*/
|
|
29
17
|
getPhoneNumber(options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
30
|
-
/**
|
|
31
|
-
* Verify specific phone number
|
|
32
|
-
*/
|
|
33
18
|
verifyPhoneNumber(phoneNumber: string, options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Reset state
|
|
36
|
-
*/
|
|
37
19
|
reset(): void;
|
|
38
20
|
}
|
|
@@ -24,33 +24,22 @@ const phone_auth_1 = require("../../core/phone-auth");
|
|
|
24
24
|
const rxjs_1 = require("rxjs");
|
|
25
25
|
let PhoneAuthService = class PhoneAuthService {
|
|
26
26
|
constructor() {
|
|
27
|
-
// State subjects
|
|
28
27
|
this.isLoadingSubject = new rxjs_1.BehaviorSubject(false);
|
|
29
28
|
this.errorSubject = new rxjs_1.BehaviorSubject(null);
|
|
30
29
|
this.resultSubject = new rxjs_1.BehaviorSubject(null);
|
|
31
30
|
this.currentStepSubject = new rxjs_1.BehaviorSubject('idle');
|
|
32
|
-
// Public observables
|
|
33
31
|
this.isLoading$ = this.isLoadingSubject.asObservable();
|
|
34
32
|
this.error$ = this.errorSubject.asObservable();
|
|
35
33
|
this.result$ = this.resultSubject.asObservable();
|
|
36
34
|
this.currentStep$ = this.currentStepSubject.asObservable();
|
|
37
35
|
this.client = new phone_auth_1.PhoneAuthClient();
|
|
38
36
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Configure the phone auth client
|
|
41
|
-
*/
|
|
42
37
|
configure(config) {
|
|
43
38
|
this.client = new phone_auth_1.PhoneAuthClient(config);
|
|
44
39
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Check if browser supports secure phone authentication
|
|
47
|
-
*/
|
|
48
40
|
isSupported() {
|
|
49
41
|
return this.client.isSupported();
|
|
50
42
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Verify phone number
|
|
53
|
-
*/
|
|
54
43
|
verify(options) {
|
|
55
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
45
|
this.isLoadingSubject.next(true);
|
|
@@ -58,19 +47,14 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
58
47
|
this.resultSubject.next(null);
|
|
59
48
|
this.currentStepSubject.next('requesting');
|
|
60
49
|
try {
|
|
61
|
-
// Step 1: Prepare request
|
|
62
50
|
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
63
|
-
// Step 2: Show authenticating state
|
|
64
51
|
this.currentStepSubject.next('authenticating');
|
|
65
52
|
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
66
|
-
// Step 3: Process response through appropriate endpoint
|
|
67
53
|
this.currentStepSubject.next('processing');
|
|
68
|
-
// Cast to credential type - adapters never use headless mode
|
|
69
54
|
const credential = credentialResponse;
|
|
70
55
|
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
71
56
|
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
72
57
|
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
73
|
-
// Create final result
|
|
74
58
|
const isVerifyResponse = 'verified' in processedResult;
|
|
75
59
|
const result = processedResult;
|
|
76
60
|
this.resultSubject.next(result);
|
|
@@ -78,7 +62,6 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
78
62
|
return result;
|
|
79
63
|
}
|
|
80
64
|
catch (error) {
|
|
81
|
-
// Enhance error with context
|
|
82
65
|
const authError = error;
|
|
83
66
|
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
84
67
|
useCase: options.use_case,
|
|
@@ -95,25 +78,16 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
95
78
|
}
|
|
96
79
|
});
|
|
97
80
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Get phone number
|
|
100
|
-
*/
|
|
101
81
|
getPhoneNumber(options) {
|
|
102
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
83
|
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
104
84
|
});
|
|
105
85
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Verify specific phone number
|
|
108
|
-
*/
|
|
109
86
|
verifyPhoneNumber(phoneNumber, options) {
|
|
110
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
88
|
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
112
89
|
});
|
|
113
90
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Reset state
|
|
116
|
-
*/
|
|
117
91
|
reset() {
|
|
118
92
|
this.isLoadingSubject.next(false);
|
|
119
93
|
this.errorSubject.next(null);
|
|
@@ -4,6 +4,6 @@ export type { UsePhoneAuthOptions } from './usePhoneAuth';
|
|
|
4
4
|
export type { ClientConfig, ClientResponse, RequestOptions } from '../../core/types';
|
|
5
5
|
export type { AuthConfig as PhoneAuthConfig, PhoneAuthOptions, PhoneAuthResult, AuthError, AuthStep } from '../../core/phone-auth';
|
|
6
6
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
7
|
-
export type { PhoneAuthCallbacks, PLMN, SessionInfo, PrepareRequest, PrepareResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, SecureCredentialRequest, SecureCredentialResponse, DigitalCredential, TS43Data, LinkData, ClientInfo,
|
|
7
|
+
export type { PhoneAuthCallbacks, PLMN, SessionInfo, PrepareRequest, PrepareResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, SecureCredentialRequest, SecureCredentialResponse, DigitalCredential, TS43Data, LinkData, ClientInfo, BrowserErrorType, BrowserErrorCodeType, BrowserNameType } from '../../core/phone-auth/types';
|
|
8
8
|
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
9
9
|
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
@@ -5,7 +5,6 @@ var usePhoneAuth_1 = require("./usePhoneAuth");
|
|
|
5
5
|
Object.defineProperty(exports, "usePhoneAuth", { enumerable: true, get: function () { return usePhoneAuth_1.usePhoneAuth; } });
|
|
6
6
|
var useClient_1 = require("./useClient");
|
|
7
7
|
Object.defineProperty(exports, "useClient", { enumerable: true, get: function () { return useClient_1.useClient; } });
|
|
8
|
-
// Export error utilities
|
|
9
8
|
var phone_auth_1 = require("../../core/phone-auth");
|
|
10
9
|
Object.defineProperty(exports, "PhoneAuthErrorCode", { enumerable: true, get: function () { return phone_auth_1.PhoneAuthErrorCode; } });
|
|
11
10
|
Object.defineProperty(exports, "isPhoneAuthError", { enumerable: true, get: function () { return phone_auth_1.isPhoneAuthError; } });
|
|
@@ -16,13 +15,11 @@ Object.defineProperty(exports, "getRetryDelay", { enumerable: true, get: functio
|
|
|
16
15
|
Object.defineProperty(exports, "isRetryableError", { enumerable: true, get: function () { return phone_auth_1.isRetryableError; } });
|
|
17
16
|
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return phone_auth_1.serializeError; } });
|
|
18
17
|
Object.defineProperty(exports, "createErrorBreadcrumb", { enumerable: true, get: function () { return phone_auth_1.createErrorBreadcrumb; } });
|
|
19
|
-
// Export constants for use case and strategy
|
|
20
18
|
var types_1 = require("../../core/phone-auth/types");
|
|
21
19
|
Object.defineProperty(exports, "UseCase", { enumerable: true, get: function () { return types_1.USE_CASE; } });
|
|
22
20
|
Object.defineProperty(exports, "AuthenticationStrategy", { enumerable: true, get: function () { return types_1.AUTHENTICATION_STRATEGY; } });
|
|
23
21
|
Object.defineProperty(exports, "BrowserError", { enumerable: true, get: function () { return types_1.BrowserError; } });
|
|
24
22
|
Object.defineProperty(exports, "BrowserErrorCode", { enumerable: true, get: function () { return types_1.BrowserErrorCode; } });
|
|
25
23
|
Object.defineProperty(exports, "BrowserName", { enumerable: true, get: function () { return types_1.BrowserName; } });
|
|
26
|
-
// Export the PhoneAuthClient class for direct use
|
|
27
24
|
var phone_auth_2 = require("../../core/phone-auth");
|
|
28
25
|
Object.defineProperty(exports, "PhoneAuthClient", { enumerable: true, get: function () { return phone_auth_2.PhoneAuthClient; } });
|
|
@@ -31,7 +31,6 @@ function useClient(config) {
|
|
|
31
31
|
};
|
|
32
32
|
}, []);
|
|
33
33
|
const authenticate = (authUrl, options) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
// Legacy authentication removed - use setToken directly
|
|
35
34
|
const error = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
36
35
|
setError(error);
|
|
37
36
|
setLoading(false);
|
|
@@ -18,13 +18,8 @@ function usePhoneAuth(config = {}) {
|
|
|
18
18
|
const [result, setResult] = (0, react_1.useState)(null);
|
|
19
19
|
const [currentStep, setCurrentStep] = (0, react_1.useState)('idle');
|
|
20
20
|
const lastRequestRef = (0, react_1.useRef)(null);
|
|
21
|
-
|
|
22
|
-
const client = (0, react_1.useMemo)(() => new phone_auth_1.PhoneAuthClient(Object.assign(Object.assign({}, config), {
|
|
23
|
-
// Pass through callbacks if provided
|
|
24
|
-
onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt })), [JSON.stringify(config)]);
|
|
25
|
-
// Check browser support
|
|
21
|
+
const client = (0, react_1.useMemo)(() => new phone_auth_1.PhoneAuthClient(Object.assign(Object.assign({}, config), { onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt })), [JSON.stringify(config)]);
|
|
26
22
|
const isSupported = (0, react_1.useMemo)(() => client.isSupported(), [client]);
|
|
27
|
-
// Verify method with silent retry support
|
|
28
23
|
const verify = (0, react_1.useCallback)((options) => __awaiter(this, void 0, void 0, function* () {
|
|
29
24
|
setIsLoading(true);
|
|
30
25
|
setError(null);
|
|
@@ -32,14 +27,12 @@ function usePhoneAuth(config = {}) {
|
|
|
32
27
|
setCurrentStep('requesting');
|
|
33
28
|
lastRequestRef.current = options;
|
|
34
29
|
try {
|
|
35
|
-
// Use the client's verify method which includes retry logic
|
|
36
30
|
const verificationResult = yield client.verify(options);
|
|
37
31
|
setResult(verificationResult);
|
|
38
32
|
setCurrentStep('complete');
|
|
39
33
|
return verificationResult;
|
|
40
34
|
}
|
|
41
35
|
catch (err) {
|
|
42
|
-
// Error is only set after all retries are exhausted
|
|
43
36
|
const authError = err;
|
|
44
37
|
setError(authError);
|
|
45
38
|
setCurrentStep('idle');
|
|
@@ -49,47 +42,39 @@ function usePhoneAuth(config = {}) {
|
|
|
49
42
|
setIsLoading(false);
|
|
50
43
|
}
|
|
51
44
|
}), [client]);
|
|
52
|
-
// Manual retry method
|
|
53
45
|
const retryLastRequest = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
54
46
|
if (!lastRequestRef.current) {
|
|
55
47
|
throw new Error('No previous request to retry');
|
|
56
48
|
}
|
|
57
49
|
return verify(lastRequestRef.current);
|
|
58
50
|
}), [verify]);
|
|
59
|
-
// Convenience methods
|
|
60
51
|
const getPhoneNumber = (0, react_1.useCallback)((options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options)), [verify]);
|
|
61
52
|
const verifyPhoneNumber = (0, react_1.useCallback)((phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options)), [verify]);
|
|
62
|
-
// Reset state
|
|
63
53
|
const reset = (0, react_1.useCallback)(() => {
|
|
64
54
|
setIsLoading(false);
|
|
65
55
|
setError(null);
|
|
66
56
|
setResult(null);
|
|
67
57
|
setCurrentStep('idle');
|
|
68
58
|
}, []);
|
|
69
|
-
// Expose granular methods directly from client for better discoverability
|
|
70
59
|
const preparePhoneRequest = (0, react_1.useCallback)((options) => client.preparePhoneRequest(options), [client]);
|
|
71
60
|
const invokeSecurePrompt = (0, react_1.useCallback)((prepareResponse) => client.invokeSecurePrompt(prepareResponse), [client]);
|
|
72
61
|
const getPhoneNumberCredential = (0, react_1.useCallback)((credentialResponse, session) => client.getPhoneNumber(credentialResponse, session), [client]);
|
|
73
62
|
const verifyPhoneNumberCredential = (0, react_1.useCallback)((credentialResponse, session) => client.verifyPhoneNumber(credentialResponse, session), [client]);
|
|
74
63
|
return {
|
|
75
|
-
// State
|
|
76
64
|
isLoading,
|
|
77
65
|
error,
|
|
78
66
|
result,
|
|
79
67
|
currentStep,
|
|
80
68
|
isSupported,
|
|
81
|
-
// High-level methods
|
|
82
69
|
verify,
|
|
83
70
|
getPhoneNumber,
|
|
84
71
|
verifyPhoneNumber,
|
|
85
72
|
retryLastRequest,
|
|
86
73
|
reset,
|
|
87
|
-
// Granular methods (directly exposed for better discoverability)
|
|
88
74
|
preparePhoneRequest,
|
|
89
75
|
invokeSecurePrompt,
|
|
90
76
|
getPhoneNumberCredential,
|
|
91
77
|
verifyPhoneNumberCredential,
|
|
92
|
-
// Client instance (still available for advanced usage)
|
|
93
78
|
client
|
|
94
79
|
};
|
|
95
80
|
}
|
|
@@ -17,7 +17,6 @@ class VanillaClient {
|
|
|
17
17
|
}
|
|
18
18
|
authenticate(authUrl, options) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
// Legacy authentication removed - use setToken directly
|
|
21
20
|
throw new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
22
21
|
});
|
|
23
22
|
}
|
|
@@ -5,7 +5,6 @@ var client_1 = require("./client");
|
|
|
5
5
|
Object.defineProperty(exports, "ClientManager", { enumerable: true, get: function () { return client_1.VanillaClient; } });
|
|
6
6
|
var phone_auth_1 = require("./phone-auth");
|
|
7
7
|
Object.defineProperty(exports, "PhoneAuthManager", { enumerable: true, get: function () { return phone_auth_1.PhoneAuthManager; } });
|
|
8
|
-
// Export error utilities
|
|
9
8
|
var phone_auth_2 = require("../../core/phone-auth");
|
|
10
9
|
Object.defineProperty(exports, "PhoneAuthErrorCode", { enumerable: true, get: function () { return phone_auth_2.PhoneAuthErrorCode; } });
|
|
11
10
|
Object.defineProperty(exports, "isPhoneAuthError", { enumerable: true, get: function () { return phone_auth_2.isPhoneAuthError; } });
|
|
@@ -23,18 +23,11 @@ class PhoneAuthManager {
|
|
|
23
23
|
isSupported: this.client.isSupported()
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Get current state
|
|
28
|
-
*/
|
|
29
26
|
getState() {
|
|
30
27
|
return Object.assign({}, this.state);
|
|
31
28
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Subscribe to state changes
|
|
34
|
-
*/
|
|
35
29
|
subscribe(listener) {
|
|
36
30
|
this.listeners.push(listener);
|
|
37
|
-
// Return unsubscribe function
|
|
38
31
|
return () => {
|
|
39
32
|
const index = this.listeners.indexOf(listener);
|
|
40
33
|
if (index !== -1) {
|
|
@@ -42,16 +35,10 @@ class PhoneAuthManager {
|
|
|
42
35
|
}
|
|
43
36
|
};
|
|
44
37
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Update state and notify listeners
|
|
47
|
-
*/
|
|
48
38
|
updateState(updates) {
|
|
49
39
|
this.state = Object.assign(Object.assign({}, this.state), updates);
|
|
50
40
|
this.listeners.forEach(listener => listener(this.getState()));
|
|
51
41
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Verify phone number
|
|
54
|
-
*/
|
|
55
42
|
verify(options) {
|
|
56
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
44
|
this.updateState({
|
|
@@ -61,19 +48,14 @@ class PhoneAuthManager {
|
|
|
61
48
|
currentStep: 'requesting'
|
|
62
49
|
});
|
|
63
50
|
try {
|
|
64
|
-
// Step 1: Prepare request
|
|
65
51
|
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
66
|
-
// Step 2: Show authenticating state
|
|
67
52
|
this.updateState({ currentStep: 'authenticating' });
|
|
68
53
|
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
69
|
-
// Step 3: Process response through appropriate endpoint
|
|
70
54
|
this.updateState({ currentStep: 'processing' });
|
|
71
|
-
// Cast to credential type - adapters never use headless mode
|
|
72
55
|
const credential = credentialResponse;
|
|
73
56
|
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
74
57
|
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
75
58
|
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
76
|
-
// Create final result
|
|
77
59
|
const isVerifyResponse = 'verified' in processedResult;
|
|
78
60
|
const result = processedResult;
|
|
79
61
|
this.updateState({
|
|
@@ -84,7 +66,6 @@ class PhoneAuthManager {
|
|
|
84
66
|
return result;
|
|
85
67
|
}
|
|
86
68
|
catch (error) {
|
|
87
|
-
// Enhance error with context
|
|
88
69
|
const authError = error;
|
|
89
70
|
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
90
71
|
useCase: options.use_case,
|
|
@@ -101,25 +82,16 @@ class PhoneAuthManager {
|
|
|
101
82
|
}
|
|
102
83
|
});
|
|
103
84
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Get phone number
|
|
106
|
-
*/
|
|
107
85
|
getPhoneNumber(options) {
|
|
108
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
87
|
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
110
88
|
});
|
|
111
89
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Verify specific phone number
|
|
114
|
-
*/
|
|
115
90
|
verifyPhoneNumber(phoneNumber, options) {
|
|
116
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
92
|
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
118
93
|
});
|
|
119
94
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Reset state
|
|
122
|
-
*/
|
|
123
95
|
reset() {
|
|
124
96
|
this.updateState({
|
|
125
97
|
isLoading: false,
|
|
@@ -128,9 +100,6 @@ class PhoneAuthManager {
|
|
|
128
100
|
currentStep: 'idle'
|
|
129
101
|
});
|
|
130
102
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Check if browser supports secure phone authentication
|
|
133
|
-
*/
|
|
134
103
|
isSupported() {
|
|
135
104
|
return this.state.isSupported;
|
|
136
105
|
}
|
|
@@ -5,6 +5,6 @@ export { PhoneAuthClient } from '../../core/phone-auth';
|
|
|
5
5
|
export type { ClientConfig, ClientResponse, RequestOptions } from '../../core/types';
|
|
6
6
|
export type { AuthConfig as PhoneAuthConfig, PhoneAuthOptions, PhoneAuthResult, AuthError, AuthStep } from '../../core/phone-auth';
|
|
7
7
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
8
|
-
export type { PhoneAuthCallbacks, PLMN, SessionInfo, PrepareRequest, PrepareResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, SecureCredentialRequest, SecureCredentialResponse, DigitalCredential, TS43Data, LinkData, ClientInfo,
|
|
8
|
+
export type { PhoneAuthCallbacks, PLMN, SessionInfo, PrepareRequest, PrepareResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, SecureCredentialRequest, SecureCredentialResponse, DigitalCredential, TS43Data, LinkData, ClientInfo, BrowserErrorType, BrowserErrorCodeType, BrowserNameType } from '../../core/phone-auth/types';
|
|
9
9
|
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
10
10
|
export { USE_CASE, ERROR_CODE, ERROR_MESSAGES, ERROR_STATUS_CODES } from '../../core/phone-auth/api-types';
|