From 229faafcfaf93eecd889783ea85081a8ead0bdef Mon Sep 17 00:00:00 2001 From: Nicholas Souphandavong Date: Mon, 8 Dec 2025 16:10:04 -0500 Subject: [PATCH 1/4] Add support for onAfterSleepSetup. --- src/client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/client.js b/src/client.js index 138c0f7..32b58cc 100644 --- a/src/client.js +++ b/src/client.js @@ -204,6 +204,14 @@ class ShotgunApiClient { }, { retries: RETRY_COUNT, + onRetry: async (err, attemptNumber) => { + // Hook for tests to advance fake timers + // Wait for next tick to ensure async-retry has set up setTimeout + if (this.onAfterSleepSetup) { + await Promise.resolve(); // Let async-retry set up setTimeout first + this.onAfterSleepSetup({ attemptNumber }); + } + } } ); } From 4d993f58e9f4695bdc640e53cae2714e592e1398 Mon Sep 17 00:00:00 2001 From: Nicholas Souphandavong Date: Mon, 8 Dec 2025 16:21:35 -0500 Subject: [PATCH 2/4] Add docs. --- src/client.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index ac6ab4d..556f15a 100644 --- a/src/client.js +++ b/src/client.js @@ -9,6 +9,18 @@ const { RequestError } = require('./error'); const DEFAULT_API_BASE_PATH = '/api/v1'; const RETRY_COUNT = 2; +/** + * Shotgun API Client + * @class + * @property {string} siteUrl - The base URL for the Shotgun site + * @property {Object} credentials - Authentication credentials + * @property {boolean} debug - Enable debug logging + * @property {string} apiBasePath - Base path for API endpoints + * @property {Function} [onAfterSleepSetup] - Testing hook called after retry delay is scheduled. + * Signature: function({ attemptNumber: number }): void + * Purpose: Allows tests with fake timers to advance time after async-retry schedules setTimeout. + * This should only be set in test environments to control retry timing with fake timers. + */ class ShotgunApiClient { constructor({ siteUrl, credentials, debug, apiBasePath = DEFAULT_API_BASE_PATH }) { @@ -205,8 +217,11 @@ class ShotgunApiClient { { retries: RETRY_COUNT, onRetry: async (err, attemptNumber) => { - // Hook for tests to advance fake timers - // Wait for next tick to ensure async-retry has set up setTimeout + // Testing hook: allows tests with fake timers to advance time after retry delay + // is scheduled by async-retry. We yield control with Promise.resolve() to ensure + // async-retry's setTimeout is registered before the test advances the clock. + // Example usage in tests: + // client.onAfterSleepSetup = () => { this.clock.next(); }; if (this.onAfterSleepSetup) { await Promise.resolve(); // Let async-retry set up setTimeout first this.onAfterSleepSetup({ attemptNumber }); From bd4141a78648498df421356afc0a3a69cededfc6 Mon Sep 17 00:00:00 2001 From: Nicholas Souphandavong Date: Mon, 8 Dec 2025 16:23:53 -0500 Subject: [PATCH 3/4] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ab3fcb1..9670c76 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "qs": "^6.10.5" }, "name": "shotgun-nodejs", - "version": "4.4.0", + "version": "4.5.0", "description": "Autodesk Shotgrid REST API library", "main": "src/index.js", "devDependencies": { From bcaf6a450a6c06ced0aec4961ba90738e65efb51 Mon Sep 17 00:00:00 2001 From: Nicholas Souphandavong Date: Mon, 8 Dec 2025 16:25:06 -0500 Subject: [PATCH 4/4] Bump version number. --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a6b8d7..d80ae35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "shotgun-nodejs", - "version": "4.3.0", + "version": "4.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "shotgun-nodejs", - "version": "4.3.0", + "version": "4.5.0", "license": "ISC", "dependencies": { "async-retry": "^1.3.3",