@passflow/core 0.38.0 → 0.39.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 +81 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +358 -138
- package/dist/index.d.ts +358 -138
- package/dist/index.mjs +1372 -1255
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -921,6 +921,139 @@ export declare const passkeyFactor: UpgradeFactor;
|
|
|
921
921
|
export declare const DEFAULT_UPGRADE_FACTORS: readonly UpgradeFactor[];
|
|
922
922
|
/** Indexes a factor list by type for lookup during a challenge. */
|
|
923
923
|
export declare const factorRegistry: (factors?: readonly UpgradeFactor[]) => Map<UpgradeFactorType, UpgradeFactor>;
|
|
924
|
+
/** The error code RFC 9470 §3 defines for an insufficient authentication event. */
|
|
925
|
+
export declare const INSUFFICIENT_USER_AUTHENTICATION = "insufficient_user_authentication";
|
|
926
|
+
/** The ADR-2 error code `/auth/session/exchange` returns in its 403 body. */
|
|
927
|
+
export declare const UPGRADE_REQUIRED = "upgrade_required";
|
|
928
|
+
/**
|
|
929
|
+
* What the server demands before it will serve the original request.
|
|
930
|
+
*
|
|
931
|
+
* Both fields are optional because the two middlewares challenge on different
|
|
932
|
+
* axes: RequireAuthLevel names an `acrValues` and omits `maxAge`, while
|
|
933
|
+
* RequireFreshAuth does the reverse. A challenge carrying neither is still
|
|
934
|
+
* valid — it means "re-prove a factor" without further qualification.
|
|
935
|
+
*/
|
|
936
|
+
type UpgradeChallenge = {
|
|
937
|
+
/**
|
|
938
|
+
* Required authentication context class (`acr`), e.g. `'2'`.
|
|
939
|
+
*
|
|
940
|
+
* After a two-channel merge this is the raw list of the channel that SET THE
|
|
941
|
+
* BAR, with the header preferred on a numeric tie. A channel that contributed
|
|
942
|
+
* no level never supplies it — showing `"2gold"` as the bar would
|
|
943
|
+
* misrepresent what the server demanded.
|
|
944
|
+
*/
|
|
945
|
+
acrValues?: string;
|
|
946
|
+
/**
|
|
947
|
+
* The parsed bar: `max` over each channel's `min` participating level
|
|
948
|
+
* (§13.2.1a). `undefined` means unknown or unconstrained on this axis.
|
|
949
|
+
*
|
|
950
|
+
* Optional, and absent from the single-channel parsers' output, so
|
|
951
|
+
* `parseChallengeHeader` / `parseChallengeBody` keep the exact shape they
|
|
952
|
+
* ship with. `readUpgradeChallenge` always sets it when a level was parsed.
|
|
953
|
+
*/
|
|
954
|
+
requiredLevel?: number;
|
|
955
|
+
/** Maximum permitted age of the authentication event, in seconds. */
|
|
956
|
+
maxAge?: number;
|
|
957
|
+
/** The status that carried the challenge: 401 (protected resource) or 403 (session exchange). */
|
|
958
|
+
status: number;
|
|
959
|
+
/**
|
|
960
|
+
* The factors this user can use, in the order to offer them, from the `403` body's
|
|
961
|
+
* `available_factors`. Absent when the server does not send it (older servers, the header channel).
|
|
962
|
+
*/
|
|
963
|
+
availableFactors?: UpgradeFactorType[];
|
|
964
|
+
/**
|
|
965
|
+
* The `403` body's `sign_in_required`: `true` when only a fresh sign-in can meet
|
|
966
|
+
* the challenge, `false` when a step-up could but `availableFactors` names none
|
|
967
|
+
* this account has (for example a device-bound passkey for AAL3). Absent from
|
|
968
|
+
* older servers.
|
|
969
|
+
*/
|
|
970
|
+
signInRequired?: boolean;
|
|
971
|
+
/**
|
|
972
|
+
* Every channel that PARSED AS A CHALLENGE in any field — not only the
|
|
973
|
+
* channels that won a comparison. An opaque header contributes no constraint
|
|
974
|
+
* yet must still be counted, because only something that saw and discarded it
|
|
975
|
+
* can report it. `length === 2` means "both channels carried a challenge".
|
|
976
|
+
*
|
|
977
|
+
* Set by `readUpgradeChallenge`; absent from the single-channel parsers.
|
|
978
|
+
*/
|
|
979
|
+
channels?: ChallengeChannel[];
|
|
980
|
+
};
|
|
981
|
+
/** Which wire channel a challenge was read from. */
|
|
982
|
+
type ChallengeChannel = 'header' | 'body';
|
|
983
|
+
/**
|
|
984
|
+
* Reads a upgrade challenge out of a `WWW-Authenticate` header, or returns
|
|
985
|
+
* `undefined` when the header is absent or describes some other failure.
|
|
986
|
+
*
|
|
987
|
+
* The header must both use the `Bearer` scheme and carry
|
|
988
|
+
* `error="insufficient_user_authentication"`. A bare `WWW-Authenticate: Bearer`
|
|
989
|
+
* (what an expired token produces) is deliberately NOT a upgrade challenge.
|
|
990
|
+
*/
|
|
991
|
+
export declare const parseChallengeHeader: (header: string | undefined | null, status: number) => UpgradeChallenge | undefined;
|
|
992
|
+
/**
|
|
993
|
+
* Reads a upgrade challenge out of the ADR-2 `403` body. Used as a fallback
|
|
994
|
+
* for `/auth/session/exchange`, whose JSON body is the documented SDK contract
|
|
995
|
+
* even though it also sets the standard header.
|
|
996
|
+
*/
|
|
997
|
+
export declare const parseChallengeBody: (body: unknown, status: number) => UpgradeChallenge | undefined;
|
|
998
|
+
/** The bar a challenge demanded, or an elevation reached, on both axes. */
|
|
999
|
+
type AssuranceBar = {
|
|
1000
|
+
/** The raw winning `acr_values` list, for display and diagnostics. */
|
|
1001
|
+
acrValues?: string;
|
|
1002
|
+
/** The parsed bar. `undefined` = unknown, or not constrained on this axis. */
|
|
1003
|
+
level?: number;
|
|
1004
|
+
/** The freshness constraint, when that is what was demanded. */
|
|
1005
|
+
maxAge?: number;
|
|
1006
|
+
};
|
|
1007
|
+
/** The reasons the SDK can decline to act on a challenge, or act on a suspect one. */
|
|
1008
|
+
type UpgradeDiagnosticReason = 'no-channel' | 'header-required-but-absent' | 'channels-disagree' | 'channels-unorderable' | 'zero-constraint-ignored' | 'challenge-out-of-scope' | 'elevated-insufficient' | 'replay-unsupported';
|
|
1009
|
+
/**
|
|
1010
|
+
* One diagnostic record.
|
|
1011
|
+
*
|
|
1012
|
+
* A diagnostic is the only observable signal of the response-rewriting and the
|
|
1013
|
+
* misconfiguration this design warns about, so it routes through a callback
|
|
1014
|
+
* whose DEFAULT sink is `console.warn` — never `debug`, which is invisible in
|
|
1015
|
+
* every default configuration. A deployment where step-up silently never fires
|
|
1016
|
+
* must be distinguishable from one where it was never required.
|
|
1017
|
+
*/
|
|
1018
|
+
type UpgradeDiagnostic = {
|
|
1019
|
+
status: number;
|
|
1020
|
+
/**
|
|
1021
|
+
* The request's URL. The parser does not know it — it is handed a status, a
|
|
1022
|
+
* header reader and a body — so it emits `''` and the core, which owns the
|
|
1023
|
+
* request context, fills it in before forwarding to the sink.
|
|
1024
|
+
*/
|
|
1025
|
+
url: string;
|
|
1026
|
+
reason: UpgradeDiagnosticReason;
|
|
1027
|
+
detail?: {
|
|
1028
|
+
obtained?: AssuranceBar;
|
|
1029
|
+
required?: AssuranceBar;
|
|
1030
|
+
/** Raw channel inputs, including values discarded as unorderable. */
|
|
1031
|
+
header?: string;
|
|
1032
|
+
body?: string;
|
|
1033
|
+
/** Which field was discarded, for `'zero-constraint-ignored'`. */
|
|
1034
|
+
field?: 'acr_values' | 'max_age';
|
|
1035
|
+
/** Which operation, for per-waiter reasons. */
|
|
1036
|
+
method?: string;
|
|
1037
|
+
/** A human-readable sentence naming the fix. The default sink prints it. */
|
|
1038
|
+
message?: string;
|
|
1039
|
+
};
|
|
1040
|
+
};
|
|
1041
|
+
/** Where diagnostics go. `console.warn` is the default sink, not the only one. */
|
|
1042
|
+
type UpgradeDiagnosticSink = (diagnostic: UpgradeDiagnostic) => void;
|
|
1043
|
+
/**
|
|
1044
|
+
* Resolves a upgrade challenge from a response, from either channel.
|
|
1045
|
+
*
|
|
1046
|
+
* The SHIPPED export: same name, same three parameters, same return, published
|
|
1047
|
+
* in `@passflow/core@0.14.1`. It is now a thin delegate over
|
|
1048
|
+
* `readUpgradeChallenge`, so there is one merge rule rather than two parsers
|
|
1049
|
+
* that can drift — but it discards the diagnostics, which is why a caller that
|
|
1050
|
+
* needs them (the core) calls the sibling directly.
|
|
1051
|
+
*
|
|
1052
|
+
* Returns `undefined` for every response that is not a upgrade challenge —
|
|
1053
|
+
* including ordinary `401`s, which callers must keep treating as "session
|
|
1054
|
+
* expired".
|
|
1055
|
+
*/
|
|
1056
|
+
export declare const parseUpgradeChallenge: (status: number, getHeader: (name: string) => string | undefined | null, body?: unknown) => UpgradeChallenge | undefined;
|
|
924
1057
|
export type RequestOptions<D> = {
|
|
925
1058
|
data?: D;
|
|
926
1059
|
config?: AxiosRequestConfig;
|
|
@@ -962,6 +1095,8 @@ export declare enum PassflowEndpointPaths {
|
|
|
962
1095
|
completeAddUserPasskey = "/user/passkey/add/complete",
|
|
963
1096
|
userSessions = "/user/sessions",
|
|
964
1097
|
userSessionsRevokeOthers = "/user/sessions/revoke-others",
|
|
1098
|
+
userProfile = "/user/profile",
|
|
1099
|
+
AddressChangeProof = "/v2/user/address-change/proof",
|
|
965
1100
|
joinInvitation = "/user/tenant/join",
|
|
966
1101
|
tenantPath = "/user/tenant",
|
|
967
1102
|
invitationsPath = "/user/tenant/:tenantID/invitations",
|
|
@@ -1274,6 +1409,51 @@ export declare class PassflowPasswordChangeRequiredError extends PassflowError {
|
|
|
1274
1409
|
cause?: unknown;
|
|
1275
1410
|
});
|
|
1276
1411
|
}
|
|
1412
|
+
/** Id of the 429 a code send answers with when the user's monthly text quota is spent. */
|
|
1413
|
+
export declare const TWO_FACTOR_SMS_QUOTA_EXCEEDED_ERROR_ID = "error.2fa.sms.quota.exceeded";
|
|
1414
|
+
/** Id of the 429 a code send answers with when the app's send limit or the challenge budget is spent. */
|
|
1415
|
+
export declare const TWO_FACTOR_SEND_LIMIT_ERROR_ID = "error.2fa.rate_limit_exceeded";
|
|
1416
|
+
/** Id of the 403 recovery-code setup answers with below level 2. */
|
|
1417
|
+
export declare const RECOVERY_CODES_STEP_UP_REQUIRED_ERROR_ID = "error.2fa.recovery_codes.step_up_required";
|
|
1418
|
+
/** Id of the 403 a profile save answers with when a change of email or phone number needs a proof. */
|
|
1419
|
+
export declare const ADDRESS_CHANGE_PROOF_REQUIRED_ERROR_ID = "error.user.address.change.proof.required";
|
|
1420
|
+
/**
|
|
1421
|
+
* No code was sent: the user's monthly text quota is spent (429). Use another method or try again
|
|
1422
|
+
* next month.
|
|
1423
|
+
*/
|
|
1424
|
+
export declare class PassflowSmsQuotaExceededError extends PassflowError {
|
|
1425
|
+
constructor(error: PassflowResponseError['error'], options?: {
|
|
1426
|
+
cause?: unknown;
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* No code was sent: the app's send limit or the challenge budget is spent (429). On `updateProfile`
|
|
1431
|
+
* it can also come from the proof check: too many wrong codes, not a spent send limit.
|
|
1432
|
+
*/
|
|
1433
|
+
export declare class PassflowSendLimitError extends PassflowError {
|
|
1434
|
+
/** Seconds to wait, from `Retry-After`; undefined when the server sent none. */
|
|
1435
|
+
readonly retryAfter?: number;
|
|
1436
|
+
constructor(error: PassflowResponseError['error'], retryAfter?: number, options?: {
|
|
1437
|
+
cause?: unknown;
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Recovery codes need a session at level 2 (403). Step up to `challenge`, or sign in again, then
|
|
1442
|
+
* repeat the call.
|
|
1443
|
+
*/
|
|
1444
|
+
export declare class PassflowRecoveryCodesStepUpRequiredError extends PassflowError {
|
|
1445
|
+
/** The RFC 9470 challenge; at least `{ acrValues: '2', requiredLevel: 2, status: 403 }`. */
|
|
1446
|
+
readonly challenge: UpgradeChallenge;
|
|
1447
|
+
constructor(error: PassflowResponseError['error'], challenge: UpgradeChallenge, options?: {
|
|
1448
|
+
cause?: unknown;
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
/** A change of email or phone number needs a proof the save did not carry (403). */
|
|
1452
|
+
export declare class PassflowAddressChangeProofRequiredError extends PassflowError {
|
|
1453
|
+
constructor(error: PassflowResponseError['error'], options?: {
|
|
1454
|
+
cause?: unknown;
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1277
1457
|
export type PassflowSignInPayload = {
|
|
1278
1458
|
password: string;
|
|
1279
1459
|
scopes?: string[];
|
|
@@ -2025,6 +2205,11 @@ export type TwoFactorEnrollmentResponse = {
|
|
|
2025
2205
|
* Absent when the user has none, and from servers that do not send it.
|
|
2026
2206
|
*/
|
|
2027
2207
|
account_hint?: string;
|
|
2208
|
+
/**
|
|
2209
|
+
* With `enrollment: 'unavailable'`: the only way on is an email or phone number the user has not
|
|
2210
|
+
* verified yet.
|
|
2211
|
+
*/
|
|
2212
|
+
verify_address?: boolean;
|
|
2028
2213
|
};
|
|
2029
2214
|
/** POST /auth/2fa/enrollment/email-link */
|
|
2030
2215
|
export type TwoFactorSetupLinkResponse = {
|
|
@@ -2139,12 +2324,19 @@ export type TwoFactorSetupMagicLinkSession = {
|
|
|
2139
2324
|
* Two-Factor method types
|
|
2140
2325
|
*/
|
|
2141
2326
|
export type TwoFactorMethod = 'totp' | 'email_otp' | 'sms_otp' | 'passkey' | 'push_fcm' | 'push_webpush' | 'recovery_codes';
|
|
2327
|
+
/** The second factors that send a code to the user's email or phone. */
|
|
2328
|
+
export type TwoFactorCodeMethod = 'email_otp' | 'sms_otp';
|
|
2142
2329
|
/**
|
|
2143
2330
|
* Challenge Request for v2 2FA flow
|
|
2144
2331
|
*/
|
|
2145
2332
|
export interface TwoFactorChallengeRequest {
|
|
2146
2333
|
first_factor_method?: string;
|
|
2147
2334
|
trust_device?: boolean;
|
|
2335
|
+
/**
|
|
2336
|
+
* Send a new code. The answer has a new `challenge_id` and the previous code stops working.
|
|
2337
|
+
* Without it, a live code of this sign-in is answered again and nothing is sent.
|
|
2338
|
+
*/
|
|
2339
|
+
resend?: boolean;
|
|
2148
2340
|
}
|
|
2149
2341
|
/**
|
|
2150
2342
|
* Challenge Response from v2 2FA flow
|
|
@@ -2161,7 +2353,10 @@ export interface TwoFactorChallengeResponse {
|
|
|
2161
2353
|
/** Other methods the user can switch to. Absent when there are none. */
|
|
2162
2354
|
alternative_methods?: TwoFactorMethod[];
|
|
2163
2355
|
expires_at: string;
|
|
2356
|
+
/** The masked email or phone the code went to. Emailed and texted codes only. */
|
|
2164
2357
|
code_sent_to?: string;
|
|
2358
|
+
/** Minutes the code stays valid, whole and at least 1. Emailed and texted codes only. */
|
|
2359
|
+
expires_in_minutes?: number;
|
|
2165
2360
|
webauthn_options?: unknown;
|
|
2166
2361
|
/** Digits in the TOTP code. TOTP challenges only. */
|
|
2167
2362
|
totp_digits?: 6 | 8;
|
|
@@ -2216,14 +2411,83 @@ export interface RegisteredTwoFactorMethod {
|
|
|
2216
2411
|
created_at?: string;
|
|
2217
2412
|
updated_at?: string;
|
|
2218
2413
|
last_used_at?: string;
|
|
2414
|
+
/** The highest acr a step-up with this factor reaches; `''` without a session. */
|
|
2415
|
+
reaches_acr_max?: '1' | '2' | '3' | '';
|
|
2416
|
+
/** `true` when the client asks for a challenge first (every method but totp and recovery_codes). */
|
|
2417
|
+
requires_prepare?: boolean;
|
|
2418
|
+
/** The masked email or phone for `email_otp` / `sms_otp`; `''` otherwise. */
|
|
2419
|
+
code_sent_to_hint?: string;
|
|
2420
|
+
/** `true` on the first item. */
|
|
2421
|
+
recommended?: boolean;
|
|
2219
2422
|
}
|
|
2423
|
+
/** Query of GET /v2/user/2fa/methods. Keys left undefined are not sent. */
|
|
2424
|
+
export type RegisteredTwoFactorMethodsQuery = {
|
|
2425
|
+
purpose?: 'two_factor' | 'upgrade';
|
|
2426
|
+
required_acr?: string;
|
|
2427
|
+
/** Seconds. */
|
|
2428
|
+
max_age?: number;
|
|
2429
|
+
};
|
|
2430
|
+
/** POST /v2/user/2fa/setup/start with method `recovery_codes` and a code method as `via`. */
|
|
2431
|
+
export type TwoFactorRecoveryCodesByCodeStartResponse = {
|
|
2432
|
+
setup_id: string;
|
|
2433
|
+
method: 'recovery_codes';
|
|
2434
|
+
/** The masked email or phone the code went to. */
|
|
2435
|
+
code_sent_to: string;
|
|
2436
|
+
};
|
|
2437
|
+
/** POST /v2/user/2fa/setup/complete with method `recovery_codes`. The codes are shown once. */
|
|
2438
|
+
export type TwoFactorRecoveryCodesByCodeCompleteResponse = {
|
|
2439
|
+
confirmed: boolean;
|
|
2440
|
+
/** The new codes; they replace any older ones. */
|
|
2441
|
+
recovery_codes: string[];
|
|
2442
|
+
};
|
|
2220
2443
|
/**
|
|
2221
2444
|
* Alternative Method Request
|
|
2222
2445
|
*/
|
|
2223
2446
|
export interface TwoFactorAlternativeRequest {
|
|
2224
2447
|
challenge_id: string;
|
|
2225
2448
|
method: TwoFactorMethod;
|
|
2449
|
+
/** Send a new code; the answer has a new `challenge_id` and the previous code stops working. */
|
|
2450
|
+
resend?: boolean;
|
|
2226
2451
|
}
|
|
2452
|
+
/** POST /v2/user/address-change/proof: a code went to the user's current address. */
|
|
2453
|
+
export type AddressChangeProofResponse = {
|
|
2454
|
+
challenge_id: string;
|
|
2455
|
+
/** The masked email or phone the code went to. */
|
|
2456
|
+
code_sent_to: string;
|
|
2457
|
+
};
|
|
2458
|
+
/**
|
|
2459
|
+
* What a profile save that changes `email` or `phone_number` carries. An emailed or texted code
|
|
2460
|
+
* names the `challenge_id` of `requestAddressChangeProof`; a TOTP or recovery code needs none. A
|
|
2461
|
+
* recovery code is spent by the change.
|
|
2462
|
+
*/
|
|
2463
|
+
export type AddressChangeProof = {
|
|
2464
|
+
method: TwoFactorCodeMethod;
|
|
2465
|
+
challenge_id: string;
|
|
2466
|
+
code: string;
|
|
2467
|
+
} | {
|
|
2468
|
+
method: 'totp' | 'recovery_codes';
|
|
2469
|
+
code: string;
|
|
2470
|
+
challenge_id?: never;
|
|
2471
|
+
};
|
|
2472
|
+
/** The fields a user can write with PATCH /user/profile. Only the keys present are written. */
|
|
2473
|
+
export type PassflowProfileUpdate = {
|
|
2474
|
+
username?: string;
|
|
2475
|
+
email?: string;
|
|
2476
|
+
phone_number?: string;
|
|
2477
|
+
given_name?: string;
|
|
2478
|
+
family_name?: string;
|
|
2479
|
+
middle_name?: string;
|
|
2480
|
+
nickname?: string;
|
|
2481
|
+
preferred_username?: string;
|
|
2482
|
+
profile?: string;
|
|
2483
|
+
picture?: string;
|
|
2484
|
+
website?: string;
|
|
2485
|
+
gender?: string;
|
|
2486
|
+
/** RFC 3339 date-time. */
|
|
2487
|
+
birthday?: string;
|
|
2488
|
+
timezone?: string;
|
|
2489
|
+
locale?: string;
|
|
2490
|
+
};
|
|
2227
2491
|
export interface CLIAuthStatusResponse {
|
|
2228
2492
|
status: 'pending' | 'completed' | 'expired' | 'failed';
|
|
2229
2493
|
expires_at?: string;
|
|
@@ -2322,7 +2586,7 @@ export declare enum PassflowEvent {
|
|
|
2322
2586
|
* The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
|
|
2323
2587
|
* emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
|
|
2324
2588
|
*/
|
|
2325
|
-
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'enterprise.resolve' | 'enterprise.start' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'session.list' | 'session.revoke' | 'session.revoke-others' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'anti-bot.token' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke' | '2fa.preferred-method.read' | '2fa.preferred-method.set' | '2fa.preferred-method.clear';
|
|
2589
|
+
type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'passwordless.wait' | 'passwordless.approval' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | 'federated.redirect' | 'enterprise.resolve' | 'enterprise.start' | 'auth-redirect.url' | 'auth-redirect' | 'redirect.check' | 'auth.is-authenticated' | 'session.check' | 'session.list' | 'session.revoke' | 'session.revoke-others' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'oidc.redirect' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | 'anti-bot.token' | 'settings.app' | 'settings.all' | 'settings.password-policy' | 'settings.passkey' | 'passkey.list' | 'passkey.rename' | 'passkey.delete' | 'passkey.add' | 'tenant.create' | 'invitation.join' | 'invitation.request-link' | 'invitation.list' | 'invitation.delete' | 'invitation.resend' | 'invitation.get-link' | '2fa.status' | '2fa.setup.begin' | '2fa.setup.confirm' | '2fa.enrollment.read' | '2fa.enrollment.setup-link' | '2fa.verify' | '2fa.recovery.use' | '2fa.disable' | '2fa.recovery.regenerate' | '2fa.methods.available' | '2fa.methods.registered' | '2fa.method.setup.start' | '2fa.method.setup.complete' | '2fa.method.remove' | '2fa.challenge.request' | '2fa.challenge.verify' | '2fa.method.switch' | '2fa.trusted-devices.list' | '2fa.trusted-devices.revoke' | '2fa.preferred-method.read' | '2fa.preferred-method.set' | '2fa.preferred-method.clear' | '2fa.recovery-codes.start' | '2fa.recovery-codes.complete' | 'profile.update' | 'profile.address-proof';
|
|
2326
2590
|
/**
|
|
2327
2591
|
* Error payload interface for structured error information
|
|
2328
2592
|
*/
|
|
@@ -2543,139 +2807,6 @@ type AntiBotMark = {
|
|
|
2543
2807
|
/** Set by the response interceptor before the one resend after `anti_bot.failed`. */
|
|
2544
2808
|
retried?: boolean;
|
|
2545
2809
|
};
|
|
2546
|
-
/** The error code RFC 9470 §3 defines for an insufficient authentication event. */
|
|
2547
|
-
export declare const INSUFFICIENT_USER_AUTHENTICATION = "insufficient_user_authentication";
|
|
2548
|
-
/** The ADR-2 error code `/auth/session/exchange` returns in its 403 body. */
|
|
2549
|
-
export declare const UPGRADE_REQUIRED = "upgrade_required";
|
|
2550
|
-
/**
|
|
2551
|
-
* What the server demands before it will serve the original request.
|
|
2552
|
-
*
|
|
2553
|
-
* Both fields are optional because the two middlewares challenge on different
|
|
2554
|
-
* axes: RequireAuthLevel names an `acrValues` and omits `maxAge`, while
|
|
2555
|
-
* RequireFreshAuth does the reverse. A challenge carrying neither is still
|
|
2556
|
-
* valid — it means "re-prove a factor" without further qualification.
|
|
2557
|
-
*/
|
|
2558
|
-
type UpgradeChallenge = {
|
|
2559
|
-
/**
|
|
2560
|
-
* Required authentication context class (`acr`), e.g. `'2'`.
|
|
2561
|
-
*
|
|
2562
|
-
* After a two-channel merge this is the raw list of the channel that SET THE
|
|
2563
|
-
* BAR, with the header preferred on a numeric tie. A channel that contributed
|
|
2564
|
-
* no level never supplies it — showing `"2gold"` as the bar would
|
|
2565
|
-
* misrepresent what the server demanded.
|
|
2566
|
-
*/
|
|
2567
|
-
acrValues?: string;
|
|
2568
|
-
/**
|
|
2569
|
-
* The parsed bar: `max` over each channel's `min` participating level
|
|
2570
|
-
* (§13.2.1a). `undefined` means unknown or unconstrained on this axis.
|
|
2571
|
-
*
|
|
2572
|
-
* Optional, and absent from the single-channel parsers' output, so
|
|
2573
|
-
* `parseChallengeHeader` / `parseChallengeBody` keep the exact shape they
|
|
2574
|
-
* ship with. `readUpgradeChallenge` always sets it when a level was parsed.
|
|
2575
|
-
*/
|
|
2576
|
-
requiredLevel?: number;
|
|
2577
|
-
/** Maximum permitted age of the authentication event, in seconds. */
|
|
2578
|
-
maxAge?: number;
|
|
2579
|
-
/** The status that carried the challenge: 401 (protected resource) or 403 (session exchange). */
|
|
2580
|
-
status: number;
|
|
2581
|
-
/**
|
|
2582
|
-
* The factors this user can use, in the order to offer them, from the `403` body's
|
|
2583
|
-
* `available_factors`. Absent when the server does not send it (older servers, the header channel).
|
|
2584
|
-
*/
|
|
2585
|
-
availableFactors?: UpgradeFactorType[];
|
|
2586
|
-
/**
|
|
2587
|
-
* The `403` body's `sign_in_required`: `true` when only a fresh sign-in can meet
|
|
2588
|
-
* the challenge, `false` when a step-up could but `availableFactors` names none
|
|
2589
|
-
* this account has (for example a device-bound passkey for AAL3). Absent from
|
|
2590
|
-
* older servers.
|
|
2591
|
-
*/
|
|
2592
|
-
signInRequired?: boolean;
|
|
2593
|
-
/**
|
|
2594
|
-
* Every channel that PARSED AS A CHALLENGE in any field — not only the
|
|
2595
|
-
* channels that won a comparison. An opaque header contributes no constraint
|
|
2596
|
-
* yet must still be counted, because only something that saw and discarded it
|
|
2597
|
-
* can report it. `length === 2` means "both channels carried a challenge".
|
|
2598
|
-
*
|
|
2599
|
-
* Set by `readUpgradeChallenge`; absent from the single-channel parsers.
|
|
2600
|
-
*/
|
|
2601
|
-
channels?: ChallengeChannel[];
|
|
2602
|
-
};
|
|
2603
|
-
/** Which wire channel a challenge was read from. */
|
|
2604
|
-
type ChallengeChannel = 'header' | 'body';
|
|
2605
|
-
/**
|
|
2606
|
-
* Reads a upgrade challenge out of a `WWW-Authenticate` header, or returns
|
|
2607
|
-
* `undefined` when the header is absent or describes some other failure.
|
|
2608
|
-
*
|
|
2609
|
-
* The header must both use the `Bearer` scheme and carry
|
|
2610
|
-
* `error="insufficient_user_authentication"`. A bare `WWW-Authenticate: Bearer`
|
|
2611
|
-
* (what an expired token produces) is deliberately NOT a upgrade challenge.
|
|
2612
|
-
*/
|
|
2613
|
-
export declare const parseChallengeHeader: (header: string | undefined | null, status: number) => UpgradeChallenge | undefined;
|
|
2614
|
-
/**
|
|
2615
|
-
* Reads a upgrade challenge out of the ADR-2 `403` body. Used as a fallback
|
|
2616
|
-
* for `/auth/session/exchange`, whose JSON body is the documented SDK contract
|
|
2617
|
-
* even though it also sets the standard header.
|
|
2618
|
-
*/
|
|
2619
|
-
export declare const parseChallengeBody: (body: unknown, status: number) => UpgradeChallenge | undefined;
|
|
2620
|
-
/** The bar a challenge demanded, or an elevation reached, on both axes. */
|
|
2621
|
-
type AssuranceBar = {
|
|
2622
|
-
/** The raw winning `acr_values` list, for display and diagnostics. */
|
|
2623
|
-
acrValues?: string;
|
|
2624
|
-
/** The parsed bar. `undefined` = unknown, or not constrained on this axis. */
|
|
2625
|
-
level?: number;
|
|
2626
|
-
/** The freshness constraint, when that is what was demanded. */
|
|
2627
|
-
maxAge?: number;
|
|
2628
|
-
};
|
|
2629
|
-
/** The reasons the SDK can decline to act on a challenge, or act on a suspect one. */
|
|
2630
|
-
type UpgradeDiagnosticReason = 'no-channel' | 'header-required-but-absent' | 'channels-disagree' | 'channels-unorderable' | 'zero-constraint-ignored' | 'challenge-out-of-scope' | 'elevated-insufficient' | 'replay-unsupported';
|
|
2631
|
-
/**
|
|
2632
|
-
* One diagnostic record.
|
|
2633
|
-
*
|
|
2634
|
-
* A diagnostic is the only observable signal of the response-rewriting and the
|
|
2635
|
-
* misconfiguration this design warns about, so it routes through a callback
|
|
2636
|
-
* whose DEFAULT sink is `console.warn` — never `debug`, which is invisible in
|
|
2637
|
-
* every default configuration. A deployment where step-up silently never fires
|
|
2638
|
-
* must be distinguishable from one where it was never required.
|
|
2639
|
-
*/
|
|
2640
|
-
type UpgradeDiagnostic = {
|
|
2641
|
-
status: number;
|
|
2642
|
-
/**
|
|
2643
|
-
* The request's URL. The parser does not know it — it is handed a status, a
|
|
2644
|
-
* header reader and a body — so it emits `''` and the core, which owns the
|
|
2645
|
-
* request context, fills it in before forwarding to the sink.
|
|
2646
|
-
*/
|
|
2647
|
-
url: string;
|
|
2648
|
-
reason: UpgradeDiagnosticReason;
|
|
2649
|
-
detail?: {
|
|
2650
|
-
obtained?: AssuranceBar;
|
|
2651
|
-
required?: AssuranceBar;
|
|
2652
|
-
/** Raw channel inputs, including values discarded as unorderable. */
|
|
2653
|
-
header?: string;
|
|
2654
|
-
body?: string;
|
|
2655
|
-
/** Which field was discarded, for `'zero-constraint-ignored'`. */
|
|
2656
|
-
field?: 'acr_values' | 'max_age';
|
|
2657
|
-
/** Which operation, for per-waiter reasons. */
|
|
2658
|
-
method?: string;
|
|
2659
|
-
/** A human-readable sentence naming the fix. The default sink prints it. */
|
|
2660
|
-
message?: string;
|
|
2661
|
-
};
|
|
2662
|
-
};
|
|
2663
|
-
/** Where diagnostics go. `console.warn` is the default sink, not the only one. */
|
|
2664
|
-
type UpgradeDiagnosticSink = (diagnostic: UpgradeDiagnostic) => void;
|
|
2665
|
-
/**
|
|
2666
|
-
* Resolves a upgrade challenge from a response, from either channel.
|
|
2667
|
-
*
|
|
2668
|
-
* The SHIPPED export: same name, same three parameters, same return, published
|
|
2669
|
-
* in `@passflow/core@0.14.1`. It is now a thin delegate over
|
|
2670
|
-
* `readUpgradeChallenge`, so there is one merge rule rather than two parsers
|
|
2671
|
-
* that can drift — but it discards the diagnostics, which is why a caller that
|
|
2672
|
-
* needs them (the core) calls the sibling directly.
|
|
2673
|
-
*
|
|
2674
|
-
* Returns `undefined` for every response that is not a upgrade challenge —
|
|
2675
|
-
* including ordinary `401`s, which callers must keep treating as "session
|
|
2676
|
-
* expired".
|
|
2677
|
-
*/
|
|
2678
|
-
export declare const parseUpgradeChallenge: (status: number, getHeader: (name: string) => string | undefined | null, body?: unknown) => UpgradeChallenge | undefined;
|
|
2679
2810
|
/**
|
|
2680
2811
|
* Handles a challenge the Passflow instance itself received, resolving with a
|
|
2681
2812
|
* replayed response once the session has been elevated.
|
|
@@ -2742,6 +2873,11 @@ declare class AxiosClient {
|
|
|
2742
2873
|
*/
|
|
2743
2874
|
readonly upgradeDomain: UpgradeDomain | null;
|
|
2744
2875
|
constructor(config: PassflowConfig, storageManager?: StorageManager, deviceService?: DeviceService);
|
|
2876
|
+
/**
|
|
2877
|
+
* Settles a failed response: a retry, a replay after a step-up, or the rejection the caller gets.
|
|
2878
|
+
* The interceptor above takes the request data off a rejected `AxiosError` once this is done.
|
|
2879
|
+
*/
|
|
2880
|
+
private onResponseError;
|
|
2745
2881
|
/**
|
|
2746
2882
|
* The `setSessionInvalid()` suppression predicate, keyed on the request that
|
|
2747
2883
|
* failed and on the response that came back — never on "this response does not
|
|
@@ -3317,10 +3453,12 @@ export declare class TwoFactorApiClient {
|
|
|
3317
3453
|
*/
|
|
3318
3454
|
getAvailableMethods(): Promise<TwoFactorMethod[]>;
|
|
3319
3455
|
/**
|
|
3320
|
-
* Get registered 2FA methods for current user
|
|
3456
|
+
* Get registered 2FA methods for current user, in the order sign-in challenges them
|
|
3321
3457
|
* GET /v2/user/2fa/methods
|
|
3458
|
+
*
|
|
3459
|
+
* Only the query keys that are not `undefined` are sent; without any, the request has no query.
|
|
3322
3460
|
*/
|
|
3323
|
-
getRegisteredMethods(): Promise<RegisteredTwoFactorMethod[]>;
|
|
3461
|
+
getRegisteredMethods(query?: RegisteredTwoFactorMethodsQuery): Promise<RegisteredTwoFactorMethod[]>;
|
|
3324
3462
|
/**
|
|
3325
3463
|
* Start 2FA method setup.
|
|
3326
3464
|
* POST /v2/user/2fa/setup/start
|
|
@@ -3334,6 +3472,18 @@ export declare class TwoFactorApiClient {
|
|
|
3334
3472
|
* POST /v2/user/2fa/setup/complete
|
|
3335
3473
|
*/
|
|
3336
3474
|
completeMethodSetup(method: TwoFactorMethod, payload: Record<string, unknown>): Promise<unknown>;
|
|
3475
|
+
/**
|
|
3476
|
+
* Send a code to the user's verified email or phone, to issue recovery codes with
|
|
3477
|
+
* POST /v2/user/2fa/setup/start
|
|
3478
|
+
*
|
|
3479
|
+
* Needs a session at level 2.
|
|
3480
|
+
*/
|
|
3481
|
+
startRecoveryCodesByCode(via: TwoFactorCodeMethod): Promise<TwoFactorRecoveryCodesByCodeStartResponse>;
|
|
3482
|
+
/**
|
|
3483
|
+
* Exchange the sent code for new recovery codes, which replace any older ones
|
|
3484
|
+
* POST /v2/user/2fa/setup/complete
|
|
3485
|
+
*/
|
|
3486
|
+
completeRecoveryCodesByCode(setupId: string, code: string): Promise<TwoFactorRecoveryCodesByCodeCompleteResponse>;
|
|
3337
3487
|
/**
|
|
3338
3488
|
* Remove registered 2FA method
|
|
3339
3489
|
* DELETE /v2/user/2fa/methods/:id
|
|
@@ -3444,6 +3594,16 @@ export declare class UserAPI {
|
|
|
3444
3594
|
getUserSessions(): Promise<PassflowUserSessionList>;
|
|
3445
3595
|
revokeUserSession(sessionId: string): Promise<void>;
|
|
3446
3596
|
revokeOtherUserSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
|
|
3597
|
+
/**
|
|
3598
|
+
* Send a code to the user's current verified email or phone, to prove an address change with
|
|
3599
|
+
* POST /v2/user/address-change/proof
|
|
3600
|
+
*/
|
|
3601
|
+
requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
|
|
3602
|
+
/**
|
|
3603
|
+
* Write the given profile fields; `proof` goes along only when given
|
|
3604
|
+
* PATCH /user/profile
|
|
3605
|
+
*/
|
|
3606
|
+
updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
|
|
3447
3607
|
}
|
|
3448
3608
|
export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
|
|
3449
3609
|
export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
|
|
@@ -5182,9 +5342,19 @@ export declare class TwoFactorService {
|
|
|
5182
5342
|
*/
|
|
5183
5343
|
getAvailableMethods(): Promise<TwoFactorMethod[]>;
|
|
5184
5344
|
/**
|
|
5185
|
-
* Get registered 2FA methods for current user
|
|
5345
|
+
* Get registered 2FA methods for current user, in the order sign-in challenges them.
|
|
5346
|
+
* `query` narrows the answer to a purpose; without it the request is the plain list.
|
|
5347
|
+
*/
|
|
5348
|
+
getRegisteredMethods(query?: RegisteredTwoFactorMethodsQuery): Promise<RegisteredTwoFactorMethod[]>;
|
|
5349
|
+
/**
|
|
5350
|
+
* Send a code to the user's verified email or phone, to issue recovery codes with.
|
|
5351
|
+
* Needs a session at level 2; below it rejects with `PassflowRecoveryCodesStepUpRequiredError`.
|
|
5352
|
+
*/
|
|
5353
|
+
startRecoveryCodesByCode(via: TwoFactorCodeMethod): Promise<TwoFactorRecoveryCodesByCodeStartResponse>;
|
|
5354
|
+
/**
|
|
5355
|
+
* Exchange the sent code for new recovery codes. They replace any older ones and are shown once.
|
|
5186
5356
|
*/
|
|
5187
|
-
|
|
5357
|
+
completeRecoveryCodesByCode(setupId: string, code: string): Promise<TwoFactorRecoveryCodesByCodeCompleteResponse>;
|
|
5188
5358
|
/**
|
|
5189
5359
|
* Start 2FA method setup
|
|
5190
5360
|
*/
|
|
@@ -5288,6 +5458,19 @@ export declare class UserService {
|
|
|
5288
5458
|
* @returns Promise with the number of sessions ended
|
|
5289
5459
|
*/
|
|
5290
5460
|
signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
|
|
5461
|
+
/**
|
|
5462
|
+
* Send a code to the user's current email or phone, to prove an address change with
|
|
5463
|
+
* @param method Where the code goes
|
|
5464
|
+
* @returns Promise with the challenge id and the masked address
|
|
5465
|
+
*/
|
|
5466
|
+
requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
|
|
5467
|
+
/**
|
|
5468
|
+
* Write the given profile fields
|
|
5469
|
+
* @param patch The fields to write
|
|
5470
|
+
* @param proof Needed when the patch changes email or phone_number
|
|
5471
|
+
* @returns Promise with the saved user
|
|
5472
|
+
*/
|
|
5473
|
+
updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
|
|
5291
5474
|
}
|
|
5292
5475
|
/**
|
|
5293
5476
|
* The level an `acr_values` list demands, or `undefined` for no constraint.
|
|
@@ -7286,6 +7469,43 @@ export declare class Passflow {
|
|
|
7286
7469
|
* ```
|
|
7287
7470
|
*/
|
|
7288
7471
|
signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
|
|
7472
|
+
/**
|
|
7473
|
+
* Send a code to the user's current verified email or phone. Its `challenge_id` and the code the
|
|
7474
|
+
* user received are the proof `updateProfile` carries to change the email or phone number.
|
|
7475
|
+
*
|
|
7476
|
+
* @param method - `'email_otp'` or `'sms_otp'`: which current address gets the code
|
|
7477
|
+
* @returns Promise with the `challenge_id` and the masked address the code went to
|
|
7478
|
+
* @throws {PassflowSendLimitError} If the app's send limit is spent (`retryAfter` in seconds)
|
|
7479
|
+
* @throws {PassflowSmsQuotaExceededError} If the user's monthly text quota is spent
|
|
7480
|
+
* @throws {PassflowError} If request fails
|
|
7481
|
+
*
|
|
7482
|
+
* @example
|
|
7483
|
+
* ```typescript
|
|
7484
|
+
* const { challenge_id, code_sent_to } = await passflow.requestAddressChangeProof('sms_otp');
|
|
7485
|
+
* ```
|
|
7486
|
+
*/
|
|
7487
|
+
requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
|
|
7488
|
+
/**
|
|
7489
|
+
* Write the given fields of the current user's profile; fields left out stay as they are.
|
|
7490
|
+
* A change of `email` or `phone_number` needs `proof`, unless the session signed in or stepped up
|
|
7491
|
+
* with a second factor in the last 15 minutes, or the user has nothing to prove with.
|
|
7492
|
+
*
|
|
7493
|
+
* @param patch - The profile fields to write
|
|
7494
|
+
* @param proof - A code from `requestAddressChangeProof`, a TOTP code or a recovery code
|
|
7495
|
+
* @returns Promise with the saved user
|
|
7496
|
+
* @throws {PassflowAddressChangeProofRequiredError} If the change needs a proof the call did not carry
|
|
7497
|
+
* @throws {PassflowError} If request fails
|
|
7498
|
+
*
|
|
7499
|
+
* @example
|
|
7500
|
+
* ```typescript
|
|
7501
|
+
* const { challenge_id } = await passflow.requestAddressChangeProof('sms_otp');
|
|
7502
|
+
* await passflow.updateProfile(
|
|
7503
|
+
* { phone_number: '+15550100' },
|
|
7504
|
+
* { method: 'sms_otp', challenge_id, code: '123456' },
|
|
7505
|
+
* );
|
|
7506
|
+
* ```
|
|
7507
|
+
*/
|
|
7508
|
+
updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
|
|
7289
7509
|
/** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
|
|
7290
7510
|
private currentSessionId;
|
|
7291
7511
|
/**
|