Installation

Requirements

  • Node.js 18+ (uses fetch natively)
  • TypeScript 5+ recommended

Install the package

bash
# npm
npm install @clockwork/sdk
 
# pnpm
pnpm add @clockwork/sdk
 
# yarn
yarn add @clockwork/sdk

Initialize the client

typescript
import { Clockwork } from '@clockwork/sdk'
 
const client = new Clockwork({
  apiKey: process.env.CLOCKWORK_API_KEY,
})

The client constructor accepts:

OptionTypeRequiredDescription
apiKeystringone ofck_live_... key from the developer console
sessionTokenstring | () => Promise<string | null>one ofSupabase JWT for browser use
baseUrlstringnoOverride API base URL (default: https://platform.clockwork-co.com)
fetchtypeof fetchnoCustom fetch implementation

Either apiKey or sessionToken is required. If neither is provided, the constructor throws.

TypeScript

All SDK methods are fully typed. Inputs, responses, and enums are exported from the package:

typescript
import { Clockwork } from '@clockwork/sdk'
import type { Task, CreateTaskInput, TaskStatus } from '@clockwork/sdk'

Use in Next.js (server-side)

typescript
// lib/clockwork.ts
import { Clockwork } from '@clockwork/sdk'
 
export const clockwork = new Clockwork({
  apiKey: process.env.CLOCKWORK_API_KEY!,
})

Use in Next.js (client-side with Supabase auth)

typescript
import { Clockwork } from '@clockwork/sdk'
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
 
const supabase = createClientComponentClient()
 
const client = new Clockwork({
  sessionToken: async () => {
    const { data } = await supabase.auth.getSession()
    return data.session?.access_token ?? null
  },
})

Pass sessionToken as a function so the client fetches a fresh token on each request, avoiding JWT expiry issues.

Custom fetch

For environments without native fetch (Node < 18, edge runtimes with custom polyfills):

typescript
import { Clockwork } from '@clockwork/sdk'
import nodeFetch from 'node-fetch'
 
const client = new Clockwork({
  apiKey: process.env.CLOCKWORK_API_KEY,
  fetch: nodeFetch as typeof fetch,
})