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