authhero 7.2.2 → 8.1.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 (37) hide show
  1. package/dist/authhero.cjs +102 -102
  2. package/dist/authhero.d.ts +148 -134
  3. package/dist/authhero.mjs +10893 -10466
  4. package/dist/stats.html +1 -1
  5. package/dist/tsconfig.types.tsbuildinfo +1 -1
  6. package/dist/types/authentication-flows/passwordless.d.ts +2 -2
  7. package/dist/types/helpers/bundle-write-purge.d.ts +16 -0
  8. package/dist/types/helpers/client-bundle.d.ts +65 -0
  9. package/dist/types/helpers/compose-auth-data.d.ts +44 -0
  10. package/dist/types/helpers/prefetch-client-bundle.d.ts +33 -0
  11. package/dist/types/helpers/request-scoped-dedup.d.ts +8 -0
  12. package/dist/types/helpers/with-client-bundle.d.ts +31 -0
  13. package/dist/types/hooks/webhooks.d.ts +14 -0
  14. package/dist/types/index.d.ts +145 -87
  15. package/dist/types/routes/auth-api/account.d.ts +2 -2
  16. package/dist/types/routes/auth-api/index.d.ts +35 -35
  17. package/dist/types/routes/auth-api/passwordless.d.ts +16 -16
  18. package/dist/types/routes/auth-api/revoke.d.ts +6 -6
  19. package/dist/types/routes/auth-api/token.d.ts +10 -10
  20. package/dist/types/routes/auth-api/well-known.d.ts +1 -1
  21. package/dist/types/routes/management-api/action-triggers.d.ts +1 -1
  22. package/dist/types/routes/management-api/authentication-methods.d.ts +1 -1
  23. package/dist/types/routes/management-api/email-templates.d.ts +18 -18
  24. package/dist/types/routes/management-api/failed-events.d.ts +1 -1
  25. package/dist/types/routes/management-api/flows.d.ts +7 -7
  26. package/dist/types/routes/management-api/guardian.d.ts +5 -5
  27. package/dist/types/routes/management-api/hooks.d.ts +60 -0
  28. package/dist/types/routes/management-api/index.d.ts +104 -44
  29. package/dist/types/routes/management-api/logs.d.ts +3 -3
  30. package/dist/types/routes/management-api/organizations.d.ts +2 -2
  31. package/dist/types/routes/management-api/prompts.d.ts +4 -4
  32. package/dist/types/routes/management-api/users.d.ts +2 -2
  33. package/dist/types/routes/universal-login/u2-index.d.ts +6 -6
  34. package/dist/types/routes/universal-login/u2-routes.d.ts +6 -6
  35. package/dist/types/types/AuthHeroConfig.d.ts +0 -12
  36. package/dist/types/utils/jwks.d.ts +2 -2
  37. package/package.json +5 -4
@@ -540,8 +540,8 @@ export declare function passwordlessGrantUser(ctx: Context<{
540
540
  } | undefined;
541
541
  authenticated_at?: string | undefined;
542
542
  };
543
- connectionType: "sms" | "email" | "username";
544
- authConnection: "sms" | "email" | "username";
543
+ connectionType: "username" | "email" | "sms";
544
+ authConnection: "username" | "email" | "sms";
545
545
  session_id: string | undefined;
546
546
  authParams: {
547
547
  client_id: string;
@@ -0,0 +1,16 @@
1
+ import { CacheAdapter, DataAdapters } from "@authhero/adapter-interfaces";
2
+ /**
3
+ * Wraps a {@link DataAdapters} so that writes to bundle-covered entities
4
+ * purge the corresponding `client-bundle:{tenant_id}:{client_id}` cache
5
+ * entry — best-effort and local-edge only on Cloudflare's Cache API.
6
+ *
7
+ * Two write shapes:
8
+ * 1. Client-scoped writes (args = [tenant_id, client_id, ...]): purge the
9
+ * exact bundle key. Affects exactly one bundle.
10
+ * 2. Tenant-scoped writes (args = [tenant_id, ...]): attempt a prefix delete
11
+ * of `client-bundle:{tenant_id}:`. This is a no-op on Cloudflare Cache
12
+ * (which can't enumerate keys) but works on the in-memory adapter and
13
+ * on Redis-backed adapters. Tenant-scoped staleness is otherwise bounded
14
+ * by the bundle TTL.
15
+ */
16
+ export declare function addBundleWritePurge(data: DataAdapters, cache: CacheAdapter, keyPrefix?: string): DataAdapters;
@@ -0,0 +1,65 @@
1
+ import { CacheAdapter, Client, Connection, ClientWithTenantId, DataAdapters, ListConnectionsResponse, ListResourceServersResponse, ListHooksResponse, Branding, PromptSetting, Tenant, Theme } from "@authhero/adapter-interfaces";
2
+ /**
3
+ * One snapshot of every per-(tenant, client) read that the request path
4
+ * touches outside of user-specific data. Loaded once per request and held
5
+ * in a 5-minute SWR cache.
6
+ *
7
+ * Tenant-scoped lists (connections, resourceServers, hooks) are stored as
8
+ * their full default-list response so callers calling list(tenant_id) with
9
+ * no params get an identical shape from the bundle.
10
+ */
11
+ export interface ClientBundle {
12
+ tenant: Tenant | null;
13
+ client: Client | null;
14
+ connections: ListConnectionsResponse;
15
+ clientConnections: Connection[];
16
+ branding: Branding | null;
17
+ resourceServers: ListResourceServersResponse;
18
+ promptSettings: PromptSetting | null;
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;
25
+ }
26
+ export interface ClientBundleConfig {
27
+ /** Seconds the bundle is served without a refresh. Default 300. */
28
+ freshSeconds?: number;
29
+ /** Seconds the bundle may be served stale while a background refresh runs. Default 600 (so total lifetime = fresh + stale). */
30
+ staleSeconds?: number;
31
+ /** Cache key prefix (per-deployment isolation). Default "client-bundle". */
32
+ keyPrefix?: string;
33
+ }
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"];
44
+ /**
45
+ * Look up — and on miss, populate — the per-(tenant, client) bundle.
46
+ *
47
+ * SWR semantics:
48
+ * - now < freshUntil → return immediately
49
+ * - freshUntil ≤ now < staleUntil → return immediately, schedule a refresh
50
+ * via `scheduleRefresh` (typically wired to `ctx.executionCtx.waitUntil`)
51
+ * - now ≥ staleUntil OR no entry → fetch synchronously
52
+ *
53
+ * `data` should be the underlying adapter (i.e. with hooks but without the
54
+ * bundle wrapper). Passing the bundle-wrapped adapter would deadlock on
55
+ * itself, since bundle reads route back into this function.
56
+ */
57
+ export declare function loadClientBundle(data: DataAdapters, cache: CacheAdapter, tenantId: string, clientId: string, options?: {
58
+ config?: ClientBundleConfig;
59
+ /** Schedule a background promise. Provide `ctx.executionCtx.waitUntil.bind(ctx.executionCtx)` on Workers; otherwise omit and we'll skip the background refresh. */
60
+ scheduleRefresh?: (promise: Promise<unknown>) => void;
61
+ /** Override the "now" clock for testing. */
62
+ now?: () => number;
63
+ }): Promise<ClientBundle>;
64
+ /** Helper to extract the ClientWithTenantId shape from a bundle. */
65
+ export declare function bundleToClientWithTenantId(bundle: ClientBundle, tenantId: string): ClientWithTenantId | null;
@@ -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;
@@ -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
+ }>;
@@ -0,0 +1,8 @@
1
+ import { DataAdapters } from "@authhero/adapter-interfaces";
2
+ export interface RequestScopedDedupOptions {
3
+ /** Names of adapter entities to dedup. Entities outside this list pass through verbatim. Required — there is no safe default. */
4
+ dedupEntities: string[];
5
+ /** Shared Map for memoized Promises. Defaults to a fresh Map per call. */
6
+ dedup?: Map<string, Promise<unknown>>;
7
+ }
8
+ export declare function addRequestScopedDedup(data: DataAdapters, options: RequestScopedDedupOptions): DataAdapters;
@@ -0,0 +1,31 @@
1
+ import { Context } from "hono";
2
+ import { CacheAdapter, DataAdapters } from "@authhero/adapter-interfaces";
3
+ import { Bindings, Variables } from "../types";
4
+ import { ClientBundleConfig } from "./client-bundle";
5
+ type Ctx = Context<{
6
+ Bindings: Bindings;
7
+ Variables: Variables;
8
+ }>;
9
+ /**
10
+ * Route reads that match the request's (tenant_id, client_id) to a single
11
+ * cached {@link ClientBundle} instead of going entity-by-entity through the
12
+ * downstream cache. Calls with different tenants/clients, or with non-default
13
+ * pagination, fall through to {@link upstream}.
14
+ *
15
+ * The bundle is loaded lazily on the first matching read — `tenant_id` and
16
+ * `client_id` typically come from middleware and route entry, so by the time
17
+ * any bundle-covered method is hit they're set.
18
+ *
19
+ * Pass `upstream` (the layer below this wrapper) so bundle component fetches
20
+ * still benefit from request-scoped dedup / persistent cache / hooks.
21
+ */
22
+ export declare function withClientBundle(ctx: Ctx, upstream: DataAdapters, cache: CacheAdapter, options?: {
23
+ config?: ClientBundleConfig;
24
+ }): DataAdapters;
25
+ /**
26
+ * Best-effort purge of a (tenant_id, client_id) bundle entry from cache.
27
+ * On Cloudflare this only affects the local edge; entries on other colos
28
+ * will expire via TTL.
29
+ */
30
+ export declare function purgeClientBundle(cache: CacheAdapter, tenantId: string, clientId: string, keyPrefix?: string): Promise<void>;
31
+ export {};
@@ -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;