> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spitshake.io/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK Libraries

> Official client libraries for React, Vue, React Native, and TypeScript/JavaScript.

# SDK Libraries

DocuTrust provides official SDK packages for embedding signing forms and template builders into your application, and for interacting with the DocuTrust API programmatically.

| Package                          | Framework               | Purpose                                                  |
| -------------------------------- | ----------------------- | -------------------------------------------------------- |
| `@docutrust/react`               | React 16.8+             | Signing form and template builder React components       |
| `@docutrust/vue`                 | Vue 3                   | Signing form and template builder Vue components         |
| `@docutrust/react-native`        | React Native            | WebView-based signing and builder components for mobile  |
| `@docutrust/angular`             | Angular 14+             | Signing form and template builder Angular components     |
| `@docutrust/api`                 | TypeScript / JavaScript | Typed API client for server-side and client-side usage   |
| `@docutrust/n8n-nodes-docutrust` | n8n                     | Custom n8n nodes for document signing automation         |
| `@docutrust/cli`                 | CLI                     | Command-line tool for managing templates and submissions |

***

## @docutrust/react

React components for embedding DocuTrust signing forms and template builders.

### Installation

```bash theme={null}
npm install @docutrust/react
```

### DocuTrustForm

Renders a signing form for a specific submitter.

```tsx theme={null}
import { DocuTrustForm } from '@docutrust/react'

function SigningPage() {
  return (
    <DocuTrustForm
      host="https://spitshake.io"
      submitterSlug="aB3kL9mNpQ"
      email="jane.doe@example.com"
      name="Jane Doe"
      role="Recipient"
      language="en"
      withTitle={true}
      withDownloadButton={true}
      withSendCopyButton={true}
      allowToResubmit={false}
      goToLast={true}
      expand={true}
      autoscroll={true}
      preview={false}
      skipFields="Internal Notes"
      readonlyFields="Contract Amount,Start Date"
      values={{
        'Full Name': 'Jane Doe',
        'Email': 'jane.doe@example.com',
        'Company': 'Acme Inc',
        'Title': 'VP of Operations',
        'Date': '2026-04-09'
      }}
      metadata={{
        customer_id: 'cust_8472',
        deal_id: 'deal_291',
        plan: 'enterprise',
        source: 'react_embed'
      }}
      completedRedirectUrl="https://your-app.com/signing-complete"
      onLoaded={(detail) => {
        console.log('Form loaded:', detail.submitter_id)
        console.log('Template:', detail.template_name)
        console.log('Role:', detail.role)
        console.log('Fields:', detail.fields.length)
      }}
      onCompleted={(detail) => {
        console.log('Completed:', detail.submission_id)
        console.log('Documents:', detail.documents)
        console.log('Values:', detail.values)
        console.log('Audit log:', detail.audit_log_url)
      }}
      onDeclined={(detail) => {
        console.log('Declined:', detail.reason)
      }}
      onFieldValue={(detail) => {
        console.log('Field changed:', detail.field_name, '=', detail.value)
        console.log('Progress:', detail.completed_fields, '/', detail.total_fields)
      }}
    />
  )
}
```

### DocuTrustBuilder

Renders the template builder for creating and editing templates.

```tsx theme={null}
import { DocuTrustBuilder } from '@docutrust/react'

function BuilderPage() {
  return (
    <DocuTrustBuilder
      host="https://spitshake.io"
      token="eyJhbGciOiJIUzI1NiJ9..."
      language="en"
      autosave={true}
      preview={true}
      withTitle={true}
      withSendButton={true}
      withRecipients={true}
      onlyDefinedFields={false}
      roles={['Sender', 'Recipient', 'Witness']}
      fields={[
        { name: 'Full Name', type: 'text', role: 'Recipient', required: true },
        { name: 'Email', type: 'text', role: 'Recipient', required: true },
        { name: 'Signature', type: 'signature', role: 'Recipient', required: true },
        { name: 'Date', type: 'date', role: 'Recipient', required: true },
        { name: 'Sender Signature', type: 'signature', role: 'Sender', required: true },
        { name: 'Witness Signature', type: 'signature', role: 'Witness', required: true }
      ]}
      onTemplateSaved={(detail) => {
        console.log('Template saved:', detail.template_id)
        console.log('Updated at:', detail.updated_at)
        console.log('Fields:', detail.fields.length)
      }}
      onSend={(detail) => {
        console.log('Send clicked:', detail.template_id)
        console.log('Roles:', detail.submitters.map(s => s.name))
      }}
      onLoaded={(detail) => {
        console.log('Builder loaded:', detail.template_id)
        console.log('Documents:', detail.documents.length)
      }}
    />
  )
}
```

### Props Reference

#### DocuTrustForm Props

| Prop                   | Type     | Required | Default | Description                                                                                           |
| ---------------------- | -------- | -------- | ------- | ----------------------------------------------------------------------------------------------------- |
| `host`                 | string   | Yes      | --      | Base URL of your DocuTrust instance                                                                   |
| `submitterSlug`        | string   | Yes      | --      | Submitter signing slug                                                                                |
| `email`                | string   | No       | --      | Pre-fill signer email                                                                                 |
| `name`                 | string   | No       | --      | Pre-fill signer name                                                                                  |
| `role`                 | string   | No       | --      | Target submitter role                                                                                 |
| `language`             | string   | No       | --      | UI language code (`en`, `es`, `fr`, `de`, `it`, `pt`, `nl`, `ar`, `cs`, `he`, `ko`, `pl`, `uk`, `ja`) |
| `withTitle`            | boolean  | No       | `true`  | Show the template title                                                                               |
| `withDownloadButton`   | boolean  | No       | `true`  | Show the download button after completion                                                             |
| `withSendCopyButton`   | boolean  | No       | `true`  | Show the "Send a copy" button                                                                         |
| `allowToResubmit`      | boolean  | No       | `false` | Allow resubmission                                                                                    |
| `goToLast`             | boolean  | No       | `false` | Jump to last incomplete field                                                                         |
| `expand`               | boolean  | No       | `false` | Expand form to full content height                                                                    |
| `autoscroll`           | boolean  | No       | `true`  | Auto-scroll to next field                                                                             |
| `preview`              | boolean  | No       | `false` | Read-only preview mode                                                                                |
| `skipFields`           | string   | No       | --      | Comma-separated field names to skip                                                                   |
| `readonlyFields`       | string   | No       | --      | Comma-separated read-only field names                                                                 |
| `values`               | object   | No       | --      | Pre-fill field values                                                                                 |
| `metadata`             | object   | No       | --      | Custom metadata                                                                                       |
| `completedRedirectUrl` | string   | No       | --      | Redirect URL after completion                                                                         |
| `onLoaded`             | function | No       | --      | Callback when form loads                                                                              |
| `onCompleted`          | function | No       | --      | Callback when signing completes                                                                       |
| `onDeclined`           | function | No       | --      | Callback when signer declines                                                                         |
| `onFieldValue`         | function | No       | --      | Callback when a field value changes                                                                   |

#### DocuTrustBuilder Props

| Prop                | Type     | Required | Default | Description                            |
| ------------------- | -------- | -------- | ------- | -------------------------------------- |
| `host`              | string   | Yes      | --      | Base URL of your DocuTrust instance    |
| `token`             | string   | No       | --      | JWT token from `POST /api/embed/token` |
| `templateId`        | number   | No       | --      | Template ID (session auth only)        |
| `language`          | string   | No       | --      | UI language code                       |
| `autosave`          | boolean  | No       | `true`  | Enable auto-save                       |
| `preview`           | boolean  | No       | `true`  | Show document preview panel            |
| `withTitle`         | boolean  | No       | `true`  | Show editable template title           |
| `withSendButton`    | boolean  | No       | `true`  | Show the "Send" button                 |
| `withRecipients`    | boolean  | No       | `true`  | Show recipients section                |
| `onlyDefinedFields` | boolean  | No       | `false` | Only show pre-defined field types      |
| `fields`            | array    | No       | --      | Pre-defined field definitions          |
| `roles`             | array    | No       | --      | Pre-defined submitter role names       |
| `onLoaded`          | function | No       | --      | Callback when builder loads            |
| `onTemplateSaved`   | function | No       | --      | Callback when template is saved        |
| `onSend`            | function | No       | --      | Callback when "Send" button is clicked |

***

## @docutrust/vue

Vue 3 components for embedding DocuTrust signing forms and template builders.

### Installation

```bash theme={null}
npm install @docutrust/vue
```

### DocuTrustForm

```vue theme={null}
<template>
  <DocuTrustForm
    host="https://spitshake.io"
    submitter-slug="aB3kL9mNpQ"
    email="jane.doe@example.com"
    name="Jane Doe"
    role="Recipient"
    language="en"
    :with-title="true"
    :with-download-button="true"
    :with-send-copy-button="true"
    :allow-to-resubmit="false"
    :go-to-last="true"
    :expand="true"
    :autoscroll="true"
    :preview="false"
    skip-fields="Internal Notes"
    readonly-fields="Contract Amount,Start Date"
    :values="{
      'Full Name': 'Jane Doe',
      'Email': 'jane.doe@example.com',
      'Company': 'Acme Inc',
      'Title': 'VP of Operations',
      'Date': '2026-04-09'
    }"
    :metadata="{
      customer_id: 'cust_8472',
      deal_id: 'deal_291',
      plan: 'enterprise',
      source: 'vue_embed'
    }"
    completed-redirect-url="https://your-app.com/signing-complete"
    @loaded="onLoaded"
    @completed="onCompleted"
    @declined="onDeclined"
    @field-value="onFieldValue"
  />
</template>

<script setup>
import { DocuTrustForm } from '@docutrust/vue'

function onLoaded(detail) {
  console.log('Form loaded:', detail.submitter_id)
  console.log('Template:', detail.template_name)
  console.log('Role:', detail.role)
  console.log('Fields:', detail.fields.length)
}

function onCompleted(detail) {
  console.log('Completed:', detail.submission_id)
  console.log('Documents:', detail.documents)
  console.log('Values:', detail.values)
  console.log('Audit log:', detail.audit_log_url)
}

function onDeclined(detail) {
  console.log('Declined:', detail.reason)
}

function onFieldValue(detail) {
  console.log('Field changed:', detail.field_name, '=', detail.value)
  console.log('Progress:', detail.completed_fields, '/', detail.total_fields)
}
</script>
```

### DocuTrustBuilder

```vue theme={null}
<template>
  <DocuTrustBuilder
    host="https://spitshake.io"
    token="eyJhbGciOiJIUzI1NiJ9..."
    language="en"
    :autosave="true"
    :preview="true"
    :with-title="true"
    :with-send-button="true"
    :with-recipients="true"
    :only-defined-fields="false"
    :roles="['Sender', 'Recipient', 'Witness']"
    :fields="[
      { name: 'Full Name', type: 'text', role: 'Recipient', required: true },
      { name: 'Email', type: 'text', role: 'Recipient', required: true },
      { name: 'Signature', type: 'signature', role: 'Recipient', required: true },
      { name: 'Date', type: 'date', role: 'Recipient', required: true },
      { name: 'Sender Signature', type: 'signature', role: 'Sender', required: true },
      { name: 'Witness Signature', type: 'signature', role: 'Witness', required: true }
    ]"
    @loaded="onBuilderLoaded"
    @template-saved="onTemplateSaved"
    @send="onSend"
  />
</template>

<script setup>
import { DocuTrustBuilder } from '@docutrust/vue'

function onBuilderLoaded(detail) {
  console.log('Builder loaded:', detail.template_id)
  console.log('Documents:', detail.documents.length)
}

function onTemplateSaved(detail) {
  console.log('Template saved:', detail.template_id)
  console.log('Updated at:', detail.updated_at)
  console.log('Fields:', detail.fields.length)
}

function onSend(detail) {
  console.log('Send clicked:', detail.template_id)
  console.log('Roles:', detail.submitters.map(s => s.name))
}
</script>
```

<Note>
  Vue components use kebab-case for props (`submitter-slug`, `with-title`) and native Vue event syntax (`@loaded`, `@completed`).
</Note>

***

## @docutrust/react-native

React Native components for embedding DocuTrust signing forms and template builders in mobile applications. Components render inside a WebView.

### Installation

```bash theme={null}
npm install @docutrust/react-native react-native-webview
```

`react-native-webview` is a required peer dependency.

### DocuTrustForm

```tsx theme={null}
import { DocuTrustForm } from '@docutrust/react-native'

function SigningScreen() {
  return (
    <DocuTrustForm
      host="https://spitshake.io"
      submitterSlug="aB3kL9mNpQ"
      email="jane.doe@example.com"
      name="Jane Doe"
      role="Recipient"
      language="en"
      withTitle={true}
      withDownloadButton={true}
      withSendCopyButton={true}
      allowToResubmit={false}
      goToLast={true}
      expand={true}
      autoscroll={true}
      preview={false}
      skipFields="Internal Notes"
      readonlyFields="Contract Amount,Start Date"
      values={{
        'Full Name': 'Jane Doe',
        'Email': 'jane.doe@example.com',
        'Company': 'Acme Inc',
        'Title': 'VP of Operations',
        'Date': '2026-04-09'
      }}
      metadata={{
        customer_id: 'cust_8472',
        deal_id: 'deal_291',
        plan: 'enterprise',
        source: 'react_native_embed'
      }}
      completedRedirectUrl="https://your-app.com/signing-complete"
      onLoaded={(detail) => {
        console.log('Form loaded:', detail.submitter_id)
        console.log('Template:', detail.template_name)
      }}
      onCompleted={(detail) => {
        console.log('Completed:', detail.submission_id)
        console.log('Documents:', detail.documents)
        console.log('Values:', detail.values)
      }}
      onDeclined={(detail) => {
        console.log('Declined:', detail.reason)
      }}
      onFieldValue={(detail) => {
        console.log('Field changed:', detail.field_name, '=', detail.value)
      }}
      style={{ flex: 1 }}
    />
  )
}
```

### DocuTrustBuilder

```tsx theme={null}
import { DocuTrustBuilder } from '@docutrust/react-native'

function BuilderScreen() {
  return (
    <DocuTrustBuilder
      host="https://spitshake.io"
      token="eyJhbGciOiJIUzI1NiJ9..."
      language="en"
      autosave={true}
      preview={true}
      withTitle={true}
      withSendButton={true}
      withRecipients={true}
      onlyDefinedFields={false}
      roles={['Sender', 'Recipient', 'Witness']}
      fields={[
        { name: 'Full Name', type: 'text', role: 'Recipient', required: true },
        { name: 'Email', type: 'text', role: 'Recipient', required: true },
        { name: 'Signature', type: 'signature', role: 'Recipient', required: true },
        { name: 'Date', type: 'date', role: 'Recipient', required: true },
        { name: 'Sender Signature', type: 'signature', role: 'Sender', required: true }
      ]}
      onLoaded={(detail) => {
        console.log('Builder loaded:', detail.template_id)
      }}
      onTemplateSaved={(detail) => {
        console.log('Template saved:', detail.template_id)
      }}
      onSend={(detail) => {
        console.log('Send clicked:', detail.template_id)
      }}
      style={{ flex: 1 }}
    />
  )
}
```

<Note>
  React Native components accept an additional `style` prop for controlling the WebView container layout. Use `flex: 1` to fill the available screen space.
</Note>

***

## @docutrust/angular

Angular components for embedding DocuTrust signing forms and template builders. Supports Angular 14 and above.

### Installation

```bash theme={null}
npm install @docutrust/angular
```

### Module Setup

Import the `DocuTrustModule` in your Angular module:

```typescript theme={null}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { DocuTrustModule } from '@docutrust/angular';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    DocuTrustModule.forRoot({
      host: 'https://spitshake.io'
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
```

### DocuTrustFormComponent

```typescript theme={null}
import { Component } from '@angular/core';

@Component({
  selector: 'app-signing-page',
  template: `
    <docutrust-form
      [submitterSlug]="'aB3kL9mNpQ'"
      [email]="'jane.doe@example.com'"
      [name]="'Jane Doe'"
      [role]="'Recipient'"
      [language]="'en'"
      [withTitle]="true"
      [withDownloadButton]="true"
      [withSendCopyButton]="true"
      [allowToResubmit]="false"
      [goToLast]="true"
      [expand]="true"
      [autoscroll]="true"
      [preview]="false"
      [skipFields]="'Internal Notes'"
      [readonlyFields]="'Contract Amount,Start Date'"
      [values]="{
        'Full Name': 'Jane Doe',
        'Email': 'jane.doe@example.com',
        'Company': 'Acme Inc',
        'Title': 'VP of Operations',
        'Date': '2026-04-09'
      }"
      [metadata]="{
        customer_id: 'cust_8472',
        deal_id: 'deal_291',
        plan: 'enterprise',
        source: 'angular_embed'
      }"
      [completedRedirectUrl]="'https://your-app.com/signing-complete'"
      (loaded)="onLoaded($event)"
      (completed)="onCompleted($event)"
      (declined)="onDeclined($event)"
      (fieldValue)="onFieldValue($event)"
    ></docutrust-form>
  `
})
export class SigningPageComponent {
  onLoaded(detail: any) {
    console.log('Form loaded:', detail.submitter_id);
    console.log('Template:', detail.template_name);
    console.log('Role:', detail.role);
    console.log('Fields:', detail.fields.length);
  }

  onCompleted(detail: any) {
    console.log('Completed:', detail.submission_id);
    console.log('Documents:', detail.documents);
    console.log('Values:', detail.values);
    console.log('Audit log:', detail.audit_log_url);
  }

  onDeclined(detail: any) {
    console.log('Declined:', detail.reason);
  }

  onFieldValue(detail: any) {
    console.log('Field changed:', detail.field_name, '=', detail.value);
    console.log('Progress:', detail.completed_fields, '/', detail.total_fields);
  }
}
```

### DocuTrustBuilderComponent

```typescript theme={null}
import { Component } from '@angular/core';

@Component({
  selector: 'app-builder-page',
  template: `
    <docutrust-builder
      [token]="'eyJhbGciOiJIUzI1NiJ9...'"
      [language]="'en'"
      [autosave]="true"
      [preview]="true"
      [withTitle]="true"
      [withSendButton]="true"
      [withRecipients]="true"
      [onlyDefinedFields]="false"
      [roles]="['Sender', 'Recipient', 'Witness']"
      [fields]="[
        { name: 'Full Name', type: 'text', role: 'Recipient', required: true },
        { name: 'Email', type: 'text', role: 'Recipient', required: true },
        { name: 'Signature', type: 'signature', role: 'Recipient', required: true },
        { name: 'Date', type: 'date', role: 'Recipient', required: true },
        { name: 'Sender Signature', type: 'signature', role: 'Sender', required: true },
        { name: 'Witness Signature', type: 'signature', role: 'Witness', required: true }
      ]"
      (loaded)="onBuilderLoaded($event)"
      (templateSaved)="onTemplateSaved($event)"
      (send)="onSend($event)"
    ></docutrust-builder>
  `
})
export class BuilderPageComponent {
  onBuilderLoaded(detail: any) {
    console.log('Builder loaded:', detail.template_id);
    console.log('Documents:', detail.documents.length);
  }

  onTemplateSaved(detail: any) {
    console.log('Template saved:', detail.template_id);
    console.log('Updated at:', detail.updated_at);
    console.log('Fields:', detail.fields.length);
  }

  onSend(detail: any) {
    console.log('Send clicked:', detail.template_id);
    console.log('Roles:', detail.submitters.map((s: any) => s.name));
  }
}
```

<Note>
  Angular components use property binding syntax (`[prop]="value"`) and event binding syntax (`(event)="handler($event)"`).
</Note>

***

## @docutrust/n8n-nodes-docutrust

Custom n8n nodes for automating document signing workflows. Provides trigger and action nodes that integrate directly with the n8n visual workflow editor.

### Installation

Install the community node in your n8n instance:

```bash theme={null}
npm install @docutrust/n8n-nodes-docutrust
```

Or install via the n8n community nodes UI: **Settings > Community Nodes > Install > `@docutrust/n8n-nodes-docutrust`**.

### Available Nodes

#### DocuTrust Trigger

Listens for webhook events from DocuTrust and starts a workflow when they fire.

**Supported trigger events:**

| Event                  | Description                               |
| ---------------------- | ----------------------------------------- |
| `form.completed`       | A submitter completed their signing form. |
| `form.declined`        | A submitter declined to sign.             |
| `form.viewed`          | A submitter opened the signing link.      |
| `submission.completed` | All submitters completed the submission.  |
| `submission.expired`   | The submission expired.                   |
| `template.created`     | A new template was created.               |
| `template.updated`     | A template was modified.                  |

#### DocuTrust Action

Performs operations against the DocuTrust API.

**Supported operations:**

| Resource   | Operation     | Description                                 |
| ---------- | ------------- | ------------------------------------------- |
| Template   | List          | List all templates with optional filters.   |
| Template   | Get           | Retrieve a single template by ID.           |
| Template   | Clone         | Create a copy of an existing template.      |
| Submission | Create        | Create a new submission from a template.    |
| Submission | Get           | Retrieve a submission by ID.                |
| Submission | List          | List submissions with optional filters.     |
| Submission | Send Reminder | Send reminder emails to pending submitters. |
| Submitter  | Get           | Retrieve a submitter by ID.                 |
| Submitter  | Update        | Update submitter details and field values.  |

### Credential Setup

1. In n8n, go to **Credentials > New Credential > DocuTrust API**.
2. Enter your DocuTrust instance URL and API token.
3. Click **Test** to verify the connection.

```json theme={null}
{
  "baseUrl": "https://spitshake.io",
  "apiToken": "YOUR_API_TOKEN"
}
```

### Example Workflow

A workflow that creates a submission when a new row is added to Google Sheets, then sends a Slack notification when signing completes:

1. **Google Sheets Trigger** -- fires when a new row is added.
2. **DocuTrust Action** -- creates a submission with data from the spreadsheet row.
3. **DocuTrust Trigger** -- listens for `form.completed` events.
4. **Slack Action** -- posts a notification to a channel.

***

## @docutrust/cli

A command-line tool for managing templates, submissions, and account settings from the terminal. Useful for scripting, CI/CD pipelines, and batch operations.

### Installation

```bash theme={null}
npm install -g @docutrust/cli
```

### Configuration

Set your DocuTrust instance URL and API token:

```bash theme={null}
docutrust config set --host https://spitshake.io --token YOUR_API_TOKEN
```

The configuration is stored in `~/.docutrustrc`:

```json theme={null}
{
  "host": "https://spitshake.io",
  "token": "YOUR_API_TOKEN"
}
```

### Commands

#### Templates

```bash theme={null}
# List all templates
docutrust templates list

# List templates in a folder
docutrust templates list --folder "Legal Contracts"

# Get a single template
docutrust templates get 42

# Create a template from a PDF file
docutrust templates create --name "Service Agreement" --file ./contract.pdf

# Clone a template
docutrust templates clone 42 --name "Service Agreement - West Region"

# Archive a template
docutrust templates archive 42
```

#### Submissions

```bash theme={null}
# List all submissions
docutrust submissions list

# List with filters
docutrust submissions list --status pending --template-id 42 --limit 25

# Create a submission
docutrust submissions create --template-id 42 \
  --submitter "Client:jane@example.com:Jane Smith" \
  --submitter "Company Representative:bob@acme.com:Bob Johnson" \
  --send-email

# Get a single submission
docutrust submissions get 187

# Send a reminder
docutrust submissions remind 187

# Download completed documents
docutrust submissions download 187 --output ./signed-docs/

# Download as merged PDF
docutrust submissions download 187 --merge --output ./signed-contract.pdf

# Archive a submission
docutrust submissions archive 187
```

#### Bulk Operations

```bash theme={null}
# Bulk send from a CSV file
docutrust submissions bulk-create --template-id 42 --csv ./recipients.csv --send-email

# CSV format: role,email,name,field_key_1,field_key_2,...
# Client,jane@example.com,Jane Smith,Acme Corp,2026-04-08
```

#### Settings

```bash theme={null}
# View account settings
docutrust settings get

# Update a setting
docutrust settings update --company-name "Acme Inc" --timezone "America/New_York"

# View webhooks
docutrust webhooks list

# Create a webhook
docutrust webhooks create --url https://yourapp.com/webhooks/docutrust \
  --events form.completed,submission.completed
```

<Tip>
  Use `docutrust --help` or `docutrust <command> --help` for detailed usage information on any command.
</Tip>

***

## @docutrust/api

A typed TypeScript/JavaScript client for the DocuTrust REST API. Works in Node.js, Deno, Bun, and browser environments.

### Installation

```bash theme={null}
npm install @docutrust/api
```

### Configuration

```ts theme={null}
import { DocuTrust } from '@docutrust/api'

const client = new DocuTrust({
  baseUrl: 'https://spitshake.io',
  apiToken: 'YOUR_API_TOKEN'
})
```

### Templates

```ts theme={null}
// List all templates
const templates = await client.templates.list()

// List with pagination
const page = await client.templates.list({ limit: 10, after: 'cursor_abc123' })

// Get a single template
const template = await client.templates.get(15)

// Update a template
const updated = await client.templates.update(15, {
  name: 'Updated Employment Agreement',
  folder_name: 'HR Documents'
})

// Archive a template
await client.templates.archive(15)

// Clone a template
const clone = await client.templates.clone(15, { name: 'Employment Agreement (Copy)' })

// Create from PDF
const fromPdf = await client.templates.createFromPdf({
  name: 'New Contract',
  documents: [
    { name: 'contract.pdf', file: pdfBuffer }
  ]
})

// Create from DOCX
const fromDocx = await client.templates.createFromDocx({
  name: 'Offer Letter',
  documents: [
    { name: 'offer.docx', file: docxBuffer }
  ]
})

// Create from HTML
const fromHtml = await client.templates.createFromHtml({
  name: 'Invoice',
  html: '<html><body><h1>Invoice #{{number}}</h1></body></html>'
})
```

### Submissions

```ts theme={null}
// Create a submission
const submission = await client.submissions.create({
  template_id: 15,
  send_email: true,
  submitters_order: 'random',
  submitters: [
    {
      email: 'signer@example.com',
      name: 'Jane Doe',
      role: 'Recipient',
      phone: '+15551234567',
      values: {
        'Full Name': 'Jane Doe',
        'Company': 'Acme Inc'
      },
      metadata: {
        customer_id: 'cust_8472'
      },
      send_email: true,
      send_sms: false
    }
  ],
  message: {
    subject: 'Please sign your employment agreement',
    body: 'Hi {{name}}, please review and sign the attached document.'
  },
  metadata: {
    deal_id: 'deal_291',
    source: 'api_client'
  }
})

// Create from emails
const fromEmails = await client.submissions.createFromEmails({
  template_id: 15,
  emails: 'signer1@example.com, signer2@example.com'
})

// List submissions
const submissions = await client.submissions.list()

// List with filters
const filtered = await client.submissions.list({
  template_id: 15,
  status: 'completed',
  limit: 25,
  after: 'cursor_xyz789'
})

// Get a single submission
const detail = await client.submissions.get(89)

// Archive a submission
await client.submissions.archive(89)

// List submission documents
const documents = await client.submissions.listDocuments(89)

// Download submission documents (merged PDF)
const pdfBlob = await client.submissions.downloadDocuments(89)
```

### Download documents

```typescript theme={null}
// Download a signed PDF as binary
const buffer = await client.submissions.downloadDocument(submissionId, documentId)
```

### Submitters

```ts theme={null}
// List submitters
const submitters = await client.submitters.list()

// List with filters
const filtered = await client.submitters.list({
  submission_id: 89,
  status: 'completed'
})

// Get a single submitter
const submitter = await client.submitters.get(142)

// Update a submitter
const updated = await client.submitters.update(142, {
  name: 'Jane M. Doe',
  email: 'jane.m.doe@example.com',
  phone: '+15559876543',
  values: {
    'Title': 'Senior VP of Operations'
  },
  metadata: {
    updated_by: 'admin'
  }
})

// Send reminder
await client.submitters.sendReminder(142)
```

### Webhooks

```ts theme={null}
// List webhooks
const webhooks = await client.webhooks.list()

// Create a webhook
const webhook = await client.webhooks.create({
  url: 'https://your-app.com/webhooks/docutrust',
  events: [
    'form.completed',
    'form.declined',
    'form.delegated',
    'submission.completed',
    'submission.archived'
  ],
  secret: 'whsec_your_webhook_secret'
})

// Update a webhook
const updated = await client.webhooks.update(webhook.id, {
  url: 'https://your-app.com/webhooks/docutrust-v2',
  events: ['form.completed', 'submission.completed']
})

// Delete a webhook
await client.webhooks.delete(webhook.id)

// Send a test webhook
await client.webhooks.sendTest(webhook.id)

// Regenerate secret
const newSecret = await client.webhooks.regenerateSecret(webhook.id)
```

### Users

```ts theme={null}
// List users
const users = await client.users.list()

// Get current user
const me = await client.users.getCurrent()

// Invite a user
const invited = await client.users.invite({
  email: 'newuser@example.com',
  first_name: 'New',
  last_name: 'User',
  role: 'admin'
})

// Update a user
const updated = await client.users.update(5, {
  first_name: 'Updated',
  last_name: 'Name'
})

// Archive a user
await client.users.archive(5)

// Restore an archived user
await client.users.restore(5)
```

### Settings

```ts theme={null}
// Get account settings
const settings = await client.settings.get()

// Update settings
const updated = await client.settings.update({
  company_name: 'Acme Inc',
  timezone: 'America/New_York'
})

// Get SMTP settings
const smtp = await client.settings.getSmtp()

// Update SMTP settings
await client.settings.updateSmtp({
  host: 'smtp.example.com',
  port: 587,
  username: 'noreply@example.com',
  password: 'smtp_password',
  from_email: 'noreply@example.com',
  from_name: 'Acme Inc'
})

// Test SMTP configuration
await client.settings.testSmtp()
```

### Audit Events

```typescript theme={null}
// List audit events
const { data } = await client.auditEvents.list({
  event_type: 'submission.completed',
  from: '2026-01-01',
  per_page: 50
})
```

### Error Handling

```ts theme={null}
import { DocuTrust, DocuTrustError } from '@docutrust/api'

const client = new DocuTrust({
  baseUrl: 'https://spitshake.io',
  apiToken: 'YOUR_API_TOKEN'
})

try {
  const submission = await client.submissions.create({
    template_id: 999,
    submitters: [{ email: 'signer@example.com' }]
  })
} catch (error) {
  if (error instanceof DocuTrustError) {
    console.error('Status:', error.status)       // 404
    console.error('Message:', error.message)      // "Template not found"
    console.error('Code:', error.code)            // "not_found"
    console.error('Details:', error.details)       // Additional error context
  }
}
```

### TypeScript Types

The client exports TypeScript types for all request and response objects:

```ts theme={null}
import type {
  Template,
  TemplateListParams,
  Submission,
  SubmissionCreateParams,
  Submitter,
  SubmitterUpdateParams,
  Webhook,
  WebhookCreateParams,
  User,
  UserInviteParams,
  AccountSettings,
  AccountSettingsUpdateParams,
  PaginatedResponse,
  DocuTrustErrorResponse
} from '@docutrust/api'
```
