@axiumine/koa-utils 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/email/SocketLabsLib.mjs +0 -2
- package/dist/email/SocketLabsLib.mjs.map +1 -1
- package/dist/files/checkForNSFW.mjs +3 -3
- package/dist/files/checkForNSFW.mjs.map +1 -1
- package/dist/files/scanVirus.mjs +0 -3
- package/dist/files/scanVirus.mjs.map +1 -1
- package/dist/files/storeUploadAsTemp.mjs +0 -1
- package/dist/files/storeUploadAsTemp.mjs.map +1 -1
- package/dist/files/uploadTempImage.mjs +0 -2
- package/dist/files/uploadTempImage.mjs.map +1 -1
- package/dist/files/uploadTempPdf.mjs +0 -1
- package/dist/files/uploadTempPdf.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +0 -6
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/login4Ever.mjs +0 -8
- package/dist/graphQL/schema/mutations/login4Ever.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginAdmin.mjs +0 -1
- package/dist/graphQL/schema/mutations/loginAdmin.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/loginRememberme.mjs +0 -1
- package/dist/graphQL/schema/mutations/loginRememberme.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/refresh.mjs +0 -1
- package/dist/graphQL/schema/mutations/refresh.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/resetPwd.mjs +1 -5
- package/dist/graphQL/schema/mutations/resetPwd.mjs.map +1 -1
- package/dist/graphQL/schema/mutations/updatePassword.mjs +3 -4
- package/dist/graphQL/schema/mutations/updatePassword.mjs.map +1 -1
- package/dist/koa/logRequestToDb.mjs +0 -11
- package/dist/koa/logRequestToDb.mjs.map +1 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs +0 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs.map +1 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs +0 -4
- package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs.map +1 -1
- package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs +0 -5
- package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs.map +1 -1
- package/dist/koa/middleware/debug/index.mjs +0 -5
- package/dist/koa/middleware/debug/index.mjs.map +1 -1
- package/dist/lib/DateLib.mjs +1 -6
- package/dist/lib/DateLib.mjs.map +1 -1
- package/dist/lib/db/registerNewUser.mjs +0 -2
- package/dist/lib/db/registerNewUser.mjs.map +1 -1
- package/dist/private/files/_validateMimeType.mjs +0 -1
- package/dist/private/files/_validateMimeType.mjs.map +1 -1
- package/dist/private/graphQL/schema/mutations/_finalizeLoginCheck.mjs +0 -3
- package/dist/private/graphQL/schema/mutations/_finalizeLoginCheck.mjs.map +1 -1
- package/dist/private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs +0 -1
- package/dist/private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs.map +1 -1
- package/dist/private/graphQL/schema/mutations/infoUserAdminForLogin.mjs +0 -1
- package/dist/private/graphQL/schema/mutations/infoUserAdminForLogin.mjs.map +1 -1
- package/dist/private/graphQL/schema/mutations/infoUserForLogin.mjs +0 -1
- package/dist/private/graphQL/schema/mutations/infoUserForLogin.mjs.map +1 -1
- package/dist/private/lib/access/db/saveResetReq.mjs +0 -1
- package/dist/private/lib/access/db/saveResetReq.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -332,8 +332,6 @@ SendResponse {
|
|
|
332
332
|
basicMessage.setTo(emailTo);
|
|
333
333
|
return this.client.send(basicMessage).then(() => {
|
|
334
334
|
//Handle successful API call
|
|
335
|
-
// console.debug('[sendEmail] Email sent correctly')
|
|
336
|
-
//console. // console.debug('[sendEmail] Email sent correctly')(res);
|
|
337
335
|
return true;
|
|
338
336
|
}, (e) => {
|
|
339
337
|
S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,CAAQ,EAAE,EAAE;YACZ,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;gBAC1B,KAAK,EAAE,EAAE,MAAM,EAAE,4BAA4B,EAAE;aAC/C,CAAC,CAAA;YACF,OAAO,KAAK,CAAA;QACb,CAAC,CACD,CAAA;IACF,CAAC;IAED;;;OAGG;IACK,WAAW;QAClB,OAAO,CACN,2HAA2H;YAC3H,uDAAuD;YACvD,SAAS;YACT,yEAAyE;YACzE,WAAW,CACX,CAAA;IACF,CAAC;IAED;;;OAGG;IACK,WAAW;QAClB,OAAO,CACN,UAAU;YACV,2EAA2E;YAC3E,SAAS;YACT,SAAS;YACT,uCAAuC;YACvC,gFAAgF;YAChF,QAAQ;YACR,+IAA+I,CAC/I,CAAA;IACF,CAAC;IAEO,OAAO,CAAC,IAAY;QAC3B,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC,CAAC;CACD","sourcesContent":["import { StringLib } from '@lib/StringLib.mjs'\nimport * as Sentry from '@sentry/node'\nimport { BasicMessage, SocketLabsClient } from '@socketlabs/email'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport * as dotenv from 'dotenv'\n\ndotenv.config()\n\ninterface ISendEmail {\n\temailFrom: string\n\temailFromName: string\n\temailTo: string\n\tsubject: string\n\ttextBody: string\n\thtmlBody: string\n}\n\ninterface IUserInfo {\n\t_id: string\n\tpersonalData: {\n\t\tname: string\n\t\tsurname: string\n\t}\n}\n\nexport class SocketLabsLib {\n\tprivate StringObj: StringLib\n\tprivate readonly platformName: string\n\tprivate readonly linkBase: string\n\tprivate readonly emailFrom: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate client: any\n\tprivate readonly emailHtmlHeader1: string\n\tprivate readonly emailHtmlHeader2: string\n\tprivate readonly emailHtmlFooter: string\n\n\tconstructor(htmlHeader1: string = '', htmlHeader2: string = '', htmlFooter: string = '') {\n\t\tthis.client = new SocketLabsClient(\n\t\t\t/* c8 ignore next -- env fallback '0' covered only when SOCKETLABS_SERVER_ID is unset */\n\t\t\tparseInt(process.env.SOCKETLABS_SERVER_ID || '0'),\n\t\t\t`${process.env.SOCKETLABS_SERVER_APIKEY}`,\n\t\t\t{ requestTimeout: 120, numberOfRetries: 3 }\n\t\t)\n\t\tthis.StringObj = new StringLib()\n\t\tthis.platformName = `${process.env.PLATFORM_NAME}`\n\t\tthis.linkBase = `${process.env.APP_DOMAIN}`\n\t\tthis.emailFrom = `${process.env.EMAIL_FROM}`\n\n\t\tthis.emailHtmlHeader1 = htmlHeader1 === '' ? this.htmlHeader1() : htmlHeader1\n\t\tthis.emailHtmlHeader2 = htmlHeader2 === '' ? this.htmlHeader2() : htmlHeader2\n\t\tthis.emailHtmlFooter = htmlFooter === '' ? this.htmlFooter() : htmlFooter\n\t}\n\n\tasync sendEmailVerify(emailTo: string, hash: string, name: string = '') {\n\t\tconst subject = `Confirm your email for ${this.platformName}`\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst nameFixed = this.fixName(name)\n\t\tconst link = `${this.linkBase}/check/verify-email/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\n\t\tconst messageTxt = `Hi${nameFixed}, you or someone else is registering you on ${this.platformName}.\n You can confirm the registration by copying this link ${link} into your browser. The Team`\n\t\tconst messageHtml = `Hi${nameFixed},<br>you or someone else is registering you on ${this.platformName}.<br><br>\n You can confirm the registration by visiting this link ${linkHtml}<br><br>\n <br><br>The Team`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\t/*\n async sendEmailPostReported(userInfo, idPost) {\n const subject = 'Post ' + idPost + ' reported'\n\n const messageTxt =\n 'Hello, post ' +\n idPost +\n ' has been reported by ' +\n userInfo.personalData.name +\n ' ' +\n userInfo.personalData.surname +\n ' (id: ' +\n userInfo._id +\n ').'\n\n const messageHtml =\n this.getHtmlHeader(subject) +\n 'Hello, post ' +\n idPost +\n ' has been reported by ' +\n userInfo.personalData.name +\n ' ' +\n userInfo.personalData.surname +\n ' (id: ' +\n userInfo._id +\n ').' +\n this.getHtmlFooter()\n\n const message = {\n emailFrom: this.emailFrom,\n emailFromName: this.platformName,\n emailTo: 'dummy@example.com',\n subject,\n textBody: messageTxt,\n htmlBody: messageHtml\n }\n return await this.sendEmail(message)\n }\n*/\n\t/**\n\t * @fixme handle retry\n\t *\nstatusCode: ECONNABORTED\nError in sending the email\nSendResponse {\n transactionReceipt: null,\n addressResults: null,\n result: {\n name: 'Timeout',\n value: 1,\n message: 'A timeout occurred sending the message'\n },\n responseMessage: 'A timeout occurred sending the message'\n}\n\t */\n\n\tasync sendEmailChangeVerify(emailTo: string, hash: string, name: string = '') {\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst subject = `Confirm your email for ${this.platformName}`\n\t\tconst nameFixed = this.fixName(name)\n\t\tconst link = `${this.linkBase}/check/verify-change-email/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\n\t\tconst messageTxt = `Hi${nameFixed}, you or someone else has changed the email you sign in with.\n You can confirm by copying this link ${link} into your browser. The Team.`\n\n\t\tconst messageHtml = `Hi${nameFixed},<br>you or someone else has changed the email you sign in with.<br><br>\n You can confirm the registration by visiting this link ${linkHtml}\n <br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\tasync sendWelcome(emailTo: string) {\n\t\tconst subject = `Welcome to ${this.platformName}`\n\t\tconst linkHtml = this.StringObj.makeLink(this.linkBase, this.platformName)\n\t\tconst messageTxt = `Welcome to ${this.platformName}`\n\t\tconst messageHtml = `Welcome to ${linkHtml}`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\t/**\n\t * Send account disabled notification\n\t * @param emailTo\n\t */\n\tasync accountDisabled(emailTo: string) {\n\t\tconst subject = 'Your account has been disabled'\n\t\tconst textBody = 'Hi, we are sorry but your account has been disabled. Contact us for more information.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * Send account disabled notification\n\t * @param emailTo\n\t */\n\tasync accountBanned(emailTo: string) {\n\t\tconst subject = 'Your account has been banned'\n\t\tconst textBody = 'Hi, we are sorry but your account has been banned. Contact us for more information.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * alertDevTeam\n\t * @param err\n\t */\n\tasync alertDevTeam(err: string) {\n\t\tconst textBody = 'error 500 ' + err\n\t\tconst htmlBody = '<p>error 500 <br><br>' + err + '</p>'\n\n\t\treturn await this.sendTemplate(`${process.env.DEV_TEAM_EMAIL}`, `${this.platformName} error 500`, textBody, htmlBody)\n\t}\n\n\t/**\n\t *\n\t * @param emailTo\n\t * @param times\n\t */\n\tasync wrongHash(emailTo: string, times: number) {\n\t\tif (times > 5) throwInternalError()\n\t\tconst remainingTimes = 5 - times\n\n\t\tconst subject = 'Wrong activation link'\n\t\tconst textBody = `Hi, you or someone else is trying to verify your email with a wrong link. You have ${remainingTimes} attempts remaining.`\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * Too much verify requests\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync tooMuchVerifyRequests(emailTo: string) {\n\t\tconst subject = 'Too many attempts to verify your email'\n\t\tconst textBody = 'Hi, you have made more than 5 attempts to verify your email. You need to repeat the registration request.'\n\t\tconst htmlBody =\n\t\t\t'<p>Hi, you have made 5 or more attempts to verify your email. You need to repeat the registration request.</p>'\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync hashReqTooOld(emailTo: string) {\n\t\tconst subject = 'Activation link expired'\n\t\tconst textBody =\n\t\t\t'Hi, the activation link you are trying to use is older than 3 days and has expired. You need to repeat the registration request.'\n\t\tconst htmlBody =\n\t\t\t'<p>Hi, the activation link you are trying to use is older than 3 days and has expired. You need to repeat the registration request.</p>'\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync emailAlreadyValid(emailTo: string) {\n\t\tconst subject = 'Account already valid'\n\t\tconst textBody = 'Hi, your account is already valid, you can log in.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * Send subscription email\n\t * @param emailTo\n\t * @param otp\n\t */\n\tasync sendSubscriptionEmail(emailTo: string, otp: string) {\n\t\tconst subject = `Activate your ${this.platformName} account`\n\t\tconst url = `${this.linkBase}/x/emailVerify`\n\t\tconst urlHtml = this.StringObj.makeLink(url)\n\t\tconst linkHomeHtml = this.StringObj.makeLink(this.linkBase, this.platformName)\n\n\t\tconst textBody = `To confirm your subscription on ${this.platformName}, open the following link in your browser\n ${url} and enter the following activation code: ${otp}`\n\n\t\tconst htmlBody = `<p>To confirm your subscription on ${linkHomeHtml}, open the following link in your browser\n ${urlHtml} and enter the following activation code: ${otp}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\tasync sendResetPwdConfirmation(emailTo: string, name: string = '') {\n\t\tconst subject = `Password reset for ${this.platformName}`\n\t\tconst link = this.linkBase\n\t\tconst linkHtml = this.StringObj.makeLink(link, this.platformName)\n\t\tconst nameFixed = this.fixName(name)\n\n\t\tconst textBody = `Hi${nameFixed}, you have confirmed your new password. You can now log in at: ${link}. The Team.`\n\t\tconst htmlBody = `Hi${nameFixed},<br>you have confirmed your new password.<br><br>You can now log in at:<br>${linkHtml}<br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\tasync sendResetPwdConfirmationHash(email: string, name: string, hash: string): Promise<boolean> {\n\t\tconst encodedEmail = encodeURI(email)\n\t\tconst subject = `Password change confirmation for ${this.platformName}`\n\t\tconst linkReset = this.linkBase + '/index.php?q=reset&hash=' + hash + '&email=' + encodedEmail\n\n\t\tconst textBody = 'Hi ' + name + ', you have confirmed your new password. You can now log in at: ' + this.linkBase + ' . '\n\t\tconst htmlBody =\n\t\t\tthis.getHtmlHeader(subject) +\n\t\t\t'Hi ' +\n\t\t\tname +\n\t\t\t',<br>you have confirmed your new password.<br><br>You can now log in at:<br> ' +\n\t\t\tthis.StringObj.makeLink(linkReset) +\n\t\t\t'<br><br>The Team' +\n\t\t\tthis.getHtmlFooter()\n\n\t\ttry {\n\t\t\treturn await this.sendTemplate(email, subject, textBody, htmlBody)\n\t\t} catch (e) {\n\t\t\tSentry.captureException(e)\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync sendEmailReset(emailTo: string, hash: string, name: string = '') {\n\t\tconst subject = `Password reset for ${this.platformName}`\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst link = `${this.linkBase}/x/reset/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\t\tconst nameFixed = this.fixName(name)\n\n\t\tconst textBody = `Hi${nameFixed}, you or someone else has requested a password reset. You can change your login password\n by copying this link ${link} into your browser. The Team.`\n\t\tconst htmlBody = `Hi${nameFixed},<br>you or someone else has requested a password reset.<br><br>\n You can change your password by clicking the link:<br>${linkHtml}\n <br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * fallback footer\n\t */\n\thtmlFooter() {\n\t\treturn '</p></td>' + ' </tr>' + ' </table>' + '</body>'\n\t}\n\n\t/**\n\t * send OTP\n\t * @param emailTo\n\t * @param otp\n\t */\n\tasync sendOTP(emailTo: string, otp: string): Promise<boolean> {\n\t\tconst subject = `OTP code for ${this.platformName}`\n\t\tconst textBody = `To confirm your subscription on ${this.platformName}, enter the following OTP code: ${otp}`\n\t\tconst htmlBody = `<p>To confirm your subscription on ${this.platformName}, enter the following OTP code: ${otp}</p>`\n\n\t\ttry {\n\t\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t\t} catch (e) {\n\t\t\tSentry.captureException(e)\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync sendEmailPostReported(userInfo: IUserInfo, idPost: number | string) {\n\t\tconst subject = 'Post ' + idPost + ' reported'\n\n\t\tconst messageTxt =\n\t\t\t'Hi, post ' +\n\t\t\tidPost +\n\t\t\t' has been reported by ' +\n\t\t\tuserInfo.personalData.name +\n\t\t\t' ' +\n\t\t\tuserInfo.personalData.surname +\n\t\t\t' (id: ' +\n\t\t\tuserInfo._id +\n\t\t\t').'\n\n\t\tconst messageHtml =\n\t\t\tthis.getHtmlHeader(subject) +\n\t\t\t'Hi, post ' +\n\t\t\tidPost +\n\t\t\t' has been reported by ' +\n\t\t\tuserInfo.personalData.name +\n\t\t\t' ' +\n\t\t\tuserInfo.personalData.surname +\n\t\t\t' (id: ' +\n\t\t\tuserInfo._id +\n\t\t\t').' +\n\t\t\tthis.getHtmlFooter()\n\n\t\treturn await this.sendTemplate(`${process.env.DEV_TEAM_EMAIL}`, subject, messageTxt, messageHtml)\n\t}\n\n\tgetHtmlHeader(title: string) {\n\t\treturn (\n\t\t\t'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">' +\n\t\t\t'<html xmlns=\"http://www.w3.org/1999/xhtml\">' +\n\t\t\t' <head>' +\n\t\t\t' <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />' +\n\t\t\t' <title>' +\n\t\t\ttitle +\n\t\t\t'</title>' +\n\t\t\t' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>' +\n\t\t\t'</head>' +\n\t\t\t'</html>' +\n\t\t\t'<body style=\"margin: 0; padding: 0;\">' +\n\t\t\t' <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">' +\n\t\t\t' <tr>' +\n\t\t\t' <td bgcolor=\"#ffffff\" style=\"padding: 40px 30px 40px 30px;\"><p style=\"color: #000000; font-family: Verdana, sans-serif; font-size: 12pt;\">'\n\t\t)\n\t}\n\n\tgetHtmlFooter() {\n\t\treturn '</p></td>' + ' </tr>' + ' </table>' + '</body>'\n\t}\n\n\tprivate async sendTemplate(emailTo: string, subject: string, textBody: string, htmlBody: string): Promise<boolean> {\n\t\treturn await this.sendEmail({\n\t\t\temailFrom: this.emailFrom,\n\t\t\temailFromName: this.platformName,\n\t\t\temailTo,\n\t\t\tsubject,\n\t\t\ttextBody,\n\t\t\thtmlBody\n\t\t})\n\t}\n\n\tprivate async sendEmail(args: ISendEmail): Promise<boolean> {\n\t\tconst { emailFrom, emailFromName, emailTo, subject, textBody, htmlBody } = args\n\t\tconst basicMessage = new BasicMessage()\n\t\tbasicMessage.setFromAddress(emailFrom, emailFromName)\n\t\tbasicMessage.setSubject(subject)\n\t\tbasicMessage.setTextBody(textBody)\n\t\tbasicMessage.setHtmlBody(this.emailHtmlHeader1 + subject + this.emailHtmlHeader2 + htmlBody + this.emailHtmlFooter)\n\t\tbasicMessage.setTo(emailTo)\n\n\t\treturn this.client.send(basicMessage).then(\n\t\t\t() => {\n\t\t\t\t//Handle successful API call\n\t\t\t\t// console.debug('[sendEmail] Email sent correctly')\n\t\t\t\t//console.\t\t\t\t// console.debug('[sendEmail] Email sent correctly')(res);\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t(e: Error) => {\n\t\t\t\tSentry.captureException(e, {\n\t\t\t\t\textra: { detail: 'Error in sending the email' }\n\t\t\t\t})\n\t\t\t\treturn false\n\t\t\t}\n\t\t)\n\t}\n\n\t/**\n\t * fallback header\n\t * @private\n\t */\n\tprivate htmlHeader1() {\n\t\treturn (\n\t\t\t'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">' +\n\t\t\t'<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">' +\n\t\t\t' <head>' +\n\t\t\t' <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />' +\n\t\t\t' <title>'\n\t\t)\n\t}\n\n\t/**\n\t * fallback header\n\t * @private\n\t */\n\tprivate htmlHeader2() {\n\t\treturn (\n\t\t\t'</title>' +\n\t\t\t' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>' +\n\t\t\t'</head>' +\n\t\t\t'</html>' +\n\t\t\t'<body style=\"margin: 0; padding: 0;\">' +\n\t\t\t' <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">' +\n\t\t\t' <tr>' +\n\t\t\t' <td bgcolor=\"#ffffff\" style=\"padding: 40px 30px 40px 30px;\"><p style=\"color: #000000; font-family: Verdana, sans-serif; font-size: 12pt;\">'\n\t\t)\n\t}\n\n\tprivate fixName(name: string) {\n\t\treturn name !== '' ? ` ${name}` : ''\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SocketLabsLib.mjs","sourceRoot":"","sources":["../../src/email/SocketLabsLib.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA0B;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,gDAAqC;AAClE,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,MAAM,CAAC,MAAM,EAAE,CAAA;AAmBf,MAAM,OAAO,aAAa;IACjB,SAAS,CAAW;IACX,YAAY,CA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AEO,OAAO,CAAC,IAAY;QAC3B,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACrC,CAAC;CACD","sourcesContent":["import { StringLib } from '@lib/StringLib.mjs'\nimport * as Sentry from '@sentry/node'\nimport { BasicMessage, SocketLabsClient } from '@socketlabs/email'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport * as dotenv from 'dotenv'\n\ndotenv.config()\n\ninterface ISendEmail {\n\temailFrom: string\n\temailFromName: string\n\temailTo: string\n\tsubject: string\n\ttextBody: string\n\thtmlBody: string\n}\n\ninterface IUserInfo {\n\t_id: string\n\tpersonalData: {\n\t\tname: string\n\t\tsurname: string\n\t}\n}\n\nexport class SocketLabsLib {\n\tprivate StringObj: StringLib\n\tprivate readonly platformName: string\n\tprivate readonly linkBase: string\n\tprivate readonly emailFrom: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tprivate client: any\n\tprivate readonly emailHtmlHeader1: string\n\tprivate readonly emailHtmlHeader2: string\n\tprivate readonly emailHtmlFooter: string\n\n\tconstructor(htmlHeader1: string = '', htmlHeader2: string = '', htmlFooter: string = '') {\n\t\tthis.client = new SocketLabsClient(\n\t\t\t/* c8 ignore next -- env fallback '0' covered only when SOCKETLABS_SERVER_ID is unset */\n\t\t\tparseInt(process.env.SOCKETLABS_SERVER_ID || '0'),\n\t\t\t`${process.env.SOCKETLABS_SERVER_APIKEY}`,\n\t\t\t{ requestTimeout: 120, numberOfRetries: 3 }\n\t\t)\n\t\tthis.StringObj = new StringLib()\n\t\tthis.platformName = `${process.env.PLATFORM_NAME}`\n\t\tthis.linkBase = `${process.env.APP_DOMAIN}`\n\t\tthis.emailFrom = `${process.env.EMAIL_FROM}`\n\n\t\tthis.emailHtmlHeader1 = htmlHeader1 === '' ? this.htmlHeader1() : htmlHeader1\n\t\tthis.emailHtmlHeader2 = htmlHeader2 === '' ? this.htmlHeader2() : htmlHeader2\n\t\tthis.emailHtmlFooter = htmlFooter === '' ? this.htmlFooter() : htmlFooter\n\t}\n\n\tasync sendEmailVerify(emailTo: string, hash: string, name: string = '') {\n\t\tconst subject = `Confirm your email for ${this.platformName}`\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst nameFixed = this.fixName(name)\n\t\tconst link = `${this.linkBase}/check/verify-email/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\n\t\tconst messageTxt = `Hi${nameFixed}, you or someone else is registering you on ${this.platformName}.\n You can confirm the registration by copying this link ${link} into your browser. The Team`\n\t\tconst messageHtml = `Hi${nameFixed},<br>you or someone else is registering you on ${this.platformName}.<br><br>\n You can confirm the registration by visiting this link ${linkHtml}<br><br>\n <br><br>The Team`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\t/*\n async sendEmailPostReported(userInfo, idPost) {\n const subject = 'Post ' + idPost + ' reported'\n\n const messageTxt =\n 'Hello, post ' +\n idPost +\n ' has been reported by ' +\n userInfo.personalData.name +\n ' ' +\n userInfo.personalData.surname +\n ' (id: ' +\n userInfo._id +\n ').'\n\n const messageHtml =\n this.getHtmlHeader(subject) +\n 'Hello, post ' +\n idPost +\n ' has been reported by ' +\n userInfo.personalData.name +\n ' ' +\n userInfo.personalData.surname +\n ' (id: ' +\n userInfo._id +\n ').' +\n this.getHtmlFooter()\n\n const message = {\n emailFrom: this.emailFrom,\n emailFromName: this.platformName,\n emailTo: 'dummy@example.com',\n subject,\n textBody: messageTxt,\n htmlBody: messageHtml\n }\n return await this.sendEmail(message)\n }\n*/\n\t/**\n\t * @fixme handle retry\n\t *\nstatusCode: ECONNABORTED\nError in sending the email\nSendResponse {\n transactionReceipt: null,\n addressResults: null,\n result: {\n name: 'Timeout',\n value: 1,\n message: 'A timeout occurred sending the message'\n },\n responseMessage: 'A timeout occurred sending the message'\n}\n\t */\n\n\tasync sendEmailChangeVerify(emailTo: string, hash: string, name: string = '') {\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst subject = `Confirm your email for ${this.platformName}`\n\t\tconst nameFixed = this.fixName(name)\n\t\tconst link = `${this.linkBase}/check/verify-change-email/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\n\t\tconst messageTxt = `Hi${nameFixed}, you or someone else has changed the email you sign in with.\n You can confirm by copying this link ${link} into your browser. The Team.`\n\n\t\tconst messageHtml = `Hi${nameFixed},<br>you or someone else has changed the email you sign in with.<br><br>\n You can confirm the registration by visiting this link ${linkHtml}\n <br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\tasync sendWelcome(emailTo: string) {\n\t\tconst subject = `Welcome to ${this.platformName}`\n\t\tconst linkHtml = this.StringObj.makeLink(this.linkBase, this.platformName)\n\t\tconst messageTxt = `Welcome to ${this.platformName}`\n\t\tconst messageHtml = `Welcome to ${linkHtml}`\n\n\t\treturn await this.sendTemplate(emailTo, subject, messageTxt, messageHtml)\n\t}\n\n\t/**\n\t * Send account disabled notification\n\t * @param emailTo\n\t */\n\tasync accountDisabled(emailTo: string) {\n\t\tconst subject = 'Your account has been disabled'\n\t\tconst textBody = 'Hi, we are sorry but your account has been disabled. Contact us for more information.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * Send account disabled notification\n\t * @param emailTo\n\t */\n\tasync accountBanned(emailTo: string) {\n\t\tconst subject = 'Your account has been banned'\n\t\tconst textBody = 'Hi, we are sorry but your account has been banned. Contact us for more information.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * alertDevTeam\n\t * @param err\n\t */\n\tasync alertDevTeam(err: string) {\n\t\tconst textBody = 'error 500 ' + err\n\t\tconst htmlBody = '<p>error 500 <br><br>' + err + '</p>'\n\n\t\treturn await this.sendTemplate(`${process.env.DEV_TEAM_EMAIL}`, `${this.platformName} error 500`, textBody, htmlBody)\n\t}\n\n\t/**\n\t *\n\t * @param emailTo\n\t * @param times\n\t */\n\tasync wrongHash(emailTo: string, times: number) {\n\t\tif (times > 5) throwInternalError()\n\t\tconst remainingTimes = 5 - times\n\n\t\tconst subject = 'Wrong activation link'\n\t\tconst textBody = `Hi, you or someone else is trying to verify your email with a wrong link. You have ${remainingTimes} attempts remaining.`\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * Too much verify requests\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync tooMuchVerifyRequests(emailTo: string) {\n\t\tconst subject = 'Too many attempts to verify your email'\n\t\tconst textBody = 'Hi, you have made more than 5 attempts to verify your email. You need to repeat the registration request.'\n\t\tconst htmlBody =\n\t\t\t'<p>Hi, you have made 5 or more attempts to verify your email. You need to repeat the registration request.</p>'\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync hashReqTooOld(emailTo: string) {\n\t\tconst subject = 'Activation link expired'\n\t\tconst textBody =\n\t\t\t'Hi, the activation link you are trying to use is older than 3 days and has expired. You need to repeat the registration request.'\n\t\tconst htmlBody =\n\t\t\t'<p>Hi, the activation link you are trying to use is older than 3 days and has expired. You need to repeat the registration request.</p>'\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/*****************\n\t * @param emailTo\n\t * @returns {Promise<string|null>}\n\t */\n\tasync emailAlreadyValid(emailTo: string) {\n\t\tconst subject = 'Account already valid'\n\t\tconst textBody = 'Hi, your account is already valid, you can log in.'\n\t\tconst htmlBody = `<p>${textBody}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * Send subscription email\n\t * @param emailTo\n\t * @param otp\n\t */\n\tasync sendSubscriptionEmail(emailTo: string, otp: string) {\n\t\tconst subject = `Activate your ${this.platformName} account`\n\t\tconst url = `${this.linkBase}/x/emailVerify`\n\t\tconst urlHtml = this.StringObj.makeLink(url)\n\t\tconst linkHomeHtml = this.StringObj.makeLink(this.linkBase, this.platformName)\n\n\t\tconst textBody = `To confirm your subscription on ${this.platformName}, open the following link in your browser\n ${url} and enter the following activation code: ${otp}`\n\n\t\tconst htmlBody = `<p>To confirm your subscription on ${linkHomeHtml}, open the following link in your browser\n ${urlHtml} and enter the following activation code: ${otp}</p>`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\tasync sendResetPwdConfirmation(emailTo: string, name: string = '') {\n\t\tconst subject = `Password reset for ${this.platformName}`\n\t\tconst link = this.linkBase\n\t\tconst linkHtml = this.StringObj.makeLink(link, this.platformName)\n\t\tconst nameFixed = this.fixName(name)\n\n\t\tconst textBody = `Hi${nameFixed}, you have confirmed your new password. You can now log in at: ${link}. The Team.`\n\t\tconst htmlBody = `Hi${nameFixed},<br>you have confirmed your new password.<br><br>You can now log in at:<br>${linkHtml}<br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\tasync sendResetPwdConfirmationHash(email: string, name: string, hash: string): Promise<boolean> {\n\t\tconst encodedEmail = encodeURI(email)\n\t\tconst subject = `Password change confirmation for ${this.platformName}`\n\t\tconst linkReset = this.linkBase + '/index.php?q=reset&hash=' + hash + '&email=' + encodedEmail\n\n\t\tconst textBody = 'Hi ' + name + ', you have confirmed your new password. You can now log in at: ' + this.linkBase + ' . '\n\t\tconst htmlBody =\n\t\t\tthis.getHtmlHeader(subject) +\n\t\t\t'Hi ' +\n\t\t\tname +\n\t\t\t',<br>you have confirmed your new password.<br><br>You can now log in at:<br> ' +\n\t\t\tthis.StringObj.makeLink(linkReset) +\n\t\t\t'<br><br>The Team' +\n\t\t\tthis.getHtmlFooter()\n\n\t\ttry {\n\t\t\treturn await this.sendTemplate(email, subject, textBody, htmlBody)\n\t\t} catch (e) {\n\t\t\tSentry.captureException(e)\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync sendEmailReset(emailTo: string, hash: string, name: string = '') {\n\t\tconst subject = `Password reset for ${this.platformName}`\n\t\tconst encodedEmail = encodeURI(emailTo)\n\t\tconst link = `${this.linkBase}/x/reset/${encodedEmail}/${hash}`\n\t\tconst linkHtml = this.StringObj.makeLink(link)\n\t\tconst nameFixed = this.fixName(name)\n\n\t\tconst textBody = `Hi${nameFixed}, you or someone else has requested a password reset. You can change your login password\n by copying this link ${link} into your browser. The Team.`\n\t\tconst htmlBody = `Hi${nameFixed},<br>you or someone else has requested a password reset.<br><br>\n You can change your password by clicking the link:<br>${linkHtml}\n <br><br>The Team.`\n\n\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t}\n\n\t/**\n\t * fallback footer\n\t */\n\thtmlFooter() {\n\t\treturn '</p></td>' + ' </tr>' + ' </table>' + '</body>'\n\t}\n\n\t/**\n\t * send OTP\n\t * @param emailTo\n\t * @param otp\n\t */\n\tasync sendOTP(emailTo: string, otp: string): Promise<boolean> {\n\t\tconst subject = `OTP code for ${this.platformName}`\n\t\tconst textBody = `To confirm your subscription on ${this.platformName}, enter the following OTP code: ${otp}`\n\t\tconst htmlBody = `<p>To confirm your subscription on ${this.platformName}, enter the following OTP code: ${otp}</p>`\n\n\t\ttry {\n\t\t\treturn await this.sendTemplate(emailTo, subject, textBody, htmlBody)\n\t\t} catch (e) {\n\t\t\tSentry.captureException(e)\n\t\t\treturn false\n\t\t}\n\t}\n\n\tasync sendEmailPostReported(userInfo: IUserInfo, idPost: number | string) {\n\t\tconst subject = 'Post ' + idPost + ' reported'\n\n\t\tconst messageTxt =\n\t\t\t'Hi, post ' +\n\t\t\tidPost +\n\t\t\t' has been reported by ' +\n\t\t\tuserInfo.personalData.name +\n\t\t\t' ' +\n\t\t\tuserInfo.personalData.surname +\n\t\t\t' (id: ' +\n\t\t\tuserInfo._id +\n\t\t\t').'\n\n\t\tconst messageHtml =\n\t\t\tthis.getHtmlHeader(subject) +\n\t\t\t'Hi, post ' +\n\t\t\tidPost +\n\t\t\t' has been reported by ' +\n\t\t\tuserInfo.personalData.name +\n\t\t\t' ' +\n\t\t\tuserInfo.personalData.surname +\n\t\t\t' (id: ' +\n\t\t\tuserInfo._id +\n\t\t\t').' +\n\t\t\tthis.getHtmlFooter()\n\n\t\treturn await this.sendTemplate(`${process.env.DEV_TEAM_EMAIL}`, subject, messageTxt, messageHtml)\n\t}\n\n\tgetHtmlHeader(title: string) {\n\t\treturn (\n\t\t\t'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">' +\n\t\t\t'<html xmlns=\"http://www.w3.org/1999/xhtml\">' +\n\t\t\t' <head>' +\n\t\t\t' <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />' +\n\t\t\t' <title>' +\n\t\t\ttitle +\n\t\t\t'</title>' +\n\t\t\t' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>' +\n\t\t\t'</head>' +\n\t\t\t'</html>' +\n\t\t\t'<body style=\"margin: 0; padding: 0;\">' +\n\t\t\t' <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">' +\n\t\t\t' <tr>' +\n\t\t\t' <td bgcolor=\"#ffffff\" style=\"padding: 40px 30px 40px 30px;\"><p style=\"color: #000000; font-family: Verdana, sans-serif; font-size: 12pt;\">'\n\t\t)\n\t}\n\n\tgetHtmlFooter() {\n\t\treturn '</p></td>' + ' </tr>' + ' </table>' + '</body>'\n\t}\n\n\tprivate async sendTemplate(emailTo: string, subject: string, textBody: string, htmlBody: string): Promise<boolean> {\n\t\treturn await this.sendEmail({\n\t\t\temailFrom: this.emailFrom,\n\t\t\temailFromName: this.platformName,\n\t\t\temailTo,\n\t\t\tsubject,\n\t\t\ttextBody,\n\t\t\thtmlBody\n\t\t})\n\t}\n\n\tprivate async sendEmail(args: ISendEmail): Promise<boolean> {\n\t\tconst { emailFrom, emailFromName, emailTo, subject, textBody, htmlBody } = args\n\t\tconst basicMessage = new BasicMessage()\n\t\tbasicMessage.setFromAddress(emailFrom, emailFromName)\n\t\tbasicMessage.setSubject(subject)\n\t\tbasicMessage.setTextBody(textBody)\n\t\tbasicMessage.setHtmlBody(this.emailHtmlHeader1 + subject + this.emailHtmlHeader2 + htmlBody + this.emailHtmlFooter)\n\t\tbasicMessage.setTo(emailTo)\n\n\t\treturn this.client.send(basicMessage).then(\n\t\t\t() => {\n\t\t\t\t//Handle successful API call\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t(e: Error) => {\n\t\t\t\tSentry.captureException(e, {\n\t\t\t\t\textra: { detail: 'Error in sending the email' }\n\t\t\t\t})\n\t\t\t\treturn false\n\t\t\t}\n\t\t)\n\t}\n\n\t/**\n\t * fallback header\n\t * @private\n\t */\n\tprivate htmlHeader1() {\n\t\treturn (\n\t\t\t'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">' +\n\t\t\t'<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">' +\n\t\t\t' <head>' +\n\t\t\t' <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />' +\n\t\t\t' <title>'\n\t\t)\n\t}\n\n\t/**\n\t * fallback header\n\t * @private\n\t */\n\tprivate htmlHeader2() {\n\t\treturn (\n\t\t\t'</title>' +\n\t\t\t' <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>' +\n\t\t\t'</head>' +\n\t\t\t'</html>' +\n\t\t\t'<body style=\"margin: 0; padding: 0;\">' +\n\t\t\t' <table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">' +\n\t\t\t' <tr>' +\n\t\t\t' <td bgcolor=\"#ffffff\" style=\"padding: 40px 30px 40px 30px;\"><p style=\"color: #000000; font-family: Verdana, sans-serif; font-size: 12pt;\">'\n\t\t)\n\t}\n\n\tprivate fixName(name: string) {\n\t\treturn name !== '' ? ` ${name}` : ''\n\t}\n}\n"]}
|
|
@@ -7,14 +7,14 @@ export async function checkForNSFW(imageUrl: string) {
|
|
|
7
7
|
const result = await Sightengine.check(['nudity', 'wad']).set_url(imageUrl)
|
|
8
8
|
|
|
9
9
|
if (result.nudity.safe < 0.9) {
|
|
10
|
-
|
|
10
|
+
// NSFW content detected in the image
|
|
11
11
|
return false
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// No NSFW content detected in the image
|
|
15
15
|
return true
|
|
16
16
|
} catch (err) {
|
|
17
|
-
|
|
17
|
+
// Error during content moderation: err
|
|
18
18
|
return false
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkForNSFW.mjs","sourceRoot":"","sources":["../../src/files/checkForNSFW.mts"],"names":[],"mappings":"AAAA,kFAAkF;;AAElF;;;;;;;;;;;;;;;;;;EAkBE","sourcesContent":["// const Sightengine = require('sightengine')('your-api-user', 'your-api-secret');\n\n/*\n// https://sightengine.com/ but there are other services too\nexport async function checkForNSFW(imageUrl: string) {\n\ttry {\n const result = await Sightengine.check(['nudity', 'wad']).set_url(imageUrl)\n\n if (result.nudity.safe < 0.9) {\n
|
|
1
|
+
{"version":3,"file":"checkForNSFW.mjs","sourceRoot":"","sources":["../../src/files/checkForNSFW.mts"],"names":[],"mappings":"AAAA,kFAAkF;;AAElF;;;;;;;;;;;;;;;;;;EAkBE","sourcesContent":["// const Sightengine = require('sightengine')('your-api-user', 'your-api-secret');\n\n/*\n// https://sightengine.com/ but there are other services too\nexport async function checkForNSFW(imageUrl: string) {\n\ttry {\n const result = await Sightengine.check(['nudity', 'wad']).set_url(imageUrl)\n\n if (result.nudity.safe < 0.9) {\n // NSFW content detected in the image\n return false\n }\n\n // No NSFW content detected in the image\n return true\n } catch (err) {\n // Error during content moderation: err\n return false\n }\n}\n*/\n"]}
|
package/dist/files/scanVirus.mjs
CHANGED
|
@@ -45,9 +45,6 @@ export async function scanVirus(filePath) {
|
|
|
45
45
|
Sentry.captureMessage(`Infected file detected: ${filePath}`);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
else {
|
|
49
|
-
//console.log(`The file ${filePath} is clean.`)
|
|
50
|
-
}
|
|
51
48
|
return { isInfected, viruses, alerted, scanned: true };
|
|
52
49
|
}
|
|
53
50
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanVirus.mjs","sourceRoot":"","sources":["../../src/files/scanVirus.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,IAAI,gBAAgB,GAAoB,IAAI,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAmC;IACrE,MAAM,cAAc,GAAqB;QACxC,cAAc,EAAE,IAAI;QACpB,kBAAkB,EAAE,KAAK;QACzB,SAAS,EAAE;YACV,MAAM,EAAE,2BAA2B;YACnC,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAI;YACf,aAAa,EAAE,KAAK;SACpB;QACD,SAAS,EAAE,KAAK;KAChB,CAAA;IACD,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;IAElC,IAAI,CAAC;QACJ,MAAM,aAAa,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAA;QACvD,gBAAgB,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAC3D,OAAO,CAAC,IAAI,CAAC,2DAA2D,CA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C9B,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;gBACrE,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gBACzB,MAAM,CAAC,cAAc,CAAC,2BAA2B,QAAQ,EAAE,CAAC,CAAA;YAC7D,CAAC,CAAC,CAAA;QACH,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACvD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE;YAC1B,KAAK,EAAE,EAAE,MAAM,EAAE,iCAAiC,QAAQ,EAAE,EAAE;SAC9D,CAAC,CAAA;QACF,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IAC1E,CAAC;AACF,CAAC","sourcesContent":["import * as Sentry from '@sentry/node'\nimport NodeClam from 'clamscan'\n\nlet clamScanInstance: NodeClam | null = null\n\n/**********\n * Call inside koa initialization\n */\nexport async function initClamScan(options?: Partial<NodeClam.Options>) {\n\tconst defaultOptions: NodeClam.Options = {\n\t\tremoveInfected: true,\n\t\tquarantineInfected: false,\n\t\tclamdscan: {\n\t\t\tsocket: '/var/run/clamav/clamd.ctl',\n\t\t\ttimeout: 60000,\n\t\t\tmultiscan: true,\n\t\t\tlocalFallback: false\n\t\t},\n\t\tdebugMode: false\n\t}\n\tconsole.info('[ClamScan] init...')\n\n\ttry {\n\t\tconst mergedOptions = { ...defaultOptions, ...options }\n\t\tclamScanInstance = await new NodeClam().init(mergedOptions)\n\t\tconsole.info('[ClamScan] OK: ClamScan has been initialized successfully')\n\t\treturn clamScanInstance\n\t} catch (e) {\n\t\tconsole.error('[ClamScan] Error')\n\t\tSentry.captureException(e)\n\t\tthrow e\n\t}\n}\n\n/**\n * Result of a virus scan.\n *\n * Returned rather than kept internal because the Sentry alert used to be the ONLY\n * effect of detecting an infected file: inverting `if (isInfected)` had no observable\n * consequence, so no test could pin it (@sentry/node is a sealed ES module namespace\n * and is never initialised in the suite, making captureMessage a silent no-op there).\n * `alerted` is set inside the branch precisely so the branch itself is observable.\n *\n * scanVirus still never throws on detection — blocking remains the caller's decision —\n * but the caller now has something to decide with. Note `scanned: false` means the scan\n * did not complete: treat it as unknown, not as clean.\n */\nexport interface IScanVirusResult {\n\t/** true when ClamAV reported the file as infected */\n\tisInfected: boolean\n\t/** virus names reported by ClamAV; empty when clean or when the scan failed */\n\tviruses: string[]\n\t/** true when the infected-file alert was raised */\n\talerted: boolean\n\t/** false when the scan itself errored — the result is unknown, NOT clean */\n\tscanned: boolean\n}\n\nexport async function scanVirus(filePath: string): Promise<IScanVirusResult> {\n\tif (!clamScanInstance) {\n\t\tthrow new Error('ClamScan has not been initialized. Call initClamScan first.')\n\t}\n\n\ttry {\n\t\tconst { isInfected, viruses } = await clamScanInstance.scanFile(filePath)\n\n\t\tlet alerted = false\n\t\tif (isInfected) {\n\t\t\talerted = true\n\t\t\tSentry.withScope((scope) => {\n\t\t\t\tscope.setTag('file', filePath)\n\t\t\t\tscope.setContext('viruses', { list: viruses, count: viruses.length })\n\t\t\t\tscope.setLevel('warning')\n\t\t\t\tSentry.captureMessage(`Infected file detected: ${filePath}`)\n\t\t\t})\n\t\t}\n\n\t\treturn { isInfected, viruses, alerted, scanned: true }\n\t} catch (e) {\n\t\tSentry.captureException(e, {\n\t\t\textra: { detail: `Error while scanning the file ${filePath}` }\n\t\t})\n\t\treturn { isInfected: false, viruses: [], alerted: false, scanned: false }\n\t}\n}\n"]}
|
|
@@ -64,7 +64,6 @@ export async function storeUploadAsTemp(upload, maxFileSize = MAX_FILE_SIZE) {
|
|
|
64
64
|
// Pipe the upload into the write stream.
|
|
65
65
|
stream.pipe(writeStream);
|
|
66
66
|
});
|
|
67
|
-
//console.debug('storedFileName', storedFileName)
|
|
68
67
|
return {
|
|
69
68
|
originalFilename: filename,
|
|
70
69
|
fileName: storedFileName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storeUploadAsTemp.mjs","sourceRoot":"","sources":["../../src/files/storeUploadAsTemp.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAGnC,OAAO,EAAc,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAEvE,2CAA2C;AAC3C,kCAAkC;AAClC,MAAM,aAAa,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,iBAAiB;AAEvD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAA4B,EAAE,cAAsB,aAAa;IACxG,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAA;IACnD,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAA;IACjC,MAAM,cAAc,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;IACtE,MAAM,aAAa,GAAG,GAAG,yBAAyB,IAAI,cAAc,EAAE,CAAA;IACtE,IAAI,QAAQ,GAAG,CAAC,CAAA,CAAC,8BAA8B;IAC/C,IAAI,YAAY,GAAG,KAAK,CAAA,CAAC,4DAA4D;IACrF,IAAI,YAAY,GAAiB,IAAI,CAAA,CAAC,2DAA2D;IAEjG,oCAAoC;IACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,uDAAuD;QACvD,MAAM,WAAW,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAA;QAEpD,oCAAoC;QACpC,6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;QAEF,sLAAsL;QACtL,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QAEhE,yCAAyC;QACzC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO;QACN,gBAAgB,EAAE,QAAQ;QAC1B,QAAQ,EAAE,cAAc;QACxB,QAAQ,EAAE,aAAa;KACvB,CAAA;AACF,CAAC","sourcesContent":["import { createWriteStream, unlink } from 'node:fs'\n\nimport path from 'path'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { IFileUpload } from '../koa/IFileUpload.mjs'\nimport { IStoreFile, UPLOAD_TEMP_DIRECTORY_URL } from './fileConst.mjs'\n\n// Simulating __dirname using process.cwd()\n// const __dirname = process.cwd()\nconst MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB size limit\n\nexport async function storeUploadAsTemp(upload: Promise<IFileUpload>, maxFileSize: number = MAX_FILE_SIZE): Promise<IStoreFile> {\n\tconst { createReadStream, filename } = await upload\n\tconst stream = createReadStream()\n\tconst storedFileName = uuidv4() + path.extname(filename).toLowerCase()\n\tconst storedFileUrl = `${UPLOAD_TEMP_DIRECTORY_URL}/${storedFileName}`\n\tlet fileSize = 0 // Variable to track file size\n\tlet sizeExceeded = false // Set once the limit is passed; read by the 'close' handler\n\tlet writeFailure: Error | null = null // Set on a write/stream error; read by the 'close' handler\n\n\t// Store the file in the filesystem.\n\tawait new Promise((resolve, reject) => {\n\t\t// Create a stream to which the upload will be written.\n\t\tconst writeStream = createWriteStream(storedFileUrl)\n\n\t\t// Check file size during streaming.\n\t\t// Only flags and stops the stream — the rejection is issued from the 'close'\n\t\t// handler below. Rejecting from inside unlink's callback here would lose the\n\t\t// race: writeStream.destroy() emits 'close' synchronously ahead of the async\n\t\t// unlink, so 'close' resolved the promise first and the later reject() was a\n\t\t// no-op on an already-settled promise. An oversize upload therefore reported\n\t\t// SUCCESS while returning a path that had just been deleted.\n\t\tstream.on('data', (chunk: Buffer) => {\n\t\t\tfileSize += chunk.length\n\t\t\tif (!sizeExceeded && fileSize > maxFileSize) {\n\t\t\t\tsizeExceeded = true\n\t\t\t\twriteStream.destroy() // Stop the stream\n\t\t\t}\n\t\t})\n\n\t\t// Best-effort cleanup, then reject. Cleanup is fire-and-forget by design: the\n\t\t// upload has already failed, and an unlink error must not mask the real cause.\n\t\tconst removeThenReject = (reason: Error) => unlink(storedFileUrl, () => reject(reason))\n\n\t\t// 'close' is the single settle point. Every failure path below only RECORDS what\n\t\t// went wrong and stops the stream; nothing settles the Promise itself. Rejecting\n\t\t// from inside an unlink callback instead would lose the race — destroy() emits\n\t\t// 'close' ahead of the async unlink, so 'close' settled the Promise first and the\n\t\t// later reject() was a no-op. That is why an oversize upload used to report\n\t\t// SUCCESS with a filePath that had just been deleted, and why a write error did\n\t\t// the same.\n\t\twriteStream.on('close', () => {\n\t\t\tif (sizeExceeded) {\n\t\t\t\tremoveThenReject(new Error(`File size exceeds the limit of ${maxFileSize} bytes`))\n\t\t\t} else if (writeFailure !== null) {\n\t\t\t\tremoveThenReject(writeFailure)\n\t\t\t} else {\n\t\t\t\tresolve(undefined)\n\t\t\t}\n\t\t})\n\n\t\t// Record the write error; 'close' follows and does the rejecting. The previous\n\t\t// version rejected here with 'File size exceeds the limit.' regardless of the\n\t\t// actual cause, which was misleading for every non-size failure — the real error\n\t\t// is propagated now.\n\t\twriteStream.on('error', (e: Error) => {\n\t\t\twriteFailure = e\n\t\t})\n\n\t\t// In Node.js <= v13, errors are not automatically propagated between piped streams. If there is an error receiving the upload, destroy the write stream with the corresponding error.\n\t\tstream.on('error', (error: Error) => writeStream.destroy(error))\n\n\t\t// Pipe the upload into the write stream.\n\t\tstream.pipe(writeStream)\n\t})\n\n\treturn {\n\t\toriginalFilename: filename,\n\t\tfileName: storedFileName,\n\t\tfilePath: storedFileUrl\n\t}\n}\n"]}
|
|
@@ -13,7 +13,6 @@ export async function uploadTemp(img) {
|
|
|
13
13
|
try {
|
|
14
14
|
// Step 1 - Readme.md
|
|
15
15
|
const { fileName, filePath } = await storeUploadAsTemp(img);
|
|
16
|
-
//console.debug(fileName, filePath)
|
|
17
16
|
await validateJpgPngExtension(fileName, filePath);
|
|
18
17
|
await validateJpgPngMimeType(filePath);
|
|
19
18
|
// step 2
|
|
@@ -31,7 +30,6 @@ export async function uploadTemp(img) {
|
|
|
31
30
|
}
|
|
32
31
|
catch (e) {
|
|
33
32
|
// error for file handling
|
|
34
|
-
console.error('Error storing image:', e);
|
|
35
33
|
throw new Error('Error storing image');
|
|
36
34
|
}
|
|
37
35
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadTempImage.mjs","sourceRoot":"","sources":["../../src/files/uploadTempImage.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAyB;IACzD,IAAI,cAAc,GAAG,EAAE,CAAA;IAEvB,IAAI,CAAC;QACJ,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC3D,
|
|
1
|
+
{"version":3,"file":"uploadTempImage.mjs","sourceRoot":"","sources":["../../src/files/uploadTempImage.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAErE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAyB;IACzD,IAAI,cAAc,GAAG,EAAE,CAAA;IAEvB,IAAI,CAAC;QACJ,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC3D,MAAM,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QACjD,MAAM,sBAAsB,CAAC,QAAQ,CAAC,CAAA;QACtC,SAAS;QACT,MAAM,SAAS,CAAC,GAAG,QAAQ,EAAE,CAAC,CAAA;QAC9B,SAAS;QAET,cAAc,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;QAC/C,+BAA+B;QAC/B,+BAA+B;QAC/B,2BAA2B;QAC3B,cAAc;QACd,cAAc;QACd,cAAc;QACd,8CAA8C;QAC9C,iEAAiE;IAClE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,0BAA0B;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACvC,CAAC;IAED,OAAO;QACN,GAAG,EAAE,MAAM;QACX,QAAQ,EAAE,cAAc;KACxB,CAAA;AACF,CAAC","sourcesContent":["import { IFileUpload } from '../koa/IFileUpload.mjs'\nimport { IUploadTemp } from './IUploadTemp.mjs'\nimport { reEncodeToWebp } from './reEncodeToWebp.mjs'\nimport { scanVirus } from './scanVirus.mjs'\nimport { storeUploadAsTemp } from './storeUploadAsTemp.mjs'\nimport { validateJpgPngExtension } from './validateJpgPngExtension.mjs'\nimport { validateJpgPngMimeType } from './validateMimeTypeImages.mjs'\n\n/**\n * Validate file extension, Mime Type, scan with ClamAV, re encode to webp, rename final file\n * @todo log uploaded file\n * @param img\n */\nexport async function uploadTemp(img: Promise<IFileUpload>): Promise<IUploadTemp> {\n\tlet storedTempFile = ''\n\n\ttry {\n\t\t// Step 1 - Readme.md\n\t\tconst { fileName, filePath } = await storeUploadAsTemp(img)\n\t\tawait validateJpgPngExtension(fileName, filePath)\n\t\tawait validateJpgPngMimeType(filePath)\n\t\t// step 2\n\t\tawait scanVirus(`${filePath}`)\n\t\t// step 3\n\n\t\tstoredTempFile = await reEncodeToWebp(filePath)\n\t\t// await checkForNSFW(filePath)\n\t\t// step 4 - safe file name (ok)\n\t\t// step 5 - rate limit (ok)\n\t\t// step 6 - ok\n\t\t// step 7 - ok\n\t\t// step8 - log\n\t\t// user's IP address, filename, and timestamp,\n\t\t// @todo await logUpload('team', uId, originalFilename, fileName)\n\t} catch (e) {\n\t\t// error for file handling\n\t\tthrow new Error('Error storing image')\n\t}\n\n\treturn {\n\t\text: 'webp',\n\t\ttempFile: storedTempFile\n\t}\n}\n"]}
|
|
@@ -12,7 +12,6 @@ export async function uploadTempPdf(pdf) {
|
|
|
12
12
|
try {
|
|
13
13
|
// Step 1 - Readme.md
|
|
14
14
|
const { fileName, filePath } = await storeUploadAsTemp(pdf);
|
|
15
|
-
//console.log(fileName, filePath)
|
|
16
15
|
await validatePdfExtension(fileName, filePath);
|
|
17
16
|
await validateMimeTypePdf(filePath);
|
|
18
17
|
// step 2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadTempPdf.mjs","sourceRoot":"","sources":["../../src/files/uploadTempPdf.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE;;;;GAIG;AACH,MAAM,CAA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AAC,CAAA;IACrC,CAAC;IAED,OAAO;QACN,GAAG,EAAE,KAAK;QACV,QAAQ,EAAE,cAAc;KACxB,CAAA;AACF,CAAC","sourcesContent":["import { IFileUpload } from '../koa/IFileUpload.mjs'\nimport { IUploadTemp } from './IUploadTemp.mjs'\nimport { scanVirus } from './scanVirus.mjs'\nimport { storeUploadAsTemp } from './storeUploadAsTemp.mjs'\nimport { validateMimeTypePdf } from './validateMimeTypePdf.mjs'\nimport { validatePdfExtension } from './validatePdfExtension.mjs'\n\n/**\n * Validate file extension, Mime Type, scan with ClamAV, re encode to pdf, rename final file\n * @todo log uploaded file, reencode pdf\n * @param pdf\n */\nexport async function uploadTempPdf(pdf: Promise<IFileUpload>): Promise<IUploadTemp> {\n\tlet storedTempFile = ''\n\n\ttry {\n\t\t// Step 1 - Readme.md\n\t\tconst { fileName, filePath } = await storeUploadAsTemp(pdf)\n\t\tawait validatePdfExtension(fileName, filePath)\n\t\tawait validateMimeTypePdf(filePath)\n\t\t// step 2\n\t\tawait scanVirus(`${filePath}`)\n\t\t// step 3\n\n\t\t// @todo reencode with dangerzone https://github.com/freedomofpress/dangerzone/tree/main\n\t\tstoredTempFile = filePath\n\t\t// await checkForNSFW(filePath)\n\t\t// step 4 - safe file name (ok)\n\t\t// step 5 - rate limit (ok)\n\t\t// step 6 - ok\n\t\t// step 7 - ok\n\t\t// step8 - log\n\t\t// user's IP address, filename, and timestamp,\n\t\t// @todo await logUpload('team', uId, originalFilename, fileName)\n\t} catch (e) {\n\t\t// error for file handling\n\t\tconsole.error('Error storing pdf:', e)\n\t\tthrow new Error('Error storing pdf')\n\t}\n\n\treturn {\n\t\text: 'pdf',\n\t\ttempFile: storedTempFile\n\t}\n}\n"]}
|
|
@@ -13,7 +13,6 @@ import { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql';
|
|
|
13
13
|
*/
|
|
14
14
|
async function handleHashMismatch(ctx, uId, requestTimes) {
|
|
15
15
|
// hash failed
|
|
16
|
-
console.debug('HASH FAILED');
|
|
17
16
|
if (typeof requestTimes === 'undefined') {
|
|
18
17
|
throw throwInternalError();
|
|
19
18
|
}
|
|
@@ -33,14 +32,12 @@ async function handleValidHash(ctx, uId, dateLastReq) {
|
|
|
33
32
|
// @fixme sentry 'dateLastReq is undefined'
|
|
34
33
|
throw throwInternalError();
|
|
35
34
|
}
|
|
36
|
-
console.debug('activation link hash is valid');
|
|
37
35
|
// if dateLastReq is older than 3 days, warn and stop
|
|
38
36
|
const StrLibObj = new StringLib();
|
|
39
37
|
const now = new Date();
|
|
40
38
|
const day3ago = new Date(now.setDate(now.getDate() - 3));
|
|
41
39
|
if (StrLibObj.isoToTimestamp(day3ago) > StrLibObj.isoToTimestamp(dateLastReq)) {
|
|
42
40
|
// dateLastReq too old then 3 days
|
|
43
|
-
console.debug('but link is too old');
|
|
44
41
|
// noinspection ES6MissingAwait
|
|
45
42
|
socketLabs.hashReqTooOld(uEmail);
|
|
46
43
|
return false;
|
|
@@ -94,12 +91,9 @@ export const createEmailChangeHashVerifyMutation = (deps) => ({
|
|
|
94
91
|
.lean();
|
|
95
92
|
// if email not found, return (do not tell the user the real problem !)
|
|
96
93
|
if (user === null) {
|
|
97
|
-
console.debug('email NOT found ', uEmail);
|
|
98
94
|
return false; // @fixme throw
|
|
99
95
|
}
|
|
100
|
-
console.debug('email found');
|
|
101
96
|
const ctx = { deps, user, uEmail, socketLabs: new SocketLabsLib() };
|
|
102
|
-
console.debug('comparing hash ');
|
|
103
97
|
const uId = readPath(user, '_id');
|
|
104
98
|
const dateLastReq = readPath(user, paths.dateLastReq);
|
|
105
99
|
if (args.hash === readPath(user, paths.hash)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emailChangeHashVerify.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/emailChangeHashVerify.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,0BAA0B,EAAmC,4CAAm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,CAAC,WAAW,CAAqB,CAAA;QAEzE,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,OAAO,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,CAAA;QAC9C,CAAC;QACD,OAAO,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAuB,CAAC,CAAA;IAC9F,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,qBAAqB,GAAmC,mCAAmC,CAAC;IACxG,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,0BAA0B;IACjC,eAAe;IACf,WAAW;CACX,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport confirmNewEmail, { TConfirmNewEmail } from '@private/lib/access/db/confirmNewEmail.mjs'\nimport { incReqTimes, TIncReqTimes } from '@private/lib/access/db/incReqTimes.mjs'\nimport { buildProjection, readPath } from '@private/lib/access/pathTools.mjs'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql'\nimport { Types } from 'mongoose'\n\n/** Arguments accepted by the `emailChangeHashVerify` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IEmailChangeHashVerifyArgs {\n\temail: string\n\thash: string\n}\n\n/** Model, field map and writers the resolver needs, all bound together by the caller. */\nexport interface IEmailChangeHashVerifyDeps {\n\tmodel: TAccessModel\n\tpaths: IVerifyEmailPaths\n\tconfirmNewEmail: TConfirmNewEmail\n\tincReqTimes: TIncReqTimes\n}\n\n/**\n * Everything the extracted branch handlers need, bundled so each stays within the max-params budget:\n * the bound deps, the lean document just read, the lowercased email and one shared SocketLabs client.\n */\ninterface IVerifyContext {\n\tdeps: IEmailChangeHashVerifyDeps\n\tuser: unknown\n\tuEmail: string\n\tsocketLabs: SocketLabsLib\n}\n\n/**\n * The submitted hash does not match the stored one: count the attempt and warn the account owner.\n * Extracted from resolve() only to keep it inside the max-lines-per-function budget — behaviour unchanged.\n */\nasync function handleHashMismatch(ctx: IVerifyContext, uId: Types.ObjectId, requestTimes: number | undefined) {\n\t// hash failed\n\tconsole.debug('HASH FAILED')\n\n\tif (typeof requestTimes === 'undefined') {\n\t\tthrow throwInternalError()\n\t}\n\n\tawait ctx.deps.incReqTimes(uId)\n\t// noinspection ES6MissingAwait\n\tctx.socketLabs.wrongHash(ctx.uEmail, requestTimes)\n\treturn false\n}\n\n/**\n * The submitted hash matches: enforce the freshness/account guards and, if the target email is still\n * free, accept it. Extracted from resolve() only to keep it inside the max-lines-per-function budget.\n */\nasync function handleValidHash(ctx: IVerifyContext, uId: Types.ObjectId, dateLastReq: Date | undefined) {\n\tconst { deps, user, uEmail, socketLabs } = ctx\n\tconst { paths } = deps\n\n\tif (typeof dateLastReq === 'undefined') {\n\t\t// @fixme sentry 'dateLastReq is undefined'\n\t\tthrow throwInternalError()\n\t}\n\n\tconsole.debug('activation link hash is valid')\n\n\t// if dateLastReq is older than 3 days, warn and stop\n\tconst StrLibObj = new StringLib()\n\tconst now = new Date()\n\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\n\tif (StrLibObj.isoToTimestamp(day3ago) > StrLibObj.isoToTimestamp(dateLastReq)) {\n\t\t// dateLastReq too old then 3 days\n\t\tconsole.debug('but link is too old')\n\n\t\t// noinspection ES6MissingAwait\n\t\tsocketLabs.hashReqTooOld(uEmail)\n\t\treturn false\n\t}\n\n\t// account is deleted -> maybe by admin for any reason\n\t// Read raw: this is a .lean() query, so Mongoose casting never runs and these are real booleans\n\t// only on data that scripts/migrate-account-disabled-to-boolean.mjs has been through. A legacy\n\t// string 'false' is truthy and blocks here — migrate, don't coerce.\n\tif (readPath(user, paths.deleted)) {\n\t\treturn false\n\t}\n\t// if account is disabled, for any reason\n\tif (readPath(user, paths.disabled)) {\n\t\t// noinspection ES6MissingAwait\n\t\tsocketLabs.accountDisabled(uEmail)\n\t\treturn false\n\t}\n\n\t// valid request. meanwhile, has some user registered with this email address ??\n\tconst qty = await deps.model.countDocuments({ [paths.email]: uEmail })\n\tif (qty > 0) {\n\t\treturn false\n\t}\n\n\t// accept new email\n\tawait deps.confirmNewEmail(uId, uEmail)\n\treturn true\n}\n\n/**\n * Change email - Verify match between email and hash\n *\n * The collection and every field path come from `deps`, so the same resolver serves any account model.\n * The projection is built from the same map the reads use, which is what keeps a read field from going\n * missing — the exact bug that made every wrong hash answer 500 through 5.1.0.\n */\nexport const createEmailChangeHashVerifyMutation = (deps: IEmailChangeHashVerifyDeps) => ({\n\tdescription: 'Change email - Verify match between email and hash',\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\thash: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IEmailChangeHashVerifyArgs) {\n\t\tconst { paths } = deps\n\t\tconst uEmail = args.email.toLowerCase()\n\n\t\t// search if the email exists\n\t\t// Every field this resolver reads must be listed. account.email.requestTimes was missing, and\n\t\t// because this is a .lean() read the absent key made handleHashMismatch throw 500 on *every*\n\t\t// wrong hash: the strike counter never advanced and the owner never got the wrongHash warning.\n\t\tconst user = await deps.model\n\t\t\t.findOne({ [paths.newEmailTmp]: uEmail })\n\t\t\t.select(buildProjection([paths.hash, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))\n\t\t\t.lean()\n\n\t\t// if email not found, return (do not tell the user the real problem !)\n\t\tif (user === null) {\n\t\t\tconsole.debug('email NOT found ', uEmail)\n\n\t\t\treturn false // @fixme throw\n\t\t}\n\t\tconsole.debug('email found')\n\n\t\tconst ctx: IVerifyContext = { deps, user, uEmail, socketLabs: new SocketLabsLib() }\n\n\t\tconsole.debug('comparing hash ')\n\t\tconst uId = readPath(user, '_id') as Types.ObjectId\n\t\tconst dateLastReq = readPath(user, paths.dateLastReq) as Date | undefined\n\n\t\tif (args.hash === readPath(user, paths.hash)) {\n\t\t\treturn handleValidHash(ctx, uId, dateLastReq)\n\t\t}\n\t\treturn handleHashMismatch(ctx, uId, readPath(user, paths.requestTimes) as number | undefined)\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TEmailChangeHashVerifyMutation = ReturnType<typeof createEmailChangeHashVerifyMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const emailChangeHashVerify: TEmailChangeHashVerifyMutation = createEmailChangeHashVerifyMutation({\n\tmodel: UserBase,\n\tpaths: DEFAULT_VERIFY_EMAIL_PATHS,\n\tconfirmNewEmail,\n\tincReqTimes\n})\n"]}
|
|
1
|
+
{"version":3,"file":"emailChangeHashVerify.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/emailChangeHashVerify.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,yCAAgC;AACxD,OAAO,EAAE,0BAA0B,EAAmC,4CAAmC;AACzG,OAAO,EAAE,SAAS,EAAE,mCAA0B;AAC9C,OAAO,EAAE,QAAQ,EAAE,0CAAoC;AACvD,OAAO,eAAqC,2DAAkD;AAC9F,OAAO,EAAE,WAAW,EAAgB,uDAA8C;AAClF,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,kDAAyC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,2CAAqC;AAClE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AA4BvE;;;GAGG;AACH,KAAK,UAAU,kBAAkB,CAAC,GAAmB,EAAE,GAAmB,EAAE,YAAgC;IAC3G,cAAc;IAEd,IAAI,OA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,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;aAC3G,IAAI,EAAE,CAAA;QAER,uEAAuE;QACvE,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,KAAK,CAAA,CAAC,eAAe;QAC7B,CAAC;QAED,MAAM,GAAG,GAAmB,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,aAAa,EAAE,EAAE,CAAA;QAEnF,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAmB,CAAA;QACnD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAqB,CAAA;QAEzE,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,OAAO,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,CAAA;QAC9C,CAAC;QACD,OAAO,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,CAAuB,CAAC,CAAA;IAC9F,CAAC;CACD,CAAC,CAAA;AAKF,uFAAuF;AACvF,MAAM,CAAC,MAAM,qBAAqB,GAAmC,mCAAmC,CAAC;IACxG,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,0BAA0B;IACjC,eAAe;IACf,WAAW;CACX,CAAC,CAAA","sourcesContent":["import { SocketLabsLib } from '@email/SocketLabsLib.mjs'\nimport { DEFAULT_VERIFY_EMAIL_PATHS, IVerifyEmailPaths, TAccessModel } from '@lib/access/accessPaths.mjs'\nimport { StringLib } from '@lib/StringLib.mjs'\nimport { UserBase } from '@models/MongoDB/UserBase.mjs'\nimport confirmNewEmail, { TConfirmNewEmail } from '@private/lib/access/db/confirmNewEmail.mjs'\nimport { incReqTimes, TIncReqTimes } from '@private/lib/access/db/incReqTimes.mjs'\nimport { buildProjection, readPath } from '@private/lib/access/pathTools.mjs'\nimport { throwInternalError } from '@throw/throwInternalError.mjs'\nimport { GraphQLBoolean, GraphQLNonNull, GraphQLString } from 'graphql'\nimport { Types } from 'mongoose'\n\n/** Arguments accepted by the `emailChangeHashVerify` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface IEmailChangeHashVerifyArgs {\n\temail: string\n\thash: string\n}\n\n/** Model, field map and writers the resolver needs, all bound together by the caller. */\nexport interface IEmailChangeHashVerifyDeps {\n\tmodel: TAccessModel\n\tpaths: IVerifyEmailPaths\n\tconfirmNewEmail: TConfirmNewEmail\n\tincReqTimes: TIncReqTimes\n}\n\n/**\n * Everything the extracted branch handlers need, bundled so each stays within the max-params budget:\n * the bound deps, the lean document just read, the lowercased email and one shared SocketLabs client.\n */\ninterface IVerifyContext {\n\tdeps: IEmailChangeHashVerifyDeps\n\tuser: unknown\n\tuEmail: string\n\tsocketLabs: SocketLabsLib\n}\n\n/**\n * The submitted hash does not match the stored one: count the attempt and warn the account owner.\n * Extracted from resolve() only to keep it inside the max-lines-per-function budget — behaviour unchanged.\n */\nasync function handleHashMismatch(ctx: IVerifyContext, uId: Types.ObjectId, requestTimes: number | undefined) {\n\t// hash failed\n\n\tif (typeof requestTimes === 'undefined') {\n\t\tthrow throwInternalError()\n\t}\n\n\tawait ctx.deps.incReqTimes(uId)\n\t// noinspection ES6MissingAwait\n\tctx.socketLabs.wrongHash(ctx.uEmail, requestTimes)\n\treturn false\n}\n\n/**\n * The submitted hash matches: enforce the freshness/account guards and, if the target email is still\n * free, accept it. Extracted from resolve() only to keep it inside the max-lines-per-function budget.\n */\nasync function handleValidHash(ctx: IVerifyContext, uId: Types.ObjectId, dateLastReq: Date | undefined) {\n\tconst { deps, user, uEmail, socketLabs } = ctx\n\tconst { paths } = deps\n\n\tif (typeof dateLastReq === 'undefined') {\n\t\t// @fixme sentry 'dateLastReq is undefined'\n\t\tthrow throwInternalError()\n\t}\n\n\t// if dateLastReq is older than 3 days, warn and stop\n\tconst StrLibObj = new StringLib()\n\tconst now = new Date()\n\tconst day3ago = new Date(now.setDate(now.getDate() - 3))\n\n\tif (StrLibObj.isoToTimestamp(day3ago) > StrLibObj.isoToTimestamp(dateLastReq)) {\n\t\t// dateLastReq too old then 3 days\n\n\t\t// noinspection ES6MissingAwait\n\t\tsocketLabs.hashReqTooOld(uEmail)\n\t\treturn false\n\t}\n\n\t// account is deleted -> maybe by admin for any reason\n\t// Read raw: this is a .lean() query, so Mongoose casting never runs and these are real booleans\n\t// only on data that scripts/migrate-account-disabled-to-boolean.mjs has been through. A legacy\n\t// string 'false' is truthy and blocks here — migrate, don't coerce.\n\tif (readPath(user, paths.deleted)) {\n\t\treturn false\n\t}\n\t// if account is disabled, for any reason\n\tif (readPath(user, paths.disabled)) {\n\t\t// noinspection ES6MissingAwait\n\t\tsocketLabs.accountDisabled(uEmail)\n\t\treturn false\n\t}\n\n\t// valid request. meanwhile, has some user registered with this email address ??\n\tconst qty = await deps.model.countDocuments({ [paths.email]: uEmail })\n\tif (qty > 0) {\n\t\treturn false\n\t}\n\n\t// accept new email\n\tawait deps.confirmNewEmail(uId, uEmail)\n\treturn true\n}\n\n/**\n * Change email - Verify match between email and hash\n *\n * The collection and every field path come from `deps`, so the same resolver serves any account model.\n * The projection is built from the same map the reads use, which is what keeps a read field from going\n * missing — the exact bug that made every wrong hash answer 500 through 5.1.0.\n */\nexport const createEmailChangeHashVerifyMutation = (deps: IEmailChangeHashVerifyDeps) => ({\n\tdescription: 'Change email - Verify match between email and hash',\n\ttype: new GraphQLNonNull(GraphQLBoolean),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\thash: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: IEmailChangeHashVerifyArgs) {\n\t\tconst { paths } = deps\n\t\tconst uEmail = args.email.toLowerCase()\n\n\t\t// search if the email exists\n\t\t// Every field this resolver reads must be listed. account.email.requestTimes was missing, and\n\t\t// because this is a .lean() read the absent key made handleHashMismatch throw 500 on *every*\n\t\t// wrong hash: the strike counter never advanced and the owner never got the wrongHash warning.\n\t\tconst user = await deps.model\n\t\t\t.findOne({ [paths.newEmailTmp]: uEmail })\n\t\t\t.select(buildProjection([paths.hash, paths.dateLastReq, paths.requestTimes, paths.deleted, paths.disabled]))\n\t\t\t.lean()\n\n\t\t// if email not found, return (do not tell the user the real problem !)\n\t\tif (user === null) {\n\t\t\treturn false // @fixme throw\n\t\t}\n\n\t\tconst ctx: IVerifyContext = { deps, user, uEmail, socketLabs: new SocketLabsLib() }\n\n\t\tconst uId = readPath(user, '_id') as Types.ObjectId\n\t\tconst dateLastReq = readPath(user, paths.dateLastReq) as Date | undefined\n\n\t\tif (args.hash === readPath(user, paths.hash)) {\n\t\t\treturn handleValidHash(ctx, uId, dateLastReq)\n\t\t}\n\t\treturn handleHashMismatch(ctx, uId, readPath(user, paths.requestTimes) as number | undefined)\n\t}\n})\n\n/** Shape of the bound mutation, for the modules that take it as a dependency. */\nexport type TEmailChangeHashVerifyMutation = ReturnType<typeof createEmailChangeHashVerifyMutation>\n\n/** `UserBase`-bound default — the mutation every existing consumer already imports. */\nexport const emailChangeHashVerify: TEmailChangeHashVerifyMutation = createEmailChangeHashVerifyMutation({\n\tmodel: UserBase,\n\tpaths: DEFAULT_VERIFY_EMAIL_PATHS,\n\tconfirmNewEmail,\n\tincReqTimes\n})\n"]}
|
|
@@ -19,30 +19,23 @@ export const login4Ever = {
|
|
|
19
19
|
},
|
|
20
20
|
async resolve(_, args, ctx) {
|
|
21
21
|
const { email, password } = args;
|
|
22
|
-
//console.debug('[login4Ever]')
|
|
23
22
|
const uEmail = email.toLowerCase().trim();
|
|
24
23
|
checkEmailLen(uEmail);
|
|
25
24
|
checkPwdLen(password);
|
|
26
|
-
//console.debug('[login4Ever] data ok')
|
|
27
25
|
let accessToken = '';
|
|
28
26
|
const session = await mongoose.startSession();
|
|
29
27
|
try {
|
|
30
28
|
await session.withTransaction(async () => {
|
|
31
29
|
// search if the email exists
|
|
32
30
|
const user = await checkUserLoginAuthorization(uEmail, password, session);
|
|
33
|
-
//console.debug('[login4Ever] auth ok')
|
|
34
31
|
// pwd valid
|
|
35
32
|
const uId = user.userId;
|
|
36
33
|
await updateLoginStats4ever(uId, user.lastLogin, session);
|
|
37
|
-
//console.debug('[login4Ever] update ok')
|
|
38
|
-
// console.debug('[login] lastlogin ok')
|
|
39
34
|
accessToken = generateAccessToken();
|
|
40
35
|
const refreshToken = generateRefreshToken();
|
|
41
36
|
const accTokenExp = accessTokenExpiry();
|
|
42
37
|
await setRedisLoginSession(uId, accessToken, accTokenExp, refreshToken);
|
|
43
|
-
//console.debug('[login4Ever] redis ok')
|
|
44
38
|
setLoginCookies(ctx, refreshToken);
|
|
45
|
-
//console.debug('[login4Ever] login cookie ok')
|
|
46
39
|
});
|
|
47
40
|
}
|
|
48
41
|
catch (e) {
|
|
@@ -53,7 +46,6 @@ export const login4Ever = {
|
|
|
53
46
|
finally {
|
|
54
47
|
await session.endSession();
|
|
55
48
|
}
|
|
56
|
-
//console.debug('[login4Ever] return accessToken', accessToken)
|
|
57
49
|
return { accessToken };
|
|
58
50
|
}
|
|
59
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login4Ever.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/login4Ever.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,WAAW,EAAE,qCAA4B;AAClD,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gCAAuB;AAC9F,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,kFAAyE;AAC/G,OAAO,EAAE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AAC,CAAA;gBACvE,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAA;YACnC,CAAC,CAAC,CAAA;QACH,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACrB,WAAW,GAAG,EAAE,CAAA;YAChB,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;YAC1B,eAAe,CAAC,CAAyB,CAAC,CAAA;QAC3C,CAAC;gBAAS,CAAC;YACV,MAAM,OAAO,CAAC,UAAU,EAAE,CAAA;QAC3B,CAAC;QACD,OAAO,EAAE,WAAW,EAAE,CAAA;IACvB,CAAC;CACD,CAAA","sourcesContent":["import { IContextLogin } from '@context/IContextLogin.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { checkPwdLen } from '@lib/checkPwdLen.mjs'\nimport { setLoginCookies } from '@lib/setLoginCookies.mjs'\nimport { accessTokenExpiry, generateAccessToken, generateRefreshToken } from '@lib/tokens.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { checkUserLoginAuthorization } from '@private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs'\nimport { setRedisLoginSession } from '@private/graphQL/schema/mutations/setRedisLoginSession.mjs'\nimport { updateLoginStats4ever } from '@private/graphQL/schema/mutations/updateLoginStats4ever.mjs'\nimport * as Sentry from '@sentry/node'\nimport { LoginType } from '@stypes/LoginType.mjs'\nimport { GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose from 'mongoose'\n\n/** Arguments accepted by the `login4Ever` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface ILogin4EverArgs {\n\temail: string\n\tpassword: string\n}\n\nexport const login4Ever = {\n\tdescription: 'login in platform WITHOUT remember me flag',\n\ttype: new GraphQLNonNull(LoginType),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpassword: { type: new GraphQLNonNull(GraphQLString) }\n\t},\n\tasync resolve(_: unknown, args: ILogin4EverArgs, ctx: IContextLogin) {\n\t\tconst { email, password } = args\n\n\t\tconst uEmail = email.toLowerCase().trim()\n\t\tcheckEmailLen(uEmail)\n\t\tcheckPwdLen(password)\n\n\t\tlet accessToken = ''\n\n\t\tconst session = await mongoose.startSession()\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\t// search if the email exists\n\t\t\t\tconst user = await checkUserLoginAuthorization(uEmail, password, session)\n\n\t\t\t\t// pwd valid\n\t\t\t\tconst uId = user.userId\n\t\t\t\tawait updateLoginStats4ever(uId, user.lastLogin, session)\n\n\t\t\t\taccessToken = generateAccessToken()\n\t\t\t\tconst refreshToken = generateRefreshToken()\n\t\t\t\tconst accTokenExp = accessTokenExpiry()\n\n\t\t\t\tawait setRedisLoginSession(uId, accessToken, accTokenExp, refreshToken)\n\t\t\t\tsetLoginCookies(ctx, refreshToken)\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\taccessToken = ''\n\t\t\tSentry.captureException(e)\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\t\treturn { accessToken }\n\t}\n}\n"]}
|
|
@@ -35,7 +35,6 @@ export const loginAdmin = {
|
|
|
35
35
|
// pwd valid
|
|
36
36
|
const uId = user.userId;
|
|
37
37
|
await updateAdminLoginStats(uId, user.lastLogin, rememberMe, session);
|
|
38
|
-
// console.debug('[login] lastlogin ok')
|
|
39
38
|
accessToken = generateAccessToken();
|
|
40
39
|
const refreshToken = generateRefreshToken();
|
|
41
40
|
const accTokenExp = accessTokenExpiry();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginAdmin.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/loginAdmin.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,WAAW,EAAE,qCAA4B;AAClD,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,i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,OAAO,CAAC,UAAU,EAAE,CAAA;QAC3B,CAAC;QAED,OAAO;YACN,WAAW;SACX,CAAA;IACF,CAAC;CACD,CAAA","sourcesContent":["import { IContextLogin } from '@context/IContextLogin.mjs'\nimport { checkEmailLen } from '@lib/checkEmailLen.mjs'\nimport { checkPwdLen } from '@lib/checkPwdLen.mjs'\nimport { setLoginCookies } from '@lib/setLoginCookies.mjs'\nimport { accessTokenExpiry, generateAccessToken, generateRefreshToken } from '@lib/tokens.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { checkUserAdminLoginAuthorization } from '@private/graphQL/schema/mutations/checkUserAdminLoginAuthorization.mjs'\nimport { setRedisLoginSession } from '@private/graphQL/schema/mutations/setRedisLoginSession.mjs'\nimport { updateAdminLoginStats } from '@private/graphQL/schema/mutations/updateAdminLoginStats.mjs'\nimport * as Sentry from '@sentry/node'\nimport { LoginType } from '@stypes/LoginType.mjs'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose from 'mongoose'\n\n/** Arguments accepted by the `loginAdmin` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface ILoginAdminArgs {\n\temail: string\n\tpassword: string\n\trememberMe: boolean\n}\n\n/**\n *\n */\nexport const loginAdmin = {\n\tdescription: 'login admin in platform',\n\ttype: new GraphQLNonNull(LoginType),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpassword: { type: new GraphQLNonNull(GraphQLString) },\n\t\trememberMe: { type: new GraphQLNonNull(GraphQLBoolean) }\n\t},\n\tasync resolve(_: unknown, args: ILoginAdminArgs, ctx: IContextLogin) {\n\t\tconst { email, password, rememberMe } = args\n\n\t\tconst uEmail = email.toLowerCase().trim()\n\t\tcheckEmailLen(uEmail)\n\t\tcheckPwdLen(password)\n\n\t\tlet accessToken = ''\n\n\t\tconst session = await mongoose.startSession()\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\t// search if the email exists\n\t\t\t\tconst user = await checkUserAdminLoginAuthorization(uEmail, password, session)\n\t\t\t\t// pwd valid\n\t\t\t\tconst uId = user.userId\n\t\t\t\tawait updateAdminLoginStats(uId, user.lastLogin, rememberMe, session)\n\n\t\t\t\taccessToken = generateAccessToken()\n\t\t\t\tconst refreshToken = generateRefreshToken()\n\t\t\t\tconst accTokenExp = accessTokenExpiry()\n\n\t\t\t\tawait setRedisLoginSession(uId, accessToken, accTokenExp, refreshToken)\n\t\t\t\tsetLoginCookies(ctx, refreshToken)\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\taccessToken = ''\n\t\t\tSentry.captureException(e)\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\treturn {\n\t\t\taccessToken\n\t\t}\n\t}\n}\n"]}
|
|
@@ -32,7 +32,6 @@ export const loginRememberme = {
|
|
|
32
32
|
// pwd valid
|
|
33
33
|
const uId = user.userId;
|
|
34
34
|
await updateLoginStatsRememberme(uId, user.lastLogin, rememberMe, session);
|
|
35
|
-
// console.debug('[login] lastlogin ok')
|
|
36
35
|
accessToken = generateAccessToken();
|
|
37
36
|
const refreshToken = generateRefreshToken();
|
|
38
37
|
const accTokenExp = accessTokenExpiry();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loginRememberme.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/loginRememberme.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uCAA8B;AACtD,OAAO,EAAE,WAAW,EAAE,qCAA4B;AAClD,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gCAAuB;AAC9F,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,kFAAyE;AAC/G,OAAO,EAAE,oBAAoB,EAAE,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{ checkPwdLen } from '@lib/checkPwdLen.mjs'\nimport { setLoginCookies } from '@lib/setLoginCookies.mjs'\nimport { accessTokenExpiry, generateAccessToken, generateRefreshToken } from '@lib/tokens.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport { checkUserLoginAuthorization } from '@private/graphQL/schema/mutations/checkUserLoginAuthorization.mjs'\nimport { setRedisLoginSession } from '@private/graphQL/schema/mutations/setRedisLoginSession.mjs'\nimport { updateLoginStatsRememberme } from '@private/graphQL/schema/mutations/updateLoginStatsRememberme.mjs'\nimport * as Sentry from '@sentry/node'\nimport { LoginType } from '@stypes/LoginType.mjs'\nimport { GraphQLBoolean, GraphQLError, GraphQLNonNull, GraphQLString } from 'graphql'\nimport mongoose from 'mongoose'\n\n/** Arguments accepted by the `loginRememberme` mutation. Exported so a consumer re-exporting the bound mutation can name its type. */\nexport interface ILoginRemembermeArgs {\n\temail: string\n\tpassword: string\n\trememberMe: boolean\n}\n\nexport const loginRememberme = {\n\tdescription: 'login in platform with remember me flag',\n\ttype: new GraphQLNonNull(LoginType),\n\targs: {\n\t\temail: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpassword: { type: new GraphQLNonNull(GraphQLString) },\n\t\trememberMe: { type: new GraphQLNonNull(GraphQLBoolean) }\n\t},\n\tasync resolve(_: unknown, args: ILoginRemembermeArgs, ctx: IContextLogin) {\n\t\tconst { email, password, rememberMe } = args\n\n\t\tconst uEmail = email.toLowerCase().trim()\n\t\tcheckEmailLen(uEmail)\n\t\tcheckPwdLen(password)\n\n\t\tlet accessToken = ''\n\n\t\tconst session = await mongoose.startSession()\n\t\ttry {\n\t\t\tawait session.withTransaction(async () => {\n\t\t\t\t// search if the email exists\n\t\t\t\tconst user = await checkUserLoginAuthorization(uEmail, password, session)\n\t\t\t\t// pwd valid\n\t\t\t\tconst uId = user.userId\n\t\t\t\tawait updateLoginStatsRememberme(uId, user.lastLogin, rememberMe, session)\n\n\t\t\t\taccessToken = generateAccessToken()\n\t\t\t\tconst refreshToken = generateRefreshToken()\n\t\t\t\tconst accTokenExp = accessTokenExpiry()\n\n\t\t\t\tawait setRedisLoginSession(uId, accessToken, accTokenExp, refreshToken)\n\t\t\t\tsetLoginCookies(ctx, refreshToken)\n\t\t\t})\n\t\t} catch (e: unknown) {\n\t\t\taccessToken = ''\n\t\t\tSentry.captureException(e)\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t} finally {\n\t\t\tawait session.endSession()\n\t\t}\n\n\t\treturn { accessToken }\n\t}\n}\n"]}
|
|
@@ -11,7 +11,6 @@ export const refresh = {
|
|
|
11
11
|
description: 'refresh token',
|
|
12
12
|
type: new GraphQLNonNull(RefreshType),
|
|
13
13
|
async resolve(_, {}, ctx) {
|
|
14
|
-
// console.debug('refresh')
|
|
15
14
|
let status = false; // default
|
|
16
15
|
// has the refresh token, access token already expired
|
|
17
16
|
// gets the user id already copied into ctx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.mjs","sourceRoot":"","sources":["../../../../src/graphQL/schema/mutations/refresh.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,uCAA8B;AACpD,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAuB;AACpH,OAAO,EAAE,eAAe,EAAE,yCAAgC;AAC1D,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,iCAA+B;AACrD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAgB,cAAc,EAAE,MAAM,SAAS,CAAA;AAEtD,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,WAAW,EAAE,eAAe;IAC5B,IAAI,EAAE,IAAI,cAAc,CAAC,WAAW,CAAC;IACrC,KAAK,CAAC,OAAO,C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\nimport { redisClient } from '@dataSources/Redis.mjs'\nimport { setLoginCookies } from '@lib/setLoginCookies.mjs'\nimport { accessTokenExpiry, generateAccessToken, generateRefreshToken, REFRESH_TOKEN_EXPIRY } from '@lib/tokens.mjs'\nimport { tryCatchRethrow } from '@lib/tryCatchRethrow.mjs'\nimport * as Sentry from '@sentry/node'\nimport { RefreshType } from '@stypes/RefreshType.mjs'\nimport * as dotenv from 'dotenv'\nimport { GraphQLError, GraphQLNonNull } from 'graphql'\n\ndotenv.config()\n\nexport const refresh = {\n\tdescription: 'refresh token',\n\ttype: new GraphQLNonNull(RefreshType),\n\tasync resolve(_: unknown, {}, ctx: IContextRefresh) {\n\t\tlet status = false // default\n\n\t\t// has the refresh token, access token already expired\n\n\t\t// gets the user id already copied into ctx\n\t\tconst userId = ctx.state.user.id.toString()\n\n\t\t// generates the 2 new tokens\n\t\tlet accessToken = generateAccessToken()\n\t\tlet refreshToken = generateRefreshToken()\n\t\tconst keyAccess = `${process.env.REDIS_KEY}access:${accessToken}`\n\t\tconst keyRefresh = `${process.env.REDIS_KEY}refresh:${refreshToken}`\n\n\t\tlet accessTokenData = ctx.state.user\n\t\tconst oldRefresh = ctx.state.user.refreshToken\n\t\t// @ts-expect-error delete refresh\n\t\tdelete accessTokenData.refreshToken\n\n\t\tconst refreshTokenData = { id: userId }\n\n\t\ttry {\n\t\t\t// Store session in Redis\n\t\t\tawait Promise.all([\n\t\t\t\tredisClient.hSet(keyAccess, accessTokenData as unknown as Record<string, string>),\n\t\t\t\tredisClient.hSet(keyRefresh, refreshTokenData as unknown as Record<string, string>)\n\t\t\t])\n\n\t\t\t// set expiry\n\t\t\tconst accTokenExp = accessTokenExpiry()\n\t\t\tawait Promise.all([redisClient.expire(keyAccess, accTokenExp), redisClient.expire(keyRefresh, REFRESH_TOKEN_EXPIRY)])\n\n\t\t\tsetLoginCookies(ctx, refreshToken)\n\n\t\t\t// deletes the refresh token used to make this call\n\t\t\tawait redisClient.del(`${process.env.REDIS_KEY}${oldRefresh}`)\n\n\t\t\tstatus = true\n\t\t} catch (e: unknown) {\n\t\t\tSentry.captureException(e)\n\t\t\t// delete keys\n\t\t\tawait Promise.all([redisClient.del(keyAccess), redisClient.del(keyRefresh)])\n\t\t\taccessToken = ''\n\t\t\ttryCatchRethrow(e as GraphQLError | Error)\n\t\t}\n\n\t\treturn {\n\t\t\tstatus,\n\t\t\taccessToken\n\t\t}\n\t}\n}\n"]}
|