@aooth/auth 0.2.4 → 0.2.6
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 +22 -9
- package/dist/index.d.cts +22 -5
- package/dist/index.d.mts +22 -5
- package/dist/index.mjs +22 -9
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -479,6 +479,7 @@ var CredentialStoreEncapsulated = class {
|
|
|
479
479
|
decrypt(token) {
|
|
480
480
|
try {
|
|
481
481
|
const blob = Buffer.from(token, "base64url");
|
|
482
|
+
if (blob.toString("base64url") !== token) return null;
|
|
482
483
|
if (blob.length < 29) return null;
|
|
483
484
|
const iv = blob.subarray(0, IV_LEN);
|
|
484
485
|
const authTag = blob.subarray(blob.length - TAG_LEN);
|
|
@@ -1280,11 +1281,14 @@ var AuthCredential = class {
|
|
|
1280
1281
|
};
|
|
1281
1282
|
// src/rate-limit/rules.ts
|
|
1282
1283
|
/**
|
|
1283
|
-
* Default English message template per rate-limit code
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1284
|
+
* Default English message template per rate-limit code, with `{name}`
|
|
1285
|
+
* placeholders filled from the 429's {@link RateLimitParams}. The 429 body
|
|
1286
|
+
* carries the `code` and those params, so a client or a server-side
|
|
1287
|
+
* error-body hook can translate the rejection without parsing this text
|
|
1288
|
+
* (`@aooth/auth-moost` registers this catalogue with moost's
|
|
1289
|
+
* `registerMessages`).
|
|
1286
1290
|
*/
|
|
1287
|
-
const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests.
|
|
1291
|
+
const RATE_LIMIT_MESSAGES = Object.freeze({ RATE_LIMITED: "Too many requests. Retry after {retryAfter} s." });
|
|
1288
1292
|
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
1289
1293
|
const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
|
|
1290
1294
|
const DURATION_UNITS = {
|
|
@@ -1357,10 +1361,21 @@ function parseRateLimitRule(input) {
|
|
|
1357
1361
|
}
|
|
1358
1362
|
/**
|
|
1359
1363
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
1360
|
-
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}
|
|
1364
|
+
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs};
|
|
1365
|
+
* and the 429's params `{limit}`, `{window}` and `{retryAfter}` (seconds),
|
|
1366
|
+
* the `{name}` form a translator uses.
|
|
1361
1367
|
*/
|
|
1362
1368
|
function renderRateLimitMessage(template, rule, retryAfterMs) {
|
|
1363
|
-
|
|
1369
|
+
const params = rateLimitParams(rule, retryAfterMs);
|
|
1370
|
+
return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs)).replace(/\{(limit|window|retryAfter)\}/g, (_, name) => String(params[name]));
|
|
1371
|
+
}
|
|
1372
|
+
/** The 429's `{limit}`, `{window}` (s) and `{retryAfter}` (s) params. */
|
|
1373
|
+
function rateLimitParams(rule, retryAfterMs) {
|
|
1374
|
+
return {
|
|
1375
|
+
limit: rule.limit,
|
|
1376
|
+
window: rule.window / 1e3,
|
|
1377
|
+
retryAfter: Math.ceil(retryAfterMs / 1e3)
|
|
1378
|
+
};
|
|
1364
1379
|
}
|
|
1365
1380
|
// src/rate-limit/store.ts
|
|
1366
1381
|
/**
|
|
@@ -1548,9 +1563,7 @@ var RateLimiter = class {
|
|
|
1548
1563
|
code: "RATE_LIMITED",
|
|
1549
1564
|
params: {
|
|
1550
1565
|
policy: scope,
|
|
1551
|
-
|
|
1552
|
-
window: governing.rule.window / 1e3,
|
|
1553
|
-
retryAfter: Math.ceil(resetAfterMs / 1e3)
|
|
1566
|
+
...rateLimitParams(governing.rule, resetAfterMs)
|
|
1554
1567
|
},
|
|
1555
1568
|
message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
|
|
1556
1569
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -242,9 +242,12 @@ type RateLimitRuleInput = string | {
|
|
|
242
242
|
/** Machine-readable code of a rate-limit rejection (the 429 body's `code`). */
|
|
243
243
|
type RateLimitErrorCode = "RATE_LIMITED";
|
|
244
244
|
/**
|
|
245
|
-
* Default English message template per rate-limit code
|
|
246
|
-
*
|
|
247
|
-
*
|
|
245
|
+
* Default English message template per rate-limit code, with `{name}`
|
|
246
|
+
* placeholders filled from the 429's {@link RateLimitParams}. The 429 body
|
|
247
|
+
* carries the `code` and those params, so a client or a server-side
|
|
248
|
+
* error-body hook can translate the rejection without parsing this text
|
|
249
|
+
* (`@aooth/auth-moost` registers this catalogue with moost's
|
|
250
|
+
* `registerMessages`).
|
|
248
251
|
*/
|
|
249
252
|
export declare const RATE_LIMIT_MESSAGES: Readonly<Record<RateLimitErrorCode, string>>;
|
|
250
253
|
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
@@ -280,7 +283,9 @@ export declare function formatDurationMs(ms: number): string;
|
|
|
280
283
|
export declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
281
284
|
/**
|
|
282
285
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
283
|
-
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}
|
|
286
|
+
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs};
|
|
287
|
+
* and the 429's params `{limit}`, `{window}` and `{retryAfter}` (seconds),
|
|
288
|
+
* the `{name}` form a translator uses.
|
|
284
289
|
*/
|
|
285
290
|
export declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
286
291
|
interface RateLimiterOptions {
|
|
@@ -371,7 +376,7 @@ export declare class RateLimiter {
|
|
|
371
376
|
* consumer-triggered security notice (e.g. impossible-travel from a
|
|
372
377
|
* `resolveRiskStepUp` override) — never auto-sent by the framework.
|
|
373
378
|
*/
|
|
374
|
-
type AuthEmailKind = "recovery.magicLink" | "invite.magicLink" | "mfa.code" | "login.pincode" | "recovery.pincode" | "invite.pincode" | "notifyNewDevice" | "securityAlert";
|
|
379
|
+
type AuthEmailKind = "recovery.magicLink" | "login.magicLink" | "invite.magicLink" | "mfa.code" | "login.pincode" | "recovery.pincode" | "invite.pincode" | "notifyNewDevice" | "securityAlert";
|
|
375
380
|
/**
|
|
376
381
|
* Structured event passed to `EmailSender.send()` from inside the auth
|
|
377
382
|
* workflows. Flat and serialisable so consumers can route it to any
|
|
@@ -390,6 +395,12 @@ interface AuthEmailEvent {
|
|
|
390
395
|
username?: string;
|
|
391
396
|
/** Free-form payload (e.g. invite-side `roles: string[]`, notify-side `ip`). */
|
|
392
397
|
metadata?: Record<string, unknown>;
|
|
398
|
+
/**
|
|
399
|
+
* The locale of the request that emitted the event (moost `useLocale()`),
|
|
400
|
+
* for a localized email. Absent outside a request or when the request has
|
|
401
|
+
* no locale.
|
|
402
|
+
*/
|
|
403
|
+
locale?: string;
|
|
393
404
|
}
|
|
394
405
|
/**
|
|
395
406
|
* Transport interface implemented by consumers. Aoothjs ships no
|
|
@@ -423,6 +434,12 @@ interface AuthSmsEvent {
|
|
|
423
434
|
ttlMs: number;
|
|
424
435
|
/** User id when known (omitted for pre-resolved flows). */
|
|
425
436
|
userId?: string;
|
|
437
|
+
/**
|
|
438
|
+
* The locale of the request that emitted the event (moost `useLocale()`),
|
|
439
|
+
* for a localized text. Absent outside a request or when the request has
|
|
440
|
+
* no locale.
|
|
441
|
+
*/
|
|
442
|
+
locale?: string;
|
|
426
443
|
}
|
|
427
444
|
/**
|
|
428
445
|
* Transport interface implemented by consumers. Aoothjs ships no concrete
|
package/dist/index.d.mts
CHANGED
|
@@ -242,9 +242,12 @@ type RateLimitRuleInput = string | {
|
|
|
242
242
|
/** Machine-readable code of a rate-limit rejection (the 429 body's `code`). */
|
|
243
243
|
type RateLimitErrorCode = "RATE_LIMITED";
|
|
244
244
|
/**
|
|
245
|
-
* Default English message template per rate-limit code
|
|
246
|
-
*
|
|
247
|
-
*
|
|
245
|
+
* Default English message template per rate-limit code, with `{name}`
|
|
246
|
+
* placeholders filled from the 429's {@link RateLimitParams}. The 429 body
|
|
247
|
+
* carries the `code` and those params, so a client or a server-side
|
|
248
|
+
* error-body hook can translate the rejection without parsing this text
|
|
249
|
+
* (`@aooth/auth-moost` registers this catalogue with moost's
|
|
250
|
+
* `registerMessages`).
|
|
248
251
|
*/
|
|
249
252
|
export declare const RATE_LIMIT_MESSAGES: Readonly<Record<RateLimitErrorCode, string>>;
|
|
250
253
|
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
@@ -280,7 +283,9 @@ export declare function formatDurationMs(ms: number): string;
|
|
|
280
283
|
export declare function parseRateLimitRule(input: RateLimitRuleInput): RateLimitRule;
|
|
281
284
|
/**
|
|
282
285
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
283
|
-
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}
|
|
286
|
+
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs};
|
|
287
|
+
* and the 429's params `{limit}`, `{window}` and `{retryAfter}` (seconds),
|
|
288
|
+
* the `{name}` form a translator uses.
|
|
284
289
|
*/
|
|
285
290
|
export declare function renderRateLimitMessage(template: string, rule: RateLimitRule, retryAfterMs: number): string;
|
|
286
291
|
interface RateLimiterOptions {
|
|
@@ -371,7 +376,7 @@ export declare class RateLimiter {
|
|
|
371
376
|
* consumer-triggered security notice (e.g. impossible-travel from a
|
|
372
377
|
* `resolveRiskStepUp` override) — never auto-sent by the framework.
|
|
373
378
|
*/
|
|
374
|
-
type AuthEmailKind = "recovery.magicLink" | "invite.magicLink" | "mfa.code" | "login.pincode" | "recovery.pincode" | "invite.pincode" | "notifyNewDevice" | "securityAlert";
|
|
379
|
+
type AuthEmailKind = "recovery.magicLink" | "login.magicLink" | "invite.magicLink" | "mfa.code" | "login.pincode" | "recovery.pincode" | "invite.pincode" | "notifyNewDevice" | "securityAlert";
|
|
375
380
|
/**
|
|
376
381
|
* Structured event passed to `EmailSender.send()` from inside the auth
|
|
377
382
|
* workflows. Flat and serialisable so consumers can route it to any
|
|
@@ -390,6 +395,12 @@ interface AuthEmailEvent {
|
|
|
390
395
|
username?: string;
|
|
391
396
|
/** Free-form payload (e.g. invite-side `roles: string[]`, notify-side `ip`). */
|
|
392
397
|
metadata?: Record<string, unknown>;
|
|
398
|
+
/**
|
|
399
|
+
* The locale of the request that emitted the event (moost `useLocale()`),
|
|
400
|
+
* for a localized email. Absent outside a request or when the request has
|
|
401
|
+
* no locale.
|
|
402
|
+
*/
|
|
403
|
+
locale?: string;
|
|
393
404
|
}
|
|
394
405
|
/**
|
|
395
406
|
* Transport interface implemented by consumers. Aoothjs ships no
|
|
@@ -423,6 +434,12 @@ interface AuthSmsEvent {
|
|
|
423
434
|
ttlMs: number;
|
|
424
435
|
/** User id when known (omitted for pre-resolved flows). */
|
|
425
436
|
userId?: string;
|
|
437
|
+
/**
|
|
438
|
+
* The locale of the request that emitted the event (moost `useLocale()`),
|
|
439
|
+
* for a localized text. Absent outside a request or when the request has
|
|
440
|
+
* no locale.
|
|
441
|
+
*/
|
|
442
|
+
locale?: string;
|
|
426
443
|
}
|
|
427
444
|
/**
|
|
428
445
|
* Transport interface implemented by consumers. Aoothjs ships no concrete
|
package/dist/index.mjs
CHANGED
|
@@ -478,6 +478,7 @@ var CredentialStoreEncapsulated = class {
|
|
|
478
478
|
decrypt(token) {
|
|
479
479
|
try {
|
|
480
480
|
const blob = Buffer.from(token, "base64url");
|
|
481
|
+
if (blob.toString("base64url") !== token) return null;
|
|
481
482
|
if (blob.length < 29) return null;
|
|
482
483
|
const iv = blob.subarray(0, IV_LEN);
|
|
483
484
|
const authTag = blob.subarray(blob.length - TAG_LEN);
|
|
@@ -1279,11 +1280,14 @@ var AuthCredential = class {
|
|
|
1279
1280
|
};
|
|
1280
1281
|
// src/rate-limit/rules.ts
|
|
1281
1282
|
/**
|
|
1282
|
-
* Default English message template per rate-limit code
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1283
|
+
* Default English message template per rate-limit code, with `{name}`
|
|
1284
|
+
* placeholders filled from the 429's {@link RateLimitParams}. The 429 body
|
|
1285
|
+
* carries the `code` and those params, so a client or a server-side
|
|
1286
|
+
* error-body hook can translate the rejection without parsing this text
|
|
1287
|
+
* (`@aooth/auth-moost` registers this catalogue with moost's
|
|
1288
|
+
* `registerMessages`).
|
|
1285
1289
|
*/
|
|
1286
|
-
const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests.
|
|
1290
|
+
const RATE_LIMIT_MESSAGES = Object.freeze({ RATE_LIMITED: "Too many requests. Retry after {retryAfter} s." });
|
|
1287
1291
|
/** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
|
|
1288
1292
|
const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
|
|
1289
1293
|
const DURATION_UNITS = {
|
|
@@ -1356,10 +1360,21 @@ function parseRateLimitRule(input) {
|
|
|
1356
1360
|
}
|
|
1357
1361
|
/**
|
|
1358
1362
|
* Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
|
|
1359
|
-
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}
|
|
1363
|
+
* `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs};
|
|
1364
|
+
* and the 429's params `{limit}`, `{window}` and `{retryAfter}` (seconds),
|
|
1365
|
+
* the `{name}` form a translator uses.
|
|
1360
1366
|
*/
|
|
1361
1367
|
function renderRateLimitMessage(template, rule, retryAfterMs) {
|
|
1362
|
-
|
|
1368
|
+
const params = rateLimitParams(rule, retryAfterMs);
|
|
1369
|
+
return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs)).replace(/\{(limit|window|retryAfter)\}/g, (_, name) => String(params[name]));
|
|
1370
|
+
}
|
|
1371
|
+
/** The 429's `{limit}`, `{window}` (s) and `{retryAfter}` (s) params. */
|
|
1372
|
+
function rateLimitParams(rule, retryAfterMs) {
|
|
1373
|
+
return {
|
|
1374
|
+
limit: rule.limit,
|
|
1375
|
+
window: rule.window / 1e3,
|
|
1376
|
+
retryAfter: Math.ceil(retryAfterMs / 1e3)
|
|
1377
|
+
};
|
|
1363
1378
|
}
|
|
1364
1379
|
// src/rate-limit/store.ts
|
|
1365
1380
|
/**
|
|
@@ -1547,9 +1562,7 @@ var RateLimiter = class {
|
|
|
1547
1562
|
code: "RATE_LIMITED",
|
|
1548
1563
|
params: {
|
|
1549
1564
|
policy: scope,
|
|
1550
|
-
|
|
1551
|
-
window: governing.rule.window / 1e3,
|
|
1552
|
-
retryAfter: Math.ceil(resetAfterMs / 1e3)
|
|
1565
|
+
...rateLimitParams(governing.rule, resetAfterMs)
|
|
1553
1566
|
},
|
|
1554
1567
|
message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
|
|
1555
1568
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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.6"
|
|
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.9",
|
|
111
|
+
"@atscript/db": "^0.1.174",
|
|
112
|
+
"@atscript/db-sql-tools": "^0.1.174",
|
|
113
|
+
"@atscript/db-sqlite": "^0.1.174",
|
|
114
|
+
"@atscript/typescript": "^0.2.9",
|
|
115
115
|
"@types/better-sqlite3": "^7.6.13",
|
|
116
|
-
"@uniqu/core": "^0.2.
|
|
116
|
+
"@uniqu/core": "^0.2.1",
|
|
117
117
|
"better-sqlite3": "^12.6.2",
|
|
118
118
|
"ioredis": "^5.11.1",
|
|
119
|
-
"unplugin-atscript": "^0.2.
|
|
119
|
+
"unplugin-atscript": "^0.2.9"
|
|
120
120
|
},
|
|
121
121
|
"peerDependencies": {
|
|
122
|
-
"@atscript/db": "^0.1.
|
|
122
|
+
"@atscript/db": "^0.1.174"
|
|
123
123
|
},
|
|
124
124
|
"peerDependenciesMeta": {
|
|
125
125
|
"@atscript/db": {
|