diff --git a/packages/rest-client/src/tools/addonJobPoller.test.ts b/packages/rest-client/src/tools/addonJobPoller.test.ts index ba7315307..ef158b1a9 100644 --- a/packages/rest-client/src/tools/addonJobPoller.test.ts +++ b/packages/rest-client/src/tools/addonJobPoller.test.ts @@ -1,6 +1,6 @@ import { jest } from '@jest/globals' import { ADDONS_UUID } from '../../test/fixtures' -import { testSettings } from '../../test/helpers' +import { testSettings, uploadClient } from '../../test/helpers' import { copyFileToLocalStorage } from '../api/file/copyFileToLocalStorage' import { AddonExecutionStatus } from '../types/AddonExecutionStatus' import { AddonName } from '../types/AddonName' @@ -15,6 +15,8 @@ describe('addonJobPoller', () => { testSettings ) + await uploadClient.isReadyPoll(copy.result.uuid, testSettings) + const result = await addonJobPoller( { addonName: AddonName.UC_CLAMAV_VIRUS_SCAN, diff --git a/packages/upload-client/src/UploadClient.ts b/packages/upload-client/src/UploadClient.ts index b43f1cf98..f0fb238e2 100644 --- a/packages/upload-client/src/UploadClient.ts +++ b/packages/upload-client/src/UploadClient.ts @@ -27,6 +27,7 @@ import { FileFromOptions, uploadFile } from './uploadFile' import { FileInfo, GroupId, GroupInfo, Token, Url, Uuid } from './api/types' import { Settings, Sliceable, SupportedFileInput } from './types' import { GroupFromOptions, uploadFileGroup } from './uploadFileGroup' +import { IsReadyPoolOptions, isReadyPoll } from './tools/isReadyPoll' /** Populate options with settings. */ const populateOptionsWithSettings = ( @@ -155,4 +156,13 @@ export default class UploadClient { return uploadFileGroup(data, populateOptionsWithSettings(options, settings)) } + + isReadyPoll( + uuid: Uuid, + options: Partial = {} + ): Promise { + const settings = this.getSettings() + + return isReadyPoll(uuid, populateOptionsWithSettings(options, settings)) + } } diff --git a/packages/upload-client/src/index.ts b/packages/upload-client/src/index.ts index c46c35a9e..94d41ad21 100644 --- a/packages/upload-client/src/index.ts +++ b/packages/upload-client/src/index.ts @@ -103,3 +103,4 @@ export { ComputableProgressInfo, UnknownProgressInfo } from './api/types' +export { isReadyPoll } from './tools/isReadyPoll' diff --git a/packages/upload-client/src/tools/isReadyPoll.ts b/packages/upload-client/src/tools/isReadyPoll.ts index 1ced19df6..652fca563 100644 --- a/packages/upload-client/src/tools/isReadyPoll.ts +++ b/packages/upload-client/src/tools/isReadyPoll.ts @@ -2,12 +2,12 @@ import info from '../api/info' import { ComputableProgressInfo, FileInfo, - ProgressCallback + ProgressCallback, + Uuid } from '../api/types' import { CustomUserAgent, poll } from '@uploadcare/api-client-utils' -type ArgsIsReadyPool = { - file: string +export type IsReadyPoolOptions = { publicKey: string baseURL?: string source?: string @@ -19,21 +19,23 @@ type ArgsIsReadyPool = { signal?: AbortSignal } -function isReadyPoll({ - file, - publicKey, - baseURL, - source, - integration, - userAgent, - retryThrottledRequestMaxTimes, - retryNetworkErrorMaxTimes, - signal, - onProgress -}: ArgsIsReadyPool): FileInfo | PromiseLike { +function isReadyPoll( + uuid: Uuid, + { + publicKey, + baseURL, + source, + integration, + userAgent, + retryThrottledRequestMaxTimes, + retryNetworkErrorMaxTimes, + signal, + onProgress + }: IsReadyPoolOptions +): Promise { return poll({ check: (signal) => - info(file, { + info(uuid, { publicKey, baseURL, signal, diff --git a/packages/upload-client/src/uploadFile/uploadDirect.ts b/packages/upload-client/src/uploadFile/uploadDirect.ts index 5ac08ccaf..1ba7276b3 100644 --- a/packages/upload-client/src/uploadFile/uploadDirect.ts +++ b/packages/upload-client/src/uploadFile/uploadDirect.ts @@ -78,8 +78,7 @@ export const uploadDirect = ( metadata }) .then(({ file }) => { - return isReadyPoll({ - file, + return isReadyPoll(file, { publicKey, baseURL, source, diff --git a/packages/upload-client/src/uploadFile/uploadFromUrl.ts b/packages/upload-client/src/uploadFile/uploadFromUrl.ts index 8d31ab148..7d896e50b 100644 --- a/packages/upload-client/src/uploadFile/uploadFromUrl.ts +++ b/packages/upload-client/src/uploadFile/uploadFromUrl.ts @@ -233,8 +233,7 @@ export const uploadFromUrl = ( return result }) .then((result) => - isReadyPoll({ - file: result.uuid, + isReadyPoll(result.uuid, { publicKey, baseURL, integration, diff --git a/packages/upload-client/src/uploadFile/uploadMultipart.ts b/packages/upload-client/src/uploadFile/uploadMultipart.ts index 03d1ec06e..37a11fcef 100644 --- a/packages/upload-client/src/uploadFile/uploadMultipart.ts +++ b/packages/upload-client/src/uploadFile/uploadMultipart.ts @@ -181,8 +181,7 @@ export const uploadMultipart = async ( if (fileInfo.isReady) { return fileInfo } else { - return isReadyPoll({ - file: fileInfo.uuid, + return isReadyPoll(fileInfo.uuid, { publicKey, baseURL, source,