auto-builder-sdk
Version:
SDK for building Auto Builder workflow plugins
200 lines (199 loc) • 7.56 kB
TypeScript
export interface PluginMetadata {
name: string;
version: string;
engines: {
'auto-builder': string;
};
main: string;
nodes: string[];
sandbox?: {
enabled?: boolean;
timeoutMs?: number;
memoryMb?: number;
};
}
export declare const log: {
debug: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
info: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
error: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
};
export declare class NodeOperationError extends Error {
node?: unknown;
constructor(node: unknown, message: string);
}
/**
* Backward compatibility utility to extract input data from both old and new formats
* Handles the transition from flat JSON structure to namespaced structure
*/
export declare const extractInputData: (inputData: any[], fallbackToLegacy?: boolean) => any;
/**
* Extract data from a specific namespace in the new format
* Used when you specifically want data from a particular node type
*/
export declare const extractNamespacedData: (inputData: any[], nodeType: string) => any;
export declare class NodeApiError extends Error {
httpStatusCode?: number;
constructor(node: unknown, message: string, opts?: {
httpStatusCode?: number;
});
}
export declare class ParameterResolver {
private static deepClone;
private static getNestedValue;
private static resolveStringTemplate;
private static resolveTemplates;
static resolve(parameters: any, context: any): any;
}
export declare class BaseNodeExecutor {
resolveParameters(parameters: any, context: any): any;
getCredentials(credentialId: string): Promise<any>;
handleContinueOnFail(error: Error, node: {
continueOnFail?: boolean;
}): {
json: {
error: string;
timestamp: string;
};
binary: {};
pairedItem: {
item: number;
};
}[];
/**
* Get the position of this node among nodes of the same type in the workflow
*/
protected getWorkflowNodePosition(node: any, context: any): number;
/**
* Generate a unique prefix for this node based on its type and position in the workflow
* This automatically handles cases where the same node type appears multiple times
*/
protected generateNodePrefix(node: any, context: any): string;
/**
* Create a namespaced result object (industry standard approach)
* Instead of prefixing every key, we namespace the entire result under the node type
*/
protected createNamespacedResult(result: any, nodeType: string, nodePosition: number): any;
}
/**
* Get the position of a node among nodes of the same type in the workflow
*/
export declare const getWorkflowNodePosition: (node: any, context: any) => number;
/**
* Get stable output key for a node
* Priority:
* 1. Use node.outputKey if already saved (stable - persisted from previous execution)
* 2. Generate based on position, ensuring no collision with existing saved keys
*
* Returns both the key and whether it's newly generated.
* When isNewlyGenerated is true, the workflow engine should save outputKey to node config.
*/
export declare const getStableOutputKey: (node: any, context: any) => {
outputKey: string;
isNewlyGenerated: boolean;
workflowNodePosition: number;
};
/**
* Create a namespaced result object
* Uses the provided outputKey as the namespace key
* @param result - The result data
* @param outputKey - The namespace key to use (from getStableOutputKey)
*/
export declare const createNamespacedResult: (result: any, outputKey: string) => any;
/**
* Create a formatted result that merges input data with namespaced node results
* This prevents key conflicts while preserving all data from previous nodes
* Automatically determines the namespace based on node type and workflow position
*
* @param inputData - The input data from previous nodes
* @param result - The result data from this node's operation
* @param context - The execution context (contains node and workflow info)
* @param dataItemIndex - The index of the current data item being processed (0, 1, 2...)
* @param options - Optional configuration for output format
* @returns Formatted result object with namespaced keys
*/
export declare const createFormattedResult: (inputData: any, nodeResult: any, context: any, dataItemIndex: number, options?: {
legacyMode?: boolean;
customPrefix?: string;
includeBothFormats?: boolean;
}) => any;
/**
* Create a formatted error result that merges input data with namespaced error information
* Automatically determines the namespace based on node type and workflow position
*
* @param inputData - The input data from previous nodes
* @param error - The error that occurred
* @param context - The execution context (contains node and workflow info)
* @param dataItemIndex - The index of the current data item being processed (0, 1, 2...)
* @param options - Optional configuration for output format
* @returns Formatted error result with namespaced keys
*/
export declare const createFormattedErrorResult: (inputData: any, error: Error, context: any, dataItemIndex: number, options?: {
legacyMode?: boolean;
customPrefix?: string;
includeBothFormats?: boolean;
}) => any;
export declare const validatePlugin: <T extends PluginMetadata>(meta: T) => T;
export declare const definePlugin: <T extends PluginMetadata>(meta: T) => T;
export declare const registerCredential: (def: {
name: string;
}) => void;
export declare const getCredentialDef: (name: string) => any;
export declare const listCredentialDefinitions: () => any[];
/**
* Creates a temporary file with metadata tracking for cleanup
* Returns a reference object with file path and metadata
*
* @param buffer - Binary data to store
* @param workflowId - Workflow ID for tracking
* @param nodeId - Node ID for tracking
* @param fileName - Original filename for extension preservation
* @param metadata - Additional metadata (optional)
* @returns Promise<TempFileReference> - Reference object with file path and metadata
*/
export declare const createTempFile: (buffer: Buffer, workflowId: string, nodeId: string, fileName: string, metadata?: Record<string, any>) => Promise<{
tempFilePath: string;
tempDir: string;
metadataPath: string;
reference: {
path: string;
size: number;
originalFileName: string;
createdAt: string;
workflowId: string;
nodeId: string;
};
}>;
/**
* Reads a temporary file and returns the buffer
*
* @param tempFilePath - Path to the temporary file (string)
* @returns Promise<Buffer> - Binary data
*/
export declare const readTempFile: (tempFilePath: string) => Promise<Buffer>;
/**
* Deletes a temporary file and its metadata
*
* @param tempFilePath - Path to the temporary file (string)
* @returns Promise<void>
*/
export declare const deleteTempFile: (tempFilePath: string) => Promise<void>;
/**
* Gets metadata for a temporary file
*
* @param tempFilePath - Path to the temporary file (string)
* @returns Promise<object | null> - Metadata object or null if not found
*/
export declare const getTempFileMetadata: (tempFilePath: string) => Promise<Record<string, any> | null>;