@intlayer/backend 3.1.0 → 3.2.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/cjs/controllers/dictionary.controller.cjs +41 -0
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/organization.controller.cjs +73 -4
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +71 -7
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/projectAccessKey.controller.cjs +31 -0
- package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -1
- package/dist/cjs/controllers/sessionAuth.controller.cjs +277 -57
- package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -1
- package/dist/cjs/controllers/stripe.controller.cjs +84 -0
- package/dist/cjs/controllers/stripe.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +40 -3
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs +182 -0
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs.map +1 -0
- package/dist/cjs/emails/SubscriptionPaymentError.cjs +182 -0
- package/dist/cjs/emails/SubscriptionPaymentError.cjs.map +1 -0
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs +188 -0
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs.map +1 -0
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/index.cjs +15 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs +4 -6
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -1
- package/dist/cjs/routes/dictionary.routes.cjs +2 -62
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/organization.routes.cjs +1 -25
- package/dist/cjs/routes/organization.routes.cjs.map +1 -1
- package/dist/cjs/routes/project.routes.cjs +10 -85
- package/dist/cjs/routes/project.routes.cjs.map +1 -1
- package/dist/cjs/routes/sessionAuth.routes.cjs +26 -25
- package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -1
- package/dist/cjs/{models/plan.moddel.cjs → routes/stripe.routes.cjs} +20 -9
- package/dist/cjs/routes/stripe.routes.cjs.map +1 -0
- package/dist/cjs/routes/user.routes.cjs +6 -27
- package/dist/cjs/routes/user.routes.cjs.map +1 -1
- package/dist/cjs/schemas/organization.schema.cjs +5 -0
- package/dist/cjs/schemas/organization.schema.cjs.map +1 -1
- package/dist/cjs/schemas/plans.schema.cjs +2 -8
- package/dist/cjs/schemas/plans.schema.cjs.map +1 -1
- package/dist/cjs/schemas/user.schema.cjs +1 -1
- package/dist/cjs/schemas/user.schema.cjs.map +1 -1
- package/dist/cjs/services/email.service.cjs +113 -43
- package/dist/cjs/services/email.service.cjs.map +1 -1
- package/dist/cjs/services/organization.service.cjs +55 -8
- package/dist/cjs/services/organization.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +1 -3
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/sessionAuth.service.cjs +9 -11
- package/dist/cjs/services/sessionAuth.service.cjs.map +1 -1
- package/dist/cjs/services/subscription.service.cjs +134 -51
- package/dist/cjs/services/subscription.service.cjs.map +1 -1
- package/dist/cjs/services/user.service.cjs +1 -3
- package/dist/cjs/services/user.service.cjs.map +1 -1
- package/dist/cjs/types/organization.types.cjs.map +1 -1
- package/dist/cjs/types/plan.types.cjs.map +1 -1
- package/dist/cjs/types/session.types.cjs.map +1 -1
- package/dist/cjs/utils/errors/ErrorHandler.cjs +29 -9
- package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
- package/dist/cjs/utils/errors/ErrorsClass.cjs +17 -3
- package/dist/cjs/utils/errors/ErrorsClass.cjs.map +1 -1
- package/dist/cjs/utils/errors/errorCodes.cjs +99 -8
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +1 -1
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/plan.cjs +7 -2
- package/dist/cjs/utils/plan.cjs.map +1 -1
- package/dist/cjs/utils/responseData.cjs +8 -0
- package/dist/cjs/utils/responseData.cjs.map +1 -1
- package/dist/cjs/webhooks/stripe.webhook.cjs +133 -0
- package/dist/cjs/webhooks/stripe.webhook.cjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +41 -0
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/organization.controller.mjs +73 -4
- package/dist/esm/controllers/organization.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +71 -7
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/projectAccessKey.controller.mjs +31 -0
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
- package/dist/esm/controllers/sessionAuth.controller.mjs +273 -56
- package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -1
- package/dist/esm/controllers/stripe.controller.mjs +60 -0
- package/dist/esm/controllers/stripe.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +40 -3
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs +168 -0
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs.map +1 -0
- package/dist/esm/emails/SubscriptionPaymentError.mjs +168 -0
- package/dist/esm/emails/SubscriptionPaymentError.mjs.map +1 -0
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs +174 -0
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs.map +1 -0
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -5
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +4 -6
- package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +2 -62
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/organization.routes.mjs +1 -25
- package/dist/esm/routes/organization.routes.mjs.map +1 -1
- package/dist/esm/routes/project.routes.mjs +10 -85
- package/dist/esm/routes/project.routes.mjs.map +1 -1
- package/dist/esm/routes/sessionAuth.routes.mjs +29 -26
- package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -1
- package/dist/esm/routes/stripe.routes.mjs +17 -0
- package/dist/esm/routes/stripe.routes.mjs.map +1 -0
- package/dist/esm/routes/user.routes.mjs +6 -27
- package/dist/esm/routes/user.routes.mjs.map +1 -1
- package/dist/esm/schemas/organization.schema.mjs +5 -0
- package/dist/esm/schemas/organization.schema.mjs.map +1 -1
- package/dist/esm/schemas/plans.schema.mjs +2 -8
- package/dist/esm/schemas/plans.schema.mjs.map +1 -1
- package/dist/esm/schemas/user.schema.mjs +1 -1
- package/dist/esm/schemas/user.schema.mjs.map +1 -1
- package/dist/esm/services/email.service.mjs +125 -43
- package/dist/esm/services/email.service.mjs.map +1 -1
- package/dist/esm/services/organization.service.mjs +51 -7
- package/dist/esm/services/organization.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +1 -3
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/sessionAuth.service.mjs +9 -10
- package/dist/esm/services/sessionAuth.service.mjs.map +1 -1
- package/dist/esm/services/subscription.service.mjs +136 -53
- package/dist/esm/services/subscription.service.mjs.map +1 -1
- package/dist/esm/services/user.service.mjs +1 -3
- package/dist/esm/services/user.service.mjs.map +1 -1
- package/dist/esm/utils/errors/ErrorHandler.mjs +29 -9
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
- package/dist/esm/utils/errors/ErrorsClass.mjs +17 -3
- package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +99 -8
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +1 -1
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/plan.mjs +7 -2
- package/dist/esm/utils/plan.mjs.map +1 -1
- package/dist/esm/utils/responseData.mjs +8 -0
- package/dist/esm/utils/responseData.mjs.map +1 -1
- package/dist/esm/webhooks/stripe.webhook.mjs +113 -0
- package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/organization.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
- package/dist/types/controllers/sessionAuth.controller.d.ts +24 -5
- package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -1
- package/dist/types/controllers/stripe.controller.d.ts +17 -0
- package/dist/types/controllers/stripe.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -0
- package/dist/types/emails/SubscriptionPaymentError.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentError.d.ts.map +1 -0
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts.map +1 -0
- package/dist/types/export.d.ts +1 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
- package/dist/types/models/organization.model.d.ts +1 -0
- package/dist/types/models/organization.model.d.ts.map +1 -1
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/organization.routes.d.ts.map +1 -1
- package/dist/types/routes/project.routes.d.ts.map +1 -1
- package/dist/types/routes/sessionAuth.routes.d.ts +15 -2
- package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -1
- package/dist/types/routes/stripe.routes.d.ts +10 -0
- package/dist/types/routes/stripe.routes.d.ts.map +1 -0
- package/dist/types/routes/user.routes.d.ts.map +1 -1
- package/dist/types/schemas/organization.schema.d.ts +1 -0
- package/dist/types/schemas/organization.schema.d.ts.map +1 -1
- package/dist/types/schemas/plans.schema.d.ts.map +1 -1
- package/dist/types/services/email.service.d.ts +33 -4
- package/dist/types/services/email.service.d.ts.map +1 -1
- package/dist/types/services/organization.service.d.ts +15 -0
- package/dist/types/services/organization.service.d.ts.map +1 -1
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/sessionAuth.service.d.ts +1 -8
- package/dist/types/services/sessionAuth.service.d.ts.map +1 -1
- package/dist/types/services/subscription.service.d.ts +20 -5
- package/dist/types/services/subscription.service.d.ts.map +1 -1
- package/dist/types/services/user.service.d.ts.map +1 -1
- package/dist/types/types/organization.types.d.ts +2 -0
- package/dist/types/types/organization.types.d.ts.map +1 -1
- package/dist/types/types/plan.types.d.ts +2 -3
- package/dist/types/types/plan.types.d.ts.map +1 -1
- package/dist/types/types/session.types.d.ts +6 -6
- package/dist/types/types/session.types.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorHandler.d.ts +5 -3
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorsClass.d.ts +4 -1
- package/dist/types/utils/errors/ErrorsClass.d.ts.map +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +92 -1
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts +1 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/plan.d.ts +1 -1
- package/dist/types/utils/plan.d.ts.map +1 -1
- package/dist/types/utils/responseData.d.ts +13 -2
- package/dist/types/utils/responseData.d.ts.map +1 -1
- package/dist/types/webhooks/stripe.d.ts.map +1 -1
- package/dist/types/webhooks/stripe.webhook.d.ts +3 -0
- package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -0
- package/package.json +6 -5
- package/dist/cjs/models/plan.moddel.cjs.map +0 -1
- package/dist/cjs/services/plans.service.cjs +0 -72
- package/dist/cjs/services/plans.service.cjs.map +0 -1
- package/dist/cjs/webhooks/stripe.cjs +0 -94
- package/dist/cjs/webhooks/stripe.cjs.map +0 -1
- package/dist/esm/models/plan.moddel.mjs +0 -7
- package/dist/esm/models/plan.moddel.mjs.map +0 -1
- package/dist/esm/services/plans.service.mjs +0 -44
- package/dist/esm/services/plans.service.mjs.map +0 -1
- package/dist/esm/webhooks/stripe.mjs +0 -70
- package/dist/esm/webhooks/stripe.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/user.routes.ts"],"sourcesContent":["import {\n getUsers,\n updateUser,\n getUserByEmail,\n getUserById,\n createUser,\n getUserByAccount,\n} from '@controllers/user.controller';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/user.routes.ts"],"sourcesContent":["import {\n getUsers,\n updateUser,\n getUserByEmail,\n getUserById,\n createUser,\n getUserByAccount,\n} from '@controllers/user.controller';\nimport { Router } from 'express';\nimport { Routes } from '@/types/Routes';\n\nexport const userRouter: Router = Router();\n\nconst baseURL = `${process.env.BACKEND_URL}/api/user`;\n\nexport const userRoutes = {\n getUsers: {\n urlModel: '/',\n url: baseURL,\n method: 'GET',\n },\n updateUser: {\n urlModel: '/',\n url: baseURL,\n method: 'PUT',\n },\n createUser: {\n urlModel: '/',\n url: baseURL,\n method: 'POST',\n },\n getUserById: {\n urlModel: '/:userId',\n url: ({ userId }: { userId: string }) => `${baseURL}/${userId}`,\n method: 'GET',\n },\n getUserByEmail: {\n urlModel: '/email/:email',\n url: ({ email }: { email: string }) => `${baseURL}/email/${email}`,\n method: 'GET',\n },\n getUserByAccount: {\n urlModel: '/account/:provider/:providerAccountId',\n url: ({\n provider,\n providerAccountId,\n }: {\n provider: string;\n providerAccountId: string;\n }) => `${baseURL}/account/${provider}/${providerAccountId}`,\n method: 'GET',\n },\n} satisfies Routes;\n\nuserRouter.get(userRoutes.getUsers.urlModel, getUsers);\nuserRouter.put(userRoutes.updateUser.urlModel, updateUser);\nuserRouter.post(userRoutes.createUser.urlModel, createUser);\nuserRouter.get(userRoutes.getUserById.urlModel, getUserById);\nuserRouter.get(userRoutes.getUserByEmail.urlModel, getUserByEmail);\nuserRouter.get(userRoutes.getUserByAccount.urlModel, getUserByAccount);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAOO;AACP,qBAAuB;AAGhB,MAAM,iBAAqB,uBAAO;AAEzC,MAAM,UAAU,GAAG,QAAQ,IAAI,WAAW;AAEnC,MAAM,aAAa;AAAA,EACxB,UAAU;AAAA,IACR,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,YAAY;AAAA,IACV,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,YAAY;AAAA,IACV,UAAU;AAAA,IACV,KAAK;AAAA,IACL,QAAQ;AAAA,EACV;AAAA,EACA,aAAa;AAAA,IACX,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,OAAO,MAA0B,GAAG,OAAO,IAAI,MAAM;AAAA,IAC7D,QAAQ;AAAA,EACV;AAAA,EACA,gBAAgB;AAAA,IACd,UAAU;AAAA,IACV,KAAK,CAAC,EAAE,MAAM,MAAyB,GAAG,OAAO,UAAU,KAAK;AAAA,IAChE,QAAQ;AAAA,EACV;AAAA,EACA,kBAAkB;AAAA,IAChB,UAAU;AAAA,IACV,KAAK,CAAC;AAAA,MACJ;AAAA,MACA;AAAA,IACF,MAGM,GAAG,OAAO,YAAY,QAAQ,IAAI,iBAAiB;AAAA,IACzD,QAAQ;AAAA,EACV;AACF;AAEA,WAAW,IAAI,WAAW,SAAS,UAAU,oBAAQ;AACrD,WAAW,IAAI,WAAW,WAAW,UAAU,sBAAU;AACzD,WAAW,KAAK,WAAW,WAAW,UAAU,sBAAU;AAC1D,WAAW,IAAI,WAAW,YAAY,UAAU,uBAAW;AAC3D,WAAW,IAAI,WAAW,eAAe,UAAU,0BAAc;AACjE,WAAW,IAAI,WAAW,iBAAiB,UAAU,4BAAgB;","names":[]}
|
|
@@ -23,6 +23,7 @@ __export(organization_schema_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(organization_schema_exports);
|
|
24
24
|
var import_validateOrganization = require('./../utils/validation/validateOrganization.cjs');
|
|
25
25
|
var import_mongoose = require("mongoose");
|
|
26
|
+
var import_plans = require('./plans.schema.cjs');
|
|
26
27
|
const organizationSchema = new import_mongoose.Schema(
|
|
27
28
|
{
|
|
28
29
|
name: {
|
|
@@ -47,6 +48,10 @@ const organizationSchema = new import_mongoose.Schema(
|
|
|
47
48
|
type: import_mongoose.Schema.Types.ObjectId,
|
|
48
49
|
ref: "User",
|
|
49
50
|
required: true
|
|
51
|
+
},
|
|
52
|
+
plan: {
|
|
53
|
+
type: import_plans.planSchema,
|
|
54
|
+
required: true
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/organization.schema.ts"],"sourcesContent":["import {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateOrganization';\nimport { Schema } from 'mongoose';\nimport type { Organization } from '@/types/organization.types';\n\nexport const organizationSchema = new Schema<Organization>(\n {\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAIO;AACP,sBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/organization.schema.ts"],"sourcesContent":["import {\n MEMBERS_MIN_LENGTH,\n NAME_MAX_LENGTH,\n NAME_MIN_LENGTH,\n} from '@utils/validation/validateOrganization';\nimport { Schema } from 'mongoose';\nimport { planSchema } from './plans.schema';\nimport type { Organization } from '@/types/organization.types';\n\nexport const organizationSchema = new Schema<Organization>(\n {\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n membersIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n adminsIds: {\n type: [Schema.Types.ObjectId],\n ref: 'User',\n required: true,\n minlength: MEMBERS_MIN_LENGTH,\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n plan: {\n type: planSchema,\n required: true,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAIO;AACP,sBAAuB;AACvB,mBAA2B;AAGpB,MAAM,qBAAqB,IAAI;AAAA,EACpC;AAAA,IACE,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,YAAY;AAAA,MACV,MAAM,CAAC,uBAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,CAAC,uBAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":[]}
|
|
@@ -30,19 +30,13 @@ const planSchema = new import_mongoose.Schema(
|
|
|
30
30
|
enum: ["FREE", "PREMIUM", "ENTERPRISE"],
|
|
31
31
|
default: "FREE"
|
|
32
32
|
},
|
|
33
|
-
|
|
33
|
+
creatorId: {
|
|
34
34
|
type: import_mongoose.Schema.Types.ObjectId,
|
|
35
35
|
ref: "User",
|
|
36
36
|
required: true
|
|
37
37
|
},
|
|
38
|
-
organizationId: {
|
|
39
|
-
type: import_mongoose.Schema.Types.ObjectId,
|
|
40
|
-
ref: "Organization",
|
|
41
|
-
required: true
|
|
42
|
-
},
|
|
43
38
|
priceId: {
|
|
44
|
-
type: String
|
|
45
|
-
required: true
|
|
39
|
+
type: String
|
|
46
40
|
},
|
|
47
41
|
status: {
|
|
48
42
|
type: String,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/plans.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport { Plan } from '@/types/plan.types';\n\nexport const planSchema = new Schema<Plan>(\n {\n type: {\n type: String,\n required: true,\n enum: ['FREE', 'PREMIUM', 'ENTERPRISE'],\n default: 'FREE',\n },\n
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/plans.schema.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport { Plan } from '@/types/plan.types';\n\nexport const planSchema = new Schema<Plan>(\n {\n type: {\n type: String,\n required: true,\n enum: ['FREE', 'PREMIUM', 'ENTERPRISE'],\n default: 'FREE',\n },\n creatorId: {\n type: Schema.Types.ObjectId,\n ref: 'User',\n required: true,\n },\n priceId: {\n type: String,\n },\n status: {\n type: String,\n required: true,\n enum: ['INACTIVE', 'ACTIVE', 'ERROR', 'CANCELLED'],\n default: 'INACTIVE',\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAGhB,MAAM,aAAa,IAAI;AAAA,EAC5B;AAAA,IACE,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,MAAM,CAAC,QAAQ,WAAW,YAAY;AAAA,MACtC,SAAS;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACT,MAAM,uBAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,MACV,MAAM,CAAC,YAAY,UAAU,SAAS,WAAW;AAAA,MACjD,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\nimport type { User } from '@/types/user.types';\n\nconst SessionSchema = new Schema(\n {\n sessionToken: {\n type: String,\n required: true,\n },\n expires: {\n type: Date,\n required: true,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nconst ProviderSchema = new Schema(\n {\n provider: {\n type: String,\n required: true,\n },\n providerAccountId: {\n type: String,\n },\n secret: {\n type: String,\n maxlength: 1024,\n minlength: 6,\n },\n emailValidated: {\n type:
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/user.schema.ts"],"sourcesContent":["import {\n NAMES_MAX_LENGTH,\n NAMES_MIN_LENGTH,\n} from '@utils/validation/validateUser';\nimport { Schema } from 'mongoose';\nimport validator from 'validator';\nimport type { User } from '@/types/user.types';\n\nconst SessionSchema = new Schema(\n {\n sessionToken: {\n type: String,\n required: true,\n },\n expires: {\n type: Date,\n required: true,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nconst ProviderSchema = new Schema(\n {\n provider: {\n type: String,\n required: true,\n },\n providerAccountId: {\n type: String,\n },\n secret: {\n type: String,\n maxlength: 1024,\n minlength: 6,\n },\n emailValidated: {\n type: String,\n },\n passwordHash: {\n type: String,\n },\n },\n { _id: false } // This prevents Mongoose from creating an _id field for the session subdocument\n);\n\nexport const userSchema = new Schema<User>(\n {\n email: {\n type: String,\n required: true,\n unique: true,\n validate: [validator.isEmail, 'Please fill a valid email address'],\n lowercase: true,\n trim: true,\n },\n name: {\n type: String,\n maxlength: NAMES_MAX_LENGTH,\n minlength: NAMES_MIN_LENGTH,\n },\n phone: {\n type: String,\n maxlength: 20,\n },\n session: {\n type: SessionSchema,\n required: false,\n },\n\n customerId: {\n type: String,\n required: false,\n },\n\n provider: {\n type: [ProviderSchema],\n default: undefined,\n required: false,\n },\n },\n {\n timestamps: true,\n }\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAGO;AACP,sBAAuB;AACvB,uBAAsB;AAGtB,MAAM,gBAAgB,IAAI;AAAA,EACxB;AAAA,IACE,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEA,MAAM,iBAAiB,IAAI;AAAA,EACzB;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IACA,mBAAmB;AAAA,MACjB,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,gBAAgB;AAAA,MACd,MAAM;AAAA,IACR;AAAA,IACA,cAAc;AAAA,MACZ,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EACA,EAAE,KAAK,MAAM;AAAA;AACf;AAEO,MAAM,aAAa,IAAI;AAAA,EAC5B;AAAA,IACE,OAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,UAAU,CAAC,iBAAAA,QAAU,SAAS,mCAAmC;AAAA,MACjE,WAAW;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,WAAW;AAAA,IACb;AAAA,IACA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,UAAU;AAAA,MACR,MAAM,CAAC,cAAc;AAAA,MACrB,SAAS;AAAA,MACT,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":["validator"]}
|
|
@@ -25,70 +25,139 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
25
25
|
var import_InviteUserEmail = require('./../emails/InviteUserEmail.cjs');
|
|
26
26
|
var import_PasswordChangeConfirmation = require('./../emails/PasswordChangeConfirmation.cjs');
|
|
27
27
|
var import_ResetUserPassword = require('./../emails/ResetUserPassword.cjs');
|
|
28
|
+
var import_SubscriptionPaymentCancellation = require('./../emails/SubscriptionPaymentCancellation.cjs');
|
|
29
|
+
var import_SubscriptionPaymentError = require('./../emails/SubscriptionPaymentError.cjs');
|
|
30
|
+
var import_SubscriptionPaymentSuccess = require('./../emails/SubscriptionPaymentSuccess.cjs');
|
|
28
31
|
var import_ValidateUserEmail = require('./../emails/ValidateUserEmail.cjs');
|
|
29
32
|
var import_Welcome = require('./../emails/Welcome.cjs');
|
|
30
33
|
var import_logger = require('./../logger/index.cjs');
|
|
31
34
|
var import_express_intlayer = require("express-intlayer");
|
|
32
35
|
var import_resend = require("resend");
|
|
33
|
-
const getEmailComponents = () => ({
|
|
36
|
+
const getEmailComponents = (locale) => ({
|
|
34
37
|
invite: {
|
|
35
|
-
template: (0, import_express_intlayer.t)(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
template: (0, import_express_intlayer.t)(
|
|
39
|
+
{
|
|
40
|
+
en: import_InviteUserEmail.InviteUserEmailEN,
|
|
41
|
+
fr: import_InviteUserEmail.InviteUserEmailFR,
|
|
42
|
+
es: import_InviteUserEmail.InviteUserEmailES
|
|
43
|
+
},
|
|
44
|
+
locale
|
|
45
|
+
),
|
|
46
|
+
subject: (0, import_express_intlayer.t)(
|
|
47
|
+
{
|
|
48
|
+
en: "You have been invited to join Intlayer",
|
|
49
|
+
fr: "Vous \xEAtes invit\xE9 \xE0 rejoindre Intlayer",
|
|
50
|
+
es: "Has sido invitado a unirte a Intlayer"
|
|
51
|
+
},
|
|
52
|
+
locale
|
|
53
|
+
)
|
|
45
54
|
},
|
|
46
55
|
validate: {
|
|
47
|
-
template: (0, import_express_intlayer.t)(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
template: (0, import_express_intlayer.t)(
|
|
57
|
+
{
|
|
58
|
+
en: import_ValidateUserEmail.ValidateUserEmailEN,
|
|
59
|
+
fr: import_ValidateUserEmail.ValidateUserEmailFR,
|
|
60
|
+
es: import_ValidateUserEmail.ValidateUserEmailES
|
|
61
|
+
},
|
|
62
|
+
locale
|
|
63
|
+
),
|
|
64
|
+
subject: (0, import_express_intlayer.t)(
|
|
65
|
+
{
|
|
66
|
+
en: "Validate your email for Intlayer",
|
|
67
|
+
fr: "Validez votre email pour Intlayer",
|
|
68
|
+
es: "Valida tu correo electr\xF3nico para Intlayer"
|
|
69
|
+
},
|
|
70
|
+
locale
|
|
71
|
+
)
|
|
57
72
|
},
|
|
58
73
|
resetPassword: {
|
|
74
|
+
template: (0, import_express_intlayer.t)(
|
|
75
|
+
{
|
|
76
|
+
en: import_ResetUserPassword.ResetPasswordEmailEN,
|
|
77
|
+
fr: import_ResetUserPassword.ResetPasswordEmailFR,
|
|
78
|
+
es: import_ResetUserPassword.ResetPasswordEmailES
|
|
79
|
+
},
|
|
80
|
+
locale
|
|
81
|
+
),
|
|
82
|
+
subject: (0, import_express_intlayer.t)(
|
|
83
|
+
{
|
|
84
|
+
en: "Reset your password for Intlayer",
|
|
85
|
+
fr: "R\xE9initialisez votre mot de passe pour Intlayer",
|
|
86
|
+
es: "Restablece tu contrase\xF1a para Intlayer"
|
|
87
|
+
},
|
|
88
|
+
locale
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
welcome: {
|
|
92
|
+
template: (0, import_express_intlayer.t)(
|
|
93
|
+
{
|
|
94
|
+
en: import_Welcome.WelcomeEmailEN,
|
|
95
|
+
fr: import_Welcome.WelcomeEmailFR,
|
|
96
|
+
es: import_Welcome.WelcomeEmailES
|
|
97
|
+
},
|
|
98
|
+
locale
|
|
99
|
+
),
|
|
100
|
+
subject: (0, import_express_intlayer.t)(
|
|
101
|
+
{
|
|
102
|
+
en: "Welcome to Intlayer!",
|
|
103
|
+
fr: "Bienvenue chez Intlayer!",
|
|
104
|
+
es: "\xA1Bienvenido a Intlayer!"
|
|
105
|
+
},
|
|
106
|
+
locale
|
|
107
|
+
)
|
|
108
|
+
},
|
|
109
|
+
passwordChangeConfirmation: {
|
|
110
|
+
template: (0, import_express_intlayer.t)(
|
|
111
|
+
{
|
|
112
|
+
en: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailEN,
|
|
113
|
+
fr: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailFR,
|
|
114
|
+
es: import_PasswordChangeConfirmation.PasswordChangeConfirmationEmailES
|
|
115
|
+
},
|
|
116
|
+
locale
|
|
117
|
+
),
|
|
118
|
+
subject: (0, import_express_intlayer.t)(
|
|
119
|
+
{
|
|
120
|
+
en: "Your Intlayer password has been changed",
|
|
121
|
+
fr: "Votre mot de passe Intlayer a \xE9t\xE9 modifi\xE9",
|
|
122
|
+
es: "Tu contrase\xF1a de Intlayer ha sido cambiada"
|
|
123
|
+
},
|
|
124
|
+
locale
|
|
125
|
+
)
|
|
126
|
+
},
|
|
127
|
+
subscriptionPaymentSuccess: {
|
|
59
128
|
template: (0, import_express_intlayer.t)({
|
|
60
|
-
en:
|
|
61
|
-
fr:
|
|
62
|
-
es:
|
|
129
|
+
en: import_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessEN,
|
|
130
|
+
fr: import_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessFR,
|
|
131
|
+
es: import_SubscriptionPaymentSuccess.SubscriptionPaymentSuccessES
|
|
63
132
|
}),
|
|
64
133
|
subject: (0, import_express_intlayer.t)({
|
|
65
|
-
en: "
|
|
66
|
-
fr: "
|
|
67
|
-
es: "
|
|
134
|
+
en: "Your payment for Intlayer subscription is confirmed",
|
|
135
|
+
fr: "Votre paiement pour l'abonnement Intlayer est confirm\xE9",
|
|
136
|
+
es: "Tu pago por la suscripci\xF3n de Intlayer ha sido confirmado"
|
|
68
137
|
})
|
|
69
138
|
},
|
|
70
|
-
|
|
139
|
+
subscriptionPaymentCancellation: {
|
|
71
140
|
template: (0, import_express_intlayer.t)({
|
|
72
|
-
en:
|
|
73
|
-
fr:
|
|
74
|
-
es:
|
|
141
|
+
en: import_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationEN,
|
|
142
|
+
fr: import_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationFR,
|
|
143
|
+
es: import_SubscriptionPaymentCancellation.SubscriptionPaymentCancellationES
|
|
75
144
|
}),
|
|
76
145
|
subject: (0, import_express_intlayer.t)({
|
|
77
|
-
en: "
|
|
78
|
-
fr: "
|
|
79
|
-
es: "\
|
|
146
|
+
en: "Your Intlayer subscription has been canceled",
|
|
147
|
+
fr: "Votre abonnement Intlayer a \xE9t\xE9 annul\xE9",
|
|
148
|
+
es: "Tu suscripci\xF3n de Intlayer ha sido cancelada"
|
|
80
149
|
})
|
|
81
150
|
},
|
|
82
|
-
|
|
151
|
+
subscriptionPaymentError: {
|
|
83
152
|
template: (0, import_express_intlayer.t)({
|
|
84
|
-
en:
|
|
85
|
-
fr:
|
|
86
|
-
es:
|
|
153
|
+
en: import_SubscriptionPaymentError.SubscriptionPaymentErrorEN,
|
|
154
|
+
fr: import_SubscriptionPaymentError.SubscriptionPaymentErrorFR,
|
|
155
|
+
es: import_SubscriptionPaymentError.SubscriptionPaymentErrorES
|
|
87
156
|
}),
|
|
88
157
|
subject: (0, import_express_intlayer.t)({
|
|
89
|
-
en: "
|
|
90
|
-
fr: "
|
|
91
|
-
es: "
|
|
158
|
+
en: "There was an issue with your Intlayer subscription payment",
|
|
159
|
+
fr: "Un probl\xE8me est survenu avec votre paiement pour l'abonnement Intlayer",
|
|
160
|
+
es: "Hubo un problema con el pago de tu suscripci\xF3n de Intlayer"
|
|
92
161
|
})
|
|
93
162
|
}
|
|
94
163
|
});
|
|
@@ -96,15 +165,16 @@ const sendEmail = async ({
|
|
|
96
165
|
type,
|
|
97
166
|
to,
|
|
98
167
|
subject,
|
|
168
|
+
locale,
|
|
99
169
|
...props
|
|
100
170
|
}) => {
|
|
101
171
|
const resend = new import_resend.Resend(process.env.RESEND_API_KEY);
|
|
102
|
-
const emailComponents = getEmailComponents();
|
|
172
|
+
const emailComponents = getEmailComponents(locale);
|
|
103
173
|
const { template, subject: baseSubject } = emailComponents[type];
|
|
104
174
|
const EmailComponent = template;
|
|
105
175
|
const react = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmailComponent, { ...props });
|
|
106
176
|
await resend.emails.send({
|
|
107
|
-
from: "no-replay@intlayer.org",
|
|
177
|
+
from: "Intlayer <no-replay@intlayer.org>",
|
|
108
178
|
to,
|
|
109
179
|
subject: subject ?? baseSubject,
|
|
110
180
|
react
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n InviteUserEmailEN,\n InviteUserEmailFR,\n InviteUserEmailES,\n} from '@emails/InviteUserEmail';\nimport {\n PasswordChangeConfirmationEmailEN,\n PasswordChangeConfirmationEmailFR,\n PasswordChangeConfirmationEmailES,\n} from '@emails/PasswordChangeConfirmation';\nimport {\n ResetPasswordEmailEN,\n ResetPasswordEmailFR,\n ResetPasswordEmailES,\n} from '@emails/ResetUserPassword';\nimport {\n ValidateUserEmailEN,\n ValidateUserEmailFR,\n ValidateUserEmailES,\n} from '@emails/ValidateUserEmail';\nimport {\n WelcomeEmailEN,\n WelcomeEmailFR,\n WelcomeEmailES,\n} from '@emails/Welcome';\nimport { logger } from '@logger';\nimport { t } from 'express-intlayer';\nimport { ComponentProps } from 'react';\nimport { Resend } from 'resend';\n\ntype EmailComponentsType = (...props: any) => JSX.Element;\ntype EmailComponents = {\n [key: string]: {\n template: EmailComponentsType;\n subject: string;\n };\n};\n\nconst getEmailComponents = ()
|
|
1
|
+
{"version":3,"sources":["../../../src/services/email.service.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n InviteUserEmailEN,\n InviteUserEmailFR,\n InviteUserEmailES,\n} from '@emails/InviteUserEmail';\nimport {\n PasswordChangeConfirmationEmailEN,\n PasswordChangeConfirmationEmailFR,\n PasswordChangeConfirmationEmailES,\n} from '@emails/PasswordChangeConfirmation';\nimport {\n ResetPasswordEmailEN,\n ResetPasswordEmailFR,\n ResetPasswordEmailES,\n} from '@emails/ResetUserPassword';\n\nimport {\n SubscriptionPaymentCancellationEN,\n SubscriptionPaymentCancellationFR,\n SubscriptionPaymentCancellationES,\n} from '@emails/SubscriptionPaymentCancellation';\nimport {\n SubscriptionPaymentErrorEN,\n SubscriptionPaymentErrorFR,\n SubscriptionPaymentErrorES,\n} from '@emails/SubscriptionPaymentError';\nimport {\n SubscriptionPaymentSuccessEN,\n SubscriptionPaymentSuccessFR,\n SubscriptionPaymentSuccessES,\n} from '@emails/SubscriptionPaymentSuccess';\nimport {\n ValidateUserEmailEN,\n ValidateUserEmailFR,\n ValidateUserEmailES,\n} from '@emails/ValidateUserEmail';\nimport {\n WelcomeEmailEN,\n WelcomeEmailFR,\n WelcomeEmailES,\n} from '@emails/Welcome';\n\nimport { logger } from '@logger';\nimport { t } from 'express-intlayer';\nimport { Locales } from 'intlayer';\nimport { ComponentProps } from 'react';\nimport { Resend } from 'resend';\n\ntype EmailComponentsType = (...props: any) => JSX.Element;\ntype EmailComponents = {\n [key: string]: {\n template: EmailComponentsType;\n subject: string;\n };\n};\n\nconst getEmailComponents = (locale?: Locales) =>\n ({\n invite: {\n template: t(\n {\n en: InviteUserEmailEN,\n fr: InviteUserEmailFR,\n es: InviteUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'You have been invited to join Intlayer',\n fr: 'Vous êtes invité à rejoindre Intlayer',\n es: 'Has sido invitado a unirte a Intlayer',\n },\n locale\n ),\n },\n validate: {\n template: t(\n {\n en: ValidateUserEmailEN,\n fr: ValidateUserEmailFR,\n es: ValidateUserEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Validate your email for Intlayer',\n fr: 'Validez votre email pour Intlayer',\n es: 'Valida tu correo electrónico para Intlayer',\n },\n locale\n ),\n },\n resetPassword: {\n template: t(\n {\n en: ResetPasswordEmailEN,\n fr: ResetPasswordEmailFR,\n es: ResetPasswordEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Reset your password for Intlayer',\n fr: 'Réinitialisez votre mot de passe pour Intlayer',\n es: 'Restablece tu contraseña para Intlayer',\n },\n locale\n ),\n },\n welcome: {\n template: t(\n {\n en: WelcomeEmailEN,\n fr: WelcomeEmailFR,\n es: WelcomeEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Welcome to Intlayer!',\n fr: 'Bienvenue chez Intlayer!',\n es: '¡Bienvenido a Intlayer!',\n },\n locale\n ),\n },\n passwordChangeConfirmation: {\n template: t(\n {\n en: PasswordChangeConfirmationEmailEN,\n fr: PasswordChangeConfirmationEmailFR,\n es: PasswordChangeConfirmationEmailES,\n },\n locale\n ),\n subject: t(\n {\n en: 'Your Intlayer password has been changed',\n fr: 'Votre mot de passe Intlayer a été modifié',\n es: 'Tu contraseña de Intlayer ha sido cambiada',\n },\n locale\n ),\n },\n subscriptionPaymentSuccess: {\n template: t({\n en: SubscriptionPaymentSuccessEN,\n fr: SubscriptionPaymentSuccessFR,\n es: SubscriptionPaymentSuccessES,\n }),\n subject: t({\n en: 'Your payment for Intlayer subscription is confirmed',\n fr: \"Votre paiement pour l'abonnement Intlayer est confirmé\",\n es: 'Tu pago por la suscripción de Intlayer ha sido confirmado',\n }),\n },\n subscriptionPaymentCancellation: {\n template: t({\n en: SubscriptionPaymentCancellationEN,\n fr: SubscriptionPaymentCancellationFR,\n es: SubscriptionPaymentCancellationES,\n }),\n subject: t({\n en: 'Your Intlayer subscription has been canceled',\n fr: 'Votre abonnement Intlayer a été annulé',\n es: 'Tu suscripción de Intlayer ha sido cancelada',\n }),\n },\n subscriptionPaymentError: {\n template: t({\n en: SubscriptionPaymentErrorEN,\n fr: SubscriptionPaymentErrorFR,\n es: SubscriptionPaymentErrorES,\n }),\n subject: t({\n en: 'There was an issue with your Intlayer subscription payment',\n fr: \"Un problème est survenu avec votre paiement pour l'abonnement Intlayer\",\n es: 'Hubo un problema con el pago de tu suscripción de Intlayer',\n }),\n },\n }) satisfies EmailComponents;\n\ntype EmailType = keyof ReturnType<typeof getEmailComponents>;\n\nexport type SendEmailProps<T extends EmailType> = {\n type: T;\n to: string;\n subject?: string;\n locale?: Locales;\n} & ComponentProps<ReturnType<typeof getEmailComponents>[T]['template']>;\n\nexport const sendEmail = async <T extends EmailType>({\n type,\n to,\n subject,\n locale,\n ...props\n}: SendEmailProps<T>) => {\n const resend = new Resend(process.env.RESEND_API_KEY);\n\n const emailComponents = getEmailComponents(locale);\n\n const { template, subject: baseSubject } = emailComponents[type];\n\n type EmailComponentType = (typeof emailComponents)[T]['template'];\n\n const EmailComponent: EmailComponentType = template;\n\n const react = <EmailComponent {...(props as any)} />;\n\n await resend.emails\n .send({\n from: 'Intlayer <no-replay@intlayer.org>',\n to,\n subject: subject ?? baseSubject,\n react,\n })\n .catch((err) => logger.error(err));\n\n logger.info(`Email sent ${type} to ${to}`);\n};\n"],"mappings":"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","names":[]}
|
|
@@ -22,9 +22,12 @@ __export(organization_service_exports, {
|
|
|
22
22
|
createOrganization: () => createOrganization,
|
|
23
23
|
deleteOrganizationById: () => deleteOrganizationById,
|
|
24
24
|
findOrganizations: () => findOrganizations,
|
|
25
|
+
getOrganizationByCustomerId: () => getOrganizationByCustomerId,
|
|
25
26
|
getOrganizationById: () => getOrganizationById,
|
|
26
27
|
getOrganizationsByOwner: () => getOrganizationsByOwner,
|
|
27
|
-
|
|
28
|
+
saveStripeCustomerId: () => saveStripeCustomerId,
|
|
29
|
+
updateOrganizationById: () => updateOrganizationById,
|
|
30
|
+
updatePlan: () => updatePlan
|
|
28
31
|
});
|
|
29
32
|
module.exports = __toCommonJS(organization_service_exports);
|
|
30
33
|
var import_organization = require('./../models/organization.model.cjs');
|
|
@@ -58,12 +61,22 @@ const createOrganization = async (organization, userId) => {
|
|
|
58
61
|
if (Object.keys(errors).length > 0) {
|
|
59
62
|
throw new import_errors.GenericError("ORGANIZATION_INVALID_FIELDS", { errors });
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
try {
|
|
65
|
+
const result = await import_organization.OrganizationModel.create({
|
|
66
|
+
creatorId: userId,
|
|
67
|
+
membersIds: [userId],
|
|
68
|
+
adminsIds: [userId],
|
|
69
|
+
plan: {
|
|
70
|
+
name: "FREE",
|
|
71
|
+
statue: "ACTIVE",
|
|
72
|
+
creatorId: userId
|
|
73
|
+
},
|
|
74
|
+
...organization
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new import_errors.GenericError("ORGANIZATION_CREATION_FAILED", { error });
|
|
79
|
+
}
|
|
67
80
|
};
|
|
68
81
|
const updateOrganizationById = async (organizationId, organization) => {
|
|
69
82
|
const updatedKeys = Object.keys(organization);
|
|
@@ -90,14 +103,48 @@ const deleteOrganizationById = async (organizationId) => {
|
|
|
90
103
|
}
|
|
91
104
|
return organization;
|
|
92
105
|
};
|
|
106
|
+
const saveStripeCustomerId = async (organization, customerId) => {
|
|
107
|
+
if (!organization) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
await import_organization.OrganizationModel.updateOne(
|
|
111
|
+
{ _id: organization._id },
|
|
112
|
+
{ $set: { plan: { customerId } } }
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
const updatePlan = async (organization, plan) => {
|
|
116
|
+
const updateOrganizationResult = await import_organization.OrganizationModel.updateOne(
|
|
117
|
+
{ _id: organization._id },
|
|
118
|
+
{ $set: { plan: { ...organization.plan, ...plan } } },
|
|
119
|
+
{ new: true }
|
|
120
|
+
);
|
|
121
|
+
if (updateOrganizationResult.matchedCount === 0) {
|
|
122
|
+
throw new import_errors.GenericError("ORGANIZATION_UPDATE_FAILED", {
|
|
123
|
+
organizationId: organization._id
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const updatedOrganization = await getOrganizationById(organization._id);
|
|
127
|
+
return updatedOrganization;
|
|
128
|
+
};
|
|
129
|
+
const getOrganizationByCustomerId = async (customerId) => {
|
|
130
|
+
const organization = await import_organization.OrganizationModel.findOne({
|
|
131
|
+
plan: {
|
|
132
|
+
customerId
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return organization;
|
|
136
|
+
};
|
|
93
137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
138
|
0 && (module.exports = {
|
|
95
139
|
countOrganizations,
|
|
96
140
|
createOrganization,
|
|
97
141
|
deleteOrganizationById,
|
|
98
142
|
findOrganizations,
|
|
143
|
+
getOrganizationByCustomerId,
|
|
99
144
|
getOrganizationById,
|
|
100
145
|
getOrganizationsByOwner,
|
|
101
|
-
|
|
146
|
+
saveStripeCustomerId,
|
|
147
|
+
updateOrganizationById,
|
|
148
|
+
updatePlan
|
|
102
149
|
});
|
|
103
150
|
//# sourceMappingURL=organization.service.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/organization.service.ts"],"sourcesContent":["import { OrganizationModel } from '@models/organization.model';\nimport { GenericError } from '@utils/errors';\nimport type { OrganizationFilters } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport {\n type OrganizationFields,\n validateOrganization,\n} from '@utils/validation/validateOrganization';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Organization,\n OrganizationCreationData,\n OrganizationDocument,\n} from '@/types/organization.types';\n\n/**\n * Finds organizations based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of organizations matching the filters.\n */\nexport const findOrganizations = async (\n filters: OrganizationFilters,\n skip: number,\n limit: number\n): Promise<OrganizationDocument[]> => {\n return await OrganizationModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Finds an organization by its ID.\n * @param organizationId - The ID of the organization to find.\n * @returns The organization matching the ID.\n */\nexport const getOrganizationById = async (\n organizationId: ObjectId | string\n): Promise<OrganizationDocument> => {\n const organization = await OrganizationModel.findById(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\n/**\n * Retrieves an organization by its owner.\n * @param userId - The ID of the user to find the organization.\n * @returns The organizations matching the user ID.\n */\nexport const getOrganizationsByOwner = async (\n userId: string | ObjectId\n): Promise<OrganizationDocument[] | null> => {\n const organization = await OrganizationModel.find({\n creatorId: userId,\n });\n\n return organization;\n};\n\n/**\n * Counts the total number of organizations that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of organizations.\n */\nexport const countOrganizations = async (\n filters: OrganizationFilters\n): Promise<number> => {\n const result = await OrganizationModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('ORGANIZATION_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new organization in the database.\n * @param organization - The organization data to create.\n * @returns The created organization.\n */\nexport const createOrganization = async (\n organization: OrganizationCreationData,\n userId: string | ObjectId\n): Promise<OrganizationDocument> => {\n const errors = validateOrganization(organization, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', { errors });\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/services/organization.service.ts"],"sourcesContent":["import { OrganizationModel } from '@models/organization.model';\nimport { GenericError } from '@utils/errors';\nimport type { OrganizationFilters } from '@utils/filtersAndPagination/getOrganizationFiltersAndPagination';\nimport {\n type OrganizationFields,\n validateOrganization,\n} from '@utils/validation/validateOrganization';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Organization,\n OrganizationCreationData,\n OrganizationDocument,\n} from '@/types/organization.types';\nimport type { Plan } from '@/types/plan.types';\n\n/**\n * Finds organizations based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of organizations matching the filters.\n */\nexport const findOrganizations = async (\n filters: OrganizationFilters,\n skip: number,\n limit: number\n): Promise<OrganizationDocument[]> => {\n return await OrganizationModel.find(filters).skip(skip).limit(limit);\n};\n\n/**\n * Finds an organization by its ID.\n * @param organizationId - The ID of the organization to find.\n * @returns The organization matching the ID.\n */\nexport const getOrganizationById = async (\n organizationId: ObjectId | string\n): Promise<OrganizationDocument> => {\n const organization = await OrganizationModel.findById(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\n/**\n * Retrieves an organization by its owner.\n * @param userId - The ID of the user to find the organization.\n * @returns The organizations matching the user ID.\n */\nexport const getOrganizationsByOwner = async (\n userId: string | ObjectId\n): Promise<OrganizationDocument[] | null> => {\n const organization = await OrganizationModel.find({\n creatorId: userId,\n });\n\n return organization;\n};\n\n/**\n * Counts the total number of organizations that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of organizations.\n */\nexport const countOrganizations = async (\n filters: OrganizationFilters\n): Promise<number> => {\n const result = await OrganizationModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('ORGANIZATION_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new organization in the database.\n * @param organization - The organization data to create.\n * @returns The created organization.\n */\nexport const createOrganization = async (\n organization: OrganizationCreationData,\n userId: string | ObjectId\n): Promise<OrganizationDocument> => {\n const errors = validateOrganization(organization, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', { errors });\n }\n\n try {\n const result = await OrganizationModel.create({\n creatorId: userId,\n membersIds: [userId],\n adminsIds: [userId],\n plan: {\n name: 'FREE',\n statue: 'ACTIVE',\n creatorId: userId,\n },\n ...organization,\n });\n\n return result;\n } catch (error) {\n throw new GenericError('ORGANIZATION_CREATION_FAILED', { error });\n }\n};\n\n/**\n * Updates an existing organization in the database by its ID.\n * @param organizationId - The ID of the organization to update.\n * @param organization - The updated organization data.\n * @returns The updated organization.\n */\nexport const updateOrganizationById = async (\n organizationId: ObjectId | string,\n organization: Partial<Organization>\n): Promise<OrganizationDocument> => {\n const updatedKeys = Object.keys(organization) as OrganizationFields;\n const errors = validateOrganization(organization, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('ORGANIZATION_INVALID_FIELDS', {\n organizationId,\n errors,\n });\n }\n\n const result = await OrganizationModel.updateOne(\n { _id: organizationId },\n organization\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('ORGANIZATION_UPDATE_FAILED', { organizationId });\n }\n\n return await getOrganizationById(organizationId);\n};\n\n/**\n * Deletes an organization from the database by its ID.\n * @param organizationId - The ID of the organization to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteOrganizationById = async (\n organizationId: ObjectId | string\n): Promise<OrganizationDocument> => {\n const organization =\n await OrganizationModel.findByIdAndDelete(organizationId);\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND', { organizationId });\n }\n\n return organization;\n};\n\nexport const saveStripeCustomerId = async (\n organization: Organization,\n customerId: string\n) => {\n if (!organization) {\n return null;\n }\n\n await OrganizationModel.updateOne(\n { _id: organization._id },\n { $set: { plan: { customerId } } }\n );\n};\n\n/**\n * Updates an existing plan in the database by its ID.\n * @param planId - The ID of the plan to update.\n * @param plan - The updated plan data.\n * @returns The updated plan.\n */\nexport const updatePlan = async (\n organization: Organization,\n plan: Partial<Plan>\n): Promise<OrganizationDocument | null> => {\n const updateOrganizationResult = await OrganizationModel.updateOne(\n { _id: organization._id },\n { $set: { plan: { ...organization.plan, ...plan } } },\n { new: true }\n );\n\n if (updateOrganizationResult.matchedCount === 0) {\n throw new GenericError('ORGANIZATION_UPDATE_FAILED', {\n organizationId: organization._id,\n });\n }\n\n const updatedOrganization = await getOrganizationById(organization._id);\n\n return updatedOrganization;\n};\n\n/**\n * Retrieves an organization by its customer ID.\n * @param customerId - The ID of the customer to find the organization.\n * @returns The organizations matching the customer ID.\n */\nexport const getOrganizationByCustomerId = async (\n customerId: string\n): Promise<OrganizationDocument | null> => {\n const organization = await OrganizationModel.findOne({\n plan: {\n customerId,\n },\n });\n\n return organization;\n};\n"],"mappings":"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","names":[]}
|
|
@@ -29,9 +29,7 @@ module.exports = __toCommonJS(project_service_exports);
|
|
|
29
29
|
var import_project = require('./../models/project.model.cjs');
|
|
30
30
|
var import_errors = require('./../utils/errors/index.cjs');
|
|
31
31
|
var import_validateProject = require('./../utils/validation/validateProject.cjs');
|
|
32
|
-
const findProjects = async (filters, skip = 0, limit = 100) =>
|
|
33
|
-
return await import_project.ProjectModel.find(filters).skip(skip).limit(limit);
|
|
34
|
-
};
|
|
32
|
+
const findProjects = async (filters, skip = 0, limit = 100) => await import_project.ProjectModel.find(filters).skip(skip).limit(limit);
|
|
35
33
|
const getProjectById = async (projectId) => {
|
|
36
34
|
const project = await import_project.ProjectModel.findById(projectId);
|
|
37
35
|
if (!project) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]>
|
|
1
|
+
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n if (project.oAuth2Access) {\n delete project.oAuth2Access;\n }\n\n const updatedKeys = Object.keys(project) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n const result = await ProjectModel.updateOne({ _id: projectId }, project);\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,oBAA6B;AAE7B,6BAGO;AAeA,MAAM,eAAe,OAC1B,SACA,OAAO,GACP,QAAQ,QAER,MAAM,4BAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AAOlD,MAAM,iBAAiB,OAC5B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,SAAS,SAAS;AAErD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;AAOO,MAAM,gBAAgB,OAC3B,YACoB;AACpB,QAAM,SAAS,MAAM,4BAAa,eAAe,OAAO;AAExD,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,2BAAa,wBAAwB,EAAE,QAAQ,CAAC;AAAA,EAC5D;AAEA,SAAO;AACT;AAOO,MAAM,gBAAgB,OAC3B,YAC6B;AAC7B,MAAK,QAA6B,cAAc;AAC9C,WAAQ,QAA6B;AAAA,EACvC;AAEA,QAAM,SAAS,UAAM,wCAAgB,SAAS,CAAC,MAAM,CAAC;AAEtD,MAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,0BAA0B,EAAE,OAAO,CAAC;AAAA,EAC7D;AAEA,SAAO,MAAM,4BAAa,OAAO,OAAO;AAC1C;AAQO,MAAM,oBAAoB,OAC/B,WACA,YAC6B;AAC7B,MAAI,QAAQ,cAAc;AACxB,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,cAAc,OAAO,KAAK,OAAO;AAEvC,QAAM,aAAS,wCAAgB,SAAS,WAAW;AAEnD,MAAI,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAClC,UAAM,IAAI,2BAAa,0BAA0B;AAAA,MAC/C;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM,4BAAa,UAAU,EAAE,KAAK,UAAU,GAAG,OAAO;AAEvE,MAAI,OAAO,iBAAiB,GAAG;AAC7B,UAAM,IAAI,2BAAa,yBAAyB,EAAE,UAAU,CAAC;AAAA,EAC/D;AAEA,SAAO,MAAM,eAAe,SAAS;AACvC;AAOO,MAAM,oBAAoB,OAC/B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,kBAAkB,SAAS;AAE9D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var sessionAuth_service_exports = {};
|
|
30
30
|
__export(sessionAuth_service_exports, {
|
|
31
|
-
activateUser: () => activateUser,
|
|
32
31
|
addSession: () => addSession,
|
|
33
32
|
addUserProvider: () => addUserProvider,
|
|
34
33
|
changeUserPassword: () => changeUserPassword,
|
|
@@ -51,6 +50,7 @@ __export(sessionAuth_service_exports, {
|
|
|
51
50
|
updateUserProvider: () => updateUserProvider
|
|
52
51
|
});
|
|
53
52
|
module.exports = __toCommonJS(sessionAuth_service_exports);
|
|
53
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
54
54
|
var import_logger = require('./../logger/index.cjs');
|
|
55
55
|
var import_cookies = require('./../utils/cookies.cjs');
|
|
56
56
|
var import_errors = require('./../utils/errors/index.cjs');
|
|
@@ -161,11 +161,6 @@ const clearProjectAuth = (res) => {
|
|
|
161
161
|
res.locals.project = null;
|
|
162
162
|
res.cookie(import_cookies.Cookies.JWT_PROJECT, "", (0, import_cookies.getClearCookieOptions)());
|
|
163
163
|
};
|
|
164
|
-
const activateUser = async (userId, secret) => {
|
|
165
|
-
return await updateUserProvider(userId, "email", {
|
|
166
|
-
secret
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
164
|
const generateSecret = (length) => {
|
|
170
165
|
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
171
166
|
return Array.from(
|
|
@@ -187,7 +182,13 @@ const resetUserPassword = async (userId, secret, newPassword) => {
|
|
|
187
182
|
if (!emailAndPasswordProvider) {
|
|
188
183
|
throw new import_errors.GenericError("USER_PROVIDER_NOT_FOUND", { userId });
|
|
189
184
|
}
|
|
190
|
-
if (emailAndPasswordProvider.secret
|
|
185
|
+
if (!emailAndPasswordProvider.secret) {
|
|
186
|
+
throw new import_errors.GenericError("USER_PROVIDER_SECRET_NOT_DEFINED", { userId });
|
|
187
|
+
}
|
|
188
|
+
if (!import_crypto.default.timingSafeEqual(
|
|
189
|
+
Buffer.from(emailAndPasswordProvider.secret),
|
|
190
|
+
Buffer.from(secret)
|
|
191
|
+
)) {
|
|
191
192
|
throw new import_errors.GenericError("USER_PROVIDER_SECRET_NOT_VALID", { userId });
|
|
192
193
|
}
|
|
193
194
|
const updatedUser = await updateUserProvider(userId, "email", {
|
|
@@ -337,13 +338,11 @@ const hashUserPassword = async (userWithPasswordNotHashed) => {
|
|
|
337
338
|
});
|
|
338
339
|
return { ...user, provider: userProvider };
|
|
339
340
|
};
|
|
340
|
-
const changeUserPassword = async (userId,
|
|
341
|
+
const changeUserPassword = async (userId, newPassword) => {
|
|
341
342
|
const user = await (0, import_user2.getUserById)(userId);
|
|
342
343
|
if (!user) {
|
|
343
344
|
throw new import_errors.GenericError("USER_NOT_FOUND", { userId });
|
|
344
345
|
}
|
|
345
|
-
const { email } = user;
|
|
346
|
-
await testUserPassword(email, oldPassword);
|
|
347
346
|
const updatedUser = await updateUserProvider(userId, "email", {
|
|
348
347
|
passwordHash: await (0, import_bcrypt.hash)(newPassword, await (0, import_bcrypt.genSalt)())
|
|
349
348
|
});
|
|
@@ -361,7 +360,6 @@ const resetPassword = async (userId, password) => {
|
|
|
361
360
|
};
|
|
362
361
|
// Annotate the CommonJS export names for ESM import in node:
|
|
363
362
|
0 && (module.exports = {
|
|
364
|
-
activateUser,
|
|
365
363
|
addSession,
|
|
366
364
|
addUserProvider,
|
|
367
365
|
changeUserPassword,
|