@axiumine/koa-utils 5.6.1 → 5.7.1
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 +33 -5
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.d.mts +7 -0
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +38 -35
- package/dist/lib/access/accessPaths.d.mts +18 -0
- package/dist/lib/access/createMailThrottle.d.mts +34 -0
- package/dist/lib/access/createMailThrottle.mjs +45 -0
- package/dist/lib/access/createVerifyEmailFlow.d.mts +37 -4
- package/dist/lib/access/createVerifyEmailFlow.mjs +33 -10
- package/dist/lib/access/verifyEmailMailer.d.mts +54 -0
- package/dist/lib/access/verifyEmailMailer.mjs +48 -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/db/abandonUser.d.mts +25 -0
- package/dist/private/lib/access/db/abandonUser.mjs +26 -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/enableEmailAccess.d.mts +9 -1
- package/dist/private/lib/access/db/enableEmailAccess.mjs +11 -5
- package/dist/private/lib/access/handleBadDB.d.mts +11 -0
- package/dist/private/lib/access/handleBadDB.mjs +13 -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/handleIfAccountDisabled.d.mts +15 -1
- package/dist/private/lib/access/handleIfAccountDisabled.mjs +15 -5
- package/dist/private/lib/access/handleIfEmailAlreadyValid.d.mts +18 -1
- package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs +18 -5
- package/dist/private/lib/access/handleIfHashBad.d.mts +5 -1
- package/dist/private/lib/access/handleIfHashBad.mjs +7 -5
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.d.mts +8 -4
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs +10 -8
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.d.mts +7 -4
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs +9 -8
- package/package.json +68 -18
- package/dist/dataSources/MariaDB.mjs.map +0 -1
- package/dist/dataSources/MongoDB.mjs.map +0 -1
- package/dist/dataSources/PostgreSQL.mjs.map +0 -1
- package/dist/dataSources/Redis.mjs.map +0 -1
- package/dist/email/SocketLabsLib.mjs.map +0 -1
- package/dist/files/IUploadTemp.mjs.map +0 -1
- package/dist/files/checkForNSFW.mjs.map +0 -1
- package/dist/files/fileConst.mjs.map +0 -1
- package/dist/files/moveFileStaticDomain.mjs.map +0 -1
- package/dist/files/moveImageFile.mjs.map +0 -1
- package/dist/files/moveTempFile.mjs.map +0 -1
- package/dist/files/reEncodeToJpeg.mjs.map +0 -1
- package/dist/files/reEncodeToPng.mjs.map +0 -1
- package/dist/files/reEncodeToWebp.mjs.map +0 -1
- package/dist/files/scanVirus.mjs.map +0 -1
- package/dist/files/storeUploadAsTemp.mjs.map +0 -1
- package/dist/files/uploadTempImage.mjs.map +0 -1
- package/dist/files/uploadTempPdf.mjs.map +0 -1
- package/dist/files/validateExtension.mjs.map +0 -1
- package/dist/files/validateJpgPngExtension.mjs.map +0 -1
- package/dist/files/validateMimeType.mjs.map +0 -1
- package/dist/files/validateMimeTypeImages.mjs.map +0 -1
- package/dist/files/validateMimeTypePdf.mjs.map +0 -1
- package/dist/files/validatePdfExtension.mjs.map +0 -1
- package/dist/graphQL/models/MongoDB/UserBase.mjs.map +0 -1
- package/dist/graphQL/models/MongoDB/log/DevStatsGraphQLCalls.mjs.map +0 -1
- package/dist/graphQL/models/MongoDB/log/LogGlobalError.mjs.map +0 -1
- package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.mjs.map +0 -1
- package/dist/graphQL/models/MongoDB/log/LogThrow.mjs.map +0 -1
- package/dist/graphQL/schema/GraphQLInput/GraphQLInputLogin.mjs.map +0 -1
- package/dist/graphQL/schema/context/IContextAuthenticatedResource.mjs.map +0 -1
- package/dist/graphQL/schema/context/IContextKoaErrorHandler.mjs.map +0 -1
- package/dist/graphQL/schema/context/IContextLogin.mjs.map +0 -1
- package/dist/graphQL/schema/context/IContextLogout.mjs.map +0 -1
- package/dist/graphQL/schema/context/IContextRefresh.mjs.map +0 -1
- package/dist/graphQL/schema/context/TCommonHeaders.mjs.map +0 -1
- package/dist/graphQL/schema/interfaces/IFindAndUpdate.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/login4Ever.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/loginAdmin.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/loginRememberme.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/logout.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/refresh.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/resetPwd.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/signUp.mjs.map +0 -1
- package/dist/graphQL/schema/mutations/updatePassword.mjs.map +0 -1
- package/dist/graphQL/schema/types/DeleteType.mjs.map +0 -1
- package/dist/graphQL/schema/types/DoneType.mjs.map +0 -1
- package/dist/graphQL/schema/types/FindOneAndUpdateType.mjs.map +0 -1
- package/dist/graphQL/schema/types/LoginAppType.mjs.map +0 -1
- package/dist/graphQL/schema/types/LoginType.mjs.map +0 -1
- package/dist/graphQL/schema/types/MidNameType.mjs.map +0 -1
- package/dist/graphQL/schema/types/OnlyIdType.mjs.map +0 -1
- package/dist/graphQL/schema/types/RefreshType.mjs.map +0 -1
- package/dist/graphQL/schema/types/RetStatusMexType.mjs.map +0 -1
- package/dist/graphQL/schema/types/RetStatusType.mjs.map +0 -1
- package/dist/graphQL/schema/types/SaveType.mjs.map +0 -1
- package/dist/graphQL/schema/types/SidNameType.mjs.map +0 -1
- package/dist/graphQL/schema/types/SidNomeType.mjs.map +0 -1
- package/dist/graphQL/schema/types/UpdateResultType.mjs.map +0 -1
- package/dist/graphQL/status.mjs.map +0 -1
- package/dist/graphQL/throw/throwAccessTokenExpiredOrDeleted.mjs.map +0 -1
- package/dist/graphQL/throw/throwAccessTokenRequired.mjs.map +0 -1
- package/dist/graphQL/throw/throwAlreadyDone.mjs.map +0 -1
- package/dist/graphQL/throw/throwAlreadyTakenError.mjs.map +0 -1
- package/dist/graphQL/throw/throwConflictError.mjs.map +0 -1
- package/dist/graphQL/throw/throwErrorWrongUserInput.mjs.map +0 -1
- package/dist/graphQL/throw/throwForbiddenError.mjs.map +0 -1
- package/dist/graphQL/throw/throwGoneError.mjs.map +0 -1
- package/dist/graphQL/throw/throwGraphQLError.mjs.map +0 -1
- package/dist/graphQL/throw/throwInternalError.mjs.map +0 -1
- package/dist/graphQL/throw/throwMethodNotAllowedError.mjs.map +0 -1
- package/dist/graphQL/throw/throwMissingMalformedInvalidToken.mjs.map +0 -1
- package/dist/graphQL/throw/throwNotAcceptableError.mjs.map +0 -1
- package/dist/graphQL/throw/throwNotFoundError.mjs.map +0 -1
- package/dist/graphQL/throw/throwNotImplementedError.mjs.map +0 -1
- package/dist/graphQL/throw/throwPaymentRequiredError.mjs.map +0 -1
- package/dist/graphQL/throw/throwPreconditionFailedNoAuthCookie.mjs.map +0 -1
- package/dist/graphQL/throw/throwPreconditionFailedNoAuthHeader.mjs.map +0 -1
- package/dist/graphQL/throw/throwRefreshTokenExpiredOrDeleted.mjs.map +0 -1
- package/dist/graphQL/throw/throwRefreshTokenRequired.mjs.map +0 -1
- package/dist/graphQL/throw/throwRefreshTokenSignatureRequired.mjs.map +0 -1
- package/dist/graphQL/throw/throwTooManyRequestsError.mjs.map +0 -1
- package/dist/graphQL/throw/throwUnauthorizedError.mjs.map +0 -1
- package/dist/graphQL/throw/throwUnprocessableContentError.mjs.map +0 -1
- package/dist/graphQL/throw/throwUnsupportedMediaTypeError.mjs.map +0 -1
- package/dist/koa/IFileUpload.mjs.map +0 -1
- package/dist/koa/IKoaError.mjs.map +0 -1
- package/dist/koa/customFormatErrorFn.mjs.map +0 -1
- package/dist/koa/logRequestToDb.mjs.map +0 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/TCookieRefreshToken.mjs.map +0 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs.map +0 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs.map +0 -1
- package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs.map +0 -1
- package/dist/koa/middleware/authenticatedResourceHandler/index.mjs.map +0 -1
- package/dist/koa/middleware/debug/index.mjs.map +0 -1
- package/dist/koa/router/verifyEmail.mjs.map +0 -1
- package/dist/koa/tdwKoaErrorHandler.mjs.map +0 -1
- package/dist/lib/ArrayLib.mjs.map +0 -1
- package/dist/lib/Constants.mjs.map +0 -1
- package/dist/lib/DateLib.mjs.map +0 -1
- package/dist/lib/IAuthorizationDisDel.mjs.map +0 -1
- package/dist/lib/ICookies.mjs.map +0 -1
- package/dist/lib/MariaDB/IMariaDBErr.mjs.map +0 -1
- package/dist/lib/MariaDB/MariaDBErrType.mjs.map +0 -1
- package/dist/lib/MariaDB/throwSqlErrors.mjs.map +0 -1
- package/dist/lib/MongoDB/IMongoDBError.mjs.map +0 -1
- package/dist/lib/MongoDB/IOnboarding.mjs.map +0 -1
- package/dist/lib/MongoDB/MongoDBErrType.mjs.map +0 -1
- package/dist/lib/MongoDB/throwIfMongoErr.mjs.map +0 -1
- package/dist/lib/MongoDB/throwMongoErrors.mjs.map +0 -1
- package/dist/lib/NumLib.mjs.map +0 -1
- package/dist/lib/PostgreSQL/IPostgresError.mjs.map +0 -1
- package/dist/lib/PostgreSQL/IPostgresErrorCodes.mjs.map +0 -1
- package/dist/lib/PostgreSQL/makePostgreSqlLogError.mjs.map +0 -1
- package/dist/lib/Redis/RedisBoolean.mjs.map +0 -1
- package/dist/lib/Redis/buildPrefixedRedisKey.mjs.map +0 -1
- package/dist/lib/Redis/fromRedisBooleanValue.mjs.map +0 -1
- package/dist/lib/Redis/toRedisBooleanValue.mjs.map +0 -1
- package/dist/lib/StringLib.mjs.map +0 -1
- package/dist/lib/access/accessPaths.mjs.map +0 -1
- package/dist/lib/access/createResetPwdFlow.mjs.map +0 -1
- package/dist/lib/access/createVerifyEmailFlow.mjs.map +0 -1
- package/dist/lib/checkEmailLen.mjs.map +0 -1
- package/dist/lib/checkPwdLen.mjs.map +0 -1
- package/dist/lib/db/log/hitStat.mjs.map +0 -1
- package/dist/lib/db/log/logGlobalError.mjs.map +0 -1
- package/dist/lib/db/log/logGraphql.mjs.map +0 -1
- package/dist/lib/db/log/logThrow.mjs.map +0 -1
- package/dist/lib/db/login/ILoginSet.mjs.map +0 -1
- package/dist/lib/db/login/ILoginUnset.mjs.map +0 -1
- package/dist/lib/db/registerNewUser.mjs.map +0 -1
- package/dist/lib/db/userExist.mjs.map +0 -1
- package/dist/lib/emailHash.mjs.map +0 -1
- package/dist/lib/encryptPassword.mjs.map +0 -1
- package/dist/lib/hash.mjs.map +0 -1
- package/dist/lib/isSafeRedirectTarget.mjs.map +0 -1
- package/dist/lib/isSessionBlocked.mjs.map +0 -1
- package/dist/lib/isValidUuidV4.mjs.map +0 -1
- package/dist/lib/makeOnboardingData.mjs.map +0 -1
- package/dist/lib/setLoginCookies.mjs.map +0 -1
- package/dist/lib/sleepMs.mjs.map +0 -1
- package/dist/lib/throwIfNotValidEnumValue.mjs.map +0 -1
- package/dist/lib/tokenOptions.mjs.map +0 -1
- package/dist/lib/tokens.mjs.map +0 -1
- package/dist/lib/tryCatchRethrow.mjs.map +0 -1
- package/dist/private/files/_validateMimeType.mjs.map +0 -1
- package/dist/private/files/assertNoTraversal.mjs.map +0 -1
- package/dist/private/files/reEncode.mjs.map +0 -1
- package/dist/private/graphQL/Consts.mjs.map +0 -1
- package/dist/private/graphQL/models/MongoDB/private/UserAdminKoaUtils.mjs.map +0 -1
- package/dist/private/graphQL/schema/context/IContextLog.mjs.map +0 -1
- package/dist/private/graphQL/schema/context/IContextVerifyEmail.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/_buildLoginStatsUpdate.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/_finalizeLoginCheck.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/checkUserAdminLoginAuthorization.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/infoUserAdminForLogin.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/infoUserForLogin.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/infoUserForLoginSQL.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/setLastLoginSQL.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/setRedisLoginSession.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/updateAdminLoginStats.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/updateLoginStats4ever.mjs.map +0 -1
- package/dist/private/graphQL/schema/mutations/updateLoginStatsRememberme.mjs.map +0 -1
- package/dist/private/lib/access/Constants.mjs.map +0 -1
- package/dist/private/lib/access/assertVerifyEmailAllowed.mjs.map +0 -1
- package/dist/private/lib/access/db/confirmNewEmail.mjs.map +0 -1
- package/dist/private/lib/access/db/deleteUserByEmail.mjs.map +0 -1
- package/dist/private/lib/access/db/enableEmailAccess.mjs.map +0 -1
- package/dist/private/lib/access/db/getResetPwd.mjs.map +0 -1
- package/dist/private/lib/access/db/incReqTimes.mjs.map +0 -1
- package/dist/private/lib/access/db/removeResetReq.mjs.map +0 -1
- package/dist/private/lib/access/db/saveResetReq.mjs.map +0 -1
- package/dist/private/lib/access/db/setEmailHash.mjs.map +0 -1
- package/dist/private/lib/access/db/updatePasswordDb.mjs.map +0 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs.map +0 -1
- package/dist/private/lib/access/handleBadDB.mjs.map +0 -1
- package/dist/private/lib/access/handleIfAccountDeleted.mjs.map +0 -1
- package/dist/private/lib/access/handleIfAccountDisabled.mjs.map +0 -1
- package/dist/private/lib/access/handleIfEmailAlreadyValid.mjs.map +0 -1
- package/dist/private/lib/access/handleIfHashBad.mjs.map +0 -1
- package/dist/private/lib/access/handleIfMoreThan3DaysPassed.mjs.map +0 -1
- package/dist/private/lib/access/handleIfTooMuchRequestsTimes.mjs.map +0 -1
- package/dist/private/lib/access/pathTools.mjs.map +0 -1
- package/dist/private/lib/makeBodyJson.mjs.map +0 -1
- package/dist/private/lib/verifyIntrospectionCode.mjs.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IVerifyEmailPaths, TAccessModel, TOnAbandon } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
import { TDeleteUserByEmail } from './deleteUserByEmail.mjs';
|
|
3
|
+
/** Model, field map and disposal policy for {@link createAbandonUser}. */
|
|
4
|
+
export interface ICreateAbandonUserArgs {
|
|
5
|
+
model: TAccessModel;
|
|
6
|
+
paths: IVerifyEmailPaths;
|
|
7
|
+
/** See {@link TOnAbandon}. */
|
|
8
|
+
mode: TOnAbandon;
|
|
9
|
+
/**
|
|
10
|
+
* Value `'soft-delete'` writes to `paths.deleted`. A function is called once per write, so a layout
|
|
11
|
+
* storing a timestamp passes `() => new Date()`.
|
|
12
|
+
*
|
|
13
|
+
* Default `true`, matching `UserBase`, where `account.deleted` is `type: Boolean`. Not hard-coded: the
|
|
14
|
+
* guards only test the flag for truthiness, so what belongs in the slot is the schema's business.
|
|
15
|
+
*/
|
|
16
|
+
deletedValue?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build the writer the two abandonment guards call — `handleIfMoreThan3DaysPassed` (link older than 3 days)
|
|
20
|
+
* and `handleIfTooMuchRequestsTimes` (fifth wrong hash).
|
|
21
|
+
*
|
|
22
|
+
* All three modes share one signature, so the guards stay unaware of which policy they are running under.
|
|
23
|
+
* They throw either way: the mode decides what happens to the row, never whether the link is honoured.
|
|
24
|
+
*/
|
|
25
|
+
export declare const createAbandonUser: ({ model, paths, mode, deletedValue }: ICreateAbandonUserArgs) => TDeleteUserByEmail;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createDeleteUserByEmail } from './deleteUserByEmail.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Build the writer the two abandonment guards call — `handleIfMoreThan3DaysPassed` (link older than 3 days)
|
|
4
|
+
* and `handleIfTooMuchRequestsTimes` (fifth wrong hash).
|
|
5
|
+
*
|
|
6
|
+
* All three modes share one signature, so the guards stay unaware of which policy they are running under.
|
|
7
|
+
* They throw either way: the mode decides what happens to the row, never whether the link is honoured.
|
|
8
|
+
*/
|
|
9
|
+
export const createAbandonUser = ({ model, paths, mode, deletedValue = true }) => {
|
|
10
|
+
if (mode === 'keep') {
|
|
11
|
+
return async function keepUser() {
|
|
12
|
+
// Nothing to do: the caller disposes of abandoned registrations themselves.
|
|
13
|
+
return undefined;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (mode === 'soft-delete') {
|
|
17
|
+
return async function softDeleteUserByEmail(email) {
|
|
18
|
+
const value = typeof deletedValue === 'function' ? deletedValue() : deletedValue;
|
|
19
|
+
// Only the tombstone is written. The verification fields are left as they are — the flag is what
|
|
20
|
+
// every guard reads, and unsetting members of a strict subdocument is what `verifyClear` exists for.
|
|
21
|
+
await model.updateOne({ [paths.email]: email }, { $set: { [paths.deleted]: value } }, { runValidators: true });
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return createDeleteUserByEmail(model, paths);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=abandonUser.mjs.map
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Hard delete of an abandoned pending registration, keyed by the login-email path.
|
|
4
|
+
*
|
|
5
|
+
* Reached through `createAbandonUser`, which is what decides whether abandonment means this, a tombstone
|
|
6
|
+
* flag or nothing at all — the package cannot know what deleting a row costs in a model it was handed.
|
|
7
|
+
* See `TOnAbandon`.
|
|
8
|
+
*/
|
|
2
9
|
export declare const createDeleteUserByEmail: (model: TAccessModel, paths: IVerifyEmailPaths) => (email: string) => Promise<void>;
|
|
3
10
|
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
4
11
|
export type TDeleteUserByEmail = ReturnType<typeof createDeleteUserByEmail>;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
// @todo report on Sentry
|
|
2
1
|
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
3
2
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
3
|
+
import * as Sentry from '@sentry/node';
|
|
4
|
+
/**
|
|
5
|
+
* Hard delete of an abandoned pending registration, keyed by the login-email path.
|
|
6
|
+
*
|
|
7
|
+
* Reached through `createAbandonUser`, which is what decides whether abandonment means this, a tombstone
|
|
8
|
+
* flag or nothing at all — the package cannot know what deleting a row costs in a model it was handed.
|
|
9
|
+
* See `TOnAbandon`.
|
|
10
|
+
*/
|
|
4
11
|
export const createDeleteUserByEmail = (model, paths) => async function deleteUserByEmail(email) {
|
|
5
|
-
await model.deleteOne({ [paths.email]: email });
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
const ret = await model.deleteOne({ [paths.email]: email });
|
|
13
|
+
if (ret.deletedCount === 0) {
|
|
14
|
+
// The caller read this account moments ago and its guards decided the registration was abandoned, so
|
|
15
|
+
// nothing matching means the address moved, the path map is wrong, or another writer got there first.
|
|
16
|
+
// Reporting nothing is what left a delete that matched nothing indistinguishable from one that worked.
|
|
17
|
+
Sentry.captureMessage(`[deleteUserByEmail] no document matched ${paths.email} = ${email}`, 'warning');
|
|
18
|
+
}
|
|
8
19
|
};
|
|
9
20
|
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
10
21
|
export default createDeleteUserByEmail(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { IVerifyEmailPaths, TAccessModel } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
import { IVerifyEmailMailer } from "../../../../lib/access/verifyEmailMailer.mjs";
|
|
2
3
|
import mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Mark the address verified, clear the pending-verification fields, welcome the user.
|
|
6
|
+
*
|
|
7
|
+
* The welcome mail goes through an injected mailer so the success path is drivable from an integration suite
|
|
8
|
+
* without a real send. It is never debounced: it fires once per account, on the one path that already required
|
|
9
|
+
* a valid hash. See `throttleMailer`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createEnableEmailAccess: (model: TAccessModel, paths: IVerifyEmailPaths, mailer: IVerifyEmailMailer) => (_id: mongoose.Types.ObjectId, email: string) => Promise<void>;
|
|
4
12
|
/** Signature of the bound writer, for the modules that take it as a dependency. */
|
|
5
13
|
export type TEnableEmailAccess = ReturnType<typeof createEnableEmailAccess>;
|
|
6
14
|
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import { SocketLabsLib } from "../../../../email/SocketLabsLib.mjs";
|
|
2
1
|
import { DEFAULT_VERIFY_EMAIL_PATHS } from "../../../../lib/access/accessPaths.mjs";
|
|
2
|
+
import { defaultVerifyEmailMailer } from "../../../../lib/access/verifyEmailMailer.mjs";
|
|
3
3
|
import { UserBase } from "../../../../graphQL/models/MongoDB/UserBase.mjs";
|
|
4
4
|
import { buildUnset } from "../pathTools.mjs";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Mark the address verified, clear the pending-verification fields, welcome the user.
|
|
7
|
+
*
|
|
8
|
+
* The welcome mail goes through an injected mailer so the success path is drivable from an integration suite
|
|
9
|
+
* without a real send. It is never debounced: it fires once per account, on the one path that already required
|
|
10
|
+
* a valid hash. See `throttleMailer`.
|
|
11
|
+
*/
|
|
12
|
+
export const createEnableEmailAccess = (model, paths, mailer) => async function enableEmailAccess(_id, email) {
|
|
6
13
|
await model.updateOne({ _id }, {
|
|
7
14
|
$set: { [paths.valid]: true },
|
|
8
15
|
$unset: buildUnset(paths.verifyClear)
|
|
9
16
|
}, {
|
|
10
17
|
runValidators: true
|
|
11
18
|
});
|
|
12
|
-
|
|
13
|
-
await SocketLabsObj.sendWelcome(email);
|
|
19
|
+
await mailer.sendWelcome(email);
|
|
14
20
|
};
|
|
15
21
|
/** `UserBase`-bound default — the behaviour every existing consumer already imports. */
|
|
16
|
-
export const enableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS);
|
|
22
|
+
export const enableEmailAccess = createEnableEmailAccess(UserBase, DEFAULT_VERIFY_EMAIL_PATHS, defaultVerifyEmailMailer);
|
|
17
23
|
//# sourceMappingURL=enableEmailAccess.mjs.map
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stored hash without its bookkeeping fields is our bug, not the caller's.
|
|
3
|
+
*
|
|
4
|
+
* It redirects exactly where a hash mismatch, an expired link and an unknown address redirect — that is the
|
|
5
|
+
* point. Through 5.6.1 this branch threw `/x/error` while an unknown address threw `EMAIL_CHECK_LINK`, so two
|
|
6
|
+
* distinguishable responses answered an unauthenticated GET and the pair told anybody who asked whether an
|
|
7
|
+
* address had an account. Worse on data predating the verification fields, where every real account answered
|
|
8
|
+
* `/x/error` and every unknown one answered the other: a clean enumeration oracle.
|
|
9
|
+
*
|
|
10
|
+
* The distinction is kept where it belongs — Sentry, which is who needs to know.
|
|
11
|
+
*/
|
|
1
12
|
export declare function handleBadDB(requestTimes?: number, dateLastReq?: Date): void;
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
|
+
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* A stored hash without its bookkeeping fields is our bug, not the caller's.
|
|
5
|
+
*
|
|
6
|
+
* It redirects exactly where a hash mismatch, an expired link and an unknown address redirect — that is the
|
|
7
|
+
* point. Through 5.6.1 this branch threw `/x/error` while an unknown address threw `EMAIL_CHECK_LINK`, so two
|
|
8
|
+
* distinguishable responses answered an unauthenticated GET and the pair told anybody who asked whether an
|
|
9
|
+
* address had an account. Worse on data predating the verification fields, where every real account answered
|
|
10
|
+
* `/x/error` and every unknown one answered the other: a clean enumeration oracle.
|
|
11
|
+
*
|
|
12
|
+
* The distinction is kept where it belongs — Sentry, which is who needs to know.
|
|
13
|
+
*/
|
|
2
14
|
export function handleBadDB(requestTimes, dateLastReq) {
|
|
3
15
|
if (typeof requestTimes === 'undefined' || dateLastReq === undefined) {
|
|
4
16
|
Sentry.captureMessage('[handleBadDB] DB ERROR', 'error');
|
|
5
17
|
// it's an our error !! cannot be present the hash without requestTimes!
|
|
6
|
-
throw new Error(
|
|
18
|
+
throw new Error(EMAIL_CHECK_LINK);
|
|
7
19
|
}
|
|
8
20
|
}
|
|
9
21
|
//# sourceMappingURL=handleBadDB.mjs.map
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The account carries the tombstone flag.
|
|
4
|
+
*
|
|
5
|
+
* Sends `accountDisabled`, not an `accountDeleted` of its own: `SocketLabsLib` has no such template, so a
|
|
6
|
+
* deleted account is told it is disabled. That is the shipped copy, left as it is here on purpose — this is
|
|
7
|
+
* the guard, not the place to invent a message.
|
|
8
|
+
*
|
|
9
|
+
* Like every other counter-less branch it mails on each request, which is why the mailer is injected and the
|
|
10
|
+
* default one is debounced. See `createMailThrottle`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const createHandleIfAccountDeleted: (mailer: IVerifyEmailMailer) => (email: string, deleted?: boolean) => Promise<void>;
|
|
13
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
14
|
+
export type THandleIfAccountDeleted = ReturnType<typeof createHandleIfAccountDeleted>;
|
|
15
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
|
|
16
|
+
export declare const handleIfAccountDeleted: THandleIfAccountDeleted;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defaultVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
|
|
2
2
|
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The account carries the tombstone flag.
|
|
5
|
+
*
|
|
6
|
+
* Sends `accountDisabled`, not an `accountDeleted` of its own: `SocketLabsLib` has no such template, so a
|
|
7
|
+
* deleted account is told it is disabled. That is the shipped copy, left as it is here on purpose — this is
|
|
8
|
+
* the guard, not the place to invent a message.
|
|
9
|
+
*
|
|
10
|
+
* Like every other counter-less branch it mails on each request, which is why the mailer is injected and the
|
|
11
|
+
* default one is debounced. See `createMailThrottle`.
|
|
12
|
+
*/
|
|
13
|
+
export const createHandleIfAccountDeleted = (mailer) => async function handleIfAccountDeleted(email, deleted = false) {
|
|
4
14
|
if (deleted) {
|
|
5
|
-
|
|
6
|
-
await SocketLabsObj.accountDisabled(email);
|
|
15
|
+
await mailer.accountDisabled(email);
|
|
7
16
|
throw new Error(EMAIL_CHECK_LINK);
|
|
8
17
|
}
|
|
9
|
-
}
|
|
18
|
+
};
|
|
19
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
|
|
20
|
+
export const handleIfAccountDeleted = createHandleIfAccountDeleted(defaultVerifyEmailMailer);
|
|
10
21
|
//# sourceMappingURL=handleIfAccountDeleted.mjs.map
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The account carries the lockout flag.
|
|
4
|
+
*
|
|
5
|
+
* Byte-identical to `handleIfAccountDeleted` apart from the flag it reads, because there is only one
|
|
6
|
+
* template for both states. Kept as two guards so the chain reads as the two distinct conditions it checks.
|
|
7
|
+
*
|
|
8
|
+
* Counter-less like the rest, so the mailer is injected and the default one is debounced. See
|
|
9
|
+
* `createMailThrottle`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createHandleIfAccountDisabled: (mailer: IVerifyEmailMailer) => (email: string, disabled?: boolean) => Promise<void>;
|
|
12
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
13
|
+
export type THandleIfAccountDisabled = ReturnType<typeof createHandleIfAccountDisabled>;
|
|
14
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
|
|
15
|
+
export declare const handleIfAccountDisabled: THandleIfAccountDisabled;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defaultVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
|
|
2
2
|
import { EMAIL_CHECK_LINK } from './Constants.mjs';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The account carries the lockout flag.
|
|
5
|
+
*
|
|
6
|
+
* Byte-identical to `handleIfAccountDeleted` apart from the flag it reads, because there is only one
|
|
7
|
+
* template for both states. Kept as two guards so the chain reads as the two distinct conditions it checks.
|
|
8
|
+
*
|
|
9
|
+
* Counter-less like the rest, so the mailer is injected and the default one is debounced. See
|
|
10
|
+
* `createMailThrottle`.
|
|
11
|
+
*/
|
|
12
|
+
export const createHandleIfAccountDisabled = (mailer) => async function handleIfAccountDisabled(email, disabled = false) {
|
|
4
13
|
if (disabled) {
|
|
5
|
-
|
|
6
|
-
await SocketLabsObj.accountDisabled(email);
|
|
14
|
+
await mailer.accountDisabled(email);
|
|
7
15
|
throw new Error(EMAIL_CHECK_LINK);
|
|
8
16
|
}
|
|
9
|
-
}
|
|
17
|
+
};
|
|
18
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
|
|
19
|
+
export const handleIfAccountDisabled = createHandleIfAccountDisabled(defaultVerifyEmailMailer);
|
|
10
20
|
//# sourceMappingURL=handleIfAccountDisabled.mjs.map
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { IVerifyEmailMailer } from "../../../lib/access/verifyEmailMailer.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The address in the link is already verified.
|
|
4
|
+
*
|
|
5
|
+
* The notification goes through an injected mailer, which buys two things. The branch becomes drivable from
|
|
6
|
+
* an integration suite without a real send — the SocketLabs client used to be constructed right here, so
|
|
7
|
+
* reaching this path with real credentials mailed a real person. And the debounce gets somewhere to live:
|
|
8
|
+
* this guard has no counter behind it, so through 5.6.1 an unauthenticated GET mailed the address once per
|
|
9
|
+
* request, for as many requests as the caller cared to make. `defaultVerifyEmailMailer` is throttled — see
|
|
10
|
+
* `createMailThrottle`.
|
|
11
|
+
*
|
|
12
|
+
* A suppressed mail changes nothing the caller can observe: the throw, and so the redirect, is unconditional.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createHandleIfEmailAlreadyValid: (mailer: IVerifyEmailMailer) => (uEmail: string, valid: boolean) => Promise<void>;
|
|
15
|
+
/** Signature of the bound guard, for the modules that take it as a dependency. */
|
|
16
|
+
export type THandleIfEmailAlreadyValid = ReturnType<typeof createHandleIfEmailAlreadyValid>;
|
|
17
|
+
/** `UserBase`-bound default — the behaviour every existing consumer already imports, now debounced. */
|
|
18
|
+
export declare const handleIfEmailAlreadyValid: THandleIfEmailAlreadyValid;
|
|
@@ -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,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,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,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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiumine/koa-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
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"
|
|
@@ -638,27 +646,69 @@
|
|
|
638
646
|
}
|
|
639
647
|
},
|
|
640
648
|
"files": [
|
|
641
|
-
"dist"
|
|
649
|
+
"dist",
|
|
650
|
+
"!dist/**/*.mjs.map",
|
|
651
|
+
"!dist/**/*.js.map"
|
|
642
652
|
],
|
|
643
653
|
"dependencies": {},
|
|
644
654
|
"peerDependencies": {
|
|
645
|
-
"@node-rs/bcrypt": "
|
|
646
|
-
"@sentry/node": "
|
|
647
|
-
"@socketlabs/email": "
|
|
648
|
-
"clamscan": "
|
|
649
|
-
"dotenv": "
|
|
650
|
-
"file-type": "
|
|
651
|
-
"fs-extra": "
|
|
652
|
-
"graphql": "
|
|
655
|
+
"@node-rs/bcrypt": "<2",
|
|
656
|
+
"@sentry/node": "<11",
|
|
657
|
+
"@socketlabs/email": "<2",
|
|
658
|
+
"clamscan": "<3",
|
|
659
|
+
"dotenv": "<18",
|
|
660
|
+
"file-type": "<23",
|
|
661
|
+
"fs-extra": "<12",
|
|
662
|
+
"graphql": "<17",
|
|
653
663
|
"keygrip": "^1.1.0",
|
|
654
|
-
"
|
|
655
|
-
"
|
|
656
|
-
"
|
|
657
|
-
"
|
|
658
|
-
"
|
|
659
|
-
"
|
|
660
|
-
"
|
|
661
|
-
"
|
|
664
|
+
"koa": "<4",
|
|
665
|
+
"mariadb": "<4",
|
|
666
|
+
"mongoose": "<10",
|
|
667
|
+
"pg": "<9",
|
|
668
|
+
"redis": "<6",
|
|
669
|
+
"reflect-metadata": "<0.3",
|
|
670
|
+
"sequelize": "<7",
|
|
671
|
+
"sequelize-typescript": "<3",
|
|
672
|
+
"sharp": "<1",
|
|
673
|
+
"uuid": "<15"
|
|
674
|
+
},
|
|
675
|
+
"peerDependenciesMeta": {
|
|
676
|
+
"@socketlabs/email": {
|
|
677
|
+
"optional": true
|
|
678
|
+
},
|
|
679
|
+
"clamscan": {
|
|
680
|
+
"optional": true
|
|
681
|
+
},
|
|
682
|
+
"file-type": {
|
|
683
|
+
"optional": true
|
|
684
|
+
},
|
|
685
|
+
"fs-extra": {
|
|
686
|
+
"optional": true
|
|
687
|
+
},
|
|
688
|
+
"keygrip": {
|
|
689
|
+
"optional": true
|
|
690
|
+
},
|
|
691
|
+
"koa": {
|
|
692
|
+
"optional": true
|
|
693
|
+
},
|
|
694
|
+
"mariadb": {
|
|
695
|
+
"optional": true
|
|
696
|
+
},
|
|
697
|
+
"pg": {
|
|
698
|
+
"optional": true
|
|
699
|
+
},
|
|
700
|
+
"reflect-metadata": {
|
|
701
|
+
"optional": true
|
|
702
|
+
},
|
|
703
|
+
"sequelize": {
|
|
704
|
+
"optional": true
|
|
705
|
+
},
|
|
706
|
+
"sequelize-typescript": {
|
|
707
|
+
"optional": true
|
|
708
|
+
},
|
|
709
|
+
"sharp": {
|
|
710
|
+
"optional": true
|
|
711
|
+
}
|
|
662
712
|
},
|
|
663
713
|
"devDependencies": {
|
|
664
714
|
"@axiumine/eslint-config-be": "^2.0.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MariaDB.mjs","sourceRoot":"","sources":["../../src/dataSources/MariaDB.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,CACrC,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,EAC/B,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,EAC7B,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,EAC5B;IACC,IAAI,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE;IACjC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;IACpB,IAAI,EAAE;QACL,2BAA2B;QAC3B,GAAG,EAAE,EAAE;QACP,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,KAAK;KACd;IACD,KAAK,EAAE;QACN;;;;;aAKK;QACL,WAAW,EAAE,GAAG;QAChB,eAAe,EAAE,GAAG;QACpB,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,GAAG,EAAE,6BAA6B;QACjD,GAAG,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC;KAClD;IACD,cAAc,EAAE;QACf,MAAM,EAAE,IAAI;QACZ,eAAe,EAAE,IAAI;QACrB,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,IAAI,IAAI;KAClE;IACD,IAAI,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,EAAE,CAAC;IACjD,4FAA4F;IAC5F,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,mCAAmC;CACxG,CACD,CAAA;AAED,0BAA0B;AAC1B,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;IACxC,OAAO,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;IACrD,IAAI,CAAC;QACJ,MAAM,SAAS,CAAC,YAAY,EAAE,CAAA;QAC9B,OAAO,CAAC,IAAI,CAAC,qEAAqE,CAAC,CAAA;IACpF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,QAAQ,GAAG,mDAAmD,CAAA;QACpE,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;YAC1B,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;SAC3B,CAAC,CAAA;QACF,MAAM;YACL,OAAO,EAAE,QAAQ;YACjB,QAAQ,EAAE,IAAI;SACd,CAAA;IACF,CAAC;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;IAC3C,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;IAC9D,IAAI,CAAC;QACJ,MAAM,SAAS,CAAC,KAAK,EAAE,CAAA;QACvB,OAAO,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAA;IAC/E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,QAAQ,GAAG,2DAA2D,CAAA;QAC5E,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;YAC1B,KAAK,EAAE,EAAE,MAAM,EAAE,qCAAqC,EAAE;SACxD,CAAC,CAAA;QACF,MAAM;YACL,OAAO,EAAE,QAAQ;YACjB,QAAQ,EAAE,IAAI;SACd,CAAA;IACF,CAAC;AACF,CAAC,CAAA","sourcesContent":["import * as Sentry from '@sentry/node'\nimport * as dotenv from 'dotenv'\nimport { Sequelize } from 'sequelize-typescript'\n\ndotenv.config()\n\nexport const sequelize = new Sequelize(\n\t`${process.env.MARIADB_DBNAME}`,\n\t`${process.env.MARIADB_USER}`,\n\t`${process.env.MARIADB_PWD}`,\n\t{\n\t\thost: `${process.env.MARIADB_IP}`,\n\t\tdialect: 'mariadb',\n\t\tquery: { raw: true },\n\t\tpool: {\n\t\t\t// handleDisconnects: true,\n\t\t\tmax: 13,\n\t\t\tmin: 1,\n\t\t\tidle: 10000,\n\t\t\tacquire: 20000\n\t\t},\n\t\tretry: {\n\t\t\t/* match: [\n\t\t\t\tSequelize.ConnectionError,\n\t\t\t\tSequelize.ConnectionTimedOutError,\n\t\t\t\tSequelize.TimeoutError,\n\t\t\t\t/Deadlock/i,\n\t\t\t], */\n\t\t\tbackoffBase: 100,\n\t\t\tbackoffExponent: 1.1,\n\t\t\ttimeout: 3000,\n\t\t\tbackoffJitter: 0.1, // Add this required property\n\t\t\tmax: parseInt(`${process.env.MARIADB_RETRY}`) || 5\n\t\t},\n\t\tdialectOptions: {\n\t\t\tuseUTC: true,\n\t\t\tskipSetTimezone: true,\n\t\t\tcompress: true,\n\t\t\trequestTimeout: parseInt(`${process.env.MARIADB_TIMEOUT}`) || 5000\n\t\t},\n\t\tport: parseInt(`${process.env.MARIADB_PORT}`, 10),\n\t\t/* c8 ignore next -- env-dependent boot config; covered only when MARIADB_LOGGING='false' */\n\t\tlogging: process.env.MARIADB_LOGGING === 'false' ? false : undefined // disable print queries in console\n\t}\n)\n\n// Setting up a connection\nexport const MariaDBConnect = async () => {\n\tconsole.info('[MariaDB] Try connect to database... ')\n\ttry {\n\t\tawait sequelize.authenticate()\n\t\tconsole.info('[MariaDB] OK: MariaDB connection has been established successfully.')\n\t} catch (e) {\n\t\tconst catchMex = '[MariaDB] FAIL: Unable to connect to the database'\n\t\tSentry.captureException(e, {\n\t\t\textra: { detail: catchMex }\n\t\t})\n\t\tthrow {\n\t\t\tmessage: catchMex,\n\t\t\tshutdown: true\n\t\t}\n\t}\n\treturn sequelize\n}\n\nexport const MariaDBDisconnect = async () => {\n\tconsole.info('[MariaDB] Try close connection to database... ')\n\ttry {\n\t\tawait sequelize.close()\n\t\tconsole.info('[MariaDB] OK: MariaDB connection has been closed successfully.')\n\t} catch (e) {\n\t\tconst catchMex = '[MariaDB] FAIL: Unable to close the database connection: '\n\t\tSentry.captureException(e, {\n\t\t\textra: { detail: 'Error during database disconnection' }\n\t\t})\n\t\tthrow {\n\t\t\tmessage: catchMex,\n\t\t\tshutdown: true\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDB.mjs","sourceRoot":"","sources":["../../src/dataSources/MongoDB.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AAEpC,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,sFAAsF;AACtF,wCAAwC;AAExC,MAAM,CAAC,KAAK,UAAU,cAAc;IACnC,OAAO,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;IAErD,MAAM,OAAO,GAA4B;QACxC,qBAAqB;QACrB,wBAAwB;QACxB,yBAAyB;QACzB,MAAM,EAAE,CAAC,EAAE,OAAO;QAClB,2BAA2B;QAC3B,4BAA4B;QAC5B,wBAAwB,EAAE,IAAI;QAC9B,qBAAqB;QAErB,iBAAiB;QACjB,SAAS,EAAE,IAAI;QACf,wEAAwE;QACxE,8DAA8D;QAC9D,uBAAuB;QACvB,mBAAmB;QACnB,gCAAgC;KAChC,CAAA;IACD,QAAQ,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAA;IACpC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA,CAAC,4BAA4B;IAC/D,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAA;IAC7D,qFAAqF;IACrF,OAAO,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAA;AACrF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACtC,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAA;IAC9D,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAA;IAC3B,OAAO,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAA;AAC/E,CAAC","sourcesContent":["import * as dotenv from 'dotenv'\nimport * as mongoose from 'mongoose'\n\ndotenv.config()\n\n// DeprecationWarning: collection.ensureIndex is deprecated.Use createIndexes instead.\n// mongoose.set('useCreateIndex', true);\n\nexport async function MongoDBConnect() {\n\tconsole.info('[MongoDB] Try connect to database... ')\n\n\tconst options: mongoose.ConnectOptions = {\n\t\t// initial directives\n\t\t// useCreateIndex: true,\n\t\t// useNewUrlParser: true,\n\t\tfamily: 4, // ipv4\n\t\t// useFindAndModify: false,\n\t\t// useUnifiedTopology: true,\n\t\tserverSelectionTimeoutMS: 5000,\n\t\t// retryWrites: true,\n\n\t\t// new directives\n\t\tautoIndex: true\n\t\t// reconnectTries: Number.MAX_VALUE, // conflict with useUnifiedTopology\n\t\t// reconnectInterval: 500, // conflict with useUnifiedTopology\n\t\t// bufferMaxEntries: 0,\n\t\t// keepAlive: true,\n\t\t// keepAliveInitialDelay: 300000\n\t}\n\tmongoose.set('sanitizeFilter', true)\n\tmongoose.set('strictQuery', false) // will be done in mongose 7\n\tawait mongoose.connect(`${process.env.MONGODB_URI}`, options)\n\t/* c8 ignore next 2 -- success log + closing brace; covered only with live MongoDB */\n\tconsole.info('[MongoDB] OK: MongoDB connection has been established successfully. ')\n}\n\nexport async function MongoDBDisconnect() {\n\tconsole.info('[MongoDB] Try close connection to database... ')\n\tawait mongoose.disconnect()\n\tconsole.info('[MongoDB] OK: MongoDB connection has been closed successfully.')\n}\n"]}
|