Skip to main content

Node.js Quickstart

Use the Treeship CLI or integrate directly into your Node.js application.

CLI Installation

npm install -g treeship-cli

CLI Setup

export TREESHIP_API_KEY=your-api-key
export TREESHIP_AGENT=my-agent

CLI Usage

Create an Attestation

treeship attest \
  --action "Deployed version 2.1.0 to production" \
  --inputs-hash "sha256-of-deployment-config"

# ✓ Attestation created
#   ID        abc123-def456-...
#   Verify    https://treeship.dev/verify/my-agent/abc123...

Verify an Attestation

treeship verify abc123-def456-ghi789

# ✓ Attestation verified
#   Agent     my-agent
#   Action    Deployed version 2.1.0 to production
#   Time      2024-01-15T10:30:00.000Z

Output Formats

# JSON output for scripts
treeship attest --action "..." --inputs-hash "..." --json

# Just the URL
treeship attest --action "..." --inputs-hash "..." --quiet

Configuration

# Set defaults
treeship config set api-url https://api.treeship.dev
treeship config set default-agent my-agent

# View current config
treeship whoami

Programmatic Usage

You can also use the client directly in Node.js:
import { createHash } from 'crypto';

const API_URL = process.env.TREESHIP_API_URL || 'https://api.treeship.dev';
const API_KEY = process.env.TREESHIP_API_KEY;

async function attest(action, inputsHash) {
  const res = await fetch(`${API_URL}/v1/attest`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      agent_slug: process.env.TREESHIP_AGENT,
      action,
      inputs_hash: inputsHash,
    }),
  });
  
  if (!res.ok) throw new Error(`Attestation failed: ${res.status}`);
  return res.json();
}

// Usage
const hash = createHash('sha256')
  .update(JSON.stringify(inputData))
  .digest('hex');

const result = await attest('Processed order #123', hash);
console.log(`Verify at: ${result.public_url}`);

Environment Variables

VariableDescriptionDefault
TREESHIP_API_KEYYour API key (required)-
TREESHIP_AGENTDefault agent slug-
TREESHIP_API_URLAPI base URLhttps://api.treeship.dev

Next Steps