sanity-plugin-studio-smartling 1.1.5 → 1.3.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.
@@ -0,0 +1,5 @@
1
+ import { SanityDocument } from '@sanity/types';
2
+ export declare const findLatestDraft: (documentId: string, ignoreI18n?: boolean) => any;
3
+ export declare const findDocumentAtRevision: (documentId: string, rev: string) => Promise<any>;
4
+ export declare const documentLevelPatch: (documentId: string, translatedFields: SanityDocument, localeId: string) => Promise<void>;
5
+ export declare const fieldLevelPatch: (documentId: string, translatedFields: SanityDocument, localeId: string) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { TranslationsTab } from 'sanity-translations-tab';
2
- import { BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentPatcher, defaultStopTypes, customSerializers } from 'sanity-naive-html-serializer';
2
+ import { BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentMerger, defaultStopTypes, customSerializers } from 'sanity-naive-html-serializer';
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) => any;
6
+ importTranslation: (id: string, localeId: string, document: string) => 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) => any;
11
+ importTranslation: (id: string, localeId: string, document: string) => void;
12
12
  adapter: import("sanity-translations-tab").Adapter;
13
13
  };
14
- export { TranslationsTab, BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentPatcher, defaultStopTypes, customSerializers, SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, };
14
+ export { TranslationsTab, BaseDocumentDeserializer, BaseDocumentSerializer, BaseDocumentMerger, defaultStopTypes, customSerializers, SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig, };
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
+
3
5
  var sanityTranslationsTab = require('sanity-translations-tab');
4
6
  var sanityNaiveHtmlSerializer = require('sanity-naive-html-serializer');
7
+ var sanityClient = _interopDefault(require('part:@sanity/base/client'));
5
8
 
6
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
7
10
  try {
@@ -976,7 +979,7 @@ var getTranslationTask = /*#__PURE__*/function () {
976
979
  locales = smartlingTask.contentProgressReport.map(function (item) {
977
980
  return {
978
981
  localeId: item.targetLocaleId,
979
- progress: item.progress.percentComplete
982
+ progress: item.progress ? item.progress.percentComplete : 0
980
983
  };
981
984
  });
982
985
  }
@@ -1001,28 +1004,30 @@ var getTranslationTask = /*#__PURE__*/function () {
1001
1004
  };
1002
1005
  }();
1003
1006
 
1004
- var uploadFile = /*#__PURE__*/function () {
1005
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, projectId, document, accessToken) {
1006
- var url, formData, htmlBuffer;
1007
+ var createJob = /*#__PURE__*/function () {
1008
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(jobName, projectId, localeIds, accessToken) {
1009
+ var url;
1007
1010
  return runtime_1.wrap(function _callee$(_context) {
1008
1011
  while (1) {
1009
1012
  switch (_context.prev = _context.next) {
1010
1013
  case 0:
1011
- url = "https://api.smartling.com/files-api/v2/projects/" + projectId + "/file";
1012
- formData = new FormData();
1013
- formData.append('fileUri', documentId);
1014
- formData.append('fileType', 'html');
1015
- htmlBuffer = Buffer.from(document.content, 'utf-8');
1016
- formData.append('file', new Blob([htmlBuffer]), document.name + ".html");
1014
+ url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs";
1017
1015
  return _context.abrupt("return", fetch(smartlingProxy, {
1018
1016
  method: 'POST',
1019
- headers: getHeaders(url, accessToken),
1020
- body: formData
1017
+ headers: _extends({}, getHeaders(url, accessToken), {
1018
+ 'content-type': 'application/json'
1019
+ }),
1020
+ body: JSON.stringify({
1021
+ jobName: jobName,
1022
+ targetLocaleIds: localeIds
1023
+ })
1021
1024
  }).then(function (res) {
1022
1025
  return res.json();
1026
+ }).then(function (res) {
1027
+ return res.response.data.translationJobUid;
1023
1028
  }));
1024
1029
 
1025
- case 7:
1030
+ case 2:
1026
1031
  case "end":
1027
1032
  return _context.stop();
1028
1033
  }
@@ -1030,32 +1035,39 @@ var uploadFile = /*#__PURE__*/function () {
1030
1035
  }, _callee);
1031
1036
  }));
1032
1037
 
1033
- return function uploadFile(_x, _x2, _x3, _x4) {
1038
+ return function createJob(_x, _x2, _x3, _x4) {
1034
1039
  return _ref.apply(this, arguments);
1035
1040
  };
1036
1041
  }();
1042
+ /* we're using batches here because it eliminates some
1043
+ * new string authorization issues for updating existing jobs,
1044
+ * and is able to be used for new bulk
1045
+ * job functionality.
1046
+ */
1047
+
1037
1048
 
1038
- var assignFileToJob = /*#__PURE__*/function () {
1039
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, documentId, projectId, localeIds, accessToken) {
1049
+ var createJobBatch = /*#__PURE__*/function () {
1050
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, projectId, documentName, accessToken) {
1040
1051
  var url;
1041
1052
  return runtime_1.wrap(function _callee2$(_context2) {
1042
1053
  while (1) {
1043
1054
  switch (_context2.prev = _context2.next) {
1044
1055
  case 0:
1045
- url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs/" + jobId + "/file/add";
1056
+ url = "https://api.smartling.com/job-batches-api/v2/projects/" + projectId + "/batches";
1046
1057
  return _context2.abrupt("return", fetch(smartlingProxy, {
1047
1058
  method: 'POST',
1048
1059
  headers: _extends({}, getHeaders(url, accessToken), {
1049
1060
  'content-type': 'application/json'
1050
1061
  }),
1051
1062
  body: JSON.stringify({
1052
- fileUri: documentId,
1053
- targetLocaleIds: localeIds
1063
+ authorize: true,
1064
+ translationJobUid: jobId,
1065
+ fileUris: [documentName]
1054
1066
  })
1055
1067
  }).then(function (res) {
1056
1068
  return res.json();
1057
1069
  }).then(function (res) {
1058
- return res.response;
1070
+ return res.response.data.batchUid;
1059
1071
  }));
1060
1072
 
1061
1073
  case 2:
@@ -1066,35 +1078,36 @@ var assignFileToJob = /*#__PURE__*/function () {
1066
1078
  }, _callee2);
1067
1079
  }));
1068
1080
 
1069
- return function assignFileToJob(_x5, _x6, _x7, _x8, _x9) {
1081
+ return function createJobBatch(_x5, _x6, _x7, _x8) {
1070
1082
  return _ref2.apply(this, arguments);
1071
1083
  };
1072
1084
  }();
1073
1085
 
1074
- var createJob = /*#__PURE__*/function () {
1075
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, projectId, localeIds, accessToken) {
1076
- var url;
1086
+ var uploadFileToBatch = /*#__PURE__*/function () {
1087
+ var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(batchUid, document, projectId, localeIds, accessToken) {
1088
+ var url, formData, htmlBuffer;
1077
1089
  return runtime_1.wrap(function _callee3$(_context3) {
1078
1090
  while (1) {
1079
1091
  switch (_context3.prev = _context3.next) {
1080
1092
  case 0:
1081
- url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs";
1093
+ url = "https://api.smartling.com/job-batches-api/v2/projects/" + projectId + "/batches/" + batchUid + "/file";
1094
+ formData = new FormData();
1095
+ formData.append('fileUri', document.name);
1096
+ formData.append('fileType', 'html');
1097
+ htmlBuffer = Buffer.from(document.content, 'utf-8');
1098
+ formData.append('file', new Blob([htmlBuffer]), document.name + ".html");
1099
+ localeIds.forEach(function (localeId) {
1100
+ return formData.append('localeIdsToAuthorize[]', localeId);
1101
+ });
1082
1102
  return _context3.abrupt("return", fetch(smartlingProxy, {
1083
1103
  method: 'POST',
1084
- headers: _extends({}, getHeaders(url, accessToken), {
1085
- 'content-type': 'application/json'
1086
- }),
1087
- body: JSON.stringify({
1088
- jobName: documentId,
1089
- targetLocaleIds: localeIds
1090
- })
1104
+ headers: getHeaders(url, accessToken),
1105
+ body: formData
1091
1106
  }).then(function (res) {
1092
1107
  return res.json();
1093
- }).then(function (res) {
1094
- return res.response.data.translationJobUid;
1095
1108
  }));
1096
1109
 
1097
- case 2:
1110
+ case 8:
1098
1111
  case "end":
1099
1112
  return _context3.stop();
1100
1113
  }
@@ -1102,108 +1115,64 @@ var createJob = /*#__PURE__*/function () {
1102
1115
  }, _callee3);
1103
1116
  }));
1104
1117
 
1105
- return function createJob(_x10, _x11, _x12, _x13) {
1118
+ return function uploadFileToBatch(_x9, _x10, _x11, _x12, _x13) {
1106
1119
  return _ref3.apply(this, arguments);
1107
1120
  };
1108
1121
  }();
1109
1122
 
1110
- var authorizeJob = /*#__PURE__*/function () {
1111
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(jobId, projectId, localeIds, accessToken) {
1112
- var url;
1123
+ var createTask = /*#__PURE__*/function () {
1124
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, localeIds, secrets) {
1125
+ var accessToken, taskId, batchUid, uploadFileRes;
1113
1126
  return runtime_1.wrap(function _callee4$(_context4) {
1114
1127
  while (1) {
1115
1128
  switch (_context4.prev = _context4.next) {
1116
1129
  case 0:
1117
- url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs/" + jobId + "/authorize";
1118
- return _context4.abrupt("return", fetch(smartlingProxy, {
1119
- method: 'POST',
1120
- headers: _extends({}, getHeaders(url, accessToken), {
1121
- 'content-type': 'application/json'
1122
- }),
1123
- body: JSON.stringify({
1124
- localeWorkflows: localeIds.map(function (l) {
1125
- return {
1126
- targetLocaleId: l
1127
- };
1128
- })
1129
- })
1130
- }).then(function (res) {
1131
- return res.json();
1132
- }));
1133
-
1134
- case 2:
1135
- case "end":
1136
- return _context4.stop();
1137
- }
1138
- }
1139
- }, _callee4);
1140
- }));
1141
-
1142
- return function authorizeJob(_x14, _x15, _x16, _x17) {
1143
- return _ref4.apply(this, arguments);
1144
- };
1145
- }();
1146
-
1147
- var createTask = /*#__PURE__*/function () {
1148
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(documentId, document, localeIds, secrets) {
1149
- var accessToken, uploadFileRes, taskId, assignStatus, authorizeStatus;
1150
- return runtime_1.wrap(function _callee5$(_context5) {
1151
- while (1) {
1152
- switch (_context5.prev = _context5.next) {
1153
- case 0:
1154
- _context5.next = 2;
1130
+ _context4.next = 2;
1155
1131
  return authenticate(secrets.secret);
1156
1132
 
1157
1133
  case 2:
1158
- accessToken = _context5.sent;
1159
- _context5.next = 5;
1160
- return uploadFile(documentId, secrets.project, document, accessToken);
1134
+ accessToken = _context4.sent;
1135
+ _context4.next = 5;
1136
+ return findExistingJob(document.name, secrets.project, accessToken);
1161
1137
 
1162
1138
  case 5:
1163
- uploadFileRes = _context5.sent;
1164
- console.log('uploadFileRes', uploadFileRes);
1165
- _context5.next = 9;
1166
- return findExistingJob(documentId, secrets.project, accessToken);
1167
-
1168
- case 9:
1169
- taskId = _context5.sent;
1139
+ taskId = _context4.sent;
1170
1140
 
1171
1141
  if (taskId) {
1172
- _context5.next = 14;
1142
+ _context4.next = 10;
1173
1143
  break;
1174
1144
  }
1175
1145
 
1176
- _context5.next = 13;
1177
- return createJob(documentId, secrets.project, localeIds, accessToken);
1146
+ _context4.next = 9;
1147
+ return createJob(document.name, secrets.project, localeIds, accessToken);
1178
1148
 
1179
- case 13:
1180
- taskId = _context5.sent;
1149
+ case 9:
1150
+ taskId = _context4.sent;
1181
1151
 
1182
- case 14:
1183
- _context5.next = 16;
1184
- return assignFileToJob(taskId, documentId, secrets.project, localeIds, accessToken);
1152
+ case 10:
1153
+ _context4.next = 12;
1154
+ return createJobBatch(taskId, secrets.project, document.name, accessToken);
1185
1155
 
1186
- case 16:
1187
- assignStatus = _context5.sent;
1188
- console.log('assign status', assignStatus);
1189
- _context5.next = 20;
1190
- return authorizeJob(taskId, secrets.project, localeIds, accessToken);
1156
+ case 12:
1157
+ batchUid = _context4.sent;
1158
+ _context4.next = 15;
1159
+ return uploadFileToBatch(batchUid, document, secrets.project, localeIds, accessToken);
1191
1160
 
1192
- case 20:
1193
- authorizeStatus = _context5.sent;
1194
- console.log('authStatus', authorizeStatus);
1195
- return _context5.abrupt("return", getTranslationTask(documentId, secrets));
1161
+ case 15:
1162
+ uploadFileRes = _context4.sent;
1163
+ console.log('upload status', uploadFileRes);
1164
+ return _context4.abrupt("return", getTranslationTask(documentId, secrets));
1196
1165
 
1197
- case 23:
1166
+ case 18:
1198
1167
  case "end":
1199
- return _context5.stop();
1168
+ return _context4.stop();
1200
1169
  }
1201
1170
  }
1202
- }, _callee5);
1171
+ }, _callee4);
1203
1172
  }));
1204
1173
 
1205
- return function createTask(_x18, _x19, _x20, _x21) {
1206
- return _ref5.apply(this, arguments);
1174
+ return function createTask(_x14, _x15, _x16, _x17) {
1175
+ return _ref4.apply(this, arguments);
1207
1176
  };
1208
1177
  }();
1209
1178
 
@@ -1254,25 +1223,279 @@ var SmartlingAdapter = {
1254
1223
  getTranslation: getTranslation
1255
1224
  };
1256
1225
 
1226
+ var client = /*#__PURE__*/sanityClient.withConfig({
1227
+ apiVersion: '2021-03-25'
1228
+ }); //document fetch
1229
+
1230
+ var findLatestDraft = function findLatestDraft(documentId, ignoreI18n) {
1231
+ if (ignoreI18n === void 0) {
1232
+ ignoreI18n = true;
1233
+ }
1234
+
1235
+ //eliminates i18n versions
1236
+ var query = "*[_id match $id " + (ignoreI18n ? ' && (_id in path("drafts.*") || _id in path("*"))' : '') + "]";
1237
+ var params = {
1238
+ id: "*" + documentId
1239
+ };
1240
+ return client.fetch(query, params).then(function (docs) {
1241
+ var _docs$find;
1242
+
1243
+ return (_docs$find = docs.find(function (doc) {
1244
+ return doc._id.includes('draft');
1245
+ })) != null ? _docs$find : docs[0];
1246
+ });
1247
+ }; //revision fetch
1248
+
1249
+ var findDocumentAtRevision = /*#__PURE__*/function () {
1250
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
1251
+ var dataset, baseUrl, url, revisionDoc;
1252
+ return runtime_1.wrap(function _callee$(_context) {
1253
+ while (1) {
1254
+ switch (_context.prev = _context.next) {
1255
+ case 0:
1256
+ dataset = client.config().dataset;
1257
+ baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
1258
+ url = client.getUrl(baseUrl);
1259
+ _context.next = 5;
1260
+ return fetch(url, {
1261
+ credentials: 'include'
1262
+ }).then(function (req) {
1263
+ return req.json();
1264
+ }).then(function (req) {
1265
+ return req.documents[0];
1266
+ });
1267
+
1268
+ case 5:
1269
+ revisionDoc = _context.sent;
1270
+
1271
+ if (!(!revisionDoc || revisionDoc._rev !== rev)) {
1272
+ _context.next = 12;
1273
+ break;
1274
+ }
1275
+
1276
+ baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
1277
+ url = client.getUrl(baseUrl);
1278
+ _context.next = 11;
1279
+ return fetch(url, {
1280
+ credentials: 'include'
1281
+ }).then(function (req) {
1282
+ return req.json();
1283
+ }).then(function (req) {
1284
+ return req.documents[0];
1285
+ });
1286
+
1287
+ case 11:
1288
+ revisionDoc = _context.sent;
1289
+
1290
+ case 12:
1291
+ return _context.abrupt("return", revisionDoc);
1292
+
1293
+ case 13:
1294
+ case "end":
1295
+ return _context.stop();
1296
+ }
1297
+ }
1298
+ }, _callee);
1299
+ }));
1300
+
1301
+ return function findDocumentAtRevision(_x, _x2) {
1302
+ return _ref.apply(this, arguments);
1303
+ };
1304
+ }(); //document-level patch
1305
+
1306
+ var documentLevelPatch = /*#__PURE__*/function () {
1307
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
1308
+ var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
1309
+ return runtime_1.wrap(function _callee2$(_context2) {
1310
+ while (1) {
1311
+ switch (_context2.prev = _context2.next) {
1312
+ case 0:
1313
+ if (!translatedFields._rev) {
1314
+ _context2.next = 6;
1315
+ break;
1316
+ }
1317
+
1318
+ _context2.next = 3;
1319
+ return findDocumentAtRevision(documentId, translatedFields._rev);
1320
+
1321
+ case 3:
1322
+ baseDoc = _context2.sent;
1323
+ _context2.next = 9;
1324
+ break;
1325
+
1326
+ case 6:
1327
+ _context2.next = 8;
1328
+ return findLatestDraft(documentId);
1329
+
1330
+ case 8:
1331
+ baseDoc = _context2.sent;
1332
+
1333
+ case 9:
1334
+ merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
1335
+ targetId = "i18n." + documentId + "." + localeId;
1336
+ _context2.next = 13;
1337
+ return findLatestDraft(targetId, false);
1338
+
1339
+ case 13:
1340
+ i18nDoc = _context2.sent;
1341
+
1342
+ if (i18nDoc) {
1343
+ cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
1344
+
1345
+ Object.entries(merged).forEach(function (_ref3) {
1346
+ var key = _ref3[0],
1347
+ value = _ref3[1];
1348
+
1349
+ if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
1350
+ cleanedMerge[key] = value;
1351
+ }
1352
+ });
1353
+ client.transaction() //@ts-ignore
1354
+ .patch(i18nDoc._id, function (p) {
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;
1364
+ }
1365
+
1366
+ client.create(merged);
1367
+ }
1368
+
1369
+ case 15:
1370
+ case "end":
1371
+ return _context2.stop();
1372
+ }
1373
+ }
1374
+ }, _callee2);
1375
+ }));
1376
+
1377
+ return function documentLevelPatch(_x3, _x4, _x5) {
1378
+ return _ref2.apply(this, arguments);
1379
+ };
1380
+ }(); //field level patch
1381
+
1382
+ var fieldLevelPatch = /*#__PURE__*/function () {
1383
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
1384
+ var baseDoc, merged;
1385
+ return runtime_1.wrap(function _callee3$(_context3) {
1386
+ while (1) {
1387
+ switch (_context3.prev = _context3.next) {
1388
+ case 0:
1389
+ if (!translatedFields._rev) {
1390
+ _context3.next = 6;
1391
+ break;
1392
+ }
1393
+
1394
+ _context3.next = 3;
1395
+ return findDocumentAtRevision(documentId, translatedFields._rev);
1396
+
1397
+ case 3:
1398
+ baseDoc = _context3.sent;
1399
+ _context3.next = 9;
1400
+ break;
1401
+
1402
+ case 6:
1403
+ _context3.next = 8;
1404
+ return findLatestDraft(documentId);
1405
+
1406
+ case 8:
1407
+ baseDoc = _context3.sent;
1408
+
1409
+ case 9:
1410
+ merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
1411
+ client.patch(baseDoc._id).set(merged).commit();
1412
+
1413
+ case 11:
1414
+ case "end":
1415
+ return _context3.stop();
1416
+ }
1417
+ }
1418
+ }, _callee3);
1419
+ }));
1420
+
1421
+ return function fieldLevelPatch(_x6, _x7, _x8) {
1422
+ return _ref4.apply(this, arguments);
1423
+ };
1424
+ }();
1425
+
1257
1426
  var defaultDocumentLevelConfig = {
1258
- exportForTranslation: function exportForTranslation(id) {
1259
- return sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(id, 'document', 'en', sanityNaiveHtmlSerializer.defaultStopTypes, sanityNaiveHtmlSerializer.customSerializers);
1260
- },
1427
+ exportForTranslation: /*#__PURE__*/function () {
1428
+ var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
1429
+ var doc, serialized;
1430
+ return runtime_1.wrap(function _callee$(_context) {
1431
+ while (1) {
1432
+ switch (_context.prev = _context.next) {
1433
+ case 0:
1434
+ _context.next = 2;
1435
+ return findLatestDraft(id);
1436
+
1437
+ case 2:
1438
+ doc = _context.sent;
1439
+ serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'document'); //needed for lookup by translation tab
1440
+
1441
+ serialized.name = id;
1442
+ return _context.abrupt("return", serialized);
1443
+
1444
+ case 6:
1445
+ case "end":
1446
+ return _context.stop();
1447
+ }
1448
+ }
1449
+ }, _callee);
1450
+ }));
1451
+
1452
+ function exportForTranslation(_x) {
1453
+ return _exportForTranslation.apply(this, arguments);
1454
+ }
1455
+
1456
+ return exportForTranslation;
1457
+ }(),
1261
1458
  importTranslation: function importTranslation(id, localeId, document) {
1262
- return sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
1263
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher.documentLevelPatch(deserialized, id, localeId);
1264
- });
1459
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1460
+ documentLevelPatch(id, deserialized, localeId);
1265
1461
  },
1266
1462
  adapter: SmartlingAdapter
1267
1463
  };
1268
1464
  var defaultFieldLevelConfig = {
1269
- exportForTranslation: function exportForTranslation(id) {
1270
- return sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(id, 'field', 'en', sanityNaiveHtmlSerializer.defaultStopTypes, sanityNaiveHtmlSerializer.customSerializers);
1271
- },
1465
+ exportForTranslation: /*#__PURE__*/function () {
1466
+ var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
1467
+ var doc, serialized;
1468
+ return runtime_1.wrap(function _callee2$(_context2) {
1469
+ while (1) {
1470
+ switch (_context2.prev = _context2.next) {
1471
+ case 0:
1472
+ _context2.next = 2;
1473
+ return findLatestDraft(id);
1474
+
1475
+ case 2:
1476
+ doc = _context2.sent;
1477
+ serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'field'); //needed for lookup by translation tab
1478
+
1479
+ serialized.name = id;
1480
+ return _context2.abrupt("return", serialized);
1481
+
1482
+ case 6:
1483
+ case "end":
1484
+ return _context2.stop();
1485
+ }
1486
+ }
1487
+ }, _callee2);
1488
+ }));
1489
+
1490
+ function exportForTranslation(_x2) {
1491
+ return _exportForTranslation2.apply(this, arguments);
1492
+ }
1493
+
1494
+ return exportForTranslation;
1495
+ }(),
1272
1496
  importTranslation: function importTranslation(id, localeId, document) {
1273
- return sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
1274
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher.fieldLevelPatch(deserialized, id, localeId, 'en');
1275
- });
1497
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1498
+ fieldLevelPatch(id, deserialized, localeId);
1276
1499
  },
1277
1500
  adapter: SmartlingAdapter
1278
1501
  };
@@ -1289,10 +1512,10 @@ Object.defineProperty(exports, 'BaseDocumentDeserializer', {
1289
1512
  return sanityNaiveHtmlSerializer.BaseDocumentDeserializer;
1290
1513
  }
1291
1514
  });
1292
- Object.defineProperty(exports, 'BaseDocumentPatcher', {
1515
+ Object.defineProperty(exports, 'BaseDocumentMerger', {
1293
1516
  enumerable: true,
1294
1517
  get: function () {
1295
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher;
1518
+ return sanityNaiveHtmlSerializer.BaseDocumentMerger;
1296
1519
  }
1297
1520
  });
1298
1521
  Object.defineProperty(exports, 'BaseDocumentSerializer', {