sanity-plugin-transifex 1.1.1 → 2.0.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.
@@ -2,818 +2,424 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
5
  var sanityTranslationsTab = require('sanity-translations-tab');
8
- var sanityNaiveHtmlSerializer = require('sanity-naive-html-serializer');
9
- var sanityClient = _interopDefault(require('part:@sanity/base/client'));
10
-
11
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
12
- try {
13
- var info = gen[key](arg);
14
- var value = info.value;
15
- } catch (error) {
16
- reject(error);
17
- return;
18
- }
19
-
20
- if (info.done) {
21
- resolve(value);
22
- } else {
23
- Promise.resolve(value).then(_next, _throw);
24
- }
25
- }
26
-
27
- function _asyncToGenerator(fn) {
28
- return function () {
29
- var self = this,
30
- args = arguments;
31
- return new Promise(function (resolve, reject) {
32
- var gen = fn.apply(self, args);
33
6
 
34
- function _next(value) {
35
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
36
- }
37
-
38
- function _throw(err) {
39
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
40
- }
7
+ function _regeneratorRuntime() {
8
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
41
9
 
42
- _next(undefined);
43
- });
10
+ _regeneratorRuntime = function () {
11
+ return exports;
44
12
  };
45
- }
46
-
47
- function createCommonjsModule(fn, module) {
48
- return module = { exports: {} }, fn(module, module.exports), module.exports;
49
- }
50
13
 
51
- var runtime_1 = createCommonjsModule(function (module) {
52
- /**
53
- * Copyright (c) 2014-present, Facebook, Inc.
54
- *
55
- * This source code is licensed under the MIT license found in the
56
- * LICENSE file in the root directory of this source tree.
57
- */
58
-
59
- var runtime = (function (exports) {
60
-
61
- var Op = Object.prototype;
62
- var hasOwn = Op.hasOwnProperty;
63
- var undefined$1; // More compressible than void 0.
64
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
65
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
66
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
67
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
14
+ var exports = {},
15
+ Op = Object.prototype,
16
+ hasOwn = Op.hasOwnProperty,
17
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
18
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
19
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
20
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
68
21
 
69
22
  function define(obj, key, value) {
70
- Object.defineProperty(obj, key, {
23
+ return Object.defineProperty(obj, key, {
71
24
  value: value,
72
- enumerable: true,
73
- configurable: true,
74
- writable: true
75
- });
76
- return obj[key];
25
+ enumerable: !0,
26
+ configurable: !0,
27
+ writable: !0
28
+ }), obj[key];
77
29
  }
30
+
78
31
  try {
79
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
80
32
  define({}, "");
81
33
  } catch (err) {
82
- define = function(obj, key, value) {
34
+ define = function (obj, key, value) {
83
35
  return obj[key] = value;
84
36
  };
85
37
  }
86
38
 
87
39
  function wrap(innerFn, outerFn, self, tryLocsList) {
88
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
89
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
90
- var generator = Object.create(protoGenerator.prototype);
91
- var context = new Context(tryLocsList || []);
40
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
41
+ generator = Object.create(protoGenerator.prototype),
42
+ context = new Context(tryLocsList || []);
43
+ return generator._invoke = function (innerFn, self, context) {
44
+ var state = "suspendedStart";
45
+ return function (method, arg) {
46
+ if ("executing" === state) throw new Error("Generator is already running");
47
+
48
+ if ("completed" === state) {
49
+ if ("throw" === method) throw arg;
50
+ return doneResult();
51
+ }
52
+
53
+ for (context.method = method, context.arg = arg;;) {
54
+ var delegate = context.delegate;
55
+
56
+ if (delegate) {
57
+ var delegateResult = maybeInvokeDelegate(delegate, context);
58
+
59
+ if (delegateResult) {
60
+ if (delegateResult === ContinueSentinel) continue;
61
+ return delegateResult;
62
+ }
63
+ }
92
64
 
93
- // The ._invoke method unifies the implementations of the .next,
94
- // .throw, and .return methods.
95
- generator._invoke = makeInvokeMethod(innerFn, self, context);
65
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
66
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
67
+ context.dispatchException(context.arg);
68
+ } else "return" === context.method && context.abrupt("return", context.arg);
69
+ state = "executing";
70
+ var record = tryCatch(innerFn, self, context);
71
+
72
+ if ("normal" === record.type) {
73
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
74
+ return {
75
+ value: record.arg,
76
+ done: context.done
77
+ };
78
+ }
96
79
 
97
- return generator;
80
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
81
+ }
82
+ };
83
+ }(innerFn, self, context), generator;
98
84
  }
99
- exports.wrap = wrap;
100
85
 
101
- // Try/catch helper to minimize deoptimizations. Returns a completion
102
- // record like context.tryEntries[i].completion. This interface could
103
- // have been (and was previously) designed to take a closure to be
104
- // invoked without arguments, but in all the cases we care about we
105
- // already have an existing method we want to call, so there's no need
106
- // to create a new function object. We can even get away with assuming
107
- // the method takes exactly one argument, since that happens to be true
108
- // in every case, so we don't have to touch the arguments object. The
109
- // only additional allocation required is the completion record, which
110
- // has a stable shape and so hopefully should be cheap to allocate.
111
86
  function tryCatch(fn, obj, arg) {
112
87
  try {
113
- return { type: "normal", arg: fn.call(obj, arg) };
88
+ return {
89
+ type: "normal",
90
+ arg: fn.call(obj, arg)
91
+ };
114
92
  } catch (err) {
115
- return { type: "throw", arg: err };
93
+ return {
94
+ type: "throw",
95
+ arg: err
96
+ };
116
97
  }
117
98
  }
118
99
 
119
- var GenStateSuspendedStart = "suspendedStart";
120
- var GenStateSuspendedYield = "suspendedYield";
121
- var GenStateExecuting = "executing";
122
- var GenStateCompleted = "completed";
123
-
124
- // Returning this object from the innerFn has the same effect as
125
- // breaking out of the dispatch switch statement.
100
+ exports.wrap = wrap;
126
101
  var ContinueSentinel = {};
127
102
 
128
- // Dummy constructor functions that we use as the .constructor and
129
- // .constructor.prototype properties for functions that return Generator
130
- // objects. For full spec compliance, you may wish to configure your
131
- // minifier not to mangle the names of these two functions.
132
103
  function Generator() {}
104
+
133
105
  function GeneratorFunction() {}
106
+
134
107
  function GeneratorFunctionPrototype() {}
135
108
 
136
- // This is a polyfill for %IteratorPrototype% for environments that
137
- // don't natively support it.
138
109
  var IteratorPrototype = {};
139
- IteratorPrototype[iteratorSymbol] = function () {
110
+ define(IteratorPrototype, iteratorSymbol, function () {
140
111
  return this;
141
- };
142
-
143
- var getProto = Object.getPrototypeOf;
144
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
145
- if (NativeIteratorPrototype &&
146
- NativeIteratorPrototype !== Op &&
147
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
148
- // This environment has a native %IteratorPrototype%; use it instead
149
- // of the polyfill.
150
- IteratorPrototype = NativeIteratorPrototype;
151
- }
112
+ });
113
+ var getProto = Object.getPrototypeOf,
114
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
115
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
116
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
152
117
 
153
- var Gp = GeneratorFunctionPrototype.prototype =
154
- Generator.prototype = Object.create(IteratorPrototype);
155
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
156
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
157
- GeneratorFunction.displayName = define(
158
- GeneratorFunctionPrototype,
159
- toStringTagSymbol,
160
- "GeneratorFunction"
161
- );
162
-
163
- // Helper for defining the .next, .throw, and .return methods of the
164
- // Iterator interface in terms of a single ._invoke method.
165
118
  function defineIteratorMethods(prototype) {
166
- ["next", "throw", "return"].forEach(function(method) {
167
- define(prototype, method, function(arg) {
119
+ ["next", "throw", "return"].forEach(function (method) {
120
+ define(prototype, method, function (arg) {
168
121
  return this._invoke(method, arg);
169
122
  });
170
123
  });
171
124
  }
172
125
 
173
- exports.isGeneratorFunction = function(genFun) {
174
- var ctor = typeof genFun === "function" && genFun.constructor;
175
- return ctor
176
- ? ctor === GeneratorFunction ||
177
- // For the native GeneratorFunction constructor, the best we can
178
- // do is to check its .name property.
179
- (ctor.displayName || ctor.name) === "GeneratorFunction"
180
- : false;
181
- };
182
-
183
- exports.mark = function(genFun) {
184
- if (Object.setPrototypeOf) {
185
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
186
- } else {
187
- genFun.__proto__ = GeneratorFunctionPrototype;
188
- define(genFun, toStringTagSymbol, "GeneratorFunction");
189
- }
190
- genFun.prototype = Object.create(Gp);
191
- return genFun;
192
- };
193
-
194
- // Within the body of any async function, `await x` is transformed to
195
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
196
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
197
- // meant to be awaited.
198
- exports.awrap = function(arg) {
199
- return { __await: arg };
200
- };
201
-
202
126
  function AsyncIterator(generator, PromiseImpl) {
203
127
  function invoke(method, arg, resolve, reject) {
204
128
  var record = tryCatch(generator[method], generator, arg);
205
- if (record.type === "throw") {
206
- reject(record.arg);
207
- } else {
208
- var result = record.arg;
209
- var value = result.value;
210
- if (value &&
211
- typeof value === "object" &&
212
- hasOwn.call(value, "__await")) {
213
- return PromiseImpl.resolve(value.__await).then(function(value) {
214
- invoke("next", value, resolve, reject);
215
- }, function(err) {
216
- invoke("throw", err, resolve, reject);
217
- });
218
- }
219
129
 
220
- return PromiseImpl.resolve(value).then(function(unwrapped) {
221
- // When a yielded Promise is resolved, its final value becomes
222
- // the .value of the Promise<{value,done}> result for the
223
- // current iteration.
224
- result.value = unwrapped;
225
- resolve(result);
226
- }, function(error) {
227
- // If a rejected Promise was yielded, throw the rejection back
228
- // into the async generator function so it can be handled there.
130
+ if ("throw" !== record.type) {
131
+ var result = record.arg,
132
+ value = result.value;
133
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
134
+ invoke("next", value, resolve, reject);
135
+ }, function (err) {
136
+ invoke("throw", err, resolve, reject);
137
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
138
+ result.value = unwrapped, resolve(result);
139
+ }, function (error) {
229
140
  return invoke("throw", error, resolve, reject);
230
141
  });
231
142
  }
143
+
144
+ reject(record.arg);
232
145
  }
233
146
 
234
147
  var previousPromise;
235
148
 
236
- function enqueue(method, arg) {
149
+ this._invoke = function (method, arg) {
237
150
  function callInvokeWithMethodAndArg() {
238
- return new PromiseImpl(function(resolve, reject) {
151
+ return new PromiseImpl(function (resolve, reject) {
239
152
  invoke(method, arg, resolve, reject);
240
153
  });
241
154
  }
242
155
 
243
- return previousPromise =
244
- // If enqueue has been called before, then we want to wait until
245
- // all previous Promises have been resolved before calling invoke,
246
- // so that results are always delivered in the correct order. If
247
- // enqueue has not been called before, then it is important to
248
- // call invoke immediately, without waiting on a callback to fire,
249
- // so that the async generator function has the opportunity to do
250
- // any necessary setup in a predictable way. This predictability
251
- // is why the Promise constructor synchronously invokes its
252
- // executor callback, and why async functions synchronously
253
- // execute code before the first await. Since we implement simple
254
- // async functions in terms of async generators, it is especially
255
- // important to get this right, even though it requires care.
256
- previousPromise ? previousPromise.then(
257
- callInvokeWithMethodAndArg,
258
- // Avoid propagating failures to Promises returned by later
259
- // invocations of the iterator.
260
- callInvokeWithMethodAndArg
261
- ) : callInvokeWithMethodAndArg();
262
- }
263
-
264
- // Define the unified helper method that is used to implement .next,
265
- // .throw, and .return (see defineIteratorMethods).
266
- this._invoke = enqueue;
267
- }
268
-
269
- defineIteratorMethods(AsyncIterator.prototype);
270
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
271
- return this;
272
- };
273
- exports.AsyncIterator = AsyncIterator;
274
-
275
- // Note that simple async functions are implemented on top of
276
- // AsyncIterator objects; they just return a Promise for the value of
277
- // the final result produced by the iterator.
278
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
279
- if (PromiseImpl === void 0) PromiseImpl = Promise;
280
-
281
- var iter = new AsyncIterator(
282
- wrap(innerFn, outerFn, self, tryLocsList),
283
- PromiseImpl
284
- );
285
-
286
- return exports.isGeneratorFunction(outerFn)
287
- ? iter // If outerFn is a generator, return the full iterator.
288
- : iter.next().then(function(result) {
289
- return result.done ? result.value : iter.next();
290
- });
291
- };
292
-
293
- function makeInvokeMethod(innerFn, self, context) {
294
- var state = GenStateSuspendedStart;
295
-
296
- return function invoke(method, arg) {
297
- if (state === GenStateExecuting) {
298
- throw new Error("Generator is already running");
299
- }
300
-
301
- if (state === GenStateCompleted) {
302
- if (method === "throw") {
303
- throw arg;
304
- }
305
-
306
- // Be forgiving, per 25.3.3.3.3 of the spec:
307
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
308
- return doneResult();
309
- }
310
-
311
- context.method = method;
312
- context.arg = arg;
313
-
314
- while (true) {
315
- var delegate = context.delegate;
316
- if (delegate) {
317
- var delegateResult = maybeInvokeDelegate(delegate, context);
318
- if (delegateResult) {
319
- if (delegateResult === ContinueSentinel) continue;
320
- return delegateResult;
321
- }
322
- }
323
-
324
- if (context.method === "next") {
325
- // Setting context._sent for legacy support of Babel's
326
- // function.sent implementation.
327
- context.sent = context._sent = context.arg;
328
-
329
- } else if (context.method === "throw") {
330
- if (state === GenStateSuspendedStart) {
331
- state = GenStateCompleted;
332
- throw context.arg;
333
- }
334
-
335
- context.dispatchException(context.arg);
336
-
337
- } else if (context.method === "return") {
338
- context.abrupt("return", context.arg);
339
- }
340
-
341
- state = GenStateExecuting;
342
-
343
- var record = tryCatch(innerFn, self, context);
344
- if (record.type === "normal") {
345
- // If an exception is thrown from innerFn, we leave state ===
346
- // GenStateExecuting and loop back for another invocation.
347
- state = context.done
348
- ? GenStateCompleted
349
- : GenStateSuspendedYield;
350
-
351
- if (record.arg === ContinueSentinel) {
352
- continue;
353
- }
354
-
355
- return {
356
- value: record.arg,
357
- done: context.done
358
- };
359
-
360
- } else if (record.type === "throw") {
361
- state = GenStateCompleted;
362
- // Dispatch the exception by looping back around to the
363
- // context.dispatchException(context.arg) call above.
364
- context.method = "throw";
365
- context.arg = record.arg;
366
- }
367
- }
156
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
368
157
  };
369
158
  }
370
159
 
371
- // Call delegate.iterator[context.method](context.arg) and handle the
372
- // result, either by returning a { value, done } result from the
373
- // delegate iterator, or by modifying context.method and context.arg,
374
- // setting context.delegate to null, and returning the ContinueSentinel.
375
160
  function maybeInvokeDelegate(delegate, context) {
376
161
  var method = delegate.iterator[context.method];
377
- if (method === undefined$1) {
378
- // A .throw or .return when the delegate iterator has no .throw
379
- // method always terminates the yield* loop.
380
- context.delegate = null;
381
-
382
- if (context.method === "throw") {
383
- // Note: ["return"] must be used for ES3 parsing compatibility.
384
- if (delegate.iterator["return"]) {
385
- // If the delegate iterator has a return method, give it a
386
- // chance to clean up.
387
- context.method = "return";
388
- context.arg = undefined$1;
389
- maybeInvokeDelegate(delegate, context);
390
-
391
- if (context.method === "throw") {
392
- // If maybeInvokeDelegate(context) changed context.method from
393
- // "return" to "throw", let that override the TypeError below.
394
- return ContinueSentinel;
395
- }
396
- }
397
162
 
398
- context.method = "throw";
399
- context.arg = new TypeError(
400
- "The iterator does not provide a 'throw' method");
163
+ if (undefined === method) {
164
+ if (context.delegate = null, "throw" === context.method) {
165
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
166
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
401
167
  }
402
168
 
403
169
  return ContinueSentinel;
404
170
  }
405
171
 
406
172
  var record = tryCatch(method, delegate.iterator, context.arg);
407
-
408
- if (record.type === "throw") {
409
- context.method = "throw";
410
- context.arg = record.arg;
411
- context.delegate = null;
412
- return ContinueSentinel;
413
- }
414
-
173
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
415
174
  var info = record.arg;
416
-
417
- if (! info) {
418
- context.method = "throw";
419
- context.arg = new TypeError("iterator result is not an object");
420
- context.delegate = null;
421
- return ContinueSentinel;
422
- }
423
-
424
- if (info.done) {
425
- // Assign the result of the finished delegate to the temporary
426
- // variable specified by delegate.resultName (see delegateYield).
427
- context[delegate.resultName] = info.value;
428
-
429
- // Resume execution at the desired location (see delegateYield).
430
- context.next = delegate.nextLoc;
431
-
432
- // If context.method was "throw" but the delegate handled the
433
- // exception, let the outer generator proceed normally. If
434
- // context.method was "next", forget context.arg since it has been
435
- // "consumed" by the delegate iterator. If context.method was
436
- // "return", allow the original .return call to continue in the
437
- // outer generator.
438
- if (context.method !== "return") {
439
- context.method = "next";
440
- context.arg = undefined$1;
441
- }
442
-
443
- } else {
444
- // Re-yield the result returned by the delegate method.
445
- return info;
446
- }
447
-
448
- // The delegate iterator is finished, so forget it and continue with
449
- // the outer generator.
450
- context.delegate = null;
451
- return ContinueSentinel;
175
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
452
176
  }
453
177
 
454
- // Define Generator.prototype.{next,throw,return} in terms of the
455
- // unified ._invoke helper method.
456
- defineIteratorMethods(Gp);
457
-
458
- define(Gp, toStringTagSymbol, "Generator");
459
-
460
- // A Generator should always return itself as the iterator object when the
461
- // @@iterator function is called on it. Some browsers' implementations of the
462
- // iterator prototype chain incorrectly implement this, causing the Generator
463
- // object to not be returned from this call. This ensures that doesn't happen.
464
- // See https://github.com/facebook/regenerator/issues/274 for more details.
465
- Gp[iteratorSymbol] = function() {
466
- return this;
467
- };
468
-
469
- Gp.toString = function() {
470
- return "[object Generator]";
471
- };
472
-
473
178
  function pushTryEntry(locs) {
474
- var entry = { tryLoc: locs[0] };
475
-
476
- if (1 in locs) {
477
- entry.catchLoc = locs[1];
478
- }
479
-
480
- if (2 in locs) {
481
- entry.finallyLoc = locs[2];
482
- entry.afterLoc = locs[3];
483
- }
484
-
485
- this.tryEntries.push(entry);
179
+ var entry = {
180
+ tryLoc: locs[0]
181
+ };
182
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
486
183
  }
487
184
 
488
185
  function resetTryEntry(entry) {
489
186
  var record = entry.completion || {};
490
- record.type = "normal";
491
- delete record.arg;
492
- entry.completion = record;
187
+ record.type = "normal", delete record.arg, entry.completion = record;
493
188
  }
494
189
 
495
190
  function Context(tryLocsList) {
496
- // The root entry object (effectively a try statement without a catch
497
- // or a finally block) gives us a place to store values thrown from
498
- // locations where there is no enclosing try statement.
499
- this.tryEntries = [{ tryLoc: "root" }];
500
- tryLocsList.forEach(pushTryEntry, this);
501
- this.reset(true);
191
+ this.tryEntries = [{
192
+ tryLoc: "root"
193
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
502
194
  }
503
195
 
504
- exports.keys = function(object) {
505
- var keys = [];
506
- for (var key in object) {
507
- keys.push(key);
508
- }
509
- keys.reverse();
510
-
511
- // Rather than returning an object with a next method, we keep
512
- // things simple and return the next function itself.
513
- return function next() {
514
- while (keys.length) {
515
- var key = keys.pop();
516
- if (key in object) {
517
- next.value = key;
518
- next.done = false;
519
- return next;
520
- }
521
- }
522
-
523
- // To avoid creating an additional object, we just hang the .value
524
- // and .done properties off the next function object itself. This
525
- // also ensures that the minifier will not anonymize the function.
526
- next.done = true;
527
- return next;
528
- };
529
- };
530
-
531
196
  function values(iterable) {
532
197
  if (iterable) {
533
198
  var iteratorMethod = iterable[iteratorSymbol];
534
- if (iteratorMethod) {
535
- return iteratorMethod.call(iterable);
536
- }
537
-
538
- if (typeof iterable.next === "function") {
539
- return iterable;
540
- }
199
+ if (iteratorMethod) return iteratorMethod.call(iterable);
200
+ if ("function" == typeof iterable.next) return iterable;
541
201
 
542
202
  if (!isNaN(iterable.length)) {
543
- var i = -1, next = function next() {
544
- while (++i < iterable.length) {
545
- if (hasOwn.call(iterable, i)) {
546
- next.value = iterable[i];
547
- next.done = false;
548
- return next;
549
- }
550
- }
551
-
552
- next.value = undefined$1;
553
- next.done = true;
203
+ var i = -1,
204
+ next = function next() {
205
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
554
206
 
555
- return next;
207
+ return next.value = undefined, next.done = !0, next;
556
208
  };
557
209
 
558
210
  return next.next = next;
559
211
  }
560
212
  }
561
213
 
562
- // Return an iterator with no values.
563
- return { next: doneResult };
214
+ return {
215
+ next: doneResult
216
+ };
564
217
  }
565
- exports.values = values;
566
218
 
567
219
  function doneResult() {
568
- return { value: undefined$1, done: true };
220
+ return {
221
+ value: undefined,
222
+ done: !0
223
+ };
569
224
  }
570
225
 
571
- Context.prototype = {
572
- constructor: Context,
573
-
574
- reset: function(skipTempReset) {
575
- this.prev = 0;
576
- this.next = 0;
577
- // Resetting context._sent for legacy support of Babel's
578
- // function.sent implementation.
579
- this.sent = this._sent = undefined$1;
580
- this.done = false;
581
- this.delegate = null;
582
-
583
- this.method = "next";
584
- this.arg = undefined$1;
585
-
586
- this.tryEntries.forEach(resetTryEntry);
587
-
588
- if (!skipTempReset) {
589
- for (var name in this) {
590
- // Not sure about the optimal order of these conditions:
591
- if (name.charAt(0) === "t" &&
592
- hasOwn.call(this, name) &&
593
- !isNaN(+name.slice(1))) {
594
- this[name] = undefined$1;
595
- }
596
- }
597
- }
598
- },
226
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
227
+ var ctor = "function" == typeof genFun && genFun.constructor;
228
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
229
+ }, exports.mark = function (genFun) {
230
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
231
+ }, exports.awrap = function (arg) {
232
+ return {
233
+ __await: arg
234
+ };
235
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
236
+ return this;
237
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
238
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
239
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
240
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
241
+ return result.done ? result.value : iter.next();
242
+ });
243
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
244
+ return this;
245
+ }), define(Gp, "toString", function () {
246
+ return "[object Generator]";
247
+ }), exports.keys = function (object) {
248
+ var keys = [];
599
249
 
600
- stop: function() {
601
- this.done = true;
250
+ for (var key in object) keys.push(key);
602
251
 
603
- var rootEntry = this.tryEntries[0];
604
- var rootRecord = rootEntry.completion;
605
- if (rootRecord.type === "throw") {
606
- throw rootRecord.arg;
252
+ return keys.reverse(), function next() {
253
+ for (; keys.length;) {
254
+ var key = keys.pop();
255
+ if (key in object) return next.value = key, next.done = !1, next;
607
256
  }
608
257
 
258
+ return next.done = !0, next;
259
+ };
260
+ }, exports.values = values, Context.prototype = {
261
+ constructor: Context,
262
+ reset: function (skipTempReset) {
263
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
264
+ },
265
+ stop: function () {
266
+ this.done = !0;
267
+ var rootRecord = this.tryEntries[0].completion;
268
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
609
269
  return this.rval;
610
270
  },
611
-
612
- dispatchException: function(exception) {
613
- if (this.done) {
614
- throw exception;
615
- }
616
-
271
+ dispatchException: function (exception) {
272
+ if (this.done) throw exception;
617
273
  var context = this;
618
- function handle(loc, caught) {
619
- record.type = "throw";
620
- record.arg = exception;
621
- context.next = loc;
622
-
623
- if (caught) {
624
- // If the dispatched exception was caught by a catch block,
625
- // then let that catch block handle the exception normally.
626
- context.method = "next";
627
- context.arg = undefined$1;
628
- }
629
274
 
630
- return !! caught;
275
+ function handle(loc, caught) {
276
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
631
277
  }
632
278
 
633
279
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
634
- var entry = this.tryEntries[i];
635
- var record = entry.completion;
636
-
637
- if (entry.tryLoc === "root") {
638
- // Exception thrown outside of any try block that could handle
639
- // it, so set the completion value of the entire function to
640
- // throw the exception.
641
- return handle("end");
642
- }
280
+ var entry = this.tryEntries[i],
281
+ record = entry.completion;
282
+ if ("root" === entry.tryLoc) return handle("end");
643
283
 
644
284
  if (entry.tryLoc <= this.prev) {
645
- var hasCatch = hasOwn.call(entry, "catchLoc");
646
- var hasFinally = hasOwn.call(entry, "finallyLoc");
285
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
286
+ hasFinally = hasOwn.call(entry, "finallyLoc");
647
287
 
648
288
  if (hasCatch && hasFinally) {
649
- if (this.prev < entry.catchLoc) {
650
- return handle(entry.catchLoc, true);
651
- } else if (this.prev < entry.finallyLoc) {
652
- return handle(entry.finallyLoc);
653
- }
654
-
289
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
290
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
655
291
  } else if (hasCatch) {
656
- if (this.prev < entry.catchLoc) {
657
- return handle(entry.catchLoc, true);
658
- }
659
-
660
- } else if (hasFinally) {
661
- if (this.prev < entry.finallyLoc) {
662
- return handle(entry.finallyLoc);
663
- }
664
-
292
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
665
293
  } else {
666
- throw new Error("try statement without catch or finally");
294
+ if (!hasFinally) throw new Error("try statement without catch or finally");
295
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
667
296
  }
668
297
  }
669
298
  }
670
299
  },
671
-
672
- abrupt: function(type, arg) {
300
+ abrupt: function (type, arg) {
673
301
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
674
302
  var entry = this.tryEntries[i];
675
- if (entry.tryLoc <= this.prev &&
676
- hasOwn.call(entry, "finallyLoc") &&
677
- this.prev < entry.finallyLoc) {
303
+
304
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
678
305
  var finallyEntry = entry;
679
306
  break;
680
307
  }
681
308
  }
682
309
 
683
- if (finallyEntry &&
684
- (type === "break" ||
685
- type === "continue") &&
686
- finallyEntry.tryLoc <= arg &&
687
- arg <= finallyEntry.finallyLoc) {
688
- // Ignore the finally entry if control is not jumping to a
689
- // location outside the try/catch block.
690
- finallyEntry = null;
691
- }
692
-
310
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
693
311
  var record = finallyEntry ? finallyEntry.completion : {};
694
- record.type = type;
695
- record.arg = arg;
696
-
697
- if (finallyEntry) {
698
- this.method = "next";
699
- this.next = finallyEntry.finallyLoc;
700
- return ContinueSentinel;
701
- }
702
-
703
- return this.complete(record);
312
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
704
313
  },
705
-
706
- complete: function(record, afterLoc) {
707
- if (record.type === "throw") {
708
- throw record.arg;
709
- }
710
-
711
- if (record.type === "break" ||
712
- record.type === "continue") {
713
- this.next = record.arg;
714
- } else if (record.type === "return") {
715
- this.rval = this.arg = record.arg;
716
- this.method = "return";
717
- this.next = "end";
718
- } else if (record.type === "normal" && afterLoc) {
719
- this.next = afterLoc;
720
- }
721
-
722
- return ContinueSentinel;
314
+ complete: function (record, afterLoc) {
315
+ if ("throw" === record.type) throw record.arg;
316
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
723
317
  },
724
-
725
- finish: function(finallyLoc) {
318
+ finish: function (finallyLoc) {
726
319
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
727
320
  var entry = this.tryEntries[i];
728
- if (entry.finallyLoc === finallyLoc) {
729
- this.complete(entry.completion, entry.afterLoc);
730
- resetTryEntry(entry);
731
- return ContinueSentinel;
732
- }
321
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
733
322
  }
734
323
  },
735
-
736
- "catch": function(tryLoc) {
324
+ catch: function (tryLoc) {
737
325
  for (var i = this.tryEntries.length - 1; i >= 0; --i) {
738
326
  var entry = this.tryEntries[i];
327
+
739
328
  if (entry.tryLoc === tryLoc) {
740
329
  var record = entry.completion;
741
- if (record.type === "throw") {
330
+
331
+ if ("throw" === record.type) {
742
332
  var thrown = record.arg;
743
333
  resetTryEntry(entry);
744
334
  }
335
+
745
336
  return thrown;
746
337
  }
747
338
  }
748
339
 
749
- // The context.catch method must only be called with a location
750
- // argument that corresponds to a known catch block.
751
340
  throw new Error("illegal catch attempt");
752
341
  },
753
-
754
- delegateYield: function(iterable, resultName, nextLoc) {
755
- this.delegate = {
342
+ delegateYield: function (iterable, resultName, nextLoc) {
343
+ return this.delegate = {
756
344
  iterator: values(iterable),
757
345
  resultName: resultName,
758
346
  nextLoc: nextLoc
759
- };
347
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
348
+ }
349
+ }, exports;
350
+ }
351
+
352
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
353
+ try {
354
+ var info = gen[key](arg);
355
+ var value = info.value;
356
+ } catch (error) {
357
+ reject(error);
358
+ return;
359
+ }
360
+
361
+ if (info.done) {
362
+ resolve(value);
363
+ } else {
364
+ Promise.resolve(value).then(_next, _throw);
365
+ }
366
+ }
367
+
368
+ function _asyncToGenerator(fn) {
369
+ return function () {
370
+ var self = this,
371
+ args = arguments;
372
+ return new Promise(function (resolve, reject) {
373
+ var gen = fn.apply(self, args);
760
374
 
761
- if (this.method === "next") {
762
- // Deliberately forget the last sent value so that we don't
763
- // accidentally pass it on to the delegate.
764
- this.arg = undefined$1;
375
+ function _next(value) {
376
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
765
377
  }
766
378
 
767
- return ContinueSentinel;
768
- }
379
+ function _throw(err) {
380
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
381
+ }
382
+
383
+ _next(undefined);
384
+ });
769
385
  };
386
+ }
387
+
388
+ function _extends() {
389
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
390
+ for (var i = 1; i < arguments.length; i++) {
391
+ var source = arguments[i];
392
+
393
+ for (var key in source) {
394
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
395
+ target[key] = source[key];
396
+ }
397
+ }
398
+ }
770
399
 
771
- // Regardless of whether this script is executing as a CommonJS module
772
- // or not, return the runtime object so that we can declare the variable
773
- // regeneratorRuntime in the outer scope, which allows this module to be
774
- // injected easily by `bin/regenerator --include-runtime script.js`.
775
- return exports;
776
-
777
- }(
778
- // If this script is executing as a CommonJS module, use module.exports
779
- // as the regeneratorRuntime namespace. Otherwise create a new empty
780
- // object. Either way, the resulting object will be used to initialize
781
- // the regeneratorRuntime variable at the top of this file.
782
- module.exports
783
- ));
784
-
785
- try {
786
- regeneratorRuntime = runtime;
787
- } catch (accidentalStrictMode) {
788
- // This module should not be running in strict mode, so the above
789
- // assignment should always work unless something is misconfigured. Just
790
- // in case runtime.js accidentally runs in strict mode, we can escape
791
- // strict mode using a global Function call. This could conceivably fail
792
- // if a Content Security Policy forbids using Function, but in that case
793
- // the proper solution is to fix the accidental strict mode problem. If
794
- // you've misconfigured your bundler to force strict mode and applied a
795
- // CSP to forbid Function, and you're not willing to fix either of those
796
- // problems, please detail your unique predicament in a GitHub issue.
797
- Function("r", "regeneratorRuntime = r")(runtime);
400
+ return target;
401
+ };
402
+ return _extends.apply(this, arguments);
798
403
  }
799
- });
800
404
 
801
405
  var baseTransifexUrl = 'https://rest.api.transifex.com';
802
-
803
406
  var getHeaders = function getHeaders(secrets) {
804
407
  return {
805
408
  Authorization: "Bearer " + (secrets == null ? void 0 : secrets.token),
806
409
  'Content-Type': 'application/vnd.api+json'
807
410
  };
808
411
  };
809
-
810
412
  var projOrgSlug = function projOrgSlug(secrets) {
811
413
  return "o:" + (secrets == null ? void 0 : secrets.organization) + ":p:" + (secrets == null ? void 0 : secrets.project);
812
414
  };
813
415
 
814
- var getLocales = /*#__PURE__*/function () {
815
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(secrets) {
816
- return runtime_1.wrap(function _callee$(_context) {
416
+ function getLocales(_x) {
417
+ return _getLocales.apply(this, arguments);
418
+ }
419
+
420
+ function _getLocales() {
421
+ _getLocales = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(secrets) {
422
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
817
423
  while (1) {
818
424
  switch (_context.prev = _context.next) {
819
425
  case 0:
@@ -846,25 +452,26 @@ var getLocales = /*#__PURE__*/function () {
846
452
  }
847
453
  }, _callee);
848
454
  }));
455
+ return _getLocales.apply(this, arguments);
456
+ }
849
457
 
850
- return function getLocales(_x) {
851
- return _ref.apply(this, arguments);
852
- };
853
- }();
458
+ function getTranslationTask(_x, _x2) {
459
+ return _getTranslationTask.apply(this, arguments);
460
+ }
854
461
 
855
- var getTranslationTask = /*#__PURE__*/function () {
856
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, secrets) {
462
+ function _getTranslationTask() {
463
+ _getTranslationTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(documentId, secrets) {
857
464
  var projectFilter, resourceFilter, task, locales, localeIds, validLocales;
858
- return runtime_1.wrap(function _callee2$(_context2) {
465
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
859
466
  while (1) {
860
- switch (_context2.prev = _context2.next) {
467
+ switch (_context.prev = _context.next) {
861
468
  case 0:
862
469
  if (!(!documentId || !secrets)) {
863
- _context2.next = 2;
470
+ _context.next = 2;
864
471
  break;
865
472
  }
866
473
 
867
- return _context2.abrupt("return", {
474
+ return _context.abrupt("return", {
868
475
  taskId: documentId,
869
476
  documentId: documentId,
870
477
  locales: []
@@ -873,21 +480,20 @@ var getTranslationTask = /*#__PURE__*/function () {
873
480
  case 2:
874
481
  projectFilter = "filter[project]=" + projOrgSlug(secrets);
875
482
  resourceFilter = "filter[resource]=" + projOrgSlug(secrets) + ":r:" + documentId;
876
- _context2.next = 6;
483
+ _context.next = 6;
877
484
  return fetch(baseTransifexUrl + "/resource_language_stats?" + projectFilter + "&" + resourceFilter, {
878
485
  headers: getHeaders(secrets)
879
486
  }).then(function (res) {
880
487
  if (res.ok) {
881
488
  return res.json();
882
489
  } //normal -- just means that this task doesn't exist yet.
883
- else //normal -- just means that this task doesn't exist yet.
884
- if (res.status === 404) {
885
- return {
886
- data: []
887
- };
888
- } else {
889
- throw Error("Failed to retrieve tasks from Transifex. Status: " + res.status);
890
- }
490
+ else if (res.status === 404) {
491
+ return {
492
+ data: []
493
+ };
494
+ } else {
495
+ throw Error("Failed to retrieve tasks from Transifex. Status: " + res.status);
496
+ }
891
497
  }).then(function (res) {
892
498
  return {
893
499
  taskId: projOrgSlug(secrets) + ":r:" + documentId,
@@ -902,12 +508,12 @@ var getTranslationTask = /*#__PURE__*/function () {
902
508
  });
903
509
 
904
510
  case 6:
905
- task = _context2.sent;
906
- _context2.next = 9;
511
+ task = _context.sent;
512
+ _context.next = 9;
907
513
  return getLocales(secrets);
908
514
 
909
515
  case 9:
910
- locales = _context2.sent;
516
+ locales = _context.sent;
911
517
  localeIds = locales.map(function (l) {
912
518
  return l.localeId;
913
519
  });
@@ -917,9 +523,170 @@ var getTranslationTask = /*#__PURE__*/function () {
917
523
  });
918
524
  });
919
525
  task.locales = validLocales;
920
- return _context2.abrupt("return", task);
526
+ return _context.abrupt("return", task);
921
527
 
922
528
  case 14:
529
+ case "end":
530
+ return _context.stop();
531
+ }
532
+ }
533
+ }, _callee);
534
+ }));
535
+ return _getTranslationTask.apply(this, arguments);
536
+ }
537
+
538
+ function getTranslation(_x, _x2, _x3) {
539
+ return _getTranslation.apply(this, arguments);
540
+ }
541
+
542
+ function _getTranslation() {
543
+ _getTranslation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(taskId, localeId, secrets) {
544
+ var resourceDownloadBody, resourceDownloadUrl, translationDownloadId, headers, location;
545
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
546
+ while (1) {
547
+ switch (_context3.prev = _context3.next) {
548
+ case 0:
549
+ resourceDownloadBody = {
550
+ data: {
551
+ attributes: {
552
+ content_encoding: 'text'
553
+ },
554
+ relationships: {
555
+ language: {
556
+ data: {
557
+ id: "l:" + localeId,
558
+ type: 'languages'
559
+ }
560
+ },
561
+ resource: {
562
+ data: {
563
+ id: taskId,
564
+ type: 'resources'
565
+ }
566
+ }
567
+ },
568
+ type: 'resource_translations_async_downloads'
569
+ }
570
+ };
571
+ resourceDownloadUrl = baseTransifexUrl + "/resource_translations_async_downloads";
572
+ _context3.next = 4;
573
+ return fetch(resourceDownloadUrl, {
574
+ headers: getHeaders(secrets),
575
+ method: 'POST',
576
+ body: JSON.stringify(resourceDownloadBody)
577
+ }).then(function (res) {
578
+ return res.json();
579
+ }).then(function (res) {
580
+ return res.data.id;
581
+ });
582
+
583
+ case 4:
584
+ translationDownloadId = _context3.sent;
585
+ headers = getHeaders(secrets);
586
+ _context3.next = 8;
587
+ return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
588
+
589
+ case 8:
590
+ location = _context3.sent;
591
+ return _context3.abrupt("return", handleFileDownload(location));
592
+
593
+ case 10:
594
+ case "end":
595
+ return _context3.stop();
596
+ }
597
+ }
598
+ }, _callee3);
599
+ }));
600
+ return _getTranslation.apply(this, arguments);
601
+ }
602
+
603
+ var pollForFileDownloadLocation = /*#__PURE__*/function () {
604
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resourceDownloadUrl, translationDownloadId, headers) {
605
+ var response;
606
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
607
+ while (1) {
608
+ switch (_context.prev = _context.next) {
609
+ case 0:
610
+ _context.next = 2;
611
+ return fetch(resourceDownloadUrl + "/" + translationDownloadId, {
612
+ headers: headers
613
+ });
614
+
615
+ case 2:
616
+ response = _context.sent;
617
+
618
+ if (!(response.status === 500)) {
619
+ _context.next = 10;
620
+ break;
621
+ }
622
+
623
+ console.info("Transifex plugin message: Received 500 for translation download ID " + translationDownloadId + ". Trying to reconnect...");
624
+ _context.next = 7;
625
+ return new Promise(function (resolve) {
626
+ return setTimeout(resolve, 3000);
627
+ });
628
+
629
+ case 7:
630
+ return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
631
+
632
+ case 10:
633
+ if (!response.redirected) {
634
+ _context.next = 15;
635
+ break;
636
+ }
637
+
638
+ console.info("Transifex plugin message: Received redirect for translation download ID " + translationDownloadId + ". Following redirect now for file download.");
639
+ return _context.abrupt("return", response.url);
640
+
641
+ case 15:
642
+ if (!(response.status === 200)) {
643
+ _context.next = 22;
644
+ break;
645
+ }
646
+
647
+ console.info("Transifex plugin message: Requested download location for translation download ID " + translationDownloadId + ". Location is still pending, trying again.");
648
+ _context.next = 19;
649
+ return new Promise(function (resolve) {
650
+ return setTimeout(resolve, 3000);
651
+ });
652
+
653
+ case 19:
654
+ return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
655
+
656
+ case 22:
657
+ console.info("Transifex plugin message: Requested download location for translation download ID " + translationDownloadId + " but received error code " + response.status + ". Waiting and trying again.");
658
+ _context.next = 25;
659
+ return new Promise(function (resolve) {
660
+ return setTimeout(resolve, 3000);
661
+ });
662
+
663
+ case 25:
664
+ return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
665
+
666
+ case 26:
667
+ case "end":
668
+ return _context.stop();
669
+ }
670
+ }
671
+ }, _callee);
672
+ }));
673
+
674
+ return function pollForFileDownloadLocation(_x4, _x5, _x6) {
675
+ return _ref.apply(this, arguments);
676
+ };
677
+ }();
678
+
679
+ var handleFileDownload = /*#__PURE__*/function () {
680
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url) {
681
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
682
+ while (1) {
683
+ switch (_context2.prev = _context2.next) {
684
+ case 0:
685
+ return _context2.abrupt("return", fetch(url).then(function (res) {
686
+ return res.text();
687
+ }));
688
+
689
+ case 1:
923
690
  case "end":
924
691
  return _context2.stop();
925
692
  }
@@ -927,17 +694,17 @@ var getTranslationTask = /*#__PURE__*/function () {
927
694
  }, _callee2);
928
695
  }));
929
696
 
930
- return function getTranslationTask(_x2, _x3) {
697
+ return function handleFileDownload(_x7) {
931
698
  return _ref2.apply(this, arguments);
932
699
  };
933
700
  }();
934
701
 
935
702
  var createResource = /*#__PURE__*/function () {
936
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(doc, documentId, secrets) {
703
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(doc, documentId, secrets) {
937
704
  var resourceCreateBody;
938
- return runtime_1.wrap(function _callee3$(_context3) {
705
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
939
706
  while (1) {
940
- switch (_context3.prev = _context3.next) {
707
+ switch (_context.prev = _context.next) {
941
708
  case 0:
942
709
  resourceCreateBody = {
943
710
  data: {
@@ -963,7 +730,7 @@ var createResource = /*#__PURE__*/function () {
963
730
  type: 'resources'
964
731
  }
965
732
  };
966
- return _context3.abrupt("return", fetch(baseTransifexUrl + "/resources", {
733
+ return _context.abrupt("return", fetch(baseTransifexUrl + "/resources", {
967
734
  headers: getHeaders(secrets),
968
735
  method: 'POST',
969
736
  body: JSON.stringify(resourceCreateBody)
@@ -975,27 +742,31 @@ var createResource = /*#__PURE__*/function () {
975
742
 
976
743
  case 2:
977
744
  case "end":
978
- return _context3.stop();
745
+ return _context.stop();
979
746
  }
980
747
  }
981
- }, _callee3);
748
+ }, _callee);
982
749
  }));
983
750
 
984
- return function createResource(_x4, _x5, _x6) {
985
- return _ref3.apply(this, arguments);
751
+ return function createResource(_x, _x2, _x3) {
752
+ return _ref.apply(this, arguments);
986
753
  };
987
754
  }();
988
755
 
989
- var createTask = /*#__PURE__*/function () {
990
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(documentId, document, //unfortunately Transifex doesn't let you specify locales on creating a task
756
+ function createTask(_x4, _x5, _x6, _x7) {
757
+ return _createTask.apply(this, arguments);
758
+ }
759
+
760
+ function _createTask() {
761
+ _createTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(documentId, document, //unfortunately Transifex doesn't let you specify locales on creating a task
991
762
  //@ts-ignore
992
763
  localeIds, secrets) {
993
764
  var resourceId, resourceUploadUrl, resourceUploadBody;
994
- return runtime_1.wrap(function _callee4$(_context4) {
765
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
995
766
  while (1) {
996
- switch (_context4.prev = _context4.next) {
767
+ switch (_context2.prev = _context2.next) {
997
768
  case 0:
998
- _context4.next = 2;
769
+ _context2.next = 2;
999
770
  return fetch(baseTransifexUrl + "/resources/" + projOrgSlug(secrets) + ":r:" + documentId, {
1000
771
  headers: getHeaders(secrets)
1001
772
  }).then(function (res) {
@@ -1005,18 +776,18 @@ var createTask = /*#__PURE__*/function () {
1005
776
  });
1006
777
 
1007
778
  case 2:
1008
- resourceId = _context4.sent;
779
+ resourceId = _context2.sent;
1009
780
 
1010
781
  if (resourceId) {
1011
- _context4.next = 7;
782
+ _context2.next = 7;
1012
783
  break;
1013
784
  }
1014
785
 
1015
- _context4.next = 6;
786
+ _context2.next = 6;
1016
787
  return createResource(document, documentId, secrets);
1017
788
 
1018
789
  case 6:
1019
- resourceId = _context4.sent;
790
+ resourceId = _context2.sent;
1020
791
 
1021
792
  case 7:
1022
793
  resourceUploadUrl = baseTransifexUrl + "/resource_strings_async_uploads";
@@ -1037,7 +808,7 @@ var createTask = /*#__PURE__*/function () {
1037
808
  type: 'resource_strings_async_uploads'
1038
809
  }
1039
810
  };
1040
- return _context4.abrupt("return", fetch(resourceUploadUrl, {
811
+ return _context2.abrupt("return", fetch(resourceUploadUrl, {
1041
812
  method: 'POST',
1042
813
  body: JSON.stringify(resourceUploadBody),
1043
814
  headers: getHeaders(secrets)
@@ -1047,109 +818,13 @@ var createTask = /*#__PURE__*/function () {
1047
818
 
1048
819
  case 10:
1049
820
  case "end":
1050
- return _context4.stop();
1051
- }
1052
- }
1053
- }, _callee4);
1054
- }));
1055
-
1056
- return function createTask(_x7, _x8, _x9, _x10) {
1057
- return _ref4.apply(this, arguments);
1058
- };
1059
- }();
1060
-
1061
- var getTranslation = /*#__PURE__*/function () {
1062
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(taskId, localeId, secrets) {
1063
- var resourceDownloadBody, resourceDownloadUrl, translationDownloadId;
1064
- return runtime_1.wrap(function _callee5$(_context5) {
1065
- while (1) {
1066
- switch (_context5.prev = _context5.next) {
1067
- case 0:
1068
- resourceDownloadBody = {
1069
- data: {
1070
- attributes: {
1071
- content_encoding: 'text'
1072
- },
1073
- relationships: {
1074
- language: {
1075
- data: {
1076
- id: "l:" + localeId,
1077
- type: 'languages'
1078
- }
1079
- },
1080
- resource: {
1081
- data: {
1082
- id: taskId,
1083
- type: 'resources'
1084
- }
1085
- }
1086
- },
1087
- type: 'resource_translations_async_downloads'
1088
- }
1089
- };
1090
- resourceDownloadUrl = baseTransifexUrl + "/resource_translations_async_downloads";
1091
- _context5.next = 4;
1092
- return fetch(resourceDownloadUrl, {
1093
- headers: getHeaders(secrets),
1094
- method: 'POST',
1095
- body: JSON.stringify(resourceDownloadBody)
1096
- }).then(function (res) {
1097
- return res.json();
1098
- }).then(function (res) {
1099
- return res.data.id;
1100
- });
1101
-
1102
- case 4:
1103
- translationDownloadId = _context5.sent;
1104
- return _context5.abrupt("return", new Promise(function (resolve) {
1105
- setTimeout(function () {
1106
- fetch(resourceDownloadUrl + "/" + translationDownloadId, {
1107
- headers: getHeaders(secrets)
1108
- }).then(function (res) {
1109
- if (res.redirected) {
1110
- return resolve(handleFileDownload(res.url));
1111
- } else {
1112
- return res.json();
1113
- }
1114
- });
1115
- }, 3000);
1116
- }));
1117
-
1118
- case 6:
1119
- case "end":
1120
- return _context5.stop();
1121
- }
1122
- }
1123
- }, _callee5);
1124
- }));
1125
-
1126
- return function getTranslation(_x11, _x12, _x13) {
1127
- return _ref5.apply(this, arguments);
1128
- };
1129
- }();
1130
-
1131
- var handleFileDownload = /*#__PURE__*/function () {
1132
- var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(url) {
1133
- return runtime_1.wrap(function _callee6$(_context6) {
1134
- while (1) {
1135
- switch (_context6.prev = _context6.next) {
1136
- case 0:
1137
- return _context6.abrupt("return", fetch(url).then(function (res) {
1138
- return res.text();
1139
- }));
1140
-
1141
- case 1:
1142
- case "end":
1143
- return _context6.stop();
821
+ return _context2.stop();
1144
822
  }
1145
823
  }
1146
- }, _callee6);
824
+ }, _callee2);
1147
825
  }));
1148
-
1149
- return function handleFileDownload(_x14) {
1150
- return _ref6.apply(this, arguments);
1151
- };
1152
- }();
826
+ return _createTask.apply(this, arguments);
827
+ }
1153
828
 
1154
829
  var TransifexAdapter = {
1155
830
  getLocales: getLocales,
@@ -1158,317 +833,56 @@ var TransifexAdapter = {
1158
833
  getTranslation: getTranslation
1159
834
  };
1160
835
 
1161
- var client = /*#__PURE__*/sanityClient.withConfig({
1162
- apiVersion: '2021-03-25'
1163
- }); //document fetch
1164
-
1165
- var findLatestDraft = function findLatestDraft(documentId, ignoreI18n) {
1166
- if (ignoreI18n === void 0) {
1167
- ignoreI18n = true;
1168
- }
1169
-
1170
- //eliminates i18n versions
1171
- var query = "*[_id match $id " + (ignoreI18n ? ' && (_id in path("drafts.*") || _id in path("*"))' : '') + "]";
1172
- var params = {
1173
- id: "*" + documentId
1174
- };
1175
- return client.fetch(query, params).then(function (docs) {
1176
- var _docs$find;
1177
-
1178
- return (_docs$find = docs.find(function (doc) {
1179
- return doc._id.includes('draft');
1180
- })) != null ? _docs$find : docs[0];
1181
- });
1182
- }; //revision fetch
1183
-
1184
- var findDocumentAtRevision = /*#__PURE__*/function () {
1185
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
1186
- var dataset, baseUrl, url, revisionDoc;
1187
- return runtime_1.wrap(function _callee$(_context) {
1188
- while (1) {
1189
- switch (_context.prev = _context.next) {
1190
- case 0:
1191
- dataset = client.config().dataset;
1192
- baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
1193
- url = client.getUrl(baseUrl);
1194
- _context.next = 5;
1195
- return fetch(url, {
1196
- credentials: 'include'
1197
- }).then(function (req) {
1198
- return req.json();
1199
- }).then(function (req) {
1200
- return req.documents[0];
1201
- });
1202
-
1203
- case 5:
1204
- revisionDoc = _context.sent;
1205
-
1206
- if (!(!revisionDoc || revisionDoc._rev !== rev)) {
1207
- _context.next = 12;
1208
- break;
1209
- }
1210
-
1211
- baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
1212
- url = client.getUrl(baseUrl);
1213
- _context.next = 11;
1214
- return fetch(url, {
1215
- credentials: 'include'
1216
- }).then(function (req) {
1217
- return req.json();
1218
- }).then(function (req) {
1219
- return req.documents[0];
1220
- });
1221
-
1222
- case 11:
1223
- revisionDoc = _context.sent;
1224
-
1225
- case 12:
1226
- return _context.abrupt("return", revisionDoc);
1227
-
1228
- case 13:
1229
- case "end":
1230
- return _context.stop();
1231
- }
1232
- }
1233
- }, _callee);
1234
- }));
1235
-
1236
- return function findDocumentAtRevision(_x, _x2) {
1237
- return _ref.apply(this, arguments);
1238
- };
1239
- }(); //document-level patch
1240
-
1241
- var documentLevelPatch = /*#__PURE__*/function () {
1242
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
1243
- var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
1244
- return runtime_1.wrap(function _callee2$(_context2) {
1245
- while (1) {
1246
- switch (_context2.prev = _context2.next) {
1247
- case 0:
1248
- if (!translatedFields._rev) {
1249
- _context2.next = 6;
1250
- break;
1251
- }
1252
-
1253
- _context2.next = 3;
1254
- return findDocumentAtRevision(documentId, translatedFields._rev);
1255
-
1256
- case 3:
1257
- baseDoc = _context2.sent;
1258
- _context2.next = 9;
1259
- break;
1260
-
1261
- case 6:
1262
- _context2.next = 8;
1263
- return findLatestDraft(documentId);
1264
-
1265
- case 8:
1266
- baseDoc = _context2.sent;
1267
-
1268
- case 9:
1269
- merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
1270
- targetId = "i18n." + documentId + "." + localeId;
1271
- _context2.next = 13;
1272
- return findLatestDraft(targetId, false);
1273
-
1274
- case 13:
1275
- i18nDoc = _context2.sent;
1276
-
1277
- if (i18nDoc) {
1278
- cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
1279
-
1280
- Object.entries(merged).forEach(function (_ref3) {
1281
- var key = _ref3[0],
1282
- value = _ref3[1];
1283
-
1284
- if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
1285
- cleanedMerge[key] = value;
1286
- }
1287
- });
1288
- client.transaction() //@ts-ignore
1289
- .patch(i18nDoc._id, function (p) {
1290
- return p.set(cleanedMerge);
1291
- }).commit();
1292
- } else {
1293
- merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
1294
-
1295
- if (baseDoc._lang) {
1296
- merged._lang = localeId;
1297
- } else if (baseDoc.__i18n_lang) {
1298
- merged.__i18n_lang = localeId;
1299
- }
1300
-
1301
- client.create(merged);
1302
- }
1303
-
1304
- case 15:
1305
- case "end":
1306
- return _context2.stop();
1307
- }
1308
- }
1309
- }, _callee2);
1310
- }));
1311
-
1312
- return function documentLevelPatch(_x3, _x4, _x5) {
1313
- return _ref2.apply(this, arguments);
1314
- };
1315
- }(); //field level patch
1316
-
1317
- var fieldLevelPatch = /*#__PURE__*/function () {
1318
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
1319
- var baseDoc, merged;
1320
- return runtime_1.wrap(function _callee3$(_context3) {
1321
- while (1) {
1322
- switch (_context3.prev = _context3.next) {
1323
- case 0:
1324
- if (!translatedFields._rev) {
1325
- _context3.next = 6;
1326
- break;
1327
- }
1328
-
1329
- _context3.next = 3;
1330
- return findDocumentAtRevision(documentId, translatedFields._rev);
1331
-
1332
- case 3:
1333
- baseDoc = _context3.sent;
1334
- _context3.next = 9;
1335
- break;
1336
-
1337
- case 6:
1338
- _context3.next = 8;
1339
- return findLatestDraft(documentId);
1340
-
1341
- case 8:
1342
- baseDoc = _context3.sent;
1343
-
1344
- case 9:
1345
- merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
1346
- client.patch(baseDoc._id).set(merged).commit();
1347
-
1348
- case 11:
1349
- case "end":
1350
- return _context3.stop();
1351
- }
1352
- }
1353
- }, _callee3);
1354
- }));
1355
-
1356
- return function fieldLevelPatch(_x6, _x7, _x8) {
1357
- return _ref4.apply(this, arguments);
1358
- };
1359
- }();
1360
-
1361
- var defaultDocumentLevelConfig = {
1362
- exportForTranslation: /*#__PURE__*/function () {
1363
- var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
1364
- var doc, serialized;
1365
- return runtime_1.wrap(function _callee$(_context) {
1366
- while (1) {
1367
- switch (_context.prev = _context.next) {
1368
- case 0:
1369
- _context.next = 2;
1370
- return findLatestDraft(id);
1371
-
1372
- case 2:
1373
- doc = _context.sent;
1374
- serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'document');
1375
- serialized.name = id;
1376
- return _context.abrupt("return", serialized);
1377
-
1378
- case 6:
1379
- case "end":
1380
- return _context.stop();
1381
- }
1382
- }
1383
- }, _callee);
1384
- }));
1385
-
1386
- function exportForTranslation(_x) {
1387
- return _exportForTranslation.apply(this, arguments);
1388
- }
1389
-
1390
- return exportForTranslation;
1391
- }(),
1392
- importTranslation: function importTranslation(id, localeId, document) {
1393
- var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1394
- documentLevelPatch(id, deserialized, localeId);
1395
- },
836
+ var defaultDocumentLevelConfig = /*#__PURE__*/_extends({}, sanityTranslationsTab.baseDocumentLevelConfig, {
1396
837
  adapter: TransifexAdapter,
1397
838
  secretsNamespace: 'transifex'
1398
- };
1399
- var defaultFieldLevelConfig = {
1400
- exportForTranslation: /*#__PURE__*/function () {
1401
- var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
1402
- var doc, serialized;
1403
- return runtime_1.wrap(function _callee2$(_context2) {
1404
- while (1) {
1405
- switch (_context2.prev = _context2.next) {
1406
- case 0:
1407
- _context2.next = 2;
1408
- return findLatestDraft(id);
1409
-
1410
- case 2:
1411
- doc = _context2.sent;
1412
- serialized = sanityNaiveHtmlSerializer.BaseDocumentSerializer.serializeDocument(doc, 'field');
1413
- serialized.name = id;
1414
- return _context2.abrupt("return", serialized);
1415
-
1416
- case 6:
1417
- case "end":
1418
- return _context2.stop();
1419
- }
1420
- }
1421
- }, _callee2);
1422
- }));
1423
-
1424
- function exportForTranslation(_x2) {
1425
- return _exportForTranslation2.apply(this, arguments);
1426
- }
839
+ });
1427
840
 
1428
- return exportForTranslation;
1429
- }(),
1430
- importTranslation: function importTranslation(id, localeId, document) {
1431
- var deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(document);
1432
- fieldLevelPatch(id, deserialized, localeId);
1433
- },
841
+ var defaultFieldLevelConfig = /*#__PURE__*/_extends({}, sanityTranslationsTab.baseFieldLevelConfig, {
1434
842
  adapter: TransifexAdapter,
1435
843
  secretsNamespace: 'transifex'
1436
- };
844
+ });
1437
845
 
1438
- Object.defineProperty(exports, 'TranslationsTab', {
846
+ Object.defineProperty(exports, 'BaseDocumentDeserializer', {
1439
847
  enumerable: true,
1440
848
  get: function () {
1441
- return sanityTranslationsTab.TranslationsTab;
849
+ return sanityTranslationsTab.BaseDocumentDeserializer;
1442
850
  }
1443
851
  });
1444
- Object.defineProperty(exports, 'BaseDocumentDeserializer', {
852
+ Object.defineProperty(exports, 'BaseDocumentMerger', {
1445
853
  enumerable: true,
1446
854
  get: function () {
1447
- return sanityNaiveHtmlSerializer.BaseDocumentDeserializer;
855
+ return sanityTranslationsTab.BaseDocumentMerger;
1448
856
  }
1449
857
  });
1450
- Object.defineProperty(exports, 'BaseDocumentMerger', {
858
+ Object.defineProperty(exports, 'BaseDocumentSerializer', {
1451
859
  enumerable: true,
1452
860
  get: function () {
1453
- return sanityNaiveHtmlSerializer.BaseDocumentMerger;
861
+ return sanityTranslationsTab.BaseDocumentSerializer;
1454
862
  }
1455
863
  });
1456
- Object.defineProperty(exports, 'BaseDocumentSerializer', {
864
+ Object.defineProperty(exports, 'TranslationsTab', {
1457
865
  enumerable: true,
1458
866
  get: function () {
1459
- return sanityNaiveHtmlSerializer.BaseDocumentSerializer;
867
+ return sanityTranslationsTab.TranslationsTab;
1460
868
  }
1461
869
  });
1462
870
  Object.defineProperty(exports, 'customSerializers', {
1463
871
  enumerable: true,
1464
872
  get: function () {
1465
- return sanityNaiveHtmlSerializer.customSerializers;
873
+ return sanityTranslationsTab.customSerializers;
1466
874
  }
1467
875
  });
1468
876
  Object.defineProperty(exports, 'defaultStopTypes', {
1469
877
  enumerable: true,
1470
878
  get: function () {
1471
- return sanityNaiveHtmlSerializer.defaultStopTypes;
879
+ return sanityTranslationsTab.defaultStopTypes;
880
+ }
881
+ });
882
+ Object.defineProperty(exports, 'findLatestDraft', {
883
+ enumerable: true,
884
+ get: function () {
885
+ return sanityTranslationsTab.findLatestDraft;
1472
886
  }
1473
887
  });
1474
888
  exports.TransifexAdapter = TransifexAdapter;