authhero 8.0.0 → 8.2.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 (41) hide show
  1. package/dist/authhero.cjs +212 -212
  2. package/dist/authhero.d.ts +277 -210
  3. package/dist/authhero.mjs +10131 -9992
  4. package/dist/{passkey-enrollment-Dw1ObR65.mjs → passkey-enrollment-Ba_8I87G.mjs} +1 -5
  5. package/dist/passkey-enrollment-CB7HjMH_.js +1 -0
  6. package/dist/stats.html +1 -1
  7. package/dist/tsconfig.types.tsbuildinfo +1 -1
  8. package/dist/types/authentication-flows/common.d.ts +18 -10
  9. package/dist/types/authentication-flows/connection.d.ts +2 -2
  10. package/dist/types/authentication-flows/passwordless.d.ts +3 -3
  11. package/dist/types/helpers/client-bundle.d.ts +15 -1
  12. package/dist/types/helpers/compose-auth-data.d.ts +44 -0
  13. package/dist/types/helpers/dcr/metadata-mapping.d.ts +1 -1
  14. package/dist/types/helpers/prefetch-client-bundle.d.ts +33 -0
  15. package/dist/types/hooks/webhooks.d.ts +14 -0
  16. package/dist/types/index.d.ts +266 -206
  17. package/dist/types/middlewares/tenant.d.ts +11 -4
  18. package/dist/types/routes/auth-api/index.d.ts +26 -26
  19. package/dist/types/routes/auth-api/passwordless.d.ts +8 -8
  20. package/dist/types/routes/auth-api/register/index.d.ts +2 -2
  21. package/dist/types/routes/auth-api/revoke.d.ts +6 -6
  22. package/dist/types/routes/auth-api/token.d.ts +10 -10
  23. package/dist/types/routes/management-api/actions.d.ts +3 -3
  24. package/dist/types/routes/management-api/authentication-methods.d.ts +1 -1
  25. package/dist/types/routes/management-api/client-grants.d.ts +8 -8
  26. package/dist/types/routes/management-api/clients.d.ts +7 -7
  27. package/dist/types/routes/management-api/connections.d.ts +1 -1
  28. package/dist/types/routes/management-api/email-templates.d.ts +18 -18
  29. package/dist/types/routes/management-api/failed-events.d.ts +1 -1
  30. package/dist/types/routes/management-api/forms.d.ts +119 -119
  31. package/dist/types/routes/management-api/guardian.d.ts +5 -5
  32. package/dist/types/routes/management-api/hooks.d.ts +60 -0
  33. package/dist/types/routes/management-api/index.d.ts +234 -174
  34. package/dist/types/routes/management-api/prompts.d.ts +4 -4
  35. package/dist/types/routes/universal-login/common.d.ts +2 -2
  36. package/dist/types/routes/universal-login/flow-api.d.ts +12 -12
  37. package/dist/types/routes/universal-login/u2-index.d.ts +6 -6
  38. package/dist/types/routes/universal-login/u2-routes.d.ts +6 -6
  39. package/dist/types/types/IdToken.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/dist/passkey-enrollment-DKWsGt-K.js +0 -1
@@ -104,6 +104,11 @@ export interface AuthenticateLoginSessionParams {
104
104
  existingSessionId?: string;
105
105
  /** The connection name used for authentication (e.g., "email", "google-oauth2") */
106
106
  authConnection?: string;
107
+ /** Strategy metadata persisted so /authorize/resume can rehydrate it */
108
+ authStrategy?: {
109
+ strategy: string;
110
+ strategy_type: string;
111
+ };
107
112
  }
108
113
  /**
109
114
  * Authenticate a login session - transitions from PENDING to AUTHENTICATED
@@ -120,14 +125,8 @@ export interface AuthenticateLoginSessionParams {
120
125
  export declare function authenticateLoginSession(ctx: Context<{
121
126
  Bindings: Bindings;
122
127
  Variables: Variables;
123
- }>, { user, client, loginSession, existingSessionId, authConnection, }: AuthenticateLoginSessionParams): Promise<string>;
124
- export interface FinalizeAuthenticatedSessionParams extends AuthenticateLoginSessionParams {
125
- /** Strategy metadata persisted so /authorize/resume can rehydrate it */
126
- authStrategy?: {
127
- strategy: string;
128
- strategy_type: string;
129
- };
130
- }
128
+ }>, { user, client, loginSession, existingSessionId, authConnection, authStrategy, }: AuthenticateLoginSessionParams): Promise<string>;
129
+ export type FinalizeAuthenticatedSessionParams = AuthenticateLoginSessionParams;
131
130
  /**
132
131
  * Persist an authenticated identity onto the login session and 302 the browser
133
132
  * to `/authorize/resume?state=…`. This is the terminal step for sub-flows
@@ -185,12 +184,15 @@ export declare function completeLoginSessionHook(ctx: Context<{
185
184
  * Mark a login session as completed (tokens issued)
186
185
  * This should be called when tokens are successfully returned to the client
187
186
  *
188
- * Uses optimistic concurrency: re-fetches current state to prevent stale overwrites
187
+ * Uses optimistic concurrency: re-fetches current state to prevent stale
188
+ * overwrites. Callers that fetched the session in the same request and have
189
+ * been the only writer since (e.g. createFrontChannelAuthResponse) can pass
190
+ * it as `freshSession` to skip the round-trip.
189
191
  */
190
192
  export declare function completeLoginSession(ctx: Context<{
191
193
  Bindings: Bindings;
192
194
  Variables: Variables;
193
- }>, tenantId: string, loginSession: LoginSession, auth_connection?: string): Promise<void>;
195
+ }>, tenantId: string, loginSession: LoginSession, auth_connection?: string, freshSession?: LoginSession): Promise<void>;
194
196
  /**
195
197
  * Start a continuation - user is redirected to an account page (change-email, etc.)
196
198
  * This transitions to AWAITING_CONTINUATION and stores the allowed scope and return URL
@@ -253,6 +255,12 @@ export declare function completeLogin(ctx: Context<{
253
255
  }>, params: Omit<CreateAuthTokensParams, "client"> & {
254
256
  client: EnrichedClient;
255
257
  responseType?: AuthorizationResponseType;
258
+ /**
259
+ * Set when `loginSession` was fetched in this request and this call chain
260
+ * has been the only writer since — lets completeLoginSession skip its
261
+ * stale-overwrite re-fetch.
262
+ */
263
+ loginSessionIsCurrent?: boolean;
256
264
  }): Promise<TokenResponse | {
257
265
  code: string;
258
266
  state?: string;
@@ -1,11 +1,11 @@
1
1
  import { Context } from "hono";
2
- import { AuthParams } from "@authhero/adapter-interfaces";
2
+ import { AuthParams, LoginSession } from "@authhero/adapter-interfaces";
3
3
  import { EnrichedClient } from "../helpers/client";
4
4
  import { Bindings, Variables } from "../types";
5
5
  export declare function connectionAuth(ctx: Context<{
6
6
  Bindings: Bindings;
7
7
  Variables: Variables;
8
- }>, client: EnrichedClient, connectionName: string, authParams: AuthParams): Promise<Response>;
8
+ }>, client: EnrichedClient, connectionName: string, authParams: AuthParams, preloadedLoginSession?: LoginSession | null): Promise<Response>;
9
9
  interface SocialAuthCallbackParams {
10
10
  code: string;
11
11
  state: string;
@@ -457,7 +457,7 @@ export declare function passwordlessGrantUser(ctx: Context<{
457
457
  custom_login_page_preview?: string | undefined;
458
458
  form_template?: string | undefined;
459
459
  addons?: Record<string, any> | undefined;
460
- token_endpoint_auth_method?: "none" | "private_key_jwt" | "client_secret_post" | "client_secret_basic" | "client_secret_jwt" | undefined;
460
+ token_endpoint_auth_method?: "client_secret_post" | "client_secret_basic" | "none" | "client_secret_jwt" | "private_key_jwt" | undefined;
461
461
  client_metadata?: Record<string, string> | undefined;
462
462
  hide_sign_up_disabled_error?: boolean | undefined;
463
463
  mobile?: Record<string, any> | undefined;
@@ -540,8 +540,8 @@ export declare function passwordlessGrantUser(ctx: Context<{
540
540
  } | undefined;
541
541
  authenticated_at?: string | undefined;
542
542
  };
543
- connectionType: "username" | "sms" | "email";
544
- authConnection: "username" | "sms" | "email";
543
+ connectionType: "username" | "email" | "sms";
544
+ authConnection: "username" | "email" | "sms";
545
545
  session_id: string | undefined;
546
546
  authParams: {
547
547
  client_id: string;
@@ -1,4 +1,4 @@
1
- import { CacheAdapter, Client, Connection, ClientWithTenantId, DataAdapters, ListConnectionsResponse, ListResourceServersResponse, ListHooksResponse, Branding, PromptSetting, Tenant } from "@authhero/adapter-interfaces";
1
+ import { CacheAdapter, Client, Connection, ClientWithTenantId, DataAdapters, ListConnectionsResponse, ListResourceServersResponse, ListHooksResponse, Branding, PromptSetting, Tenant, Theme } from "@authhero/adapter-interfaces";
2
2
  /**
3
3
  * One snapshot of every per-(tenant, client) read that the request path
4
4
  * touches outside of user-specific data. Loaded once per request and held
@@ -17,6 +17,11 @@ export interface ClientBundle {
17
17
  resourceServers: ListResourceServersResponse;
18
18
  promptSettings: PromptSetting | null;
19
19
  hooks: ListHooksResponse;
20
+ /** The tenant's default theme. Universal-login routes always fetch this
21
+ * one ("default") key, so bundling it saves a round-trip on every UI
22
+ * render. Non-UI routes get the field for free; the payload is small.
23
+ */
24
+ defaultTheme: Theme | null;
20
25
  }
21
26
  export interface ClientBundleConfig {
22
27
  /** Seconds the bundle is served without a refresh. Default 300. */
@@ -27,6 +32,15 @@ export interface ClientBundleConfig {
27
32
  keyPrefix?: string;
28
33
  }
29
34
  export declare function clientBundleKey(tenantId: string, clientId: string, prefix?: string): string;
35
+ /**
36
+ * Entity names covered by the {@link ClientBundle}. Single source of truth
37
+ * used by {@link composeAuthData} so individual apps don't need to enumerate
38
+ * the bundled entities themselves — they only declare their long-tail
39
+ * (non-bundle) entities.
40
+ *
41
+ * Keep in sync with {@link fetchBundle} above.
42
+ */
43
+ export declare const BUNDLE_ENTITIES: readonly ["tenants", "clients", "connections", "clientConnections", "branding", "resourceServers", "promptSettings", "hooks", "themes"];
30
44
  /**
31
45
  * Look up — and on miss, populate — the per-(tenant, client) bundle.
32
46
  *
@@ -0,0 +1,44 @@
1
+ import { Context } from "hono";
2
+ import { CacheAdapter, DataAdapters } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../types";
4
+ /**
5
+ * Composes the per-request data-adapter wrapper stack used by every app
6
+ * that serves authenticated/tenant-scoped traffic (auth-api, universal-
7
+ * login v1/v2, saml). Keeps the layer order — and the safety constraints
8
+ * between layers — in one place so individual apps can't drift.
9
+ *
10
+ * Layering (outermost first; that's the order callers hit on each read):
11
+ * addTimingLogs — server-timing instrumentation
12
+ * withClientBundle — L0: per-(tenant_id, client_id) snapshot
13
+ * addBundleWritePurge — local-edge bundle invalidation on writes
14
+ * addRequestScopedDedup — L1: in-request Promise memoization
15
+ * addCaching — L2: cross-request cache (CF Cache API in prod)
16
+ * addDataHooks — user lifecycle hooks
17
+ * raw dataAdapter — underlying DB
18
+ *
19
+ * Apps declare only their `nonBundleEntities` — the long-tail entities they
20
+ * read that aren't covered by {@link BUNDLE_ENTITIES}. Those get cross-
21
+ * request caching via L2 (`addCaching`). Bundle entities are intentionally
22
+ * NOT in L2 — the bundle (L0) is their cross-request cache, and double-
23
+ * caching them under per-entity keys would waste edge storage and create a
24
+ * second invalidation surface.
25
+ *
26
+ * L1 (`addRequestScopedDedup`) covers both sets, since in-request dedup is
27
+ * essentially free and a useful backstop for the rare bundle fall-through
28
+ * (mismatched ctx.var args, non-default list params).
29
+ *
30
+ * Transactional entities (sessions, codes, loginSessions, users, refresh-
31
+ * Tokens, clientGrants, logs, …) MUST NOT be included in `nonBundleEntities`
32
+ * — see request-scoped-dedup.ts for the rationale.
33
+ */
34
+ export declare function composeAuthData(opts: {
35
+ ctx: Context<{
36
+ Bindings: Bindings;
37
+ Variables: Variables;
38
+ }>;
39
+ rawData: DataAdapters;
40
+ cacheAdapter: CacheAdapter;
41
+ defaultTtl: number;
42
+ /** Entities outside the ClientBundle that should still be cached cross-request. */
43
+ nonBundleEntities: string[];
44
+ }): DataAdapters;
@@ -24,10 +24,10 @@ export declare const dcrRequestSchema: z.ZodObject<{
24
24
  response_types: z.ZodOptional<z.ZodArray<z.ZodString>>;
25
25
  token_endpoint_auth_method: z.ZodOptional<z.ZodEnum<{
26
26
  none: "none";
27
- private_key_jwt: "private_key_jwt";
28
27
  client_secret_post: "client_secret_post";
29
28
  client_secret_basic: "client_secret_basic";
30
29
  client_secret_jwt: "client_secret_jwt";
30
+ private_key_jwt: "private_key_jwt";
31
31
  }>>;
32
32
  jwks_uri: z.ZodOptional<z.ZodString>;
33
33
  jwks: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -0,0 +1,33 @@
1
+ import { Context } from "hono";
2
+ import { Client, Tenant } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../types";
4
+ /**
5
+ * Explicit prefetch for the per-(tenant_id, client_id) bundle.
6
+ *
7
+ * Called once at the top of a route handler. Discovers tenant_id from
8
+ * client_id (if not provided), populates `ctx.var.{client_id, tenant_id}`,
9
+ * and warms the bundle so every downstream bundle-covered read in this
10
+ * request is served from one cache key.
11
+ *
12
+ * Why explicit instead of relying on the wrapper alone: the wrapper hooks
13
+ * via ctx.var, but several helpers (e.g. getEnrichedClient) need to read
14
+ * config BEFORE the route has resolved client_id/tenant_id. With this
15
+ * prefetch you set those upfront, so all the subsequent reads — including
16
+ * the ones inside getEnrichedClient's Promise.all — engage the bundle.
17
+ *
18
+ * Throws 403 if the client_id can't be resolved, 404 if its tenant is
19
+ * missing — matching the contract of getEnrichedClient. Does NOT handle
20
+ * CIMD clients (URL-based client_ids); callers that may receive a CIMD
21
+ * client_id should continue to use {@link getEnrichedClient} which has
22
+ * the CIMD-specific resolution path.
23
+ */
24
+ export declare function prefetchClientBundle(ctx: Context<{
25
+ Bindings: Bindings;
26
+ Variables: Variables;
27
+ }>, opts: {
28
+ client_id: string;
29
+ tenant_id?: string;
30
+ }): Promise<{
31
+ tenant: Tenant;
32
+ client: Client;
33
+ }>;
@@ -1,6 +1,20 @@
1
1
  import { DataAdapters, Hook, User } from "@authhero/adapter-interfaces";
2
2
  import { Context } from "hono";
3
3
  import { Variables, Bindings } from "../types";
4
+ export interface WebHookResult {
5
+ ok: boolean;
6
+ status?: number;
7
+ body?: string;
8
+ error?: string;
9
+ }
10
+ export declare function invokeWebHook(ctx: Context<{
11
+ Bindings: Bindings;
12
+ Variables: Variables;
13
+ }>, hook: Hook & {
14
+ url: string;
15
+ }, data: any & {
16
+ tenant_id: string;
17
+ }): Promise<WebHookResult>;
4
18
  export declare function invokeHooks(ctx: Context<{
5
19
  Bindings: Bindings;
6
20
  Variables: Variables;