@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
@@ -0,0 +1,92 @@
1
+ import { Model } from 'mongoose';
2
+ /**
3
+ * Any mongoose model an access flow can be pointed at.
4
+ *
5
+ * Deliberately `Model<any>`: the flows only ever call `findOne`, `updateOne`, `countDocuments` and
6
+ * `deleteOne` with computed field paths, so nothing here can be typed against a concrete document
7
+ * shape without forcing every consumer to describe theirs. The `paths` map below is what pins the
8
+ * contract instead — a wrong path is a runtime no-op, which is why the defaults are exported and the
9
+ * flows are tested against them.
10
+ */
11
+ export type TAccessModel = Model<any>;
12
+ /**
13
+ * Field paths the password-reset flow reads and writes.
14
+ *
15
+ * Every value is a dotted mongo path into the account document. They are supplied as data rather
16
+ * than hard-coded because `UserBase` is only one possible layout: a consumer whose accounts live in
17
+ * another collection, or under another field tree, could not use `resetPwd` / `updatePassword` at
18
+ * all while the paths were baked in.
19
+ */
20
+ export interface IResetPwdPaths {
21
+ /** Login address. Used as the lookup filter by `getResetPwd` and `removeResetReq`. */
22
+ email: string;
23
+ /** Bcrypt hash slot `updatePassword` overwrites. */
24
+ password: string;
25
+ /** Display name passed to the reset / confirmation emails. Missing value ⇒ empty string. */
26
+ name: string;
27
+ /** When the pending reset was requested. Drives the 10-minute throttle and the 60-minute expiry. */
28
+ resetDateReq: string;
29
+ /** Password-reset token. Must stay disjoint from the email-verification hash slot. */
30
+ resetHash: string;
31
+ /**
32
+ * Paths `removeResetReq` `$unset`s once a reset has been consumed.
33
+ *
34
+ * Kept separate from `resetDateReq` / `resetHash` on purpose — it is NOT always the same list.
35
+ * A layout that stores the request as one all-or-nothing subdocument, e.g.
36
+ * `resetPwd: { resetDateReq, resetHash }` under `validationLevel: 'strict'` +
37
+ * `validationAction: 'error'`, rejects a write that unsets a single member: the leftover document
38
+ * fails validation. The only legal cleanup there is `$unset: { resetPwd: '' }` — one container
39
+ * path, not two leaf paths. Deriving this list from the leaves would make that layout impossible
40
+ * to express, and the flat default hides the problem completely.
41
+ */
42
+ resetClear: readonly string[];
43
+ }
44
+ /** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */
45
+ export declare const DEFAULT_RESET_PWD_PATHS: IResetPwdPaths;
46
+ /**
47
+ * Merge a partial override over {@link DEFAULT_RESET_PWD_PATHS}.
48
+ *
49
+ * Plain spread: a key present with an explicit `undefined` value overrides the default with
50
+ * `undefined`, so pass only the keys being changed.
51
+ */
52
+ export declare function resolveResetPwdPaths(paths?: Partial<IResetPwdPaths>): IResetPwdPaths;
53
+ /**
54
+ * Field paths the email-verification and email-change flows read and write.
55
+ *
56
+ * Same rationale as {@link IResetPwdPaths}. Note that `hash` here is the inbox-proof token
57
+ * (activation and email change, 3-day life, `requestTimes` throttle) and must never be pointed at
58
+ * the same field as `IResetPwdPaths.resetHash`: while the two shared one slot, a hash issued by
59
+ * either flow authenticated the other, and an unauthenticated reset request killed pending
60
+ * activation links.
61
+ */
62
+ export interface IVerifyEmailPaths {
63
+ /** Live login address — lookup filter, and the field `confirmNewEmail` writes on an email change. */
64
+ email: string;
65
+ /** Boolean flag `enableEmailAccess` flips once a verification link is honoured. */
66
+ valid: string;
67
+ /** Verification / email-change token. Never the password-reset slot. */
68
+ hash: string;
69
+ /** When the current token was issued. Drives the 3-day link window. */
70
+ dateLastReq: string;
71
+ /** Strike counter. Five wrong hashes delete the account. */
72
+ requestTimes: string;
73
+ /** Address awaiting confirmation during an email change. */
74
+ newEmailTmp: string;
75
+ /** Account tombstone flag. */
76
+ deleted: string;
77
+ /** Account lockout flag. */
78
+ disabled: string;
79
+ /** Paths `enableEmailAccess` `$unset`s once a verification link is honoured. */
80
+ verifyClear: readonly string[];
81
+ /** Paths `confirmNewEmail` `$unset`s once a new address is accepted. */
82
+ emailChangeClear: readonly string[];
83
+ }
84
+ /** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */
85
+ export declare const DEFAULT_VERIFY_EMAIL_PATHS: IVerifyEmailPaths;
86
+ /**
87
+ * Merge a partial override over {@link DEFAULT_VERIFY_EMAIL_PATHS}.
88
+ *
89
+ * Plain spread: a key present with an explicit `undefined` value overrides the default with
90
+ * `undefined`, so pass only the keys being changed.
91
+ */
92
+ export declare function resolveVerifyEmailPaths(paths?: Partial<IVerifyEmailPaths>): IVerifyEmailPaths;
@@ -0,0 +1,46 @@
1
+ /** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */
2
+ export const DEFAULT_RESET_PWD_PATHS = Object.freeze({
3
+ email: 'login.email',
4
+ password: 'login.password',
5
+ name: 'personalData.name',
6
+ resetDateReq: 'account.resetDateReq',
7
+ resetHash: 'account.resetHash',
8
+ resetClear: Object.freeze(['account.resetDateReq', 'account.resetHash'])
9
+ });
10
+ /**
11
+ * Merge a partial override over {@link DEFAULT_RESET_PWD_PATHS}.
12
+ *
13
+ * Plain spread: a key present with an explicit `undefined` value overrides the default with
14
+ * `undefined`, so pass only the keys being changed.
15
+ */
16
+ export function resolveResetPwdPaths(paths) {
17
+ return { ...DEFAULT_RESET_PWD_PATHS, ...paths };
18
+ }
19
+ /** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */
20
+ export const DEFAULT_VERIFY_EMAIL_PATHS = Object.freeze({
21
+ email: 'login.email',
22
+ valid: 'account.email.valid',
23
+ hash: 'account.email.hash',
24
+ dateLastReq: 'account.email.dateLastReq',
25
+ requestTimes: 'account.email.requestTimes',
26
+ newEmailTmp: 'account.email.newEmailTmp',
27
+ deleted: 'account.deleted',
28
+ disabled: 'account.disabled',
29
+ verifyClear: Object.freeze(['account.email.hash', 'account.email.dateLastReq', 'account.email.requestTimes']),
30
+ emailChangeClear: Object.freeze([
31
+ 'account.email.hash',
32
+ 'account.email.dateLastReq',
33
+ 'account.email.requestTimes',
34
+ 'account.email.newEmailTmp'
35
+ ])
36
+ });
37
+ /**
38
+ * Merge a partial override over {@link DEFAULT_VERIFY_EMAIL_PATHS}.
39
+ *
40
+ * Plain spread: a key present with an explicit `undefined` value overrides the default with
41
+ * `undefined`, so pass only the keys being changed.
42
+ */
43
+ export function resolveVerifyEmailPaths(paths) {
44
+ return { ...DEFAULT_VERIFY_EMAIL_PATHS, ...paths };
45
+ }
46
+ //# sourceMappingURL=accessPaths.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessPaths.mjs","sourceRoot":"","sources":["../../../src/lib/access/accessPaths.mts"],"names":[],"mappings":"AA+CA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,uBAAuB,GAAmB,MAAM,CAAC,MAAM,CAAC;IACpE,KAAK,EAAE,aAAa;IACpB,QAAQ,EAAE,gBAAgB;IAC1B,IAAI,EAAE,mBAAmB;IACzB,YAAY,EAAE,sBAAsB;IACpC,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC;CACxE,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAA+B;IACnE,OAAO,EAAE,GAAG,uBAAuB,EAAE,GAAG,KAAK,EAAE,CAAA;AAChD,CAAC;AAkCD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,0BAA0B,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC1E,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,qBAAqB;IAC5B,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,2BAA2B;IACxC,YAAY,EAAE,4BAA4B;IAC1C,WAAW,EAAE,2BAA2B;IACxC,OAAO,EAAE,iBAAiB;IAC1B,QAAQ,EAAE,kBAAkB;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,2BAA2B,EAAE,4BAA4B,CAAC,CAAC;IAC7G,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC;QAC/B,oBAAoB;QACpB,2BAA2B;QAC3B,4BAA4B;QAC5B,2BAA2B;KAC3B,CAAC;CACF,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAkC;IACzE,OAAO,EAAE,GAAG,0BAA0B,EAAE,GAAG,KAAK,EAAE,CAAA;AACnD,CAAC","sourcesContent":["import { Model } from 'mongoose'\n\n/**\n * Any mongoose model an access flow can be pointed at.\n *\n * Deliberately `Model<any>`: the flows only ever call `findOne`, `updateOne`, `countDocuments` and\n * `deleteOne` with computed field paths, so nothing here can be typed against a concrete document\n * shape without forcing every consumer to describe theirs. The `paths` map below is what pins the\n * contract instead — a wrong path is a runtime no-op, which is why the defaults are exported and the\n * flows are tested against them.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TAccessModel = Model<any>\n\n/**\n * Field paths the password-reset flow reads and writes.\n *\n * Every value is a dotted mongo path into the account document. They are supplied as data rather\n * than hard-coded because `UserBase` is only one possible layout: a consumer whose accounts live in\n * another collection, or under another field tree, could not use `resetPwd` / `updatePassword` at\n * all while the paths were baked in.\n */\nexport interface IResetPwdPaths {\n\t/** Login address. Used as the lookup filter by `getResetPwd` and `removeResetReq`. */\n\temail: string\n\t/** Bcrypt hash slot `updatePassword` overwrites. */\n\tpassword: string\n\t/** Display name passed to the reset / confirmation emails. Missing value ⇒ empty string. */\n\tname: string\n\t/** When the pending reset was requested. Drives the 10-minute throttle and the 60-minute expiry. */\n\tresetDateReq: string\n\t/** Password-reset token. Must stay disjoint from the email-verification hash slot. */\n\tresetHash: string\n\t/**\n\t * Paths `removeResetReq` `$unset`s once a reset has been consumed.\n\t *\n\t * Kept separate from `resetDateReq` / `resetHash` on purpose — it is NOT always the same list.\n\t * A layout that stores the request as one all-or-nothing subdocument, e.g.\n\t * `resetPwd: { resetDateReq, resetHash }` under `validationLevel: 'strict'` +\n\t * `validationAction: 'error'`, rejects a write that unsets a single member: the leftover document\n\t * fails validation. The only legal cleanup there is `$unset: { resetPwd: '' }` — one container\n\t * path, not two leaf paths. Deriving this list from the leaves would make that layout impossible\n\t * to express, and the flat default hides the problem completely.\n\t */\n\tresetClear: readonly string[]\n}\n\n/** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */\nexport const DEFAULT_RESET_PWD_PATHS: IResetPwdPaths = Object.freeze({\n\temail: 'login.email',\n\tpassword: 'login.password',\n\tname: 'personalData.name',\n\tresetDateReq: 'account.resetDateReq',\n\tresetHash: 'account.resetHash',\n\tresetClear: Object.freeze(['account.resetDateReq', 'account.resetHash'])\n})\n\n/**\n * Merge a partial override over {@link DEFAULT_RESET_PWD_PATHS}.\n *\n * Plain spread: a key present with an explicit `undefined` value overrides the default with\n * `undefined`, so pass only the keys being changed.\n */\nexport function resolveResetPwdPaths(paths?: Partial<IResetPwdPaths>): IResetPwdPaths {\n\treturn { ...DEFAULT_RESET_PWD_PATHS, ...paths }\n}\n\n/**\n * Field paths the email-verification and email-change flows read and write.\n *\n * Same rationale as {@link IResetPwdPaths}. Note that `hash` here is the inbox-proof token\n * (activation and email change, 3-day life, `requestTimes` throttle) and must never be pointed at\n * the same field as `IResetPwdPaths.resetHash`: while the two shared one slot, a hash issued by\n * either flow authenticated the other, and an unauthenticated reset request killed pending\n * activation links.\n */\nexport interface IVerifyEmailPaths {\n\t/** Live login address — lookup filter, and the field `confirmNewEmail` writes on an email change. */\n\temail: string\n\t/** Boolean flag `enableEmailAccess` flips once a verification link is honoured. */\n\tvalid: string\n\t/** Verification / email-change token. Never the password-reset slot. */\n\thash: string\n\t/** When the current token was issued. Drives the 3-day link window. */\n\tdateLastReq: string\n\t/** Strike counter. Five wrong hashes delete the account. */\n\trequestTimes: string\n\t/** Address awaiting confirmation during an email change. */\n\tnewEmailTmp: string\n\t/** Account tombstone flag. */\n\tdeleted: string\n\t/** Account lockout flag. */\n\tdisabled: string\n\t/** Paths `enableEmailAccess` `$unset`s once a verification link is honoured. */\n\tverifyClear: readonly string[]\n\t/** Paths `confirmNewEmail` `$unset`s once a new address is accepted. */\n\temailChangeClear: readonly string[]\n}\n\n/** The layout of `UserBase` — i.e. the behaviour of the flow before it took a `paths` map. */\nexport const DEFAULT_VERIFY_EMAIL_PATHS: IVerifyEmailPaths = Object.freeze({\n\temail: 'login.email',\n\tvalid: 'account.email.valid',\n\thash: 'account.email.hash',\n\tdateLastReq: 'account.email.dateLastReq',\n\trequestTimes: 'account.email.requestTimes',\n\tnewEmailTmp: 'account.email.newEmailTmp',\n\tdeleted: 'account.deleted',\n\tdisabled: 'account.disabled',\n\tverifyClear: Object.freeze(['account.email.hash', 'account.email.dateLastReq', 'account.email.requestTimes']),\n\temailChangeClear: Object.freeze([\n\t\t'account.email.hash',\n\t\t'account.email.dateLastReq',\n\t\t'account.email.requestTimes',\n\t\t'account.email.newEmailTmp'\n\t])\n})\n\n/**\n * Merge a partial override over {@link DEFAULT_VERIFY_EMAIL_PATHS}.\n *\n * Plain spread: a key present with an explicit `undefined` value overrides the default with\n * `undefined`, so pass only the keys being changed.\n */\nexport function resolveVerifyEmailPaths(paths?: Partial<IVerifyEmailPaths>): IVerifyEmailPaths {\n\treturn { ...DEFAULT_VERIFY_EMAIL_PATHS, ...paths }\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { TResetPwdMutation } from '../../graphQL/schema/mutations/resetPwd.mjs';
2
+ import { TUpdatePasswordMutation } from '../../graphQL/schema/mutations/updatePassword.mjs';
3
+ import { IResetPwdPaths, TAccessModel } from './accessPaths.mjs';
4
+ /** What the factory needs: the account model, plus any path that differs from the default layout. */
5
+ export interface ICreateResetPwdFlowArgs {
6
+ model: TAccessModel;
7
+ paths?: Partial<IResetPwdPaths>;
8
+ }
9
+ /** The two mutations the flow exposes, bound to the model and paths passed in. */
10
+ export interface IResetPwdFlow {
11
+ resetPwd: TResetPwdMutation;
12
+ updatePassword: TUpdatePasswordMutation;
13
+ }
14
+ /**
15
+ * Build the password-reset mutations against any mongoose model.
16
+ *
17
+ * The package's own `resetPwd` / `updatePassword` exports are this factory applied to `UserBase` with
18
+ * `DEFAULT_RESET_PWD_PATHS`, so switching to it changes nothing until a path is overridden.
19
+ *
20
+ * Every key of `paths` is optional and falls back to the default layout. `resetClear` is the one to
21
+ * look at twice: it is the list of paths the cleanup `$unset`s, and it is NOT derived from
22
+ * `resetDateReq` + `resetHash`. A schema storing the request as one required-members subdocument under
23
+ * `validationLevel: 'strict'` is left invalid by unsetting a single member, and the write is rejected —
24
+ * such a schema must pass the container path instead. See `IResetPwdPaths.resetClear`.
25
+ *
26
+ * ```ts
27
+ * const { resetPwd, updatePassword } = createResetPwdFlow({
28
+ * model: Account,
29
+ * paths: { email: 'mail', password: 'pwd', name: 'profile.fullName', resetClear: ['resetPwd'] }
30
+ * })
31
+ * ```
32
+ */
33
+ export declare const createResetPwdFlow: ({ model, paths }: ICreateResetPwdFlowArgs) => IResetPwdFlow;
@@ -0,0 +1,42 @@
1
+ import { createGetResetPwd } from "../../private/lib/access/db/getResetPwd.mjs";
2
+ import { createRemoveResetReq } from "../../private/lib/access/db/removeResetReq.mjs";
3
+ import { createSaveResetReq } from "../../private/lib/access/db/saveResetReq.mjs";
4
+ import { createUpdatePasswordDb } from "../../private/lib/access/db/updatePasswordDb.mjs";
5
+ import { createResetPwdMutation } from '../../graphQL/schema/mutations/resetPwd.mjs';
6
+ import { createUpdatePasswordMutation } from '../../graphQL/schema/mutations/updatePassword.mjs';
7
+ import { resolveResetPwdPaths } from './accessPaths.mjs';
8
+ /**
9
+ * Build the password-reset mutations against any mongoose model.
10
+ *
11
+ * The package's own `resetPwd` / `updatePassword` exports are this factory applied to `UserBase` with
12
+ * `DEFAULT_RESET_PWD_PATHS`, so switching to it changes nothing until a path is overridden.
13
+ *
14
+ * Every key of `paths` is optional and falls back to the default layout. `resetClear` is the one to
15
+ * look at twice: it is the list of paths the cleanup `$unset`s, and it is NOT derived from
16
+ * `resetDateReq` + `resetHash`. A schema storing the request as one required-members subdocument under
17
+ * `validationLevel: 'strict'` is left invalid by unsetting a single member, and the write is rejected —
18
+ * such a schema must pass the container path instead. See `IResetPwdPaths.resetClear`.
19
+ *
20
+ * ```ts
21
+ * const { resetPwd, updatePassword } = createResetPwdFlow({
22
+ * model: Account,
23
+ * paths: { email: 'mail', password: 'pwd', name: 'profile.fullName', resetClear: ['resetPwd'] }
24
+ * })
25
+ * ```
26
+ */
27
+ export const createResetPwdFlow = ({ model, paths }) => {
28
+ const resolved = resolveResetPwdPaths(paths);
29
+ const getResetPwd = createGetResetPwd(model, resolved);
30
+ return {
31
+ resetPwd: createResetPwdMutation({
32
+ getResetPwd,
33
+ saveResetReq: createSaveResetReq(model, resolved)
34
+ }),
35
+ updatePassword: createUpdatePasswordMutation({
36
+ getResetPwd,
37
+ updatePasswordDb: createUpdatePasswordDb(model, resolved),
38
+ removeResetReq: createRemoveResetReq(model, resolved)
39
+ })
40
+ };
41
+ };
42
+ //# sourceMappingURL=createResetPwdFlow.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createResetPwdFlow.mjs","sourceRoot":"","sources":["../../../src/lib/access/createResetPwdFlow.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,oDAA8C;AAC1E,OAAO,EAAE,oBAAoB,EAAE,uDAAiD;AAChF,OAAO,EAAE,kBAAkB,EAAE,qDAA+C;AAC5E,OAAO,EAAE,sBAAsB,EAAE,yDAAmD;AAEpF,OAAO,EAAE,sBAAsB,EAAqB,MAAM,6CAA6C,CAAA;AACvG,OAAO,EAAE,4BAA4B,EAA2B,MAAM,mDAAmD,CAAA;AACzH,OAAO,EAAkB,oBAAoB,EAAgB,MAAM,mBAAmB,CAAA;AActF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAA2B,EAAiB,EAAE;IAC9F,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAE5C,MAAM,WAAW,GAAG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAEtD,OAAO;QACN,QAAQ,EAAE,sBAAsB,CAAC;YAChC,WAAW;YACX,YAAY,EAAE,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC;SACjD,CAAC;QACF,cAAc,EAAE,4BAA4B,CAAC;YAC5C,WAAW;YACX,gBAAgB,EAAE,sBAAsB,CAAC,KAAK,EAAE,QAAQ,CAAC;YACzD,cAAc,EAAE,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC;SACrD,CAAC;KACF,CAAA;AACF,CAAC,CAAA","sourcesContent":["import { createGetResetPwd } from '@private/lib/access/db/getResetPwd.mjs'\nimport { createRemoveResetReq } from '@private/lib/access/db/removeResetReq.mjs'\nimport { createSaveResetReq } from '@private/lib/access/db/saveResetReq.mjs'\nimport { createUpdatePasswordDb } from '@private/lib/access/db/updatePasswordDb.mjs'\n\nimport { createResetPwdMutation, TResetPwdMutation } from '../../graphQL/schema/mutations/resetPwd.mjs'\nimport { createUpdatePasswordMutation, TUpdatePasswordMutation } from '../../graphQL/schema/mutations/updatePassword.mjs'\nimport { IResetPwdPaths, resolveResetPwdPaths, TAccessModel } from './accessPaths.mjs'\n\n/** What the factory needs: the account model, plus any path that differs from the default layout. */\nexport interface ICreateResetPwdFlowArgs {\n\tmodel: TAccessModel\n\tpaths?: Partial<IResetPwdPaths>\n}\n\n/** The two mutations the flow exposes, bound to the model and paths passed in. */\nexport interface IResetPwdFlow {\n\tresetPwd: TResetPwdMutation\n\tupdatePassword: TUpdatePasswordMutation\n}\n\n/**\n * Build the password-reset mutations against any mongoose model.\n *\n * The package's own `resetPwd` / `updatePassword` exports are this factory applied to `UserBase` with\n * `DEFAULT_RESET_PWD_PATHS`, so switching to it changes nothing until a path is overridden.\n *\n * Every key of `paths` is optional and falls back to the default layout. `resetClear` is the one to\n * look at twice: it is the list of paths the cleanup `$unset`s, and it is NOT derived from\n * `resetDateReq` + `resetHash`. A schema storing the request as one required-members subdocument under\n * `validationLevel: 'strict'` is left invalid by unsetting a single member, and the write is rejected —\n * such a schema must pass the container path instead. See `IResetPwdPaths.resetClear`.\n *\n * ```ts\n * const { resetPwd, updatePassword } = createResetPwdFlow({\n * model: Account,\n * paths: { email: 'mail', password: 'pwd', name: 'profile.fullName', resetClear: ['resetPwd'] }\n * })\n * ```\n */\nexport const createResetPwdFlow = ({ model, paths }: ICreateResetPwdFlowArgs): IResetPwdFlow => {\n\tconst resolved = resolveResetPwdPaths(paths)\n\n\tconst getResetPwd = createGetResetPwd(model, resolved)\n\n\treturn {\n\t\tresetPwd: createResetPwdMutation({\n\t\t\tgetResetPwd,\n\t\t\tsaveResetReq: createSaveResetReq(model, resolved)\n\t\t}),\n\t\tupdatePassword: createUpdatePasswordMutation({\n\t\t\tgetResetPwd,\n\t\t\tupdatePasswordDb: createUpdatePasswordDb(model, resolved),\n\t\t\tremoveResetReq: createRemoveResetReq(model, resolved)\n\t\t})\n\t}\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import { TAssertVerifyEmailAllowed } from "../../private/lib/access/assertVerifyEmailAllowed.mjs";
2
+ import { TConfirmNewEmail } from "../../private/lib/access/db/confirmNewEmail.mjs";
3
+ import { TDeleteUserByEmail } from "../../private/lib/access/db/deleteUserByEmail.mjs";
4
+ import { TEnableEmailAccess } from "../../private/lib/access/db/enableEmailAccess.mjs";
5
+ import { TIncReqTimes } from "../../private/lib/access/db/incReqTimes.mjs";
6
+ import { TSetEmailHash } from "../../private/lib/access/db/setEmailHash.mjs";
7
+ import { TUserData4VerifyEmail } from "../../private/lib/access/db/userData4VerifyEmail.mjs";
8
+ import { TEmailChangeHashVerifyMutation } from '../../graphQL/schema/mutations/emailChangeHashVerify.mjs';
9
+ import { TVerifyEmailRouter } from '../../koa/router/verifyEmail.mjs';
10
+ import { IVerifyEmailPaths, TAccessModel } from './accessPaths.mjs';
11
+ /** What the factory needs: the account model, plus any path that differs from the default layout. */
12
+ export interface ICreateVerifyEmailFlowArgs {
13
+ model: TAccessModel;
14
+ paths?: Partial<IVerifyEmailPaths>;
15
+ }
16
+ /** Everything the verify-email chain exposes, bound to the model and paths passed in. */
17
+ export interface IVerifyEmailFlow {
18
+ userData4VerifyEmail: TUserData4VerifyEmail;
19
+ setEmailHash: TSetEmailHash;
20
+ enableEmailAccess: TEnableEmailAccess;
21
+ confirmNewEmail: TConfirmNewEmail;
22
+ deleteUserByEmail: TDeleteUserByEmail;
23
+ incReqTimes: TIncReqTimes;
24
+ assertVerifyEmailAllowed: TAssertVerifyEmailAllowed;
25
+ emailChangeHashVerify: TEmailChangeHashVerifyMutation;
26
+ routerVerifyEmail: TVerifyEmailRouter;
27
+ }
28
+ /**
29
+ * Build the whole email-verification chain against any mongoose model.
30
+ *
31
+ * The package's own exports (`userData4VerifyEmail`, `setEmailHash`, `enableEmailAccess`,
32
+ * `confirmNewEmail`, `emailChangeHashVerify`, `routerVerifyEmail`) are this factory applied to
33
+ * `UserBase` with `DEFAULT_VERIFY_EMAIL_PATHS`, so switching to it changes nothing until a path is
34
+ * overridden.
35
+ *
36
+ * The two `*Clear` keys are lists of paths to `$unset`, and neither is derived from the leaf paths the
37
+ * flow reads: a schema storing the verification state as one required-members subdocument is left
38
+ * invalid by unsetting a single member. Pass the container path in that case. See `IVerifyEmailPaths`.
39
+ *
40
+ * ```ts
41
+ * const flow = createVerifyEmailFlow({
42
+ * model: Account,
43
+ * paths: { email: 'mail', valid: 'verified', verifyClear: ['verification'] }
44
+ * })
45
+ * router.get('/check/verify-email/:email/:hash', flow.routerVerifyEmail())
46
+ * ```
47
+ */
48
+ export declare const createVerifyEmailFlow: ({ model, paths }: ICreateVerifyEmailFlowArgs) => IVerifyEmailFlow;
@@ -0,0 +1,68 @@
1
+ import { createAssertVerifyEmailAllowed } from "../../private/lib/access/assertVerifyEmailAllowed.mjs";
2
+ import { createConfirmNewEmail } from "../../private/lib/access/db/confirmNewEmail.mjs";
3
+ import { createDeleteUserByEmail } from "../../private/lib/access/db/deleteUserByEmail.mjs";
4
+ import { createEnableEmailAccess } from "../../private/lib/access/db/enableEmailAccess.mjs";
5
+ import { createIncReqTimes } from "../../private/lib/access/db/incReqTimes.mjs";
6
+ import { createSetEmailHash } from "../../private/lib/access/db/setEmailHash.mjs";
7
+ import { createUserData4VerifyEmail } from "../../private/lib/access/db/userData4VerifyEmail.mjs";
8
+ import { createHandleIfHashBad } from "../../private/lib/access/handleIfHashBad.mjs";
9
+ import { createHandleIfMoreThan3DaysPassed } from "../../private/lib/access/handleIfMoreThan3DaysPassed.mjs";
10
+ import { createHandleIfTooMuchRequestsTimes } from "../../private/lib/access/handleIfTooMuchRequestsTimes.mjs";
11
+ import { createEmailChangeHashVerifyMutation } from '../../graphQL/schema/mutations/emailChangeHashVerify.mjs';
12
+ import { createVerifyEmailRouter } from '../../koa/router/verifyEmail.mjs';
13
+ import { resolveVerifyEmailPaths } from './accessPaths.mjs';
14
+ /**
15
+ * Build the whole email-verification chain against any mongoose model.
16
+ *
17
+ * The package's own exports (`userData4VerifyEmail`, `setEmailHash`, `enableEmailAccess`,
18
+ * `confirmNewEmail`, `emailChangeHashVerify`, `routerVerifyEmail`) are this factory applied to
19
+ * `UserBase` with `DEFAULT_VERIFY_EMAIL_PATHS`, so switching to it changes nothing until a path is
20
+ * overridden.
21
+ *
22
+ * The two `*Clear` keys are lists of paths to `$unset`, and neither is derived from the leaf paths the
23
+ * flow reads: a schema storing the verification state as one required-members subdocument is left
24
+ * invalid by unsetting a single member. Pass the container path in that case. See `IVerifyEmailPaths`.
25
+ *
26
+ * ```ts
27
+ * const flow = createVerifyEmailFlow({
28
+ * model: Account,
29
+ * paths: { email: 'mail', valid: 'verified', verifyClear: ['verification'] }
30
+ * })
31
+ * router.get('/check/verify-email/:email/:hash', flow.routerVerifyEmail())
32
+ * ```
33
+ */
34
+ export const createVerifyEmailFlow = ({ model, paths }) => {
35
+ const resolved = resolveVerifyEmailPaths(paths);
36
+ const userData4VerifyEmail = createUserData4VerifyEmail(model, resolved);
37
+ const enableEmailAccess = createEnableEmailAccess(model, resolved);
38
+ const confirmNewEmail = createConfirmNewEmail(model, resolved);
39
+ const deleteUserByEmail = createDeleteUserByEmail(model, resolved);
40
+ const incReqTimes = createIncReqTimes(model, resolved);
41
+ const assertVerifyEmailAllowed = createAssertVerifyEmailAllowed({
42
+ paths: resolved,
43
+ handleIfHashBad: createHandleIfHashBad(incReqTimes),
44
+ handleIfMoreThan3DaysPassed: createHandleIfMoreThan3DaysPassed(deleteUserByEmail),
45
+ handleIfTooMuchRequestsTimes: createHandleIfTooMuchRequestsTimes(deleteUserByEmail)
46
+ });
47
+ return {
48
+ userData4VerifyEmail,
49
+ setEmailHash: createSetEmailHash(model, resolved),
50
+ enableEmailAccess,
51
+ confirmNewEmail,
52
+ deleteUserByEmail,
53
+ incReqTimes,
54
+ assertVerifyEmailAllowed,
55
+ emailChangeHashVerify: createEmailChangeHashVerifyMutation({
56
+ model,
57
+ paths: resolved,
58
+ confirmNewEmail,
59
+ incReqTimes
60
+ }),
61
+ routerVerifyEmail: createVerifyEmailRouter({
62
+ userData4VerifyEmail,
63
+ assertVerifyEmailAllowed,
64
+ enableEmailAccess
65
+ })
66
+ };
67
+ };
68
+ //# sourceMappingURL=createVerifyEmailFlow.mjs.map
@@ -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;