@axiumine/koa-utils 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +26 -0
  2. package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +19 -1
  3. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +31 -15
  4. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
  5. package/dist/graphQL/schema/mutations/resetPwd.d.mts +15 -1
  6. package/dist/graphQL/schema/mutations/resetPwd.mjs +9 -4
  7. package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
  8. package/dist/graphQL/schema/mutations/updatePassword.d.mts +21 -1
  9. package/dist/graphQL/schema/mutations/updatePassword.mjs +18 -5
  10. package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
  11. package/dist/koa/router/verifyEmail.d.mts +22 -1
  12. package/dist/koa/router/verifyEmail.mjs +18 -9
  13. package/dist/koa/router/verifyEmail.mjs.map +1 -1
  14. package/dist/lib/access/accessPaths.d.mts +92 -0
  15. package/dist/lib/access/accessPaths.mjs +46 -0
  16. package/dist/lib/access/accessPaths.mjs.map +1 -0
  17. package/dist/lib/access/createResetPwdFlow.d.mts +33 -0
  18. package/dist/lib/access/createResetPwdFlow.mjs +42 -0
  19. package/dist/lib/access/createResetPwdFlow.mjs.map +1 -0
  20. package/dist/lib/access/createVerifyEmailFlow.d.mts +48 -0
  21. package/dist/lib/access/createVerifyEmailFlow.mjs +68 -0
  22. package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -0
  23. package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +20 -2
  24. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +30 -12
  25. package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
  26. package/dist/private/lib/access/db/confirmNewEmail.d.mts +7 -1
  27. package/dist/private/lib/access/db/confirmNewEmail.mjs +12 -11
  28. package/dist/private/lib/access/db/confirmNewEmail.mjs.map +1 -1
  29. package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -1
  30. package/dist/private/lib/access/db/deleteUserByEmail.mjs +6 -3
  31. package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
  32. package/dist/private/lib/access/db/enableEmailAccess.d.mts +6 -1
  33. package/dist/private/lib/access/db/enableEmailAccess.mjs +9 -9
  34. package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
  35. package/dist/private/lib/access/db/getResetPwd.d.mts +11 -4
  36. package/dist/private/lib/access/db/getResetPwd.mjs +17 -12
  37. package/dist/private/lib/access/db/getResetPwd.mjs.map +1 -1
  38. package/dist/private/lib/access/db/incReqTimes.d.mts +6 -1
  39. package/dist/private/lib/access/db/incReqTimes.mjs +6 -3
  40. package/dist/private/lib/access/db/incReqTimes.mjs.map +1 -1
  41. package/dist/private/lib/access/db/removeResetReq.d.mts +7 -1
  42. package/dist/private/lib/access/db/removeResetReq.mjs +16 -7
  43. package/dist/private/lib/access/db/removeResetReq.mjs.map +1 -1
  44. package/dist/private/lib/access/db/saveResetReq.d.mts +6 -1
  45. package/dist/private/lib/access/db/saveResetReq.mjs +10 -7
  46. package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
  47. package/dist/private/lib/access/db/setEmailHash.d.mts +6 -1
  48. package/dist/private/lib/access/db/setEmailHash.mjs +9 -6
  49. package/dist/private/lib/access/db/setEmailHash.mjs.map +1 -1
  50. package/dist/private/lib/access/db/updatePasswordDb.d.mts +7 -1
  51. package/dist/private/lib/access/db/updatePasswordDb.mjs +6 -3
  52. package/dist/private/lib/access/db/updatePasswordDb.mjs.map +1 -1
  53. package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +6 -3
  54. package/dist/private/lib/access/db/userData4VerifyEmail.mjs +12 -5
  55. package/dist/private/lib/access/db/userData4VerifyEmail.mjs.map +1 -1
  56. package/dist/private/lib/access/handleIfHashBad.d.mts +10 -3
  57. package/dist/private/lib/access/handleIfHashBad.mjs +9 -5
  58. package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
  59. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +12 -1
  60. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +11 -3
  61. package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
  62. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +12 -1
  63. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +11 -3
  64. package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
  65. package/dist/private/lib/access/pathTools.d.mts +25 -0
  66. package/dist/private/lib/access/pathTools.mjs +43 -0
  67. package/dist/private/lib/access/pathTools.mjs.map +1 -0
  68. package/package.json +13 -1
@@ -1,13 +1,21 @@
1
1
  import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
2
2
  import { EMAIL_CHECK_LINK } from './Constants.mjs';
3
3
  import deleteUserByEmail from './db/deleteUserByEmail.mjs';
4
- export async function handleIfTooMuchRequestsTimes(uEmail, requestTimes = 99 // but it is already handled
4
+ /**
5
+ * Five wrong-hash attempts delete the pending account.
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.
9
+ */
10
+ export const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn) => async function handleIfTooMuchRequestsTimes(uEmail, requestTimes = 99 // but it is already handled
5
11
  ) {
6
12
  if (requestTimes >= 5) {
7
13
  const SocketLabsObj = new SocketLabsLib();
8
14
  await SocketLabsObj.tooMuchVerifyRequests(uEmail);
9
- await deleteUserByEmail(uEmail);
15
+ await deleteUserByEmailFn(uEmail);
10
16
  throw new Error(EMAIL_CHECK_LINK);
11
17
  }
12
- }
18
+ };
19
+ /** `UserBase`-bound default — the behaviour every existing consumer already imports. */
20
+ export const handleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail);
13
21
  //# 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,iBAAiB,MAAM,4BAA4B,CAAA;AAE1D,MAAM,CAAC,KAAK,UAAU,4BAA4B,CACjD,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,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAE/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail from './db/deleteUserByEmail.mjs'\n\nexport async function handleIfTooMuchRequestsTimes(\n\tuEmail: string,\n\trequestTimes: number = 99 // but it is already handled\n) {\n\tif (requestTimes >= 5) {\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.tooMuchVerifyRequests(uEmail)\n\n\t\tawait deleteUserByEmail(uEmail)\n\n\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t}\n}\n"]}
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"]}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Read a dotted mongo path out of a lean document.
3
+ *
4
+ * `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be
5
+ * walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path
6
+ * pointing at a field the document does not carry must read as "absent", exactly like a projection
7
+ * that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.
8
+ */
9
+ export declare function readPath(source: unknown, path: string): unknown;
10
+ /**
11
+ * Build a mongo `$unset` payload from a list of paths.
12
+ *
13
+ * The list is supplied by the caller, never derived from the fields that were written: a layout
14
+ * storing the reset request as one required subdocument can only be cleared by unsetting the
15
+ * container, not its members. See `IResetPwdPaths.resetClear`.
16
+ */
17
+ export declare function buildUnset(paths: readonly string[]): Record<string, ''>;
18
+ /**
19
+ * Build a `.select()` projection string, always including `_id`.
20
+ *
21
+ * Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the
22
+ * projection is simply absent, with no error — that is how a missing `account.email.requestTimes`
23
+ * turned every wrong-hash attempt into a 500 while the coverage gate stayed green.
24
+ */
25
+ export declare function buildProjection(paths: readonly string[]): string;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Read a dotted mongo path out of a lean document.
3
+ *
4
+ * `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be
5
+ * walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path
6
+ * pointing at a field the document does not carry must read as "absent", exactly like a projection
7
+ * that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.
8
+ */
9
+ export function readPath(source, path) {
10
+ let current = source;
11
+ for (const key of path.split('.')) {
12
+ if (current === null || typeof current !== 'object') {
13
+ return undefined;
14
+ }
15
+ current = current[key];
16
+ }
17
+ return current;
18
+ }
19
+ /**
20
+ * Build a mongo `$unset` payload from a list of paths.
21
+ *
22
+ * The list is supplied by the caller, never derived from the fields that were written: a layout
23
+ * storing the reset request as one required subdocument can only be cleared by unsetting the
24
+ * container, not its members. See `IResetPwdPaths.resetClear`.
25
+ */
26
+ export function buildUnset(paths) {
27
+ const unset = {};
28
+ for (const path of paths) {
29
+ unset[path] = '';
30
+ }
31
+ return unset;
32
+ }
33
+ /**
34
+ * Build a `.select()` projection string, always including `_id`.
35
+ *
36
+ * Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the
37
+ * projection is simply absent, with no error — that is how a missing `account.email.requestTimes`
38
+ * turned every wrong-hash attempt into a 500 while the coverage gate stayed green.
39
+ */
40
+ export function buildProjection(paths) {
41
+ return ['_id', ...paths].join(' ');
42
+ }
43
+ //# sourceMappingURL=pathTools.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathTools.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/pathTools.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAe,EAAE,IAAY;IACrD,IAAI,OAAO,GAAY,MAAM,CAAA;IAE7B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACrD,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,OAAO,GAAI,OAAmC,CAAC,GAAG,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IAClD,MAAM,KAAK,GAAuB,EAAE,CAAA;IAEpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACjB,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAwB;IACvD,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACnC,CAAC","sourcesContent":["/**\n * Read a dotted mongo path out of a lean document.\n *\n * `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be\n * walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path\n * pointing at a field the document does not carry must read as \"absent\", exactly like a projection\n * that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.\n */\nexport function readPath(source: unknown, path: string): unknown {\n\tlet current: unknown = source\n\n\tfor (const key of path.split('.')) {\n\t\tif (current === null || typeof current !== 'object') {\n\t\t\treturn undefined\n\t\t}\n\t\tcurrent = (current as Record<string, unknown>)[key]\n\t}\n\n\treturn current\n}\n\n/**\n * Build a mongo `$unset` payload from a list of paths.\n *\n * The list is supplied by the caller, never derived from the fields that were written: a layout\n * storing the reset request as one required subdocument can only be cleared by unsetting the\n * container, not its members. See `IResetPwdPaths.resetClear`.\n */\nexport function buildUnset(paths: readonly string[]): Record<string, ''> {\n\tconst unset: Record<string, ''> = {}\n\n\tfor (const path of paths) {\n\t\tunset[path] = ''\n\t}\n\n\treturn unset\n}\n\n/**\n * Build a `.select()` projection string, always including `_id`.\n *\n * Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the\n * projection is simply absent, with no error — that is how a missing `account.email.requestTimes`\n * turned every wrong-hash attempt into a 500 while the coverage gate stayed green.\n */\nexport function buildProjection(paths: readonly string[]): string {\n\treturn ['_id', ...paths].join(' ')\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiumine/koa-utils",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Koa Utils",
5
5
  "type": "module",
6
6
  "repository": {
@@ -51,6 +51,18 @@
51
51
  "@dataSources": "dist/dataSources"
52
52
  },
53
53
  "exports": {
54
+ "./lib/access/accessPaths": {
55
+ "import": "./dist/lib/access/accessPaths.mjs",
56
+ "types": "./dist/lib/access/accessPaths.d.mts"
57
+ },
58
+ "./lib/access/createResetPwdFlow": {
59
+ "import": "./dist/lib/access/createResetPwdFlow.mjs",
60
+ "types": "./dist/lib/access/createResetPwdFlow.d.mts"
61
+ },
62
+ "./lib/access/createVerifyEmailFlow": {
63
+ "import": "./dist/lib/access/createVerifyEmailFlow.mjs",
64
+ "types": "./dist/lib/access/createVerifyEmailFlow.d.mts"
65
+ },
54
66
  "./lib/MongoDB/IOnboarding": {
55
67
  "import": "./dist/lib/MongoDB/IOnboarding.mjs",
56
68
  "types": "./dist/lib/MongoDB/IOnboarding.d.mts"