authhero 9.39.0 → 9.41.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.
Files changed (82) hide show
  1. package/dist/assets/u/widget/authhero-widget.esm.js +1 -1
  2. package/dist/assets/u/widget/index.esm.js +1 -1
  3. package/dist/assets/u/widget/p-603aa8fa.entry.js +1 -0
  4. package/dist/assets/u/widget/p-6774edd2.entry.js +1 -0
  5. package/dist/authhero.cjs +173 -168
  6. package/dist/authhero.d.ts +717 -611
  7. package/dist/authhero.mjs +14301 -12851
  8. package/dist/{mfa-DMThiuUR.mjs → mfa-CdC-9ysu.mjs} +89 -89
  9. package/dist/{mfa-Dh6nNiRX.js → mfa-Dx8-AJ6U.js} +2 -2
  10. package/dist/mfa-attempts-CtWWceg2.js +393 -0
  11. package/dist/{mfa-attempts-O0x4jJzl.mjs → mfa-attempts-mBkfX0wf.mjs} +7055 -6373
  12. package/dist/{passkey-enrollment-CSeOQWv1.js → passkey-enrollment-KQcVF_QM.js} +1 -1
  13. package/dist/tsconfig.types.tsbuildinfo +1 -1
  14. package/dist/types/authentication-flows/common.d.ts +4 -1
  15. package/dist/types/authentication-flows/mfa-attempts.d.ts +7 -0
  16. package/dist/types/generated/locale-types.d.ts +45 -0
  17. package/dist/types/helpers/client.d.ts +1 -0
  18. package/dist/types/helpers/code-recipient.d.ts +37 -0
  19. package/dist/types/helpers/reserved-claims.d.ts +2 -2
  20. package/dist/types/hooks/codehooks.d.ts +45 -0
  21. package/dist/types/hooks/helpers/action-users.d.ts +56 -0
  22. package/dist/types/hooks/helpers/post-login-account-linking.d.ts +18 -4
  23. package/dist/types/hooks/lifecycle-codehooks.d.ts +2 -2
  24. package/dist/types/hooks/pre-screen.d.ts +114 -0
  25. package/dist/types/index.d.ts +409 -363
  26. package/dist/types/routes/auth-api/index.d.ts +20 -20
  27. package/dist/types/routes/auth-api/passwordless.d.ts +14 -14
  28. package/dist/types/routes/auth-api/revoke.d.ts +6 -6
  29. package/dist/types/routes/management-api/action-executions.d.ts +1 -1
  30. package/dist/types/routes/management-api/action-triggers.d.ts +28 -28
  31. package/dist/types/routes/management-api/actions.d.ts +13 -13
  32. package/dist/types/routes/management-api/branding-uploads.d.ts +4 -4
  33. package/dist/types/routes/management-api/branding.d.ts +9 -9
  34. package/dist/types/routes/management-api/client-registration-tokens.d.ts +3 -3
  35. package/dist/types/routes/management-api/clients.d.ts +20 -18
  36. package/dist/types/routes/management-api/connections.d.ts +15 -9
  37. package/dist/types/routes/management-api/emails.d.ts +6 -6
  38. package/dist/types/routes/management-api/failed-events.d.ts +4 -4
  39. package/dist/types/routes/management-api/forms.d.ts +168 -144
  40. package/dist/types/routes/management-api/guardian.d.ts +1 -1
  41. package/dist/types/routes/management-api/helpers.d.ts +1 -1
  42. package/dist/types/routes/management-api/hooks.d.ts +49 -49
  43. package/dist/types/routes/management-api/index.d.ts +370 -338
  44. package/dist/types/routes/management-api/jobs.d.ts +2 -2
  45. package/dist/types/routes/management-api/keys.d.ts +4 -4
  46. package/dist/types/routes/management-api/log-streams.d.ts +6 -6
  47. package/dist/types/routes/management-api/logs.d.ts +4 -4
  48. package/dist/types/routes/management-api/organizations.d.ts +2 -2
  49. package/dist/types/routes/management-api/prompts.d.ts +8 -8
  50. package/dist/types/routes/management-api/resource-servers.d.ts +8 -8
  51. package/dist/types/routes/management-api/roles.d.ts +1 -1
  52. package/dist/types/routes/management-api/rollouts.d.ts +6 -6
  53. package/dist/types/routes/management-api/self-service-profiles.d.ts +1 -1
  54. package/dist/types/routes/management-api/tenant-members.d.ts +8 -8
  55. package/dist/types/routes/management-api/tenant-operations.d.ts +4 -4
  56. package/dist/types/routes/management-api/tenants.d.ts +20 -20
  57. package/dist/types/routes/management-api/users.d.ts +12 -12
  58. package/dist/types/routes/universal-login/common.d.ts +6 -6
  59. package/dist/types/routes/universal-login/flow-api.d.ts +8 -8
  60. package/dist/types/routes/universal-login/pre-screen-gates.d.ts +31 -0
  61. package/dist/types/routes/universal-login/screens/account-change-email.d.ts +52 -0
  62. package/dist/types/routes/universal-login/screens/account-helpers.d.ts +19 -24
  63. package/dist/types/routes/universal-login/screens/account.d.ts +6 -0
  64. package/dist/types/routes/universal-login/screens/index.d.ts +4 -2
  65. package/dist/types/routes/universal-login/screens/invalid-session.d.ts +10 -0
  66. package/dist/types/routes/universal-login/screens/login-otp.d.ts +81 -7
  67. package/dist/types/routes/universal-login/screens/magic-link-sent.d.ts +8 -1
  68. package/dist/types/routes/universal-login/screens/signup.d.ts +0 -3
  69. package/dist/types/routes/universal-login/screens/social-connections.d.ts +31 -0
  70. package/dist/types/routes/universal-login/screens/types.d.ts +3 -0
  71. package/dist/types/routes/universal-login/u2-index.d.ts +19 -5
  72. package/dist/types/routes/universal-login/u2-routes.d.ts +6 -5
  73. package/dist/types/routes/universal-login/u2-widget-page.d.ts +1 -4
  74. package/dist/types/state-machines/login-session-data.d.ts +36 -1
  75. package/dist/types/state-machines/login-session.d.ts +29 -1
  76. package/dist/types/types/Hooks.d.ts +62 -17
  77. package/dist/types/types/Variables.d.ts +2 -0
  78. package/dist/types/utils/embedded-browser.d.ts +4 -0
  79. package/package.json +6 -6
  80. package/dist/assets/u/widget/p-32247347.entry.js +0 -1
  81. package/dist/assets/u/widget/p-3f908508.entry.js +0 -1
  82. package/dist/mfa-attempts-BaKbuGvZ.js +0 -321
@@ -246,7 +246,10 @@ export declare function completeLoginSessionContinuation(ctx: Context<{
246
246
  Variables: Variables;
247
247
  }>, tenantId: string, loginSession: LoginSession): Promise<string | undefined>;
248
248
  /**
249
- * Check if a login session allows access to a given scope during continuation
249
+ * Check if a login session allows access to a given scope during continuation.
250
+ * The scope stands in for a signed-in session, so it ends when the login
251
+ * session expires: adapters return expired rows and nothing else on the
252
+ * continuation paths checks `expires_at`.
250
253
  */
251
254
  export declare function hasValidContinuationScope(loginSession: LoginSession, requiredScope: string): boolean;
252
255
  export interface CreateAuthResponseParams {
@@ -40,6 +40,13 @@ export declare function resetMfaFailures(ctx: MfaContext, tenantId: string, logi
40
40
  * Count an MFA SMS send on the login session and consume the per-user (or,
41
41
  * without a user, per-number) rate limit. Throws MfaSmsRateLimitError when
42
42
  * either limit is reached. Counted before sending, so failed sends count too.
43
+ *
44
+ * Order: check the session without writing (finalized or expired sessions
45
+ * throw FinalizedLoginSessionError, at the cap MfaSmsRateLimitError), then the
46
+ * rate limit, then reserve the slot atomically (see
47
+ * reserveLoginSessionCounter). Neither a finished session nor a send the rate
48
+ * limit rejects uses up the shared rate limit or the session's allowance, and
49
+ * concurrent sends on one session cannot exceed MFA_MAX_SMS_SENDS.
43
50
  */
44
51
  export declare function enforceMfaSmsSendLimit(ctx: MfaContext, tenantId: string, loginSessionId: string, phoneNumber: string, userId?: string): Promise<void>;
45
52
  export {};
@@ -59,6 +59,8 @@ export interface CommonAccountScreen {
59
59
  deleteAccountLabel: () => string;
60
60
  deleteAccountDetail: () => string;
61
61
  logoutText: () => string;
62
+ changeEmailLabel: () => string;
63
+ continueText: () => string;
62
64
  }
63
65
  export interface CommonAccountProfileScreen {
64
66
  title: () => string;
@@ -71,6 +73,7 @@ export interface CommonAccountProfileScreen {
71
73
  buttonText: () => string;
72
74
  backToAccountText: () => string;
73
75
  updateFailed: () => string;
76
+ changeEmailText: () => string;
74
77
  }
75
78
  export interface CommonAccountDeleteScreen {
76
79
  title: () => string;
@@ -186,6 +189,39 @@ export interface CommonAccountMfaTotpEnrollmentScreen {
186
189
  verificationFailedText: () => string;
187
190
  tooManyFailuresText: () => string;
188
191
  }
192
+ export interface CommonInvalidSessionScreen {
193
+ title: () => string;
194
+ description: () => string;
195
+ backText: () => string;
196
+ }
197
+ export interface CommonAccountChangeEmailScreen {
198
+ title: () => string;
199
+ description: () => string;
200
+ currentEmailLabel: () => string;
201
+ emailLabel: () => string;
202
+ invalidEmail: () => string;
203
+ buttonText: () => string;
204
+ sendFailed: () => string;
205
+ backToAccountText: () => string;
206
+ }
207
+ export interface CommonAccountChangeEmailVerifyScreen {
208
+ title: () => string;
209
+ description: (vars: {
210
+ email: string;
211
+ }) => string;
212
+ codeLabel: () => string;
213
+ buttonText: () => string;
214
+ noCode: () => string;
215
+ invalidCode: () => string;
216
+ tooManyAttempts: () => string;
217
+ emailTaken: () => string;
218
+ successTitle: () => string;
219
+ successDescription: (vars: {
220
+ email: string;
221
+ }) => string;
222
+ continueText: () => string;
223
+ backText: () => string;
224
+ }
189
225
  export interface ConsentScreen {
190
226
  buttonText: () => string;
191
227
  cancelButtonText: () => string;
@@ -288,6 +324,8 @@ export interface EmailOtpChallengeScreen {
288
324
  clientName: string;
289
325
  }) => string;
290
326
  resendText: () => string;
327
+ resendSuccess: () => string;
328
+ resendFailed: () => string;
291
329
  sessionExpired: () => string;
292
330
  title: () => string;
293
331
  unexpectedError: () => string;
@@ -573,6 +611,8 @@ export interface MagicLinkSentScreen {
573
611
  username: string;
574
612
  }) => string;
575
613
  resendText: () => string;
614
+ resendSuccess: () => string;
615
+ resendFailed: () => string;
576
616
  spamText: () => string;
577
617
  title: () => string;
578
618
  }
@@ -949,6 +989,8 @@ export interface SmsOtpChallengeScreen {
949
989
  clientName: string;
950
990
  }) => string;
951
991
  resendText: () => string;
992
+ resendSuccess: () => string;
993
+ resendFailed: () => string;
952
994
  sessionExpired: () => string;
953
995
  title: () => string;
954
996
  unexpectedError: () => string;
@@ -1057,6 +1099,9 @@ export interface ScreenMap {
1057
1099
  "common.account-passkeys": CommonAccountPasskeysScreen;
1058
1100
  "common.account-mfa-phone-enrollment": CommonAccountMfaPhoneEnrollmentScreen;
1059
1101
  "common.account-mfa-totp-enrollment": CommonAccountMfaTotpEnrollmentScreen;
1102
+ "common.invalid-session": CommonInvalidSessionScreen;
1103
+ "common.account-change-email": CommonAccountChangeEmailScreen;
1104
+ "common.account-change-email-verify": CommonAccountChangeEmailVerifyScreen;
1060
1105
  "consent.consent": ConsentScreen;
1061
1106
  "consent.connect-consent": ConsentConnectConsentScreen;
1062
1107
  "consent.connect-tenant-select": ConsentConnectTenantSelectScreen;
@@ -541,6 +541,7 @@ export declare const enrichedClientSchema: z.ZodObject<{
541
541
  max: z.ZodOptional<z.ZodNumber>;
542
542
  }, z.core.$strip>>;
543
543
  }, z.core.$strip>>;
544
+ allow_action_users: z.ZodOptional<z.ZodBoolean>;
544
545
  set_user_root_attributes: z.ZodOptional<z.ZodEnum<{
545
546
  on_each_login: "on_each_login";
546
547
  on_first_login: "on_first_login";
@@ -0,0 +1,37 @@
1
+ import type { Context } from "hono";
2
+ import type { Code, CodesAdapter } from "@authhero/adapter-interfaces";
3
+ import type { CountryCode } from "libphonenumber-js";
4
+ /**
5
+ * Login and pre-signup codes are delivered to one address, and only that
6
+ * address may redeem them. The address is stored on the code when it is
7
+ * created (`state.recipient`), normalized like the identifier it is later
8
+ * compared with, because the login session's username can change after the
9
+ * code was sent.
10
+ *
11
+ * Codes without a stored recipient (minted before the recipient was stored)
12
+ * are not accepted: login codes expire within 30 minutes and are simply
13
+ * requested again, and a pre-signup code without one only means the signup
14
+ * continues unverified and a verification email is sent instead.
15
+ */
16
+ /** `state.purpose` of a pre-signup `email_verification` code. */
17
+ export declare const PRE_SIGNUP_CODE_PURPOSE = "pre_signup";
18
+ export declare function normalizeCodeRecipient(identifier: string, countryCode?: CountryCode): string;
19
+ export declare function codeRecipientState(recipient: string, countryCode?: CountryCode, extra?: Record<string, unknown>): string;
20
+ export declare function parseCodeState(code: Pick<Code, "state">): Record<string, unknown>;
21
+ /** The address the code was sent to, if it was stored when it was created. */
22
+ export declare function getCodeRecipient(code: Pick<Code, "state">): string | undefined;
23
+ /** Whether `identifier` is the address the code was sent to. */
24
+ export declare function isCodeRecipient(code: Pick<Code, "state">, identifier: string | undefined, countryCode?: CountryCode): boolean;
25
+ /**
26
+ * Retire a login session's unused login codes that were sent to another
27
+ * address than `recipient`, for when the session's username changes. Best
28
+ * effort: redemption checks the recipient regardless, so a failure here is
29
+ * logged and ignored.
30
+ */
31
+ export declare function invalidateOtherLoginCodes(ctx: Context<any>, codes: CodesAdapter, tenantId: string, loginId: string, recipient: string): Promise<void>;
32
+ export declare function preSignupCodeState(recipient: string): string;
33
+ /**
34
+ * Whether `stored` is an unexpired, unused pre-signup code minted for this
35
+ * login session and sent to `email`.
36
+ */
37
+ export declare function isPreSignupCodeFor(stored: Code | null | undefined, loginId: string, email: string | undefined): stored is Code;
@@ -14,9 +14,9 @@ export declare const USERINFO_RESERVED_CLAIMS: readonly ["iss", "sub", "aud", "e
14
14
  * vendor/tenant for downstream APIs while `sub` stays `auth-service`.
15
15
  * Client-bound mints keep `azp` locked (see below).
16
16
  */
17
- export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "scope" | "tenant_id" | "client_id" | "org_name" | "jti" | "sid" | "org_id" | "iss" | "exp" | "iat" | "aud" | "auth_time" | "acr" | "amr" | "gty" | "nbf" | "act" | "permissions" | "requested_userinfo_claims")[];
17
+ export declare const SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "scope" | "tenant_id" | "jti" | "client_id" | "org_name" | "sid" | "permissions" | "auth_time" | "iss" | "aud" | "exp" | "nbf" | "iat" | "acr" | "amr" | "act" | "org_id" | "requested_userinfo_claims" | "gty")[];
18
18
  /** Client-bound mints: `azp` must stay the registered client id. */
19
- export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "scope" | "tenant_id" | "client_id" | "org_name" | "jti" | "sid" | "org_id" | "iss" | "exp" | "iat" | "aud" | "auth_time" | "acr" | "amr" | "azp" | "gty" | "nbf" | "act" | "permissions" | "requested_userinfo_claims")[];
19
+ export declare const CLIENT_SERVICE_TOKEN_RESERVED_CLAIMS: ("sub" | "scope" | "tenant_id" | "jti" | "client_id" | "org_name" | "sid" | "permissions" | "auth_time" | "iss" | "aud" | "exp" | "nbf" | "iat" | "azp" | "acr" | "amr" | "act" | "org_id" | "requested_userinfo_claims" | "gty")[];
20
20
  export type AccessTokenReservedClaim = (typeof ACCESS_TOKEN_RESERVED_CLAIMS)[number];
21
21
  export type IdTokenReservedClaim = (typeof ID_TOKEN_RESERVED_CLAIMS)[number];
22
22
  /**
@@ -74,12 +74,44 @@ export declare function replayApiCalls(apiCalls: Array<{
74
74
  method: string;
75
75
  args: unknown[];
76
76
  }>, api: CodeHookApi): Promise<void>;
77
+ /**
78
+ * Why an action produced no usable result: it ran past the host's timeout, or
79
+ * it failed (threw, returned `success: false`, its code is missing, or no code
80
+ * executor is configured). Used by the fail-closed option (issue #1816).
81
+ */
82
+ export type CodeHookFailure = "action_timeout" | "action_failed";
77
83
  export type HandleCodeHookOutcome = {
78
84
  result: ActionExecutionResult;
79
85
  logs: CodeExecutionLog[];
80
86
  /** True if the executor recorded an API call that cancels the flow. */
81
87
  denied: boolean;
88
+ /** Set when the action did not run to completion. */
89
+ failure?: CodeHookFailure;
82
90
  };
91
+ /**
92
+ * Hook `metadata` key: `true` makes a failing action deny the request instead
93
+ * of letting it continue. Shared with `pre-screen`, which reads the same key.
94
+ */
95
+ export declare const HOOK_FAIL_CLOSED_METADATA_KEY = "fail_closed";
96
+ /**
97
+ * True when the hook binding opted into failing closed: a timeout, a failed
98
+ * execution or a non-HTTP throw denies the request (issue #1816). Off by
99
+ * default, so an action that breaks lets the request through as before.
100
+ */
101
+ export declare function isFailClosedHook(hook: {
102
+ metadata?: Record<string, unknown>;
103
+ }): boolean;
104
+ /**
105
+ * The outcome to record for an action that threw outside the executor (for
106
+ * example a replayed API call throwing a plain `Error`).
107
+ */
108
+ export declare function thrownOutcome(actionName: string, err: unknown, denied?: boolean): HandleCodeHookOutcome;
109
+ /**
110
+ * The outcome to record when no code executor (or no tenant) was available to
111
+ * run a bound action. Only recorded for fail-closed bindings: a fail-open
112
+ * binding keeps skipping silently, as before.
113
+ */
114
+ export declare function unavailableOutcome(actionName: string): HandleCodeHookOutcome;
83
115
  /**
84
116
  * Core code-hook execution, decoupled from the Hono request `ctx`.
85
117
  *
@@ -180,9 +212,22 @@ export declare function persistActionExecution(data: Pick<DataAdapters, "actionE
180
212
  * surrounding tenant log (the standard token-exchange log entry). The
181
213
  * execution record itself follows Auth0's shape — see
182
214
  * GET /api/v2/actions/executions/:id.
215
+ *
216
+ * `api.access.deny` stops token issuance: the execution is persisted as
217
+ * canceled and the 400 from `deny` is rethrown, so no tokens are signed and
218
+ * later actions don't run. A binding with `metadata.fail_closed` also denies
219
+ * when its action times out, fails or throws (issue #1816).
183
220
  */
184
221
  export declare function handleCredentialsExchangeCodeHooks(ctx: Context<{
185
222
  Bindings: Bindings;
186
223
  Variables: Variables;
187
224
  }>, hooks: any[], event: HookEvent, api: OnExecuteCredentialsExchangeAPI): Promise<string | null>;
225
+ /**
226
+ * Store the execution record of a denied request, then rethrow the denial.
227
+ * Storing it must not replace the denial with a 500.
228
+ */
229
+ export declare function persistThenThrow(ctx: Context<{
230
+ Bindings: Bindings;
231
+ Variables: Variables;
232
+ }>, persist: () => Promise<string | null>, err: unknown): Promise<never>;
188
233
  export {};
@@ -0,0 +1,56 @@
1
+ import { Context } from "hono";
2
+ import { Connection, DataAdapters, User } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../../types";
4
+ /** Most `api.users.ensure` calls one action execution may make. */
5
+ export declare const MAX_ENSURED_USERS_PER_EXECUTION = 5;
6
+ /**
7
+ * Lazily loads the tenant's connections once per execution. Used to resolve
8
+ * the connection `ensure` writes to and to tell whether a user is an anchor
9
+ * (a primary whose connection is an external connection) without a lookup
10
+ * per call.
11
+ *
12
+ * `injectedStrategies` are the names of strategies supplied through
13
+ * `env.STRATEGIES`: a login connection using one stores its users under that
14
+ * name, so an external connection must not reuse it.
15
+ */
16
+ export declare function createExternalConnectionLookup(data: DataAdapters, tenantId: string, injectedStrategies?: Iterable<string>): {
17
+ /**
18
+ * The external connection named `name` if actions may create users in it:
19
+ * opted in with `allow_action_users`, and not named like a prefix that
20
+ * login identities use.
21
+ */
22
+ getActionUsersConnection: (name: string) => Promise<Connection | undefined>;
23
+ /** True when `user` lives in one of the tenant's external connections. */
24
+ isExternalUser: (user: Pick<User, "connection" | "provider">) => Promise<boolean>;
25
+ };
26
+ export type ExternalConnectionLookup = ReturnType<typeof createExternalConnectionLookup>;
27
+ /**
28
+ * Builds the host implementation of `api.users.ensure` (issue #1802).
29
+ *
30
+ * The isolate only records the call; this runs when it is replayed. It
31
+ * creates `<connection>|<id>` if missing, otherwise merges the profile and
32
+ * `app_metadata` into it. Every refusal logs `FAILED_HOOK` and writes nothing.
33
+ *
34
+ * Writes go through the transaction's adapters, which are undecorated: no
35
+ * registration or update hooks, no built-in email linking (which would demote
36
+ * a new anchor under an older same-email user), and no post-registration
37
+ * webhook or outbox event — the user is a record, not a signup.
38
+ */
39
+ export declare function createActionUsersApi(params: {
40
+ ctx: Context<{
41
+ Bindings: Bindings;
42
+ Variables: Variables;
43
+ }>;
44
+ data: DataAdapters;
45
+ tenantId: string;
46
+ triggerId: string;
47
+ externalConnections: ExternalConnectionLookup;
48
+ }): {
49
+ api: {
50
+ users: {
51
+ ensure: (raw: unknown) => Promise<void>;
52
+ };
53
+ };
54
+ /** user_ids that `ensure` created or updated during this execution. */
55
+ ensuredUserIds: Set<string>;
56
+ };
@@ -1,6 +1,7 @@
1
1
  import { Context } from "hono";
2
2
  import { DataAdapters, User } from "@authhero/adapter-interfaces";
3
3
  import { Bindings, Variables } from "../../types";
4
+ import { ExternalConnectionLookup } from "./action-users";
4
5
  /**
5
6
  * The `user` namespace exposed to `post-user-login` code hooks. `setLinkedTo`
6
7
  * is the programmable account-linking verb (issue #1184): an action reads
@@ -28,10 +29,16 @@ export type PostLoginUserApi = {
28
29
  * - **Verified-email gate.** When `requireVerifiedEmail` (the default), the
29
30
  * logging-in user must have a verified email, regardless of what the action
30
31
  * asserts.
31
- * - **Direction.** Older account wins (`compareUsersByAge`): if the logging-in
32
- * user pre-dates the target, the target is demoted instead. Either way the
33
- * write goes through the update decorator's `linkUserTo` chokepoint, which
34
- * keeps the cluster a single hop deep.
32
+ * Users created by `api.users.ensure` in the same execution are also
33
+ * allowed (issue #1802); they skip the verified-email gate because the
34
+ * action resolved the person against its own system of record.
35
+ * - **Direction.** A primary in an `external` connection (an anchor) always
36
+ * stays primary. Otherwise the older account wins (`compareUsersByAge`):
37
+ * if the logging-in user pre-dates the target, the target is demoted
38
+ * instead. Either way the write goes through the update decorator's
39
+ * `linkUserTo` chokepoint, which keeps the cluster a single hop deep.
40
+ * - **No re-anchoring.** A user already under one anchor is never moved
41
+ * under a different one by a login; that is an admin operation.
35
42
  * - **Idempotency.** A no-op when the user is already linked to the target.
36
43
  */
37
44
  export declare function createPostLoginUserApi(params: {
@@ -46,6 +53,13 @@ export declare function createPostLoginUserApi(params: {
46
53
  candidates: User[];
47
54
  /** @default true */
48
55
  requireVerifiedEmail?: boolean;
56
+ /**
57
+ * user_ids created or updated by `api.users.ensure` earlier in the same
58
+ * execution. Read at replay time, so it must be the live set.
59
+ */
60
+ ensuredUserIds?: ReadonlySet<string>;
61
+ /** Tells anchors (users in an `external` connection) apart. */
62
+ externalConnections?: ExternalConnectionLookup;
49
63
  }): {
50
64
  api: PostLoginUserApi;
51
65
  /** The user id of the primary after linking, or null if nothing linked. */
@@ -10,7 +10,7 @@ export declare function listEnabledCodeHooks(ctx: Context<{
10
10
  Bindings: Bindings;
11
11
  Variables: Variables;
12
12
  }>, tenantId: string, triggerId: string): Promise<{
13
- trigger_id: "post-user-login" | "credentials-exchange" | "pre-user-registration" | "post-user-registration" | "post-user-update" | "validate-registration-username" | "pre-user-deletion" | "post-user-deletion" | "pre-user-update" | "pre-account-action" | "custom-email-provider" | "custom-phone-provider";
13
+ trigger_id: "post-user-login" | "pre-user-registration" | "post-user-registration" | "post-user-update" | "validate-registration-username" | "pre-user-deletion" | "post-user-deletion" | "credentials-exchange" | "pre-user-update" | "pre-screen" | "custom-email-provider" | "custom-phone-provider";
14
14
  enabled: boolean;
15
15
  synchronous: boolean;
16
16
  created_at: string;
@@ -18,7 +18,7 @@ export declare function listEnabledCodeHooks(ctx: Context<{
18
18
  hook_id: string;
19
19
  code_id: string;
20
20
  scope?: "local" | "shared" | "platform" | undefined;
21
- override?: "secrets" | "none" | "fields" | undefined;
21
+ override?: "none" | "secrets" | "fields" | undefined;
22
22
  enforce?: boolean | undefined;
23
23
  priority?: number | undefined;
24
24
  metadata?: Record<string, unknown> | undefined;
@@ -0,0 +1,114 @@
1
+ import { Context } from "hono";
2
+ import { Hook, LoginSession, PreScreenOperation, PreScreenPhase, User } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../types";
4
+ import { EnrichedClient } from "../helpers/client";
5
+ type Ctx = Context<{
6
+ Bindings: Bindings;
7
+ Variables: Variables;
8
+ }>;
9
+ type CodeHook = Extract<Hook, {
10
+ code_id: string;
11
+ }>;
12
+ export declare const PRE_SCREEN_TRIGGER = "pre-screen";
13
+ /**
14
+ * Host wait for the `onExecutePreScreen` config callback, matching the bound
15
+ * on code Actions. A callback that never settles must not leave the screen
16
+ * hanging.
17
+ */
18
+ export declare const PRE_SCREEN_TIMEOUT_MS = 5000;
19
+ /** Shown when an action denies without a reason, or fails closed. */
20
+ export declare const DEFAULT_PRE_SCREEN_DENIAL = "This isn't available for your account.";
21
+ export type PreScreenDecision = {
22
+ type: "continue";
23
+ } | {
24
+ type: "redirect";
25
+ url: string;
26
+ } | {
27
+ type: "deny";
28
+ reason: string;
29
+ };
30
+ /** What a submission does, for the submit phase's `event.operation`. */
31
+ export type PreScreenSubmission = {
32
+ operation: PreScreenOperation;
33
+ details?: Record<string, string>;
34
+ };
35
+ /**
36
+ * Thrown when a `pre-screen` Action denies a screen or its submission. The
37
+ * universal-login error handler renders `reason` on the branded error page
38
+ * (other error messages are replaced by a generic text there, which would
39
+ * hide the tenant's explanation).
40
+ */
41
+ export declare class ScreenDeniedError extends Error {
42
+ readonly reason: string;
43
+ readonly status = 403;
44
+ constructor(reason: string);
45
+ }
46
+ /** A loader that only runs when something is bound to the screen. */
47
+ type Lazy<T> = () => Promise<T>;
48
+ export interface PreScreenParams {
49
+ tenantId: string;
50
+ /** Screen name from `PRE_SCREEN_SCREENS`, e.g. `login-id`. */
51
+ screen: string;
52
+ phase: PreScreenPhase;
53
+ /**
54
+ * Everything below is only loaded when something is bound to the screen,
55
+ * so unbound screens pay nothing beyond the (cached) hook list.
56
+ */
57
+ client?: Lazy<EnrichedClient | undefined>;
58
+ loginSession?: Lazy<LoginSession | undefined>;
59
+ user?: Lazy<User | undefined>;
60
+ /** Submit phase: the operation the submission performs, if any. */
61
+ submission?: Lazy<PreScreenSubmission | undefined>;
62
+ }
63
+ /**
64
+ * The enabled code hooks bound to `pre-screen` that run for `screen`, highest
65
+ * priority first. Reads the unparameterized hook list, which the client bundle
66
+ * serves from cache, and only queries when that page is full.
67
+ */
68
+ export declare function findPreScreenHooks(ctx: Ctx, tenantId: string, screen: string): Promise<CodeHook[]>;
69
+ /**
70
+ * Resolve a redirect target from an Action. Only the URL and query the Action
71
+ * returned are used: relative URLs resolve against the current request and
72
+ * anything other than http(s) is rejected, so an Action can't send the
73
+ * browser to `javascript:` or `data:` URLs. Nothing from the request (its
74
+ * query, `redirect_uri`, the login session) is added, so the trigger can't be
75
+ * used as an open redirect. No `state` is appended: the user leaves this
76
+ * transaction, which stays resumable until the login session expires.
77
+ */
78
+ export declare function buildPreScreenRedirectUrl(requestUrl: string, url: unknown, options: unknown): string;
79
+ /**
80
+ * Run the `pre-screen` trigger: the `onExecutePreScreen` config hook first,
81
+ * then the code Actions bound to the screen in priority order. The first one
82
+ * that redirects or denies decides and later ones don't run.
83
+ *
84
+ * An Action that throws, times out or fails denies a submission (fail
85
+ * closed). In the render phase it is logged and the screen is shown, unless
86
+ * the binding set `metadata.fail_closed`.
87
+ */
88
+ export declare function runPreScreen(ctx: Ctx, params: PreScreenParams): Promise<PreScreenDecision>;
89
+ /**
90
+ * Run the trigger and act on the result: throws `RedirectException` to send
91
+ * the user elsewhere and `ScreenDeniedError` to stop. Both are rendered by the
92
+ * universal-login error handler. Returns normally when the screen may go on.
93
+ */
94
+ export declare function enforcePreScreen(ctx: Ctx, params: PreScreenParams): Promise<void>;
95
+ /**
96
+ * The user an identifier (email, phone number or username) entered on a
97
+ * login, signup or password-reset screen belongs to, resolved to the primary
98
+ * user. Undefined when no user matches.
99
+ */
100
+ export declare function findUserByIdentifier(ctx: Ctx, tenantId: string, identifier: unknown): Promise<User | undefined>;
101
+ /**
102
+ * The user of a login-flow screen: the identifier just submitted (pass it
103
+ * only for screens where the user enters one), then the user the transaction
104
+ * already authenticated (MFA, consent, passkey enrollment), then the
105
+ * identifier entered earlier in the flow.
106
+ */
107
+ export declare function findLoginScreenUser(ctx: Ctx, tenantId: string, loginSession: LoginSession | undefined, submittedIdentifier?: unknown): Promise<User | undefined>;
108
+ /**
109
+ * The user of an account screen: the signed-in session's user, or, mid-login
110
+ * (a form hook sent the user to an account page), the user the transaction
111
+ * authenticated. The screen still enforces its own access rules afterwards.
112
+ */
113
+ export declare function findAccountScreenUser(ctx: Ctx, tenantId: string, loginSession: LoginSession | undefined): Promise<User | undefined>;
114
+ export {};