@bpmnkit/core 1.2.0 → 1.3.0

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 (50) hide show
  1. package/README.md +26 -0
  2. package/dist/bpmn/bpmn-builder.d.ts +8 -0
  3. package/dist/bpmn/bpmn-builder.js +6 -2
  4. package/dist/bpmn/compact.d.ts +33 -5
  5. package/dist/bpmn/compact.js +138 -30
  6. package/dist/bpmn/connector-line.d.ts +46 -0
  7. package/dist/bpmn/connector-line.js +135 -0
  8. package/dist/bpmn/optimize/patterns.js +1 -3
  9. package/dist/bpmn/process-delta.d.ts +3 -0
  10. package/dist/bpmn/process-delta.js +23 -0
  11. package/dist/bpmn/process-text-writer.d.ts +12 -2
  12. package/dist/bpmn/process-text-writer.js +10 -1
  13. package/dist/bpmn/process-text.d.ts +26 -1
  14. package/dist/bpmn/process-text.js +329 -16
  15. package/dist/bpmn/rest-connector.d.ts +6 -0
  16. package/dist/bpmn/rest-connector.js +6 -0
  17. package/dist/bpmn/secrets.d.ts +15 -0
  18. package/dist/bpmn/secrets.js +59 -0
  19. package/dist/bpmn/utils.js +4 -0
  20. package/dist/bpmn/zeebe-extensions.d.ts +10 -0
  21. package/dist/bpmn/zeebe-extensions.js +7 -0
  22. package/dist/connectors/aliases.d.ts +21 -0
  23. package/dist/connectors/aliases.js +272 -0
  24. package/dist/connectors/api.d.ts +118 -0
  25. package/dist/connectors/api.js +280 -0
  26. package/dist/connectors/apply-element.d.ts +59 -0
  27. package/dist/connectors/apply-element.js +385 -0
  28. package/dist/connectors/apply.d.ts +136 -0
  29. package/dist/connectors/apply.js +352 -0
  30. package/dist/connectors/cards.d.ts +96 -0
  31. package/dist/connectors/cards.js +306 -0
  32. package/dist/connectors/catalog.d.ts +79 -0
  33. package/dist/connectors/catalog.js +209 -0
  34. package/dist/connectors/index.d.ts +33 -0
  35. package/dist/connectors/index.js +24 -0
  36. package/dist/connectors/lines.d.ts +108 -0
  37. package/dist/connectors/lines.js +568 -0
  38. package/dist/connectors/select.d.ts +85 -0
  39. package/dist/connectors/select.js +419 -0
  40. package/dist/connectors/template-types.d.ts +188 -0
  41. package/dist/connectors/template-types.js +6 -0
  42. package/dist/connectors/templates/bpmnkit.d.ts +12 -0
  43. package/dist/connectors/templates/bpmnkit.js +186 -0
  44. package/dist/connectors/templates/generated.d.ts +3 -0
  45. package/dist/connectors/templates/generated.js +95885 -0
  46. package/dist/connectors/validate.d.ts +66 -0
  47. package/dist/connectors/validate.js +271 -0
  48. package/dist/index.d.ts +7 -3
  49. package/dist/index.js +2 -0
  50. package/package.json +5 -1
package/README.md CHANGED
@@ -33,6 +33,7 @@ Parse → Modify → Validate → Export
33
33
  - **Camunda Form Definitions** — type-safe form schema builder
34
34
  - **Optimizer** — built-in rule engine to detect and auto-fix anti-patterns
35
35
  - **Compact Format** — 70% smaller token-efficient JSON representation for AI/LLM workflows
36
+ - **Connector catalog** — all Camunda 8 out-of-the-box connector templates, applied deterministically (`@bpmnkit/core/connectors`)
36
37
  - **Zero Dependencies** — runs in browsers, Node.js, Deno, Bun, and edge runtimes
37
38
 
38
39
  ## Installation
@@ -308,6 +309,31 @@ import { writeBpmn } from "@bpmnkit/core/node"
308
309
  const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
309
310
  ```
310
311
 
312
+ ### Connectors (`@bpmnkit/core/connectors`)
313
+
314
+ The Camunda 8 out-of-the-box connector catalog, behind its own subpath so its data is only
315
+ bundled by code that imports it. The templates leave out icons, groups, tooltips and
316
+ placeholders; [`@bpmnkit/connectors`](https://www.npmjs.com/package/@bpmnkit/connectors)
317
+ adds those back for a property panel.
318
+
319
+ | Export | Description |
320
+ |--------|-------------|
321
+ | `listConnectors()` / `searchConnectors(query)` | Summaries: task type, direction, required and optional inputs |
322
+ | `applyConnectorTemplate(id, values)` | Builder options for a bundled template, plus problems |
323
+ | `applyTemplateToElement(defs, id, template, values)` | Apply a template to an existing element |
324
+ | `validateElementTemplate(value)` | Structural check of an element template |
325
+ | `findConnectorCards(query)` / `formatConnectorCard(card)` | One card per operation, with only its inputs — for a model's prompt |
326
+ | `applyConnectorLines(defs, lines)` | Apply the `with` lines a model wrote in the line format |
327
+ | `selectConnectors({ text, tasks })` | Pick the cards a model sees for each task of a diagram |
328
+
329
+ ```typescript
330
+ import { applyConnectorTemplate } from "@bpmnkit/core/connectors"
331
+
332
+ const { serviceTask, problems } = applyConnectorTemplate("io.camunda.connectors.HttpJson.v2", {
333
+ url: "https://api.example.com/orders",
334
+ })
335
+ ```
336
+
311
337
  ### DMN
312
338
 
313
339
  | Export | Description |
@@ -67,6 +67,10 @@ export interface ServiceTaskOptions {
67
67
  name: string;
68
68
  value: string;
69
69
  }>;
70
+ /** Marks the task as an AI agent the engine runs (`zeebe:agentDefinition`, Camunda 8.10+). */
71
+ agentDefinition?: {
72
+ agentType: string;
73
+ };
70
74
  /** Zeebe modeler template ID. */
71
75
  modelerTemplate?: string;
72
76
  /** Zeebe modeler template version. */
@@ -293,6 +297,10 @@ export interface AdHocSubProcessOptions extends ElementOptions {
293
297
  name: string;
294
298
  value: string;
295
299
  }>;
300
+ /** Marks the sub-process as an AI agent the engine runs (`zeebe:agentDefinition`, Camunda 8.10+). */
301
+ agentDefinition?: {
302
+ agentType: string;
303
+ };
296
304
  /** Multi-instance loop configuration. */
297
305
  loopCharacteristics?: {
298
306
  inputCollection: string;
@@ -2,7 +2,7 @@ import { ValidationError } from "../errors.js";
2
2
  import { generateId } from "../types/id-generator.js";
3
3
  import { applyAutoLayout } from "./auto-layout.js";
4
4
  import { createFlowElement } from "./element-shape.js";
5
- import { restConnectorRetries, restConnectorTaskType, restConnectorToIoMappingInputs, restConnectorToTaskHeaders, } from "./rest-connector.js";
5
+ import { REST_CONNECTOR_TEMPLATE_VERSION, restConnectorRetries, restConnectorTaskType, restConnectorToIoMappingInputs, restConnectorToTaskHeaders, } from "./rest-connector.js";
6
6
  import { assignStableFlowIds, rootDefinitionId } from "./stable-ids.js";
7
7
  import { ensureZeebeExtension, zeebeExtensionsToXmlElements, } from "./zeebe-extensions.js";
8
8
  // Keep in sync with packages/core/package.json version
@@ -266,6 +266,8 @@ function buildServiceTaskExtensions(options) {
266
266
  if (options.zeebeProperties) {
267
267
  extensions.properties = { properties: options.zeebeProperties };
268
268
  }
269
+ if (options.agentDefinition)
270
+ extensions.agentDefinition = options.agentDefinition;
269
271
  return zeebeExtensionsToXmlElements(extensions);
270
272
  }
271
273
  function makeConditionExpression(expression) {
@@ -294,6 +296,8 @@ function buildAdHocSubProcessExtensions(options) {
294
296
  if (options?.zeebeProperties) {
295
297
  zeebeExt.properties = { properties: options.zeebeProperties };
296
298
  }
299
+ if (options?.agentDefinition)
300
+ zeebeExt.agentDefinition = options.agentDefinition;
297
301
  const extensionElements = zeebeExtensionsToXmlElements(zeebeExt);
298
302
  const adHocAttrs = {};
299
303
  if (options?.activeElementsCollection) {
@@ -1914,7 +1918,7 @@ export class ProcessBuilder {
1914
1918
  // Stamp the template identifier so editors recognise this as a REST connector
1915
1919
  el.unknownAttributes = {
1916
1920
  "zeebe:modelerTemplate": "io.camunda.connectors.HttpJson.v2",
1917
- "zeebe:modelerTemplateVersion": "12",
1921
+ "zeebe:modelerTemplateVersion": REST_CONNECTOR_TEMPLATE_VERSION,
1918
1922
  };
1919
1923
  this.addFlowElement(el);
1920
1924
  return this;
@@ -19,12 +19,20 @@ export interface CompactElement {
19
19
  dataStoreRef?: string;
20
20
  /** dataObject / dataObjectReference: marks a collection. */
21
21
  isCollection?: boolean;
22
+ /** Zeebe task headers (key→value). */
23
+ taskHeaders?: Record<string, string>;
22
24
  /**
23
- * Zeebe task headers (key→value).
24
- * For the Camunda HTTP connector use jobType "io.camunda:http-json:1" and set:
25
- * url, method, and optionally headers/body/connectionTimeoutInSeconds.
25
+ * Zeebe input mappings (target→source); a source starting with `=` is FEEL.
26
+ * A connector reads its configuration from these: for the Camunda HTTP
27
+ * connector (jobType "io.camunda:http-json:1") set `url`, `method`, and
28
+ * optionally `headers`, `queryParameters`, `body`, `authentication.type`.
26
29
  */
27
- taskHeaders?: Record<string, string>;
30
+ inputs?: Record<string, string>;
31
+ /** The element template applied to this element (`zeebe:modelerTemplate`). */
32
+ modelerTemplate?: {
33
+ id: string;
34
+ version?: number;
35
+ };
28
36
  /** Called process ID (callActivity: zeebe:calledElement.processId) */
29
37
  calledProcess?: string;
30
38
  /** Linked form ID (userTask: zeebe:formDefinition.formId) */
@@ -34,7 +42,9 @@ export interface CompactElement {
34
42
  /**
35
43
  * Primary output variable.
36
44
  * - For businessRuleTask: stored in zeebe:calledDecision.resultVariable.
37
- * - For serviceTask with jobType: stored as a zeebe:ioMapping output (source "= response").
45
+ * - For a Camunda connector job type (`io.camunda:…`): stored as the `resultVariable`
46
+ * task header, which is where the connector runtime reads it.
47
+ * - For any other serviceTask with jobType: stored as a zeebe:ioMapping output (source "= response").
38
48
  */
39
49
  resultVariable?: string;
40
50
  /** Event definition type (timer, error, message, signal, …) */
@@ -48,6 +58,18 @@ export interface CompactElement {
48
58
  elements: CompactElement[];
49
59
  flows: CompactFlow[];
50
60
  };
61
+ /**
62
+ * Runs the activity once per item of a list (`zeebe:loopCharacteristics`):
63
+ * `collection` is the FEEL expression of the list, `element` the variable each
64
+ * instance gets its item in. In parallel unless `sequential`.
65
+ */
66
+ multiInstance?: {
67
+ collection: string;
68
+ element?: string;
69
+ sequential?: boolean;
70
+ };
71
+ /** A timer event's ISO 8601 duration (`PT5M`): how long it waits once reached. */
72
+ timerDuration?: string;
51
73
  }
52
74
  /** A sequence flow in compact form. */
53
75
  export interface CompactFlow {
@@ -126,6 +148,12 @@ export declare function defaultFlows(elements: readonly CompactElement[], flows:
126
148
  */
127
149
  export declare function compactify(defs: BpmnDefinitions): CompactDiagram;
128
150
  export declare function makeEventDef(eventType: string): BpmnEventDefinition | undefined;
151
+ /**
152
+ * Job types run by the Camunda connector runtime (`io.camunda:http-json:1`,
153
+ * `io.camunda.agenticai:aiagent:1`, …). The runtime reads `resultVariable` from
154
+ * a task header, not from an output mapping.
155
+ */
156
+ export declare function isConnectorJobType(jobType: string): boolean;
129
157
  export declare function makeExtensions(el: CompactElement): XmlElement[];
130
158
  export declare function buildFlowElement(el: CompactElement, incoming: string[], outgoing: string[],
131
159
  /** Id of the outgoing flow marked `isDefault`, for a gateway that has one. */
@@ -1,5 +1,6 @@
1
1
  import { layoutProcess } from "../layout/index.js";
2
2
  import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
3
+ import { restConnectorTaskType } from "./rest-connector.js";
3
4
  // ── Default flows ────────────────────────────────────────────────────────────
4
5
  /**
5
6
  * The gateway types that carry a `bpmn:default`. No other element in this model
@@ -49,14 +50,21 @@ function compactifyElement(el) {
49
50
  const jobType = findAttr(ext, "zeebe:taskDefinition", "type");
50
51
  if (jobType)
51
52
  result.jobType = jobType;
52
- // Extract task headers (key→value map from zeebe:taskHeaders children)
53
+ // Extract task headers (key→value map from zeebe:taskHeaders children). A connector's
54
+ // result variable is a header; it is kept apart to round-trip as `resultVariable`.
55
+ const connector = jobType !== undefined && isConnectorJobType(jobType);
56
+ let headerResult;
53
57
  const taskHeadersEl = ext.find((e) => e.name === "zeebe:taskHeaders");
54
58
  if (taskHeadersEl && taskHeadersEl.children.length > 0) {
55
59
  const headers = {};
56
60
  for (const child of taskHeadersEl.children) {
57
61
  const key = child.attributes.key;
58
62
  const value = child.attributes.value;
59
- if (key !== undefined && value !== undefined)
63
+ if (key === undefined || value === undefined)
64
+ continue;
65
+ if (connector && key === "resultVariable")
66
+ headerResult = value;
67
+ else
60
68
  headers[key] = value;
61
69
  }
62
70
  if (Object.keys(headers).length > 0)
@@ -75,8 +83,12 @@ function compactifyElement(el) {
75
83
  if (rv)
76
84
  result.resultVariable = rv;
77
85
  }
86
+ else if (connector) {
87
+ if (headerResult !== undefined)
88
+ result.resultVariable = headerResult;
89
+ }
78
90
  else {
79
- // For service tasks: extract the primary output variable from ioMapping
91
+ // For job workers: extract the primary output variable from ioMapping
80
92
  const ioMappingEl = ext.find((e) => e.name === "zeebe:ioMapping");
81
93
  if (ioMappingEl) {
82
94
  const outputs = ioMappingEl.children.filter((c) => c.name === "zeebe:output");
@@ -87,8 +99,35 @@ function compactifyElement(el) {
87
99
  }
88
100
  }
89
101
  }
102
+ const inputs = {};
103
+ for (const input of ext.find((e) => e.name === "zeebe:ioMapping")?.children ?? []) {
104
+ const { source, target } = input.attributes;
105
+ if (input.name === "zeebe:input" && source !== undefined && target !== undefined) {
106
+ inputs[target] = source;
107
+ }
108
+ }
109
+ if (Object.keys(inputs).length > 0)
110
+ result.inputs = inputs;
111
+ const template = el.unknownAttributes["zeebe:modelerTemplate"];
112
+ if (template) {
113
+ const version = Number.parseInt(el.unknownAttributes["zeebe:modelerTemplateVersion"] ?? "", 10);
114
+ result.modelerTemplate = Number.isNaN(version) ? { id: template } : { id: template, version };
115
+ }
90
116
  if ("eventDefinitions" in el && el.eventDefinitions.length > 0) {
91
- result.eventType = el.eventDefinitions[0]?.type;
117
+ const def = el.eventDefinitions[0];
118
+ result.eventType = def?.type;
119
+ if (def?.type === "timer" && def.timeDuration)
120
+ result.timerDuration = def.timeDuration;
121
+ }
122
+ const loop = "loopCharacteristics" in el ? el.loopCharacteristics : undefined;
123
+ const zeebeLoop = loop?.extensionElements.find((x) => x.name === "zeebe:loopCharacteristics");
124
+ const collection = zeebeLoop?.attributes.inputCollection;
125
+ if (loop && collection) {
126
+ result.multiInstance = { collection };
127
+ if (zeebeLoop.attributes.inputElement)
128
+ result.multiInstance.element = zeebeLoop.attributes.inputElement;
129
+ if (loop.isSequential)
130
+ result.multiInstance.sequential = true;
92
131
  }
93
132
  if (el.type === "boundaryEvent") {
94
133
  result.attachedTo = el.attachedToRef;
@@ -263,16 +302,59 @@ export function makeEventDef(eventType) {
263
302
  return undefined;
264
303
  }
265
304
  }
305
+ /**
306
+ * Job types run by the Camunda connector runtime (`io.camunda:http-json:1`,
307
+ * `io.camunda.agenticai:aiagent:1`, …). The runtime reads `resultVariable` from
308
+ * a task header, not from an output mapping.
309
+ */
310
+ export function isConnectorJobType(jobType) {
311
+ return /^io\.camunda[.:]/.test(jobType);
312
+ }
313
+ /** Inputs of the HTTP connector that older compact answers wrote as task headers. */
314
+ function isRestInputKey(key) {
315
+ return (key === "url" ||
316
+ key === "method" ||
317
+ key === "headers" ||
318
+ key === "queryParameters" ||
319
+ key === "body" ||
320
+ key === "connectionTimeoutInSeconds" ||
321
+ key === "readTimeoutInSeconds" ||
322
+ key.startsWith("authentication."));
323
+ }
324
+ /**
325
+ * Split an element's configuration into input mappings and task headers the
326
+ * way the engine reads them. The HTTP connector reads `url`, `method` and the
327
+ * rest from its inputs, so those keys move out of `taskHeaders`, where earlier
328
+ * prompts told models to put them and where the connector never looks.
329
+ */
330
+ function zeebeConfig(el) {
331
+ const rest = el.jobType === restConnectorTaskType();
332
+ const inputs = { ...el.inputs };
333
+ const headers = {};
334
+ for (const [key, value] of Object.entries(el.taskHeaders ?? {})) {
335
+ if (rest && isRestInputKey(key))
336
+ inputs[key] ??= value;
337
+ else
338
+ headers[key] = value;
339
+ }
340
+ if (rest && inputs.url !== undefined)
341
+ inputs["authentication.type"] ??= "noAuth";
342
+ if (el.jobType && isConnectorJobType(el.jobType) && el.resultVariable && !el.decisionId) {
343
+ headers.resultVariable ??= el.resultVariable;
344
+ }
345
+ return { inputs, headers };
346
+ }
266
347
  export function makeExtensions(el) {
267
348
  const ext = [];
349
+ const { inputs, headers } = zeebeConfig(el);
268
350
  if (el.jobType) {
269
351
  ext.push({ name: "zeebe:taskDefinition", attributes: { type: el.jobType }, children: [] });
270
352
  }
271
- if (el.taskHeaders && Object.keys(el.taskHeaders).length > 0) {
353
+ if (Object.keys(headers).length > 0) {
272
354
  ext.push({
273
355
  name: "zeebe:taskHeaders",
274
356
  attributes: {},
275
- children: Object.entries(el.taskHeaders).map(([key, value]) => ({
357
+ children: Object.entries(headers).map(([key, value]) => ({
276
358
  name: "zeebe:header",
277
359
  attributes: { key, value },
278
360
  children: [],
@@ -299,20 +381,22 @@ export function makeExtensions(el) {
299
381
  children: [],
300
382
  });
301
383
  }
302
- else if (el.resultVariable && el.jobType) {
303
- // Service task with a result variable: map the connector response to the variable
304
- ext.push({
305
- name: "zeebe:ioMapping",
306
- attributes: {},
307
- children: [
308
- {
309
- name: "zeebe:output",
310
- attributes: { source: "= response", target: el.resultVariable },
311
- children: [],
312
- },
313
- ],
384
+ const ioMapping = Object.entries(inputs).map(([target, source]) => ({
385
+ name: "zeebe:input",
386
+ attributes: { source, target },
387
+ children: [],
388
+ }));
389
+ if (el.resultVariable && el.jobType && !el.decisionId && !isConnectorJobType(el.jobType)) {
390
+ // A job worker's result: map its `response` variable to the result variable
391
+ ioMapping.push({
392
+ name: "zeebe:output",
393
+ attributes: { source: "= response", target: el.resultVariable },
394
+ children: [],
314
395
  });
315
396
  }
397
+ if (ioMapping.length > 0) {
398
+ ext.push({ name: "zeebe:ioMapping", attributes: {}, children: ioMapping });
399
+ }
316
400
  return ext;
317
401
  }
318
402
  function buildSubContent(children) {
@@ -352,6 +436,14 @@ function buildSubContent(children) {
352
436
  groups: [],
353
437
  };
354
438
  }
439
+ function templateAttributes(el) {
440
+ if (!el.modelerTemplate)
441
+ return {};
442
+ const { id, version } = el.modelerTemplate;
443
+ return version === undefined
444
+ ? { "zeebe:modelerTemplate": id }
445
+ : { "zeebe:modelerTemplate": id, "zeebe:modelerTemplateVersion": String(version) };
446
+ }
355
447
  export function buildFlowElement(el, incoming, outgoing,
356
448
  /** Id of the outgoing flow marked `isDefault`, for a gateway that has one. */
357
449
  defaultFlow) {
@@ -362,11 +454,27 @@ defaultFlow) {
362
454
  incoming,
363
455
  outgoing,
364
456
  extensionElements: makeExtensions(el),
365
- unknownAttributes: {},
457
+ unknownAttributes: templateAttributes(el),
366
458
  };
367
- const eventDef = el.eventType ? makeEventDef(el.eventType) : undefined;
459
+ const made = el.eventType ? makeEventDef(el.eventType) : undefined;
460
+ const eventDef = made?.type === "timer" && el.timerDuration ? { ...made, timeDuration: el.timerDuration } : made;
368
461
  const eventDefs = eventDef ? [eventDef] : [];
369
462
  const subContent = buildSubContent(el.children);
463
+ const loop = el.multiInstance && {
464
+ loopCharacteristics: {
465
+ isSequential: el.multiInstance.sequential || undefined,
466
+ extensionElements: [
467
+ {
468
+ name: "zeebe:loopCharacteristics",
469
+ attributes: {
470
+ inputCollection: el.multiInstance.collection,
471
+ ...(el.multiInstance.element ? { inputElement: el.multiInstance.element } : {}),
472
+ },
473
+ children: [],
474
+ },
475
+ ],
476
+ },
477
+ };
370
478
  switch (el.type) {
371
479
  case "startEvent":
372
480
  return { ...base, type: "startEvent", eventDefinitions: eventDefs };
@@ -385,25 +493,25 @@ defaultFlow) {
385
493
  eventDefinitions: eventDefs,
386
494
  };
387
495
  case "serviceTask":
388
- return { ...base, type: "serviceTask" };
496
+ return { ...base, type: "serviceTask", ...loop };
389
497
  case "scriptTask":
390
- return { ...base, type: "scriptTask" };
498
+ return { ...base, type: "scriptTask", ...loop };
391
499
  case "userTask":
392
- return { ...base, type: "userTask" };
500
+ return { ...base, type: "userTask", ...loop };
393
501
  case "businessRuleTask":
394
- return { ...base, type: "businessRuleTask" };
502
+ return { ...base, type: "businessRuleTask", ...loop };
395
503
  case "callActivity":
396
- return { ...base, type: "callActivity" };
504
+ return { ...base, type: "callActivity", ...loop };
397
505
  case "sendTask":
398
- return { ...base, type: "sendTask" };
506
+ return { ...base, type: "sendTask", ...loop };
399
507
  case "receiveTask":
400
- return { ...base, type: "receiveTask" };
508
+ return { ...base, type: "receiveTask", ...loop };
401
509
  case "manualTask":
402
- return { ...base, type: "manualTask" };
510
+ return { ...base, type: "manualTask", ...loop };
403
511
  case "task":
404
- return { ...base, type: "task" };
512
+ return { ...base, type: "task", ...loop };
405
513
  case "subProcess":
406
- return { ...base, type: "subProcess", ...subContent };
514
+ return { ...base, type: "subProcess", ...subContent, ...loop };
407
515
  case "adHocSubProcess":
408
516
  return { ...base, type: "adHocSubProcess", ...subContent };
409
517
  case "eventSubProcess":
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `with` lines: how a model configures a connector in the line format.
3
+ *
4
+ * ```
5
+ * with post: slack chat.postMessage | data.channel=#ops | data.text== "Order " + orderId
6
+ * with fetch: http GET https://api.example.com/orders | result=order
7
+ * ```
8
+ *
9
+ * A line names a node already written by its id, the connector by its alias,
10
+ * the operation when the connector has several, and the inputs as
11
+ * `key=value` (`key==expr` for FEEL). Path lines are unchanged, so a `with`
12
+ * line can follow anywhere and a diagram streams as before.
13
+ *
14
+ * This module only reads the line. Which connector an alias names, which keys
15
+ * it has and what it writes is `@bpmnkit/core/connectors`' part, so the parser
16
+ * stays free of the catalog's data.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ import type { ProcessTextProblem } from "./process-text.js";
21
+ /** One `with` line, as written. Nothing is resolved against the catalog yet. */
22
+ export interface ConnectorLine {
23
+ /** The node's id as written. */
24
+ id: string;
25
+ /** The connector alias, e.g. `slack`. */
26
+ alias: string;
27
+ /**
28
+ * The words after the alias, before the first `|`: the operation, and for
29
+ * some connectors values written without a key (`http GET <url>`). A word
30
+ * starting with `=` or a quote runs to the end of the head.
31
+ */
32
+ args: string[];
33
+ /** `key=value` parts, in the order written; a later key wins. */
34
+ values: Record<string, string>;
35
+ line: number;
36
+ }
37
+ /** `with <id>:` at the start of a line. */
38
+ export declare const CONNECTOR_LINE: RegExp;
39
+ /**
40
+ * Reads a `with` line, or answers `undefined` when the line is not one.
41
+ *
42
+ * Never throws: a line that starts like one but cannot be read becomes a
43
+ * problem, and the parts it could read are kept.
44
+ */
45
+ export declare function parseConnectorLine(text: string, line: number, problems: ProcessTextProblem[]): ConnectorLine | undefined;
46
+ //# sourceMappingURL=connector-line.d.ts.map
@@ -0,0 +1,135 @@
1
+ /**
2
+ * `with` lines: how a model configures a connector in the line format.
3
+ *
4
+ * ```
5
+ * with post: slack chat.postMessage | data.channel=#ops | data.text== "Order " + orderId
6
+ * with fetch: http GET https://api.example.com/orders | result=order
7
+ * ```
8
+ *
9
+ * A line names a node already written by its id, the connector by its alias,
10
+ * the operation when the connector has several, and the inputs as
11
+ * `key=value` (`key==expr` for FEEL). Path lines are unchanged, so a `with`
12
+ * line can follow anywhere and a diagram streams as before.
13
+ *
14
+ * This module only reads the line. Which connector an alias names, which keys
15
+ * it has and what it writes is `@bpmnkit/core/connectors`' part, so the parser
16
+ * stays free of the catalog's data.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ /** `with <id>:` at the start of a line. */
21
+ export const CONNECTOR_LINE = /^with\s+([A-Za-z_][\w.-]*)\s*:\s*(.*)$/i;
22
+ /** Splits on `|` outside quotes, brackets, braces and parentheses. */
23
+ function splitParts(text) {
24
+ const parts = [];
25
+ let depth = 0;
26
+ let quote;
27
+ let start = 0;
28
+ for (let i = 0; i < text.length; i++) {
29
+ const ch = text[i];
30
+ if (quote !== undefined) {
31
+ if (ch === "\\")
32
+ i++;
33
+ else if (ch === quote)
34
+ quote = undefined;
35
+ }
36
+ else if (ch === '"' || ch === "'")
37
+ quote = ch;
38
+ else if (ch === "(" || ch === "[" || ch === "{")
39
+ depth++;
40
+ else if (ch === ")" || ch === "]" || ch === "}")
41
+ depth = Math.max(0, depth - 1);
42
+ else if (ch === "|" && depth === 0) {
43
+ parts.push(text.slice(start, i));
44
+ start = i + 1;
45
+ }
46
+ }
47
+ parts.push(text.slice(start));
48
+ return parts.map((p) => p.trim());
49
+ }
50
+ /**
51
+ * `a=1 b=2 c==x + 1`, several inputs in one part as the cards list them, split
52
+ * into one part each: at a space before `key=`, outside quotes and brackets.
53
+ * A FEEL value runs to the end of the part, as it may hold `=` itself.
54
+ */
55
+ function splitPairs(part) {
56
+ const pairs = [];
57
+ let depth = 0;
58
+ let quote;
59
+ let start = 0;
60
+ for (let i = 0; i < part.length; i++) {
61
+ const ch = part[i];
62
+ if (quote !== undefined) {
63
+ if (ch === "\\")
64
+ i++;
65
+ else if (ch === quote)
66
+ quote = undefined;
67
+ }
68
+ else if (ch === '"' || ch === "'")
69
+ quote = ch;
70
+ else if (ch === "(" || ch === "[" || ch === "{")
71
+ depth++;
72
+ else if (ch === ")" || ch === "]" || ch === "}")
73
+ depth = Math.max(0, depth - 1);
74
+ else if (ch === "=" && part[i + 1] === "=" && depth === 0)
75
+ break;
76
+ else if (/\s/.test(ch ?? "") && depth === 0 && /^\s+[A-Za-z_][\w.]*\*?=/.test(part.slice(i))) {
77
+ pairs.push(part.slice(start, i));
78
+ start = i + 1;
79
+ }
80
+ }
81
+ pairs.push(part.slice(start));
82
+ return pairs.map((p) => p.trim()).filter((p) => p !== "");
83
+ }
84
+ function headWords(head) {
85
+ const words = [];
86
+ let rest = head.trim();
87
+ while (rest !== "") {
88
+ if (rest.startsWith("=") || rest.startsWith('"') || rest.startsWith("'")) {
89
+ words.push(rest);
90
+ break;
91
+ }
92
+ const space = rest.search(/\s/);
93
+ words.push(space < 0 ? rest : rest.slice(0, space));
94
+ rest = space < 0 ? "" : rest.slice(space).trim();
95
+ }
96
+ return words;
97
+ }
98
+ /**
99
+ * Reads a `with` line, or answers `undefined` when the line is not one.
100
+ *
101
+ * Never throws: a line that starts like one but cannot be read becomes a
102
+ * problem, and the parts it could read are kept.
103
+ */
104
+ export function parseConnectorLine(text, line, problems) {
105
+ const match = CONNECTOR_LINE.exec(text.trim());
106
+ if (!match)
107
+ return undefined;
108
+ const [, id = "", body = ""] = match;
109
+ const [head = "", ...rest] = splitParts(body);
110
+ const [alias, ...args] = headWords(head);
111
+ if (alias === undefined) {
112
+ problems.push({ line, message: `"with ${id}:" names no connector; ignored` });
113
+ return undefined;
114
+ }
115
+ const values = {};
116
+ for (const part of rest.flatMap(splitPairs)) {
117
+ const eq = part.indexOf("=");
118
+ // `token*={{secrets.T}}`: the card's required mark copied with the key
119
+ const key = eq < 0 ? "" : part.slice(0, eq).trim().replace(/\*$/, "");
120
+ if (eq <= 0 || !/^[\w.:$-]+$/.test(key)) {
121
+ problems.push({ line, message: `expected "key=value" at "${part.slice(0, 30)}"; ignored` });
122
+ continue;
123
+ }
124
+ values[key] = part.slice(eq + 1).trim();
125
+ }
126
+ // A URL where the alias goes keeps its case: paths are case-sensitive
127
+ return {
128
+ id,
129
+ alias: /^https?:\/\//i.test(alias) ? alias : alias.toLowerCase(),
130
+ args,
131
+ values,
132
+ line,
133
+ };
134
+ }
135
+ //# sourceMappingURL=connector-line.js.map
@@ -49,9 +49,7 @@ export function analyzePatterns(p) {
49
49
  if (el.type !== "serviceTask")
50
50
  continue;
51
51
  const jobType = readZeebeTaskType(el.extensionElements) ?? "";
52
- const isHttp = jobType.toLowerCase().includes("http") ||
53
- jobType.toLowerCase().includes("rest") ||
54
- jobType === "io.camunda.connector.HttpJson:1";
52
+ const isHttp = jobType.toLowerCase().includes("http") || jobType.toLowerCase().includes("rest");
55
53
  if (!isHttp)
56
54
  continue;
57
55
  if (!hasBoundaryOf(el.id, "error", boundaryTypes)) {
@@ -17,6 +17,7 @@
17
17
  */
18
18
  import type { BpmnElementType } from "./bpmn-model.js";
19
19
  import type { CompactFlow } from "./compact.js";
20
+ import { type ConnectorLine } from "./connector-line.js";
20
21
  import { type ProcessTextProblem } from "./process-text.js";
21
22
  /**
22
23
  * Kind words the writer uses for element types the line format cannot create.
@@ -74,6 +75,8 @@ export interface ProcessDelta {
74
75
  ids: string[];
75
76
  line: number;
76
77
  }[];
78
+ /** `with` lines: connector configuration for a node, existing or new. */
79
+ connectors: ConnectorLine[];
77
80
  /** Lines, or parts of lines, that were left out. */
78
81
  problems: ProcessTextProblem[];
79
82
  }