@passflow/core 0.43.1 → 0.45.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
@@ -1412,6 +1412,8 @@ export declare const PASSWORD_CHANGE_REQUIRED_ERROR_ID = "error.api.password.cha
1412
1412
  export declare const ANTI_BOT_REQUIRED_ERROR_ID = "error.api.anti_bot.required";
1413
1413
  /** The anti-bot value was wrong, expired or used before (403). The built-in check is resent once. */
1414
1414
  export declare const ANTI_BOT_FAILED_ERROR_ID = "error.api.anti_bot.failed";
1415
+ /** Attack protection refused the sign-in before the credential was checked (403). Not resent. */
1416
+ export declare const SIGN_IN_REFUSED_ERROR_ID = "error.api.sign_in.refused";
1415
1417
  /** The server could not check the anti-bot value right now (503, `Retry-After`). */
1416
1418
  export declare const ANTI_BOT_UNAVAILABLE_ERROR_ID = "error.api.anti_bot.unavailable";
1417
1419
  /** A `human_only` app uses its own provider and `setAntiBotTokenProvider()` was not called. */
@@ -1489,6 +1491,20 @@ export declare class PassflowRecoveryCodesStepUpRequiredError extends PassflowEr
1489
1491
  cause?: unknown;
1490
1492
  });
1491
1493
  }
1494
+ /**
1495
+ * A 403 `error.api.anti_bot.required` or `error.api.anti_bot.failed` that names the check to pass:
1496
+ * the server's attack protection asked for it, also on a `bot_friendly` app. The SDK resends a
1497
+ * covered call once with a value for that check; this error is what a second refusal, or a request
1498
+ * the SDK does not send itself, rejects with. To answer it yourself, pass `antiBot` to
1499
+ * `antiBotToken({ operation, settings: { bot_mode: 'human_only', anti_bot: antiBot } })`.
1500
+ */
1501
+ export declare class PassflowAntiBotChallengeError extends PassflowError {
1502
+ /** The check the server asks for: its provider and, for the customer's own provider, the site key. */
1503
+ readonly antiBot: AntiBotSettings;
1504
+ constructor(error: PassflowResponseError['error'], antiBot: AntiBotSettings, options?: {
1505
+ cause?: unknown;
1506
+ });
1507
+ }
1492
1508
  /** A change of email or phone number needs a proof the save did not carry (403). */
1493
1509
  export declare class PassflowAddressChangeProofRequiredError extends PassflowError {
1494
1510
  constructor(error: PassflowResponseError['error'], options?: {
@@ -1745,6 +1761,21 @@ export type AppSettings = {
1745
1761
  bot_mode?: BotMode;
1746
1762
  /** Only when `human_only`. Absent on a `human_only` app means the built-in check. */
1747
1763
  anti_bot?: AntiBotSettings;
1764
+ /** The public values of the browser risk providers the app has on; absent when none is on. */
1765
+ attack_protection?: AttackProtectionSettings;
1766
+ };
1767
+ /**
1768
+ * The browser risk providers whose ids `POST /auth/login` and `POST /auth/register` carry. Each key
1769
+ * is present only when that provider is on; `region` may be empty.
1770
+ */
1771
+ export type AttackProtectionSettings = {
1772
+ fingerprint?: {
1773
+ public_key: string;
1774
+ region: string;
1775
+ };
1776
+ stytch?: {
1777
+ public_token: string;
1778
+ };
1748
1779
  };
1749
1780
  /** `human_only`: every sign-in start must carry an anti-bot value in `X-Passflow-Anti-Bot`. */
1750
1781
  export type BotMode = 'bot_friendly' | 'human_only';
@@ -2603,6 +2634,13 @@ type AntiBotOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passkey.
2603
2634
  type AntiBotTokenContext = {
2604
2635
  action: 'passflow_auth';
2605
2636
  operation: AntiBotOperation;
2637
+ /**
2638
+ * The provider whose widget to run: the app's own provider, or the one a 403 from the server's
2639
+ * attack protection names. Set on every call the SDK makes.
2640
+ */
2641
+ provider?: Exclude<AntiBotProviderName, 'builtin'>;
2642
+ /** The provider's public site key, when the app settings or the server's 403 give one. */
2643
+ siteKey?: string;
2606
2644
  };
2607
2645
  /**
2608
2646
  * The customer's own anti-bot provider (Turnstile, hCaptcha, reCAPTCHA): resolves with a token
@@ -2889,15 +2927,23 @@ type AntiBotHeader = {
2889
2927
  };
2890
2928
  /**
2891
2929
  * Axios copies this object into each request's config (and each resend's), so the interceptors
2892
- * may write `builtin` and `retried` on it.
2930
+ * may write `builtin`, `retried` and `settings` on it.
2893
2931
  */
2894
2932
  type AntiBotMark = {
2895
2933
  operation: AntiBotOperation;
2896
2934
  identifier?: string;
2897
2935
  /** Set by the request interceptor: the value came from the built-in check. */
2898
2936
  builtin?: boolean;
2899
- /** Set by the response interceptor before the one resend after `anti_bot.failed`. */
2937
+ /**
2938
+ * Set by the response interceptor before the one resend: after `anti_bot.failed` for the built-in
2939
+ * check, or after a 403 that names the check to pass. A request is never sent a third time.
2940
+ */
2900
2941
  retried?: boolean;
2942
+ /**
2943
+ * Set by the response interceptor from a 403's `anti_bot`: the check the server asks for on this
2944
+ * request. The resend's value is produced for it, whatever the app's own bot mode.
2945
+ */
2946
+ settings?: AntiBotAppSettings;
2901
2947
  };
2902
2948
  /**
2903
2949
  * Handles a challenge the Passflow instance itself received, resolving with a
@@ -2930,6 +2976,12 @@ type AxiosRefreshHandler = (request: {
2930
2976
  * without the header, as it always has.
2931
2977
  */
2932
2978
  type AxiosAntiBotHandler = (mark: AntiBotMark) => Promise<AntiBotHeader | undefined>;
2979
+ /**
2980
+ * Produces the provider-id headers of a covered request (`X-Passflow-Fingerprint-Event`,
2981
+ * `X-Passflow-Stytch-Telemetry`). Installed by `Passflow` on its auth client. Resolves `{}` for
2982
+ * any request whose answer the risk providers do not judge.
2983
+ */
2984
+ type AxiosRiskIdHandler = (operation: AntiBotOperation) => Promise<Record<string, string>>;
2933
2985
  declare class AxiosClient {
2934
2986
  private instance;
2935
2987
  protected storageManager: StorageManager;
@@ -2958,6 +3010,8 @@ declare class AxiosClient {
2958
3010
  private refreshHandler?;
2959
3011
  /** Set by `Passflow` on its auth client. Absent elsewhere: no request is marked there. */
2960
3012
  private antiBotHandler?;
3013
+ /** Set by `Passflow` on its auth client. Absent elsewhere: no request is marked there. */
3014
+ private riskIdHandler?;
2961
3015
  /**
2962
3016
  * Passflow's own API as an interception scope, resolved ONCE here from
2963
3017
  * `PassflowConfig.url` so no wrapper or adapter ever derives it. `null` when
@@ -2997,6 +3051,11 @@ declare class AxiosClient {
2997
3051
  * every other request is unchanged.
2998
3052
  */
2999
3053
  setAntiBotHandler(handler: AxiosAntiBotHandler | undefined): void;
3054
+ /**
3055
+ * Installs (or clears) the provider-id handler. Only requests marked with `withAntiBot` consult
3056
+ * it; every other request is unchanged.
3057
+ */
3058
+ setRiskIdHandler(handler: AxiosRiskIdHandler | undefined): void;
3000
3059
  /**
3001
3060
  * Re-issues a request after an elevation. Exposed for the upgrade handler,
3002
3061
  * which owns the replay-once decision; the marker preventing a second
@@ -3054,6 +3113,8 @@ export declare class AuthAPI {
3054
3113
  setAppId(appId: string): void;
3055
3114
  /** Installs (or clears) the handler that produces the anti-bot value of covered calls. */
3056
3115
  setAntiBotHandler(handler: AxiosAntiBotHandler | undefined): void;
3116
+ /** Installs (or clears) the handler that produces the provider-id headers of covered calls. */
3117
+ setRiskIdHandler(handler: AxiosRiskIdHandler | undefined): void;
3057
3118
  /**
3058
3119
  * A built-in anti-bot challenge for this app. `identifier` is used by the server for difficulty
3059
3120
  * only. Rejects only with a `PassflowError`.
@@ -3727,6 +3788,25 @@ export declare class UserAPI {
3727
3788
  */
3728
3789
  updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
3729
3790
  }
3791
+ /** The requests whose answer the server's risk providers judge. */
3792
+ type RiskIdOperation = 'sign-in' | 'sign-up';
3793
+ /** What a risk id function is asked for: one provider that is on, with its public values. */
3794
+ type RiskIdContext = {
3795
+ provider: 'fingerprint';
3796
+ publicKey: string;
3797
+ region: string;
3798
+ operation: RiskIdOperation;
3799
+ } | {
3800
+ provider: 'stytch';
3801
+ publicToken: string;
3802
+ operation: RiskIdOperation;
3803
+ };
3804
+ /**
3805
+ * Resolves with the provider's id for this request: the Fingerprint agent's `event_id`, or the
3806
+ * Stytch telemetry id. Called once per provider per request; a resend calls it again. The request
3807
+ * waits for it, so it should resolve quickly.
3808
+ */
3809
+ type RiskIdProvider = (context: RiskIdContext) => Promise<string>;
3730
3810
  export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
3731
3811
  export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
3732
3812
  export declare const DEVICE_ID_HEADER_KEY = "X-Passflow-DeviceId";
@@ -3737,6 +3817,10 @@ export declare const ANTI_BOT_HEADER_KEY = "X-Passflow-Anti-Bot";
3737
3817
  export declare const AGENT_TOOL_HEADER_KEY = "X-Passflow-Agent-Tool";
3738
3818
  /** A device-key proof (compact JWS) on sign-in and refresh requests, with `PassflowConfig.deviceKey`. */
3739
3819
  export declare const DEVICE_PROOF_HEADER_KEY = "X-Passflow-Device-Proof";
3820
+ /** The Fingerprint agent's `event_id` on `signIn` and `signUp`, when the app has Fingerprint on. */
3821
+ export declare const FINGERPRINT_EVENT_HEADER_KEY = "X-Passflow-Fingerprint-Event";
3822
+ /** The Stytch telemetry id on `signIn` and `signUp`, when the app has Stytch on. */
3823
+ export declare const STYTCH_TELEMETRY_HEADER_KEY = "X-Passflow-Stytch-Telemetry";
3740
3824
  /** The `action` a token provider receives; a reCAPTCHA score key must be executed with it. */
3741
3825
  export declare const ANTI_BOT_ACTION = "passflow_auth";
3742
3826
  /**
@@ -5047,6 +5131,18 @@ export declare class AuthService {
5047
5131
  * after app-id discovery, and a code this tab did not ask for is not exchanged
5048
5132
  */
5049
5133
  handleFederatedCode(code: string): boolean;
5134
+ /**
5135
+ * A `#tfa_token` landing of a federated sign-in: the token goes to the second factor through
5136
+ * `TwoFactorRequired`. A live slot (a PKCE sign-in this tab started) becomes the pending PKCE
5137
+ * sign-in, because the server issued the 2FA token with that sign-in's challenge: the code the
5138
+ * second factor answers with is exchanged with the slot's verifier. The slot is taken. With no
5139
+ * live slot any earlier pending verifier is dropped, since the second factor then answers with
5140
+ * tokens.
5141
+ *
5142
+ * Unlike `handleFederatedCode`, this needs no appId: nothing is exchanged here, and the pending
5143
+ * verifier is kept in sessionStorage for the instance built after app-id discovery.
5144
+ */
5145
+ handleFederatedTwoFactor(tfaToken: string): void;
5050
5146
  private finishFederatedLanding;
5051
5147
  private reportFederatedRedirectFailure;
5052
5148
  authRedirectUrl(options?: {
@@ -5218,8 +5314,19 @@ export declare class TenantUserMembership {
5218
5314
  export declare class TenantService {
5219
5315
  private tenantApi;
5220
5316
  private scopes;
5317
+ private readStoredAccessToken?;
5221
5318
  private logger;
5222
- constructor(tenantApi: TenantAPI, scopes: string[], logger?: Logger);
5319
+ private tenantScopeWarned;
5320
+ /**
5321
+ * @param readStoredAccessToken Returns the stored access token. Without it the service never
5322
+ * warns about a token that lacks tenant membership.
5323
+ */
5324
+ constructor(tenantApi: TenantAPI, scopes: string[], logger?: Logger, readStoredAccessToken?: (() => string | undefined) | undefined);
5325
+ /**
5326
+ * Warns once when the stored access token has no `passflow_tm` claim, which means the sign-in
5327
+ * did not ask for the tenant scope. Never throws: a missing or unparseable token is ignored.
5328
+ */
5329
+ private warnIfNoTenantMembership;
5223
5330
  /**
5224
5331
  * Handle Passflow API errors
5225
5332
  * @param error The error object
@@ -6608,6 +6715,7 @@ export declare class Passflow {
6608
6715
  private tokenCacheService;
6609
6716
  private twoFactorService;
6610
6717
  private antiBot;
6718
+ private riskIds;
6611
6719
  /** This instance's device key: present with `deviceKey: true` outside BFF mode. */
6612
6720
  private readonly deviceKeyService;
6613
6721
  tenant: TenantService;
@@ -6888,7 +6996,9 @@ export declare class Passflow {
6888
6996
  /**
6889
6997
  * Adopts a `#tfa_token=` fragment: the 2FA token goes to the TwoFactorService
6890
6998
  * through `TwoFactorRequired`, exactly as a password sign-in's does, and the
6891
- * token and `user_state` leave the URL. Nothing is saved as a session.
6999
+ * token and `user_state` leave the URL. Nothing is saved as a session. After a
7000
+ * PKCE federated sign-in this tab started, its verifier becomes the pending PKCE
7001
+ * sign-in, so the code the second factor answers with is exchanged.
6892
7002
  *
6893
7003
  * @returns true when the URL carried a 2FA token
6894
7004
  */
@@ -7174,16 +7284,41 @@ export declare class Passflow {
7174
7284
  /**
7175
7285
  * Sets the token provider for an app in `human_only` bot mode that uses its own anti-bot
7176
7286
  * provider (Turnstile, hCaptcha, reCAPTCHA). Before each covered sign-in request the SDK calls it
7177
- * with `{ action: 'passflow_auth', operation }` and sends the token it resolves with in
7178
- * `X-Passflow-Anti-Bot`. Not called on a `bot_friendly` app, nor with the built-in check.
7179
- * `undefined` removes it.
7287
+ * with `{ action: 'passflow_auth', operation, provider, siteKey }` and sends the token it resolves
7288
+ * with in `X-Passflow-Anti-Bot`. Not called on a `bot_friendly` app, nor with the built-in check.
7289
+ *
7290
+ * It is also called on any app when the server's attack protection answers a covered call with
7291
+ * a 403 that names one of these providers: `provider` and `siteKey` then come from that answer,
7292
+ * so the widget to render may differ from the app's own. The call is sent again once with the
7293
+ * token. `undefined` removes it.
7180
7294
  *
7181
7295
  * @example
7182
7296
  * ```typescript
7183
- * passflow.setAntiBotTokenProvider(() => getTurnstileToken());
7297
+ * passflow.setAntiBotTokenProvider(({ provider, siteKey }) => renderWidget(provider, siteKey));
7184
7298
  * ```
7185
7299
  */
7186
7300
  setAntiBotTokenProvider(provider: AntiBotTokenProvider | undefined): void;
7301
+ /**
7302
+ * Sets the function that gives the id of each browser risk provider the app has on
7303
+ * (`attack_protection` in the app settings): the Fingerprint agent's `event_id`, the Stytch
7304
+ * telemetry id. Before each `signIn` and `signUp` request (a resend included) the SDK calls it
7305
+ * once per provider with that provider's public values, and sends the id in
7306
+ * `X-Passflow-Fingerprint-Event` or `X-Passflow-Stytch-Telemetry`. The request waits for it.
7307
+ *
7308
+ * A rejection or `''` sends no header for that provider and the sign-in goes on; so does an app
7309
+ * with a provider on and no function set (a warning is logged). The SDK loads no vendor script.
7310
+ * `undefined` removes it.
7311
+ *
7312
+ * @example
7313
+ * ```typescript
7314
+ * passflow.setRiskIdProvider(async (context) =>
7315
+ * context.provider === 'fingerprint'
7316
+ * ? (await fingerprintAgent.get()).event_id
7317
+ * : stytch.getTelemetryId({ publicToken: context.publicToken }),
7318
+ * );
7319
+ * ```
7320
+ */
7321
+ setRiskIdProvider(provider: RiskIdProvider | undefined): void;
7187
7322
  /**
7188
7323
  * A fresh `X-Passflow-Anti-Bot` value for a request the SDK does not send itself:
7189
7324
  * `POST /auth/session/exchange`, `/oidc/device/authenticate`, `/oidc/device/passkey/start`.
@@ -8405,4 +8540,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
8405
8540
  * @returns true if valid username format, false otherwise
8406
8541
  */
8407
8542
  export declare function isValidUsername(username: string): boolean;
8408
- export type { AntiBotAppSettings, AntiBotDeviceContext, AntiBotOperation, AntiBotTokenContext, AntiBotTokenProvider, AntiBotTokenRequest, AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, DeviceProofUse, DevicePushProofUse, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };
8543
+ export type { AntiBotAppSettings, AntiBotDeviceContext, AntiBotOperation, AntiBotTokenContext, AntiBotTokenProvider, AntiBotTokenRequest, AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, DeviceProofUse, DevicePushProofUse, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, RiskIdContext, RiskIdOperation, RiskIdProvider, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };
package/dist/index.d.ts CHANGED
@@ -1412,6 +1412,8 @@ export declare const PASSWORD_CHANGE_REQUIRED_ERROR_ID = "error.api.password.cha
1412
1412
  export declare const ANTI_BOT_REQUIRED_ERROR_ID = "error.api.anti_bot.required";
1413
1413
  /** The anti-bot value was wrong, expired or used before (403). The built-in check is resent once. */
1414
1414
  export declare const ANTI_BOT_FAILED_ERROR_ID = "error.api.anti_bot.failed";
1415
+ /** Attack protection refused the sign-in before the credential was checked (403). Not resent. */
1416
+ export declare const SIGN_IN_REFUSED_ERROR_ID = "error.api.sign_in.refused";
1415
1417
  /** The server could not check the anti-bot value right now (503, `Retry-After`). */
1416
1418
  export declare const ANTI_BOT_UNAVAILABLE_ERROR_ID = "error.api.anti_bot.unavailable";
1417
1419
  /** A `human_only` app uses its own provider and `setAntiBotTokenProvider()` was not called. */
@@ -1489,6 +1491,20 @@ export declare class PassflowRecoveryCodesStepUpRequiredError extends PassflowEr
1489
1491
  cause?: unknown;
1490
1492
  });
1491
1493
  }
1494
+ /**
1495
+ * A 403 `error.api.anti_bot.required` or `error.api.anti_bot.failed` that names the check to pass:
1496
+ * the server's attack protection asked for it, also on a `bot_friendly` app. The SDK resends a
1497
+ * covered call once with a value for that check; this error is what a second refusal, or a request
1498
+ * the SDK does not send itself, rejects with. To answer it yourself, pass `antiBot` to
1499
+ * `antiBotToken({ operation, settings: { bot_mode: 'human_only', anti_bot: antiBot } })`.
1500
+ */
1501
+ export declare class PassflowAntiBotChallengeError extends PassflowError {
1502
+ /** The check the server asks for: its provider and, for the customer's own provider, the site key. */
1503
+ readonly antiBot: AntiBotSettings;
1504
+ constructor(error: PassflowResponseError['error'], antiBot: AntiBotSettings, options?: {
1505
+ cause?: unknown;
1506
+ });
1507
+ }
1492
1508
  /** A change of email or phone number needs a proof the save did not carry (403). */
1493
1509
  export declare class PassflowAddressChangeProofRequiredError extends PassflowError {
1494
1510
  constructor(error: PassflowResponseError['error'], options?: {
@@ -1745,6 +1761,21 @@ export type AppSettings = {
1745
1761
  bot_mode?: BotMode;
1746
1762
  /** Only when `human_only`. Absent on a `human_only` app means the built-in check. */
1747
1763
  anti_bot?: AntiBotSettings;
1764
+ /** The public values of the browser risk providers the app has on; absent when none is on. */
1765
+ attack_protection?: AttackProtectionSettings;
1766
+ };
1767
+ /**
1768
+ * The browser risk providers whose ids `POST /auth/login` and `POST /auth/register` carry. Each key
1769
+ * is present only when that provider is on; `region` may be empty.
1770
+ */
1771
+ export type AttackProtectionSettings = {
1772
+ fingerprint?: {
1773
+ public_key: string;
1774
+ region: string;
1775
+ };
1776
+ stytch?: {
1777
+ public_token: string;
1778
+ };
1748
1779
  };
1749
1780
  /** `human_only`: every sign-in start must carry an anti-bot value in `X-Passflow-Anti-Bot`. */
1750
1781
  export type BotMode = 'bot_friendly' | 'human_only';
@@ -2603,6 +2634,13 @@ type AntiBotOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passkey.
2603
2634
  type AntiBotTokenContext = {
2604
2635
  action: 'passflow_auth';
2605
2636
  operation: AntiBotOperation;
2637
+ /**
2638
+ * The provider whose widget to run: the app's own provider, or the one a 403 from the server's
2639
+ * attack protection names. Set on every call the SDK makes.
2640
+ */
2641
+ provider?: Exclude<AntiBotProviderName, 'builtin'>;
2642
+ /** The provider's public site key, when the app settings or the server's 403 give one. */
2643
+ siteKey?: string;
2606
2644
  };
2607
2645
  /**
2608
2646
  * The customer's own anti-bot provider (Turnstile, hCaptcha, reCAPTCHA): resolves with a token
@@ -2889,15 +2927,23 @@ type AntiBotHeader = {
2889
2927
  };
2890
2928
  /**
2891
2929
  * Axios copies this object into each request's config (and each resend's), so the interceptors
2892
- * may write `builtin` and `retried` on it.
2930
+ * may write `builtin`, `retried` and `settings` on it.
2893
2931
  */
2894
2932
  type AntiBotMark = {
2895
2933
  operation: AntiBotOperation;
2896
2934
  identifier?: string;
2897
2935
  /** Set by the request interceptor: the value came from the built-in check. */
2898
2936
  builtin?: boolean;
2899
- /** Set by the response interceptor before the one resend after `anti_bot.failed`. */
2937
+ /**
2938
+ * Set by the response interceptor before the one resend: after `anti_bot.failed` for the built-in
2939
+ * check, or after a 403 that names the check to pass. A request is never sent a third time.
2940
+ */
2900
2941
  retried?: boolean;
2942
+ /**
2943
+ * Set by the response interceptor from a 403's `anti_bot`: the check the server asks for on this
2944
+ * request. The resend's value is produced for it, whatever the app's own bot mode.
2945
+ */
2946
+ settings?: AntiBotAppSettings;
2901
2947
  };
2902
2948
  /**
2903
2949
  * Handles a challenge the Passflow instance itself received, resolving with a
@@ -2930,6 +2976,12 @@ type AxiosRefreshHandler = (request: {
2930
2976
  * without the header, as it always has.
2931
2977
  */
2932
2978
  type AxiosAntiBotHandler = (mark: AntiBotMark) => Promise<AntiBotHeader | undefined>;
2979
+ /**
2980
+ * Produces the provider-id headers of a covered request (`X-Passflow-Fingerprint-Event`,
2981
+ * `X-Passflow-Stytch-Telemetry`). Installed by `Passflow` on its auth client. Resolves `{}` for
2982
+ * any request whose answer the risk providers do not judge.
2983
+ */
2984
+ type AxiosRiskIdHandler = (operation: AntiBotOperation) => Promise<Record<string, string>>;
2933
2985
  declare class AxiosClient {
2934
2986
  private instance;
2935
2987
  protected storageManager: StorageManager;
@@ -2958,6 +3010,8 @@ declare class AxiosClient {
2958
3010
  private refreshHandler?;
2959
3011
  /** Set by `Passflow` on its auth client. Absent elsewhere: no request is marked there. */
2960
3012
  private antiBotHandler?;
3013
+ /** Set by `Passflow` on its auth client. Absent elsewhere: no request is marked there. */
3014
+ private riskIdHandler?;
2961
3015
  /**
2962
3016
  * Passflow's own API as an interception scope, resolved ONCE here from
2963
3017
  * `PassflowConfig.url` so no wrapper or adapter ever derives it. `null` when
@@ -2997,6 +3051,11 @@ declare class AxiosClient {
2997
3051
  * every other request is unchanged.
2998
3052
  */
2999
3053
  setAntiBotHandler(handler: AxiosAntiBotHandler | undefined): void;
3054
+ /**
3055
+ * Installs (or clears) the provider-id handler. Only requests marked with `withAntiBot` consult
3056
+ * it; every other request is unchanged.
3057
+ */
3058
+ setRiskIdHandler(handler: AxiosRiskIdHandler | undefined): void;
3000
3059
  /**
3001
3060
  * Re-issues a request after an elevation. Exposed for the upgrade handler,
3002
3061
  * which owns the replay-once decision; the marker preventing a second
@@ -3054,6 +3113,8 @@ export declare class AuthAPI {
3054
3113
  setAppId(appId: string): void;
3055
3114
  /** Installs (or clears) the handler that produces the anti-bot value of covered calls. */
3056
3115
  setAntiBotHandler(handler: AxiosAntiBotHandler | undefined): void;
3116
+ /** Installs (or clears) the handler that produces the provider-id headers of covered calls. */
3117
+ setRiskIdHandler(handler: AxiosRiskIdHandler | undefined): void;
3057
3118
  /**
3058
3119
  * A built-in anti-bot challenge for this app. `identifier` is used by the server for difficulty
3059
3120
  * only. Rejects only with a `PassflowError`.
@@ -3727,6 +3788,25 @@ export declare class UserAPI {
3727
3788
  */
3728
3789
  updateProfile(patch: PassflowProfileUpdate, proof?: AddressChangeProof): Promise<PassflowSessionUser>;
3729
3790
  }
3791
+ /** The requests whose answer the server's risk providers judge. */
3792
+ type RiskIdOperation = 'sign-in' | 'sign-up';
3793
+ /** What a risk id function is asked for: one provider that is on, with its public values. */
3794
+ type RiskIdContext = {
3795
+ provider: 'fingerprint';
3796
+ publicKey: string;
3797
+ region: string;
3798
+ operation: RiskIdOperation;
3799
+ } | {
3800
+ provider: 'stytch';
3801
+ publicToken: string;
3802
+ operation: RiskIdOperation;
3803
+ };
3804
+ /**
3805
+ * Resolves with the provider's id for this request: the Fingerprint agent's `event_id`, or the
3806
+ * Stytch telemetry id. Called once per provider per request; a resend calls it again. The request
3807
+ * waits for it, so it should resolve quickly.
3808
+ */
3809
+ type RiskIdProvider = (context: RiskIdContext) => Promise<string>;
3730
3810
  export declare const APP_ID_HEADER_KEY = "X-Passflow-Clientid";
3731
3811
  export declare const AUTHORIZATION_HEADER_KEY = "Authorization";
3732
3812
  export declare const DEVICE_ID_HEADER_KEY = "X-Passflow-DeviceId";
@@ -3737,6 +3817,10 @@ export declare const ANTI_BOT_HEADER_KEY = "X-Passflow-Anti-Bot";
3737
3817
  export declare const AGENT_TOOL_HEADER_KEY = "X-Passflow-Agent-Tool";
3738
3818
  /** A device-key proof (compact JWS) on sign-in and refresh requests, with `PassflowConfig.deviceKey`. */
3739
3819
  export declare const DEVICE_PROOF_HEADER_KEY = "X-Passflow-Device-Proof";
3820
+ /** The Fingerprint agent's `event_id` on `signIn` and `signUp`, when the app has Fingerprint on. */
3821
+ export declare const FINGERPRINT_EVENT_HEADER_KEY = "X-Passflow-Fingerprint-Event";
3822
+ /** The Stytch telemetry id on `signIn` and `signUp`, when the app has Stytch on. */
3823
+ export declare const STYTCH_TELEMETRY_HEADER_KEY = "X-Passflow-Stytch-Telemetry";
3740
3824
  /** The `action` a token provider receives; a reCAPTCHA score key must be executed with it. */
3741
3825
  export declare const ANTI_BOT_ACTION = "passflow_auth";
3742
3826
  /**
@@ -5047,6 +5131,18 @@ export declare class AuthService {
5047
5131
  * after app-id discovery, and a code this tab did not ask for is not exchanged
5048
5132
  */
5049
5133
  handleFederatedCode(code: string): boolean;
5134
+ /**
5135
+ * A `#tfa_token` landing of a federated sign-in: the token goes to the second factor through
5136
+ * `TwoFactorRequired`. A live slot (a PKCE sign-in this tab started) becomes the pending PKCE
5137
+ * sign-in, because the server issued the 2FA token with that sign-in's challenge: the code the
5138
+ * second factor answers with is exchanged with the slot's verifier. The slot is taken. With no
5139
+ * live slot any earlier pending verifier is dropped, since the second factor then answers with
5140
+ * tokens.
5141
+ *
5142
+ * Unlike `handleFederatedCode`, this needs no appId: nothing is exchanged here, and the pending
5143
+ * verifier is kept in sessionStorage for the instance built after app-id discovery.
5144
+ */
5145
+ handleFederatedTwoFactor(tfaToken: string): void;
5050
5146
  private finishFederatedLanding;
5051
5147
  private reportFederatedRedirectFailure;
5052
5148
  authRedirectUrl(options?: {
@@ -5218,8 +5314,19 @@ export declare class TenantUserMembership {
5218
5314
  export declare class TenantService {
5219
5315
  private tenantApi;
5220
5316
  private scopes;
5317
+ private readStoredAccessToken?;
5221
5318
  private logger;
5222
- constructor(tenantApi: TenantAPI, scopes: string[], logger?: Logger);
5319
+ private tenantScopeWarned;
5320
+ /**
5321
+ * @param readStoredAccessToken Returns the stored access token. Without it the service never
5322
+ * warns about a token that lacks tenant membership.
5323
+ */
5324
+ constructor(tenantApi: TenantAPI, scopes: string[], logger?: Logger, readStoredAccessToken?: (() => string | undefined) | undefined);
5325
+ /**
5326
+ * Warns once when the stored access token has no `passflow_tm` claim, which means the sign-in
5327
+ * did not ask for the tenant scope. Never throws: a missing or unparseable token is ignored.
5328
+ */
5329
+ private warnIfNoTenantMembership;
5223
5330
  /**
5224
5331
  * Handle Passflow API errors
5225
5332
  * @param error The error object
@@ -6608,6 +6715,7 @@ export declare class Passflow {
6608
6715
  private tokenCacheService;
6609
6716
  private twoFactorService;
6610
6717
  private antiBot;
6718
+ private riskIds;
6611
6719
  /** This instance's device key: present with `deviceKey: true` outside BFF mode. */
6612
6720
  private readonly deviceKeyService;
6613
6721
  tenant: TenantService;
@@ -6888,7 +6996,9 @@ export declare class Passflow {
6888
6996
  /**
6889
6997
  * Adopts a `#tfa_token=` fragment: the 2FA token goes to the TwoFactorService
6890
6998
  * through `TwoFactorRequired`, exactly as a password sign-in's does, and the
6891
- * token and `user_state` leave the URL. Nothing is saved as a session.
6999
+ * token and `user_state` leave the URL. Nothing is saved as a session. After a
7000
+ * PKCE federated sign-in this tab started, its verifier becomes the pending PKCE
7001
+ * sign-in, so the code the second factor answers with is exchanged.
6892
7002
  *
6893
7003
  * @returns true when the URL carried a 2FA token
6894
7004
  */
@@ -7174,16 +7284,41 @@ export declare class Passflow {
7174
7284
  /**
7175
7285
  * Sets the token provider for an app in `human_only` bot mode that uses its own anti-bot
7176
7286
  * provider (Turnstile, hCaptcha, reCAPTCHA). Before each covered sign-in request the SDK calls it
7177
- * with `{ action: 'passflow_auth', operation }` and sends the token it resolves with in
7178
- * `X-Passflow-Anti-Bot`. Not called on a `bot_friendly` app, nor with the built-in check.
7179
- * `undefined` removes it.
7287
+ * with `{ action: 'passflow_auth', operation, provider, siteKey }` and sends the token it resolves
7288
+ * with in `X-Passflow-Anti-Bot`. Not called on a `bot_friendly` app, nor with the built-in check.
7289
+ *
7290
+ * It is also called on any app when the server's attack protection answers a covered call with
7291
+ * a 403 that names one of these providers: `provider` and `siteKey` then come from that answer,
7292
+ * so the widget to render may differ from the app's own. The call is sent again once with the
7293
+ * token. `undefined` removes it.
7180
7294
  *
7181
7295
  * @example
7182
7296
  * ```typescript
7183
- * passflow.setAntiBotTokenProvider(() => getTurnstileToken());
7297
+ * passflow.setAntiBotTokenProvider(({ provider, siteKey }) => renderWidget(provider, siteKey));
7184
7298
  * ```
7185
7299
  */
7186
7300
  setAntiBotTokenProvider(provider: AntiBotTokenProvider | undefined): void;
7301
+ /**
7302
+ * Sets the function that gives the id of each browser risk provider the app has on
7303
+ * (`attack_protection` in the app settings): the Fingerprint agent's `event_id`, the Stytch
7304
+ * telemetry id. Before each `signIn` and `signUp` request (a resend included) the SDK calls it
7305
+ * once per provider with that provider's public values, and sends the id in
7306
+ * `X-Passflow-Fingerprint-Event` or `X-Passflow-Stytch-Telemetry`. The request waits for it.
7307
+ *
7308
+ * A rejection or `''` sends no header for that provider and the sign-in goes on; so does an app
7309
+ * with a provider on and no function set (a warning is logged). The SDK loads no vendor script.
7310
+ * `undefined` removes it.
7311
+ *
7312
+ * @example
7313
+ * ```typescript
7314
+ * passflow.setRiskIdProvider(async (context) =>
7315
+ * context.provider === 'fingerprint'
7316
+ * ? (await fingerprintAgent.get()).event_id
7317
+ * : stytch.getTelemetryId({ publicToken: context.publicToken }),
7318
+ * );
7319
+ * ```
7320
+ */
7321
+ setRiskIdProvider(provider: RiskIdProvider | undefined): void;
7187
7322
  /**
7188
7323
  * A fresh `X-Passflow-Anti-Bot` value for a request the SDK does not send itself:
7189
7324
  * `POST /auth/session/exchange`, `/oidc/device/authenticate`, `/oidc/device/passkey/start`.
@@ -8405,4 +8540,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
8405
8540
  * @returns true if valid username format, false otherwise
8406
8541
  */
8407
8542
  export declare function isValidUsername(username: string): boolean;
8408
- export type { AntiBotAppSettings, AntiBotDeviceContext, AntiBotOperation, AntiBotTokenContext, AntiBotTokenProvider, AntiBotTokenRequest, AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, DeviceProofUse, DevicePushProofUse, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };
8543
+ export type { AntiBotAppSettings, AntiBotDeviceContext, AntiBotOperation, AntiBotTokenContext, AntiBotTokenProvider, AntiBotTokenRequest, AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, DeviceProofUse, DevicePushProofUse, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, RiskIdContext, RiskIdOperation, RiskIdProvider, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };