Skip to main content

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.

Instance Methods
MethodReturnsDescription
.action(slug, defaults?)ActionGet an action by slug. Optionally pass default settings.
.pipeline(steps)PipelineChain actions together. Takes an array of configured actions.
.createAction(name, steps)CustomActionSave 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; }
Compressorapp.action("compressor")

Reduce file sizes with format-aware compression.

const action = app.action("compressor"); action.set(property, value); const result = await action.run(files);
Accepts:Any filemax -1
Properties
IDTypeDefaultDescription
resize_method"smooth" | "lanczos" | "pixelated""smooth"Resize Method
Helper:
resize_fit"scale" | "contain" | "cover""scale"Resize Fit
Helper:
resizenumber100Resize
Helper:
Range: 0500
jpeg_mode"lossless" | "balanced" | "maximum""balanced"JPEG Mode
Helper:
jpeg_encoder"mozjpeg" | "standard""mozjpeg"Encoder
Helper:
jpeg_qualitynumber85JPEG Quality
Helper:
Range: 1100
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_smoothingnumber0Smoothing
Helper:
Range: 0100
jpeg_separate_chroma_qualitybooleanfalseSplit Chroma
Helper:
jpeg_chroma_qualitynumber70Chroma Quality
Helper:
Range: 1100
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_quantizenumber256PNG Quantize
Helper:
Range: 2256
png_deflate_method"standard" | "zopfli""standard"PNG Deflate Method
Helper:
png_optimizationnumber2PNG Optimization
Helper:
Range: 16
webp_qualitynumber100WebP Quality
Helper:
Range: 1100
gif_qualitynumber100GIF Quality
Helper:
Range: 1100
palette_sizenumber256Palette Size
Helper:
Range: 2256
pdf_qualitynumber100PDF Quality
Helper:
Range: 1100
qualitynumber100Quality
Helper:
Range: 1100
svg_minifybooleanfalseSVG Minify
Helper:
svg_remove_commentsbooleanfalseSVG Remove Comments
Helper:
metadata_editorunknown[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:
ReturnsPromise<ActionResult[]>
Assemblyapp.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);
Accepts:Any filemax -1
Properties
IDTypeDefaultDescription
pattern_pdfstring"{"rule":"concatenate","ratios":[],"st..."Pattern PDF
Helper:
pattern_imagestring"{}"Pattern Image
Helper:
background_colorstring"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
ReturnsPromise<ActionResult[]>
Extractorapp.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);
Accepts:Any filemax -1
Properties
IDTypeDefaultDescription
extract_method"auto" | "pages" | "images" | "text""auto"Extract Method
Helper:
selectionstring"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
ReturnsPromise<ActionResult[]>
Transformapp.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);
Accepts:Any filemax -1
Properties
IDTypeDefaultDescription
resize_method"smooth" | "lanczos" | "pixelated""smooth"Resize Method
Helper:
resize_fit"scale" | "contain" | "cover""scale"Resize Fit
Helper:
resizenumber100Resize
Helper:
Range: 0500
shapeunknown"{"region":{"x":0,"y":0,"w":1,"h":1},"..."Shape
Helper:
cropunknown[object Object]Crop
Helper:
feathernumber0Feather
Helper:
Range: 01
background_colorstring"transparent"Background Color
Helper:
alpha_bleednumber0Alpha Bleed
Helper:
Range: 01
ReturnsPromise<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); });
Pipeline Methods
MethodReturnsDescription
.run(files, onProgress?)Promise<ActionResult[]>Runs every step in order. Pass an optional callback to track progress.
.addStep(action)PipelineAppend 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.

FieldTypeDescription
blobBlobThe raw file data.
namestringFilename with extension.
sizenumberSize in bytes.
timestampnumberWhen the file was generated (unix ms).