gt-sanity 0.0.5 → 0.0.6

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.
Files changed (48) hide show
  1. package/LICENSE.md +1 -8
  2. package/README.md +5 -5
  3. package/dist/index.d.mts +35 -30
  4. package/dist/index.d.ts +35 -30
  5. package/dist/index.js +234 -123
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +237 -124
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +5 -3
  10. package/src/adapter/core.ts +72 -7
  11. package/src/adapter/createTask.ts +1 -1
  12. package/src/adapter/types.ts +9 -0
  13. package/src/components/LanguageStatus.tsx +2 -0
  14. package/src/components/NewTask.tsx +2 -0
  15. package/src/components/ProgressBar.tsx +2 -0
  16. package/src/components/TaskView.tsx +2 -0
  17. package/src/components/TranslationContext.tsx +5 -0
  18. package/src/components/TranslationView.tsx +34 -2
  19. package/src/components/TranslationsTab.tsx +4 -0
  20. package/src/components/page/TranslationsTool.tsx +876 -0
  21. package/src/configuration/baseDocumentLevelConfig/documentLevelPatch.ts +23 -10
  22. package/src/configuration/baseDocumentLevelConfig/helpers/createI18nDocAndPatchMetadata.ts +77 -24
  23. package/src/configuration/baseDocumentLevelConfig/helpers/createTranslationMetadata.ts +2 -0
  24. package/src/configuration/baseDocumentLevelConfig/helpers/getOrCreateTranslationMetadata.ts +2 -0
  25. package/src/configuration/baseDocumentLevelConfig/helpers/getTranslationMetadata.ts +2 -0
  26. package/src/configuration/baseDocumentLevelConfig/helpers/patchI18nDoc.ts +51 -8
  27. package/src/configuration/baseDocumentLevelConfig/index.ts +6 -37
  28. package/src/configuration/baseFieldLevelConfig.ts +4 -1
  29. package/src/configuration/utils/checkSerializationVersion.ts +2 -0
  30. package/src/configuration/utils/findDocumentAtRevision.ts +2 -0
  31. package/src/configuration/utils/findLatestDraft.ts +2 -0
  32. package/src/hooks/useClient.ts +3 -1
  33. package/src/hooks/useSecrets.ts +2 -0
  34. package/src/index.ts +70 -32
  35. package/src/translation/checkTranslationStatus.ts +42 -0
  36. package/src/translation/createJobs.ts +16 -0
  37. package/src/translation/downloadTranslations.ts +68 -0
  38. package/src/translation/importDocument.ts +24 -0
  39. package/src/translation/initProject.ts +61 -0
  40. package/src/translation/uploadFiles.ts +32 -0
  41. package/src/types.ts +4 -1
  42. package/src/utils/applyDocuments.ts +72 -0
  43. package/src/utils/serialize.ts +32 -0
  44. package/src/utils/shared.ts +1 -0
  45. package/src/configuration/baseDocumentLevelConfig/helpers/index.ts +0 -5
  46. package/src/configuration/baseDocumentLevelConfig/legacyDocumentLevelPatch.ts +0 -69
  47. package/src/configuration/index.ts +0 -18
  48. package/src/configuration/utils/index.ts +0 -3
package/dist/index.js CHANGED
@@ -1,13 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), o = require("react"), sanity = require("sanity"), content = require("@sanity/util/content"), ui = require("@sanity/ui"), icons = require("@sanity/icons"), sanityNaiveHtmlSerializer = require("sanity-naive-html-serializer"), generaltranslation = require("generaltranslation"), internal = require("generaltranslation/internal");
3
+ var jsxRuntime = require("react/jsx-runtime"), o = require("react"), sanity = require("sanity"), content = require("@sanity/util/content"), ui = require("@sanity/ui"), generaltranslation = require("generaltranslation"), internal = require("generaltranslation/internal"), icons = require("@sanity/icons"), sanityNaiveHtmlSerializer = require("sanity-naive-html-serializer"), jsonpathPlus = require("jsonpath-plus"), JSONPointer = require("jsonpointer");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var o__default = /* @__PURE__ */ _interopDefaultCompat(o);
7
+ var o__default = /* @__PURE__ */ _interopDefaultCompat(o), JSONPointer__default = /* @__PURE__ */ _interopDefaultCompat(JSONPointer);
8
8
  const TranslationContext = o__default.default.createContext(
9
9
  null
10
- );
10
+ ), SECRETS_NAMESPACE = "generaltranslation", gt = new generaltranslation.GT();
11
+ function overrideConfig(secrets) {
12
+ gt.setConfig({
13
+ ...secrets?.project && { projectId: secrets?.project },
14
+ ...secrets?.secret && { apiKey: secrets?.secret }
15
+ });
16
+ }
17
+ class GTConfig {
18
+ secretsNamespace;
19
+ languageField;
20
+ sourceLocale;
21
+ locales;
22
+ singletons;
23
+ singletonMapping;
24
+ ignoreFields;
25
+ translateDocuments;
26
+ static instance;
27
+ constructor(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, translateDocuments) {
28
+ this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.translateDocuments = translateDocuments;
29
+ }
30
+ static getInstance() {
31
+ return this.instance || (this.instance = new GTConfig(
32
+ SECRETS_NAMESPACE,
33
+ "language",
34
+ gt.sourceLocale || internal.libraryDefaultLocale,
35
+ [],
36
+ [],
37
+ () => "",
38
+ [],
39
+ []
40
+ )), this.instance;
41
+ }
42
+ init(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, translateDocuments) {
43
+ this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.translateDocuments = translateDocuments;
44
+ }
45
+ getSecretsNamespace() {
46
+ return this.secretsNamespace;
47
+ }
48
+ getLanguageField() {
49
+ return this.languageField;
50
+ }
51
+ getSourceLocale() {
52
+ return this.sourceLocale;
53
+ }
54
+ getLocales() {
55
+ return this.locales;
56
+ }
57
+ getSingletons() {
58
+ return this.singletons;
59
+ }
60
+ getSingletonMapping() {
61
+ return this.singletonMapping;
62
+ }
63
+ getIgnoreFields() {
64
+ return this.ignoreFields;
65
+ }
66
+ getTranslateDocuments() {
67
+ return this.translateDocuments;
68
+ }
69
+ }
70
+ const gtConfig = GTConfig.getInstance();
11
71
  var __assign = function() {
12
72
  return __assign = Object.assign || function(t) {
13
73
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -1549,7 +1609,7 @@ const LanguageStatus = ({
1549
1609
  ] }) })
1550
1610
  ] });
1551
1611
  }, TranslationView = () => {
1552
- const [locales, setLocales] = o.useState([]), [task, setTask] = o.useState(null), context = o.useContext(TranslationContext), toast = ui.useToast();
1612
+ const [locales, setLocales] = o.useState([]), [task, setTask] = o.useState(null), context = o.useContext(TranslationContext), toast = ui.useToast(), currentDocumentLanguage = o.useMemo(() => !context?.document || !context?.languageField ? null : context.document[context.languageField] || gtConfig.getSourceLocale(), [context?.document, context?.languageField]), shouldShowTranslationComponents = o.useMemo(() => currentDocumentLanguage ? currentDocumentLanguage === gtConfig.getSourceLocale() : !1, [currentDocumentLanguage]);
1553
1613
  o.useEffect(() => {
1554
1614
  async function fetchData() {
1555
1615
  if (!context) {
@@ -1589,11 +1649,16 @@ const LanguageStatus = ({
1589
1649
  );
1590
1650
  task2 && setTask(task2);
1591
1651
  }, [context, setTask]);
1592
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 6, children: [
1652
+ return shouldShowTranslationComponents ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 6, children: [
1593
1653
  /* @__PURE__ */ jsxRuntime.jsx(NewTask, { locales, refreshTask }),
1594
1654
  task && /* @__PURE__ */ jsxRuntime.jsx(TaskView, { task, locales, refreshTask })
1595
- ] });
1596
- }, useClient = () => sanity.useClient({ apiVersion: "2022-12-07" });
1655
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 4, tone: "neutral", border: !0, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, children: [
1656
+ "Translation tools are only available for",
1657
+ " ",
1658
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: gtConfig.getSourceLocale() }),
1659
+ " documents."
1660
+ ] }) });
1661
+ }, useClient = () => sanity.useClient({ apiVersion: "2025-09-15" });
1597
1662
  function useSecrets(id) {
1598
1663
  const [loading, setLoading] = o.useState(!0), [secrets, setSecrets] = o.useState(null), client = useClient();
1599
1664
  return o.useEffect(() => {
@@ -1668,6 +1733,8 @@ const TranslationTab = (props) => {
1668
1733
  {
1669
1734
  value: {
1670
1735
  documentInfo: { documentId, versionId: revisionId },
1736
+ document: displayed,
1737
+ languageField: props.options.languageField || "language",
1671
1738
  secrets,
1672
1739
  importTranslation,
1673
1740
  exportForTranslation,
@@ -1681,40 +1748,99 @@ const TranslationTab = (props) => {
1681
1748
  }
1682
1749
  )
1683
1750
  ] }) }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.ThemeProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "caution", padding: [2, 3, 4, 4], shadow: 1, radius: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Can't find secrets for your translation service. Did you load them into this dataset?" }) }) }) });
1684
- }, findDocumentAtRevision = async (documentId, rev, client) => {
1685
- const baseUrl = `/data/history/${client.config().dataset}/documents/${documentId}?revision=${rev}`, url = client.getUrl(baseUrl);
1686
- return await fetch(url, { credentials: "include" }).then((req) => req.json()).then((req) => req.documents && req.documents.length ? req.documents[0] : null);
1687
1751
  }, findLatestDraft = (documentId, client) => {
1688
1752
  const query = "*[_id == $id || _id == $draftId]", params = { id: documentId, draftId: `drafts.${documentId}` };
1689
1753
  return client.fetch(query, params).then(
1690
1754
  (docs) => docs.find((doc) => doc._id.startsWith("drafts.")) ?? docs[0]
1691
1755
  );
1692
- }, createI18nDocAndPatchMetadata = (translatedDoc, localeId, client, translationMetadata, languageField = "language") => {
1756
+ }, findDocumentAtRevision = async (documentId, rev, client) => {
1757
+ const baseUrl = `/data/history/${client.config().dataset}/documents/${documentId}?revision=${rev}`, url = client.getUrl(baseUrl);
1758
+ return await fetch(url, { credentials: "include" }).then((req) => req.json()).then((req) => req.documents && req.documents.length ? req.documents[0] : null);
1759
+ };
1760
+ function applyDocuments(documentId, sourceDocument, targetDocument, ignore) {
1761
+ const ignoreFields = ignore.filter(
1762
+ (field) => field.documentId === documentId || field.documentId === void 0 || field.documentId === null
1763
+ ), mergedDocument = { ...sourceDocument };
1764
+ for (const [key, value] of Object.entries(targetDocument))
1765
+ mergedDocument[key] = value;
1766
+ for (const ignoreField of ignoreFields)
1767
+ if (ignoreField.fields)
1768
+ for (const field of ignoreField.fields) {
1769
+ const { property, type } = field;
1770
+ try {
1771
+ const sourceResults = jsonpathPlus.JSONPath({
1772
+ json: sourceDocument,
1773
+ path: property,
1774
+ resultType: "all",
1775
+ flatten: !0,
1776
+ wrap: !0
1777
+ });
1778
+ sourceResults && sourceResults.length > 0 && sourceResults.forEach((result) => {
1779
+ const sourceValue = result.value;
1780
+ type !== void 0 ? typeof sourceValue == "object" && sourceValue !== null && sourceValue._type === type && JSONPointer__default.default.set(mergedDocument, result.pointer, sourceValue) : JSONPointer__default.default.set(mergedDocument, result.pointer, sourceValue);
1781
+ });
1782
+ } catch (error) {
1783
+ console.warn(`Invalid JSONPath: ${property}`, error);
1784
+ }
1785
+ }
1786
+ return mergedDocument;
1787
+ }
1788
+ async function createI18nDocAndPatchMetadata(sourceDocument, translatedDoc, localeId, client, translationMetadata, sourceDocumentId, languageField = "language", publish = !1) {
1693
1789
  translatedDoc[languageField] = localeId;
1694
1790
  const existingLocaleKey = translationMetadata.translations.find(
1695
1791
  (translation) => translation._key === localeId
1696
- ), operation = existingLocaleKey ? "replace" : "after", location = existingLocaleKey ? `translations[_key == "${localeId}"]` : "translations[-1]", { _updatedAt, _createdAt, ...rest } = translatedDoc;
1697
- client.create({ ...rest, _id: "drafts." }).then((doc) => {
1698
- const _ref = doc._id.replace("drafts.", "");
1699
- client.transaction().patch(
1700
- translationMetadata._id,
1701
- (p) => p.insert(operation, location, [
1702
- {
1703
- _key: localeId,
1704
- _type: "internationalizedArrayReferenceValue",
1705
- value: {
1706
- _type: "reference",
1707
- _ref,
1708
- _weak: !0,
1709
- _strengthenOnPublish: {
1710
- type: doc._type
1711
- }
1792
+ ), operation = existingLocaleKey ? "replace" : "after", location = existingLocaleKey ? `translations[_key == "${localeId}"]` : "translations[-1]", { _updatedAt, _createdAt, ...rest } = translatedDoc, appliedDocument = applyDocuments(
1793
+ sourceDocumentId,
1794
+ sourceDocument,
1795
+ rest,
1796
+ gtConfig.getIgnoreFields()
1797
+ ), isSingleton = gtConfig.getSingletons().includes(sourceDocumentId);
1798
+ let createDocumentPromise;
1799
+ if (isSingleton) {
1800
+ const translatedDocId = gtConfig.getSingletonMapping()(sourceDocumentId, localeId);
1801
+ createDocumentPromise = client.create({
1802
+ ...appliedDocument,
1803
+ _type: rest._type,
1804
+ _id: `drafts.${translatedDocId}`
1805
+ });
1806
+ } else
1807
+ createDocumentPromise = client.create({
1808
+ ...appliedDocument,
1809
+ _type: rest._type,
1810
+ _id: "drafts."
1811
+ });
1812
+ const doc = await createDocumentPromise, _ref = doc._id.replace("drafts.", "");
1813
+ if (await client.transaction().patch(
1814
+ translationMetadata._id,
1815
+ (p) => p.insert(operation, location, [
1816
+ {
1817
+ _key: localeId,
1818
+ _type: "internationalizedArrayReferenceValue",
1819
+ value: {
1820
+ _type: "reference",
1821
+ _ref,
1822
+ _weak: !0,
1823
+ _strengthenOnPublish: {
1824
+ type: doc._type
1712
1825
  }
1713
1826
  }
1714
- ])
1715
- ).commit();
1716
- });
1717
- }, getOrCreateTranslationMetadata = async (documentId, baseDocument, client, baseLanguage) => {
1827
+ }
1828
+ ])
1829
+ ).commit(), publish)
1830
+ try {
1831
+ doc._id.startsWith("drafts.") && await client.action(
1832
+ {
1833
+ actionType: "sanity.action.document.publish",
1834
+ draftId: doc._id,
1835
+ publishedId: doc._id.replace("drafts.", "")
1836
+ },
1837
+ {}
1838
+ );
1839
+ } catch (error) {
1840
+ console.error("Error publishing document", error);
1841
+ }
1842
+ }
1843
+ const getOrCreateTranslationMetadata = async (documentId, baseDocument, client, baseLanguage) => {
1718
1844
  const existingMetadata = await client.fetch(
1719
1845
  `*[
1720
1846
  _type == 'translation.metadata' &&
@@ -1759,43 +1885,38 @@ const TranslationTab = (props) => {
1759
1885
  return metadata;
1760
1886
  throw error;
1761
1887
  }
1762
- }, patchI18nDoc = (i18nDocId, mergedDocument, translatedFields, client) => {
1888
+ }, SYSTEM_FIELDS = ["_id", "_rev", "_updatedAt", "language"], isSystemField = (field) => SYSTEM_FIELDS.includes(field);
1889
+ async function patchI18nDoc(sourceDocumentId, i18nDocId, sourceDocument, mergedDocument, translatedFields, client, publish = !1) {
1763
1890
  const cleanedMerge = {};
1764
1891
  Object.entries(mergedDocument).forEach(([key, value]) => {
1765
1892
  key in translatedFields && //don't overwrite any existing system values on the i18n doc
1766
- !["_id", "_rev", "_updatedAt", "language"].includes(key) && (cleanedMerge[key] = value);
1767
- }), client.transaction().patch(i18nDocId, (p) => p.set(cleanedMerge)).commit();
1768
- }, gt = new generaltranslation.GT();
1769
- function overrideConfig(secrets) {
1770
- gt.setConfig({
1771
- ...secrets?.project && { projectId: secrets?.project },
1772
- ...secrets?.secret && { apiKey: secrets?.secret }
1893
+ !isSystemField(key) && (cleanedMerge[key] = value);
1773
1894
  });
1895
+ const cleanedSourceDocument = {};
1896
+ Object.entries(sourceDocument).forEach(([key, value]) => {
1897
+ isSystemField(key) || (cleanedSourceDocument[key] = value);
1898
+ });
1899
+ const appliedDocument = applyDocuments(
1900
+ sourceDocumentId,
1901
+ cleanedSourceDocument,
1902
+ cleanedMerge,
1903
+ gtConfig.getIgnoreFields()
1904
+ ), newDocument = await client.patch(i18nDocId, { set: appliedDocument }).commit();
1905
+ if (publish)
1906
+ try {
1907
+ newDocument._id.startsWith("drafts.") && await client.action(
1908
+ {
1909
+ actionType: "sanity.action.document.publish",
1910
+ draftId: newDocument._id,
1911
+ publishedId: newDocument._id.replace("drafts.", "")
1912
+ },
1913
+ {}
1914
+ );
1915
+ } catch (error) {
1916
+ console.error("Error publishing document", error);
1917
+ }
1774
1918
  }
1775
- class GTConfig {
1776
- sourceLocale;
1777
- locales;
1778
- static instance;
1779
- constructor(sourceLocale, locales) {
1780
- this.sourceLocale = sourceLocale, this.locales = locales;
1781
- }
1782
- static getInstance() {
1783
- return this.instance || (this.instance = new GTConfig(gt.sourceLocale || internal.libraryDefaultLocale, [])), this.instance;
1784
- }
1785
- setSourceLocale(sourceLocale) {
1786
- this.sourceLocale = sourceLocale;
1787
- }
1788
- getSourceLocale() {
1789
- return this.sourceLocale;
1790
- }
1791
- setLocales(locales) {
1792
- this.locales = locales;
1793
- }
1794
- getLocales() {
1795
- return this.locales;
1796
- }
1797
- }
1798
- const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, translatedFields, localeId, client, languageField = "language", mergeWithTargetLocale = !1) => {
1919
+ const documentLevelPatch = async (docInfo, translatedFields, localeId, client, languageField = "language", mergeWithTargetLocale = !1, publish = !1) => {
1799
1920
  const baseLanguage = gtConfig.getSourceLocale();
1800
1921
  let baseDoc = null, i18nDoc = null;
1801
1922
  docInfo.documentId && docInfo.versionId && (baseDoc = await findDocumentAtRevision(
@@ -1818,31 +1939,24 @@ const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, tr
1818
1939
  translatedFields,
1819
1940
  baseDoc
1820
1941
  );
1821
- i18nDoc ? patchI18nDoc(docInfo.documentId, merged, translatedFields, client) : createI18nDocAndPatchMetadata(
1942
+ i18nDoc ? await patchI18nDoc(
1943
+ docInfo.documentId,
1944
+ i18nDoc._id,
1945
+ baseDoc,
1946
+ merged,
1947
+ translatedFields,
1948
+ client,
1949
+ publish
1950
+ ) : await createI18nDocAndPatchMetadata(
1951
+ baseDoc,
1822
1952
  merged,
1823
1953
  localeId,
1824
1954
  client,
1825
1955
  translationMetadata,
1826
- languageField
1827
- );
1828
- }, legacyDocumentLevelPatch = async (docInfo, translatedFields, localeId, client) => {
1829
- let baseDoc = null;
1830
- docInfo.documentId && docInfo.versionId && (baseDoc = await findDocumentAtRevision(
1831
1956
  docInfo.documentId,
1832
- docInfo.versionId,
1833
- client
1834
- )), baseDoc || (baseDoc = await findLatestDraft(docInfo.documentId, client));
1835
- const merged = sanityNaiveHtmlSerializer.BaseDocumentMerger.documentLevelMerge(
1836
- translatedFields,
1837
- baseDoc
1838
- ), targetId = `drafts.${docInfo.documentId}__i18n_${localeId}`, i18nDoc = await findLatestDraft(targetId, client);
1839
- if (i18nDoc) {
1840
- const cleanedMerge = {};
1841
- Object.entries(merged).forEach(([key, value]) => {
1842
- Object.keys(translatedFields).includes(key) && !["_id", "_rev", "_updatedAt"].includes(key) && (cleanedMerge[key] = value);
1843
- }), await client.transaction().patch(i18nDoc._id, (p) => p.set(cleanedMerge)).commit();
1844
- } else
1845
- merged._id = targetId, merged.__i18n_lang = localeId, await client.create(merged);
1957
+ languageField,
1958
+ publish
1959
+ );
1846
1960
  }, baseDocumentLevelConfig = {
1847
1961
  exportForTranslation: async (...params) => {
1848
1962
  const [
@@ -1882,7 +1996,8 @@ const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, tr
1882
1996
  context,
1883
1997
  serializationOptions = {},
1884
1998
  languageField = "language",
1885
- mergeWithTargetLocale = !1
1999
+ mergeWithTargetLocale = !1,
2000
+ publish = !1
1886
2001
  ] = params, { client } = context, deserializers = {
1887
2002
  types: {
1888
2003
  ...serializationOptions.additionalDeserializers ?? {}
@@ -1902,33 +2017,11 @@ const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, tr
1902
2017
  localeId,
1903
2018
  client,
1904
2019
  languageField,
1905
- mergeWithTargetLocale
2020
+ mergeWithTargetLocale,
2021
+ publish
1906
2022
  );
1907
2023
  },
1908
2024
  secretsNamespace: "translationService"
1909
- }, legacyDocumentLevelConfig$1 = {
1910
- ...baseDocumentLevelConfig,
1911
- importTranslation: (...params) => {
1912
- const [docInfo, localeId, document2, context, serializationOptions = {}] = params, { client } = context, deserializers = {
1913
- types: {
1914
- ...serializationOptions.additionalDeserializers ?? {}
1915
- }
1916
- }, blockDeserializers = [
1917
- ...serializationOptions.additionalBlockDeserializers ?? [],
1918
- ...sanityNaiveHtmlSerializer.customBlockDeserializers
1919
- ], deserialized = sanityNaiveHtmlSerializer.BaseDocumentDeserializer.deserializeDocument(
1920
- document2,
1921
- deserializers,
1922
- blockDeserializers
1923
- );
1924
- return legacyDocumentLevelPatch(
1925
- docInfo,
1926
- // versionId is not used here, since we just use the _rev id in the deserialized HTML itself
1927
- deserialized,
1928
- localeId,
1929
- client
1930
- );
1931
- }
1932
2025
  }, fieldLevelPatch = async (docInfo, translatedFields, localeId, client, mergeWithTargetLocale = !1) => {
1933
2026
  let baseDoc;
1934
2027
  const baseLanguage = gtConfig.getSourceLocale();
@@ -2028,7 +2121,7 @@ const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, tr
2028
2121
  versionId: documentInfo.versionId || void 0,
2029
2122
  locale: localeId
2030
2123
  })) : "", createTask = async (documentInfo, serializedDocument, localeIds, secrets, workflowUid, callbackUrl) => {
2031
- const fileName = `sanity-${documentInfo.documentId}`;
2124
+ const fileName = `sanity/${documentInfo.documentId}`;
2032
2125
  overrideConfig(secrets);
2033
2126
  const uploadResult = await gt.uploadSourceFiles(
2034
2127
  [
@@ -2060,22 +2153,42 @@ const gtConfig = GTConfig.getInstance(), documentLevelPatch = async (docInfo, tr
2060
2153
  ...baseDocumentLevelConfig,
2061
2154
  adapter: GTAdapter,
2062
2155
  secretsNamespace: "generaltranslation"
2063
- }, legacyDocumentLevelConfig = {
2064
- ...legacyDocumentLevelConfig$1,
2065
- adapter: GTAdapter,
2066
- secretsNamespace: "generaltranslation"
2067
2156
  }, defaultFieldLevelConfig = {
2068
2157
  ...baseFieldLevelConfig,
2069
2158
  adapter: GTAdapter,
2070
2159
  secretsNamespace: "generaltranslation"
2071
- }, gtPlugin = sanity.definePlugin(({ sourceLocale, locales, customMapping, apiKey, projectId }) => (gtConfig.setLocales(locales), gtConfig.setSourceLocale(sourceLocale || internal.libraryDefaultLocale), gt.setConfig({
2072
- sourceLocale,
2073
- customMapping,
2074
- apiKey,
2075
- projectId
2076
- }), {
2077
- name: "@generaltranslation/sanity"
2078
- }));
2160
+ }, gtPlugin = sanity.definePlugin(
2161
+ ({
2162
+ languageField = "language",
2163
+ sourceLocale = internal.libraryDefaultLocale,
2164
+ locales,
2165
+ customMapping,
2166
+ apiKey,
2167
+ projectId,
2168
+ singletons,
2169
+ singletonMapping,
2170
+ ignoreFields,
2171
+ translateDocuments,
2172
+ secretsNamespace = SECRETS_NAMESPACE
2173
+ }) => (translateDocuments = translateDocuments?.filter((filter2) => !!(filter2.documentId || filter2.type)), gtConfig.init(
2174
+ secretsNamespace,
2175
+ languageField,
2176
+ sourceLocale,
2177
+ locales,
2178
+ singletons || [],
2179
+ // singletons is a string array of singleton document ids
2180
+ singletonMapping || ((sourceDocumentId, locale) => `${sourceDocumentId}-${locale}`),
2181
+ ignoreFields || [],
2182
+ translateDocuments || []
2183
+ ), gt.setConfig({
2184
+ sourceLocale,
2185
+ customMapping,
2186
+ apiKey,
2187
+ projectId
2188
+ }), {
2189
+ name: "gt-sanity"
2190
+ })
2191
+ );
2079
2192
  Object.defineProperty(exports, "BaseDocumentDeserializer", {
2080
2193
  enumerable: !0,
2081
2194
  get: function() {
@@ -2114,6 +2227,4 @@ exports.documentLevelPatch = documentLevelPatch;
2114
2227
  exports.fieldLevelPatch = fieldLevelPatch;
2115
2228
  exports.findLatestDraft = findLatestDraft;
2116
2229
  exports.gtPlugin = gtPlugin;
2117
- exports.legacyDocumentLevelConfig = legacyDocumentLevelConfig;
2118
- exports.legacyDocumentLevelPatch = legacyDocumentLevelPatch;
2119
2230
  //# sourceMappingURL=index.js.map