diff --git a/packages/integration-sdk-http-client/src/client.ts b/packages/integration-sdk-http-client/src/client.ts index 11add8869..73ddece63 100644 --- a/packages/integration-sdk-http-client/src/client.ts +++ b/packages/integration-sdk-http-client/src/client.ts @@ -6,7 +6,13 @@ import { IntegrationLogger, IntegrationProviderAPIError, } from '@jupiterone/integration-sdk-core'; -import { AttemptContext, retry, sleep } from '@lifeomic/attempt'; +import { + AttemptContext, + AttemptOptions, + defaultCalculateDelay, + retry, + sleep, +} from '@lifeomic/attempt'; import { fatalRequestError, isRetryableRequest, @@ -338,6 +344,9 @@ export abstract class BaseAPIClient { delay: this.retryOptions.delay, timeout: this.retryOptions.timeout, factor: this.retryOptions.factor, + calculateDelay: (context, options) => { + return this.retryCalculateDelay(context, options); + }, handleError: async (err, context) => { if (this.retryOptions.handleError) { await this.retryOptions.handleError(err, context, this.logger); @@ -418,6 +427,16 @@ export abstract class BaseAPIClient { } } + protected retryCalculateDelay( + context: AttemptContext, + options: AttemptOptions, + ) { + if (context.attemptNum === 0) { + return 0; // don't wait before the first attempt + } + return defaultCalculateDelay(context, options); + } + /** * Iteratively performs API requests based on the initial request and subsequent requests defined by a callback function. * This method is designed to facilitate paginated API requests where each request's response determines the parameters of the next request. diff --git a/packages/integration-sdk-http-client/src/types.ts b/packages/integration-sdk-http-client/src/types.ts index 558e93e83..d11fb65de 100644 --- a/packages/integration-sdk-http-client/src/types.ts +++ b/packages/integration-sdk-http-client/src/types.ts @@ -5,6 +5,8 @@ import { import { AttemptContext } from '@lifeomic/attempt'; import { Agent } from 'node:https'; +export { AttemptContext, AttemptOptions } from '@lifeomic/attempt'; + export type OptionalPromise = T | Promise; export interface RequestOptions {