@blazeo.com/calendar-client 1.0.4 → 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,53 +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
- - **FlowModel (static):** `list`, `get`, `createFlow`, `updateFlow`, `delete`, `duplicate`, `getAppearance`, `saveAppearance`, `getEmbed`, `saveEmbed`, `getPublic`, `getPreview`
45
- - **LeadModel (static):** `get`, `getByEmail`, `getByCompany`
46
- - **RootStore:** `addCalendar`, `addEvent`
47
-
48
- All methods return `Promise<{ status, data?, message? }>`. Check `response.status === 'success'` and use `response.data`.
49
-
50
- ## Samples
51
-
52
- - **`sample/`** – Uses the package via `file:..` for local development (run `npm run build` in parent first).
53
- - **`sample-npm/`** – Uses the package from npm: `npm i @blazeo.com/calendar-client`. For testing the published 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,8 +1,9 @@
1
1
  /** @blazeo.com/calendar-client - type declarations */
2
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;
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
5
  export function setBaseUrl(baseUrl: string): void;
6
+ export function setConsumer(consumer: string): void;
6
7
  export function getConfigStore(): unknown;
7
8
 
8
9
  export const ConfigModel: unknown;
@@ -92,6 +93,7 @@ export const PreferenceModel: {
92
93
  export const PreferenceScope: Record<string, number>;
93
94
 
94
95
  export const FlowModel: {
96
+ getRaw(flowId: string): Promise<{ status: string; data?: unknown; message?: string }>;
95
97
  list(companyKey: string, includeDeleted?: boolean): Promise<unknown[] | null>;
96
98
  get(flowId: string): Promise<unknown>;
97
99
  createFlow(payload: object): Promise<unknown>;
@@ -104,14 +106,17 @@ export const FlowModel: {
104
106
  saveEmbed(payload: object): Promise<unknown>;
105
107
  getPublic(flowId: string): Promise<{ flow: unknown; appearance: unknown; embed: unknown } | null>;
106
108
  getPreview(flowId: string): Promise<{ flow: unknown; appearance: unknown; embed: unknown } | null>;
107
- create(snapshot: object, options?: { env?: object }): unknown;
109
+ /** Empty snapshot is valid: `FlowModel.create({}, { env })` after configure() */
110
+ create(snapshot?: object, options?: { env?: object }): unknown;
108
111
  };
109
112
 
110
113
  export const LeadModel: {
114
+ getRaw(leadId: string): Promise<{ status: string; data?: unknown; message?: string }>;
111
115
  get(leadId: string): Promise<unknown>;
112
116
  getByEmail(email: string, companyKey: string): Promise<unknown>;
113
117
  getByCompany(companyKey: string, opts?: { skip?: number; take?: number }): Promise<unknown[] | null>;
114
- create(snapshot: object, options?: { env?: object }): unknown;
118
+ /** Empty snapshot is valid: `LeadModel.create({}, { env })` after configure() */
119
+ create(snapshot?: object, options?: { env?: object }): unknown;
115
120
  };
116
121
 
117
122
  export const RootStore: unknown;
package/dist/index.js CHANGED
@@ -57,7 +57,8 @@ var import_mobx_state_tree7 = require("mobx-state-tree");
57
57
  // src/ConfigModel.js
58
58
  var import_mobx_state_tree = require("mobx-state-tree");
59
59
  var ConfigModel = import_mobx_state_tree.types.model("Config", {
60
- 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, "")
61
62
  }).volatile(() => ({
62
63
  fetch: void 0,
63
64
  getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
@@ -65,6 +66,9 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
65
66
  setBaseUrl(url) {
66
67
  self.baseUrl = url;
67
68
  },
69
+ setConsumer(value) {
70
+ self.consumer = value ?? "";
71
+ },
68
72
  setFetch(fn) {
69
73
  self.fetch = fn;
70
74
  },
@@ -73,6 +77,7 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
73
77
  },
74
78
  configure(env) {
75
79
  if (env.baseUrl != null) self.baseUrl = env.baseUrl;
80
+ if (env.consumer != null) self.consumer = env.consumer;
76
81
  if (env.fetch != null) self.fetch = env.fetch;
77
82
  if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
78
83
  }
@@ -80,6 +85,7 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
80
85
  getEnv() {
81
86
  return {
82
87
  baseUrl: self.baseUrl || void 0,
88
+ consumer: self.consumer || void 0,
83
89
  fetch: self.fetch,
84
90
  getDefaultOffset: self.getDefaultOffset
85
91
  };
@@ -139,6 +145,11 @@ async function request(baseUrl, fetchFn, path, options = {}) {
139
145
  }
140
146
  return data;
141
147
  }
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
+ }
142
153
  function createRequestHelpers(self, getEnv9) {
143
154
  const env = () => getEnv9(self);
144
155
  const baseUrl = () => env().baseUrl;
@@ -148,7 +159,7 @@ function createRequestHelpers(self, getEnv9) {
148
159
  const req = (path, opts = {}) => {
149
160
  const url = baseUrl();
150
161
  if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
151
- return request(url, fetchFn(), path, opts);
162
+ return request(url, fetchFn(), path, mergeConsumerHeader(env(), opts));
152
163
  };
153
164
  return {
154
165
  req,
@@ -166,7 +177,7 @@ function createRequestHelpersFromEnv(env) {
166
177
  const req = (path, opts = {}) => {
167
178
  const url = baseUrl();
168
179
  if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
169
- return request(url, fetchFn(), path, opts);
180
+ return request(url, fetchFn(), path, mergeConsumerHeader(e, opts));
170
181
  };
171
182
  return {
172
183
  env: e,
@@ -1494,16 +1505,16 @@ function mapFlowFromApi(d) {
1494
1505
  };
1495
1506
  }
1496
1507
  var FlowModel = import_mobx_state_tree16.types.model("Flow", {
1497
- id: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.number),
1508
+ id: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.number), null),
1498
1509
  flowId: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.identifier, "new"),
1499
- companyKey: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string),
1500
- name: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string),
1501
- description: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string),
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),
1502
1513
  flowJson: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.string, ""),
1503
1514
  isActive: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.boolean, true),
1504
1515
  isDeleted: import_mobx_state_tree16.types.optional(import_mobx_state_tree16.types.boolean, false),
1505
- createdOn: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string),
1506
- modifiedOn: import_mobx_state_tree16.types.maybeNull(import_mobx_state_tree16.types.string)
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)
1507
1518
  }).actions((self) => {
1508
1519
  const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree16.getEnv);
1509
1520
  return {
@@ -1516,7 +1527,7 @@ var FlowModel = import_mobx_state_tree16.types.model("Flow", {
1516
1527
  }
1517
1528
  return res;
1518
1529
  },
1519
- /** POST flow/create – create flow */
1530
+ /** POST flow/create – create flow from current snapshot */
1520
1531
  async create() {
1521
1532
  const payload = {
1522
1533
  companyKey: self.companyKey ?? void 0,
@@ -1533,6 +1544,7 @@ var FlowModel = import_mobx_state_tree16.types.model("Flow", {
1533
1544
  },
1534
1545
  /** POST flow/update – update flow */
1535
1546
  async update() {
1547
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1536
1548
  const payload = {
1537
1549
  flowId: self.flowId,
1538
1550
  name: self.name ?? void 0,
@@ -1551,14 +1563,53 @@ var FlowModel = import_mobx_state_tree16.types.model("Flow", {
1551
1563
  if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1552
1564
  return reqPost("/flow/delete", { flow_id: self.flowId });
1553
1565
  },
1554
- /** POST flow/duplicate – duplicate flow */
1566
+ /** POST flow/duplicate – duplicate flow; applies snapshot if new flow returned */
1555
1567
  async duplicate(newName) {
1556
1568
  if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1557
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
+ }
1558
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);
1559
1606
  }
1560
1607
  };
1561
1608
  });
1609
+ FlowModel.getRaw = async (flowId) => {
1610
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1611
+ return reqGet("/flow/get", { flow_id: flowId });
1612
+ };
1562
1613
  FlowModel.list = async (companyKey, includeDeleted = false) => {
1563
1614
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1564
1615
  const query = { company_key: companyKey };
@@ -1679,7 +1730,17 @@ FlowModel.getPublic = async (flowId) => {
1679
1730
  return null;
1680
1731
  };
1681
1732
  FlowModel.getPreview = async (flowId) => {
1682
- return FlowModel.getPublic(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;
1683
1744
  };
1684
1745
  var Flow_default = FlowModel;
1685
1746
 
@@ -1701,15 +1762,15 @@ function mapLeadFromApi(d) {
1701
1762
  };
1702
1763
  }
1703
1764
  var LeadModel = import_mobx_state_tree17.types.model("Lead", {
1704
- id: import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.number),
1765
+ id: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.number), null),
1705
1766
  leadId: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.identifier, "new"),
1706
1767
  email: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1707
1768
  name: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1708
1769
  phone: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1709
1770
  companyKey: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1710
1771
  source: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
1711
- createdOn: import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string),
1712
- modifiedOn: import_mobx_state_tree17.types.maybeNull(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)
1713
1774
  }).actions((self) => {
1714
1775
  const { reqGet } = createRequestHelpers(self, import_mobx_state_tree17.getEnv);
1715
1776
  return {
@@ -1721,9 +1782,29 @@ var LeadModel = import_mobx_state_tree17.types.model("Lead", {
1721
1782
  (0, import_mobx_state_tree17.applySnapshot)(self, mapLeadFromApi(res.data));
1722
1783
  }
1723
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);
1724
1801
  }
1725
1802
  };
1726
1803
  });
1804
+ LeadModel.getRaw = async (leadId) => {
1805
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1806
+ return reqGet("/lead/get", { lead_id: leadId });
1807
+ };
1727
1808
  LeadModel.get = async (leadId) => {
1728
1809
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1729
1810
  const res = await reqGet("/lead/get", { lead_id: leadId });
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,6 +92,11 @@ async function request(baseUrl, fetchFn, path, options = {}) {
86
92
  }
87
93
  return data;
88
94
  }
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
+ }
89
100
  function createRequestHelpers(self, getEnv9) {
90
101
  const env = () => getEnv9(self);
91
102
  const baseUrl = () => env().baseUrl;
@@ -95,7 +106,7 @@ function createRequestHelpers(self, getEnv9) {
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,
@@ -1441,16 +1452,16 @@ function mapFlowFromApi(d) {
1441
1452
  };
1442
1453
  }
1443
1454
  var FlowModel = types16.model("Flow", {
1444
- id: types16.maybeNull(types16.number),
1455
+ id: types16.optional(types16.maybeNull(types16.number), null),
1445
1456
  flowId: types16.optional(types16.identifier, "new"),
1446
- companyKey: types16.maybeNull(types16.string),
1447
- name: types16.maybeNull(types16.string),
1448
- description: types16.maybeNull(types16.string),
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),
1449
1460
  flowJson: types16.optional(types16.string, ""),
1450
1461
  isActive: types16.optional(types16.boolean, true),
1451
1462
  isDeleted: types16.optional(types16.boolean, false),
1452
- createdOn: types16.maybeNull(types16.string),
1453
- modifiedOn: types16.maybeNull(types16.string)
1463
+ createdOn: types16.optional(types16.maybeNull(types16.string), null),
1464
+ modifiedOn: types16.optional(types16.maybeNull(types16.string), null)
1454
1465
  }).actions((self) => {
1455
1466
  const { reqGet, reqPost } = createRequestHelpers(self, getEnv6);
1456
1467
  return {
@@ -1463,7 +1474,7 @@ var FlowModel = types16.model("Flow", {
1463
1474
  }
1464
1475
  return res;
1465
1476
  },
1466
- /** POST flow/create – create flow */
1477
+ /** POST flow/create – create flow from current snapshot */
1467
1478
  async create() {
1468
1479
  const payload = {
1469
1480
  companyKey: self.companyKey ?? void 0,
@@ -1480,6 +1491,7 @@ var FlowModel = types16.model("Flow", {
1480
1491
  },
1481
1492
  /** POST flow/update – update flow */
1482
1493
  async update() {
1494
+ if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1483
1495
  const payload = {
1484
1496
  flowId: self.flowId,
1485
1497
  name: self.name ?? void 0,
@@ -1498,14 +1510,53 @@ var FlowModel = types16.model("Flow", {
1498
1510
  if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1499
1511
  return reqPost("/flow/delete", { flow_id: self.flowId });
1500
1512
  },
1501
- /** POST flow/duplicate – duplicate flow */
1513
+ /** POST flow/duplicate – duplicate flow; applies snapshot if new flow returned */
1502
1514
  async duplicate(newName) {
1503
1515
  if (!self.flowId || self.flowId === "new") return { status: "failure", message: "flowId required" };
1504
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
+ }
1505
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);
1506
1553
  }
1507
1554
  };
1508
1555
  });
1556
+ FlowModel.getRaw = async (flowId) => {
1557
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1558
+ return reqGet("/flow/get", { flow_id: flowId });
1559
+ };
1509
1560
  FlowModel.list = async (companyKey, includeDeleted = false) => {
1510
1561
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1511
1562
  const query = { company_key: companyKey };
@@ -1626,12 +1677,22 @@ FlowModel.getPublic = async (flowId) => {
1626
1677
  return null;
1627
1678
  };
1628
1679
  FlowModel.getPreview = async (flowId) => {
1629
- return FlowModel.getPublic(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;
1630
1691
  };
1631
1692
  var Flow_default = FlowModel;
1632
1693
 
1633
1694
  // src/models/appointment/Lead.js
1634
- import { types as types17, getEnv as getEnv7, applySnapshot as applySnapshot7 } from "mobx-state-tree";
1695
+ import { types as types17, getEnv as getEnv7, applySnapshot as applySnapshot7, getSnapshot } from "mobx-state-tree";
1635
1696
  function mapLeadFromApi(d) {
1636
1697
  if (!d) return d;
1637
1698
  const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
@@ -1648,15 +1709,15 @@ function mapLeadFromApi(d) {
1648
1709
  };
1649
1710
  }
1650
1711
  var LeadModel = types17.model("Lead", {
1651
- id: types17.maybeNull(types17.number),
1712
+ id: types17.optional(types17.maybeNull(types17.number), null),
1652
1713
  leadId: types17.optional(types17.identifier, "new"),
1653
1714
  email: types17.optional(types17.string, ""),
1654
1715
  name: types17.optional(types17.string, ""),
1655
1716
  phone: types17.optional(types17.string, ""),
1656
1717
  companyKey: types17.optional(types17.string, ""),
1657
1718
  source: types17.optional(types17.string, ""),
1658
- createdOn: types17.maybeNull(types17.string),
1659
- modifiedOn: types17.maybeNull(types17.string)
1719
+ createdOn: types17.optional(types17.maybeNull(types17.string), null),
1720
+ modifiedOn: types17.optional(types17.maybeNull(types17.string), null)
1660
1721
  }).actions((self) => {
1661
1722
  const { reqGet } = createRequestHelpers(self, getEnv7);
1662
1723
  return {
@@ -1668,9 +1729,29 @@ var LeadModel = types17.model("Lead", {
1668
1729
  applySnapshot7(self, mapLeadFromApi(res.data));
1669
1730
  }
1670
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);
1671
1748
  }
1672
1749
  };
1673
1750
  });
1751
+ LeadModel.getRaw = async (leadId) => {
1752
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
1753
+ return reqGet("/lead/get", { lead_id: leadId });
1754
+ };
1674
1755
  LeadModel.get = async (leadId) => {
1675
1756
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
1676
1757
  const res = await reqGet("/lead/get", { lead_id: leadId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazeo.com/calendar-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Blazeo Calendar / Appointment API client with MobX State Tree models",
5
5
  "exports": {
6
6
  ".": {