@onlive.ai/flow-client 0.1.31 → 0.1.35

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 CHANGED
@@ -1,8 +1,64 @@
1
1
  # Onlive Flow Client
2
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).
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 and provides a modern TypeScript-first API.
4
4
 
5
- ## Initialization
5
+ ## Installation
6
+
7
+ ### Using pnpm (recommended)
8
+
9
+ ```bash
10
+ pnpm add @onlive.ai/flow-client
11
+ # or
12
+ npm install @onlive.ai/flow-client
13
+ ```
14
+
15
+ ## Package Structure
16
+
17
+ This package is organized into the following main components:
18
+
19
+ ```
20
+ packages/flow-client/
21
+ ├── client/ # Core client implementation
22
+ │ ├── client.service.ts # Main FlowClient class
23
+ │ ├── client.types.ts # Type definitions and schemas
24
+ │ └── client.service.spec.ts # Unit tests
25
+ ├── tracking/ # Event tracking functionality
26
+ │ ├── tracking.service.ts # Tracking service implementation
27
+ │ └── tracking.types.ts # Tracking-related types
28
+ ├── flow.types.ts # Flow-specific type definitions
29
+ ├── index.ts # Main package exports
30
+ ├── schema-generator.ts # JSON schema generation utilities
31
+ └── README.md # This documentation
32
+ ```
33
+
34
+ ### Main Exports
35
+
36
+ The package exports the following main components:
37
+
38
+ - **FlowClient**: Main client class for flow interactions
39
+ - **Type definitions**: Comprehensive TypeScript types for flows, steps, actions, and events
40
+ - **Event types**: Types for tracking and event handling from `@onlive.ai/tracker`
41
+
42
+ ## Dependencies
43
+
44
+ This package depends on:
45
+
46
+ - **@onlive.ai/tracker**: Event tracking functionality
47
+ - **@onlive.ai/calendar**: Calendar-related utilities
48
+ - **@onlive.ai/common-121**: Shared utilities and types
49
+ - **zod**: Runtime type validation and schema definitions
50
+
51
+ ## Usage
52
+
53
+ ### Basic Import
54
+
55
+ ```typescript
56
+ import { FlowClient } from '@onlive.ai/flow-client';
57
+ // or
58
+ import { FlowClient, type FlowContext, type ClientOptions } from '@onlive.ai/flow-client';
59
+ ```
60
+
61
+ ### Initialization
6
62
 
7
63
  Create an instance of the FlowClient by passing a valid ClientOptions object. The options must conform to the ClientOptionsSchema. The options include:
8
64
 
@@ -20,9 +76,15 @@ const client = new FlowClient({
20
76
  });
21
77
  ```
22
78
 
23
- ## Methods
79
+ ### API Reference
80
+
81
+ #### FlowClient Class
82
+
83
+ The main class for interacting with flows. All methods are type-safe and include runtime validation.
84
+
85
+ #### Methods
24
86
 
25
- ### firstStep(options?: GetStepOptions): Promise<FlowContext>
87
+ ##### firstStep(options?: GetStepOptions): Promise<FlowContext>
26
88
 
27
89
  Initiates the first step of the flow.
28
90
 
@@ -35,7 +97,7 @@ Initiates the first step of the flow.
35
97
  - Sends a POST request to `flow/{flowId}/first-step`.
36
98
  - Analyzes and emits "track" events via the tracking service.
37
99
 
38
- ### getStep(stepId: string, options?: GetStepOptions): Promise<FlowContext>
100
+ ##### getStep(stepId: string, options?: GetStepOptions): Promise<FlowContext>
39
101
 
40
102
  Retrieves a specific step in the flow.
41
103
 
@@ -49,7 +111,7 @@ Retrieves a specific step in the flow.
49
111
  - Sends a POST request to `flow/{flowId}/steps/{stepId}`.
50
112
  - Tracks request and response events.
51
113
 
52
- ### nextStep(trigger: GetStepTrigger, options?: GetStepOptions): Promise<FlowContext>
114
+ ##### nextStep(trigger: GetStepTrigger, options?: GetStepOptions): Promise<FlowContext>
53
115
 
54
116
  Proceeds to the next step in the flow based on user actions.
55
117
 
@@ -65,9 +127,9 @@ Proceeds to the next step in the flow based on user actions.
65
127
  - Sends a POST request to `flow/{flowId}/steps/{currentStepId}/action/{actionId}`.
66
128
  - Analyzes both request and response by emitting tracking events.
67
129
 
68
- ## Event Handling
130
+ #### Event Handling
69
131
 
70
- ### on(type: EventType, listener: EventListener): void
132
+ ##### on(type: EventType, listener: EventListener): void
71
133
 
72
134
  Registers a listener for specific events.
73
135
 
@@ -81,11 +143,94 @@ Internally, FlowClient uses a private `emit` method to deliver events to all reg
81
143
 
82
144
  ## Types & Schemas
83
145
 
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):
146
+ The methods and the overall flow behavior are governed by types and validation schemas defined in the package:
85
147
 
86
148
  - **FlowContext**: Contains the status of the flow, current step details, and flow metadata.
87
149
  - **StepSchema**, **ActionSchema**, **FieldSchema**: Define properties and validation for steps, actions, and form fields.
88
150
  - **GetStepOptions** and **GetStepTrigger**: Govern the payload structure for step operations.
89
151
  - **EventData**: Structure for tracking events, ensuring consistency with the "track" event type.
90
152
 
153
+ ## Features
154
+
155
+ - **Type Safety**: Full TypeScript support with runtime validation using Zod schemas
156
+ - **Event Tracking**: Built-in event tracking for flow interactions
157
+ - **Multi-format Support**: Supports both ESM and CommonJS
158
+ - **Modern API**: Promise-based API with async/await support
159
+ - **Flexible Configuration**: Configurable client options with validation
160
+ - **Error Handling**: Comprehensive error handling with type-safe error responses
161
+
162
+ ## Development
163
+
164
+ ### Building the Package
165
+
166
+ ```bash
167
+ pnpm build:package
168
+ ```
169
+
170
+ ### Running Tests
171
+
172
+ ```bash
173
+ # Run tests
174
+ pnpm test
175
+
176
+ # Run tests with coverage
177
+ pnpm test:coverage
178
+ ```
179
+
180
+ ### Cleaning Build Artifacts
181
+
182
+ ```bash
183
+ pnpm clean
184
+ ```
185
+
186
+ ## Examples
187
+
188
+ ### Complete Flow Example
189
+
190
+ ```typescript
191
+ import { FlowClient } from '@onlive.ai/flow-client';
192
+
193
+ const client = new FlowClient({
194
+ baseUrl: "https://api.example.com",
195
+ flowId: "0123456789abcdef01234567",
196
+ organizationId: "550e8400-e29b-41d4-a716-446655440000",
197
+ lang: "en",
198
+ });
199
+
200
+ // Set up event tracking
201
+ client.on('track', (eventType, eventData) => {
202
+ console.log('Flow event:', eventType, eventData);
203
+ });
204
+
205
+ // Start the flow
206
+ try {
207
+ const firstStep = await client.firstStep();
208
+ console.log('First step:', firstStep);
209
+
210
+ // Progress through the flow
211
+ const nextStep = await client.nextStep({
212
+ currentStepId: firstStep.step.id,
213
+ actionId: 'continue'
214
+ });
215
+
216
+ console.log('Next step:', nextStep);
217
+ } catch (error) {
218
+ console.error('Flow error:', error);
219
+ }
220
+ ```
221
+
222
+ ### Getting a Specific Step
223
+
224
+ ```typescript
225
+ const specificStep = await client.getStep('step-id-123', {
226
+ // optional additional parameters
227
+ });
228
+ ```
229
+
230
+ ## License
231
+
232
+ This package is part of the Onlive workspace and follows the project's licensing terms.
233
+
234
+ ---
235
+
91
236
  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.
@@ -26,12 +26,12 @@ __export(client_service_exports, {
26
26
  default: () => client_service_default
27
27
  });
28
28
  module.exports = __toCommonJS(client_service_exports);
29
- var import_merge2 = require("@packages/common/utils/merge");
29
+ var import_merge2 = require("@onlive.ai/common-121/utils/merge.js");
30
30
 
31
31
  // tracking/tracking.service.ts
32
- var import_tracker = require("@onlive.site/tracker");
33
- var import_merge = require("@packages/common/utils/merge");
34
- var import_browser_preferences = require("@packages/common/utils/browser-preferences.js");
32
+ var import_tracker = require("@onlive.ai/tracker");
33
+ var import_merge = require("@onlive.ai/common-121/utils/merge.js");
34
+ var import_browser_preferences = require("@onlive.ai/common-121/utils/browser-preferences.js");
35
35
 
36
36
  // tracking/tracking.types.ts
37
37
  var import_zod = require("zod");
@@ -237,12 +237,12 @@ var TrackingService = class {
237
237
  var tracking_service_default = TrackingService;
238
238
 
239
239
  // client/client.types.ts
240
- var import_calendar = require("@onlive.site/calendar");
240
+ var import_calendar = require("@onlive.ai/calendar");
241
241
  var import_zod2 = require("zod");
242
242
  var DEFAULT_CLIENT_OPTIONS = {
243
243
  tracking: {
244
244
  removeExtraneousValues: true,
245
- apiUrl: "https://srvless.onlive.site/tracking",
245
+ apiUrl: "https://srvless.onlive.ai/tracking",
246
246
  data: {
247
247
  widget_type: "OnliveAppFlow"
248
248
  }
@@ -1,5 +1,5 @@
1
- import '@onlive.site/tracker';
2
- import { TrackingService } from '../tracking/tracking.service.cjs';
1
+ import '@onlive.ai/tracker';
2
+ import TrackingService from '../tracking/tracking.service.cjs';
3
3
  import { ClientOptions, GetStepOptions, FlowContext, GetStepTrigger } from './client.types.cjs';
4
4
  import '../tracking/tracking.types.cjs';
5
5
  import 'zod';
@@ -1,5 +1,5 @@
1
- import '@onlive.site/tracker';
2
- import { TrackingService } from '../tracking/tracking.service.js';
1
+ import '@onlive.ai/tracker';
2
+ import TrackingService from '../tracking/tracking.service.js';
3
3
  import { ClientOptions, GetStepOptions, FlowContext, GetStepTrigger } from './client.types.js';
4
4
  import '../tracking/tracking.types.js';
5
5
  import 'zod';
@@ -3,12 +3,12 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
5
  // client/client.service.ts
6
- import { merge as merge2 } from "@packages/common/utils/merge";
6
+ import { merge as merge2 } from "@onlive.ai/common-121/utils/merge.js";
7
7
 
8
8
  // tracking/tracking.service.ts
9
- import { Session, Tracker } from "@onlive.site/tracker";
10
- import { merge } from "@packages/common/utils/merge";
11
- import { browserPreferences } from "@packages/common/utils/browser-preferences.js";
9
+ import { Session, Tracker } from "@onlive.ai/tracker";
10
+ import { merge } from "@onlive.ai/common-121/utils/merge.js";
11
+ import { browserPreferences } from "@onlive.ai/common-121/utils/browser-preferences.js";
12
12
 
13
13
  // tracking/tracking.types.ts
14
14
  import { z } from "zod";
@@ -214,12 +214,12 @@ var TrackingService = class {
214
214
  var tracking_service_default = TrackingService;
215
215
 
216
216
  // client/client.types.ts
217
- import { GetAvailabilityFilters, GetAvailabilityOptions } from "@onlive.site/calendar";
217
+ import { GetAvailabilityFilters, GetAvailabilityOptions } from "@onlive.ai/calendar";
218
218
  import { z as z2 } from "zod";
219
219
  var DEFAULT_CLIENT_OPTIONS = {
220
220
  tracking: {
221
221
  removeExtraneousValues: true,
222
- apiUrl: "https://srvless.onlive.site/tracking",
222
+ apiUrl: "https://srvless.onlive.ai/tracking",
223
223
  data: {
224
224
  widget_type: "OnliveAppFlow"
225
225
  }
@@ -8,12 +8,12 @@ var import_vitest = require("vitest");
8
8
  var import_zod3 = require("zod");
9
9
 
10
10
  // client/client.service.ts
11
- var import_merge2 = require("@packages/common/utils/merge");
11
+ var import_merge2 = require("@onlive.ai/common-121/utils/merge.js");
12
12
 
13
13
  // tracking/tracking.service.ts
14
- var import_tracker = require("@onlive.site/tracker");
15
- var import_merge = require("@packages/common/utils/merge");
16
- var import_browser_preferences = require("@packages/common/utils/browser-preferences.js");
14
+ var import_tracker = require("@onlive.ai/tracker");
15
+ var import_merge = require("@onlive.ai/common-121/utils/merge.js");
16
+ var import_browser_preferences = require("@onlive.ai/common-121/utils/browser-preferences.js");
17
17
 
18
18
  // tracking/tracking.types.ts
19
19
  var import_zod = require("zod");
@@ -219,12 +219,12 @@ var TrackingService = class {
219
219
  var tracking_service_default = TrackingService;
220
220
 
221
221
  // client/client.types.ts
222
- var import_calendar = require("@onlive.site/calendar");
222
+ var import_calendar = require("@onlive.ai/calendar");
223
223
  var import_zod2 = require("zod");
224
224
  var DEFAULT_CLIENT_OPTIONS = {
225
225
  tracking: {
226
226
  removeExtraneousValues: true,
227
- apiUrl: "https://srvless.onlive.site/tracking",
227
+ apiUrl: "https://srvless.onlive.ai/tracking",
228
228
  data: {
229
229
  widget_type: "OnliveAppFlow"
230
230
  }
@@ -7,12 +7,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
7
7
  import { ZodError } from "zod";
8
8
 
9
9
  // client/client.service.ts
10
- import { merge as merge2 } from "@packages/common/utils/merge";
10
+ import { merge as merge2 } from "@onlive.ai/common-121/utils/merge.js";
11
11
 
12
12
  // tracking/tracking.service.ts
13
- import { Session, Tracker } from "@onlive.site/tracker";
14
- import { merge } from "@packages/common/utils/merge";
15
- import { browserPreferences } from "@packages/common/utils/browser-preferences.js";
13
+ import { Session, Tracker } from "@onlive.ai/tracker";
14
+ import { merge } from "@onlive.ai/common-121/utils/merge.js";
15
+ import { browserPreferences } from "@onlive.ai/common-121/utils/browser-preferences.js";
16
16
 
17
17
  // tracking/tracking.types.ts
18
18
  import { z } from "zod";
@@ -218,12 +218,12 @@ var TrackingService = class {
218
218
  var tracking_service_default = TrackingService;
219
219
 
220
220
  // client/client.types.ts
221
- import { GetAvailabilityFilters, GetAvailabilityOptions } from "@onlive.site/calendar";
221
+ import { GetAvailabilityFilters, GetAvailabilityOptions } from "@onlive.ai/calendar";
222
222
  import { z as z2 } from "zod";
223
223
  var DEFAULT_CLIENT_OPTIONS = {
224
224
  tracking: {
225
225
  removeExtraneousValues: true,
226
- apiUrl: "https://srvless.onlive.site/tracking",
226
+ apiUrl: "https://srvless.onlive.ai/tracking",
227
227
  data: {
228
228
  widget_type: "OnliveAppFlow"
229
229
  }
@@ -37,7 +37,7 @@ __export(client_types_exports, {
37
37
  StepId: () => StepId
38
38
  });
39
39
  module.exports = __toCommonJS(client_types_exports);
40
- var import_calendar = require("@onlive.site/calendar");
40
+ var import_calendar = require("@onlive.ai/calendar");
41
41
  var import_zod2 = require("zod");
42
42
 
43
43
  // tracking/tracking.types.ts
@@ -60,7 +60,7 @@ var TrackingOptionsSchema = import_zod.z.object({
60
60
  var DEFAULT_CLIENT_OPTIONS = {
61
61
  tracking: {
62
62
  removeExtraneousValues: true,
63
- apiUrl: "https://srvless.onlive.site/tracking",
63
+ apiUrl: "https://srvless.onlive.ai/tracking",
64
64
  data: {
65
65
  widget_type: "OnliveAppFlow"
66
66
  }