API Reference
Everything runs through actions. Configure one, run it on files, get results back. This page covers every action, property, and method in the SDK.
Overview
The SDK has two things: Actions (configure and run on files) and Pipelines (chain actions so each step's output feeds the next). All processing runs locally through WebAssembly. Files stay on the machine.
Initialization
import { Enclave } from '@enclave/sdk';
const app = new Enclave({
key: process.env.ENCLAVE_KEY
});Create an Enclave instance with your API key. From there you can create actions, build pipelines, and register custom actions.
| Method | Returns | Description |
|---|---|---|
| .action(slug, defaults?) | Action | Get an action by slug. Optionally pass default settings. |
| .pipeline(steps) | Pipeline | Chain actions together. Takes an array of configured actions. |
| .createAction(name, steps) | CustomAction | Save a pipeline as a reusable action with its own name and variants. |
| .getActions() | ActionDef[] | Returns every available action with its property schema. |
Actions
Call .set() to configure, .run() to execute, and .getProperties() to see what you can configure.
interface Action {
set(property: string, value: unknown): Action; // chainable
run(files: File[]): Promise<ActionResult[]>;
getProperties(): PropertyDef[];
reset(): Action;
}app.action("compressor")Reduce file sizes with format-aware compression.
const action = app.action("compressor");
action.set(property, value);
const result = await action.run(files);| ID | Type | Default | Description |
|---|---|---|---|
| resize_method | "smooth" | "lanczos" | "pixelated" | "smooth" | Resize Method Helper: |
| resize_fit | "scale" | "contain" | "cover" | "scale" | Resize Fit Helper: |
| resize | number | 100 | Resize Helper: Range: 0–500 |
| jpeg_mode | "lossless" | "balanced" | "maximum" | "balanced" | JPEG Mode Helper: |
| jpeg_encoder | "mozjpeg" | "standard" | "mozjpeg" | Encoder Helper: |
| jpeg_quality | number | 85 | JPEG Quality Helper: Range: 1–100 |
| jpeg_chroma_subsampling | "auto" | "444" | "422" | "420" | "gray" | "auto" | Chroma Subsampling Helper: |
| jpeg_quantization_table | "auto" | "annex_k" | "flat" | "ms_ssim" | "psnr_hvs" | "imagick" | "klein" | "watson" | "ahumada" | "peterson" | "auto" | Quant Table Helper: |
| jpeg_smoothing | number | 0 | Smoothing Helper: Range: 0–100 |
| jpeg_separate_chroma_quality | boolean | false | Split Chroma Helper: |
| jpeg_chroma_quality | number | 70 | Chroma Quality Helper: Range: 1–100 |
| jpeg_progressive | "auto" | "progressive" | "baseline" | "auto" | Progressive Helper: |
| jpeg_optimization | "auto" | "full" | "huffman" | "none" | "auto" | JPEG Optimization Helper: |
| jpeg_metadata | "keep_all" | "keep_icc" | "strip_all" | "strip_all" | JPEG Metadata Helper: |
| png_mode | "lossless" | "balanced" | "maximum" | "balanced" | PNG Mode Helper: |
| png_quantize_method | "standard" | "imagequant" | "standard" | PNG Quantize Method Helper: |
| dither_method | "floyd_steinberg" | "stucki" | "atkinson" | "jarvis" | "burkes" | "sierra" | "sierra_lite" | "none" | "floyd_steinberg" | Dither Method Helper: |
| png_quantize | number | 256 | PNG Quantize Helper: Range: 2–256 |
| png_deflate_method | "standard" | "zopfli" | "standard" | PNG Deflate Method Helper: |
| png_optimization | number | 2 | PNG Optimization Helper: Range: 1–6 |
| webp_quality | number | 100 | WebP Quality Helper: Range: 1–100 |
| gif_quality | number | 100 | GIF Quality Helper: Range: 1–100 |
| palette_size | number | 256 | Palette Size Helper: Range: 2–256 |
| pdf_quality | number | 100 | PDF Quality Helper: Range: 1–100 |
| quality | number | 100 | Quality Helper: Range: 1–100 |
| svg_minify | boolean | false | SVG Minify Helper: |
| svg_remove_comments | boolean | false | SVG Remove Comments Helper: |
| metadata_editor | unknown | [object Object] | Metadata Editor Helper: |
| output | "auto" | "png" | "jpg" | "webp" | "gif" | "svg" | "avif" | "bmp" | "tiff" | "pdf" | "txt" | "mp4" | "webm" | "mov" | "mkv" | "avi" | "flv" | "wmv" | "m4v" | "ogv" | "mp3" | "wav" | "aac" | "flac" | "ogg" | "m4a" | "opus" | "wma" | "auto" | Output |
| archive_format | "none" | "zip" | "tar.gz" | "none" | Archive Format Helper: |
Promise<ActionResult[]>app.action("assembly")Combine files by merging PDFs or tiling images together.
const action = app.action("assembly");
action.set(property, value);
const result = await action.run(files);| ID | Type | Default | Description |
|---|---|---|---|
| pattern_pdf | string | "{"rule":"concatenate","ratios":[],"st..." | Pattern PDF Helper: |
| pattern_image | string | "{}" | Pattern Image Helper: |
| background_color | string | "transparent" | Background Color Helper: |
| output | "auto" | "png" | "jpg" | "webp" | "gif" | "svg" | "avif" | "bmp" | "tiff" | "pdf" | "txt" | "mp4" | "webm" | "mov" | "mkv" | "avi" | "flv" | "wmv" | "m4v" | "ogv" | "mp3" | "wav" | "aac" | "flac" | "ogg" | "m4a" | "opus" | "wma" | "auto" | Output |
Promise<ActionResult[]>app.action("extractor")Split files into pages, images, text, or frames.
const action = app.action("extractor");
action.set(property, value);
const result = await action.run(files);| ID | Type | Default | Description |
|---|---|---|---|
| extract_method | "auto" | "pages" | "images" | "text" | "auto" | Extract Method Helper: |
| selection | string | "all" | Selection Helper: |
| output | "auto" | "png" | "jpg" | "webp" | "gif" | "svg" | "avif" | "bmp" | "tiff" | "pdf" | "txt" | "mp4" | "webm" | "mov" | "mkv" | "avi" | "flv" | "wmv" | "m4v" | "ogv" | "mp3" | "wav" | "aac" | "flac" | "ogg" | "m4a" | "opus" | "wma" | "auto" | Output |
Promise<ActionResult[]>app.action("transform")Resize, crop, rotate, and modify files without changing format.
const action = app.action("transform");
action.set(property, value);
const result = await action.run(files);| ID | Type | Default | Description |
|---|---|---|---|
| resize_method | "smooth" | "lanczos" | "pixelated" | "smooth" | Resize Method Helper: |
| resize_fit | "scale" | "contain" | "cover" | "scale" | Resize Fit Helper: |
| resize | number | 100 | Resize Helper: Range: 0–500 |
| shape | unknown | "{"region":{"x":0,"y":0,"w":1,"h":1},"..." | Shape Helper: |
| crop | unknown | [object Object] | Crop Helper: |
| feather | number | 0 | Feather Helper: Range: 0–1 |
| background_color | string | "transparent" | Background Color Helper: |
| alpha_bleed | number | 0 | Alpha Bleed Helper: Range: 0–1 |
Promise<ActionResult[]>Pipelines
A pipeline runs actions in sequence. Output from step 1 goes into step 2, and so on.
const pipeline = app.pipeline([
app.action('compressor', { quality: 60 }),
app.action('assembly', { output: 'pdf', pattern_pdf: { rule: 'alternate' } })
]);
const results = await pipeline.run(inputFiles, (progress) => {
console.log(progress.stepName, progress.stepProgress);
});| Method | Returns | Description |
|---|---|---|
| .run(files, onProgress?) | Promise<ActionResult[]> | Runs every step in order. Pass an optional callback to track progress. |
| .addStep(action) | Pipeline | Append another action. Chainable. |
| .getSteps() | Action[] | Returns the steps in order. |
Custom Actions
A custom action is a saved pipeline with a name. Once saved, it works like any built-in action and can have its own variants.
// Create a reusable custom action
const webOptimizer = app.createAction('Web Optimizer', [
app.action('compressor', { quality: 75 }),
app.action('assembly', { output: 'webp' })
]);
// Use it like any other action
const optimized = await webOptimizer.run(uploadedImages);
// Custom actions have isolated variants
webOptimizer.saveVariant('High Quality', { quality: 95 });
webOptimizer.saveVariant('Thumbnail', { quality: 50 });ActionResult
Calling .run() gives you back an array of ActionResult objects, one per output file.
| Field | Type | Description |
|---|---|---|
| blob | Blob | The raw file data. |
| name | string | Filename with extension. |
| size | number | Size in bytes. |
| timestamp | number | When the file was generated (unix ms). |