@intlayer/backend 7.5.10 → 7.5.11
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/assets/utils/AI/askDocQuestion/embeddings/docs/en/cli/ci.json +3080 -0
- package/dist/assets/utils/AI/askDocQuestion/embeddings/docs/en/cli/list_projects.json +1 -0
- package/dist/esm/controllers/bitbucket.controller.mjs +77 -0
- package/dist/esm/controllers/bitbucket.controller.mjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +20 -0
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/github.controller.mjs.map +1 -1
- package/dist/esm/controllers/gitlab.controller.mjs +77 -0
- package/dist/esm/controllers/gitlab.controller.mjs.map +1 -0
- package/dist/esm/controllers/project.controller.mjs +109 -2
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/export.mjs +3 -1
- package/dist/esm/index.mjs +5 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/routes/bitbucket.routes.mjs +43 -0
- package/dist/esm/routes/bitbucket.routes.mjs.map +1 -0
- package/dist/esm/routes/gitlab.routes.mjs +43 -0
- package/dist/esm/routes/gitlab.routes.mjs.map +1 -0
- package/dist/esm/routes/project.routes.mjs +25 -1
- package/dist/esm/routes/project.routes.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +39 -4
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/services/bitbucket.service.mjs +173 -0
- package/dist/esm/services/bitbucket.service.mjs.map +1 -0
- package/dist/esm/services/ci.service.mjs +134 -0
- package/dist/esm/services/ci.service.mjs.map +1 -0
- package/dist/esm/services/github.service.mjs +90 -2
- package/dist/esm/services/github.service.mjs.map +1 -1
- package/dist/esm/services/gitlab.service.mjs +217 -0
- package/dist/esm/services/gitlab.service.mjs.map +1 -0
- package/dist/esm/services/webhook.service.mjs +164 -0
- package/dist/esm/services/webhook.service.mjs.map +1 -0
- package/dist/esm/utils/auth/getAuth.mjs +15 -9
- package/dist/esm/utils/auth/getAuth.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +156 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/types/controllers/ai.controller.d.ts.map +1 -1
- package/dist/types/controllers/bitbucket.controller.d.ts +62 -0
- package/dist/types/controllers/bitbucket.controller.d.ts.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/github.controller.d.ts.map +1 -1
- package/dist/types/controllers/gitlab.controller.d.ts +67 -0
- package/dist/types/controllers/gitlab.controller.d.ts.map +1 -0
- package/dist/types/controllers/project.controller.d.ts +39 -1
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/emails/InviteUserEmail.d.ts +4 -4
- package/dist/types/emails/MagicLinkEmail.d.ts +4 -4
- package/dist/types/emails/MagicLinkEmail.d.ts.map +1 -1
- package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +4 -4
- package/dist/types/emails/OAuthTokenCreatedEmail.d.ts.map +1 -1
- package/dist/types/emails/PasswordChangeConfirmation.d.ts +4 -4
- package/dist/types/emails/PasswordChangeConfirmation.d.ts.map +1 -1
- package/dist/types/emails/ResetUserPassword.d.ts +4 -4
- package/dist/types/emails/ResetUserPassword.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +4 -4
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentError.d.ts +4 -4
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +4 -4
- package/dist/types/emails/ValidateUserEmail.d.ts +4 -4
- package/dist/types/emails/ValidateUserEmail.d.ts.map +1 -1
- package/dist/types/emails/Welcome.d.ts +4 -4
- package/dist/types/export.d.ts +8 -4
- package/dist/types/models/dictionary.model.d.ts +4 -4
- package/dist/types/models/dictionary.model.d.ts.map +1 -1
- package/dist/types/models/discussion.model.d.ts +3 -3
- package/dist/types/models/discussion.model.d.ts.map +1 -1
- package/dist/types/models/oAuth2.model.d.ts +3 -3
- package/dist/types/models/oAuth2.model.d.ts.map +1 -1
- package/dist/types/routes/bitbucket.routes.d.ts +35 -0
- package/dist/types/routes/bitbucket.routes.d.ts.map +1 -0
- package/dist/types/routes/gitlab.routes.d.ts +35 -0
- package/dist/types/routes/gitlab.routes.d.ts.map +1 -0
- package/dist/types/routes/project.routes.d.ts +20 -0
- package/dist/types/routes/project.routes.d.ts.map +1 -1
- package/dist/types/schemas/dictionary.schema.d.ts +6 -6
- package/dist/types/schemas/discussion.schema.d.ts +6 -6
- package/dist/types/schemas/oAuth2.schema.d.ts +5 -5
- package/dist/types/schemas/oAuth2.schema.d.ts.map +1 -1
- package/dist/types/schemas/organization.schema.d.ts +6 -6
- package/dist/types/schemas/plans.schema.d.ts +6 -6
- package/dist/types/schemas/plans.schema.d.ts.map +1 -1
- package/dist/types/schemas/project.schema.d.ts +6 -6
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/session.schema.d.ts +6 -6
- package/dist/types/schemas/tag.schema.d.ts +6 -6
- package/dist/types/schemas/user.schema.d.ts +6 -6
- package/dist/types/services/bitbucket.service.d.ts +71 -0
- package/dist/types/services/bitbucket.service.d.ts.map +1 -0
- package/dist/types/services/ci.service.d.ts +27 -0
- package/dist/types/services/ci.service.d.ts.map +1 -0
- package/dist/types/services/email.service.d.ts +11 -11
- package/dist/types/services/github.service.d.ts +20 -1
- package/dist/types/services/github.service.d.ts.map +1 -1
- package/dist/types/services/gitlab.service.d.ts +58 -0
- package/dist/types/services/gitlab.service.d.ts.map +1 -0
- package/dist/types/services/webhook.service.d.ts +19 -0
- package/dist/types/services/webhook.service.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +32 -4
- package/dist/types/types/project.types.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorHandler.d.ts +3 -3
- package/dist/types/utils/errors/errorCodes.d.ts +156 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -2
- package/dist/types/utils/filtersAndPagination/getDiscussionFiltersAndPagination.d.ts +2 -2
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +2 -2
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +2 -2
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +2 -2
- package/dist/types/utils/mergeFunctionTypes.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "chunk_1": [], "chunk_2": [] }
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { formatResponse } from "../utils/responseData.mjs";
|
|
2
|
+
import { ErrorHandler } from "../utils/errors/ErrorHandler.mjs";
|
|
3
|
+
import { checkIntlayerConfig, exchangeCodeForToken, getAuthorizationUrl, getBitbucketTokenFromUser, getRepositoryFileContents, getUserRepositories } from "../services/bitbucket.service.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/controllers/bitbucket.controller.ts
|
|
6
|
+
const getAuthUrl = async (request, reply) => {
|
|
7
|
+
const { redirectUri } = request.query;
|
|
8
|
+
if (!redirectUri) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_REDIRECT_URI_MISSING");
|
|
9
|
+
try {
|
|
10
|
+
const responseData = formatResponse({ data: { authUrl: getAuthorizationUrl(redirectUri) } });
|
|
11
|
+
return reply.send(responseData);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const authCallback = async (request, reply) => {
|
|
17
|
+
const { code } = request.body;
|
|
18
|
+
if (!code) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_CODE_MISSING");
|
|
19
|
+
try {
|
|
20
|
+
const responseData = formatResponse({ data: { token: await exchangeCodeForToken(code) } });
|
|
21
|
+
return reply.send(responseData);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const listRepos = async (request, reply) => {
|
|
27
|
+
const { token } = request.query;
|
|
28
|
+
const userId = request.locals?.user?.id;
|
|
29
|
+
try {
|
|
30
|
+
let accessToken = token;
|
|
31
|
+
if (!accessToken && userId) accessToken = await getBitbucketTokenFromUser(String(userId)) ?? void 0;
|
|
32
|
+
if (!accessToken) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_TOKEN_MISSING");
|
|
33
|
+
const responseData = formatResponse({ data: await getUserRepositories(accessToken) });
|
|
34
|
+
return reply.send(responseData);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Check if intlayer.config.ts (or candidates) exists in a Bitbucket repository
|
|
41
|
+
*/
|
|
42
|
+
const checkConfig = async (request, reply) => {
|
|
43
|
+
const { token, workspace, repoSlug, branch = "main" } = request.body;
|
|
44
|
+
const userId = request.locals?.user?.id;
|
|
45
|
+
try {
|
|
46
|
+
let accessToken = token;
|
|
47
|
+
if (!accessToken && userId) accessToken = await getBitbucketTokenFromUser(String(userId)) ?? void 0;
|
|
48
|
+
if (!accessToken || !workspace || !repoSlug) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_CHECK_CONFIG_MISSING_PARAMS");
|
|
49
|
+
const configPaths = await checkIntlayerConfig(accessToken, workspace, repoSlug, branch);
|
|
50
|
+
const responseData = formatResponse({ data: {
|
|
51
|
+
hasConfig: configPaths.length > 0,
|
|
52
|
+
configPaths
|
|
53
|
+
} });
|
|
54
|
+
return reply.send(responseData);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const getConfigFile = async (request, reply) => {
|
|
60
|
+
const { token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts" } = request.body;
|
|
61
|
+
const userId = request.locals?.user?.id;
|
|
62
|
+
try {
|
|
63
|
+
let accessToken = token;
|
|
64
|
+
if (!accessToken && userId) accessToken = await getBitbucketTokenFromUser(String(userId)) ?? void 0;
|
|
65
|
+
if (!accessToken || !workspace || !repoSlug) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_GET_CONFIG_FILE_MISSING_PARAMS");
|
|
66
|
+
const content = await getRepositoryFileContents(accessToken, workspace, repoSlug, path, branch);
|
|
67
|
+
if (!content) return ErrorHandler.handleGenericErrorResponse(reply, "BITBUCKET_CONFIG_FILE_NOT_FOUND");
|
|
68
|
+
const responseData = formatResponse({ data: { content } });
|
|
69
|
+
return reply.send(responseData);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { authCallback, checkConfig, getAuthUrl, getConfigFile, listRepos };
|
|
77
|
+
//# sourceMappingURL=bitbucket.controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitbucket.controller.mjs","names":["bitbucketService.getAuthorizationUrl","bitbucketService.exchangeCodeForToken","accessToken: string | undefined","bitbucketService.getUserRepositories","bitbucketService.checkIntlayerConfig","bitbucketService.getRepositoryFileContents"],"sources":["../../../src/controllers/bitbucket.controller.ts"],"sourcesContent":["import * as bitbucketService from '@services/bitbucket.service';\nimport { getBitbucketTokenFromUser } from '@services/bitbucket.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport { formatResponse, type ResponseData } from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\n\nexport type BitbucketGetAuthUrlQuerystring = {\n redirectUri: string;\n};\n\nexport type BitbucketGetAuthUrlResult = ResponseData<{\n authUrl: string;\n}>;\n\nexport const getAuthUrl = async (\n request: FastifyRequest<{ Querystring: BitbucketGetAuthUrlQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { redirectUri } = request.query;\n\n if (!redirectUri) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_REDIRECT_URI_MISSING'\n );\n }\n\n try {\n const authUrl = bitbucketService.getAuthorizationUrl(redirectUri);\n const responseData = formatResponse<{ authUrl: string }>({\n data: { authUrl },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = ResponseData<{\n token: string;\n}>;\n\nexport const authCallback = async (\n request: FastifyRequest<{ Body: BitbucketAuthCallbackBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { code } = request.body;\n\n if (!code) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_CODE_MISSING'\n );\n }\n\n try {\n const token = await bitbucketService.exchangeCodeForToken(code);\n const responseData = formatResponse<{ token: string }>({\n data: { token },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type BitbucketListReposQuerystring = {\n token?: string;\n};\n\nexport type BitbucketListReposResult = ResponseData<\n bitbucketService.BitbucketRepository[]\n>;\n\nexport const listRepos = async (\n request: FastifyRequest<{ Querystring: BitbucketListReposQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token } = request.query;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken =\n (await getBitbucketTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_TOKEN_MISSING'\n );\n }\n\n const repos = await bitbucketService.getUserRepositories(accessToken);\n const responseData = formatResponse<bitbucketService.BitbucketRepository[]>(\n {\n data: repos,\n }\n );\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = ResponseData<{\n hasConfig: boolean;\n configPaths: string[];\n}>;\n\n/**\n * Check if intlayer.config.ts (or candidates) exists in a Bitbucket repository\n */\nexport const checkConfig = async (\n request: FastifyRequest<{ Body: BitbucketCheckConfigBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token, workspace, repoSlug, branch = 'main' } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken =\n (await getBitbucketTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !workspace || !repoSlug) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_CHECK_CONFIG_MISSING_PARAMS'\n );\n }\n\n const configPaths = await bitbucketService.checkIntlayerConfig(\n accessToken,\n workspace,\n repoSlug,\n branch\n );\n\n const responseData = formatResponse<{\n hasConfig: boolean;\n configPaths: string[];\n }>({\n data: {\n hasConfig: configPaths.length > 0,\n configPaths: configPaths,\n },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = ResponseData<{\n content: string;\n}>;\n\nexport const getConfigFile = async (\n request: FastifyRequest<{ Body: BitbucketGetConfigFileBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const {\n token,\n workspace,\n repoSlug,\n branch = 'main',\n path = 'intlayer.config.ts',\n } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken =\n (await getBitbucketTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !workspace || !repoSlug) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_GET_CONFIG_FILE_MISSING_PARAMS'\n );\n }\n\n const content = await bitbucketService.getRepositoryFileContents(\n accessToken,\n workspace,\n repoSlug,\n path,\n branch\n );\n\n if (!content) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'BITBUCKET_CONFIG_FILE_NOT_FOUND'\n );\n }\n\n const responseData = formatResponse<{ content: string }>({\n data: { content },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n"],"mappings":";;;;;AAcA,MAAa,aAAa,OACxB,SACA,UACkB;CAClB,MAAM,EAAE,gBAAgB,QAAQ;AAEhC,KAAI,CAAC,YACH,QAAO,aAAa,2BAClB,OACA,iCACD;AAGH,KAAI;EAEF,MAAM,eAAe,eAAoC,EACvD,MAAM,EAAE,SAFMA,oBAAqC,YAAY,EAE9C,EAClB,CAAC;AACF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB;;;AAYxE,MAAa,eAAe,OAC1B,SACA,UACkB;CAClB,MAAM,EAAE,SAAS,QAAQ;AAEzB,KAAI,CAAC,KACH,QAAO,aAAa,2BAClB,OACA,yBACD;AAGH,KAAI;EAEF,MAAM,eAAe,eAAkC,EACrD,MAAM,EAAE,OAFI,MAAMC,qBAAsC,KAAK,EAE9C,EAChB,CAAC;AACF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB;;;AAYxE,MAAa,YAAY,OACvB,SACA,UACkB;CAClB,MAAM,EAAE,UAAU,QAAQ;CAC1B,MAAM,SAAS,QAAQ,QAAQ,MAAM;AAErC,KAAI;EACF,IAAIC,cAAkC;AAEtC,MAAI,CAAC,eAAe,OAClB,eACG,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AoC,EACvD,MAAM,EAAE,SAAS,EAClB,CAAC;AAEF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB"}
|
|
@@ -2,8 +2,10 @@ import { ensureMongoDocumentToObject } from "../utils/ensureMongoDocumentToObjec
|
|
|
2
2
|
import { logger } from "../logger/index.mjs";
|
|
3
3
|
import { formatPaginatedResponse, formatResponse } from "../utils/responseData.mjs";
|
|
4
4
|
import { ErrorHandler } from "../utils/errors/ErrorHandler.mjs";
|
|
5
|
+
import { getProjectById } from "../services/project.service.mjs";
|
|
5
6
|
import { countDictionaries, createDictionary, deleteDictionaryById, findDictionaries, getDictionaryById, getDictionaryByKey as getDictionaryByKey$1, incrementVersion, updateDictionaryById, updateDictionaryByKey } from "../services/dictionary.service.mjs";
|
|
6
7
|
import { sendDictionaryUpdate } from "./eventListener.controller.mjs";
|
|
8
|
+
import { triggerAll } from "../services/webhook.service.mjs";
|
|
7
9
|
import { getDictionaryFiltersAndPagination } from "../utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs";
|
|
8
10
|
import { mapDictionaryToAPI } from "../utils/mapper/dictionary.mjs";
|
|
9
11
|
import { hasPermission } from "../utils/permissions.mjs";
|
|
@@ -152,6 +154,12 @@ const addDictionary = async (request, reply) => {
|
|
|
152
154
|
dictionary: mapDictionaryToAPI(newDictionary),
|
|
153
155
|
status: "ADDED"
|
|
154
156
|
}]);
|
|
157
|
+
if (project) try {
|
|
158
|
+
const fullProject = await getProjectById(project.id);
|
|
159
|
+
await triggerAll(fullProject);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
logger.error("Failed to trigger CI builds after dictionary creation", error);
|
|
162
|
+
}
|
|
155
163
|
return reply.send(responseData);
|
|
156
164
|
} catch (error) {
|
|
157
165
|
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
@@ -260,6 +268,12 @@ const pushDictionaries = async (request, reply) => {
|
|
|
260
268
|
dictionary,
|
|
261
269
|
status: "UPDATED"
|
|
262
270
|
}))]);
|
|
271
|
+
if (project && (newDictionariesResult.length > 0 || updatedDictionariesResult.length > 0)) try {
|
|
272
|
+
const fullProject = await getProjectById(project.id);
|
|
273
|
+
await triggerAll(fullProject);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
logger.error("Failed to trigger CI builds after dictionary push", error);
|
|
276
|
+
}
|
|
263
277
|
return reply.send(responseData);
|
|
264
278
|
} catch (error) {
|
|
265
279
|
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
@@ -296,6 +310,12 @@ const updateDictionary = async (request, reply) => {
|
|
|
296
310
|
dictionary: apiResult,
|
|
297
311
|
status: "UPDATED"
|
|
298
312
|
}]);
|
|
313
|
+
if (project) try {
|
|
314
|
+
const fullProject = await getProjectById(project.id);
|
|
315
|
+
await triggerAll(fullProject);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
logger.error("Failed to trigger CI builds after dictionary update", error);
|
|
318
|
+
}
|
|
299
319
|
return reply.send(responseData);
|
|
300
320
|
} catch (error) {
|
|
301
321
|
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.controller.mjs","names":["clone: T","dictionaryService.findDictionaries","dictionaryService.countDictionaries","dictionariesUpdateTimestamp: Record<\n string,\n { key: string; updatedAt: number }\n >","dictionaryService.getDictionaryByKey","dictionary: DictionaryData","dictionaryService.createDictionary","newDictionariesResult: PushDictionariesResultData['newDictionaries']","updatedDictionariesResult: PushDictionariesResultData['updatedDictionaries']","errorResult: PushDictionariesResultData['error']","dictionaryService.getDictionaryById","newContent: VersionedContent","dictionaryService.incrementVersion","dictionaryService.updateDictionaryByKey","result: PushDictionariesResultData","dictionaryService.updateDictionaryById","dictionaryService.deleteDictionaryById"],"sources":["../../../src/controllers/dictionary.controller.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'node:util';\nimport * as eventListener from '@controllers/eventListener.controller';\nimport type {\n ContentNode,\n DictionaryId,\n Dictionary as LocalDictionary,\n LocalDictionaryId,\n} from '@intlayer/types';\nimport { logger } from '@logger';\nimport * as dictionaryService from '@services/dictionary.service';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DictionaryFiltersParams,\n getDictionaryFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { mapDictionaryToAPI } from '@utils/mapper/dictionary';\nimport { hasPermission } from '@utils/permissions';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { t } from 'fastify-intlayer';\nimport type {\n Dictionary,\n DictionaryAPI,\n DictionaryCreationData,\n DictionaryData,\n VersionedContent,\n} from '@/types/dictionary.types';\n\nexport type GetDictionariesParams =\n FiltersAndPagination<DictionaryFiltersParams>;\nexport type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;\n\nconst removeMetadata = <T extends Record<string, any>>(obj: T): T => {\n if (Array.isArray(obj)) {\n return obj.map(removeMetadata) as unknown as T;\n }\n\n if (obj && typeof obj === 'object') {\n const clone: T = {} as T;\n for (const key in obj) {\n if (key !== 'metadata') {\n clone[key] = removeMetadata(obj[key]);\n }\n }\n return clone as T;\n }\n\n return obj as T;\n};\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaries = async (\n request: FastifyRequest<{ Querystring: GetDictionariesParams }>,\n reply: FastifyReply\n): Promise<void> => {\n const { user, project, roles } = request.locals || {};\n const { filters, sortOptions, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(request);\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries(\n {\n ...filters,\n projectIds: project.id,\n },\n skip,\n pageSize,\n sortOptions\n );\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ...request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const totalItems = await dictionaryService.countDictionaries(filters);\n\n const dictionariesAPI = dictionaries.map((el) => mapDictionaryToAPI(el));\n\n const responseData = formatPaginatedResponse<DictionaryAPI>({\n data: dictionariesAPI,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionariesKeysResult = ResponseData<string[]>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesKeys = async (\n _request: FastifyRequest,\n reply: FastifyReply\n) => {\n const { project, roles } = _request.locals || {};\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries({\n projectIds: project.id,\n });\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ..._request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const dictionariesKeys = dictionaries.map((dictionary) => dictionary.key);\n\n const responseData = formatResponse<string[]>({\n data: dictionariesKeys,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionariesUpdateTimestampResult = ResponseData<\n Record<DictionaryId, { key: string; updatedAt: number }>\n>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesUpdateTimestamp = async (\n _request: FastifyRequest,\n reply: FastifyReply\n) => {\n const { project, roles } = _request.locals || {};\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries({\n projectIds: project.id,\n });\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ..._request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const dictionariesUpdateTimestamp: Record<\n string,\n { key: string; updatedAt: number }\n > = {};\n for (const dictionary of dictionaries) {\n dictionariesUpdateTimestamp[dictionary.id] = {\n key: dictionary.key,\n updatedAt: new Date(dictionary.updatedAt).getTime(),\n };\n }\n\n const responseData = formatResponse<\n Record<string, { key: string; updatedAt: number }>\n >({\n data: dictionariesUpdateTimestamp,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionaryParams = { dictionaryKey: string };\nexport type GetDictionaryQuery = { version?: string };\nexport type GetDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaryByKey = async (\n request: FastifyRequest<{\n Params: GetDictionaryParams;\n Querystring: GetDictionaryQuery;\n }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n const { dictionaryKey } = request.params;\n const version = request.query.version;\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n try {\n const dictionary = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project.id\n );\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ...request.locals,\n targetDictionaries: [dictionary],\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n if (!dictionary.projectIds.map(String).includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const apiResult = mapDictionaryToAPI(dictionary, version);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type AddDictionaryBody = { dictionary: DictionaryCreationData };\nexport type AddDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Adds a new dictionary to the database.\n */\nexport const addDictionary = async (\n request: FastifyRequest<{ Body: AddDictionaryBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n const dictionaryData = request.body.dictionary;\n\n if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const dictionary: DictionaryData = {\n key: dictionaryData.key,\n title: dictionaryData.title,\n description: dictionaryData.description,\n content: new Map([\n [\n 'v1',\n {\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n content: removeMetadata(dictionaryData.content ?? {}) as ContentNode,\n },\n ],\n ]),\n creatorId: user.id,\n projectIds: dictionaryData.projectIds ?? [String(project.id)],\n };\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const newDictionary = await dictionaryService.createDictionary(dictionary);\n\n const apiResult = mapDictionaryToAPI(newDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary created successfully',\n fr: 'Dictionnaire créé avec succès',\n es: 'Diccionario creado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been created successfully',\n fr: 'Votre dictionnaire a été créé avec succès',\n es: 'Su diccionario ha sido creado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: mapDictionaryToAPI(newDictionary),\n status: 'ADDED',\n },\n ]);\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type PushDictionariesBody = {\n dictionaries: LocalDictionary[];\n};\ntype PushDictionariesResultData = {\n newDictionaries: {\n key: string;\n localId: LocalDictionaryId;\n id: string | undefined;\n }[];\n updatedDictionaries: {\n key: string;\n localId: LocalDictionaryId;\n id: string | undefined;\n }[];\n error: {\n id: string | undefined;\n key: string;\n localId: LocalDictionaryId | undefined;\n message: string;\n }[];\n};\nexport type PushDictionariesResult = ResponseData<PushDictionariesResultData>;\n\n/**\n * Check each dictionaries, add the new ones and update the existing ones.\n */\nexport const pushDictionaries = async (\n request: FastifyRequest<{ Body: PushDictionariesBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n\n // Normalize the input: handle both { dictionaries: [...] } and { dictionaries: { dictionaries: [...] } }\n // The latter can happen due to client-side double-wrapping issues\n let dictionaryData = request.body.dictionaries;\n if (\n dictionaryData &&\n !Array.isArray(dictionaryData) &&\n typeof dictionaryData === 'object' &&\n 'dictionaries' in dictionaryData &&\n Array.isArray(\n (dictionaryData as unknown as PushDictionariesBody).dictionaries\n )\n ) {\n dictionaryData = (dictionaryData as unknown as PushDictionariesBody)\n .dictionaries;\n }\n\n if (\n typeof dictionaryData === 'object' &&\n Array.isArray(dictionaryData) &&\n dictionaryData.length === 0\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARIES_NOT_PROVIDED'\n );\n } else if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const existingDictionaries = dictionaryData.filter(\n (dictionary) => dictionary.id !== undefined\n );\n const newDictionaries = dictionaryData.filter(\n (dictionary) => dictionary.id === undefined\n );\n\n const newDictionariesResult: PushDictionariesResultData['newDictionaries'] =\n [];\n const updatedDictionariesResult: PushDictionariesResultData['updatedDictionaries'] =\n [];\n const errorResult: PushDictionariesResultData['error'] = [];\n\n for (const dictionaryDataEl of newDictionaries) {\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n projectIds: [String(project.id)],\n creatorId: user.id,\n content: new Map([\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n\n [\n 'v1',\n {\n content:\n removeMetadata(dictionaryDataEl.content) ?? ({} as ContentNode),\n },\n ],\n ]),\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary =\n await dictionaryService.createDictionary(dictionary);\n newDictionariesResult.push({\n key: newDictionary.key,\n localId: dictionaryDataEl.localId!,\n id: newDictionary.id,\n });\n } catch (error) {\n errorResult.push({\n id: dictionaryDataEl.id!,\n key: dictionaryDataEl.key,\n localId: dictionaryDataEl.localId!,\n message: (error as AppError).message,\n });\n }\n }\n\n for (const dictionaryDataEl of existingDictionaries) {\n const remoteDictionary = await dictionaryService.getDictionaryById(\n dictionaryDataEl.id!\n );\n\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n const cleanedContent = removeMetadata(dictionaryDataEl.content);\n\n const versionList = [...(remoteDictionary.content.keys() ?? [])];\n const lastVersion = versionList[versionList.length - 1];\n\n const lastContent =\n (remoteDictionary.content.get(lastVersion)\n ?.content as DictionaryAPI['content']) ?? null;\n\n const isSameContent = isDeepStrictEqual(lastContent, cleanedContent);\n\n const newContent: VersionedContent = new Map(remoteDictionary.content);\n\n if (!isSameContent) {\n const newContentVersion =\n dictionaryService.incrementVersion(remoteDictionary);\n\n newContent.set(newContentVersion, {\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n content: cleanedContent,\n });\n }\n\n const dictionary: DictionaryData = {\n ...ensureMongoDocumentToObject(remoteDictionary),\n ...dictionaryDataEl,\n content: newContent,\n projectIds: [String(project.id)],\n creatorId: user.id,\n key: remoteDictionary.key,\n };\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryByKey(\n remoteDictionary.key,\n dictionary,\n project.id\n );\n updatedDictionariesResult.push({\n key: updatedDictionary.key,\n localId: dictionaryDataEl.localId!,\n id: updatedDictionary.id,\n });\n } catch (error) {\n errorResult.push({\n id: dictionaryDataEl.id!,\n key: dictionaryDataEl.key,\n localId: dictionaryDataEl.localId!,\n message: (error as AppError).message,\n });\n }\n }\n\n const result: PushDictionariesResultData = {\n newDictionaries: newDictionariesResult,\n updatedDictionaries: updatedDictionariesResult,\n error: errorResult,\n };\n\n const responseData = formatResponse<PushDictionariesResultData>({\n message: t({\n en: 'Dictionaries updated successfully',\n fr: 'Dictionnaires mis à jour avec succès',\n es: 'Diccionarios actualizados con éxito',\n }),\n description: t({\n en: 'Your dictionaries have been updated successfully',\n fr: 'Vos dictionnaires ont été mis à jour avec succès',\n es: 'Sus diccionarios han sido actualizados con éxito',\n }),\n data: result,\n });\n\n eventListener.sendDictionaryUpdate([\n ...newDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'ADDED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ...updatedDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'UPDATED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ]);\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type UpdateDictionaryParam = { dictionaryId: string };\nexport type UpdateDictionaryBody = Partial<Dictionary>;\nexport type UpdateDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Updates an existing dictionary in the database.\n */\nexport const updateDictionary = async (\n request: FastifyRequest<{\n Params: UpdateDictionaryParam;\n Body: UpdateDictionaryBody;\n }>,\n reply: FastifyReply\n): Promise<void> => {\n const { dictionaryId } = request.params;\n const { project, roles } = request.locals || {};\n const dictionaryData = request.body;\n\n if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n if (typeof dictionaryId === 'undefined') {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_ID_NOT_FOUND'\n );\n }\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryById(\n dictionaryId,\n dictionaryData\n );\n\n const apiResult = mapDictionaryToAPI(updatedDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary updated successfully',\n fr: 'Dictionnaire mis à jour avec succès',\n es: 'Diccionario actualizado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been updated successfully',\n fr: 'Votre dictionnaire a été mis à jour avec succès',\n es: 'Su diccionario ha sido actualizado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'UPDATED',\n },\n ]);\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type DeleteDictionaryParam = { dictionaryId: string };\nexport type DeleteDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Deletes a dictionary from the database by its ID.\n */\nexport const deleteDictionary = async (\n request: FastifyRequest<{ Params: DeleteDictionaryParam }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, roles } = request.locals || {};\n const { dictionaryId } = request.params;\n\n if (!dictionaryId) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_ID_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!hasPermission(roles || [], 'dictionary:admin')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const dictionaryToDelete =\n await dictionaryService.getDictionaryById(dictionaryId);\n\n if (!dictionaryToDelete.projectIds.includes(project.id)) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const deletedDictionary =\n await dictionaryService.deleteDictionaryById(dictionaryId);\n\n if (!deletedDictionary) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_NOT_FOUND',\n {\n dictionaryId,\n }\n );\n }\n\n logger.info(`Dictionary deleted: ${String(deletedDictionary.id)}`);\n\n const apiResult = mapDictionaryToAPI(deletedDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary deleted successfully',\n fr: 'Dictionnaire supprimé avec succès',\n es: 'Diccionario eliminado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been deleted successfully',\n fr: 'Votre dictionnaire a été supprimé avec succès',\n es: 'Su diccionario ha sido eliminado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'DELETED',\n },\n ]);\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAuCA,MAAM,kBAAiD,QAAc;AACnE,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,eAAe;AAGhC,KAAI,OAAO,OAAO,QAAQ,UAAU;EAClC,MAAMA,QAAW,EAAE;AACnB,OAAK,MAAM,OAAO,IAChB,KAAI,QAAQ,WACV,OAAM,OAAO,eAAe,IAAI,KAAK;AAGzC,SAAO;;AAGT,QAAO;;;;;AAMT,MAAa,kBAAkB,OAC7B,SACA,UACkB;CAClB,MAAM,EAAE,MAAM,SAAS,UAAU,QAAQ,UAAU,EAAE;CACrD,MAAM,EAAE,SAAS,aAAa,UAAU,MAAM,MAAM,qBAClD,kCAAkC,QAAQ;AAE5C,KAAI,CAAC,QACH,QAAO,aAAa,2BAClB,OACA,sBACD;AAGH,KAAI,CAAC,KACH,QAAO,aAAa,2BAA2B,OAAO,mBAAmB;AAG3E,KAAI;EACF,MAAM,eAAe,MAAMC,iBACzB;GACE,GAAG;GACH,YAAY,QAAQ;GACrB,EACD,MACA,UACA,YACD;AAED,MACE,CAAC,cACC,SAAS,EAAE,EACX,kBACD,CAAC;GACA,GAAG,QAAQ;GACX,oBAAoB;GACrB,CAAC,CAEF,QAAO,aAAa,2BAClB,OACA,oBACD;EAGH,MAAM,aAAa,MAAMC,kBAAoC,QAAQ;EAIrE,MAAM,eAAe,wBAAuC;GAC1D,MAHsB,aAAa,KAAK,OAAO,mBAAmB,GAAG,CAAC;GAItE;GACA;GACA,YAAY,iBAAiB,WAAW;GACxC;GACD,CAAC;AAEF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB;;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AGH,SAAO,KAAK,uBAAuB,OAAO,kBAAkB,GAAG,GAAG;EAElE,MAAM,YAAY,mBAAmB,kBAAkB;EAEvD,MAAM,eAAe,eAA8B;GACjD,SAAS,EAAE;IACT,IAAI;IACJ,IAAI;IACJ,IAAI;IACL,CAAC;GACF,aAAa,EAAE;IACb,IAAI;IACJ,IAAI;IACJ,IAAI;IACL,CAAC;GACF,MAAM;GACP,CAAC;AAEF,uBAAmC,CACjC;GACE,YAAY;GACZ,QAAQ;GACT,CACF,CAAC;AAEF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB"}
|
|
1
|
+
{"version":3,"file":"dictionary.controller.mjs","names":["clone: T","dictionaryService.findDictionaries","dictionaryService.countDictionaries","dictionariesUpdateTimestamp: Record<\n string,\n { key: string; updatedAt: number }\n >","dictionaryService.getDictionaryByKey","dictionary: DictionaryData","dictionaryService.createDictionary","projectService.getProjectById","webhooksService.triggerAll","newDictionariesResult: PushDictionariesResultData['newDictionaries']","updatedDictionariesResult: PushDictionariesResultData['updatedDictionaries']","errorResult: PushDictionariesResultData['error']","dictionaryService.getDictionaryById","newContent: VersionedContent","dictionaryService.incrementVersion","dictionaryService.updateDictionaryByKey","result: PushDictionariesResultData","dictionaryService.updateDictionaryById","dictionaryService.deleteDictionaryById"],"sources":["../../../src/controllers/dictionary.controller.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'node:util';\nimport * as eventListener from '@controllers/eventListener.controller';\nimport type {\n ContentNode,\n DictionaryId,\n Dictionary as LocalDictionary,\n LocalDictionaryId,\n} from '@intlayer/types';\nimport { logger } from '@logger';\nimport * as dictionaryService from '@services/dictionary.service';\nimport * as projectService from '@services/project.service';\nimport * as webhooksService from '@services/webhook.service';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DictionaryFiltersParams,\n getDictionaryFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { mapDictionaryToAPI } from '@utils/mapper/dictionary';\nimport { hasPermission } from '@utils/permissions';\nimport {\n formatPaginatedResponse,\n formatResponse,\n type PaginatedResponse,\n type ResponseData,\n} from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { t } from 'fastify-intlayer';\nimport type {\n Dictionary,\n DictionaryAPI,\n DictionaryCreationData,\n DictionaryData,\n VersionedContent,\n} from '@/types/dictionary.types';\n\nexport type GetDictionariesParams =\n FiltersAndPagination<DictionaryFiltersParams>;\nexport type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;\n\nconst removeMetadata = <T extends Record<string, any>>(obj: T): T => {\n if (Array.isArray(obj)) {\n return obj.map(removeMetadata) as unknown as T;\n }\n\n if (obj && typeof obj === 'object') {\n const clone: T = {} as T;\n for (const key in obj) {\n if (key !== 'metadata') {\n clone[key] = removeMetadata(obj[key]);\n }\n }\n return clone as T;\n }\n\n return obj as T;\n};\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaries = async (\n request: FastifyRequest<{ Querystring: GetDictionariesParams }>,\n reply: FastifyReply\n): Promise<void> => {\n const { user, project, roles } = request.locals || {};\n const { filters, sortOptions, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(request);\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries(\n {\n ...filters,\n projectIds: project.id,\n },\n skip,\n pageSize,\n sortOptions\n );\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ...request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const totalItems = await dictionaryService.countDictionaries(filters);\n\n const dictionariesAPI = dictionaries.map((el) => mapDictionaryToAPI(el));\n\n const responseData = formatPaginatedResponse<DictionaryAPI>({\n data: dictionariesAPI,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionariesKeysResult = ResponseData<string[]>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesKeys = async (\n _request: FastifyRequest,\n reply: FastifyReply\n) => {\n const { project, roles } = _request.locals || {};\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries({\n projectIds: project.id,\n });\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ..._request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const dictionariesKeys = dictionaries.map((dictionary) => dictionary.key);\n\n const responseData = formatResponse<string[]>({\n data: dictionariesKeys,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionariesUpdateTimestampResult = ResponseData<\n Record<DictionaryId, { key: string; updatedAt: number }>\n>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesUpdateTimestamp = async (\n _request: FastifyRequest,\n reply: FastifyReply\n) => {\n const { project, roles } = _request.locals || {};\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries({\n projectIds: project.id,\n });\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ..._request.locals,\n targetDictionaries: dictionaries,\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n const dictionariesUpdateTimestamp: Record<\n string,\n { key: string; updatedAt: number }\n > = {};\n for (const dictionary of dictionaries) {\n dictionariesUpdateTimestamp[dictionary.id] = {\n key: dictionary.key,\n updatedAt: new Date(dictionary.updatedAt).getTime(),\n };\n }\n\n const responseData = formatResponse<\n Record<string, { key: string; updatedAt: number }>\n >({\n data: dictionariesUpdateTimestamp,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GetDictionaryParams = { dictionaryKey: string };\nexport type GetDictionaryQuery = { version?: string };\nexport type GetDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaryByKey = async (\n request: FastifyRequest<{\n Params: GetDictionaryParams;\n Querystring: GetDictionaryQuery;\n }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n const { dictionaryKey } = request.params;\n const version = request.query.version;\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n try {\n const dictionary = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project.id\n );\n\n if (\n !hasPermission(\n roles || [],\n 'dictionary:read'\n )({\n ...request.locals,\n targetDictionaries: [dictionary],\n })\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PERMISSION_DENIED'\n );\n }\n\n if (!dictionary.projectIds.map(String).includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const apiResult = mapDictionaryToAPI(dictionary, version);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type AddDictionaryBody = { dictionary: DictionaryCreationData };\nexport type AddDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Adds a new dictionary to the database.\n */\nexport const addDictionary = async (\n request: FastifyRequest<{ Body: AddDictionaryBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n const dictionaryData = request.body.dictionary;\n\n if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const dictionary: DictionaryData = {\n key: dictionaryData.key,\n title: dictionaryData.title,\n description: dictionaryData.description,\n content: new Map([\n [\n 'v1',\n {\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n content: removeMetadata(dictionaryData.content ?? {}) as ContentNode,\n },\n ],\n ]),\n creatorId: user.id,\n projectIds: dictionaryData.projectIds ?? [String(project.id)],\n };\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const newDictionary = await dictionaryService.createDictionary(dictionary);\n\n const apiResult = mapDictionaryToAPI(newDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary created successfully',\n fr: 'Dictionnaire créé avec succès',\n es: 'Diccionario creado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been created successfully',\n fr: 'Votre dictionnaire a été créé avec succès',\n es: 'Su diccionario ha sido creado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: mapDictionaryToAPI(newDictionary),\n status: 'ADDED',\n },\n ]);\n\n // Trigger CI builds if configured\n if (project) {\n try {\n const fullProject = await projectService.getProjectById(project.id);\n await webhooksService.triggerAll(fullProject);\n } catch (error) {\n // Log error but don't fail the dictionary creation\n logger.error(\n 'Failed to trigger CI builds after dictionary creation',\n error\n );\n }\n }\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type PushDictionariesBody = {\n dictionaries: LocalDictionary[];\n};\ntype PushDictionariesResultData = {\n newDictionaries: {\n key: string;\n localId: LocalDictionaryId;\n id: string | undefined;\n }[];\n updatedDictionaries: {\n key: string;\n localId: LocalDictionaryId;\n id: string | undefined;\n }[];\n error: {\n id: string | undefined;\n key: string;\n localId: LocalDictionaryId | undefined;\n message: string;\n }[];\n};\nexport type PushDictionariesResult = ResponseData<PushDictionariesResultData>;\n\n/**\n * Check each dictionaries, add the new ones and update the existing ones.\n */\nexport const pushDictionaries = async (\n request: FastifyRequest<{ Body: PushDictionariesBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, user, roles } = request.locals || {};\n\n // Normalize the input: handle both { dictionaries: [...] } and { dictionaries: { dictionaries: [...] } }\n // The latter can happen due to client-side double-wrapping issues\n let dictionaryData = request.body.dictionaries;\n if (\n dictionaryData &&\n !Array.isArray(dictionaryData) &&\n typeof dictionaryData === 'object' &&\n 'dictionaries' in dictionaryData &&\n Array.isArray(\n (dictionaryData as unknown as PushDictionariesBody).dictionaries\n )\n ) {\n dictionaryData = (dictionaryData as unknown as PushDictionariesBody)\n .dictionaries;\n }\n\n if (\n typeof dictionaryData === 'object' &&\n Array.isArray(dictionaryData) &&\n dictionaryData.length === 0\n ) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARIES_NOT_PROVIDED'\n );\n } else if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!user) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'USER_NOT_DEFINED');\n }\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const existingDictionaries = dictionaryData.filter(\n (dictionary) => dictionary.id !== undefined\n );\n const newDictionaries = dictionaryData.filter(\n (dictionary) => dictionary.id === undefined\n );\n\n const newDictionariesResult: PushDictionariesResultData['newDictionaries'] =\n [];\n const updatedDictionariesResult: PushDictionariesResultData['updatedDictionaries'] =\n [];\n const errorResult: PushDictionariesResultData['error'] = [];\n\n for (const dictionaryDataEl of newDictionaries) {\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n projectIds: [String(project.id)],\n creatorId: user.id,\n content: new Map([\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n\n [\n 'v1',\n {\n content:\n removeMetadata(dictionaryDataEl.content) ?? ({} as ContentNode),\n },\n ],\n ]),\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary =\n await dictionaryService.createDictionary(dictionary);\n newDictionariesResult.push({\n key: newDictionary.key,\n localId: dictionaryDataEl.localId!,\n id: newDictionary.id,\n });\n } catch (error) {\n errorResult.push({\n id: dictionaryDataEl.id!,\n key: dictionaryDataEl.key,\n localId: dictionaryDataEl.localId!,\n message: (error as AppError).message,\n });\n }\n }\n\n for (const dictionaryDataEl of existingDictionaries) {\n const remoteDictionary = await dictionaryService.getDictionaryById(\n dictionaryDataEl.id!\n );\n\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n const cleanedContent = removeMetadata(dictionaryDataEl.content);\n\n const versionList = [...(remoteDictionary.content.keys() ?? [])];\n const lastVersion = versionList[versionList.length - 1];\n\n const lastContent =\n (remoteDictionary.content.get(lastVersion)\n ?.content as DictionaryAPI['content']) ?? null;\n\n const isSameContent = isDeepStrictEqual(lastContent, cleanedContent);\n\n const newContent: VersionedContent = new Map(remoteDictionary.content);\n\n if (!isSameContent) {\n const newContentVersion =\n dictionaryService.incrementVersion(remoteDictionary);\n\n newContent.set(newContentVersion, {\n // Remove metadata as markdown metadata are dynamic data inserted at build time\n content: cleanedContent,\n });\n }\n\n const dictionary: DictionaryData = {\n ...ensureMongoDocumentToObject(remoteDictionary),\n ...dictionaryDataEl,\n content: newContent,\n projectIds: [String(project.id)],\n creatorId: user.id,\n key: remoteDictionary.key,\n };\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryByKey(\n remoteDictionary.key,\n dictionary,\n project.id\n );\n updatedDictionariesResult.push({\n key: updatedDictionary.key,\n localId: dictionaryDataEl.localId!,\n id: updatedDictionary.id,\n });\n } catch (error) {\n errorResult.push({\n id: dictionaryDataEl.id!,\n key: dictionaryDataEl.key,\n localId: dictionaryDataEl.localId!,\n message: (error as AppError).message,\n });\n }\n }\n\n const result: PushDictionariesResultData = {\n newDictionaries: newDictionariesResult,\n updatedDictionaries: updatedDictionariesResult,\n error: errorResult,\n };\n\n const responseData = formatResponse<PushDictionariesResultData>({\n message: t({\n en: 'Dictionaries updated successfully',\n fr: 'Dictionnaires mis à jour avec succès',\n es: 'Diccionarios actualizados con éxito',\n }),\n description: t({\n en: 'Your dictionaries have been updated successfully',\n fr: 'Vos dictionnaires ont été mis à jour avec succès',\n es: 'Sus diccionarios han sido actualizados con éxito',\n }),\n data: result,\n });\n\n eventListener.sendDictionaryUpdate([\n ...newDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'ADDED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ...updatedDictionariesResult.map(\n (dictionary) =>\n ({\n dictionary,\n status: 'UPDATED',\n }) as eventListener.SendDictionaryUpdateArg\n ),\n ]);\n\n // Trigger CI builds if configured (only if there were actual changes)\n if (\n project &&\n (newDictionariesResult.length > 0 || updatedDictionariesResult.length > 0)\n ) {\n try {\n const fullProject = await projectService.getProjectById(project.id);\n await webhooksService.triggerAll(fullProject);\n } catch (error) {\n // Log error but don't fail the dictionary push\n logger.error(\n 'Failed to trigger CI builds after dictionary push',\n error\n );\n }\n }\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type UpdateDictionaryParam = { dictionaryId: string };\nexport type UpdateDictionaryBody = Partial<Dictionary>;\nexport type UpdateDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Updates an existing dictionary in the database.\n */\nexport const updateDictionary = async (\n request: FastifyRequest<{\n Params: UpdateDictionaryParam;\n Body: UpdateDictionaryBody;\n }>,\n reply: FastifyReply\n): Promise<void> => {\n const { dictionaryId } = request.params;\n const { project, roles } = request.locals || {};\n const dictionaryData = request.body;\n\n if (!dictionaryData) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_DATA_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!dictionaryData.projectIds?.includes(String(project.id))) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n if (typeof dictionaryId === 'undefined') {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_ID_NOT_FOUND'\n );\n }\n\n if (!hasPermission(roles || [], 'dictionary:write')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryById(\n dictionaryId,\n dictionaryData\n );\n\n const apiResult = mapDictionaryToAPI(updatedDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary updated successfully',\n fr: 'Dictionnaire mis à jour avec succès',\n es: 'Diccionario actualizado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been updated successfully',\n fr: 'Votre dictionnaire a été mis à jour avec succès',\n es: 'Su diccionario ha sido actualizado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'UPDATED',\n },\n ]);\n\n // Trigger CI builds if configured\n if (project) {\n try {\n const fullProject = await projectService.getProjectById(project.id);\n await webhooksService.triggerAll(fullProject);\n } catch (error) {\n // Log error but don't fail the dictionary update\n logger.error(\n 'Failed to trigger CI builds after dictionary update',\n error\n );\n }\n }\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type DeleteDictionaryParam = { dictionaryId: string };\nexport type DeleteDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Deletes a dictionary from the database by its ID.\n */\nexport const deleteDictionary = async (\n request: FastifyRequest<{ Params: DeleteDictionaryParam }>,\n reply: FastifyReply\n): Promise<void> => {\n const { project, roles } = request.locals || {};\n const { dictionaryId } = request.params;\n\n if (!dictionaryId) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_ID_NOT_FOUND'\n );\n }\n\n if (!project) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'PROJECT_NOT_DEFINED'\n );\n }\n\n if (!hasPermission(roles || [], 'dictionary:admin')(request.locals)) {\n return ErrorHandler.handleGenericErrorResponse(reply, 'PERMISSION_DENIED');\n }\n\n try {\n const dictionaryToDelete =\n await dictionaryService.getDictionaryById(dictionaryId);\n\n if (!dictionaryToDelete.projectIds.includes(project.id)) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n }\n\n const deletedDictionary =\n await dictionaryService.deleteDictionaryById(dictionaryId);\n\n if (!deletedDictionary) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'DICTIONARY_NOT_FOUND',\n {\n dictionaryId,\n }\n );\n }\n\n logger.info(`Dictionary deleted: ${String(deletedDictionary.id)}`);\n\n const apiResult = mapDictionaryToAPI(deletedDictionary);\n\n const responseData = formatResponse<DictionaryAPI>({\n message: t({\n en: 'Dictionary deleted successfully',\n fr: 'Dictionnaire supprimé avec succès',\n es: 'Diccionario eliminado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been deleted successfully',\n fr: 'Votre dictionnaire a été supprimé avec succès',\n es: 'Su diccionario ha sido eliminado con éxito',\n }),\n data: apiResult,\n });\n\n eventListener.sendDictionaryUpdate([\n {\n dictionary: apiResult,\n status: 'DELETED',\n },\n ]);\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAyCA,MAAM,kBAAiD,QAAc;AACnE,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,eAAe;AAGhC,KAAI,OAAO,OAAO,QAAQ,UAAU;EAClC,MAAMA,QAAW,EAAE;AACnB,OAAK,MAAM,OAAO,IAChB,KAAI,QAAQ,WACV,OAAM,OAAO,eAAe,IAAI,KAAK;AAGzC,SAAO;;AAGT,QAAO;;;;;AAMT,MAAa,kBAAkB,OAC7B,SACA,UACkB;CAClB,MAAM,EAAE,MAAM,SAAS,UAAU,QAAQ,UAAU,EAAE;CACrD,MAAM,EAAE,SAAS,aAAa,UAAU,MAAM,MAAM,qBAClD,kCAAkC,QAAQ;AAE5C,KAAI,CAAC,QACH,QAAO,aAAa,2BAClB,OACA,sBACD;AAGH,KAAI,CAAC,KACH,QAAO,aAAa,2BAA2B,OAAO,mBAAmB;AAG3E,KAAI;EACF,MAAM,eAAe,MAAMC,iBACzB;GACE,GAAG;GACH,YAAY,QAAQ;GACrB,EACD,MACA,UACA,YACD;AAED,MACE,CAAC,cACC,SAAS,EAAE,EACX,kBACD,CAAC;GAC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mjs","names":["githubService.getAuthorizationUrl","githubService.exchangeCodeForToken","accessToken: string | undefined","githubService.getUserRepos","githubService.checkIntlayerConfig","githubService.getRepositoryFileContents"],"sources":["../../../src/controllers/github.controller.ts"],"sourcesContent":["import * as githubService from '@services/github.service';\nimport { getGitHubTokenFromUser } from '@services/github.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport { formatResponse, type ResponseData } from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\n\nexport type GitHubGetAuthUrlQuerystring = {\n redirectUri: string;\n login?: string;\n};\n\nexport type GitHubGetAuthUrlResult = ResponseData<{\n authUrl: string;\n}>;\n\nexport const getAuthUrl = async (\n request: FastifyRequest<{ Querystring: GitHubGetAuthUrlQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { redirectUri, login } = request.query;\n\n if (!redirectUri) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_REDIRECT_URI_MISSING'\n );\n }\n\n try {\n const authUrl = githubService.getAuthorizationUrl(redirectUri, login);\n const responseData = formatResponse<{ authUrl: string }>({\n data: { authUrl },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubAuthCallbackBody = {\n code: string;\n};\n\nexport type GitHubAuthCallbackResult = ResponseData<{\n token: string;\n}>;\n\nexport const authCallback = async (\n request: FastifyRequest<{ Body: GitHubAuthCallbackBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { code } = request.body;\n\n if (!code) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_CODE_MISSING'\n );\n }\n\n try {\n const token = await githubService.exchangeCodeForToken(code);\n const responseData = formatResponse<{ token: string }>({\n data: { token },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubListReposQuerystring = {\n token?: string;\n};\n\nexport type GitHubListReposResult = ResponseData<\n githubService.GitHubRepository[]\n>;\n\nexport const listRepos = async (\n request: FastifyRequest<{ Querystring: GitHubListReposQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token } = request.query;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitHubTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_TOKEN_MISSING'\n );\n }\n\n const repos = await githubService.getUserRepos(accessToken);\n const responseData = formatResponse<githubService.GitHubRepository[]>({\n data: repos,\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubCheckConfigBody = {\n token?: string;\n owner: string;\n repository: string;\n branch?: string;\n};\n\nexport type GitHubCheckConfigResult = ResponseData<{\n hasConfig: boolean;\n configPaths: string[]; // Changed from single path to array\n}>;\n\n/**\n * Check if intlayer.config.ts (or candidates) exists in a repository\n */\nexport const checkConfig = async (\n request: FastifyRequest<{ Body: GitHubCheckConfigBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token, owner, repository, branch = 'main' } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitHubTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !owner || !repository) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_CHECK_CONFIG_MISSING_PARAMS'\n );\n }\n\n // Returns array of strings\n const configPaths = await githubService.checkIntlayerConfig(\n accessToken,\n owner,\n repository,\n branch\n );\n\n const responseData = formatResponse<{\n hasConfig: boolean;\n configPaths: string[];\n }>({\n data: {\n hasConfig: configPaths.length > 0,\n configPaths: configPaths,\n },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\
|
|
1
|
+
{"version":3,"file":"github.controller.mjs","names":["githubService.getAuthorizationUrl","githubService.exchangeCodeForToken","accessToken: string | undefined","githubService.getUserRepos","githubService.checkIntlayerConfig","githubService.getRepositoryFileContents"],"sources":["../../../src/controllers/github.controller.ts"],"sourcesContent":["import * as githubService from '@services/github.service';\nimport { getGitHubTokenFromUser } from '@services/github.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport { formatResponse, type ResponseData } from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\n\nexport type GitHubGetAuthUrlQuerystring = {\n redirectUri: string;\n login?: string;\n};\n\nexport type GitHubGetAuthUrlResult = ResponseData<{\n authUrl: string;\n}>;\n\nexport const getAuthUrl = async (\n request: FastifyRequest<{ Querystring: GitHubGetAuthUrlQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { redirectUri, login } = request.query;\n\n if (!redirectUri) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_REDIRECT_URI_MISSING'\n );\n }\n\n try {\n const authUrl = githubService.getAuthorizationUrl(redirectUri, login);\n const responseData = formatResponse<{ authUrl: string }>({\n data: { authUrl },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubAuthCallbackBody = {\n code: string;\n};\n\nexport type GitHubAuthCallbackResult = ResponseData<{\n token: string;\n}>;\n\nexport const authCallback = async (\n request: FastifyRequest<{ Body: GitHubAuthCallbackBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { code } = request.body;\n\n if (!code) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_CODE_MISSING'\n );\n }\n\n try {\n const token = await githubService.exchangeCodeForToken(code);\n const responseData = formatResponse<{ token: string }>({\n data: { token },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubListReposQuerystring = {\n token?: string;\n};\n\nexport type GitHubListReposResult = ResponseData<\n githubService.GitHubRepository[]\n>;\n\nexport const listRepos = async (\n request: FastifyRequest<{ Querystring: GitHubListReposQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token } = request.query;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitHubTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_TOKEN_MISSING'\n );\n }\n\n const repos = await githubService.getUserRepos(accessToken);\n const responseData = formatResponse<githubService.GitHubRepository[]>({\n data: repos,\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubCheckConfigBody = {\n token?: string;\n owner: string;\n repository: string;\n branch?: string;\n};\n\nexport type GitHubCheckConfigResult = ResponseData<{\n hasConfig: boolean;\n configPaths: string[]; // Changed from single path to array\n}>;\n\n/**\n * Check if intlayer.config.ts (or candidates) exists in a repository\n */\nexport const checkConfig = async (\n request: FastifyRequest<{ Body: GitHubCheckConfigBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token, owner, repository, branch = 'main' } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitHubTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !owner || !repository) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_CHECK_CONFIG_MISSING_PARAMS'\n );\n }\n\n // Returns array of strings\n const configPaths = await githubService.checkIntlayerConfig(\n accessToken,\n owner,\n repository,\n branch\n );\n\n const responseData = formatResponse<{\n hasConfig: boolean;\n configPaths: string[];\n }>({\n data: {\n hasConfig: configPaths.length > 0,\n configPaths: configPaths,\n },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitHubGetConfigFileBody = {\n token?: string;\n owner: string;\n repository: string;\n branch?: string;\n path?: string;\n};\n\nexport type GitHubGetConfigFileResult = ResponseData<{\n content: string;\n}>;\n\nexport const getConfigFile = async (\n request: FastifyRequest<{ Body: GitHubGetConfigFileBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const {\n token,\n owner,\n repository,\n branch = 'main',\n path = 'intlayer.config.ts',\n } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitHubTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !owner || !repository) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_GET_CONFIG_FILE_MISSING_PARAMS'\n );\n }\n\n const content = await githubService.getRepositoryFileContents(\n accessToken,\n owner,\n repository,\n path,\n branch\n );\n\n if (!content) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITHUB_CONFIG_FILE_NOT_FOUND'\n );\n }\n\n const responseData = formatResponse<{ content: string }>({\n data: { content },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n"],"mappings":";;;;;AAeA,MAAa,aAAa,OACxB,SACA,UACkB;CAClB,MAAM,EAAE,aAAa,UAAU,QAAQ;AAEvC,KAAI,CAAC,YACH,QAAO,aAAa,2BAClB,OACA,8BACD;AAGH,KAAI;EAEF,MAAM,eAAe,eAAoC,EACvD,MAAM,EAAE,SAFMA,oBAAkC,aAAa,MAAM,EAElD,EAClB,CAAC;AACF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB;;;AAYxE,MAAa,eAAe,OAC1B,SACA,UACkB;CAClB,MAAM,EAAE,SAAS,QAAQ;AAEzB,KAAI,CAAC,KACH,QAAO,aAAa,2BAClB,OACA,sBACD;AAGH,KAAI;EAEF,MAAM,eAAe,eAAkC,EAC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AAQ,MAAM;AAErC,KAAI;EACF,IAAIF,cAAkC;AAEtC,MAAI,CAAC,eAAe,OAClB,eAAe,MAAM,uBAAuB,OAAO,OAAO,CAAC,IAAK;AAGlE,MAAI,CAAC,eAAe,CAAC,SAAS,CAAC,WAC7B,QAAO,aAAa,2BAClB,OACA,wCACD;EAGH,MAAM,UAAU,MAAMG,0BACpB,aACA,OACA,YACA,MACA,OACD;AAED,MAAI,CAAC,QACH,QAAO,aAAa,2BAClB,OACA,+BACD;EAGH,MAAM,eAAe,eAAoC,EACvD,MAAM,EAAE,SAAS,EAClB,CAAC;AAEF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { formatResponse } from "../utils/responseData.mjs";
|
|
2
|
+
import { ErrorHandler } from "../utils/errors/ErrorHandler.mjs";
|
|
3
|
+
import { checkIntlayerConfig, exchangeCodeForToken, getAuthorizationUrl, getGitLabTokenFromUser, getRepositoryFileContents, getUserProjects } from "../services/gitlab.service.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/controllers/gitlab.controller.ts
|
|
6
|
+
const getAuthUrl = async (request, reply) => {
|
|
7
|
+
const { redirectUri, instanceUrl, login } = request.query;
|
|
8
|
+
if (!redirectUri) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_REDIRECT_URI_MISSING");
|
|
9
|
+
try {
|
|
10
|
+
const responseData = formatResponse({ data: { authUrl: getAuthorizationUrl(redirectUri, instanceUrl, login) } });
|
|
11
|
+
return reply.send(responseData);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const authCallback = async (request, reply) => {
|
|
17
|
+
const { code, redirectUri, instanceUrl } = request.body;
|
|
18
|
+
if (!code || !redirectUri) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_CODE_MISSING");
|
|
19
|
+
try {
|
|
20
|
+
const responseData = formatResponse({ data: { token: await exchangeCodeForToken(code, redirectUri, instanceUrl) } });
|
|
21
|
+
return reply.send(responseData);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const listProjects = async (request, reply) => {
|
|
27
|
+
const { token, instanceUrl } = request.query;
|
|
28
|
+
const userId = request.locals?.user?.id;
|
|
29
|
+
try {
|
|
30
|
+
let accessToken = token;
|
|
31
|
+
if (!accessToken && userId) accessToken = await getGitLabTokenFromUser(String(userId)) ?? void 0;
|
|
32
|
+
if (!accessToken) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_TOKEN_MISSING");
|
|
33
|
+
const responseData = formatResponse({ data: await getUserProjects(accessToken, instanceUrl) });
|
|
34
|
+
return reply.send(responseData);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Check if intlayer.config.ts (or candidates) exists in a GitLab repository
|
|
41
|
+
*/
|
|
42
|
+
const checkConfig = async (request, reply) => {
|
|
43
|
+
const { token, projectId, branch = "main", instanceUrl } = request.body;
|
|
44
|
+
const userId = request.locals?.user?.id;
|
|
45
|
+
try {
|
|
46
|
+
let accessToken = token;
|
|
47
|
+
if (!accessToken && userId) accessToken = await getGitLabTokenFromUser(String(userId)) ?? void 0;
|
|
48
|
+
if (!accessToken || !projectId) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_CHECK_CONFIG_MISSING_PARAMS");
|
|
49
|
+
const configPaths = await checkIntlayerConfig(accessToken, projectId, branch, instanceUrl);
|
|
50
|
+
const responseData = formatResponse({ data: {
|
|
51
|
+
hasConfig: configPaths.length > 0,
|
|
52
|
+
configPaths
|
|
53
|
+
} });
|
|
54
|
+
return reply.send(responseData);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const getConfigFile = async (request, reply) => {
|
|
60
|
+
const { token, projectId, branch = "main", path = "intlayer.config.ts", instanceUrl } = request.body;
|
|
61
|
+
const userId = request.locals?.user?.id;
|
|
62
|
+
try {
|
|
63
|
+
let accessToken = token;
|
|
64
|
+
if (!accessToken && userId) accessToken = await getGitLabTokenFromUser(String(userId)) ?? void 0;
|
|
65
|
+
if (!accessToken || !projectId) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_GET_CONFIG_FILE_MISSING_PARAMS");
|
|
66
|
+
const content = await getRepositoryFileContents(accessToken, projectId, path, branch, instanceUrl);
|
|
67
|
+
if (!content) return ErrorHandler.handleGenericErrorResponse(reply, "GITLAB_CONFIG_FILE_NOT_FOUND");
|
|
68
|
+
const responseData = formatResponse({ data: { content } });
|
|
69
|
+
return reply.send(responseData);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { authCallback, checkConfig, getAuthUrl, getConfigFile, listProjects };
|
|
77
|
+
//# sourceMappingURL=gitlab.controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab.controller.mjs","names":["gitlabService.getAuthorizationUrl","gitlabService.exchangeCodeForToken","accessToken: string | undefined","gitlabService.getUserProjects","gitlabService.checkIntlayerConfig","gitlabService.getRepositoryFileContents"],"sources":["../../../src/controllers/gitlab.controller.ts"],"sourcesContent":["import * as gitlabService from '@services/gitlab.service';\nimport { getGitLabTokenFromUser } from '@services/gitlab.service';\nimport { type AppError, ErrorHandler } from '@utils/errors';\nimport { formatResponse, type ResponseData } from '@utils/responseData';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\n\nexport type GitLabGetAuthUrlQuerystring = {\n redirectUri: string;\n instanceUrl?: string;\n login?: string;\n};\n\nexport type GitLabGetAuthUrlResult = ResponseData<{\n authUrl: string;\n}>;\n\nexport const getAuthUrl = async (\n request: FastifyRequest<{ Querystring: GitLabGetAuthUrlQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { redirectUri, instanceUrl, login } = request.query;\n\n if (!redirectUri) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_REDIRECT_URI_MISSING'\n );\n }\n\n try {\n const authUrl = gitlabService.getAuthorizationUrl(\n redirectUri,\n instanceUrl,\n login\n );\n const responseData = formatResponse<{ authUrl: string }>({\n data: { authUrl },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitLabAuthCallbackBody = {\n code: string;\n redirectUri: string;\n instanceUrl?: string;\n};\n\nexport type GitLabAuthCallbackResult = ResponseData<{\n token: string;\n}>;\n\nexport const authCallback = async (\n request: FastifyRequest<{ Body: GitLabAuthCallbackBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { code, redirectUri, instanceUrl } = request.body;\n\n if (!code || !redirectUri) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_CODE_MISSING'\n );\n }\n\n try {\n const token = await gitlabService.exchangeCodeForToken(\n code,\n redirectUri,\n instanceUrl\n );\n const responseData = formatResponse<{ token: string }>({\n data: { token },\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitLabListProjectsQuerystring = {\n token?: string;\n instanceUrl?: string;\n};\n\nexport type GitLabListProjectsResult = ResponseData<\n gitlabService.GitLabProject[]\n>;\n\nexport const listProjects = async (\n request: FastifyRequest<{ Querystring: GitLabListProjectsQuerystring }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token, instanceUrl } = request.query;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitLabTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_TOKEN_MISSING'\n );\n }\n\n const projects = await gitlabService.getUserProjects(\n accessToken,\n instanceUrl\n );\n const responseData = formatResponse<gitlabService.GitLabProject[]>({\n data: projects,\n });\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitLabCheckConfigBody = {\n token?: string;\n projectId: number;\n branch?: string;\n instanceUrl?: string;\n};\n\nexport type GitLabCheckConfigResult = ResponseData<{\n hasConfig: boolean;\n configPaths: string[];\n}>;\n\n/**\n * Check if intlayer.config.ts (or candidates) exists in a GitLab repository\n */\nexport const checkConfig = async (\n request: FastifyRequest<{ Body: GitLabCheckConfigBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const { token, projectId, branch = 'main', instanceUrl } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitLabTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !projectId) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_CHECK_CONFIG_MISSING_PARAMS'\n );\n }\n\n const configPaths = await gitlabService.checkIntlayerConfig(\n accessToken,\n projectId,\n branch,\n instanceUrl\n );\n\n const responseData = formatResponse<{\n hasConfig: boolean;\n configPaths: string[];\n }>({\n data: {\n hasConfig: configPaths.length > 0,\n configPaths: configPaths,\n },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n\nexport type GitLabGetConfigFileBody = {\n token?: string;\n projectId: number;\n branch?: string;\n path?: string;\n instanceUrl?: string;\n};\n\nexport type GitLabGetConfigFileResult = ResponseData<{\n content: string;\n}>;\n\nexport const getConfigFile = async (\n request: FastifyRequest<{ Body: GitLabGetConfigFileBody }>,\n reply: FastifyReply\n): Promise<void> => {\n const {\n token,\n projectId,\n branch = 'main',\n path = 'intlayer.config.ts',\n instanceUrl,\n } = request.body;\n const userId = request.locals?.user?.id;\n\n try {\n let accessToken: string | undefined = token;\n\n if (!accessToken && userId) {\n accessToken = (await getGitLabTokenFromUser(String(userId))) ?? undefined;\n }\n\n if (!accessToken || !projectId) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_GET_CONFIG_FILE_MISSING_PARAMS'\n );\n }\n\n const content = await gitlabService.getRepositoryFileContents(\n accessToken,\n projectId,\n path,\n branch,\n instanceUrl\n );\n\n if (!content) {\n return ErrorHandler.handleGenericErrorResponse(\n reply,\n 'GITLAB_CONFIG_FILE_NOT_FOUND'\n );\n }\n\n const responseData = formatResponse<{ content: string }>({\n data: { content },\n });\n\n return reply.send(responseData);\n } catch (error) {\n return ErrorHandler.handleAppErrorResponse(reply, error as AppError);\n }\n};\n"],"mappings":";;;;;AAgBA,MAAa,aAAa,OACxB,SACA,UACkB;CAClB,MAAM,EAAE,aAAa,aAAa,UAAU,QAAQ;AAEpD,KAAI,CAAC,YACH,QAAO,aAAa,2BAClB,OACA,8BACD;AAGH,KAAI;EAMF,MAAM,eAAe,eAAoC,EACvD,MAAM,EAAE,SANMA,oBACd,aACA,aACA,MACD,EAEkB,EAClB,CAAC;AACF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB;;;AAcxE,MAAa,eAAe,OAC1B,SACA,UACkB;CAClB,MAAM,EAAE,MAAM,aAAa,gBAAgB,QAAQ;AAEnD,KAAI,CAAC,QAAQ,CAAC,YACZ,QAAO,aAAa,2BAClB,OACA,sBACD;AAGH,KAAI;EAMF,MAAM,eAAe,eAAkC,EACrD,MAAM,EAAE,OANI,MAAMC,qBAClB,MACA,aACA,YACD,EAEgB,EAChB,CAAC;AACF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,a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AK;AAGlE,MAAI,CAAC,eAAe,CAAC,UACnB,QAAO,aAAa,2BAClB,OACA,wCACD;EAGH,MAAM,UAAU,MAAMG,0BACpB,aACA,WACA,MACA,QACA,YACD;AAED,MAAI,CAAC,QACH,QAAO,aAAa,2BAClB,OACA,+BACD;EAGH,MAAM,eAAe,eAAoC,EACvD,MAAM,EAAE,SAAS,EAClB,CAAC;AAEF,SAAO,MAAM,KAAK,aAAa;UACxB,OAAO;AACd,SAAO,aAAa,uBAAuB,OAAO,MAAkB"}
|
|
@@ -2,10 +2,12 @@ import { logger } from "../logger/index.mjs";
|
|
|
2
2
|
import { formatPaginatedResponse, formatResponse } from "../utils/responseData.mjs";
|
|
3
3
|
import { ErrorHandler } from "../utils/errors/ErrorHandler.mjs";
|
|
4
4
|
import { countProjects, createProject, deleteProjectById, findProjects, getProjectById, updateProjectById } from "../services/project.service.mjs";
|
|
5
|
+
import { triggerAll, triggerSingleWebhook } from "../services/webhook.service.mjs";
|
|
5
6
|
import { hasPermission } from "../utils/permissions.mjs";
|
|
6
7
|
import { getUsersByIds } from "../services/user.service.mjs";
|
|
7
8
|
import { SessionModel } from "../models/session.model.mjs";
|
|
8
9
|
import { getPlanDetails } from "../utils/plan.mjs";
|
|
10
|
+
import { getCIStatus, installCI } from "../services/ci.service.mjs";
|
|
9
11
|
import { getProjectFiltersAndPagination } from "../utils/filtersAndPagination/getProjectFiltersAndPagination.mjs";
|
|
10
12
|
import { mapProjectToAPI, mapProjectsToAPI } from "../utils/mapper/project.mjs";
|
|
11
13
|
import { t } from "fastify-intlayer";
|
|
@@ -184,7 +186,7 @@ const pushProjectConfiguration = async (request, reply) => {
|
|
|
184
186
|
})) return ErrorHandler.handleGenericErrorResponse(reply, "PERMISSION_DENIED");
|
|
185
187
|
try {
|
|
186
188
|
const projectObject = await getProjectById(project.id);
|
|
187
|
-
if (projectConfiguration.ai && projectObject.configuration?.ai?.apiKey
|
|
189
|
+
if (projectConfiguration.ai && projectObject.configuration?.ai?.apiKey) projectConfiguration.ai.apiKey = projectObject.configuration.ai.apiKey;
|
|
188
190
|
projectObject.configuration = projectConfiguration;
|
|
189
191
|
await projectObject.save();
|
|
190
192
|
if (!projectObject.configuration) return ErrorHandler.handleGenericErrorResponse(reply, "PROJECT_UPDATE_FAILED", { projectId: project.id });
|
|
@@ -207,6 +209,70 @@ const pushProjectConfiguration = async (request, reply) => {
|
|
|
207
209
|
}
|
|
208
210
|
};
|
|
209
211
|
/**
|
|
212
|
+
* Triggers CI builds for a project (Git provider pipelines and webhooks)
|
|
213
|
+
*/
|
|
214
|
+
const triggerBuild = async (request, reply) => {
|
|
215
|
+
const { project, roles } = request.locals || {};
|
|
216
|
+
if (!project) return ErrorHandler.handleGenericErrorResponse(reply, "PROJECT_NOT_DEFINED");
|
|
217
|
+
if (!hasPermission(roles || [], "project:write")({
|
|
218
|
+
...request.locals,
|
|
219
|
+
targetProjectIds: [String(project.id)]
|
|
220
|
+
})) return ErrorHandler.handleGenericErrorResponse(reply, "PERMISSION_DENIED");
|
|
221
|
+
try {
|
|
222
|
+
const fullProject = await getProjectById(project.id);
|
|
223
|
+
const results = await triggerAll(fullProject);
|
|
224
|
+
const responseData = formatResponse({
|
|
225
|
+
message: t({
|
|
226
|
+
en: "Build triggers initiated",
|
|
227
|
+
fr: "Déclenchement des builds initié",
|
|
228
|
+
es: "Inicio de los triggers de build"
|
|
229
|
+
}),
|
|
230
|
+
description: t({
|
|
231
|
+
en: "CI pipelines and webhooks have been triggered",
|
|
232
|
+
fr: "Les pipelines CI et webhooks ont été déclenchés",
|
|
233
|
+
es: "Los pipelines CI y webhooks han sido activados"
|
|
234
|
+
}),
|
|
235
|
+
data: { results }
|
|
236
|
+
});
|
|
237
|
+
return reply.send(responseData);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Triggers a single webhook by index
|
|
244
|
+
*/
|
|
245
|
+
const triggerWebhook = async (request, reply) => {
|
|
246
|
+
const { project, roles } = request.locals || {};
|
|
247
|
+
if (!project) return ErrorHandler.handleGenericErrorResponse(reply, "PROJECT_NOT_DEFINED");
|
|
248
|
+
if (!hasPermission(roles || [], "project:write")({
|
|
249
|
+
...request.locals,
|
|
250
|
+
targetProjectIds: [String(project.id)]
|
|
251
|
+
})) return ErrorHandler.handleGenericErrorResponse(reply, "PERMISSION_DENIED");
|
|
252
|
+
try {
|
|
253
|
+
const { webhookIndex } = request.body;
|
|
254
|
+
if (typeof webhookIndex !== "number" || webhookIndex < 0) return ErrorHandler.handleGenericErrorResponse(reply, "INVALID_REQUEST_BODY");
|
|
255
|
+
const fullProject = await getProjectById(project.id);
|
|
256
|
+
const result = await triggerSingleWebhook(fullProject, webhookIndex);
|
|
257
|
+
const responseData = formatResponse({
|
|
258
|
+
message: t({
|
|
259
|
+
en: "Webhook triggered",
|
|
260
|
+
fr: "Webhook déclenché",
|
|
261
|
+
es: "Webhook activado"
|
|
262
|
+
}),
|
|
263
|
+
description: t({
|
|
264
|
+
en: `Webhook "${result.target}" has been triggered`,
|
|
265
|
+
fr: `Le webhook "${result.target}" a été déclenché`,
|
|
266
|
+
es: `El webhook "${result.target}" ha sido activado`
|
|
267
|
+
}),
|
|
268
|
+
data: result
|
|
269
|
+
});
|
|
270
|
+
return reply.send(responseData);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
210
276
|
* Deletes a project from the database by its ID.
|
|
211
277
|
*/
|
|
212
278
|
const deleteProject = async (_request, reply) => {
|
|
@@ -299,7 +365,48 @@ const unselectProject = async (_request, reply) => {
|
|
|
299
365
|
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
300
366
|
}
|
|
301
367
|
};
|
|
368
|
+
/**
|
|
369
|
+
* Get CI configuration status for the current project
|
|
370
|
+
*/
|
|
371
|
+
const getCIConfiguration = async (request, reply) => {
|
|
372
|
+
const { project, user } = request.locals || {};
|
|
373
|
+
if (!project) return ErrorHandler.handleGenericErrorResponse(reply, "PROJECT_NOT_DEFINED");
|
|
374
|
+
if (!user) return ErrorHandler.handleGenericErrorResponse(reply, "USER_NOT_DEFINED");
|
|
375
|
+
try {
|
|
376
|
+
const responseData = formatResponse({ data: await getCIStatus(project) });
|
|
377
|
+
return reply.send(responseData);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Push CI configuration file to the repository
|
|
384
|
+
*/
|
|
385
|
+
const pushCIConfiguration = async (request, reply) => {
|
|
386
|
+
const { project, user } = request.locals || {};
|
|
387
|
+
if (!project) return ErrorHandler.handleGenericErrorResponse(reply, "PROJECT_NOT_DEFINED");
|
|
388
|
+
if (!user) return ErrorHandler.handleGenericErrorResponse(reply, "USER_NOT_DEFINED");
|
|
389
|
+
try {
|
|
390
|
+
await installCI(project);
|
|
391
|
+
const responseData = formatResponse({
|
|
392
|
+
message: t({
|
|
393
|
+
en: "CI configuration installed successfully",
|
|
394
|
+
fr: "Configuration CI installée avec succès",
|
|
395
|
+
es: "Configuración CI instalada con éxito"
|
|
396
|
+
}),
|
|
397
|
+
description: t({
|
|
398
|
+
en: "The CI workflow file has been added to your repository",
|
|
399
|
+
fr: "Le fichier de workflow CI a été ajouté à votre dépôt",
|
|
400
|
+
es: "El archivo de flujo de trabajo CI se ha agregado a su repositorio"
|
|
401
|
+
}),
|
|
402
|
+
data: { success: true }
|
|
403
|
+
});
|
|
404
|
+
return reply.send(responseData);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
return ErrorHandler.handleAppErrorResponse(reply, error);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
302
409
|
|
|
303
410
|
//#endregion
|
|
304
|
-
export { addProject, deleteProject, getProjects, pushProjectConfiguration, selectProject, unselectProject, updateProject, updateProjectMembers };
|
|
411
|
+
export { addProject, deleteProject, getCIConfiguration, getProjects, pushCIConfiguration, pushProjectConfiguration, selectProject, triggerBuild, triggerWebhook, unselectProject, updateProject, updateProjectMembers };
|
|
305
412
|
//# sourceMappingURL=project.controller.mjs.map
|