@io-orkes/conductor-javascript 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +258 -0
- package/dist/index.d.mts +478 -1
- package/dist/index.d.ts +478 -1
- package/dist/index.js +1369 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1366 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,22 @@ Show support for the Conductor OSS. Please help spread the awareness by starrin
|
|
|
62
62
|
- [Step 1: Create a MetadataClient](#step-1-create-a-metadataclient)
|
|
63
63
|
- [Step 2: Define and Register a Task](#step-2-define-and-register-a-task)
|
|
64
64
|
- [Step 3: Define and Register a Workflow](#step-3-define-and-register-a-workflow)
|
|
65
|
+
- [Events](#events)
|
|
66
|
+
- [The EventClient](#the-eventclient)
|
|
67
|
+
- [Quick Start: Using Event Handlers](#quick-start-using-event-handlers)
|
|
68
|
+
- [Step 1: Create an EventClient](#step-1-create-an-eventclient)
|
|
69
|
+
- [Step 2: Register an Event Handler](#step-2-register-an-event-handler)
|
|
70
|
+
- [Step 3: Publish Events](#step-3-publish-events)
|
|
71
|
+
- [Step 4: Monitor Event Processing](#step-4-monitor-event-processing)
|
|
72
|
+
- [Step 5: Manage Event Handlers](#step-5-manage-event-handlers)
|
|
73
|
+
- [Applications](#applications)
|
|
74
|
+
- [The ApplicationClient](#the-applicationclient)
|
|
75
|
+
- [Quick Start: Managing Applications](#quick-start-managing-applications)
|
|
76
|
+
- [Step 1: Create an ApplicationClient](#step-1-create-an-applicationclient)
|
|
77
|
+
- [Step 2: Create an Application](#step-2-create-an-application)
|
|
78
|
+
- [Step 3: Generate Access Keys](#step-3-generate-access-keys)
|
|
79
|
+
- [Step 4: Manage Application Roles](#step-4-manage-application-roles)
|
|
80
|
+
- [Step 5: Manage Applications](#step-5-manage-applications)
|
|
65
81
|
- [Human Tasks](#human-tasks)
|
|
66
82
|
- [The HumanExecutor and TemplateClient](#the-humanexecutor-and-templateclient)
|
|
67
83
|
- [Quick Start: Creating and Managing a Human Task](#quick-start-creating-and-managing-a-human-task)
|
|
@@ -716,6 +732,248 @@ await metadataClient.registerWorkflowDef(wf);
|
|
|
716
732
|
|
|
717
733
|
For a complete method reference, see the [MetadataClient API Reference](docs/api-reference/metadata-client.md).
|
|
718
734
|
|
|
735
|
+
## Events
|
|
736
|
+
|
|
737
|
+
Event handlers in Conductor allow you to automatically trigger actions (like starting workflows) when events are received. This enables event-driven workflows and integrations with external systems.
|
|
738
|
+
|
|
739
|
+
### The EventClient
|
|
740
|
+
|
|
741
|
+
The `EventClient` manages event handlers and event processing. For a complete method reference, see the [EventClient API Reference](docs/api-reference/event-client.md).
|
|
742
|
+
|
|
743
|
+
### Quick Start: Using Event Handlers
|
|
744
|
+
|
|
745
|
+
Here's how to set up event-driven workflows:
|
|
746
|
+
|
|
747
|
+
#### Step 1: Create an EventClient
|
|
748
|
+
|
|
749
|
+
First, create an instance of the `EventClient`:
|
|
750
|
+
|
|
751
|
+
```typescript
|
|
752
|
+
import { EventClient } from "@io-orkes/conductor-javascript";
|
|
753
|
+
|
|
754
|
+
const eventClient = new EventClient(client);
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
#### Step 2: Register an Event Handler
|
|
758
|
+
|
|
759
|
+
Create an event handler that defines what action to take when an event is received. In this example, we'll start a workflow when an order is created:
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
await eventClient.addEventHandler({
|
|
763
|
+
name: "order_created_handler",
|
|
764
|
+
event: "order.created",
|
|
765
|
+
active: true,
|
|
766
|
+
description: "Starts fulfillment workflow when order is created",
|
|
767
|
+
actions: [
|
|
768
|
+
{
|
|
769
|
+
action: "start_workflow",
|
|
770
|
+
start_workflow: {
|
|
771
|
+
name: "fulfill_order",
|
|
772
|
+
version: 1,
|
|
773
|
+
input: {
|
|
774
|
+
orderId: "${event.orderId}",
|
|
775
|
+
customerId: "${event.customerId}",
|
|
776
|
+
},
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
],
|
|
780
|
+
});
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
#### Step 3: Publish Events
|
|
784
|
+
|
|
785
|
+
When an event occurs, publish it to Conductor. All active handlers registered for that event will be triggered:
|
|
786
|
+
|
|
787
|
+
```typescript
|
|
788
|
+
await eventClient.handleIncomingEvent({
|
|
789
|
+
event: "order.created",
|
|
790
|
+
orderId: "ORDER-123",
|
|
791
|
+
customerId: "CUST-456",
|
|
792
|
+
amount: "99.99",
|
|
793
|
+
timestamp: Date.now().toString(),
|
|
794
|
+
});
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
#### Step 4: Monitor Event Processing
|
|
798
|
+
|
|
799
|
+
You can monitor event handlers and their execution history:
|
|
800
|
+
|
|
801
|
+
```typescript
|
|
802
|
+
// Get all handlers for a specific event
|
|
803
|
+
const handlers = await eventClient.getEventHandlersForEvent("order.created");
|
|
804
|
+
|
|
805
|
+
// Get execution history for a handler
|
|
806
|
+
const executions = await eventClient.getEventExecutions("order_created_handler");
|
|
807
|
+
|
|
808
|
+
// Get event messages
|
|
809
|
+
const messages = await eventClient.getEventMessages("order.created");
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
#### Step 5: Manage Event Handlers
|
|
813
|
+
|
|
814
|
+
Update, deactivate, or remove event handlers as needed:
|
|
815
|
+
|
|
816
|
+
```typescript
|
|
817
|
+
// Update a handler
|
|
818
|
+
await eventClient.updateEventHandler({
|
|
819
|
+
name: "order_created_handler",
|
|
820
|
+
active: false, // Deactivate
|
|
821
|
+
// ... other fields
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// Remove a handler
|
|
825
|
+
await eventClient.removeEventHandler("order_created_handler");
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
**Event Handler Actions:**
|
|
829
|
+
|
|
830
|
+
Event handlers support various actions:
|
|
831
|
+
- `start_workflow` - Start a workflow execution
|
|
832
|
+
- `complete_task` - Complete a specific task
|
|
833
|
+
- `fail_task` - Fail a specific task
|
|
834
|
+
- `terminate_workflow` - Terminate a workflow
|
|
835
|
+
- `update_workflow_variables` - Update workflow variables
|
|
836
|
+
|
|
837
|
+
For a complete method reference, see the [EventClient API Reference](docs/api-reference/event-client.md).
|
|
838
|
+
|
|
839
|
+
## Applications
|
|
840
|
+
|
|
841
|
+
Applications in Conductor are security entities that enable programmatic access to the Conductor API. Each application can have multiple access keys for authentication and can be assigned roles to control what operations it can perform.
|
|
842
|
+
|
|
843
|
+
### The ApplicationClient
|
|
844
|
+
|
|
845
|
+
The `ApplicationClient` manages applications, access keys, and roles. For a complete method reference, see the [ApplicationClient API Reference](docs/api-reference/application-client.md).
|
|
846
|
+
|
|
847
|
+
### Quick Start: Managing Applications
|
|
848
|
+
|
|
849
|
+
Here's how to create and manage applications in Conductor:
|
|
850
|
+
|
|
851
|
+
#### Step 1: Create an ApplicationClient
|
|
852
|
+
|
|
853
|
+
First, create an instance of the `ApplicationClient`:
|
|
854
|
+
|
|
855
|
+
```typescript
|
|
856
|
+
import { ApplicationClient, ApplicationRole } from "@io-orkes/conductor-javascript";
|
|
857
|
+
|
|
858
|
+
const appClient = new ApplicationClient(client);
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
#### Step 2: Create an Application
|
|
862
|
+
|
|
863
|
+
Create a new application to represent your service or integration:
|
|
864
|
+
|
|
865
|
+
```typescript
|
|
866
|
+
// Create a new application
|
|
867
|
+
const app = await appClient.createApplication("payment-service");
|
|
868
|
+
console.log(`Created application: ${app.id}`);
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
#### Step 3: Generate Access Keys
|
|
872
|
+
|
|
873
|
+
Create access keys for the application to authenticate API requests:
|
|
874
|
+
|
|
875
|
+
```typescript
|
|
876
|
+
// Create an access key
|
|
877
|
+
const accessKey = await appClient.createAccessKey(app.id);
|
|
878
|
+
console.log(`Key ID: ${accessKey.id}`);
|
|
879
|
+
console.log(`Key Secret: ${accessKey.secret}`); // Save this immediately!
|
|
880
|
+
|
|
881
|
+
// The secret is only shown once - store it securely
|
|
882
|
+
// Use these credentials to create authenticated clients
|
|
883
|
+
const authenticatedClient = await orkesConductorClient({
|
|
884
|
+
serverUrl: "https://play.orkes.io/api",
|
|
885
|
+
keyId: accessKey.id,
|
|
886
|
+
keySecret: accessKey.secret
|
|
887
|
+
});
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
#### Step 4: Manage Application Roles
|
|
891
|
+
|
|
892
|
+
Grant the application permissions by adding roles:
|
|
893
|
+
|
|
894
|
+
```typescript
|
|
895
|
+
import { ApplicationRole } from "@io-orkes/conductor-javascript";
|
|
896
|
+
|
|
897
|
+
// Add roles to the application
|
|
898
|
+
await appClient.addApplicationRole(app.id, "WORKFLOW_MANAGER");
|
|
899
|
+
await appClient.addApplicationRole(app.id, "WORKER");
|
|
900
|
+
|
|
901
|
+
console.log("Application can now execute workflows and run workers");
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
**Available Roles:**
|
|
905
|
+
|
|
906
|
+
The SDK provides an `ApplicationRole` type with the following options:
|
|
907
|
+
|
|
908
|
+
- `ADMIN` - Full administrative access to all resources
|
|
909
|
+
- `WORKFLOW_MANAGER` - Start and manage workflow executions
|
|
910
|
+
- `WORKER` - Poll for and execute assigned tasks
|
|
911
|
+
- `UNRESTRICTED_WORKER` - Can execute any task without restrictions
|
|
912
|
+
- `METADATA_MANAGER` - Manage workflow and task definitions
|
|
913
|
+
- `APPLICATION_MANAGER` - Manage applications and access keys
|
|
914
|
+
- `APPLICATION_CREATOR` - Can create new applications
|
|
915
|
+
- `USER` - Standard user access
|
|
916
|
+
- `USER_READ_ONLY` - Read-only access to resources
|
|
917
|
+
- `METADATA_API` - API access to metadata operations
|
|
918
|
+
- `PROMPT_MANAGER` - Can manage AI prompts and templates
|
|
919
|
+
|
|
920
|
+
#### Step 5: Manage Applications
|
|
921
|
+
|
|
922
|
+
Manage the lifecycle of your applications:
|
|
923
|
+
|
|
924
|
+
```typescript
|
|
925
|
+
// List all applications
|
|
926
|
+
const applications = await appClient.getAllApplications();
|
|
927
|
+
console.log(`Total applications: ${applications.length}`);
|
|
928
|
+
|
|
929
|
+
// Get a specific application
|
|
930
|
+
const myApp = await appClient.getApplication(app.id);
|
|
931
|
+
console.log(`Application name: ${myApp.name}`);
|
|
932
|
+
|
|
933
|
+
// Update application name
|
|
934
|
+
await appClient.updateApplication(app.id, "payment-service-v2");
|
|
935
|
+
|
|
936
|
+
// Get all access keys for an application
|
|
937
|
+
const keys = await appClient.getAccessKeys(app.id);
|
|
938
|
+
console.log(`Application has ${keys.length} access keys`);
|
|
939
|
+
|
|
940
|
+
// Toggle access key status (ACTIVE/INACTIVE)
|
|
941
|
+
await appClient.toggleAccessKeyStatus(app.id, accessKey.id);
|
|
942
|
+
|
|
943
|
+
// Remove a role from the application
|
|
944
|
+
await appClient.removeRoleFromApplicationUser(app.id, "WORKER");
|
|
945
|
+
|
|
946
|
+
// Delete an access key
|
|
947
|
+
await appClient.deleteAccessKey(app.id, accessKey.id);
|
|
948
|
+
|
|
949
|
+
// Delete the application
|
|
950
|
+
await appClient.deleteApplication(app.id);
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
**Tagging Applications:**
|
|
954
|
+
|
|
955
|
+
Organize applications with tags for better management:
|
|
956
|
+
|
|
957
|
+
```typescript
|
|
958
|
+
// Add tags to an application
|
|
959
|
+
await appClient.addApplicationTags(app.id, [
|
|
960
|
+
{ key: "environment", value: "production" },
|
|
961
|
+
{ key: "team", value: "payments" },
|
|
962
|
+
{ key: "cost-center", value: "engineering" }
|
|
963
|
+
]);
|
|
964
|
+
|
|
965
|
+
// Get application tags
|
|
966
|
+
const tags = await appClient.getApplicationTags(app.id);
|
|
967
|
+
|
|
968
|
+
// Delete specific tags
|
|
969
|
+
await appClient.deleteApplicationTag(app.id, {
|
|
970
|
+
key: "cost-center",
|
|
971
|
+
value: "engineering"
|
|
972
|
+
});
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
For a complete method reference, see the [ApplicationClient API Reference](docs/api-reference/application-client.md).
|
|
976
|
+
|
|
719
977
|
## Human Tasks
|
|
720
978
|
|
|
721
979
|
Human tasks integrate human interaction into your automated workflows. They pause a workflow until a person provides input, such as an approval, a correction, or additional information.
|