@aooth/user 0.2.4 → 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/atscript-db.cjs +1 -1
- package/dist/atscript-db.d.cts +1 -1
- package/dist/atscript-db.d.mts +1 -1
- package/dist/atscript-db.mjs +1 -1
- package/dist/{federated-identity-store-BZRvw9Pz.mjs → federated-identity-store-B1J4lMeN.mjs} +12 -4
- package/dist/{federated-identity-store-Ds7Ye9qJ.d.cts → federated-identity-store-D8BFFhpm.d.cts} +21 -1
- package/dist/{federated-identity-store-Ds7Ye9qJ.d.mts → federated-identity-store-D8BFFhpm.d.mts} +21 -1
- package/dist/{federated-identity-store-Cbstwl4-.cjs → federated-identity-store-DL0He6X_.cjs} +17 -3
- package/dist/index.cjs +68 -14
- package/dist/index.d.cts +42 -2
- package/dist/index.d.mts +42 -2
- package/dist/index.mjs +67 -15
- package/package.json +9 -9
package/dist/atscript-db.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_federated_identity_store = require("./federated-identity-store-
|
|
2
|
+
const require_federated_identity_store = require("./federated-identity-store-DL0He6X_.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
// src/atscript-db/federated-identity-store.ts
|
|
5
5
|
function isConflict$1(err) {
|
package/dist/atscript-db.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as UserStoreUpdate, O as UserCredentials, i as NewFederatedIdentity, n as FederatedIdentityStore, o as UserStore, r as FederatedProfileSnapshot, s as WithCasOptions, t as FederatedIdentity } from "./federated-identity-store-D8BFFhpm.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Structural surface of `AtscriptDbTable` covering exactly the methods this
|
|
4
4
|
* adapter calls — kept loose so `@aooth/user` doesn't pull `@atscript/db` types
|
package/dist/atscript-db.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as UserStoreUpdate, O as UserCredentials, i as NewFederatedIdentity, n as FederatedIdentityStore, o as UserStore, r as FederatedProfileSnapshot, s as WithCasOptions, t as FederatedIdentity } from "./federated-identity-store-D8BFFhpm.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Structural surface of `AtscriptDbTable` covering exactly the methods this
|
|
4
4
|
* adapter calls — kept loose so `@aooth/user` doesn't pull `@atscript/db` types
|
package/dist/atscript-db.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as setAtPath, l as UserStore, n as pickDefinedProfile, t as FederatedIdentityStore
|
|
1
|
+
import { c as setAtPath, d as UserAuthError, l as UserStore, n as pickDefinedProfile, t as FederatedIdentityStore } from "./federated-identity-store-B1J4lMeN.mjs";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
// src/atscript-db/federated-identity-store.ts
|
|
4
4
|
function isConflict$1(err) {
|
package/dist/{federated-identity-store-BZRvw9Pz.mjs → federated-identity-store-B1J4lMeN.mjs}
RENAMED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import "node:crypto";
|
|
2
2
|
// src/errors.ts
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The default English message of each `UserAuthError` type — the error's
|
|
5
|
+
* `type` is its message code.
|
|
6
|
+
*
|
|
7
|
+
* `@aooth/auth-moost` registers it with moost's `registerMessages`, so a moost
|
|
8
|
+
* translator (`setTranslator`) translates a `UserAuthError` by its type and the
|
|
9
|
+
* texts reach the `$i18n` the server sends with form schemas and `/meta`.
|
|
10
|
+
*/
|
|
11
|
+
const USER_AUTH_ERROR_MESSAGES = Object.freeze({
|
|
4
12
|
NOT_FOUND: "User not found",
|
|
5
13
|
ALREADY_EXISTS: "User already exists",
|
|
6
14
|
LOCKED: "Account is locked",
|
|
@@ -13,13 +21,13 @@ const defaultMessages = {
|
|
|
13
21
|
MFA_INVALID: "Invalid MFA code",
|
|
14
22
|
MFA_NOT_CONFIGURED: "MFA method is not configured",
|
|
15
23
|
CAS_EXHAUSTED: "Update conflict — please retry"
|
|
16
|
-
};
|
|
24
|
+
});
|
|
17
25
|
var UserAuthError = class extends Error {
|
|
18
26
|
type;
|
|
19
27
|
details;
|
|
20
28
|
name = "UserAuthError";
|
|
21
29
|
constructor(type, message, details) {
|
|
22
|
-
super(message ??
|
|
30
|
+
super(message ?? USER_AUTH_ERROR_MESSAGES[type]);
|
|
23
31
|
this.type = type;
|
|
24
32
|
this.details = details;
|
|
25
33
|
}
|
|
@@ -123,4 +131,4 @@ function pickDefinedProfile(src) {
|
|
|
123
131
|
* keeps the federated-login core (`@aooth/idp`, phase 2) storage-agnostic.
|
|
124
132
|
*/
|
|
125
133
|
var FederatedIdentityStore = class {};
|
|
126
|
-
export { maskEmail as a, setAtPath as c, incrementAtPath as i, UserStore as l, pickDefinedProfile as n, maskMfaValue as o, deepMerge as r, maskPhone as s, FederatedIdentityStore as t,
|
|
134
|
+
export { maskEmail as a, setAtPath as c, UserAuthError as d, incrementAtPath as i, UserStore as l, pickDefinedProfile as n, maskMfaValue as o, deepMerge as r, maskPhone as s, FederatedIdentityStore as t, USER_AUTH_ERROR_MESSAGES as u };
|
package/dist/{federated-identity-store-Ds7Ye9qJ.d.cts → federated-identity-store-D8BFFhpm.d.cts}
RENAMED
|
@@ -177,7 +177,18 @@ interface PasswordPolicyDef {
|
|
|
177
177
|
serialized?: string;
|
|
178
178
|
description?: string;
|
|
179
179
|
errorMessage?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Message code of the policy's texts, for translation: `errorMessage` is
|
|
182
|
+
* translated by `code`, `description` by `${code}_DESCRIPTION`, both with
|
|
183
|
+
* `params` — the English texts are the fallback. The built-in `pp*`
|
|
184
|
+
* policies carry `PP_*` codes (`PASSWORD_POLICY_MESSAGES`).
|
|
185
|
+
*/
|
|
186
|
+
code?: string;
|
|
187
|
+
/** Values of the code's `{name}` placeholders (e.g. `{ min: 8 }`). */
|
|
188
|
+
params?: PasswordPolicyParams;
|
|
180
189
|
}
|
|
190
|
+
/** Values of a password policy's message placeholders. */
|
|
191
|
+
type PasswordPolicyParams = Readonly<Record<string, string | number>>;
|
|
181
192
|
type PasswordPolicyEvalFn = (password: string, context?: PasswordPolicyContext) => boolean | Promise<boolean>;
|
|
182
193
|
interface PasswordPolicyContext {
|
|
183
194
|
passwordData?: PasswordData;
|
|
@@ -217,9 +228,14 @@ interface LockStatus {
|
|
|
217
228
|
}
|
|
218
229
|
interface PolicyCheckResult {
|
|
219
230
|
passed: boolean;
|
|
231
|
+
/** Every policy and its result, with its texts and (when set) message `code` + `params`. */
|
|
220
232
|
policies: {
|
|
221
233
|
description: string;
|
|
222
234
|
passed: boolean;
|
|
235
|
+
/** The policy's failure text (always set by `checkPolicies`). */
|
|
236
|
+
errorMessage?: string;
|
|
237
|
+
code?: string;
|
|
238
|
+
params?: PasswordPolicyParams;
|
|
223
239
|
}[];
|
|
224
240
|
errors: string[];
|
|
225
241
|
}
|
|
@@ -227,6 +243,10 @@ interface TransferablePolicy {
|
|
|
227
243
|
rule: string;
|
|
228
244
|
description?: string;
|
|
229
245
|
errorMessage?: string;
|
|
246
|
+
/** The policy's message code ({@link PasswordPolicyDef.code}). */
|
|
247
|
+
code?: string;
|
|
248
|
+
/** The code's placeholder values ({@link PasswordPolicyDef.params}). */
|
|
249
|
+
params?: PasswordPolicyParams;
|
|
230
250
|
}
|
|
231
251
|
interface MfaMethodInfo {
|
|
232
252
|
name: string;
|
|
@@ -405,4 +425,4 @@ declare abstract class FederatedIdentityStore {
|
|
|
405
425
|
*/
|
|
406
426
|
abstract deleteAllForUser(userId: string): Promise<number>;
|
|
407
427
|
}
|
|
408
|
-
export {
|
|
428
|
+
export { UserStoreUpdate as A, PolicyCheckResult as C, UserAuthErrorType as D, TrustedDeviceRecord as E, UserCredentials as O, PasswordPolicyParams as S, TransferablePolicy as T, PasswordData as _, pickDefinedProfile as a, PasswordPolicyEvalFn as b, AccountData as c, LockoutConfig as d, LoginResult as f, PasswordConfig as g, MfaMethodInfo as h, NewFederatedIdentity as i, UserServiceConfig as k, DeepPartial as l, MfaMethod as m, FederatedIdentityStore as n, UserStore as o, MfaData as p, FederatedProfileSnapshot as r, WithCasOptions as s, FederatedIdentity as t, LockStatus as u, PasswordPolicyContext as v, TotpConfig as w, PasswordPolicyInstance as x, PasswordPolicyDef as y };
|
package/dist/{federated-identity-store-Ds7Ye9qJ.d.mts → federated-identity-store-D8BFFhpm.d.mts}
RENAMED
|
@@ -177,7 +177,18 @@ interface PasswordPolicyDef {
|
|
|
177
177
|
serialized?: string;
|
|
178
178
|
description?: string;
|
|
179
179
|
errorMessage?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Message code of the policy's texts, for translation: `errorMessage` is
|
|
182
|
+
* translated by `code`, `description` by `${code}_DESCRIPTION`, both with
|
|
183
|
+
* `params` — the English texts are the fallback. The built-in `pp*`
|
|
184
|
+
* policies carry `PP_*` codes (`PASSWORD_POLICY_MESSAGES`).
|
|
185
|
+
*/
|
|
186
|
+
code?: string;
|
|
187
|
+
/** Values of the code's `{name}` placeholders (e.g. `{ min: 8 }`). */
|
|
188
|
+
params?: PasswordPolicyParams;
|
|
180
189
|
}
|
|
190
|
+
/** Values of a password policy's message placeholders. */
|
|
191
|
+
type PasswordPolicyParams = Readonly<Record<string, string | number>>;
|
|
181
192
|
type PasswordPolicyEvalFn = (password: string, context?: PasswordPolicyContext) => boolean | Promise<boolean>;
|
|
182
193
|
interface PasswordPolicyContext {
|
|
183
194
|
passwordData?: PasswordData;
|
|
@@ -217,9 +228,14 @@ interface LockStatus {
|
|
|
217
228
|
}
|
|
218
229
|
interface PolicyCheckResult {
|
|
219
230
|
passed: boolean;
|
|
231
|
+
/** Every policy and its result, with its texts and (when set) message `code` + `params`. */
|
|
220
232
|
policies: {
|
|
221
233
|
description: string;
|
|
222
234
|
passed: boolean;
|
|
235
|
+
/** The policy's failure text (always set by `checkPolicies`). */
|
|
236
|
+
errorMessage?: string;
|
|
237
|
+
code?: string;
|
|
238
|
+
params?: PasswordPolicyParams;
|
|
223
239
|
}[];
|
|
224
240
|
errors: string[];
|
|
225
241
|
}
|
|
@@ -227,6 +243,10 @@ interface TransferablePolicy {
|
|
|
227
243
|
rule: string;
|
|
228
244
|
description?: string;
|
|
229
245
|
errorMessage?: string;
|
|
246
|
+
/** The policy's message code ({@link PasswordPolicyDef.code}). */
|
|
247
|
+
code?: string;
|
|
248
|
+
/** The code's placeholder values ({@link PasswordPolicyDef.params}). */
|
|
249
|
+
params?: PasswordPolicyParams;
|
|
230
250
|
}
|
|
231
251
|
interface MfaMethodInfo {
|
|
232
252
|
name: string;
|
|
@@ -405,4 +425,4 @@ declare abstract class FederatedIdentityStore {
|
|
|
405
425
|
*/
|
|
406
426
|
abstract deleteAllForUser(userId: string): Promise<number>;
|
|
407
427
|
}
|
|
408
|
-
export {
|
|
428
|
+
export { UserStoreUpdate as A, PolicyCheckResult as C, UserAuthErrorType as D, TrustedDeviceRecord as E, UserCredentials as O, PasswordPolicyParams as S, TransferablePolicy as T, PasswordData as _, pickDefinedProfile as a, PasswordPolicyEvalFn as b, AccountData as c, LockoutConfig as d, LoginResult as f, PasswordConfig as g, MfaMethodInfo as h, NewFederatedIdentity as i, UserServiceConfig as k, DeepPartial as l, MfaMethod as m, FederatedIdentityStore as n, UserStore as o, MfaData as p, FederatedProfileSnapshot as r, WithCasOptions as s, FederatedIdentity as t, LockStatus as u, PasswordPolicyContext as v, TotpConfig as w, PasswordPolicyInstance as x, PasswordPolicyDef as y };
|
package/dist/{federated-identity-store-Cbstwl4-.cjs → federated-identity-store-DL0He6X_.cjs}
RENAMED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
require("node:crypto");
|
|
2
2
|
// src/errors.ts
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The default English message of each `UserAuthError` type — the error's
|
|
5
|
+
* `type` is its message code.
|
|
6
|
+
*
|
|
7
|
+
* `@aooth/auth-moost` registers it with moost's `registerMessages`, so a moost
|
|
8
|
+
* translator (`setTranslator`) translates a `UserAuthError` by its type and the
|
|
9
|
+
* texts reach the `$i18n` the server sends with form schemas and `/meta`.
|
|
10
|
+
*/
|
|
11
|
+
const USER_AUTH_ERROR_MESSAGES = Object.freeze({
|
|
4
12
|
NOT_FOUND: "User not found",
|
|
5
13
|
ALREADY_EXISTS: "User already exists",
|
|
6
14
|
LOCKED: "Account is locked",
|
|
@@ -13,13 +21,13 @@ const defaultMessages = {
|
|
|
13
21
|
MFA_INVALID: "Invalid MFA code",
|
|
14
22
|
MFA_NOT_CONFIGURED: "MFA method is not configured",
|
|
15
23
|
CAS_EXHAUSTED: "Update conflict — please retry"
|
|
16
|
-
};
|
|
24
|
+
});
|
|
17
25
|
var UserAuthError = class extends Error {
|
|
18
26
|
type;
|
|
19
27
|
details;
|
|
20
28
|
name = "UserAuthError";
|
|
21
29
|
constructor(type, message, details) {
|
|
22
|
-
super(message ??
|
|
30
|
+
super(message ?? USER_AUTH_ERROR_MESSAGES[type]);
|
|
23
31
|
this.type = type;
|
|
24
32
|
this.details = details;
|
|
25
33
|
}
|
|
@@ -129,6 +137,12 @@ Object.defineProperty(exports, "FederatedIdentityStore", {
|
|
|
129
137
|
return FederatedIdentityStore;
|
|
130
138
|
}
|
|
131
139
|
});
|
|
140
|
+
Object.defineProperty(exports, "USER_AUTH_ERROR_MESSAGES", {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function() {
|
|
143
|
+
return USER_AUTH_ERROR_MESSAGES;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
132
146
|
Object.defineProperty(exports, "UserAuthError", {
|
|
133
147
|
enumerable: true,
|
|
134
148
|
get: function() {
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_federated_identity_store = require("./federated-identity-store-
|
|
2
|
+
const require_federated_identity_store = require("./federated-identity-store-DL0He6X_.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
// src/base-x/base32.ts
|
|
5
5
|
/**
|
|
@@ -252,7 +252,7 @@ function normalizePolicies(policies) {
|
|
|
252
252
|
* and only the server check enforces the rule.
|
|
253
253
|
*/
|
|
254
254
|
function definePasswordPolicy(opts) {
|
|
255
|
-
const { rule, args, description, errorMessage } = opts;
|
|
255
|
+
const { rule, args, description, errorMessage, code, params } = opts;
|
|
256
256
|
const def = { rule: args ? (v) => rule(v, ...args) : (v) => rule(v, ...[]) };
|
|
257
257
|
if (args) {
|
|
258
258
|
const argList = args.map((a) => JSON.stringify(a)).join(", ");
|
|
@@ -260,6 +260,8 @@ function definePasswordPolicy(opts) {
|
|
|
260
260
|
}
|
|
261
261
|
if (description !== void 0) def.description = description;
|
|
262
262
|
if (errorMessage !== void 0) def.errorMessage = errorMessage;
|
|
263
|
+
if (code !== void 0) def.code = code;
|
|
264
|
+
if (params !== void 0) def.params = params;
|
|
263
265
|
return def;
|
|
264
266
|
}
|
|
265
267
|
var PasswordPolicy = class {
|
|
@@ -267,11 +269,15 @@ var PasswordPolicy = class {
|
|
|
267
269
|
serialized;
|
|
268
270
|
description;
|
|
269
271
|
errorMessage;
|
|
272
|
+
code;
|
|
273
|
+
params;
|
|
270
274
|
constructor(config) {
|
|
271
275
|
this.rule = config.rule;
|
|
272
276
|
if (config.serialized !== void 0) this.serialized = config.serialized;
|
|
273
277
|
this.description = config.description || "";
|
|
274
278
|
this.errorMessage = config.errorMessage || "";
|
|
279
|
+
if (config.code !== void 0) this.code = config.code;
|
|
280
|
+
if (config.params !== void 0) this.params = config.params;
|
|
275
281
|
}
|
|
276
282
|
evaluate(password, context) {
|
|
277
283
|
return this.rule(password, context);
|
|
@@ -681,7 +687,9 @@ var UserService = class {
|
|
|
681
687
|
result.passed = result.passed && passed;
|
|
682
688
|
result.policies.push({
|
|
683
689
|
description: policy.description,
|
|
684
|
-
passed
|
|
690
|
+
passed,
|
|
691
|
+
errorMessage: policy.errorMessage,
|
|
692
|
+
...policyCodeOf(policy)
|
|
685
693
|
});
|
|
686
694
|
if (!passed) result.errors.push(policy.errorMessage);
|
|
687
695
|
}
|
|
@@ -691,7 +699,8 @@ var UserService = class {
|
|
|
691
699
|
return this.config.password.policies.filter((p) => p.transferable).map((p) => ({
|
|
692
700
|
rule: p.serialized,
|
|
693
701
|
description: p.description,
|
|
694
|
-
errorMessage: p.errorMessage
|
|
702
|
+
errorMessage: p.errorMessage,
|
|
703
|
+
...policyCodeOf(p)
|
|
695
704
|
}));
|
|
696
705
|
}
|
|
697
706
|
async addMfaMethod(id, method) {
|
|
@@ -1134,6 +1143,13 @@ function observeWrites(store, hooks) {
|
|
|
1134
1143
|
return fn;
|
|
1135
1144
|
} });
|
|
1136
1145
|
}
|
|
1146
|
+
/** A policy's message `code` / `params`, when it has them. */
|
|
1147
|
+
function policyCodeOf({ code, params }) {
|
|
1148
|
+
return {
|
|
1149
|
+
...code !== void 0 && { code },
|
|
1150
|
+
...params !== void 0 && { params }
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1137
1153
|
// src/store/memory.ts
|
|
1138
1154
|
var UserStoreMemory = class extends require_federated_identity_store.UserStore {
|
|
1139
1155
|
/** Keyed by the stable surrogate `id` (the token subject). */
|
|
@@ -1310,41 +1326,77 @@ function compositeKey(provider, subject) {
|
|
|
1310
1326
|
return `${provider}${subject}`;
|
|
1311
1327
|
}
|
|
1312
1328
|
// src/password/policies.ts
|
|
1329
|
+
/**
|
|
1330
|
+
* English templates of the built-in password policies' texts, by code: the
|
|
1331
|
+
* failure (`PP_*`, a policy's `errorMessage`) and the rule
|
|
1332
|
+
* (`PP_*_DESCRIPTION`, its `description`). Placeholders: `{min}`, `{max}`,
|
|
1333
|
+
* `{count}`. The templates are the plural forms; the policies' own English
|
|
1334
|
+
* texts are singular / plural-correct and are the fallback a translator
|
|
1335
|
+
* replaces. On a moost server `@aooth/auth-moost` registers them with
|
|
1336
|
+
* `registerMessages` on import.
|
|
1337
|
+
*/
|
|
1338
|
+
const PASSWORD_POLICY_MESSAGES = {
|
|
1339
|
+
PP_MIN_LENGTH: "Password must be at least {min} characters long",
|
|
1340
|
+
PP_MIN_LENGTH_DESCRIPTION: "Minimum length {min}",
|
|
1341
|
+
PP_UPPERCASE: "Password must include at least {count} uppercase characters",
|
|
1342
|
+
PP_UPPERCASE_DESCRIPTION: "At least {count} uppercase characters",
|
|
1343
|
+
PP_LOWERCASE: "Password must include at least {count} lowercase characters",
|
|
1344
|
+
PP_LOWERCASE_DESCRIPTION: "At least {count} lowercase characters",
|
|
1345
|
+
PP_NUMBER: "Password must include at least {count} numbers",
|
|
1346
|
+
PP_NUMBER_DESCRIPTION: "At least {count} numbers",
|
|
1347
|
+
PP_SPECIAL_CHAR: "Password must include at least {count} special characters",
|
|
1348
|
+
PP_SPECIAL_CHAR_DESCRIPTION: "At least {count} special characters",
|
|
1349
|
+
PP_MAX_REPEATED: "Password must not have more than {max} consecutive repeated characters",
|
|
1350
|
+
PP_MAX_REPEATED_DESCRIPTION: "No more than {max} consecutive repeated characters"
|
|
1351
|
+
};
|
|
1352
|
+
const plural = (n) => n === 1 ? "" : "s";
|
|
1313
1353
|
const ppHasMinLength = (min = 8) => definePasswordPolicy({
|
|
1314
1354
|
rule: (v, min) => v.length >= min,
|
|
1315
1355
|
args: [min],
|
|
1316
1356
|
description: `Minimum length ${min}`,
|
|
1317
|
-
errorMessage: `Password must be at least ${min} characters long
|
|
1357
|
+
errorMessage: `Password must be at least ${min} characters long`,
|
|
1358
|
+
code: "PP_MIN_LENGTH",
|
|
1359
|
+
params: { min }
|
|
1318
1360
|
});
|
|
1319
1361
|
const ppHasUpperCase = (n = 1) => definePasswordPolicy({
|
|
1320
1362
|
rule: (v, n) => (v.match(/[A-Z]/g) || []).length >= n,
|
|
1321
1363
|
args: [n],
|
|
1322
|
-
description: `At least ${n} uppercase character${n
|
|
1323
|
-
errorMessage: `Password must include at least ${n} uppercase character${n
|
|
1364
|
+
description: `At least ${n} uppercase character${plural(n)}`,
|
|
1365
|
+
errorMessage: `Password must include at least ${n} uppercase character${plural(n)}`,
|
|
1366
|
+
code: "PP_UPPERCASE",
|
|
1367
|
+
params: { count: n }
|
|
1324
1368
|
});
|
|
1325
1369
|
const ppHasLowerCase = (n = 1) => definePasswordPolicy({
|
|
1326
1370
|
rule: (v, n) => (v.match(/[a-z]/g) || []).length >= n,
|
|
1327
1371
|
args: [n],
|
|
1328
|
-
description: `At least ${n} lowercase character${n
|
|
1329
|
-
errorMessage: `Password must include at least ${n} lowercase character${n
|
|
1372
|
+
description: `At least ${n} lowercase character${plural(n)}`,
|
|
1373
|
+
errorMessage: `Password must include at least ${n} lowercase character${plural(n)}`,
|
|
1374
|
+
code: "PP_LOWERCASE",
|
|
1375
|
+
params: { count: n }
|
|
1330
1376
|
});
|
|
1331
1377
|
const ppHasNumber = (n = 1) => definePasswordPolicy({
|
|
1332
1378
|
rule: (v, n) => (v.match(/\d/g) || []).length >= n,
|
|
1333
1379
|
args: [n],
|
|
1334
|
-
description: `At least ${n} number${n
|
|
1335
|
-
errorMessage: `Password must include at least ${n} number${n
|
|
1380
|
+
description: `At least ${n} number${plural(n)}`,
|
|
1381
|
+
errorMessage: `Password must include at least ${n} number${plural(n)}`,
|
|
1382
|
+
code: "PP_NUMBER",
|
|
1383
|
+
params: { count: n }
|
|
1336
1384
|
});
|
|
1337
1385
|
const ppHasSpecialChar = (n = 1) => definePasswordPolicy({
|
|
1338
1386
|
rule: (v, n) => (v.match(/[^A-Za-z0-9]/g) || []).length >= n,
|
|
1339
1387
|
args: [n],
|
|
1340
|
-
description: `At least ${n} special character${n
|
|
1341
|
-
errorMessage: `Password must include at least ${n} special character${n
|
|
1388
|
+
description: `At least ${n} special character${plural(n)}`,
|
|
1389
|
+
errorMessage: `Password must include at least ${n} special character${plural(n)}`,
|
|
1390
|
+
code: "PP_SPECIAL_CHAR",
|
|
1391
|
+
params: { count: n }
|
|
1342
1392
|
});
|
|
1343
1393
|
const ppMaxRepeatedChars = (maxRepeated = 2) => definePasswordPolicy({
|
|
1344
1394
|
rule: (v, maxRepeated) => !new RegExp(`(.)\\1{${maxRepeated},}`).test(v),
|
|
1345
1395
|
args: [maxRepeated],
|
|
1346
1396
|
description: `No more than ${maxRepeated} consecutive repeated characters`,
|
|
1347
|
-
errorMessage: `Password must not have more than ${maxRepeated} consecutive repeated characters
|
|
1397
|
+
errorMessage: `Password must not have more than ${maxRepeated} consecutive repeated characters`,
|
|
1398
|
+
code: "PP_MAX_REPEATED",
|
|
1399
|
+
params: { max: maxRepeated }
|
|
1348
1400
|
});
|
|
1349
1401
|
// src/mfa/codes.ts
|
|
1350
1402
|
/**
|
|
@@ -1373,9 +1425,11 @@ function verifyMfaCode(submitted, expectedHash) {
|
|
|
1373
1425
|
}
|
|
1374
1426
|
exports.FederatedIdentityStore = require_federated_identity_store.FederatedIdentityStore;
|
|
1375
1427
|
exports.FederatedIdentityStoreMemory = FederatedIdentityStoreMemory;
|
|
1428
|
+
exports.PASSWORD_POLICY_MESSAGES = PASSWORD_POLICY_MESSAGES;
|
|
1376
1429
|
exports.PasswordHasher = PasswordHasher;
|
|
1377
1430
|
exports.PasswordPolicy = PasswordPolicy;
|
|
1378
1431
|
exports.SEEN_DEVICES_DEFAULT_CAP = SEEN_DEVICES_DEFAULT_CAP;
|
|
1432
|
+
exports.USER_AUTH_ERROR_MESSAGES = require_federated_identity_store.USER_AUTH_ERROR_MESSAGES;
|
|
1379
1433
|
exports.UserAuthError = require_federated_identity_store.UserAuthError;
|
|
1380
1434
|
exports.UserService = UserService;
|
|
1381
1435
|
exports.UserStore = require_federated_identity_store.UserStore;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as UserStoreUpdate, C as PolicyCheckResult, D as UserAuthErrorType, E as TrustedDeviceRecord, O as UserCredentials, S as PasswordPolicyParams, T as TransferablePolicy, _ as PasswordData, a as pickDefinedProfile, b as PasswordPolicyEvalFn, c as AccountData, d as LockoutConfig, f as LoginResult, g as PasswordConfig, h as MfaMethodInfo, i as NewFederatedIdentity, k as UserServiceConfig, l as DeepPartial, m as MfaMethod, n as FederatedIdentityStore, o as UserStore, p as MfaData, r as FederatedProfileSnapshot, s as WithCasOptions, t as FederatedIdentity, u as LockStatus, v as PasswordPolicyContext, w as TotpConfig, x as PasswordPolicyInstance, y as PasswordPolicyDef } from "./federated-identity-store-D8BFFhpm.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* The default English message of each `UserAuthError` type — the error's
|
|
4
|
+
* `type` is its message code.
|
|
5
|
+
*
|
|
6
|
+
* `@aooth/auth-moost` registers it with moost's `registerMessages`, so a moost
|
|
7
|
+
* translator (`setTranslator`) translates a `UserAuthError` by its type and the
|
|
8
|
+
* texts reach the `$i18n` the server sends with form schemas and `/meta`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const USER_AUTH_ERROR_MESSAGES: Readonly<Record<UserAuthErrorType, string>>;
|
|
2
11
|
export declare class UserAuthError extends Error {
|
|
3
12
|
readonly type: UserAuthErrorType;
|
|
4
13
|
readonly details?: Record<string, unknown> | undefined;
|
|
@@ -43,12 +52,18 @@ export declare function definePasswordPolicy<A extends readonly unknown[]>(opts:
|
|
|
43
52
|
args?: A;
|
|
44
53
|
description?: string;
|
|
45
54
|
errorMessage?: string;
|
|
55
|
+
/** Message code of the texts (see {@link PasswordPolicyDef.code}). */
|
|
56
|
+
code?: string;
|
|
57
|
+
/** Values of the code's `{name}` placeholders. */
|
|
58
|
+
params?: PasswordPolicyParams;
|
|
46
59
|
}): PasswordPolicyDef;
|
|
47
60
|
export declare class PasswordPolicy implements PasswordPolicyInstance {
|
|
48
61
|
readonly rule: PasswordPolicyEvalFn;
|
|
49
62
|
readonly serialized?: string;
|
|
50
63
|
readonly description: string;
|
|
51
64
|
readonly errorMessage: string;
|
|
65
|
+
readonly code?: string;
|
|
66
|
+
readonly params?: PasswordPolicyParams;
|
|
52
67
|
constructor(config: PasswordPolicyDef);
|
|
53
68
|
evaluate(password: string, context?: PasswordPolicyContext): boolean | Promise<boolean>;
|
|
54
69
|
get transferable(): boolean;
|
|
@@ -460,6 +475,31 @@ export declare class FederatedIdentityStoreMemory extends FederatedIdentityStore
|
|
|
460
475
|
touchLogin(provider: string, subject: string, profile?: FederatedProfileSnapshot): Promise<void>;
|
|
461
476
|
deleteAllForUser(userId: string): Promise<number>;
|
|
462
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* English templates of the built-in password policies' texts, by code: the
|
|
480
|
+
* failure (`PP_*`, a policy's `errorMessage`) and the rule
|
|
481
|
+
* (`PP_*_DESCRIPTION`, its `description`). Placeholders: `{min}`, `{max}`,
|
|
482
|
+
* `{count}`. The templates are the plural forms; the policies' own English
|
|
483
|
+
* texts are singular / plural-correct and are the fallback a translator
|
|
484
|
+
* replaces. On a moost server `@aooth/auth-moost` registers them with
|
|
485
|
+
* `registerMessages` on import.
|
|
486
|
+
*/
|
|
487
|
+
export declare const PASSWORD_POLICY_MESSAGES: {
|
|
488
|
+
readonly PP_MIN_LENGTH: "Password must be at least {min} characters long";
|
|
489
|
+
readonly PP_MIN_LENGTH_DESCRIPTION: "Minimum length {min}";
|
|
490
|
+
readonly PP_UPPERCASE: "Password must include at least {count} uppercase characters";
|
|
491
|
+
readonly PP_UPPERCASE_DESCRIPTION: "At least {count} uppercase characters";
|
|
492
|
+
readonly PP_LOWERCASE: "Password must include at least {count} lowercase characters";
|
|
493
|
+
readonly PP_LOWERCASE_DESCRIPTION: "At least {count} lowercase characters";
|
|
494
|
+
readonly PP_NUMBER: "Password must include at least {count} numbers";
|
|
495
|
+
readonly PP_NUMBER_DESCRIPTION: "At least {count} numbers";
|
|
496
|
+
readonly PP_SPECIAL_CHAR: "Password must include at least {count} special characters";
|
|
497
|
+
readonly PP_SPECIAL_CHAR_DESCRIPTION: "At least {count} special characters";
|
|
498
|
+
readonly PP_MAX_REPEATED: "Password must not have more than {max} consecutive repeated characters";
|
|
499
|
+
readonly PP_MAX_REPEATED_DESCRIPTION: "No more than {max} consecutive repeated characters";
|
|
500
|
+
};
|
|
501
|
+
/** A code of {@link PASSWORD_POLICY_MESSAGES}. */
|
|
502
|
+
type PasswordPolicyMessageCode = keyof typeof PASSWORD_POLICY_MESSAGES;
|
|
463
503
|
export declare const ppHasMinLength: (min?: number) => PasswordPolicyDef;
|
|
464
504
|
export declare const ppHasUpperCase: (n?: number) => PasswordPolicyDef;
|
|
465
505
|
export declare const ppHasLowerCase: (n?: number) => PasswordPolicyDef;
|
|
@@ -496,4 +536,4 @@ export declare function maskEmail(email: string): string;
|
|
|
496
536
|
export declare function maskPhone(phone: string): string;
|
|
497
537
|
export declare function maskMfaValue(method: MfaMethod): string;
|
|
498
538
|
export declare function setAtPath(obj: object, path: string, value: unknown): void;
|
|
499
|
-
export { type AccountData, type DeepPartial, type FederatedIdentity, FederatedIdentityStore, type FederatedIdentityStoreMemoryOptions, type FederatedProfileSnapshot, type LockStatus, type LockoutConfig, type LoginResult, type MfaData, type MfaMethod, type MfaMethodInfo, type NewFederatedIdentity, type PasswordConfig, type PasswordData, type PasswordPolicyContext, type PasswordPolicyDef, type PasswordPolicyEvalFn, type PasswordPolicyInstance, type PolicyCheckResult, type TotpConfig, type TransferablePolicy, type TrustedDeviceRecord, type UserAuthErrorType, type UserCredentials, type UserServiceConfig, UserStore, type UserStoreUpdate, pickDefinedProfile };
|
|
539
|
+
export { type AccountData, type DeepPartial, type FederatedIdentity, FederatedIdentityStore, type FederatedIdentityStoreMemoryOptions, type FederatedProfileSnapshot, type LockStatus, type LockoutConfig, type LoginResult, type MfaData, type MfaMethod, type MfaMethodInfo, type NewFederatedIdentity, type PasswordConfig, type PasswordData, type PasswordPolicyContext, type PasswordPolicyDef, type PasswordPolicyEvalFn, type PasswordPolicyInstance, type PasswordPolicyMessageCode, type PasswordPolicyParams, type PolicyCheckResult, type TotpConfig, type TransferablePolicy, type TrustedDeviceRecord, type UserAuthErrorType, type UserCredentials, type UserServiceConfig, UserStore, type UserStoreUpdate, pickDefinedProfile };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as UserStoreUpdate, C as PolicyCheckResult, D as UserAuthErrorType, E as TrustedDeviceRecord, O as UserCredentials, S as PasswordPolicyParams, T as TransferablePolicy, _ as PasswordData, a as pickDefinedProfile, b as PasswordPolicyEvalFn, c as AccountData, d as LockoutConfig, f as LoginResult, g as PasswordConfig, h as MfaMethodInfo, i as NewFederatedIdentity, k as UserServiceConfig, l as DeepPartial, m as MfaMethod, n as FederatedIdentityStore, o as UserStore, p as MfaData, r as FederatedProfileSnapshot, s as WithCasOptions, t as FederatedIdentity, u as LockStatus, v as PasswordPolicyContext, w as TotpConfig, x as PasswordPolicyInstance, y as PasswordPolicyDef } from "./federated-identity-store-D8BFFhpm.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The default English message of each `UserAuthError` type — the error's
|
|
4
|
+
* `type` is its message code.
|
|
5
|
+
*
|
|
6
|
+
* `@aooth/auth-moost` registers it with moost's `registerMessages`, so a moost
|
|
7
|
+
* translator (`setTranslator`) translates a `UserAuthError` by its type and the
|
|
8
|
+
* texts reach the `$i18n` the server sends with form schemas and `/meta`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const USER_AUTH_ERROR_MESSAGES: Readonly<Record<UserAuthErrorType, string>>;
|
|
2
11
|
export declare class UserAuthError extends Error {
|
|
3
12
|
readonly type: UserAuthErrorType;
|
|
4
13
|
readonly details?: Record<string, unknown> | undefined;
|
|
@@ -43,12 +52,18 @@ export declare function definePasswordPolicy<A extends readonly unknown[]>(opts:
|
|
|
43
52
|
args?: A;
|
|
44
53
|
description?: string;
|
|
45
54
|
errorMessage?: string;
|
|
55
|
+
/** Message code of the texts (see {@link PasswordPolicyDef.code}). */
|
|
56
|
+
code?: string;
|
|
57
|
+
/** Values of the code's `{name}` placeholders. */
|
|
58
|
+
params?: PasswordPolicyParams;
|
|
46
59
|
}): PasswordPolicyDef;
|
|
47
60
|
export declare class PasswordPolicy implements PasswordPolicyInstance {
|
|
48
61
|
readonly rule: PasswordPolicyEvalFn;
|
|
49
62
|
readonly serialized?: string;
|
|
50
63
|
readonly description: string;
|
|
51
64
|
readonly errorMessage: string;
|
|
65
|
+
readonly code?: string;
|
|
66
|
+
readonly params?: PasswordPolicyParams;
|
|
52
67
|
constructor(config: PasswordPolicyDef);
|
|
53
68
|
evaluate(password: string, context?: PasswordPolicyContext): boolean | Promise<boolean>;
|
|
54
69
|
get transferable(): boolean;
|
|
@@ -460,6 +475,31 @@ export declare class FederatedIdentityStoreMemory extends FederatedIdentityStore
|
|
|
460
475
|
touchLogin(provider: string, subject: string, profile?: FederatedProfileSnapshot): Promise<void>;
|
|
461
476
|
deleteAllForUser(userId: string): Promise<number>;
|
|
462
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* English templates of the built-in password policies' texts, by code: the
|
|
480
|
+
* failure (`PP_*`, a policy's `errorMessage`) and the rule
|
|
481
|
+
* (`PP_*_DESCRIPTION`, its `description`). Placeholders: `{min}`, `{max}`,
|
|
482
|
+
* `{count}`. The templates are the plural forms; the policies' own English
|
|
483
|
+
* texts are singular / plural-correct and are the fallback a translator
|
|
484
|
+
* replaces. On a moost server `@aooth/auth-moost` registers them with
|
|
485
|
+
* `registerMessages` on import.
|
|
486
|
+
*/
|
|
487
|
+
export declare const PASSWORD_POLICY_MESSAGES: {
|
|
488
|
+
readonly PP_MIN_LENGTH: "Password must be at least {min} characters long";
|
|
489
|
+
readonly PP_MIN_LENGTH_DESCRIPTION: "Minimum length {min}";
|
|
490
|
+
readonly PP_UPPERCASE: "Password must include at least {count} uppercase characters";
|
|
491
|
+
readonly PP_UPPERCASE_DESCRIPTION: "At least {count} uppercase characters";
|
|
492
|
+
readonly PP_LOWERCASE: "Password must include at least {count} lowercase characters";
|
|
493
|
+
readonly PP_LOWERCASE_DESCRIPTION: "At least {count} lowercase characters";
|
|
494
|
+
readonly PP_NUMBER: "Password must include at least {count} numbers";
|
|
495
|
+
readonly PP_NUMBER_DESCRIPTION: "At least {count} numbers";
|
|
496
|
+
readonly PP_SPECIAL_CHAR: "Password must include at least {count} special characters";
|
|
497
|
+
readonly PP_SPECIAL_CHAR_DESCRIPTION: "At least {count} special characters";
|
|
498
|
+
readonly PP_MAX_REPEATED: "Password must not have more than {max} consecutive repeated characters";
|
|
499
|
+
readonly PP_MAX_REPEATED_DESCRIPTION: "No more than {max} consecutive repeated characters";
|
|
500
|
+
};
|
|
501
|
+
/** A code of {@link PASSWORD_POLICY_MESSAGES}. */
|
|
502
|
+
type PasswordPolicyMessageCode = keyof typeof PASSWORD_POLICY_MESSAGES;
|
|
463
503
|
export declare const ppHasMinLength: (min?: number) => PasswordPolicyDef;
|
|
464
504
|
export declare const ppHasUpperCase: (n?: number) => PasswordPolicyDef;
|
|
465
505
|
export declare const ppHasLowerCase: (n?: number) => PasswordPolicyDef;
|
|
@@ -496,4 +536,4 @@ export declare function maskEmail(email: string): string;
|
|
|
496
536
|
export declare function maskPhone(phone: string): string;
|
|
497
537
|
export declare function maskMfaValue(method: MfaMethod): string;
|
|
498
538
|
export declare function setAtPath(obj: object, path: string, value: unknown): void;
|
|
499
|
-
export { type AccountData, type DeepPartial, type FederatedIdentity, FederatedIdentityStore, type FederatedIdentityStoreMemoryOptions, type FederatedProfileSnapshot, type LockStatus, type LockoutConfig, type LoginResult, type MfaData, type MfaMethod, type MfaMethodInfo, type NewFederatedIdentity, type PasswordConfig, type PasswordData, type PasswordPolicyContext, type PasswordPolicyDef, type PasswordPolicyEvalFn, type PasswordPolicyInstance, type PolicyCheckResult, type TotpConfig, type TransferablePolicy, type TrustedDeviceRecord, type UserAuthErrorType, type UserCredentials, type UserServiceConfig, UserStore, type UserStoreUpdate, pickDefinedProfile };
|
|
539
|
+
export { type AccountData, type DeepPartial, type FederatedIdentity, FederatedIdentityStore, type FederatedIdentityStoreMemoryOptions, type FederatedProfileSnapshot, type LockStatus, type LockoutConfig, type LoginResult, type MfaData, type MfaMethod, type MfaMethodInfo, type NewFederatedIdentity, type PasswordConfig, type PasswordData, type PasswordPolicyContext, type PasswordPolicyDef, type PasswordPolicyEvalFn, type PasswordPolicyInstance, type PasswordPolicyMessageCode, type PasswordPolicyParams, type PolicyCheckResult, type TotpConfig, type TransferablePolicy, type TrustedDeviceRecord, type UserAuthErrorType, type UserCredentials, type UserServiceConfig, UserStore, type UserStoreUpdate, pickDefinedProfile };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as maskEmail, c as setAtPath, i as incrementAtPath, l as UserStore, n as pickDefinedProfile, o as maskMfaValue, r as deepMerge, s as maskPhone, t as FederatedIdentityStore, u as
|
|
1
|
+
import { a as maskEmail, c as setAtPath, d as UserAuthError, i as incrementAtPath, l as UserStore, n as pickDefinedProfile, o as maskMfaValue, r as deepMerge, s as maskPhone, t as FederatedIdentityStore, u as USER_AUTH_ERROR_MESSAGES } from "./federated-identity-store-B1J4lMeN.mjs";
|
|
2
2
|
import { createHash, createHmac, randomBytes, randomInt, randomUUID, scrypt, timingSafeEqual } from "node:crypto";
|
|
3
3
|
// src/base-x/base32.ts
|
|
4
4
|
/**
|
|
@@ -251,7 +251,7 @@ function normalizePolicies(policies) {
|
|
|
251
251
|
* and only the server check enforces the rule.
|
|
252
252
|
*/
|
|
253
253
|
function definePasswordPolicy(opts) {
|
|
254
|
-
const { rule, args, description, errorMessage } = opts;
|
|
254
|
+
const { rule, args, description, errorMessage, code, params } = opts;
|
|
255
255
|
const def = { rule: args ? (v) => rule(v, ...args) : (v) => rule(v, ...[]) };
|
|
256
256
|
if (args) {
|
|
257
257
|
const argList = args.map((a) => JSON.stringify(a)).join(", ");
|
|
@@ -259,6 +259,8 @@ function definePasswordPolicy(opts) {
|
|
|
259
259
|
}
|
|
260
260
|
if (description !== void 0) def.description = description;
|
|
261
261
|
if (errorMessage !== void 0) def.errorMessage = errorMessage;
|
|
262
|
+
if (code !== void 0) def.code = code;
|
|
263
|
+
if (params !== void 0) def.params = params;
|
|
262
264
|
return def;
|
|
263
265
|
}
|
|
264
266
|
var PasswordPolicy = class {
|
|
@@ -266,11 +268,15 @@ var PasswordPolicy = class {
|
|
|
266
268
|
serialized;
|
|
267
269
|
description;
|
|
268
270
|
errorMessage;
|
|
271
|
+
code;
|
|
272
|
+
params;
|
|
269
273
|
constructor(config) {
|
|
270
274
|
this.rule = config.rule;
|
|
271
275
|
if (config.serialized !== void 0) this.serialized = config.serialized;
|
|
272
276
|
this.description = config.description || "";
|
|
273
277
|
this.errorMessage = config.errorMessage || "";
|
|
278
|
+
if (config.code !== void 0) this.code = config.code;
|
|
279
|
+
if (config.params !== void 0) this.params = config.params;
|
|
274
280
|
}
|
|
275
281
|
evaluate(password, context) {
|
|
276
282
|
return this.rule(password, context);
|
|
@@ -680,7 +686,9 @@ var UserService = class {
|
|
|
680
686
|
result.passed = result.passed && passed;
|
|
681
687
|
result.policies.push({
|
|
682
688
|
description: policy.description,
|
|
683
|
-
passed
|
|
689
|
+
passed,
|
|
690
|
+
errorMessage: policy.errorMessage,
|
|
691
|
+
...policyCodeOf(policy)
|
|
684
692
|
});
|
|
685
693
|
if (!passed) result.errors.push(policy.errorMessage);
|
|
686
694
|
}
|
|
@@ -690,7 +698,8 @@ var UserService = class {
|
|
|
690
698
|
return this.config.password.policies.filter((p) => p.transferable).map((p) => ({
|
|
691
699
|
rule: p.serialized,
|
|
692
700
|
description: p.description,
|
|
693
|
-
errorMessage: p.errorMessage
|
|
701
|
+
errorMessage: p.errorMessage,
|
|
702
|
+
...policyCodeOf(p)
|
|
694
703
|
}));
|
|
695
704
|
}
|
|
696
705
|
async addMfaMethod(id, method) {
|
|
@@ -1133,6 +1142,13 @@ function observeWrites(store, hooks) {
|
|
|
1133
1142
|
return fn;
|
|
1134
1143
|
} });
|
|
1135
1144
|
}
|
|
1145
|
+
/** A policy's message `code` / `params`, when it has them. */
|
|
1146
|
+
function policyCodeOf({ code, params }) {
|
|
1147
|
+
return {
|
|
1148
|
+
...code !== void 0 && { code },
|
|
1149
|
+
...params !== void 0 && { params }
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1136
1152
|
// src/store/memory.ts
|
|
1137
1153
|
var UserStoreMemory = class extends UserStore {
|
|
1138
1154
|
/** Keyed by the stable surrogate `id` (the token subject). */
|
|
@@ -1309,41 +1325,77 @@ function compositeKey(provider, subject) {
|
|
|
1309
1325
|
return `${provider}${subject}`;
|
|
1310
1326
|
}
|
|
1311
1327
|
// src/password/policies.ts
|
|
1328
|
+
/**
|
|
1329
|
+
* English templates of the built-in password policies' texts, by code: the
|
|
1330
|
+
* failure (`PP_*`, a policy's `errorMessage`) and the rule
|
|
1331
|
+
* (`PP_*_DESCRIPTION`, its `description`). Placeholders: `{min}`, `{max}`,
|
|
1332
|
+
* `{count}`. The templates are the plural forms; the policies' own English
|
|
1333
|
+
* texts are singular / plural-correct and are the fallback a translator
|
|
1334
|
+
* replaces. On a moost server `@aooth/auth-moost` registers them with
|
|
1335
|
+
* `registerMessages` on import.
|
|
1336
|
+
*/
|
|
1337
|
+
const PASSWORD_POLICY_MESSAGES = {
|
|
1338
|
+
PP_MIN_LENGTH: "Password must be at least {min} characters long",
|
|
1339
|
+
PP_MIN_LENGTH_DESCRIPTION: "Minimum length {min}",
|
|
1340
|
+
PP_UPPERCASE: "Password must include at least {count} uppercase characters",
|
|
1341
|
+
PP_UPPERCASE_DESCRIPTION: "At least {count} uppercase characters",
|
|
1342
|
+
PP_LOWERCASE: "Password must include at least {count} lowercase characters",
|
|
1343
|
+
PP_LOWERCASE_DESCRIPTION: "At least {count} lowercase characters",
|
|
1344
|
+
PP_NUMBER: "Password must include at least {count} numbers",
|
|
1345
|
+
PP_NUMBER_DESCRIPTION: "At least {count} numbers",
|
|
1346
|
+
PP_SPECIAL_CHAR: "Password must include at least {count} special characters",
|
|
1347
|
+
PP_SPECIAL_CHAR_DESCRIPTION: "At least {count} special characters",
|
|
1348
|
+
PP_MAX_REPEATED: "Password must not have more than {max} consecutive repeated characters",
|
|
1349
|
+
PP_MAX_REPEATED_DESCRIPTION: "No more than {max} consecutive repeated characters"
|
|
1350
|
+
};
|
|
1351
|
+
const plural = (n) => n === 1 ? "" : "s";
|
|
1312
1352
|
const ppHasMinLength = (min = 8) => definePasswordPolicy({
|
|
1313
1353
|
rule: (v, min) => v.length >= min,
|
|
1314
1354
|
args: [min],
|
|
1315
1355
|
description: `Minimum length ${min}`,
|
|
1316
|
-
errorMessage: `Password must be at least ${min} characters long
|
|
1356
|
+
errorMessage: `Password must be at least ${min} characters long`,
|
|
1357
|
+
code: "PP_MIN_LENGTH",
|
|
1358
|
+
params: { min }
|
|
1317
1359
|
});
|
|
1318
1360
|
const ppHasUpperCase = (n = 1) => definePasswordPolicy({
|
|
1319
1361
|
rule: (v, n) => (v.match(/[A-Z]/g) || []).length >= n,
|
|
1320
1362
|
args: [n],
|
|
1321
|
-
description: `At least ${n} uppercase character${n
|
|
1322
|
-
errorMessage: `Password must include at least ${n} uppercase character${n
|
|
1363
|
+
description: `At least ${n} uppercase character${plural(n)}`,
|
|
1364
|
+
errorMessage: `Password must include at least ${n} uppercase character${plural(n)}`,
|
|
1365
|
+
code: "PP_UPPERCASE",
|
|
1366
|
+
params: { count: n }
|
|
1323
1367
|
});
|
|
1324
1368
|
const ppHasLowerCase = (n = 1) => definePasswordPolicy({
|
|
1325
1369
|
rule: (v, n) => (v.match(/[a-z]/g) || []).length >= n,
|
|
1326
1370
|
args: [n],
|
|
1327
|
-
description: `At least ${n} lowercase character${n
|
|
1328
|
-
errorMessage: `Password must include at least ${n} lowercase character${n
|
|
1371
|
+
description: `At least ${n} lowercase character${plural(n)}`,
|
|
1372
|
+
errorMessage: `Password must include at least ${n} lowercase character${plural(n)}`,
|
|
1373
|
+
code: "PP_LOWERCASE",
|
|
1374
|
+
params: { count: n }
|
|
1329
1375
|
});
|
|
1330
1376
|
const ppHasNumber = (n = 1) => definePasswordPolicy({
|
|
1331
1377
|
rule: (v, n) => (v.match(/\d/g) || []).length >= n,
|
|
1332
1378
|
args: [n],
|
|
1333
|
-
description: `At least ${n} number${n
|
|
1334
|
-
errorMessage: `Password must include at least ${n} number${n
|
|
1379
|
+
description: `At least ${n} number${plural(n)}`,
|
|
1380
|
+
errorMessage: `Password must include at least ${n} number${plural(n)}`,
|
|
1381
|
+
code: "PP_NUMBER",
|
|
1382
|
+
params: { count: n }
|
|
1335
1383
|
});
|
|
1336
1384
|
const ppHasSpecialChar = (n = 1) => definePasswordPolicy({
|
|
1337
1385
|
rule: (v, n) => (v.match(/[^A-Za-z0-9]/g) || []).length >= n,
|
|
1338
1386
|
args: [n],
|
|
1339
|
-
description: `At least ${n} special character${n
|
|
1340
|
-
errorMessage: `Password must include at least ${n} special character${n
|
|
1387
|
+
description: `At least ${n} special character${plural(n)}`,
|
|
1388
|
+
errorMessage: `Password must include at least ${n} special character${plural(n)}`,
|
|
1389
|
+
code: "PP_SPECIAL_CHAR",
|
|
1390
|
+
params: { count: n }
|
|
1341
1391
|
});
|
|
1342
1392
|
const ppMaxRepeatedChars = (maxRepeated = 2) => definePasswordPolicy({
|
|
1343
1393
|
rule: (v, maxRepeated) => !new RegExp(`(.)\\1{${maxRepeated},}`).test(v),
|
|
1344
1394
|
args: [maxRepeated],
|
|
1345
1395
|
description: `No more than ${maxRepeated} consecutive repeated characters`,
|
|
1346
|
-
errorMessage: `Password must not have more than ${maxRepeated} consecutive repeated characters
|
|
1396
|
+
errorMessage: `Password must not have more than ${maxRepeated} consecutive repeated characters`,
|
|
1397
|
+
code: "PP_MAX_REPEATED",
|
|
1398
|
+
params: { max: maxRepeated }
|
|
1347
1399
|
});
|
|
1348
1400
|
// src/mfa/codes.ts
|
|
1349
1401
|
/**
|
|
@@ -1370,4 +1422,4 @@ function verifyMfaCode(submitted, expectedHash) {
|
|
|
1370
1422
|
if (a.length !== b.length) return false;
|
|
1371
1423
|
return timingSafeEqual(a, b);
|
|
1372
1424
|
}
|
|
1373
|
-
export { FederatedIdentityStore, FederatedIdentityStoreMemory, PasswordHasher, PasswordPolicy, SEEN_DEVICES_DEFAULT_CAP, UserAuthError, UserService, UserStore, UserStoreMemory, definePasswordPolicy, generateMfaCode, generateTotpCode, generateTotpSecret, generateTotpUri, hashMfaCode, maskEmail, maskMfaValue, maskPhone, normalizePolicies, pickDefinedProfile, ppHasLowerCase, ppHasMinLength, ppHasNumber, ppHasSpecialChar, ppHasUpperCase, ppMaxRepeatedChars, setAtPath, verifyMfaCode, verifyTotpCode };
|
|
1425
|
+
export { FederatedIdentityStore, FederatedIdentityStoreMemory, PASSWORD_POLICY_MESSAGES, PasswordHasher, PasswordPolicy, SEEN_DEVICES_DEFAULT_CAP, USER_AUTH_ERROR_MESSAGES, UserAuthError, UserService, UserStore, UserStoreMemory, definePasswordPolicy, generateMfaCode, generateTotpCode, generateTotpSecret, generateTotpUri, hashMfaCode, maskEmail, maskMfaValue, maskPhone, normalizePolicies, pickDefinedProfile, ppHasLowerCase, ppHasMinLength, ppHasNumber, ppHasSpecialChar, ppHasUpperCase, ppMaxRepeatedChars, setAtPath, verifyMfaCode, verifyTotpCode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/user",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "User credential primitives for aoothjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aoothjs",
|
|
@@ -60,18 +60,18 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@atscript/core": "^0.2.
|
|
64
|
-
"@atscript/db": "^0.1.
|
|
65
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
66
|
-
"@atscript/db-sqlite": "^0.1.
|
|
67
|
-
"@atscript/typescript": "^0.2.
|
|
63
|
+
"@atscript/core": "^0.2.8",
|
|
64
|
+
"@atscript/db": "^0.1.171",
|
|
65
|
+
"@atscript/db-sql-tools": "^0.1.171",
|
|
66
|
+
"@atscript/db-sqlite": "^0.1.171",
|
|
67
|
+
"@atscript/typescript": "^0.2.8",
|
|
68
68
|
"@types/better-sqlite3": "^7.6.13",
|
|
69
|
-
"@uniqu/core": "^0.2.
|
|
69
|
+
"@uniqu/core": "^0.2.1",
|
|
70
70
|
"better-sqlite3": "^12.6.2",
|
|
71
|
-
"unplugin-atscript": "^0.2.
|
|
71
|
+
"unplugin-atscript": "^0.2.8"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@atscript/db": "^0.1.
|
|
74
|
+
"@atscript/db": "^0.1.171"
|
|
75
75
|
},
|
|
76
76
|
"peerDependenciesMeta": {
|
|
77
77
|
"@atscript/db": {
|