@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.
- package/dist/atscript-db.cjs +5 -7
- package/dist/atscript-db.d.cts +21 -25
- package/dist/atscript-db.d.mts +21 -25
- package/dist/atscript-db.mjs +5 -7
- package/dist/{auth-credential-CjCgZv7n.d.mts → auth-credential-46_eOF3c.d.cts} +1 -3
- package/dist/{auth-credential-UV3sJ-lt.d.cts → auth-credential-Co-0pqcD.d.mts} +1 -3
- package/dist/authz.cjs +21 -33
- package/dist/authz.d.cts +23 -45
- package/dist/authz.d.mts +23 -45
- package/dist/authz.mjs +21 -33
- package/dist/client.cjs +1 -2
- package/dist/client.d.cts +7 -10
- package/dist/client.d.mts +7 -10
- package/dist/client.mjs +1 -2
- package/dist/{clock-Bl-H3eqE.cjs → clock-BcBMqB9g.cjs} +1 -2
- package/dist/{clock-Bdsep_1j.mjs → clock-DzAK2bWR.mjs} +1 -2
- package/dist/{clock-CzAaCoZ5.d.cts → clock-hTHoZ2vA.d.cts} +0 -6
- package/dist/{clock-CzAaCoZ5.d.mts → clock-hTHoZ2vA.d.mts} +0 -6
- package/dist/{dynamic-client-store-DykM9QOT.cjs → dynamic-client-store-CC4qr_kz.cjs} +5 -8
- package/dist/{dynamic-client-store-B7EnHuRp.d.cts → dynamic-client-store-CTt1B6Gj.d.cts} +2 -10
- package/dist/{dynamic-client-store-B1JwFHdP.mjs → dynamic-client-store-DrMBcFtG.mjs} +5 -8
- package/dist/{dynamic-client-store-BifZLGkT.d.mts → dynamic-client-store-mYg0nRJU.d.mts} +2 -10
- package/dist/index.cjs +31 -26
- package/dist/index.d.cts +49 -40
- package/dist/index.d.mts +49 -40
- package/dist/index.mjs +31 -27
- package/dist/{opaque-token-BaMOrC1A.mjs → opaque-token-BLoQKkZ3.mjs} +1 -2
- package/dist/{opaque-token-CaZgD2i6.cjs → opaque-token-BLuVHSVJ.cjs} +1 -2
- package/dist/{payload-C1cQW7p_.cjs → payload-CqQH88C6.cjs} +2 -4
- package/dist/{payload-DDlf38B-.mjs → payload-DizkKbzh.mjs} +2 -4
- package/dist/redis.cjs +1 -2
- package/dist/redis.d.cts +7 -9
- package/dist/redis.d.mts +7 -9
- package/dist/redis.mjs +1 -2
- package/dist/{store-BaFYDHxn.d.cts → store-BXxX8sUP.d.mts} +1 -3
- package/dist/{store-h-bLOAaS.d.mts → store-D9CcbcBp.d.cts} +1 -3
- package/package.json +10 -10
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-
|
|
2
|
-
import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-
|
|
3
|
-
import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-
|
|
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,50 @@ type RateLimitRuleInput = string | {
|
|
|
250
239
|
window: number | string;
|
|
251
240
|
message?: string;
|
|
252
241
|
};
|
|
253
|
-
|
|
242
|
+
/** Machine-readable code of a rate-limit rejection (the 429 body's `code`). */
|
|
243
|
+
type RateLimitErrorCode = "RATE_LIMITED";
|
|
244
|
+
/**
|
|
245
|
+
* Default English message template per rate-limit code. The 429 body carries
|
|
246
|
+
* the `code` and its {@link RateLimitParams}, so a client or a server-side
|
|
247
|
+
* error-body hook can translate the rejection without parsing this text.
|
|
248
|
+
*/
|
|
249
|
+
export declare const RATE_LIMIT_MESSAGES: Readonly<Record<RateLimitErrorCode, string>>;
|
|
250
|
+
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
251
|
+
export declare const DEFAULT_RATE_LIMIT_MESSAGE: string;
|
|
252
|
+
/**
|
|
253
|
+
* Values of a rate-limit rejection, sent as the 429 body's `params` next to
|
|
254
|
+
* its `code`. Durations are in seconds.
|
|
255
|
+
*/
|
|
256
|
+
type RateLimitParams = {
|
|
257
|
+
/**
|
|
258
|
+
* The limited bucket — the `scope` passed to `RateLimiter.check()`; with the
|
|
259
|
+
* moost interceptor, the policy's `id` (default `<Class>.<method>`, `#<n>`
|
|
260
|
+
* for stacked policies). Tells rules apart when translating.
|
|
261
|
+
*/
|
|
262
|
+
policy: string;
|
|
263
|
+
/** Max requests per window of the violated rule. */
|
|
264
|
+
limit: number;
|
|
265
|
+
/** Window length of the violated rule, in seconds. */
|
|
266
|
+
window: number;
|
|
267
|
+
/** Seconds until a retry can pass — the same value as the `Retry-After` header. */
|
|
268
|
+
retryAfter: number;
|
|
269
|
+
};
|
|
254
270
|
/** `'5m'` / `'90s'` / `'500ms'` / `'1h'` / `'2d'` → ms. Throws on anything else. */
|
|
255
|
-
declare function parseDurationMs(input: string): number;
|
|
271
|
+
export declare function parseDurationMs(input: string): number;
|
|
256
272
|
/**
|
|
257
273
|
* Humanize a ms duration for `{{window}}` / `{{delta}}` placeholders:
|
|
258
274
|
* `"5 minutes"`, `"4 minutes 32 seconds"`, `"1 hour"`. Sub-second values
|
|
259
275
|
* round UP to `"1 second"` — a retry hint of "0 seconds" reads as broken.
|
|
260
276
|
* At most the two largest units are shown.
|
|
261
277
|
*/
|
|
262
|
-
declare function formatDurationMs(ms: number): string;
|
|
278
|
+
export declare function formatDurationMs(ms: number): string;
|
|
263
279
|
/** Normalize any {@link RateLimitRuleInput}. Throws on invalid grammar or non-positive values. */
|
|
264
|
-
declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
280
|
+
export declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
265
281
|
/**
|
|
266
282
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
267
283
|
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}.
|
|
268
284
|
*/
|
|
269
|
-
declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/rate-limit/rate-limiter.d.ts
|
|
285
|
+
export declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
272
286
|
interface RateLimiterOptions {
|
|
273
287
|
/** Counter storage. Default: a fresh `RateLimitStoreMemory` (single process only). */
|
|
274
288
|
store?: RateLimitStore;
|
|
@@ -293,6 +307,10 @@ interface RateLimitDecision {
|
|
|
293
307
|
retryAfterMs?: number;
|
|
294
308
|
/** Present when `!allowed`: rendered from the violated rule's message template. */
|
|
295
309
|
message?: string;
|
|
310
|
+
/** Present when `!allowed`: the machine-readable code of the rejection. */
|
|
311
|
+
code?: RateLimitErrorCode;
|
|
312
|
+
/** Present when `!allowed`: the violated rule's values, for translating {@link code}. */
|
|
313
|
+
params?: RateLimitParams;
|
|
296
314
|
/** Every evaluated rule (for the `RateLimit-Policy` header). */
|
|
297
315
|
policies: RateLimitRule[];
|
|
298
316
|
}
|
|
@@ -311,11 +329,11 @@ interface RateLimitDecision {
|
|
|
311
329
|
* guaranteed-rejected retries; otherwise the one with the least remaining
|
|
312
330
|
* budget. Used across the rules of one check and across stacked policies.
|
|
313
331
|
*/
|
|
314
|
-
declare function pickGoverning<T extends {
|
|
332
|
+
export declare function pickGoverning<T extends {
|
|
315
333
|
resetAt: number;
|
|
316
334
|
remaining: number;
|
|
317
335
|
}>(items: readonly T[], rejected: (item: T) => boolean): T;
|
|
318
|
-
declare class RateLimiter {
|
|
336
|
+
export declare class RateLimiter {
|
|
319
337
|
private readonly store;
|
|
320
338
|
private readonly clock;
|
|
321
339
|
constructor(opts?: RateLimiterOptions);
|
|
@@ -344,8 +362,6 @@ declare class RateLimiter {
|
|
|
344
362
|
}): Promise<RateLimitDecision>;
|
|
345
363
|
private evaluate;
|
|
346
364
|
}
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/email.d.ts
|
|
349
365
|
/**
|
|
350
366
|
* Discriminator for auth-related email events emitted by the workflow stack.
|
|
351
367
|
*
|
|
@@ -385,8 +401,6 @@ interface AuthEmailEvent {
|
|
|
385
401
|
interface EmailSender {
|
|
386
402
|
send(event: AuthEmailEvent): Promise<void>;
|
|
387
403
|
}
|
|
388
|
-
//#endregion
|
|
389
|
-
//#region src/sms.d.ts
|
|
390
404
|
/**
|
|
391
405
|
* Discriminator for SMS events emitted by the auth workflow stack.
|
|
392
406
|
*
|
|
@@ -422,8 +436,6 @@ interface AuthSmsEvent {
|
|
|
422
436
|
interface SmsSender {
|
|
423
437
|
send(event: AuthSmsEvent): Promise<void>;
|
|
424
438
|
}
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/magic-link.d.ts
|
|
427
439
|
/**
|
|
428
440
|
* Consumer-supplied URL builder. The consumer chooses route, query
|
|
429
441
|
* convention, and base URL — aoothjs does not assume a domain or scheme.
|
|
@@ -441,15 +453,12 @@ type BuildMagicLinkUrl = (kind: AuthEmailKind, token: string, ctx?: {
|
|
|
441
453
|
userId?: string;
|
|
442
454
|
}) => string;
|
|
443
455
|
/** 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
|
|
456
|
+
export declare function generateMagicLinkToken(): string;
|
|
447
457
|
/**
|
|
448
458
|
* 32 bytes of CSPRNG entropy (256 bits) encoded as base64url — 43 chars,
|
|
449
459
|
* URL-safe. The single mint for every opaque bearer-style secret in the stack
|
|
450
460
|
* (magic-link tokens, dynamic-client secrets, authz browser bindings):
|
|
451
461
|
* unguessable online, cheap to generate, safe to place in a URL.
|
|
452
462
|
*/
|
|
453
|
-
declare function generateOpaqueToken(): string;
|
|
454
|
-
|
|
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 };
|
|
463
|
+
export declare function generateOpaqueToken(): string;
|
|
464
|
+
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 RateLimitErrorCode, type RateLimitParams, 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.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-
|
|
2
|
-
import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-
|
|
3
|
-
import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-
|
|
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,50 @@ type RateLimitRuleInput = string | {
|
|
|
250
239
|
window: number | string;
|
|
251
240
|
message?: string;
|
|
252
241
|
};
|
|
253
|
-
|
|
242
|
+
/** Machine-readable code of a rate-limit rejection (the 429 body's `code`). */
|
|
243
|
+
type RateLimitErrorCode = "RATE_LIMITED";
|
|
244
|
+
/**
|
|
245
|
+
* Default English message template per rate-limit code. The 429 body carries
|
|
246
|
+
* the `code` and its {@link RateLimitParams}, so a client or a server-side
|
|
247
|
+
* error-body hook can translate the rejection without parsing this text.
|
|
248
|
+
*/
|
|
249
|
+
export declare const RATE_LIMIT_MESSAGES: Readonly<Record<RateLimitErrorCode, string>>;
|
|
250
|
+
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
251
|
+
export declare const DEFAULT_RATE_LIMIT_MESSAGE: string;
|
|
252
|
+
/**
|
|
253
|
+
* Values of a rate-limit rejection, sent as the 429 body's `params` next to
|
|
254
|
+
* its `code`. Durations are in seconds.
|
|
255
|
+
*/
|
|
256
|
+
type RateLimitParams = {
|
|
257
|
+
/**
|
|
258
|
+
* The limited bucket — the `scope` passed to `RateLimiter.check()`; with the
|
|
259
|
+
* moost interceptor, the policy's `id` (default `<Class>.<method>`, `#<n>`
|
|
260
|
+
* for stacked policies). Tells rules apart when translating.
|
|
261
|
+
*/
|
|
262
|
+
policy: string;
|
|
263
|
+
/** Max requests per window of the violated rule. */
|
|
264
|
+
limit: number;
|
|
265
|
+
/** Window length of the violated rule, in seconds. */
|
|
266
|
+
window: number;
|
|
267
|
+
/** Seconds until a retry can pass — the same value as the `Retry-After` header. */
|
|
268
|
+
retryAfter: number;
|
|
269
|
+
};
|
|
254
270
|
/** `'5m'` / `'90s'` / `'500ms'` / `'1h'` / `'2d'` → ms. Throws on anything else. */
|
|
255
|
-
declare function parseDurationMs(input: string): number;
|
|
271
|
+
export declare function parseDurationMs(input: string): number;
|
|
256
272
|
/**
|
|
257
273
|
* Humanize a ms duration for `{{window}}` / `{{delta}}` placeholders:
|
|
258
274
|
* `"5 minutes"`, `"4 minutes 32 seconds"`, `"1 hour"`. Sub-second values
|
|
259
275
|
* round UP to `"1 second"` — a retry hint of "0 seconds" reads as broken.
|
|
260
276
|
* At most the two largest units are shown.
|
|
261
277
|
*/
|
|
262
|
-
declare function formatDurationMs(ms: number): string;
|
|
278
|
+
export declare function formatDurationMs(ms: number): string;
|
|
263
279
|
/** Normalize any {@link RateLimitRuleInput}. Throws on invalid grammar or non-positive values. */
|
|
264
|
-
declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
280
|
+
export declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
265
281
|
/**
|
|
266
282
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
267
283
|
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}.
|
|
268
284
|
*/
|
|
269
|
-
declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/rate-limit/rate-limiter.d.ts
|
|
285
|
+
export declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
272
286
|
interface RateLimiterOptions {
|
|
273
287
|
/** Counter storage. Default: a fresh `RateLimitStoreMemory` (single process only). */
|
|
274
288
|
store?: RateLimitStore;
|
|
@@ -293,6 +307,10 @@ interface RateLimitDecision {
|
|
|
293
307
|
retryAfterMs?: number;
|
|
294
308
|
/** Present when `!allowed`: rendered from the violated rule's message template. */
|
|
295
309
|
message?: string;
|
|
310
|
+
/** Present when `!allowed`: the machine-readable code of the rejection. */
|
|
311
|
+
code?: RateLimitErrorCode;
|
|
312
|
+
/** Present when `!allowed`: the violated rule's values, for translating {@link code}. */
|
|
313
|
+
params?: RateLimitParams;
|
|
296
314
|
/** Every evaluated rule (for the `RateLimit-Policy` header). */
|
|
297
315
|
policies: RateLimitRule[];
|
|
298
316
|
}
|
|
@@ -311,11 +329,11 @@ interface RateLimitDecision {
|
|
|
311
329
|
* guaranteed-rejected retries; otherwise the one with the least remaining
|
|
312
330
|
* budget. Used across the rules of one check and across stacked policies.
|
|
313
331
|
*/
|
|
314
|
-
declare function pickGoverning<T extends {
|
|
332
|
+
export declare function pickGoverning<T extends {
|
|
315
333
|
resetAt: number;
|
|
316
334
|
remaining: number;
|
|
317
335
|
}>(items: readonly T[], rejected: (item: T) => boolean): T;
|
|
318
|
-
declare class RateLimiter {
|
|
336
|
+
export declare class RateLimiter {
|
|
319
337
|
private readonly store;
|
|
320
338
|
private readonly clock;
|
|
321
339
|
constructor(opts?: RateLimiterOptions);
|
|
@@ -344,8 +362,6 @@ declare class RateLimiter {
|
|
|
344
362
|
}): Promise<RateLimitDecision>;
|
|
345
363
|
private evaluate;
|
|
346
364
|
}
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/email.d.ts
|
|
349
365
|
/**
|
|
350
366
|
* Discriminator for auth-related email events emitted by the workflow stack.
|
|
351
367
|
*
|
|
@@ -385,8 +401,6 @@ interface AuthEmailEvent {
|
|
|
385
401
|
interface EmailSender {
|
|
386
402
|
send(event: AuthEmailEvent): Promise<void>;
|
|
387
403
|
}
|
|
388
|
-
//#endregion
|
|
389
|
-
//#region src/sms.d.ts
|
|
390
404
|
/**
|
|
391
405
|
* Discriminator for SMS events emitted by the auth workflow stack.
|
|
392
406
|
*
|
|
@@ -422,8 +436,6 @@ interface AuthSmsEvent {
|
|
|
422
436
|
interface SmsSender {
|
|
423
437
|
send(event: AuthSmsEvent): Promise<void>;
|
|
424
438
|
}
|
|
425
|
-
//#endregion
|
|
426
|
-
//#region src/magic-link.d.ts
|
|
427
439
|
/**
|
|
428
440
|
* Consumer-supplied URL builder. The consumer chooses route, query
|
|
429
441
|
* convention, and base URL — aoothjs does not assume a domain or scheme.
|
|
@@ -441,15 +453,12 @@ type BuildMagicLinkUrl = (kind: AuthEmailKind, token: string, ctx?: {
|
|
|
441
453
|
userId?: string;
|
|
442
454
|
}) => string;
|
|
443
455
|
/** 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
|
|
456
|
+
export declare function generateMagicLinkToken(): string;
|
|
447
457
|
/**
|
|
448
458
|
* 32 bytes of CSPRNG entropy (256 bits) encoded as base64url — 43 chars,
|
|
449
459
|
* URL-safe. The single mint for every opaque bearer-style secret in the stack
|
|
450
460
|
* (magic-link tokens, dynamic-client secrets, authz browser bindings):
|
|
451
461
|
* unguessable online, cheap to generate, safe to place in a URL.
|
|
452
462
|
*/
|
|
453
|
-
declare function generateOpaqueToken(): string;
|
|
454
|
-
|
|
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 };
|
|
463
|
+
export declare function generateOpaqueToken(): string;
|
|
464
|
+
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 RateLimitErrorCode, type RateLimitParams, 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-
|
|
2
|
-
import { t as defaultClock } from "./clock-
|
|
3
|
-
import { t as generateOpaqueToken } from "./opaque-token-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
513
|
-
|
|
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,9 +1277,15 @@ var AuthCredential = class {
|
|
|
1282
1277
|
});
|
|
1283
1278
|
}
|
|
1284
1279
|
};
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1280
|
+
// src/rate-limit/rules.ts
|
|
1281
|
+
/**
|
|
1282
|
+
* Default English message template per rate-limit code. The 429 body carries
|
|
1283
|
+
* the `code` and its {@link RateLimitParams}, so a client or a server-side
|
|
1284
|
+
* error-body hook can translate the rejection without parsing this text.
|
|
1285
|
+
*/
|
|
1286
|
+
const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests. Please try again in {{delta}}." };
|
|
1287
|
+
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
1288
|
+
const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
|
|
1288
1289
|
const DURATION_UNITS = {
|
|
1289
1290
|
ms: 1,
|
|
1290
1291
|
s: 1e3,
|
|
@@ -1360,8 +1361,7 @@ function parseRateLimitRule(input) {
|
|
|
1360
1361
|
function renderRateLimitMessage(template, rule, retryAfterMs) {
|
|
1361
1362
|
return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
|
|
1362
1363
|
}
|
|
1363
|
-
|
|
1364
|
-
//#region src/rate-limit/store.ts
|
|
1364
|
+
// src/rate-limit/store.ts
|
|
1365
1365
|
/**
|
|
1366
1366
|
* In-memory `RateLimitStore` — the zero-config default (single process only).
|
|
1367
1367
|
* Lazy-evicts expired counters on access, and sweeps expired counters itself
|
|
@@ -1465,8 +1465,7 @@ var RateLimitStoreMemory = class {
|
|
|
1465
1465
|
};
|
|
1466
1466
|
/** Smallest map size an amortized expiry sweep runs at. */
|
|
1467
1467
|
const MIN_SWEEP_SIZE = 1024;
|
|
1468
|
-
|
|
1469
|
-
//#region src/rate-limit/rate-limiter.ts
|
|
1468
|
+
// src/rate-limit/rate-limiter.ts
|
|
1470
1469
|
/**
|
|
1471
1470
|
* Fixed-window rate limiter with window-aligned keys (RL.spec.md §4.2).
|
|
1472
1471
|
*
|
|
@@ -1545,16 +1544,21 @@ var RateLimiter = class {
|
|
|
1545
1544
|
policies: parsed,
|
|
1546
1545
|
...rejected && {
|
|
1547
1546
|
retryAfterMs: resetAfterMs,
|
|
1548
|
-
|
|
1547
|
+
code: "RATE_LIMITED",
|
|
1548
|
+
params: {
|
|
1549
|
+
policy: scope,
|
|
1550
|
+
limit: governing.rule.limit,
|
|
1551
|
+
window: governing.rule.window / 1e3,
|
|
1552
|
+
retryAfter: Math.ceil(resetAfterMs / 1e3)
|
|
1553
|
+
},
|
|
1554
|
+
message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
|
|
1549
1555
|
}
|
|
1550
1556
|
};
|
|
1551
1557
|
}
|
|
1552
1558
|
};
|
|
1553
|
-
|
|
1554
|
-
//#region src/magic-link.ts
|
|
1559
|
+
// src/magic-link.ts
|
|
1555
1560
|
/** A magic-link token is a plain {@link generateOpaqueToken} mint. */
|
|
1556
1561
|
function generateMagicLinkToken() {
|
|
1557
1562
|
return generateOpaqueToken();
|
|
1558
1563
|
}
|
|
1559
|
-
|
|
1560
|
-
export { AuthCredential, AuthError, CredentialStoreEncapsulated, CredentialStoreJwt, CredentialStoreMemory, DEFAULT_RATE_LIMIT_MESSAGE, DenylistStoreMemory, RateLimitStoreMemory, RateLimiter, defaultClock, formatDurationMs, generateMagicLinkToken, generateOpaqueToken, parseDurationMs, parseRateLimitRule, pickGoverning, renderRateLimitMessage };
|
|
1564
|
+
export { AuthCredential, AuthError, CredentialStoreEncapsulated, CredentialStoreJwt, CredentialStoreMemory, DEFAULT_RATE_LIMIT_MESSAGE, DenylistStoreMemory, RATE_LIMIT_MESSAGES, RateLimitStoreMemory, RateLimiter, defaultClock, formatDurationMs, generateMagicLinkToken, generateOpaqueToken, parseDurationMs, parseRateLimitRule, pickGoverning, renderRateLimitMessage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|