import { Readable, Writable } from "stream"; export type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue; }; export type SendPayload = any; export interface SendConfigHTTPKv { [key: string]: string; } export interface SendConfigHTTPAuth { username: string; password: string; } export type UppercaseHTTPMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH"; export interface SendConfigHTTP { method?: UppercaseHTTPMethod; url: string; headers?: SendConfigHTTPKv; params?: SendConfigHTTPKv; auth?: SendConfigHTTPAuth; data?: SendPayload; } export interface SendConfigS3 { bucket: string; prefix: string; payload: SendPayload; } export interface SendConfigEmail { subject: string; text?: string; html?: string; } export interface SendConfigEmit { raw_event: SendPayload; } export interface SendConfigSSE { channel: string; payload: SendPayload; } export interface SendFunctionsWrapper { http: (config: SendConfigHTTP) => void; email: (config: SendConfigEmail) => void; emit: (config: SendConfigEmit) => void; s3: (config: SendConfigS3) => void; sse: (config: SendConfigSSE) => void; } /** * Http Response. */ export interface HTTPResponse { /** * HTTP Status */ status: number; /** * Http Body */ body: string | Buffer | Readable; /** * If true, issue the response when the promise returned is resolved, otherwise issue * the response at the end of the workflow execution */ immediate?: boolean; } export interface Methods { [key: string]: (...args: any) => unknown; } export interface FlowFunctions { exit: (reason: string) => void; delay: (ms: number, context: object) => { resume_url: string; cancel_url: string; }; rerun: (ms: number, context: object) => { resume_url: string; cancel_url: string; }; suspend: (ms: number, context: object) => { resume_url: string; cancel_url: string; }; refreshTimeout: () => string; } export interface IApi { open(path: string): IFile; openDescriptor(descriptor: any): IFile; dir(path?: string): AsyncGenerator<{ isDirectory: () => boolean; isFile: () => boolean; path: string; name: string; size?: number; modifiedAt?: Date; file?: IFile; }>; } export interface IFile { delete(): Promise; createReadStream(): Promise; createWriteStream(contentType?: string, contentLength?: number): Promise; toEncodedString(encoding?: string, start?: number, end?: number): Promise; toUrl(): Promise; toFile(localFilePath: string): Promise; toBuffer(): Promise; fromReadableStream(readableStream: Readable, contentType?: string, contentSize?: number): Promise; fromFile(localFilePath: string, contentType?: string): Promise; fromUrl(url: string, options?: any): Promise; toJSON(): any; } export interface Pipedream { export: (key: string, value: JSONValue) => void; send: SendFunctionsWrapper; /** * Respond to an HTTP interface. * @param response Define the status and body of the request. * @returns A promise that is fulfilled when the body is read or an immediate response is issued */ respond: (response: HTTPResponse) => Promise | void; flow: FlowFunctions; files: IApi; } export interface OptionsMethodArgs { page?: number; prevContext?: any; [key: string]: any; } export interface OptionalOptsFn { (configuredProps: { [key: string]: any; }): object; } export type PropDefinition = [ App, string ] | [ App, string, OptionalOptsFn ]; export interface PropDefinitionReference { propDefinition: PropDefinition; } export interface App { type: "app"; app: string; propDefinitions?: AppPropDefinitions; methods?: Methods & ThisType; } export declare function defineApp(app: App): App; export interface DefaultConfig { intervalSeconds?: number; cron?: string; } export interface Field { name: string; value: string; } export interface HttpAuth { type?: "basic" | "bearer" | "none"; username?: string; password?: string; token?: string; } export interface HttpBody { type?: "fields" | "raw"; contentType?: string; fields?: Field[]; mode?: "fields" | "raw"; raw?: string; } export interface DefaultHttpRequestPropConfig { auth?: HttpAuth; body?: HttpBody; headers?: Field[]; params?: Field[]; tab?: string; method?: string; url?: string; } export interface BasePropInterface { label?: string; description?: string; } export type PropOptions = any[] | Array<{ [key: string]: string; }>; export interface UserProp extends BasePropInterface { type: "boolean" | "boolean[]" | "integer" | "integer[]" | "string" | "string[]" | "object" | "any"; options?: PropOptions | ((this: any, opts: OptionsMethodArgs) => Promise); optional?: boolean; default?: JSONValue; secret?: boolean; min?: number; max?: number; disabled?: boolean; hidden?: boolean; } export interface InterfaceProp extends BasePropInterface { type: "$.interface.http" | "$.interface.timer"; default?: string | DefaultConfig; } export interface ServiceDBProp extends BasePropInterface { type: "$.service.db"; } export interface DataStoreProp extends BasePropInterface { type: "data_store"; } export interface HttpRequestProp extends BasePropInterface { type: "http_request"; default?: DefaultHttpRequestPropConfig; } export interface SourcePropDefinitions { [name: string]: PropDefinitionReference | App | UserProp | InterfaceProp | ServiceDBProp | HttpRequestProp; } export interface ActionPropDefinitions { [name: string]: PropDefinitionReference | App | UserProp | DataStoreProp | HttpRequestProp; } export interface AppPropDefinitions { [name: string]: PropDefinitionReference | App | UserProp; } export interface Hooks { deploy?: () => Promise; activate?: () => Promise; deactivate?: () => Promise; } export type SourceHttpRunOptions = { method: string; path: string; query: { [key: string]: string; }; headers: { [key: string]: string; }; bodyRaw?: string; body?: { [key: string]: JSONValue; }; }; export type SourceTimerRunOptions = { timestamp: number; interval_seconds: number; }; export type SourceRunOptions = SourceHttpRunOptions | SourceTimerRunOptions; export interface ActionRunOptions { $: Pipedream; steps: JSONValue; } export interface EmitMetadata { id?: string | number; name?: string; summary?: string; ts?: number; } export interface IdEmitMetadata extends EmitMetadata { id: string | number; } type EmitFunction = { $emit: (event: JSONValue, metadata?: EmitMetadata) => Promise; }; type IdEmitFunction = { $emit: (event: JSONValue, metadata: IdEmitMetadata) => Promise; }; type PropThis = { [Prop in keyof Props]: Props[Prop] extends App ? any : any; }; interface BaseSource { key: string; name?: string; description?: string; version: string; type: "source"; methods?: Methods & ThisType & Methods & EmitFunction>; hooks?: Hooks & ThisType & Methods & EmitFunction>; props?: SourcePropDefinitions; dedupe?: "last" | "greatest" | "unique"; additionalProps?: (previousPropDefs: SourcePropDefinitions) => Promise; run: (this: PropThis & Methods & EmitFunction, options?: SourceRunOptions) => void | Promise; } export interface DedupedSource extends BaseSource { dedupe: "last" | "greatest" | "unique"; run: (this: PropThis & Methods & IdEmitFunction, options?: SourceRunOptions) => void | Promise; } export interface NonDedupedSource extends BaseSource { dedupe?: never; } export type Source = DedupedSource | NonDedupedSource; export declare function defineSource(component: Source): Source; export interface Action { key: string; name?: string; description?: string; version: string; type: "action"; methods?: Methods & ThisType & Methods>; props?: ActionPropDefinitions; annotations?: { destructiveHint?: boolean; idempotentHint?: boolean; openWorldHint?: boolean; readOnlyHint?: boolean; }; additionalProps?: (previousPropDefs: ActionPropDefinitions) => Promise; run: (this: PropThis & Methods, options?: ActionRunOptions) => any; } export declare function defineAction(component: Action): Action; export {};