@axiumine/koa-utils 5.4.1 → 5.6.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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/email/SocketLabsLib.mjs +0 -2
  3. package/dist/email/SocketLabsLib.mjs.map +1 -1
  4. package/dist/files/checkForNSFW.mjs +3 -3
  5. package/dist/files/checkForNSFW.mjs.map +1 -1
  6. package/dist/files/scanVirus.mjs +0 -3
  7. package/dist/files/scanVirus.mjs.map +1 -1
  8. package/dist/files/storeUploadAsTemp.mjs +0 -1
  9. package/dist/files/storeUploadAsTemp.mjs.map +1 -1
  10. package/dist/files/uploadTempImage.mjs +0 -2
  11. package/dist/files/uploadTempImage.mjs.map +1 -1
  12. package/dist/files/uploadTempPdf.mjs +0 -1
  13. package/dist/files/uploadTempPdf.mjs.map +1 -1
  14. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +0 -6
  15. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
  16. package/dist/graphQL/schema/mutations/login4Ever.mjs +0 -8
  17. package/dist/graphQL/schema/mutations/login4Ever.mjs.map +1 -1
  18. package/dist/graphQL/schema/mutations/loginAdmin.mjs +0 -1
  19. package/dist/graphQL/schema/mutations/loginAdmin.mjs.map +1 -1
  20. package/dist/graphQL/schema/mutations/loginRememberme.mjs +0 -1
  21. package/dist/graphQL/schema/mutations/loginRememberme.mjs.map +1 -1
  22. package/dist/graphQL/schema/mutations/refresh.mjs +0 -1
  23. package/dist/graphQL/schema/mutations/refresh.mjs.map +1 -1
  24. package/dist/graphQL/schema/mutations/resetPwd.mjs +1 -5
  25. package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
  26. package/dist/graphQL/schema/mutations/updatePassword.mjs +3 -4
  27. package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
  28. package/dist/koa/logRequestToDb.mjs +0 -11
  29. package/dist/koa/logRequestToDb.mjs.map +1 -1
  30. package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs +0 -1
  31. package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs.map +1 -1
  32. package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs +0 -4
  33. package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs.map +1 -1
  34. package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs +0 -5
  35. package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs.map +1 -1
  36. package/dist/koa/middleware/debug/index.mjs +0 -5
  37. package/dist/koa/middleware/debug/index.mjs.map +1 -1
  38. package/dist/lib/DateLib.mjs +1 -6
  39. package/dist/lib/DateLib.mjs.map +1 -1
  40. package/dist/lib/db/registerNewUser.mjs +0 -2
  41. package/dist/lib/db/registerNewUser.mjs.map +1 -1
  42. package/dist/private/files/_validateMimeType.mjs +0 -1
  43. package/dist/private/files/_validateMimeType.mjs.map +1 -1
  44. package/dist/private/graphQL/schema/mutations/_finalizeLoginCheck.mjs +0 -3
  45. package/dist/private/graphQL/schema/mutations/_finalizeLoginCheck.mjs.map +1 -1
  46. package/dist/private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs +0 -1
  47. package/dist/private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs.map +1 -1
  48. package/dist/private/graphQL/schema/mutations/infoUserAdminForLogin.mjs +0 -1
  49. package/dist/private/graphQL/schema/mutations/infoUserAdminForLogin.mjs.map +1 -1
  50. package/dist/private/graphQL/schema/mutations/infoUserForLogin.mjs +0 -1
  51. package/dist/private/graphQL/schema/mutations/infoUserForLogin.mjs.map +1 -1
  52. package/dist/private/lib/access/db/saveResetReq.mjs +0 -1
  53. package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
  54. package/package.json +1 -3
@@ -35,13 +35,11 @@ export const createResetPwdMutation = (deps) => ({
35
35
  const session = await mongoose.startSession();
36
36
  try {
37
37
  await session.withTransaction(async () => {
38
- // console.debug('email exists ?')
39
38
  // email exists? -> retrieve whether there have already been reset requests -> return 4xx ??
40
39
  const resetPwdVal = await deps.getResetPwd(session, uEmail);
41
40
  // don't reveal that the email doesn't exist, for privacy
42
41
  if (resetPwdVal === null)
43
42
  return;
44
- // console.debug("the email exists")
45
43
  // ok, email exists
46
44
  // -> wait 10 minutes from the last password reset request
47
45
  // if a password request already exists, read the date in seconds.
@@ -55,10 +53,8 @@ export const createResetPwdMutation = (deps) => ({
55
53
  // this flow. Both cases now return true and send nothing.
56
54
  let calculateHash = true;
57
55
  if (lastReq !== null) {
58
- // console.debug('reset request already made')
59
- // console.debug('previous pwd reset request: ' + lastReq + ' it is now ' + nowDt)
60
56
  calculateHash = DateLib.minElapsed(lastReq) >= 10;
61
- } //else console.debug('first reset request')
57
+ }
62
58
  if (calculateHash) {
63
59
  // generate hash for password reset
64
60
  const StrObj = new StringLib();
@@ -1 +1 @@
1
- {"version":3,"file":"resetPwd.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/resetPwd.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,cAAc,EAAE,mCAA0B;AACnD,OAAO,EAAE,OAAO,EAAE,iCAAwB;AAC1C,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAC9C,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,WAAW,EAAgB,uDAA8C;AAClF,OAAO,EAAE,YAAY,EAAiB,wDAA+C;AACrF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,cAAc,EAAgB,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACrF,OAAO,QAAQ,MAAM,UAAU,CAAA;AAmB/B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAmB,EAAE,EAAE,CAAC,CAAC;IAC/D,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AC,CAAC,CAAU,EAAE,EAAE;oBACpF,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;gBAC3B,CAAC,CAAC,CAAA;YACH,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACrB,oEAAoE;gBACpE,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;YAC3B,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,QAAQ,GAAsB,sBAAsB,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { EMAIL_HASH_LEN } from '@lib/Constants.mjs'\nimport { DateLib } from '@lib/DateLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { getResetPwd, TGetResetPwd } from '@private/lib/access/db/getResetPwd.mjs'\nimport { saveResetReq, TSaveResetReq } from '@private/lib/access/db/saveResetReq.mjs'\nimport * as Sentry from '@sentry/node'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose from 'mongoose'\n\n/** Arguments accepted by the `resetPwd` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IResetPwdArgs {\n\temail: string\n}\n\n/** What the committed transaction leaves behind for the post-commit send. */\ninterface IPendingMail {\n\thash: string\n\tname: string\n}\n\n/** Readers and writers the resolver needs, all bound to the same model + paths by the caller. */\nexport interface IResetPwdDeps {\n\tgetResetPwd: TGetResetPwd\n\tsaveResetReq: TSaveResetReq\n}\n\n/**\n * Take the user email and send an email with a link for change the password.\n * for privacy, true is returned whatever happens: unknown address, first request, or a request\n * throttled because the previous one is less than 10 minutes old. The caller can never tell them apart,\n * and the mail is queued after the commit without being awaited so the response time does not tell\n * them apart either.\n *\n * The collection and field layout live entirely in the injected reader/writer, so the same resolver\n * serves any account model. Nothing about the flow itself changes.\n */\nexport const createResetPwdMutation = (deps: IResetPwdDeps) => ({\n\tdescription: 'send reset password link',\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IResetPwdArgs) {\n\t\tconst { email } = args\n\n\t\tconst uEmail = email.toLowerCase().trim()\n\t\tcheckEmailLen(uEmail)\n\n\t\t// Set only when the transaction actually persisted a fresh reset request. The mail itself goes\n\t\t// out after the commit, and is not awaited — see the block below the transaction.\n\t\tlet pendingMail: IPendingMail | null = null\n\n\t\tconst session = await mongoose.startSession()\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\t// console.debug('email exists ?')\n\t\t\t\t// email exists? -> retrieve whether there have already been reset requests -> return 4xx ??\n\t\t\t\tconst resetPwdVal = await deps.getResetPwd(session, uEmail)\n\n\t\t\t\t// don't reveal that the email doesn't exist, for privacy\n\t\t\t\tif (resetPwdVal === null) return\n\t\t\t\t// console.debug(\"the email exists\")\n\n\t\t\t\t// ok, email exists\n\n\t\t\t\t// -> wait 10 minutes from the last password reset request\n\n\t\t\t\t// if a password request already exists, read the date in seconds.\n\t\t\t\tconst lastReq = typeof resetPwdVal.resetDateReq !== 'undefined' ? new Date('' + resetPwdVal.resetDateReq) : null\n\n\t\t\t\t// request already made previously?\n\t\t\t\t// send a new email with the recovery link only if the last one is at least 10 minutes old\n\t\t\t\tconst nowDt = new Date()\n\n\t\t\t\t// The throttle is enforced silently. Throwing 429 here answered \"this address is\n\t\t\t\t// registered and has a reset pending\" to an unauthenticated caller, while an unknown\n\t\t\t\t// address returned true — an enumeration oracle for any address that had been through\n\t\t\t\t// this flow. Both cases now return true and send nothing.\n\t\t\t\tlet calculateHash = true\n\t\t\t\tif (lastReq !== null) {\n\t\t\t\t\t// console.debug('reset request already made')\n\t\t\t\t\t// console.debug('previous pwd reset request: ' + lastReq + ' it is now ' + nowDt)\n\t\t\t\t\tcalculateHash = DateLib.minElapsed(lastReq) >= 10\n\t\t\t\t} //else console.debug('first reset request')\n\n\t\t\t\tif (calculateHash) {\n\t\t\t\t\t// generate hash for password reset\n\t\t\t\t\tconst StrObj = new StringLib()\n\t\t\t\t\tconst hash = StrObj.randomString(EMAIL_HASH_LEN)\n\n\t\t\t\t\t// set hash and current reset date\n\t\t\t\t\tawait deps.saveResetReq(session, resetPwdVal._id, nowDt, hash)\n\n\t\t\t\t\t// the mail is queued after the commit, not here\n\t\t\t\t\tpendingMail = { hash, name: resetPwdVal.name }\n\t\t\t\t} // calculateHash\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\t// Reached only on a committed transaction: tryCatchRethrow above always throws.\n\t\t//\n\t\t// Three reasons this send sits here and is deliberately not awaited:\n\t\t// 1. Timing. Awaiting a network round-trip to SocketLabs made the response measurably slower\n\t\t// exactly when the address was registered and not throttled — the same fact the removed 429\n\t\t// used to state outright. What is left is one extra updateOne, ~a millisecond against\n\t\t// internet jitter, and the 10-minute throttle caps an attacker at one sample per address,\n\t\t// so there is nothing to average out.\n\t\t// 2. Retries. session.withTransaction re-runs its callback on a transient error. With the send\n\t\t// inside, a retried commit mailed the user a second link and invalidated the first.\n\t\t// 3. Failure disclosure. A SocketLabs outage used to surface as a 500, which only an address\n\t\t// that actually exists could ever receive.\n\t\t// The cost is that a delivery failure is now visible in Sentry only, mail in flight is lost if\n\t\t// the process is killed before the request settles, and — the one a user feels — the hash is\n\t\t// already committed when the send fails, so the 10-minute throttle is armed for a link that\n\t\t// never arrived. Clearing resetHash/resetDateReq from the catch below to undo that was\n\t\t// considered and rejected: a rejected promise does not prove non-delivery, and a timeout after\n\t\t// SocketLabs accepted the message would kill a link already sitting in the user's inbox.\n\t\tconst mail = pendingMail as IPendingMail | null\n\t\tif (mail !== null) {\n\t\t\ttry {\n\t\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\t\tvoid SocketLabsObj.sendEmailReset(uEmail, mail.hash, mail.name).catch((e: unknown) => {\n\t\t\t\t\tSentry.captureException(e)\n\t\t\t\t})\n\t\t\t} catch (e: unknown) {\n\t\t\t\t// the constructor, or a synchronous throw before the promise exists\n\t\t\t\tSentry.captureException(e)\n\t\t\t}\n\t\t}\n\n\t\treturn true\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TResetPwdMutation = ReturnType<typeof createResetPwdMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const resetPwd: TResetPwdMutation = createResetPwdMutation({ getResetPwd, saveResetReq })\n"]}
1
+ {"version":3,"file":"resetPwd.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/resetPwd.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,cAAc,EAAE,mCAA0B;AACnD,OAAO,EAAE,OAAO,EAAE,iCAAwB;AAC1C,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAC9C,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,WAAW,EAAgB,uDAA8C;AAClF,OAAO,EAAE,YAAY,EAAiB,wDAA+C;AACrF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,cAAc,EAAgB,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACrF,OAAO,QAAQ,MAAM,UAAU,CAAA;AAmB/B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAmB,EAAE,EAAE,CAAC,CAAC;IAC/D,WAAW,EAAE,0BAA0B;IACvC,IAAI,EAAE,IAAI,cAAc,CAAC,cAAc,CAAC;IACx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,oEAAoE;gBACpE,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;YAC3B,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,QAAQ,GAAsB,sBAAsB,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { EMAIL_HASH_LEN } from '@lib/Constants.mjs'\nimport { DateLib } from '@lib/DateLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { getResetPwd, TGetResetPwd } from '@private/lib/access/db/getResetPwd.mjs'\nimport { saveResetReq, TSaveResetReq } from '@private/lib/access/db/saveResetReq.mjs'\nimport * as Sentry from '@sentry/node'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose from 'mongoose'\n\n/** Arguments accepted by the `resetPwd` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IResetPwdArgs {\n\temail: string\n}\n\n/** What the committed transaction leaves behind for the post-commit send. */\ninterface IPendingMail {\n\thash: string\n\tname: string\n}\n\n/** Readers and writers the resolver needs, all bound to the same model + paths by the caller. */\nexport interface IResetPwdDeps {\n\tgetResetPwd: TGetResetPwd\n\tsaveResetReq: TSaveResetReq\n}\n\n/**\n * Take the user email and send an email with a link for change the password.\n * for privacy, true is returned whatever happens: unknown address, first request, or a request\n * throttled because the previous one is less than 10 minutes old. The caller can never tell them apart,\n * and the mail is queued after the commit without being awaited so the response time does not tell\n * them apart either.\n *\n * The collection and field layout live entirely in the injected reader/writer, so the same resolver\n * serves any account model. Nothing about the flow itself changes.\n */\nexport const createResetPwdMutation = (deps: IResetPwdDeps) => ({\n\tdescription: 'send reset password link',\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IResetPwdArgs) {\n\t\tconst { email } = args\n\n\t\tconst uEmail = email.toLowerCase().trim()\n\t\tcheckEmailLen(uEmail)\n\n\t\t// Set only when the transaction actually persisted a fresh reset request. The mail itself goes\n\t\t// out after the commit, and is not awaited — see the block below the transaction.\n\t\tlet pendingMail: IPendingMail | null = null\n\n\t\tconst session = await mongoose.startSession()\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\t// email exists? -> retrieve whether there have already been reset requests -> return 4xx ??\n\t\t\t\tconst resetPwdVal = await deps.getResetPwd(session, uEmail)\n\n\t\t\t\t// don't reveal that the email doesn't exist, for privacy\n\t\t\t\tif (resetPwdVal === null) return\n\n\t\t\t\t// ok, email exists\n\n\t\t\t\t// -> wait 10 minutes from the last password reset request\n\n\t\t\t\t// if a password request already exists, read the date in seconds.\n\t\t\t\tconst lastReq = typeof resetPwdVal.resetDateReq !== 'undefined' ? new Date('' + resetPwdVal.resetDateReq) : null\n\n\t\t\t\t// request already made previously?\n\t\t\t\t// send a new email with the recovery link only if the last one is at least 10 minutes old\n\t\t\t\tconst nowDt = new Date()\n\n\t\t\t\t// The throttle is enforced silently. Throwing 429 here answered \"this address is\n\t\t\t\t// registered and has a reset pending\" to an unauthenticated caller, while an unknown\n\t\t\t\t// address returned true — an enumeration oracle for any address that had been through\n\t\t\t\t// this flow. Both cases now return true and send nothing.\n\t\t\t\tlet calculateHash = true\n\t\t\t\tif (lastReq !== null) {\n\t\t\t\t\tcalculateHash = DateLib.minElapsed(lastReq) >= 10\n\t\t\t\t}\n\n\t\t\t\tif (calculateHash) {\n\t\t\t\t\t// generate hash for password reset\n\t\t\t\t\tconst StrObj = new StringLib()\n\t\t\t\t\tconst hash = StrObj.randomString(EMAIL_HASH_LEN)\n\n\t\t\t\t\t// set hash and current reset date\n\t\t\t\t\tawait deps.saveResetReq(session, resetPwdVal._id, nowDt, hash)\n\n\t\t\t\t\t// the mail is queued after the commit, not here\n\t\t\t\t\tpendingMail = { hash, name: resetPwdVal.name }\n\t\t\t\t} // calculateHash\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\t// Reached only on a committed transaction: tryCatchRethrow above always throws.\n\t\t//\n\t\t// Three reasons this send sits here and is deliberately not awaited:\n\t\t// 1. Timing. Awaiting a network round-trip to SocketLabs made the response measurably slower\n\t\t// exactly when the address was registered and not throttled — the same fact the removed 429\n\t\t// used to state outright. What is left is one extra updateOne, ~a millisecond against\n\t\t// internet jitter, and the 10-minute throttle caps an attacker at one sample per address,\n\t\t// so there is nothing to average out.\n\t\t// 2. Retries. session.withTransaction re-runs its callback on a transient error. With the send\n\t\t// inside, a retried commit mailed the user a second link and invalidated the first.\n\t\t// 3. Failure disclosure. A SocketLabs outage used to surface as a 500, which only an address\n\t\t// that actually exists could ever receive.\n\t\t// The cost is that a delivery failure is now visible in Sentry only, mail in flight is lost if\n\t\t// the process is killed before the request settles, and — the one a user feels — the hash is\n\t\t// already committed when the send fails, so the 10-minute throttle is armed for a link that\n\t\t// never arrived. Clearing resetHash/resetDateReq from the catch below to undo that was\n\t\t// considered and rejected: a rejected promise does not prove non-delivery, and a timeout after\n\t\t// SocketLabs accepted the message would kill a link already sitting in the user's inbox.\n\t\tconst mail = pendingMail as IPendingMail | null\n\t\tif (mail !== null) {\n\t\t\ttry {\n\t\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\t\tvoid SocketLabsObj.sendEmailReset(uEmail, mail.hash, mail.name).catch((e: unknown) => {\n\t\t\t\t\tSentry.captureException(e)\n\t\t\t\t})\n\t\t\t} catch (e: unknown) {\n\t\t\t\t// the constructor, or a synchronous throw before the promise exists\n\t\t\t\tSentry.captureException(e)\n\t\t\t}\n\t\t}\n\n\t\treturn true\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TResetPwdMutation = ReturnType<typeof createResetPwdMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const resetPwd: TResetPwdMutation = createResetPwdMutation({ getResetPwd, saveResetReq })\n"]}
@@ -23,7 +23,6 @@ async function applyPasswordReset(deps, session, input) {
23
23
  if (resetPwd === null) {
24
24
  throw throwForbiddenError(); // don't reveal whether the email is present, for privacy
25
25
  }
26
- // console.debug('--email present')
27
26
  // No usable reset state. This is NOT an internal error as far as the caller is concerned:
28
27
  // answering 500 here while an unknown address answers 403 turns this mutation into an
29
28
  // account-enumeration oracle, because every registered account that has never requested a
@@ -42,16 +41,16 @@ async function applyPasswordReset(deps, session, input) {
42
41
  // check if hash is missing or invalid
43
42
  if (resetPwd.resetHash !== hash) {
44
43
  throw throwForbiddenError(); // don't reveal whether the email is present, for privacy
45
- } // else console.debug('--hash valid')
44
+ }
46
45
  // check if the request was made within 1 hour
47
46
  const dt1 = new Date('' + resetPwd.resetDateReq);
48
47
  if (DateLib.minElapsed(dt1) > 60) {
49
48
  throw throwForbiddenError(); // The link is no longer valid
50
- } // else console.debug('--link valid')
49
+ }
51
50
  const update = await deps.updatePasswordDb(session, resetPwd._id, password);
52
51
  if (!update) {
53
52
  throw throwInternalError(); // "System error while updating the password."
54
- } // else console.debug('--pwd updated')
53
+ }
55
54
  // delete password reset request data from db
56
55
  await deps.removeResetReq(session, uEmail);
57
56
  // the confirmation email is sent after the commit, not here
@@ -1 +1 @@
1
- {"version":3,"file":"updatePassword.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/updatePassword.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,WAAW,EAAE,qCAA4B;AAClD,OAAO,EAAE,OAAO,EAAE,iCAAwB;AAC1C,OAAO,EAAE,eAAe,EAAE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AED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,cAAc,GAA4B,4BAA4B,CAAC;IACnF,WAAW;IACX,gBAAgB;IAChB,cAAc;CACd,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { checkPwdLen } from '@lib/checkPwdLen.mjs'\nimport { DateLib } from '@lib/DateLib.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { getResetPwd, TGetResetPwd } from '@private/lib/access/db/getResetPwd.mjs'\nimport removeResetReq, { TRemoveResetReq } from '@private/lib/access/db/removeResetReq.mjs'\nimport updatePasswordDb, { TUpdatePasswordDb } from '@private/lib/access/db/updatePasswordDb.mjs'\nimport * as Sentry from '@sentry/node'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose, { ClientSession } from 'mongoose'\n\n/** Arguments accepted by the `updatePassword` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IUpdatePasswordArgs {\n\temail: string\n\thash: string\n\tpassword: string\n}\n\n/** Readers and writers the resolver needs, all bound to the same model + paths by the caller. */\nexport interface IUpdatePasswordDeps {\n\tgetResetPwd: TGetResetPwd\n\tupdatePasswordDb: TUpdatePasswordDb\n\tremoveResetReq: TRemoveResetReq\n}\n\n/** Normalised inputs the transaction body works on, bundled to keep it within the max-params budget. */\ninterface IUpdatePasswordInput {\n\tuEmail: string\n\thash: string\n\tpassword: string\n}\n\n/**\n * The transactional core: validate the reset hash, apply the new password and clear the request.\n * Extracted from resolve() only to keep it inside the max-lines-per-function budget — behaviour\n * unchanged. Returns the account holder's name so the caller can mail the post-commit confirmation.\n */\nasync function applyPasswordReset(\n\tdeps: IUpdatePasswordDeps,\n\tsession: ClientSession,\n\tinput: IUpdatePasswordInput\n): Promise<string> {\n\tconst { uEmail, hash, password } = input\n\tconst resetPwd = await deps.getResetPwd(session, uEmail)\n\n\t// check if email is present in db\n\tif (resetPwd === null) {\n\t\tthrow throwForbiddenError() // don't reveal whether the email is present, for privacy\n\t}\n\t// console.debug('--email present')\n\n\t// No usable reset state. This is NOT an internal error as far as the caller is concerned:\n\t// answering 500 here while an unknown address answers 403 turns this mutation into an\n\t// account-enumeration oracle, because every registered account that has never requested a\n\t// reset lands on this branch (getResetPwd yields resetHash === null whenever\n\t// account.resetDateReq is undefined). Same 403 as the unknown-address path; the orphan\n\t// state is reported to Sentry instead of to the caller.\n\tif (resetPwd.resetHash === null) {\n\t\tSentry.captureMessage(`[updatePassword] no usable resetHash for ${uEmail}`)\n\t\tthrow throwForbiddenError()\n\t}\n\t/* c8 ignore next 4 -- defensive guard, resetDateReq cannot be null when resetHash is set */\n\tif (resetPwd.resetDateReq === null) {\n\t\tSentry.captureMessage(`[updatePassword] resetHash set but resetDateReq missing for ${uEmail}`)\n\t\tthrow throwForbiddenError()\n\t}\n\n\t// check if hash is missing or invalid\n\tif (resetPwd.resetHash !== hash) {\n\t\tthrow throwForbiddenError() // don't reveal whether the email is present, for privacy\n\t} // else console.debug('--hash valid')\n\n\t// check if the request was made within 1 hour\n\tconst dt1 = new Date('' + resetPwd.resetDateReq)\n\tif (DateLib.minElapsed(dt1) > 60) {\n\t\tthrow throwForbiddenError() // The link is no longer valid\n\t} // else console.debug('--link valid')\n\n\tconst update = await deps.updatePasswordDb(session, resetPwd._id, password)\n\tif (!update) {\n\t\tthrow throwInternalError() // \"System error while updating the password.\"\n\t} // else console.debug('--pwd updated')\n\n\t// delete password reset request data from db\n\tawait deps.removeResetReq(session, uEmail)\n\n\t// the confirmation email is sent after the commit, not here\n\treturn resetPwd.name\n}\n\n/**\n * Change the password of an account holding a valid, unexpired reset hash.\n *\n * The collection and field layout live entirely in the injected reader/writers, so the same resolver\n * serves any account model. In particular the cleanup unsets whatever `resetClear` names, which is not\n * necessarily the two leaf paths this resolver reads — see `removeResetReq`.\n */\nexport const createUpdatePasswordMutation = (deps: IUpdatePasswordDeps) => ({\n\tdescription: \"changes the user's password\",\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\thash: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpassword: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IUpdatePasswordArgs) {\n\t\tconst { email, hash, password } = args\n\n\t\tconst uEmail = email.trim().toLowerCase()\n\t\tcheckEmailLen(uEmail)\n\t\tcheckPwdLen(password)\n\n\t\t// Set only once the transaction has actually persisted the new password. Carries the user's\n\t\t// name to the post-commit confirmation email.\n\t\tlet confirmTo: string | null = null\n\n\t\tconst session = await mongoose.startSession()\n\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\tconfirmTo = await applyPasswordReset(deps, session, { uEmail, hash, password })\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\t// Reached only on a committed transaction: tryCatchRethrow above always throws.\n\t\t//\n\t\t// The send sits here rather than inside the callback because session.withTransaction re-runs\n\t\t// its callback on a transient error, and a retried commit therefore mailed the user a second\n\t\t// \"your password was changed\" notice. It is still awaited — unlike resetPwd there is no timing\n\t\t// oracle to close here, since reaching this point at all requires a valid reset hash.\n\t\t//\n\t\t// A delivery failure no longer fails the request. It used to abort the transaction and answer\n\t\t// 500, rolling back the password change with it — consistent, but it made the mail provider a\n\t\t// hard dependency: with SocketLabs down, nobody could complete a reset at all. The password is\n\t\t// committed by the time we get here, so the failure goes to Sentry and the caller still gets\n\t\t// true. The confirmation is a notice, not part of the operation.\n\t\t//\n\t\t// Don't \"restore\" the abort: there is no transaction left to abort at this point. Rethrowing\n\t\t// would report 500 for a password that is already live, and compensating would mean writing\n\t\t// back the old bcrypt hash, which this flow never reads. Moving the send back inside the\n\t\t// callback brings back the duplicate notice AND lets a mail go out for a commit that then\n\t\t// fails — an email cannot be recalled.\n\t\tconst name = confirmTo as string | null\n\t\tif (name !== null) {\n\t\t\ttry {\n\t\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\t\tawait SocketLabsObj.sendResetPwdConfirmation(uEmail, name)\n\t\t\t} catch (e: unknown) {\n\t\t\t\tSentry.captureException(e)\n\t\t\t}\n\t\t}\n\n\t\treturn true\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TUpdatePasswordMutation = ReturnType<typeof createUpdatePasswordMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const updatePassword: TUpdatePasswordMutation = createUpdatePasswordMutation({\n\tgetResetPwd,\n\tupdatePasswordDb,\n\tremoveResetReq\n})\n"]}
1
+ {"version":3,"file":"updatePassword.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/updatePassword.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,WAAW,EAAE,qCAA4B;AAClD,OAAO,EAAE,OAAO,EAAE,iCAAwB;AAC1C,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,WAAW,EAAgB,uDAA8C;AAClF,OAAO,cAAmC,0DAAiD;AAC3F,OAAO,gBAAuC,4DAAmD;AACjG,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,4CAAsC;AACpE,OAAO,EAAE,kBAAkB,EAAE,2CAAqC;AAClE,OAAO,EAAE,cAAc,EAAgB,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACrF,OAAO,QAA2B,MAAM,UAAU,CAAA;AAuBlD;;;;G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EAAE,QAAQ,EAAE,CAAC,CAAA;YAChF,CAAC,CAAC,CAAA;QACH,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACrB,eAAe,CAAC,CAAyB,CAAC,CAAA;QAC3C,CAAC;gBAAS,CAAC;YACV,MAAM,OAAO,CAAC,UAAU,EAAE,CAAA;QAC3B,CAAC;QAED,gFAAgF;QAChF,EAAE;QACF,6FAA6F;QAC7F,6FAA6F;QAC7F,+FAA+F;QAC/F,sFAAsF;QACtF,EAAE;QACF,8FAA8F;QAC9F,8FAA8F;QAC9F,+FAA+F;QAC/F,6FAA6F;QAC7F,iEAAiE;QACjE,EAAE;QACF,6FAA6F;QAC7F,4FAA4F;QAC5F,yFAAyF;QACzF,0FAA0F;QAC1F,uCAAuC;QACvC,MAAM,IAAI,GAAG,SAA0B,CAAA;QACvC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC;gBACJ,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;gBACzC,MAAM,aAAa,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;YAC3D,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACrB,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;YAC3B,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,cAAc,GAA4B,4BAA4B,CAAC;IACnF,WAAW;IACX,gBAAgB;IAChB,cAAc;CACd,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { checkPwdLen } from '@lib/checkPwdLen.mjs'\nimport { DateLib } from '@lib/DateLib.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { getResetPwd, TGetResetPwd } from '@private/lib/access/db/getResetPwd.mjs'\nimport removeResetReq, { TRemoveResetReq } from '@private/lib/access/db/removeResetReq.mjs'\nimport updatePasswordDb, { TUpdatePasswordDb } from '@private/lib/access/db/updatePasswordDb.mjs'\nimport * as Sentry from '@sentry/node'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose, { ClientSession } from 'mongoose'\n\n/** Arguments accepted by the `updatePassword` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IUpdatePasswordArgs {\n\temail: string\n\thash: string\n\tpassword: string\n}\n\n/** Readers and writers the resolver needs, all bound to the same model + paths by the caller. */\nexport interface IUpdatePasswordDeps {\n\tgetResetPwd: TGetResetPwd\n\tupdatePasswordDb: TUpdatePasswordDb\n\tremoveResetReq: TRemoveResetReq\n}\n\n/** Normalised inputs the transaction body works on, bundled to keep it within the max-params budget. */\ninterface IUpdatePasswordInput {\n\tuEmail: string\n\thash: string\n\tpassword: string\n}\n\n/**\n * The transactional core: validate the reset hash, apply the new password and clear the request.\n * Extracted from resolve() only to keep it inside the max-lines-per-function budget — behaviour\n * unchanged. Returns the account holder's name so the caller can mail the post-commit confirmation.\n */\nasync function applyPasswordReset(\n\tdeps: IUpdatePasswordDeps,\n\tsession: ClientSession,\n\tinput: IUpdatePasswordInput\n): Promise<string> {\n\tconst { uEmail, hash, password } = input\n\tconst resetPwd = await deps.getResetPwd(session, uEmail)\n\n\t// check if email is present in db\n\tif (resetPwd === null) {\n\t\tthrow throwForbiddenError() // don't reveal whether the email is present, for privacy\n\t}\n\n\t// No usable reset state. This is NOT an internal error as far as the caller is concerned:\n\t// answering 500 here while an unknown address answers 403 turns this mutation into an\n\t// account-enumeration oracle, because every registered account that has never requested a\n\t// reset lands on this branch (getResetPwd yields resetHash === null whenever\n\t// account.resetDateReq is undefined). Same 403 as the unknown-address path; the orphan\n\t// state is reported to Sentry instead of to the caller.\n\tif (resetPwd.resetHash === null) {\n\t\tSentry.captureMessage(`[updatePassword] no usable resetHash for ${uEmail}`)\n\t\tthrow throwForbiddenError()\n\t}\n\t/* c8 ignore next 4 -- defensive guard, resetDateReq cannot be null when resetHash is set */\n\tif (resetPwd.resetDateReq === null) {\n\t\tSentry.captureMessage(`[updatePassword] resetHash set but resetDateReq missing for ${uEmail}`)\n\t\tthrow throwForbiddenError()\n\t}\n\n\t// check if hash is missing or invalid\n\tif (resetPwd.resetHash !== hash) {\n\t\tthrow throwForbiddenError() // don't reveal whether the email is present, for privacy\n\t}\n\n\t// check if the request was made within 1 hour\n\tconst dt1 = new Date('' + resetPwd.resetDateReq)\n\tif (DateLib.minElapsed(dt1) > 60) {\n\t\tthrow throwForbiddenError() // The link is no longer valid\n\t}\n\n\tconst update = await deps.updatePasswordDb(session, resetPwd._id, password)\n\tif (!update) {\n\t\tthrow throwInternalError() // \"System error while updating the password.\"\n\t}\n\n\t// delete password reset request data from db\n\tawait deps.removeResetReq(session, uEmail)\n\n\t// the confirmation email is sent after the commit, not here\n\treturn resetPwd.name\n}\n\n/**\n * Change the password of an account holding a valid, unexpired reset hash.\n *\n * The collection and field layout live entirely in the injected reader/writers, so the same resolver\n * serves any account model. In particular the cleanup unsets whatever `resetClear` names, which is not\n * necessarily the two leaf paths this resolver reads — see `removeResetReq`.\n */\nexport const createUpdatePasswordMutation = (deps: IUpdatePasswordDeps) => ({\n\tdescription: \"changes the user's password\",\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\thash: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpassword: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IUpdatePasswordArgs) {\n\t\tconst { email, hash, password } = args\n\n\t\tconst uEmail = email.trim().toLowerCase()\n\t\tcheckEmailLen(uEmail)\n\t\tcheckPwdLen(password)\n\n\t\t// Set only once the transaction has actually persisted the new password. Carries the user's\n\t\t// name to the post-commit confirmation email.\n\t\tlet confirmTo: string | null = null\n\n\t\tconst session = await mongoose.startSession()\n\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\tconfirmTo = await applyPasswordReset(deps, session, { uEmail, hash, password })\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\t// Reached only on a committed transaction: tryCatchRethrow above always throws.\n\t\t//\n\t\t// The send sits here rather than inside the callback because session.withTransaction re-runs\n\t\t// its callback on a transient error, and a retried commit therefore mailed the user a second\n\t\t// \"your password was changed\" notice. It is still awaited — unlike resetPwd there is no timing\n\t\t// oracle to close here, since reaching this point at all requires a valid reset hash.\n\t\t//\n\t\t// A delivery failure no longer fails the request. It used to abort the transaction and answer\n\t\t// 500, rolling back the password change with it — consistent, but it made the mail provider a\n\t\t// hard dependency: with SocketLabs down, nobody could complete a reset at all. The password is\n\t\t// committed by the time we get here, so the failure goes to Sentry and the caller still gets\n\t\t// true. The confirmation is a notice, not part of the operation.\n\t\t//\n\t\t// Don't \"restore\" the abort: there is no transaction left to abort at this point. Rethrowing\n\t\t// would report 500 for a password that is already live, and compensating would mean writing\n\t\t// back the old bcrypt hash, which this flow never reads. Moving the send back inside the\n\t\t// callback brings back the duplicate notice AND lets a mail go out for a commit that then\n\t\t// fails — an email cannot be recalled.\n\t\tconst name = confirmTo as string | null\n\t\tif (name !== null) {\n\t\t\ttry {\n\t\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\t\tawait SocketLabsObj.sendResetPwdConfirmation(uEmail, name)\n\t\t\t} catch (e: unknown) {\n\t\t\t\tSentry.captureException(e)\n\t\t\t}\n\t\t}\n\n\t\treturn true\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TUpdatePasswordMutation = ReturnType<typeof createUpdatePasswordMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const updatePassword: TUpdatePasswordMutation = createUpdatePasswordMutation({\n\tgetResetPwd,\n\tupdatePasswordDb,\n\tremoveResetReq\n})\n"]}
@@ -1,16 +1,5 @@
1
- import { OBJECTID_0_OBJ } from "../lib/Constants.mjs";
2
1
  export async function logRequestToDb(ctx, next) {
3
- // here ${ctx.request.body?.operationName} is undefined
4
- const method = ctx.method;
5
- console.debug(`${method} ${ctx.url}\n\r`);
6
- const start = Date.now();
7
2
  await next();
8
- const now = Date.now();
9
- const msTot = now - start;
10
- const user = ctx.state.user?.id || OBJECTID_0_OBJ;
11
- const operationName = ctx.request.body?.operationName;
12
- const status = ctx.status;
13
- console.debug(`${status} ${operationName} executed by ${user.toString()} - ${msTot}ms\n\r---------------`);
14
3
  // logGraphql(user, operationName, status, msTot)
15
4
  }
16
5
  //# sourceMappingURL=logRequestToDb.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"logRequestToDb.mjs","sourceRoot":"","sources":["../../src/koa/logRequestToDb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,6BAA0B;AAInD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAgB,EAAE,IAAU;IAChE,uDAAuD;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;IACzB,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,MAAM,IAAI,EAAE,CAAA;IAEZ,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAA;IAEzB,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,cAAc,CAAA;IACjD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAA;IACrD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAA;IACzB,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,aAAa,gBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,KAAK,uBAAuB,CAAC,CAAA;IAE1G,iDAAiD;AAClD,CAAC","sourcesContent":["import { OBJECTID_0_OBJ } from '@lib/Constants.mjs'\nimport { IContextLog } from '@private/graphQL/schema/context/IContextLog.mjs'\nimport { Next } from 'koa'\n\nexport async function logRequestToDb(ctx: IContextLog, next: Next) {\n\t// here ${ctx.request.body?.operationName} is undefined\n\tconst method = ctx.method\n\tconsole.debug(`${method} ${ctx.url}\\n\\r`)\n\tconst start = Date.now()\n\tawait next()\n\n\tconst now = Date.now()\n\tconst msTot = now - start\n\n\tconst user = ctx.state.user?.id || OBJECTID_0_OBJ\n\tconst operationName = ctx.request.body?.operationName\n\tconst status = ctx.status\n\tconsole.debug(`${status} ${operationName} executed by ${user.toString()} - ${msTot}ms\\n\\r---------------`)\n\n\t// logGraphql(user, operationName, status, msTot)\n}\n"]}
1
+ {"version":3,"file":"logRequestToDb.mjs","sourceRoot":"","sources":["../../src/koa/logRequestToDb.mts"],"names":[],"mappings":"AAGA,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAgB,EAAE,IAAU;IAChE,MAAM,IAAI,EAAE,CAAA;IAEZ,iDAAiD;AAClD,CAAC","sourcesContent":["import { IContextLog } from '@private/graphQL/schema/context/IContextLog.mjs'\nimport { Next } from 'koa'\n\nexport async function logRequestToDb(ctx: IContextLog, next: Next) {\n\tawait next()\n\n\t// logGraphql(user, operationName, status, msTot)\n}\n"]}
@@ -8,7 +8,6 @@ import { Types } from 'mongoose';
8
8
  import { verifySignedRefreshToken } from './verifySignedRefreshToken.mjs';
9
9
  dotenv.config();
10
10
  export const authenticatedAuthorizationHandler = (keys) => async (ctx, next) => {
11
- // console.debug('[authorizationHandler] ')
12
11
  /***************************
13
12
  * CLIENT:
14
13
  * - sends opaque token as cookie
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/authenticatedAuthorizationHandler/index.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,uCAA8B;AACpD,OAAO,EAAE,gBAAgB,EAAE,0CAAiC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,yDAAgD;AAClF,OAAO,EAAE,mBAAmB,EAAE,uDAAsC;AACpE,OAAO,EAAE,iCAAiC,EAAE,qEAAoD;AAChG,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAGhC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAEzE,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,KAAK,EAAE,GAAoB,EAAE,IAAU,EAAE,EAAE;IAC9G,2CAA2C;IAE3C;;;OAGG;IAEH,8CAA8C;IAC9C,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC7D,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,iBAAiB,EAAE,CAAC,CAAA;IAC5F,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,EAAE,GAAG,UAAU,EAAE,CAAA,CAAC,mGAAmG;QAErI,6EAA6E;QAC7E,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,mBAAmB,EAAE,CAAA;QAC5B,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG;YAChB,GAAG,OAAO;YACV,EAAE,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,YAAY,EAAE,iBAAiB;SAC/B,CAAA;IACF,CAAC;SAAM,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC;QAClF,MAAM,iCAAiC,EAAE,CAAA;IAC1C,CAAC,CAAC,qBAAqB;IAEvB,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { redisClient } from '@dataSources/Redis.mjs'\nimport { isSessionBlocked } from '@lib/isSessionBlocked.mjs'\nimport { verifyIntrospectionCode } from '@private/lib/verifyIntrospectionCode.mjs'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { throwRefreshTokenExpiredOrDeleted } from '@throw/throwRefreshTokenExpiredOrDeleted.mjs'\nimport * as dotenv from 'dotenv'\nimport Keygrip from 'keygrip'\nimport { Next } from 'koa'\nimport { Types } from 'mongoose'\n\nimport { verifySignedRefreshToken } from './verifySignedRefreshToken.mjs'\n\ndotenv.config()\n\nexport const authenticatedAuthorizationHandler = (keys: Keygrip) => async (ctx: IContextRefresh, next: Next) => {\n\t// console.debug('[authorizationHandler] ')\n\n\t/***************************\n\t * CLIENT:\n\t * - sends opaque token as cookie\n\t */\n\n\t// does the key exist in redis? ok, read redis\n\tconst refreshTokenRedis = verifySignedRefreshToken(ctx, keys)\n\tconst redSession = await redisClient.hGetAll(`${process.env.REDIS_KEY}${refreshTokenRedis}`)\n\tif (Object.keys(redSession).length !== 0) {\n\t\tconst redData = { ...redSession } // For safety, Redis return an object without the default Object.prototype in its prototype chain.\n\n\t\t// is the user reported as blocked within the session? (see isSessionBlocked)\n\t\tif (isSessionBlocked(redData)) {\n\t\t\tthrow throwForbiddenError()\n\t\t}\n\t\tctx.state.user = {\n\t\t\t...redData,\n\t\t\tid: new Types.ObjectId(redData.id),\n\t\t\trefreshToken: refreshTokenRedis\n\t\t}\n\t} else if (!verifyIntrospectionCode(ctx.request.header?.['x-introspectioncode'])) {\n\t\tthrow throwRefreshTokenExpiredOrDeleted()\n\t} // else return next()\n\n\treturn next()\n}\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/authenticatedAuthorizationHandler/index.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,uCAA8B;AACpD,OAAO,EAAE,gBAAgB,EAAE,0CAAiC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,yDAAgD;AAClF,OAAO,EAAE,mBAAmB,EAAE,uDAAsC;AACpE,OAAO,EAAE,iCAAiC,EAAE,qEAAoD;AAChG,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAGhC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAEzE,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,KAAK,EAAE,GAAoB,EAAE,IAAU,EAAE,EAAE;IAC9G;;;OAGG;IAEH,8CAA8C;IAC9C,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC7D,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,iBAAiB,EAAE,CAAC,CAAA;IAC5F,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,EAAE,GAAG,UAAU,EAAE,CAAA,CAAC,mGAAmG;QAErI,6EAA6E;QAC7E,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,mBAAmB,EAAE,CAAA;QAC5B,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG;YAChB,GAAG,OAAO;YACV,EAAE,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,YAAY,EAAE,iBAAiB;SAC/B,CAAA;IACF,CAAC;SAAM,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC;QAClF,MAAM,iCAAiC,EAAE,CAAA;IAC1C,CAAC,CAAC,qBAAqB;IAEvB,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { redisClient } from '@dataSources/Redis.mjs'\nimport { isSessionBlocked } from '@lib/isSessionBlocked.mjs'\nimport { verifyIntrospectionCode } from '@private/lib/verifyIntrospectionCode.mjs'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { throwRefreshTokenExpiredOrDeleted } from '@throw/throwRefreshTokenExpiredOrDeleted.mjs'\nimport * as dotenv from 'dotenv'\nimport Keygrip from 'keygrip'\nimport { Next } from 'koa'\nimport { Types } from 'mongoose'\n\nimport { verifySignedRefreshToken } from './verifySignedRefreshToken.mjs'\n\ndotenv.config()\n\nexport const authenticatedAuthorizationHandler = (keys: Keygrip) => async (ctx: IContextRefresh, next: Next) => {\n\t/***************************\n\t * CLIENT:\n\t * - sends opaque token as cookie\n\t */\n\n\t// does the key exist in redis? ok, read redis\n\tconst refreshTokenRedis = verifySignedRefreshToken(ctx, keys)\n\tconst redSession = await redisClient.hGetAll(`${process.env.REDIS_KEY}${refreshTokenRedis}`)\n\tif (Object.keys(redSession).length !== 0) {\n\t\tconst redData = { ...redSession } // For safety, Redis return an object without the default Object.prototype in its prototype chain.\n\n\t\t// is the user reported as blocked within the session? (see isSessionBlocked)\n\t\tif (isSessionBlocked(redData)) {\n\t\t\tthrow throwForbiddenError()\n\t\t}\n\t\tctx.state.user = {\n\t\t\t...redData,\n\t\t\tid: new Types.ObjectId(redData.id),\n\t\t\trefreshToken: refreshTokenRedis\n\t\t}\n\t} else if (!verifyIntrospectionCode(ctx.request.header?.['x-introspectioncode'])) {\n\t\tthrow throwRefreshTokenExpiredOrDeleted()\n\t} // else return next()\n\n\treturn next()\n}\n"]}
@@ -5,7 +5,6 @@ import { throwUnauthorizedError } from "../../../graphQL/throw/throwUnauthorized
5
5
  export function verifySignedRefreshToken(ctx, keys) {
6
6
  // @todo must check the cookie or the header or both, and what to do if one of the two is missing ??
7
7
  const cookieHeader = ctx.request.header?.cookie;
8
- // console.debug('ctx.request.header', ctx.request.header)
9
8
  if (cookieHeader === undefined) {
10
9
  throw throwPreconditionFailedNoAuthCookie();
11
10
  }
@@ -26,8 +25,6 @@ export function verifySignedRefreshToken(ctx, keys) {
26
25
  if (!signature) {
27
26
  throw throwRefreshTokenSignatureRequired();
28
27
  }
29
- // console.debug('refreshToken', refreshToken)
30
- // console.debug('signature', signature)
31
28
  // Verify signature
32
29
  // Verify signature with Keygrip
33
30
  const index = keys.index(`refresh_token=${refreshToken}`, signature);
@@ -35,7 +32,6 @@ export function verifySignedRefreshToken(ctx, keys) {
35
32
  // Signature invalid
36
33
  throw throwUnauthorizedError('Invalid Refresh Cookie signature');
37
34
  }
38
- // console.debug('signature OK')
39
35
  return `refresh:${refreshToken}`;
40
36
  }
41
37
  //# sourceMappingURL=verifySignedRefreshToken.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"verifySignedRefreshToken.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,mCAAmC,EAAE,uEAAsD;AACpG,OAAO,EAAE,yBAAyB,EAAE,6DAA4C;AAChF,OAAO,EAAE,kCAAkC,EAAE,sEAAqD;AAClG,OAAO,EAAE,sBAAsB,EAAE,0DAAyC;AAK1E,MAAM,UAAU,wBAAwB,CAAC,GAAoB,EAAE,IAAa;IAC3E,oGAAoG;IAEpG,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAA;IAC/C,0DAA0D;IAE1D,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,mCAAmC,EAAE,CAAA;IAC5C,CAAC;IAED,MAAM,OAAO,GAAwB,EAAE,CAAA;IACvC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAC1C,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC7C,qCAAqC;QACrC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACrB,CAAC,CAAC,CAAA;IACF;;OAEG;IACH,MAAM,YAAY,GAAG,OAAO,EAAE,aAAa,CAAA;IAC3C,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,MAAM,yBAAyB,EAAE,CAAA;IAClC,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,mBAAmB,CAAC,CAAA;IAChD,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,MAAM,kCAAkC,EAAE,CAAA;IAC3C,CAAC;IACD,8CAA8C;IAC9C,wCAAwC;IAExC,mBAAmB;IACnB,gCAAgC;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,YAAY,EAAE,EAAE,SAAS,CAAC,CAAA;IAEpE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,oBAAoB;QACpB,MAAM,sBAAsB,CAAC,kCAAkC,CAAC,CAAA;IACjE,CAAC;IACD,gCAAgC;IAEhC,OAAO,WAAW,YAAY,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { throwPreconditionFailedNoAuthCookie } from '@throw/throwPreconditionFailedNoAuthCookie.mjs'\nimport { throwRefreshTokenRequired } from '@throw/throwRefreshTokenRequired.mjs'\nimport { throwRefreshTokenSignatureRequired } from '@throw/throwRefreshTokenSignatureRequired.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport Keygrip from 'keygrip'\n\nimport { TCookieRefreshToken } from './TCookieRefreshToken.mjs'\n\nexport function verifySignedRefreshToken(ctx: IContextRefresh, keys: Keygrip): string {\n\t// @todo must check the cookie or the header or both, and what to do if one of the two is missing ??\n\n\tconst cookieHeader = ctx.request.header?.cookie\n\t// console.debug('ctx.request.header', ctx.request.header)\n\n\tif (cookieHeader === undefined) {\n\t\tthrow throwPreconditionFailedNoAuthCookie()\n\t}\n\n\tconst cookies: TCookieRefreshToken = {}\n\tcookieHeader.split(';').forEach((cookie) => {\n\t\tconst [key, value] = cookie.trim().split('=')\n\t\t// @ts-expect-error ignore wrong keys\n\t\tcookies[key] = value\n\t})\n\t/**\n\t * 'refresh_token=27119032-9043-4a9f-bd4c-9d06fd576290; refresh_token.sig=P1gZO6-49xVEMkiMqkOjJ2Cxaf3mQb18GaflDsjibuv4fFWYIOzcW26didnVJ1aridyY40CFzDtufzI6zI8jkQ'\n\t */\n\tconst refreshToken = cookies?.refresh_token\n\tif (!refreshToken) {\n\t\tthrow throwRefreshTokenRequired()\n\t}\n\tconst signature = cookies?.['refresh_token.sig']\n\tif (!signature) {\n\t\tthrow throwRefreshTokenSignatureRequired()\n\t}\n\t// console.debug('refreshToken', refreshToken)\n\t// console.debug('signature', signature)\n\n\t// Verify signature\n\t// Verify signature with Keygrip\n\tconst index = keys.index(`refresh_token=${refreshToken}`, signature)\n\n\tif (index === -1) {\n\t\t// Signature invalid\n\t\tthrow throwUnauthorizedError('Invalid Refresh Cookie signature')\n\t}\n\t// console.debug('signature OK')\n\n\treturn `refresh:${refreshToken}`\n}\n"]}
1
+ {"version":3,"file":"verifySignedRefreshToken.mjs","sourceRoot":"","sources":["../../../../src/koa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oB;QACpB,MAAM,sBAAsB,CAAC,kCAAkC,CAAC,CAAA;IACjE,CAAC;IAED,OAAO,WAAW,YAAY,EAAE,CAAA;AACjC,CAAC","sourcesContent":["import { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { throwPreconditionFailedNoAuthCookie } from '@throw/throwPreconditionFailedNoAuthCookie.mjs'\nimport { throwRefreshTokenRequired } from '@throw/throwRefreshTokenRequired.mjs'\nimport { throwRefreshTokenSignatureRequired } from '@throw/throwRefreshTokenSignatureRequired.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport Keygrip from 'keygrip'\n\nimport { TCookieRefreshToken } from './TCookieRefreshToken.mjs'\n\nexport function verifySignedRefreshToken(ctx: IContextRefresh, keys: Keygrip): string {\n\t// @todo must check the cookie or the header or both, and what to do if one of the two is missing ??\n\n\tconst cookieHeader = ctx.request.header?.cookie\n\n\tif (cookieHeader === undefined) {\n\t\tthrow throwPreconditionFailedNoAuthCookie()\n\t}\n\n\tconst cookies: TCookieRefreshToken = {}\n\tcookieHeader.split(';').forEach((cookie) => {\n\t\tconst [key, value] = cookie.trim().split('=')\n\t\t// @ts-expect-error ignore wrong keys\n\t\tcookies[key] = value\n\t})\n\t/**\n\t * 'refresh_token=27119032-9043-4a9f-bd4c-9d06fd576290; refresh_token.sig=P1gZO6-49xVEMkiMqkOjJ2Cxaf3mQb18GaflDsjibuv4fFWYIOzcW26didnVJ1aridyY40CFzDtufzI6zI8jkQ'\n\t */\n\tconst refreshToken = cookies?.refresh_token\n\tif (!refreshToken) {\n\t\tthrow throwRefreshTokenRequired()\n\t}\n\tconst signature = cookies?.['refresh_token.sig']\n\tif (!signature) {\n\t\tthrow throwRefreshTokenSignatureRequired()\n\t}\n\n\t// Verify signature\n\t// Verify signature with Keygrip\n\tconst index = keys.index(`refresh_token=${refreshToken}`, signature)\n\n\tif (index === -1) {\n\t\t// Signature invalid\n\t\tthrow throwUnauthorizedError('Invalid Refresh Cookie signature')\n\t}\n\n\treturn `refresh:${refreshToken}`\n}\n"]}
@@ -22,11 +22,6 @@ export const authenticatedLogoutHandler = (keys) => async (ctx, next) => {
22
22
  * - in authorization: ctx.request.header.authorization = Bearer ACCESS_TOKEN_HERE
23
23
  * - in cookie: ctx.request.header.cookie = refresh_cookie=TOKEN_HERE
24
24
  */
25
- /*
26
- if (typeof ctx.request.header?.operation !== 'undefined') {
27
- const operationName = ctx.request.header.operation
28
- console.debug('[authorizationHandler] operationName: ', operationName)
29
- } */
30
25
  let introspection = false;
31
26
  // refresh
32
27
  const cookie = ctx.request.header?.cookie; // refresh
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/authenticatedLogoutHandler/index.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,uCAA8B;AACpD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,uBAAuB,EAAE,yDAAgD;AAClF,OAAO,EAAE,gBAAgB,EAAE,oDAAmC;AAC9D,OAAO,EAAE,mCAAmC,EAAE,uEAAsD;AACpG,OAAO,EAAE,mCAAmC,EAAE,uEAAsD;AACpG,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAIhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mEAAmE,CAAA;AAE5G,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,2BAA2B,GAAG,CAAC,MAA2C,EAAE,WAAwB,EAAQ,EAAE;IACnH,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,uBAAuB,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC;QAC7F,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,MAAM,WAAW,EAAE,CAAA;AACpB,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,aAAiC,EAAU,EAAE,CAC9E,aAAa,EAAE,UAAU,CAAC,gBAAgB,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,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,CAAC;QAED,yBAAyB;QACzB,6EAA6E;QAC7E,0FAA0F;QAC1F,kGAAkG;QAClG,2FAA2F;QAC3F,oDAAoD;QACpD,MAAM,WAAW,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAA;QAC3D,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;YACxB,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,WAAW,EAAE,EAAE,IAAI,CAAC,CAAA,CAAC,4BAA4B;YAC5H,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;gBAC9B,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;YACzC,CAAC,CAAC,4CAA4C;QAC/C,CAAC;IACF,CAAC,CAAC,qBAAqB;IACvB,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { IContextLogout } from '@context/IContextLogout.mjs'\nimport { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { redisClient } from '@dataSources/Redis.mjs'\nimport { isValidUuidV4 } from '@lib/isValidUuidV4.mjs'\nimport { verifyIntrospectionCode } from '@private/lib/verifyIntrospectionCode.mjs'\nimport { throwAlreadyDone } from '@throw/throwAlreadyDone.mjs'\nimport { throwPreconditionFailedNoAuthCookie } from '@throw/throwPreconditionFailedNoAuthCookie.mjs'\nimport { throwPreconditionFailedNoAuthHeader } from '@throw/throwPreconditionFailedNoAuthHeader.mjs'\nimport * as dotenv from 'dotenv'\nimport Keygrip from 'keygrip'\nimport { Next } from 'koa'\n\nimport { verifySignedRefreshToken } from '../authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs'\n\ndotenv.config()\n\nconst requireIntrospectionOrThrow = (header: IContextLogout['request']['header'], throwOnFail: () => never): true => {\n\tif (typeof header !== 'undefined' && verifyIntrospectionCode(header['x-introspectioncode'])) {\n\t\treturn true\n\t}\n\tthrow throwOnFail()\n}\n\nconst extractBearerAccessToken = (authorization: string | undefined): string =>\n\tauthorization?.startsWith('Bearer access:') && isValidUuidV4(authorization.slice('Bearer access:'.length))\n\t\t? authorization.replace('Bearer ', '')\n\t\t: ''\n\nexport const authenticatedLogoutHandler = (keys: Keygrip) => async (ctx: IContextLogout, next: Next) => {\n\t/***************************\n\t * CLIENT:\n\t * - in authorization: ctx.request.header.authorization = Bearer ACCESS_TOKEN_HERE\n\t * - in cookie: ctx.request.header.cookie = refresh_cookie=TOKEN_HERE\n\t */\n\t/*\n\tif (typeof ctx.request.header?.operation !== 'undefined') {\n\t\tconst operationName = ctx.request.header.operation\n\t\tconsole.debug('[authorizationHandler] operationName: ', operationName)\n\t} */\n\tlet introspection = false\n\n\t// refresh\n\tconst cookie = ctx.request.header?.cookie // refresh\n\tif (typeof cookie === 'undefined') {\n\t\tintrospection = requireIntrospectionOrThrow(ctx.request.header, throwPreconditionFailedNoAuthCookie)\n\t}\n\n\tconst authorization = ctx.request.header?.authorization // access\n\tif (typeof authorization === 'undefined') {\n\t\tintrospection = requireIntrospectionOrThrow(ctx.request.header, throwPreconditionFailedNoAuthHeader)\n\t}\n\n\tif (!introspection) {\n\t\tconst refreshToken = verifySignedRefreshToken(ctx as unknown as IContextRefresh, keys)\n\t\tconst redRefreshSession = await redisClient.hGet(`${process.env.REDIS_KEY}${refreshToken}`, 'id')\n\t\tif (redRefreshSession != null) {\n\t\t\tctx.state = {\n\t\t\t\tuser: {\n\t\t\t\t\trefreshToken: refreshToken\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow throwAlreadyDone()\n\t\t}\n\n\t\t// Access Token, optional\n\t\t// The 'Bearer access:' prefix must be checked before building the Redis key:\n\t\t// without this check the client controls the entire key and could reach refresh: entries.\n\t\t// The suffix is checked too: the prefix alone still leaves the rest of the key client-controlled.\n\t\t// Tokens with the wrong prefix, or a suffix that is not a v4 uuid, are ignored rather than\n\t\t// rejected: the access token remains optional here.\n\t\tconst accessToken = extractBearerAccessToken(authorization)\n\t\tif (accessToken !== '') {\n\t\t\tconst redAccessSession = await redisClient.hGet(`${process.env.REDIS_KEY}${accessToken}`, 'id') // 'access:' already present\n\t\t\tif (redAccessSession != null) {\n\t\t\t\tctx.state.user.accessToken = accessToken\n\t\t\t} // else no problem, session could be expired\n\t\t}\n\t} // else introspection\n\treturn next()\n}\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/authenticatedLogoutHandler/index.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,uCAA8B;AACpD,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,uBAAuB,EAAE,yDAAgD;AAClF,OAAO,EAAE,gBAAgB,EAAE,oDAAmC;AAC9D,OAAO,EAAE,mCAAmC,EAAE,uEAAsD;AACpG,OAAO,EAAE,mCAAmC,EAAE,uEAAsD;AACpG,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAIhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mEAAmE,CAAA;AAE5G,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,2BAA2B,GAAG,CAAC,MAA2C,EAAE,WAAwB,EAAQ,EAAE;IACnH,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,uBAAuB,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC;QAC7F,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,MAAM,WAAW,EAAE,CAAA;AACpB,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,aAAiC,EAAU,EAAE,CAC9E,aAAa,EAAE,UAAU,CAAC,gBAAgB,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;IACtC,CAAC,CAAC,EAAE,CAAA;AAEN,MAAM,CAAC,MAA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,EAAE,EAAE,CAAC;YACxB,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,WAAW,EAAE,EAAE,IAAI,CAAC,CAAA,CAAC,4BAA4B;YAC5H,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;gBAC9B,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;YACzC,CAAC,CAAC,4CAA4C;QAC/C,CAAC;IACF,CAAC,CAAC,qBAAqB;IACvB,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { IContextLogout } from '@context/IContextLogout.mjs'\nimport { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { redisClient } from '@dataSources/Redis.mjs'\nimport { isValidUuidV4 } from '@lib/isValidUuidV4.mjs'\nimport { verifyIntrospectionCode } from '@private/lib/verifyIntrospectionCode.mjs'\nimport { throwAlreadyDone } from '@throw/throwAlreadyDone.mjs'\nimport { throwPreconditionFailedNoAuthCookie } from '@throw/throwPreconditionFailedNoAuthCookie.mjs'\nimport { throwPreconditionFailedNoAuthHeader } from '@throw/throwPreconditionFailedNoAuthHeader.mjs'\nimport * as dotenv from 'dotenv'\nimport Keygrip from 'keygrip'\nimport { Next } from 'koa'\n\nimport { verifySignedRefreshToken } from '../authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs'\n\ndotenv.config()\n\nconst requireIntrospectionOrThrow = (header: IContextLogout['request']['header'], throwOnFail: () => never): true => {\n\tif (typeof header !== 'undefined' && verifyIntrospectionCode(header['x-introspectioncode'])) {\n\t\treturn true\n\t}\n\tthrow throwOnFail()\n}\n\nconst extractBearerAccessToken = (authorization: string | undefined): string =>\n\tauthorization?.startsWith('Bearer access:') && isValidUuidV4(authorization.slice('Bearer access:'.length))\n\t\t? authorization.replace('Bearer ', '')\n\t\t: ''\n\nexport const authenticatedLogoutHandler = (keys: Keygrip) => async (ctx: IContextLogout, next: Next) => {\n\t/***************************\n\t * CLIENT:\n\t * - in authorization: ctx.request.header.authorization = Bearer ACCESS_TOKEN_HERE\n\t * - in cookie: ctx.request.header.cookie = refresh_cookie=TOKEN_HERE\n\t */\n\tlet introspection = false\n\n\t// refresh\n\tconst cookie = ctx.request.header?.cookie // refresh\n\tif (typeof cookie === 'undefined') {\n\t\tintrospection = requireIntrospectionOrThrow(ctx.request.header, throwPreconditionFailedNoAuthCookie)\n\t}\n\n\tconst authorization = ctx.request.header?.authorization // access\n\tif (typeof authorization === 'undefined') {\n\t\tintrospection = requireIntrospectionOrThrow(ctx.request.header, throwPreconditionFailedNoAuthHeader)\n\t}\n\n\tif (!introspection) {\n\t\tconst refreshToken = verifySignedRefreshToken(ctx as unknown as IContextRefresh, keys)\n\t\tconst redRefreshSession = await redisClient.hGet(`${process.env.REDIS_KEY}${refreshToken}`, 'id')\n\t\tif (redRefreshSession != null) {\n\t\t\tctx.state = {\n\t\t\t\tuser: {\n\t\t\t\t\trefreshToken: refreshToken\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow throwAlreadyDone()\n\t\t}\n\n\t\t// Access Token, optional\n\t\t// The 'Bearer access:' prefix must be checked before building the Redis key:\n\t\t// without this check the client controls the entire key and could reach refresh: entries.\n\t\t// The suffix is checked too: the prefix alone still leaves the rest of the key client-controlled.\n\t\t// Tokens with the wrong prefix, or a suffix that is not a v4 uuid, are ignored rather than\n\t\t// rejected: the access token remains optional here.\n\t\tconst accessToken = extractBearerAccessToken(authorization)\n\t\tif (accessToken !== '') {\n\t\t\tconst redAccessSession = await redisClient.hGet(`${process.env.REDIS_KEY}${accessToken}`, 'id') // 'access:' already present\n\t\t\tif (redAccessSession != null) {\n\t\t\t\tctx.state.user.accessToken = accessToken\n\t\t\t} // else no problem, session could be expired\n\t\t}\n\t} // else introspection\n\treturn next()\n}\n"]}
@@ -1,9 +1,4 @@
1
- import * as console from 'node:console';
2
1
  export const debugHandler = () => async (ctx, next) => {
3
- console.debug('[debugHandler]', new Date());
4
- console.debug('[debugHandler] ctx.request.header:', ctx.request.header);
5
- console.debug('[debugHandler] ctx.request.header.cookie:', ctx.request.header?.cookie);
6
- console.debug('[debugHandler] ctx.cookies[refresh_token]:', ctx.cookies.get('refresh_token'));
7
2
  return next();
8
3
  };
9
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/debug/index.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAKvC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,GAAoB,EAAE,IAAU,EAAE,EAAE;IAC5E,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;IAC3C,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtF,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAA;IAE7F,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import * as console from 'node:console'\n\nimport { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { Next } from 'koa'\n\nexport const debugHandler = () => async (ctx: IContextRefresh, next: Next) => {\n\tconsole.debug('[debugHandler]', new Date())\n\tconsole.debug('[debugHandler] ctx.request.header:', ctx.request.header)\n\tconsole.debug('[debugHandler] ctx.request.header.cookie:', ctx.request.header?.cookie)\n\tconsole.debug('[debugHandler] ctx.cookies[refresh_token]:', ctx.cookies.get('refresh_token'))\n\n\treturn next()\n}\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/koa/middleware/debug/index.mts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,GAAoB,EAAE,IAAU,EAAE,EAAE;IAC5E,OAAO,IAAI,EAAE,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { IContextRefresh } from '@context/IContextRefresh.mjs'\nimport { Next } from 'koa'\n\nexport const debugHandler = () => async (ctx: IContextRefresh, next: Next) => {\n\treturn next()\n}\n"]}
@@ -15,17 +15,12 @@ export const DateLib = class DateLib {
15
15
  };
16
16
  }
17
17
  static minElapsed(dt) {
18
- // print dates being compared
19
18
  // read elapsed minutes
20
19
  const nowDt = new Date();
21
20
  const now = nowDt.getTime();
22
- console.debug('last sent time: ', new Date('' + dt));
23
- console.debug('current time : ', nowDt);
24
21
  const lastReq = dt.getTime();
25
22
  // const lastReq = new Date('' + dt).getTime()
26
- const elapsed = DateLib.timeDiffMin(lastReq, now);
27
- console.debug('minutes elapsed: ', elapsed);
28
- return elapsed;
23
+ return DateLib.timeDiffMin(lastReq, now);
29
24
  }
30
25
  static timeDiffMin(lastReq, now) {
31
26
  const difference = lastReq > now ? lastReq - now : now - lastReq;
@@ -1 +1 @@
1
- {"version":3,"file":"DateLib.mjs","sourceRoot":"","sources":["../../src/lib/DateLib.mts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,OAAO;IACnC,gBAAe,CAAC;IAEhB,MAAM,CAAC,OAAO,CAAC,OAAa;QAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;QAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/C,MAAM,GAAG,GAAG,QAAQ,C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,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAA;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAA;IAC5C,CAAC;CACD,CAAA,CAAC,oBAAoB","sourcesContent":["export const DateLib = class DateLib {\n\tconstructor() {}\n\n\tstatic getDate(dateNum: Date) {\n\t\tconst dateStr = dateNum.toString()\n\t\tconst year = parseInt(dateStr.substring(0, 4))\n\t\tconst month = parseInt(dateStr.substring(4, 6))\n\t\tconst day = parseInt(dateStr.substring(6, 8))\n\t\tconst hours = parseInt(dateStr.substring(8, 10))\n\t\tconst min = parseInt(dateStr.substring(10, 12))\n\t\tconst sec = parseInt(dateStr.substring(12, 14))\n\n\t\tconst date = new Date(Date.UTC(year, month - 1, day, hours, min, sec))\n\n\t\treturn {\n\t\t\tyear,\n\t\t\tdate\n\t\t}\n\t}\n\n\tstatic minElapsed(dt: Date): number {\n\t\t// print dates being compared\n\n\t\t// read elapsed minutes\n\t\tconst nowDt = new Date()\n\t\tconst now = nowDt.getTime()\n\n\t\tconsole.debug('last sent time: ', new Date('' + dt))\n\t\tconsole.debug('current time : ', nowDt)\n\n\t\tconst lastReq = dt.getTime()\n\t\t// const lastReq = new Date('' + dt).getTime()\n\n\t\tconst elapsed = DateLib.timeDiffMin(lastReq, now)\n\t\tconsole.debug('minutes elapsed: ', elapsed)\n\t\treturn elapsed\n\t}\n\n\tstatic timeDiffMin(lastReq: number, now: number): number {\n\t\tconst difference = lastReq > now ? lastReq - now : now - lastReq\n\t\treturn Math.floor(difference / (1000 * 60))\n\t}\n} /* c8 ignore next */\n"]}
1
+ {"version":3,"file":"DateLib.mjs","sourceRoot":"","sources":["../../src/lib/DateLib.mts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,OAAO;IACnC,gBAAe,CAAC;IAEhB,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AAe,EAAE,GAAW;QAC9C,MAAM,UAAU,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAA;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAA;IAC5C,CAAC;CACD,CAAA,CAAC,oBAAoB","sourcesContent":["export const DateLib = class DateLib {\n\tconstructor() {}\n\n\tstatic getDate(dateNum: Date) {\n\t\tconst dateStr = dateNum.toString()\n\t\tconst year = parseInt(dateStr.substring(0, 4))\n\t\tconst month = parseInt(dateStr.substring(4, 6))\n\t\tconst day = parseInt(dateStr.substring(6, 8))\n\t\tconst hours = parseInt(dateStr.substring(8, 10))\n\t\tconst min = parseInt(dateStr.substring(10, 12))\n\t\tconst sec = parseInt(dateStr.substring(12, 14))\n\n\t\tconst date = new Date(Date.UTC(year, month - 1, day, hours, min, sec))\n\n\t\treturn {\n\t\t\tyear,\n\t\t\tdate\n\t\t}\n\t}\n\n\tstatic minElapsed(dt: Date): number {\n\t\t// read elapsed minutes\n\t\tconst nowDt = new Date()\n\t\tconst now = nowDt.getTime()\n\n\t\tconst lastReq = dt.getTime()\n\t\t// const lastReq = new Date('' + dt).getTime()\n\n\t\treturn DateLib.timeDiffMin(lastReq, now)\n\t}\n\n\tstatic timeDiffMin(lastReq: number, now: number): number {\n\t\tconst difference = lastReq > now ? lastReq - now : now - lastReq\n\t\treturn Math.floor(difference / (1000 * 60))\n\t}\n} /* c8 ignore next */\n"]}
@@ -3,7 +3,6 @@ import { encryptPassword } from "../encryptPassword.mjs";
3
3
  import { UserBase } from "../../graphQL/models/MongoDB/UserBase.mjs";
4
4
  import { Types } from 'mongoose';
5
5
  export async function registerNewUser(uEmail, password, session) {
6
- // console.debug('new user')
7
6
  const userId = new Types.ObjectId();
8
7
  const nowDt = new Date();
9
8
  const hashConfirmEmail = emailHash();
@@ -26,7 +25,6 @@ export async function registerNewUser(uEmail, password, session) {
26
25
  }
27
26
  }
28
27
  ];
29
- console.debug('newUsers: ', JSON.stringify(newUsers, undefined, 2));
30
28
  await UserBase.create(newUsers, { session });
31
29
  return hashConfirmEmail;
32
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"registerNewUser.mjs","sourceRoot":"","sources":["../../../src/lib/db/registerNewUser.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,yBAA0B;AAC9C,OAAO,EAAE,eAAe,EAAE,+BAAgC;AAC1D,OAAO,EAAE,QAAQ,EAAE,kDAAoC;AACvD,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAsB;IAC7F,4BAA4B;IAC5B,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;IACxB,MAAM,gBAAgB,GAAG,SAAS,EAAE,CAAA;IACpC,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAA;IAE3C,MAAM,QAAQ,GAAG;QAChB;YACC,GAAG,EAAE,MAAM;YACX,KAAK,EAAE;gBACN,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,GAAG;aACb;YACD,OAAO,EAAE;gBACR,KAAK,EAAE;oBACN,KAAK,EAAE,KAAK;oBACZ,WAAW,EAAE,KAAK;oBAClB,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,gBAAgB;iBACtB;gBACD,gBAAgB,EAAE,KAAK;aACvB;SACD;KACD,CAAA;IACD,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAA;IAEnE,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5C,OAAO,gBAAgB,CAAA;AACxB,CAAC","sourcesContent":["import { emailHash } from '@lib/emailHash.mjs'\nimport { encryptPassword } from '@lib/encryptPassword.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport async function registerNewUser(uEmail: string, password: string, session: ClientSession) {\n\t// console.debug('new user')\n\tconst userId = new Types.ObjectId()\n\tconst nowDt = new Date()\n\tconst hashConfirmEmail = emailHash()\n\tconst pwd = await encryptPassword(password)\n\n\tconst newUsers = [\n\t\t{\n\t\t\t_id: userId,\n\t\t\tlogin: {\n\t\t\t\temail: uEmail,\n\t\t\t\tpassword: pwd\n\t\t\t},\n\t\t\taccount: {\n\t\t\t\temail: {\n\t\t\t\t\tvalid: false,\n\t\t\t\t\tdateLastReq: nowDt,\n\t\t\t\t\trequestTimes: 1,\n\t\t\t\t\thash: hashConfirmEmail\n\t\t\t\t},\n\t\t\t\tregistrationDate: nowDt\n\t\t\t}\n\t\t}\n\t]\n\tconsole.debug('newUsers: ', JSON.stringify(newUsers, undefined, 2))\n\n\tawait UserBase.create(newUsers, { session })\n\treturn hashConfirmEmail\n}\n"]}
1
+ {"version":3,"file":"registerNewUser.mjs","sourceRoot":"","sources":["../../../src/lib/db/registerNewUser.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,yBAA0B;AAC9C,OAAO,EAAE,eAAe,EAAE,+BAAgC;AAC1D,OAAO,EAAE,QAAQ,EAAE,kDAAoC;AACvD,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAsB;IAC7F,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;IACxB,MAAM,gBAAgB,GAAG,SAAS,EAAE,CAAA;IACpC,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAA;IAE3C,MAAM,QAAQ,GAAG;QAChB;YACC,GAAG,EAAE,MAAM;YACX,KAAK,EAAE;gBACN,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,GAAG;aACb;YACD,OAAO,EAAE;gBACR,KAAK,EAAE;oBACN,KAAK,EAAE,KAAK;oBACZ,WAAW,EAAE,KAAK;oBAClB,YAAY,EAAE,CAAC;oBACf,IAAI,EAAE,gBAAgB;iBACtB;gBACD,gBAAgB,EAAE,KAAK;aACvB;SACD;KACD,CAAA;IAED,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAC5C,OAAO,gBAAgB,CAAA;AACxB,CAAC","sourcesContent":["import { emailHash } from '@lib/emailHash.mjs'\nimport { encryptPassword } from '@lib/encryptPassword.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport async function registerNewUser(uEmail: string, password: string, session: ClientSession) {\n\tconst userId = new Types.ObjectId()\n\tconst nowDt = new Date()\n\tconst hashConfirmEmail = emailHash()\n\tconst pwd = await encryptPassword(password)\n\n\tconst newUsers = [\n\t\t{\n\t\t\t_id: userId,\n\t\t\tlogin: {\n\t\t\t\temail: uEmail,\n\t\t\t\tpassword: pwd\n\t\t\t},\n\t\t\taccount: {\n\t\t\t\temail: {\n\t\t\t\t\tvalid: false,\n\t\t\t\t\tdateLastReq: nowDt,\n\t\t\t\t\trequestTimes: 1,\n\t\t\t\t\thash: hashConfirmEmail\n\t\t\t\t},\n\t\t\t\tregistrationDate: nowDt\n\t\t\t}\n\t\t}\n\t]\n\n\tawait UserBase.create(newUsers, { session })\n\treturn hashConfirmEmail\n}\n"]}
@@ -7,7 +7,6 @@ export const _validateMimeType = async (filePath, allowedMimeTypes) => {
7
7
  // Dynamically import the file-type module
8
8
  const { fileTypeFromFile } = await import('file-type');
9
9
  const fileType = await fileTypeFromFile(filePath); // Get the file type from the file
10
- //console.debug('fileType', fileType)
11
10
  if (!fileType)
12
11
  return ''; // Could not detect file type
13
12
  // Check if the detected MIME type is allowed and is so, return file extension
@@ -1 +1 @@
1
- {"version":3,"file":"_validateMimeType.mjs","sourceRoot":"","sources":["../../../src/private/files/_validateMimeType.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,QAAgB,EAAE,gBAA0B,EAAmB,EAAE;IACxG,0CAA0C;IAC1C,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAA;IAEtD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAA,CAAC,kCAAkC;IACpF,qCAAqC;IACrC,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAA,CAAC,6BAA6B;IACtD,8EAA8E;IAC9E,IAAI,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,OAAO,QAAQ,CAAC,GAAG,CAAA;IACpB,CAAC;SAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACV,CAAC;AACF,CAAC,CAAA","sourcesContent":["/**\n * Utility function to validate MIME type via magic number\n * @param filePath\n * @param allowedMimeTypes\n */\nexport const _validateMimeType = async (filePath: string, allowedMimeTypes: string[]): Promise<string> => {\n\t// Dynamically import the file-type module\n\tconst { fileTypeFromFile } = await import('file-type')\n\n\tconst fileType = await fileTypeFromFile(filePath) // Get the file type from the file\n\t//console.debug('fileType', fileType)\n\tif (!fileType) return '' // Could not detect file type\n\t// Check if the detected MIME type is allowed and is so, return file extension\n\tif (allowedMimeTypes.includes(fileType.mime)) {\n\t\treturn fileType.ext\n\t} else {\n\t\treturn ''\n\t}\n}\n"]}
1
+ {"version":3,"file":"_validateMimeType.mjs","sourceRoot":"","sources":["../../../src/private/files/_validateMimeType.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,QAAgB,EAAE,gBAA0B,EAAmB,EAAE;IACxG,0CAA0C;IAC1C,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAA;IAEtD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAA,CAAC,kCAAkC;IACpF,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAA,CAAC,6BAA6B;IACtD,8EAA8E;IAC9E,IAAI,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,OAAO,QAAQ,CAAC,GAAG,CAAA;IACpB,CAAC;SAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACV,CAAC;AACF,CAAC,CAAA","sourcesContent":["/**\n * Utility function to validate MIME type via magic number\n * @param filePath\n * @param allowedMimeTypes\n */\nexport const _validateMimeType = async (filePath: string, allowedMimeTypes: string[]): Promise<string> => {\n\t// Dynamically import the file-type module\n\tconst { fileTypeFromFile } = await import('file-type')\n\n\tconst fileType = await fileTypeFromFile(filePath) // Get the file type from the file\n\tif (!fileType) return '' // Could not detect file type\n\t// Check if the detected MIME type is allowed and is so, return file extension\n\tif (allowedMimeTypes.includes(fileType.mime)) {\n\t\treturn fileType.ext\n\t} else {\n\t\treturn ''\n\t}\n}\n"]}
@@ -7,15 +7,12 @@ export async function _finalizeLoginCheck(user, uEmail, password) {
7
7
  }
8
8
  const ret = await compareHashAsync(password, user.login.password);
9
9
  if (!ret) {
10
- // console.debug('[checkUserLoginAuthorization] pwd failed')
11
10
  throw throwForbiddenError();
12
11
  }
13
12
  if (user.account.deleted) {
14
- // console.debug('[checkUserLoginAuthorization] user deleted')
15
13
  throw throwForbiddenError();
16
14
  }
17
15
  if (user.account.disabled) {
18
- // console.debug('[checkUserLoginAuthorization] user disabled')
19
16
  const SocketLabsObj = new SocketLabsLib();
20
17
  await SocketLabsObj.accountDisabled(uEmail);
21
18
  throw throwForbiddenError();
@@ -1 +1 @@
1
- {"version":3,"file":"_finalizeLoginCheck.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/_finalizeLoginCheck.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4CAAgC;AACxD,OAAO,EAAE,gBAAgB,EAAE,iCAAqB;AAChD,OAAO,EAAE,mBAAmB,EAAE,0DAAsC;AASpE,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAqB,EAAE,MAAc,EAAE,QAAgB;IAChG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAEjE,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,4DAA4D;QAC5D,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1B,8DAA8D;QAC9D,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC3B,+DAA+D;QAC/D,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC3C,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,OAAO;QACN,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI;KACvC,CAAA;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { compareHashAsync } from '@lib/hash.mjs'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { Types } from 'mongoose'\n\nexport interface ILoginUserShape {\n\t_id: Types.ObjectId\n\tlogin: { password: string; lastLogin?: Date }\n\taccount: { email: { valid: boolean }; disabled?: boolean; deleted?: boolean }\n}\n\nexport async function _finalizeLoginCheck(user: ILoginUserShape, uEmail: string, password: string) {\n\tif (!user.account.email.valid) {\n\t\tthrow throwForbiddenError()\n\t}\n\n\tconst ret = await compareHashAsync(password, user.login.password)\n\n\tif (!ret) {\n\t\t// console.debug('[checkUserLoginAuthorization] pwd failed')\n\t\tthrow throwForbiddenError()\n\t}\n\n\tif (user.account.deleted) {\n\t\t// console.debug('[checkUserLoginAuthorization] user deleted')\n\t\tthrow throwForbiddenError()\n\t}\n\n\tif (user.account.disabled) {\n\t\t// console.debug('[checkUserLoginAuthorization] user disabled')\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.accountDisabled(uEmail)\n\t\tthrow throwForbiddenError()\n\t}\n\n\treturn {\n\t\tuserId: user._id,\n\t\tlastLogin: user.login.lastLogin ?? null\n\t}\n}\n"]}
1
+ {"version":3,"file":"_finalizeLoginCheck.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/_finalizeLoginCheck.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4CAAgC;AACxD,OAAO,EAAE,gBAAgB,EAAE,iCAAqB;AAChD,OAAO,EAAE,mBAAmB,EAAE,0DAAsC;AASpE,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAqB,EAAE,MAAc,EAAE,QAAgB;IAChG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAEjE,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC3B,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC3C,MAAM,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED,OAAO;QACN,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI;KACvC,CAAA;AACF,CAAC","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { compareHashAsync } from '@lib/hash.mjs'\nimport { throwForbiddenError } from '@throw/throwForbiddenError.mjs'\nimport { Types } from 'mongoose'\n\nexport interface ILoginUserShape {\n\t_id: Types.ObjectId\n\tlogin: { password: string; lastLogin?: Date }\n\taccount: { email: { valid: boolean }; disabled?: boolean; deleted?: boolean }\n}\n\nexport async function _finalizeLoginCheck(user: ILoginUserShape, uEmail: string, password: string) {\n\tif (!user.account.email.valid) {\n\t\tthrow throwForbiddenError()\n\t}\n\n\tconst ret = await compareHashAsync(password, user.login.password)\n\n\tif (!ret) {\n\t\tthrow throwForbiddenError()\n\t}\n\n\tif (user.account.deleted) {\n\t\tthrow throwForbiddenError()\n\t}\n\n\tif (user.account.disabled) {\n\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\tawait SocketLabsObj.accountDisabled(uEmail)\n\t\tthrow throwForbiddenError()\n\t}\n\n\treturn {\n\t\tuserId: user._id,\n\t\tlastLogin: user.login.lastLogin ?? null\n\t}\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import { _finalizeLoginCheck } from './_finalizeLoginCheck.mjs';
2
2
  import { infoUserForLogin } from './infoUserForLogin.mjs';
3
3
  export async function checkUserLoginAuthorization(uEmail, password, session) {
4
- //console.debug('[checkUserLoginAuthorization] infoUserForLogin')
5
4
  const user = await infoUserForLogin(uEmail, session);
6
5
  return _finalizeLoginCheck(user, uEmail, password);
7
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"checkUserLoginAuthorization.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/checkUserLoginAuthorization.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAsB;IACzG,iEAAiE;IACjE,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEpD,OAAO,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AACnD,CAAC","sourcesContent":["import { ClientSession } from 'mongoose'\n\nimport { _finalizeLoginCheck } from './_finalizeLoginCheck.mjs'\nimport { infoUserForLogin } from './infoUserForLogin.mjs'\n\nexport async function checkUserLoginAuthorization(uEmail: string, password: string, session: ClientSession) {\n\t//console.debug('[checkUserLoginAuthorization] infoUserForLogin')\n\tconst user = await infoUserForLogin(uEmail, session)\n\n\treturn _finalizeLoginCheck(user, uEmail, password)\n}\n"]}
1
+ {"version":3,"file":"checkUserLoginAuthorization.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/checkUserLoginAuthorization.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAsB;IACzG,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEpD,OAAO,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AACnD,CAAC","sourcesContent":["import { ClientSession } from 'mongoose'\n\nimport { _finalizeLoginCheck } from './_finalizeLoginCheck.mjs'\nimport { infoUserForLogin } from './infoUserForLogin.mjs'\n\nexport async function checkUserLoginAuthorization(uEmail: string, password: string, session: ClientSession) {\n\tconst user = await infoUserForLogin(uEmail, session)\n\n\treturn _finalizeLoginCheck(user, uEmail, password)\n}\n"]}
@@ -5,7 +5,6 @@ export async function infoUserAdminForLogin(email, session) {
5
5
  .select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')
6
6
  .session(session)
7
7
  .exec();
8
- // console.debug('[infoUserForLogin] ret: ', ret);
9
8
  if (ret === null)
10
9
  throw throwUnauthorizedError();
11
10
  return ret;
@@ -1 +1 @@
1
- {"version":3,"file":"infoUserAdminForLogin.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/infoUserAdminForLogin.mts"],"names":[],"mappings":"AAAA,OAAO,iBAA6C,2DAAqE;AACzH,OAAO,EAAE,sBAAsB,EAAE,6DAAyC;AAG1E,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAa,EAAE,OAAsB;IAChF,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;SACnE,MAAM,CAAC,yEAAyE,GAAG,kBAAkB,CAAC;SACtG,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IACR,kDAAkD;IAElD,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,sBAAsB,EAAE,CAAA;IAEhD,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["import UserAdminKoaUtils, { IInfoUserAdminForLogin } from '@private/graphQL/models/MongoDB/private/UserAdminKoaUtils.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport async function infoUserAdminForLogin(email: string, session: ClientSession): Promise<IInfoUserAdminForLogin> {\n\tconst ret = await UserAdminKoaUtils.findOne({ 'login.email': email })\n\t\t.select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')\n\t\t.session(session)\n\t\t.exec()\n\t// console.debug('[infoUserForLogin] ret: ', ret);\n\n\tif (ret === null) throw throwUnauthorizedError()\n\n\treturn ret\n}\n"]}
1
+ {"version":3,"file":"infoUserAdminForLogin.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/infoUserAdminForLogin.mts"],"names":[],"mappings":"AAAA,OAAO,iBAA6C,2DAAqE;AACzH,OAAO,EAAE,sBAAsB,EAAE,6DAAyC;AAG1E,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAa,EAAE,OAAsB;IAChF,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;SACnE,MAAM,CAAC,yEAAyE,GAAG,kBAAkB,CAAC;SACtG,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IAER,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,sBAAsB,EAAE,CAAA;IAEhD,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["import UserAdminKoaUtils, { IInfoUserAdminForLogin } from '@private/graphQL/models/MongoDB/private/UserAdminKoaUtils.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport async function infoUserAdminForLogin(email: string, session: ClientSession): Promise<IInfoUserAdminForLogin> {\n\tconst ret = await UserAdminKoaUtils.findOne({ 'login.email': email })\n\t\t.select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')\n\t\t.session(session)\n\t\t.exec()\n\n\tif (ret === null) throw throwUnauthorizedError()\n\n\treturn ret\n}\n"]}
@@ -5,7 +5,6 @@ export async function infoUserForLogin(email, session) {
5
5
  .select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')
6
6
  .session(session)
7
7
  .exec();
8
- // console.debug('[infoUserForLogin] ret: ', ret);
9
8
  if (ret === null)
10
9
  throw throwUnauthorizedError();
11
10
  return ret;
@@ -1 +1 @@
1
- {"version":3,"file":"infoUserForLogin.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/infoUserForLogin.mts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,wDAAoC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,6DAAyC;AAG1E,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAa,EAAE,OAAsB;IAC3E,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;SAC1D,MAAM,CAAC,yEAAyE,GAAG,kBAAkB,CAAC;SACtG,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IACR,kDAAkD;IAElD,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,sBAAsB,EAAE,CAAA;IAEhD,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["import { IInfoUserForLogin, UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport async function infoUserForLogin(email: string, session: ClientSession): Promise<IInfoUserForLogin> {\n\tconst ret = await UserBase.findOne({ 'login.email': email })\n\t\t.select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')\n\t\t.session(session)\n\t\t.exec()\n\t// console.debug('[infoUserForLogin] ret: ', ret);\n\n\tif (ret === null) throw throwUnauthorizedError()\n\n\treturn ret\n}\n"]}
1
+ {"version":3,"file":"infoUserForLogin.mjs","sourceRoot":"","sources":["../../../../../src/private/graphQL/schema/mutations/infoUserForLogin.mts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,wDAAoC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,6DAAyC;AAG1E,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAa,EAAE,OAAsB;IAC3E,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;SAC1D,MAAM,CAAC,yEAAyE,GAAG,kBAAkB,CAAC;SACtG,OAAO,CAAC,OAAO,CAAC;SAChB,IAAI,EAAE,CAAA;IAER,IAAI,GAAG,KAAK,IAAI;QAAE,MAAM,sBAAsB,EAAE,CAAA;IAEhD,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["import { IInfoUserForLogin, UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { throwUnauthorizedError } from '@throw/throwUnauthorizedError.mjs'\nimport { ClientSession } from 'mongoose'\n\nexport async function infoUserForLogin(email: string, session: ClientSession): Promise<IInfoUserForLogin> {\n\tconst ret = await UserBase.findOne({ 'login.email': email })\n\t\t.select('_id login.password login.lastLogin account.email.valid account.deleted ' + 'account.disabled')\n\t\t.session(session)\n\t\t.exec()\n\n\tif (ret === null) throw throwUnauthorizedError()\n\n\treturn ret\n}\n"]}
@@ -2,7 +2,6 @@ import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs"
2
2
  import { throwMongoDBErrors } from "../../../../lib/MongoDB/throwMongoErrors.mjs";
3
3
  import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
4
4
  export const createSaveResetReq = (model, paths) => async function saveResetReq(session, _id, now, hash) {
5
- // console.debug('imposto reset in coll Utenti')
6
5
  try {
7
6
  await model.updateOne({ _id }, {
8
7
  $set: {
@@ -1 +1 @@
1
- {"version":3,"file":"saveResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/saveResetReq.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AAEnG,OAAO,EAAE,kBAAkB,EAAE,qDAAyC;AACtE,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CAChF,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,GAAmB,EAAE,GAAS,EAAE,IAAY;IAC/F,gDAAgD;IAChD,IAAI,CAAC;QACJ,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,EACP;YACC,IAAI,EAAE;gBACL,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG;gBACzB,kFAAkF;gBAClF,gFAAgF;gBAChF,wDAAwD;gBACxD,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI;aACvB;SACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,kBAAkB,CAAC,CAAkB,CAAC,CAAA;IAC7C,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAkB,kBAAkB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { IMongoDBError } from '@lib/MongoDB/IMongoDBError.mjs'\nimport { throwMongoDBErrors } from '@lib/MongoDB/throwMongoErrors.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport const createSaveResetReq = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function saveResetReq(session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) {\n\t\t// console.debug('imposto reset in coll Utenti')\n\t\ttry {\n\t\t\tawait model.updateOne(\n\t\t\t\t{ _id },\n\t\t\t\t{\n\t\t\t\t\t$set: {\n\t\t\t\t\t\t[paths.resetDateReq]: now,\n\t\t\t\t\t\t// the reset slot, never the email-verification one: writing the verification slot\n\t\t\t\t\t\t// here invalidated any pending activation or email-change link, and left a live\n\t\t\t\t\t\t// reset token in the field those flows compare against.\n\t\t\t\t\t\t[paths.resetHash]: hash\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ session, runValidators: true }\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tthrow throwMongoDBErrors(e as IMongoDBError)\n\t\t}\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TSaveResetReq = ReturnType<typeof createSaveResetReq>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const saveResetReq: TSaveResetReq = createSaveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
1
+ {"version":3,"file":"saveResetReq.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/saveResetReq.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AAEnG,OAAO,EAAE,kBAAkB,EAAE,qDAAyC;AACtE,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CAChF,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,GAAmB,EAAE,GAAS,EAAE,IAAY;IAC/F,IAAI,CAAC;QACJ,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,EACP;YACC,IAAI,EAAE;gBACL,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG;gBACzB,kFAAkF;gBAClF,gFAAgF;gBAChF,wDAAwD;gBACxD,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI;aACvB;SACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,kBAAkB,CAAC,CAAkB,CAAC,CAAA;IAC7C,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAkB,kBAAkB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { IMongoDBError } from '@lib/MongoDB/IMongoDBError.mjs'\nimport { throwMongoDBErrors } from '@lib/MongoDB/throwMongoErrors.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport const createSaveResetReq = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function saveResetReq(session: ClientSession, _id: Types.ObjectId, now: Date, hash: string) {\n\t\ttry {\n\t\t\tawait model.updateOne(\n\t\t\t\t{ _id },\n\t\t\t\t{\n\t\t\t\t\t$set: {\n\t\t\t\t\t\t[paths.resetDateReq]: now,\n\t\t\t\t\t\t// the reset slot, never the email-verification one: writing the verification slot\n\t\t\t\t\t\t// here invalidated any pending activation or email-change link, and left a live\n\t\t\t\t\t\t// reset token in the field those flows compare against.\n\t\t\t\t\t\t[paths.resetHash]: hash\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ session, runValidators: true }\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tthrow throwMongoDBErrors(e as IMongoDBError)\n\t\t}\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TSaveResetReq = ReturnType<typeof createSaveResetReq>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const saveResetReq: TSaveResetReq = createSaveResetReq(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiumine/koa-utils",
3
- "version": "5.4.1",
3
+ "version": "5.6.0",
4
4
  "description": "Koa Utils",
5
5
  "type": "module",
6
6
  "repository": {
@@ -651,7 +651,6 @@
651
651
  "fs-extra": "*",
652
652
  "graphql": "*",
653
653
  "keygrip": "^1.1.0",
654
- "koa-logger": "*",
655
654
  "mongoose": "*",
656
655
  "pg": "*",
657
656
  "redis": "*",
@@ -697,7 +696,6 @@
697
696
  "fs-extra": "^11.3.4",
698
697
  "graphql": "^16.13.1",
699
698
  "koa": "^3.1.1",
700
- "koa-logger": "^4.0.0",
701
699
  "lint-staged": "^17.0.5",
702
700
  "mariadb": "^3.5.2",
703
701
  "mocha": "^11.7.6",