contensis-cli 1.0.12-beta.2 → 1.0.12-beta.20

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 (71) hide show
  1. package/README.md +9 -9
  2. package/dist/commands/get.js +13 -1
  3. package/dist/commands/get.js.map +2 -2
  4. package/dist/commands/globalOptions.js +9 -10
  5. package/dist/commands/globalOptions.js.map +2 -2
  6. package/dist/commands/import.js +22 -12
  7. package/dist/commands/import.js.map +2 -2
  8. package/dist/commands/index.js +2 -2
  9. package/dist/commands/index.js.map +2 -2
  10. package/dist/commands/list.js +9 -0
  11. package/dist/commands/list.js.map +2 -2
  12. package/dist/commands/remove.js +13 -0
  13. package/dist/commands/remove.js.map +2 -2
  14. package/dist/localisation/en-GB.js +12 -4
  15. package/dist/localisation/en-GB.js.map +2 -2
  16. package/dist/mappers/DevInit-to-CIWorkflow.js +6 -8
  17. package/dist/mappers/DevInit-to-CIWorkflow.js.map +2 -2
  18. package/dist/mappers/DevInit-to-RolePermissions.js +4 -4
  19. package/dist/mappers/DevInit-to-RolePermissions.js.map +2 -2
  20. package/dist/providers/file-provider.js +5 -1
  21. package/dist/providers/file-provider.js.map +2 -2
  22. package/dist/services/ContensisAuthService.js.map +2 -2
  23. package/dist/services/ContensisCliService.js +158 -40
  24. package/dist/services/ContensisCliService.js.map +2 -2
  25. package/dist/services/ContensisDevService.js +51 -56
  26. package/dist/services/ContensisDevService.js.map +3 -3
  27. package/dist/shell.js +6 -0
  28. package/dist/shell.js.map +2 -2
  29. package/dist/util/console.printer.js +61 -52
  30. package/dist/util/console.printer.js.map +3 -3
  31. package/dist/util/csv.formatter.js +3 -11
  32. package/dist/util/csv.formatter.js.map +3 -3
  33. package/dist/util/diff.js +1 -1
  34. package/dist/util/diff.js.map +2 -2
  35. package/dist/util/error.js +36 -0
  36. package/dist/util/error.js.map +7 -0
  37. package/dist/util/find.js +10 -2
  38. package/dist/util/find.js.map +2 -2
  39. package/dist/util/git.js +1 -0
  40. package/dist/util/git.js.map +2 -2
  41. package/dist/util/json.formatter.js +35 -3
  42. package/dist/util/json.formatter.js.map +3 -3
  43. package/dist/util/logger.js +52 -9
  44. package/dist/util/logger.js.map +3 -3
  45. package/dist/version.js +1 -1
  46. package/dist/version.js.map +1 -1
  47. package/package.json +4 -4
  48. package/src/commands/get.ts +19 -1
  49. package/src/commands/globalOptions.ts +9 -7
  50. package/src/commands/import.ts +35 -15
  51. package/src/commands/index.ts +2 -3
  52. package/src/commands/list.ts +15 -0
  53. package/src/commands/remove.ts +20 -0
  54. package/src/localisation/en-GB.ts +15 -5
  55. package/src/mappers/DevInit-to-CIWorkflow.ts +8 -8
  56. package/src/mappers/DevInit-to-RolePermissions.ts +5 -2
  57. package/src/models/Cache.d.ts +2 -1
  58. package/src/providers/file-provider.ts +5 -1
  59. package/src/services/ContensisAuthService.ts +1 -1
  60. package/src/services/ContensisCliService.ts +195 -55
  61. package/src/services/ContensisDevService.ts +76 -70
  62. package/src/shell.ts +8 -0
  63. package/src/util/console.printer.ts +151 -72
  64. package/src/util/csv.formatter.ts +1 -4
  65. package/src/util/diff.ts +1 -1
  66. package/src/util/error.ts +7 -0
  67. package/src/util/find.ts +13 -2
  68. package/src/util/git.ts +2 -1
  69. package/src/util/json.formatter.ts +32 -1
  70. package/src/util/logger.ts +90 -15
  71. package/src/version.ts +1 -1
@@ -56,14 +56,14 @@ class ContensisCli {
56
56
  const exitCode = error ? 1 : 0;
57
57
  process.exit(exitCode);
58
58
  };
59
- command;
60
59
  format;
61
60
  output;
62
61
  session;
62
+ auth;
63
+ command;
63
64
  contensis;
64
65
  contensisOpts;
65
66
  currentProject;
66
- devinit;
67
67
  sourceAlias;
68
68
  targetEnv;
69
69
  urls;
@@ -72,9 +72,6 @@ class ContensisCli {
72
72
  verb;
73
73
  noun;
74
74
  thirdArg;
75
- get invokedBy() {
76
- return this.command.createdUserId;
77
- }
78
75
  get cache() {
79
76
  return this.session.Get();
80
77
  }
@@ -123,7 +120,12 @@ class ContensisCli {
123
120
  if (outputOpts == null ? void 0 : outputOpts.clientId)
124
121
  env.lastUserId = outputOpts.clientId;
125
122
  if (outputOpts == null ? void 0 : outputOpts.sharedSecret)
126
- env.passwordFallback = outputOpts.sharedSecret;
123
+ if (outputOpts.sharedSecret.startsWith("-"))
124
+ throw new Error(
125
+ `Shared secret option provided a value of ${outputOpts.sharedSecret}`
126
+ );
127
+ else
128
+ env.passwordFallback = outputOpts.sharedSecret;
127
129
  this.currentProject = (env == null ? void 0 : env.currentProject) || "null";
128
130
  this.sourceAlias = (outputOpts == null ? void 0 : outputOpts.sourceAlias) || currentEnvironment;
129
131
  if (currentEnvironment) {
@@ -131,8 +133,9 @@ class ContensisCli {
131
133
  }
132
134
  this.command = {
133
135
  commandText,
136
+ options: outputOpts,
134
137
  createdDate: new Date().toISOString(),
135
- createdUserId: env == null ? void 0 : env.lastUserId
138
+ invokedBy: env == null ? void 0 : env.lastUserId
136
139
  };
137
140
  if (currentEnvironment) {
138
141
  env.history = [this.command];
@@ -324,7 +327,10 @@ class ContensisCli {
324
327
  password
325
328
  ).Init();
326
329
  if (credentialError && !credentials.current) {
327
- log.error(credentialError);
330
+ log.error(
331
+ `Unable to find credentials for user ${userId} at ${currentEnv}`,
332
+ credentialError
333
+ );
328
334
  return;
329
335
  }
330
336
  if (credentials.remarks.secure !== true) {
@@ -371,7 +377,7 @@ class ContensisCli {
371
377
  ]));
372
378
  }
373
379
  if (inputPassword || cachedPassword || cachedSecret) {
374
- const authService = new import_ContensisAuthService.default({
380
+ this.auth = new import_ContensisAuthService.default({
375
381
  username: userId,
376
382
  password: inputPassword || cachedPassword,
377
383
  projectId: (env == null ? void 0 : env.currentProject) || "website",
@@ -379,9 +385,7 @@ class ContensisCli {
379
385
  clientId: userId,
380
386
  clientSecret: sharedSecret || cachedSecret
381
387
  });
382
- const [authError, bearerToken] = await (0, import_await_to_js.default)(
383
- authService.BearerToken()
384
- );
388
+ const [authError, bearerToken] = await (0, import_await_to_js.default)(this.auth.BearerToken());
385
389
  if (bearerToken) {
386
390
  env.authToken = bearerToken;
387
391
  env.lastUserId = userId;
@@ -594,7 +598,7 @@ class ContensisCli {
594
598
  }
595
599
  }
596
600
  };
597
- CreateApiKey = async (name, description) => {
601
+ CreateApiKey = async (name, description = "") => {
598
602
  const { currentEnv, log, messages } = this;
599
603
  const contensis = await this.ConnectContensis();
600
604
  if (contensis) {
@@ -796,6 +800,78 @@ class ContensisCli {
796
800
  }
797
801
  }
798
802
  };
803
+ PrintWorkflows = async () => {
804
+ const { currentEnv, log, messages } = this;
805
+ const contensis = await this.ConnectContensis();
806
+ if (contensis) {
807
+ const [workflowsErr, workflows] = await contensis.content.sourceRepo.workflows.GetWorkflows();
808
+ if (Array.isArray(workflows)) {
809
+ log.success(messages.workflows.list(currentEnv));
810
+ if (!workflows.length)
811
+ log.help(messages.workflows.noneExist());
812
+ const stringFromLanguageObject = (o) => {
813
+ var _a;
814
+ return (_a = Object.values(o || {})) == null ? void 0 : _a[0];
815
+ };
816
+ this.HandleFormattingAndOutput(workflows, () => {
817
+ for (const {
818
+ id,
819
+ name,
820
+ description,
821
+ states,
822
+ eventGroups,
823
+ isSystem
824
+ } of workflows) {
825
+ const color = isSystem ? (s) => s : log.infoText;
826
+ console.log(
827
+ color(
828
+ ` - ${import_chalk.default.bold(
829
+ stringFromLanguageObject(name)
830
+ )} ${log.infoText(id)}`
831
+ )
832
+ );
833
+ if (description)
834
+ console.log(
835
+ log.infoText(` ${stringFromLanguageObject(description)}`)
836
+ );
837
+ if (isSystem === false)
838
+ console.log(` ${import_chalk.default.bold.grey("isSystem")}: false`);
839
+ if (states == null ? void 0 : states.length)
840
+ console.log(
841
+ ` ${import_chalk.default.bold.grey("states")}: ${states.map((state) => state.id).join(", ")}`
842
+ );
843
+ if (eventGroups == null ? void 0 : eventGroups.length)
844
+ console.log(
845
+ ` ${import_chalk.default.bold.grey("eventGroups")}: ${eventGroups.map((evtGrp) => evtGrp.id).join(", ")}`
846
+ );
847
+ }
848
+ });
849
+ }
850
+ if (workflowsErr) {
851
+ log.error(messages.workflows.noList(currentEnv));
852
+ log.error((0, import_json.jsonFormatter)(workflowsErr));
853
+ }
854
+ }
855
+ };
856
+ PrintWorkflow = async (workflowNameOrId) => {
857
+ const { currentEnv, log, messages } = this;
858
+ const contensis = await this.ConnectContensis();
859
+ if (contensis) {
860
+ const [workflowsErr, workflows] = await contensis.content.sourceRepo.workflows.GetWorkflows();
861
+ if (Array.isArray(workflows)) {
862
+ log.success(messages.workflows.list(currentEnv));
863
+ const workflow = (0, import_find.findByIdOrName)(workflows, workflowNameOrId);
864
+ if (workflow)
865
+ this.HandleFormattingAndOutput(workflow, log.object);
866
+ else
867
+ log.error(messages.workflows.failedGet(currentEnv, workflowNameOrId));
868
+ }
869
+ if (workflowsErr) {
870
+ log.error(messages.workflows.noList(currentEnv));
871
+ log.error((0, import_json.jsonFormatter)(workflowsErr));
872
+ }
873
+ }
874
+ };
799
875
  CreateProject = async (project) => {
800
876
  const { currentEnv, log, messages } = this;
801
877
  const contensis = await this.ConnectContensis();
@@ -1223,7 +1299,7 @@ Components:`));
1223
1299
  }
1224
1300
  };
1225
1301
  RemoveEntries = async (commit = false) => {
1226
- var _a;
1302
+ var _a, _b, _c;
1227
1303
  const { currentEnv, currentProject, log, messages } = this;
1228
1304
  const contensis = await this.ConnectContensisImport({
1229
1305
  commit,
@@ -1251,7 +1327,7 @@ Components:`));
1251
1327
  }
1252
1328
  } else {
1253
1329
  log.error(messages.entries.failedRemove(currentEnv), err);
1254
- if (!result.entriesToMigrate[currentProject].totalCount)
1330
+ if (!((_c = (_b = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _b[currentProject]) == null ? void 0 : _c.totalCount))
1255
1331
  log.help(messages.entries.notFound(currentEnv));
1256
1332
  }
1257
1333
  }
@@ -1285,7 +1361,7 @@ Components:`));
1285
1361
  fromFile,
1286
1362
  logOutput
1287
1363
  }) => {
1288
- var _a, _b, _c, _d, _e;
1364
+ var _a, _b, _c, _d, _e, _f, _g;
1289
1365
  const { currentEnv, currentProject, log, messages } = this;
1290
1366
  const contensis = await this.ConnectContensisImport({
1291
1367
  commit,
@@ -1323,7 +1399,7 @@ Components:`));
1323
1399
  }
1324
1400
  } else {
1325
1401
  log.error(messages.entries.failedImport(currentEnv), err);
1326
- if (!result.entriesToMigrate[currentProject].totalCount)
1402
+ if (!((_g = (_f = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _f[currentProject]) == null ? void 0 : _g.totalCount))
1327
1403
  log.help(messages.entries.notFound(currentEnv));
1328
1404
  }
1329
1405
  } else {
@@ -1336,16 +1412,15 @@ Components:`));
1336
1412
  const contensis = await this.ConnectContensis();
1337
1413
  if (contensis) {
1338
1414
  log.line();
1339
- const [err] = await (0, import_await_to_js.default)(
1340
- contensis.content.sourceRepo.nodes.GetNodes(rootPath, depth)
1341
- );
1415
+ const [err, nodes] = await (0, import_await_to_js.default)(contensis.nodes.GetNodes(rootPath, depth));
1342
1416
  if (err) {
1343
1417
  log.error(messages.nodes.failedGet(currentProject), err);
1344
1418
  return;
1345
1419
  }
1346
- const root = contensis.content.sourceRepo.nodes.tree;
1420
+ const root = contensis.nodes.sourceRepo.nodes.tree;
1347
1421
  log.success(messages.nodes.get(currentProject, rootPath, depth));
1348
- this.HandleFormattingAndOutput(root, () => {
1422
+ this.HandleFormattingAndOutput(nodes, () => {
1423
+ log.object({ ...root, children: void 0, language: void 0 });
1349
1424
  (0, import_console.printNodeTreeOutput)(this, root);
1350
1425
  });
1351
1426
  } else {
@@ -1356,9 +1431,10 @@ Components:`));
1356
1431
  ImportNodes = async ({
1357
1432
  commit,
1358
1433
  fromFile,
1359
- logOutput
1434
+ logOutput,
1435
+ logLimit
1360
1436
  }) => {
1361
- var _a, _b, _c;
1437
+ var _a, _b, _c, _d, _e, _f, _g;
1362
1438
  const { currentEnv, currentProject, log, messages } = this;
1363
1439
  const contensis = await this.ConnectContensisImport({
1364
1440
  commit,
@@ -1373,39 +1449,42 @@ Components:`));
1373
1449
  console.log(log.warningText(` *** COMMITTING IMPORT *** `));
1374
1450
  }
1375
1451
  const [err, result] = await contensis.MigrateNodes();
1452
+ const migrateTree = contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView;
1376
1453
  if (err)
1377
- (0, import_logger.logError)(err);
1454
+ log.raw(``);
1378
1455
  else
1379
1456
  this.HandleFormattingAndOutput(result, () => {
1457
+ (0, import_console.printNodeTreeOutput)(this, migrateTree, logOutput, logLimit);
1380
1458
  (0, import_console.printNodesMigrateResult)(this, result, {
1381
1459
  showAll: logOutput === "all",
1382
1460
  showChanged: logOutput === "changes"
1383
1461
  });
1384
1462
  });
1385
- const nodesTotalCount = result == null ? void 0 : result.nodesToMigrate[currentProject].totalCount;
1386
- const nodesCreated = ((_a = result == null ? void 0 : result.nodesResult) == null ? void 0 : _a["created"]) || 0;
1387
- const nodesUpdated = ((_b = result == null ? void 0 : result.nodesResult) == null ? void 0 : _b["updated"]) || 0;
1388
- const noChange = result.nodesToMigrate[currentProject]["no change"] !== 0;
1389
- if (!err && !((_c = result.errors) == null ? void 0 : _c.length) && (!commit && nodesTotalCount || commit && (nodesCreated || nodesUpdated))) {
1463
+ const nodesMigrateCount = (_a = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _a[currentProject].totalCount;
1464
+ const nodesCreated = ((_b = result == null ? void 0 : result.nodesResult) == null ? void 0 : _b["created"]) || 0;
1465
+ const nodesUpdated = ((_c = result == null ? void 0 : result.nodesResult) == null ? void 0 : _c["updated"]) || 0;
1466
+ const nodesErrored = ((_d = result == null ? void 0 : result.nodesResult) == null ? void 0 : _d["errors"]) || 0;
1467
+ const noChanges = ((_e = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _e[currentProject]["no change"]) && nodesMigrateCount === 0;
1468
+ 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)))) {
1390
1469
  let totalCount;
1391
1470
  if (commit) {
1392
1471
  let created = typeof nodesCreated === "number" ? nodesCreated : 0;
1393
1472
  let updated = typeof nodesUpdated === "number" ? nodesUpdated : 0;
1394
1473
  totalCount = created + updated;
1395
1474
  } else {
1396
- totalCount = typeof nodesTotalCount === "number" ? nodesTotalCount : 0;
1475
+ totalCount = typeof nodesMigrateCount === "number" ? nodesMigrateCount : 0;
1397
1476
  }
1398
1477
  log.success(messages.nodes.imported(currentEnv, commit, totalCount));
1478
+ log.raw(``);
1399
1479
  if (!commit) {
1400
- log.raw(``);
1401
1480
  log.help(messages.nodes.commitTip());
1402
1481
  }
1403
1482
  } else {
1404
- if (noChange) {
1483
+ if (noChanges && !err && !nodesErrored) {
1405
1484
  log.help(messages.nodes.noChange(currentEnv));
1406
1485
  } else {
1407
1486
  log.error(messages.nodes.failedImport(currentEnv), err);
1408
- if (!nodesTotalCount)
1487
+ if (!nodesMigrateCount)
1409
1488
  log.help(messages.nodes.notFound(currentEnv));
1410
1489
  }
1411
1490
  }
@@ -1414,6 +1493,43 @@ Components:`));
1414
1493
  log.help(messages.connect.tip());
1415
1494
  }
1416
1495
  };
1496
+ RemoveNodes = async (commit = false) => {
1497
+ var _a, _b, _c;
1498
+ const { currentEnv, currentProject, log, messages } = this;
1499
+ const contensis = await this.ConnectContensisImport({
1500
+ commit,
1501
+ importDataType: "user-input"
1502
+ });
1503
+ if (contensis) {
1504
+ if (contensis.isPreview) {
1505
+ console.log(log.successText(` -- PREVIEW -- `));
1506
+ } else {
1507
+ console.log(log.warningText(` *** COMMITTING DELETE *** `));
1508
+ }
1509
+ const [err, result] = await contensis.DeleteNodes();
1510
+ if (result) {
1511
+ this.HandleFormattingAndOutput(result, () => {
1512
+ (0, import_console.printNodeTreeOutput)(
1513
+ this,
1514
+ contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView
1515
+ );
1516
+ });
1517
+ }
1518
+ if (!err && (!commit && result.nodesToMigrate[currentProject].totalCount || commit && ((_a = result.nodesResult) == null ? void 0 : _a.deleted))) {
1519
+ log.success(
1520
+ messages.nodes.removed(currentEnv, commit, contensis.nodes.rootPath)
1521
+ );
1522
+ log.raw(``);
1523
+ if (!commit) {
1524
+ log.help(messages.nodes.commitTip());
1525
+ }
1526
+ } else {
1527
+ log.error(messages.nodes.failedRemove(currentEnv), err);
1528
+ if (!((_c = (_b = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _b[currentProject]) == null ? void 0 : _c.totalCount))
1529
+ log.help(messages.nodes.notFound(currentEnv));
1530
+ }
1531
+ }
1532
+ };
1417
1533
  PrintWebhookSubscriptions = async (subscriptionIdsOrNames) => {
1418
1534
  const { currentEnv, log, messages } = this;
1419
1535
  const contensis = await this.ConnectContensis();
@@ -1835,29 +1951,31 @@ Components:`));
1835
1951
  }
1836
1952
  };
1837
1953
  HandleFormattingAndOutput = (obj, logFn) => {
1954
+ var _a, _b;
1838
1955
  const { format, log, messages, output } = this;
1956
+ const fields = (_b = (_a = this.contensis) == null ? void 0 : _a.payload.query) == null ? void 0 : _b.fields;
1839
1957
  if (!format) {
1840
1958
  logFn(obj);
1841
1959
  } else if (format === "csv") {
1842
1960
  log.raw("");
1843
- log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
1961
+ log.raw(log.infoText((0, import_csv.csvFormatter)((0, import_json.limitFields)(obj, fields))));
1844
1962
  } else if (format === "xml") {
1845
1963
  log.raw("");
1846
- log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
1964
+ log.raw(log.infoText((0, import_xml.xmlFormatter)((0, import_json.limitFields)(obj, fields))));
1847
1965
  } else if (format === "json") {
1848
1966
  log.raw("");
1849
- log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
1967
+ log.raw(log.infoText((0, import_json.jsonFormatter)(obj, fields)));
1850
1968
  }
1851
1969
  log.raw("");
1852
1970
  if (output) {
1853
1971
  let writeString = "";
1854
1972
  const isText = !(0, import_util.tryParse)(obj) && typeof obj === "string";
1855
1973
  if (format === "csv") {
1856
- writeString = (0, import_csv.csvFormatter)(obj);
1974
+ writeString = (0, import_csv.csvFormatter)((0, import_json.limitFields)(obj, fields));
1857
1975
  } else if (format === "xml") {
1858
- writeString = (0, import_xml.xmlFormatter)(obj);
1976
+ writeString = (0, import_xml.xmlFormatter)((0, import_json.limitFields)(obj, fields));
1859
1977
  } else
1860
- writeString = isText ? obj : (0, import_json.jsonFormatter)(obj);
1978
+ writeString = isText ? obj : (0, import_json.jsonFormatter)(obj, fields);
1861
1979
  if (writeString) {
1862
1980
  import_fs.default.writeFileSync(output, writeString);
1863
1981
  log.success(messages.app.fileOutput(isText ? "text" : format, output));