@webhooks-cc/sdk 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +157 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # @webhooks-cc/sdk
2
+
3
+ TypeScript SDK for [webhooks.cc](https://webhooks.cc). Create temporary webhook endpoints, capture requests, and assert on their contents in your test suite.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @webhooks-cc/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { WebhooksCC } from '@webhooks-cc/sdk';
15
+
16
+ const client = new WebhooksCC({ apiKey: 'whcc_...' });
17
+
18
+ // Create a temporary endpoint
19
+ const endpoint = await client.endpoints.create({ name: 'My Test' });
20
+ console.log(endpoint.url); // https://go.webhooks.cc/w/abc123
21
+
22
+ // Point your service at endpoint.url, then wait for the webhook
23
+ const request = await client.requests.waitFor(endpoint.slug, {
24
+ timeout: 10000,
25
+ match: (r) => r.method === 'POST',
26
+ });
27
+
28
+ console.log(request.body); // '{"event":"order.created"}'
29
+ console.log(request.headers); // { 'content-type': 'application/json', ... }
30
+
31
+ // Clean up
32
+ await client.endpoints.delete(endpoint.slug);
33
+ ```
34
+
35
+ ## API
36
+
37
+ ### `new WebhooksCC(options)`
38
+
39
+ | Option | Type | Default | Description |
40
+ |-----------|----------|------------------------|----------------------|
41
+ | `apiKey` | `string` | *required* | API key (`whcc_...`) |
42
+ | `baseUrl` | `string` | `https://webhooks.cc` | API base URL |
43
+ | `timeout` | `number` | `30000` | Request timeout (ms) |
44
+
45
+ ### Endpoints
46
+
47
+ ```typescript
48
+ // Create
49
+ const endpoint = await client.endpoints.create({ name: 'optional name' });
50
+
51
+ // List all
52
+ const endpoints = await client.endpoints.list();
53
+
54
+ // Get by slug
55
+ const endpoint = await client.endpoints.get('abc123');
56
+
57
+ // Delete
58
+ await client.endpoints.delete('abc123');
59
+ ```
60
+
61
+ ### Requests
62
+
63
+ ```typescript
64
+ // List captured requests for an endpoint
65
+ const requests = await client.requests.list('endpoint-slug', {
66
+ limit: 50, // default: 50, max: 1000
67
+ since: Date.now() - 60000, // only after this timestamp (ms)
68
+ });
69
+
70
+ // Get a single request by ID
71
+ const request = await client.requests.get('request-id');
72
+
73
+ // Poll until a matching request arrives
74
+ const request = await client.requests.waitFor('endpoint-slug', {
75
+ timeout: 30000, // max wait (ms), default: 30000
76
+ pollInterval: 500, // poll interval (ms), default: 500
77
+ match: (r) => r.method === 'POST' && r.body?.includes('order'),
78
+ });
79
+ ```
80
+
81
+ ### Errors
82
+
83
+ ```typescript
84
+ import { WebhooksCC, ApiError } from '@webhooks-cc/sdk';
85
+
86
+ try {
87
+ await client.endpoints.get('nonexistent');
88
+ } catch (error) {
89
+ if (error instanceof ApiError) {
90
+ console.log(error.statusCode); // 404
91
+ console.log(error.message); // "API error (404): ..."
92
+ }
93
+ }
94
+ ```
95
+
96
+ ## GitHub Actions
97
+
98
+ Add your API key as a repository secret named `WHK_API_KEY`:
99
+
100
+ ```yaml
101
+ - name: Run webhook tests
102
+ env:
103
+ WHK_API_KEY: ${{ secrets.WHK_API_KEY }}
104
+ run: npx vitest run
105
+ ```
106
+
107
+ ```typescript
108
+ // webhook.test.ts
109
+ import { describe, it, expect, afterAll } from 'vitest';
110
+ import { WebhooksCC } from '@webhooks-cc/sdk';
111
+
112
+ const client = new WebhooksCC({ apiKey: process.env.WHK_API_KEY! });
113
+
114
+ describe('webhook integration', () => {
115
+ let slug: string;
116
+
117
+ it('receives order webhook', async () => {
118
+ const endpoint = await client.endpoints.create({ name: 'CI Test' });
119
+ slug = endpoint.slug;
120
+
121
+ // Trigger your service to send a webhook to endpoint.url
122
+ await yourService.registerWebhook(endpoint.url!);
123
+ await yourService.createOrder();
124
+
125
+ const req = await client.requests.waitFor(slug, {
126
+ timeout: 15000,
127
+ match: (r) => r.body?.includes('order.created'),
128
+ });
129
+
130
+ const body = JSON.parse(req.body!);
131
+ expect(body.event).toBe('order.created');
132
+ });
133
+
134
+ afterAll(async () => {
135
+ if (slug) await client.endpoints.delete(slug);
136
+ });
137
+ });
138
+ ```
139
+
140
+ ## Types
141
+
142
+ All types are exported:
143
+
144
+ ```typescript
145
+ import type {
146
+ ClientOptions,
147
+ Endpoint,
148
+ Request,
149
+ CreateEndpointOptions,
150
+ ListRequestsOptions,
151
+ WaitForOptions,
152
+ } from '@webhooks-cc/sdk';
153
+ ```
154
+
155
+ ## License
156
+
157
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webhooks-cc/sdk",
3
- "version": "0.1.0",
4
- "description": "Official SDK for webhooks.cc — programmatic webhook testing",
3
+ "version": "0.1.1",
4
+ "description": "TypeScript SDK for webhooks.cc — create endpoints, capture requests, assert in tests",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "README.md"
17
18
  ],
18
19
  "keywords": [
19
20
  "webhook",