@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/index.d.mts 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.mjs";
2
- import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-CjCgZv7n.mjs";
3
- import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-h-bLOAaS.mjs";
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.mjs";
2
+ import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-Co-0pqcD.mjs";
3
+ import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-BXxX8sUP.mjs";
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 };
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { n as AuthError, t as credentialPayloadOf } from "./payload-DDlf38B-.mjs";
2
- import { t as defaultClock } from "./clock-Bdsep_1j.mjs";
3
- import { t as generateOpaqueToken } from "./opaque-token-BaMOrC1A.mjs";
1
+ import { n as AuthError, t as credentialPayloadOf } from "./payload-DizkKbzh.mjs";
2
+ import { t as defaultClock } from "./clock-DzAK2bWR.mjs";
3
+ import { t as generateOpaqueToken } from "./opaque-token-BLoQKkZ3.mjs";
4
4
  import { createCipheriv, createDecipheriv, createHash, hkdfSync, randomBytes, randomUUID, scryptSync } from "node:crypto";
5
5
  import { SignJWT, jwtVerify } from "jose";
6
- //#region src/stores/memory.ts
6
+ // src/stores/memory.ts
7
7
  /**
8
8
  * In-memory implementation of CredentialStore using random opaque token IDs.
9
9
  *
@@ -118,8 +118,7 @@ var CredentialStoreMemory = class {
118
118
  if (set.size === 0) this.byUser.delete(userId);
119
119
  }
120
120
  };
121
- //#endregion
122
- //#region src/stores/denylist-memory.ts
121
+ // src/stores/denylist-memory.ts
123
122
  /**
124
123
  * In-memory denylist for stateless revocation.
125
124
  *
@@ -167,15 +166,13 @@ var DenylistStoreMemory = class {
167
166
  };
168
167
  /** Smallest map size an amortized expiry sweep runs at. */
169
168
  const MIN_SWEEP_SIZE$2 = 1024;
170
- //#endregion
171
- //#region src/stores/derive-subkey.ts
169
+ // src/stores/derive-subkey.ts
172
170
  const SUBKEY_SALT = Buffer.from("aooth/credential-store/subkey-v1");
173
171
  /** HKDF-SHA256 a stable 32-byte subkey from symmetric key material + a label. */
174
172
  function hkdfSubkey(ikm, label) {
175
173
  return Buffer.from(hkdfSync("sha256", ikm, SUBKEY_SALT, Buffer.from(label, "utf8"), 32));
176
174
  }
177
- //#endregion
178
- //#region src/stores/jwt.ts
175
+ // src/stores/jwt.ts
179
176
  const HS_ALGS = /* @__PURE__ */ new Set([
180
177
  "HS256",
181
178
  "HS384",
@@ -359,8 +356,7 @@ function normalizeSecret(secret) {
359
356
  if (typeof secret === "string") return new TextEncoder().encode(secret);
360
357
  return secret;
361
358
  }
362
- //#endregion
363
- //#region src/stores/encapsulated.ts
359
+ // src/stores/encapsulated.ts
364
360
  const KEY_LEN = 32;
365
361
  const IV_LEN = 12;
366
362
  const TAG_LEN = 16;
@@ -509,9 +505,8 @@ function stripJti(payload) {
509
505
  const { jti: _jti, ...rest } = payload;
510
506
  return rest;
511
507
  }
512
- //#endregion
513
- //#region src/credential/auth-credential.ts
514
- const DEFAULT_ACCESS_TTL = 3600 * 1e3;
508
+ // src/credential/auth-credential.ts
509
+ const DEFAULT_ACCESS_TTL = 36e5;
515
510
  const DEFAULT_ROTATION_GRACE_MS = 3e4;
516
511
  /**
517
512
  * Upper bound on list-then-delete passes in one revocation. Two is the norm;
@@ -1282,8 +1277,7 @@ var AuthCredential = class {
1282
1277
  });
1283
1278
  }
1284
1279
  };
1285
- //#endregion
1286
- //#region src/rate-limit/rules.ts
1280
+ // src/rate-limit/rules.ts
1287
1281
  const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests. Please try again in {{delta}}.";
1288
1282
  const DURATION_UNITS = {
1289
1283
  ms: 1,
@@ -1360,8 +1354,7 @@ function parseRateLimitRule(input) {
1360
1354
  function renderRateLimitMessage(template, rule, retryAfterMs) {
1361
1355
  return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
1362
1356
  }
1363
- //#endregion
1364
- //#region src/rate-limit/store.ts
1357
+ // src/rate-limit/store.ts
1365
1358
  /**
1366
1359
  * In-memory `RateLimitStore` — the zero-config default (single process only).
1367
1360
  * Lazy-evicts expired counters on access, and sweeps expired counters itself
@@ -1465,8 +1458,7 @@ var RateLimitStoreMemory = class {
1465
1458
  };
1466
1459
  /** Smallest map size an amortized expiry sweep runs at. */
1467
1460
  const MIN_SWEEP_SIZE = 1024;
1468
- //#endregion
1469
- //#region src/rate-limit/rate-limiter.ts
1461
+ // src/rate-limit/rate-limiter.ts
1470
1462
  /**
1471
1463
  * Fixed-window rate limiter with window-aligned keys (RL.spec.md §4.2).
1472
1464
  *
@@ -1550,11 +1542,9 @@ var RateLimiter = class {
1550
1542
  };
1551
1543
  }
1552
1544
  };
1553
- //#endregion
1554
- //#region src/magic-link.ts
1545
+ // src/magic-link.ts
1555
1546
  /** A magic-link token is a plain {@link generateOpaqueToken} mint. */
1556
1547
  function generateMagicLinkToken() {
1557
1548
  return generateOpaqueToken();
1558
1549
  }
1559
- //#endregion
1560
1550
  export { AuthCredential, AuthError, CredentialStoreEncapsulated, CredentialStoreJwt, CredentialStoreMemory, DEFAULT_RATE_LIMIT_MESSAGE, DenylistStoreMemory, RateLimitStoreMemory, RateLimiter, defaultClock, formatDurationMs, generateMagicLinkToken, generateOpaqueToken, parseDurationMs, parseRateLimitRule, pickGoverning, renderRateLimitMessage };
@@ -1,5 +1,5 @@
1
1
  import { randomBytes } from "node:crypto";
2
- //#region src/utils/opaque-token.ts
2
+ // src/utils/opaque-token.ts
3
3
  /**
4
4
  * 32 bytes of CSPRNG entropy (256 bits) encoded as base64url — 43 chars,
5
5
  * URL-safe. The single mint for every opaque bearer-style secret in the stack
@@ -9,5 +9,4 @@ import { randomBytes } from "node:crypto";
9
9
  function generateOpaqueToken() {
10
10
  return randomBytes(32).toString("base64url");
11
11
  }
12
- //#endregion
13
12
  export { generateOpaqueToken as t };
@@ -1,5 +1,5 @@
1
1
  let node_crypto = require("node:crypto");
2
- //#region src/utils/opaque-token.ts
2
+ // src/utils/opaque-token.ts
3
3
  /**
4
4
  * 32 bytes of CSPRNG entropy (256 bits) encoded as base64url — 43 chars,
5
5
  * URL-safe. The single mint for every opaque bearer-style secret in the stack
@@ -9,7 +9,6 @@ let node_crypto = require("node:crypto");
9
9
  function generateOpaqueToken() {
10
10
  return (0, node_crypto.randomBytes)(32).toString("base64url");
11
11
  }
12
- //#endregion
13
12
  Object.defineProperty(exports, "generateOpaqueToken", {
14
13
  enumerable: true,
15
14
  get: function() {
@@ -1,4 +1,4 @@
1
- //#region src/errors.ts
1
+ // src/errors.ts
2
2
  const defaultMessages = {
3
3
  INVALID_TOKEN: "Invalid token",
4
4
  TOKEN_EXPIRED: "Token has expired",
@@ -18,8 +18,7 @@ var AuthError = class extends Error {
18
18
  this.details = details;
19
19
  }
20
20
  };
21
- //#endregion
22
- //#region src/credential/payload.ts
21
+ // src/credential/payload.ts
23
22
  const ENVELOPE_KEYS = new Set(Object.keys({
24
23
  userId: true,
25
24
  issuedAt: true,
@@ -45,7 +44,6 @@ function credentialPayloadOf(state) {
45
44
  for (const [key, value] of Object.entries(state)) if (!ENVELOPE_KEYS.has(key)) out[key] = value;
46
45
  return out;
47
46
  }
48
- //#endregion
49
47
  Object.defineProperty(exports, "AuthError", {
50
48
  enumerable: true,
51
49
  get: function() {
@@ -1,4 +1,4 @@
1
- //#region src/errors.ts
1
+ // src/errors.ts
2
2
  const defaultMessages = {
3
3
  INVALID_TOKEN: "Invalid token",
4
4
  TOKEN_EXPIRED: "Token has expired",
@@ -18,8 +18,7 @@ var AuthError = class extends Error {
18
18
  this.details = details;
19
19
  }
20
20
  };
21
- //#endregion
22
- //#region src/credential/payload.ts
21
+ // src/credential/payload.ts
23
22
  const ENVELOPE_KEYS = new Set(Object.keys({
24
23
  userId: true,
25
24
  issuedAt: true,
@@ -45,5 +44,4 @@ function credentialPayloadOf(state) {
45
44
  for (const [key, value] of Object.entries(state)) if (!ENVELOPE_KEYS.has(key)) out[key] = value;
46
45
  return out;
47
46
  }
48
- //#endregion
49
47
  export { AuthError as n, credentialPayloadOf as t };
package/dist/redis.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let node_crypto = require("node:crypto");
3
- //#region src/redis/index.ts
3
+ // src/redis/index.ts
4
4
  /**
5
5
  * Redis-backed `CredentialStore`. Token id is a random UUID (the same
6
6
  * scheme as `CredentialStoreMemory`) — the token is opaque to the client.
@@ -191,7 +191,6 @@ var RateLimitStoreRedis = class {
191
191
  await this.redis.del(this.key(key));
192
192
  }
193
193
  };
194
- //#endregion
195
194
  exports.CredentialStoreRedis = CredentialStoreRedis;
196
195
  exports.DenylistStoreRedis = DenylistStoreRedis;
197
196
  exports.RateLimitStoreRedis = RateLimitStoreRedis;
package/dist/redis.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { i as DenylistStore, r as CredentialStore, s as CredentialState } from "./clock-CzAaCoZ5.cjs";
2
- import { t as RateLimitStore } from "./store-BaFYDHxn.cjs";
3
- //#region src/redis/index.d.ts
1
+ import { i as DenylistStore, r as CredentialStore, s as CredentialState } from "./clock-hTHoZ2vA.cjs";
2
+ import { t as RateLimitStore } from "./store-D9CcbcBp.cjs";
4
3
  /**
5
4
  * Structural Redis client. Covers the exact set of commands used by
6
5
  * `CredentialStoreRedis`, `DenylistStoreRedis`, and `RateLimitStoreRedis` —
@@ -61,7 +60,7 @@ import { t as RateLimitStore } from "./store-BaFYDHxn.cjs";
61
60
  * - `get` returns `string | null`
62
61
  * - `smembers` returns `string[]`
63
62
  */
64
- interface RedisLike {
63
+ export interface RedisLike {
65
64
  /** `SET key value PX ms` — `mode`/`ttlMs` are a required pair (see above). */
66
65
  set(key: string, value: string, mode: "PX", ttlMs: number): Promise<string | null>;
67
66
  /**
@@ -102,7 +101,7 @@ interface RedisCredentialStoreOptions {
102
101
  * so Redis evicts it on expiry. The user-index set is NOT TTL-bounded — we
103
102
  * lazily prune dead members on `listForUser` and `revokeAllForUser`.
104
103
  */
105
- declare class CredentialStoreRedis<TPayload extends object = object> implements CredentialStore<TPayload> {
104
+ export declare class CredentialStoreRedis<TPayload extends object = object> implements CredentialStore<TPayload> {
106
105
  private readonly redis;
107
106
  private readonly prefix;
108
107
  constructor(opts: RedisCredentialStoreOptions);
@@ -130,7 +129,7 @@ interface RedisDenylistStoreOptions {
130
129
  * to `expiresAt - now`, so Redis self-evicts the entry once the underlying
131
130
  * token would have expired anyway. `cleanup` is a no-op for that reason.
132
131
  */
133
- declare class DenylistStoreRedis implements DenylistStore {
132
+ export declare class DenylistStoreRedis implements DenylistStore {
134
133
  private readonly redis;
135
134
  private readonly prefix;
136
135
  constructor(opts: RedisDenylistStoreOptions);
@@ -153,7 +152,7 @@ interface RedisRateLimitStoreOptions {
153
152
  * `incr` and `pexpire`, the TTL-less key leaks a few bytes but is never
154
153
  * counted again.
155
154
  */
156
- declare class RateLimitStoreRedis implements RateLimitStore {
155
+ export declare class RateLimitStoreRedis implements RateLimitStore {
157
156
  private readonly redis;
158
157
  private readonly prefix;
159
158
  constructor(opts: RedisRateLimitStoreOptions);
@@ -163,5 +162,4 @@ declare class RateLimitStoreRedis implements RateLimitStore {
163
162
  expire(key: string, ttlMs: number): Promise<void>;
164
163
  reset(key: string): Promise<void>;
165
164
  }
166
- //#endregion
167
- export { CredentialStoreRedis, DenylistStoreRedis, RateLimitStoreRedis, RedisLike };
165
+ export {};
package/dist/redis.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { i as DenylistStore, r as CredentialStore, s as CredentialState } from "./clock-CzAaCoZ5.mjs";
2
- import { t as RateLimitStore } from "./store-h-bLOAaS.mjs";
3
- //#region src/redis/index.d.ts
1
+ import { i as DenylistStore, r as CredentialStore, s as CredentialState } from "./clock-hTHoZ2vA.mjs";
2
+ import { t as RateLimitStore } from "./store-BXxX8sUP.mjs";
4
3
  /**
5
4
  * Structural Redis client. Covers the exact set of commands used by
6
5
  * `CredentialStoreRedis`, `DenylistStoreRedis`, and `RateLimitStoreRedis` —
@@ -61,7 +60,7 @@ import { t as RateLimitStore } from "./store-h-bLOAaS.mjs";
61
60
  * - `get` returns `string | null`
62
61
  * - `smembers` returns `string[]`
63
62
  */
64
- interface RedisLike {
63
+ export interface RedisLike {
65
64
  /** `SET key value PX ms` — `mode`/`ttlMs` are a required pair (see above). */
66
65
  set(key: string, value: string, mode: "PX", ttlMs: number): Promise<string | null>;
67
66
  /**
@@ -102,7 +101,7 @@ interface RedisCredentialStoreOptions {
102
101
  * so Redis evicts it on expiry. The user-index set is NOT TTL-bounded — we
103
102
  * lazily prune dead members on `listForUser` and `revokeAllForUser`.
104
103
  */
105
- declare class CredentialStoreRedis<TPayload extends object = object> implements CredentialStore<TPayload> {
104
+ export declare class CredentialStoreRedis<TPayload extends object = object> implements CredentialStore<TPayload> {
106
105
  private readonly redis;
107
106
  private readonly prefix;
108
107
  constructor(opts: RedisCredentialStoreOptions);
@@ -130,7 +129,7 @@ interface RedisDenylistStoreOptions {
130
129
  * to `expiresAt - now`, so Redis self-evicts the entry once the underlying
131
130
  * token would have expired anyway. `cleanup` is a no-op for that reason.
132
131
  */
133
- declare class DenylistStoreRedis implements DenylistStore {
132
+ export declare class DenylistStoreRedis implements DenylistStore {
134
133
  private readonly redis;
135
134
  private readonly prefix;
136
135
  constructor(opts: RedisDenylistStoreOptions);
@@ -153,7 +152,7 @@ interface RedisRateLimitStoreOptions {
153
152
  * `incr` and `pexpire`, the TTL-less key leaks a few bytes but is never
154
153
  * counted again.
155
154
  */
156
- declare class RateLimitStoreRedis implements RateLimitStore {
155
+ export declare class RateLimitStoreRedis implements RateLimitStore {
157
156
  private readonly redis;
158
157
  private readonly prefix;
159
158
  constructor(opts: RedisRateLimitStoreOptions);
@@ -163,5 +162,4 @@ declare class RateLimitStoreRedis implements RateLimitStore {
163
162
  expire(key: string, ttlMs: number): Promise<void>;
164
163
  reset(key: string): Promise<void>;
165
164
  }
166
- //#endregion
167
- export { CredentialStoreRedis, DenylistStoreRedis, RateLimitStoreRedis, RedisLike };
165
+ export {};
package/dist/redis.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- //#region src/redis/index.ts
2
+ // src/redis/index.ts
3
3
  /**
4
4
  * Redis-backed `CredentialStore`. Token id is a random UUID (the same
5
5
  * scheme as `CredentialStoreMemory`) — the token is opaque to the client.
@@ -190,5 +190,4 @@ var RateLimitStoreRedis = class {
190
190
  await this.redis.del(this.key(key));
191
191
  }
192
192
  };
193
- //#endregion
194
193
  export { CredentialStoreRedis, DenylistStoreRedis, RateLimitStoreRedis };
@@ -1,5 +1,4 @@
1
- import { t as Clock } from "./clock-CzAaCoZ5.cjs";
2
- //#region src/rate-limit/store.d.ts
1
+ import { t as Clock } from "./clock-hTHoZ2vA.mjs";
3
2
  /**
4
3
  * Storage contract for the fixed-window limiter (RL.spec.md §4.3).
5
4
  *
@@ -65,5 +64,4 @@ declare class RateLimitStoreMemory implements RateLimitStore {
65
64
  cleanup(): Promise<number>;
66
65
  private sweep;
67
66
  }
68
- //#endregion
69
67
  export { RateLimitStoreMemory as n, RateLimitStore as t };
@@ -1,5 +1,4 @@
1
- import { t as Clock } from "./clock-CzAaCoZ5.mjs";
2
- //#region src/rate-limit/store.d.ts
1
+ import { t as Clock } from "./clock-hTHoZ2vA.cjs";
3
2
  /**
4
3
  * Storage contract for the fixed-window limiter (RL.spec.md §4.3).
5
4
  *
@@ -65,5 +64,4 @@ declare class RateLimitStoreMemory implements RateLimitStore {
65
64
  cleanup(): Promise<number>;
66
65
  private sweep;
67
66
  }
68
- //#endregion
69
67
  export { RateLimitStoreMemory as n, RateLimitStore as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aooth/auth",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Auth method layer for aoothjs (sessions, tokens, password reset, MFA primitives)",
5
5
  "keywords": [
6
6
  "aoothjs",
@@ -104,22 +104,22 @@
104
104
  },
105
105
  "dependencies": {
106
106
  "jose": "^6.2.3",
107
- "@aooth/user": "0.2.1"
107
+ "@aooth/user": "0.2.2"
108
108
  },
109
109
  "devDependencies": {
110
- "@atscript/core": "^0.2.1",
111
- "@atscript/db": "^0.1.166",
112
- "@atscript/db-sql-tools": "^0.1.166",
113
- "@atscript/db-sqlite": "^0.1.166",
114
- "@atscript/typescript": "^0.2.1",
110
+ "@atscript/core": "^0.2.3",
111
+ "@atscript/db": "^0.1.167",
112
+ "@atscript/db-sql-tools": "^0.1.167",
113
+ "@atscript/db-sqlite": "^0.1.167",
114
+ "@atscript/typescript": "^0.2.3",
115
115
  "@types/better-sqlite3": "^7.6.13",
116
116
  "@uniqu/core": "^0.1.15",
117
117
  "better-sqlite3": "^12.6.2",
118
118
  "ioredis": "^5.11.1",
119
- "unplugin-atscript": "^0.2.1"
119
+ "unplugin-atscript": "^0.2.3"
120
120
  },
121
121
  "peerDependencies": {
122
- "@atscript/db": "^0.1.166"
122
+ "@atscript/db": "^0.1.167"
123
123
  },
124
124
  "peerDependenciesMeta": {
125
125
  "@atscript/db": {