contensis-cli 1.6.1-beta.2 → 1.6.1-beta.4

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.
@@ -1398,7 +1398,7 @@ class ContensisCli {
1398
1398
  if (migrateErr) (0, import_logger.logError)(migrateErr);
1399
1399
  else
1400
1400
  await this.HandleFormattingAndOutput(result, () => {
1401
- if (!result.committed) {
1401
+ if (result && !(result == null ? void 0 : result.committed)) {
1402
1402
  log.raw(log.boldText(`
1403
1403
  Content types:`));
1404
1404
  if (!result.contentTypes) log.info(`- None returned
@@ -1430,7 +1430,7 @@ Errors:`));
1430
1430
  log.object(result.errors);
1431
1431
  }
1432
1432
  } else {
1433
- const { modelsResult = {} } = result;
1433
+ const { modelsResult = {} } = result || {};
1434
1434
  log.raw(log.boldText(`
1435
1435
  Content types:`));
1436
1436
  (0, import_console.printModelMigrationResult)(
@@ -1762,7 +1762,7 @@ Components:`));
1762
1762
  showAll: true
1763
1763
  });
1764
1764
  });
1765
- if (!err && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && ((_a = result.migrateResult) == null ? void 0 : _a.deleted))) {
1765
+ if (!err && (!commit && (result == null ? void 0 : result.entriesToMigrate[currentProject].totalCount) || commit && ((_a = result == null ? void 0 : result.migrateResult) == null ? void 0 : _a.deleted))) {
1766
1766
  log.success(messages.entries.removed(currentEnv, commit));
1767
1767
  if (!commit) {
1768
1768
  log.raw(``);
@@ -1829,7 +1829,7 @@ Components:`));
1829
1829
  }
1830
1830
  const [err, result] = await contensis.MigrateEntries();
1831
1831
  if (err) (0, import_logger.logError)(err);
1832
- else {
1832
+ else if (result) {
1833
1833
  const { entries, nodes, tags } = contensis.content.targets[currentProject];
1834
1834
  const output = saveEntries ? (
1835
1835
  // include entries and dependent nodes (or tags) when saving entries
@@ -1858,12 +1858,12 @@ Components:`));
1858
1858
  );
1859
1859
  });
1860
1860
  }
1861
- if (!err && !((_b = result.errors) == null ? void 0 : _b.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_c = result.migrateResult) == null ? void 0 : _c.created) || ((_d = result.migrateResult) == null ? void 0 : _d.updated)))) {
1861
+ if (!err && !((_b = result == null ? void 0 : result.errors) == null ? void 0 : _b.length) && (!commit && (result == null ? void 0 : result.entriesToMigrate[currentProject].totalCount) || commit && (((_c = result == null ? void 0 : result.migrateResult) == null ? void 0 : _c.created) || ((_d = result == null ? void 0 : result.migrateResult) == null ? void 0 : _d.updated)))) {
1862
1862
  log.success(
1863
1863
  messages.entries.imported(
1864
1864
  currentEnv,
1865
1865
  commit,
1866
- commit ? (((_e = result.migrateResult) == null ? void 0 : _e.created) || 0) + (((_f = result.migrateResult) == null ? void 0 : _f.updated) || 0) : result.entriesToMigrate[currentProject].totalCount,
1866
+ commit ? (((_e = result == null ? void 0 : result.migrateResult) == null ? void 0 : _e.created) || 0) + (((_f = result == null ? void 0 : result.migrateResult) == null ? void 0 : _f.updated) || 0) : result == null ? void 0 : result.entriesToMigrate[currentProject].totalCount,
1867
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
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
1869
1869
  )
@@ -2044,7 +2044,7 @@ Components:`));
2044
2044
  }
2045
2045
  const [err, result] = await contensis.MigrateNodes();
2046
2046
  if (err) log.raw(``);
2047
- else
2047
+ else if (result)
2048
2048
  await this.HandleFormattingAndOutput(result, () => {
2049
2049
  const migrateTree = contensis.nodes.targets[currentProject].nodes.migrateNodesTreeView;
2050
2050
  (0, import_console.printNodeTreeOutput)(this, migrateTree, logOutput, logLimit);
@@ -2058,7 +2058,7 @@ Components:`));
2058
2058
  const nodesUpdated = ((_c = result == null ? void 0 : result.nodesResult) == null ? void 0 : _c["updated"]) || 0;
2059
2059
  const nodesErrored = ((_d = result == null ? void 0 : result.nodesResult) == null ? void 0 : _d["errors"]) || 0;
2060
2060
  const noChanges = ((_e = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _e[currentProject]["no change"]) && nodesMigrateCount === 0;
2061
- if (!err && (!((_f = result.errors) == null ? void 0 : _f.length) || this.contensisOpts.ignoreErrors) && (!commit && nodesMigrateCount || commit && (nodesCreated || nodesUpdated || ((_g = result.errors) == null ? void 0 : _g.length)))) {
2061
+ if (!err && (!((_f = result == null ? void 0 : result.errors) == null ? void 0 : _f.length) || this.contensisOpts.ignoreErrors) && (!commit && nodesMigrateCount || commit && (nodesCreated || nodesUpdated || ((_g = result == null ? void 0 : result.errors) == null ? void 0 : _g.length)))) {
2062
2062
  let totalCount;
2063
2063
  if (commit) {
2064
2064
  const created = typeof nodesCreated === "number" ? nodesCreated : 0;
@@ -2107,7 +2107,7 @@ Components:`));
2107
2107
  );
2108
2108
  });
2109
2109
  }
2110
- if (!err && (!commit && result.nodesToMigrate[currentProject].totalCount || commit && ((_a = result.nodesResult) == null ? void 0 : _a.deleted))) {
2110
+ if (!err && (!commit && (result == null ? void 0 : result.nodesToMigrate[currentProject].totalCount) || commit && ((_a = result == null ? void 0 : result.nodesResult) == null ? void 0 : _a.deleted))) {
2111
2111
  log.success(
2112
2112
  messages.nodes.removed(currentEnv, commit, contensis.nodes.rootPath)
2113
2113
  );
@@ -2156,10 +2156,13 @@ Components:`));
2156
2156
  } of filteredResults) {
2157
2157
  console.log(
2158
2158
  log.infoText(
2159
- ` ${import_chalk.default.bold.white`- ${name}`} ${id} [${(version.modified || version.created).toString().substring(0, 10)} ${version.modifiedBy || version.createdBy}]`
2159
+ `${import_chalk.default.bold.white`${enabled ? "\u{1F7E2}" : "\u{1F534}"} ${name}`} ${id} [${(version.modified || version.created).toString().substring(0, 10)} ${version.modifiedBy || version.createdBy}]`
2160
2160
  )
2161
2161
  );
2162
2162
  if (description) console.log(log.infoText` ${description}`);
2163
+ console.log(
2164
+ ` ${log.infoText`enabled`}: ${import_chalk.default[enabled ? "green" : "red"](enabled)}`
2165
+ );
2163
2166
  console.log(` ${log.infoText`[${method}]`} ${url2}`);
2164
2167
  if (headers && Object.keys(headers).length) {
2165
2168
  console.log(` ${log.infoText`headers`}:`);
@@ -2183,8 +2186,6 @@ Components:`));
2183
2186
  templates
2184
2187
  ).join(" ")}`
2185
2188
  );
2186
- if (enabled === false)
2187
- console.log(` ${log.infoText`enabled`}: ${enabled}`);
2188
2189
  }
2189
2190
  });
2190
2191
  }
@@ -2195,6 +2196,68 @@ Components:`));
2195
2196
  }
2196
2197
  }
2197
2198
  };
2199
+ ImportWebhooks = async ({
2200
+ commit,
2201
+ fromFile,
2202
+ logOutput,
2203
+ enabled = false,
2204
+ disabled = false
2205
+ }) => {
2206
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2207
+ const { currentEnv, currentProject, log, messages } = this;
2208
+ const contensis = await this.ConnectContensisImport({
2209
+ commit,
2210
+ fromFile
2211
+ });
2212
+ if (contensis) {
2213
+ log.line();
2214
+ if (contensis.isPreview) {
2215
+ log.success(messages.migrate.preview());
2216
+ } else {
2217
+ log.warning(messages.migrate.commit());
2218
+ }
2219
+ const [err, result] = await (0, import_await_to_js.default)(
2220
+ contensis.webhooks.MigrateWebhooks({
2221
+ // trying to simulate XOR logic, setting enabled arg from
2222
+ // enabled or disabled option only if one of them is set
2223
+ enabled: enabled !== disabled ? enabled || !disabled : void 0
2224
+ })
2225
+ );
2226
+ if (err) (0, import_logger.logError)(err);
2227
+ else if (result) {
2228
+ await this.HandleFormattingAndOutput(result, () => {
2229
+ (0, import_console.printWebhooksMigrateResult)(this, result, {
2230
+ showAll: logOutput === "all",
2231
+ showDiff: logOutput === "all" || logOutput === "changes",
2232
+ showChanged: logOutput === "changes"
2233
+ });
2234
+ });
2235
+ }
2236
+ if (!err && !((_a = result.errors) == null ? void 0 : _a.length) && (!commit && result.webhooksToMigrate[currentProject].totalCount || commit && (((_b = result.webhooksResult) == null ? void 0 : _b.created) || ((_c = result.webhooksResult) == null ? void 0 : _c.updated)))) {
2237
+ log.success(
2238
+ messages.webhooks.imported(
2239
+ currentEnv,
2240
+ commit,
2241
+ commit ? (((_d = result.webhooksResult) == null ? void 0 : _d.created) || 0) + (((_e = result.webhooksResult) == null ? void 0 : _e.updated) || 0) : result.webhooksToMigrate[currentProject].totalCount
2242
+ )
2243
+ );
2244
+ if (!commit) {
2245
+ log.raw(``);
2246
+ log.help(messages.migrate.commitTip());
2247
+ }
2248
+ } else {
2249
+ const noChanges = ((_g = (_f = result == null ? void 0 : result.webhooksToMigrate) == null ? void 0 : _f[currentProject]) == null ? void 0 : _g["no change"]) && ((_h = result == null ? void 0 : result.webhooksToMigrate) == null ? void 0 : _h[currentProject].totalCount) === 0;
2250
+ if (noChanges && !err && !((_i = result.errors) == null ? void 0 : _i.length)) {
2251
+ log.help(messages.webhooks.noChange(currentEnv));
2252
+ } else {
2253
+ log.error(messages.webhooks.failedCreate(currentEnv), err);
2254
+ }
2255
+ }
2256
+ } else {
2257
+ log.warning(messages.models.noList(currentProject));
2258
+ log.help(messages.connect.tip());
2259
+ }
2260
+ };
2198
2261
  PrintBlocks = async () => {
2199
2262
  const { currentEnv, env, log, messages } = this;
2200
2263
  const contensis = await this.ConnectContensis();