@axiumine/koa-utils 5.6.1 → 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 (49) hide show
  1. package/README.md +10 -1
  2. package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +7 -0
  3. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +38 -35
  4. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
  5. package/dist/lib/access/accessPaths.d.mts +18 -0
  6. package/dist/lib/access/accessPaths.mjs.map +1 -1
  7. package/dist/lib/access/createMailThrottle.d.mts +34 -0
  8. package/dist/lib/access/createMailThrottle.mjs +45 -0
  9. package/dist/lib/access/createMailThrottle.mjs.map +1 -0
  10. package/dist/lib/access/createVerifyEmailFlow.d.mts +37 -4
  11. package/dist/lib/access/createVerifyEmailFlow.mjs +33 -10
  12. package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -1
  13. package/dist/lib/access/verifyEmailMailer.d.mts +54 -0
  14. package/dist/lib/access/verifyEmailMailer.mjs +48 -0
  15. package/dist/lib/access/verifyEmailMailer.mjs.map +1 -0
  16. package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +13 -1
  17. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +7 -4
  18. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
  19. package/dist/private/lib/access/db/abandonUser.d.mts +25 -0
  20. package/dist/private/lib/access/db/abandonUser.mjs +26 -0
  21. package/dist/private/lib/access/db/abandonUser.mjs.map +1 -0
  22. package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -0
  23. package/dist/private/lib/access/db/deleteUserByEmail.mjs +15 -4
  24. package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
  25. package/dist/private/lib/access/db/enableEmailAccess.d.mts +9 -1
  26. package/dist/private/lib/access/db/enableEmailAccess.mjs +11 -5
  27. package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
  28. package/dist/private/lib/access/handleBadDB.d.mts +11 -0
  29. package/dist/private/lib/access/handleBadDB.mjs +13 -1
  30. package/dist/private/lib/access/handleBadDB.mjs.map +1 -1
  31. package/dist/private/lib/access/handleIfAccountDeleted.d.mts +16 -1
  32. package/dist/private/lib/access/handleIfAccountDeleted.mjs +16 -5
  33. package/dist/private/lib/access/handleIfAccountDeleted.mjs.map +1 -1
  34. package/dist/private/lib/access/handleIfAccountDisabled.d.mts +15 -1
  35. package/dist/private/lib/access/handleIfAccountDisabled.mjs +15 -5
  36. package/dist/private/lib/access/handleIfAccountDisabled.mjs.map +1 -1
  37. package/dist/private/lib/access/handleIfEmailAlreadyValid.d.mts +18 -1
  38. package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs +18 -5
  39. package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs.map +1 -1
  40. package/dist/private/lib/access/handleIfHashBad.d.mts +5 -1
  41. package/dist/private/lib/access/handleIfHashBad.mjs +7 -5
  42. package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
  43. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +8 -4
  44. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +10 -8
  45. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
  46. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +7 -4
  47. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +9 -8
  48. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
  49. package/package.json +9 -1
@@ -1,10 +1,23 @@
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 handleIfEmailAlreadyValid(uEmail, valid) {
3
+ /**
4
+ * The address in the link is already verified.
5
+ *
6
+ * The notification goes through an injected mailer, which buys two things. The branch becomes drivable from
7
+ * an integration suite without a real send — the SocketLabs client used to be constructed right here, so
8
+ * reaching this path with real credentials mailed a real person. And the debounce gets somewhere to live:
9
+ * this guard has no counter behind it, so through 5.6.1 an unauthenticated GET mailed the address once per
10
+ * request, for as many requests as the caller cared to make. `defaultVerifyEmailMailer` is throttled — see
11
+ * `createMailThrottle`.
12
+ *
13
+ * A suppressed mail changes nothing the caller can observe: the throw, and so the redirect, is unconditional.
14
+ */
15
+ export const createHandleIfEmailAlreadyValid = (mailer) => async function handleIfEmailAlreadyValid(uEmail, valid) {
4
16
  if (valid) {
5
- const SocketLabsObj = new SocketLabsLib();
6
- await SocketLabsObj.emailAlreadyValid(uEmail);
17
+ await mailer.emailAlreadyValid(uEmail);
7
18
  throw new Error(EMAIL_CHECK_LINK);
8
19
  }
9
- }
20
+ };
21
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
22
+ export const handleIfEmailAlreadyValid = createHandleIfEmailAlreadyValid(defaultVerifyEmailMailer);
10
23
  //# sourceMappingURL=handleIfEmailAlreadyValid.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfEmailAlreadyValid.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfEmailAlreadyValid.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,MAAc,EAAE,KAAc;IAC7E,IAAI,KAAK,EAAE,CAAC;QACX,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QAEzC,MAAM,aAAa,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAC7C,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 handleIfEmailAlreadyValid(uEmail: string, valid: boolean) {\n\tif (valid) {\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\n\t\tawait SocketLabsObj.emailAlreadyValid(uEmail)\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
1
+ {"version":3,"file":"handleIfEmailAlreadyValid.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfEmailAlreadyValid.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAEhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,MAA0B,EAAE,EAAE,CAC7E,KAAK,UAAU,yBAAyB,CAAC,MAAc,EAAE,KAAc;IACtE,IAAI,KAAK,EAAE,CAAC;QACX,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;QACtC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,uGAAuG;AACvG,MAAM,CAAC,MAAM,yBAAyB,GAA+B,+BAA+B,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 address in the link is already verified.\n *\n * The notification goes through an injected mailer, which buys two things. The branch becomes drivable from\n * an integration suite without a real send — the SocketLabs client used to be constructed right here, so\n * reaching this path with real credentials mailed a real person. And the debounce gets somewhere to live:\n * this guard has no counter behind it, so through 5.6.1 an unauthenticated GET mailed the address once per\n * request, for as many requests as the caller cared to make. `defaultVerifyEmailMailer` is throttled — see\n * `createMailThrottle`.\n *\n * A suppressed mail changes nothing the caller can observe: the throw, and so the redirect, is unconditional.\n */\nexport const createHandleIfEmailAlreadyValid = (mailer: IVerifyEmailMailer) =>\n\tasync function handleIfEmailAlreadyValid(uEmail: string, valid: boolean) {\n\t\tif (valid) {\n\t\t\tawait mailer.emailAlreadyValid(uEmail)\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 THandleIfEmailAlreadyValid = ReturnType<typeof createHandleIfEmailAlreadyValid>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */\nexport const handleIfEmailAlreadyValid: THandleIfEmailAlreadyValid = createHandleIfEmailAlreadyValid(defaultVerifyEmailMailer)\n"]}
@@ -1,3 +1,4 @@
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
1
2
  import mongoose from 'mongoose';
2
3
  import { TIncReqTimes } from './db/incReqTimes.mjs';
3
4
  interface IHandleIfHashBadArgs {
@@ -12,8 +13,11 @@ interface IHandleIfHashBadArgs {
12
13
  *
13
14
  * The strike counter is bumped through an injected writer so the guard can serve a model other than
14
15
  * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
16
+ *
17
+ * The warning mail goes through an injected mailer for the same reason plus one more — a constructed-in-place
18
+ * SocketLabs client made this branch unreachable from an integration suite without sending for real.
15
19
  */
16
- export declare const createHandleIfHashBad: (incReqTimesFn: TIncReqTimes) => ({ uId, uEmail, hash, requestTimes, dbHash }: IHandleIfHashBadArgs) => Promise<void>;
20
+ export declare const createHandleIfHashBad: (incReqTimesFn: TIncReqTimes, mailer: IVerifyEmailMailer) => ({ uId, uEmail, hash, requestTimes, dbHash }: IHandleIfHashBadArgs) => Promise<void>;
17
21
  /** Signature of the bound guard, for the modules that take it as a dependency. */
18
22
  export type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>;
19
23
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
@@ -1,4 +1,4 @@
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
3
  import { incReqTimes } from './db/incReqTimes.mjs';
4
4
  /**
@@ -6,16 +6,18 @@ import { incReqTimes } from './db/incReqTimes.mjs';
6
6
  *
7
7
  * The strike counter is bumped through an injected writer so the guard can serve a model other than
8
8
  * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
9
+ *
10
+ * The warning mail goes through an injected mailer for the same reason plus one more — a constructed-in-place
11
+ * SocketLabs client made this branch unreachable from an integration suite without sending for real.
9
12
  */
10
- export const createHandleIfHashBad = (incReqTimesFn) => async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
13
+ export const createHandleIfHashBad = (incReqTimesFn, mailer) => async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
11
14
  if (hash !== dbHash) {
12
15
  // hash failed
13
16
  await incReqTimesFn(uId);
14
- const SocketLabsObj = new SocketLabsLib();
15
- await SocketLabsObj.wrongHash(uEmail, requestTimes + 1);
17
+ await mailer.wrongHash(uEmail, requestTimes + 1);
16
18
  throw new Error(EMAIL_CHECK_LINK);
17
19
  }
18
20
  };
19
21
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
20
- export const handleIfHashBad = createHandleIfHashBad(incReqTimes);
22
+ export const handleIfHashBad = createHandleIfHashBad(incReqTimes, defaultVerifyEmailMailer);
21
23
  //# sourceMappingURL=handleIfHashBad.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,sBAAsB,CAAA;AAUhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,aAA2B,EAAE,EAAE,CACpE,KAAK,UAAU,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,EAAE,MAAM,EAAwB;IACnG,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,cAAc;QACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;QAExB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAA;QACvD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAqB,qBAAqB,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport mongoose from 'mongoose'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport { incReqTimes, TIncReqTimes } from './db/incReqTimes.mjs'\n\ninterface IHandleIfHashBadArgs {\n\tuId: mongoose.Types.ObjectId\n\tuEmail: string\n\thash: string\n\trequestTimes?: number // but the check is already performed\n\tdbHash?: string\n}\n\n/**\n * The hash in the activation url is wrong.\n *\n * The strike counter is bumped through an injected writer so the guard can serve a model other than\n * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.\n */\nexport const createHandleIfHashBad = (incReqTimesFn: TIncReqTimes) =>\n\tasync function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }: IHandleIfHashBadArgs) {\n\t\tif (hash !== dbHash) {\n\t\t\t// hash failed\n\t\t\tawait incReqTimesFn(uId)\n\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.wrongHash(uEmail, requestTimes + 1)\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfHashBad: THandleIfHashBad = createHandleIfHashBad(incReqTimes)\n"]}
1
+ {"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAGhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,sBAAsB,CAAA;AAUhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,aAA2B,EAAE,MAA0B,EAAE,EAAE,CAChG,KAAK,UAAU,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,EAAE,MAAM,EAAwB;IACnG,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,cAAc;QACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;QAExB,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAA;QAChD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAqB,qBAAqB,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAA","sourcesContent":["import { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\nimport mongoose from 'mongoose'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport { incReqTimes, TIncReqTimes } from './db/incReqTimes.mjs'\n\ninterface IHandleIfHashBadArgs {\n\tuId: mongoose.Types.ObjectId\n\tuEmail: string\n\thash: string\n\trequestTimes?: number // but the check is already performed\n\tdbHash?: string\n}\n\n/**\n * The hash in the activation url is wrong.\n *\n * The strike counter is bumped through an injected writer so the guard can serve a model other than\n * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.\n *\n * The warning mail goes through an injected mailer for the same reason plus one more — a constructed-in-place\n * SocketLabs client made this branch unreachable from an integration suite without sending for real.\n */\nexport const createHandleIfHashBad = (incReqTimesFn: TIncReqTimes, mailer: IVerifyEmailMailer) =>\n\tasync function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }: IHandleIfHashBadArgs) {\n\t\tif (hash !== dbHash) {\n\t\t\t// hash failed\n\t\t\tawait incReqTimesFn(uId)\n\n\t\t\tawait mailer.wrongHash(uEmail, requestTimes + 1)\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfHashBad: THandleIfHashBad = createHandleIfHashBad(incReqTimes, defaultVerifyEmailMailer)\n"]}
@@ -1,11 +1,15 @@
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
1
2
  import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
2
3
  /**
3
- * A verification link older than 3 days deletes the pending account.
4
+ * A verification link older than 3 days disposes of the pending account.
4
5
  *
5
- * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
6
- * both the collection and the login-email path come from the writer it was built with.
6
+ * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the
7
+ * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. The guard throws
8
+ * either way — what happens to the row never changes whether the link is honoured.
9
+ *
10
+ * The mail goes through an injected mailer, which also carries the debounce on the default binding.
7
11
  */
8
- export declare const createHandleIfMoreThan3DaysPassed: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, dateLastReq?: Date) => Promise<void>;
12
+ export declare const createHandleIfMoreThan3DaysPassed: (deleteUserByEmailFn: TDeleteUserByEmail, mailer: IVerifyEmailMailer) => (uEmail: string, dateLastReq?: Date) => Promise<void>;
9
13
  /** Signature of the bound guard, for the modules that take it as a dependency. */
10
14
  export type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>;
11
15
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
@@ -1,14 +1,17 @@
1
- import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
1
+ import { defaultVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
2
2
  import { StringLib } from "../../../lib/StringLib.mjs";
3
3
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
4
4
  import deleteUserByEmail from './db/deleteUserByEmail.mjs';
5
5
  /**
6
- * A verification link older than 3 days deletes the pending account.
6
+ * A verification link older than 3 days disposes of the pending account.
7
7
  *
8
- * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
9
- * both the collection and the login-email path come from the writer it was built with.
8
+ * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the
9
+ * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. The guard throws
10
+ * either way — what happens to the row never changes whether the link is honoured.
11
+ *
12
+ * The mail goes through an injected mailer, which also carries the debounce on the default binding.
10
13
  */
11
- export const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn) => async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date() // but it is already handled
14
+ export const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn, mailer) => async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date() // but it is already handled
12
15
  ) {
13
16
  /****************************************************
14
17
  * if dateLastReq too old then 3 days send email
@@ -20,12 +23,11 @@ export const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn) => async
20
23
  const ts3DayAgo = StrLibObj.isoToTimestamp(day3ago);
21
24
  if (ts3DayAgo > tsReq) {
22
25
  // dateLastReq too old then 3 days
23
- const SocketLabsObj = new SocketLabsLib();
24
- await SocketLabsObj.hashReqTooOld(uEmail);
26
+ await mailer.hashReqTooOld(uEmail);
25
27
  await deleteUserByEmailFn(uEmail);
26
28
  throw new Error(EMAIL_CHECK_LINK);
27
29
  }
28
30
  };
29
31
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
30
- export const handleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail);
32
+ export const handleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail, defaultVerifyEmailMailer);
31
33
  //# sourceMappingURL=handleIfMoreThan3DaysPassed.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,mBAAuC,EAAE,EAAE,CAC5F,KAAK,UAAU,2BAA2B,CACzC,MAAc,EACd,cAAoB,IAAI,IAAI,EAAE,CAAC,4BAA4B;;IAE3D;;OAEG;IAEH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,IAAI,SAAS,GAAG,KAAK,EAAE,CAAC;QACvB,kCAAkC;QAClC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAEzC,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAiC,iCAAiC,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * A verification link older than 3 days deletes the pending account.\n *\n * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:\n * both the collection and the login-email path come from the writer it was built with.\n */\nexport const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn: TDeleteUserByEmail) =>\n\tasync function handleIfMoreThan3DaysPassed(\n\t\tuEmail: string,\n\t\tdateLastReq: Date = new Date() // but it is already handled\n\t) {\n\t\t/****************************************************\n\t\t * if dateLastReq too old then 3 days send email\n\t\t */\n\n\t\tconst now = new Date()\n\t\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\t\tconst StrLibObj = new StringLib()\n\t\tconst tsReq = StrLibObj.isoToTimestamp(dateLastReq)\n\t\tconst ts3DayAgo = StrLibObj.isoToTimestamp(day3ago)\n\n\t\tif (ts3DayAgo > tsReq) {\n\t\t\t// dateLastReq too old then 3 days\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.hashReqTooOld(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail)\n"]}
1
+ {"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAChG,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,mBAAuC,EAAE,MAA0B,EAAE,EAAE,CACxH,KAAK,UAAU,2BAA2B,CACzC,MAAc,EACd,cAAoB,IAAI,IAAI,EAAE,CAAC,4BAA4B;;IAE3D;;OAEG;IAEH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,IAAI,SAAS,GAAG,KAAK,EAAE,CAAC;QACvB,kCAAkC;QAClC,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAElC,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAiC,iCAAiC,CACzG,iBAAiB,EACjB,wBAAwB,CACxB,CAAA","sourcesContent":["import { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * A verification link older than 3 days disposes of the pending account.\n *\n * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the\n * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. The guard throws\n * either way — what happens to the row never changes whether the link is honoured.\n *\n * The mail goes through an injected mailer, which also carries the debounce on the default binding.\n */\nexport const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn: TDeleteUserByEmail, mailer: IVerifyEmailMailer) =>\n\tasync function handleIfMoreThan3DaysPassed(\n\t\tuEmail: string,\n\t\tdateLastReq: Date = new Date() // but it is already handled\n\t) {\n\t\t/****************************************************\n\t\t * if dateLastReq too old then 3 days send email\n\t\t */\n\n\t\tconst now = new Date()\n\t\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\t\tconst StrLibObj = new StringLib()\n\t\tconst tsReq = StrLibObj.isoToTimestamp(dateLastReq)\n\t\tconst ts3DayAgo = StrLibObj.isoToTimestamp(day3ago)\n\n\t\tif (ts3DayAgo > tsReq) {\n\t\t\t// dateLastReq too old then 3 days\n\t\t\tawait mailer.hashReqTooOld(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(\n\tdeleteUserByEmail,\n\tdefaultVerifyEmailMailer\n)\n"]}
@@ -1,11 +1,14 @@
1
+ import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
1
2
  import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
2
3
  /**
3
- * Five wrong-hash attempts delete the pending account.
4
+ * Five wrong-hash attempts dispose of the pending account.
4
5
  *
5
- * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
6
- * both the collection and the login-email path come from the writer it was built with.
6
+ * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the
7
+ * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. Under `'keep'`
8
+ * the strike count keeps climbing past 5, so this branch repeats — which is the other reason the mail is
9
+ * injected and the default binding is debounced.
7
10
  */
8
- export declare const createHandleIfTooMuchRequestsTimes: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, requestTimes?: number) => Promise<void>;
11
+ export declare const createHandleIfTooMuchRequestsTimes: (deleteUserByEmailFn: TDeleteUserByEmail, mailer: IVerifyEmailMailer) => (uEmail: string, requestTimes?: number) => Promise<void>;
9
12
  /** Signature of the bound guard, for the modules that take it as a dependency. */
10
13
  export type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>;
11
14
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
@@ -1,21 +1,22 @@
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
3
  import deleteUserByEmail from './db/deleteUserByEmail.mjs';
4
4
  /**
5
- * Five wrong-hash attempts delete the pending account.
5
+ * Five wrong-hash attempts dispose of the pending account.
6
6
  *
7
- * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
8
- * both the collection and the login-email path come from the writer it was built with.
7
+ * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the
8
+ * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. Under `'keep'`
9
+ * the strike count keeps climbing past 5, so this branch repeats — which is the other reason the mail is
10
+ * injected and the default binding is debounced.
9
11
  */
10
- export const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn) => async function handleIfTooMuchRequestsTimes(uEmail, requestTimes = 99 // but it is already handled
12
+ export const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn, mailer) => async function handleIfTooMuchRequestsTimes(uEmail, requestTimes = 99 // but it is already handled
11
13
  ) {
12
14
  if (requestTimes >= 5) {
13
- const SocketLabsObj = new SocketLabsLib();
14
- await SocketLabsObj.tooMuchVerifyRequests(uEmail);
15
+ await mailer.tooMuchVerifyRequests(uEmail);
15
16
  await deleteUserByEmailFn(uEmail);
16
17
  throw new Error(EMAIL_CHECK_LINK);
17
18
  }
18
19
  };
19
20
  /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
20
- export const handleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail);
21
+ export const handleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail, defaultVerifyEmailMailer);
21
22
  //# sourceMappingURL=handleIfTooMuchRequestsTimes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleIfTooMuchRequestsTimes.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfTooMuchRequestsTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,mBAAuC,EAAE,EAAE,CAC7F,KAAK,UAAU,4BAA4B,CAC1C,MAAc,EACd,eAAuB,EAAE,CAAC,4BAA4B;;IAEtD,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QAEjD,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,4BAA4B,GAAkC,kCAAkC,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * Five wrong-hash attempts delete the pending account.\n *\n * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:\n * both the collection and the login-email path come from the writer it was built with.\n */\nexport const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn: TDeleteUserByEmail) =>\n\tasync function handleIfTooMuchRequestsTimes(\n\t\tuEmail: string,\n\t\trequestTimes: number = 99 // but it is already handled\n\t) {\n\t\tif (requestTimes >= 5) {\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.tooMuchVerifyRequests(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail)\n"]}
1
+ {"version":3,"file":"handleIfTooMuchRequestsTimes.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfTooMuchRequestsTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,kDAAyC;AAEhG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,mBAAuC,EAAE,MAA0B,EAAE,EAAE,CACzH,KAAK,UAAU,4BAA4B,CAC1C,MAAc,EACd,eAAuB,EAAE,CAAC,4BAA4B;;IAEtD,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QAE1C,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,4BAA4B,GAAkC,kCAAkC,CAC5G,iBAAiB,EACjB,wBAAwB,CACxB,CAAA","sourcesContent":["import { defaultVerifyEmailMailer, IVerifyEmailMailer } from '@lib/access/verifyEmailMailer.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * Five wrong-hash attempts dispose of the pending account.\n *\n * Disposal runs through an injected writer so the guard can serve a model other than `UserBase`, and so the\n * *policy* is the caller's: hard delete, tombstone flag or nothing. See `createAbandonUser`. Under `'keep'`\n * the strike count keeps climbing past 5, so this branch repeats — which is the other reason the mail is\n * injected and the default binding is debounced.\n */\nexport const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn: TDeleteUserByEmail, mailer: IVerifyEmailMailer) =>\n\tasync function handleIfTooMuchRequestsTimes(\n\t\tuEmail: string,\n\t\trequestTimes: number = 99 // but it is already handled\n\t) {\n\t\tif (requestTimes >= 5) {\n\t\t\tawait mailer.tooMuchVerifyRequests(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(\n\tdeleteUserByEmail,\n\tdefaultVerifyEmailMailer\n)\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiumine/koa-utils",
3
- "version": "5.6.1",
3
+ "version": "5.7.0",
4
4
  "description": "Koa Utils",
5
5
  "type": "module",
6
6
  "repository": {
@@ -64,6 +64,14 @@
64
64
  "import": "./dist/lib/access/createVerifyEmailFlow.mjs",
65
65
  "types": "./dist/lib/access/createVerifyEmailFlow.d.mts"
66
66
  },
67
+ "./lib/access/createMailThrottle": {
68
+ "import": "./dist/lib/access/createMailThrottle.mjs",
69
+ "types": "./dist/lib/access/createMailThrottle.d.mts"
70
+ },
71
+ "./lib/access/verifyEmailMailer": {
72
+ "import": "./dist/lib/access/verifyEmailMailer.mjs",
73
+ "types": "./dist/lib/access/verifyEmailMailer.d.mts"
74
+ },
67
75
  "./lib/MongoDB/IOnboarding": {
68
76
  "import": "./dist/lib/MongoDB/IOnboarding.mjs",
69
77
  "types": "./dist/lib/MongoDB/IOnboarding.d.mts"