@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.
Files changed (89) hide show
  1. package/README.md +108 -8
  2. package/dist/adapters/angular/index.js +0 -1
  3. package/dist/adapters/angular/phone-auth.service.d.ts +0 -18
  4. package/dist/adapters/angular/phone-auth.service.js +0 -26
  5. package/dist/adapters/react/index.js +0 -3
  6. package/dist/adapters/react/useClient.js +0 -1
  7. package/dist/adapters/react/usePhoneAuth.js +1 -16
  8. package/dist/adapters/vanilla/client.js +0 -1
  9. package/dist/adapters/vanilla/index.js +0 -1
  10. package/dist/adapters/vanilla/phone-auth.js +0 -31
  11. package/dist/adapters/vue/index.js +0 -4
  12. package/dist/adapters/vue/useClient.js +0 -5
  13. package/dist/adapters/vue/usePhoneAuth.js +1 -20
  14. package/dist/browser/web-client-sdk.min.js +1 -1
  15. package/dist/browser.js +0 -6
  16. package/dist/core/client.js +0 -12
  17. package/dist/core/logger.js +1 -81
  18. package/dist/core/phone-auth/api-types.js +0 -83
  19. package/dist/core/phone-auth/client.js +27 -366
  20. package/dist/core/phone-auth/error-utils.js +1 -83
  21. package/dist/core/phone-auth/index.js +0 -1
  22. package/dist/core/phone-auth/status-types.d.ts +0 -78
  23. package/dist/core/phone-auth/status-types.js +0 -17
  24. package/dist/core/phone-auth/strategies/desktop.js +8 -126
  25. package/dist/core/phone-auth/strategies/index.d.ts +0 -4
  26. package/dist/core/phone-auth/strategies/index.js +0 -4
  27. package/dist/core/phone-auth/strategies/link.js +10 -88
  28. package/dist/core/phone-auth/strategies/ts43.d.ts +0 -19
  29. package/dist/core/phone-auth/strategies/ts43.js +2 -33
  30. package/dist/core/phone-auth/strategies/types.js +0 -4
  31. package/dist/core/phone-auth/type-guards.js +0 -131
  32. package/dist/core/phone-auth/types.js +0 -32
  33. package/dist/core/phone-auth/ui/mobile-debug-console.js +2 -28
  34. package/dist/core/phone-auth/ui/modal.d.ts +33 -55
  35. package/dist/core/phone-auth/ui/modal.js +889 -422
  36. package/dist/core/phone-auth/validation-utils.js +2 -40
  37. package/dist/core/version.js +1 -2
  38. package/dist/esm/adapters/angular/index.js +0 -1
  39. package/dist/esm/adapters/angular/phone-auth.service.d.ts +0 -18
  40. package/dist/esm/adapters/angular/phone-auth.service.js +0 -26
  41. package/dist/esm/adapters/react/index.js +0 -3
  42. package/dist/esm/adapters/react/useClient.js +0 -1
  43. package/dist/esm/adapters/react/usePhoneAuth.js +1 -16
  44. package/dist/esm/adapters/vanilla/client.js +0 -1
  45. package/dist/esm/adapters/vanilla/index.js +0 -1
  46. package/dist/esm/adapters/vanilla/phone-auth.d.ts +0 -24
  47. package/dist/esm/adapters/vanilla/phone-auth.js +0 -31
  48. package/dist/esm/adapters/vue/index.js +0 -4
  49. package/dist/esm/adapters/vue/useClient.js +0 -5
  50. package/dist/esm/adapters/vue/usePhoneAuth.js +1 -20
  51. package/dist/esm/browser.js +0 -6
  52. package/dist/esm/core/client.d.ts +0 -10
  53. package/dist/esm/core/client.js +0 -12
  54. package/dist/esm/core/logger.d.ts +0 -53
  55. package/dist/esm/core/logger.js +1 -81
  56. package/dist/esm/core/phone-auth/api-types.d.ts +0 -315
  57. package/dist/esm/core/phone-auth/api-types.js +0 -83
  58. package/dist/esm/core/phone-auth/client.d.ts +0 -144
  59. package/dist/esm/core/phone-auth/client.js +27 -366
  60. package/dist/esm/core/phone-auth/error-utils.d.ts +0 -29
  61. package/dist/esm/core/phone-auth/error-utils.js +1 -83
  62. package/dist/esm/core/phone-auth/index.js +1 -3
  63. package/dist/esm/core/phone-auth/status-types.d.ts +0 -78
  64. package/dist/esm/core/phone-auth/status-types.js +0 -17
  65. package/dist/esm/core/phone-auth/strategies/desktop.d.ts +0 -63
  66. package/dist/esm/core/phone-auth/strategies/desktop.js +8 -126
  67. package/dist/esm/core/phone-auth/strategies/index.d.ts +0 -4
  68. package/dist/esm/core/phone-auth/strategies/index.js +0 -4
  69. package/dist/esm/core/phone-auth/strategies/link.d.ts +0 -48
  70. package/dist/esm/core/phone-auth/strategies/link.js +10 -88
  71. package/dist/esm/core/phone-auth/strategies/ts43.d.ts +0 -19
  72. package/dist/esm/core/phone-auth/strategies/ts43.js +2 -33
  73. package/dist/esm/core/phone-auth/strategies/types.d.ts +0 -13
  74. package/dist/esm/core/phone-auth/strategies/types.js +0 -4
  75. package/dist/esm/core/phone-auth/type-guards.d.ts +0 -128
  76. package/dist/esm/core/phone-auth/type-guards.js +0 -131
  77. package/dist/esm/core/phone-auth/types.d.ts +0 -108
  78. package/dist/esm/core/phone-auth/types.js +0 -32
  79. package/dist/esm/core/phone-auth/ui/mobile-debug-console.d.ts +0 -4
  80. package/dist/esm/core/phone-auth/ui/mobile-debug-console.js +2 -28
  81. package/dist/esm/core/phone-auth/ui/modal.d.ts +27 -68
  82. package/dist/esm/core/phone-auth/ui/modal.js +889 -422
  83. package/dist/esm/core/phone-auth/validation-utils.d.ts +0 -31
  84. package/dist/esm/core/phone-auth/validation-utils.js +2 -40
  85. package/dist/esm/core/types.d.ts +0 -35
  86. package/dist/esm/core/version.js +1 -2
  87. package/dist/esm/index.js +1 -9
  88. package/dist/index.js +0 -7
  89. package/package.json +1 -1
@@ -1,61 +1,28 @@
1
- /**
2
- * Glide Phone Authentication API Types
3
- *
4
- * This file is copied from the master API specification at /glide-api-types.ts
5
- * It defines the exact contract that ALL implementations must follow.
6
- *
7
- * NAMING CONVENTION:
8
- * - ALL TYPES USE snake_case FOR API COMMUNICATION
9
- * - Frontend SDKs should use snake_case throughout for consistency
10
- * - This eliminates conversion errors and makes debugging easier
11
- * - While not idiomatic JavaScript, it matches the API exactly
12
- */
13
- // ============================================================================
14
- // USE CASES
15
- // ============================================================================
16
1
  export const USE_CASE = {
17
2
  GET_PHONE_NUMBER: 'GetPhoneNumber',
18
3
  VERIFY_PHONE_NUMBER: 'VerifyPhoneNumber'
19
4
  };
20
- // ============================================================================
21
- // AUTHENTICATION STRATEGIES
22
- // ============================================================================
23
5
  export const AUTHENTICATION_STRATEGY = {
24
6
  TS43: 'ts43',
25
7
  LINK: 'link',
26
8
  DESKTOP: 'desktop'
27
9
  };
28
- // ============================================================================
29
- // ERROR HANDLING
30
- // ============================================================================
31
- /**
32
- * Error codes - MUST match server implementation
33
- */
34
10
  export const ERROR_CODE = {
35
- // 400 Bad Request
36
11
  INVALID_PHONE_NUMBER: 'INVALID_PHONE_NUMBER',
37
12
  MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
38
13
  INVALID_USE_CASE: 'INVALID_USE_CASE',
39
- // 404 Not Found
40
14
  INVALID_SESSION: 'INVALID_SESSION',
41
15
  SESSION_EXPIRED: 'SESSION_EXPIRED',
42
- // 422 Unprocessable Entity
43
16
  CARRIER_NOT_ELIGIBLE: 'CARRIER_NOT_ELIGIBLE',
44
17
  UNSUPPORTED_PLATFORM: 'UNSUPPORTED_PLATFORM',
45
18
  PHONE_NUMBER_MISMATCH: 'PHONE_NUMBER_MISMATCH',
46
19
  INVALID_CREDENTIAL: 'INVALID_CREDENTIAL',
47
20
  VERIFICATION_FAILED: 'VERIFICATION_FAILED',
48
21
  USE_CASE_MISMATCH: 'USE_CASE_MISMATCH',
49
- // 429 Too Many Requests
50
22
  RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
51
- // 500 Internal Server Error
52
23
  INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
53
- // 503 Service Unavailable
54
24
  SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE'
55
25
  };
56
- /**
57
- * Error messages - User-friendly messages for each error code
58
- */
59
26
  export const ERROR_MESSAGES = {
60
27
  [ERROR_CODE.INVALID_PHONE_NUMBER]: "Phone number must be in E.164 format",
61
28
  [ERROR_CODE.MISSING_REQUIRED_FIELD]: "Required field is missing",
@@ -72,9 +39,6 @@ export const ERROR_MESSAGES = {
72
39
  [ERROR_CODE.INTERNAL_SERVER_ERROR]: "An unexpected error occurred",
73
40
  [ERROR_CODE.SERVICE_UNAVAILABLE]: "Service temporarily unavailable"
74
41
  };
75
- /**
76
- * HTTP status codes for each error
77
- */
78
42
  export const ERROR_STATUS_CODES = {
79
43
  [ERROR_CODE.INVALID_PHONE_NUMBER]: 400,
80
44
  [ERROR_CODE.MISSING_REQUIRED_FIELD]: 400,
@@ -91,50 +55,26 @@ export const ERROR_STATUS_CODES = {
91
55
  [ERROR_CODE.INTERNAL_SERVER_ERROR]: 500,
92
56
  [ERROR_CODE.SERVICE_UNAVAILABLE]: 503
93
57
  };
94
- // ============================================================================
95
- // VALIDATION HELPERS
96
- // ============================================================================
97
- /**
98
- * E.164 phone number validation regex
99
- */
100
58
  export const E164_REGEX = /^\+[1-9]\d{1,14}$/;
101
- /**
102
- * Validate phone number format
103
- */
104
59
  export function validatePhoneNumber(phone) {
105
60
  return E164_REGEX.test(phone);
106
61
  }
107
- /**
108
- * Validate PLMN format
109
- */
110
62
  export function validatePLMN(plmn) {
111
- // MCC: exactly 3 digits
112
63
  if (!/^\d{3}$/.test(plmn.mcc))
113
64
  return false;
114
- // MNC: 2 or 3 digits
115
65
  if (!/^\d{2,3}$/.test(plmn.mnc))
116
66
  return false;
117
67
  return true;
118
68
  }
119
- /**
120
- * Validate session info
121
- */
122
69
  export function validateSession(session) {
123
70
  if (!session.session_key || session.session_key.length < 16)
124
71
  return false;
125
- // nonce and enc_key are optional and stored in metadata if needed
126
72
  return true;
127
73
  }
128
- /**
129
- * Validate use case
130
- */
131
74
  export function validateUseCase(useCase) {
132
75
  return useCase === USE_CASE.GET_PHONE_NUMBER ||
133
76
  useCase === USE_CASE.VERIFY_PHONE_NUMBER;
134
77
  }
135
- /**
136
- * Create error response helper
137
- */
138
78
  export function createErrorResponse(code, details, requestId) {
139
79
  return {
140
80
  code,
@@ -144,60 +84,37 @@ export function createErrorResponse(code, details, requestId) {
144
84
  details
145
85
  };
146
86
  }
147
- /**
148
- * Get HTTP status code for error
149
- */
150
87
  export function getErrorStatusCode(code) {
151
88
  return ERROR_STATUS_CODES[code] || 500;
152
89
  }
153
- // ============================================================================
154
- // TYPE GUARDS
155
- // ============================================================================
156
- /**
157
- * Check if data is TS43 strategy data
158
- */
159
90
  export function isTS43Data(data) {
160
- // Check for TS43 data structure - has protocol and data.dcql_query
161
91
  return data &&
162
92
  typeof data.protocol === 'string' &&
163
93
  data.data &&
164
94
  data.data.dcql_query;
165
95
  }
166
- /**
167
- * Check if data is Link strategy data
168
- */
169
96
  export function isLinkData(data) {
170
97
  return data && data.url && typeof data.url === 'string';
171
98
  }
172
- /**
173
- * Check if response is an error
174
- */
175
99
  export function isErrorResponse(response) {
176
100
  return response &&
177
101
  typeof response.code === 'string' &&
178
102
  typeof response.message === 'string';
179
103
  }
180
- // ============================================================================
181
- // EXPORTS FOR CONVENIENCE
182
- // ============================================================================
183
104
  export default {
184
- // Constants
185
105
  USE_CASE,
186
106
  AUTHENTICATION_STRATEGY,
187
107
  ERROR_CODE,
188
108
  ERROR_MESSAGES,
189
109
  ERROR_STATUS_CODES,
190
110
  E164_REGEX,
191
- // Validators
192
111
  validatePhoneNumber,
193
112
  validatePLMN,
194
113
  validateSession,
195
114
  validateUseCase,
196
- // Type guards
197
115
  isTS43Data,
198
116
  isLinkData,
199
117
  isErrorResponse,
200
- // Helpers
201
118
  createErrorResponse,
202
119
  getErrorStatusCode
203
120
  };
@@ -12,178 +12,34 @@ export declare class PhoneAuthClient {
12
12
  private baseTimeout;
13
13
  private lastRequest?;
14
14
  constructor(config?: AuthConfig);
15
- /**
16
- * Get user-friendly error message using error utilities
17
- */
18
15
  private getUserFriendlyMessage;
19
- /**
20
- * Log error with proper context and sanitization
21
- */
22
16
  private logError;
23
- /**
24
- * Check if the browser supports secure phone authentication
25
- */
26
17
  isSupported(): boolean;
27
- /**
28
- * Get detailed browser support information
29
- */
30
18
  getBrowserSupportInfo(): {
31
19
  supported: boolean;
32
20
  browser: string;
33
21
  message?: string;
34
22
  helpUrl?: string;
35
23
  };
36
- /**
37
- * Main verification method with silent retry support
38
- */
39
24
  verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
40
25
  private verifyWithRetry;
41
- /**
42
- * High-level method to get phone number (complete flow)
43
- * Handles prepare, credential prompt, and get phone number in one call
44
- */
45
26
  getPhoneNumberComplete(options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
46
- /**
47
- * High-level method to verify phone number (complete flow)
48
- * Handles prepare, credential prompt, and verification in one call
49
- */
50
27
  verifyPhoneNumberComplete(phoneNumber: string, options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
51
- /**
52
- * Step 1: Prepare phone verification request
53
- *
54
- * This method prepares a secure request for phone verification.
55
- * You can use this with your own backend or the glide-sdk-node.
56
- *
57
- * @example
58
- * ```typescript
59
- * const request = await phoneAuthClient.preparePhoneRequest({ useCase: 'GetPhoneNumber' });
60
- * // Handle the request with custom logic
61
- * ```
62
- */
63
28
  preparePhoneRequest(options: PhoneAuthOptions): Promise<PrepareResponse>;
64
- /**
65
- * Step 2: Invoke secure prompt for user consent
66
- *
67
- * This method can work in two modes:
68
- * 1. **UI Mode (default)**: Shows built-in UI components (modals/buttons)
69
- * 2. **Headless Mode**: Returns raw data for custom UI implementation
70
- *
71
- * **Important**: This method automatically handles reactive objects from frameworks
72
- * like Vue.js and React by deep cloning the input. This ensures compatibility with
73
- * browser APIs that expect plain objects.
74
- *
75
- * @example UI Mode (shows modal/button)
76
- * ```typescript
77
- * // Shows SDK's built-in UI
78
- * const credential = await phoneAuth.invokeSecurePrompt(prepareResult);
79
- *
80
- * // Customize the UI
81
- * const credential = await phoneAuth.invokeSecurePrompt(prepareResult, {
82
- * modalOptions: {
83
- * title: 'Verify Your Identity',
84
- * buttonText: 'Continue with Verizon'
85
- * }
86
- * });
87
- * ```
88
- *
89
- * @example Extended Mode (returns control methods)
90
- * ```typescript
91
- * // Get control methods for custom implementation
92
- * const result = await phoneAuth.invokeSecurePrompt(prepareResult, {
93
- * executionMode: 'extended',
94
- * preventDefaultUI: true // Desktop: no modal
95
- * });
96
- *
97
- * if (result.strategy === 'desktop') {
98
- * // Show custom QR UI
99
- * showCustomQR(result.qr_code_data);
100
- * // Start polling
101
- * await result.start_polling();
102
- * }
103
- * ```
104
- *
105
- * @param prepareResponse - Response from prepare() with strategy and data
106
- * @param options - Control UI behavior and response type
107
- * @returns Credential or ExtendedResponse based on executionMode
108
- */
109
29
  invokeSecurePrompt(prepareResponse: PrepareResponse, options?: InvokeOptions | DesktopAuthOptions): Promise<AuthCredential | SecureCredentialResponse['vp_token'] | AnyExtendedResponse>;
110
- /**
111
- * Step 3A: Get phone number from credential
112
- *
113
- * @example
114
- * ```typescript
115
- * const prepareResp = await phoneAuthClient.preparePhoneRequest({ useCase: 'GetPhoneNumber', plmn: {...} });
116
- * const credential = await phoneAuthClient.invokeSecurePrompt(prepareResp);
117
- * const result = await phoneAuthClient.getPhoneNumber(credential, prepareResp.session);
118
- * console.log(result.phone_number); // +1234567890
119
- * ```
120
- */
121
30
  getPhoneNumber(credentialResponse: SecureCredentialResponse['vp_token'] | string, session: SessionInfo): Promise<GetPhoneNumberResponse>;
122
- /**
123
- * Step 3B: Verify phone number with credential
124
- *
125
- * @example
126
- * ```typescript
127
- * const prepareResp = await phoneAuthClient.preparePhoneRequest({
128
- * useCase: 'VerifyPhoneNumber',
129
- * phoneNumber: '+1234567890'
130
- * });
131
- * const credential = await phoneAuthClient.invokeSecurePrompt(prepareResp);
132
- * const result = await phoneAuthClient.verifyPhoneNumber(credential, prepareResp.session);
133
- * console.log(result.verified); // true
134
- * ```
135
- */
136
31
  verifyPhoneNumber(credentialResponse: SecureCredentialResponse['vp_token'] | string, session: SessionInfo): Promise<VerifyPhoneNumberResponse>;
137
- /**
138
- * Helper to extract credential string from various formats
139
- */
140
32
  private extractCredentialString;
141
- /**
142
- * Helper to extract error details from response
143
- */
144
33
  private extractErrorDetails;
145
- /**
146
- * Fetch with timeout
147
- */
148
34
  private fetchWithTimeout;
149
- /**
150
- * Create an AuthError
151
- */
152
35
  private createError;
153
- /**
154
- * Type guard for AuthError
155
- */
156
36
  private isAuthError;
157
- /**
158
- * Debug logging
159
- */
160
37
  private log;
161
- /**
162
- * Determine if an error should trigger a retry
163
- */
164
38
  private shouldRetry;
165
- /**
166
- * Analyze and enhance errors specific to cross-device flows
167
- */
168
39
  private analyzeCrossDeviceError;
169
- /**
170
- * Cache successful session for retry scenarios
171
- */
172
40
  private cacheSession;
173
- /**
174
- * Retrieve cached session if available and recent
175
- */
176
41
  private getCachedSession;
177
- /**
178
- * Generate cache key for session storage
179
- */
180
42
  private getCacheKey;
181
- /**
182
- * Set up periodic cache cleanup
183
- */
184
43
  private setupCacheCleanup;
185
- /**
186
- * Utility delay function
187
- */
188
44
  private delay;
189
45
  }