sanity-plugin-studio-smartling 1.2.1 → 1.5.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/dist/adapter/createTask.d.ts +7 -1
- package/dist/adapter/getTranslationTask.d.ts +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/sanity-plugin-studio-smartling.cjs.development.js +135 -63
- package/dist/sanity-plugin-studio-smartling.cjs.development.js.map +1 -1
- package/dist/sanity-plugin-studio-smartling.cjs.production.min.js +1 -1
- package/dist/sanity-plugin-studio-smartling.cjs.production.min.js.map +1 -1
- package/dist/sanity-plugin-studio-smartling.esm.js +136 -64
- package/dist/sanity-plugin-studio-smartling.esm.js.map +1 -1
- package/package.json +4 -3
- package/src/adapter/createTask.ts +27 -8
- package/src/adapter/getTranslation.ts +10 -1
- package/src/adapter/getTranslationTask.ts +4 -2
- package/src/helpers.ts +7 -3
- package/src/index.ts +4 -4
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Secrets } from 'sanity-translations-tab';
|
|
2
|
-
export declare const createTask: (documentId: string, document: Record<string, any>, localeIds: string[], secrets: Secrets) => Promise<{
|
|
2
|
+
export declare const createTask: (documentId: string, document: Record<string, any>, localeIds: string[], secrets: Secrets, workflowUid?: string) => Promise<{
|
|
3
|
+
documentId: string;
|
|
4
|
+
taskId: string;
|
|
5
|
+
locales: any[];
|
|
6
|
+
linkToVendorTask?: undefined;
|
|
7
|
+
} | {
|
|
3
8
|
documentId: string;
|
|
4
9
|
locales: any[];
|
|
5
10
|
taskId: string;
|
|
11
|
+
linkToVendorTask: string;
|
|
6
12
|
}>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Secrets } from 'sanity-translations-tab';
|
|
2
2
|
export declare const getTranslationTask: (documentId: string, secrets: Secrets) => Promise<{
|
|
3
|
+
documentId: string;
|
|
4
|
+
taskId: string;
|
|
5
|
+
locales: any[];
|
|
6
|
+
linkToVendorTask?: undefined;
|
|
7
|
+
} | {
|
|
3
8
|
documentId: string;
|
|
4
9
|
locales: any[];
|
|
5
10
|
taskId: string;
|
|
11
|
+
linkToVendorTask: string;
|
|
6
12
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentMerger, d
|
|
|
3
3
|
import { SmartlingAdapter } from './adapter';
|
|
4
4
|
declare const defaultDocumentLevelConfig: {
|
|
5
5
|
exportForTranslation: (id: string) => Promise<import("sanity-naive-html-serializer/dist/types").SerializedDocument>;
|
|
6
|
-
importTranslation: (id: string, localeId: string, document: string) => void
|
|
6
|
+
importTranslation: (id: string, localeId: string, document: string) => Promise<void>;
|
|
7
7
|
adapter: import("sanity-translations-tab").Adapter;
|
|
8
8
|
};
|
|
9
9
|
declare const defaultFieldLevelConfig: {
|
|
10
10
|
exportForTranslation: (id: string) => Promise<import("sanity-naive-html-serializer/dist/types").SerializedDocument>;
|
|
11
|
-
importTranslation: (id: string, localeId: string, document: string) => void
|
|
11
|
+
importTranslation: (id: string, localeId: string, document: string) => Promise<void>;
|
|
12
12
|
adapter: import("sanity-translations-tab").Adapter;
|
|
13
13
|
};
|
|
14
14
|
export { TranslationsTab, BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentMerger, defaultStopTypes, customSerializers, SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, };
|
|
@@ -932,7 +932,7 @@ var getLocales = /*#__PURE__*/function () {
|
|
|
932
932
|
|
|
933
933
|
var getTranslationTask = /*#__PURE__*/function () {
|
|
934
934
|
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, secrets) {
|
|
935
|
-
var accessToken, taskId,
|
|
935
|
+
var accessToken, taskId, projectId, progressUrl, smartlingTask, locales;
|
|
936
936
|
return runtime_1.wrap(function _callee$(_context) {
|
|
937
937
|
while (1) {
|
|
938
938
|
switch (_context.prev = _context.next) {
|
|
@@ -960,18 +960,19 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
960
960
|
});
|
|
961
961
|
|
|
962
962
|
case 8:
|
|
963
|
-
|
|
964
|
-
|
|
963
|
+
projectId = secrets.project;
|
|
964
|
+
progressUrl = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs/" + taskId + "/progress";
|
|
965
|
+
_context.next = 12;
|
|
965
966
|
return fetch(smartlingProxy, {
|
|
966
967
|
method: 'POST',
|
|
967
|
-
headers: getHeaders(
|
|
968
|
+
headers: getHeaders(progressUrl, accessToken)
|
|
968
969
|
}).then(function (res) {
|
|
969
970
|
return res.json();
|
|
970
971
|
}).then(function (res) {
|
|
971
972
|
return res.response.data;
|
|
972
973
|
});
|
|
973
974
|
|
|
974
|
-
case
|
|
975
|
+
case 12:
|
|
975
976
|
smartlingTask = _context.sent;
|
|
976
977
|
locales = [];
|
|
977
978
|
|
|
@@ -988,10 +989,11 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
988
989
|
documentId: documentId,
|
|
989
990
|
locales: locales,
|
|
990
991
|
//since our download is tied to document id for smartling, keep track of it as a task
|
|
991
|
-
taskId: documentId
|
|
992
|
+
taskId: documentId,
|
|
993
|
+
linkToVendorTask: "https://dashboard.smartling.com/app/projects/" + projectId + "/account-jobs/" + projectId + ":" + taskId
|
|
992
994
|
});
|
|
993
995
|
|
|
994
|
-
case
|
|
996
|
+
case 16:
|
|
995
997
|
case "end":
|
|
996
998
|
return _context.stop();
|
|
997
999
|
}
|
|
@@ -1047,30 +1049,41 @@ var createJob = /*#__PURE__*/function () {
|
|
|
1047
1049
|
|
|
1048
1050
|
|
|
1049
1051
|
var createJobBatch = /*#__PURE__*/function () {
|
|
1050
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, projectId, documentName, accessToken) {
|
|
1051
|
-
var url;
|
|
1052
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, projectId, documentName, accessToken, localeIds, workflowUid) {
|
|
1053
|
+
var url, reqBody;
|
|
1052
1054
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1053
1055
|
while (1) {
|
|
1054
1056
|
switch (_context2.prev = _context2.next) {
|
|
1055
1057
|
case 0:
|
|
1056
1058
|
url = "https://api.smartling.com/job-batches-api/v2/projects/" + projectId + "/batches";
|
|
1059
|
+
reqBody = {
|
|
1060
|
+
authorize: true,
|
|
1061
|
+
translationJobUid: jobId,
|
|
1062
|
+
fileUris: [documentName]
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
if (workflowUid) {
|
|
1066
|
+
reqBody.localeWorkflows = localeIds.map(function (l) {
|
|
1067
|
+
return {
|
|
1068
|
+
targetLocaleId: l,
|
|
1069
|
+
workflowUid: workflowUid
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1057
1074
|
return _context2.abrupt("return", fetch(smartlingProxy, {
|
|
1058
1075
|
method: 'POST',
|
|
1059
1076
|
headers: _extends({}, getHeaders(url, accessToken), {
|
|
1060
1077
|
'content-type': 'application/json'
|
|
1061
1078
|
}),
|
|
1062
|
-
body: JSON.stringify(
|
|
1063
|
-
authorize: true,
|
|
1064
|
-
translationJobUid: jobId,
|
|
1065
|
-
fileUris: [documentName]
|
|
1066
|
-
})
|
|
1079
|
+
body: JSON.stringify(reqBody)
|
|
1067
1080
|
}).then(function (res) {
|
|
1068
1081
|
return res.json();
|
|
1069
1082
|
}).then(function (res) {
|
|
1070
1083
|
return res.response.data.batchUid;
|
|
1071
1084
|
}));
|
|
1072
1085
|
|
|
1073
|
-
case
|
|
1086
|
+
case 4:
|
|
1074
1087
|
case "end":
|
|
1075
1088
|
return _context2.stop();
|
|
1076
1089
|
}
|
|
@@ -1078,7 +1091,7 @@ var createJobBatch = /*#__PURE__*/function () {
|
|
|
1078
1091
|
}, _callee2);
|
|
1079
1092
|
}));
|
|
1080
1093
|
|
|
1081
|
-
return function createJobBatch(_x5, _x6, _x7, _x8) {
|
|
1094
|
+
return function createJobBatch(_x5, _x6, _x7, _x8, _x9, _x10) {
|
|
1082
1095
|
return _ref2.apply(this, arguments);
|
|
1083
1096
|
};
|
|
1084
1097
|
}();
|
|
@@ -1115,13 +1128,13 @@ var uploadFileToBatch = /*#__PURE__*/function () {
|
|
|
1115
1128
|
}, _callee3);
|
|
1116
1129
|
}));
|
|
1117
1130
|
|
|
1118
|
-
return function uploadFileToBatch(
|
|
1131
|
+
return function uploadFileToBatch(_x11, _x12, _x13, _x14, _x15) {
|
|
1119
1132
|
return _ref3.apply(this, arguments);
|
|
1120
1133
|
};
|
|
1121
1134
|
}();
|
|
1122
1135
|
|
|
1123
1136
|
var createTask = /*#__PURE__*/function () {
|
|
1124
|
-
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, localeIds, secrets) {
|
|
1137
|
+
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, localeIds, secrets, workflowUid) {
|
|
1125
1138
|
var accessToken, taskId, batchUid, uploadFileRes;
|
|
1126
1139
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1127
1140
|
while (1) {
|
|
@@ -1151,7 +1164,7 @@ var createTask = /*#__PURE__*/function () {
|
|
|
1151
1164
|
|
|
1152
1165
|
case 10:
|
|
1153
1166
|
_context4.next = 12;
|
|
1154
|
-
return createJobBatch(taskId, secrets.project, document.name, accessToken);
|
|
1167
|
+
return createJobBatch(taskId, secrets.project, document.name, accessToken, localeIds, workflowUid);
|
|
1155
1168
|
|
|
1156
1169
|
case 12:
|
|
1157
1170
|
batchUid = _context4.sent;
|
|
@@ -1171,7 +1184,7 @@ var createTask = /*#__PURE__*/function () {
|
|
|
1171
1184
|
}, _callee4);
|
|
1172
1185
|
}));
|
|
1173
1186
|
|
|
1174
|
-
return function createTask(
|
|
1187
|
+
return function createTask(_x16, _x17, _x18, _x19, _x20) {
|
|
1175
1188
|
return _ref4.apply(this, arguments);
|
|
1176
1189
|
};
|
|
1177
1190
|
}();
|
|
@@ -1196,7 +1209,14 @@ var getTranslation = /*#__PURE__*/function () {
|
|
|
1196
1209
|
}).then(function (res) {
|
|
1197
1210
|
return res.json();
|
|
1198
1211
|
}).then(function (res) {
|
|
1199
|
-
|
|
1212
|
+
if (res.body) {
|
|
1213
|
+
return res.body;
|
|
1214
|
+
} else if (res.response.errors) {
|
|
1215
|
+
var _res$response$errors$;
|
|
1216
|
+
|
|
1217
|
+
var errMsg = ((_res$response$errors$ = res.response.errors[0]) == null ? void 0 : _res$response$errors$.message) || 'Error retrieving translation from Smartling';
|
|
1218
|
+
throw new Error(errMsg);
|
|
1219
|
+
}
|
|
1200
1220
|
});
|
|
1201
1221
|
|
|
1202
1222
|
case 6:
|
|
@@ -1262,7 +1282,7 @@ var findDocumentAtRevision = /*#__PURE__*/function () {
|
|
|
1262
1282
|
}).then(function (req) {
|
|
1263
1283
|
return req.json();
|
|
1264
1284
|
}).then(function (req) {
|
|
1265
|
-
return req.documents[0];
|
|
1285
|
+
return req.documents && req.documents[0];
|
|
1266
1286
|
});
|
|
1267
1287
|
|
|
1268
1288
|
case 5:
|
|
@@ -1339,34 +1359,43 @@ var documentLevelPatch = /*#__PURE__*/function () {
|
|
|
1339
1359
|
case 13:
|
|
1340
1360
|
i18nDoc = _context2.sent;
|
|
1341
1361
|
|
|
1342
|
-
if (i18nDoc) {
|
|
1343
|
-
|
|
1362
|
+
if (!i18nDoc) {
|
|
1363
|
+
_context2.next = 21;
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1344
1366
|
|
|
1345
|
-
|
|
1346
|
-
var key = _ref3[0],
|
|
1347
|
-
value = _ref3[1];
|
|
1367
|
+
cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
|
|
1348
1368
|
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return p.set(cleanedMerge);
|
|
1356
|
-
}).commit();
|
|
1357
|
-
} else {
|
|
1358
|
-
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1359
|
-
|
|
1360
|
-
if (baseDoc._lang) {
|
|
1361
|
-
merged._lang = localeId;
|
|
1362
|
-
} else if (baseDoc.__i18n_lang) {
|
|
1363
|
-
merged.__i18n_lang = localeId;
|
|
1369
|
+
Object.entries(merged).forEach(function (_ref3) {
|
|
1370
|
+
var key = _ref3[0],
|
|
1371
|
+
value = _ref3[1];
|
|
1372
|
+
|
|
1373
|
+
if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
|
|
1374
|
+
cleanedMerge[key] = value;
|
|
1364
1375
|
}
|
|
1376
|
+
});
|
|
1377
|
+
_context2.next = 19;
|
|
1378
|
+
return client.transaction() //@ts-ignore
|
|
1379
|
+
.patch(i18nDoc._id, function (p) {
|
|
1380
|
+
return p.set(cleanedMerge);
|
|
1381
|
+
}).commit();
|
|
1382
|
+
|
|
1383
|
+
case 19:
|
|
1384
|
+
_context2.next = 24;
|
|
1385
|
+
break;
|
|
1365
1386
|
|
|
1366
|
-
|
|
1387
|
+
case 21:
|
|
1388
|
+
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1389
|
+
|
|
1390
|
+
if (baseDoc._lang) {
|
|
1391
|
+
merged._lang = localeId;
|
|
1392
|
+
} else if (baseDoc.__i18n_lang) {
|
|
1393
|
+
merged.__i18n_lang = localeId;
|
|
1367
1394
|
}
|
|
1368
1395
|
|
|
1369
|
-
|
|
1396
|
+
client.create(merged);
|
|
1397
|
+
|
|
1398
|
+
case 24:
|
|
1370
1399
|
case "end":
|
|
1371
1400
|
return _context2.stop();
|
|
1372
1401
|
}
|
|
@@ -1408,9 +1437,10 @@ var fieldLevelPatch = /*#__PURE__*/function () {
|
|
|
1408
1437
|
|
|
1409
1438
|
case 9:
|
|
1410
1439
|
merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
|
|
1411
|
-
|
|
1440
|
+
_context3.next = 12;
|
|
1441
|
+
return client.patch(baseDoc._id).set(merged).commit();
|
|
1412
1442
|
|
|
1413
|
-
case
|
|
1443
|
+
case 12:
|
|
1414
1444
|
case "end":
|
|
1415
1445
|
return _context3.stop();
|
|
1416
1446
|
}
|
|
@@ -1455,48 +1485,90 @@ var defaultDocumentLevelConfig = {
|
|
|
1455
1485
|
|
|
1456
1486
|
return exportForTranslation;
|
|
1457
1487
|
}(),
|
|
1458
|
-
importTranslation: function
|
|
1459
|
-
var
|
|
1460
|
-
|
|
1461
|
-
|
|
1488
|
+
importTranslation: /*#__PURE__*/function () {
|
|
1489
|
+
var _importTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id, localeId, document) {
|
|
1490
|
+
var deserialized;
|
|
1491
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1492
|
+
while (1) {
|
|
1493
|
+
switch (_context2.prev = _context2.next) {
|
|
1494
|
+
case 0:
|
|
1495
|
+
deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
|
|
1496
|
+
_context2.next = 3;
|
|
1497
|
+
return documentLevelPatch(id, deserialized, localeId);
|
|
1498
|
+
|
|
1499
|
+
case 3:
|
|
1500
|
+
case "end":
|
|
1501
|
+
return _context2.stop();
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
}, _callee2);
|
|
1505
|
+
}));
|
|
1506
|
+
|
|
1507
|
+
function importTranslation(_x2, _x3, _x4) {
|
|
1508
|
+
return _importTranslation.apply(this, arguments);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
return importTranslation;
|
|
1512
|
+
}(),
|
|
1462
1513
|
adapter: SmartlingAdapter
|
|
1463
1514
|
};
|
|
1464
1515
|
var defaultFieldLevelConfig = {
|
|
1465
1516
|
exportForTranslation: /*#__PURE__*/function () {
|
|
1466
|
-
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1517
|
+
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(id) {
|
|
1467
1518
|
var doc, serialized;
|
|
1468
|
-
return runtime_1.wrap(function
|
|
1519
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1469
1520
|
while (1) {
|
|
1470
|
-
switch (
|
|
1521
|
+
switch (_context3.prev = _context3.next) {
|
|
1471
1522
|
case 0:
|
|
1472
|
-
|
|
1523
|
+
_context3.next = 2;
|
|
1473
1524
|
return findLatestDraft(id);
|
|
1474
1525
|
|
|
1475
1526
|
case 2:
|
|
1476
|
-
doc =
|
|
1527
|
+
doc = _context3.sent;
|
|
1477
1528
|
serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'field'); //needed for lookup by translation tab
|
|
1478
1529
|
|
|
1479
1530
|
serialized.name = id;
|
|
1480
|
-
return
|
|
1531
|
+
return _context3.abrupt("return", serialized);
|
|
1481
1532
|
|
|
1482
1533
|
case 6:
|
|
1483
1534
|
case "end":
|
|
1484
|
-
return
|
|
1535
|
+
return _context3.stop();
|
|
1485
1536
|
}
|
|
1486
1537
|
}
|
|
1487
|
-
},
|
|
1538
|
+
}, _callee3);
|
|
1488
1539
|
}));
|
|
1489
1540
|
|
|
1490
|
-
function exportForTranslation(
|
|
1541
|
+
function exportForTranslation(_x5) {
|
|
1491
1542
|
return _exportForTranslation2.apply(this, arguments);
|
|
1492
1543
|
}
|
|
1493
1544
|
|
|
1494
1545
|
return exportForTranslation;
|
|
1495
1546
|
}(),
|
|
1496
|
-
importTranslation: function
|
|
1497
|
-
var
|
|
1498
|
-
|
|
1499
|
-
|
|
1547
|
+
importTranslation: /*#__PURE__*/function () {
|
|
1548
|
+
var _importTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(id, localeId, document) {
|
|
1549
|
+
var deserialized;
|
|
1550
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
1551
|
+
while (1) {
|
|
1552
|
+
switch (_context4.prev = _context4.next) {
|
|
1553
|
+
case 0:
|
|
1554
|
+
deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
|
|
1555
|
+
_context4.next = 3;
|
|
1556
|
+
return fieldLevelPatch(id, deserialized, localeId);
|
|
1557
|
+
|
|
1558
|
+
case 3:
|
|
1559
|
+
case "end":
|
|
1560
|
+
return _context4.stop();
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
}, _callee4);
|
|
1564
|
+
}));
|
|
1565
|
+
|
|
1566
|
+
function importTranslation(_x6, _x7, _x8) {
|
|
1567
|
+
return _importTranslation2.apply(this, arguments);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
return importTranslation;
|
|
1571
|
+
}(),
|
|
1500
1572
|
adapter: SmartlingAdapter
|
|
1501
1573
|
};
|
|
1502
1574
|
|