@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
|
@@ -32,19 +32,6 @@ export declare function validateUseCaseRequirements(useCase: UseCase, phoneNumbe
|
|
|
32
32
|
valid: boolean;
|
|
33
33
|
error?: string;
|
|
34
34
|
};
|
|
35
|
-
/**
|
|
36
|
-
* Validates consent data
|
|
37
|
-
* @param consentData - Consent data object
|
|
38
|
-
* @returns Validation result
|
|
39
|
-
*/
|
|
40
|
-
export declare function validateConsentData(consentData?: {
|
|
41
|
-
consent_text: string;
|
|
42
|
-
policy_link: string;
|
|
43
|
-
policy_text: string;
|
|
44
|
-
}): {
|
|
45
|
-
valid: boolean;
|
|
46
|
-
error?: string;
|
|
47
|
-
};
|
|
48
35
|
/**
|
|
49
36
|
* Creates a validation error
|
|
50
37
|
* @param code - Error code
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Validation utilities for phone authentication
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.validatePhoneNumber = validatePhoneNumber;
|
|
7
4
|
exports.validatePlmn = validatePlmn;
|
|
8
5
|
exports.validateUseCaseRequirements = validateUseCaseRequirements;
|
|
9
|
-
exports.validateConsentData = validateConsentData;
|
|
10
6
|
exports.createValidationError = createValidationError;
|
|
11
7
|
exports.validateNonce = validateNonce;
|
|
12
8
|
const api_types_1 = require("./api-types");
|
|
13
|
-
/**
|
|
14
|
-
* Validates E.164 phone number format
|
|
15
|
-
* @param phoneNumber - Phone number to validate
|
|
16
|
-
* @returns Validation result with error if invalid
|
|
17
|
-
*/
|
|
18
9
|
function validatePhoneNumber(phoneNumber) {
|
|
19
10
|
if (!phoneNumber) {
|
|
20
|
-
return { valid: true };
|
|
11
|
+
return { valid: true };
|
|
21
12
|
}
|
|
22
|
-
// E.164 format validation - strict, no cleaning
|
|
23
13
|
const e164Regex = /^\+[1-9]\d{1,14}$/;
|
|
24
14
|
if (!phoneNumber.startsWith('+')) {
|
|
25
15
|
return {
|
|
@@ -39,7 +29,6 @@ function validatePhoneNumber(phoneNumber) {
|
|
|
39
29
|
error: 'Phone number too long for E.164 format (maximum 15 digits after +)'
|
|
40
30
|
};
|
|
41
31
|
}
|
|
42
|
-
// Check for any invalid characters (spaces, dashes, parentheses, etc.)
|
|
43
32
|
if (!/^\+\d+$/.test(phoneNumber)) {
|
|
44
33
|
return {
|
|
45
34
|
valid: false,
|
|
@@ -54,42 +43,26 @@ function validatePhoneNumber(phoneNumber) {
|
|
|
54
43
|
}
|
|
55
44
|
return { valid: true };
|
|
56
45
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Validates PLMN (MCC/MNC) values
|
|
59
|
-
* @param plmn - PLMN object with MCC and MNC
|
|
60
|
-
* @returns Validation result
|
|
61
|
-
*/
|
|
62
46
|
function validatePlmn(plmn) {
|
|
63
47
|
if (!plmn) {
|
|
64
|
-
return { valid: true };
|
|
48
|
+
return { valid: true };
|
|
65
49
|
}
|
|
66
50
|
const { mcc, mnc } = plmn;
|
|
67
|
-
// MCC validation (3 digits) - no range check for telco labs
|
|
68
51
|
if (!mcc || !/^\d{3}$/.test(mcc)) {
|
|
69
52
|
return {
|
|
70
53
|
valid: false,
|
|
71
54
|
error: 'MCC must be exactly 3 digits'
|
|
72
55
|
};
|
|
73
56
|
}
|
|
74
|
-
// MNC validation (2 or 3 digits)
|
|
75
57
|
if (!mnc || !/^\d{2,3}$/.test(mnc)) {
|
|
76
58
|
return {
|
|
77
59
|
valid: false,
|
|
78
60
|
error: 'MNC must be 2 or 3 digits'
|
|
79
61
|
};
|
|
80
62
|
}
|
|
81
|
-
// No range validation - allowing unofficial MCCs for telco labs
|
|
82
63
|
return { valid: true };
|
|
83
64
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Validates use case and phone number combination
|
|
86
|
-
* @param useCase - The use case
|
|
87
|
-
* @param phoneNumber - The phone number (required for VerifyPhoneNumber)
|
|
88
|
-
* @param hasParentSessionId - Whether parent_session_id is provided (allows skipping normal validation)
|
|
89
|
-
* @returns Validation result
|
|
90
|
-
*/
|
|
91
65
|
function validateUseCaseRequirements(useCase, phoneNumber, hasParentSessionId) {
|
|
92
|
-
// VerifyPhoneNumber requires a phone number (unless parent_session_id is provided)
|
|
93
66
|
if (useCase === api_types_1.USE_CASE.VERIFY_PHONE_NUMBER && !phoneNumber && !hasParentSessionId) {
|
|
94
67
|
return {
|
|
95
68
|
valid: false,
|
|
@@ -98,52 +71,6 @@ function validateUseCaseRequirements(useCase, phoneNumber, hasParentSessionId) {
|
|
|
98
71
|
}
|
|
99
72
|
return { valid: true };
|
|
100
73
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Validates consent data
|
|
103
|
-
* @param consentData - Consent data object
|
|
104
|
-
* @returns Validation result
|
|
105
|
-
*/
|
|
106
|
-
function validateConsentData(consentData) {
|
|
107
|
-
if (!consentData) {
|
|
108
|
-
return { valid: true }; // Consent data is optional
|
|
109
|
-
}
|
|
110
|
-
const { consent_text: consentText, policy_link: policyLink, policy_text: policyText } = consentData;
|
|
111
|
-
if (!consentText || consentText.trim().length === 0) {
|
|
112
|
-
return {
|
|
113
|
-
valid: false,
|
|
114
|
-
error: 'Consent text is required when consent data is provided'
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if (!policyLink || policyLink.trim().length === 0) {
|
|
118
|
-
return {
|
|
119
|
-
valid: false,
|
|
120
|
-
error: 'Policy link is required when consent data is provided'
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
// Validate URL format for policy link
|
|
124
|
-
try {
|
|
125
|
-
new URL(policyLink);
|
|
126
|
-
}
|
|
127
|
-
catch (_a) {
|
|
128
|
-
return {
|
|
129
|
-
valid: false,
|
|
130
|
-
error: 'Policy link must be a valid URL'
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (!policyText || policyText.trim().length === 0) {
|
|
134
|
-
return {
|
|
135
|
-
valid: false,
|
|
136
|
-
error: 'Policy text is required when consent data is provided'
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
return { valid: true };
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Creates a validation error
|
|
143
|
-
* @param code - Error code
|
|
144
|
-
* @param message - Error message
|
|
145
|
-
* @param field - Field that failed validation
|
|
146
|
-
*/
|
|
147
74
|
function createValidationError(code, message, field) {
|
|
148
75
|
const error = new Error(message);
|
|
149
76
|
error.code = code;
|
|
@@ -152,13 +79,7 @@ function createValidationError(code, message, field) {
|
|
|
152
79
|
}
|
|
153
80
|
return error;
|
|
154
81
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Validates nonce format
|
|
157
|
-
* @param nonce - Nonce string to validate
|
|
158
|
-
* @returns Validation result
|
|
159
|
-
*/
|
|
160
82
|
function validateNonce(nonce) {
|
|
161
|
-
// Nonce should be base64url encoded and have reasonable length
|
|
162
83
|
const base64urlRegex = /^[A-Za-z0-9_-]+$/;
|
|
163
84
|
if (!nonce || nonce.length === 0) {
|
|
164
85
|
return {
|
package/dist/core/version.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { ClientService } from './client.service';
|
|
2
2
|
export { PhoneAuthService } from './phone-auth.service';
|
|
3
|
-
// Export error utilities
|
|
4
3
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -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
|
}
|
|
@@ -21,33 +21,22 @@ import { PhoneAuthClient } from '../../core/phone-auth';
|
|
|
21
21
|
import { BehaviorSubject } from 'rxjs';
|
|
22
22
|
let PhoneAuthService = class PhoneAuthService {
|
|
23
23
|
constructor() {
|
|
24
|
-
// State subjects
|
|
25
24
|
this.isLoadingSubject = new BehaviorSubject(false);
|
|
26
25
|
this.errorSubject = new BehaviorSubject(null);
|
|
27
26
|
this.resultSubject = new BehaviorSubject(null);
|
|
28
27
|
this.currentStepSubject = new BehaviorSubject('idle');
|
|
29
|
-
// Public observables
|
|
30
28
|
this.isLoading$ = this.isLoadingSubject.asObservable();
|
|
31
29
|
this.error$ = this.errorSubject.asObservable();
|
|
32
30
|
this.result$ = this.resultSubject.asObservable();
|
|
33
31
|
this.currentStep$ = this.currentStepSubject.asObservable();
|
|
34
32
|
this.client = new PhoneAuthClient();
|
|
35
33
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Configure the phone auth client
|
|
38
|
-
*/
|
|
39
34
|
configure(config) {
|
|
40
35
|
this.client = new PhoneAuthClient(config);
|
|
41
36
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Check if browser supports secure phone authentication
|
|
44
|
-
*/
|
|
45
37
|
isSupported() {
|
|
46
38
|
return this.client.isSupported();
|
|
47
39
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Verify phone number
|
|
50
|
-
*/
|
|
51
40
|
verify(options) {
|
|
52
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
42
|
this.isLoadingSubject.next(true);
|
|
@@ -55,19 +44,14 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
55
44
|
this.resultSubject.next(null);
|
|
56
45
|
this.currentStepSubject.next('requesting');
|
|
57
46
|
try {
|
|
58
|
-
// Step 1: Prepare request
|
|
59
47
|
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
60
|
-
// Step 2: Show authenticating state
|
|
61
48
|
this.currentStepSubject.next('authenticating');
|
|
62
49
|
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
63
|
-
// Step 3: Process response through appropriate endpoint
|
|
64
50
|
this.currentStepSubject.next('processing');
|
|
65
|
-
// Cast to credential type - adapters never use headless mode
|
|
66
51
|
const credential = credentialResponse;
|
|
67
52
|
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
68
53
|
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
69
54
|
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
70
|
-
// Create final result
|
|
71
55
|
const isVerifyResponse = 'verified' in processedResult;
|
|
72
56
|
const result = processedResult;
|
|
73
57
|
this.resultSubject.next(result);
|
|
@@ -75,7 +59,6 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
75
59
|
return result;
|
|
76
60
|
}
|
|
77
61
|
catch (error) {
|
|
78
|
-
// Enhance error with context
|
|
79
62
|
const authError = error;
|
|
80
63
|
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
81
64
|
useCase: options.use_case,
|
|
@@ -92,25 +75,16 @@ let PhoneAuthService = class PhoneAuthService {
|
|
|
92
75
|
}
|
|
93
76
|
});
|
|
94
77
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Get phone number
|
|
97
|
-
*/
|
|
98
78
|
getPhoneNumber(options) {
|
|
99
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
80
|
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
101
81
|
});
|
|
102
82
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Verify specific phone number
|
|
105
|
-
*/
|
|
106
83
|
verifyPhoneNumber(phoneNumber, options) {
|
|
107
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
85
|
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
109
86
|
});
|
|
110
87
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Reset state
|
|
113
|
-
*/
|
|
114
88
|
reset() {
|
|
115
89
|
this.isLoadingSubject.next(false);
|
|
116
90
|
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';
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export { usePhoneAuth } from './usePhoneAuth';
|
|
2
2
|
export { useClient } from './useClient';
|
|
3
|
-
// Export error utilities
|
|
4
3
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
5
|
-
// Export constants for use case and strategy
|
|
6
4
|
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
7
|
-
// Export the PhoneAuthClient class for direct use
|
|
8
5
|
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
@@ -27,7 +27,6 @@ export function useClient(config) {
|
|
|
27
27
|
};
|
|
28
28
|
}, []);
|
|
29
29
|
const authenticate = (authUrl, options) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
// Legacy authentication removed - use setToken directly
|
|
31
30
|
const error = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
32
31
|
setError(error);
|
|
33
32
|
setLoading(false);
|
|
@@ -15,13 +15,8 @@ export function usePhoneAuth(config = {}) {
|
|
|
15
15
|
const [result, setResult] = useState(null);
|
|
16
16
|
const [currentStep, setCurrentStep] = useState('idle');
|
|
17
17
|
const lastRequestRef = useRef(null);
|
|
18
|
-
|
|
19
|
-
const client = useMemo(() => new PhoneAuthClient(Object.assign(Object.assign({}, config), {
|
|
20
|
-
// Pass through callbacks if provided
|
|
21
|
-
onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt })), [JSON.stringify(config)]);
|
|
22
|
-
// Check browser support
|
|
18
|
+
const client = useMemo(() => new PhoneAuthClient(Object.assign(Object.assign({}, config), { onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt })), [JSON.stringify(config)]);
|
|
23
19
|
const isSupported = useMemo(() => client.isSupported(), [client]);
|
|
24
|
-
// Verify method with silent retry support
|
|
25
20
|
const verify = useCallback((options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
21
|
setIsLoading(true);
|
|
27
22
|
setError(null);
|
|
@@ -29,14 +24,12 @@ export function usePhoneAuth(config = {}) {
|
|
|
29
24
|
setCurrentStep('requesting');
|
|
30
25
|
lastRequestRef.current = options;
|
|
31
26
|
try {
|
|
32
|
-
// Use the client's verify method which includes retry logic
|
|
33
27
|
const verificationResult = yield client.verify(options);
|
|
34
28
|
setResult(verificationResult);
|
|
35
29
|
setCurrentStep('complete');
|
|
36
30
|
return verificationResult;
|
|
37
31
|
}
|
|
38
32
|
catch (err) {
|
|
39
|
-
// Error is only set after all retries are exhausted
|
|
40
33
|
const authError = err;
|
|
41
34
|
setError(authError);
|
|
42
35
|
setCurrentStep('idle');
|
|
@@ -46,47 +39,39 @@ export function usePhoneAuth(config = {}) {
|
|
|
46
39
|
setIsLoading(false);
|
|
47
40
|
}
|
|
48
41
|
}), [client]);
|
|
49
|
-
// Manual retry method
|
|
50
42
|
const retryLastRequest = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
51
43
|
if (!lastRequestRef.current) {
|
|
52
44
|
throw new Error('No previous request to retry');
|
|
53
45
|
}
|
|
54
46
|
return verify(lastRequestRef.current);
|
|
55
47
|
}), [verify]);
|
|
56
|
-
// Convenience methods
|
|
57
48
|
const getPhoneNumber = useCallback((options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options)), [verify]);
|
|
58
49
|
const verifyPhoneNumber = useCallback((phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options)), [verify]);
|
|
59
|
-
// Reset state
|
|
60
50
|
const reset = useCallback(() => {
|
|
61
51
|
setIsLoading(false);
|
|
62
52
|
setError(null);
|
|
63
53
|
setResult(null);
|
|
64
54
|
setCurrentStep('idle');
|
|
65
55
|
}, []);
|
|
66
|
-
// Expose granular methods directly from client for better discoverability
|
|
67
56
|
const preparePhoneRequest = useCallback((options) => client.preparePhoneRequest(options), [client]);
|
|
68
57
|
const invokeSecurePrompt = useCallback((prepareResponse) => client.invokeSecurePrompt(prepareResponse), [client]);
|
|
69
58
|
const getPhoneNumberCredential = useCallback((credentialResponse, session) => client.getPhoneNumber(credentialResponse, session), [client]);
|
|
70
59
|
const verifyPhoneNumberCredential = useCallback((credentialResponse, session) => client.verifyPhoneNumber(credentialResponse, session), [client]);
|
|
71
60
|
return {
|
|
72
|
-
// State
|
|
73
61
|
isLoading,
|
|
74
62
|
error,
|
|
75
63
|
result,
|
|
76
64
|
currentStep,
|
|
77
65
|
isSupported,
|
|
78
|
-
// High-level methods
|
|
79
66
|
verify,
|
|
80
67
|
getPhoneNumber,
|
|
81
68
|
verifyPhoneNumber,
|
|
82
69
|
retryLastRequest,
|
|
83
70
|
reset,
|
|
84
|
-
// Granular methods (directly exposed for better discoverability)
|
|
85
71
|
preparePhoneRequest,
|
|
86
72
|
invokeSecurePrompt,
|
|
87
73
|
getPhoneNumberCredential,
|
|
88
74
|
verifyPhoneNumberCredential,
|
|
89
|
-
// Client instance (still available for advanced usage)
|
|
90
75
|
client
|
|
91
76
|
};
|
|
92
77
|
}
|
|
@@ -14,7 +14,6 @@ export class VanillaClient {
|
|
|
14
14
|
}
|
|
15
15
|
authenticate(authUrl, options) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
// Legacy authentication removed - use setToken directly
|
|
18
17
|
throw new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
19
18
|
});
|
|
20
19
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { VanillaClient as ClientManager } from './client';
|
|
2
2
|
export { PhoneAuthManager } from './phone-auth';
|
|
3
|
-
// Export error utilities
|
|
4
3
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -11,36 +11,12 @@ export declare class PhoneAuthManager {
|
|
|
11
11
|
private state;
|
|
12
12
|
private listeners;
|
|
13
13
|
constructor(config?: AuthConfig);
|
|
14
|
-
/**
|
|
15
|
-
* Get current state
|
|
16
|
-
*/
|
|
17
14
|
getState(): PhoneAuthState;
|
|
18
|
-
/**
|
|
19
|
-
* Subscribe to state changes
|
|
20
|
-
*/
|
|
21
15
|
subscribe(listener: (state: PhoneAuthState) => void): () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Update state and notify listeners
|
|
24
|
-
*/
|
|
25
16
|
private updateState;
|
|
26
|
-
/**
|
|
27
|
-
* Verify phone number
|
|
28
|
-
*/
|
|
29
17
|
verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
|
|
30
|
-
/**
|
|
31
|
-
* Get phone number
|
|
32
|
-
*/
|
|
33
18
|
getPhoneNumber(options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Verify specific phone number
|
|
36
|
-
*/
|
|
37
19
|
verifyPhoneNumber(phoneNumber: string, options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Reset state
|
|
40
|
-
*/
|
|
41
20
|
reset(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Check if browser supports secure phone authentication
|
|
44
|
-
*/
|
|
45
21
|
isSupported(): boolean;
|
|
46
22
|
}
|
|
@@ -20,18 +20,11 @@ export class PhoneAuthManager {
|
|
|
20
20
|
isSupported: this.client.isSupported()
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Get current state
|
|
25
|
-
*/
|
|
26
23
|
getState() {
|
|
27
24
|
return Object.assign({}, this.state);
|
|
28
25
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Subscribe to state changes
|
|
31
|
-
*/
|
|
32
26
|
subscribe(listener) {
|
|
33
27
|
this.listeners.push(listener);
|
|
34
|
-
// Return unsubscribe function
|
|
35
28
|
return () => {
|
|
36
29
|
const index = this.listeners.indexOf(listener);
|
|
37
30
|
if (index !== -1) {
|
|
@@ -39,16 +32,10 @@ export class PhoneAuthManager {
|
|
|
39
32
|
}
|
|
40
33
|
};
|
|
41
34
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Update state and notify listeners
|
|
44
|
-
*/
|
|
45
35
|
updateState(updates) {
|
|
46
36
|
this.state = Object.assign(Object.assign({}, this.state), updates);
|
|
47
37
|
this.listeners.forEach(listener => listener(this.getState()));
|
|
48
38
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Verify phone number
|
|
51
|
-
*/
|
|
52
39
|
verify(options) {
|
|
53
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
41
|
this.updateState({
|
|
@@ -58,19 +45,14 @@ export class PhoneAuthManager {
|
|
|
58
45
|
currentStep: 'requesting'
|
|
59
46
|
});
|
|
60
47
|
try {
|
|
61
|
-
// Step 1: Prepare request
|
|
62
48
|
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
63
|
-
// Step 2: Show authenticating state
|
|
64
49
|
this.updateState({ currentStep: 'authenticating' });
|
|
65
50
|
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
66
|
-
// Step 3: Process response through appropriate endpoint
|
|
67
51
|
this.updateState({ currentStep: 'processing' });
|
|
68
|
-
// Cast to credential type - adapters never use headless mode
|
|
69
52
|
const credential = credentialResponse;
|
|
70
53
|
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
71
54
|
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
72
55
|
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
73
|
-
// Create final result
|
|
74
56
|
const isVerifyResponse = 'verified' in processedResult;
|
|
75
57
|
const result = processedResult;
|
|
76
58
|
this.updateState({
|
|
@@ -81,7 +63,6 @@ export class PhoneAuthManager {
|
|
|
81
63
|
return result;
|
|
82
64
|
}
|
|
83
65
|
catch (error) {
|
|
84
|
-
// Enhance error with context
|
|
85
66
|
const authError = error;
|
|
86
67
|
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
87
68
|
useCase: options.use_case,
|
|
@@ -98,25 +79,16 @@ export class PhoneAuthManager {
|
|
|
98
79
|
}
|
|
99
80
|
});
|
|
100
81
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Get phone number
|
|
103
|
-
*/
|
|
104
82
|
getPhoneNumber(options) {
|
|
105
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
84
|
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
107
85
|
});
|
|
108
86
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Verify specific phone number
|
|
111
|
-
*/
|
|
112
87
|
verifyPhoneNumber(phoneNumber, options) {
|
|
113
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
89
|
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
115
90
|
});
|
|
116
91
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Reset state
|
|
119
|
-
*/
|
|
120
92
|
reset() {
|
|
121
93
|
this.updateState({
|
|
122
94
|
isLoading: false,
|
|
@@ -125,9 +97,6 @@ export class PhoneAuthManager {
|
|
|
125
97
|
currentStep: 'idle'
|
|
126
98
|
});
|
|
127
99
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Check if browser supports secure phone authentication
|
|
130
|
-
*/
|
|
131
100
|
isSupported() {
|
|
132
101
|
return this.state.isSupported;
|
|
133
102
|
}
|
|
@@ -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';
|
|
@@ -2,10 +2,6 @@ export { usePhoneAuth } from './usePhoneAuth';
|
|
|
2
2
|
export { useClient } from './useClient';
|
|
3
3
|
export { SDKClient } from '../../core/client';
|
|
4
4
|
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
5
|
-
// API response types are already exported via core/phone-auth/types
|
|
6
|
-
// Export error utilities
|
|
7
5
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
8
|
-
// Export constants for use case and strategy
|
|
9
6
|
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
10
|
-
// Export API constants from api-types
|
|
11
7
|
export { USE_CASE, ERROR_CODE, ERROR_MESSAGES, ERROR_STATUS_CODES } from '../../core/phone-auth/api-types';
|
|
@@ -40,17 +40,14 @@ export function useClient(config) {
|
|
|
40
40
|
const authenticate = (authUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
loading.value = true;
|
|
42
42
|
error.value = null;
|
|
43
|
-
// Clean up previous authentication if exists
|
|
44
43
|
if (cleanup) {
|
|
45
44
|
cleanup();
|
|
46
45
|
cleanup = null;
|
|
47
46
|
}
|
|
48
|
-
// Legacy authentication removed - use setToken directly
|
|
49
47
|
error.value = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
50
48
|
loading.value = false;
|
|
51
49
|
throw error.value;
|
|
52
50
|
});
|
|
53
|
-
// Cleanup on component unmount
|
|
54
51
|
onUnmounted(() => {
|
|
55
52
|
if (cleanup) {
|
|
56
53
|
cleanup();
|
|
@@ -103,7 +100,6 @@ export function useClient(config) {
|
|
|
103
100
|
loading.value = false;
|
|
104
101
|
}
|
|
105
102
|
});
|
|
106
|
-
// Low-level methods for advanced control
|
|
107
103
|
const preparePhoneRequest = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
108
104
|
return client.value.phoneAuth.preparePhoneRequest(options);
|
|
109
105
|
});
|
|
@@ -117,7 +113,6 @@ export function useClient(config) {
|
|
|
117
113
|
isSupported,
|
|
118
114
|
getPhoneNumber,
|
|
119
115
|
verifyPhoneNumber,
|
|
120
|
-
// Low-level API for advanced usage
|
|
121
116
|
preparePhoneRequest,
|
|
122
117
|
invokeSecurePrompt
|
|
123
118
|
};
|