@glideidentity/web-client-sdk 5.1.3 → 6.0.0-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 +337 -526
- package/dist/browser/web-client-sdk.min.js +1 -1
- package/dist/cjs/adapters/index.js +15 -0
- package/dist/cjs/adapters/react.js +192 -0
- package/dist/cjs/adapters/vanilla.js +38 -0
- package/dist/cjs/adapters/vue.js +187 -0
- package/dist/cjs/browser.js +58 -0
- package/dist/cjs/client/http.js +159 -0
- package/dist/cjs/client/index.js +19 -0
- package/dist/cjs/client/logger.js +135 -0
- package/dist/cjs/client/phone-auth-client.js +439 -0
- package/dist/cjs/client/strategies/polling.js +177 -0
- package/dist/cjs/core/errors.js +204 -0
- package/dist/cjs/core/index.js +83 -0
- package/dist/cjs/core/type-guards.js +196 -0
- package/dist/cjs/core/types.js +25 -0
- package/dist/{core/phone-auth/validation-utils.js → cjs/core/validators.js} +70 -23
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/ui/index.js +11 -0
- package/dist/{core/phone-auth → cjs}/ui/mobile-debug-console.js +149 -78
- package/dist/cjs/ui/modal.js +1122 -0
- package/dist/esm/adapters/index.js +11 -0
- package/dist/esm/adapters/react.js +182 -0
- package/dist/esm/adapters/vanilla.js +29 -0
- package/dist/esm/adapters/vue.js +177 -0
- package/dist/esm/browser.js +30 -11
- package/dist/esm/client/http.js +156 -0
- package/dist/esm/client/index.js +11 -0
- package/dist/esm/client/logger.js +131 -0
- package/dist/esm/client/phone-auth-client.js +435 -0
- package/dist/esm/client/strategies/polling.js +174 -0
- package/dist/esm/core/errors.js +193 -0
- package/dist/esm/core/index.js +60 -0
- package/dist/esm/core/type-guards.js +181 -0
- package/dist/esm/core/types.js +22 -1
- package/dist/esm/core/{phone-auth/validation-utils.js → validators.js} +66 -21
- package/dist/esm/index.js +45 -17
- package/dist/esm/ui/index.js +5 -0
- package/dist/esm/{core/phone-auth/ui → ui}/mobile-debug-console.js +149 -78
- package/dist/esm/ui/modal.js +1117 -0
- package/dist/types/adapters/index.d.ts +10 -0
- package/dist/types/adapters/index.d.ts.map +1 -0
- package/dist/types/adapters/react.d.ts +70 -0
- package/dist/types/adapters/react.d.ts.map +1 -0
- package/dist/types/adapters/vanilla.d.ts +29 -0
- package/dist/types/adapters/vanilla.d.ts.map +1 -0
- package/dist/types/adapters/vue.d.ts +71 -0
- package/dist/types/adapters/vue.d.ts.map +1 -0
- package/dist/types/browser.d.ts +27 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/client/http.d.ts +41 -0
- package/dist/types/client/http.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +10 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/logger.d.ts +36 -0
- package/dist/types/client/logger.d.ts.map +1 -0
- package/dist/types/client/phone-auth-client.d.ts +91 -0
- package/dist/types/client/phone-auth-client.d.ts.map +1 -0
- package/dist/types/client/strategies/polling.d.ts +36 -0
- package/dist/types/client/strategies/polling.d.ts.map +1 -0
- package/dist/types/core/errors.d.ts +71 -0
- package/dist/types/core/errors.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +38 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/type-guards.d.ts +118 -0
- package/dist/types/core/type-guards.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +534 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/core/validators.d.ts +63 -0
- package/dist/types/core/validators.d.ts.map +1 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ui/index.d.ts +6 -0
- package/dist/types/ui/index.d.ts.map +1 -0
- package/dist/{esm/core/phone-auth → types}/ui/mobile-debug-console.d.ts +1 -0
- package/dist/types/ui/mobile-debug-console.d.ts.map +1 -0
- package/dist/types/ui/modal.d.ts +87 -0
- package/dist/types/ui/modal.d.ts.map +1 -0
- package/package.json +48 -34
- package/dist/adapters/angular/client.service.d.ts +0 -7
- package/dist/adapters/angular/client.service.js +0 -30
- package/dist/adapters/angular/index.d.ts +0 -3
- package/dist/adapters/angular/index.js +0 -18
- package/dist/adapters/angular/phone-auth.service.d.ts +0 -38
- package/dist/adapters/angular/phone-auth.service.js +0 -130
- package/dist/adapters/react/index.d.ts +0 -9
- package/dist/adapters/react/index.js +0 -28
- package/dist/adapters/react/useClient.d.ts +0 -26
- package/dist/adapters/react/useClient.js +0 -121
- package/dist/adapters/react/usePhoneAuth.d.ts +0 -23
- package/dist/adapters/react/usePhoneAuth.js +0 -95
- package/dist/adapters/vanilla/client.d.ts +0 -8
- package/dist/adapters/vanilla/client.js +0 -33
- package/dist/adapters/vanilla/index.d.ts +0 -3
- package/dist/adapters/vanilla/index.js +0 -18
- package/dist/adapters/vanilla/phone-auth.d.ts +0 -46
- package/dist/adapters/vanilla/phone-auth.js +0 -138
- package/dist/adapters/vue/index.d.ts +0 -10
- package/dist/adapters/vue/index.js +0 -36
- package/dist/adapters/vue/useClient.d.ts +0 -115
- package/dist/adapters/vue/useClient.js +0 -131
- package/dist/adapters/vue/usePhoneAuth.d.ts +0 -94
- package/dist/adapters/vue/usePhoneAuth.js +0 -103
- package/dist/browser.d.ts +0 -7
- package/dist/browser.js +0 -31
- package/dist/core/client.d.ts +0 -22
- package/dist/core/client.js +0 -77
- package/dist/core/logger.d.ts +0 -130
- package/dist/core/logger.js +0 -370
- package/dist/core/phone-auth/api-types.d.ts +0 -593
- package/dist/core/phone-auth/api-types.js +0 -215
- package/dist/core/phone-auth/client.d.ts +0 -189
- package/dist/core/phone-auth/client.js +0 -1441
- package/dist/core/phone-auth/error-utils.d.ts +0 -110
- package/dist/core/phone-auth/error-utils.js +0 -350
- package/dist/core/phone-auth/index.d.ts +0 -7
- package/dist/core/phone-auth/index.js +0 -50
- package/dist/core/phone-auth/status-types.d.ts +0 -107
- package/dist/core/phone-auth/status-types.js +0 -31
- package/dist/core/phone-auth/strategies/desktop.d.ts +0 -122
- package/dist/core/phone-auth/strategies/desktop.js +0 -596
- package/dist/core/phone-auth/strategies/index.d.ts +0 -11
- package/dist/core/phone-auth/strategies/index.js +0 -15
- package/dist/core/phone-auth/strategies/link.d.ts +0 -89
- package/dist/core/phone-auth/strategies/link.js +0 -384
- package/dist/core/phone-auth/strategies/ts43.d.ts +0 -32
- package/dist/core/phone-auth/strategies/ts43.js +0 -161
- package/dist/core/phone-auth/strategies/types.d.ts +0 -18
- package/dist/core/phone-auth/strategies/types.js +0 -6
- package/dist/core/phone-auth/type-guards.d.ts +0 -143
- package/dist/core/phone-auth/type-guards.js +0 -198
- package/dist/core/phone-auth/types.d.ts +0 -237
- package/dist/core/phone-auth/types.js +0 -93
- package/dist/core/phone-auth/ui/mobile-debug-console.d.ts +0 -25
- package/dist/core/phone-auth/ui/modal.d.ts +0 -88
- package/dist/core/phone-auth/ui/modal.js +0 -598
- package/dist/core/phone-auth/validation-utils.d.ts +0 -44
- package/dist/core/types.d.ts +0 -62
- package/dist/core/types.js +0 -2
- package/dist/core/version.d.ts +0 -1
- package/dist/core/version.js +0 -5
- package/dist/esm/adapters/angular/client.service.d.ts +0 -7
- package/dist/esm/adapters/angular/client.service.js +0 -27
- package/dist/esm/adapters/angular/index.d.ts +0 -3
- package/dist/esm/adapters/angular/index.js +0 -4
- package/dist/esm/adapters/angular/phone-auth.service.d.ts +0 -38
- package/dist/esm/adapters/angular/phone-auth.service.js +0 -127
- package/dist/esm/adapters/react/index.d.ts +0 -9
- package/dist/esm/adapters/react/index.js +0 -8
- package/dist/esm/adapters/react/useClient.d.ts +0 -26
- package/dist/esm/adapters/react/useClient.js +0 -116
- package/dist/esm/adapters/react/usePhoneAuth.d.ts +0 -23
- package/dist/esm/adapters/react/usePhoneAuth.js +0 -92
- package/dist/esm/adapters/vanilla/client.d.ts +0 -8
- package/dist/esm/adapters/vanilla/client.js +0 -29
- package/dist/esm/adapters/vanilla/index.d.ts +0 -3
- package/dist/esm/adapters/vanilla/index.js +0 -4
- package/dist/esm/adapters/vanilla/phone-auth.d.ts +0 -46
- package/dist/esm/adapters/vanilla/phone-auth.js +0 -134
- package/dist/esm/adapters/vue/index.d.ts +0 -10
- package/dist/esm/adapters/vue/index.js +0 -11
- package/dist/esm/adapters/vue/useClient.d.ts +0 -115
- package/dist/esm/adapters/vue/useClient.js +0 -127
- package/dist/esm/adapters/vue/usePhoneAuth.d.ts +0 -94
- package/dist/esm/adapters/vue/usePhoneAuth.js +0 -100
- package/dist/esm/browser.d.ts +0 -7
- package/dist/esm/core/client.d.ts +0 -22
- package/dist/esm/core/client.js +0 -70
- package/dist/esm/core/logger.d.ts +0 -130
- package/dist/esm/core/logger.js +0 -359
- package/dist/esm/core/phone-auth/api-types.d.ts +0 -593
- package/dist/esm/core/phone-auth/api-types.js +0 -203
- package/dist/esm/core/phone-auth/client.d.ts +0 -189
- package/dist/esm/core/phone-auth/client.js +0 -1404
- package/dist/esm/core/phone-auth/error-utils.d.ts +0 -110
- package/dist/esm/core/phone-auth/error-utils.js +0 -338
- package/dist/esm/core/phone-auth/index.d.ts +0 -7
- package/dist/esm/core/phone-auth/index.js +0 -8
- package/dist/esm/core/phone-auth/status-types.d.ts +0 -107
- package/dist/esm/core/phone-auth/status-types.js +0 -26
- package/dist/esm/core/phone-auth/strategies/desktop.d.ts +0 -122
- package/dist/esm/core/phone-auth/strategies/desktop.js +0 -590
- package/dist/esm/core/phone-auth/strategies/index.d.ts +0 -11
- package/dist/esm/core/phone-auth/strategies/index.js +0 -7
- package/dist/esm/core/phone-auth/strategies/link.d.ts +0 -89
- package/dist/esm/core/phone-auth/strategies/link.js +0 -380
- package/dist/esm/core/phone-auth/strategies/ts43.d.ts +0 -32
- package/dist/esm/core/phone-auth/strategies/ts43.js +0 -157
- package/dist/esm/core/phone-auth/strategies/types.d.ts +0 -18
- package/dist/esm/core/phone-auth/strategies/types.js +0 -5
- package/dist/esm/core/phone-auth/type-guards.d.ts +0 -143
- package/dist/esm/core/phone-auth/type-guards.js +0 -185
- package/dist/esm/core/phone-auth/types.d.ts +0 -237
- package/dist/esm/core/phone-auth/types.js +0 -76
- package/dist/esm/core/phone-auth/ui/modal.d.ts +0 -88
- package/dist/esm/core/phone-auth/ui/modal.js +0 -594
- package/dist/esm/core/phone-auth/validation-utils.d.ts +0 -44
- package/dist/esm/core/types.d.ts +0 -62
- package/dist/esm/core/version.d.ts +0 -1
- package/dist/esm/core/version.js +0 -2
- package/dist/esm/index.d.ts +0 -12
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -55
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Ref } from 'vue';
|
|
2
|
-
import type { ClientConfig, ClientResponse } from '../../core/types';
|
|
3
|
-
import type { PhoneAuthResult, AuthError, PhoneAuthOptions } from '../../core/phone-auth';
|
|
4
|
-
export declare function useClient<T>(config: ClientConfig): {
|
|
5
|
-
client: {
|
|
6
|
-
phoneAuth: {
|
|
7
|
-
isSupported: () => boolean;
|
|
8
|
-
getBrowserSupportInfo: () => {
|
|
9
|
-
supported: boolean;
|
|
10
|
-
browser: string;
|
|
11
|
-
message?: string;
|
|
12
|
-
helpUrl?: string;
|
|
13
|
-
};
|
|
14
|
-
verify: (options: PhoneAuthOptions) => Promise<PhoneAuthResult>;
|
|
15
|
-
getPhoneNumberComplete: (options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<PhoneAuthResult>;
|
|
16
|
-
verifyPhoneNumberComplete: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<PhoneAuthResult>;
|
|
17
|
-
preparePhoneRequest: (options: PhoneAuthOptions) => Promise<import("../../core/phone-auth").PrepareResponse>;
|
|
18
|
-
invokeSecurePrompt: (prepareResponse: import("../../core/phone-auth").PrepareResponse, options?: import("../../core/phone-auth").InvokeOptions | import("../..").DesktopAuthOptions) => Promise<import("../../core/phone-auth").AuthCredential | import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | import("../../core/phone-auth").AnyExtendedResponse>;
|
|
19
|
-
getPhoneNumber: (credentialResponse: import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | string, session: import("../../core/phone-auth").SessionInfo) => Promise<import("../../core/phone-auth").GetPhoneNumberResponse>;
|
|
20
|
-
verifyPhoneNumber: (credentialResponse: import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | string, session: import("../../core/phone-auth").SessionInfo) => Promise<import("../../core/phone-auth").VerifyPhoneNumberResponse>;
|
|
21
|
-
};
|
|
22
|
-
setToken: (token: string) => void;
|
|
23
|
-
clearToken: () => void;
|
|
24
|
-
get: <T_1 = any>(path: string, options?: import("../../core/types").RequestOptions) => Promise<ClientResponse<T_1>>;
|
|
25
|
-
};
|
|
26
|
-
useQuery: (path: string) => {
|
|
27
|
-
data: [T | null] extends [Ref<any, any>] ? import("@vue/shared").IfAny<Ref<any, any> & T, Ref<Ref<any, any> & T, Ref<any, any> & T>, Ref<any, any> & T> : Ref<import("vue").UnwrapRef<T> | null, T | import("vue").UnwrapRef<T> | null>;
|
|
28
|
-
loading: Ref<boolean, boolean>;
|
|
29
|
-
error: Ref<Error | null, Error | null>;
|
|
30
|
-
refetch: () => Promise<void>;
|
|
31
|
-
};
|
|
32
|
-
useAuth: (options?: any) => {
|
|
33
|
-
token: Ref<string | null, string | null>;
|
|
34
|
-
loading: Ref<boolean, boolean>;
|
|
35
|
-
error: Ref<Error | null, Error | null>;
|
|
36
|
-
authenticate: (authUrl: string) => Promise<never>;
|
|
37
|
-
};
|
|
38
|
-
usePhoneAuth: () => {
|
|
39
|
-
result: Ref<{
|
|
40
|
-
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
41
|
-
aud?: string | undefined;
|
|
42
|
-
} | {
|
|
43
|
-
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
44
|
-
verified: boolean;
|
|
45
|
-
aud?: string | undefined;
|
|
46
|
-
} | null, PhoneAuthResult | {
|
|
47
|
-
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
48
|
-
aud?: string | undefined;
|
|
49
|
-
} | {
|
|
50
|
-
phone_number: import("../../core/phone-auth").PhoneNumber;
|
|
51
|
-
verified: boolean;
|
|
52
|
-
aud?: string | undefined;
|
|
53
|
-
} | null>;
|
|
54
|
-
loading: Ref<boolean, boolean>;
|
|
55
|
-
error: Ref<{
|
|
56
|
-
code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
57
|
-
message: string;
|
|
58
|
-
details?: any;
|
|
59
|
-
status?: number | undefined;
|
|
60
|
-
requestId?: string | undefined;
|
|
61
|
-
timestamp?: string | undefined;
|
|
62
|
-
traceId?: string | undefined;
|
|
63
|
-
spanId?: string | undefined;
|
|
64
|
-
service?: string | undefined;
|
|
65
|
-
retryAfter?: number | undefined;
|
|
66
|
-
browserError?: {
|
|
67
|
-
name: string;
|
|
68
|
-
message: string;
|
|
69
|
-
stack?: string;
|
|
70
|
-
code?: number;
|
|
71
|
-
} | undefined;
|
|
72
|
-
context?: {
|
|
73
|
-
[x: string]: any;
|
|
74
|
-
step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
75
|
-
useCase?: string | undefined;
|
|
76
|
-
timestamp: string;
|
|
77
|
-
userAgent?: string | undefined;
|
|
78
|
-
url?: string | undefined;
|
|
79
|
-
} | undefined;
|
|
80
|
-
} | null, AuthError | {
|
|
81
|
-
code: import("../../core/phone-auth/types").PhoneAuthErrorCode;
|
|
82
|
-
message: string;
|
|
83
|
-
details?: any;
|
|
84
|
-
status?: number | undefined;
|
|
85
|
-
requestId?: string | undefined;
|
|
86
|
-
timestamp?: string | undefined;
|
|
87
|
-
traceId?: string | undefined;
|
|
88
|
-
spanId?: string | undefined;
|
|
89
|
-
service?: string | undefined;
|
|
90
|
-
retryAfter?: number | undefined;
|
|
91
|
-
browserError?: {
|
|
92
|
-
name: string;
|
|
93
|
-
message: string;
|
|
94
|
-
stack?: string;
|
|
95
|
-
code?: number;
|
|
96
|
-
} | undefined;
|
|
97
|
-
context?: {
|
|
98
|
-
[x: string]: any;
|
|
99
|
-
step?: "prepare" | "prompt" | "process" | "complete" | undefined;
|
|
100
|
-
useCase?: string | undefined;
|
|
101
|
-
timestamp: string;
|
|
102
|
-
userAgent?: string | undefined;
|
|
103
|
-
url?: string | undefined;
|
|
104
|
-
} | undefined;
|
|
105
|
-
} | null>;
|
|
106
|
-
isSupported: Ref<boolean, boolean>;
|
|
107
|
-
getPhoneNumber: (options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
108
|
-
verifyPhoneNumber: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
109
|
-
preparePhoneRequest: (options: Parameters<(options: PhoneAuthOptions) => Promise<import("../../core/phone-auth").PrepareResponse>>[0]) => Promise<import("../../core/phone-auth").PrepareResponse>;
|
|
110
|
-
invokeSecurePrompt: (request: Parameters<(prepareResponse: import("../../core/phone-auth").PrepareResponse, options?: import("../../core/phone-auth").InvokeOptions | import("../..").DesktopAuthOptions) => Promise<import("../../core/phone-auth").AuthCredential | import("../../core/phone-auth").SecureCredentialResponse["vp_token"] | import("../../core/phone-auth").AnyExtendedResponse>>[0]) => Promise<{
|
|
111
|
-
[aggregator_id: string]: string | string[];
|
|
112
|
-
} | import("../../core/phone-auth").AuthCredential | import("../../core/phone-auth").AnyExtendedResponse>;
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
export declare const useVueClient: typeof useClient;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.useVueClient = void 0;
|
|
13
|
-
exports.useClient = useClient;
|
|
14
|
-
const vue_1 = require("vue");
|
|
15
|
-
const client_1 = require("../../core/client");
|
|
16
|
-
function useClient(config) {
|
|
17
|
-
const client = (0, vue_1.ref)(new client_1.SDKClient(config));
|
|
18
|
-
return {
|
|
19
|
-
client: client.value,
|
|
20
|
-
useQuery: (path) => {
|
|
21
|
-
const data = (0, vue_1.ref)(null);
|
|
22
|
-
const loading = (0, vue_1.ref)(true);
|
|
23
|
-
const error = (0, vue_1.ref)(null);
|
|
24
|
-
const fetchData = () => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
try {
|
|
26
|
-
const response = yield client.value.get(path);
|
|
27
|
-
data.value = response.data;
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
error.value = err;
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
loading.value = false;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
fetchData();
|
|
37
|
-
return { data, loading, error, refetch: fetchData };
|
|
38
|
-
},
|
|
39
|
-
useAuth: (options = {}) => {
|
|
40
|
-
const token = (0, vue_1.ref)(null);
|
|
41
|
-
const loading = (0, vue_1.ref)(false);
|
|
42
|
-
const error = (0, vue_1.ref)(null);
|
|
43
|
-
let cleanup = null;
|
|
44
|
-
const authenticate = (authUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
loading.value = true;
|
|
46
|
-
error.value = null;
|
|
47
|
-
// Clean up previous authentication if exists
|
|
48
|
-
if (cleanup) {
|
|
49
|
-
cleanup();
|
|
50
|
-
cleanup = null;
|
|
51
|
-
}
|
|
52
|
-
// Legacy authentication removed - use setToken directly
|
|
53
|
-
error.value = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
54
|
-
loading.value = false;
|
|
55
|
-
throw error.value;
|
|
56
|
-
});
|
|
57
|
-
// Cleanup on component unmount
|
|
58
|
-
(0, vue_1.onUnmounted)(() => {
|
|
59
|
-
if (cleanup) {
|
|
60
|
-
cleanup();
|
|
61
|
-
cleanup = null;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
token,
|
|
66
|
-
loading,
|
|
67
|
-
error,
|
|
68
|
-
authenticate
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
usePhoneAuth: () => {
|
|
72
|
-
const result = (0, vue_1.ref)(null);
|
|
73
|
-
const loading = (0, vue_1.ref)(false);
|
|
74
|
-
const error = (0, vue_1.ref)(null);
|
|
75
|
-
const isSupported = (0, vue_1.ref)(client.value.phoneAuth.isSupported());
|
|
76
|
-
const getPhoneNumber = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
loading.value = true;
|
|
78
|
-
error.value = null;
|
|
79
|
-
result.value = null;
|
|
80
|
-
try {
|
|
81
|
-
const res = yield client.value.phoneAuth.getPhoneNumberComplete(options);
|
|
82
|
-
result.value = res;
|
|
83
|
-
return res;
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
error.value = err;
|
|
87
|
-
throw err;
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
loading.value = false;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
const verifyPhoneNumber = (phoneNumber, options) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
loading.value = true;
|
|
95
|
-
error.value = null;
|
|
96
|
-
result.value = null;
|
|
97
|
-
try {
|
|
98
|
-
const res = yield client.value.phoneAuth.verifyPhoneNumberComplete(phoneNumber, options);
|
|
99
|
-
result.value = res;
|
|
100
|
-
return res;
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
error.value = err;
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
loading.value = false;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
// Low-level methods for advanced control
|
|
111
|
-
const preparePhoneRequest = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
return client.value.phoneAuth.preparePhoneRequest(options);
|
|
113
|
-
});
|
|
114
|
-
const invokeSecurePrompt = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
return client.value.phoneAuth.invokeSecurePrompt(request);
|
|
116
|
-
});
|
|
117
|
-
return {
|
|
118
|
-
result,
|
|
119
|
-
loading,
|
|
120
|
-
error,
|
|
121
|
-
isSupported,
|
|
122
|
-
getPhoneNumber,
|
|
123
|
-
verifyPhoneNumber,
|
|
124
|
-
// Low-level API for advanced usage
|
|
125
|
-
preparePhoneRequest,
|
|
126
|
-
invokeSecurePrompt
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
exports.useVueClient = useClient;
|
|
@@ -1,94 +0,0 @@
|
|
|
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.AuthCredential | API.SecureCredentialResponse["vp_token"] | API.AnyExtendedResponse>;
|
|
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
|
-
};
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.usePhoneAuth = usePhoneAuth;
|
|
13
|
-
const vue_1 = require("vue");
|
|
14
|
-
const phone_auth_1 = require("../../core/phone-auth");
|
|
15
|
-
function usePhoneAuth(config = {}) {
|
|
16
|
-
// State management
|
|
17
|
-
const isLoading = (0, vue_1.ref)(false);
|
|
18
|
-
const error = (0, vue_1.ref)(null);
|
|
19
|
-
const result = (0, vue_1.ref)(null);
|
|
20
|
-
const currentStep = (0, vue_1.ref)('idle');
|
|
21
|
-
// Create client instance with callbacks
|
|
22
|
-
const client = new phone_auth_1.PhoneAuthClient(Object.assign(Object.assign({}, config), {
|
|
23
|
-
// Callbacks are now properly typed through AuthConfig
|
|
24
|
-
onCrossDeviceDetected: config.onCrossDeviceDetected, onRetryAttempt: config.onRetryAttempt }));
|
|
25
|
-
// Check browser support
|
|
26
|
-
const isSupported = (0, vue_1.computed)(() => client.isSupported());
|
|
27
|
-
// Verify method - internal wrapper that converts to API format
|
|
28
|
-
const verify = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
isLoading.value = true;
|
|
30
|
-
error.value = null;
|
|
31
|
-
result.value = null;
|
|
32
|
-
currentStep.value = 'requesting';
|
|
33
|
-
try {
|
|
34
|
-
// Step 1: Prepare the request
|
|
35
|
-
const preparedRequest = yield client.preparePhoneRequest(options);
|
|
36
|
-
// Step 2: User authentication
|
|
37
|
-
currentStep.value = 'authenticating';
|
|
38
|
-
const credentialResponse = yield client.invokeSecurePrompt(preparedRequest);
|
|
39
|
-
// Step 3: Process the response through appropriate endpoint
|
|
40
|
-
currentStep.value = 'processing';
|
|
41
|
-
// Cast to credential type - adapters never use headless mode
|
|
42
|
-
const credential = credentialResponse;
|
|
43
|
-
const verificationResult = options.use_case === 'GetPhoneNumber'
|
|
44
|
-
? yield client.getPhoneNumber(credential, preparedRequest.session)
|
|
45
|
-
: yield client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
46
|
-
// Use the result directly - it's already the correct type
|
|
47
|
-
result.value = verificationResult;
|
|
48
|
-
currentStep.value = 'complete';
|
|
49
|
-
return result.value;
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
// Enhance error with context if it's an AuthError
|
|
53
|
-
const authError = err;
|
|
54
|
-
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
55
|
-
useCase: options.use_case,
|
|
56
|
-
timestamp: new Date().toISOString(),
|
|
57
|
-
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,
|
|
58
|
-
url: typeof window !== 'undefined' ? window.location.href : undefined
|
|
59
|
-
} });
|
|
60
|
-
error.value = enhancedError;
|
|
61
|
-
currentStep.value = 'idle';
|
|
62
|
-
throw enhancedError;
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
isLoading.value = false;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
// Convenience methods
|
|
69
|
-
const getPhoneNumber = (options) => verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
70
|
-
const verifyPhoneNumber = (phoneNumber, options) => verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
71
|
-
// Reset state
|
|
72
|
-
const reset = () => {
|
|
73
|
-
isLoading.value = false;
|
|
74
|
-
error.value = null;
|
|
75
|
-
result.value = null;
|
|
76
|
-
currentStep.value = 'idle';
|
|
77
|
-
};
|
|
78
|
-
// Expose granular methods directly from client for better discoverability
|
|
79
|
-
const preparePhoneRequest = client.preparePhoneRequest.bind(client);
|
|
80
|
-
const invokeSecurePrompt = client.invokeSecurePrompt.bind(client);
|
|
81
|
-
const getPhoneNumberCredential = client.getPhoneNumber.bind(client);
|
|
82
|
-
const verifyPhoneNumberCredential = client.verifyPhoneNumber.bind(client);
|
|
83
|
-
return {
|
|
84
|
-
// State (readonly)
|
|
85
|
-
isLoading: (0, vue_1.readonly)(isLoading),
|
|
86
|
-
error: (0, vue_1.readonly)(error),
|
|
87
|
-
result: (0, vue_1.readonly)(result),
|
|
88
|
-
currentStep: (0, vue_1.readonly)(currentStep),
|
|
89
|
-
isSupported: (0, vue_1.readonly)(isSupported),
|
|
90
|
-
// High-level methods
|
|
91
|
-
verify,
|
|
92
|
-
getPhoneNumber,
|
|
93
|
-
verifyPhoneNumber,
|
|
94
|
-
reset,
|
|
95
|
-
// Granular methods (directly exposed for better discoverability)
|
|
96
|
-
preparePhoneRequest,
|
|
97
|
-
invokeSecurePrompt,
|
|
98
|
-
getPhoneNumberCredential,
|
|
99
|
-
verifyPhoneNumberCredential,
|
|
100
|
-
// Client instance (still available for advanced usage)
|
|
101
|
-
client
|
|
102
|
-
};
|
|
103
|
-
}
|
package/dist/browser.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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, 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';
|
package/dist/browser.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Browser-specific entry point for vanilla JavaScript usage
|
|
3
|
-
// This excludes framework-specific adapters that require Angular/React/Vue
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
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
|
-
var phone_auth_1 = require("./core/phone-auth");
|
|
8
|
-
Object.defineProperty(exports, "PhoneAuthClient", { enumerable: true, get: function () { return phone_auth_1.PhoneAuthClient; } });
|
|
9
|
-
// Phone Auth Error Utilities
|
|
10
|
-
var phone_auth_2 = require("./core/phone-auth");
|
|
11
|
-
Object.defineProperty(exports, "PhoneAuthErrorCode", { enumerable: true, get: function () { return phone_auth_2.PhoneAuthErrorCode; } });
|
|
12
|
-
Object.defineProperty(exports, "isPhoneAuthError", { enumerable: true, get: function () { return phone_auth_2.isPhoneAuthError; } });
|
|
13
|
-
Object.defineProperty(exports, "isUserError", { enumerable: true, get: function () { return phone_auth_2.isUserError; } });
|
|
14
|
-
Object.defineProperty(exports, "getUserMessage", { enumerable: true, get: function () { return phone_auth_2.getUserMessage; } });
|
|
15
|
-
Object.defineProperty(exports, "isErrorCode", { enumerable: true, get: function () { return phone_auth_2.isErrorCode; } });
|
|
16
|
-
Object.defineProperty(exports, "getRetryDelay", { enumerable: true, get: function () { return phone_auth_2.getRetryDelay; } });
|
|
17
|
-
Object.defineProperty(exports, "isRetryableError", { enumerable: true, get: function () { return phone_auth_2.isRetryableError; } });
|
|
18
|
-
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return phone_auth_2.serializeError; } });
|
|
19
|
-
Object.defineProperty(exports, "createErrorBreadcrumb", { enumerable: true, get: function () { return phone_auth_2.createErrorBreadcrumb; } });
|
|
20
|
-
// Export constants for use case and strategy
|
|
21
|
-
var types_1 = require("./core/phone-auth/types");
|
|
22
|
-
Object.defineProperty(exports, "UseCase", { enumerable: true, get: function () { return types_1.USE_CASE; } });
|
|
23
|
-
Object.defineProperty(exports, "AuthenticationStrategy", { enumerable: true, get: function () { return types_1.AUTHENTICATION_STRATEGY; } });
|
|
24
|
-
Object.defineProperty(exports, "BrowserError", { enumerable: true, get: function () { return types_1.BrowserError; } });
|
|
25
|
-
Object.defineProperty(exports, "BrowserErrorCode", { enumerable: true, get: function () { return types_1.BrowserErrorCode; } });
|
|
26
|
-
Object.defineProperty(exports, "BrowserName", { enumerable: true, get: function () { return types_1.BrowserName; } });
|
|
27
|
-
// Vanilla adapters ONLY (no framework dependencies)
|
|
28
|
-
var client_1 = require("./adapters/vanilla/client");
|
|
29
|
-
Object.defineProperty(exports, "ClientManager", { enumerable: true, get: function () { return client_1.VanillaClient; } });
|
|
30
|
-
var phone_auth_3 = require("./adapters/vanilla/phone-auth");
|
|
31
|
-
Object.defineProperty(exports, "PhoneAuthManager", { enumerable: true, get: function () { return phone_auth_3.PhoneAuthManager; } });
|
package/dist/core/client.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/core/client.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SDKClient = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const phone_auth_1 = require("./phone-auth");
|
|
18
|
-
class SDKClient {
|
|
19
|
-
constructor(config) {
|
|
20
|
-
this.config = config;
|
|
21
|
-
this.client = axios_1.default.create({
|
|
22
|
-
baseURL: config.baseURL || '',
|
|
23
|
-
timeout: config.timeout || 10000,
|
|
24
|
-
headers: {
|
|
25
|
-
'Content-Type': 'application/json',
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
// Initialize Phone Auth client
|
|
29
|
-
this.phoneAuth = new phone_auth_1.PhoneAuthClient({
|
|
30
|
-
endpoints: config.phoneAuthEndpoints ? {
|
|
31
|
-
prepare: config.phoneAuthEndpoints.prepareRequest,
|
|
32
|
-
process: config.phoneAuthEndpoints.processResponse
|
|
33
|
-
} : undefined,
|
|
34
|
-
debug: config.debug
|
|
35
|
-
});
|
|
36
|
-
// Add authentication interceptor
|
|
37
|
-
this.client.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
if (this.token) {
|
|
39
|
-
config.headers.Authorization = `Bearer ${this.token}`;
|
|
40
|
-
}
|
|
41
|
-
return config;
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Set authentication token for API requests
|
|
46
|
-
*/
|
|
47
|
-
setToken(token) {
|
|
48
|
-
this.token = token;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Clear authentication token
|
|
52
|
-
*/
|
|
53
|
-
clearToken() {
|
|
54
|
-
this.token = undefined;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Make a GET request to the API
|
|
58
|
-
* Note: Requires baseURL to be set in the config
|
|
59
|
-
*/
|
|
60
|
-
get(path, options) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
if (!this.config.baseURL) {
|
|
63
|
-
throw new Error('baseURL is required for making API requests. Please provide it in the ClientConfig.');
|
|
64
|
-
}
|
|
65
|
-
const response = yield this.client.get(path, {
|
|
66
|
-
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
67
|
-
params: options === null || options === void 0 ? void 0 : options.params,
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
data: response.data,
|
|
71
|
-
status: response.status,
|
|
72
|
-
headers: Object.fromEntries(Object.entries(response.headers).map(([k, v]) => [k, String(v)])),
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SDKClient = SDKClient;
|