@onlive.ai/flow-client 0.1.38 → 0.1.44

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.
@@ -1,747 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
-
22
- // client/client.service.ts
23
- var client_service_exports = {};
24
- __export(client_service_exports, {
25
- FlowClient: () => FlowClient,
26
- default: () => client_service_default
27
- });
28
- module.exports = __toCommonJS(client_service_exports);
29
- var import_merge2 = require("@onlive.ai/common-121/utils/merge.js");
30
-
31
- // tracking/tracking.service.ts
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
-
36
- // tracking/tracking.types.ts
37
- var import_zod = require("zod");
38
- var ONLIVE_FLOW_FORM_NAME = "flow_form";
39
- var ONLIVE_ANALYTICS_EVENT = "onlive-analytics-event";
40
- var TrackingOptionsSchema = import_zod.z.object({
41
- enabled: import_zod.z.boolean().default(false).optional(),
42
- data: import_zod.z.custom().optional(),
43
- removeExtraneousValues: import_zod.z.boolean().default(true).optional(),
44
- allowBotTraffic: import_zod.z.boolean().default(false).optional(),
45
- adapters: import_zod.z.array(import_zod.z.string()).default([]).optional(),
46
- apiUrl: import_zod.z.string().url().optional(),
47
- emitters: import_zod.z.object({
48
- windowEvent: import_zod.z.boolean().optional(),
49
- dataLayer: import_zod.z.boolean().optional(),
50
- windowPostMessage: import_zod.z.boolean().optional()
51
- }).optional()
52
- });
53
-
54
- // tracking/tracking.service.ts
55
- var TrackingService = class {
56
- /**
57
- * Creates a new TrackingService instance.
58
- * @param organizationId - The ID of the organization
59
- * @param flowId - The ID of the flow being tracked
60
- * @param options - Configuration options for the tracking service
61
- * @param devMode - Flag indicating whether to run in development mode
62
- */
63
- constructor(organizationId, flowId, options, devMode) {
64
- /**
65
- * Configuration options for the tracking service.
66
- */
67
- __publicField(this, "options");
68
- /**
69
- * The tracker instance used to send events.
70
- */
71
- __publicField(this, "tracker");
72
- /**
73
- * List of event listeners for tracking events.
74
- */
75
- __publicField(this, "eventListeners", []);
76
- this.options = TrackingOptionsSchema.parse(options);
77
- this.tracker = new import_tracker.Tracker({
78
- apiUrl: this.options.apiUrl,
79
- removeExtraneousValues: this.options.removeExtraneousValues,
80
- allowBotTraffic: this.options.allowBotTraffic,
81
- adapters: this.options.adapters,
82
- dryRun: devMode
83
- });
84
- this.tracker.setBase(
85
- (0, import_merge.merge)(
86
- {},
87
- {
88
- organization_id: organizationId,
89
- page_url: window.location.href,
90
- page_referrer: document.referrer,
91
- origin_medium: "web",
92
- guest_id: import_tracker.Session.id,
93
- interaction_id: import_tracker.Session.interactionId,
94
- extra: {
95
- flow_id: flowId
96
- }
97
- },
98
- this.options.data
99
- )
100
- );
101
- window.addEventListener(
102
- ONLIVE_ANALYTICS_EVENT,
103
- ({ detail }) => this.emit(detail.event, detail.data)
104
- );
105
- }
106
- /**
107
- * Returns the tracker instance used for sending events.
108
- * @returns {Tracker} The tracker instance
109
- */
110
- getTracker() {
111
- return this.tracker;
112
- }
113
- /**
114
- * Returns tracking-related user preferences and session information.
115
- *
116
- * This method combines browser preferences with session identification data
117
- * that can be used for tracking and analytics purposes.
118
- *
119
- * @returns {Object} An object containing browser preferences and session identifiers
120
- * @property {string} interactionId - The current session interaction identifier
121
- * @property {string} guestId - The unique identifier for the current guest/user
122
- */
123
- preferences() {
124
- return {
125
- ...(0, import_browser_preferences.browserPreferences)(),
126
- interactionId: import_tracker.Session.interactionId,
127
- guestId: import_tracker.Session.id
128
- };
129
- }
130
- /**
131
- * Analyzes a request and generates tracking events based on the provided trigger and options.
132
- *
133
- * @param {GetStepTrigger | { stepId?: string }} trigger - The trigger for the step, which can be either a `GetStepTrigger` or an object containing an optional `stepId`.
134
- * @param {GetStepOptions} options - The options for getting the step, including fields for form data.
135
- */
136
- analyzeRequest(trigger, options) {
137
- if ("currentStepId" in trigger) {
138
- if (trigger.actionId) {
139
- this.tracker.send("element_click", {
140
- element_label: trigger.actionId,
141
- element_type: "button",
142
- form_name: Object.keys(options.fields || {}).length ? ONLIVE_FLOW_FORM_NAME : void 0,
143
- step_name: trigger.currentStepId
144
- });
145
- }
146
- if (options.fields) {
147
- this.tracker.send("form_submit", {
148
- form_name: ONLIVE_FLOW_FORM_NAME,
149
- form_data: options.fields,
150
- step_name: trigger.currentStepId
151
- });
152
- }
153
- }
154
- }
155
- /**
156
- * Analyzes the response based on the provided trigger and flow context, and generates tracking events.
157
- *
158
- * @param {GetStepTrigger | { stepId?: string }} trigger - The trigger for the step, which can be either a `GetStepTrigger` or an object containing an optional `stepId`.
159
- * @param {FlowContext} flowContext - The context of the flow, containing information about the current step and its result.
160
- */
161
- analyzeResponse(trigger, flowContext) {
162
- if ("currentStepId" in trigger) {
163
- if (flowContext.step.result?.pipelines) {
164
- flowContext.step.result.pipelines.forEach((pipeline) => {
165
- this.tracker.send("task_success", {
166
- task_name: pipeline.name,
167
- task_data: pipeline.data,
168
- step_name: flowContext.step.id
169
- });
170
- });
171
- }
172
- if (flowContext.step.error) {
173
- this.tracker.send("form_error", {
174
- form_name: ONLIVE_FLOW_FORM_NAME,
175
- form_error: flowContext.step.error.code,
176
- step_name: flowContext.step.id
177
- });
178
- }
179
- }
180
- this.tracker.send("impression", {
181
- impression_type: "step",
182
- form_name: void 0,
183
- step_name: flowContext.step.id,
184
- step_initial: !("currentStepId" in trigger) || void 0,
185
- step_final: flowContext.step.isFinal
186
- });
187
- this.tracker.setBase({
188
- form_name: ONLIVE_FLOW_FORM_NAME,
189
- step_name: flowContext.step.id,
190
- step_initial: !("currentStepId" in trigger) || void 0,
191
- step_final: flowContext.step.isFinal,
192
- ...flowContext.step.result?.tracking
193
- });
194
- }
195
- /**
196
- * Sends an event to the tracker.
197
- *
198
- * This method dispatches an event with the provided name and data to the tracking system.
199
- * Events represent user interactions or system occurrences that should be recorded for analytics.
200
- *
201
- * @param eventName - The name of the event to send
202
- * @param eventData - The data associated with the event
203
- */
204
- send(eventName, eventData) {
205
- this.tracker.send(eventName, eventData);
206
- }
207
- /**
208
- * Sets base data for the tracker that will be included in all future events.
209
- *
210
- * This method defines default properties that will be automatically included
211
- * in every tracking event sent after this call. This is useful for setting
212
- * context information that remains constant across multiple events.
213
- *
214
- * @param data - The base data to set for the tracker
215
- */
216
- setData(data) {
217
- this.tracker.setBase(data);
218
- }
219
- /**
220
- * Registers an event listener to be notified when tracking events are emitted.
221
- *
222
- * @param {function} listener - The callback function to execute when an event is emitted
223
- */
224
- onEvent(listener) {
225
- this.eventListeners.push(listener);
226
- }
227
- /**
228
- * Emits an event to all registered listeners for the specified event name.
229
- *
230
- * @param {EventName} eventName - The name of the event to emit
231
- * @param {EventData} eventData - The data associated with the event
232
- */
233
- emit(eventName, eventData) {
234
- this.eventListeners.forEach((listener) => listener({ event: eventName, data: eventData }));
235
- }
236
- };
237
- var tracking_service_default = TrackingService;
238
-
239
- // client/client.types.ts
240
- var import_calendar = require("@onlive.ai/calendar");
241
- var import_zod2 = require("zod");
242
- var DEFAULT_CLIENT_OPTIONS = {
243
- tracking: {
244
- removeExtraneousValues: true,
245
- apiUrl: "https://srvless.onlive.site/tracking",
246
- data: {
247
- widget_type: "OnliveAppFlow"
248
- }
249
- }
250
- };
251
- var StepId = import_zod2.z.string().nonempty();
252
- var ClientOptions = import_zod2.z.object({
253
- baseUrl: import_zod2.z.string().url().nonempty(),
254
- flowId: import_zod2.z.string().length(24).nonempty(),
255
- organizationId: import_zod2.z.string().uuid().nonempty(),
256
- lang: import_zod2.z.string().length(2).nonempty(),
257
- tracking: TrackingOptionsSchema.optional(),
258
- devMode: import_zod2.z.boolean().default(false).optional()
259
- });
260
- var GetStepOptions = import_zod2.z.object({
261
- state: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional(),
262
- fields: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
263
- });
264
- var GetStepTrigger = import_zod2.z.object({
265
- currentStepId: import_zod2.z.string().nonempty(),
266
- actionId: import_zod2.z.string().nonempty()
267
- });
268
- var FieldType = import_zod2.z.enum([
269
- "text",
270
- "boolean",
271
- "number",
272
- "email",
273
- "phone",
274
- "mobile_phone",
275
- "date",
276
- "time",
277
- "datetime",
278
- "password",
279
- "url",
280
- "color",
281
- "object",
282
- "void",
283
- "location",
284
- "availability"
285
- ]);
286
- var LocationProperty = import_zod2.z.object({
287
- name: import_zod2.z.string(),
288
- value: import_zod2.z.string().optional(),
289
- icon: import_zod2.z.string().optional(),
290
- type: import_zod2.z.enum(["url", "email", "phone"]).optional()
291
- });
292
- var Location = import_zod2.z.object({
293
- lat: import_zod2.z.number().min(-90).max(90),
294
- lng: import_zod2.z.number().min(-180).max(180),
295
- meta: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional(),
296
- properties: import_zod2.z.record(import_zod2.z.string(), LocationProperty).optional(),
297
- attributes: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
298
- });
299
- var Availability = import_zod2.z.object({
300
- datetime: import_zod2.z.string().datetime(),
301
- meta: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
302
- });
303
- var FieldValue = import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number(), import_zod2.z.boolean(), Location, Availability]);
304
- var MapPin = import_zod2.z.object({
305
- content: import_zod2.z.object({
306
- icon: import_zod2.z.string().optional(),
307
- url: import_zod2.z.string().url().optional(),
308
- width: import_zod2.z.string().optional(),
309
- height: import_zod2.z.string().optional(),
310
- scale: import_zod2.z.number().optional()
311
- }).optional(),
312
- background: import_zod2.z.string().optional(),
313
- glyph: import_zod2.z.object({
314
- color: import_zod2.z.string().optional(),
315
- url: import_zod2.z.string().url().optional(),
316
- icon: import_zod2.z.string().optional()
317
- }).optional(),
318
- borderColor: import_zod2.z.string().optional(),
319
- scale: import_zod2.z.number().optional()
320
- });
321
- var FormatDateString = import_zod2.z.custom((val) => /^\d{4}-\d{2}-\d{2}$/.test(val), {
322
- message: "Date must be in 'YYYY-MM-DD' format"
323
- });
324
- var AffixSlot = import_zod2.z.object({
325
- text: import_zod2.z.string().optional(),
326
- icon: import_zod2.z.string().optional()
327
- });
328
- var Field = import_zod2.z.object({
329
- name: import_zod2.z.string().nonempty(),
330
- label: import_zod2.z.string().optional(),
331
- value: import_zod2.z.union([FieldValue, import_zod2.z.array(FieldValue)]).optional(),
332
- type: FieldType,
333
- component: import_zod2.z.enum([
334
- "input",
335
- "textarea",
336
- "select",
337
- "radio",
338
- "checkbox",
339
- "switch",
340
- "rating",
341
- "carousel",
342
- "button",
343
- "label",
344
- "map",
345
- "calendar"
346
- ]).optional(),
347
- disabled: import_zod2.z.boolean().optional(),
348
- readonly: import_zod2.z.boolean().optional(),
349
- multiple: import_zod2.z.boolean().optional(),
350
- placeholder: import_zod2.z.string().optional(),
351
- options: import_zod2.z.array(
352
- import_zod2.z.object({
353
- label: import_zod2.z.string().nonempty(),
354
- value: FieldValue.optional(),
355
- image: import_zod2.z.string().url().optional(),
356
- description: import_zod2.z.string().optional(),
357
- disabled: import_zod2.z.boolean().optional()
358
- })
359
- ).optional(),
360
- required: import_zod2.z.boolean().optional(),
361
- configuration: import_zod2.z.object({
362
- input: import_zod2.z.object({
363
- min: import_zod2.z.number().optional(),
364
- max: import_zod2.z.number().optional(),
365
- step: import_zod2.z.number().optional(),
366
- pattern: import_zod2.z.string().refine((val) => {
367
- try {
368
- new RegExp(val);
369
- return true;
370
- } catch {
371
- return false;
372
- }
373
- }, "Invalid regex pattern").optional(),
374
- minLength: import_zod2.z.number().optional(),
375
- maxLength: import_zod2.z.number().optional(),
376
- exactLength: import_zod2.z.number().optional(),
377
- prefix: import_zod2.z.object({
378
- default: AffixSlot.optional(),
379
- success: AffixSlot.optional(),
380
- error: AffixSlot.optional()
381
- }).optional(),
382
- suffix: import_zod2.z.object({
383
- default: AffixSlot.optional(),
384
- success: AffixSlot.optional(),
385
- error: AffixSlot.optional()
386
- }).optional(),
387
- clearable: import_zod2.z.boolean().optional(),
388
- floatingLabel: import_zod2.z.boolean().optional()
389
- }).optional(),
390
- textarea: import_zod2.z.object({
391
- rows: import_zod2.z.number().optional()
392
- }).optional(),
393
- checkbox: import_zod2.z.object({
394
- layout: import_zod2.z.enum(["horizontal", "vertical"])
395
- }).optional(),
396
- rating: import_zod2.z.object({
397
- icons: import_zod2.z.array(import_zod2.z.string()).optional(),
398
- color: import_zod2.z.string().optional(),
399
- precision: import_zod2.z.number().optional()
400
- }).optional(),
401
- map: import_zod2.z.object({
402
- apiKey: import_zod2.z.string().optional(),
403
- region: import_zod2.z.string().length(2).optional(),
404
- center: import_zod2.z.object({
405
- lat: import_zod2.z.number().min(-90).max(90),
406
- lng: import_zod2.z.number().min(-180).max(180)
407
- }).optional(),
408
- showMap: import_zod2.z.enum(["always", "on-search"]).optional(),
409
- zoom: import_zod2.z.object({
410
- initial: import_zod2.z.number().optional(),
411
- focus: import_zod2.z.number().optional(),
412
- max: import_zod2.z.number().optional(),
413
- min: import_zod2.z.number().optional()
414
- }).optional(),
415
- controls: import_zod2.z.object({
416
- fullscreen: import_zod2.z.boolean().optional(),
417
- mapType: import_zod2.z.boolean().optional(),
418
- zoom: import_zod2.z.boolean().optional(),
419
- rotate: import_zod2.z.boolean().optional(),
420
- scale: import_zod2.z.boolean().optional(),
421
- streetView: import_zod2.z.boolean().optional()
422
- }).optional(),
423
- initialLocations: import_zod2.z.number().optional(),
424
- maxLocations: import_zod2.z.number().optional(),
425
- distanceUnit: import_zod2.z.enum(["km", "mi"]).optional(),
426
- distanceFormat: import_zod2.z.enum(["short", "long"]).optional(),
427
- options: import_zod2.z.object({
428
- show: import_zod2.z.enum(["always", "on-search", "never"]).optional(),
429
- component: import_zod2.z.enum(["list-button", "list-radio", "carousel"]).optional(),
430
- searchLabel: import_zod2.z.string().optional(),
431
- detailsLabel: import_zod2.z.string().optional()
432
- }).optional(),
433
- search: import_zod2.z.object({
434
- value: import_zod2.z.string().optional(),
435
- button: import_zod2.z.object({
436
- label: import_zod2.z.string().optional(),
437
- position: import_zod2.z.enum(["inside", "outside"]).optional()
438
- }).optional(),
439
- placeholder: import_zod2.z.string().optional(),
440
- noResultsText: import_zod2.z.string().optional(),
441
- autocomplete: import_zod2.z.boolean().optional(),
442
- clearable: import_zod2.z.boolean().optional(),
443
- mode: import_zod2.z.enum(["address", "postcode"]).optional(),
444
- showLocationButton: import_zod2.z.boolean().optional(),
445
- locationButton: import_zod2.z.object({
446
- icon: import_zod2.z.string().optional(),
447
- position: import_zod2.z.enum(["left", "right"]).optional()
448
- }).optional()
449
- }).optional(),
450
- distanceRange: import_zod2.z.object({
451
- initial: import_zod2.z.number().optional(),
452
- min: import_zod2.z.number().optional(),
453
- max: import_zod2.z.number().optional(),
454
- step: import_zod2.z.number().optional()
455
- }).optional(),
456
- mapRegion: import_zod2.z.object({
457
- strokeColor: import_zod2.z.string().optional(),
458
- fillColor: import_zod2.z.string().optional(),
459
- fillOpacity: import_zod2.z.number().optional()
460
- }).optional(),
461
- locationPin: MapPin.optional(),
462
- markerPin: import_zod2.z.object({
463
- default: MapPin.optional(),
464
- hover: MapPin.optional(),
465
- selected: MapPin.optional()
466
- }).optional(),
467
- infoWindow: import_zod2.z.object({
468
- button: import_zod2.z.object({
469
- label: import_zod2.z.string(),
470
- action: import_zod2.z.string()
471
- }).optional()
472
- }).optional()
473
- }).optional(),
474
- calendar: import_zod2.z.object({
475
- current: import_zod2.z.object({
476
- month: import_zod2.z.number().min(0).max(11).optional(),
477
- year: import_zod2.z.number().optional()
478
- }).optional(),
479
- range: import_zod2.z.object({
480
- min: FormatDateString.optional(),
481
- max: FormatDateString.optional(),
482
- enabled: import_zod2.z.array(FormatDateString).optional(),
483
- disabled: import_zod2.z.array(FormatDateString).optional()
484
- }).optional(),
485
- time: import_zod2.z.object({
486
- label: import_zod2.z.string().optional(),
487
- format: import_zod2.z.enum(["12h", "24h"]).optional(),
488
- component: import_zod2.z.enum(["carousel", "list"]).optional()
489
- }).optional(),
490
- api: import_zod2.z.object({
491
- url: import_zod2.z.string().url().nonempty(),
492
- organizationId: import_zod2.z.string().nonempty(),
493
- availability: import_zod2.z.object({
494
- filters: import_calendar.GetAvailabilityFilters,
495
- options: import_calendar.GetAvailabilityOptions.optional()
496
- }).optional()
497
- }).optional()
498
- }).optional()
499
- }).optional(),
500
- dependsOn: import_zod2.z.array(
501
- import_zod2.z.object({
502
- fieldName: import_zod2.z.string().nonempty(),
503
- value: FieldValue.optional()
504
- })
505
- ).optional(),
506
- dependentBehavior: import_zod2.z.enum(["hidden", "disabled"]).optional(),
507
- customError: import_zod2.z.object({
508
- required: import_zod2.z.string().optional(),
509
- invalid: import_zod2.z.string().optional(),
510
- minLength: import_zod2.z.string().optional(),
511
- maxLength: import_zod2.z.string().optional(),
512
- minValue: import_zod2.z.string().optional(),
513
- maxValue: import_zod2.z.string().optional(),
514
- mismatch: import_zod2.z.string().optional()
515
- }).optional()
516
- });
517
- var ActionScript = import_zod2.z.object({
518
- src: import_zod2.z.string().url(),
519
- preload: import_zod2.z.boolean().optional(),
520
- name: import_zod2.z.string().nonempty(),
521
- function: import_zod2.z.string().nonempty(),
522
- params: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
523
- });
524
- var ActionEvent = import_zod2.z.object({
525
- name: import_zod2.z.enum(["organization_call", "close_panel"]),
526
- params: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
527
- });
528
- var Action = import_zod2.z.object({
529
- id: import_zod2.z.string().nonempty(),
530
- type: import_zod2.z.enum(["submit", "navigate", "link", "back", "dispatcher", "script"]),
531
- label: import_zod2.z.string().nonempty(),
532
- variant: import_zod2.z.enum(["primary", "secondary", "success", "danger", "warning", "info"]),
533
- url: import_zod2.z.string().url().optional(),
534
- scripts: ActionScript.array().optional(),
535
- events: ActionEvent.array().optional()
536
- });
537
- var ErrorCode = import_zod2.z.enum([
538
- "INVALID_DATA",
539
- "INVALID_ACTION",
540
- "STEP_NOT_FOUND",
541
- "UNKNOWN_ERROR",
542
- "APPOINTMENT_INVALID_DATA",
543
- "APPOINTMENT_BUSY_SLOT",
544
- "APPOINTMENT_OUT_OF_DATE",
545
- "APPOINTMENT_UNKNOWN_ERROR",
546
- "LEAD_INVALID_DATA",
547
- "LEAD_UNKNOWN_ERROR",
548
- "CONTENT_INVALID_DATA",
549
- "CONTENT_UNKNOWN_ERROR",
550
- "CONTACT_INVALID_DATA",
551
- "CONTACT_UNKNOWN_ERROR",
552
- "LOST_OPPORTUNITY_INVALID_DATA",
553
- "LOST_OPPORTUNITY_UNKNOWN_ERROR"
554
- ]);
555
- var PostAction = import_zod2.z.object({
556
- type: import_zod2.z.enum(["redirect"]),
557
- params: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
558
- });
559
- var Step = import_zod2.z.object({
560
- id: import_zod2.z.string().nonempty(),
561
- title: import_zod2.z.string().optional(),
562
- description: import_zod2.z.string().optional(),
563
- stageId: import_zod2.z.string().optional(),
564
- state: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional(),
565
- fields: import_zod2.z.array(Field).optional(),
566
- actions: import_zod2.z.array(Action).optional(),
567
- result: import_zod2.z.object({
568
- postActions: import_zod2.z.array(PostAction).optional(),
569
- pipelines: import_zod2.z.array(import_zod2.z.object({ name: import_zod2.z.string(), data: import_zod2.z.object({}) })).optional(),
570
- tracking: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.any()).optional()
571
- }).optional(),
572
- error: import_zod2.z.object({
573
- code: ErrorCode,
574
- message: import_zod2.z.string().optional(),
575
- fields: import_zod2.z.array(
576
- import_zod2.z.object({
577
- name: import_zod2.z.string(),
578
- type: FieldType,
579
- value: import_zod2.z.any(),
580
- error: import_zod2.z.string()
581
- })
582
- ).optional()
583
- }).optional(),
584
- isFinal: import_zod2.z.boolean().optional()
585
- });
586
- var Flow = import_zod2.z.object({
587
- id: import_zod2.z.string().length(24).nonempty(),
588
- organizationId: import_zod2.z.string().uuid().nonempty(),
589
- updatedAt: import_zod2.z.string().datetime().nonempty(),
590
- stages: import_zod2.z.array(
591
- import_zod2.z.object({
592
- id: import_zod2.z.string().nonempty(),
593
- name: import_zod2.z.string().nonempty()
594
- })
595
- )
596
- });
597
- var FlowContext = import_zod2.z.object({
598
- status: import_zod2.z.enum(["ok", "error"]),
599
- step: Step,
600
- flow: Flow
601
- });
602
- var EventType = import_zod2.z.enum(["track"]);
603
-
604
- // client/client.service.ts
605
- var FlowClient = class {
606
- /**
607
- * Creates a new FlowClient instance.
608
- * @param _options - Configuration options for the client
609
- */
610
- constructor(_options) {
611
- /**
612
- * The base URL for API requests.
613
- */
614
- __publicField(this, "baseURL");
615
- /**
616
- * HTTP headers to be sent with each request.
617
- */
618
- __publicField(this, "headers");
619
- /**
620
- * The unique identifier of the flow.
621
- */
622
- __publicField(this, "flowId");
623
- /**
624
- * Service for tracking user interactions and events.
625
- * Only available if tracking is enabled in the options.
626
- */
627
- __publicField(this, "tracking");
628
- const options = (0, import_merge2.merge)(
629
- {},
630
- DEFAULT_CLIENT_OPTIONS,
631
- ClientOptions.parse(_options)
632
- );
633
- this.flowId = options.flowId;
634
- this.baseURL = options.baseUrl;
635
- this.headers = new Headers({
636
- "Content-Type": "application/json",
637
- "X-Onlive-Organization-Id": options.organizationId,
638
- "X-Lang": options.lang
639
- });
640
- if (options.tracking?.enabled) {
641
- this.tracking = new tracking_service_default(
642
- options.organizationId,
643
- options.flowId,
644
- options.tracking,
645
- !!options.devMode
646
- );
647
- }
648
- }
649
- /**
650
- * Sends an HTTP request to the specified path and returns the response as a JSON object.
651
- *
652
- * @template T - The expected response type.
653
- * @param {string} path - The path to which the request is sent.
654
- * @param {RequestInit} [options={}] - Optional configuration for the request.
655
- * @returns {Promise<T>} - A promise that resolves to the response data.
656
- * @throws {Error} - Throws an error if the response status is not ok.
657
- */
658
- async request(path, options = {}) {
659
- const response = await fetch(`${this.baseURL}/${path}`, {
660
- ...options,
661
- headers: this.headers
662
- });
663
- if (!response?.ok) {
664
- throw new Error(`HTTP error! status: ${response?.status || "unknown"}`);
665
- }
666
- return response.json();
667
- }
668
- /**
669
- * Initiates the first step of the flow process.
670
- *
671
- * @param {GetStepOptions} options - Optional parameters for getting the step.
672
- * @returns {Promise<FlowContext>} A promise that resolves to the flow context.
673
- */
674
- async firstStep(options = {}) {
675
- this.tracking?.analyzeRequest({}, options);
676
- const preferences = this.tracking?.preferences();
677
- const flowContext = await this.request(`flow/${this.flowId}/first-step`, {
678
- method: "POST",
679
- body: JSON.stringify(
680
- GetStepOptions.parse({
681
- ...options,
682
- state: {
683
- preferences,
684
- ...options.state
685
- }
686
- })
687
- )
688
- });
689
- this.tracking?.analyzeResponse({}, flowContext);
690
- return flowContext;
691
- }
692
- /**
693
- * Retrieves a specific step in the flow based on the provided step ID.
694
- *
695
- * @param {string} stepId - The unique identifier of the step to retrieve.
696
- * @param {GetStepOptions} options - Optional parameters for customizing the step request.
697
- * @returns {Promise<FlowContext>} A promise that resolves to the flow context containing the requested step information.
698
- * @throws {Error} If the step ID is invalid or the step cannot be found.
699
- */
700
- async getStep(stepId, options = {}) {
701
- this.tracking?.analyzeRequest({ stepId }, options);
702
- const preferences = this.tracking?.preferences();
703
- const flowContext = await this.request(
704
- `flow/${this.flowId}/steps/${StepId.parse(stepId)}`,
705
- {
706
- method: "POST",
707
- body: JSON.stringify(
708
- GetStepOptions.parse({
709
- ...options,
710
- state: {
711
- preferences,
712
- ...options.state
713
- }
714
- })
715
- )
716
- }
717
- );
718
- this.tracking?.analyzeResponse({ stepId }, flowContext);
719
- return flowContext;
720
- }
721
- /**
722
- * Advances to the next step in the flow based on the provided trigger action.
723
- *
724
- * @param {GetStepTrigger} trigger - Contains the current step ID and action ID to determine the next step.
725
- * @param {GetStepOptions} options - Optional parameters to customize the step transition.
726
- * @returns {Promise<FlowContext>} A promise that resolves to the updated flow context containing the next step information.
727
- * @throws {Error} If the action is invalid or the next step cannot be determined.
728
- */
729
- async nextStep(trigger, options = {}) {
730
- this.tracking?.analyzeRequest(trigger, options);
731
- const { currentStepId, actionId } = GetStepTrigger.parse(trigger);
732
- const flowContext = await this.request(
733
- `flow/${this.flowId}/steps/${currentStepId}/action/${actionId}`,
734
- {
735
- method: "POST",
736
- body: JSON.stringify(GetStepOptions.parse(options))
737
- }
738
- );
739
- this.tracking?.analyzeResponse(trigger, flowContext);
740
- return flowContext;
741
- }
742
- };
743
- var client_service_default = FlowClient;
744
- // Annotate the CommonJS export names for ESM import in node:
745
- 0 && (module.exports = {
746
- FlowClient
747
- });
1
+ /*! @onlive.ai/flow-client v0.1.44 | © 2025 Onlive.ai */
2
+ "use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var z=(i,e,o)=>e in i?d(i,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[e]=o;var R=(i,e)=>{for(var o in e)d(i,o,{get:e[o],enumerable:!0})},P=(i,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of L(e))!D.call(i,r)&&r!==o&&d(i,r,{get:()=>e[r],enumerable:!(n=w(e,r))||n.enumerable});return i};var F=i=>P(d({},"__esModule",{value:!0}),i);var p=(i,e,o)=>z(i,typeof e!="symbol"?e+"":e,o);var J={};R(J,{FlowClient:()=>v,default:()=>H});module.exports=F(J);var A=require("@onlive.ai/common-121/utils/merge.js");var l=require("@onlive.ai/tracker"),_=require("@onlive.ai/common-121/utils/merge.js"),O=require("@onlive.ai/common-121/utils/browser-preferences.js");var a=require("zod"),m="flow_form",T="onlive-analytics-event",u=a.z.object({enabled:a.z.boolean().default(!1).optional(),data:a.z.custom().optional(),removeExtraneousValues:a.z.boolean().default(!0).optional(),allowBotTraffic:a.z.boolean().default(!1).optional(),adapters:a.z.array(a.z.string()).default([]).optional(),apiUrl:a.z.string().url().optional(),emitters:a.z.object({windowEvent:a.z.boolean().optional(),dataLayer:a.z.boolean().optional(),windowPostMessage:a.z.boolean().optional()}).optional()});var x=class{constructor(e,o,n,r){p(this,"options");p(this,"tracker");p(this,"eventListeners",[]);this.options=u.parse(n),this.tracker=new l.Tracker({apiUrl:this.options.apiUrl,removeExtraneousValues:this.options.removeExtraneousValues,allowBotTraffic:this.options.allowBotTraffic,adapters:this.options.adapters,dryRun:r}),this.tracker.setBase((0,_.merge)({},{organization_id:e,page_url:window.location.href,page_referrer:document.referrer,origin_medium:"web",guest_id:l.Session.id,interaction_id:l.Session.interactionId,extra:{flow_id:o}},this.options.data)),window.addEventListener(T,({detail:c})=>this.emit(c.event,c.data))}getTracker(){return this.tracker}preferences(){return{...(0,O.browserPreferences)(),interactionId:l.Session.interactionId,guestId:l.Session.id}}analyzeRequest(e,o){"currentStepId"in e&&(e.actionId&&this.tracker.send("element_click",{element_label:e.actionId,element_type:"button",form_name:Object.keys(o.fields||{}).length?m:void 0,step_name:e.currentStepId}),o.fields&&this.tracker.send("form_submit",{form_name:m,form_data:o.fields,step_name:e.currentStepId}))}analyzeResponse(e,o){"currentStepId"in e&&(o.step.result?.pipelines&&o.step.result.pipelines.forEach(n=>{this.tracker.send("task_success",{task_name:n.name,task_data:n.data,step_name:o.step.id})}),o.step.error&&this.tracker.send("form_error",{form_name:m,form_error:o.step.error.code,step_name:o.step.id})),this.tracker.send("impression",{impression_type:"step",form_name:void 0,step_name:o.step.id,step_initial:!("currentStepId"in e)||void 0,step_final:o.step.isFinal}),this.tracker.setBase({form_name:m,step_name:o.step.id,step_initial:!("currentStepId"in e)||void 0,step_final:o.step.isFinal,...o.step.result?.tracking})}send(e,o){this.tracker.send(e,o)}setData(e){this.tracker.setBase(e)}onEvent(e){this.eventListeners.push(e)}emit(e,o){this.eventListeners.forEach(n=>n({event:e,data:o}))}},E=x;var y=require("@onlive.ai/calendar"),t=require("zod");var N={tracking:{removeExtraneousValues:!0,apiUrl:"https://srvless.onlive.site/tracking",data:{widget_type:"OnliveAppFlow"}}},I=t.z.string().nonempty(),j=t.z.object({baseUrl:t.z.string().url().nonempty(),flowId:t.z.string().length(24).nonempty(),organizationId:t.z.string().uuid().nonempty(),lang:t.z.string().length(2).nonempty(),tracking:u.optional(),devMode:t.z.boolean().default(!1).optional()}),h=t.z.object({state:t.z.record(t.z.string(),t.z.any()).optional(),fields:t.z.record(t.z.string(),t.z.any()).optional()}),k=t.z.object({currentStepId:t.z.string().nonempty(),actionId:t.z.string().nonempty()}),S=t.z.enum(["text","boolean","number","email","phone","mobile_phone","date","time","datetime","password","url","color","object","void","location","availability"]),C=t.z.object({name:t.z.string(),value:t.z.string().optional(),icon:t.z.string().optional(),type:t.z.enum(["url","email","phone"]).optional()}),U=t.z.object({lat:t.z.number().min(-90).max(90),lng:t.z.number().min(-180).max(180),meta:t.z.record(t.z.string(),t.z.any()).optional(),properties:t.z.record(t.z.string(),C).optional()}),V=t.z.object({datetime:t.z.string().datetime(),meta:t.z.record(t.z.string(),t.z.any()).optional()}),g=t.z.union([t.z.string(),t.z.number(),t.z.boolean(),U,V]),b=t.z.object({content:t.z.object({icon:t.z.string().optional(),url:t.z.string().url().optional(),width:t.z.string().optional(),height:t.z.string().optional(),scale:t.z.number().optional()}).optional(),background:t.z.string().optional(),glyph:t.z.object({color:t.z.string().optional(),url:t.z.string().url().optional(),icon:t.z.string().optional()}).optional(),borderColor:t.z.string().optional(),scale:t.z.number().optional()}),f=t.z.custom(i=>/^\d{4}-\d{2}-\d{2}$/.test(i),{message:"Date must be in 'YYYY-MM-DD' format"}),s=t.z.object({text:t.z.string().optional(),icon:t.z.string().optional()}),M=t.z.object({name:t.z.string().nonempty(),label:t.z.string().optional(),value:t.z.union([g,t.z.array(g)]).optional(),type:S,component:t.z.enum(["input","textarea","select","radio","checkbox","switch","rating","carousel","button","label","map","calendar"]).optional(),disabled:t.z.boolean().optional(),readonly:t.z.boolean().optional(),multiple:t.z.boolean().optional(),placeholder:t.z.string().optional(),options:t.z.array(t.z.object({label:t.z.string().nonempty(),value:g.optional(),image:t.z.string().url().optional(),description:t.z.string().optional(),disabled:t.z.boolean().optional(),attributes:t.z.record(t.z.string(),t.z.any()).optional()})).optional(),required:t.z.boolean().optional(),configuration:t.z.object({input:t.z.object({min:t.z.number().optional(),max:t.z.number().optional(),step:t.z.number().optional(),pattern:t.z.string().refine(i=>{try{return new RegExp(i),!0}catch{return!1}},"Invalid regex pattern").optional(),minLength:t.z.number().optional(),maxLength:t.z.number().optional(),exactLength:t.z.number().optional(),prefix:t.z.object({default:s.optional(),success:s.optional(),error:s.optional()}).optional(),suffix:t.z.object({default:s.optional(),success:s.optional(),error:s.optional()}).optional(),clearable:t.z.boolean().optional(),floatingLabel:t.z.boolean().optional()}).optional(),textarea:t.z.object({rows:t.z.number().optional()}).optional(),checkbox:t.z.object({layout:t.z.enum(["horizontal","vertical"])}).optional(),rating:t.z.object({icons:t.z.array(t.z.string()).optional(),color:t.z.string().optional(),precision:t.z.number().optional()}).optional(),map:t.z.object({apiKey:t.z.string().optional(),region:t.z.string().length(2).optional(),center:t.z.object({lat:t.z.number().min(-90).max(90),lng:t.z.number().min(-180).max(180)}).optional(),showMap:t.z.enum(["always","on-search"]).optional(),zoom:t.z.object({initial:t.z.number().optional(),focus:t.z.number().optional(),max:t.z.number().optional(),min:t.z.number().optional()}).optional(),controls:t.z.object({fullscreen:t.z.boolean().optional(),mapType:t.z.boolean().optional(),zoom:t.z.boolean().optional(),rotate:t.z.boolean().optional(),scale:t.z.boolean().optional(),streetView:t.z.boolean().optional()}).optional(),initialLocations:t.z.number().optional(),maxLocations:t.z.number().optional(),distanceUnit:t.z.enum(["km","mi"]).optional(),distanceFormat:t.z.enum(["short","long"]).optional(),options:t.z.object({show:t.z.enum(["always","on-search","never"]).optional(),component:t.z.enum(["list-button","list-radio","carousel"]).optional(),searchLabel:t.z.string().optional(),detailsLabel:t.z.string().optional()}).optional(),search:t.z.object({value:t.z.string().optional(),button:t.z.object({label:t.z.string().optional(),position:t.z.enum(["inside","outside"]).optional()}).optional(),placeholder:t.z.string().optional(),noResultsText:t.z.string().optional(),autocomplete:t.z.boolean().optional(),clearable:t.z.boolean().optional(),mode:t.z.enum(["address","postcode"]).default("postcode").optional(),locationButton:t.z.object({icon:t.z.string().optional(),position:t.z.enum(["left","right"]).optional()}).optional(),prefix:t.z.object({default:s.optional()}).optional(),suffix:t.z.object({default:s.optional()}).optional(),mappedResults:t.z.object({mapping:t.z.record(t.z.string(),t.z.array(t.z.object({key:t.z.string(),value:t.z.string()})))}).optional()}).optional(),distanceRange:t.z.object({initial:t.z.number().optional(),min:t.z.number().optional(),max:t.z.number().optional(),step:t.z.number().optional()}).optional(),mapRegion:t.z.object({strokeColor:t.z.string().optional(),fillColor:t.z.string().optional(),fillOpacity:t.z.number().optional()}).optional(),locationPin:b.optional(),markerPin:t.z.object({default:b.optional(),hover:b.optional(),selected:b.optional()}).optional(),infoWindow:t.z.object({button:t.z.object({label:t.z.string(),action:t.z.string()}).optional()}).optional()}).optional(),calendar:t.z.object({current:t.z.object({month:t.z.number().min(0).max(11).optional(),year:t.z.number().optional()}).optional(),range:t.z.object({min:f.optional(),max:f.optional(),enabled:t.z.array(f).optional(),disabled:t.z.array(f).optional()}).optional(),time:t.z.object({label:t.z.string().optional(),format:t.z.enum(["12h","24h"]).optional(),component:t.z.enum(["carousel","list"]).optional()}).optional(),api:t.z.object({url:t.z.string().url().nonempty(),organizationId:t.z.string().nonempty(),availability:t.z.object({filters:y.GetAvailabilityFilters,options:y.GetAvailabilityOptions.optional()}).optional()}).optional()}).optional()}).optional(),dependsOn:t.z.array(t.z.object({fieldName:t.z.string().nonempty(),value:g.optional()})).optional(),dependentBehavior:t.z.enum(["hidden","disabled"]).optional(),customError:t.z.object({required:t.z.string().optional(),invalid:t.z.string().optional(),minLength:t.z.string().optional(),maxLength:t.z.string().optional(),minValue:t.z.string().optional(),maxValue:t.z.string().optional(),mismatch:t.z.string().optional()}).optional()}),G=t.z.object({src:t.z.string().url(),preload:t.z.boolean().optional(),name:t.z.string().nonempty(),function:t.z.string().nonempty(),params:t.z.record(t.z.string(),t.z.any()).optional()}),$=t.z.object({name:t.z.enum(["organization_call","close_panel"]),params:t.z.record(t.z.string(),t.z.any()).optional()}),q=t.z.object({id:t.z.string().nonempty(),type:t.z.enum(["submit","navigate","link","back","dispatcher","script"]),label:t.z.string().nonempty(),variant:t.z.enum(["primary","secondary","success","danger","warning","info"]),url:t.z.string().url().optional(),scripts:G.array().optional(),events:$.array().optional()}),B=t.z.enum(["INVALID_DATA","INVALID_ACTION","STEP_NOT_FOUND","UNKNOWN_ERROR","APPOINTMENT_INVALID_DATA","APPOINTMENT_BUSY_SLOT","APPOINTMENT_OUT_OF_DATE","APPOINTMENT_UNKNOWN_ERROR","LEAD_INVALID_DATA","LEAD_UNKNOWN_ERROR","CONTENT_INVALID_DATA","CONTENT_UNKNOWN_ERROR","CONTACT_INVALID_DATA","CONTACT_UNKNOWN_ERROR","LOST_OPPORTUNITY_INVALID_DATA","LOST_OPPORTUNITY_UNKNOWN_ERROR"]),W=t.z.object({type:t.z.enum(["redirect"]),params:t.z.record(t.z.string(),t.z.any()).optional()}),Y=t.z.object({id:t.z.string().nonempty(),title:t.z.string().optional(),description:t.z.string().optional(),stageId:t.z.string().optional(),state:t.z.record(t.z.string(),t.z.any()).optional(),fields:t.z.array(M).optional(),actions:t.z.array(q).optional(),result:t.z.object({postActions:t.z.array(W).optional(),pipelines:t.z.array(t.z.object({name:t.z.string(),data:t.z.object({})})).optional(),tracking:t.z.record(t.z.string(),t.z.any()).optional()}).optional(),error:t.z.object({code:B,message:t.z.string().optional(),fields:t.z.array(t.z.object({name:t.z.string(),type:S,value:t.z.any(),error:t.z.string()})).optional()}).optional(),isFinal:t.z.boolean().optional()}),K=t.z.object({id:t.z.string().length(24).nonempty(),organizationId:t.z.string().uuid().nonempty(),updatedAt:t.z.string().datetime().nonempty(),stages:t.z.array(t.z.object({id:t.z.string().nonempty(),name:t.z.string().nonempty()}))}),pt=t.z.object({status:t.z.enum(["ok","error"]),step:Y,flow:K}),st=t.z.enum(["track"]);var v=class{constructor(e){p(this,"baseURL");p(this,"headers");p(this,"flowId");p(this,"tracking");let o=(0,A.merge)({},N,j.parse(e));this.flowId=o.flowId,this.baseURL=o.baseUrl,this.headers=new Headers({"Content-Type":"application/json","X-Onlive-Organization-Id":o.organizationId,"X-Lang":o.lang}),o.tracking?.enabled&&(this.tracking=new E(o.organizationId,o.flowId,o.tracking,!!o.devMode))}async request(e,o={}){let n=await fetch(`${this.baseURL}/${e}`,{...o,headers:this.headers});if(!n?.ok)throw new Error(`HTTP error! status: ${n?.status||"unknown"}`);return n.json()}async firstStep(e={}){this.tracking?.analyzeRequest({},e);let o=this.tracking?.preferences(),n=await this.request(`flow/${this.flowId}/first-step`,{method:"POST",body:JSON.stringify(h.parse({...e,state:{preferences:o,...e.state}}))});return this.tracking?.analyzeResponse({},n),n}async getStep(e,o={}){this.tracking?.analyzeRequest({stepId:e},o);let n=this.tracking?.preferences(),r=await this.request(`flow/${this.flowId}/steps/${I.parse(e)}`,{method:"POST",body:JSON.stringify(h.parse({...o,state:{preferences:n,...o.state}}))});return this.tracking?.analyzeResponse({stepId:e},r),r}async nextStep(e,o={}){this.tracking?.analyzeRequest(e,o);let{currentStepId:n,actionId:r}=k.parse(e),c=await this.request(`flow/${this.flowId}/steps/${n}/action/${r}`,{method:"POST",body:JSON.stringify(h.parse(o))});return this.tracking?.analyzeResponse(e,c),c}},H=v;0&&(module.exports={FlowClient});