@dereekb/calcom 13.4.0
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/LICENSE +21 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +2202 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +2141 -0
- package/nestjs/index.cjs.default.js +1 -0
- package/nestjs/index.cjs.js +1970 -0
- package/nestjs/index.cjs.mjs +2 -0
- package/nestjs/index.d.ts +1 -0
- package/nestjs/index.esm.js +1938 -0
- package/nestjs/package.json +28 -0
- package/nestjs/src/index.d.ts +1 -0
- package/nestjs/src/lib/calcom/calcom.api.d.ts +160 -0
- package/nestjs/src/lib/calcom/calcom.config.d.ts +10 -0
- package/nestjs/src/lib/calcom/calcom.module.d.ts +18 -0
- package/nestjs/src/lib/calcom/index.d.ts +3 -0
- package/nestjs/src/lib/index.d.ts +3 -0
- package/nestjs/src/lib/oauth/index.d.ts +4 -0
- package/nestjs/src/lib/oauth/oauth.api.d.ts +25 -0
- package/nestjs/src/lib/oauth/oauth.config.d.ts +22 -0
- package/nestjs/src/lib/oauth/oauth.module.d.ts +24 -0
- package/nestjs/src/lib/oauth/oauth.service.d.ts +66 -0
- package/nestjs/src/lib/webhook/index.d.ts +7 -0
- package/nestjs/src/lib/webhook/webhook.calcom.config.d.ts +11 -0
- package/nestjs/src/lib/webhook/webhook.calcom.controller.d.ts +8 -0
- package/nestjs/src/lib/webhook/webhook.calcom.d.ts +16 -0
- package/nestjs/src/lib/webhook/webhook.calcom.module.d.ts +20 -0
- package/nestjs/src/lib/webhook/webhook.calcom.service.d.ts +21 -0
- package/nestjs/src/lib/webhook/webhook.calcom.type.d.ts +33 -0
- package/nestjs/src/lib/webhook/webhook.calcom.verify.d.ts +16 -0
- package/package.json +34 -0
- package/src/index.d.ts +1 -0
- package/src/lib/calcom/calcom.api.booking.d.ts +86 -0
- package/src/lib/calcom/calcom.api.calendar.d.ts +82 -0
- package/src/lib/calcom/calcom.api.eventtype.d.ts +85 -0
- package/src/lib/calcom/calcom.api.schedule.d.ts +32 -0
- package/src/lib/calcom/calcom.api.slot.d.ts +46 -0
- package/src/lib/calcom/calcom.api.user.d.ts +29 -0
- package/src/lib/calcom/calcom.api.webhook.d.ts +97 -0
- package/src/lib/calcom/calcom.config.d.ts +66 -0
- package/src/lib/calcom/calcom.error.api.d.ts +6 -0
- package/src/lib/calcom/calcom.factory.d.ts +23 -0
- package/src/lib/calcom/index.d.ts +10 -0
- package/src/lib/calcom.config.d.ts +35 -0
- package/src/lib/calcom.error.api.d.ts +86 -0
- package/src/lib/calcom.limit.d.ts +35 -0
- package/src/lib/calcom.type.d.ts +70 -0
- package/src/lib/index.d.ts +7 -0
- package/src/lib/oauth/index.d.ts +5 -0
- package/src/lib/oauth/oauth.api.d.ts +54 -0
- package/src/lib/oauth/oauth.config.d.ts +53 -0
- package/src/lib/oauth/oauth.d.ts +64 -0
- package/src/lib/oauth/oauth.error.api.d.ts +26 -0
- package/src/lib/oauth/oauth.factory.d.ts +31 -0
- package/src/lib/shared/calcom.api-version.d.ts +17 -0
- package/src/lib/shared/index.d.ts +1 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type EmailAddress, type ISO8601DateString, type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext } from './calcom.config';
|
|
3
|
+
import { type CalcomId, type CalcomCredentialId, type CalcomCalendarIntegration, type CalcomUserId, type CalcomEventTypeId, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export interface CalcomCalendar {
|
|
5
|
+
readonly externalId: string;
|
|
6
|
+
readonly integration: CalcomCalendarIntegration;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly readOnly: boolean;
|
|
9
|
+
readonly email: EmailAddress;
|
|
10
|
+
readonly isSelected: boolean;
|
|
11
|
+
readonly credentialId: CalcomCredentialId;
|
|
12
|
+
}
|
|
13
|
+
export interface CalcomConnectedCalendar {
|
|
14
|
+
readonly integration: CalcomCalendarIntegration;
|
|
15
|
+
readonly credentialId: CalcomCredentialId;
|
|
16
|
+
readonly primary: {
|
|
17
|
+
readonly calendars: CalcomCalendar[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface CalcomDestinationCalendar {
|
|
21
|
+
readonly id: CalcomId;
|
|
22
|
+
readonly integration: CalcomCalendarIntegration;
|
|
23
|
+
readonly externalId: string;
|
|
24
|
+
readonly primaryEmail: EmailAddress;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly readOnly: boolean;
|
|
27
|
+
readonly email: EmailAddress;
|
|
28
|
+
readonly isSelected: boolean;
|
|
29
|
+
readonly credentialId: CalcomCredentialId;
|
|
30
|
+
readonly userId: CalcomUserId;
|
|
31
|
+
readonly eventTypeId: Maybe<CalcomEventTypeId>;
|
|
32
|
+
readonly integrationTitle: string;
|
|
33
|
+
}
|
|
34
|
+
export interface CalcomGetCalendarsResponseData {
|
|
35
|
+
readonly connectedCalendars: CalcomConnectedCalendar[];
|
|
36
|
+
readonly destinationCalendar: Maybe<CalcomDestinationCalendar>;
|
|
37
|
+
}
|
|
38
|
+
export interface CalcomGetCalendarsResponse {
|
|
39
|
+
readonly status: CalcomResponseStatus;
|
|
40
|
+
readonly data: CalcomGetCalendarsResponseData;
|
|
41
|
+
}
|
|
42
|
+
export interface CalcomGetBusyTimesInput {
|
|
43
|
+
readonly dateFrom: ISO8601DateString;
|
|
44
|
+
readonly dateTo: ISO8601DateString;
|
|
45
|
+
readonly calendarsToLoad?: Maybe<string[]>;
|
|
46
|
+
}
|
|
47
|
+
export interface CalcomBusyTime {
|
|
48
|
+
readonly start: ISO8601DateString;
|
|
49
|
+
readonly end: ISO8601DateString;
|
|
50
|
+
readonly source?: Maybe<string>;
|
|
51
|
+
}
|
|
52
|
+
export interface CalcomGetBusyTimesResponse {
|
|
53
|
+
readonly status: CalcomResponseStatus;
|
|
54
|
+
readonly data: CalcomBusyTime[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves all connected calendars and the destination calendar for the authenticated user.
|
|
58
|
+
*
|
|
59
|
+
* @see https://cal.com/docs/api-reference/v2/calendars/get-all-calendars
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const response = await getCalendars(context)();
|
|
64
|
+
* response.data.connectedCalendars.forEach(cc => console.log(cc.integration));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function getCalendars(context: CalcomContext): () => Promise<CalcomGetCalendarsResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves busy time ranges across the user's connected calendars for a given date range.
|
|
70
|
+
*
|
|
71
|
+
* @see https://cal.com/docs/api-reference/v2/calendars/get-busy-times
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const response = await getBusyTimes(context)({
|
|
76
|
+
* dateFrom: '2026-03-17',
|
|
77
|
+
* dateTo: '2026-03-24'
|
|
78
|
+
* });
|
|
79
|
+
* response.data.forEach(bt => console.log(bt.start, bt.end));
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function getBusyTimes(context: CalcomContext): (input: CalcomGetBusyTimesInput) => Promise<CalcomGetBusyTimesResponse>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type Minutes } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext } from './calcom.config';
|
|
3
|
+
import { type CalcomEventTypeId, type CalcomEventTypeSlug, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export interface CalcomEventType {
|
|
5
|
+
readonly id: CalcomEventTypeId;
|
|
6
|
+
readonly title: string;
|
|
7
|
+
readonly slug: CalcomEventTypeSlug;
|
|
8
|
+
readonly description: string | null;
|
|
9
|
+
readonly lengthInMinutes: Minutes;
|
|
10
|
+
readonly locations: unknown[];
|
|
11
|
+
}
|
|
12
|
+
export interface CalcomGetEventTypesResponse {
|
|
13
|
+
readonly status: CalcomResponseStatus;
|
|
14
|
+
readonly data: CalcomEventType[];
|
|
15
|
+
}
|
|
16
|
+
export interface CalcomEventTypeResponse {
|
|
17
|
+
readonly status: CalcomResponseStatus;
|
|
18
|
+
readonly data: CalcomEventType;
|
|
19
|
+
}
|
|
20
|
+
export interface CalcomCreateEventTypeInput {
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly slug: CalcomEventTypeSlug;
|
|
23
|
+
readonly lengthInMinutes: Minutes;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
readonly locations?: unknown[];
|
|
26
|
+
readonly bookingFields?: unknown[];
|
|
27
|
+
}
|
|
28
|
+
export interface CalcomUpdateEventTypeInput {
|
|
29
|
+
readonly title?: string;
|
|
30
|
+
readonly slug?: CalcomEventTypeSlug;
|
|
31
|
+
readonly lengthInMinutes?: Minutes;
|
|
32
|
+
readonly description?: string;
|
|
33
|
+
readonly locations?: unknown[];
|
|
34
|
+
readonly bookingFields?: unknown[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves all event types for the authenticated user.
|
|
38
|
+
*
|
|
39
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/get-all-event-types
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const response = await getEventTypes(context)();
|
|
44
|
+
* response.data.forEach(et => console.log(et.title, et.slug, et.lengthInMinutes));
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function getEventTypes(context: CalcomContext): () => Promise<CalcomGetEventTypesResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new event type for the authenticated user.
|
|
50
|
+
*
|
|
51
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/create-an-event-type
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const response = await createEventType(context)({
|
|
56
|
+
* title: 'Mentoring Session',
|
|
57
|
+
* slug: 'mentoring-session',
|
|
58
|
+
* lengthInMinutes: 30
|
|
59
|
+
* });
|
|
60
|
+
* console.log(response.data.id);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function createEventType(context: CalcomContext): (input: CalcomCreateEventTypeInput) => Promise<CalcomEventTypeResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Updates an existing event type by ID.
|
|
66
|
+
*
|
|
67
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/update-an-event-type
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* await updateEventType(context)(12345, { title: 'Updated Session Title' });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function updateEventType(context: CalcomContext): (eventTypeId: CalcomEventTypeId, input: CalcomUpdateEventTypeInput) => Promise<CalcomEventTypeResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Deletes an event type by ID.
|
|
77
|
+
*
|
|
78
|
+
* @see https://cal.com/docs/api-reference/v2/event-types/delete-an-event-type
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* await deleteEventType(context)(12345);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function deleteEventType(context: CalcomContext): (eventTypeId: CalcomEventTypeId) => Promise<CalcomEventTypeResponse>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type TimezoneString } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext } from './calcom.config';
|
|
3
|
+
import { type CalcomScheduleId, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export interface CalcomAvailabilityRule {
|
|
5
|
+
readonly days: string[];
|
|
6
|
+
readonly startTime: string;
|
|
7
|
+
readonly endTime: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CalcomSchedule {
|
|
10
|
+
readonly id: CalcomScheduleId;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly timeZone: TimezoneString;
|
|
13
|
+
readonly availability: CalcomAvailabilityRule[];
|
|
14
|
+
readonly isDefault: boolean;
|
|
15
|
+
readonly overrides: Record<string, CalcomAvailabilityRule[]>;
|
|
16
|
+
}
|
|
17
|
+
export interface CalcomGetSchedulesResponse {
|
|
18
|
+
readonly status: CalcomResponseStatus;
|
|
19
|
+
readonly data: CalcomSchedule[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves all schedules for the authenticated user, including availability rules and overrides.
|
|
23
|
+
*
|
|
24
|
+
* @see https://cal.com/docs/api-reference/v2/schedules/get-all-schedules
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const response = await getSchedules(context)();
|
|
29
|
+
* response.data.forEach(schedule => console.log(schedule.name, schedule.timeZone));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function getSchedules(context: CalcomContext): () => Promise<CalcomGetSchedulesResponse>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ISO8601DateString, type Maybe, type Minutes, type TimezoneString } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext, type CalcomPublicContext } from './calcom.config';
|
|
3
|
+
import { type CalcomEventTypeId, type CalcomEventTypeSlug, type CalcomUsername, type CalcomTeamSlug, type CalcomOrganizationSlug, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export interface CalcomGetAvailableSlotsInput {
|
|
5
|
+
readonly start: ISO8601DateString;
|
|
6
|
+
readonly end: ISO8601DateString;
|
|
7
|
+
readonly eventTypeId?: Maybe<CalcomEventTypeId>;
|
|
8
|
+
readonly eventTypeSlug?: Maybe<CalcomEventTypeSlug>;
|
|
9
|
+
readonly username?: Maybe<CalcomUsername>;
|
|
10
|
+
readonly teamSlug?: Maybe<CalcomTeamSlug>;
|
|
11
|
+
readonly organizationSlug?: Maybe<CalcomOrganizationSlug>;
|
|
12
|
+
readonly timeZone?: Maybe<TimezoneString>;
|
|
13
|
+
readonly duration?: Maybe<Minutes>;
|
|
14
|
+
readonly format?: Maybe<'range' | 'time'>;
|
|
15
|
+
}
|
|
16
|
+
export interface CalcomSlot {
|
|
17
|
+
readonly time: ISO8601DateString;
|
|
18
|
+
}
|
|
19
|
+
export interface CalcomGetAvailableSlotsResponse {
|
|
20
|
+
readonly status: CalcomResponseStatus;
|
|
21
|
+
readonly data: {
|
|
22
|
+
readonly slots: Record<string, CalcomSlot[]>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Queries available booking slots for a given event type within a date range.
|
|
27
|
+
* This endpoint is public and does not require authentication.
|
|
28
|
+
*
|
|
29
|
+
* Identify the event type by `eventTypeId`, or by `eventTypeSlug` + `username`/`teamSlug`.
|
|
30
|
+
*
|
|
31
|
+
* @see https://cal.com/docs/api-reference/v2/slots/get-available-time-slots-for-an-event-type
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const response = await getAvailableSlots(context)({
|
|
36
|
+
* start: '2026-03-17T00:00:00.000Z',
|
|
37
|
+
* end: '2026-03-24T00:00:00.000Z',
|
|
38
|
+
* eventTypeId: 12345
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* for (const [date, slots] of Object.entries(response.data.slots)) {
|
|
42
|
+
* console.log(date, slots.map(s => s.time));
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function getAvailableSlots(context: CalcomContext | CalcomPublicContext): (input: CalcomGetAvailableSlotsInput) => Promise<CalcomGetAvailableSlotsResponse>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type EmailAddress, type ISO8601DateString, type TimezoneString } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext } from './calcom.config';
|
|
3
|
+
import { type CalcomUserId, type CalcomUsername, type CalcomScheduleId, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export interface CalcomUser {
|
|
5
|
+
readonly id: CalcomUserId;
|
|
6
|
+
readonly email: EmailAddress;
|
|
7
|
+
readonly username: CalcomUsername | null;
|
|
8
|
+
readonly timeZone: TimezoneString;
|
|
9
|
+
readonly weekStart: string;
|
|
10
|
+
readonly createdDate: ISO8601DateString;
|
|
11
|
+
readonly timeFormat: number;
|
|
12
|
+
readonly defaultScheduleId: CalcomScheduleId | null;
|
|
13
|
+
}
|
|
14
|
+
export interface CalcomGetMeResponse {
|
|
15
|
+
readonly status: CalcomResponseStatus;
|
|
16
|
+
readonly data: CalcomUser;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the profile of the currently authenticated Cal.com user.
|
|
20
|
+
*
|
|
21
|
+
* @see https://cal.com/docs/api-reference/v2/me
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const response = await getMe(context)();
|
|
26
|
+
* console.log(response.data.email);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function getMe(context: CalcomContext): () => Promise<CalcomGetMeResponse>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type WebsiteUrl } from '@dereekb/util';
|
|
2
|
+
import { type CalcomContext } from './calcom.config';
|
|
3
|
+
import { type CalcomWebhookId, type CalcomResponseStatus } from '../calcom.type';
|
|
4
|
+
export type CalcomWebhookTrigger = 'BOOKING_CREATED' | 'BOOKING_CANCELLED' | 'BOOKING_RESCHEDULED' | 'BOOKING_REQUESTED' | 'BOOKING_REJECTED' | 'BOOKING_NO_SHOW_UPDATED' | 'BOOKING_PAYMENT_INITIATED' | 'BOOKING_PAID' | 'MEETING_STARTED' | 'MEETING_ENDED' | 'RECORDING_READY' | 'RECORDING_TRANSCRIPTION_GENERATED';
|
|
5
|
+
export interface CalcomWebhook {
|
|
6
|
+
readonly id: CalcomWebhookId;
|
|
7
|
+
readonly subscriberUrl: WebsiteUrl;
|
|
8
|
+
readonly triggers: CalcomWebhookTrigger[];
|
|
9
|
+
readonly active: boolean;
|
|
10
|
+
readonly payloadTemplate?: string | null;
|
|
11
|
+
readonly secret?: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface CalcomCreateWebhookInput {
|
|
14
|
+
readonly subscriberUrl: WebsiteUrl;
|
|
15
|
+
readonly triggers: CalcomWebhookTrigger[];
|
|
16
|
+
readonly active?: boolean;
|
|
17
|
+
readonly payloadTemplate?: string;
|
|
18
|
+
readonly secret?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CalcomUpdateWebhookInput {
|
|
21
|
+
readonly subscriberUrl?: WebsiteUrl;
|
|
22
|
+
readonly triggers?: CalcomWebhookTrigger[];
|
|
23
|
+
readonly active?: boolean;
|
|
24
|
+
readonly payloadTemplate?: string;
|
|
25
|
+
readonly secret?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CalcomWebhookResponse {
|
|
28
|
+
readonly status: CalcomResponseStatus;
|
|
29
|
+
readonly data: CalcomWebhook;
|
|
30
|
+
}
|
|
31
|
+
export interface CalcomGetWebhooksResponse {
|
|
32
|
+
readonly status: CalcomResponseStatus;
|
|
33
|
+
readonly data: CalcomWebhook[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a webhook subscription for the authenticated user. Webhooks notify your app
|
|
37
|
+
* when specified events occur (e.g., bookings created, cancelled, rescheduled).
|
|
38
|
+
*
|
|
39
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/create-a-webhook
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const response = await createWebhook(context)({
|
|
44
|
+
* subscriberUrl: 'https://example.com/webhook/calcom',
|
|
45
|
+
* triggers: ['BOOKING_CREATED', 'BOOKING_CANCELLED'],
|
|
46
|
+
* active: true
|
|
47
|
+
* });
|
|
48
|
+
* console.log(response.data.id);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function createWebhook(context: CalcomContext): (input: CalcomCreateWebhookInput) => Promise<CalcomWebhookResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves all webhooks for the authenticated user.
|
|
54
|
+
*
|
|
55
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/get-all-webhooks
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const response = await getWebhooks(context)();
|
|
60
|
+
* response.data.forEach(wh => console.log(wh.subscriberUrl, wh.triggers));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function getWebhooks(context: CalcomContext): () => Promise<CalcomGetWebhooksResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves a specific webhook by ID.
|
|
66
|
+
*
|
|
67
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/get-a-webhook
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const response = await getWebhook(context)(42);
|
|
72
|
+
* console.log(response.data.subscriberUrl);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function getWebhook(context: CalcomContext): (webhookId: CalcomWebhookId) => Promise<CalcomWebhookResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Updates an existing webhook by ID.
|
|
78
|
+
*
|
|
79
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/update-a-webhook
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* await updateWebhook(context)(42, { active: false });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function updateWebhook(context: CalcomContext): (webhookId: CalcomWebhookId, input: CalcomUpdateWebhookInput) => Promise<CalcomWebhookResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* Deletes a webhook by ID.
|
|
89
|
+
*
|
|
90
|
+
* @see https://cal.com/docs/api-reference/v2/webhooks/delete-a-webhook
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* await deleteWebhook(context)(42);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function deleteWebhook(context: CalcomContext): (webhookId: CalcomWebhookId) => Promise<CalcomWebhookResponse>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type FactoryWithRequiredInput, type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type ConfiguredFetch, type FetchJsonFunction } from '@dereekb/util/fetch';
|
|
3
|
+
import { type CalcomConfig, type CalcomRefreshToken } from '../calcom.config';
|
|
4
|
+
import { type CalcomAccessTokenCache, type CalcomAccessTokenStringFactory } from '../oauth/oauth';
|
|
5
|
+
import { type CalcomRateLimiterRef } from '../calcom.limit';
|
|
6
|
+
export interface CalcomFetchFactoryInput {
|
|
7
|
+
readonly calcomAccessTokenStringFactory: CalcomAccessTokenStringFactory;
|
|
8
|
+
}
|
|
9
|
+
export type CalcomFetchFactory = (input: CalcomFetchFactoryInput) => ConfiguredFetch;
|
|
10
|
+
/**
|
|
11
|
+
* A calcom context that can send requests to the Cal.com API.
|
|
12
|
+
*/
|
|
13
|
+
export interface CalcomContext extends CalcomRateLimiterRef {
|
|
14
|
+
/**
|
|
15
|
+
* Type of context this is.
|
|
16
|
+
*/
|
|
17
|
+
readonly type: 'server' | 'user';
|
|
18
|
+
/**
|
|
19
|
+
* Performs a fetch.
|
|
20
|
+
*/
|
|
21
|
+
readonly fetch: ConfiguredFetch;
|
|
22
|
+
/**
|
|
23
|
+
* Performs a json fetch.
|
|
24
|
+
*/
|
|
25
|
+
readonly fetchJson: FetchJsonFunction;
|
|
26
|
+
}
|
|
27
|
+
export interface CalcomUserContext extends CalcomContext {
|
|
28
|
+
readonly type: 'user';
|
|
29
|
+
readonly calcomServerContext: CalcomServerContext;
|
|
30
|
+
readonly userFetch: ConfiguredFetch;
|
|
31
|
+
readonly userFetchJson: FetchJsonFunction;
|
|
32
|
+
}
|
|
33
|
+
export interface CalcomUserContextFactoryInput {
|
|
34
|
+
/**
|
|
35
|
+
* The user's refresh token.
|
|
36
|
+
*/
|
|
37
|
+
readonly refreshToken: CalcomRefreshToken;
|
|
38
|
+
/**
|
|
39
|
+
* Optional cache to use for the user's access token.
|
|
40
|
+
*
|
|
41
|
+
* The cache should only be configured for the user that owns the refresh token.
|
|
42
|
+
*/
|
|
43
|
+
readonly accessTokenCache?: Maybe<CalcomAccessTokenCache>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a CalcomUserContext from the input.
|
|
47
|
+
*/
|
|
48
|
+
export type CalcomUserContextFactory = FactoryWithRequiredInput<CalcomUserContext, CalcomUserContextFactoryInput>;
|
|
49
|
+
/**
|
|
50
|
+
* Context for making public (unauthenticated) requests to the Cal.com API.
|
|
51
|
+
*/
|
|
52
|
+
export interface CalcomPublicContext {
|
|
53
|
+
readonly fetch: ConfiguredFetch;
|
|
54
|
+
readonly fetchJson: FetchJsonFunction;
|
|
55
|
+
}
|
|
56
|
+
export interface CalcomServerContext extends CalcomContext {
|
|
57
|
+
readonly type: 'server';
|
|
58
|
+
readonly serverFetch: ConfiguredFetch;
|
|
59
|
+
readonly serverFetchJson: FetchJsonFunction;
|
|
60
|
+
readonly makeUserContext: CalcomUserContextFactory;
|
|
61
|
+
readonly makePublicContext: () => CalcomPublicContext;
|
|
62
|
+
readonly config: CalcomConfig;
|
|
63
|
+
}
|
|
64
|
+
export interface CalcomServerContextRef {
|
|
65
|
+
readonly calcomServerContext: CalcomServerContext;
|
|
66
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FetchResponseError } from '@dereekb/util/fetch';
|
|
2
|
+
import { type CalcomServerErrorData, type ParsedCalcomServerError } from '../calcom.error.api';
|
|
3
|
+
export declare const logCalcomErrorToConsole: import("..").LogCalcomServerErrorFunction;
|
|
4
|
+
export declare function parseCalcomApiError(responseError: FetchResponseError): Promise<ParsedCalcomServerError>;
|
|
5
|
+
export declare function parseCalcomApiServerErrorResponseData(calcomServerError: CalcomServerErrorData, responseError: FetchResponseError): ParsedCalcomServerError;
|
|
6
|
+
export declare const handleCalcomErrorFetch: import("..").HandleCalcomErrorFetchFactory;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type CalcomServerContextRef, type CalcomFetchFactory } from './calcom.config';
|
|
2
|
+
import { type LogCalcomServerErrorFunction } from '../calcom.error.api';
|
|
3
|
+
import { type CalcomOAuthContextRef } from '../oauth/oauth.config';
|
|
4
|
+
import { type CalcomRateLimitedFetchHandlerConfig } from '../calcom.limit';
|
|
5
|
+
import { type Maybe } from '@dereekb/util';
|
|
6
|
+
import { type CalcomConfig } from '../calcom.config';
|
|
7
|
+
export type Calcom = CalcomServerContextRef;
|
|
8
|
+
export interface CalcomFactoryConfig extends CalcomOAuthContextRef {
|
|
9
|
+
/**
|
|
10
|
+
* Custom CalcomRateLimitedFetchHandlerConfig
|
|
11
|
+
*/
|
|
12
|
+
readonly rateLimiterConfig?: Maybe<CalcomRateLimitedFetchHandlerConfig>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new fetch instance to use when making calls.
|
|
15
|
+
*/
|
|
16
|
+
readonly fetchFactory?: CalcomFetchFactory;
|
|
17
|
+
/**
|
|
18
|
+
* Custom log error function.
|
|
19
|
+
*/
|
|
20
|
+
readonly logCalcomServerErrorFunction?: LogCalcomServerErrorFunction;
|
|
21
|
+
}
|
|
22
|
+
export type CalcomFactory = (config: CalcomConfig) => Calcom;
|
|
23
|
+
export declare function calcomFactory(factoryConfig: CalcomFactoryConfig): CalcomFactory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './calcom.config';
|
|
2
|
+
export * from './calcom.factory';
|
|
3
|
+
export * from './calcom.api.user';
|
|
4
|
+
export * from './calcom.api.schedule';
|
|
5
|
+
export * from './calcom.api.slot';
|
|
6
|
+
export * from './calcom.api.booking';
|
|
7
|
+
export * from './calcom.api.eventtype';
|
|
8
|
+
export * from './calcom.api.calendar';
|
|
9
|
+
export * from './calcom.api.webhook';
|
|
10
|
+
export * from './calcom.error.api';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cal.com API URL.
|
|
3
|
+
*/
|
|
4
|
+
export declare const CALCOM_API_URL = "https://api.cal.com/v2";
|
|
5
|
+
/**
|
|
6
|
+
* OAuth Client Id
|
|
7
|
+
*/
|
|
8
|
+
export type CalcomOAuthClientId = string;
|
|
9
|
+
/**
|
|
10
|
+
* OAuth Client Secret
|
|
11
|
+
*/
|
|
12
|
+
export type CalcomOAuthClientSecret = string;
|
|
13
|
+
export interface CalcomAuthClientIdAndSecretPair {
|
|
14
|
+
readonly clientId: CalcomOAuthClientId;
|
|
15
|
+
readonly clientSecret: CalcomOAuthClientSecret;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refresh token used to retrieve access tokens for performing API calls.
|
|
19
|
+
*
|
|
20
|
+
* Cal.com rotates refresh tokens on each use, so the latest value must always be persisted.
|
|
21
|
+
*/
|
|
22
|
+
export type CalcomRefreshToken = string;
|
|
23
|
+
/**
|
|
24
|
+
* Cal.com API key, prefixed with `cal_` (test) or `cal_live_` (production).
|
|
25
|
+
*
|
|
26
|
+
* Created in Cal.com user settings > Security. Acts as the user who created it.
|
|
27
|
+
* Does not expire and requires no refresh.
|
|
28
|
+
*/
|
|
29
|
+
export type CalcomApiKey = string;
|
|
30
|
+
export interface CalcomConfig {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Secret used for validating Cal.com webhooks.
|
|
34
|
+
*/
|
|
35
|
+
export type CalcomWebhookSecret = string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type Maybe } from '@dereekb/util';
|
|
2
|
+
import { type ConfiguredFetch, type FetchRequestFactoryError, FetchResponseError } from '@dereekb/util/fetch';
|
|
3
|
+
import { BaseError } from 'make-error';
|
|
4
|
+
/**
|
|
5
|
+
* Cal.com server error codes are numbers or strings.
|
|
6
|
+
*/
|
|
7
|
+
export type CalcomServerErrorCode = string | number;
|
|
8
|
+
/**
|
|
9
|
+
* Cal.com Server Error Data
|
|
10
|
+
*
|
|
11
|
+
* Always contains a code and message. Details and status are optional.
|
|
12
|
+
*/
|
|
13
|
+
export interface CalcomServerErrorData<T = unknown> {
|
|
14
|
+
readonly code: CalcomServerErrorCode;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly details?: T;
|
|
17
|
+
/**
|
|
18
|
+
* Is sometimes present on some error responses.
|
|
19
|
+
*/
|
|
20
|
+
readonly status?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Cal.com Server Error
|
|
24
|
+
*/
|
|
25
|
+
export declare class CalcomServerError<D extends CalcomServerErrorData = CalcomServerErrorData> extends BaseError {
|
|
26
|
+
readonly error: D;
|
|
27
|
+
get code(): CalcomServerErrorCode;
|
|
28
|
+
constructor(error: D);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Cal.com Server Error that includes the FetchResponseError
|
|
32
|
+
*/
|
|
33
|
+
export declare class CalcomServerFetchResponseError<D extends CalcomServerErrorData = CalcomServerErrorData> extends CalcomServerError<D> {
|
|
34
|
+
readonly data: D;
|
|
35
|
+
readonly responseError: FetchResponseError;
|
|
36
|
+
constructor(data: D, responseError: FetchResponseError);
|
|
37
|
+
}
|
|
38
|
+
export type LogCalcomServerErrorFunction = (error: FetchRequestFactoryError | CalcomServerError | CalcomServerFetchResponseError) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a logCalcomServerErrorFunction that logs the error to console.
|
|
41
|
+
*
|
|
42
|
+
* @param calcomApiNamePrefix Prefix to use when logging. I.E. CalcomError, etc.
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function logCalcomServerErrorFunction(calcomApiNamePrefix: string): LogCalcomServerErrorFunction;
|
|
46
|
+
/**
|
|
47
|
+
* Wraps a ConfiguredFetch to support handling errors returned by fetch.
|
|
48
|
+
*/
|
|
49
|
+
export type HandleCalcomErrorFetchFactory = (fetch: ConfiguredFetch, logError?: LogCalcomServerErrorFunction) => ConfiguredFetch;
|
|
50
|
+
export type ParsedCalcomServerError = FetchRequestFactoryError | CalcomServerError | undefined;
|
|
51
|
+
export type ParseCalcomFetchResponseErrorFunction = (responseError: FetchResponseError) => Promise<ParsedCalcomServerError>;
|
|
52
|
+
/**
|
|
53
|
+
* Wraps a ConfiguredFetch to support handling errors returned by fetch.
|
|
54
|
+
*/
|
|
55
|
+
export declare function handleCalcomErrorFetchFactory(parseCalcomError: ParseCalcomFetchResponseErrorFunction, defaultLogError: LogCalcomServerErrorFunction): HandleCalcomErrorFetchFactory;
|
|
56
|
+
/**
|
|
57
|
+
* The status code that indicates too many requests have been made.
|
|
58
|
+
*/
|
|
59
|
+
export declare const CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE = 429;
|
|
60
|
+
export declare const CALCOM_RATE_LIMIT_LIMIT_HEADER = "X-RateLimit-Limit";
|
|
61
|
+
export declare const CALCOM_RATE_LIMIT_REMAINING_HEADER = "X-RateLimit-Remaining";
|
|
62
|
+
export declare const CALCOM_RATE_LIMIT_RESET_HEADER = "X-RateLimit-Reset";
|
|
63
|
+
export declare const DEFAULT_CALCOM_API_RATE_LIMIT = 100;
|
|
64
|
+
export declare const DEFAULT_CALCOM_API_RATE_LIMIT_RESET_PERIOD: number;
|
|
65
|
+
export interface CalcomRateLimitHeaderDetails {
|
|
66
|
+
/**
|
|
67
|
+
* Total limit in a given period.
|
|
68
|
+
*/
|
|
69
|
+
readonly limit?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Total number of remaining allowed requests.
|
|
72
|
+
*/
|
|
73
|
+
readonly remaining?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The time at which the rate limit will reset.
|
|
76
|
+
*/
|
|
77
|
+
readonly resetAt?: Date;
|
|
78
|
+
}
|
|
79
|
+
export declare function calcomRateLimitHeaderDetails(headers: Headers): Maybe<CalcomRateLimitHeaderDetails>;
|
|
80
|
+
export declare class CalcomTooManyRequestsError extends CalcomServerFetchResponseError {
|
|
81
|
+
get headerDetails(): Maybe<CalcomRateLimitHeaderDetails>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Function that parses/transforms a CalcomServerErrorData into a general CalcomServerError or other known error type.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseCalcomServerErrorData(calcomServerError: CalcomServerErrorData, responseError: FetchResponseError): CalcomServerFetchResponseError | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Maybe, type Milliseconds, type PromiseOrValue, type ResetPeriodPromiseRateLimiter } from '@dereekb/util';
|
|
2
|
+
import { type FetchResponseError, type RateLimitedFetchHandler } from '@dereekb/util/fetch';
|
|
3
|
+
import { type CalcomRateLimitHeaderDetails } from './calcom.error.api';
|
|
4
|
+
export interface CalcomRateLimiterRef {
|
|
5
|
+
readonly calcomRateLimiter: ResetPeriodPromiseRateLimiter;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Function to execute when too many requests is reached.
|
|
9
|
+
*
|
|
10
|
+
* Typically used for logging of some sort. Thrown errors are ignored.
|
|
11
|
+
*/
|
|
12
|
+
export type CalcomRateLimitedTooManyRequestsLogFunction = (headers: CalcomRateLimitHeaderDetails, response: Response, fetchResponseError?: FetchResponseError) => PromiseOrValue<void>;
|
|
13
|
+
export declare const DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION: (headers: CalcomRateLimitHeaderDetails) => void;
|
|
14
|
+
export interface CalcomRateLimitedFetchHandlerConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Custom max rate limit.
|
|
17
|
+
*
|
|
18
|
+
* Cal.com allows 120 req/min. We default to 100 as a conservative limit.
|
|
19
|
+
*/
|
|
20
|
+
readonly maxRateLimit?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Custom reset period for the rate limiter.
|
|
23
|
+
*
|
|
24
|
+
* Defaults to 1 minute in milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
readonly resetPeriod?: Milliseconds;
|
|
27
|
+
/**
|
|
28
|
+
* Optional function to execute when too many requests is reached.
|
|
29
|
+
*
|
|
30
|
+
* Defaults to the default logging function, unless false is passed.
|
|
31
|
+
*/
|
|
32
|
+
readonly onTooManyRequests?: CalcomRateLimitedTooManyRequestsLogFunction | false;
|
|
33
|
+
}
|
|
34
|
+
export type CalcomRateLimitedFetchHandler = RateLimitedFetchHandler<ResetPeriodPromiseRateLimiter>;
|
|
35
|
+
export declare function calcomRateLimitedFetchHandler(config?: Maybe<CalcomRateLimitedFetchHandlerConfig>): CalcomRateLimitedFetchHandler;
|