@passflow/core 0.24.0 → 0.25.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
@@ -1042,6 +1042,10 @@ export declare enum PassflowEndpointPaths {
1042
1042
  twoFactorRecovery = "/auth/2fa/recovery",
1043
1043
  twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate",
1044
1044
  twoFactorSetupMagicLink = "/auth/2fa-setup", // :token param appended in API call
1045
+ twoFactorEnrollment = "/auth/2fa/enrollment",
1046
+ twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link",
1047
+ twoFactorEnrollmentBegin = "/auth/2fa/setup/begin",
1048
+ twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm",
1045
1049
  TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available",
1046
1050
  TwoFactorMethodsRegistered = "/v2/user/2fa/methods",
1047
1051
  TwoFactorSetupStart = "/v2/user/2fa/setup/start",
@@ -1817,13 +1821,33 @@ export type TwoFactorStatusResponse = {
1817
1821
  };
1818
1822
  export type TwoFactorSetupResponse = {
1819
1823
  secret: string;
1824
+ /** Base64-encoded PNG of the QR code. Empty when the server sent no image: use `qr_code_url`. */
1820
1825
  qr_code: string;
1826
+ /** The `otpauth://` URL the QR code holds. */
1827
+ qr_code_url?: string;
1821
1828
  totp_digits?: 6 | 8;
1822
1829
  };
1823
1830
  export type TwoFactorConfirmResponse = {
1824
1831
  success: true;
1832
+ enabled?: boolean;
1825
1833
  recovery_codes: string[];
1826
1834
  };
1835
+ /**
1836
+ * What a sign-in waiting on its second factor can do next, decided by the server:
1837
+ * - `verify`: ask for a code; the user has a factor the app accepts.
1838
+ * - `email_link`: no factor yet and a validated email: send the setup link, then the user signs in again.
1839
+ * - `direct`: no factor and no validated email: enrol here, then finish with the code.
1840
+ * - `unavailable`: the app offers no way to enrol this user: contact the administrator.
1841
+ */
1842
+ export type TwoFactorEnrollment = 'verify' | 'email_link' | 'direct' | 'unavailable';
1843
+ /** GET /auth/2fa/enrollment */
1844
+ export type TwoFactorEnrollmentResponse = {
1845
+ enrollment: TwoFactorEnrollment;
1846
+ };
1847
+ /** POST /auth/2fa/enrollment/email-link */
1848
+ export type TwoFactorSetupLinkResponse = {
1849
+ email_sent: boolean;
1850
+ };
1827
1851
  export type TwoFactorVerifyResponse = Tokens & {
1828
1852
  success: true;
1829
1853
  /** On a PKCE app; `TwoFactorService` redeems it, so its callers never see one. */
@@ -1872,7 +1896,7 @@ export type TwoFactorRegenerateResponse = {
1872
1896
  /**
1873
1897
  * Two-Factor magic link error codes
1874
1898
  */
1875
- export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
1899
+ export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
1876
1900
  /**
1877
1901
  * Two-Factor magic link error details
1878
1902
  */
@@ -2475,20 +2499,46 @@ export declare class TwoFactorApiClient {
2475
2499
  /**
2476
2500
  * Get current 2FA enrollment status
2477
2501
  * GET /user/2fa/status
2502
+ *
2503
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2478
2504
  */
2479
- getStatus(): Promise<TwoFactorStatusResponse>;
2505
+ getStatus(setupSessionToken?: string): Promise<TwoFactorStatusResponse>;
2480
2506
  /**
2481
2507
  * Begin 2FA setup process
2482
2508
  * POST /user/2fa/setup/begin
2483
2509
  * Returns secret and QR code for authenticator app
2510
+ *
2511
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2484
2512
  */
2485
- beginSetup(): Promise<TwoFactorSetupResponse>;
2513
+ beginSetup(setupSessionToken?: string): Promise<TwoFactorSetupResponse>;
2486
2514
  /**
2487
2515
  * Confirm 2FA setup with TOTP code
2488
2516
  * POST /user/2fa/setup/confirm
2489
2517
  * Returns recovery codes on success
2518
+ *
2519
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2520
+ */
2521
+ confirmSetup(payload: TwoFactorConfirmRequest, setupSessionToken?: string): Promise<TwoFactorConfirmResponse>;
2522
+ /**
2523
+ * What a sign-in waiting on its second factor can do next
2524
+ * GET /auth/2fa/enrollment
2525
+ */
2526
+ getEnrollment(tfaToken: string): Promise<TwoFactorEnrollment>;
2527
+ /**
2528
+ * Email the user a link to set up 2FA
2529
+ * POST /auth/2fa/enrollment/email-link
2530
+ */
2531
+ sendSetupLink(tfaToken: string): Promise<TwoFactorSetupLinkResponse>;
2532
+ /**
2533
+ * Begin 2FA setup on the sign-in itself, for a user with no validated email
2534
+ * POST /auth/2fa/setup/begin
2490
2535
  */
2491
- confirmSetup(payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
2536
+ beginEnrollment(tfaToken: string): Promise<TwoFactorSetupResponse>;
2537
+ /**
2538
+ * Confirm 2FA setup on the sign-in itself; `verify` with the same code then finishes it
2539
+ * POST /auth/2fa/setup/confirm
2540
+ */
2541
+ confirmEnrollment(tfaToken: string, payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
2492
2542
  /**
2493
2543
  * Verify TOTP code during login
2494
2544
  * POST /auth/2fa/verify
@@ -3393,7 +3443,7 @@ export declare enum PassflowEvent {
3393
3443
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3394
3444
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3395
3445
  */
3396
- 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' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | '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.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';
3446
+ 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' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | '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';
3397
3447
  /**
3398
3448
  * Error payload interface for structured error information
3399
3449
  */
@@ -3514,7 +3564,7 @@ type PassflowEventPayload = {
3514
3564
  };
3515
3565
  [PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
3516
3566
  error: {
3517
- code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
3567
+ code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
3518
3568
  message: string;
3519
3569
  retryAfter?: number;
3520
3570
  };
@@ -4321,13 +4371,39 @@ export declare class TwoFactorService {
4321
4371
  /**
4322
4372
  * Begin 2FA setup process
4323
4373
  * Returns secret and QR code for authenticator app
4374
+ *
4375
+ * With a setup link's session active the call runs on that session, whoever is signed in here.
4324
4376
  */
4325
4377
  beginSetup(): Promise<TwoFactorSetupResponse>;
4326
4378
  /**
4327
4379
  * Confirm 2FA setup with TOTP code
4328
4380
  * Returns recovery codes that MUST be displayed to user
4381
+ *
4382
+ * With a setup link's session active the call runs on that session, which it then ends.
4329
4383
  */
4330
4384
  confirmSetup(code: string): Promise<TwoFactorConfirmResponse>;
4385
+ /**
4386
+ * What the sign-in waiting on its second factor can do next. Read this before asking for a code:
4387
+ * the server decides, and only `verify` means the user has a factor to enter a code from.
4388
+ */
4389
+ getEnrollment(): Promise<TwoFactorEnrollment>;
4390
+ /**
4391
+ * Email the user a link to set up 2FA (`email_link`). They sign in again after enrolling.
4392
+ */
4393
+ sendSetupLink(): Promise<TwoFactorSetupLinkResponse>;
4394
+ /**
4395
+ * Begin 2FA setup on the sign-in itself (`direct`).
4396
+ */
4397
+ beginEnrollment(): Promise<TwoFactorSetupResponse>;
4398
+ /**
4399
+ * Confirm 2FA setup on the sign-in itself (`direct`). The sign-in stays pending:
4400
+ * show the recovery codes, then `verify` with the same code finishes it.
4401
+ */
4402
+ confirmEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
4403
+ private assertTotpCode;
4404
+ private requirePendingTfaToken;
4405
+ private setupStarted;
4406
+ private setupConfirmed;
4331
4407
  /**
4332
4408
  * Verify TOTP code during login
4333
4409
  * Completes authentication if successful
@@ -4419,7 +4495,7 @@ export declare class TwoFactorService {
4419
4495
  hasMagicLinkSession(): boolean;
4420
4496
  /**
4421
4497
  * Get the session token from magic link session (if active)
4422
- * Used by AxiosClient for injecting auth header on 2FA setup endpoints
4498
+ * `getStatus`, `beginSetup` and `confirmSetup` send it as their bearer while it is active
4423
4499
  */
4424
4500
  getMagicLinkSessionToken(): string | null;
4425
4501
  /**
@@ -6452,6 +6528,39 @@ export declare class Passflow {
6452
6528
  * ```
6453
6529
  */
6454
6530
  confirmTwoFactorSetup(code: string): Promise<TwoFactorConfirmResponse>;
6531
+ /**
6532
+ * What the sign-in waiting on its second factor can do next. The server decides; read this
6533
+ * before asking for a code, and call `requestChallenge` only on `verify`.
6534
+ *
6535
+ * @returns `verify`: ask for a code. `email_link`: `sendTwoFactorSetupLink`, then the user signs
6536
+ * in again after enrolling. `direct`: `beginTwoFactorEnrollment`, `confirmTwoFactorEnrollment`,
6537
+ * then `verifyTwoFactor`. `unavailable`: tell the user to contact the administrator.
6538
+ * @throws {PassflowError} A 401 means the sign-in is over: sign in again.
6539
+ */
6540
+ getTwoFactorEnrollment(): Promise<TwoFactorEnrollment>;
6541
+ /**
6542
+ * Email the user a link to set up 2FA, on a sign-in whose enrollment is `email_link`.
6543
+ * The budget is 3 requests in 5 minutes, shared with `requestChallenge`, so limit resends.
6544
+ *
6545
+ * @throws {PassflowError} 503 `error.2fa.setup_link.send_failed` when the email could not be sent
6546
+ */
6547
+ sendTwoFactorSetupLink(): Promise<TwoFactorSetupLinkResponse>;
6548
+ /**
6549
+ * Begin 2FA setup on the pending sign-in, when its enrollment is `direct`.
6550
+ * Returns a secret and QR code to scan with an authenticator app.
6551
+ *
6552
+ * @throws {PassflowError} 403 `error.2fa.enrollment.not_allowed` in any other state
6553
+ */
6554
+ beginTwoFactorEnrollment(): Promise<TwoFactorSetupResponse>;
6555
+ /**
6556
+ * Confirm 2FA setup on the pending sign-in. The sign-in stays pending: show the recovery codes,
6557
+ * then `verifyTwoFactor` with the same code finishes it.
6558
+ *
6559
+ * @param code - TOTP code from the authenticator app
6560
+ * @returns Promise with the recovery codes the user must save
6561
+ * @throws {PassflowError} 401 `error.api.request.2fa_code.invalid` on a wrong code
6562
+ */
6563
+ confirmTwoFactorEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
6455
6564
  /**
6456
6565
  * Verify a TOTP code during login when 2FA is required.
6457
6566
  * Completes the authentication process and saves tokens.
package/dist/index.d.ts CHANGED
@@ -1042,6 +1042,10 @@ export declare enum PassflowEndpointPaths {
1042
1042
  twoFactorRecovery = "/auth/2fa/recovery",
1043
1043
  twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate",
1044
1044
  twoFactorSetupMagicLink = "/auth/2fa-setup", // :token param appended in API call
1045
+ twoFactorEnrollment = "/auth/2fa/enrollment",
1046
+ twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link",
1047
+ twoFactorEnrollmentBegin = "/auth/2fa/setup/begin",
1048
+ twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm",
1045
1049
  TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available",
1046
1050
  TwoFactorMethodsRegistered = "/v2/user/2fa/methods",
1047
1051
  TwoFactorSetupStart = "/v2/user/2fa/setup/start",
@@ -1817,13 +1821,33 @@ export type TwoFactorStatusResponse = {
1817
1821
  };
1818
1822
  export type TwoFactorSetupResponse = {
1819
1823
  secret: string;
1824
+ /** Base64-encoded PNG of the QR code. Empty when the server sent no image: use `qr_code_url`. */
1820
1825
  qr_code: string;
1826
+ /** The `otpauth://` URL the QR code holds. */
1827
+ qr_code_url?: string;
1821
1828
  totp_digits?: 6 | 8;
1822
1829
  };
1823
1830
  export type TwoFactorConfirmResponse = {
1824
1831
  success: true;
1832
+ enabled?: boolean;
1825
1833
  recovery_codes: string[];
1826
1834
  };
1835
+ /**
1836
+ * What a sign-in waiting on its second factor can do next, decided by the server:
1837
+ * - `verify`: ask for a code; the user has a factor the app accepts.
1838
+ * - `email_link`: no factor yet and a validated email: send the setup link, then the user signs in again.
1839
+ * - `direct`: no factor and no validated email: enrol here, then finish with the code.
1840
+ * - `unavailable`: the app offers no way to enrol this user: contact the administrator.
1841
+ */
1842
+ export type TwoFactorEnrollment = 'verify' | 'email_link' | 'direct' | 'unavailable';
1843
+ /** GET /auth/2fa/enrollment */
1844
+ export type TwoFactorEnrollmentResponse = {
1845
+ enrollment: TwoFactorEnrollment;
1846
+ };
1847
+ /** POST /auth/2fa/enrollment/email-link */
1848
+ export type TwoFactorSetupLinkResponse = {
1849
+ email_sent: boolean;
1850
+ };
1827
1851
  export type TwoFactorVerifyResponse = Tokens & {
1828
1852
  success: true;
1829
1853
  /** On a PKCE app; `TwoFactorService` redeems it, so its callers never see one. */
@@ -1872,7 +1896,7 @@ export type TwoFactorRegenerateResponse = {
1872
1896
  /**
1873
1897
  * Two-Factor magic link error codes
1874
1898
  */
1875
- export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
1899
+ export type TwoFactorSetupMagicLinkErrorCode = 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
1876
1900
  /**
1877
1901
  * Two-Factor magic link error details
1878
1902
  */
@@ -2475,20 +2499,46 @@ export declare class TwoFactorApiClient {
2475
2499
  /**
2476
2500
  * Get current 2FA enrollment status
2477
2501
  * GET /user/2fa/status
2502
+ *
2503
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2478
2504
  */
2479
- getStatus(): Promise<TwoFactorStatusResponse>;
2505
+ getStatus(setupSessionToken?: string): Promise<TwoFactorStatusResponse>;
2480
2506
  /**
2481
2507
  * Begin 2FA setup process
2482
2508
  * POST /user/2fa/setup/begin
2483
2509
  * Returns secret and QR code for authenticator app
2510
+ *
2511
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2484
2512
  */
2485
- beginSetup(): Promise<TwoFactorSetupResponse>;
2513
+ beginSetup(setupSessionToken?: string): Promise<TwoFactorSetupResponse>;
2486
2514
  /**
2487
2515
  * Confirm 2FA setup with TOTP code
2488
2516
  * POST /user/2fa/setup/confirm
2489
2517
  * Returns recovery codes on success
2518
+ *
2519
+ * `setupSessionToken` is a setup link's session; without it the stored session is used.
2520
+ */
2521
+ confirmSetup(payload: TwoFactorConfirmRequest, setupSessionToken?: string): Promise<TwoFactorConfirmResponse>;
2522
+ /**
2523
+ * What a sign-in waiting on its second factor can do next
2524
+ * GET /auth/2fa/enrollment
2525
+ */
2526
+ getEnrollment(tfaToken: string): Promise<TwoFactorEnrollment>;
2527
+ /**
2528
+ * Email the user a link to set up 2FA
2529
+ * POST /auth/2fa/enrollment/email-link
2530
+ */
2531
+ sendSetupLink(tfaToken: string): Promise<TwoFactorSetupLinkResponse>;
2532
+ /**
2533
+ * Begin 2FA setup on the sign-in itself, for a user with no validated email
2534
+ * POST /auth/2fa/setup/begin
2490
2535
  */
2491
- confirmSetup(payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
2536
+ beginEnrollment(tfaToken: string): Promise<TwoFactorSetupResponse>;
2537
+ /**
2538
+ * Confirm 2FA setup on the sign-in itself; `verify` with the same code then finishes it
2539
+ * POST /auth/2fa/setup/confirm
2540
+ */
2541
+ confirmEnrollment(tfaToken: string, payload: TwoFactorConfirmRequest): Promise<TwoFactorConfirmResponse>;
2492
2542
  /**
2493
2543
  * Verify TOTP code during login
2494
2544
  * POST /auth/2fa/verify
@@ -3393,7 +3443,7 @@ export declare enum PassflowEvent {
3393
3443
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3394
3444
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3395
3445
  */
3396
- 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' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | '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.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';
3446
+ 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' | 'auth-redirect.url' | 'auth-redirect' | 'auth.is-authenticated' | 'session.check' | 'tokens.get' | 'tokens.load' | 'tokens.from-url' | 'refresh' | 'upgrade.commit' | 'log-out' | 'reset' | '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';
3397
3447
  /**
3398
3448
  * Error payload interface for structured error information
3399
3449
  */
@@ -3514,7 +3564,7 @@ type PassflowEventPayload = {
3514
3564
  };
3515
3565
  [PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
3516
3566
  error: {
3517
- code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'RATE_LIMITED' | 'SERVER_ERROR';
3567
+ code: 'INVALID_TOKEN' | 'EXPIRED_TOKEN' | 'REVOKED_TOKEN' | 'ALREADY_USED' | 'RATE_LIMITED' | 'SERVER_ERROR';
3518
3568
  message: string;
3519
3569
  retryAfter?: number;
3520
3570
  };
@@ -4321,13 +4371,39 @@ export declare class TwoFactorService {
4321
4371
  /**
4322
4372
  * Begin 2FA setup process
4323
4373
  * Returns secret and QR code for authenticator app
4374
+ *
4375
+ * With a setup link's session active the call runs on that session, whoever is signed in here.
4324
4376
  */
4325
4377
  beginSetup(): Promise<TwoFactorSetupResponse>;
4326
4378
  /**
4327
4379
  * Confirm 2FA setup with TOTP code
4328
4380
  * Returns recovery codes that MUST be displayed to user
4381
+ *
4382
+ * With a setup link's session active the call runs on that session, which it then ends.
4329
4383
  */
4330
4384
  confirmSetup(code: string): Promise<TwoFactorConfirmResponse>;
4385
+ /**
4386
+ * What the sign-in waiting on its second factor can do next. Read this before asking for a code:
4387
+ * the server decides, and only `verify` means the user has a factor to enter a code from.
4388
+ */
4389
+ getEnrollment(): Promise<TwoFactorEnrollment>;
4390
+ /**
4391
+ * Email the user a link to set up 2FA (`email_link`). They sign in again after enrolling.
4392
+ */
4393
+ sendSetupLink(): Promise<TwoFactorSetupLinkResponse>;
4394
+ /**
4395
+ * Begin 2FA setup on the sign-in itself (`direct`).
4396
+ */
4397
+ beginEnrollment(): Promise<TwoFactorSetupResponse>;
4398
+ /**
4399
+ * Confirm 2FA setup on the sign-in itself (`direct`). The sign-in stays pending:
4400
+ * show the recovery codes, then `verify` with the same code finishes it.
4401
+ */
4402
+ confirmEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
4403
+ private assertTotpCode;
4404
+ private requirePendingTfaToken;
4405
+ private setupStarted;
4406
+ private setupConfirmed;
4331
4407
  /**
4332
4408
  * Verify TOTP code during login
4333
4409
  * Completes authentication if successful
@@ -4419,7 +4495,7 @@ export declare class TwoFactorService {
4419
4495
  hasMagicLinkSession(): boolean;
4420
4496
  /**
4421
4497
  * Get the session token from magic link session (if active)
4422
- * Used by AxiosClient for injecting auth header on 2FA setup endpoints
4498
+ * `getStatus`, `beginSetup` and `confirmSetup` send it as their bearer while it is active
4423
4499
  */
4424
4500
  getMagicLinkSessionToken(): string | null;
4425
4501
  /**
@@ -6452,6 +6528,39 @@ export declare class Passflow {
6452
6528
  * ```
6453
6529
  */
6454
6530
  confirmTwoFactorSetup(code: string): Promise<TwoFactorConfirmResponse>;
6531
+ /**
6532
+ * What the sign-in waiting on its second factor can do next. The server decides; read this
6533
+ * before asking for a code, and call `requestChallenge` only on `verify`.
6534
+ *
6535
+ * @returns `verify`: ask for a code. `email_link`: `sendTwoFactorSetupLink`, then the user signs
6536
+ * in again after enrolling. `direct`: `beginTwoFactorEnrollment`, `confirmTwoFactorEnrollment`,
6537
+ * then `verifyTwoFactor`. `unavailable`: tell the user to contact the administrator.
6538
+ * @throws {PassflowError} A 401 means the sign-in is over: sign in again.
6539
+ */
6540
+ getTwoFactorEnrollment(): Promise<TwoFactorEnrollment>;
6541
+ /**
6542
+ * Email the user a link to set up 2FA, on a sign-in whose enrollment is `email_link`.
6543
+ * The budget is 3 requests in 5 minutes, shared with `requestChallenge`, so limit resends.
6544
+ *
6545
+ * @throws {PassflowError} 503 `error.2fa.setup_link.send_failed` when the email could not be sent
6546
+ */
6547
+ sendTwoFactorSetupLink(): Promise<TwoFactorSetupLinkResponse>;
6548
+ /**
6549
+ * Begin 2FA setup on the pending sign-in, when its enrollment is `direct`.
6550
+ * Returns a secret and QR code to scan with an authenticator app.
6551
+ *
6552
+ * @throws {PassflowError} 403 `error.2fa.enrollment.not_allowed` in any other state
6553
+ */
6554
+ beginTwoFactorEnrollment(): Promise<TwoFactorSetupResponse>;
6555
+ /**
6556
+ * Confirm 2FA setup on the pending sign-in. The sign-in stays pending: show the recovery codes,
6557
+ * then `verifyTwoFactor` with the same code finishes it.
6558
+ *
6559
+ * @param code - TOTP code from the authenticator app
6560
+ * @returns Promise with the recovery codes the user must save
6561
+ * @throws {PassflowError} 401 `error.api.request.2fa_code.invalid` on a wrong code
6562
+ */
6563
+ confirmTwoFactorEnrollment(code: string): Promise<TwoFactorConfirmResponse>;
6455
6564
  /**
6456
6565
  * Verify a TOTP code during login when 2FA is required.
6457
6566
  * Completes the authentication process and saves tokens.