@blazeo.com/calendar-client 1.0.29 → 1.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -72,7 +72,7 @@ await LeadModel.requestExport('company-key');
72
72
  - **CalendarModel (static):** `get`, `getByCompany`, `getTimeZones`, `getTimeZone`, `getParticipants`, `getMonth`, `getEvents`, etc.
73
73
  - **EventModel (instance):** `get`, `create`, `cancel`, `getCancellable`, `getAvailability`, `setReminder`
74
74
  - **FlowModel:** Same pattern as Calendar — `FlowModel.create({}, { env })` with no fields; static `get`, `getRaw`, `list`, `createFlow`, `updateFlow`, `delete`, `duplicate`, appearance/embed/public/preview helpers; instance methods mirror those using `flowId` on the snapshot
75
- - **LeadModel:** `LeadModel.create({}, { env })`; static `get`, `getRaw`, `getByEmail`, `getByCompany`; instance `get`, `getByEmail`, `getByCompany` (uses `leadId` / `email` / `companyKey` on the snapshot)
75
+ - **LeadModel:** `LeadModel.create({}, { env })`; static `get`, `getRaw`, `getByEmail`, `getByPhone`, `getByCompany`, `saveColumnSelection`, `getColumnSelection`, `allowedColumns`; instance `get`, `getByEmail`, `getByPhone`, `getByCompany`, `saveColumnSelection`, `getColumnSelection`. Pass `userId` in `getByCompany(companyKey, { userId })` to return only columns saved for that user.
76
76
  - **ParticipantModel:** static `get`, `getByEmail`, `getByIds`, `getAll`, …; instance `getByEmail` uses `email` + `companyKey` on the snapshot (see `GET /participant/getbyemail`)
77
77
  - **AuthModel (calendar OAuth / Connect Calendar):** `getCalendarProviders`, `getAuthorizationUrl`, `getAuthorizationStatus`, `openOAuthPopup`, `onCalendarAuthMessage` — see [Calendar authorization flow](#calendar-authorization-direct-ui)
78
78
  - **RootStore:** `addCalendar`, `addEvent`
package/dist/index.d.ts CHANGED
@@ -230,6 +230,17 @@ 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>;
234
+ allowedColumns: string[];
235
+ saveColumnSelection(
236
+ userId: string,
237
+ columns: string[]
238
+ ): Promise<{ status: string; data?: unknown; message?: string }>;
239
+ getColumnSelection(userId: string): Promise<{
240
+ status: string;
241
+ data?: { userId?: string; columns?: string[]; isDefault?: boolean };
242
+ message?: string;
243
+ }>;
233
244
  createLead(payload: {
234
245
  email: string;
235
246
  companyKey: string;
@@ -262,6 +273,8 @@ export const LeadModel: {
262
273
  getByCompany(
263
274
  companyKey: string,
264
275
  opts?: {
276
+ userId?: string;
277
+ user_id?: string;
265
278
  skip?: number;
266
279
  take?: number;
267
280
  /** Maps to API query `sort`. */
@@ -376,7 +389,9 @@ export const AuthModel: {
376
389
  type: string;
377
390
  status: 'success' | 'error';
378
391
  message?: string;
379
- }) => void
392
+ closePopup?: boolean;
393
+ }) => void,
394
+ popup?: Window | null
380
395
  ): () => void;
381
396
  };
382
397
 
package/dist/index.js CHANGED
@@ -2026,9 +2026,11 @@ var PreferenceScope = {
2026
2026
  Consumer: 1,
2027
2027
  Company: 2,
2028
2028
  Calendar: 3,
2029
- Event: 4
2029
+ Event: 4,
2030
+ Participant: 5,
2031
+ User: 6
2030
2032
  };
2031
- var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event"];
2033
+ var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event", "Participant", "User"];
2032
2034
  var PreferenceModel = import_mobx_state_tree17.types.model("Preference", {
2033
2035
  id: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.number), null),
2034
2036
  preferenceId: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string), null),
@@ -2410,11 +2412,30 @@ var LeadModel = import_mobx_state_tree19.types.model("Lead", {
2410
2412
  }
2411
2413
  return { status: lead ? "success" : "failure", data: lead ?? void 0 };
2412
2414
  },
2415
+ /** GET /lead/getbyphone – uses self.phone and self.companyKey */
2416
+ async getByPhone() {
2417
+ if (!self.phone || !self.companyKey) {
2418
+ return { status: "failure", message: "phone and companyKey required on model" };
2419
+ }
2420
+ const lead = await LeadModel.getByPhone(self.phone, self.companyKey);
2421
+ if (lead) {
2422
+ (0, import_mobx_state_tree19.applySnapshot)(self, (0, import_mobx_state_tree19.getSnapshot)(lead));
2423
+ }
2424
+ return { status: lead ? "success" : "failure", data: lead ?? void 0 };
2425
+ },
2413
2426
  /** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
2414
2427
  async getByCompany(opts = {}) {
2415
2428
  if (!self.companyKey) return null;
2416
2429
  return LeadModel.getByCompany(self.companyKey, opts);
2417
2430
  },
2431
+ /** POST /lead/columns/save – saves user column selection to Preference (scope User). */
2432
+ async saveColumnSelection(userId, columns) {
2433
+ return LeadModel.saveColumnSelection(userId, columns);
2434
+ },
2435
+ /** GET /lead/columns/get – reads saved column selection for a user. */
2436
+ async getColumnSelection(userId) {
2437
+ return LeadModel.getColumnSelection(userId);
2438
+ },
2418
2439
  /** POST /lead/create – create this lead */
2419
2440
  async createLead() {
2420
2441
  const payload = {
@@ -2492,10 +2513,52 @@ LeadModel.getByEmail = async (email, companyKey) => {
2492
2513
  }
2493
2514
  return null;
2494
2515
  };
2516
+ LeadModel.getByPhone = async (phone, companyKey) => {
2517
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
2518
+ const res = await reqGet("/lead/getbyphone", {
2519
+ phone: phone != null ? String(phone).trim() : "",
2520
+ company_key: companyKey != null ? String(companyKey).trim() : ""
2521
+ });
2522
+ if (res.status === "success" && res.data) {
2523
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
2524
+ }
2525
+ return null;
2526
+ };
2527
+ LeadModel.allowedColumns = [
2528
+ "id",
2529
+ "lead_id",
2530
+ "email",
2531
+ "name",
2532
+ "phone",
2533
+ "company_key",
2534
+ "source",
2535
+ "lead_type",
2536
+ "referrer_link",
2537
+ "created_on",
2538
+ "modified_on"
2539
+ ];
2540
+ LeadModel.saveColumnSelection = async (userId, columns) => {
2541
+ const uid = userId != null ? String(userId).trim() : "";
2542
+ if (!uid) return { status: "failure", message: "userId required" };
2543
+ const cols = Array.isArray(columns) ? columns.map((c) => String(c).trim()).filter(Boolean) : [];
2544
+ if (!cols.length) return { status: "failure", message: "columns required" };
2545
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
2546
+ return reqPost("/lead/columns/save", { user_id: uid, columns: cols });
2547
+ };
2548
+ LeadModel.getColumnSelection = async (userId) => {
2549
+ const uid = userId != null ? String(userId).trim() : "";
2550
+ if (!uid) return { status: "failure", message: "userId required" };
2551
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
2552
+ return reqGet("/lead/columns/get", { user_id: uid });
2553
+ };
2495
2554
  LeadModel.getByCompany = async (companyKey, opts = {}) => {
2496
2555
  var _a, _b;
2497
2556
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
2498
2557
  const query = { company_key: companyKey };
2558
+ const userId = opts.userId ?? opts.user_id;
2559
+ if (userId != null && String(userId).trim() !== "") {
2560
+ query.user_id = String(userId).trim();
2561
+ }
2499
2562
  const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
2500
2563
  if (sortBy != null && sortBy !== "") query.sort = sortBy;
2501
2564
  const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
@@ -2888,16 +2951,25 @@ var AuthModel = {
2888
2951
  * Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
2889
2952
  * Do not use popup.closed to detect completion — Cross-Origin-Opener-Policy on the parent app
2890
2953
  * blocks that check after the popup navigates to Google/Microsoft.
2891
- * @param {(payload: { type: string, status: 'success' | 'error', message?: string }) => void} handler
2954
+ * Pass the Window returned from openOAuthPopup so this helper can close it; self-close from
2955
+ * Authorized.html/Error.html is often blocked after OAuth redirects.
2956
+ * @param {(payload: { type: string, status: 'success' | 'error', message?: string, closePopup?: boolean }) => void} handler
2957
+ * @param {Window | null | undefined} [popup] — popup to close when auth completes
2892
2958
  * @returns {() => void} unsubscribe
2893
2959
  */
2894
- onCalendarAuthMessage(handler) {
2960
+ onCalendarAuthMessage(handler, popup) {
2895
2961
  if (typeof window === "undefined") return () => {
2896
2962
  };
2897
2963
  const listener = (event) => {
2898
2964
  const payload = event == null ? void 0 : event.data;
2899
2965
  if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
2900
2966
  handler(payload);
2967
+ if (popup) {
2968
+ try {
2969
+ popup.close();
2970
+ } catch (_) {
2971
+ }
2972
+ }
2901
2973
  };
2902
2974
  window.addEventListener("message", listener);
2903
2975
  return () => window.removeEventListener("message", listener);
package/dist/index.mjs CHANGED
@@ -1955,9 +1955,11 @@ var PreferenceScope = {
1955
1955
  Consumer: 1,
1956
1956
  Company: 2,
1957
1957
  Calendar: 3,
1958
- Event: 4
1958
+ Event: 4,
1959
+ Participant: 5,
1960
+ User: 6
1959
1961
  };
1960
- var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event"];
1962
+ var SCOPE_NAMES = ["Global", "Consumer", "Company", "Calendar", "Event", "Participant", "User"];
1961
1963
  var PreferenceModel = types17.model("Preference", {
1962
1964
  id: types17.optional(types17.maybeNull(types17.number), null),
1963
1965
  preferenceId: types17.optional(types17.maybeNull(types17.string), null),
@@ -2339,11 +2341,30 @@ var LeadModel = types19.model("Lead", {
2339
2341
  }
2340
2342
  return { status: lead ? "success" : "failure", data: lead ?? void 0 };
2341
2343
  },
2344
+ /** GET /lead/getbyphone – uses self.phone and self.companyKey */
2345
+ async getByPhone() {
2346
+ if (!self.phone || !self.companyKey) {
2347
+ return { status: "failure", message: "phone and companyKey required on model" };
2348
+ }
2349
+ const lead = await LeadModel.getByPhone(self.phone, self.companyKey);
2350
+ if (lead) {
2351
+ applySnapshot8(self, getSnapshot(lead));
2352
+ }
2353
+ return { status: lead ? "success" : "failure", data: lead ?? void 0 };
2354
+ },
2342
2355
  /** GET /lead/company/get – uses self.companyKey; same result as LeadModel.getByCompany(companyKey, opts) */
2343
2356
  async getByCompany(opts = {}) {
2344
2357
  if (!self.companyKey) return null;
2345
2358
  return LeadModel.getByCompany(self.companyKey, opts);
2346
2359
  },
2360
+ /** POST /lead/columns/save – saves user column selection to Preference (scope User). */
2361
+ async saveColumnSelection(userId, columns) {
2362
+ return LeadModel.saveColumnSelection(userId, columns);
2363
+ },
2364
+ /** GET /lead/columns/get – reads saved column selection for a user. */
2365
+ async getColumnSelection(userId) {
2366
+ return LeadModel.getColumnSelection(userId);
2367
+ },
2347
2368
  /** POST /lead/create – create this lead */
2348
2369
  async createLead() {
2349
2370
  const payload = {
@@ -2421,10 +2442,52 @@ LeadModel.getByEmail = async (email, companyKey) => {
2421
2442
  }
2422
2443
  return null;
2423
2444
  };
2445
+ LeadModel.getByPhone = async (phone, companyKey) => {
2446
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
2447
+ const res = await reqGet("/lead/getbyphone", {
2448
+ phone: phone != null ? String(phone).trim() : "",
2449
+ company_key: companyKey != null ? String(companyKey).trim() : ""
2450
+ });
2451
+ if (res.status === "success" && res.data) {
2452
+ return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
2453
+ }
2454
+ return null;
2455
+ };
2456
+ LeadModel.allowedColumns = [
2457
+ "id",
2458
+ "lead_id",
2459
+ "email",
2460
+ "name",
2461
+ "phone",
2462
+ "company_key",
2463
+ "source",
2464
+ "lead_type",
2465
+ "referrer_link",
2466
+ "created_on",
2467
+ "modified_on"
2468
+ ];
2469
+ LeadModel.saveColumnSelection = async (userId, columns) => {
2470
+ const uid = userId != null ? String(userId).trim() : "";
2471
+ if (!uid) return { status: "failure", message: "userId required" };
2472
+ const cols = Array.isArray(columns) ? columns.map((c) => String(c).trim()).filter(Boolean) : [];
2473
+ if (!cols.length) return { status: "failure", message: "columns required" };
2474
+ const { reqPost } = createRequestHelpersFromEnv(getConfig());
2475
+ return reqPost("/lead/columns/save", { user_id: uid, columns: cols });
2476
+ };
2477
+ LeadModel.getColumnSelection = async (userId) => {
2478
+ const uid = userId != null ? String(userId).trim() : "";
2479
+ if (!uid) return { status: "failure", message: "userId required" };
2480
+ const { reqGet } = createRequestHelpersFromEnv(getConfig());
2481
+ return reqGet("/lead/columns/get", { user_id: uid });
2482
+ };
2424
2483
  LeadModel.getByCompany = async (companyKey, opts = {}) => {
2425
2484
  var _a, _b;
2426
2485
  const { reqGet } = createRequestHelpersFromEnv(getConfig());
2427
2486
  const query = { company_key: companyKey };
2487
+ const userId = opts.userId ?? opts.user_id;
2488
+ if (userId != null && String(userId).trim() !== "") {
2489
+ query.user_id = String(userId).trim();
2490
+ }
2428
2491
  const sortBy = opts.sortBy ?? opts.sort ?? opts.sort_column;
2429
2492
  if (sortBy != null && sortBy !== "") query.sort = sortBy;
2430
2493
  const sortOrderRaw = opts.sortOrder ?? opts.sort_dir;
@@ -2817,16 +2880,25 @@ var AuthModel = {
2817
2880
  * Subscribe to calendar-authorization postMessage from OAuth popup (Authorized.html / Error.html).
2818
2881
  * Do not use popup.closed to detect completion — Cross-Origin-Opener-Policy on the parent app
2819
2882
  * blocks that check after the popup navigates to Google/Microsoft.
2820
- * @param {(payload: { type: string, status: 'success' | 'error', message?: string }) => void} handler
2883
+ * Pass the Window returned from openOAuthPopup so this helper can close it; self-close from
2884
+ * Authorized.html/Error.html is often blocked after OAuth redirects.
2885
+ * @param {(payload: { type: string, status: 'success' | 'error', message?: string, closePopup?: boolean }) => void} handler
2886
+ * @param {Window | null | undefined} [popup] — popup to close when auth completes
2821
2887
  * @returns {() => void} unsubscribe
2822
2888
  */
2823
- onCalendarAuthMessage(handler) {
2889
+ onCalendarAuthMessage(handler, popup) {
2824
2890
  if (typeof window === "undefined") return () => {
2825
2891
  };
2826
2892
  const listener = (event) => {
2827
2893
  const payload = event == null ? void 0 : event.data;
2828
2894
  if (!payload || payload.type !== CALENDAR_AUTH_MESSAGE_TYPE) return;
2829
2895
  handler(payload);
2896
+ if (popup) {
2897
+ try {
2898
+ popup.close();
2899
+ } catch (_) {
2900
+ }
2901
+ }
2830
2902
  };
2831
2903
  window.addEventListener("message", listener);
2832
2904
  return () => window.removeEventListener("message", listener);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazeo.com/calendar-client",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Blazeo Calendar / Appointment API client with MobX State Tree models",
5
5
  "exports": {
6
6
  ".": {