@intlayer/backend 3.0.3 → 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 +91 -18
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/organization.controller.cjs +140 -12
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +181 -31
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/projectAccessKey.controller.cjs +61 -10
- package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -1
- package/dist/cjs/controllers/sessionAuth.controller.cjs +291 -62
- 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 +49 -20
- 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 +16 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/oAuth2.middleware.cjs +10 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -1
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs +50 -10
- 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/routes/stripe.routes.cjs +42 -0
- 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/{middlewares/admin.middleware.cjs → schemas/plans.schema.cjs} +32 -20
- package/dist/cjs/schemas/plans.schema.cjs.map +1 -0
- package/dist/cjs/schemas/project.schema.cjs +14 -1
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/schemas/user.schema.cjs +5 -1
- package/dist/cjs/schemas/user.schema.cjs.map +1 -1
- package/dist/cjs/services/dictionary.service.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/oAuth2.service.cjs +16 -8
- package/dist/cjs/services/oAuth2.service.cjs.map +1 -1
- package/dist/cjs/services/organization.service.cjs +63 -8
- package/dist/cjs/services/organization.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +9 -5
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/projectAccessKey.service.cjs +42 -10
- package/dist/cjs/services/projectAccessKey.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 +201 -0
- package/dist/cjs/services/subscription.service.cjs.map +1 -0
- package/dist/cjs/services/user.service.cjs +1 -3
- package/dist/cjs/services/user.service.cjs.map +1 -1
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/types/organization.types.cjs.map +1 -1
- package/dist/cjs/types/plan.types.cjs +17 -0
- package/dist/cjs/types/plan.types.cjs.map +1 -0
- package/dist/cjs/types/project.types.cjs.map +1 -1
- package/dist/cjs/types/session.types.cjs.map +1 -1
- package/dist/cjs/types/user.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 +321 -9
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +19 -3
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/mapper/user.cjs.map +1 -1
- package/dist/cjs/utils/plan.cjs +75 -0
- package/dist/cjs/utils/plan.cjs.map +1 -0
- 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 +91 -18
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/organization.controller.mjs +140 -12
- package/dist/esm/controllers/organization.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +181 -31
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/projectAccessKey.controller.mjs +61 -10
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
- package/dist/esm/controllers/sessionAuth.controller.mjs +287 -61
- 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 +49 -20
- 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 +19 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/oAuth2.middleware.mjs +10 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +49 -9
- 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 +32 -0
- package/dist/esm/schemas/plans.schema.mjs.map +1 -0
- package/dist/esm/schemas/project.schema.mjs +13 -1
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/schemas/user.schema.mjs +5 -1
- package/dist/esm/schemas/user.schema.mjs.map +1 -1
- package/dist/esm/services/dictionary.service.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/oAuth2.service.mjs +16 -8
- package/dist/esm/services/oAuth2.service.mjs.map +1 -1
- package/dist/esm/services/organization.service.mjs +58 -7
- package/dist/esm/services/organization.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +9 -5
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/projectAccessKey.service.mjs +42 -10
- package/dist/esm/services/projectAccessKey.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 +178 -0
- package/dist/esm/services/subscription.service.mjs.map +1 -0
- package/dist/esm/services/user.service.mjs +1 -3
- package/dist/esm/services/user.service.mjs.map +1 -1
- package/dist/esm/types/plan.types.mjs +1 -0
- package/dist/esm/types/plan.types.mjs.map +1 -0
- 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 +321 -9
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/mapper/organization.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +17 -2
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mapper/user.mjs.map +1 -1
- package/dist/esm/utils/plan.mjs +50 -0
- package/dist/esm/utils/plan.mjs.map +1 -0
- 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 +9 -7
- 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 +28 -9
- 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 +2 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
- package/dist/types/middlewares/sessionAuth.middleware.d.ts +13 -7
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +1 -1
- package/dist/types/models/oAuth2.model.d.ts +1 -1
- package/dist/types/models/organization.model.d.ts +2 -1
- package/dist/types/models/organization.model.d.ts.map +1 -1
- package/dist/types/models/plan.moddel.d.ts +11 -0
- package/dist/types/models/plan.moddel.d.ts.map +1 -0
- package/dist/types/models/project.model.d.ts +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/dictionary.schema.d.ts +2 -2
- package/dist/types/schemas/oAuth2.schema.d.ts +2 -2
- package/dist/types/schemas/organization.schema.d.ts +3 -2
- package/dist/types/schemas/organization.schema.d.ts.map +1 -1
- package/dist/types/schemas/plans.schema.d.ts +16 -0
- package/dist/types/schemas/plans.schema.d.ts.map +1 -0
- package/dist/types/schemas/project.schema.d.ts +12 -3
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/user.schema.d.ts +2 -2
- package/dist/types/schemas/user.schema.d.ts.map +1 -1
- package/dist/types/services/dictionary.service.d.ts +9 -9
- package/dist/types/services/dictionary.service.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/oAuth2.service.d.ts +7 -5
- package/dist/types/services/oAuth2.service.d.ts.map +1 -1
- package/dist/types/services/organization.service.d.ts +27 -6
- package/dist/types/services/organization.service.d.ts.map +1 -1
- package/dist/types/services/plans.service.d.ts +35 -0
- package/dist/types/services/plans.service.d.ts.map +1 -0
- package/dist/types/services/project.service.d.ts +6 -6
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/projectAccessKey.service.d.ts +4 -4
- package/dist/types/services/projectAccessKey.service.d.ts.map +1 -1
- package/dist/types/services/sessionAuth.service.d.ts +9 -16
- package/dist/types/services/sessionAuth.service.d.ts.map +1 -1
- package/dist/types/services/subscription.service.d.ts +22 -0
- package/dist/types/services/subscription.service.d.ts.map +1 -0
- package/dist/types/services/user.service.d.ts +11 -19
- package/dist/types/services/user.service.d.ts.map +1 -1
- package/dist/types/types/dictionary.types.d.ts +2 -2
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/types/organization.types.d.ts +4 -2
- package/dist/types/types/organization.types.d.ts.map +1 -1
- package/dist/types/types/plan.types.d.ts +18 -0
- package/dist/types/types/plan.types.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +13 -2
- package/dist/types/types/project.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/types/user.types.d.ts +2 -1
- package/dist/types/types/user.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 +313 -1
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/mapper/organization.d.ts +1 -1
- package/dist/types/utils/mapper/organization.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts +10 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mapper/user.d.ts +1 -1
- package/dist/types/utils/mapper/user.d.ts.map +1 -1
- package/dist/types/utils/plan.d.ts +17 -0
- package/dist/types/utils/plan.d.ts.map +1 -0
- 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 +3 -0
- package/dist/types/webhooks/stripe.d.ts.map +1 -0
- package/dist/types/webhooks/stripe.webhook.d.ts +3 -0
- package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -0
- package/package.json +27 -24
- package/dist/cjs/middlewares/admin.middleware.cjs.map +0 -1
- package/dist/esm/middlewares/admin.middleware.mjs +0 -20
- package/dist/esm/middlewares/admin.middleware.mjs.map +0 -1
|
@@ -6,10 +6,9 @@ import {
|
|
|
6
6
|
createUser,
|
|
7
7
|
getUserByAccount
|
|
8
8
|
} from './../controllers/user.controller.mjs';
|
|
9
|
-
import { accessControlMiddleWare, AccessRule } from './../utils/accessControl.mjs';
|
|
10
9
|
import { Router } from "express";
|
|
11
10
|
const userRouter = Router();
|
|
12
|
-
const baseURL = `${process.env.
|
|
11
|
+
const baseURL = `${process.env.BACKEND_URL}/api/user`;
|
|
13
12
|
const userRoutes = {
|
|
14
13
|
getUsers: {
|
|
15
14
|
urlModel: "/",
|
|
@@ -45,31 +44,11 @@ const userRoutes = {
|
|
|
45
44
|
method: "GET"
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
|
-
userRouter.get(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
userRouter.put(
|
|
54
|
-
userRoutes.updateUser.urlModel,
|
|
55
|
-
accessControlMiddleWare(AccessRule.none),
|
|
56
|
-
updateUser
|
|
57
|
-
);
|
|
58
|
-
userRouter.post(
|
|
59
|
-
userRoutes.createUser.urlModel,
|
|
60
|
-
accessControlMiddleWare(AccessRule.admin),
|
|
61
|
-
createUser
|
|
62
|
-
);
|
|
63
|
-
userRouter.get(
|
|
64
|
-
userRoutes.getUserById.urlModel,
|
|
65
|
-
accessControlMiddleWare(AccessRule.authenticated),
|
|
66
|
-
getUserById
|
|
67
|
-
);
|
|
68
|
-
userRouter.get(
|
|
69
|
-
userRoutes.getUserByEmail.urlModel,
|
|
70
|
-
accessControlMiddleWare(AccessRule.authenticated),
|
|
71
|
-
getUserByEmail
|
|
72
|
-
);
|
|
47
|
+
userRouter.get(userRoutes.getUsers.urlModel, getUsers);
|
|
48
|
+
userRouter.put(userRoutes.updateUser.urlModel, updateUser);
|
|
49
|
+
userRouter.post(userRoutes.createUser.urlModel, createUser);
|
|
50
|
+
userRouter.get(userRoutes.getUserById.urlModel, getUserById);
|
|
51
|
+
userRouter.get(userRoutes.getUserByEmail.urlModel, getUserByEmail);
|
|
73
52
|
userRouter.get(userRoutes.getUserByAccount.urlModel, getUserByAccount);
|
|
74
53
|
export {
|
|
75
54
|
userRouter,
|
|
@@ -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,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AAGhB,MAAM,aAAqB,OAAO;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,QAAQ;AACrD,WAAW,IAAI,WAAW,WAAW,UAAU,UAAU;AACzD,WAAW,KAAK,WAAW,WAAW,UAAU,UAAU;AAC1D,WAAW,IAAI,WAAW,YAAY,UAAU,WAAW;AAC3D,WAAW,IAAI,WAAW,eAAe,UAAU,cAAc;AACjE,WAAW,IAAI,WAAW,iBAAiB,UAAU,gBAAgB;","names":[]}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
NAME_MIN_LENGTH
|
|
5
5
|
} from './../utils/validation/validateOrganization.mjs';
|
|
6
6
|
import { Schema } from "mongoose";
|
|
7
|
+
import { planSchema } from './plans.schema.mjs';
|
|
7
8
|
const organizationSchema = new Schema(
|
|
8
9
|
{
|
|
9
10
|
name: {
|
|
@@ -28,6 +29,10 @@ const organizationSchema = new Schema(
|
|
|
28
29
|
type: Schema.Types.ObjectId,
|
|
29
30
|
ref: "User",
|
|
30
31
|
required: true
|
|
32
|
+
},
|
|
33
|
+
plan: {
|
|
34
|
+
type: planSchema,
|
|
35
|
+
required: true
|
|
31
36
|
}
|
|
32
37
|
},
|
|
33
38
|
{
|
|
@@ -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,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;
|
|
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,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,SAAS,kBAAkB;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,OAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,CAAC,OAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,OAAO,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":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
const planSchema = new Schema(
|
|
3
|
+
{
|
|
4
|
+
type: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true,
|
|
7
|
+
enum: ["FREE", "PREMIUM", "ENTERPRISE"],
|
|
8
|
+
default: "FREE"
|
|
9
|
+
},
|
|
10
|
+
creatorId: {
|
|
11
|
+
type: Schema.Types.ObjectId,
|
|
12
|
+
ref: "User",
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
priceId: {
|
|
16
|
+
type: String
|
|
17
|
+
},
|
|
18
|
+
status: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
enum: ["INACTIVE", "ACTIVE", "ERROR", "CANCELLED"],
|
|
22
|
+
default: "INACTIVE"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
timestamps: true
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
export {
|
|
30
|
+
planSchema
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=plans.schema.mjs.map
|
|
@@ -0,0 +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 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,SAAS,cAAc;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,OAAO,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":[]}
|
|
@@ -4,6 +4,16 @@ import {
|
|
|
4
4
|
MEMBERS_MIN_LENGTH
|
|
5
5
|
} from './../utils/validation/validateProject.mjs';
|
|
6
6
|
import { Schema } from "mongoose";
|
|
7
|
+
const RightsSchema = new Schema({
|
|
8
|
+
read: { type: Boolean, required: true },
|
|
9
|
+
write: { type: Boolean, required: true },
|
|
10
|
+
admin: { type: Boolean, required: true }
|
|
11
|
+
});
|
|
12
|
+
const TokenRightsSchema = new Schema({
|
|
13
|
+
dictionary: { type: RightsSchema, required: true },
|
|
14
|
+
project: { type: RightsSchema, required: true },
|
|
15
|
+
organization: { type: RightsSchema, required: true }
|
|
16
|
+
});
|
|
7
17
|
const oAuth2AccessSchema = new Schema(
|
|
8
18
|
{
|
|
9
19
|
clientId: { type: String, required: true, unique: true },
|
|
@@ -11,7 +21,8 @@ const oAuth2AccessSchema = new Schema(
|
|
|
11
21
|
userId: { type: Schema.Types.ObjectId, ref: "User", required: true },
|
|
12
22
|
name: { type: String, required: true },
|
|
13
23
|
expiresAt: { type: Date },
|
|
14
|
-
accessToken: { type: [String], required: true }
|
|
24
|
+
accessToken: { type: [String], required: true },
|
|
25
|
+
rights: { type: TokenRightsSchema, required: true }
|
|
15
26
|
},
|
|
16
27
|
{
|
|
17
28
|
timestamps: true
|
|
@@ -54,6 +65,7 @@ const projectSchema = new Schema(
|
|
|
54
65
|
}
|
|
55
66
|
);
|
|
56
67
|
export {
|
|
68
|
+
TokenRightsSchema,
|
|
57
69
|
projectSchema
|
|
58
70
|
};
|
|
59
71
|
//# sourceMappingURL=project.schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/schemas/project.schema.ts"],"sourcesContent":["import {\n NAME_MIN_LENGTH,\n NAME_MAX_LENGTH,\n MEMBERS_MIN_LENGTH,\n} from '@utils/validation/validateProject';\nimport { Schema } from 'mongoose';\nimport { Project } from '@/types/project.types';\n\n// Define the oAuth2Access subdocument schema with timestamps\nconst oAuth2AccessSchema = new Schema(\n {\n clientId: { type: String, required: true, unique: true },\n clientSecret: { type: String, required: true },\n userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },\n name: { type: String, required: true },\n expiresAt: { type: Date },\n accessToken: { type: [String], required: true },\n },\n {\n timestamps: true,\n }\n);\n\nexport const projectSchema = new Schema<Project>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n oAuth2Access: [oAuth2AccessSchema],\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,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;
|
|
1
|
+
{"version":3,"sources":["../../../src/schemas/project.schema.ts"],"sourcesContent":["import {\n NAME_MIN_LENGTH,\n NAME_MAX_LENGTH,\n MEMBERS_MIN_LENGTH,\n} from '@utils/validation/validateProject';\nimport { Schema } from 'mongoose';\nimport { Project, Rights, TokenRights } from '@/types/project.types';\n\nconst RightsSchema = new Schema<Rights>({\n read: { type: Boolean, required: true },\n write: { type: Boolean, required: true },\n admin: { type: Boolean, required: true },\n});\n\nexport const TokenRightsSchema = new Schema<TokenRights>({\n dictionary: { type: RightsSchema, required: true },\n project: { type: RightsSchema, required: true },\n organization: { type: RightsSchema, required: true },\n});\n\n// Define the oAuth2Access subdocument schema with timestamps\nconst oAuth2AccessSchema = new Schema(\n {\n clientId: { type: String, required: true, unique: true },\n clientSecret: { type: String, required: true },\n userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },\n name: { type: String, required: true },\n expiresAt: { type: Date },\n accessToken: { type: [String], required: true },\n rights: { type: TokenRightsSchema, required: true },\n },\n {\n timestamps: true,\n }\n);\n\nexport const projectSchema = new Schema<Project>(\n {\n organizationId: {\n type: Schema.Types.ObjectId,\n ref: 'Organization',\n required: true,\n },\n name: {\n type: String,\n required: true,\n minlength: NAME_MIN_LENGTH,\n maxlength: NAME_MAX_LENGTH,\n },\n oAuth2Access: [oAuth2AccessSchema],\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,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AAGvB,MAAM,eAAe,IAAI,OAAe;AAAA,EACtC,MAAM,EAAE,MAAM,SAAS,UAAU,KAAK;AAAA,EACtC,OAAO,EAAE,MAAM,SAAS,UAAU,KAAK;AAAA,EACvC,OAAO,EAAE,MAAM,SAAS,UAAU,KAAK;AACzC,CAAC;AAEM,MAAM,oBAAoB,IAAI,OAAoB;AAAA,EACvD,YAAY,EAAE,MAAM,cAAc,UAAU,KAAK;AAAA,EACjD,SAAS,EAAE,MAAM,cAAc,UAAU,KAAK;AAAA,EAC9C,cAAc,EAAE,MAAM,cAAc,UAAU,KAAK;AACrD,CAAC;AAGD,MAAM,qBAAqB,IAAI;AAAA,EAC7B;AAAA,IACE,UAAU,EAAE,MAAM,QAAQ,UAAU,MAAM,QAAQ,KAAK;AAAA,IACvD,cAAc,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IAC7C,QAAQ,EAAE,MAAM,OAAO,MAAM,UAAU,KAAK,QAAQ,UAAU,KAAK;AAAA,IACnE,MAAM,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACrC,WAAW,EAAE,MAAM,KAAK;AAAA,IACxB,aAAa,EAAE,MAAM,CAAC,MAAM,GAAG,UAAU,KAAK;AAAA,IAC9C,QAAQ,EAAE,MAAM,mBAAmB,UAAU,KAAK;AAAA,EACpD;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;AAEO,MAAM,gBAAgB,IAAI;AAAA,EAC/B;AAAA,IACE,gBAAgB;AAAA,MACd,MAAM,OAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,IACA,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,IACb;AAAA,IACA,cAAc,CAAC,kBAAkB;AAAA,IACjC,YAAY;AAAA,MACV,MAAM,CAAC,OAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,CAAC,OAAO,MAAM,QAAQ;AAAA,MAC5B,KAAK;AAAA,MACL,UAAU;AAAA,MACV,WAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,MAAM,OAAO,MAAM;AAAA,MACnB,KAAK;AAAA,MACL,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA;AAAA,IACE,YAAY;AAAA,EACd;AACF;","names":[]}
|
|
@@ -33,7 +33,7 @@ const ProviderSchema = new Schema(
|
|
|
33
33
|
minlength: 6
|
|
34
34
|
},
|
|
35
35
|
emailValidated: {
|
|
36
|
-
type:
|
|
36
|
+
type: String
|
|
37
37
|
},
|
|
38
38
|
passwordHash: {
|
|
39
39
|
type: String
|
|
@@ -65,6 +65,10 @@ const userSchema = new Schema(
|
|
|
65
65
|
type: SessionSchema,
|
|
66
66
|
required: false
|
|
67
67
|
},
|
|
68
|
+
customerId: {
|
|
69
|
+
type: String,
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
68
72
|
provider: {
|
|
69
73
|
type: [ProviderSchema],
|
|
70
74
|
default: void 0,
|
|
@@ -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,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,OAAO,eAAe;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,UAAU,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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import { DictionaryModel } from '@models/dictionary.model';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport {\n type DictionaryFields,\n validateDictionary,\n} from '@utils/validation/validateDictionary';\nimport type { ObjectId } from 'mongoose';\nimport type { Dictionary, DictionaryData } from '@/types/dictionary.types';\n\n/**\n * Finds dictionaries 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 dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<Dictionary[]> =>\n await DictionaryModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<Dictionary> => {\n const dictionary = await DictionaryModel.findById(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<Dictionary> => {\n const dictionary = await DictionaryModel.findOne({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKey,\n projectId,\n });\n }\n\n return dictionary;\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKey: string[],\n projectId: string | ObjectId\n): Promise<Dictionary[]> => {\n const dictionaries = await DictionaryModel.find({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n return dictionaries;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<Dictionary> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<Dictionary> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryById(dictionaryId);\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n return await getDictionaryById(dictionaryId);\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<Dictionary> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n return await getDictionaryByKey(dictionaryKey, projectId);\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<Dictionary> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n"],"mappings":"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","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/services/dictionary.service.ts"],"sourcesContent":["import { DictionaryModel } from '@models/dictionary.model';\nimport { GenericError } from '@utils/errors';\nimport type { DictionaryFilters } from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport {\n type DictionaryFields,\n validateDictionary,\n} from '@utils/validation/validateDictionary';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Dictionary,\n DictionaryData,\n DictionaryDocument,\n} from '@/types/dictionary.types';\n\n/**\n * Finds dictionaries 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 dictionaries matching the filters.\n */\nexport const findDictionaries = async (\n filters: DictionaryFilters,\n skip = 0,\n limit = 100\n): Promise<DictionaryDocument[]> =>\n await DictionaryModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryId - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryById = async (\n dictionaryId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findById(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n\n/**\n * Finds a dictionary by its ID.\n * @param dictionaryKey - The ID of the dictionary to find.\n * @returns The dictionary matching the ID.\n */\nexport const getDictionaryByKey = async (\n dictionaryKey: string,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findOne({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', {\n dictionaryKey,\n projectId,\n });\n }\n\n return dictionary;\n};\n\nexport const getDictionariesByKeys = async (\n dictionaryKey: string[],\n projectId: string | ObjectId\n): Promise<DictionaryDocument[]> => {\n const dictionaries = await DictionaryModel.find({\n key: dictionaryKey,\n projectIds: projectId,\n });\n\n return dictionaries;\n};\n\nexport const getDictionariesKeys = async (\n projectId: string | ObjectId\n): Promise<string[]> => {\n const dictionaries = await DictionaryModel.find({\n projectIds: projectId,\n }).select('key');\n\n return dictionaries.map((dictionary) => dictionary.key);\n};\n\n/**\n * Counts the total number of dictionaries that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of dictionaries.\n */\nexport const countDictionaries = async (\n filters: DictionaryFilters\n): Promise<number> => {\n const result = await DictionaryModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('DICTIONARY_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new dictionary in the database.\n * @param dictionary - The dictionary data to create.\n * @returns The created dictionary.\n */\nexport const createDictionary = async (\n dictionary: DictionaryData\n): Promise<DictionaryDocument> => {\n const errors = await validateDictionary(dictionary);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n errors,\n });\n }\n\n return await DictionaryModel.create(dictionary);\n};\n\ntype GetExistingDictionaryResult = {\n existingDictionariesKey: string[];\n newDictionariesKey: string[];\n};\n\n/**\n * Gets the existing dictionaries from the provided list of keys.\n * @param dictionariesKeys - List of dictionary keys to check.\n * @param projectId - The ID of the project to check the dictionaries against.\n * @returns The existing dictionaries and the new dictionaries.\n */\nexport const getExistingDictionaryKey = async (\n dictionariesKeys: string[],\n projectId: string | ObjectId\n): Promise<GetExistingDictionaryResult> => {\n // Fetch dictionaries from the database where the key is in the provided list\n const existingDictionaries = await DictionaryModel.find({\n key: { $in: dictionariesKeys },\n projectIds: projectId,\n });\n\n // Map existing dictionaries to a LocalDictionary object\n const existingDictionariesKey: string[] = [];\n const newDictionariesKey: string[] = [];\n\n for (const key of dictionariesKeys) {\n const isDictionaryExist = existingDictionaries.some(\n (dictionary) => dictionary.key === key\n );\n\n if (isDictionaryExist) {\n existingDictionariesKey.push(key);\n } else {\n newDictionariesKey.push(key);\n }\n }\n\n return { existingDictionariesKey, newDictionariesKey };\n};\n\n/**\n * Updates an existing dictionary in the database by its ID.\n * @param dictionaryId - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryById = async (\n dictionaryId: string | ObjectId,\n dictionary: Partial<Dictionary>\n): Promise<DictionaryDocument> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryById(dictionaryId);\n\n const result = await DictionaryModel.updateOne(\n { _id: dictionaryId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryId });\n }\n\n return await getDictionaryById(dictionaryId);\n};\n\n/**\n * Updates an existing dictionary in the database by its key.\n * @param dictionaryKey - The ID of the dictionary to update.\n * @param dictionary - The updated dictionary data.\n * @returns The updated dictionary.\n */\nexport const updateDictionaryByKey = async (\n dictionaryKey: string,\n dictionary: Partial<Dictionary>,\n projectId: string | ObjectId\n): Promise<DictionaryDocument> => {\n const updatedKeys = Object.keys(dictionary) as DictionaryFields;\n const errors = validateDictionary(dictionary, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('DICTIONARY_INVALID_FIELDS', {\n dictionaryKey,\n projectId,\n errors,\n });\n }\n\n const existingDictionary = await getDictionaryByKey(dictionaryKey, projectId);\n\n const result = await DictionaryModel.updateOne(\n { key: dictionaryKey, projectIds: projectId },\n { ...dictionary, content: [existingDictionary.content, dictionary.content] }\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('DICTIONARY_UPDATE_FAILED', { dictionaryKey });\n }\n\n return await getDictionaryByKey(dictionaryKey, projectId);\n};\n\n/**\n * Deletes a dictionary from the database by its ID.\n * @param dictionaryId - The ID of the dictionary to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteDictionaryById = async (\n dictionaryId: string\n): Promise<DictionaryDocument> => {\n const dictionary = await DictionaryModel.findByIdAndDelete(dictionaryId);\n\n if (!dictionary) {\n throw new GenericError('DICTIONARY_NOT_FOUND', { dictionaryId });\n }\n\n return dictionary;\n};\n"],"mappings":"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","names":[]}
|
|
@@ -14,6 +14,21 @@ import {
|
|
|
14
14
|
ResetPasswordEmailFR,
|
|
15
15
|
ResetPasswordEmailES
|
|
16
16
|
} from './../emails/ResetUserPassword.mjs';
|
|
17
|
+
import {
|
|
18
|
+
SubscriptionPaymentCancellationEN,
|
|
19
|
+
SubscriptionPaymentCancellationFR,
|
|
20
|
+
SubscriptionPaymentCancellationES
|
|
21
|
+
} from './../emails/SubscriptionPaymentCancellation.mjs';
|
|
22
|
+
import {
|
|
23
|
+
SubscriptionPaymentErrorEN,
|
|
24
|
+
SubscriptionPaymentErrorFR,
|
|
25
|
+
SubscriptionPaymentErrorES
|
|
26
|
+
} from './../emails/SubscriptionPaymentError.mjs';
|
|
27
|
+
import {
|
|
28
|
+
SubscriptionPaymentSuccessEN,
|
|
29
|
+
SubscriptionPaymentSuccessFR,
|
|
30
|
+
SubscriptionPaymentSuccessES
|
|
31
|
+
} from './../emails/SubscriptionPaymentSuccess.mjs';
|
|
17
32
|
import {
|
|
18
33
|
ValidateUserEmailEN,
|
|
19
34
|
ValidateUserEmailFR,
|
|
@@ -27,65 +42,131 @@ import {
|
|
|
27
42
|
import { logger } from './../logger/index.mjs';
|
|
28
43
|
import { t } from "express-intlayer";
|
|
29
44
|
import { Resend } from "resend";
|
|
30
|
-
const getEmailComponents = () => ({
|
|
45
|
+
const getEmailComponents = (locale) => ({
|
|
31
46
|
invite: {
|
|
32
|
-
template: t(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
template: t(
|
|
48
|
+
{
|
|
49
|
+
en: InviteUserEmailEN,
|
|
50
|
+
fr: InviteUserEmailFR,
|
|
51
|
+
es: InviteUserEmailES
|
|
52
|
+
},
|
|
53
|
+
locale
|
|
54
|
+
),
|
|
55
|
+
subject: t(
|
|
56
|
+
{
|
|
57
|
+
en: "You have been invited to join Intlayer",
|
|
58
|
+
fr: "Vous \xEAtes invit\xE9 \xE0 rejoindre Intlayer",
|
|
59
|
+
es: "Has sido invitado a unirte a Intlayer"
|
|
60
|
+
},
|
|
61
|
+
locale
|
|
62
|
+
)
|
|
42
63
|
},
|
|
43
64
|
validate: {
|
|
44
|
-
template: t(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
template: t(
|
|
66
|
+
{
|
|
67
|
+
en: ValidateUserEmailEN,
|
|
68
|
+
fr: ValidateUserEmailFR,
|
|
69
|
+
es: ValidateUserEmailES
|
|
70
|
+
},
|
|
71
|
+
locale
|
|
72
|
+
),
|
|
73
|
+
subject: t(
|
|
74
|
+
{
|
|
75
|
+
en: "Validate your email for Intlayer",
|
|
76
|
+
fr: "Validez votre email pour Intlayer",
|
|
77
|
+
es: "Valida tu correo electr\xF3nico para Intlayer"
|
|
78
|
+
},
|
|
79
|
+
locale
|
|
80
|
+
)
|
|
54
81
|
},
|
|
55
82
|
resetPassword: {
|
|
83
|
+
template: t(
|
|
84
|
+
{
|
|
85
|
+
en: ResetPasswordEmailEN,
|
|
86
|
+
fr: ResetPasswordEmailFR,
|
|
87
|
+
es: ResetPasswordEmailES
|
|
88
|
+
},
|
|
89
|
+
locale
|
|
90
|
+
),
|
|
91
|
+
subject: t(
|
|
92
|
+
{
|
|
93
|
+
en: "Reset your password for Intlayer",
|
|
94
|
+
fr: "R\xE9initialisez votre mot de passe pour Intlayer",
|
|
95
|
+
es: "Restablece tu contrase\xF1a para Intlayer"
|
|
96
|
+
},
|
|
97
|
+
locale
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
welcome: {
|
|
101
|
+
template: t(
|
|
102
|
+
{
|
|
103
|
+
en: WelcomeEmailEN,
|
|
104
|
+
fr: WelcomeEmailFR,
|
|
105
|
+
es: WelcomeEmailES
|
|
106
|
+
},
|
|
107
|
+
locale
|
|
108
|
+
),
|
|
109
|
+
subject: t(
|
|
110
|
+
{
|
|
111
|
+
en: "Welcome to Intlayer!",
|
|
112
|
+
fr: "Bienvenue chez Intlayer!",
|
|
113
|
+
es: "\xA1Bienvenido a Intlayer!"
|
|
114
|
+
},
|
|
115
|
+
locale
|
|
116
|
+
)
|
|
117
|
+
},
|
|
118
|
+
passwordChangeConfirmation: {
|
|
119
|
+
template: t(
|
|
120
|
+
{
|
|
121
|
+
en: PasswordChangeConfirmationEmailEN,
|
|
122
|
+
fr: PasswordChangeConfirmationEmailFR,
|
|
123
|
+
es: PasswordChangeConfirmationEmailES
|
|
124
|
+
},
|
|
125
|
+
locale
|
|
126
|
+
),
|
|
127
|
+
subject: t(
|
|
128
|
+
{
|
|
129
|
+
en: "Your Intlayer password has been changed",
|
|
130
|
+
fr: "Votre mot de passe Intlayer a \xE9t\xE9 modifi\xE9",
|
|
131
|
+
es: "Tu contrase\xF1a de Intlayer ha sido cambiada"
|
|
132
|
+
},
|
|
133
|
+
locale
|
|
134
|
+
)
|
|
135
|
+
},
|
|
136
|
+
subscriptionPaymentSuccess: {
|
|
56
137
|
template: t({
|
|
57
|
-
en:
|
|
58
|
-
fr:
|
|
59
|
-
es:
|
|
138
|
+
en: SubscriptionPaymentSuccessEN,
|
|
139
|
+
fr: SubscriptionPaymentSuccessFR,
|
|
140
|
+
es: SubscriptionPaymentSuccessES
|
|
60
141
|
}),
|
|
61
142
|
subject: t({
|
|
62
|
-
en: "
|
|
63
|
-
fr: "
|
|
64
|
-
es: "
|
|
143
|
+
en: "Your payment for Intlayer subscription is confirmed",
|
|
144
|
+
fr: "Votre paiement pour l'abonnement Intlayer est confirm\xE9",
|
|
145
|
+
es: "Tu pago por la suscripci\xF3n de Intlayer ha sido confirmado"
|
|
65
146
|
})
|
|
66
147
|
},
|
|
67
|
-
|
|
148
|
+
subscriptionPaymentCancellation: {
|
|
68
149
|
template: t({
|
|
69
|
-
en:
|
|
70
|
-
fr:
|
|
71
|
-
es:
|
|
150
|
+
en: SubscriptionPaymentCancellationEN,
|
|
151
|
+
fr: SubscriptionPaymentCancellationFR,
|
|
152
|
+
es: SubscriptionPaymentCancellationES
|
|
72
153
|
}),
|
|
73
154
|
subject: t({
|
|
74
|
-
en: "
|
|
75
|
-
fr: "
|
|
76
|
-
es: "\
|
|
155
|
+
en: "Your Intlayer subscription has been canceled",
|
|
156
|
+
fr: "Votre abonnement Intlayer a \xE9t\xE9 annul\xE9",
|
|
157
|
+
es: "Tu suscripci\xF3n de Intlayer ha sido cancelada"
|
|
77
158
|
})
|
|
78
159
|
},
|
|
79
|
-
|
|
160
|
+
subscriptionPaymentError: {
|
|
80
161
|
template: t({
|
|
81
|
-
en:
|
|
82
|
-
fr:
|
|
83
|
-
es:
|
|
162
|
+
en: SubscriptionPaymentErrorEN,
|
|
163
|
+
fr: SubscriptionPaymentErrorFR,
|
|
164
|
+
es: SubscriptionPaymentErrorES
|
|
84
165
|
}),
|
|
85
166
|
subject: t({
|
|
86
|
-
en: "
|
|
87
|
-
fr: "
|
|
88
|
-
es: "
|
|
167
|
+
en: "There was an issue with your Intlayer subscription payment",
|
|
168
|
+
fr: "Un probl\xE8me est survenu avec votre paiement pour l'abonnement Intlayer",
|
|
169
|
+
es: "Hubo un problema con el pago de tu suscripci\xF3n de Intlayer"
|
|
89
170
|
})
|
|
90
171
|
}
|
|
91
172
|
});
|
|
@@ -93,15 +174,16 @@ const sendEmail = async ({
|
|
|
93
174
|
type,
|
|
94
175
|
to,
|
|
95
176
|
subject,
|
|
177
|
+
locale,
|
|
96
178
|
...props
|
|
97
179
|
}) => {
|
|
98
180
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
99
|
-
const emailComponents = getEmailComponents();
|
|
181
|
+
const emailComponents = getEmailComponents(locale);
|
|
100
182
|
const { template, subject: baseSubject } = emailComponents[type];
|
|
101
183
|
const EmailComponent = template;
|
|
102
184
|
const react = /* @__PURE__ */ jsx(EmailComponent, { ...props });
|
|
103
185
|
await resend.emails.send({
|
|
104
|
-
from: "no-replay@intlayer.org",
|
|
186
|
+
from: "Intlayer <no-replay@intlayer.org>",
|
|
105
187
|
to,
|
|
106
188
|
subject: subject ?? baseSubject,
|
|
107
189
|
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":[]}
|
|
@@ -29,7 +29,12 @@ const getClientAndProjectByClientId = async (clientId) => {
|
|
|
29
29
|
clientSecret: oAuth2Access.clientSecret,
|
|
30
30
|
grants: ["client_credentials"]
|
|
31
31
|
};
|
|
32
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
client: formattedClient,
|
|
34
|
+
oAuth2Access,
|
|
35
|
+
rights: oAuth2Access.rights,
|
|
36
|
+
project
|
|
37
|
+
};
|
|
33
38
|
};
|
|
34
39
|
const getClient = async (clientId, clientSecret) => {
|
|
35
40
|
const result = await getClientAndProjectByClientId(clientId);
|
|
@@ -42,7 +47,7 @@ const getClient = async (clientId, clientSecret) => {
|
|
|
42
47
|
}
|
|
43
48
|
return client;
|
|
44
49
|
};
|
|
45
|
-
const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
50
|
+
const formatOAuth2Token = (token, client, user, project, organization, rights) => {
|
|
46
51
|
const { clientId, userId, ...restToken } = token;
|
|
47
52
|
if (String(userId) !== String(user._id)) {
|
|
48
53
|
throw new GenericError("USER_ID_MISMATCH");
|
|
@@ -54,7 +59,8 @@ const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
|
54
59
|
organization,
|
|
55
60
|
project,
|
|
56
61
|
accessToken: token.accessToken,
|
|
57
|
-
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99")
|
|
62
|
+
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99"),
|
|
63
|
+
rights
|
|
58
64
|
};
|
|
59
65
|
return formattedToken;
|
|
60
66
|
};
|
|
@@ -87,7 +93,8 @@ const saveToken = async (token, client, user) => {
|
|
|
87
93
|
client,
|
|
88
94
|
user,
|
|
89
95
|
project,
|
|
90
|
-
organization
|
|
96
|
+
organization,
|
|
97
|
+
token.rights
|
|
91
98
|
);
|
|
92
99
|
return formattedResult;
|
|
93
100
|
};
|
|
@@ -107,7 +114,7 @@ const getAccessToken = async (accessToken) => {
|
|
|
107
114
|
if (!result) {
|
|
108
115
|
return false;
|
|
109
116
|
}
|
|
110
|
-
const { client, project } = result;
|
|
117
|
+
const { client, project, rights } = result;
|
|
111
118
|
const organization = await getOrganizationById(project.organizationId);
|
|
112
119
|
if (!organization) {
|
|
113
120
|
return false;
|
|
@@ -117,7 +124,8 @@ const getAccessToken = async (accessToken) => {
|
|
|
117
124
|
client,
|
|
118
125
|
user,
|
|
119
126
|
project,
|
|
120
|
-
organization
|
|
127
|
+
organization,
|
|
128
|
+
rights
|
|
121
129
|
);
|
|
122
130
|
return formattedAccessToken;
|
|
123
131
|
};
|
|
@@ -130,8 +138,8 @@ const getUserFromClient = async (client) => {
|
|
|
130
138
|
if (!userId) {
|
|
131
139
|
return false;
|
|
132
140
|
}
|
|
133
|
-
const user = getUserById(userId);
|
|
134
|
-
return user;
|
|
141
|
+
const user = await getUserById(userId);
|
|
142
|
+
return user ?? false;
|
|
135
143
|
};
|
|
136
144
|
const verifyScope = async (_token, _scope, _callback) => {
|
|
137
145
|
return true;
|