@glideidentity/web-client-sdk 4.4.8-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +938 -0
- package/dist/adapters/angular/client.service.d.ts +7 -0
- package/dist/adapters/angular/client.service.js +30 -0
- package/dist/adapters/angular/index.d.ts +3 -0
- package/dist/adapters/angular/index.js +18 -0
- package/dist/adapters/angular/phone-auth.service.d.ts +38 -0
- package/dist/adapters/angular/phone-auth.service.js +130 -0
- package/dist/adapters/react/index.d.ts +9 -0
- package/dist/adapters/react/index.js +28 -0
- package/dist/adapters/react/useClient.d.ts +26 -0
- package/dist/adapters/react/useClient.js +121 -0
- package/dist/adapters/react/usePhoneAuth.d.ts +23 -0
- package/dist/adapters/react/usePhoneAuth.js +95 -0
- package/dist/adapters/vanilla/client.d.ts +8 -0
- package/dist/adapters/vanilla/client.js +33 -0
- package/dist/adapters/vanilla/index.d.ts +3 -0
- package/dist/adapters/vanilla/index.js +18 -0
- package/dist/adapters/vanilla/phone-auth.d.ts +46 -0
- package/dist/adapters/vanilla/phone-auth.js +138 -0
- package/dist/adapters/vue/index.d.ts +10 -0
- package/dist/adapters/vue/index.js +36 -0
- package/dist/adapters/vue/useClient.d.ts +115 -0
- package/dist/adapters/vue/useClient.js +131 -0
- package/dist/adapters/vue/usePhoneAuth.d.ts +94 -0
- package/dist/adapters/vue/usePhoneAuth.js +103 -0
- package/dist/browser/web-client-sdk.min.js +2 -0
- package/dist/browser/web-client-sdk.min.js.LICENSE.txt +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +31 -0
- package/dist/core/client.d.ts +22 -0
- package/dist/core/client.js +77 -0
- package/dist/core/logger.d.ts +130 -0
- package/dist/core/logger.js +370 -0
- package/dist/core/phone-auth/api-types.d.ts +525 -0
- package/dist/core/phone-auth/api-types.js +215 -0
- package/dist/core/phone-auth/client.d.ts +187 -0
- package/dist/core/phone-auth/client.js +1353 -0
- package/dist/core/phone-auth/error-utils.d.ts +110 -0
- package/dist/core/phone-auth/error-utils.js +350 -0
- package/dist/core/phone-auth/index.d.ts +7 -0
- package/dist/core/phone-auth/index.js +47 -0
- package/dist/core/phone-auth/status-types.d.ts +107 -0
- package/dist/core/phone-auth/status-types.js +31 -0
- package/dist/core/phone-auth/strategies/desktop.d.ts +113 -0
- package/dist/core/phone-auth/strategies/desktop.js +502 -0
- package/dist/core/phone-auth/strategies/index.d.ts +11 -0
- package/dist/core/phone-auth/strategies/index.js +15 -0
- package/dist/core/phone-auth/strategies/link.d.ts +81 -0
- package/dist/core/phone-auth/strategies/link.js +265 -0
- package/dist/core/phone-auth/strategies/ts43.d.ts +32 -0
- package/dist/core/phone-auth/strategies/ts43.js +146 -0
- package/dist/core/phone-auth/strategies/types.d.ts +18 -0
- package/dist/core/phone-auth/strategies/types.js +6 -0
- package/dist/core/phone-auth/type-guards.d.ts +125 -0
- package/dist/core/phone-auth/type-guards.js +160 -0
- package/dist/core/phone-auth/types.d.ts +232 -0
- package/dist/core/phone-auth/types.js +93 -0
- package/dist/core/phone-auth/ui/mobile-debug-console.d.ts +25 -0
- package/dist/core/phone-auth/ui/mobile-debug-console.js +288 -0
- package/dist/core/phone-auth/ui/modal.d.ts +84 -0
- package/dist/core/phone-auth/ui/modal.js +574 -0
- package/dist/core/phone-auth/validation-utils.d.ts +66 -0
- package/dist/core/phone-auth/validation-utils.js +182 -0
- package/dist/core/types.d.ts +62 -0
- package/dist/core/types.js +2 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/esm/adapters/angular/client.service.d.ts +7 -0
- package/dist/esm/adapters/angular/client.service.js +27 -0
- package/dist/esm/adapters/angular/index.d.ts +3 -0
- package/dist/esm/adapters/angular/index.js +4 -0
- package/dist/esm/adapters/angular/phone-auth.service.d.ts +38 -0
- package/dist/esm/adapters/angular/phone-auth.service.js +127 -0
- package/dist/esm/adapters/react/index.d.ts +9 -0
- package/dist/esm/adapters/react/index.js +8 -0
- package/dist/esm/adapters/react/useClient.d.ts +26 -0
- package/dist/esm/adapters/react/useClient.js +116 -0
- package/dist/esm/adapters/react/usePhoneAuth.d.ts +23 -0
- package/dist/esm/adapters/react/usePhoneAuth.js +92 -0
- package/dist/esm/adapters/vanilla/client.d.ts +8 -0
- package/dist/esm/adapters/vanilla/client.js +29 -0
- package/dist/esm/adapters/vanilla/index.d.ts +3 -0
- package/dist/esm/adapters/vanilla/index.js +4 -0
- package/dist/esm/adapters/vanilla/phone-auth.d.ts +46 -0
- package/dist/esm/adapters/vanilla/phone-auth.js +134 -0
- package/dist/esm/adapters/vue/index.d.ts +10 -0
- package/dist/esm/adapters/vue/index.js +11 -0
- package/dist/esm/adapters/vue/useClient.d.ts +115 -0
- package/dist/esm/adapters/vue/useClient.js +127 -0
- package/dist/esm/adapters/vue/usePhoneAuth.d.ts +94 -0
- package/dist/esm/adapters/vue/usePhoneAuth.js +100 -0
- package/dist/esm/browser.d.ts +7 -0
- package/dist/esm/browser.js +11 -0
- package/dist/esm/core/client.d.ts +22 -0
- package/dist/esm/core/client.js +70 -0
- package/dist/esm/core/logger.d.ts +130 -0
- package/dist/esm/core/logger.js +359 -0
- package/dist/esm/core/phone-auth/api-types.d.ts +525 -0
- package/dist/esm/core/phone-auth/api-types.js +203 -0
- package/dist/esm/core/phone-auth/client.d.ts +187 -0
- package/dist/esm/core/phone-auth/client.js +1316 -0
- package/dist/esm/core/phone-auth/error-utils.d.ts +110 -0
- package/dist/esm/core/phone-auth/error-utils.js +338 -0
- package/dist/esm/core/phone-auth/index.d.ts +7 -0
- package/dist/esm/core/phone-auth/index.js +6 -0
- package/dist/esm/core/phone-auth/status-types.d.ts +107 -0
- package/dist/esm/core/phone-auth/status-types.js +26 -0
- package/dist/esm/core/phone-auth/strategies/desktop.d.ts +113 -0
- package/dist/esm/core/phone-auth/strategies/desktop.js +496 -0
- package/dist/esm/core/phone-auth/strategies/index.d.ts +11 -0
- package/dist/esm/core/phone-auth/strategies/index.js +7 -0
- package/dist/esm/core/phone-auth/strategies/link.d.ts +81 -0
- package/dist/esm/core/phone-auth/strategies/link.js +261 -0
- package/dist/esm/core/phone-auth/strategies/ts43.d.ts +32 -0
- package/dist/esm/core/phone-auth/strategies/ts43.js +142 -0
- package/dist/esm/core/phone-auth/strategies/types.d.ts +18 -0
- package/dist/esm/core/phone-auth/strategies/types.js +5 -0
- package/dist/esm/core/phone-auth/type-guards.d.ts +125 -0
- package/dist/esm/core/phone-auth/type-guards.js +150 -0
- package/dist/esm/core/phone-auth/types.d.ts +232 -0
- package/dist/esm/core/phone-auth/types.js +76 -0
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.d.ts +25 -0
- package/dist/esm/core/phone-auth/ui/mobile-debug-console.js +284 -0
- package/dist/esm/core/phone-auth/ui/modal.d.ts +84 -0
- package/dist/esm/core/phone-auth/ui/modal.js +570 -0
- package/dist/esm/core/phone-auth/validation-utils.d.ts +66 -0
- package/dist/esm/core/phone-auth/validation-utils.js +174 -0
- package/dist/esm/core/types.d.ts +62 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/core/version.d.ts +1 -0
- package/dist/esm/core/version.js +2 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +15 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +52 -0
- package/package.json +92 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { useState, useCallback, useMemo, useRef } from 'react';
|
|
11
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
12
|
+
export function usePhoneAuth(config = {}) {
|
|
13
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const [result, setResult] = useState(null);
|
|
16
|
+
const [currentStep, setCurrentStep] = useState('idle');
|
|
17
|
+
const lastRequestRef = useRef(null);
|
|
18
|
+
// Create client instance with callbacks
|
|
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
|
|
23
|
+
const isSupported = useMemo(() => client.isSupported(), [client]);
|
|
24
|
+
// Verify method with silent retry support
|
|
25
|
+
const verify = useCallback((options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
setIsLoading(true);
|
|
27
|
+
setError(null);
|
|
28
|
+
setResult(null);
|
|
29
|
+
setCurrentStep('requesting');
|
|
30
|
+
lastRequestRef.current = options;
|
|
31
|
+
try {
|
|
32
|
+
// Use the client's verify method which includes retry logic
|
|
33
|
+
const verificationResult = yield client.verify(options);
|
|
34
|
+
setResult(verificationResult);
|
|
35
|
+
setCurrentStep('complete');
|
|
36
|
+
return verificationResult;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
// Error is only set after all retries are exhausted
|
|
40
|
+
const authError = err;
|
|
41
|
+
setError(authError);
|
|
42
|
+
setCurrentStep('idle');
|
|
43
|
+
throw authError;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
setIsLoading(false);
|
|
47
|
+
}
|
|
48
|
+
}), [client]);
|
|
49
|
+
// Manual retry method
|
|
50
|
+
const retryLastRequest = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
if (!lastRequestRef.current) {
|
|
52
|
+
throw new Error('No previous request to retry');
|
|
53
|
+
}
|
|
54
|
+
return verify(lastRequestRef.current);
|
|
55
|
+
}), [verify]);
|
|
56
|
+
// Convenience methods
|
|
57
|
+
const getPhoneNumber = useCallback((options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options)), [verify]);
|
|
58
|
+
const verifyPhoneNumber = useCallback((phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options)), [verify]);
|
|
59
|
+
// Reset state
|
|
60
|
+
const reset = useCallback(() => {
|
|
61
|
+
setIsLoading(false);
|
|
62
|
+
setError(null);
|
|
63
|
+
setResult(null);
|
|
64
|
+
setCurrentStep('idle');
|
|
65
|
+
}, []);
|
|
66
|
+
// Expose granular methods directly from client for better discoverability
|
|
67
|
+
const preparePhoneRequest = useCallback((options) => client.preparePhoneRequest(options), [client]);
|
|
68
|
+
const invokeSecurePrompt = useCallback((prepareResponse) => client.invokeSecurePrompt(prepareResponse), [client]);
|
|
69
|
+
const getPhoneNumberCredential = useCallback((credentialResponse, session) => client.getPhoneNumber(credentialResponse, session), [client]);
|
|
70
|
+
const verifyPhoneNumberCredential = useCallback((credentialResponse, session) => client.verifyPhoneNumber(credentialResponse, session), [client]);
|
|
71
|
+
return {
|
|
72
|
+
// State
|
|
73
|
+
isLoading,
|
|
74
|
+
error,
|
|
75
|
+
result,
|
|
76
|
+
currentStep,
|
|
77
|
+
isSupported,
|
|
78
|
+
// High-level methods
|
|
79
|
+
verify,
|
|
80
|
+
getPhoneNumber,
|
|
81
|
+
verifyPhoneNumber,
|
|
82
|
+
retryLastRequest,
|
|
83
|
+
reset,
|
|
84
|
+
// Granular methods (directly exposed for better discoverability)
|
|
85
|
+
preparePhoneRequest,
|
|
86
|
+
invokeSecurePrompt,
|
|
87
|
+
getPhoneNumberCredential,
|
|
88
|
+
verifyPhoneNumberCredential,
|
|
89
|
+
// Client instance (still available for advanced usage)
|
|
90
|
+
client
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ClientConfig, ClientResponse, RequestOptions } from '../../core/types';
|
|
2
|
+
export declare class VanillaClient {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(config: ClientConfig);
|
|
5
|
+
authenticate(authUrl: string, options?: any): Promise<void>;
|
|
6
|
+
setToken(token: string): void;
|
|
7
|
+
get<T>(path: string, options?: RequestOptions): Promise<ClientResponse<T>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { SDKClient } from '../../core/client';
|
|
11
|
+
export class VanillaClient {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.client = new SDKClient(config);
|
|
14
|
+
}
|
|
15
|
+
authenticate(authUrl, options) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
// Legacy authentication removed - use setToken directly
|
|
18
|
+
throw new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
setToken(token) {
|
|
22
|
+
this.client.setToken(token);
|
|
23
|
+
}
|
|
24
|
+
get(path, options) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return this.client.get(path, options);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { VanillaClient as ClientManager } from './client';
|
|
2
|
+
export { PhoneAuthManager } from './phone-auth';
|
|
3
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { VanillaClient as ClientManager } from './client';
|
|
2
|
+
export { PhoneAuthManager } from './phone-auth';
|
|
3
|
+
// Export error utilities
|
|
4
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AuthConfig, PhoneAuthResult, AuthError, AuthStep, PhoneAuthOptions } from '../../core/phone-auth';
|
|
2
|
+
export interface PhoneAuthState {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: AuthError | null;
|
|
5
|
+
result: PhoneAuthResult | null;
|
|
6
|
+
currentStep: AuthStep;
|
|
7
|
+
isSupported: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class PhoneAuthManager {
|
|
10
|
+
private client;
|
|
11
|
+
private state;
|
|
12
|
+
private listeners;
|
|
13
|
+
constructor(config?: AuthConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Get current state
|
|
16
|
+
*/
|
|
17
|
+
getState(): PhoneAuthState;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to state changes
|
|
20
|
+
*/
|
|
21
|
+
subscribe(listener: (state: PhoneAuthState) => void): () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Update state and notify listeners
|
|
24
|
+
*/
|
|
25
|
+
private updateState;
|
|
26
|
+
/**
|
|
27
|
+
* Verify phone number
|
|
28
|
+
*/
|
|
29
|
+
verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Get phone number
|
|
32
|
+
*/
|
|
33
|
+
getPhoneNumber(options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Verify specific phone number
|
|
36
|
+
*/
|
|
37
|
+
verifyPhoneNumber(phoneNumber: string, options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Reset state
|
|
40
|
+
*/
|
|
41
|
+
reset(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Check if browser supports secure phone authentication
|
|
44
|
+
*/
|
|
45
|
+
isSupported(): boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
11
|
+
export class PhoneAuthManager {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
this.listeners = [];
|
|
14
|
+
this.client = new PhoneAuthClient(config);
|
|
15
|
+
this.state = {
|
|
16
|
+
isLoading: false,
|
|
17
|
+
error: null,
|
|
18
|
+
result: null,
|
|
19
|
+
currentStep: 'idle',
|
|
20
|
+
isSupported: this.client.isSupported()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get current state
|
|
25
|
+
*/
|
|
26
|
+
getState() {
|
|
27
|
+
return Object.assign({}, this.state);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to state changes
|
|
31
|
+
*/
|
|
32
|
+
subscribe(listener) {
|
|
33
|
+
this.listeners.push(listener);
|
|
34
|
+
// Return unsubscribe function
|
|
35
|
+
return () => {
|
|
36
|
+
const index = this.listeners.indexOf(listener);
|
|
37
|
+
if (index !== -1) {
|
|
38
|
+
this.listeners.splice(index, 1);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Update state and notify listeners
|
|
44
|
+
*/
|
|
45
|
+
updateState(updates) {
|
|
46
|
+
this.state = Object.assign(Object.assign({}, this.state), updates);
|
|
47
|
+
this.listeners.forEach(listener => listener(this.getState()));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Verify phone number
|
|
51
|
+
*/
|
|
52
|
+
verify(options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
this.updateState({
|
|
55
|
+
isLoading: true,
|
|
56
|
+
error: null,
|
|
57
|
+
result: null,
|
|
58
|
+
currentStep: 'requesting'
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
// Step 1: Prepare request
|
|
62
|
+
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
63
|
+
// Step 2: Show authenticating state
|
|
64
|
+
this.updateState({ currentStep: 'authenticating' });
|
|
65
|
+
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
66
|
+
// Step 3: Process response through appropriate endpoint
|
|
67
|
+
this.updateState({ currentStep: 'processing' });
|
|
68
|
+
// Cast to credential type - adapters never use headless mode
|
|
69
|
+
const credential = credentialResponse;
|
|
70
|
+
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
71
|
+
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
72
|
+
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
73
|
+
// Create final result
|
|
74
|
+
const isVerifyResponse = 'verified' in processedResult;
|
|
75
|
+
const result = processedResult;
|
|
76
|
+
this.updateState({
|
|
77
|
+
result,
|
|
78
|
+
currentStep: 'complete',
|
|
79
|
+
isLoading: false
|
|
80
|
+
});
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Enhance error with context
|
|
85
|
+
const authError = error;
|
|
86
|
+
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
87
|
+
useCase: options.use_case,
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,
|
|
90
|
+
url: typeof window !== 'undefined' ? window.location.href : undefined
|
|
91
|
+
} });
|
|
92
|
+
this.updateState({
|
|
93
|
+
error: enhancedError,
|
|
94
|
+
currentStep: 'idle',
|
|
95
|
+
isLoading: false
|
|
96
|
+
});
|
|
97
|
+
throw enhancedError;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get phone number
|
|
103
|
+
*/
|
|
104
|
+
getPhoneNumber(options) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Verify specific phone number
|
|
111
|
+
*/
|
|
112
|
+
verifyPhoneNumber(phoneNumber, options) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Reset state
|
|
119
|
+
*/
|
|
120
|
+
reset() {
|
|
121
|
+
this.updateState({
|
|
122
|
+
isLoading: false,
|
|
123
|
+
error: null,
|
|
124
|
+
result: null,
|
|
125
|
+
currentStep: 'idle'
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Check if browser supports secure phone authentication
|
|
130
|
+
*/
|
|
131
|
+
isSupported() {
|
|
132
|
+
return this.state.isSupported;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { usePhoneAuth } from './usePhoneAuth';
|
|
2
|
+
export { useClient } from './useClient';
|
|
3
|
+
export { SDKClient } from '../../core/client';
|
|
4
|
+
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
5
|
+
export type { ClientConfig, ClientResponse, RequestOptions } from '../../core/types';
|
|
6
|
+
export type { AuthConfig as PhoneAuthConfig, PhoneAuthOptions, PhoneAuthResult, AuthError, AuthStep } from '../../core/phone-auth';
|
|
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, ConsentData, BrowserErrorType, BrowserErrorCodeType, BrowserNameType } from '../../core/phone-auth/types';
|
|
9
|
+
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
10
|
+
export { USE_CASE, ERROR_CODE, ERROR_MESSAGES, ERROR_STATUS_CODES } from '../../core/phone-auth/api-types';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { usePhoneAuth } from './usePhoneAuth';
|
|
2
|
+
export { useClient } from './useClient';
|
|
3
|
+
export { SDKClient } from '../../core/client';
|
|
4
|
+
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
5
|
+
// API response types are already exported via core/phone-auth/types
|
|
6
|
+
// Export error utilities
|
|
7
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
8
|
+
// Export constants for use case and strategy
|
|
9
|
+
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
|
+
export { USE_CASE, ERROR_CODE, ERROR_MESSAGES, ERROR_STATUS_CODES } from '../../core/phone-auth/api-types';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import type { ClientConfig, ClientResponse } from '../../core/types';
|
|
3
|
+
import type { PhoneAuthResult, AuthError, PhoneAuthOptions } from '../../core/phone-auth';
|
|
4
|
+
export declare function useClient<T>(config: ClientConfig): {
|
|
5
|
+
client: {
|
|
6
|
+
phoneAuth: {
|
|
7
|
+
isSupported: () => boolean;
|
|
8
|
+
getBrowserSupportInfo: () => {
|
|
9
|
+
supported: boolean;
|
|
10
|
+
browser: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
helpUrl?: string;
|
|
13
|
+
};
|
|
14
|
+
verify: (options: PhoneAuthOptions) => Promise<PhoneAuthResult>;
|
|
15
|
+
getPhoneNumberComplete: (options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<PhoneAuthResult>;
|
|
16
|
+
verifyPhoneNumberComplete: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<PhoneAuthResult>;
|
|
17
|
+
preparePhoneRequest: (options: PhoneAuthOptions) => Promise<import("../../core/phone-auth").PrepareResponse>;
|
|
18
|
+
invokeSecurePrompt: (prepareResponse: import("../../core/phone-auth").PrepareResponse, options?: import("../../core/phone-auth").InvokeOptions | import("../..").DesktopAuthOptions) => Promise<import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | import("../../core/phone-auth").HeadlessResult>;
|
|
19
|
+
getPhoneNumber: (credentialResponse: import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | string, session: import("../../core/phone-auth").SessionInfo) => Promise<import("../../core/phone-auth").GetPhoneNumberResponse>;
|
|
20
|
+
verifyPhoneNumber: (credentialResponse: import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | string, session: import("../../core/phone-auth").SessionInfo) => Promise<import("../../core/phone-auth").VerifyPhoneNumberResponse>;
|
|
21
|
+
};
|
|
22
|
+
setToken: (token: string) => void;
|
|
23
|
+
clearToken: () => void;
|
|
24
|
+
get: <T_1 = any>(path: string, options?: import("../../core/types").RequestOptions) => Promise<ClientResponse<T_1>>;
|
|
25
|
+
};
|
|
26
|
+
useQuery: (path: string) => {
|
|
27
|
+
data: [T | null] extends [Ref<any, any>] ? import("@vue/shared").IfAny<Ref<any, any> & T, Ref<Ref<any, any> & T, Ref<any, any> & T>, Ref<any, any> & T> : Ref<import("vue").UnwrapRef<T> | null, T | import("vue").UnwrapRef<T> | null>;
|
|
28
|
+
loading: Ref<boolean, boolean>;
|
|
29
|
+
error: Ref<Error | null, Error | null>;
|
|
30
|
+
refetch: () => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
useAuth: (options?: any) => {
|
|
33
|
+
token: Ref<string | null, string | null>;
|
|
34
|
+
loading: Ref<boolean, boolean>;
|
|
35
|
+
error: Ref<Error | null, Error | null>;
|
|
36
|
+
authenticate: (authUrl: string) => Promise<never>;
|
|
37
|
+
};
|
|
38
|
+
usePhoneAuth: () => {
|
|
39
|
+
result: Ref<{
|
|
40
|
+
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
41
|
+
aud?: string | undefined;
|
|
42
|
+
} | {
|
|
43
|
+
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
44
|
+
verified: boolean;
|
|
45
|
+
aud?: string | undefined;
|
|
46
|
+
} | null, PhoneAuthResult | {
|
|
47
|
+
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
48
|
+
aud?: string | undefined;
|
|
49
|
+
} | {
|
|
50
|
+
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
51
|
+
verified: boolean;
|
|
52
|
+
aud?: string | undefined;
|
|
53
|
+
} | null>;
|
|
54
|
+
loading: Ref<boolean, boolean>;
|
|
55
|
+
error: Ref<{
|
|
56
|
+
code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
57
|
+
message: string;
|
|
58
|
+
details?: any;
|
|
59
|
+
status?: number | undefined;
|
|
60
|
+
requestId?: string | undefined;
|
|
61
|
+
timestamp?: string | undefined;
|
|
62
|
+
traceId?: string | undefined;
|
|
63
|
+
spanId?: string | undefined;
|
|
64
|
+
service?: string | undefined;
|
|
65
|
+
retryAfter?: number | undefined;
|
|
66
|
+
browserError?: {
|
|
67
|
+
name: string;
|
|
68
|
+
message: string;
|
|
69
|
+
stack?: string;
|
|
70
|
+
code?: number;
|
|
71
|
+
} | undefined;
|
|
72
|
+
context?: {
|
|
73
|
+
[x: string]: any;
|
|
74
|
+
step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
75
|
+
useCase?: string | undefined;
|
|
76
|
+
timestamp: string;
|
|
77
|
+
userAgent?: string | undefined;
|
|
78
|
+
url?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
} | null, AuthError | {
|
|
81
|
+
code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
82
|
+
message: string;
|
|
83
|
+
details?: any;
|
|
84
|
+
status?: number | undefined;
|
|
85
|
+
requestId?: string | undefined;
|
|
86
|
+
timestamp?: string | undefined;
|
|
87
|
+
traceId?: string | undefined;
|
|
88
|
+
spanId?: string | undefined;
|
|
89
|
+
service?: string | undefined;
|
|
90
|
+
retryAfter?: number | undefined;
|
|
91
|
+
browserError?: {
|
|
92
|
+
name: string;
|
|
93
|
+
message: string;
|
|
94
|
+
stack?: string;
|
|
95
|
+
code?: number;
|
|
96
|
+
} | undefined;
|
|
97
|
+
context?: {
|
|
98
|
+
[x: string]: any;
|
|
99
|
+
step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
100
|
+
useCase?: string | undefined;
|
|
101
|
+
timestamp: string;
|
|
102
|
+
userAgent?: string | undefined;
|
|
103
|
+
url?: string | undefined;
|
|
104
|
+
} | undefined;
|
|
105
|
+
} | null>;
|
|
106
|
+
isSupported: Ref<boolean, boolean>;
|
|
107
|
+
getPhoneNumber: (options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
108
|
+
verifyPhoneNumber: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
109
|
+
preparePhoneRequest: (options: Parameters<(options: PhoneAuthOptions) => Promise<import("../../core/phone-auth").PrepareResponse>>[0]) => Promise<import("../../core/phone-auth").PrepareResponse>;
|
|
110
|
+
invokeSecurePrompt: (request: Parameters<(prepareResponse: import("../../core/phone-auth").PrepareResponse, options?: import("../../core/phone-auth").InvokeOptions | import("../..").DesktopAuthOptions) => Promise<import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | import("../../core/phone-auth").HeadlessResult>>[0]) => Promise<{
|
|
111
|
+
[aggregator_id: string]: string | string[];
|
|
112
|
+
} | import("../../core/phone-auth").HeadlessResult>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare const useVueClient: typeof useClient;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ref, onUnmounted } from 'vue';
|
|
11
|
+
import { SDKClient } from '../../core/client';
|
|
12
|
+
export function useClient(config) {
|
|
13
|
+
const client = ref(new SDKClient(config));
|
|
14
|
+
return {
|
|
15
|
+
client: client.value,
|
|
16
|
+
useQuery: (path) => {
|
|
17
|
+
const data = ref(null);
|
|
18
|
+
const loading = ref(true);
|
|
19
|
+
const error = ref(null);
|
|
20
|
+
const fetchData = () => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
const response = yield client.value.get(path);
|
|
23
|
+
data.value = response.data;
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
error.value = err;
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
loading.value = false;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
fetchData();
|
|
33
|
+
return { data, loading, error, refetch: fetchData };
|
|
34
|
+
},
|
|
35
|
+
useAuth: (options = {}) => {
|
|
36
|
+
const token = ref(null);
|
|
37
|
+
const loading = ref(false);
|
|
38
|
+
const error = ref(null);
|
|
39
|
+
let cleanup = null;
|
|
40
|
+
const authenticate = (authUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
loading.value = true;
|
|
42
|
+
error.value = null;
|
|
43
|
+
// Clean up previous authentication if exists
|
|
44
|
+
if (cleanup) {
|
|
45
|
+
cleanup();
|
|
46
|
+
cleanup = null;
|
|
47
|
+
}
|
|
48
|
+
// Legacy authentication removed - use setToken directly
|
|
49
|
+
error.value = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
50
|
+
loading.value = false;
|
|
51
|
+
throw error.value;
|
|
52
|
+
});
|
|
53
|
+
// Cleanup on component unmount
|
|
54
|
+
onUnmounted(() => {
|
|
55
|
+
if (cleanup) {
|
|
56
|
+
cleanup();
|
|
57
|
+
cleanup = null;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
token,
|
|
62
|
+
loading,
|
|
63
|
+
error,
|
|
64
|
+
authenticate
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
usePhoneAuth: () => {
|
|
68
|
+
const result = ref(null);
|
|
69
|
+
const loading = ref(false);
|
|
70
|
+
const error = ref(null);
|
|
71
|
+
const isSupported = ref(client.value.phoneAuth.isSupported());
|
|
72
|
+
const getPhoneNumber = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
loading.value = true;
|
|
74
|
+
error.value = null;
|
|
75
|
+
result.value = null;
|
|
76
|
+
try {
|
|
77
|
+
const res = yield client.value.phoneAuth.getPhoneNumberComplete(options);
|
|
78
|
+
result.value = res;
|
|
79
|
+
return res;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
error.value = err;
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
loading.value = false;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const verifyPhoneNumber = (phoneNumber, options) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
loading.value = true;
|
|
91
|
+
error.value = null;
|
|
92
|
+
result.value = null;
|
|
93
|
+
try {
|
|
94
|
+
const res = yield client.value.phoneAuth.verifyPhoneNumberComplete(phoneNumber, options);
|
|
95
|
+
result.value = res;
|
|
96
|
+
return res;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
error.value = err;
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
loading.value = false;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
// Low-level methods for advanced control
|
|
107
|
+
const preparePhoneRequest = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return client.value.phoneAuth.preparePhoneRequest(options);
|
|
109
|
+
});
|
|
110
|
+
const invokeSecurePrompt = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return client.value.phoneAuth.invokeSecurePrompt(request);
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
result,
|
|
115
|
+
loading,
|
|
116
|
+
error,
|
|
117
|
+
isSupported,
|
|
118
|
+
getPhoneNumber,
|
|
119
|
+
verifyPhoneNumber,
|
|
120
|
+
// Low-level API for advanced usage
|
|
121
|
+
preparePhoneRequest,
|
|
122
|
+
invokeSecurePrompt
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export const useVueClient = useClient;
|