@glideidentity/web-client-sdk 5.0.0 → 5.0.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 (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
package/dist/browser.js CHANGED
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
- // Browser-specific entry point for vanilla JavaScript usage
3
- // This excludes framework-specific adapters that require Angular/React/Vue
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  exports.PhoneAuthManager = exports.ClientManager = exports.BrowserName = exports.BrowserErrorCode = exports.BrowserError = exports.AuthenticationStrategy = exports.UseCase = exports.createErrorBreadcrumb = exports.serializeError = exports.isRetryableError = exports.getRetryDelay = exports.isErrorCode = exports.getUserMessage = exports.isUserError = exports.isPhoneAuthError = exports.PhoneAuthErrorCode = exports.PhoneAuthClient = void 0;
6
- // Phone Authentication - Core client
7
4
  var phone_auth_1 = require("./core/phone-auth");
8
5
  Object.defineProperty(exports, "PhoneAuthClient", { enumerable: true, get: function () { return phone_auth_1.PhoneAuthClient; } });
9
- // Phone Auth Error Utilities
10
6
  var phone_auth_2 = require("./core/phone-auth");
11
7
  Object.defineProperty(exports, "PhoneAuthErrorCode", { enumerable: true, get: function () { return phone_auth_2.PhoneAuthErrorCode; } });
12
8
  Object.defineProperty(exports, "isPhoneAuthError", { enumerable: true, get: function () { return phone_auth_2.isPhoneAuthError; } });
@@ -17,14 +13,12 @@ Object.defineProperty(exports, "getRetryDelay", { enumerable: true, get: functio
17
13
  Object.defineProperty(exports, "isRetryableError", { enumerable: true, get: function () { return phone_auth_2.isRetryableError; } });
18
14
  Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return phone_auth_2.serializeError; } });
19
15
  Object.defineProperty(exports, "createErrorBreadcrumb", { enumerable: true, get: function () { return phone_auth_2.createErrorBreadcrumb; } });
20
- // Export constants for use case and strategy
21
16
  var types_1 = require("./core/phone-auth/types");
22
17
  Object.defineProperty(exports, "UseCase", { enumerable: true, get: function () { return types_1.USE_CASE; } });
23
18
  Object.defineProperty(exports, "AuthenticationStrategy", { enumerable: true, get: function () { return types_1.AUTHENTICATION_STRATEGY; } });
24
19
  Object.defineProperty(exports, "BrowserError", { enumerable: true, get: function () { return types_1.BrowserError; } });
25
20
  Object.defineProperty(exports, "BrowserErrorCode", { enumerable: true, get: function () { return types_1.BrowserErrorCode; } });
26
21
  Object.defineProperty(exports, "BrowserName", { enumerable: true, get: function () { return types_1.BrowserName; } });
27
- // Vanilla adapters ONLY (no framework dependencies)
28
22
  var client_1 = require("./adapters/vanilla/client");
29
23
  Object.defineProperty(exports, "ClientManager", { enumerable: true, get: function () { return client_1.VanillaClient; } });
30
24
  var phone_auth_3 = require("./adapters/vanilla/phone-auth");
@@ -25,7 +25,6 @@ class SDKClient {
25
25
  'Content-Type': 'application/json',
26
26
  },
27
27
  });
28
- // Initialize Phone Auth client
29
28
  this.phoneAuth = new phone_auth_1.PhoneAuthClient({
30
29
  endpoints: config.phoneAuthEndpoints ? {
31
30
  prepare: config.phoneAuthEndpoints.prepareRequest,
@@ -33,7 +32,6 @@ class SDKClient {
33
32
  } : undefined,
34
33
  debug: config.debug
35
34
  });
36
- // Add authentication interceptor
37
35
  this.client.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
38
36
  if (this.token) {
39
37
  config.headers.Authorization = `Bearer ${this.token}`;
@@ -41,22 +39,12 @@ class SDKClient {
41
39
  return config;
42
40
  }));
43
41
  }
44
- /**
45
- * Set authentication token for API requests
46
- */
47
42
  setToken(token) {
48
43
  this.token = token;
49
44
  }
50
- /**
51
- * Clear authentication token
52
- */
53
45
  clearToken() {
54
46
  this.token = undefined;
55
47
  }
56
- /**
57
- * Make a GET request to the API
58
- * Note: Requires baseURL to be set in the config
59
- */
60
48
  get(path, options) {
61
49
  return __awaiter(this, void 0, void 0, function* () {
62
50
  if (!this.config.baseURL) {
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Industry-grade logging for Glide Web SDK
4
- * Following best practices from Stripe, Auth0, Twilio, and AWS Amplify
5
- */
6
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -25,9 +21,6 @@ var LogLevel;
25
21
  LogLevel[LogLevel["INFO"] = 3] = "INFO";
26
22
  LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
27
23
  })(LogLevel || (exports.LogLevel = LogLevel = {}));
28
- /**
29
- * Default browser console logger with automatic data sanitization
30
- */
31
24
  class ConsoleLogger {
32
25
  constructor(level = LogLevel.SILENT, prefix = '[Glide]', enableGrouping = false) {
33
26
  this.level = level;
@@ -57,9 +50,7 @@ class ConsoleLogger {
57
50
  log(level, message, fields) {
58
51
  const timestamp = new Date().toISOString();
59
52
  const sanitizedFields = fields ? this.sanitizeFields(fields) : {};
60
- // Format the message
61
53
  const formattedMessage = `${this.prefix} ${timestamp} [${level.toUpperCase()}] ${message}`;
62
- // Use console grouping for better readability if enabled
63
54
  if (this.enableGrouping && Object.keys(sanitizedFields).length > 0) {
64
55
  console.groupCollapsed(formattedMessage);
65
56
  Object.entries(sanitizedFields).forEach(([key, value]) => {
@@ -68,7 +59,6 @@ class ConsoleLogger {
68
59
  console.groupEnd();
69
60
  }
70
61
  else {
71
- // Standard logging with or without fields
72
62
  if (Object.keys(sanitizedFields).length > 0) {
73
63
  console[level](formattedMessage, sanitizedFields);
74
64
  }
@@ -77,9 +67,6 @@ class ConsoleLogger {
77
67
  }
78
68
  }
79
69
  }
80
- /**
81
- * Sanitize sensitive data from log fields
82
- */
83
70
  sanitizeFields(fields) {
84
71
  const sanitized = {};
85
72
  for (const [key, value] of Object.entries(fields)) {
@@ -87,11 +74,7 @@ class ConsoleLogger {
87
74
  }
88
75
  return sanitized;
89
76
  }
90
- /**
91
- * Redact sensitive information based on field name and value patterns
92
- */
93
77
  sanitizeValue(key, value) {
94
- // List of sensitive field patterns
95
78
  const sensitiveFields = [
96
79
  'apikey', 'api_key', 'apiKey',
97
80
  'token', 'accesstoken', 'access_token', 'accessToken',
@@ -101,7 +84,6 @@ class ConsoleLogger {
101
84
  'cookie', 'session',
102
85
  ];
103
86
  const lowerKey = key.toLowerCase();
104
- // Check if field name indicates sensitive data
105
87
  for (const sensitive of sensitiveFields) {
106
88
  if (lowerKey.includes(sensitive.toLowerCase())) {
107
89
  if (typeof value === 'string' && value.length > 4) {
@@ -110,38 +92,30 @@ class ConsoleLogger {
110
92
  return '****[REDACTED]';
111
93
  }
112
94
  }
113
- // Handle specific value patterns
114
95
  if (typeof value === 'string') {
115
- // Phone number pattern - show area code only
116
96
  const phoneRegex = /^\+?[1-9]\d{6,14}$/;
117
97
  if (phoneRegex.test(value)) {
118
98
  return value.substring(0, 6) + '****';
119
99
  }
120
- // Email pattern - show domain only
121
100
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
122
101
  if (emailRegex.test(value)) {
123
102
  const [, domain] = value.split('@');
124
103
  return '****@' + domain;
125
104
  }
126
- // URL with credentials
127
105
  if (value.includes('://') && value.includes('@')) {
128
106
  return value.replace(/\/\/([^:]+):([^@]+)@/, '//****:****@');
129
107
  }
130
- // JWT tokens
131
108
  if (value.startsWith('eyJ') && value.split('.').length === 3) {
132
109
  return value.substring(0, 10) + '****[JWT]';
133
110
  }
134
- // Credit card numbers
135
111
  const creditCardRegex = /\b\d{13,19}\b/;
136
112
  if (creditCardRegex.test(value)) {
137
113
  return value.substring(0, 4) + '****' + value.substring(value.length - 4);
138
114
  }
139
115
  }
140
- // Recursively sanitize objects
141
116
  if (value && typeof value === 'object' && !Array.isArray(value)) {
142
117
  return this.sanitizeFields(value);
143
118
  }
144
- // Sanitize arrays
145
119
  if (Array.isArray(value)) {
146
120
  return value.map((item, index) => this.sanitizeValue(`${key}[${index}]`, item));
147
121
  }
@@ -149,9 +123,6 @@ class ConsoleLogger {
149
123
  }
150
124
  }
151
125
  exports.ConsoleLogger = ConsoleLogger;
152
- /**
153
- * No-op logger for when logging is disabled
154
- */
155
126
  class NoopLogger {
156
127
  debug(message, fields) { }
157
128
  info(message, fields) { }
@@ -159,22 +130,16 @@ class NoopLogger {
159
130
  error(message, fields) { }
160
131
  }
161
132
  exports.NoopLogger = NoopLogger;
162
- /**
163
- * Remote logger for sending logs to a backend service
164
- * Useful for debugging production issues
165
- */
166
133
  class RemoteLogger {
167
134
  constructor(endpoint, apiKey, fallbackLogger) {
168
135
  this.buffer = [];
169
- this.flushInterval = 5000; // 5 seconds
136
+ this.flushInterval = 5000;
170
137
  this.maxBufferSize = 100;
171
138
  this.endpoint = endpoint;
172
139
  this.apiKey = apiKey;
173
140
  this.localLogger = fallbackLogger || new ConsoleLogger(LogLevel.ERROR);
174
- // Set up automatic flushing
175
141
  if (typeof window !== 'undefined') {
176
142
  setInterval(() => this.flush(), this.flushInterval);
177
- // Flush on page unload
178
143
  window.addEventListener('beforeunload', () => this.flush());
179
144
  }
180
145
  }
@@ -200,9 +165,7 @@ class RemoteLogger {
200
165
  url: typeof window !== 'undefined' ? window.location.href : undefined,
201
166
  };
202
167
  this.buffer.push(logEntry);
203
- // Also log locally for immediate feedback
204
168
  this.localLogger[level](message, fields);
205
- // Flush if buffer is full
206
169
  if (this.buffer.length >= this.maxBufferSize) {
207
170
  this.flush();
208
171
  }
@@ -224,18 +187,12 @@ class RemoteLogger {
224
187
  });
225
188
  }
226
189
  catch (error) {
227
- // Failed to send logs, log locally
228
190
  this.localLogger.error('Failed to send logs to remote server', { error });
229
- // Optionally, put logs back in buffer for retry
230
- // this.buffer.unshift(...logs);
231
191
  }
232
192
  });
233
193
  }
234
194
  }
235
195
  exports.RemoteLogger = RemoteLogger;
236
- /**
237
- * Parse log level from string
238
- */
239
196
  function parseLogLevel(level) {
240
197
  switch (level.toLowerCase()) {
241
198
  case 'debug':
@@ -255,11 +212,7 @@ function parseLogLevel(level) {
255
212
  return LogLevel.SILENT;
256
213
  }
257
214
  }
258
- /**
259
- * Get log level from browser environment
260
- */
261
215
  function getLogLevelFromEnv() {
262
- // Check localStorage
263
216
  if (typeof localStorage !== 'undefined') {
264
217
  const storedLevel = localStorage.getItem('GLIDE_LOG_LEVEL');
265
218
  if (storedLevel) {
@@ -270,7 +223,6 @@ function getLogLevelFromEnv() {
270
223
  return LogLevel.DEBUG;
271
224
  }
272
225
  }
273
- // Check URL parameters
274
226
  if (typeof window !== 'undefined' && window.location) {
275
227
  const params = new URLSearchParams(window.location.search);
276
228
  const urlLogLevel = params.get('glide_log_level');
@@ -283,31 +235,19 @@ function getLogLevelFromEnv() {
283
235
  }
284
236
  return LogLevel.SILENT;
285
237
  }
286
- /**
287
- * Performance timer for measuring operation duration
288
- */
289
238
  class PerformanceTimer {
290
239
  constructor(logger) {
291
240
  this.marks = new Map();
292
241
  this.startTime = performance.now();
293
242
  this.logger = logger;
294
243
  }
295
- /**
296
- * Mark a point in time
297
- */
298
244
  mark(name) {
299
245
  this.marks.set(name, performance.now());
300
246
  }
301
- /**
302
- * Log elapsed time with optional fields
303
- */
304
247
  logElapsed(message, fields) {
305
248
  const elapsed = performance.now() - this.startTime;
306
249
  this.logger.debug(message, Object.assign(Object.assign({}, fields), { elapsedMs: elapsed, elapsed: `${elapsed.toFixed(2)}ms` }));
307
250
  }
308
- /**
309
- * Log time between marks
310
- */
311
251
  logMarkDuration(fromMark, toMark, message, fields) {
312
252
  const from = this.marks.get(fromMark);
313
253
  const to = this.marks.get(toMark);
@@ -319,49 +259,29 @@ class PerformanceTimer {
319
259
  }
320
260
  }
321
261
  exports.PerformanceTimer = PerformanceTimer;
322
- /**
323
- * Generate a unique request ID for distributed tracing
324
- */
325
262
  function generateRequestId() {
326
263
  return `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
327
264
  }
328
- /**
329
- * Logger factory for creating loggers with consistent configuration
330
- */
331
265
  class LoggerFactory {
332
- /**
333
- * Set the default log level for all new loggers
334
- */
335
266
  static setDefaultLevel(level) {
336
267
  this.defaultLevel = level;
337
268
  }
338
- /**
339
- * Set a default logger instance to use
340
- */
341
269
  static setDefaultLogger(logger) {
342
270
  this.defaultLogger = logger;
343
271
  }
344
- /**
345
- * Create a logger instance based on configuration
346
- */
347
272
  static create(options) {
348
273
  var _a, _b;
349
- // Use custom logger if provided
350
274
  if (options === null || options === void 0 ? void 0 : options.custom) {
351
275
  return options.custom;
352
276
  }
353
- // Use default logger if set
354
277
  if (this.defaultLogger) {
355
278
  return this.defaultLogger;
356
279
  }
357
- // Determine log level
358
280
  const level = (_b = (_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : getLogLevelFromEnv()) !== null && _b !== void 0 ? _b : this.defaultLevel;
359
- // Create remote logger if configured
360
281
  if (options === null || options === void 0 ? void 0 : options.remote) {
361
282
  const fallbackLogger = new ConsoleLogger(level, options === null || options === void 0 ? void 0 : options.prefix);
362
283
  return new RemoteLogger(options.remote.endpoint, options.remote.apiKey, fallbackLogger);
363
284
  }
364
- // Create console logger
365
285
  return new ConsoleLogger(level, options === null || options === void 0 ? void 0 : options.prefix);
366
286
  }
367
287
  }
@@ -1,16 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Glide Phone Authentication API Types
4
- *
5
- * This file is copied from the master API specification at /glide-api-types.ts
6
- * It defines the exact contract that ALL implementations must follow.
7
- *
8
- * NAMING CONVENTION:
9
- * - ALL TYPES USE snake_case FOR API COMMUNICATION
10
- * - Frontend SDKs should use snake_case throughout for consistency
11
- * - This eliminates conversion errors and makes debugging easier
12
- * - While not idiomatic JavaScript, it matches the API exactly
13
- */
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.E164_REGEX = exports.ERROR_STATUS_CODES = exports.ERROR_MESSAGES = exports.ERROR_CODE = exports.AUTHENTICATION_STRATEGY = exports.USE_CASE = void 0;
16
4
  exports.validatePhoneNumber = validatePhoneNumber;
@@ -22,52 +10,31 @@ exports.getErrorStatusCode = getErrorStatusCode;
22
10
  exports.isTS43Data = isTS43Data;
23
11
  exports.isLinkData = isLinkData;
24
12
  exports.isErrorResponse = isErrorResponse;
25
- // ============================================================================
26
- // USE CASES
27
- // ============================================================================
28
13
  exports.USE_CASE = {
29
14
  GET_PHONE_NUMBER: 'GetPhoneNumber',
30
15
  VERIFY_PHONE_NUMBER: 'VerifyPhoneNumber'
31
16
  };
32
- // ============================================================================
33
- // AUTHENTICATION STRATEGIES
34
- // ============================================================================
35
17
  exports.AUTHENTICATION_STRATEGY = {
36
18
  TS43: 'ts43',
37
19
  LINK: 'link',
38
20
  DESKTOP: 'desktop'
39
21
  };
40
- // ============================================================================
41
- // ERROR HANDLING
42
- // ============================================================================
43
- /**
44
- * Error codes - MUST match server implementation
45
- */
46
22
  exports.ERROR_CODE = {
47
- // 400 Bad Request
48
23
  INVALID_PHONE_NUMBER: 'INVALID_PHONE_NUMBER',
49
24
  MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
50
25
  INVALID_USE_CASE: 'INVALID_USE_CASE',
51
- // 404 Not Found
52
26
  INVALID_SESSION: 'INVALID_SESSION',
53
27
  SESSION_EXPIRED: 'SESSION_EXPIRED',
54
- // 422 Unprocessable Entity
55
28
  CARRIER_NOT_ELIGIBLE: 'CARRIER_NOT_ELIGIBLE',
56
29
  UNSUPPORTED_PLATFORM: 'UNSUPPORTED_PLATFORM',
57
30
  PHONE_NUMBER_MISMATCH: 'PHONE_NUMBER_MISMATCH',
58
31
  INVALID_CREDENTIAL: 'INVALID_CREDENTIAL',
59
32
  VERIFICATION_FAILED: 'VERIFICATION_FAILED',
60
33
  USE_CASE_MISMATCH: 'USE_CASE_MISMATCH',
61
- // 429 Too Many Requests
62
34
  RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
63
- // 500 Internal Server Error
64
35
  INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
65
- // 503 Service Unavailable
66
36
  SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE'
67
37
  };
68
- /**
69
- * Error messages - User-friendly messages for each error code
70
- */
71
38
  exports.ERROR_MESSAGES = {
72
39
  [exports.ERROR_CODE.INVALID_PHONE_NUMBER]: "Phone number must be in E.164 format",
73
40
  [exports.ERROR_CODE.MISSING_REQUIRED_FIELD]: "Required field is missing",
@@ -84,9 +51,6 @@ exports.ERROR_MESSAGES = {
84
51
  [exports.ERROR_CODE.INTERNAL_SERVER_ERROR]: "An unexpected error occurred",
85
52
  [exports.ERROR_CODE.SERVICE_UNAVAILABLE]: "Service temporarily unavailable"
86
53
  };
87
- /**
88
- * HTTP status codes for each error
89
- */
90
54
  exports.ERROR_STATUS_CODES = {
91
55
  [exports.ERROR_CODE.INVALID_PHONE_NUMBER]: 400,
92
56
  [exports.ERROR_CODE.MISSING_REQUIRED_FIELD]: 400,
@@ -103,50 +67,26 @@ exports.ERROR_STATUS_CODES = {
103
67
  [exports.ERROR_CODE.INTERNAL_SERVER_ERROR]: 500,
104
68
  [exports.ERROR_CODE.SERVICE_UNAVAILABLE]: 503
105
69
  };
106
- // ============================================================================
107
- // VALIDATION HELPERS
108
- // ============================================================================
109
- /**
110
- * E.164 phone number validation regex
111
- */
112
70
  exports.E164_REGEX = /^\+[1-9]\d{1,14}$/;
113
- /**
114
- * Validate phone number format
115
- */
116
71
  function validatePhoneNumber(phone) {
117
72
  return exports.E164_REGEX.test(phone);
118
73
  }
119
- /**
120
- * Validate PLMN format
121
- */
122
74
  function validatePLMN(plmn) {
123
- // MCC: exactly 3 digits
124
75
  if (!/^\d{3}$/.test(plmn.mcc))
125
76
  return false;
126
- // MNC: 2 or 3 digits
127
77
  if (!/^\d{2,3}$/.test(plmn.mnc))
128
78
  return false;
129
79
  return true;
130
80
  }
131
- /**
132
- * Validate session info
133
- */
134
81
  function validateSession(session) {
135
82
  if (!session.session_key || session.session_key.length < 16)
136
83
  return false;
137
- // nonce and enc_key are optional and stored in metadata if needed
138
84
  return true;
139
85
  }
140
- /**
141
- * Validate use case
142
- */
143
86
  function validateUseCase(useCase) {
144
87
  return useCase === exports.USE_CASE.GET_PHONE_NUMBER ||
145
88
  useCase === exports.USE_CASE.VERIFY_PHONE_NUMBER;
146
89
  }
147
- /**
148
- * Create error response helper
149
- */
150
90
  function createErrorResponse(code, details, requestId) {
151
91
  return {
152
92
  code,
@@ -156,60 +96,37 @@ function createErrorResponse(code, details, requestId) {
156
96
  details
157
97
  };
158
98
  }
159
- /**
160
- * Get HTTP status code for error
161
- */
162
99
  function getErrorStatusCode(code) {
163
100
  return exports.ERROR_STATUS_CODES[code] || 500;
164
101
  }
165
- // ============================================================================
166
- // TYPE GUARDS
167
- // ============================================================================
168
- /**
169
- * Check if data is TS43 strategy data
170
- */
171
102
  function isTS43Data(data) {
172
- // Check for TS43 data structure - has protocol and data.dcql_query
173
103
  return data &&
174
104
  typeof data.protocol === 'string' &&
175
105
  data.data &&
176
106
  data.data.dcql_query;
177
107
  }
178
- /**
179
- * Check if data is Link strategy data
180
- */
181
108
  function isLinkData(data) {
182
109
  return data && data.url && typeof data.url === 'string';
183
110
  }
184
- /**
185
- * Check if response is an error
186
- */
187
111
  function isErrorResponse(response) {
188
112
  return response &&
189
113
  typeof response.code === 'string' &&
190
114
  typeof response.message === 'string';
191
115
  }
192
- // ============================================================================
193
- // EXPORTS FOR CONVENIENCE
194
- // ============================================================================
195
116
  exports.default = {
196
- // Constants
197
117
  USE_CASE: exports.USE_CASE,
198
118
  AUTHENTICATION_STRATEGY: exports.AUTHENTICATION_STRATEGY,
199
119
  ERROR_CODE: exports.ERROR_CODE,
200
120
  ERROR_MESSAGES: exports.ERROR_MESSAGES,
201
121
  ERROR_STATUS_CODES: exports.ERROR_STATUS_CODES,
202
122
  E164_REGEX: exports.E164_REGEX,
203
- // Validators
204
123
  validatePhoneNumber,
205
124
  validatePLMN,
206
125
  validateSession,
207
126
  validateUseCase,
208
- // Type guards
209
127
  isTS43Data,
210
128
  isLinkData,
211
129
  isErrorResponse,
212
- // Helpers
213
130
  createErrorResponse,
214
131
  getErrorStatusCode
215
132
  };