@axiumine/koa-utils 5.6.0 → 5.7.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 (51) hide show
  1. package/README.md +10 -1
  2. package/dist/files/uploadTempImage.mjs +1 -0
  3. package/dist/files/uploadTempImage.mjs.map +1 -1
  4. package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +7 -0
  5. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +38 -35
  6. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
  7. package/dist/lib/access/accessPaths.d.mts +18 -0
  8. package/dist/lib/access/accessPaths.mjs.map +1 -1
  9. package/dist/lib/access/createMailThrottle.d.mts +34 -0
  10. package/dist/lib/access/createMailThrottle.mjs +45 -0
  11. package/dist/lib/access/createMailThrottle.mjs.map +1 -0
  12. package/dist/lib/access/createVerifyEmailFlow.d.mts +37 -4
  13. package/dist/lib/access/createVerifyEmailFlow.mjs +33 -10
  14. package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -1
  15. package/dist/lib/access/verifyEmailMailer.d.mts +54 -0
  16. package/dist/lib/access/verifyEmailMailer.mjs +48 -0
  17. package/dist/lib/access/verifyEmailMailer.mjs.map +1 -0
  18. package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +13 -1
  19. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +7 -4
  20. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
  21. package/dist/private/lib/access/db/abandonUser.d.mts +25 -0
  22. package/dist/private/lib/access/db/abandonUser.mjs +26 -0
  23. package/dist/private/lib/access/db/abandonUser.mjs.map +1 -0
  24. package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -0
  25. package/dist/private/lib/access/db/deleteUserByEmail.mjs +15 -4
  26. package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
  27. package/dist/private/lib/access/db/enableEmailAccess.d.mts +9 -1
  28. package/dist/private/lib/access/db/enableEmailAccess.mjs +11 -5
  29. package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
  30. package/dist/private/lib/access/handleBadDB.d.mts +11 -0
  31. package/dist/private/lib/access/handleBadDB.mjs +13 -1
  32. package/dist/private/lib/access/handleBadDB.mjs.map +1 -1
  33. package/dist/private/lib/access/handleIfAccountDeleted.d.mts +16 -1
  34. package/dist/private/lib/access/handleIfAccountDeleted.mjs +16 -5
  35. package/dist/private/lib/access/handleIfAccountDeleted.mjs.map +1 -1
  36. package/dist/private/lib/access/handleIfAccountDisabled.d.mts +15 -1
  37. package/dist/private/lib/access/handleIfAccountDisabled.mjs +15 -5
  38. package/dist/private/lib/access/handleIfAccountDisabled.mjs.map +1 -1
  39. package/dist/private/lib/access/handleIfEmailAlreadyValid.d.mts +18 -1
  40. package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs +18 -5
  41. package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs.map +1 -1
  42. package/dist/private/lib/access/handleIfHashBad.d.mts +5 -1
  43. package/dist/private/lib/access/handleIfHashBad.mjs +7 -5
  44. package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
  45. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +8 -4
  46. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +10 -8
  47. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
  48. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +7 -4
  49. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +9 -8
  50. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
  51. package/package.json +9 -1
@@ -0,0 +1,54 @@
1
+ import { TMailThrottle } from './createMailThrottle.mjs';
2
+ /**
3
+ * Every notification the email-verification chain sends.
4
+ *
5
+ * Each guard used to construct its own `SocketLabsLib` inline, which made no branch of the chain drivable
6
+ * from an integration suite: with real credentials in `.env` the only two paths reachable without mailing
7
+ * a real person were "address not found" and the bad-DB guard. Everything else was unit-tests-with-mocks
8
+ * only — including the success path, since `enableEmailAccess` sent the welcome mail itself.
9
+ *
10
+ * Structural, not nominal: any object carrying these six methods satisfies it, `SocketLabsLib` included.
11
+ * `sendWelcome` is the only one not reachable unauthenticated, and the only one the debounce leaves alone.
12
+ */
13
+ export interface IVerifyEmailMailer {
14
+ /** The address is already verified. No counter guards this branch — see {@link createMailThrottle}. */
15
+ emailAlreadyValid(email: string): Promise<unknown>;
16
+ /** The hash in the link does not match the stored one. `times` is the strike this attempt makes. */
17
+ wrongHash(email: string, times: number): Promise<unknown>;
18
+ /** The strike counter reached 5. */
19
+ tooMuchVerifyRequests(email: string): Promise<unknown>;
20
+ /** The link is older than the 3-day window. */
21
+ hashReqTooOld(email: string): Promise<unknown>;
22
+ /** The account is disabled — or deleted: there is no `accountDeleted` template, so both guards send this one. */
23
+ accountDisabled(email: string): Promise<unknown>;
24
+ /** The account has just been activated. Success path only, so never debounced. */
25
+ sendWelcome(email: string): Promise<unknown>;
26
+ }
27
+ /**
28
+ * SocketLabs, constructed per call exactly as the guards did inline.
29
+ *
30
+ * Per call rather than once at module load because the constructor reads `process.env` (server id, API key,
31
+ * platform name, domain, sender) and builds a client from it — hoisting that to import time would pin
32
+ * whatever the environment held when the module was first resolved.
33
+ */
34
+ export declare const socketLabsVerifyEmailMailer: IVerifyEmailMailer;
35
+ /**
36
+ * Wrap a mailer so each guard notification is asked of `throttle` first, keyed `<method>:<address>`.
37
+ *
38
+ * A dropped send resolves `undefined` and is invisible to the caller: the guard still throws, so the
39
+ * request still gets the same redirect it always did. Only the mail is suppressed.
40
+ *
41
+ * `sendWelcome` passes straight through. It fires once, on the success path, at the moment the account is
42
+ * activated — debouncing it could silently swallow the welcome mail of an address that re-registered
43
+ * inside the window, and no unauthenticated caller can trigger it twice anyway (the second request meets
44
+ * `handleIfEmailAlreadyValid`).
45
+ */
46
+ export declare const throttleMailer: (mailer: IVerifyEmailMailer, throttle: TMailThrottle) => IVerifyEmailMailer;
47
+ /**
48
+ * What the `UserBase`-bound guard exports mail through: SocketLabs, debounced on the default window.
49
+ *
50
+ * One shared throttle for the whole process, because these bindings are one shared chain — the
51
+ * `routerVerifyEmail` export every existing consumer imports. `createVerifyEmailFlow` does not use this
52
+ * value; it builds its own mailer and its own throttle per flow.
53
+ */
54
+ export declare const defaultVerifyEmailMailer: IVerifyEmailMailer;
@@ -0,0 +1,48 @@
1
+ import { SocketLabsLib } from "../../email/SocketLabsLib.mjs";
2
+ import { createMailThrottle } from './createMailThrottle.mjs';
3
+ /**
4
+ * SocketLabs, constructed per call exactly as the guards did inline.
5
+ *
6
+ * Per call rather than once at module load because the constructor reads `process.env` (server id, API key,
7
+ * platform name, domain, sender) and builds a client from it — hoisting that to import time would pin
8
+ * whatever the environment held when the module was first resolved.
9
+ */
10
+ export const socketLabsVerifyEmailMailer = {
11
+ emailAlreadyValid: (email) => new SocketLabsLib().emailAlreadyValid(email),
12
+ wrongHash: (email, times) => new SocketLabsLib().wrongHash(email, times),
13
+ tooMuchVerifyRequests: (email) => new SocketLabsLib().tooMuchVerifyRequests(email),
14
+ hashReqTooOld: (email) => new SocketLabsLib().hashReqTooOld(email),
15
+ accountDisabled: (email) => new SocketLabsLib().accountDisabled(email),
16
+ sendWelcome: (email) => new SocketLabsLib().sendWelcome(email)
17
+ };
18
+ /**
19
+ * Wrap a mailer so each guard notification is asked of `throttle` first, keyed `<method>:<address>`.
20
+ *
21
+ * A dropped send resolves `undefined` and is invisible to the caller: the guard still throws, so the
22
+ * request still gets the same redirect it always did. Only the mail is suppressed.
23
+ *
24
+ * `sendWelcome` passes straight through. It fires once, on the success path, at the moment the account is
25
+ * activated — debouncing it could silently swallow the welcome mail of an address that re-registered
26
+ * inside the window, and no unauthenticated caller can trigger it twice anyway (the second request meets
27
+ * `handleIfEmailAlreadyValid`).
28
+ */
29
+ export const throttleMailer = (mailer, throttle) => {
30
+ const gated = async (kind, email, deliver) => (await throttle(`${kind}:${email}`)) ? deliver() : undefined;
31
+ return {
32
+ emailAlreadyValid: (email) => gated('emailAlreadyValid', email, () => mailer.emailAlreadyValid(email)),
33
+ wrongHash: (email, times) => gated('wrongHash', email, () => mailer.wrongHash(email, times)),
34
+ tooMuchVerifyRequests: (email) => gated('tooMuchVerifyRequests', email, () => mailer.tooMuchVerifyRequests(email)),
35
+ hashReqTooOld: (email) => gated('hashReqTooOld', email, () => mailer.hashReqTooOld(email)),
36
+ accountDisabled: (email) => gated('accountDisabled', email, () => mailer.accountDisabled(email)),
37
+ sendWelcome: (email) => mailer.sendWelcome(email)
38
+ };
39
+ };
40
+ /**
41
+ * What the `UserBase`-bound guard exports mail through: SocketLabs, debounced on the default window.
42
+ *
43
+ * One shared throttle for the whole process, because these bindings are one shared chain — the
44
+ * `routerVerifyEmail` export every existing consumer imports. `createVerifyEmailFlow` does not use this
45
+ * value; it builds its own mailer and its own throttle per flow.
46
+ */
47
+ export const defaultVerifyEmailMailer = throttleMailer(socketLabsVerifyEmailMailer, createMailThrottle());
48
+ //# sourceMappingURL=verifyEmailMailer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyEmailMailer.mjs","sourceRoot":"","sources":["../../../src/lib/access/verifyEmailMailer.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,sCAAgC;AAExD,OAAO,EAAE,kBAAkB,EAAiB,MAAM,0BAA0B,CAAA;AA4B5E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAuB;IAC9D,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC;IAC1E,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACxE,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,qBAAqB,CAAC,KAAK,CAAC;IAClF,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;IAClE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;IACtE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,aAAa,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;CAC9D,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAA0B,EAAE,QAAuB,EAAsB,EAAE;IACzG,MAAM,KAAK,GAAG,KAAK,EAAE,IAAY,EAAE,KAAa,EAAE,OAA+B,EAAoB,EAAE,CACtG,CAAC,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;IAE7D,OAAO;QACN,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACtG,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5F,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAClH,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1F,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAChG,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC;KACjD,CAAA;AACF,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAuB,cAAc,CAAC,2BAA2B,EAAE,kBAAkB,EAAE,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { createMailThrottle, TMailThrottle } from './createMailThrottle.mjs'\n\n/**\n * Every notification the email-verification chain sends.\n *\n * Each guard used to construct its own `SocketLabsLib` inline, which made no branch of the chain drivable\n * from an integration suite: with real credentials in `.env` the only two paths reachable without mailing\n * a real person were \"address not found\" and the bad-DB guard. Everything else was unit-tests-with-mocks\n * only — including the success path, since `enableEmailAccess` sent the welcome mail itself.\n *\n * Structural, not nominal: any object carrying these six methods satisfies it, `SocketLabsLib` included.\n * `sendWelcome` is the only one not reachable unauthenticated, and the only one the debounce leaves alone.\n */\nexport interface IVerifyEmailMailer {\n\t/** The address is already verified. No counter guards this branch — see {@link createMailThrottle}. */\n\temailAlreadyValid(email: string): Promise<unknown>\n\t/** The hash in the link does not match the stored one. `times` is the strike this attempt makes. */\n\twrongHash(email: string, times: number): Promise<unknown>\n\t/** The strike counter reached 5. */\n\ttooMuchVerifyRequests(email: string): Promise<unknown>\n\t/** The link is older than the 3-day window. */\n\thashReqTooOld(email: string): Promise<unknown>\n\t/** The account is disabled — or deleted: there is no `accountDeleted` template, so both guards send this one. */\n\taccountDisabled(email: string): Promise<unknown>\n\t/** The account has just been activated. Success path only, so never debounced. */\n\tsendWelcome(email: string): Promise<unknown>\n}\n\n/**\n * SocketLabs, constructed per call exactly as the guards did inline.\n *\n * Per call rather than once at module load because the constructor reads `process.env` (server id, API key,\n * platform name, domain, sender) and builds a client from it — hoisting that to import time would pin\n * whatever the environment held when the module was first resolved.\n */\nexport const socketLabsVerifyEmailMailer: IVerifyEmailMailer = {\n\temailAlreadyValid: (email) => new SocketLabsLib().emailAlreadyValid(email),\n\twrongHash: (email, times) => new SocketLabsLib().wrongHash(email, times),\n\ttooMuchVerifyRequests: (email) => new SocketLabsLib().tooMuchVerifyRequests(email),\n\thashReqTooOld: (email) => new SocketLabsLib().hashReqTooOld(email),\n\taccountDisabled: (email) => new SocketLabsLib().accountDisabled(email),\n\tsendWelcome: (email) => new SocketLabsLib().sendWelcome(email)\n}\n\n/**\n * Wrap a mailer so each guard notification is asked of `throttle` first, keyed `<method>:<address>`.\n *\n * A dropped send resolves `undefined` and is invisible to the caller: the guard still throws, so the\n * request still gets the same redirect it always did. Only the mail is suppressed.\n *\n * `sendWelcome` passes straight through. It fires once, on the success path, at the moment the account is\n * activated — debouncing it could silently swallow the welcome mail of an address that re-registered\n * inside the window, and no unauthenticated caller can trigger it twice anyway (the second request meets\n * `handleIfEmailAlreadyValid`).\n */\nexport const throttleMailer = (mailer: IVerifyEmailMailer, throttle: TMailThrottle): IVerifyEmailMailer => {\n\tconst gated = async (kind: string, email: string, deliver: () => Promise<unknown>): Promise<unknown> =>\n\t\t(await throttle(`${kind}:${email}`)) ? deliver() : undefined\n\n\treturn {\n\t\temailAlreadyValid: (email) => gated('emailAlreadyValid', email, () => mailer.emailAlreadyValid(email)),\n\t\twrongHash: (email, times) => gated('wrongHash', email, () => mailer.wrongHash(email, times)),\n\t\ttooMuchVerifyRequests: (email) => gated('tooMuchVerifyRequests', email, () => mailer.tooMuchVerifyRequests(email)),\n\t\thashReqTooOld: (email) => gated('hashReqTooOld', email, () => mailer.hashReqTooOld(email)),\n\t\taccountDisabled: (email) => gated('accountDisabled', email, () => mailer.accountDisabled(email)),\n\t\tsendWelcome: (email) => mailer.sendWelcome(email)\n\t}\n}\n\n/**\n * What the `UserBase`-bound guard exports mail through: SocketLabs, debounced on the default window.\n *\n * One shared throttle for the whole process, because these bindings are one shared chain — the\n * `routerVerifyEmail` export every existing consumer imports. `createVerifyEmailFlow` does not use this\n * value; it builds its own mailer and its own throttle per flow.\n */\nexport const defaultVerifyEmailMailer: IVerifyEmailMailer = throttleMailer(socketLabsVerifyEmailMailer, createMailThrottle())\n"]}
@@ -1,5 +1,8 @@
1
1
  import { IVerifyEmailPaths } from "../../../lib/access/accessPaths.mjs";
2
2
  import { Types } from 'mongoose';
3
+ import { THandleIfAccountDeleted } from './handleIfAccountDeleted.mjs';
4
+ import { THandleIfAccountDisabled } from './handleIfAccountDisabled.mjs';
5
+ import { THandleIfEmailAlreadyValid } from './handleIfEmailAlreadyValid.mjs';
3
6
  import { THandleIfHashBad } from './handleIfHashBad.mjs';
4
7
  import { THandleIfMoreThan3DaysPassed } from './handleIfMoreThan3DaysPassed.mjs';
5
8
  import { THandleIfTooMuchRequestsTimes } from './handleIfTooMuchRequestsTimes.mjs';
@@ -17,12 +20,21 @@ export interface IVerifyEmailUser {
17
20
  disabled?: boolean;
18
21
  };
19
22
  }
20
- /** Collaborators the chain needs, all bound to the same model + paths by the caller. */
23
+ /**
24
+ * Collaborators the chain needs, all bound to the same model + paths by the caller.
25
+ *
26
+ * The three mail-only guards are here for the same reason the writer-backed ones are: hard-importing them
27
+ * meant the mailer they use was fixed at module load, so no caller could reach these branches without a real
28
+ * SocketLabs send. `handleBadDB` stays a direct import — it writes nothing and mails nobody.
29
+ */
21
30
  export interface IAssertVerifyEmailAllowedDeps {
22
31
  paths: IVerifyEmailPaths;
32
+ handleIfEmailAlreadyValid: THandleIfEmailAlreadyValid;
23
33
  handleIfHashBad: THandleIfHashBad;
24
34
  handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed;
25
35
  handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes;
36
+ handleIfAccountDeleted: THandleIfAccountDeleted;
37
+ handleIfAccountDisabled: THandleIfAccountDisabled;
26
38
  }
27
39
  /**
28
40
  * Run every guard that must pass before an email-verification link is honoured, in order.
@@ -37,7 +37,7 @@ export const createAssertVerifyEmailAllowed = (deps) => async function assertVer
37
37
  const dateLastReq = readPath(user, paths.dateLastReq);
38
38
  const deleted = readPath(user, paths.deleted);
39
39
  const disabled = readPath(user, paths.disabled);
40
- await handleIfEmailAlreadyValid(email, readPath(user, paths.valid));
40
+ await deps.handleIfEmailAlreadyValid(email, readPath(user, paths.valid));
41
41
  handleBadDB(requestTimes, dateLastReq);
42
42
  await deps.handleIfTooMuchRequestsTimes(email, requestTimes);
43
43
  // dbHash is the value STORED for this account — never the one supplied in the URL
@@ -53,15 +53,18 @@ export const createAssertVerifyEmailAllowed = (deps) => async function assertVer
53
53
  // and these are exactly what the driver found — which is only ever a boolean once
54
54
  // scripts/migrate-account-disabled-to-boolean.mjs has run. On un-migrated data a stored 'false'
55
55
  // is a truthy string and blocks the account; the fix is the migration, not a coercion here.
56
- await handleIfAccountDeleted(email, deleted);
57
- await handleIfAccountDisabled(email, disabled);
56
+ await deps.handleIfAccountDeleted(email, deleted);
57
+ await deps.handleIfAccountDisabled(email, disabled);
58
58
  return uId;
59
59
  };
60
60
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
61
61
  export const assertVerifyEmailAllowed = createAssertVerifyEmailAllowed({
62
62
  paths: DEFAULT_VERIFY_EMAIL_PATHS,
63
+ handleIfEmailAlreadyValid,
63
64
  handleIfHashBad,
64
65
  handleIfMoreThan3DaysPassed,
65
- handleIfTooMuchRequestsTimes
66
+ handleIfTooMuchRequestsTimes,
67
+ handleIfAccountDeleted,
68
+ handleIfAccountDisabled
66
69
  });
67
70
  //# sourceMappingURL=assertVerifyEmailAllowed.mjs.map
@@ -1 +1 @@
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
+ {"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,EAA2B,MAAM,8BAA8B,CAAA;AAC9F,OAAO,EAAE,uBAAuB,EAA4B,MAAM,+BAA+B,CAAA;AACjG,OAAO,EAAE,yBAAyB,EAA8B,MAAM,iCAAiC,CAAA;AACvG,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;AAkC1C;;;;;;;;;;;;;;;;;;;;;;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,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAY,CAAC,CAAA;IACnF,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,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACjD,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAEnD,OAAO,GAAG,CAAA;AACX,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,wBAAwB,GAA8B,8BAA8B,CAAC;IACjG,KAAK,EAAE,0BAA0B;IACjC,yBAAyB;IACzB,eAAe;IACf,2BAA2B;IAC3B,4BAA4B;IAC5B,sBAAsB;IACtB,uBAAuB;CACvB,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, THandleIfAccountDeleted } from './handleIfAccountDeleted.mjs'\nimport { handleIfAccountDisabled, THandleIfAccountDisabled } from './handleIfAccountDisabled.mjs'\nimport { handleIfEmailAlreadyValid, THandleIfEmailAlreadyValid } 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/**\n * Collaborators the chain needs, all bound to the same model + paths by the caller.\n *\n * The three mail-only guards are here for the same reason the writer-backed ones are: hard-importing them\n * meant the mailer they use was fixed at module load, so no caller could reach these branches without a real\n * SocketLabs send. `handleBadDB` stays a direct import — it writes nothing and mails nobody.\n */\nexport interface IAssertVerifyEmailAllowedDeps {\n\tpaths: IVerifyEmailPaths\n\thandleIfEmailAlreadyValid: THandleIfEmailAlreadyValid\n\thandleIfHashBad: THandleIfHashBad\n\thandleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed\n\thandleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes\n\thandleIfAccountDeleted: THandleIfAccountDeleted\n\thandleIfAccountDisabled: THandleIfAccountDisabled\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 deps.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 deps.handleIfAccountDeleted(email, deleted)\n\t\tawait deps.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\thandleIfEmailAlreadyValid,\n\thandleIfHashBad,\n\thandleIfMoreThan3DaysPassed,\n\thandleIfTooMuchRequestsTimes,\n\thandleIfAccountDeleted,\n\thandleIfAccountDisabled\n})\n"]}
@@ -0,0 +1,25 @@
1
+ import { IVerifyEmailPaths, TAccessModel, TOnAbandon } from "../../../../lib/access/accessPaths.mjs";
2
+ import { TDeleteUserByEmail } from './deleteUserByEmail.mjs';
3
+ /** Model, field map and disposal policy for {@link createAbandonUser}. */
4
+ export interface ICreateAbandonUserArgs {
5
+ model: TAccessModel;
6
+ paths: IVerifyEmailPaths;
7
+ /** See {@link TOnAbandon}. */
8
+ mode: TOnAbandon;
9
+ /**
10
+ * Value `'soft-delete'` writes to `paths.deleted`. A function is called once per write, so a layout
11
+ * storing a timestamp passes `() => new Date()`.
12
+ *
13
+ * Default `true`, matching `UserBase`, where `account.deleted` is `type: Boolean`. Not hard-coded: the
14
+ * guards only test the flag for truthiness, so what belongs in the slot is the schema's business.
15
+ */
16
+ deletedValue?: unknown;
17
+ }
18
+ /**
19
+ * Build the writer the two abandonment guards call — `handleIfMoreThan3DaysPassed` (link older than 3 days)
20
+ * and `handleIfTooMuchRequestsTimes` (fifth wrong hash).
21
+ *
22
+ * All three modes share one signature, so the guards stay unaware of which policy they are running under.
23
+ * They throw either way: the mode decides what happens to the row, never whether the link is honoured.
24
+ */
25
+ export declare const createAbandonUser: ({ model, paths, mode, deletedValue }: ICreateAbandonUserArgs) => TDeleteUserByEmail;
@@ -0,0 +1,26 @@
1
+ import { createDeleteUserByEmail } from './deleteUserByEmail.mjs';
2
+ /**
3
+ * Build the writer the two abandonment guards call — `handleIfMoreThan3DaysPassed` (link older than 3 days)
4
+ * and `handleIfTooMuchRequestsTimes` (fifth wrong hash).
5
+ *
6
+ * All three modes share one signature, so the guards stay unaware of which policy they are running under.
7
+ * They throw either way: the mode decides what happens to the row, never whether the link is honoured.
8
+ */
9
+ export const createAbandonUser = ({ model, paths, mode, deletedValue = true }) => {
10
+ if (mode === 'keep') {
11
+ return async function keepUser() {
12
+ // Nothing to do: the caller disposes of abandoned registrations themselves.
13
+ return undefined;
14
+ };
15
+ }
16
+ if (mode === 'soft-delete') {
17
+ return async function softDeleteUserByEmail(email) {
18
+ const value = typeof deletedValue === 'function' ? deletedValue() : deletedValue;
19
+ // Only the tombstone is written. The verification fields are left as they are — the flag is what
20
+ // every guard reads, and unsetting members of a strict subdocument is what `verifyClear` exists for.
21
+ await model.updateOne({ [paths.email]: email }, { $set: { [paths.deleted]: value } }, { runValidators: true });
22
+ };
23
+ }
24
+ return createDeleteUserByEmail(model, paths);
25
+ };
26
+ //# sourceMappingURL=abandonUser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abandonUser.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/abandonUser.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAsB,MAAM,yBAAyB,CAAA;AAkBrF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,EAA0B,EAAsB,EAAE;IAC5H,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,KAAK,UAAU,QAAQ;YAC7B,4EAA4E;YAC5E,OAAO,SAAS,CAAA;QACjB,CAAC,CAAA;IACF,CAAC;IAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;QAC5B,OAAO,KAAK,UAAU,qBAAqB,CAAC,KAAa;YACxD,MAAM,KAAK,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAE,YAA8B,EAAE,CAAC,CAAC,CAAC,YAAY,CAAA;YAEnG,iGAAiG;YACjG,qGAAqG;YACrG,MAAM,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;QAC/G,CAAC,CAAA;IACF,CAAC;IAED,OAAO,uBAAuB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC7C,CAAC,CAAA","sourcesContent":["import { IVerifyEmailPaths, TAccessModel, TOnAbandon } from '@lib/access/accessPaths.mjs'\n\nimport { createDeleteUserByEmail, TDeleteUserByEmail } from './deleteUserByEmail.mjs'\n\n/** Model, field map and disposal policy for {@link createAbandonUser}. */\nexport interface ICreateAbandonUserArgs {\n\tmodel: TAccessModel\n\tpaths: IVerifyEmailPaths\n\t/** See {@link TOnAbandon}. */\n\tmode: TOnAbandon\n\t/**\n\t * Value `'soft-delete'` writes to `paths.deleted`. A function is called once per write, so a layout\n\t * storing a timestamp passes `() => new Date()`.\n\t *\n\t * Default `true`, matching `UserBase`, where `account.deleted` is `type: Boolean`. Not hard-coded: the\n\t * guards only test the flag for truthiness, so what belongs in the slot is the schema's business.\n\t */\n\tdeletedValue?: unknown\n}\n\n/**\n * Build the writer the two abandonment guards call — `handleIfMoreThan3DaysPassed` (link older than 3 days)\n * and `handleIfTooMuchRequestsTimes` (fifth wrong hash).\n *\n * All three modes share one signature, so the guards stay unaware of which policy they are running under.\n * They throw either way: the mode decides what happens to the row, never whether the link is honoured.\n */\nexport const createAbandonUser = ({ model, paths, mode, deletedValue = true }: ICreateAbandonUserArgs): TDeleteUserByEmail => {\n\tif (mode === 'keep') {\n\t\treturn async function keepUser(): Promise<void> {\n\t\t\t// Nothing to do: the caller disposes of abandoned registrations themselves.\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tif (mode === 'soft-delete') {\n\t\treturn async function softDeleteUserByEmail(email: string) {\n\t\t\tconst value = typeof deletedValue === 'function' ? (deletedValue as () => unknown)() : deletedValue\n\n\t\t\t// Only the tombstone is written. The verification fields are left as they are — the flag is what\n\t\t\t// every guard reads, and unsetting members of a strict subdocument is what `verifyClear` exists for.\n\t\t\tawait model.updateOne({ [paths.email]: email }, { $set: { [paths.deleted]: value } }, { runValidators: true })\n\t\t}\n\t}\n\n\treturn createDeleteUserByEmail(model, paths)\n}\n"]}
@@ -1,4 +1,11 @@
1
1
  import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
2
+ /**
3
+ * Hard delete of an abandoned pending registration, keyed by the login-email path.
4
+ *
5
+ * Reached through `createAbandonUser`, which is what decides whether abandonment means this, a tombstone
6
+ * flag or nothing at all — the package cannot know what deleting a row costs in a model it was handed.
7
+ * See `TOnAbandon`.
8
+ */
2
9
  export declare const createDeleteUserByEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (email: string) => Promise<void>;
3
10
  /** Signature of the bound writer, for the modules that take it as a dependency. */
4
11
  export type TDeleteUserByEmail = ReturnType<typeof createDeleteUserByEmail>;
@@ -1,10 +1,21 @@
1
- // @todo report on Sentry
2
1
  import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
3
2
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
3
+ import * as Sentry from '@sentry/node';
4
+ /**
5
+ * Hard delete of an abandoned pending registration, keyed by the login-email path.
6
+ *
7
+ * Reached through `createAbandonUser`, which is what decides whether abandonment means this, a tombstone
8
+ * flag or nothing at all — the package cannot know what deleting a row costs in a model it was handed.
9
+ * See `TOnAbandon`.
10
+ */
4
11
  export const createDeleteUserByEmail = (model, paths) => async function deleteUserByEmail(email) {
5
- await model.deleteOne({ [paths.email]: email });
6
- /* if (ret.deletedCount === 0) {
7
- } */
12
+ const ret = await model.deleteOne({ [paths.email]: email });
13
+ if (ret.deletedCount === 0) {
14
+ // The caller read this account moments ago and its guards decided the registration was abandoned, so
15
+ // nothing matching means the address moved, the path map is wrong, or another writer got there first.
16
+ // Reporting nothing is what left a delete that matched nothing indistinguishable from one that worked.
17
+ Sentry.captureMessage(`[deleteUserByEmail] no document matched ${paths.email} = ${email}`, 'warning');
18
+ }
8
19
  };
9
20
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
10
21
  export default createDeleteUserByEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
@@ -1 +1 @@
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
+ {"version":3,"file":"deleteUserByEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/deleteUserByEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACxF,KAAK,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;IAE3D,IAAI,GAAG,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;QAC5B,qGAAqG;QACrG,sGAAsG;QACtG,uGAAuG;QACvG,MAAM,CAAC,cAAc,CAAC,2CAA2C,KAAK,CAAC,KAAK,MAAM,KAAK,EAAE,EAAE,SAAS,CAAC,CAAA;IACtG,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,uBAAuB,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 * as Sentry from '@sentry/node'\n\n/**\n * Hard delete of an abandoned pending registration, keyed by the login-email path.\n *\n * Reached through `createAbandonUser`, which is what decides whether abandonment means this, a tombstone\n * flag or nothing at all — the package cannot know what deleting a row costs in a model it was handed.\n * See `TOnAbandon`.\n */\nexport const createDeleteUserByEmail = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function deleteUserByEmail(email: string) {\n\t\tconst ret = await model.deleteOne({ [paths.email]: email })\n\n\t\tif (ret.deletedCount === 0) {\n\t\t\t// The caller read this account moments ago and its guards decided the registration was abandoned, so\n\t\t\t// nothing matching means the address moved, the path map is wrong, or another writer got there first.\n\t\t\t// Reporting nothing is what left a delete that matched nothing indistinguishable from one that worked.\n\t\t\tSentry.captureMessage(`[deleteUserByEmail] no document matched ${paths.email} = ${email}`, 'warning')\n\t\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,6 +1,14 @@
1
1
  import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
2
+ import { IVerifyEmailMailer } from "../../../../lib/access/verifyEmailMailer.mjs";
2
3
  import mongoose from 'mongoose';
3
- export declare const createEnableEmailAccess: (model: TAccessModel, paths: IVerifyEmailPaths) => (_id: mongoose.Types.ObjectId, email: string) => Promise<void>;
4
+ /**
5
+ * Mark the address verified, clear the pending-verification fields, welcome the user.
6
+ *
7
+ * The welcome mail goes through an injected mailer so the success path is drivable from an integration suite
8
+ * without a real send. It is never debounced: it fires once per account, on the one path that already required
9
+ * a valid hash. See `throttleMailer`.
10
+ */
11
+ export declare const createEnableEmailAccess: (model: TAccessModel, paths: IVerifyEmailPaths, mailer: IVerifyEmailMailer) => (_id: mongoose.Types.ObjectId, email: string) => Promise<void>;
4
12
  /** Signature of the bound writer, for the modules that take it as a dependency. */
5
13
  export type TEnableEmailAccess = ReturnType<typeof createEnableEmailAccess>;
6
14
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
@@ -1,17 +1,23 @@
1
- import { SocketLabsLib } from "../../../../email/SocketLabsLib.mjs";
2
1
  import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
2
+ import { defaultVerifyEmailMailer } from "../../../../lib/access/verifyEmailMailer.mjs";
3
3
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
4
4
  import { buildUnset } from "../pathTools.mjs";
5
- export const createEnableEmailAccess = (model, paths) => async function enableEmailAccess(_id, email) {
5
+ /**
6
+ * Mark the address verified, clear the pending-verification fields, welcome the user.
7
+ *
8
+ * The welcome mail goes through an injected mailer so the success path is drivable from an integration suite
9
+ * without a real send. It is never debounced: it fires once per account, on the one path that already required
10
+ * a valid hash. See `throttleMailer`.
11
+ */
12
+ export const createEnableEmailAccess = (model, paths, mailer) => async function enableEmailAccess(_id, email) {
6
13
  await model.updateOne({ _id }, {
7
14
  $set: { [paths.valid]: true },
8
15
  $unset: buildUnset(paths.verifyClear)
9
16
  }, {
10
17
  runValidators: true
11
18
  });
12
- const SocketLabsObj = new SocketLabsLib();
13
- await SocketLabsObj.sendWelcome(email);
19
+ await mailer.sendWelcome(email);
14
20
  };
15
21
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
16
- export const enableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
22
+ export const enableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS, defaultVerifyEmailMailer);
17
23
  //# 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,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
+ {"version":3,"file":"enableEmailAccess.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/enableEmailAccess.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,wBAAwB,EAAsB,qDAAyC;AAChG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,UAAU,EAAE,yBAAyC;AAG9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,MAA0B,EAAE,EAAE,CACpH,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,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAuB,uBAAuB,CAC3E,QAAQ,EACR,0BAA0B,EAC1B,wBAAwB,CACxB,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { buildUnset } from '@private/lib/access/pathTools.mjs'\nimport mongoose from 'mongoose'\n\n/**\n * Mark the address verified, clear the pending-verification fields, welcome the user.\n *\n * The welcome mail goes through an injected mailer so the success path is drivable from an integration suite\n * without a real send. It is never debounced: it fires once per account, on the one path that already required\n * a valid hash. See `throttleMailer`.\n */\nexport const createEnableEmailAccess = (model: TAccessModel, paths: IVerifyEmailPaths, mailer: IVerifyEmailMailer) =>\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\tawait mailer.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(\n\tUserBase,\n\tDEFAULT_VERIFY_EMAIL_PATHS,\n\tdefaultVerifyEmailMailer\n)\n"]}
@@ -1 +1,12 @@
1
+ /**
2
+ * A stored hash without its bookkeeping fields is our bug, not the caller's.
3
+ *
4
+ * It redirects exactly where a hash mismatch, an expired link and an unknown address redirect — that is the
5
+ * point. Through 5.6.1 this branch threw `/x/error` while an unknown address threw `EMAIL_CHECK_LINK`, so two
6
+ * distinguishable responses answered an unauthenticated GET and the pair told anybody who asked whether an
7
+ * address had an account. Worse on data predating the verification fields, where every real account answered
8
+ * `/x/error` and every unknown one answered the other: a clean enumeration oracle.
9
+ *
10
+ * The distinction is kept where it belongs — Sentry, which is who needs to know.
11
+ */
1
12
  export declare function handleBadDB(requestTimes?: number, dateLastReq?: Date): void;
@@ -1,9 +1,21 @@
1
1
  import * as Sentry from '@sentry/node';
2
+ import { EMAIL_CHECK_LINK } from './Constants.mjs';
3
+ /**
4
+ * A stored hash without its bookkeeping fields is our bug, not the caller's.
5
+ *
6
+ * It redirects exactly where a hash mismatch, an expired link and an unknown address redirect — that is the
7
+ * point. Through 5.6.1 this branch threw `/x/error` while an unknown address threw `EMAIL_CHECK_LINK`, so two
8
+ * distinguishable responses answered an unauthenticated GET and the pair told anybody who asked whether an
9
+ * address had an account. Worse on data predating the verification fields, where every real account answered
10
+ * `/x/error` and every unknown one answered the other: a clean enumeration oracle.
11
+ *
12
+ * The distinction is kept where it belongs — Sentry, which is who needs to know.
13
+ */
2
14
  export function handleBadDB(requestTimes, dateLastReq) {
3
15
  if (typeof requestTimes === 'undefined' || dateLastReq === undefined) {
4
16
  Sentry.captureMessage('[handleBadDB] DB ERROR', 'error');
5
17
  // it's an our error !! cannot be present the hash without requestTimes!
6
- throw new Error('/x/error');
18
+ throw new Error(EMAIL_CHECK_LINK);
7
19
  }
8
20
  }
9
21
  //# sourceMappingURL=handleBadDB.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleBadDB.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleBadDB.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,WAAW,CAAC,YAAqB,EAAE,WAAkB;IACpE,IAAI,OAAO,YAAY,KAAK,WAAW,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACtE,MAAM,CAAC,cAAc,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAA;QAExD,wEAAwE;QACxE,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;IAC5B,CAAC;AACF,CAAC","sourcesContent":["import * as Sentry from '@sentry/node'\n\nexport function handleBadDB(requestTimes?: number, dateLastReq?: Date) {\n\tif (typeof requestTimes === 'undefined' || dateLastReq === undefined) {\n\t\tSentry.captureMessage('[handleBadDB] DB ERROR', 'error')\n\n\t\t// it's an our error !! cannot be present the hash without requestTimes!\n\t\tthrow new Error('/x/error')\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleBadDB.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleBadDB.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,YAAqB,EAAE,WAAkB;IACpE,IAAI,OAAO,YAAY,KAAK,WAAW,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACtE,MAAM,CAAC,cAAc,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAA;QAExD,wEAAwE;QACxE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import * as Sentry from '@sentry/node'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\n\n/**\n * A stored hash without its bookkeeping fields is our bug, not the caller's.\n *\n * It redirects exactly where a hash mismatch, an expired link and an unknown address redirect — that is the\n * point. Through 5.6.1 this branch threw `/x/error` while an unknown address threw `EMAIL_CHECK_LINK`, so two\n * distinguishable responses answered an unauthenticated GET and the pair told anybody who asked whether an\n * address had an account. Worse on data predating the verification fields, where every real account answered\n * `/x/error` and every unknown one answered the other: a clean enumeration oracle.\n *\n * The distinction is kept where it belongs — Sentry, which is who needs to know.\n */\nexport function handleBadDB(requestTimes?: number, dateLastReq?: Date) {\n\tif (typeof requestTimes === 'undefined' || dateLastReq === undefined) {\n\t\tSentry.captureMessage('[handleBadDB] DB ERROR', 'error')\n\n\t\t// it's an our error !! cannot be present the hash without requestTimes!\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
@@ -1 +1,16 @@
1
- export declare function handleIfAccountDeleted(email: string, deleted?: boolean): Promise<void>;
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
+ /**
3
+ * The account carries the tombstone flag.
4
+ *
5
+ * Sends `accountDisabled`, not an `accountDeleted` of its own: `SocketLabsLib` has no such template, so a
6
+ * deleted account is told it is disabled. That is the shipped copy, left as it is here on purpose — this is
7
+ * the guard, not the place to invent a message.
8
+ *
9
+ * Like every other counter-less branch it mails on each request, which is why the mailer is injected and the
10
+ * default one is debounced. See `createMailThrottle`.
11
+ */
12
+ export declare const createHandleIfAccountDeleted: (mailer: IVerifyEmailMailer) => (email: string, deleted?: boolean) => Promise<void>;
13
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
14
+ export type THandleIfAccountDeleted = ReturnType<typeof createHandleIfAccountDeleted>;
15
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
16
+ export declare const handleIfAccountDeleted: THandleIfAccountDeleted;
@@ -1,10 +1,21 @@
1
- import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
1
+ import { defaultVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
2
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
3
- export async function handleIfAccountDeleted(email, deleted = false) {
3
+ /**
4
+ * The account carries the tombstone flag.
5
+ *
6
+ * Sends `accountDisabled`, not an `accountDeleted` of its own: `SocketLabsLib` has no such template, so a
7
+ * deleted account is told it is disabled. That is the shipped copy, left as it is here on purpose — this is
8
+ * the guard, not the place to invent a message.
9
+ *
10
+ * Like every other counter-less branch it mails on each request, which is why the mailer is injected and the
11
+ * default one is debounced. See `createMailThrottle`.
12
+ */
13
+ export const createHandleIfAccountDeleted = (mailer) => async function handleIfAccountDeleted(email, deleted = false) {
4
14
  if (deleted) {
5
- const SocketLabsObj = new SocketLabsLib();
6
- await SocketLabsObj.accountDisabled(email);
15
+ await mailer.accountDisabled(email);
7
16
  throw new Error(EMAIL_CHECK_LINK);
8
17
  }
9
- }
18
+ };
19
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
20
+ export const handleIfAccountDeleted = createHandleIfAccountDeleted(defaultVerifyEmailMailer);
10
21
  //# sourceMappingURL=handleIfAccountDeleted.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfAccountDeleted.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfAccountDeleted.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAAa,EAAE,UAAmB,KAAK;IACnF,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QAEzC,MAAM,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QAC1C,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\n\nexport async function handleIfAccountDeleted(email: string, deleted: boolean = false) {\n\tif (deleted) {\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\n\t\tawait SocketLabsObj.accountDisabled(email)\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleIfAccountDeleted.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfAccountDeleted.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAEhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,MAA0B,EAAE,EAAE,CAC1E,KAAK,UAAU,sBAAsB,CAAC,KAAa,EAAE,UAAmB,KAAK;IAC5E,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,uGAAuG;AACvG,MAAM,CAAC,MAAM,sBAAsB,GAA4B,4BAA4B,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\n\n/**\n * The account carries the tombstone flag.\n *\n * Sends `accountDisabled`, not an `accountDeleted` of its own: `SocketLabsLib` has no such template, so a\n * deleted account is told it is disabled. That is the shipped copy, left as it is here on purpose — this is\n * the guard, not the place to invent a message.\n *\n * Like every other counter-less branch it mails on each request, which is why the mailer is injected and the\n * default one is debounced. See `createMailThrottle`.\n */\nexport const createHandleIfAccountDeleted = (mailer: IVerifyEmailMailer) =>\n\tasync function handleIfAccountDeleted(email: string, deleted: boolean = false) {\n\t\tif (deleted) {\n\t\t\tawait mailer.accountDisabled(email)\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 THandleIfAccountDeleted = ReturnType<typeof createHandleIfAccountDeleted>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */\nexport const handleIfAccountDeleted: THandleIfAccountDeleted = createHandleIfAccountDeleted(defaultVerifyEmailMailer)\n"]}
@@ -1 +1,15 @@
1
- export declare function handleIfAccountDisabled(email: string, disabled?: boolean): Promise<void>;
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
+ /**
3
+ * The account carries the lockout flag.
4
+ *
5
+ * Byte-identical to `handleIfAccountDeleted` apart from the flag it reads, because there is only one
6
+ * template for both states. Kept as two guards so the chain reads as the two distinct conditions it checks.
7
+ *
8
+ * Counter-less like the rest, so the mailer is injected and the default one is debounced. See
9
+ * `createMailThrottle`.
10
+ */
11
+ export declare const createHandleIfAccountDisabled: (mailer: IVerifyEmailMailer) => (email: string, disabled?: boolean) => Promise<void>;
12
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
13
+ export type THandleIfAccountDisabled = ReturnType<typeof createHandleIfAccountDisabled>;
14
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
15
+ export declare const handleIfAccountDisabled: THandleIfAccountDisabled;
@@ -1,10 +1,20 @@
1
- import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
1
+ import { defaultVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
2
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
3
- export async function handleIfAccountDisabled(email, disabled = false) {
3
+ /**
4
+ * The account carries the lockout flag.
5
+ *
6
+ * Byte-identical to `handleIfAccountDeleted` apart from the flag it reads, because there is only one
7
+ * template for both states. Kept as two guards so the chain reads as the two distinct conditions it checks.
8
+ *
9
+ * Counter-less like the rest, so the mailer is injected and the default one is debounced. See
10
+ * `createMailThrottle`.
11
+ */
12
+ export const createHandleIfAccountDisabled = (mailer) => async function handleIfAccountDisabled(email, disabled = false) {
4
13
  if (disabled) {
5
- const SocketLabsObj = new SocketLabsLib();
6
- await SocketLabsObj.accountDisabled(email);
14
+ await mailer.accountDisabled(email);
7
15
  throw new Error(EMAIL_CHECK_LINK);
8
16
  }
9
- }
17
+ };
18
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
19
+ export const handleIfAccountDisabled = createHandleIfAccountDisabled(defaultVerifyEmailMailer);
10
20
  //# sourceMappingURL=handleIfAccountDisabled.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfAccountDisabled.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfAccountDisabled.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAAa,EAAE,WAAoB,KAAK;IACrF,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QAEzC,MAAM,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QAC1C,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\n\nexport async function handleIfAccountDisabled(email: string, disabled: boolean = false) {\n\tif (disabled) {\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\n\t\tawait SocketLabsObj.accountDisabled(email)\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleIfAccountDisabled.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfAccountDisabled.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAEhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,MAA0B,EAAE,EAAE,CAC3E,KAAK,UAAU,uBAAuB,CAAC,KAAa,EAAE,WAAoB,KAAK;IAC9E,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,uGAAuG;AACvG,MAAM,CAAC,MAAM,uBAAuB,GAA6B,6BAA6B,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\n\n/**\n * The account carries the lockout flag.\n *\n * Byte-identical to `handleIfAccountDeleted` apart from the flag it reads, because there is only one\n * template for both states. Kept as two guards so the chain reads as the two distinct conditions it checks.\n *\n * Counter-less like the rest, so the mailer is injected and the default one is debounced. See\n * `createMailThrottle`.\n */\nexport const createHandleIfAccountDisabled = (mailer: IVerifyEmailMailer) =>\n\tasync function handleIfAccountDisabled(email: string, disabled: boolean = false) {\n\t\tif (disabled) {\n\t\t\tawait mailer.accountDisabled(email)\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 THandleIfAccountDisabled = ReturnType<typeof createHandleIfAccountDisabled>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */\nexport const handleIfAccountDisabled: THandleIfAccountDisabled = createHandleIfAccountDisabled(defaultVerifyEmailMailer)\n"]}
@@ -1 +1,18 @@
1
- export declare function handleIfEmailAlreadyValid(uEmail: string, valid: boolean): Promise<void>;
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
+ /**
3
+ * The address in the link is already verified.
4
+ *
5
+ * The notification goes through an injected mailer, which buys two things. The branch becomes drivable from
6
+ * an integration suite without a real send — the SocketLabs client used to be constructed right here, so
7
+ * reaching this path with real credentials mailed a real person. And the debounce gets somewhere to live:
8
+ * this guard has no counter behind it, so through 5.6.1 an unauthenticated GET mailed the address once per
9
+ * request, for as many requests as the caller cared to make. `defaultVerifyEmailMailer` is throttled — see
10
+ * `createMailThrottle`.
11
+ *
12
+ * A suppressed mail changes nothing the caller can observe: the throw, and so the redirect, is unconditional.
13
+ */
14
+ export declare const createHandleIfEmailAlreadyValid: (mailer: IVerifyEmailMailer) => (uEmail: string, valid: boolean) => Promise<void>;
15
+ /** Signature of the bound guard, for the modules that take it as a dependency. */
16
+ export type THandleIfEmailAlreadyValid = ReturnType<typeof createHandleIfEmailAlreadyValid>;
17
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
18
+ export declare const handleIfEmailAlreadyValid: THandleIfEmailAlreadyValid;