sanity-plugin-studio-smartling 4.3.3 → 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/package.json CHANGED
@@ -1,88 +1,56 @@
1
1
  {
2
2
  "name": "sanity-plugin-studio-smartling",
3
- "version": "4.3.3",
4
- "description": "!smartling gif",
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/sanity-plugin-studio-smartling/issues"
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:sanity-io/sanity-plugin-studio-smartling.git"
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
- "scripts": {
40
- "build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
41
- "lint": "eslint . --fix",
42
- "clean": "rimraf dist",
43
- "format": "prettier --write --cache --ignore-unknown .",
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
- "@sanity/incompatible-plugin": "^1.0.5",
51
- "sanity-translations-tab": "^5.0.0"
30
+ "sanity-translations-tab": "6.1.4"
52
31
  },
53
32
  "devDependencies": {
54
- "@commitlint/cli": "^17.7.1",
55
- "@commitlint/config-conventional": "^17.7.0",
56
- "@sanity/pkg-utils": "^2.4.8",
57
- "@sanity/plugin-kit": "^3.1.10",
58
- "@sanity/semantic-release-preset": "^4.1.4",
59
- "@types/react": "^18.2.21",
60
- "@typescript-eslint/eslint-plugin": "^6.6.0",
61
- "@typescript-eslint/parser": "^6.6.0",
62
- "eslint": "^8.48.0",
63
- "eslint-config-prettier": "^9.0.0",
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": "^18.3 || ^19",
83
- "sanity": "^3 || ^4.0.0-0 || ^5.0.0"
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": ">=14"
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
@@ -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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AwBM,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,uBAAA;EACHC,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMI,yBAA0D,GAAA;EAC9D,GAAGC,2BAAA;EACHF,OAAS,EAAAH;AACX,CAAA;AAEA,MAAMM,uBAAwD,GAAA;EAC5D,GAAGC,oBAAA;EACHJ,OAAS,EAAAH;AACX,CAAA;"}
package/sanity.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "parts": [
3
- {
4
- "implements": "part:@sanity/base/sanity-root",
5
- "path": "./v2-incompatible.js"
6
- }
7
- ]
8
- }
@@ -1,166 +0,0 @@
1
- import {authenticate, getHeaders, findExistingJob} from './helpers'
2
- import {Adapter, Secrets, SerializedDocument} from 'sanity-translations-tab'
3
- import {getTranslationTask} from './getTranslationTask'
4
- import {Buffer} from 'buffer'
5
-
6
- const createJob = (
7
- jobName: string,
8
- secrets: Secrets,
9
- localeIds: string[],
10
- accessToken: string,
11
- documentId: string,
12
- ) => {
13
- const {project, proxy} = secrets
14
- if (!project || !proxy) {
15
- throw new Error(
16
- 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',
17
- )
18
- }
19
-
20
- const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs`
21
- return fetch(proxy, {
22
- method: 'POST',
23
- headers: {
24
- ...getHeaders(url, accessToken),
25
- 'content-type': 'application/json',
26
- },
27
- body: JSON.stringify({
28
- jobName,
29
- targetLocaleIds: localeIds,
30
- referenceNumber: documentId,
31
- }),
32
- })
33
- .then((res) => res.json())
34
- .then((res) => res.response.data.translationJobUid)
35
- }
36
-
37
- /* we're using batches here because it eliminates some
38
- * new string authorization issues for updating existing jobs,
39
- * and is able to be used for new bulk
40
- * job functionality.
41
- */
42
-
43
- const createJobBatch = (
44
- jobId: string,
45
- secrets: Secrets,
46
- documentId: string,
47
- accessToken: string,
48
- localeIds: string[],
49
- workflowUid?: string,
50
- //eslint-disable-next-line max-params
51
- ) => {
52
- const {project, proxy} = secrets
53
- if (!project || !proxy) {
54
- throw new Error(
55
- 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',
56
- )
57
- }
58
- const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches`
59
- const reqBody: {
60
- authorize: boolean
61
- translationJobUid: string
62
- fileUris: string[]
63
- localeWorkflows?: {targetLocaleId: string; workflowUid: string}[]
64
- } = {
65
- authorize: true,
66
- translationJobUid: jobId,
67
- fileUris: [documentId],
68
- }
69
-
70
- if (workflowUid) {
71
- reqBody.localeWorkflows = localeIds.map((l) => ({
72
- targetLocaleId: l,
73
- workflowUid,
74
- }))
75
- }
76
-
77
- return fetch(proxy, {
78
- method: 'POST',
79
- headers: {
80
- ...getHeaders(url, accessToken),
81
- 'content-type': 'application/json',
82
- },
83
- body: JSON.stringify(reqBody),
84
- })
85
- .then((res) => res.json())
86
- .then((res) => res.response.data.batchUid)
87
- }
88
-
89
- const uploadFileToBatch = (
90
- batchUid: string,
91
- documentId: string,
92
- document: SerializedDocument,
93
- secrets: Secrets,
94
- localeIds: string[],
95
- accessToken: string,
96
- callbackUrl?: string,
97
- //eslint-disable-next-line max-params
98
- ) => {
99
- const {project, proxy} = secrets
100
- if (!project || !proxy) {
101
- throw new Error(
102
- 'The Smartling adapter requires a Smartling project identifier and a proxy URL. Please check your secrets document in this dataset, per the plugin documentation.',
103
- )
104
- }
105
- const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches/${batchUid}/file`
106
- const formData = new FormData()
107
- formData.append('fileUri', documentId)
108
- formData.append('fileType', 'html')
109
- const htmlBuffer = Buffer.from(document.content, 'utf-8')
110
- formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`)
111
- localeIds.forEach((localeId) => formData.append('localeIdsToAuthorize[]', localeId))
112
- if (callbackUrl) {
113
- formData.append('callbackUrl', callbackUrl)
114
- }
115
-
116
- return fetch(proxy, {
117
- method: 'POST',
118
- headers: getHeaders(url, accessToken),
119
- body: formData,
120
- }).then((res) => res.json())
121
- }
122
-
123
- export const createTask: Adapter['createTask'] = async (
124
- documentId: string,
125
- document: SerializedDocument,
126
- localeIds: string[],
127
- secrets: Secrets | null,
128
- workflowUid?: string,
129
- callbackUrl?: string,
130
- // eslint-disable-next-line max-params
131
- ) => {
132
- if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {
133
- throw new Error(
134
- '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.',
135
- )
136
- }
137
-
138
- const accessToken = await authenticate(secrets)
139
-
140
- let taskId = await findExistingJob(document.name, secrets, accessToken)
141
- if (!taskId) {
142
- taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId)
143
- }
144
-
145
- const batchUid = await createJobBatch(
146
- taskId,
147
- secrets,
148
- documentId,
149
- accessToken,
150
- localeIds,
151
- workflowUid,
152
- )
153
- const uploadFileRes = await uploadFileToBatch(
154
- batchUid,
155
- documentId,
156
- document,
157
- secrets,
158
- localeIds,
159
- accessToken,
160
- callbackUrl,
161
- )
162
- //eslint-disable-next-line no-console -- for developer debugging
163
- console.info('Upload status from Smartling: ', uploadFileRes)
164
-
165
- return getTranslationTask(documentId, secrets)
166
- }
@@ -1,18 +0,0 @@
1
- import {authenticate, getHeaders} from './helpers'
2
- import {Secrets} from 'sanity-translations-tab'
3
- import {Adapter} from 'sanity-translations-tab'
4
-
5
- export const getLocales: Adapter['getLocales'] = async (secrets: Secrets | null) => {
6
- if (!secrets?.project || !secrets?.secret || !secrets?.proxy) {
7
- return []
8
- }
9
- const {project, proxy} = secrets
10
- const url = `https://api.smartling.com/projects-api/v2/projects/${project}`
11
- const accessToken = await authenticate(secrets)
12
- return fetch(proxy, {
13
- method: 'GET',
14
- headers: getHeaders(url, accessToken),
15
- })
16
- .then((res) => res.json())
17
- .then((res) => res.response.data.targetLocales)
18
- }