@dereekb/zoho 11.0.13 → 11.0.14

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
@@ -3410,17 +3410,23 @@ function zohoAccessTokenStringFactory(zohoAccessTokenFactory) {
3410
3410
  };
3411
3411
  }
3412
3412
 
3413
+ const DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = headers => {
3414
+ console.warn(`zohoRateLimitedFetchHandler(): Too many requests made. The limit is ${headers.limit} requests per reset period. Will be reset at ${headers.resetAt}.`);
3415
+ };
3413
3416
  function zohoRateLimitedFetchHandler(config) {
3414
- var _config$maxRateLimit, _config$resetPeriod;
3417
+ var _config$onTooManyRequ, _config$maxRateLimit, _config$resetPeriod;
3418
+ const onTooManyRequests = (config == null ? void 0 : config.onTooManyRequests) !== false ? (_config$onTooManyRequ = config == null ? void 0 : config.onTooManyRequests) != null ? _config$onTooManyRequ : DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION : undefined;
3415
3419
  const defaultLimit = (_config$maxRateLimit = config == null ? void 0 : config.maxRateLimit) != null ? _config$maxRateLimit : DEFAULT_ZOHO_API_RATE_LIMIT;
3416
3420
  const defaultResetPeriod = (_config$resetPeriod = config == null ? void 0 : config.resetPeriod) != null ? _config$resetPeriod : DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD;
3417
3421
  function configForLimit(limit, resetAt) {
3418
3422
  return {
3419
3423
  limit: defaultLimit,
3420
- cooldownRate: limit / (defaultResetPeriod / util.MS_IN_SECOND),
3421
- exponentRate: 1.12,
3424
+ startLimitAt: Math.ceil(limit / 20),
3425
+ cooldownRate: 1.1 * (limit / (defaultResetPeriod / util.MS_IN_SECOND)),
3426
+ exponentRate: 1.1,
3422
3427
  maxWaitTime: util.MS_IN_SECOND * 10,
3423
- resetPeriod: defaultResetPeriod
3428
+ resetPeriod: defaultResetPeriod,
3429
+ resetAt
3424
3430
  };
3425
3431
  }
3426
3432
  const defaultConfig = configForLimit(defaultLimit);
@@ -3440,14 +3446,19 @@ function zohoRateLimitedFetchHandler(config) {
3440
3446
  remaining
3441
3447
  } = headerDetails;
3442
3448
  if (limit !== defaultLimit) {
3443
- const newConfig = configForLimit(limit);
3449
+ const newConfig = configForLimit(limit, resetAt);
3444
3450
  rateLimiter.setConfig(newConfig, false);
3445
3451
  }
3446
3452
  rateLimiter.setRemainingLimit(remaining);
3447
3453
  rateLimiter.setNextResetAt(resetAt);
3448
3454
  enabled = true;
3449
3455
  // only retry if it's a TOO MANY REQUESTS error
3450
- shouldRetry = response.status === ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE;
3456
+ if (response.status === ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
3457
+ shouldRetry = true;
3458
+ try {
3459
+ onTooManyRequests == null || onTooManyRequests(headerDetails, response, fetchResponseError);
3460
+ } catch (e) {}
3461
+ }
3451
3462
  }
3452
3463
  }
3453
3464
  rateLimiter.setEnabled(enabled);
@@ -3757,6 +3768,7 @@ function zohoAccountsZohoAccessTokenFactory(config) {
3757
3768
 
3758
3769
  exports.DEFAULT_ZOHO_API_RATE_LIMIT = DEFAULT_ZOHO_API_RATE_LIMIT;
3759
3770
  exports.DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD = DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD;
3771
+ exports.DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION;
3760
3772
  exports.ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE = ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE;
3761
3773
  exports.ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE = ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE;
3762
3774
  exports.ZOHO_ACCOUNTS_US_API_URL = ZOHO_ACCOUNTS_US_API_URL;
package/index.esm.js CHANGED
@@ -3542,17 +3542,30 @@ function zohoAccessTokenStringFactory(zohoAccessTokenFactory) {
3542
3542
  };
3543
3543
  }
3544
3544
 
3545
+ /**
3546
+ * Function to execute when too many requests is reached.
3547
+ *
3548
+ * Typically used for logging of some sort. Thrown errors are ignored.
3549
+ */
3550
+
3551
+ const DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = headers => {
3552
+ console.warn(`zohoRateLimitedFetchHandler(): Too many requests made. The limit is ${headers.limit} requests per reset period. Will be reset at ${headers.resetAt}.`);
3553
+ };
3545
3554
  function zohoRateLimitedFetchHandler(config) {
3546
- var _config$maxRateLimit, _config$resetPeriod;
3555
+ var _config$onTooManyRequ, _config$maxRateLimit, _config$resetPeriod;
3556
+ const onTooManyRequests = (config == null ? void 0 : config.onTooManyRequests) !== false ? (_config$onTooManyRequ = config == null ? void 0 : config.onTooManyRequests) != null ? _config$onTooManyRequ : DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION : undefined;
3547
3557
  const defaultLimit = (_config$maxRateLimit = config == null ? void 0 : config.maxRateLimit) != null ? _config$maxRateLimit : DEFAULT_ZOHO_API_RATE_LIMIT;
3548
3558
  const defaultResetPeriod = (_config$resetPeriod = config == null ? void 0 : config.resetPeriod) != null ? _config$resetPeriod : DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD;
3549
3559
  function configForLimit(limit, resetAt) {
3550
3560
  return {
3551
3561
  limit: defaultLimit,
3552
- cooldownRate: limit / (defaultResetPeriod / MS_IN_SECOND),
3553
- exponentRate: 1.12,
3562
+ startLimitAt: Math.ceil(limit / 20),
3563
+ // can do 5% of the requests of the limit before rate limiting begins
3564
+ cooldownRate: 1.1 * (limit / (defaultResetPeriod / MS_IN_SECOND)),
3565
+ exponentRate: 1.1,
3554
3566
  maxWaitTime: MS_IN_SECOND * 10,
3555
- resetPeriod: defaultResetPeriod
3567
+ resetPeriod: defaultResetPeriod,
3568
+ resetAt
3556
3569
  };
3557
3570
  }
3558
3571
  const defaultConfig = configForLimit(defaultLimit);
@@ -3572,7 +3585,7 @@ function zohoRateLimitedFetchHandler(config) {
3572
3585
  remaining
3573
3586
  } = headerDetails;
3574
3587
  if (limit !== defaultLimit) {
3575
- const newConfig = configForLimit(limit);
3588
+ const newConfig = configForLimit(limit, resetAt);
3576
3589
  rateLimiter.setConfig(newConfig, false);
3577
3590
  }
3578
3591
  rateLimiter.setRemainingLimit(remaining);
@@ -3580,7 +3593,12 @@ function zohoRateLimitedFetchHandler(config) {
3580
3593
  enabled = true;
3581
3594
 
3582
3595
  // only retry if it's a TOO MANY REQUESTS error
3583
- shouldRetry = response.status === ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE;
3596
+ if (response.status === ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
3597
+ shouldRetry = true;
3598
+ try {
3599
+ onTooManyRequests == null || onTooManyRequests(headerDetails, response, fetchResponseError);
3600
+ } catch (e) {}
3601
+ }
3584
3602
  }
3585
3603
  }
3586
3604
  rateLimiter.setEnabled(enabled);
@@ -3815,4 +3833,4 @@ function zohoAccountsZohoAccessTokenFactory(config) {
3815
3833
  };
3816
3834
  }
3817
3835
 
3818
- export { DEFAULT_ZOHO_API_RATE_LIMIT, DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD, ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE, ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE, ZOHO_ACCOUNTS_US_API_URL, ZOHO_DUPLICATE_DATA_ERROR_CODE, ZOHO_INTERNAL_ERROR_CODE, ZOHO_INVALID_AUTHORIZATION_ERROR_CODE, ZOHO_INVALID_DATA_ERROR_CODE, ZOHO_INVALID_QUERY_ERROR_CODE, ZOHO_MANDATORY_NOT_FOUND_ERROR_CODE, ZOHO_RATE_LIMIT_LIMIT_HEADER, ZOHO_RATE_LIMIT_REMAINING_HEADER, ZOHO_RATE_LIMIT_RESET_HEADER, ZOHO_RECRUIT_CANDIDATES_MODULE, ZOHO_RECRUIT_SERVICE_NAME, ZOHO_SUCCESS_CODE, ZOHO_TOO_MANY_REQUESTS_ERROR_CODE, ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE, ZohoAccountsAccessTokenError, ZohoAccountsAuthFailureError, ZohoInternalError, ZohoInvalidAuthorizationError, ZohoInvalidQueryError, ZohoRecruitRecordCrudDuplicateDataError, ZohoRecruitRecordCrudError, ZohoRecruitRecordCrudInvalidDataError, ZohoRecruitRecordCrudMandatoryFieldNotFoundError, ZohoRecruitRecordCrudNoMatchingRecordError, ZohoRecruitRecordNoContentError, ZohoServerError, ZohoServerFetchResponseError, ZohoTooManyRequestsError, accessToken, assertRecordDataArrayResultHasContent, createNotes, createNotesForRecord, deleteNotes, escapeZohoFieldValueForCriteriaString, getNotesForRecord, getNotesForRecordPageFactory, getRecordById, getRecords, handleZohoAccountsErrorFetch, handleZohoErrorFetchFactory, handleZohoRecruitErrorFetch, insertRecord, interceptZohoAccountsErrorResponse, interceptZohoErrorResponseFactory, interceptZohoRecruitErrorResponse, isZohoRecruitValidUrl, logZohoAccountsErrorToConsole, logZohoRecruitErrorToConsole, logZohoServerErrorFunction, parseZohoAccountsError, parseZohoAccountsServerErrorResponseData, parseZohoRecruitError, parseZohoRecruitServerErrorResponseData, parseZohoServerErrorResponseData, searchRecords, searchRecordsPageFactory, tryFindZohoServerErrorData, updateRecord, upsertRecord, zohoAccessTokenStringFactory, zohoAccountsApiFetchJsonInput, zohoAccountsConfigApiUrl, zohoAccountsFactory, zohoAccountsZohoAccessTokenFactory, zohoFetchPageFactory, zohoRateLimitHeaderDetails, zohoRateLimitedFetchHandler, zohoRecruitApiFetchJsonInput, zohoRecruitConfigApiUrl, zohoRecruitFactory, zohoRecruitMultiRecordResult, zohoRecruitRecordCrudError, zohoRecruitSearchRecordsCriteriaEntryToCriteriaString, zohoRecruitSearchRecordsCriteriaString, zohoRecruitSearchRecordsCriteriaStringForTree, zohoRecruitUrlSearchParams, zohoRecruitUrlSearchParamsMinusIdAndModule, zohoRecruitUrlSearchParamsMinusModule, zohoServerErrorData };
3836
+ export { DEFAULT_ZOHO_API_RATE_LIMIT, DEFAULT_ZOHO_API_RATE_LIMIT_RESET_PERIOD, DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION, ZOHO_ACCOUNTS_INVALID_CLIENT_ERROR_CODE, ZOHO_ACCOUNTS_INVALID_CODE_ERROR_CODE, ZOHO_ACCOUNTS_US_API_URL, ZOHO_DUPLICATE_DATA_ERROR_CODE, ZOHO_INTERNAL_ERROR_CODE, ZOHO_INVALID_AUTHORIZATION_ERROR_CODE, ZOHO_INVALID_DATA_ERROR_CODE, ZOHO_INVALID_QUERY_ERROR_CODE, ZOHO_MANDATORY_NOT_FOUND_ERROR_CODE, ZOHO_RATE_LIMIT_LIMIT_HEADER, ZOHO_RATE_LIMIT_REMAINING_HEADER, ZOHO_RATE_LIMIT_RESET_HEADER, ZOHO_RECRUIT_CANDIDATES_MODULE, ZOHO_RECRUIT_SERVICE_NAME, ZOHO_SUCCESS_CODE, ZOHO_TOO_MANY_REQUESTS_ERROR_CODE, ZOHO_TOO_MANY_REQUESTS_HTTP_STATUS_CODE, ZohoAccountsAccessTokenError, ZohoAccountsAuthFailureError, ZohoInternalError, ZohoInvalidAuthorizationError, ZohoInvalidQueryError, ZohoRecruitRecordCrudDuplicateDataError, ZohoRecruitRecordCrudError, ZohoRecruitRecordCrudInvalidDataError, ZohoRecruitRecordCrudMandatoryFieldNotFoundError, ZohoRecruitRecordCrudNoMatchingRecordError, ZohoRecruitRecordNoContentError, ZohoServerError, ZohoServerFetchResponseError, ZohoTooManyRequestsError, accessToken, assertRecordDataArrayResultHasContent, createNotes, createNotesForRecord, deleteNotes, escapeZohoFieldValueForCriteriaString, getNotesForRecord, getNotesForRecordPageFactory, getRecordById, getRecords, handleZohoAccountsErrorFetch, handleZohoErrorFetchFactory, handleZohoRecruitErrorFetch, insertRecord, interceptZohoAccountsErrorResponse, interceptZohoErrorResponseFactory, interceptZohoRecruitErrorResponse, isZohoRecruitValidUrl, logZohoAccountsErrorToConsole, logZohoRecruitErrorToConsole, logZohoServerErrorFunction, parseZohoAccountsError, parseZohoAccountsServerErrorResponseData, parseZohoRecruitError, parseZohoRecruitServerErrorResponseData, parseZohoServerErrorResponseData, searchRecords, searchRecordsPageFactory, tryFindZohoServerErrorData, updateRecord, upsertRecord, zohoAccessTokenStringFactory, zohoAccountsApiFetchJsonInput, zohoAccountsConfigApiUrl, zohoAccountsFactory, zohoAccountsZohoAccessTokenFactory, zohoFetchPageFactory, zohoRateLimitHeaderDetails, zohoRateLimitedFetchHandler, zohoRecruitApiFetchJsonInput, zohoRecruitConfigApiUrl, zohoRecruitFactory, zohoRecruitMultiRecordResult, zohoRecruitRecordCrudError, zohoRecruitSearchRecordsCriteriaEntryToCriteriaString, zohoRecruitSearchRecordsCriteriaString, zohoRecruitSearchRecordsCriteriaStringForTree, zohoRecruitUrlSearchParams, zohoRecruitUrlSearchParamsMinusIdAndModule, zohoRecruitUrlSearchParamsMinusModule, zohoServerErrorData };
@@ -2,6 +2,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [11.0.14](https://github.com/dereekb/dbx-components/compare/v11.0.13-dev...v11.0.14) (2024-11-27)
6
+
7
+
8
+
5
9
  ## [11.0.13](https://github.com/dereekb/dbx-components/compare/v11.0.12-dev...v11.0.13) (2024-11-27)
6
10
 
7
11
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/zoho/nestjs",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/zoho",
3
- "version": "11.0.13",
3
+ "version": "11.0.14",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -1,8 +1,16 @@
1
- import { Maybe, Milliseconds, ResetPeriodPromiseRateLimiter } from '@dereekb/util';
2
- import { RateLimitedFetchHandler } from '@dereekb/util/fetch';
1
+ import { Maybe, Milliseconds, PromiseOrValue, ResetPeriodPromiseRateLimiter } from '@dereekb/util';
2
+ import { FetchResponseError, RateLimitedFetchHandler } from '@dereekb/util/fetch';
3
+ import { ZohoRateLimitHeaderDetails } from './zoho.error.api';
3
4
  export interface ZohoRateLimiterRef {
4
5
  readonly zohoRateLimiter: ResetPeriodPromiseRateLimiter;
5
6
  }
7
+ /**
8
+ * Function to execute when too many requests is reached.
9
+ *
10
+ * Typically used for logging of some sort. Thrown errors are ignored.
11
+ */
12
+ export type ZohoRateLimitedTooManyRequestsLogFunction = (headers: ZohoRateLimitHeaderDetails, response: Response, fetchResponseError?: FetchResponseError) => PromiseOrValue<void>;
13
+ export declare const DEFAULT_ZOHO_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION: (headers: ZohoRateLimitHeaderDetails) => void;
6
14
  export interface ZohoRateLimitedFetchHandlerConfig {
7
15
  /**
8
16
  * Custom max rate limit.
@@ -18,6 +26,12 @@ export interface ZohoRateLimitedFetchHandlerConfig {
18
26
  * Defaults to 1 minute in milliseconds.
19
27
  */
20
28
  readonly resetPeriod?: Milliseconds;
29
+ /**
30
+ * Optional function to execute when too many requests is reached.t
31
+ *
32
+ * Defaults to the default logging function, unless false is passed.
33
+ */
34
+ readonly onTooManyRequests?: ZohoRateLimitedTooManyRequestsLogFunction | false;
21
35
  }
22
36
  export type ZohoRateLimitedFetchHandler = RateLimitedFetchHandler<ResetPeriodPromiseRateLimiter>;
23
37
  export declare function zohoRateLimitedFetchHandler(config?: Maybe<ZohoRateLimitedFetchHandlerConfig>): ZohoRateLimitedFetchHandler;