@dereekb/calcom 13.4.0 → 13.4.2

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.
@@ -2,6 +2,12 @@ import { type ModuleMetadata } from '@nestjs/common';
2
2
  import { ConfigService } from '@nestjs/config';
3
3
  import { CalcomWebhookServiceConfig } from './webhook.calcom.config';
4
4
  import { type Maybe } from '@dereekb/util';
5
+ /**
6
+ * Factory function that creates a {@link CalcomWebhookServiceConfig} from NestJS ConfigService environment variables.
7
+ *
8
+ * @param configService - the NestJS ConfigService instance
9
+ * @returns a validated CalcomWebhookServiceConfig
10
+ */
5
11
  export declare function calcomWebhookServiceConfigFactory(configService: ConfigService): CalcomWebhookServiceConfig;
6
12
  /**
7
13
  * Configures webhooks for the service.
@@ -16,5 +22,8 @@ export interface ProvideAppCalcomWebhookMetadataConfig extends Pick<ModuleMetada
16
22
  }
17
23
  /**
18
24
  * Convenience function used to generate ModuleMetadata for an app's CalcomWebhookModule.
25
+ *
26
+ * @param config - the module metadata configuration including optional dependency module
27
+ * @returns NestJS ModuleMetadata for registering the CalcomWebhookModule
19
28
  */
20
29
  export declare function appCalcomWebhookModuleMetadata(config: ProvideAppCalcomWebhookMetadataConfig): ModuleMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/calcom",
3
- "version": "13.4.0",
3
+ "version": "13.4.2",
4
4
  "exports": {
5
5
  "./nestjs": {
6
6
  "module": "./nestjs/index.esm.js",
@@ -17,8 +17,8 @@
17
17
  }
18
18
  },
19
19
  "peerDependencies": {
20
- "@dereekb/nestjs": "13.4.0",
21
- "@dereekb/util": "13.4.0",
20
+ "@dereekb/nestjs": "13.4.2",
21
+ "@dereekb/util": "13.4.2",
22
22
  "@nestjs/common": "^11.1.16",
23
23
  "@nestjs/config": "^4.0.3",
24
24
  "express": "^5.0.0",
@@ -50,6 +50,9 @@ export interface CalcomCancelBookingResponse {
50
50
  *
51
51
  * @see https://cal.com/docs/api-reference/v2/bookings/create-a-booking
52
52
  *
53
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
54
+ * @returns a function that creates a booking from the given input
55
+ *
53
56
  * @example
54
57
  * ```ts
55
58
  * const response = await createBooking(context)({
@@ -66,6 +69,9 @@ export declare function createBooking(context: CalcomContext): (input: CalcomCre
66
69
  *
67
70
  * @see https://cal.com/docs/api-reference/v2/bookings/get-a-booking
68
71
  *
72
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
73
+ * @returns a function that retrieves a booking by its UID
74
+ *
69
75
  * @example
70
76
  * ```ts
71
77
  * const response = await getBooking(context)('abc-123-uid');
@@ -78,6 +84,9 @@ export declare function getBooking(context: CalcomContext): (uid: CalcomBookingU
78
84
  *
79
85
  * @see https://cal.com/docs/api-reference/v2/bookings/cancel-a-booking
80
86
  *
87
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
88
+ * @returns a function that cancels a booking by UID
89
+ *
81
90
  * @example
82
91
  * ```ts
83
92
  * await cancelBooking(context)({ uid: 'abc-123-uid', cancellationReason: 'Schedule conflict' });
@@ -58,6 +58,9 @@ export interface CalcomGetBusyTimesResponse {
58
58
  *
59
59
  * @see https://cal.com/docs/api-reference/v2/calendars/get-all-calendars
60
60
  *
61
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
62
+ * @returns a function that retrieves all connected calendars
63
+ *
61
64
  * @example
62
65
  * ```ts
63
66
  * const response = await getCalendars(context)();
@@ -70,6 +73,9 @@ export declare function getCalendars(context: CalcomContext): () => Promise<Calc
70
73
  *
71
74
  * @see https://cal.com/docs/api-reference/v2/calendars/get-busy-times
72
75
  *
76
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
77
+ * @returns a function that retrieves busy time ranges for a date range
78
+ *
73
79
  * @example
74
80
  * ```ts
75
81
  * const response = await getBusyTimes(context)({
@@ -38,6 +38,9 @@ export interface CalcomUpdateEventTypeInput {
38
38
  *
39
39
  * @see https://cal.com/docs/api-reference/v2/event-types/get-all-event-types
40
40
  *
41
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
42
+ * @returns a function that retrieves all event types
43
+ *
41
44
  * @example
42
45
  * ```ts
43
46
  * const response = await getEventTypes(context)();
@@ -50,6 +53,9 @@ export declare function getEventTypes(context: CalcomContext): () => Promise<Cal
50
53
  *
51
54
  * @see https://cal.com/docs/api-reference/v2/event-types/create-an-event-type
52
55
  *
56
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
57
+ * @returns a function that creates a new event type from the given input
58
+ *
53
59
  * @example
54
60
  * ```ts
55
61
  * const response = await createEventType(context)({
@@ -66,6 +72,9 @@ export declare function createEventType(context: CalcomContext): (input: CalcomC
66
72
  *
67
73
  * @see https://cal.com/docs/api-reference/v2/event-types/update-an-event-type
68
74
  *
75
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
76
+ * @returns a function that updates an event type by ID
77
+ *
69
78
  * @example
70
79
  * ```ts
71
80
  * await updateEventType(context)(12345, { title: 'Updated Session Title' });
@@ -77,6 +86,9 @@ export declare function updateEventType(context: CalcomContext): (eventTypeId: C
77
86
  *
78
87
  * @see https://cal.com/docs/api-reference/v2/event-types/delete-an-event-type
79
88
  *
89
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
90
+ * @returns a function that deletes an event type by ID
91
+ *
80
92
  * @example
81
93
  * ```ts
82
94
  * await deleteEventType(context)(12345);
@@ -23,6 +23,9 @@ export interface CalcomGetSchedulesResponse {
23
23
  *
24
24
  * @see https://cal.com/docs/api-reference/v2/schedules/get-all-schedules
25
25
  *
26
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
27
+ * @returns a function that retrieves all schedules
28
+ *
26
29
  * @example
27
30
  * ```ts
28
31
  * const response = await getSchedules(context)();
@@ -30,6 +30,9 @@ export interface CalcomGetAvailableSlotsResponse {
30
30
  *
31
31
  * @see https://cal.com/docs/api-reference/v2/slots/get-available-time-slots-for-an-event-type
32
32
  *
33
+ * @param context - the Cal.com API context (authenticated or public)
34
+ * @returns a function that queries available slots for the given input
35
+ *
33
36
  * @example
34
37
  * ```ts
35
38
  * const response = await getAvailableSlots(context)({
@@ -20,6 +20,9 @@ export interface CalcomGetMeResponse {
20
20
  *
21
21
  * @see https://cal.com/docs/api-reference/v2/me
22
22
  *
23
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
24
+ * @returns a function that retrieves the authenticated user's profile
25
+ *
23
26
  * @example
24
27
  * ```ts
25
28
  * const response = await getMe(context)();
@@ -38,6 +38,9 @@ export interface CalcomGetWebhooksResponse {
38
38
  *
39
39
  * @see https://cal.com/docs/api-reference/v2/webhooks/create-a-webhook
40
40
  *
41
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
42
+ * @returns a function that creates a webhook subscription from the given input
43
+ *
41
44
  * @example
42
45
  * ```ts
43
46
  * const response = await createWebhook(context)({
@@ -54,6 +57,9 @@ export declare function createWebhook(context: CalcomContext): (input: CalcomCre
54
57
  *
55
58
  * @see https://cal.com/docs/api-reference/v2/webhooks/get-all-webhooks
56
59
  *
60
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
61
+ * @returns a function that retrieves all webhooks
62
+ *
57
63
  * @example
58
64
  * ```ts
59
65
  * const response = await getWebhooks(context)();
@@ -66,6 +72,9 @@ export declare function getWebhooks(context: CalcomContext): () => Promise<Calco
66
72
  *
67
73
  * @see https://cal.com/docs/api-reference/v2/webhooks/get-a-webhook
68
74
  *
75
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
76
+ * @returns a function that retrieves a specific webhook by ID
77
+ *
69
78
  * @example
70
79
  * ```ts
71
80
  * const response = await getWebhook(context)(42);
@@ -78,6 +87,9 @@ export declare function getWebhook(context: CalcomContext): (webhookId: CalcomWe
78
87
  *
79
88
  * @see https://cal.com/docs/api-reference/v2/webhooks/update-a-webhook
80
89
  *
90
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
91
+ * @returns a function that updates an existing webhook by ID
92
+ *
81
93
  * @example
82
94
  * ```ts
83
95
  * await updateWebhook(context)(42, { active: false });
@@ -89,6 +101,9 @@ export declare function updateWebhook(context: CalcomContext): (webhookId: Calco
89
101
  *
90
102
  * @see https://cal.com/docs/api-reference/v2/webhooks/delete-a-webhook
91
103
  *
104
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
105
+ * @returns a function that deletes a webhook by ID
106
+ *
92
107
  * @example
93
108
  * ```ts
94
109
  * await deleteWebhook(context)(42);
@@ -1,6 +1,21 @@
1
1
  import { type FetchResponseError } from '@dereekb/util/fetch';
2
2
  import { type CalcomServerErrorData, type ParsedCalcomServerError } from '../calcom.error.api';
3
3
  export declare const logCalcomErrorToConsole: import("..").LogCalcomServerErrorFunction;
4
+ /**
5
+ * Parses a FetchResponseError from a Cal.com API call into a typed CalcomServerError.
6
+ * Attempts to extract JSON error data from the response body.
7
+ *
8
+ * @param responseError - the fetch response error to parse
9
+ * @returns a parsed CalcomServerError, or undefined if the response body cannot be parsed
10
+ */
4
11
  export declare function parseCalcomApiError(responseError: FetchResponseError): Promise<ParsedCalcomServerError>;
12
+ /**
13
+ * Parses Cal.com API server error response data into a specific error type.
14
+ * Delegates to {@link parseCalcomServerErrorData} for general error classification.
15
+ *
16
+ * @param calcomServerError - the parsed error data from the Cal.com response body
17
+ * @param responseError - the original FetchResponseError containing the HTTP response
18
+ * @returns a parsed CalcomServerError, or undefined if the error data is falsy
19
+ */
5
20
  export declare function parseCalcomApiServerErrorResponseData(calcomServerError: CalcomServerErrorData, responseError: FetchResponseError): ParsedCalcomServerError;
6
21
  export declare const handleCalcomErrorFetch: import("..").HandleCalcomErrorFetchFactory;
@@ -20,4 +20,12 @@ export interface CalcomFactoryConfig extends CalcomOAuthContextRef {
20
20
  readonly logCalcomServerErrorFunction?: LogCalcomServerErrorFunction;
21
21
  }
22
22
  export type CalcomFactory = (config: CalcomConfig) => Calcom;
23
+ /**
24
+ * Creates a {@link CalcomFactory} that produces fully configured Cal.com API instances.
25
+ * Sets up rate limiting, error handling, OAuth token management, and both server
26
+ * and per-user fetch contexts.
27
+ *
28
+ * @param factoryConfig - configuration including OAuth context, rate limiter, and optional fetch/logging overrides
29
+ * @returns a factory function that accepts a CalcomConfig and produces a Calcom instance
30
+ */
23
31
  export declare function calcomFactory(factoryConfig: CalcomFactoryConfig): CalcomFactory;
@@ -40,7 +40,7 @@ export type LogCalcomServerErrorFunction = (error: FetchRequestFactoryError | Ca
40
40
  * Creates a logCalcomServerErrorFunction that logs the error to console.
41
41
  *
42
42
  * @param calcomApiNamePrefix Prefix to use when logging. I.E. CalcomError, etc.
43
- * @returns
43
+ * @returns a LogCalcomServerErrorFunction that logs errors with the given prefix
44
44
  */
45
45
  export declare function logCalcomServerErrorFunction(calcomApiNamePrefix: string): LogCalcomServerErrorFunction;
46
46
  /**
@@ -51,6 +51,10 @@ export type ParsedCalcomServerError = FetchRequestFactoryError | CalcomServerErr
51
51
  export type ParseCalcomFetchResponseErrorFunction = (responseError: FetchResponseError) => Promise<ParsedCalcomServerError>;
52
52
  /**
53
53
  * Wraps a ConfiguredFetch to support handling errors returned by fetch.
54
+ *
55
+ * @param parseCalcomError - function to parse a FetchResponseError into a CalcomServerError
56
+ * @param defaultLogError - default error logging function used when no override is provided
57
+ * @returns a factory that wraps any ConfiguredFetch with Cal.com error handling
54
58
  */
55
59
  export declare function handleCalcomErrorFetchFactory(parseCalcomError: ParseCalcomFetchResponseErrorFunction, defaultLogError: LogCalcomServerErrorFunction): HandleCalcomErrorFetchFactory;
56
60
  /**
@@ -76,11 +80,21 @@ export interface CalcomRateLimitHeaderDetails {
76
80
  */
77
81
  readonly resetAt?: Date;
78
82
  }
83
+ /**
84
+ * Extracts Cal.com rate limit information from HTTP response headers.
85
+ *
86
+ * @param headers - the HTTP response headers to parse
87
+ * @returns parsed rate limit details, or null if no rate limit headers are present
88
+ */
79
89
  export declare function calcomRateLimitHeaderDetails(headers: Headers): Maybe<CalcomRateLimitHeaderDetails>;
80
90
  export declare class CalcomTooManyRequestsError extends CalcomServerFetchResponseError {
81
91
  get headerDetails(): Maybe<CalcomRateLimitHeaderDetails>;
82
92
  }
83
93
  /**
84
94
  * Function that parses/transforms a CalcomServerErrorData into a general CalcomServerError or other known error type.
95
+ *
96
+ * @param calcomServerError - the parsed error data from the Cal.com response body
97
+ * @param responseError - the original FetchResponseError containing the HTTP response
98
+ * @returns a CalcomServerFetchResponseError (or subclass like CalcomTooManyRequestsError), or undefined if unrecognized
85
99
  */
86
100
  export declare function parseCalcomServerErrorData(calcomServerError: CalcomServerErrorData, responseError: FetchResponseError): CalcomServerFetchResponseError | undefined;
@@ -32,4 +32,11 @@ export interface CalcomRateLimitedFetchHandlerConfig {
32
32
  readonly onTooManyRequests?: CalcomRateLimitedTooManyRequestsLogFunction | false;
33
33
  }
34
34
  export type CalcomRateLimitedFetchHandler = RateLimitedFetchHandler<ResetPeriodPromiseRateLimiter>;
35
+ /**
36
+ * Creates a rate-limited fetch handler configured for Cal.com API rate limits.
37
+ * Automatically adjusts based on rate limit response headers and retries on 429 responses.
38
+ *
39
+ * @param config - optional rate limiter configuration overrides
40
+ * @returns a CalcomRateLimitedFetchHandler that enforces rate limiting
41
+ */
35
42
  export declare function calcomRateLimitedFetchHandler(config?: Maybe<CalcomRateLimitedFetchHandlerConfig>): CalcomRateLimitedFetchHandler;
@@ -27,6 +27,9 @@ export interface CalcomOAuthAccessTokenErrorResponse {
27
27
  *
28
28
  * @see https://cal.com/docs/api-reference/v2/oauth/refresh-an-existing-access-token
29
29
  *
30
+ * @param context - the Cal.com OAuth context providing client credentials and fetch capabilities
31
+ * @returns a function that refreshes an access token using an optional refresh token override
32
+ *
30
33
  * @example
31
34
  * ```ts
32
35
  * const response = await refreshAccessToken(context)({ refreshToken: 'existing-refresh-token' });
@@ -42,6 +45,9 @@ export declare function refreshAccessToken(context: CalcomOAuthContext): (input?
42
45
  *
43
46
  * @see https://cal.com/docs/api-reference/v2/oauth/exchange-an-authorization-code-for-access-tokens
44
47
  *
48
+ * @param context - the Cal.com OAuth context providing client credentials and fetch capabilities
49
+ * @returns a function that exchanges an authorization code for access and refresh tokens
50
+ *
45
51
  * @example
46
52
  * ```ts
47
53
  * const response = await exchangeAuthorizationCode(context)({
@@ -60,5 +60,10 @@ export type CalcomAccessTokenRefresher = CalcomAccessTokenFactory;
60
60
  export type CalcomAccessTokenStringFactory = () => Promise<CalcomAccessTokenString>;
61
61
  /**
62
62
  * Generates a new CalcomAccessTokenStringFactory.
63
+ * Wraps a CalcomAccessTokenFactory to extract just the access token string,
64
+ * throwing a CalcomOAuthAuthFailureError if the token is missing.
65
+ *
66
+ * @param calcomAccessTokenFactory - the factory that produces CalcomAccessToken objects
67
+ * @returns a factory function that returns the access token string
63
68
  */
64
69
  export declare function calcomAccessTokenStringFactory(calcomAccessTokenFactory: CalcomAccessTokenFactory): CalcomAccessTokenStringFactory;
@@ -21,6 +21,22 @@ export declare class CalcomOAuthAuthFailureError extends FetchRequestFactoryErro
21
21
  constructor(reason?: string | undefined);
22
22
  }
23
23
  export declare const logCalcomOAuthErrorToConsole: import("..").LogCalcomServerErrorFunction;
24
+ /**
25
+ * Parses a FetchResponseError from a Cal.com OAuth call into a typed error.
26
+ * Attempts to extract JSON error data from the response body.
27
+ *
28
+ * @param responseError - the fetch response error to parse
29
+ * @returns a parsed CalcomServerError or CalcomOAuthAccessTokenError, or undefined if unparseable
30
+ */
24
31
  export declare function parseCalcomOAuthError(responseError: FetchResponseError): Promise<ParsedCalcomServerError>;
32
+ /**
33
+ * Parses Cal.com OAuth server error response data into a specific error type.
34
+ * Handles known error codes like `invalid_grant` and delegates unknown errors
35
+ * to {@link parseCalcomServerErrorData}.
36
+ *
37
+ * @param calcomServerError - the parsed error data from the Cal.com OAuth response body
38
+ * @param responseError - the original FetchResponseError containing the HTTP response
39
+ * @returns a parsed error instance, or undefined if the error data is falsy
40
+ */
25
41
  export declare function parseCalcomOAuthServerErrorResponseData(calcomServerError: CalcomServerErrorData, responseError: FetchResponseError): ParsedCalcomServerError;
26
42
  export declare const handleCalcomOAuthErrorFetch: import("..").HandleCalcomErrorFetchFactory;
@@ -14,6 +14,14 @@ export interface CalcomOAuthFactoryConfig {
14
14
  logCalcomServerErrorFunction?: LogCalcomServerErrorFunction;
15
15
  }
16
16
  export type CalcomOAuthFactory = (config: CalcomOAuthConfig) => CalcomOAuth;
17
+ /**
18
+ * Creates a {@link CalcomOAuthFactory} that produces configured Cal.com OAuth instances.
19
+ * Supports both API key authentication (static token, no refresh) and full OAuth
20
+ * refresh token flow with automatic token rotation.
21
+ *
22
+ * @param factoryConfig - configuration including optional fetch factory and error logging
23
+ * @returns a factory function that accepts a CalcomOAuthConfig and produces a CalcomOAuth instance
24
+ */
17
25
  export declare function calcomOAuthFactory(factoryConfig: CalcomOAuthFactoryConfig): CalcomOAuthFactory;
18
26
  export interface CalcomOAuthAccessTokenFactoryConfig {
19
27
  /**
@@ -27,5 +35,10 @@ export interface CalcomOAuthAccessTokenFactoryConfig {
27
35
  }
28
36
  /**
29
37
  * Creates a CalcomAccessTokenFactory with multi-tier caching.
38
+ * Checks the in-memory cache first, then the external cache, and finally refreshes
39
+ * from the token refresher if no valid token is available.
40
+ *
41
+ * @param config - configuration including the token refresher, optional cache, and expiration buffer
42
+ * @returns a CalcomAccessTokenFactory that returns a valid access token on each call
30
43
  */
31
44
  export declare function calcomOAuthAccessTokenFactory(config: CalcomOAuthAccessTokenFactoryConfig): CalcomAccessTokenFactory;
@@ -13,5 +13,8 @@ export type CalcomApiVersionString = string;
13
13
  export declare const CALCOM_API_VERSION_HEADER = "cal-api-version";
14
14
  /**
15
15
  * Returns a headers object with the cal-api-version header set.
16
+ *
17
+ * @param version - the Cal.com API version string to include in the header
18
+ * @returns a headers record containing the cal-api-version header
16
19
  */
17
20
  export declare function calcomApiVersionHeaders(version: CalcomApiVersionString): Record<string, string>;