@nanobpm/urban 0.82.0 → 0.83.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.
@@ -34,6 +34,9 @@ function ctxWith(surfaces: Record<string, unknown>): Parameters<typeof mountSurf
34
34
  getForm: async () => null,
35
35
  completeUserTask: async () => {},
36
36
  searchProcessInstances: async () => [],
37
+ searchElementInstances: async () => [],
38
+ searchElementInstanceWaitStates: async () => [],
39
+ getElementInstance: async () => null,
37
40
  registerWorker: async (jobType) => ({ jobType, unsubscribe: async () => {} }),
38
41
  close: async () => {},
39
42
  };
@@ -50,6 +53,9 @@ const fakeEngine: EngineClient = {
50
53
  getForm: async () => null,
51
54
  completeUserTask: async () => {},
52
55
  searchProcessInstances: async () => [],
56
+ searchElementInstances: async () => [],
57
+ searchElementInstanceWaitStates: async () => [],
58
+ getElementInstance: async () => null,
53
59
  registerWorker: async (jobType) => ({ jobType, unsubscribe: async () => {} }),
54
60
  close: async () => {},
55
61
  };
@@ -35,6 +35,9 @@ class MiniEngine implements EngineClient {
35
35
  async getForm(): Promise<null> { return null; }
36
36
  async completeUserTask(): Promise<void> {}
37
37
  async searchProcessInstances(): Promise<[]> { return []; }
38
+ async searchElementInstances(): Promise<[]> { return []; }
39
+ async searchElementInstanceWaitStates(): Promise<[]> { return []; }
40
+ async getElementInstance(): Promise<null> { return null; }
38
41
  async registerWorker(jobType: string): Promise<{ jobType: string; unsubscribe(): Promise<void> }> {
39
42
  return { jobType, unsubscribe: async () => {} };
40
43
  }
@@ -32,6 +32,9 @@ class MiniEngine implements EngineClient {
32
32
  async getForm(): Promise<null> { return null; }
33
33
  async completeUserTask(): Promise<void> {}
34
34
  async searchProcessInstances(): Promise<[]> { return []; }
35
+ async searchElementInstances(): Promise<[]> { return []; }
36
+ async searchElementInstanceWaitStates(): Promise<[]> { return []; }
37
+ async getElementInstance(): Promise<null> { return null; }
35
38
  async close(): Promise<void> {}
36
39
  async registerWorker(jobType: string, handler: JobHandler): Promise<WorkerSubscription> {
37
40
  this.workers.set(jobType, handler);
@@ -32,6 +32,15 @@ class NoopEngine implements EngineClient {
32
32
  async searchProcessInstances() {
33
33
  return [];
34
34
  }
35
+ async searchElementInstances() {
36
+ return [];
37
+ }
38
+ async searchElementInstanceWaitStates() {
39
+ return [];
40
+ }
41
+ async getElementInstance() {
42
+ return null;
43
+ }
35
44
  async registerWorker(jobType: string): Promise<WorkerSubscription> {
36
45
  return { jobType, unsubscribe: async () => {} };
37
46
  }
@@ -53,6 +53,15 @@ class FakeEngine implements EngineClient {
53
53
  async searchProcessInstances() {
54
54
  return [];
55
55
  }
56
+ async searchElementInstances() {
57
+ return [];
58
+ }
59
+ async searchElementInstanceWaitStates() {
60
+ return [];
61
+ }
62
+ async getElementInstance() {
63
+ return null;
64
+ }
56
65
  async registerWorker(jobType: string, handler: JobHandler): Promise<WorkerSubscription> {
57
66
  this.workers.set(jobType, handler);
58
67
  return { jobType, unsubscribe: async () => void this.workers.delete(jobType) };
@@ -3,6 +3,8 @@ import assert from "node:assert/strict";
3
3
  import {
4
4
  createNanoSdkEngineClient,
5
5
  normalizeProcessInstanceState,
6
+ normalizeElementInstanceState,
7
+ normalizeWaitStateType,
6
8
  requireProcessInstanceKey,
7
9
  SdkEngineClient,
8
10
  type NanoSdkActivatedJob,
@@ -74,6 +76,18 @@ function fakeSdkClient(overrides: Partial<NanoSdkClient> = {}): NanoSdkClient &
74
76
  calls.push("searchProcessInstances");
75
77
  return { items: [] };
76
78
  },
79
+ async searchElementInstances() {
80
+ calls.push("searchElementInstances");
81
+ return { items: [] };
82
+ },
83
+ async searchElementInstanceWaitStates() {
84
+ calls.push("searchElementInstanceWaitStates");
85
+ return { items: [] };
86
+ },
87
+ async getElementInstance() {
88
+ calls.push("getElementInstance");
89
+ return {};
90
+ },
77
91
  async completeUserTask() {
78
92
  calls.push("completeUserTask");
79
93
  return {};
@@ -448,6 +462,273 @@ test("normalizeProcessInstanceState maps the terminal set and rejects others", (
448
462
  assert.equal(normalizeProcessInstanceState(undefined), undefined);
449
463
  });
450
464
 
465
+ test("normalizeElementInstanceState maps the recognized states (case-insensitive) and rejects others", () => {
466
+ assert.equal(normalizeElementInstanceState("ACTIVE"), "ACTIVE");
467
+ assert.equal(normalizeElementInstanceState("completed"), "COMPLETED");
468
+ assert.equal(normalizeElementInstanceState("Terminated"), "TERMINATED");
469
+ assert.equal(normalizeElementInstanceState("SKIPPED"), undefined);
470
+ assert.equal(normalizeElementInstanceState(7), undefined);
471
+ assert.equal(normalizeElementInstanceState(undefined), undefined);
472
+ });
473
+
474
+ test("normalizeWaitStateType maps the wait-state kinds (case-insensitive) and rejects others", () => {
475
+ assert.equal(normalizeWaitStateType("JOB"), "JOB");
476
+ assert.equal(normalizeWaitStateType("message"), "MESSAGE");
477
+ assert.equal(normalizeWaitStateType("User_Task"), "USER_TASK");
478
+ assert.equal(normalizeWaitStateType("TIMER"), "TIMER");
479
+ assert.equal(normalizeWaitStateType("signal"), "SIGNAL");
480
+ assert.equal(normalizeWaitStateType("CONDITION"), "CONDITION");
481
+ assert.equal(normalizeWaitStateType("ESCALATION"), undefined);
482
+ assert.equal(normalizeWaitStateType(3), undefined);
483
+ });
484
+
485
+ test("searchElementInstances passes zero-wait consistency, maps rows, and forwards selectors", async () => {
486
+ let seenInput: unknown;
487
+ let seenConsistency: unknown;
488
+ const client = fakeSdkClient({
489
+ searchElementInstances: async (input, c) => {
490
+ seenInput = input;
491
+ seenConsistency = c;
492
+ return {
493
+ items: [
494
+ {
495
+ elementInstanceKey: 5,
496
+ processInstanceKey: 3,
497
+ elementId: "task",
498
+ type: "SERVICE_TASK",
499
+ state: "active",
500
+ },
501
+ // elementType may arrive as `elementType` on a plain REST body.
502
+ {
503
+ elementInstanceKey: "6",
504
+ processInstanceKey: "3",
505
+ elementId: "gw",
506
+ elementType: "PARALLEL_GATEWAY",
507
+ state: "COMPLETED",
508
+ },
509
+ ],
510
+ };
511
+ },
512
+ });
513
+ const engine = new SdkEngineClient(client);
514
+ const out = await engine.searchElementInstances({
515
+ processInstanceKey: "3",
516
+ elementId: "task",
517
+ state: "ACTIVE",
518
+ });
519
+ assert.deepEqual(seenInput, {
520
+ filter: { processInstanceKey: "3", elementId: "task", state: "ACTIVE" },
521
+ });
522
+ assert.deepEqual(seenConsistency, { consistency: { waitUpToMs: 0 } });
523
+ assert.deepEqual(out, [
524
+ {
525
+ elementInstanceKey: "5",
526
+ processInstanceKey: "3",
527
+ elementId: "task",
528
+ elementType: "SERVICE_TASK",
529
+ state: "ACTIVE",
530
+ },
531
+ {
532
+ elementInstanceKey: "6",
533
+ processInstanceKey: "3",
534
+ elementId: "gw",
535
+ elementType: "PARALLEL_GATEWAY",
536
+ state: "COMPLETED",
537
+ },
538
+ ]);
539
+ });
540
+
541
+ test("searchElementInstances with no filter sends an empty filter", async () => {
542
+ let seenInput: unknown;
543
+ const client = fakeSdkClient({
544
+ searchElementInstances: async (input) => {
545
+ seenInput = input;
546
+ return { items: [] };
547
+ },
548
+ });
549
+ const engine = new SdkEngineClient(client);
550
+ await engine.searchElementInstances();
551
+ assert.deepEqual(seenInput, { filter: {} });
552
+ });
553
+
554
+ test("searchElementInstances skips malformed rows (missing key/elementId/state)", async () => {
555
+ const client = fakeSdkClient({
556
+ searchElementInstances: async () => ({
557
+ items: [
558
+ { elementInstanceKey: "", processInstanceKey: "3", elementId: "a", state: "ACTIVE" }, // keyless
559
+ { elementInstanceKey: " ", processInstanceKey: "3", elementId: "a", state: "ACTIVE" }, // whitespace key
560
+ { elementInstanceKey: "5", processInstanceKey: "", elementId: "a", state: "ACTIVE" }, // no PI key
561
+ { elementInstanceKey: "6", processInstanceKey: "3", elementId: "", state: "ACTIVE" }, // no elementId
562
+ { elementInstanceKey: "9", processInstanceKey: "3", elementId: " ", state: "ACTIVE" }, // whitespace elementId
563
+ { elementInstanceKey: "7", processInstanceKey: "3", elementId: "a", state: "SKIPPED" }, // bad state
564
+ { elementInstanceKey: "8", processInstanceKey: "3", elementId: "ok", state: "ACTIVE" }, // kept
565
+ ],
566
+ }),
567
+ });
568
+ const engine = new SdkEngineClient(client);
569
+ const out = await engine.searchElementInstances();
570
+ assert.deepEqual(out, [
571
+ { elementInstanceKey: "8", processInstanceKey: "3", elementId: "ok", state: "ACTIVE" },
572
+ ]);
573
+ });
574
+
575
+ test("searchElementInstanceWaitStates maps JOB/MESSAGE parks and unwraps SDK `details`", async () => {
576
+ let seenInput: unknown;
577
+ let seenConsistency: unknown;
578
+ const client = fakeSdkClient({
579
+ searchElementInstanceWaitStates: async (input, c) => {
580
+ seenInput = input;
581
+ seenConsistency = c;
582
+ return {
583
+ items: [
584
+ {
585
+ elementInstanceKey: 5,
586
+ processInstanceKey: 3,
587
+ elementId: "svc",
588
+ type: "SERVICE_TASK",
589
+ details: { waitStateType: "JOB", jobType: "work", jobKey: 6 },
590
+ },
591
+ {
592
+ elementInstanceKey: 8,
593
+ processInstanceKey: 3,
594
+ elementId: "catch",
595
+ details: { waitStateType: "MESSAGE", messageName: "Go", correlationKey: "K1" },
596
+ },
597
+ ],
598
+ };
599
+ },
600
+ });
601
+ const engine = new SdkEngineClient(client);
602
+ const out = await engine.searchElementInstanceWaitStates({ processInstanceKey: "3" });
603
+ assert.deepEqual(seenInput, { filter: { processInstanceKey: "3" } });
604
+ assert.deepEqual(seenConsistency, { consistency: { waitUpToMs: 0 } });
605
+ assert.deepEqual(out, [
606
+ {
607
+ elementInstanceKey: "5",
608
+ processInstanceKey: "3",
609
+ elementId: "svc",
610
+ elementType: "SERVICE_TASK",
611
+ waitStateType: "JOB",
612
+ jobType: "work",
613
+ jobKey: "6",
614
+ },
615
+ {
616
+ elementInstanceKey: "8",
617
+ processInstanceKey: "3",
618
+ elementId: "catch",
619
+ waitStateType: "MESSAGE",
620
+ messageName: "Go",
621
+ correlationKey: "K1",
622
+ },
623
+ ]);
624
+ });
625
+
626
+ test("searchElementInstanceWaitStates forwards a waitStateType selector and reads inlined details", async () => {
627
+ let seenInput: unknown;
628
+ const client = fakeSdkClient({
629
+ searchElementInstanceWaitStates: async (input) => {
630
+ seenInput = input;
631
+ // A plain REST body may inline the park fields rather than nesting them under `details`.
632
+ return {
633
+ items: [
634
+ {
635
+ elementInstanceKey: "9",
636
+ processInstanceKey: "3",
637
+ elementId: "ut",
638
+ waitStateType: "USER_TASK",
639
+ taskKey: "42",
640
+ },
641
+ {
642
+ elementInstanceKey: "11",
643
+ processInstanceKey: "3",
644
+ elementId: "ut2",
645
+ waitStateType: "USER_TASK",
646
+ }, // USER_TASK with no taskKey/userTaskKey → dropped (invalid identity)
647
+ { elementInstanceKey: "10", processInstanceKey: "3", elementId: "?" }, // no waitStateType → dropped
648
+ ],
649
+ };
650
+ },
651
+ });
652
+ const engine = new SdkEngineClient(client);
653
+ const out = await engine.searchElementInstanceWaitStates({ waitStateType: "USER_TASK" });
654
+ assert.deepEqual(seenInput, { filter: { waitStateType: "USER_TASK" } });
655
+ assert.deepEqual(out, [
656
+ {
657
+ elementInstanceKey: "9",
658
+ processInstanceKey: "3",
659
+ elementId: "ut",
660
+ waitStateType: "USER_TASK",
661
+ userTaskKey: "42",
662
+ },
663
+ ]);
664
+ });
665
+
666
+ test("searchElementInstanceWaitStates drops parks missing their required discriminator field", async () => {
667
+ const client = fakeSdkClient({
668
+ searchElementInstanceWaitStates: async () => ({
669
+ items: [
670
+ { elementInstanceKey: "5", processInstanceKey: "3", elementId: "j", waitStateType: "JOB" }, // no jobType
671
+ { elementInstanceKey: "6", processInstanceKey: "3", elementId: "m", waitStateType: "MESSAGE" }, // no messageName
672
+ { elementInstanceKey: "7", processInstanceKey: "3", elementId: "s", waitStateType: "SIGNAL" }, // no signalName
673
+ {
674
+ elementInstanceKey: "8",
675
+ processInstanceKey: "3",
676
+ elementId: "j2",
677
+ waitStateType: "JOB",
678
+ jobType: " ",
679
+ }, // blank jobType → dropped
680
+ {
681
+ elementInstanceKey: "9",
682
+ processInstanceKey: "3",
683
+ elementId: "t",
684
+ waitStateType: "TIMER",
685
+ }, // TIMER has no required field → kept
686
+ ],
687
+ }),
688
+ });
689
+ const engine = new SdkEngineClient(client);
690
+ const out = await engine.searchElementInstanceWaitStates();
691
+ assert.deepEqual(out, [
692
+ { elementInstanceKey: "9", processInstanceKey: "3", elementId: "t", waitStateType: "TIMER" },
693
+ ]);
694
+ });
695
+
696
+ test("getElementInstance returns a mapped summary, and null for a blank key or a 404", async () => {
697
+ const client = fakeSdkClient({
698
+ getElementInstance: async (input) => {
699
+ if (input.elementInstanceKey === "5") {
700
+ return {
701
+ elementInstanceKey: 5,
702
+ processInstanceKey: 3,
703
+ elementId: "task",
704
+ type: "SERVICE_TASK",
705
+ state: "ACTIVE",
706
+ };
707
+ }
708
+ throw new Error("404 not found");
709
+ },
710
+ });
711
+ const engine = new SdkEngineClient(client);
712
+ assert.deepEqual(await engine.getElementInstance("5"), {
713
+ elementInstanceKey: "5",
714
+ processInstanceKey: "3",
715
+ elementId: "task",
716
+ elementType: "SERVICE_TASK",
717
+ state: "ACTIVE",
718
+ });
719
+ // A padded-but-valid key is normalized before the fetch, so it addresses the same instance.
720
+ assert.deepEqual(await engine.getElementInstance(" 5 "), {
721
+ elementInstanceKey: "5",
722
+ processInstanceKey: "3",
723
+ elementId: "task",
724
+ elementType: "SERVICE_TASK",
725
+ state: "ACTIVE",
726
+ });
727
+ // A blank key short-circuits without hitting the engine; a 404 is treated as absence.
728
+ assert.equal(await engine.getElementInstance(" "), null);
729
+ assert.equal(await engine.getElementInstance("missing"), null);
730
+ });
731
+
451
732
  test("registerWorker creates a worker the SDK auto-starts, and dispatches + completes", async () => {
452
733
  const client = fakeSdkClient();
453
734
  const engine = new SdkEngineClient(client);