@fullstory/server-api-client
Version:
The official FullStory server API client SDK for NodeJS.
95 lines (94 loc) • 3.56 kB
TypeScript
import { JobMetadata, JobStatus } from '../model/index';
import { FSRequestOptions } from '../http';
export interface BatchRequester<REQ, RSP, STATUS_RSP, IMPORTS_RSP, ERRORS_RSP> {
requestCreateJob(request: {
body: REQ;
idempotencyKey?: string;
}): Promise<RSP>;
requestImports(id: string, pageToken?: string): Promise<IMPORTS_RSP>;
requestImportErrors(id: string, pageToken?: string): Promise<ERRORS_RSP>;
requestJobStatus(id: string): Promise<STATUS_RSP>;
}
export interface BatchJobOptions {
pollInterval?: number;
maxRetry?: number;
}
export declare const DefaultBatchJobOpts: Required<BatchJobOptions>;
export interface BatchJob<REQUEST extends {
requests: SINGLE_REQ[];
}, SINGLE_REQ, IMPORT, FAILURE> {
readonly options: Required<BatchJobOptions> & FSRequestOptions;
request: REQUEST;
readonly metadata?: JobMetadata;
readonly imports: IMPORT[];
readonly failedImports: FAILURE[];
errors: Error[];
add(...requests: SINGLE_REQ[]): this;
execute(): void;
restart(jobId?: string): void;
getId(): string | undefined;
getStatus(): JobStatus | undefined;
getImports(): IMPORT[];
getFailedImports(): FAILURE[];
on(type: 'created', callback: (job: this) => void): this;
on(type: 'processing', callback: (job: this) => void): this;
on(type: 'done', callback: (imported: IMPORT[], failed: FAILURE[]) => void): this;
on(type: 'error', callback: (error: Error) => void): this;
on(type: 'abort', callback: (errors: Error[]) => void): this;
}
export declare class BatchJobImpl<REQUEST extends {
requests: SINGLE_REQ[];
}, SINGLE_REQ, CREATE_RSP extends {
job?: JobMetadata;
}, STATUS_RSP extends {
job?: JobMetadata;
}, IMPORT, FAILURE> implements BatchJob<REQUEST, SINGLE_REQ, IMPORT, FAILURE> {
private requester;
readonly options: Required<BatchJobOptions> & FSRequestOptions;
request: REQUEST;
metadata?: JobMetadata | undefined;
imports: IMPORT[];
failedImports: FAILURE[];
errors: Error[];
private _createdCallbacks;
private _processingCallbacks;
private _doneCallbacks;
private _abortCallbacks;
private _errorCallbacks;
private _executionStatus;
private _interval?;
private _statusPromise?;
private _nextPollDelay;
private _numRetries;
constructor(request: REQUEST, requester: BatchRequester<REQUEST, CREATE_RSP, STATUS_RSP, {
results?: IMPORT[];
next_page_token?: string;
}, {
results?: FAILURE[];
next_page_token?: string;
}>, opts?: BatchJobOptions & FSRequestOptions);
restart(jobId?: string): void;
getId(): string | undefined;
getStatus(): JobStatus | undefined;
getImports(): IMPORT[];
getFailedImports(): FAILURE[];
add(...requests: SINGLE_REQ[]): this;
execute(): void;
on(type: 'created', callback: (job: this) => void): this;
on(type: 'processing', callback: (job: this) => void): this;
on(type: 'done', callback: (imported: IMPORT[], failed: FAILURE[]) => void): this;
on(type: 'error', callback: (error: Error) => void): this;
on(type: 'abort', callback: (errors: Error[]) => void): this;
private setMetadata;
private startPolling;
private stopPolling;
private handleJobCreated;
private handleProcessing;
private handleCompleted;
private handleCompletedWithFailure;
private handleError;
private handleAbort;
private requestImportsWithPaging;
private requestImportErrorsWithPaging;
private withPageToken;
}