@passflow/core 0.36.0 → 0.37.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
@@ -991,6 +991,7 @@ export declare enum PassflowEndpointPaths {
991
991
  TwoFactorAlternative = "/v2/auth/2fa/alternative",
992
992
  TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices",
993
993
  TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id",
994
+ TwoFactorPreferredMethod = "/v2/user/2fa/preferred-method",
994
995
  cliAuthStatus = "/cli/auth/status/:sessionId",
995
996
  cliAuthComplete = "/cli/auth/complete",
996
997
  upgradeStart = "/auth/upgrade/start",
@@ -1451,11 +1452,23 @@ export type AuthStrategies = {
1451
1452
  };
1452
1453
  export type AppType = 'web' | 'spa' | 'bff' | 'android' | 'ios' | 'desktop' | 'm2m' | 'other';
1453
1454
  export type TokenDeliveryMethod = 'json_body' | 'cookie' | '';
1455
+ /** One connection in `AppSettings.connections`. */
1456
+ export type AppSettingsConnection = {
1457
+ /**
1458
+ * The bare connection id. The provider for `federatedAuthWithRedirect` and
1459
+ * `federatedAuthWithPopup` is `conn_<id>`: pass `` `conn_${id}` ``.
1460
+ */
1461
+ id: string;
1462
+ /** What the sign-in button shows. */
1463
+ name: string;
1464
+ /** The identity provider's kind. */
1465
+ provider: string;
1466
+ };
1454
1467
  /**
1455
1468
  * The public app-settings read (`GET /app/settings`) sends only `id`, `name`, `description`,
1456
1469
  * `offline`, `type`, `custom_email_templates`, `auth_strategies`, the four registration and
1457
1470
  * merge flags, `force_passwordless_login`, `login_app_theme`, `pkce_enabled`, `public_client`,
1458
- * and `defaults` when the server has them; the rest come with admin reads.
1471
+ * `connections` and `defaults` when the server has them; the rest come with admin reads.
1459
1472
  */
1460
1473
  export type AppSettings = {
1461
1474
  id: string;
@@ -1480,6 +1493,11 @@ export type AppSettings = {
1480
1493
  * on servers that do not report it.
1481
1494
  */
1482
1495
  public_client?: boolean;
1496
+ /**
1497
+ * The enabled, verified connections a sign-in button may offer for this app. Empty when the app
1498
+ * has none; absent when the server has no connection storage.
1499
+ */
1500
+ connections?: AppSettingsConnection[];
1483
1501
  custom_sms_messages?: boolean;
1484
1502
  registration_allowed: boolean;
1485
1503
  invite_only_registration?: boolean;
@@ -2002,6 +2020,11 @@ export type TwoFactorEnrollmentResponse = {
2002
2020
  * Absent from servers older than the flag; treat absent as unknown.
2003
2021
  */
2004
2022
  device_trust_available?: boolean;
2023
+ /**
2024
+ * A masked name of the account signing in: the email, else the phone, else the username.
2025
+ * Absent when the user has none, and from servers that do not send it.
2026
+ */
2027
+ account_hint?: string;
2005
2028
  };
2006
2029
  /** POST /auth/2fa/enrollment/email-link */
2007
2030
  export type TwoFactorSetupLinkResponse = {
@@ -2051,6 +2074,11 @@ export type TwoFactorTrustedDevice = {
2051
2074
  export type TwoFactorTrustedDevicesResponse = {
2052
2075
  devices: TwoFactorTrustedDevice[];
2053
2076
  };
2077
+ /** GET, PUT and DELETE /v2/user/2fa/preferred-method */
2078
+ export type TwoFactorPreferredMethodResponse = {
2079
+ /** `null` when the user has no preference this app can use now. */
2080
+ preferred_method: TwoFactorMethod | null;
2081
+ };
2054
2082
  export type TwoFactorRecoveryResponse = Tokens & {
2055
2083
  success?: true;
2056
2084
  /** Codes left after this one. The server may leave it out. */
@@ -2086,6 +2114,11 @@ export type TwoFactorSetupMagicLinkValidationResponse = {
2086
2114
  userId?: string;
2087
2115
  expiresIn?: number;
2088
2116
  appId?: string | null;
2117
+ /**
2118
+ * On a success: `true` for a link an administrator sent to replace an enrolled authenticator.
2119
+ * Its session replaces that authenticator once, when setup begins, without a code.
2120
+ */
2121
+ reset?: boolean;
2089
2122
  error?: TwoFactorSetupMagicLinkError;
2090
2123
  };
2091
2124
  /**
@@ -2097,6 +2130,8 @@ export type TwoFactorSetupMagicLinkSession = {
2097
2130
  userId: string;
2098
2131
  appId?: string | null;
2099
2132
  scope: '2fa_setup';
2133
+ /** `true` when the link replaces an enrolled authenticator. The SDK always sets it. */
2134
+ reset?: boolean;
2100
2135
  timestamp: number;
2101
2136
  expiresAt: number;
2102
2137
  };
@@ -2117,7 +2152,13 @@ export interface TwoFactorChallengeRequest {
2117
2152
  export interface TwoFactorChallengeResponse {
2118
2153
  challenge_id: string;
2119
2154
  method: TwoFactorMethod;
2120
- /** Other methods the user can switch to. Absent from the answer to a switch. */
2155
+ /**
2156
+ * The method login offers first. From `requestChallenge` it equals `method`; from
2157
+ * `switchToAlternative` it stays the suggestion while `method` is the one the user chose.
2158
+ * Absent from servers that do not send it.
2159
+ */
2160
+ suggested_method?: TwoFactorMethod;
2161
+ /** Other methods the user can switch to. Absent when there are none. */
2121
2162
  alternative_methods?: TwoFactorMethod[];
2122
2163
  expires_at: string;
2123
2164
  code_sent_to?: string;
@@ -2131,6 +2172,11 @@ export interface TwoFactorChallengeResponse {
2131
2172
  * Absent from servers older than the flag; treat absent as unknown.
2132
2173
  */
2133
2174
  device_trust_available?: boolean;
2175
+ /**
2176
+ * A masked name of the account signing in: the email, else the phone, else the username.
2177
+ * Absent when the user has none, and from servers that do not send it.
2178
+ */
2179
+ account_hint?: string;
2134
2180
  }
2135
2181
  /**
2136
2182
  * Verify Request for v2 2FA flow
@@ -2162,6 +2208,11 @@ export interface RegisteredTwoFactorMethod {
2162
2208
  app_id?: string;
2163
2209
  /** `true` when this passkey also signs the user in as the first factor. */
2164
2210
  is_passkey_for_1fa?: boolean;
2211
+ /**
2212
+ * `true` on the user's preferred method, on at most one item. Absent from servers that do not
2213
+ * send it.
2214
+ */
2215
+ preferred?: boolean;
2165
2216
  created_at?: string;
2166
2217
  updated_at?: string;
2167
2218
  last_used_at?: string;
@@ -2271,7 +2322,7 @@ export declare enum PassflowEvent {
2271
2322
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
2272
2323
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
2273
2324
  */
2274
- 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';
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';
2275
2326
  /**
2276
2327
  * Error payload interface for structured error information
2277
2328
  */
@@ -2396,6 +2447,8 @@ type PassflowEventPayload = {
2396
2447
  appId?: string | null;
2397
2448
  expiresIn: number;
2398
2449
  sessionToken: string;
2450
+ /** `true` when the link replaces an enrolled authenticator. The SDK always sets it. */
2451
+ reset?: boolean;
2399
2452
  };
2400
2453
  [PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
2401
2454
  error: {
@@ -3320,6 +3373,25 @@ export declare class TwoFactorApiClient {
3320
3373
  * The server answers 404 when the user has no such device.
3321
3374
  */
3322
3375
  revokeTrustedDevice(deviceId: string): Promise<void>;
3376
+ /**
3377
+ * Get the user's preferred 2FA method
3378
+ * GET /v2/user/2fa/preferred-method
3379
+ * `null` when the user has no preference this app can use now.
3380
+ */
3381
+ getPreferredMethod(): Promise<TwoFactorMethod | null>;
3382
+ /**
3383
+ * Set the user's preferred 2FA method
3384
+ * PUT /v2/user/2fa/preferred-method
3385
+ * Answers the stored method. The server refuses `recovery_codes` and a method the user
3386
+ * cannot present at this app with 400 `error.2fa.preferred_method.unavailable`.
3387
+ */
3388
+ setPreferredMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
3389
+ /**
3390
+ * Clear the user's preferred 2FA method
3391
+ * DELETE /v2/user/2fa/preferred-method
3392
+ * No error when none is stored.
3393
+ */
3394
+ clearPreferredMethod(): Promise<void>;
3323
3395
  }
3324
3396
  /** The `POST /auth/upgrade/start` request body. `relying_party_id` is passkey-only. */
3325
3397
  export type UpgradeStartPayload = {
@@ -5148,6 +5220,21 @@ export declare class TwoFactorService {
5148
5220
  * Rejects with the server's 404 when the user has no such device.
5149
5221
  */
5150
5222
  revokeTrustedDevice(deviceId: string): Promise<void>;
5223
+ /**
5224
+ * The method the user prefers as their second factor on this app, or `null` when there is
5225
+ * none the app can use now.
5226
+ */
5227
+ getPreferredMethod(): Promise<TwoFactorMethod | null>;
5228
+ /**
5229
+ * Store the user's preferred second factor; resolves the method the server stored.
5230
+ * Rejects with the server's 400 `error.2fa.preferred_method.unavailable` for `recovery_codes`
5231
+ * and for a method the user cannot present at this app.
5232
+ */
5233
+ setPreferredMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
5234
+ /**
5235
+ * Remove the user's preferred second factor. Resolves also when none was stored.
5236
+ */
5237
+ clearPreferredMethod(): Promise<void>;
5151
5238
  }
5152
5239
  /**
5153
5240
  * Service for managing user profile, passkeys and sessions
@@ -7559,6 +7646,45 @@ export declare class Passflow {
7559
7646
  * ```
7560
7647
  */
7561
7648
  revokeTrustedDevice(id: string): Promise<void>;
7649
+ /**
7650
+ * Read the second factor the signed-in user prefers on this app.
7651
+ *
7652
+ * @returns Promise with the method, or `null` when the user has no preference the app can use now
7653
+ * @throws {PassflowError} If the request fails
7654
+ *
7655
+ * @example
7656
+ * ```typescript
7657
+ * const preferred = await passflow.getPreferredTwoFactorMethod();
7658
+ * console.log(preferred ?? 'no preferred method');
7659
+ * ```
7660
+ */
7661
+ getPreferredTwoFactorMethod(): Promise<TwoFactorMethod | null>;
7662
+ /**
7663
+ * Store the second factor the signed-in user prefers on this app. Sign-in then offers it first.
7664
+ *
7665
+ * @param method - A method the user can present at this app; not `recovery_codes`
7666
+ * @returns Promise with the method the server stored
7667
+ * @throws {PassflowError} If the request fails, including a 400
7668
+ * `error.2fa.preferred_method.unavailable` for `recovery_codes`, an unknown method, or one the
7669
+ * user cannot present at this app
7670
+ *
7671
+ * @example
7672
+ * ```typescript
7673
+ * await passflow.setPreferredTwoFactorMethod('totp');
7674
+ * ```
7675
+ */
7676
+ setPreferredTwoFactorMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
7677
+ /**
7678
+ * Remove the signed-in user's preferred second factor. Resolves also when none was stored.
7679
+ *
7680
+ * @throws {PassflowError} If the request fails
7681
+ *
7682
+ * @example
7683
+ * ```typescript
7684
+ * await passflow.clearPreferredTwoFactorMethod();
7685
+ * ```
7686
+ */
7687
+ clearPreferredTwoFactorMethod(): Promise<void>;
7562
7688
  /**
7563
7689
  * Check if 2FA verification is currently required (local state check).
7564
7690
  * Returns true if user has signed in but needs to complete 2FA verification.
@@ -7605,6 +7731,7 @@ export declare class Passflow {
7605
7731
  * console.log('Magic link validated');
7606
7732
  * console.log('User ID:', result.userId);
7607
7733
  * console.log('Session expires in:', result.expiresIn, 'seconds');
7734
+ * console.log('Replaces an enrolled authenticator:', result.reset);
7608
7735
  * // Show 2FA setup form
7609
7736
  * } else {
7610
7737
  * console.error('Validation failed:', result.error?.message);
package/dist/index.d.ts CHANGED
@@ -991,6 +991,7 @@ export declare enum PassflowEndpointPaths {
991
991
  TwoFactorAlternative = "/v2/auth/2fa/alternative",
992
992
  TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices",
993
993
  TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id",
994
+ TwoFactorPreferredMethod = "/v2/user/2fa/preferred-method",
994
995
  cliAuthStatus = "/cli/auth/status/:sessionId",
995
996
  cliAuthComplete = "/cli/auth/complete",
996
997
  upgradeStart = "/auth/upgrade/start",
@@ -1451,11 +1452,23 @@ export type AuthStrategies = {
1451
1452
  };
1452
1453
  export type AppType = 'web' | 'spa' | 'bff' | 'android' | 'ios' | 'desktop' | 'm2m' | 'other';
1453
1454
  export type TokenDeliveryMethod = 'json_body' | 'cookie' | '';
1455
+ /** One connection in `AppSettings.connections`. */
1456
+ export type AppSettingsConnection = {
1457
+ /**
1458
+ * The bare connection id. The provider for `federatedAuthWithRedirect` and
1459
+ * `federatedAuthWithPopup` is `conn_<id>`: pass `` `conn_${id}` ``.
1460
+ */
1461
+ id: string;
1462
+ /** What the sign-in button shows. */
1463
+ name: string;
1464
+ /** The identity provider's kind. */
1465
+ provider: string;
1466
+ };
1454
1467
  /**
1455
1468
  * The public app-settings read (`GET /app/settings`) sends only `id`, `name`, `description`,
1456
1469
  * `offline`, `type`, `custom_email_templates`, `auth_strategies`, the four registration and
1457
1470
  * merge flags, `force_passwordless_login`, `login_app_theme`, `pkce_enabled`, `public_client`,
1458
- * and `defaults` when the server has them; the rest come with admin reads.
1471
+ * `connections` and `defaults` when the server has them; the rest come with admin reads.
1459
1472
  */
1460
1473
  export type AppSettings = {
1461
1474
  id: string;
@@ -1480,6 +1493,11 @@ export type AppSettings = {
1480
1493
  * on servers that do not report it.
1481
1494
  */
1482
1495
  public_client?: boolean;
1496
+ /**
1497
+ * The enabled, verified connections a sign-in button may offer for this app. Empty when the app
1498
+ * has none; absent when the server has no connection storage.
1499
+ */
1500
+ connections?: AppSettingsConnection[];
1483
1501
  custom_sms_messages?: boolean;
1484
1502
  registration_allowed: boolean;
1485
1503
  invite_only_registration?: boolean;
@@ -2002,6 +2020,11 @@ export type TwoFactorEnrollmentResponse = {
2002
2020
  * Absent from servers older than the flag; treat absent as unknown.
2003
2021
  */
2004
2022
  device_trust_available?: boolean;
2023
+ /**
2024
+ * A masked name of the account signing in: the email, else the phone, else the username.
2025
+ * Absent when the user has none, and from servers that do not send it.
2026
+ */
2027
+ account_hint?: string;
2005
2028
  };
2006
2029
  /** POST /auth/2fa/enrollment/email-link */
2007
2030
  export type TwoFactorSetupLinkResponse = {
@@ -2051,6 +2074,11 @@ export type TwoFactorTrustedDevice = {
2051
2074
  export type TwoFactorTrustedDevicesResponse = {
2052
2075
  devices: TwoFactorTrustedDevice[];
2053
2076
  };
2077
+ /** GET, PUT and DELETE /v2/user/2fa/preferred-method */
2078
+ export type TwoFactorPreferredMethodResponse = {
2079
+ /** `null` when the user has no preference this app can use now. */
2080
+ preferred_method: TwoFactorMethod | null;
2081
+ };
2054
2082
  export type TwoFactorRecoveryResponse = Tokens & {
2055
2083
  success?: true;
2056
2084
  /** Codes left after this one. The server may leave it out. */
@@ -2086,6 +2114,11 @@ export type TwoFactorSetupMagicLinkValidationResponse = {
2086
2114
  userId?: string;
2087
2115
  expiresIn?: number;
2088
2116
  appId?: string | null;
2117
+ /**
2118
+ * On a success: `true` for a link an administrator sent to replace an enrolled authenticator.
2119
+ * Its session replaces that authenticator once, when setup begins, without a code.
2120
+ */
2121
+ reset?: boolean;
2089
2122
  error?: TwoFactorSetupMagicLinkError;
2090
2123
  };
2091
2124
  /**
@@ -2097,6 +2130,8 @@ export type TwoFactorSetupMagicLinkSession = {
2097
2130
  userId: string;
2098
2131
  appId?: string | null;
2099
2132
  scope: '2fa_setup';
2133
+ /** `true` when the link replaces an enrolled authenticator. The SDK always sets it. */
2134
+ reset?: boolean;
2100
2135
  timestamp: number;
2101
2136
  expiresAt: number;
2102
2137
  };
@@ -2117,7 +2152,13 @@ export interface TwoFactorChallengeRequest {
2117
2152
  export interface TwoFactorChallengeResponse {
2118
2153
  challenge_id: string;
2119
2154
  method: TwoFactorMethod;
2120
- /** Other methods the user can switch to. Absent from the answer to a switch. */
2155
+ /**
2156
+ * The method login offers first. From `requestChallenge` it equals `method`; from
2157
+ * `switchToAlternative` it stays the suggestion while `method` is the one the user chose.
2158
+ * Absent from servers that do not send it.
2159
+ */
2160
+ suggested_method?: TwoFactorMethod;
2161
+ /** Other methods the user can switch to. Absent when there are none. */
2121
2162
  alternative_methods?: TwoFactorMethod[];
2122
2163
  expires_at: string;
2123
2164
  code_sent_to?: string;
@@ -2131,6 +2172,11 @@ export interface TwoFactorChallengeResponse {
2131
2172
  * Absent from servers older than the flag; treat absent as unknown.
2132
2173
  */
2133
2174
  device_trust_available?: boolean;
2175
+ /**
2176
+ * A masked name of the account signing in: the email, else the phone, else the username.
2177
+ * Absent when the user has none, and from servers that do not send it.
2178
+ */
2179
+ account_hint?: string;
2134
2180
  }
2135
2181
  /**
2136
2182
  * Verify Request for v2 2FA flow
@@ -2162,6 +2208,11 @@ export interface RegisteredTwoFactorMethod {
2162
2208
  app_id?: string;
2163
2209
  /** `true` when this passkey also signs the user in as the first factor. */
2164
2210
  is_passkey_for_1fa?: boolean;
2211
+ /**
2212
+ * `true` on the user's preferred method, on at most one item. Absent from servers that do not
2213
+ * send it.
2214
+ */
2215
+ preferred?: boolean;
2165
2216
  created_at?: string;
2166
2217
  updated_at?: string;
2167
2218
  last_used_at?: string;
@@ -2271,7 +2322,7 @@ export declare enum PassflowEvent {
2271
2322
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
2272
2323
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
2273
2324
  */
2274
- 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';
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';
2275
2326
  /**
2276
2327
  * Error payload interface for structured error information
2277
2328
  */
@@ -2396,6 +2447,8 @@ type PassflowEventPayload = {
2396
2447
  appId?: string | null;
2397
2448
  expiresIn: number;
2398
2449
  sessionToken: string;
2450
+ /** `true` when the link replaces an enrolled authenticator. The SDK always sets it. */
2451
+ reset?: boolean;
2399
2452
  };
2400
2453
  [PassflowEvent.TwoFactorSetupMagicLinkFailed]: {
2401
2454
  error: {
@@ -3320,6 +3373,25 @@ export declare class TwoFactorApiClient {
3320
3373
  * The server answers 404 when the user has no such device.
3321
3374
  */
3322
3375
  revokeTrustedDevice(deviceId: string): Promise<void>;
3376
+ /**
3377
+ * Get the user's preferred 2FA method
3378
+ * GET /v2/user/2fa/preferred-method
3379
+ * `null` when the user has no preference this app can use now.
3380
+ */
3381
+ getPreferredMethod(): Promise<TwoFactorMethod | null>;
3382
+ /**
3383
+ * Set the user's preferred 2FA method
3384
+ * PUT /v2/user/2fa/preferred-method
3385
+ * Answers the stored method. The server refuses `recovery_codes` and a method the user
3386
+ * cannot present at this app with 400 `error.2fa.preferred_method.unavailable`.
3387
+ */
3388
+ setPreferredMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
3389
+ /**
3390
+ * Clear the user's preferred 2FA method
3391
+ * DELETE /v2/user/2fa/preferred-method
3392
+ * No error when none is stored.
3393
+ */
3394
+ clearPreferredMethod(): Promise<void>;
3323
3395
  }
3324
3396
  /** The `POST /auth/upgrade/start` request body. `relying_party_id` is passkey-only. */
3325
3397
  export type UpgradeStartPayload = {
@@ -5148,6 +5220,21 @@ export declare class TwoFactorService {
5148
5220
  * Rejects with the server's 404 when the user has no such device.
5149
5221
  */
5150
5222
  revokeTrustedDevice(deviceId: string): Promise<void>;
5223
+ /**
5224
+ * The method the user prefers as their second factor on this app, or `null` when there is
5225
+ * none the app can use now.
5226
+ */
5227
+ getPreferredMethod(): Promise<TwoFactorMethod | null>;
5228
+ /**
5229
+ * Store the user's preferred second factor; resolves the method the server stored.
5230
+ * Rejects with the server's 400 `error.2fa.preferred_method.unavailable` for `recovery_codes`
5231
+ * and for a method the user cannot present at this app.
5232
+ */
5233
+ setPreferredMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
5234
+ /**
5235
+ * Remove the user's preferred second factor. Resolves also when none was stored.
5236
+ */
5237
+ clearPreferredMethod(): Promise<void>;
5151
5238
  }
5152
5239
  /**
5153
5240
  * Service for managing user profile, passkeys and sessions
@@ -7559,6 +7646,45 @@ export declare class Passflow {
7559
7646
  * ```
7560
7647
  */
7561
7648
  revokeTrustedDevice(id: string): Promise<void>;
7649
+ /**
7650
+ * Read the second factor the signed-in user prefers on this app.
7651
+ *
7652
+ * @returns Promise with the method, or `null` when the user has no preference the app can use now
7653
+ * @throws {PassflowError} If the request fails
7654
+ *
7655
+ * @example
7656
+ * ```typescript
7657
+ * const preferred = await passflow.getPreferredTwoFactorMethod();
7658
+ * console.log(preferred ?? 'no preferred method');
7659
+ * ```
7660
+ */
7661
+ getPreferredTwoFactorMethod(): Promise<TwoFactorMethod | null>;
7662
+ /**
7663
+ * Store the second factor the signed-in user prefers on this app. Sign-in then offers it first.
7664
+ *
7665
+ * @param method - A method the user can present at this app; not `recovery_codes`
7666
+ * @returns Promise with the method the server stored
7667
+ * @throws {PassflowError} If the request fails, including a 400
7668
+ * `error.2fa.preferred_method.unavailable` for `recovery_codes`, an unknown method, or one the
7669
+ * user cannot present at this app
7670
+ *
7671
+ * @example
7672
+ * ```typescript
7673
+ * await passflow.setPreferredTwoFactorMethod('totp');
7674
+ * ```
7675
+ */
7676
+ setPreferredTwoFactorMethod(method: TwoFactorMethod): Promise<TwoFactorMethod | null>;
7677
+ /**
7678
+ * Remove the signed-in user's preferred second factor. Resolves also when none was stored.
7679
+ *
7680
+ * @throws {PassflowError} If the request fails
7681
+ *
7682
+ * @example
7683
+ * ```typescript
7684
+ * await passflow.clearPreferredTwoFactorMethod();
7685
+ * ```
7686
+ */
7687
+ clearPreferredTwoFactorMethod(): Promise<void>;
7562
7688
  /**
7563
7689
  * Check if 2FA verification is currently required (local state check).
7564
7690
  * Returns true if user has signed in but needs to complete 2FA verification.
@@ -7605,6 +7731,7 @@ export declare class Passflow {
7605
7731
  * console.log('Magic link validated');
7606
7732
  * console.log('User ID:', result.userId);
7607
7733
  * console.log('Session expires in:', result.expiresIn, 'seconds');
7734
+ * console.log('Replaces an enrolled authenticator:', result.reset);
7608
7735
  * // Show 2FA setup form
7609
7736
  * } else {
7610
7737
  * console.error('Validation failed:', result.error?.message);
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ var i = "__passflowAntiBot", a = (e, t) => {
11
11
  if (typeof e != "object" || !e) return;
12
12
  let t = e[i];
13
13
  return typeof t == "object" && t ? t : void 0;
14
- }, s = "0.36.0", c = "X-Passflow-Clientid", l = "Authorization", u = "X-Passflow-DeviceId", d = "X-Passflow-DeviceType", f = "X-Passflow-Anti-Bot", p = "X-Passflow-Agent-Tool", m = "passflow_auth", h = s, g = [
14
+ }, s = "0.37.0", c = "X-Passflow-Clientid", l = "Authorization", u = "X-Passflow-DeviceId", d = "X-Passflow-DeviceType", f = "X-Passflow-Anti-Bot", p = "X-Passflow-Agent-Tool", m = "passflow_auth", h = s, g = [
15
15
  "id",
16
16
  "offline",
17
17
  "openid"
@@ -675,7 +675,7 @@ var M = /* @__PURE__ */ function(e) {
675
675
  }), Le = (e) => Ne(e, Me), Re = /* @__PURE__ */ function(e) {
676
676
  return e.GET = "get", e.POST = "post", e.PUT = "put", e.PATCH = "patch", e.DELETE = "delete", e;
677
677
  }({}), z = /* @__PURE__ */ function(e) {
678
- return e.signin = "/auth/login", e.signup = "/auth/register", e.pkceExchange = "/auth/pkce_exchange", e.redirectCheck = "/auth/redirect/check", e.signInWithProvider = "/auth/federated/start/", e.passwordless = "/auth/passwordless/start", e.passwordlessComplete = "/auth/passwordless/complete", e.passwordlessStatus = "/auth/passwordless/status", e.passwordlessApprovalInfo = "/auth/passwordless/approval/info", e.passwordlessApprovalDecide = "/auth/passwordless/approval/decide", e.logout = "/user/logout", e.refresh = "/auth/refresh", e.validateSession = "/user/me", e.sendPasswordResetEmail = "/auth/password/reset", e.resetPassword = "/auth/password/change", e.appSettings = "/app/settings", e.passkeyRegisterStart = "/auth/passkey/register/start", e.passkeyRegisterComplete = "/auth/passkey/register/complete", e.passkeyAuthenticateStart = "/auth/passkey/authenticate/start", e.passkeyAuthenticateComplete = "/auth/passkey/authenticate/complete", e.passkeyValidate = "/auth/validate", e.settingsAll = "/settings", e.settingsPasswordPolicy = "/settings/password", e.settingsPasskey = "/settings/passkey", e.userPasskey = "/user/passkey", e.addUserPasskey = "/user/passkey/add/start", e.completeAddUserPasskey = "/user/passkey/add/complete", e.userSessions = "/user/sessions", e.userSessionsRevokeOthers = "/user/sessions/revoke-others", e.joinInvitation = "/user/tenant/join", e.tenantPath = "/user/tenant", e.invitationsPath = "/user/tenant/:tenantID/invitations", e.requestInvitation = "/user/invite", e.invitationDelete = "/user/invite/:invitationID", e.invitationResend = "/user/invite/:invitationID/resend", e.invitationGetLink = "/user/invite/:invitationID/link", e.twoFactor = "/user/2fa", e.twoFactorStatus = "/user/2fa/status", e.twoFactorSetupBegin = "/user/2fa/setup/begin", e.twoFactorSetupConfirm = "/user/2fa/setup/confirm", e.twoFactorVerify = "/auth/2fa/verify", e.twoFactorRecovery = "/auth/2fa/recovery", e.twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate", e.twoFactorSetupMagicLink = "/auth/2fa-setup", e.twoFactorEnrollment = "/auth/2fa/enrollment", e.twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link", e.twoFactorEnrollmentBegin = "/auth/2fa/setup/begin", e.twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm", e.TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available", e.TwoFactorMethodsRegistered = "/v2/user/2fa/methods", e.TwoFactorSetupStart = "/v2/user/2fa/setup/start", e.TwoFactorSetupComplete = "/v2/user/2fa/setup/complete", e.TwoFactorMethodRemove = "/v2/user/2fa/methods/:id", e.TwoFactorChallenge = "/v2/auth/2fa/challenge", e.TwoFactorVerifyV2 = "/v2/auth/2fa/verify", e.TwoFactorAlternative = "/v2/auth/2fa/alternative", e.TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices", e.TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id", e.cliAuthStatus = "/cli/auth/status/:sessionId", e.cliAuthComplete = "/cli/auth/complete", e.upgradeStart = "/auth/upgrade/start", e.hostedUpgradeStart = "/auth/session/upgrade/start", e.hostedUpgrade = "/auth/session/upgrade", e.antiBotChallenge = "/auth/anti-bot/challenge", e.deviceAntiBotChallenge = "/oidc/device/anti-bot/challenge", e.enterpriseResolve = "/auth/enterprise/resolve", e.enterpriseStart = "/auth/enterprise/start", e;
678
+ return e.signin = "/auth/login", e.signup = "/auth/register", e.pkceExchange = "/auth/pkce_exchange", e.redirectCheck = "/auth/redirect/check", e.signInWithProvider = "/auth/federated/start/", e.passwordless = "/auth/passwordless/start", e.passwordlessComplete = "/auth/passwordless/complete", e.passwordlessStatus = "/auth/passwordless/status", e.passwordlessApprovalInfo = "/auth/passwordless/approval/info", e.passwordlessApprovalDecide = "/auth/passwordless/approval/decide", e.logout = "/user/logout", e.refresh = "/auth/refresh", e.validateSession = "/user/me", e.sendPasswordResetEmail = "/auth/password/reset", e.resetPassword = "/auth/password/change", e.appSettings = "/app/settings", e.passkeyRegisterStart = "/auth/passkey/register/start", e.passkeyRegisterComplete = "/auth/passkey/register/complete", e.passkeyAuthenticateStart = "/auth/passkey/authenticate/start", e.passkeyAuthenticateComplete = "/auth/passkey/authenticate/complete", e.passkeyValidate = "/auth/validate", e.settingsAll = "/settings", e.settingsPasswordPolicy = "/settings/password", e.settingsPasskey = "/settings/passkey", e.userPasskey = "/user/passkey", e.addUserPasskey = "/user/passkey/add/start", e.completeAddUserPasskey = "/user/passkey/add/complete", e.userSessions = "/user/sessions", e.userSessionsRevokeOthers = "/user/sessions/revoke-others", e.joinInvitation = "/user/tenant/join", e.tenantPath = "/user/tenant", e.invitationsPath = "/user/tenant/:tenantID/invitations", e.requestInvitation = "/user/invite", e.invitationDelete = "/user/invite/:invitationID", e.invitationResend = "/user/invite/:invitationID/resend", e.invitationGetLink = "/user/invite/:invitationID/link", e.twoFactor = "/user/2fa", e.twoFactorStatus = "/user/2fa/status", e.twoFactorSetupBegin = "/user/2fa/setup/begin", e.twoFactorSetupConfirm = "/user/2fa/setup/confirm", e.twoFactorVerify = "/auth/2fa/verify", e.twoFactorRecovery = "/auth/2fa/recovery", e.twoFactorRegenerateCodes = "/user/2fa/recovery-codes/regenerate", e.twoFactorSetupMagicLink = "/auth/2fa-setup", e.twoFactorEnrollment = "/auth/2fa/enrollment", e.twoFactorEnrollmentEmailLink = "/auth/2fa/enrollment/email-link", e.twoFactorEnrollmentBegin = "/auth/2fa/setup/begin", e.twoFactorEnrollmentConfirm = "/auth/2fa/setup/confirm", e.TwoFactorMethodsAvailable = "/v2/user/2fa/methods/available", e.TwoFactorMethodsRegistered = "/v2/user/2fa/methods", e.TwoFactorSetupStart = "/v2/user/2fa/setup/start", e.TwoFactorSetupComplete = "/v2/user/2fa/setup/complete", e.TwoFactorMethodRemove = "/v2/user/2fa/methods/:id", e.TwoFactorChallenge = "/v2/auth/2fa/challenge", e.TwoFactorVerifyV2 = "/v2/auth/2fa/verify", e.TwoFactorAlternative = "/v2/auth/2fa/alternative", e.TwoFactorTrustedDevices = "/v2/user/2fa/trusted-devices", e.TwoFactorTrustedDeviceRevoke = "/v2/user/2fa/trusted-devices/:id", e.TwoFactorPreferredMethod = "/v2/user/2fa/preferred-method", e.cliAuthStatus = "/cli/auth/status/:sessionId", e.cliAuthComplete = "/cli/auth/complete", e.upgradeStart = "/auth/upgrade/start", e.hostedUpgradeStart = "/auth/session/upgrade/start", e.hostedUpgrade = "/auth/session/upgrade", e.antiBotChallenge = "/auth/anti-bot/challenge", e.deviceAntiBotChallenge = "/oidc/device/anti-bot/challenge", e.enterpriseResolve = "/auth/enterprise/resolve", e.enterpriseStart = "/auth/enterprise/start", e;
679
679
  }({}), ze = /* @__PURE__ */ function(e) {
680
680
  return e.passkeyRegisterStart = "/admin/auth/passkey/register/start", e.passkeyRegisterComplete = "/admin/auth/passkey/register/complete", e.passkeyAuthenticateStart = "/admin/auth/passkey/authenticate/start", e.passkeyAuthenticateComplete = "/admin/auth/passkey/authenticate/complete", e.passkeyValidate = "/admin/auth/validate", e.logout = "/admin/auth/logout", e;
681
681
  }({}), Be = (e) => {
@@ -1405,7 +1405,8 @@ var ut = /* @__PURE__ */ function(e) {
1405
1405
  sessionToken: t.session_token,
1406
1406
  userId: t.user_id,
1407
1407
  expiresIn: t.expires_in,
1408
- appId: t.app_id
1408
+ appId: t.app_id,
1409
+ reset: t.reset === !0
1409
1410
  };
1410
1411
  }).catch((e) => {
1411
1412
  if (e instanceof B) return {
@@ -1495,6 +1496,15 @@ var ut = /* @__PURE__ */ function(e) {
1495
1496
  let t = lt(z.TwoFactorTrustedDeviceRevoke, { id: e });
1496
1497
  return this.axiosClient.delete(t);
1497
1498
  }
1499
+ async getPreferredMethod() {
1500
+ return (await this.axiosClient.get(z.TwoFactorPreferredMethod))?.preferred_method ?? null;
1501
+ }
1502
+ async setPreferredMethod(e) {
1503
+ return (await this.axiosClient.put(z.TwoFactorPreferredMethod, { method: e }))?.preferred_method ?? null;
1504
+ }
1505
+ async clearPreferredMethod() {
1506
+ await this.axiosClient.delete(z.TwoFactorPreferredMethod);
1507
+ }
1498
1508
  }, Kt = class {
1499
1509
  constructor(e, t, n) {
1500
1510
  this.axiosClient = new Ot(e, t, n);
@@ -5789,13 +5799,15 @@ var sa = 10, ca = "The sign-in answered with a PKCE code, but its verifier is go
5789
5799
  userId: t.userId,
5790
5800
  appId: t.appId,
5791
5801
  scope: "2fa_setup",
5802
+ reset: t.reset === !0,
5792
5803
  timestamp: Date.now(),
5793
5804
  expiresAt: Date.now() + (t.expiresIn || 3600) * 1e3
5794
5805
  }, this.subscribeStore.notify(G.TwoFactorSetupMagicLinkValidated, {
5795
5806
  userId: t.userId,
5796
5807
  appId: t.appId,
5797
5808
  expiresIn: t.expiresIn || 3600,
5798
- sessionToken: t.sessionToken
5809
+ sessionToken: t.sessionToken,
5810
+ reset: t.reset === !0
5799
5811
  })) : t.error && this.subscribeStore.notify(G.TwoFactorSetupMagicLinkFailed, { error: t.error }), t;
5800
5812
  }
5801
5813
  getMagicLinkSession() {
@@ -5905,6 +5917,27 @@ var sa = 10, ca = "The sign-in answered with a PKCE code, but its verifier is go
5905
5917
  this.emitErrorAndThrow(e, "2fa.trusted-devices.revoke", "Revoke trusted device");
5906
5918
  }
5907
5919
  }
5920
+ async getPreferredMethod() {
5921
+ try {
5922
+ return await this.twoFactorApi.getPreferredMethod();
5923
+ } catch (e) {
5924
+ this.emitErrorAndThrow(e, "2fa.preferred-method.read", "Get preferred 2FA method");
5925
+ }
5926
+ }
5927
+ async setPreferredMethod(e) {
5928
+ try {
5929
+ return await this.twoFactorApi.setPreferredMethod(e);
5930
+ } catch (e) {
5931
+ this.emitErrorAndThrow(e, "2fa.preferred-method.set", "Set preferred 2FA method");
5932
+ }
5933
+ }
5934
+ async clearPreferredMethod() {
5935
+ try {
5936
+ await this.twoFactorApi.clearPreferredMethod();
5937
+ } catch (e) {
5938
+ this.emitErrorAndThrow(e, "2fa.preferred-method.clear", "Clear preferred 2FA method");
5939
+ }
5940
+ }
5908
5941
  }, va = class {
5909
5942
  constructor(e, t, n = R) {
5910
5943
  this.userAPI = e, this.deviceService = t, this.platform = n;
@@ -7841,6 +7874,27 @@ var sa = 10, ca = "The sign-in answered with a PKCE code, but its verifier is go
7841
7874
  this.handleError(e, "2fa.trusted-devices.revoke", "Revoke trusted device");
7842
7875
  }
7843
7876
  }
7877
+ async getPreferredTwoFactorMethod() {
7878
+ try {
7879
+ return await this.twoFactorService.getPreferredMethod();
7880
+ } catch (e) {
7881
+ this.handleError(e, "2fa.preferred-method.read", "Get preferred 2FA method");
7882
+ }
7883
+ }
7884
+ async setPreferredTwoFactorMethod(e) {
7885
+ try {
7886
+ return await this.twoFactorService.setPreferredMethod(e);
7887
+ } catch (e) {
7888
+ this.handleError(e, "2fa.preferred-method.set", "Set preferred 2FA method");
7889
+ }
7890
+ }
7891
+ async clearPreferredTwoFactorMethod() {
7892
+ try {
7893
+ await this.twoFactorService.clearPreferredMethod();
7894
+ } catch (e) {
7895
+ this.handleError(e, "2fa.preferred-method.clear", "Clear preferred 2FA method");
7896
+ }
7897
+ }
7844
7898
  isTwoFactorVerificationRequired() {
7845
7899
  return this.twoFactorService.isVerificationRequired();
7846
7900
  }