@axiumine/koa-utils 5.2.0 → 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 +15 -1
  6. package/dist/graphQL/schema/mutations/resetPwd.mjs +9 -4
  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 +18 -5
  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
@@ -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 the same 403 it gives an unknown address.
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,8EAA8E;YAC9E,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 the same 403 it gives an unknown address.\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"]}
@@ -1,2 +1,8 @@
1
+ import { IResetPwdPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
1
2
  import mongoose, { ClientSession } from 'mongoose';
2
- export default function updatePassword(session: ClientSession, _id: mongoose.Types.ObjectId, password: string): Promise<mongoose.UpdateWriteOpResult>;
3
+ export declare const createUpdatePasswordDb: (model: TAccessModel, paths: IResetPwdPaths) => (session: ClientSession, _id: mongoose.Types.ObjectId, password: string) => Promise<mongoose.UpdateWriteOpResult>;
4
+ /** Signature of the bound writer, for the modules that take it as a dependency. */
5
+ export type TUpdatePasswordDb = ReturnType<typeof createUpdatePasswordDb>;
6
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
7
+ declare const _default: (session: ClientSession, _id: mongoose.Types.ObjectId, password: string) => Promise<mongoose.UpdateWriteOpResult>;
8
+ export default _default;
@@ -1,8 +1,11 @@
1
+ import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
1
2
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
2
3
  import { hash } from '@node-rs/bcrypt';
3
4
  import { SALT_ROUNDS } from "../Constants.mjs";
4
- export default async function updatePassword(session, _id, password) {
5
+ export const createUpdatePasswordDb = (model, paths) => async function updatePassword(session, _id, password) {
5
6
  const hashVal = await hash(password, SALT_ROUNDS);
6
- return UserBase.updateOne({ _id }, { $set: { 'login.password': hashVal } }, { session, runValidators: true });
7
- }
7
+ return model.updateOne({ _id }, { $set: { [paths.password]: hashVal } }, { session, runValidators: true });
8
+ };
9
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
10
+ export default createUpdatePasswordDb(UserBase, DEFAULT_RESET_PWD_PATHS);
8
11
  //# sourceMappingURL=updatePasswordDb.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"updatePasswordDb.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/updatePasswordDb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,yBAAyC;AAG/D,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,GAA4B,EAAE,QAAgB;IAClH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;IAEjD,OAAO,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAC9G,CAAC","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { hash } from '@node-rs/bcrypt'\nimport { SALT_ROUNDS } from '@private/lib/access/Constants.mjs'\nimport mongoose, { ClientSession } from 'mongoose'\n\nexport default async function updatePassword(session: ClientSession, _id: mongoose.Types.ObjectId, password: string) {\n\tconst hashVal = await hash(password, SALT_ROUNDS)\n\n\treturn UserBase.updateOne({ _id }, { $set: { 'login.password': hashVal } }, { session, runValidators: true })\n}\n"]}
1
+ {"version":3,"file":"updatePasswordDb.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/updatePasswordDb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AACnG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,yBAAyC;AAG/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CACpF,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,GAA4B,EAAE,QAAgB;IACnG,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;IAEjD,OAAO,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAC3G,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,sBAAsB,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 { hash } from '@node-rs/bcrypt'\nimport { SALT_ROUNDS } from '@private/lib/access/Constants.mjs'\nimport mongoose, { ClientSession } from 'mongoose'\n\nexport const createUpdatePasswordDb = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function updatePassword(session: ClientSession, _id: mongoose.Types.ObjectId, password: string) {\n\t\tconst hashVal = await hash(password, SALT_ROUNDS)\n\n\t\treturn model.updateOne({ _id }, { $set: { [paths.password]: hashVal } }, { session, runValidators: true })\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TUpdatePasswordDb = ReturnType<typeof createUpdatePasswordDb>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport default createUpdatePasswordDb(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
@@ -1,3 +1,6 @@
1
- export declare function userData4VerifyEmail(uEmail: string): Promise<import("../../../../graphQL/models/MongoDB/UserBase.mjs").IUserBaseSchema & Required<{
2
- _id: import("mongoose").Types.ObjectId;
3
- }>>;
1
+ import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
2
+ export declare const createUserData4VerifyEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (uEmail: string) => Promise<any>;
3
+ /** Signature of the bound reader, for the modules that take it as a dependency. */
4
+ export type TUserData4VerifyEmail = ReturnType<typeof createUserData4VerifyEmail>;
5
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
6
+ export declare const userData4VerifyEmail: TUserData4VerifyEmail;
@@ -1,10 +1,15 @@
1
+ import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
1
2
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
2
3
  import { EMAIL_CHECK_LINK } from "../Constants.mjs";
4
+ import { buildProjection } from "../pathTools.mjs";
3
5
  import * as Sentry from '@sentry/node';
4
- export async function userData4VerifyEmail(uEmail) {
5
- const user = await UserBase.findOne({ 'login.email': uEmail })
6
- .select('_id account.email.hash account.email.valid account.email.dateLastReq account.email.requestTimes ' +
7
- 'account.deleted account.disabled')
6
+ export const createUserData4VerifyEmail = (model, paths) => async function userData4VerifyEmail(uEmail) {
7
+ // Every field the guard chain reads must be listed. This is a .lean() read, so a field left out
8
+ // of the projection is simply absent on the returned object, with no error — which is how a
9
+ // missing requestTimes turned every wrong-hash attempt into a 500 under a green coverage gate.
10
+ const user = await model
11
+ .findOne({ [paths.email]: uEmail })
12
+ .select(buildProjection([paths.hash, paths.valid, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))
8
13
  .lean();
9
14
  // if email not found, return stNotFoundNotMatch
10
15
  if (user === null) {
@@ -12,5 +17,7 @@ export async function userData4VerifyEmail(uEmail) {
12
17
  throw new Error(EMAIL_CHECK_LINK);
13
18
  }
14
19
  return user;
15
- }
20
+ };
21
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
22
+ export const userData4VerifyEmail = createUserData4VerifyEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
16
23
  //# sourceMappingURL=userData4VerifyEmail.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"userData4VerifyEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/userData4VerifyEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,gBAAgB,EAAE,yBAAyC;AACpE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAc;IACxD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;SAC5D,MAAM,CACN,kGAAkG;QACjG,kCAAkC,CACnC;SACA,IAAI,EAAE,CAAA;IAER,gDAAgD;IAChD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,QAAQ,MAAM,YAAY,CAAC,CAAA;QAEjD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC","sourcesContent":["import { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { EMAIL_CHECK_LINK } from '@private/lib/access/Constants.mjs'\nimport * as Sentry from '@sentry/node'\n\nexport async function userData4VerifyEmail(uEmail: string) {\n\tconst user = await UserBase.findOne({ 'login.email': uEmail })\n\t\t.select(\n\t\t\t'_id account.email.hash account.email.valid account.email.dateLastReq account.email.requestTimes ' +\n\t\t\t\t'account.deleted account.disabled'\n\t\t)\n\t\t.lean()\n\n\t// if email not found, return stNotFoundNotMatch\n\tif (user === null) {\n\t\tSentry.captureMessage(`User ${uEmail} not exist`)\n\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n\treturn user\n}\n"]}
1
+ {"version":3,"file":"userData4VerifyEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/userData4VerifyEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,gBAAgB,EAAE,yBAAyC;AACpE,OAAO,EAAE,eAAe,EAAE,yBAAyC;AACnE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CAC3F,KAAK,UAAU,oBAAoB,CAAC,MAAc;IACjD,gGAAgG;IAChG,4FAA4F;IAC5F,+FAA+F;IAC/F,MAAM,IAAI,GAAG,MAAM,KAAK;SACtB,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;SAClC,MAAM,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;SACxH,IAAI,EAAE,CAAA;IAER,gDAAgD;IAChD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,QAAQ,MAAM,YAAY,CAAC,CAAA;QAEjD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,oBAAoB,GAA0B,0BAA0B,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 { EMAIL_CHECK_LINK } from '@private/lib/access/Constants.mjs'\nimport { buildProjection } from '@private/lib/access/pathTools.mjs'\nimport * as Sentry from '@sentry/node'\n\nexport const createUserData4VerifyEmail = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function userData4VerifyEmail(uEmail: string) {\n\t\t// Every field the guard chain reads must be listed. This is a .lean() read, so a field left out\n\t\t// of the projection is simply absent on the returned object, with no error — which is how a\n\t\t// missing requestTimes turned every wrong-hash attempt into a 500 under a green coverage gate.\n\t\tconst user = await model\n\t\t\t.findOne({ [paths.email]: uEmail })\n\t\t\t.select(buildProjection([paths.hash, paths.valid, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))\n\t\t\t.lean()\n\n\t\t// if email not found, return stNotFoundNotMatch\n\t\tif (user === null) {\n\t\t\tSentry.captureMessage(`User ${uEmail} not exist`)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t\treturn user\n\t}\n\n/** Signature of the bound reader, for the modules that take it as a dependency. */\nexport type TUserData4VerifyEmail = ReturnType<typeof createUserData4VerifyEmail>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const userData4VerifyEmail: TUserData4VerifyEmail = createUserData4VerifyEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
@@ -1,4 +1,5 @@
1
1
  import mongoose from 'mongoose';
2
+ import { TIncReqTimes } from './db/incReqTimes.mjs';
2
3
  interface IHandleIfHashBadArgs {
3
4
  uId: mongoose.Types.ObjectId;
4
5
  uEmail: string;
@@ -7,8 +8,14 @@ interface IHandleIfHashBadArgs {
7
8
  dbHash?: string;
8
9
  }
9
10
  /**
10
- * The hash in the activation url is wrong
11
- * @param args
11
+ * The hash in the activation url is wrong.
12
+ *
13
+ * The strike counter is bumped through an injected writer so the guard can serve a model other than
14
+ * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
12
15
  */
13
- export declare function handleIfHashBad({ uId, uEmail, hash, requestTimes, dbHash }: IHandleIfHashBadArgs): Promise<void>;
16
+ export declare const createHandleIfHashBad: (incReqTimesFn: TIncReqTimes) => ({ uId, uEmail, hash, requestTimes, dbHash }: IHandleIfHashBadArgs) => Promise<void>;
17
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
18
+ export type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>;
19
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
20
+ export declare const handleIfHashBad: THandleIfHashBad;
14
21
  export {};
@@ -2,16 +2,20 @@ import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
2
2
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
3
3
  import { incReqTimes } from './db/incReqTimes.mjs';
4
4
  /**
5
- * The hash in the activation url is wrong
6
- * @param args
5
+ * The hash in the activation url is wrong.
6
+ *
7
+ * The strike counter is bumped through an injected writer so the guard can serve a model other than
8
+ * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
7
9
  */
8
- export async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
10
+ export const createHandleIfHashBad = (incReqTimesFn) => async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
9
11
  if (hash !== dbHash) {
10
12
  // hash failed
11
- await incReqTimes(uId);
13
+ await incReqTimesFn(uId);
12
14
  const SocketLabsObj = new SocketLabsLib();
13
15
  await SocketLabsObj.wrongHash(uEmail, requestTimes + 1);
14
16
  throw new Error(EMAIL_CHECK_LINK);
15
17
  }
16
- }
18
+ };
19
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
20
+ export const handleIfHashBad = createHandleIfHashBad(incReqTimes);
17
21
  //# sourceMappingURL=handleIfHashBad.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAUlD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,EAAE,MAAM,EAAwB;IAC1G,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,cAAc;QACd,MAAM,WAAW,CAAC,GAAG,CAAC,CAAA;QAEtB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAA;QACvD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport mongoose from 'mongoose'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport { incReqTimes } from './db/incReqTimes.mjs'\n\ninterface IHandleIfHashBadArgs {\n\tuId: mongoose.Types.ObjectId\n\tuEmail: string\n\thash: string\n\trequestTimes?: number // but the check is already performed\n\tdbHash?: string\n}\n\n/**\n * The hash in the activation url is wrong\n * @param args\n */\nexport async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }: IHandleIfHashBadArgs) {\n\tif (hash !== dbHash) {\n\t\t// hash failed\n\t\tawait incReqTimes(uId)\n\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.wrongHash(uEmail, requestTimes + 1)\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,sBAAsB,CAAA;AAUhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,aAA2B,EAAE,EAAE,CACpE,KAAK,UAAU,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,EAAE,MAAM,EAAwB;IACnG,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,cAAc;QACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;QAExB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAA;QACvD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAqB,qBAAqB,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport mongoose from 'mongoose'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport { incReqTimes, TIncReqTimes } from './db/incReqTimes.mjs'\n\ninterface IHandleIfHashBadArgs {\n\tuId: mongoose.Types.ObjectId\n\tuEmail: string\n\thash: string\n\trequestTimes?: number // but the check is already performed\n\tdbHash?: string\n}\n\n/**\n * The hash in the activation url is wrong.\n *\n * The strike counter is bumped through an injected writer so the guard can serve a model other than\n * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.\n */\nexport const createHandleIfHashBad = (incReqTimesFn: TIncReqTimes) =>\n\tasync function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }: IHandleIfHashBadArgs) {\n\t\tif (hash !== dbHash) {\n\t\t\t// hash failed\n\t\t\tawait incReqTimesFn(uId)\n\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.wrongHash(uEmail, requestTimes + 1)\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfHashBad: THandleIfHashBad = createHandleIfHashBad(incReqTimes)\n"]}
@@ -1 +1,12 @@
1
- export declare function handleIfMoreThan3DaysPassed(uEmail: string, dateLastReq?: Date): Promise<void>;
1
+ import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
2
+ /**
3
+ * A verification link older than 3 days deletes the pending account.
4
+ *
5
+ * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
6
+ * both the collection and the login-email path come from the writer it was built with.
7
+ */
8
+ export declare const createHandleIfMoreThan3DaysPassed: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, dateLastReq?: Date) => Promise<void>;
9
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
10
+ export type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>;
11
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
12
+ export declare const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed;
@@ -2,7 +2,13 @@ import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
2
2
  import { StringLib } from "../../../lib/StringLib.mjs";
3
3
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
4
4
  import deleteUserByEmail from './db/deleteUserByEmail.mjs';
5
- export async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date() // but it is already handled
5
+ /**
6
+ * A verification link older than 3 days deletes the pending account.
7
+ *
8
+ * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
9
+ * both the collection and the login-email path come from the writer it was built with.
10
+ */
11
+ export const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn) => async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date() // but it is already handled
6
12
  ) {
7
13
  /****************************************************
8
14
  * if dateLastReq too old then 3 days send email
@@ -16,8 +22,10 @@ export async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date
16
22
  // dateLastReq too old then 3 days
17
23
  const SocketLabsObj = new SocketLabsLib();
18
24
  await SocketLabsObj.hashReqTooOld(uEmail);
19
- await deleteUserByEmail(uEmail);
25
+ await deleteUserByEmailFn(uEmail);
20
26
  throw new Error(EMAIL_CHECK_LINK);
21
27
  }
22
- }
28
+ };
29
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
30
+ export const handleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail);
23
31
  //# sourceMappingURL=handleIfMoreThan3DaysPassed.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAE1D,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAChD,MAAc,EACd,cAAoB,IAAI,IAAI,EAAE,CAAC,4BAA4B;;IAE3D;;OAEG;IAEH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,IAAI,SAAS,GAAG,KAAK,EAAE,CAAC;QACvB,kCAAkC;QAClC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAEzC,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAE/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail from './db/deleteUserByEmail.mjs'\n\nexport async function handleIfMoreThan3DaysPassed(\n\tuEmail: string,\n\tdateLastReq: Date = new Date() // but it is already handled\n) {\n\t/****************************************************\n\t * if dateLastReq too old then 3 days send email\n\t */\n\n\tconst now = new Date()\n\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\tconst StrLibObj = new StringLib()\n\tconst tsReq = StrLibObj.isoToTimestamp(dateLastReq)\n\tconst ts3DayAgo = StrLibObj.isoToTimestamp(day3ago)\n\n\tif (ts3DayAgo > tsReq) {\n\t\t// dateLastReq too old then 3 days\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.hashReqTooOld(uEmail)\n\n\t\tawait deleteUserByEmail(uEmail)\n\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,mBAAuC,EAAE,EAAE,CAC5F,KAAK,UAAU,2BAA2B,CACzC,MAAc,EACd,cAAoB,IAAI,IAAI,EAAE,CAAC,4BAA4B;;IAE3D;;OAEG;IAEH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,IAAI,SAAS,GAAG,KAAK,EAAE,CAAC;QACvB,kCAAkC;QAClC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAEzC,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAiC,iCAAiC,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * A verification link older than 3 days deletes the pending account.\n *\n * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:\n * both the collection and the login-email path come from the writer it was built with.\n */\nexport const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn: TDeleteUserByEmail) =>\n\tasync function handleIfMoreThan3DaysPassed(\n\t\tuEmail: string,\n\t\tdateLastReq: Date = new Date() // but it is already handled\n\t) {\n\t\t/****************************************************\n\t\t * if dateLastReq too old then 3 days send email\n\t\t */\n\n\t\tconst now = new Date()\n\t\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\t\tconst StrLibObj = new StringLib()\n\t\tconst tsReq = StrLibObj.isoToTimestamp(dateLastReq)\n\t\tconst ts3DayAgo = StrLibObj.isoToTimestamp(day3ago)\n\n\t\tif (ts3DayAgo > tsReq) {\n\t\t\t// dateLastReq too old then 3 days\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.hashReqTooOld(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail)\n"]}
@@ -1 +1,12 @@
1
- export declare function handleIfTooMuchRequestsTimes(uEmail: string, requestTimes?: number): Promise<void>;
1
+ import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
2
+ /**
3
+ * Five wrong-hash attempts delete the pending account.
4
+ *
5
+ * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
6
+ * both the collection and the login-email path come from the writer it was built with.
7
+ */
8
+ export declare const createHandleIfTooMuchRequestsTimes: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, requestTimes?: number) => Promise<void>;
9
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
10
+ export type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>;
11
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
12
+ export declare const handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes;