sanity-plugin-studio-smartling 1.0.1 → 1.2.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,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 {
@@ -149,9 +152,9 @@ var runtime = (function (exports) {
149
152
  // This is a polyfill for %IteratorPrototype% for environments that
150
153
  // don't natively support it.
151
154
  var IteratorPrototype = {};
152
- IteratorPrototype[iteratorSymbol] = function () {
155
+ define(IteratorPrototype, iteratorSymbol, function () {
153
156
  return this;
154
- };
157
+ });
155
158
 
156
159
  var getProto = Object.getPrototypeOf;
157
160
  var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
@@ -165,8 +168,9 @@ var runtime = (function (exports) {
165
168
 
166
169
  var Gp = GeneratorFunctionPrototype.prototype =
167
170
  Generator.prototype = Object.create(IteratorPrototype);
168
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
169
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
171
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
172
+ define(Gp, "constructor", GeneratorFunctionPrototype);
173
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
170
174
  GeneratorFunction.displayName = define(
171
175
  GeneratorFunctionPrototype,
172
176
  toStringTagSymbol,
@@ -280,9 +284,9 @@ var runtime = (function (exports) {
280
284
  }
281
285
 
282
286
  defineIteratorMethods(AsyncIterator.prototype);
283
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
287
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
284
288
  return this;
285
- };
289
+ });
286
290
  exports.AsyncIterator = AsyncIterator;
287
291
 
288
292
  // Note that simple async functions are implemented on top of
@@ -475,13 +479,13 @@ var runtime = (function (exports) {
475
479
  // iterator prototype chain incorrectly implement this, causing the Generator
476
480
  // object to not be returned from this call. This ensures that doesn't happen.
477
481
  // See https://github.com/facebook/regenerator/issues/274 for more details.
478
- Gp[iteratorSymbol] = function() {
482
+ define(Gp, iteratorSymbol, function() {
479
483
  return this;
480
- };
484
+ });
481
485
 
482
- Gp.toString = function() {
486
+ define(Gp, "toString", function() {
483
487
  return "[object Generator]";
484
- };
488
+ });
485
489
 
486
490
  function pushTryEntry(locs) {
487
491
  var entry = { tryLoc: locs[0] };
@@ -800,14 +804,19 @@ try {
800
804
  } catch (accidentalStrictMode) {
801
805
  // This module should not be running in strict mode, so the above
802
806
  // assignment should always work unless something is misconfigured. Just
803
- // in case runtime.js accidentally runs in strict mode, we can escape
807
+ // in case runtime.js accidentally runs in strict mode, in modern engines
808
+ // we can explicitly access globalThis. In older engines we can escape
804
809
  // strict mode using a global Function call. This could conceivably fail
805
810
  // if a Content Security Policy forbids using Function, but in that case
806
811
  // the proper solution is to fix the accidental strict mode problem. If
807
812
  // you've misconfigured your bundler to force strict mode and applied a
808
813
  // CSP to forbid Function, and you're not willing to fix either of those
809
814
  // problems, please detail your unique predicament in a GitHub issue.
810
- Function("r", "regeneratorRuntime = r")(runtime);
815
+ if (typeof globalThis === "object") {
816
+ globalThis.regeneratorRuntime = runtime;
817
+ } else {
818
+ Function("r", "regeneratorRuntime = r")(runtime);
819
+ }
811
820
  }
812
821
  });
813
822
 
@@ -970,7 +979,7 @@ var getTranslationTask = /*#__PURE__*/function () {
970
979
  locales = smartlingTask.contentProgressReport.map(function (item) {
971
980
  return {
972
981
  localeId: item.targetLocaleId,
973
- progress: item.progress.percentComplete
982
+ progress: item.progress ? item.progress.percentComplete : 0
974
983
  };
975
984
  });
976
985
  }
@@ -995,28 +1004,30 @@ var getTranslationTask = /*#__PURE__*/function () {
995
1004
  };
996
1005
  }();
997
1006
 
998
- var uploadFile = /*#__PURE__*/function () {
999
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, projectId, document, accessToken) {
1000
- 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;
1001
1010
  return runtime_1.wrap(function _callee$(_context) {
1002
1011
  while (1) {
1003
1012
  switch (_context.prev = _context.next) {
1004
1013
  case 0:
1005
- url = "https://api.smartling.com/files-api/v2/projects/" + projectId + "/file";
1006
- formData = new FormData();
1007
- formData.append('fileUri', documentId);
1008
- formData.append('fileType', 'html');
1009
- htmlBuffer = Buffer.from(document.content, 'utf-8');
1010
- formData.append('file', new Blob([htmlBuffer]), document.name + ".html");
1014
+ url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs";
1011
1015
  return _context.abrupt("return", fetch(smartlingProxy, {
1012
1016
  method: 'POST',
1013
- headers: getHeaders(url, accessToken),
1014
- 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
+ })
1015
1024
  }).then(function (res) {
1016
1025
  return res.json();
1026
+ }).then(function (res) {
1027
+ return res.response.data.translationJobUid;
1017
1028
  }));
1018
1029
 
1019
- case 7:
1030
+ case 2:
1020
1031
  case "end":
1021
1032
  return _context.stop();
1022
1033
  }
@@ -1024,32 +1035,39 @@ var uploadFile = /*#__PURE__*/function () {
1024
1035
  }, _callee);
1025
1036
  }));
1026
1037
 
1027
- return function uploadFile(_x, _x2, _x3, _x4) {
1038
+ return function createJob(_x, _x2, _x3, _x4) {
1028
1039
  return _ref.apply(this, arguments);
1029
1040
  };
1030
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
+ */
1031
1047
 
1032
- var assignFileToJob = /*#__PURE__*/function () {
1033
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, documentId, projectId, localeIds, accessToken) {
1048
+
1049
+ var createJobBatch = /*#__PURE__*/function () {
1050
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(jobId, projectId, documentName, accessToken) {
1034
1051
  var url;
1035
1052
  return runtime_1.wrap(function _callee2$(_context2) {
1036
1053
  while (1) {
1037
1054
  switch (_context2.prev = _context2.next) {
1038
1055
  case 0:
1039
- 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";
1040
1057
  return _context2.abrupt("return", fetch(smartlingProxy, {
1041
1058
  method: 'POST',
1042
1059
  headers: _extends({}, getHeaders(url, accessToken), {
1043
1060
  'content-type': 'application/json'
1044
1061
  }),
1045
1062
  body: JSON.stringify({
1046
- fileUri: documentId,
1047
- targetLocaleIds: localeIds
1063
+ authorize: true,
1064
+ translationJobUid: jobId,
1065
+ fileUris: [documentName]
1048
1066
  })
1049
1067
  }).then(function (res) {
1050
1068
  return res.json();
1051
1069
  }).then(function (res) {
1052
- return res.response;
1070
+ return res.response.data.batchUid;
1053
1071
  }));
1054
1072
 
1055
1073
  case 2:
@@ -1060,35 +1078,36 @@ var assignFileToJob = /*#__PURE__*/function () {
1060
1078
  }, _callee2);
1061
1079
  }));
1062
1080
 
1063
- return function assignFileToJob(_x5, _x6, _x7, _x8, _x9) {
1081
+ return function createJobBatch(_x5, _x6, _x7, _x8) {
1064
1082
  return _ref2.apply(this, arguments);
1065
1083
  };
1066
1084
  }();
1067
1085
 
1068
- var createJob = /*#__PURE__*/function () {
1069
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, projectId, localeIds, accessToken) {
1070
- 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;
1071
1089
  return runtime_1.wrap(function _callee3$(_context3) {
1072
1090
  while (1) {
1073
1091
  switch (_context3.prev = _context3.next) {
1074
1092
  case 0:
1075
- 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
+ });
1076
1102
  return _context3.abrupt("return", fetch(smartlingProxy, {
1077
1103
  method: 'POST',
1078
- headers: _extends({}, getHeaders(url, accessToken), {
1079
- 'content-type': 'application/json'
1080
- }),
1081
- body: JSON.stringify({
1082
- jobName: documentId,
1083
- targetLocaleIds: localeIds
1084
- })
1104
+ headers: getHeaders(url, accessToken),
1105
+ body: formData
1085
1106
  }).then(function (res) {
1086
1107
  return res.json();
1087
- }).then(function (res) {
1088
- return res.response.data.translationJobUid;
1089
1108
  }));
1090
1109
 
1091
- case 2:
1110
+ case 8:
1092
1111
  case "end":
1093
1112
  return _context3.stop();
1094
1113
  }
@@ -1096,108 +1115,64 @@ var createJob = /*#__PURE__*/function () {
1096
1115
  }, _callee3);
1097
1116
  }));
1098
1117
 
1099
- return function createJob(_x10, _x11, _x12, _x13) {
1118
+ return function uploadFileToBatch(_x9, _x10, _x11, _x12, _x13) {
1100
1119
  return _ref3.apply(this, arguments);
1101
1120
  };
1102
1121
  }();
1103
1122
 
1104
- var authorizeJob = /*#__PURE__*/function () {
1105
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(jobId, projectId, localeIds, accessToken) {
1106
- 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;
1107
1126
  return runtime_1.wrap(function _callee4$(_context4) {
1108
1127
  while (1) {
1109
1128
  switch (_context4.prev = _context4.next) {
1110
1129
  case 0:
1111
- url = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs/" + jobId + "/authorize";
1112
- return _context4.abrupt("return", fetch(smartlingProxy, {
1113
- method: 'POST',
1114
- headers: _extends({}, getHeaders(url, accessToken), {
1115
- 'content-type': 'application/json'
1116
- }),
1117
- body: JSON.stringify({
1118
- localeWorkflows: localeIds.map(function (l) {
1119
- return {
1120
- targetLocaleId: l
1121
- };
1122
- })
1123
- })
1124
- }).then(function (res) {
1125
- return res.json();
1126
- }));
1127
-
1128
- case 2:
1129
- case "end":
1130
- return _context4.stop();
1131
- }
1132
- }
1133
- }, _callee4);
1134
- }));
1135
-
1136
- return function authorizeJob(_x14, _x15, _x16, _x17) {
1137
- return _ref4.apply(this, arguments);
1138
- };
1139
- }();
1140
-
1141
- var createTask = /*#__PURE__*/function () {
1142
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(documentId, document, localeIds, secrets) {
1143
- var accessToken, uploadFileRes, taskId, assignStatus, authorizeStatus;
1144
- return runtime_1.wrap(function _callee5$(_context5) {
1145
- while (1) {
1146
- switch (_context5.prev = _context5.next) {
1147
- case 0:
1148
- _context5.next = 2;
1130
+ _context4.next = 2;
1149
1131
  return authenticate(secrets.secret);
1150
1132
 
1151
1133
  case 2:
1152
- accessToken = _context5.sent;
1153
- _context5.next = 5;
1154
- return uploadFile(documentId, secrets.project, document, accessToken);
1134
+ accessToken = _context4.sent;
1135
+ _context4.next = 5;
1136
+ return findExistingJob(document.name, secrets.project, accessToken);
1155
1137
 
1156
1138
  case 5:
1157
- uploadFileRes = _context5.sent;
1158
- console.log('uploadFileRes', uploadFileRes);
1159
- _context5.next = 9;
1160
- return findExistingJob(documentId, secrets.project, accessToken);
1161
-
1162
- case 9:
1163
- taskId = _context5.sent;
1139
+ taskId = _context4.sent;
1164
1140
 
1165
1141
  if (taskId) {
1166
- _context5.next = 14;
1142
+ _context4.next = 10;
1167
1143
  break;
1168
1144
  }
1169
1145
 
1170
- _context5.next = 13;
1171
- return createJob(documentId, secrets.project, localeIds, accessToken);
1146
+ _context4.next = 9;
1147
+ return createJob(document.name, secrets.project, localeIds, accessToken);
1172
1148
 
1173
- case 13:
1174
- taskId = _context5.sent;
1149
+ case 9:
1150
+ taskId = _context4.sent;
1175
1151
 
1176
- case 14:
1177
- _context5.next = 16;
1178
- return assignFileToJob(taskId, documentId, secrets.project, localeIds, accessToken);
1152
+ case 10:
1153
+ _context4.next = 12;
1154
+ return createJobBatch(taskId, secrets.project, document.name, accessToken);
1179
1155
 
1180
- case 16:
1181
- assignStatus = _context5.sent;
1182
- console.log('assign status', assignStatus);
1183
- _context5.next = 20;
1184
- 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);
1185
1160
 
1186
- case 20:
1187
- authorizeStatus = _context5.sent;
1188
- console.log('authStatus', authorizeStatus);
1189
- 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));
1190
1165
 
1191
- case 23:
1166
+ case 18:
1192
1167
  case "end":
1193
- return _context5.stop();
1168
+ return _context4.stop();
1194
1169
  }
1195
1170
  }
1196
- }, _callee5);
1171
+ }, _callee4);
1197
1172
  }));
1198
1173
 
1199
- return function createTask(_x18, _x19, _x20, _x21) {
1200
- return _ref5.apply(this, arguments);
1174
+ return function createTask(_x14, _x15, _x16, _x17) {
1175
+ return _ref4.apply(this, arguments);
1201
1176
  };
1202
1177
  }();
1203
1178
 
@@ -1248,25 +1223,279 @@ var SmartlingAdapter = {
1248
1223
  getTranslation: getTranslation
1249
1224
  };
1250
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
+
1251
1426
  var defaultDocumentLevelConfig = {
1252
- exportForTranslation: function exportForTranslation(id) {
1253
- return sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(id, 'document', 'en', sanityNaiveHtmlSerializer.defaultStopTypes, sanityNaiveHtmlSerializer.customSerializers);
1254
- },
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
+ }(),
1255
1458
  importTranslation: function importTranslation(id, localeId, document) {
1256
- return sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
1257
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher.documentLevelPatch(deserialized, id, localeId);
1258
- });
1459
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1460
+ documentLevelPatch(id, deserialized, localeId);
1259
1461
  },
1260
1462
  adapter: SmartlingAdapter
1261
1463
  };
1262
1464
  var defaultFieldLevelConfig = {
1263
- exportForTranslation: function exportForTranslation(id) {
1264
- return sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(id, 'field', 'en', sanityNaiveHtmlSerializer.defaultStopTypes, sanityNaiveHtmlSerializer.customSerializers);
1265
- },
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
+ }(),
1266
1496
  importTranslation: function importTranslation(id, localeId, document) {
1267
- return sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(id, document).then(function (deserialized) {
1268
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher.fieldLevelPatch(deserialized, id, localeId, 'en');
1269
- });
1497
+ var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1498
+ fieldLevelPatch(id, deserialized, localeId);
1270
1499
  },
1271
1500
  adapter: SmartlingAdapter
1272
1501
  };
@@ -1283,10 +1512,10 @@ Object.defineProperty(exports, 'BaseDocumentDeserializer', {
1283
1512
  return sanityNaiveHtmlSerializer.BaseDocumentDeserializer;
1284
1513
  }
1285
1514
  });
1286
- Object.defineProperty(exports, 'BaseDocumentPatcher', {
1515
+ Object.defineProperty(exports, 'BaseDocumentMerger', {
1287
1516
  enumerable: true,
1288
1517
  get: function () {
1289
- return sanityNaiveHtmlSerializer.BaseDocumentPatcher;
1518
+ return sanityNaiveHtmlSerializer.BaseDocumentMerger;
1290
1519
  }
1291
1520
  });
1292
1521
  Object.defineProperty(exports, 'BaseDocumentSerializer', {