@jupiterone/integration-sdk-http-client
Advanced tools
Comparing version 12.2.1 to 12.2.2
@@ -33,6 +33,10 @@ import { Response } from 'node-fetch'; | ||
* @param {number} [config.rateLimitThrottling.threshold] - The threshold at which to throttle requests | ||
* It uses the Rate Limit header fields standard by default: https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-07.html | ||
* @param {string} [config.rateLimitThrottling.resetMode='remaining_epoch_s'] - The mode to use for rate limit reset, | ||
* - 'remaining_epoch_s' - Use when reset header has the remaining window before the rate limit resets, in UTC epoch seconds. | ||
* - 'datetime_epoch_s' - Use when reset header has the time at which the current rate limit window resets in UTC epoch seconds. | ||
* @param {RateLimitHeaders} [config.rateLimitThrottling.rateLimitHeaders] - The headers to use for rate limiting | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.limit='x-rate-limit-limit'] - The header for the rate limit limit | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.remaining='x-rate-limit-remaining'] - The header for the rate limit remaining | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.reset='x-rate-limit-reset'] - The header for the rate limit reset | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.limit='ratelimit-limit'] - The header for the rate limit limit | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.remaining='ratelimit-remaining'] - The header for the rate limit remaining | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.reset='ratelimit-reset'] - The header for the rate limit reset | ||
* @param {TokenBucketOptions} [config.tokenBucket] - The token bucket options, | ||
@@ -39,0 +43,0 @@ * if not provided, token bucket will not be enabled |
@@ -8,2 +8,3 @@ "use strict"; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const integration_sdk_core_1 = require("@jupiterone/integration-sdk-core"); | ||
const attempt_1 = require("@lifeomic/attempt"); | ||
@@ -37,5 +38,5 @@ const errors_1 = require("./errors"); | ||
const DEFAULT_RATE_LIMIT_HEADERS = { | ||
limit: 'x-rate-limit-limit', | ||
remaining: 'x-rate-limit-remaining', | ||
reset: 'x-rate-limit-reset', | ||
limit: 'ratelimit-limit', | ||
remaining: 'ratelimit-remaining', | ||
reset: 'ratelimit-reset', | ||
}; | ||
@@ -68,6 +69,10 @@ class BaseAPIClient { | ||
* @param {number} [config.rateLimitThrottling.threshold] - The threshold at which to throttle requests | ||
* It uses the Rate Limit header fields standard by default: https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-07.html | ||
* @param {string} [config.rateLimitThrottling.resetMode='remaining_epoch_s'] - The mode to use for rate limit reset, | ||
* - 'remaining_epoch_s' - Use when reset header has the remaining window before the rate limit resets, in UTC epoch seconds. | ||
* - 'datetime_epoch_s' - Use when reset header has the time at which the current rate limit window resets in UTC epoch seconds. | ||
* @param {RateLimitHeaders} [config.rateLimitThrottling.rateLimitHeaders] - The headers to use for rate limiting | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.limit='x-rate-limit-limit'] - The header for the rate limit limit | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.remaining='x-rate-limit-remaining'] - The header for the rate limit remaining | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.reset='x-rate-limit-reset'] - The header for the rate limit reset | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.limit='ratelimit-limit'] - The header for the rate limit limit | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.remaining='ratelimit-remaining'] - The header for the rate limit remaining | ||
* @param {string} [config.rateLimitThrottling.rateLimitHeaders.reset='ratelimit-reset'] - The header for the rate limit reset | ||
* @param {TokenBucketOptions} [config.tokenBucket] - The token bucket options, | ||
@@ -101,2 +106,6 @@ * if not provided, token bucket will not be enabled | ||
this.rateLimitThrottling = config.rateLimitThrottling; | ||
if (this.rateLimitThrottling && !this.rateLimitThrottling.resetMode) { | ||
// Set default resetMode | ||
this.rateLimitThrottling.resetMode = 'remaining_epoch_s'; | ||
} | ||
if (config.tokenBucket) { | ||
@@ -364,5 +373,16 @@ this.tokenBucketInitialConfig = config.tokenBucket; | ||
} | ||
const nowDate = new Date(headers.get('date') ?? Date.now()); | ||
const retryDate = new Date(parseInt(resetValue, 10) * 1000); | ||
return retryDate.getTime() - nowDate.getTime() + 1000; | ||
if (this.rateLimitThrottling?.resetMode === 'remaining_epoch_s') { | ||
return parseInt(resetValue, 10) * 1000 + 1000; // add one second to make sure the reset time has passed | ||
} | ||
else if (this.rateLimitThrottling?.resetMode === 'datetime_epoch_s') { | ||
const nowDate = new Date(headers.get('date') ?? Date.now()); | ||
const retryDate = new Date(parseInt(resetValue, 10) * 1000); | ||
return retryDate.getTime() - nowDate.getTime() + 1000; // add one second to make sure the reset time has passed | ||
} | ||
else { | ||
throw new integration_sdk_core_1.IntegrationError({ | ||
code: 'INVALID_RATE_LIMIT_RESET_MODE', | ||
message: 'Invalid rate limit reset mode', | ||
}); | ||
} | ||
} | ||
@@ -369,0 +389,0 @@ getRateLimitHeaderValue(headers, header) { |
@@ -25,2 +25,3 @@ import { IntegrationLogger } from '@jupiterone/integration-sdk-core'; | ||
threshold: number; | ||
resetMode?: 'remaining_epoch_s' | 'datetime_epoch_s'; | ||
rateLimitHeaders?: RateLimitHeaders; | ||
@@ -27,0 +28,0 @@ } |
{ | ||
"name": "@jupiterone/integration-sdk-http-client", | ||
"version": "12.2.1", | ||
"version": "12.2.2", | ||
"description": "The HTTP client for use in JupiterOne integrations", | ||
@@ -27,3 +27,3 @@ "main": "dist/src/index.js", | ||
"@jupiterone/hierarchical-token-bucket": "^0.3.1", | ||
"@jupiterone/integration-sdk-core": "^12.2.1", | ||
"@jupiterone/integration-sdk-core": "^12.2.2", | ||
"@lifeomic/attempt": "^3.0.3", | ||
@@ -34,4 +34,4 @@ "lodash": "^4.17.21", | ||
"devDependencies": { | ||
"@jupiterone/integration-sdk-dev-tools": "^12.2.1", | ||
"@jupiterone/integration-sdk-private-test-utils": "^12.2.1", | ||
"@jupiterone/integration-sdk-dev-tools": "^12.2.2", | ||
"@jupiterone/integration-sdk-private-test-utils": "^12.2.2", | ||
"@types/node-fetch": "^2.6.11" | ||
@@ -43,3 +43,3 @@ }, | ||
"homepage": "https://github.com/JupiterOne/sdk#readme", | ||
"gitHead": "53a556f10b4ae9d2ae02727c4cecf3bcf77088cf" | ||
"gitHead": "3500a730207dde4d9c80ca97fa76cbe7757047cb" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165950
771