From 33f5cf9c40feb6544cd94076f6f07d4554e747c5 Mon Sep 17 00:00:00 2001 From: Steven Thompson Date: Fri, 10 Jan 2025 15:20:52 +0000 Subject: [PATCH] fix(crowdin): move from import to require (#235) --- plugin/src/lib/api/connection.ts | 6 ------ .../src/lib/api/payload-crowdin-sync/translations.ts | 7 +++++-- plugin/src/lib/hooks/collections/afterChange.ts | 8 +++++--- plugin/src/lib/hooks/collections/afterDelete.ts | 10 ++++++---- 4 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 plugin/src/lib/api/connection.ts diff --git a/plugin/src/lib/api/connection.ts b/plugin/src/lib/api/connection.ts deleted file mode 100644 index 1235ba3..0000000 --- a/plugin/src/lib/api/connection.ts +++ /dev/null @@ -1,6 +0,0 @@ -import crowdin from "@crowdin/crowdin-api-client"; - -export const { uploadStorageApi, sourceFilesApi } = new crowdin({ - token: process.env['CROWDIN_API_TOKEN'] as string, - organization: process.env['CROWDIN_ORGANIZATION'] as string, -}); diff --git a/plugin/src/lib/api/payload-crowdin-sync/translations.ts b/plugin/src/lib/api/payload-crowdin-sync/translations.ts index 54a4cfe..5401e76 100644 --- a/plugin/src/lib/api/payload-crowdin-sync/translations.ts +++ b/plugin/src/lib/api/payload-crowdin-sync/translations.ts @@ -1,4 +1,4 @@ -import crowdin, { +import { Credentials, CrowdinError, Translations, @@ -35,6 +35,9 @@ import { getRelationshipId } from "../../utilities/payload"; import { merge } from "es-toolkit"; import { isEmpty } from 'es-toolkit/compat'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const crowdin = require('@crowdin/crowdin-api-client'); + interface IgetLatestDocumentTranslation { collection: string; doc: any; @@ -87,7 +90,7 @@ export class payloadCrowdinSyncTranslationsApi { token: pluginOptions.token, organization: pluginOptions.organization, }; - const { translationsApi } = new crowdin(credentials); + const { translationsApi } = new crowdin.default(credentials); this.projectId = pluginOptions.projectId; this.directoryId = pluginOptions.directoryId; this.translationsApi = translationsApi; diff --git a/plugin/src/lib/hooks/collections/afterChange.ts b/plugin/src/lib/hooks/collections/afterChange.ts index f04dfae..ddb86c9 100644 --- a/plugin/src/lib/hooks/collections/afterChange.ts +++ b/plugin/src/lib/hooks/collections/afterChange.ts @@ -31,7 +31,9 @@ import { import { CrowdinArticleDirectory, CrowdinFile } from "./../../payload-types"; import { toWords } from 'payload'; -import crowdin, { Credentials, SourceFiles, UploadStorage, } from "@crowdin/crowdin-api-client"; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const crowdin = require('@crowdin/crowdin-api-client'); +import { Credentials, SourceFiles, UploadStorage } from "@crowdin/crowdin-api-client"; import { getCollectionConfig, getArticleDirectory, getFileByDocumentID, @@ -69,7 +71,7 @@ export class payloadCrowdinSyncFilesApi { const credentials: Credentials = { token: pluginOptions.token, }; - const { sourceFilesApi, uploadStorageApi } = new crowdin(credentials); + const { sourceFilesApi, uploadStorageApi } = new crowdin.default(credentials); this.projectId = pluginOptions.projectId; this.directoryId = pluginOptions.directoryId; this.sourceFilesApi = sourceFilesApi; @@ -217,7 +219,7 @@ export class filesApiByDocument { token: pluginOptions.token, organization: pluginOptions.organization, }; - const { sourceFilesApi } = new crowdin(credentials); + const { sourceFilesApi } = new crowdin.default(credentials); this.projectId = pluginOptions.projectId; this.directoryId = pluginOptions.directoryId; this.sourceFilesApi = sourceFilesApi; diff --git a/plugin/src/lib/hooks/collections/afterDelete.ts b/plugin/src/lib/hooks/collections/afterDelete.ts index 989eed5..31a1ec4 100644 --- a/plugin/src/lib/hooks/collections/afterDelete.ts +++ b/plugin/src/lib/hooks/collections/afterDelete.ts @@ -1,7 +1,6 @@ import type { BlocksField as BlockField, CollectionConfig, - Config, Document, GlobalConfig, PayloadRequest, @@ -25,7 +24,7 @@ import { import { CrowdinArticleDirectory, CrowdinFile } from "./../../payload-types"; import { toWords } from 'payload'; -import crowdin, { Credentials, SourceFiles, UploadStorage, } from "@crowdin/crowdin-api-client"; +import { Credentials, SourceFiles, UploadStorage, } from "@crowdin/crowdin-api-client"; import { getCollectionConfig, getArticleDirectory, getFileByDocumentID, @@ -36,6 +35,9 @@ import { isEmpty } from 'es-toolkit/compat'; import { convertLexicalToHtml, convertSlateToHtml } from '../../utilities/richTextConversion' import { extractLexicalBlockContent, getLexicalBlockFields, getLexicalEditorConfig } from '../../utilities/lexical'; +// eslint-disable-next-line @typescript-eslint/no-var-requires +const crowdin = require('@crowdin/crowdin-api-client'); + interface IcreateOrUpdateFile { name: string; fileData: string | object; @@ -63,7 +65,7 @@ export class payloadCrowdinSyncFilesApi { const credentials: Credentials = { token: pluginOptions.token, }; - const { sourceFilesApi, uploadStorageApi } = new crowdin(credentials); + const { sourceFilesApi, uploadStorageApi } = new crowdin.default(credentials); this.projectId = pluginOptions.projectId; this.directoryId = pluginOptions.directoryId; this.sourceFilesApi = sourceFilesApi; @@ -211,7 +213,7 @@ export class filesApiByDocument { token: pluginOptions.token, organization: pluginOptions.organization, }; - const { sourceFilesApi } = new crowdin(credentials); + const { sourceFilesApi } = new crowdin.default(credentials); this.projectId = pluginOptions.projectId; this.directoryId = pluginOptions.directoryId; this.sourceFilesApi = sourceFilesApi;