Skip to content

DX | 13-06-2025 | Release #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog

## [v1.21.6](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.6) (2025-06-11)
- Fix
- Revert Retry Logic modification on x-ratelimit-remaining Header

## [v1.21.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.21.5) (2025-06-09)
- Enhancement
- Preview token support added
29 changes: 11 additions & 18 deletions lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
@@ -245,26 +245,19 @@ export function ConcurrencyQueue ({ axios, config }) {
} else {
return Promise.reject(responseHandler(error))
}
} else {
const rateLimitRemaining = response.headers['x-ratelimit-remaining']
if (rateLimitRemaining !== undefined && parseInt(rateLimitRemaining) <= 0) {
return Promise.reject(responseHandler(error))
}

if ((response.status === 401 && this.config.refreshToken)) {
retryErrorType = `Error with status: ${response.status}`
networkError++
} else if ((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))
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))
}
if (this.config.retryCondition && this.config.retryCondition(error)) {
retryErrorType = error.response ? `Error with status: ${response.status}` : `Error Code:${error.code}`
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/management",
"version": "1.21.5",
"version": "1.21.6",
"description": "The Content Management API is used to manage the content of your Contentstack account",
"main": "./dist/node/contentstack-management.js",
"browser": "./dist/web/contentstack-management.js",
70 changes: 0 additions & 70 deletions test/unit/concurrency-Queue-test.js
Original file line number Diff line number Diff line change
@@ -506,76 +506,6 @@ describe('Concurrency queue test', () => {
})
.catch(done)
})

it('should not retry when rate limit remaining is 0', done => {
const mock = new MockAdapter(api)
mock.onGet('/ratelimit').reply(429, { errorCode: 429 }, {
'x-ratelimit-remaining': '0'
})

reconfigureQueue({
retryOnError: true,
retryLimit: 3,
retryDelay: 300
})

api.get('/ratelimit')
.catch(error => {
expect(error.response.status).to.equal(429)
expect(error.config.retryCount).to.equal(0) // Should not have retried
expect(logHandlerStub.callCount).to.equal(0) // No retry logs
mock.restore()
done()
})
})

it('should retry when rate limit remaining is greater than 0', done => {
const mock = new MockAdapter(api)
mock.onGet('/ratelimit').reply(429, { errorCode: 429 }, {
'x-ratelimit-remaining': '5'
})
mock.onGet('/ratelimit').reply(200, { success: true })

reconfigureQueue({
retryOnError: true,
retryLimit: 3,
retryDelay: 300
})

api.get('/ratelimit')
.then(response => {
/* eslint-disable no-unused-expressions */
expect(response.status).to.equal(200)
expect(response.data.success).to.be.true
/* eslint-enable no-unused-expressions */
mock.restore()
done()
})
.catch(done)
})

it('should retry when rate limit remaining header is not present', done => {
const mock = new MockAdapter(api)
mock.onGet('/ratelimit').reply(429, { errorCode: 429 })
mock.onGet('/ratelimit').reply(200, { success: true })

reconfigureQueue({
retryOnError: true,
retryLimit: 3,
retryDelay: 300
})

api.get('/ratelimit')
.then(response => {
/* eslint-disable no-unused-expressions */
expect(response.status).to.equal(200)
expect(response.data.success).to.be.true
/* eslint-enable no-unused-expressions */
mock.restore()
done()
})
.catch(done)
})
})

function makeConcurrencyQueue (config) {