@proteinjs/user-server 1.22.4 → 1.23.1
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/CHANGELOG.md +26 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/routes/executePasswordReset.js +3 -1
- package/dist/src/routes/executePasswordReset.js.map +1 -1
- package/dist/src/routes/initiatePasswordReset.d.ts.map +1 -1
- package/dist/src/routes/initiatePasswordReset.js +14 -12
- package/dist/src/routes/initiatePasswordReset.js.map +1 -1
- package/dist/src/routes/login.js +18 -14
- package/dist/src/routes/login.js.map +1 -1
- package/dist/src/throttle/MemoryThrottleWindowStore.d.ts +28 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.d.ts.map +1 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.js +108 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.js.map +1 -0
- package/dist/src/throttle/PasswordResetThrottle.d.ts +9 -8
- package/dist/src/throttle/PasswordResetThrottle.d.ts.map +1 -1
- package/dist/src/throttle/PasswordResetThrottle.js +63 -15
- package/dist/src/throttle/PasswordResetThrottle.js.map +1 -1
- package/dist/src/throttle/SignInThrottle.d.ts +21 -15
- package/dist/src/throttle/SignInThrottle.d.ts.map +1 -1
- package/dist/src/throttle/SignInThrottle.js +94 -25
- package/dist/src/throttle/SignInThrottle.js.map +1 -1
- package/dist/src/throttle/SlidingWindow.d.ts +6 -4
- package/dist/src/throttle/SlidingWindow.d.ts.map +1 -1
- package/dist/src/throttle/SlidingWindow.js +6 -4
- package/dist/src/throttle/SlidingWindow.js.map +1 -1
- package/dist/src/throttle/StoredWindow.d.ts +59 -0
- package/dist/src/throttle/StoredWindow.d.ts.map +1 -0
- package/dist/src/throttle/StoredWindow.js +209 -0
- package/dist/src/throttle/StoredWindow.js.map +1 -0
- package/dist/src/throttle/ThrottleWindowStore.d.ts +38 -0
- package/dist/src/throttle/ThrottleWindowStore.d.ts.map +1 -0
- package/dist/src/throttle/ThrottleWindowStore.js +3 -0
- package/dist/src/throttle/ThrottleWindowStore.js.map +1 -0
- package/dist/test/MemoryThrottleWindowStore.test.d.ts +2 -0
- package/dist/test/MemoryThrottleWindowStore.test.d.ts.map +1 -0
- package/dist/test/MemoryThrottleWindowStore.test.js +210 -0
- package/dist/test/MemoryThrottleWindowStore.test.js.map +1 -0
- package/dist/test/SharedThrottleWindows.integration.test.d.ts +2 -0
- package/dist/test/SharedThrottleWindows.integration.test.d.ts.map +1 -0
- package/dist/test/SharedThrottleWindows.integration.test.js +756 -0
- package/dist/test/SharedThrottleWindows.integration.test.js.map +1 -0
- package/dist/test/UserServerTestEnvironment.d.ts.map +1 -1
- package/dist/test/UserServerTestEnvironment.js +3 -0
- package/dist/test/UserServerTestEnvironment.js.map +1 -1
- package/generated/index.ts +1 -1
- package/index.ts +4 -0
- package/package.json +5 -5
- package/src/routes/executePasswordReset.ts +1 -1
- package/src/routes/initiatePasswordReset.ts +2 -1
- package/src/routes/login.ts +2 -2
- package/src/throttle/MemoryThrottleWindowStore.ts +60 -0
- package/src/throttle/PasswordResetThrottle.ts +14 -11
- package/src/throttle/SignInThrottle.ts +27 -19
- package/src/throttle/SlidingWindow.ts +6 -4
- package/src/throttle/StoredWindow.ts +132 -0
- package/src/throttle/ThrottleWindowStore.ts +41 -0
- package/test/MemoryThrottleWindowStore.test.ts +74 -0
- package/test/SharedThrottleWindows.integration.test.ts +407 -0
- package/test/UserServerTestEnvironment.ts +3 -0
|
@@ -103,8 +103,10 @@ exports.initiatePasswordReset = {
|
|
|
103
103
|
}
|
|
104
104
|
digests = new util_node_1.RequestDigests();
|
|
105
105
|
fields = { account: digests.account(requestedEmail), ip: digests.coarseIp(new ClientAddress_1.ClientAddress().of(request)) };
|
|
106
|
-
window = PasswordResetThrottle_1.passwordResetThrottle.admit(fields.ip, fields.account);
|
|
107
106
|
response.send(ONE_ANSWER);
|
|
107
|
+
return [4 /*yield*/, PasswordResetThrottle_1.passwordResetThrottle.admit(fields.ip, fields.account)];
|
|
108
|
+
case 1:
|
|
109
|
+
window = _d.sent();
|
|
108
110
|
if (window) {
|
|
109
111
|
logger.warn({ message: "Password reset throttled", obj: __assign(__assign({}, fields), { window: window }) });
|
|
110
112
|
return [2 /*return*/];
|
|
@@ -112,7 +114,7 @@ exports.initiatePasswordReset = {
|
|
|
112
114
|
email = requestedEmail.toLowerCase();
|
|
113
115
|
db = (0, db_1.getDbAsSystem)();
|
|
114
116
|
return [4 /*yield*/, db.get(user_1.tables.User, { email: email })];
|
|
115
|
-
case
|
|
117
|
+
case 2:
|
|
116
118
|
user = _d.sent();
|
|
117
119
|
if (!user) {
|
|
118
120
|
logger.info({ message: "Password reset requested for non-existent user", obj: fields });
|
|
@@ -130,30 +132,30 @@ exports.initiatePasswordReset = {
|
|
|
130
132
|
throw new Error("Unable to find a @proteinjs/email-server/DefaultPasswordResetEmailConfigFactory implementation when initiating password reset.");
|
|
131
133
|
}
|
|
132
134
|
return [4 /*yield*/, resetToken.mint(user)];
|
|
133
|
-
case 2:
|
|
134
|
-
passwordResetToken = _d.sent();
|
|
135
|
-
_d.label = 3;
|
|
136
135
|
case 3:
|
|
137
|
-
_d.
|
|
136
|
+
passwordResetToken = _d.sent();
|
|
137
|
+
_d.label = 4;
|
|
138
|
+
case 4:
|
|
139
|
+
_d.trys.push([4, 6, , 8]);
|
|
138
140
|
config = defaultConfigFactory.getConfig();
|
|
139
141
|
_a = config.getEmailContent("".concat(user_1.uiRoutes.auth.passwordReset, "?token=").concat(passwordResetToken)), text = _a.text, html = _a.html;
|
|
140
142
|
// Send email containing a reset link
|
|
141
143
|
return [4 /*yield*/, emailSender.sendEmail(__assign({ to: user.email, subject: ((_c = config.options) === null || _c === void 0 ? void 0 : _c.subject) || 'Reset Password', text: text, html: html }, config.options))];
|
|
142
|
-
case
|
|
144
|
+
case 5:
|
|
143
145
|
// Send email containing a reset link
|
|
144
146
|
_d.sent();
|
|
145
147
|
logger.info({ message: "Password reset link mailed", obj: fields });
|
|
146
|
-
return [3 /*break*/,
|
|
147
|
-
case
|
|
148
|
+
return [3 /*break*/, 8];
|
|
149
|
+
case 6:
|
|
148
150
|
error_1 = _d.sent();
|
|
149
151
|
logger.error({ message: "Failed to send password reset email", obj: fields, error: error_1 });
|
|
150
152
|
// The link never reached the account: withdraw the token so asking again is not throttled
|
|
151
153
|
return [4 /*yield*/, resetToken.revoke(user, passwordResetToken)];
|
|
152
|
-
case
|
|
154
|
+
case 7:
|
|
153
155
|
// The link never reached the account: withdraw the token so asking again is not throttled
|
|
154
156
|
_d.sent();
|
|
155
|
-
return [3 /*break*/,
|
|
156
|
-
case
|
|
157
|
+
return [3 /*break*/, 8];
|
|
158
|
+
case 8: return [2 /*return*/];
|
|
157
159
|
}
|
|
158
160
|
});
|
|
159
161
|
}); },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initiatePasswordReset.js","sourceRoot":"","sources":["../../../src/routes/initiatePasswordReset.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAA8C;AAC9C,wCAA2D;AAC3D,4CAA2C;AAC3C,kDAAsD;AACtD,kDAA4B;AAC5B,wDAGiC;AACjC,2EAA0E;AAC1E,2DAA0D;AAC1D,2EAA0E;AAE1E;;;GAGG;AACH,IAAM,UAAU,GAAG,EAAE,OAAO,EAAE,6DAA6D,EAAE,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,qBAAqB,GAAU;IAC1C,IAAI,EAAE,aAAM,CAAC,qBAAqB,CAAC,IAAI;IACvC,MAAM,EAAE,aAAM,CAAC,qBAAqB,CAAC,MAAM;IAC3C,SAAS,EAAE,UAAO,OAAO,EAAE,QAAQ;;;;;;oBAC3B,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAA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EAAE,qCAAqC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,SAAA,EAAE,CAAC,CAAC;oBACrF,0FAA0F;oBAC1F,qBAAM,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAA;;oBADjD,0FAA0F;oBAC1F,SAAiD,CAAC;;;;;SAErD;CACF,CAAC"}
|
package/dist/src/routes/login.js
CHANGED
|
@@ -81,15 +81,17 @@ exports.login = {
|
|
|
81
81
|
ip = digests.coarseIp(new ClientAddress_1.ClientAddress().of(request));
|
|
82
82
|
account = email ? digests.account(email) : undefined;
|
|
83
83
|
fields = account ? { account: account, ip: ip } : { ip: ip };
|
|
84
|
-
|
|
85
|
-
if (!window) return [3 /*break*/, 2];
|
|
86
|
-
return [4 /*yield*/, (0, authenticate_1.checkPassword)(email, password)];
|
|
84
|
+
return [4 /*yield*/, SignInThrottle_1.signInThrottle.admit(ip, password ? account : undefined)];
|
|
87
85
|
case 1:
|
|
86
|
+
window = _b.sent();
|
|
87
|
+
if (!window) return [3 /*break*/, 3];
|
|
88
|
+
return [4 /*yield*/, (0, authenticate_1.checkPassword)(email, password)];
|
|
89
|
+
case 2:
|
|
88
90
|
_b.sent();
|
|
89
91
|
logger.warn({ message: 'Sign-in throttled', obj: __assign(__assign({}, fields), { window: window }) });
|
|
90
92
|
response.send({ error: SignInThrottle_1.SignInThrottle.ANSWER });
|
|
91
93
|
return [2 /*return*/];
|
|
92
|
-
case
|
|
94
|
+
case 3:
|
|
93
95
|
if (!email || !password || !account) {
|
|
94
96
|
error = "Email and password cannot be blank";
|
|
95
97
|
logger.info({ message: 'Sign-in refused', obj: __assign(__assign({}, fields), { reason: error }) });
|
|
@@ -97,22 +99,24 @@ exports.login = {
|
|
|
97
99
|
return [2 /*return*/];
|
|
98
100
|
}
|
|
99
101
|
return [4 /*yield*/, (0, authenticate_1.authenticate)(email, password)];
|
|
100
|
-
case
|
|
102
|
+
case 4:
|
|
101
103
|
result = _b.sent();
|
|
102
104
|
if (result !== true) {
|
|
103
105
|
logger.info({ message: 'Sign-in refused', obj: __assign(__assign({}, fields), { reason: result }) });
|
|
104
106
|
response.send({ error: result });
|
|
105
107
|
return [2 /*return*/];
|
|
106
108
|
}
|
|
107
|
-
SignInThrottle_1.signInThrottle.recordSuccess(account, ip);
|
|
108
|
-
_b.label = 4;
|
|
109
|
-
case 4:
|
|
110
|
-
_b.trys.push([4, 6, , 7]);
|
|
111
|
-
return [4 /*yield*/, new AccountDeletion_1.AccountDeletion().cancelPendingDeletion(email)];
|
|
109
|
+
return [4 /*yield*/, SignInThrottle_1.signInThrottle.recordSuccess(account, ip)];
|
|
112
110
|
case 5:
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
_b.sent();
|
|
112
|
+
_b.label = 6;
|
|
115
113
|
case 6:
|
|
114
|
+
_b.trys.push([6, 8, , 9]);
|
|
115
|
+
return [4 /*yield*/, new AccountDeletion_1.AccountDeletion().cancelPendingDeletion(email)];
|
|
116
|
+
case 7:
|
|
117
|
+
outcome = _b.sent();
|
|
118
|
+
return [3 /*break*/, 9];
|
|
119
|
+
case 8:
|
|
116
120
|
error_1 = _b.sent();
|
|
117
121
|
// Security boundary: the login response never carries internal error detail — an
|
|
118
122
|
// attacker probing emails must learn nothing from failure shapes (founder ruling
|
|
@@ -121,7 +125,7 @@ exports.login = {
|
|
|
121
125
|
console.error('cancelPendingDeletion failed during login', error_1);
|
|
122
126
|
response.send({ error: 'Unable to log in right now. Please try again.' });
|
|
123
127
|
return [2 /*return*/];
|
|
124
|
-
case
|
|
128
|
+
case 9:
|
|
125
129
|
if (outcome === 'purging') {
|
|
126
130
|
error = 'This account is being deleted and can no longer be restored.';
|
|
127
131
|
console.error(error);
|
|
@@ -129,7 +133,7 @@ exports.login = {
|
|
|
129
133
|
return [2 /*return*/];
|
|
130
134
|
}
|
|
131
135
|
return [4 /*yield*/, (0, establishSession_1.establishSession)(request, email)];
|
|
132
|
-
case
|
|
136
|
+
case 10:
|
|
133
137
|
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BACjC,sBAAO;qBACR;oBACD,qBAAM,+BAAc,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,EAAA;;oBAA/C,SAA+C,CAAC;;;;oBAOpC,qBAAM,IAAI,iCAAe,EAAE,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAA;;oBAAlE,OAAO,GAAG,SAAwD,CAAC;;;;oBAEnE,iFAAiF;oBACjF,iFAAiF;oBACjF,kFAAkF;oBAClF,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,OAAK,CAAC,CAAC;oBAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,+CAA+C,EAAE,CAAC,CAAC;oBAC1E,sBAAO;;oBAET,IAAI,OAAO,KAAK,SAAS,EAAE;wBACnB,KAAK,GAAG,8DAA8D,CAAC;wBAC7E,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;wBACzB,sBAAO;qBACR;oBAED,qBAAM,IAAA,mCAAgB,EAAC,OAAO,EAAE,KAAK,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;oBACvC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;;;;SACnB;CACF,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ThrottleWindowStore } from './ThrottleWindowStore';
|
|
2
|
+
/**
|
|
3
|
+
* The library's own `ThrottleWindowStore`: windows held in this process's memory. It is the
|
|
4
|
+
* default when no shared store is registered — right for tests and single-process servers; in a
|
|
5
|
+
* deployment of several processes each keeps its own counts (register a shared store there).
|
|
6
|
+
*
|
|
7
|
+
* BOUNDED like `SlidingWindow`: at most `maxKeys` keys are held; at the bound the oldest-touched
|
|
8
|
+
* key is forgotten first, so a flood of fresh keys degrades the friction before it grows memory.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MemoryThrottleWindowStore implements ThrottleWindowStore {
|
|
11
|
+
private static readonly DEFAULT_MAX_KEYS;
|
|
12
|
+
private readonly maxKeys;
|
|
13
|
+
private readonly now;
|
|
14
|
+
/** key → its count and when its window ends, in touch order. */
|
|
15
|
+
private readonly windows;
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
maxKeys?: number;
|
|
18
|
+
now?: () => number;
|
|
19
|
+
});
|
|
20
|
+
increment(key: string, windowMs: number): Promise<number>;
|
|
21
|
+
read(key: string): Promise<number>;
|
|
22
|
+
clear(key: string): Promise<void>;
|
|
23
|
+
/** `key`'s window while it lasts; an ended one is dropped. */
|
|
24
|
+
private live;
|
|
25
|
+
/** Store `key`'s window as the most recently touched, evicting the oldest-touched key at the bound. */
|
|
26
|
+
private touch;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=MemoryThrottleWindowStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryThrottleWindowStore.d.ts","sourceRoot":"","sources":["../../../src/throttle/MemoryThrottleWindowStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,mBAAmB;IACnE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAElD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,gEAAgE;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2D;gBAEvE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE;IAKxD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOzD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,8DAA8D;IAC9D,OAAO,CAAC,IAAI;IASZ,uGAAuG;IACvG,OAAO,CAAC,KAAK;CAUd"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.MemoryThrottleWindowStore = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* The library's own `ThrottleWindowStore`: windows held in this process's memory. It is the
|
|
42
|
+
* default when no shared store is registered — right for tests and single-process servers; in a
|
|
43
|
+
* deployment of several processes each keeps its own counts (register a shared store there).
|
|
44
|
+
*
|
|
45
|
+
* BOUNDED like `SlidingWindow`: at most `maxKeys` keys are held; at the bound the oldest-touched
|
|
46
|
+
* key is forgotten first, so a flood of fresh keys degrades the friction before it grows memory.
|
|
47
|
+
*/
|
|
48
|
+
var MemoryThrottleWindowStore = /** @class */ (function () {
|
|
49
|
+
function MemoryThrottleWindowStore(options) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
/** key → its count and when its window ends, in touch order. */
|
|
52
|
+
this.windows = new Map();
|
|
53
|
+
this.maxKeys = (_a = options === null || options === void 0 ? void 0 : options.maxKeys) !== null && _a !== void 0 ? _a : MemoryThrottleWindowStore.DEFAULT_MAX_KEYS;
|
|
54
|
+
this.now = (_b = options === null || options === void 0 ? void 0 : options.now) !== null && _b !== void 0 ? _b : Date.now;
|
|
55
|
+
}
|
|
56
|
+
MemoryThrottleWindowStore.prototype.increment = function (key, windowMs) {
|
|
57
|
+
var _a;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var window;
|
|
60
|
+
return __generator(this, function (_b) {
|
|
61
|
+
window = (_a = this.live(key)) !== null && _a !== void 0 ? _a : { count: 0, expiresAt: this.now() + windowMs };
|
|
62
|
+
window.count++;
|
|
63
|
+
this.touch(key, window);
|
|
64
|
+
return [2 /*return*/, window.count];
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
MemoryThrottleWindowStore.prototype.read = function (key) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
return __generator(this, function (_c) {
|
|
72
|
+
return [2 /*return*/, (_b = (_a = this.live(key)) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
MemoryThrottleWindowStore.prototype.clear = function (key) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
this.windows.delete(key);
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/** `key`'s window while it lasts; an ended one is dropped. */
|
|
85
|
+
MemoryThrottleWindowStore.prototype.live = function (key) {
|
|
86
|
+
var window = this.windows.get(key);
|
|
87
|
+
if (window && window.expiresAt <= this.now()) {
|
|
88
|
+
this.windows.delete(key);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
return window;
|
|
92
|
+
};
|
|
93
|
+
/** Store `key`'s window as the most recently touched, evicting the oldest-touched key at the bound. */
|
|
94
|
+
MemoryThrottleWindowStore.prototype.touch = function (key, window) {
|
|
95
|
+
if (!this.windows.has(key) && this.windows.size >= this.maxKeys) {
|
|
96
|
+
var oldest = this.windows.keys().next().value;
|
|
97
|
+
if (oldest !== undefined) {
|
|
98
|
+
this.windows.delete(oldest);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.windows.delete(key);
|
|
102
|
+
this.windows.set(key, window);
|
|
103
|
+
};
|
|
104
|
+
MemoryThrottleWindowStore.DEFAULT_MAX_KEYS = 10000;
|
|
105
|
+
return MemoryThrottleWindowStore;
|
|
106
|
+
}());
|
|
107
|
+
exports.MemoryThrottleWindowStore = MemoryThrottleWindowStore;
|
|
108
|
+
//# sourceMappingURL=MemoryThrottleWindowStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryThrottleWindowStore.js","sourceRoot":"","sources":["../../../src/throttle/MemoryThrottleWindowStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;GAOG;AACH;IAQE,mCAAY,OAAkD;;QAH9D,gEAAgE;QAC/C,YAAO,GAAG,IAAI,GAAG,EAAgD,CAAC;QAGjF,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,yBAAyB,CAAC,gBAAgB,CAAC;QAC9E,IAAI,CAAC,GAAG,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,mCAAI,IAAI,CAAC,GAAG,CAAC;IACtC,CAAC;IAEK,6CAAS,GAAf,UAAgB,GAAW,EAAE,QAAgB;;;;;gBACrC,MAAM,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,mCAAI,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;gBAChF,MA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AAC;IAChC,CAAC;IA/CuB,0CAAgB,GAAG,KAAM,AAAT,CAAU;IAgDpD,gCAAC;CAAA,AAjDD,IAiDC;AAjDY,8DAAyB"}
|
|
@@ -7,11 +7,12 @@ import { ThrottleWindow } from './SignInThrottle';
|
|
|
7
7
|
* same sentence as always (see the route).
|
|
8
8
|
*
|
|
9
9
|
* These sit on top of the account row's own five-minute gap between links, which spans replicas
|
|
10
|
-
* (it is stored)
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* (it is stored). The per-address window is a `StoredWindow`: counted in the store the deployment
|
|
11
|
+
* registers (`DefaultThrottleWindowStoreFactory`), so with a shared store it is one count across
|
|
12
|
+
* every replica and survives a deploy; while that store fails it counts in this process's memory
|
|
13
|
+
* (the named fallback, see `StoredWindow`), so the door still mints and mails. The per-client window stays in process memory (`SlidingWindow`), per
|
|
14
|
+
* replica — the second line behind a per-address limit at the load balancer (see
|
|
15
|
+
* `SignInThrottle`).
|
|
15
16
|
*/
|
|
16
17
|
export declare class PasswordResetThrottle {
|
|
17
18
|
/**
|
|
@@ -21,8 +22,8 @@ export declare class PasswordResetThrottle {
|
|
|
21
22
|
private static readonly CLIENT_LIMIT;
|
|
22
23
|
private static readonly CLIENT_WINDOW_MS;
|
|
23
24
|
/**
|
|
24
|
-
* Per address: 3 requests an hour. A person whose mail is slow asks once or twice
|
|
25
|
-
* that it is mail aimed at somebody's inbox.
|
|
25
|
+
* Per address: 3 requests in an hour's window. A person whose mail is slow asks once or twice
|
|
26
|
+
* more; beyond that it is mail aimed at somebody's inbox.
|
|
26
27
|
*/
|
|
27
28
|
private static readonly ACCOUNT_LIMIT;
|
|
28
29
|
private static readonly ACCOUNT_WINDOW_MS;
|
|
@@ -32,7 +33,7 @@ export declare class PasswordResetThrottle {
|
|
|
32
33
|
now?: () => number;
|
|
33
34
|
});
|
|
34
35
|
/** Count this request and answer which window refuses it, if any. */
|
|
35
|
-
admit(client: string, account: string): ThrottleWindow | undefined
|
|
36
|
+
admit(client: string, account: string): Promise<ThrottleWindow | undefined>;
|
|
36
37
|
}
|
|
37
38
|
/** The process-wide windows the reset door shares — they must span requests. */
|
|
38
39
|
export declare const passwordResetThrottle: PasswordResetThrottle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordResetThrottle.d.ts","sourceRoot":"","sources":["../../../src/throttle/PasswordResetThrottle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PasswordResetThrottle.d.ts","sourceRoot":"","sources":["../../../src/throttle/PasswordResetThrottle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IAChC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAM;IAC1C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAE1D;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAK;IAC1C,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,qEAAqE;IAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CASlF;AAED,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,uBAA8B,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.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)
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
|
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
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"PasswordResetThrottle.js","sourceRoot":"","sources":["../../../src/throttle/PasswordResetThrottle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAgD;AAChD,+CAA8C;AAG9C;;;;;;;;;;;;;;GAcG;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,2BAAY,CAAC;YAC/B,IAAI,EAAE,eAAe;YACrB,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;IAC/D,qCAAK,GAAX,UAAY,MAAc,EAAE,OAAe;;;;;wBACzC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;4BAC5B,sBAAO,QAAQ,EAAC;yBACjB;wBACG,qBAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAApC,IAAI,SAAgC,EAAE;4BACpC,sBAAO,SAAS,EAAC;yBAClB;wBACD,sBAAO,SAAS,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
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
38
|
-
* Someone who has forgotten a password tries a handful and asks for a reset link; ten wrong
|
|
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
|
|
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
|
|
60
|
-
* (rather than a reset link redeemed), that try is forgiven — a success never
|
|
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":"
|
|
1
|
+
{"version":3,"file":"SignInThrottle.d.ts","sourceRoot":"","sources":["../../../src/throttle/SignInThrottle.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,SAAS,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,cAAc;IACzB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,oDAAoD;IAE1E;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAM;IAC1C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;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"}
|