@aooth/auth 0.1.84 → 0.2.0

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/index.d.cts CHANGED
@@ -1,6 +1,6 @@
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-CyjqzLxc.cjs";
2
- import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-GRAK230V.cjs";
3
- import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-ClQnA8yh.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-CzAaCoZ5.cjs";
2
+ import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-D1V5-2uy.cjs";
3
+ import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-BaFYDHxn.cjs";
4
4
  import { CryptoKey } from "jose";
5
5
  //#region src/errors.d.ts
6
6
  type AuthErrorType = "INVALID_TOKEN" | "TOKEN_EXPIRED" | "TOKEN_REVOKED" | "REFRESH_REUSE_DETECTED" | "STATELESS_OPERATION_UNSUPPORTED" | "MAX_CONCURRENT_REACHED" | "INVALID_CONFIG";
@@ -28,6 +28,7 @@ declare class CredentialStoreMemory<TPayload extends object = object> implements
28
28
  clock?: Clock;
29
29
  });
30
30
  persist(state: CredentialState & TPayload, ttl?: number): Promise<string>;
31
+ persistAs(id: string, state: CredentialState & TPayload, ttl?: number): Promise<void>;
31
32
  retrieve(token: string): Promise<(CredentialState & TPayload) | null>;
32
33
  consume(token: string): Promise<(CredentialState & TPayload) | null>;
33
34
  update(token: string, state: CredentialState & TPayload): Promise<string>;
@@ -303,6 +304,17 @@ interface RateLimitDecision {
303
304
  * key and one atomic store increment decides. All rules are hit on every
304
305
  * check (rejected requests count too — they cannot extend a fixed window).
305
306
  */
307
+ /**
308
+ * The item that governs a combined decision: among the rejected ones (when
309
+ * any), the one whose window frees capacity LAST — the request only becomes
310
+ * allowed once every one passes, so a shorter hint would invite
311
+ * guaranteed-rejected retries; otherwise the one with the least remaining
312
+ * budget. Used across the rules of one check and across stacked policies.
313
+ */
314
+ declare function pickGoverning<T extends {
315
+ resetAt: number;
316
+ remaining: number;
317
+ }>(items: readonly T[], rejected: (item: T) => boolean): T;
306
318
  declare class RateLimiter {
307
319
  private readonly store;
308
320
  private readonly clock;
@@ -321,6 +333,16 @@ declare class RateLimiter {
321
333
  check(scope: string, subject: string, rules: RateLimitRuleInput[], opts?: {
322
334
  defaultMessage?: string;
323
335
  }): Promise<RateLimitDecision>;
336
+ /**
337
+ * Read the budget `check()` would see — without spending it. `remaining`
338
+ * is what is left in each window; `allowed` says whether a `check()` made
339
+ * now would pass. Use it for a "N left today" status line. Requires a store
340
+ * with `get()` (both bundled stores have it).
341
+ */
342
+ peek(scope: string, subject: string, rules: RateLimitRuleInput[], opts?: {
343
+ defaultMessage?: string;
344
+ }): Promise<RateLimitDecision>;
345
+ private evaluate;
324
346
  }
325
347
  //#endregion
326
348
  //#region src/email.d.ts
@@ -430,4 +452,4 @@ declare function generateMagicLinkToken(): string;
430
452
  */
431
453
  declare function generateOpaqueToken(): string;
432
454
  //#endregion
433
- 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, renderRateLimitMessage };
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 };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
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-CyjqzLxc.mjs";
2
- import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-CLAQgjCS.mjs";
3
- import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-CVD1nd2j.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-CzAaCoZ5.mjs";
2
+ import { i as RefreshCallOptions, n as AuthCredentialOptions, r as IssueOptions, t as AuthCredential } from "./auth-credential-BsH0E8hG.mjs";
3
+ import { n as RateLimitStoreMemory, t as RateLimitStore } from "./store-h-bLOAaS.mjs";
4
4
  import { CryptoKey } from "jose";
5
5
  //#region src/errors.d.ts
6
6
  type AuthErrorType = "INVALID_TOKEN" | "TOKEN_EXPIRED" | "TOKEN_REVOKED" | "REFRESH_REUSE_DETECTED" | "STATELESS_OPERATION_UNSUPPORTED" | "MAX_CONCURRENT_REACHED" | "INVALID_CONFIG";
@@ -28,6 +28,7 @@ declare class CredentialStoreMemory<TPayload extends object = object> implements
28
28
  clock?: Clock;
29
29
  });
30
30
  persist(state: CredentialState & TPayload, ttl?: number): Promise<string>;
31
+ persistAs(id: string, state: CredentialState & TPayload, ttl?: number): Promise<void>;
31
32
  retrieve(token: string): Promise<(CredentialState & TPayload) | null>;
32
33
  consume(token: string): Promise<(CredentialState & TPayload) | null>;
33
34
  update(token: string, state: CredentialState & TPayload): Promise<string>;
@@ -303,6 +304,17 @@ interface RateLimitDecision {
303
304
  * key and one atomic store increment decides. All rules are hit on every
304
305
  * check (rejected requests count too — they cannot extend a fixed window).
305
306
  */
307
+ /**
308
+ * The item that governs a combined decision: among the rejected ones (when
309
+ * any), the one whose window frees capacity LAST — the request only becomes
310
+ * allowed once every one passes, so a shorter hint would invite
311
+ * guaranteed-rejected retries; otherwise the one with the least remaining
312
+ * budget. Used across the rules of one check and across stacked policies.
313
+ */
314
+ declare function pickGoverning<T extends {
315
+ resetAt: number;
316
+ remaining: number;
317
+ }>(items: readonly T[], rejected: (item: T) => boolean): T;
306
318
  declare class RateLimiter {
307
319
  private readonly store;
308
320
  private readonly clock;
@@ -321,6 +333,16 @@ declare class RateLimiter {
321
333
  check(scope: string, subject: string, rules: RateLimitRuleInput[], opts?: {
322
334
  defaultMessage?: string;
323
335
  }): Promise<RateLimitDecision>;
336
+ /**
337
+ * Read the budget `check()` would see — without spending it. `remaining`
338
+ * is what is left in each window; `allowed` says whether a `check()` made
339
+ * now would pass. Use it for a "N left today" status line. Requires a store
340
+ * with `get()` (both bundled stores have it).
341
+ */
342
+ peek(scope: string, subject: string, rules: RateLimitRuleInput[], opts?: {
343
+ defaultMessage?: string;
344
+ }): Promise<RateLimitDecision>;
345
+ private evaluate;
324
346
  }
325
347
  //#endregion
326
348
  //#region src/email.d.ts
@@ -430,4 +452,4 @@ declare function generateMagicLinkToken(): string;
430
452
  */
431
453
  declare function generateOpaqueToken(): string;
432
454
  //#endregion
433
- 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, renderRateLimitMessage };
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 };