@glideidentity/glide-be-node-magical-auth 2.0.0 → 3.0.0
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/dist/index.cjs +47 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -3
- package/dist/index.d.ts +57 -3
- package/dist/index.js +47 -10
- package/dist/index.js.map +1 -1
- package/dist/{types-DKfytuP6.d.cts → types-DgXuYYzq.d.cts} +26 -1
- package/dist/{types-DKfytuP6.d.ts → types-DgXuYYzq.d.ts} +26 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +7 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MagicalAuthConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { A as AuthenticationStrategy, P as PLMN, c as ClientInfo, M as MagicalAuthConfig, z as PrepareRequest, K as PrepareResult, a8 as VerifyPhoneNumberRequest, a9 as VerifyPhoneNumberResponse, G as GetPhoneNumberRequest, p as GetPhoneNumberResponse, Q as ReportInvocationResponse, $ as StatusResponse, H as HttpClient, t as Logger } from './types-DgXuYYzq.cjs';
|
|
2
|
+
export { B as BadRequestError, a as BrowserMismatchError, C as CarrierNotEligibleError, b as Challenge, d as ConsentData, D as DCQLCredential, e as DCQLCredentialMeta, f as DCQLQuery, g as DEFAULT_BASE_URL, h as DEFAULT_TIMEOUT, i as DesktopQRData, j as DesktopStrategyData, k as DesktopWaitError, l as DeviceBindingError, m as DeviceInfo, n as DeviceSwapInfo, E as ErrorCode, o as ErrorResponse, F as ForbiddenError, q as HttpRequestOptions, r as HttpResponse, I as InternalServerError, s as InvalidCredentialError, L as LinkStrategyData, u as LoggerConfig, v as MagicalAuthError, w as MissingBindingCookieError, x as PhoneNumberMismatchError, y as PrepareOptions, J as PrepareResponse, N as ProtocolType, R as RateLimitError, O as ReportInvocationRequest, S as ResolvedConfig, T as RiskLevel, U as ServiceUnavailableError, V as SessionInfo, W as SessionNotEligibleError, X as SessionNotFoundError, Y as SessionStatus, Z as SimSwapFailureReason, _ as SimSwapInfo, a0 as StrategyData, a1 as TS43RequestData, a2 as TS43StrategyData, a3 as Theme, a4 as UnauthorizedError, a5 as UnsupportedPlatformError, a6 as UseCase, a7 as ValidationError, aa as createErrorFromResponse, ab as createLogger, ac as defaultHttpClient, ad as noopLogger, ae as resolveConfig, af as sanitize } from './types-DgXuYYzq.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Request body for device-bound session completion (link protocol only).
|
|
@@ -48,6 +48,49 @@ interface DesktopWaitResponse {
|
|
|
48
48
|
session_expires_in_seconds: number;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** Request to check authentication eligibility. */
|
|
52
|
+
interface EligibilityRequest {
|
|
53
|
+
/** Phone number in E.164 format. At least one of phone_number or plmn required. */
|
|
54
|
+
phone_number?: string;
|
|
55
|
+
/** PLMN (MCC+MNC). At least one of phone_number or plmn required. */
|
|
56
|
+
plmn?: PLMN;
|
|
57
|
+
/** Optional client info for platform-specific filtering. */
|
|
58
|
+
client_info?: ClientInfo;
|
|
59
|
+
}
|
|
60
|
+
/** Constraints for the device that completes an option (always the phone). */
|
|
61
|
+
interface Requirements {
|
|
62
|
+
/** "self" = requesting device; "companion" = a separate phone. */
|
|
63
|
+
target?: 'self' | 'companion';
|
|
64
|
+
/** Minimum Android OS version (user-facing messaging). */
|
|
65
|
+
android_min_version?: number;
|
|
66
|
+
/** Minimum Android SDK/API level (enforced in code). */
|
|
67
|
+
android_min_sdk?: number;
|
|
68
|
+
/** Minimum iOS version (App Clip floor for link). */
|
|
69
|
+
ios_min_version?: number;
|
|
70
|
+
/** Forward-compat: any future fields are preserved here. */
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
/** An available authentication strategy option. */
|
|
74
|
+
interface AvailableOption {
|
|
75
|
+
/** The authentication strategy identifier. */
|
|
76
|
+
authentication_strategy: Exclude<AuthenticationStrategy, ''>;
|
|
77
|
+
/** Human-readable strategy name. */
|
|
78
|
+
name: string;
|
|
79
|
+
/** Description of the authentication flow. */
|
|
80
|
+
description: string;
|
|
81
|
+
/** Platforms this strategy is available on. */
|
|
82
|
+
available_platforms: string[];
|
|
83
|
+
/** Platform/version requirements for the completing device. */
|
|
84
|
+
requirements?: Requirements;
|
|
85
|
+
}
|
|
86
|
+
/** Response from the eligibility check. */
|
|
87
|
+
interface EligibilityResponse {
|
|
88
|
+
/** Whether authentication is available. */
|
|
89
|
+
eligible: boolean;
|
|
90
|
+
/** Available authentication strategy options. */
|
|
91
|
+
available_options: AvailableOption[];
|
|
92
|
+
}
|
|
93
|
+
|
|
51
94
|
/**
|
|
52
95
|
* Per-request options for API calls.
|
|
53
96
|
*/
|
|
@@ -89,6 +132,17 @@ declare class MagicalAuthClient {
|
|
|
89
132
|
* @throws {Error} If clientId or clientSecret is missing
|
|
90
133
|
*/
|
|
91
134
|
constructor(config: MagicalAuthConfig);
|
|
135
|
+
/**
|
|
136
|
+
* Check authentication eligibility for a phone number or PLMN.
|
|
137
|
+
* Returns available authentication strategies with platform requirements.
|
|
138
|
+
*
|
|
139
|
+
* @param request - Eligibility request with phone_number or plmn. `client_info.user_agent` is required.
|
|
140
|
+
* @param options - Per-request options (e.g., correlationId)
|
|
141
|
+
* @returns Eligibility response with available options
|
|
142
|
+
* @throws {ValidationError} If request validation fails (incl. missing/blank `client_info.user_agent`)
|
|
143
|
+
* @throws {MagicalAuthError} For other API errors
|
|
144
|
+
*/
|
|
145
|
+
checkEligibility(request: EligibilityRequest, options?: RequestOptions): Promise<EligibilityResponse>;
|
|
92
146
|
/**
|
|
93
147
|
* Prepares authentication by checking carrier eligibility and generating protocol-specific requests.
|
|
94
148
|
*
|
|
@@ -416,4 +470,4 @@ declare function getCompletionPageHtml(completeEndpoint: string): string;
|
|
|
416
470
|
*/
|
|
417
471
|
declare const VERSION: string;
|
|
418
472
|
|
|
419
|
-
export { BINDING_COOKIE_MAX_AGE, BINDING_COOKIE_PREFIX, type BindingCookieOptions, type CompleteRequest, type CompleteResponse, type DesktopWaitResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, HEX_64, HttpClient, Logger, MagicalAuthClient, MagicalAuthConfig, PrepareRequest, PrepareResult, ReportInvocationResponse, type RequestOptions, SENSITIVE_KEYS, StatusResponse, TokenManager, VERSION, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, assertValidFeCode, buildClearBindingCookieHeader, buildSetBindingCookieHeader, clearStaleBindingCookies, computeFeHash, generateFeCode, getBindingCookieName, getCompletionPageHtml, parseBindingCookie };
|
|
473
|
+
export { AuthenticationStrategy, type AvailableOption, BINDING_COOKIE_MAX_AGE, BINDING_COOKIE_PREFIX, type BindingCookieOptions, ClientInfo, type CompleteRequest, type CompleteResponse, type DesktopWaitResponse, type EligibilityRequest, type EligibilityResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, HEX_64, HttpClient, Logger, MagicalAuthClient, MagicalAuthConfig, PLMN, PrepareRequest, PrepareResult, ReportInvocationResponse, type RequestOptions, type Requirements, SENSITIVE_KEYS, StatusResponse, TokenManager, VERSION, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, assertValidFeCode, buildClearBindingCookieHeader, buildSetBindingCookieHeader, clearStaleBindingCookies, computeFeHash, generateFeCode, getBindingCookieName, getCompletionPageHtml, parseBindingCookie };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MagicalAuthConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { A as AuthenticationStrategy, P as PLMN, c as ClientInfo, M as MagicalAuthConfig, z as PrepareRequest, K as PrepareResult, a8 as VerifyPhoneNumberRequest, a9 as VerifyPhoneNumberResponse, G as GetPhoneNumberRequest, p as GetPhoneNumberResponse, Q as ReportInvocationResponse, $ as StatusResponse, H as HttpClient, t as Logger } from './types-DgXuYYzq.js';
|
|
2
|
+
export { B as BadRequestError, a as BrowserMismatchError, C as CarrierNotEligibleError, b as Challenge, d as ConsentData, D as DCQLCredential, e as DCQLCredentialMeta, f as DCQLQuery, g as DEFAULT_BASE_URL, h as DEFAULT_TIMEOUT, i as DesktopQRData, j as DesktopStrategyData, k as DesktopWaitError, l as DeviceBindingError, m as DeviceInfo, n as DeviceSwapInfo, E as ErrorCode, o as ErrorResponse, F as ForbiddenError, q as HttpRequestOptions, r as HttpResponse, I as InternalServerError, s as InvalidCredentialError, L as LinkStrategyData, u as LoggerConfig, v as MagicalAuthError, w as MissingBindingCookieError, x as PhoneNumberMismatchError, y as PrepareOptions, J as PrepareResponse, N as ProtocolType, R as RateLimitError, O as ReportInvocationRequest, S as ResolvedConfig, T as RiskLevel, U as ServiceUnavailableError, V as SessionInfo, W as SessionNotEligibleError, X as SessionNotFoundError, Y as SessionStatus, Z as SimSwapFailureReason, _ as SimSwapInfo, a0 as StrategyData, a1 as TS43RequestData, a2 as TS43StrategyData, a3 as Theme, a4 as UnauthorizedError, a5 as UnsupportedPlatformError, a6 as UseCase, a7 as ValidationError, aa as createErrorFromResponse, ab as createLogger, ac as defaultHttpClient, ad as noopLogger, ae as resolveConfig, af as sanitize } from './types-DgXuYYzq.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Request body for device-bound session completion (link protocol only).
|
|
@@ -48,6 +48,49 @@ interface DesktopWaitResponse {
|
|
|
48
48
|
session_expires_in_seconds: number;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** Request to check authentication eligibility. */
|
|
52
|
+
interface EligibilityRequest {
|
|
53
|
+
/** Phone number in E.164 format. At least one of phone_number or plmn required. */
|
|
54
|
+
phone_number?: string;
|
|
55
|
+
/** PLMN (MCC+MNC). At least one of phone_number or plmn required. */
|
|
56
|
+
plmn?: PLMN;
|
|
57
|
+
/** Optional client info for platform-specific filtering. */
|
|
58
|
+
client_info?: ClientInfo;
|
|
59
|
+
}
|
|
60
|
+
/** Constraints for the device that completes an option (always the phone). */
|
|
61
|
+
interface Requirements {
|
|
62
|
+
/** "self" = requesting device; "companion" = a separate phone. */
|
|
63
|
+
target?: 'self' | 'companion';
|
|
64
|
+
/** Minimum Android OS version (user-facing messaging). */
|
|
65
|
+
android_min_version?: number;
|
|
66
|
+
/** Minimum Android SDK/API level (enforced in code). */
|
|
67
|
+
android_min_sdk?: number;
|
|
68
|
+
/** Minimum iOS version (App Clip floor for link). */
|
|
69
|
+
ios_min_version?: number;
|
|
70
|
+
/** Forward-compat: any future fields are preserved here. */
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
/** An available authentication strategy option. */
|
|
74
|
+
interface AvailableOption {
|
|
75
|
+
/** The authentication strategy identifier. */
|
|
76
|
+
authentication_strategy: Exclude<AuthenticationStrategy, ''>;
|
|
77
|
+
/** Human-readable strategy name. */
|
|
78
|
+
name: string;
|
|
79
|
+
/** Description of the authentication flow. */
|
|
80
|
+
description: string;
|
|
81
|
+
/** Platforms this strategy is available on. */
|
|
82
|
+
available_platforms: string[];
|
|
83
|
+
/** Platform/version requirements for the completing device. */
|
|
84
|
+
requirements?: Requirements;
|
|
85
|
+
}
|
|
86
|
+
/** Response from the eligibility check. */
|
|
87
|
+
interface EligibilityResponse {
|
|
88
|
+
/** Whether authentication is available. */
|
|
89
|
+
eligible: boolean;
|
|
90
|
+
/** Available authentication strategy options. */
|
|
91
|
+
available_options: AvailableOption[];
|
|
92
|
+
}
|
|
93
|
+
|
|
51
94
|
/**
|
|
52
95
|
* Per-request options for API calls.
|
|
53
96
|
*/
|
|
@@ -89,6 +132,17 @@ declare class MagicalAuthClient {
|
|
|
89
132
|
* @throws {Error} If clientId or clientSecret is missing
|
|
90
133
|
*/
|
|
91
134
|
constructor(config: MagicalAuthConfig);
|
|
135
|
+
/**
|
|
136
|
+
* Check authentication eligibility for a phone number or PLMN.
|
|
137
|
+
* Returns available authentication strategies with platform requirements.
|
|
138
|
+
*
|
|
139
|
+
* @param request - Eligibility request with phone_number or plmn. `client_info.user_agent` is required.
|
|
140
|
+
* @param options - Per-request options (e.g., correlationId)
|
|
141
|
+
* @returns Eligibility response with available options
|
|
142
|
+
* @throws {ValidationError} If request validation fails (incl. missing/blank `client_info.user_agent`)
|
|
143
|
+
* @throws {MagicalAuthError} For other API errors
|
|
144
|
+
*/
|
|
145
|
+
checkEligibility(request: EligibilityRequest, options?: RequestOptions): Promise<EligibilityResponse>;
|
|
92
146
|
/**
|
|
93
147
|
* Prepares authentication by checking carrier eligibility and generating protocol-specific requests.
|
|
94
148
|
*
|
|
@@ -416,4 +470,4 @@ declare function getCompletionPageHtml(completeEndpoint: string): string;
|
|
|
416
470
|
*/
|
|
417
471
|
declare const VERSION: string;
|
|
418
472
|
|
|
419
|
-
export { BINDING_COOKIE_MAX_AGE, BINDING_COOKIE_PREFIX, type BindingCookieOptions, type CompleteRequest, type CompleteResponse, type DesktopWaitResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, HEX_64, HttpClient, Logger, MagicalAuthClient, MagicalAuthConfig, PrepareRequest, PrepareResult, ReportInvocationResponse, type RequestOptions, SENSITIVE_KEYS, StatusResponse, TokenManager, VERSION, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, assertValidFeCode, buildClearBindingCookieHeader, buildSetBindingCookieHeader, clearStaleBindingCookies, computeFeHash, generateFeCode, getBindingCookieName, getCompletionPageHtml, parseBindingCookie };
|
|
473
|
+
export { AuthenticationStrategy, type AvailableOption, BINDING_COOKIE_MAX_AGE, BINDING_COOKIE_PREFIX, type BindingCookieOptions, ClientInfo, type CompleteRequest, type CompleteResponse, type DesktopWaitResponse, type EligibilityRequest, type EligibilityResponse, GetPhoneNumberRequest, GetPhoneNumberResponse, HEX_64, HttpClient, Logger, MagicalAuthClient, MagicalAuthConfig, PLMN, PrepareRequest, PrepareResult, ReportInvocationResponse, type RequestOptions, type Requirements, SENSITIVE_KEYS, StatusResponse, TokenManager, VERSION, VerifyPhoneNumberRequest, VerifyPhoneNumberResponse, assertValidFeCode, buildClearBindingCookieHeader, buildSetBindingCookieHeader, clearStaleBindingCookies, computeFeHash, generateFeCode, getBindingCookieName, getCompletionPageHtml, parseBindingCookie };
|
package/dist/index.js
CHANGED
|
@@ -710,10 +710,11 @@ var SessionStatus = {
|
|
|
710
710
|
function validatePrepareRequest(request) {
|
|
711
711
|
const errors = {};
|
|
712
712
|
const hasParentSession = !!request.options?.parent_session_id?.trim();
|
|
713
|
+
const phoneNumber = request.phone_number?.trim();
|
|
713
714
|
if (!request.use_case && !hasParentSession) {
|
|
714
715
|
errors.use_case = "use_case is required";
|
|
715
716
|
}
|
|
716
|
-
if (request.use_case === UseCase.VERIFY_PHONE_NUMBER && !
|
|
717
|
+
if (request.use_case === UseCase.VERIFY_PHONE_NUMBER && !phoneNumber) {
|
|
717
718
|
errors.phone_number = "phone_number is required for VerifyPhoneNumber";
|
|
718
719
|
}
|
|
719
720
|
if (Object.keys(errors).length > 0) {
|
|
@@ -778,6 +779,19 @@ function validateCompleteRequest(request) {
|
|
|
778
779
|
throw new DeviceBindingError("Invalid device binding inputs");
|
|
779
780
|
}
|
|
780
781
|
}
|
|
782
|
+
function validateEligibilityRequest(request) {
|
|
783
|
+
const errors = {};
|
|
784
|
+
const phoneNumber = request.phone_number?.trim();
|
|
785
|
+
if (!phoneNumber && !request.plmn) {
|
|
786
|
+
errors.phone_number = "phone_number or plmn is required";
|
|
787
|
+
}
|
|
788
|
+
if (!request.client_info?.user_agent?.trim()) {
|
|
789
|
+
errors["client_info.user_agent"] = "client_info.user_agent is required";
|
|
790
|
+
}
|
|
791
|
+
if (Object.keys(errors).length > 0) {
|
|
792
|
+
throw new ValidationError("Request validation failed", errors);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
781
795
|
|
|
782
796
|
// src/client.ts
|
|
783
797
|
var MagicalAuthClient = class {
|
|
@@ -805,6 +819,26 @@ var MagicalAuthClient = class {
|
|
|
805
819
|
this.config.logger
|
|
806
820
|
);
|
|
807
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Check authentication eligibility for a phone number or PLMN.
|
|
824
|
+
* Returns available authentication strategies with platform requirements.
|
|
825
|
+
*
|
|
826
|
+
* @param request - Eligibility request with phone_number or plmn. `client_info.user_agent` is required.
|
|
827
|
+
* @param options - Per-request options (e.g., correlationId)
|
|
828
|
+
* @returns Eligibility response with available options
|
|
829
|
+
* @throws {ValidationError} If request validation fails (incl. missing/blank `client_info.user_agent`)
|
|
830
|
+
* @throws {MagicalAuthError} For other API errors
|
|
831
|
+
*/
|
|
832
|
+
async checkEligibility(request, options) {
|
|
833
|
+
validateEligibilityRequest(request);
|
|
834
|
+
const response = await this.doRequest(
|
|
835
|
+
"POST",
|
|
836
|
+
"/magic-auth/v2/auth/eligibility",
|
|
837
|
+
request,
|
|
838
|
+
options
|
|
839
|
+
);
|
|
840
|
+
return response;
|
|
841
|
+
}
|
|
808
842
|
/**
|
|
809
843
|
* Prepares authentication by checking carrier eligibility and generating protocol-specific requests.
|
|
810
844
|
*
|
|
@@ -1135,19 +1169,22 @@ var JWT_RE = /(eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)/g;
|
|
|
1135
1169
|
var SESSION_RE = /(session[_-]?key)(["']?\s*[:=]\s*["']?)([A-Za-z0-9_-]{16,})/gi;
|
|
1136
1170
|
var SENSITIVE = ["phone_number", "phonenumber", "credential", "token", "password", "secret", "fe_code", "fecode"];
|
|
1137
1171
|
function sanitize(data) {
|
|
1172
|
+
return sanitizeWith(data, /* @__PURE__ */ new WeakSet());
|
|
1173
|
+
}
|
|
1174
|
+
function sanitizeWith(data, seen) {
|
|
1138
1175
|
if (data == null) return data;
|
|
1139
1176
|
if (typeof data === "string") {
|
|
1140
|
-
return data.replace(
|
|
1177
|
+
return data.replace(JWT_RE, "[JWT]").replace(SESSION_RE, (_, k, sep, v) => `${k}${sep}${v.slice(0, 4)}***${v.slice(-4)}`).replace(PHONE_RE, (m) => m.length < 8 ? m : `${m.slice(0, 4)}***${m.slice(-4)}`);
|
|
1141
1178
|
}
|
|
1142
|
-
if (
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1179
|
+
if (typeof data !== "object") return data;
|
|
1180
|
+
if (seen.has(data)) return "[Circular]";
|
|
1181
|
+
seen.add(data);
|
|
1182
|
+
if (Array.isArray(data)) return data.map((v) => sanitizeWith(v, seen));
|
|
1183
|
+
const out = {};
|
|
1184
|
+
for (const [k, v] of Object.entries(data)) {
|
|
1185
|
+
out[k] = SENSITIVE.some((s) => k.toLowerCase().includes(s)) ? "[REDACTED]" : sanitizeWith(v, seen);
|
|
1149
1186
|
}
|
|
1150
|
-
return
|
|
1187
|
+
return out;
|
|
1151
1188
|
}
|
|
1152
1189
|
|
|
1153
1190
|
// src/index.ts
|