@proteinjs/user-server 1.22.3 → 1.23.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/generated/index.js +1 -1
  3. package/dist/generated/index.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/src/routes/executePasswordReset.js +3 -1
  8. package/dist/src/routes/executePasswordReset.js.map +1 -1
  9. package/dist/src/routes/initiatePasswordReset.d.ts.map +1 -1
  10. package/dist/src/routes/initiatePasswordReset.js +14 -12
  11. package/dist/src/routes/initiatePasswordReset.js.map +1 -1
  12. package/dist/src/routes/login.js +18 -14
  13. package/dist/src/routes/login.js.map +1 -1
  14. package/dist/src/services/Signup.d.ts +10 -0
  15. package/dist/src/services/Signup.d.ts.map +1 -1
  16. package/dist/src/services/Signup.js +51 -21
  17. package/dist/src/services/Signup.js.map +1 -1
  18. package/dist/src/throttle/MemoryThrottleWindowStore.d.ts +28 -0
  19. package/dist/src/throttle/MemoryThrottleWindowStore.d.ts.map +1 -0
  20. package/dist/src/throttle/MemoryThrottleWindowStore.js +108 -0
  21. package/dist/src/throttle/MemoryThrottleWindowStore.js.map +1 -0
  22. package/dist/src/throttle/PasswordResetThrottle.d.ts +9 -8
  23. package/dist/src/throttle/PasswordResetThrottle.d.ts.map +1 -1
  24. package/dist/src/throttle/PasswordResetThrottle.js +63 -15
  25. package/dist/src/throttle/PasswordResetThrottle.js.map +1 -1
  26. package/dist/src/throttle/SignInThrottle.d.ts +21 -15
  27. package/dist/src/throttle/SignInThrottle.d.ts.map +1 -1
  28. package/dist/src/throttle/SignInThrottle.js +94 -25
  29. package/dist/src/throttle/SignInThrottle.js.map +1 -1
  30. package/dist/src/throttle/SlidingWindow.d.ts +6 -4
  31. package/dist/src/throttle/SlidingWindow.d.ts.map +1 -1
  32. package/dist/src/throttle/SlidingWindow.js +6 -4
  33. package/dist/src/throttle/SlidingWindow.js.map +1 -1
  34. package/dist/src/throttle/StoredWindow.d.ts +59 -0
  35. package/dist/src/throttle/StoredWindow.d.ts.map +1 -0
  36. package/dist/src/throttle/StoredWindow.js +209 -0
  37. package/dist/src/throttle/StoredWindow.js.map +1 -0
  38. package/dist/src/throttle/ThrottleWindowStore.d.ts +38 -0
  39. package/dist/src/throttle/ThrottleWindowStore.d.ts.map +1 -0
  40. package/dist/src/throttle/ThrottleWindowStore.js +3 -0
  41. package/dist/src/throttle/ThrottleWindowStore.js.map +1 -0
  42. package/dist/test/MemoryThrottleWindowStore.test.d.ts +2 -0
  43. package/dist/test/MemoryThrottleWindowStore.test.d.ts.map +1 -0
  44. package/dist/test/MemoryThrottleWindowStore.test.js +210 -0
  45. package/dist/test/MemoryThrottleWindowStore.test.js.map +1 -0
  46. package/dist/test/NoAddressesInLogs.integration.test.js +13 -11
  47. package/dist/test/NoAddressesInLogs.integration.test.js.map +1 -1
  48. package/dist/test/SharedThrottleWindows.integration.test.d.ts +2 -0
  49. package/dist/test/SharedThrottleWindows.integration.test.d.ts.map +1 -0
  50. package/dist/test/SharedThrottleWindows.integration.test.js +756 -0
  51. package/dist/test/SharedThrottleWindows.integration.test.js.map +1 -0
  52. package/dist/test/SignupRace.integration.test.d.ts +2 -0
  53. package/dist/test/SignupRace.integration.test.d.ts.map +1 -0
  54. package/dist/test/SignupRace.integration.test.js +320 -0
  55. package/dist/test/SignupRace.integration.test.js.map +1 -0
  56. package/dist/test/UserServerTestEnvironment.d.ts.map +1 -1
  57. package/dist/test/UserServerTestEnvironment.js +3 -0
  58. package/dist/test/UserServerTestEnvironment.js.map +1 -1
  59. package/generated/index.ts +1 -1
  60. package/index.ts +4 -0
  61. package/package.json +5 -5
  62. package/src/routes/executePasswordReset.ts +1 -1
  63. package/src/routes/initiatePasswordReset.ts +2 -1
  64. package/src/routes/login.ts +2 -2
  65. package/src/services/Signup.ts +30 -11
  66. package/src/throttle/MemoryThrottleWindowStore.ts +60 -0
  67. package/src/throttle/PasswordResetThrottle.ts +14 -11
  68. package/src/throttle/SignInThrottle.ts +27 -19
  69. package/src/throttle/SlidingWindow.ts +6 -4
  70. package/src/throttle/StoredWindow.ts +132 -0
  71. package/src/throttle/ThrottleWindowStore.ts +41 -0
  72. package/test/MemoryThrottleWindowStore.test.ts +74 -0
  73. package/test/NoAddressesInLogs.integration.test.ts +9 -8
  74. package/test/SharedThrottleWindows.integration.test.ts +407 -0
  75. package/test/SignupRace.integration.test.ts +230 -0
  76. package/test/UserServerTestEnvironment.ts +3 -0
@@ -1,7 +1,44 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.passwordResetThrottle = exports.PasswordResetThrottle = void 0;
4
40
  var SlidingWindow_1 = require("./SlidingWindow");
41
+ var StoredWindow_1 = require("./StoredWindow");
5
42
  /**
6
43
  * The password-reset door's two windows (`POST /user/initiate-password-reset`), keyed by digests
7
44
  * (`RequestDigests`), never by an address. Both count every request, whether or not the address
@@ -10,11 +47,12 @@ var SlidingWindow_1 = require("./SlidingWindow");
10
47
  * same sentence as always (see the route).
11
48
  *
12
49
  * These sit on top of the account row's own five-minute gap between links, which spans replicas
13
- * (it is stored); the windows are in process memory (`SlidingWindow`): per replica. A
14
- * deployment of three replicas behind a load balancer (up to ten under load) keeps three sets
15
- * of windows, so its effective ceiling is ~3× the numbers below (up to ~10×) — for one address
16
- * still at most one mail per five minutes. Friction, not the wall — a shared store is a
17
- * separate step.
50
+ * (it is stored). The per-address window is a `StoredWindow`: counted in the store the deployment
51
+ * registers (`DefaultThrottleWindowStoreFactory`), so with a shared store it is one count across
52
+ * every replica and survives a deploy; while that store fails it counts in this process's memory
53
+ * (the named fallback, see `StoredWindow`), so the door still mints and mails. The per-client window stays in process memory (`SlidingWindow`), per
54
+ * replica — the second line behind a per-address limit at the load balancer (see
55
+ * `SignInThrottle`).
18
56
  */
19
57
  var PasswordResetThrottle = /** @class */ (function () {
20
58
  function PasswordResetThrottle(options) {
@@ -23,7 +61,8 @@ var PasswordResetThrottle = /** @class */ (function () {
23
61
  limit: PasswordResetThrottle.CLIENT_LIMIT,
24
62
  now: options === null || options === void 0 ? void 0 : options.now,
25
63
  });
26
- this.accounts = new SlidingWindow_1.SlidingWindow({
64
+ this.accounts = new StoredWindow_1.StoredWindow({
65
+ name: 'reset-address',
27
66
  windowMs: PasswordResetThrottle.ACCOUNT_WINDOW_MS,
28
67
  limit: PasswordResetThrottle.ACCOUNT_LIMIT,
29
68
  now: options === null || options === void 0 ? void 0 : options.now,
@@ -31,13 +70,22 @@ var PasswordResetThrottle = /** @class */ (function () {
31
70
  }
32
71
  /** Count this request and answer which window refuses it, if any. */
33
72
  PasswordResetThrottle.prototype.admit = function (client, account) {
34
- if (this.clients.hit(client)) {
35
- return 'client';
36
- }
37
- if (this.accounts.hit(account)) {
38
- return 'account';
39
- }
40
- return undefined;
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ if (this.clients.hit(client)) {
78
+ return [2 /*return*/, 'client'];
79
+ }
80
+ return [4 /*yield*/, this.accounts.hit(account)];
81
+ case 1:
82
+ if (_a.sent()) {
83
+ return [2 /*return*/, 'account'];
84
+ }
85
+ return [2 /*return*/, undefined];
86
+ }
87
+ });
88
+ });
41
89
  };
42
90
  /**
43
91
  * Per client: 10 requests an hour. Someone asking for their own address again, or a household
@@ -46,8 +94,8 @@ var PasswordResetThrottle = /** @class */ (function () {
46
94
  PasswordResetThrottle.CLIENT_LIMIT = 10;
47
95
  PasswordResetThrottle.CLIENT_WINDOW_MS = 60 * 60 * 1000;
48
96
  /**
49
- * Per address: 3 requests an hour. A person whose mail is slow asks once or twice more; beyond
50
- * that it is mail aimed at somebody's inbox.
97
+ * Per address: 3 requests in an hour's window. A person whose mail is slow asks once or twice
98
+ * more; beyond that it is mail aimed at somebody's inbox.
51
99
  */
52
100
  PasswordResetThrottle.ACCOUNT_LIMIT = 3;
53
101
  PasswordResetThrottle.ACCOUNT_WINDOW_MS = 60 * 60 * 1000;
@@ -1 +1 @@
1
- {"version":3,"file":"PasswordResetThrottle.js","sourceRoot":"","sources":["../../../src/throttle/PasswordResetThrottle.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAGhD;;;;;;;;;;;;;GAaG;AACH;IAkBE,+BAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,6BAAa,CAAC;YAC/B,QAAQ,EAAE,qBAAqB,CAAC,gBAAgB;YAChD,KAAK,EAAE,qBAAqB,CAAC,YAAY;YACzC,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAa,CAAC;YAChC,QAAQ,EAAE,qBAAqB,CAAC,iBAAiB;YACjD,KAAK,EAAE,qBAAqB,CAAC,aAAa;YAC1C,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;SAClB,CAAC,CAAC;IACL,CAAC;IAED,qEAAqE;IACrE,qCAAK,GAAL,UAAM,MAAc,EAAE,OAAe;QACnC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC5B,OAAO,QAAQ,CAAC;SACjB;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAC9B,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAvCD;;;OAGG;IACqB,kCAAY,GAAG,EAAE,CAAC;IAClB,sCAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,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,EAAC;;;;KAClB;IAxCD;;;OAGG;IACqB,kCAAY,GAAG,EAAE,CAAC;IAClB,sCAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE1D;;;OAGG;IACqB,mCAAa,GAAG,CAAC,CAAC;IAClB,uCAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IA6B7D,4BAAC;CAAA,AA1CD,IA0CC;AA1CY,sDAAqB;AA4ClC,gFAAgF;AACnE,QAAA,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC"}
@@ -16,13 +16,20 @@ export type ThrottleWindow = 'client' | 'account';
16
16
  * has an account, in the same time a refused password takes (the door runs the same password
17
17
  * check and discards its verdict).
18
18
  *
19
- * The windows are in process memory (`SlidingWindow`): per replica. A deployment of three
20
- * replicas behind a load balancer (up to ten under load) keeps three sets of windows, so its
21
- * effective ceiling is ~3× the numbers below (up to ~10×). Friction, not the wall — a shared
22
- * store is a separate step.
19
+ * WHERE THE COUNTS LIVE. The account window is a `StoredWindow`: counted in the store the
20
+ * deployment registers (`DefaultThrottleWindowStoreFactory`), so with a shared store it is ONE
21
+ * count across every replica and survives a deploy; while that store fails it counts in this
22
+ * process's memory (the named fallback, see `StoredWindow`). The client window stays in process memory (`SlidingWindow`), per replica: a
23
+ * deployment that needs one per-address wall across replicas puts it in front of the servers (a
24
+ * rate limit at the load balancer, keyed on the client address); this window is the second line
25
+ * behind it, and keeping it local keeps the per-try forgiveness of a success exact and cheap.
23
26
  */
24
27
  export declare class SignInThrottle {
25
- /** What a throttled try is told — in plain words, the same for every address, known or not. */
28
+ /**
29
+ * What a throttled try is told — in plain words, the same for every address, known or not. The
30
+ * sign-in, sign-up and reset forms say the same when a load balancer's per-address limit answers
31
+ * 429 in front of the door (@proteinjs/user-ui `AuthApi.TOO_MANY_ATTEMPTS`).
32
+ */
26
33
  static readonly ANSWER = "Too many attempts. Try again in a few minutes.";
27
34
  /**
28
35
  * Per client: 50 tries that are not successes in 10 minutes (the founder's number, 2026-09-23).
@@ -34,11 +41,10 @@ export declare class SignInThrottle {
34
41
  private static readonly CLIENT_LIMIT;
35
42
  private static readonly CLIENT_WINDOW_MS;
36
43
  /**
37
- * Per account: 10 tries in 15 minutes (a success clears them, so only wrong ones ever add up).
38
- * Someone who has forgotten a password tries a handful and asks for a reset link; ten wrong in
39
- * a quarter of an hour is guessing, and counting per account holds however many devices the
40
- * guesses come from. "A few minutes" in the answer is honest: the oldest try leaves the window
41
- * within 15.
44
+ * Per account: 10 tries in a 15-minute window (a success clears them, so only wrong ones ever add
45
+ * up). Someone who has forgotten a password tries a handful and asks for a reset link; ten wrong
46
+ * in a quarter of an hour is guessing, and counting per account holds however many devices the
47
+ * guesses come from. "A few minutes" in the answer is honest: the window ends within 15.
42
48
  */
43
49
  private static readonly ACCOUNT_LIMIT;
44
50
  private static readonly ACCOUNT_WINDOW_MS;
@@ -54,13 +60,13 @@ export declare class SignInThrottle {
54
60
  * count is taken here, before the try is judged, so tries in flight at once cannot all pass
55
61
  * the window; a success clears it (`recordSuccess`).
56
62
  */
57
- admit(client: string, account?: string): ThrottleWindow | undefined;
63
+ admit(client: string, account?: string): Promise<ThrottleWindow | undefined>;
58
64
  /**
59
- * The account proved itself: its window opens again. When it was a sign-in try from `client`
60
- * (rather than a reset link redeemed), that try is forgiven — a success never counts against
61
- * the device.
65
+ * The account proved itself: its window opens again, on every replica. When it was a sign-in try
66
+ * from `client` (rather than a reset link redeemed), that try is forgiven — a success never
67
+ * counts against the device.
62
68
  */
63
- recordSuccess(account: string, client?: string): void;
69
+ recordSuccess(account: string, client?: string): Promise<void>;
64
70
  }
65
71
  /** The process-wide windows the sign-in door shares — they must span requests. */
66
72
  export declare const signInThrottle: SignInThrottle;
@@ -1 +1 @@
1
- {"version":3,"file":"SignInThrottle.d.ts","sourceRoot":"","sources":["../../../src/throttle/SignInThrottle.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,MAAM,MAAM,cAAc,GAAG,QAAQ,G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AkB;IAE1D;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAM;IAC3C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAkB;IAE3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAE5B,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE;IAc5C;;;;;;OAMG;IACG,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAUlF;;;;OAIG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMrE;AAED,kFAAkF;AAClF,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
@@ -1,7 +1,44 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.signInThrottle = exports.SignInThrottle = void 0;
4
40
  var SlidingWindow_1 = require("./SlidingWindow");
41
+ var StoredWindow_1 = require("./StoredWindow");
5
42
  /**
6
43
  * The sign-in door's two windows (`POST /user/login`), keyed by digests (`RequestDigests`),
7
44
  * never by an address:
@@ -18,10 +55,13 @@ var SlidingWindow_1 = require("./SlidingWindow");
18
55
  * has an account, in the same time a refused password takes (the door runs the same password
19
56
  * check and discards its verdict).
20
57
  *
21
- * The windows are in process memory (`SlidingWindow`): per replica. A deployment of three
22
- * replicas behind a load balancer (up to ten under load) keeps three sets of windows, so its
23
- * effective ceiling is ~3× the numbers below (up to ~10×). Friction, not the wall — a shared
24
- * store is a separate step.
58
+ * WHERE THE COUNTS LIVE. The account window is a `StoredWindow`: counted in the store the
59
+ * deployment registers (`DefaultThrottleWindowStoreFactory`), so with a shared store it is ONE
60
+ * count across every replica and survives a deploy; while that store fails it counts in this
61
+ * process's memory (the named fallback, see `StoredWindow`). The client window stays in process memory (`SlidingWindow`), per replica: a
62
+ * deployment that needs one per-address wall across replicas puts it in front of the servers (a
63
+ * rate limit at the load balancer, keyed on the client address); this window is the second line
64
+ * behind it, and keeping it local keeps the per-try forgiveness of a success exact and cheap.
25
65
  */
26
66
  var SignInThrottle = /** @class */ (function () {
27
67
  function SignInThrottle(options) {
@@ -30,7 +70,8 @@ var SignInThrottle = /** @class */ (function () {
30
70
  limit: SignInThrottle.CLIENT_LIMIT,
31
71
  now: options === null || options === void 0 ? void 0 : options.now,
32
72
  });
33
- this.accounts = new SlidingWindow_1.SlidingWindow({
73
+ this.accounts = new StoredWindow_1.StoredWindow({
74
+ name: 'sign-in-account',
34
75
  windowMs: SignInThrottle.ACCOUNT_WINDOW_MS,
35
76
  limit: SignInThrottle.ACCOUNT_LIMIT,
36
77
  now: options === null || options === void 0 ? void 0 : options.now,
@@ -44,26 +85,55 @@ var SignInThrottle = /** @class */ (function () {
44
85
  * the window; a success clears it (`recordSuccess`).
45
86
  */
46
87
  SignInThrottle.prototype.admit = function (client, account) {
47
- if (this.clients.hit(client)) {
48
- return 'client';
49
- }
50
- if (account !== undefined && this.accounts.hit(account)) {
51
- return 'account';
52
- }
53
- return undefined;
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var _a;
90
+ return __generator(this, function (_b) {
91
+ switch (_b.label) {
92
+ case 0:
93
+ if (this.clients.hit(client)) {
94
+ return [2 /*return*/, 'client'];
95
+ }
96
+ _a = account !== undefined;
97
+ if (!_a) return [3 /*break*/, 2];
98
+ return [4 /*yield*/, this.accounts.hit(account)];
99
+ case 1:
100
+ _a = (_b.sent());
101
+ _b.label = 2;
102
+ case 2:
103
+ if (_a) {
104
+ return [2 /*return*/, 'account'];
105
+ }
106
+ return [2 /*return*/, undefined];
107
+ }
108
+ });
109
+ });
54
110
  };
55
111
  /**
56
- * The account proved itself: its window opens again. When it was a sign-in try from `client`
57
- * (rather than a reset link redeemed), that try is forgiven — a success never counts against
58
- * the device.
112
+ * The account proved itself: its window opens again, on every replica. When it was a sign-in try
113
+ * from `client` (rather than a reset link redeemed), that try is forgiven — a success never
114
+ * counts against the device.
59
115
  */
60
116
  SignInThrottle.prototype.recordSuccess = function (account, client) {
61
- this.accounts.clear(account);
62
- if (client !== undefined) {
63
- this.clients.forgive(client);
64
- }
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0:
121
+ if (client !== undefined) {
122
+ this.clients.forgive(client);
123
+ }
124
+ return [4 /*yield*/, this.accounts.clear(account)];
125
+ case 1:
126
+ _a.sent();
127
+ return [2 /*return*/];
128
+ }
129
+ });
130
+ });
65
131
  };
66
- /** What a throttled try is told — in plain words, the same for every address, known or not. */
132
+ /**
133
+ * What a throttled try is told — in plain words, the same for every address, known or not. The
134
+ * sign-in, sign-up and reset forms say the same when a load balancer's per-address limit answers
135
+ * 429 in front of the door (@proteinjs/user-ui `AuthApi.TOO_MANY_ATTEMPTS`).
136
+ */
67
137
  SignInThrottle.ANSWER = 'Too many attempts. Try again in a few minutes.';
68
138
  /**
69
139
  * Per client: 50 tries that are not successes in 10 minutes (the founder's number, 2026-09-23).
@@ -75,11 +145,10 @@ var SignInThrottle = /** @class */ (function () {
75
145
  SignInThrottle.CLIENT_LIMIT = 50;
76
146
  SignInThrottle.CLIENT_WINDOW_MS = 10 * 60 * 1000;
77
147
  /**
78
- * Per account: 10 tries in 15 minutes (a success clears them, so only wrong ones ever add up).
79
- * Someone who has forgotten a password tries a handful and asks for a reset link; ten wrong in
80
- * a quarter of an hour is guessing, and counting per account holds however many devices the
81
- * guesses come from. "A few minutes" in the answer is honest: the oldest try leaves the window
82
- * within 15.
148
+ * Per account: 10 tries in a 15-minute window (a success clears them, so only wrong ones ever add
149
+ * up). Someone who has forgotten a password tries a handful and asks for a reset link; ten wrong
150
+ * in a quarter of an hour is guessing, and counting per account holds however many devices the
151
+ * guesses come from. "A few minutes" in the answer is honest: the window ends within 15.
83
152
  */
84
153
  SignInThrottle.ACCOUNT_LIMIT = 10;
85
154
  SignInThrottle.ACCOUNT_WINDOW_MS = 15 * 60 * 1000;
@@ -1 +1 @@
1
- {"version":3,"file":"SignInThrottle.js","sourceRoot":"","sources":["../../../src/throttle/SignInThrottle.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAKhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IA2BE,wBAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,6BAAa,CAAC;YAC/B,QAAQ,EAAE,cAAc,CAAC,gBAAgB;YACzC,KAAK,EAAE,cAAc,CAAC,YAAY;YAClC,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAa,CAAC;YAChC,QAAQ,EAAE,cAAc,CAAC,iBAAiB;YAC1C,KAAK,EAAE,cAAc,CAAC,aAAa;YACnC,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;SAClB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,8BAAK,GAAL,UAAM,MAAc,EAAE,OAAgB;QACpC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC5B,OAAO,QAAQ,CAAC;SACjB;QACD,IAAI,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACvD,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,sCAAa,GA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AClB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACG,8BAAK,GAAX,UAAY,MAAc,EAAE,OAAgB;;;;;;wBAC1C,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;4BAC5B,sBAAO,QAAQ,EAAC;yBACjB;wBACG,KAAA,OAAO,KAAK,SAAS,CAAA;iCAArB,wBAAqB;wBAAK,qBAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAAjC,KAAA,CAAC,SAAgC,CAAC,CAAA;;;wBAA/D,QAAiE;4BAC/D,sBAAO,SAAS,EAAC;yBAClB;wBACD,sBAAO,SAAS,EAAC;;;;KAClB;IAED;;;;OAIG;IACG,sCAAa,GAAnB,UAAoB,OAAe,EAAE,MAAe;;;;;wBAClD,IAAI,MAAM,KAAK,SAAS,EAAE;4BACxB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;yBAC9B;wBACD,qBAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAA;;wBAAlC,SAAkC,CAAC;;;;;KACpC;IAtED;;;;OAIG;IACa,qBAAM,GAAG,gDAAgD,CAAC;IAE1E;;;;;;OAMG;IACqB,2BAAY,GAAG,EAAE,CAAC;IAClB,+BAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE1D;;;;;OAKG;IACqB,4BAAa,GAAG,EAAE,CAAC;IACnB,gCAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IA+C7D,qBAAC;CAAA,AAxED,IAwEC;AAxEY,wCAAc;AA0E3B,kFAAkF;AACrE,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * A per-key sliding window: how many attempts a key made in the last `windowMs`, against a
3
- * `limit`. The one window every throttled door shares — the sign-in and password-reset doors in
4
- * this package, and any consumer door throttling per client (lifted from the invite-request
5
- * door's per-IP throttle, which it replaces).
3
+ * `limit`. The per-CLIENT window the throttled doors share — the sign-in and password-reset doors
4
+ * in this package, and any consumer door throttling per client (lifted from the invite-request
5
+ * door's per-IP throttle, which it replaces). The windows that must hold across replicas (per
6
+ * account, per reset address) are `StoredWindow`s, counted in a shared `ThrottleWindowStore`.
6
7
  *
7
8
  * Held in process memory only, which is what makes it cheap and what bounds it:
8
9
  * - PER PROCESS. Each replica keeps its own windows, so behind a load balancer spreading a
9
10
  * client over N replicas the effective ceiling is ~N× the limit; a restart forgets them.
10
- * A throttle built on this is friction, not the wall. A shared store is a separate step.
11
+ * A throttle built on this is friction, not the wall — the per-address wall across replicas
12
+ * belongs in front of the servers (a rate limit at the load balancer).
11
13
  * - BOUNDED. At most `maxKeys` keys are tracked; at the bound the oldest-touched key is
12
14
  * forgotten first, so a flood of fresh keys degrades the friction before it grows memory.
13
15
  *
@@ -1 +1 @@
1
- {"version":3,"file":"SlidingWindow.d.ts","sourceRoot":"","sources":["../../../src/throttle/SlidingWindow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAElD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,2FAA2F;IAC3F,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;gBAE5C,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE;IAO9F;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,G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EAAE,MAAM,GAAG,IAAI;IAM1B,OAAO,CAAC,QAAQ;IAKhB,yGAAyG;IACzG,OAAO,CAAC,KAAK;CAUd"}
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SlidingWindow = void 0;
4
4
  /**
5
5
  * A per-key sliding window: how many attempts a key made in the last `windowMs`, against a
6
- * `limit`. The one window every throttled door shares — the sign-in and password-reset doors in
7
- * this package, and any consumer door throttling per client (lifted from the invite-request
8
- * door's per-IP throttle, which it replaces).
6
+ * `limit`. The per-CLIENT window the throttled doors share — the sign-in and password-reset doors
7
+ * in this package, and any consumer door throttling per client (lifted from the invite-request
8
+ * door's per-IP throttle, which it replaces). The windows that must hold across replicas (per
9
+ * account, per reset address) are `StoredWindow`s, counted in a shared `ThrottleWindowStore`.
9
10
  *
10
11
  * Held in process memory only, which is what makes it cheap and what bounds it:
11
12
  * - PER PROCESS. Each replica keeps its own windows, so behind a load balancer spreading a
12
13
  * client over N replicas the effective ceiling is ~N× the limit; a restart forgets them.
13
- * A throttle built on this is friction, not the wall. A shared store is a separate step.
14
+ * A throttle built on this is friction, not the wall — the per-address wall across replicas
15
+ * belongs in front of the servers (a rate limit at the load balancer).
14
16
  * - BOUNDED. At most `maxKeys` keys are tracked; at the bound the oldest-touched key is
15
17
  * forgotten first, so a flood of fresh keys degrades the friction before it grows memory.
16
18
  *
@@ -1 +1 @@
1
- {"version":3,"file":"SlidingWindow.js","sourceRoot":"","sources":["../../../src/throttle/SlidingWindow.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;GAeG;AACH;IAUE,uBAAY,OAAkF;;QAH9F,2FAA2F;QAC1E,aAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;QAGtD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAA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AQ,GAAhB,UAAiB,GAAW;;QAC1B,IAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC1C,OAAO,CAAC,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,GAAG,MAAM,EAAb,CAAa,CAAC,CAAC;IACxE,CAAC;IAED,yGAAyG;IACjG,6BAAK,GAAb,UAAc,GAAW,EAAE,QAAkB;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YACjE,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YACjD,IAAI,MAAM,KAAK,SAAS,EAAE;gBACxB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aAC9B;SACF;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAvEuB,8BAAgB,GAAG,KAAM,AAAT,CAAU;IAwEpD,oBAAC;CAAA,AAzED,IAyEC;AAzEY,sCAAa"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A throttle window counted in a `ThrottleWindowStore` — the windows that must hold across server
3
+ * processes (the sign-in door's per-account window, the reset door's per-address window). The
4
+ * store is the one a consuming application registers through `DefaultThrottleWindowStoreFactory`
5
+ * (read on every call, so a registration made after start-up is honoured), else the library's own
6
+ * per-process `MemoryThrottleWindowStore`. The window's name prefixes every key, so windows sharing
7
+ * one store never meet.
8
+ *
9
+ * THE NAMED FALLBACK when the store fails — an error, or no answer within `STORE_DEADLINE_MS` (a
10
+ * client queueing commands while it reconnects never answers at all): the window COUNTS IN THIS
11
+ * PROCESS'S MEMORY (the `MemoryThrottleWindowStore` it already holds) until the store answers
12
+ * again — `hit` counts and judges there, `clear` clears there. A door that cannot reach the shared
13
+ * count still counts the way a single process does: each process holds its own count for the
14
+ * outage (at most the limit per process), behind the per-client window and any per-address limit
15
+ * in front of the servers — where refusing every try would lock out every person for a blip with
16
+ * a sentence that is untrue for them. The outage is one WARN line per window saying so, however
17
+ * many tries meet it, and one INFO line when the store answers again; the store then counts again
18
+ * from what it holds (the outage's tries were this process's own). A success clears the memory
19
+ * window as well as the store's, so an account that proved itself starts clean in both.
20
+ *
21
+ * THE SHADOW: every try the store answers is counted in the memory window too, so memory always
22
+ * holds this process's own count — judged by the store while it answers, by memory when it does
23
+ * not. An outage therefore continues from what this process already counted (nine wrong tries,
24
+ * then the store fails: the eleventh is refused), never from zero.
25
+ */
26
+ export declare class StoredWindow {
27
+ /** How long a door waits on the store before counting in memory: well above a healthy store's milliseconds. */
28
+ private static readonly STORE_DEADLINE_MS;
29
+ private static readonly FACTORY;
30
+ private readonly name;
31
+ private readonly windowMs;
32
+ private readonly limit;
33
+ private readonly memory;
34
+ private readonly logger;
35
+ /** Whether the last call met a failed store — the outage is logged once, on the way in. */
36
+ private storeUnavailable;
37
+ constructor(options: {
38
+ name: string;
39
+ windowMs: number;
40
+ limit: number;
41
+ now?: () => number;
42
+ });
43
+ /**
44
+ * Count an attempt for `key` and answer whether it is over the window — `true` means refuse.
45
+ * Every attempt is counted (the window's end is fixed at its first count, so counting a refused
46
+ * attempt never extends it): in the store, and in this process's memory too (the shadow) — judged
47
+ * by the store when it answers, by memory when it fails (see the class comment).
48
+ */
49
+ hit(key: string): Promise<boolean>;
50
+ /** Forget `key`'s window — in this process's memory, and in the store when it answers. */
51
+ clear(key: string): Promise<void>;
52
+ /** The registered shared store, else the library's own. */
53
+ private store;
54
+ private key;
55
+ private withDeadline;
56
+ private failed;
57
+ private answered;
58
+ }
59
+ //# sourceMappingURL=StoredWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StoredWindow.d.ts","sourceRoot":"","sources":["../../../src/throttle/StoredWindow.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,YAAY;IACvB,+GAA+G;IAC/G,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IACjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAA8D;IAE7F,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,2FAA2F;IAC3F,OAAO,CAAC,gBAAgB,CAAS;gBAErB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE;IAO1F;;;;;OAKG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBxC,0FAA0F;IACpF,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvC,2DAA2D;IAC3D,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,GAAG;YAIG,YAAY;IAiB1B,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,QAAQ;CAOjB"}