@centrali-io/centrali-sdk 2.8.7 → 2.8.8
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/README.md +121 -0
- package/dist/index.js +356 -1
- package/index.ts +821 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@ const centrali = new CentraliSDK({
|
|
|
78
78
|
- ✅ **File uploads** - Upload files to Centrali storage
|
|
79
79
|
- ✅ **Data Validation** - AI-powered typo detection, format validation, duplicate detection
|
|
80
80
|
- ✅ **Anomaly Insights** - AI-powered anomaly detection and data quality insights
|
|
81
|
+
- ✅ **Orchestrations** - Multi-step workflows with compute functions, decision logic, and delays
|
|
81
82
|
- ✅ **Service accounts** - Automatic token refresh for server-to-server auth
|
|
82
83
|
|
|
83
84
|
## Core Operations
|
|
@@ -454,6 +455,126 @@ console.log('By severity:', summary.data.bySeverity);
|
|
|
454
455
|
| `orphaned_reference` | References to deleted or non-existent records |
|
|
455
456
|
| `reference_integrity` | Broken relationships between records |
|
|
456
457
|
|
|
458
|
+
### Orchestrations
|
|
459
|
+
|
|
460
|
+
Multi-step workflows that chain compute functions together with conditional logic, delays, and decision branches:
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
// List all orchestrations
|
|
464
|
+
const orchestrations = await centrali.orchestrations.list();
|
|
465
|
+
|
|
466
|
+
// Get an orchestration by ID
|
|
467
|
+
const orch = await centrali.orchestrations.get('orch-id');
|
|
468
|
+
console.log('Name:', orch.data.name);
|
|
469
|
+
console.log('Status:', orch.data.status);
|
|
470
|
+
console.log('Steps:', orch.data.steps.length);
|
|
471
|
+
|
|
472
|
+
// Create a new orchestration
|
|
473
|
+
const newOrch = await centrali.orchestrations.create({
|
|
474
|
+
slug: 'order-processing',
|
|
475
|
+
name: 'Order Processing Workflow',
|
|
476
|
+
trigger: { type: 'on-demand' },
|
|
477
|
+
steps: [
|
|
478
|
+
{
|
|
479
|
+
id: 'validate',
|
|
480
|
+
type: 'compute',
|
|
481
|
+
functionId: 'func_validate_order',
|
|
482
|
+
onSuccess: { nextStepId: 'check-result' }
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
id: 'check-result',
|
|
486
|
+
type: 'decision',
|
|
487
|
+
cases: [
|
|
488
|
+
{
|
|
489
|
+
conditions: [{ path: 'steps.validate.output.isValid', op: 'eq', value: true }],
|
|
490
|
+
nextStepId: 'fulfill'
|
|
491
|
+
}
|
|
492
|
+
],
|
|
493
|
+
defaultNextStepId: 'reject'
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
id: 'fulfill',
|
|
497
|
+
type: 'compute',
|
|
498
|
+
functionId: 'func_fulfill_order'
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
id: 'reject',
|
|
502
|
+
type: 'compute',
|
|
503
|
+
functionId: 'func_reject_order'
|
|
504
|
+
}
|
|
505
|
+
]
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// Trigger an orchestration run
|
|
509
|
+
const run = await centrali.orchestrations.trigger('orch-id', {
|
|
510
|
+
input: {
|
|
511
|
+
orderId: '12345',
|
|
512
|
+
customerId: 'cust_abc'
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
console.log('Run started:', run.data.id);
|
|
516
|
+
console.log('Status:', run.data.status);
|
|
517
|
+
|
|
518
|
+
// Get run status
|
|
519
|
+
const runStatus = await centrali.orchestrations.getRun('orch-id', run.data.id);
|
|
520
|
+
console.log('Current step:', runStatus.data.currentStepId);
|
|
521
|
+
console.log('Has errors:', runStatus.data.hasErrors);
|
|
522
|
+
|
|
523
|
+
// Get run with step history
|
|
524
|
+
const runWithSteps = await centrali.orchestrations.getRun('orch-id', run.data.id, true);
|
|
525
|
+
for (const step of runWithSteps.data.steps || []) {
|
|
526
|
+
console.log(`${step.stepId}: ${step.status}`);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// List runs for an orchestration
|
|
530
|
+
const runs = await centrali.orchestrations.listRuns('orch-id', {
|
|
531
|
+
status: 'completed', // Filter by status
|
|
532
|
+
limit: 10
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// Activate an orchestration (enables scheduled/event triggers)
|
|
536
|
+
await centrali.orchestrations.activate('orch-id');
|
|
537
|
+
|
|
538
|
+
// Pause an orchestration (disables all triggers)
|
|
539
|
+
await centrali.orchestrations.pause('orch-id');
|
|
540
|
+
|
|
541
|
+
// Update an orchestration
|
|
542
|
+
await centrali.orchestrations.update('orch-id', {
|
|
543
|
+
name: 'Updated Name',
|
|
544
|
+
status: 'active'
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
// Delete an orchestration
|
|
548
|
+
await centrali.orchestrations.delete('orch-id');
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
#### Trigger Types
|
|
552
|
+
|
|
553
|
+
| Type | Description |
|
|
554
|
+
|------|-------------|
|
|
555
|
+
| `on-demand` | Manual invocation via API |
|
|
556
|
+
| `event-driven` | React to record events (created, updated, deleted) |
|
|
557
|
+
| `scheduled` | Run on a schedule (cron, interval, or once) |
|
|
558
|
+
| `http-trigger` | External webhook endpoint |
|
|
559
|
+
|
|
560
|
+
#### Step Types
|
|
561
|
+
|
|
562
|
+
| Type | Description |
|
|
563
|
+
|------|-------------|
|
|
564
|
+
| `compute` | Execute a compute function |
|
|
565
|
+
| `decision` | Branch based on conditions |
|
|
566
|
+
| `delay` | Wait for a duration |
|
|
567
|
+
|
|
568
|
+
#### Run Statuses
|
|
569
|
+
|
|
570
|
+
| Status | Description |
|
|
571
|
+
|--------|-------------|
|
|
572
|
+
| `pending` | Run is queued |
|
|
573
|
+
| `running` | Run is executing |
|
|
574
|
+
| `waiting` | Run is waiting (delay step) |
|
|
575
|
+
| `completed` | Run finished successfully |
|
|
576
|
+
| `failed` | Run failed with error |
|
|
577
|
+
|
|
457
578
|
## TypeScript Support
|
|
458
579
|
|
|
459
580
|
The SDK includes full TypeScript definitions for type-safe development:
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.CentraliSDK = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.RealtimeManager = void 0;
|
|
21
|
+
exports.CentraliSDK = exports.ValidationManager = exports.AnomalyInsightsManager = exports.SmartQueriesManager = exports.TriggersManager = exports.OrchestrationsManager = exports.RealtimeManager = void 0;
|
|
22
22
|
exports.getApiUrl = getApiUrl;
|
|
23
23
|
exports.getAuthUrl = getAuthUrl;
|
|
24
24
|
exports.getRealtimeUrl = getRealtimeUrl;
|
|
@@ -50,6 +50,9 @@ exports.getValidationSummaryApiPath = getValidationSummaryApiPath;
|
|
|
50
50
|
exports.getValidationRecordSuggestionsApiPath = getValidationRecordSuggestionsApiPath;
|
|
51
51
|
exports.getValidationPendingCountApiPath = getValidationPendingCountApiPath;
|
|
52
52
|
exports.getValidationScanApiPath = getValidationScanApiPath;
|
|
53
|
+
exports.getOrchestrationsApiPath = getOrchestrationsApiPath;
|
|
54
|
+
exports.getOrchestrationRunsApiPath = getOrchestrationRunsApiPath;
|
|
55
|
+
exports.getOrchestrationRunStepsApiPath = getOrchestrationRunStepsApiPath;
|
|
53
56
|
const axios_1 = __importDefault(require("axios"));
|
|
54
57
|
const qs_1 = __importDefault(require("qs"));
|
|
55
58
|
const eventsource_1 = require("eventsource");
|
|
@@ -512,6 +515,320 @@ function getValidationScanApiPath(workspaceId, batchId) {
|
|
|
512
515
|
return batchId ? `${basePath}/${batchId}` : basePath;
|
|
513
516
|
}
|
|
514
517
|
// =====================================================
|
|
518
|
+
// Orchestration API Paths
|
|
519
|
+
// =====================================================
|
|
520
|
+
/**
|
|
521
|
+
* Generate Orchestrations API URL PATH.
|
|
522
|
+
* Routes to the orchestration service.
|
|
523
|
+
*/
|
|
524
|
+
function getOrchestrationsApiPath(workspaceId, orchestrationId) {
|
|
525
|
+
const basePath = `orchestration/ws/${workspaceId}/api/v1/orchestrations`;
|
|
526
|
+
return orchestrationId ? `${basePath}/${orchestrationId}` : basePath;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Generate Orchestration Runs API URL PATH.
|
|
530
|
+
*/
|
|
531
|
+
function getOrchestrationRunsApiPath(workspaceId, orchestrationId, runId) {
|
|
532
|
+
const basePath = `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs`;
|
|
533
|
+
return runId ? `${basePath}/${runId}` : basePath;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Generate Orchestration Run Steps API URL PATH.
|
|
537
|
+
*/
|
|
538
|
+
function getOrchestrationRunStepsApiPath(workspaceId, orchestrationId, runId) {
|
|
539
|
+
return `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs/${runId}/steps`;
|
|
540
|
+
}
|
|
541
|
+
// =====================================================
|
|
542
|
+
// Orchestrations Manager
|
|
543
|
+
// =====================================================
|
|
544
|
+
/**
|
|
545
|
+
* OrchestrationsManager provides methods for managing orchestrations and triggering runs.
|
|
546
|
+
* Access via `client.orchestrations`.
|
|
547
|
+
*
|
|
548
|
+
* Orchestrations are multi-step workflows that chain compute functions together
|
|
549
|
+
* with conditional logic, delays, and decision branches.
|
|
550
|
+
*
|
|
551
|
+
* Usage:
|
|
552
|
+
* ```ts
|
|
553
|
+
* // List all orchestrations
|
|
554
|
+
* const orchestrations = await client.orchestrations.list();
|
|
555
|
+
*
|
|
556
|
+
* // Get an orchestration by ID
|
|
557
|
+
* const orch = await client.orchestrations.get('orch-id');
|
|
558
|
+
*
|
|
559
|
+
* // Trigger an on-demand orchestration
|
|
560
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
561
|
+
* input: { orderId: '12345' }
|
|
562
|
+
* });
|
|
563
|
+
*
|
|
564
|
+
* // Get run status
|
|
565
|
+
* const runStatus = await client.orchestrations.getRun('orch-id', run.data.id);
|
|
566
|
+
*
|
|
567
|
+
* // List runs for an orchestration
|
|
568
|
+
* const runs = await client.orchestrations.listRuns('orch-id');
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
class OrchestrationsManager {
|
|
572
|
+
constructor(workspaceId, requestFn) {
|
|
573
|
+
this.workspaceId = workspaceId;
|
|
574
|
+
this.requestFn = requestFn;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* List all orchestrations in the workspace.
|
|
578
|
+
*
|
|
579
|
+
* @param options - Optional pagination and filtering options
|
|
580
|
+
* @returns Paginated list of orchestrations
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* // List all orchestrations
|
|
585
|
+
* const result = await client.orchestrations.list();
|
|
586
|
+
* console.log('Total:', result.data.meta.total);
|
|
587
|
+
*
|
|
588
|
+
* // With pagination and status filter
|
|
589
|
+
* const result = await client.orchestrations.list({
|
|
590
|
+
* limit: 10,
|
|
591
|
+
* offset: 0,
|
|
592
|
+
* status: 'active'
|
|
593
|
+
* });
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
596
|
+
list(options) {
|
|
597
|
+
const path = getOrchestrationsApiPath(this.workspaceId);
|
|
598
|
+
return this.requestFn('GET', path, null, options);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Get an orchestration by ID.
|
|
602
|
+
*
|
|
603
|
+
* @param orchestrationId - The orchestration ID
|
|
604
|
+
* @returns The orchestration details including all steps
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```ts
|
|
608
|
+
* const orch = await client.orchestrations.get('orch-id');
|
|
609
|
+
* console.log('Name:', orch.data.name);
|
|
610
|
+
* console.log('Steps:', orch.data.steps.length);
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
get(orchestrationId) {
|
|
614
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
615
|
+
return this.requestFn('GET', path);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Create a new orchestration.
|
|
619
|
+
*
|
|
620
|
+
* @param input - The orchestration definition
|
|
621
|
+
* @returns The created orchestration
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* const orch = await client.orchestrations.create({
|
|
626
|
+
* slug: 'order-processing',
|
|
627
|
+
* name: 'Order Processing Workflow',
|
|
628
|
+
* trigger: { type: 'on-demand' },
|
|
629
|
+
* steps: [
|
|
630
|
+
* {
|
|
631
|
+
* id: 'validate',
|
|
632
|
+
* type: 'compute',
|
|
633
|
+
* functionId: 'func_validate',
|
|
634
|
+
* onSuccess: { nextStepId: 'process' }
|
|
635
|
+
* },
|
|
636
|
+
* {
|
|
637
|
+
* id: 'process',
|
|
638
|
+
* type: 'compute',
|
|
639
|
+
* functionId: 'func_process'
|
|
640
|
+
* }
|
|
641
|
+
* ]
|
|
642
|
+
* });
|
|
643
|
+
* ```
|
|
644
|
+
*/
|
|
645
|
+
create(input) {
|
|
646
|
+
const path = getOrchestrationsApiPath(this.workspaceId);
|
|
647
|
+
return this.requestFn('POST', path, input);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Update an existing orchestration.
|
|
651
|
+
*
|
|
652
|
+
* Updates increment the orchestration version. Running instances use the
|
|
653
|
+
* version at the time they started.
|
|
654
|
+
*
|
|
655
|
+
* @param orchestrationId - The orchestration ID
|
|
656
|
+
* @param input - Fields to update
|
|
657
|
+
* @returns The updated orchestration
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* // Activate an orchestration
|
|
662
|
+
* await client.orchestrations.update('orch-id', { status: 'active' });
|
|
663
|
+
*
|
|
664
|
+
* // Update steps
|
|
665
|
+
* await client.orchestrations.update('orch-id', {
|
|
666
|
+
* steps: [...]
|
|
667
|
+
* });
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
update(orchestrationId, input) {
|
|
671
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
672
|
+
return this.requestFn('PUT', path, input);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Delete an orchestration.
|
|
676
|
+
*
|
|
677
|
+
* This also deletes all runs associated with the orchestration.
|
|
678
|
+
*
|
|
679
|
+
* @param orchestrationId - The orchestration ID
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* await client.orchestrations.delete('orch-id');
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
686
|
+
delete(orchestrationId) {
|
|
687
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
688
|
+
return this.requestFn('DELETE', path);
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Trigger an orchestration run.
|
|
692
|
+
*
|
|
693
|
+
* This creates a new run instance and starts executing the workflow.
|
|
694
|
+
* Can be used on on-demand, draft, or active orchestrations.
|
|
695
|
+
* Paused orchestrations cannot be triggered.
|
|
696
|
+
*
|
|
697
|
+
* @param orchestrationId - The orchestration ID
|
|
698
|
+
* @param options - Optional input data and correlation ID
|
|
699
|
+
* @returns The created run
|
|
700
|
+
*
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* // Simple trigger
|
|
704
|
+
* const run = await client.orchestrations.trigger('orch-id');
|
|
705
|
+
*
|
|
706
|
+
* // With input data
|
|
707
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
708
|
+
* input: {
|
|
709
|
+
* orderId: '12345',
|
|
710
|
+
* customerId: 'cust_abc'
|
|
711
|
+
* }
|
|
712
|
+
* });
|
|
713
|
+
*
|
|
714
|
+
* // With correlation ID for tracing
|
|
715
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
716
|
+
* input: { orderId: '12345' },
|
|
717
|
+
* correlationId: 'req-123'
|
|
718
|
+
* });
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
trigger(orchestrationId, options) {
|
|
722
|
+
var _a;
|
|
723
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId);
|
|
724
|
+
const body = {
|
|
725
|
+
input: (_a = options === null || options === void 0 ? void 0 : options.input) !== null && _a !== void 0 ? _a : {},
|
|
726
|
+
correlationId: options === null || options === void 0 ? void 0 : options.correlationId
|
|
727
|
+
};
|
|
728
|
+
return this.requestFn('POST', path, body);
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* List runs for an orchestration.
|
|
732
|
+
*
|
|
733
|
+
* @param orchestrationId - The orchestration ID
|
|
734
|
+
* @param options - Optional pagination and filtering options
|
|
735
|
+
* @returns Paginated list of runs
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* ```ts
|
|
739
|
+
* // List all runs
|
|
740
|
+
* const runs = await client.orchestrations.listRuns('orch-id');
|
|
741
|
+
*
|
|
742
|
+
* // Filter by status
|
|
743
|
+
* const failedRuns = await client.orchestrations.listRuns('orch-id', {
|
|
744
|
+
* status: 'failed'
|
|
745
|
+
* });
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
listRuns(orchestrationId, options) {
|
|
749
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId);
|
|
750
|
+
return this.requestFn('GET', path, null, options);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Get a specific run by ID.
|
|
754
|
+
*
|
|
755
|
+
* @param orchestrationId - The orchestration ID
|
|
756
|
+
* @param runId - The run ID
|
|
757
|
+
* @param includeSteps - Whether to include step execution history
|
|
758
|
+
* @returns The run details
|
|
759
|
+
*
|
|
760
|
+
* @example
|
|
761
|
+
* ```ts
|
|
762
|
+
* // Get basic run info
|
|
763
|
+
* const run = await client.orchestrations.getRun('orch-id', 'run-id');
|
|
764
|
+
* console.log('Status:', run.data.status);
|
|
765
|
+
*
|
|
766
|
+
* // Include step history
|
|
767
|
+
* const run = await client.orchestrations.getRun('orch-id', 'run-id', true);
|
|
768
|
+
* console.log('Steps:', run.data.steps);
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
771
|
+
getRun(orchestrationId, runId, includeSteps) {
|
|
772
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId, runId);
|
|
773
|
+
const params = includeSteps ? { include: 'steps' } : undefined;
|
|
774
|
+
return this.requestFn('GET', path, null, params);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Get step execution history for a run.
|
|
778
|
+
*
|
|
779
|
+
* @param orchestrationId - The orchestration ID
|
|
780
|
+
* @param runId - The run ID
|
|
781
|
+
* @returns List of step executions
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```ts
|
|
785
|
+
* const steps = await client.orchestrations.getRunSteps('orch-id', 'run-id');
|
|
786
|
+
* for (const step of steps.data.data) {
|
|
787
|
+
* console.log(`${step.stepId}: ${step.status}`);
|
|
788
|
+
* }
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
getRunSteps(orchestrationId, runId) {
|
|
792
|
+
const path = getOrchestrationRunStepsApiPath(this.workspaceId, orchestrationId, runId);
|
|
793
|
+
return this.requestFn('GET', path);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Activate an orchestration.
|
|
797
|
+
*
|
|
798
|
+
* Convenience method to set status to 'active'.
|
|
799
|
+
* Active orchestrations can be triggered by scheduled events, record events, and webhooks.
|
|
800
|
+
*
|
|
801
|
+
* @param orchestrationId - The orchestration ID
|
|
802
|
+
* @returns The updated orchestration
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* ```ts
|
|
806
|
+
* await client.orchestrations.activate('orch-id');
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
activate(orchestrationId) {
|
|
810
|
+
return this.update(orchestrationId, { status: 'active' });
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Pause an orchestration.
|
|
814
|
+
*
|
|
815
|
+
* Convenience method to set status to 'paused'.
|
|
816
|
+
* Paused orchestrations cannot be triggered by any mechanism.
|
|
817
|
+
*
|
|
818
|
+
* @param orchestrationId - The orchestration ID
|
|
819
|
+
* @returns The updated orchestration
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```ts
|
|
823
|
+
* await client.orchestrations.pause('orch-id');
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
pause(orchestrationId) {
|
|
827
|
+
return this.update(orchestrationId, { status: 'paused' });
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
exports.OrchestrationsManager = OrchestrationsManager;
|
|
831
|
+
// =====================================================
|
|
515
832
|
// Triggers Manager
|
|
516
833
|
// =====================================================
|
|
517
834
|
/**
|
|
@@ -1222,6 +1539,7 @@ class CentraliSDK {
|
|
|
1222
1539
|
this._smartQueries = null;
|
|
1223
1540
|
this._anomalyInsights = null;
|
|
1224
1541
|
this._validation = null;
|
|
1542
|
+
this._orchestrations = null;
|
|
1225
1543
|
this.options = options;
|
|
1226
1544
|
this.token = options.token || null;
|
|
1227
1545
|
const apiUrl = getApiUrl(options.baseUrl);
|
|
@@ -1392,6 +1710,43 @@ class CentraliSDK {
|
|
|
1392
1710
|
}
|
|
1393
1711
|
return this._validation;
|
|
1394
1712
|
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Orchestrations namespace for managing multi-step workflows.
|
|
1715
|
+
*
|
|
1716
|
+
* Orchestrations chain compute functions together with conditional logic,
|
|
1717
|
+
* delays, and decision branches to automate complex business processes.
|
|
1718
|
+
*
|
|
1719
|
+
* Usage:
|
|
1720
|
+
* ```ts
|
|
1721
|
+
* // List all orchestrations
|
|
1722
|
+
* const orchestrations = await client.orchestrations.list();
|
|
1723
|
+
*
|
|
1724
|
+
* // Trigger an on-demand orchestration
|
|
1725
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
1726
|
+
* input: { orderId: '12345' }
|
|
1727
|
+
* });
|
|
1728
|
+
*
|
|
1729
|
+
* // Get run status
|
|
1730
|
+
* const runStatus = await client.orchestrations.getRun('orch-id', run.data.id);
|
|
1731
|
+
*
|
|
1732
|
+
* // Create a new orchestration
|
|
1733
|
+
* const orch = await client.orchestrations.create({
|
|
1734
|
+
* slug: 'order-processing',
|
|
1735
|
+
* name: 'Order Processing',
|
|
1736
|
+
* trigger: { type: 'on-demand' },
|
|
1737
|
+
* steps: [
|
|
1738
|
+
* { id: 'validate', type: 'compute', functionId: 'func_validate', onSuccess: { nextStepId: 'process' } },
|
|
1739
|
+
* { id: 'process', type: 'compute', functionId: 'func_process' }
|
|
1740
|
+
* ]
|
|
1741
|
+
* });
|
|
1742
|
+
* ```
|
|
1743
|
+
*/
|
|
1744
|
+
get orchestrations() {
|
|
1745
|
+
if (!this._orchestrations) {
|
|
1746
|
+
this._orchestrations = new OrchestrationsManager(this.options.workspaceId, this.request.bind(this));
|
|
1747
|
+
}
|
|
1748
|
+
return this._orchestrations;
|
|
1749
|
+
}
|
|
1395
1750
|
/**
|
|
1396
1751
|
* Manually set or update the bearer token for subsequent requests.
|
|
1397
1752
|
*/
|
package/index.ts
CHANGED
|
@@ -545,6 +545,450 @@ export interface DeleteRecordOptions {
|
|
|
545
545
|
*/
|
|
546
546
|
export type TriggerInvokeResponse = string;
|
|
547
547
|
|
|
548
|
+
// =====================================================
|
|
549
|
+
// Orchestration Types
|
|
550
|
+
// =====================================================
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Orchestration trigger types.
|
|
554
|
+
*/
|
|
555
|
+
export type OrchestrationTriggerType = 'event-driven' | 'scheduled' | 'on-demand' | 'http-trigger';
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Schedule types for scheduled orchestrations.
|
|
559
|
+
*/
|
|
560
|
+
export type OrchestrationScheduleType = 'interval' | 'cron' | 'once';
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Orchestration lifecycle status.
|
|
564
|
+
*/
|
|
565
|
+
export type OrchestrationStatus = 'draft' | 'active' | 'paused';
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Orchestration run status.
|
|
569
|
+
*/
|
|
570
|
+
export type OrchestrationRunStatus = 'pending' | 'running' | 'waiting' | 'completed' | 'failed';
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Orchestration step types.
|
|
574
|
+
*/
|
|
575
|
+
export type OrchestrationStepType = 'compute' | 'decision' | 'delay';
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Run step status.
|
|
579
|
+
*/
|
|
580
|
+
export type OrchestrationStepStatus = 'pending' | 'running' | 'waiting' | 'succeeded' | 'failed';
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Condition operators for decision steps.
|
|
584
|
+
*/
|
|
585
|
+
export type ConditionOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists' | 'notExists' | 'in' | 'notIn';
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Orchestration trigger configuration.
|
|
589
|
+
*/
|
|
590
|
+
export interface OrchestrationTrigger {
|
|
591
|
+
/** Trigger type */
|
|
592
|
+
type: OrchestrationTriggerType;
|
|
593
|
+
|
|
594
|
+
// Event-driven trigger config
|
|
595
|
+
/** Event type for event-driven triggers */
|
|
596
|
+
eventType?: string;
|
|
597
|
+
/** Structure slug to watch */
|
|
598
|
+
structureSlug?: string;
|
|
599
|
+
|
|
600
|
+
// Scheduled trigger config
|
|
601
|
+
/** Schedule type for scheduled triggers */
|
|
602
|
+
scheduleType?: OrchestrationScheduleType;
|
|
603
|
+
/** Interval in seconds (for interval type) */
|
|
604
|
+
interval?: number;
|
|
605
|
+
/** Cron expression (for cron type) */
|
|
606
|
+
cronExpression?: string;
|
|
607
|
+
/** ISO datetime (for once type) */
|
|
608
|
+
scheduledAt?: string;
|
|
609
|
+
/** IANA timezone (default: UTC) */
|
|
610
|
+
timezone?: string;
|
|
611
|
+
|
|
612
|
+
// HTTP trigger config
|
|
613
|
+
/** Webhook path */
|
|
614
|
+
path?: string;
|
|
615
|
+
/** Whether to validate HMAC signature */
|
|
616
|
+
validateSignature?: boolean;
|
|
617
|
+
/** Signing secret for HMAC validation */
|
|
618
|
+
signingSecret?: string;
|
|
619
|
+
/** Header name for signature */
|
|
620
|
+
signatureHeaderName?: string;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Retry configuration for compute steps.
|
|
625
|
+
*/
|
|
626
|
+
export interface OrchestrationRetryConfig {
|
|
627
|
+
/** Maximum retry attempts */
|
|
628
|
+
maxAttempts: number;
|
|
629
|
+
/** Backoff delay in milliseconds */
|
|
630
|
+
backoffMs: number;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* On success configuration for compute steps.
|
|
635
|
+
*/
|
|
636
|
+
export interface OrchestrationOnSuccess {
|
|
637
|
+
/** Next step ID to execute on success */
|
|
638
|
+
nextStepId?: string;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* On failure configuration for compute steps.
|
|
643
|
+
*/
|
|
644
|
+
export interface OrchestrationOnFailure {
|
|
645
|
+
/** Action to take on failure: 'fail' or 'end' */
|
|
646
|
+
action: 'fail' | 'end';
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Condition in a decision case.
|
|
651
|
+
*/
|
|
652
|
+
export interface OrchestrationCondition {
|
|
653
|
+
/** Path to evaluate (e.g., 'input.data.status', 'steps.validate.output.isValid') */
|
|
654
|
+
path: string;
|
|
655
|
+
/** Comparison operator */
|
|
656
|
+
op: ConditionOperator;
|
|
657
|
+
/** Static value to compare against */
|
|
658
|
+
value?: unknown;
|
|
659
|
+
/** Path to dynamic value to compare against (alternative to value) */
|
|
660
|
+
valuePath?: string;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Decision case in a decision step.
|
|
665
|
+
*/
|
|
666
|
+
export interface OrchestrationDecisionCase {
|
|
667
|
+
/** Conditions to evaluate (AND logic) */
|
|
668
|
+
conditions: OrchestrationCondition[];
|
|
669
|
+
/** Next step ID if conditions match */
|
|
670
|
+
nextStepId: string;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Orchestration step definition.
|
|
675
|
+
*/
|
|
676
|
+
export interface OrchestrationStep {
|
|
677
|
+
/** Unique step identifier */
|
|
678
|
+
id: string;
|
|
679
|
+
/** Human-readable step name */
|
|
680
|
+
name?: string;
|
|
681
|
+
/** Step type */
|
|
682
|
+
type: OrchestrationStepType;
|
|
683
|
+
|
|
684
|
+
// Compute step fields
|
|
685
|
+
/** Function ID to execute (for compute steps) */
|
|
686
|
+
functionId?: string;
|
|
687
|
+
/** Timeout in milliseconds (for compute steps) */
|
|
688
|
+
timeoutMs?: number;
|
|
689
|
+
/** Retry configuration (for compute steps) */
|
|
690
|
+
retry?: OrchestrationRetryConfig;
|
|
691
|
+
/** On success handler (for compute steps) */
|
|
692
|
+
onSuccess?: OrchestrationOnSuccess;
|
|
693
|
+
/** On failure handler (for compute steps) */
|
|
694
|
+
onFailure?: OrchestrationOnFailure;
|
|
695
|
+
|
|
696
|
+
// Decision step fields
|
|
697
|
+
/** Decision cases (for decision steps) */
|
|
698
|
+
cases?: OrchestrationDecisionCase[];
|
|
699
|
+
/** Default next step if no case matches (for decision steps) */
|
|
700
|
+
defaultNextStepId?: string;
|
|
701
|
+
|
|
702
|
+
// Delay step fields
|
|
703
|
+
/** Delay duration in milliseconds (for delay steps) */
|
|
704
|
+
delayMs?: number;
|
|
705
|
+
/** Next step ID (for delay steps) */
|
|
706
|
+
nextStepId?: string;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Orchestration definition.
|
|
711
|
+
*/
|
|
712
|
+
export interface Orchestration {
|
|
713
|
+
/** Unique identifier */
|
|
714
|
+
id: string;
|
|
715
|
+
/** Workspace slug */
|
|
716
|
+
workspaceSlug: string;
|
|
717
|
+
/** URL-friendly slug */
|
|
718
|
+
slug: string;
|
|
719
|
+
/** Human-readable name */
|
|
720
|
+
name: string;
|
|
721
|
+
/** Optional description */
|
|
722
|
+
description?: string;
|
|
723
|
+
/** Version number (increments on update) */
|
|
724
|
+
version: number;
|
|
725
|
+
/** Lifecycle status */
|
|
726
|
+
status: OrchestrationStatus;
|
|
727
|
+
/** Trigger configuration */
|
|
728
|
+
trigger: OrchestrationTrigger;
|
|
729
|
+
/** Workflow steps */
|
|
730
|
+
steps: OrchestrationStep[];
|
|
731
|
+
/** ISO timestamp of creation */
|
|
732
|
+
createdAt: string;
|
|
733
|
+
/** User who created the orchestration */
|
|
734
|
+
createdBy: string;
|
|
735
|
+
/** ISO timestamp of last update */
|
|
736
|
+
updatedAt: string;
|
|
737
|
+
/** User who last updated the orchestration */
|
|
738
|
+
updatedBy: string;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Input for creating an orchestration.
|
|
743
|
+
*/
|
|
744
|
+
export interface CreateOrchestrationInput {
|
|
745
|
+
/** URL-friendly slug (unique within workspace) */
|
|
746
|
+
slug: string;
|
|
747
|
+
/** Human-readable name */
|
|
748
|
+
name: string;
|
|
749
|
+
/** Optional description */
|
|
750
|
+
description?: string;
|
|
751
|
+
/** Trigger configuration */
|
|
752
|
+
trigger: OrchestrationTrigger;
|
|
753
|
+
/** Workflow steps */
|
|
754
|
+
steps: OrchestrationStep[];
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Input for updating an orchestration.
|
|
759
|
+
*/
|
|
760
|
+
export interface UpdateOrchestrationInput {
|
|
761
|
+
/** Updated name */
|
|
762
|
+
name?: string;
|
|
763
|
+
/** Updated description */
|
|
764
|
+
description?: string;
|
|
765
|
+
/** Updated status */
|
|
766
|
+
status?: OrchestrationStatus;
|
|
767
|
+
/** Updated trigger configuration */
|
|
768
|
+
trigger?: OrchestrationTrigger;
|
|
769
|
+
/** Updated workflow steps */
|
|
770
|
+
steps?: OrchestrationStep[];
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Trigger metadata for a run.
|
|
775
|
+
*/
|
|
776
|
+
export interface OrchestrationTriggerMetadata {
|
|
777
|
+
/** Event type (for event-driven triggers) */
|
|
778
|
+
eventType?: string;
|
|
779
|
+
/** Schedule ID (for scheduled triggers) */
|
|
780
|
+
scheduleId?: string;
|
|
781
|
+
/** Principal ID who initiated the run (for manual triggers) */
|
|
782
|
+
initiatedByPrincipalId?: string;
|
|
783
|
+
/** Webhook path (for HTTP triggers) */
|
|
784
|
+
webhookPath?: string;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Orchestration run instance.
|
|
789
|
+
*/
|
|
790
|
+
export interface OrchestrationRun {
|
|
791
|
+
/** Unique run identifier */
|
|
792
|
+
id: string;
|
|
793
|
+
/** Parent orchestration ID */
|
|
794
|
+
orchestrationId: string;
|
|
795
|
+
/** Orchestration version at time of run */
|
|
796
|
+
orchestrationVersion: number;
|
|
797
|
+
/** Workspace slug */
|
|
798
|
+
workspaceSlug: string;
|
|
799
|
+
/** Run status */
|
|
800
|
+
status: OrchestrationRunStatus;
|
|
801
|
+
/** Current step being executed */
|
|
802
|
+
currentStepId?: string;
|
|
803
|
+
/** Input data that triggered the run */
|
|
804
|
+
input: Record<string, unknown>;
|
|
805
|
+
/** Shared context across steps */
|
|
806
|
+
context: Record<string, unknown>;
|
|
807
|
+
/** Outputs from completed steps */
|
|
808
|
+
stepOutputs: Record<string, unknown>;
|
|
809
|
+
/** Correlation ID for tracing */
|
|
810
|
+
correlationId?: string;
|
|
811
|
+
/** How the run was triggered */
|
|
812
|
+
triggerType: OrchestrationTriggerType;
|
|
813
|
+
/** Trigger-specific metadata */
|
|
814
|
+
triggerMetadata?: OrchestrationTriggerMetadata;
|
|
815
|
+
/** Whether any step has errors */
|
|
816
|
+
hasErrors: boolean;
|
|
817
|
+
/** Number of delay steps encountered */
|
|
818
|
+
delayStepCount: number;
|
|
819
|
+
/** Reason for failure (if failed) */
|
|
820
|
+
failureReason?: string;
|
|
821
|
+
/** ISO timestamp when run started */
|
|
822
|
+
startedAt: string;
|
|
823
|
+
/** ISO timestamp when run completed */
|
|
824
|
+
completedAt?: string;
|
|
825
|
+
/** ISO timestamp when run data expires */
|
|
826
|
+
ttlExpiresAt: string;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Decision result from a decision step.
|
|
831
|
+
*/
|
|
832
|
+
export interface OrchestrationDecisionResult {
|
|
833
|
+
/** Number of cases evaluated */
|
|
834
|
+
evaluatedCases: number;
|
|
835
|
+
/** Index of matched case (null if default) */
|
|
836
|
+
matchedCaseIndex?: number;
|
|
837
|
+
/** Selected next step ID */
|
|
838
|
+
selectedNextStepId: string;
|
|
839
|
+
/** Detailed evaluation of each case */
|
|
840
|
+
evaluations?: OrchestrationCaseEvaluation[];
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Evaluation result for a single decision case.
|
|
845
|
+
*/
|
|
846
|
+
export interface OrchestrationCaseEvaluation {
|
|
847
|
+
/** Case index */
|
|
848
|
+
caseIndex: number;
|
|
849
|
+
/** Next step ID for this case */
|
|
850
|
+
nextStepId: string;
|
|
851
|
+
/** Condition evaluations */
|
|
852
|
+
conditions: OrchestrationConditionEvaluation[];
|
|
853
|
+
/** Whether this case matched */
|
|
854
|
+
matched: boolean;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Evaluation result for a single condition.
|
|
859
|
+
*/
|
|
860
|
+
export interface OrchestrationConditionEvaluation {
|
|
861
|
+
/** Path that was evaluated */
|
|
862
|
+
path: string;
|
|
863
|
+
/** Operator used */
|
|
864
|
+
operator: string;
|
|
865
|
+
/** Expected value */
|
|
866
|
+
expectedValue?: unknown;
|
|
867
|
+
/** Value path (if comparing against another path) */
|
|
868
|
+
valuePath?: string;
|
|
869
|
+
/** Actual value found at path */
|
|
870
|
+
actualValue?: unknown;
|
|
871
|
+
/** Whether the path exists */
|
|
872
|
+
pathExists: boolean;
|
|
873
|
+
/** Whether condition matched */
|
|
874
|
+
matched: boolean;
|
|
875
|
+
/** Error message if evaluation failed */
|
|
876
|
+
error?: string;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Delay configuration result from a delay step.
|
|
881
|
+
*/
|
|
882
|
+
export interface OrchestrationDelayConfig {
|
|
883
|
+
/** Delay duration in milliseconds */
|
|
884
|
+
delayMs: number;
|
|
885
|
+
/** ISO timestamp when step will resume */
|
|
886
|
+
resumeAt: string;
|
|
887
|
+
/** ISO timestamp when step actually resumed */
|
|
888
|
+
resumedAt?: string;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Error information from a failed step.
|
|
893
|
+
*/
|
|
894
|
+
export interface OrchestrationStepError {
|
|
895
|
+
/** Error message */
|
|
896
|
+
message: string;
|
|
897
|
+
/** Error code */
|
|
898
|
+
code?: string;
|
|
899
|
+
/** Stack trace */
|
|
900
|
+
stack?: string;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Run step execution record.
|
|
905
|
+
*/
|
|
906
|
+
export interface OrchestrationRunStep {
|
|
907
|
+
/** Unique step execution identifier */
|
|
908
|
+
id: string;
|
|
909
|
+
/** Parent run ID */
|
|
910
|
+
orchestrationRunId: string;
|
|
911
|
+
/** Step ID from orchestration definition */
|
|
912
|
+
stepId: string;
|
|
913
|
+
/** Step type */
|
|
914
|
+
stepType: OrchestrationStepType;
|
|
915
|
+
/** Attempt number (for retries) */
|
|
916
|
+
attempt: number;
|
|
917
|
+
/** Step execution status */
|
|
918
|
+
status: OrchestrationStepStatus;
|
|
919
|
+
/** Input data for this step */
|
|
920
|
+
input?: Record<string, unknown>;
|
|
921
|
+
/** Output data from this step */
|
|
922
|
+
output?: Record<string, unknown>;
|
|
923
|
+
/** Decision result (for decision steps) */
|
|
924
|
+
decisionResult?: OrchestrationDecisionResult;
|
|
925
|
+
/** Delay configuration (for delay steps) */
|
|
926
|
+
delayConfig?: OrchestrationDelayConfig;
|
|
927
|
+
/** Error information (if failed) */
|
|
928
|
+
error?: OrchestrationStepError;
|
|
929
|
+
/** ISO timestamp when step started */
|
|
930
|
+
startedAt?: string;
|
|
931
|
+
/** ISO timestamp when step completed */
|
|
932
|
+
completedAt?: string;
|
|
933
|
+
/** Compute gateway execution ID (for logs) */
|
|
934
|
+
executionId?: string;
|
|
935
|
+
/** Function run ID (for UI linking) */
|
|
936
|
+
functionRunId?: string;
|
|
937
|
+
/** Function ID that was executed */
|
|
938
|
+
functionId?: string;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Options for triggering an orchestration run.
|
|
943
|
+
*/
|
|
944
|
+
export interface TriggerOrchestrationRunOptions {
|
|
945
|
+
/** Input data for the run */
|
|
946
|
+
input?: Record<string, unknown>;
|
|
947
|
+
/** Correlation ID for tracing */
|
|
948
|
+
correlationId?: string;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Options for listing orchestrations.
|
|
953
|
+
*/
|
|
954
|
+
export interface ListOrchestrationsOptions {
|
|
955
|
+
/** Number of items per page (default: 20, max: 100) */
|
|
956
|
+
limit?: number;
|
|
957
|
+
/** Number of items to skip */
|
|
958
|
+
offset?: number;
|
|
959
|
+
/** Filter by status */
|
|
960
|
+
status?: OrchestrationStatus;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Options for listing orchestration runs.
|
|
965
|
+
*/
|
|
966
|
+
export interface ListOrchestrationRunsOptions {
|
|
967
|
+
/** Number of items per page (default: 20, max: 100) */
|
|
968
|
+
limit?: number;
|
|
969
|
+
/** Number of items to skip */
|
|
970
|
+
offset?: number;
|
|
971
|
+
/** Filter by run status */
|
|
972
|
+
status?: OrchestrationRunStatus;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Paginated response wrapper.
|
|
977
|
+
*/
|
|
978
|
+
export interface PaginatedResponse<T> {
|
|
979
|
+
/** Data items */
|
|
980
|
+
data: T[];
|
|
981
|
+
/** Pagination metadata */
|
|
982
|
+
meta: {
|
|
983
|
+
/** Total number of items */
|
|
984
|
+
total: number;
|
|
985
|
+
/** Current page number */
|
|
986
|
+
page: number;
|
|
987
|
+
/** Items per page */
|
|
988
|
+
pageSize: number;
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
|
|
548
992
|
// =====================================================
|
|
549
993
|
// Smart Query Types
|
|
550
994
|
// =====================================================
|
|
@@ -1526,6 +1970,341 @@ export function getValidationScanApiPath(workspaceId: string, batchId?: string):
|
|
|
1526
1970
|
return batchId ? `${basePath}/${batchId}` : basePath;
|
|
1527
1971
|
}
|
|
1528
1972
|
|
|
1973
|
+
// =====================================================
|
|
1974
|
+
// Orchestration API Paths
|
|
1975
|
+
// =====================================================
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* Generate Orchestrations API URL PATH.
|
|
1979
|
+
* Routes to the orchestration service.
|
|
1980
|
+
*/
|
|
1981
|
+
export function getOrchestrationsApiPath(workspaceId: string, orchestrationId?: string): string {
|
|
1982
|
+
const basePath = `orchestration/ws/${workspaceId}/api/v1/orchestrations`;
|
|
1983
|
+
return orchestrationId ? `${basePath}/${orchestrationId}` : basePath;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/**
|
|
1987
|
+
* Generate Orchestration Runs API URL PATH.
|
|
1988
|
+
*/
|
|
1989
|
+
export function getOrchestrationRunsApiPath(workspaceId: string, orchestrationId: string, runId?: string): string {
|
|
1990
|
+
const basePath = `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs`;
|
|
1991
|
+
return runId ? `${basePath}/${runId}` : basePath;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Generate Orchestration Run Steps API URL PATH.
|
|
1996
|
+
*/
|
|
1997
|
+
export function getOrchestrationRunStepsApiPath(workspaceId: string, orchestrationId: string, runId: string): string {
|
|
1998
|
+
return `orchestration/ws/${workspaceId}/api/v1/orchestrations/${orchestrationId}/runs/${runId}/steps`;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
// =====================================================
|
|
2002
|
+
// Orchestrations Manager
|
|
2003
|
+
// =====================================================
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* OrchestrationsManager provides methods for managing orchestrations and triggering runs.
|
|
2007
|
+
* Access via `client.orchestrations`.
|
|
2008
|
+
*
|
|
2009
|
+
* Orchestrations are multi-step workflows that chain compute functions together
|
|
2010
|
+
* with conditional logic, delays, and decision branches.
|
|
2011
|
+
*
|
|
2012
|
+
* Usage:
|
|
2013
|
+
* ```ts
|
|
2014
|
+
* // List all orchestrations
|
|
2015
|
+
* const orchestrations = await client.orchestrations.list();
|
|
2016
|
+
*
|
|
2017
|
+
* // Get an orchestration by ID
|
|
2018
|
+
* const orch = await client.orchestrations.get('orch-id');
|
|
2019
|
+
*
|
|
2020
|
+
* // Trigger an on-demand orchestration
|
|
2021
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
2022
|
+
* input: { orderId: '12345' }
|
|
2023
|
+
* });
|
|
2024
|
+
*
|
|
2025
|
+
* // Get run status
|
|
2026
|
+
* const runStatus = await client.orchestrations.getRun('orch-id', run.data.id);
|
|
2027
|
+
*
|
|
2028
|
+
* // List runs for an orchestration
|
|
2029
|
+
* const runs = await client.orchestrations.listRuns('orch-id');
|
|
2030
|
+
* ```
|
|
2031
|
+
*/
|
|
2032
|
+
export class OrchestrationsManager {
|
|
2033
|
+
private requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>;
|
|
2034
|
+
private workspaceId: string;
|
|
2035
|
+
|
|
2036
|
+
constructor(
|
|
2037
|
+
workspaceId: string,
|
|
2038
|
+
requestFn: <T>(method: Method, path: string, data?: any, queryParams?: Record<string, any>) => Promise<ApiResponse<T>>
|
|
2039
|
+
) {
|
|
2040
|
+
this.workspaceId = workspaceId;
|
|
2041
|
+
this.requestFn = requestFn;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* List all orchestrations in the workspace.
|
|
2046
|
+
*
|
|
2047
|
+
* @param options - Optional pagination and filtering options
|
|
2048
|
+
* @returns Paginated list of orchestrations
|
|
2049
|
+
*
|
|
2050
|
+
* @example
|
|
2051
|
+
* ```ts
|
|
2052
|
+
* // List all orchestrations
|
|
2053
|
+
* const result = await client.orchestrations.list();
|
|
2054
|
+
* console.log('Total:', result.data.meta.total);
|
|
2055
|
+
*
|
|
2056
|
+
* // With pagination and status filter
|
|
2057
|
+
* const result = await client.orchestrations.list({
|
|
2058
|
+
* limit: 10,
|
|
2059
|
+
* offset: 0,
|
|
2060
|
+
* status: 'active'
|
|
2061
|
+
* });
|
|
2062
|
+
* ```
|
|
2063
|
+
*/
|
|
2064
|
+
public list(options?: ListOrchestrationsOptions): Promise<ApiResponse<PaginatedResponse<Orchestration>>> {
|
|
2065
|
+
const path = getOrchestrationsApiPath(this.workspaceId);
|
|
2066
|
+
return this.requestFn<PaginatedResponse<Orchestration>>('GET', path, null, options);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/**
|
|
2070
|
+
* Get an orchestration by ID.
|
|
2071
|
+
*
|
|
2072
|
+
* @param orchestrationId - The orchestration ID
|
|
2073
|
+
* @returns The orchestration details including all steps
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```ts
|
|
2077
|
+
* const orch = await client.orchestrations.get('orch-id');
|
|
2078
|
+
* console.log('Name:', orch.data.name);
|
|
2079
|
+
* console.log('Steps:', orch.data.steps.length);
|
|
2080
|
+
* ```
|
|
2081
|
+
*/
|
|
2082
|
+
public get(orchestrationId: string): Promise<ApiResponse<Orchestration>> {
|
|
2083
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
2084
|
+
return this.requestFn<Orchestration>('GET', path);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* Create a new orchestration.
|
|
2089
|
+
*
|
|
2090
|
+
* @param input - The orchestration definition
|
|
2091
|
+
* @returns The created orchestration
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```ts
|
|
2095
|
+
* const orch = await client.orchestrations.create({
|
|
2096
|
+
* slug: 'order-processing',
|
|
2097
|
+
* name: 'Order Processing Workflow',
|
|
2098
|
+
* trigger: { type: 'on-demand' },
|
|
2099
|
+
* steps: [
|
|
2100
|
+
* {
|
|
2101
|
+
* id: 'validate',
|
|
2102
|
+
* type: 'compute',
|
|
2103
|
+
* functionId: 'func_validate',
|
|
2104
|
+
* onSuccess: { nextStepId: 'process' }
|
|
2105
|
+
* },
|
|
2106
|
+
* {
|
|
2107
|
+
* id: 'process',
|
|
2108
|
+
* type: 'compute',
|
|
2109
|
+
* functionId: 'func_process'
|
|
2110
|
+
* }
|
|
2111
|
+
* ]
|
|
2112
|
+
* });
|
|
2113
|
+
* ```
|
|
2114
|
+
*/
|
|
2115
|
+
public create(input: CreateOrchestrationInput): Promise<ApiResponse<Orchestration>> {
|
|
2116
|
+
const path = getOrchestrationsApiPath(this.workspaceId);
|
|
2117
|
+
return this.requestFn<Orchestration>('POST', path, input);
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
/**
|
|
2121
|
+
* Update an existing orchestration.
|
|
2122
|
+
*
|
|
2123
|
+
* Updates increment the orchestration version. Running instances use the
|
|
2124
|
+
* version at the time they started.
|
|
2125
|
+
*
|
|
2126
|
+
* @param orchestrationId - The orchestration ID
|
|
2127
|
+
* @param input - Fields to update
|
|
2128
|
+
* @returns The updated orchestration
|
|
2129
|
+
*
|
|
2130
|
+
* @example
|
|
2131
|
+
* ```ts
|
|
2132
|
+
* // Activate an orchestration
|
|
2133
|
+
* await client.orchestrations.update('orch-id', { status: 'active' });
|
|
2134
|
+
*
|
|
2135
|
+
* // Update steps
|
|
2136
|
+
* await client.orchestrations.update('orch-id', {
|
|
2137
|
+
* steps: [...]
|
|
2138
|
+
* });
|
|
2139
|
+
* ```
|
|
2140
|
+
*/
|
|
2141
|
+
public update(orchestrationId: string, input: UpdateOrchestrationInput): Promise<ApiResponse<Orchestration>> {
|
|
2142
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
2143
|
+
return this.requestFn<Orchestration>('PUT', path, input);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
/**
|
|
2147
|
+
* Delete an orchestration.
|
|
2148
|
+
*
|
|
2149
|
+
* This also deletes all runs associated with the orchestration.
|
|
2150
|
+
*
|
|
2151
|
+
* @param orchestrationId - The orchestration ID
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* ```ts
|
|
2155
|
+
* await client.orchestrations.delete('orch-id');
|
|
2156
|
+
* ```
|
|
2157
|
+
*/
|
|
2158
|
+
public delete(orchestrationId: string): Promise<ApiResponse<void>> {
|
|
2159
|
+
const path = getOrchestrationsApiPath(this.workspaceId, orchestrationId);
|
|
2160
|
+
return this.requestFn<void>('DELETE', path);
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
/**
|
|
2164
|
+
* Trigger an orchestration run.
|
|
2165
|
+
*
|
|
2166
|
+
* This creates a new run instance and starts executing the workflow.
|
|
2167
|
+
* Can be used on on-demand, draft, or active orchestrations.
|
|
2168
|
+
* Paused orchestrations cannot be triggered.
|
|
2169
|
+
*
|
|
2170
|
+
* @param orchestrationId - The orchestration ID
|
|
2171
|
+
* @param options - Optional input data and correlation ID
|
|
2172
|
+
* @returns The created run
|
|
2173
|
+
*
|
|
2174
|
+
* @example
|
|
2175
|
+
* ```ts
|
|
2176
|
+
* // Simple trigger
|
|
2177
|
+
* const run = await client.orchestrations.trigger('orch-id');
|
|
2178
|
+
*
|
|
2179
|
+
* // With input data
|
|
2180
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
2181
|
+
* input: {
|
|
2182
|
+
* orderId: '12345',
|
|
2183
|
+
* customerId: 'cust_abc'
|
|
2184
|
+
* }
|
|
2185
|
+
* });
|
|
2186
|
+
*
|
|
2187
|
+
* // With correlation ID for tracing
|
|
2188
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
2189
|
+
* input: { orderId: '12345' },
|
|
2190
|
+
* correlationId: 'req-123'
|
|
2191
|
+
* });
|
|
2192
|
+
* ```
|
|
2193
|
+
*/
|
|
2194
|
+
public trigger(orchestrationId: string, options?: TriggerOrchestrationRunOptions): Promise<ApiResponse<OrchestrationRun>> {
|
|
2195
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId);
|
|
2196
|
+
const body = {
|
|
2197
|
+
input: options?.input ?? {},
|
|
2198
|
+
correlationId: options?.correlationId
|
|
2199
|
+
};
|
|
2200
|
+
return this.requestFn<OrchestrationRun>('POST', path, body);
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* List runs for an orchestration.
|
|
2205
|
+
*
|
|
2206
|
+
* @param orchestrationId - The orchestration ID
|
|
2207
|
+
* @param options - Optional pagination and filtering options
|
|
2208
|
+
* @returns Paginated list of runs
|
|
2209
|
+
*
|
|
2210
|
+
* @example
|
|
2211
|
+
* ```ts
|
|
2212
|
+
* // List all runs
|
|
2213
|
+
* const runs = await client.orchestrations.listRuns('orch-id');
|
|
2214
|
+
*
|
|
2215
|
+
* // Filter by status
|
|
2216
|
+
* const failedRuns = await client.orchestrations.listRuns('orch-id', {
|
|
2217
|
+
* status: 'failed'
|
|
2218
|
+
* });
|
|
2219
|
+
* ```
|
|
2220
|
+
*/
|
|
2221
|
+
public listRuns(orchestrationId: string, options?: ListOrchestrationRunsOptions): Promise<ApiResponse<PaginatedResponse<OrchestrationRun>>> {
|
|
2222
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId);
|
|
2223
|
+
return this.requestFn<PaginatedResponse<OrchestrationRun>>('GET', path, null, options);
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Get a specific run by ID.
|
|
2228
|
+
*
|
|
2229
|
+
* @param orchestrationId - The orchestration ID
|
|
2230
|
+
* @param runId - The run ID
|
|
2231
|
+
* @param includeSteps - Whether to include step execution history
|
|
2232
|
+
* @returns The run details
|
|
2233
|
+
*
|
|
2234
|
+
* @example
|
|
2235
|
+
* ```ts
|
|
2236
|
+
* // Get basic run info
|
|
2237
|
+
* const run = await client.orchestrations.getRun('orch-id', 'run-id');
|
|
2238
|
+
* console.log('Status:', run.data.status);
|
|
2239
|
+
*
|
|
2240
|
+
* // Include step history
|
|
2241
|
+
* const run = await client.orchestrations.getRun('orch-id', 'run-id', true);
|
|
2242
|
+
* console.log('Steps:', run.data.steps);
|
|
2243
|
+
* ```
|
|
2244
|
+
*/
|
|
2245
|
+
public getRun(orchestrationId: string, runId: string, includeSteps?: boolean): Promise<ApiResponse<OrchestrationRun & { steps?: OrchestrationRunStep[] }>> {
|
|
2246
|
+
const path = getOrchestrationRunsApiPath(this.workspaceId, orchestrationId, runId);
|
|
2247
|
+
const params = includeSteps ? { include: 'steps' } : undefined;
|
|
2248
|
+
return this.requestFn<OrchestrationRun & { steps?: OrchestrationRunStep[] }>('GET', path, null, params);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
/**
|
|
2252
|
+
* Get step execution history for a run.
|
|
2253
|
+
*
|
|
2254
|
+
* @param orchestrationId - The orchestration ID
|
|
2255
|
+
* @param runId - The run ID
|
|
2256
|
+
* @returns List of step executions
|
|
2257
|
+
*
|
|
2258
|
+
* @example
|
|
2259
|
+
* ```ts
|
|
2260
|
+
* const steps = await client.orchestrations.getRunSteps('orch-id', 'run-id');
|
|
2261
|
+
* for (const step of steps.data.data) {
|
|
2262
|
+
* console.log(`${step.stepId}: ${step.status}`);
|
|
2263
|
+
* }
|
|
2264
|
+
* ```
|
|
2265
|
+
*/
|
|
2266
|
+
public getRunSteps(orchestrationId: string, runId: string): Promise<ApiResponse<{ data: OrchestrationRunStep[]; meta: { total: number } }>> {
|
|
2267
|
+
const path = getOrchestrationRunStepsApiPath(this.workspaceId, orchestrationId, runId);
|
|
2268
|
+
return this.requestFn<{ data: OrchestrationRunStep[]; meta: { total: number } }>('GET', path);
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
/**
|
|
2272
|
+
* Activate an orchestration.
|
|
2273
|
+
*
|
|
2274
|
+
* Convenience method to set status to 'active'.
|
|
2275
|
+
* Active orchestrations can be triggered by scheduled events, record events, and webhooks.
|
|
2276
|
+
*
|
|
2277
|
+
* @param orchestrationId - The orchestration ID
|
|
2278
|
+
* @returns The updated orchestration
|
|
2279
|
+
*
|
|
2280
|
+
* @example
|
|
2281
|
+
* ```ts
|
|
2282
|
+
* await client.orchestrations.activate('orch-id');
|
|
2283
|
+
* ```
|
|
2284
|
+
*/
|
|
2285
|
+
public activate(orchestrationId: string): Promise<ApiResponse<Orchestration>> {
|
|
2286
|
+
return this.update(orchestrationId, { status: 'active' });
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
/**
|
|
2290
|
+
* Pause an orchestration.
|
|
2291
|
+
*
|
|
2292
|
+
* Convenience method to set status to 'paused'.
|
|
2293
|
+
* Paused orchestrations cannot be triggered by any mechanism.
|
|
2294
|
+
*
|
|
2295
|
+
* @param orchestrationId - The orchestration ID
|
|
2296
|
+
* @returns The updated orchestration
|
|
2297
|
+
*
|
|
2298
|
+
* @example
|
|
2299
|
+
* ```ts
|
|
2300
|
+
* await client.orchestrations.pause('orch-id');
|
|
2301
|
+
* ```
|
|
2302
|
+
*/
|
|
2303
|
+
public pause(orchestrationId: string): Promise<ApiResponse<Orchestration>> {
|
|
2304
|
+
return this.update(orchestrationId, { status: 'paused' });
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
|
|
1529
2308
|
// =====================================================
|
|
1530
2309
|
// Triggers Manager
|
|
1531
2310
|
// =====================================================
|
|
@@ -2320,6 +3099,7 @@ export class CentraliSDK {
|
|
|
2320
3099
|
private _smartQueries: SmartQueriesManager | null = null;
|
|
2321
3100
|
private _anomalyInsights: AnomalyInsightsManager | null = null;
|
|
2322
3101
|
private _validation: ValidationManager | null = null;
|
|
3102
|
+
private _orchestrations: OrchestrationsManager | null = null;
|
|
2323
3103
|
|
|
2324
3104
|
constructor(options: CentraliSDKOptions) {
|
|
2325
3105
|
this.options = options;
|
|
@@ -2531,6 +3311,47 @@ export class CentraliSDK {
|
|
|
2531
3311
|
return this._validation;
|
|
2532
3312
|
}
|
|
2533
3313
|
|
|
3314
|
+
/**
|
|
3315
|
+
* Orchestrations namespace for managing multi-step workflows.
|
|
3316
|
+
*
|
|
3317
|
+
* Orchestrations chain compute functions together with conditional logic,
|
|
3318
|
+
* delays, and decision branches to automate complex business processes.
|
|
3319
|
+
*
|
|
3320
|
+
* Usage:
|
|
3321
|
+
* ```ts
|
|
3322
|
+
* // List all orchestrations
|
|
3323
|
+
* const orchestrations = await client.orchestrations.list();
|
|
3324
|
+
*
|
|
3325
|
+
* // Trigger an on-demand orchestration
|
|
3326
|
+
* const run = await client.orchestrations.trigger('orch-id', {
|
|
3327
|
+
* input: { orderId: '12345' }
|
|
3328
|
+
* });
|
|
3329
|
+
*
|
|
3330
|
+
* // Get run status
|
|
3331
|
+
* const runStatus = await client.orchestrations.getRun('orch-id', run.data.id);
|
|
3332
|
+
*
|
|
3333
|
+
* // Create a new orchestration
|
|
3334
|
+
* const orch = await client.orchestrations.create({
|
|
3335
|
+
* slug: 'order-processing',
|
|
3336
|
+
* name: 'Order Processing',
|
|
3337
|
+
* trigger: { type: 'on-demand' },
|
|
3338
|
+
* steps: [
|
|
3339
|
+
* { id: 'validate', type: 'compute', functionId: 'func_validate', onSuccess: { nextStepId: 'process' } },
|
|
3340
|
+
* { id: 'process', type: 'compute', functionId: 'func_process' }
|
|
3341
|
+
* ]
|
|
3342
|
+
* });
|
|
3343
|
+
* ```
|
|
3344
|
+
*/
|
|
3345
|
+
public get orchestrations(): OrchestrationsManager {
|
|
3346
|
+
if (!this._orchestrations) {
|
|
3347
|
+
this._orchestrations = new OrchestrationsManager(
|
|
3348
|
+
this.options.workspaceId,
|
|
3349
|
+
this.request.bind(this)
|
|
3350
|
+
);
|
|
3351
|
+
}
|
|
3352
|
+
return this._orchestrations;
|
|
3353
|
+
}
|
|
3354
|
+
|
|
2534
3355
|
/**
|
|
2535
3356
|
* Manually set or update the bearer token for subsequent requests.
|
|
2536
3357
|
*/
|