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