contensis-cli 1.5.1-beta.7 → 1.5.1-beta.9

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.
@@ -42,7 +42,7 @@ var import_rfdc = __toESM(require("rfdc"));
42
42
  var import_migratortron = require("migratortron");
43
43
  var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
44
44
  var import_en_GB = require("../localisation/en-GB");
45
- var import_file_provider = require("../providers/file-provider");
45
+ var import_MixedFileData = require("../mappers/MixedFileData");
46
46
  var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
47
47
  var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
48
48
  var import_util = require("../util");
@@ -262,16 +262,13 @@ class ContensisCli {
262
262
  };
263
263
  ConnectContensisImport = async ({
264
264
  commit = false,
265
+ noSource = false,
265
266
  fromFile,
266
- importDataType,
267
- importData,
268
- mixedData
267
+ importData
269
268
  }) => {
270
269
  var _a, _b, _c, _d, _e, _f;
271
- const source = fromFile || importData || mixedData ? "file" : "contensis";
272
- const fileData = importData || (fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : []);
273
- if (typeof fileData === "string")
274
- throw new Error(`Import file format must be of type JSON`);
270
+ const source = fromFile || importData || noSource ? "user-input" : "contensis";
271
+ const mixedData = fromFile ? await new import_MixedFileData.MixedFileData().readFile(fromFile) : importData;
275
272
  const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
276
273
  const environments = this.cache.environments || {};
277
274
  const sourceEnvironment = environments[sourceAlias || ""] || {};
@@ -297,7 +294,7 @@ class ContensisCli {
297
294
  );
298
295
  const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
299
296
  if (cachedSourcePassword && cachedTargetPassword) {
300
- if (source === "file" || importDataType === "user-input") {
297
+ if (source === "user-input") {
301
298
  this.contensis = new import_migratortron.ContensisMigrationService(
302
299
  {
303
300
  concurrency: 2,
@@ -312,7 +309,6 @@ class ContensisCli {
312
309
  targetProjects: [env.currentProject || ""],
313
310
  assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
314
311
  },
315
- ...importDataType ? { [importDataType]: fileData } : {},
316
312
  ...mixedData || {}
317
313
  },
318
314
  !commit
@@ -891,14 +887,16 @@ class ContensisCli {
891
887
  }) => {
892
888
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
893
889
  const { currentEnv, currentProject, log, messages } = this;
890
+ let importData;
891
+ if (tags) {
892
+ importData = new import_MixedFileData.MixedFileData();
893
+ importData.tags = tags;
894
+ importData.tagGroups = data || [];
895
+ }
894
896
  const contensis = await this.ConnectContensisImport({
895
897
  commit,
896
898
  fromFile,
897
- importDataType: tags ? "user-input" : "tagGroups",
898
- mixedData: {
899
- tagGroups: data,
900
- tags
901
- }
899
+ importData
902
900
  });
903
901
  if (contensis) {
904
902
  log.line();
@@ -994,10 +992,7 @@ class ContensisCli {
994
992
  withDependents
995
993
  });
996
994
  if (Array.isArray(result)) {
997
- let tags = [];
998
- const groups = [];
999
- if (withDependents) (0, import_util.splitTagsAndGroups)(result, tags, groups);
1000
- else tags = result;
995
+ const { tags, tagGroups } = new import_MixedFileData.MixedFileData(result);
1001
996
  log.success(messages.tags.list(currentEnv, tags.length));
1002
997
  if (tags)
1003
998
  await this.HandleFormattingAndOutput(result, () => {
@@ -1005,10 +1000,12 @@ class ContensisCli {
1005
1000
  log.raw("");
1006
1001
  log.object(tag);
1007
1002
  }
1008
- if (groups.length) {
1003
+ if (tagGroups.length) {
1009
1004
  log.raw("");
1010
- log.success(messages.taggroups.list(currentEnv, groups.length));
1011
- for (const group of groups) {
1005
+ log.success(
1006
+ messages.taggroups.list(currentEnv, tagGroups.length)
1007
+ );
1008
+ for (const group of tagGroups) {
1012
1009
  log.raw("");
1013
1010
  log.object(group);
1014
1011
  }
@@ -1027,10 +1024,7 @@ class ContensisCli {
1027
1024
  withDependents
1028
1025
  });
1029
1026
  if (Array.isArray(result)) {
1030
- let tags = [];
1031
- const groups = [];
1032
- if (withDependents) (0, import_util.splitTagsAndGroups)(result, tags, groups);
1033
- else tags = result;
1027
+ const { tags, tagGroups } = new import_MixedFileData.MixedFileData(result);
1034
1028
  log.success(messages.tags.list(currentEnv, tags.length));
1035
1029
  if (!tags.length) log.help(messages.tags.noneExist());
1036
1030
  await this.HandleFormattingAndOutput(result, () => {
@@ -1038,10 +1032,10 @@ class ContensisCli {
1038
1032
  log.raw("");
1039
1033
  log.object(tag);
1040
1034
  }
1041
- if (groups.length) {
1035
+ if (tagGroups.length) {
1042
1036
  log.raw("");
1043
- log.success(messages.taggroups.list(currentEnv, groups.length));
1044
- for (const { version, ...group } of groups) {
1037
+ log.success(messages.taggroups.list(currentEnv, tagGroups.length));
1038
+ for (const { version, ...group } of tagGroups) {
1045
1039
  log.raw("");
1046
1040
  log.object(group);
1047
1041
  }
@@ -1060,23 +1054,20 @@ class ContensisCli {
1060
1054
  }) => {
1061
1055
  var _a, _b, _c, _d, _e, _f, _g, _h;
1062
1056
  const { currentEnv, currentProject, log, messages } = this;
1063
- const mixedData = { tags: [], tagGroups: [] };
1057
+ let importData;
1064
1058
  if (data) {
1065
- mixedData.tags = data;
1066
- mixedData.tagGroups = [...new Set(data.map((t) => t.groupId))].map(
1059
+ importData = new import_MixedFileData.MixedFileData();
1060
+ importData.tags = data;
1061
+ importData.tagGroups = [...new Set(data.map((t) => t.groupId))].map(
1067
1062
  (id) => ({
1068
1063
  id
1069
1064
  })
1070
1065
  );
1071
1066
  }
1072
- if (fromFile) {
1073
- const fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1074
- (0, import_util.splitTagsAndGroups)(fileData, mixedData.tags, mixedData.tagGroups);
1075
- }
1076
1067
  const contensis = await this.ConnectContensisImport({
1077
1068
  commit,
1078
- importDataType: "tags",
1079
- mixedData
1069
+ fromFile,
1070
+ importData
1080
1071
  });
1081
1072
  if (contensis) {
1082
1073
  log.line();
@@ -1136,8 +1127,7 @@ class ContensisCli {
1136
1127
  this.contensisOpts.concurrency = 1;
1137
1128
  const contensis = await this.ConnectContensisImport({
1138
1129
  commit,
1139
- importDataType: "user-input"
1140
- // 'user-input' import type does not require a source cms
1130
+ noSource: true
1141
1131
  });
1142
1132
  if (contensis) {
1143
1133
  log.line();
@@ -1393,14 +1383,9 @@ class ContensisCli {
1393
1383
  fromFile
1394
1384
  }) => {
1395
1385
  const { currentProject, log, messages } = this;
1396
- const mixedData = { models: [], tagGroups: [] };
1397
- if (fromFile) {
1398
- const fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1399
- (0, import_util.splitTagGroupsInModels)(fileData, mixedData.models, mixedData.tagGroups);
1400
- }
1401
1386
  const contensis = await this.ConnectContensisImport({
1402
1387
  commit,
1403
- mixedData: mixedData.models.length ? mixedData : void 0
1388
+ fromFile
1404
1389
  });
1405
1390
  if (contensis) {
1406
1391
  log.line();
@@ -1544,8 +1529,7 @@ Nodes:`));
1544
1529
  const { currentProject, log, messages } = this;
1545
1530
  const contensis = await this.ConnectContensisImport({
1546
1531
  commit,
1547
- importDataType: "user-input"
1548
- // 'user-input' import type does not require a source cms
1532
+ noSource: true
1549
1533
  });
1550
1534
  if (contensis) {
1551
1535
  const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
@@ -1575,17 +1559,15 @@ Nodes:`));
1575
1559
  fromFile
1576
1560
  }, contentTypeIds = []) => {
1577
1561
  const { currentProject, log, messages } = this;
1578
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1579
- if (typeof fileData === "string")
1580
- throw new Error(`Import file format must be of type JSON`);
1581
- if (!Array.isArray(fileData)) fileData = [fileData];
1562
+ let importData;
1563
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1582
1564
  const contensis = await this.ConnectContensisImport({
1583
1565
  commit,
1584
- importDataType: fromFile ? "user-input" : void 0
1566
+ noSource: !!fromFile
1585
1567
  });
1586
1568
  if (contensis) {
1587
1569
  if (fromFile)
1588
- for (const contentType of fileData) {
1570
+ for (const contentType of importData.models) {
1589
1571
  contentType.projectId = currentProject;
1590
1572
  delete contentType.uuid;
1591
1573
  const [err, , createStatus] = await contensis.models.targets[currentProject].repo.UpsertContentType(false, contentType);
@@ -1616,17 +1598,14 @@ Nodes:`));
1616
1598
  fromFile
1617
1599
  }, modelIds = []) => {
1618
1600
  const { log } = this;
1619
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1620
- if (typeof fileData === "string")
1621
- throw new Error(`Import file format must be of type JSON`);
1622
- if (!Array.isArray(fileData)) fileData = [fileData];
1623
- const contensis = await this.ConnectContensisImport({
1624
- fromFile,
1625
- importDataType: "models"
1626
- });
1601
+ let importData;
1602
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1603
+ const contensis = await this.ConnectContensisImport({ fromFile });
1627
1604
  if (contensis) {
1628
1605
  const [err, result] = await (0, import_await_to_js.default)(
1629
- contensis.models.Diff(fileData.length ? fileData : modelIds)
1606
+ contensis.models.Diff(
1607
+ importData.models.length ? importData.models : modelIds
1608
+ )
1630
1609
  );
1631
1610
  if (err) log.error(err.message, err);
1632
1611
  if (result)
@@ -1693,8 +1672,7 @@ Components:`));
1693
1672
  const { currentProject, log, messages } = this;
1694
1673
  const contensis = await this.ConnectContensisImport({
1695
1674
  commit,
1696
- importDataType: "user-input"
1697
- // 'user-input' import type does not require a source cms
1675
+ noSource: true
1698
1676
  });
1699
1677
  if (contensis) {
1700
1678
  const [err, result] = await contensis.DeleteContentTypes(
@@ -1727,17 +1705,15 @@ Components:`));
1727
1705
  fromFile
1728
1706
  }, componentIds = []) => {
1729
1707
  const { currentProject, log, messages } = this;
1730
- let fileData = fromFile ? await (0, import_file_provider.readFileAsJSON)(fromFile) || [] : [];
1731
- if (typeof fileData === "string")
1732
- throw new Error(`Import file format must be of type JSON`);
1733
- if (!Array.isArray(fileData)) fileData = [fileData];
1708
+ let importData;
1709
+ if (fromFile) importData = await new import_MixedFileData.MixedFileData().readFile(fromFile);
1734
1710
  const contensis = await this.ConnectContensisImport({
1735
1711
  commit,
1736
- importDataType: fromFile ? "user-input" : void 0
1712
+ noSource: !!fromFile
1737
1713
  });
1738
1714
  if (contensis) {
1739
1715
  if (fromFile)
1740
- for (const component of fileData) {
1716
+ for (const component of importData.models) {
1741
1717
  component.projectId = currentProject;
1742
1718
  delete component.uuid;
1743
1719
  const [err, , createStatus] = await contensis.models.targets[currentProject].repo.UpsertComponent(false, component);
@@ -1770,8 +1746,7 @@ Components:`));
1770
1746
  this.contensisOpts.concurrency = 1;
1771
1747
  const contensis = await this.ConnectContensisImport({
1772
1748
  commit,
1773
- importDataType: "user-input"
1774
- // 'user-input' import type does not require a source cms
1749
+ noSource: true
1775
1750
  });
1776
1751
  if (contensis) {
1777
1752
  if (contensis.isPreview) {
@@ -1836,13 +1811,14 @@ Components:`));
1836
1811
  saveEntries,
1837
1812
  data
1838
1813
  }) => {
1839
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1814
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1840
1815
  const { currentEnv, currentProject, log, messages } = this;
1816
+ let importData;
1817
+ if (data) importData = new import_MixedFileData.MixedFileData(data);
1841
1818
  const contensis = await this.ConnectContensisImport({
1842
1819
  commit,
1843
1820
  fromFile,
1844
- importDataType: "entries",
1845
- importData: data
1821
+ importData
1846
1822
  });
1847
1823
  if (contensis) {
1848
1824
  log.line();
@@ -1854,12 +1830,14 @@ Components:`));
1854
1830
  const [err, result] = await contensis.MigrateEntries();
1855
1831
  if (err) (0, import_logger.logError)(err);
1856
1832
  else {
1857
- const { entries, nodes } = contensis.content.targets[currentProject];
1833
+ const { entries, nodes, tags } = contensis.content.targets[currentProject];
1858
1834
  const output = saveEntries ? (
1859
- // include entries and dependent nodes when saving entries
1835
+ // include entries and dependent nodes (or tags) when saving entries
1860
1836
  [
1861
1837
  ((_a = entries.migrate) == null ? void 0 : _a.map((me) => me.toJSON())) || [],
1862
- nodes.migrateNodes.map((mn) => mn.node)
1838
+ nodes.migrateNodes.map((mn) => mn.node),
1839
+ tags.migrateTags.map((mt) => mt.toJSON()),
1840
+ tags.migrateGroups.map((mg) => mg.toJSON())
1863
1841
  ].flat()
1864
1842
  ) : result;
1865
1843
  await this.HandleFormattingAndOutput(output, () => {
@@ -1886,7 +1864,8 @@ Components:`));
1886
1864
  currentEnv,
1887
1865
  commit,
1888
1866
  commit ? (((_e = result.migrateResult) == null ? void 0 : _e.created) || 0) + (((_f = result.migrateResult) == null ? void 0 : _f.updated) || 0) : result.entriesToMigrate[currentProject].totalCount,
1889
- commit ? (((_g = result.nodesResult) == null ? void 0 : _g.created) || 0) + (((_h = result.nodesResult) == null ? void 0 : _h.updated) || 0) : ((_i = result.nodesToMigrate) == null ? void 0 : _i[currentProject].totalCount) || 0
1867
+ commit ? (((_g = result.nodesResult) == null ? void 0 : _g.created) || 0) + (((_h = result.nodesResult) == null ? void 0 : _h.updated) || 0) : ((_i = result.nodesToMigrate) == null ? void 0 : _i[currentProject].totalCount) || 0,
1868
+ commit ? (((_j = result.tagsResult) == null ? void 0 : _j.created) || 0) + (((_k = result.tagsResult) == null ? void 0 : _k.updated) || 0) : ((_l = result.tagsToMigrate) == null ? void 0 : _l[currentProject].totalCount) || 0
1890
1869
  )
1891
1870
  );
1892
1871
  if (!commit) {
@@ -1894,14 +1873,14 @@ Components:`));
1894
1873
  log.help(messages.migrate.commitTip());
1895
1874
  }
1896
1875
  } else {
1897
- const noChanges = Object.values((_j = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _j[currentProject]).every(
1876
+ const noChanges = Object.values((_m = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _m[currentProject]).every(
1898
1877
  (status) => typeof status === "number" || (status["no change"] || 0) > 0
1899
1878
  ) && result.entriesToMigrate[currentProject].totalCount === 0;
1900
- if (noChanges && !err && !((_k = result == null ? void 0 : result.migrateResult) == null ? void 0 : _k.errors) && !((_l = result == null ? void 0 : result.nodesResult) == null ? void 0 : _l.errors)) {
1879
+ if (noChanges && !err && !((_n = result == null ? void 0 : result.migrateResult) == null ? void 0 : _n.errors) && !((_o = result == null ? void 0 : result.nodesResult) == null ? void 0 : _o.errors) && !((_p = result == null ? void 0 : result.tagsResult) == null ? void 0 : _p.errors)) {
1901
1880
  log.help(messages.entries.noChange(currentEnv));
1902
1881
  } else {
1903
1882
  log.error(messages.entries.failedImport(currentEnv), err);
1904
- if (!((_n = (_m = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _m[currentProject]) == null ? void 0 : _n.totalCount))
1883
+ if (!((_r = (_q = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _q[currentProject]) == null ? void 0 : _r.totalCount))
1905
1884
  log.help(messages.entries.notFound(currentEnv));
1906
1885
  }
1907
1886
  }
@@ -1920,8 +1899,7 @@ Components:`));
1920
1899
  const { currentEnv, currentProject, log, messages } = this;
1921
1900
  const contensis = await this.ConnectContensisImport({
1922
1901
  commit,
1923
- fromFile,
1924
- importDataType: "entries"
1902
+ fromFile
1925
1903
  });
1926
1904
  if (contensis) {
1927
1905
  log.line();
@@ -1978,8 +1956,7 @@ Components:`));
1978
1956
  const { currentEnv, currentProject, log, messages } = this;
1979
1957
  const contensis = await this.ConnectContensisImport({
1980
1958
  commit,
1981
- fromFile,
1982
- importDataType: "entries"
1959
+ fromFile
1983
1960
  });
1984
1961
  if (contensis) {
1985
1962
  log.line();
@@ -2056,8 +2033,7 @@ Components:`));
2056
2033
  const { currentEnv, currentProject, log, messages } = this;
2057
2034
  const contensis = await this.ConnectContensisImport({
2058
2035
  commit,
2059
- fromFile,
2060
- importDataType: "nodes"
2036
+ fromFile
2061
2037
  });
2062
2038
  if (contensis) {
2063
2039
  log.line();
@@ -2114,8 +2090,7 @@ Components:`));
2114
2090
  const { currentEnv, currentProject, log, messages } = this;
2115
2091
  const contensis = await this.ConnectContensisImport({
2116
2092
  commit,
2117
- importDataType: "user-input"
2118
- // 'user-input' import type does not require a source cms
2093
+ noSource: true
2119
2094
  });
2120
2095
  if (contensis) {
2121
2096
  if (contensis.isPreview) {