@aooth/auth 0.2.2 → 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/index.cjs +17 -2
- package/dist/index.d.cts +33 -2
- package/dist/index.d.mts +33 -2
- package/dist/index.mjs +17 -3
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1279,7 +1279,14 @@ var AuthCredential = class {
|
|
|
1279
1279
|
}
|
|
1280
1280
|
};
|
|
1281
1281
|
// src/rate-limit/rules.ts
|
|
1282
|
-
|
|
1282
|
+
/**
|
|
1283
|
+
* Default English message template per rate-limit code. The 429 body carries
|
|
1284
|
+
* the `code` and its {@link RateLimitParams}, so a client or a server-side
|
|
1285
|
+
* error-body hook can translate the rejection without parsing this text.
|
|
1286
|
+
*/
|
|
1287
|
+
const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests. Please try again in {{delta}}." };
|
|
1288
|
+
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
1289
|
+
const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
|
|
1283
1290
|
const DURATION_UNITS = {
|
|
1284
1291
|
ms: 1,
|
|
1285
1292
|
s: 1e3,
|
|
@@ -1538,7 +1545,14 @@ var RateLimiter = class {
|
|
|
1538
1545
|
policies: parsed,
|
|
1539
1546
|
...rejected && {
|
|
1540
1547
|
retryAfterMs: resetAfterMs,
|
|
1541
|
-
|
|
1548
|
+
code: "RATE_LIMITED",
|
|
1549
|
+
params: {
|
|
1550
|
+
policy: scope,
|
|
1551
|
+
limit: governing.rule.limit,
|
|
1552
|
+
window: governing.rule.window / 1e3,
|
|
1553
|
+
retryAfter: Math.ceil(resetAfterMs / 1e3)
|
|
1554
|
+
},
|
|
1555
|
+
message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
|
|
1542
1556
|
}
|
|
1543
1557
|
};
|
|
1544
1558
|
}
|
|
@@ -1555,6 +1569,7 @@ exports.CredentialStoreJwt = CredentialStoreJwt;
|
|
|
1555
1569
|
exports.CredentialStoreMemory = CredentialStoreMemory;
|
|
1556
1570
|
exports.DEFAULT_RATE_LIMIT_MESSAGE = DEFAULT_RATE_LIMIT_MESSAGE;
|
|
1557
1571
|
exports.DenylistStoreMemory = DenylistStoreMemory;
|
|
1572
|
+
exports.RATE_LIMIT_MESSAGES = RATE_LIMIT_MESSAGES;
|
|
1558
1573
|
exports.RateLimitStoreMemory = RateLimitStoreMemory;
|
|
1559
1574
|
exports.RateLimiter = RateLimiter;
|
|
1560
1575
|
exports.defaultClock = require_clock.defaultClock;
|
package/dist/index.d.cts
CHANGED
|
@@ -239,7 +239,34 @@ type RateLimitRuleInput = string | {
|
|
|
239
239
|
window: number | string;
|
|
240
240
|
message?: string;
|
|
241
241
|
};
|
|
242
|
-
|
|
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
|
+
};
|
|
243
270
|
/** `'5m'` / `'90s'` / `'500ms'` / `'1h'` / `'2d'` → ms. Throws on anything else. */
|
|
244
271
|
export declare function parseDurationMs(input: string): number;
|
|
245
272
|
/**
|
|
@@ -280,6 +307,10 @@ interface RateLimitDecision {
|
|
|
280
307
|
retryAfterMs?: number;
|
|
281
308
|
/** Present when `!allowed`: rendered from the violated rule's message template. */
|
|
282
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;
|
|
283
314
|
/** Every evaluated rule (for the `RateLimit-Policy` header). */
|
|
284
315
|
policies: RateLimitRule[];
|
|
285
316
|
}
|
|
@@ -430,4 +461,4 @@ export declare function generateMagicLinkToken(): string;
|
|
|
430
461
|
* unguessable online, cheap to generate, safe to place in a URL.
|
|
431
462
|
*/
|
|
432
463
|
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 };
|
|
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
|
@@ -239,7 +239,34 @@ type RateLimitRuleInput = string | {
|
|
|
239
239
|
window: number | string;
|
|
240
240
|
message?: string;
|
|
241
241
|
};
|
|
242
|
-
|
|
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
|
+
};
|
|
243
270
|
/** `'5m'` / `'90s'` / `'500ms'` / `'1h'` / `'2d'` → ms. Throws on anything else. */
|
|
244
271
|
export declare function parseDurationMs(input: string): number;
|
|
245
272
|
/**
|
|
@@ -280,6 +307,10 @@ interface RateLimitDecision {
|
|
|
280
307
|
retryAfterMs?: number;
|
|
281
308
|
/** Present when `!allowed`: rendered from the violated rule's message template. */
|
|
282
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;
|
|
283
314
|
/** Every evaluated rule (for the `RateLimit-Policy` header). */
|
|
284
315
|
policies: RateLimitRule[];
|
|
285
316
|
}
|
|
@@ -430,4 +461,4 @@ export declare function generateMagicLinkToken(): string;
|
|
|
430
461
|
* unguessable online, cheap to generate, safe to place in a URL.
|
|
431
462
|
*/
|
|
432
463
|
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 };
|
|
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
|
@@ -1278,7 +1278,14 @@ var AuthCredential = class {
|
|
|
1278
1278
|
}
|
|
1279
1279
|
};
|
|
1280
1280
|
// src/rate-limit/rules.ts
|
|
1281
|
-
|
|
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;
|
|
1282
1289
|
const DURATION_UNITS = {
|
|
1283
1290
|
ms: 1,
|
|
1284
1291
|
s: 1e3,
|
|
@@ -1537,7 +1544,14 @@ var RateLimiter = class {
|
|
|
1537
1544
|
policies: parsed,
|
|
1538
1545
|
...rejected && {
|
|
1539
1546
|
retryAfterMs: resetAfterMs,
|
|
1540
|
-
|
|
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)
|
|
1541
1555
|
}
|
|
1542
1556
|
};
|
|
1543
1557
|
}
|
|
@@ -1547,4 +1561,4 @@ var RateLimiter = class {
|
|
|
1547
1561
|
function generateMagicLinkToken() {
|
|
1548
1562
|
return generateOpaqueToken();
|
|
1549
1563
|
}
|
|
1550
|
-
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.
|
|
107
|
+
"@aooth/user": "0.2.3"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
|
-
"@atscript/core": "^0.2.
|
|
111
|
-
"@atscript/db": "^0.1.
|
|
112
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
113
|
-
"@atscript/db-sqlite": "^0.1.
|
|
114
|
-
"@atscript/typescript": "^0.2.
|
|
110
|
+
"@atscript/core": "^0.2.4",
|
|
111
|
+
"@atscript/db": "^0.1.168",
|
|
112
|
+
"@atscript/db-sql-tools": "^0.1.168",
|
|
113
|
+
"@atscript/db-sqlite": "^0.1.168",
|
|
114
|
+
"@atscript/typescript": "^0.2.4",
|
|
115
115
|
"@types/better-sqlite3": "^7.6.13",
|
|
116
|
-
"@uniqu/core": "^0.
|
|
116
|
+
"@uniqu/core": "^0.2.0",
|
|
117
117
|
"better-sqlite3": "^12.6.2",
|
|
118
118
|
"ioredis": "^5.11.1",
|
|
119
|
-
"unplugin-atscript": "^0.2.
|
|
119
|
+
"unplugin-atscript": "^0.2.4"
|
|
120
120
|
},
|
|
121
121
|
"peerDependencies": {
|
|
122
|
-
"@atscript/db": "^0.1.
|
|
122
|
+
"@atscript/db": "^0.1.168"
|
|
123
123
|
},
|
|
124
124
|
"peerDependenciesMeta": {
|
|
125
125
|
"@atscript/db": {
|