@aooth/auth 0.2.3 → 0.2.5

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 CHANGED
@@ -1280,11 +1280,14 @@ var AuthCredential = class {
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.
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`).
1286
1289
  */
1287
- const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests. Please try again in {{delta}}." };
1290
+ const RATE_LIMIT_MESSAGES = Object.freeze({ RATE_LIMITED: "Too many requests. Retry after {retryAfter} s." });
1288
1291
  /** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
1289
1292
  const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
1290
1293
  const DURATION_UNITS = {
@@ -1357,10 +1360,21 @@ function parseRateLimitRule(input) {
1357
1360
  }
1358
1361
  /**
1359
1362
  * Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
1360
- * `{{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.
1361
1366
  */
1362
1367
  function renderRateLimitMessage(template, rule, retryAfterMs) {
1363
- return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
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
+ };
1364
1378
  }
1365
1379
  // src/rate-limit/store.ts
1366
1380
  /**
@@ -1548,9 +1562,7 @@ var RateLimiter = class {
1548
1562
  code: "RATE_LIMITED",
1549
1563
  params: {
1550
1564
  policy: scope,
1551
- limit: governing.rule.limit,
1552
- window: governing.rule.window / 1e3,
1553
- retryAfter: Math.ceil(resetAfterMs / 1e3)
1565
+ ...rateLimitParams(governing.rule, resetAfterMs)
1554
1566
  },
1555
1567
  message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
1556
1568
  }
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. 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.
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 {
@@ -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. 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.
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 {
@@ -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
@@ -1279,11 +1279,14 @@ var AuthCredential = class {
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.
1282
+ * Default English message template per rate-limit code, with `{name}`
1283
+ * placeholders filled from the 429's {@link RateLimitParams}. The 429 body
1284
+ * carries the `code` and those params, so a client or a server-side
1285
+ * error-body hook can translate the rejection without parsing this text
1286
+ * (`@aooth/auth-moost` registers this catalogue with moost's
1287
+ * `registerMessages`).
1285
1288
  */
1286
- const RATE_LIMIT_MESSAGES = { RATE_LIMITED: "Too many requests. Please try again in {{delta}}." };
1289
+ const RATE_LIMIT_MESSAGES = Object.freeze({ RATE_LIMITED: "Too many requests. Retry after {retryAfter} s." });
1287
1290
  /** The built-in 429 message template (`RATE_LIMIT_MESSAGES.RATE_LIMITED`). */
1288
1291
  const DEFAULT_RATE_LIMIT_MESSAGE = RATE_LIMIT_MESSAGES.RATE_LIMITED;
1289
1292
  const DURATION_UNITS = {
@@ -1356,10 +1359,21 @@ function parseRateLimitRule(input) {
1356
1359
  }
1357
1360
  /**
1358
1361
  * Render a 429 message template. Placeholders: `{{limit}}` (alias `{{max}}`),
1359
- * `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs}.
1362
+ * `{{window}}` and `{{delta}}` — both humanized via {@link formatDurationMs};
1363
+ * and the 429's params `{limit}`, `{window}` and `{retryAfter}` (seconds),
1364
+ * the `{name}` form a translator uses.
1360
1365
  */
1361
1366
  function renderRateLimitMessage(template, rule, retryAfterMs) {
1362
- return template.replaceAll("{{limit}}", String(rule.limit)).replaceAll("{{max}}", String(rule.limit)).replaceAll("{{window}}", formatDurationMs(rule.window)).replaceAll("{{delta}}", formatDurationMs(retryAfterMs));
1367
+ const params = rateLimitParams(rule, retryAfterMs);
1368
+ 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]));
1369
+ }
1370
+ /** The 429's `{limit}`, `{window}` (s) and `{retryAfter}` (s) params. */
1371
+ function rateLimitParams(rule, retryAfterMs) {
1372
+ return {
1373
+ limit: rule.limit,
1374
+ window: rule.window / 1e3,
1375
+ retryAfter: Math.ceil(retryAfterMs / 1e3)
1376
+ };
1363
1377
  }
1364
1378
  // src/rate-limit/store.ts
1365
1379
  /**
@@ -1547,9 +1561,7 @@ var RateLimiter = class {
1547
1561
  code: "RATE_LIMITED",
1548
1562
  params: {
1549
1563
  policy: scope,
1550
- limit: governing.rule.limit,
1551
- window: governing.rule.window / 1e3,
1552
- retryAfter: Math.ceil(resetAfterMs / 1e3)
1564
+ ...rateLimitParams(governing.rule, resetAfterMs)
1553
1565
  },
1554
1566
  message: renderRateLimitMessage(governing.rule.message ?? opts?.defaultMessage ?? DEFAULT_RATE_LIMIT_MESSAGE, governing.rule, resetAfterMs)
1555
1567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aooth/auth",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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.3"
107
+ "@aooth/user": "0.2.5"
108
108
  },
109
109
  "devDependencies": {
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",
110
+ "@atscript/core": "^0.2.8",
111
+ "@atscript/db": "^0.1.171",
112
+ "@atscript/db-sql-tools": "^0.1.171",
113
+ "@atscript/db-sqlite": "^0.1.171",
114
+ "@atscript/typescript": "^0.2.8",
115
115
  "@types/better-sqlite3": "^7.6.13",
116
- "@uniqu/core": "^0.2.0",
116
+ "@uniqu/core": "^0.2.1",
117
117
  "better-sqlite3": "^12.6.2",
118
118
  "ioredis": "^5.11.1",
119
- "unplugin-atscript": "^0.2.4"
119
+ "unplugin-atscript": "^0.2.8"
120
120
  },
121
121
  "peerDependencies": {
122
- "@atscript/db": "^0.1.168"
122
+ "@atscript/db": "^0.1.171"
123
123
  },
124
124
  "peerDependenciesMeta": {
125
125
  "@atscript/db": {