@intlayer/backend 3.5.5 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/controllers/ai.controller.cjs +159 -7
- package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
- package/dist/cjs/controllers/dictionary.controller.cjs +50 -17
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +2 -6
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/tag.controller.cjs +235 -0
- package/dist/cjs/controllers/tag.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +1 -0
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/models/tag.model.cjs +31 -0
- package/dist/cjs/models/tag.model.cjs.map +1 -0
- package/dist/cjs/routes/ai.routes.cjs +31 -4
- package/dist/cjs/routes/ai.routes.cjs.map +1 -1
- package/dist/cjs/routes/dictionary.routes.cjs +4 -4
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/tags.routes.cjs +60 -0
- package/dist/cjs/routes/tags.routes.cjs.map +1 -0
- package/dist/cjs/schemas/dictionary.schema.cjs +31 -6
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
- package/dist/cjs/schemas/project.schema.cjs +5 -0
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/schemas/tag.schema.cjs +64 -0
- package/dist/cjs/schemas/tag.schema.cjs.map +1 -0
- package/dist/cjs/services/dictionary.service.cjs +139 -27
- package/dist/cjs/services/dictionary.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +14 -5
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/tag.service.cjs +91 -0
- package/dist/cjs/services/tag.service.cjs.map +1 -0
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/types/tag.types.cjs +17 -0
- package/dist/cjs/types/tag.types.cjs.map +1 -0
- package/dist/cjs/utils/{audit → auditDictionary}/PROMPT.md +6 -1
- package/dist/cjs/utils/{audit → auditDictionary}/index.cjs +10 -8
- package/dist/cjs/utils/auditDictionary/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs +81 -0
- package/dist/cjs/utils/auditDictionaryField/index.cjs.map +1 -0
- package/dist/cjs/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs +78 -0
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs.map +1 -0
- package/dist/cjs/utils/auditTag/PROMPT.md +34 -0
- package/dist/cjs/utils/auditTag/index.cjs +74 -0
- package/dist/cjs/utils/auditTag/index.cjs.map +1 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs +39 -0
- package/dist/cjs/utils/ensureArrayQueryFilter.cjs.map +1 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs +35 -0
- package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -0
- package/dist/cjs/utils/errors/errorCodes.cjs +91 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +10 -11
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +6 -10
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +51 -0
- package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +2 -9
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
- package/dist/cjs/utils/mapper/dictionary.cjs +8 -4
- package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
- package/dist/cjs/utils/mapper/organization.cjs +2 -4
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +2 -4
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/mapper/tag.cjs +37 -0
- package/dist/cjs/utils/mapper/tag.cjs.map +1 -0
- package/dist/cjs/utils/mapper/user.cjs +2 -4
- package/dist/cjs/utils/mapper/user.cjs.map +1 -1
- package/dist/cjs/utils/removeObjectKeys.cjs +35 -0
- package/dist/cjs/utils/removeObjectKeys.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateProject.cjs +17 -10
- package/dist/cjs/utils/validation/validateProject.cjs.map +1 -1
- package/dist/cjs/utils/validation/validateTag.cjs +93 -0
- package/dist/cjs/utils/validation/validateTag.cjs.map +1 -0
- package/dist/esm/controllers/ai.controller.mjs +155 -6
- package/dist/esm/controllers/ai.controller.mjs.map +1 -1
- package/dist/esm/controllers/dictionary.controller.mjs +50 -17
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +2 -6
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/tag.controller.mjs +203 -0
- package/dist/esm/controllers/tag.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +1 -0
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/models/tag.model.mjs +7 -0
- package/dist/esm/models/tag.model.mjs.map +1 -0
- package/dist/esm/routes/ai.routes.mjs +37 -5
- package/dist/esm/routes/ai.routes.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +4 -4
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/tags.routes.mjs +40 -0
- package/dist/esm/routes/tags.routes.mjs.map +1 -0
- package/dist/esm/schemas/dictionary.schema.mjs +31 -6
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +5 -0
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/schemas/tag.schema.mjs +45 -0
- package/dist/esm/schemas/tag.schema.mjs.map +1 -0
- package/dist/esm/services/dictionary.service.mjs +137 -27
- package/dist/esm/services/dictionary.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +14 -5
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/tag.service.mjs +61 -0
- package/dist/esm/services/tag.service.mjs.map +1 -0
- package/dist/esm/types/tag.types.mjs +1 -0
- package/dist/esm/types/tag.types.mjs.map +1 -0
- package/dist/esm/utils/{audit → auditDictionary}/PROMPT.md +6 -1
- package/dist/esm/utils/{audit → auditDictionary}/index.mjs +6 -4
- package/dist/esm/utils/auditDictionary/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryField/PROMPT.md +115 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs +56 -0
- package/dist/esm/utils/auditDictionaryField/index.mjs.map +1 -0
- package/dist/esm/utils/auditDictionaryMetadata/PROMPT.md +76 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs +53 -0
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs.map +1 -0
- package/dist/esm/utils/auditTag/PROMPT.md +34 -0
- package/dist/esm/utils/auditTag/index.mjs +49 -0
- package/dist/esm/utils/auditTag/index.mjs.map +1 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs +15 -0
- package/dist/esm/utils/ensureArrayQueryFilter.mjs.map +1 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs +11 -0
- package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -0
- package/dist/esm/utils/errors/errorCodes.mjs +91 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +10 -11
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +6 -10
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +29 -0
- package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +2 -9
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
- package/dist/esm/utils/mapper/dictionary.mjs +8 -4
- package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
- package/dist/esm/utils/mapper/organization.mjs +2 -4
- package/dist/esm/utils/mapper/organization.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +2 -4
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mapper/tag.mjs +12 -0
- package/dist/esm/utils/mapper/tag.mjs.map +1 -0
- package/dist/esm/utils/mapper/user.mjs +2 -4
- package/dist/esm/utils/mapper/user.mjs.map +1 -1
- package/dist/esm/utils/removeObjectKeys.mjs +11 -0
- package/dist/esm/utils/removeObjectKeys.mjs.map +1 -0
- package/dist/esm/utils/validation/validateProject.mjs +17 -10
- package/dist/esm/utils/validation/validateProject.mjs.map +1 -1
- package/dist/esm/utils/validation/validateTag.mjs +65 -0
- package/dist/esm/utils/validation/validateTag.mjs.map +1 -0
- package/dist/types/controllers/ai.controller.d.ts +45 -4
- package/dist/types/controllers/ai.controller.d.ts.map +1 -1
- package/dist/types/controllers/dictionary.controller.d.ts +6 -3
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts +2 -4
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/tag.controller.d.ts +39 -0
- package/dist/types/controllers/tag.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/export.d.ts +2 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +1 -0
- package/dist/types/models/dictionary.model.d.ts.map +1 -1
- package/dist/types/models/tag.model.d.ts +3 -0
- package/dist/types/models/tag.model.d.ts.map +1 -0
- package/dist/types/routes/ai.routes.d.ts +16 -1
- package/dist/types/routes/ai.routes.d.ts.map +1 -1
- package/dist/types/routes/dictionary.routes.d.ts +6 -2
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/tags.routes.d.ts +29 -0
- package/dist/types/routes/tags.routes.d.ts.map +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/tag.schema.d.ts +16 -0
- package/dist/types/schemas/tag.schema.d.ts.map +1 -0
- package/dist/types/services/dictionary.service.d.ts +10 -2
- package/dist/types/services/dictionary.service.d.ts.map +1 -1
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/tag.service.d.ts +45 -0
- package/dist/types/services/tag.service.d.ts.map +1 -0
- package/dist/types/types/dictionary.types.d.ts +14 -4
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/types/tag.types.d.ts +26 -0
- package/dist/types/types/tag.types.d.ts.map +1 -0
- package/dist/types/utils/auditDictionary/index.d.ts +24 -0
- package/dist/types/utils/auditDictionary/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts +24 -0
- package/dist/types/utils/auditDictionaryField/index.d.ts.map +1 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts +21 -0
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts.map +1 -0
- package/dist/types/utils/auditTag/index.d.ts +27 -0
- package/dist/types/utils/auditTag/index.d.ts.map +1 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts +2 -0
- package/dist/types/utils/ensureArrayQueryFilter.d.ts.map +1 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts +8 -0
- package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -0
- package/dist/types/utils/errors/errorCodes.d.ts +91 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +24 -0
- package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts +1 -1
- package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
- package/dist/types/utils/mapper/organization.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mapper/tag.d.ts +16 -0
- package/dist/types/utils/mapper/tag.d.ts.map +1 -0
- package/dist/types/utils/mapper/user.d.ts +2 -2
- package/dist/types/utils/mapper/user.d.ts.map +1 -1
- package/dist/types/utils/removeObjectKeys.d.ts +2 -0
- package/dist/types/utils/removeObjectKeys.d.ts.map +1 -0
- package/dist/types/utils/validation/validateProject.d.ts.map +1 -1
- package/dist/types/utils/validation/validateTag.d.ts +16 -0
- package/dist/types/utils/validation/validateTag.d.ts.map +1 -0
- package/package.json +2 -3
- package/dist/cjs/utils/audit/index.cjs.map +0 -1
- package/dist/esm/utils/audit/index.mjs.map +0 -1
- /package/dist/cjs/utils/{audit → auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{audit → auditDictionary}/TS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{audit → auditDictionary}/TS_FORMAT.md +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/services/project.service.ts"],"sourcesContent":["import { ProjectModel } from '@models/project.model';\nimport { ensureMongoDocumentToObject } from '@utils/ensureMongoDocumentToObject';\nimport { GenericError } from '@utils/errors';\nimport type { ProjectFilters } from '@utils/filtersAndPagination/getProjectFiltersAndPagination';\nimport { removeObjectKeys } from '@utils/removeObjectKeys';\nimport {\n type ProjectFields,\n validateProject,\n} from '@utils/validation/validateProject';\nimport type { ObjectId } from 'mongoose';\nimport type {\n Project,\n ProjectData,\n ProjectDocument,\n} from '@/types/project.types';\n\n/**\n * Finds projects based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of projects matching the filters.\n */\nexport const findProjects = async (\n filters: ProjectFilters,\n skip = 0,\n limit = 100\n): Promise<ProjectDocument[]> =>\n await ProjectModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a project by its ID.\n * @param projectId - The ID of the project to find.\n * @returns The project matching the ID.\n */\nexport const getProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findById(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n\n/**\n * Counts the total number of projects that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of projects.\n */\nexport const countProjects = async (\n filters: ProjectFilters\n): Promise<number> => {\n const result = await ProjectModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('PROJECT_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new project in the database.\n * @param project - The project data to create.\n * @returns The created project.\n */\nexport const createProject = async (\n project: ProjectData\n): Promise<ProjectDocument> => {\n if ((project as Partial<Project>).oAuth2Access) {\n delete (project as Partial<Project>).oAuth2Access;\n }\n\n const errors = await validateProject(project, ['name']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', { errors });\n }\n\n return await ProjectModel.create(project);\n};\n\n/**\n * Updates an existing project in the database by its ID.\n * @param projectId - The ID of the project to update.\n * @param project - The updated project data.\n * @returns The updated project.\n */\nexport const updateProjectById = async (\n projectId: string | ObjectId,\n project: Partial<Project>\n): Promise<ProjectDocument> => {\n const projectObject = ensureMongoDocumentToObject(project);\n const projectToUpdate = removeObjectKeys(projectObject, [\n '_id',\n 'oAuth2Access',\n 'organizationId',\n ]);\n\n const updatedKeys = Object.keys(projectToUpdate) as ProjectFields;\n\n const errors = validateProject(project, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('PROJECT_INVALID_FIELDS', {\n projectId,\n errors,\n });\n }\n\n console.log('projectToUpdate', projectToUpdate);\n\n const result = await ProjectModel.updateOne(\n { _id: projectId },\n projectToUpdate\n );\n\n if (result.matchedCount === 0) {\n throw new GenericError('PROJECT_UPDATE_FAILED', { projectId });\n }\n\n return await getProjectById(projectId);\n};\n\n/**\n * Deletes a project from the database by its ID.\n * @param projectId - The ID of the project to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteProjectById = async (\n projectId: string | ObjectId\n): Promise<ProjectDocument> => {\n const project = await ProjectModel.findByIdAndDelete(projectId);\n\n if (!project) {\n throw new GenericError('PROJECT_NOT_DEFINED', { projectId });\n }\n\n return project;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,yCAA4C;AAC5C,oBAA6B;AAE7B,8BAAiC;AACjC,6BAGO;AAeA,MAAM,eAAe,OAC1B,SACA,OAAO,GACP,QAAQ,QAER,MAAM,4BAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AAOlD,MAAM,iBAAiB,OAC5B,cAC6B;AAC7B,QAAM,UAAU,MAAM,4BAAa,SAAS,SAAS;AAErD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,2BAAa,uBAAuB,EAAE,UAAU,CAAC;AAAA,EAC7D;AAEA,SAAO;AACT;AAOO,MAAM,gBAAgB,OAC3B,YACoB;AACpB,QAAM,SAAS,MAAM,4BAAa,eAAe,OAAO;AAExD,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,2BAAa,wB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
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tag_service_exports = {};
|
|
20
|
+
__export(tag_service_exports, {
|
|
21
|
+
countTags: () => countTags,
|
|
22
|
+
createTag: () => createTag,
|
|
23
|
+
deleteTagById: () => deleteTagById,
|
|
24
|
+
findTags: () => findTags,
|
|
25
|
+
getTagById: () => getTagById,
|
|
26
|
+
getTagsByKeys: () => getTagsByKeys,
|
|
27
|
+
updateTagById: () => updateTagById
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(tag_service_exports);
|
|
30
|
+
var import_tag = require('./../models/tag.model.cjs');
|
|
31
|
+
var import_errors = require('./../utils/errors/index.cjs');
|
|
32
|
+
var import_validateTag = require('./../utils/validation/validateTag.cjs');
|
|
33
|
+
const findTags = async (filters, skip = 0, limit = 100) => await import_tag.TagModel.find(filters).skip(skip).limit(limit);
|
|
34
|
+
const getTagById = async (tagId) => {
|
|
35
|
+
const tag = await import_tag.TagModel.findById(tagId);
|
|
36
|
+
if (!tag) {
|
|
37
|
+
throw new import_errors.GenericError("TAG_NOT_FOUND", { tagId });
|
|
38
|
+
}
|
|
39
|
+
return tag;
|
|
40
|
+
};
|
|
41
|
+
const getTagsByKeys = async (keys, organizationId) => {
|
|
42
|
+
const tags = await import_tag.TagModel.find({ key: { $in: keys }, organizationId });
|
|
43
|
+
return tags;
|
|
44
|
+
};
|
|
45
|
+
const countTags = async (filters) => {
|
|
46
|
+
const result = await import_tag.TagModel.countDocuments(filters);
|
|
47
|
+
if (typeof result === "undefined") {
|
|
48
|
+
throw new import_errors.GenericError("TAG_COUNT_FAILED", { filters });
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const createTag = async (tag) => {
|
|
53
|
+
const errors = await (0, import_validateTag.validateTag)(tag, ["key"]);
|
|
54
|
+
if (Object.keys(errors).length > 0) {
|
|
55
|
+
throw new import_errors.GenericError("TAG_INVALID_FIELDS", { errors });
|
|
56
|
+
}
|
|
57
|
+
return await import_tag.TagModel.create(tag);
|
|
58
|
+
};
|
|
59
|
+
const updateTagById = async (tagId, tag) => {
|
|
60
|
+
const updatedKeys = Object.keys(tag);
|
|
61
|
+
const errors = (0, import_validateTag.validateTag)(tag, updatedKeys);
|
|
62
|
+
if (Object.keys(errors).length > 0) {
|
|
63
|
+
throw new import_errors.GenericError("TAG_INVALID_FIELDS", {
|
|
64
|
+
tagId,
|
|
65
|
+
errors
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const result = await import_tag.TagModel.updateOne({ _id: tagId }, tag);
|
|
69
|
+
if (result.matchedCount === 0) {
|
|
70
|
+
throw new import_errors.GenericError("TAG_UPDATE_FAILED", { tagId });
|
|
71
|
+
}
|
|
72
|
+
return await getTagById(tagId);
|
|
73
|
+
};
|
|
74
|
+
const deleteTagById = async (tagId) => {
|
|
75
|
+
const tag = await import_tag.TagModel.findByIdAndDelete(tagId);
|
|
76
|
+
if (!tag) {
|
|
77
|
+
throw new import_errors.GenericError("TAG_NOT_FOUND", { tagId });
|
|
78
|
+
}
|
|
79
|
+
return tag;
|
|
80
|
+
};
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
countTags,
|
|
84
|
+
createTag,
|
|
85
|
+
deleteTagById,
|
|
86
|
+
findTags,
|
|
87
|
+
getTagById,
|
|
88
|
+
getTagsByKeys,
|
|
89
|
+
updateTagById
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=tag.service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/tag.service.ts"],"sourcesContent":["import { TagModel } from '@models/tag.model';\nimport { GenericError } from '@utils/errors';\nimport type { TagFilters } from '@utils/filtersAndPagination/getTagFiltersAndPagination';\nimport { type TagFields, validateTag } from '@utils/validation/validateTag';\nimport type { ObjectId } from 'mongoose';\nimport { Organization } from '@/export';\nimport type { Tag, TagData, TagDocument } from '@/types/tag.types';\n\n/**\n * Finds tags based on filters and pagination options.\n * @param filters - MongoDB filter query.\n * @param skip - Number of documents to skip.\n * @param limit - Number of documents to limit.\n * @returns List of tags matching the filters.\n */\nexport const findTags = async (\n filters: TagFilters,\n skip = 0,\n limit = 100\n): Promise<TagDocument[]> =>\n await TagModel.find(filters).skip(skip).limit(limit);\n\n/**\n * Finds a tag by its ID.\n * @param tagId - The ID of the tag to find.\n * @returns The tag matching the ID.\n */\nexport const getTagById = async (\n tagId: string | ObjectId\n): Promise<TagDocument> => {\n const tag = await TagModel.findById(tagId);\n\n if (!tag) {\n throw new GenericError('TAG_NOT_FOUND', { tagId });\n }\n\n return tag;\n};\n\nexport const getTagsByKeys = async (\n keys: string[],\n organizationId: string | Organization['_id']\n): Promise<TagDocument[]> => {\n const tags = await TagModel.find({ key: { $in: keys }, organizationId });\n\n return tags;\n};\n\n/**\n * Counts the total number of tags that match the filters.\n * @param filters - MongoDB filter query.\n * @returns Total number of tags.\n */\nexport const countTags = async (filters: TagFilters): Promise<number> => {\n const result = await TagModel.countDocuments(filters);\n\n if (typeof result === 'undefined') {\n throw new GenericError('TAG_COUNT_FAILED', { filters });\n }\n\n return result;\n};\n\n/**\n * Creates a new tag in the database.\n * @param tag - The tag data to create.\n * @returns The created tag.\n */\nexport const createTag = async (tag: TagData): Promise<TagDocument> => {\n const errors = await validateTag(tag, ['key']);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('TAG_INVALID_FIELDS', { errors });\n }\n\n return await TagModel.create(tag);\n};\n\n/**\n * Updates an existing tag in the database by its ID.\n * @param tagId - The ID of the tag to update.\n * @param tag - The updated tag data.\n * @returns The updated tag.\n */\nexport const updateTagById = async (\n tagId: string | ObjectId,\n tag: Partial<Tag>\n): Promise<TagDocument> => {\n const updatedKeys = Object.keys(tag) as TagFields;\n\n const errors = validateTag(tag, updatedKeys);\n\n if (Object.keys(errors).length > 0) {\n throw new GenericError('TAG_INVALID_FIELDS', {\n tagId,\n errors,\n });\n }\n\n const result = await TagModel.updateOne({ _id: tagId }, tag);\n\n if (result.matchedCount === 0) {\n throw new GenericError('TAG_UPDATE_FAILED', { tagId });\n }\n\n return await getTagById(tagId);\n};\n\n/**\n * Deletes a tag from the database by its ID.\n * @param tagId - The ID of the tag to delete.\n * @returns The result of the deletion operation.\n */\nexport const deleteTagById = async (\n tagId: string | ObjectId\n): Promise<TagDocument> => {\n const tag = await TagModel.findByIdAndDelete(tagId);\n\n if (!tag) {\n throw new GenericError('TAG_NOT_FOUND', { tagId });\n }\n\n return tag;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAyB;AACzB,oBAA6B;AAE7B,yBAA4C;AAYrC,MAAM,WAAW,OACtB,SACA,OAAO,GACP,QAAQ,QAER,MAAM,oBAAS,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,KAAK;AAO9C,MAAM,aAAa,OACxB,UACyB;AACzB,QAAM,MAAM,MAAM,oBAAS,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AI,CAAC,KAAK;AACR,UAAM,IAAI,2BAAa,iBAAiB,EAAE,MAAM,CAAC;AAAA,EACnD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import type { DictionaryValue } from '@intlayer/core';\nimport type { Model, ObjectId, Document } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['_id'] | string)[];\n key: string;\n content?: DictionaryValue;\n title?: string;\n description?: string;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/types/dictionary.types.ts"],"sourcesContent":["import type { DictionaryValue } from '@intlayer/core';\nimport type { Model, ObjectId, Document } from 'mongoose';\nimport type { Project } from './project.types';\nimport type { User } from './user.types';\n\nexport type DictionaryCreationData = {\n projectIds: (Project['_id'] | string)[];\n key: string;\n content?: DictionaryValue;\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: string;\n};\n\nexport type VersionedContentEl = {\n name?: string;\n description?: string;\n content: DictionaryValue;\n};\n\nexport type ContentVersion = string;\nexport type VersionedContent = Record<string, VersionedContentEl>;\n\nexport type DictionaryData = {\n key: string;\n content: VersionedContent;\n projectIds: (Project['_id'] | string)[];\n creatorId: User['_id'];\n title?: string;\n description?: string;\n tags?: string[];\n filePath?: Record<string, string>;\n publishedVersion?: string | null;\n};\n\nexport type Dictionary = DictionaryData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n availableVersions?: string[];\n};\n\nexport type DictionaryAPI = Omit<Dictionary, 'filePath' | 'content'> & {\n content: DictionaryValue;\n filePath?: string;\n availableVersions?: string[];\n};\n\nexport type DictionaryDocument = Document<unknown, {}, Dictionary> & Dictionary;\nexport type DictionaryModelType = Model<Dictionary>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var tag_types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(tag_types_exports);
|
|
17
|
+
//# sourceMappingURL=tag.types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/tag.types.ts"],"sourcesContent":["import type { ObjectId, Document, Model } from 'mongoose';\nimport { Organization } from './organization.types';\nimport { User } from './user.types';\n\nexport type TagCreationData = {\n key: string;\n name?: string;\n description?: string;\n instructions?: string;\n};\n\nexport type TagData = {\n key: string;\n name?: string;\n description?: string;\n instructions?: string;\n creatorId: User['_id'];\n organizationId: Organization['_id'];\n};\n\nexport type Tag = TagData & {\n _id: ObjectId;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type TagAPI = Tag;\n\nexport type TagDocument = Document<unknown, {}, Tag> & Tag;\n\nexport type TagModelType = Model<Tag>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
You are an expert in internationalization and content management. Your task is to audit the content declaration files in the project and identify any potential issues or inconsistencies. Provide a detailed report of any issues found, including the file path, line number, and a brief explanation of the issue.
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the content declaration files in the project and identify any potential issues or inconsistencies. Provide a detailed report of any issues found, including the file path, line number, and a brief explanation of the issue.
|
|
2
2
|
|
|
3
3
|
**Instructions:**
|
|
4
4
|
|
|
@@ -33,6 +33,7 @@ You are an expert in internationalization and content management. Your task is t
|
|
|
33
33
|
- **Manage Localizations:** If the required languages contains similar languages, as `en` and `en-GB`, consider `en` as English US and `en-GB` as English UK, and insert or review both translations to maintain clarity and correctness.
|
|
34
34
|
- **Order Translations:** If the translations are not in the same order as the required languages list, consider reordering the translations to maintain clarity and correctness.
|
|
35
35
|
- **Escape Special Characters:** If the translations contain special characters, escape them using the appropriate escape sequence.
|
|
36
|
+
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
36
37
|
|
|
37
38
|
6. **Example Scenario:**
|
|
38
39
|
|
|
@@ -137,6 +138,10 @@ You are an expert in internationalization and content management. Your task is t
|
|
|
137
138
|
- The import of the `t` function was imported from `react-intlayer` instead of `intlayer`.
|
|
138
139
|
- A type `DeclarationContent` was added to the file to strengthen the content declaration.
|
|
139
140
|
|
|
141
|
+
**Tags Instructions:**
|
|
142
|
+
|
|
143
|
+
{{tagsInstructions}}
|
|
144
|
+
|
|
140
145
|
**File to Audit:**
|
|
141
146
|
|
|
142
147
|
{{fileContent}}
|
|
@@ -16,11 +16,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var auditDictionary_exports = {};
|
|
20
|
+
__export(auditDictionary_exports, {
|
|
21
|
+
auditDictionary: () => auditDictionary
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(auditDictionary_exports);
|
|
24
24
|
var import_fs = require("fs");
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_url = require("url");
|
|
@@ -48,14 +48,16 @@ const formatLocaleWithName = (locale) => {
|
|
|
48
48
|
const localeName = (0, import_core.getLocaleName)(locale);
|
|
49
49
|
return `${locale}: ${localeName}`;
|
|
50
50
|
};
|
|
51
|
-
const
|
|
51
|
+
const formatTagInstructions = (tags = []) => tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join("\n\n");
|
|
52
|
+
const auditDictionary = async ({
|
|
52
53
|
fileContent,
|
|
53
54
|
filePath,
|
|
54
55
|
model,
|
|
55
56
|
openAiApiKey,
|
|
56
57
|
customPrompt,
|
|
57
58
|
locales,
|
|
58
|
-
defaultLocale
|
|
59
|
+
defaultLocale,
|
|
60
|
+
tags
|
|
59
61
|
}) => {
|
|
60
62
|
try {
|
|
61
63
|
const openai = new import_openai.OpenAI({
|
|
@@ -72,7 +74,7 @@ const auditFile = async ({
|
|
|
72
74
|
).replace(
|
|
73
75
|
"{{declarationsContentTemplate}}",
|
|
74
76
|
FILE_TEMPLATE[fileExtension]
|
|
75
|
-
).replace("{{fileContent}}", fileContent);
|
|
77
|
+
).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
76
78
|
const chatCompletion = await openai.chat.completions.create({
|
|
77
79
|
model: model ?? "gpt-4o-mini",
|
|
78
80
|
messages: [{ role: "system", content: prompt }]
|
|
@@ -91,6 +93,6 @@ const auditFile = async ({
|
|
|
91
93
|
};
|
|
92
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
93
95
|
0 && (module.exports = {
|
|
94
|
-
|
|
96
|
+
auditDictionary
|
|
95
97
|
});
|
|
96
98
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionary/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName } from '@intlayer/core';\nimport { logger } from '@logger';\nimport { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditOptions = {\n locales: Locales[];\n defaultLocale: Locales;\n fileContent: string;\n filePath?: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n tags?: Tag[];\n};\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\nconst FILE_TEMPLATE: Record<string, string> = {\n ts: getFileContent('./TS_FORMAT.md'),\n tsx: getFileContent('./TSX_FORMAT.md'),\n js: getFileContent('./MJS_FORMAT.md'),\n mjs: getFileContent('./MJS_FORMAT.md'),\n cjs: getFileContent('./CJS_FORMAT.md'),\n jsx: getFileContent('./JSX_FORMAT.md'),\n json: getFileContent('./JSON_FORMAT.md'),\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionary = async ({\n fileContent,\n filePath,\n model,\n openAiApiKey,\n customPrompt,\n locales,\n defaultLocale,\n tags,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Read the file's content.\n const splitted = (filePath ?? '.json').split('.');\n const fileExtension = splitted[splitted.length - 1];\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace('{{filePath}}', filePath ?? 'Not provided')\n .replace(\n '{{defaultLocale}}',\n `{${formatLocaleWithName(defaultLocale)}}`\n )\n .replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace(\n '{{declarationsContentTemplate}}',\n FILE_TEMPLATE[fileExtension]\n )\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,kBAA8B;AAC9B,oBAAuB;AAEvB,oBAAu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AClD,EACC;AAAA,MACC;AAAA,MACA,cAAc,aAAa;AAAA,IAC7B,EACC,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the given element into the content declaration file. If the element is not declared, review it. If this element is missing, write it by considering the given context of the content declaration, and by following instructions.
|
|
2
|
+
|
|
3
|
+
**Instructions:**
|
|
4
|
+
|
|
5
|
+
1. **Terminology:**
|
|
6
|
+
|
|
7
|
+
- **Content Declaration:** A content declaration is a is a file (.ts, .js or .json) that contains the multilingual declaration related to a specific content. A content declaration file is usually related to a specific component, or page or section of a website.
|
|
8
|
+
- **Tag:** A tag is attached to a content declaration and is used to group content declaration and harmonize them.
|
|
9
|
+
- **KeyPath** The KeyPath correspond to to the path to retrieve the targeted element from the `content` key of the content declaration file.
|
|
10
|
+
|
|
11
|
+
2. **Locales:**
|
|
12
|
+
|
|
13
|
+
- Required Locales: {{otherLocales}}
|
|
14
|
+
|
|
15
|
+
3. **Audit Requirements:**
|
|
16
|
+
|
|
17
|
+
- **Consistency:** Ensure that all keys have translations for all specified locales.
|
|
18
|
+
- **Missing Content:** Identify any missing translations and specify the expected content.
|
|
19
|
+
- **Misplaced Content:** Detect if any translations are placed under incorrect keys.
|
|
20
|
+
- **Type Compliance:** Verify that the content types match the declarations (e.g., strings, string arrays).
|
|
21
|
+
|
|
22
|
+
4. **Modification Guidelines:**
|
|
23
|
+
|
|
24
|
+
- **Return Only the Targeted Content:** Provide the updated targeted content as plain text without any markdown, additional comments or explanations.
|
|
25
|
+
- **Consider the locale context:** If the targeted field correspond to a specific language, contains similar languages, as `zh` or `en-GB`, consider return the content in this specified language.
|
|
26
|
+
- **Escape Special Characters:** If the translations contain special characters, escape them using the appropriate escape sequence.
|
|
27
|
+
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
28
|
+
|
|
29
|
+
5. **Example Scenario:**
|
|
30
|
+
|
|
31
|
+
- **Example 1:**
|
|
32
|
+
|
|
33
|
+
- **Input File:**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
key: "creative-work-structured-data",
|
|
40
|
+
content: {
|
|
41
|
+
audienceType: t({
|
|
42
|
+
en: "Developers, Content Managers",
|
|
43
|
+
fr: "Développeurs, Responsables de contenu",
|
|
44
|
+
es: "",
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
} satisfies DeclarationContent;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Input keyPath:**
|
|
51
|
+
|
|
52
|
+
`[{type: "object", key: "audienceType"},{type: "translation", key: "es"}]`
|
|
53
|
+
|
|
54
|
+
- **Expected Output:**
|
|
55
|
+
|
|
56
|
+
Desarrolladores, Gestores de Contenido
|
|
57
|
+
|
|
58
|
+
- **Example 2:**
|
|
59
|
+
|
|
60
|
+
- **Input File:**
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { t, enu, type DeclarationContent } from "intlayer";
|
|
64
|
+
|
|
65
|
+
const content = {
|
|
66
|
+
key: "creative-work-structured-data",
|
|
67
|
+
content: {
|
|
68
|
+
en: {
|
|
69
|
+
audienceType: t({
|
|
70
|
+
en: "Developers, Content Managers",
|
|
71
|
+
fr: "Développeurs, Responsables de contenu",
|
|
72
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
audienceType: {
|
|
76
|
+
object1: enu({
|
|
77
|
+
"1": t({
|
|
78
|
+
en: "Developers, Content Managers",
|
|
79
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
80
|
+
fr: "Développeurs, Responsables de contenu",
|
|
81
|
+
}),
|
|
82
|
+
">2": t({
|
|
83
|
+
en: "Developers, Content Managers",
|
|
84
|
+
es: "Desarrolladores, Gestores de Contenido",
|
|
85
|
+
fr: "Here content thst make no sense and should be replaced",
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
} satisfies DeclarationContent;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **Input target:**
|
|
94
|
+
|
|
95
|
+
`[{type: "object", key: "audienceType"},{type: "enumeration", key: ">2"},{type: "object", key: "audienceType"},{type: "translation", key: "es"}]`
|
|
96
|
+
|
|
97
|
+
- **Expected Output:**
|
|
98
|
+
|
|
99
|
+
Développeurs, Responsables de contenu
|
|
100
|
+
|
|
101
|
+
**Tags Instructions:**
|
|
102
|
+
|
|
103
|
+
{{tagsInstructions}}
|
|
104
|
+
|
|
105
|
+
**File to Audit:**
|
|
106
|
+
|
|
107
|
+
{{fileContent}}
|
|
108
|
+
|
|
109
|
+
**KeyPath:**
|
|
110
|
+
|
|
111
|
+
{{keyPath}}
|
|
112
|
+
|
|
113
|
+
**Expected Response:**
|
|
114
|
+
|
|
115
|
+
After auditing, provide only the targeted content as plain text without any Markdown or code block formatting. If no changes are needed, return the targeted content
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auditDictionaryField_exports = {};
|
|
20
|
+
__export(auditDictionaryField_exports, {
|
|
21
|
+
auditDictionaryField: () => auditDictionaryField
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auditDictionaryField_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_url = require("url");
|
|
27
|
+
var import_core = require("@intlayer/core");
|
|
28
|
+
var import_logger = require('./../../logger/index.cjs');
|
|
29
|
+
var import_openai = require("openai");
|
|
30
|
+
const import_meta = {};
|
|
31
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
32
|
+
const getFileContent = (relativeFilePath) => {
|
|
33
|
+
const absolutePath = (0, import_path.join)(__dirname, relativeFilePath);
|
|
34
|
+
const fileContent = (0, import_fs.readFileSync)(absolutePath, "utf-8");
|
|
35
|
+
return fileContent;
|
|
36
|
+
};
|
|
37
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
38
|
+
const formatLocaleWithName = (locale) => {
|
|
39
|
+
const localeName = (0, import_core.getLocaleName)(locale);
|
|
40
|
+
return `${locale}: ${localeName}`;
|
|
41
|
+
};
|
|
42
|
+
const formatTagInstructions = (tags = []) => tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join("\n\n");
|
|
43
|
+
const auditDictionaryField = async ({
|
|
44
|
+
fileContent,
|
|
45
|
+
model,
|
|
46
|
+
openAiApiKey,
|
|
47
|
+
customPrompt,
|
|
48
|
+
locales,
|
|
49
|
+
keyPath,
|
|
50
|
+
tags
|
|
51
|
+
}) => {
|
|
52
|
+
try {
|
|
53
|
+
const openai = new import_openai.OpenAI({
|
|
54
|
+
apiKey: openAiApiKey
|
|
55
|
+
});
|
|
56
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
57
|
+
"{{otherLocales}}",
|
|
58
|
+
`{${locales.map(formatLocaleWithName).join(", ")}}`
|
|
59
|
+
).replace("{{keyPath}}", JSON.stringify(keyPath)).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
60
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
61
|
+
model: model ?? "gpt-4o-mini",
|
|
62
|
+
messages: [{ role: "system", content: prompt }]
|
|
63
|
+
});
|
|
64
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
65
|
+
import_logger.logger.info(
|
|
66
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
67
|
+
);
|
|
68
|
+
console.log("newContent", newContent);
|
|
69
|
+
return {
|
|
70
|
+
fileContent: newContent ?? "",
|
|
71
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(error);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
auditDictionaryField
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionaryField/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName, type KeyPath } from '@intlayer/core';\nimport { logger } from '@logger';\nimport { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditDictionaryFieldOptions = {\n locales: Locales[];\n fileContent: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n keyPath: KeyPath[];\n tags?: Tag[];\n};\nexport type AuditDictionaryFieldResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionaryField = async ({\n fileContent,\n model,\n openAiApiKey,\n customPrompt,\n locales,\n keyPath,\n tags,\n}: AuditDictionaryFieldOptions): Promise<\n AuditDictionaryFieldResultData | undefined\n> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace('{{keyPath}}', JSON.stringify(keyPath))\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n console.log('newContent', newContent);\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,kBAA4C;AAC5C,oBAAuB;AAEvB,oBAAuB;AANvB;AASA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAuBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AASpD,MAAM,uBAAuB,CAAC,WAA4B;AAExD,QAAM,iBAAa,2BAAc,MAAM;AAGvC,SAAO,GAAG,MAAM,KAAK,UAAU;AACjC;AASA,MAAM,wBAAwB,CAAC,OAAc,CAAC,MAC5C,KAAK,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,YAAY,EAAE,EAAE,KAAK,MAAM;AAQ7D,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAEK;AACH,MAAI;AAIF,UAAM,SAAS,IAAI,qBAAO;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB;AAAA,MACd;AAAA,MACA,IAAI,QAAQ,IAAI,oBAAoB,EAAE,KAAK,IAAI,CAAC;AAAA,IAClD,EACG,QAAQ,eAAe,KAAK,UAAU,OAAO,CAAC,EAC9C,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,SAAS;AAAA,MAChB,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,yBAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,YAAQ,IAAI,cAAc,UAAU;AAEpC,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Your role is to review content declaration fields. Correct this fields if they are misspelled or do not match the expected content, and / or complete missing content.
|
|
2
|
+
|
|
3
|
+
1. **Terminology:**
|
|
4
|
+
|
|
5
|
+
- **Content Declaration:** A content declaration is a is a file (.ts, .js or .json) that contains the multilingual declaration related to a specific content. A content declaration file is usually related to a specific component, or page or section of a website.
|
|
6
|
+
- **Tag:** A tag is attached to a content declaration and is used to group content declaration and harmonize them.
|
|
7
|
+
|
|
8
|
+
2. **Audit Requirements:**
|
|
9
|
+
|
|
10
|
+
- **Do Not Alter Structure:** If the file structure is correct, do not modify it. Only add, update, or remove content declarations as necessary.
|
|
11
|
+
- **Misspelled Content:** If declared, detect each `title`, `description` and `tags` are not misspelled. If some content is misspelled, correct it.
|
|
12
|
+
|
|
13
|
+
3. **Fields functions:**
|
|
14
|
+
|
|
15
|
+
- **Title:** The title of the content declaration allows to easily identify it. It should be considered as a readable way to represent the `key` (example: `page-metadata` -> `Page metadata`). It should be a short and descriptive title that accurately reflects the dictionary.
|
|
16
|
+
- **Description:** The description of the content declaration provides a brief summary of the content declaration. It should be a concise and informative description that explains the purpose and content of the dictionary.
|
|
17
|
+
- **Tags:** The tags is an array of strings that represent the key of the tags associated with the content declaration.
|
|
18
|
+
|
|
19
|
+
**Expected Response:**
|
|
20
|
+
|
|
21
|
+
After completion, provide only the final title, description and tags fields in a JSON without any Markdown, code block formatting or any additional comments or explanations.
|
|
22
|
+
|
|
23
|
+
**Example of expected response:**
|
|
24
|
+
|
|
25
|
+
- Entry:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { t, type DeclarationContent } from "intlayer";
|
|
29
|
+
import { Metadata } from "next";
|
|
30
|
+
|
|
31
|
+
const metadataContent = {
|
|
32
|
+
key: "pricing-metadata",
|
|
33
|
+
title: "",
|
|
34
|
+
description:
|
|
35
|
+
"here a description that doesn't make any sense and should be replaced",
|
|
36
|
+
content: {
|
|
37
|
+
title: t({
|
|
38
|
+
en: "Pricing | Intlayer",
|
|
39
|
+
fr: "Tarification | Intlayer",
|
|
40
|
+
es: "Precios | Intlayer",
|
|
41
|
+
}),
|
|
42
|
+
description: t({
|
|
43
|
+
en: "Discover our pricing plans and get access to premium features with Intlayer. Choose the plan that suits you best.",
|
|
44
|
+
fr: "Découvrez nos plans tarifaires et accédez aux fonctionnalités premium avec Intlayer. Choisissez le plan qui vous convient le mieux.",
|
|
45
|
+
es: "Descubre nuestros planes de precios y accede a funciones premium con Intlayer. Elige el plan que mejor te convenga.",
|
|
46
|
+
}),
|
|
47
|
+
keywords: t<string[]>({
|
|
48
|
+
en: ["Pricing", "Subscription"],
|
|
49
|
+
fr: ["Tarification", "Abonnement"],
|
|
50
|
+
es: ["Precios", "Suscripción"],
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
} satisfies DeclarationContent<Metadata>;
|
|
54
|
+
|
|
55
|
+
export default metadataContent;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Response:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"title": "Pricing page metadata",
|
|
63
|
+
"description": "Metadata related to the pricing page, includes title, description, keywords, metadata for SEO purpose. It will help search engines understand the content of the page.",
|
|
64
|
+
"tags": ["page metadata", "pricing page"]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**List of existing Tags:**
|
|
69
|
+
|
|
70
|
+
Here the list of existing tags as a context to help you to pick related ones.
|
|
71
|
+
|
|
72
|
+
{{tags}}
|
|
73
|
+
|
|
74
|
+
**Content Declaration to complete:**
|
|
75
|
+
|
|
76
|
+
{{contentDeclaration}}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var auditDictionaryMetadata_exports = {};
|
|
20
|
+
__export(auditDictionaryMetadata_exports, {
|
|
21
|
+
auditDictionaryMetadata: () => auditDictionaryMetadata
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(auditDictionaryMetadata_exports);
|
|
24
|
+
var import_fs = require("fs");
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_url = require("url");
|
|
27
|
+
var import_logger = require('./../../logger/index.cjs');
|
|
28
|
+
var import_openai = require("openai");
|
|
29
|
+
const import_meta = {};
|
|
30
|
+
const __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url));
|
|
31
|
+
const getFileContent = (relativeFilePath) => {
|
|
32
|
+
const absolutePath = (0, import_path.join)(__dirname, relativeFilePath);
|
|
33
|
+
const fileContent = (0, import_fs.readFileSync)(absolutePath, "utf-8");
|
|
34
|
+
return fileContent;
|
|
35
|
+
};
|
|
36
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
37
|
+
const auditDictionaryMetadata = async ({
|
|
38
|
+
model,
|
|
39
|
+
openAiApiKey,
|
|
40
|
+
customPrompt,
|
|
41
|
+
tags,
|
|
42
|
+
fileContent
|
|
43
|
+
}) => {
|
|
44
|
+
try {
|
|
45
|
+
const openai = new import_openai.OpenAI({
|
|
46
|
+
apiKey: openAiApiKey
|
|
47
|
+
});
|
|
48
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
49
|
+
"{{tags}}",
|
|
50
|
+
`${JSON.stringify(
|
|
51
|
+
tags.map(({ key, description }) => `- ${key}: ${description}`).join("\n\n"),
|
|
52
|
+
null,
|
|
53
|
+
2
|
|
54
|
+
)}`
|
|
55
|
+
).replace("{{contentDeclaration}}", fileContent);
|
|
56
|
+
console.log("prompt", prompt);
|
|
57
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
58
|
+
model: model ?? "gpt-4o-mini",
|
|
59
|
+
messages: [{ role: "system", content: prompt }]
|
|
60
|
+
});
|
|
61
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
62
|
+
console.log("newContent", newContent);
|
|
63
|
+
import_logger.logger.info(
|
|
64
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
65
|
+
);
|
|
66
|
+
return {
|
|
67
|
+
fileContent: newContent ?? "",
|
|
68
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
auditDictionaryMetadata
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AuditOptions = {\n tags: Tag[];\n fileContent: string;\n model?: string;\n openAiApiKey: string;\n customPrompt?: string;\n};\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n */\nexport const auditDictionaryMetadata = async ({\n model,\n openAiApiKey,\n customPrompt,\n tags,\n fileContent,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{tags}}',\n `${JSON.stringify(\n tags\n .map(({ key, description }) => `- ${key}: ${description}`)\n .join('\\n\\n'),\n null,\n 2\n )}`\n ).replace('{{contentDeclaration}}', fileContent);\n\n console.log('prompt', prompt);\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: model ?? 'gpt-4o-mini',\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n console.log('newContent', newContent);\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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