diff --git a/docs/01-advanced-configuration.md b/docs/01-advanced-configuration.md index 9be44ff..58e9305 100644 --- a/docs/01-advanced-configuration.md +++ b/docs/01-advanced-configuration.md @@ -54,6 +54,13 @@ const customConfig = { }, }, ] + }, + + // add custom params for Smartling + customParams: { + // GET request that creates a callback to a URL when a file is 100% published for a locale. + // The callback gives the fileUri and locale with the format http[/s]://your.url?locale=xx-XX&fileUri=your.file. + callbackUrl: 'https://your-endpoint.here' } //adapter, baseLanguage, secretsNamespace, importTranslation, exportForTranslation should likely not be touched unless you very much want to customize your plugin. } satisfies TranslationsTabConfigOptions diff --git a/src/adapter/createTask.ts b/src/adapter/createTask.ts index d8039a1..3b2811c 100644 --- a/src/adapter/createTask.ts +++ b/src/adapter/createTask.ts @@ -1,5 +1,5 @@ import {authenticate, getHeaders, findExistingJob} from './helpers' -import {Adapter, Secrets} from 'sanity-translations-tab' +import {Adapter, Secrets, CustomParams} from 'sanity-translations-tab' import {getTranslationTask} from './getTranslationTask' import {Buffer} from 'buffer' @@ -93,6 +93,7 @@ const uploadFileToBatch = ( secrets: Secrets, localeIds: string[], accessToken: string, + customParams?: CustomParams, //eslint-disable-next-line max-params ) => { const {project, proxy} = secrets @@ -109,6 +110,10 @@ const uploadFileToBatch = ( formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`) localeIds.forEach((localeId) => formData.append('localeIdsToAuthorize[]', localeId)) + if (customParams?.callbackUrl && typeof customParams?.callbackUrl === 'function') { + formData.append('callbackUrl', customParams?.callbackUrl(document)) + } + return fetch(proxy, { method: 'POST', headers: getHeaders(url, accessToken), @@ -122,6 +127,8 @@ export const createTask: Adapter['createTask'] = async ( localeIds: string[], secrets: Secrets | null, workflowUid?: string, + customParams?: CustomParams, + // eslint-disable-next-line max-params ) => { if (!secrets?.project || !secrets?.secret || !secrets?.proxy) { throw new Error( @@ -151,6 +158,7 @@ export const createTask: Adapter['createTask'] = async ( secrets, localeIds, accessToken, + customParams, ) //eslint-disable-next-line no-console -- for developer debugging console.info('Upload status from Smartling: ', uploadFileRes) diff --git a/src/adapter/helpers.ts b/src/adapter/helpers.ts index 24467e8..31b6a29 100644 --- a/src/adapter/helpers.ts +++ b/src/adapter/helpers.ts @@ -41,7 +41,7 @@ export const findExistingJob = async ( 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.', ) } - const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs?jobName=${documentId}` + const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs` //first, try fetching from name resolution let items = await fetch(proxy, { headers: getHeaders(url, accessToken),