sanity-plugin-studio-smartling 3.0.6-beta-private → 4.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/README.md CHANGED
@@ -16,6 +16,8 @@ We're proud to be partnered with Smartling and their [official connector](https:
16
16
 
17
17
  This is a separate plugin, and differs in that it provides editors a visual progress bar for ongoing translations and a way to import translations back into your content at either the document or field level. Feel free to try it out and see which solution works for you!
18
18
 
19
+ _Recent updates for v4:_ We've added support for the new document internationalization plugin pattern. Please read the [Document level translations](#document-level-translations) section for more information.
20
+
19
21
  # Table of Contents
20
22
 
21
23
  - [Quickstart](#quickstart)
@@ -35,7 +37,7 @@ npm install sanity-plugin-studio-smartling
35
37
 
36
38
  2. Because of Smartling CORS restrictions, you will need to set up a proxy endpoint to funnel requests to Smartling. We've provided a tiny Next.js app you can set up [here](https://github.com/sanity-io/example-sanity-smartling-proxy). If that's not useful, the important thing to pay attention to is that this endpoint handles requests with an `X-URL` header that contains the Smartling URL configured by the plugin, and can parse a data file to an HTML string and send it back to the adapter.
37
39
 
38
- 3. Ensure the plugin has access to your Smartling project token. You'll want to create a document that includes your project name, organization name, and a token with appropriate access.
40
+ 3. Create or use a Smartling project token.
39
41
 
40
42
  [Please refer to the Smartling documentation on creating a token if you don't have one already.](https://help.smartling.com/hc/en-us/articles/115004187694-API-Tokens)
41
43
 
@@ -80,13 +82,18 @@ If you have concerns about this being exposed to authenticated users of your stu
80
82
  import {DefaultDocumentNodeResolver} from 'sanity/desk'
81
83
  //...your other desk structure imports...
82
84
  import {TranslationsTab, defaultDocumentLevelConfig} from 'sanity-plugin-studio-smartling'
85
+ //if you are using field-level translations, you can import the field-level config instead:
86
+ //import {TranslationsTab, defaultFieldLevelConfig} from 'sanity-plugin-studio-smartling'
87
+ //if you're not sure which, please look at the document-level and field-level sections below
83
88
 
84
- export const getDefaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
89
+ export const defaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
85
90
  if (schemaType === 'myTranslatableDocumentType') {
86
91
  return S.document().views([
87
92
  S.view.form(),
88
93
  //...my other views -- for example, live preview, document pane, etc.,
89
94
  S.view.component(TranslationsTab).title('Smartling').options(defaultDocumentLevelConfig)
95
+ //again, if you're using field-level translations, you can use the field-level config instead:
96
+ //S.view.component(TranslationsTab).title('Smartling').options(defaultFieldLevelConfig)
90
97
  ])
91
98
  }
92
99
  return S.document()
@@ -101,13 +108,13 @@ To use the default config mentioned above, we assume that you are following the
101
108
 
102
109
  ### Field-level translations
103
110
 
104
- If you are using field-level translation, we assume any fields you want translated exist in the multi-locale object form we recommend.
105
- For example, on a document you don't want to be translated, you may have a "title" field that's a flat string: `title: 'My title is here.'` For a field you want to include many languages for, your title may look like
111
+ If you are using field-level translation and the `defaultFieldLevelConfig` configuration, we assume any fields you want translated exist in the multi-locale object form we recommend.
112
+ For example, a non-localizable "title" field will be a flat string: `title: 'My title is here.'` For a field you want to include many languages for, your title may look like
106
113
  `
107
114
  {
108
115
  title: {
109
116
  en: 'My title is here.',
110
- es: 'Mi título está aquí.',
117
+ es_ES: 'Mi título está aquí.',
111
118
  etc...
112
119
  }
113
120
  }
@@ -116,84 +123,10 @@ _Important_: Smartling's locale representation includes hyphens, like `fr-FR`. T
116
123
 
117
124
  ### Document level translations
118
125
 
119
- Since we often find users want to use the [Document internationalization plugin](https://www.sanity.io/plugins/document-internationalization) if they're using document-level translations, we assume that any documents you want in different languages will follow the pattern `{id-of-base-language-document}__i18n_{locale}`
120
-
121
- ### Final note
122
-
123
- It's okay if your data doesn't follow these patterns and you don't want to change them! You will simply have to override how the plugin gets and patches back information from your documents. Please see [Overriding defaults](#overriding-defaults).
124
-
125
- ## Quickstart
126
-
127
- 1. Install this plugin with `npm install sanity-plugin-studio-smartling`
128
-
129
- 2. Ensure the plugin has access to your Smartling token secret. You'll want to create a document that includes your project name and a token secret with appropriate access. [Please refer to the Smartling documentation on creating a token if you don't have one already.](https://help.smartling.com/hc/en-us/articles/115004187694-API-Tokens-)
130
- - In your studio, create a file called `populateSmartlingSecrets.js`.
131
- - Place the following in the file and fill out the correct values.
132
-
133
- ```javascript
134
- import sanityClient from 'part:@sanity/base/client'
135
-
136
- const client = sanityClient.withConfig({apiVersion: '2021-03-25'})
137
-
138
- client.createOrReplace({
139
- _id: 'translationService.secrets',
140
- _type: 'smartlingSettings',
141
- organization: 'YOUR_ORG_HERE',
142
- project: 'YOUR_PROJECT_HERE',
143
- secret: '{"userIdentifier":"xxxxxx","userSecret":"xxxx"}' //in this format from Smartling
144
- })
145
- ```
146
-
147
- - On the command line, run the file with `sanity exec populateSmartlingSecrets.js --with-user-token`.
148
- Verify that everything went well by using Vision in the studio to query `*[_id == 'translationService.secrets']`. (NOTE: If you have multiple datasets, you'll have to do this across all of them, since it's a document!)
149
- - If everything looks good, go ahead and delete `populateSmartlingSecrets.js` so you don't commit it.
150
- Because the document's `_id` is on a path (`translationService`), it won't be exposed to the outside world, even in a public dataset. If you have concerns about this being exposed to authenticated users of your studio, you can control access to this path with [role-based access control](https://www.sanity.io/docs/access-control).
126
+ Since we often find users want to use the [Document internationalization plugin](https://www.sanity.io/plugins/document-internationalization) if they're using document-level translations, we assume that any documents you want in different languages will be present in a `translation.metadata` document.
151
127
 
152
- 5. Now it's time to get the Smartling tab on your desired document type, using whatever pattern you like. You'll use the [desk structure](https://www.sanity.io/docs/structure-builder-introduction) for this. The options for translation will be nested under this desired document type's views. Here's an example:
128
+ _Important_: The above is true if you are using the Document Internationalization Plugin at version 2 or above. If you are using version 1 please use the `legacyDocumentLevelConfig` configuration exported from this plugin. This configuration assumes your translations follow the pattern `{id-of-base-language-document}__i18n_{locale}`
153
129
 
154
- ```javascript
155
- import {DefaultDocumentNodeResolver} from 'sanity/desk'
156
- //...your other desk structure imports...
157
- import {TranslationsTab, defaultDocumentLevelConfig} from 'sanity-plugin-studio-smartling'
158
-
159
- export const getDefaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
160
- if (schemaType === 'myTranslatableDocumentType') {
161
- return S.document().views([
162
- S.view.form(),
163
- //...my other views -- for example, live preview, the i18n plugin, etc.,
164
- S.view.component(TranslationsTab).title('Smartling').options(defaultDocumentLevelConfig)
165
- ])
166
- }
167
- return S.document()
168
- }
169
- ```
170
-
171
- And that should do it! Go into your studio, click around, and check the document in Smartling (it should be a job under its Sanity `_id`). Once it's translated, check the import by clicking the `Import` button on your Smartling tab!
172
-
173
- ## Assumptions
174
-
175
- To use the default config mentioned above, we assume that you are following the conventions we outline in [our documentation on localization](https://www.sanity.io/docs/localization).
176
-
177
- ### Field-level translations
178
-
179
- If you are using field-level translation, we assume any fields you want to be translated exist in the multi-locale object form we recommend.
180
-
181
- For example, on a document you don't want to be translated, you may have a "title" field that's a flat string: `title: 'My title is here.'` For a field you want to include many languages for your title may look like:
182
-
183
- ```javascript
184
- {
185
- //...other document fields,
186
- title: {
187
- en: 'My title is here.',
188
- es: 'Mi título está aquí.',
189
- etc...
190
- }
191
- }
192
- ```
193
-
194
- ### Document level translations
195
-
196
- Since we often find users want to use the [Document internationalization plugin](https://www.sanity.io/plugins/document-internationalization) if they're using document-level translations, we assume that any documents you want in different languages will follow the pattern `{id-of-base-language-document}__i18n_{locale}`
197
130
 
198
131
  ### Final note
199
132
 
@@ -248,12 +181,14 @@ and run the script with `sanity exec patchSmartlingSecrets.js --with-user-token`
248
181
 
249
182
  Alternatively, you can re-run the `populateSmartlingSecrets` script in [Quickstart](#quickstart) to create a new secrets document with the proxy set.
250
183
 
251
- We apologize for the inconvenience. Because of the new embeddability of the studio, developers may find that their v3 Studio is built and deployed in different ways, with access to different environments. Keeping this setting in `secrets` allows developers to set it in a way that works for their deployment and reduce complexity.
184
+ We apologize for the inconvenience. Because of the new embeddability of the studio, developers may find that their v3 Studio is built and deployed in different ways, with access to different environments. Keeping this setting in `secrets` allows developers to set it in a way that works for their deployment and reduce complexity. You can find more information on our guidance around environment variables [here](https://github.com/sanity-io/sanity/releases/tag/v3.5.0).
252
185
 
253
186
  Otherwise, you should not have to do anything to migrate to Sanity Studio v3. If you are using the default configs, you should be able to upgrade without any changes. If you are using custom serialization, you may need to update how `BaseDocumentSerializer` receives your schema.
254
187
 
255
188
  These are outlined in the serializer README [here](https://github.com/sanity-io/sanity-naive-html-serializer#v2-to-v3-changes).
256
189
 
190
+ The final change from the v2 to v3 version of the plugin is in how progress in a translation job is calculated. The plugin will now count progress as the percentage of all strings that have reached the final stage of a Smartling workflow.
191
+
257
192
  ## License
258
193
 
259
194
  [MIT](LICENSE) © Sanity.io
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import {defaultStopTypes} from 'sanity-translations-tab'
7
7
  import {documentLevelPatch} from 'sanity-translations-tab'
8
8
  import {fieldLevelPatch} from 'sanity-translations-tab'
9
9
  import {findLatestDraft} from 'sanity-translations-tab'
10
+ import {legacyDocumentLevelPatch} from 'sanity-translations-tab'
10
11
  import {SerializedDocument} from 'sanity-naive-html-serializer'
11
12
  import {TranslationFunctionContext} from 'sanity-translations-tab'
12
13
  import {TranslationsTab} from 'sanity-translations-tab'
@@ -46,6 +47,10 @@ export {fieldLevelPatch}
46
47
 
47
48
  export {findLatestDraft}
48
49
 
50
+ export declare const legacyDocumentLevelConfig: ConfigOptions
51
+
52
+ export {legacyDocumentLevelPatch}
53
+
49
54
  export declare const SmartlingAdapter: Adapter
50
55
 
51
56
  export {TranslationsTab}
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { baseDocumentLevelConfig, baseFieldLevelConfig } from 'sanity-translations-tab';
2
- export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft } from 'sanity-translations-tab';
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
3
  import { Buffer } from 'buffer';
4
4
  const authenticate = secrets => {
5
5
  const url = "https://api.smartling.com/auth-api/v2/authenticate";
@@ -49,7 +49,7 @@ const findExistingJob = (documentId, secrets, accessToken) => {
49
49
  };
50
50
  const getLocales = async secrets => {
51
51
  if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
52
- 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.");
52
+ return [];
53
53
  }
54
54
  const {
55
55
  project,
@@ -64,7 +64,11 @@ const getLocales = async secrets => {
64
64
  };
65
65
  const getTranslationTask = async (documentId, secrets) => {
66
66
  if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
67
- 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.");
67
+ return {
68
+ documentId,
69
+ taskId: documentId,
70
+ locales: []
71
+ };
68
72
  }
69
73
  const {
70
74
  project,
@@ -232,9 +236,13 @@ const defaultDocumentLevelConfig = {
232
236
  ...baseDocumentLevelConfig,
233
237
  adapter: SmartlingAdapter
234
238
  };
239
+ const legacyDocumentLevelConfig = {
240
+ ...legacyDocumentLevelConfig$1,
241
+ adapter: SmartlingAdapter
242
+ };
235
243
  const defaultFieldLevelConfig = {
236
244
  ...baseFieldLevelConfig,
237
245
  adapter: SmartlingAdapter
238
246
  };
239
- export { SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig };
247
+ export { SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, legacyDocumentLevelConfig };
240
248
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
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 = (\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 return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.response.data.items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = res.response.data.items.find(\n (item: {jobName: string}) => item.jobName && item.jobName === documentId\n )\n if (correctJob) {\n return correctJob.translationJobUid\n }\n return ''\n }\n return ''\n })\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 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 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 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 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} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (jobName: string, secrets: Secrets, localeIds: string[], accessToken: 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\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 }),\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 documentName: 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: [documentName],\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 document: Record<string, any>,\n secrets: Secrets,\n localeIds: string[],\n accessToken: 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', document.name)\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\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: Record<string, any>,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: 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)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(batchUid, document, secrets, localeIds, accessToken)\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 {SerializedDocument} from 'sanity-naive-html-serializer'\nimport {\n TranslationsTab,\n baseDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (\n id: string,\n context: TranslationFunctionContext\n ) => Promise<SerializedDocument>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string,\n context: TranslationFunctionContext\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n documentLevelPatch,\n fieldLevelPatch,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","findExistingJob","documentId","project","concat","items","length","correctJob","find","item","jobName","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","_a","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","name","htmlBuffer","Buffer","from","content","Blob","forEach","createTask","uploadFileRes","console","info","getTranslation","translatedHTML","errors","errMsg","message","SmartlingAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","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;E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AA;MAC9B,MAAMC,WACJ/C,EAAI,GAAA3B,GAAA,CAAAE,QAAA,CAASuE,OAAO,CAAC,CAAA,KAArB,mBAAwBE,OAAW,KAAA,6CAAA;MAC/B,MAAA,IAAIlF,MAAMiF,MAAM,CAAA;IACxB;IACO,OAAA,EAAA;EAAA,CACR,CAAA;EAEI,OAAAF,cAAA;AACT,CAAA;AC7BO,MAAMI,gBAA4B,GAAA;EACvC1D,UAAA;EACAE,kBAAA;EACA+C,UAAA;EACAI;AACF,CAAA;ACqBA,MAAMM,0BAA4C,GAAA;EAChD,GAAGC,uBAAA;EACHC,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMI,uBAAyC,GAAA;EAC7C,GAAGC,oBAAA;EACHF,OAAS,EAAAH;AACX,CAAA;"}
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 = (\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 return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.response.data.items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = res.response.data.items.find(\n (item: {jobName: string}) => item.jobName && item.jobName === documentId\n )\n if (correctJob) {\n return correctJob.translationJobUid\n }\n return ''\n }\n return ''\n })\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} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (jobName: string, secrets: Secrets, localeIds: string[], accessToken: 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\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 }),\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 documentName: 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: [documentName],\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 document: Record<string, any>,\n secrets: Secrets,\n localeIds: string[],\n accessToken: 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', document.name)\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\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: Record<string, any>,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: 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)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(batchUid, document, secrets, localeIds, accessToken)\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 {SerializedDocument} from 'sanity-naive-html-serializer'\nimport {\n TranslationsTab,\n baseDocumentLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (\n id: string,\n context: TranslationFunctionContext\n ) => Promise<SerializedDocument>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string,\n context: TranslationFunctionContext\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst legacyDocumentLevelConfig: ConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\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"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","findExistingJob","documentId","project","concat","items","length","correctJob","find","item","jobName","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","_a","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","name","htmlBuffer","Buffer","from","content","Blob","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,EAAM,CAAA,CACxBF,KAAMC,GAAA,IAAQA,GAAI,CAAAE,QAAA,CAASC,KAAKC,WAAW,CAAA;AAChD,CAAA;AAEa,MAAAC,UAAA,GAAaA,CAAChB,GAAA,EAAae,WAAkC,MAAA;EACxEE,gCAAyBF,WAAA,CAAA;EACzB,OAAS,EAAAf;AACX,CAAA,CAAA;AAEO,MAAMkB,eAAkB,GAAAA,CAC7BC,UACA,EAAApB,OAAA,EACAgB,WACoB,KAAA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54
54
  const getLocales = async secrets => {
55
55
  if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
56
- 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.");
56
+ return [];
57
57
  }
58
58
  const {
59
59
  project,
@@ -68,7 +68,11 @@ const getLocales = async secrets => {
68
68
  };
69
69
  const getTranslationTask = async (documentId, secrets) => {
70
70
  if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
71
- 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.");
71
+ return {
72
+ documentId,
73
+ taskId: documentId,
74
+ locales: []
75
+ };
72
76
  }
73
77
  const {
74
78
  project,
@@ -236,6 +240,10 @@ const defaultDocumentLevelConfig = {
236
240
  ...sanityTranslationsTab.baseDocumentLevelConfig,
237
241
  adapter: SmartlingAdapter
238
242
  };
243
+ const legacyDocumentLevelConfig = {
244
+ ...sanityTranslationsTab.legacyDocumentLevelConfig,
245
+ adapter: SmartlingAdapter
246
+ };
239
247
  const defaultFieldLevelConfig = {
240
248
  ...sanityTranslationsTab.baseFieldLevelConfig,
241
249
  adapter: SmartlingAdapter
@@ -294,7 +302,14 @@ Object.defineProperty(exports, 'findLatestDraft', {
294
302
  return sanityTranslationsTab.findLatestDraft;
295
303
  }
296
304
  });
305
+ Object.defineProperty(exports, 'legacyDocumentLevelPatch', {
306
+ enumerable: true,
307
+ get: function () {
308
+ return sanityTranslationsTab.legacyDocumentLevelPatch;
309
+ }
310
+ });
297
311
  exports.SmartlingAdapter = SmartlingAdapter;
298
312
  exports.defaultDocumentLevelConfig = defaultDocumentLevelConfig;
299
313
  exports.defaultFieldLevelConfig = defaultFieldLevelConfig;
314
+ exports.legacyDocumentLevelConfig = legacyDocumentLevelConfig;
300
315
  //# sourceMappingURL=index.js.map
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 = (\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 return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.response.data.items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = res.response.data.items.find(\n (item: {jobName: string}) => item.jobName && item.jobName === documentId\n )\n if (correctJob) {\n return correctJob.translationJobUid\n }\n return ''\n }\n return ''\n })\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 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 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 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 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} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (jobName: string, secrets: Secrets, localeIds: string[], accessToken: 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\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 }),\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 documentName: 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: [documentName],\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 document: Record<string, any>,\n secrets: Secrets,\n localeIds: string[],\n accessToken: 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', document.name)\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\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: Record<string, any>,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: 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)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(batchUid, document, secrets, localeIds, accessToken)\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 {SerializedDocument} from 'sanity-naive-html-serializer'\nimport {\n TranslationsTab,\n baseDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (\n id: string,\n context: TranslationFunctionContext\n ) => Promise<SerializedDocument>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string,\n context: TranslationFunctionContext\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n documentLevelPatch,\n fieldLevelPatch,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","findExistingJob","documentId","project","concat","items","length","correctJob","find","item","jobName","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","_a","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","name","htmlBuffer","Buffer","from","content","Blob","forEach","createTask","uploadFileRes","console","info","getTranslation","translatedHTML","errors","errMsg","message","SmartlingAdapter","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":";;;;;;;AAMa,MAAAA,YAAA,GAAgBC,OAAsC,IAAA;EACjE,MAAMC,GAAM,GAAA,oDAAA;EACZ,MAAMC,OAAU,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IAAA;IAAA,CACb,MAAA,IAAWI,GAAI,CAAAE,QAAA,CAASuE,MAAQ,EAAA;MAC9B,MAAMC,WACJ/C,EAAI,GAAA3B,GAAA,CAAAE,QAAA,CAASuE,OAAO,CAAC,CAAA,KAArB,mBAAwBE,OAAW,KAAA,6CAAA;MAC/B,MAAA,IAAIlF,MAAMiF,MAAM,CAAA;IACxB;IACO,OAAA,EAAA;EAAA,CACR,CAAA;EAEI,OAAAF,cAAA;AACT,CAAA;AC7BO,MAAMI,gBAA4B,GAAA;EACvC1D,UAAA;EACAE,kBAAA;EACA+C,UAAA;EACAI;AACF,CAAA;ACqBA,MAAMM,0BAA4C,GAAA;EAChD,GAAGC,qBAAA,CAAAA,uBAAA;EACHC,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMI,uBAAyC,GAAA;EAC7C,GAAGC,qBAAA,CAAAA,oBAAA;EACHF,OAAS,EAAAH;AACX,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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 = (\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 return fetch(proxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then((res) => res.json())\n .then((res) => {\n if (res.response.data.items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = res.response.data.items.find(\n (item: {jobName: string}) => item.jobName && item.jobName === documentId\n )\n if (correctJob) {\n return correctJob.translationJobUid\n }\n return ''\n }\n return ''\n })\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} from 'sanity-translations-tab'\nimport {getTranslationTask} from './getTranslationTask'\nimport {Buffer} from 'buffer'\n\nconst createJob = (jobName: string, secrets: Secrets, localeIds: string[], accessToken: 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\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 }),\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 documentName: 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: [documentName],\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 document: Record<string, any>,\n secrets: Secrets,\n localeIds: string[],\n accessToken: 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', document.name)\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\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: Record<string, any>,\n localeIds: string[],\n secrets: Secrets | null,\n workflowUid?: 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)\n }\n\n const batchUid = await createJobBatch(\n taskId,\n secrets,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(batchUid, document, secrets, localeIds, accessToken)\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 {SerializedDocument} from 'sanity-naive-html-serializer'\nimport {\n TranslationsTab,\n baseDocumentLevelConfig,\n legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n legacyDocumentLevelPatch,\n documentLevelPatch,\n fieldLevelPatch,\n TranslationFunctionContext,\n} from 'sanity-translations-tab'\nimport {SmartlingAdapter} from './adapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (\n id: string,\n context: TranslationFunctionContext\n ) => Promise<SerializedDocument>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string,\n context: TranslationFunctionContext\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst legacyDocumentLevelConfig: ConfigOptions = {\n ...baseLegacyDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\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"],"names":["authenticate","secrets","url","headers","secret","proxy","Error","fetch","method","body","JSON","stringify","then","res","json","response","data","accessToken","getHeaders","Authorization","findExistingJob","documentId","project","concat","items","length","correctJob","find","item","jobName","translationJobUid","getLocales","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","_a","progress","percentComplete","workflowProgressReportList","progressItem","workflowStepSummaryReportItemList","lastStep","at","wordCount","Math","floor","totalWordCount","localeId","targetLocaleId","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","name","htmlBuffer","Buffer","from","content","Blob","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,EAAM,CAAA,CACxBF,KAAMC,GAAA,IAAQA,GAAI,CAAAE,QAAA,CAASC,KAAKC,WAAW,CAAA;AAChD,CAAA;AAEa,MAAAC,UAAA,GAAaA,CAAChB,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AA,CAAAD,yBAAA;EACHD,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMM,uBAAyC,GAAA;EAC7C,GAAGC,qBAAA,CAAAA,oBAAA;EACHJ,OAAS,EAAAH;AACX,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-studio-smartling",
3
- "version": "3.0.6-beta-private",
3
+ "version": "4.0.0",
4
4
  "description": "!smartling gif",
5
5
  "keywords": [
6
6
  "sanity",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@sanity/incompatible-plugin": "^1.0.4",
51
- "sanity-translations-tab": "^3.0.4-beta"
51
+ "sanity-translations-tab": "^4.0.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@commitlint/cli": "^17.4.4",
@@ -4,9 +4,7 @@ import {Adapter} from 'sanity-translations-tab'
4
4
 
5
5
  export const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {
6
6
  if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {
7
- throw new Error(
8
- '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.'
9
- )
7
+ return []
10
8
  }
11
9
  const {project, proxy} = secrets
12
10
  const url = `https://api.smartling.com/projects-api/v2/projects/${project}`
@@ -21,9 +21,11 @@ export const getTranslationTask: Adapter['getTranslationTask'] = async (
21
21
  secrets: Secrets | null
22
22
  ) => {
23
23
  if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {
24
- throw new Error(
25
- '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.'
26
- )
24
+ return {
25
+ documentId,
26
+ taskId: documentId,
27
+ locales: [],
28
+ }
27
29
  }
28
30
 
29
31
  const {project, proxy} = secrets
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import {SerializedDocument} from 'sanity-naive-html-serializer'
2
2
  import {
3
3
  TranslationsTab,
4
4
  baseDocumentLevelConfig,
5
+ legacyDocumentLevelConfig as baseLegacyDocumentLevelConfig,
5
6
  baseFieldLevelConfig,
6
7
  findLatestDraft,
7
8
  BaseDocumentDeserializer,
@@ -10,6 +11,7 @@ import {
10
11
  defaultStopTypes,
11
12
  customSerializers,
12
13
  Adapter,
14
+ legacyDocumentLevelPatch,
13
15
  documentLevelPatch,
14
16
  fieldLevelPatch,
15
17
  TranslationFunctionContext,
@@ -35,6 +37,11 @@ const defaultDocumentLevelConfig: ConfigOptions = {
35
37
  adapter: SmartlingAdapter,
36
38
  }
37
39
 
40
+ const legacyDocumentLevelConfig: ConfigOptions = {
41
+ ...baseLegacyDocumentLevelConfig,
42
+ adapter: SmartlingAdapter,
43
+ }
44
+
38
45
  const defaultFieldLevelConfig: ConfigOptions = {
39
46
  ...baseFieldLevelConfig,
40
47
  adapter: SmartlingAdapter,
@@ -43,6 +50,7 @@ const defaultFieldLevelConfig: ConfigOptions = {
43
50
  export {
44
51
  TranslationsTab,
45
52
  findLatestDraft,
53
+ legacyDocumentLevelPatch,
46
54
  documentLevelPatch,
47
55
  fieldLevelPatch,
48
56
  BaseDocumentDeserializer,
@@ -51,6 +59,7 @@ export {
51
59
  defaultStopTypes,
52
60
  customSerializers,
53
61
  SmartlingAdapter,
62
+ legacyDocumentLevelConfig,
54
63
  defaultDocumentLevelConfig,
55
64
  defaultFieldLevelConfig,
56
65
  }