sanity-plugin-transifex 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -15
- package/dist/sanity-plugin-transifex.cjs.development.js +64 -302
- package/dist/sanity-plugin-transifex.cjs.development.js.map +1 -1
- package/dist/sanity-plugin-transifex.cjs.production.min.js +1 -1
- package/dist/sanity-plugin-transifex.cjs.production.min.js.map +1 -1
- package/dist/sanity-plugin-transifex.esm.js +50 -292
- package/dist/sanity-plugin-transifex.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +21 -30
- package/src/transifexAdapter.ts +1 -0
- package/dist/helpers.d.ts +0 -5
- package/src/helpers.ts +0 -114
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, customSerializers, defaultStopTypes } from 'sanity-naive-html-serializer';
|
|
4
|
-
import sanityClient from 'part:@sanity/base/client';
|
|
1
|
+
import { baseFieldLevelConfig, baseDocumentLevelConfig } from 'sanity-translations-tab';
|
|
2
|
+
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, findLatestDraft } from 'sanity-translations-tab';
|
|
5
3
|
|
|
6
4
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
7
5
|
try {
|
|
@@ -39,6 +37,24 @@ function _asyncToGenerator(fn) {
|
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
|
|
40
|
+
function _extends() {
|
|
41
|
+
_extends = Object.assign || function (target) {
|
|
42
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
43
|
+
var source = arguments[i];
|
|
44
|
+
|
|
45
|
+
for (var key in source) {
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
47
|
+
target[key] = source[key];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return target;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return _extends.apply(this, arguments);
|
|
56
|
+
}
|
|
57
|
+
|
|
42
58
|
function createCommonjsModule(fn, module) {
|
|
43
59
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
44
60
|
}
|
|
@@ -131,9 +147,9 @@ var runtime = (function (exports) {
|
|
|
131
147
|
// This is a polyfill for %IteratorPrototype% for environments that
|
|
132
148
|
// don't natively support it.
|
|
133
149
|
var IteratorPrototype = {};
|
|
134
|
-
IteratorPrototype
|
|
150
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
135
151
|
return this;
|
|
136
|
-
};
|
|
152
|
+
});
|
|
137
153
|
|
|
138
154
|
var getProto = Object.getPrototypeOf;
|
|
139
155
|
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
@@ -147,8 +163,9 @@ var runtime = (function (exports) {
|
|
|
147
163
|
|
|
148
164
|
var Gp = GeneratorFunctionPrototype.prototype =
|
|
149
165
|
Generator.prototype = Object.create(IteratorPrototype);
|
|
150
|
-
GeneratorFunction.prototype =
|
|
151
|
-
|
|
166
|
+
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
167
|
+
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
168
|
+
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
152
169
|
GeneratorFunction.displayName = define(
|
|
153
170
|
GeneratorFunctionPrototype,
|
|
154
171
|
toStringTagSymbol,
|
|
@@ -262,9 +279,9 @@ var runtime = (function (exports) {
|
|
|
262
279
|
}
|
|
263
280
|
|
|
264
281
|
defineIteratorMethods(AsyncIterator.prototype);
|
|
265
|
-
AsyncIterator.prototype
|
|
282
|
+
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
266
283
|
return this;
|
|
267
|
-
};
|
|
284
|
+
});
|
|
268
285
|
exports.AsyncIterator = AsyncIterator;
|
|
269
286
|
|
|
270
287
|
// Note that simple async functions are implemented on top of
|
|
@@ -457,13 +474,13 @@ var runtime = (function (exports) {
|
|
|
457
474
|
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
458
475
|
// object to not be returned from this call. This ensures that doesn't happen.
|
|
459
476
|
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
460
|
-
Gp
|
|
477
|
+
define(Gp, iteratorSymbol, function() {
|
|
461
478
|
return this;
|
|
462
|
-
};
|
|
479
|
+
});
|
|
463
480
|
|
|
464
|
-
Gp
|
|
481
|
+
define(Gp, "toString", function() {
|
|
465
482
|
return "[object Generator]";
|
|
466
|
-
};
|
|
483
|
+
});
|
|
467
484
|
|
|
468
485
|
function pushTryEntry(locs) {
|
|
469
486
|
var entry = { tryLoc: locs[0] };
|
|
@@ -782,14 +799,19 @@ try {
|
|
|
782
799
|
} catch (accidentalStrictMode) {
|
|
783
800
|
// This module should not be running in strict mode, so the above
|
|
784
801
|
// assignment should always work unless something is misconfigured. Just
|
|
785
|
-
// in case runtime.js accidentally runs in strict mode,
|
|
802
|
+
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
803
|
+
// we can explicitly access globalThis. In older engines we can escape
|
|
786
804
|
// strict mode using a global Function call. This could conceivably fail
|
|
787
805
|
// if a Content Security Policy forbids using Function, but in that case
|
|
788
806
|
// the proper solution is to fix the accidental strict mode problem. If
|
|
789
807
|
// you've misconfigured your bundler to force strict mode and applied a
|
|
790
808
|
// CSP to forbid Function, and you're not willing to fix either of those
|
|
791
809
|
// problems, please detail your unique predicament in a GitHub issue.
|
|
792
|
-
|
|
810
|
+
if (typeof globalThis === "object") {
|
|
811
|
+
globalThis.regeneratorRuntime = runtime;
|
|
812
|
+
} else {
|
|
813
|
+
Function("r", "regeneratorRuntime = r")(runtime);
|
|
814
|
+
}
|
|
793
815
|
}
|
|
794
816
|
});
|
|
795
817
|
|
|
@@ -875,14 +897,13 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
875
897
|
if (res.ok) {
|
|
876
898
|
return res.json();
|
|
877
899
|
} //normal -- just means that this task doesn't exist yet.
|
|
878
|
-
else
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
}
|
|
900
|
+
else if (res.status === 404) {
|
|
901
|
+
return {
|
|
902
|
+
data: []
|
|
903
|
+
};
|
|
904
|
+
} else {
|
|
905
|
+
throw Error("Failed to retrieve tasks from Transifex. Status: " + res.status);
|
|
906
|
+
}
|
|
886
907
|
}).then(function (res) {
|
|
887
908
|
return {
|
|
888
909
|
taskId: projOrgSlug(secrets) + ":r:" + documentId,
|
|
@@ -1104,6 +1125,7 @@ var getTranslation = /*#__PURE__*/function () {
|
|
|
1104
1125
|
if (res.redirected) {
|
|
1105
1126
|
return resolve(handleFileDownload(res.url));
|
|
1106
1127
|
} else {
|
|
1128
|
+
console.log('no redirected, try again');
|
|
1107
1129
|
return res.json();
|
|
1108
1130
|
}
|
|
1109
1131
|
});
|
|
@@ -1153,279 +1175,15 @@ var TransifexAdapter = {
|
|
|
1153
1175
|
getTranslation: getTranslation
|
|
1154
1176
|
};
|
|
1155
1177
|
|
|
1156
|
-
var
|
|
1157
|
-
apiVersion: '2021-03-25'
|
|
1158
|
-
}); //document fetch
|
|
1159
|
-
|
|
1160
|
-
var findLatestDraft = function findLatestDraft(documentId) {
|
|
1161
|
-
//eliminates i18n versions
|
|
1162
|
-
var query = "*[_id == $id || _id == $draftId]";
|
|
1163
|
-
var params = {
|
|
1164
|
-
id: "" + documentId,
|
|
1165
|
-
draftId: "drafts." + documentId
|
|
1166
|
-
};
|
|
1167
|
-
return client.fetch(query, params).then(function (docs) {
|
|
1168
|
-
var _docs$find;
|
|
1169
|
-
|
|
1170
|
-
return (_docs$find = docs.find(function (doc) {
|
|
1171
|
-
return doc._id.includes('draft');
|
|
1172
|
-
})) != null ? _docs$find : docs[0];
|
|
1173
|
-
});
|
|
1174
|
-
}; //revision fetch
|
|
1175
|
-
|
|
1176
|
-
var findDocumentAtRevision = /*#__PURE__*/function () {
|
|
1177
|
-
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
|
|
1178
|
-
var dataset, baseUrl, url, revisionDoc;
|
|
1179
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1180
|
-
while (1) {
|
|
1181
|
-
switch (_context.prev = _context.next) {
|
|
1182
|
-
case 0:
|
|
1183
|
-
dataset = client.config().dataset;
|
|
1184
|
-
baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
|
|
1185
|
-
url = client.getUrl(baseUrl);
|
|
1186
|
-
_context.next = 5;
|
|
1187
|
-
return fetch(url, {
|
|
1188
|
-
credentials: 'include'
|
|
1189
|
-
}).then(function (req) {
|
|
1190
|
-
return req.json();
|
|
1191
|
-
}).then(function (req) {
|
|
1192
|
-
return req.documents[0];
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
case 5:
|
|
1196
|
-
revisionDoc = _context.sent;
|
|
1197
|
-
|
|
1198
|
-
if (!(!revisionDoc || revisionDoc._rev !== rev)) {
|
|
1199
|
-
_context.next = 12;
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
|
|
1204
|
-
url = client.getUrl(baseUrl);
|
|
1205
|
-
_context.next = 11;
|
|
1206
|
-
return fetch(url, {
|
|
1207
|
-
credentials: 'include'
|
|
1208
|
-
}).then(function (req) {
|
|
1209
|
-
return req.json();
|
|
1210
|
-
}).then(function (req) {
|
|
1211
|
-
return req.documents[0];
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
case 11:
|
|
1215
|
-
revisionDoc = _context.sent;
|
|
1216
|
-
|
|
1217
|
-
case 12:
|
|
1218
|
-
return _context.abrupt("return", revisionDoc);
|
|
1219
|
-
|
|
1220
|
-
case 13:
|
|
1221
|
-
case "end":
|
|
1222
|
-
return _context.stop();
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}, _callee);
|
|
1226
|
-
}));
|
|
1227
|
-
|
|
1228
|
-
return function findDocumentAtRevision(_x, _x2) {
|
|
1229
|
-
return _ref.apply(this, arguments);
|
|
1230
|
-
};
|
|
1231
|
-
}(); //document-level patch
|
|
1232
|
-
|
|
1233
|
-
var documentLevelPatch = /*#__PURE__*/function () {
|
|
1234
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
|
|
1235
|
-
var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
|
|
1236
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1237
|
-
while (1) {
|
|
1238
|
-
switch (_context2.prev = _context2.next) {
|
|
1239
|
-
case 0:
|
|
1240
|
-
if (!translatedFields._rev) {
|
|
1241
|
-
_context2.next = 6;
|
|
1242
|
-
break;
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
_context2.next = 3;
|
|
1246
|
-
return findDocumentAtRevision(documentId, translatedFields._rev);
|
|
1247
|
-
|
|
1248
|
-
case 3:
|
|
1249
|
-
baseDoc = _context2.sent;
|
|
1250
|
-
_context2.next = 9;
|
|
1251
|
-
break;
|
|
1252
|
-
|
|
1253
|
-
case 6:
|
|
1254
|
-
_context2.next = 8;
|
|
1255
|
-
return findLatestDraft(documentId);
|
|
1256
|
-
|
|
1257
|
-
case 8:
|
|
1258
|
-
baseDoc = _context2.sent;
|
|
1259
|
-
|
|
1260
|
-
case 9:
|
|
1261
|
-
merged = BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
|
|
1262
|
-
targetId = "i18n." + documentId + "." + localeId;
|
|
1263
|
-
_context2.next = 13;
|
|
1264
|
-
return findLatestDraft(targetId);
|
|
1265
|
-
|
|
1266
|
-
case 13:
|
|
1267
|
-
i18nDoc = _context2.sent;
|
|
1268
|
-
|
|
1269
|
-
if (i18nDoc) {
|
|
1270
|
-
cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
|
|
1271
|
-
|
|
1272
|
-
Object.entries(merged).forEach(function (_ref3) {
|
|
1273
|
-
var key = _ref3[0],
|
|
1274
|
-
value = _ref3[1];
|
|
1275
|
-
|
|
1276
|
-
if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
|
|
1277
|
-
cleanedMerge[key] = value;
|
|
1278
|
-
}
|
|
1279
|
-
});
|
|
1280
|
-
client.transaction() //@ts-ignore
|
|
1281
|
-
.patch(i18nDoc._id, function (p) {
|
|
1282
|
-
return p.set(cleanedMerge);
|
|
1283
|
-
}).commit();
|
|
1284
|
-
} else {
|
|
1285
|
-
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1286
|
-
|
|
1287
|
-
if (baseDoc._lang) {
|
|
1288
|
-
merged._lang = localeId;
|
|
1289
|
-
} else if (baseDoc.__i18n_lang) {
|
|
1290
|
-
merged.__i18n_lang = localeId;
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
client.create(merged);
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
case 15:
|
|
1297
|
-
case "end":
|
|
1298
|
-
return _context2.stop();
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
}, _callee2);
|
|
1302
|
-
}));
|
|
1303
|
-
|
|
1304
|
-
return function documentLevelPatch(_x3, _x4, _x5) {
|
|
1305
|
-
return _ref2.apply(this, arguments);
|
|
1306
|
-
};
|
|
1307
|
-
}(); //field level patch
|
|
1308
|
-
|
|
1309
|
-
var fieldLevelPatch = /*#__PURE__*/function () {
|
|
1310
|
-
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
|
|
1311
|
-
var baseDoc, merged;
|
|
1312
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1313
|
-
while (1) {
|
|
1314
|
-
switch (_context3.prev = _context3.next) {
|
|
1315
|
-
case 0:
|
|
1316
|
-
if (!translatedFields._rev) {
|
|
1317
|
-
_context3.next = 6;
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
_context3.next = 3;
|
|
1322
|
-
return findDocumentAtRevision(documentId, translatedFields._rev);
|
|
1323
|
-
|
|
1324
|
-
case 3:
|
|
1325
|
-
baseDoc = _context3.sent;
|
|
1326
|
-
_context3.next = 9;
|
|
1327
|
-
break;
|
|
1328
|
-
|
|
1329
|
-
case 6:
|
|
1330
|
-
_context3.next = 8;
|
|
1331
|
-
return findLatestDraft(documentId);
|
|
1332
|
-
|
|
1333
|
-
case 8:
|
|
1334
|
-
baseDoc = _context3.sent;
|
|
1335
|
-
|
|
1336
|
-
case 9:
|
|
1337
|
-
merged = BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
|
|
1338
|
-
client.patch(baseDoc._id).set(merged).commit();
|
|
1339
|
-
|
|
1340
|
-
case 11:
|
|
1341
|
-
case "end":
|
|
1342
|
-
return _context3.stop();
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}, _callee3);
|
|
1346
|
-
}));
|
|
1347
|
-
|
|
1348
|
-
return function fieldLevelPatch(_x6, _x7, _x8) {
|
|
1349
|
-
return _ref4.apply(this, arguments);
|
|
1350
|
-
};
|
|
1351
|
-
}();
|
|
1352
|
-
|
|
1353
|
-
var defaultDocumentLevelConfig = {
|
|
1354
|
-
exportForTranslation: /*#__PURE__*/function () {
|
|
1355
|
-
var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
|
|
1356
|
-
var doc, serialized;
|
|
1357
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1358
|
-
while (1) {
|
|
1359
|
-
switch (_context.prev = _context.next) {
|
|
1360
|
-
case 0:
|
|
1361
|
-
_context.next = 2;
|
|
1362
|
-
return findLatestDraft(id);
|
|
1363
|
-
|
|
1364
|
-
case 2:
|
|
1365
|
-
doc = _context.sent;
|
|
1366
|
-
serialized = BaseDocumentSerializer.serializeDocument(doc, 'document');
|
|
1367
|
-
serialized.name = id;
|
|
1368
|
-
return _context.abrupt("return", serialized);
|
|
1369
|
-
|
|
1370
|
-
case 6:
|
|
1371
|
-
case "end":
|
|
1372
|
-
return _context.stop();
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}, _callee);
|
|
1376
|
-
}));
|
|
1377
|
-
|
|
1378
|
-
function exportForTranslation(_x) {
|
|
1379
|
-
return _exportForTranslation.apply(this, arguments);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
return exportForTranslation;
|
|
1383
|
-
}(),
|
|
1384
|
-
importTranslation: function importTranslation(id, localeId, document) {
|
|
1385
|
-
var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
|
|
1386
|
-
documentLevelPatch(id, deserialized, localeId);
|
|
1387
|
-
},
|
|
1178
|
+
var defaultDocumentLevelConfig = /*#__PURE__*/_extends({}, baseDocumentLevelConfig, {
|
|
1388
1179
|
adapter: TransifexAdapter,
|
|
1389
1180
|
secretsNamespace: 'transifex'
|
|
1390
|
-
};
|
|
1391
|
-
var defaultFieldLevelConfig = {
|
|
1392
|
-
exportForTranslation: /*#__PURE__*/function () {
|
|
1393
|
-
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
|
|
1394
|
-
var doc, serialized;
|
|
1395
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1396
|
-
while (1) {
|
|
1397
|
-
switch (_context2.prev = _context2.next) {
|
|
1398
|
-
case 0:
|
|
1399
|
-
_context2.next = 2;
|
|
1400
|
-
return findLatestDraft(id);
|
|
1401
|
-
|
|
1402
|
-
case 2:
|
|
1403
|
-
doc = _context2.sent;
|
|
1404
|
-
serialized = BaseDocumentSerializer.serializeDocument(doc, 'field');
|
|
1405
|
-
serialized.name = id;
|
|
1406
|
-
return _context2.abrupt("return", serialized);
|
|
1407
|
-
|
|
1408
|
-
case 6:
|
|
1409
|
-
case "end":
|
|
1410
|
-
return _context2.stop();
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}, _callee2);
|
|
1414
|
-
}));
|
|
1415
|
-
|
|
1416
|
-
function exportForTranslation(_x2) {
|
|
1417
|
-
return _exportForTranslation2.apply(this, arguments);
|
|
1418
|
-
}
|
|
1181
|
+
});
|
|
1419
1182
|
|
|
1420
|
-
|
|
1421
|
-
}(),
|
|
1422
|
-
importTranslation: function importTranslation(id, localeId, document) {
|
|
1423
|
-
var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
|
|
1424
|
-
fieldLevelPatch(id, deserialized, localeId);
|
|
1425
|
-
},
|
|
1183
|
+
var defaultFieldLevelConfig = /*#__PURE__*/_extends({}, baseFieldLevelConfig, {
|
|
1426
1184
|
adapter: TransifexAdapter,
|
|
1427
1185
|
secretsNamespace: 'transifex'
|
|
1428
|
-
};
|
|
1186
|
+
});
|
|
1429
1187
|
|
|
1430
1188
|
export { TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig };
|
|
1431
1189
|
//# sourceMappingURL=sanity-plugin-transifex.esm.js.map
|