@blazeo.com/calendar-client
v1.0.56
Published
Blazeo Calendar / Appointment API client with MobX State Tree models
Readme
@blazeo.com/calendar-client
Private package – for Blazeo internal teams only. JavaScript client for the Blazeo Calendar / Appointment API. Use it in React (or any JS app) to call calendar and event endpoints via MobX State Tree models.
Install
From your npm registry (internal teams; ensure you're logged in to the scope):
npm install @blazeo.com/calendar-clientOr link locally:
cd calendar-client && npm run build && npm link
cd your-app && npm link @blazeo.com/calendar-clientUsage
Configure once at app startup, then use models and their methods:
import {
configure,
setAccessToken,
setGetAccessToken,
CalendarModel,
createRootStore,
} from '@blazeo.com/calendar-client';
configure({
baseUrl: 'https://your-appointment-api.example.com',
consumer: 'my-app', // optional Consumer header
accessToken: yourIdpAccessToken, // JWT from your identity provider
expiresAtUtc: '2026-05-21T12:00:00Z', // optional — used before auto-refresh
getAccessToken: async () => yourIdp.getAccessToken(), // optional refresh callback
});
// Calendar static methods (no store needed)
const timezones = await CalendarModel.getTimeZones();
const calendar = await CalendarModel.get('calendar-guid');
// Or use RootStore with models
const store = createRootStore();
const cal = store.addCalendar({ calendarId: 'my-cal', name: 'My Calendar' });
await cal.create(); // POST to backendJWT authentication
The Appointment API validates Bearer JWTs from your identity provider (Authentication:Jwt:Authority on the server). This package does not exchange api keys for tokens — pass the JWT your app already has.
| Function | Purpose |
|----------|---------|
| setAccessToken(token, expiresAtUtc?) | Store JWT from your IdP |
| setGetAccessToken(fn) | Async callback to refresh when missing/near expiry |
| ensureValidAccessToken() | Resolve token before a request (uses callback if needed) |
| clearAuth() | Clear token and refresh callback |
All reqGet / reqPost calls attach Authorization: Bearer … when a token is configured.
setAccessToken(session.accessToken, session.expiresAt);
setGetAccessToken(() => authService.acquireTokenSilent());
await LeadModel.requestExport('company-key', { userEmail: '[email protected]' });API overview
- CalendarModel (static):
get,getByCompany,getTimeZones,getTimeZone,getParticipants,getMonth,getEvents, etc. - EventModel (instance):
get,create,cancel,delete,getCancellable,getAvailability,setReminder - EventModel (static):
get,cancel,delete,getCancellable,createEvent,reschedule,updateEvent, … - FlowModel: Same pattern as Calendar —
FlowModel.create({}, { env })with no fields; staticget,getRaw,list,createFlow,updateFlow,delete,duplicate, appearance/embed/public/preview helpers; instance methods mirror those usingflowIdon the snapshot - LeadModel:
LeadModel.create({}, { env }); staticget,getRaw,getByEmail,getByPhone,getByCompany,saveColumnSelection,getColumnSelection,allowedColumns,requestExport; instanceget,getByEmail,getByPhone,getByCompany,saveColumnSelection,getColumnSelection,requestLeadExport. PassuserIdingetByCompany(companyKey, { userId })to return only columns saved for that user. ForrequestExport, passuserEmail(or rely on JWT email claim) so the server can publish aNotificationGeneratedmessage when export completes. - ParticipantModel: static
get,getByEmail,getByIds,getAll, …; instancegetByEmailusesemail+companyKeyon the snapshot (seeGET /participant/getbyemail) - AuthModel (calendar OAuth / Connect Calendar):
getCalendarProviders,getAuthorizationUrl,getAuthorizationStatus,openOAuthPopup,onCalendarAuthMessage— see Calendar authorization flow - RootStore:
addCalendar,addEvent
Calendar authorization (direct UI)
When the user connects Google or Outlook from the Scheduling modal:
import {
configure,
AuthModel,
CalendarEmailProvider,
CALENDAR_AUTH_MESSAGE_TYPE,
} from '@blazeo.com/calendar-client';
configure({ baseUrl: 'https://your-appointment-api.example.com' });
const participantId = '...'; // logged-in participant GUID
// Optional: already connected?
const statusRes = await AuthModel.getAuthorizationStatus(participantId);
if (statusRes.status === 'success' && statusRes.data?.isAuthorized) {
// show connected UI
}
// Load provider cards (Google / Gmail, Microsoft Outlook)
const providersRes = await AuthModel.getCalendarProviders();
const providers = providersRes.data; // [{ key: 'google', displayName: 'Google / Gmail', ... }, ...]
// User clicks Google
const urlRes = await AuthModel.getAuthorizationUrl(participantId, 'google');
const popup = AuthModel.openOAuthPopup(urlRes.data.authorizationUrl);
const unsubscribe = AuthModel.onCalendarAuthMessage(async (payload) => {
if (payload.status === 'success') {
const check = await AuthModel.getAuthorizationStatus(participantId);
if (check.data?.isAuthorized) {
// close modal, show success
}
}
});
// On modal unmount: unsubscribe(); popup?.close();email_provider for getAuthorizationUrl: google, gmail, 1, outlook, microsoft, or 2.
All methods return Promise<{ status, data?, message? }>. Check response.status === 'success' and use response.data.
Samples
sample/– Uses the package viafile:..for local development (runnpm run buildin parent first).sample-npm/– Uses the package from npm:npm i @blazeo.com/calendar-client. For testing the published package.
