@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.js
CHANGED
|
@@ -22,9 +22,12 @@ __export(index_exports, {
|
|
|
22
22
|
AssetModel: () => Asset_default,
|
|
23
23
|
AssignmentMethod: () => AssignmentMethod,
|
|
24
24
|
AttendeeStatus: () => AttendeeStatus,
|
|
25
|
+
AuthModel: () => Auth_default,
|
|
25
26
|
AvailabilityDetailModel: () => AvailabilityDetail_default,
|
|
26
27
|
AvailabilityModel: () => Availability_default,
|
|
28
|
+
CALENDAR_AUTH_MESSAGE_TYPE: () => CALENDAR_AUTH_MESSAGE_TYPE,
|
|
27
29
|
CalendarDayModel: () => CalendarDay_default,
|
|
30
|
+
CalendarEmailProvider: () => EmailProvider2,
|
|
28
31
|
CalendarLocationModel: () => CalendarLocation_default,
|
|
29
32
|
CalendarModel: () => Calendar_default,
|
|
30
33
|
CalendarParticipantModel: () => CalendarParticipant_default,
|
|
@@ -32,6 +35,7 @@ __export(index_exports, {
|
|
|
32
35
|
ConfigModel: () => ConfigModel_default,
|
|
33
36
|
CustomFieldModel: () => CustomField_default,
|
|
34
37
|
DayOfWeek: () => DayOfWeek,
|
|
38
|
+
EmailProvider: () => EmailProvider,
|
|
35
39
|
EventModel: () => Event_default,
|
|
36
40
|
FlowModel: () => Flow_default,
|
|
37
41
|
LeadModel: () => Lead_default,
|
|
@@ -44,14 +48,27 @@ __export(index_exports, {
|
|
|
44
48
|
RecurringFrequency: () => RecurringFrequency,
|
|
45
49
|
RootStore: () => RootStore,
|
|
46
50
|
SettingModel: () => Setting_default,
|
|
51
|
+
TOKEN_PATH: () => TOKEN_PATH,
|
|
47
52
|
TimeFrameModel: () => TimeFrame_default,
|
|
48
53
|
TimeSlotModel: () => TimeSlot_default,
|
|
49
54
|
Unit: () => Unit,
|
|
55
|
+
buildAuthHeaders: () => buildAuthHeaders,
|
|
56
|
+
clearAccessToken: () => clearAccessToken,
|
|
57
|
+
clearApiCredentials: () => clearApiCredentials,
|
|
58
|
+
clearAuth: () => clearAuth,
|
|
50
59
|
configure: () => configure,
|
|
51
60
|
createRootStore: () => createRootStore,
|
|
61
|
+
ensureValidAccessToken: () => ensureValidAccessToken,
|
|
62
|
+
fetchAccessToken: () => fetchAccessToken2,
|
|
63
|
+
getAuth: () => getAuth,
|
|
52
64
|
getConfig: () => getConfig,
|
|
53
65
|
getConfigStore: () => getConfigStore,
|
|
54
|
-
|
|
66
|
+
isAccessTokenExpired: () => isAccessTokenExpired,
|
|
67
|
+
requestAccessToken: () => requestAccessToken,
|
|
68
|
+
setAccessToken: () => setAccessToken,
|
|
69
|
+
setApiCredentials: () => setApiCredentials,
|
|
70
|
+
setBaseUrl: () => setBaseUrl,
|
|
71
|
+
setConsumer: () => setConsumer
|
|
55
72
|
});
|
|
56
73
|
module.exports = __toCommonJS(index_exports);
|
|
57
74
|
|
|
@@ -65,6 +82,10 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
|
|
|
65
82
|
consumer: import_mobx_state_tree.types.optional(import_mobx_state_tree.types.string, "")
|
|
66
83
|
}).volatile(() => ({
|
|
67
84
|
fetch: void 0,
|
|
85
|
+
accessToken: void 0,
|
|
86
|
+
tokenExpiresAt: void 0,
|
|
87
|
+
apiKey: void 0,
|
|
88
|
+
apiSecret: void 0,
|
|
68
89
|
getDefaultOffset: () => -(/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
69
90
|
})).actions((self) => ({
|
|
70
91
|
setBaseUrl(url) {
|
|
@@ -79,19 +100,57 @@ var ConfigModel = import_mobx_state_tree.types.model("Config", {
|
|
|
79
100
|
setGetDefaultOffset(fn) {
|
|
80
101
|
self.getDefaultOffset = fn;
|
|
81
102
|
},
|
|
103
|
+
setAccessToken(token, expiresAtUtc = void 0) {
|
|
104
|
+
self.accessToken = token ? String(token) : void 0;
|
|
105
|
+
self.tokenExpiresAt = expiresAtUtc != null && expiresAtUtc !== "" ? String(expiresAtUtc) : void 0;
|
|
106
|
+
},
|
|
107
|
+
clearAccessToken() {
|
|
108
|
+
self.accessToken = void 0;
|
|
109
|
+
self.tokenExpiresAt = void 0;
|
|
110
|
+
},
|
|
111
|
+
setApiCredentials(apiKey, apiSecret) {
|
|
112
|
+
self.apiKey = apiKey != null ? String(apiKey) : void 0;
|
|
113
|
+
self.apiSecret = apiSecret != null ? String(apiSecret) : void 0;
|
|
114
|
+
},
|
|
115
|
+
clearApiCredentials() {
|
|
116
|
+
self.apiKey = void 0;
|
|
117
|
+
self.apiSecret = void 0;
|
|
118
|
+
},
|
|
119
|
+
clearAuth() {
|
|
120
|
+
self.clearAccessToken();
|
|
121
|
+
self.clearApiCredentials();
|
|
122
|
+
},
|
|
82
123
|
configure(env) {
|
|
83
124
|
if (env.baseUrl != null) self.baseUrl = env.baseUrl;
|
|
84
125
|
if (env.consumer != null) self.consumer = env.consumer;
|
|
85
126
|
if (env.fetch != null) self.fetch = env.fetch;
|
|
86
127
|
if (env.getDefaultOffset != null) self.getDefaultOffset = env.getDefaultOffset;
|
|
128
|
+
if (env.accessToken != null) {
|
|
129
|
+
self.setAccessToken(
|
|
130
|
+
env.accessToken,
|
|
131
|
+
env.expiresAtUtc ?? env.tokenExpiresAt ?? env.expires_at_utc
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (env.apiKey != null || env.api_key != null) {
|
|
135
|
+
self.apiKey = String(env.apiKey ?? env.api_key);
|
|
136
|
+
}
|
|
137
|
+
if (env.apiSecret != null || env.api_secret != null) {
|
|
138
|
+
self.apiSecret = String(env.apiSecret ?? env.api_secret);
|
|
139
|
+
}
|
|
87
140
|
}
|
|
88
141
|
})).views((self) => ({
|
|
142
|
+
get hasApiCredentials() {
|
|
143
|
+
return Boolean(self.apiKey && self.apiSecret);
|
|
144
|
+
},
|
|
89
145
|
getEnv() {
|
|
90
146
|
return {
|
|
91
147
|
baseUrl: self.baseUrl || void 0,
|
|
92
148
|
consumer: self.consumer || void 0,
|
|
93
149
|
fetch: self.fetch,
|
|
94
|
-
getDefaultOffset: self.getDefaultOffset
|
|
150
|
+
getDefaultOffset: self.getDefaultOffset,
|
|
151
|
+
accessToken: self.accessToken,
|
|
152
|
+
tokenExpiresAt: self.tokenExpiresAt,
|
|
153
|
+
hasApiCredentials: self.hasApiCredentials
|
|
95
154
|
};
|
|
96
155
|
}
|
|
97
156
|
}));
|
|
@@ -102,6 +161,122 @@ function getConfigStore() {
|
|
|
102
161
|
}
|
|
103
162
|
var ConfigModel_default = ConfigModel;
|
|
104
163
|
|
|
164
|
+
// src/apiAuth.js
|
|
165
|
+
var TOKEN_PATH = "/Api/Auth/Token";
|
|
166
|
+
var DEFAULT_TOKEN_REFRESH_SKEW_MS = 6e4;
|
|
167
|
+
function defaultFetch() {
|
|
168
|
+
if (typeof fetch === "undefined") {
|
|
169
|
+
throw new Error("fetch not available");
|
|
170
|
+
}
|
|
171
|
+
return fetch;
|
|
172
|
+
}
|
|
173
|
+
function pickTokenPayload(data) {
|
|
174
|
+
if (!data || typeof data !== "object") return null;
|
|
175
|
+
const nested = data.data && typeof data.data === "object" ? data.data : data;
|
|
176
|
+
const accessToken = nested.access_token ?? nested.accessToken ?? nested.AccessToken ?? null;
|
|
177
|
+
if (!accessToken) return null;
|
|
178
|
+
const expiresAtUtc = nested.expires_at_utc ?? nested.expiresAtUtc ?? nested.ExpiresAtUtc ?? null;
|
|
179
|
+
return {
|
|
180
|
+
accessToken: String(accessToken),
|
|
181
|
+
expiresAtUtc: expiresAtUtc != null ? String(expiresAtUtc) : null,
|
|
182
|
+
tokenType: nested.token_type ?? nested.tokenType ?? "Bearer"
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function isAccessTokenExpired(expiresAtUtc, skewMs = DEFAULT_TOKEN_REFRESH_SKEW_MS) {
|
|
186
|
+
if (expiresAtUtc == null || expiresAtUtc === "") return false;
|
|
187
|
+
const expMs = new Date(expiresAtUtc).getTime();
|
|
188
|
+
if (Number.isNaN(expMs)) return false;
|
|
189
|
+
return Date.now() >= expMs - skewMs;
|
|
190
|
+
}
|
|
191
|
+
function getAuthState() {
|
|
192
|
+
const store = getConfigStore();
|
|
193
|
+
return {
|
|
194
|
+
accessToken: store.accessToken ?? void 0,
|
|
195
|
+
tokenExpiresAt: store.tokenExpiresAt ?? void 0,
|
|
196
|
+
apiKey: store.apiKey ?? void 0,
|
|
197
|
+
apiSecret: store.apiSecret ?? void 0,
|
|
198
|
+
hasApiCredentials: Boolean(store.apiKey && store.apiSecret)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async function requestAccessToken(apiKey, apiSecret, opts = {}) {
|
|
202
|
+
const store = getConfigStore();
|
|
203
|
+
const baseUrl = opts.baseUrl ?? store.baseUrl;
|
|
204
|
+
if (!baseUrl) {
|
|
205
|
+
return { status: "failure", message: "baseUrl required. Call configure({ baseUrl }) first." };
|
|
206
|
+
}
|
|
207
|
+
const key = apiKey != null ? String(apiKey).trim() : "";
|
|
208
|
+
const secret = apiSecret != null ? String(apiSecret).trim() : "";
|
|
209
|
+
if (!key || !secret) {
|
|
210
|
+
return { status: "failure", message: "api_key and api_secret are required" };
|
|
211
|
+
}
|
|
212
|
+
const fetchFn = opts.fetch ?? store.fetch ?? defaultFetch();
|
|
213
|
+
const url = `${String(baseUrl).replace(/\/+$/, "")}${TOKEN_PATH}`;
|
|
214
|
+
const httpRes = await fetchFn(url, {
|
|
215
|
+
method: "POST",
|
|
216
|
+
headers: { "Content-Type": "application/json" },
|
|
217
|
+
body: JSON.stringify({ api_key: key, api_secret: secret })
|
|
218
|
+
});
|
|
219
|
+
const text = await httpRes.text();
|
|
220
|
+
let body;
|
|
221
|
+
try {
|
|
222
|
+
body = JSON.parse(text);
|
|
223
|
+
} catch {
|
|
224
|
+
body = { status: "failure", message: text || httpRes.statusText };
|
|
225
|
+
}
|
|
226
|
+
if (!httpRes.ok && body.status !== "failure") {
|
|
227
|
+
body.status = "failure";
|
|
228
|
+
body.message = body.message ?? `HTTP ${httpRes.status}`;
|
|
229
|
+
}
|
|
230
|
+
if (body.status !== "success") {
|
|
231
|
+
return {
|
|
232
|
+
status: "failure",
|
|
233
|
+
message: body.message ?? "Failed to obtain access token"
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const parsed = pickTokenPayload(body);
|
|
237
|
+
if (!parsed) {
|
|
238
|
+
return { status: "failure", message: "Token response missing access_token" };
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
status: "success",
|
|
242
|
+
accessToken: parsed.accessToken,
|
|
243
|
+
expiresAtUtc: parsed.expiresAtUtc,
|
|
244
|
+
tokenType: parsed.tokenType
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async function fetchAccessToken(apiKey, apiSecret) {
|
|
248
|
+
const store = getConfigStore();
|
|
249
|
+
const key = apiKey ?? store.apiKey;
|
|
250
|
+
const secret = apiSecret ?? store.apiSecret;
|
|
251
|
+
const result = await requestAccessToken(key, secret);
|
|
252
|
+
if (result.status === "success") {
|
|
253
|
+
store.setAccessToken(result.accessToken, result.expiresAtUtc);
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
async function ensureAccessToken() {
|
|
258
|
+
const store = getConfigStore();
|
|
259
|
+
const { accessToken, tokenExpiresAt, apiKey, apiSecret } = getAuthState();
|
|
260
|
+
if (accessToken && !isAccessTokenExpired(tokenExpiresAt)) {
|
|
261
|
+
return accessToken;
|
|
262
|
+
}
|
|
263
|
+
if (apiKey && apiSecret) {
|
|
264
|
+
const result = await fetchAccessToken(apiKey, apiSecret);
|
|
265
|
+
if (result.status === "success") return result.accessToken;
|
|
266
|
+
}
|
|
267
|
+
return accessToken;
|
|
268
|
+
}
|
|
269
|
+
function buildAuthHeaders(extra = {}) {
|
|
270
|
+
const headers = { ...extra };
|
|
271
|
+
const { consumer } = getConfigStore();
|
|
272
|
+
const { accessToken } = getAuthState();
|
|
273
|
+
if (!headers.Consumer && consumer) headers.Consumer = consumer;
|
|
274
|
+
if (!headers.Authorization && accessToken) {
|
|
275
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
276
|
+
}
|
|
277
|
+
return headers;
|
|
278
|
+
}
|
|
279
|
+
|
|
105
280
|
// src/config.js
|
|
106
281
|
function configure(env) {
|
|
107
282
|
const store = getConfigStore();
|
|
@@ -115,6 +290,33 @@ function getConfig() {
|
|
|
115
290
|
function setBaseUrl(baseUrl) {
|
|
116
291
|
getConfigStore().setBaseUrl(baseUrl);
|
|
117
292
|
}
|
|
293
|
+
function setConsumer(consumer) {
|
|
294
|
+
getConfigStore().setConsumer(consumer);
|
|
295
|
+
}
|
|
296
|
+
function setAccessToken(accessToken, expiresAtUtc) {
|
|
297
|
+
getConfigStore().setAccessToken(accessToken, expiresAtUtc);
|
|
298
|
+
}
|
|
299
|
+
function clearAccessToken() {
|
|
300
|
+
getConfigStore().clearAccessToken();
|
|
301
|
+
}
|
|
302
|
+
function setApiCredentials(apiKey, apiSecret) {
|
|
303
|
+
getConfigStore().setApiCredentials(apiKey, apiSecret);
|
|
304
|
+
}
|
|
305
|
+
function clearApiCredentials() {
|
|
306
|
+
getConfigStore().clearApiCredentials();
|
|
307
|
+
}
|
|
308
|
+
function clearAuth() {
|
|
309
|
+
getConfigStore().clearAuth();
|
|
310
|
+
}
|
|
311
|
+
function getAuth() {
|
|
312
|
+
return getAuthState();
|
|
313
|
+
}
|
|
314
|
+
function fetchAccessToken2(apiKey, apiSecret) {
|
|
315
|
+
return fetchAccessToken(apiKey, apiSecret);
|
|
316
|
+
}
|
|
317
|
+
function ensureValidAccessToken() {
|
|
318
|
+
return ensureAccessToken();
|
|
319
|
+
}
|
|
118
320
|
|
|
119
321
|
// src/apiRequest.js
|
|
120
322
|
function buildQuery(params) {
|
|
@@ -131,10 +333,18 @@ function buildQuery(params) {
|
|
|
131
333
|
return q ? `?${q}` : "";
|
|
132
334
|
}
|
|
133
335
|
async function request(baseUrl, fetchFn, path, options = {}) {
|
|
134
|
-
const { method = "GET", headers = {}, body, query, skipContentType } = options;
|
|
336
|
+
const { method = "GET", headers = {}, body, query, skipContentType, skipAuth } = options;
|
|
135
337
|
const url = `${String(baseUrl).replace(/\/+$/, "")}${path}${buildQuery(query)}`;
|
|
136
338
|
const reqHeaders = { ...headers };
|
|
137
339
|
if (!skipContentType && typeof body === "string") reqHeaders["Content-Type"] = "application/json";
|
|
340
|
+
if (!skipAuth) {
|
|
341
|
+
const store = getConfigStore();
|
|
342
|
+
if (!reqHeaders["Consumer"] && store.consumer) reqHeaders["Consumer"] = store.consumer;
|
|
343
|
+
const { accessToken } = getAuthState();
|
|
344
|
+
if (!reqHeaders["Authorization"] && accessToken) {
|
|
345
|
+
reqHeaders["Authorization"] = `Bearer ${accessToken}`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
138
348
|
const res = await fetchFn(url, { method, headers: reqHeaders, body });
|
|
139
349
|
const text = await res.text();
|
|
140
350
|
let data;
|
|
@@ -147,23 +357,35 @@ async function request(baseUrl, fetchFn, path, options = {}) {
|
|
|
147
357
|
data.status = "failure";
|
|
148
358
|
data.message = data.message ?? `HTTP ${res.status}`;
|
|
149
359
|
}
|
|
360
|
+
data._httpStatus = res.status;
|
|
150
361
|
return data;
|
|
151
362
|
}
|
|
152
|
-
function
|
|
363
|
+
function mergeRequestHeaders(env, opts) {
|
|
153
364
|
const headers = { ...opts.headers || {} };
|
|
154
|
-
|
|
365
|
+
const store = getConfigStore();
|
|
366
|
+
if (!headers["Consumer"] && ((env == null ? void 0 : env.consumer) || store.consumer)) {
|
|
367
|
+
headers["Consumer"] = (env == null ? void 0 : env.consumer) || store.consumer;
|
|
368
|
+
}
|
|
369
|
+
const { accessToken } = getAuthState();
|
|
370
|
+
if (!headers["Authorization"] && accessToken) {
|
|
371
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
372
|
+
}
|
|
155
373
|
return { ...opts, headers };
|
|
156
374
|
}
|
|
375
|
+
async function executeRequest(baseUrl, fetchFn, path, opts) {
|
|
376
|
+
if (!opts.skipAuth) await ensureAccessToken();
|
|
377
|
+
return request(baseUrl, fetchFn, path, mergeRequestHeaders(null, opts));
|
|
378
|
+
}
|
|
157
379
|
function createRequestHelpers(self, getEnv12) {
|
|
158
380
|
const env = () => getEnv12(self);
|
|
159
381
|
const baseUrl = () => env().baseUrl;
|
|
160
|
-
const fetchFn = () => env().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
382
|
+
const fetchFn = () => env().fetch ?? getConfigStore().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
161
383
|
throw new Error("fetch not available");
|
|
162
384
|
});
|
|
163
385
|
const req = (path, opts = {}) => {
|
|
164
386
|
const url = baseUrl();
|
|
165
387
|
if (!url) throw new Error("Model env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
166
|
-
return
|
|
388
|
+
return executeRequest(url, fetchFn(), path, opts);
|
|
167
389
|
};
|
|
168
390
|
return {
|
|
169
391
|
req,
|
|
@@ -174,14 +396,14 @@ function createRequestHelpers(self, getEnv12) {
|
|
|
174
396
|
function createRequestHelpersFromEnv(env) {
|
|
175
397
|
const e = env ?? getConfig();
|
|
176
398
|
if (!e) throw new Error("Env required. Pass env to the method or call configure({ baseUrl }) at app startup.");
|
|
177
|
-
const baseUrl = () => e == null ? void 0 : e.baseUrl;
|
|
178
|
-
const fetchFn = () => (e == null ? void 0 : e.fetch) ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
399
|
+
const baseUrl = () => (e == null ? void 0 : e.baseUrl) ?? getConfigStore().baseUrl;
|
|
400
|
+
const fetchFn = () => (e == null ? void 0 : e.fetch) ?? getConfigStore().fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
179
401
|
throw new Error("fetch not available");
|
|
180
402
|
});
|
|
181
403
|
const req = (path, opts = {}) => {
|
|
182
404
|
const url = baseUrl();
|
|
183
405
|
if (!url) throw new Error("Env requires baseUrl. Call configure({ baseUrl }) at app startup.");
|
|
184
|
-
return
|
|
406
|
+
return executeRequest(url, fetchFn(), path, opts);
|
|
185
407
|
};
|
|
186
408
|
return {
|
|
187
409
|
env: e,
|
|
@@ -228,6 +450,11 @@ var DayOfWeek = {
|
|
|
228
450
|
Friday: 5,
|
|
229
451
|
Saturday: 6
|
|
230
452
|
};
|
|
453
|
+
var EmailProvider = {
|
|
454
|
+
Google: 1,
|
|
455
|
+
Microsoft: 2,
|
|
456
|
+
Default: 3
|
|
457
|
+
};
|
|
231
458
|
var LocationType = {
|
|
232
459
|
Physical: 0,
|
|
233
460
|
Video: 1,
|
|
@@ -487,34 +714,34 @@ var EventModel = import_mobx_state_tree4.types.model("Event", {
|
|
|
487
714
|
});
|
|
488
715
|
function mapEventFromApi(d) {
|
|
489
716
|
if (!d) return d;
|
|
490
|
-
const
|
|
717
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
491
718
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
492
719
|
return {
|
|
493
|
-
eventId: String(
|
|
494
|
-
calendarId: String(
|
|
495
|
-
participantId:
|
|
496
|
-
title:
|
|
497
|
-
description:
|
|
498
|
-
startDate:
|
|
499
|
-
endDate:
|
|
500
|
-
startHour: n(
|
|
501
|
-
startMinute: n(
|
|
502
|
-
endHour: n(
|
|
503
|
-
endMinute: n(
|
|
504
|
-
visitorName:
|
|
505
|
-
visitorEmail:
|
|
506
|
-
visitorPhone:
|
|
507
|
-
externalEventId:
|
|
508
|
-
calendarLocationId:
|
|
509
|
-
customLocation:
|
|
510
|
-
flowId:
|
|
511
|
-
flowPath:
|
|
512
|
-
attendeeStatus: n(
|
|
513
|
-
rescheduleLink:
|
|
514
|
-
cancelLink:
|
|
515
|
-
timeZone:
|
|
516
|
-
createdOn:
|
|
517
|
-
modifiedOn:
|
|
720
|
+
eventId: String(pick2("eventId", "EventId", "event_id") ?? ""),
|
|
721
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
722
|
+
participantId: pick2("participantId", "ParticipantId", "participant_id") ?? null,
|
|
723
|
+
title: pick2("title", "Title"),
|
|
724
|
+
description: pick2("description", "Description"),
|
|
725
|
+
startDate: pick2("startDate", "StartDate", "start_date"),
|
|
726
|
+
endDate: pick2("endDate", "EndDate", "end_date"),
|
|
727
|
+
startHour: n(pick2("startHour", "StartHour", "start_hour")),
|
|
728
|
+
startMinute: n(pick2("startMinute", "StartMinute", "start_minute")),
|
|
729
|
+
endHour: n(pick2("endHour", "EndHour", "end_hour")),
|
|
730
|
+
endMinute: n(pick2("endMinute", "EndMinute", "end_minute")),
|
|
731
|
+
visitorName: pick2("visitorName", "VisitorName", "visitor_name"),
|
|
732
|
+
visitorEmail: pick2("visitorEmail", "VisitorEmail", "visitor_email"),
|
|
733
|
+
visitorPhone: pick2("visitorPhone", "VisitorPhone", "visitor_phone"),
|
|
734
|
+
externalEventId: pick2("externalEventId", "ExternalEventId", "external_event_id"),
|
|
735
|
+
calendarLocationId: pick2("calendarLocationId", "CalendarLocationId", "calendar_location_id"),
|
|
736
|
+
customLocation: pick2("customLocation", "CustomLocation", "custom_location"),
|
|
737
|
+
flowId: pick2("flowId", "FlowId", "flow_id"),
|
|
738
|
+
flowPath: pick2("flowPath", "FlowPath", "flow_path"),
|
|
739
|
+
attendeeStatus: n(pick2("attendeeStatus", "AttendeeStatus", "attendee_status")),
|
|
740
|
+
rescheduleLink: pick2("rescheduleLink", "RescheduleLink", "reschedule_link"),
|
|
741
|
+
cancelLink: pick2("cancelLink", "CancelLink", "cancel_link"),
|
|
742
|
+
timeZone: pick2("timeZone", "TimeZone", "time_zone"),
|
|
743
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on"),
|
|
744
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on")
|
|
518
745
|
};
|
|
519
746
|
}
|
|
520
747
|
EventModel.get = async (eventId) => {
|
|
@@ -768,14 +995,14 @@ var CalendarParticipantModel = import_mobx_state_tree6.types.model("CalendarPart
|
|
|
768
995
|
});
|
|
769
996
|
function mapFromApi(d) {
|
|
770
997
|
if (!d) return d;
|
|
771
|
-
const
|
|
998
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
772
999
|
return {
|
|
773
|
-
id:
|
|
774
|
-
calendarParticipantId: String(
|
|
775
|
-
participantId: String(
|
|
776
|
-
calendarId: String(
|
|
777
|
-
createdOn:
|
|
778
|
-
modifiedOn:
|
|
1000
|
+
id: pick2("id", "Id"),
|
|
1001
|
+
calendarParticipantId: String(pick2("calendarParticipantId", "CalendarParticipantId", "calendarparticipant_id") ?? ""),
|
|
1002
|
+
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1003
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1004
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1005
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
779
1006
|
};
|
|
780
1007
|
}
|
|
781
1008
|
CalendarParticipantModel.getByCalendar = async (calendarId) => {
|
|
@@ -1043,30 +1270,30 @@ var CalendarModel = import_mobx_state_tree8.types.model("Calendar", {
|
|
|
1043
1270
|
});
|
|
1044
1271
|
function mapCalendarFromApi(d) {
|
|
1045
1272
|
if (!d) return d;
|
|
1046
|
-
const
|
|
1273
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1047
1274
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1048
1275
|
return {
|
|
1049
|
-
id:
|
|
1050
|
-
companyKey:
|
|
1051
|
-
calendarId:
|
|
1052
|
-
name:
|
|
1053
|
-
timeZoneId:
|
|
1054
|
-
purpose:
|
|
1055
|
-
description:
|
|
1056
|
-
assignmentMethod: n(
|
|
1057
|
-
duration: n(
|
|
1058
|
-
durationUnit: n(
|
|
1059
|
-
minimumBookingNotice: n(
|
|
1060
|
-
minimumBookingNoticeUnit: n(
|
|
1061
|
-
minimumCancelationNotice: n(
|
|
1062
|
-
minimumCancelationNoticeUnit: n(
|
|
1063
|
-
futureLimit: n(
|
|
1064
|
-
futureLimitUnit: n(
|
|
1065
|
-
bufferTime: n(
|
|
1066
|
-
bufferTimeUnit: n(
|
|
1067
|
-
bookingLimit: n(
|
|
1068
|
-
createdOn:
|
|
1069
|
-
modifiedOn:
|
|
1276
|
+
id: pick2("id", "Id"),
|
|
1277
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key"),
|
|
1278
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? "",
|
|
1279
|
+
name: pick2("name", "Name"),
|
|
1280
|
+
timeZoneId: pick2("timeZoneId", "TimeZoneId", "time_zone_id"),
|
|
1281
|
+
purpose: pick2("purpose", "Purpose") ?? "",
|
|
1282
|
+
description: pick2("description", "Description"),
|
|
1283
|
+
assignmentMethod: n(pick2("assignmentMethod", "AssignmentMethod", "assignment_method")),
|
|
1284
|
+
duration: n(pick2("duration", "Duration")),
|
|
1285
|
+
durationUnit: n(pick2("durationUnit", "DurationUnit", "duration_unit")),
|
|
1286
|
+
minimumBookingNotice: n(pick2("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")),
|
|
1287
|
+
minimumBookingNoticeUnit: n(pick2("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")),
|
|
1288
|
+
minimumCancelationNotice: n(pick2("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")),
|
|
1289
|
+
minimumCancelationNoticeUnit: n(pick2("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")),
|
|
1290
|
+
futureLimit: n(pick2("futureLimit", "FutureLimit", "future_limit")),
|
|
1291
|
+
futureLimitUnit: n(pick2("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")),
|
|
1292
|
+
bufferTime: n(pick2("bufferTime", "BufferTime", "buffer_time")),
|
|
1293
|
+
bufferTimeUnit: n(pick2("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")),
|
|
1294
|
+
bookingLimit: n(pick2("bookingLimit", "BookingLimit", "booking_limit")),
|
|
1295
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on"),
|
|
1296
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on")
|
|
1070
1297
|
};
|
|
1071
1298
|
}
|
|
1072
1299
|
CalendarModel.getRaw = async (calendarId) => {
|
|
@@ -1291,6 +1518,15 @@ var ParticipantModel = import_mobx_state_tree11.types.model("Participant", {
|
|
|
1291
1518
|
if (res.status === "success" && res.data) (0, import_mobx_state_tree11.applySnapshot)(self, mapFromApi2(res.data));
|
|
1292
1519
|
return res;
|
|
1293
1520
|
},
|
|
1521
|
+
/** GET participant/getbyemail – fetch by companyKey + email on this snapshot */
|
|
1522
|
+
async getByEmail() {
|
|
1523
|
+
const res = await reqGet("/participant/getbyemail", {
|
|
1524
|
+
email: self.email,
|
|
1525
|
+
company_key: self.companyKey
|
|
1526
|
+
});
|
|
1527
|
+
if (res.status === "success" && res.data) (0, import_mobx_state_tree11.applySnapshot)(self, mapFromApi2(res.data));
|
|
1528
|
+
return res;
|
|
1529
|
+
},
|
|
1294
1530
|
/** POST participant/save – save participant (add or update) */
|
|
1295
1531
|
async save() {
|
|
1296
1532
|
const payload = toPayload(self);
|
|
@@ -1352,19 +1588,19 @@ var ParticipantModel = import_mobx_state_tree11.types.model("Participant", {
|
|
|
1352
1588
|
});
|
|
1353
1589
|
function mapFromApi2(d) {
|
|
1354
1590
|
if (!d) return d;
|
|
1355
|
-
const
|
|
1591
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1356
1592
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1357
1593
|
return {
|
|
1358
|
-
participantId: String(
|
|
1359
|
-
companyKey:
|
|
1360
|
-
alias:
|
|
1361
|
-
email:
|
|
1362
|
-
isApproved: Boolean(
|
|
1363
|
-
isAvailable: Boolean(
|
|
1364
|
-
provider: n(
|
|
1365
|
-
createdOn:
|
|
1366
|
-
modifiedOn:
|
|
1367
|
-
isDeleted: Boolean(
|
|
1594
|
+
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1595
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1596
|
+
alias: pick2("alias", "Alias") ?? "",
|
|
1597
|
+
email: pick2("email", "Email") ?? "",
|
|
1598
|
+
isApproved: Boolean(pick2("isApproved", "IsApproved", "is_approved")),
|
|
1599
|
+
isAvailable: Boolean(pick2("isAvailable", "IsAvailable", "is_available")),
|
|
1600
|
+
provider: n(pick2("provider", "Provider")) ?? 0,
|
|
1601
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1602
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
1603
|
+
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
1368
1604
|
};
|
|
1369
1605
|
}
|
|
1370
1606
|
function toPayload(self) {
|
|
@@ -1380,32 +1616,40 @@ function toPayload(self) {
|
|
|
1380
1616
|
}
|
|
1381
1617
|
function mapCalendarFromApi2(d) {
|
|
1382
1618
|
if (!d) return d;
|
|
1383
|
-
const
|
|
1619
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1384
1620
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1385
1621
|
return {
|
|
1386
|
-
id:
|
|
1387
|
-
companyKey:
|
|
1388
|
-
calendarId: String(
|
|
1389
|
-
name:
|
|
1390
|
-
timeZoneId:
|
|
1391
|
-
purpose:
|
|
1392
|
-
description:
|
|
1393
|
-
assignmentMethod: n(
|
|
1394
|
-
duration: n(
|
|
1395
|
-
durationUnit: n(
|
|
1396
|
-
minimumBookingNotice: n(
|
|
1397
|
-
minimumBookingNoticeUnit: n(
|
|
1398
|
-
minimumCancelationNotice: n(
|
|
1399
|
-
minimumCancelationNoticeUnit: n(
|
|
1400
|
-
futureLimit: n(
|
|
1401
|
-
futureLimitUnit: n(
|
|
1402
|
-
bufferTime: n(
|
|
1403
|
-
bufferTimeUnit: n(
|
|
1404
|
-
bookingLimit: n(
|
|
1405
|
-
createdOn:
|
|
1406
|
-
modifiedOn:
|
|
1622
|
+
id: pick2("id", "Id"),
|
|
1623
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1624
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1625
|
+
name: pick2("name", "Name") ?? null,
|
|
1626
|
+
timeZoneId: pick2("timeZoneId", "TimeZoneId", "time_zone_id") ?? null,
|
|
1627
|
+
purpose: pick2("purpose", "Purpose") ?? "",
|
|
1628
|
+
description: pick2("description", "Description") ?? null,
|
|
1629
|
+
assignmentMethod: n(pick2("assignmentMethod", "AssignmentMethod", "assignment_method")) ?? void 0,
|
|
1630
|
+
duration: n(pick2("duration", "Duration")) ?? void 0,
|
|
1631
|
+
durationUnit: n(pick2("durationUnit", "DurationUnit", "duration_unit")) ?? void 0,
|
|
1632
|
+
minimumBookingNotice: n(pick2("minimumBookingNotice", "MinimumBookingNotice", "minimum_booking_notice")) ?? void 0,
|
|
1633
|
+
minimumBookingNoticeUnit: n(pick2("minimumBookingNoticeUnit", "MinimumBookingNoticeUnit", "minimum_booking_notice_unit")) ?? void 0,
|
|
1634
|
+
minimumCancelationNotice: n(pick2("minimumCancelationNotice", "MinimumCancelationNotice", "minimum_cancelation_notice")) ?? void 0,
|
|
1635
|
+
minimumCancelationNoticeUnit: n(pick2("minimumCancelationNoticeUnit", "MinimumCancelationNoticeUnit", "minimum_cancelation_notice_unit")) ?? void 0,
|
|
1636
|
+
futureLimit: n(pick2("futureLimit", "FutureLimit", "future_limit")) ?? void 0,
|
|
1637
|
+
futureLimitUnit: n(pick2("futureLimitUnit", "FutureLimitUnit", "future_limit_unit")) ?? void 0,
|
|
1638
|
+
bufferTime: n(pick2("bufferTime", "BufferTime", "buffer_time")) ?? void 0,
|
|
1639
|
+
bufferTimeUnit: n(pick2("bufferTimeUnit", "BufferTimeUnit", "buffer_time_unit")) ?? void 0,
|
|
1640
|
+
bookingLimit: n(pick2("bookingLimit", "BookingLimit", "booking_limit")) ?? void 0,
|
|
1641
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1642
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1407
1643
|
};
|
|
1408
1644
|
}
|
|
1645
|
+
ParticipantModel.getByEmail = async (email, companyKey) => {
|
|
1646
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1647
|
+
const res = await reqGet("/participant/getbyemail", { email, company_key: companyKey });
|
|
1648
|
+
if (res.status === "success" && res.data) {
|
|
1649
|
+
return ParticipantModel.create(mapFromApi2(res.data), { env: getConfig() });
|
|
1650
|
+
}
|
|
1651
|
+
return null;
|
|
1652
|
+
};
|
|
1409
1653
|
ParticipantModel.get = async (participantId) => {
|
|
1410
1654
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
1411
1655
|
const res = await reqGet("/participant/get", { participant_id: participantId });
|
|
@@ -1549,14 +1793,14 @@ var SettingModel = import_mobx_state_tree13.types.model("Setting", {
|
|
|
1549
1793
|
});
|
|
1550
1794
|
function mapFromApi3(d) {
|
|
1551
1795
|
if (!d) return d;
|
|
1552
|
-
const
|
|
1796
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1553
1797
|
return {
|
|
1554
|
-
settingsId: String(
|
|
1555
|
-
calendarId: String(
|
|
1556
|
-
logo:
|
|
1557
|
-
theme:
|
|
1558
|
-
schedulingButtonText:
|
|
1559
|
-
scheduledMessage:
|
|
1798
|
+
settingsId: String(pick2("settingsId", "SettingsId", "settings_id") ?? ""),
|
|
1799
|
+
calendarId: String(pick2("calendarId", "CalendarId", "calendar_id") ?? ""),
|
|
1800
|
+
logo: pick2("logo", "Logo") ?? null,
|
|
1801
|
+
theme: pick2("theme", "Theme") ?? null,
|
|
1802
|
+
schedulingButtonText: pick2("schedulingButtonText", "SchedulingButtonText", "scheduling_button_text") ?? null,
|
|
1803
|
+
scheduledMessage: pick2("scheduledMessage", "ScheduledMessage", "scheduled_message") ?? null
|
|
1560
1804
|
};
|
|
1561
1805
|
}
|
|
1562
1806
|
function toPayload2(self) {
|
|
@@ -1584,6 +1828,7 @@ SettingModel.save = async (payload) => {
|
|
|
1584
1828
|
SettingModel.uploadLogo = async (calendarId, file) => {
|
|
1585
1829
|
const cfg = getConfig();
|
|
1586
1830
|
if (!(cfg == null ? void 0 : cfg.baseUrl)) throw new Error("Configure baseUrl before uploadLogo");
|
|
1831
|
+
await ensureAccessToken();
|
|
1587
1832
|
const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
1588
1833
|
throw new Error("fetch not available");
|
|
1589
1834
|
});
|
|
@@ -1593,6 +1838,7 @@ SettingModel.uploadLogo = async (calendarId, file) => {
|
|
|
1593
1838
|
formData.append("file", file);
|
|
1594
1839
|
const res = await fetchFn(url, {
|
|
1595
1840
|
method: "POST",
|
|
1841
|
+
headers: buildAuthHeaders(),
|
|
1596
1842
|
body: formData
|
|
1597
1843
|
});
|
|
1598
1844
|
const text = await res.text();
|
|
@@ -1638,12 +1884,12 @@ var CompanyModel = import_mobx_state_tree14.types.model("Company", {
|
|
|
1638
1884
|
});
|
|
1639
1885
|
function mapFromApi4(d) {
|
|
1640
1886
|
if (!d) return d;
|
|
1641
|
-
const
|
|
1887
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1642
1888
|
return {
|
|
1643
|
-
companyKey: String(
|
|
1644
|
-
companyName:
|
|
1645
|
-
createdOn:
|
|
1646
|
-
modifiedOn:
|
|
1889
|
+
companyKey: String(pick2("companyKey", "CompanyKey", "company_key") ?? ""),
|
|
1890
|
+
companyName: pick2("companyName", "CompanyName", "company_name") ?? "",
|
|
1891
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1892
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1647
1893
|
};
|
|
1648
1894
|
}
|
|
1649
1895
|
function toPayload3(self) {
|
|
@@ -1715,6 +1961,7 @@ AssetModel.upload = async (file, opts = {}) => {
|
|
|
1715
1961
|
if (!file) return { status: "failure", message: "file is required" };
|
|
1716
1962
|
const category = opts.category != null ? String(opts.category).trim() : "";
|
|
1717
1963
|
if (!category) return { status: "failure", message: "category is required" };
|
|
1964
|
+
await ensureAccessToken();
|
|
1718
1965
|
const fetchFn = cfg.fetch ?? (typeof fetch !== "undefined" ? fetch : () => {
|
|
1719
1966
|
throw new Error("fetch not available");
|
|
1720
1967
|
});
|
|
@@ -1729,8 +1976,7 @@ AssetModel.upload = async (file, opts = {}) => {
|
|
|
1729
1976
|
if (opts.calendarId != null && String(opts.calendarId).trim() !== "") {
|
|
1730
1977
|
formData.append("calendar_id", String(opts.calendarId).trim());
|
|
1731
1978
|
}
|
|
1732
|
-
const headers =
|
|
1733
|
-
if (cfg.consumer) headers.Consumer = cfg.consumer;
|
|
1979
|
+
const headers = buildAuthHeaders();
|
|
1734
1980
|
if (opts.consumer != null && String(opts.consumer).trim() !== "") {
|
|
1735
1981
|
headers.Consumer = String(opts.consumer).trim();
|
|
1736
1982
|
}
|
|
@@ -1762,20 +2008,20 @@ var Asset_default = AssetModel;
|
|
|
1762
2008
|
var import_mobx_state_tree16 = require("mobx-state-tree");
|
|
1763
2009
|
function mapCalendarLocationFromApi(d) {
|
|
1764
2010
|
if (!d) return d;
|
|
1765
|
-
const
|
|
2011
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1766
2012
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1767
2013
|
const b = (v) => v === true || v === "true" || v === 1 || v === "1";
|
|
1768
2014
|
return {
|
|
1769
|
-
id: n(
|
|
1770
|
-
calendarLocationId:
|
|
1771
|
-
calendarId:
|
|
1772
|
-
locationType: n(
|
|
1773
|
-
name:
|
|
1774
|
-
value:
|
|
1775
|
-
isDefault: b(
|
|
1776
|
-
sortOrder: n(
|
|
1777
|
-
createdOn:
|
|
1778
|
-
modifiedOn:
|
|
2015
|
+
id: n(pick2("id", "Id")),
|
|
2016
|
+
calendarLocationId: pick2("calendarLocationId", "CalendarLocationId", "calendar_location_id") ?? null,
|
|
2017
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
2018
|
+
locationType: n(pick2("locationType", "LocationType", "location_type")),
|
|
2019
|
+
name: pick2("name", "Name") ?? "",
|
|
2020
|
+
value: pick2("value", "Value") ?? "",
|
|
2021
|
+
isDefault: b(pick2("isDefault", "IsDefault", "is_default")),
|
|
2022
|
+
sortOrder: n(pick2("sortOrder", "SortOrder", "sort_order")) ?? 0,
|
|
2023
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2024
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1779
2025
|
};
|
|
1780
2026
|
}
|
|
1781
2027
|
function toPayload4(self) {
|
|
@@ -1933,20 +2179,20 @@ var Preference_default = PreferenceModel;
|
|
|
1933
2179
|
var import_mobx_state_tree18 = require("mobx-state-tree");
|
|
1934
2180
|
function mapFlowFromApi(d) {
|
|
1935
2181
|
if (!d) return d;
|
|
1936
|
-
const
|
|
2182
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1937
2183
|
const b = (v) => v === true || v === "true" || v === 1;
|
|
1938
2184
|
return {
|
|
1939
|
-
id:
|
|
1940
|
-
flowId:
|
|
1941
|
-
companyKey:
|
|
1942
|
-
calendarId:
|
|
1943
|
-
name:
|
|
1944
|
-
description:
|
|
1945
|
-
flowJson:
|
|
1946
|
-
isActive: b(
|
|
1947
|
-
isDeleted: b(
|
|
1948
|
-
createdOn:
|
|
1949
|
-
modifiedOn:
|
|
2185
|
+
id: pick2("id", "Id") ?? null,
|
|
2186
|
+
flowId: pick2("flowId", "FlowId", "flow_id") ?? "",
|
|
2187
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? "",
|
|
2188
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
2189
|
+
name: pick2("name", "Name") ?? "",
|
|
2190
|
+
description: pick2("description", "Description") ?? null,
|
|
2191
|
+
flowJson: pick2("flowJson", "FlowJson", "flow_json") ?? "",
|
|
2192
|
+
isActive: b(pick2("isActive", "IsActive", "is_active")) ?? true,
|
|
2193
|
+
isDeleted: b(pick2("isDeleted", "IsDeleted", "is_deleted")) ?? false,
|
|
2194
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2195
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1950
2196
|
};
|
|
1951
2197
|
}
|
|
1952
2198
|
var FlowModel = import_mobx_state_tree18.types.model("Flow", {
|
|
@@ -2196,8 +2442,8 @@ var Flow_default = FlowModel;
|
|
|
2196
2442
|
var import_mobx_state_tree19 = require("mobx-state-tree");
|
|
2197
2443
|
function mapLeadFromApi(d) {
|
|
2198
2444
|
if (!d) return d;
|
|
2199
|
-
const
|
|
2200
|
-
const leadTypeRaw =
|
|
2445
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2446
|
+
const leadTypeRaw = pick2("leadType", "LeadType", "lead_type");
|
|
2201
2447
|
let leadType = 2;
|
|
2202
2448
|
if (typeof leadTypeRaw === "number" && Number.isFinite(leadTypeRaw)) {
|
|
2203
2449
|
leadType = leadTypeRaw;
|
|
@@ -2209,17 +2455,17 @@ function mapLeadFromApi(d) {
|
|
|
2209
2455
|
else if (!Number.isNaN(Number(leadTypeRaw))) leadType = Number(leadTypeRaw);
|
|
2210
2456
|
}
|
|
2211
2457
|
return {
|
|
2212
|
-
id:
|
|
2213
|
-
leadId:
|
|
2214
|
-
email:
|
|
2215
|
-
name:
|
|
2216
|
-
phone:
|
|
2217
|
-
companyKey:
|
|
2218
|
-
source:
|
|
2458
|
+
id: pick2("id", "Id") ?? null,
|
|
2459
|
+
leadId: pick2("leadId", "LeadId", "lead_id") ?? "",
|
|
2460
|
+
email: pick2("email", "Email") ?? "",
|
|
2461
|
+
name: pick2("name", "Name") ?? "",
|
|
2462
|
+
phone: pick2("phone", "Phone") ?? "",
|
|
2463
|
+
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? "",
|
|
2464
|
+
source: pick2("source", "Source") ?? "",
|
|
2219
2465
|
leadType,
|
|
2220
|
-
referrerLink:
|
|
2221
|
-
createdOn:
|
|
2222
|
-
modifiedOn:
|
|
2466
|
+
referrerLink: pick2("referrerLink", "ReferrerLink", "referrer_link") ?? "",
|
|
2467
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2468
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
2223
2469
|
};
|
|
2224
2470
|
}
|
|
2225
2471
|
var LeadModel = import_mobx_state_tree19.types.model("Lead", {
|
|
@@ -2506,17 +2752,17 @@ var CustomFieldModel = import_mobx_state_tree20.types.model("CustomField", {
|
|
|
2506
2752
|
});
|
|
2507
2753
|
function mapCustomFieldFromApi(d) {
|
|
2508
2754
|
if (!d) return d;
|
|
2509
|
-
const
|
|
2755
|
+
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2510
2756
|
return {
|
|
2511
|
-
id:
|
|
2512
|
-
customFieldId:
|
|
2513
|
-
calendarId:
|
|
2514
|
-
label:
|
|
2515
|
-
type:
|
|
2516
|
-
isRequired: Boolean(
|
|
2517
|
-
createdOn:
|
|
2518
|
-
modifiedOn:
|
|
2519
|
-
isDeleted: Boolean(
|
|
2757
|
+
id: pick2("id", "Id") ?? null,
|
|
2758
|
+
customFieldId: pick2("customFieldId", "CustomFieldId", "custom_field_id") ?? null,
|
|
2759
|
+
calendarId: pick2("calendarId", "CalendarId", "calendar_id") ?? null,
|
|
2760
|
+
label: pick2("label", "Label") ?? null,
|
|
2761
|
+
type: pick2("type", "Type") ?? "",
|
|
2762
|
+
isRequired: Boolean(pick2("isRequired", "IsRequired", "is_required")),
|
|
2763
|
+
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
2764
|
+
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
2765
|
+
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
2520
2766
|
};
|
|
2521
2767
|
}
|
|
2522
2768
|
function toPayload5(self) {
|
|
@@ -2590,6 +2836,150 @@ CustomFieldModel.saveFormFieldData = async (fieldPayload) => {
|
|
|
2590
2836
|
};
|
|
2591
2837
|
var CustomField_default = CustomFieldModel;
|
|
2592
2838
|
|
|
2839
|
+
// src/models/appointment/Auth.js
|
|
2840
|
+
var CALENDAR_AUTH_MESSAGE_TYPE = "calendar-authorization";
|
|
2841
|
+
var EmailProvider2 = {
|
|
2842
|
+
Google: 1,
|
|
2843
|
+
Microsoft: 2,
|
|
2844
|
+
Default: 3
|
|
2845
|
+
};
|
|
2846
|
+
function pick(d, ...keys) {
|
|
2847
|
+
return keys.reduce((v, k) => v ?? d[k], void 0);
|
|
2848
|
+
}
|
|
2849
|
+
function mapCalendarProviderFromApi(d) {
|
|
2850
|
+
if (!d) return d;
|
|
2851
|
+
return {
|
|
2852
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2853
|
+
key: pick(d, "key", "Key") ?? "",
|
|
2854
|
+
name: pick(d, "name", "Name") ?? "",
|
|
2855
|
+
displayName: pick(d, "displayName", "DisplayName", "display_name") ?? "",
|
|
2856
|
+
description: pick(d, "description", "Description") ?? "",
|
|
2857
|
+
scope: pick(d, "scope", "Scope") ?? "",
|
|
2858
|
+
redirectUrl: pick(d, "redirectUrl", "RedirectUrl", "redirect_url") ?? ""
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
function mapAuthorizationUrlFromApi(d) {
|
|
2862
|
+
if (!d) return d;
|
|
2863
|
+
return {
|
|
2864
|
+
participantId: String(pick(d, "participantId", "ParticipantId", "participant_id") ?? ""),
|
|
2865
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2866
|
+
providerKey: pick(d, "providerKey", "ProviderKey", "provider_key") ?? "",
|
|
2867
|
+
authorizationUrl: pick(d, "authorizationUrl", "AuthorizationUrl", "authorization_url") ?? "",
|
|
2868
|
+
redirectUrl: pick(d, "redirectUrl", "RedirectUrl", "redirect_url") ?? ""
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
function mapProviderStateFromApi(d) {
|
|
2872
|
+
if (!d) return d;
|
|
2873
|
+
return {
|
|
2874
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2875
|
+
key: pick(d, "key", "Key") ?? "",
|
|
2876
|
+
name: pick(d, "name", "Name") ?? "",
|
|
2877
|
+
hasCredentials: Boolean(pick(d, "hasCredentials", "HasCredentials", "has_credentials")),
|
|
2878
|
+
isAuthorized: Boolean(pick(d, "isAuthorized", "IsAuthorized", "is_authorized")),
|
|
2879
|
+
isSelected: Boolean(pick(d, "isSelected", "IsSelected", "is_selected"))
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
function mapAuthorizationStatusFromApi(d) {
|
|
2883
|
+
if (!d) return d;
|
|
2884
|
+
const providersRaw = pick(d, "providers", "Providers");
|
|
2885
|
+
return {
|
|
2886
|
+
participantId: String(pick(d, "participantId", "ParticipantId", "participant_id") ?? ""),
|
|
2887
|
+
email: pick(d, "email", "Email") ?? "",
|
|
2888
|
+
emailProvider: pick(d, "emailProvider", "EmailProvider", "email_provider") ?? 0,
|
|
2889
|
+
providerKey: pick(d, "providerKey", "ProviderKey", "provider_key") ?? "",
|
|
2890
|
+
hasCredentials: Boolean(pick(d, "hasCredentials", "HasCredentials", "has_credentials")),
|
|
2891
|
+
isAuthorized: Boolean(pick(d, "isAuthorized", "IsAuthorized", "is_authorized")),
|
|
2892
|
+
providers: Array.isArray(providersRaw) ? providersRaw.map(mapProviderStateFromApi) : []
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
var AuthModel = {
|
|
2896
|
+
CALENDAR_AUTH_MESSAGE_TYPE,
|
|
2897
|
+
EmailProvider: EmailProvider2,
|
|
2898
|
+
/**
|
|
2899
|
+
* GET Auth/CalendarProviders — supported providers (Google / Outlook) for the Scheduling modal.
|
|
2900
|
+
* @param {{ host?: string }} [opts]
|
|
2901
|
+
* @returns {Promise<{ status: string, data?: object[], message?: string }>}
|
|
2902
|
+
*/
|
|
2903
|
+
async getCalendarProviders(opts = {}) {
|
|
2904
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2905
|
+
const q = {};
|
|
2906
|
+
if (opts.host) q.host = opts.host;
|
|
2907
|
+
const res = await reqGet("/Auth/CalendarProviders", q);
|
|
2908
|
+
if (res.status === "success" && Array.isArray(res.data)) {
|
|
2909
|
+
res.data = res.data.map(mapCalendarProviderFromApi);
|
|
2910
|
+
}
|
|
2911
|
+
return res;
|
|
2912
|
+
},
|
|
2913
|
+
/**
|
|
2914
|
+
* GET Auth/AuthorizationUrl — OAuth URL to open in a popup when user picks a provider.
|
|
2915
|
+
* @param {string} participantId
|
|
2916
|
+
* @param {string|number} emailProvider — google, gmail, 1, outlook, microsoft, 2
|
|
2917
|
+
* @param {{ host?: string }} [opts]
|
|
2918
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2919
|
+
*/
|
|
2920
|
+
async getAuthorizationUrl(participantId, emailProvider, opts = {}) {
|
|
2921
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2922
|
+
const q = {
|
|
2923
|
+
participant_id: participantId,
|
|
2924
|
+
email_provider: String(emailProvider)
|
|
2925
|
+
};
|
|
2926
|
+
if (opts.host) q.host = opts.host;
|
|
2927
|
+
const res = await reqGet("/Auth/AuthorizationUrl", q);
|
|
2928
|
+
if (res.status === "success" && res.data) {
|
|
2929
|
+
res.data = mapAuthorizationUrlFromApi(res.data);
|
|
2930
|
+
}
|
|
2931
|
+
return res;
|
|
2932
|
+
},
|
|
2933
|
+
/**
|
|
2934
|
+
* GET Auth/Status — whether participant calendar is connected (call after OAuth popup).
|
|
2935
|
+
* @param {string} participantId
|
|
2936
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2937
|
+
*/
|
|
2938
|
+
async getAuthorizationStatus(participantId) {
|
|
2939
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2940
|
+
const res = await reqGet("/Auth/Status", { participant_id: participantId });
|
|
2941
|
+
if (res.status === "success" && res.data) {
|
|
2942
|
+
res.data = mapAuthorizationStatusFromApi(res.data);
|
|
2943
|
+
}
|
|
2944
|
+
return res;
|
|
2945
|
+
},
|
|
2946
|
+
/**
|
|
2947
|
+
* Open Google/Microsoft OAuth in a centered popup.
|
|
2948
|
+
* @param {string} authorizationUrl — from getAuthorizationUrl().data.authorizationUrl
|
|
2949
|
+
* @param {{ width?: number, height?: number }} [opts]
|
|
2950
|
+
* @returns {Window | null}
|
|
2951
|
+
*/
|
|
2952
|
+
openOAuthPopup(authorizationUrl, opts = {}) {
|
|
2953
|
+
if (typeof window === "undefined" || !authorizationUrl) return null;
|
|
2954
|
+
const width = opts.width ?? 500;
|
|
2955
|
+
const height = opts.height ?? 650;
|
|
2956
|
+
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
2957
|
+
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
2958
|
+
return window.open(
|
|
2959
|
+
authorizationUrl,
|
|
2960
|
+
"calendar-oauth",
|
|
2961
|
+
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes`
|
|
2962
|
+
);
|
|
2963
|
+
},
|
|
2964
|
+
/**
|
|
2965
|
+
* Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
|
|
2966
|
+
* @param {(payload: { type: string, status: 'success' | 'error', message?: string }) => void} handler
|
|
2967
|
+
* @returns {() => void} unsubscribe
|
|
2968
|
+
*/
|
|
2969
|
+
onCalendarAuthMessage(handler) {
|
|
2970
|
+
if (typeof window === "undefined") return () => {
|
|
2971
|
+
};
|
|
2972
|
+
const listener = (event) => {
|
|
2973
|
+
const payload = event == null ? void 0 : event.data;
|
|
2974
|
+
if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
|
|
2975
|
+
handler(payload);
|
|
2976
|
+
};
|
|
2977
|
+
window.addEventListener("message", listener);
|
|
2978
|
+
return () => window.removeEventListener("message", listener);
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
var Auth_default = AuthModel;
|
|
2982
|
+
|
|
2593
2983
|
// src/models/appointment/index.js
|
|
2594
2984
|
var import_mobx_state_tree21 = require("mobx-state-tree");
|
|
2595
2985
|
var RootStore = import_mobx_state_tree21.types.model("RootStore", {
|
|
@@ -2617,9 +3007,12 @@ function createRootStore(initialState = {}) {
|
|
|
2617
3007
|
AssetModel,
|
|
2618
3008
|
AssignmentMethod,
|
|
2619
3009
|
AttendeeStatus,
|
|
3010
|
+
AuthModel,
|
|
2620
3011
|
AvailabilityDetailModel,
|
|
2621
3012
|
AvailabilityModel,
|
|
3013
|
+
CALENDAR_AUTH_MESSAGE_TYPE,
|
|
2622
3014
|
CalendarDayModel,
|
|
3015
|
+
CalendarEmailProvider,
|
|
2623
3016
|
CalendarLocationModel,
|
|
2624
3017
|
CalendarModel,
|
|
2625
3018
|
CalendarParticipantModel,
|
|
@@ -2627,6 +3020,7 @@ function createRootStore(initialState = {}) {
|
|
|
2627
3020
|
ConfigModel,
|
|
2628
3021
|
CustomFieldModel,
|
|
2629
3022
|
DayOfWeek,
|
|
3023
|
+
EmailProvider,
|
|
2630
3024
|
EventModel,
|
|
2631
3025
|
FlowModel,
|
|
2632
3026
|
LeadModel,
|
|
@@ -2639,12 +3033,25 @@ function createRootStore(initialState = {}) {
|
|
|
2639
3033
|
RecurringFrequency,
|
|
2640
3034
|
RootStore,
|
|
2641
3035
|
SettingModel,
|
|
3036
|
+
TOKEN_PATH,
|
|
2642
3037
|
TimeFrameModel,
|
|
2643
3038
|
TimeSlotModel,
|
|
2644
3039
|
Unit,
|
|
3040
|
+
buildAuthHeaders,
|
|
3041
|
+
clearAccessToken,
|
|
3042
|
+
clearApiCredentials,
|
|
3043
|
+
clearAuth,
|
|
2645
3044
|
configure,
|
|
2646
3045
|
createRootStore,
|
|
3046
|
+
ensureValidAccessToken,
|
|
3047
|
+
fetchAccessToken,
|
|
3048
|
+
getAuth,
|
|
2647
3049
|
getConfig,
|
|
2648
3050
|
getConfigStore,
|
|
2649
|
-
|
|
3051
|
+
isAccessTokenExpired,
|
|
3052
|
+
requestAccessToken,
|
|
3053
|
+
setAccessToken,
|
|
3054
|
+
setApiCredentials,
|
|
3055
|
+
setBaseUrl,
|
|
3056
|
+
setConsumer
|
|
2650
3057
|
});
|