@timbrix/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @timbrix/sdk
2
+
3
+ TypeScript/JavaScript client for the Timbrix API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @timbrix/sdk
9
+ # or
10
+ pnpm add @timbrix/sdk
11
+ # or
12
+ yarn add @timbrix/sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### With API Key (Machine-to-Machine)
18
+
19
+ ```typescript
20
+ import { TimbrixClient } from "@timbrix/sdk"
21
+
22
+ const client = new TimbrixClient({
23
+ apiKey: "sk_live_abc123...",
24
+ baseUrl: "https://api.timbrix.com", // optional, defaults to localhost
25
+ })
26
+
27
+ // List webhooks
28
+ const webhooks = await client.webhooks.list("organization-id")
29
+
30
+ // Create webhook
31
+ const webhook = await client.webhooks.create("organization-id", {
32
+ url: "https://example.com/webhooks",
33
+ events: ["organization.created", "member.added"],
34
+ })
35
+ ```
36
+
37
+ ### With Bearer Token (User Authentication)
38
+
39
+ ```typescript
40
+ import { TimbrixClient } from "@timbrix/sdk"
41
+
42
+ const client = new TimbrixClient({
43
+ bearerToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
44
+ baseUrl: "https://api.timbrix.com",
45
+ })
46
+
47
+ // List organizations
48
+ const orgs = await client.organizations.list()
49
+
50
+ // Create organization
51
+ const org = await client.organizations.create({
52
+ name: "Acme Corp",
53
+ slug: "acme-corp",
54
+ })
55
+ ```
56
+
57
+ ## API Reference
58
+
59
+ ### Organizations
60
+
61
+ ```typescript
62
+ // List all organizations
63
+ await client.organizations.list()
64
+
65
+ // Get organization by slug
66
+ await client.organizations.get("acme-corp")
67
+
68
+ // Create organization
69
+ await client.organizations.create({
70
+ name: "Acme Corp",
71
+ slug: "acme-corp",
72
+ })
73
+
74
+ // Update organization
75
+ await client.organizations.update("acme-corp", {
76
+ name: "New Name",
77
+ logo: "https://example.com/logo.png",
78
+ })
79
+
80
+ // Delete organization
81
+ await client.organizations.delete("acme-corp")
82
+ ```
83
+
84
+ ### Webhooks
85
+
86
+ ```typescript
87
+ // List webhooks
88
+ await client.webhooks.list("organization-id")
89
+
90
+ // Get webhook
91
+ await client.webhooks.get("organization-id", "webhook-id")
92
+
93
+ // Create webhook
94
+ await client.webhooks.create("organization-id", {
95
+ url: "https://example.com/webhooks",
96
+ events: ["organization.created"],
97
+ })
98
+
99
+ // Update webhook
100
+ await client.webhooks.update("organization-id", "webhook-id", {
101
+ url: "https://new-url.com/webhooks",
102
+ isActive: false,
103
+ })
104
+
105
+ // Delete webhook
106
+ await client.webhooks.delete("organization-id", "webhook-id")
107
+
108
+ // Get delivery history
109
+ await client.webhooks.deliveries("organization-id", "webhook-id")
110
+
111
+ // Send test webhook
112
+ await client.webhooks.test("organization-id", "webhook-id")
113
+ ```
114
+
115
+ ### API Keys
116
+
117
+ ```typescript
118
+ // List API keys
119
+ await client.apiKeys.list("organization-id")
120
+
121
+ // Get API key
122
+ await client.apiKeys.get("organization-id", "api-key-id")
123
+
124
+ // Create API key
125
+ await client.apiKeys.create("organization-id", {
126
+ name: "Production Key",
127
+ expiresAt: "2025-12-31T23:59:59Z", // optional
128
+ })
129
+
130
+ // Update API key
131
+ await client.apiKeys.update("organization-id", "api-key-id", {
132
+ name: "New Name",
133
+ })
134
+
135
+ // Revoke API key
136
+ await client.apiKeys.delete("organization-id", "api-key-id")
137
+
138
+ // Get usage stats
139
+ await client.apiKeys.stats("organization-id", "api-key-id")
140
+
141
+ // Validate API key
142
+ await client.apiKeys.validate("organization-id", "sk_live_abc123...")
143
+ ```
144
+
145
+ ## Error Handling
146
+
147
+ ```typescript
148
+ import { TimbrixClient, type TimbrixError } from "@timbrix/sdk"
149
+
150
+ const client = new TimbrixClient({ apiKey: "sk_live_abc123..." })
151
+
152
+ try {
153
+ await client.organizations.get("non-existent")
154
+ } catch (error) {
155
+ const timbrixError = error as TimbrixError
156
+ console.error(`Error ${timbrixError.statusCode}: ${timbrixError.message}`)
157
+ }
158
+ ```
159
+
160
+ ## TypeScript Support
161
+
162
+ The client is written in TypeScript and includes full type definitions:
163
+
164
+ ```typescript
165
+ import type {
166
+ Organization,
167
+ Webhook,
168
+ ApiKey,
169
+ CreateWebhookInput,
170
+ WebhookEvent,
171
+ } from "@timbrix/sdk"
172
+ ```
173
+
174
+ ## License
175
+
176
+ MIT