@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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/index.cjs.default.js +1 -0
  3. package/index.cjs.js +2202 -0
  4. package/index.cjs.mjs +2 -0
  5. package/index.d.ts +1 -0
  6. package/index.esm.js +2141 -0
  7. package/nestjs/index.cjs.default.js +1 -0
  8. package/nestjs/index.cjs.js +1970 -0
  9. package/nestjs/index.cjs.mjs +2 -0
  10. package/nestjs/index.d.ts +1 -0
  11. package/nestjs/index.esm.js +1938 -0
  12. package/nestjs/package.json +28 -0
  13. package/nestjs/src/index.d.ts +1 -0
  14. package/nestjs/src/lib/calcom/calcom.api.d.ts +160 -0
  15. package/nestjs/src/lib/calcom/calcom.config.d.ts +10 -0
  16. package/nestjs/src/lib/calcom/calcom.module.d.ts +18 -0
  17. package/nestjs/src/lib/calcom/index.d.ts +3 -0
  18. package/nestjs/src/lib/index.d.ts +3 -0
  19. package/nestjs/src/lib/oauth/index.d.ts +4 -0
  20. package/nestjs/src/lib/oauth/oauth.api.d.ts +25 -0
  21. package/nestjs/src/lib/oauth/oauth.config.d.ts +22 -0
  22. package/nestjs/src/lib/oauth/oauth.module.d.ts +24 -0
  23. package/nestjs/src/lib/oauth/oauth.service.d.ts +66 -0
  24. package/nestjs/src/lib/webhook/index.d.ts +7 -0
  25. package/nestjs/src/lib/webhook/webhook.calcom.config.d.ts +11 -0
  26. package/nestjs/src/lib/webhook/webhook.calcom.controller.d.ts +8 -0
  27. package/nestjs/src/lib/webhook/webhook.calcom.d.ts +16 -0
  28. package/nestjs/src/lib/webhook/webhook.calcom.module.d.ts +20 -0
  29. package/nestjs/src/lib/webhook/webhook.calcom.service.d.ts +21 -0
  30. package/nestjs/src/lib/webhook/webhook.calcom.type.d.ts +33 -0
  31. package/nestjs/src/lib/webhook/webhook.calcom.verify.d.ts +16 -0
  32. package/package.json +34 -0
  33. package/src/index.d.ts +1 -0
  34. package/src/lib/calcom/calcom.api.booking.d.ts +86 -0
  35. package/src/lib/calcom/calcom.api.calendar.d.ts +82 -0
  36. package/src/lib/calcom/calcom.api.eventtype.d.ts +85 -0
  37. package/src/lib/calcom/calcom.api.schedule.d.ts +32 -0
  38. package/src/lib/calcom/calcom.api.slot.d.ts +46 -0
  39. package/src/lib/calcom/calcom.api.user.d.ts +29 -0
  40. package/src/lib/calcom/calcom.api.webhook.d.ts +97 -0
  41. package/src/lib/calcom/calcom.config.d.ts +66 -0
  42. package/src/lib/calcom/calcom.error.api.d.ts +6 -0
  43. package/src/lib/calcom/calcom.factory.d.ts +23 -0
  44. package/src/lib/calcom/index.d.ts +10 -0
  45. package/src/lib/calcom.config.d.ts +35 -0
  46. package/src/lib/calcom.error.api.d.ts +86 -0
  47. package/src/lib/calcom.limit.d.ts +35 -0
  48. package/src/lib/calcom.type.d.ts +70 -0
  49. package/src/lib/index.d.ts +7 -0
  50. package/src/lib/oauth/index.d.ts +5 -0
  51. package/src/lib/oauth/oauth.api.d.ts +54 -0
  52. package/src/lib/oauth/oauth.config.d.ts +53 -0
  53. package/src/lib/oauth/oauth.d.ts +64 -0
  54. package/src/lib/oauth/oauth.error.api.d.ts +26 -0
  55. package/src/lib/oauth/oauth.factory.d.ts +31 -0
  56. package/src/lib/shared/calcom.api-version.d.ts +17 -0
  57. package/src/lib/shared/index.d.ts +1 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@dereekb/calcom/nestjs",
3
+ "version": "13.4.0",
4
+ "peerDependencies": {
5
+ "@dereekb/nestjs": "13.4.0",
6
+ "@dereekb/util": "13.4.0",
7
+ "@dereekb/calcom": "13.4.0",
8
+ "@nestjs/common": "^11.1.16",
9
+ "@nestjs/config": "^4.0.3",
10
+ "express": "^5.0.0"
11
+ },
12
+ "devDependencies": {
13
+ "@nestjs/testing": "^11.1.14",
14
+ "date-fns": "^4.0.0"
15
+ },
16
+ "exports": {
17
+ "./package.json": "./package.json",
18
+ ".": {
19
+ "module": "./index.esm.js",
20
+ "types": "./index.d.ts",
21
+ "import": "./index.cjs.mjs",
22
+ "default": "./index.cjs.js"
23
+ }
24
+ },
25
+ "module": "./index.esm.js",
26
+ "main": "./index.cjs.js",
27
+ "types": "./index.d.ts"
28
+ }
@@ -0,0 +1 @@
1
+ export * from './lib';
@@ -0,0 +1,160 @@
1
+ import { CalcomServiceConfig } from './calcom.config';
2
+ import { type Calcom, type CalcomContext, type CalcomServerContext, type CalcomUserContext, type CalcomUserContextFactoryInput } from '@dereekb/calcom';
3
+ import { CalcomOAuthApi } from '../oauth';
4
+ /**
5
+ * Injectable NestJS service that provides access to the Cal.com API.
6
+ *
7
+ * Use {@link serverContextInstance} to access API functions via the server context,
8
+ * or {@link makeUserContextInstance} to create per-mentor API instances.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Server context (API key or server OAuth)
13
+ * const instance = calcomApi.serverContextInstance;
14
+ * const me = await instance.getMe();
15
+ *
16
+ * // Per-mentor context
17
+ * const mentorInstance = calcomApi.makeUserContextInstance({ refreshToken: mentor.calcomRefreshToken });
18
+ * const eventTypes = await mentorInstance.getEventTypes();
19
+ *
20
+ * // Public slot query (no auth)
21
+ * const slots = await calcomApi.getAvailableSlots({ start: '...', end: '...', eventTypeId: 123 });
22
+ * ```
23
+ */
24
+ export declare class CalcomApi {
25
+ readonly config: CalcomServiceConfig;
26
+ readonly calcomOAuthApi: CalcomOAuthApi;
27
+ readonly calcom: Calcom;
28
+ private readonly _serverInstance;
29
+ private readonly _publicContext;
30
+ get calcomServerContext(): CalcomServerContext;
31
+ constructor(config: CalcomServiceConfig, calcomOAuthApi: CalcomOAuthApi);
32
+ /**
33
+ * Returns the cached {@link CalcomApiContextInstance} for the server context.
34
+ * All API functions are available through this instance.
35
+ */
36
+ get serverContextInstance(): CalcomApiContextInstance;
37
+ /** Configured pass-through for {@link getAvailableSlots} using the public (unauthenticated) context. */
38
+ get getAvailableSlots(): (input: import("@dereekb/calcom").CalcomGetAvailableSlotsInput) => Promise<import("@dereekb/calcom").CalcomGetAvailableSlotsResponse>;
39
+ /**
40
+ * Creates a {@link CalcomApiContextInstance} for a specific user using their OAuth refresh token.
41
+ * The returned instance has all API functions scoped to that user's account.
42
+ *
43
+ * When no explicit `accessTokenCache` is provided, a per-user cache is automatically
44
+ * resolved from the cache service using an md5 hash of the refresh token as the key.
45
+ * This ensures tokens persist across requests and server restarts without collisions.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * // Automatic per-user caching (recommended):
50
+ * const userInstance = calcomApi.makeUserContextInstance({
51
+ * refreshToken: user.calcomRefreshToken
52
+ * });
53
+ *
54
+ * // With explicit cache override:
55
+ * const userInstance = calcomApi.makeUserContextInstance({
56
+ * refreshToken: user.calcomRefreshToken,
57
+ * accessTokenCache: customCache
58
+ * });
59
+ * ```
60
+ */
61
+ makeUserContextInstance(input: CalcomUserContextFactoryInput): CalcomApiContextInstance;
62
+ /**
63
+ * Creates a {@link CalcomApiContextInstance} from any {@link CalcomContext}.
64
+ */
65
+ makeContextInstance(context: CalcomContext): CalcomApiContextInstance;
66
+ /**
67
+ * Creates a raw {@link CalcomUserContext} from a refresh token, without wrapping in a {@link CalcomApiContextInstance}.
68
+ * Prefer {@link makeUserContextInstance} unless you need direct context access.
69
+ */
70
+ makeUserContext(input: CalcomUserContextFactoryInput): CalcomUserContext;
71
+ }
72
+ /**
73
+ * Wraps a {@link CalcomContext} (server or user) and exposes all authenticated Cal.com API
74
+ * functions bound to that context. Each getter delegates to the corresponding function
75
+ * from `@dereekb/calcom`.
76
+ *
77
+ * Access the parent {@link CalcomApi} via {@link calcomApi} for public endpoints
78
+ * (e.g., `calcomApi.getAvailableSlots`) or to create additional context instances.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const instance = calcomApi.serverContextInstance;
83
+ *
84
+ * // Authenticated API calls
85
+ * const me = await instance.getMe();
86
+ * const schedules = await instance.getSchedules();
87
+ *
88
+ * // Access public endpoints via parent
89
+ * const slots = await instance.calcomApi.getAvailableSlots({ start: '...', end: '...', eventTypeId: 123 });
90
+ * ```
91
+ */
92
+ export declare class CalcomApiContextInstance {
93
+ readonly calcomApi: CalcomApi;
94
+ readonly context: CalcomContext;
95
+ constructor(calcomApi: CalcomApi, context: CalcomContext);
96
+ /**
97
+ * Configured pass-through for {@link getMe}.
98
+ */
99
+ get getMe(): () => Promise<import("@dereekb/calcom").CalcomGetMeResponse>;
100
+ /**
101
+ * Configured pass-through for {@link getSchedules}.
102
+ */
103
+ get getSchedules(): () => Promise<import("@dereekb/calcom").CalcomGetSchedulesResponse>;
104
+ /**
105
+ * Configured pass-through for {@link createBooking}.
106
+ */
107
+ get createBooking(): (input: import("@dereekb/calcom").CalcomCreateBookingInput) => Promise<import("@dereekb/calcom").CalcomCreateBookingResponse>;
108
+ /**
109
+ * Configured pass-through for {@link getBooking}.
110
+ */
111
+ get getBooking(): (uid: import("@dereekb/calcom").CalcomBookingUid) => Promise<import("@dereekb/calcom").CalcomGetBookingResponse>;
112
+ /**
113
+ * Configured pass-through for {@link cancelBooking}.
114
+ */
115
+ get cancelBooking(): (input: import("@dereekb/calcom").CalcomCancelBookingInput) => Promise<import("@dereekb/calcom").CalcomCancelBookingResponse>;
116
+ /**
117
+ * Configured pass-through for {@link getEventTypes}.
118
+ */
119
+ get getEventTypes(): () => Promise<import("@dereekb/calcom").CalcomGetEventTypesResponse>;
120
+ /**
121
+ * Configured pass-through for {@link createEventType}.
122
+ */
123
+ get createEventType(): (input: import("@dereekb/calcom").CalcomCreateEventTypeInput) => Promise<import("@dereekb/calcom").CalcomEventTypeResponse>;
124
+ /**
125
+ * Configured pass-through for {@link updateEventType}.
126
+ */
127
+ get updateEventType(): (eventTypeId: import("@dereekb/calcom").CalcomEventTypeId, input: import("@dereekb/calcom").CalcomUpdateEventTypeInput) => Promise<import("@dereekb/calcom").CalcomEventTypeResponse>;
128
+ /**
129
+ * Configured pass-through for {@link deleteEventType}.
130
+ */
131
+ get deleteEventType(): (eventTypeId: import("@dereekb/calcom").CalcomEventTypeId) => Promise<import("@dereekb/calcom").CalcomEventTypeResponse>;
132
+ /**
133
+ * Configured pass-through for {@link getCalendars}.
134
+ */
135
+ get getCalendars(): () => Promise<import("@dereekb/calcom").CalcomGetCalendarsResponse>;
136
+ /**
137
+ * Configured pass-through for {@link getBusyTimes}.
138
+ */
139
+ get getBusyTimes(): (input: import("@dereekb/calcom").CalcomGetBusyTimesInput) => Promise<import("@dereekb/calcom").CalcomGetBusyTimesResponse>;
140
+ /**
141
+ * Configured pass-through for {@link createWebhook}.
142
+ */
143
+ get createWebhook(): (input: import("@dereekb/calcom").CalcomCreateWebhookInput) => Promise<import("@dereekb/calcom").CalcomWebhookResponse>;
144
+ /**
145
+ * Configured pass-through for {@link getWebhooks}.
146
+ */
147
+ get getWebhooks(): () => Promise<import("@dereekb/calcom").CalcomGetWebhooksResponse>;
148
+ /**
149
+ * Configured pass-through for {@link getWebhook}.
150
+ */
151
+ get getWebhook(): (webhookId: import("@dereekb/calcom").CalcomWebhookId) => Promise<import("@dereekb/calcom").CalcomWebhookResponse>;
152
+ /**
153
+ * Configured pass-through for {@link updateWebhook}.
154
+ */
155
+ get updateWebhook(): (webhookId: import("@dereekb/calcom").CalcomWebhookId, input: import("@dereekb/calcom").CalcomUpdateWebhookInput) => Promise<import("@dereekb/calcom").CalcomWebhookResponse>;
156
+ /**
157
+ * Configured pass-through for {@link deleteWebhook}.
158
+ */
159
+ get deleteWebhook(): (webhookId: import("@dereekb/calcom").CalcomWebhookId) => Promise<import("@dereekb/calcom").CalcomWebhookResponse>;
160
+ }
@@ -0,0 +1,10 @@
1
+ import { type CalcomConfig, type CalcomFactoryConfig } from '@dereekb/calcom';
2
+ export type CalcomServiceApiConfig = CalcomConfig & {};
3
+ /**
4
+ * Configuration for CalcomService
5
+ */
6
+ export declare abstract class CalcomServiceConfig {
7
+ readonly calcom: CalcomServiceApiConfig;
8
+ readonly factoryConfig?: CalcomFactoryConfig;
9
+ static assertValidConfig(_config: CalcomServiceConfig): void;
10
+ }
@@ -0,0 +1,18 @@
1
+ import { type ModuleMetadata } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { CalcomServiceConfig } from './calcom.config';
4
+ import { type Maybe } from '@dereekb/util';
5
+ export declare function calcomServiceConfigFactory(_configService: ConfigService): CalcomServiceConfig;
6
+ export interface ProvideAppCalcomMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
7
+ /**
8
+ * The CalcomModule requires the following dependencies in order to initialize properly:
9
+ * - CalcomOAuthApi
10
+ *
11
+ * This module declaration makes it easier to import a module that exports those dependencies.
12
+ */
13
+ readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
14
+ }
15
+ /**
16
+ * Convenience function used to generate ModuleMetadata for an app's CalcomModule.
17
+ */
18
+ export declare function appCalcomModuleMetadata(config: ProvideAppCalcomMetadataConfig): ModuleMetadata;
@@ -0,0 +1,3 @@
1
+ export * from './calcom.api';
2
+ export * from './calcom.config';
3
+ export * from './calcom.module';
@@ -0,0 +1,3 @@
1
+ export * from './oauth';
2
+ export * from './calcom';
3
+ export * from './webhook';
@@ -0,0 +1,4 @@
1
+ export * from './oauth.api';
2
+ export * from './oauth.config';
3
+ export * from './oauth.module';
4
+ export * from './oauth.service';
@@ -0,0 +1,25 @@
1
+ import { type CalcomAccessTokenCache, type CalcomOAuth, type CalcomOAuthContext, type CalcomRefreshToken } from '@dereekb/calcom';
2
+ import { type Maybe } from '@dereekb/util';
3
+ import { CalcomOAuthServiceConfig } from './oauth.config';
4
+ import { CalcomOAuthAccessTokenCacheService } from './oauth.service';
5
+ export declare class CalcomOAuthApi {
6
+ readonly config: CalcomOAuthServiceConfig;
7
+ readonly cacheService: CalcomOAuthAccessTokenCacheService;
8
+ readonly calcomOAuth: CalcomOAuth;
9
+ get oauthContext(): CalcomOAuthContext;
10
+ constructor(config: CalcomOAuthServiceConfig, cacheService: CalcomOAuthAccessTokenCacheService);
11
+ /** Configured pass-through for {@link exchangeAuthorizationCode}. */
12
+ get exchangeAuthorizationCode(): (input: import("@dereekb/calcom").CalcomOAuthExchangeAuthorizationCodeInput) => Promise<import("@dereekb/calcom").CalcomOAuthTokenResponse>;
13
+ /**
14
+ * Retrieves an access token for a specific user using their refresh token.
15
+ */
16
+ userAccessToken(input: {
17
+ refreshToken: string;
18
+ userAccessTokenCache?: Maybe<CalcomAccessTokenCache>;
19
+ }): Promise<import("@dereekb/calcom").CalcomAccessToken>;
20
+ /**
21
+ * Returns a per-user CalcomAccessTokenCache derived from the refresh token (md5 hashed as the file key).
22
+ * Returns undefined if the cache service does not support per-user caching.
23
+ */
24
+ cacheForRefreshToken(refreshToken: CalcomRefreshToken): Maybe<CalcomAccessTokenCache>;
25
+ }
@@ -0,0 +1,22 @@
1
+ import { type CalcomOAuthFactoryConfig } from '@dereekb/calcom';
2
+ import { type ConfigService } from '@nestjs/config';
3
+ export declare const CALCOM_SERVICE_NAME = "calcom";
4
+ export declare const CALCOM_CLIENT_ID_CONFIG_KEY = "CALCOM_CLIENT_ID";
5
+ export declare const CALCOM_CLIENT_SECRET_CONFIG_KEY = "CALCOM_CLIENT_SECRET";
6
+ export declare const CALCOM_REFRESH_TOKEN_CONFIG_KEY = "CALCOM_REFRESH_TOKEN";
7
+ export declare const CALCOM_API_KEY_CONFIG_KEY = "CALCOM_API_KEY";
8
+ export interface CalcomOAuthServiceApiConfig {
9
+ readonly clientId?: string;
10
+ readonly clientSecret?: string;
11
+ readonly refreshToken?: string;
12
+ readonly apiKey?: string;
13
+ }
14
+ /**
15
+ * Configuration for CalcomOAuthService
16
+ */
17
+ export declare abstract class CalcomOAuthServiceConfig {
18
+ readonly calcomOAuth: CalcomOAuthServiceApiConfig;
19
+ readonly factoryConfig?: CalcomOAuthFactoryConfig;
20
+ static assertValidConfig(config: CalcomOAuthServiceConfig): void;
21
+ }
22
+ export declare function calcomOAuthServiceConfigFactory(configService: ConfigService): CalcomOAuthServiceConfig;
@@ -0,0 +1,24 @@
1
+ import { type ModuleMetadata } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { CalcomOAuthServiceConfig } from './oauth.config';
4
+ import { type Maybe } from '@dereekb/util';
5
+ export type CalcomOAuthServiceConfigFactory = (configService: ConfigService) => CalcomOAuthServiceConfig;
6
+ export interface ProvideAppCalcomOAuthMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
7
+ /**
8
+ * The CalcomOAuthModule requires the following dependencies in order to initialize properly:
9
+ * - CalcomOAuthAccessTokenCacheService
10
+ *
11
+ * This module declaration makes it easier to import a module that exports those dependencies.
12
+ */
13
+ readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
14
+ /**
15
+ * Optional override for the CalcomOAuthServiceConfigFactory.
16
+ *
17
+ * @default calcomOAuthServiceConfigFactory
18
+ */
19
+ readonly calcomOAuthServiceConfigFactory?: CalcomOAuthServiceConfigFactory;
20
+ }
21
+ /**
22
+ * Convenience function used to generate ModuleMetadata for an app's CalcomOAuthModule.
23
+ */
24
+ export declare function appCalcomOAuthModuleMetadata(config: ProvideAppCalcomOAuthMetadataConfig): ModuleMetadata;
@@ -0,0 +1,66 @@
1
+ import { type CalcomAccessToken, type CalcomAccessTokenCache, type CalcomRefreshToken } from '@dereekb/calcom';
2
+ import { type Maybe } from '@dereekb/util';
3
+ /**
4
+ * Service used for retrieving CalcomAccessTokenCache for Cal.com services.
5
+ *
6
+ * Implementations store and retrieve OAuth access tokens (and the rotated refresh tokens
7
+ * embedded in them). The service supports both a server-level cache and per-user caches
8
+ * keyed by the user's initial refresh token.
9
+ */
10
+ export declare abstract class CalcomOAuthAccessTokenCacheService {
11
+ /**
12
+ * Loads the server-level CalcomAccessTokenCache.
13
+ */
14
+ abstract loadCalcomAccessTokenCache(): CalcomAccessTokenCache;
15
+ /**
16
+ * Creates or retrieves a cache for a specific user context, keyed by the refresh token.
17
+ *
18
+ * The refresh token is hashed to derive a stable cache key. Even though Cal.com
19
+ * rotates refresh tokens, the cache instance persists the updated token in-place,
20
+ * so subsequent reads return the latest token regardless of rotation.
21
+ */
22
+ abstract cacheForRefreshToken?(refreshToken: CalcomRefreshToken): CalcomAccessTokenCache;
23
+ }
24
+ export type CalcomOAuthAccessTokenCacheServiceWithRefreshToken = Required<CalcomOAuthAccessTokenCacheService>;
25
+ /**
26
+ * Derives a short, filesystem-safe cache key from a refresh token using md5.
27
+ */
28
+ export declare function calcomRefreshTokenCacheKey(refreshToken: string): string;
29
+ export type LogMergeCalcomOAuthAccessTokenCacheServiceErrorFunction = (failedUpdates: (readonly [CalcomAccessTokenCache, unknown])[]) => void;
30
+ export declare function logMergeCalcomOAuthAccessTokenCacheServiceErrorFunction(failedUpdates: (readonly [CalcomAccessTokenCache, unknown])[]): void;
31
+ /**
32
+ * Merges the input services in order to use some as a backup source.
33
+ *
34
+ * If one source fails retrieval, the next will be tried.
35
+ * When updating a cached token, it will update the token across all services.
36
+ *
37
+ * @param inputServicesToMerge Must include at least one service. Empty arrays will throw an error.
38
+ */
39
+ export declare function mergeCalcomOAuthAccessTokenCacheServices(inputServicesToMerge: CalcomOAuthAccessTokenCacheService[], logError?: Maybe<boolean | LogMergeCalcomOAuthAccessTokenCacheServiceErrorFunction>): CalcomOAuthAccessTokenCacheService;
40
+ /**
41
+ * Creates a CalcomOAuthAccessTokenCacheService that uses in-memory storage.
42
+ * Per-user caches are stored in a Map keyed by the md5 hash of the refresh token.
43
+ */
44
+ export declare function memoryCalcomOAuthAccessTokenCacheService(existingToken?: Maybe<CalcomAccessToken>, logAccessToConsole?: boolean): CalcomOAuthAccessTokenCacheService;
45
+ export declare const DEFAULT_FILE_CALCOM_ACCESS_TOKEN_CACHE_DIR = ".tmp/calcom-tokens";
46
+ export declare const CALCOM_SERVER_TOKEN_FILE_KEY = "server";
47
+ export type CalcomOAuthAccessTokenCacheFileContent = {
48
+ readonly token?: Maybe<CalcomAccessToken>;
49
+ };
50
+ export interface FileSystemCalcomOAuthAccessTokenCacheService extends CalcomOAuthAccessTokenCacheService {
51
+ readonly cacheDir: string;
52
+ }
53
+ /**
54
+ * Creates a CalcomOAuthAccessTokenCacheService that reads and writes access tokens
55
+ * to the file system. Each user gets their own file, keyed by an md5 hash of their refresh token.
56
+ *
57
+ * File structure:
58
+ * ```
59
+ * <cacheDir>/
60
+ * server.json — server-level token
61
+ * user-<md5hash>.json — per-user tokens (hash of initial refresh token)
62
+ * ```
63
+ *
64
+ * @param cacheDir Directory to store token files. Defaults to `.tmp/calcom-tokens`.
65
+ */
66
+ export declare function fileCalcomOAuthAccessTokenCacheService(cacheDir?: string): FileSystemCalcomOAuthAccessTokenCacheService;
@@ -0,0 +1,7 @@
1
+ export * from './webhook.calcom';
2
+ export * from './webhook.calcom.config';
3
+ export * from './webhook.calcom.controller';
4
+ export * from './webhook.calcom.module';
5
+ export * from './webhook.calcom.service';
6
+ export * from './webhook.calcom.type';
7
+ export * from './webhook.calcom.verify';
@@ -0,0 +1,11 @@
1
+ export declare const CALCOM_WEBHOOK_SECRET_CONFIG_KEY = "CALCOM_WEBHOOK_SECRET";
2
+ export interface CalcomWebhookConfig {
3
+ readonly webhookSecret: string;
4
+ }
5
+ /**
6
+ * Configuration for CalcomWebhookService
7
+ */
8
+ export declare abstract class CalcomWebhookServiceConfig {
9
+ readonly webhookConfig: CalcomWebhookConfig;
10
+ static assertValidConfig(config: CalcomWebhookServiceConfig): void;
11
+ }
@@ -0,0 +1,8 @@
1
+ import { type RawBodyBuffer } from '@dereekb/nestjs';
2
+ import { type Request, type Response } from 'express';
3
+ import { CalcomWebhookService } from './webhook.calcom.service';
4
+ export declare class CalcomWebhookController {
5
+ readonly calcomWebhookService: CalcomWebhookService;
6
+ constructor(calcomWebhookService: CalcomWebhookService);
7
+ handleCalcomWebhook(res: Response, req: Request, rawBody: RawBodyBuffer): Promise<void>;
8
+ }
@@ -0,0 +1,16 @@
1
+ import { type HandlerBindAccessor, type HandlerMappedSetFunction, type Handler } from '@dereekb/util';
2
+ import { type CalcomWebhookEventType, type UntypedCalcomWebhookEvent, type CalcomWebhookEvent, type CalcomWebhookBookingPayload } from './webhook.calcom.type';
3
+ /**
4
+ * Creates a CalcomWebhookEvent and treats the data as the input type.
5
+ */
6
+ export declare function calcomWebhookEvent<T>(event: UntypedCalcomWebhookEvent): CalcomWebhookEvent<T>;
7
+ export type CalcomEventHandler = Handler<UntypedCalcomWebhookEvent, CalcomWebhookEventType>;
8
+ export declare const calcomEventHandlerFactory: import("@dereekb/util").HandlerFactory<UntypedCalcomWebhookEvent, string, boolean>;
9
+ export type CalcomHandlerMappedSetFunction<T> = HandlerMappedSetFunction<CalcomWebhookEvent<T>>;
10
+ export interface CalcomEventHandlerConfigurer extends HandlerBindAccessor<UntypedCalcomWebhookEvent, CalcomWebhookEventType> {
11
+ handleBookingCreated: CalcomHandlerMappedSetFunction<CalcomWebhookBookingPayload>;
12
+ handleBookingCancelled: CalcomHandlerMappedSetFunction<CalcomWebhookBookingPayload>;
13
+ handleBookingRescheduled: CalcomHandlerMappedSetFunction<CalcomWebhookBookingPayload>;
14
+ handleBookingConfirmed: CalcomHandlerMappedSetFunction<CalcomWebhookBookingPayload>;
15
+ }
16
+ export declare const calcomEventHandlerConfigurerFactory: import("@dereekb/util").HandlerConfigurerFactory<CalcomEventHandlerConfigurer, UntypedCalcomWebhookEvent, string, boolean>;
@@ -0,0 +1,20 @@
1
+ import { type ModuleMetadata } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
3
+ import { CalcomWebhookServiceConfig } from './webhook.calcom.config';
4
+ import { type Maybe } from '@dereekb/util';
5
+ export declare function calcomWebhookServiceConfigFactory(configService: ConfigService): CalcomWebhookServiceConfig;
6
+ /**
7
+ * Configures webhooks for the service.
8
+ */
9
+ export declare class CalcomWebhookModule {
10
+ }
11
+ export interface ProvideAppCalcomWebhookMetadataConfig extends Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
12
+ /**
13
+ * Optional dependency module that provides required services.
14
+ */
15
+ readonly dependencyModule?: Maybe<Required<ModuleMetadata>['imports']['0']>;
16
+ }
17
+ /**
18
+ * Convenience function used to generate ModuleMetadata for an app's CalcomWebhookModule.
19
+ */
20
+ export declare function appCalcomWebhookModuleMetadata(config: ProvideAppCalcomWebhookMetadataConfig): ModuleMetadata;
@@ -0,0 +1,21 @@
1
+ import { type Request } from 'express';
2
+ import { type Handler } from '@dereekb/util';
3
+ import { CalcomWebhookServiceConfig } from './webhook.calcom.config';
4
+ import { type UntypedCalcomWebhookEvent } from './webhook.calcom.type';
5
+ export interface CalcomUpdateForWebhookResponse {
6
+ readonly valid: boolean;
7
+ readonly handled: boolean;
8
+ readonly event: UntypedCalcomWebhookEvent;
9
+ }
10
+ /**
11
+ * Service that makes system changes based on Cal.com webhook events.
12
+ */
13
+ export declare class CalcomWebhookService {
14
+ private readonly logger;
15
+ private readonly _verifier;
16
+ readonly handler: Handler<UntypedCalcomWebhookEvent>;
17
+ readonly configure: import("@dereekb/util").HandlerConfigurer<import("./webhook.calcom").CalcomEventHandlerConfigurer, UntypedCalcomWebhookEvent, string, boolean>;
18
+ constructor(config: CalcomWebhookServiceConfig);
19
+ updateForWebhook(req: Request, rawBody: Buffer): Promise<CalcomUpdateForWebhookResponse>;
20
+ updateForCalcomEvent(event: UntypedCalcomWebhookEvent): Promise<boolean>;
21
+ }
@@ -0,0 +1,33 @@
1
+ import { type EmailAddress, type ISO8601DateString, type TimezoneString } from '@dereekb/util';
2
+ import { type CalcomBookingId, type CalcomBookingUid, type CalcomBookingStatus } from '@dereekb/calcom';
3
+ export declare const CALCOM_WEBHOOK_BOOKING_CREATED = "BOOKING_CREATED";
4
+ export declare const CALCOM_WEBHOOK_BOOKING_CANCELLED = "BOOKING_CANCELLED";
5
+ export declare const CALCOM_WEBHOOK_BOOKING_RESCHEDULED = "BOOKING_RESCHEDULED";
6
+ export declare const CALCOM_WEBHOOK_BOOKING_CONFIRMED = "BOOKING_CONFIRMED";
7
+ export type CalcomWebhookEventType = typeof CALCOM_WEBHOOK_BOOKING_CREATED | typeof CALCOM_WEBHOOK_BOOKING_CANCELLED | typeof CALCOM_WEBHOOK_BOOKING_RESCHEDULED | typeof CALCOM_WEBHOOK_BOOKING_CONFIRMED | string;
8
+ export interface CalcomWebhookEvent<T, ET extends string = string> {
9
+ readonly triggerEvent: ET;
10
+ readonly createdAt: ISO8601DateString;
11
+ readonly payload: T;
12
+ }
13
+ export type UntypedCalcomWebhookEvent = CalcomWebhookEvent<any>;
14
+ export interface CalcomWebhookBookingAttendee {
15
+ readonly email: EmailAddress;
16
+ readonly name: string;
17
+ readonly timeZone: TimezoneString;
18
+ }
19
+ export interface CalcomWebhookBookingOrganizer {
20
+ readonly email: EmailAddress;
21
+ readonly name: string;
22
+ readonly timeZone: TimezoneString;
23
+ }
24
+ export interface CalcomWebhookBookingPayload {
25
+ readonly id: CalcomBookingId;
26
+ readonly uid: CalcomBookingUid;
27
+ readonly title: string;
28
+ readonly startTime: ISO8601DateString;
29
+ readonly endTime: ISO8601DateString;
30
+ readonly status: CalcomBookingStatus;
31
+ readonly attendees: readonly CalcomWebhookBookingAttendee[];
32
+ readonly organizer: CalcomWebhookBookingOrganizer;
33
+ }
@@ -0,0 +1,16 @@
1
+ import { type UntypedCalcomWebhookEvent } from './webhook.calcom.type';
2
+ export interface CalcomWebhookEventVerificationResult {
3
+ readonly valid: boolean;
4
+ readonly event: UntypedCalcomWebhookEvent;
5
+ }
6
+ /**
7
+ * Function that verifies a Cal.com webhook event.
8
+ */
9
+ export type CalcomWebhookEventVerifier = (rawBody: Buffer, headers: Record<string, string>) => CalcomWebhookEventVerificationResult;
10
+ /**
11
+ * Verifies a Cal.com webhook event using HMAC-SHA256 signature.
12
+ *
13
+ * @param secret The webhook signing secret.
14
+ * @returns A function that verifies a Cal.com webhook event.
15
+ */
16
+ export declare function calcomWebhookEventVerifier(secret: string): CalcomWebhookEventVerifier;
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@dereekb/calcom",
3
+ "version": "13.4.0",
4
+ "exports": {
5
+ "./nestjs": {
6
+ "module": "./nestjs/index.esm.js",
7
+ "types": "./nestjs/index.d.ts",
8
+ "import": "./nestjs/index.cjs.mjs",
9
+ "default": "./nestjs/index.cjs.js"
10
+ },
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "module": "./index.esm.js",
14
+ "types": "./index.d.ts",
15
+ "import": "./index.cjs.mjs",
16
+ "default": "./index.cjs.js"
17
+ }
18
+ },
19
+ "peerDependencies": {
20
+ "@dereekb/nestjs": "13.4.0",
21
+ "@dereekb/util": "13.4.0",
22
+ "@nestjs/common": "^11.1.16",
23
+ "@nestjs/config": "^4.0.3",
24
+ "express": "^5.0.0",
25
+ "make-error": "^1.3.0"
26
+ },
27
+ "devDependencies": {
28
+ "@nestjs/testing": "^11.1.14",
29
+ "date-fns": "^4.0.0"
30
+ },
31
+ "module": "./index.esm.js",
32
+ "main": "./index.cjs.js",
33
+ "types": "./index.d.ts"
34
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib';
@@ -0,0 +1,86 @@
1
+ import { type EmailAddress, type ISO8601DateString, type Maybe, type Minutes, type TimezoneString } from '@dereekb/util';
2
+ import { type CalcomContext } from './calcom.config';
3
+ import { type CalcomBookingId, type CalcomBookingUid, type CalcomBookingStatus, type CalcomEventTypeId, type CalcomResponseStatus } from '../calcom.type';
4
+ export interface CalcomBookingAttendee {
5
+ readonly name: string;
6
+ readonly email: EmailAddress;
7
+ readonly timeZone: TimezoneString;
8
+ }
9
+ export interface CalcomCreateBookingInput {
10
+ readonly start: ISO8601DateString;
11
+ readonly eventTypeId: CalcomEventTypeId;
12
+ readonly attendee: {
13
+ readonly name: string;
14
+ readonly email: EmailAddress;
15
+ readonly timeZone: TimezoneString;
16
+ };
17
+ readonly metadata?: Maybe<Record<string, unknown>>;
18
+ readonly lengthInMinutes?: Maybe<Minutes>;
19
+ readonly guests?: Maybe<string[]>;
20
+ }
21
+ export interface CalcomBooking {
22
+ readonly id: CalcomBookingId;
23
+ readonly uid: CalcomBookingUid;
24
+ readonly title: string;
25
+ readonly status: CalcomBookingStatus;
26
+ readonly startTime: ISO8601DateString;
27
+ readonly endTime: ISO8601DateString;
28
+ readonly attendees: CalcomBookingAttendee[];
29
+ readonly metadata: Record<string, unknown>;
30
+ }
31
+ export interface CalcomCreateBookingResponse {
32
+ readonly status: CalcomResponseStatus;
33
+ readonly data: CalcomBooking;
34
+ }
35
+ export interface CalcomGetBookingResponse {
36
+ readonly status: CalcomResponseStatus;
37
+ readonly data: CalcomBooking;
38
+ }
39
+ export interface CalcomCancelBookingInput {
40
+ readonly uid: CalcomBookingUid;
41
+ readonly cancellationReason?: Maybe<string>;
42
+ }
43
+ export interface CalcomCancelBookingResponse {
44
+ readonly status: CalcomResponseStatus;
45
+ readonly data: CalcomBooking;
46
+ }
47
+ /**
48
+ * Creates a new booking for the specified event type. The `attendee` represents the person
49
+ * booking (the client), not the host. This endpoint can be called without authentication.
50
+ *
51
+ * @see https://cal.com/docs/api-reference/v2/bookings/create-a-booking
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const response = await createBooking(context)({
56
+ * start: '2026-03-20T14:00:00.000Z',
57
+ * eventTypeId: 12345,
58
+ * attendee: { name: 'Jane Doe', email: 'jane@example.com', timeZone: 'America/New_York' }
59
+ * });
60
+ * console.log(response.data.uid);
61
+ * ```
62
+ */
63
+ export declare function createBooking(context: CalcomContext): (input: CalcomCreateBookingInput) => Promise<CalcomCreateBookingResponse>;
64
+ /**
65
+ * Retrieves a booking by its unique UID.
66
+ *
67
+ * @see https://cal.com/docs/api-reference/v2/bookings/get-a-booking
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const response = await getBooking(context)('abc-123-uid');
72
+ * console.log(response.data.title, response.data.status);
73
+ * ```
74
+ */
75
+ export declare function getBooking(context: CalcomContext): (uid: CalcomBookingUid) => Promise<CalcomGetBookingResponse>;
76
+ /**
77
+ * Cancels a booking by its unique UID, with an optional cancellation reason.
78
+ *
79
+ * @see https://cal.com/docs/api-reference/v2/bookings/cancel-a-booking
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * await cancelBooking(context)({ uid: 'abc-123-uid', cancellationReason: 'Schedule conflict' });
84
+ * ```
85
+ */
86
+ export declare function cancelBooking(context: CalcomContext): (input: CalcomCancelBookingInput) => Promise<CalcomCancelBookingResponse>;