@glideidentity/web-client-sdk 5.0.0 → 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 +108 -8
- 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.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.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.js +0 -6
- package/dist/core/client.js +0 -12
- package/dist/core/logger.js +1 -81
- package/dist/core/phone-auth/api-types.js +0 -83
- package/dist/core/phone-auth/client.js +27 -366
- package/dist/core/phone-auth/error-utils.js +1 -83
- package/dist/core/phone-auth/index.js +0 -1
- 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.js +2 -40
- 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.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.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.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 -315
- 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 +27 -366
- 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.js +1 -3
- 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 -31
- package/dist/esm/core/phone-auth/validation-utils.js +2 -40
- package/dist/esm/core/types.d.ts +0 -35
- package/dist/esm/core/version.js +1 -2
- package/dist/esm/index.js +1 -9
- package/dist/index.js +0 -7
- package/package.json +1 -1
|
@@ -1,7 +1,4 @@
|
|
|
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;
|
|
@@ -9,16 +6,10 @@ exports.validateUseCaseRequirements = validateUseCaseRequirements;
|
|
|
9
6
|
exports.createValidationError = createValidationError;
|
|
10
7
|
exports.validateNonce = validateNonce;
|
|
11
8
|
const api_types_1 = require("./api-types");
|
|
12
|
-
/**
|
|
13
|
-
* Validates E.164 phone number format
|
|
14
|
-
* @param phoneNumber - Phone number to validate
|
|
15
|
-
* @returns Validation result with error if invalid
|
|
16
|
-
*/
|
|
17
9
|
function validatePhoneNumber(phoneNumber) {
|
|
18
10
|
if (!phoneNumber) {
|
|
19
|
-
return { valid: true };
|
|
11
|
+
return { valid: true };
|
|
20
12
|
}
|
|
21
|
-
// E.164 format validation - strict, no cleaning
|
|
22
13
|
const e164Regex = /^\+[1-9]\d{1,14}$/;
|
|
23
14
|
if (!phoneNumber.startsWith('+')) {
|
|
24
15
|
return {
|
|
@@ -38,7 +29,6 @@ function validatePhoneNumber(phoneNumber) {
|
|
|
38
29
|
error: 'Phone number too long for E.164 format (maximum 15 digits after +)'
|
|
39
30
|
};
|
|
40
31
|
}
|
|
41
|
-
// Check for any invalid characters (spaces, dashes, parentheses, etc.)
|
|
42
32
|
if (!/^\+\d+$/.test(phoneNumber)) {
|
|
43
33
|
return {
|
|
44
34
|
valid: false,
|
|
@@ -53,42 +43,26 @@ function validatePhoneNumber(phoneNumber) {
|
|
|
53
43
|
}
|
|
54
44
|
return { valid: true };
|
|
55
45
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Validates PLMN (MCC/MNC) values
|
|
58
|
-
* @param plmn - PLMN object with MCC and MNC
|
|
59
|
-
* @returns Validation result
|
|
60
|
-
*/
|
|
61
46
|
function validatePlmn(plmn) {
|
|
62
47
|
if (!plmn) {
|
|
63
|
-
return { valid: true };
|
|
48
|
+
return { valid: true };
|
|
64
49
|
}
|
|
65
50
|
const { mcc, mnc } = plmn;
|
|
66
|
-
// MCC validation (3 digits) - no range check for telco labs
|
|
67
51
|
if (!mcc || !/^\d{3}$/.test(mcc)) {
|
|
68
52
|
return {
|
|
69
53
|
valid: false,
|
|
70
54
|
error: 'MCC must be exactly 3 digits'
|
|
71
55
|
};
|
|
72
56
|
}
|
|
73
|
-
// MNC validation (2 or 3 digits)
|
|
74
57
|
if (!mnc || !/^\d{2,3}$/.test(mnc)) {
|
|
75
58
|
return {
|
|
76
59
|
valid: false,
|
|
77
60
|
error: 'MNC must be 2 or 3 digits'
|
|
78
61
|
};
|
|
79
62
|
}
|
|
80
|
-
// No range validation - allowing unofficial MCCs for telco labs
|
|
81
63
|
return { valid: true };
|
|
82
64
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Validates use case and phone number combination
|
|
85
|
-
* @param useCase - The use case
|
|
86
|
-
* @param phoneNumber - The phone number (required for VerifyPhoneNumber)
|
|
87
|
-
* @param hasParentSessionId - Whether parent_session_id is provided (allows skipping normal validation)
|
|
88
|
-
* @returns Validation result
|
|
89
|
-
*/
|
|
90
65
|
function validateUseCaseRequirements(useCase, phoneNumber, hasParentSessionId) {
|
|
91
|
-
// VerifyPhoneNumber requires a phone number (unless parent_session_id is provided)
|
|
92
66
|
if (useCase === api_types_1.USE_CASE.VERIFY_PHONE_NUMBER && !phoneNumber && !hasParentSessionId) {
|
|
93
67
|
return {
|
|
94
68
|
valid: false,
|
|
@@ -97,12 +71,6 @@ function validateUseCaseRequirements(useCase, phoneNumber, hasParentSessionId) {
|
|
|
97
71
|
}
|
|
98
72
|
return { valid: true };
|
|
99
73
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Creates a validation error
|
|
102
|
-
* @param code - Error code
|
|
103
|
-
* @param message - Error message
|
|
104
|
-
* @param field - Field that failed validation
|
|
105
|
-
*/
|
|
106
74
|
function createValidationError(code, message, field) {
|
|
107
75
|
const error = new Error(message);
|
|
108
76
|
error.code = code;
|
|
@@ -111,13 +79,7 @@ function createValidationError(code, message, field) {
|
|
|
111
79
|
}
|
|
112
80
|
return error;
|
|
113
81
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Validates nonce format
|
|
116
|
-
* @param nonce - Nonce string to validate
|
|
117
|
-
* @returns Validation result
|
|
118
|
-
*/
|
|
119
82
|
function validateNonce(nonce) {
|
|
120
|
-
// Nonce should be base64url encoded and have reasonable length
|
|
121
83
|
const base64urlRegex = /^[A-Za-z0-9_-]+$/;
|
|
122
84
|
if (!nonce || nonce.length === 0) {
|
|
123
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);
|
|
@@ -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
|
}
|
|
@@ -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
|
};
|
|
@@ -10,43 +10,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { ref, computed, readonly } from 'vue';
|
|
11
11
|
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
12
12
|
export function usePhoneAuth(config = {}) {
|
|
13
|
-
// State management
|
|
14
13
|
const isLoading = ref(false);
|
|
15
14
|
const error = ref(null);
|
|
16
15
|
const result = ref(null);
|
|
17
16
|
const currentStep = ref('idle');
|
|
18
|
-
|
|
19
|
-
const client = new PhoneAuthClient(Object.assign(Object.assign({}, config), {
|
|
20
|
-
// Callbacks are now properly typed through AuthConfig
|
|
21
|
-
onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt }));
|
|
22
|
-
// Check browser support
|
|
17
|
+
const client = new PhoneAuthClient(Object.assign(Object.assign({}, config), { onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt }));
|
|
23
18
|
const isSupported = computed(() => client.isSupported());
|
|
24
|
-
// Verify method - internal wrapper that converts to API format
|
|
25
19
|
const verify = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
20
|
isLoading.value = true;
|
|
27
21
|
error.value = null;
|
|
28
22
|
result.value = null;
|
|
29
23
|
currentStep.value = 'requesting';
|
|
30
24
|
try {
|
|
31
|
-
// Step 1: Prepare the request
|
|
32
25
|
const preparedRequest = yield client.preparePhoneRequest(options);
|
|
33
|
-
// Step 2: User authentication
|
|
34
26
|
currentStep.value = 'authenticating';
|
|
35
27
|
const credentialResponse = yield client.invokeSecurePrompt(preparedRequest);
|
|
36
|
-
// Step 3: Process the response through appropriate endpoint
|
|
37
28
|
currentStep.value = 'processing';
|
|
38
|
-
// Cast to credential type - adapters never use headless mode
|
|
39
29
|
const credential = credentialResponse;
|
|
40
30
|
const verificationResult = options.use_case === 'GetPhoneNumber'
|
|
41
31
|
? yield client.getPhoneNumber(credential, preparedRequest.session)
|
|
42
32
|
: yield client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
43
|
-
// Use the result directly - it's already the correct type
|
|
44
33
|
result.value = verificationResult;
|
|
45
34
|
currentStep.value = 'complete';
|
|
46
35
|
return result.value;
|
|
47
36
|
}
|
|
48
37
|
catch (err) {
|
|
49
|
-
// Enhance error with context if it's an AuthError
|
|
50
38
|
const authError = err;
|
|
51
39
|
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
52
40
|
useCase: options.use_case,
|
|
@@ -62,39 +50,32 @@ export function usePhoneAuth(config = {}) {
|
|
|
62
50
|
isLoading.value = false;
|
|
63
51
|
}
|
|
64
52
|
});
|
|
65
|
-
// Convenience methods
|
|
66
53
|
const getPhoneNumber = (options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
67
54
|
const verifyPhoneNumber = (phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
68
|
-
// Reset state
|
|
69
55
|
const reset = () => {
|
|
70
56
|
isLoading.value = false;
|
|
71
57
|
error.value = null;
|
|
72
58
|
result.value = null;
|
|
73
59
|
currentStep.value = 'idle';
|
|
74
60
|
};
|
|
75
|
-
// Expose granular methods directly from client for better discoverability
|
|
76
61
|
const preparePhoneRequest = client.preparePhoneRequest.bind(client);
|
|
77
62
|
const invokeSecurePrompt = client.invokeSecurePrompt.bind(client);
|
|
78
63
|
const getPhoneNumberCredential = client.getPhoneNumber.bind(client);
|
|
79
64
|
const verifyPhoneNumberCredential = client.verifyPhoneNumber.bind(client);
|
|
80
65
|
return {
|
|
81
|
-
// State (readonly)
|
|
82
66
|
isLoading: readonly(isLoading),
|
|
83
67
|
error: readonly(error),
|
|
84
68
|
result: readonly(result),
|
|
85
69
|
currentStep: readonly(currentStep),
|
|
86
70
|
isSupported: readonly(isSupported),
|
|
87
|
-
// High-level methods
|
|
88
71
|
verify,
|
|
89
72
|
getPhoneNumber,
|
|
90
73
|
verifyPhoneNumber,
|
|
91
74
|
reset,
|
|
92
|
-
// Granular methods (directly exposed for better discoverability)
|
|
93
75
|
preparePhoneRequest,
|
|
94
76
|
invokeSecurePrompt,
|
|
95
77
|
getPhoneNumberCredential,
|
|
96
78
|
verifyPhoneNumberCredential,
|
|
97
|
-
// Client instance (still available for advanced usage)
|
|
98
79
|
client
|
|
99
80
|
};
|
|
100
81
|
}
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
// Browser-specific entry point for vanilla JavaScript usage
|
|
2
|
-
// This excludes framework-specific adapters that require Angular/React/Vue
|
|
3
|
-
// Phone Authentication - Core client
|
|
4
1
|
export { PhoneAuthClient } from './core/phone-auth';
|
|
5
|
-
// Phone Auth Error Utilities
|
|
6
2
|
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from './core/phone-auth';
|
|
7
|
-
// Export constants for use case and strategy
|
|
8
3
|
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from './core/phone-auth/types';
|
|
9
|
-
// Vanilla adapters ONLY (no framework dependencies)
|
|
10
4
|
export { VanillaClient as ClientManager } from './adapters/vanilla/client';
|
|
11
5
|
export { PhoneAuthManager } from './adapters/vanilla/phone-auth';
|
|
@@ -6,17 +6,7 @@ export declare class SDKClient {
|
|
|
6
6
|
private token?;
|
|
7
7
|
phoneAuth: PhoneAuthClient;
|
|
8
8
|
constructor(config: ClientConfig);
|
|
9
|
-
/**
|
|
10
|
-
* Set authentication token for API requests
|
|
11
|
-
*/
|
|
12
9
|
setToken(token: string): void;
|
|
13
|
-
/**
|
|
14
|
-
* Clear authentication token
|
|
15
|
-
*/
|
|
16
10
|
clearToken(): void;
|
|
17
|
-
/**
|
|
18
|
-
* Make a GET request to the API
|
|
19
|
-
* Note: Requires baseURL to be set in the config
|
|
20
|
-
*/
|
|
21
11
|
get<T = any>(path: string, options?: RequestOptions): Promise<ClientResponse<T>>;
|
|
22
12
|
}
|