@better-webhook/cli 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -1,156 +1,320 @@
1
- # Better Webhook CLI
1
+ # @better-webhook/cli
2
2
 
3
- Simple CLI for listing, downloading, and executing predefined webhook JSON payloads stored in a local `.webhooks` directory.
3
+ [![npm](https://img.shields.io/npm/v/@better-webhook/cli?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@better-webhook/cli)
4
+ [![GitHub](https://img.shields.io/github/stars/endalk200/better-webhook?style=for-the-badge&logo=github)](https://github.com/endalk200/better-webhook)
5
+ [![License](https://img.shields.io/github/license/endalk200/better-webhook?style=for-the-badge)](https://opensource.org/licenses/MIT)
6
+ [![Node.js](https://img.shields.io/node/v/@better-webhook/cli?style=for-the-badge&logo=node.js)](https://nodejs.org/)
4
7
 
5
- ## Install (workspace)
8
+ A powerful CLI tool for webhook development, testing, and management. Capture incoming webhooks, replay them, generate reusable templates, and manage webhook definitions locally.
6
9
 
7
- From repo root after cloning:
10
+ ## Features
11
+
12
+ ✅ **Webhook Management** - Store and execute webhook definitions locally
13
+ 🎣 **Live Capture** - Capture incoming webhooks with a local server
14
+ 🔄 **Replay** - Replay captured webhooks to any endpoint
15
+ 📋 **Templates** - Generate reusable templates from captured requests
16
+ 📥 **Download** - Access curated webhook templates from the community
17
+ 🎯 **Override** - Override URLs, methods, and headers on the fly
18
+
19
+ ## Installation
20
+
21
+ ### NPM/YARN/PNPM
8
22
 
9
23
  ```bash
10
- pnpm install
11
- pnpm --filter @better-webhook/cli build
24
+ # Install globally
25
+ npm install -g @better-webhook/cli
26
+ # or use with npx
27
+ npx @better-webhook/cli --help
28
+
29
+ # With yarn
30
+ yarn global add @better-webhook/cli
31
+
32
+ # With pnpm
33
+ pnpm add -g @better-webhook/cli
12
34
  ```
13
35
 
14
- Run via pnpm:
36
+ ### Verify Installation
15
37
 
16
38
  ```bash
17
- pnpm --filter @better-webhook/cli exec better-webhook list
39
+ better-webhook --help
18
40
  ```
19
41
 
20
- Or in dev (watch) mode:
42
+ ## Quick Start
43
+
44
+ ### 1. Manage Webhook Definitions
21
45
 
22
46
  ```bash
23
- pnpm --filter @better-webhook/cli dev run sample
47
+ # List available webhook definitions
48
+ better-webhook webhooks list
49
+
50
+ # Download community templates
51
+ better-webhook webhooks download stripe-invoice.payment_succeeded
52
+ better-webhook webhooks download --all
53
+
54
+ # Run a webhook
55
+ better-webhook webhooks run stripe-invoice
56
+ better-webhook webhooks run mywebhook --url https://example.com/hook --method POST
24
57
  ```
25
58
 
26
- ## Install (published)
59
+ ### 2. Capture Live Webhooks
60
+
61
+ ```bash
62
+ # Start capture server (default port 3001)
63
+ better-webhook capture
64
+ better-webhook capture --port 3000
27
65
 
28
- After publishing to npm you can use:
66
+ # List captured webhooks
67
+ better-webhook capture list
68
+ better-webhook capture list --limit 20
69
+
70
+ # Generate template from capture
71
+ better-webhook capture template abc123 my-template-name
72
+ ```
73
+
74
+ ### 3. Replay Webhooks
29
75
 
30
76
  ```bash
31
- npx @better-webhook/cli list
32
- # or (after global install)
33
- pnpm add -g @better-webhook/cli
34
- better-webhook list
77
+ # Replay captured webhook to any endpoint
78
+ better-webhook replay abc123 https://example.com/webhook
79
+ better-webhook replay abc123 https://test.com/hook --method PUT
35
80
  ```
36
81
 
37
- The binary name is `better-webhook`.
82
+ ## Commands
83
+
84
+ ### `better-webhook webhooks`
38
85
 
39
- ## Publishing (maintainers)
86
+ Manage and execute webhook definitions stored in `.webhooks/` directory.
40
87
 
41
- 1. Update version (pnpm):
42
- ```bash
43
- pnpm --filter @better-webhook/cli version patch # or minor / major
44
- ```
45
- 2. Build & publish (ensure you are logged in with `npm whoami`):
46
- ```bash
47
- pnpm --filter @better-webhook/cli run build
48
- cd apps/webhook-cli
49
- npm publish --access public
50
- ```
51
- (The `prepublishOnly` script also builds/validates automatically.)
52
- 3. Test install:
53
- ```bash
54
- pnpm dlx @better-webhook/cli@latest --help
55
- ```
88
+ | Command | Description | Options |
89
+ | -------------------------- | ---------------------------------- | ------------------- |
90
+ | `webhooks list` | List available webhook definitions | - |
91
+ | `webhooks run <name>` | Execute a webhook definition | `--url`, `--method` |
92
+ | `webhooks download [name]` | Download community templates | `--all`, `--force` |
56
93
 
57
- ## Webhook File Schema
94
+ ### `better-webhook capture`
58
95
 
59
- Every webhook JSON file MUST conform to this schema (validated with `zod`):
96
+ Capture, list, and generate templates from live webhook requests.
60
97
 
61
- ```jsonc
98
+ | Command | Description | Options |
99
+ | ------------------------------ | ------------------------------ | ----------------------- |
100
+ | `capture` | Start webhook capture server | `--port` |
101
+ | `capture list` | List captured webhook requests | `--limit` |
102
+ | `capture template <id> [name]` | Generate template from capture | `--url`, `--output-dir` |
103
+
104
+ ### `better-webhook replay`
105
+
106
+ Replay captured webhooks to any endpoint.
107
+
108
+ | Command | Description | Options |
109
+ | -------------------------------- | ----------------------- | ---------------------- |
110
+ | `replay <captureId> <targetUrl>` | Replay captured webhook | `--method`, `--header` |
111
+
112
+ ## Webhook Definition Format
113
+
114
+ Webhook definitions are JSON files that follow this schema:
115
+
116
+ ```json
62
117
  {
63
- "url": "https://example.com/endpoint", // required, valid URL
64
- "method": "POST", // optional, defaults to POST (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS)
118
+ "url": "https://api.example.com/webhook",
119
+ "method": "POST",
65
120
  "headers": [
66
- // optional, defaults to []
67
- { "key": "X-Custom", "value": "abc" },
121
+ { "key": "Authorization", "value": "Bearer token123" },
122
+ { "key": "Content-Type", "value": "application/json" }
68
123
  ],
69
124
  "body": {
70
- // optional (omit for methods w/out body)
71
125
  "event": "user.created",
72
- "data": { "id": "123" },
73
- },
126
+ "data": {
127
+ "id": "12345",
128
+ "email": "user@example.com"
129
+ }
130
+ }
74
131
  }
75
132
  ```
76
133
 
77
- Validation errors list all failing fields with context.
134
+ ### Schema Fields
135
+
136
+ | Field | Type | Required | Description |
137
+ | --------- | ------ | -------- | --------------------------- |
138
+ | `url` | string | ✅ | Target webhook URL |
139
+ | `method` | string | ❌ | HTTP method (default: POST) |
140
+ | `headers` | array | ❌ | Array of header objects |
141
+ | `body` | any | ❌ | Request payload |
78
142
 
79
143
  ## Directory Structure
80
144
 
81
145
  ```
82
- ./.webhooks/
83
- user_created.json
84
- order_paid.json
146
+ your-project/
147
+ ├── .webhooks/ # Webhook definitions
148
+ │ ├── stripe-payment.json
149
+ │ ├── user-signup.json
150
+ │ └── order-complete.json
151
+ └── .webhook-captures/ # Captured requests (auto-created)
152
+ ├── 2024-01-15T10-30-00_abc123.json
153
+ └── 2024-01-15T11-00-00_def456.json
85
154
  ```
86
155
 
87
- ## Commands
156
+ ## Use Cases
88
157
 
89
- ### List
158
+ ### Development & Testing
90
159
 
91
- ```
92
- better-webhook list
93
- ```
94
-
95
- Lists all JSON filenames (without extension) in `.webhooks`.
160
+ ```bash
161
+ # Test your webhook endpoint during development
162
+ better-webhook webhooks run test-payload --url http://localhost:3000/webhook
96
163
 
97
- ### Download Templates
164
+ # Capture webhooks from external services
165
+ better-webhook capture --port 4000
166
+ # Point your webhook provider to http://localhost:4000
98
167
 
99
- ```
100
- better-webhook download # lists available templates
101
- better-webhook download stripe-invoice.payment_succeeded
102
- better-webhook download --all
168
+ # Replay captured requests for debugging
169
+ better-webhook replay abc123 http://localhost:3000/debug
103
170
  ```
104
171
 
105
- ### Run
172
+ ### CI/CD & Automation
106
173
 
107
- ```
108
- better-webhook run user_created
109
- better-webhook run path/to/file.json
174
+ ```bash
175
+ # Test webhook endpoints in your pipeline
176
+ better-webhook webhooks run deployment-success --url $PROD_WEBHOOK_URL
177
+
178
+ # Capture and replay for integration testing
179
+ better-webhook capture --port 8080 &
180
+ run_integration_tests
181
+ better-webhook capture list
182
+ better-webhook replay latest-capture $TEST_ENDPOINT
110
183
  ```
111
184
 
112
- Overrides:
185
+ ### API Integration
113
186
 
114
- ```
115
- --url https://override.test/hook
116
- --method PUT
187
+ ```bash
188
+ # Download and customize templates for popular services
189
+ better-webhook webhooks download stripe-invoice.payment_succeeded
190
+ better-webhook webhooks run stripe-invoice --url https://myapp.com/stripe
191
+
192
+ # Generate templates from real webhook data
193
+ better-webhook capture template abc123 stripe-custom-template
117
194
  ```
118
195
 
119
- ### Examples
196
+ ## Examples
120
197
 
121
- Minimal:
198
+ ### Stripe Payment Webhook
122
199
 
123
200
  ```json
124
- { "url": "https://example.com/hook" }
201
+ {
202
+ "url": "https://api.myapp.com/webhooks/stripe",
203
+ "method": "POST",
204
+ "headers": [
205
+ { "key": "Stripe-Signature", "value": "t=1234567890,v1=signature" }
206
+ ],
207
+ "body": {
208
+ "id": "evt_1234567890",
209
+ "object": "event",
210
+ "type": "payment_intent.succeeded",
211
+ "data": {
212
+ "object": {
213
+ "id": "pi_1234567890",
214
+ "amount": 2000,
215
+ "currency": "usd",
216
+ "status": "succeeded"
217
+ }
218
+ }
219
+ }
220
+ }
125
221
  ```
126
222
 
127
- With headers + body:
223
+ ### GitHub Webhook
128
224
 
129
225
  ```json
130
226
  {
131
- "url": "https://example.com/hook",
227
+ "url": "https://api.myapp.com/webhooks/github",
132
228
  "method": "POST",
133
229
  "headers": [
134
- { "key": "X-Env", "value": "staging" },
135
- { "key": "Authorization", "value": "Bearer TOKEN" }
230
+ { "key": "X-GitHub-Event", "value": "push" },
231
+ { "key": "X-Hub-Signature-256", "value": "sha256=signature" }
136
232
  ],
137
- "body": { "event": "deploy", "status": "ok" }
233
+ "body": {
234
+ "ref": "refs/heads/main",
235
+ "commits": [
236
+ {
237
+ "id": "abc123",
238
+ "message": "Update README",
239
+ "author": {
240
+ "name": "Developer",
241
+ "email": "dev@example.com"
242
+ }
243
+ }
244
+ ]
245
+ }
138
246
  }
139
247
  ```
140
248
 
141
- ## Output
249
+ ## Error Handling
142
250
 
143
- - Prints status code
144
- - Prints response headers
145
- - Pretty-prints JSON response or raw body
251
+ The CLI provides detailed error messages and uses appropriate exit codes:
146
252
 
147
- ## Error Handling
253
+ - **0**: Success
254
+ - **1**: General error (network, validation, file not found)
255
+
256
+ ```bash
257
+ # Validation errors show detailed field information
258
+ better-webhook webhooks run invalid-webhook
259
+ # Error: Webhook validation failed:
260
+ # - url: Required field missing
261
+ # - method: Invalid HTTP method "INVALID"
262
+
263
+ # Network errors are clearly reported
264
+ better-webhook webhooks run test --url https://invalid-domain.nonexistent
265
+ # Error: Request failed: getaddrinfo ENOTFOUND invalid-domain.nonexistent
266
+ ```
267
+
268
+ ## Configuration
269
+
270
+ ### Environment Variables
271
+
272
+ | Variable | Description | Default |
273
+ | -------------- | --------------------------------- | ------------------- |
274
+ | `WEBHOOKS_DIR` | Directory for webhook definitions | `.webhooks` |
275
+ | `CAPTURES_DIR` | Directory for captured webhooks | `.webhook-captures` |
276
+
277
+ ### Global Options
278
+
279
+ | Flag | Description |
280
+ | ----------- | ------------------------ |
281
+ | `--help` | Show help information |
282
+ | `--version` | Show version information |
283
+
284
+ ## Contributing
285
+
286
+ We welcome contributions! Please see our [Contributing Guide](https://github.com/endalk200/better-webhook/blob/main/CONTRIBUTING.md) for details.
287
+
288
+ ### Development Setup
289
+
290
+ ```bash
291
+ git clone https://github.com/endalk200/better-webhook.git
292
+ cd better-webhook
293
+ pnpm install
294
+ pnpm --filter @better-webhook/cli build
295
+ ```
296
+
297
+ ### Running Tests
298
+
299
+ ```bash
300
+ pnpm --filter @better-webhook/cli test
301
+ ```
302
+
303
+ ## Changelog
304
+
305
+ See [CHANGELOG.md](https://github.com/endalk200/better-webhook/blob/main/apps/webhook-cli/CHANGELOG.md) for version history.
306
+
307
+ ## License
308
+
309
+ MIT © [Endalk](https://github.com/endalk200)
310
+
311
+ ## Support
312
+
313
+ - 🐛 [Report bugs](https://github.com/endalk200/better-webhook/issues)
314
+ - 💡 [Request features](https://github.com/endalk200/better-webhook/issues)
315
+ - 📖 [Documentation](https://github.com/endalk200/better-webhook#readme)
148
316
 
149
- - Invalid JSON -> fails with parse message
150
- - Schema violations -> detailed list of issues
151
- - Network errors -> reported with non-zero exit code
317
+ ---
152
318
 
153
- ## Notes
319
+ Made with ❤️ by [Endalk](https://github.com/endalk200)
154
320
 
155
- - Content-Type automatically set to `application/json` if body present and not already specified.
156
- - Headers defined later override earlier duplicates.