@passflow/core 0.37.1 → 0.39.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.d.cts 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,48 @@ 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
+ /** No code was sent: the app's send limit or the challenge budget is spent (429). */
1430
+ export declare class PassflowSendLimitError extends PassflowError {
1431
+ /** Seconds to wait, from `Retry-After`; undefined when the server sent none. */
1432
+ readonly retryAfter?: number;
1433
+ constructor(error: PassflowResponseError['error'], retryAfter?: number, options?: {
1434
+ cause?: unknown;
1435
+ });
1436
+ }
1437
+ /**
1438
+ * Recovery codes need a session at level 2 (403). Step up to `challenge`, or sign in again, then
1439
+ * repeat the call.
1440
+ */
1441
+ export declare class PassflowRecoveryCodesStepUpRequiredError extends PassflowError {
1442
+ /** The RFC 9470 challenge; at least `{ acrValues: '2', requiredLevel: 2, status: 403 }`. */
1443
+ readonly challenge: UpgradeChallenge;
1444
+ constructor(error: PassflowResponseError['error'], challenge: UpgradeChallenge, options?: {
1445
+ cause?: unknown;
1446
+ });
1447
+ }
1448
+ /** A change of email or phone number needs a proof the save did not carry (403). */
1449
+ export declare class PassflowAddressChangeProofRequiredError extends PassflowError {
1450
+ constructor(error: PassflowResponseError['error'], options?: {
1451
+ cause?: unknown;
1452
+ });
1453
+ }
1277
1454
  export type PassflowSignInPayload = {
1278
1455
  password: string;
1279
1456
  scopes?: string[];
@@ -2025,6 +2202,11 @@ export type TwoFactorEnrollmentResponse = {
2025
2202
  * Absent when the user has none, and from servers that do not send it.
2026
2203
  */
2027
2204
  account_hint?: string;
2205
+ /**
2206
+ * With `enrollment: 'unavailable'`: the only way on is an email or phone number the user has not
2207
+ * verified yet.
2208
+ */
2209
+ verify_address?: boolean;
2028
2210
  };
2029
2211
  /** POST /auth/2fa/enrollment/email-link */
2030
2212
  export type TwoFactorSetupLinkResponse = {
@@ -2139,12 +2321,19 @@ export type TwoFactorSetupMagicLinkSession = {
2139
2321
  * Two-Factor method types
2140
2322
  */
2141
2323
  export type TwoFactorMethod = 'totp' | 'email_otp' | 'sms_otp' | 'passkey' | 'push_fcm' | 'push_webpush' | 'recovery_codes';
2324
+ /** The second factors that send a code to the user's email or phone. */
2325
+ export type TwoFactorCodeMethod = 'email_otp' | 'sms_otp';
2142
2326
  /**
2143
2327
  * Challenge Request for v2 2FA flow
2144
2328
  */
2145
2329
  export interface TwoFactorChallengeRequest {
2146
2330
  first_factor_method?: string;
2147
2331
  trust_device?: boolean;
2332
+ /**
2333
+ * Send a new code. The answer has a new `challenge_id` and the previous code stops working.
2334
+ * Without it, a live code of this sign-in is answered again and nothing is sent.
2335
+ */
2336
+ resend?: boolean;
2148
2337
  }
2149
2338
  /**
2150
2339
  * Challenge Response from v2 2FA flow
@@ -2161,7 +2350,10 @@ export interface TwoFactorChallengeResponse {
2161
2350
  /** Other methods the user can switch to. Absent when there are none. */
2162
2351
  alternative_methods?: TwoFactorMethod[];
2163
2352
  expires_at: string;
2353
+ /** The masked email or phone the code went to. Emailed and texted codes only. */
2164
2354
  code_sent_to?: string;
2355
+ /** Minutes the code stays valid, whole and at least 1. Emailed and texted codes only. */
2356
+ expires_in_minutes?: number;
2165
2357
  webauthn_options?: unknown;
2166
2358
  /** Digits in the TOTP code. TOTP challenges only. */
2167
2359
  totp_digits?: 6 | 8;
@@ -2216,14 +2408,83 @@ export interface RegisteredTwoFactorMethod {
2216
2408
  created_at?: string;
2217
2409
  updated_at?: string;
2218
2410
  last_used_at?: string;
2411
+ /** The highest acr a step-up with this factor reaches; `''` without a session. */
2412
+ reaches_acr_max?: '1' | '2' | '3' | '';
2413
+ /** `true` when the client asks for a challenge first (every method but totp and recovery_codes). */
2414
+ requires_prepare?: boolean;
2415
+ /** The masked email or phone for `email_otp` / `sms_otp`; `''` otherwise. */
2416
+ code_sent_to_hint?: string;
2417
+ /** `true` on the first item. */
2418
+ recommended?: boolean;
2219
2419
  }
2420
+ /** Query of GET /v2/user/2fa/methods. Keys left undefined are not sent. */
2421
+ export type RegisteredTwoFactorMethodsQuery = {
2422
+ purpose?: 'two_factor' | 'upgrade';
2423
+ required_acr?: string;
2424
+ /** Seconds. */
2425
+ max_age?: number;
2426
+ };
2427
+ /** POST /v2/user/2fa/setup/start with method `recovery_codes` and a code method as `via`. */
2428
+ export type TwoFactorRecoveryCodesByCodeStartResponse = {
2429
+ setup_id: string;
2430
+ method: 'recovery_codes';
2431
+ /** The masked email or phone the code went to. */
2432
+ code_sent_to: string;
2433
+ };
2434
+ /** POST /v2/user/2fa/setup/complete with method `recovery_codes`. The codes are shown once. */
2435
+ export type TwoFactorRecoveryCodesByCodeCompleteResponse = {
2436
+ confirmed: boolean;
2437
+ /** The new codes; they replace any older ones. */
2438
+ recovery_codes: string[];
2439
+ };
2220
2440
  /**
2221
2441
  * Alternative Method Request
2222
2442
  */
2223
2443
  export interface TwoFactorAlternativeRequest {
2224
2444
  challenge_id: string;
2225
2445
  method: TwoFactorMethod;
2446
+ /** Send a new code; the answer has a new `challenge_id` and the previous code stops working. */
2447
+ resend?: boolean;
2226
2448
  }
2449
+ /** POST /v2/user/address-change/proof: a code went to the user's current address. */
2450
+ export type AddressChangeProofResponse = {
2451
+ challenge_id: string;
2452
+ /** The masked email or phone the code went to. */
2453
+ code_sent_to: string;
2454
+ };
2455
+ /**
2456
+ * What a profile save that changes `email` or `phone_number` carries. An emailed or texted code
2457
+ * names the `challenge_id` of `requestAddressChangeProof`; a TOTP or recovery code needs none. A
2458
+ * recovery code is spent by the change.
2459
+ */
2460
+ export type AddressChangeProof = {
2461
+ method: TwoFactorCodeMethod;
2462
+ challenge_id: string;
2463
+ code: string;
2464
+ } | {
2465
+ method: 'totp' | 'recovery_codes';
2466
+ code: string;
2467
+ challenge_id?: never;
2468
+ };
2469
+ /** The fields a user can write with PATCH /user/profile. Only the keys present are written. */
2470
+ export type PassflowProfileUpdate = {
2471
+ username?: string;
2472
+ email?: string;
2473
+ phone_number?: string;
2474
+ given_name?: string;
2475
+ family_name?: string;
2476
+ middle_name?: string;
2477
+ nickname?: string;
2478
+ preferred_username?: string;
2479
+ profile?: string;
2480
+ picture?: string;
2481
+ website?: string;
2482
+ gender?: string;
2483
+ /** RFC 3339 date-time. */
2484
+ birthday?: string;
2485
+ timezone?: string;
2486
+ locale?: string;
2487
+ };
2227
2488
  export interface CLIAuthStatusResponse {
2228
2489
  status: 'pending' | 'completed' | 'expired' | 'failed';
2229
2490
  expires_at?: string;
@@ -2322,7 +2583,7 @@ export declare enum PassflowEvent {
2322
2583
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
2323
2584
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
2324
2585
  */
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';
2586
+ 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
2587
  /**
2327
2588
  * Error payload interface for structured error information
2328
2589
  */
@@ -2543,139 +2804,6 @@ type AntiBotMark = {
2543
2804
  /** Set by the response interceptor before the one resend after `anti_bot.failed`. */
2544
2805
  retried?: boolean;
2545
2806
  };
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
2807
  /**
2680
2808
  * Handles a challenge the Passflow instance itself received, resolving with a
2681
2809
  * replayed response once the session has been elevated.
@@ -3317,10 +3445,12 @@ export declare class TwoFactorApiClient {
3317
3445
  */
3318
3446
  getAvailableMethods(): Promise<TwoFactorMethod[]>;
3319
3447
  /**
3320
- * Get registered 2FA methods for current user
3448
+ * Get registered 2FA methods for current user, in the order sign-in challenges them
3321
3449
  * GET /v2/user/2fa/methods
3450
+ *
3451
+ * Only the query keys that are not `undefined` are sent; without any, the request has no query.
3322
3452
  */
3323
- getRegisteredMethods(): Promise<RegisteredTwoFactorMethod[]>;
3453
+ getRegisteredMethods(query?: RegisteredTwoFactorMethodsQuery): Promise<RegisteredTwoFactorMethod[]>;
3324
3454
  /**
3325
3455
  * Start 2FA method setup.
3326
3456
  * POST /v2/user/2fa/setup/start
@@ -3334,6 +3464,18 @@ export declare class TwoFactorApiClient {
3334
3464
  * POST /v2/user/2fa/setup/complete
3335
3465
  */
3336
3466
  completeMethodSetup(method: TwoFactorMethod, payload: Record<string, unknown>): Promise<unknown>;
3467
+ /**
3468
+ * Send a code to the user's verified email or phone, to issue recovery codes with
3469
+ * POST /v2/user/2fa/setup/start
3470
+ *
3471
+ * Needs a session at level 2.
3472
+ */
3473
+ startRecoveryCodesByCode(via: TwoFactorCodeMethod): Promise<TwoFactorRecoveryCodesByCodeStartResponse>;
3474
+ /**
3475
+ * Exchange the sent code for new recovery codes, which replace any older ones
3476
+ * POST /v2/user/2fa/setup/complete
3477
+ */
3478
+ completeRecoveryCodesByCode(setupId: string, code: string): Promise<TwoFactorRecoveryCodesByCodeCompleteResponse>;
3337
3479
  /**
3338
3480
  * Remove registered 2FA method
3339
3481
  * DELETE /v2/user/2fa/methods/:id
@@ -3444,6 +3586,16 @@ export declare class UserAPI {
3444
3586
  getUserSessions(): Promise<PassflowUserSessionList>;
3445
3587
  revokeUserSession(sessionId: string): Promise<void>;
3446
3588
  revokeOtherUserSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
3589
+ /**
3590
+ * Send a code to the user's current verified email or phone, to prove an address change with
3591
+ * POST /v2/user/address-change/proof
3592
+ */
3593
+ requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
3594
+ /**
3595
+ * Write the given profile fields; `proof` goes along only when given
3596
+ * PATCH /user/profile
3597
+ */
3598
+ updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
3447
3599
  }
3448
3600
  export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
3449
3601
  export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
@@ -5182,9 +5334,19 @@ export declare class TwoFactorService {
5182
5334
  */
5183
5335
  getAvailableMethods(): Promise<TwoFactorMethod[]>;
5184
5336
  /**
5185
- * Get registered 2FA methods for current user
5337
+ * Get registered 2FA methods for current user, in the order sign-in challenges them.
5338
+ * `query` narrows the answer to a purpose; without it the request is the plain list.
5186
5339
  */
5187
- getRegisteredMethods(): Promise<RegisteredTwoFactorMethod[]>;
5340
+ getRegisteredMethods(query?: RegisteredTwoFactorMethodsQuery): Promise<RegisteredTwoFactorMethod[]>;
5341
+ /**
5342
+ * Send a code to the user's verified email or phone, to issue recovery codes with.
5343
+ * Needs a session at level 2; below it rejects with `PassflowRecoveryCodesStepUpRequiredError`.
5344
+ */
5345
+ startRecoveryCodesByCode(via: TwoFactorCodeMethod): Promise<TwoFactorRecoveryCodesByCodeStartResponse>;
5346
+ /**
5347
+ * Exchange the sent code for new recovery codes. They replace any older ones and are shown once.
5348
+ */
5349
+ completeRecoveryCodesByCode(setupId: string, code: string): Promise<TwoFactorRecoveryCodesByCodeCompleteResponse>;
5188
5350
  /**
5189
5351
  * Start 2FA method setup
5190
5352
  */
@@ -5288,6 +5450,19 @@ export declare class UserService {
5288
5450
  * @returns Promise with the number of sessions ended
5289
5451
  */
5290
5452
  signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
5453
+ /**
5454
+ * Send a code to the user's current email or phone, to prove an address change with
5455
+ * @param method Where the code goes
5456
+ * @returns Promise with the challenge id and the masked address
5457
+ */
5458
+ requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
5459
+ /**
5460
+ * Write the given profile fields
5461
+ * @param patch The fields to write
5462
+ * @param proof Needed when the patch changes email or phone_number
5463
+ * @returns Promise with the saved user
5464
+ */
5465
+ updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
5291
5466
  }
5292
5467
  /**
5293
5468
  * The level an `acr_values` list demands, or `undefined` for no constraint.
@@ -7286,6 +7461,43 @@ export declare class Passflow {
7286
7461
  * ```
7287
7462
  */
7288
7463
  signOutOtherSessions(): Promise<PassflowRevokeOtherSessionsResponse>;
7464
+ /**
7465
+ * Send a code to the user's current verified email or phone. Its `challenge_id` and the code the
7466
+ * user received are the proof `updateProfile` carries to change the email or phone number.
7467
+ *
7468
+ * @param method - `'email_otp'` or `'sms_otp'`: which current address gets the code
7469
+ * @returns Promise with the `challenge_id` and the masked address the code went to
7470
+ * @throws {PassflowSendLimitError} If the app's send limit is spent (`retryAfter` in seconds)
7471
+ * @throws {PassflowSmsQuotaExceededError} If the user's monthly text quota is spent
7472
+ * @throws {PassflowError} If request fails
7473
+ *
7474
+ * @example
7475
+ * ```typescript
7476
+ * const { challenge_id, code_sent_to } = await passflow.requestAddressChangeProof('sms_otp');
7477
+ * ```
7478
+ */
7479
+ requestAddressChangeProof(method: TwoFactorCodeMethod): Promise<AddressChangeProofResponse>;
7480
+ /**
7481
+ * Write the given fields of the current user's profile; fields left out stay as they are.
7482
+ * A change of `email` or `phone_number` needs `proof`, unless the session signed in or stepped up
7483
+ * with a second factor in the last 15 minutes, or the user has nothing to prove with.
7484
+ *
7485
+ * @param patch - The profile fields to write
7486
+ * @param proof - A code from `requestAddressChangeProof`, a TOTP code or a recovery code
7487
+ * @returns Promise with the saved user
7488
+ * @throws {PassflowAddressChangeProofRequiredError} If the change needs a proof the call did not carry
7489
+ * @throws {PassflowError} If request fails
7490
+ *
7491
+ * @example
7492
+ * ```typescript
7493
+ * const { challenge_id } = await passflow.requestAddressChangeProof('sms_otp');
7494
+ * await passflow.updateProfile(
7495
+ * { phone_number: '+15550100' },
7496
+ * { method: 'sms_otp', challenge_id, code: '123456' },
7497
+ * );
7498
+ * ```
7499
+ */
7500
+ updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
7289
7501
  /** The `sid` of the stored access token, else of the stored ID token; undefined when neither is readable. */
7290
7502
  private currentSessionId;
7291
7503
  /**
@@ -7452,6 +7664,19 @@ export declare class Passflow {
7452
7664
  * ```
7453
7665
  */
7454
7666
  getDeliveryMode(): TokenDeliveryMode;
7667
+ /**
7668
+ * The id that identifies this browser or device to Passflow.
7669
+ * It is the same value the SDK sends with every request. It is read from storage;
7670
+ * on first use it is minted and stored, so later calls and page loads return the same id.
7671
+ *
7672
+ * @returns The device id
7673
+ *
7674
+ * @example
7675
+ * ```typescript
7676
+ * const deviceId = passflow.getDeviceId();
7677
+ * ```
7678
+ */
7679
+ getDeviceId(): string;
7455
7680
  /**
7456
7681
  * Restore and validate session for cookie mode on page load.
7457
7682
  * Only applicable when using cookie-based token delivery.