@axiumine/koa-utils 5.2.0 → 5.4.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 +28 -0
- package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.d.mts +2 -1
- package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +22 -4
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +31 -15
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/login4Ever.d.mts +3 -3
- package/dist/graphQL/schema/mutations/login4Ever.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginAdmin.d.mts +3 -3
- package/dist/graphQL/schema/mutations/loginAdmin.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginRememberme.d.mts +3 -3
- package/dist/graphQL/schema/mutations/loginRememberme.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/resetPwd.d.mts +18 -4
- package/dist/graphQL/schema/mutations/resetPwd.mjs +9 -4
- package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/signUp.d.mts +3 -3
- package/dist/graphQL/schema/mutations/signUp.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/updatePassword.d.mts +24 -4
- package/dist/graphQL/schema/mutations/updatePassword.mjs +18 -5
- package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
- package/dist/koa/router/verifyEmail.d.mts +22 -1
- package/dist/koa/router/verifyEmail.mjs +18 -9
- package/dist/koa/router/verifyEmail.mjs.map +1 -1
- package/dist/lib/access/accessPaths.d.mts +96 -0
- package/dist/lib/access/accessPaths.mjs +48 -0
- package/dist/lib/access/accessPaths.mjs.map +1 -0
- package/dist/lib/access/createResetPwdFlow.d.mts +33 -0
- package/dist/lib/access/createResetPwdFlow.mjs +42 -0
- package/dist/lib/access/createResetPwdFlow.mjs.map +1 -0
- package/dist/lib/access/createVerifyEmailFlow.d.mts +48 -0
- package/dist/lib/access/createVerifyEmailFlow.mjs +68 -0
- package/dist/lib/access/createVerifyEmailFlow.mjs.map +1 -0
- package/dist/lib/db/log/logGlobalError.d.mts +2 -2
- package/dist/lib/db/log/logGlobalError.mjs.map +1 -1
- package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +20 -2
- package/dist/private/lib/access/assertVerifyEmailAllowed.mjs +30 -12
- package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +1 -1
- package/dist/private/lib/access/db/confirmNewEmail.d.mts +7 -1
- package/dist/private/lib/access/db/confirmNewEmail.mjs +12 -11
- package/dist/private/lib/access/db/confirmNewEmail.mjs.map +1 -1
- package/dist/private/lib/access/db/deleteUserByEmail.d.mts +7 -1
- package/dist/private/lib/access/db/deleteUserByEmail.mjs +6 -3
- package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +1 -1
- package/dist/private/lib/access/db/enableEmailAccess.d.mts +6 -1
- package/dist/private/lib/access/db/enableEmailAccess.mjs +9 -9
- package/dist/private/lib/access/db/enableEmailAccess.mjs.map +1 -1
- package/dist/private/lib/access/db/getResetPwd.d.mts +11 -4
- package/dist/private/lib/access/db/getResetPwd.mjs +31 -12
- package/dist/private/lib/access/db/getResetPwd.mjs.map +1 -1
- package/dist/private/lib/access/db/incReqTimes.d.mts +6 -1
- package/dist/private/lib/access/db/incReqTimes.mjs +6 -3
- package/dist/private/lib/access/db/incReqTimes.mjs.map +1 -1
- package/dist/private/lib/access/db/removeResetReq.d.mts +7 -1
- package/dist/private/lib/access/db/removeResetReq.mjs +16 -7
- package/dist/private/lib/access/db/removeResetReq.mjs.map +1 -1
- package/dist/private/lib/access/db/saveResetReq.d.mts +6 -1
- package/dist/private/lib/access/db/saveResetReq.mjs +10 -7
- package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
- package/dist/private/lib/access/db/setEmailHash.d.mts +6 -1
- package/dist/private/lib/access/db/setEmailHash.mjs +9 -6
- package/dist/private/lib/access/db/setEmailHash.mjs.map +1 -1
- package/dist/private/lib/access/db/updatePasswordDb.d.mts +7 -1
- package/dist/private/lib/access/db/updatePasswordDb.mjs +6 -3
- package/dist/private/lib/access/db/updatePasswordDb.mjs.map +1 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +6 -3
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs +12 -5
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs.map +1 -1
- package/dist/private/lib/access/handleIfHashBad.d.mts +10 -3
- package/dist/private/lib/access/handleIfHashBad.mjs +9 -5
- package/dist/private/lib/access/handleIfHashBad.mjs.map +1 -1
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +12 -1
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +11 -3
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +1 -1
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +12 -1
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +11 -3
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +1 -1
- package/dist/private/lib/access/pathTools.d.mts +25 -0
- package/dist/private/lib/access/pathTools.mjs +43 -0
- package/dist/private/lib/access/pathTools.mjs.map +1 -0
- package/package.json +14 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setEmailHash.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/setEmailHash.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sCAA0B;AAC9C,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,MAAsB;
|
|
1
|
+
{"version":3,"file":"setEmailHash.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/setEmailHash.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,SAAS,EAAE,sCAA0B;AAC9C,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CACnF,KAAK,UAAU,YAAY,CAAC,OAAsB,EAAE,MAAsB;IACzE,MAAM,IAAI,GAAG,SAAS,EAAE,CAAA;IAExB,yBAAyB;IACzB,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAA;IAExB,MAAM,KAAK,CAAC,SAAS,CACpB,EAAE,GAAG,EAAE,MAAM,EAAE,EACf;QACC,IAAI,EAAE;YACL,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI;YAClB,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,KAAK;YAC9B,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK;SAC1B;KACD,EACD,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAChC,CAAA;IAED,OAAO,IAAI,CAAA,CAAC,2CAA2C;AACxD,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAkB,kBAAkB,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { emailHash } from '@lib/emailHash.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { ClientSession, Types } from 'mongoose'\n\nexport const createSetEmailHash = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function setEmailHash(session: ClientSession, userId: Types.ObjectId) {\n\t\tconst hash = emailHash()\n\n\t\t//calculate password hash\n\t\tconst dtNow = new Date()\n\n\t\tawait model.updateOne(\n\t\t\t{ _id: userId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\t[paths.hash]: hash,\n\t\t\t\t\t[paths.requestTimes]: 1, // ok\n\t\t\t\t\t[paths.dateLastReq]: dtNow\n\t\t\t\t}\n\t\t\t},\n\t\t\t{ session, runValidators: true }\n\t\t)\n\n\t\treturn hash // else it goes into exception @fixme check\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TSetEmailHash = ReturnType<typeof createSetEmailHash>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const setEmailHash: TSetEmailHash = createSetEmailHash(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { IResetPwdPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import mongoose, { ClientSession } from 'mongoose';
|
|
2
|
-
export
|
|
3
|
+
export declare const createUpdatePasswordDb: (model: TAccessModel, paths: IResetPwdPaths) => (session: ClientSession, _id: mongoose.Types.ObjectId, password: string) => Promise<mongoose.UpdateWriteOpResult>;
|
|
4
|
+
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
|
+
export type TUpdatePasswordDb = ReturnType<typeof createUpdatePasswordDb>;
|
|
6
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
7
|
+
declare const _default: (session: ClientSession, _id: mongoose.Types.ObjectId, password: string) => Promise<mongoose.UpdateWriteOpResult>;
|
|
8
|
+
export default _default;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_RESET_PWD_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
3
|
import { hash } from '@node-rs/bcrypt';
|
|
3
4
|
import { SALT_ROUNDS } from "../Constants.mjs";
|
|
4
|
-
export
|
|
5
|
+
export const createUpdatePasswordDb = (model, paths) => async function updatePassword(session, _id, password) {
|
|
5
6
|
const hashVal = await hash(password, SALT_ROUNDS);
|
|
6
|
-
return
|
|
7
|
-
}
|
|
7
|
+
return model.updateOne({ _id }, { $set: { [paths.password]: hashVal } }, { session, runValidators: true });
|
|
8
|
+
};
|
|
9
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
10
|
+
export default createUpdatePasswordDb(UserBase, DEFAULT_RESET_PWD_PATHS);
|
|
8
11
|
//# sourceMappingURL=updatePasswordDb.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updatePasswordDb.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/updatePasswordDb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,yBAAyC;AAG/D,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"updatePasswordDb.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/updatePasswordDb.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAgC,+CAAmC;AACnG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,yBAAyC;AAG/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAmB,EAAE,KAAqB,EAAE,EAAE,CACpF,KAAK,UAAU,cAAc,CAAC,OAAsB,EAAE,GAA4B,EAAE,QAAgB;IACnG,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;IAEjD,OAAO,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAC3G,CAAC,CAAA;AAKF,wFAAwF;AACxF,eAAe,sBAAsB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAA","sourcesContent":["import { DEFAULT_RESET_PWD_PATHS, IResetPwdPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { hash } from '@node-rs/bcrypt'\nimport { SALT_ROUNDS } from '@private/lib/access/Constants.mjs'\nimport mongoose, { ClientSession } from 'mongoose'\n\nexport const createUpdatePasswordDb = (model: TAccessModel, paths: IResetPwdPaths) =>\n\tasync function updatePassword(session: ClientSession, _id: mongoose.Types.ObjectId, password: string) {\n\t\tconst hashVal = await hash(password, SALT_ROUNDS)\n\n\t\treturn model.updateOne({ _id }, { $set: { [paths.password]: hashVal } }, { session, runValidators: true })\n\t}\n\n/** Signature of the bound writer, for the modules that take it as a dependency. */\nexport type TUpdatePasswordDb = ReturnType<typeof createUpdatePasswordDb>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport default createUpdatePasswordDb(UserBase, DEFAULT_RESET_PWD_PATHS)\n"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
export declare const createUserData4VerifyEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (uEmail: string) => Promise<any>;
|
|
3
|
+
/** Signature of the bound reader, for the modules that take it as a dependency. */
|
|
4
|
+
export type TUserData4VerifyEmail = ReturnType<typeof createUserData4VerifyEmail>;
|
|
5
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
6
|
+
export declare const userData4VerifyEmail: TUserData4VerifyEmail;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
1
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
2
3
|
import { EMAIL_CHECK_LINK } from "../Constants.mjs";
|
|
4
|
+
import { buildProjection } from "../pathTools.mjs";
|
|
3
5
|
import * as Sentry from '@sentry/node';
|
|
4
|
-
export async function userData4VerifyEmail(uEmail) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export const createUserData4VerifyEmail = (model, paths) => async function userData4VerifyEmail(uEmail) {
|
|
7
|
+
// Every field the guard chain reads must be listed. This is a .lean() read, so a field left out
|
|
8
|
+
// of the projection is simply absent on the returned object, with no error — which is how a
|
|
9
|
+
// missing requestTimes turned every wrong-hash attempt into a 500 under a green coverage gate.
|
|
10
|
+
const user = await model
|
|
11
|
+
.findOne({ [paths.email]: uEmail })
|
|
12
|
+
.select(buildProjection([paths.hash, paths.valid, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))
|
|
8
13
|
.lean();
|
|
9
14
|
// if email not found, return stNotFoundNotMatch
|
|
10
15
|
if (user === null) {
|
|
@@ -12,5 +17,7 @@ export async function userData4VerifyEmail(uEmail) {
|
|
|
12
17
|
throw new Error(EMAIL_CHECK_LINK);
|
|
13
18
|
}
|
|
14
19
|
return user;
|
|
15
|
-
}
|
|
20
|
+
};
|
|
21
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
22
|
+
export const userData4VerifyEmail = createUserData4VerifyEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
16
23
|
//# sourceMappingURL=userData4VerifyEmail.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userData4VerifyEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/userData4VerifyEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,gBAAgB,EAAE,yBAAyC;AACpE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAc;
|
|
1
|
+
{"version":3,"file":"userData4VerifyEmail.mjs","sourceRoot":"","sources":["../../../../../src/private/lib/access/db/userData4VerifyEmail.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAmC,+CAAmC;AACzG,OAAO,EAAE,QAAQ,EAAE,wDAAoC;AACvD,OAAO,EAAE,gBAAgB,EAAE,yBAAyC;AACpE,OAAO,EAAE,eAAe,EAAE,yBAAyC;AACnE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,KAAmB,EAAE,KAAwB,EAAE,EAAE,CAC3F,KAAK,UAAU,oBAAoB,CAAC,MAAc;IACjD,gGAAgG;IAChG,4FAA4F;IAC5F,+FAA+F;IAC/F,MAAM,IAAI,GAAG,MAAM,KAAK;SACtB,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;SAClC,MAAM,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;SACxH,IAAI,EAAE,CAAA;IAER,gDAAgD;IAChD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,CAAC,QAAQ,MAAM,YAAY,CAAC,CAAA;QAEjD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,oBAAoB,GAA0B,0BAA0B,CAAC,QAAQ,EAAE,0BAA0B,CAAC,CAAA","sourcesContent":["import { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport { EMAIL_CHECK_LINK } from '@private/lib/access/Constants.mjs'\nimport { buildProjection } from '@private/lib/access/pathTools.mjs'\nimport * as Sentry from '@sentry/node'\n\nexport const createUserData4VerifyEmail = (model: TAccessModel, paths: IVerifyEmailPaths) =>\n\tasync function userData4VerifyEmail(uEmail: string) {\n\t\t// Every field the guard chain reads must be listed. This is a .lean() read, so a field left out\n\t\t// of the projection is simply absent on the returned object, with no error — which is how a\n\t\t// missing requestTimes turned every wrong-hash attempt into a 500 under a green coverage gate.\n\t\tconst user = await model\n\t\t\t.findOne({ [paths.email]: uEmail })\n\t\t\t.select(buildProjection([paths.hash, paths.valid, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))\n\t\t\t.lean()\n\n\t\t// if email not found, return stNotFoundNotMatch\n\t\tif (user === null) {\n\t\t\tSentry.captureMessage(`User ${uEmail} not exist`)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t\treturn user\n\t}\n\n/** Signature of the bound reader, for the modules that take it as a dependency. */\nexport type TUserData4VerifyEmail = ReturnType<typeof createUserData4VerifyEmail>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const userData4VerifyEmail: TUserData4VerifyEmail = createUserData4VerifyEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS)\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
+
import { TIncReqTimes } from './db/incReqTimes.mjs';
|
|
2
3
|
interface IHandleIfHashBadArgs {
|
|
3
4
|
uId: mongoose.Types.ObjectId;
|
|
4
5
|
uEmail: string;
|
|
@@ -7,8 +8,14 @@ interface IHandleIfHashBadArgs {
|
|
|
7
8
|
dbHash?: string;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
|
-
* The hash in the activation url is wrong
|
|
11
|
-
*
|
|
11
|
+
* The hash in the activation url is wrong.
|
|
12
|
+
*
|
|
13
|
+
* The strike counter is bumped through an injected writer so the guard can serve a model other than
|
|
14
|
+
* `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
|
|
12
15
|
*/
|
|
13
|
-
export declare
|
|
16
|
+
export declare const createHandleIfHashBad: (incReqTimesFn: TIncReqTimes) => ({ uId, uEmail, hash, requestTimes, dbHash }: IHandleIfHashBadArgs) => Promise<void>;
|
|
17
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
18
|
+
export type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>;
|
|
19
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
20
|
+
export declare const handleIfHashBad: THandleIfHashBad;
|
|
14
21
|
export {};
|
|
@@ -2,16 +2,20 @@ import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
|
|
|
2
2
|
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
3
3
|
import { incReqTimes } from './db/incReqTimes.mjs';
|
|
4
4
|
/**
|
|
5
|
-
* The hash in the activation url is wrong
|
|
6
|
-
*
|
|
5
|
+
* The hash in the activation url is wrong.
|
|
6
|
+
*
|
|
7
|
+
* The strike counter is bumped through an injected writer so the guard can serve a model other than
|
|
8
|
+
* `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.
|
|
7
9
|
*/
|
|
8
|
-
export async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
|
|
10
|
+
export const createHandleIfHashBad = (incReqTimesFn) => async function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }) {
|
|
9
11
|
if (hash !== dbHash) {
|
|
10
12
|
// hash failed
|
|
11
|
-
await
|
|
13
|
+
await incReqTimesFn(uId);
|
|
12
14
|
const SocketLabsObj = new SocketLabsLib();
|
|
13
15
|
await SocketLabsObj.wrongHash(uEmail, requestTimes + 1);
|
|
14
16
|
throw new Error(EMAIL_CHECK_LINK);
|
|
15
17
|
}
|
|
16
|
-
}
|
|
18
|
+
};
|
|
19
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
20
|
+
export const handleIfHashBad = createHandleIfHashBad(incReqTimes);
|
|
17
21
|
//# sourceMappingURL=handleIfHashBad.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"handleIfHashBad.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfHashBad.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,sBAAsB,CAAA;AAUhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,aAA2B,EAAE,EAAE,CACpE,KAAK,UAAU,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,CAAC,EAAE,MAAM,EAAwB;IACnG,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACrB,cAAc;QACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;QAExB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,CAAC,CAAC,CAAA;QACvD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAqB,qBAAqB,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport mongoose from 'mongoose'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport { incReqTimes, TIncReqTimes } from './db/incReqTimes.mjs'\n\ninterface IHandleIfHashBadArgs {\n\tuId: mongoose.Types.ObjectId\n\tuEmail: string\n\thash: string\n\trequestTimes?: number // but the check is already performed\n\tdbHash?: string\n}\n\n/**\n * The hash in the activation url is wrong.\n *\n * The strike counter is bumped through an injected writer so the guard can serve a model other than\n * `UserBase`: the counter path itself lives in the verify-email `paths` map the writer was built with.\n */\nexport const createHandleIfHashBad = (incReqTimesFn: TIncReqTimes) =>\n\tasync function handleIfHashBad({ uId, uEmail, hash, requestTimes = 0, dbHash }: IHandleIfHashBadArgs) {\n\t\tif (hash !== dbHash) {\n\t\t\t// hash failed\n\t\t\tawait incReqTimesFn(uId)\n\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.wrongHash(uEmail, requestTimes + 1)\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfHashBad = ReturnType<typeof createHandleIfHashBad>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfHashBad: THandleIfHashBad = createHandleIfHashBad(incReqTimes)\n"]}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* A verification link older than 3 days deletes the pending account.
|
|
4
|
+
*
|
|
5
|
+
* The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
|
|
6
|
+
* both the collection and the login-email path come from the writer it was built with.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createHandleIfMoreThan3DaysPassed: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, dateLastReq?: Date) => Promise<void>;
|
|
9
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
10
|
+
export type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>;
|
|
11
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
12
|
+
export declare const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed;
|
|
@@ -2,7 +2,13 @@ import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
|
|
|
2
2
|
import { StringLib } from "../../../lib/StringLib.mjs";
|
|
3
3
|
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
4
4
|
import deleteUserByEmail from './db/deleteUserByEmail.mjs';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A verification link older than 3 days deletes the pending account.
|
|
7
|
+
*
|
|
8
|
+
* The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
|
|
9
|
+
* both the collection and the login-email path come from the writer it was built with.
|
|
10
|
+
*/
|
|
11
|
+
export const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn) => async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date() // but it is already handled
|
|
6
12
|
) {
|
|
7
13
|
/****************************************************
|
|
8
14
|
* if dateLastReq too old then 3 days send email
|
|
@@ -16,8 +22,10 @@ export async function handleIfMoreThan3DaysPassed(uEmail, dateLastReq = new Date
|
|
|
16
22
|
// dateLastReq too old then 3 days
|
|
17
23
|
const SocketLabsObj = new SocketLabsLib();
|
|
18
24
|
await SocketLabsObj.hashReqTooOld(uEmail);
|
|
19
|
-
await
|
|
25
|
+
await deleteUserByEmailFn(uEmail);
|
|
20
26
|
throw new Error(EMAIL_CHECK_LINK);
|
|
21
27
|
}
|
|
22
|
-
}
|
|
28
|
+
};
|
|
29
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
30
|
+
export const handleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail);
|
|
23
31
|
//# sourceMappingURL=handleIfMoreThan3DaysPassed.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"handleIfMoreThan3DaysPassed.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfMoreThan3DaysPassed.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,mBAAuC,EAAE,EAAE,CAC5F,KAAK,UAAU,2BAA2B,CACzC,MAAc,EACd,cAAoB,IAAI,IAAI,EAAE,CAAC,4BAA4B;;IAE3D;;OAEG;IAEH,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,IAAI,SAAS,GAAG,KAAK,EAAE,CAAC;QACvB,kCAAkC;QAClC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAEzC,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAiC,iCAAiC,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * A verification link older than 3 days deletes the pending account.\n *\n * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:\n * both the collection and the login-email path come from the writer it was built with.\n */\nexport const createHandleIfMoreThan3DaysPassed = (deleteUserByEmailFn: TDeleteUserByEmail) =>\n\tasync function handleIfMoreThan3DaysPassed(\n\t\tuEmail: string,\n\t\tdateLastReq: Date = new Date() // but it is already handled\n\t) {\n\t\t/****************************************************\n\t\t * if dateLastReq too old then 3 days send email\n\t\t */\n\n\t\tconst now = new Date()\n\t\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\t\tconst StrLibObj = new StringLib()\n\t\tconst tsReq = StrLibObj.isoToTimestamp(dateLastReq)\n\t\tconst ts3DayAgo = StrLibObj.isoToTimestamp(day3ago)\n\n\t\tif (ts3DayAgo > tsReq) {\n\t\t\t// dateLastReq too old then 3 days\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.hashReqTooOld(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfMoreThan3DaysPassed = ReturnType<typeof createHandleIfMoreThan3DaysPassed>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfMoreThan3DaysPassed: THandleIfMoreThan3DaysPassed = createHandleIfMoreThan3DaysPassed(deleteUserByEmail)\n"]}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Five wrong-hash attempts delete the pending account.
|
|
4
|
+
*
|
|
5
|
+
* The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
|
|
6
|
+
* both the collection and the login-email path come from the writer it was built with.
|
|
7
|
+
*/
|
|
8
|
+
export declare const createHandleIfTooMuchRequestsTimes: (deleteUserByEmailFn: TDeleteUserByEmail) => (uEmail: string, requestTimes?: number) => Promise<void>;
|
|
9
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
10
|
+
export type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>;
|
|
11
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
12
|
+
export declare const handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { SocketLabsLib } from "../../../email/SocketLabsLib.mjs";
|
|
2
2
|
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
3
3
|
import deleteUserByEmail from './db/deleteUserByEmail.mjs';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Five wrong-hash attempts delete the pending account.
|
|
6
|
+
*
|
|
7
|
+
* The delete runs through an injected writer so the guard can serve a model other than `UserBase`:
|
|
8
|
+
* both the collection and the login-email path come from the writer it was built with.
|
|
9
|
+
*/
|
|
10
|
+
export const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn) => async function handleIfTooMuchRequestsTimes(uEmail, requestTimes = 99 // but it is already handled
|
|
5
11
|
) {
|
|
6
12
|
if (requestTimes >= 5) {
|
|
7
13
|
const SocketLabsObj = new SocketLabsLib();
|
|
8
14
|
await SocketLabsObj.tooMuchVerifyRequests(uEmail);
|
|
9
|
-
await
|
|
15
|
+
await deleteUserByEmailFn(uEmail);
|
|
10
16
|
throw new Error(EMAIL_CHECK_LINK);
|
|
11
17
|
}
|
|
12
|
-
}
|
|
18
|
+
};
|
|
19
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
20
|
+
export const handleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail);
|
|
13
21
|
//# sourceMappingURL=handleIfTooMuchRequestsTimes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleIfTooMuchRequestsTimes.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfTooMuchRequestsTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"handleIfTooMuchRequestsTimes.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/handleIfTooMuchRequestsTimes.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,iBAAyC,MAAM,4BAA4B,CAAA;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,mBAAuC,EAAE,EAAE,CAC7F,KAAK,UAAU,4BAA4B,CAC1C,MAAc,EACd,eAAuB,EAAE,CAAC,4BAA4B;;IAEtD,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAA;QACzC,MAAM,aAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QAEjD,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAEjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAClC,CAAC;AACF,CAAC,CAAA;AAKF,wFAAwF;AACxF,MAAM,CAAC,MAAM,4BAA4B,GAAkC,kCAAkC,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\n\nimport { EMAIL_CHECK_LINK } from './Constants.mjs'\nimport deleteUserByEmail, { TDeleteUserByEmail } from './db/deleteUserByEmail.mjs'\n\n/**\n * Five wrong-hash attempts delete the pending account.\n *\n * The delete runs through an injected writer so the guard can serve a model other than `UserBase`:\n * both the collection and the login-email path come from the writer it was built with.\n */\nexport const createHandleIfTooMuchRequestsTimes = (deleteUserByEmailFn: TDeleteUserByEmail) =>\n\tasync function handleIfTooMuchRequestsTimes(\n\t\tuEmail: string,\n\t\trequestTimes: number = 99 // but it is already handled\n\t) {\n\t\tif (requestTimes >= 5) {\n\t\t\tconst SocketLabsObj = new SocketLabsLib()\n\t\t\tawait SocketLabsObj.tooMuchVerifyRequests(uEmail)\n\n\t\t\tawait deleteUserByEmailFn(uEmail)\n\n\t\t\tthrow new Error(EMAIL_CHECK_LINK)\n\t\t}\n\t}\n\n/** Signature of the bound guard, for the modules that take it as a dependency. */\nexport type THandleIfTooMuchRequestsTimes = ReturnType<typeof createHandleIfTooMuchRequestsTimes>\n\n/** `UserBase`-bound default — the behaviour every existing consumer already imports. */\nexport const handleIfTooMuchRequestsTimes: THandleIfTooMuchRequestsTimes = createHandleIfTooMuchRequestsTimes(deleteUserByEmail)\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a dotted mongo path out of a lean document.
|
|
3
|
+
*
|
|
4
|
+
* `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be
|
|
5
|
+
* walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path
|
|
6
|
+
* pointing at a field the document does not carry must read as "absent", exactly like a projection
|
|
7
|
+
* that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readPath(source: unknown, path: string): unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Build a mongo `$unset` payload from a list of paths.
|
|
12
|
+
*
|
|
13
|
+
* The list is supplied by the caller, never derived from the fields that were written: a layout
|
|
14
|
+
* storing the reset request as one required subdocument can only be cleared by unsetting the
|
|
15
|
+
* container, not its members. See `IResetPwdPaths.resetClear`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildUnset(paths: readonly string[]): Record<string, ''>;
|
|
18
|
+
/**
|
|
19
|
+
* Build a `.select()` projection string, always including `_id`.
|
|
20
|
+
*
|
|
21
|
+
* Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the
|
|
22
|
+
* projection is simply absent, with no error — that is how a missing `account.email.requestTimes`
|
|
23
|
+
* turned every wrong-hash attempt into a 500 while the coverage gate stayed green.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildProjection(paths: readonly string[]): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a dotted mongo path out of a lean document.
|
|
3
|
+
*
|
|
4
|
+
* `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be
|
|
5
|
+
* walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path
|
|
6
|
+
* pointing at a field the document does not carry must read as "absent", exactly like a projection
|
|
7
|
+
* that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.
|
|
8
|
+
*/
|
|
9
|
+
export function readPath(source, path) {
|
|
10
|
+
let current = source;
|
|
11
|
+
for (const key of path.split('.')) {
|
|
12
|
+
if (current === null || typeof current !== 'object') {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
current = current[key];
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Build a mongo `$unset` payload from a list of paths.
|
|
21
|
+
*
|
|
22
|
+
* The list is supplied by the caller, never derived from the fields that were written: a layout
|
|
23
|
+
* storing the reset request as one required subdocument can only be cleared by unsetting the
|
|
24
|
+
* container, not its members. See `IResetPwdPaths.resetClear`.
|
|
25
|
+
*/
|
|
26
|
+
export function buildUnset(paths) {
|
|
27
|
+
const unset = {};
|
|
28
|
+
for (const path of paths) {
|
|
29
|
+
unset[path] = '';
|
|
30
|
+
}
|
|
31
|
+
return unset;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build a `.select()` projection string, always including `_id`.
|
|
35
|
+
*
|
|
36
|
+
* Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the
|
|
37
|
+
* projection is simply absent, with no error — that is how a missing `account.email.requestTimes`
|
|
38
|
+
* turned every wrong-hash attempt into a 500 while the coverage gate stayed green.
|
|
39
|
+
*/
|
|
40
|
+
export function buildProjection(paths) {
|
|
41
|
+
return ['_id', ...paths].join(' ');
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=pathTools.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathTools.mjs","sourceRoot":"","sources":["../../../../src/private/lib/access/pathTools.mts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAe,EAAE,IAAY;IACrD,IAAI,OAAO,GAAY,MAAM,CAAA;IAE7B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACrD,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,OAAO,GAAI,OAAmC,CAAC,GAAG,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAwB;IAClD,MAAM,KAAK,GAAuB,EAAE,CAAA;IAEpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;IACjB,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAwB;IACvD,OAAO,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACnC,CAAC","sourcesContent":["/**\n * Read a dotted mongo path out of a lean document.\n *\n * `.lean()` hands back a plain object, so a configured path such as `account.email.hash` has to be\n * walked by hand. Any missing or non-object link yields `undefined` rather than throwing: a path\n * pointing at a field the document does not carry must read as \"absent\", exactly like a projection\n * that left the field out, so the callers' existing `typeof x === 'undefined'` guards keep working.\n */\nexport function readPath(source: unknown, path: string): unknown {\n\tlet current: unknown = source\n\n\tfor (const key of path.split('.')) {\n\t\tif (current === null || typeof current !== 'object') {\n\t\t\treturn undefined\n\t\t}\n\t\tcurrent = (current as Record<string, unknown>)[key]\n\t}\n\n\treturn current\n}\n\n/**\n * Build a mongo `$unset` payload from a list of paths.\n *\n * The list is supplied by the caller, never derived from the fields that were written: a layout\n * storing the reset request as one required subdocument can only be cleared by unsetting the\n * container, not its members. See `IResetPwdPaths.resetClear`.\n */\nexport function buildUnset(paths: readonly string[]): Record<string, ''> {\n\tconst unset: Record<string, ''> = {}\n\n\tfor (const path of paths) {\n\t\tunset[path] = ''\n\t}\n\n\treturn unset\n}\n\n/**\n * Build a `.select()` projection string, always including `_id`.\n *\n * Every field a resolver reads must be listed here. A `.lean()` read of a field left out of the\n * projection is simply absent, with no error — that is how a missing `account.email.requestTimes`\n * turned every wrong-hash attempt into a 500 while the coverage gate stayed green.\n */\nexport function buildProjection(paths: readonly string[]): string {\n\treturn ['_id', ...paths].join(' ')\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiumine/koa-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Koa Utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"test:coverage": "yarn build && yarn build:tests && c8 mocha",
|
|
30
30
|
"qodana": "yarn test:coverage && mkdir -p .qodana/results && docker run --rm --env-file .env -v \"$PWD\":/data/project -v \"$PWD\"/.qodana/results:/data/results jetbrains/qodana-js:2026.1 --show-report",
|
|
31
31
|
"qodana:cli": "yarn test:coverage && set -a && . ./.env && set +a && qodana scan --show-report",
|
|
32
|
+
"reindex": "node .gitnexus/run.cjs analyze --no-stats",
|
|
32
33
|
"semgrep": "./scripts/semgrep.sh",
|
|
33
34
|
"semgrep:all": "./scripts/semgrep.sh --registry",
|
|
34
35
|
"semgrep:canary": "./scripts/semgrep-canary.sh",
|
|
@@ -51,6 +52,18 @@
|
|
|
51
52
|
"@dataSources": "dist/dataSources"
|
|
52
53
|
},
|
|
53
54
|
"exports": {
|
|
55
|
+
"./lib/access/accessPaths": {
|
|
56
|
+
"import": "./dist/lib/access/accessPaths.mjs",
|
|
57
|
+
"types": "./dist/lib/access/accessPaths.d.mts"
|
|
58
|
+
},
|
|
59
|
+
"./lib/access/createResetPwdFlow": {
|
|
60
|
+
"import": "./dist/lib/access/createResetPwdFlow.mjs",
|
|
61
|
+
"types": "./dist/lib/access/createResetPwdFlow.d.mts"
|
|
62
|
+
},
|
|
63
|
+
"./lib/access/createVerifyEmailFlow": {
|
|
64
|
+
"import": "./dist/lib/access/createVerifyEmailFlow.mjs",
|
|
65
|
+
"types": "./dist/lib/access/createVerifyEmailFlow.d.mts"
|
|
66
|
+
},
|
|
54
67
|
"./lib/MongoDB/IOnboarding": {
|
|
55
68
|
"import": "./dist/lib/MongoDB/IOnboarding.mjs",
|
|
56
69
|
"types": "./dist/lib/MongoDB/IOnboarding.d.mts"
|