@credda/cli 0.1.5 → 1.0.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.
@@ -1,17 +0,0 @@
1
- /**
2
- * `credda listen` — a local webhook receiver for development.
3
- *
4
- * Accepts POSTs on a local port, verifies each delivery's HMAC signature with
5
- * the webhook's signing secret (when provided), and pretty-prints the payload.
6
- * Responds 200 so a tunneled Credda delivery counts as delivered.
7
- *
8
- * Honest scope: Credda only delivers to public HTTPS endpoints, so this does
9
- * NOT tunnel by itself — put your own tunnel in front (cloudflared, ngrok, …)
10
- * and register the tunnel URL as the webhook. What this gives you is the
11
- * Stripe-CLI-style local loop: see every delivery, verify its signature the
12
- * same way your production handler must, and iterate without redeploying.
13
- */
14
- export declare function startListener(opts: {
15
- port: number;
16
- secret?: string;
17
- }): Promise<void>;
package/dist/listener.js DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * `credda listen` — a local webhook receiver for development.
3
- *
4
- * Accepts POSTs on a local port, verifies each delivery's HMAC signature with
5
- * the webhook's signing secret (when provided), and pretty-prints the payload.
6
- * Responds 200 so a tunneled Credda delivery counts as delivered.
7
- *
8
- * Honest scope: Credda only delivers to public HTTPS endpoints, so this does
9
- * NOT tunnel by itself — put your own tunnel in front (cloudflared, ngrok, …)
10
- * and register the tunnel URL as the webhook. What this gives you is the
11
- * Stripe-CLI-style local loop: see every delivery, verify its signature the
12
- * same way your production handler must, and iterate without redeploying.
13
- */
14
- import { createServer } from 'node:http';
15
- import { verifyWebhookSignature } from '@credda/js/headless';
16
- export function startListener(opts) {
17
- return new Promise((resolve, reject) => {
18
- const server = createServer((req, res) => {
19
- const chunks = [];
20
- req.on('data', (c) => chunks.push(c));
21
- req.on('end', () => {
22
- void (async () => {
23
- const rawBody = Buffer.concat(chunks).toString('utf8');
24
- const time = new Date().toISOString();
25
- let verdict = 'unverified (set CREDDA_WEBHOOK_SECRET to verify signatures)';
26
- if (opts.secret) {
27
- try {
28
- const result = await verifyWebhookSignature({
29
- secret: opts.secret,
30
- rawBody,
31
- signatureHeader: req.headers['x-credda-signature'],
32
- timestampHeader: req.headers['x-credda-timestamp'],
33
- });
34
- verdict = result.valid ? 'signature VERIFIED' : `signature INVALID: ${result.reason}`;
35
- }
36
- catch (e) {
37
- verdict = `signature check errored: ${e instanceof Error ? e.message : String(e)}`;
38
- }
39
- }
40
- let pretty = rawBody;
41
- let eventType = req.headers['x-credda-event'] ?? '?';
42
- try {
43
- const parsed = JSON.parse(rawBody);
44
- if (parsed.type)
45
- eventType = parsed.type;
46
- pretty = JSON.stringify(parsed, null, 2);
47
- }
48
- catch {
49
- // non-JSON body — print raw
50
- }
51
- console.log(`\n── ${time} · ${req.method} ${req.url} · ${String(eventType)} · ${verdict}`);
52
- console.log(pretty);
53
- res.writeHead(200, { 'content-type': 'application/json' });
54
- res.end('{"received":true}');
55
- })();
56
- });
57
- });
58
- server.on('error', reject);
59
- server.listen(opts.port, () => {
60
- console.error(`credda listen: receiving webhook deliveries on http://localhost:${opts.port}`);
61
- console.error(opts.secret
62
- ? 'Signatures will be verified with CREDDA_WEBHOOK_SECRET.'
63
- : 'No CREDDA_WEBHOOK_SECRET set; payloads will print unverified.');
64
- console.error('Expose this port with your own tunnel and register the HTTPS URL as your webhook. Ctrl+C to stop.');
65
- });
66
- // Runs until the process is interrupted.
67
- process.on('SIGINT', () => {
68
- server.close(() => resolve());
69
- // Give close a moment, then let the default handler end the process.
70
- setTimeout(() => resolve(), 200);
71
- });
72
- });
73
- }