@blazeo.com/calendar-client 1.0.23 → 1.0.26
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 +81 -1
- package/dist/index.d.ts +134 -2
- package/dist/index.js +565 -158
- package/dist/index.mjs +547 -157
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,10 @@ var ConfigModel = types.model("Config", {
|
|
|
8
8
|
consumer: types.optional(types.string, "")
|
|
9
9
|
}).volatile(() => ({
|
|
10
10
|
fetch: void 0,
|
|
11
|
+
accessToken: void 0,
|
|
12
|
+
tokenExpiresAt: void 0,
|
|
13
|
+
apiKey: void 0,
|
|
14
|
+
apiSecret: void 0,
|
|
11
15
|
getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
12
16
|
})).actions((self) => ({
|
|
13
17
|
setBaseUrl(url) {
|
|
@@ -22,19 +26,57 @@ var ConfigModel = types.model("Config", {
|
|
|
22
26
|
setGetDefaultOffset(fn) {
|
|
23
27
|
self.getDefaultOffset = fn;
|
|
24
28
|
},
|
|
29
|
+
setAccessToken(token, expiresAtUtc = void 0) {
|
|
30
|
+
self.accessToken = token ? String(token) : void 0;
|
|
31
|
+
self.tokenExpiresAt = expiresAtUtc != null && expiresAtUtc !== "" ? String(expiresAtUtc) : void 0;
|
|
32
|
+
},
|
|
33
|
+
clearAccessToken() {
|
|
34
|
+
self.accessToken = void 0;
|
|
35
|
+
self.tokenExpiresAt = void 0;
|
|
36
|
+
},
|
|
37
|
+
setApiCredentials(apiKey, apiSecret) {
|
|
38
|
+
self.apiKey = apiKey != null ? String(apiKey) : void 0;
|
|
39
|
+
self.apiSecret = apiSecret != null ? String(apiSecret) : void 0;
|
|
40
|
+
},
|
|
41
|
+
clearApiCredentials() {
|
|
42
|
+
self.apiKey = void 0;
|
|
43
|
+
self.apiSecret = void 0;
|
|
44
|
+
},
|
|
45
|
+
clearAuth() {
|
|
46
|
+
self.clearAccessToken();
|
|
47
|
+
self.clearApiCredentials();
|
|
48
|
+
},
|
|
25
49
|
configure(env) {
|
|
26
50
|
if (env.baseUrl != null) self.baseUrl = env.baseUrl;
|
|
27
51
|
if (env.consumer != null) self.consumer = env.consumer;
|
|
28
52
|
if (env.fetch != null) self.fetch = env.fetch;
|
|
29
53
|
if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
|
|
54
|
+
if (env.accessToken != null) {
|
|
55
|
+
self.setAccessToken(
|
|
56
|
+
env.accessToken,
|
|
57
|
+
env.expiresAtUtc ?? env.tokenExpiresAt ?? env.expires_at_utc
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (env.apiKey != null || env.api_key != null) {
|
|
61
|
+
self.apiKey = String(env.apiKey ?? env.api_key);
|
|
62
|
+
}
|
|
63
|
+
if (env.apiSecret != null || env.api_secret != null) {
|
|
64
|
+
self.apiSecret = String(env.apiSecret ?? env.api_secret);
|
|
65
|
+
}
|
|
30
66
|
}
|
|
31
67
|
})).views((self) => ({
|
|
68
|
+
get hasApiCredentials() {
|
|
69
|
+
return Boolean(self.apiKey && self.apiSecret);
|
|
70
|
+
},
|
|
32
71
|
getEnv() {
|
|
33
72
|
return {
|
|
34
73
|
baseUrl: self.baseUrl || void 0,
|
|
35
74
|
consumer: self.consumer || void 0,
|
|
36
75
|
fetch: self.fetch,
|
|
37
|
-
getDefaultOffset: self.getDefaultOffset
|
|
76
|
+
getDefaultOffset: self.getDefaultOffset,
|
|
77
|
+
accessToken: self.accessToken,
|
|
78
|
+
tokenExpiresAt: self.tokenExpiresAt,
|
|
79
|
+
hasApiCredentials: self.hasApiCredentials
|
|
38
80
|
};
|
|
39
81
|
}
|
|
40
82
|
}));
|
|
@@ -45,6 +87,122 @@ function getConfigStore() {
|
|
|
45
87
|
}
|
|
46
88
|
var ConfigModel_default = ConfigModel;
|
|
47
89
|
|
|
90
|
+
// src/apiAuth.js
|
|
91
|
+
var TOKEN_PATH = "/Api/Auth/Token";
|
|
92
|
+
var DEFAULT_TOKEN_REFRESH_SKEW_MS = 6e4;
|
|
93
|
+
function defaultFetch() {
|
|
94
|
+
if (typeof fetch === "undefined") {
|
|
95
|
+
throw new Error("fetch not available");
|
|
96
|
+
}
|
|
97
|
+
return fetch;
|
|
98
|
+
}
|
|
99
|
+
function pickTokenPayload(data) {
|
|
100
|
+
if (!data || typeof data !== "object") return null;
|
|
101
|
+
const nested = data.data && typeof data.data === "object" ? data.data : data;
|
|
102
|
+
const accessToken = nested.access_token ?? nested.accessToken ?? nested.AccessToken ?? null;
|
|
103
|
+
if (!accessToken) return null;
|
|
104
|
+
const expiresAtUtc = nested.expires_at_utc ?? nested.expiresAtUtc ?? nested.ExpiresAtUtc ?? null;
|
|
105
|
+
return {
|
|
106
|
+
accessToken: String(accessToken),
|
|
107
|
+
expiresAtUtc: expiresAtUtc != null ? String(expiresAtUtc) : null,
|
|
108
|
+
tokenType: nested.token_type ?? nested.tokenType ?? "Bearer"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function isAccessTokenExpired(expiresAtUtc, skewMs = DEFAULT_TOKEN_REFRESH_SKEW_MS) {
|
|
112
|
+
if (expiresAtUtc == null || expiresAtUtc === "") return false;
|
|
113
|
+
const expMs = new Date(expiresAtUtc).getTime();
|
|
114
|
+
if (Number.isNaN(expMs)) return false;
|
|
115
|
+
return Date.now() >= expMs - skewMs;
|
|
116
|
+
}
|
|
117
|
+
function getAuthState() {
|
|
118
|
+
const store = getConfigStore();
|
|
119
|
+
return {
|
|
120
|
+
accessToken: store.accessToken ?? void 0,
|
|
121
|
+
tokenExpiresAt: store.tokenExpiresAt ?? void 0,
|
|
122
|
+
apiKey: store.apiKey ?? void 0,
|
|
123
|
+
apiSecret: store.apiSecret ?? void 0,
|
|
124
|
+
hasApiCredentials: Boolean(store.apiKey && store.apiSecret)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function requestAccessToken(apiKey, apiSecret, opts = {}) {
|
|
128
|
+
const store = getConfigStore();
|
|
129
|
+
const baseUrl = opts.baseUrl ?? store.baseUrl;
|
|
130
|
+
if (!baseUrl) {
|
|
131
|
+
return { status: "failure", message: "baseUrl required. Call configure({ baseUrl }) first." };
|
|
132
|
+
}
|
|
133
|
+
const key = apiKey != null ? String(apiKey).trim() : "";
|
|
134
|
+
const secret = apiSecret != null ? String(apiSecret).trim() : "";
|
|
135
|
+
if (!key || !secret) {
|
|
136
|
+
return { status: "failure", message: "api_key and api_secret are required" };
|
|
137
|
+
}
|
|
138
|
+
const fetchFn = opts.fetch ?? store.fetch ?? defaultFetch();
|
|
139
|
+
const url = `${String(baseUrl).replace(/\/+$/, "")}${TOKEN_PATH}`;
|
|
140
|
+
const httpRes = await fetchFn(url, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
headers: { "Content-Type": "application/json" },
|
|
143
|
+
body: JSON.stringify({ api_key: key, api_secret: secret })
|
|
144
|
+
});
|
|
145
|
+
const text = await httpRes.text();
|
|
146
|
+
let body;
|
|
147
|
+
try {
|
|
148
|
+
body = JSON.parse(text);
|
|
149
|
+
} catch {
|
|
150
|
+
body = { status: "failure", message: text || httpRes.statusText };
|
|
151
|
+
}
|
|
152
|
+
if (!httpRes.ok && body.status !== "failure") {
|
|
153
|
+
body.status = "failure";
|
|
154
|
+
body.message = body.message ?? `HTTP ${httpRes.status}`;
|
|
155
|
+
}
|
|
156
|
+
if (body.status !== "success") {
|
|
157
|
+
return {
|
|
158
|
+
status: "failure",
|
|
159
|
+
message: body.message ?? "Failed to obtain access token"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const parsed = pickTokenPayload(body);
|
|
163
|
+
if (!parsed) {
|
|
164
|
+
return { status: "failure", message: "Token response missing access_token" };
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
status: "success",
|
|
168
|
+
accessToken: parsed.accessToken,
|
|
169
|
+
expiresAtUtc: parsed.expiresAtUtc,
|
|
170
|
+
tokenType: parsed.tokenType
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async function fetchAccessToken(apiKey, apiSecret) {
|
|
174
|
+
const store = getConfigStore();
|
|
175
|
+
const key = apiKey ?? store.apiKey;
|
|
176
|
+
const secret = apiSecret ?? store.apiSecret;
|
|
177
|
+
const result = await requestAccessToken(key, secret);
|
|
178
|
+
if (result.status === "success") {
|
|
179
|
+
store.setAccessToken(result.accessToken, result.expiresAtUtc);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
async function ensureAccessToken() {
|
|
184
|
+
const store = getConfigStore();
|
|
185
|
+
const { accessToken, tokenExpiresAt, apiKey, apiSecret } = getAuthState();
|
|
186
|
+
if (accessToken && !isAccessTokenExpired(tokenExpiresAt)) {
|
|
187
|
+
return accessToken;
|
|
188
|
+
}
|
|
189
|
+
if (apiKey && apiSecret) {
|
|
190
|
+
const result = await fetchAccessToken(apiKey, apiSecret);
|
|
191
|
+
if (result.status === "success") return result.accessToken;
|
|
192
|
+
}
|
|
193
|
+
return accessToken;
|
|
194
|
+
}
|
|
195
|
+
function buildAuthHeaders(extra = {}) {
|
|
196
|
+
const headers = { ...extra };
|
|
197
|
+
const { consumer } = getConfigStore();
|
|
198
|
+
const { accessToken } = getAuthState();
|
|
199
|
+
if (!headers.Consumer && consumer) headers.Consumer = consumer;
|
|
200
|
+
if (!headers.Authorization && accessToken) {
|
|
201
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
202
|
+
}
|
|
203
|
+
return headers;
|
|
204
|
+
}
|
|
205
|
+
|
|
48
206
|
// src/config.js
|
|
49
207
|
function configure(env) {
|
|
50
208
|
const store = getConfigStore();
|
|
@@ -58,6 +216,33 @@ function getConfig() {
|
|
|
58
216
|
function setBaseUrl(baseUrl) {
|
|
59
217
|
getConfigStore().setBaseUrl(baseUrl);
|
|
60
218
|
}
|
|
219
|
+
function setConsumer(consumer) {
|
|
220
|
+
getConfigStore().setConsumer(consumer);
|
|
221
|
+
}
|
|
222
|
+
function setAccessToken(accessToken, expiresAtUtc) {
|
|
223
|
+
getConfigStore().setAccessToken(accessToken, expiresAtUtc);
|
|
224
|
+
}
|
|
225
|
+
function clearAccessToken() {
|
|
226
|
+
getConfigStore().clearAccessToken();
|
|
227
|
+
}
|
|
228
|
+
function setApiCredentials(apiKey, apiSecret) {
|
|
229
|
+
getConfigStore().setApiCredentials(apiKey, apiSecret);
|
|
230
|
+
}
|
|
231
|
+
function clearApiCredentials() {
|
|
232
|
+
getConfigStore().clearApiCredentials();
|
|
233
|
+
}
|
|
234
|
+
function clearAuth() {
|
|
235
|
+
getConfigStore().clearAuth();
|
|
236
|
+
}
|
|
237
|
+
function getAuth() {
|
|
238
|
+
return getAuthState();
|
|
239
|
+
}
|
|
240
|
+
function fetchAccessToken2(apiKey, apiSecret) {
|
|
241
|
+
return fetchAccessToken(apiKey, apiSecret);
|
|
242
|
+
}
|
|
243
|
+
function ensureValidAccessToken() {
|
|
244
|
+
return ensureAccessToken();
|
|
245
|
+
}
|
|
61
246
|
|
|
62
247
|
// src/apiRequest.js
|
|
63
248
|
function buildQuery(params) {
|
|
@@ -74,10 +259,18 @@ function buildQuery(params) {
|
|
|
74
259
|
return q ? `?${q}` : "";
|
|
75
260
|
}
|
|
76
261
|
async function request(baseUrl, fetchFn, path, options = {}) {
|
|
77
|
-
const { method = "GET", headers = {}, body, query, skipContentType } = options;
|
|
262
|
+
const { method = "GET", headers = {}, body, query, skipContentType, skipAuth } = options;
|
|
78
263
|
const url = `${String(baseUrl).replace(/\/+$/, "")}${path}${buildQuery(query)}`;
|
|
79
264
|
const reqHeaders = { ...headers };
|
|
80
265
|
if (!skipContentType && typeof body === "string") reqHeaders["Content-Type"] = "application/json";
|
|
266
|
+
if (!skipAuth) {
|
|
267
|
+
const store = getConfigStore();
|
|
268
|
+
if (!reqHeaders["Consumer"] && store.consumer) reqHeaders["Consumer"] = store.consumer;
|
|
269
|
+
const { accessToken } = getAuthState();
|
|
270
|
+
if (!reqHeaders["Authorization"] && accessToken) {
|
|
271
|
+
reqHeaders["Authorization"] = `Bearer ${accessToken}`;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
81
274
|
const res = await fetchFn(url, { method, headers: reqHeaders, body });
|
|
82
275
|
const text = await res.text();
|
|
83
276
|
let data;
|
|
@@ -90,23 +283,35 @@ async function request(baseUrl, fetchFn, path, options = {}) {
|
|
|
90
283
|
data.status = "failure";
|
|
91
284
|
data.message = data.message ?? `HTTP ${res.status}`;
|
|
92
285
|
}
|
|
286
|
+
data._httpStatus = res.status;
|
|
93
287
|
return data;
|
|
94
288
|
}
|
|
95
|
-
function
|
|
289
|
+
function mergeRequestHeaders(env, opts) {
|
|
96
290
|
const headers = { ...opts.headers || {} };
|
|
97
|
-
|
|
291
|
+
const store = getConfigStore();
|
|
292
|
+
if (!headers["Consumer"] && ((env == null ? void 0 : env.consumer) || store.consumer)) {
|
|
293
|
+
headers["Consumer"] = (env == null ? void 0 : env.consumer) || store.consumer;
|
|
294
|
+
}
|
|
295
|
+
const { accessToken } = getAuthState();
|
|
296
|
+
if (!headers["Authorization"] && accessToken) {
|
|
297
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
298
|
+
}
|
|
98
299
|
return { ...opts, headers };
|
|
99
300
|
}
|
|
301
|
+
async function executeRequest(baseUrl, fetchFn, path, opts) {
|
|
302
|
+
if (!opts.skipAuth) await ensureAccessToken();
|
|
303
|
+
return request(baseUrl, fetchFn, path, mergeRequestHeaders(null, opts));
|
|
304
|
+
}
|
|
100
305
|
function createRequestHelpers(self, getEnv12) {
|
|
101
306
|
const env = () => getEnv12(self);
|
|
102
307
|
const baseUrl = () => env().baseUrl;
|
|
103
|
-
const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
308
|
+
const fetchFn = () => env().fetch ?? getConfigStore().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
104
309
|
throw new Error("fetch not available");
|
|
105
310
|
});
|
|
106
311
|
const req = (path, opts = {}) => {
|
|
107
312
|
const url = baseUrl();
|
|
108
313
|
if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
109
|
-
return
|
|
314
|
+
return executeRequest(url, fetchFn(), path, opts);
|
|
110
315
|
};
|
|
111
316
|
return {
|
|
112
317
|
req,
|
|
@@ -117,14 +322,14 @@ function createRequestHelpers(self, getEnv12) {
|
|
|
117
322
|
function createRequestHelpersFromEnv(env) {
|
|
118
323
|
const e = env ?? getConfig();
|
|
119
324
|
if (!e) throw new Error("Env required. Pass env to the method or call configure({ baseUrl }) at app startup.");
|
|
120
|
-
const baseUrl = () => e == null ? void 0 : e.baseUrl;
|
|
121
|
-
const fetchFn = () => (e == null ? void 0 : e.fetch) ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
325
|
+
const baseUrl = () => (e == null ? void 0 : e.baseUrl) ?? getConfigStore().baseUrl;
|
|
326
|
+
const fetchFn = () => (e == null ? void 0 : e.fetch) ?? getConfigStore().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
122
327
|
throw new Error("fetch not available");
|
|
123
328
|
});
|
|
124
329
|
const req = (path, opts = {}) => {
|
|
125
330
|
const url = baseUrl();
|
|
126
331
|
if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
127
|
-
return
|
|
332
|
+
return executeRequest(url, fetchFn(), path, opts);
|
|
128
333
|
};
|
|
129
334
|
return {
|
|
130
335
|
env: e,
|
|
@@ -171,6 +376,11 @@ var DayOfWeek = {
|
|
|
171
376
|
Friday: 5,
|
|
172
377
|
Saturday: 6
|
|
173
378
|
};
|
|
379
|
+
var EmailProvider = {
|
|
380
|
+
Google: 1,
|
|
381
|
+
Microsoft: 2,
|
|
382
|
+
Default: 3
|
|
383
|
+
};
|
|
174
384
|
var LocationType = {
|
|
175
385
|
Physical: 0,
|
|
176
386
|
Video: 1,
|
|
@@ -430,34 +640,34 @@ var EventModel = types4.model("Event", {
|
|
|
430
640
|
});
|
|
431
641
|
function mapEventFromApi(d) {
|
|
432
642
|
if (!d) return d;
|
|
433
|
-
const
|
|
643
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
434
644
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
435
645
|
return {
|
|
436
|
-
eventId: String(
|
|
437
|
-
calendarId: String(
|
|
438
|
-
participantId:
|
|
439
|
-
title:
|
|
440
|
-
description:
|
|
441
|
-
startDate:
|
|
442
|
-
endDate:
|
|
443
|
-
startHour: n(
|
|
444
|
-
startMinute: n(
|
|
445
|
-
endHour: n(
|
|
446
|
-
endMinute: n(
|
|
447
|
-
visitorName:
|
|
448
|
-
visitorEmail:
|
|
449
|
-
visitorPhone:
|
|
450
|
-
externalEventId:
|
|
451
|
-
calendarLocationId:
|
|
452
|
-
customLocation:
|
|
453
|
-
flowId:
|
|
454
|
-
flowPath:
|
|
455
|
-
attendeeStatus: n(
|
|
456
|
-
rescheduleLink:
|
|
457
|
-
cancelLink:
|
|
458
|
-
timeZone:
|
|
459
|
-
createdOn:
|
|
460
|
-
modifiedOn:
|
|
646
|
+
eventId: String(pick2("eventId", "EventId", "event_id") ?? ""),
|
|
647
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
648
|
+
participantId: pick2("participantId", "ParticipantId", "participant_id") ?? null,
|
|
649
|
+
title: pick2("title", "Title"),
|
|
650
|
+
description: pick2("description", "Description"),
|
|
651
|
+
startDate: pick2("startDate", "StartDate", "start_date"),
|
|
652
|
+
endDate: pick2("endDate", "EndDate", "end_date"),
|
|
653
|
+
startHour: n(pick2("startHour", "StartHour", "start_hour")),
|
|
654
|
+
startMinute: n(pick2("startMinute", "StartMinute", "start_minute")),
|
|
655
|
+
endHour: n(pick2("endHour", "EndHour", "end_hour")),
|
|
656
|
+
endMinute: n(pick2("endMinute", "EndMinute", "end_minute")),
|
|
657
|
+
visitorName: pick2("visitorName", "VisitorName", "visitor_name"),
|
|
658
|
+
visitorEmail: pick2("visitorEmail", "VisitorEmail", "visitor_email"),
|
|
659
|
+
visitorPhone: pick2("visitorPhone", "VisitorPhone", "visitor_phone"),
|
|
660
|
+
externalEventId: pick2("externalEventId", "ExternalEventId", "external_event_id"),
|
|
661
|
+
calendarLocationId: pick2("calendarLocationId", "CalendarLocationId", "calendar_location_id"),
|
|
662
|
+
customLocation: pick2("customLocation", "CustomLocation", "custom_location"),
|
|
663
|
+
flowId: pick2("flowId", "FlowId", "flow_id"),
|
|
664
|
+
flowPath: pick2("flowPath", "FlowPath", "flow_path"),
|
|
665
|
+
attendeeStatus: n(pick2("attendeeStatus", "AttendeeStatus", "attendee_status")),
|
|
666
|
+
rescheduleLink: pick2("rescheduleLink", "RescheduleLink", "reschedule_link"),
|
|
667
|
+
cancelLink: pick2("cancelLink", "CancelLink", "cancel_link"),
|
|
668
|
+
timeZone: pick2("timeZone", "TimeZone", "time_zone"),
|
|
669
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on"),
|
|
670
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on")
|
|
461
671
|
};
|
|
462
672
|
}
|
|
463
673
|
EventModel.get = async (eventId) => {
|
|
@@ -711,14 +921,14 @@ var CalendarParticipantModel = types6.model("CalendarParticipant", {
|
|
|
711
921
|
});
|
|
712
922
|
function mapFromApi(d) {
|
|
713
923
|
if (!d) return d;
|
|
714
|
-
const
|
|
924
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
715
925
|
return {
|
|
716
|
-
id:
|
|
717
|
-
calendarParticipantId: String(
|
|
718
|
-
participantId: String(
|
|
719
|
-
calendarId: String(
|
|
720
|
-
createdOn:
|
|
721
|
-
modifiedOn:
|
|
926
|
+
id: pick2("id", "Id"),
|
|
927
|
+
calendarParticipantId: String(pick2("calendarParticipantId", "CalendarParticipantId", "calendarparticipant_id") ?? ""),
|
|
928
|
+
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
929
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
930
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
931
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
722
932
|
};
|
|
723
933
|
}
|
|
724
934
|
CalendarParticipantModel.getByCalendar = async (calendarId) => {
|
|
@@ -986,30 +1196,30 @@ var CalendarModel = types8.model("Calendar", {
|
|
|
986
1196
|
});
|
|
987
1197
|
function mapCalendarFromApi(d) {
|
|
988
1198
|
if (!d) return d;
|
|
989
|
-
const
|
|
1199
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
990
1200
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
991
1201
|
return {
|
|
992
|
-
id:
|
|
993
|
-
companyKey:
|
|
994
|
-
calendarId:
|
|
995
|
-
name:
|
|
996
|
-
timeZoneId:
|
|
997
|
-
purpose:
|
|
998
|
-
description:
|
|
999
|
-
assignmentMethod: n(
|
|
1000
|
-
duration: n(
|
|
1001
|
-
durationUnit: n(
|
|
1002
|
-
minimumBookingNotice: n(
|
|
1003
|
-
minimumBookingNoticeUnit: n(
|
|
1004
|
-
minimumCancelationNotice: n(
|
|
1005
|
-
minimumCancelationNoticeUnit: n(
|
|
1006
|
-
futureLimit: n(
|
|
1007
|
-
futureLimitUnit: n(
|
|
1008
|
-
bufferTime: n(
|
|
1009
|
-
bufferTimeUnit: n(
|
|
1010
|
-
bookingLimit: n(
|
|
1011
|
-
createdOn:
|
|
1012
|
-
modifiedOn:
|
|
1202
|
+
id: pick2("id", "Id"),
|
|
1203
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key"),
|
|
1204
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? "",
|
|
1205
|
+
name: pick2("name", "Name"),
|
|
1206
|
+
timeZoneId: pick2("timeZoneId", "TimeZoneId", "time_zone_id"),
|
|
1207
|
+
purpose: pick2("purpose", "Purpose") ?? "",
|
|
1208
|
+
description: pick2("description", "Description"),
|
|
1209
|
+
assignmentMethod: n(pick2("assignmentMethod", "AssignmentMethod", "assignment_method")),
|
|
1210
|
+
duration: n(pick2("duration", "Duration")),
|
|
1211
|
+
durationUnit: n(pick2("durationUnit", "DurationUnit", "duration_unit")),
|
|
1212
|
+
minimumBookingNotice: n(pick2("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")),
|
|
1213
|
+
minimumBookingNoticeUnit: n(pick2("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")),
|
|
1214
|
+
minimumCancelationNotice: n(pick2("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")),
|
|
1215
|
+
minimumCancelationNoticeUnit: n(pick2("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")),
|
|
1216
|
+
futureLimit: n(pick2("futureLimit", "FutureLimit", "future_limit")),
|
|
1217
|
+
futureLimitUnit: n(pick2("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")),
|
|
1218
|
+
bufferTime: n(pick2("bufferTime", "BufferTime", "buffer_time")),
|
|
1219
|
+
bufferTimeUnit: n(pick2("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")),
|
|
1220
|
+
bookingLimit: n(pick2("bookingLimit", "BookingLimit", "booking_limit")),
|
|
1221
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on"),
|
|
1222
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on")
|
|
1013
1223
|
};
|
|
1014
1224
|
}
|
|
1015
1225
|
CalendarModel.getRaw = async (calendarId) => {
|
|
@@ -1234,6 +1444,15 @@ var ParticipantModel = types11.model("Participant", {
|
|
|
1234
1444
|
if (res.status === "success" && res.data) applySnapshot3(self, mapFromApi2(res.data));
|
|
1235
1445
|
return res;
|
|
1236
1446
|
},
|
|
1447
|
+
/** GET participant/getbyemail – fetch by companyKey + email on this snapshot */
|
|
1448
|
+
async getByEmail() {
|
|
1449
|
+
const res = await reqGet("/participant/getbyemail", {
|
|
1450
|
+
email: self.email,
|
|
1451
|
+
company_key: self.companyKey
|
|
1452
|
+
});
|
|
1453
|
+
if (res.status === "success" && res.data) applySnapshot3(self, mapFromApi2(res.data));
|
|
1454
|
+
return res;
|
|
1455
|
+
},
|
|
1237
1456
|
/** POST participant/save – save participant (add or update) */
|
|
1238
1457
|
async save() {
|
|
1239
1458
|
const payload = toPayload(self);
|
|
@@ -1295,19 +1514,19 @@ var ParticipantModel = types11.model("Participant", {
|
|
|
1295
1514
|
});
|
|
1296
1515
|
function mapFromApi2(d) {
|
|
1297
1516
|
if (!d) return d;
|
|
1298
|
-
const
|
|
1517
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1299
1518
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1300
1519
|
return {
|
|
1301
|
-
participantId: String(
|
|
1302
|
-
companyKey:
|
|
1303
|
-
alias:
|
|
1304
|
-
email:
|
|
1305
|
-
isApproved: Boolean(
|
|
1306
|
-
isAvailable: Boolean(
|
|
1307
|
-
provider: n(
|
|
1308
|
-
createdOn:
|
|
1309
|
-
modifiedOn:
|
|
1310
|
-
isDeleted: Boolean(
|
|
1520
|
+
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1521
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1522
|
+
alias: pick2("alias", "Alias") ?? "",
|
|
1523
|
+
email: pick2("email", "Email") ?? "",
|
|
1524
|
+
isApproved: Boolean(pick2("isApproved", "IsApproved", "is_approved")),
|
|
1525
|
+
isAvailable: Boolean(pick2("isAvailable", "IsAvailable", "is_available")),
|
|
1526
|
+
provider: n(pick2("provider", "Provider")) ?? 0,
|
|
1527
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1528
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
1529
|
+
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
1311
1530
|
};
|
|
1312
1531
|
}
|
|
1313
1532
|
function toPayload(self) {
|
|
@@ -1323,32 +1542,40 @@ function toPayload(self) {
|
|
|
1323
1542
|
}
|
|
1324
1543
|
function mapCalendarFromApi2(d) {
|
|
1325
1544
|
if (!d) return d;
|
|
1326
|
-
const
|
|
1545
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1327
1546
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1328
1547
|
return {
|
|
1329
|
-
id:
|
|
1330
|
-
companyKey:
|
|
1331
|
-
calendarId: String(
|
|
1332
|
-
name:
|
|
1333
|
-
timeZoneId:
|
|
1334
|
-
purpose:
|
|
1335
|
-
description:
|
|
1336
|
-
assignmentMethod: n(
|
|
1337
|
-
duration: n(
|
|
1338
|
-
durationUnit: n(
|
|
1339
|
-
minimumBookingNotice: n(
|
|
1340
|
-
minimumBookingNoticeUnit: n(
|
|
1341
|
-
minimumCancelationNotice: n(
|
|
1342
|
-
minimumCancelationNoticeUnit: n(
|
|
1343
|
-
futureLimit: n(
|
|
1344
|
-
futureLimitUnit: n(
|
|
1345
|
-
bufferTime: n(
|
|
1346
|
-
bufferTimeUnit: n(
|
|
1347
|
-
bookingLimit: n(
|
|
1348
|
-
createdOn:
|
|
1349
|
-
modifiedOn:
|
|
1548
|
+
id: pick2("id", "Id"),
|
|
1549
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1550
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1551
|
+
name: pick2("name", "Name") ?? null,
|
|
1552
|
+
timeZoneId: pick2("timeZoneId", "TimeZoneId", "time_zone_id") ?? null,
|
|
1553
|
+
purpose: pick2("purpose", "Purpose") ?? "",
|
|
1554
|
+
description: pick2("description", "Description") ?? null,
|
|
1555
|
+
assignmentMethod: n(pick2("assignmentMethod", "AssignmentMethod", "assignment_method")) ?? void 0,
|
|
1556
|
+
duration: n(pick2("duration", "Duration")) ?? void 0,
|
|
1557
|
+
durationUnit: n(pick2("durationUnit", "DurationUnit", "duration_unit")) ?? void 0,
|
|
1558
|
+
minimumBookingNotice: n(pick2("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")) ?? void 0,
|
|
1559
|
+
minimumBookingNoticeUnit: n(pick2("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")) ?? void 0,
|
|
1560
|
+
minimumCancelationNotice: n(pick2("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")) ?? void 0,
|
|
1561
|
+
minimumCancelationNoticeUnit: n(pick2("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")) ?? void 0,
|
|
1562
|
+
futureLimit: n(pick2("futureLimit", "FutureLimit", "future_limit")) ?? void 0,
|
|
1563
|
+
futureLimitUnit: n(pick2("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")) ?? void 0,
|
|
1564
|
+
bufferTime: n(pick2("bufferTime", "BufferTime", "buffer_time")) ?? void 0,
|
|
1565
|
+
bufferTimeUnit: n(pick2("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")) ?? void 0,
|
|
1566
|
+
bookingLimit: n(pick2("bookingLimit", "BookingLimit", "booking_limit")) ?? void 0,
|
|
1567
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1568
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1350
1569
|
};
|
|
1351
1570
|
}
|
|
1571
|
+
ParticipantModel.getByEmail = async (email, companyKey) => {
|
|
1572
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1573
|
+
const res = await reqGet("/participant/getbyemail", { email, company_key: companyKey });
|
|
1574
|
+
if (res.status === "success" && res.data) {
|
|
1575
|
+
return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
|
|
1576
|
+
}
|
|
1577
|
+
return null;
|
|
1578
|
+
};
|
|
1352
1579
|
ParticipantModel.get = async (participantId) => {
|
|
1353
1580
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1354
1581
|
const res = await reqGet("/participant/get", { participant_id: participantId });
|
|
@@ -1492,14 +1719,14 @@ var SettingModel = types13.model("Setting", {
|
|
|
1492
1719
|
});
|
|
1493
1720
|
function mapFromApi3(d) {
|
|
1494
1721
|
if (!d) return d;
|
|
1495
|
-
const
|
|
1722
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1496
1723
|
return {
|
|
1497
|
-
settingsId: String(
|
|
1498
|
-
calendarId: String(
|
|
1499
|
-
logo:
|
|
1500
|
-
theme:
|
|
1501
|
-
schedulingButtonText:
|
|
1502
|
-
scheduledMessage:
|
|
1724
|
+
settingsId: String(pick2("settingsId", "SettingsId", "settings_id") ?? ""),
|
|
1725
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1726
|
+
logo: pick2("logo", "Logo") ?? null,
|
|
1727
|
+
theme: pick2("theme", "Theme") ?? null,
|
|
1728
|
+
schedulingButtonText: pick2("schedulingButtonText", "SchedulingButtonText", "scheduling_button_text") ?? null,
|
|
1729
|
+
scheduledMessage: pick2("scheduledMessage", "ScheduledMessage", "scheduled_message") ?? null
|
|
1503
1730
|
};
|
|
1504
1731
|
}
|
|
1505
1732
|
function toPayload2(self) {
|
|
@@ -1527,6 +1754,7 @@ SettingModel.save = async (payload) => {
|
|
|
1527
1754
|
SettingModel.uploadLogo = async (calendarId, file) => {
|
|
1528
1755
|
const cfg = getConfig();
|
|
1529
1756
|
if (!(cfg == null ? void 0 : cfg.baseUrl)) throw new Error("Configure baseUrl before uploadLogo");
|
|
1757
|
+
await ensureAccessToken();
|
|
1530
1758
|
const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
1531
1759
|
throw new Error("fetch not available");
|
|
1532
1760
|
});
|
|
@@ -1536,6 +1764,7 @@ SettingModel.uploadLogo = async (calendarId, file) => {
|
|
|
1536
1764
|
formData.append("file", file);
|
|
1537
1765
|
const res = await fetchFn(url, {
|
|
1538
1766
|
method: "POST",
|
|
1767
|
+
headers: buildAuthHeaders(),
|
|
1539
1768
|
body: formData
|
|
1540
1769
|
});
|
|
1541
1770
|
const text = await res.text();
|
|
@@ -1581,12 +1810,12 @@ var CompanyModel = types14.model("Company", {
|
|
|
1581
1810
|
});
|
|
1582
1811
|
function mapFromApi4(d) {
|
|
1583
1812
|
if (!d) return d;
|
|
1584
|
-
const
|
|
1813
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1585
1814
|
return {
|
|
1586
|
-
companyKey: String(
|
|
1587
|
-
companyName:
|
|
1588
|
-
createdOn:
|
|
1589
|
-
modifiedOn:
|
|
1815
|
+
companyKey: String(pick2("companyKey", "CompanyKey", "company_key") ?? ""),
|
|
1816
|
+
companyName: pick2("companyName", "CompanyName", "company_name") ?? "",
|
|
1817
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1818
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1590
1819
|
};
|
|
1591
1820
|
}
|
|
1592
1821
|
function toPayload3(self) {
|
|
@@ -1658,6 +1887,7 @@ AssetModel.upload = async (file, opts = {}) => {
|
|
|
1658
1887
|
if (!file) return { status: "failure", message: "file is required" };
|
|
1659
1888
|
const category = opts.category != null ? String(opts.category).trim() : "";
|
|
1660
1889
|
if (!category) return { status: "failure", message: "category is required" };
|
|
1890
|
+
await ensureAccessToken();
|
|
1661
1891
|
const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
1662
1892
|
throw new Error("fetch not available");
|
|
1663
1893
|
});
|
|
@@ -1672,8 +1902,7 @@ AssetModel.upload = async (file, opts = {}) => {
|
|
|
1672
1902
|
if (opts.calendarId != null && String(opts.calendarId).trim() !== "") {
|
|
1673
1903
|
formData.append("calendar_id", String(opts.calendarId).trim());
|
|
1674
1904
|
}
|
|
1675
|
-
const headers =
|
|
1676
|
-
if (cfg.consumer) headers.Consumer = cfg.consumer;
|
|
1905
|
+
const headers = buildAuthHeaders();
|
|
1677
1906
|
if (opts.consumer != null && String(opts.consumer).trim() !== "") {
|
|
1678
1907
|
headers.Consumer = String(opts.consumer).trim();
|
|
1679
1908
|
}
|
|
@@ -1705,20 +1934,20 @@ var Asset_default = AssetModel;
|
|
|
1705
1934
|
import { types as types16, getEnv as getEnv7, applySnapshot as applySnapshot6 } from "mobx-state-tree";
|
|
1706
1935
|
function mapCalendarLocationFromApi(d) {
|
|
1707
1936
|
if (!d) return d;
|
|
1708
|
-
const
|
|
1937
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1709
1938
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1710
1939
|
const b = (v) => v === true || v === "true" || v === 1 || v === "1";
|
|
1711
1940
|
return {
|
|
1712
|
-
id: n(
|
|
1713
|
-
calendarLocationId:
|
|
1714
|
-
calendarId:
|
|
1715
|
-
locationType: n(
|
|
1716
|
-
name:
|
|
1717
|
-
value:
|
|
1718
|
-
isDefault: b(
|
|
1719
|
-
sortOrder: n(
|
|
1720
|
-
createdOn:
|
|
1721
|
-
modifiedOn:
|
|
1941
|
+
id: n(pick2("id", "Id")),
|
|
1942
|
+
calendarLocationId: pick2("calendarLocationId", "CalendarLocationId", "calendar_location_id") ?? null,
|
|
1943
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
1944
|
+
locationType: n(pick2("locationType", "LocationType", "location_type")),
|
|
1945
|
+
name: pick2("name", "Name") ?? "",
|
|
1946
|
+
value: pick2("value", "Value") ?? "",
|
|
1947
|
+
isDefault: b(pick2("isDefault", "IsDefault", "is_default")),
|
|
1948
|
+
sortOrder: n(pick2("sortOrder", "SortOrder", "sort_order")) ?? 0,
|
|
1949
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1950
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1722
1951
|
};
|
|
1723
1952
|
}
|
|
1724
1953
|
function toPayload4(self) {
|
|
@@ -1876,20 +2105,20 @@ var Preference_default = PreferenceModel;
|
|
|
1876
2105
|
import { types as types18, getEnv as getEnv8, applySnapshot as applySnapshot7 } from "mobx-state-tree";
|
|
1877
2106
|
function mapFlowFromApi(d) {
|
|
1878
2107
|
if (!d) return d;
|
|
1879
|
-
const
|
|
2108
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1880
2109
|
const b = (v) => v === true || v === "true" || v === 1;
|
|
1881
2110
|
return {
|
|
1882
|
-
id:
|
|
1883
|
-
flowId:
|
|
1884
|
-
companyKey:
|
|
1885
|
-
calendarId:
|
|
1886
|
-
name:
|
|
1887
|
-
description:
|
|
1888
|
-
flowJson:
|
|
1889
|
-
isActive: b(
|
|
1890
|
-
isDeleted: b(
|
|
1891
|
-
createdOn:
|
|
1892
|
-
modifiedOn:
|
|
2111
|
+
id: pick2("id", "Id") ?? null,
|
|
2112
|
+
flowId: pick2("flowId", "FlowId", "flow_id") ?? "",
|
|
2113
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? "",
|
|
2114
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
2115
|
+
name: pick2("name", "Name") ?? "",
|
|
2116
|
+
description: pick2("description", "Description") ?? null,
|
|
2117
|
+
flowJson: pick2("flowJson", "FlowJson", "flow_json") ?? "",
|
|
2118
|
+
isActive: b(pick2("isActive", "IsActive", "is_active")) ?? true,
|
|
2119
|
+
isDeleted: b(pick2("isDeleted", "IsDeleted", "is_deleted")) ?? false,
|
|
2120
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2121
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1893
2122
|
};
|
|
1894
2123
|
}
|
|
1895
2124
|
var FlowModel = types18.model("Flow", {
|
|
@@ -2139,8 +2368,8 @@ var Flow_default = FlowModel;
|
|
|
2139
2368
|
import { types as types19, getEnv as getEnv9, applySnapshot as applySnapshot8, getSnapshot } from "mobx-state-tree";
|
|
2140
2369
|
function mapLeadFromApi(d) {
|
|
2141
2370
|
if (!d) return d;
|
|
2142
|
-
const
|
|
2143
|
-
const leadTypeRaw =
|
|
2371
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2372
|
+
const leadTypeRaw = pick2("leadType", "LeadType", "lead_type");
|
|
2144
2373
|
let leadType = 2;
|
|
2145
2374
|
if (typeof leadTypeRaw === "number" && Number.isFinite(leadTypeRaw)) {
|
|
2146
2375
|
leadType = leadTypeRaw;
|
|
@@ -2152,17 +2381,17 @@ function mapLeadFromApi(d) {
|
|
|
2152
2381
|
else if (!Number.isNaN(Number(leadTypeRaw))) leadType = Number(leadTypeRaw);
|
|
2153
2382
|
}
|
|
2154
2383
|
return {
|
|
2155
|
-
id:
|
|
2156
|
-
leadId:
|
|
2157
|
-
email:
|
|
2158
|
-
name:
|
|
2159
|
-
phone:
|
|
2160
|
-
companyKey:
|
|
2161
|
-
source:
|
|
2384
|
+
id: pick2("id", "Id") ?? null,
|
|
2385
|
+
leadId: pick2("leadId", "LeadId", "lead_id") ?? "",
|
|
2386
|
+
email: pick2("email", "Email") ?? "",
|
|
2387
|
+
name: pick2("name", "Name") ?? "",
|
|
2388
|
+
phone: pick2("phone", "Phone") ?? "",
|
|
2389
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? "",
|
|
2390
|
+
source: pick2("source", "Source") ?? "",
|
|
2162
2391
|
leadType,
|
|
2163
|
-
referrerLink:
|
|
2164
|
-
createdOn:
|
|
2165
|
-
modifiedOn:
|
|
2392
|
+
referrerLink: pick2("referrerLink", "ReferrerLink", "referrer_link") ?? "",
|
|
2393
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2394
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
2166
2395
|
};
|
|
2167
2396
|
}
|
|
2168
2397
|
var LeadModel = types19.model("Lead", {
|
|
@@ -2449,17 +2678,17 @@ var CustomFieldModel = types20.model("CustomField", {
|
|
|
2449
2678
|
});
|
|
2450
2679
|
function mapCustomFieldFromApi(d) {
|
|
2451
2680
|
if (!d) return d;
|
|
2452
|
-
const
|
|
2681
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2453
2682
|
return {
|
|
2454
|
-
id:
|
|
2455
|
-
customFieldId:
|
|
2456
|
-
calendarId:
|
|
2457
|
-
label:
|
|
2458
|
-
type:
|
|
2459
|
-
isRequired: Boolean(
|
|
2460
|
-
createdOn:
|
|
2461
|
-
modifiedOn:
|
|
2462
|
-
isDeleted: Boolean(
|
|
2683
|
+
id: pick2("id", "Id") ?? null,
|
|
2684
|
+
customFieldId: pick2("customFieldId", "CustomFieldId", "custom_field_id") ?? null,
|
|
2685
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
2686
|
+
label: pick2("label", "Label") ?? null,
|
|
2687
|
+
type: pick2("type", "Type") ?? "",
|
|
2688
|
+
isRequired: Boolean(pick2("isRequired", "IsRequired", "is_required")),
|
|
2689
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2690
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
2691
|
+
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
2463
2692
|
};
|
|
2464
2693
|
}
|
|
2465
2694
|
function toPayload5(self) {
|
|
@@ -2533,6 +2762,150 @@ CustomFieldModel.saveFormFieldData = async (fieldPayload) => {
|
|
|
2533
2762
|
};
|
|
2534
2763
|
var CustomField_default = CustomFieldModel;
|
|
2535
2764
|
|
|
2765
|
+
// src/models/appointment/Auth.js
|
|
2766
|
+
var CALENDAR_AUTH_MESSAGE_TYPE = "calendar-authorization";
|
|
2767
|
+
var EmailProvider2 = {
|
|
2768
|
+
Google: 1,
|
|
2769
|
+
Microsoft: 2,
|
|
2770
|
+
Default: 3
|
|
2771
|
+
};
|
|
2772
|
+
function pick(d, ...keys) {
|
|
2773
|
+
return keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2774
|
+
}
|
|
2775
|
+
function mapCalendarProviderFromApi(d) {
|
|
2776
|
+
if (!d) return d;
|
|
2777
|
+
return {
|
|
2778
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2779
|
+
key: pick(d, "key", "Key") ?? "",
|
|
2780
|
+
name: pick(d, "name", "Name") ?? "",
|
|
2781
|
+
displayName: pick(d, "displayName", "DisplayName", "display_name") ?? "",
|
|
2782
|
+
description: pick(d, "description", "Description") ?? "",
|
|
2783
|
+
scope: pick(d, "scope", "Scope") ?? "",
|
|
2784
|
+
redirectUrl: pick(d, "redirectUrl", "RedirectUrl", "redirect_url") ?? ""
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
function mapAuthorizationUrlFromApi(d) {
|
|
2788
|
+
if (!d) return d;
|
|
2789
|
+
return {
|
|
2790
|
+
participantId: String(pick(d, "participantId", "ParticipantId", "participant_id") ?? ""),
|
|
2791
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2792
|
+
providerKey: pick(d, "providerKey", "ProviderKey", "provider_key") ?? "",
|
|
2793
|
+
authorizationUrl: pick(d, "authorizationUrl", "AuthorizationUrl", "authorization_url") ?? "",
|
|
2794
|
+
redirectUrl: pick(d, "redirectUrl", "RedirectUrl", "redirect_url") ?? ""
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
function mapProviderStateFromApi(d) {
|
|
2798
|
+
if (!d) return d;
|
|
2799
|
+
return {
|
|
2800
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2801
|
+
key: pick(d, "key", "Key") ?? "",
|
|
2802
|
+
name: pick(d, "name", "Name") ?? "",
|
|
2803
|
+
hasCredentials: Boolean(pick(d, "hasCredentials", "HasCredentials", "has_credentials")),
|
|
2804
|
+
isAuthorized: Boolean(pick(d, "isAuthorized", "IsAuthorized", "is_authorized")),
|
|
2805
|
+
isSelected: Boolean(pick(d, "isSelected", "IsSelected", "is_selected"))
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
function mapAuthorizationStatusFromApi(d) {
|
|
2809
|
+
if (!d) return d;
|
|
2810
|
+
const providersRaw = pick(d, "providers", "Providers");
|
|
2811
|
+
return {
|
|
2812
|
+
participantId: String(pick(d, "participantId", "ParticipantId", "participant_id") ?? ""),
|
|
2813
|
+
email: pick(d, "email", "Email") ?? "",
|
|
2814
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2815
|
+
providerKey: pick(d, "providerKey", "ProviderKey", "provider_key") ?? "",
|
|
2816
|
+
hasCredentials: Boolean(pick(d, "hasCredentials", "HasCredentials", "has_credentials")),
|
|
2817
|
+
isAuthorized: Boolean(pick(d, "isAuthorized", "IsAuthorized", "is_authorized")),
|
|
2818
|
+
providers: Array.isArray(providersRaw) ? providersRaw.map(mapProviderStateFromApi) : []
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
var AuthModel = {
|
|
2822
|
+
CALENDAR_AUTH_MESSAGE_TYPE,
|
|
2823
|
+
EmailProvider: EmailProvider2,
|
|
2824
|
+
/**
|
|
2825
|
+
* GET Auth/CalendarProviders — supported providers (Google / Outlook) for the Scheduling modal.
|
|
2826
|
+
* @param {{ host?: string }} [opts]
|
|
2827
|
+
* @returns {Promise<{ status: string, data?: object[], message?: string }>}
|
|
2828
|
+
*/
|
|
2829
|
+
async getCalendarProviders(opts = {}) {
|
|
2830
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2831
|
+
const q = {};
|
|
2832
|
+
if (opts.host) q.host = opts.host;
|
|
2833
|
+
const res = await reqGet("/Auth/CalendarProviders", q);
|
|
2834
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
2835
|
+
res.data = res.data.map(mapCalendarProviderFromApi);
|
|
2836
|
+
}
|
|
2837
|
+
return res;
|
|
2838
|
+
},
|
|
2839
|
+
/**
|
|
2840
|
+
* GET Auth/AuthorizationUrl — OAuth URL to open in a popup when user picks a provider.
|
|
2841
|
+
* @param {string} participantId
|
|
2842
|
+
* @param {string|number} emailProvider — google, gmail, 1, outlook, microsoft, 2
|
|
2843
|
+
* @param {{ host?: string }} [opts]
|
|
2844
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2845
|
+
*/
|
|
2846
|
+
async getAuthorizationUrl(participantId, emailProvider, opts = {}) {
|
|
2847
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2848
|
+
const q = {
|
|
2849
|
+
participant_id: participantId,
|
|
2850
|
+
email_provider: String(emailProvider)
|
|
2851
|
+
};
|
|
2852
|
+
if (opts.host) q.host = opts.host;
|
|
2853
|
+
const res = await reqGet("/Auth/AuthorizationUrl", q);
|
|
2854
|
+
if (res.status === "success" && res.data) {
|
|
2855
|
+
res.data = mapAuthorizationUrlFromApi(res.data);
|
|
2856
|
+
}
|
|
2857
|
+
return res;
|
|
2858
|
+
},
|
|
2859
|
+
/**
|
|
2860
|
+
* GET Auth/Status — whether participant calendar is connected (call after OAuth popup).
|
|
2861
|
+
* @param {string} participantId
|
|
2862
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2863
|
+
*/
|
|
2864
|
+
async getAuthorizationStatus(participantId) {
|
|
2865
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2866
|
+
const res = await reqGet("/Auth/Status", { participant_id: participantId });
|
|
2867
|
+
if (res.status === "success" && res.data) {
|
|
2868
|
+
res.data = mapAuthorizationStatusFromApi(res.data);
|
|
2869
|
+
}
|
|
2870
|
+
return res;
|
|
2871
|
+
},
|
|
2872
|
+
/**
|
|
2873
|
+
* Open Google/Microsoft OAuth in a centered popup.
|
|
2874
|
+
* @param {string} authorizationUrl — from getAuthorizationUrl().data.authorizationUrl
|
|
2875
|
+
* @param {{ width?: number, height?: number }} [opts]
|
|
2876
|
+
* @returns {Window | null}
|
|
2877
|
+
*/
|
|
2878
|
+
openOAuthPopup(authorizationUrl, opts = {}) {
|
|
2879
|
+
if (typeof window === "undefined" || !authorizationUrl) return null;
|
|
2880
|
+
const width = opts.width ?? 500;
|
|
2881
|
+
const height = opts.height ?? 650;
|
|
2882
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
2883
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
2884
|
+
return window.open(
|
|
2885
|
+
authorizationUrl,
|
|
2886
|
+
"calendar-oauth",
|
|
2887
|
+
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes`
|
|
2888
|
+
);
|
|
2889
|
+
},
|
|
2890
|
+
/**
|
|
2891
|
+
* Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
|
|
2892
|
+
* @param {(payload: { type: string, status: 'success' | 'error', message?: string }) => void} handler
|
|
2893
|
+
* @returns {() => void} unsubscribe
|
|
2894
|
+
*/
|
|
2895
|
+
onCalendarAuthMessage(handler) {
|
|
2896
|
+
if (typeof window === "undefined") return () => {
|
|
2897
|
+
};
|
|
2898
|
+
const listener = (event) => {
|
|
2899
|
+
const payload = event == null ? void 0 : event.data;
|
|
2900
|
+
if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
|
|
2901
|
+
handler(payload);
|
|
2902
|
+
};
|
|
2903
|
+
window.addEventListener("message", listener);
|
|
2904
|
+
return () => window.removeEventListener("message", listener);
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
var Auth_default = AuthModel;
|
|
2908
|
+
|
|
2536
2909
|
// src/models/appointment/index.js
|
|
2537
2910
|
import { types as types21, getEnv as getEnv11 } from "mobx-state-tree";
|
|
2538
2911
|
var RootStore = types21.model("RootStore", {
|
|
@@ -2559,9 +2932,12 @@ export {
|
|
|
2559
2932
|
Asset_default as AssetModel,
|
|
2560
2933
|
AssignmentMethod,
|
|
2561
2934
|
AttendeeStatus,
|
|
2935
|
+
Auth_default as AuthModel,
|
|
2562
2936
|
AvailabilityDetail_default as AvailabilityDetailModel,
|
|
2563
2937
|
Availability_default as AvailabilityModel,
|
|
2938
|
+
CALENDAR_AUTH_MESSAGE_TYPE,
|
|
2564
2939
|
CalendarDay_default as CalendarDayModel,
|
|
2940
|
+
EmailProvider2 as CalendarEmailProvider,
|
|
2565
2941
|
CalendarLocation_default as CalendarLocationModel,
|
|
2566
2942
|
Calendar_default as CalendarModel,
|
|
2567
2943
|
CalendarParticipant_default as CalendarParticipantModel,
|
|
@@ -2569,6 +2945,7 @@ export {
|
|
|
2569
2945
|
ConfigModel_default as ConfigModel,
|
|
2570
2946
|
CustomField_default as CustomFieldModel,
|
|
2571
2947
|
DayOfWeek,
|
|
2948
|
+
EmailProvider,
|
|
2572
2949
|
Event_default as EventModel,
|
|
2573
2950
|
Flow_default as FlowModel,
|
|
2574
2951
|
Lead_default as LeadModel,
|
|
@@ -2581,12 +2958,25 @@ export {
|
|
|
2581
2958
|
RecurringFrequency,
|
|
2582
2959
|
RootStore,
|
|
2583
2960
|
Setting_default as SettingModel,
|
|
2961
|
+
TOKEN_PATH,
|
|
2584
2962
|
TimeFrame_default as TimeFrameModel,
|
|
2585
2963
|
TimeSlot_default as TimeSlotModel,
|
|
2586
2964
|
Unit,
|
|
2965
|
+
buildAuthHeaders,
|
|
2966
|
+
clearAccessToken,
|
|
2967
|
+
clearApiCredentials,
|
|
2968
|
+
clearAuth,
|
|
2587
2969
|
configure,
|
|
2588
2970
|
createRootStore,
|
|
2971
|
+
ensureValidAccessToken,
|
|
2972
|
+
fetchAccessToken2 as fetchAccessToken,
|
|
2973
|
+
getAuth,
|
|
2589
2974
|
getConfig,
|
|
2590
2975
|
getConfigStore,
|
|
2591
|
-
|
|
2976
|
+
isAccessTokenExpired,
|
|
2977
|
+
requestAccessToken,
|
|
2978
|
+
setAccessToken,
|
|
2979
|
+
setApiCredentials,
|
|
2980
|
+
setBaseUrl,
|
|
2981
|
+
setConsumer
|
|
2592
2982
|
};
|