@axiumine/koa-utils 5.2.0 → 5.4.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.
- package/README.md +28 -0
- package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.d.mts +2 -1
- package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +22 -4
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +31 -15
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/login4Ever.d.mts +3 -3
- package/dist/graphQL/schema/mutations/login4Ever.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginAdmin.d.mts +3 -3
- package/dist/graphQL/schema/mutations/loginAdmin.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginRememberme.d.mts +3 -3
- package/dist/graphQL/schema/mutations/loginRememberme.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/resetPwd.d.mts +18 -4
- package/dist/graphQL/schema/mutations/resetPwd.mjs +9 -4
- package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/signUp.d.mts +3 -3
- package/dist/graphQL/schema/mutations/signUp.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/updatePassword.d.mts +24 -4
- package/dist/graphQL/schema/mutations/updatePassword.mjs +18 -5
- package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
- package/dist/koa/router/verifyEmail.d.mts +22 -1
- package/dist/koa/router/verifyEmail.mjs +18 -9
- package/dist/koa/router/verifyEmail.mjs.map +1 -1
- package/dist/lib/access/accessPaths.d.mts +96 -0
- package/dist/lib/access/accessPaths.mjs +48 -0
- package/dist/lib/access/accessPaths.mjs.map +1 -0
- package/dist/lib/access/createResetPwdFlow.d.mts +33 -0
- package/dist/lib/access/createResetPwdFlow.mjs +42 -0
- package/dist/lib/access/createResetPwdFlow.mjs.map +1 -0
- package/dist/lib/access/createVerifyEmailFlow.d.mts +48 -0
- package/dist/lib/access/createVerifyEmailFlow.mjs +68 -0
- package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -0
- package/dist/lib/db/log/logGlobalError.d.mts +2 -2
- package/dist/lib/db/log/logGlobalError.mjs.map +1 -1
- package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +20 -2
- package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +30 -12
- package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
- package/dist/private/lib/access/db/confirmNewEmail.d.mts +7 -1
- package/dist/private/lib/access/db/confirmNewEmail.mjs +12 -11
- package/dist/private/lib/access/db/confirmNewEmail.mjs.map +1 -1
- package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -1
- package/dist/private/lib/access/db/deleteUserByEmail.mjs +6 -3
- package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
- package/dist/private/lib/access/db/enableEmailAccess.d.mts +6 -1
- package/dist/private/lib/access/db/enableEmailAccess.mjs +9 -9
- package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
- package/dist/private/lib/access/db/getResetPwd.d.mts +11 -4
- package/dist/private/lib/access/db/getResetPwd.mjs +31 -12
- package/dist/private/lib/access/db/getResetPwd.mjs.map +1 -1
- package/dist/private/lib/access/db/incReqTimes.d.mts +6 -1
- package/dist/private/lib/access/db/incReqTimes.mjs +6 -3
- package/dist/private/lib/access/db/incReqTimes.mjs.map +1 -1
- package/dist/private/lib/access/db/removeResetReq.d.mts +7 -1
- package/dist/private/lib/access/db/removeResetReq.mjs +16 -7
- package/dist/private/lib/access/db/removeResetReq.mjs.map +1 -1
- package/dist/private/lib/access/db/saveResetReq.d.mts +6 -1
- package/dist/private/lib/access/db/saveResetReq.mjs +10 -7
- package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
- package/dist/private/lib/access/db/setEmailHash.d.mts +6 -1
- package/dist/private/lib/access/db/setEmailHash.mjs +9 -6
- package/dist/private/lib/access/db/setEmailHash.mjs.map +1 -1
- package/dist/private/lib/access/db/updatePasswordDb.d.mts +7 -1
- package/dist/private/lib/access/db/updatePasswordDb.mjs +6 -3
- package/dist/private/lib/access/db/updatePasswordDb.mjs.map +1 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +6 -3
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs +12 -5
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs.map +1 -1
- package/dist/private/lib/access/handleIfHashBad.d.mts +10 -3
- package/dist/private/lib/access/handleIfHashBad.mjs +9 -5
- package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +12 -1
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +11 -3
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +12 -1
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +11 -3
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
- package/dist/private/lib/access/pathTools.d.mts +25 -0
- package/dist/private/lib/access/pathTools.mjs +43 -0
- package/dist/private/lib/access/pathTools.mjs.map +1 -0
- package/package.json +14 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/** Payload accepted by `logGlobalError`. Exported so a consumer re-exporting the helper can name its type. */
|
|
2
|
+
export interface IGlobalError {
|
|
2
3
|
message: string;
|
|
3
4
|
stackArr: Array<string>;
|
|
4
5
|
}
|
|
5
6
|
export declare const logGlobalError: (log: IGlobalError) => void;
|
|
6
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logGlobalError.mjs","sourceRoot":"","sources":["../../../../src/lib/db/log/logGlobalError.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,+DAA8C;
|
|
1
|
+
{"version":3,"file":"logGlobalError.mjs","sourceRoot":"","sources":["../../../../src/lib/db/log/logGlobalError.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,+DAA8C;AAQvE,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,GAAiB;IACxD,IAAI,GAAG,CAAC,OAAO,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAM;IAE3D,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,EAAE,CAAC,CAAA;IAC7C,IAAI,GAAG,CAAC,OAAO,KAAK,EAAE;QAAE,cAAc,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAAA;IACtD,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,cAAc,CAAC,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAA;IAE9D,+BAA+B;AAChC,CAAC,CAAA","sourcesContent":["import { LogGlobalError } from '@models/MongoDB/log/LogGlobalError.mjs'\n\n/** Payload accepted by `logGlobalError`. Exported so a consumer re-exporting the helper can name its type. */\nexport interface IGlobalError {\n\tmessage: string\n\tstackArr: Array<string>\n}\n\nexport const logGlobalError = function (log: IGlobalError) {\n\tif (log.message === '' && log.stackArr.length === 0) return\n\n\tconst newGlobalError = new LogGlobalError({})\n\tif (log.message !== '') newGlobalError.m = log.message\n\tif (log.stackArr.length !== 0) newGlobalError.s = log.stackArr\n\n\t// return newGlobalError.save()\n}\n"]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { IVerifyEmailPaths } from "../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { Types } from 'mongoose';
|
|
2
|
-
|
|
3
|
+
import { THandleIfHashBad } from './handleIfHashBad.mjs';
|
|
4
|
+
import { THandleIfMoreThan3DaysPassed } from './handleIfMoreThan3DaysPassed.mjs';
|
|
5
|
+
import { THandleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs';
|
|
6
|
+
/** The projection userData4VerifyEmail selects under the default paths, as the guard chain needs it. */
|
|
3
7
|
export interface IVerifyEmailUser {
|
|
4
8
|
_id: Types.ObjectId;
|
|
5
9
|
account: {
|
|
@@ -13,6 +17,13 @@ export interface IVerifyEmailUser {
|
|
|
13
17
|
disabled?: boolean;
|
|
14
18
|
};
|
|
15
19
|
}
|
|
20
|
+
/** Collaborators the chain needs, all bound to the same model + paths by the caller. */
|
|
21
|
+
export interface IAssertVerifyEmailAllowedDeps {
|
|
22
|
+
paths: IVerifyEmailPaths;
|
|
23
|
+
handleIfHashBad: THandleIfHashBad;
|
|
24
|
+
handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed;
|
|
25
|
+
handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes;
|
|
26
|
+
}
|
|
16
27
|
/**
|
|
17
28
|
* Run every guard that must pass before an email-verification link is honoured, in order.
|
|
18
29
|
*
|
|
@@ -32,5 +43,12 @@ export interface IVerifyEmailUser {
|
|
|
32
43
|
* Enabling the account is deliberately NOT done here. The caller performs it on the
|
|
33
44
|
* returned id, so the irreversible side effect cannot be reordered ahead of a guard —
|
|
34
45
|
* a mutation that did exactly that also survived.
|
|
46
|
+
*
|
|
47
|
+
* The document is read through `paths` rather than by fixed property access, so the same
|
|
48
|
+
* chain serves any account layout. Nothing else about the sequence changes.
|
|
35
49
|
*/
|
|
36
|
-
export declare
|
|
50
|
+
export declare const createAssertVerifyEmailAllowed: (deps: IAssertVerifyEmailAllowedDeps) => (user: unknown, email: string, hash: string) => Promise<Types.ObjectId>;
|
|
51
|
+
/** Signature of the bound chain, for the modules that take it as a dependency. */
|
|
52
|
+
export type TAssertVerifyEmailAllowed = ReturnType<typeof createAssertVerifyEmailAllowed>;
|
|
53
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
54
|
+
export declare const assertVerifyEmailAllowed: TAssertVerifyEmailAllowed;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { handleBadDB } from './handleBadDB.mjs';
|
|
2
3
|
import { handleIfAccountDeleted } from './handleIfAccountDeleted.mjs';
|
|
3
4
|
import { handleIfAccountDisabled } from './handleIfAccountDisabled.mjs';
|
|
@@ -5,6 +6,7 @@ import { handleIfEmailAlreadyValid } from './handleIfEmailAlreadyValid.mjs';
|
|
|
5
6
|
import { handleIfHashBad } from './handleIfHashBad.mjs';
|
|
6
7
|
import { handleIfMoreThan3DaysPassed } from './handleIfMoreThan3DaysPassed.mjs';
|
|
7
8
|
import { handleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs';
|
|
9
|
+
import { readPath } from './pathTools.mjs';
|
|
8
10
|
/**
|
|
9
11
|
* Run every guard that must pass before an email-verification link is honoured, in order.
|
|
10
12
|
*
|
|
@@ -24,20 +26,29 @@ import { handleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs
|
|
|
24
26
|
* Enabling the account is deliberately NOT done here. The caller performs it on the
|
|
25
27
|
* returned id, so the irreversible side effect cannot be reordered ahead of a guard —
|
|
26
28
|
* a mutation that did exactly that also survived.
|
|
29
|
+
*
|
|
30
|
+
* The document is read through `paths` rather than by fixed property access, so the same
|
|
31
|
+
* chain serves any account layout. Nothing else about the sequence changes.
|
|
27
32
|
*/
|
|
28
|
-
export async function assertVerifyEmailAllowed(user, email, hash) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
await handleIfEmailAlreadyValid(email,
|
|
33
|
+
export const createAssertVerifyEmailAllowed = (deps) => async function assertVerifyEmailAllowed(user, email, hash) {
|
|
34
|
+
const { paths } = deps;
|
|
35
|
+
const uId = readPath(user, '_id');
|
|
36
|
+
const requestTimes = readPath(user, paths.requestTimes);
|
|
37
|
+
const dateLastReq = readPath(user, paths.dateLastReq);
|
|
38
|
+
const deleted = readPath(user, paths.deleted);
|
|
39
|
+
const disabled = readPath(user, paths.disabled);
|
|
40
|
+
await handleIfEmailAlreadyValid(email, readPath(user, paths.valid));
|
|
36
41
|
handleBadDB(requestTimes, dateLastReq);
|
|
37
|
-
await handleIfTooMuchRequestsTimes(email, requestTimes);
|
|
42
|
+
await deps.handleIfTooMuchRequestsTimes(email, requestTimes);
|
|
38
43
|
// dbHash is the value STORED for this account — never the one supplied in the URL
|
|
39
|
-
await handleIfHashBad({
|
|
40
|
-
|
|
44
|
+
await deps.handleIfHashBad({
|
|
45
|
+
uId,
|
|
46
|
+
uEmail: email,
|
|
47
|
+
hash,
|
|
48
|
+
requestTimes,
|
|
49
|
+
dbHash: readPath(user, paths.hash)
|
|
50
|
+
});
|
|
51
|
+
await deps.handleIfMoreThan3DaysPassed(email, dateLastReq);
|
|
41
52
|
// The flags are passed raw. userData4VerifyEmail reads .lean(), so Mongoose casting never runs
|
|
42
53
|
// and these are exactly what the driver found — which is only ever a boolean once
|
|
43
54
|
// scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored 'false'
|
|
@@ -45,5 +56,12 @@ export async function assertVerifyEmailAllowed(user, email, hash) {
|
|
|
45
56
|
await handleIfAccountDeleted(email, deleted);
|
|
46
57
|
await handleIfAccountDisabled(email, disabled);
|
|
47
58
|
return uId;
|
|
48
|
-
}
|
|
59
|
+
};
|
|
60
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
61
|
+
export const assertVerifyEmailAllowed = createAssertVerifyEmailAllowed({
|
|
62
|
+
paths: DEFAULT_VERIFY_EMAIL_PATHS,
|
|
63
|
+
handleIfHashBad,
|
|
64
|
+
handleIfMoreThan3DaysPassed,
|
|
65
|
+
handleIfTooMuchRequestsTimes
|
|
66
|
+
});
|
|
49
67
|
//# sourceMappingURL=assertVerifyEmailAllowed.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertVerifyEmailAllowed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/assertVerifyEmailAllowed.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assertVerifyEmailAllowed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/assertVerifyEmailAllowed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAqB,4CAAmC;AAG3F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,eAAe,EAAoB,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,2BAA2B,EAAgC,MAAM,mCAAmC,CAAA;AAC7G,OAAO,EAAE,4BAA4B,EAAiC,MAAM,oCAAoC,CAAA;AAChH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAyB1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,IAAmC,EAAE,EAAE,CACrF,KAAK,UAAU,wBAAwB,CAAC,IAAa,EAAE,KAAa,EAAE,IAAY;IACjF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IACtB,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAmB,CAAA;IACnD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAuB,CAAA;IAC7E,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAqB,CAAA;IACzE,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAwB,CAAA;IACpE,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAwB,CAAA;IAEtE,MAAM,yBAAyB,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAY,CAAC,CAAA;IAC9E,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IACtC,MAAM,IAAI,CAAC,4BAA4B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAC5D,kFAAkF;IAClF,MAAM,IAAI,CAAC,eAAe,CAAC;QAC1B,GAAG;QACH,MAAM,EAAE,KAAK;QACb,IAAI;QACJ,YAAY;QACZ,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAuB;KACxD,CAAC,CAAA;IAEF,MAAM,IAAI,CAAC,2BAA2B,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IAC1D,+FAA+F;IAC/F,kFAAkF;IAClF,gGAAgG;IAChG,4FAA4F;IAC5F,MAAM,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC5C,MAAM,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAE9C,OAAO,GAAG,CAAA;AACX,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAA8B,8BAA8B,CAAC;IACjG,KAAK,EAAE,0BAA0B;IACjC,eAAe;IACf,2BAA2B;IAC3B,4BAA4B;CAC5B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths } from '@lib/access/accessPaths.mjs'\nimport { Types } from 'mongoose'\n\nimport { handleBadDB } from './handleBadDB.mjs'\nimport { handleIfAccountDeleted } from './handleIfAccountDeleted.mjs'\nimport { handleIfAccountDisabled } from './handleIfAccountDisabled.mjs'\nimport { handleIfEmailAlreadyValid } from './handleIfEmailAlreadyValid.mjs'\nimport { handleIfHashBad, THandleIfHashBad } from './handleIfHashBad.mjs'\nimport { handleIfMoreThan3DaysPassed, THandleIfMoreThan3DaysPassed } from './handleIfMoreThan3DaysPassed.mjs'\nimport { handleIfTooMuchRequestsTimes, THandleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs'\nimport { readPath } from './pathTools.mjs'\n\n/** The projection userData4VerifyEmail selects under the default paths, as the guard chain needs it. */\nexport interface IVerifyEmailUser {\n\t_id: Types.ObjectId\n\taccount: {\n\t\temail: {\n\t\t\thash?: string\n\t\t\tvalid: boolean\n\t\t\tdateLastReq?: Date\n\t\t\trequestTimes?: number\n\t\t}\n\t\tdeleted?: boolean\n\t\tdisabled?: boolean\n\t}\n}\n\n/** Collaborators the chain needs, all bound to the same model + paths by the caller. */\nexport interface IAssertVerifyEmailAllowedDeps {\n\tpaths: IVerifyEmailPaths\n\thandleIfHashBad: THandleIfHashBad\n\thandleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed\n\thandleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes\n}\n\n/**\n * Run every guard that must pass before an email-verification link is honoured, in order.\n *\n * Extracted from routerVerifyEmail so the sequence is reachable by tests. Inside the\n * router it was not: the handler's only entry point performs a DB read, which cannot be\n * stubbed under the tsx loader (ESM live bindings), so in the suite it always rejected\n * and the whole try-body was dead code — sitting under a `c8 ignore` besides. Mutation\n * testing confirmed the cost: deleting the disabled-account guard, negating the deleted\n * flag, comparing the URL hash against ITSELF instead of the stored one, hard-coding\n * requestTimes to 0, and dropping the `await` on the hash check ALL left the suite green.\n * Each guard had thorough unit tests of its own; nothing tested that the router called\n * them, with the right values, in the right order.\n *\n * Throws (via the handleIf* guards) when the link must not be honoured. Returns the user\n * id to enable when every guard passes.\n *\n * Enabling the account is deliberately NOT done here. The caller performs it on the\n * returned id, so the irreversible side effect cannot be reordered ahead of a guard —\n * a mutation that did exactly that also survived.\n *\n * The document is read through `paths` rather than by fixed property access, so the same\n * chain serves any account layout. Nothing else about the sequence changes.\n */\nexport const createAssertVerifyEmailAllowed = (deps: IAssertVerifyEmailAllowedDeps) =>\n\tasync function assertVerifyEmailAllowed(user: unknown, email: string, hash: string): Promise<Types.ObjectId> {\n\t\tconst { paths } = deps\n\t\tconst uId = readPath(user, '_id') as Types.ObjectId\n\t\tconst requestTimes = readPath(user, paths.requestTimes) as number | undefined\n\t\tconst dateLastReq = readPath(user, paths.dateLastReq) as Date | undefined\n\t\tconst deleted = readPath(user, paths.deleted) as boolean | undefined\n\t\tconst disabled = readPath(user, paths.disabled) as boolean | undefined\n\n\t\tawait handleIfEmailAlreadyValid(email, readPath(user, paths.valid) as boolean)\n\t\thandleBadDB(requestTimes, dateLastReq)\n\t\tawait deps.handleIfTooMuchRequestsTimes(email, requestTimes)\n\t\t// dbHash is the value STORED for this account — never the one supplied in the URL\n\t\tawait deps.handleIfHashBad({\n\t\t\tuId,\n\t\t\tuEmail: email,\n\t\t\thash,\n\t\t\trequestTimes,\n\t\t\tdbHash: readPath(user, paths.hash) as string | undefined\n\t\t})\n\n\t\tawait deps.handleIfMoreThan3DaysPassed(email, dateLastReq)\n\t\t// The flags are passed raw. userData4VerifyEmail reads .lean(), so Mongoose casting never runs\n\t\t// and these are exactly what the driver found — which is only ever a boolean once\n\t\t// scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored 'false'\n\t\t// is a truthy string and blocks the account; the fix is the migration, not a coercion here.\n\t\tawait handleIfAccountDeleted(email, deleted)\n\t\tawait handleIfAccountDisabled(email, disabled)\n\n\t\treturn uId\n\t}\n\n/** Signature of the bound chain, for the modules that take it as a dependency. */\nexport type TAssertVerifyEmailAllowed = ReturnType<typeof createAssertVerifyEmailAllowed>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const assertVerifyEmailAllowed: TAssertVerifyEmailAllowed = createAssertVerifyEmailAllowed({\n\tpaths: DEFAULT_VERIFY_EMAIL_PATHS,\n\thandleIfHashBad,\n\thandleIfMoreThan3DaysPassed,\n\thandleIfTooMuchRequestsTimes\n})\n"]}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import mongoose from 'mongoose';
|
|
2
|
-
export
|
|
3
|
+
export declare const createConfirmNewEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (_id: mongoose.Types.ObjectId, email: string) => Promise<mongoose.UpdateWriteOpResult>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TConfirmNewEmail = ReturnType<typeof createConfirmNewEmail>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
declare const _default: (_id: mongoose.Types.ObjectId, email: string) => Promise<mongoose.UpdateWriteOpResult>;
|
|
8
|
+
export default _default;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { buildUnset } from "../pathTools.mjs";
|
|
4
|
+
export const createConfirmNewEmail = (model, paths) => async function confirmNewEmail(_id, email) {
|
|
5
|
+
return await model
|
|
6
|
+
.updateOne({ _id }, {
|
|
7
|
+
$set: { [paths.email]: email },
|
|
8
|
+
$unset: buildUnset(paths.emailChangeClear)
|
|
9
|
+
})
|
|
10
|
+
.exec();
|
|
11
|
+
};
|
|
12
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
13
|
+
export default createConfirmNewEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
13
14
|
//# sourceMappingURL=confirmNewEmail.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmNewEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/confirmNewEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;
|
|
1
|
+
{"version":3,"file":"confirmNewEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/confirmNewEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,UAAU,EAAE,yBAAyC;AAG9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACtF,KAAK,UAAU,eAAe,CAAC,GAA4B,EAAE,KAAa;IACzE,OAAO,MAAM,KAAK;SAChB,SAAS,CACT,EAAE,GAAG,EAAE,EACP;QACC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE;QAC9B,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC;KAC1C,CACD;SACA,IAAI,EAAE,CAAA;AACT,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,qBAAqB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { buildUnset } from '@private/lib/access/pathTools.mjs'\nimport mongoose from 'mongoose'\n\nexport const createConfirmNewEmail = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function confirmNewEmail(_id: mongoose.Types.ObjectId, email: string) {\n\t\treturn await model\n\t\t\t.updateOne(\n\t\t\t\t{ _id },\n\t\t\t\t{\n\t\t\t\t\t$set: { [paths.email]: email },\n\t\t\t\t\t$unset: buildUnset(paths.emailChangeClear)\n\t\t\t\t}\n\t\t\t)\n\t\t\t.exec()\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TConfirmNewEmail = ReturnType<typeof createConfirmNewEmail>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport default createConfirmNewEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
export declare const createDeleteUserByEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (email: string) => Promise<void>;
|
|
3
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
4
|
+
export type TDeleteUserByEmail = ReturnType<typeof createDeleteUserByEmail>;
|
|
5
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
6
|
+
declare const _default: (email: string) => Promise<void>;
|
|
7
|
+
export default _default;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// @todo report on Sentry
|
|
2
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
2
3
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
3
|
-
export
|
|
4
|
-
await
|
|
4
|
+
export const createDeleteUserByEmail = (model, paths) => async function deleteUserByEmail(email) {
|
|
5
|
+
await model.deleteOne({ [paths.email]: email });
|
|
5
6
|
/* if (ret.deletedCount === 0) {
|
|
6
7
|
} */
|
|
7
|
-
}
|
|
8
|
+
};
|
|
9
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
10
|
+
export default createDeleteUserByEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
8
11
|
//# sourceMappingURL=deleteUserByEmail.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteUserByEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/deleteUserByEmail.mts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAEvD,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"deleteUserByEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/deleteUserByEmail.mts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAEvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACxF,KAAK,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IAE/C;MACK;AACN,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,uBAAuB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["// @todo report on Sentry\nimport { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\n\nexport const createDeleteUserByEmail = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function deleteUserByEmail(email: string) {\n\t\tawait model.deleteOne({ [paths.email]: email })\n\n\t\t/* if (ret.deletedCount === 0) {\n\t } */\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TDeleteUserByEmail = ReturnType<typeof createDeleteUserByEmail>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport default createDeleteUserByEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import mongoose from 'mongoose';
|
|
2
|
-
export declare
|
|
3
|
+
export declare const createEnableEmailAccess: (model: TAccessModel, paths: IVerifyEmailPaths) => (_id: mongoose.Types.ObjectId, email: string) => Promise<void>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TEnableEmailAccess = ReturnType<typeof createEnableEmailAccess>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
export declare const enableEmailAccess: TEnableEmailAccess;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { SocketLabsLib } from "../../../../email/SocketLabsLib.mjs";
|
|
2
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
2
3
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
$
|
|
7
|
-
|
|
8
|
-
'account.email.dateLastReq': '',
|
|
9
|
-
'account.email.requestTimes': ''
|
|
10
|
-
}
|
|
4
|
+
import { buildUnset } from "../pathTools.mjs";
|
|
5
|
+
export const createEnableEmailAccess = (model, paths) => async function enableEmailAccess(_id, email) {
|
|
6
|
+
await model.updateOne({ _id }, {
|
|
7
|
+
$set: { [paths.valid]: true },
|
|
8
|
+
$unset: buildUnset(paths.verifyClear)
|
|
11
9
|
}, {
|
|
12
10
|
runValidators: true
|
|
13
11
|
});
|
|
14
12
|
const SocketLabsObj = new SocketLabsLib();
|
|
15
13
|
await SocketLabsObj.sendWelcome(email);
|
|
16
|
-
}
|
|
14
|
+
};
|
|
15
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
16
|
+
export const enableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
17
17
|
//# sourceMappingURL=enableEmailAccess.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableEmailAccess.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/enableEmailAccess.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4CAAgC;AACxD,OAAO,EAAE,QAAQ,EAAE,wDAAoC;
|
|
1
|
+
{"version":3,"file":"enableEmailAccess.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/enableEmailAccess.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4CAAgC;AACxD,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,UAAU,EAAE,yBAAyC;AAG9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACxF,KAAK,UAAU,iBAAiB,CAAC,GAA4B,EAAE,KAAa;IAC3E,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,EACP;QACC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE;QAC7B,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC;KACrC,EACD;QACC,aAAa,EAAE,IAAI;KACnB,CACD,CAAA;IAED,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;IACzC,MAAM,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AACvC,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAuB,uBAAuB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { buildUnset } from '@private/lib/access/pathTools.mjs'\nimport mongoose from 'mongoose'\n\nexport const createEnableEmailAccess = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function enableEmailAccess(_id: mongoose.Types.ObjectId, email: string) {\n\t\tawait model.updateOne(\n\t\t\t{ _id },\n\t\t\t{\n\t\t\t\t$set: { [paths.valid]: true },\n\t\t\t\t$unset: buildUnset(paths.verifyClear)\n\t\t\t},\n\t\t\t{\n\t\t\t\trunValidators: true\n\t\t\t}\n\t\t)\n\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.sendWelcome(email)\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TEnableEmailAccess = ReturnType<typeof createEnableEmailAccess>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const enableEmailAccess: TEnableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IResetPwdPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
import { ClientSession, Types } from 'mongoose';
|
|
3
|
+
/** What the reset flow needs about an account, flattened out of whatever layout `paths` describes. */
|
|
4
|
+
export interface IResetPwdRecord {
|
|
5
|
+
_id: Types.ObjectId;
|
|
4
6
|
resetDateReq: Date | undefined;
|
|
5
7
|
resetHash: string | null;
|
|
6
8
|
name: string;
|
|
7
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export declare const createGetResetPwd: (model: TAccessModel, paths: IResetPwdPaths) => (session: ClientSession, email: string) => Promise<IResetPwdRecord | null>;
|
|
11
|
+
/** Signature of the bound reader, for the modules that take it as a dependency. */
|
|
12
|
+
export type TGetResetPwd = ReturnType<typeof createGetResetPwd>;
|
|
13
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
14
|
+
export declare const getResetPwd: TGetResetPwd;
|
|
@@ -1,22 +1,39 @@
|
|
|
1
|
+
import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
|
-
|
|
3
|
+
import { buildProjection, readPath } from "../pathTools.mjs";
|
|
4
|
+
export const createGetResetPwd = (model, paths) => async function getResetPwd(session, email) {
|
|
3
5
|
let ret = null;
|
|
4
|
-
const queryRet = await
|
|
5
|
-
.
|
|
6
|
+
const queryRet = await model
|
|
7
|
+
.findOne({ [paths.email]: email })
|
|
8
|
+
.select(buildProjection([paths.name, paths.resetDateReq, paths.resetHash, paths.deleted, paths.disabled]))
|
|
6
9
|
.session(session)
|
|
7
10
|
.lean();
|
|
8
11
|
// if a reset request is found
|
|
9
12
|
if (queryRet !== null) {
|
|
10
|
-
|
|
13
|
+
// A tombstoned or locked-out account is not a reset target: without this, resetPwd mailed a
|
|
14
|
+
// live link to a deleted address and updatePassword overwrote the bcrypt hash of a disabled
|
|
15
|
+
// one, so re-enabling the account handed it back with an attacker-chosen password. `null` is
|
|
16
|
+
// the same answer an unknown address gets — resetPwd returns true and sends nothing,
|
|
17
|
+
// updatePassword answers the same 403 — so no new enumeration oracle is opened.
|
|
18
|
+
//
|
|
19
|
+
// The flags are read raw, exactly as assertVerifyEmailAllowed reads them. This is a .lean()
|
|
20
|
+
// read, so Mongoose casting never runs and these are what the driver found: a boolean once
|
|
21
|
+
// scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored
|
|
22
|
+
// 'false' is a truthy string and blocks the reset; the fix is the migration, not a coercion
|
|
23
|
+
// here.
|
|
24
|
+
if (readPath(queryRet, paths.deleted) || readPath(queryRet, paths.disabled)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const resetDateReq = readPath(queryRet, paths.resetDateReq);
|
|
11
28
|
let resetHash = null;
|
|
12
29
|
if (typeof resetDateReq !== 'undefined') {
|
|
13
|
-
const storedHash = queryRet.
|
|
14
|
-
// Never stringify, and never fall back to
|
|
15
|
-
// literal string "undefined", which passed updatePassword's null check and then
|
|
16
|
-
// caller sending that same literal as the hash argument — a reset with no secret
|
|
17
|
-
// The two fields must also stay disjoint: reading the verification slot here is
|
|
18
|
-
// hash issued by one flow authenticate the other. Anything but a stored string
|
|
19
|
-
// which updatePassword rejects with the same 403 it gives an unknown address.
|
|
30
|
+
const storedHash = readPath(queryRet, paths.resetHash);
|
|
31
|
+
// Never stringify, and never fall back to the email-verification hash slot. '' + undefined
|
|
32
|
+
// yields the literal string "undefined", which passed updatePassword's null check and then
|
|
33
|
+
// matched a caller sending that same literal as the hash argument — a reset with no secret
|
|
34
|
+
// at all. The two fields must also stay disjoint: reading the verification slot here is
|
|
35
|
+
// what let a hash issued by one flow authenticate the other. Anything but a stored string
|
|
36
|
+
// => null, which updatePassword rejects with the same 403 it gives an unknown address.
|
|
20
37
|
if (typeof storedHash === 'string') {
|
|
21
38
|
resetHash = storedHash;
|
|
22
39
|
}
|
|
@@ -25,9 +42,11 @@ export const getResetPwd = async function (session, email) {
|
|
|
25
42
|
_id: queryRet._id,
|
|
26
43
|
resetDateReq,
|
|
27
44
|
resetHash,
|
|
28
|
-
name: queryRet.
|
|
45
|
+
name: readPath(queryRet, paths.name) || ''
|
|
29
46
|
};
|
|
30
47
|
}
|
|
31
48
|
return ret;
|
|
32
49
|
};
|
|
50
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
51
|
+
export const getResetPwd = createGetResetPwd(UserBase, DEFAULT_RESET_PWD_PATHS);
|
|
33
52
|
//# sourceMappingURL=getResetPwd.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getResetPwd.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/getResetPwd.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;
|
|
1
|
+
{"version":3,"file":"getResetPwd.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/getResetPwd.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AACnG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,yBAAyC;AAW7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CAC/E,KAAK,UAAU,WAAW,CAAC,OAAsB,EAAE,KAAa;IAC/D,IAAI,GAAG,GAA2B,IAAI,CAAA;IAEtC,MAAM,QAAQ,GAAG,MAAM,KAAK;SAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;SACjC,MAAM,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;SACzG,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IAER,8BAA8B;IAC9B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,4FAA4F;QAC5F,4FAA4F;QAC5F,6FAA6F;QAC7F,qFAAqF;QACrF,gFAAgF;QAChF,EAAE;QACF,4FAA4F;QAC5F,2FAA2F;QAC3F,wFAAwF;QACxF,4FAA4F;QAC5F,QAAQ;QACR,IAAI,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7E,OAAO,IAAI,CAAA;QACZ,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAqB,CAAA;QAC/E,IAAI,SAAS,GAAkB,IAAI,CAAA;QAEnC,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;YAEtD,2FAA2F;YAC3F,2FAA2F;YAC3F,2FAA2F;YAC3F,wFAAwF;YACxF,0FAA0F;YAC1F,uFAAuF;YACvF,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;gBACpC,SAAS,GAAG,UAAU,CAAA;YACvB,CAAC;QACF,CAAC;QAED,GAAG,GAAG;YACL,GAAG,EAAE,QAAQ,CAAC,GAAqB;YACnC,YAAY;YACZ,SAAS;YACT,IAAI,EAAG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAwB,IAAI,EAAE;SAClE,CAAA;IACF,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,WAAW,GAAiB,iBAAiB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { buildProjection, readPath } from '@private/lib/access/pathTools.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\n/** What the reset flow needs about an account, flattened out of whatever layout `paths` describes. */\nexport interface IResetPwdRecord {\n\t_id: Types.ObjectId\n\tresetDateReq: Date | undefined\n\tresetHash: string | null\n\tname: string\n}\n\nexport const createGetResetPwd = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function getResetPwd(session: ClientSession, email: string): Promise<IResetPwdRecord | null> {\n\t\tlet ret: IResetPwdRecord | null = null\n\n\t\tconst queryRet = await model\n\t\t\t.findOne({ [paths.email]: email })\n\t\t\t.select(buildProjection([paths.name, paths.resetDateReq, paths.resetHash, paths.deleted, paths.disabled]))\n\t\t\t.session(session)\n\t\t\t.lean()\n\n\t\t// if a reset request is found\n\t\tif (queryRet !== null) {\n\t\t\t// A tombstoned or locked-out account is not a reset target: without this, resetPwd mailed a\n\t\t\t// live link to a deleted address and updatePassword overwrote the bcrypt hash of a disabled\n\t\t\t// one, so re-enabling the account handed it back with an attacker-chosen password. `null` is\n\t\t\t// the same answer an unknown address gets — resetPwd returns true and sends nothing,\n\t\t\t// updatePassword answers the same 403 — so no new enumeration oracle is opened.\n\t\t\t//\n\t\t\t// The flags are read raw, exactly as assertVerifyEmailAllowed reads them. This is a .lean()\n\t\t\t// read, so Mongoose casting never runs and these are what the driver found: a boolean once\n\t\t\t// scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored\n\t\t\t// 'false' is a truthy string and blocks the reset; the fix is the migration, not a coercion\n\t\t\t// here.\n\t\t\tif (readPath(queryRet, paths.deleted) || readPath(queryRet, paths.disabled)) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst resetDateReq = readPath(queryRet, paths.resetDateReq) as Date | undefined\n\t\t\tlet resetHash: string | null = null\n\n\t\t\tif (typeof resetDateReq !== 'undefined') {\n\t\t\t\tconst storedHash = readPath(queryRet, paths.resetHash)\n\n\t\t\t\t// Never stringify, and never fall back to the email-verification hash slot. '' + undefined\n\t\t\t\t// yields the literal string \"undefined\", which passed updatePassword's null check and then\n\t\t\t\t// matched a caller sending that same literal as the hash argument — a reset with no secret\n\t\t\t\t// at all. The two fields must also stay disjoint: reading the verification slot here is\n\t\t\t\t// what let a hash issued by one flow authenticate the other. Anything but a stored string\n\t\t\t\t// => null, which updatePassword rejects with the same 403 it gives an unknown address.\n\t\t\t\tif (typeof storedHash === 'string') {\n\t\t\t\t\tresetHash = storedHash\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tret = {\n\t\t\t\t_id: queryRet._id as Types.ObjectId,\n\t\t\t\tresetDateReq,\n\t\t\t\tresetHash,\n\t\t\t\tname: (readPath(queryRet, paths.name) as string | undefined) || ''\n\t\t\t}\n\t\t}\n\t\treturn ret\n\t}\n\n/** Signature of the bound reader, for the modules that take it as a dependency. */\nexport type TGetResetPwd = ReturnType<typeof createGetResetPwd>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const getResetPwd: TGetResetPwd = createGetResetPwd(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import mongoose from 'mongoose';
|
|
2
|
-
export declare
|
|
3
|
+
export declare const createIncReqTimes: (model: TAccessModel, paths: IVerifyEmailPaths) => (_id: mongoose.Types.ObjectId) => Promise<mongoose.UpdateWriteOpResult>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TIncReqTimes = ReturnType<typeof createIncReqTimes>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
export declare const incReqTimes: TIncReqTimes;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
|
-
export async function incReqTimes(_id) {
|
|
3
|
-
return
|
|
4
|
-
}
|
|
3
|
+
export const createIncReqTimes = (model, paths) => async function incReqTimes(_id) {
|
|
4
|
+
return model.updateOne({ _id }, { $inc: { [paths.requestTimes]: 1 } }, { runValidators: true });
|
|
5
|
+
};
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
export const incReqTimes = createIncReqTimes(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
5
8
|
//# sourceMappingURL=incReqTimes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incReqTimes.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/incReqTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAA4B;
|
|
1
|
+
{"version":3,"file":"incReqTimes.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/incReqTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CAClF,KAAK,UAAU,WAAW,CAAC,GAA4B;IACtD,OAAO,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAChG,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,WAAW,GAAiB,iBAAiB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport mongoose from 'mongoose'\n\nexport const createIncReqTimes = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function incReqTimes(_id: mongoose.Types.ObjectId) {\n\t\treturn model.updateOne({ _id }, { $inc: { [paths.requestTimes]: 1 } }, { runValidators: true })\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TIncReqTimes = ReturnType<typeof createIncReqTimes>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const incReqTimes: TIncReqTimes = createIncReqTimes(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { IResetPwdPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { ClientSession } from 'mongoose';
|
|
2
|
-
export
|
|
3
|
+
export declare const createRemoveResetReq: (model: TAccessModel, paths: IResetPwdPaths) => (session: ClientSession, email: string) => Promise<import("mongoose").UpdateWriteOpResult>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TRemoveResetReq = ReturnType<typeof createRemoveResetReq>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
declare const _default: (session: ClientSession, email: string) => Promise<import("mongoose").UpdateWriteOpResult>;
|
|
8
|
+
export default _default;
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
|
-
|
|
3
|
+
import { buildUnset } from "../pathTools.mjs";
|
|
4
|
+
export const createRemoveResetReq = (model, paths) => async function removeResetReq(session, email) {
|
|
3
5
|
// No { upsert: true }. An upsert on a clearing operation is backwards: when the email matched no
|
|
4
|
-
// document MongoDB did not no-op, it inserted one keyed by login
|
|
5
|
-
// validators, so that row bypassed every required field in the schema (
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
6
|
+
// document MongoDB did not no-op, it inserted one keyed by the login-email path — and updateOne
|
|
7
|
+
// skips validators, so that row bypassed every required field in the schema (password,
|
|
8
|
+
// email.valid, registrationDate). A no-op is the only correct answer to "clear the reset state of
|
|
9
|
+
// a user that does not exist".
|
|
10
|
+
//
|
|
11
|
+
// The unset list comes from paths.resetClear, NOT from the fields saveResetReq writes. A layout
|
|
12
|
+
// holding the request in one required subdocument can only be cleared by unsetting the container;
|
|
13
|
+
// unsetting its members leaves a document that fails validation and the write is rejected.
|
|
14
|
+
return model
|
|
15
|
+
.updateOne({ [paths.email]: email }, { $unset: buildUnset(paths.resetClear) })
|
|
9
16
|
.session(session)
|
|
10
17
|
.exec();
|
|
11
|
-
}
|
|
18
|
+
};
|
|
19
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
20
|
+
export default createRemoveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS);
|
|
12
21
|
//# sourceMappingURL=removeResetReq.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/removeResetReq.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;
|
|
1
|
+
{"version":3,"file":"removeResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/removeResetReq.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AACnG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,UAAU,EAAE,yBAAyC;AAG9D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CAClF,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,KAAa;IAClE,iGAAiG;IACjG,gGAAgG;IAChG,uFAAuF;IACvF,kGAAkG;IAClG,+BAA+B;IAC/B,EAAE;IACF,gGAAgG;IAChG,kGAAkG;IAClG,2FAA2F;IAC3F,OAAO,KAAK;SACV,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;SAC7E,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;AACT,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,oBAAoB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { buildUnset } from '@private/lib/access/pathTools.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport const createRemoveResetReq = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function removeResetReq(session: ClientSession, email: string) {\n\t\t// No { upsert: true }. An upsert on a clearing operation is backwards: when the email matched no\n\t\t// document MongoDB did not no-op, it inserted one keyed by the login-email path — and updateOne\n\t\t// skips validators, so that row bypassed every required field in the schema (password,\n\t\t// email.valid, registrationDate). A no-op is the only correct answer to \"clear the reset state of\n\t\t// a user that does not exist\".\n\t\t//\n\t\t// The unset list comes from paths.resetClear, NOT from the fields saveResetReq writes. A layout\n\t\t// holding the request in one required subdocument can only be cleared by unsetting the container;\n\t\t// unsetting its members leaves a document that fails validation and the write is rejected.\n\t\treturn model\n\t\t\t.updateOne({ [paths.email]: email }, { $unset: buildUnset(paths.resetClear) })\n\t\t\t.session(session)\n\t\t\t.exec()\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TRemoveResetReq = ReturnType<typeof createRemoveResetReq>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport default createRemoveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { IResetPwdPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { ClientSession, Types } from 'mongoose';
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const createSaveResetReq: (model: TAccessModel, paths: IResetPwdPaths) => (session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) => Promise<void>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TSaveResetReq = ReturnType<typeof createSaveResetReq>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
export declare const saveResetReq: TSaveResetReq;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { throwMongoDBErrors } from "../../../../lib/MongoDB/throwMongoErrors.mjs";
|
|
2
3
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
3
|
-
export const
|
|
4
|
+
export const createSaveResetReq = (model, paths) => async function saveResetReq(session, _id, now, hash) {
|
|
4
5
|
// console.debug('imposto reset in coll Utenti')
|
|
5
6
|
try {
|
|
6
|
-
await
|
|
7
|
+
await model.updateOne({ _id }, {
|
|
7
8
|
$set: {
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
// invalidated any pending activation or email-change link, and left a live
|
|
11
|
-
// token in the field those flows compare against.
|
|
12
|
-
|
|
9
|
+
[paths.resetDateReq]: now,
|
|
10
|
+
// the reset slot, never the email-verification one: writing the verification slot
|
|
11
|
+
// here invalidated any pending activation or email-change link, and left a live
|
|
12
|
+
// reset token in the field those flows compare against.
|
|
13
|
+
[paths.resetHash]: hash
|
|
13
14
|
}
|
|
14
15
|
}, { session, runValidators: true });
|
|
15
16
|
}
|
|
@@ -17,4 +18,6 @@ export const saveResetReq = async function (session, _id, now, hash) {
|
|
|
17
18
|
throw throwMongoDBErrors(e);
|
|
18
19
|
}
|
|
19
20
|
};
|
|
21
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
22
|
+
export const saveResetReq = createSaveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS);
|
|
20
23
|
//# sourceMappingURL=saveResetReq.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"saveResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/saveResetReq.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"saveResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/saveResetReq.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AAEnG,OAAO,EAAE,kBAAkB,EAAE,qDAAyC;AACtE,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CAChF,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,GAAmB,EAAE,GAAS,EAAE,IAAY;IAC/F,gDAAgD;IAChD,IAAI,CAAC;QACJ,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,EACP;YACC,IAAI,EAAE;gBACL,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG;gBACzB,kFAAkF;gBAClF,gFAAgF;gBAChF,wDAAwD;gBACxD,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI;aACvB;SACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,kBAAkB,CAAC,CAAkB,CAAC,CAAA;IAC7C,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAkB,kBAAkB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { IMongoDBError } from '@lib/MongoDB/IMongoDBError.mjs'\nimport { throwMongoDBErrors } from '@lib/MongoDB/throwMongoErrors.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport const createSaveResetReq = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function saveResetReq(session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) {\n\t\t// console.debug('imposto reset in coll Utenti')\n\t\ttry {\n\t\t\tawait model.updateOne(\n\t\t\t\t{ _id },\n\t\t\t\t{\n\t\t\t\t\t$set: {\n\t\t\t\t\t\t[paths.resetDateReq]: now,\n\t\t\t\t\t\t// the reset slot, never the email-verification one: writing the verification slot\n\t\t\t\t\t\t// here invalidated any pending activation or email-change link, and left a live\n\t\t\t\t\t\t// reset token in the field those flows compare against.\n\t\t\t\t\t\t[paths.resetHash]: hash\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ session, runValidators: true }\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tthrow throwMongoDBErrors(e as IMongoDBError)\n\t\t}\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TSaveResetReq = ReturnType<typeof createSaveResetReq>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const saveResetReq: TSaveResetReq = createSaveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { ClientSession, Types } from 'mongoose';
|
|
2
|
-
export declare
|
|
3
|
+
export declare const createSetEmailHash: (model: TAccessModel, paths: IVerifyEmailPaths) => (session: ClientSession, userId: Types.ObjectId) => Promise<string>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TSetEmailHash = ReturnType<typeof createSetEmailHash>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
export declare const setEmailHash: TSetEmailHash;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { emailHash } from "../../../../lib/emailHash.mjs";
|
|
2
3
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
3
|
-
export async function setEmailHash(session, userId) {
|
|
4
|
+
export const createSetEmailHash = (model, paths) => async function setEmailHash(session, userId) {
|
|
4
5
|
const hash = emailHash();
|
|
5
6
|
//calculate password hash
|
|
6
7
|
const dtNow = new Date();
|
|
7
|
-
await
|
|
8
|
+
await model.updateOne({ _id: userId }, {
|
|
8
9
|
$set: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
[paths.hash]: hash,
|
|
11
|
+
[paths.requestTimes]: 1, // ok
|
|
12
|
+
[paths.dateLastReq]: dtNow
|
|
12
13
|
}
|
|
13
14
|
}, { session, runValidators: true });
|
|
14
15
|
return hash; // else it goes into exception @fixme check
|
|
15
|
-
}
|
|
16
|
+
};
|
|
17
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
18
|
+
export const setEmailHash = createSetEmailHash(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
16
19
|
//# sourceMappingURL=setEmailHash.mjs.map
|