sanity-plugin-studio-smartling 1.4.0 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"sanity-plugin-studio-smartling.cjs.production.min.js","sources":["../node_modules/regenerator-runtime/runtime.js","../src/adapter/helpers.ts","../src/adapter/getLocales.ts","../src/adapter/getTranslationTask.ts","../src/adapter/createTask.ts","../src/adapter/index.ts","../src/adapter/getTranslation.ts","../src/helpers.ts","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2014-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvar runtime = (function (exports) {\n \"use strict\";\n\n var Op = Object.prototype;\n var hasOwn = Op.hasOwnProperty;\n var undefined; // More compressible than void 0.\n var $Symbol = typeof Symbol === \"function\" ? Symbol : {};\n var iteratorSymbol = $Symbol.iterator || \"@@iterator\";\n var asyncIteratorSymbol = $Symbol.asyncIterator || \"@@asyncIterator\";\n var toStringTagSymbol = $Symbol.toStringTag || \"@@toStringTag\";\n\n function define(obj, key, value) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n return obj[key];\n }\n try {\n // IE 8 has a broken Object.defineProperty that only works on DOM objects.\n define({}, \"\");\n } catch (err) {\n define = function(obj, key, value) {\n return obj[key] = value;\n };\n }\n\n function wrap(innerFn, outerFn, self, tryLocsList) {\n // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.\n var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;\n var generator = Object.create(protoGenerator.prototype);\n var context = new Context(tryLocsList || []);\n\n // The ._invoke method unifies the implementations of the .next,\n // .throw, and .return methods.\n generator._invoke = makeInvokeMethod(innerFn, self, context);\n\n return generator;\n }\n exports.wrap = wrap;\n\n // Try/catch helper to minimize deoptimizations. Returns a completion\n // record like context.tryEntries[i].completion. This interface could\n // have been (and was previously) designed to take a closure to be\n // invoked without arguments, but in all the cases we care about we\n // already have an existing method we want to call, so there's no need\n // to create a new function object. We can even get away with assuming\n // the method takes exactly one argument, since that happens to be true\n // in every case, so we don't have to touch the arguments object. The\n // only additional allocation required is the completion record, which\n // has a stable shape and so hopefully should be cheap to allocate.\n function tryCatch(fn, obj, arg) {\n try {\n return { type: \"normal\", arg: fn.call(obj, arg) };\n } catch (err) {\n return { type: \"throw\", arg: err };\n }\n }\n\n var GenStateSuspendedStart = \"suspendedStart\";\n var GenStateSuspendedYield = \"suspendedYield\";\n var GenStateExecuting = \"executing\";\n var GenStateCompleted = \"completed\";\n\n // Returning this object from the innerFn has the same effect as\n // breaking out of the dispatch switch statement.\n var ContinueSentinel = {};\n\n // Dummy constructor functions that we use as the .constructor and\n // .constructor.prototype properties for functions that return Generator\n // objects. For full spec compliance, you may wish to configure your\n // minifier not to mangle the names of these two functions.\n function Generator() {}\n function GeneratorFunction() {}\n function GeneratorFunctionPrototype() {}\n\n // This is a polyfill for %IteratorPrototype% for environments that\n // don't natively support it.\n var IteratorPrototype = {};\n define(IteratorPrototype, iteratorSymbol, function () {\n return this;\n });\n\n var getProto = Object.getPrototypeOf;\n var NativeIteratorPrototype = getProto && getProto(getProto(values([])));\n if (NativeIteratorPrototype &&\n NativeIteratorPrototype !== Op &&\n hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {\n // This environment has a native %IteratorPrototype%; use it instead\n // of the polyfill.\n IteratorPrototype = NativeIteratorPrototype;\n }\n\n var Gp = GeneratorFunctionPrototype.prototype =\n Generator.prototype = Object.create(IteratorPrototype);\n GeneratorFunction.prototype = GeneratorFunctionPrototype;\n define(Gp, \"constructor\", GeneratorFunctionPrototype);\n define(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction);\n GeneratorFunction.displayName = define(\n GeneratorFunctionPrototype,\n toStringTagSymbol,\n \"GeneratorFunction\"\n );\n\n // Helper for defining the .next, .throw, and .return methods of the\n // Iterator interface in terms of a single ._invoke method.\n function defineIteratorMethods(prototype) {\n [\"next\", \"throw\", \"return\"].forEach(function(method) {\n define(prototype, method, function(arg) {\n return this._invoke(method, arg);\n });\n });\n }\n\n exports.isGeneratorFunction = function(genFun) {\n var ctor = typeof genFun === \"function\" && genFun.constructor;\n return ctor\n ? ctor === GeneratorFunction ||\n // For the native GeneratorFunction constructor, the best we can\n // do is to check its .name property.\n (ctor.displayName || ctor.name) === \"GeneratorFunction\"\n : false;\n };\n\n exports.mark = function(genFun) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);\n } else {\n genFun.__proto__ = GeneratorFunctionPrototype;\n define(genFun, toStringTagSymbol, \"GeneratorFunction\");\n }\n genFun.prototype = Object.create(Gp);\n return genFun;\n };\n\n // Within the body of any async function, `await x` is transformed to\n // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test\n // `hasOwn.call(value, \"__await\")` to determine if the yielded value is\n // meant to be awaited.\n exports.awrap = function(arg) {\n return { __await: arg };\n };\n\n function AsyncIterator(generator, PromiseImpl) {\n function invoke(method, arg, resolve, reject) {\n var record = tryCatch(generator[method], generator, arg);\n if (record.type === \"throw\") {\n reject(record.arg);\n } else {\n var result = record.arg;\n var value = result.value;\n if (value &&\n typeof value === \"object\" &&\n hasOwn.call(value, \"__await\")) {\n return PromiseImpl.resolve(value.__await).then(function(value) {\n invoke(\"next\", value, resolve, reject);\n }, function(err) {\n invoke(\"throw\", err, resolve, reject);\n });\n }\n\n return PromiseImpl.resolve(value).then(function(unwrapped) {\n // When a yielded Promise is resolved, its final value becomes\n // the .value of the Promise<{value,done}> result for the\n // current iteration.\n result.value = unwrapped;\n resolve(result);\n }, function(error) {\n // If a rejected Promise was yielded, throw the rejection back\n // into the async generator function so it can be handled there.\n return invoke(\"throw\", error, resolve, reject);\n });\n }\n }\n\n var previousPromise;\n\n function enqueue(method, arg) {\n function callInvokeWithMethodAndArg() {\n return new PromiseImpl(function(resolve, reject) {\n invoke(method, arg, resolve, reject);\n });\n }\n\n return previousPromise =\n // If enqueue has been called before, then we want to wait until\n // all previous Promises have been resolved before calling invoke,\n // so that results are always delivered in the correct order. If\n // enqueue has not been called before, then it is important to\n // call invoke immediately, without waiting on a callback to fire,\n // so that the async generator function has the opportunity to do\n // any necessary setup in a predictable way. This predictability\n // is why the Promise constructor synchronously invokes its\n // executor callback, and why async functions synchronously\n // execute code before the first await. Since we implement simple\n // async functions in terms of async generators, it is especially\n // important to get this right, even though it requires care.\n previousPromise ? previousPromise.then(\n callInvokeWithMethodAndArg,\n // Avoid propagating failures to Promises returned by later\n // invocations of the iterator.\n callInvokeWithMethodAndArg\n ) : callInvokeWithMethodAndArg();\n }\n\n // Define the unified helper method that is used to implement .next,\n // .throw, and .return (see defineIteratorMethods).\n this._invoke = enqueue;\n }\n\n defineIteratorMethods(AsyncIterator.prototype);\n define(AsyncIterator.prototype, asyncIteratorSymbol, function () {\n return this;\n });\n exports.AsyncIterator = AsyncIterator;\n\n // Note that simple async functions are implemented on top of\n // AsyncIterator objects; they just return a Promise for the value of\n // the final result produced by the iterator.\n exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {\n if (PromiseImpl === void 0) PromiseImpl = Promise;\n\n var iter = new AsyncIterator(\n wrap(innerFn, outerFn, self, tryLocsList),\n PromiseImpl\n );\n\n return exports.isGeneratorFunction(outerFn)\n ? iter // If outerFn is a generator, return the full iterator.\n : iter.next().then(function(result) {\n return result.done ? result.value : iter.next();\n });\n };\n\n function makeInvokeMethod(innerFn, self, context) {\n var state = GenStateSuspendedStart;\n\n return function invoke(method, arg) {\n if (state === GenStateExecuting) {\n throw new Error(\"Generator is already running\");\n }\n\n if (state === GenStateCompleted) {\n if (method === \"throw\") {\n throw arg;\n }\n\n // Be forgiving, per 25.3.3.3.3 of the spec:\n // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume\n return doneResult();\n }\n\n context.method = method;\n context.arg = arg;\n\n while (true) {\n var delegate = context.delegate;\n if (delegate) {\n var delegateResult = maybeInvokeDelegate(delegate, context);\n if (delegateResult) {\n if (delegateResult === ContinueSentinel) continue;\n return delegateResult;\n }\n }\n\n if (context.method === \"next\") {\n // Setting context._sent for legacy support of Babel's\n // function.sent implementation.\n context.sent = context._sent = context.arg;\n\n } else if (context.method === \"throw\") {\n if (state === GenStateSuspendedStart) {\n state = GenStateCompleted;\n throw context.arg;\n }\n\n context.dispatchException(context.arg);\n\n } else if (context.method === \"return\") {\n context.abrupt(\"return\", context.arg);\n }\n\n state = GenStateExecuting;\n\n var record = tryCatch(innerFn, self, context);\n if (record.type === \"normal\") {\n // If an exception is thrown from innerFn, we leave state ===\n // GenStateExecuting and loop back for another invocation.\n state = context.done\n ? GenStateCompleted\n : GenStateSuspendedYield;\n\n if (record.arg === ContinueSentinel) {\n continue;\n }\n\n return {\n value: record.arg,\n done: context.done\n };\n\n } else if (record.type === \"throw\") {\n state = GenStateCompleted;\n // Dispatch the exception by looping back around to the\n // context.dispatchException(context.arg) call above.\n context.method = \"throw\";\n context.arg = record.arg;\n }\n }\n };\n }\n\n // Call delegate.iterator[context.method](context.arg) and handle the\n // result, either by returning a { value, done } result from the\n // delegate iterator, or by modifying context.method and context.arg,\n // setting context.delegate to null, and returning the ContinueSentinel.\n function maybeInvokeDelegate(delegate, context) {\n var method = delegate.iterator[context.method];\n if (method === undefined) {\n // A .throw or .return when the delegate iterator has no .throw\n // method always terminates the yield* loop.\n context.delegate = null;\n\n if (context.method === \"throw\") {\n // Note: [\"return\"] must be used for ES3 parsing compatibility.\n if (delegate.iterator[\"return\"]) {\n // If the delegate iterator has a return method, give it a\n // chance to clean up.\n context.method = \"return\";\n context.arg = undefined;\n maybeInvokeDelegate(delegate, context);\n\n if (context.method === \"throw\") {\n // If maybeInvokeDelegate(context) changed context.method from\n // \"return\" to \"throw\", let that override the TypeError below.\n return ContinueSentinel;\n }\n }\n\n context.method = \"throw\";\n context.arg = new TypeError(\n \"The iterator does not provide a 'throw' method\");\n }\n\n return ContinueSentinel;\n }\n\n var record = tryCatch(method, delegate.iterator, context.arg);\n\n if (record.type === \"throw\") {\n context.method = \"throw\";\n context.arg = record.arg;\n context.delegate = null;\n return ContinueSentinel;\n }\n\n var info = record.arg;\n\n if (! info) {\n context.method = \"throw\";\n context.arg = new TypeError(\"iterator result is not an object\");\n context.delegate = null;\n return ContinueSentinel;\n }\n\n if (info.done) {\n // Assign the result of the finished delegate to the temporary\n // variable specified by delegate.resultName (see delegateYield).\n context[delegate.resultName] = info.value;\n\n // Resume execution at the desired location (see delegateYield).\n context.next = delegate.nextLoc;\n\n // If context.method was \"throw\" but the delegate handled the\n // exception, let the outer generator proceed normally. If\n // context.method was \"next\", forget context.arg since it has been\n // \"consumed\" by the delegate iterator. If context.method was\n // \"return\", allow the original .return call to continue in the\n // outer generator.\n if (context.method !== \"return\") {\n context.method = \"next\";\n context.arg = undefined;\n }\n\n } else {\n // Re-yield the result returned by the delegate method.\n return info;\n }\n\n // The delegate iterator is finished, so forget it and continue with\n // the outer generator.\n context.delegate = null;\n return ContinueSentinel;\n }\n\n // Define Generator.prototype.{next,throw,return} in terms of the\n // unified ._invoke helper method.\n defineIteratorMethods(Gp);\n\n define(Gp, toStringTagSymbol, \"Generator\");\n\n // A Generator should always return itself as the iterator object when the\n // @@iterator function is called on it. Some browsers' implementations of the\n // iterator prototype chain incorrectly implement this, causing the Generator\n // object to not be returned from this call. This ensures that doesn't happen.\n // See https://github.com/facebook/regenerator/issues/274 for more details.\n define(Gp, iteratorSymbol, function() {\n return this;\n });\n\n define(Gp, \"toString\", function() {\n return \"[object Generator]\";\n });\n\n function pushTryEntry(locs) {\n var entry = { tryLoc: locs[0] };\n\n if (1 in locs) {\n entry.catchLoc = locs[1];\n }\n\n if (2 in locs) {\n entry.finallyLoc = locs[2];\n entry.afterLoc = locs[3];\n }\n\n this.tryEntries.push(entry);\n }\n\n function resetTryEntry(entry) {\n var record = entry.completion || {};\n record.type = \"normal\";\n delete record.arg;\n entry.completion = record;\n }\n\n function Context(tryLocsList) {\n // The root entry object (effectively a try statement without a catch\n // or a finally block) gives us a place to store values thrown from\n // locations where there is no enclosing try statement.\n this.tryEntries = [{ tryLoc: \"root\" }];\n tryLocsList.forEach(pushTryEntry, this);\n this.reset(true);\n }\n\n exports.keys = function(object) {\n var keys = [];\n for (var key in object) {\n keys.push(key);\n }\n keys.reverse();\n\n // Rather than returning an object with a next method, we keep\n // things simple and return the next function itself.\n return function next() {\n while (keys.length) {\n var key = keys.pop();\n if (key in object) {\n next.value = key;\n next.done = false;\n return next;\n }\n }\n\n // To avoid creating an additional object, we just hang the .value\n // and .done properties off the next function object itself. This\n // also ensures that the minifier will not anonymize the function.\n next.done = true;\n return next;\n };\n };\n\n function values(iterable) {\n if (iterable) {\n var iteratorMethod = iterable[iteratorSymbol];\n if (iteratorMethod) {\n return iteratorMethod.call(iterable);\n }\n\n if (typeof iterable.next === \"function\") {\n return iterable;\n }\n\n if (!isNaN(iterable.length)) {\n var i = -1, next = function next() {\n while (++i < iterable.length) {\n if (hasOwn.call(iterable, i)) {\n next.value = iterable[i];\n next.done = false;\n return next;\n }\n }\n\n next.value = undefined;\n next.done = true;\n\n return next;\n };\n\n return next.next = next;\n }\n }\n\n // Return an iterator with no values.\n return { next: doneResult };\n }\n exports.values = values;\n\n function doneResult() {\n return { value: undefined, done: true };\n }\n\n Context.prototype = {\n constructor: Context,\n\n reset: function(skipTempReset) {\n this.prev = 0;\n this.next = 0;\n // Resetting context._sent for legacy support of Babel's\n // function.sent implementation.\n this.sent = this._sent = undefined;\n this.done = false;\n this.delegate = null;\n\n this.method = \"next\";\n this.arg = undefined;\n\n this.tryEntries.forEach(resetTryEntry);\n\n if (!skipTempReset) {\n for (var name in this) {\n // Not sure about the optimal order of these conditions:\n if (name.charAt(0) === \"t\" &&\n hasOwn.call(this, name) &&\n !isNaN(+name.slice(1))) {\n this[name] = undefined;\n }\n }\n }\n },\n\n stop: function() {\n this.done = true;\n\n var rootEntry = this.tryEntries[0];\n var rootRecord = rootEntry.completion;\n if (rootRecord.type === \"throw\") {\n throw rootRecord.arg;\n }\n\n return this.rval;\n },\n\n dispatchException: function(exception) {\n if (this.done) {\n throw exception;\n }\n\n var context = this;\n function handle(loc, caught) {\n record.type = \"throw\";\n record.arg = exception;\n context.next = loc;\n\n if (caught) {\n // If the dispatched exception was caught by a catch block,\n // then let that catch block handle the exception normally.\n context.method = \"next\";\n context.arg = undefined;\n }\n\n return !! caught;\n }\n\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n var record = entry.completion;\n\n if (entry.tryLoc === \"root\") {\n // Exception thrown outside of any try block that could handle\n // it, so set the completion value of the entire function to\n // throw the exception.\n return handle(\"end\");\n }\n\n if (entry.tryLoc <= this.prev) {\n var hasCatch = hasOwn.call(entry, \"catchLoc\");\n var hasFinally = hasOwn.call(entry, \"finallyLoc\");\n\n if (hasCatch && hasFinally) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n } else if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else if (hasCatch) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n }\n\n } else if (hasFinally) {\n if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else {\n throw new Error(\"try statement without catch or finally\");\n }\n }\n }\n },\n\n abrupt: function(type, arg) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc <= this.prev &&\n hasOwn.call(entry, \"finallyLoc\") &&\n this.prev < entry.finallyLoc) {\n var finallyEntry = entry;\n break;\n }\n }\n\n if (finallyEntry &&\n (type === \"break\" ||\n type === \"continue\") &&\n finallyEntry.tryLoc <= arg &&\n arg <= finallyEntry.finallyLoc) {\n // Ignore the finally entry if control is not jumping to a\n // location outside the try/catch block.\n finallyEntry = null;\n }\n\n var record = finallyEntry ? finallyEntry.completion : {};\n record.type = type;\n record.arg = arg;\n\n if (finallyEntry) {\n this.method = \"next\";\n this.next = finallyEntry.finallyLoc;\n return ContinueSentinel;\n }\n\n return this.complete(record);\n },\n\n complete: function(record, afterLoc) {\n if (record.type === \"throw\") {\n throw record.arg;\n }\n\n if (record.type === \"break\" ||\n record.type === \"continue\") {\n this.next = record.arg;\n } else if (record.type === \"return\") {\n this.rval = this.arg = record.arg;\n this.method = \"return\";\n this.next = \"end\";\n } else if (record.type === \"normal\" && afterLoc) {\n this.next = afterLoc;\n }\n\n return ContinueSentinel;\n },\n\n finish: function(finallyLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.finallyLoc === finallyLoc) {\n this.complete(entry.completion, entry.afterLoc);\n resetTryEntry(entry);\n return ContinueSentinel;\n }\n }\n },\n\n \"catch\": function(tryLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc === tryLoc) {\n var record = entry.completion;\n if (record.type === \"throw\") {\n var thrown = record.arg;\n resetTryEntry(entry);\n }\n return thrown;\n }\n }\n\n // The context.catch method must only be called with a location\n // argument that corresponds to a known catch block.\n throw new Error(\"illegal catch attempt\");\n },\n\n delegateYield: function(iterable, resultName, nextLoc) {\n this.delegate = {\n iterator: values(iterable),\n resultName: resultName,\n nextLoc: nextLoc\n };\n\n if (this.method === \"next\") {\n // Deliberately forget the last sent value so that we don't\n // accidentally pass it on to the delegate.\n this.arg = undefined;\n }\n\n return ContinueSentinel;\n }\n };\n\n // Regardless of whether this script is executing as a CommonJS module\n // or not, return the runtime object so that we can declare the variable\n // regeneratorRuntime in the outer scope, which allows this module to be\n // injected easily by `bin/regenerator --include-runtime script.js`.\n return exports;\n\n}(\n // If this script is executing as a CommonJS module, use module.exports\n // as the regeneratorRuntime namespace. Otherwise create a new empty\n // object. Either way, the resulting object will be used to initialize\n // the regeneratorRuntime variable at the top of this file.\n typeof module === \"object\" ? module.exports : {}\n));\n\ntry {\n regeneratorRuntime = runtime;\n} catch (accidentalStrictMode) {\n // This module should not be running in strict mode, so the above\n // assignment should always work unless something is misconfigured. Just\n // in case runtime.js accidentally runs in strict mode, in modern engines\n // we can explicitly access globalThis. In older engines we can escape\n // strict mode using a global Function call. This could conceivably fail\n // if a Content Security Policy forbids using Function, but in that case\n // the proper solution is to fix the accidental strict mode problem. If\n // you've misconfigured your bundler to force strict mode and applied a\n // CSP to forbid Function, and you're not willing to fix either of those\n // problems, please detail your unique predicament in a GitHub issue.\n if (typeof globalThis === \"object\") {\n globalThis.regeneratorRuntime = runtime;\n } else {\n Function(\"r\", \"regeneratorRuntime = r\")(runtime);\n }\n}\n","export const smartlingProxy = process.env.SANITY_STUDIO_SMARTLING_PROXY\n\nexport const authenticate = async (secret: string) => {\n const url = 'https://api.smartling.com/auth-api/v2/authenticate'\n const headers = {\n 'content-type': 'application/json',\n 'X-URL': url,\n }\n return fetch(smartlingProxy, {\n headers,\n method: 'POST',\n body: JSON.stringify(secret),\n })\n .then(res => res.json())\n .then(res => res.response.data.accessToken)\n}\n\nexport const getHeaders = (url: string, accessToken: string) => ({\n Authorization: `Bearer ${accessToken}`,\n 'X-URL': url,\n})\n\nexport const findExistingJob = async (\n documentId: string,\n projectId: string,\n accessToken: string\n): Promise<string> => {\n const url = `https://api.smartling.com/jobs-api/v3/projects/${projectId}/jobs?jobName=${documentId}`\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => {\n if (res.response.data.items.length) {\n return res.response.data.items[0].translationJobUid\n } else {\n return ''\n }\n })\n}\n","import { smartlingProxy, authenticate, getHeaders } from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getLocales = async (secrets: Secrets) => {\n const url = `https://api.smartling.com/projects-api/v2/projects/${secrets.project}`\n const accessToken = await authenticate(secrets.secret)\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => res.response.data.targetLocales)\n}\n","import {\n smartlingProxy,\n authenticate,\n getHeaders,\n findExistingJob,\n} from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getTranslationTask = async (\n documentId: string,\n secrets: Secrets\n) => {\n const accessToken = await authenticate(secrets.secret)\n const taskId = await findExistingJob(documentId, secrets.project, accessToken)\n if (!taskId) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const url = `https://api.smartling.com/jobs-api/v3/projects/${secrets.project}/jobs/${taskId}/progress`\n const smartlingTask = await fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => res.response.data)\n\n let locales = []\n if (smartlingTask && smartlingTask.contentProgressReport) {\n locales = smartlingTask.contentProgressReport.map(item => ({\n localeId: item.targetLocaleId,\n progress: item.progress ? item.progress.percentComplete : 0,\n }))\n }\n\n return {\n documentId,\n locales,\n //since our download is tied to document id for smartling, keep track of it as a task\n taskId: documentId,\n }\n}\n","import {\n smartlingProxy,\n authenticate,\n getHeaders,\n findExistingJob,\n} from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\nimport { getTranslationTask } from './getTranslationTask'\n\nconst createJob = async (\n jobName: string,\n projectId: string,\n localeIds: string[],\n accessToken: string\n) => {\n const url = `https://api.smartling.com/jobs-api/v3/projects/${projectId}/jobs`\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n jobName,\n targetLocaleIds: localeIds,\n }),\n })\n .then(res => res.json())\n .then(res => res.response.data.translationJobUid)\n}\n\n/* we're using batches here because it eliminates some\n * new string authorization issues for updating existing jobs,\n * and is able to be used for new bulk\n * job functionality.\n */\nconst createJobBatch = async (\n jobId: string,\n projectId: string,\n documentName: string,\n accessToken: string,\n localeIds: string[],\n workflowUid?: string\n) => {\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${projectId}/batches`\n const reqBody: {\n authorize: boolean\n translationJobUid: string\n fileUris: string[]\n localeWorkflows?: { targetLocaleId: string; workflowUid: string }[]\n } = {\n authorize: true,\n translationJobUid: jobId,\n fileUris: [documentName],\n }\n\n if (workflowUid) {\n reqBody.localeWorkflows = localeIds.map(l => ({\n targetLocaleId: l,\n workflowUid,\n }))\n }\n\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify(reqBody),\n })\n .then(res => res.json())\n .then(res => res.response.data.batchUid)\n}\n\nconst uploadFileToBatch = async (\n batchUid: string,\n document: Record<string, any>,\n projectId: string,\n localeIds: string[],\n accessToken: string\n) => {\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${projectId}/batches/${batchUid}/file`\n const formData = new FormData()\n formData.append('fileUri', document.name)\n formData.append('fileType', 'html')\n const htmlBuffer = Buffer.from(document.content, 'utf-8')\n formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`)\n localeIds.forEach(localeId =>\n formData.append('localeIdsToAuthorize[]', localeId)\n )\n\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n body: formData,\n }).then(res => res.json())\n}\n\nexport const createTask = async (\n documentId: string,\n document: Record<string, any>,\n localeIds: string[],\n secrets: Secrets,\n workflowUid?: string\n) => {\n const accessToken = await authenticate(secrets.secret)\n\n //TODO: announce errors here\n let taskId = await findExistingJob(\n document.name,\n secrets.project,\n accessToken\n )\n if (!taskId) {\n taskId = await createJob(\n document.name,\n secrets.project,\n localeIds,\n accessToken\n )\n }\n\n //TODO: log errors here if needed\n const batchUid = await createJobBatch(\n taskId,\n secrets.project,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(\n batchUid,\n document,\n secrets.project,\n localeIds,\n accessToken\n )\n console.log('upload status', uploadFileRes)\n\n return getTranslationTask(documentId, secrets)\n}\n","import { Adapter } from 'sanity-translations-tab'\nimport { getLocales } from './getLocales'\nimport { getTranslationTask } from './getTranslationTask'\nimport { createTask } from './createTask'\nimport { getTranslation } from './getTranslation'\n\nexport const SmartlingAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import { smartlingProxy, authenticate, getHeaders } from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getTranslation = async (\n taskId: string,\n localeId: string,\n secrets: Secrets\n) => {\n const url = `https://api.smartling.com/files-api/v2/projects/${secrets.project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`\n const accessToken = await authenticate(secrets.secret)\n const translatedHTML = await fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => res.body)\n\n return translatedHTML\n}\n","import { SanityDocument } from '@sanity/types'\nimport sanityClient from 'part:@sanity/base/client'\nimport { BaseDocumentMerger } from 'sanity-naive-html-serializer'\n\nconst client = sanityClient.withConfig({ apiVersion: '2021-03-25' })\n\n//document fetch\nexport const findLatestDraft = (documentId: string, ignoreI18n = true) => {\n //eliminates i18n versions\n const query = `*[_id match $id ${\n ignoreI18n ? ' && (_id in path(\"drafts.*\") || _id in path(\"*\"))' : ''\n }]`\n const params = { id: `*${documentId}` }\n return client\n .fetch(query, params)\n .then(\n (docs: SanityDocument[]) =>\n docs.find(doc => doc._id.includes('draft')) ?? docs[0]\n )\n}\n\n//revision fetch\nexport const findDocumentAtRevision = async (\n documentId: string,\n rev: string\n) => {\n const dataset = client.config().dataset\n let baseUrl = `/data/history/${dataset}/documents/${documentId}?revision=${rev}`\n let url = client.getUrl(baseUrl)\n let revisionDoc = await fetch(url, { credentials: 'include' })\n .then(req => req.json())\n .then(req => req.documents && req.documents[0])\n /* endpoint will silently give you incorrect doc\n * if you don't request draft and the rev belongs to a draft, so check\n */\n if (!revisionDoc || revisionDoc._rev !== rev) {\n baseUrl = `/data/history/${dataset}/documents/drafts.${documentId}?revision=${rev}`\n url = client.getUrl(baseUrl)\n revisionDoc = await fetch(url, { credentials: 'include' })\n .then(req => req.json())\n .then(req => req.documents[0])\n }\n return revisionDoc\n}\n\n//document-level patch\nexport const documentLevelPatch = async (\n documentId: string,\n translatedFields: SanityDocument,\n localeId: string\n) => {\n let baseDoc: SanityDocument\n if (translatedFields._rev) {\n baseDoc = await findDocumentAtRevision(documentId, translatedFields._rev)\n } else {\n baseDoc = await findLatestDraft(documentId)\n }\n\n const merged = BaseDocumentMerger.documentLevelMerge(\n translatedFields,\n baseDoc\n )\n const targetId = `i18n.${documentId}.${localeId}`\n const i18nDoc = await findLatestDraft(targetId, false)\n\n if (i18nDoc) {\n const cleanedMerge: Record<string, any> = {}\n //don't overwrite any existing values on the i18n doc\n Object.entries(merged).forEach(([key, value]) => {\n if (\n Object.keys(translatedFields).includes(key) &&\n !['_id', '_rev', '_updatedAt'].includes(key)\n ) {\n cleanedMerge[key] = value\n }\n })\n client\n .transaction()\n //@ts-ignore\n .patch(i18nDoc._id, p => p.set(cleanedMerge))\n .commit()\n } else {\n merged._id = `drafts.${targetId}`\n //account for legacy implementations of i18n plugin lang\n if (baseDoc._lang) {\n merged._lang = localeId\n } else if (baseDoc.__i18n_lang) {\n merged.__i18n_lang = localeId\n }\n client.create(merged)\n }\n}\n\n//field level patch\nexport const fieldLevelPatch = async (\n documentId: string,\n translatedFields: SanityDocument,\n localeId: string\n) => {\n let baseDoc: SanityDocument\n if (translatedFields._rev) {\n baseDoc = await findDocumentAtRevision(documentId, translatedFields._rev)\n } else {\n baseDoc = await findLatestDraft(documentId)\n }\n const merged = BaseDocumentMerger.fieldLevelMerge(\n translatedFields,\n baseDoc,\n localeId,\n 'en'\n )\n client\n .patch(baseDoc._id)\n .set(merged)\n .commit()\n}\n","import { TranslationsTab } from 'sanity-translations-tab'\nimport {\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n} from 'sanity-naive-html-serializer'\nimport { SmartlingAdapter } from './adapter'\nimport { findLatestDraft, documentLevelPatch, fieldLevelPatch } from './helpers'\nimport { SanityDocument } from '@sanity/types'\n\nconst defaultDocumentLevelConfig = {\n exportForTranslation: async (id: string) => {\n const doc = await findLatestDraft(id)\n const serialized = BaseDocumentSerializer.serializeDocument(doc, 'document')\n //needed for lookup by translation tab\n serialized.name = id\n return serialized\n },\n importTranslation: (id: string, localeId: string, document: string) => {\n const deserialized = BaseDocumentDeserializer.deserializeDocument(\n document\n ) as SanityDocument\n documentLevelPatch(id, deserialized, localeId)\n },\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig = {\n exportForTranslation: async (id: string) => {\n const doc = await findLatestDraft(id)\n const serialized = BaseDocumentSerializer.serializeDocument(doc, 'field')\n //needed for lookup by translation tab\n serialized.name = id\n return serialized\n },\n importTranslation: (id: string, localeId: string, document: string) => {\n const deserialized = BaseDocumentDeserializer.deserializeDocument(\n document\n ) as SanityDocument\n fieldLevelPatch(id, deserialized, localeId)\n },\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n"],"names":["runtime","exports","Op","Object","prototype","hasOwn","hasOwnProperty","$Symbol","Symbol","iteratorSymbol","iterator","asyncIteratorSymbol","asyncIterator","toStringTagSymbol","toStringTag","define","obj","key","value","defineProperty","enumerable","configurable","writable","err","wrap","innerFn","outerFn","self","tryLocsList","generator","create","Generator","context","Context","_invoke","state","method","arg","Error","undefined","done","delegate","delegateResult","maybeInvokeDelegate","ContinueSentinel","sent","_sent","dispatchException","abrupt","record","tryCatch","type","makeInvokeMethod","fn","call","GeneratorFunction","GeneratorFunctionPrototype","IteratorPrototype","this","getProto","getPrototypeOf","NativeIteratorPrototype","values","Gp","defineIteratorMethods","forEach","AsyncIterator","PromiseImpl","previousPromise","callInvokeWithMethodAndArg","resolve","reject","invoke","result","__await","then","unwrapped","error","TypeError","info","resultName","next","nextLoc","pushTryEntry","locs","entry","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","push","resetTryEntry","completion","reset","iterable","iteratorMethod","isNaN","length","i","doneResult","displayName","isGeneratorFunction","genFun","ctor","constructor","name","mark","setPrototypeOf","__proto__","awrap","async","Promise","iter","keys","object","reverse","pop","skipTempReset","prev","charAt","slice","stop","rootRecord","rval","exception","handle","loc","caught","hasCatch","hasFinally","finallyEntry","complete","finish","catch","thrown","delegateYield","module","regeneratorRuntime","accidentalStrictMode","globalThis","Function","smartlingProxy","process","env","SANITY_STUDIO_SMARTLING_PROXY","authenticate","secret","fetch","headers","body","JSON","stringify","res","json","response","data","accessToken","getHeaders","url","Authorization","findExistingJob","documentId","projectId","items","translationJobUid","getLocales","secrets","project","targetLocales","getTranslationTask","taskId","locales","smartlingTask","contentProgressReport","map","item","localeId","targetLocaleId","progress","percentComplete","createJob","jobName","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","htmlBuffer","Buffer","from","content","Blob","createTask","console","log","SmartlingAdapter","getTranslation","client","sanityClient","withConfig","apiVersion","findLatestDraft","ignoreI18n","id","docs","find","doc","_id","includes","findDocumentAtRevision","rev","dataset","config","getUrl","credentials","req","documents","revisionDoc","_rev","documentLevelPatch","translatedFields","baseDoc","merged","BaseDocumentMerger","documentLevelMerge","targetId","i18nDoc","cleanedMerge","entries","transaction","patch","p","set","commit","_lang","__i18n_lang","fieldLevelPatch","fieldLevelMerge","defaultDocumentLevelConfig","exportForTranslation","serialized","BaseDocumentSerializer","serializeDocument","importTranslation","deserialized","BaseDocumentDeserializer","deserializeDocument","adapter","defaultFieldLevelConfig"],"mappings":"2tBAOA,IAAIA,EAAW,SAAUC,GAGvB,IAAIC,EAAKC,OAAOC,UACZC,EAASH,EAAGI,eAEZC,EAA4B,mBAAXC,OAAwBA,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uBC,yBAAuB,UAEtDrJ,KAAO8G,oBACXqC,oGAETG,kBAAmB,SAACxC,EAAYvC,EAAkBmB,OAC1C6D,EAAeC,2BAAyBC,oBAC5C/D,GAEFqD,EAAgBjC,EAAIyC,EAAchF,IAEpCmF,QAASpD"}
1
+ {"version":3,"file":"sanity-plugin-studio-smartling.cjs.production.min.js","sources":["../node_modules/regenerator-runtime/runtime.js","../src/adapter/helpers.ts","../src/adapter/getLocales.ts","../src/adapter/getTranslationTask.ts","../src/adapter/createTask.ts","../src/adapter/index.ts","../src/adapter/getTranslation.ts","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2014-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nvar runtime = (function (exports) {\n \"use strict\";\n\n var Op = Object.prototype;\n var hasOwn = Op.hasOwnProperty;\n var undefined; // More compressible than void 0.\n var $Symbol = typeof Symbol === \"function\" ? Symbol : {};\n var iteratorSymbol = $Symbol.iterator || \"@@iterator\";\n var asyncIteratorSymbol = $Symbol.asyncIterator || \"@@asyncIterator\";\n var toStringTagSymbol = $Symbol.toStringTag || \"@@toStringTag\";\n\n function define(obj, key, value) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n return obj[key];\n }\n try {\n // IE 8 has a broken Object.defineProperty that only works on DOM objects.\n define({}, \"\");\n } catch (err) {\n define = function(obj, key, value) {\n return obj[key] = value;\n };\n }\n\n function wrap(innerFn, outerFn, self, tryLocsList) {\n // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.\n var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;\n var generator = Object.create(protoGenerator.prototype);\n var context = new Context(tryLocsList || []);\n\n // The ._invoke method unifies the implementations of the .next,\n // .throw, and .return methods.\n generator._invoke = makeInvokeMethod(innerFn, self, context);\n\n return generator;\n }\n exports.wrap = wrap;\n\n // Try/catch helper to minimize deoptimizations. Returns a completion\n // record like context.tryEntries[i].completion. This interface could\n // have been (and was previously) designed to take a closure to be\n // invoked without arguments, but in all the cases we care about we\n // already have an existing method we want to call, so there's no need\n // to create a new function object. We can even get away with assuming\n // the method takes exactly one argument, since that happens to be true\n // in every case, so we don't have to touch the arguments object. The\n // only additional allocation required is the completion record, which\n // has a stable shape and so hopefully should be cheap to allocate.\n function tryCatch(fn, obj, arg) {\n try {\n return { type: \"normal\", arg: fn.call(obj, arg) };\n } catch (err) {\n return { type: \"throw\", arg: err };\n }\n }\n\n var GenStateSuspendedStart = \"suspendedStart\";\n var GenStateSuspendedYield = \"suspendedYield\";\n var GenStateExecuting = \"executing\";\n var GenStateCompleted = \"completed\";\n\n // Returning this object from the innerFn has the same effect as\n // breaking out of the dispatch switch statement.\n var ContinueSentinel = {};\n\n // Dummy constructor functions that we use as the .constructor and\n // .constructor.prototype properties for functions that return Generator\n // objects. For full spec compliance, you may wish to configure your\n // minifier not to mangle the names of these two functions.\n function Generator() {}\n function GeneratorFunction() {}\n function GeneratorFunctionPrototype() {}\n\n // This is a polyfill for %IteratorPrototype% for environments that\n // don't natively support it.\n var IteratorPrototype = {};\n define(IteratorPrototype, iteratorSymbol, function () {\n return this;\n });\n\n var getProto = Object.getPrototypeOf;\n var NativeIteratorPrototype = getProto && getProto(getProto(values([])));\n if (NativeIteratorPrototype &&\n NativeIteratorPrototype !== Op &&\n hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {\n // This environment has a native %IteratorPrototype%; use it instead\n // of the polyfill.\n IteratorPrototype = NativeIteratorPrototype;\n }\n\n var Gp = GeneratorFunctionPrototype.prototype =\n Generator.prototype = Object.create(IteratorPrototype);\n GeneratorFunction.prototype = GeneratorFunctionPrototype;\n define(Gp, \"constructor\", GeneratorFunctionPrototype);\n define(GeneratorFunctionPrototype, \"constructor\", GeneratorFunction);\n GeneratorFunction.displayName = define(\n GeneratorFunctionPrototype,\n toStringTagSymbol,\n \"GeneratorFunction\"\n );\n\n // Helper for defining the .next, .throw, and .return methods of the\n // Iterator interface in terms of a single ._invoke method.\n function defineIteratorMethods(prototype) {\n [\"next\", \"throw\", \"return\"].forEach(function(method) {\n define(prototype, method, function(arg) {\n return this._invoke(method, arg);\n });\n });\n }\n\n exports.isGeneratorFunction = function(genFun) {\n var ctor = typeof genFun === \"function\" && genFun.constructor;\n return ctor\n ? ctor === GeneratorFunction ||\n // For the native GeneratorFunction constructor, the best we can\n // do is to check its .name property.\n (ctor.displayName || ctor.name) === \"GeneratorFunction\"\n : false;\n };\n\n exports.mark = function(genFun) {\n if (Object.setPrototypeOf) {\n Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);\n } else {\n genFun.__proto__ = GeneratorFunctionPrototype;\n define(genFun, toStringTagSymbol, \"GeneratorFunction\");\n }\n genFun.prototype = Object.create(Gp);\n return genFun;\n };\n\n // Within the body of any async function, `await x` is transformed to\n // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test\n // `hasOwn.call(value, \"__await\")` to determine if the yielded value is\n // meant to be awaited.\n exports.awrap = function(arg) {\n return { __await: arg };\n };\n\n function AsyncIterator(generator, PromiseImpl) {\n function invoke(method, arg, resolve, reject) {\n var record = tryCatch(generator[method], generator, arg);\n if (record.type === \"throw\") {\n reject(record.arg);\n } else {\n var result = record.arg;\n var value = result.value;\n if (value &&\n typeof value === \"object\" &&\n hasOwn.call(value, \"__await\")) {\n return PromiseImpl.resolve(value.__await).then(function(value) {\n invoke(\"next\", value, resolve, reject);\n }, function(err) {\n invoke(\"throw\", err, resolve, reject);\n });\n }\n\n return PromiseImpl.resolve(value).then(function(unwrapped) {\n // When a yielded Promise is resolved, its final value becomes\n // the .value of the Promise<{value,done}> result for the\n // current iteration.\n result.value = unwrapped;\n resolve(result);\n }, function(error) {\n // If a rejected Promise was yielded, throw the rejection back\n // into the async generator function so it can be handled there.\n return invoke(\"throw\", error, resolve, reject);\n });\n }\n }\n\n var previousPromise;\n\n function enqueue(method, arg) {\n function callInvokeWithMethodAndArg() {\n return new PromiseImpl(function(resolve, reject) {\n invoke(method, arg, resolve, reject);\n });\n }\n\n return previousPromise =\n // If enqueue has been called before, then we want to wait until\n // all previous Promises have been resolved before calling invoke,\n // so that results are always delivered in the correct order. If\n // enqueue has not been called before, then it is important to\n // call invoke immediately, without waiting on a callback to fire,\n // so that the async generator function has the opportunity to do\n // any necessary setup in a predictable way. This predictability\n // is why the Promise constructor synchronously invokes its\n // executor callback, and why async functions synchronously\n // execute code before the first await. Since we implement simple\n // async functions in terms of async generators, it is especially\n // important to get this right, even though it requires care.\n previousPromise ? previousPromise.then(\n callInvokeWithMethodAndArg,\n // Avoid propagating failures to Promises returned by later\n // invocations of the iterator.\n callInvokeWithMethodAndArg\n ) : callInvokeWithMethodAndArg();\n }\n\n // Define the unified helper method that is used to implement .next,\n // .throw, and .return (see defineIteratorMethods).\n this._invoke = enqueue;\n }\n\n defineIteratorMethods(AsyncIterator.prototype);\n define(AsyncIterator.prototype, asyncIteratorSymbol, function () {\n return this;\n });\n exports.AsyncIterator = AsyncIterator;\n\n // Note that simple async functions are implemented on top of\n // AsyncIterator objects; they just return a Promise for the value of\n // the final result produced by the iterator.\n exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {\n if (PromiseImpl === void 0) PromiseImpl = Promise;\n\n var iter = new AsyncIterator(\n wrap(innerFn, outerFn, self, tryLocsList),\n PromiseImpl\n );\n\n return exports.isGeneratorFunction(outerFn)\n ? iter // If outerFn is a generator, return the full iterator.\n : iter.next().then(function(result) {\n return result.done ? result.value : iter.next();\n });\n };\n\n function makeInvokeMethod(innerFn, self, context) {\n var state = GenStateSuspendedStart;\n\n return function invoke(method, arg) {\n if (state === GenStateExecuting) {\n throw new Error(\"Generator is already running\");\n }\n\n if (state === GenStateCompleted) {\n if (method === \"throw\") {\n throw arg;\n }\n\n // Be forgiving, per 25.3.3.3.3 of the spec:\n // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume\n return doneResult();\n }\n\n context.method = method;\n context.arg = arg;\n\n while (true) {\n var delegate = context.delegate;\n if (delegate) {\n var delegateResult = maybeInvokeDelegate(delegate, context);\n if (delegateResult) {\n if (delegateResult === ContinueSentinel) continue;\n return delegateResult;\n }\n }\n\n if (context.method === \"next\") {\n // Setting context._sent for legacy support of Babel's\n // function.sent implementation.\n context.sent = context._sent = context.arg;\n\n } else if (context.method === \"throw\") {\n if (state === GenStateSuspendedStart) {\n state = GenStateCompleted;\n throw context.arg;\n }\n\n context.dispatchException(context.arg);\n\n } else if (context.method === \"return\") {\n context.abrupt(\"return\", context.arg);\n }\n\n state = GenStateExecuting;\n\n var record = tryCatch(innerFn, self, context);\n if (record.type === \"normal\") {\n // If an exception is thrown from innerFn, we leave state ===\n // GenStateExecuting and loop back for another invocation.\n state = context.done\n ? GenStateCompleted\n : GenStateSuspendedYield;\n\n if (record.arg === ContinueSentinel) {\n continue;\n }\n\n return {\n value: record.arg,\n done: context.done\n };\n\n } else if (record.type === \"throw\") {\n state = GenStateCompleted;\n // Dispatch the exception by looping back around to the\n // context.dispatchException(context.arg) call above.\n context.method = \"throw\";\n context.arg = record.arg;\n }\n }\n };\n }\n\n // Call delegate.iterator[context.method](context.arg) and handle the\n // result, either by returning a { value, done } result from the\n // delegate iterator, or by modifying context.method and context.arg,\n // setting context.delegate to null, and returning the ContinueSentinel.\n function maybeInvokeDelegate(delegate, context) {\n var method = delegate.iterator[context.method];\n if (method === undefined) {\n // A .throw or .return when the delegate iterator has no .throw\n // method always terminates the yield* loop.\n context.delegate = null;\n\n if (context.method === \"throw\") {\n // Note: [\"return\"] must be used for ES3 parsing compatibility.\n if (delegate.iterator[\"return\"]) {\n // If the delegate iterator has a return method, give it a\n // chance to clean up.\n context.method = \"return\";\n context.arg = undefined;\n maybeInvokeDelegate(delegate, context);\n\n if (context.method === \"throw\") {\n // If maybeInvokeDelegate(context) changed context.method from\n // \"return\" to \"throw\", let that override the TypeError below.\n return ContinueSentinel;\n }\n }\n\n context.method = \"throw\";\n context.arg = new TypeError(\n \"The iterator does not provide a 'throw' method\");\n }\n\n return ContinueSentinel;\n }\n\n var record = tryCatch(method, delegate.iterator, context.arg);\n\n if (record.type === \"throw\") {\n context.method = \"throw\";\n context.arg = record.arg;\n context.delegate = null;\n return ContinueSentinel;\n }\n\n var info = record.arg;\n\n if (! info) {\n context.method = \"throw\";\n context.arg = new TypeError(\"iterator result is not an object\");\n context.delegate = null;\n return ContinueSentinel;\n }\n\n if (info.done) {\n // Assign the result of the finished delegate to the temporary\n // variable specified by delegate.resultName (see delegateYield).\n context[delegate.resultName] = info.value;\n\n // Resume execution at the desired location (see delegateYield).\n context.next = delegate.nextLoc;\n\n // If context.method was \"throw\" but the delegate handled the\n // exception, let the outer generator proceed normally. If\n // context.method was \"next\", forget context.arg since it has been\n // \"consumed\" by the delegate iterator. If context.method was\n // \"return\", allow the original .return call to continue in the\n // outer generator.\n if (context.method !== \"return\") {\n context.method = \"next\";\n context.arg = undefined;\n }\n\n } else {\n // Re-yield the result returned by the delegate method.\n return info;\n }\n\n // The delegate iterator is finished, so forget it and continue with\n // the outer generator.\n context.delegate = null;\n return ContinueSentinel;\n }\n\n // Define Generator.prototype.{next,throw,return} in terms of the\n // unified ._invoke helper method.\n defineIteratorMethods(Gp);\n\n define(Gp, toStringTagSymbol, \"Generator\");\n\n // A Generator should always return itself as the iterator object when the\n // @@iterator function is called on it. Some browsers' implementations of the\n // iterator prototype chain incorrectly implement this, causing the Generator\n // object to not be returned from this call. This ensures that doesn't happen.\n // See https://github.com/facebook/regenerator/issues/274 for more details.\n define(Gp, iteratorSymbol, function() {\n return this;\n });\n\n define(Gp, \"toString\", function() {\n return \"[object Generator]\";\n });\n\n function pushTryEntry(locs) {\n var entry = { tryLoc: locs[0] };\n\n if (1 in locs) {\n entry.catchLoc = locs[1];\n }\n\n if (2 in locs) {\n entry.finallyLoc = locs[2];\n entry.afterLoc = locs[3];\n }\n\n this.tryEntries.push(entry);\n }\n\n function resetTryEntry(entry) {\n var record = entry.completion || {};\n record.type = \"normal\";\n delete record.arg;\n entry.completion = record;\n }\n\n function Context(tryLocsList) {\n // The root entry object (effectively a try statement without a catch\n // or a finally block) gives us a place to store values thrown from\n // locations where there is no enclosing try statement.\n this.tryEntries = [{ tryLoc: \"root\" }];\n tryLocsList.forEach(pushTryEntry, this);\n this.reset(true);\n }\n\n exports.keys = function(object) {\n var keys = [];\n for (var key in object) {\n keys.push(key);\n }\n keys.reverse();\n\n // Rather than returning an object with a next method, we keep\n // things simple and return the next function itself.\n return function next() {\n while (keys.length) {\n var key = keys.pop();\n if (key in object) {\n next.value = key;\n next.done = false;\n return next;\n }\n }\n\n // To avoid creating an additional object, we just hang the .value\n // and .done properties off the next function object itself. This\n // also ensures that the minifier will not anonymize the function.\n next.done = true;\n return next;\n };\n };\n\n function values(iterable) {\n if (iterable) {\n var iteratorMethod = iterable[iteratorSymbol];\n if (iteratorMethod) {\n return iteratorMethod.call(iterable);\n }\n\n if (typeof iterable.next === \"function\") {\n return iterable;\n }\n\n if (!isNaN(iterable.length)) {\n var i = -1, next = function next() {\n while (++i < iterable.length) {\n if (hasOwn.call(iterable, i)) {\n next.value = iterable[i];\n next.done = false;\n return next;\n }\n }\n\n next.value = undefined;\n next.done = true;\n\n return next;\n };\n\n return next.next = next;\n }\n }\n\n // Return an iterator with no values.\n return { next: doneResult };\n }\n exports.values = values;\n\n function doneResult() {\n return { value: undefined, done: true };\n }\n\n Context.prototype = {\n constructor: Context,\n\n reset: function(skipTempReset) {\n this.prev = 0;\n this.next = 0;\n // Resetting context._sent for legacy support of Babel's\n // function.sent implementation.\n this.sent = this._sent = undefined;\n this.done = false;\n this.delegate = null;\n\n this.method = \"next\";\n this.arg = undefined;\n\n this.tryEntries.forEach(resetTryEntry);\n\n if (!skipTempReset) {\n for (var name in this) {\n // Not sure about the optimal order of these conditions:\n if (name.charAt(0) === \"t\" &&\n hasOwn.call(this, name) &&\n !isNaN(+name.slice(1))) {\n this[name] = undefined;\n }\n }\n }\n },\n\n stop: function() {\n this.done = true;\n\n var rootEntry = this.tryEntries[0];\n var rootRecord = rootEntry.completion;\n if (rootRecord.type === \"throw\") {\n throw rootRecord.arg;\n }\n\n return this.rval;\n },\n\n dispatchException: function(exception) {\n if (this.done) {\n throw exception;\n }\n\n var context = this;\n function handle(loc, caught) {\n record.type = \"throw\";\n record.arg = exception;\n context.next = loc;\n\n if (caught) {\n // If the dispatched exception was caught by a catch block,\n // then let that catch block handle the exception normally.\n context.method = \"next\";\n context.arg = undefined;\n }\n\n return !! caught;\n }\n\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n var record = entry.completion;\n\n if (entry.tryLoc === \"root\") {\n // Exception thrown outside of any try block that could handle\n // it, so set the completion value of the entire function to\n // throw the exception.\n return handle(\"end\");\n }\n\n if (entry.tryLoc <= this.prev) {\n var hasCatch = hasOwn.call(entry, \"catchLoc\");\n var hasFinally = hasOwn.call(entry, \"finallyLoc\");\n\n if (hasCatch && hasFinally) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n } else if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else if (hasCatch) {\n if (this.prev < entry.catchLoc) {\n return handle(entry.catchLoc, true);\n }\n\n } else if (hasFinally) {\n if (this.prev < entry.finallyLoc) {\n return handle(entry.finallyLoc);\n }\n\n } else {\n throw new Error(\"try statement without catch or finally\");\n }\n }\n }\n },\n\n abrupt: function(type, arg) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc <= this.prev &&\n hasOwn.call(entry, \"finallyLoc\") &&\n this.prev < entry.finallyLoc) {\n var finallyEntry = entry;\n break;\n }\n }\n\n if (finallyEntry &&\n (type === \"break\" ||\n type === \"continue\") &&\n finallyEntry.tryLoc <= arg &&\n arg <= finallyEntry.finallyLoc) {\n // Ignore the finally entry if control is not jumping to a\n // location outside the try/catch block.\n finallyEntry = null;\n }\n\n var record = finallyEntry ? finallyEntry.completion : {};\n record.type = type;\n record.arg = arg;\n\n if (finallyEntry) {\n this.method = \"next\";\n this.next = finallyEntry.finallyLoc;\n return ContinueSentinel;\n }\n\n return this.complete(record);\n },\n\n complete: function(record, afterLoc) {\n if (record.type === \"throw\") {\n throw record.arg;\n }\n\n if (record.type === \"break\" ||\n record.type === \"continue\") {\n this.next = record.arg;\n } else if (record.type === \"return\") {\n this.rval = this.arg = record.arg;\n this.method = \"return\";\n this.next = \"end\";\n } else if (record.type === \"normal\" && afterLoc) {\n this.next = afterLoc;\n }\n\n return ContinueSentinel;\n },\n\n finish: function(finallyLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.finallyLoc === finallyLoc) {\n this.complete(entry.completion, entry.afterLoc);\n resetTryEntry(entry);\n return ContinueSentinel;\n }\n }\n },\n\n \"catch\": function(tryLoc) {\n for (var i = this.tryEntries.length - 1; i >= 0; --i) {\n var entry = this.tryEntries[i];\n if (entry.tryLoc === tryLoc) {\n var record = entry.completion;\n if (record.type === \"throw\") {\n var thrown = record.arg;\n resetTryEntry(entry);\n }\n return thrown;\n }\n }\n\n // The context.catch method must only be called with a location\n // argument that corresponds to a known catch block.\n throw new Error(\"illegal catch attempt\");\n },\n\n delegateYield: function(iterable, resultName, nextLoc) {\n this.delegate = {\n iterator: values(iterable),\n resultName: resultName,\n nextLoc: nextLoc\n };\n\n if (this.method === \"next\") {\n // Deliberately forget the last sent value so that we don't\n // accidentally pass it on to the delegate.\n this.arg = undefined;\n }\n\n return ContinueSentinel;\n }\n };\n\n // Regardless of whether this script is executing as a CommonJS module\n // or not, return the runtime object so that we can declare the variable\n // regeneratorRuntime in the outer scope, which allows this module to be\n // injected easily by `bin/regenerator --include-runtime script.js`.\n return exports;\n\n}(\n // If this script is executing as a CommonJS module, use module.exports\n // as the regeneratorRuntime namespace. Otherwise create a new empty\n // object. Either way, the resulting object will be used to initialize\n // the regeneratorRuntime variable at the top of this file.\n typeof module === \"object\" ? module.exports : {}\n));\n\ntry {\n regeneratorRuntime = runtime;\n} catch (accidentalStrictMode) {\n // This module should not be running in strict mode, so the above\n // assignment should always work unless something is misconfigured. Just\n // in case runtime.js accidentally runs in strict mode, in modern engines\n // we can explicitly access globalThis. In older engines we can escape\n // strict mode using a global Function call. This could conceivably fail\n // if a Content Security Policy forbids using Function, but in that case\n // the proper solution is to fix the accidental strict mode problem. If\n // you've misconfigured your bundler to force strict mode and applied a\n // CSP to forbid Function, and you're not willing to fix either of those\n // problems, please detail your unique predicament in a GitHub issue.\n if (typeof globalThis === \"object\") {\n globalThis.regeneratorRuntime = runtime;\n } else {\n Function(\"r\", \"regeneratorRuntime = r\")(runtime);\n }\n}\n","export const smartlingProxy = process.env.SANITY_STUDIO_SMARTLING_PROXY\n\nexport const authenticate = async (secret: string) => {\n const url = 'https://api.smartling.com/auth-api/v2/authenticate'\n const headers = {\n 'content-type': 'application/json',\n 'X-URL': url,\n }\n return fetch(smartlingProxy, {\n headers,\n method: 'POST',\n body: JSON.stringify(secret),\n })\n .then(res => res.json())\n .then(res => res.response.data.accessToken)\n}\n\nexport const getHeaders = (url: string, accessToken: string) => ({\n Authorization: `Bearer ${accessToken}`,\n 'X-URL': url,\n})\n\nexport const findExistingJob = async (\n documentId: string,\n projectId: string,\n accessToken: string\n): Promise<string> => {\n const url = `https://api.smartling.com/jobs-api/v3/projects/${projectId}/jobs?jobName=${documentId}`\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => {\n if (res.response.data.items.length) {\n //smartling will fuzzy match job names. We need to be precise.\n const correctJob = res.response.data.items.find(\n item => item.jobName && item.jobName === documentId\n )\n if (correctJob) {\n return correctJob.translationJobUid\n } else {\n return ''\n }\n } else {\n return ''\n }\n })\n}\n","import { smartlingProxy, authenticate, getHeaders } from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getLocales = async (secrets: Secrets) => {\n const url = `https://api.smartling.com/projects-api/v2/projects/${secrets.project}`\n const accessToken = await authenticate(secrets.secret)\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => res.response.data.targetLocales)\n}\n","import {\n smartlingProxy,\n authenticate,\n getHeaders,\n findExistingJob,\n} from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getTranslationTask = async (\n documentId: string,\n secrets: Secrets\n) => {\n const accessToken = await authenticate(secrets.secret)\n const taskId = await findExistingJob(documentId, secrets.project, accessToken)\n if (!taskId) {\n return {\n documentId,\n taskId: documentId,\n locales: [],\n }\n }\n\n const projectId = secrets.project\n const progressUrl = `https://api.smartling.com/jobs-api/v3/projects/${projectId}/jobs/${taskId}/progress`\n const smartlingTask = await fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(progressUrl, accessToken),\n })\n .then(res => res.json())\n .then(res => res.response.data)\n\n let locales = []\n if (smartlingTask && smartlingTask.contentProgressReport) {\n locales = smartlingTask.contentProgressReport.map(item => ({\n localeId: item.targetLocaleId,\n progress: item.progress ? item.progress.percentComplete : 0,\n }))\n }\n\n return {\n documentId,\n locales,\n //since our download is tied to document id for smartling, keep track of it as a task\n taskId: documentId,\n linkToVendorTask: `https://dashboard.smartling.com/app/projects/${projectId}/account-jobs/${projectId}:${taskId}`,\n }\n}\n","import {\n smartlingProxy,\n authenticate,\n getHeaders,\n findExistingJob,\n} from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\nimport { getTranslationTask } from './getTranslationTask'\n\nconst createJob = async (\n jobName: string,\n projectId: string,\n localeIds: string[],\n accessToken: string\n) => {\n const url = `https://api.smartling.com/jobs-api/v3/projects/${projectId}/jobs`\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify({\n jobName,\n targetLocaleIds: localeIds,\n }),\n })\n .then(res => res.json())\n .then(res => res.response.data.translationJobUid)\n}\n\n/* we're using batches here because it eliminates some\n * new string authorization issues for updating existing jobs,\n * and is able to be used for new bulk\n * job functionality.\n */\nconst createJobBatch = async (\n jobId: string,\n projectId: string,\n documentName: string,\n accessToken: string,\n localeIds: string[],\n workflowUid?: string\n) => {\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${projectId}/batches`\n const reqBody: {\n authorize: boolean\n translationJobUid: string\n fileUris: string[]\n localeWorkflows?: { targetLocaleId: string; workflowUid: string }[]\n } = {\n authorize: true,\n translationJobUid: jobId,\n fileUris: [documentName],\n }\n\n if (workflowUid) {\n reqBody.localeWorkflows = localeIds.map(l => ({\n targetLocaleId: l,\n workflowUid,\n }))\n }\n\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: {\n ...getHeaders(url, accessToken),\n 'content-type': 'application/json',\n },\n body: JSON.stringify(reqBody),\n })\n .then(res => res.json())\n .then(res => res.response.data.batchUid)\n}\n\nconst uploadFileToBatch = async (\n batchUid: string,\n document: Record<string, any>,\n projectId: string,\n localeIds: string[],\n accessToken: string\n) => {\n const url = `https://api.smartling.com/job-batches-api/v2/projects/${projectId}/batches/${batchUid}/file`\n const formData = new FormData()\n formData.append('fileUri', document.name)\n formData.append('fileType', 'html')\n const htmlBuffer = Buffer.from(document.content, 'utf-8')\n formData.append('file', new Blob([htmlBuffer]), `${document.name}.html`)\n localeIds.forEach(localeId =>\n formData.append('localeIdsToAuthorize[]', localeId)\n )\n\n return fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n body: formData,\n }).then(res => res.json())\n}\n\nexport const createTask = async (\n documentId: string,\n document: Record<string, any>,\n localeIds: string[],\n secrets: Secrets,\n workflowUid?: string\n) => {\n const accessToken = await authenticate(secrets.secret)\n\n //TODO: announce errors here\n let taskId = await findExistingJob(\n document.name,\n secrets.project,\n accessToken\n )\n if (!taskId) {\n taskId = await createJob(\n document.name,\n secrets.project,\n localeIds,\n accessToken\n )\n }\n\n //TODO: log errors here if needed\n const batchUid = await createJobBatch(\n taskId,\n secrets.project,\n document.name,\n accessToken,\n localeIds,\n workflowUid\n )\n const uploadFileRes = await uploadFileToBatch(\n batchUid,\n document,\n secrets.project,\n localeIds,\n accessToken\n )\n console.log('upload status', uploadFileRes)\n\n return getTranslationTask(documentId, secrets)\n}\n","import { Adapter } from 'sanity-translations-tab'\nimport { getLocales } from './getLocales'\nimport { getTranslationTask } from './getTranslationTask'\nimport { createTask } from './createTask'\nimport { getTranslation } from './getTranslation'\n\nexport const SmartlingAdapter: Adapter = {\n getLocales,\n getTranslationTask,\n createTask,\n getTranslation,\n}\n","import { smartlingProxy, authenticate, getHeaders } from './helpers'\nimport { Secrets } from 'sanity-translations-tab'\n\nexport const getTranslation = async (\n taskId: string,\n localeId: string,\n secrets: Secrets\n) => {\n const url = `https://api.smartling.com/files-api/v2/projects/${secrets.project}/locales/${localeId}/file?fileUri=${taskId}&retrievalType=pending`\n const accessToken = await authenticate(secrets.secret)\n const translatedHTML = await fetch(smartlingProxy, {\n method: 'POST',\n headers: getHeaders(url, accessToken),\n })\n .then(res => res.json())\n .then(res => {\n if (res.body) {\n return res.body\n } else if (res.response.errors) {\n const errMsg =\n res.response.errors[0]?.message ||\n 'Error retrieving translation from Smartling'\n throw new Error(errMsg)\n }\n })\n\n return translatedHTML\n}\n","import {\n TranslationsTab,\n baseDocumentLevelConfig,\n baseFieldLevelConfig,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n Adapter,\n} from 'sanity-translations-tab'\nimport { SmartlingAdapter } from './adapter'\n\ninterface ConfigOptions {\n adapter: Adapter\n secretsNamespace: string | null\n exportForTranslation: (id: string) => Promise<Record<string, any>>\n importTranslation: (\n id: string,\n localeId: string,\n doc: string\n ) => Promise<void>\n}\nconst defaultDocumentLevelConfig: ConfigOptions = {\n ...baseDocumentLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nconst defaultFieldLevelConfig: ConfigOptions = {\n ...baseFieldLevelConfig,\n adapter: SmartlingAdapter,\n}\n\nexport {\n TranslationsTab,\n findLatestDraft,\n BaseDocumentDeserializer,\n BaseDocumentSerializer,\n BaseDocumentMerger,\n defaultStopTypes,\n customSerializers,\n SmartlingAdapter,\n defaultDocumentLevelConfig,\n defaultFieldLevelConfig,\n}\n"],"names":["runtime","exports","Op","Object","prototype","hasOwn","hasOwnProperty","$Symbol","Symbol","iteratorSymbol","iterator","asyncIteratorSymbol","asyncIterator","toStringTagSymbol","toStringTag","define","obj","key","value","defineProperty","enumerable","configurable","writable","err","wrap","innerFn","outerFn","self","tryLocsList","generator","create","Generator","context","Context","_invoke","state","method","arg","Error","undefined","done","delegate","delegateResult","maybeInvokeDelegate","ContinueSentinel","sent","_sent","dispatchException","abrupt","record","tryCatch","type","makeInvokeMethod","fn","call","GeneratorFunction","GeneratorFunctionPrototype","IteratorPrototype","this","getProto","getPrototypeOf","NativeIteratorPrototype","values","Gp","defineIteratorMethods","forEach","AsyncIterator","PromiseImpl","previousPromise","callInvokeWithMethodAndArg","resolve","reject","invoke","result","__await","then","unwrapped","error","TypeError","info","resultName","next","nextLoc","pushTryEntry","locs","entry","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","push","resetTryEntry","completion","reset","iterable","iteratorMethod","isNaN","length","i","doneResult","displayName","isGeneratorFunction","genFun","ctor","constructor","name","mark","setPrototypeOf","__proto__","awrap","async","Promise","iter","keys","object","reverse","pop","skipTempReset","prev","charAt","slice","stop","rootRecord","rval","exception","handle","loc","caught","hasCatch","hasFinally","finallyEntry","complete","finish","catch","thrown","delegateYield","module","regeneratorRuntime","accidentalStrictMode","globalThis","Function","smartlingProxy","process","env","SANITY_STUDIO_SMARTLING_PROXY","authenticate","secret","fetch","headers","body","JSON","stringify","res","json","response","data","accessToken","getHeaders","url","Authorization","findExistingJob","documentId","projectId","items","correctJob","find","item","jobName","translationJobUid","getLocales","secrets","project","targetLocales","getTranslationTask","taskId","locales","progressUrl","smartlingTask","contentProgressReport","map","localeId","targetLocaleId","progress","percentComplete","linkToVendorTask","createJob","localeIds","targetLocaleIds","createJobBatch","jobId","documentName","workflowUid","reqBody","authorize","fileUris","localeWorkflows","l","batchUid","uploadFileToBatch","document","formData","FormData","append","htmlBuffer","Buffer","from","content","Blob","createTask","console","log","SmartlingAdapter","getTranslation","errors","errMsg","message","defaultDocumentLevelConfig","baseDocumentLevelConfig","adapter","defaultFieldLevelConfig","baseFieldLevelConfig"],"mappings":"slBAOA,IAAIA,EAAW,SAAUC,GAGvB,IAAIC,EAAKC,OAAOC,UACZC,EAASH,EAAGI,eAEZC,EAA4B,mBAAXC,OAAwBA,OAAS,GAClDC,EAAiBF,EAAQG,UAAY,aACrCC,EAAsBJ,EAAQK,eAAiB,kBAC/CC,EAAoBN,EAAQO,aAAe,gBAE/C,SAASC,EAAOC,EAAKC,EAAKC,GAOxB,OANAf,OAAOgB,eAAeH,EAAKC,EAAK,CAC9BC,MAAOA,EACPE,YAAY,EACZC,cAAc,EACdC,UAAU,IAELN,EAAIC,GAEb,IAEEF,EAAO,GAAI,IACX,MAAOQ,GACPR,EAAS,SAASC,EAAKC,EAAKC,GAC1B,OAAOF,EAAIC,GAAOC,GAItB,SAASM,EAAKC,EAASC,EAASC,EAAMC,GAEpC,IACIC,EAAY1B,OAAO2B,QADFJ,GAAWA,EAAQtB,qBAAqB2B,EAAYL,EAAUK,GACtC3B,WACzC4B,EAAU,IAAIC,EAAQL,GAAe,IAMzC,OAFAC,EAAUK,QAuMZ,SAA0BT,EAASE,EAAMK,GACvC,IAAIG,EAhLuB,iBAkL3B,OAAO,SAAgBC,EAAQC,GAC7B,GAjLoB,cAiLhBF,EACF,MAAM,IAAIG,MAAM,gCAGlB,GApLoB,cAoLhBH,EAA6B,CAC/B,GAAe,UAAXC,EACF,MAAMC,EAKR,MAoQG,CAAEnB,WA1fPqB,EA0fyBC,MAAM,GA9P/B,IAHAR,EAAQI,OAASA,EACjBJ,EAAQK,IAAMA,IAED,CACX,IAAII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P,IAGLQ,OACDC,wBACHF,QAASP"}
@@ -1,7 +1,5 @@
1
- export { TranslationsTab } from 'sanity-translations-tab';
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';
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 {
@@ -873,7 +871,16 @@ var findExistingJob = /*#__PURE__*/function () {
873
871
  return res.json();
874
872
  }).then(function (res) {
875
873
  if (res.response.data.items.length) {
876
- return res.response.data.items[0].translationJobUid;
874
+ //smartling will fuzzy match job names. We need to be precise.
875
+ var correctJob = res.response.data.items.find(function (item) {
876
+ return item.jobName && item.jobName === documentId;
877
+ });
878
+
879
+ if (correctJob) {
880
+ return correctJob.translationJobUid;
881
+ } else {
882
+ return '';
883
+ }
877
884
  } else {
878
885
  return '';
879
886
  }
@@ -929,7 +936,7 @@ var getLocales = /*#__PURE__*/function () {
929
936
 
930
937
  var getTranslationTask = /*#__PURE__*/function () {
931
938
  var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, secrets) {
932
- var accessToken, taskId, url, smartlingTask, locales;
939
+ var accessToken, taskId, projectId, progressUrl, smartlingTask, locales;
933
940
  return runtime_1.wrap(function _callee$(_context) {
934
941
  while (1) {
935
942
  switch (_context.prev = _context.next) {
@@ -957,18 +964,19 @@ var getTranslationTask = /*#__PURE__*/function () {
957
964
  });
958
965
 
959
966
  case 8:
960
- url = "https://api.smartling.com/jobs-api/v3/projects/" + secrets.project + "/jobs/" + taskId + "/progress";
961
- _context.next = 11;
967
+ projectId = secrets.project;
968
+ progressUrl = "https://api.smartling.com/jobs-api/v3/projects/" + projectId + "/jobs/" + taskId + "/progress";
969
+ _context.next = 12;
962
970
  return fetch(smartlingProxy, {
963
971
  method: 'POST',
964
- headers: getHeaders(url, accessToken)
972
+ headers: getHeaders(progressUrl, accessToken)
965
973
  }).then(function (res) {
966
974
  return res.json();
967
975
  }).then(function (res) {
968
976
  return res.response.data;
969
977
  });
970
978
 
971
- case 11:
979
+ case 12:
972
980
  smartlingTask = _context.sent;
973
981
  locales = [];
974
982
 
@@ -985,10 +993,11 @@ var getTranslationTask = /*#__PURE__*/function () {
985
993
  documentId: documentId,
986
994
  locales: locales,
987
995
  //since our download is tied to document id for smartling, keep track of it as a task
988
- taskId: documentId
996
+ taskId: documentId,
997
+ linkToVendorTask: "https://dashboard.smartling.com/app/projects/" + projectId + "/account-jobs/" + projectId + ":" + taskId
989
998
  });
990
999
 
991
- case 15:
1000
+ case 16:
992
1001
  case "end":
993
1002
  return _context.stop();
994
1003
  }
@@ -1204,7 +1213,14 @@ var getTranslation = /*#__PURE__*/function () {
1204
1213
  }).then(function (res) {
1205
1214
  return res.json();
1206
1215
  }).then(function (res) {
1207
- return res.body;
1216
+ if (res.body) {
1217
+ return res.body;
1218
+ } else if (res.response.errors) {
1219
+ var _res$response$errors$;
1220
+
1221
+ var errMsg = ((_res$response$errors$ = res.response.errors[0]) == null ? void 0 : _res$response$errors$.message) || 'Error retrieving translation from Smartling';
1222
+ throw new Error(errMsg);
1223
+ }
1208
1224
  });
1209
1225
 
1210
1226
  case 6:
@@ -1231,282 +1247,13 @@ var SmartlingAdapter = {
1231
1247
  getTranslation: getTranslation
1232
1248
  };
1233
1249
 
1234
- var client = /*#__PURE__*/sanityClient.withConfig({
1235
- apiVersion: '2021-03-25'
1236
- }); //document fetch
1237
-
1238
- var findLatestDraft = function findLatestDraft(documentId, ignoreI18n) {
1239
- if (ignoreI18n === void 0) {
1240
- ignoreI18n = true;
1241
- }
1242
-
1243
- //eliminates i18n versions
1244
- var query = "*[_id match $id " + (ignoreI18n ? ' && (_id in path("drafts.*") || _id in path("*"))' : '') + "]";
1245
- var params = {
1246
- id: "*" + documentId
1247
- };
1248
- return client.fetch(query, params).then(function (docs) {
1249
- var _docs$find;
1250
-
1251
- return (_docs$find = docs.find(function (doc) {
1252
- return doc._id.includes('draft');
1253
- })) != null ? _docs$find : docs[0];
1254
- });
1255
- }; //revision fetch
1256
-
1257
- var findDocumentAtRevision = /*#__PURE__*/function () {
1258
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
1259
- var dataset, baseUrl, url, revisionDoc;
1260
- return runtime_1.wrap(function _callee$(_context) {
1261
- while (1) {
1262
- switch (_context.prev = _context.next) {
1263
- case 0:
1264
- dataset = client.config().dataset;
1265
- baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
1266
- url = client.getUrl(baseUrl);
1267
- _context.next = 5;
1268
- return fetch(url, {
1269
- credentials: 'include'
1270
- }).then(function (req) {
1271
- return req.json();
1272
- }).then(function (req) {
1273
- return req.documents && req.documents[0];
1274
- });
1275
-
1276
- case 5:
1277
- revisionDoc = _context.sent;
1278
-
1279
- if (!(!revisionDoc || revisionDoc._rev !== rev)) {
1280
- _context.next = 12;
1281
- break;
1282
- }
1283
-
1284
- baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
1285
- url = client.getUrl(baseUrl);
1286
- _context.next = 11;
1287
- return fetch(url, {
1288
- credentials: 'include'
1289
- }).then(function (req) {
1290
- return req.json();
1291
- }).then(function (req) {
1292
- return req.documents[0];
1293
- });
1294
-
1295
- case 11:
1296
- revisionDoc = _context.sent;
1297
-
1298
- case 12:
1299
- return _context.abrupt("return", revisionDoc);
1300
-
1301
- case 13:
1302
- case "end":
1303
- return _context.stop();
1304
- }
1305
- }
1306
- }, _callee);
1307
- }));
1308
-
1309
- return function findDocumentAtRevision(_x, _x2) {
1310
- return _ref.apply(this, arguments);
1311
- };
1312
- }(); //document-level patch
1313
-
1314
- var documentLevelPatch = /*#__PURE__*/function () {
1315
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
1316
- var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
1317
- return runtime_1.wrap(function _callee2$(_context2) {
1318
- while (1) {
1319
- switch (_context2.prev = _context2.next) {
1320
- case 0:
1321
- if (!translatedFields._rev) {
1322
- _context2.next = 6;
1323
- break;
1324
- }
1325
-
1326
- _context2.next = 3;
1327
- return findDocumentAtRevision(documentId, translatedFields._rev);
1328
-
1329
- case 3:
1330
- baseDoc = _context2.sent;
1331
- _context2.next = 9;
1332
- break;
1333
-
1334
- case 6:
1335
- _context2.next = 8;
1336
- return findLatestDraft(documentId);
1337
-
1338
- case 8:
1339
- baseDoc = _context2.sent;
1340
-
1341
- case 9:
1342
- merged = BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
1343
- targetId = "i18n." + documentId + "." + localeId;
1344
- _context2.next = 13;
1345
- return findLatestDraft(targetId, false);
1346
-
1347
- case 13:
1348
- i18nDoc = _context2.sent;
1349
-
1350
- if (i18nDoc) {
1351
- cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
1352
-
1353
- Object.entries(merged).forEach(function (_ref3) {
1354
- var key = _ref3[0],
1355
- value = _ref3[1];
1356
-
1357
- if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
1358
- cleanedMerge[key] = value;
1359
- }
1360
- });
1361
- client.transaction() //@ts-ignore
1362
- .patch(i18nDoc._id, function (p) {
1363
- return p.set(cleanedMerge);
1364
- }).commit();
1365
- } else {
1366
- merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
1367
-
1368
- if (baseDoc._lang) {
1369
- merged._lang = localeId;
1370
- } else if (baseDoc.__i18n_lang) {
1371
- merged.__i18n_lang = localeId;
1372
- }
1373
-
1374
- client.create(merged);
1375
- }
1376
-
1377
- case 15:
1378
- case "end":
1379
- return _context2.stop();
1380
- }
1381
- }
1382
- }, _callee2);
1383
- }));
1384
-
1385
- return function documentLevelPatch(_x3, _x4, _x5) {
1386
- return _ref2.apply(this, arguments);
1387
- };
1388
- }(); //field level patch
1389
-
1390
- var fieldLevelPatch = /*#__PURE__*/function () {
1391
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
1392
- var baseDoc, merged;
1393
- return runtime_1.wrap(function _callee3$(_context3) {
1394
- while (1) {
1395
- switch (_context3.prev = _context3.next) {
1396
- case 0:
1397
- if (!translatedFields._rev) {
1398
- _context3.next = 6;
1399
- break;
1400
- }
1401
-
1402
- _context3.next = 3;
1403
- return findDocumentAtRevision(documentId, translatedFields._rev);
1404
-
1405
- case 3:
1406
- baseDoc = _context3.sent;
1407
- _context3.next = 9;
1408
- break;
1409
-
1410
- case 6:
1411
- _context3.next = 8;
1412
- return findLatestDraft(documentId);
1413
-
1414
- case 8:
1415
- baseDoc = _context3.sent;
1416
-
1417
- case 9:
1418
- merged = BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
1419
- client.patch(baseDoc._id).set(merged).commit();
1420
-
1421
- case 11:
1422
- case "end":
1423
- return _context3.stop();
1424
- }
1425
- }
1426
- }, _callee3);
1427
- }));
1428
-
1429
- return function fieldLevelPatch(_x6, _x7, _x8) {
1430
- return _ref4.apply(this, arguments);
1431
- };
1432
- }();
1433
-
1434
- var defaultDocumentLevelConfig = {
1435
- exportForTranslation: /*#__PURE__*/function () {
1436
- var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
1437
- var doc, serialized;
1438
- return runtime_1.wrap(function _callee$(_context) {
1439
- while (1) {
1440
- switch (_context.prev = _context.next) {
1441
- case 0:
1442
- _context.next = 2;
1443
- return findLatestDraft(id);
1444
-
1445
- case 2:
1446
- doc = _context.sent;
1447
- serialized = BaseDocumentSerializer.serializeDocument(doc, 'document'); //needed for lookup by translation tab
1448
-
1449
- serialized.name = id;
1450
- return _context.abrupt("return", serialized);
1451
-
1452
- case 6:
1453
- case "end":
1454
- return _context.stop();
1455
- }
1456
- }
1457
- }, _callee);
1458
- }));
1459
-
1460
- function exportForTranslation(_x) {
1461
- return _exportForTranslation.apply(this, arguments);
1462
- }
1463
-
1464
- return exportForTranslation;
1465
- }(),
1466
- importTranslation: function importTranslation(id, localeId, document) {
1467
- var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
1468
- documentLevelPatch(id, deserialized, localeId);
1469
- },
1250
+ var defaultDocumentLevelConfig = /*#__PURE__*/_extends({}, baseDocumentLevelConfig, {
1470
1251
  adapter: SmartlingAdapter
1471
- };
1472
- var defaultFieldLevelConfig = {
1473
- exportForTranslation: /*#__PURE__*/function () {
1474
- var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
1475
- var doc, serialized;
1476
- return runtime_1.wrap(function _callee2$(_context2) {
1477
- while (1) {
1478
- switch (_context2.prev = _context2.next) {
1479
- case 0:
1480
- _context2.next = 2;
1481
- return findLatestDraft(id);
1482
-
1483
- case 2:
1484
- doc = _context2.sent;
1485
- serialized = BaseDocumentSerializer.serializeDocument(doc, 'field'); //needed for lookup by translation tab
1486
-
1487
- serialized.name = id;
1488
- return _context2.abrupt("return", serialized);
1489
-
1490
- case 6:
1491
- case "end":
1492
- return _context2.stop();
1493
- }
1494
- }
1495
- }, _callee2);
1496
- }));
1497
-
1498
- function exportForTranslation(_x2) {
1499
- return _exportForTranslation2.apply(this, arguments);
1500
- }
1252
+ });
1501
1253
 
1502
- return exportForTranslation;
1503
- }(),
1504
- importTranslation: function importTranslation(id, localeId, document) {
1505
- var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
1506
- fieldLevelPatch(id, deserialized, localeId);
1507
- },
1254
+ var defaultFieldLevelConfig = /*#__PURE__*/_extends({}, baseFieldLevelConfig, {
1508
1255
  adapter: SmartlingAdapter
1509
- };
1256
+ });
1510
1257
 
1511
1258
  export { SmartlingAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig };
1512
1259
  //# sourceMappingURL=sanity-plugin-studio-smartling.esm.js.map