sanity-plugin-studio-smartling 4.3.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -5
- package/dist/index.d.ts +7 -47
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -219
- package/dist/index.js.map +1 -1
- package/package.json +34 -66
- package/dist/index.esm.js +0 -268
- package/dist/index.esm.js.map +0 -1
- package/sanity.json +0 -8
- package/src/adapter/createTask.ts +0 -166
- package/src/adapter/getLocales.ts +0 -18
- package/src/adapter/getTranslation.ts +0 -36
- package/src/adapter/getTranslationTask.ts +0 -89
- package/src/adapter/helpers.ts +0 -84
- package/src/adapter/index.ts +0 -12
- package/src/index.ts +0 -52
- package/src/types.d.ts +0 -0
- package/v2-incompatible.js +0 -11
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/adapter/helpers.ts","../src/adapter/getLocales.ts","../src/adapter/getTranslationTask.ts","../src/adapter/createTask.ts","../src/adapter/getTranslation.ts","../src/adapter/index.ts","../src/index.ts"],"sourcesContent":["import {Secrets} from 'sanity-translations-tab'\n\ninterface Headers {\n [key: string]: string\n}\n\nexport const authenticate = (secrets: Secrets): Promise<string> => {\n const url = 'https://api.smartling.com/auth-api/v2/authenticate'\n const headers = {\n 'content-type': 'application/json',\n 'X-URL': url,\n }\n const {secret, proxy} = secrets\n if (!secret || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a secret key and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n return fetch(proxy, {\n headers,\n method: 'POST',\n body: JSON.stringify(secret),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.accessToken)\n}\n\nexport const getHeaders = (url: string, accessToken: string): Headers => ({\n Authorization: `Bearer ${accessToken}`,\n 'X-URL': url,\n})\n\nexport const findExistingJob = async (\n documentId: string,\n secrets: Secrets,\n accessToken: string,\n): Promise<string> => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs?jobName=${documentId}`\n //first, try fetching from name resolution\n let items = await fetch(proxy, {\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n\n if (!items || !items.length) {\n //if that fails, try fetching by fileUri and check the referenceNumber\n const refUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/search`\n items = await fetch(proxy, {\n headers: {\n ...getHeaders(refUrl, accessToken),\n 'content-type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n fileUris: [documentId],\n }),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n }\n\n if (items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = items\n .filter((item: {jobStatus: string}) => item.jobStatus !== 'DELETED')\n .find(\n (item: {jobName: string; referenceNumber: string}) =>\n (item.jobName && item.jobName === documentId) ||\n (item.referenceNumber && item.referenceNumber === documentId),\n )\n\n if (correctJob) {\n return correctJob.translationJobUid\n }\n }\n return ''\n}\n","import {authenticate, getHeaders} from './helpers'\nimport {Secrets} from 'sanity-translations-tab'\nimport {Adapter} from 'sanity-translations-tab'\n\nexport const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return []\n }\n const {project, proxy} = secrets\n const url = `https://api.smartling.com/projects-api/v2/projects/${project}`\n const accessToken = await authenticate(secrets)\n return fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.targetLocales)\n}\n","import {authenticate, getHeaders, findExistingJob} from './helpers'\nimport {Adapter, Secrets} from 'sanity-translations-tab'\n\ninterface WorkflowProgressItem {\n workflowStepSummaryReportItemList: {\n wordCount: number\n }[]\n}\n\ninterface SmartlingProgressItem {\n targetLocaleId: string\n progress: {\n percentComplete: number\n totalWordCount: number\n }\n workflowProgressReportList: WorkflowProgressItem[]\n}\n\nexport const getTranslationTask: Adapter['getTranslationTask'] = async (\n documentId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const {project, proxy} = secrets\n\n const accessToken = await authenticate(secrets)\n const taskId = await findExistingJob(documentId, secrets, accessToken)\n if (!taskId) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const progressUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/${taskId}/progress`\n const smartlingTask = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(progressUrl, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data)\n\n let locales = []\n if (smartlingTask && smartlingTask.contentProgressReport) {\n locales = smartlingTask.contentProgressReport.map((item: SmartlingProgressItem) => {\n let progress = item.progress ? item.progress.percentComplete : 0\n if (\n item.workflowProgressReportList &&\n item.workflowProgressReportList.length > 0 &&\n item.progress\n ) {\n //default to the first workflow -- it's likely what is being used\n const progressItem = item.workflowProgressReportList[0]\n //this is a list of the various steps in the workflow\n if (\n progressItem.workflowStepSummaryReportItemList &&\n progressItem.workflowStepSummaryReportItemList.length > 1\n ) {\n //get the last step in the workflow -- usually \"published\"\n const lastStep = progressItem.workflowStepSummaryReportItemList.at(-1)\n //get the percentage of how many words have reached the last step\n if (lastStep && lastStep.wordCount >= 0) {\n progress = Math.floor((lastStep.wordCount / item.progress.totalWordCount) * 100) ?? 0\n }\n }\n }\n return {\n localeId: item.targetLocaleId,\n progress,\n }\n })\n }\n\n return {\n documentId,\n locales,\n //since our download is tied to document id for smartling, keep track of it as a task\n taskId: documentId,\n linkToVendorTask: `https://dashboard.smartling.com/app/projects/${project}/account-jobs/${project}:${taskId}`,\n }\n}\n","import {authenticate, getHeaders, findExistingJob} from './helpers'\nimport {Adapter, Secrets, SerializedDocument} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (\n jobName: string,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n documentId: string,\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs`\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n jobName,\n targetLocaleIds: localeIds,\n referenceNumber: documentId,\n }),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.translationJobUid)\n}\n\n/* we're using batches here because it eliminates some\n * new string authorization issues for updating existing jobs,\n * and is able to be used for new bulk\n * job functionality.\n */\n\nconst createJobBatch = (\n jobId: string,\n secrets: Secrets,\n documentId: string,\n accessToken: string,\n localeIds: string[],\n workflowUid?: string,\n //eslint-disable-next-line max-params\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches`\n const reqBody: {\n authorize: boolean\n translationJobUid: string\n fileUris: string[]\n localeWorkflows?: {targetLocaleId: string; workflowUid: string}[]\n } = {\n authorize: true,\n translationJobUid: jobId,\n fileUris: [documentId],\n }\n\n if (workflowUid) {\n reqBody.localeWorkflows = localeIds.map((l) => ({\n targetLocaleId: l,\n workflowUid,\n }))\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify(reqBody),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.batchUid)\n}\n\nconst uploadFileToBatch = (\n batchUid: string,\n documentId: string,\n document: SerializedDocument,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n callbackUrl?: string,\n //eslint-disable-next-line max-params\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches/${batchUid}/file`\n const formData = new FormData()\n formData.append('fileUri', documentId)\n formData.append('fileType', 'html')\n const htmlBuffer = Buffer.from(document.content, 'utf-8')\n formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`)\n localeIds.forEach((localeId) => formData.append('localeIdsToAuthorize[]', localeId))\n if (callbackUrl) {\n formData.append('callbackUrl', callbackUrl)\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n body: formData,\n }).then((res) => res.json())\n}\n\nexport const createTask: Adapter['createTask'] = async (\n documentId: string,\n document: SerializedDocument,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: string,\n callbackUrl?: string,\n // eslint-disable-next-line max-params\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const accessToken = await authenticate(secrets)\n\n let taskId = await findExistingJob(document.name, secrets, accessToken)\n if (!taskId) {\n taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n documentId,\n accessToken,\n localeIds,\n workflowUid,\n )\n const uploadFileRes = await uploadFileToBatch(\n batchUid,\n documentId,\n document,\n secrets,\n localeIds,\n accessToken,\n callbackUrl,\n )\n //eslint-disable-next-line no-console -- for developer debugging\n console.info('Upload status from Smartling: ', uploadFileRes)\n\n return getTranslationTask(documentId, secrets)\n}\n","import {authenticate, getHeaders} from './helpers'\nimport {Adapter, Secrets} from 'sanity-translations-tab'\n\nexport const getTranslation: Adapter['getTranslation'] = async (\n taskId: string,\n localeId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const {project, proxy} = secrets\n\n const url = `https://api.smartling.com/files-api/v2/projects/${project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`\n const accessToken = await authenticate(secrets)\n const translatedHTML = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.body) {\n return res.body\n } else if (res.response.errors) {\n const errMsg =\n res.response.errors[0]?.message || 'Error retrieving translation from Smartling'\n throw new Error(errMsg)\n }\n return ''\n })\n\n return translatedHTML\n}\n","import {Adapter} from 'sanity-translations-tab'\nimport {getLocales} from './getLocales'\nimport {getTranslationTask} from './getTranslationTask'\nimport {createTask} from './createTask'\nimport {getTranslation} from './getTranslation'\n\nexport const SmartlingAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import {\n TranslationsTab,\n baseDocumentLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n TranslationsTabConfigOptions,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\nconst defaultDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst legacyDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: TranslationsTabConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n legacyDocumentLevelConfig,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n\nexport type {TranslationFunctionContext, TranslationsTabConfigOptions}\n"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","concat","findExistingJob","documentId","project","items","_a","_b","length","refUrl","fileUris","correctJob","filter","item","jobStatus","find","jobName","referenceNumber","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","workflowUid","reqBody","authorize","localeWorkflows","l","batchUid","uploadFileToBatch","document","callbackUrl","formData","FormData","append","htmlBuffer","Buffer","from","content","Blob","name","forEach","createTask","uploadFileRes","console","info","getTranslation","translatedHTML","errors","errMsg","message","SmartlingAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","legacyDocumentLevelConfig","baseLegacyDocumentLevelConfig","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;;;;;;AAMa,MAAAA,YAAA,GAAgBC,OAAsC,IAAA;EACjE,MAAMC,GAAM,GAAA,oDAAA;EACZ,MAAMC,OAAU,GAAA;IACd,cAAgB,EAAA,kBAAA;IAChB,OAAS,EAAAD;EAAA,CACX;EACM,MAAA;IAACE,MAAQ;IAAAC;EAAS,CAAA,GAAAJ,OAAA;EACpB,IAAA,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,MAAMnF,KAAA,CAAMF,KAAO,EAAA;IACxCG,MAAQ,EAAA,KAAA;IACRL,OAAA,EAASe,UAAW,CAAAhB,GAAA,EAAKe,WAAW;EAAA,CACrC,CACE,CAAAL,IAAA,CAAMC,GAAA,IAAQA,GAAI,CAAAC,IAAA,EAAM,CAAA,CACxBF,IAAK,CAACC,GAAQ,IAAA;IAvBnB,IAAAY,EAAA;IAwBM,IAAIZ,IAAIJ,IAAM,EAAA;MACZ,OAAOI,GAAI,CAAAJ,IAAA;IAAA,CACb,MAAA,IAAWI,GAAI,CAAAE,QAAA,CAAS4E,MAAQ,EAAA;MAC9B,MAAMC,WACJnE,EAAI,GAAAZ,GAAA,CAAAE,QAAA,CAAS4E,OAAO,CAAC,CAAA,KAArB,mBAAwBE,OAAW,KAAA,6CAAA;MAC/B,MAAA,IAAIvF,MAAMsF,MAAM,CAAA;IACxB;IACO,OAAA,EAAA;EAAA,CACR,CAAA;EAEI,OAAAF,cAAA;AACT,CAAA;AC7BO,MAAMI,gBAA4B,GAAA;EACvCxD,UAAA;EACAE,kBAAA;EACA6C,UAAA;EACAI;AACF,CAAA;ACQA,MAAMM,0BAA2D,GAAA;EAC/D,GAAGC,qBAAA,CAAAA,uBAAA;EACHC,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMI,yBAA0D,GAAA;EAC9D,GAAGC,qBAAA,CAAAD,yBAAA;EACHD,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMM,uBAAwD,GAAA;EAC5D,GAAGC,qBAAA,CAAAA,oBAAA;EACHJ,OAAS,EAAAH;AACX,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/adapter/helpers.ts","../src/adapter/getTranslationTask.ts","../src/adapter/createTask.ts","../src/adapter/getLocales.ts","../src/adapter/getTranslation.ts","../src/adapter/index.ts","../src/index.ts"],"sourcesContent":["import type {Secrets} from 'sanity-translations-tab'\n\nexport const authenticate = (secrets: Secrets): Promise<string> => {\n const url = 'https://api.smartling.com/auth-api/v2/authenticate'\n const headers = {\n 'content-type': 'application/json',\n 'X-URL': url,\n }\n const {secret, proxy} = secrets\n if (!secret || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a secret key and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n return fetch(proxy, {\n headers,\n method: 'POST',\n body: JSON.stringify(secret),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.accessToken)\n}\n\nexport const getHeaders = (url: string, accessToken: string): Record<string, string> => ({\n 'Authorization': `Bearer ${accessToken}`,\n 'X-URL': url,\n})\n\nexport const findExistingJob = async (\n documentId: string,\n secrets: Secrets,\n accessToken: string,\n): Promise<string> => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs?jobName=${documentId}`\n //first, try fetching from name resolution\n let items = await fetch(proxy, {\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n\n if (!items || !items.length) {\n //if that fails, try fetching by fileUri and check the referenceNumber\n const refUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/search`\n items = await fetch(proxy, {\n headers: {\n ...getHeaders(refUrl, accessToken),\n 'content-type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n fileUris: [documentId],\n }),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n }\n\n if (items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = items\n .filter((item: {jobStatus: string}) => item.jobStatus !== 'DELETED')\n .find(\n (item: {jobName: string; referenceNumber: string}) =>\n (item.jobName && item.jobName === documentId) ||\n (item.referenceNumber && item.referenceNumber === documentId),\n )\n\n if (correctJob) {\n return correctJob.translationJobUid\n }\n }\n return ''\n}\n","import type {Adapter, Secrets} from 'sanity-translations-tab'\n\nimport {authenticate, getHeaders, findExistingJob} from './helpers'\n\ninterface WorkflowProgressItem {\n workflowStepSummaryReportItemList: {\n wordCount: number\n }[]\n}\n\ninterface SmartlingProgressItem {\n targetLocaleId: string\n progress: {\n percentComplete: number\n totalWordCount: number\n }\n workflowProgressReportList: WorkflowProgressItem[]\n}\n\nexport const getTranslationTask: Adapter['getTranslationTask'] = async (\n documentId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const {project, proxy} = secrets\n\n const accessToken = await authenticate(secrets)\n const taskId = await findExistingJob(documentId, secrets, accessToken)\n if (!taskId) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const progressUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/${taskId}/progress`\n const smartlingTask = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(progressUrl, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data)\n\n let locales = []\n if (smartlingTask && smartlingTask.contentProgressReport) {\n locales = smartlingTask.contentProgressReport.map((item: SmartlingProgressItem) => {\n let progress = item.progress ? item.progress.percentComplete : 0\n //default to the first workflow -- it's likely what is being used\n const progressItem = item.workflowProgressReportList?.[0]\n if (progressItem && item.progress) {\n //this is a list of the various steps in the workflow\n if (\n progressItem.workflowStepSummaryReportItemList &&\n progressItem.workflowStepSummaryReportItemList.length > 1\n ) {\n //get the last step in the workflow -- usually \"published\"\n const lastStep = progressItem.workflowStepSummaryReportItemList.at(-1)\n //get the percentage of how many words have reached the last step\n if (lastStep && lastStep.wordCount >= 0) {\n progress = Math.floor((lastStep.wordCount / item.progress.totalWordCount) * 100) ?? 0\n }\n }\n }\n return {\n localeId: item.targetLocaleId,\n progress,\n }\n })\n }\n\n return {\n documentId,\n locales,\n //since our download is tied to document id for smartling, keep track of it as a task\n taskId: documentId,\n linkToVendorTask: `https://dashboard.smartling.com/app/projects/${project}/account-jobs/${project}:${taskId}`,\n }\n}\n","import type {Adapter, Secrets, SerializedDocument} from 'sanity-translations-tab'\n\nimport {getTranslationTask} from './getTranslationTask'\nimport {authenticate, getHeaders, findExistingJob} from './helpers'\n\nconst createJob = (\n jobName: string,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n documentId: string,\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs`\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n jobName,\n targetLocaleIds: localeIds,\n referenceNumber: documentId,\n }),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.translationJobUid)\n}\n\n/* we're using batches here because it eliminates some\n * new string authorization issues for updating existing jobs,\n * and is able to be used for new bulk\n * job functionality.\n */\n\nconst createJobBatch = (\n jobId: string,\n secrets: Secrets,\n documentId: string,\n accessToken: string,\n localeIds: string[],\n workflowUid?: string,\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches`\n const reqBody: {\n authorize: boolean\n translationJobUid: string\n fileUris: string[]\n localeWorkflows?: {targetLocaleId: string; workflowUid: string}[]\n } = {\n authorize: true,\n translationJobUid: jobId,\n fileUris: [documentId],\n }\n\n if (workflowUid) {\n reqBody.localeWorkflows = localeIds.map((l) => ({\n targetLocaleId: l,\n workflowUid,\n }))\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify(reqBody),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.batchUid)\n}\n\nconst uploadFileToBatch = (\n batchUid: string,\n documentId: string,\n document: SerializedDocument,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n callbackUrl?: string,\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches/${batchUid}/file`\n const formData = new FormData()\n formData.append('fileUri', documentId)\n formData.append('fileType', 'html')\n formData.append('file', new Blob([document.content]), `${document.name}.html`)\n localeIds.forEach((localeId) => formData.append('localeIdsToAuthorize[]', localeId))\n if (callbackUrl) {\n formData.append('callbackUrl', callbackUrl)\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n body: formData,\n }).then((res) => res.json())\n}\n\nexport const createTask: Adapter['createTask'] = async (\n documentId: string,\n document: SerializedDocument,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: string,\n callbackUrl?: string,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const accessToken = await authenticate(secrets)\n\n let taskId = await findExistingJob(document.name, secrets, accessToken)\n if (!taskId) {\n taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n documentId,\n accessToken,\n localeIds,\n workflowUid,\n )\n await uploadFileToBatch(\n batchUid,\n documentId,\n document,\n secrets,\n localeIds,\n accessToken,\n callbackUrl,\n )\n\n return getTranslationTask(documentId, secrets)\n}\n","import type {Adapter, Secrets} from 'sanity-translations-tab'\n\nimport {authenticate, getHeaders} from './helpers'\n\nexport const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return []\n }\n const {project, proxy} = secrets\n const url = `https://api.smartling.com/projects-api/v2/projects/${project}`\n const accessToken = await authenticate(secrets)\n return fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.targetLocales)\n}\n","import type {Adapter, Secrets} from 'sanity-translations-tab'\n\nimport {authenticate, getHeaders} from './helpers'\n\nexport const getTranslation: Adapter['getTranslation'] = async (\n taskId: string,\n localeId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const {project, proxy} = secrets\n\n const url = `https://api.smartling.com/files-api/v2/projects/${project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`\n const accessToken = await authenticate(secrets)\n const translatedHTML = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.body) {\n return res.body\n } else if (res.response.errors) {\n const errMsg =\n res.response.errors[0]?.message || 'Error retrieving translation from Smartling'\n throw new Error(errMsg)\n }\n return ''\n })\n\n return translatedHTML\n}\n","import type {Adapter} from 'sanity-translations-tab'\n\nimport {createTask} from './createTask'\nimport {getLocales} from './getLocales'\nimport {getTranslation} from './getTranslation'\nimport {getTranslationTask} from './getTranslationTask'\n\nexport const SmartlingAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import {\n baseDocumentLevelConfig,\n baseFieldLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n} from 'sanity-translations-tab'\nimport type {TranslationsTabConfigOptions} from 'sanity-translations-tab'\n\nimport {SmartlingAdapter} from './adapter'\n\nexport {\n BaseDocumentDeserializer,\n BaseDocumentMerger,\n BaseDocumentSerializer,\n customSerializers,\n defaultStopTypes,\n documentLevelPatch,\n fieldLevelPatch,\n findLatestDraft,\n legacyDocumentLevelPatch,\n TranslationsTab,\n} from 'sanity-translations-tab'\nexport type {\n TranslationFunctionContext,\n TranslationsTabConfigOptions,\n} from 'sanity-translations-tab'\n\nconst defaultDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst legacyDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: TranslationsTabConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n legacyDocumentLevelConfig,\n SmartlingAdapter,\n}\n"],"names":["authenticate","secrets","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","url","findExistingJob","documentId","project","items","length","refUrl","fileUris","correctJob","filter","item","jobStatus","find","jobName","referenceNumber","translationJobUid","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","progress","percentComplete","progressItem","workflowProgressReportList","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","workflowUid","reqBody","authorize","localeWorkflows","l","batchUid","uploadFileToBatch","document","callbackUrl","formData","FormData","append","Blob","content","name","forEach","createTask","getLocales","targetLocales","getTranslation","errors","errMsg","message","SmartlingAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","legacyDocumentLevelConfig","baseLegacyDocumentLevelConfig","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;AAEO,MAAMA,eAAgBC,CAAAA,YAAsC;AAEjE,QAAMC,UAAU;AAAA,IACd,gBAAgB;AAAA,IAChB,SAHU;AAAA,EAAA,GAKN;AAAA,IAACC;AAAAA,IAA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AAAAA,IAASjB;AAAAA,EAAAA,IAASH,SAEnBiB,MAAM,mDAAmDG,OAAO,YAAY+B,QAAQ,iBAAiBjB,MAAM,0BAC3GnB,cAAc,MAAMhB,aAAaC,OAAO;AAiB9C,SAhBuB,MAAMK,MAAMF,OAAO;AAAA,IACxCG,QAAQ;AAAA,IACRL,SAASe,WAAWC,KAAKF,WAAW;AAAA,EAAA,CACrC,EACEL,KAAMC,CAAAA,QAAQA,IAAIC,MAAM,EACxBF,KAAMC,CAAAA,QAAQ;AACb,QAAIA,IAAIJ;AACN,aAAOI,IAAIJ;AACN,QAAII,IAAIE,SAASkE,QAAQ;AAC9B,YAAMC,SACJrE,IAAIE,SAASkE,OAAO,CAAC,GAAGE,WAAW;AACrC,YAAM,IAAI7E,MAAM4E,MAAM;AAAA,IACxB;AACA,WAAO;AAAA,EACT,CAAC;AAGL,GC7BaE,mBAA4B;AAAA,EACvCN;AAAAA,EACA3C;AAAAA,EACA0C;AAAAA,EACAG;AACF,GCcMK,6BAA2D;AAAA,EAC/D,GAAGC;AAAAA,EACHC,SAASH;AACX,GAEMI,4BAA0D;AAAA,EAC9D,GAAGC;AAAAA,EACHF,SAASH;AACX,GAEMM,0BAAwD;AAAA,EAC5D,GAAGC;AAAAA,EACHJ,SAASH;AACX;"}
|
package/package.json
CHANGED
|
@@ -1,88 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-studio-smartling",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "This plugin provides an in-studio integration with Smartling. It allows your editors to send any document to Smartling with the click of a button, monitor ongoing translations, and import partial or complete translations back into the studio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
7
7
|
"sanity-plugin"
|
|
8
8
|
],
|
|
9
|
-
"homepage": "https://github.com/sanity-io/sanity-plugin-studio-smartling#readme",
|
|
9
|
+
"homepage": "https://github.com/sanity-io/plugins/tree/main/plugins/sanity-plugin-studio-smartling#readme",
|
|
10
10
|
"bugs": {
|
|
11
|
-
"url": "https://github.com/sanity-io/
|
|
11
|
+
"url": "https://github.com/sanity-io/plugins/issues"
|
|
12
12
|
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
13
15
|
"repository": {
|
|
14
16
|
"type": "git",
|
|
15
|
-
"url": "git@github.com
|
|
16
|
-
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"author": "Sanity.io",
|
|
19
|
-
"exports": {
|
|
20
|
-
".": {
|
|
21
|
-
"types": "./dist/index.d.ts",
|
|
22
|
-
"source": "./src/index.ts",
|
|
23
|
-
"require": "./dist/index.js",
|
|
24
|
-
"import": "./dist/index.esm.js",
|
|
25
|
-
"default": "./dist/index.esm.js"
|
|
26
|
-
},
|
|
27
|
-
"./package.json": "./package.json"
|
|
17
|
+
"url": "git+ssh://git@github.com/sanity-io/plugins.git",
|
|
18
|
+
"directory": "plugins/sanity-plugin-studio-smartling"
|
|
28
19
|
},
|
|
29
|
-
"main": "./dist/index.js",
|
|
30
|
-
"module": "./dist/index.esm.js",
|
|
31
|
-
"source": "./src/index.ts",
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
33
20
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"sanity.json",
|
|
36
|
-
"src",
|
|
37
|
-
"v2-incompatible.js"
|
|
21
|
+
"dist"
|
|
38
22
|
],
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"link-watch": "plugin-kit link-watch",
|
|
45
|
-
"prepublishOnly": "run-s build",
|
|
46
|
-
"watch": "pkg-utils watch --strict",
|
|
47
|
-
"prepare": "husky install"
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
48
28
|
},
|
|
49
29
|
"dependencies": {
|
|
50
|
-
"
|
|
51
|
-
"sanity-translations-tab": "^4.4.0"
|
|
30
|
+
"sanity-translations-tab": "6.1.4"
|
|
52
31
|
},
|
|
53
32
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"eslint-config-sanity": "^6.0.0",
|
|
65
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
66
|
-
"eslint-plugin-react": "^7.33.2",
|
|
67
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
68
|
-
"husky": "^8.0.3",
|
|
69
|
-
"lint-staged": "^14.0.1",
|
|
70
|
-
"npm-run-all": "^4.1.5",
|
|
71
|
-
"prettier": "^3.0.3",
|
|
72
|
-
"prettier-plugin-packagejson": "^2.4.5",
|
|
73
|
-
"react": "^18.3.1",
|
|
74
|
-
"react-dom": "^18.3.1",
|
|
75
|
-
"react-is": "^18.3.1",
|
|
76
|
-
"rimraf": "^5.0.1",
|
|
77
|
-
"sanity": "^3.40.0",
|
|
78
|
-
"styled-components": "^6.1",
|
|
79
|
-
"typescript": "^5.2.2"
|
|
33
|
+
"@sanity/pkg-utils": "^10.5.7",
|
|
34
|
+
"@types/react": "^19.2.17",
|
|
35
|
+
"@types/react-dom": "^19.2.3",
|
|
36
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
37
|
+
"react": "^19.2.7",
|
|
38
|
+
"react-dom": "^19.2.7",
|
|
39
|
+
"sanity": "^6.1.0",
|
|
40
|
+
"styled-components": "^6.4.2",
|
|
41
|
+
"@repo/package.config": "0.0.0",
|
|
42
|
+
"@repo/tsconfig": "0.0.0"
|
|
80
43
|
},
|
|
81
44
|
"peerDependencies": {
|
|
82
|
-
"react": "^
|
|
83
|
-
"
|
|
45
|
+
"react": "^19.2",
|
|
46
|
+
"react-dom": "^19.2",
|
|
47
|
+
"sanity": "^5 || ^6.0.0-0",
|
|
48
|
+
"styled-components": "^6.1"
|
|
84
49
|
},
|
|
85
50
|
"engines": {
|
|
86
|
-
"node": ">=
|
|
51
|
+
"node": ">=20.19 <22 || >=22.12"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "pkg build --strict --check --clean"
|
|
87
55
|
}
|
|
88
|
-
}
|
|
56
|
+
}
|
package/dist/index.esm.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { baseDocumentLevelConfig, legacyDocumentLevelConfig as legacyDocumentLevelConfig$1, baseFieldLevelConfig } from 'sanity-translations-tab';
|
|
2
|
-
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelPatch } from 'sanity-translations-tab';
|
|
3
|
-
import { Buffer } from 'buffer';
|
|
4
|
-
const authenticate = secrets => {
|
|
5
|
-
const url = "https://api.smartling.com/auth-api/v2/authenticate";
|
|
6
|
-
const headers = {
|
|
7
|
-
"content-type": "application/json",
|
|
8
|
-
"X-URL": url
|
|
9
|
-
};
|
|
10
|
-
const {
|
|
11
|
-
secret,
|
|
12
|
-
proxy
|
|
13
|
-
} = secrets;
|
|
14
|
-
if (!secret || !proxy) {
|
|
15
|
-
throw new Error("The Smartling adapter requires a secret key and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
16
|
-
}
|
|
17
|
-
return fetch(proxy, {
|
|
18
|
-
headers,
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: JSON.stringify(secret)
|
|
21
|
-
}).then(res => res.json()).then(res => res.response.data.accessToken);
|
|
22
|
-
};
|
|
23
|
-
const getHeaders = (url, accessToken) => ({
|
|
24
|
-
Authorization: "Bearer ".concat(accessToken),
|
|
25
|
-
"X-URL": url
|
|
26
|
-
});
|
|
27
|
-
const findExistingJob = async (documentId, secrets, accessToken) => {
|
|
28
|
-
const {
|
|
29
|
-
project,
|
|
30
|
-
proxy
|
|
31
|
-
} = secrets;
|
|
32
|
-
if (!project || !proxy) {
|
|
33
|
-
throw new Error("The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
34
|
-
}
|
|
35
|
-
const url = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs?jobName=").concat(documentId);
|
|
36
|
-
let items = await fetch(proxy, {
|
|
37
|
-
headers: getHeaders(url, accessToken)
|
|
38
|
-
}).then(res => res.json()).then(res => {
|
|
39
|
-
var _a, _b;
|
|
40
|
-
return (_b = (_a = res == null ? void 0 : res.response) == null ? void 0 : _a.data) == null ? void 0 : _b.items;
|
|
41
|
-
});
|
|
42
|
-
if (!items || !items.length) {
|
|
43
|
-
const refUrl = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs/search");
|
|
44
|
-
items = await fetch(proxy, {
|
|
45
|
-
headers: {
|
|
46
|
-
...getHeaders(refUrl, accessToken),
|
|
47
|
-
"content-type": "application/json"
|
|
48
|
-
},
|
|
49
|
-
method: "POST",
|
|
50
|
-
body: JSON.stringify({
|
|
51
|
-
fileUris: [documentId]
|
|
52
|
-
})
|
|
53
|
-
}).then(res => res.json()).then(res => {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
return (_b = (_a = res == null ? void 0 : res.response) == null ? void 0 : _a.data) == null ? void 0 : _b.items;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (items.length) {
|
|
59
|
-
const correctJob = items.filter(item => item.jobStatus !== "DELETED").find(item => item.jobName && item.jobName === documentId || item.referenceNumber && item.referenceNumber === documentId);
|
|
60
|
-
if (correctJob) {
|
|
61
|
-
return correctJob.translationJobUid;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return "";
|
|
65
|
-
};
|
|
66
|
-
const getLocales = async secrets => {
|
|
67
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
const {
|
|
71
|
-
project,
|
|
72
|
-
proxy
|
|
73
|
-
} = secrets;
|
|
74
|
-
const url = "https://api.smartling.com/projects-api/v2/projects/".concat(project);
|
|
75
|
-
const accessToken = await authenticate(secrets);
|
|
76
|
-
return fetch(proxy, {
|
|
77
|
-
method: "GET",
|
|
78
|
-
headers: getHeaders(url, accessToken)
|
|
79
|
-
}).then(res => res.json()).then(res => res.response.data.targetLocales);
|
|
80
|
-
};
|
|
81
|
-
const getTranslationTask = async (documentId, secrets) => {
|
|
82
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
83
|
-
return {
|
|
84
|
-
documentId,
|
|
85
|
-
taskId: documentId,
|
|
86
|
-
locales: []
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const {
|
|
90
|
-
project,
|
|
91
|
-
proxy
|
|
92
|
-
} = secrets;
|
|
93
|
-
const accessToken = await authenticate(secrets);
|
|
94
|
-
const taskId = await findExistingJob(documentId, secrets, accessToken);
|
|
95
|
-
if (!taskId) {
|
|
96
|
-
return {
|
|
97
|
-
documentId,
|
|
98
|
-
taskId: documentId,
|
|
99
|
-
locales: []
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const progressUrl = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs/").concat(taskId, "/progress");
|
|
103
|
-
const smartlingTask = await fetch(proxy, {
|
|
104
|
-
method: "GET",
|
|
105
|
-
headers: getHeaders(progressUrl, accessToken)
|
|
106
|
-
}).then(res => res.json()).then(res => res.response.data);
|
|
107
|
-
let locales = [];
|
|
108
|
-
if (smartlingTask && smartlingTask.contentProgressReport) {
|
|
109
|
-
locales = smartlingTask.contentProgressReport.map(item => {
|
|
110
|
-
var _a;
|
|
111
|
-
let progress = item.progress ? item.progress.percentComplete : 0;
|
|
112
|
-
if (item.workflowProgressReportList && item.workflowProgressReportList.length > 0 && item.progress) {
|
|
113
|
-
const progressItem = item.workflowProgressReportList[0];
|
|
114
|
-
if (progressItem.workflowStepSummaryReportItemList && progressItem.workflowStepSummaryReportItemList.length > 1) {
|
|
115
|
-
const lastStep = progressItem.workflowStepSummaryReportItemList.at(-1);
|
|
116
|
-
if (lastStep && lastStep.wordCount >= 0) {
|
|
117
|
-
progress = (_a = Math.floor(lastStep.wordCount / item.progress.totalWordCount * 100)) != null ? _a : 0;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
localeId: item.targetLocaleId,
|
|
123
|
-
progress
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
documentId,
|
|
129
|
-
locales,
|
|
130
|
-
//since our download is tied to document id for smartling, keep track of it as a task
|
|
131
|
-
taskId: documentId,
|
|
132
|
-
linkToVendorTask: "https://dashboard.smartling.com/app/projects/".concat(project, "/account-jobs/").concat(project, ":").concat(taskId)
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
const createJob = (jobName, secrets, localeIds, accessToken, documentId) => {
|
|
136
|
-
const {
|
|
137
|
-
project,
|
|
138
|
-
proxy
|
|
139
|
-
} = secrets;
|
|
140
|
-
if (!project || !proxy) {
|
|
141
|
-
throw new Error("The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
142
|
-
}
|
|
143
|
-
const url = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs");
|
|
144
|
-
return fetch(proxy, {
|
|
145
|
-
method: "POST",
|
|
146
|
-
headers: {
|
|
147
|
-
...getHeaders(url, accessToken),
|
|
148
|
-
"content-type": "application/json"
|
|
149
|
-
},
|
|
150
|
-
body: JSON.stringify({
|
|
151
|
-
jobName,
|
|
152
|
-
targetLocaleIds: localeIds,
|
|
153
|
-
referenceNumber: documentId
|
|
154
|
-
})
|
|
155
|
-
}).then(res => res.json()).then(res => res.response.data.translationJobUid);
|
|
156
|
-
};
|
|
157
|
-
const createJobBatch = (jobId, secrets, documentId, accessToken, localeIds, workflowUid) => {
|
|
158
|
-
const {
|
|
159
|
-
project,
|
|
160
|
-
proxy
|
|
161
|
-
} = secrets;
|
|
162
|
-
if (!project || !proxy) {
|
|
163
|
-
throw new Error("The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
164
|
-
}
|
|
165
|
-
const url = "https://api.smartling.com/job-batches-api/v2/projects/".concat(project, "/batches");
|
|
166
|
-
const reqBody = {
|
|
167
|
-
authorize: true,
|
|
168
|
-
translationJobUid: jobId,
|
|
169
|
-
fileUris: [documentId]
|
|
170
|
-
};
|
|
171
|
-
if (workflowUid) {
|
|
172
|
-
reqBody.localeWorkflows = localeIds.map(l => ({
|
|
173
|
-
targetLocaleId: l,
|
|
174
|
-
workflowUid
|
|
175
|
-
}));
|
|
176
|
-
}
|
|
177
|
-
return fetch(proxy, {
|
|
178
|
-
method: "POST",
|
|
179
|
-
headers: {
|
|
180
|
-
...getHeaders(url, accessToken),
|
|
181
|
-
"content-type": "application/json"
|
|
182
|
-
},
|
|
183
|
-
body: JSON.stringify(reqBody)
|
|
184
|
-
}).then(res => res.json()).then(res => res.response.data.batchUid);
|
|
185
|
-
};
|
|
186
|
-
const uploadFileToBatch = (batchUid, documentId, document, secrets, localeIds, accessToken, callbackUrl) => {
|
|
187
|
-
const {
|
|
188
|
-
project,
|
|
189
|
-
proxy
|
|
190
|
-
} = secrets;
|
|
191
|
-
if (!project || !proxy) {
|
|
192
|
-
throw new Error("The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
193
|
-
}
|
|
194
|
-
const url = "https://api.smartling.com/job-batches-api/v2/projects/".concat(project, "/batches/").concat(batchUid, "/file");
|
|
195
|
-
const formData = new FormData();
|
|
196
|
-
formData.append("fileUri", documentId);
|
|
197
|
-
formData.append("fileType", "html");
|
|
198
|
-
const htmlBuffer = Buffer.from(document.content, "utf-8");
|
|
199
|
-
formData.append("file", new Blob([htmlBuffer]), "".concat(document.name, ".html"));
|
|
200
|
-
localeIds.forEach(localeId => formData.append("localeIdsToAuthorize[]", localeId));
|
|
201
|
-
if (callbackUrl) {
|
|
202
|
-
formData.append("callbackUrl", callbackUrl);
|
|
203
|
-
}
|
|
204
|
-
return fetch(proxy, {
|
|
205
|
-
method: "POST",
|
|
206
|
-
headers: getHeaders(url, accessToken),
|
|
207
|
-
body: formData
|
|
208
|
-
}).then(res => res.json());
|
|
209
|
-
};
|
|
210
|
-
const createTask = async (documentId, document, localeIds, secrets, workflowUid, callbackUrl) => {
|
|
211
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
212
|
-
throw new Error("The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
213
|
-
}
|
|
214
|
-
const accessToken = await authenticate(secrets);
|
|
215
|
-
let taskId = await findExistingJob(document.name, secrets, accessToken);
|
|
216
|
-
if (!taskId) {
|
|
217
|
-
taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId);
|
|
218
|
-
}
|
|
219
|
-
const batchUid = await createJobBatch(taskId, secrets, documentId, accessToken, localeIds, workflowUid);
|
|
220
|
-
const uploadFileRes = await uploadFileToBatch(batchUid, documentId, document, secrets, localeIds, accessToken, callbackUrl);
|
|
221
|
-
console.info("Upload status from Smartling: ", uploadFileRes);
|
|
222
|
-
return getTranslationTask(documentId, secrets);
|
|
223
|
-
};
|
|
224
|
-
const getTranslation = async (taskId, localeId, secrets) => {
|
|
225
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
226
|
-
throw new Error("The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.");
|
|
227
|
-
}
|
|
228
|
-
const {
|
|
229
|
-
project,
|
|
230
|
-
proxy
|
|
231
|
-
} = secrets;
|
|
232
|
-
const url = "https://api.smartling.com/files-api/v2/projects/".concat(project, "/locales/").concat(localeId, "/file?fileUri=").concat(taskId, "&retrievalType=pending");
|
|
233
|
-
const accessToken = await authenticate(secrets);
|
|
234
|
-
const translatedHTML = await fetch(proxy, {
|
|
235
|
-
method: "GET",
|
|
236
|
-
headers: getHeaders(url, accessToken)
|
|
237
|
-
}).then(res => res.json()).then(res => {
|
|
238
|
-
var _a;
|
|
239
|
-
if (res.body) {
|
|
240
|
-
return res.body;
|
|
241
|
-
} else if (res.response.errors) {
|
|
242
|
-
const errMsg = ((_a = res.response.errors[0]) == null ? void 0 : _a.message) || "Error retrieving translation from Smartling";
|
|
243
|
-
throw new Error(errMsg);
|
|
244
|
-
}
|
|
245
|
-
return "";
|
|
246
|
-
});
|
|
247
|
-
return translatedHTML;
|
|
248
|
-
};
|
|
249
|
-
const SmartlingAdapter = {
|
|
250
|
-
getLocales,
|
|
251
|
-
getTranslationTask,
|
|
252
|
-
createTask,
|
|
253
|
-
getTranslation
|
|
254
|
-
};
|
|
255
|
-
const defaultDocumentLevelConfig = {
|
|
256
|
-
...baseDocumentLevelConfig,
|
|
257
|
-
adapter: SmartlingAdapter
|
|
258
|
-
};
|
|
259
|
-
const legacyDocumentLevelConfig = {
|
|
260
|
-
...legacyDocumentLevelConfig$1,
|
|
261
|
-
adapter: SmartlingAdapter
|
|
262
|
-
};
|
|
263
|
-
const defaultFieldLevelConfig = {
|
|
264
|
-
...baseFieldLevelConfig,
|
|
265
|
-
adapter: SmartlingAdapter
|
|
266
|
-
};
|
|
267
|
-
export { SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, legacyDocumentLevelConfig };
|
|
268
|
-
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/adapter/helpers.ts","../src/adapter/getLocales.ts","../src/adapter/getTranslationTask.ts","../src/adapter/createTask.ts","../src/adapter/getTranslation.ts","../src/adapter/index.ts","../src/index.ts"],"sourcesContent":["import {Secrets} from 'sanity-translations-tab'\n\ninterface Headers {\n [key: string]: string\n}\n\nexport const authenticate = (secrets: Secrets): Promise<string> => {\n const url = 'https://api.smartling.com/auth-api/v2/authenticate'\n const headers = {\n 'content-type': 'application/json',\n 'X-URL': url,\n }\n const {secret, proxy} = secrets\n if (!secret || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a secret key and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n return fetch(proxy, {\n headers,\n method: 'POST',\n body: JSON.stringify(secret),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.accessToken)\n}\n\nexport const getHeaders = (url: string, accessToken: string): Headers => ({\n Authorization: `Bearer ${accessToken}`,\n 'X-URL': url,\n})\n\nexport const findExistingJob = async (\n documentId: string,\n secrets: Secrets,\n accessToken: string,\n): Promise<string> => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs?jobName=${documentId}`\n //first, try fetching from name resolution\n let items = await fetch(proxy, {\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n\n if (!items || !items.length) {\n //if that fails, try fetching by fileUri and check the referenceNumber\n const refUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/search`\n items = await fetch(proxy, {\n headers: {\n ...getHeaders(refUrl, accessToken),\n 'content-type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n fileUris: [documentId],\n }),\n })\n .then((res) => res.json())\n .then((res) => res?.response?.data?.items)\n }\n\n if (items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = items\n .filter((item: {jobStatus: string}) => item.jobStatus !== 'DELETED')\n .find(\n (item: {jobName: string; referenceNumber: string}) =>\n (item.jobName && item.jobName === documentId) ||\n (item.referenceNumber && item.referenceNumber === documentId),\n )\n\n if (correctJob) {\n return correctJob.translationJobUid\n }\n }\n return ''\n}\n","import {authenticate, getHeaders} from './helpers'\nimport {Secrets} from 'sanity-translations-tab'\nimport {Adapter} from 'sanity-translations-tab'\n\nexport const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return []\n }\n const {project, proxy} = secrets\n const url = `https://api.smartling.com/projects-api/v2/projects/${project}`\n const accessToken = await authenticate(secrets)\n return fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.targetLocales)\n}\n","import {authenticate, getHeaders, findExistingJob} from './helpers'\nimport {Adapter, Secrets} from 'sanity-translations-tab'\n\ninterface WorkflowProgressItem {\n workflowStepSummaryReportItemList: {\n wordCount: number\n }[]\n}\n\ninterface SmartlingProgressItem {\n targetLocaleId: string\n progress: {\n percentComplete: number\n totalWordCount: number\n }\n workflowProgressReportList: WorkflowProgressItem[]\n}\n\nexport const getTranslationTask: Adapter['getTranslationTask'] = async (\n documentId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const {project, proxy} = secrets\n\n const accessToken = await authenticate(secrets)\n const taskId = await findExistingJob(documentId, secrets, accessToken)\n if (!taskId) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const progressUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/${taskId}/progress`\n const smartlingTask = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(progressUrl, accessToken),\n })\n .then((res) => res.json())\n .then((res) => res.response.data)\n\n let locales = []\n if (smartlingTask && smartlingTask.contentProgressReport) {\n locales = smartlingTask.contentProgressReport.map((item: SmartlingProgressItem) => {\n let progress = item.progress ? item.progress.percentComplete : 0\n if (\n item.workflowProgressReportList &&\n item.workflowProgressReportList.length > 0 &&\n item.progress\n ) {\n //default to the first workflow -- it's likely what is being used\n const progressItem = item.workflowProgressReportList[0]\n //this is a list of the various steps in the workflow\n if (\n progressItem.workflowStepSummaryReportItemList &&\n progressItem.workflowStepSummaryReportItemList.length > 1\n ) {\n //get the last step in the workflow -- usually \"published\"\n const lastStep = progressItem.workflowStepSummaryReportItemList.at(-1)\n //get the percentage of how many words have reached the last step\n if (lastStep && lastStep.wordCount >= 0) {\n progress = Math.floor((lastStep.wordCount / item.progress.totalWordCount) * 100) ?? 0\n }\n }\n }\n return {\n localeId: item.targetLocaleId,\n progress,\n }\n })\n }\n\n return {\n documentId,\n locales,\n //since our download is tied to document id for smartling, keep track of it as a task\n taskId: documentId,\n linkToVendorTask: `https://dashboard.smartling.com/app/projects/${project}/account-jobs/${project}:${taskId}`,\n }\n}\n","import {authenticate, getHeaders, findExistingJob} from './helpers'\nimport {Adapter, Secrets, SerializedDocument} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (\n jobName: string,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n documentId: string,\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs`\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n jobName,\n targetLocaleIds: localeIds,\n referenceNumber: documentId,\n }),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.translationJobUid)\n}\n\n/* we're using batches here because it eliminates some\n * new string authorization issues for updating existing jobs,\n * and is able to be used for new bulk\n * job functionality.\n */\n\nconst createJobBatch = (\n jobId: string,\n secrets: Secrets,\n documentId: string,\n accessToken: string,\n localeIds: string[],\n workflowUid?: string,\n //eslint-disable-next-line max-params\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches`\n const reqBody: {\n authorize: boolean\n translationJobUid: string\n fileUris: string[]\n localeWorkflows?: {targetLocaleId: string; workflowUid: string}[]\n } = {\n authorize: true,\n translationJobUid: jobId,\n fileUris: [documentId],\n }\n\n if (workflowUid) {\n reqBody.localeWorkflows = localeIds.map((l) => ({\n targetLocaleId: l,\n workflowUid,\n }))\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify(reqBody),\n })\n .then((res) => res.json())\n .then((res) => res.response.data.batchUid)\n}\n\nconst uploadFileToBatch = (\n batchUid: string,\n documentId: string,\n document: SerializedDocument,\n secrets: Secrets,\n localeIds: string[],\n accessToken: string,\n callbackUrl?: string,\n //eslint-disable-next-line max-params\n) => {\n const {project, proxy} = secrets\n if (!project || !proxy) {\n throw new Error(\n 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches/${batchUid}/file`\n const formData = new FormData()\n formData.append('fileUri', documentId)\n formData.append('fileType', 'html')\n const htmlBuffer = Buffer.from(document.content, 'utf-8')\n formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`)\n localeIds.forEach((localeId) => formData.append('localeIdsToAuthorize[]', localeId))\n if (callbackUrl) {\n formData.append('callbackUrl', callbackUrl)\n }\n\n return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n body: formData,\n }).then((res) => res.json())\n}\n\nexport const createTask: Adapter['createTask'] = async (\n documentId: string,\n document: SerializedDocument,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: string,\n callbackUrl?: string,\n // eslint-disable-next-line max-params\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const accessToken = await authenticate(secrets)\n\n let taskId = await findExistingJob(document.name, secrets, accessToken)\n if (!taskId) {\n taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n documentId,\n accessToken,\n localeIds,\n workflowUid,\n )\n const uploadFileRes = await uploadFileToBatch(\n batchUid,\n documentId,\n document,\n secrets,\n localeIds,\n accessToken,\n callbackUrl,\n )\n //eslint-disable-next-line no-console -- for developer debugging\n console.info('Upload status from Smartling: ', uploadFileRes)\n\n return getTranslationTask(documentId, secrets)\n}\n","import {authenticate, getHeaders} from './helpers'\nimport {Adapter, Secrets} from 'sanity-translations-tab'\n\nexport const getTranslation: Adapter['getTranslation'] = async (\n taskId: string,\n localeId: string,\n secrets: Secrets | null,\n) => {\n if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {\n throw new Error(\n 'The Smartling adapter requires a project ID, a secret key, and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',\n )\n }\n\n const {project, proxy} = secrets\n\n const url = `https://api.smartling.com/files-api/v2/projects/${project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`\n const accessToken = await authenticate(secrets)\n const translatedHTML = await fetch(proxy, {\n method: 'GET',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.body) {\n return res.body\n } else if (res.response.errors) {\n const errMsg =\n res.response.errors[0]?.message || 'Error retrieving translation from Smartling'\n throw new Error(errMsg)\n }\n return ''\n })\n\n return translatedHTML\n}\n","import {Adapter} from 'sanity-translations-tab'\nimport {getLocales} from './getLocales'\nimport {getTranslationTask} from './getTranslationTask'\nimport {createTask} from './createTask'\nimport {getTranslation} from './getTranslation'\n\nexport const SmartlingAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import {\n TranslationsTab,\n baseDocumentLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n TranslationsTabConfigOptions,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\nconst defaultDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst legacyDocumentLevelConfig: TranslationsTabConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: TranslationsTabConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n legacyDocumentLevelConfig,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n\nexport type {TranslationFunctionContext, TranslationsTabConfigOptions}\n"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","concat","findExistingJob","documentId","project","items","_a","_b","length","refUrl","fileUris","correctJob","filter","item","jobStatus","find","jobName","referenceNumber","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","workflowUid","reqBody","authorize","localeWorkflows","l","batchUid","uploadFileToBatch","document","callbackUrl","formData","FormData","append","htmlBuffer","Buffer","from","content","Blob","name","forEach","createTask","uploadFileRes","console","info","getTranslation","translatedHTML","errors","errMsg","message","SmartlingAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","legacyDocumentLevelConfig","baseLegacyDocumentLevelConfig","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;;AAMa,MAAAA,YAAA,GAAgBC,OAAsC,IAAA;EACjE,MAAMC,GAAM,GAAA,oDAAA;EACZ,MAAMC,OAAU,GAAA;IACd,cAAgB,EAAA,kBAAA;IAChB,OAAS,EAAAD;EAAA,CACX;EACM,MAAA;IAACE,MAAQ;IAAAC;EAAS,CAAA,GAAAJ,OAAA;EACpB,IAAA,CAACG,MAAU,IAAA,CAACC,KAAO,EAAA;IACrB,MAAM,IAAIC,KAAA,CACR,gJAAA,CACF;EACF;EACA,OAAOC,MAAMF,KAAO,EAAA;IAClBF,OAAA;IACAK,MAAQ,EAAA,MAAA;IACRC,IAAA,EAAMC,IAAK,CAAAC,SAAA,CAAUP,MAAM;EAC5B,CAAA,CAAA,CACEQ,IAAK,CAACC,OAAQA,GAAI,CAAAC,IAAA,CAAA,CAAM,CAAA,CACxBF,KAAMC,GAAA,IAAQA,GAAI,CAAAE,QAAA,CAASC,KAAKC,WAAW,CAAA;AAChD,CAAA;AAEa,MAAAC,UAAA,GAAaA,CAAChB,GAAA,EAAae,WAAkC,MAAA;EACxEE,eAAe,SAAU,CAAAC,MAAA,CAAAH,WAAA,CAAA;EACzB,OAAS,EA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