@intlayer/backend 7.5.8 → 7.5.10
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/README.md +9 -2
- package/dist/assets/utils/AI/askDocQuestion/PROMPT.md +1 -1
- package/dist/assets/utils/AI/askDocQuestion/embeddings/docs/en/cli/init.json +2054 -0
- package/dist/assets/utils/AI/askDocQuestion/embeddings/docs/en/intlayer_with_fastify.json +9 -0
- package/dist/esm/controllers/ai.controller.mjs +95 -128
- package/dist/esm/controllers/ai.controller.mjs.map +1 -1
- package/dist/esm/controllers/dictionary.controller.mjs +86 -198
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/eventListener.controller.mjs +13 -19
- package/dist/esm/controllers/eventListener.controller.mjs.map +1 -1
- package/dist/esm/controllers/github.controller.mjs +77 -0
- package/dist/esm/controllers/github.controller.mjs.map +1 -0
- package/dist/esm/controllers/newsletter.controller.mjs +30 -60
- package/dist/esm/controllers/newsletter.controller.mjs.map +1 -1
- package/dist/esm/controllers/oAuth2.controller.mjs +11 -8
- package/dist/esm/controllers/oAuth2.controller.mjs.map +1 -1
- package/dist/esm/controllers/organization.controller.mjs +100 -225
- package/dist/esm/controllers/organization.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +87 -204
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/projectAccessKey.controller.mjs +38 -71
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
- package/dist/esm/controllers/search.controller.mjs +3 -3
- package/dist/esm/controllers/search.controller.mjs.map +1 -1
- package/dist/esm/controllers/stripe.controller.mjs +34 -67
- package/dist/esm/controllers/stripe.controller.mjs.map +1 -1
- package/dist/esm/controllers/tag.controller.mjs +51 -113
- package/dist/esm/controllers/tag.controller.mjs.map +1 -1
- package/dist/esm/controllers/user.controller.mjs +64 -113
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/export.mjs +2 -1
- package/dist/esm/index.mjs +101 -41
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/oAuth2.middleware.mjs +19 -14
- package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +6 -7
- package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
- package/dist/esm/routes/ai.routes.mjs +19 -15
- package/dist/esm/routes/ai.routes.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +10 -10
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/eventListener.routes.mjs +3 -3
- package/dist/esm/routes/eventListener.routes.mjs.map +1 -1
- package/dist/esm/routes/github.routes.mjs +43 -0
- package/dist/esm/routes/github.routes.mjs.map +1 -0
- package/dist/esm/routes/newsletter.routes.mjs +5 -5
- package/dist/esm/routes/newsletter.routes.mjs.map +1 -1
- package/dist/esm/routes/organization.routes.mjs +11 -11
- package/dist/esm/routes/organization.routes.mjs.map +1 -1
- package/dist/esm/routes/project.routes.mjs +13 -13
- package/dist/esm/routes/project.routes.mjs.map +1 -1
- package/dist/esm/routes/search.routes.mjs +3 -3
- package/dist/esm/routes/search.routes.mjs.map +1 -1
- package/dist/esm/routes/stripe.routes.mjs +5 -5
- package/dist/esm/routes/stripe.routes.mjs.map +1 -1
- package/dist/esm/routes/tags.routes.mjs +6 -6
- package/dist/esm/routes/tags.routes.mjs.map +1 -1
- package/dist/esm/routes/user.routes.mjs +9 -9
- package/dist/esm/routes/user.routes.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +35 -1
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/services/email.service.mjs +1 -1
- package/dist/esm/services/email.service.mjs.map +1 -1
- package/dist/esm/services/github.service.mjs +130 -0
- package/dist/esm/services/github.service.mjs.map +1 -0
- package/dist/esm/services/oAuth2.service.mjs +1 -1
- package/dist/esm/services/subscription.service.mjs +1 -1
- package/dist/esm/services/subscription.service.mjs.map +1 -1
- package/dist/esm/utils/auth/getAuth.mjs +14 -8
- package/dist/esm/utils/auth/getAuth.mjs.map +1 -1
- package/dist/esm/utils/cors.mjs +15 -5
- package/dist/esm/utils/cors.mjs.map +1 -1
- package/dist/esm/utils/errors/ErrorHandler.mjs +32 -4
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
- package/dist/esm/utils/errors/ErrorsClass.mjs +1 -1
- package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +78 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +3 -2
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getDiscussionFiltersAndPagination.mjs +1 -1
- package/dist/esm/utils/filtersAndPagination/getDiscussionFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs +1 -1
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +3 -2
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +3 -2
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +3 -2
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +3 -2
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +28 -1
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mongoDB/connectDB.mjs +1 -1
- package/dist/esm/utils/rateLimiter.mjs +40 -30
- package/dist/esm/utils/rateLimiter.mjs.map +1 -1
- package/dist/esm/webhooks/stripe.webhook.mjs +2 -2
- package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -1
- package/dist/types/controllers/ai.controller.d.ts +29 -12
- package/dist/types/controllers/ai.controller.d.ts.map +1 -1
- package/dist/types/controllers/dictionary.controller.d.ts +23 -13
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/eventListener.controller.d.ts +4 -2
- package/dist/types/controllers/eventListener.controller.d.ts.map +1 -1
- package/dist/types/controllers/github.controller.d.ts +63 -0
- package/dist/types/controllers/github.controller.d.ts.map +1 -0
- package/dist/types/controllers/newsletter.controller.d.ts +8 -7
- package/dist/types/controllers/newsletter.controller.d.ts.map +1 -1
- package/dist/types/controllers/oAuth2.controller.d.ts +4 -2
- package/dist/types/controllers/oAuth2.controller.d.ts.map +1 -1
- package/dist/types/controllers/organization.controller.d.ts +28 -12
- package/dist/types/controllers/organization.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts +21 -16
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/projectAccessKey.controller.d.ts +10 -5
- package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
- package/dist/types/controllers/search.controller.d.ts +4 -2
- package/dist/types/controllers/search.controller.d.ts.map +1 -1
- package/dist/types/controllers/stripe.controller.d.ts +11 -12
- package/dist/types/controllers/stripe.controller.d.ts.map +1 -1
- package/dist/types/controllers/tag.controller.d.ts +14 -9
- package/dist/types/controllers/tag.controller.d.ts.map +1 -1
- package/dist/types/controllers/user.controller.d.ts +22 -9
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/emails/InviteUserEmail.d.ts +4 -4
- package/dist/types/emails/InviteUserEmail.d.ts.map +1 -1
- package/dist/types/emails/MagicLinkEmail.d.ts +4 -4
- package/dist/types/emails/OAuthTokenCreatedEmail.d.ts +4 -4
- 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/emails/Welcome.d.ts.map +1 -1
- package/dist/types/export.d.ts +6 -4
- package/dist/types/middlewares/oAuth2.middleware.d.ts +9 -4
- package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
- package/dist/types/middlewares/sessionAuth.middleware.d.ts +13 -3
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +4 -4
- package/dist/types/models/discussion.model.d.ts +2 -2
- package/dist/types/models/oAuth2.model.d.ts +3 -3
- package/dist/types/routes/ai.routes.d.ts +2 -2
- package/dist/types/routes/ai.routes.d.ts.map +1 -1
- package/dist/types/routes/dictionary.routes.d.ts +2 -2
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/eventListener.routes.d.ts +2 -2
- package/dist/types/routes/eventListener.routes.d.ts.map +1 -1
- package/dist/types/routes/github.routes.d.ts +35 -0
- package/dist/types/routes/github.routes.d.ts.map +1 -0
- package/dist/types/routes/newsletter.routes.d.ts +2 -2
- package/dist/types/routes/newsletter.routes.d.ts.map +1 -1
- package/dist/types/routes/organization.routes.d.ts +2 -2
- package/dist/types/routes/organization.routes.d.ts.map +1 -1
- package/dist/types/routes/project.routes.d.ts +2 -2
- package/dist/types/routes/project.routes.d.ts.map +1 -1
- package/dist/types/routes/search.routes.d.ts +2 -2
- package/dist/types/routes/search.routes.d.ts.map +1 -1
- package/dist/types/routes/stripe.routes.d.ts +2 -2
- package/dist/types/routes/stripe.routes.d.ts.map +1 -1
- package/dist/types/routes/tags.routes.d.ts +2 -2
- package/dist/types/routes/tags.routes.d.ts.map +1 -1
- package/dist/types/routes/user.routes.d.ts +2 -2
- package/dist/types/routes/user.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/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/email.service.d.ts +11 -11
- package/dist/types/services/github.service.d.ts +21 -0
- package/dist/types/services/github.service.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +18 -5
- package/dist/types/types/project.types.d.ts.map +1 -1
- package/dist/types/types/session.types.d.ts +1 -1
- package/dist/types/types/user.types.d.ts +1 -1
- package/dist/types/utils/AI/auditTag/index.d.ts +1 -1
- package/dist/types/utils/auth/getAuth.d.ts.map +1 -1
- package/dist/types/utils/cors.d.ts +2 -2
- package/dist/types/utils/errors/ErrorHandler.d.ts +31 -3
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorsClass.d.ts +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +78 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +8 -4
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDiscussionFiltersAndPagination.d.ts +6 -3
- package/dist/types/utils/filtersAndPagination/getDiscussionFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts +6 -2
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +8 -4
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +8 -4
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +8 -4
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts +6 -2
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mergeFunctionTypes.d.ts.map +1 -1
- package/dist/types/utils/permissions.d.ts +1 -1
- package/dist/types/utils/rateLimiter.d.ts +4 -2
- package/dist/types/utils/rateLimiter.d.ts.map +1 -1
- package/package.json +23 -27
- package/dist/esm/middlewares/request.middleware.mjs +0 -17
- package/dist/esm/middlewares/request.middleware.mjs.map +0 -1
- package/dist/types/middlewares/request.middleware.d.ts +0 -7
- package/dist/types/middlewares/request.middleware.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProjectFiltersAndPagination.mjs","names":["filters: ProjectFilters","sortOptions: Record<string, 1 | -1>"],"sources":["../../../../src/utils/filtersAndPagination/getProjectFiltersAndPagination.ts"],"sourcesContent":["import type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { Project } from '@/types/project.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type ProjectFiltersParams = {\n ids?: string | string[];\n name?: string;\n search?: string;\n organizationId?: string;\n membersIds?: string[];\n sortBy?: string;\n sortOrder?: string;\n /**\n * For admin users, if true, will fetch all projects without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type ProjectFilters = RootFilterQuery<Project>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express request object.\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getProjectFiltersAndPagination = (\n req
|
|
1
|
+
{"version":3,"file":"getProjectFiltersAndPagination.mjs","names":["filters: ProjectFilters","sortOptions: Record<string, 1 | -1>"],"sources":["../../../../src/utils/filtersAndPagination/getProjectFiltersAndPagination.ts"],"sourcesContent":["import type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { FastifyRequest } from 'fastify';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { Project } from '@/types/project.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type ProjectFiltersParams = {\n ids?: string | string[];\n name?: string;\n search?: string;\n organizationId?: string;\n membersIds?: string[];\n sortBy?: string;\n sortOrder?: string;\n /**\n * For admin users, if true, will fetch all projects without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type ProjectFilters = RootFilterQuery<Project>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express or Fastify request object.\n * @param res - Express or Fastify response object (optional, for Express compatibility).\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getProjectFiltersAndPagination = (\n req:\n | Request<FiltersAndPagination<ProjectFiltersParams>>\n | FastifyRequest<{\n Querystring: FiltersAndPagination<ProjectFiltersParams>;\n }>,\n res?: ResponseWithSession\n) => {\n const { filters: filtersRequest, ...pagination } =\n getFiltersAndPaginationFromBody<ProjectFiltersParams>(req as any);\n // Support both Express (res.locals) and Fastify (req.locals)\n const locals = (res as any)?.locals || (req as FastifyRequest).locals || {};\n const { roles, organization } = locals;\n\n let filters: ProjectFilters = {};\n let sortOptions: Record<string, 1 | -1> = { updatedAt: -1 };\n\n const {\n name,\n search,\n ids,\n organizationId,\n membersIds,\n sortBy,\n sortOrder,\n fetchAll,\n } = filtersRequest ?? {};\n\n if (ids) {\n filters = { ...filters, _id: { $in: ensureArrayQueryFilter(ids) } };\n }\n\n if (name) {\n filters = { ...filters, name: new RegExp(name, 'i') };\n }\n\n if (search) {\n const searchRegex = new RegExp(search, 'i');\n filters = {\n ...filters,\n $or: [{ name: searchRegex }],\n };\n }\n\n if (organizationId) {\n filters = { ...filters, organizationId };\n }\n\n if (membersIds) {\n filters = {\n ...filters,\n membersIds: { $in: ensureArrayQueryFilter(membersIds) },\n };\n }\n\n if (sortBy && sortOrder && (sortOrder === 'asc' || sortOrder === 'desc')) {\n sortOptions = { [sortBy]: sortOrder === 'asc' ? 1 : -1 };\n }\n\n if (!(roles.includes('admin') && fetchAll === 'true')) {\n filters = { ...filters, organizationId: organization?.id };\n }\n\n return { filters, sortOptions, ...pagination };\n};\n"],"mappings":";;;;;;;;;;AAgCA,MAAa,kCACX,KAKA,QACG;CACH,MAAM,EAAE,SAAS,gBAAgB,GAAG,eAClC,gCAAsD,IAAW;CAGnE,MAAM,EAAE,OAAO,iBADC,KAAa,UAAW,IAAuB,UAAU,EAAE;CAG3E,IAAIA,UAA0B,EAAE;CAChC,IAAIC,cAAsC,EAAE,WAAW,IAAI;CAE3D,MAAM,EACJ,MACA,QACA,KACA,gBACA,YACA,QACA,WACA,aACE,kBAAkB,EAAE;AAExB,KAAI,IACF,WAAU;EAAE,GAAG;EAAS,KAAK,EAAE,KAAK,uBAAuB,IAAI,EAAE;EAAE;AAGrE,KAAI,KACF,WAAU;EAAE,GAAG;EAAS,MAAM,IAAI,OAAO,MAAM,IAAI;EAAE;AAGvD,KAAI,QAAQ;EACV,MAAM,cAAc,IAAI,OAAO,QAAQ,IAAI;AAC3C,YAAU;GACR,GAAG;GACH,KAAK,CAAC,EAAE,MAAM,aAAa,CAAC;GAC7B;;AAGH,KAAI,eACF,WAAU;EAAE,GAAG;EAAS;EAAgB;AAG1C,KAAI,WACF,WAAU;EACR,GAAG;EACH,YAAY,EAAE,KAAK,uBAAuB,WAAW,EAAE;EACxD;AAGH,KAAI,UAAU,cAAc,cAAc,SAAS,cAAc,QAC/D,eAAc,GAAG,SAAS,cAAc,QAAQ,IAAI,IAAI;AAG1D,KAAI,EAAE,MAAM,SAAS,QAAQ,IAAI,aAAa,QAC5C,WAAU;EAAE,GAAG;EAAS,gBAAgB,cAAc;EAAI;AAG5D,QAAO;EAAE;EAAS;EAAa,GAAG;EAAY"}
|
|
@@ -4,12 +4,13 @@ import { getFiltersAndPaginationFromBody } from "./getFiltersAndPaginationFromBo
|
|
|
4
4
|
//#region src/utils/filtersAndPagination/getTagFiltersAndPagination.ts
|
|
5
5
|
/**
|
|
6
6
|
* Extracts filters and pagination information from the request body.
|
|
7
|
-
* @param req - Express request object.
|
|
7
|
+
* @param req - Express or Fastify request object.
|
|
8
|
+
* @param res - Express or Fastify response object (optional, for Express compatibility).
|
|
8
9
|
* @returns Object containing filters, page, pageSize, and getNumberOfPages functions.
|
|
9
10
|
*/
|
|
10
11
|
const getTagFiltersAndPagination = (req, res) => {
|
|
11
12
|
const { filters: filtersRequest, ...pagination } = getFiltersAndPaginationFromBody(req);
|
|
12
|
-
const { roles, organization } = res.locals;
|
|
13
|
+
const { roles, organization } = res?.locals || req.locals || {};
|
|
13
14
|
let filters = {};
|
|
14
15
|
const sortOptions = { updatedAt: -1 };
|
|
15
16
|
const { name, search, ids, keys, organizationId, fetchAll } = filtersRequest ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTagFiltersAndPagination.mjs","names":["filters: TagFilters","sortOptions: Record<string, 1 | -1>"],"sources":["../../../../src/utils/filtersAndPagination/getTagFiltersAndPagination.ts"],"sourcesContent":["import type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { Tag } from '@/types/tag.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type TagFiltersParams = {\n ids?: string | string[];\n keys?: string | string[];\n name?: string;\n search?: string;\n organizationId?: string;\n /**\n * For admin users, if true, will fetch all tags without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type TagFilters = RootFilterQuery<Tag>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express request object.\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getTagFiltersAndPagination = (\n req
|
|
1
|
+
{"version":3,"file":"getTagFiltersAndPagination.mjs","names":["filters: TagFilters","sortOptions: Record<string, 1 | -1>"],"sources":["../../../../src/utils/filtersAndPagination/getTagFiltersAndPagination.ts"],"sourcesContent":["import type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { FastifyRequest } from 'fastify';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { Tag } from '@/types/tag.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type TagFiltersParams = {\n ids?: string | string[];\n keys?: string | string[];\n name?: string;\n search?: string;\n organizationId?: string;\n /**\n * For admin users, if true, will fetch all tags without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type TagFilters = RootFilterQuery<Tag>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express or Fastify request object.\n * @param res - Express or Fastify response object (optional, for Express compatibility).\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getTagFiltersAndPagination = (\n req:\n | Request<FiltersAndPagination<TagFiltersParams>>\n | FastifyRequest<{ Querystring: FiltersAndPagination<TagFiltersParams> }>,\n res?: ResponseWithSession\n) => {\n const { filters: filtersRequest, ...pagination } =\n getFiltersAndPaginationFromBody<TagFiltersParams>(req as any);\n // Support both Express (res.locals) and Fastify (req.locals)\n const locals = (res as any)?.locals || (req as FastifyRequest).locals || {};\n const { roles, organization } = locals;\n\n let filters: TagFilters = {};\n const sortOptions: Record<string, 1 | -1> = { updatedAt: -1 };\n\n const { name, search, ids, keys, organizationId, fetchAll } =\n filtersRequest ?? {};\n\n if (ids) {\n filters = { ...filters, _id: { $in: ensureArrayQueryFilter(ids) } };\n }\n\n if (keys) {\n filters = { ...filters, key: { $in: ensureArrayQueryFilter(keys) } };\n }\n\n if (name) {\n filters = { ...filters, name: new RegExp(name, 'i') };\n }\n\n if (search) {\n const searchRegex = new RegExp(search, 'i');\n filters = {\n ...filters,\n $or: [\n { name: searchRegex },\n { key: searchRegex },\n { description: searchRegex },\n { instructions: searchRegex },\n ],\n };\n }\n\n if (organizationId) {\n filters = { ...filters, organizationId };\n }\n\n if (!(roles.includes('admin') && fetchAll === 'true')) {\n filters = { ...filters, organizationId: organization?.id };\n }\n\n return { filters, sortOptions, ...pagination };\n};\n"],"mappings":";;;;;;;;;;AA8BA,MAAa,8BACX,KAGA,QACG;CACH,MAAM,EAAE,SAAS,gBAAgB,GAAG,eAClC,gCAAkD,IAAW;CAG/D,MAAM,EAAE,OAAO,iBADC,KAAa,UAAW,IAAuB,UAAU,EAAE;CAG3E,IAAIA,UAAsB,EAAE;CAC5B,MAAMC,cAAsC,EAAE,WAAW,IAAI;CAE7D,MAAM,EAAE,MAAM,QAAQ,KAAK,MAAM,gBAAgB,aAC/C,kBAAkB,EAAE;AAEtB,KAAI,IACF,WAAU;EAAE,GAAG;EAAS,KAAK,EAAE,KAAK,uBAAuB,IAAI,EAAE;EAAE;AAGrE,KAAI,KACF,WAAU;EAAE,GAAG;EAAS,KAAK,EAAE,KAAK,uBAAuB,KAAK,EAAE;EAAE;AAGtE,KAAI,KACF,WAAU;EAAE,GAAG;EAAS,MAAM,IAAI,OAAO,MAAM,IAAI;EAAE;AAGvD,KAAI,QAAQ;EACV,MAAM,cAAc,IAAI,OAAO,QAAQ,IAAI;AAC3C,YAAU;GACR,GAAG;GACH,KAAK;IACH,EAAE,MAAM,aAAa;IACrB,EAAE,KAAK,aAAa;IACpB,EAAE,aAAa,aAAa;IAC5B,EAAE,cAAc,aAAa;IAC9B;GACF;;AAGH,KAAI,eACF,WAAU;EAAE,GAAG;EAAS;EAAgB;AAG1C,KAAI,EAAE,MAAM,SAAS,QAAQ,IAAI,aAAa,QAC5C,WAAU;EAAE,GAAG;EAAS,gBAAgB,cAAc;EAAI;AAG5D,QAAO;EAAE;EAAS;EAAa,GAAG;EAAY"}
|
|
@@ -4,12 +4,13 @@ import { getFiltersAndPaginationFromBody } from "./getFiltersAndPaginationFromBo
|
|
|
4
4
|
//#region src/utils/filtersAndPagination/getUserFiltersAndPagination.ts
|
|
5
5
|
/**
|
|
6
6
|
* Extracts filters and pagination information from the request body.
|
|
7
|
-
* @param req - Express request object.
|
|
7
|
+
* @param req - Express or Fastify request object.
|
|
8
|
+
* @param res - Express or Fastify response object (optional, for Express compatibility).
|
|
8
9
|
* @returns Object containing filters, page, pageSize, and getNumberOfPages functions.
|
|
9
10
|
*/
|
|
10
11
|
const getUserFiltersAndPagination = (req, res) => {
|
|
11
12
|
const { filters: filtersRequest, ...pagination } = getFiltersAndPaginationFromBody(req);
|
|
12
|
-
const { roles, organization } = res.locals;
|
|
13
|
+
const { roles, organization } = res?.locals || req.locals || {};
|
|
13
14
|
let filters = {};
|
|
14
15
|
let sortOptions = { updatedAt: -1 };
|
|
15
16
|
const { firstName, lastName, email, emailVerified, role, search, sortBy, sortOrder, ids, fetchAll } = filtersRequest ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUserFiltersAndPagination.mjs","names":["sortOptions: Record<string, 1 | -1>","secureMembersIds: string[]"],"sources":["../../../../src/utils/filtersAndPagination/getUserFiltersAndPagination.ts"],"sourcesContent":["import type { GetUsersResult } from '@controllers/user.controller';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { User } from '@/types/user.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type UserFiltersParam = {\n ids?: string | string[];\n firstName?: string;\n lastName?: string;\n email?: string;\n emailVerified?: string;\n role?: string;\n search?: string;\n sortBy?: string;\n sortOrder?: string;\n /**\n * For admin users, if true, will fetch all users without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type UserFilters = RootFilterQuery<User>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express request object.\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getUserFiltersAndPagination = (\n req
|
|
1
|
+
{"version":3,"file":"getUserFiltersAndPagination.mjs","names":["sortOptions: Record<string, 1 | -1>","secureMembersIds: string[]"],"sources":["../../../../src/utils/filtersAndPagination/getUserFiltersAndPagination.ts"],"sourcesContent":["import type { GetUsersResult } from '@controllers/user.controller';\nimport type { ResponseWithSession } from '@middlewares/sessionAuth.middleware';\nimport { ensureArrayQueryFilter } from '@utils/ensureArrayQueryFilter';\nimport type { Request } from 'express';\nimport type { FastifyRequest } from 'fastify';\nimport type { RootFilterQuery } from 'mongoose';\nimport type { User } from '@/types/user.types';\nimport {\n type FiltersAndPagination,\n getFiltersAndPaginationFromBody,\n} from './getFiltersAndPaginationFromBody';\n\nexport type UserFiltersParam = {\n ids?: string | string[];\n firstName?: string;\n lastName?: string;\n email?: string;\n emailVerified?: string;\n role?: string;\n search?: string;\n sortBy?: string;\n sortOrder?: string;\n /**\n * For admin users, if true, will fetch all users without filtering by organization\n */\n fetchAll?: 'true' | 'false';\n};\nexport type UserFilters = RootFilterQuery<User>;\n\n/**\n * Extracts filters and pagination information from the request body.\n * @param req - Express or Fastify request object.\n * @param res - Express or Fastify response object (optional, for Express compatibility).\n * @returns Object containing filters, page, pageSize, and getNumberOfPages functions.\n */\nexport const getUserFiltersAndPagination = (\n req:\n | Request<FiltersAndPagination<UserFiltersParam>>\n | FastifyRequest<{ Querystring: FiltersAndPagination<UserFiltersParam> }>,\n res?: ResponseWithSession<GetUsersResult>\n) => {\n const { filters: filtersRequest, ...pagination } =\n getFiltersAndPaginationFromBody<UserFiltersParam>(req as any);\n // Support both Express (res.locals) and Fastify (req.locals)\n const locals = (res as any)?.locals || (req as FastifyRequest).locals || {};\n const { roles, organization } = locals;\n\n let filters = {};\n let sortOptions: Record<string, 1 | -1> = { updatedAt: -1 };\n\n const {\n firstName,\n lastName,\n email,\n emailVerified,\n role,\n search,\n sortBy,\n sortOrder,\n ids,\n fetchAll,\n } = filtersRequest ?? {};\n\n if (ids) {\n filters = { ...filters, _id: { $in: ensureArrayQueryFilter(ids) } };\n\n if (!(roles.includes('admin') && fetchAll === 'true')) {\n const secureMembersIds: string[] =\n ensureArrayQueryFilter(ids)?.filter((id) =>\n organization?.membersIds?.map(String).includes(id)\n ) ?? [];\n\n filters = {\n ...filters,\n _id: {\n $in: secureMembersIds,\n },\n };\n }\n }\n\n if (firstName) {\n filters = { ...filters, firstName: new RegExp(firstName, 'i') };\n }\n\n if (lastName) {\n filters = { ...filters, lastName: new RegExp(lastName, 'i') };\n }\n\n if (email) {\n filters = { ...filters, email: new RegExp(email, 'i') };\n }\n\n if (emailVerified !== undefined) {\n const isVerified = emailVerified === 'true';\n filters = { ...filters, emailVerified: isVerified };\n }\n\n if (role) {\n filters = { ...filters, role };\n }\n\n if (search) {\n const searchRegex = new RegExp(search, 'i');\n filters = {\n ...filters,\n $or: [\n { firstName: searchRegex },\n { lastName: searchRegex },\n { email: searchRegex },\n { name: searchRegex },\n ],\n };\n }\n\n if (sortBy && sortOrder && (sortOrder === 'asc' || sortOrder === 'desc')) {\n sortOptions = { [sortBy]: sortOrder === 'asc' ? 1 : -1 };\n }\n\n return { filters, sortOptions, ...pagination };\n};\n"],"mappings":";;;;;;;;;;AAmCA,MAAa,+BACX,KAGA,QACG;CACH,MAAM,EAAE,SAAS,gBAAgB,GAAG,eAClC,gCAAkD,IAAW;CAG/D,MAAM,EAAE,OAAO,iBADC,KAAa,UAAW,IAAuB,UAAU,EAAE;CAG3E,IAAI,UAAU,EAAE;CAChB,IAAIA,cAAsC,EAAE,WAAW,IAAI;CAE3D,MAAM,EACJ,WACA,UACA,OACA,eACA,MACA,QACA,QACA,WACA,KACA,aACE,kBAAkB,EAAE;AAExB,KAAI,KAAK;AACP,YAAU;GAAE,GAAG;GAAS,KAAK,EAAE,KAAK,uBAAuB,IAAI,EAAE;GAAE;AAEnE,MAAI,EAAE,MAAM,SAAS,QAAQ,IAAI,aAAa,SAAS;GACrD,MAAMC,mBACJ,uBAAuB,IAAI,EAAE,QAAQ,OACnC,cAAc,YAAY,IAAI,OAAO,CAAC,SAAS,GAAG,CACnD,IAAI,EAAE;AAET,aAAU;IACR,GAAG;IACH,KAAK,EACH,KAAK,kBACN;IACF;;;AAIL,KAAI,UACF,WAAU;EAAE,GAAG;EAAS,WAAW,IAAI,OAAO,WAAW,IAAI;EAAE;AAGjE,KAAI,SACF,WAAU;EAAE,GAAG;EAAS,UAAU,IAAI,OAAO,UAAU,IAAI;EAAE;AAG/D,KAAI,MACF,WAAU;EAAE,GAAG;EAAS,OAAO,IAAI,OAAO,OAAO,IAAI;EAAE;AAGzD,KAAI,kBAAkB,QAAW;EAC/B,MAAM,aAAa,kBAAkB;AACrC,YAAU;GAAE,GAAG;GAAS,eAAe;GAAY;;AAGrD,KAAI,KACF,WAAU;EAAE,GAAG;EAAS;EAAM;AAGhC,KAAI,QAAQ;EACV,MAAM,cAAc,IAAI,OAAO,QAAQ,IAAI;AAC3C,YAAU;GACR,GAAG;GACH,KAAK;IACH,EAAE,WAAW,aAAa;IAC1B,EAAE,UAAU,aAAa;IACzB,EAAE,OAAO,aAAa;IACtB,EAAE,MAAM,aAAa;IACtB;GACF;;AAGH,KAAI,UAAU,cAAc,cAAc,SAAS,cAAc,QAC/D,eAAc,GAAG,SAAS,cAAc,QAAQ,IAAI,IAAI;AAG1D,QAAO;EAAE;EAAS;EAAa,GAAG;EAAY"}
|
|
@@ -2,6 +2,31 @@ import { ensureMongoDocumentToObject } from "../ensureMongoDocumentToObject.mjs"
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/mapper/project.ts
|
|
4
4
|
/**
|
|
5
|
+
* Sanitizes the AI configuration by removing the API key and adding a flag.
|
|
6
|
+
* @param aiConfig - The AI configuration to sanitize.
|
|
7
|
+
* @returns The sanitized AI configuration.
|
|
8
|
+
*/
|
|
9
|
+
const sanitizeAIConfig = (aiConfig) => {
|
|
10
|
+
if (!aiConfig) return aiConfig;
|
|
11
|
+
const { apiKey, ...rest } = aiConfig;
|
|
12
|
+
return {
|
|
13
|
+
...rest,
|
|
14
|
+
apiKeyConfigured: !!apiKey
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Sanitizes the project configuration by removing sensitive data.
|
|
19
|
+
* @param configuration - The project configuration to sanitize.
|
|
20
|
+
* @returns The sanitized project configuration.
|
|
21
|
+
*/
|
|
22
|
+
const sanitizeProjectConfiguration = (configuration) => {
|
|
23
|
+
if (!configuration) return configuration;
|
|
24
|
+
return {
|
|
25
|
+
...configuration,
|
|
26
|
+
ai: sanitizeAIConfig(configuration.ai)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
5
30
|
* Maps a project to an API response.
|
|
6
31
|
* @param project - The project to map.
|
|
7
32
|
* @param - Whether the user is an admin of the project.
|
|
@@ -9,7 +34,9 @@ import { ensureMongoDocumentToObject } from "../ensureMongoDocumentToObject.mjs"
|
|
|
9
34
|
*/
|
|
10
35
|
const mapProjectToAPI = (project) => {
|
|
11
36
|
if (!project) return null;
|
|
12
|
-
|
|
37
|
+
const projectObject = ensureMongoDocumentToObject(project);
|
|
38
|
+
if (projectObject.configuration) projectObject.configuration = sanitizeProjectConfiguration(projectObject.configuration);
|
|
39
|
+
return projectObject;
|
|
13
40
|
};
|
|
14
41
|
/**
|
|
15
42
|
* Formats an array of projects for API response. Removes sensitive information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.mjs","names":[],"sources":["../../../../src/utils/mapper/project.ts"],"sourcesContent":["import { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport type { Project, ProjectAPI } from '@/types/project.types';\n\n/**\n * Maps a project to an API response.\n * @param project - The project to map.\n * @param - Whether the user is an admin of the project.\n * @returns The project mapped to an API response.\n */\nexport const mapProjectToAPI = <T extends Project | ProjectAPI | null>(\n project?: T\n): T extends null ? null : ProjectAPI => {\n if (!project) {\n return null as any;\n }\n\n const projectObject = ensureMongoDocumentToObject(project);\n\n return projectObject as any;\n};\n\n/**\n * Formats an array of projects for API response. Removes sensitive information.\n * @param projects - The array of project objects to format.\n * @param user - The user object.\n * @param - Whether the user is an admin of the project.\n * @returns The formatted array of user objects.\n */\nexport const mapProjectsToAPI = (\n projects: (Project | ProjectAPI)[]\n): ProjectAPI[] =>\n projects.map(mapProjectToAPI).filter(Boolean) as ProjectAPI[];\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"project.mjs","names":[],"sources":["../../../../src/utils/mapper/project.ts"],"sourcesContent":["import { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport type { Project, ProjectAPI } from '@/types/project.types';\n\n/**\n * Sanitizes the AI configuration by removing the API key and adding a flag.\n * @param aiConfig - The AI configuration to sanitize.\n * @returns The sanitized AI configuration.\n */\nconst sanitizeAIConfig = (aiConfig?: any) => {\n if (!aiConfig) {\n return aiConfig;\n }\n\n const { apiKey, ...rest } = aiConfig;\n return {\n ...rest,\n apiKeyConfigured: !!apiKey,\n };\n};\n\n/**\n * Sanitizes the project configuration by removing sensitive data.\n * @param configuration - The project configuration to sanitize.\n * @returns The sanitized project configuration.\n */\nconst sanitizeProjectConfiguration = (\n configuration?: Project['configuration']\n) => {\n if (!configuration) {\n return configuration;\n }\n\n return {\n ...configuration,\n ai: sanitizeAIConfig(configuration.ai),\n };\n};\n\n/**\n * Maps a project to an API response.\n * @param project - The project to map.\n * @param - Whether the user is an admin of the project.\n * @returns The project mapped to an API response.\n */\nexport const mapProjectToAPI = <T extends Project | ProjectAPI | null>(\n project?: T\n): T extends null ? null : ProjectAPI => {\n if (!project) {\n return null as any;\n }\n\n const projectObject = ensureMongoDocumentToObject(project);\n\n // Sanitize configuration to remove sensitive API key\n if (projectObject.configuration) {\n projectObject.configuration = sanitizeProjectConfiguration(\n projectObject.configuration\n ) as any;\n }\n\n return projectObject as any;\n};\n\n/**\n * Formats an array of projects for API response. Removes sensitive information.\n * @param projects - The array of project objects to format.\n * @param user - The user object.\n * @param - Whether the user is an admin of the project.\n * @returns The formatted array of user objects.\n */\nexport const mapProjectsToAPI = (\n projects: (Project | ProjectAPI)[]\n): ProjectAPI[] =>\n projects.map(mapProjectToAPI).filter(Boolean) as ProjectAPI[];\n"],"mappings":";;;;;;;;AAQA,MAAM,oBAAoB,aAAmB;AAC3C,KAAI,CAAC,SACH,QAAO;CAGT,MAAM,EAAE,QAAQ,GAAG,SAAS;AAC5B,QAAO;EACL,GAAG;EACH,kBAAkB,CAAC,CAAC;EACrB;;;;;;;AAQH,MAAM,gCACJ,kBACG;AACH,KAAI,CAAC,cACH,QAAO;AAGT,QAAO;EACL,GAAG;EACH,IAAI,iBAAiB,cAAc,GAAG;EACvC;;;;;;;;AASH,MAAa,mBACX,YACuC;AACvC,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,gBAAgB,4BAA4B,QAAQ;AAG1D,KAAI,cAAc,cAChB,eAAc,gBAAgB,6BAC5B,cAAc,cACf;AAGH,QAAO;;;;;;;;;AAUT,MAAa,oBACX,aAEA,SAAS,IAAI,gBAAgB,CAAC,OAAO,QAAQ"}
|
|
@@ -3,8 +3,8 @@ import { logger } from "../../logger/index.mjs";
|
|
|
3
3
|
import { OrganizationModel } from "../../models/organization.model.mjs";
|
|
4
4
|
import { ProjectModel } from "../../models/project.model.mjs";
|
|
5
5
|
import { TagModel } from "../../models/tag.model.mjs";
|
|
6
|
-
import { UserModel } from "../../models/user.model.mjs";
|
|
7
6
|
import { OAuth2AccessTokenModel } from "../../models/oAuth2.model.mjs";
|
|
7
|
+
import { UserModel } from "../../models/user.model.mjs";
|
|
8
8
|
import { connect } from "mongoose";
|
|
9
9
|
|
|
10
10
|
//#region src/utils/mongoDB/connectDB.ts
|
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
import { ErrorHandler } from "./errors/ErrorHandler.mjs";
|
|
2
|
-
import rateLimit, { ipKeyGenerator } from "express-rate-limit";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/rateLimiter.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const normalizeIP = (ip) => {
|
|
5
|
+
if (!ip) return "unknown";
|
|
6
|
+
if (ip.startsWith("::ffff:")) return ip.substring(7);
|
|
7
|
+
return ip;
|
|
8
|
+
};
|
|
9
|
+
const ipLimiter = {
|
|
10
|
+
max: 500,
|
|
11
|
+
timeWindow: 60 * 1e3,
|
|
12
|
+
enableDraftSpec: true,
|
|
13
|
+
keyGenerator: (request) => {
|
|
14
|
+
const ip = request.ip ?? request.socket?.remoteAddress ?? request.headers["x-forwarded-for"] ?? "unknown";
|
|
15
|
+
return normalizeIP(typeof ip === "string" ? ip : ip[0]);
|
|
12
16
|
},
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
ErrorHandler.
|
|
16
|
-
limit: `${
|
|
17
|
-
retryAfter
|
|
18
|
-
remaining
|
|
17
|
+
errorResponseBuilder: (_request, context) => {
|
|
18
|
+
const retryAfter = Math.ceil(context.ttl / 1e3);
|
|
19
|
+
const errorResponse = ErrorHandler.formatGenericErrorResponse("RATE_LIMIT_EXCEEDED", {
|
|
20
|
+
limit: `${context.max} per minute`,
|
|
21
|
+
retryAfter
|
|
19
22
|
});
|
|
23
|
+
return {
|
|
24
|
+
statusCode: errorResponse.status,
|
|
25
|
+
...errorResponse
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
};
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
keyGenerator: (
|
|
30
|
-
|
|
29
|
+
const unauthenticatedChatBotLimiter = {
|
|
30
|
+
max: 3,
|
|
31
|
+
timeWindow: 3600 * 1e3,
|
|
32
|
+
enableDraftSpec: true,
|
|
33
|
+
allowList: (request) => {
|
|
34
|
+
return Boolean(request.locals?.user);
|
|
35
|
+
},
|
|
36
|
+
keyGenerator: (request) => {
|
|
37
|
+
const ip = request.ip ?? request.socket?.remoteAddress ?? request.headers["x-forwarded-for"] ?? "unknown";
|
|
38
|
+
return normalizeIP(typeof ip === "string" ? ip : ip[0]);
|
|
31
39
|
},
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
ErrorHandler.
|
|
35
|
-
limit: `${
|
|
36
|
-
retryAfter
|
|
37
|
-
remaining
|
|
40
|
+
errorResponseBuilder: (_request, context) => {
|
|
41
|
+
const retryAfter = Math.ceil(context.ttl / 1e3);
|
|
42
|
+
const errorResponse = ErrorHandler.formatGenericErrorResponse("RATE_LIMIT_EXCEEDED_UNAUTHENTICATED", {
|
|
43
|
+
limit: `${context.max} per hour`,
|
|
44
|
+
retryAfter
|
|
38
45
|
});
|
|
46
|
+
return {
|
|
47
|
+
statusCode: errorResponse.status,
|
|
48
|
+
...errorResponse
|
|
49
|
+
};
|
|
39
50
|
}
|
|
40
51
|
};
|
|
41
|
-
const unauthenticatedChatBotLimiter = rateLimit(unauthenticatedChatBotLimiterOptions);
|
|
42
52
|
|
|
43
53
|
//#endregion
|
|
44
54
|
export { ipLimiter, unauthenticatedChatBotLimiter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rateLimiter.mjs","names":["
|
|
1
|
+
{"version":3,"file":"rateLimiter.mjs","names":["ipLimiter: RateLimitOptions","unauthenticatedChatBotLimiter: RateLimitOptions"],"sources":["../../../src/utils/rateLimiter.ts"],"sourcesContent":["import type { RateLimitOptions } from '@fastify/rate-limit';\nimport type { FastifyRequest } from 'fastify';\nimport { ErrorHandler } from './errors';\n\n// Helper function to normalize IP addresses (similar to express-rate-limit's ipKeyGenerator)\nconst normalizeIP = (ip: string | undefined): string => {\n if (!ip) return 'unknown';\n // Normalize IPv6 mapped IPv4 addresses\n if (ip.startsWith('::ffff:')) {\n return ip.substring(7);\n }\n return ip;\n};\n\n// -------------------------------------------------------------\n// Create the rate-limiter instances once at module load-time so\n// that the hit counters are shared across every incoming request.\n// -------------------------------------------------------------\n\nexport const ipLimiter: RateLimitOptions = {\n max: 500, // 500 requests\n timeWindow: 60 * 1000, // 1-minute window\n enableDraftSpec: true,\n // Use a custom key generator that handles proxy headers securely\n keyGenerator: (request: FastifyRequest) => {\n const ip =\n request.ip ??\n request.socket?.remoteAddress ??\n request.headers['x-forwarded-for'] ??\n 'unknown';\n return normalizeIP(typeof ip === 'string' ? ip : ip[0]);\n },\n errorResponseBuilder: (_request: FastifyRequest, context) => {\n // context.ttl is already the remaining time in milliseconds\n const retryAfter = Math.ceil(context.ttl / 1000);\n const errorResponse = ErrorHandler.formatGenericErrorResponse(\n 'RATE_LIMIT_EXCEEDED',\n {\n limit: `${context.max} per minute`,\n retryAfter,\n }\n );\n return {\n statusCode: errorResponse.status,\n ...errorResponse,\n };\n },\n};\n\nexport const unauthenticatedChatBotLimiter: RateLimitOptions = {\n max: 3, // 3 requests\n timeWindow: 60 * 60 * 1000, // 1-hour window\n enableDraftSpec: true,\n // Skip rate limiting if user is authenticated (allowList returns true to skip)\n allowList: (request: FastifyRequest) => {\n return Boolean((request as any).locals?.user);\n },\n // Use a custom key generator that handles proxy headers securely\n keyGenerator: (request: FastifyRequest) => {\n const ip =\n request.ip ??\n request.socket?.remoteAddress ??\n request.headers['x-forwarded-for'] ??\n 'unknown';\n return normalizeIP(typeof ip === 'string' ? ip : ip[0]);\n },\n errorResponseBuilder: (_request: FastifyRequest, context) => {\n // context.ttl is already the remaining time in milliseconds\n const retryAfter = Math.ceil(context.ttl / 1000);\n const errorResponse = ErrorHandler.formatGenericErrorResponse(\n 'RATE_LIMIT_EXCEEDED_UNAUTHENTICATED',\n {\n limit: `${context.max} per hour`,\n retryAfter,\n }\n );\n return {\n statusCode: errorResponse.status,\n ...errorResponse,\n };\n },\n};\n"],"mappings":";;;AAKA,MAAM,eAAe,OAAmC;AACtD,KAAI,CAAC,GAAI,QAAO;AAEhB,KAAI,GAAG,WAAW,UAAU,CAC1B,QAAO,GAAG,UAAU,EAAE;AAExB,QAAO;;AAQT,MAAaA,YAA8B;CACzC,KAAK;CACL,YAAY,KAAK;CACjB,iBAAiB;CAEjB,eAAe,YAA4B;EACzC,MAAM,KACJ,QAAQ,MACR,QAAQ,QAAQ,iBAChB,QAAQ,QAAQ,sBAChB;AACF,SAAO,YAAY,OAAO,OAAO,WAAW,KAAK,GAAG,GAAG;;CAEzD,uBAAuB,UAA0B,YAAY;EAE3D,MAAM,aAAa,KAAK,KAAK,QAAQ,MAAM,IAAK;EAChD,MAAM,gBAAgB,aAAa,2BACjC,uBACA;GACE,OAAO,GAAG,QAAQ,IAAI;GACtB;GACD,CACF;AACD,SAAO;GACL,YAAY,cAAc;GAC1B,GAAG;GACJ;;CAEJ;AAED,MAAaC,gCAAkD;CAC7D,KAAK;CACL,YAAY,OAAU;CACtB,iBAAiB;CAEjB,YAAY,YAA4B;AACtC,SAAO,QAAS,QAAgB,QAAQ,KAAK;;CAG/C,eAAe,YAA4B;EACzC,MAAM,KACJ,QAAQ,MACR,QAAQ,QAAQ,iBAChB,QAAQ,QAAQ,sBAChB;AACF,SAAO,YAAY,OAAO,OAAO,WAAW,KAAK,GAAG,GAAG;;CAEzD,uBAAuB,UAA0B,YAAY;EAE3D,MAAM,aAAa,KAAK,KAAK,QAAQ,MAAM,IAAK;EAChD,MAAM,gBAAgB,aAAa,2BACjC,uCACA;GACE,OAAO,GAAG,QAAQ,IAAI;GACtB;GACD,CACF;AACD,SAAO;GACL,YAAY,cAAc;GAC1B,GAAG;GACJ;;CAEJ"}
|
|
@@ -44,7 +44,7 @@ const stripeWebhook = async (req, res) => {
|
|
|
44
44
|
to: user.email,
|
|
45
45
|
email: user.email,
|
|
46
46
|
subscriptionStartDate: (/* @__PURE__ */ new Date()).toLocaleDateString(),
|
|
47
|
-
manageSubscriptionLink: `${process.env.
|
|
47
|
+
manageSubscriptionLink: `${process.env.APP_URL}/organization`,
|
|
48
48
|
username: user.name,
|
|
49
49
|
organizationName: organization.name,
|
|
50
50
|
planName: organization.plan?.type ?? "Unknown"
|
|
@@ -54,7 +54,7 @@ const stripeWebhook = async (req, res) => {
|
|
|
54
54
|
to: user.email,
|
|
55
55
|
email: user.email,
|
|
56
56
|
cancellationDate: (/* @__PURE__ */ new Date(subscription.current_period_end * 1e3)).toLocaleDateString(),
|
|
57
|
-
reactivateLink: `${process.env.
|
|
57
|
+
reactivateLink: `${process.env.APP_URL}/pricing`,
|
|
58
58
|
username: user.name,
|
|
59
59
|
organizationName: organization.name,
|
|
60
60
|
planName: organization.plan?.type ?? "Unknown"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.webhook.mjs","names":["event: Stripe.Event","emailService.sendEmail"],"sources":["../../../src/webhooks/stripe.webhook.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { logger } from '@logger';\nimport * as emailService from '@services/email.service';\nimport { getOrganizationById } from '@services/organization.service';\nimport {\n addOrUpdateSubscription,\n cancelSubscription,\n changeSubscriptionStatus,\n} from '@services/subscription.service';\nimport { getUserById } from '@services/user.service';\nimport { GenericError } from '@utils/errors';\nimport type { Request, Response } from 'express';\nimport { Stripe } from 'stripe';\nimport type { Plan } from '@/types/plan.types';\n\ntype SubscriptionMetadata = {\n locale: Locale; // Localization setting (e.g., 'en', 'fr', 'es')\n userId: string; // ID of the user associated with the subscription\n organizationId: string; // ID of the organization associated with the subscription\n};\n\n/**\n * Stripe webhook handler for processing subscription and invoice events.\n * @param req - Express request object.\n * @param res - Express response object.\n */\nexport const stripeWebhook = async (req: Request, res: Response) => {\n // Initialize the Stripe client with the secret key\n const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);\n\n const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET!; // Webhook secret for verifying event signatures\n const sig = req.headers['stripe-signature']!; // Retrieve the signature from the webhook request headers\n\n let event: Stripe.Event;\n\n // Verify the webhook signature to ensure the request is authentic\n try {\n event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);\n } catch (err) {\n // Respond with a 400 status code if the signature verification fails\n res.status(400).send(`Webhook Error: ${(err as Error).message}`);\n return;\n }\n\n // Utility function to extract metadata from a Stripe customer\n const extractMetadata = async (customerId: string) => {\n const customer = await stripe.customers.retrieve(customerId); // Retrieve customer details from Stripe\n return (customer as Stripe.Customer).metadata as SubscriptionMetadata; // Return the metadata object\n };\n\n // Handles subscription-related events (creation, update, deletion)\n const handleSubscriptionEvent = async (\n subscription: Stripe.Subscription,\n statusOverride?: Plan['status'] // Optionally override the subscription status\n ) => {\n const { id: subscriptionId, customer } = subscription;\n const priceId = subscription.items.data[0]?.price?.id; // Extract the price ID from subscription items\n\n if (!customer) {\n throw new GenericError('STRIPE_SUBSCRIPTION_NO_CUSTOMER');\n }\n\n const customerId = customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId); // Extract metadata from the customer\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n const organization = await getOrganizationById(organizationId); // Fetch organization details by ID\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND');\n }\n\n const user = await getUserById(userId);\n\n if (!user) {\n throw new GenericError('USER_NOT_FOUND');\n }\n\n const status = statusOverride ?? subscription.status; // Use the provided status override or the subscription's status\n\n // Update or create a subscription record in the database\n await addOrUpdateSubscription(\n subscriptionId,\n priceId!,\n customerId,\n userId,\n organization,\n status\n );\n\n if (status === 'active') {\n await emailService.sendEmail({\n type: 'subscriptionPaymentSuccess',\n to: user.email,\n email: user.email,\n subscriptionStartDate: new Date().toLocaleDateString(),\n manageSubscriptionLink: `${process.env.CLIENT_URL}/dashboard/organization`,\n username: user.name,\n organizationName: organization.name,\n planName: organization.plan?.type ?? 'Unknown',\n });\n }\n if (status === 'canceled') {\n await emailService.sendEmail({\n type: 'subscriptionPaymentCancellation',\n to: user.email,\n email: user.email,\n cancellationDate: new Date(\n (subscription as any).current_period_end * 1000\n ).toLocaleDateString(),\n reactivateLink: `${process.env.CLIENT_URL}/pricing`,\n username: user.name,\n organizationName: organization.name,\n planName: organization.plan?.type ?? 'Unknown',\n });\n }\n };\n\n // Handles invoice-related events (payment success or failure)\n const handleInvoiceEvent = async (\n invoice: Stripe.Invoice,\n status: 'active' | 'incomplete'\n ) => {\n const subscriptionId =\n typeof (invoice as any).subscription === 'string'\n ? (invoice as any).subscription\n : (invoice as any).subscription?.id; // Extract the subscription ID from the invoice\n if (!subscriptionId) {\n logger.warn('Subscription ID is undefined in invoice.');\n return;\n }\n\n // Retrieve the subscription details from Stripe\n const subscription = await stripe.subscriptions.retrieve(subscriptionId);\n const organization = await getOrganizationById(\n subscription.metadata.organizationId\n );\n\n // Prevent duplicate subscriptions by canceling conflicting subscriptions\n if (\n organization.plan?.subscriptionId &&\n organization.plan.subscriptionId !== subscriptionId\n ) {\n await stripe.subscriptions.cancel(subscriptionId);\n }\n\n const customerId = invoice.customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Update the subscription status in the database\n await changeSubscriptionStatus(\n subscriptionId,\n status,\n userId,\n organizationId\n );\n };\n\n try {\n // Log the event type for debugging and monitoring\n logger.info(`Triggered event type ${event.type}`);\n\n // Handle specific event types\n switch (event.type) {\n case 'customer.subscription.created': {\n logger.info(`Handled event type ${event.type}`);\n // Process a new subscription creation event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.updated': {\n logger.info(`Handled event type ${event.type}`);\n // Process a subscription update event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.deleted': {\n logger.info(`Handled event type ${event.type}`);\n const subscription = event.data\n .object as unknown as Stripe.Subscription;\n const customerId = subscription.customer as string;\n const { locale, organizationId } = await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Handle subscription deletion by canceling it in the database\n await cancelSubscription(subscription.id, organizationId);\n break;\n }\n case 'invoice.payment_succeeded': {\n logger.info(`Handled event type ${event.type}`);\n // Handle successful invoice payment\n await handleInvoiceEvent(event.data.object as Stripe.Invoice, 'active');\n break;\n }\n case 'invoice.payment_failed': {\n logger.info(`Handled event type ${event.type}`);\n // Handle failed invoice payment\n await handleInvoiceEvent(\n event.data.object as Stripe.Invoice,\n 'incomplete'\n );\n break;\n }\n default:\n // Log unhandled event types for visibility\n logger.info(`Unhandled event type ${event.type}`);\n }\n\n // Respond to Stripe to confirm the event was processed successfully\n res.send();\n } catch (error) {\n // Log errors for debugging and respond with a 500 status code\n logger.error(\n `Error handling event ${event.type}: ${(error as Error).message}`\n );\n res.status(500).send('Server Error');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,OAAO,KAAc,QAAkB;CAElE,MAAM,SAAS,IAAI,OAAO,QAAQ,IAAI,kBAAmB;CAEzD,MAAM,iBAAiB,QAAQ,IA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S;AACvE;GAEF,KAAK;AACH,WAAO,KAAK,sBAAsB,MAAM,OAAO;AAE/C,UAAM,mBACJ,MAAM,KAAK,QACX,aACD;AACD;GAEF,QAEE,QAAO,KAAK,wBAAwB,MAAM,OAAO;;AAIrD,MAAI,MAAM;UACH,OAAO;AAEd,SAAO,MACL,wBAAwB,MAAM,KAAK,IAAK,MAAgB,UACzD;AACD,MAAI,OAAO,IAAI,CAAC,KAAK,eAAe"}
|
|
1
|
+
{"version":3,"file":"stripe.webhook.mjs","names":["event: Stripe.Event","emailService.sendEmail"],"sources":["../../../src/webhooks/stripe.webhook.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { logger } from '@logger';\nimport * as emailService from '@services/email.service';\nimport { getOrganizationById } from '@services/organization.service';\nimport {\n addOrUpdateSubscription,\n cancelSubscription,\n changeSubscriptionStatus,\n} from '@services/subscription.service';\nimport { getUserById } from '@services/user.service';\nimport { GenericError } from '@utils/errors';\nimport type { Request, Response } from 'express';\nimport { Stripe } from 'stripe';\nimport type { Plan } from '@/types/plan.types';\n\ntype SubscriptionMetadata = {\n locale: Locale; // Localization setting (e.g., 'en', 'fr', 'es')\n userId: string; // ID of the user associated with the subscription\n organizationId: string; // ID of the organization associated with the subscription\n};\n\n/**\n * Stripe webhook handler for processing subscription and invoice events.\n * @param req - Express request object.\n * @param res - Express response object.\n */\nexport const stripeWebhook = async (req: Request, res: Response) => {\n // Initialize the Stripe client with the secret key\n const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);\n\n const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET!; // Webhook secret for verifying event signatures\n const sig = req.headers['stripe-signature']!; // Retrieve the signature from the webhook request headers\n\n let event: Stripe.Event;\n\n // Verify the webhook signature to ensure the request is authentic\n try {\n event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);\n } catch (err) {\n // Respond with a 400 status code if the signature verification fails\n res.status(400).send(`Webhook Error: ${(err as Error).message}`);\n return;\n }\n\n // Utility function to extract metadata from a Stripe customer\n const extractMetadata = async (customerId: string) => {\n const customer = await stripe.customers.retrieve(customerId); // Retrieve customer details from Stripe\n return (customer as Stripe.Customer).metadata as SubscriptionMetadata; // Return the metadata object\n };\n\n // Handles subscription-related events (creation, update, deletion)\n const handleSubscriptionEvent = async (\n subscription: Stripe.Subscription,\n statusOverride?: Plan['status'] // Optionally override the subscription status\n ) => {\n const { id: subscriptionId, customer } = subscription;\n const priceId = subscription.items.data[0]?.price?.id; // Extract the price ID from subscription items\n\n if (!customer) {\n throw new GenericError('STRIPE_SUBSCRIPTION_NO_CUSTOMER');\n }\n\n const customerId = customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId); // Extract metadata from the customer\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n const organization = await getOrganizationById(organizationId); // Fetch organization details by ID\n\n if (!organization) {\n throw new GenericError('ORGANIZATION_NOT_FOUND');\n }\n\n const user = await getUserById(userId);\n\n if (!user) {\n throw new GenericError('USER_NOT_FOUND');\n }\n\n const status = statusOverride ?? subscription.status; // Use the provided status override or the subscription's status\n\n // Update or create a subscription record in the database\n await addOrUpdateSubscription(\n subscriptionId,\n priceId!,\n customerId,\n userId,\n organization,\n status\n );\n\n if (status === 'active') {\n await emailService.sendEmail({\n type: 'subscriptionPaymentSuccess',\n to: user.email,\n email: user.email,\n subscriptionStartDate: new Date().toLocaleDateString(),\n manageSubscriptionLink: `${process.env.APP_URL}/organization`,\n username: user.name,\n organizationName: organization.name,\n planName: organization.plan?.type ?? 'Unknown',\n });\n }\n if (status === 'canceled') {\n await emailService.sendEmail({\n type: 'subscriptionPaymentCancellation',\n to: user.email,\n email: user.email,\n cancellationDate: new Date(\n (subscription as any).current_period_end * 1000\n ).toLocaleDateString(),\n reactivateLink: `${process.env.APP_URL}/pricing`,\n username: user.name,\n organizationName: organization.name,\n planName: organization.plan?.type ?? 'Unknown',\n });\n }\n };\n\n // Handles invoice-related events (payment success or failure)\n const handleInvoiceEvent = async (\n invoice: Stripe.Invoice,\n status: 'active' | 'incomplete'\n ) => {\n const subscriptionId =\n typeof (invoice as any).subscription === 'string'\n ? (invoice as any).subscription\n : (invoice as any).subscription?.id; // Extract the subscription ID from the invoice\n if (!subscriptionId) {\n logger.warn('Subscription ID is undefined in invoice.');\n return;\n }\n\n // Retrieve the subscription details from Stripe\n const subscription = await stripe.subscriptions.retrieve(subscriptionId);\n const organization = await getOrganizationById(\n subscription.metadata.organizationId\n );\n\n // Prevent duplicate subscriptions by canceling conflicting subscriptions\n if (\n organization.plan?.subscriptionId &&\n organization.plan.subscriptionId !== subscriptionId\n ) {\n await stripe.subscriptions.cancel(subscriptionId);\n }\n\n const customerId = invoice.customer as string;\n const { locale, userId, organizationId } =\n await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Update the subscription status in the database\n await changeSubscriptionStatus(\n subscriptionId,\n status,\n userId,\n organizationId\n );\n };\n\n try {\n // Log the event type for debugging and monitoring\n logger.info(`Triggered event type ${event.type}`);\n\n // Handle specific event types\n switch (event.type) {\n case 'customer.subscription.created': {\n logger.info(`Handled event type ${event.type}`);\n // Process a new subscription creation event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.updated': {\n logger.info(`Handled event type ${event.type}`);\n // Process a subscription update event\n await handleSubscriptionEvent(event.data.object as Stripe.Subscription);\n break;\n }\n case 'customer.subscription.deleted': {\n logger.info(`Handled event type ${event.type}`);\n const subscription = event.data\n .object as unknown as Stripe.Subscription;\n const customerId = subscription.customer as string;\n const { locale, organizationId } = await extractMetadata(customerId);\n\n // Set localization in response locals if available\n if (locale) {\n res.locals.locales = locale;\n }\n\n // Handle subscription deletion by canceling it in the database\n await cancelSubscription(subscription.id, organizationId);\n break;\n }\n case 'invoice.payment_succeeded': {\n logger.info(`Handled event type ${event.type}`);\n // Handle successful invoice payment\n await handleInvoiceEvent(event.data.object as Stripe.Invoice, 'active');\n break;\n }\n case 'invoice.payment_failed': {\n logger.info(`Handled event type ${event.type}`);\n // Handle failed invoice payment\n await handleInvoiceEvent(\n event.data.object as Stripe.Invoice,\n 'incomplete'\n );\n break;\n }\n default:\n // Log unhandled event types for visibility\n logger.info(`Unhandled event type ${event.type}`);\n }\n\n // Respond to Stripe to confirm the event was processed successfully\n res.send();\n } catch (error) {\n // Log errors for debugging and respond with a 500 status code\n logger.error(\n `Error handling event ${event.type}: ${(error as Error).message}`\n );\n res.status(500).send('Server Error');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,OAAO,KAAc,QAAkB;CAElE,MAAM,SAAS,IAAI,OAAO,QAAQ,IAAI,kBAAmB;CAEzD,MAAM,iBAAiB,QAAQ,IAAI;CACnC,MAAM,MAAM,IAAI,QAAQ;CAExB,IAAIA;AAGJ,KAAI;AACF,UAAQ,OAAO,SAAS,eAAe,IAAI,MAAM,KAAK,eAAe;UAC9D,KAAK;AAEZ,MAAI,OAAO,IAAI,CAAC,KAAK,kBAAmB,IAAc,UAAU;AAChE;;CAIF,MAAM,kBAAkB,OAAO,eAAuB;AAEpD,UADiB,MAAM,OAAO,UAAU,SAAS,WAAW,EACvB;;CAIvC,MAAM,0BAA0B,OAC9B,cACA,mBACG;EACH,MAAM,EAAE,IAAI,gBAAgB,aAAa;EACzC,MAAM,UAAU,aAAa,MAAM,KAAK,IAAI,OAAO;AAEnD,MAAI,CAAC,SACH,OAAM,IAAI,aAAa,kCAAkC;EAG3D,MAAM,aAAa;EACnB,MAAM,EAAE,QAAQ,QAAQ,mBACtB,MAAM,gBAAgB,WAAW;AAGnC,MAAI,OACF,KAAI,OAAO,UAAU;EAGvB,MAAM,eAAe,MAAM,oBAAoB,eAAe;AAE9D,MAAI,CAAC,aACH,OAAM,IAAI,aAAa,yBAAyB;EAGlD,MAAM,OAAO,MAAM,YAAY,OAAO;AAEtC,MAAI,CAAC,KACH,OAAM,IAAI,aAAa,iBAAiB;EAG1C,MAAM,S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BAAwB,MAAM,KAAK,OAA8B;AACvE;GAEF,KAAK;AACH,WAAO,KAAK,sBAAsB,MAAM,OAAO;AAE/C,UAAM,wBAAwB,MAAM,KAAK,OAA8B;AACvE;GAEF,KAAK,iCAAiC;AACpC,WAAO,KAAK,sBAAsB,MAAM,OAAO;IAC/C,MAAM,eAAe,MAAM,KACxB;IACH,MAAM,aAAa,aAAa;IAChC,MAAM,EAAE,QAAQ,mBAAmB,MAAM,gBAAgB,WAAW;AAGpE,QAAI,OACF,KAAI,OAAO,UAAU;AAIvB,UAAM,mBAAmB,aAAa,IAAI,eAAe;AACzD;;GAEF,KAAK;AACH,WAAO,KAAK,sBAAsB,MAAM,OAAO;AAE/C,UAAM,mBAAmB,MAAM,KAAK,QAA0B,SAAS;AACvE;GAEF,KAAK;AACH,WAAO,KAAK,sBAAsB,MAAM,OAAO;AAE/C,UAAM,mBACJ,MAAM,KAAK,QACX,aACD;AACD;GAEF,QAEE,QAAO,KAAK,wBAAwB,MAAM,OAAO;;AAIrD,MAAI,MAAM;UACH,OAAO;AAEd,SAAO,MACL,wBAAwB,MAAM,KAAK,IAAK,MAAgB,UACzD;AACD,MAAI,OAAO,IAAI,CAAC,KAAK,eAAe"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TagAPI } from "../types/tag.types.js";
|
|
2
|
-
import { ResponseWithSession } from "../middlewares/sessionAuth.middleware.js";
|
|
3
1
|
import { AskDocQuestionResult as AskDocQuestionResult$1 } from "../utils/AI/askDocQuestion/askDocQuestion.js";
|
|
2
|
+
import { TagAPI } from "../types/tag.types.js";
|
|
4
3
|
import { AuditFileResultData } from "../utils/AI/auditDictionary/index.js";
|
|
5
4
|
import { AuditDictionaryFieldResultData } from "../utils/AI/auditDictionaryField/index.js";
|
|
6
5
|
import { AuditFileResultData as AuditFileResultData$1 } from "../utils/AI/auditDictionaryMetadata/index.js";
|
|
@@ -12,7 +11,7 @@ import { DiscussionFiltersParams } from "../utils/filtersAndPagination/getDiscus
|
|
|
12
11
|
import { PaginatedResponse, ResponseData } from "../utils/responseData.js";
|
|
13
12
|
import { AIOptions, ChatCompletionRequestMessage } from "@intlayer/ai";
|
|
14
13
|
import { KeyPath, Locale } from "@intlayer/types";
|
|
15
|
-
import {
|
|
14
|
+
import { FastifyReply, FastifyRequest } from "fastify";
|
|
16
15
|
|
|
17
16
|
//#region src/controllers/ai.controller.d.ts
|
|
18
17
|
type ReplaceAIConfigByOptions<T> = Omit<T, 'aiConfig'> & {
|
|
@@ -23,12 +22,16 @@ type CustomQueryBody = ReplaceAIConfigByOptions<CustomQueryOptions> & {
|
|
|
23
22
|
applicationContext?: string;
|
|
24
23
|
};
|
|
25
24
|
type CustomQueryResult = ResponseData<CustomQueryResultData>;
|
|
26
|
-
declare const customQuery: (
|
|
25
|
+
declare const customQuery: (request: FastifyRequest<{
|
|
26
|
+
Body: CustomQueryBody;
|
|
27
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
27
28
|
type TranslateJSONBody = Omit<ReplaceAIConfigByOptions<TranslateJSONOptions<JSON>>, 'tags'> & {
|
|
28
29
|
tagsKeys?: string[];
|
|
29
30
|
};
|
|
30
31
|
type TranslateJSONResult = ResponseData<TranslateJSONResultData$1<JSON>>;
|
|
31
|
-
declare const translateJSON: (
|
|
32
|
+
declare const translateJSON: (request: FastifyRequest<{
|
|
33
|
+
Body: TranslateJSONBody;
|
|
34
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
32
35
|
type AuditContentDeclarationBody = {
|
|
33
36
|
aiOptions?: AIOptions;
|
|
34
37
|
locales: Locale[];
|
|
@@ -41,7 +44,9 @@ type AuditContentDeclarationResult = ResponseData<AuditFileResultData>;
|
|
|
41
44
|
/**
|
|
42
45
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
43
46
|
*/
|
|
44
|
-
declare const auditContentDeclaration: (
|
|
47
|
+
declare const auditContentDeclaration: (request: FastifyRequest<{
|
|
48
|
+
Body: AuditContentDeclarationBody;
|
|
49
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
45
50
|
type AuditContentDeclarationFieldBody = {
|
|
46
51
|
aiOptions?: AIOptions;
|
|
47
52
|
locales: Locale[];
|
|
@@ -54,7 +59,9 @@ type AuditContentDeclarationFieldResult = ResponseData<AuditDictionaryFieldResul
|
|
|
54
59
|
/**
|
|
55
60
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
56
61
|
*/
|
|
57
|
-
declare const auditContentDeclarationField: (
|
|
62
|
+
declare const auditContentDeclarationField: (request: FastifyRequest<{
|
|
63
|
+
Body: AuditContentDeclarationFieldBody;
|
|
64
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
58
65
|
type AuditContentDeclarationMetadataBody = {
|
|
59
66
|
aiOptions?: AIOptions;
|
|
60
67
|
fileContent: string;
|
|
@@ -63,7 +70,9 @@ type AuditContentDeclarationMetadataResult = ResponseData<AuditFileResultData$1>
|
|
|
63
70
|
/**
|
|
64
71
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
65
72
|
*/
|
|
66
|
-
declare const auditContentDeclarationMetadata: (
|
|
73
|
+
declare const auditContentDeclarationMetadata: (request: FastifyRequest<{
|
|
74
|
+
Body: AuditContentDeclarationMetadataBody;
|
|
75
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
67
76
|
type AuditTagBody = {
|
|
68
77
|
aiOptions?: AIOptions;
|
|
69
78
|
tag: TagAPI;
|
|
@@ -72,13 +81,17 @@ type AuditTagResult = ResponseData<TranslateJSONResultData>;
|
|
|
72
81
|
/**
|
|
73
82
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
74
83
|
*/
|
|
75
|
-
declare const auditTag: (
|
|
84
|
+
declare const auditTag: (request: FastifyRequest<{
|
|
85
|
+
Body: AuditTagBody;
|
|
86
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
76
87
|
type AskDocQuestionBody = {
|
|
77
88
|
messages: ChatCompletionRequestMessage[];
|
|
78
89
|
discussionId: string;
|
|
79
90
|
};
|
|
80
91
|
type AskDocQuestionResult = ResponseData<AskDocQuestionResult$1>;
|
|
81
|
-
declare const askDocQuestion: (
|
|
92
|
+
declare const askDocQuestion: (request: FastifyRequest<{
|
|
93
|
+
Body: AskDocQuestionBody;
|
|
94
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
82
95
|
type AutocompleteBody = {
|
|
83
96
|
text: string;
|
|
84
97
|
aiOptions?: AIOptions;
|
|
@@ -89,7 +102,9 @@ type AutocompleteBody = {
|
|
|
89
102
|
type AutocompleteResponse = ResponseData<{
|
|
90
103
|
autocompletion: string;
|
|
91
104
|
}>;
|
|
92
|
-
declare const autocomplete: (
|
|
105
|
+
declare const autocomplete: (request: FastifyRequest<{
|
|
106
|
+
Body: AutocompleteBody;
|
|
107
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
93
108
|
type GetDiscussionsParams = ({
|
|
94
109
|
page?: string | number;
|
|
95
110
|
pageSize?: string | number;
|
|
@@ -100,7 +115,9 @@ type GetDiscussionsResult = PaginatedResponse<DiscussionAPI>;
|
|
|
100
115
|
* Retrieves a list of discussions with filters and pagination.
|
|
101
116
|
* Only the owner or admins can access. By default, users only see their own.
|
|
102
117
|
*/
|
|
103
|
-
declare const getDiscussions: (
|
|
118
|
+
declare const getDiscussions: (request: FastifyRequest<{
|
|
119
|
+
Querystring: GetDiscussionsParams;
|
|
120
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
104
121
|
//#endregion
|
|
105
122
|
export { AskDocQuestionBody, AskDocQuestionResult, AuditContentDeclarationBody, AuditContentDeclarationFieldBody, AuditContentDeclarationFieldResult, AuditContentDeclarationMetadataBody, AuditContentDeclarationMetadataResult, AuditContentDeclarationResult, AuditTagBody, AuditTagResult, AutocompleteBody, AutocompleteResponse, CustomQueryBody, CustomQueryResult, GetDiscussionsParams, GetDiscussionsResult, TranslateJSONBody, TranslateJSONResult, askDocQuestion, auditContentDeclaration, auditContentDeclarationField, auditContentDeclarationMetadata, auditTag, autocomplete, customQuery, getDiscussions, translateJSON };
|
|
106
123
|
//# sourceMappingURL=ai.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.controller.d.ts","names":[],"sources":["../../../src/controllers/ai.controller.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai.controller.d.ts","names":[],"sources":["../../../src/controllers/ai.controller.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;KAmCK,8BAA8B,KAAK;cAC1B;AAHuC,CAAA;AAEb,KAI5B,eAAA,GACV,wBALsC,CAKb,kBALa,CAAA,GAAA;EAAL,QAAA,CAAA,EAAA,MAAA,EAAA;EACrB,kBAAA,CAAA,EAAA,MAAA;CAAS;AAGX,KAKA,iBAAA,GACV,YALyB,CAKZ,qBALW,CAAA;AAId,cAGC,WAHgB,EAAA,CAAA,OACd,EAGJ,cAHI,CAAA;EAEF,IAAA,EACqB,eA4CjC;CA5CiC,CAAA,EAAA,KAAA,EACzB,YADyB,EAAA,GAE/B,OAF+B,CAAA,IAAA,CAAA;AAAvB,KA8CC,iBAAA,GAAoB,IA9CrB,CA+CT,wBA/CS,CA+CgB,oBA/ChB,CA+CuD,IA/CvD,CAAA,CAAA,EAAA,MAAA,CAAA,GAAA;EACF,QAAA,CAAA,EAAA,MAAA,EAAA;CACN;AAAO,KAkDE,mBAAA,GAAsB,YAlDxB,CAmDR,yBAnDQ,CAmDkC,IAnDlC,CAAA,CAAA;AA4CE,cAUC,aAVgB,EAAA,CAAA,OAAA,EAWlB,cAXkB,CAAA;EACqC,IAAA,EAUhC,iBAVgC;CAAvC,CAAA,EAAA,KAAA,EAWlB,YAXkB,EAAA,GAYxB,OAZwB,CAAA,IAAA,CAAA;AAAzB,KAiEU,2BAAA,GAjEV;EAD8B,SAAA,CAAA,EAmElB,SAnEkB;EAAI,OAAA,EAoEzB,MApEyB,EAAA;EAMxB,aAAA,EA+DK,MA/DL;EACgC,WAAA,EAAA,MAAA;EAA1C,QAAA,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ary.types.js";
|
|
2
|
-
import { ResponseWithSession } from "../middlewares/sessionAuth.middleware.js";
|
|
3
2
|
import { FiltersAndPagination } from "../utils/filtersAndPagination/getFiltersAndPaginationFromBody.js";
|
|
4
3
|
import { PaginatedResponse, ResponseData } from "../utils/responseData.js";
|
|
5
4
|
import { DictionaryFiltersParams } from "../utils/filtersAndPagination/getDictionaryFiltersAndPagination.js";
|
|
6
5
|
import { Dictionary, DictionaryId, LocalDictionaryId } from "@intlayer/types";
|
|
7
|
-
import {
|
|
6
|
+
import { FastifyReply, FastifyRequest } from "fastify";
|
|
8
7
|
|
|
9
8
|
//#region src/controllers/dictionary.controller.d.ts
|
|
10
9
|
type GetDictionariesParams = FiltersAndPagination<DictionaryFiltersParams>;
|
|
@@ -12,12 +11,14 @@ type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;
|
|
|
12
11
|
/**
|
|
13
12
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
14
13
|
*/
|
|
15
|
-
declare const getDictionaries: (
|
|
14
|
+
declare const getDictionaries: (request: FastifyRequest<{
|
|
15
|
+
Querystring: GetDictionariesParams;
|
|
16
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
16
17
|
type GetDictionariesKeysResult = ResponseData<string[]>;
|
|
17
18
|
/**
|
|
18
19
|
* Retrieves a list of dictionaries keys based on filters and pagination.
|
|
19
20
|
*/
|
|
20
|
-
declare const getDictionariesKeys: (
|
|
21
|
+
declare const getDictionariesKeys: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
21
22
|
type GetDictionariesUpdateTimestampResult = ResponseData<Record<DictionaryId, {
|
|
22
23
|
key: string;
|
|
23
24
|
updatedAt: number;
|
|
@@ -25,7 +26,7 @@ type GetDictionariesUpdateTimestampResult = ResponseData<Record<DictionaryId, {
|
|
|
25
26
|
/**
|
|
26
27
|
* Retrieves a list of dictionaries keys based on filters and pagination.
|
|
27
28
|
*/
|
|
28
|
-
declare const getDictionariesUpdateTimestamp: (
|
|
29
|
+
declare const getDictionariesUpdateTimestamp: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
29
30
|
type GetDictionaryParams = {
|
|
30
31
|
dictionaryKey: string;
|
|
31
32
|
};
|
|
@@ -36,7 +37,10 @@ type GetDictionaryResult = ResponseData<DictionaryAPI>;
|
|
|
36
37
|
/**
|
|
37
38
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
38
39
|
*/
|
|
39
|
-
declare const getDictionaryByKey: (
|
|
40
|
+
declare const getDictionaryByKey: (request: FastifyRequest<{
|
|
41
|
+
Params: GetDictionaryParams;
|
|
42
|
+
Querystring: GetDictionaryQuery;
|
|
43
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
40
44
|
type AddDictionaryBody = {
|
|
41
45
|
dictionary: DictionaryCreationData;
|
|
42
46
|
};
|
|
@@ -44,7 +48,9 @@ type AddDictionaryResult = ResponseData<DictionaryAPI>;
|
|
|
44
48
|
/**
|
|
45
49
|
* Adds a new dictionary to the database.
|
|
46
50
|
*/
|
|
47
|
-
declare const addDictionary: (
|
|
51
|
+
declare const addDictionary: (request: FastifyRequest<{
|
|
52
|
+
Body: AddDictionaryBody;
|
|
53
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
48
54
|
type PushDictionariesBody = {
|
|
49
55
|
dictionaries: Dictionary[];
|
|
50
56
|
};
|
|
@@ -69,11 +75,10 @@ type PushDictionariesResultData = {
|
|
|
69
75
|
type PushDictionariesResult = ResponseData<PushDictionariesResultData>;
|
|
70
76
|
/**
|
|
71
77
|
* Check each dictionaries, add the new ones and update the existing ones.
|
|
72
|
-
* @param req - Express request object.
|
|
73
|
-
* @param res - Express response object.
|
|
74
|
-
* @returns Response containing the created dictionary.
|
|
75
78
|
*/
|
|
76
|
-
declare const pushDictionaries: (
|
|
79
|
+
declare const pushDictionaries: (request: FastifyRequest<{
|
|
80
|
+
Body: PushDictionariesBody;
|
|
81
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
77
82
|
type UpdateDictionaryParam = {
|
|
78
83
|
dictionaryId: string;
|
|
79
84
|
};
|
|
@@ -82,7 +87,10 @@ type UpdateDictionaryResult = ResponseData<DictionaryAPI>;
|
|
|
82
87
|
/**
|
|
83
88
|
* Updates an existing dictionary in the database.
|
|
84
89
|
*/
|
|
85
|
-
declare const updateDictionary: (
|
|
90
|
+
declare const updateDictionary: (request: FastifyRequest<{
|
|
91
|
+
Params: UpdateDictionaryParam;
|
|
92
|
+
Body: UpdateDictionaryBody;
|
|
93
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
86
94
|
type DeleteDictionaryParam = {
|
|
87
95
|
dictionaryId: string;
|
|
88
96
|
};
|
|
@@ -90,7 +98,9 @@ type DeleteDictionaryResult = ResponseData<DictionaryAPI>;
|
|
|
90
98
|
/**
|
|
91
99
|
* Deletes a dictionary from the database by its ID.
|
|
92
100
|
*/
|
|
93
|
-
declare const deleteDictionary: (
|
|
101
|
+
declare const deleteDictionary: (request: FastifyRequest<{
|
|
102
|
+
Params: DeleteDictionaryParam;
|
|
103
|
+
}>, reply: FastifyReply) => Promise<void>;
|
|
94
104
|
//#endregion
|
|
95
105
|
export { AddDictionaryBody, AddDictionaryResult, DeleteDictionaryParam, DeleteDictionaryResult, GetDictionariesKeysResult, GetDictionariesParams, GetDictionariesResult, GetDictionariesUpdateTimestampResult, GetDictionaryParams, GetDictionaryQuery, GetDictionaryResult, PushDictionariesBody, PushDictionariesResult, UpdateDictionaryBody, UpdateDictionaryParam, UpdateDictionaryResult, addDictionary, deleteDictionary, getDictionaries, getDictionariesKeys, getDictionariesUpdateTimestamp, getDictionaryByKey, pushDictionaries, updateDictionary };
|
|
96
106
|
//# sourceMappingURL=dictionary.controller.d.ts.map
|