@tagma/trigger-webhook 0.1.1 → 0.1.3
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/LICENSE +21 -21
- package/README.md +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +44 -13
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Tagma
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tagma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ bun add @tagma/trigger-webhook
|
|
|
16
16
|
pipeline:
|
|
17
17
|
name: deploy-on-demand
|
|
18
18
|
plugins:
|
|
19
|
-
-
|
|
19
|
+
- '@tagma/trigger-webhook'
|
|
20
20
|
tracks:
|
|
21
21
|
- id: deploy
|
|
22
22
|
name: Deploy
|
|
@@ -30,7 +30,7 @@ pipeline:
|
|
|
30
30
|
path: /hooks/deploy
|
|
31
31
|
secret_env: TAGMA_WEBHOOK_SECRET
|
|
32
32
|
timeout: 30m
|
|
33
|
-
prompt:
|
|
33
|
+
prompt: 'Run the deploy playbook for the staging environment'
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Then fire the webhook from anywhere (CI, Slack, cron, another pipeline):
|
|
@@ -55,12 +55,12 @@ await loadPlugins(['@tagma/trigger-webhook']);
|
|
|
55
55
|
|
|
56
56
|
## Config
|
|
57
57
|
|
|
58
|
-
| Field | Type | Default
|
|
59
|
-
|
|
60
|
-
| `port` | number |
|
|
61
|
-
| `path` | string | `/webhook`
|
|
62
|
-
| `secret_env` | string |
|
|
63
|
-
| `timeout` | duration |
|
|
58
|
+
| Field | Type | Default | Notes |
|
|
59
|
+
| ------------ | -------- | ------------ | ------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `port` | number | _(required)_ | TCP port to listen on (1-65535) |
|
|
61
|
+
| `path` | string | `/webhook` | URL path to match; must start with `/` |
|
|
62
|
+
| `secret_env` | string | _(none)_ | Env var holding the HMAC-SHA256 secret. When set, requests must include `x-tagma-signature` |
|
|
63
|
+
| `timeout` | duration | _(forever)_ | Max wait time; omit for unbounded wait |
|
|
64
64
|
|
|
65
65
|
## Behavior
|
|
66
66
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;AAkIlE,QAAA,MAAM,cAAc,EAAE,aAwHrB,CAAC;AAGF,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,UAAU,YAAY,CAAC;AACpC,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,9 +26,10 @@ import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
|
26
26
|
// listener. Bun.serve refuses to bind a port twice, so this sharing is
|
|
27
27
|
// required — not just an optimization.
|
|
28
28
|
const servers = new Map();
|
|
29
|
-
function serverKey(port, path) {
|
|
30
|
-
return `${port}::${path}`;
|
|
29
|
+
function serverKey(port, path, hostname) {
|
|
30
|
+
return `${hostname}::${port}::${path}`;
|
|
31
31
|
}
|
|
32
|
+
const DEFAULT_WEBHOOK_HOST = '127.0.0.1';
|
|
32
33
|
function parseDurationSafe(raw, fallback) {
|
|
33
34
|
if (raw == null)
|
|
34
35
|
return fallback;
|
|
@@ -38,11 +39,15 @@ function parseDurationSafe(raw, fallback) {
|
|
|
38
39
|
return fallback;
|
|
39
40
|
const n = Number(m[1]);
|
|
40
41
|
switch (m[2]) {
|
|
41
|
-
case 'ms':
|
|
42
|
-
|
|
43
|
-
case '
|
|
42
|
+
case 'ms':
|
|
43
|
+
return n;
|
|
44
|
+
case 'm':
|
|
45
|
+
return n * 60_000;
|
|
46
|
+
case 'h':
|
|
47
|
+
return n * 3_600_000;
|
|
44
48
|
case 's':
|
|
45
|
-
default:
|
|
49
|
+
default:
|
|
50
|
+
return n * 1000;
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
function verifySignature(rawBody, header, secret) {
|
|
@@ -53,8 +58,8 @@ function verifySignature(rawBody, header, secret) {
|
|
|
53
58
|
return false;
|
|
54
59
|
return timingSafeEqual(a, b);
|
|
55
60
|
}
|
|
56
|
-
function ensureServer(port, path, secretEnv) {
|
|
57
|
-
const key = serverKey(port, path);
|
|
61
|
+
function ensureServer(port, path, secretEnv, hostname) {
|
|
62
|
+
const key = serverKey(port, path, hostname);
|
|
58
63
|
const existing = servers.get(key);
|
|
59
64
|
if (existing)
|
|
60
65
|
return existing;
|
|
@@ -66,6 +71,12 @@ function ensureServer(port, path, secretEnv) {
|
|
|
66
71
|
};
|
|
67
72
|
Bun.serve({
|
|
68
73
|
port,
|
|
74
|
+
// Default to loopback so the webhook endpoint is not reachable from the
|
|
75
|
+
// LAN unless the user explicitly sets `host` in their YAML (e.g. for
|
|
76
|
+
// container/WSL scenarios). Without this, Bun.serve listens on all
|
|
77
|
+
// interfaces and a secret-less webhook would accept traffic from any
|
|
78
|
+
// network-adjacent caller.
|
|
79
|
+
hostname,
|
|
69
80
|
async fetch(req) {
|
|
70
81
|
const url = new URL(req.url);
|
|
71
82
|
if (url.pathname !== path) {
|
|
@@ -142,6 +153,12 @@ const WebhookTrigger = {
|
|
|
142
153
|
description: 'Env var containing the HMAC-SHA256 secret. When set, POSTs must include an x-tagma-signature: sha256=<hex> header computed over the raw body.',
|
|
143
154
|
placeholder: 'TAGMA_WEBHOOK_SECRET',
|
|
144
155
|
},
|
|
156
|
+
host: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
default: DEFAULT_WEBHOOK_HOST,
|
|
159
|
+
description: 'Interface to bind on. Defaults to 127.0.0.1 so the webhook is only reachable from the local machine. Set to 0.0.0.0 to accept LAN traffic (only do this when secret_env is also set).',
|
|
160
|
+
placeholder: DEFAULT_WEBHOOK_HOST,
|
|
161
|
+
},
|
|
145
162
|
timeout: {
|
|
146
163
|
type: 'duration',
|
|
147
164
|
description: 'Maximum wait time (e.g. 10m). Omit or 0 to wait indefinitely.',
|
|
@@ -160,10 +177,18 @@ const WebhookTrigger = {
|
|
|
160
177
|
throw new Error(`webhook trigger: "path" must start with "/", got ${path}`);
|
|
161
178
|
}
|
|
162
179
|
const secretEnv = config.secret_env;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
const rawHost = config.host;
|
|
181
|
+
const hostname = typeof rawHost === 'string' && rawHost.trim().length > 0
|
|
182
|
+
? rawHost.trim()
|
|
183
|
+
: DEFAULT_WEBHOOK_HOST;
|
|
184
|
+
const timeoutMs = config.timeout != null ? parseDurationSafe(config.timeout, 0) : 0;
|
|
185
|
+
if (hostname !== DEFAULT_WEBHOOK_HOST && hostname !== 'localhost' && !secretEnv) {
|
|
186
|
+
// Loud warning — the user has opted into a non-loopback bind without
|
|
187
|
+
// HMAC. Refuse by default rather than silently expose the endpoint to
|
|
188
|
+
// the network.
|
|
189
|
+
throw new Error(`webhook trigger: binding to "${hostname}" without secret_env is refused — set secret_env to enable HMAC authentication before exposing to non-loopback interfaces`);
|
|
190
|
+
}
|
|
191
|
+
const state = ensureServer(port, path, secretEnv, hostname);
|
|
167
192
|
return new Promise((resolvePromise, rejectPromise) => {
|
|
168
193
|
if (ctx.signal.aborted) {
|
|
169
194
|
rejectPromise(new Error('Pipeline aborted'));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,gCAAgC;AAChC,EAAE;AACF,0BAA0B;AAC1B,wCAAwC;AACxC,YAAY;AACZ,eAAe;AACf,uBAAuB;AACvB,qBAAqB;AACrB,4BAA4B;AAC5B,yBAAyB;AACzB,kCAAkC;AAClC,+CAA+C;AAC/C,2BAA2B;AAG3B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAW1D,sEAAsE;AACtE,uEAAuE;AACvE,uCAAuC;AACvC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;AAEtD,SAAS,SAAS,CAAC,IAAY,EAAE,IAAY;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,gCAAgC;AAChC,EAAE;AACF,0BAA0B;AAC1B,wCAAwC;AACxC,YAAY;AACZ,eAAe;AACf,uBAAuB;AACvB,qBAAqB;AACrB,4BAA4B;AAC5B,yBAAyB;A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,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3B,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAE9D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;gBAClB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;oBACtB,IAAI,OAAO;wBAAE,OAAO;oBACpB,OAAO,GAAG,IAAI,CAAC;oBACf,OAAO,EAAE,CAAC;oBACV,aAAa,CACX,IAAI,KAAK,CACP,wCAAwC,IAAI,GAAG,IAAI,WAAW,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CACvF,CACF,CAAC;gBACJ,CAAC,EAAE,SAAS,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,eAAe,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tagma/trigger-webhook",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "HTTP webhook trigger plugin for tagma-sdk pipelines",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"prepublishOnly": "bun run build"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@tagma/types": "0.2.
|
|
51
|
+
"@tagma/types": "0.2.6"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"bun-types": "^1.3.11",
|
package/src/index.ts
CHANGED
|
@@ -39,10 +39,12 @@ interface WebhookServerState {
|
|
|
39
39
|
// required — not just an optimization.
|
|
40
40
|
const servers = new Map<string, WebhookServerState>();
|
|
41
41
|
|
|
42
|
-
function serverKey(port: number, path: string): string {
|
|
43
|
-
return `${port}::${path}`;
|
|
42
|
+
function serverKey(port: number, path: string, hostname: string): string {
|
|
43
|
+
return `${hostname}::${port}::${path}`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const DEFAULT_WEBHOOK_HOST = '127.0.0.1';
|
|
47
|
+
|
|
46
48
|
function parseDurationSafe(raw: unknown, fallback: number): number {
|
|
47
49
|
if (raw == null) return fallback;
|
|
48
50
|
const str = String(raw).trim();
|
|
@@ -50,11 +52,15 @@ function parseDurationSafe(raw: unknown, fallback: number): number {
|
|
|
50
52
|
if (!m) return fallback;
|
|
51
53
|
const n = Number(m[1]);
|
|
52
54
|
switch (m[2]) {
|
|
53
|
-
case 'ms':
|
|
54
|
-
|
|
55
|
-
case '
|
|
55
|
+
case 'ms':
|
|
56
|
+
return n;
|
|
57
|
+
case 'm':
|
|
58
|
+
return n * 60_000;
|
|
59
|
+
case 'h':
|
|
60
|
+
return n * 3_600_000;
|
|
56
61
|
case 's':
|
|
57
|
-
default:
|
|
62
|
+
default:
|
|
63
|
+
return n * 1000;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -70,8 +76,9 @@ function ensureServer(
|
|
|
70
76
|
port: number,
|
|
71
77
|
path: string,
|
|
72
78
|
secretEnv: string | undefined,
|
|
79
|
+
hostname: string,
|
|
73
80
|
): WebhookServerState {
|
|
74
|
-
const key = serverKey(port, path);
|
|
81
|
+
const key = serverKey(port, path, hostname);
|
|
75
82
|
const existing = servers.get(key);
|
|
76
83
|
if (existing) return existing;
|
|
77
84
|
|
|
@@ -84,6 +91,12 @@ function ensureServer(
|
|
|
84
91
|
|
|
85
92
|
Bun.serve({
|
|
86
93
|
port,
|
|
94
|
+
// Default to loopback so the webhook endpoint is not reachable from the
|
|
95
|
+
// LAN unless the user explicitly sets `host` in their YAML (e.g. for
|
|
96
|
+
// container/WSL scenarios). Without this, Bun.serve listens on all
|
|
97
|
+
// interfaces and a secret-less webhook would accept traffic from any
|
|
98
|
+
// network-adjacent caller.
|
|
99
|
+
hostname,
|
|
87
100
|
async fetch(req) {
|
|
88
101
|
const url = new URL(req.url);
|
|
89
102
|
if (url.pathname !== path) {
|
|
@@ -142,8 +155,7 @@ function ensureServer(
|
|
|
142
155
|
const WebhookTrigger: TriggerPlugin = {
|
|
143
156
|
name: 'webhook',
|
|
144
157
|
schema: {
|
|
145
|
-
description:
|
|
146
|
-
'Wait for an HTTP POST to arrive on a local listener before the task runs.',
|
|
158
|
+
description: 'Wait for an HTTP POST to arrive on a local listener before the task runs.',
|
|
147
159
|
fields: {
|
|
148
160
|
port: {
|
|
149
161
|
type: 'number',
|
|
@@ -167,6 +179,13 @@ const WebhookTrigger: TriggerPlugin = {
|
|
|
167
179
|
'Env var containing the HMAC-SHA256 secret. When set, POSTs must include an x-tagma-signature: sha256=<hex> header computed over the raw body.',
|
|
168
180
|
placeholder: 'TAGMA_WEBHOOK_SECRET',
|
|
169
181
|
},
|
|
182
|
+
host: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
default: DEFAULT_WEBHOOK_HOST,
|
|
185
|
+
description:
|
|
186
|
+
'Interface to bind on. Defaults to 127.0.0.1 so the webhook is only reachable from the local machine. Set to 0.0.0.0 to accept LAN traffic (only do this when secret_env is also set).',
|
|
187
|
+
placeholder: DEFAULT_WEBHOOK_HOST,
|
|
188
|
+
},
|
|
170
189
|
timeout: {
|
|
171
190
|
type: 'duration',
|
|
172
191
|
description: 'Maximum wait time (e.g. 10m). Omit or 0 to wait indefinitely.',
|
|
@@ -188,11 +207,23 @@ const WebhookTrigger: TriggerPlugin = {
|
|
|
188
207
|
}
|
|
189
208
|
|
|
190
209
|
const secretEnv = config.secret_env as string | undefined;
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
210
|
+
const rawHost = config.host;
|
|
211
|
+
const hostname =
|
|
212
|
+
typeof rawHost === 'string' && rawHost.trim().length > 0
|
|
213
|
+
? rawHost.trim()
|
|
214
|
+
: DEFAULT_WEBHOOK_HOST;
|
|
215
|
+
const timeoutMs = config.timeout != null ? parseDurationSafe(config.timeout, 0) : 0;
|
|
216
|
+
|
|
217
|
+
if (hostname !== DEFAULT_WEBHOOK_HOST && hostname !== 'localhost' && !secretEnv) {
|
|
218
|
+
// Loud warning — the user has opted into a non-loopback bind without
|
|
219
|
+
// HMAC. Refuse by default rather than silently expose the endpoint to
|
|
220
|
+
// the network.
|
|
221
|
+
throw new Error(
|
|
222
|
+
`webhook trigger: binding to "${hostname}" without secret_env is refused — set secret_env to enable HMAC authentication before exposing to non-loopback interfaces`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
194
225
|
|
|
195
|
-
const state = ensureServer(port, path, secretEnv);
|
|
226
|
+
const state = ensureServer(port, path, secretEnv, hostname);
|
|
196
227
|
|
|
197
228
|
return new Promise<unknown>((resolvePromise, rejectPromise) => {
|
|
198
229
|
if (ctx.signal.aborted) {
|