@glideidentity/web-client-sdk 5.0.1 → 5.1.1-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.
Files changed (97) hide show
  1. package/README.md +8 -108
  2. package/dist/adapters/angular/index.js +1 -0
  3. package/dist/adapters/angular/phone-auth.service.d.ts +18 -0
  4. package/dist/adapters/angular/phone-auth.service.js +26 -0
  5. package/dist/adapters/react/index.js +3 -0
  6. package/dist/adapters/react/useClient.js +1 -0
  7. package/dist/adapters/react/usePhoneAuth.js +16 -1
  8. package/dist/adapters/vanilla/client.js +1 -0
  9. package/dist/adapters/vanilla/index.js +1 -0
  10. package/dist/adapters/vanilla/phone-auth.js +31 -0
  11. package/dist/adapters/vue/index.js +4 -0
  12. package/dist/adapters/vue/useClient.js +5 -0
  13. package/dist/adapters/vue/usePhoneAuth.js +20 -1
  14. package/dist/browser/web-client-sdk.min.js +1 -2
  15. package/dist/browser.js +6 -0
  16. package/dist/core/client.js +12 -0
  17. package/dist/core/logger.js +81 -1
  18. package/dist/core/phone-auth/api-types.d.ts +1 -4
  19. package/dist/core/phone-auth/api-types.js +83 -0
  20. package/dist/core/phone-auth/client.js +374 -38
  21. package/dist/core/phone-auth/error-utils.js +83 -1
  22. package/dist/core/phone-auth/index.d.ts +1 -1
  23. package/dist/core/phone-auth/index.js +2 -2
  24. package/dist/core/phone-auth/status-types.d.ts +78 -0
  25. package/dist/core/phone-auth/status-types.js +17 -0
  26. package/dist/core/phone-auth/strategies/desktop.d.ts +2 -0
  27. package/dist/core/phone-auth/strategies/desktop.js +136 -13
  28. package/dist/core/phone-auth/strategies/index.d.ts +4 -0
  29. package/dist/core/phone-auth/strategies/index.js +4 -0
  30. package/dist/core/phone-auth/strategies/link.d.ts +2 -0
  31. package/dist/core/phone-auth/strategies/link.js +97 -13
  32. package/dist/core/phone-auth/strategies/ts43.d.ts +19 -0
  33. package/dist/core/phone-auth/strategies/ts43.js +33 -2
  34. package/dist/core/phone-auth/strategies/types.js +4 -0
  35. package/dist/core/phone-auth/type-guards.js +131 -0
  36. package/dist/core/phone-auth/types.d.ts +5 -0
  37. package/dist/core/phone-auth/types.js +32 -0
  38. package/dist/core/phone-auth/ui/mobile-debug-console.js +28 -2
  39. package/dist/core/phone-auth/ui/modal.d.ts +55 -33
  40. package/dist/core/phone-auth/ui/modal.js +422 -889
  41. package/dist/core/phone-auth/validation-utils.d.ts +0 -9
  42. package/dist/core/phone-auth/validation-utils.js +34 -25
  43. package/dist/core/version.js +2 -1
  44. package/dist/esm/adapters/angular/index.js +1 -0
  45. package/dist/esm/adapters/angular/phone-auth.service.d.ts +18 -0
  46. package/dist/esm/adapters/angular/phone-auth.service.js +26 -0
  47. package/dist/esm/adapters/react/index.js +3 -0
  48. package/dist/esm/adapters/react/useClient.js +1 -0
  49. package/dist/esm/adapters/react/usePhoneAuth.js +16 -1
  50. package/dist/esm/adapters/vanilla/client.js +1 -0
  51. package/dist/esm/adapters/vanilla/index.js +1 -0
  52. package/dist/esm/adapters/vanilla/phone-auth.d.ts +24 -0
  53. package/dist/esm/adapters/vanilla/phone-auth.js +31 -0
  54. package/dist/esm/adapters/vue/index.js +4 -0
  55. package/dist/esm/adapters/vue/useClient.js +5 -0
  56. package/dist/esm/adapters/vue/usePhoneAuth.js +20 -1
  57. package/dist/esm/browser.js +6 -0
  58. package/dist/esm/core/client.d.ts +10 -0
  59. package/dist/esm/core/client.js +12 -0
  60. package/dist/esm/core/logger.d.ts +53 -0
  61. package/dist/esm/core/logger.js +81 -1
  62. package/dist/esm/core/phone-auth/api-types.d.ts +313 -1
  63. package/dist/esm/core/phone-auth/api-types.js +83 -0
  64. package/dist/esm/core/phone-auth/client.d.ts +144 -0
  65. package/dist/esm/core/phone-auth/client.js +375 -39
  66. package/dist/esm/core/phone-auth/error-utils.d.ts +29 -0
  67. package/dist/esm/core/phone-auth/error-utils.js +83 -1
  68. package/dist/esm/core/phone-auth/index.d.ts +1 -1
  69. package/dist/esm/core/phone-auth/index.js +4 -2
  70. package/dist/esm/core/phone-auth/status-types.d.ts +78 -0
  71. package/dist/esm/core/phone-auth/status-types.js +17 -0
  72. package/dist/esm/core/phone-auth/strategies/desktop.d.ts +65 -0
  73. package/dist/esm/core/phone-auth/strategies/desktop.js +136 -13
  74. package/dist/esm/core/phone-auth/strategies/index.d.ts +4 -0
  75. package/dist/esm/core/phone-auth/strategies/index.js +4 -0
  76. package/dist/esm/core/phone-auth/strategies/link.d.ts +50 -0
  77. package/dist/esm/core/phone-auth/strategies/link.js +97 -13
  78. package/dist/esm/core/phone-auth/strategies/ts43.d.ts +19 -0
  79. package/dist/esm/core/phone-auth/strategies/ts43.js +33 -2
  80. package/dist/esm/core/phone-auth/strategies/types.d.ts +13 -0
  81. package/dist/esm/core/phone-auth/strategies/types.js +4 -0
  82. package/dist/esm/core/phone-auth/type-guards.d.ts +128 -0
  83. package/dist/esm/core/phone-auth/type-guards.js +131 -0
  84. package/dist/esm/core/phone-auth/types.d.ts +113 -0
  85. package/dist/esm/core/phone-auth/types.js +32 -0
  86. package/dist/esm/core/phone-auth/ui/mobile-debug-console.d.ts +4 -0
  87. package/dist/esm/core/phone-auth/ui/mobile-debug-console.js +28 -2
  88. package/dist/esm/core/phone-auth/ui/modal.d.ts +68 -27
  89. package/dist/esm/core/phone-auth/ui/modal.js +422 -889
  90. package/dist/esm/core/phone-auth/validation-utils.d.ts +26 -4
  91. package/dist/esm/core/phone-auth/validation-utils.js +34 -24
  92. package/dist/esm/core/types.d.ts +35 -0
  93. package/dist/esm/core/version.js +2 -1
  94. package/dist/esm/index.js +9 -1
  95. package/dist/index.js +7 -0
  96. package/package.json +1 -1
  97. package/dist/browser/web-client-sdk.min.js.LICENSE.txt +0 -1
@@ -1,28 +1,61 @@
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
+ // ============================================================================
1
16
  export const USE_CASE = {
2
17
  GET_PHONE_NUMBER: 'GetPhoneNumber',
3
18
  VERIFY_PHONE_NUMBER: 'VerifyPhoneNumber'
4
19
  };
20
+ // ============================================================================
21
+ // AUTHENTICATION STRATEGIES
22
+ // ============================================================================
5
23
  export const AUTHENTICATION_STRATEGY = {
6
24
  TS43: 'ts43',
7
25
  LINK: 'link',
8
26
  DESKTOP: 'desktop'
9
27
  };
28
+ // ============================================================================
29
+ // ERROR HANDLING
30
+ // ============================================================================
31
+ /**
32
+ * Error codes - MUST match server implementation
33
+ */
10
34
  export const ERROR_CODE = {
35
+ // 400 Bad Request
11
36
  INVALID_PHONE_NUMBER: 'INVALID_PHONE_NUMBER',
12
37
  MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
13
38
  INVALID_USE_CASE: 'INVALID_USE_CASE',
39
+ // 404 Not Found
14
40
  INVALID_SESSION: 'INVALID_SESSION',
15
41
  SESSION_EXPIRED: 'SESSION_EXPIRED',
42
+ // 422 Unprocessable Entity
16
43
  CARRIER_NOT_ELIGIBLE: 'CARRIER_NOT_ELIGIBLE',
17
44
  UNSUPPORTED_PLATFORM: 'UNSUPPORTED_PLATFORM',
18
45
  PHONE_NUMBER_MISMATCH: 'PHONE_NUMBER_MISMATCH',
19
46
  INVALID_CREDENTIAL: 'INVALID_CREDENTIAL',
20
47
  VERIFICATION_FAILED: 'VERIFICATION_FAILED',
21
48
  USE_CASE_MISMATCH: 'USE_CASE_MISMATCH',
49
+ // 429 Too Many Requests
22
50
  RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
51
+ // 500 Internal Server Error
23
52
  INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
53
+ // 503 Service Unavailable
24
54
  SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE'
25
55
  };
56
+ /**
57
+ * Error messages - User-friendly messages for each error code
58
+ */
26
59
  export const ERROR_MESSAGES = {
27
60
  [ERROR_CODE.INVALID_PHONE_NUMBER]: "Phone number must be in E.164 format",
28
61
  [ERROR_CODE.MISSING_REQUIRED_FIELD]: "Required field is missing",
@@ -39,6 +72,9 @@ export const ERROR_MESSAGES = {
39
72
  [ERROR_CODE.INTERNAL_SERVER_ERROR]: "An unexpected error occurred",
40
73
  [ERROR_CODE.SERVICE_UNAVAILABLE]: "Service temporarily unavailable"
41
74
  };
75
+ /**
76
+ * HTTP status codes for each error
77
+ */
42
78
  export const ERROR_STATUS_CODES = {
43
79
  [ERROR_CODE.INVALID_PHONE_NUMBER]: 400,
44
80
  [ERROR_CODE.MISSING_REQUIRED_FIELD]: 400,
@@ -55,26 +91,50 @@ export const ERROR_STATUS_CODES = {
55
91
  [ERROR_CODE.INTERNAL_SERVER_ERROR]: 500,
56
92
  [ERROR_CODE.SERVICE_UNAVAILABLE]: 503
57
93
  };
94
+ // ============================================================================
95
+ // VALIDATION HELPERS
96
+ // ============================================================================
97
+ /**
98
+ * E.164 phone number validation regex
99
+ */
58
100
  export const E164_REGEX = /^\+[1-9]\d{1,14}$/;
101
+ /**
102
+ * Validate phone number format
103
+ */
59
104
  export function validatePhoneNumber(phone) {
60
105
  return E164_REGEX.test(phone);
61
106
  }
107
+ /**
108
+ * Validate PLMN format
109
+ */
62
110
  export function validatePLMN(plmn) {
111
+ // MCC: exactly 3 digits
63
112
  if (!/^\d{3}$/.test(plmn.mcc))
64
113
  return false;
114
+ // MNC: 2 or 3 digits
65
115
  if (!/^\d{2,3}$/.test(plmn.mnc))
66
116
  return false;
67
117
  return true;
68
118
  }
119
+ /**
120
+ * Validate session info
121
+ */
69
122
  export function validateSession(session) {
70
123
  if (!session.session_key || session.session_key.length < 16)
71
124
  return false;
125
+ // nonce and enc_key are optional and stored in metadata if needed
72
126
  return true;
73
127
  }
128
+ /**
129
+ * Validate use case
130
+ */
74
131
  export function validateUseCase(useCase) {
75
132
  return useCase === USE_CASE.GET_PHONE_NUMBER ||
76
133
  useCase === USE_CASE.VERIFY_PHONE_NUMBER;
77
134
  }
135
+ /**
136
+ * Create error response helper
137
+ */
78
138
  export function createErrorResponse(code, details, requestId) {
79
139
  return {
80
140
  code,
@@ -84,37 +144,60 @@ export function createErrorResponse(code, details, requestId) {
84
144
  details
85
145
  };
86
146
  }
147
+ /**
148
+ * Get HTTP status code for error
149
+ */
87
150
  export function getErrorStatusCode(code) {
88
151
  return ERROR_STATUS_CODES[code] || 500;
89
152
  }
153
+ // ============================================================================
154
+ // TYPE GUARDS
155
+ // ============================================================================
156
+ /**
157
+ * Check if data is TS43 strategy data
158
+ */
90
159
  export function isTS43Data(data) {
160
+ // Check for TS43 data structure - has protocol and data.dcql_query
91
161
  return data &&
92
162
  typeof data.protocol === 'string' &&
93
163
  data.data &&
94
164
  data.data.dcql_query;
95
165
  }
166
+ /**
167
+ * Check if data is Link strategy data
168
+ */
96
169
  export function isLinkData(data) {
97
170
  return data && data.url && typeof data.url === 'string';
98
171
  }
172
+ /**
173
+ * Check if response is an error
174
+ */
99
175
  export function isErrorResponse(response) {
100
176
  return response &&
101
177
  typeof response.code === 'string' &&
102
178
  typeof response.message === 'string';
103
179
  }
180
+ // ============================================================================
181
+ // EXPORTS FOR CONVENIENCE
182
+ // ============================================================================
104
183
  export default {
184
+ // Constants
105
185
  USE_CASE,
106
186
  AUTHENTICATION_STRATEGY,
107
187
  ERROR_CODE,
108
188
  ERROR_MESSAGES,
109
189
  ERROR_STATUS_CODES,
110
190
  E164_REGEX,
191
+ // Validators
111
192
  validatePhoneNumber,
112
193
  validatePLMN,
113
194
  validateSession,
114
195
  validateUseCase,
196
+ // Type guards
115
197
  isTS43Data,
116
198
  isLinkData,
117
199
  isErrorResponse,
200
+ // Helpers
118
201
  createErrorResponse,
119
202
  getErrorStatusCode
120
203
  };
@@ -12,34 +12,178 @@ 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
+ */
15
18
  private getUserFriendlyMessage;
19
+ /**
20
+ * Log error with proper context and sanitization
21
+ */
16
22
  private logError;
23
+ /**
24
+ * Check if the browser supports secure phone authentication
25
+ */
17
26
  isSupported(): boolean;
27
+ /**
28
+ * Get detailed browser support information
29
+ */
18
30
  getBrowserSupportInfo(): {
19
31
  supported: boolean;
20
32
  browser: string;
21
33
  message?: string;
22
34
  helpUrl?: string;
23
35
  };
36
+ /**
37
+ * Main verification method with silent retry support
38
+ */
24
39
  verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
25
40
  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
+ */
26
45
  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
+ */
27
50
  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
+ */
28
63
  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
+ */
29
109
  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
+ */
30
121
  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
+ */
31
136
  verifyPhoneNumber(credentialResponse: SecureCredentialResponse['vp_token'] | string, session: SessionInfo): Promise<VerifyPhoneNumberResponse>;
137
+ /**
138
+ * Helper to extract credential string from various formats
139
+ */
32
140
  private extractCredentialString;
141
+ /**
142
+ * Helper to extract error details from response
143
+ */
33
144
  private extractErrorDetails;
145
+ /**
146
+ * Fetch with timeout
147
+ */
34
148
  private fetchWithTimeout;
149
+ /**
150
+ * Create an AuthError
151
+ */
35
152
  private createError;
153
+ /**
154
+ * Type guard for AuthError
155
+ */
36
156
  private isAuthError;
157
+ /**
158
+ * Debug logging
159
+ */
37
160
  private log;
161
+ /**
162
+ * Determine if an error should trigger a retry
163
+ */
38
164
  private shouldRetry;
165
+ /**
166
+ * Analyze and enhance errors specific to cross-device flows
167
+ */
39
168
  private analyzeCrossDeviceError;
169
+ /**
170
+ * Cache successful session for retry scenarios
171
+ */
40
172
  private cacheSession;
173
+ /**
174
+ * Retrieve cached session if available and recent
175
+ */
41
176
  private getCachedSession;
177
+ /**
178
+ * Generate cache key for session storage
179
+ */
42
180
  private getCacheKey;
181
+ /**
182
+ * Set up periodic cache cleanup
183
+ */
43
184
  private setupCacheCleanup;
185
+ /**
186
+ * Utility delay function
187
+ */
44
188
  private delay;
45
189
  }