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