0.5.0 • Published 6 years ago

@shutter/api v0.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

@shutter/api NPM Version

Shutter.sh API client package.

API

import { createSnapshot, retrieveFile, loadFileFromDisk } from '@shutter/api'

createSnapshot(authToken: string, page: File, pageAssets: File[], options: SnapshotCreationOptions = {}): Promise<Snapshot>

Sends an HTML document and additional assets to the shutter.sh service for rendering. Returns a promise that resolves upon finished upload. The snapshot will not have been rendered yet (see retrieveProcessedSnapshot).

interface SnapshotCreationOptions {
  expectation?: File | null,
  diffOptions?: DiffOptions,
  labels?: Labels,
  renderOptions?: RenderOptions
}

interface DiffOptions {
  autoCrop?: boolean,
  relativeThreshold?: number
}

interface RenderOptions {
  autoCrop?: boolean,
  omitBackground?: boolean
}

type Snapshot = any   // Not yet typed

retrieveFile(fileHash: string): Promise<Buffer>

Takes a file hash as included in the Snapshot body and returns a promise that resolves to a Buffer containing the file contents.

retrieveProcessedSnapshot(snapshotID: string): Promise<Snapshot>

Takes a snapshot ID and returns a promise resolving to the rendered snapshot once the rendering has completed.

createFileFromBuffer(content: Buffer, fileName: string, options: FromBufferOptions = {}): File

Takes a Buffer and wraps it to become a File.

interface FromBufferOptions {
  contentType?: string
}

loadFileFromDisk(filePath: string, options: FromFSOptions = {}): Promise<File>

Loads a file from the file system.

interface FromFSOptions {
  contentType?: string,
  fileName?: string
}

File

interface File {
  readonly contentType: string | null
  readonly fileName: string
  getContent: () => Promise<Buffer>
}