sanity-plugin-studio-smartling 1.0.11 → 1.2.1

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