@onlive.ai/flow-client 0.0.3 → 0.1.31

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 ADDED
@@ -0,0 +1,91 @@
1
+ # Onlive Flow Client
2
+
3
+ The Flow Client package offers a convenient interface for interacting with a multi-step process flow. The client helps you initiate, retrieve, and progress through flow steps while tracking events. It leverages robust type validation from [client.types.ts](#file:client.types.ts-context).
4
+
5
+ ## Initialization
6
+
7
+ Create an instance of the FlowClient by passing a valid ClientOptions object. The options must conform to the ClientOptionsSchema. The options include:
8
+
9
+ - **baseUrl**: (string) URL of the service.
10
+ - **flowId**: (string) 24-character identifier.
11
+ - **organizationId**: (string) UUID.
12
+ - **lang**: (string) 2-character language code.
13
+
14
+ ```typescript
15
+ const client = new FlowClient({
16
+ baseUrl: "https://api.example.com",
17
+ flowId: "0123456789abcdef01234567",
18
+ organizationId: "550e8400-e29b-41d4-a716-446655440000",
19
+ lang: "en",
20
+ });
21
+ ```
22
+
23
+ ## Methods
24
+
25
+ ### firstStep(options?: GetStepOptions): Promise<FlowContext>
26
+
27
+ Initiates the first step of the flow.
28
+
29
+ - **Parameters**:
30
+ - **options** (optional): An object conforming to GetStepOptionsSchema.
31
+ - **Response**:
32
+ - Returns a `Promise` that resolves to a `FlowContext` object, representing the flow’s status, the current step (as defined in StepSchema), and flow metadata (FlowSchema).
33
+ - **Process**:
34
+ - Validates the options.
35
+ - Sends a POST request to `flow/{flowId}/first-step`.
36
+ - Analyzes and emits "track" events via the tracking service.
37
+
38
+ ### getStep(stepId: string, options?: GetStepOptions): Promise<FlowContext>
39
+
40
+ Retrieves a specific step in the flow.
41
+
42
+ - **Parameters**:
43
+ - **stepId**: (string) A non-empty string identifier validated by StepIdSchema.
44
+ - **options** (optional): Additional parameters adhering to GetStepOptionsSchema.
45
+ - **Response**:
46
+ - Returns a `Promise` resolving to a FlowContext.
47
+ - **Process**:
48
+ - Validates the stepId.
49
+ - Sends a POST request to `flow/{flowId}/steps/{stepId}`.
50
+ - Tracks request and response events.
51
+
52
+ ### nextStep(trigger: GetStepTrigger, options?: GetStepOptions): Promise<FlowContext>
53
+
54
+ Proceeds to the next step in the flow based on user actions.
55
+
56
+ - **Parameters**:
57
+ - **trigger**: An object conforming to GetStepTriggerSchema containing:
58
+ - `currentStepId` (string): Current step identifier.
59
+ - `actionId` (string): Identifier of the action to trigger.
60
+ - **options** (optional): Configuration for step retrieval following GetStepOptionsSchema.
61
+ - **Response**:
62
+ - Returns a `Promise` that resolves to an updated FlowContext.
63
+ - **Process**:
64
+ - Validates the trigger.
65
+ - Sends a POST request to `flow/{flowId}/steps/{currentStepId}/action/{actionId}`.
66
+ - Analyzes both request and response by emitting tracking events.
67
+
68
+ ## Event Handling
69
+
70
+ ### on(type: EventType, listener: EventListener): void
71
+
72
+ Registers a listener for specific events.
73
+
74
+ - **Parameters**:
75
+ - **type**: A string event type, currently supporting `"track"` as defined by EventTypeSchema.
76
+ - **listener**: Callback accepting the event type and event data.
77
+ - **Usage**:
78
+ Register multiple listener functions to react to tracking events.
79
+
80
+ Internally, FlowClient uses a private `emit` method to deliver events to all registered listeners.
81
+
82
+ ## Types & Schemas
83
+
84
+ The methods and the overall flow behavior are governed by types and validation schemas defined in [client.types.ts](#file:client.types.ts-context):
85
+
86
+ - **FlowContext**: Contains the status of the flow, current step details, and flow metadata.
87
+ - **StepSchema**, **ActionSchema**, **FieldSchema**: Define properties and validation for steps, actions, and form fields.
88
+ - **GetStepOptions** and **GetStepTrigger**: Govern the payload structure for step operations.
89
+ - **EventData**: Structure for tracking events, ensuring consistency with the "track" event type.
90
+
91
+ This documentation mirrors common npm package libraries by providing a straightforward interface with strong type validations and event tracking, ensuring that clients can interact with a dynamic flow efficiently.