contensis-cli 1.6.1-beta.14 → 1.6.1-beta.15

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.
package/dist/index.js CHANGED
@@ -46454,7 +46454,7 @@ var progress = {
46454
46454
  };
46455
46455
 
46456
46456
  // src/version.ts
46457
- var LIB_VERSION = "1.6.1-beta.14";
46457
+ var LIB_VERSION = "1.6.1-beta.15";
46458
46458
 
46459
46459
  // src/commands/connect.ts
46460
46460
  var import_commander2 = require("commander");
@@ -46692,7 +46692,15 @@ ${Logger.errorText(">>")} Available commands:`,
46692
46692
  failedGet: (projectId) => `[${projectId}] Cannot retrieve nodes from Site view`,
46693
46693
  get: (projectId, root, depth) => `[${projectId}] Site view nodes at: ${Logger.highlightText(root)}${depth ? ` to a depth of ${depth}` : ``}
46694
46694
  `,
46695
- noChange: (env) => `[${env}] No changes to be made`
46695
+ noChange: (env) => `[${env}] No changes to be made`,
46696
+ setPayload: () => `Updating node with details
46697
+ `,
46698
+ set: (env) => `[${env}] Succesfully updated node
46699
+ `,
46700
+ failedSet: (env, name) => `[${env}] Unable to update node ${Logger.highlightText(name)}`,
46701
+ created: (env, name) => `[${env}] Created node ${Logger.highlightText(name)}
46702
+ `,
46703
+ failedCreate: (env, name) => `[${env}] Unable to create node ${Logger.highlightText(name)}`
46696
46704
  },
46697
46705
  contenttypes: {
46698
46706
  list: (projectId) => `Content types in ${Logger.highlightText(projectId)}:`,
@@ -50276,6 +50284,100 @@ Components:`));
50276
50284
  }
50277
50285
  }
50278
50286
  };
50287
+ CreateOrUpdateNode = async (nodePathOrId, nodeUpdates, displayName, slug, language) => {
50288
+ var _a, _b;
50289
+ const { currentEnv, currentProject, log, messages } = this;
50290
+ const contensis = await this.ConnectContensis();
50291
+ const nodePath = nodePathOrId.startsWith("/") ? nodePathOrId : void 0;
50292
+ let nodeId = isUuid(nodePathOrId) ? nodePathOrId : void 0;
50293
+ let existingNode;
50294
+ let parentNode;
50295
+ let updateNode;
50296
+ if (contensis) {
50297
+ if (nodePath) {
50298
+ const [, nodesByPath] = await (0, import_await_to_js2.default)(contensis.nodes.GetNodes(nodePath, 0));
50299
+ if (Array.isArray(nodesByPath) && ((_a = nodesByPath[0]) == null ? void 0 : _a.id)) {
50300
+ nodeId = nodesByPath[0].id;
50301
+ }
50302
+ }
50303
+ if (nodeId) {
50304
+ const [, nodeById] = await (0, import_await_to_js2.default)(
50305
+ contensis.source.repo.GetNodeById(nodeId)
50306
+ );
50307
+ if (nodeById) existingNode = nodeById;
50308
+ }
50309
+ if (!existingNode) {
50310
+ if (!language) {
50311
+ const project2 = await contensis.source.repo.GetProject(currentProject);
50312
+ language = (project2 == null ? void 0 : project2.primaryLanguage) || "en-GB";
50313
+ }
50314
+ if (!nodeUpdates.parentId) {
50315
+ if (!nodePath)
50316
+ throw new Error(
50317
+ `A node with id "${nodeId}" does not exist, and a path was not provided to find the parent node.`
50318
+ );
50319
+ const parentPath = nodePath.substring(0, nodePath.lastIndexOf("/")) || "/";
50320
+ const [, parentNodesByPath] = await (0, import_await_to_js2.default)(
50321
+ contensis.nodes.GetNodes(parentPath, 0)
50322
+ );
50323
+ if (!((_b = parentNodesByPath == null ? void 0 : parentNodesByPath[0]) == null ? void 0 : _b.id))
50324
+ throw new Error(
50325
+ `A node with id "${nodeId}" does not exist, and the parent node could not be found at path "${parentPath}".`
50326
+ );
50327
+ else parentNode = parentNodesByPath[0];
50328
+ }
50329
+ const pathSlug = nodePath == null ? void 0 : nodePath.substring(nodePath.lastIndexOf("/") + 1);
50330
+ const createNode = {
50331
+ id: nodeId,
50332
+ parentId: nodeUpdates.parentId || (parentNode == null ? void 0 : parentNode.id),
50333
+ projectId: currentProject,
50334
+ displayName: displayName ? {
50335
+ [language]: displayName
50336
+ } : nodeUpdates.displayName ? nodeUpdates.displayName : pathSlug ? {
50337
+ [language]: pathSlug
50338
+ } : void 0,
50339
+ slug: slug ? {
50340
+ [language]: slug
50341
+ } : nodeUpdates.slug ? nodeUpdates.slug : pathSlug ? {
50342
+ [language]: pathSlug
50343
+ } : void 0,
50344
+ entryId: nodeUpdates.entryId,
50345
+ isCanonical: nodeUpdates.isCanonical,
50346
+ renderer: nodeUpdates.renderer,
50347
+ proxy: nodeUpdates.proxy,
50348
+ includeInMenu: nodeUpdates.includeInMenu
50349
+ };
50350
+ updateNode = createNode;
50351
+ } else {
50352
+ updateNode = { ...existingNode, ...nodeUpdates };
50353
+ }
50354
+ if (updateNode) {
50355
+ log.info(messages.nodes.setPayload());
50356
+ log.object(updateNode);
50357
+ const [err, newNode] = await contensis.source.repo.UpdateOrCreateNode(
50358
+ existingNode,
50359
+ updateNode
50360
+ );
50361
+ if (err)
50362
+ log.error(
50363
+ messages.nodes[existingNode ? "failedSet" : "failedCreate"](
50364
+ currentEnv,
50365
+ nodePathOrId
50366
+ ),
50367
+ err
50368
+ );
50369
+ else if (newNode) {
50370
+ log.success(
50371
+ messages.nodes[existingNode ? "set" : "created"](
50372
+ currentEnv,
50373
+ newNode.id
50374
+ )
50375
+ );
50376
+ await this.HandleFormattingAndOutput(newNode, log.object);
50377
+ }
50378
+ }
50379
+ }
50380
+ };
50279
50381
  PrintWebhookSubscriptions = async (subscriptionIdsOrNames) => {
50280
50382
  const { currentEnv, log, messages } = this;
50281
50383
  const contensis = await this.ConnectContensis();
@@ -50724,25 +50826,29 @@ Components:`));
50724
50826
  }
50725
50827
  }
50726
50828
  };
50727
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
50728
50829
  PrintRenderers = async (rendererId) => {
50729
50830
  const { currentEnv, env, log, messages } = this;
50730
50831
  const contensis = await this.ConnectContensis();
50731
50832
  if (contensis) {
50732
50833
  const [err, renderers] = await contensis.renderers.GetRenderers();
50733
50834
  if (Array.isArray(renderers)) {
50734
- await this.HandleFormattingAndOutput(renderers, () => {
50835
+ const result = rendererId ? [renderers.find((r) => r.id === rendererId)].filter(
50836
+ Boolean
50837
+ ) : renderers || [];
50838
+ await this.HandleFormattingAndOutput(result, () => {
50735
50839
  log.success(messages.renderers.list(currentEnv, env.currentProject));
50736
50840
  for (const {
50841
+ uuid,
50737
50842
  id,
50738
50843
  description,
50739
50844
  assignedContentTypes,
50740
50845
  rules,
50741
50846
  version
50742
- } of renderers) {
50847
+ } of result) {
50743
50848
  console.log(
50744
50849
  ` - ${id} [${version.versionNo}] ${log.infoText`${description}`}`
50745
50850
  );
50851
+ console.log(log.infoText` uuid: ${uuid}`);
50746
50852
  if (assignedContentTypes == null ? void 0 : assignedContentTypes.length)
50747
50853
  console.log(
50748
50854
  log.infoText` assignedContentTypes: ${assignedContentTypes.join(
@@ -50756,7 +50862,7 @@ Components:`));
50756
50862
  );
50757
50863
  }
50758
50864
  });
50759
- return renderers;
50865
+ return result;
50760
50866
  }
50761
50867
  if (err) {
50762
50868
  log.error(messages.renderers.noList(currentEnv, env.currentProject));
@@ -50931,12 +51037,15 @@ var ContensisShell = class {
50931
51037
  "login",
50932
51038
  "list projects",
50933
51039
  "set project",
50934
- ...(((_a = this.env) == null ? void 0 : _a.projects) || []).map((project2) => `set project ${project2.id}`)
51040
+ ...(((_a = this.env) == null ? void 0 : _a.projects) || []).map(
51041
+ (project2) => `set project ${project2.id}`
51042
+ )
50935
51043
  );
50936
51044
  if (userId)
50937
51045
  availableCommands.push(
50938
51046
  "copy field",
50939
51047
  "create key",
51048
+ "create node",
50940
51049
  "create project",
50941
51050
  "create role",
50942
51051
  "create tag",
@@ -50997,6 +51106,8 @@ var ContensisShell = class {
50997
51106
  "remove tags",
50998
51107
  "remove tags in",
50999
51108
  "remove taggroup",
51109
+ "set node entry",
51110
+ "set node renderer",
51000
51111
  "set project name",
51001
51112
  "set project description",
51002
51113
  "set role name",
@@ -51383,6 +51494,38 @@ Example call:
51383
51494
  description
51384
51495
  );
51385
51496
  });
51497
+ create.command("node").description("create a new site view node").argument('<"node path or id">', "the path or id of the node to create").argument(
51498
+ '["display name"]',
51499
+ "provide a separate display name for the node (optional)"
51500
+ ).argument(
51501
+ '["slug"]',
51502
+ "provide a slug for the node (defaults to slug from provided node path)"
51503
+ ).option(
51504
+ "--include-in-menu",
51505
+ "set include in menu flag on the created node",
51506
+ false
51507
+ ).option(
51508
+ "--language <language>",
51509
+ "language of the node to create (defaults to current project primary language)"
51510
+ ).option("--entry-id <entryId>", "attach an entry to the node").usage(
51511
+ '<"node path or id"> ["display name"] (both args in "double quotes")'
51512
+ ).addHelpText(
51513
+ "after",
51514
+ `
51515
+ Example call:
51516
+ > create node /test "Test Node" --include-in-menu
51517
+ `
51518
+ ).action(
51519
+ async (pathOrId, displayName, slug, opts) => {
51520
+ await cliCommand(["create", "node", pathOrId], opts).CreateOrUpdateNode(
51521
+ pathOrId,
51522
+ opts,
51523
+ displayName,
51524
+ slug,
51525
+ opts.language
51526
+ );
51527
+ }
51528
+ );
51386
51529
  create.command("role").description("create a new role").argument('<"Role name">', "the name of the role to create").argument('["Role description">', "the description of the role").option("--disabled", "do not enable the created role", false).addHelpText(
51387
51530
  "after",
51388
51531
  `
@@ -57831,6 +57974,40 @@ var import_commander14 = require("commander");
57831
57974
  var makeSetCommand = () => {
57832
57975
  const set = new import_commander14.Command().command("set").description("set command").addHelpText("after", `
57833
57976
  `).showHelpAfterError(true).exitOverride();
57977
+ const node = set.command("node").description("update a site view node");
57978
+ node.command("entry").description("assign an entry to a node").argument('<"node path or id">', "the path or id of the node to update").argument("<entryId>", "the new entry id to assign to the node").usage('<"node path or id"> <entryId>').addHelpText(
57979
+ "after",
57980
+ `
57981
+ Example call:
57982
+ > set node entry /path 1502f64e-e9b1-436b-b62f-e273f639ecb6
57983
+ `
57984
+ ).action(async (nodePathOrId, entryId2, opts) => {
57985
+ await cliCommand(["set", "node", "entry"], opts).CreateOrUpdateNode(
57986
+ nodePathOrId,
57987
+ { entryId: entryId2 }
57988
+ );
57989
+ });
57990
+ node.command("renderer").description("assign a renderer to a node").argument('<"node path or id">', "the path or id of the node to update").argument("<rendererUuid>", "the renderer uuid to assign to the node").option(
57991
+ "--is-partial-match-root",
57992
+ "should the renderer be used as the partial match root for the node",
57993
+ false
57994
+ ).usage('<"node path or id"> <rendererUuid>').addHelpText(
57995
+ "after",
57996
+ `
57997
+ Example call:
57998
+ > set node renderer /path 1502f64e-e9b1-436b-b62f-e273f639ecb6 --is-partial-match-root
57999
+ `
58000
+ ).action(async (nodePathOrId, rendererId, opts) => {
58001
+ await cliCommand(["set", "node", "renderer"], opts).CreateOrUpdateNode(
58002
+ nodePathOrId,
58003
+ {
58004
+ renderer: {
58005
+ id: rendererId,
58006
+ isPartialMatchRoot: opts.isPartialMatchRoot
58007
+ }
58008
+ }
58009
+ );
58010
+ });
57834
58011
  const project2 = set.command("project").description("set current working project").argument("<projectId>", "the project id to work with").usage("<projectId>").addHelpText(
57835
58012
  "after",
57836
58013
  `