contensis-cli 1.0.12-beta.1 → 1.0.12-beta.11

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 (61) 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 +25 -10
  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 +8 -2
  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.map +2 -2
  19. package/dist/providers/file-provider.js +5 -1
  20. package/dist/providers/file-provider.js.map +2 -2
  21. package/dist/services/ContensisAuthService.js.map +2 -2
  22. package/dist/services/ContensisCliService.js +164 -75
  23. package/dist/services/ContensisCliService.js.map +3 -3
  24. package/dist/services/ContensisDevService.js +48 -53
  25. package/dist/services/ContensisDevService.js.map +3 -3
  26. package/dist/shell.js +5 -0
  27. package/dist/shell.js.map +2 -2
  28. package/dist/util/console.printer.js +111 -10
  29. package/dist/util/console.printer.js.map +2 -2
  30. package/dist/util/error.js +36 -0
  31. package/dist/util/error.js.map +7 -0
  32. package/dist/util/find.js +10 -2
  33. package/dist/util/find.js.map +2 -2
  34. package/dist/util/git.js +1 -0
  35. package/dist/util/git.js.map +2 -2
  36. package/dist/util/logger.js +52 -9
  37. package/dist/util/logger.js.map +3 -3
  38. package/dist/version.js +1 -1
  39. package/dist/version.js.map +1 -1
  40. package/package.json +4 -4
  41. package/src/commands/get.ts +19 -1
  42. package/src/commands/globalOptions.ts +9 -7
  43. package/src/commands/import.ts +41 -13
  44. package/src/commands/index.ts +2 -3
  45. package/src/commands/list.ts +15 -0
  46. package/src/commands/remove.ts +20 -0
  47. package/src/localisation/en-GB.ts +10 -3
  48. package/src/mappers/DevInit-to-CIWorkflow.ts +6 -8
  49. package/src/mappers/DevInit-to-RolePermissions.ts +1 -0
  50. package/src/models/Cache.d.ts +1 -1
  51. package/src/providers/file-provider.ts +5 -1
  52. package/src/services/ContensisAuthService.ts +1 -1
  53. package/src/services/ContensisCliService.ts +206 -101
  54. package/src/services/ContensisDevService.ts +70 -66
  55. package/src/shell.ts +5 -0
  56. package/src/util/console.printer.ts +238 -12
  57. package/src/util/error.ts +7 -0
  58. package/src/util/find.ts +13 -2
  59. package/src/util/git.ts +2 -1
  60. package/src/util/logger.ts +90 -15
  61. 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) {
@@ -132,7 +134,7 @@ class ContensisCli {
132
134
  this.command = {
133
135
  commandText,
134
136
  createdDate: new Date().toISOString(),
135
- createdUserId: env == null ? void 0 : env.lastUserId
137
+ invokedBy: env == null ? void 0 : env.lastUserId
136
138
  };
137
139
  if (currentEnvironment) {
138
140
  env.history = [this.command];
@@ -324,7 +326,10 @@ class ContensisCli {
324
326
  password
325
327
  ).Init();
326
328
  if (credentialError && !credentials.current) {
327
- log.error(credentialError);
329
+ log.error(
330
+ `Unable to find credentials for user ${userId} at ${currentEnv}`,
331
+ credentialError
332
+ );
328
333
  return;
329
334
  }
330
335
  if (credentials.remarks.secure !== true) {
@@ -371,7 +376,7 @@ class ContensisCli {
371
376
  ]));
372
377
  }
373
378
  if (inputPassword || cachedPassword || cachedSecret) {
374
- const authService = new import_ContensisAuthService.default({
379
+ this.auth = new import_ContensisAuthService.default({
375
380
  username: userId,
376
381
  password: inputPassword || cachedPassword,
377
382
  projectId: (env == null ? void 0 : env.currentProject) || "website",
@@ -379,9 +384,7 @@ class ContensisCli {
379
384
  clientId: userId,
380
385
  clientSecret: sharedSecret || cachedSecret
381
386
  });
382
- const [authError, bearerToken] = await (0, import_await_to_js.default)(
383
- authService.BearerToken()
384
- );
387
+ const [authError, bearerToken] = await (0, import_await_to_js.default)(this.auth.BearerToken());
385
388
  if (bearerToken) {
386
389
  env.authToken = bearerToken;
387
390
  env.lastUserId = userId;
@@ -594,7 +597,7 @@ class ContensisCli {
594
597
  }
595
598
  }
596
599
  };
597
- CreateApiKey = async (name, description) => {
600
+ CreateApiKey = async (name, description = "") => {
598
601
  const { currentEnv, log, messages } = this;
599
602
  const contensis = await this.ConnectContensis();
600
603
  if (contensis) {
@@ -688,9 +691,7 @@ class ContensisCli {
688
691
  ` ${import_chalk.default.bold.grey(
689
692
  "contentTypes"
690
693
  )}: ${permissions.contentTypes.map(
691
- (p) => `${p.id} [${p.actions.join(",")}] ${p.languages.join(
692
- " "
693
- )}`
694
+ (p) => `${p.id} [${p.actions.join(",")}] ${p.languages.join(" ")}`
694
695
  ).join(", ")}`
695
696
  );
696
697
  }
@@ -798,6 +799,78 @@ class ContensisCli {
798
799
  }
799
800
  }
800
801
  };
802
+ PrintWorkflows = async () => {
803
+ const { currentEnv, log, messages } = this;
804
+ const contensis = await this.ConnectContensis();
805
+ if (contensis) {
806
+ const [workflowsErr, workflows] = await contensis.content.sourceRepo.workflows.GetWorkflows();
807
+ if (Array.isArray(workflows)) {
808
+ log.success(messages.workflows.list(currentEnv));
809
+ if (!workflows.length)
810
+ log.help(messages.workflows.noneExist());
811
+ const stringFromLanguageObject = (o) => {
812
+ var _a;
813
+ return (_a = Object.values(o || {})) == null ? void 0 : _a[0];
814
+ };
815
+ this.HandleFormattingAndOutput(workflows, () => {
816
+ for (const {
817
+ id,
818
+ name,
819
+ description,
820
+ states,
821
+ eventGroups,
822
+ isSystem
823
+ } of workflows) {
824
+ const color = isSystem ? (s) => s : log.infoText;
825
+ console.log(
826
+ color(
827
+ ` - ${import_chalk.default.bold(
828
+ stringFromLanguageObject(name)
829
+ )} ${log.infoText(id)}`
830
+ )
831
+ );
832
+ if (description)
833
+ console.log(
834
+ log.infoText(` ${stringFromLanguageObject(description)}`)
835
+ );
836
+ if (isSystem === false)
837
+ console.log(` ${import_chalk.default.bold.grey("isSystem")}: false`);
838
+ if (states == null ? void 0 : states.length)
839
+ console.log(
840
+ ` ${import_chalk.default.bold.grey("states")}: ${states.map((state) => state.id).join(", ")}`
841
+ );
842
+ if (eventGroups == null ? void 0 : eventGroups.length)
843
+ console.log(
844
+ ` ${import_chalk.default.bold.grey("eventGroups")}: ${eventGroups.map((evtGrp) => evtGrp.id).join(", ")}`
845
+ );
846
+ }
847
+ });
848
+ }
849
+ if (workflowsErr) {
850
+ log.error(messages.workflows.noList(currentEnv));
851
+ log.error((0, import_json.jsonFormatter)(workflowsErr));
852
+ }
853
+ }
854
+ };
855
+ PrintWorkflow = async (workflowNameOrId) => {
856
+ const { currentEnv, log, messages } = this;
857
+ const contensis = await this.ConnectContensis();
858
+ if (contensis) {
859
+ const [workflowsErr, workflows] = await contensis.content.sourceRepo.workflows.GetWorkflows();
860
+ if (Array.isArray(workflows)) {
861
+ log.success(messages.workflows.list(currentEnv));
862
+ const workflow = (0, import_find.findByIdOrName)(workflows, workflowNameOrId);
863
+ if (workflow)
864
+ this.HandleFormattingAndOutput(workflow, log.object);
865
+ else
866
+ log.error(messages.workflows.failedGet(currentEnv, workflowNameOrId));
867
+ }
868
+ if (workflowsErr) {
869
+ log.error(messages.workflows.noList(currentEnv));
870
+ log.error((0, import_json.jsonFormatter)(workflowsErr));
871
+ }
872
+ }
873
+ };
801
874
  CreateProject = async (project) => {
802
875
  const { currentEnv, log, messages } = this;
803
876
  const contensis = await this.ConnectContensis();
@@ -1225,7 +1298,7 @@ Components:`));
1225
1298
  }
1226
1299
  };
1227
1300
  RemoveEntries = async (commit = false) => {
1228
- var _a;
1301
+ var _a, _b, _c;
1229
1302
  const { currentEnv, currentProject, log, messages } = this;
1230
1303
  const contensis = await this.ConnectContensisImport({
1231
1304
  commit,
@@ -1240,9 +1313,9 @@ Components:`));
1240
1313
  const [err, result] = await contensis.DeleteEntries();
1241
1314
  if (result)
1242
1315
  this.HandleFormattingAndOutput(result, () => {
1243
- (0, import_console.printMigrateResult)(this, result, {
1316
+ (0, import_console.printEntriesMigrateResult)(this, result, {
1244
1317
  action: "delete",
1245
- showAllEntries: true
1318
+ showAll: true
1246
1319
  });
1247
1320
  });
1248
1321
  if (!err && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && ((_a = result.migrateResult) == null ? void 0 : _a.deleted))) {
@@ -1253,7 +1326,7 @@ Components:`));
1253
1326
  }
1254
1327
  } else {
1255
1328
  log.error(messages.entries.failedRemove(currentEnv), err);
1256
- if (!result.entriesToMigrate[currentProject].totalCount)
1329
+ if (!((_c = (_b = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _b[currentProject]) == null ? void 0 : _c.totalCount))
1257
1330
  log.help(messages.entries.notFound(currentEnv));
1258
1331
  }
1259
1332
  }
@@ -1270,11 +1343,11 @@ Components:`));
1270
1343
  entries,
1271
1344
  () => {
1272
1345
  var _a;
1273
- return (0, import_migratortron.logEntriesTable)(
1346
+ return (0, import_migratortron.logEntitiesTable)({
1274
1347
  entries,
1275
- currentProject,
1276
- (_a = contensis.payload.query) == null ? void 0 : _a.fields
1277
- );
1348
+ projectId: currentProject,
1349
+ fields: (_a = contensis.payload.query) == null ? void 0 : _a.fields
1350
+ });
1278
1351
  }
1279
1352
  );
1280
1353
  } else {
@@ -1287,7 +1360,7 @@ Components:`));
1287
1360
  fromFile,
1288
1361
  logOutput
1289
1362
  }) => {
1290
- var _a, _b, _c, _d, _e;
1363
+ var _a, _b, _c, _d, _e, _f, _g;
1291
1364
  const { currentEnv, currentProject, log, messages } = this;
1292
1365
  const contensis = await this.ConnectContensisImport({
1293
1366
  commit,
@@ -1306,9 +1379,9 @@ Components:`));
1306
1379
  (0, import_logger.logError)(err);
1307
1380
  else
1308
1381
  this.HandleFormattingAndOutput(result, () => {
1309
- (0, import_console.printMigrateResult)(this, result, {
1310
- showAllEntries: logOutput === "all",
1311
- showChangedEntries: logOutput === "changes"
1382
+ (0, import_console.printEntriesMigrateResult)(this, result, {
1383
+ showAll: logOutput === "all",
1384
+ showChanged: logOutput === "changes"
1312
1385
  });
1313
1386
  });
1314
1387
  if (!err && !((_a = result.errors) == null ? void 0 : _a.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_b = result.migrateResult) == null ? void 0 : _b.created) || ((_c = result.migrateResult) == null ? void 0 : _c.updated)))) {
@@ -1325,7 +1398,7 @@ Components:`));
1325
1398
  }
1326
1399
  } else {
1327
1400
  log.error(messages.entries.failedImport(currentEnv), err);
1328
- if (!result.entriesToMigrate[currentProject].totalCount)
1401
+ if (!((_g = (_f = result == null ? void 0 : result.entriesToMigrate) == null ? void 0 : _f[currentProject]) == null ? void 0 : _g.totalCount))
1329
1402
  log.help(messages.entries.notFound(currentEnv));
1330
1403
  }
1331
1404
  } else {
@@ -1338,41 +1411,16 @@ Components:`));
1338
1411
  const contensis = await this.ConnectContensis();
1339
1412
  if (contensis) {
1340
1413
  log.line();
1341
- const [err] = await (0, import_await_to_js.default)(
1342
- contensis.content.sourceRepo.nodes.GetNodes(rootPath, depth)
1343
- );
1414
+ const [err, nodes] = await (0, import_await_to_js.default)(contensis.nodes.GetNodes(rootPath, depth));
1344
1415
  if (err) {
1345
1416
  log.error(messages.nodes.failedGet(currentProject), err);
1346
1417
  return;
1347
1418
  }
1348
- const root = contensis.content.sourceRepo.nodes.tree;
1419
+ const root = contensis.nodes.sourceRepo.nodes.tree;
1349
1420
  log.success(messages.nodes.get(currentProject, rootPath, depth));
1350
- const outputNode = (node, spaces) => `${node.entry ? log.highlightText("e") : log.infoText("-")}${node.isCanonical ? log.highlightText("c") : log.infoText("-")}${node.includeInMenu ? log.highlightText("m") : log.infoText("-")}${spaces}${node.isCanonical ? log.boldText(`/${node.slug}`) : `/${node.slug}`}${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ""}${node.childCount ? ` +${node.childCount}` : ``} ${log.infoText(node.displayName)}`;
1351
- this.HandleFormattingAndOutput(root, () => {
1352
- log.object({ ...root, children: void 0 });
1353
- log.raw("");
1354
- log.info(
1355
- `${log.highlightText("e")} = has entry; ${log.highlightText(
1356
- "c"
1357
- )} = canonical; ${log.highlightText("m")} = include in menu`
1358
- );
1359
- log.line();
1360
- const outputChildren = (root2, depth2 = 2) => {
1361
- let str = "";
1362
- for (const node of root2 == null ? void 0 : root2.children) {
1363
- str += `${outputNode(node, Array(depth2 + 1).join(" "))}
1364
- `;
1365
- if ("children" in node)
1366
- str += outputChildren(node, depth2 + 1);
1367
- }
1368
- return str;
1369
- };
1370
- const children = outputChildren(root);
1371
- log.limits(
1372
- `${outputNode(root, " ")}${children ? `
1373
- ${children}` : ""}`,
1374
- 100
1375
- );
1421
+ this.HandleFormattingAndOutput(nodes, () => {
1422
+ log.object({ ...root, children: void 0, language: void 0 });
1423
+ (0, import_console.printNodeTreeOutput)(this, root);
1376
1424
  });
1377
1425
  } else {
1378
1426
  log.warning(messages.models.noList(currentProject));
@@ -1382,9 +1430,10 @@ ${children}` : ""}`,
1382
1430
  ImportNodes = async ({
1383
1431
  commit,
1384
1432
  fromFile,
1385
- logOutput
1433
+ logOutput,
1434
+ logLimit
1386
1435
  }) => {
1387
- var _a, _b, _c;
1436
+ var _a, _b, _c, _d, _e, _f, _g;
1388
1437
  const { currentEnv, currentProject, log, messages } = this;
1389
1438
  const contensis = await this.ConnectContensisImport({
1390
1439
  commit,
@@ -1399,39 +1448,42 @@ ${children}` : ""}`,
1399
1448
  console.log(log.warningText(` *** COMMITTING IMPORT *** `));
1400
1449
  }
1401
1450
  const [err, result] = await contensis.MigrateNodes();
1451
+ const migrateTree = contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView;
1402
1452
  if (err)
1403
- (0, import_logger.logError)(err);
1453
+ log.raw(``);
1404
1454
  else
1405
1455
  this.HandleFormattingAndOutput(result, () => {
1406
- (0, import_console.printMigrateResult)(this, result, {
1407
- showAllEntries: logOutput === "all",
1408
- showChangedEntries: logOutput === "changes"
1456
+ (0, import_console.printNodeTreeOutput)(this, migrateTree, logOutput, logLimit);
1457
+ (0, import_console.printNodesMigrateResult)(this, result, {
1458
+ showAll: logOutput === "all",
1459
+ showChanged: logOutput === "changes"
1409
1460
  });
1410
1461
  });
1411
- const nodesTotalCount = result == null ? void 0 : result.nodesToMigrate[currentProject].totalCount;
1412
- const nodesCreated = ((_a = result == null ? void 0 : result.nodesResult) == null ? void 0 : _a["created"]) || 0;
1413
- const nodesUpdated = ((_b = result == null ? void 0 : result.nodesResult) == null ? void 0 : _b["updated"]) || 0;
1414
- const noChange = result.nodesToMigrate[currentProject]["no change"] !== 0;
1415
- if (!err && !((_c = result.errors) == null ? void 0 : _c.length) && (!commit && nodesTotalCount || commit && (nodesCreated || nodesUpdated))) {
1462
+ const nodesMigrateCount = (_a = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _a[currentProject].totalCount;
1463
+ const nodesCreated = ((_b = result == null ? void 0 : result.nodesResult) == null ? void 0 : _b["created"]) || 0;
1464
+ const nodesUpdated = ((_c = result == null ? void 0 : result.nodesResult) == null ? void 0 : _c["updated"]) || 0;
1465
+ const nodesErrored = ((_d = result == null ? void 0 : result.nodesResult) == null ? void 0 : _d["errors"]) || 0;
1466
+ const noChanges = ((_e = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _e[currentProject]["no change"]) && nodesMigrateCount === 0;
1467
+ 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)))) {
1416
1468
  let totalCount;
1417
1469
  if (commit) {
1418
1470
  let created = typeof nodesCreated === "number" ? nodesCreated : 0;
1419
1471
  let updated = typeof nodesUpdated === "number" ? nodesUpdated : 0;
1420
1472
  totalCount = created + updated;
1421
1473
  } else {
1422
- totalCount = typeof nodesTotalCount === "number" ? nodesTotalCount : 0;
1474
+ totalCount = typeof nodesMigrateCount === "number" ? nodesMigrateCount : 0;
1423
1475
  }
1424
1476
  log.success(messages.nodes.imported(currentEnv, commit, totalCount));
1477
+ log.raw(``);
1425
1478
  if (!commit) {
1426
- log.raw(``);
1427
1479
  log.help(messages.nodes.commitTip());
1428
1480
  }
1429
1481
  } else {
1430
- if (noChange) {
1431
- log.help(messages.nodes.noChange(currentEnv), err);
1482
+ if (noChanges && !err && !nodesErrored) {
1483
+ log.help(messages.nodes.noChange(currentEnv));
1432
1484
  } else {
1433
1485
  log.error(messages.nodes.failedImport(currentEnv), err);
1434
- if (!nodesTotalCount)
1486
+ if (!nodesMigrateCount)
1435
1487
  log.help(messages.nodes.notFound(currentEnv));
1436
1488
  }
1437
1489
  }
@@ -1440,6 +1492,43 @@ ${children}` : ""}`,
1440
1492
  log.help(messages.connect.tip());
1441
1493
  }
1442
1494
  };
1495
+ RemoveNodes = async (commit = false) => {
1496
+ var _a, _b, _c;
1497
+ const { currentEnv, currentProject, log, messages } = this;
1498
+ const contensis = await this.ConnectContensisImport({
1499
+ commit,
1500
+ importDataType: "user-input"
1501
+ });
1502
+ if (contensis) {
1503
+ if (contensis.isPreview) {
1504
+ console.log(log.successText(` -- PREVIEW -- `));
1505
+ } else {
1506
+ console.log(log.warningText(` *** COMMITTING DELETE *** `));
1507
+ }
1508
+ const [err, result] = await contensis.DeleteNodes();
1509
+ if (result) {
1510
+ this.HandleFormattingAndOutput(result, () => {
1511
+ (0, import_console.printNodeTreeOutput)(
1512
+ this,
1513
+ contensis.nodes.targetRepos[currentProject].nodes.migrateNodesTreeView
1514
+ );
1515
+ });
1516
+ }
1517
+ if (!err && (!commit && result.nodesToMigrate[currentProject].totalCount || commit && ((_a = result.nodesResult) == null ? void 0 : _a.deleted))) {
1518
+ log.success(
1519
+ messages.nodes.removed(currentEnv, commit, contensis.nodes.rootPath)
1520
+ );
1521
+ log.raw(``);
1522
+ if (!commit) {
1523
+ log.help(messages.nodes.commitTip());
1524
+ }
1525
+ } else {
1526
+ log.error(messages.nodes.failedRemove(currentEnv), err);
1527
+ if (!((_c = (_b = result == null ? void 0 : result.nodesToMigrate) == null ? void 0 : _b[currentProject]) == null ? void 0 : _c.totalCount))
1528
+ log.help(messages.nodes.notFound(currentEnv));
1529
+ }
1530
+ }
1531
+ };
1443
1532
  PrintWebhookSubscriptions = async (subscriptionIdsOrNames) => {
1444
1533
  const { currentEnv, log, messages } = this;
1445
1534
  const contensis = await this.ConnectContensis();