sanity-plugin-studio-smartling 4.3.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -5
- package/dist/index.d.ts +7 -47
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -219
- package/dist/index.js.map +1 -1
- package/package.json +34 -66
- package/dist/index.esm.js +0 -268
- package/dist/index.esm.js.map +0 -1
- package/sanity.json +0 -8
- package/src/adapter/createTask.ts +0 -166
- package/src/adapter/getLocales.ts +0 -18
- package/src/adapter/getTranslation.ts +0 -36
- package/src/adapter/getTranslationTask.ts +0 -89
- package/src/adapter/helpers.ts +0 -84
- package/src/adapter/index.ts +0 -12
- package/src/index.ts +0 -52
- package/src/types.d.ts +0 -0
- package/v2-incompatible.js +0 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
## Installation
|
|
3
2
|
|
|
4
3
|
```sh
|
|
5
4
|
npm install sanity-plugin-studio-smartling
|
|
6
5
|
```
|
|
7
6
|
|
|
8
|
-
## Usage
|
|
9
|
-
|
|
10
7
|
# Studio Plugin for Sanity & Smartling
|
|
11
8
|
|
|
12
9
|

|
|
@@ -59,7 +56,7 @@ client.createOrReplace({
|
|
|
59
56
|
organization: 'YOUR_SMARTLING_ORGANIZATION_HERE',
|
|
60
57
|
project: 'YOUR_SMARTLING_PROJECT_HERE',
|
|
61
58
|
secret: '{"userIdentifier":"xxxxxx","userSecret":"xxxx"}', //in this format from Smartling when you press the button "copy token" on creation
|
|
62
|
-
proxy: 'my-proxy-endpoint.com/api/proxy' //the endpoint you set up in step 2
|
|
59
|
+
proxy: 'my-proxy-endpoint.com/api/proxy', //the endpoint you set up in step 2
|
|
63
60
|
})
|
|
64
61
|
```
|
|
65
62
|
|
|
@@ -126,7 +123,6 @@ Since we often find users want to use the [Document internationalization plugin]
|
|
|
126
123
|
|
|
127
124
|
_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}`
|
|
128
125
|
|
|
129
|
-
|
|
130
126
|
### Final note
|
|
131
127
|
|
|
132
128
|
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).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,7 @@
|
|
|
1
|
-
import {Adapter} from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {fieldLevelPatch} from 'sanity-translations-tab'
|
|
9
|
-
import {findLatestDraft} from 'sanity-translations-tab'
|
|
10
|
-
import {legacyDocumentLevelPatch} from 'sanity-translations-tab'
|
|
11
|
-
import {TranslationFunctionContext} from 'sanity-translations-tab'
|
|
12
|
-
import {TranslationsTab} from 'sanity-translations-tab'
|
|
13
|
-
import {TranslationsTabConfigOptions} from 'sanity-translations-tab'
|
|
14
|
-
|
|
15
|
-
export {BaseDocumentDeserializer}
|
|
16
|
-
|
|
17
|
-
export {BaseDocumentMerger}
|
|
18
|
-
|
|
19
|
-
export {BaseDocumentSerializer}
|
|
20
|
-
|
|
21
|
-
export {customSerializers}
|
|
22
|
-
|
|
23
|
-
export declare const defaultDocumentLevelConfig: TranslationsTabConfigOptions
|
|
24
|
-
|
|
25
|
-
export declare const defaultFieldLevelConfig: TranslationsTabConfigOptions
|
|
26
|
-
|
|
27
|
-
export {defaultStopTypes}
|
|
28
|
-
|
|
29
|
-
export {documentLevelPatch}
|
|
30
|
-
|
|
31
|
-
export {fieldLevelPatch}
|
|
32
|
-
|
|
33
|
-
export {findLatestDraft}
|
|
34
|
-
|
|
35
|
-
export declare const legacyDocumentLevelConfig: TranslationsTabConfigOptions
|
|
36
|
-
|
|
37
|
-
export {legacyDocumentLevelPatch}
|
|
38
|
-
|
|
39
|
-
export declare const SmartlingAdapter: Adapter
|
|
40
|
-
|
|
41
|
-
export {TranslationFunctionContext}
|
|
42
|
-
|
|
43
|
-
export {TranslationsTab}
|
|
44
|
-
|
|
45
|
-
export {TranslationsTabConfigOptions}
|
|
46
|
-
|
|
47
|
-
export {}
|
|
1
|
+
import { Adapter, BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationFunctionContext, TranslationsTab, TranslationsTabConfigOptions, TranslationsTabConfigOptions as TranslationsTabConfigOptions$1, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelPatch } from "sanity-translations-tab";
|
|
2
|
+
declare const SmartlingAdapter: Adapter;
|
|
3
|
+
declare const defaultDocumentLevelConfig: TranslationsTabConfigOptions$1;
|
|
4
|
+
declare const legacyDocumentLevelConfig: TranslationsTabConfigOptions$1;
|
|
5
|
+
declare const defaultFieldLevelConfig: TranslationsTabConfigOptions$1;
|
|
6
|
+
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, SmartlingAdapter, type TranslationFunctionContext, TranslationsTab, type TranslationsTabConfigOptions, customSerializers, defaultDocumentLevelConfig, defaultFieldLevelConfig, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelConfig, legacyDocumentLevelPatch };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapter/index.ts","../src/index.ts"],"mappings":";cAOa,gBAAA,EAAkB,OAK9B;AAAA,cCcK,0BAAA,EAA4B,8BAGjC;AAAA,cAEK,yBAAA,EAA2B,8BAGhC;AAAA,cAEK,uBAAA,EAAyB,8BAG9B"}
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var sanityTranslationsTab = require('sanity-translations-tab');
|
|
7
|
-
var buffer = require('buffer');
|
|
8
|
-
const authenticate = secrets => {
|
|
9
|
-
const url = "https://api.smartling.com/auth-api/v2/authenticate";
|
|
1
|
+
import { baseDocumentLevelConfig, baseFieldLevelConfig, legacyDocumentLevelConfig as legacyDocumentLevelConfig$1 } from "sanity-translations-tab";
|
|
2
|
+
import { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft, legacyDocumentLevelPatch } from "sanity-translations-tab";
|
|
3
|
+
const authenticate = (secrets) => {
|
|
10
4
|
const headers = {
|
|
11
5
|
"content-type": "application/json",
|
|
12
|
-
"X-URL":
|
|
13
|
-
}
|
|
14
|
-
const {
|
|
6
|
+
"X-URL": "https://api.smartling.com/auth-api/v2/authenticate"
|
|
7
|
+
}, {
|
|
15
8
|
secret,
|
|
16
9
|
proxy
|
|
17
10
|
} = secrets;
|
|
18
|
-
if (!secret || !proxy)
|
|
11
|
+
if (!secret || !proxy)
|
|
19
12
|
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.");
|
|
20
|
-
}
|
|
21
13
|
return fetch(proxy, {
|
|
22
14
|
headers,
|
|
23
15
|
method: "POST",
|
|
24
16
|
body: JSON.stringify(secret)
|
|
25
|
-
}).then(res => res.json()).then(res => res.response.data.accessToken);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Authorization: "Bearer ".concat(accessToken),
|
|
17
|
+
}).then((res) => res.json()).then((res) => res.response.data.accessToken);
|
|
18
|
+
}, getHeaders = (url, accessToken) => ({
|
|
19
|
+
Authorization: `Bearer ${accessToken}`,
|
|
29
20
|
"X-URL": url
|
|
30
|
-
})
|
|
31
|
-
const findExistingJob = async (documentId, secrets, accessToken) => {
|
|
21
|
+
}), findExistingJob = async (documentId, secrets, accessToken) => {
|
|
32
22
|
const {
|
|
33
23
|
project,
|
|
34
24
|
proxy
|
|
35
25
|
} = secrets;
|
|
36
|
-
if (!project || !proxy)
|
|
26
|
+
if (!project || !proxy)
|
|
37
27
|
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.");
|
|
38
|
-
}
|
|
39
|
-
const url = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs?jobName=").concat(documentId);
|
|
28
|
+
const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs?jobName=${documentId}`;
|
|
40
29
|
let items = await fetch(proxy, {
|
|
41
30
|
headers: getHeaders(url, accessToken)
|
|
42
|
-
}).then(res => res.json()).then(res =>
|
|
43
|
-
var _a, _b;
|
|
44
|
-
return (_b = (_a = res == null ? void 0 : res.response) == null ? void 0 : _a.data) == null ? void 0 : _b.items;
|
|
45
|
-
});
|
|
31
|
+
}).then((res) => res.json()).then((res) => res?.response?.data?.items);
|
|
46
32
|
if (!items || !items.length) {
|
|
47
|
-
const refUrl =
|
|
33
|
+
const refUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/search`;
|
|
48
34
|
items = await fetch(proxy, {
|
|
49
35
|
headers: {
|
|
50
36
|
...getHeaders(refUrl, accessToken),
|
|
@@ -54,97 +40,62 @@ const findExistingJob = async (documentId, secrets, accessToken) => {
|
|
|
54
40
|
body: JSON.stringify({
|
|
55
41
|
fileUris: [documentId]
|
|
56
42
|
})
|
|
57
|
-
}).then(res => res.json()).then(res =>
|
|
58
|
-
var _a, _b;
|
|
59
|
-
return (_b = (_a = res == null ? void 0 : res.response) == null ? void 0 : _a.data) == null ? void 0 : _b.items;
|
|
60
|
-
});
|
|
43
|
+
}).then((res) => res.json()).then((res) => res?.response?.data?.items);
|
|
61
44
|
}
|
|
62
45
|
if (items.length) {
|
|
63
|
-
const correctJob = items.filter(item => item.jobStatus !== "DELETED").find(item => item.jobName && item.jobName === documentId || item.referenceNumber && item.referenceNumber === documentId);
|
|
64
|
-
if (correctJob)
|
|
46
|
+
const correctJob = items.filter((item) => item.jobStatus !== "DELETED").find((item) => item.jobName && item.jobName === documentId || item.referenceNumber && item.referenceNumber === documentId);
|
|
47
|
+
if (correctJob)
|
|
65
48
|
return correctJob.translationJobUid;
|
|
66
|
-
}
|
|
67
49
|
}
|
|
68
50
|
return "";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
const {
|
|
75
|
-
project,
|
|
76
|
-
proxy
|
|
77
|
-
} = secrets;
|
|
78
|
-
const url = "https://api.smartling.com/projects-api/v2/projects/".concat(project);
|
|
79
|
-
const accessToken = await authenticate(secrets);
|
|
80
|
-
return fetch(proxy, {
|
|
81
|
-
method: "GET",
|
|
82
|
-
headers: getHeaders(url, accessToken)
|
|
83
|
-
}).then(res => res.json()).then(res => res.response.data.targetLocales);
|
|
84
|
-
};
|
|
85
|
-
const getTranslationTask = async (documentId, secrets) => {
|
|
86
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
51
|
+
}, getTranslationTask = async (documentId, secrets) => {
|
|
52
|
+
if (!secrets?.project || !secrets?.secret || !secrets?.proxy)
|
|
87
53
|
return {
|
|
88
54
|
documentId,
|
|
89
55
|
taskId: documentId,
|
|
90
56
|
locales: []
|
|
91
57
|
};
|
|
92
|
-
}
|
|
93
58
|
const {
|
|
94
59
|
project,
|
|
95
60
|
proxy
|
|
96
|
-
} = secrets;
|
|
97
|
-
|
|
98
|
-
const taskId = await findExistingJob(documentId, secrets, accessToken);
|
|
99
|
-
if (!taskId) {
|
|
61
|
+
} = secrets, accessToken = await authenticate(secrets), taskId = await findExistingJob(documentId, secrets, accessToken);
|
|
62
|
+
if (!taskId)
|
|
100
63
|
return {
|
|
101
64
|
documentId,
|
|
102
65
|
taskId: documentId,
|
|
103
66
|
locales: []
|
|
104
67
|
};
|
|
105
|
-
}
|
|
106
|
-
const progressUrl = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs/").concat(taskId, "/progress");
|
|
107
|
-
const smartlingTask = await fetch(proxy, {
|
|
68
|
+
const progressUrl = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs/${taskId}/progress`, smartlingTask = await fetch(proxy, {
|
|
108
69
|
method: "GET",
|
|
109
70
|
headers: getHeaders(progressUrl, accessToken)
|
|
110
|
-
}).then(res => res.json()).then(res => res.response.data);
|
|
71
|
+
}).then((res) => res.json()).then((res) => res.response.data);
|
|
111
72
|
let locales = [];
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
localeId: item.targetLocaleId,
|
|
127
|
-
progress
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
73
|
+
return smartlingTask && smartlingTask.contentProgressReport && (locales = smartlingTask.contentProgressReport.map((item) => {
|
|
74
|
+
let progress = item.progress ? item.progress.percentComplete : 0;
|
|
75
|
+
const progressItem = item.workflowProgressReportList?.[0];
|
|
76
|
+
if (progressItem && item.progress && progressItem.workflowStepSummaryReportItemList && progressItem.workflowStepSummaryReportItemList.length > 1) {
|
|
77
|
+
const lastStep = progressItem.workflowStepSummaryReportItemList.at(-1);
|
|
78
|
+
lastStep && lastStep.wordCount >= 0 && (progress = Math.floor(lastStep.wordCount / item.progress.totalWordCount * 100) ?? 0);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
localeId: item.targetLocaleId,
|
|
82
|
+
progress
|
|
83
|
+
};
|
|
84
|
+
})), {
|
|
132
85
|
documentId,
|
|
133
86
|
locales,
|
|
134
87
|
//since our download is tied to document id for smartling, keep track of it as a task
|
|
135
88
|
taskId: documentId,
|
|
136
|
-
linkToVendorTask:
|
|
89
|
+
linkToVendorTask: `https://dashboard.smartling.com/app/projects/${project}/account-jobs/${project}:${taskId}`
|
|
137
90
|
};
|
|
138
|
-
}
|
|
139
|
-
const createJob = (jobName, secrets, localeIds, accessToken, documentId) => {
|
|
91
|
+
}, createJob = (jobName, secrets, localeIds, accessToken, documentId) => {
|
|
140
92
|
const {
|
|
141
93
|
project,
|
|
142
94
|
proxy
|
|
143
95
|
} = secrets;
|
|
144
|
-
if (!project || !proxy)
|
|
96
|
+
if (!project || !proxy)
|
|
145
97
|
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.");
|
|
146
|
-
}
|
|
147
|
-
const url = "https://api.smartling.com/jobs-api/v3/projects/".concat(project, "/jobs");
|
|
98
|
+
const url = `https://api.smartling.com/jobs-api/v3/projects/${project}/jobs`;
|
|
148
99
|
return fetch(proxy, {
|
|
149
100
|
method: "POST",
|
|
150
101
|
headers: {
|
|
@@ -156,180 +107,110 @@ const createJob = (jobName, secrets, localeIds, accessToken, documentId) => {
|
|
|
156
107
|
targetLocaleIds: localeIds,
|
|
157
108
|
referenceNumber: documentId
|
|
158
109
|
})
|
|
159
|
-
}).then(res => res.json()).then(res => res.response.data.translationJobUid);
|
|
160
|
-
}
|
|
161
|
-
const createJobBatch = (jobId, secrets, documentId, accessToken, localeIds, workflowUid) => {
|
|
110
|
+
}).then((res) => res.json()).then((res) => res.response.data.translationJobUid);
|
|
111
|
+
}, createJobBatch = (jobId, secrets, documentId, accessToken, localeIds, workflowUid) => {
|
|
162
112
|
const {
|
|
163
113
|
project,
|
|
164
114
|
proxy
|
|
165
115
|
} = secrets;
|
|
166
|
-
if (!project || !proxy)
|
|
116
|
+
if (!project || !proxy)
|
|
167
117
|
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.");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const reqBody = {
|
|
171
|
-
authorize: true,
|
|
118
|
+
const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches`, reqBody = {
|
|
119
|
+
authorize: !0,
|
|
172
120
|
translationJobUid: jobId,
|
|
173
121
|
fileUris: [documentId]
|
|
174
122
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
return fetch(proxy, {
|
|
123
|
+
return workflowUid && (reqBody.localeWorkflows = localeIds.map((l) => ({
|
|
124
|
+
targetLocaleId: l,
|
|
125
|
+
workflowUid
|
|
126
|
+
}))), fetch(proxy, {
|
|
182
127
|
method: "POST",
|
|
183
128
|
headers: {
|
|
184
129
|
...getHeaders(url, accessToken),
|
|
185
130
|
"content-type": "application/json"
|
|
186
131
|
},
|
|
187
132
|
body: JSON.stringify(reqBody)
|
|
188
|
-
}).then(res => res.json()).then(res => res.response.data.batchUid);
|
|
189
|
-
}
|
|
190
|
-
const uploadFileToBatch = (batchUid, documentId, document, secrets, localeIds, accessToken, callbackUrl) => {
|
|
133
|
+
}).then((res) => res.json()).then((res) => res.response.data.batchUid);
|
|
134
|
+
}, uploadFileToBatch = (batchUid, documentId, document, secrets, localeIds, accessToken, callbackUrl) => {
|
|
191
135
|
const {
|
|
192
136
|
project,
|
|
193
137
|
proxy
|
|
194
138
|
} = secrets;
|
|
195
|
-
if (!project || !proxy)
|
|
139
|
+
if (!project || !proxy)
|
|
196
140
|
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.");
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const formData = new FormData();
|
|
200
|
-
formData.append("fileUri", documentId);
|
|
201
|
-
formData.append("fileType", "html");
|
|
202
|
-
const htmlBuffer = buffer.Buffer.from(document.content, "utf-8");
|
|
203
|
-
formData.append("file", new Blob([htmlBuffer]), "".concat(document.name, ".html"));
|
|
204
|
-
localeIds.forEach(localeId => formData.append("localeIdsToAuthorize[]", localeId));
|
|
205
|
-
if (callbackUrl) {
|
|
206
|
-
formData.append("callbackUrl", callbackUrl);
|
|
207
|
-
}
|
|
208
|
-
return fetch(proxy, {
|
|
141
|
+
const url = `https://api.smartling.com/job-batches-api/v2/projects/${project}/batches/${batchUid}/file`, formData = new FormData();
|
|
142
|
+
return formData.append("fileUri", documentId), formData.append("fileType", "html"), formData.append("file", new Blob([document.content]), `${document.name}.html`), localeIds.forEach((localeId) => formData.append("localeIdsToAuthorize[]", localeId)), callbackUrl && formData.append("callbackUrl", callbackUrl), fetch(proxy, {
|
|
209
143
|
method: "POST",
|
|
210
144
|
headers: getHeaders(url, accessToken),
|
|
211
145
|
body: formData
|
|
212
|
-
}).then(res => res.json());
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (!(secrets == null ? void 0 : secrets.project) || !(secrets == null ? void 0 : secrets.secret) || !(secrets == null ? void 0 : secrets.proxy)) {
|
|
146
|
+
}).then((res) => res.json());
|
|
147
|
+
}, createTask = async (documentId, document, localeIds, secrets, workflowUid, callbackUrl) => {
|
|
148
|
+
if (!secrets?.project || !secrets?.secret || !secrets?.proxy)
|
|
216
149
|
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.");
|
|
217
|
-
}
|
|
218
150
|
const accessToken = await authenticate(secrets);
|
|
219
151
|
let taskId = await findExistingJob(document.name, secrets, accessToken);
|
|
220
|
-
|
|
221
|
-
taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId);
|
|
222
|
-
}
|
|
152
|
+
taskId || (taskId = await createJob(document.name, secrets, localeIds, accessToken, documentId));
|
|
223
153
|
const batchUid = await createJobBatch(taskId, secrets, documentId, accessToken, localeIds, workflowUid);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
|
|
154
|
+
return await uploadFileToBatch(batchUid, documentId, document, secrets, localeIds, accessToken, callbackUrl), getTranslationTask(documentId, secrets);
|
|
155
|
+
}, getLocales = async (secrets) => {
|
|
156
|
+
if (!secrets?.project || !secrets?.secret || !secrets?.proxy)
|
|
157
|
+
return [];
|
|
158
|
+
const {
|
|
159
|
+
project,
|
|
160
|
+
proxy
|
|
161
|
+
} = secrets, url = `https://api.smartling.com/projects-api/v2/projects/${project}`, accessToken = await authenticate(secrets);
|
|
162
|
+
return fetch(proxy, {
|
|
163
|
+
method: "GET",
|
|
164
|
+
headers: getHeaders(url, accessToken)
|
|
165
|
+
}).then((res) => res.json()).then((res) => res.response.data.targetLocales);
|
|
166
|
+
}, getTranslation = async (taskId, localeId, secrets) => {
|
|
167
|
+
if (!secrets?.project || !secrets?.secret || !secrets?.proxy)
|
|
230
168
|
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.");
|
|
231
|
-
}
|
|
232
169
|
const {
|
|
233
170
|
project,
|
|
234
171
|
proxy
|
|
235
|
-
} = secrets;
|
|
236
|
-
|
|
237
|
-
const accessToken = await authenticate(secrets);
|
|
238
|
-
const translatedHTML = await fetch(proxy, {
|
|
172
|
+
} = secrets, url = `https://api.smartling.com/files-api/v2/projects/${project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`, accessToken = await authenticate(secrets);
|
|
173
|
+
return await fetch(proxy, {
|
|
239
174
|
method: "GET",
|
|
240
175
|
headers: getHeaders(url, accessToken)
|
|
241
|
-
}).then(res => res.json()).then(res => {
|
|
242
|
-
|
|
243
|
-
if (res.body) {
|
|
176
|
+
}).then((res) => res.json()).then((res) => {
|
|
177
|
+
if (res.body)
|
|
244
178
|
return res.body;
|
|
245
|
-
|
|
246
|
-
const errMsg =
|
|
179
|
+
if (res.response.errors) {
|
|
180
|
+
const errMsg = res.response.errors[0]?.message || "Error retrieving translation from Smartling";
|
|
247
181
|
throw new Error(errMsg);
|
|
248
182
|
}
|
|
249
183
|
return "";
|
|
250
184
|
});
|
|
251
|
-
|
|
252
|
-
};
|
|
253
|
-
const SmartlingAdapter = {
|
|
185
|
+
}, SmartlingAdapter = {
|
|
254
186
|
getLocales,
|
|
255
187
|
getTranslationTask,
|
|
256
188
|
createTask,
|
|
257
189
|
getTranslation
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
...sanityTranslationsTab.baseDocumentLevelConfig,
|
|
190
|
+
}, defaultDocumentLevelConfig = {
|
|
191
|
+
...baseDocumentLevelConfig,
|
|
261
192
|
adapter: SmartlingAdapter
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
...sanityTranslationsTab.legacyDocumentLevelConfig,
|
|
193
|
+
}, legacyDocumentLevelConfig = {
|
|
194
|
+
...legacyDocumentLevelConfig$1,
|
|
265
195
|
adapter: SmartlingAdapter
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
...sanityTranslationsTab.baseFieldLevelConfig,
|
|
196
|
+
}, defaultFieldLevelConfig = {
|
|
197
|
+
...baseFieldLevelConfig,
|
|
269
198
|
adapter: SmartlingAdapter
|
|
270
199
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
Object.defineProperty(exports, 'TranslationsTab', {
|
|
290
|
-
enumerable: true,
|
|
291
|
-
get: function () {
|
|
292
|
-
return sanityTranslationsTab.TranslationsTab;
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
Object.defineProperty(exports, 'customSerializers', {
|
|
296
|
-
enumerable: true,
|
|
297
|
-
get: function () {
|
|
298
|
-
return sanityTranslationsTab.customSerializers;
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
Object.defineProperty(exports, 'defaultStopTypes', {
|
|
302
|
-
enumerable: true,
|
|
303
|
-
get: function () {
|
|
304
|
-
return sanityTranslationsTab.defaultStopTypes;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
Object.defineProperty(exports, 'documentLevelPatch', {
|
|
308
|
-
enumerable: true,
|
|
309
|
-
get: function () {
|
|
310
|
-
return sanityTranslationsTab.documentLevelPatch;
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
Object.defineProperty(exports, 'fieldLevelPatch', {
|
|
314
|
-
enumerable: true,
|
|
315
|
-
get: function () {
|
|
316
|
-
return sanityTranslationsTab.fieldLevelPatch;
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
Object.defineProperty(exports, 'findLatestDraft', {
|
|
320
|
-
enumerable: true,
|
|
321
|
-
get: function () {
|
|
322
|
-
return sanityTranslationsTab.findLatestDraft;
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
Object.defineProperty(exports, 'legacyDocumentLevelPatch', {
|
|
326
|
-
enumerable: true,
|
|
327
|
-
get: function () {
|
|
328
|
-
return sanityTranslationsTab.legacyDocumentLevelPatch;
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
exports.SmartlingAdapter = SmartlingAdapter;
|
|
332
|
-
exports.defaultDocumentLevelConfig = defaultDocumentLevelConfig;
|
|
333
|
-
exports.defaultFieldLevelConfig = defaultFieldLevelConfig;
|
|
334
|
-
exports.legacyDocumentLevelConfig = legacyDocumentLevelConfig;
|
|
200
|
+
export {
|
|
201
|
+
BaseDocumentDeserializer,
|
|
202
|
+
BaseDocumentMerger,
|
|
203
|
+
BaseDocumentSerializer,
|
|
204
|
+
SmartlingAdapter,
|
|
205
|
+
TranslationsTab,
|
|
206
|
+
customSerializers,
|
|
207
|
+
defaultDocumentLevelConfig,
|
|
208
|
+
defaultFieldLevelConfig,
|
|
209
|
+
defaultStopTypes,
|
|
210
|
+
documentLevelPatch,
|
|
211
|
+
fieldLevelPatch,
|
|
212
|
+
findLatestDraft,
|
|
213
|
+
legacyDocumentLevelConfig,
|
|
214
|
+
legacyDocumentLevelPatch
|
|
215
|
+
};
|
|
335
216
|
//# sourceMappingURL=index.js.map
|