@blazeo.com/calendar-client 1.0.23 → 1.0.24

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
@@ -44,8 +44,53 @@ await cal.create(); // POST to backend
44
44
  - **EventModel (instance):** `get`, `create`, `cancel`, `getCancellable`, `getAvailability`, `setReminder`
45
45
  - **FlowModel:** Same pattern as Calendar — `FlowModel.create({}, { env })` with no fields; static `get`, `getRaw`, `list`, `createFlow`, `updateFlow`, `delete`, `duplicate`, appearance/embed/public/preview helpers; instance methods mirror those using `flowId` on the snapshot
46
46
  - **LeadModel:** `LeadModel.create({}, { env })`; static `get`, `getRaw`, `getByEmail`, `getByCompany`; instance `get`, `getByEmail`, `getByCompany` (uses `leadId` / `email` / `companyKey` on the snapshot)
47
+ - **AuthModel (calendar OAuth / Connect Calendar):** `getCalendarProviders`, `getAuthorizationUrl`, `getAuthorizationStatus`, `openOAuthPopup`, `onCalendarAuthMessage` — see [Calendar authorization flow](#calendar-authorization-direct-ui)
47
48
  - **RootStore:** `addCalendar`, `addEvent`
48
49
 
50
+ ### Calendar authorization (direct UI)
51
+
52
+ When the user connects Google or Outlook from the Scheduling modal:
53
+
54
+ ```js
55
+ import {
56
+ configure,
57
+ AuthModel,
58
+ CalendarEmailProvider,
59
+ CALENDAR_AUTH_MESSAGE_TYPE,
60
+ } from '@blazeo.com/calendar-client';
61
+
62
+ configure({ baseUrl: 'https://your-appointment-api.example.com' });
63
+
64
+ const participantId = '...'; // logged-in participant GUID
65
+
66
+ // Optional: already connected?
67
+ const statusRes = await AuthModel.getAuthorizationStatus(participantId);
68
+ if (statusRes.status === 'success' && statusRes.data?.isAuthorized) {
69
+ // show connected UI
70
+ }
71
+
72
+ // Load provider cards (Google / Gmail, Microsoft Outlook)
73
+ const providersRes = await AuthModel.getCalendarProviders();
74
+ const providers = providersRes.data; // [{ key: 'google', displayName: 'Google / Gmail', ... }, ...]
75
+
76
+ // User clicks Google
77
+ const urlRes = await AuthModel.getAuthorizationUrl(participantId, 'google');
78
+ const popup = AuthModel.openOAuthPopup(urlRes.data.authorizationUrl);
79
+
80
+ const unsubscribe = AuthModel.onCalendarAuthMessage(async (payload) => {
81
+ if (payload.status === 'success') {
82
+ const check = await AuthModel.getAuthorizationStatus(participantId);
83
+ if (check.data?.isAuthorized) {
84
+ // close modal, show success
85
+ }
86
+ }
87
+ });
88
+
89
+ // On modal unmount: unsubscribe(); popup?.close();
90
+ ```
91
+
92
+ `email_provider` for `getAuthorizationUrl`: `google`, `gmail`, `1`, `outlook`, `microsoft`, or `2`.
93
+
49
94
  All methods return `Promise<{ status, data?, message? }>`. Check `response.status === 'success'` and use `response.data`.
50
95
 
51
96
  ## Samples
package/dist/index.d.ts CHANGED
@@ -246,6 +246,86 @@ export const LeadModel: {
246
246
  create(snapshot?: object, options?: { env?: object }): unknown;
247
247
  };
248
248
 
249
+ export type CalendarProviderOption = {
250
+ emailProvider: number;
251
+ key: string;
252
+ name: string;
253
+ displayName: string;
254
+ description: string;
255
+ scope: string;
256
+ redirectUrl: string;
257
+ };
258
+
259
+ export type ParticipantAuthorizationUrl = {
260
+ participantId: string;
261
+ emailProvider: number;
262
+ providerKey: string;
263
+ authorizationUrl: string;
264
+ redirectUrl: string;
265
+ };
266
+
267
+ export type CalendarProviderAuthorizationState = {
268
+ emailProvider: number;
269
+ key: string;
270
+ name: string;
271
+ hasCredentials: boolean;
272
+ isAuthorized: boolean;
273
+ isSelected: boolean;
274
+ };
275
+
276
+ export type ParticipantAuthorizationStatus = {
277
+ participantId: string;
278
+ email: string;
279
+ emailProvider: number;
280
+ providerKey: string;
281
+ hasCredentials: boolean;
282
+ isAuthorized: boolean;
283
+ providers: CalendarProviderAuthorizationState[];
284
+ };
285
+
286
+ export const CALENDAR_AUTH_MESSAGE_TYPE: 'calendar-authorization';
287
+
288
+ export const CalendarEmailProvider: {
289
+ Google: 1;
290
+ Microsoft: 2;
291
+ Default: 3;
292
+ };
293
+
294
+ export const AuthModel: {
295
+ CALENDAR_AUTH_MESSAGE_TYPE: typeof CALENDAR_AUTH_MESSAGE_TYPE;
296
+ EmailProvider: typeof CalendarEmailProvider;
297
+ getCalendarProviders(opts?: { host?: string }): Promise<{
298
+ status: string;
299
+ data?: CalendarProviderOption[];
300
+ message?: string;
301
+ }>;
302
+ getAuthorizationUrl(
303
+ participantId: string,
304
+ emailProvider: string | number,
305
+ opts?: { host?: string }
306
+ ): Promise<{
307
+ status: string;
308
+ data?: ParticipantAuthorizationUrl;
309
+ message?: string;
310
+ }>;
311
+ getAuthorizationStatus(participantId: string): Promise<{
312
+ status: string;
313
+ data?: ParticipantAuthorizationStatus;
314
+ message?: string;
315
+ }>;
316
+ openOAuthPopup(
317
+ authorizationUrl: string,
318
+ opts?: { width?: number; height?: number }
319
+ ): Window | null;
320
+ onCalendarAuthMessage(
321
+ handler: (payload: {
322
+ type: string;
323
+ status: 'success' | 'error';
324
+ message?: string;
325
+ }) => void
326
+ ): () => void;
327
+ };
328
+
249
329
  export const CustomFieldModel: {
250
330
  getAll(calendarId: string): Promise<unknown[] | null>;
251
331
  getFieldType(fieldType: string): Promise<unknown>;
@@ -270,3 +350,4 @@ export const AttendeeStatus: Record<string, number>;
270
350
  export const RecurringFrequency: Record<string, number>;
271
351
  export const DayOfWeek: Record<string, number>;
272
352
  export const LocationType: Record<string, number>;
353
+ export const EmailProvider: Record<string, number>;