@open-mercato/core 0.4.2-canary-15e78de280 → 0.4.2-canary-ed15f2e753
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/entities/workflow_event_trigger/index.js +33 -0
- package/dist/generated/entities/workflow_event_trigger/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +1 -0
- package/dist/generated/entities.ids.generated.js.map +2 -2
- package/dist/generated/entity-fields-registry.js +2 -0
- package/dist/generated/entity-fields-registry.js.map +2 -2
- package/dist/modules/auth/events.js +30 -0
- package/dist/modules/auth/events.js.map +7 -0
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js +145 -0
- package/dist/modules/business_rules/api/execute/[ruleId]/route.js.map +7 -0
- package/dist/modules/business_rules/data/validators.js +34 -0
- package/dist/modules/business_rules/data/validators.js.map +2 -2
- package/dist/modules/business_rules/index.js +21 -1
- package/dist/modules/business_rules/index.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-engine.js +182 -1
- package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
- package/dist/modules/catalog/events.js +34 -0
- package/dist/modules/catalog/events.js.map +7 -0
- package/dist/modules/customers/events.js +49 -0
- package/dist/modules/customers/events.js.map +7 -0
- package/dist/modules/directory/events.js +23 -0
- package/dist/modules/directory/events.js.map +7 -0
- package/dist/modules/sales/acl.js +1 -0
- package/dist/modules/sales/acl.js.map +2 -2
- package/dist/modules/sales/backend/sales/documents/[id]/page.js +12 -0
- package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +62 -0
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/events.js +63 -0
- package/dist/modules/sales/events.js.map +7 -0
- package/dist/modules/sales/lib/dictionaries.js +3 -0
- package/dist/modules/sales/lib/dictionaries.js.map +2 -2
- package/dist/modules/sales/lib/frontend/documentDataEvents.js +25 -0
- package/dist/modules/sales/lib/frontend/documentDataEvents.js.map +7 -0
- package/dist/modules/workflows/acl.js +2 -0
- package/dist/modules/workflows/acl.js.map +2 -2
- package/dist/modules/workflows/api/instances/route.js +18 -6
- package/dist/modules/workflows/api/instances/route.js.map +2 -2
- package/dist/modules/workflows/api/tasks/route.js +6 -1
- package/dist/modules/workflows/api/tasks/route.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.js +9 -1
- package/dist/modules/workflows/backend/definitions/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.js +24 -15
- package/dist/modules/workflows/backend/definitions/create/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/create/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/create/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js +150 -132
- package/dist/modules/workflows/backend/definitions/visual-editor/page.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js +1 -1
- package/dist/modules/workflows/backend/definitions/visual-editor/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/events/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/events/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/instances/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.js +1 -1
- package/dist/modules/workflows/backend/tasks/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js +2 -2
- package/dist/modules/workflows/backend/tasks/[id]/page.meta.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/page.js +5 -6
- package/dist/modules/workflows/backend/tasks/page.js.map +2 -2
- package/dist/modules/workflows/cli.js +81 -3
- package/dist/modules/workflows/cli.js.map +3 -3
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js +481 -0
- package/dist/modules/workflows/components/DefinitionTriggersEditor.js.map +7 -0
- package/dist/modules/workflows/components/EventTriggersEditor.js +553 -0
- package/dist/modules/workflows/components/EventTriggersEditor.js.map +7 -0
- package/dist/modules/workflows/data/entities.js +64 -1
- package/dist/modules/workflows/data/entities.js.map +2 -2
- package/dist/modules/workflows/data/validators.js +115 -0
- package/dist/modules/workflows/data/validators.js.map +2 -2
- package/dist/modules/workflows/events.js +38 -0
- package/dist/modules/workflows/events.js.map +7 -0
- package/dist/modules/workflows/examples/checkout-demo-definition.json +1 -5
- package/dist/modules/workflows/examples/order-approval-definition.json +257 -0
- package/dist/modules/workflows/examples/order-approval-guard-rules.json +32 -0
- package/dist/modules/workflows/lib/activity-executor.js +75 -13
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/event-trigger-service.js +308 -0
- package/dist/modules/workflows/lib/event-trigger-service.js.map +7 -0
- package/dist/modules/workflows/lib/graph-utils.js +71 -2
- package/dist/modules/workflows/lib/graph-utils.js.map +2 -2
- package/dist/modules/workflows/lib/seeds.js +22 -5
- package/dist/modules/workflows/lib/seeds.js.map +2 -2
- package/dist/modules/workflows/lib/start-validator.js +33 -23
- package/dist/modules/workflows/lib/start-validator.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +157 -45
- package/dist/modules/workflows/lib/transition-handler.js.map +3 -3
- package/dist/modules/workflows/migrations/Migration20260123143500.js +36 -0
- package/dist/modules/workflows/migrations/Migration20260123143500.js.map +7 -0
- package/dist/modules/workflows/subscribers/event-trigger.js +78 -0
- package/dist/modules/workflows/subscribers/event-trigger.js.map +7 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js +323 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.client.js.map +7 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js +17 -0
- package/dist/modules/workflows/widgets/injection/order-approval/widget.js.map +7 -0
- package/dist/modules/workflows/widgets/injection-table.js +19 -0
- package/dist/modules/workflows/widgets/injection-table.js.map +7 -0
- package/generated/entities/workflow_event_trigger/index.ts +15 -0
- package/generated/entities.ids.generated.ts +1 -0
- package/generated/entity-fields-registry.ts +2 -0
- package/package.json +2 -2
- package/src/modules/auth/events.ts +39 -0
- package/src/modules/business_rules/api/execute/[ruleId]/route.ts +163 -0
- package/src/modules/business_rules/data/validators.ts +40 -0
- package/src/modules/business_rules/index.ts +25 -0
- package/src/modules/business_rules/lib/rule-engine.ts +281 -1
- package/src/modules/catalog/events.ts +45 -0
- package/src/modules/customers/events.ts +63 -0
- package/src/modules/directory/events.ts +31 -0
- package/src/modules/sales/acl.ts +1 -0
- package/src/modules/sales/backend/sales/documents/[id]/page.tsx +16 -0
- package/src/modules/sales/commands/documents.ts +74 -1
- package/src/modules/sales/events.ts +82 -0
- package/src/modules/sales/lib/dictionaries.ts +3 -0
- package/src/modules/sales/lib/frontend/documentDataEvents.ts +28 -0
- package/src/modules/workflows/acl.ts +2 -0
- package/src/modules/workflows/api/__tests__/instances.route.test.ts +5 -2
- package/src/modules/workflows/api/instances/route.ts +21 -7
- package/src/modules/workflows/api/tasks/route.ts +7 -1
- package/src/modules/workflows/backend/definitions/[id]/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/[id]/page.tsx +9 -0
- package/src/modules/workflows/backend/definitions/create/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/create/page.tsx +9 -0
- package/src/modules/workflows/backend/definitions/visual-editor/page.meta.ts +1 -1
- package/src/modules/workflows/backend/definitions/visual-editor/page.tsx +21 -3
- package/src/modules/workflows/backend/events/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/events/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/instances/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.meta.ts +2 -2
- package/src/modules/workflows/backend/tasks/[id]/page.tsx +1 -1
- package/src/modules/workflows/backend/tasks/page.tsx +5 -6
- package/src/modules/workflows/cli.ts +111 -0
- package/src/modules/workflows/components/DefinitionTriggersEditor.tsx +581 -0
- package/src/modules/workflows/components/EventTriggersEditor.tsx +664 -0
- package/src/modules/workflows/data/entities.ts +124 -0
- package/src/modules/workflows/data/validators.ts +138 -0
- package/src/modules/workflows/events.ts +49 -0
- package/src/modules/workflows/examples/checkout-demo-definition.json +1 -5
- package/src/modules/workflows/examples/order-approval-definition.json +257 -0
- package/src/modules/workflows/examples/order-approval-guard-rules.json +32 -0
- package/src/modules/workflows/i18n/en.json +71 -0
- package/src/modules/workflows/lib/__tests__/activity-executor.test.ts +43 -36
- package/src/modules/workflows/lib/__tests__/transition-handler.test.ts +170 -90
- package/src/modules/workflows/lib/activity-executor.ts +129 -16
- package/src/modules/workflows/lib/event-trigger-service.ts +557 -0
- package/src/modules/workflows/lib/graph-utils.ts +117 -2
- package/src/modules/workflows/lib/seeds.ts +34 -8
- package/src/modules/workflows/lib/start-validator.ts +38 -28
- package/src/modules/workflows/lib/transition-handler.ts +208 -55
- package/src/modules/workflows/migrations/Migration20260123143500.ts +38 -0
- package/src/modules/workflows/subscribers/event-trigger.ts +109 -0
- package/src/modules/workflows/widgets/injection/order-approval/widget.client.tsx +446 -0
- package/src/modules/workflows/widgets/injection/order-approval/widget.ts +16 -0
- package/src/modules/workflows/widgets/injection-table.ts +21 -0
|
@@ -448,7 +448,30 @@ export async function executeEmitEvent(
|
|
|
448
448
|
/**
|
|
449
449
|
* UPDATE_ENTITY activity handler
|
|
450
450
|
*
|
|
451
|
-
* Updates an entity via
|
|
451
|
+
* Updates an entity via CommandBus for proper audit logging, undo support, and side effects.
|
|
452
|
+
*
|
|
453
|
+
* Config format:
|
|
454
|
+
* ```json
|
|
455
|
+
* {
|
|
456
|
+
* "commandId": "sales.documents.update",
|
|
457
|
+
* "input": {
|
|
458
|
+
* "id": "{{context.orderId}}",
|
|
459
|
+
* "statusEntryId": "{{context.approvedStatusId}}"
|
|
460
|
+
* }
|
|
461
|
+
* }
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* Alternative format with statusValue (auto-resolves to statusEntryId):
|
|
465
|
+
* ```json
|
|
466
|
+
* {
|
|
467
|
+
* "commandId": "sales.orders.update",
|
|
468
|
+
* "statusDictionary": "sales.order_status",
|
|
469
|
+
* "input": {
|
|
470
|
+
* "id": "{{context.id}}",
|
|
471
|
+
* "statusValue": "pending_approval"
|
|
472
|
+
* }
|
|
473
|
+
* }
|
|
474
|
+
* ```
|
|
452
475
|
*/
|
|
453
476
|
export async function executeUpdateEntity(
|
|
454
477
|
em: EntityManager,
|
|
@@ -456,29 +479,119 @@ export async function executeUpdateEntity(
|
|
|
456
479
|
context: ActivityContext,
|
|
457
480
|
container: AwilixContainer
|
|
458
481
|
): Promise<any> {
|
|
459
|
-
const {
|
|
482
|
+
const { commandId, input, statusDictionary } = config
|
|
483
|
+
|
|
484
|
+
if (!commandId) {
|
|
485
|
+
throw new Error('UPDATE_ENTITY requires "commandId" field (e.g., "sales.documents.update")')
|
|
486
|
+
}
|
|
460
487
|
|
|
461
|
-
if (!
|
|
462
|
-
throw new Error('UPDATE_ENTITY requires "
|
|
488
|
+
if (!input || typeof input !== 'object') {
|
|
489
|
+
throw new Error('UPDATE_ENTITY requires "input" object with entity data')
|
|
463
490
|
}
|
|
464
491
|
|
|
465
|
-
//
|
|
466
|
-
const
|
|
492
|
+
// Resolve CommandBus from container
|
|
493
|
+
const commandBus = container.resolve('commandBus') as any
|
|
467
494
|
|
|
468
|
-
if (!
|
|
469
|
-
throw new Error('
|
|
495
|
+
if (!commandBus || typeof commandBus.execute !== 'function') {
|
|
496
|
+
throw new Error('CommandBus not available in container')
|
|
470
497
|
}
|
|
471
498
|
|
|
472
|
-
//
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
499
|
+
// Prepare final input, resolving statusValue if provided
|
|
500
|
+
let finalInput = { ...input }
|
|
501
|
+
|
|
502
|
+
// If statusValue is provided with a statusDictionary, resolve it to statusEntryId
|
|
503
|
+
if (finalInput.statusValue && statusDictionary) {
|
|
504
|
+
const statusEntryId = await resolveDictionaryEntryId(
|
|
505
|
+
em,
|
|
506
|
+
statusDictionary,
|
|
507
|
+
finalInput.statusValue,
|
|
508
|
+
context.workflowInstance.tenantId,
|
|
509
|
+
context.workflowInstance.organizationId
|
|
510
|
+
)
|
|
511
|
+
if (statusEntryId) {
|
|
512
|
+
finalInput.statusEntryId = statusEntryId
|
|
513
|
+
}
|
|
514
|
+
delete finalInput.statusValue
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Build synthetic CommandRuntimeContext for workflow execution
|
|
518
|
+
// Use nil UUID for system actions when no user context is available
|
|
519
|
+
const SYSTEM_USER_ID = '00000000-0000-0000-0000-000000000000'
|
|
520
|
+
const ctx = {
|
|
521
|
+
container,
|
|
522
|
+
auth: {
|
|
523
|
+
sub: context.userId || SYSTEM_USER_ID,
|
|
524
|
+
tenantId: context.workflowInstance.tenantId,
|
|
525
|
+
orgId: context.workflowInstance.organizationId,
|
|
526
|
+
isSuperAdmin: false,
|
|
527
|
+
},
|
|
528
|
+
organizationScope: null,
|
|
529
|
+
selectedOrganizationId: context.workflowInstance.organizationId,
|
|
530
|
+
organizationIds: context.workflowInstance.organizationId
|
|
531
|
+
? [context.workflowInstance.organizationId]
|
|
532
|
+
: null,
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Execute the command
|
|
536
|
+
const { result, logEntry } = await commandBus.execute(commandId, {
|
|
537
|
+
input: finalInput,
|
|
538
|
+
ctx,
|
|
479
539
|
})
|
|
480
540
|
|
|
481
|
-
return {
|
|
541
|
+
return {
|
|
542
|
+
executed: true,
|
|
543
|
+
commandId,
|
|
544
|
+
result,
|
|
545
|
+
logEntryId: logEntry?.id,
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Helper to resolve dictionary entry ID by value
|
|
551
|
+
*/
|
|
552
|
+
async function resolveDictionaryEntryId(
|
|
553
|
+
em: EntityManager,
|
|
554
|
+
dictionaryKey: string,
|
|
555
|
+
value: string,
|
|
556
|
+
tenantId: string,
|
|
557
|
+
organizationId: string
|
|
558
|
+
): Promise<string | null> {
|
|
559
|
+
try {
|
|
560
|
+
// Import here to avoid circular dependencies
|
|
561
|
+
const { Dictionary, DictionaryEntry } = await import('@open-mercato/core/modules/dictionaries/data/entities')
|
|
562
|
+
|
|
563
|
+
// Find the dictionary
|
|
564
|
+
const dictionary = await em.findOne(Dictionary, {
|
|
565
|
+
key: dictionaryKey,
|
|
566
|
+
tenantId,
|
|
567
|
+
organizationId,
|
|
568
|
+
deletedAt: null,
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
if (!dictionary) {
|
|
572
|
+
console.warn(`[UPDATE_ENTITY] Dictionary not found: ${dictionaryKey}`)
|
|
573
|
+
return null
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Find the entry by normalized value
|
|
577
|
+
const normalizedValue = value.toLowerCase().trim()
|
|
578
|
+
const entry = await em.findOne(DictionaryEntry, {
|
|
579
|
+
dictionary: dictionary.id,
|
|
580
|
+
tenantId,
|
|
581
|
+
organizationId,
|
|
582
|
+
normalizedValue,
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
if (!entry) {
|
|
586
|
+
console.warn(`[UPDATE_ENTITY] Dictionary entry not found: ${dictionaryKey}/${value}`)
|
|
587
|
+
return null
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return entry.id
|
|
591
|
+
} catch (error) {
|
|
592
|
+
console.error(`[UPDATE_ENTITY] Error resolving dictionary entry:`, error)
|
|
593
|
+
return null
|
|
594
|
+
}
|
|
482
595
|
}
|
|
483
596
|
|
|
484
597
|
/**
|