diff --git a/.talismanrc b/.talismanrc index 32fad92e..83861a19 100644 --- a/.talismanrc +++ b/.talismanrc @@ -9,7 +9,7 @@ fileignoreconfig: ignore_detectors: - filecontent - filename: package-lock.json - checksum: c37956b0e6ccd5267dac7fd6f4347fbb5ad41defe1c42d39aaaeaf64d2cf8605 + checksum: bab53d56ce2609e960fdbbd1e87cc89915820e6761016ddd74ee57f931f4223d - filename: .husky/pre-commit checksum: 52a664f536cf5d1be0bea19cb6031ca6e8107b45b6314fe7d47b7fad7d800632 - filename: test/sanity-check/api/user-test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2571992b..02ef5456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [v1.25.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.25.1) (2025-10-06) + - Fix + - Updated delay handling to use centralized external configuration in SDK interceptor + ## [v1.25.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.25.0) (2025-09-03) - Enhancement - Added publish_all_localized param in bulk publish/unpublish diff --git a/lib/core/concurrency-queue.js b/lib/core/concurrency-queue.js index 27c49364..747713d5 100644 --- a/lib/core/concurrency-queue.js +++ b/lib/core/concurrency-queue.js @@ -14,7 +14,8 @@ const defaultConfig = { retryOnHttpServerError: true, maxNetworkRetries: 3, networkRetryDelay: 100, // Base delay for network retries (ms) - networkBackoffStrategy: 'exponential' // 'exponential' or 'fixed' + networkBackoffStrategy: 'exponential', // 'exponential' or 'fixed' + delayMs: null // Delay in milliseconds before making each request } export function ConcurrencyQueue ({ axios, config }) { @@ -175,16 +176,22 @@ export function ConcurrencyQueue ({ axios, config }) { // Initial shift will check running request, // and adds request to running queue if max requests are not running - this.initialShift = () => { + this.initialShift = async () => { if (this.running.length < this.config.maxRequests && !this.paused) { - shift() + await shift() } } // INTERNAL: Shift the queued item to running queue - const shift = () => { + const shift = async () => { if (this.queue.length && !this.paused) { const queueItem = this.queue.shift() + + // Add configurable delay before making the request if specified + if (this.config.delayMs && this.config.delayMs > 0) { + await new Promise(resolve => setTimeout(resolve, this.config.delayMs)) + } + queueItem.resolve(queueItem.request) this.running.push(queueItem) } @@ -197,7 +204,7 @@ export function ConcurrencyQueue ({ axios, config }) { this.push = requestPromise => { this.queue.push(requestPromise) - this.initialShift() + this.initialShift().catch(console.error) } this.clear = () => { @@ -312,7 +319,7 @@ export function ConcurrencyQueue ({ axios, config }) { return refreshToken() } else { for (let i = 0; i < this.config.maxRequests; i++) { - this.initialShift() + this.initialShift().catch(console.error) } } }, time)) @@ -360,7 +367,7 @@ export function ConcurrencyQueue ({ axios, config }) { } }) for (let i = 0; i < this.config.maxRequests; i++) { - this.initialShift() + this.initialShift().catch(console.error) } }) } diff --git a/package-lock.json b/package-lock.json index 52af398b..2aea0186 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@contentstack/management", - "version": "1.25.0", + "version": "1.25.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/management", - "version": "1.25.0", + "version": "1.25.1", "license": "MIT", "dependencies": { "assert": "^2.1.0", - "axios": "^1.11.0", + "axios": "^1.12.2", "buffer": "^6.0.3", "form-data": "^4.0.4", "husky": "^9.1.7", @@ -3747,7 +3747,9 @@ } }, "node_modules/axios": { - "version": "1.11.0", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.12.2.tgz", + "integrity": "sha512-vMJzPewAlRyOgxV2dU0Cuz2O8zzzx9VYtbJOaBgXFeLc4IV/Eg50n4LowmehOOR61S8ZMpc2K5Sa7g6A4jfkUw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", diff --git a/package.json b/package.json index 2e6cb22f..c80d580a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.25.0", + "version": "1.25.1", "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", @@ -53,7 +53,7 @@ "license": "MIT", "dependencies": { "assert": "^2.1.0", - "axios": "^1.11.0", + "axios": "^1.12.2", "buffer": "^6.0.3", "form-data": "^4.0.4", "husky": "^9.1.7", diff --git a/types/contentstackClient.d.ts b/types/contentstackClient.d.ts index fc2c65d5..3d89f093 100644 --- a/types/contentstackClient.d.ts +++ b/types/contentstackClient.d.ts @@ -45,6 +45,7 @@ export interface ContentstackConfig extends AxiosRequestConfig, ContentstackToke logHandler?: (level: string, data: any) => void application?: string integration?: string + delayMs?: number } export interface LoginDetails {