diff --git a/CHANGELOG.md b/CHANGELOG.md index aa9bce9..3ed6fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [v1.4.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.3.0) (2024-08-25) + - Enhancement: Retry logic to make use of x-ratelimit-remaining header + ## [v1.3.0](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.3.0) (2024-08-11) - Enh: Add search function to query apps by names @@ -9,6 +12,7 @@ - Added Pre-commit hook to run the snyk and talismand scans ## [v1.2.8](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.8) (2024-05-26) + - Fix: Added params support to getInstalledApps method for enhanced flexibility ## [v1.2.7](https://github.com/contentstack/contentstack-marketplace-sdk/tree/v1.2.7) (2024-05-15) diff --git a/lib/core/concurrency-queue.js b/lib/core/concurrency-queue.js index 44be851..3601a4b 100644 --- a/lib/core/concurrency-queue.js +++ b/lib/core/concurrency-queue.js @@ -202,19 +202,32 @@ export function ConcurrencyQueue ({ axios, config }) { } else { return Promise.reject(responseHandler(error)) } - } else if (response.status === 429 || (response.status === 401 && this.config.refreshToken)) { - retryErrorType = `Error with status: ${response.status}` - networkError++ + } else { + const rateLimitRemaining = response.headers['x-ratelimit-remaining'] + if (rateLimitRemaining !== undefined && parseInt(rateLimitRemaining) <= 0) { + // return Promise.reject(responseHandler(error)) - if (networkError > this.config.retryLimit) { - return Promise.reject(responseHandler(error)) + this.running.shift() + return delay(wait).then(() => { + error.config.retryCount = networkError++ + // deepcode ignore Ssrf: URL is dynamic + return axios(updateRequestConfig(error, 'Rate Limit Hit', wait)) + }) + } + if (response.status === 429 || (response.status === 401 && this.config.refreshToken)) { + retryErrorType = `Error with status: ${response.status}` + networkError++ + + if (networkError > this.config.retryLimit) { + return Promise.reject(responseHandler(error)) + } + this.running.shift() + // Cool down the running requests + delay(wait, response.status === 401) + error.config.retryCount = networkError + // deepcode ignore Ssrf: URL is dynamic + return axios(updateRequestConfig(error, retryErrorType, wait)) } - this.running.shift() - // Cool down the running requests - delay(wait, response.status === 401) - error.config.retryCount = networkError - // deepcode ignore Ssrf: URL is dynamic - return axios(updateRequestConfig(error, retryErrorType, wait)) } if (this.config.retryCondition && this.config.retryCondition(error)) { retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}` diff --git a/package-lock.json b/package-lock.json index ac6c774..c8f3942 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/marketplace-sdk", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/marketplace-sdk", - "version": "1.3.0", + "version": "1.4.0", "license": "MIT", "dependencies": { "axios": "^1.11.0" diff --git a/package.json b/package.json index 7752afc..297c631 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/marketplace-sdk", - "version": "1.3.0", + "version": "1.4.0", "description": "The Contentstack Marketplace SDK is used to manage the content of your Contentstack marketplace apps", "main": "./dist/node/contentstack-marketplace.js", "browser": "./dist/web/contentstack-marketplace.js",