@axiumine/koa-utils 5.1.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +26 -0
  2. package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +19 -1
  3. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +31 -15
  4. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
  5. package/dist/graphQL/schema/mutations/resetPwd.d.mts +19 -2
  6. package/dist/graphQL/schema/mutations/resetPwd.mjs +60 -35
  7. package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
  8. package/dist/graphQL/schema/mutations/updatePassword.d.mts +21 -1
  9. package/dist/graphQL/schema/mutations/updatePassword.mjs +63 -11
  10. package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
  11. package/dist/koa/router/verifyEmail.d.mts +22 -1
  12. package/dist/koa/router/verifyEmail.mjs +18 -9
  13. package/dist/koa/router/verifyEmail.mjs.map +1 -1
  14. package/dist/lib/access/accessPaths.d.mts +92 -0
  15. package/dist/lib/access/accessPaths.mjs +46 -0
  16. package/dist/lib/access/accessPaths.mjs.map +1 -0
  17. package/dist/lib/access/createResetPwdFlow.d.mts +33 -0
  18. package/dist/lib/access/createResetPwdFlow.mjs +42 -0
  19. package/dist/lib/access/createResetPwdFlow.mjs.map +1 -0
  20. package/dist/lib/access/createVerifyEmailFlow.d.mts +48 -0
  21. package/dist/lib/access/createVerifyEmailFlow.mjs +68 -0
  22. package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -0
  23. package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +20 -2
  24. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +30 -12
  25. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
  26. package/dist/private/lib/access/db/confirmNewEmail.d.mts +7 -1
  27. package/dist/private/lib/access/db/confirmNewEmail.mjs +12 -11
  28. package/dist/private/lib/access/db/confirmNewEmail.mjs.map +1 -1
  29. package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -1
  30. package/dist/private/lib/access/db/deleteUserByEmail.mjs +6 -3
  31. package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
  32. package/dist/private/lib/access/db/enableEmailAccess.d.mts +6 -1
  33. package/dist/private/lib/access/db/enableEmailAccess.mjs +9 -9
  34. package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
  35. package/dist/private/lib/access/db/getResetPwd.d.mts +11 -4
  36. package/dist/private/lib/access/db/getResetPwd.mjs +17 -12
  37. package/dist/private/lib/access/db/getResetPwd.mjs.map +1 -1
  38. package/dist/private/lib/access/db/incReqTimes.d.mts +6 -1
  39. package/dist/private/lib/access/db/incReqTimes.mjs +6 -3
  40. package/dist/private/lib/access/db/incReqTimes.mjs.map +1 -1
  41. package/dist/private/lib/access/db/removeResetReq.d.mts +7 -1
  42. package/dist/private/lib/access/db/removeResetReq.mjs +16 -7
  43. package/dist/private/lib/access/db/removeResetReq.mjs.map +1 -1
  44. package/dist/private/lib/access/db/saveResetReq.d.mts +6 -1
  45. package/dist/private/lib/access/db/saveResetReq.mjs +10 -7
  46. package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
  47. package/dist/private/lib/access/db/setEmailHash.d.mts +6 -1
  48. package/dist/private/lib/access/db/setEmailHash.mjs +9 -6
  49. package/dist/private/lib/access/db/setEmailHash.mjs.map +1 -1
  50. package/dist/private/lib/access/db/updatePasswordDb.d.mts +7 -1
  51. package/dist/private/lib/access/db/updatePasswordDb.mjs +6 -3
  52. package/dist/private/lib/access/db/updatePasswordDb.mjs.map +1 -1
  53. package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +6 -3
  54. package/dist/private/lib/access/db/userData4VerifyEmail.mjs +12 -5
  55. package/dist/private/lib/access/db/userData4VerifyEmail.mjs.map +1 -1
  56. package/dist/private/lib/access/handleIfHashBad.d.mts +10 -3
  57. package/dist/private/lib/access/handleIfHashBad.mjs +9 -5
  58. package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
  59. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +12 -1
  60. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +11 -3
  61. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
  62. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +12 -1
  63. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +11 -3
  64. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
  65. package/dist/private/lib/access/pathTools.d.mts +25 -0
  66. package/dist/private/lib/access/pathTools.mjs +43 -0
  67. package/dist/private/lib/access/pathTools.mjs.map +1 -0
  68. package/package.json +13 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createVerifyEmailFlow.mjs","sourceRoot":"","sources":["../../../src/lib/access/createVerifyEmailFlow.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAA6B,8DAAwD;AAC5H,OAAO,EAAE,qBAAqB,EAAoB,wDAAkD;AACpG,OAAO,EAAE,uBAAuB,EAAsB,0DAAoD;AAC1G,OAAO,EAAE,uBAAuB,EAAsB,0DAAoD;AAC1G,OAAO,EAAE,iBAAiB,EAAgB,oDAA8C;AACxF,OAAO,EAAE,kBAAkB,EAAiB,qDAA+C;AAC3F,OAAO,EAAE,0BAA0B,EAAyB,6DAAuD;AACnH,OAAO,EAAE,qBAAqB,EAAE,qDAA+C;AAC/E,OAAO,EAAE,iCAAiC,EAAE,iEAA2D;AACvG,OAAO,EAAE,kCAAkC,EAAE,kEAA4D;AAEzG,OAAO,EACN,mCAAmC,EAEnC,MAAM,0DAA0D,CAAA;AACjE,OAAO,EAAE,uBAAuB,EAAsB,MAAM,kCAAkC,CAAA;AAC9F,OAAO,EAAqB,uBAAuB,EAAgB,MAAM,mBAAmB,CAAA;AAqB5F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAA8B,EAAoB,EAAE;IACvG,MAAM,QAAQ,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;IAE/C,MAAM,oBAAoB,GAAG,0BAA0B,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACxE,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAClE,MAAM,eAAe,GAAG,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC9D,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAClE,MAAM,WAAW,GAAG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAEtD,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;QAC/D,KAAK,EAAE,QAAQ;QACf,eAAe,EAAE,qBAAqB,CAAC,WAAW,CAAC;QACnD,2BAA2B,EAAE,iCAAiC,CAAC,iBAAiB,CAAC;QACjF,4BAA4B,EAAE,kCAAkC,CAAC,iBAAiB,CAAC;KACnF,CAAC,CAAA;IAEF,OAAO;QACN,oBAAoB;QACpB,YAAY,EAAE,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC;QACjD,iBAAiB;QACjB,eAAe;QACf,iBAAiB;QACjB,WAAW;QACX,wBAAwB;QACxB,qBAAqB,EAAE,mCAAmC,CAAC;YAC1D,KAAK;YACL,KAAK,EAAE,QAAQ;YACf,eAAe;YACf,WAAW;SACX,CAAC;QACF,iBAAiB,EAAE,uBAAuB,CAAC;YAC1C,oBAAoB;YACpB,wBAAwB;YACxB,iBAAiB;SACjB,CAAC;KACF,CAAA;AACF,CAAC,CAAA","sourcesContent":["import { createAssertVerifyEmailAllowed, TAssertVerifyEmailAllowed } from '@private/lib/access/assertVerifyEmailAllowed.mjs'\nimport { createConfirmNewEmail, TConfirmNewEmail } from '@private/lib/access/db/confirmNewEmail.mjs'\nimport { createDeleteUserByEmail, TDeleteUserByEmail } from '@private/lib/access/db/deleteUserByEmail.mjs'\nimport { createEnableEmailAccess, TEnableEmailAccess } from '@private/lib/access/db/enableEmailAccess.mjs'\nimport { createIncReqTimes, TIncReqTimes } from '@private/lib/access/db/incReqTimes.mjs'\nimport { createSetEmailHash, TSetEmailHash } from '@private/lib/access/db/setEmailHash.mjs'\nimport { createUserData4VerifyEmail, TUserData4VerifyEmail } from '@private/lib/access/db/userData4VerifyEmail.mjs'\nimport { createHandleIfHashBad } from '@private/lib/access/handleIfHashBad.mjs'\nimport { createHandleIfMoreThan3DaysPassed } from '@private/lib/access/handleIfMoreThan3DaysPassed.mjs'\nimport { createHandleIfTooMuchRequestsTimes } from '@private/lib/access/handleIfTooMuchRequestsTimes.mjs'\n\nimport {\n\tcreateEmailChangeHashVerifyMutation,\n\tTEmailChangeHashVerifyMutation\n} from '../../graphQL/schema/mutations/emailChangeHashVerify.mjs'\nimport { createVerifyEmailRouter, TVerifyEmailRouter } from '../../koa/router/verifyEmail.mjs'\nimport { IVerifyEmailPaths, resolveVerifyEmailPaths, TAccessModel } from './accessPaths.mjs'\n\n/** What the factory needs: the account model, plus any path that differs from the default layout. */\nexport interface ICreateVerifyEmailFlowArgs {\n\tmodel: TAccessModel\n\tpaths?: Partial<IVerifyEmailPaths>\n}\n\n/** Everything the verify-email chain exposes, bound to the model and paths passed in. */\nexport interface IVerifyEmailFlow {\n\tuserData4VerifyEmail: TUserData4VerifyEmail\n\tsetEmailHash: TSetEmailHash\n\tenableEmailAccess: TEnableEmailAccess\n\tconfirmNewEmail: TConfirmNewEmail\n\tdeleteUserByEmail: TDeleteUserByEmail\n\tincReqTimes: TIncReqTimes\n\tassertVerifyEmailAllowed: TAssertVerifyEmailAllowed\n\temailChangeHashVerify: TEmailChangeHashVerifyMutation\n\trouterVerifyEmail: TVerifyEmailRouter\n}\n\n/**\n * Build the whole email-verification chain against any mongoose model.\n *\n * The package's own exports (`userData4VerifyEmail`, `setEmailHash`, `enableEmailAccess`,\n * `confirmNewEmail`, `emailChangeHashVerify`, `routerVerifyEmail`) are this factory applied to\n * `UserBase` with `DEFAULT_VERIFY_EMAIL_PATHS`, so switching to it changes nothing until a path is\n * overridden.\n *\n * The two `*Clear` keys are lists of paths to `$unset`, and neither is derived from the leaf paths the\n * flow reads: a schema storing the verification state as one required-members subdocument is left\n * invalid by unsetting a single member. Pass the container path in that case. See `IVerifyEmailPaths`.\n *\n * ```ts\n * const flow = createVerifyEmailFlow({\n * model: Account,\n * paths: { email: 'mail', valid: 'verified', verifyClear: ['verification'] }\n * })\n * router.get('/check/verify-email/:email/:hash', flow.routerVerifyEmail())\n * ```\n */\nexport const createVerifyEmailFlow = ({ model, paths }: ICreateVerifyEmailFlowArgs): IVerifyEmailFlow => {\n\tconst resolved = resolveVerifyEmailPaths(paths)\n\n\tconst userData4VerifyEmail = createUserData4VerifyEmail(model, resolved)\n\tconst enableEmailAccess = createEnableEmailAccess(model, resolved)\n\tconst confirmNewEmail = createConfirmNewEmail(model, resolved)\n\tconst deleteUserByEmail = createDeleteUserByEmail(model, resolved)\n\tconst incReqTimes = createIncReqTimes(model, resolved)\n\n\tconst assertVerifyEmailAllowed = createAssertVerifyEmailAllowed({\n\t\tpaths: resolved,\n\t\thandleIfHashBad: createHandleIfHashBad(incReqTimes),\n\t\thandleIfMoreThan3DaysPassed: createHandleIfMoreThan3DaysPassed(deleteUserByEmail),\n\t\thandleIfTooMuchRequestsTimes: createHandleIfTooMuchRequestsTimes(deleteUserByEmail)\n\t})\n\n\treturn {\n\t\tuserData4VerifyEmail,\n\t\tsetEmailHash: createSetEmailHash(model, resolved),\n\t\tenableEmailAccess,\n\t\tconfirmNewEmail,\n\t\tdeleteUserByEmail,\n\t\tincReqTimes,\n\t\tassertVerifyEmailAllowed,\n\t\temailChangeHashVerify: createEmailChangeHashVerifyMutation({\n\t\t\tmodel,\n\t\t\tpaths: resolved,\n\t\t\tconfirmNewEmail,\n\t\t\tincReqTimes\n\t\t}),\n\t\trouterVerifyEmail: createVerifyEmailRouter({\n\t\t\tuserData4VerifyEmail,\n\t\t\tassertVerifyEmailAllowed,\n\t\t\tenableEmailAccess\n\t\t})\n\t}\n}\n"]}
@@ -1,5 +1,9 @@
1
+ import { IVerifyEmailPaths } from "../../../lib/access/accessPaths.mjs";
1
2
  import { Types } from 'mongoose';
2
- /** The projection userData4VerifyEmail selects, as the guard chain needs it. */
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 function assertVerifyEmailAllowed(user: IVerifyEmailUser, email: string, hash: string): Promise<Types.ObjectId>;
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 uId = user._id;
30
- const userAccount = user.account;
31
- const userAccountEmail = userAccount.email;
32
- const requestTimes = userAccountEmail.requestTimes;
33
- const dateLastReq = userAccountEmail.dateLastReq;
34
- const { deleted, disabled } = userAccount;
35
- await handleIfEmailAlreadyValid(email, userAccountEmail.valid);
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({ uId, uEmail: email, hash, requestTimes, dbHash: userAccountEmail.hash });
40
- await handleIfMoreThan3DaysPassed(email, dateLastReq);
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":"AAEA,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,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAA;AAiBjF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,IAAsB,EAAE,KAAa,EAAE,IAAY;IACjG,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;IACpB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAA;IAChC,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAA;IAC1C,MAAM,YAAY,GAAG,gBAAgB,CAAC,YAAY,CAAA;IAClD,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,CAAA;IAChD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;IAEzC,MAAM,yBAAyB,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAC9D,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IACtC,MAAM,4BAA4B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IACvD,kFAAkF;IAClF,MAAM,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAA;IAEhG,MAAM,2BAA2B,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IACrD,+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","sourcesContent":["import { 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 } from './handleIfHashBad.mjs'\nimport { handleIfMoreThan3DaysPassed } from './handleIfMoreThan3DaysPassed.mjs'\nimport { handleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs'\n\n/** The projection userData4VerifyEmail selects, 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/**\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 */\nexport async function assertVerifyEmailAllowed(user: IVerifyEmailUser, email: string, hash: string): Promise<Types.ObjectId> {\n\tconst uId = user._id\n\tconst userAccount = user.account\n\tconst userAccountEmail = userAccount.email\n\tconst requestTimes = userAccountEmail.requestTimes\n\tconst dateLastReq = userAccountEmail.dateLastReq\n\tconst { deleted, disabled } = userAccount\n\n\tawait handleIfEmailAlreadyValid(email, userAccountEmail.valid)\n\thandleBadDB(requestTimes, dateLastReq)\n\tawait handleIfTooMuchRequestsTimes(email, requestTimes)\n\t// dbHash is the value STORED for this account — never the one supplied in the URL\n\tawait handleIfHashBad({ uId, uEmail: email, hash, requestTimes, dbHash: userAccountEmail.hash })\n\n\tawait handleIfMoreThan3DaysPassed(email, dateLastReq)\n\t// The flags are passed raw. userData4VerifyEmail reads .lean(), so Mongoose casting never runs\n\t// and these are exactly what the driver found — which is only ever a boolean once\n\t// scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored 'false'\n\t// is a truthy string and blocks the account; the fix is the migration, not a coercion here.\n\tawait handleIfAccountDeleted(email, deleted)\n\tawait handleIfAccountDisabled(email, disabled)\n\n\treturn uId\n}\n"]}
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 default function confirmNewEmail(_id: mongoose.Types.ObjectId, email: string): Promise<mongoose.UpdateWriteOpResult>;
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
- export default async function confirmNewEmail(_id, email) {
3
- return await UserBase.updateOne({ _id }, {
4
- $set: { 'login.email': email },
5
- $unset: {
6
- 'account.email.hash': '',
7
- 'account.email.dateLastReq': '',
8
- 'account.email.requestTimes': '',
9
- 'account.email.newEmailTmp': ''
10
- }
11
- }).exec();
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;AAGvD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CAAC,GAA4B,EAAE,KAAa;IACxF,OAAO,MAAM,QAAQ,CAAC,SAAS,CAC9B,EAAE,GAAG,EAAE,EACP;QACC,IAAI,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE;QAC9B,MAAM,EAAE;YACP,oBAAoB,EAAE,EAAE;YACxB,2BAA2B,EAAE,EAAE;YAC/B,4BAA4B,EAAE,EAAE;YAChC,2BAA2B,EAAE,EAAE;SAC/B;KACD,CACD,CAAC,IAAI,EAAE,CAAA;AACT,CAAC","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport mongoose from 'mongoose'\n\nexport default async function confirmNewEmail(_id: mongoose.Types.ObjectId, email: string) {\n\treturn await UserBase.updateOne(\n\t\t{ _id },\n\t\t{\n\t\t\t$set: { 'login.email': email },\n\t\t\t$unset: {\n\t\t\t\t'account.email.hash': '',\n\t\t\t\t'account.email.dateLastReq': '',\n\t\t\t\t'account.email.requestTimes': '',\n\t\t\t\t'account.email.newEmailTmp': ''\n\t\t\t}\n\t\t}\n\t).exec()\n}\n"]}
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
- export default function deleteUserByEmail(email: string): Promise<void>;
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 default async function deleteUserByEmail(email) {
4
- await UserBase.deleteOne({ 'login.email': email });
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,OAAO,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAa;IAC5D,MAAM,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAA;IAElD;MACK;AACN,CAAC","sourcesContent":["// @todo report on Sentry\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\n\nexport default async function deleteUserByEmail(email: string) {\n\tawait UserBase.deleteOne({ 'login.email': email })\n\n\t/* if (ret.deletedCount === 0) {\n } */\n}\n"]}
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 function enableEmailAccess(_id: mongoose.Types.ObjectId, email: string): Promise<void>;
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
- export async function enableEmailAccess(_id, email) {
4
- await UserBase.updateOne({ _id }, {
5
- $set: { 'account.email.valid': true },
6
- $unset: {
7
- 'account.email.hash': '',
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;AAGvD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAA4B,EAAE,KAAa;IAClF,MAAM,QAAQ,CAAC,SAAS,CACvB,EAAE,GAAG,EAAE,EACP;QACC,IAAI,EAAE,EAAE,qBAAqB,EAAE,IAAI,EAAE;QACrC,MAAM,EAAE;YACP,oBAAoB,EAAE,EAAE;YACxB,2BAA2B,EAAE,EAAE;YAC/B,4BAA4B,EAAE,EAAE;SAChC;KACD,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","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport mongoose from 'mongoose'\n\nexport async function enableEmailAccess(_id: mongoose.Types.ObjectId, email: string) {\n\tawait UserBase.updateOne(\n\t\t{ _id },\n\t\t{\n\t\t\t$set: { 'account.email.valid': true },\n\t\t\t$unset: {\n\t\t\t\t'account.email.hash': '',\n\t\t\t\t'account.email.dateLastReq': '',\n\t\t\t\t'account.email.requestTimes': ''\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\trunValidators: true\n\t\t}\n\t)\n\n\tconst SocketLabsObj = new SocketLabsLib()\n\tawait SocketLabsObj.sendWelcome(email)\n}\n"]}
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 { ClientSession } from 'mongoose';
2
- export declare const getResetPwd: (session: ClientSession, email: string) => Promise<{
3
- _id: import("mongoose").Types.ObjectId;
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
- } | null>;
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,25 @@
1
+ import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
1
2
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
2
- export const getResetPwd = async function (session, email) {
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 UserBase.findOne({ 'login.email': email })
5
- .select('_id personalData.name account.resetDateReq account.resetHash')
6
+ const queryRet = await model
7
+ .findOne({ [paths.email]: email })
8
+ .select(buildProjection([paths.name, paths.resetDateReq, paths.resetHash]))
6
9
  .session(session)
7
10
  .lean();
8
11
  // if a reset request is found
9
12
  if (queryRet !== null) {
10
- const resetDateReq = queryRet.account.resetDateReq;
13
+ const resetDateReq = readPath(queryRet, paths.resetDateReq);
11
14
  let resetHash = null;
12
15
  if (typeof resetDateReq !== 'undefined') {
13
- const storedHash = queryRet.account.resetHash;
14
- // Never stringify, and never fall back to account.email.hash. '' + undefined yields the
15
- // literal string "undefined", which passed updatePassword's null check and then matched a
16
- // caller sending that same literal as the hash argument — a reset with no secret at all.
17
- // The two fields must also stay disjoint: reading the verification slot here is what let a
18
- // hash issued by one flow authenticate the other. Anything but a stored string => null,
19
- // which updatePassword rejects with a 500.
16
+ const storedHash = readPath(queryRet, paths.resetHash);
17
+ // Never stringify, and never fall back to the email-verification hash slot. '' + undefined
18
+ // yields the literal string "undefined", which passed updatePassword's null check and then
19
+ // matched a caller sending that same literal as the hash argument — a reset with no secret
20
+ // at all. The two fields must also stay disjoint: reading the verification slot here is
21
+ // what let a hash issued by one flow authenticate the other. Anything but a stored string
22
+ // => null, which updatePassword rejects with the same 403 it gives an unknown address.
20
23
  if (typeof storedHash === 'string') {
21
24
  resetHash = storedHash;
22
25
  }
@@ -25,9 +28,11 @@ export const getResetPwd = async function (session, email) {
25
28
  _id: queryRet._id,
26
29
  resetDateReq,
27
30
  resetHash,
28
- name: queryRet.personalData?.name || ''
31
+ name: readPath(queryRet, paths.name) || ''
29
32
  };
30
33
  }
31
34
  return ret;
32
35
  };
36
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
37
+ export const getResetPwd = createGetResetPwd(UserBase, DEFAULT_RESET_PWD_PATHS);
33
38
  //# 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;AAGvD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,WAAW,OAAsB,EAAE,KAAa;IAC/E,IAAI,GAAG,GAAG,IAAI,CAAA;IAEd,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;SAC/D,MAAM,CAAC,8DAA8D,CAAC;SACtE,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IAER,8BAA8B;IAC9B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAA;QAClD,IAAI,SAAS,GAAG,IAAI,CAAA;QAEpB,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;YACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAA;YAE7C,wFAAwF;YACxF,0FAA0F;YAC1F,yFAAyF;YACzF,2FAA2F;YAC3F,wFAAwF;YACxF,2CAA2C;YAC3C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;gBACpC,SAAS,GAAG,UAAU,CAAA;YACvB,CAAC;QACF,CAAC;QAED,GAAG,GAAG;YACL,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,YAAY;YACZ,SAAS;YACT,IAAI,EAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,IAAI,EAAE;SACvC,CAAA;IACF,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC,CAAA","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport const getResetPwd = async function (session: ClientSession, email: string) {\n\tlet ret = null\n\n\tconst queryRet = await UserBase.findOne({ 'login.email': email })\n\t\t.select('_id personalData.name account.resetDateReq account.resetHash')\n\t\t.session(session)\n\t\t.lean()\n\n\t// if a reset request is found\n\tif (queryRet !== null) {\n\t\tconst resetDateReq = queryRet.account.resetDateReq\n\t\tlet resetHash = null\n\n\t\tif (typeof resetDateReq !== 'undefined') {\n\t\t\tconst storedHash = queryRet.account.resetHash\n\n\t\t\t// Never stringify, and never fall back to account.email.hash. '' + undefined yields the\n\t\t\t// literal string \"undefined\", which passed updatePassword's null check and then matched a\n\t\t\t// caller sending that same literal as the hash argument — a reset with no secret at all.\n\t\t\t// The two fields must also stay disjoint: reading the verification slot here is what let a\n\t\t\t// hash issued by one flow authenticate the other. Anything but a stored string => null,\n\t\t\t// which updatePassword rejects with a 500.\n\t\t\tif (typeof storedHash === 'string') {\n\t\t\t\tresetHash = storedHash\n\t\t\t}\n\t\t}\n\n\t\tret = {\n\t\t\t_id: queryRet._id,\n\t\t\tresetDateReq,\n\t\t\tresetHash,\n\t\t\tname: queryRet.personalData?.name || ''\n\t\t}\n\t}\n\treturn ret\n}\n"]}
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,CAAC,CAAC,CAAC;SAC1E,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IAER,8BAA8B;IAC9B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,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]))\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\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 function incReqTimes(_id: mongoose.Types.ObjectId): Promise<mongoose.UpdateWriteOpResult>;
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 UserBase.updateOne({ _id }, { $inc: { 'account.email.requestTimes': 1 } }, { runValidators: true });
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;IAC7D,OAAO,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,4BAA4B,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAC3G,CAAC","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport mongoose from 'mongoose'\n\nexport async function incReqTimes(_id: mongoose.Types.ObjectId) {\n\treturn UserBase.updateOne({ _id }, { $inc: { 'account.email.requestTimes': 1 } }, { runValidators: true })\n}\n"]}
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 default function removeResetReq(session: ClientSession, email: string): Promise<import("mongoose").UpdateWriteOpResult>;
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
- export default async function removeResetReq(session, email) {
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.email — and updateOne skips
5
- // validators, so that row bypassed every required field in the schema (login.password,
6
- // account.email.valid, account.registrationDate). A no-op is the only correct answer to "clear the
7
- // reset state of a user that does not exist".
8
- return UserBase.updateOne({ 'login.email': email }, { $unset: { 'account.resetDateReq': '', 'account.resetHash': '' } })
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;AAGvD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,KAAa;IACjF,iGAAiG;IACjG,6FAA6F;IAC7F,uFAAuF;IACvF,mGAAmG;IACnG,8CAA8C;IAC9C,OAAO,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,sBAAsB,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,EAAE,EAAE,CAAC;SACtH,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;AACT,CAAC","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport default async function removeResetReq(session: ClientSession, email: string) {\n\t// No { upsert: true }. An upsert on a clearing operation is backwards: when the email matched no\n\t// document MongoDB did not no-op, it inserted one keyed by login.email — and updateOne skips\n\t// validators, so that row bypassed every required field in the schema (login.password,\n\t// account.email.valid, account.registrationDate). A no-op is the only correct answer to \"clear the\n\t// reset state of a user that does not exist\".\n\treturn UserBase.updateOne({ 'login.email': email }, { $unset: { 'account.resetDateReq': '', 'account.resetHash': '' } })\n\t\t.session(session)\n\t\t.exec()\n}\n"]}
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 saveResetReq: (session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) => Promise<void>;
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 saveResetReq = async function (session, _id, now, hash) {
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 UserBase.updateOne({ _id }, {
7
+ await model.updateOne({ _id }, {
7
8
  $set: {
8
- 'account.resetDateReq': now,
9
- // account.resetHash, never account.email.hash: writing the verification slot here
10
- // invalidated any pending activation or email-change link, and left a live reset
11
- // token in the field those flows compare against.
12
- 'account.resetHash': hash
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":"AACA,OAAO,EAAE,kBAAkB,EAAE,qDAAyC;AACtE,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,WAAW,OAAsB,EAAE,GAAmB,EAAE,GAAS,EAAE,IAAY;IAC/G,gDAAgD;IAChD,IAAI,CAAC;QACJ,MAAM,QAAQ,CAAC,SAAS,CACvB,EAAE,GAAG,EAAE,EACP;YACC,IAAI,EAAE;gBACL,sBAAsB,EAAE,GAAG;gBAC3B,kFAAkF;gBAClF,iFAAiF;gBACjF,kDAAkD;gBAClD,mBAAmB,EAAE,IAAI;aACzB;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","sourcesContent":["import { 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 saveResetReq = async function (session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) {\n\t// console.debug('imposto reset in coll Utenti')\n\ttry {\n\t\tawait UserBase.updateOne(\n\t\t\t{ _id },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\t'account.resetDateReq': now,\n\t\t\t\t\t// account.resetHash, never account.email.hash: writing the verification slot here\n\t\t\t\t\t// invalidated any pending activation or email-change link, and left a live reset\n\t\t\t\t\t// token in the field those flows compare against.\n\t\t\t\t\t'account.resetHash': hash\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ session, runValidators: true }\n\t\t)\n\t} catch (e) {\n\t\tthrow throwMongoDBErrors(e as IMongoDBError)\n\t}\n}\n"]}
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 function setEmailHash(session: ClientSession, userId: Types.ObjectId): Promise<string>;
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 UserBase.updateOne({ _id: userId }, {
8
+ await model.updateOne({ _id: userId }, {
8
9
  $set: {
9
- 'account.email.hash': hash,
10
- 'account.email.requestTimes': 1, // ok
11
- 'account.email.dateLastReq': dtNow
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
@@ -1 +1 @@
1
- {"version":3,"file":"setEmailHash.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/setEmailHash.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sCAA0B;AAC9C,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,MAAsB;IAChF,MAAM,IAAI,GAAG,SAAS,EAAE,CAAA;IAExB,yBAAyB;IACzB,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;IAExB,MAAM,QAAQ,CAAC,SAAS,CACvB,EAAE,GAAG,EAAE,MAAM,EAAE,EACf;QACC,IAAI,EAAE;YACL,oBAAoB,EAAE,IAAI;YAC1B,4BAA4B,EAAE,CAAC,EAAE,KAAK;YACtC,2BAA2B,EAAE,KAAK;SAClC;KACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IAED,OAAO,IAAI,CAAA,CAAC,2CAA2C;AACxD,CAAC","sourcesContent":["import { emailHash } from '@lib/emailHash.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport async function setEmailHash(session: ClientSession, userId: Types.ObjectId) {\n\tconst hash = emailHash()\n\n\t//calculate password hash\n\tconst dtNow = new Date()\n\n\tawait UserBase.updateOne(\n\t\t{ _id: userId },\n\t\t{\n\t\t\t$set: {\n\t\t\t\t'account.email.hash': hash,\n\t\t\t\t'account.email.requestTimes': 1, // ok\n\t\t\t\t'account.email.dateLastReq': dtNow\n\t\t\t}\n\t\t},\n\t\t{ session, runValidators: true }\n\t)\n\n\treturn hash // else it goes into exception @fixme check\n}\n"]}
1
+ {"version":3,"file":"setEmailHash.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/setEmailHash.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,SAAS,EAAE,sCAA0B;AAC9C,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACnF,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,MAAsB;IACzE,MAAM,IAAI,GAAG,SAAS,EAAE,CAAA;IAExB,yBAAyB;IACzB,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;IAExB,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,MAAM,EAAE,EACf;QACC,IAAI,EAAE;YACL,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI;YAClB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,KAAK;YAC9B,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK;SAC1B;KACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IAED,OAAO,IAAI,CAAA,CAAC,2CAA2C;AACxD,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAkB,kBAAkB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { emailHash } from '@lib/emailHash.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport const createSetEmailHash = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function setEmailHash(session: ClientSession, userId: Types.ObjectId) {\n\t\tconst hash = emailHash()\n\n\t\t//calculate password hash\n\t\tconst dtNow = new Date()\n\n\t\tawait model.updateOne(\n\t\t\t{ _id: userId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\t[paths.hash]: hash,\n\t\t\t\t\t[paths.requestTimes]: 1, // ok\n\t\t\t\t\t[paths.dateLastReq]: dtNow\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ session, runValidators: true }\n\t\t)\n\n\t\treturn hash // else it goes into exception @fixme check\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TSetEmailHash = ReturnType<typeof createSetEmailHash>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const setEmailHash: TSetEmailHash = createSetEmailHash(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}