@passflow/core 0.21.1 → 0.22.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
@@ -1213,7 +1213,33 @@ export type PassflowAuthorizationResponse = Tokens & {
1213
1213
  token_delivery?: 'json_body' | 'cookie' | 'mobile';
1214
1214
  cookies?: string[];
1215
1215
  csrf_token?: string;
1216
+ /** `true` when the server needs the email proven before this sign-in finishes. No tokens come with it. */
1217
+ email_verification_required?: boolean;
1218
+ /** Human-readable text from the server, e.g. "We sent a code to a***@example.com." */
1219
+ message?: string;
1220
+ };
1221
+ /**
1222
+ * A sign-up, sign-in or password change that waits for the email to be proven.
1223
+ * With `challenge_id`: a code was emailed, finish with `Passflow.verifyEmailCode`.
1224
+ * Without: the code budget is spent and a link was emailed instead.
1225
+ * `message` is what the server sent; a malformed answer may leave it out.
1226
+ */
1227
+ export type PassflowEmailVerificationStep = {
1228
+ email_verification_required: true;
1229
+ message: string;
1230
+ challenge_id?: string;
1231
+ };
1232
+ /** The emailed code for a `PassflowEmailVerificationStep` that carried a `challenge_id`. */
1233
+ export type PassflowEmailCodePayload = {
1234
+ challenge_id: string;
1235
+ otp: string;
1216
1236
  };
1237
+ /**
1238
+ * Whether an auth answer is an email verification step rather than a session. Only the
1239
+ * `email_verification_required` flag is checked, so an answer with the flag is never taken
1240
+ * for a session.
1241
+ */
1242
+ export declare const isEmailVerificationStep: (response: unknown) => response is PassflowEmailVerificationStep;
1217
1243
  export type PassflowValidationResponse = Tokens & {
1218
1244
  redirect_url: string;
1219
1245
  requires_2fa?: boolean;
@@ -1990,6 +2016,13 @@ export declare class AuthAPI {
1990
2016
  pkceExchange(code: string, verifier: string): Promise<PassflowAuthorizationResponse>;
1991
2017
  passwordlessSignIn(payload: PassflowPasswordlessSignInPayload, deviceId: string, os: OS): Promise<PassflowPasswordlessResponse>;
1992
2018
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
2019
+ /**
2020
+ * Proves an emailed code for a sign-up, sign-in or password change that answered with
2021
+ * `email_verification_required`. Only `{challenge_id, otp}` is sent: the server reads the
2022
+ * device from the `X-Passflow-DeviceId` header. Sent with credentials, as every call that
2023
+ * ends a sign-in is.
2024
+ */
2025
+ validateEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
1993
2026
  logOut(deviceId?: string, refreshToken?: string, isAdmin?: boolean): Promise<PassflowLogoutResponse>;
1994
2027
  validateSession(): Promise<PassflowSessionValidationResponse>;
1995
2028
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload): Promise<PassflowSuccessResponse>;
@@ -3198,6 +3231,8 @@ export declare enum PassflowEvent {
3198
3231
  SignInStart = "signin:start",
3199
3232
  Register = "register",
3200
3233
  RegisterStart = "register:start",
3234
+ /** A sign-up, sign-in or password change is waiting for the email to be proven (no session yet). */
3235
+ EmailVerificationRequired = "email-verification:required",
3201
3236
  SignOut = "signout",
3202
3237
  SessionRestored = "session:restored",
3203
3238
  SessionExpired = "session:expired",
@@ -3227,7 +3262,7 @@ export declare enum PassflowEvent {
3227
3262
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3228
3263
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3229
3264
  */
3230
- type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'password-reset.send' | 'password-reset.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | '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';
3265
+ type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | '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';
3231
3266
  /**
3232
3267
  * Error payload interface for structured error information
3233
3268
  */
@@ -3247,6 +3282,8 @@ interface ErrorPayload {
3247
3282
  type OperationErrorPayload = ErrorPayload & {
3248
3283
  operation: PassflowOperation;
3249
3284
  };
3285
+ /** Which call produced an `EmailVerificationRequired` event. */
3286
+ type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password';
3250
3287
  /**
3251
3288
  * Event-specific payload types
3252
3289
  */
@@ -3268,6 +3305,13 @@ type PassflowEventPayload = {
3268
3305
  [PassflowEvent.RegisterStart]: {
3269
3306
  email?: string;
3270
3307
  };
3308
+ [PassflowEvent.EmailVerificationRequired]: {
3309
+ /** The address the code or link went to, when the SDK knows it. */
3310
+ email?: string;
3311
+ /** Present when a code was emailed; absent when a link was emailed instead. */
3312
+ challengeId?: string;
3313
+ operation: PassflowEmailVerificationOperation;
3314
+ };
3271
3315
  [PassflowEvent.SignOut]: {
3272
3316
  /** `sub` of the session that ended, when known. */
3273
3317
  userId?: string;
@@ -3492,6 +3536,11 @@ export declare class AuthService {
3492
3536
  private tokenDeliveryManager;
3493
3537
  private tokenExchangeConfig?;
3494
3538
  private pendingPkce?;
3539
+ /**
3540
+ * The emailed code challenges this instance produced, by `challenge_id`. Memory only: an id
3541
+ * this instance does not know (reload, another tab, a recreated instance) finishes as a sign-in.
3542
+ */
3543
+ private emailChallenges;
3495
3544
  /**
3496
3545
  * The one place this instance sends `/auth/refresh` (PFL-792). Every refresh path asks it: the
3497
3546
  * explicit `refreshToken()`, the upgrade commit, `getTokens(true)`/`session()` and, once
@@ -3544,6 +3593,17 @@ export declare class AuthService {
3544
3593
  * the verifier stays here for `completePkceSignIn`, off the public event.
3545
3594
  */
3546
3595
  private handlePendingSecondFactor;
3596
+ /**
3597
+ * Reports whether an answer is an email verification step, and when it is, prepares its completion.
3598
+ *
3599
+ * That answer is not a session: on `true` the caller returns it as it is, without
3600
+ * `processAuthResponse`, a `SignIn`/`Register` event, a session check or an error event. With a
3601
+ * code (`challenge_id`) on a PKCE app the verifier is kept for the code `/auth/validate` answers
3602
+ * with. A link step drops any verifier: that sign-in finishes on another page.
3603
+ */
3604
+ private handleEmailVerificationStep;
3605
+ /** Adds a challenge at the newest end, dropping the oldest past `MAX_EMAIL_CHALLENGES`. */
3606
+ private rememberEmailChallenge;
3547
3607
  /**
3548
3608
  * Keeps the verifier in memory, which is where it is read from first. The copy
3549
3609
  * in sessionStorage is only for a redirect or reload during the second factor,
@@ -3591,6 +3651,14 @@ export declare class AuthService {
3591
3651
  signUp(payload: PassflowSignUpPayload): Promise<PassflowAuthorizationResponse>;
3592
3652
  passwordlessSignIn(payload: PassflowPasswordlessSignInPayload): Promise<PassflowPasswordlessResponse>;
3593
3653
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
3654
+ /**
3655
+ * Finishes a sign-up, sign-in or password change that answered with an emailed code
3656
+ * (`email_verification_required` with a `challenge_id`): posts the code to `/auth/validate`, then
3657
+ * continues like `signIn`. Emits `Register` for a sign-up's challenge and `SignIn` otherwise
3658
+ * (an unknown id included), `TwoFactorRequired` when a second factor is owed, and one `Error`
3659
+ * on failure. Emits no Start event: the code step's `EmailVerificationRequired` ended that one.
3660
+ */
3661
+ verifyEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
3594
3662
  /**
3595
3663
  * Signs this tab out under the refresh lock (PFL-792 §2.8): stops this tab's refresh callers and
3596
3664
  * retry timer, waits at most 5 s for the lock (a request already in flight lands first), posts
@@ -3680,7 +3748,7 @@ export declare class AuthService {
3680
3748
  */
3681
3749
  refreshToken(upgrade?: UpgradeRefreshField, pin?: UpgradeSessionPin): Promise<PassflowAuthorizationResponse>;
3682
3750
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload): Promise<PassflowSuccessResponse>;
3683
- resetPassword(newPassword: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
3751
+ resetPassword(newPassword: string, scopes?: string[], token?: string): Promise<PassflowAuthorizationResponse>;
3684
3752
  passkeyRegister(payload: PassflowPasskeyRegisterStartPayload): Promise<PassflowAuthorizationResponse>;
3685
3753
  passkeyAuthenticate(payload: PassflowPasskeyAuthenticateStartPayload): Promise<PassflowAuthorizationResponse>;
3686
3754
  createFederatedAuthUrl(payload: PassflowFederatedAuthExtendedPayload): string;
@@ -5383,6 +5451,8 @@ export declare class Passflow {
5383
5451
  * @param payload.password - User's password
5384
5452
  * @param payload.scopes - Optional scopes to request (defaults to SDK scopes)
5385
5453
  * @returns Promise with authorization response containing tokens
5454
+ * May answer an email verification step instead of tokens: check it with
5455
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5386
5456
  * @throws {PassflowError} If authentication fails
5387
5457
  *
5388
5458
  * @example
@@ -5408,6 +5478,8 @@ export declare class Passflow {
5408
5478
  * @param payload.username - Optional username
5409
5479
  * @param payload.scopes - Optional scopes to request
5410
5480
  * @returns Promise with authorization response containing tokens
5481
+ * May answer an email verification step instead of tokens: check it with
5482
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5411
5483
  * @throws {PassflowError} If registration fails
5412
5484
  *
5413
5485
  * @example
@@ -5469,6 +5541,29 @@ export declare class Passflow {
5469
5541
  * ```
5470
5542
  */
5471
5543
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
5544
+ /**
5545
+ * Finishes a sign-up, sign-in or password change that answered with `email_verification_required`
5546
+ * and a `challenge_id`, using the code the user received by email. Answers like `signIn`: a new
5547
+ * token pair, or a `tfa_token` when a second factor is owed (`isTwoFactorVerificationRequired()`
5548
+ * is then true).
5549
+ *
5550
+ * Emits `Register` for a challenge this instance got from `signUp`, and `SignIn` otherwise. The
5551
+ * challenges are remembered in memory only, so a code typed in another tab or after the
5552
+ * `Passflow` instance was recreated emits `SignIn`, even for a sign-up.
5553
+ *
5554
+ * @param payload.challenge_id - The `challenge_id` from the email verification step
5555
+ * @param payload.otp - The code from the email
5556
+ * @throws {PassflowError} wrong, expired or spent code (`error.otp.*`), unknown challenge (`error.not.found`)
5557
+ *
5558
+ * @example
5559
+ * ```typescript
5560
+ * const step = await passflow.signUp({ user: { email, password } });
5561
+ * if (isEmailVerificationStep(step) && step.challenge_id) {
5562
+ * const response = await passflow.verifyEmailCode({ challenge_id: step.challenge_id, otp: '123456' });
5563
+ * }
5564
+ * ```
5565
+ */
5566
+ verifyEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
5472
5567
  /**
5473
5568
  * Centralized error handler for all public methods.
5474
5569
  * Creates proper ErrorPayload, distinguishes PassflowError from generic Error,
@@ -5627,7 +5722,12 @@ export declare class Passflow {
5627
5722
  *
5628
5723
  * @param newPassword - The new password to set
5629
5724
  * @param scopes - Optional scopes to request after reset
5725
+ * @param resetToken - The reset link's token. Without it the token is read from `?token=` in
5726
+ * `location.search`, then from a hash route's query (`#/reset?token=…`). Pass it when your
5727
+ * router keeps the link's query somewhere else (memory router).
5630
5728
  * @returns Promise with authorization response containing new tokens
5729
+ * May answer an email verification step instead of tokens: check it with
5730
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5631
5731
  * @throws {PassflowError} If reset fails
5632
5732
  *
5633
5733
  * @example
@@ -5641,7 +5741,7 @@ export declare class Passflow {
5641
5741
  * }
5642
5742
  * ```
5643
5743
  */
5644
- resetPassword(newPassword: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
5744
+ resetPassword(newPassword: string, scopes?: string[], resetToken?: string): Promise<PassflowAuthorizationResponse>;
5645
5745
  /**
5646
5746
  * Get application settings and configuration.
5647
5747
  *
@@ -6368,4 +6468,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
6368
6468
  * @returns true if valid username format, false otherwise
6369
6469
  */
6370
6470
  export declare function isValidUsername(username: string): boolean;
6371
- export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OpenAuthUrlOptions, OperationErrorPayload, 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 };
6471
+ export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, 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 };
package/dist/index.d.ts CHANGED
@@ -1213,7 +1213,33 @@ export type PassflowAuthorizationResponse = Tokens & {
1213
1213
  token_delivery?: 'json_body' | 'cookie' | 'mobile';
1214
1214
  cookies?: string[];
1215
1215
  csrf_token?: string;
1216
+ /** `true` when the server needs the email proven before this sign-in finishes. No tokens come with it. */
1217
+ email_verification_required?: boolean;
1218
+ /** Human-readable text from the server, e.g. "We sent a code to a***@example.com." */
1219
+ message?: string;
1220
+ };
1221
+ /**
1222
+ * A sign-up, sign-in or password change that waits for the email to be proven.
1223
+ * With `challenge_id`: a code was emailed, finish with `Passflow.verifyEmailCode`.
1224
+ * Without: the code budget is spent and a link was emailed instead.
1225
+ * `message` is what the server sent; a malformed answer may leave it out.
1226
+ */
1227
+ export type PassflowEmailVerificationStep = {
1228
+ email_verification_required: true;
1229
+ message: string;
1230
+ challenge_id?: string;
1231
+ };
1232
+ /** The emailed code for a `PassflowEmailVerificationStep` that carried a `challenge_id`. */
1233
+ export type PassflowEmailCodePayload = {
1234
+ challenge_id: string;
1235
+ otp: string;
1216
1236
  };
1237
+ /**
1238
+ * Whether an auth answer is an email verification step rather than a session. Only the
1239
+ * `email_verification_required` flag is checked, so an answer with the flag is never taken
1240
+ * for a session.
1241
+ */
1242
+ export declare const isEmailVerificationStep: (response: unknown) => response is PassflowEmailVerificationStep;
1217
1243
  export type PassflowValidationResponse = Tokens & {
1218
1244
  redirect_url: string;
1219
1245
  requires_2fa?: boolean;
@@ -1990,6 +2016,13 @@ export declare class AuthAPI {
1990
2016
  pkceExchange(code: string, verifier: string): Promise<PassflowAuthorizationResponse>;
1991
2017
  passwordlessSignIn(payload: PassflowPasswordlessSignInPayload, deviceId: string, os: OS): Promise<PassflowPasswordlessResponse>;
1992
2018
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
2019
+ /**
2020
+ * Proves an emailed code for a sign-up, sign-in or password change that answered with
2021
+ * `email_verification_required`. Only `{challenge_id, otp}` is sent: the server reads the
2022
+ * device from the `X-Passflow-DeviceId` header. Sent with credentials, as every call that
2023
+ * ends a sign-in is.
2024
+ */
2025
+ validateEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
1993
2026
  logOut(deviceId?: string, refreshToken?: string, isAdmin?: boolean): Promise<PassflowLogoutResponse>;
1994
2027
  validateSession(): Promise<PassflowSessionValidationResponse>;
1995
2028
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload): Promise<PassflowSuccessResponse>;
@@ -3198,6 +3231,8 @@ export declare enum PassflowEvent {
3198
3231
  SignInStart = "signin:start",
3199
3232
  Register = "register",
3200
3233
  RegisterStart = "register:start",
3234
+ /** A sign-up, sign-in or password change is waiting for the email to be proven (no session yet). */
3235
+ EmailVerificationRequired = "email-verification:required",
3201
3236
  SignOut = "signout",
3202
3237
  SessionRestored = "session:restored",
3203
3238
  SessionExpired = "session:expired",
@@ -3227,7 +3262,7 @@ export declare enum PassflowEvent {
3227
3262
  * The SDK operation that failed (`ErrorPayload.operation`). The SDK sets it on every `Error` it
3228
3263
  * emits, so a subscriber can tell a failed sign-in from a failed refresh without parsing messages.
3229
3264
  */
3230
- type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'password-reset.send' | 'password-reset.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | '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';
3265
+ type PassflowOperation = 'sign-in' | 'sign-up' | 'passwordless.start' | 'passwordless.complete' | 'password-reset.send' | 'password-reset.complete' | 'email-verification.complete' | 'passkey.register' | 'passkey.authenticate' | 'federated.popup' | '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';
3231
3266
  /**
3232
3267
  * Error payload interface for structured error information
3233
3268
  */
@@ -3247,6 +3282,8 @@ interface ErrorPayload {
3247
3282
  type OperationErrorPayload = ErrorPayload & {
3248
3283
  operation: PassflowOperation;
3249
3284
  };
3285
+ /** Which call produced an `EmailVerificationRequired` event. */
3286
+ type PassflowEmailVerificationOperation = 'sign-up' | 'sign-in' | 'reset-password';
3250
3287
  /**
3251
3288
  * Event-specific payload types
3252
3289
  */
@@ -3268,6 +3305,13 @@ type PassflowEventPayload = {
3268
3305
  [PassflowEvent.RegisterStart]: {
3269
3306
  email?: string;
3270
3307
  };
3308
+ [PassflowEvent.EmailVerificationRequired]: {
3309
+ /** The address the code or link went to, when the SDK knows it. */
3310
+ email?: string;
3311
+ /** Present when a code was emailed; absent when a link was emailed instead. */
3312
+ challengeId?: string;
3313
+ operation: PassflowEmailVerificationOperation;
3314
+ };
3271
3315
  [PassflowEvent.SignOut]: {
3272
3316
  /** `sub` of the session that ended, when known. */
3273
3317
  userId?: string;
@@ -3492,6 +3536,11 @@ export declare class AuthService {
3492
3536
  private tokenDeliveryManager;
3493
3537
  private tokenExchangeConfig?;
3494
3538
  private pendingPkce?;
3539
+ /**
3540
+ * The emailed code challenges this instance produced, by `challenge_id`. Memory only: an id
3541
+ * this instance does not know (reload, another tab, a recreated instance) finishes as a sign-in.
3542
+ */
3543
+ private emailChallenges;
3495
3544
  /**
3496
3545
  * The one place this instance sends `/auth/refresh` (PFL-792). Every refresh path asks it: the
3497
3546
  * explicit `refreshToken()`, the upgrade commit, `getTokens(true)`/`session()` and, once
@@ -3544,6 +3593,17 @@ export declare class AuthService {
3544
3593
  * the verifier stays here for `completePkceSignIn`, off the public event.
3545
3594
  */
3546
3595
  private handlePendingSecondFactor;
3596
+ /**
3597
+ * Reports whether an answer is an email verification step, and when it is, prepares its completion.
3598
+ *
3599
+ * That answer is not a session: on `true` the caller returns it as it is, without
3600
+ * `processAuthResponse`, a `SignIn`/`Register` event, a session check or an error event. With a
3601
+ * code (`challenge_id`) on a PKCE app the verifier is kept for the code `/auth/validate` answers
3602
+ * with. A link step drops any verifier: that sign-in finishes on another page.
3603
+ */
3604
+ private handleEmailVerificationStep;
3605
+ /** Adds a challenge at the newest end, dropping the oldest past `MAX_EMAIL_CHALLENGES`. */
3606
+ private rememberEmailChallenge;
3547
3607
  /**
3548
3608
  * Keeps the verifier in memory, which is where it is read from first. The copy
3549
3609
  * in sessionStorage is only for a redirect or reload during the second factor,
@@ -3591,6 +3651,14 @@ export declare class AuthService {
3591
3651
  signUp(payload: PassflowSignUpPayload): Promise<PassflowAuthorizationResponse>;
3592
3652
  passwordlessSignIn(payload: PassflowPasswordlessSignInPayload): Promise<PassflowPasswordlessResponse>;
3593
3653
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
3654
+ /**
3655
+ * Finishes a sign-up, sign-in or password change that answered with an emailed code
3656
+ * (`email_verification_required` with a `challenge_id`): posts the code to `/auth/validate`, then
3657
+ * continues like `signIn`. Emits `Register` for a sign-up's challenge and `SignIn` otherwise
3658
+ * (an unknown id included), `TwoFactorRequired` when a second factor is owed, and one `Error`
3659
+ * on failure. Emits no Start event: the code step's `EmailVerificationRequired` ended that one.
3660
+ */
3661
+ verifyEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
3594
3662
  /**
3595
3663
  * Signs this tab out under the refresh lock (PFL-792 §2.8): stops this tab's refresh callers and
3596
3664
  * retry timer, waits at most 5 s for the lock (a request already in flight lands first), posts
@@ -3680,7 +3748,7 @@ export declare class AuthService {
3680
3748
  */
3681
3749
  refreshToken(upgrade?: UpgradeRefreshField, pin?: UpgradeSessionPin): Promise<PassflowAuthorizationResponse>;
3682
3750
  sendPasswordResetEmail(payload: PassflowSendPasswordResetEmailPayload): Promise<PassflowSuccessResponse>;
3683
- resetPassword(newPassword: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
3751
+ resetPassword(newPassword: string, scopes?: string[], token?: string): Promise<PassflowAuthorizationResponse>;
3684
3752
  passkeyRegister(payload: PassflowPasskeyRegisterStartPayload): Promise<PassflowAuthorizationResponse>;
3685
3753
  passkeyAuthenticate(payload: PassflowPasskeyAuthenticateStartPayload): Promise<PassflowAuthorizationResponse>;
3686
3754
  createFederatedAuthUrl(payload: PassflowFederatedAuthExtendedPayload): string;
@@ -5383,6 +5451,8 @@ export declare class Passflow {
5383
5451
  * @param payload.password - User's password
5384
5452
  * @param payload.scopes - Optional scopes to request (defaults to SDK scopes)
5385
5453
  * @returns Promise with authorization response containing tokens
5454
+ * May answer an email verification step instead of tokens: check it with
5455
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5386
5456
  * @throws {PassflowError} If authentication fails
5387
5457
  *
5388
5458
  * @example
@@ -5408,6 +5478,8 @@ export declare class Passflow {
5408
5478
  * @param payload.username - Optional username
5409
5479
  * @param payload.scopes - Optional scopes to request
5410
5480
  * @returns Promise with authorization response containing tokens
5481
+ * May answer an email verification step instead of tokens: check it with
5482
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5411
5483
  * @throws {PassflowError} If registration fails
5412
5484
  *
5413
5485
  * @example
@@ -5469,6 +5541,29 @@ export declare class Passflow {
5469
5541
  * ```
5470
5542
  */
5471
5543
  passwordlessSignInComplete(payload: PassflowPasswordlessSignInCompletePayload): Promise<PassflowValidationResponse>;
5544
+ /**
5545
+ * Finishes a sign-up, sign-in or password change that answered with `email_verification_required`
5546
+ * and a `challenge_id`, using the code the user received by email. Answers like `signIn`: a new
5547
+ * token pair, or a `tfa_token` when a second factor is owed (`isTwoFactorVerificationRequired()`
5548
+ * is then true).
5549
+ *
5550
+ * Emits `Register` for a challenge this instance got from `signUp`, and `SignIn` otherwise. The
5551
+ * challenges are remembered in memory only, so a code typed in another tab or after the
5552
+ * `Passflow` instance was recreated emits `SignIn`, even for a sign-up.
5553
+ *
5554
+ * @param payload.challenge_id - The `challenge_id` from the email verification step
5555
+ * @param payload.otp - The code from the email
5556
+ * @throws {PassflowError} wrong, expired or spent code (`error.otp.*`), unknown challenge (`error.not.found`)
5557
+ *
5558
+ * @example
5559
+ * ```typescript
5560
+ * const step = await passflow.signUp({ user: { email, password } });
5561
+ * if (isEmailVerificationStep(step) && step.challenge_id) {
5562
+ * const response = await passflow.verifyEmailCode({ challenge_id: step.challenge_id, otp: '123456' });
5563
+ * }
5564
+ * ```
5565
+ */
5566
+ verifyEmailCode(payload: PassflowEmailCodePayload): Promise<PassflowAuthorizationResponse>;
5472
5567
  /**
5473
5568
  * Centralized error handler for all public methods.
5474
5569
  * Creates proper ErrorPayload, distinguishes PassflowError from generic Error,
@@ -5627,7 +5722,12 @@ export declare class Passflow {
5627
5722
  *
5628
5723
  * @param newPassword - The new password to set
5629
5724
  * @param scopes - Optional scopes to request after reset
5725
+ * @param resetToken - The reset link's token. Without it the token is read from `?token=` in
5726
+ * `location.search`, then from a hash route's query (`#/reset?token=…`). Pass it when your
5727
+ * router keeps the link's query somewhere else (memory router).
5630
5728
  * @returns Promise with authorization response containing new tokens
5729
+ * May answer an email verification step instead of tokens: check it with
5730
+ * `isEmailVerificationStep(response)`. With a `challenge_id`, finish with `verifyEmailCode`.
5631
5731
  * @throws {PassflowError} If reset fails
5632
5732
  *
5633
5733
  * @example
@@ -5641,7 +5741,7 @@ export declare class Passflow {
5641
5741
  * }
5642
5742
  * ```
5643
5743
  */
5644
- resetPassword(newPassword: string, scopes?: string[]): Promise<PassflowAuthorizationResponse>;
5744
+ resetPassword(newPassword: string, scopes?: string[], resetToken?: string): Promise<PassflowAuthorizationResponse>;
5645
5745
  /**
5646
5746
  * Get application settings and configuration.
5647
5747
  *
@@ -6368,4 +6468,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
6368
6468
  * @returns true if valid username format, false otherwise
6369
6469
  */
6370
6470
  export declare function isValidUsername(username: string): boolean;
6371
- export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OpenAuthUrlOptions, OperationErrorPayload, 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 };
6471
+ export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, 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 };