@get-dx/cli 0.2.0 → 0.2.1
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/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { initCommand } from "./commands/init.js";
|
|
|
5
5
|
import { scorecardsCommand } from "./commands/scorecards.js";
|
|
6
6
|
import { studioCommand } from "./commands/studio.js";
|
|
7
7
|
import { teamsCommand } from "./commands/teams.js";
|
|
8
|
+
import { workflowsCommand } from "./commands/workflows.js";
|
|
8
9
|
import { handleError } from "./commandHelpers.js";
|
|
9
10
|
import cliPackage from "../package.json" with { type: "json" };
|
|
10
11
|
export async function run(argv = process.argv) {
|
|
@@ -35,6 +36,7 @@ function createProgram() {
|
|
|
35
36
|
program.addCommand(scorecardsCommand());
|
|
36
37
|
program.addCommand(studioCommand());
|
|
37
38
|
program.addCommand(teamsCommand());
|
|
39
|
+
program.addCommand(workflowsCommand());
|
|
38
40
|
applyExitOverride(program);
|
|
39
41
|
return program;
|
|
40
42
|
}
|
|
@@ -21,6 +21,7 @@ export function entitiesCommand() {
|
|
|
21
21
|
.option("--owner-team-ids <ids>", "Comma-separated owner team IDs")
|
|
22
22
|
.option("--owner-user-ids <ids>", "Comma-separated owner user IDs")
|
|
23
23
|
.option("--property <kv>", "Set a property value as key=value. Repeat for multiple properties.", (val, prev) => [...prev, val], [])
|
|
24
|
+
.option("--alias <kv>", "Set an alias value as key=value. Repeat for multiple aliases.", (val, prev) => [...prev, val], [])
|
|
24
25
|
.addHelpText("afterAll", createExampleText([
|
|
25
26
|
{
|
|
26
27
|
label: "Create a new service entity",
|
|
@@ -38,6 +39,10 @@ export function entitiesCommand() {
|
|
|
38
39
|
label: "Create with properties",
|
|
39
40
|
command: 'dx catalog entities create --type service --identifier my-service --property tier=Tier-1 --property "languages=Ruby,TypeScript"',
|
|
40
41
|
},
|
|
42
|
+
{
|
|
43
|
+
label: "Create with aliases",
|
|
44
|
+
command: "dx catalog entities create --type service --identifier my-service --alias github_repo=12345",
|
|
45
|
+
},
|
|
41
46
|
]))
|
|
42
47
|
.action(wrapAction(async (options, command) => {
|
|
43
48
|
if (!options.identifier) {
|
|
@@ -47,7 +52,7 @@ export function entitiesCommand() {
|
|
|
47
52
|
throw new CliError("--type is required", EXIT_CODES.ARGUMENT_ERROR);
|
|
48
53
|
}
|
|
49
54
|
const runtime = buildRuntime(getContext(command));
|
|
50
|
-
const
|
|
55
|
+
const resolvedValues = await resolveValuesForEntityType(runtime, options.type, options.property, options.alias);
|
|
51
56
|
const response = await createEntity(runtime, options.identifier, {
|
|
52
57
|
type: options.type,
|
|
53
58
|
name: options.name,
|
|
@@ -58,7 +63,7 @@ export function entitiesCommand() {
|
|
|
58
63
|
owner_user_ids: options.ownerUserIds
|
|
59
64
|
?.split(",")
|
|
60
65
|
.map((s) => s.trim()),
|
|
61
|
-
|
|
66
|
+
...resolvedValues,
|
|
62
67
|
});
|
|
63
68
|
if (runtime.context.json) {
|
|
64
69
|
renderJson(response);
|
|
@@ -100,6 +105,7 @@ export function entitiesCommand() {
|
|
|
100
105
|
.option("--owner-team-ids <ids>", "Comma-separated owner team IDs")
|
|
101
106
|
.option("--owner-user-ids <ids>", "Comma-separated owner user IDs")
|
|
102
107
|
.option("--property <kv>", "Set a property value as key=value. Repeat for multiple properties. Use value null to remove a property.", (val, prev) => [...prev, val], [])
|
|
108
|
+
.option("--alias <kv>", "Set an alias value as key=value. Repeat for multiple aliases. Use value null to remove an alias.", (val, prev) => [...prev, val], [])
|
|
103
109
|
.addHelpText("afterAll", createExampleText([
|
|
104
110
|
{
|
|
105
111
|
label: "Rename an entity",
|
|
@@ -113,13 +119,17 @@ export function entitiesCommand() {
|
|
|
113
119
|
label: "Update properties",
|
|
114
120
|
command: 'dx catalog entities update my-service --property tier=Tier-1 --property "languages=Ruby,TypeScript"',
|
|
115
121
|
},
|
|
122
|
+
{
|
|
123
|
+
label: "Update aliases",
|
|
124
|
+
command: "dx catalog entities update my-service --alias github_repo=12345",
|
|
125
|
+
},
|
|
116
126
|
]))
|
|
117
127
|
.action(wrapAction(async (identifier, options, command) => {
|
|
118
128
|
const runtime = buildRuntime(getContext(command));
|
|
119
|
-
const
|
|
129
|
+
const resolvedValues = await resolveValuesForExistingEntity(runtime, identifier, options.property, options.alias);
|
|
120
130
|
const response = await updateEntity(runtime, identifier, {
|
|
121
131
|
...getEntityMutationOptionValues(options),
|
|
122
|
-
|
|
132
|
+
...resolvedValues,
|
|
123
133
|
});
|
|
124
134
|
if (runtime.context.json) {
|
|
125
135
|
renderJson(response);
|
|
@@ -138,6 +148,7 @@ export function entitiesCommand() {
|
|
|
138
148
|
.option("--owner-team-ids <ids>", "Comma-separated owner team IDs")
|
|
139
149
|
.option("--owner-user-ids <ids>", "Comma-separated owner user IDs")
|
|
140
150
|
.option("--property <kv>", "Set a property value as key=value. Repeat for multiple properties. Use value null to remove a property.", (val, prev) => [...prev, val], [])
|
|
151
|
+
.option("--alias <kv>", "Set an alias value as key=value. Repeat for multiple aliases. Use value null to remove an alias.", (val, prev) => [...prev, val], [])
|
|
141
152
|
.addHelpText("afterAll", createExampleText([
|
|
142
153
|
{
|
|
143
154
|
label: "Create a new service entity if it does not exist",
|
|
@@ -151,6 +162,10 @@ export function entitiesCommand() {
|
|
|
151
162
|
label: "Set properties while preserving omitted fields",
|
|
152
163
|
command: 'dx catalog entities upsert --type service --identifier my-service --property tier=Tier-1 --property "languages=Ruby,TypeScript"',
|
|
153
164
|
},
|
|
165
|
+
{
|
|
166
|
+
label: "Set aliases while preserving omitted fields",
|
|
167
|
+
command: "dx catalog entities upsert --type service --identifier my-service --alias github_repo=12345",
|
|
168
|
+
},
|
|
154
169
|
]))
|
|
155
170
|
.action(wrapAction(async (options, command) => {
|
|
156
171
|
if (!options.type) {
|
|
@@ -160,11 +175,11 @@ export function entitiesCommand() {
|
|
|
160
175
|
throw new CliError("--identifier is required", EXIT_CODES.ARGUMENT_ERROR);
|
|
161
176
|
}
|
|
162
177
|
const runtime = buildRuntime(getContext(command));
|
|
163
|
-
const
|
|
178
|
+
const resolvedValues = await resolveValuesForEntityType(runtime, options.type, options.property, options.alias);
|
|
164
179
|
const response = await upsertEntity(runtime, options.identifier, {
|
|
165
180
|
type: options.type,
|
|
166
181
|
...getEntityMutationOptionValues(options),
|
|
167
|
-
|
|
182
|
+
...resolvedValues,
|
|
168
183
|
});
|
|
169
184
|
if (runtime.context.json) {
|
|
170
185
|
renderJson(response);
|
|
@@ -459,6 +474,33 @@ export function parsePropertyValue(prop, rawValue) {
|
|
|
459
474
|
return rawValue;
|
|
460
475
|
}
|
|
461
476
|
}
|
|
477
|
+
function parseEntityAliases(entityTypeIdentifier, rawAliases, knownAliases) {
|
|
478
|
+
const aliasKeys = Object.keys(knownAliases);
|
|
479
|
+
const aliasSet = new Set(aliasKeys);
|
|
480
|
+
const result = {};
|
|
481
|
+
for (const kv of rawAliases) {
|
|
482
|
+
const eqIndex = kv.indexOf("=");
|
|
483
|
+
if (eqIndex === -1) {
|
|
484
|
+
throw new CliError(`Invalid --alias "${kv}": expected format key=value`, EXIT_CODES.ARGUMENT_ERROR);
|
|
485
|
+
}
|
|
486
|
+
const key = kv.slice(0, eqIndex);
|
|
487
|
+
const rawValue = kv.slice(eqIndex + 1);
|
|
488
|
+
if (!aliasSet.has(key)) {
|
|
489
|
+
const availableAliases = aliasKeys
|
|
490
|
+
.sort()
|
|
491
|
+
.map((k) => `\`${k}\``)
|
|
492
|
+
.join(", ");
|
|
493
|
+
const availableAliasesText = availableAliases.length > 0 ? availableAliases : "(none)";
|
|
494
|
+
throw new CliError(`Unknown alias \`${key}\` for entity type \`${entityTypeIdentifier}\`. Available aliases: ${availableAliasesText}`, EXIT_CODES.ARGUMENT_ERROR);
|
|
495
|
+
}
|
|
496
|
+
if (rawValue === "null") {
|
|
497
|
+
result[key] = [];
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
result[key] = [...(result[key] ?? []), { identifier: rawValue }];
|
|
501
|
+
}
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
462
504
|
// --- Include helpers ---
|
|
463
505
|
const ENTITY_INCLUDE_SECTIONS = [
|
|
464
506
|
"core",
|
|
@@ -487,22 +529,31 @@ function parseIncludeSections(include) {
|
|
|
487
529
|
}
|
|
488
530
|
return results;
|
|
489
531
|
}
|
|
490
|
-
async function
|
|
491
|
-
if (rawProperties.length === 0) {
|
|
492
|
-
return
|
|
532
|
+
async function resolveValuesForEntityType(runtime, entityTypeIdentifier, rawProperties, rawAliases) {
|
|
533
|
+
if (rawProperties.length === 0 && rawAliases.length === 0) {
|
|
534
|
+
return {};
|
|
493
535
|
}
|
|
494
536
|
let entityTypeResponse;
|
|
495
537
|
try {
|
|
496
538
|
entityTypeResponse = await getEntityType(runtime, entityTypeIdentifier);
|
|
497
539
|
}
|
|
498
540
|
catch (err) {
|
|
499
|
-
throw wrapEntityTypeLookupError(entityTypeIdentifier, err
|
|
541
|
+
throw wrapEntityTypeLookupError(entityTypeIdentifier, err, rawAliases.length > 0
|
|
542
|
+
? "resolve property and alias values"
|
|
543
|
+
: "resolve property types");
|
|
544
|
+
}
|
|
545
|
+
const values = {};
|
|
546
|
+
if (rawProperties.length > 0) {
|
|
547
|
+
values.properties = parseEntityProperties(entityTypeIdentifier, rawProperties, entityTypeResponse.entity_type.properties);
|
|
500
548
|
}
|
|
501
|
-
|
|
549
|
+
if (rawAliases.length > 0) {
|
|
550
|
+
values.aliases = parseEntityAliases(entityTypeIdentifier, rawAliases, entityTypeResponse.entity_type.aliases);
|
|
551
|
+
}
|
|
552
|
+
return values;
|
|
502
553
|
}
|
|
503
|
-
async function
|
|
504
|
-
if (rawProperties.length === 0) {
|
|
505
|
-
return
|
|
554
|
+
async function resolveValuesForExistingEntity(runtime, identifier, rawProperties, rawAliases) {
|
|
555
|
+
if (rawProperties.length === 0 && rawAliases.length === 0) {
|
|
556
|
+
return {};
|
|
506
557
|
}
|
|
507
558
|
let entityResponse;
|
|
508
559
|
try {
|
|
@@ -512,9 +563,23 @@ async function resolvePropertiesForExistingEntity(runtime, identifier, rawProper
|
|
|
512
563
|
const exitCode = err instanceof HttpError && err.status !== undefined && err.status < 500
|
|
513
564
|
? EXIT_CODES.ARGUMENT_ERROR
|
|
514
565
|
: EXIT_CODES.RETRY_RECOMMENDED;
|
|
515
|
-
throw new CliError(`Failed to fetch entity "${identifier}" to resolve property
|
|
566
|
+
throw new CliError(`Failed to fetch entity "${identifier}" to resolve property and alias values: ${err instanceof Error ? err.message : String(err)}`, exitCode);
|
|
567
|
+
}
|
|
568
|
+
let entityTypeResponse;
|
|
569
|
+
try {
|
|
570
|
+
entityTypeResponse = await getEntityType(runtime, entityResponse.entity.type);
|
|
571
|
+
}
|
|
572
|
+
catch (err) {
|
|
573
|
+
throw wrapEntityTypeLookupError(entityResponse.entity.type, err, "resolve property and alias values");
|
|
574
|
+
}
|
|
575
|
+
const values = {};
|
|
576
|
+
if (rawProperties.length > 0) {
|
|
577
|
+
values.properties = parseEntityProperties(entityResponse.entity.type, rawProperties, entityTypeResponse.entity_type.properties);
|
|
578
|
+
}
|
|
579
|
+
if (rawAliases.length > 0) {
|
|
580
|
+
values.aliases = parseEntityAliases(entityResponse.entity.type, rawAliases, entityTypeResponse.entity_type.aliases);
|
|
516
581
|
}
|
|
517
|
-
return
|
|
582
|
+
return values;
|
|
518
583
|
}
|
|
519
584
|
function getEntityMutationOptionValues(options) {
|
|
520
585
|
return {
|
|
@@ -549,13 +614,15 @@ function buildEntityMutationBody(identifier, params) {
|
|
|
549
614
|
body.owner_user_ids = params.owner_user_ids;
|
|
550
615
|
if (params.properties !== undefined)
|
|
551
616
|
body.properties = params.properties;
|
|
617
|
+
if (params.aliases !== undefined)
|
|
618
|
+
body.aliases = params.aliases;
|
|
552
619
|
return body;
|
|
553
620
|
}
|
|
554
|
-
function wrapEntityTypeLookupError(entityTypeIdentifier, err) {
|
|
621
|
+
function wrapEntityTypeLookupError(entityTypeIdentifier, err, purpose = "resolve property types") {
|
|
555
622
|
const exitCode = err instanceof HttpError && err.status !== undefined && err.status < 500
|
|
556
623
|
? EXIT_CODES.ARGUMENT_ERROR
|
|
557
624
|
: EXIT_CODES.RETRY_RECOMMENDED;
|
|
558
|
-
return new CliError(`Failed to fetch entity type "${entityTypeIdentifier}" to
|
|
625
|
+
return new CliError(`Failed to fetch entity type "${entityTypeIdentifier}" to ${purpose}: ${err instanceof Error ? err.message : String(err)}`, exitCode);
|
|
559
626
|
}
|
|
560
627
|
function uniqueSectionsInOrder(sections) {
|
|
561
628
|
const seen = new Set();
|
|
@@ -97,7 +97,7 @@ function entityFilterContent(scorecard) {
|
|
|
97
97
|
else if (scorecard.entity_filter_type === "sql") {
|
|
98
98
|
blocks.push(ui.p(`Filter: ${ui.code("sql")}`));
|
|
99
99
|
if (scorecard.entity_filter_sql) {
|
|
100
|
-
blocks.push(truncatedSqlBlock(scorecard.entity_filter_sql));
|
|
100
|
+
blocks.push(ui.truncatedSqlBlock(scorecard.entity_filter_sql));
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
103
|
blocks.push(ui.p(ui.dim("(No SQL provided)")));
|
|
@@ -190,7 +190,7 @@ function checkContent(check, scorecardType) {
|
|
|
190
190
|
}
|
|
191
191
|
// Query
|
|
192
192
|
blocks.push(ui.p(ui.bold("Query:")));
|
|
193
|
-
blocks.push(truncatedSqlBlock(check.sql));
|
|
193
|
+
blocks.push(ui.truncatedSqlBlock(check.sql));
|
|
194
194
|
// Output settings
|
|
195
195
|
if (check.output_enabled) {
|
|
196
196
|
const outputParts = [`Output: ${ui.code(check.output_type ?? "unknown")}`];
|
|
@@ -202,18 +202,10 @@ function checkContent(check, scorecardType) {
|
|
|
202
202
|
// Entity filter
|
|
203
203
|
if (check.filter_sql) {
|
|
204
204
|
blocks.push(ui.p(ui.bold("Entity filter:")));
|
|
205
|
-
blocks.push(truncatedSqlBlock(check.filter_sql));
|
|
205
|
+
blocks.push(ui.truncatedSqlBlock(check.filter_sql));
|
|
206
206
|
if (check.filter_message) {
|
|
207
207
|
blocks.push(ui.p(`Excluded message: ${ui.dim(check.filter_message)}`, false));
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
return blocks;
|
|
211
211
|
}
|
|
212
|
-
function truncatedSqlBlock(sql) {
|
|
213
|
-
const lines = sql.split("\n");
|
|
214
|
-
const firstLine = lines[0];
|
|
215
|
-
const isLong = firstLine.length > 80 || lines.length > 1;
|
|
216
|
-
const truncated = firstLine.length > 80 ? firstLine.slice(0, 80) : firstLine;
|
|
217
|
-
const display = isLong ? truncated + ui.dim(" …") : truncated;
|
|
218
|
-
return ui.p(ui.code(display));
|
|
219
|
-
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { createExampleText, getContext, wrapAction, } from "../commandHelpers.js";
|
|
3
|
+
import { CliError, EXIT_CODES } from "../errors.js";
|
|
4
|
+
import { request } from "../http.js";
|
|
5
|
+
import { renderJson } from "../renderers.js";
|
|
6
|
+
import { buildRuntime } from "../runtime.js";
|
|
7
|
+
import { renderWorkflowList } from "./workflowsRendering.js";
|
|
8
|
+
const WORKFLOW_SCOPES = ["GLOBAL", "ENTITY"];
|
|
9
|
+
export function workflowsCommand() {
|
|
10
|
+
const workflows = new Command()
|
|
11
|
+
.name("workflows")
|
|
12
|
+
.description("Manage Self-service workflow definitions");
|
|
13
|
+
workflows
|
|
14
|
+
.command("list")
|
|
15
|
+
.description("List Self-service workflows for the account")
|
|
16
|
+
.option("--scope <scope>", "Filter by workflow scope: GLOBAL or ENTITY (omit for both)")
|
|
17
|
+
.option("--entity-identifier <id>", "Catalog entity identifier; must be used with --scope ENTITY")
|
|
18
|
+
.addHelpText("afterAll", createExampleText([
|
|
19
|
+
{
|
|
20
|
+
label: "List workflows the token can trigger",
|
|
21
|
+
command: "dx workflows list",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "Entity-scoped workflows for a catalog entity",
|
|
25
|
+
command: "dx workflows list --scope ENTITY --entity-identifier acme-app",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: "Same request as JSON",
|
|
29
|
+
command: "dx --json workflows list --scope ENTITY --entity-identifier acme-app",
|
|
30
|
+
},
|
|
31
|
+
]))
|
|
32
|
+
.action(wrapAction(async (options, command) => {
|
|
33
|
+
const scope = parseOptionalScope(options.scope);
|
|
34
|
+
const entityIdentifier = parseOptionalTrimmed(options.entityIdentifier);
|
|
35
|
+
if (entityIdentifier && scope !== "ENTITY") {
|
|
36
|
+
throw new CliError("--entity-identifier requires --scope ENTITY", EXIT_CODES.ARGUMENT_ERROR);
|
|
37
|
+
}
|
|
38
|
+
const runtime = buildRuntime(getContext(command));
|
|
39
|
+
const response = await listWorkflows(runtime, {
|
|
40
|
+
scope,
|
|
41
|
+
entity_identifier: entityIdentifier,
|
|
42
|
+
});
|
|
43
|
+
if (runtime.context.json) {
|
|
44
|
+
renderJson(response);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
renderWorkflowList(response.workflows);
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
return workflows;
|
|
51
|
+
}
|
|
52
|
+
function parseOptionalTrimmed(value) {
|
|
53
|
+
if (typeof value !== "string") {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const t = value.trim();
|
|
57
|
+
return t.length > 0 ? t : undefined;
|
|
58
|
+
}
|
|
59
|
+
function parseOptionalScope(value) {
|
|
60
|
+
const raw = parseOptionalTrimmed(value);
|
|
61
|
+
if (raw === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
if (!WORKFLOW_SCOPES.includes(raw)) {
|
|
65
|
+
throw new CliError(`--scope must be one of: ${WORKFLOW_SCOPES.join(", ")}`, EXIT_CODES.ARGUMENT_ERROR);
|
|
66
|
+
}
|
|
67
|
+
return raw;
|
|
68
|
+
}
|
|
69
|
+
// --- API ---
|
|
70
|
+
async function listWorkflows(runtime, params) {
|
|
71
|
+
const query = {};
|
|
72
|
+
if (params.scope !== undefined)
|
|
73
|
+
query.scope = params.scope;
|
|
74
|
+
if (params.entity_identifier !== undefined) {
|
|
75
|
+
query.entity_identifier = params.entity_identifier;
|
|
76
|
+
}
|
|
77
|
+
const response = await request(runtime, "/workflows.list", {
|
|
78
|
+
method: "GET",
|
|
79
|
+
query,
|
|
80
|
+
});
|
|
81
|
+
return response.body;
|
|
82
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { renderRichText } from "../renderers.js";
|
|
2
|
+
import * as ui from "../ui.js";
|
|
3
|
+
const WORKFLOW_SCOPE_LABELS = {
|
|
4
|
+
GLOBAL: "Global",
|
|
5
|
+
ENTITY: "Catalog entity",
|
|
6
|
+
};
|
|
7
|
+
const WORKFLOW_EXECUTION_TYPE_LABELS = {
|
|
8
|
+
SIMPLE: "Simple",
|
|
9
|
+
EVENT_DRIVEN: "Event-driven",
|
|
10
|
+
};
|
|
11
|
+
const WORKFLOW_TRIGGER_TYPE_LABELS = {
|
|
12
|
+
ANY: "All users",
|
|
13
|
+
APPROVAL: "All users with approval",
|
|
14
|
+
RUNNERS: "Selected teams and users",
|
|
15
|
+
ENTITY: "Entity owners only",
|
|
16
|
+
};
|
|
17
|
+
const WORKFLOW_TRIGGER_TYPE_DESCRIPTIONS = {
|
|
18
|
+
ANY: "All users can trigger this workflow run without approval.",
|
|
19
|
+
APPROVAL: "All users can request a workflow run, but a designated approver must accept before it runs.",
|
|
20
|
+
RUNNERS: "Only selected teams or users can trigger a workflow run.",
|
|
21
|
+
ENTITY: "Only users who directly own the entity, or belong to an owning team, can trigger a run.",
|
|
22
|
+
};
|
|
23
|
+
function workflowScopeLabel(scope) {
|
|
24
|
+
return WORKFLOW_SCOPE_LABELS[scope] ?? scope;
|
|
25
|
+
}
|
|
26
|
+
function workflowExecutionTypeLabel(executionType) {
|
|
27
|
+
return WORKFLOW_EXECUTION_TYPE_LABELS[executionType] ?? executionType;
|
|
28
|
+
}
|
|
29
|
+
function workflowTriggerTypeLabel(triggerType) {
|
|
30
|
+
return WORKFLOW_TRIGGER_TYPE_LABELS[triggerType] ?? triggerType;
|
|
31
|
+
}
|
|
32
|
+
function workflowTriggerTypeDescription(triggerType) {
|
|
33
|
+
return WORKFLOW_TRIGGER_TYPE_DESCRIPTIONS[triggerType] ?? "";
|
|
34
|
+
}
|
|
35
|
+
export function renderWorkflowList(workflows) {
|
|
36
|
+
const blocks = [
|
|
37
|
+
ui.h1("Workflows"),
|
|
38
|
+
ui.p(`Displaying ${ui.bold(workflows.length.toString())} workflows.`),
|
|
39
|
+
];
|
|
40
|
+
for (const workflow of workflows) {
|
|
41
|
+
blocks.push(ui.h2(`${workflow.name} (${ui.code(workflow.identifier)})`));
|
|
42
|
+
blocks.push(ui.h3("Core attributes"));
|
|
43
|
+
blocks.push(...coreContent(workflow));
|
|
44
|
+
if (workflow.scope === "ENTITY") {
|
|
45
|
+
blocks.push(ui.h3("Entity filter"));
|
|
46
|
+
blocks.push(...entityFilterContent(workflow));
|
|
47
|
+
}
|
|
48
|
+
blocks.push(ui.h3("Parameters"));
|
|
49
|
+
blocks.push(...parametersContent(workflow));
|
|
50
|
+
}
|
|
51
|
+
renderRichText(blocks);
|
|
52
|
+
}
|
|
53
|
+
function coreContent(workflow) {
|
|
54
|
+
const blocks = [];
|
|
55
|
+
const description = workflow.description?.trim()
|
|
56
|
+
? workflow.description
|
|
57
|
+
: ui.dim("(None)");
|
|
58
|
+
blocks.push(ui.dl([
|
|
59
|
+
ui.dli("Description", description),
|
|
60
|
+
ui.dli("Scope", workflowScopeLabel(workflow.scope)),
|
|
61
|
+
ui.dli("Execution type", workflowExecutionTypeLabel(workflow.execution_type)),
|
|
62
|
+
ui.dli("Who can run", `${workflowTriggerTypeLabel(workflow.trigger_type)} ${ui.dim(workflowTriggerTypeDescription(workflow.trigger_type))}`),
|
|
63
|
+
], { termWidth: 16 }));
|
|
64
|
+
return blocks;
|
|
65
|
+
}
|
|
66
|
+
function entityFilterContent(workflow) {
|
|
67
|
+
const blocks = [];
|
|
68
|
+
if (workflow.entity_filter_type === "ENTITY_TYPES") {
|
|
69
|
+
blocks.push(ui.p(`Filter type: ${ui.code("Entity types")}`));
|
|
70
|
+
if (workflow.entity_filter_type_identifiers &&
|
|
71
|
+
workflow.entity_filter_type_identifiers.length > 0) {
|
|
72
|
+
blocks.push(ui.ul(workflow.entity_filter_type_identifiers.map((identifier) => ui.li([ui.p(ui.code(identifier), false)]))));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (workflow.entity_filter_type === "SQL") {
|
|
76
|
+
blocks.push(ui.p(`Filter type: ${ui.code("SQL")}`));
|
|
77
|
+
if (workflow.entity_filter_sql) {
|
|
78
|
+
blocks.push(ui.truncatedSqlBlock(workflow.entity_filter_sql));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return blocks;
|
|
82
|
+
}
|
|
83
|
+
function parametersContent(workflow) {
|
|
84
|
+
if (workflow.parameters.length === 0) {
|
|
85
|
+
return [ui.p(ui.dim("(No parameters)"))];
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
ui.ul(workflow.parameters.map((parameter) => ui.li(singleParameterContent(parameter)))),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
function singleParameterContent(parameter) {
|
|
92
|
+
const requiredPart = parameter.is_required ? ` ${ui.dim("required")}` : "";
|
|
93
|
+
const headline = `${ui.bold(parameter.name)} (${ui.code(parameter.identifier)}) ${ui.code(parameter.type)}${requiredPart}`;
|
|
94
|
+
const blocks = [ui.p(headline, false)];
|
|
95
|
+
const desc = parameter.description?.trim();
|
|
96
|
+
if (desc) {
|
|
97
|
+
blocks.push(ui.p(desc, false));
|
|
98
|
+
}
|
|
99
|
+
if (parameter.default_value !== null &&
|
|
100
|
+
parameter.default_value !== undefined &&
|
|
101
|
+
parameter.default_value !== "") {
|
|
102
|
+
blocks.push(ui.p(`Default: ${ui.code(formatParameterDefault(parameter.default_value))}`, false));
|
|
103
|
+
}
|
|
104
|
+
if (parameter.type === "SELECT") {
|
|
105
|
+
const options = selectParameterOptions(parameter.definition);
|
|
106
|
+
if (options.length > 0) {
|
|
107
|
+
blocks.push(ui.p("Options:", false));
|
|
108
|
+
blocks.push(ui.ul(options.map((value) => ui.li([ui.p(ui.code(value), false)]))));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return blocks;
|
|
112
|
+
}
|
|
113
|
+
function selectParameterOptions(definition) {
|
|
114
|
+
if (!definition || typeof definition !== "object") {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
const raw = definition.options;
|
|
118
|
+
if (!Array.isArray(raw)) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
return raw.filter((item) => typeof item === "string");
|
|
122
|
+
}
|
|
123
|
+
function formatParameterDefault(value) {
|
|
124
|
+
if (typeof value === "string") {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
128
|
+
return String(value);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return JSON.stringify(value);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return String(value);
|
|
135
|
+
}
|
|
136
|
+
}
|
package/dist/ui.js
CHANGED
|
@@ -58,6 +58,14 @@ export function json(value) {
|
|
|
58
58
|
export function blankLine() {
|
|
59
59
|
return new ParagraphBlock("", false);
|
|
60
60
|
}
|
|
61
|
+
export function truncatedSqlBlock(sql) {
|
|
62
|
+
const lines = sql.split("\n");
|
|
63
|
+
const firstLine = lines[0];
|
|
64
|
+
const isLong = firstLine.length > 80 || lines.length > 1;
|
|
65
|
+
const truncated = firstLine.length > 80 ? firstLine.slice(0, 80) : firstLine;
|
|
66
|
+
const display = isLong ? truncated + dim(" …") : truncated;
|
|
67
|
+
return p(code(display));
|
|
68
|
+
}
|
|
61
69
|
// Inline elements
|
|
62
70
|
export function bold(text) {
|
|
63
71
|
return pc.bold(text);
|