sanity-plugin-studio-smartling 1.4.0 → 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 +6 -0
- package/dist/adapter/getTranslationTask.d.ts +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/sanity-plugin-studio-smartling.cjs.development.js +110 -49
- 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 +111 -50
- package/dist/sanity-plugin-studio-smartling.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/adapter/getTranslation.ts +10 -1
- package/src/adapter/getTranslationTask.ts +4 -2
- package/src/helpers.ts +6 -2
- package/src/index.ts +4 -4
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Secrets } from 'sanity-translations-tab';
|
|
2
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
|
}
|
|
@@ -1207,7 +1209,14 @@ var getTranslation = /*#__PURE__*/function () {
|
|
|
1207
1209
|
}).then(function (res) {
|
|
1208
1210
|
return res.json();
|
|
1209
1211
|
}).then(function (res) {
|
|
1210
|
-
|
|
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
|
+
}
|
|
1211
1220
|
});
|
|
1212
1221
|
|
|
1213
1222
|
case 6:
|
|
@@ -1350,34 +1359,43 @@ var documentLevelPatch = /*#__PURE__*/function () {
|
|
|
1350
1359
|
case 13:
|
|
1351
1360
|
i18nDoc = _context2.sent;
|
|
1352
1361
|
|
|
1353
|
-
if (i18nDoc) {
|
|
1354
|
-
|
|
1362
|
+
if (!i18nDoc) {
|
|
1363
|
+
_context2.next = 21;
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
|
|
1355
1368
|
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1369
|
+
Object.entries(merged).forEach(function (_ref3) {
|
|
1370
|
+
var key = _ref3[0],
|
|
1371
|
+
value = _ref3[1];
|
|
1359
1372
|
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
}
|
|
1363
|
-
});
|
|
1364
|
-
client.transaction() //@ts-ignore
|
|
1365
|
-
.patch(i18nDoc._id, function (p) {
|
|
1366
|
-
return p.set(cleanedMerge);
|
|
1367
|
-
}).commit();
|
|
1368
|
-
} else {
|
|
1369
|
-
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1370
|
-
|
|
1371
|
-
if (baseDoc._lang) {
|
|
1372
|
-
merged._lang = localeId;
|
|
1373
|
-
} else if (baseDoc.__i18n_lang) {
|
|
1374
|
-
merged.__i18n_lang = localeId;
|
|
1373
|
+
if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
|
|
1374
|
+
cleanedMerge[key] = value;
|
|
1375
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;
|
|
1386
|
+
|
|
1387
|
+
case 21:
|
|
1388
|
+
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1376
1389
|
|
|
1377
|
-
|
|
1390
|
+
if (baseDoc._lang) {
|
|
1391
|
+
merged._lang = localeId;
|
|
1392
|
+
} else if (baseDoc.__i18n_lang) {
|
|
1393
|
+
merged.__i18n_lang = localeId;
|
|
1378
1394
|
}
|
|
1379
1395
|
|
|
1380
|
-
|
|
1396
|
+
client.create(merged);
|
|
1397
|
+
|
|
1398
|
+
case 24:
|
|
1381
1399
|
case "end":
|
|
1382
1400
|
return _context2.stop();
|
|
1383
1401
|
}
|
|
@@ -1419,9 +1437,10 @@ var fieldLevelPatch = /*#__PURE__*/function () {
|
|
|
1419
1437
|
|
|
1420
1438
|
case 9:
|
|
1421
1439
|
merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
|
|
1422
|
-
|
|
1440
|
+
_context3.next = 12;
|
|
1441
|
+
return client.patch(baseDoc._id).set(merged).commit();
|
|
1423
1442
|
|
|
1424
|
-
case
|
|
1443
|
+
case 12:
|
|
1425
1444
|
case "end":
|
|
1426
1445
|
return _context3.stop();
|
|
1427
1446
|
}
|
|
@@ -1466,48 +1485,90 @@ var defaultDocumentLevelConfig = {
|
|
|
1466
1485
|
|
|
1467
1486
|
return exportForTranslation;
|
|
1468
1487
|
}(),
|
|
1469
|
-
importTranslation: function
|
|
1470
|
-
var
|
|
1471
|
-
|
|
1472
|
-
|
|
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
|
+
}(),
|
|
1473
1513
|
adapter: SmartlingAdapter
|
|
1474
1514
|
};
|
|
1475
1515
|
var defaultFieldLevelConfig = {
|
|
1476
1516
|
exportForTranslation: /*#__PURE__*/function () {
|
|
1477
|
-
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1517
|
+
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(id) {
|
|
1478
1518
|
var doc, serialized;
|
|
1479
|
-
return runtime_1.wrap(function
|
|
1519
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1480
1520
|
while (1) {
|
|
1481
|
-
switch (
|
|
1521
|
+
switch (_context3.prev = _context3.next) {
|
|
1482
1522
|
case 0:
|
|
1483
|
-
|
|
1523
|
+
_context3.next = 2;
|
|
1484
1524
|
return findLatestDraft(id);
|
|
1485
1525
|
|
|
1486
1526
|
case 2:
|
|
1487
|
-
doc =
|
|
1527
|
+
doc = _context3.sent;
|
|
1488
1528
|
serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'field'); //needed for lookup by translation tab
|
|
1489
1529
|
|
|
1490
1530
|
serialized.name = id;
|
|
1491
|
-
return
|
|
1531
|
+
return _context3.abrupt("return", serialized);
|
|
1492
1532
|
|
|
1493
1533
|
case 6:
|
|
1494
1534
|
case "end":
|
|
1495
|
-
return
|
|
1535
|
+
return _context3.stop();
|
|
1496
1536
|
}
|
|
1497
1537
|
}
|
|
1498
|
-
},
|
|
1538
|
+
}, _callee3);
|
|
1499
1539
|
}));
|
|
1500
1540
|
|
|
1501
|
-
function exportForTranslation(
|
|
1541
|
+
function exportForTranslation(_x5) {
|
|
1502
1542
|
return _exportForTranslation2.apply(this, arguments);
|
|
1503
1543
|
}
|
|
1504
1544
|
|
|
1505
1545
|
return exportForTranslation;
|
|
1506
1546
|
}(),
|
|
1507
|
-
importTranslation: function
|
|
1508
|
-
var
|
|
1509
|
-
|
|
1510
|
-
|
|
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
|
+
}(),
|
|
1511
1572
|
adapter: SmartlingAdapter
|
|
1512
1573
|
};
|
|
1513
1574
|
|