@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,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation utilities for phone authentication
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validatePhoneNumber = validatePhoneNumber;
|
|
7
|
+
exports.validatePlmn = validatePlmn;
|
|
8
|
+
exports.validateUseCaseRequirements = validateUseCaseRequirements;
|
|
9
|
+
exports.validateConsentData = validateConsentData;
|
|
10
|
+
exports.createValidationError = createValidationError;
|
|
11
|
+
exports.validateNonce = validateNonce;
|
|
12
|
+
const api_types_1 = require("./api-types");
|
|
13
|
+
/**
|
|
14
|
+
* Validates E.164 phone number format
|
|
15
|
+
* @param phoneNumber - Phone number to validate
|
|
16
|
+
* @returns Validation result with error if invalid
|
|
17
|
+
*/
|
|
18
|
+
function validatePhoneNumber(phoneNumber) {
|
|
19
|
+
if (!phoneNumber) {
|
|
20
|
+
return { valid: true }; // Phone number is optional for GetPhoneNumber
|
|
21
|
+
}
|
|
22
|
+
// E.164 format validation - strict, no cleaning
|
|
23
|
+
const e164Regex = /^\+[1-9]\d{1,14}$/;
|
|
24
|
+
if (!phoneNumber.startsWith('+')) {
|
|
25
|
+
return {
|
|
26
|
+
valid: false,
|
|
27
|
+
error: 'Phone number must be in E.164 format (start with +)'
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (phoneNumber.length < 8) {
|
|
31
|
+
return {
|
|
32
|
+
valid: false,
|
|
33
|
+
error: 'Phone number too short for E.164 format (minimum 8 characters including +)'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (phoneNumber.length > 16) {
|
|
37
|
+
return {
|
|
38
|
+
valid: false,
|
|
39
|
+
error: 'Phone number too long for E.164 format (maximum 15 digits after +)'
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Check for any invalid characters (spaces, dashes, parentheses, etc.)
|
|
43
|
+
if (!/^\+\d+$/.test(phoneNumber)) {
|
|
44
|
+
return {
|
|
45
|
+
valid: false,
|
|
46
|
+
error: 'Phone number contains invalid characters. E.164 format only allows + followed by digits'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (!e164Regex.test(phoneNumber)) {
|
|
50
|
+
return {
|
|
51
|
+
valid: false,
|
|
52
|
+
error: 'Invalid E.164 phone number format'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { valid: true };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Validates PLMN (MCC/MNC) values
|
|
59
|
+
* @param plmn - PLMN object with MCC and MNC
|
|
60
|
+
* @returns Validation result
|
|
61
|
+
*/
|
|
62
|
+
function validatePlmn(plmn) {
|
|
63
|
+
if (!plmn) {
|
|
64
|
+
return { valid: true }; // PLMN is optional
|
|
65
|
+
}
|
|
66
|
+
const { mcc, mnc } = plmn;
|
|
67
|
+
// MCC validation (3 digits) - no range check for telco labs
|
|
68
|
+
if (!mcc || !/^\d{3}$/.test(mcc)) {
|
|
69
|
+
return {
|
|
70
|
+
valid: false,
|
|
71
|
+
error: 'MCC must be exactly 3 digits'
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// MNC validation (2 or 3 digits)
|
|
75
|
+
if (!mnc || !/^\d{2,3}$/.test(mnc)) {
|
|
76
|
+
return {
|
|
77
|
+
valid: false,
|
|
78
|
+
error: 'MNC must be 2 or 3 digits'
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// No range validation - allowing unofficial MCCs for telco labs
|
|
82
|
+
return { valid: true };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Validates use case and phone number combination
|
|
86
|
+
* @param useCase - The use case
|
|
87
|
+
* @param phoneNumber - The phone number (required for VerifyPhoneNumber)
|
|
88
|
+
* @param hasParentSessionId - Whether parent_session_id is provided (allows skipping normal validation)
|
|
89
|
+
* @returns Validation result
|
|
90
|
+
*/
|
|
91
|
+
function validateUseCaseRequirements(useCase, phoneNumber, hasParentSessionId) {
|
|
92
|
+
// VerifyPhoneNumber requires a phone number (unless parent_session_id is provided)
|
|
93
|
+
if (useCase === api_types_1.USE_CASE.VERIFY_PHONE_NUMBER && !phoneNumber && !hasParentSessionId) {
|
|
94
|
+
return {
|
|
95
|
+
valid: false,
|
|
96
|
+
error: 'Phone number is required for VerifyPhoneNumber use case'
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return { valid: true };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Validates consent data
|
|
103
|
+
* @param consentData - Consent data object
|
|
104
|
+
* @returns Validation result
|
|
105
|
+
*/
|
|
106
|
+
function validateConsentData(consentData) {
|
|
107
|
+
if (!consentData) {
|
|
108
|
+
return { valid: true }; // Consent data is optional
|
|
109
|
+
}
|
|
110
|
+
const { consent_text: consentText, policy_link: policyLink, policy_text: policyText } = consentData;
|
|
111
|
+
if (!consentText || consentText.trim().length === 0) {
|
|
112
|
+
return {
|
|
113
|
+
valid: false,
|
|
114
|
+
error: 'Consent text is required when consent data is provided'
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (!policyLink || policyLink.trim().length === 0) {
|
|
118
|
+
return {
|
|
119
|
+
valid: false,
|
|
120
|
+
error: 'Policy link is required when consent data is provided'
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Validate URL format for policy link
|
|
124
|
+
try {
|
|
125
|
+
new URL(policyLink);
|
|
126
|
+
}
|
|
127
|
+
catch (_a) {
|
|
128
|
+
return {
|
|
129
|
+
valid: false,
|
|
130
|
+
error: 'Policy link must be a valid URL'
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (!policyText || policyText.trim().length === 0) {
|
|
134
|
+
return {
|
|
135
|
+
valid: false,
|
|
136
|
+
error: 'Policy text is required when consent data is provided'
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { valid: true };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates a validation error
|
|
143
|
+
* @param code - Error code
|
|
144
|
+
* @param message - Error message
|
|
145
|
+
* @param field - Field that failed validation
|
|
146
|
+
*/
|
|
147
|
+
function createValidationError(code, message, field) {
|
|
148
|
+
const error = new Error(message);
|
|
149
|
+
error.code = code;
|
|
150
|
+
if (field) {
|
|
151
|
+
error.field = field;
|
|
152
|
+
}
|
|
153
|
+
return error;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validates nonce format
|
|
157
|
+
* @param nonce - Nonce string to validate
|
|
158
|
+
* @returns Validation result
|
|
159
|
+
*/
|
|
160
|
+
function validateNonce(nonce) {
|
|
161
|
+
// Nonce should be base64url encoded and have reasonable length
|
|
162
|
+
const base64urlRegex = /^[A-Za-z0-9_-]+$/;
|
|
163
|
+
if (!nonce || nonce.length === 0) {
|
|
164
|
+
return {
|
|
165
|
+
valid: false,
|
|
166
|
+
error: 'Nonce is required'
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
if (!base64urlRegex.test(nonce)) {
|
|
170
|
+
return {
|
|
171
|
+
valid: false,
|
|
172
|
+
error: 'Nonce must be base64url encoded'
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (nonce.length < 32 || nonce.length > 128) {
|
|
176
|
+
return {
|
|
177
|
+
valid: false,
|
|
178
|
+
error: 'Nonce must be between 32 and 128 characters'
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return { valid: true };
|
|
182
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LogLevel, Logger } from './logger';
|
|
2
|
+
export interface ClientConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Base URL for API requests
|
|
5
|
+
* Required only if using useQuery() or client.get() methods
|
|
6
|
+
* Not required for phone authentication
|
|
7
|
+
*/
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
/**
|
|
10
|
+
* API key for authentication
|
|
11
|
+
* Currently not used in the SDK but kept for backward compatibility
|
|
12
|
+
*/
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Request timeout in milliseconds
|
|
16
|
+
* @default 10000
|
|
17
|
+
*/
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Target origin for authentication
|
|
21
|
+
* Used for cross-origin authentication flows
|
|
22
|
+
* If not provided, uses baseURL or current origin
|
|
23
|
+
*/
|
|
24
|
+
authTargetOrigin?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Phone authentication endpoints
|
|
27
|
+
* If not provided, uses default endpoints relative to baseURL
|
|
28
|
+
*/
|
|
29
|
+
phoneAuthEndpoints?: {
|
|
30
|
+
prepareRequest: string;
|
|
31
|
+
processResponse: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Enable debug logging
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Set specific log level
|
|
40
|
+
*/
|
|
41
|
+
logLevel?: LogLevel;
|
|
42
|
+
/**
|
|
43
|
+
* Custom logger implementation
|
|
44
|
+
*/
|
|
45
|
+
logger?: Logger;
|
|
46
|
+
/**
|
|
47
|
+
* Remote logging configuration
|
|
48
|
+
*/
|
|
49
|
+
remoteLogging?: {
|
|
50
|
+
endpoint: string;
|
|
51
|
+
apiKey: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface RequestOptions {
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
params?: Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
export interface ClientResponse<T = any> {
|
|
59
|
+
data: T;
|
|
60
|
+
status: number;
|
|
61
|
+
headers: Record<string, string>;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "__SDK_VERSION__";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Injectable } from '@angular/core';
|
|
11
|
+
import { SDKClient } from '../../core/client';
|
|
12
|
+
import { from } from 'rxjs';
|
|
13
|
+
let ClientService = class ClientService {
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.client = new SDKClient(config);
|
|
16
|
+
}
|
|
17
|
+
query(path) {
|
|
18
|
+
return from(this.client.get(path));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
ClientService = __decorate([
|
|
22
|
+
Injectable({
|
|
23
|
+
providedIn: 'root',
|
|
24
|
+
}),
|
|
25
|
+
__metadata("design:paramtypes", [Object])
|
|
26
|
+
], ClientService);
|
|
27
|
+
export { ClientService };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ClientService } from './client.service';
|
|
2
|
+
export { PhoneAuthService } from './phone-auth.service';
|
|
3
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ClientService } from './client.service';
|
|
2
|
+
export { PhoneAuthService } from './phone-auth.service';
|
|
3
|
+
// Export error utilities
|
|
4
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AuthConfig, PhoneAuthResult, AuthError, AuthStep, PhoneAuthOptions } from '../../core/phone-auth';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class PhoneAuthService {
|
|
4
|
+
private client;
|
|
5
|
+
private isLoadingSubject;
|
|
6
|
+
private errorSubject;
|
|
7
|
+
private resultSubject;
|
|
8
|
+
private currentStepSubject;
|
|
9
|
+
isLoading$: Observable<boolean>;
|
|
10
|
+
error$: Observable<AuthError | null>;
|
|
11
|
+
result$: Observable<PhoneAuthResult | null>;
|
|
12
|
+
currentStep$: Observable<AuthStep>;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Configure the phone auth client
|
|
16
|
+
*/
|
|
17
|
+
configure(config: AuthConfig): void;
|
|
18
|
+
/**
|
|
19
|
+
* Check if browser supports secure phone authentication
|
|
20
|
+
*/
|
|
21
|
+
isSupported(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Verify phone number
|
|
24
|
+
*/
|
|
25
|
+
verify(options: PhoneAuthOptions): Promise<PhoneAuthResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Get phone number
|
|
28
|
+
*/
|
|
29
|
+
getPhoneNumber(options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Verify specific phone number
|
|
32
|
+
*/
|
|
33
|
+
verifyPhoneNumber(phoneNumber: string, options?: Omit<PhoneAuthOptions, 'use_case' | 'phone_number'>): Promise<PhoneAuthResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Reset state
|
|
36
|
+
*/
|
|
37
|
+
reset(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
import { Injectable } from '@angular/core';
|
|
20
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
21
|
+
import { BehaviorSubject } from 'rxjs';
|
|
22
|
+
let PhoneAuthService = class PhoneAuthService {
|
|
23
|
+
constructor() {
|
|
24
|
+
// State subjects
|
|
25
|
+
this.isLoadingSubject = new BehaviorSubject(false);
|
|
26
|
+
this.errorSubject = new BehaviorSubject(null);
|
|
27
|
+
this.resultSubject = new BehaviorSubject(null);
|
|
28
|
+
this.currentStepSubject = new BehaviorSubject('idle');
|
|
29
|
+
// Public observables
|
|
30
|
+
this.isLoading$ = this.isLoadingSubject.asObservable();
|
|
31
|
+
this.error$ = this.errorSubject.asObservable();
|
|
32
|
+
this.result$ = this.resultSubject.asObservable();
|
|
33
|
+
this.currentStep$ = this.currentStepSubject.asObservable();
|
|
34
|
+
this.client = new PhoneAuthClient();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Configure the phone auth client
|
|
38
|
+
*/
|
|
39
|
+
configure(config) {
|
|
40
|
+
this.client = new PhoneAuthClient(config);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if browser supports secure phone authentication
|
|
44
|
+
*/
|
|
45
|
+
isSupported() {
|
|
46
|
+
return this.client.isSupported();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Verify phone number
|
|
50
|
+
*/
|
|
51
|
+
verify(options) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
this.isLoadingSubject.next(true);
|
|
54
|
+
this.errorSubject.next(null);
|
|
55
|
+
this.resultSubject.next(null);
|
|
56
|
+
this.currentStepSubject.next('requesting');
|
|
57
|
+
try {
|
|
58
|
+
// Step 1: Prepare request
|
|
59
|
+
const preparedRequest = yield this.client.preparePhoneRequest(options);
|
|
60
|
+
// Step 2: Show authenticating state
|
|
61
|
+
this.currentStepSubject.next('authenticating');
|
|
62
|
+
const credentialResponse = yield this.client.invokeSecurePrompt(preparedRequest);
|
|
63
|
+
// Step 3: Process response through appropriate endpoint
|
|
64
|
+
this.currentStepSubject.next('processing');
|
|
65
|
+
// Cast to credential type - adapters never use headless mode
|
|
66
|
+
const credential = credentialResponse;
|
|
67
|
+
const processedResult = options.use_case === 'GetPhoneNumber'
|
|
68
|
+
? yield this.client.getPhoneNumber(credential, preparedRequest.session)
|
|
69
|
+
: yield this.client.verifyPhoneNumber(credential, preparedRequest.session);
|
|
70
|
+
// Create final result
|
|
71
|
+
const isVerifyResponse = 'verified' in processedResult;
|
|
72
|
+
const result = processedResult;
|
|
73
|
+
this.resultSubject.next(result);
|
|
74
|
+
this.currentStepSubject.next('complete');
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// Enhance error with context
|
|
79
|
+
const authError = error;
|
|
80
|
+
const enhancedError = Object.assign(Object.assign({}, authError), { context: authError.context || {
|
|
81
|
+
useCase: options.use_case,
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
userAgent: typeof navigator !== 'undefined' ? navigator.userAgent : undefined,
|
|
84
|
+
url: typeof window !== 'undefined' ? window.location.href : undefined
|
|
85
|
+
} });
|
|
86
|
+
this.errorSubject.next(enhancedError);
|
|
87
|
+
this.currentStepSubject.next('idle');
|
|
88
|
+
throw enhancedError;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
this.isLoadingSubject.next(false);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get phone number
|
|
97
|
+
*/
|
|
98
|
+
getPhoneNumber(options) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return this.verify(Object.assign({ use_case: 'GetPhoneNumber' }, options));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Verify specific phone number
|
|
105
|
+
*/
|
|
106
|
+
verifyPhoneNumber(phoneNumber, options) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return this.verify(Object.assign({ use_case: 'VerifyPhoneNumber', phone_number: phoneNumber }, options));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Reset state
|
|
113
|
+
*/
|
|
114
|
+
reset() {
|
|
115
|
+
this.isLoadingSubject.next(false);
|
|
116
|
+
this.errorSubject.next(null);
|
|
117
|
+
this.resultSubject.next(null);
|
|
118
|
+
this.currentStepSubject.next('idle');
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
PhoneAuthService = __decorate([
|
|
122
|
+
Injectable({
|
|
123
|
+
providedIn: 'root'
|
|
124
|
+
}),
|
|
125
|
+
__metadata("design:paramtypes", [])
|
|
126
|
+
], PhoneAuthService);
|
|
127
|
+
export { PhoneAuthService };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { usePhoneAuth } from './usePhoneAuth';
|
|
2
|
+
export { useClient } from './useClient';
|
|
3
|
+
export type { UsePhoneAuthOptions } from './usePhoneAuth';
|
|
4
|
+
export type { ClientConfig, ClientResponse, RequestOptions } from '../../core/types';
|
|
5
|
+
export type { AuthConfig as PhoneAuthConfig, PhoneAuthOptions, PhoneAuthResult, AuthError, AuthStep } from '../../core/phone-auth';
|
|
6
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
7
|
+
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';
|
|
8
|
+
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
9
|
+
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { usePhoneAuth } from './usePhoneAuth';
|
|
2
|
+
export { useClient } from './useClient';
|
|
3
|
+
// Export error utilities
|
|
4
|
+
export { PhoneAuthErrorCode, isPhoneAuthError, isUserError, getUserMessage, isErrorCode, getRetryDelay, isRetryableError, serializeError, createErrorBreadcrumb } from '../../core/phone-auth';
|
|
5
|
+
// Export constants for use case and strategy
|
|
6
|
+
export { USE_CASE as UseCase, AUTHENTICATION_STRATEGY as AuthenticationStrategy, BrowserError, BrowserErrorCode, BrowserName } from '../../core/phone-auth/types';
|
|
7
|
+
// Export the PhoneAuthClient class for direct use
|
|
8
|
+
export { PhoneAuthClient } from '../../core/phone-auth';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SDKClient } from '../../core/client';
|
|
2
|
+
import type { ClientConfig } from '../../core/types';
|
|
3
|
+
import type { PhoneAuthResult, AuthError, PhoneAuthOptions } from '../../core/phone-auth';
|
|
4
|
+
export declare function useClient(config: ClientConfig): {
|
|
5
|
+
client: SDKClient;
|
|
6
|
+
isAuthenticated: boolean;
|
|
7
|
+
token: string | null;
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
authenticate: (authUrl: string, options?: any) => Promise<never>;
|
|
11
|
+
useQuery: <T>(path: string) => {
|
|
12
|
+
data: T | null;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: Error | null;
|
|
15
|
+
refetch: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
usePhoneAuth: () => {
|
|
18
|
+
result: PhoneAuthResult | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error: AuthError | null;
|
|
21
|
+
isSupported: boolean;
|
|
22
|
+
getPhoneNumber: (options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
23
|
+
verifyPhoneNumber: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "useCase" | "phoneNumber">) => Promise<PhoneAuthResult>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export { useClient as useReactClient } from './useClient';
|
|
@@ -0,0 +1,116 @@
|
|
|
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 { useState, useEffect, useCallback } from 'react';
|
|
11
|
+
import { SDKClient } from '../../core/client';
|
|
12
|
+
export function useClient(config) {
|
|
13
|
+
const [client] = useState(() => new SDKClient(config));
|
|
14
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
15
|
+
const [token, setToken] = useState(null);
|
|
16
|
+
const [loading, setLoading] = useState(false);
|
|
17
|
+
const [error, setError] = useState(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let cleanupFn;
|
|
20
|
+
const setCleanup = (fn) => {
|
|
21
|
+
cleanupFn = fn;
|
|
22
|
+
};
|
|
23
|
+
return () => {
|
|
24
|
+
if (cleanupFn) {
|
|
25
|
+
cleanupFn();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
const authenticate = (authUrl, options) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
// Legacy authentication removed - use setToken directly
|
|
31
|
+
const error = new Error('authenticate method is deprecated. Use client.setToken() directly.');
|
|
32
|
+
setError(error);
|
|
33
|
+
setLoading(false);
|
|
34
|
+
throw error;
|
|
35
|
+
});
|
|
36
|
+
const useQuery = (path) => {
|
|
37
|
+
const [data, setData] = useState(null);
|
|
38
|
+
const [queryLoading, setQueryLoading] = useState(true);
|
|
39
|
+
const [queryError, setQueryError] = useState(null);
|
|
40
|
+
const fetchData = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
try {
|
|
42
|
+
const response = yield client.get(path);
|
|
43
|
+
setData(response.data);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
setQueryError(err);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
setQueryLoading(false);
|
|
50
|
+
}
|
|
51
|
+
}), [path]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
fetchData();
|
|
54
|
+
}, [fetchData]);
|
|
55
|
+
return { data, loading: queryLoading, error: queryError, refetch: fetchData };
|
|
56
|
+
};
|
|
57
|
+
const usePhoneAuth = () => {
|
|
58
|
+
const [phoneAuthResult, setPhoneAuthResult] = useState(null);
|
|
59
|
+
const [phoneAuthLoading, setPhoneAuthLoading] = useState(false);
|
|
60
|
+
const [phoneAuthError, setPhoneAuthError] = useState(null);
|
|
61
|
+
const [isSupported] = useState(() => client.phoneAuth.isSupported());
|
|
62
|
+
const getPhoneNumber = useCallback((options) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
setPhoneAuthLoading(true);
|
|
64
|
+
setPhoneAuthError(null);
|
|
65
|
+
setPhoneAuthResult(null);
|
|
66
|
+
try {
|
|
67
|
+
const result = yield client.phoneAuth.getPhoneNumberComplete(options);
|
|
68
|
+
setPhoneAuthResult(result);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
setPhoneAuthError(err);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
setPhoneAuthLoading(false);
|
|
77
|
+
}
|
|
78
|
+
}), [client]);
|
|
79
|
+
const verifyPhoneNumber = useCallback((phoneNumber, options) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
setPhoneAuthLoading(true);
|
|
81
|
+
setPhoneAuthError(null);
|
|
82
|
+
setPhoneAuthResult(null);
|
|
83
|
+
try {
|
|
84
|
+
const result = yield client.phoneAuth.verifyPhoneNumberComplete(phoneNumber, options);
|
|
85
|
+
setPhoneAuthResult(result);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
setPhoneAuthError(err);
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
setPhoneAuthLoading(false);
|
|
94
|
+
}
|
|
95
|
+
}), [client]);
|
|
96
|
+
return {
|
|
97
|
+
result: phoneAuthResult,
|
|
98
|
+
loading: phoneAuthLoading,
|
|
99
|
+
error: phoneAuthError,
|
|
100
|
+
isSupported,
|
|
101
|
+
getPhoneNumber,
|
|
102
|
+
verifyPhoneNumber
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
client,
|
|
107
|
+
isAuthenticated,
|
|
108
|
+
token,
|
|
109
|
+
loading,
|
|
110
|
+
error,
|
|
111
|
+
authenticate,
|
|
112
|
+
useQuery,
|
|
113
|
+
usePhoneAuth,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export { useClient as useReactClient } from './useClient';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PhoneAuthClient } from '../../core/phone-auth';
|
|
2
|
+
import type { AuthConfig, PhoneAuthResult, AuthError, AuthStep, PhoneAuthOptions } from '../../core/phone-auth';
|
|
3
|
+
export interface UsePhoneAuthOptions extends AuthConfig {
|
|
4
|
+
}
|
|
5
|
+
export declare function usePhoneAuth(config?: UsePhoneAuthOptions): {
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: AuthError | null;
|
|
8
|
+
result: PhoneAuthResult | null;
|
|
9
|
+
currentStep: AuthStep;
|
|
10
|
+
isSupported: boolean;
|
|
11
|
+
verify: (options: PhoneAuthOptions) => Promise<PhoneAuthResult>;
|
|
12
|
+
getPhoneNumber: (options?: Omit<PhoneAuthOptions, "use_case">) => Promise<PhoneAuthResult>;
|
|
13
|
+
verifyPhoneNumber: (phoneNumber: string, options?: Omit<PhoneAuthOptions, "use_case" | "phone_number">) => Promise<PhoneAuthResult>;
|
|
14
|
+
retryLastRequest: () => Promise<PhoneAuthResult>;
|
|
15
|
+
reset: () => void;
|
|
16
|
+
preparePhoneRequest: (options: PhoneAuthOptions) => Promise<import("../../core/phone-auth").PrepareResponse>;
|
|
17
|
+
invokeSecurePrompt: (prepareResponse: any) => Promise<{
|
|
18
|
+
[aggregator_id: string]: string | string[];
|
|
19
|
+
} | import("../../core/phone-auth").HeadlessResult>;
|
|
20
|
+
getPhoneNumberCredential: (credentialResponse: any, session: any) => Promise<import("../../core/phone-auth").GetPhoneNumberResponse>;
|
|
21
|
+
verifyPhoneNumberCredential: (credentialResponse: any, session: any) => Promise<import("../../core/phone-auth").VerifyPhoneNumberResponse>;
|
|
22
|
+
client: PhoneAuthClient;
|
|
23
|
+
};
|