@dereekb/calcom 13.4.1 → 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.
package/index.cjs.js CHANGED
@@ -267,7 +267,7 @@ function _ts_generator$5(thisArg, body) {
267
267
  * Creates a logCalcomServerErrorFunction that logs the error to console.
268
268
  *
269
269
  * @param calcomApiNamePrefix Prefix to use when logging. I.E. CalcomError, etc.
270
- * @returns
270
+ * @returns a LogCalcomServerErrorFunction that logs errors with the given prefix
271
271
  */ function logCalcomServerErrorFunction(calcomApiNamePrefix) {
272
272
  return function(error) {
273
273
  if (_instanceof(error, CalcomServerFetchResponseError)) {
@@ -288,6 +288,10 @@ function _ts_generator$5(thisArg, body) {
288
288
  }
289
289
  /**
290
290
  * Wraps a ConfiguredFetch to support handling errors returned by fetch.
291
+ *
292
+ * @param parseCalcomError - function to parse a FetchResponseError into a CalcomServerError
293
+ * @param defaultLogError - default error logging function used when no override is provided
294
+ * @returns a factory that wraps any ConfiguredFetch with Cal.com error handling
291
295
  */ function handleCalcomErrorFetchFactory(parseCalcomError, defaultLogError) {
292
296
  return function(fetch$1) {
293
297
  var logError = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultLogError;
@@ -350,7 +354,12 @@ var CALCOM_RATE_LIMIT_REMAINING_HEADER = 'X-RateLimit-Remaining';
350
354
  var CALCOM_RATE_LIMIT_RESET_HEADER = 'X-RateLimit-Reset';
351
355
  var DEFAULT_CALCOM_API_RATE_LIMIT = 100;
352
356
  var DEFAULT_CALCOM_API_RATE_LIMIT_RESET_PERIOD = 60 * util.MS_IN_SECOND;
353
- function calcomRateLimitHeaderDetails(headers) {
357
+ /**
358
+ * Extracts Cal.com rate limit information from HTTP response headers.
359
+ *
360
+ * @param headers - the HTTP response headers to parse
361
+ * @returns parsed rate limit details, or null if no rate limit headers are present
362
+ */ function calcomRateLimitHeaderDetails(headers) {
354
363
  var limitHeader = headers.get(CALCOM_RATE_LIMIT_LIMIT_HEADER);
355
364
  var remainingHeader = headers.get(CALCOM_RATE_LIMIT_REMAINING_HEADER);
356
365
  var resetHeader = headers.get(CALCOM_RATE_LIMIT_RESET_HEADER);
@@ -385,6 +394,10 @@ var CalcomTooManyRequestsError = /*#__PURE__*/ function(CalcomServerFetchRespons
385
394
  }(CalcomServerFetchResponseError);
386
395
  /**
387
396
  * Function that parses/transforms a CalcomServerErrorData into a general CalcomServerError or other known error type.
397
+ *
398
+ * @param calcomServerError - the parsed error data from the Cal.com response body
399
+ * @param responseError - the original FetchResponseError containing the HTTP response
400
+ * @returns a CalcomServerFetchResponseError (or subclass like CalcomTooManyRequestsError), or undefined if unrecognized
388
401
  */ function parseCalcomServerErrorData(calcomServerError, responseError) {
389
402
  var result;
390
403
  if (responseError.response.status === CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
@@ -534,7 +547,13 @@ function _ts_generator$4(thisArg, body) {
534
547
  }
535
548
  // MARK: Parser
536
549
  var logCalcomErrorToConsole = logCalcomServerErrorFunction('Calcom');
537
- function parseCalcomApiError(responseError) {
550
+ /**
551
+ * Parses a FetchResponseError from a Cal.com API call into a typed CalcomServerError.
552
+ * Attempts to extract JSON error data from the response body.
553
+ *
554
+ * @param responseError - the fetch response error to parse
555
+ * @returns a parsed CalcomServerError, or undefined if the response body cannot be parsed
556
+ */ function parseCalcomApiError(responseError) {
538
557
  return _async_to_generator$4(function() {
539
558
  var data, result;
540
559
  return _ts_generator$4(this, function(_state) {
@@ -559,7 +578,14 @@ function parseCalcomApiError(responseError) {
559
578
  });
560
579
  })();
561
580
  }
562
- function parseCalcomApiServerErrorResponseData(calcomServerError, responseError) {
581
+ /**
582
+ * Parses Cal.com API server error response data into a specific error type.
583
+ * Delegates to {@link parseCalcomServerErrorData} for general error classification.
584
+ *
585
+ * @param calcomServerError - the parsed error data from the Cal.com response body
586
+ * @param responseError - the original FetchResponseError containing the HTTP response
587
+ * @returns a parsed CalcomServerError, or undefined if the error data is falsy
588
+ */ function parseCalcomApiServerErrorResponseData(calcomServerError, responseError) {
563
589
  var result;
564
590
  if (calcomServerError) {
565
591
  switch(calcomServerError.code){
@@ -807,7 +833,13 @@ function _ts_generator$3(thisArg, body) {
807
833
  return CalcomOAuthAuthFailureError;
808
834
  }(fetch.FetchRequestFactoryError);
809
835
  var logCalcomOAuthErrorToConsole = logCalcomServerErrorFunction('CalcomOAuth');
810
- function parseCalcomOAuthError(responseError) {
836
+ /**
837
+ * Parses a FetchResponseError from a Cal.com OAuth call into a typed error.
838
+ * Attempts to extract JSON error data from the response body.
839
+ *
840
+ * @param responseError - the fetch response error to parse
841
+ * @returns a parsed CalcomServerError or CalcomOAuthAccessTokenError, or undefined if unparseable
842
+ */ function parseCalcomOAuthError(responseError) {
811
843
  return _async_to_generator$3(function() {
812
844
  var data, result;
813
845
  return _ts_generator$3(this, function(_state) {
@@ -832,7 +864,15 @@ function parseCalcomOAuthError(responseError) {
832
864
  });
833
865
  })();
834
866
  }
835
- function parseCalcomOAuthServerErrorResponseData(calcomServerError, responseError) {
867
+ /**
868
+ * Parses Cal.com OAuth server error response data into a specific error type.
869
+ * Handles known error codes like `invalid_grant` and delegates unknown errors
870
+ * to {@link parseCalcomServerErrorData}.
871
+ *
872
+ * @param calcomServerError - the parsed error data from the Cal.com OAuth response body
873
+ * @param responseError - the original FetchResponseError containing the HTTP response
874
+ * @returns a parsed error instance, or undefined if the error data is falsy
875
+ */ function parseCalcomOAuthServerErrorResponseData(calcomServerError, responseError) {
836
876
  var result;
837
877
  if (calcomServerError) {
838
878
  var potentialErrorStringCode = calcomServerError.error;
@@ -980,6 +1020,11 @@ function _ts_generator$2(thisArg, body) {
980
1020
  }
981
1021
  /**
982
1022
  * Generates a new CalcomAccessTokenStringFactory.
1023
+ * Wraps a CalcomAccessTokenFactory to extract just the access token string,
1024
+ * throwing a CalcomOAuthAuthFailureError if the token is missing.
1025
+ *
1026
+ * @param calcomAccessTokenFactory - the factory that produces CalcomAccessToken objects
1027
+ * @returns a factory function that returns the access token string
983
1028
  */ function calcomAccessTokenStringFactory(calcomAccessTokenFactory) {
984
1029
  return function() {
985
1030
  return _async_to_generator$2(function() {
@@ -1009,7 +1054,13 @@ function _ts_generator$2(thisArg, body) {
1009
1054
  var DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION = function DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION(headers) {
1010
1055
  console.warn("calcomRateLimitedFetchHandler(): Too many requests made. The limit is ".concat(headers.limit, " requests per reset period. ResetAt is set for ").concat(headers.resetAt, "."));
1011
1056
  };
1012
- function calcomRateLimitedFetchHandler(config) {
1057
+ /**
1058
+ * Creates a rate-limited fetch handler configured for Cal.com API rate limits.
1059
+ * Automatically adjusts based on rate limit response headers and retries on 429 responses.
1060
+ *
1061
+ * @param config - optional rate limiter configuration overrides
1062
+ * @returns a CalcomRateLimitedFetchHandler that enforces rate limiting
1063
+ */ function calcomRateLimitedFetchHandler(config) {
1013
1064
  var _ref, _ref1, _ref2;
1014
1065
  var onTooManyRequests = (config === null || config === void 0 ? void 0 : config.onTooManyRequests) !== false ? (_ref = config === null || config === void 0 ? void 0 : config.onTooManyRequests) !== null && _ref !== void 0 ? _ref : DEFAULT_CALCOM_RATE_LIMITED_TOO_MANY_REQUESTS_LOG_FUNCTION : undefined;
1015
1066
  var defaultLimit = (_ref1 = config === null || config === void 0 ? void 0 : config.maxRateLimit) !== null && _ref1 !== void 0 ? _ref1 : DEFAULT_CALCOM_API_RATE_LIMIT;
@@ -1039,8 +1090,8 @@ function calcomRateLimitedFetchHandler(config) {
1039
1090
  if (response.status === CALCOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
1040
1091
  shouldRetry = true;
1041
1092
  try {
1042
- onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails, response, fetchResponseError);
1043
- } catch (_) {
1093
+ void (onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails, response, fetchResponseError));
1094
+ } catch (unused) {
1044
1095
  // ignore logging errors
1045
1096
  }
1046
1097
  }
@@ -1057,8 +1108,8 @@ function calcomRateLimitedFetchHandler(config) {
1057
1108
  shouldRetry = true;
1058
1109
  try {
1059
1110
  var headerDetails1 = {};
1060
- onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails1, response, fetchResponseError);
1061
- } catch (_) {
1111
+ void (onTooManyRequests === null || onTooManyRequests === void 0 ? void 0 : onTooManyRequests(headerDetails1, response, fetchResponseError));
1112
+ } catch (unused) {
1062
1113
  // ignore logging errors
1063
1114
  }
1064
1115
  }
@@ -1199,7 +1250,14 @@ function _ts_generator$1(thisArg, body) {
1199
1250
  };
1200
1251
  }
1201
1252
  }
1202
- function calcomFactory(factoryConfig) {
1253
+ /**
1254
+ * Creates a {@link CalcomFactory} that produces fully configured Cal.com API instances.
1255
+ * Sets up rate limiting, error handling, OAuth token management, and both server
1256
+ * and per-user fetch contexts.
1257
+ *
1258
+ * @param factoryConfig - configuration including OAuth context, rate limiter, and optional fetch/logging overrides
1259
+ * @returns a factory function that accepts a CalcomConfig and produces a Calcom instance
1260
+ */ function calcomFactory(factoryConfig) {
1203
1261
  var oauthContext = factoryConfig.oauthContext;
1204
1262
  var serverAccessTokenStringFactory = calcomAccessTokenStringFactory(oauthContext.loadAccessToken);
1205
1263
  var fetchHandler = calcomRateLimitedFetchHandler(factoryConfig.rateLimiterConfig);
@@ -1338,6 +1396,9 @@ var CALCOM_API_VERSION_ME = '2024-08-13';
1338
1396
  var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1339
1397
  /**
1340
1398
  * Returns a headers object with the cal-api-version header set.
1399
+ *
1400
+ * @param version - the Cal.com API version string to include in the header
1401
+ * @returns a headers record containing the cal-api-version header
1341
1402
  */ function calcomApiVersionHeaders(version) {
1342
1403
  return _define_property({}, CALCOM_API_VERSION_HEADER, version);
1343
1404
  }
@@ -1347,6 +1408,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1347
1408
  *
1348
1409
  * @see https://cal.com/docs/api-reference/v2/me
1349
1410
  *
1411
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1412
+ * @returns a function that retrieves the authenticated user's profile
1413
+ *
1350
1414
  * @example
1351
1415
  * ```ts
1352
1416
  * const response = await getMe(context)();
@@ -1366,6 +1430,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1366
1430
  *
1367
1431
  * @see https://cal.com/docs/api-reference/v2/schedules/get-all-schedules
1368
1432
  *
1433
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1434
+ * @returns a function that retrieves all schedules
1435
+ *
1369
1436
  * @example
1370
1437
  * ```ts
1371
1438
  * const response = await getSchedules(context)();
@@ -1388,6 +1455,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1388
1455
  *
1389
1456
  * @see https://cal.com/docs/api-reference/v2/slots/get-available-time-slots-for-an-event-type
1390
1457
  *
1458
+ * @param context - the Cal.com API context (authenticated or public)
1459
+ * @returns a function that queries available slots for the given input
1460
+ *
1391
1461
  * @example
1392
1462
  * ```ts
1393
1463
  * const response = await getAvailableSlots(context)({
@@ -1416,6 +1486,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1416
1486
  *
1417
1487
  * @see https://cal.com/docs/api-reference/v2/bookings/create-a-booking
1418
1488
  *
1489
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1490
+ * @returns a function that creates a booking from the given input
1491
+ *
1419
1492
  * @example
1420
1493
  * ```ts
1421
1494
  * const response = await createBooking(context)({
@@ -1439,6 +1512,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1439
1512
  *
1440
1513
  * @see https://cal.com/docs/api-reference/v2/bookings/get-a-booking
1441
1514
  *
1515
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1516
+ * @returns a function that retrieves a booking by its UID
1517
+ *
1442
1518
  * @example
1443
1519
  * ```ts
1444
1520
  * const response = await getBooking(context)('abc-123-uid');
@@ -1457,6 +1533,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1457
1533
  *
1458
1534
  * @see https://cal.com/docs/api-reference/v2/bookings/cancel-a-booking
1459
1535
  *
1536
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1537
+ * @returns a function that cancels a booking by UID
1538
+ *
1460
1539
  * @example
1461
1540
  * ```ts
1462
1541
  * await cancelBooking(context)({ uid: 'abc-123-uid', cancellationReason: 'Schedule conflict' });
@@ -1480,6 +1559,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1480
1559
  *
1481
1560
  * @see https://cal.com/docs/api-reference/v2/event-types/get-all-event-types
1482
1561
  *
1562
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1563
+ * @returns a function that retrieves all event types
1564
+ *
1483
1565
  * @example
1484
1566
  * ```ts
1485
1567
  * const response = await getEventTypes(context)();
@@ -1498,6 +1580,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1498
1580
  *
1499
1581
  * @see https://cal.com/docs/api-reference/v2/event-types/create-an-event-type
1500
1582
  *
1583
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1584
+ * @returns a function that creates a new event type from the given input
1585
+ *
1501
1586
  * @example
1502
1587
  * ```ts
1503
1588
  * const response = await createEventType(context)({
@@ -1521,6 +1606,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1521
1606
  *
1522
1607
  * @see https://cal.com/docs/api-reference/v2/event-types/update-an-event-type
1523
1608
  *
1609
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1610
+ * @returns a function that updates an event type by ID
1611
+ *
1524
1612
  * @example
1525
1613
  * ```ts
1526
1614
  * await updateEventType(context)(12345, { title: 'Updated Session Title' });
@@ -1539,6 +1627,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1539
1627
  *
1540
1628
  * @see https://cal.com/docs/api-reference/v2/event-types/delete-an-event-type
1541
1629
  *
1630
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1631
+ * @returns a function that deletes an event type by ID
1632
+ *
1542
1633
  * @example
1543
1634
  * ```ts
1544
1635
  * await deleteEventType(context)(12345);
@@ -1557,6 +1648,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1557
1648
  *
1558
1649
  * @see https://cal.com/docs/api-reference/v2/calendars/get-all-calendars
1559
1650
  *
1651
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1652
+ * @returns a function that retrieves all connected calendars
1653
+ *
1560
1654
  * @example
1561
1655
  * ```ts
1562
1656
  * const response = await getCalendars(context)();
@@ -1575,6 +1669,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1575
1669
  *
1576
1670
  * @see https://cal.com/docs/api-reference/v2/calendars/get-busy-times
1577
1671
  *
1672
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1673
+ * @returns a function that retrieves busy time ranges for a date range
1674
+ *
1578
1675
  * @example
1579
1676
  * ```ts
1580
1677
  * const response = await getBusyTimes(context)({
@@ -1604,6 +1701,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1604
1701
  *
1605
1702
  * @see https://cal.com/docs/api-reference/v2/webhooks/create-a-webhook
1606
1703
  *
1704
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1705
+ * @returns a function that creates a webhook subscription from the given input
1706
+ *
1607
1707
  * @example
1608
1708
  * ```ts
1609
1709
  * const response = await createWebhook(context)({
@@ -1626,6 +1726,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1626
1726
  *
1627
1727
  * @see https://cal.com/docs/api-reference/v2/webhooks/get-all-webhooks
1628
1728
  *
1729
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1730
+ * @returns a function that retrieves all webhooks
1731
+ *
1629
1732
  * @example
1630
1733
  * ```ts
1631
1734
  * const response = await getWebhooks(context)();
@@ -1643,6 +1746,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1643
1746
  *
1644
1747
  * @see https://cal.com/docs/api-reference/v2/webhooks/get-a-webhook
1645
1748
  *
1749
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1750
+ * @returns a function that retrieves a specific webhook by ID
1751
+ *
1646
1752
  * @example
1647
1753
  * ```ts
1648
1754
  * const response = await getWebhook(context)(42);
@@ -1660,6 +1766,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1660
1766
  *
1661
1767
  * @see https://cal.com/docs/api-reference/v2/webhooks/update-a-webhook
1662
1768
  *
1769
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1770
+ * @returns a function that updates an existing webhook by ID
1771
+ *
1663
1772
  * @example
1664
1773
  * ```ts
1665
1774
  * await updateWebhook(context)(42, { active: false });
@@ -1677,6 +1786,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1677
1786
  *
1678
1787
  * @see https://cal.com/docs/api-reference/v2/webhooks/delete-a-webhook
1679
1788
  *
1789
+ * @param context - the Cal.com API context providing authentication and fetch capabilities
1790
+ * @returns a function that deletes a webhook by ID
1791
+ *
1680
1792
  * @example
1681
1793
  * ```ts
1682
1794
  * await deleteWebhook(context)(42);
@@ -1697,6 +1809,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1697
1809
  *
1698
1810
  * @see https://cal.com/docs/api-reference/v2/oauth/refresh-an-existing-access-token
1699
1811
  *
1812
+ * @param context - the Cal.com OAuth context providing client credentials and fetch capabilities
1813
+ * @returns a function that refreshes an access token using an optional refresh token override
1814
+ *
1700
1815
  * @example
1701
1816
  * ```ts
1702
1817
  * const response = await refreshAccessToken(context)({ refreshToken: 'existing-refresh-token' });
@@ -1726,6 +1841,9 @@ var CALCOM_API_VERSION_HEADER = 'cal-api-version';
1726
1841
  *
1727
1842
  * @see https://cal.com/docs/api-reference/v2/oauth/exchange-an-authorization-code-for-access-tokens
1728
1843
  *
1844
+ * @param context - the Cal.com OAuth context providing client credentials and fetch capabilities
1845
+ * @returns a function that exchanges an authorization code for access and refresh tokens
1846
+ *
1729
1847
  * @example
1730
1848
  * ```ts
1731
1849
  * const response = await exchangeAuthorizationCode(context)({
@@ -1885,7 +2003,14 @@ function _ts_generator(thisArg, body) {
1885
2003
  };
1886
2004
  }
1887
2005
  }
1888
- function calcomOAuthFactory(factoryConfig) {
2006
+ /**
2007
+ * Creates a {@link CalcomOAuthFactory} that produces configured Cal.com OAuth instances.
2008
+ * Supports both API key authentication (static token, no refresh) and full OAuth
2009
+ * refresh token flow with automatic token rotation.
2010
+ *
2011
+ * @param factoryConfig - configuration including optional fetch factory and error logging
2012
+ * @returns a factory function that accepts a CalcomOAuthConfig and produces a CalcomOAuth instance
2013
+ */ function calcomOAuthFactory(factoryConfig) {
1889
2014
  var fetchHandler = calcomRateLimitedFetchHandler();
1890
2015
  var logCalcomServerErrorFunction = factoryConfig.logCalcomServerErrorFunction, _factoryConfig_fetchFactory = factoryConfig.fetchFactory, fetchFactory = _factoryConfig_fetchFactory === void 0 ? function(_) {
1891
2016
  return fetch.fetchApiFetchService.makeFetch({
@@ -2040,6 +2165,11 @@ function calcomOAuthFactory(factoryConfig) {
2040
2165
  }
2041
2166
  /**
2042
2167
  * Creates a CalcomAccessTokenFactory with multi-tier caching.
2168
+ * Checks the in-memory cache first, then the external cache, and finally refreshes
2169
+ * from the token refresher if no valid token is available.
2170
+ *
2171
+ * @param config - configuration including the token refresher, optional cache, and expiration buffer
2172
+ * @returns a CalcomAccessTokenFactory that returns a valid access token on each call
2043
2173
  */ function calcomOAuthAccessTokenFactory(config) {
2044
2174
  var tokenRefresher = config.tokenRefresher, accessTokenCache = config.accessTokenCache, inputTokenExpirationBuffer = config.tokenExpirationBuffer;
2045
2175
  var tokenExpirationBuffer = inputTokenExpirationBuffer !== null && inputTokenExpirationBuffer !== void 0 ? inputTokenExpirationBuffer : util.MS_IN_MINUTE;