authhero 8.1.0 → 8.2.1

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 (36) hide show
  1. package/dist/authhero.cjs +215 -215
  2. package/dist/authhero.d.ts +111 -79
  3. package/dist/authhero.mjs +9829 -9731
  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/helpers/compose-auth-data.d.ts +9 -1
  11. package/dist/types/helpers/dcr/metadata-mapping.d.ts +1 -1
  12. package/dist/types/helpers/server-timing.d.ts +44 -2
  13. package/dist/types/index.d.ts +75 -75
  14. package/dist/types/middlewares/tenant.d.ts +11 -4
  15. package/dist/types/routes/auth-api/account.d.ts +2 -2
  16. package/dist/types/routes/auth-api/index.d.ts +6 -6
  17. package/dist/types/routes/auth-api/passwordless.d.ts +4 -4
  18. package/dist/types/routes/management-api/action-triggers.d.ts +1 -1
  19. package/dist/types/routes/management-api/client-grants.d.ts +8 -8
  20. package/dist/types/routes/management-api/email-templates.d.ts +18 -18
  21. package/dist/types/routes/management-api/flows.d.ts +7 -7
  22. package/dist/types/routes/management-api/guardian.d.ts +5 -5
  23. package/dist/types/routes/management-api/index.d.ts +63 -63
  24. package/dist/types/routes/management-api/log-streams.d.ts +6 -6
  25. package/dist/types/routes/management-api/logs.d.ts +3 -3
  26. package/dist/types/routes/management-api/migration-sources.d.ts +6 -6
  27. package/dist/types/routes/management-api/organizations.d.ts +3 -3
  28. package/dist/types/routes/management-api/prompts.d.ts +4 -4
  29. package/dist/types/routes/management-api/users.d.ts +2 -2
  30. package/dist/types/routes/universal-login/u2-index.d.ts +6 -6
  31. package/dist/types/routes/universal-login/u2-routes.d.ts +6 -6
  32. package/dist/types/types/Bindings.d.ts +21 -0
  33. package/dist/types/types/IdToken.d.ts +2 -2
  34. package/dist/types/types/Variables.d.ts +4 -0
  35. package/package.json +1 -1
  36. 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;
@@ -8,12 +8,20 @@ import { Bindings, Variables } from "../types";
8
8
  * between layers — in one place so individual apps can't drift.
9
9
  *
10
10
  * Layering (outermost first; that's the order callers hit on each read):
11
- * addTimingLogs — server-timing instrumentation
12
11
  * withClientBundle — L0: per-(tenant_id, client_id) snapshot
13
12
  * addBundleWritePurge — local-edge bundle invalidation on writes
14
13
  * addRequestScopedDedup — L1: in-request Promise memoization
15
14
  * addCaching — L2: cross-request cache (CF Cache API in prod)
16
15
  * addDataHooks — user lifecycle hooks
16
+ * addTimingLogs — server-timing instrumentation. Innermost on
17
+ * purpose: a read served by the bundle (L0), request
18
+ * dedup (L1), or cache (L2) is satisfied above this
19
+ * layer and never reaches it, so the Server-Timing
20
+ * header carries one line per genuine backend
21
+ * round-trip — with its true duration — instead of
22
+ * one line per surface call (cache/bundle hits
23
+ * included, the whole bundle's cost attributed to
24
+ * whichever call happened to trigger assembly).
17
25
  * raw dataAdapter — underlying DB
18
26
  *
19
27
  * Apps declare only their `nonBundleEntities` — the long-tail entities they
@@ -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>>;
@@ -1,6 +1,47 @@
1
- import { Context } from "hono";
2
- import { DataAdapters } from "@authhero/adapter-interfaces";
1
+ import { Context, MiddlewareHandler } from "hono";
2
+ import { CacheAdapter, DataAdapters } from "@authhero/adapter-interfaces";
3
3
  import { Bindings, Variables } from "../types";
4
+ type TimingCtx = Context<{
5
+ Bindings: Bindings;
6
+ Variables: Variables;
7
+ }>;
8
+ /**
9
+ * Record one Server-Timing measurement on the request-scoped buffer
10
+ * (`ctx.var.serverTiming`). The measurement is NOT written to the response
11
+ * header here — {@link serverTimingMiddleware} decides at the end of the
12
+ * request whether to emit it to the client, log it server-side, or drop it.
13
+ * Used by the adapter wrappers below and by the webhook hook.
14
+ */
15
+ export declare function recordServerTiming(ctx: TimingCtx, name: string, duration: number): void;
16
+ /**
17
+ * Flushes the request-scoped Server-Timing buffer according to the
18
+ * `SERVER_TIMING` env. Mount this right after `applyConfigMiddleware` so that
19
+ * env is populated before it runs and the client `ip` is resolved by the time
20
+ * `next()` returns.
21
+ *
22
+ * Sinks (see {@link Bindings.SERVER_TIMING}):
23
+ * - "off"/unset → drop the buffer (default; nothing reaches the client).
24
+ * - "client" → set the `Server-Timing` header, optionally gated to
25
+ * `SERVER_TIMING_IPS`.
26
+ * - "log" → emit a structured log line; never sent to the client.
27
+ * - "both" → both of the above.
28
+ *
29
+ * Off by default because per-operation timings on the public auth endpoints are
30
+ * a user-enumeration / side-channel surface.
31
+ */
32
+ export declare const serverTimingMiddleware: MiddlewareHandler<{
33
+ Bindings: Bindings;
34
+ Variables: Variables;
35
+ }>;
36
+ /**
37
+ * Wraps a {@link CacheAdapter} so each operation appends a Server-Timing entry
38
+ * labelled by the key's prefix, e.g. `cache-get:client-bundle`,
39
+ * `cache-get:customText`. The cache layers call this adapter directly — not
40
+ * through the timed data stack — so on Workers the Cache API `match()` / `put()`
41
+ * round-trips would otherwise be invisible. This makes that latency observable
42
+ * without exposing the full (id-bearing) cache key.
43
+ */
44
+ export declare function addCacheTimingLogs(ctx: TimingCtx, cache: CacheAdapter): CacheAdapter;
4
45
  /**
5
46
  * Adds server-timing middleware logging to all adapter methods
6
47
  * This wraps each method of the data adapter to measure its execution time
@@ -10,3 +51,4 @@ export declare function addTimingLogs(ctx: Context<{
10
51
  Bindings: Bindings;
11
52
  Variables: Variables;
12
53
  }>, data: DataAdapters): DataAdapters;
54
+ export {};