@blazeo.com/calendar-client 1.0.4 → 1.0.6
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 +4 -3
- package/dist/index.d.ts +140 -124
- package/dist/index.js +101 -15
- package/dist/index.mjs +102 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,10 +22,11 @@ cd your-app && npm link @blazeo.com/calendar-client
|
|
|
22
22
|
Configure once at app startup, then use models and their methods:
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import { configure, setBaseUrl, CalendarModel, createRootStore } from '@blazeo.com/calendar-client';
|
|
25
|
+
import { configure, setBaseUrl, setConsumer, CalendarModel, createRootStore } from '@blazeo.com/calendar-client';
|
|
26
26
|
|
|
27
27
|
configure({ baseUrl: 'https://your-appointment-api.example.com' });
|
|
28
28
|
// or: setBaseUrl('https://localhost:7051');
|
|
29
|
+
setConsumer('my-app'); // optional: sent as Consumer header (e.g. for lead source)
|
|
29
30
|
|
|
30
31
|
// Calendar static methods (no store needed)
|
|
31
32
|
const timezones = await CalendarModel.getTimeZones();
|
|
@@ -41,8 +42,8 @@ await cal.create(); // POST to backend
|
|
|
41
42
|
|
|
42
43
|
- **CalendarModel (static):** `get`, `getByCompany`, `getTimeZones`, `getTimeZone`, `getParticipants`, `getMonth`, `getEvents`, etc.
|
|
43
44
|
- **EventModel (instance):** `get`, `create`, `cancel`, `getCancellable`, `getAvailability`, `setReminder`
|
|
44
|
-
- **FlowModel (
|
|
45
|
-
- **LeadModel (
|
|
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)
|
|
46
47
|
- **RootStore:** `addCalendar`, `addEvent`
|
|
47
48
|
|
|
48
49
|
All methods return `Promise<{ status, data?, message? }>`. Check `response.status === 'success'` and use `response.data`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,124 +1,140 @@
|
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export const
|
|
49
|
-
export const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const
|
|
68
|
-
export const
|
|
69
|
-
export const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const
|
|
83
|
-
export const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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(
|
|
118
|
+
companyKey: string,
|
|
119
|
+
opts?: {
|
|
120
|
+
skip?: number;
|
|
121
|
+
take?: number;
|
|
122
|
+
sort?: string;
|
|
123
|
+
sort_column?: string;
|
|
124
|
+
sort_dir?: 'asc' | 'desc';
|
|
125
|
+
page?: number;
|
|
126
|
+
page_size?: number;
|
|
127
|
+
}
|
|
128
|
+
): Promise<unknown[] | null>;
|
|
129
|
+
/** Empty snapshot is valid: `LeadModel.create({}, { env })` after configure() */
|
|
130
|
+
create(snapshot?: object, options?: { env?: object }): unknown;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const RootStore: unknown;
|
|
134
|
+
export function createRootStore(initialState?: object): unknown;
|
|
135
|
+
|
|
136
|
+
export const Unit: Record<string, number>;
|
|
137
|
+
export const AssignmentMethod: Record<string, number>;
|
|
138
|
+
export const AttendeeStatus: Record<string, number>;
|
|
139
|
+
export const RecurringFrequency: Record<string, number>;
|
|
140
|
+
export const DayOfWeek: Record<string, number>;
|
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
|
-
|
|
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 });
|
|
@@ -1745,6 +1826,11 @@ LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
|
1745
1826
|
const query = { company_key: companyKey };
|
|
1746
1827
|
if (opts.skip != null) query.skip = opts.skip;
|
|
1747
1828
|
if (opts.take != null) query.take = opts.take;
|
|
1829
|
+
const sortCol = opts.sort ?? opts.sort_column;
|
|
1830
|
+
if (sortCol != null && sortCol !== "") query.sort = sortCol;
|
|
1831
|
+
if (opts.sort_dir != null) query.sort_dir = opts.sort_dir;
|
|
1832
|
+
if (opts.page != null) query.page = opts.page;
|
|
1833
|
+
if (opts.page_size != null) query.page_size = opts.page_size;
|
|
1748
1834
|
const res = await reqGet("/lead/company/get", query);
|
|
1749
1835
|
if (res.status === "success" && Array.isArray(res.data)) {
|
|
1750
1836
|
return res.data.map((l) => LeadModel.create(mapLeadFromApi(l), { env: getConfig() }));
|
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
|
-
|
|
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 });
|
|
@@ -1692,6 +1773,11 @@ LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
|
1692
1773
|
const query = { company_key: companyKey };
|
|
1693
1774
|
if (opts.skip != null) query.skip = opts.skip;
|
|
1694
1775
|
if (opts.take != null) query.take = opts.take;
|
|
1776
|
+
const sortCol = opts.sort ?? opts.sort_column;
|
|
1777
|
+
if (sortCol != null && sortCol !== "") query.sort = sortCol;
|
|
1778
|
+
if (opts.sort_dir != null) query.sort_dir = opts.sort_dir;
|
|
1779
|
+
if (opts.page != null) query.page = opts.page;
|
|
1780
|
+
if (opts.page_size != null) query.page_size = opts.page_size;
|
|
1695
1781
|
const res = await reqGet("/lead/company/get", query);
|
|
1696
1782
|
if (res.status === "success" && Array.isArray(res.data)) {
|
|
1697
1783
|
return res.data.map((l) => LeadModel.create(mapLeadFromApi(l), { env: getConfig() }));
|