@camunda8/cli 2.7.0-alpha.1 → 2.7.0-alpha.10

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 (144) hide show
  1. package/README.md +80 -1
  2. package/dist/command-dispatch.d.ts +16 -0
  3. package/dist/command-dispatch.d.ts.map +1 -0
  4. package/dist/command-dispatch.js +129 -0
  5. package/dist/command-dispatch.js.map +1 -0
  6. package/dist/command-framework.d.ts +248 -0
  7. package/dist/command-framework.d.ts.map +1 -0
  8. package/dist/command-framework.js +229 -0
  9. package/dist/command-framework.js.map +1 -0
  10. package/dist/command-registry.d.ts +2014 -14
  11. package/dist/command-registry.d.ts.map +1 -1
  12. package/dist/command-registry.js +653 -66
  13. package/dist/command-registry.js.map +1 -1
  14. package/dist/command-validation.d.ts +30 -4
  15. package/dist/command-validation.d.ts.map +1 -1
  16. package/dist/command-validation.js +90 -4
  17. package/dist/command-validation.js.map +1 -1
  18. package/dist/commands/completion.d.ts +25 -1
  19. package/dist/commands/completion.d.ts.map +1 -1
  20. package/dist/commands/completion.js +590 -1223
  21. package/dist/commands/completion.js.map +1 -1
  22. package/dist/commands/deployments.d.ts +2 -0
  23. package/dist/commands/deployments.d.ts.map +1 -1
  24. package/dist/commands/deployments.js +13 -2
  25. package/dist/commands/deployments.js.map +1 -1
  26. package/dist/commands/forms.d.ts +2 -20
  27. package/dist/commands/forms.d.ts.map +1 -1
  28. package/dist/commands/forms.js +76 -79
  29. package/dist/commands/forms.js.map +1 -1
  30. package/dist/commands/help.d.ts +4 -88
  31. package/dist/commands/help.d.ts.map +1 -1
  32. package/dist/commands/help.js +574 -1948
  33. package/dist/commands/help.js.map +1 -1
  34. package/dist/commands/identity-authorizations.d.ts +5 -24
  35. package/dist/commands/identity-authorizations.d.ts.map +1 -1
  36. package/dist/commands/identity-authorizations.js +113 -137
  37. package/dist/commands/identity-authorizations.js.map +1 -1
  38. package/dist/commands/identity-groups.d.ts +5 -26
  39. package/dist/commands/identity-groups.d.ts.map +1 -1
  40. package/dist/commands/identity-groups.js +91 -124
  41. package/dist/commands/identity-groups.js.map +1 -1
  42. package/dist/commands/identity-mapping-rules.d.ts +5 -30
  43. package/dist/commands/identity-mapping-rules.d.ts.map +1 -1
  44. package/dist/commands/identity-mapping-rules.js +106 -136
  45. package/dist/commands/identity-mapping-rules.js.map +1 -1
  46. package/dist/commands/identity-roles.d.ts +5 -26
  47. package/dist/commands/identity-roles.d.ts.map +1 -1
  48. package/dist/commands/identity-roles.js +91 -124
  49. package/dist/commands/identity-roles.js.map +1 -1
  50. package/dist/commands/identity-tenants.d.ts +5 -26
  51. package/dist/commands/identity-tenants.d.ts.map +1 -1
  52. package/dist/commands/identity-tenants.js +92 -126
  53. package/dist/commands/identity-tenants.js.map +1 -1
  54. package/dist/commands/identity-users.d.ts +5 -29
  55. package/dist/commands/identity-users.d.ts.map +1 -1
  56. package/dist/commands/identity-users.js +95 -129
  57. package/dist/commands/identity-users.js.map +1 -1
  58. package/dist/commands/identity.d.ts +6 -6
  59. package/dist/commands/identity.d.ts.map +1 -1
  60. package/dist/commands/identity.js +6 -7
  61. package/dist/commands/identity.js.map +1 -1
  62. package/dist/commands/incidents.d.ts +3 -16
  63. package/dist/commands/incidents.d.ts.map +1 -1
  64. package/dist/commands/incidents.js +71 -98
  65. package/dist/commands/incidents.js.map +1 -1
  66. package/dist/commands/jobs.d.ts +4 -26
  67. package/dist/commands/jobs.d.ts.map +1 -1
  68. package/dist/commands/jobs.js +143 -159
  69. package/dist/commands/jobs.js.map +1 -1
  70. package/dist/commands/mcp-proxy.d.ts +1 -0
  71. package/dist/commands/mcp-proxy.d.ts.map +1 -1
  72. package/dist/commands/mcp-proxy.js +10 -2
  73. package/dist/commands/mcp-proxy.js.map +1 -1
  74. package/dist/commands/messages.d.ts +2 -12
  75. package/dist/commands/messages.d.ts.map +1 -1
  76. package/dist/commands/messages.js +87 -81
  77. package/dist/commands/messages.js.map +1 -1
  78. package/dist/commands/open.d.ts +4 -0
  79. package/dist/commands/open.d.ts.map +1 -1
  80. package/dist/commands/open.js +18 -0
  81. package/dist/commands/open.js.map +1 -1
  82. package/dist/commands/plugins.d.ts +7 -9
  83. package/dist/commands/plugins.d.ts.map +1 -1
  84. package/dist/commands/plugins.js +32 -25
  85. package/dist/commands/plugins.js.map +1 -1
  86. package/dist/commands/process-definitions.d.ts +2 -14
  87. package/dist/commands/process-definitions.d.ts.map +1 -1
  88. package/dist/commands/process-definitions.js +57 -80
  89. package/dist/commands/process-definitions.js.map +1 -1
  90. package/dist/commands/process-instances.d.ts +8 -37
  91. package/dist/commands/process-instances.d.ts.map +1 -1
  92. package/dist/commands/process-instances.js +242 -193
  93. package/dist/commands/process-instances.js.map +1 -1
  94. package/dist/commands/profiles.d.ts +4 -0
  95. package/dist/commands/profiles.d.ts.map +1 -1
  96. package/dist/commands/profiles.js +29 -0
  97. package/dist/commands/profiles.js.map +1 -1
  98. package/dist/commands/run.d.ts +2 -0
  99. package/dist/commands/run.d.ts.map +1 -1
  100. package/dist/commands/run.js +10 -0
  101. package/dist/commands/run.js.map +1 -1
  102. package/dist/commands/search.d.ts +7 -100
  103. package/dist/commands/search.d.ts.map +1 -1
  104. package/dist/commands/search.js +530 -694
  105. package/dist/commands/search.js.map +1 -1
  106. package/dist/commands/session.d.ts +3 -0
  107. package/dist/commands/session.d.ts.map +1 -1
  108. package/dist/commands/session.js +30 -0
  109. package/dist/commands/session.js.map +1 -1
  110. package/dist/commands/topology.d.ts +1 -3
  111. package/dist/commands/topology.d.ts.map +1 -1
  112. package/dist/commands/topology.js +11 -18
  113. package/dist/commands/topology.js.map +1 -1
  114. package/dist/commands/user-tasks.d.ts +2 -16
  115. package/dist/commands/user-tasks.d.ts.map +1 -1
  116. package/dist/commands/user-tasks.js +73 -101
  117. package/dist/commands/user-tasks.js.map +1 -1
  118. package/dist/commands/watch.d.ts +1 -0
  119. package/dist/commands/watch.d.ts.map +1 -1
  120. package/dist/commands/watch.js +15 -0
  121. package/dist/commands/watch.js.map +1 -1
  122. package/dist/config.d.ts.map +1 -1
  123. package/dist/config.js +5 -0
  124. package/dist/config.js.map +1 -1
  125. package/dist/default-plugins/cluster/README.md +1 -1
  126. package/dist/default-plugins/cluster/c8ctl-plugin.js +281 -59
  127. package/dist/index.d.ts +0 -4
  128. package/dist/index.d.ts.map +1 -1
  129. package/dist/index.js +102 -979
  130. package/dist/index.js.map +1 -1
  131. package/dist/logger.d.ts +5 -0
  132. package/dist/logger.d.ts.map +1 -1
  133. package/dist/logger.js +7 -1
  134. package/dist/logger.js.map +1 -1
  135. package/dist/plugin-loader.d.ts +5 -0
  136. package/dist/plugin-loader.d.ts.map +1 -1
  137. package/dist/plugin-loader.js +1 -0
  138. package/dist/plugin-loader.js.map +1 -1
  139. package/dist/update-check.d.ts +67 -0
  140. package/dist/update-check.d.ts.map +1 -0
  141. package/dist/update-check.js +284 -0
  142. package/dist/update-check.js.map +1 -0
  143. package/package.json +3 -2
  144. /package/dist/templates/{tsconfig.json → tsconfig.json.template} +0 -0
@@ -1,136 +1,10 @@
1
1
  /**
2
2
  * Search commands
3
3
  */
4
- import { createClient, DEFAULT_PAGE_SIZE, emitDryRun, fetchAllPages, } from "../client.js";
5
- import { resolveTenantId } from "../config.js";
4
+ import { DEFAULT_PAGE_SIZE, fetchAllPages } from "../client.js";
5
+ import { defineCommand, dryRun } from "../command-framework.js";
6
6
  import { buildDateFilter, parseBetween } from "../date-filter.js";
7
- import { handleCommandError } from "../errors.js";
8
- import { getLogger, sortTableData, } from "../logger.js";
9
- /**
10
- * CLI infrastructure flags — valid for every command, never passed to search APIs.
11
- */
12
- const CLI_FLAGS = new Set(["profile", "help", "version"]);
13
- /**
14
- * Search behavior flags consumed by shared infrastructure (fetchAllPages / buildDateFilter / sort)
15
- * for ALL search resources. A flag belongs here only if every search handler consumes it
16
- * via shared code paths — never for flags consumed by a subset of handlers.
17
- *
18
- * If a flag is only relevant to some resources, put it in SEARCH_RESOURCE_FLAGS instead.
19
- */
20
- const SHARED_SEARCH_FLAGS = new Set([
21
- "sortBy",
22
- "asc",
23
- "desc",
24
- "between",
25
- "dateField",
26
- ]);
27
- /**
28
- * Union of CLI_FLAGS and SHARED_SEARCH_FLAGS — exported for use in detectUnknownSearchFlags.
29
- * Do NOT add resource-specific flags here; add them to SEARCH_RESOURCE_FLAGS instead.
30
- */
31
- export const GLOBAL_FLAGS = new Set([...CLI_FLAGS, ...SHARED_SEARCH_FLAGS]);
32
- /**
33
- * Valid search filter flags per resource (values keys that are consumed by the search handler).
34
- * This map is used to detect when a user passes a flag that looks valid but is not recognized
35
- * for the specific resource, causing silent filter drops.
36
- */
37
- export const SEARCH_RESOURCE_FLAGS = {
38
- "process-definition": new Set([
39
- "bpmnProcessId",
40
- "id",
41
- "processDefinitionId",
42
- "name",
43
- "key",
44
- "iid",
45
- "iname",
46
- ]),
47
- "process-instance": new Set([
48
- "bpmnProcessId",
49
- "id",
50
- "processDefinitionId",
51
- "processDefinitionKey",
52
- "state",
53
- "key",
54
- "parentProcessInstanceKey",
55
- "iid",
56
- ]),
57
- "user-task": new Set([
58
- "state",
59
- "assignee",
60
- "processInstanceKey",
61
- "processDefinitionKey",
62
- "elementId",
63
- "iassignee",
64
- ]),
65
- incident: new Set([
66
- "state",
67
- "processInstanceKey",
68
- "processDefinitionKey",
69
- "bpmnProcessId",
70
- "id",
71
- "processDefinitionId",
72
- "errorType",
73
- "errorMessage",
74
- "ierrorMessage",
75
- "iid",
76
- ]),
77
- jobs: new Set([
78
- "state",
79
- "type",
80
- "processInstanceKey",
81
- "processDefinitionKey",
82
- "itype",
83
- ]),
84
- variable: new Set([
85
- "name",
86
- "value",
87
- "processInstanceKey",
88
- "scopeKey",
89
- "fullValue",
90
- "iname",
91
- "ivalue",
92
- "limit",
93
- ]),
94
- user: new Set(["username", "name", "email", "limit"]),
95
- role: new Set(["roleId", "name", "limit"]),
96
- group: new Set(["groupId", "name", "limit"]),
97
- tenant: new Set(["tenantId", "name", "limit"]),
98
- authorization: new Set([
99
- "ownerId",
100
- "ownerType",
101
- "resourceType",
102
- "resourceId",
103
- "limit",
104
- ]),
105
- "mapping-rule": new Set([
106
- "mappingRuleId",
107
- "name",
108
- "claimName",
109
- "claimValue",
110
- "limit",
111
- ]),
112
- };
113
- /**
114
- * Detect flags the user set that are not recognized for the given search resource.
115
- * Returns the list of unknown flag names (without the --prefix).
116
- */
117
- export function detectUnknownSearchFlags(values, normalizedResource) {
118
- const validFlags = SEARCH_RESOURCE_FLAGS[normalizedResource] ||
119
- SEARCH_RESOURCE_FLAGS[normalizedResource.replace(/s$/, "")];
120
- if (!validFlags)
121
- return [];
122
- const unknown = [];
123
- for (const [key, val] of Object.entries(values)) {
124
- if (val === undefined || val === false)
125
- continue; // not set by the user
126
- if (GLOBAL_FLAGS.has(key))
127
- continue;
128
- if (validFlags.has(key))
129
- continue;
130
- unknown.push(key);
131
- }
132
- return unknown;
133
- }
7
+ import { sortTableData } from "../logger.js";
134
8
  /**
135
9
  * Detect wildcard characters (* or ?) in a string value and return
136
10
  * a $like filter object for the API. Returns the plain string for exact match.
@@ -270,661 +144,623 @@ export function logResultCount(logger, count, resourceName, hasFilters) {
270
144
  /**
271
145
  * Search process definitions
272
146
  */
273
- export async function searchProcessDefinitions(options) {
274
- const logger = getLogger();
275
- const client = createClient(options.profile);
276
- const tenantId = resolveTenantId(options.profile);
277
- const hasCiFilter = !!(options.iProcessDefinitionId || options.iName);
147
+ export const searchProcessDefinitionsCommand = defineCommand("search", "process-definition", async (ctx, flags, _args) => {
148
+ const { client, logger, tenantId, profile } = ctx;
149
+ const processDefinitionId = flags.id || flags.processDefinitionId || flags.bpmnProcessId;
150
+ const version = ctx.version;
151
+ const hasCiFilter = !!(flags.iid || flags.iname);
278
152
  // Build search criteria description for user feedback
279
153
  const criteria = [];
280
- if (options.processDefinitionId) {
281
- criteria.push(formatCriterion("Process Definition ID", options.processDefinitionId));
154
+ if (processDefinitionId) {
155
+ criteria.push(formatCriterion("Process Definition ID", processDefinitionId));
156
+ }
157
+ if (flags.name) {
158
+ criteria.push(formatCriterion("name", flags.name));
159
+ }
160
+ if (version !== undefined) {
161
+ criteria.push(formatCriterion("version", version));
162
+ }
163
+ if (flags.key) {
164
+ criteria.push(formatCriterion("key", flags.key));
165
+ }
166
+ if (flags.iid) {
167
+ criteria.push(formatCriterion("Process Definition ID", flags.iid, true));
168
+ }
169
+ if (flags.iname) {
170
+ criteria.push(formatCriterion("name", flags.iname, true));
171
+ }
172
+ const filter = {
173
+ filter: {
174
+ tenantId,
175
+ },
176
+ };
177
+ if (processDefinitionId) {
178
+ filter.filter.processDefinitionId = toStringFilter(processDefinitionId);
179
+ }
180
+ if (flags.name) {
181
+ filter.filter.name = toStringFilter(flags.name);
182
+ }
183
+ if (version !== undefined) {
184
+ filter.filter.version = version;
185
+ }
186
+ if (flags.key) {
187
+ filter.filter.processDefinitionKey = flags.key;
188
+ }
189
+ const dr = dryRun({
190
+ command: "search process-definitions",
191
+ method: "POST",
192
+ endpoint: "/process-definitions/search",
193
+ profile,
194
+ body: filter,
195
+ });
196
+ if (dr)
197
+ return dr;
198
+ logSearchCriteria(logger, "Process Definitions", criteria);
199
+ const allItems = await fetchAllPages((f, opts) => client.searchProcessDefinitions(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
200
+ const result = { items: allItems };
201
+ if (result.items?.length) {
202
+ result.items = [...result.items].sort((left, right) => {
203
+ const versionDelta = (Number(right.version) || 0) - (Number(left.version) || 0);
204
+ if (versionDelta !== 0)
205
+ return versionDelta;
206
+ const leftKey = toBigIntSafe(left.processDefinitionKey ?? left.key);
207
+ const rightKey = toBigIntSafe(right.processDefinitionKey ?? right.key);
208
+ if (leftKey === rightKey)
209
+ return 0;
210
+ return rightKey > leftKey ? 1 : -1;
211
+ });
212
+ }
213
+ // Client-side case-insensitive post-filtering
214
+ if (hasCiFilter && result.items) {
215
+ result.items = result.items.filter((pd) => {
216
+ if (flags.iid &&
217
+ !matchesCaseInsensitive(pd.processDefinitionId, flags.iid))
218
+ return false;
219
+ if (flags.iname && !matchesCaseInsensitive(pd.name, flags.iname))
220
+ return false;
221
+ return true;
222
+ });
223
+ }
224
+ if (result.items && result.items.length > 0) {
225
+ let tableData = result.items.map((pd) => ({
226
+ Key: pd.processDefinitionKey || pd.key,
227
+ "Process ID": pd.processDefinitionId,
228
+ Name: pd.name || "-",
229
+ Version: pd.version,
230
+ "Tenant ID": pd.tenantId,
231
+ }));
232
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
233
+ logger.table(tableData);
234
+ logResultCount(logger, result.items.length, "process definition(s)", criteria.length > 0);
282
235
  }
283
- if (options.name) {
284
- criteria.push(formatCriterion("name", options.name));
236
+ else {
237
+ logNoResults(logger, "process definitions", criteria.length > 0);
285
238
  }
286
- if (options.version !== undefined) {
287
- criteria.push(formatCriterion("version", options.version));
239
+ });
240
+ /**
241
+ * Search process instances
242
+ */
243
+ export const searchProcessInstancesCommand = defineCommand("search", "process-instance", async (ctx, flags, _args) => {
244
+ const { client, logger, tenantId, profile } = ctx;
245
+ const processDefinitionId = flags.id || flags.processDefinitionId || flags.bpmnProcessId;
246
+ const version = ctx.version;
247
+ const hasCiFilter = !!flags.iid;
248
+ // Build search criteria description for user feedback
249
+ const criteria = [];
250
+ if (processDefinitionId) {
251
+ criteria.push(formatCriterion("Process Definition ID", processDefinitionId));
288
252
  }
289
- if (options.key) {
290
- criteria.push(formatCriterion("key", options.key));
253
+ if (flags.processDefinitionKey) {
254
+ criteria.push(formatCriterion("Process Definition Key", flags.processDefinitionKey));
291
255
  }
292
- if (options.iProcessDefinitionId) {
293
- criteria.push(formatCriterion("Process Definition ID", options.iProcessDefinitionId, true));
256
+ if (flags.state) {
257
+ criteria.push(formatCriterion("state", flags.state));
294
258
  }
295
- if (options.iName) {
296
- criteria.push(formatCriterion("name", options.iName, true));
259
+ if (version !== undefined) {
260
+ criteria.push(formatCriterion("version", version));
297
261
  }
298
- try {
299
- const filter = {
300
- filter: {
301
- tenantId,
302
- },
303
- };
304
- if (options.processDefinitionId) {
305
- filter.filter.processDefinitionId = toStringFilter(options.processDefinitionId);
306
- }
307
- if (options.name) {
308
- filter.filter.name = toStringFilter(options.name);
309
- }
310
- if (options.version !== undefined) {
311
- filter.filter.version = options.version;
312
- }
313
- if (options.key) {
314
- filter.filter.processDefinitionKey = options.key;
315
- }
316
- if (emitDryRun({
317
- command: "search process-definitions",
318
- method: "POST",
319
- endpoint: "/process-definitions/search",
320
- profile: options.profile,
321
- body: filter,
322
- }))
323
- return;
324
- logSearchCriteria(logger, "Process Definitions", criteria);
325
- const allItems = await fetchAllPages((f, opts) => client.searchProcessDefinitions(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
326
- const result = { items: allItems };
327
- if (result.items?.length) {
328
- result.items = [...result.items].sort((left, right) => {
329
- const versionDelta = (Number(right.version) || 0) - (Number(left.version) || 0);
330
- if (versionDelta !== 0)
331
- return versionDelta;
332
- const leftKey = toBigIntSafe(left.processDefinitionKey ?? left.key);
333
- const rightKey = toBigIntSafe(right.processDefinitionKey ?? right.key);
334
- if (leftKey === rightKey)
335
- return 0;
336
- return rightKey > leftKey ? 1 : -1;
337
- });
338
- }
339
- // Client-side case-insensitive post-filtering
340
- if (hasCiFilter && result.items) {
341
- result.items = result.items.filter((pd) => {
342
- if (options.iProcessDefinitionId &&
343
- !matchesCaseInsensitive(pd.processDefinitionId, options.iProcessDefinitionId))
344
- return false;
345
- if (options.iName && !matchesCaseInsensitive(pd.name, options.iName))
346
- return false;
347
- return true;
348
- });
349
- }
350
- if (result.items && result.items.length > 0) {
351
- let tableData = result.items.map((pd) => ({
352
- Key: pd.processDefinitionKey || pd.key,
353
- "Process ID": pd.processDefinitionId,
354
- Name: pd.name || "-",
355
- Version: pd.version,
356
- "Tenant ID": pd.tenantId,
357
- }));
358
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
359
- logger.table(tableData);
360
- logResultCount(logger, result.items.length, "process definition(s)", criteria.length > 0);
361
- }
362
- else {
363
- logNoResults(logger, "process definitions", criteria.length > 0, options._unknownFlags);
364
- }
365
- return result;
262
+ if (flags.key) {
263
+ criteria.push(formatCriterion("key", flags.key));
366
264
  }
367
- catch (error) {
368
- handleCommandError(logger, "Failed to search process definitions", error);
265
+ if (flags.parentProcessInstanceKey) {
266
+ criteria.push(formatCriterion("Parent Process Instance Key", flags.parentProcessInstanceKey));
369
267
  }
370
- }
371
- /**
372
- * Search process instances
373
- */
374
- export async function searchProcessInstances(options) {
375
- const logger = getLogger();
376
- const client = createClient(options.profile);
377
- const tenantId = resolveTenantId(options.profile);
378
- const hasCiFilter = !!options.iProcessDefinitionId;
379
- // Build search criteria description for user feedback
380
- const criteria = [];
381
- if (options.processDefinitionId) {
382
- criteria.push(formatCriterion("Process Definition ID", options.processDefinitionId));
268
+ if (flags.iid) {
269
+ criteria.push(formatCriterion("Process Definition ID", flags.iid, true));
383
270
  }
384
- if (options.processDefinitionKey) {
385
- criteria.push(formatCriterion("Process Definition Key", options.processDefinitionKey));
271
+ if (ctx.between) {
272
+ const field = ctx.dateField ?? "startDate";
273
+ criteria.push(`'${field}' between "${ctx.between}"`);
386
274
  }
387
- if (options.state) {
388
- criteria.push(formatCriterion("state", options.state));
275
+ const filter = {
276
+ filter: {
277
+ tenantId,
278
+ },
279
+ };
280
+ if (processDefinitionId) {
281
+ filter.filter.processDefinitionId = toStringFilter(processDefinitionId);
389
282
  }
390
- if (options.version !== undefined) {
391
- criteria.push(formatCriterion("version", options.version));
283
+ if (flags.processDefinitionKey) {
284
+ filter.filter.processDefinitionKey = flags.processDefinitionKey;
392
285
  }
393
- if (options.key) {
394
- criteria.push(formatCriterion("key", options.key));
286
+ if (version !== undefined) {
287
+ filter.filter.processDefinitionVersion = version;
395
288
  }
396
- if (options.parentProcessInstanceKey) {
397
- criteria.push(formatCriterion("Parent Process Instance Key", options.parentProcessInstanceKey));
289
+ if (flags.state) {
290
+ filter.filter.state = flags.state;
398
291
  }
399
- if (options.iProcessDefinitionId) {
400
- criteria.push(formatCriterion("Process Definition ID", options.iProcessDefinitionId, true));
292
+ if (flags.key) {
293
+ filter.filter.processInstanceKey = flags.key;
401
294
  }
402
- if (options.between) {
403
- const field = options.dateField ?? "startDate";
404
- criteria.push(`'${field}' between "${options.between}"`);
295
+ if (flags.parentProcessInstanceKey) {
296
+ filter.filter.parentProcessInstanceKey = flags.parentProcessInstanceKey;
405
297
  }
406
- try {
407
- const filter = {
408
- filter: {
409
- tenantId,
410
- },
411
- };
412
- if (options.processDefinitionId) {
413
- filter.filter.processDefinitionId = toStringFilter(options.processDefinitionId);
414
- }
415
- if (options.processDefinitionKey) {
416
- filter.filter.processDefinitionKey = options.processDefinitionKey;
417
- }
418
- if (options.version !== undefined) {
419
- filter.filter.processDefinitionVersion = options.version;
420
- }
421
- if (options.state) {
422
- filter.filter.state = options.state;
423
- }
424
- if (options.key) {
425
- filter.filter.processInstanceKey = options.key;
426
- }
427
- if (options.parentProcessInstanceKey) {
428
- filter.filter.parentProcessInstanceKey = options.parentProcessInstanceKey;
429
- }
430
- if (options.between) {
431
- const parsed = parseBetween(options.between);
432
- if (parsed) {
433
- const field = options.dateField ?? "startDate";
434
- filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
435
- }
436
- else {
437
- logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
438
- process.exit(1);
439
- }
440
- }
441
- if (emitDryRun({
442
- command: "search process-instances",
443
- method: "POST",
444
- endpoint: "/process-instances/search",
445
- profile: options.profile,
446
- body: filter,
447
- }))
448
- return;
449
- logSearchCriteria(logger, "Process Instances", criteria);
450
- const allItems = await fetchAllPages((f, opts) => client.searchProcessInstances(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
451
- const result = { items: allItems };
452
- if (hasCiFilter && result.items) {
453
- result.items = result.items.filter((pi) => {
454
- if (options.iProcessDefinitionId &&
455
- !matchesCaseInsensitive(pi.processDefinitionId, options.iProcessDefinitionId))
456
- return false;
457
- return true;
458
- });
459
- }
460
- if (result.items && result.items.length > 0) {
461
- let tableData = result.items.map((pi) => ({
462
- Key: pi.processInstanceKey || pi.key,
463
- "Process ID": pi.processDefinitionId,
464
- State: pi.state,
465
- Version: pi.processDefinitionVersion || pi.version,
466
- "Start Date": pi.startDate || "-",
467
- "Tenant ID": pi.tenantId,
468
- }));
469
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
470
- logger.table(tableData);
471
- logResultCount(logger, result.items.length, "process instance(s)", criteria.length > 0);
298
+ if (ctx.between) {
299
+ const parsed = parseBetween(ctx.between);
300
+ if (parsed) {
301
+ const field = ctx.dateField ?? "startDate";
302
+ filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
472
303
  }
473
304
  else {
474
- logNoResults(logger, "process instances", criteria.length > 0, options._unknownFlags);
475
- }
476
- return result;
305
+ logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
306
+ process.exit(1);
307
+ }
308
+ }
309
+ const dr = dryRun({
310
+ command: "search process-instances",
311
+ method: "POST",
312
+ endpoint: "/process-instances/search",
313
+ profile,
314
+ body: filter,
315
+ });
316
+ if (dr)
317
+ return dr;
318
+ logSearchCriteria(logger, "Process Instances", criteria);
319
+ const allItems = await fetchAllPages((f, opts) => client.searchProcessInstances(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
320
+ const result = { items: allItems };
321
+ if (hasCiFilter && result.items) {
322
+ result.items = result.items.filter((pi) => {
323
+ if (flags.iid &&
324
+ !matchesCaseInsensitive(pi.processDefinitionId, flags.iid))
325
+ return false;
326
+ return true;
327
+ });
328
+ }
329
+ if (result.items && result.items.length > 0) {
330
+ let tableData = result.items.map((pi) => ({
331
+ Key: pi.processInstanceKey || pi.key,
332
+ "Process ID": pi.processDefinitionId,
333
+ State: pi.state,
334
+ Version: pi.processDefinitionVersion || pi.version,
335
+ "Start Date": pi.startDate || "-",
336
+ "Tenant ID": pi.tenantId,
337
+ }));
338
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
339
+ logger.table(tableData);
340
+ logResultCount(logger, result.items.length, "process instance(s)", criteria.length > 0);
477
341
  }
478
- catch (error) {
479
- handleCommandError(logger, "Failed to search process instances", error);
342
+ else {
343
+ logNoResults(logger, "process instances", criteria.length > 0);
480
344
  }
481
- }
345
+ });
482
346
  /**
483
347
  * Search user tasks
484
348
  */
485
- export async function searchUserTasks(options) {
486
- const logger = getLogger();
487
- const client = createClient(options.profile);
488
- const tenantId = resolveTenantId(options.profile);
489
- const hasCiFilter = !!options.iAssignee;
349
+ export const searchUserTasksCommand = defineCommand("search", "user-task", async (ctx, flags, _args) => {
350
+ const { client, logger, tenantId, profile } = ctx;
351
+ const hasCiFilter = !!flags.iassignee;
490
352
  // Build search criteria description for user feedback
491
353
  const criteria = [];
492
- if (options.state) {
493
- criteria.push(formatCriterion("state", options.state));
354
+ if (flags.state) {
355
+ criteria.push(formatCriterion("state", flags.state));
494
356
  }
495
- if (options.assignee) {
496
- criteria.push(formatCriterion("assignee", options.assignee));
357
+ if (flags.assignee) {
358
+ criteria.push(formatCriterion("assignee", flags.assignee));
497
359
  }
498
- if (options.processInstanceKey) {
499
- criteria.push(formatCriterion("Process Instance Key", options.processInstanceKey));
360
+ if (flags.processInstanceKey) {
361
+ criteria.push(formatCriterion("Process Instance Key", flags.processInstanceKey));
500
362
  }
501
- if (options.processDefinitionKey) {
502
- criteria.push(formatCriterion("Process Definition Key", options.processDefinitionKey));
363
+ if (flags.processDefinitionKey) {
364
+ criteria.push(formatCriterion("Process Definition Key", flags.processDefinitionKey));
503
365
  }
504
- if (options.elementId) {
505
- criteria.push(formatCriterion("Element ID", options.elementId));
366
+ if (flags.elementId) {
367
+ criteria.push(formatCriterion("Element ID", flags.elementId));
506
368
  }
507
- if (options.iAssignee) {
508
- criteria.push(formatCriterion("assignee", options.iAssignee, true));
369
+ if (flags.iassignee) {
370
+ criteria.push(formatCriterion("assignee", flags.iassignee, true));
509
371
  }
510
- if (options.between) {
511
- const field = options.dateField ?? "creationDate";
512
- criteria.push(`'${field}' between "${options.between}"`);
372
+ if (ctx.between) {
373
+ const field = ctx.dateField ?? "creationDate";
374
+ criteria.push(`'${field}' between "${ctx.between}"`);
513
375
  }
514
- try {
515
- const filter = {
516
- filter: {
517
- tenantId,
518
- },
519
- };
520
- if (options.state) {
521
- filter.filter.state = options.state;
522
- }
523
- if (options.assignee) {
524
- filter.filter.assignee = toStringFilter(options.assignee);
525
- }
526
- if (options.processInstanceKey) {
527
- filter.filter.processInstanceKey = options.processInstanceKey;
528
- }
529
- if (options.processDefinitionKey) {
530
- filter.filter.processDefinitionKey = options.processDefinitionKey;
531
- }
532
- if (options.elementId) {
533
- filter.filter.elementId = options.elementId;
534
- }
535
- if (options.between) {
536
- const parsed = parseBetween(options.between);
537
- if (parsed) {
538
- const field = options.dateField ?? "creationDate";
539
- filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
540
- }
541
- else {
542
- logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
543
- process.exit(1);
544
- }
545
- }
546
- if (emitDryRun({
547
- command: "search user-tasks",
548
- method: "POST",
549
- endpoint: "/user-tasks/search",
550
- profile: options.profile,
551
- body: filter,
552
- }))
553
- return;
554
- logSearchCriteria(logger, "User Tasks", criteria);
555
- const allItems = await fetchAllPages((f, opts) => client.searchUserTasks(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
556
- const result = { items: allItems };
557
- if (hasCiFilter && result.items) {
558
- result.items = result.items.filter((task) => {
559
- if (options.iAssignee &&
560
- !matchesCaseInsensitive(task.assignee, options.iAssignee))
561
- return false;
562
- return true;
563
- });
564
- }
565
- if (result.items && result.items.length > 0) {
566
- let tableData = result.items.map((task) => ({
567
- Key: task.userTaskKey || task.key,
568
- Name: task.name || task.elementId,
569
- State: task.state,
570
- Assignee: task.assignee || "(unassigned)",
571
- Created: task.creationDate || "-",
572
- "Process Instance": task.processInstanceKey,
573
- "Tenant ID": task.tenantId,
574
- }));
575
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
576
- logger.table(tableData);
577
- logResultCount(logger, result.items.length, "user task(s)", criteria.length > 0);
376
+ const filter = {
377
+ filter: {
378
+ tenantId,
379
+ },
380
+ };
381
+ if (flags.state) {
382
+ filter.filter.state = flags.state;
383
+ }
384
+ if (flags.assignee) {
385
+ filter.filter.assignee = toStringFilter(flags.assignee);
386
+ }
387
+ if (flags.processInstanceKey) {
388
+ filter.filter.processInstanceKey = flags.processInstanceKey;
389
+ }
390
+ if (flags.processDefinitionKey) {
391
+ filter.filter.processDefinitionKey = flags.processDefinitionKey;
392
+ }
393
+ if (flags.elementId) {
394
+ filter.filter.elementId = flags.elementId;
395
+ }
396
+ if (ctx.between) {
397
+ const parsed = parseBetween(ctx.between);
398
+ if (parsed) {
399
+ const field = ctx.dateField ?? "creationDate";
400
+ filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
578
401
  }
579
402
  else {
580
- logNoResults(logger, "user tasks", criteria.length > 0, options._unknownFlags);
581
- }
582
- return result;
403
+ logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
404
+ process.exit(1);
405
+ }
406
+ }
407
+ const dr = dryRun({
408
+ command: "search user-tasks",
409
+ method: "POST",
410
+ endpoint: "/user-tasks/search",
411
+ profile,
412
+ body: filter,
413
+ });
414
+ if (dr)
415
+ return dr;
416
+ logSearchCriteria(logger, "User Tasks", criteria);
417
+ const allItems = await fetchAllPages((f, opts) => client.searchUserTasks(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
418
+ const result = { items: allItems };
419
+ if (hasCiFilter && result.items) {
420
+ result.items = result.items.filter((task) => {
421
+ if (flags.iassignee &&
422
+ !matchesCaseInsensitive(task.assignee, flags.iassignee))
423
+ return false;
424
+ return true;
425
+ });
426
+ }
427
+ if (result.items && result.items.length > 0) {
428
+ let tableData = result.items.map((task) => ({
429
+ Key: task.userTaskKey || task.key,
430
+ Name: task.name || task.elementId,
431
+ State: task.state,
432
+ Assignee: task.assignee || "(unassigned)",
433
+ Created: task.creationDate || "-",
434
+ "Process Instance": task.processInstanceKey,
435
+ "Tenant ID": task.tenantId,
436
+ }));
437
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
438
+ logger.table(tableData);
439
+ logResultCount(logger, result.items.length, "user task(s)", criteria.length > 0);
583
440
  }
584
- catch (error) {
585
- handleCommandError(logger, "Failed to search user tasks", error);
441
+ else {
442
+ logNoResults(logger, "user tasks", criteria.length > 0);
586
443
  }
587
- }
444
+ });
588
445
  /**
589
446
  * Search incidents
590
447
  */
591
- export async function searchIncidents(options) {
592
- const logger = getLogger();
593
- const client = createClient(options.profile);
594
- const tenantId = resolveTenantId(options.profile);
448
+ export const searchIncidentsCommand = defineCommand("search", "incident", async (ctx, flags, _args) => {
449
+ const { client, logger, tenantId, profile } = ctx;
450
+ const processDefinitionId = flags.id || flags.processDefinitionId || flags.bpmnProcessId;
595
451
  // The incident API does not support a $like filter for errorMessage; fall back to client-side filtering for wildcard patterns
596
- const errorMessageHasWildcard = !!(options.errorMessage && hasUnescapedWildcard(options.errorMessage));
597
- const hasCiFilter = !!(options.iErrorMessage ||
598
- options.iProcessDefinitionId ||
452
+ const errorMessageHasWildcard = !!(flags.errorMessage && hasUnescapedWildcard(flags.errorMessage));
453
+ const hasCiFilter = !!(flags.ierrorMessage ||
454
+ flags.iid ||
599
455
  errorMessageHasWildcard);
600
456
  // Build search criteria description for user feedback
601
457
  const criteria = [];
602
- if (options.state) {
603
- criteria.push(formatCriterion("state", options.state));
458
+ if (flags.state) {
459
+ criteria.push(formatCriterion("state", flags.state));
604
460
  }
605
- if (options.processInstanceKey) {
606
- criteria.push(formatCriterion("Process Instance Key", options.processInstanceKey));
461
+ if (flags.processInstanceKey) {
462
+ criteria.push(formatCriterion("Process Instance Key", flags.processInstanceKey));
607
463
  }
608
- if (options.processDefinitionKey) {
609
- criteria.push(formatCriterion("Process Definition Key", options.processDefinitionKey));
464
+ if (flags.processDefinitionKey) {
465
+ criteria.push(formatCriterion("Process Definition Key", flags.processDefinitionKey));
610
466
  }
611
- if (options.errorType) {
612
- criteria.push(formatCriterion("Error Type", options.errorType));
467
+ if (flags.errorType) {
468
+ criteria.push(formatCriterion("Error Type", flags.errorType));
613
469
  }
614
- if (options.errorMessage) {
615
- criteria.push(formatCriterion("Error Message", options.errorMessage));
470
+ if (flags.errorMessage) {
471
+ criteria.push(formatCriterion("Error Message", flags.errorMessage));
616
472
  }
617
- if (options.processDefinitionId) {
618
- criteria.push(formatCriterion("Process Definition ID", options.processDefinitionId));
473
+ if (processDefinitionId) {
474
+ criteria.push(formatCriterion("Process Definition ID", processDefinitionId));
619
475
  }
620
- if (options.iErrorMessage) {
621
- criteria.push(formatCriterion("Error Message", options.iErrorMessage, true));
476
+ if (flags.ierrorMessage) {
477
+ criteria.push(formatCriterion("Error Message", flags.ierrorMessage, true));
622
478
  }
623
- if (options.iProcessDefinitionId) {
624
- criteria.push(formatCriterion("Process Definition ID", options.iProcessDefinitionId, true));
479
+ if (flags.iid) {
480
+ criteria.push(formatCriterion("Process Definition ID", flags.iid, true));
625
481
  }
626
- if (options.between) {
627
- criteria.push(`'creationTime' between "${options.between}"`);
482
+ if (ctx.between) {
483
+ criteria.push(`'creationTime' between "${ctx.between}"`);
628
484
  }
629
- try {
630
- const filter = {
631
- filter: {
632
- tenantId,
633
- },
634
- };
635
- if (options.state) {
636
- filter.filter.state = options.state;
637
- }
638
- if (options.processInstanceKey) {
639
- filter.filter.processInstanceKey = options.processInstanceKey;
640
- }
641
- if (options.processDefinitionKey) {
642
- filter.filter.processDefinitionKey = options.processDefinitionKey;
643
- }
644
- if (options.errorType) {
645
- filter.filter.errorType = options.errorType;
646
- }
647
- if (options.errorMessage && !errorMessageHasWildcard) {
648
- filter.filter.errorMessage = options.errorMessage;
649
- }
650
- if (options.processDefinitionId) {
651
- filter.filter.processDefinitionId = toStringFilter(options.processDefinitionId);
652
- }
653
- if (options.between) {
654
- const parsed = parseBetween(options.between);
655
- if (parsed) {
656
- filter.filter.creationTime = buildDateFilter(parsed.from, parsed.to);
657
- }
658
- else {
659
- logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
660
- process.exit(1);
661
- }
662
- }
663
- if (emitDryRun({
664
- command: "search incidents",
665
- method: "POST",
666
- endpoint: "/incidents/search",
667
- profile: options.profile,
668
- body: filter,
669
- }))
670
- return;
671
- logSearchCriteria(logger, "Incidents", criteria);
672
- const allItems = await fetchAllPages((f, opts) => client.searchIncidents(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
673
- const result = { items: allItems };
674
- if (hasCiFilter && result.items) {
675
- result.items = result.items.filter((incident) => {
676
- if (options.iErrorMessage &&
677
- !matchesCaseInsensitive(incident.errorMessage, options.iErrorMessage))
678
- return false;
679
- if (options.iProcessDefinitionId &&
680
- !matchesCaseInsensitive(incident.processDefinitionId, options.iProcessDefinitionId))
681
- return false;
682
- if (errorMessageHasWildcard &&
683
- options.errorMessage &&
684
- !matchesCaseSensitive(incident.errorMessage, options.errorMessage))
685
- return false;
686
- return true;
687
- });
688
- }
689
- if (result.items && result.items.length > 0) {
690
- let tableData = result.items.map((incident) => ({
691
- Key: incident.incidentKey || incident.key,
692
- Type: incident.errorType,
693
- Message: typeof incident.errorMessage === "string"
694
- ? incident.errorMessage.substring(0, 50)
695
- : "",
696
- State: incident.state,
697
- Created: incident.creationTime || "-",
698
- "Process Instance": incident.processInstanceKey,
699
- "Tenant ID": incident.tenantId,
700
- }));
701
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
702
- logger.table(tableData);
703
- logResultCount(logger, result.items.length, "incident(s)", criteria.length > 0);
485
+ const filter = {
486
+ filter: {
487
+ tenantId,
488
+ },
489
+ };
490
+ if (flags.state) {
491
+ filter.filter.state = flags.state;
492
+ }
493
+ if (flags.processInstanceKey) {
494
+ filter.filter.processInstanceKey = flags.processInstanceKey;
495
+ }
496
+ if (flags.processDefinitionKey) {
497
+ filter.filter.processDefinitionKey = flags.processDefinitionKey;
498
+ }
499
+ if (flags.errorType) {
500
+ filter.filter.errorType = flags.errorType;
501
+ }
502
+ if (flags.errorMessage && !errorMessageHasWildcard) {
503
+ filter.filter.errorMessage = flags.errorMessage;
504
+ }
505
+ if (processDefinitionId) {
506
+ filter.filter.processDefinitionId = toStringFilter(processDefinitionId);
507
+ }
508
+ if (ctx.between) {
509
+ const parsed = parseBetween(ctx.between);
510
+ if (parsed) {
511
+ filter.filter.creationTime = buildDateFilter(parsed.from, parsed.to);
704
512
  }
705
513
  else {
706
- logNoResults(logger, "incidents", criteria.length > 0, options._unknownFlags);
707
- }
708
- return result;
514
+ logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
515
+ process.exit(1);
516
+ }
517
+ }
518
+ const dr = dryRun({
519
+ command: "search incidents",
520
+ method: "POST",
521
+ endpoint: "/incidents/search",
522
+ profile,
523
+ body: filter,
524
+ });
525
+ if (dr)
526
+ return dr;
527
+ logSearchCriteria(logger, "Incidents", criteria);
528
+ const allItems = await fetchAllPages((f, opts) => client.searchIncidents(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
529
+ const result = { items: allItems };
530
+ if (hasCiFilter && result.items) {
531
+ result.items = result.items.filter((incident) => {
532
+ if (flags.ierrorMessage &&
533
+ !matchesCaseInsensitive(incident.errorMessage, flags.ierrorMessage))
534
+ return false;
535
+ if (flags.iid &&
536
+ !matchesCaseInsensitive(incident.processDefinitionId, flags.iid))
537
+ return false;
538
+ if (errorMessageHasWildcard &&
539
+ flags.errorMessage &&
540
+ !matchesCaseSensitive(incident.errorMessage, flags.errorMessage))
541
+ return false;
542
+ return true;
543
+ });
544
+ }
545
+ if (result.items && result.items.length > 0) {
546
+ let tableData = result.items.map((incident) => ({
547
+ Key: incident.incidentKey || incident.key,
548
+ Type: incident.errorType,
549
+ Message: typeof incident.errorMessage === "string"
550
+ ? incident.errorMessage.substring(0, 50)
551
+ : "",
552
+ State: incident.state,
553
+ Created: incident.creationTime || "-",
554
+ "Process Instance": incident.processInstanceKey,
555
+ "Tenant ID": incident.tenantId,
556
+ }));
557
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
558
+ logger.table(tableData);
559
+ logResultCount(logger, result.items.length, "incident(s)", criteria.length > 0);
709
560
  }
710
- catch (error) {
711
- handleCommandError(logger, "Failed to search incidents", error);
561
+ else {
562
+ logNoResults(logger, "incidents", criteria.length > 0);
712
563
  }
713
- }
564
+ });
714
565
  /**
715
566
  * Search jobs
716
567
  */
717
- export async function searchJobs(options) {
718
- const logger = getLogger();
719
- const client = createClient(options.profile);
720
- const tenantId = resolveTenantId(options.profile);
721
- const hasCiFilter = !!options.iType;
568
+ export const searchJobsCommand = defineCommand("search", "jobs", async (ctx, flags, _args) => {
569
+ const { client, logger, tenantId, profile } = ctx;
570
+ const hasCiFilter = !!flags.itype;
722
571
  // Build search criteria description for user feedback
723
572
  const criteria = [];
724
- if (options.state) {
725
- criteria.push(formatCriterion("state", options.state));
573
+ if (flags.state) {
574
+ criteria.push(formatCriterion("state", flags.state));
726
575
  }
727
- if (options.type) {
728
- criteria.push(formatCriterion("type", options.type));
576
+ if (flags.type) {
577
+ criteria.push(formatCriterion("type", flags.type));
729
578
  }
730
- if (options.processInstanceKey) {
731
- criteria.push(formatCriterion("Process Instance Key", options.processInstanceKey));
579
+ if (flags.processInstanceKey) {
580
+ criteria.push(formatCriterion("Process Instance Key", flags.processInstanceKey));
732
581
  }
733
- if (options.processDefinitionKey) {
734
- criteria.push(formatCriterion("Process Definition Key", options.processDefinitionKey));
582
+ if (flags.processDefinitionKey) {
583
+ criteria.push(formatCriterion("Process Definition Key", flags.processDefinitionKey));
735
584
  }
736
- if (options.iType) {
737
- criteria.push(formatCriterion("type", options.iType, true));
585
+ if (flags.itype) {
586
+ criteria.push(formatCriterion("type", flags.itype, true));
738
587
  }
739
- if (options.between) {
740
- const field = options.dateField ?? "creationTime";
741
- criteria.push(`'${field}' between "${options.between}"`);
588
+ if (ctx.between) {
589
+ const field = ctx.dateField ?? "creationTime";
590
+ criteria.push(`'${field}' between "${ctx.between}"`);
742
591
  }
743
- try {
744
- const filter = {
745
- filter: {
746
- tenantId,
747
- },
748
- };
749
- if (options.state) {
750
- filter.filter.state = options.state;
751
- }
752
- if (options.type) {
753
- filter.filter.type = toStringFilter(options.type);
754
- }
755
- if (options.processInstanceKey) {
756
- filter.filter.processInstanceKey = options.processInstanceKey;
757
- }
758
- if (options.processDefinitionKey) {
759
- filter.filter.processDefinitionKey = options.processDefinitionKey;
760
- }
761
- if (options.between) {
762
- const parsed = parseBetween(options.between);
763
- if (parsed) {
764
- const field = options.dateField ?? "creationTime";
765
- filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
766
- }
767
- else {
768
- logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
769
- process.exit(1);
770
- }
771
- }
772
- if (emitDryRun({
773
- command: "search jobs",
774
- method: "POST",
775
- endpoint: "/jobs/search",
776
- profile: options.profile,
777
- body: filter,
778
- }))
779
- return;
780
- logSearchCriteria(logger, "Jobs", criteria);
781
- const allItems = await fetchAllPages((f, opts) => client.searchJobs(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
782
- const result = { items: allItems };
783
- if (hasCiFilter && result.items) {
784
- result.items = result.items.filter((job) => {
785
- if (options.iType && !matchesCaseInsensitive(job.type, options.iType))
786
- return false;
787
- return true;
788
- });
789
- }
790
- if (result.items && result.items.length > 0) {
791
- let tableData = result.items.map((job) => ({
792
- Key: job.jobKey || job.key,
793
- Type: job.type,
794
- State: job.state,
795
- Retries: job.retries,
796
- Created: job.creationTime || "-",
797
- "Process Instance": job.processInstanceKey,
798
- "Tenant ID": job.tenantId,
799
- }));
800
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
801
- logger.table(tableData);
802
- logResultCount(logger, result.items.length, "job(s)", criteria.length > 0);
592
+ const filter = {
593
+ filter: {
594
+ tenantId,
595
+ },
596
+ };
597
+ if (flags.state) {
598
+ filter.filter.state = flags.state;
599
+ }
600
+ if (flags.type) {
601
+ filter.filter.type = toStringFilter(flags.type);
602
+ }
603
+ if (flags.processInstanceKey) {
604
+ filter.filter.processInstanceKey = flags.processInstanceKey;
605
+ }
606
+ if (flags.processDefinitionKey) {
607
+ filter.filter.processDefinitionKey = flags.processDefinitionKey;
608
+ }
609
+ if (ctx.between) {
610
+ const parsed = parseBetween(ctx.between);
611
+ if (parsed) {
612
+ const field = ctx.dateField ?? "creationTime";
613
+ filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
803
614
  }
804
615
  else {
805
- logNoResults(logger, "jobs", criteria.length > 0, options._unknownFlags);
806
- }
807
- return result;
616
+ logger.error("Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31, ISO 8601 datetimes, or open-ended: ..2024-12-31 or 2024-01-01..)");
617
+ process.exit(1);
618
+ }
619
+ }
620
+ const dr = dryRun({
621
+ command: "search jobs",
622
+ method: "POST",
623
+ endpoint: "/jobs/search",
624
+ profile,
625
+ body: filter,
626
+ });
627
+ if (dr)
628
+ return dr;
629
+ logSearchCriteria(logger, "Jobs", criteria);
630
+ const allItems = await fetchAllPages((f, opts) => client.searchJobs(f, opts), filter, ...(hasCiFilter ? [CI_PAGE_SIZE] : []));
631
+ const result = { items: allItems };
632
+ if (hasCiFilter && result.items) {
633
+ result.items = result.items.filter((job) => {
634
+ if (flags.itype && !matchesCaseInsensitive(job.type, flags.itype))
635
+ return false;
636
+ return true;
637
+ });
638
+ }
639
+ if (result.items && result.items.length > 0) {
640
+ let tableData = result.items.map((job) => ({
641
+ Key: job.jobKey || job.key,
642
+ Type: job.type,
643
+ State: job.state,
644
+ Retries: job.retries,
645
+ Created: job.creationTime || "-",
646
+ "Process Instance": job.processInstanceKey,
647
+ "Tenant ID": job.tenantId,
648
+ }));
649
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
650
+ logger.table(tableData);
651
+ logResultCount(logger, result.items.length, "job(s)", criteria.length > 0);
808
652
  }
809
- catch (error) {
810
- handleCommandError(logger, "Failed to search jobs", error);
653
+ else {
654
+ logNoResults(logger, "jobs", criteria.length > 0);
811
655
  }
812
- }
656
+ });
813
657
  /**
814
658
  * Search variables
815
659
  */
816
- export async function searchVariables(options) {
817
- const logger = getLogger();
818
- const client = createClient(options.profile);
819
- const tenantId = resolveTenantId(options.profile);
820
- const hasCiFilter = !!(options.iName || options.iValue);
660
+ export const searchVariablesCommand = defineCommand("search", "variable", async (ctx, flags, _args) => {
661
+ const { client, logger, tenantId, profile } = ctx;
662
+ const hasCiFilter = !!(flags.iname || flags.ivalue);
821
663
  // Build search criteria description for user feedback
822
664
  const criteria = [];
823
- if (options.name) {
824
- criteria.push(formatCriterion("name", options.name));
665
+ if (flags.name) {
666
+ criteria.push(formatCriterion("name", flags.name));
825
667
  }
826
- if (options.value) {
827
- criteria.push(formatCriterion("value", options.value));
668
+ if (flags.value) {
669
+ criteria.push(formatCriterion("value", flags.value));
828
670
  }
829
- if (options.processInstanceKey) {
830
- criteria.push(formatCriterion("Process Instance Key", options.processInstanceKey));
671
+ if (flags.processInstanceKey) {
672
+ criteria.push(formatCriterion("Process Instance Key", flags.processInstanceKey));
831
673
  }
832
- if (options.scopeKey) {
833
- criteria.push(formatCriterion("Scope Key", options.scopeKey));
674
+ if (flags.scopeKey) {
675
+ criteria.push(formatCriterion("Scope Key", flags.scopeKey));
834
676
  }
835
- if (options.iName) {
836
- criteria.push(formatCriterion("name", options.iName, true));
677
+ if (flags.iname) {
678
+ criteria.push(formatCriterion("name", flags.iname, true));
837
679
  }
838
- if (options.iValue) {
839
- criteria.push(formatCriterion("value", options.iValue, true));
680
+ if (flags.ivalue) {
681
+ criteria.push(formatCriterion("value", flags.ivalue, true));
840
682
  }
841
- if (options.fullValue) {
683
+ if (flags.fullValue) {
842
684
  criteria.push(formatCriterion("fullValue", true));
843
685
  }
844
- try {
845
- const filter = {
846
- filter: {
847
- tenantId,
848
- },
849
- };
850
- if (options.name) {
851
- filter.filter.name = toStringFilter(options.name);
852
- }
853
- if (options.value) {
854
- filter.filter.value = toStringFilter(options.value);
855
- }
856
- if (options.processInstanceKey) {
857
- filter.filter.processInstanceKey = options.processInstanceKey;
858
- }
859
- if (options.scopeKey) {
860
- filter.filter.scopeKey = options.scopeKey;
861
- }
862
- // By default, truncate values unless --fullValue is specified
863
- const truncateValues = !options.fullValue;
864
- if (emitDryRun({
865
- command: "search variables",
866
- method: "POST",
867
- endpoint: "/variables/search",
868
- profile: options.profile,
869
- body: { ...filter, truncateValues },
870
- }))
871
- return;
872
- logSearchCriteria(logger, "Variables", criteria);
873
- const allItems = await fetchAllPages((f, opts) => client.searchVariables({ ...f, truncateValues }, opts), filter, hasCiFilter ? CI_PAGE_SIZE : DEFAULT_PAGE_SIZE, options.limit);
874
- const result = { items: allItems };
875
- if (hasCiFilter && result.items) {
876
- result.items = result.items.filter((variable) => {
877
- if (options.iName &&
878
- !matchesCaseInsensitive(variable.name, options.iName))
879
- return false;
880
- if (options.iValue) {
881
- // Variable values come JSON-encoded from the API (e.g., '"PendingReview"').
882
- // Unwrap the JSON string for comparison so users can match the actual value.
883
- let rawValue = typeof variable.value === "string"
884
- ? variable.value
885
- : String(variable.value ?? "");
886
- try {
887
- const parsed = JSON.parse(rawValue);
888
- if (typeof parsed === "string")
889
- rawValue = parsed;
890
- }
891
- catch {
892
- /* keep original value */
893
- }
894
- if (!matchesCaseInsensitive(rawValue, options.iValue))
895
- return false;
686
+ const filter = {
687
+ filter: {
688
+ tenantId,
689
+ },
690
+ };
691
+ if (flags.name) {
692
+ filter.filter.name = toStringFilter(flags.name);
693
+ }
694
+ if (flags.value) {
695
+ filter.filter.value = toStringFilter(flags.value);
696
+ }
697
+ if (flags.processInstanceKey) {
698
+ filter.filter.processInstanceKey = flags.processInstanceKey;
699
+ }
700
+ if (flags.scopeKey) {
701
+ filter.filter.scopeKey = flags.scopeKey;
702
+ }
703
+ // By default, truncate values unless --fullValue is specified
704
+ const truncateValues = !flags.fullValue;
705
+ const dr = dryRun({
706
+ command: "search variables",
707
+ method: "POST",
708
+ endpoint: "/variables/search",
709
+ profile,
710
+ body: { ...filter, truncateValues },
711
+ });
712
+ if (dr)
713
+ return dr;
714
+ logSearchCriteria(logger, "Variables", criteria);
715
+ const allItems = await fetchAllPages((f, opts) => client.searchVariables({ ...f, truncateValues }, opts), filter, hasCiFilter ? CI_PAGE_SIZE : DEFAULT_PAGE_SIZE, ctx.limit);
716
+ const result = { items: allItems };
717
+ if (hasCiFilter && result.items) {
718
+ result.items = result.items.filter((variable) => {
719
+ if (flags.iname && !matchesCaseInsensitive(variable.name, flags.iname))
720
+ return false;
721
+ if (flags.ivalue) {
722
+ // Variable values come JSON-encoded from the API (e.g., '"PendingReview"').
723
+ // Unwrap the JSON string for comparison so users can match the actual value.
724
+ let rawValue = typeof variable.value === "string"
725
+ ? variable.value
726
+ : String(variable.value ?? "");
727
+ try {
728
+ const parsed = JSON.parse(rawValue);
729
+ if (typeof parsed === "string")
730
+ rawValue = parsed;
896
731
  }
897
- return true;
898
- });
899
- }
900
- if (result.items && result.items.length > 0) {
901
- let tableData = result.items.map((variable) => {
902
- const row = {
903
- Name: variable.name,
904
- Value: variable.value || "",
905
- "Process Instance": variable.processInstanceKey,
906
- "Scope Key": variable.scopeKey,
907
- "Tenant ID": variable.tenantId,
908
- };
909
- if (variable.isTruncated) {
910
- row.Truncated = "✓";
732
+ catch {
733
+ /* keep original value */
911
734
  }
912
- return row;
913
- });
914
- tableData = sortTableData(tableData, options.sortBy, logger, options.sortOrder);
915
- logger.table(tableData);
916
- logResultCount(logger, result.items.length, "variable(s)", criteria.length > 0);
917
- if (!options.fullValue && result.items.some((v) => v.isTruncated)) {
918
- logger.info("Some values are truncated. Use --fullValue to see full values.");
735
+ if (!matchesCaseInsensitive(rawValue, flags.ivalue))
736
+ return false;
919
737
  }
738
+ return true;
739
+ });
740
+ }
741
+ if (result.items && result.items.length > 0) {
742
+ let tableData = result.items.map((variable) => {
743
+ const row = {
744
+ Name: variable.name,
745
+ Value: variable.value || "",
746
+ "Process Instance": variable.processInstanceKey,
747
+ "Scope Key": variable.scopeKey,
748
+ "Tenant ID": variable.tenantId,
749
+ };
750
+ if (variable.isTruncated) {
751
+ row.Truncated = "✓";
752
+ }
753
+ return row;
754
+ });
755
+ tableData = sortTableData(tableData, ctx.sortBy, logger, ctx.sortOrder);
756
+ logger.table(tableData);
757
+ logResultCount(logger, result.items.length, "variable(s)", criteria.length > 0);
758
+ if (!flags.fullValue && result.items.some((v) => v.isTruncated)) {
759
+ logger.info("Some values are truncated. Use --fullValue to see full values.");
920
760
  }
921
- else {
922
- logNoResults(logger, "variables", criteria.length > 0, options._unknownFlags);
923
- }
924
- return result;
925
761
  }
926
- catch (error) {
927
- handleCommandError(logger, "Failed to search variables", error);
762
+ else {
763
+ logNoResults(logger, "variables", criteria.length > 0);
928
764
  }
929
- }
765
+ });
930
766
  //# sourceMappingURL=search.js.map