@aooth/auth 0.2.1 → 0.2.3

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/atscript-db.cjs +5 -7
  2. package/dist/atscript-db.d.cts +21 -25
  3. package/dist/atscript-db.d.mts +21 -25
  4. package/dist/atscript-db.mjs +5 -7
  5. package/dist/{auth-credential-CjCgZv7n.d.mts → auth-credential-46_eOF3c.d.cts} +1 -3
  6. package/dist/{auth-credential-UV3sJ-lt.d.cts → auth-credential-Co-0pqcD.d.mts} +1 -3
  7. package/dist/authz.cjs +21 -33
  8. package/dist/authz.d.cts +23 -45
  9. package/dist/authz.d.mts +23 -45
  10. package/dist/authz.mjs +21 -33
  11. package/dist/client.cjs +1 -2
  12. package/dist/client.d.cts +7 -10
  13. package/dist/client.d.mts +7 -10
  14. package/dist/client.mjs +1 -2
  15. package/dist/{clock-Bl-H3eqE.cjs → clock-BcBMqB9g.cjs} +1 -2
  16. package/dist/{clock-Bdsep_1j.mjs → clock-DzAK2bWR.mjs} +1 -2
  17. package/dist/{clock-CzAaCoZ5.d.cts → clock-hTHoZ2vA.d.cts} +0 -6
  18. package/dist/{clock-CzAaCoZ5.d.mts → clock-hTHoZ2vA.d.mts} +0 -6
  19. package/dist/{dynamic-client-store-DykM9QOT.cjs → dynamic-client-store-CC4qr_kz.cjs} +5 -8
  20. package/dist/{dynamic-client-store-B7EnHuRp.d.cts → dynamic-client-store-CTt1B6Gj.d.cts} +2 -10
  21. package/dist/{dynamic-client-store-B1JwFHdP.mjs → dynamic-client-store-DrMBcFtG.mjs} +5 -8
  22. package/dist/{dynamic-client-store-BifZLGkT.d.mts → dynamic-client-store-mYg0nRJU.d.mts} +2 -10
  23. package/dist/index.cjs +31 -26
  24. package/dist/index.d.cts +49 -40
  25. package/dist/index.d.mts +49 -40
  26. package/dist/index.mjs +31 -27
  27. package/dist/{opaque-token-BaMOrC1A.mjs → opaque-token-BLoQKkZ3.mjs} +1 -2
  28. package/dist/{opaque-token-CaZgD2i6.cjs → opaque-token-BLuVHSVJ.cjs} +1 -2
  29. package/dist/{payload-C1cQW7p_.cjs → payload-CqQH88C6.cjs} +2 -4
  30. package/dist/{payload-DDlf38B-.mjs → payload-DizkKbzh.mjs} +2 -4
  31. package/dist/redis.cjs +1 -2
  32. package/dist/redis.d.cts +7 -9
  33. package/dist/redis.d.mts +7 -9
  34. package/dist/redis.mjs +1 -2
  35. package/dist/{store-BaFYDHxn.d.cts → store-BXxX8sUP.d.mts} +1 -3
  36. package/dist/{store-h-bLOAaS.d.mts → store-D9CcbcBp.d.cts} +1 -3
  37. package/package.json +10 -10
package/dist/client.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- //#region src/client/index.d.ts
2
1
  /** Minimal structural view of a fetch `Response` this helper reads. The DOM `Response` satisfies it. */
3
- interface MinimalResponse {
2
+ export interface MinimalResponse {
4
3
  readonly ok: boolean;
5
4
  readonly status: number;
6
5
  }
@@ -9,7 +8,7 @@ interface MinimalResponse {
9
8
  * (and Node's) is assignable to it: fields the helper never inspects are typed
10
9
  * `unknown` so `Headers` instances, `AbortSignal`s and any body type pass through.
11
10
  */
12
- interface MinimalRequestInit {
11
+ export interface MinimalRequestInit {
13
12
  method?: string;
14
13
  headers?: unknown;
15
14
  body?: unknown;
@@ -32,7 +31,7 @@ interface MinimalRequestInit {
32
31
  * Declared method-style so its parameters are compared bivariantly — the DOM
33
32
  * `fetch`'s wider `RequestInfo` / `RequestInit` parameters still match.
34
33
  */
35
- type FetchFn = {
34
+ export type FetchFn = {
36
35
  fetch(input: string | URL, init?: MinimalRequestInit): Promise<MinimalResponse>;
37
36
  }["fetch"];
38
37
  /**
@@ -42,7 +41,7 @@ type FetchFn = {
42
41
  * `@aooth/auth/client` free of a hard DOM-lib dependency while preserving great
43
42
  * DX in browser projects.
44
43
  */
45
- type DefaultFetch = typeof globalThis extends {
44
+ export type DefaultFetch = typeof globalThis extends {
46
45
  fetch: infer F extends FetchFn;
47
46
  } ? F : FetchFn;
48
47
  /**
@@ -50,11 +49,11 @@ type DefaultFetch = typeof globalThis extends {
50
49
  * answered; `error` is the thrown value when the request itself failed
51
50
  * (offline, aborted, DNS, CORS).
52
51
  */
53
- interface AuthedFetchRefreshFailure {
52
+ export interface AuthedFetchRefreshFailure {
54
53
  status?: number;
55
54
  error?: unknown;
56
55
  }
57
- interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
56
+ export interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
58
57
  /** Refresh endpoint path or URL. Default `'/auth/refresh'`. Match your `AuthController` mount. */
59
58
  refreshPath?: string;
60
59
  /**
@@ -105,6 +104,4 @@ interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
105
104
  * const res = await api('/api/me') // 401 → silent refresh → retried once
106
105
  * ```
107
106
  */
108
- declare function createAuthedFetch<TFetch extends FetchFn = DefaultFetch>(options?: CreateAuthedFetchOptions<TFetch>): TFetch;
109
- //#endregion
110
- export { AuthedFetchRefreshFailure, CreateAuthedFetchOptions, DefaultFetch, FetchFn, MinimalRequestInit, MinimalResponse, createAuthedFetch };
107
+ export declare function createAuthedFetch<TFetch extends FetchFn = DefaultFetch>(options?: CreateAuthedFetchOptions<TFetch>): TFetch;
package/dist/client.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- //#region src/client/index.d.ts
2
1
  /** Minimal structural view of a fetch `Response` this helper reads. The DOM `Response` satisfies it. */
3
- interface MinimalResponse {
2
+ export interface MinimalResponse {
4
3
  readonly ok: boolean;
5
4
  readonly status: number;
6
5
  }
@@ -9,7 +8,7 @@ interface MinimalResponse {
9
8
  * (and Node's) is assignable to it: fields the helper never inspects are typed
10
9
  * `unknown` so `Headers` instances, `AbortSignal`s and any body type pass through.
11
10
  */
12
- interface MinimalRequestInit {
11
+ export interface MinimalRequestInit {
13
12
  method?: string;
14
13
  headers?: unknown;
15
14
  body?: unknown;
@@ -32,7 +31,7 @@ interface MinimalRequestInit {
32
31
  * Declared method-style so its parameters are compared bivariantly — the DOM
33
32
  * `fetch`'s wider `RequestInfo` / `RequestInit` parameters still match.
34
33
  */
35
- type FetchFn = {
34
+ export type FetchFn = {
36
35
  fetch(input: string | URL, init?: MinimalRequestInit): Promise<MinimalResponse>;
37
36
  }["fetch"];
38
37
  /**
@@ -42,7 +41,7 @@ type FetchFn = {
42
41
  * `@aooth/auth/client` free of a hard DOM-lib dependency while preserving great
43
42
  * DX in browser projects.
44
43
  */
45
- type DefaultFetch = typeof globalThis extends {
44
+ export type DefaultFetch = typeof globalThis extends {
46
45
  fetch: infer F extends FetchFn;
47
46
  } ? F : FetchFn;
48
47
  /**
@@ -50,11 +49,11 @@ type DefaultFetch = typeof globalThis extends {
50
49
  * answered; `error` is the thrown value when the request itself failed
51
50
  * (offline, aborted, DNS, CORS).
52
51
  */
53
- interface AuthedFetchRefreshFailure {
52
+ export interface AuthedFetchRefreshFailure {
54
53
  status?: number;
55
54
  error?: unknown;
56
55
  }
57
- interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
56
+ export interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
58
57
  /** Refresh endpoint path or URL. Default `'/auth/refresh'`. Match your `AuthController` mount. */
59
58
  refreshPath?: string;
60
59
  /**
@@ -105,6 +104,4 @@ interface CreateAuthedFetchOptions<TFetch extends FetchFn = DefaultFetch> {
105
104
  * const res = await api('/api/me') // 401 → silent refresh → retried once
106
105
  * ```
107
106
  */
108
- declare function createAuthedFetch<TFetch extends FetchFn = DefaultFetch>(options?: CreateAuthedFetchOptions<TFetch>): TFetch;
109
- //#endregion
110
- export { AuthedFetchRefreshFailure, CreateAuthedFetchOptions, DefaultFetch, FetchFn, MinimalRequestInit, MinimalResponse, createAuthedFetch };
107
+ export declare function createAuthedFetch<TFetch extends FetchFn = DefaultFetch>(options?: CreateAuthedFetchOptions<TFetch>): TFetch;
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/client/index.ts
1
+ // src/client/index.ts
2
2
  /**
3
3
  * Wraps `fetch` with cookie-session silent refresh. Every call forwards
4
4
  * credentials; a response whose status is in `refreshOn` (401 by default)
@@ -67,5 +67,4 @@ function createAuthedFetch(options = {}) {
67
67
  };
68
68
  return authedFetch;
69
69
  }
70
- //#endregion
71
70
  export { createAuthedFetch };
@@ -1,6 +1,5 @@
1
- //#region src/utils/clock.ts
1
+ // src/utils/clock.ts
2
2
  const defaultClock = { now: () => Date.now() };
3
- //#endregion
4
3
  Object.defineProperty(exports, "defaultClock", {
5
4
  enumerable: true,
6
5
  get: function() {
@@ -1,4 +1,3 @@
1
- //#region src/utils/clock.ts
1
+ // src/utils/clock.ts
2
2
  const defaultClock = { now: () => Date.now() };
3
- //#endregion
4
3
  export { defaultClock as t };
@@ -1,4 +1,3 @@
1
- //#region src/credential/types.d.ts
2
1
  /**
3
2
  * The read-time envelope a successful auth check always produces — the fixed
4
3
  * fields, before the credential's typed payload is merged in. See
@@ -284,8 +283,6 @@ interface RefreshConfig {
284
283
  */
285
284
  onRotationGraceHit?: (state: CredentialState) => void;
286
285
  }
287
- //#endregion
288
- //#region src/stores/store.d.ts
289
286
  /**
290
287
  * Pluggable credential storage. Implementations: Memory, JWT, Encapsulated.
291
288
  * Same shape works for stateful and stateless stores. Stateless stores treat
@@ -358,8 +355,6 @@ interface DenylistStore {
358
355
  has(jti: string): Promise<boolean>;
359
356
  cleanup(): Promise<number>;
360
357
  }
361
- //#endregion
362
- //#region src/utils/clock.d.ts
363
358
  /**
364
359
  * Minimal time abstraction shared across stores and orchestrators.
365
360
  *
@@ -371,5 +366,4 @@ interface Clock {
371
366
  now(): number;
372
367
  }
373
368
  declare const defaultClock: Clock;
374
- //#endregion
375
369
  export { AuthContext as a, CredentialSuccessorRef as c, RefreshConfig as d, RefreshResult as f, DenylistStore as i, EnrichedSession as l, SessionInfo as m, defaultClock as n, CredentialMetadata as o, SessionEnricher as p, CredentialStore as r, CredentialState as s, Clock as t, IssueResult as u };
@@ -1,4 +1,3 @@
1
- //#region src/credential/types.d.ts
2
1
  /**
3
2
  * The read-time envelope a successful auth check always produces — the fixed
4
3
  * fields, before the credential's typed payload is merged in. See
@@ -284,8 +283,6 @@ interface RefreshConfig {
284
283
  */
285
284
  onRotationGraceHit?: (state: CredentialState) => void;
286
285
  }
287
- //#endregion
288
- //#region src/stores/store.d.ts
289
286
  /**
290
287
  * Pluggable credential storage. Implementations: Memory, JWT, Encapsulated.
291
288
  * Same shape works for stateful and stateless stores. Stateless stores treat
@@ -358,8 +355,6 @@ interface DenylistStore {
358
355
  has(jti: string): Promise<boolean>;
359
356
  cleanup(): Promise<number>;
360
357
  }
361
- //#endregion
362
- //#region src/utils/clock.d.ts
363
358
  /**
364
359
  * Minimal time abstraction shared across stores and orchestrators.
365
360
  *
@@ -371,5 +366,4 @@ interface Clock {
371
366
  now(): number;
372
367
  }
373
368
  declare const defaultClock: Clock;
374
- //#endregion
375
369
  export { AuthContext as a, CredentialSuccessorRef as c, RefreshConfig as d, RefreshResult as f, DenylistStore as i, EnrichedSession as l, SessionInfo as m, defaultClock as n, CredentialMetadata as o, SessionEnricher as p, CredentialStore as r, CredentialState as s, Clock as t, IssueResult as u };
@@ -1,6 +1,6 @@
1
- const require_clock = require("./clock-Bl-H3eqE.cjs");
1
+ const require_clock = require("./clock-BcBMqB9g.cjs");
2
2
  let node_crypto = require("node:crypto");
3
- //#region src/authz/pending-authorization-store.ts
3
+ // src/authz/pending-authorization-store.ts
4
4
  /**
5
5
  * Storage seam for in-flight authorizations (AUTH-SERVER.md §4.3). Short-lived
6
6
  * (≈ the login-session ceiling): created at `/authorize`, read+deleted at the
@@ -10,7 +10,7 @@ let node_crypto = require("node:crypto");
10
10
  */
11
11
  var PendingAuthorizationStore = class {};
12
12
  /** Default pending-authorization lifetime (15 min). Shared by the memory + atscript-db stores. */
13
- const DEFAULT_PENDING_TTL_MS = 15 * 6e4;
13
+ const DEFAULT_PENDING_TTL_MS = 9e5;
14
14
  /**
15
15
  * In-memory {@link PendingAuthorizationStore} — the reference impl for a
16
16
  * single-process app + tests. `structuredClone` on read/write isolates callers.
@@ -63,8 +63,7 @@ var PendingAuthorizationStoreMemory = class extends PendingAuthorizationStore {
63
63
  return this.store.delete(handle);
64
64
  }
65
65
  };
66
- //#endregion
67
- //#region src/authz/auth-code-store.ts
66
+ // src/authz/auth-code-store.ts
68
67
  /**
69
68
  * Storage seam for issued authorization codes (AUTH-SERVER.md §4.3). Very
70
69
  * short-lived (≈ 30–60 s) and **single-use**: {@link consume} returns the row
@@ -119,8 +118,7 @@ var AuthCodeStoreMemory = class extends AuthCodeStore {
119
118
  return structuredClone(row);
120
119
  }
121
120
  };
122
- //#endregion
123
- //#region src/authz/dynamic-client-store.ts
121
+ // src/authz/dynamic-client-store.ts
124
122
  /**
125
123
  * Storage seam for dynamically-registered clients (OAUTH.md R2). Long-lived
126
124
  * (unlike the pending-auth / auth-code stores): a connector caches its
@@ -179,7 +177,6 @@ var DynamicClientStoreMemory = class extends DynamicClientStore {
179
177
  return removed;
180
178
  }
181
179
  };
182
- //#endregion
183
180
  Object.defineProperty(exports, "AuthCodeStore", {
184
181
  enumerable: true,
185
182
  get: function() {
@@ -1,6 +1,5 @@
1
- import { t as Clock } from "./clock-CzAaCoZ5.cjs";
2
- import { r as IssueOptions } from "./auth-credential-UV3sJ-lt.cjs";
3
- //#region src/authz/token-policy.d.ts
1
+ import { t as Clock } from "./clock-hTHoZ2vA.cjs";
2
+ import { r as IssueOptions } from "./auth-credential-46_eOF3c.cjs";
4
3
  /**
5
4
  * What the authorization server mints for a completed grant — forwarded verbatim
6
5
  * into `AuthCredential.issue(userId, …)` at the token endpoint. Decided by the
@@ -69,8 +68,6 @@ declare const DEFAULT_AUTHZ_REFRESH_TTL_MS: number;
69
68
  * its default ttl, so every HTTP adapter applies the same semantics.
70
69
  */
71
70
  declare function tokenPolicyToIssueOptions(policy: TokenPolicy, clientId: string | undefined): IssueOptions;
72
- //#endregion
73
- //#region src/authz/pending-authorization-store.d.ts
74
71
  /**
75
72
  * One in-flight authorization request, recorded at `GET /auth/authorize` and
76
73
  * read once at the login-workflow terminal that mints the auth code. Keyed by an
@@ -190,8 +187,6 @@ declare class PendingAuthorizationStoreMemory extends PendingAuthorizationStore
190
187
  get(handle: string): Promise<PendingAuthorization | null>;
191
188
  delete(handle: string): Promise<boolean>;
192
189
  }
193
- //#endregion
194
- //#region src/authz/auth-code-store.d.ts
195
190
  /**
196
191
  * A minted, single-use authorization code, bound to the user the login resolved
197
192
  * plus the PKCE challenge / redirect / token policy recorded at `/authorize`.
@@ -281,8 +276,6 @@ declare class AuthCodeStoreMemory extends AuthCodeStore {
281
276
  }>;
282
277
  consume(code: string): Promise<AuthCode | null>;
283
278
  }
284
- //#endregion
285
- //#region src/authz/dynamic-client-store.d.ts
286
279
  /** Token-endpoint auth methods a dynamic client may register with. */
287
280
  type DynamicClientAuthMethod = "none" | "client_secret_post";
288
281
  /**
@@ -384,5 +377,4 @@ declare class DynamicClientStoreMemory extends DynamicClientStore {
384
377
  touch(clientId: string, at: number): Promise<void>;
385
378
  deleteUnusedBefore(cutoff: number): Promise<number>;
386
379
  }
387
- //#endregion
388
380
  export { PendingAuthorizationStoreMemoryOptions as _, DynamicClientStoreMemoryOptions as a, tokenPolicyToIssueOptions as b, AuthCodeStore as c, NewAuthCode as d, DEFAULT_PENDING_TTL_MS as f, PendingAuthorizationStoreMemory as g, PendingAuthorizationStore as h, DynamicClientStoreMemory as i, AuthCodeStoreMemory as l, PendingAuthorization as m, DynamicClientAuthMethod as n, NewDynamicClient as o, NewPendingAuthorization as p, DynamicClientStore as r, AuthCode as s, DynamicClient as t, AuthCodeStoreMemoryOptions as u, DEFAULT_AUTHZ_REFRESH_TTL_MS as v, TokenPolicy as y };
@@ -1,6 +1,6 @@
1
- import { t as defaultClock } from "./clock-Bdsep_1j.mjs";
1
+ import { t as defaultClock } from "./clock-DzAK2bWR.mjs";
2
2
  import { randomUUID } from "node:crypto";
3
- //#region src/authz/pending-authorization-store.ts
3
+ // src/authz/pending-authorization-store.ts
4
4
  /**
5
5
  * Storage seam for in-flight authorizations (AUTH-SERVER.md §4.3). Short-lived
6
6
  * (≈ the login-session ceiling): created at `/authorize`, read+deleted at the
@@ -10,7 +10,7 @@ import { randomUUID } from "node:crypto";
10
10
  */
11
11
  var PendingAuthorizationStore = class {};
12
12
  /** Default pending-authorization lifetime (15 min). Shared by the memory + atscript-db stores. */
13
- const DEFAULT_PENDING_TTL_MS = 15 * 6e4;
13
+ const DEFAULT_PENDING_TTL_MS = 9e5;
14
14
  /**
15
15
  * In-memory {@link PendingAuthorizationStore} — the reference impl for a
16
16
  * single-process app + tests. `structuredClone` on read/write isolates callers.
@@ -63,8 +63,7 @@ var PendingAuthorizationStoreMemory = class extends PendingAuthorizationStore {
63
63
  return this.store.delete(handle);
64
64
  }
65
65
  };
66
- //#endregion
67
- //#region src/authz/auth-code-store.ts
66
+ // src/authz/auth-code-store.ts
68
67
  /**
69
68
  * Storage seam for issued authorization codes (AUTH-SERVER.md §4.3). Very
70
69
  * short-lived (≈ 30–60 s) and **single-use**: {@link consume} returns the row
@@ -119,8 +118,7 @@ var AuthCodeStoreMemory = class extends AuthCodeStore {
119
118
  return structuredClone(row);
120
119
  }
121
120
  };
122
- //#endregion
123
- //#region src/authz/dynamic-client-store.ts
121
+ // src/authz/dynamic-client-store.ts
124
122
  /**
125
123
  * Storage seam for dynamically-registered clients (OAUTH.md R2). Long-lived
126
124
  * (unlike the pending-auth / auth-code stores): a connector caches its
@@ -179,5 +177,4 @@ var DynamicClientStoreMemory = class extends DynamicClientStore {
179
177
  return removed;
180
178
  }
181
179
  };
182
- //#endregion
183
180
  export { DEFAULT_CODE_TTL_MS as a, PendingAuthorizationStoreMemory as c, AuthCodeStoreMemory as i, DynamicClientStoreMemory as n, DEFAULT_PENDING_TTL_MS as o, AuthCodeStore as r, PendingAuthorizationStore as s, DynamicClientStore as t };
@@ -1,6 +1,5 @@
1
- import { t as Clock } from "./clock-CzAaCoZ5.mjs";
2
- import { r as IssueOptions } from "./auth-credential-CjCgZv7n.mjs";
3
- //#region src/authz/token-policy.d.ts
1
+ import { t as Clock } from "./clock-hTHoZ2vA.mjs";
2
+ import { r as IssueOptions } from "./auth-credential-Co-0pqcD.mjs";
4
3
  /**
5
4
  * What the authorization server mints for a completed grant — forwarded verbatim
6
5
  * into `AuthCredential.issue(userId, …)` at the token endpoint. Decided by the
@@ -69,8 +68,6 @@ declare const DEFAULT_AUTHZ_REFRESH_TTL_MS: number;
69
68
  * its default ttl, so every HTTP adapter applies the same semantics.
70
69
  */
71
70
  declare function tokenPolicyToIssueOptions(policy: TokenPolicy, clientId: string | undefined): IssueOptions;
72
- //#endregion
73
- //#region src/authz/pending-authorization-store.d.ts
74
71
  /**
75
72
  * One in-flight authorization request, recorded at `GET /auth/authorize` and
76
73
  * read once at the login-workflow terminal that mints the auth code. Keyed by an
@@ -190,8 +187,6 @@ declare class PendingAuthorizationStoreMemory extends PendingAuthorizationStore
190
187
  get(handle: string): Promise<PendingAuthorization | null>;
191
188
  delete(handle: string): Promise<boolean>;
192
189
  }
193
- //#endregion
194
- //#region src/authz/auth-code-store.d.ts
195
190
  /**
196
191
  * A minted, single-use authorization code, bound to the user the login resolved
197
192
  * plus the PKCE challenge / redirect / token policy recorded at `/authorize`.
@@ -281,8 +276,6 @@ declare class AuthCodeStoreMemory extends AuthCodeStore {
281
276
  }>;
282
277
  consume(code: string): Promise<AuthCode | null>;
283
278
  }
284
- //#endregion
285
- //#region src/authz/dynamic-client-store.d.ts
286
279
  /** Token-endpoint auth methods a dynamic client may register with. */
287
280
  type DynamicClientAuthMethod = "none" | "client_secret_post";
288
281
  /**
@@ -384,5 +377,4 @@ declare class DynamicClientStoreMemory extends DynamicClientStore {
384
377
  touch(clientId: string, at: number): Promise<void>;
385
378
  deleteUnusedBefore(cutoff: number): Promise<number>;
386
379
  }
387
- //#endregion
388
380
  export { PendingAuthorizationStoreMemoryOptions as _, DynamicClientStoreMemoryOptions as a, tokenPolicyToIssueOptions as b, AuthCodeStore as c, NewAuthCode as d, DEFAULT_PENDING_TTL_MS as f, PendingAuthorizationStoreMemory as g, PendingAuthorizationStore as h, DynamicClientStoreMemory as i, AuthCodeStoreMemory as l, PendingAuthorization as m, DynamicClientAuthMethod as n, NewDynamicClient as o, NewPendingAuthorization as p, DynamicClientStore as r, AuthCode as s, DynamicClient as t, AuthCodeStoreMemoryOptions as u, DEFAULT_AUTHZ_REFRESH_TTL_MS as v, TokenPolicy as y };
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_payload = require("./payload-C1cQW7p_.cjs");
3
- const require_clock = require("./clock-Bl-H3eqE.cjs");
4
- const require_opaque_token = require("./opaque-token-CaZgD2i6.cjs");
2
+ const require_payload = require("./payload-CqQH88C6.cjs");
3
+ const require_clock = require("./clock-BcBMqB9g.cjs");
4
+ const require_opaque_token = require("./opaque-token-BLuVHSVJ.cjs");
5
5
  let node_crypto = require("node:crypto");
6
6
  let jose = require("jose");
7
- //#region src/stores/memory.ts
7
+ // src/stores/memory.ts
8
8
  /**
9
9
  * In-memory implementation of CredentialStore using random opaque token IDs.
10
10
  *
@@ -119,8 +119,7 @@ var CredentialStoreMemory = class {
119
119
  if (set.size === 0) this.byUser.delete(userId);
120
120
  }
121
121
  };
122
- //#endregion
123
- //#region src/stores/denylist-memory.ts
122
+ // src/stores/denylist-memory.ts
124
123
  /**
125
124
  * In-memory denylist for stateless revocation.
126
125
  *
@@ -168,15 +167,13 @@ var DenylistStoreMemory = class {
168
167
  };
169
168
  /** Smallest map size an amortized expiry sweep runs at. */
170
169
  const MIN_SWEEP_SIZE$2 = 1024;
171
- //#endregion
172
- //#region src/stores/derive-subkey.ts
170
+ // src/stores/derive-subkey.ts
173
171
  const SUBKEY_SALT = Buffer.from("aooth/credential-store/subkey-v1");
174
172
  /** HKDF-SHA256 a stable 32-byte subkey from symmetric key material + a label. */
175
173
  function hkdfSubkey(ikm, label) {
176
174
  return Buffer.from((0, node_crypto.hkdfSync)("sha256", ikm, SUBKEY_SALT, Buffer.from(label, "utf8"), 32));
177
175
  }
178
- //#endregion
179
- //#region src/stores/jwt.ts
176
+ // src/stores/jwt.ts
180
177
  const HS_ALGS = /* @__PURE__ */ new Set([
181
178
  "HS256",
182
179
  "HS384",
@@ -360,8 +357,7 @@ function normalizeSecret(secret) {
360
357
  if (typeof secret === "string") return new TextEncoder().encode(secret);
361
358
  return secret;
362
359
  }
363
- //#endregion
364
- //#region src/stores/encapsulated.ts
360
+ // src/stores/encapsulated.ts
365
361
  const KEY_LEN = 32;
366
362
  const IV_LEN = 12;
367
363
  const TAG_LEN = 16;
@@ -510,9 +506,8 @@ function stripJti(payload) {
510
506
  const { jti: _jti, ...rest } = payload;
511
507
  return rest;
512
508
  }
513
- //#endregion
514
- //#region src/credential/auth-credential.ts
515
- const DEFAULT_ACCESS_TTL = 3600 * 1e3;
509
+ // src/credential/auth-credential.ts
510
+ const DEFAULT_ACCESS_TTL = 36e5;
516
511
  const DEFAULT_ROTATION_GRACE_MS = 3e4;
517
512
  /**
518
513
  * Upper bound on list-then-delete passes in one revocation. Two is the norm;
@@ -1283,9 +1278,15 @@ var AuthCredential = class {
1283
1278
  });
1284
1279
  }
1285
1280
  };
1286
- //#endregion
1287
- //#region src/rate-limit/rules.ts
1288
- const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests. Please try again in {{delta}}.";
1281
+ // src/rate-limit/rules.ts
1282
+ /**
1283
+ * Default English message template per rate-limit code. The 429 body carries
1284
+ * the `code` and its {@link RateLimitParams}, so a client or a server-side
1285
+ * error-body hook can translate the rejection without parsing this text.
1286
+ */
1287
+ const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests. Please try again in {{delta}}." };
1288
+ /** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
1289
+ const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
1289
1290
  const DURATION_UNITS = {
1290
1291
  ms: 1,
1291
1292
  s: 1e3,
@@ -1361,8 +1362,7 @@ function parseRateLimitRule(input) {
1361
1362
  function renderRateLimitMessage(template, rule, retryAfterMs) {
1362
1363
  return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
1363
1364
  }
1364
- //#endregion
1365
- //#region src/rate-limit/store.ts
1365
+ // src/rate-limit/store.ts
1366
1366
  /**
1367
1367
  * In-memory `RateLimitStore` — the zero-config default (single process only).
1368
1368
  * Lazy-evicts expired counters on access, and sweeps expired counters itself
@@ -1466,8 +1466,7 @@ var RateLimitStoreMemory = class {
1466
1466
  };
1467
1467
  /** Smallest map size an amortized expiry sweep runs at. */
1468
1468
  const MIN_SWEEP_SIZE = 1024;
1469
- //#endregion
1470
- //#region src/rate-limit/rate-limiter.ts
1469
+ // src/rate-limit/rate-limiter.ts
1471
1470
  /**
1472
1471
  * Fixed-window rate limiter with window-aligned keys (RL.spec.md §4.2).
1473
1472
  *
@@ -1546,18 +1545,23 @@ var RateLimiter = class {
1546
1545
  policies: parsed,
1547
1546
  ...rejected && {
1548
1547
  retryAfterMs: resetAfterMs,
1549
- message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? "Too many requests. Please try again in {{delta}}.", governing.rule, resetAfterMs)
1548
+ code: "RATE_LIMITED",
1549
+ params: {
1550
+ policy: scope,
1551
+ limit: governing.rule.limit,
1552
+ window: governing.rule.window / 1e3,
1553
+ retryAfter: Math.ceil(resetAfterMs / 1e3)
1554
+ },
1555
+ message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
1550
1556
  }
1551
1557
  };
1552
1558
  }
1553
1559
  };
1554
- //#endregion
1555
- //#region src/magic-link.ts
1560
+ // src/magic-link.ts
1556
1561
  /** A magic-link token is a plain {@link generateOpaqueToken} mint. */
1557
1562
  function generateMagicLinkToken() {
1558
1563
  return require_opaque_token.generateOpaqueToken();
1559
1564
  }
1560
- //#endregion
1561
1565
  exports.AuthCredential = AuthCredential;
1562
1566
  exports.AuthError = require_payload.AuthError;
1563
1567
  exports.CredentialStoreEncapsulated = CredentialStoreEncapsulated;
@@ -1565,6 +1569,7 @@ exports.CredentialStoreJwt = CredentialStoreJwt;
1565
1569
  exports.CredentialStoreMemory = CredentialStoreMemory;
1566
1570
  exports.DEFAULT_RATE_LIMIT_MESSAGE = DEFAULT_RATE_LIMIT_MESSAGE;
1567
1571
  exports.DenylistStoreMemory = DenylistStoreMemory;
1572
+ exports.RATE_LIMIT_MESSAGES = RATE_LIMIT_MESSAGES;
1568
1573
  exports.RateLimitStoreMemory = RateLimitStoreMemory;
1569
1574
  exports.RateLimiter = RateLimiter;
1570
1575
  exports.defaultClock = require_clock.defaultClock;