hopwire 0.2.0 → 0.3.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/dist/account.js +180 -35
- package/dist/agent/redact.js +17 -8
- package/dist/bin.js +136 -6
- package/dist/cli.js +116 -69
- package/dist/commands/doctor.js +19 -14
- package/dist/commands/http.js +3 -2
- package/dist/commands/init.js +10 -7
- package/dist/commands/login.js +47 -8
- package/dist/commands/up.js +3 -2
- package/dist/commands/watch.js +3 -3
- package/dist/config.js +7 -2
- package/dist/inspector/assets/{index-CIOfyIbK.js → index-CdyIIKdA.js} +1 -1
- package/dist/inspector/index.html +1 -1
- package/dist/live.js +226 -0
- package/dist/main.js +14 -3
- package/dist/output.js +19 -0
- package/dist/p2p.js +59 -1
- package/dist/relay.js +1 -1
- package/dist/serve.js +1 -0
- package/dist/shortcuts.js +217 -0
- package/dist/terminal.js +619 -0
- package/dist/version.js +12 -0
- package/dist/webhook.js +91 -0
- package/package.json +1 -1
package/dist/webhook.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Bodies larger than this are not parsed for the event name: a row must never wait for a big JSON. */
|
|
2
|
+
const PARSE_LIMIT_BYTES = 256 * 1024;
|
|
3
|
+
/** Longest event name shown; a provider's own names are far shorter. */
|
|
4
|
+
const EVENT_MAX_LENGTH = 48;
|
|
5
|
+
/**
|
|
6
|
+
* The providers, each recognised by a header only it sends. The order matters where two could match: Svix carries
|
|
7
|
+
* the webhooks of several products (Clerk, Resend and others) and is named as itself.
|
|
8
|
+
*/
|
|
9
|
+
const PROVIDERS = [
|
|
10
|
+
{ provider: 'stripe', matches: (h) => h.has('stripe-signature'), event: (_h, body) => text(body()?.type) },
|
|
11
|
+
{
|
|
12
|
+
provider: 'github',
|
|
13
|
+
matches: (h) => h.has('x-github-event'),
|
|
14
|
+
event: (h, body) => joined(h.get('x-github-event'), text(body()?.action)),
|
|
15
|
+
},
|
|
16
|
+
{ provider: 'gitlab', matches: (h) => h.has('x-gitlab-event'), event: (h) => text(h.get('x-gitlab-event')) },
|
|
17
|
+
{ provider: 'shopify', matches: (h) => h.has('x-shopify-topic'), event: (h) => text(h.get('x-shopify-topic')) },
|
|
18
|
+
{
|
|
19
|
+
provider: 'slack',
|
|
20
|
+
matches: (h) => h.has('x-slack-signature'),
|
|
21
|
+
event: (_h, body) => {
|
|
22
|
+
const payload = body();
|
|
23
|
+
const inner = payload?.event;
|
|
24
|
+
return text(typeof inner === 'object' && inner !== null && 'type' in inner ? inner.type : payload?.type);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provider: 'linear',
|
|
29
|
+
matches: (h) => h.has('linear-signature') || h.has('linear-event'),
|
|
30
|
+
event: (h, body) => joined(text(body()?.type) ?? h.get('linear-event'), text(body()?.action)),
|
|
31
|
+
},
|
|
32
|
+
{ provider: 'paddle', matches: (h) => h.has('paddle-signature'), event: (_h, body) => text(body()?.event_type) },
|
|
33
|
+
{
|
|
34
|
+
provider: 'paypal',
|
|
35
|
+
matches: (h) => h.has('paypal-transmission-id'),
|
|
36
|
+
event: (_h, body) => text(body()?.event_type),
|
|
37
|
+
},
|
|
38
|
+
{ provider: 'twilio', matches: (h) => h.has('x-twilio-signature'), event: () => null },
|
|
39
|
+
{
|
|
40
|
+
provider: 'svix',
|
|
41
|
+
matches: (h) => h.has('svix-id') || h.has('webhook-id'),
|
|
42
|
+
event: (_h, body) => text(body()?.type),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* The webhook a request is, from its headers and, for the event name, its captured JSON body. Only what this machine
|
|
47
|
+
* captured is read; nothing is sent anywhere. Null for a request no provider's header marks.
|
|
48
|
+
*/
|
|
49
|
+
export function recogniseWebhook(exchange) {
|
|
50
|
+
const headers = new Map(exchange.request.headers.map(([name, value]) => [name.toLowerCase(), value]));
|
|
51
|
+
const match = PROVIDERS.find((entry) => entry.matches(headers));
|
|
52
|
+
if (match === undefined) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
const body = () => {
|
|
57
|
+
parsed ??= jsonBody(exchange);
|
|
58
|
+
return parsed;
|
|
59
|
+
};
|
|
60
|
+
const event = match.event(headers, body);
|
|
61
|
+
return { provider: match.provider, event: event === null ? null : event.slice(0, EVENT_MAX_LENGTH) };
|
|
62
|
+
}
|
|
63
|
+
/** The request body as a JSON object; null when it is none, was cut by the capture, or is too large to parse here. */
|
|
64
|
+
function jsonBody(exchange) {
|
|
65
|
+
const { request } = exchange;
|
|
66
|
+
if (request.bodyTruncated ||
|
|
67
|
+
request.bodyBase64.length === 0 ||
|
|
68
|
+
(request.bodyBase64.length / 4) * 3 > PARSE_LIMIT_BYTES) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const value = JSON.parse(Buffer.from(request.bodyBase64, 'base64').toString('utf8'));
|
|
73
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
74
|
+
? value
|
|
75
|
+
: null;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** A non-empty string value, or null. */
|
|
82
|
+
function text(value) {
|
|
83
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
84
|
+
}
|
|
85
|
+
/** "push", "pull_request.opened": the event and its action when there is one. */
|
|
86
|
+
function joined(event, action) {
|
|
87
|
+
if (event === null || event === undefined || event === '') {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return action === null ? event : `${event}.${action}`;
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hopwire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"mcpName": "to.hopwire/hopwire",
|
|
5
5
|
"description": "Record, share and replay the HTTP traffic of your local services: private P2P sharing with teammates, and public HTTPS URLs.",
|
|
6
6
|
"license": "Apache-2.0",
|