@blazeo.com/calendar-client 1.0.3 → 1.0.5

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,50 +1,54 @@
1
- # @blazeo.com/calendar-client
2
-
3
- **Private package** – for Blazeo internal teams only. JavaScript client for the Blazeo Calendar / Appointment API. Use it in React (or any JS app) to call calendar and event endpoints via MobX State Tree models.
4
-
5
- ## Install
6
-
7
- From your npm registry (internal teams; ensure you're logged in to the scope):
8
-
9
- ```bash
10
- npm install @blazeo.com/calendar-client
11
- ```
12
-
13
- Or link locally:
14
-
15
- ```bash
16
- cd calendar-client && npm run build && npm link
17
- cd your-app && npm link @blazeo.com/calendar-client
18
- ```
19
-
20
- ## Usage
21
-
22
- Configure once at app startup, then use models and their methods:
23
-
24
- ```js
25
- import { configure, setBaseUrl, CalendarModel, createRootStore } from '@blazeo.com/calendar-client';
26
-
27
- configure({ baseUrl: 'https://your-appointment-api.example.com' });
28
- // or: setBaseUrl('https://localhost:7051');
29
-
30
- // Calendar static methods (no store needed)
31
- const timezones = await CalendarModel.getTimeZones();
32
- const calendar = await CalendarModel.get('calendar-guid');
33
-
34
- // Or use RootStore with models
35
- const store = createRootStore();
36
- const cal = store.addCalendar({ calendarId: 'my-cal', name: 'My Calendar' });
37
- await cal.create(); // POST to backend
38
- ```
39
-
40
- ## API overview
41
-
42
- - **CalendarModel (static):** `get`, `getByCompany`, `getTimeZones`, `getTimeZone`, `getParticipants`, `getMonth`, `getEvents`, etc.
43
- - **EventModel (instance):** `get`, `create`, `cancel`, `getCancellable`, `getAvailability`, `setReminder`
44
- - **RootStore:** `addCalendar`, `addEvent`
45
-
46
- All methods return `Promise<{ status, data?, message? }>`. Check `response.status === 'success'` and use `response.data`.
47
-
48
- ## Sample
49
-
50
- See the `sample` folder for a minimal React app that uses this package.
1
+ # @blazeo.com/calendar-client
2
+
3
+ **Private package** – for Blazeo internal teams only. JavaScript client for the Blazeo Calendar / Appointment API. Use it in React (or any JS app) to call calendar and event endpoints via MobX State Tree models.
4
+
5
+ ## Install
6
+
7
+ From your npm registry (internal teams; ensure you're logged in to the scope):
8
+
9
+ ```bash
10
+ npm install @blazeo.com/calendar-client
11
+ ```
12
+
13
+ Or link locally:
14
+
15
+ ```bash
16
+ cd calendar-client && npm run build && npm link
17
+ cd your-app && npm link @blazeo.com/calendar-client
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Configure once at app startup, then use models and their methods:
23
+
24
+ ```js
25
+ import { configure, setBaseUrl, setConsumer, CalendarModel, createRootStore } from '@blazeo.com/calendar-client';
26
+
27
+ configure({ baseUrl: 'https://your-appointment-api.example.com' });
28
+ // or: setBaseUrl('https://localhost:7051');
29
+ setConsumer('my-app'); // optional: sent as Consumer header (e.g. for lead source)
30
+
31
+ // Calendar static methods (no store needed)
32
+ const timezones = await CalendarModel.getTimeZones();
33
+ const calendar = await CalendarModel.get('calendar-guid');
34
+
35
+ // Or use RootStore with models
36
+ const store = createRootStore();
37
+ const cal = store.addCalendar({ calendarId: 'my-cal', name: 'My Calendar' });
38
+ await cal.create(); // POST to backend
39
+ ```
40
+
41
+ ## API overview
42
+
43
+ - **CalendarModel (static):** `get`, `getByCompany`, `getTimeZones`, `getTimeZone`, `getParticipants`, `getMonth`, `getEvents`, etc.
44
+ - **EventModel (instance):** `get`, `create`, `cancel`, `getCancellable`, `getAvailability`, `setReminder`
45
+ - **FlowModel:** Same pattern as Calendar — `FlowModel.create({}, { env })` with no fields; static `get`, `getRaw`, `list`, `createFlow`, `updateFlow`, `delete`, `duplicate`, appearance/embed/public/preview helpers; instance methods mirror those using `flowId` on the snapshot
46
+ - **LeadModel:** `LeadModel.create({}, { env })`; static `get`, `getRaw`, `getByEmail`, `getByCompany`; instance `get`, `getByEmail`, `getByCompany` (uses `leadId` / `email` / `companyKey` on the snapshot)
47
+ - **RootStore:** `addCalendar`, `addEvent`
48
+
49
+ All methods return `Promise<{ status, data?, message? }>`. Check `response.status === 'success'` and use `response.data`.
50
+
51
+ ## Samples
52
+
53
+ - **`sample/`** – Uses the package via `file:..` for local development (run `npm run build` in parent first).
54
+ - **`sample-npm/`** – Uses the package from npm: `npm i @blazeo.com/calendar-client`. For testing the published package.
package/dist/index.d.ts CHANGED
@@ -1,101 +1,129 @@
1
- /** @blazeo.com/calendar-client - type declarations */
2
-
3
- export function configure(env: { baseUrl?: string; fetch?: typeof fetch; getDefaultOffset?: () => number }): void;
4
- export function getConfig(): { baseUrl?: string; fetch?: typeof fetch; getDefaultOffset?: () => number } | null;
5
- export function setBaseUrl(baseUrl: string): void;
6
- export function getConfigStore(): unknown;
7
-
8
- export const ConfigModel: unknown;
9
-
10
- export const CalendarModel: {
11
- get(calendarId: string): Promise<unknown>;
12
- getRaw(calendarId: string): Promise<{ status: string; data?: unknown; message?: string }>;
13
- getByCompany(companyKey: string): Promise<unknown[]>;
14
- getTimeZones(): Promise<unknown>;
15
- getTimeZone(timezoneId: string): Promise<unknown>;
16
- getParticipants(calendarId: string): Promise<unknown>;
17
- getCalendarParticipant(calendarId: string): Promise<unknown>;
18
- getParticipantsInfo(calendarId: string): Promise<unknown>;
19
- getMonth(calendarId: string, year: number, month: number): Promise<unknown>;
20
- getEvents(calendarId: string): Promise<unknown>;
21
- createWithParticipants(name: string, companyKey: string, participantIds: string[], description: string, calendarId?: string): Promise<unknown>;
22
- editWithParticipants(calendarId: string, name: string, participantIds: string[], description: string): Promise<unknown>;
23
- create(snapshot: object, options?: { env?: object }): unknown;
24
- };
25
-
26
- export const EventModel: {
27
- get(eventId: string): Promise<unknown>;
28
- getByExternalId(externalEventId: string): Promise<unknown>;
29
- getRoundRobinParticipant(calendarId: string): Promise<unknown>;
30
- getEarliestAvailableDays(calendarId: string, count: number, opts?: { year?: number; month?: number; day?: number; offset?: number }): Promise<string[] | null>;
31
- getDaySelectable(calendarId: string, year: number, month: number, day: number, opts?: { participantId?: string; offset?: number }): Promise<boolean>;
32
- getByVisitorEmail(email: string, opts: { companyKey?: string; calendarId?: string; offset?: number }): Promise<unknown[] | null>;
33
- getByVisitorPhone(phone: string, opts: { companyKey?: string; calendarId?: string; offset?: number }): Promise<unknown[] | null>;
34
- getAvailability(calendarId: string, year: number, month: number, day: number, opts?: { participantId?: string; offset?: number }): Promise<unknown[]>;
35
- cancel(eventId: string): Promise<unknown>;
36
- getCancellable(eventId: string): Promise<boolean>;
37
- createEvent(payload: object, offsetMinutes?: number): Promise<unknown>;
38
- reschedule(payload: object, offsetMinutes?: number): Promise<unknown>;
39
- updateEvent(payload: object): Promise<unknown>;
40
- createTest(payload: object, offsetMinutes?: number): Promise<unknown>;
41
- getCustomData(calendarId: string, eventId?: string): Promise<unknown>;
42
- setReminder(eventId: string): Promise<unknown>;
43
- setAttendeeStatus(eventId: string, attendeeStatus: number | string): Promise<unknown>;
44
- create(snapshot: object, options?: { env?: object }): unknown;
45
- };
46
-
47
- export const AvailabilityModel: { create(snapshot: object, options?: { env?: object }): unknown };
48
- export const AvailabilityDetailModel: { create(snapshot: object, options?: { env?: object }): unknown };
49
- export const CalendarParticipantModel: {
50
- getByCalendar(calendarId: string): Promise<unknown[] | null>;
51
- getInfoByCalendar(calendarId: string): Promise<unknown[] | null>;
52
- getByParticipant(participantId: string): Promise<unknown[] | null>;
53
- create(snapshot: object, options?: { env?: object }): unknown;
54
- };
55
- export const ParticipantModel: {
56
- get(participantId: string): Promise<unknown>;
57
- getByIds(participantIds: string[] | string): Promise<unknown[] | null>;
58
- getAll(companyKey: string): Promise<unknown[] | null>;
59
- add(payload: object, calendarId?: string): Promise<unknown>;
60
- remove(participantId: string): Promise<unknown>;
61
- update(payload: object): Promise<unknown>;
62
- save(payload: object): Promise<unknown>;
63
- sendEmail(participantId: string): Promise<unknown>;
64
- create(snapshot: object, options?: { env?: object }): unknown;
65
- };
66
- export const OpeningHourModel: { create(snapshot: object, options?: { env?: object }): unknown };
67
- export const TimeSlotModel: { create(snapshot: object, options?: { env?: object }): unknown };
68
- export const TimeFrameModel: { create(snapshot: object, options?: { env?: object }): unknown };
69
- export const SettingModel: {
70
- get(calendarId: string): Promise<unknown>;
71
- save(payload: object): Promise<unknown>;
72
- uploadLogo(calendarId: string, file: File | Blob): Promise<unknown>;
73
- create(snapshot: object, options?: { env?: object }): unknown;
74
- };
75
- export const CompanyModel: {
76
- get(companyKey: string): Promise<unknown>;
77
- getAll(): Promise<unknown[] | null>;
78
- save(payload: object): Promise<unknown>;
79
- create(snapshot: object, options?: { env?: object }): unknown;
80
- };
81
- export const CalendarDayModel: { create(snapshot: object, options?: { env?: object }): unknown };
82
- export const ParticipantInfoModel: { create(snapshot: object, options?: { env?: object }): unknown };
83
- export const PreferenceModel: {
84
- getScopes(): Promise<string[] | null>;
85
- getOptions(): Promise<string[] | null>;
86
- getOptionTemplate(option: string): Promise<unknown>;
87
- get(option: string, keys: string | string[]): Promise<unknown>;
88
- set(scope: string, key: string, option: string, body: string | object): Promise<unknown>;
89
- delete(preferenceId: string): Promise<unknown>;
90
- create(snapshot: object, options?: { env?: object }): unknown;
91
- };
92
- export const PreferenceScope: Record<string, number>;
93
-
94
- export const RootStore: unknown;
95
- export function createRootStore(initialState?: object): unknown;
96
-
97
- export const Unit: Record<string, number>;
98
- export const AssignmentMethod: Record<string, number>;
99
- export const AttendeeStatus: Record<string, number>;
100
- export const RecurringFrequency: Record<string, number>;
101
- export const DayOfWeek: Record<string, number>;
1
+ /** @blazeo.com/calendar-client - type declarations */
2
+
3
+ export function configure(env: { baseUrl?: string; consumer?: string; fetch?: typeof fetch; getDefaultOffset?: () => number }): void;
4
+ export function getConfig(): { baseUrl?: string; consumer?: string; fetch?: typeof fetch; getDefaultOffset?: () => number } | null;
5
+ export function setBaseUrl(baseUrl: string): void;
6
+ export function setConsumer(consumer: string): void;
7
+ export function getConfigStore(): unknown;
8
+
9
+ export const ConfigModel: unknown;
10
+
11
+ export const CalendarModel: {
12
+ get(calendarId: string): Promise<unknown>;
13
+ getRaw(calendarId: string): Promise<{ status: string; data?: unknown; message?: string }>;
14
+ getByCompany(companyKey: string): Promise<unknown[]>;
15
+ getTimeZones(): Promise<unknown>;
16
+ getTimeZone(timezoneId: string): Promise<unknown>;
17
+ getParticipants(calendarId: string): Promise<unknown>;
18
+ getCalendarParticipant(calendarId: string): Promise<unknown>;
19
+ getParticipantsInfo(calendarId: string): Promise<unknown>;
20
+ getMonth(calendarId: string, year: number, month: number): Promise<unknown>;
21
+ getEvents(calendarId: string): Promise<unknown>;
22
+ createWithParticipants(name: string, companyKey: string, participantIds: string[], description: string, calendarId?: string): Promise<unknown>;
23
+ editWithParticipants(calendarId: string, name: string, participantIds: string[], description: string): Promise<unknown>;
24
+ create(snapshot: object, options?: { env?: object }): unknown;
25
+ };
26
+
27
+ export const EventModel: {
28
+ get(eventId: string): Promise<unknown>;
29
+ getByExternalId(externalEventId: string): Promise<unknown>;
30
+ getRoundRobinParticipant(calendarId: string): Promise<unknown>;
31
+ getEarliestAvailableDays(calendarId: string, count: number, opts?: { year?: number; month?: number; day?: number; offset?: number }): Promise<string[] | null>;
32
+ getDaySelectable(calendarId: string, year: number, month: number, day: number, opts?: { participantId?: string; offset?: number }): Promise<boolean>;
33
+ getByVisitorEmail(email: string, opts: { companyKey?: string; calendarId?: string; offset?: number }): Promise<unknown[] | null>;
34
+ getByVisitorPhone(phone: string, opts: { companyKey?: string; calendarId?: string; offset?: number }): Promise<unknown[] | null>;
35
+ getAvailability(calendarId: string, year: number, month: number, day: number, opts?: { participantId?: string; offset?: number }): Promise<unknown[]>;
36
+ cancel(eventId: string): Promise<unknown>;
37
+ getCancellable(eventId: string): Promise<boolean>;
38
+ createEvent(payload: object, offsetMinutes?: number): Promise<unknown>;
39
+ reschedule(payload: object, offsetMinutes?: number): Promise<unknown>;
40
+ updateEvent(payload: object): Promise<unknown>;
41
+ createTest(payload: object, offsetMinutes?: number): Promise<unknown>;
42
+ getCustomData(calendarId: string, eventId?: string): Promise<unknown>;
43
+ setReminder(eventId: string): Promise<unknown>;
44
+ setAttendeeStatus(eventId: string, attendeeStatus: number | string): Promise<unknown>;
45
+ create(snapshot: object, options?: { env?: object }): unknown;
46
+ };
47
+
48
+ export const AvailabilityModel: { create(snapshot: object, options?: { env?: object }): unknown };
49
+ export const AvailabilityDetailModel: { create(snapshot: object, options?: { env?: object }): unknown };
50
+ export const CalendarParticipantModel: {
51
+ getByCalendar(calendarId: string): Promise<unknown[] | null>;
52
+ getInfoByCalendar(calendarId: string): Promise<unknown[] | null>;
53
+ getByParticipant(participantId: string): Promise<unknown[] | null>;
54
+ create(snapshot: object, options?: { env?: object }): unknown;
55
+ };
56
+ export const ParticipantModel: {
57
+ get(participantId: string): Promise<unknown>;
58
+ getByIds(participantIds: string[] | string): Promise<unknown[] | null>;
59
+ getAll(companyKey: string): Promise<unknown[] | null>;
60
+ add(payload: object, calendarId?: string): Promise<unknown>;
61
+ remove(participantId: string): Promise<unknown>;
62
+ update(payload: object): Promise<unknown>;
63
+ save(payload: object): Promise<unknown>;
64
+ sendEmail(participantId: string): Promise<unknown>;
65
+ create(snapshot: object, options?: { env?: object }): unknown;
66
+ };
67
+ export const OpeningHourModel: { create(snapshot: object, options?: { env?: object }): unknown };
68
+ export const TimeSlotModel: { create(snapshot: object, options?: { env?: object }): unknown };
69
+ export const TimeFrameModel: { create(snapshot: object, options?: { env?: object }): unknown };
70
+ export const SettingModel: {
71
+ get(calendarId: string): Promise<unknown>;
72
+ save(payload: object): Promise<unknown>;
73
+ uploadLogo(calendarId: string, file: File | Blob): Promise<unknown>;
74
+ create(snapshot: object, options?: { env?: object }): unknown;
75
+ };
76
+ export const CompanyModel: {
77
+ get(companyKey: string): Promise<unknown>;
78
+ getAll(): Promise<unknown[] | null>;
79
+ save(payload: object): Promise<unknown>;
80
+ create(snapshot: object, options?: { env?: object }): unknown;
81
+ };
82
+ export const CalendarDayModel: { create(snapshot: object, options?: { env?: object }): unknown };
83
+ export const ParticipantInfoModel: { create(snapshot: object, options?: { env?: object }): unknown };
84
+ export const PreferenceModel: {
85
+ getScopes(): Promise<string[] | null>;
86
+ getOptions(): Promise<string[] | null>;
87
+ getOptionTemplate(option: string): Promise<unknown>;
88
+ get(option: string, keys: string | string[]): Promise<unknown>;
89
+ set(scope: string, key: string, option: string, body: string | object): Promise<unknown>;
90
+ delete(preferenceId: string): Promise<unknown>;
91
+ create(snapshot: object, options?: { env?: object }): unknown;
92
+ };
93
+ export const PreferenceScope: Record<string, number>;
94
+
95
+ export const FlowModel: {
96
+ getRaw(flowId: string): Promise<{ status: string; data?: unknown; message?: string }>;
97
+ list(companyKey: string, includeDeleted?: boolean): Promise<unknown[] | null>;
98
+ get(flowId: string): Promise<unknown>;
99
+ createFlow(payload: object): Promise<unknown>;
100
+ updateFlow(payload: object): Promise<unknown>;
101
+ delete(flowId: string): Promise<unknown>;
102
+ duplicate(flowId: string, newName?: string): Promise<unknown>;
103
+ getAppearance(flowId: string): Promise<unknown>;
104
+ saveAppearance(payload: object): Promise<unknown>;
105
+ getEmbed(flowId: string): Promise<unknown>;
106
+ saveEmbed(payload: object): Promise<unknown>;
107
+ getPublic(flowId: string): Promise<{ flow: unknown; appearance: unknown; embed: unknown } | null>;
108
+ getPreview(flowId: string): Promise<{ flow: unknown; appearance: unknown; embed: unknown } | null>;
109
+ /** Empty snapshot is valid: `FlowModel.create({}, { env })` after configure() */
110
+ create(snapshot?: object, options?: { env?: object }): unknown;
111
+ };
112
+
113
+ export const LeadModel: {
114
+ getRaw(leadId: string): Promise<{ status: string; data?: unknown; message?: string }>;
115
+ get(leadId: string): Promise<unknown>;
116
+ getByEmail(email: string, companyKey: string): Promise<unknown>;
117
+ getByCompany(companyKey: string, opts?: { skip?: number; take?: number }): Promise<unknown[] | null>;
118
+ /** Empty snapshot is valid: `LeadModel.create({}, { env })` after configure() */
119
+ create(snapshot?: object, options?: { env?: object }): unknown;
120
+ };
121
+
122
+ export const RootStore: unknown;
123
+ export function createRootStore(initialState?: object): unknown;
124
+
125
+ export const Unit: Record<string, number>;
126
+ export const AssignmentMethod: Record<string, number>;
127
+ export const AttendeeStatus: Record<string, number>;
128
+ export const RecurringFrequency: Record<string, number>;
129
+ export const DayOfWeek: Record<string, number>;
package/dist/index.js CHANGED
@@ -30,6 +30,8 @@ __export(index_exports, {
30
30
  ConfigModel: () => ConfigModel_default,
31
31
  DayOfWeek: () => DayOfWeek,
32
32
  EventModel: () => Event_default,
33
+ FlowModel: () => Flow_default,
34
+ LeadModel: () => Lead_default,
33
35
  OpeningHourModel: () => OpeningHour_default,
34
36
  ParticipantInfoModel: () => ParticipantInfo_default,
35
37
  ParticipantModel: () => Participant_default,
@@ -55,7 +57,8 @@ var import_mobx_state_tree7 = require("mobx-state-tree");
55
57
  // src/ConfigModel.js
56
58
  var import_mobx_state_tree = require("mobx-state-tree");
57
59
  var ConfigModel = import_mobx_state_tree.types.model("Config", {
58
- baseUrl: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, "")
60
+ baseUrl: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, ""),
61
+ consumer: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, "")
59
62
  }).volatile(() => ({
60
63
  fetch: void 0,
61
64
  getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
@@ -63,6 +66,9 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
63
66
  setBaseUrl(url) {
64
67
  self.baseUrl = url;
65
68
  },
69
+ setConsumer(value) {
70
+ self.consumer = value ?? "";
71
+ },
66
72
  setFetch(fn) {
67
73
  self.fetch = fn;
68
74
  },
@@ -71,6 +77,7 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
71
77
  },
72
78
  configure(env) {
73
79
  if (env.baseUrl != null) self.baseUrl = env.baseUrl;
80
+ if (env.consumer != null) self.consumer = env.consumer;
74
81
  if (env.fetch != null) self.fetch = env.fetch;
75
82
  if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
76
83
  }
@@ -78,6 +85,7 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
78
85
  getEnv() {
79
86
  return {
80
87
  baseUrl: self.baseUrl || void 0,
88
+ consumer: self.consumer || void 0,
81
89
  fetch: self.fetch,
82
90
  getDefaultOffset: self.getDefaultOffset
83
91
  };
@@ -137,8 +145,13 @@ async function request(baseUrl, fetchFn, path, options = {}) {
137
145
  }
138
146
  return data;
139
147
  }
140
- function createRequestHelpers(self, getEnv7) {
141
- const env = () => getEnv7(self);
148
+ function mergeConsumerHeader(env, opts) {
149
+ const headers = { ...opts.headers || {} };
150
+ if (env == null ? void 0 : env.consumer) headers["Consumer"] = env.consumer;
151
+ return { ...opts, headers };
152
+ }
153
+ function createRequestHelpers(self, getEnv9) {
154
+ const env = () => getEnv9(self);
142
155
  const baseUrl = () => env().baseUrl;
143
156
  const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
144
157
  throw new Error("fetch not available");
@@ -146,7 +159,7 @@ function createRequestHelpers(self, getEnv7) {
146
159
  const req = (path, opts = {}) => {
147
160
  const url = baseUrl();
148
161
  if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
149
- return request(url, fetchFn(), path, opts);
162
+ return request(url, fetchFn(), path, mergeConsumerHeader(env(), opts));
150
163
  };
151
164
  return {
152
165
  req,
@@ -164,7 +177,7 @@ function createRequestHelpersFromEnv(env) {
164
177
  const req = (path, opts = {}) => {
165
178
  const url = baseUrl();
166
179
  if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
167
- return request(url, fetchFn(), path, opts);
180
+ return request(url, fetchFn(), path, mergeConsumerHeader(e, opts));
168
181
  };
169
182
  return {
170
183
  env: e,
@@ -1472,11 +1485,360 @@ PreferenceModel.delete = async (preferenceId) => {
1472
1485
  };
1473
1486
  var Preference_default = PreferenceModel;
1474
1487
 
1475
- // src/models/appointment/index.js
1488
+ // src/models/appointment/Flow.js
1476
1489
  var import_mobx_state_tree16 = require("mobx-state-tree");
1477
- var RootStore = import_mobx_state_tree16.types.model("RootStore", {
1478
- calendars: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Calendar_default), {}),
1479
- events: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.map(Event_default), {})
1490
+ function mapFlowFromApi(d) {
1491
+ if (!d) return d;
1492
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1493
+ const b = (v) => v === true || v === "true" || v === 1;
1494
+ return {
1495
+ id: pick("id", "Id") ?? null,
1496
+ flowId: pick("flowId", "FlowId", "flow_id") ?? "",
1497
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1498
+ name: pick("name", "Name") ?? "",
1499
+ description: pick("description", "Description") ?? null,
1500
+ flowJson: pick("flowJson", "FlowJson", "flow_json") ?? "",
1501
+ isActive: b(pick("isActive", "IsActive", "is_active")) ?? true,
1502
+ isDeleted: b(pick("isDeleted", "IsDeleted", "is_deleted")) ?? false,
1503
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1504
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1505
+ };
1506
+ }
1507
+ var FlowModel = import_mobx_state_tree16.types.model("Flow", {
1508
+ id: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.number), null),
1509
+ flowId: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.identifier, "new"),
1510
+ companyKey: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string), null),
1511
+ name: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string), null),
1512
+ description: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string), null),
1513
+ flowJson: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.string, ""),
1514
+ isActive: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.boolean, true),
1515
+ isDeleted: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.boolean, false),
1516
+ createdOn: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string), null),
1517
+ modifiedOn: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string), null)
1518
+ }).actions((self) => {
1519
+ const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree16.getEnv);
1520
+ return {
1521
+ /** GET flow/get – fetch this flow by flowId */
1522
+ async get() {
1523
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1524
+ const res = await reqGet("/flow/get", { flow_id: self.flowId });
1525
+ if (res.status === "success" && res.data) {
1526
+ (0, import_mobx_state_tree16.applySnapshot)(self, mapFlowFromApi(res.data));
1527
+ }
1528
+ return res;
1529
+ },
1530
+ /** POST flow/create – create flow from current snapshot */
1531
+ async create() {
1532
+ const payload = {
1533
+ companyKey: self.companyKey ?? void 0,
1534
+ name: self.name ?? void 0,
1535
+ description: self.description ?? void 0,
1536
+ flowJson: self.flowJson || void 0,
1537
+ isActive: self.isActive
1538
+ };
1539
+ const res = await reqPost("/flow/create", payload);
1540
+ if (res.status === "success" && res.data) {
1541
+ (0, import_mobx_state_tree16.applySnapshot)(self, mapFlowFromApi(res.data));
1542
+ }
1543
+ return res;
1544
+ },
1545
+ /** POST flow/update – update flow */
1546
+ async update() {
1547
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1548
+ const payload = {
1549
+ flowId: self.flowId,
1550
+ name: self.name ?? void 0,
1551
+ description: self.description ?? void 0,
1552
+ flowJson: self.flowJson || void 0,
1553
+ isActive: self.isActive
1554
+ };
1555
+ const res = await reqPost("/flow/update", payload);
1556
+ if (res.status === "success" && res.data) {
1557
+ (0, import_mobx_state_tree16.applySnapshot)(self, mapFlowFromApi(res.data));
1558
+ }
1559
+ return res;
1560
+ },
1561
+ /** POST flow/delete – soft delete flow */
1562
+ async delete() {
1563
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1564
+ return reqPost("/flow/delete", { flow_id: self.flowId });
1565
+ },
1566
+ /** POST flow/duplicate – duplicate flow; applies snapshot if new flow returned */
1567
+ async duplicate(newName) {
1568
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1569
+ const res = await reqPost("/flow/duplicate", { flow_id: self.flowId, new_name: newName ?? void 0 });
1570
+ if (res.status === "success" && res.data) {
1571
+ (0, import_mobx_state_tree16.applySnapshot)(self, mapFlowFromApi(res.data));
1572
+ }
1573
+ return res;
1574
+ },
1575
+ /** GET flow/appearance/get – uses self.flowId */
1576
+ async getAppearance() {
1577
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1578
+ return FlowModel.getAppearance(self.flowId);
1579
+ },
1580
+ /** POST flow/appearance/save – merges self.flowId into payload */
1581
+ async saveAppearance(payload = {}) {
1582
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1583
+ const body = { ...payload, flowId: self.flowId };
1584
+ return FlowModel.saveAppearance(body);
1585
+ },
1586
+ /** GET flow/embed/get – uses self.flowId */
1587
+ async getEmbed() {
1588
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1589
+ return FlowModel.getEmbed(self.flowId);
1590
+ },
1591
+ /** POST flow/embed/save – merges self.flowId into payload */
1592
+ async saveEmbed(payload = {}) {
1593
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1594
+ const body = { ...payload, flowId: self.flowId };
1595
+ return FlowModel.saveEmbed(body);
1596
+ },
1597
+ /** GET flow/public/get – uses self.flowId */
1598
+ async getPublic() {
1599
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1600
+ return FlowModel.getPublic(self.flowId);
1601
+ },
1602
+ /** GET flow/preview/get – same as getPublic */
1603
+ async getPreview() {
1604
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1605
+ return FlowModel.getPreview(self.flowId);
1606
+ }
1607
+ };
1608
+ });
1609
+ FlowModel.getRaw = async (flowId) => {
1610
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1611
+ return reqGet("/flow/get", { flow_id: flowId });
1612
+ };
1613
+ FlowModel.list = async (companyKey, includeDeleted = false) => {
1614
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1615
+ const query = { company_key: companyKey };
1616
+ if (includeDeleted) query.include_deleted = "true";
1617
+ const res = await reqGet("/flow/list", query);
1618
+ if (res.status === "success" && Array.isArray(res.data)) {
1619
+ return res.data.map((f) => FlowModel.create(mapFlowFromApi(f), { env: getConfig() }));
1620
+ }
1621
+ return null;
1622
+ };
1623
+ FlowModel.get = async (flowId) => {
1624
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1625
+ const res = await reqGet("/flow/get", { flow_id: flowId });
1626
+ if (res.status === "success" && res.data) {
1627
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1628
+ }
1629
+ return null;
1630
+ };
1631
+ FlowModel.createFlow = async (payload) => {
1632
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1633
+ const res = await reqPost("/flow/create", payload);
1634
+ if (res.status === "success" && res.data) {
1635
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1636
+ }
1637
+ return null;
1638
+ };
1639
+ FlowModel.updateFlow = async (payload) => {
1640
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1641
+ const res = await reqPost("/flow/update", payload);
1642
+ if (res.status === "success" && res.data) {
1643
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1644
+ }
1645
+ return null;
1646
+ };
1647
+ FlowModel.delete = async (flowId) => {
1648
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1649
+ return reqPost("/flow/delete", { flow_id: flowId });
1650
+ };
1651
+ FlowModel.duplicate = async (flowId, newName) => {
1652
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1653
+ const res = await reqPost("/flow/duplicate", { flow_id: flowId, new_name: newName ?? void 0 });
1654
+ if (res.status === "success" && res.data) {
1655
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1656
+ }
1657
+ return null;
1658
+ };
1659
+ FlowModel.getAppearance = async (flowId) => {
1660
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1661
+ const res = await reqGet("/flow/appearance/get", { flow_id: flowId });
1662
+ if (res.status === "success" && res.data != null) {
1663
+ const d = res.data;
1664
+ return {
1665
+ id: d.id ?? d.Id ?? null,
1666
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1667
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1668
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1669
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1670
+ };
1671
+ }
1672
+ return null;
1673
+ };
1674
+ FlowModel.saveAppearance = async (payload) => {
1675
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1676
+ const res = await reqPost("/flow/appearance/save", payload);
1677
+ if (res.status === "success" && res.data) {
1678
+ const d = res.data;
1679
+ return {
1680
+ id: d.id ?? d.Id ?? null,
1681
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1682
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1683
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1684
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1685
+ };
1686
+ }
1687
+ return null;
1688
+ };
1689
+ FlowModel.getEmbed = async (flowId) => {
1690
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1691
+ const res = await reqGet("/flow/embed/get", { flow_id: flowId });
1692
+ if (res.status === "success" && res.data != null) {
1693
+ const d = res.data;
1694
+ return {
1695
+ id: d.id ?? d.Id ?? null,
1696
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1697
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1698
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1699
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1700
+ };
1701
+ }
1702
+ return null;
1703
+ };
1704
+ FlowModel.saveEmbed = async (payload) => {
1705
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1706
+ const res = await reqPost("/flow/embed/save", payload);
1707
+ if (res.status === "success" && res.data) {
1708
+ const d = res.data;
1709
+ return {
1710
+ id: d.id ?? d.Id ?? null,
1711
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1712
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1713
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1714
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1715
+ };
1716
+ }
1717
+ return null;
1718
+ };
1719
+ FlowModel.getPublic = async (flowId) => {
1720
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1721
+ const res = await reqGet("/flow/public/get", { flow_id: flowId });
1722
+ if (res.status === "success" && res.data) {
1723
+ const d = res.data;
1724
+ return {
1725
+ flow: d.flow ? mapFlowFromApi(d.flow) : null,
1726
+ appearance: d.appearance ?? null,
1727
+ embed: d.embed ?? null
1728
+ };
1729
+ }
1730
+ return null;
1731
+ };
1732
+ FlowModel.getPreview = async (flowId) => {
1733
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1734
+ const res = await reqGet("/flow/preview/get", { flow_id: flowId });
1735
+ if (res.status === "success" && res.data) {
1736
+ const d = res.data;
1737
+ return {
1738
+ flow: d.flow ? mapFlowFromApi(d.flow) : null,
1739
+ appearance: d.appearance ?? null,
1740
+ embed: d.embed ?? null
1741
+ };
1742
+ }
1743
+ return null;
1744
+ };
1745
+ var Flow_default = FlowModel;
1746
+
1747
+ // src/models/appointment/Lead.js
1748
+ var import_mobx_state_tree17 = require("mobx-state-tree");
1749
+ function mapLeadFromApi(d) {
1750
+ if (!d) return d;
1751
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1752
+ return {
1753
+ id: pick("id", "Id") ?? null,
1754
+ leadId: pick("leadId", "LeadId", "lead_id") ?? "",
1755
+ email: pick("email", "Email") ?? "",
1756
+ name: pick("name", "Name") ?? "",
1757
+ phone: pick("phone", "Phone") ?? "",
1758
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1759
+ source: pick("source", "Source") ?? "",
1760
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1761
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1762
+ };
1763
+ }
1764
+ var LeadModel = import_mobx_state_tree17.types.model("Lead", {
1765
+ id: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.number), null),
1766
+ leadId: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.identifier, "new"),
1767
+ email: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1768
+ name: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1769
+ phone: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1770
+ companyKey: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1771
+ source: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1772
+ createdOn: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string), null),
1773
+ modifiedOn: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string), null)
1774
+ }).actions((self) => {
1775
+ const { reqGet } = createRequestHelpers(self, import_mobx_state_tree17.getEnv);
1776
+ return {
1777
+ /** GET /lead/get – fetch this lead by leadId */
1778
+ async get() {
1779
+ if (!self.leadId || self.leadId === "new") return { status: "failure", message: "leadId required" };
1780
+ const res = await reqGet("/lead/get", { lead_id: self.leadId });
1781
+ if (res.status === "success" && res.data) {
1782
+ (0, import_mobx_state_tree17.applySnapshot)(self, mapLeadFromApi(res.data));
1783
+ }
1784
+ return res;
1785
+ },
1786
+ /** GET /lead/getbyemail – uses self.email and self.companyKey */
1787
+ async getByEmail() {
1788
+ if (!self.email || !self.companyKey) {
1789
+ return { status: "failure", message: "email and companyKey required on model" };
1790
+ }
1791
+ const lead = await LeadModel.getByEmail(self.email, self.companyKey);
1792
+ if (lead) {
1793
+ (0, import_mobx_state_tree17.applySnapshot)(self, (0, import_mobx_state_tree17.getSnapshot)(lead));
1794
+ }
1795
+ return { status: lead ? "success" : "failure", data: lead ?? void 0 };
1796
+ },
1797
+ /** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
1798
+ async getByCompany(opts = {}) {
1799
+ if (!self.companyKey) return null;
1800
+ return LeadModel.getByCompany(self.companyKey, opts);
1801
+ }
1802
+ };
1803
+ });
1804
+ LeadModel.getRaw = async (leadId) => {
1805
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1806
+ return reqGet("/lead/get", { lead_id: leadId });
1807
+ };
1808
+ LeadModel.get = async (leadId) => {
1809
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1810
+ const res = await reqGet("/lead/get", { lead_id: leadId });
1811
+ if (res.status === "success" && res.data) {
1812
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1813
+ }
1814
+ return null;
1815
+ };
1816
+ LeadModel.getByEmail = async (email, companyKey) => {
1817
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1818
+ const res = await reqGet("/lead/getbyemail", { email, company_key: companyKey });
1819
+ if (res.status === "success" && res.data) {
1820
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1821
+ }
1822
+ return null;
1823
+ };
1824
+ LeadModel.getByCompany = async (companyKey, opts = {}) => {
1825
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1826
+ const query = { company_key: companyKey };
1827
+ if (opts.skip != null) query.skip = opts.skip;
1828
+ if (opts.take != null) query.take = opts.take;
1829
+ const res = await reqGet("/lead/company/get", query);
1830
+ if (res.status === "success" && Array.isArray(res.data)) {
1831
+ return res.data.map((l) => LeadModel.create(mapLeadFromApi(l), { env: getConfig() }));
1832
+ }
1833
+ return null;
1834
+ };
1835
+ var Lead_default = LeadModel;
1836
+
1837
+ // src/models/appointment/index.js
1838
+ var import_mobx_state_tree18 = require("mobx-state-tree");
1839
+ var RootStore = import_mobx_state_tree18.types.model("RootStore", {
1840
+ calendars: import_mobx_state_tree18.types.optional(import_mobx_state_tree18.types.map(Calendar_default), {}),
1841
+ events: import_mobx_state_tree18.types.optional(import_mobx_state_tree18.types.map(Event_default), {})
1480
1842
  }).actions((self) => ({
1481
1843
  addCalendar(snapshot) {
1482
1844
  const cal = Calendar_default.create(snapshot);
@@ -1507,6 +1869,8 @@ function createRootStore(initialState = {}) {
1507
1869
  ConfigModel,
1508
1870
  DayOfWeek,
1509
1871
  EventModel,
1872
+ FlowModel,
1873
+ LeadModel,
1510
1874
  OpeningHourModel,
1511
1875
  ParticipantInfoModel,
1512
1876
  ParticipantModel,
package/dist/index.mjs CHANGED
@@ -4,7 +4,8 @@ import { types as types7, getEnv as getEnv2, applySnapshot as applySnapshot2 } f
4
4
  // src/ConfigModel.js
5
5
  import { types } from "mobx-state-tree";
6
6
  var ConfigModel = types.model("Config", {
7
- baseUrl: types.optional(types.string, "")
7
+ baseUrl: types.optional(types.string, ""),
8
+ consumer: types.optional(types.string, "")
8
9
  }).volatile(() => ({
9
10
  fetch: void 0,
10
11
  getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
@@ -12,6 +13,9 @@ var ConfigModel = types.model("Config", {
12
13
  setBaseUrl(url) {
13
14
  self.baseUrl = url;
14
15
  },
16
+ setConsumer(value) {
17
+ self.consumer = value ?? "";
18
+ },
15
19
  setFetch(fn) {
16
20
  self.fetch = fn;
17
21
  },
@@ -20,6 +24,7 @@ var ConfigModel = types.model("Config", {
20
24
  },
21
25
  configure(env) {
22
26
  if (env.baseUrl != null) self.baseUrl = env.baseUrl;
27
+ if (env.consumer != null) self.consumer = env.consumer;
23
28
  if (env.fetch != null) self.fetch = env.fetch;
24
29
  if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
25
30
  }
@@ -27,6 +32,7 @@ var ConfigModel = types.model("Config", {
27
32
  getEnv() {
28
33
  return {
29
34
  baseUrl: self.baseUrl || void 0,
35
+ consumer: self.consumer || void 0,
30
36
  fetch: self.fetch,
31
37
  getDefaultOffset: self.getDefaultOffset
32
38
  };
@@ -86,8 +92,13 @@ async function request(baseUrl, fetchFn, path, options = {}) {
86
92
  }
87
93
  return data;
88
94
  }
89
- function createRequestHelpers(self, getEnv7) {
90
- const env = () => getEnv7(self);
95
+ function mergeConsumerHeader(env, opts) {
96
+ const headers = { ...opts.headers || {} };
97
+ if (env == null ? void 0 : env.consumer) headers["Consumer"] = env.consumer;
98
+ return { ...opts, headers };
99
+ }
100
+ function createRequestHelpers(self, getEnv9) {
101
+ const env = () => getEnv9(self);
91
102
  const baseUrl = () => env().baseUrl;
92
103
  const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
93
104
  throw new Error("fetch not available");
@@ -95,7 +106,7 @@ function createRequestHelpers(self, getEnv7) {
95
106
  const req = (path, opts = {}) => {
96
107
  const url = baseUrl();
97
108
  if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
98
- return request(url, fetchFn(), path, opts);
109
+ return request(url, fetchFn(), path, mergeConsumerHeader(env(), opts));
99
110
  };
100
111
  return {
101
112
  req,
@@ -113,7 +124,7 @@ function createRequestHelpersFromEnv(env) {
113
124
  const req = (path, opts = {}) => {
114
125
  const url = baseUrl();
115
126
  if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
116
- return request(url, fetchFn(), path, opts);
127
+ return request(url, fetchFn(), path, mergeConsumerHeader(e, opts));
117
128
  };
118
129
  return {
119
130
  env: e,
@@ -1421,11 +1432,360 @@ PreferenceModel.delete = async (preferenceId) => {
1421
1432
  };
1422
1433
  var Preference_default = PreferenceModel;
1423
1434
 
1435
+ // src/models/appointment/Flow.js
1436
+ import { types as types16, getEnv as getEnv6, applySnapshot as applySnapshot6 } from "mobx-state-tree";
1437
+ function mapFlowFromApi(d) {
1438
+ if (!d) return d;
1439
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1440
+ const b = (v) => v === true || v === "true" || v === 1;
1441
+ return {
1442
+ id: pick("id", "Id") ?? null,
1443
+ flowId: pick("flowId", "FlowId", "flow_id") ?? "",
1444
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1445
+ name: pick("name", "Name") ?? "",
1446
+ description: pick("description", "Description") ?? null,
1447
+ flowJson: pick("flowJson", "FlowJson", "flow_json") ?? "",
1448
+ isActive: b(pick("isActive", "IsActive", "is_active")) ?? true,
1449
+ isDeleted: b(pick("isDeleted", "IsDeleted", "is_deleted")) ?? false,
1450
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1451
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1452
+ };
1453
+ }
1454
+ var FlowModel = types16.model("Flow", {
1455
+ id: types16.optional(types16.maybeNull(types16.number), null),
1456
+ flowId: types16.optional(types16.identifier, "new"),
1457
+ companyKey: types16.optional(types16.maybeNull(types16.string), null),
1458
+ name: types16.optional(types16.maybeNull(types16.string), null),
1459
+ description: types16.optional(types16.maybeNull(types16.string), null),
1460
+ flowJson: types16.optional(types16.string, ""),
1461
+ isActive: types16.optional(types16.boolean, true),
1462
+ isDeleted: types16.optional(types16.boolean, false),
1463
+ createdOn: types16.optional(types16.maybeNull(types16.string), null),
1464
+ modifiedOn: types16.optional(types16.maybeNull(types16.string), null)
1465
+ }).actions((self) => {
1466
+ const { reqGet, reqPost } = createRequestHelpers(self, getEnv6);
1467
+ return {
1468
+ /** GET flow/get – fetch this flow by flowId */
1469
+ async get() {
1470
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1471
+ const res = await reqGet("/flow/get", { flow_id: self.flowId });
1472
+ if (res.status === "success" && res.data) {
1473
+ applySnapshot6(self, mapFlowFromApi(res.data));
1474
+ }
1475
+ return res;
1476
+ },
1477
+ /** POST flow/create – create flow from current snapshot */
1478
+ async create() {
1479
+ const payload = {
1480
+ companyKey: self.companyKey ?? void 0,
1481
+ name: self.name ?? void 0,
1482
+ description: self.description ?? void 0,
1483
+ flowJson: self.flowJson || void 0,
1484
+ isActive: self.isActive
1485
+ };
1486
+ const res = await reqPost("/flow/create", payload);
1487
+ if (res.status === "success" && res.data) {
1488
+ applySnapshot6(self, mapFlowFromApi(res.data));
1489
+ }
1490
+ return res;
1491
+ },
1492
+ /** POST flow/update – update flow */
1493
+ async update() {
1494
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1495
+ const payload = {
1496
+ flowId: self.flowId,
1497
+ name: self.name ?? void 0,
1498
+ description: self.description ?? void 0,
1499
+ flowJson: self.flowJson || void 0,
1500
+ isActive: self.isActive
1501
+ };
1502
+ const res = await reqPost("/flow/update", payload);
1503
+ if (res.status === "success" && res.data) {
1504
+ applySnapshot6(self, mapFlowFromApi(res.data));
1505
+ }
1506
+ return res;
1507
+ },
1508
+ /** POST flow/delete – soft delete flow */
1509
+ async delete() {
1510
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1511
+ return reqPost("/flow/delete", { flow_id: self.flowId });
1512
+ },
1513
+ /** POST flow/duplicate – duplicate flow; applies snapshot if new flow returned */
1514
+ async duplicate(newName) {
1515
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1516
+ const res = await reqPost("/flow/duplicate", { flow_id: self.flowId, new_name: newName ?? void 0 });
1517
+ if (res.status === "success" && res.data) {
1518
+ applySnapshot6(self, mapFlowFromApi(res.data));
1519
+ }
1520
+ return res;
1521
+ },
1522
+ /** GET flow/appearance/get – uses self.flowId */
1523
+ async getAppearance() {
1524
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1525
+ return FlowModel.getAppearance(self.flowId);
1526
+ },
1527
+ /** POST flow/appearance/save – merges self.flowId into payload */
1528
+ async saveAppearance(payload = {}) {
1529
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1530
+ const body = { ...payload, flowId: self.flowId };
1531
+ return FlowModel.saveAppearance(body);
1532
+ },
1533
+ /** GET flow/embed/get – uses self.flowId */
1534
+ async getEmbed() {
1535
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1536
+ return FlowModel.getEmbed(self.flowId);
1537
+ },
1538
+ /** POST flow/embed/save – merges self.flowId into payload */
1539
+ async saveEmbed(payload = {}) {
1540
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1541
+ const body = { ...payload, flowId: self.flowId };
1542
+ return FlowModel.saveEmbed(body);
1543
+ },
1544
+ /** GET flow/public/get – uses self.flowId */
1545
+ async getPublic() {
1546
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1547
+ return FlowModel.getPublic(self.flowId);
1548
+ },
1549
+ /** GET flow/preview/get – same as getPublic */
1550
+ async getPreview() {
1551
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1552
+ return FlowModel.getPreview(self.flowId);
1553
+ }
1554
+ };
1555
+ });
1556
+ FlowModel.getRaw = async (flowId) => {
1557
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1558
+ return reqGet("/flow/get", { flow_id: flowId });
1559
+ };
1560
+ FlowModel.list = async (companyKey, includeDeleted = false) => {
1561
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1562
+ const query = { company_key: companyKey };
1563
+ if (includeDeleted) query.include_deleted = "true";
1564
+ const res = await reqGet("/flow/list", query);
1565
+ if (res.status === "success" && Array.isArray(res.data)) {
1566
+ return res.data.map((f) => FlowModel.create(mapFlowFromApi(f), { env: getConfig() }));
1567
+ }
1568
+ return null;
1569
+ };
1570
+ FlowModel.get = async (flowId) => {
1571
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1572
+ const res = await reqGet("/flow/get", { flow_id: flowId });
1573
+ if (res.status === "success" && res.data) {
1574
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1575
+ }
1576
+ return null;
1577
+ };
1578
+ FlowModel.createFlow = async (payload) => {
1579
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1580
+ const res = await reqPost("/flow/create", payload);
1581
+ if (res.status === "success" && res.data) {
1582
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1583
+ }
1584
+ return null;
1585
+ };
1586
+ FlowModel.updateFlow = async (payload) => {
1587
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1588
+ const res = await reqPost("/flow/update", payload);
1589
+ if (res.status === "success" && res.data) {
1590
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1591
+ }
1592
+ return null;
1593
+ };
1594
+ FlowModel.delete = async (flowId) => {
1595
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1596
+ return reqPost("/flow/delete", { flow_id: flowId });
1597
+ };
1598
+ FlowModel.duplicate = async (flowId, newName) => {
1599
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1600
+ const res = await reqPost("/flow/duplicate", { flow_id: flowId, new_name: newName ?? void 0 });
1601
+ if (res.status === "success" && res.data) {
1602
+ return FlowModel.create(mapFlowFromApi(res.data), { env: getConfig() });
1603
+ }
1604
+ return null;
1605
+ };
1606
+ FlowModel.getAppearance = async (flowId) => {
1607
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1608
+ const res = await reqGet("/flow/appearance/get", { flow_id: flowId });
1609
+ if (res.status === "success" && res.data != null) {
1610
+ const d = res.data;
1611
+ return {
1612
+ id: d.id ?? d.Id ?? null,
1613
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1614
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1615
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1616
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1617
+ };
1618
+ }
1619
+ return null;
1620
+ };
1621
+ FlowModel.saveAppearance = async (payload) => {
1622
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1623
+ const res = await reqPost("/flow/appearance/save", payload);
1624
+ if (res.status === "success" && res.data) {
1625
+ const d = res.data;
1626
+ return {
1627
+ id: d.id ?? d.Id ?? null,
1628
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1629
+ appearanceJson: d.appearanceJson ?? d.AppearanceJson ?? d.appearance_json ?? "",
1630
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1631
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1632
+ };
1633
+ }
1634
+ return null;
1635
+ };
1636
+ FlowModel.getEmbed = async (flowId) => {
1637
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1638
+ const res = await reqGet("/flow/embed/get", { flow_id: flowId });
1639
+ if (res.status === "success" && res.data != null) {
1640
+ const d = res.data;
1641
+ return {
1642
+ id: d.id ?? d.Id ?? null,
1643
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? flowId,
1644
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1645
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1646
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1647
+ };
1648
+ }
1649
+ return null;
1650
+ };
1651
+ FlowModel.saveEmbed = async (payload) => {
1652
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
1653
+ const res = await reqPost("/flow/embed/save", payload);
1654
+ if (res.status === "success" && res.data) {
1655
+ const d = res.data;
1656
+ return {
1657
+ id: d.id ?? d.Id ?? null,
1658
+ flowId: d.flowId ?? d.FlowId ?? d.flow_id ?? payload.flowId ?? payload.flow_id,
1659
+ embedJson: d.embedJson ?? d.EmbedJson ?? d.embed_json ?? "",
1660
+ createdOn: d.createdOn ?? d.CreatedOn ?? d.created_on ?? null,
1661
+ modifiedOn: d.modifiedOn ?? d.ModifiedOn ?? d.modified_on ?? null
1662
+ };
1663
+ }
1664
+ return null;
1665
+ };
1666
+ FlowModel.getPublic = async (flowId) => {
1667
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1668
+ const res = await reqGet("/flow/public/get", { flow_id: flowId });
1669
+ if (res.status === "success" && res.data) {
1670
+ const d = res.data;
1671
+ return {
1672
+ flow: d.flow ? mapFlowFromApi(d.flow) : null,
1673
+ appearance: d.appearance ?? null,
1674
+ embed: d.embed ?? null
1675
+ };
1676
+ }
1677
+ return null;
1678
+ };
1679
+ FlowModel.getPreview = async (flowId) => {
1680
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1681
+ const res = await reqGet("/flow/preview/get", { flow_id: flowId });
1682
+ if (res.status === "success" && res.data) {
1683
+ const d = res.data;
1684
+ return {
1685
+ flow: d.flow ? mapFlowFromApi(d.flow) : null,
1686
+ appearance: d.appearance ?? null,
1687
+ embed: d.embed ?? null
1688
+ };
1689
+ }
1690
+ return null;
1691
+ };
1692
+ var Flow_default = FlowModel;
1693
+
1694
+ // src/models/appointment/Lead.js
1695
+ import { types as types17, getEnv as getEnv7, applySnapshot as applySnapshot7, getSnapshot } from "mobx-state-tree";
1696
+ function mapLeadFromApi(d) {
1697
+ if (!d) return d;
1698
+ const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
1699
+ return {
1700
+ id: pick("id", "Id") ?? null,
1701
+ leadId: pick("leadId", "LeadId", "lead_id") ?? "",
1702
+ email: pick("email", "Email") ?? "",
1703
+ name: pick("name", "Name") ?? "",
1704
+ phone: pick("phone", "Phone") ?? "",
1705
+ companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
1706
+ source: pick("source", "Source") ?? "",
1707
+ createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
1708
+ modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
1709
+ };
1710
+ }
1711
+ var LeadModel = types17.model("Lead", {
1712
+ id: types17.optional(types17.maybeNull(types17.number), null),
1713
+ leadId: types17.optional(types17.identifier, "new"),
1714
+ email: types17.optional(types17.string, ""),
1715
+ name: types17.optional(types17.string, ""),
1716
+ phone: types17.optional(types17.string, ""),
1717
+ companyKey: types17.optional(types17.string, ""),
1718
+ source: types17.optional(types17.string, ""),
1719
+ createdOn: types17.optional(types17.maybeNull(types17.string), null),
1720
+ modifiedOn: types17.optional(types17.maybeNull(types17.string), null)
1721
+ }).actions((self) => {
1722
+ const { reqGet } = createRequestHelpers(self, getEnv7);
1723
+ return {
1724
+ /** GET /lead/get – fetch this lead by leadId */
1725
+ async get() {
1726
+ if (!self.leadId || self.leadId === "new") return { status: "failure", message: "leadId required" };
1727
+ const res = await reqGet("/lead/get", { lead_id: self.leadId });
1728
+ if (res.status === "success" && res.data) {
1729
+ applySnapshot7(self, mapLeadFromApi(res.data));
1730
+ }
1731
+ return res;
1732
+ },
1733
+ /** GET /lead/getbyemail – uses self.email and self.companyKey */
1734
+ async getByEmail() {
1735
+ if (!self.email || !self.companyKey) {
1736
+ return { status: "failure", message: "email and companyKey required on model" };
1737
+ }
1738
+ const lead = await LeadModel.getByEmail(self.email, self.companyKey);
1739
+ if (lead) {
1740
+ applySnapshot7(self, getSnapshot(lead));
1741
+ }
1742
+ return { status: lead ? "success" : "failure", data: lead ?? void 0 };
1743
+ },
1744
+ /** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
1745
+ async getByCompany(opts = {}) {
1746
+ if (!self.companyKey) return null;
1747
+ return LeadModel.getByCompany(self.companyKey, opts);
1748
+ }
1749
+ };
1750
+ });
1751
+ LeadModel.getRaw = async (leadId) => {
1752
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1753
+ return reqGet("/lead/get", { lead_id: leadId });
1754
+ };
1755
+ LeadModel.get = async (leadId) => {
1756
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1757
+ const res = await reqGet("/lead/get", { lead_id: leadId });
1758
+ if (res.status === "success" && res.data) {
1759
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1760
+ }
1761
+ return null;
1762
+ };
1763
+ LeadModel.getByEmail = async (email, companyKey) => {
1764
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1765
+ const res = await reqGet("/lead/getbyemail", { email, company_key: companyKey });
1766
+ if (res.status === "success" && res.data) {
1767
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
1768
+ }
1769
+ return null;
1770
+ };
1771
+ LeadModel.getByCompany = async (companyKey, opts = {}) => {
1772
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1773
+ const query = { company_key: companyKey };
1774
+ if (opts.skip != null) query.skip = opts.skip;
1775
+ if (opts.take != null) query.take = opts.take;
1776
+ const res = await reqGet("/lead/company/get", query);
1777
+ if (res.status === "success" && Array.isArray(res.data)) {
1778
+ return res.data.map((l) => LeadModel.create(mapLeadFromApi(l), { env: getConfig() }));
1779
+ }
1780
+ return null;
1781
+ };
1782
+ var Lead_default = LeadModel;
1783
+
1424
1784
  // src/models/appointment/index.js
1425
- import { types as types16, getEnv as getEnv6 } from "mobx-state-tree";
1426
- var RootStore = types16.model("RootStore", {
1427
- calendars: types16.optional(types16.map(Calendar_default), {}),
1428
- events: types16.optional(types16.map(Event_default), {})
1785
+ import { types as types18, getEnv as getEnv8 } from "mobx-state-tree";
1786
+ var RootStore = types18.model("RootStore", {
1787
+ calendars: types18.optional(types18.map(Calendar_default), {}),
1788
+ events: types18.optional(types18.map(Event_default), {})
1429
1789
  }).actions((self) => ({
1430
1790
  addCalendar(snapshot) {
1431
1791
  const cal = Calendar_default.create(snapshot);
@@ -1455,6 +1815,8 @@ export {
1455
1815
  ConfigModel_default as ConfigModel,
1456
1816
  DayOfWeek,
1457
1817
  Event_default as EventModel,
1818
+ Flow_default as FlowModel,
1819
+ Lead_default as LeadModel,
1458
1820
  OpeningHour_default as OpeningHourModel,
1459
1821
  ParticipantInfo_default as ParticipantInfoModel,
1460
1822
  Participant_default as ParticipantModel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazeo.com/calendar-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Blazeo Calendar / Appointment API client with MobX State Tree models",
5
5
  "exports": {
6
6
  ".": {