@shutter/api
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

@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>
}

Readme

Keywords

none

Package Sidebar

Install

npm i @shutter/api

Weekly Downloads

0

Version

0.5.0

License

MIT

Unpacked Size

10.2 kB

Total Files

9

Last publish

Collaborators

  • andywer