@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
|
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqNgB;AApNhB,6BAIO;AACP,wCAIO;AACP,+BAIO;AAEP,6CAIO;AACP,sCAIO;AACP,wCAIO;AACP,+BAIO;AACP,qBAIO;AAEP,oBAAuB;AACvB,8BAAkB;AAGlB,oBAAuB;AAUvB,MAAM,qBAAqB,CAAC,YACzB;AAAA,EACC,QAAQ;AAAA,IACN,cAAU;AAAA,MACR;AAAA,QACE,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,MACA;AAAA,IACF;AAAA,IACA,aAAS;AAAA,MACP;AAAA,QACE,IAA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S,2BAAE;AAAA,MACT,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA,EACA,iCAAiC;AAAA,IAC/B,cAAU,2BAAE;AAAA,MACV,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,IACD,aAAS,2BAAE;AAAA,MACT,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA,EACA,0BAA0B;AAAA,IACxB,cAAU,2BAAE;AAAA,MACV,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,IACD,aAAS,2BAAE;AAAA,MACT,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AACF;AAWK,MAAM,YAAY,OAA4B;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,SAAS,IAAI,qBAAO,QAAQ,IAAI,cAAc;AAEpD,QAAM,kBAAkB,mBAAmB,MAAM;AAEjD,QAAM,EAAE,UAAU,SAAS,YAAY,IAAI,gBAAgB,IAAI;AAI/D,QAAM,iBAAqC;AAE3C,QAAM,QAAQ,4CAAC,kBAAgB,GAAI,OAAe;AAElD,QAAM,OAAO,OACV,KAAK;AAAA,IACJ,MAAM;AAAA,IACN;AAAA,IACA,SAAS,WAAW;AAAA,IACpB;AAAA,EACF,CAAC,EACA,MAAM,CAAC,QAAQ,qBAAO,MAAM,GAAG,CAAC;AAEnC,uBAAO,KAAK,cAAc,IAAI,OAAO,EAAE,EAAE;AAC3C;","names":[]}
|
|
@@ -60,7 +60,12 @@ const getClientAndProjectByClientId = async (clientId) => {
|
|
|
60
60
|
clientSecret: oAuth2Access.clientSecret,
|
|
61
61
|
grants: ["client_credentials"]
|
|
62
62
|
};
|
|
63
|
-
return {
|
|
63
|
+
return {
|
|
64
|
+
client: formattedClient,
|
|
65
|
+
oAuth2Access,
|
|
66
|
+
rights: oAuth2Access.rights,
|
|
67
|
+
project
|
|
68
|
+
};
|
|
64
69
|
};
|
|
65
70
|
const getClient = async (clientId, clientSecret) => {
|
|
66
71
|
const result = await getClientAndProjectByClientId(clientId);
|
|
@@ -73,7 +78,7 @@ const getClient = async (clientId, clientSecret) => {
|
|
|
73
78
|
}
|
|
74
79
|
return client;
|
|
75
80
|
};
|
|
76
|
-
const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
81
|
+
const formatOAuth2Token = (token, client, user, project, organization, rights) => {
|
|
77
82
|
const { clientId, userId, ...restToken } = token;
|
|
78
83
|
if (String(userId) !== String(user._id)) {
|
|
79
84
|
throw new import_errors.GenericError("USER_ID_MISMATCH");
|
|
@@ -85,7 +90,8 @@ const formatOAuth2Token = (token, client, user, project, organization) => {
|
|
|
85
90
|
organization,
|
|
86
91
|
project,
|
|
87
92
|
accessToken: token.accessToken,
|
|
88
|
-
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99")
|
|
93
|
+
accessTokenExpiresAt: token.accessTokenExpiresAt ?? /* @__PURE__ */ new Date("999-99-99"),
|
|
94
|
+
rights
|
|
89
95
|
};
|
|
90
96
|
return formattedToken;
|
|
91
97
|
};
|
|
@@ -118,7 +124,8 @@ const saveToken = async (token, client, user) => {
|
|
|
118
124
|
client,
|
|
119
125
|
user,
|
|
120
126
|
project,
|
|
121
|
-
organization
|
|
127
|
+
organization,
|
|
128
|
+
token.rights
|
|
122
129
|
);
|
|
123
130
|
return formattedResult;
|
|
124
131
|
};
|
|
@@ -138,7 +145,7 @@ const getAccessToken = async (accessToken) => {
|
|
|
138
145
|
if (!result) {
|
|
139
146
|
return false;
|
|
140
147
|
}
|
|
141
|
-
const { client, project } = result;
|
|
148
|
+
const { client, project, rights } = result;
|
|
142
149
|
const organization = await (0, import_organization.getOrganizationById)(project.organizationId);
|
|
143
150
|
if (!organization) {
|
|
144
151
|
return false;
|
|
@@ -148,7 +155,8 @@ const getAccessToken = async (accessToken) => {
|
|
|
148
155
|
client,
|
|
149
156
|
user,
|
|
150
157
|
project,
|
|
151
|
-
organization
|
|
158
|
+
organization,
|
|
159
|
+
rights
|
|
152
160
|
);
|
|
153
161
|
return formattedAccessToken;
|
|
154
162
|
};
|
|
@@ -161,8 +169,8 @@ const getUserFromClient = async (client) => {
|
|
|
161
169
|
if (!userId) {
|
|
162
170
|
return false;
|
|
163
171
|
}
|
|
164
|
-
const user = (0, import_user.getUserById)(userId);
|
|
165
|
-
return user;
|
|
172
|
+
const user = await (0, import_user.getUserById)(userId);
|
|
173
|
+
return user ?? false;
|
|
166
174
|
};
|
|
167
175
|
const verifyScope = async (_token, _scope, _callback) => {
|
|
168
176
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import { randomBytes } from 'crypto';\nimport { OAuth2AccessTokenModel } from '@models/oAuth2.model';\nimport { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport { getTokenExpireAt } from '@utils/oAuth2';\nimport { Client, User, Token as OAuth2Token, Callback } from 'oauth2-server';\nimport { Token } from '../schemas/oAuth2.schema';\nimport { getOrganizationById } from './organization.service';\nimport { getUserById } from './user.service';\nimport { Organization } from '@/types/organization.types';\nimport { OAuth2Access, Project } from '@/types/project.types';\n\n/**\n * Function to generate client credentials\n *\n * @returns The client id and client secret\n */\nexport const generateClientCredentials = (): {\n clientId: string;\n clientSecret: string;\n} => {\n const clientId = randomBytes(16).toString('hex'); // Generate a 16 character hexadecimal string\n const clientSecret = randomBytes(32).toString('hex'); // Generate a 32 character hexadecimal string\n\n return { clientId, clientSecret };\n};\n\n/**\n * Method to get the client and the project\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The an object containing the client and the project or false if not found\n */\nexport const getClientAndProjectByClientId = async (\n clientId: string\n): Promise<\n {
|
|
1
|
+
{"version":3,"sources":["../../../src/services/oAuth2.service.ts"],"sourcesContent":["import { randomBytes } from 'crypto';\nimport { OAuth2AccessTokenModel } from '@models/oAuth2.model';\nimport { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport { getTokenExpireAt } from '@utils/oAuth2';\nimport { Client, User, Token as OAuth2Token, Callback } from 'oauth2-server';\nimport { Token } from '../schemas/oAuth2.schema';\nimport { getOrganizationById } from './organization.service';\nimport { getUserById } from './user.service';\nimport { UserDocument } from '@/export';\nimport { Organization } from '@/types/organization.types';\nimport { OAuth2Access, Project, ProjectDocument } from '@/types/project.types';\n\n/**\n * Function to generate client credentials\n *\n * @returns The client id and client secret\n */\nexport const generateClientCredentials = (): {\n clientId: string;\n clientSecret: string;\n} => {\n const clientId = randomBytes(16).toString('hex'); // Generate a 16 character hexadecimal string\n const clientSecret = randomBytes(32).toString('hex'); // Generate a 32 character hexadecimal string\n\n return { clientId, clientSecret };\n};\n\n/**\n * Method to get the client and the project\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The an object containing the client, the rights and the project or false if not found\n */\nexport const getClientAndProjectByClientId = async (\n clientId: string\n): Promise<\n | {\n client: Client;\n oAuth2Access: OAuth2Access;\n project: ProjectDocument;\n rights: Token['rights'];\n }\n | false\n> => {\n const project = await ProjectModel.findOne({\n 'oAuth2Access.clientId': clientId,\n });\n\n if (!project) {\n return false;\n }\n\n const oAuth2Access = project.oAuth2Access.find(\n (access) => access.clientId === clientId\n );\n\n if (!oAuth2Access) {\n return false;\n }\n\n const formattedClient: Client = {\n id: oAuth2Access.clientId,\n clientId,\n clientSecret: oAuth2Access.clientSecret,\n grants: ['client_credentials'],\n };\n\n return {\n client: formattedClient,\n oAuth2Access,\n rights: oAuth2Access.rights,\n project,\n };\n};\n\n/**\n * Get the client and verify that the client secret is correct\n *\n * @param clientId - The client id\n * @param clientSecret - The client secret\n * @returns The client or false if not found\n */\nexport const getClient = async (\n clientId: string,\n clientSecret: string\n): Promise<Client | false> => {\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client } = result;\n\n if (!client || client.clientSecret !== clientSecret) {\n return false;\n }\n\n return client;\n};\n\n/**\n * Format an OAuth2Token\n *\n * @param token\n * @param client\n * @param user\n * @param project\n * @param organization\n * @returns\n */\nexport const formatOAuth2Token = (\n token: Token,\n client: Client,\n user: User,\n project: Project,\n organization: Organization,\n rights: Token['rights']\n): OAuth2Token => {\n const { clientId, userId, ...restToken } = token;\n\n if (String(userId) !== String(user._id)) {\n throw new GenericError('USER_ID_MISMATCH');\n }\n\n const formattedToken: OAuth2Token = {\n ...restToken,\n client,\n user,\n organization,\n project,\n accessToken: token.accessToken,\n accessTokenExpiresAt: token.accessTokenExpiresAt ?? new Date('999-99-99'),\n rights,\n };\n\n return formattedToken;\n};\n\n/**\n * Format a auth token for the database\n *\n * @param token - The oAuth2 token to format\n * @param clientId - The client ID\n * @param userId - The user ID\n * @returns\n */\nexport const formatDBToken = (\n token: OAuth2Token,\n clientId: Client['id'],\n userId: User['_id']\n): Token => {\n const formattedToken: Token = {\n clientId: clientId,\n userId: userId,\n accessToken: token.accessToken,\n expiresIn: token.accessTokenExpiresAt ?? getTokenExpireAt(),\n };\n\n return formattedToken;\n};\n\n/**\n * Method to save the token\n *\n * @param token - The token\n * @param client - The client\n * @param user - The user\n * @returns The saved token or false if not saved\n */\nexport const saveToken = async (\n token: OAuth2Token,\n client: Client,\n user: User\n): Promise<OAuth2Token | false> => {\n const formattedAccessToken: Token = formatDBToken(token, client.id, user._id);\n\n const result = await OAuth2AccessTokenModel.create(formattedAccessToken);\n\n if (!result) {\n return false;\n }\n\n const result2 = await getClientAndProjectByClientId(result.clientId);\n\n if (!result2) {\n return false;\n }\n\n const { project } = result2;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedResult = formatOAuth2Token(\n formattedAccessToken,\n client,\n user,\n project,\n organization,\n token.rights\n );\n return formattedResult;\n};\n\n/**\n * Method to get the access token\n *\n * @param accessToken - The access token\n * @returns The access token or false if not found\n */\nexport const getAccessToken = async (\n accessToken: string\n): Promise<OAuth2Token | false> => {\n const token = await OAuth2AccessTokenModel.findOne({\n accessToken,\n });\n\n if (!token) {\n return false;\n }\n\n const { userId, clientId } = token;\n\n const user = await getUserById(userId);\n\n if (!user) {\n return false;\n }\n\n const result = await getClientAndProjectByClientId(clientId);\n\n if (!result) {\n return false;\n }\n\n const { client, project, rights } = result;\n\n const organization = await getOrganizationById(project.organizationId);\n\n if (!organization) {\n return false;\n }\n\n const formattedAccessToken = formatOAuth2Token(\n token,\n client,\n user,\n project,\n organization,\n rights\n );\n\n return formattedAccessToken;\n};\n\n/**\n * Method to get the user from the client\n *\n * @param client - The client\n * @returns The user or false if not found\n */\nexport const getUserFromClient = async (\n client: Client\n): Promise<UserDocument | false> => {\n const response = await getClientAndProjectByClientId(client.id);\n\n if (!response) {\n return false;\n }\n\n const { userId } = response.oAuth2Access;\n\n if (!userId) {\n return false;\n }\n\n const user = await getUserById(userId);\n\n return user ?? false;\n};\n\n/**\n * Method to verify the permissions (grants)\n *\n * @param token - The token\n * @param scope - The scope\n * @returns True if the token has the required scope, false otherwise\n */\nexport const verifyScope = async (\n _token: OAuth2Token,\n _scope: string,\n _callback?: Callback<boolean> | undefined\n): Promise<boolean> => {\n // Implement the verification of scopes if necessary\n return true;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4B;AAC5B,oBAAuC;AACvC,qBAA6B;AAC7B,oBAA6B;AAC7B,IAAAA,iBAAiC;AAGjC,0BAAoC;AACpC,kBAA4B;AAUrB,MAAM,4BAA4B,MAGpC;AACH,QAAM,eAAW,2BAAY,EAAE,EAAE,SAAS,KAAK;AAC/C,QAAM,mBAAe,2BAAY,EAAE,EAAE,SAAS,K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AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAQO,MAAM,oBAAoB,OAC/B,WACkC;AAClC,QAAM,WAAW,MAAM,8BAA8B,OAAO,EAAE;AAE9D,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,IAAI,SAAS;AAE5B,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,UAAM,yBAAY,MAAM;AAErC,SAAO,QAAQ;AACjB;AASO,MAAM,cAAc,OACzB,QACA,QACA,cACqB;AAErB,SAAO;AACT;","names":["import_oAuth2"]}
|
|
@@ -22,8 +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,
|
|
28
|
+
saveStripeCustomerId: () => saveStripeCustomerId,
|
|
29
|
+
updateOrganizationById: () => updateOrganizationById,
|
|
30
|
+
updatePlan: () => updatePlan
|
|
27
31
|
});
|
|
28
32
|
module.exports = __toCommonJS(organization_service_exports);
|
|
29
33
|
var import_organization = require('./../models/organization.model.cjs');
|
|
@@ -39,6 +43,12 @@ const getOrganizationById = async (organizationId) => {
|
|
|
39
43
|
}
|
|
40
44
|
return organization;
|
|
41
45
|
};
|
|
46
|
+
const getOrganizationsByOwner = async (userId) => {
|
|
47
|
+
const organization = await import_organization.OrganizationModel.find({
|
|
48
|
+
creatorId: userId
|
|
49
|
+
});
|
|
50
|
+
return organization;
|
|
51
|
+
};
|
|
42
52
|
const countOrganizations = async (filters) => {
|
|
43
53
|
const result = await import_organization.OrganizationModel.countDocuments(filters);
|
|
44
54
|
if (typeof result === "undefined") {
|
|
@@ -51,12 +61,22 @@ const createOrganization = async (organization, userId) => {
|
|
|
51
61
|
if (Object.keys(errors).length > 0) {
|
|
52
62
|
throw new import_errors.GenericError("ORGANIZATION_INVALID_FIELDS", { errors });
|
|
53
63
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
80
|
};
|
|
61
81
|
const updateOrganizationById = async (organizationId, organization) => {
|
|
62
82
|
const updatedKeys = Object.keys(organization);
|
|
@@ -83,13 +103,48 @@ const deleteOrganizationById = async (organizationId) => {
|
|
|
83
103
|
}
|
|
84
104
|
return organization;
|
|
85
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
|
+
};
|
|
86
137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
138
|
0 && (module.exports = {
|
|
88
139
|
countOrganizations,
|
|
89
140
|
createOrganization,
|
|
90
141
|
deleteOrganizationById,
|
|
91
142
|
findOrganizations,
|
|
143
|
+
getOrganizationByCustomerId,
|
|
92
144
|
getOrganizationById,
|
|
93
|
-
|
|
145
|
+
getOrganizationsByOwner,
|
|
146
|
+
saveStripeCustomerId,
|
|
147
|
+
updateOrganizationById,
|
|
148
|
+
updatePlan
|
|
94
149
|
});
|
|
95
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} 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<
|
|
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAkC;AAClC,oBAA6B;AAE7B,kCAGO;AAgBA,MAAM,oBAAoB,OAC/B,SACA,MACA,UACoC;AACpC,SAAO,MAAM,sCAAkB,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AACrE;AAOO,MAAM,sBAAsB,OACjC,mBACkC;AAClC,QAAM,eAAe,MAAM,sCAAkB,SAAS,cAAc;AAEpE,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,2BAAa,0BAA0B,EAAE,eAAe,CAAC;AAAA,EACrE;AAEA,SAAO;AACT;AAOO,MAAM,0BAA0B,OACrC,WAC2C;AAC3C,QAAM,eAAe,MAAM,sCAAkB,KAAK;AAAA,IAChD,WAAW;AAAA,EACb,CAAC;AAED,SAAO;AACT;AAOO,MAAM,qBAAqB,OAChC,YACoB;AACpB,QAAM,SAAS,MAAM,sCAAkB,eAAe,OAAO;AAE7D,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,2BAAa,6BAA6B,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;AAEA,SAAO;AACT;AAEO,MAAM,uBAAuB,OAClC,cACA,eACG;AACH,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,sCAAkB;AAAA,IACtB,EAAE,KAAK,aAAa,IAAI;AAAA,IACxB,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE;AAAA,EACnC;AACF;AAQO,MAAM,aAAa,OACxB,cACA,SACyC;AACzC,QAAM,2BAA2B,MAAM,sCAAkB;AAAA,IACvD,EAAE,KAAK,aAAa,IAAI;AAAA,IACxB,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,MAAM,GAAG,KAAK,EAAE,EAAE;AAAA,IACpD,EAAE,KAAK,KAAK;AAAA,EACd;AAEA,MAAI,yBAAyB,iBAAiB,GAAG;AAC/C,UAAM,IAAI,2BAAa,8BAA8B;AAAA,MACnD,gBAAgB,aAAa;AAAA,IAC/B,CAAC;AAAA,EACH;AAEA,QAAM,sBAAsB,MAAM,oBAAoB,aAAa,GAAG;AAEtE,SAAO;AACT;AAOO,MAAM,8BAA8B,OACzC,eACyC;AACzC,QAAM,eAAe,MAAM,sCAAkB,QAAQ;AAAA,IACnD,MAAM;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -29,13 +29,11 @@ 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) {
|
|
38
|
-
throw new import_errors.GenericError("
|
|
36
|
+
throw new import_errors.GenericError("PROJECT_NOT_DEFINED", { projectId });
|
|
39
37
|
}
|
|
40
38
|
return project;
|
|
41
39
|
};
|
|
@@ -47,6 +45,9 @@ const countProjects = async (filters) => {
|
|
|
47
45
|
return result;
|
|
48
46
|
};
|
|
49
47
|
const createProject = async (project) => {
|
|
48
|
+
if (project.oAuth2Access) {
|
|
49
|
+
delete project.oAuth2Access;
|
|
50
|
+
}
|
|
50
51
|
const errors = await (0, import_validateProject.validateProject)(project, ["name"]);
|
|
51
52
|
if (Object.keys(errors).length > 0) {
|
|
52
53
|
throw new import_errors.GenericError("PROJECT_INVALID_FIELDS", { errors });
|
|
@@ -54,6 +55,9 @@ const createProject = async (project) => {
|
|
|
54
55
|
return await import_project.ProjectModel.create(project);
|
|
55
56
|
};
|
|
56
57
|
const updateProjectById = async (projectId, project) => {
|
|
58
|
+
if (project.oAuth2Access) {
|
|
59
|
+
delete project.oAuth2Access;
|
|
60
|
+
}
|
|
57
61
|
const updatedKeys = Object.keys(project);
|
|
58
62
|
const errors = (0, import_validateProject.validateProject)(project, updatedKeys);
|
|
59
63
|
if (Object.keys(errors).length > 0) {
|
|
@@ -71,7 +75,7 @@ const updateProjectById = async (projectId, project) => {
|
|
|
71
75
|
const deleteProjectById = async (projectId) => {
|
|
72
76
|
const project = await import_project.ProjectModel.findByIdAndDelete(projectId);
|
|
73
77
|
if (!project) {
|
|
74
|
-
throw new import_errors.GenericError("
|
|
78
|
+
throw new import_errors.GenericError("PROJECT_NOT_DEFINED", { projectId });
|
|
75
79
|
}
|
|
76
80
|
return project;
|
|
77
81
|
};
|
|
@@ -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 {
|
|
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,WA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