@blazeo.com/calendar-client 1.0.28 → 1.0.30
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/dist/index.d.ts +23 -1
- package/dist/index.js +57 -4
- package/dist/index.mjs +57 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -230,6 +230,7 @@ export const LeadModel: {
|
|
|
230
230
|
getRaw(leadId: string): Promise<{ status: string; data?: unknown; message?: string }>;
|
|
231
231
|
get(leadId: string): Promise<unknown>;
|
|
232
232
|
getByEmail(email: string, companyKey: string): Promise<unknown>;
|
|
233
|
+
getByPhone(phone: string, companyKey: string): Promise<unknown>;
|
|
233
234
|
createLead(payload: {
|
|
234
235
|
email: string;
|
|
235
236
|
companyKey: string;
|
|
@@ -318,6 +319,20 @@ export type ParticipantAuthorizationStatus = {
|
|
|
318
319
|
providers: CalendarProviderAuthorizationState[];
|
|
319
320
|
};
|
|
320
321
|
|
|
322
|
+
export type ParticipantData = {
|
|
323
|
+
id?: number | null;
|
|
324
|
+
participantId: string;
|
|
325
|
+
companyKey?: string | null;
|
|
326
|
+
alias?: string;
|
|
327
|
+
email?: string;
|
|
328
|
+
isApproved: boolean;
|
|
329
|
+
isAvailable: boolean;
|
|
330
|
+
provider: number;
|
|
331
|
+
createdOn?: string | null;
|
|
332
|
+
modifiedOn?: string | null;
|
|
333
|
+
isDeleted?: boolean;
|
|
334
|
+
};
|
|
335
|
+
|
|
321
336
|
export const CALENDAR_AUTH_MESSAGE_TYPE: 'calendar-authorization';
|
|
322
337
|
|
|
323
338
|
export const CalendarEmailProvider: {
|
|
@@ -348,6 +363,11 @@ export const AuthModel: {
|
|
|
348
363
|
data?: ParticipantAuthorizationStatus;
|
|
349
364
|
message?: string;
|
|
350
365
|
}>;
|
|
366
|
+
IsAuthorized(participantId: string): Promise<{
|
|
367
|
+
status: string;
|
|
368
|
+
data?: ParticipantData;
|
|
369
|
+
message?: string;
|
|
370
|
+
}>;
|
|
351
371
|
openOAuthPopup(
|
|
352
372
|
authorizationUrl: string,
|
|
353
373
|
opts?: { width?: number; height?: number }
|
|
@@ -357,7 +377,9 @@ export const AuthModel: {
|
|
|
357
377
|
type: string;
|
|
358
378
|
status: 'success' | 'error';
|
|
359
379
|
message?: string;
|
|
360
|
-
|
|
380
|
+
closePopup?: boolean;
|
|
381
|
+
}) => void,
|
|
382
|
+
popup?: Window | null
|
|
361
383
|
): () => void;
|
|
362
384
|
};
|
|
363
385
|
|
package/dist/index.js
CHANGED
|
@@ -1489,23 +1489,27 @@ var ParticipantModel = import_mobx_state_tree11.types.model("Participant", {
|
|
|
1489
1489
|
}
|
|
1490
1490
|
};
|
|
1491
1491
|
});
|
|
1492
|
-
function
|
|
1492
|
+
function mapParticipantFromApi(d) {
|
|
1493
1493
|
if (!d) return d;
|
|
1494
1494
|
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1495
1495
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1496
1496
|
return {
|
|
1497
|
+
id: n(pick2("id", "Id")) ?? null,
|
|
1497
1498
|
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1498
1499
|
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1499
1500
|
alias: pick2("alias", "Alias") ?? "",
|
|
1500
1501
|
email: pick2("email", "Email") ?? "",
|
|
1501
1502
|
isApproved: Boolean(pick2("isApproved", "IsApproved", "is_approved")),
|
|
1502
1503
|
isAvailable: Boolean(pick2("isAvailable", "IsAvailable", "is_available")),
|
|
1503
|
-
provider: n(pick2("provider", "Provider")) ?? 0,
|
|
1504
|
+
provider: n(pick2("provider", "Provider", "emailProvider", "EmailProvider", "email_provider")) ?? 0,
|
|
1504
1505
|
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1505
1506
|
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
1506
1507
|
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
1507
1508
|
};
|
|
1508
1509
|
}
|
|
1510
|
+
function mapFromApi2(d) {
|
|
1511
|
+
return mapParticipantFromApi(d);
|
|
1512
|
+
}
|
|
1509
1513
|
function toPayload(self) {
|
|
1510
1514
|
return {
|
|
1511
1515
|
participantId: self.participantId,
|
|
@@ -2406,6 +2410,17 @@ var LeadModel = import_mobx_state_tree19.types.model("Lead", {
|
|
|
2406
2410
|
}
|
|
2407
2411
|
return { status: lead ? "success" : "failure", data: lead ?? void 0 };
|
|
2408
2412
|
},
|
|
2413
|
+
/** GET /lead/getbyphone – uses self.phone and self.companyKey */
|
|
2414
|
+
async getByPhone() {
|
|
2415
|
+
if (!self.phone || !self.companyKey) {
|
|
2416
|
+
return { status: "failure", message: "phone and companyKey required on model" };
|
|
2417
|
+
}
|
|
2418
|
+
const lead = await LeadModel.getByPhone(self.phone, self.companyKey);
|
|
2419
|
+
if (lead) {
|
|
2420
|
+
(0, import_mobx_state_tree19.applySnapshot)(self, (0, import_mobx_state_tree19.getSnapshot)(lead));
|
|
2421
|
+
}
|
|
2422
|
+
return { status: lead ? "success" : "failure", data: lead ?? void 0 };
|
|
2423
|
+
},
|
|
2409
2424
|
/** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
|
|
2410
2425
|
async getByCompany(opts = {}) {
|
|
2411
2426
|
if (!self.companyKey) return null;
|
|
@@ -2488,6 +2503,17 @@ LeadModel.getByEmail = async (email, companyKey) => {
|
|
|
2488
2503
|
}
|
|
2489
2504
|
return null;
|
|
2490
2505
|
};
|
|
2506
|
+
LeadModel.getByPhone = async (phone, companyKey) => {
|
|
2507
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2508
|
+
const res = await reqGet("/lead/getbyphone", {
|
|
2509
|
+
phone: phone != null ? String(phone).trim() : "",
|
|
2510
|
+
company_key: companyKey != null ? String(companyKey).trim() : ""
|
|
2511
|
+
});
|
|
2512
|
+
if (res.status === "success" && res.data) {
|
|
2513
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2514
|
+
}
|
|
2515
|
+
return null;
|
|
2516
|
+
};
|
|
2491
2517
|
LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
2492
2518
|
var _a, _b;
|
|
2493
2519
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
@@ -2846,6 +2872,22 @@ var AuthModel = {
|
|
|
2846
2872
|
}
|
|
2847
2873
|
return res;
|
|
2848
2874
|
},
|
|
2875
|
+
/**
|
|
2876
|
+
* GET Auth/IsAuthorized — validates OAuth with the provider; clears isApproved when not authorized.
|
|
2877
|
+
* Returns the updated participant record (same shape as participant/get).
|
|
2878
|
+
* @param {string} participantId
|
|
2879
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2880
|
+
*/
|
|
2881
|
+
async IsAuthorized(participantId) {
|
|
2882
|
+
const id = participantId != null ? String(participantId).trim() : "";
|
|
2883
|
+
if (!id) return { status: "failure", message: "participantId required" };
|
|
2884
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2885
|
+
const res = await reqGet("/Auth/IsAuthorized", { participant_id: id });
|
|
2886
|
+
if (res.status === "success" && res.data) {
|
|
2887
|
+
res.data = mapParticipantFromApi(res.data);
|
|
2888
|
+
}
|
|
2889
|
+
return res;
|
|
2890
|
+
},
|
|
2849
2891
|
/**
|
|
2850
2892
|
* Open Google/Microsoft OAuth in a centered popup.
|
|
2851
2893
|
* @param {string} authorizationUrl — from getAuthorizationUrl().data.authorizationUrl
|
|
@@ -2866,16 +2908,27 @@ var AuthModel = {
|
|
|
2866
2908
|
},
|
|
2867
2909
|
/**
|
|
2868
2910
|
* Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
|
|
2869
|
-
*
|
|
2911
|
+
* Do not use popup.closed to detect completion — Cross-Origin-Opener-Policy on the parent app
|
|
2912
|
+
* blocks that check after the popup navigates to Google/Microsoft.
|
|
2913
|
+
* Pass the Window returned from openOAuthPopup so this helper can close it; self-close from
|
|
2914
|
+
* Authorized.html/Error.html is often blocked after OAuth redirects.
|
|
2915
|
+
* @param {(payload: { type: string, status: 'success' | 'error', message?: string, closePopup?: boolean }) => void} handler
|
|
2916
|
+
* @param {Window | null | undefined} [popup] — popup to close when auth completes
|
|
2870
2917
|
* @returns {() => void} unsubscribe
|
|
2871
2918
|
*/
|
|
2872
|
-
onCalendarAuthMessage(handler) {
|
|
2919
|
+
onCalendarAuthMessage(handler, popup) {
|
|
2873
2920
|
if (typeof window === "undefined") return () => {
|
|
2874
2921
|
};
|
|
2875
2922
|
const listener = (event) => {
|
|
2876
2923
|
const payload = event == null ? void 0 : event.data;
|
|
2877
2924
|
if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
|
|
2878
2925
|
handler(payload);
|
|
2926
|
+
if (popup) {
|
|
2927
|
+
try {
|
|
2928
|
+
popup.close();
|
|
2929
|
+
} catch (_) {
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2879
2932
|
};
|
|
2880
2933
|
window.addEventListener("message", listener);
|
|
2881
2934
|
return () => window.removeEventListener("message", listener);
|
package/dist/index.mjs
CHANGED
|
@@ -1418,23 +1418,27 @@ var ParticipantModel = types11.model("Participant", {
|
|
|
1418
1418
|
}
|
|
1419
1419
|
};
|
|
1420
1420
|
});
|
|
1421
|
-
function
|
|
1421
|
+
function mapParticipantFromApi(d) {
|
|
1422
1422
|
if (!d) return d;
|
|
1423
1423
|
const pick2 = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1424
1424
|
const n = (v) => v != null && v !== "" ? Number(v) : void 0;
|
|
1425
1425
|
return {
|
|
1426
|
+
id: n(pick2("id", "Id")) ?? null,
|
|
1426
1427
|
participantId: String(pick2("participantId", "ParticipantId", "participant_id") ?? ""),
|
|
1427
1428
|
companyKey: pick2("companyKey", "CompanyKey", "company_key") ?? null,
|
|
1428
1429
|
alias: pick2("alias", "Alias") ?? "",
|
|
1429
1430
|
email: pick2("email", "Email") ?? "",
|
|
1430
1431
|
isApproved: Boolean(pick2("isApproved", "IsApproved", "is_approved")),
|
|
1431
1432
|
isAvailable: Boolean(pick2("isAvailable", "IsAvailable", "is_available")),
|
|
1432
|
-
provider: n(pick2("provider", "Provider")) ?? 0,
|
|
1433
|
+
provider: n(pick2("provider", "Provider", "emailProvider", "EmailProvider", "email_provider")) ?? 0,
|
|
1433
1434
|
createdOn: pick2("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1434
1435
|
modifiedOn: pick2("modifiedOn", "ModifiedOn", "modified_on") ?? null,
|
|
1435
1436
|
isDeleted: Boolean(pick2("isDeleted", "IsDeleted", "is_deleted"))
|
|
1436
1437
|
};
|
|
1437
1438
|
}
|
|
1439
|
+
function mapFromApi2(d) {
|
|
1440
|
+
return mapParticipantFromApi(d);
|
|
1441
|
+
}
|
|
1438
1442
|
function toPayload(self) {
|
|
1439
1443
|
return {
|
|
1440
1444
|
participantId: self.participantId,
|
|
@@ -2335,6 +2339,17 @@ var LeadModel = types19.model("Lead", {
|
|
|
2335
2339
|
}
|
|
2336
2340
|
return { status: lead ? "success" : "failure", data: lead ?? void 0 };
|
|
2337
2341
|
},
|
|
2342
|
+
/** GET /lead/getbyphone – uses self.phone and self.companyKey */
|
|
2343
|
+
async getByPhone() {
|
|
2344
|
+
if (!self.phone || !self.companyKey) {
|
|
2345
|
+
return { status: "failure", message: "phone and companyKey required on model" };
|
|
2346
|
+
}
|
|
2347
|
+
const lead = await LeadModel.getByPhone(self.phone, self.companyKey);
|
|
2348
|
+
if (lead) {
|
|
2349
|
+
applySnapshot8(self, getSnapshot(lead));
|
|
2350
|
+
}
|
|
2351
|
+
return { status: lead ? "success" : "failure", data: lead ?? void 0 };
|
|
2352
|
+
},
|
|
2338
2353
|
/** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
|
|
2339
2354
|
async getByCompany(opts = {}) {
|
|
2340
2355
|
if (!self.companyKey) return null;
|
|
@@ -2417,6 +2432,17 @@ LeadModel.getByEmail = async (email, companyKey) => {
|
|
|
2417
2432
|
}
|
|
2418
2433
|
return null;
|
|
2419
2434
|
};
|
|
2435
|
+
LeadModel.getByPhone = async (phone, companyKey) => {
|
|
2436
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2437
|
+
const res = await reqGet("/lead/getbyphone", {
|
|
2438
|
+
phone: phone != null ? String(phone).trim() : "",
|
|
2439
|
+
company_key: companyKey != null ? String(companyKey).trim() : ""
|
|
2440
|
+
});
|
|
2441
|
+
if (res.status === "success" && res.data) {
|
|
2442
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2443
|
+
}
|
|
2444
|
+
return null;
|
|
2445
|
+
};
|
|
2420
2446
|
LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
2421
2447
|
var _a, _b;
|
|
2422
2448
|
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
@@ -2775,6 +2801,22 @@ var AuthModel = {
|
|
|
2775
2801
|
}
|
|
2776
2802
|
return res;
|
|
2777
2803
|
},
|
|
2804
|
+
/**
|
|
2805
|
+
* GET Auth/IsAuthorized — validates OAuth with the provider; clears isApproved when not authorized.
|
|
2806
|
+
* Returns the updated participant record (same shape as participant/get).
|
|
2807
|
+
* @param {string} participantId
|
|
2808
|
+
* @returns {Promise<{ status: string, data?: object, message?: string }>}
|
|
2809
|
+
*/
|
|
2810
|
+
async IsAuthorized(participantId) {
|
|
2811
|
+
const id = participantId != null ? String(participantId).trim() : "";
|
|
2812
|
+
if (!id) return { status: "failure", message: "participantId required" };
|
|
2813
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2814
|
+
const res = await reqGet("/Auth/IsAuthorized", { participant_id: id });
|
|
2815
|
+
if (res.status === "success" && res.data) {
|
|
2816
|
+
res.data = mapParticipantFromApi(res.data);
|
|
2817
|
+
}
|
|
2818
|
+
return res;
|
|
2819
|
+
},
|
|
2778
2820
|
/**
|
|
2779
2821
|
* Open Google/Microsoft OAuth in a centered popup.
|
|
2780
2822
|
* @param {string} authorizationUrl — from getAuthorizationUrl().data.authorizationUrl
|
|
@@ -2795,16 +2837,27 @@ var AuthModel = {
|
|
|
2795
2837
|
},
|
|
2796
2838
|
/**
|
|
2797
2839
|
* Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
|
|
2798
|
-
*
|
|
2840
|
+
* Do not use popup.closed to detect completion — Cross-Origin-Opener-Policy on the parent app
|
|
2841
|
+
* blocks that check after the popup navigates to Google/Microsoft.
|
|
2842
|
+
* Pass the Window returned from openOAuthPopup so this helper can close it; self-close from
|
|
2843
|
+
* Authorized.html/Error.html is often blocked after OAuth redirects.
|
|
2844
|
+
* @param {(payload: { type: string, status: 'success' | 'error', message?: string, closePopup?: boolean }) => void} handler
|
|
2845
|
+
* @param {Window | null | undefined} [popup] — popup to close when auth completes
|
|
2799
2846
|
* @returns {() => void} unsubscribe
|
|
2800
2847
|
*/
|
|
2801
|
-
onCalendarAuthMessage(handler) {
|
|
2848
|
+
onCalendarAuthMessage(handler, popup) {
|
|
2802
2849
|
if (typeof window === "undefined") return () => {
|
|
2803
2850
|
};
|
|
2804
2851
|
const listener = (event) => {
|
|
2805
2852
|
const payload = event == null ? void 0 : event.data;
|
|
2806
2853
|
if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
|
|
2807
2854
|
handler(payload);
|
|
2855
|
+
if (popup) {
|
|
2856
|
+
try {
|
|
2857
|
+
popup.close();
|
|
2858
|
+
} catch (_) {
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2808
2861
|
};
|
|
2809
2862
|
window.addEventListener("message", listener);
|
|
2810
2863
|
return () => window.removeEventListener("message", listener);
|