@open-mercato/core 0.6.5-develop.4516.1.88e6ab71a9 → 0.6.5-develop.4534.1.b459babe6d

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 (102) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/dist/generated/entities/step_instance/index.js +2 -0
  3. package/dist/generated/entities/step_instance/index.js.map +2 -2
  4. package/dist/generated/entities/user_task/index.js +2 -0
  5. package/dist/generated/entities/user_task/index.js.map +2 -2
  6. package/dist/generated/entities/workflow_branch_instance/index.js +39 -0
  7. package/dist/generated/entities/workflow_branch_instance/index.js.map +7 -0
  8. package/dist/generated/entities/workflow_event/index.js +2 -0
  9. package/dist/generated/entities/workflow_event/index.js.map +2 -2
  10. package/dist/generated/entities/workflow_instance/index.js +2 -0
  11. package/dist/generated/entities/workflow_instance/index.js.map +2 -2
  12. package/dist/generated/entities.ids.generated.js +1 -0
  13. package/dist/generated/entities.ids.generated.js.map +2 -2
  14. package/dist/generated/entity-fields-registry.js +24 -0
  15. package/dist/generated/entity-fields-registry.js.map +2 -2
  16. package/dist/modules/progress/api/jobs/[id]/route.js +7 -1
  17. package/dist/modules/progress/api/jobs/[id]/route.js.map +2 -2
  18. package/dist/modules/shipping_carriers/api/cancel/route.js +2 -2
  19. package/dist/modules/shipping_carriers/api/cancel/route.js.map +2 -2
  20. package/dist/modules/shipping_carriers/lib/status-sync.js +8 -1
  21. package/dist/modules/shipping_carriers/lib/status-sync.js.map +2 -2
  22. package/dist/modules/workflows/components/NodeEditDialog.js +3 -1
  23. package/dist/modules/workflows/components/NodeEditDialog.js.map +2 -2
  24. package/dist/modules/workflows/components/WorkflowGraphImpl.js +4 -2
  25. package/dist/modules/workflows/components/WorkflowGraphImpl.js.map +2 -2
  26. package/dist/modules/workflows/components/nodes/ParallelForkNode.js +49 -0
  27. package/dist/modules/workflows/components/nodes/ParallelForkNode.js.map +7 -0
  28. package/dist/modules/workflows/components/nodes/ParallelJoinNode.js +49 -0
  29. package/dist/modules/workflows/components/nodes/ParallelJoinNode.js.map +7 -0
  30. package/dist/modules/workflows/components/nodes/index.js +4 -0
  31. package/dist/modules/workflows/components/nodes/index.js.map +2 -2
  32. package/dist/modules/workflows/data/entities.js +81 -0
  33. package/dist/modules/workflows/data/entities.js.map +2 -2
  34. package/dist/modules/workflows/data/validators.js +146 -1
  35. package/dist/modules/workflows/data/validators.js.map +2 -2
  36. package/dist/modules/workflows/events.js +7 -1
  37. package/dist/modules/workflows/events.js.map +2 -2
  38. package/dist/modules/workflows/lib/activity-executor.js +4 -2
  39. package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
  40. package/dist/modules/workflows/lib/activity-queue-types.js.map +2 -2
  41. package/dist/modules/workflows/lib/event-logger.js +2 -0
  42. package/dist/modules/workflows/lib/event-logger.js.map +2 -2
  43. package/dist/modules/workflows/lib/execution-token.js +98 -0
  44. package/dist/modules/workflows/lib/execution-token.js.map +7 -0
  45. package/dist/modules/workflows/lib/node-type-icons.js +14 -5
  46. package/dist/modules/workflows/lib/node-type-icons.js.map +2 -2
  47. package/dist/modules/workflows/lib/parallel-handler.js +364 -0
  48. package/dist/modules/workflows/lib/parallel-handler.js.map +7 -0
  49. package/dist/modules/workflows/lib/signal-handler.js +63 -1
  50. package/dist/modules/workflows/lib/signal-handler.js.map +2 -2
  51. package/dist/modules/workflows/lib/step-handler.js +74 -30
  52. package/dist/modules/workflows/lib/step-handler.js.map +2 -2
  53. package/dist/modules/workflows/lib/task-handler.js +26 -0
  54. package/dist/modules/workflows/lib/task-handler.js.map +2 -2
  55. package/dist/modules/workflows/lib/timer-handler.js +26 -1
  56. package/dist/modules/workflows/lib/timer-handler.js.map +2 -2
  57. package/dist/modules/workflows/lib/transition-handler.js +33 -21
  58. package/dist/modules/workflows/lib/transition-handler.js.map +2 -2
  59. package/dist/modules/workflows/lib/workflow-executor.js +39 -1
  60. package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
  61. package/dist/modules/workflows/migrations/Migration20260602120000.js +24 -0
  62. package/dist/modules/workflows/migrations/Migration20260602120000.js.map +7 -0
  63. package/dist/modules/workflows/workers/workflow-activities.worker.js +8 -4
  64. package/dist/modules/workflows/workers/workflow-activities.worker.js.map +2 -2
  65. package/generated/entities/step_instance/index.ts +1 -0
  66. package/generated/entities/user_task/index.ts +1 -0
  67. package/generated/entities/workflow_branch_instance/index.ts +18 -0
  68. package/generated/entities/workflow_event/index.ts +1 -0
  69. package/generated/entities/workflow_instance/index.ts +1 -0
  70. package/generated/entities.ids.generated.ts +1 -0
  71. package/generated/entity-fields-registry.ts +24 -0
  72. package/package.json +7 -7
  73. package/src/modules/progress/api/jobs/[id]/route.ts +7 -0
  74. package/src/modules/shipping_carriers/api/cancel/route.ts +2 -2
  75. package/src/modules/shipping_carriers/lib/status-sync.ts +19 -0
  76. package/src/modules/workflows/components/NodeEditDialog.tsx +2 -0
  77. package/src/modules/workflows/components/WorkflowGraphImpl.tsx +3 -1
  78. package/src/modules/workflows/components/nodes/ParallelForkNode.tsx +66 -0
  79. package/src/modules/workflows/components/nodes/ParallelJoinNode.tsx +66 -0
  80. package/src/modules/workflows/components/nodes/index.ts +6 -0
  81. package/src/modules/workflows/data/entities.ts +109 -0
  82. package/src/modules/workflows/data/validators.ts +223 -0
  83. package/src/modules/workflows/events.ts +7 -0
  84. package/src/modules/workflows/i18n/de.json +12 -0
  85. package/src/modules/workflows/i18n/en.json +12 -0
  86. package/src/modules/workflows/i18n/es.json +12 -0
  87. package/src/modules/workflows/i18n/pl.json +12 -0
  88. package/src/modules/workflows/lib/activity-executor.ts +8 -2
  89. package/src/modules/workflows/lib/activity-queue-types.ts +3 -0
  90. package/src/modules/workflows/lib/event-logger.ts +3 -0
  91. package/src/modules/workflows/lib/execution-token.ts +166 -0
  92. package/src/modules/workflows/lib/node-type-icons.ts +11 -2
  93. package/src/modules/workflows/lib/parallel-handler.ts +575 -0
  94. package/src/modules/workflows/lib/signal-handler.ts +72 -1
  95. package/src/modules/workflows/lib/step-handler.ts +94 -34
  96. package/src/modules/workflows/lib/task-handler.ts +32 -0
  97. package/src/modules/workflows/lib/timer-handler.ts +30 -1
  98. package/src/modules/workflows/lib/transition-handler.ts +56 -24
  99. package/src/modules/workflows/lib/workflow-executor.ts +53 -1
  100. package/src/modules/workflows/migrations/.snapshot-open-mercato.json +263 -0
  101. package/src/modules/workflows/migrations/Migration20260602120000.ts +25 -0
  102. package/src/modules/workflows/workers/workflow-activities.worker.ts +9 -4
@@ -168,6 +168,15 @@
168
168
  "nullable": false,
169
169
  "length": 6,
170
170
  "mappedType": "datetime"
171
+ },
172
+ "branch_instance_id": {
173
+ "name": "branch_instance_id",
174
+ "type": "uuid",
175
+ "unsigned": false,
176
+ "autoincrement": false,
177
+ "primary": false,
178
+ "nullable": true,
179
+ "mappedType": "uuid"
171
180
  }
172
181
  },
173
182
  "name": "step_instances",
@@ -433,6 +442,15 @@
433
442
  "nullable": false,
434
443
  "length": 6,
435
444
  "mappedType": "datetime"
445
+ },
446
+ "branch_instance_id": {
447
+ "name": "branch_instance_id",
448
+ "type": "uuid",
449
+ "unsigned": false,
450
+ "autoincrement": false,
451
+ "primary": false,
452
+ "nullable": true,
453
+ "mappedType": "uuid"
436
454
  }
437
455
  },
438
456
  "name": "user_tasks",
@@ -496,6 +514,232 @@
496
514
  "foreignKeys": {},
497
515
  "nativeEnums": {}
498
516
  },
517
+ {
518
+ "columns": {
519
+ "id": {
520
+ "name": "id",
521
+ "type": "uuid",
522
+ "unsigned": false,
523
+ "autoincrement": false,
524
+ "primary": false,
525
+ "nullable": false,
526
+ "default": "gen_random_uuid()",
527
+ "mappedType": "uuid"
528
+ },
529
+ "workflow_instance_id": {
530
+ "name": "workflow_instance_id",
531
+ "type": "uuid",
532
+ "unsigned": false,
533
+ "autoincrement": false,
534
+ "primary": false,
535
+ "nullable": false,
536
+ "mappedType": "uuid"
537
+ },
538
+ "fork_step_id": {
539
+ "name": "fork_step_id",
540
+ "type": "varchar(100)",
541
+ "unsigned": false,
542
+ "autoincrement": false,
543
+ "primary": false,
544
+ "nullable": false,
545
+ "length": 100,
546
+ "mappedType": "string"
547
+ },
548
+ "join_step_id": {
549
+ "name": "join_step_id",
550
+ "type": "varchar(100)",
551
+ "unsigned": false,
552
+ "autoincrement": false,
553
+ "primary": false,
554
+ "nullable": false,
555
+ "length": 100,
556
+ "mappedType": "string"
557
+ },
558
+ "branch_key": {
559
+ "name": "branch_key",
560
+ "type": "varchar(100)",
561
+ "unsigned": false,
562
+ "autoincrement": false,
563
+ "primary": false,
564
+ "nullable": false,
565
+ "length": 100,
566
+ "mappedType": "string"
567
+ },
568
+ "parent_branch_id": {
569
+ "name": "parent_branch_id",
570
+ "type": "uuid",
571
+ "unsigned": false,
572
+ "autoincrement": false,
573
+ "primary": false,
574
+ "nullable": true,
575
+ "mappedType": "uuid"
576
+ },
577
+ "current_step_id": {
578
+ "name": "current_step_id",
579
+ "type": "varchar(100)",
580
+ "unsigned": false,
581
+ "autoincrement": false,
582
+ "primary": false,
583
+ "nullable": false,
584
+ "length": 100,
585
+ "mappedType": "string"
586
+ },
587
+ "status": {
588
+ "name": "status",
589
+ "type": "varchar(30)",
590
+ "unsigned": false,
591
+ "autoincrement": false,
592
+ "primary": false,
593
+ "nullable": false,
594
+ "length": 30,
595
+ "mappedType": "string"
596
+ },
597
+ "context_namespace": {
598
+ "name": "context_namespace",
599
+ "type": "jsonb",
600
+ "unsigned": false,
601
+ "autoincrement": false,
602
+ "primary": false,
603
+ "nullable": false,
604
+ "mappedType": "json"
605
+ },
606
+ "pending_transition": {
607
+ "name": "pending_transition",
608
+ "type": "jsonb",
609
+ "unsigned": false,
610
+ "autoincrement": false,
611
+ "primary": false,
612
+ "nullable": true,
613
+ "mappedType": "json"
614
+ },
615
+ "error_message": {
616
+ "name": "error_message",
617
+ "type": "text",
618
+ "unsigned": false,
619
+ "autoincrement": false,
620
+ "primary": false,
621
+ "nullable": true,
622
+ "mappedType": "text"
623
+ },
624
+ "error_details": {
625
+ "name": "error_details",
626
+ "type": "jsonb",
627
+ "unsigned": false,
628
+ "autoincrement": false,
629
+ "primary": false,
630
+ "nullable": true,
631
+ "mappedType": "json"
632
+ },
633
+ "started_at": {
634
+ "name": "started_at",
635
+ "type": "timestamptz",
636
+ "unsigned": false,
637
+ "autoincrement": false,
638
+ "primary": false,
639
+ "nullable": true,
640
+ "length": 6,
641
+ "mappedType": "datetime"
642
+ },
643
+ "completed_at": {
644
+ "name": "completed_at",
645
+ "type": "timestamptz",
646
+ "unsigned": false,
647
+ "autoincrement": false,
648
+ "primary": false,
649
+ "nullable": true,
650
+ "length": 6,
651
+ "mappedType": "datetime"
652
+ },
653
+ "tenant_id": {
654
+ "name": "tenant_id",
655
+ "type": "uuid",
656
+ "unsigned": false,
657
+ "autoincrement": false,
658
+ "primary": false,
659
+ "nullable": false,
660
+ "mappedType": "uuid"
661
+ },
662
+ "organization_id": {
663
+ "name": "organization_id",
664
+ "type": "uuid",
665
+ "unsigned": false,
666
+ "autoincrement": false,
667
+ "primary": false,
668
+ "nullable": false,
669
+ "mappedType": "uuid"
670
+ },
671
+ "created_at": {
672
+ "name": "created_at",
673
+ "type": "timestamptz",
674
+ "unsigned": false,
675
+ "autoincrement": false,
676
+ "primary": false,
677
+ "nullable": false,
678
+ "length": 6,
679
+ "mappedType": "datetime"
680
+ },
681
+ "updated_at": {
682
+ "name": "updated_at",
683
+ "type": "timestamptz",
684
+ "unsigned": false,
685
+ "autoincrement": false,
686
+ "primary": false,
687
+ "nullable": false,
688
+ "length": 6,
689
+ "mappedType": "datetime"
690
+ }
691
+ },
692
+ "name": "workflow_branch_instances",
693
+ "schema": "public",
694
+ "indexes": [
695
+ {
696
+ "keyName": "workflow_branch_instances_tenant_org_idx",
697
+ "columnNames": [
698
+ "tenant_id",
699
+ "organization_id"
700
+ ],
701
+ "composite": true,
702
+ "constraint": false,
703
+ "primary": false,
704
+ "unique": false
705
+ },
706
+ {
707
+ "keyName": "workflow_branch_instances_instance_fork_idx",
708
+ "columnNames": [
709
+ "workflow_instance_id",
710
+ "fork_step_id"
711
+ ],
712
+ "composite": true,
713
+ "constraint": false,
714
+ "primary": false,
715
+ "unique": false
716
+ },
717
+ {
718
+ "keyName": "workflow_branch_instances_instance_status_idx",
719
+ "columnNames": [
720
+ "workflow_instance_id",
721
+ "status"
722
+ ],
723
+ "composite": true,
724
+ "constraint": false,
725
+ "primary": false,
726
+ "unique": false
727
+ },
728
+ {
729
+ "keyName": "workflow_branch_instances_pkey",
730
+ "columnNames": [
731
+ "id"
732
+ ],
733
+ "composite": false,
734
+ "constraint": true,
735
+ "primary": true,
736
+ "unique": true
737
+ }
738
+ ],
739
+ "checks": [],
740
+ "foreignKeys": {},
741
+ "nativeEnums": {}
742
+ },
499
743
  {
500
744
  "columns": {
501
745
  "id": {
@@ -819,6 +1063,15 @@
819
1063
  "primary": false,
820
1064
  "nullable": false,
821
1065
  "mappedType": "uuid"
1066
+ },
1067
+ "branch_instance_id": {
1068
+ "name": "branch_instance_id",
1069
+ "type": "uuid",
1070
+ "unsigned": false,
1071
+ "autoincrement": false,
1072
+ "primary": false,
1073
+ "nullable": true,
1074
+ "mappedType": "uuid"
822
1075
  }
823
1076
  },
824
1077
  "name": "workflow_events",
@@ -1293,6 +1546,16 @@
1293
1546
  "nullable": true,
1294
1547
  "length": 6,
1295
1548
  "mappedType": "datetime"
1549
+ },
1550
+ "active_fork_step_id": {
1551
+ "name": "active_fork_step_id",
1552
+ "type": "varchar(100)",
1553
+ "unsigned": false,
1554
+ "autoincrement": false,
1555
+ "primary": false,
1556
+ "nullable": true,
1557
+ "length": 100,
1558
+ "mappedType": "string"
1296
1559
  }
1297
1560
  },
1298
1561
  "name": "workflow_instances",
@@ -0,0 +1,25 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+
3
+ export class Migration20260602120000 extends Migration {
4
+
5
+ override async up(): Promise<void> {
6
+ this.addSql(`create table "workflow_branch_instances" ("id" uuid not null default gen_random_uuid(), "workflow_instance_id" uuid not null, "fork_step_id" varchar(100) not null, "join_step_id" varchar(100) not null, "branch_key" varchar(100) not null, "parent_branch_id" uuid null, "current_step_id" varchar(100) not null, "status" varchar(30) not null, "context_namespace" jsonb not null, "pending_transition" jsonb null, "error_message" text null, "error_details" jsonb null, "started_at" timestamptz null, "completed_at" timestamptz null, "tenant_id" uuid not null, "organization_id" uuid not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "workflow_branch_instances_pkey" primary key ("id"));`);
7
+ this.addSql(`create index "workflow_branch_instances_tenant_org_idx" on "workflow_branch_instances" ("tenant_id", "organization_id");`);
8
+ this.addSql(`create index "workflow_branch_instances_instance_fork_idx" on "workflow_branch_instances" ("workflow_instance_id", "fork_step_id");`);
9
+ this.addSql(`create index "workflow_branch_instances_instance_status_idx" on "workflow_branch_instances" ("workflow_instance_id", "status");`);
10
+
11
+ this.addSql(`alter table "workflow_instances" add column "active_fork_step_id" varchar(100) null;`);
12
+ this.addSql(`alter table "step_instances" add column "branch_instance_id" uuid null;`);
13
+ this.addSql(`alter table "user_tasks" add column "branch_instance_id" uuid null;`);
14
+ this.addSql(`alter table "workflow_events" add column "branch_instance_id" uuid null;`);
15
+ }
16
+
17
+ override async down(): Promise<void> {
18
+ this.addSql(`alter table "workflow_events" drop column "branch_instance_id";`);
19
+ this.addSql(`alter table "user_tasks" drop column "branch_instance_id";`);
20
+ this.addSql(`alter table "step_instances" drop column "branch_instance_id";`);
21
+ this.addSql(`alter table "workflow_instances" drop column "active_fork_step_id";`);
22
+ this.addSql(`drop table if exists "workflow_branch_instances" cascade;`);
23
+ }
24
+
25
+ }
@@ -77,6 +77,7 @@ export default async function handle(
77
77
  await fireTimer(em, container, {
78
78
  instanceId: payload.workflowInstanceId,
79
79
  stepInstanceId: payload.stepInstanceId,
80
+ branchInstanceId: payload.branchInstanceId,
80
81
  tenantId: payload.tenantId,
81
82
  organizationId: payload.organizationId,
82
83
  userId: payload.userId,
@@ -108,6 +109,7 @@ export default async function handle(
108
109
  workflowContext: payload.workflowContext,
109
110
  stepContext: payload.stepContext,
110
111
  stepInstanceId: payload.stepInstanceId,
112
+ branchInstanceId: payload.branchInstanceId,
111
113
  userId: payload.userId,
112
114
  }
113
115
 
@@ -177,6 +179,7 @@ export default async function handle(
177
179
  await logWorkflowEvent(em, {
178
180
  workflowInstanceId: payload.workflowInstanceId,
179
181
  stepInstanceId: payload.stepInstanceId,
182
+ branchInstanceId: payload.branchInstanceId,
180
183
  eventType: 'ACTIVITY_COMPLETED',
181
184
  eventData: {
182
185
  activityId: payload.activityId,
@@ -198,7 +201,7 @@ export default async function handle(
198
201
  )
199
202
 
200
203
  // Attempt to resume workflow if all activities complete
201
- await checkAndResumeWorkflow(em, ctx, payload.workflowInstanceId)
204
+ await checkAndResumeWorkflow(em, ctx, payload.workflowInstanceId, payload.branchInstanceId)
202
205
  } catch (error: any) {
203
206
  const executionTimeMs = Date.now() - startTime
204
207
 
@@ -211,6 +214,7 @@ export default async function handle(
211
214
  await logWorkflowEvent(em, {
212
215
  workflowInstanceId: payload.workflowInstanceId,
213
216
  stepInstanceId: payload.stepInstanceId,
217
+ branchInstanceId: payload.branchInstanceId,
214
218
  eventType: 'ACTIVITY_FAILED',
215
219
  eventData: {
216
220
  activityId: payload.activityId,
@@ -235,7 +239,7 @@ export default async function handle(
235
239
  `[workflows:activity-worker] Activity ${payload.activityId} (${payload.activityType}) failed after ${maxAttempts} attempts for workflow instance ${payload.workflowInstanceId} - triggering workflow failure handling`
236
240
  )
237
241
  // Final failure - attempt to resume workflow (may transition to FAILED state)
238
- await checkAndResumeWorkflow(em, ctx, payload.workflowInstanceId)
242
+ await checkAndResumeWorkflow(em, ctx, payload.workflowInstanceId, payload.branchInstanceId)
239
243
  }
240
244
 
241
245
  // Re-throw to let BullMQ handle retry logic
@@ -256,7 +260,8 @@ export default async function handle(
256
260
  async function checkAndResumeWorkflow(
257
261
  em: EntityManager,
258
262
  ctx: HandlerContext,
259
- workflowInstanceId: string
263
+ workflowInstanceId: string,
264
+ branchInstanceId?: string | null
260
265
  ): Promise<void> {
261
266
  // Import here to avoid circular dependency
262
267
  const { resumeWorkflowAfterActivities } = await import('../lib/workflow-executor')
@@ -265,7 +270,7 @@ async function checkAndResumeWorkflow(
265
270
  const container = ctx as unknown as AwilixContainer
266
271
 
267
272
  try {
268
- await resumeWorkflowAfterActivities(em, container, workflowInstanceId)
273
+ await resumeWorkflowAfterActivities(em, container, workflowInstanceId, branchInstanceId)
269
274
  } catch (error: any) {
270
275
  // Ignore error if workflow not ready to resume yet (activities still pending)
271
276
  if (!error.message?.includes('Activities still pending')) {