Last active
March 25, 2021 21:16
-
-
Save nategraves/76f48350a45867c9226c40bbdc623714 to your computer and use it in GitHub Desktop.
Typescript definitions for apify-client-js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'apify-client' { | |
class ApifyClient { | |
constructor(options?: { | |
baseUrl?: string; | |
maxRetries?: number; | |
minDelayBetweenRetriesMillis?: number; | |
requestInterceptors?: Function[]; | |
timeoutSecs?: number; | |
token?: string; | |
}); | |
actors(): ActorCollectionClient; | |
actor(id: string): ActorClient; | |
build( | |
versionNumber: string, | |
options?: { | |
useCache?: boolean; | |
betaPackages?: boolean; | |
tag?: string; | |
waitForFinish?: number; | |
}, | |
): Build; | |
builds(): BuildCollectionClient; | |
datasets(): DatasetCollectionClient; | |
dataset(id: string): DatasetClient; | |
keyValueStores(): KeyValueStoreCollectionClient; | |
keyValueStore(id: string): KeyValueStoreClient; | |
log(buildOrRunId: string): LogClient; | |
requestQueues(): RequestQueueCollection; | |
requestQueue(id: string, options?: { clientKey?: object }): RequestQueueClient; | |
run(id: string): RunClient; | |
tasks(): TaskCollectionClient; | |
task(id: string): TaskClient; | |
schedules(): ScheduleCollectionClient; | |
schedule(id: string): ScheduleClient; | |
user(id: string): UserClient; | |
webhooks(): WebhookCollectionClient; | |
webhook(id: string): WebhookClient; | |
webhookDispatches(): WebhookDispatchCollectionClient; | |
webhookDispatch(id: string): WebhookDispatchClient; | |
} | |
interface ActorCollectionClient { | |
create(actor: { name: string; description: string; isPublic: boolean }): Promise<Actor>; | |
list(options?: { | |
my?: boolean; | |
limit?: number; | |
offset?: number; | |
desc?: boolean; | |
}): Promise<PaginationList<ActorClient>>; | |
} | |
interface BaseCollectionClientProps { | |
limit?: number; | |
offset?: number; | |
desc?: boolean; | |
} | |
interface BuildCollectionClient { | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<Build>>; | |
} | |
interface Build { | |
id: string; | |
actId: string; | |
userId: string; | |
startedAt: string; | |
finishedAt?: string; | |
status: string; | |
meta: { | |
origin: string; | |
clientIp: string; | |
userAgent: string; | |
}; | |
stats: { | |
durationMillis: number; | |
runTimeSecs: number; | |
computedUnits: number; | |
}; | |
options: { | |
inputSchema?: string; | |
readme?: string; | |
buildNumber: string; | |
}; | |
} | |
interface Dataset { | |
id: string; | |
name: string; | |
userId: string; | |
createdAt: string; | |
modifiedAt: string; | |
accessedAt: string; | |
itemCount: number; | |
cleanItemCount: number; | |
actId?: Maybe<object>; | |
actRunId?: Maybe<object>; | |
fields?: string[]; | |
} | |
interface DatasetClient { | |
delete(): Promise<void>; | |
downloadItems( | |
format: DownloadItemFormat, | |
options?: { | |
attachment?: boolean; | |
bom?: boolean; | |
clean?: boolean; | |
delimiter?: string; | |
desc?: boolean; | |
fields?: string[]; | |
omit?: string[]; | |
limit?: number; | |
offset?: number; | |
skipEmpty?: boolean; | |
skipHeaderRow?: boolean; | |
skipHidden?: boolean; | |
unwind?: string; | |
xmlRoot?: string; | |
xmlRow?: string; | |
}, | |
): Promise<Buffer>; | |
get(): Promise<Dataset>; | |
listItems(options?: { | |
clean?: boolean; | |
desc?: boolean; | |
fields?: string[]; | |
omit?: string[]; | |
limit?: number; | |
offset?: number; | |
skipEmpty?: boolean; | |
skipHidden?: boolean; | |
unwind?: string; | |
}): Promise<PaginationList<any>>; | |
pushItems(items: object | string | object[] | string[]): Promise<void>; | |
update(newFields: object): Promise<Dataset>; | |
} | |
interface DatasetCollectionClient { | |
getOrCreate(name?: string): Promise<object>; | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<Dataset>>; | |
} | |
interface KeyValueStoreClient { | |
delete(): Promise<void>; | |
deleteRecord(key: string): Promise<void>; | |
get(): Promise<KeyValueStore>; | |
getRecord( | |
key: string, | |
options?: { buffer?: boolean; stream?: boolean }, | |
): Promise<KeyValueStoreRecord>; | |
listKeys(options?: { limit?: object; exclusiveStartKey?: string }): Promise<object>; | |
setRecord(record: KeyValueStoreRecord): Promise<void>; | |
update(newRecords: { [key as string]: KeyValueStoreRecordValue }): Promise<KeyValueStore>; | |
} | |
interface KeyValueStore { | |
id: string; | |
name: string; | |
userId: string; | |
createdAt: string; | |
modifiedAt: string; | |
accessedAt: string; | |
actId?: Maybe<object>; | |
actRunId?: Maybe<object>; | |
} | |
interface KeyValueStoreCollectionClient { | |
getOrCreate(name?: string): Promise<object>; | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<KeyValueStore>>; | |
} | |
interface KeyValueStoreRecord { | |
key: string; | |
value: KeyValueStoreRecordValue; | |
contentType?: string; | |
} | |
interface LogClient { | |
get(): Promise<Maybe<string>>; | |
stream(): Promise<Maybe<Readable>>; | |
} | |
interface PaginationList<T> { | |
items: T[]; | |
total: number; | |
offset: number; | |
count: number; | |
limit: number; | |
desc: boolean; | |
} | |
interface Request { | |
id: string; | |
retryCount: number; | |
uniqueKey: string; | |
url: string; | |
method: string; | |
loadedUrl?: object; | |
payload?: object; | |
noRetry?: boolean; | |
errorMessages?: any[]; | |
headers?: object; | |
userData?: { | |
label?: string; | |
image?: string; | |
}; | |
handledAt?: object; | |
} | |
interface RequestQueueClient { | |
addRequest(request: any, options?: any): Promise<RequestQueueClientBaseResponse>; | |
delete(): Promise<void>; | |
deleteRequest(id: string): Promise<void>; | |
get(): Promise<RequestQueue>; | |
getRequest(id: string): Promise<Maybe<Request>>; | |
listHead(options?: { | |
limit?: number; | |
}): Promise<{ | |
limit: number; | |
queueModifiedAt: string; | |
hadMultipleClients: boolean; | |
items: Pick<Request, 'id' | 'retryCount' | 'uniqueKey' | 'url' | 'method'>[]; | |
}>; | |
update(newFields: object): Promise<RequestQueue>; | |
updateRequest( | |
request: Request, | |
options?: { forefront?: boolean }, | |
): Promise<RequestQueueClientBaseResponse>; | |
} | |
interface RequestQueueClientBaseResponse { | |
requestId: string; | |
wasAlreadyPresent: boolean; | |
wasAlreadyHandled: boolean; | |
} | |
interface RequestQueueCollection { | |
getOrCreate(name?: string): Promise<object>; | |
list( | |
options?: { unnamed?: boolean } & BaseCollectionClientProps, | |
): Promise<PaginationList<RequestQueue>>; | |
} | |
interface Run { | |
id: string; | |
actId: string; | |
userId: string; | |
actorTaskId: string; | |
startedAt: string; | |
finishedAt: string | null; | |
status: TaskStatus; | |
meta: { | |
origin: string; | |
userAgent: string; | |
}; | |
stats: { | |
inputBodyLen: number; | |
restartCount: number; | |
durationMillis: number; | |
resurrectCount: number; | |
runTimeSecs: number; | |
metamorph: number; | |
computeUnits: number; | |
memAvgBytes: number; | |
memMaxBytes: number; | |
memCurrentBytes: number; | |
cpuAvgUsage: number; | |
cpuMaxUsage: number; | |
cpuCurrentUsage: number; | |
}; | |
options: { | |
build: string; | |
timeoutSecs: number; | |
memoryMbytes: number; | |
diskMbytes: number; | |
}; | |
buildId: string; | |
exitCode: number; | |
defaultKeyValueStoreId: string; | |
defaultDatasetId: string; | |
defaultRequestQueueId: string; | |
} | |
interface RunClient { | |
abort(): Promise<Run>; | |
dataset(): DatasetClient; | |
get(options?: { waitForFinish?: boolean }): Promise<Run>; | |
keyValueStore(): KeyValueStoreClient; | |
log(): LogClient; | |
metamorph( | |
targetActorId: string, | |
input?: KeyValue, | |
options?: { | |
contentType?: object; | |
build?: object; | |
}, | |
): Promise<Run>; | |
requestQueue(): RequestQueueClient; | |
resurrect(options?: { build?: string; memory?: number; timeout?: number }): Promise<Run>; | |
waitForFinish(options?: { waitSecs?: number }): Promise<Run>; | |
} | |
interface RunCollectionClient { | |
list( | |
options?: BaseCollectionClientProps & { | |
status?: boolean; | |
}, | |
); | |
} | |
interface Schedule { | |
id: string; | |
userId: string; | |
name: string; | |
cronExpression: string; | |
timezone: string; | |
isEnabled: boolean; | |
isExclusive: boolean; | |
description?: string; | |
createdAt: string; | |
modifiedAt: string; | |
nextRunAt?: string; | |
lastRunAt?: string; | |
actions: ScheduleAction[]; | |
} | |
interface ScheduleAction { | |
id: string; | |
type: string; | |
actorTaskId: string; | |
input?: KeyValue; | |
} | |
interface ScheduleClient { | |
delete(): Promise<void>; | |
get(): Promise<Maybe<Schedule>>; | |
getLog(): Promise<Maybe<string>>; | |
update(newFields: object): Promise<Schedule>; | |
} | |
interface ScheduleCollectionClient { | |
create(schedule?: Schedule): Promise<Schedule>; | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<Schedule>>; | |
} | |
interface Task { | |
id: string; | |
userId: string; | |
actId: string; | |
name: string; | |
username?: string; | |
createdAt: string; | |
modifiedAt: string; | |
removedAt?: string; | |
stats?: { | |
totalRuns: number; | |
}; | |
options?: { | |
build?: string; | |
timeoutSecs?: number; | |
memoryMbytes?: number; | |
}; | |
input?: KeyValue; | |
} | |
interface TaskClient { | |
call(input?: object, options?: TaskOptions): Promise<Run>; | |
delete(): Promise<void>; | |
get(): Promise<Maybe<Task>>; | |
getInput(): Promise<Maybe<object>>; | |
lastRun(options: { status: string }): RunClient; | |
runs(): RunCollectionClient; | |
start(input?: object, options?: TaskOptions): Promise<Run>; | |
update(newFields: object): Promise<Task>; | |
updateInput(): Promise<object>; | |
webhooks(): WebhookCollectionClient; | |
} | |
interface TaskCollectionClient { | |
create(task?: object): Promise<Task>; | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<Task>>; | |
} | |
interface User { | |
username: string; | |
profile: { | |
bio?: string; | |
name?: string; | |
pictureUrl?: string; | |
githubUsername?: string; | |
websiteUrl?: string; | |
twitterUsername?: string; | |
}; | |
} | |
interface UserClient { | |
get(): Promise<Maybe<User>>; | |
} | |
interface TaskOptions { | |
build?: string; | |
memory?: number; | |
timeout?: number; | |
waitSecs?: number; | |
webhooks?: object[]; | |
} | |
interface Webhook { | |
id: string; | |
createdAt: string; | |
modifiedAt: string; | |
userId: string; | |
isAdHoc?: boolean; | |
eventTypes?: EventType[]; | |
condition: { | |
actorId?: string; | |
actorTaskId?: string; | |
actorRunId?: string; | |
}; | |
ignoreSslErrors: boolean; | |
doNotRetry?: boolean; | |
requestUrl: string; | |
payloadTemplate?: string; | |
lastDispatch?: { | |
status: string; | |
finishedAt: string; | |
}; | |
stats?: { | |
totalDispatches: number; | |
}; | |
} | |
interface WebhookCall { | |
startedAt?: string; | |
finishedAt?: string; | |
errorMessage?: string; | |
responseStatus?: number; | |
responseBody?: string; | |
} | |
interface WebhookClient { | |
delete(): Promise<void>; | |
dispatches(): WebhookDispatchCollectionClient; | |
get(): Promise<Maybe<Webhook>>; | |
update(newFields: object): Promise<Webhook>; | |
} | |
interface WebhookCollectionClient { | |
create(webhook?: object): Promise<Webhook>; | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<Webhook>>; | |
} | |
interface WebhookDispatch { | |
id: string; | |
userId: string; | |
webhookId: string; | |
createdAt: string; | |
status: string; | |
eventType: EventType; | |
eventData: { | |
actorId: string; | |
actorRunId: string; | |
}; | |
calls: WebhookCall[]; | |
} | |
interface WebhookDispatchClient { | |
get(): Promise<Maybe<WebhookDispatch>>; | |
} | |
interface WebhookDispatchCollectionClient { | |
list(options?: BaseCollectionClientProps): Promise<PaginationList<WebhookDispatch>>; | |
} | |
type DownloadItemFormat = 'json' | 'jsonl' | 'xml' | 'html' | 'csv' | 'xlsx' | 'rss'; | |
type EventType = | |
| 'ACTOR.RUN.CREATED' | |
| 'ACTOR.RUN.SUCCEEDED' | |
| 'ACTOR.RUN.FAILED' | |
| 'ACTOR.RUN.ABORTED' | |
| 'ACTOR.RUN.TIMED_OUT'; | |
type KeyValue = { [key: string]: string | number | object | null | undefined }; | |
type KeyValueStoreRecordValue = null | string | number | object; | |
type Maybe<T> = T | null | undefined; | |
export = ApifyClient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment