Skip to content

Commit b5bc398

Browse files
authored
TA-4289: Add command to find staging node (#272)
1 parent 795a93e commit b5bc398

File tree

6 files changed

+339
-0
lines changed

6 files changed

+339
-0
lines changed

DOCUMENTATION.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
- [Listing package variables](#listing-package-variables)
2828
- [Listing assignments](#listing-assignments)
2929
- [Mapping variables](#mapping-variables)
30+
- [Finding staging nodes](#finding-staging-nodes)
31+
- [Find a node](#find-a-node)
32+
- [Find a node with configuration](#find-a-node-with-configuration)
33+
- [Export node as JSON](#export-node-as-json)
3034
- [Data Pool export / import commands](#data-pool-export--import-commands)
3135
- [Export Data Pool](#export-data-pool)
3236
- [Batch Import multiple Data Pools](#batch-import-multiple-data-pools)
@@ -632,6 +636,60 @@ This mapping should be saved and then used during import.
632636
Since the format of the variables.json file on import is the same JSON structure as the list variables result, you can either map the values to the variables.json file for each variable, or replace the variables.json file with the result of the listing & mapping altogether.
633637
If the mapping of variables is skipped, you should delete the variables.json file before importing.
634638

639+
#### Finding nodes
640+
641+
The **config nodes find** command allows you to retrieve information about a specific node within a package.
642+
643+
##### Find a staging node
644+
To find a specific node in a package, use the following command:
645+
```
646+
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey>
647+
```
648+
649+
The command will display the node information in the console:
650+
```
651+
info: ID: node-id-123
652+
info: Key: node-key
653+
info: Name: My Node
654+
info: Type: VIEW
655+
info: Package Node Key: package-node-key
656+
info: Parent Node Key: parent-node-key
657+
info: Created By: [email protected]
658+
info: Updated By: [email protected]
659+
info: Creation Date: 2025-10-22T10:30:00.000Z
660+
info: Change Date: 2025-10-22T15:45:00.000Z
661+
info: Flavor: STUDIO
662+
```
663+
664+
##### Find a staging node with configuration
665+
By default, the node configuration is not included in the response. To include the node's configuration, use the `--withConfiguration` flag:
666+
```
667+
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration
668+
```
669+
670+
When configuration is included, it will be displayed as a JSON string in the output:
671+
```
672+
info: Configuration: {"key":"value","nested":{"field":"data"}}
673+
```
674+
675+
##### Export staging node as JSON
676+
To export the node information as a JSON file instead of displaying it in the console, use the `--json` option:
677+
```
678+
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --json
679+
```
680+
681+
This will create a JSON file in the current working directory with a UUID filename:
682+
```
683+
info: File downloaded successfully. New filename: 9560f81f-f746-4117-83ee-dd1f614ad624.json
684+
```
685+
686+
The JSON file contains the complete node information including all fields and, if requested, the configuration.
687+
688+
You can combine options to export a node with its configuration:
689+
```
690+
content-cli config nodes find --packageKey <packageKey> --nodeKey <nodeKey> --withConfiguration --json
691+
```
692+
635693
### Deployment commands (beta)
636694
The **deployment** command group allows you to create deployments, list their history, check active deployments, and retrieve deployables and targets.
637695

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { HttpClient } from "../../../core/http/http-client";
2+
import { Context } from "../../../core/command/cli-context";
3+
import { NodeTransport } from "../interfaces/node.interfaces";
4+
import { FatalError } from "../../../core/utils/logger";
5+
6+
export class NodeApi {
7+
private httpClient: () => HttpClient;
8+
9+
constructor(context: Context) {
10+
this.httpClient = () => context.httpClient;
11+
}
12+
13+
public async findStagingNodeByKey(packageKey: string, nodeKey: string, withConfiguration: boolean): Promise<NodeTransport> {
14+
const queryParams = new URLSearchParams();
15+
queryParams.set("withConfiguration", withConfiguration.toString());
16+
17+
return this.httpClient()
18+
.get(`/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?${queryParams.toString()}`)
19+
.catch((e) => {
20+
throw new FatalError(`Problem finding node ${nodeKey} in package ${packageKey}: ${e}`);
21+
});
22+
}
23+
}
24+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface NodeConfiguration {
2+
[key: string]: any;
3+
}
4+
5+
export interface NodeTransport {
6+
id: string;
7+
key: string;
8+
name: string;
9+
packageNodeKey: string;
10+
parentNodeKey?: string;
11+
packageNodeId: string;
12+
type: string;
13+
configuration?: NodeConfiguration;
14+
invalidConfiguration?: string;
15+
invalidContent: boolean;
16+
creationDate: string;
17+
changeDate: string;
18+
createdBy: string;
19+
updatedBy: string;
20+
schemaVersion: number;
21+
flavor?: string;
22+
}

src/commands/configuration-management/module.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Context } from "../../core/command/cli-context";
77
import { Command, OptionValues } from "commander";
88
import { ConfigCommandService } from "./config-command.service";
99
import { VariableCommandService } from "./variable-command.service";
10+
import { NodeService } from "./node.service";
1011

1112
class Module extends IModule {
1213

@@ -68,6 +69,17 @@ class Module extends IModule {
6869
.option("--keysByVersionFile <keysByVersionFile>", "Package keys by version mappings file path.", "")
6970
.action(this.listVariables);
7071

72+
const nodesCommand = configCommand.command("nodes")
73+
.description("Commands related to nodes of the package");
74+
75+
nodesCommand.command("find")
76+
.description("Find a specific node in a package")
77+
.requiredOption("--packageKey <packageKey>", "Identifier of the package")
78+
.requiredOption("--nodeKey <nodeKey>", "Identifier of the node")
79+
.option("--withConfiguration", "Include node configuration in the response", false)
80+
.option("--json", "Return the response as a JSON file")
81+
.action(this.findNode);
82+
7183
const listCommand = configurator.command("list");
7284
listCommand.command("assignments")
7385
.description("Command to list possible variable assignments for a type")
@@ -114,6 +126,10 @@ class Module extends IModule {
114126
private async listAssignments(context: Context, command: Command, options: OptionValues): Promise<void> {
115127
await new VariableCommandService(context).listAssignments(options.type, options.json, options.params);
116128
}
129+
130+
private async findNode(context: Context, command: Command, options: OptionValues): Promise<void> {
131+
await new NodeService(context).findNode(options.packageKey, options.nodeKey, options.withConfiguration, options.json);
132+
}
117133
}
118134

119135
export = Module;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { NodeApi } from "./api/node-api";
2+
import { Context } from "../../core/command/cli-context";
3+
import { fileService, FileService } from "../../core/utils/file-service";
4+
import { logger } from "../../core/utils/logger";
5+
import { v4 as uuidv4 } from "uuid";
6+
7+
export class NodeService {
8+
private nodeApi: NodeApi;
9+
10+
constructor(context: Context) {
11+
this.nodeApi = new NodeApi(context);
12+
}
13+
14+
public async findNode(packageKey: string, nodeKey: string, withConfiguration: boolean, jsonResponse: boolean): Promise<void> {
15+
const node = await this.nodeApi.findStagingNodeByKey(packageKey, nodeKey, withConfiguration);
16+
17+
if (jsonResponse) {
18+
const filename = uuidv4() + ".json";
19+
fileService.writeToFileWithGivenName(JSON.stringify(node, null, 2), filename);
20+
logger.info(FileService.fileDownloadedMessage + filename);
21+
} else {
22+
logger.info(`ID: ${node.id}`);
23+
logger.info(`Key: ${node.key}`);
24+
logger.info(`Name: ${node.name}`);
25+
logger.info(`Type: ${node.type}`);
26+
logger.info(`Package Node Key: ${node.packageNodeKey}`);
27+
if (node.parentNodeKey) {
28+
logger.info(`Parent Node Key: ${node.parentNodeKey}`);
29+
}
30+
logger.info(`Created By: ${node.createdBy}`);
31+
logger.info(`Updated By: ${node.updatedBy}`);
32+
logger.info(`Creation Date: ${new Date(node.creationDate).toISOString()}`);
33+
logger.info(`Change Date: ${new Date(node.changeDate).toISOString()}`);
34+
if (node.configuration) {
35+
logger.info(`Configuration: ${JSON.stringify(node.configuration, null, 2)}`);
36+
}
37+
if (node.invalidContent) {
38+
logger.info(`Invalid Configuration: ${node.invalidConfiguration}`);
39+
}
40+
logger.info(`Flavor: ${node.flavor}`);
41+
}
42+
}
43+
}
44+
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import { NodeTransport } from "../../../src/commands/configuration-management/interfaces/node.interfaces";
2+
import { mockAxiosGet } from "../../utls/http-requests-mock";
3+
import { NodeService } from "../../../src/commands/configuration-management/node.service";
4+
import { testContext } from "../../utls/test-context";
5+
import { loggingTestTransport, mockWriteFileSync } from "../../jest.setup";
6+
import { FileService } from "../../../src/core/utils/file-service";
7+
import * as path from "path";
8+
9+
describe("Node find", () => {
10+
const node: NodeTransport = {
11+
id: "node-id",
12+
key: "node-key",
13+
name: "Node Name",
14+
packageNodeKey: "package-node-key",
15+
parentNodeKey: "parent-node-key",
16+
packageNodeId: "package-node-id",
17+
type: "VIEW",
18+
invalidContent: false,
19+
creationDate: new Date().toISOString(),
20+
changeDate: new Date().toISOString(),
21+
createdBy: "user-id",
22+
updatedBy: "user-id",
23+
schemaVersion: 1,
24+
flavor: "STUDIO",
25+
};
26+
27+
it("Should find node without configuration", async () => {
28+
const packageKey = "package-key";
29+
const nodeKey = "node-key";
30+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node);
31+
32+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
33+
34+
expect(loggingTestTransport.logMessages.length).toBe(11);
35+
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${node.id}`);
36+
expect(loggingTestTransport.logMessages[1].message).toContain(`Key: ${node.key}`);
37+
expect(loggingTestTransport.logMessages[2].message).toContain(`Name: ${node.name}`);
38+
expect(loggingTestTransport.logMessages[3].message).toContain(`Type: ${node.type}`);
39+
expect(loggingTestTransport.logMessages[4].message).toContain(`Package Node Key: ${node.packageNodeKey}`);
40+
expect(loggingTestTransport.logMessages[5].message).toContain(`Parent Node Key: ${node.parentNodeKey}`);
41+
expect(loggingTestTransport.logMessages[6].message).toContain(`Created By: ${node.createdBy}`);
42+
expect(loggingTestTransport.logMessages[7].message).toContain(`Updated By: ${node.updatedBy}`);
43+
expect(loggingTestTransport.logMessages[8].message).toContain(`Creation Date: ${new Date(node.creationDate).toISOString()}`);
44+
expect(loggingTestTransport.logMessages[9].message).toContain(`Change Date: ${new Date(node.changeDate).toISOString()}`);
45+
expect(loggingTestTransport.logMessages[10].message).toContain(`Flavor: ${node.flavor}`);
46+
});
47+
48+
it("Should find node with configuration", async () => {
49+
const packageKey = "package-key";
50+
const nodeKey = "node-key";
51+
const nodeWithConfig: NodeTransport = {
52+
...node,
53+
configuration: {
54+
someKey: "someValue",
55+
anotherKey: 123,
56+
},
57+
};
58+
59+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig);
60+
61+
await new NodeService(testContext).findNode(packageKey, nodeKey, true, false);
62+
63+
expect(loggingTestTransport.logMessages.length).toBe(12);
64+
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithConfig.id}`);
65+
expect(loggingTestTransport.logMessages[10].message).toContain(`Configuration: ${JSON.stringify(nodeWithConfig.configuration, null, 2)}`);
66+
expect(loggingTestTransport.logMessages[11].message).toContain(`Flavor: ${nodeWithConfig.flavor}`);
67+
});
68+
69+
it("Should find node without parent node key", async () => {
70+
const packageKey = "package-key";
71+
const nodeKey = "node-key";
72+
const nodeWithoutParent: NodeTransport = {
73+
...node,
74+
parentNodeKey: undefined,
75+
};
76+
77+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithoutParent);
78+
79+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
80+
81+
expect(loggingTestTransport.logMessages.length).toBe(10);
82+
// Verify that parent node key is not logged
83+
const parentNodeKeyMessage = loggingTestTransport.logMessages.find(log => log.message.includes("Parent Node Key"));
84+
expect(parentNodeKeyMessage).toBeUndefined();
85+
});
86+
87+
it("Should find node and return as JSON", async () => {
88+
const packageKey = "package-key";
89+
const nodeKey = "node-key";
90+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, node);
91+
92+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, true);
93+
94+
const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
95+
96+
expect(mockWriteFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), expect.any(String), {encoding: "utf-8"});
97+
98+
const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport;
99+
100+
expect(nodeTransport).toEqual(node);
101+
});
102+
103+
it("Should find node with configuration and return as JSON", async () => {
104+
const packageKey = "package-key";
105+
const nodeKey = "node-key";
106+
const nodeWithConfig: NodeTransport = {
107+
...node,
108+
configuration: {
109+
someKey: "someValue",
110+
nested: {
111+
value: true,
112+
},
113+
},
114+
};
115+
116+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=true`, nodeWithConfig);
117+
118+
await new NodeService(testContext).findNode(packageKey, nodeKey, true, true);
119+
120+
const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
121+
122+
expect(mockWriteFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), expect.any(String), {encoding: "utf-8"});
123+
124+
const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport;
125+
126+
expect(nodeTransport).toEqual(nodeWithConfig);
127+
expect(nodeTransport.configuration).toEqual(nodeWithConfig.configuration);
128+
});
129+
130+
it("Should find node with invalid configuration", async () => {
131+
const packageKey = "package-key";
132+
const nodeKey = "node-key";
133+
const invalidConfigMessage = "Invalid JSON: Unexpected token at position 10";
134+
const nodeWithInvalidConfig: NodeTransport = {
135+
...node,
136+
invalidContent: true,
137+
invalidConfiguration: invalidConfigMessage,
138+
};
139+
140+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig);
141+
142+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, false);
143+
144+
expect(loggingTestTransport.logMessages.length).toBe(12);
145+
expect(loggingTestTransport.logMessages[0].message).toContain(`ID: ${nodeWithInvalidConfig.id}`);
146+
expect(loggingTestTransport.logMessages[10].message).toContain(`Invalid Configuration: ${invalidConfigMessage}`);
147+
expect(loggingTestTransport.logMessages[11].message).toContain(`Flavor: ${nodeWithInvalidConfig.flavor}`);
148+
});
149+
150+
it("Should find node with invalid configuration and return as JSON", async () => {
151+
const packageKey = "package-key";
152+
const nodeKey = "node-key";
153+
const invalidConfigMessage = "Syntax error in configuration";
154+
const nodeWithInvalidConfig: NodeTransport = {
155+
...node,
156+
invalidContent: true,
157+
invalidConfiguration: invalidConfigMessage,
158+
};
159+
160+
mockAxiosGet(`https://myTeam.celonis.cloud/pacman/api/core/staging/packages/${packageKey}/nodes/${nodeKey}?withConfiguration=false`, nodeWithInvalidConfig);
161+
162+
await new NodeService(testContext).findNode(packageKey, nodeKey, false, true);
163+
164+
const expectedFileName = loggingTestTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
165+
166+
expect(mockWriteFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), expect.any(String), {encoding: "utf-8"});
167+
168+
const nodeTransport = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as NodeTransport;
169+
170+
expect(nodeTransport).toEqual(nodeWithInvalidConfig);
171+
expect(nodeTransport.invalidConfiguration).toEqual(invalidConfigMessage);
172+
expect(nodeTransport.invalidContent).toBe(true);
173+
});
174+
});
175+

0 commit comments

Comments
 (0)