@aooth/auth 0.2.1 → 0.2.2

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 +14 -24
  24. package/dist/index.d.cts +18 -40
  25. package/dist/index.d.mts +18 -40
  26. package/dist/index.mjs +14 -24
  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 +9 -9
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,8 +1278,7 @@ var AuthCredential = class {
1283
1278
  });
1284
1279
  }
1285
1280
  };
1286
- //#endregion
1287
- //#region src/rate-limit/rules.ts
1281
+ // src/rate-limit/rules.ts
1288
1282
  const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests. Please try again in {{delta}}.";
1289
1283
  const DURATION_UNITS = {
1290
1284
  ms: 1,
@@ -1361,8 +1355,7 @@ function parseRateLimitRule(input) {
1361
1355
  function renderRateLimitMessage(template, rule, retryAfterMs) {
1362
1356
  return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
1363
1357
  }
1364
- //#endregion
1365
- //#region src/rate-limit/store.ts
1358
+ // src/rate-limit/store.ts
1366
1359
  /**
1367
1360
  * In-memory `RateLimitStore` — the zero-config default (single process only).
1368
1361
  * Lazy-evicts expired counters on access, and sweeps expired counters itself
@@ -1466,8 +1459,7 @@ var RateLimitStoreMemory = class {
1466
1459
  };
1467
1460
  /** Smallest map size an amortized expiry sweep runs at. */
1468
1461
  const MIN_SWEEP_SIZE = 1024;
1469
- //#endregion
1470
- //#region src/rate-limit/rate-limiter.ts
1462
+ // src/rate-limit/rate-limiter.ts
1471
1463
  /**
1472
1464
  * Fixed-window rate limiter with window-aligned keys (RL.spec.md §4.2).
1473
1465
  *
@@ -1551,13 +1543,11 @@ var RateLimiter = class {
1551
1543
  };
1552
1544
  }
1553
1545
  };
1554
- //#endregion
1555
- //#region src/magic-link.ts
1546
+ // src/magic-link.ts
1556
1547
  /** A magic-link token is a plain {@link generateOpaqueToken} mint. */
1557
1548
  function generateMagicLinkToken() {
1558
1549
  return require_opaque_token.generateOpaqueToken();
1559
1550
  }
1560
- //#endregion
1561
1551
  exports.AuthCredential = AuthCredential;
1562
1552
  exports.AuthError = require_payload.AuthError;
1563
1553
  exports.CredentialStoreEncapsulated = CredentialStoreEncapsulated;
package/dist/index.d.cts CHANGED
@@ -1,17 +1,14 @@
1
- import { a as AuthContext, d as RefreshConfig, f as RefreshResult, i as DenylistStore, l as EnrichedSession, m as SessionInfo, n as defaultClock, o as CredentialMetadata, p as SessionEnricher, r as CredentialStore, s as CredentialState, t as Clock, u as IssueResult } from "./clock-CzAaCoZ5.cjs";
2
- import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-UV3sJ-lt.cjs";
3
- import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-BaFYDHxn.cjs";
1
+ import { a as AuthContext, d as RefreshConfig, f as RefreshResult, i as DenylistStore, l as EnrichedSession, m as SessionInfo, n as defaultClock, o as CredentialMetadata, p as SessionEnricher, r as CredentialStore, s as CredentialState, t as Clock, u as IssueResult } from "./clock-hTHoZ2vA.cjs";
2
+ import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-46_eOF3c.cjs";
3
+ import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-D9CcbcBp.cjs";
4
4
  import { CryptoKey } from "jose";
5
- //#region src/errors.d.ts
6
5
  type AuthErrorType = "INVALID_TOKEN" | "TOKEN_EXPIRED" | "TOKEN_REVOKED" | "REFRESH_REUSE_DETECTED" | "STATELESS_OPERATION_UNSUPPORTED" | "MAX_CONCURRENT_REACHED" | "INVALID_CONFIG";
7
- declare class AuthError extends Error {
6
+ export declare class AuthError extends Error {
8
7
  readonly type: AuthErrorType;
9
8
  readonly details?: Record<string, unknown> | undefined;
10
9
  readonly name = "AuthError";
11
10
  constructor(type: AuthErrorType, message?: string, details?: Record<string, unknown> | undefined);
12
11
  }
13
- //#endregion
14
- //#region src/stores/memory.d.ts
15
12
  /**
16
13
  * In-memory implementation of CredentialStore using random opaque token IDs.
17
14
  *
@@ -20,7 +17,7 @@ declare class AuthError extends Error {
20
17
  * `listForUser` without scanning the full primary map.
21
18
  * - Both maps are kept in sync on every mutation.
22
19
  */
23
- declare class CredentialStoreMemory<TPayload extends object = object> implements CredentialStore<TPayload> {
20
+ export declare class CredentialStoreMemory<TPayload extends object = object> implements CredentialStore<TPayload> {
24
21
  private readonly states;
25
22
  private readonly byUser;
26
23
  private readonly clock;
@@ -41,8 +38,6 @@ declare class CredentialStoreMemory<TPayload extends object = object> implements
41
38
  private indexAdd;
42
39
  private indexRemove;
43
40
  }
44
- //#endregion
45
- //#region src/stores/denylist-memory.d.ts
46
41
  /**
47
42
  * In-memory denylist for stateless revocation.
48
43
  *
@@ -52,7 +47,7 @@ declare class CredentialStoreMemory<TPayload extends object = object> implements
52
47
  * doubles). `cleanup` performs a sweep on demand and returns the number of
53
48
  * entries removed.
54
49
  */
55
- declare class DenylistStoreMemory implements DenylistStore {
50
+ export declare class DenylistStoreMemory implements DenylistStore {
56
51
  private readonly entries;
57
52
  private readonly clock;
58
53
  /** Map size at which `add` next sweeps expired entries (amortized; doubles). */
@@ -65,8 +60,6 @@ declare class DenylistStoreMemory implements DenylistStore {
65
60
  cleanup(): Promise<number>;
66
61
  private sweep;
67
62
  }
68
- //#endregion
69
- //#region src/stores/jwt.d.ts
70
63
  /**
71
64
  * Supported JWT signing algorithms.
72
65
  * - HS256/HS384/HS512: symmetric (shared secret).
@@ -99,7 +92,7 @@ interface CredentialStoreJwtOptions {
99
92
  * `denylist`; without one, `revoke`/`update`/`consume` throw
100
93
  * STATELESS_OPERATION_UNSUPPORTED.
101
94
  */
102
- declare class CredentialStoreJwt<TPayload extends object = object> implements CredentialStore<TPayload> {
95
+ export declare class CredentialStoreJwt<TPayload extends object = object> implements CredentialStore<TPayload> {
103
96
  private readonly algorithm;
104
97
  private readonly signingKey;
105
98
  private readonly verifyingKey;
@@ -150,8 +143,6 @@ declare class CredentialStoreJwt<TPayload extends object = object> implements Cr
150
143
  private keyFor;
151
144
  private payloadToState;
152
145
  }
153
- //#endregion
154
- //#region src/stores/encapsulated.d.ts
155
146
  interface CredentialStoreEncapsulatedOptions {
156
147
  /**
157
148
  * Encryption key material. If a 32-byte Buffer/Uint8Array is provided it is
@@ -188,7 +179,7 @@ interface CredentialStoreEncapsulatedOptions {
188
179
  * `CredentialStoreAtscriptDb` when you need native enumeration with durable
189
180
  * cross-instance cascade semantics.
190
181
  */
191
- declare class CredentialStoreEncapsulated<TPayload extends object = object> implements CredentialStore<TPayload> {
182
+ export declare class CredentialStoreEncapsulated<TPayload extends object = object> implements CredentialStore<TPayload> {
192
183
  private readonly key;
193
184
  private readonly denylist?;
194
185
  private readonly clock;
@@ -218,8 +209,6 @@ declare class CredentialStoreEncapsulated<TPayload extends object = object> impl
218
209
  private requireDenylist;
219
210
  private decrypt;
220
211
  }
221
- //#endregion
222
- //#region src/rate-limit/rules.d.ts
223
212
  /**
224
213
  * Rate-limit rule model + the compact string grammar (RL.spec.md §4.1).
225
214
  *
@@ -250,25 +239,23 @@ type RateLimitRuleInput = string | {
250
239
  window: number | string;
251
240
  message?: string;
252
241
  };
253
- declare const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests. Please try again in {{delta}}.";
242
+ export declare const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests. Please try again in {{delta}}.";
254
243
  /** `'5m'` / `'90s'` / `'500ms'` / `'1h'` / `'2d'` → ms. Throws on anything else. */
255
- declare function parseDurationMs(input: string): number;
244
+ export declare function parseDurationMs(input: string): number;
256
245
  /**
257
246
  * Humanize a ms duration for `{{window}}` / `{{delta}}` placeholders:
258
247
  * `"5 minutes"`, `"4 minutes 32 seconds"`, `"1 hour"`. Sub-second values
259
248
  * round UP to `"1 second"` — a retry hint of "0 seconds" reads as broken.
260
249
  * At most the two largest units are shown.
261
250
  */
262
- declare function formatDurationMs(ms: number): string;
251
+ export declare function formatDurationMs(ms: number): string;
263
252
  /** Normalize any {@link RateLimitRuleInput}. Throws on invalid grammar or non-positive values. */
264
- declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
253
+ export declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
265
254
  /**
266
255
  * Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
267
256
  * `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}.
268
257
  */
269
- declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
270
- //#endregion
271
- //#region src/rate-limit/rate-limiter.d.ts
258
+ export declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
272
259
  interface RateLimiterOptions {
273
260
  /** Counter storage. Default: a fresh `RateLimitStoreMemory` (single process only). */
274
261
  store?: RateLimitStore;
@@ -311,11 +298,11 @@ interface RateLimitDecision {
311
298
  * guaranteed-rejected retries; otherwise the one with the least remaining
312
299
  * budget. Used across the rules of one check and across stacked policies.
313
300
  */
314
- declare function pickGoverning<T extends {
301
+ export declare function pickGoverning<T extends {
315
302
  resetAt: number;
316
303
  remaining: number;
317
304
  }>(items: readonly T[], rejected: (item: T) => boolean): T;
318
- declare class RateLimiter {
305
+ export declare class RateLimiter {
319
306
  private readonly store;
320
307
  private readonly clock;
321
308
  constructor(opts?: RateLimiterOptions);
@@ -344,8 +331,6 @@ declare class RateLimiter {
344
331
  }): Promise<RateLimitDecision>;
345
332
  private evaluate;
346
333
  }
347
- //#endregion
348
- //#region src/email.d.ts
349
334
  /**
350
335
  * Discriminator for auth-related email events emitted by the workflow stack.
351
336
  *
@@ -385,8 +370,6 @@ interface AuthEmailEvent {
385
370
  interface EmailSender {
386
371
  send(event: AuthEmailEvent): Promise<void>;
387
372
  }
388
- //#endregion
389
- //#region src/sms.d.ts
390
373
  /**
391
374
  * Discriminator for SMS events emitted by the auth workflow stack.
392
375
  *
@@ -422,8 +405,6 @@ interface AuthSmsEvent {
422
405
  interface SmsSender {
423
406
  send(event: AuthSmsEvent): Promise<void>;
424
407
  }
425
- //#endregion
426
- //#region src/magic-link.d.ts
427
408
  /**
428
409
  * Consumer-supplied URL builder. The consumer chooses route, query
429
410
  * convention, and base URL — aoothjs does not assume a domain or scheme.
@@ -441,15 +422,12 @@ type BuildMagicLinkUrl = (kind: AuthEmailKind, token: string, ctx?: {
441
422
  userId?: string;
442
423
  }) => string;
443
424
  /** A magic-link token is a plain {@link generateOpaqueToken} mint. */
444
- declare function generateMagicLinkToken(): string;
445
- //#endregion
446
- //#region src/utils/opaque-token.d.ts
425
+ export declare function generateMagicLinkToken(): string;
447
426
  /**
448
427
  * 32 bytes of CSPRNG entropy (256 bits) encoded as base64url — 43 chars,
449
428
  * URL-safe. The single mint for every opaque bearer-style secret in the stack
450
429
  * (magic-link tokens, dynamic-client secrets, authz browser bindings):
451
430
  * unguessable online, cheap to generate, safe to place in a URL.
452
431
  */
453
- declare function generateOpaqueToken(): string;
454
- //#endregion
455
- export { type AuthContext, AuthCredential, type AuthCredentialOptions, type AuthEmailEvent, type AuthEmailKind, AuthError, type AuthErrorType, type AuthSmsEvent, type AuthSmsKind, type BuildMagicLinkUrl, type Clock, type CredentialMetadata, type CredentialState, type CredentialStore, CredentialStoreEncapsulated, type CredentialStoreEncapsulatedOptions, CredentialStoreJwt, type CredentialStoreJwtOptions, CredentialStoreMemory, DEFAULT_RATE_LIMIT_MESSAGE, type DenylistStore, DenylistStoreMemory, type EmailSender, type EnrichedSession, type IssueOptions, type IssueResult, type JwtAlgorithm, type RateLimitDecision, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, RateLimiter, type RateLimiterOptions, type RefreshCallOptions, type RefreshConfig, type RefreshResult, type SessionEnricher, type SessionInfo, type SmsSender, defaultClock, formatDurationMs, generateMagicLinkToken, generateOpaqueToken, parseDurationMs, parseRateLimitRule, pickGoverning, renderRateLimitMessage };
432
+ export declare function generateOpaqueToken(): string;
433
+ export { type AuthContext, AuthCredential, type AuthCredentialOptions, type AuthEmailEvent, type AuthEmailKind, type AuthErrorType, type AuthSmsEvent, type AuthSmsKind, type BuildMagicLinkUrl, type Clock, type CredentialMetadata, type CredentialState, type CredentialStore, type CredentialStoreEncapsulatedOptions, type CredentialStoreJwtOptions, type DenylistStore, type EmailSender, type EnrichedSession, type IssueOptions, type IssueResult, type JwtAlgorithm, type RateLimitDecision, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, type RateLimiterOptions, type RefreshCallOptions, type RefreshConfig, type RefreshResult, type SessionEnricher, type SessionInfo, type SmsSender, defaultClock };