Skip to main content

Introduction

The Cuey TypeScript client provides a type-safe, object-based interface for interacting with the Cuey REST API. It handles authentication, request formatting, error handling, and provides full TypeScript type definitions.

Features

  • Type-safe: Full TypeScript support with comprehensive type definitions
  • Easy to use: Simple API with intuitive method names
  • Environment-based: Configure using environment variables
  • Error handling: Typed error classes for different error scenarios
  • Resource-based: Organized into crons and events resources

Basic Usage

Environment Variables

Before using the client, set the required environment variable:
export CUEY_API_KEY="your-api-key-here"
Optionally, you can also set a base URL for resolving relative webhook URLs:
export CUEY_BASE_URL="https://api.example.com"

Using the Client

Import and use the default cuey instance:
import { cuey } from "cuey";

// The client automatically reads CUEY_API_KEY from environment variables
const event = await cuey.events.create({
  webhook_url: "https://api.example.com/webhook",
  scheduled_at: "2024-12-31T23:59:59Z",
  payload: { message: "Hello!" },
});
For advanced configuration options, including using multiple API keys or custom instances, see the Advanced Configuration section.

Client Structure

The cuey instance provides resource objects for managing events and cron jobs:
// Access events resource
const newEvent = await cuey.events.create({ ... });
const { data: events } = await cuey.events.list();
const event = await cuey.events.get("event-id");
await cuey.events.update("event-id", { ... });
await cuey.events.delete("event-id");

// Access crons resource
const newCron = await cuey.crons.create({ ... });
const { data: crons } = await cuey.crons.list();
const cron = await cuey.crons.get("cron-id");
await cuey.crons.update("cron-id", { ... });
await cuey.crons.delete("cron-id");

// Convenience methods
const event = await cuey.schedule({ ... }); // Alias for cuey.events.create()
const cron = await cuey.repeat({ ... });    // Alias for cuey.crons.create()

What’s Next?