@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,94 @@
|
|
|
1
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
2
|
+
import type { AuthConfig, AuthStep, PhoneAuthOptions } from '../../core/phone-auth';
|
|
3
|
+
import * as API from '../../core/phone-auth/api-types';
|
|
4
|
+
export interface UsePhoneAuthOptions extends AuthConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare function usePhoneAuth(config?: UsePhoneAuthOptions): {
|
|
7
|
+
isLoading: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
8
|
+
error: Readonly<import("vue").Ref<{
|
|
9
|
+
readonly code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
10
|
+
readonly message: string;
|
|
11
|
+
readonly details?: any;
|
|
12
|
+
readonly status?: number | undefined;
|
|
13
|
+
readonly requestId?: string | undefined;
|
|
14
|
+
readonly timestamp?: string | undefined;
|
|
15
|
+
readonly traceId?: string | undefined;
|
|
16
|
+
readonly spanId?: string | undefined;
|
|
17
|
+
readonly service?: string | undefined;
|
|
18
|
+
readonly retryAfter?: number | undefined;
|
|
19
|
+
readonly browserError?: {
|
|
20
|
+
name: string;
|
|
21
|
+
message: string;
|
|
22
|
+
stack?: string;
|
|
23
|
+
code?: number;
|
|
24
|
+
} | undefined;
|
|
25
|
+
readonly context?: {
|
|
26
|
+
readonly [x: string]: any;
|
|
27
|
+
readonly step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
28
|
+
readonly useCase?: string | undefined;
|
|
29
|
+
readonly timestamp: string;
|
|
30
|
+
readonly userAgent?: string | undefined;
|
|
31
|
+
readonly url?: string | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
} | null, {
|
|
34
|
+
readonly code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
35
|
+
readonly message: string;
|
|
36
|
+
readonly details?: any;
|
|
37
|
+
readonly status?: number | undefined;
|
|
38
|
+
readonly requestId?: string | undefined;
|
|
39
|
+
readonly timestamp?: string | undefined;
|
|
40
|
+
readonly traceId?: string | undefined;
|
|
41
|
+
readonly spanId?: string | undefined;
|
|
42
|
+
readonly service?: string | undefined;
|
|
43
|
+
readonly retryAfter?: number | undefined;
|
|
44
|
+
readonly browserError?: {
|
|
45
|
+
name: string;
|
|
46
|
+
message: string;
|
|
47
|
+
stack?: string;
|
|
48
|
+
code?: number;
|
|
49
|
+
} | undefined;
|
|
50
|
+
readonly context?: {
|
|
51
|
+
readonly [x: string]: any;
|
|
52
|
+
readonly step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
53
|
+
readonly useCase?: string | undefined;
|
|
54
|
+
readonly timestamp: string;
|
|
55
|
+
readonly userAgent?: string | undefined;
|
|
56
|
+
readonly url?: string | undefined;
|
|
57
|
+
} | undefined;
|
|
58
|
+
} | null>>;
|
|
59
|
+
result: Readonly<import("vue").Ref<{
|
|
60
|
+
readonly phone_number: API.PhoneNumber;
|
|
61
|
+
readonly aud?: string | undefined;
|
|
62
|
+
} | {
|
|
63
|
+
readonly phone_number: API.PhoneNumber;
|
|
64
|
+
readonly verified: boolean;
|
|
65
|
+
readonly aud?: string | undefined;
|
|
66
|
+
} | null, {
|
|
67
|
+
readonly phone_number: API.PhoneNumber;
|
|
68
|
+
readonly aud?: string | undefined;
|
|
69
|
+
} | {
|
|
70
|
+
readonly phone_number: API.PhoneNumber;
|
|
71
|
+
readonly verified: boolean;
|
|
72
|
+
readonly aud?: string | undefined;
|
|
73
|
+
} | null>>;
|
|
74
|
+
currentStep: Readonly<import("vue").Ref<AuthStep, AuthStep>>;
|
|
75
|
+
isSupported: Readonly<import("vue").Ref<boolean, boolean>>;
|
|
76
|
+
verify: (options: PhoneAuthOptions) => Promise<{
|
|
77
|
+
phone_number: API.PhoneNumber;
|
|
78
|
+
aud?: string | undefined;
|
|
79
|
+
}>;
|
|
80
|
+
getPhoneNumber: (options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<{
|
|
81
|
+
phone_number: API.PhoneNumber;
|
|
82
|
+
aud?: string | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
verifyPhoneNumber: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<{
|
|
85
|
+
phone_number: API.PhoneNumber;
|
|
86
|
+
aud?: string | undefined;
|
|
87
|
+
}>;
|
|
88
|
+
reset: () => void;
|
|
89
|
+
preparePhoneRequest: (options: PhoneAuthOptions) => Promise<API.PrepareResponse>;
|
|
90
|
+
invokeSecurePrompt: (prepareResponse: API.PrepareResponse, options?: API.InvokeOptions | import("../..").DesktopAuthOptions) => Promise<API.SecureCredentialResponse["vp_token"] | API.HeadlessResult>;
|
|
91
|
+
getPhoneNumberCredential: (credentialResponse: API.SecureCredentialResponse["vp_token"] | string, session: API.SessionInfo) => Promise<API.GetPhoneNumberResponse>;
|
|
92
|
+
verifyPhoneNumberCredential: (credentialResponse: API.SecureCredentialResponse["vp_token"] | string, session: API.SessionInfo) => Promise<API.VerifyPhoneNumberResponse>;
|
|
93
|
+
client: PhoneAuthClient;
|
|
94
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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, computed, readonly } from 'vue';
|
|
11
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
12
|
+
export function usePhoneAuth(config = {}) {
|
|
13
|
+
// State management
|
|
14
|
+
const isLoading = ref(false);
|
|
15
|
+
const error = ref(null);
|
|
16
|
+
const result = ref(null);
|
|
17
|
+
const currentStep = ref('idle');
|
|
18
|
+
// Create client instance with callbacks
|
|
19
|
+
const client = new PhoneAuthClient(Object.assign(Object.assign({}, config), {
|
|
20
|
+
// Callbacks are now properly typed through AuthConfig
|
|
21
|
+
onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt }));
|
|
22
|
+
// Check browser support
|
|
23
|
+
const isSupported = computed(() => client.isSupported());
|
|
24
|
+
// Verify method - internal wrapper that converts to API format
|
|
25
|
+
const verify = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
isLoading.value = true;
|
|
27
|
+
error.value = null;
|
|
28
|
+
result.value = null;
|
|
29
|
+
currentStep.value = 'requesting';
|
|
30
|
+
try {
|
|
31
|
+
// Step 1: Prepare the request
|
|
32
|
+
const preparedRequest = yield client.preparePhoneRequest(options);
|
|
33
|
+
// Step 2: User authentication
|
|
34
|
+
currentStep.value = 'authenticating';
|
|
35
|
+
const credentialResponse = yield client.invokeSecurePrompt(preparedRequest);
|
|
36
|
+
// Step 3: Process the response through appropriate endpoint
|
|
37
|
+
currentStep.value = 'processing';
|
|
38
|
+
// Cast to credential type - adapters never use headless mode
|
|
39
|
+
const credential = credentialResponse;
|
|
40
|
+
const verificationResult = options.use_case === 'GetPhoneNumber'
|
|
41
|
+
? yield client.getPhoneNumber(credential, preparedRequest.session)
|
|
42
|
+
: yield client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
43
|
+
// Use the result directly - it's already the correct type
|
|
44
|
+
result.value = verificationResult;
|
|
45
|
+
currentStep.value = 'complete';
|
|
46
|
+
return result.value;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
// Enhance error with context if it's an AuthError
|
|
50
|
+
const authError = err;
|
|
51
|
+
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
52
|
+
useCase: options.use_case,
|
|
53
|
+
timestamp: new Date().toISOString(),
|
|
54
|
+
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,
|
|
55
|
+
url: typeof window !== 'undefined' ? window.location.href : undefined
|
|
56
|
+
} });
|
|
57
|
+
error.value = enhancedError;
|
|
58
|
+
currentStep.value = 'idle';
|
|
59
|
+
throw enhancedError;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
isLoading.value = false;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Convenience methods
|
|
66
|
+
const getPhoneNumber = (options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
67
|
+
const verifyPhoneNumber = (phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
68
|
+
// Reset state
|
|
69
|
+
const reset = () => {
|
|
70
|
+
isLoading.value = false;
|
|
71
|
+
error.value = null;
|
|
72
|
+
result.value = null;
|
|
73
|
+
currentStep.value = 'idle';
|
|
74
|
+
};
|
|
75
|
+
// Expose granular methods directly from client for better discoverability
|
|
76
|
+
const preparePhoneRequest = client.preparePhoneRequest.bind(client);
|
|
77
|
+
const invokeSecurePrompt = client.invokeSecurePrompt.bind(client);
|
|
78
|
+
const getPhoneNumberCredential = client.getPhoneNumber.bind(client);
|
|
79
|
+
const verifyPhoneNumberCredential = client.verifyPhoneNumber.bind(client);
|
|
80
|
+
return {
|
|
81
|
+
// State (readonly)
|
|
82
|
+
isLoading: readonly(isLoading),
|
|
83
|
+
error: readonly(error),
|
|
84
|
+
result: readonly(result),
|
|
85
|
+
currentStep: readonly(currentStep),
|
|
86
|
+
isSupported: readonly(isSupported),
|
|
87
|
+
// High-level methods
|
|
88
|
+
verify,
|
|
89
|
+
getPhoneNumber,
|
|
90
|
+
verifyPhoneNumber,
|
|
91
|
+
reset,
|
|
92
|
+
// Granular methods (directly exposed for better discoverability)
|
|
93
|
+
preparePhoneRequest,
|
|
94
|
+
invokeSecurePrompt,
|
|
95
|
+
getPhoneNumberCredential,
|
|
96
|
+
verifyPhoneNumberCredential,
|
|
97
|
+
// Client instance (still available for advanced usage)
|
|
98
|
+
client
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { PhoneAuthClient } from './core/phone-auth';
|
|
2
|
+
export type { AuthConfig as PhoneAuthConfig, PhoneAuthOptions, PhoneAuthResult, AuthError as PhoneAuthError, AuthStep as PhoneAuthStep } from './core/phone-auth';
|
|
3
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from './core/phone-auth';
|
|
4
|
+
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';
|
|
5
|
+
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from './core/phone-auth/types';
|
|
6
|
+
export { VanillaClient as ClientManager } from './adapters/vanilla/client';
|
|
7
|
+
export { PhoneAuthManager } from './adapters/vanilla/phone-auth';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Browser-specific entry point for vanilla JavaScript usage
|
|
2
|
+
// This excludes framework-specific adapters that require Angular/React/Vue
|
|
3
|
+
// Phone Authentication - Core client
|
|
4
|
+
export { PhoneAuthClient } from './core/phone-auth';
|
|
5
|
+
// Phone Auth Error Utilities
|
|
6
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from './core/phone-auth';
|
|
7
|
+
// Export constants for use case and strategy
|
|
8
|
+
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from './core/phone-auth/types';
|
|
9
|
+
// Vanilla adapters ONLY (no framework dependencies)
|
|
10
|
+
export { VanillaClient as ClientManager } from './adapters/vanilla/client';
|
|
11
|
+
export { PhoneAuthManager } from './adapters/vanilla/phone-auth';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientConfig, RequestOptions, ClientResponse } from './types';
|
|
2
|
+
import { PhoneAuthClient } from './phone-auth';
|
|
3
|
+
export declare class SDKClient {
|
|
4
|
+
private client;
|
|
5
|
+
private config;
|
|
6
|
+
private token?;
|
|
7
|
+
phoneAuth: PhoneAuthClient;
|
|
8
|
+
constructor(config: ClientConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Set authentication token for API requests
|
|
11
|
+
*/
|
|
12
|
+
setToken(token: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Clear authentication token
|
|
15
|
+
*/
|
|
16
|
+
clearToken(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Make a GET request to the API
|
|
19
|
+
* Note: Requires baseURL to be set in the config
|
|
20
|
+
*/
|
|
21
|
+
get<T = any>(path: string, options?: RequestOptions): Promise<ClientResponse<T>>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 axios from 'axios';
|
|
11
|
+
import { PhoneAuthClient } from './phone-auth';
|
|
12
|
+
export class SDKClient {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.client = axios.create({
|
|
16
|
+
baseURL: config.baseURL || '',
|
|
17
|
+
timeout: config.timeout || 10000,
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
// Initialize Phone Auth client
|
|
23
|
+
this.phoneAuth = new PhoneAuthClient({
|
|
24
|
+
endpoints: config.phoneAuthEndpoints ? {
|
|
25
|
+
prepare: config.phoneAuthEndpoints.prepareRequest,
|
|
26
|
+
process: config.phoneAuthEndpoints.processResponse
|
|
27
|
+
} : undefined,
|
|
28
|
+
debug: config.debug
|
|
29
|
+
});
|
|
30
|
+
// Add authentication interceptor
|
|
31
|
+
this.client.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (this.token) {
|
|
33
|
+
config.headers.Authorization = `Bearer ${this.token}`;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Set authentication token for API requests
|
|
40
|
+
*/
|
|
41
|
+
setToken(token) {
|
|
42
|
+
this.token = token;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clear authentication token
|
|
46
|
+
*/
|
|
47
|
+
clearToken() {
|
|
48
|
+
this.token = undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Make a GET request to the API
|
|
52
|
+
* Note: Requires baseURL to be set in the config
|
|
53
|
+
*/
|
|
54
|
+
get(path, options) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (!this.config.baseURL) {
|
|
57
|
+
throw new Error('baseURL is required for making API requests. Please provide it in the ClientConfig.');
|
|
58
|
+
}
|
|
59
|
+
const response = yield this.client.get(path, {
|
|
60
|
+
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
61
|
+
params: options === null || options === void 0 ? void 0 : options.params,
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
data: response.data,
|
|
65
|
+
status: response.status,
|
|
66
|
+
headers: Object.fromEntries(Object.entries(response.headers).map(([k, v]) => [k, String(v)])),
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Industry-grade logging for Glide Web SDK
|
|
3
|
+
* Following best practices from Stripe, Auth0, Twilio, and AWS Amplify
|
|
4
|
+
*/
|
|
5
|
+
export declare enum LogLevel {
|
|
6
|
+
SILENT = 0,
|
|
7
|
+
ERROR = 1,
|
|
8
|
+
WARN = 2,
|
|
9
|
+
INFO = 3,
|
|
10
|
+
DEBUG = 4
|
|
11
|
+
}
|
|
12
|
+
export interface LogFields {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export interface Logger {
|
|
16
|
+
debug(message: string, fields?: LogFields): void;
|
|
17
|
+
info(message: string, fields?: LogFields): void;
|
|
18
|
+
warn(message: string, fields?: LogFields): void;
|
|
19
|
+
error(message: string, fields?: LogFields): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Default browser console logger with automatic data sanitization
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConsoleLogger implements Logger {
|
|
25
|
+
private level;
|
|
26
|
+
private prefix;
|
|
27
|
+
private enableGrouping;
|
|
28
|
+
constructor(level?: LogLevel, prefix?: string, enableGrouping?: boolean);
|
|
29
|
+
debug(message: string, fields?: LogFields): void;
|
|
30
|
+
info(message: string, fields?: LogFields): void;
|
|
31
|
+
warn(message: string, fields?: LogFields): void;
|
|
32
|
+
error(message: string, fields?: LogFields): void;
|
|
33
|
+
private log;
|
|
34
|
+
/**
|
|
35
|
+
* Sanitize sensitive data from log fields
|
|
36
|
+
*/
|
|
37
|
+
private sanitizeFields;
|
|
38
|
+
/**
|
|
39
|
+
* Redact sensitive information based on field name and value patterns
|
|
40
|
+
*/
|
|
41
|
+
private sanitizeValue;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* No-op logger for when logging is disabled
|
|
45
|
+
*/
|
|
46
|
+
export declare class NoopLogger implements Logger {
|
|
47
|
+
debug(message: string, fields?: LogFields): void;
|
|
48
|
+
info(message: string, fields?: LogFields): void;
|
|
49
|
+
warn(message: string, fields?: LogFields): void;
|
|
50
|
+
error(message: string, fields?: LogFields): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remote logger for sending logs to a backend service
|
|
54
|
+
* Useful for debugging production issues
|
|
55
|
+
*/
|
|
56
|
+
export declare class RemoteLogger implements Logger {
|
|
57
|
+
private endpoint;
|
|
58
|
+
private apiKey;
|
|
59
|
+
private localLogger;
|
|
60
|
+
private buffer;
|
|
61
|
+
private flushInterval;
|
|
62
|
+
private maxBufferSize;
|
|
63
|
+
constructor(endpoint: string, apiKey: string, fallbackLogger?: Logger);
|
|
64
|
+
debug(message: string, fields?: LogFields): void;
|
|
65
|
+
info(message: string, fields?: LogFields): void;
|
|
66
|
+
warn(message: string, fields?: LogFields): void;
|
|
67
|
+
error(message: string, fields?: LogFields): void;
|
|
68
|
+
private log;
|
|
69
|
+
private flush;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parse log level from string
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseLogLevel(level: string): LogLevel;
|
|
75
|
+
/**
|
|
76
|
+
* Get log level from browser environment
|
|
77
|
+
*/
|
|
78
|
+
export declare function getLogLevelFromEnv(): LogLevel;
|
|
79
|
+
/**
|
|
80
|
+
* Performance timer for measuring operation duration
|
|
81
|
+
*/
|
|
82
|
+
export declare class PerformanceTimer {
|
|
83
|
+
private startTime;
|
|
84
|
+
private marks;
|
|
85
|
+
private logger;
|
|
86
|
+
constructor(logger: Logger);
|
|
87
|
+
/**
|
|
88
|
+
* Mark a point in time
|
|
89
|
+
*/
|
|
90
|
+
mark(name: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Log elapsed time with optional fields
|
|
93
|
+
*/
|
|
94
|
+
logElapsed(message: string, fields?: LogFields): void;
|
|
95
|
+
/**
|
|
96
|
+
* Log time between marks
|
|
97
|
+
*/
|
|
98
|
+
logMarkDuration(fromMark: string, toMark: string, message: string, fields?: LogFields): void;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a unique request ID for distributed tracing
|
|
102
|
+
*/
|
|
103
|
+
export declare function generateRequestId(): string;
|
|
104
|
+
/**
|
|
105
|
+
* Logger factory for creating loggers with consistent configuration
|
|
106
|
+
*/
|
|
107
|
+
export declare class LoggerFactory {
|
|
108
|
+
private static defaultLevel;
|
|
109
|
+
private static defaultLogger;
|
|
110
|
+
/**
|
|
111
|
+
* Set the default log level for all new loggers
|
|
112
|
+
*/
|
|
113
|
+
static setDefaultLevel(level: LogLevel): void;
|
|
114
|
+
/**
|
|
115
|
+
* Set a default logger instance to use
|
|
116
|
+
*/
|
|
117
|
+
static setDefaultLogger(logger: Logger): void;
|
|
118
|
+
/**
|
|
119
|
+
* Create a logger instance based on configuration
|
|
120
|
+
*/
|
|
121
|
+
static create(options?: {
|
|
122
|
+
level?: LogLevel;
|
|
123
|
+
prefix?: string;
|
|
124
|
+
remote?: {
|
|
125
|
+
endpoint: string;
|
|
126
|
+
apiKey: string;
|
|
127
|
+
};
|
|
128
|
+
custom?: Logger;
|
|
129
|
+
}): Logger;
|
|
130
|
+
}
|