@timbrix/sdk
v0.3.1
Published
TypeScript SDK for Timbrix API
Downloads
171
Readme
@timbrix/sdk
TypeScript/JavaScript client for the Timbrix API.
Installation
npm install @timbrix/sdk
# or
pnpm add @timbrix/sdk
# or
yarn add @timbrix/sdkUsage
With API Key (Machine-to-Machine)
import { TimbrixClient } from "@timbrix/sdk"
const client = new TimbrixClient({
apiKey: "sk_live_abc123...",
baseUrl: "https://api.timbrix.com", // optional, defaults to localhost
})
// List webhooks
const webhooks = await client.webhooks.list("organization-id")
// Create webhook
const webhook = await client.webhooks.create("organization-id", {
url: "https://example.com/webhooks",
events: ["organization.created", "member.added"],
})With Bearer Token (User Authentication)
import { TimbrixClient } from "@timbrix/sdk"
const client = new TimbrixClient({
bearerToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
baseUrl: "https://api.timbrix.com",
})
// List organizations
const orgs = await client.organizations.list()
// Create organization
const org = await client.organizations.create({
name: "Acme Corp",
slug: "acme-corp",
})API Reference
Organizations
// List all organizations
await client.organizations.list()
// Get organization by slug
await client.organizations.get("acme-corp")
// Create organization
await client.organizations.create({
name: "Acme Corp",
slug: "acme-corp",
})
// Update organization
await client.organizations.update("acme-corp", {
name: "New Name",
logo: "https://example.com/logo.png",
})
// Delete organization
await client.organizations.delete("acme-corp")Webhooks
// List webhooks
await client.webhooks.list("organization-id")
// Get webhook
await client.webhooks.get("organization-id", "webhook-id")
// Create webhook
await client.webhooks.create("organization-id", {
url: "https://example.com/webhooks",
events: ["organization.created"],
})
// Update webhook
await client.webhooks.update("organization-id", "webhook-id", {
url: "https://new-url.com/webhooks",
isActive: false,
})
// Delete webhook
await client.webhooks.delete("organization-id", "webhook-id")
// Get delivery history
await client.webhooks.deliveries("organization-id", "webhook-id")
// Send test webhook
await client.webhooks.test("organization-id", "webhook-id")API Keys
// List API keys
await client.apiKeys.list("organization-id")
// Get API key
await client.apiKeys.get("organization-id", "api-key-id")
// Create API key
await client.apiKeys.create("organization-id", {
name: "Production Key",
expiresAt: "2025-12-31T23:59:59Z", // optional
})
// Update API key
await client.apiKeys.update("organization-id", "api-key-id", {
name: "New Name",
})
// Revoke API key
await client.apiKeys.delete("organization-id", "api-key-id")
// Get usage stats
await client.apiKeys.stats("organization-id", "api-key-id")
// Validate API key
await client.apiKeys.validate("organization-id", "sk_live_abc123...")Error Handling
import { TimbrixClient, type TimbrixError } from "@timbrix/sdk"
const client = new TimbrixClient({ apiKey: "sk_live_abc123..." })
try {
await client.organizations.get("non-existent")
} catch (error) {
const timbrixError = error as TimbrixError
console.error(`Error ${timbrixError.statusCode}: ${timbrixError.message}`)
}TypeScript Support
The client is written in TypeScript and includes full type definitions:
import type {
Organization,
Webhook,
ApiKey,
CreateWebhookInput,
WebhookEvent,
} from "@timbrix/sdk"License
MIT
