@tagma/trigger-webhook 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.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +214 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/index.ts +249 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @tagma/trigger-webhook
|
|
2
|
+
|
|
3
|
+
HTTP webhook trigger plugin for [@tagma/sdk](https://www.npmjs.com/package/@tagma/sdk).
|
|
4
|
+
|
|
5
|
+
Pauses a task until a POST request arrives on a configured local HTTP listener. Optional HMAC-SHA256 signature validation protects against unauthenticated callers.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @tagma/trigger-webhook
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
pipeline:
|
|
17
|
+
name: deploy-on-demand
|
|
18
|
+
plugins:
|
|
19
|
+
- "@tagma/trigger-webhook"
|
|
20
|
+
tracks:
|
|
21
|
+
- id: deploy
|
|
22
|
+
name: Deploy
|
|
23
|
+
driver: claude-code
|
|
24
|
+
tasks:
|
|
25
|
+
- id: wait-signal
|
|
26
|
+
name: Wait for deploy signal
|
|
27
|
+
trigger:
|
|
28
|
+
type: webhook
|
|
29
|
+
port: 8787
|
|
30
|
+
path: /hooks/deploy
|
|
31
|
+
secret_env: TAGMA_WEBHOOK_SECRET
|
|
32
|
+
timeout: 30m
|
|
33
|
+
prompt: "Run the deploy playbook for the staging environment"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then fire the webhook from anywhere (CI, Slack, cron, another pipeline):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
BODY='{"env":"staging","sha":"abc123"}'
|
|
40
|
+
SIG="sha256=$(printf %s "$BODY" | openssl dgst -sha256 -hmac "$TAGMA_WEBHOOK_SECRET" | awk '{print $2}')"
|
|
41
|
+
curl -X POST http://localhost:8787/hooks/deploy \
|
|
42
|
+
-H "content-type: application/json" \
|
|
43
|
+
-H "x-tagma-signature: $SIG" \
|
|
44
|
+
-d "$BODY"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or load it programmatically:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { bootstrapBuiltins, loadPlugins } from '@tagma/sdk';
|
|
51
|
+
|
|
52
|
+
bootstrapBuiltins();
|
|
53
|
+
await loadPlugins(['@tagma/trigger-webhook']);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Config
|
|
57
|
+
|
|
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
|
+
|
|
65
|
+
## Behavior
|
|
66
|
+
|
|
67
|
+
- A single `Bun.serve` listener is created per unique `(port, path)` pair and shared across all tasks that watch it. Multiple tasks on the same endpoint form a FIFO waiter queue — the next POST wakes one waiter.
|
|
68
|
+
- Signature header format: `x-tagma-signature: sha256=<hex>`, HMAC-SHA256 of the raw request body using the secret. Verification is constant-time.
|
|
69
|
+
- JSON bodies (`content-type: application/json`) are parsed and handed to the task as the trigger payload; other bodies are passed through as raw strings.
|
|
70
|
+
- A POST arriving while no task is waiting is rejected with `409 no waiting task` so the caller can retry once a pipeline is up.
|
|
71
|
+
- The listener outlives the task — it's a per-process singleton, not cleaned up between pipeline runs. Restart the host to free the port.
|
|
72
|
+
|
|
73
|
+
## Security
|
|
74
|
+
|
|
75
|
+
Always set `secret_env` in production. Without it, anyone who can reach the port can fire the trigger. Bind the host to `127.0.0.1` at the OS level if you only need local callers.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,cAAc,CAAC;AAqHlE,QAAA,MAAM,cAAc,EAAE,aAsGrB,CAAC;AAGF,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,eAAO,MAAM,UAAU,YAAY,CAAC;AACpC,eAAe,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// ═══ Webhook Trigger Plugin ═══
|
|
2
|
+
//
|
|
3
|
+
// Spins up a Bun.serve HTTP listener and resolves the trigger when a POST
|
|
4
|
+
// arrives on the configured path. Optional HMAC-SHA256 validation via the
|
|
5
|
+
// `x-tagma-signature: sha256=<hex>` header protects against unauthenticated
|
|
6
|
+
// callers when the secret env var is set.
|
|
7
|
+
//
|
|
8
|
+
// Multiple tasks sharing the same `(port, path)` pair hit the same listener
|
|
9
|
+
// instance and are enqueued as waiters — the next inbound request wakes one
|
|
10
|
+
// waiter (FIFO). This keeps the plugin lightweight even when a pipeline has
|
|
11
|
+
// many webhook-triggered tasks.
|
|
12
|
+
//
|
|
13
|
+
// Usage in pipeline.yaml:
|
|
14
|
+
// plugins: ["@tagma/trigger-webhook"]
|
|
15
|
+
// tracks:
|
|
16
|
+
// - tasks:
|
|
17
|
+
// - id: deploy
|
|
18
|
+
// trigger:
|
|
19
|
+
// type: webhook
|
|
20
|
+
// port: 8787
|
|
21
|
+
// path: /hooks/deploy
|
|
22
|
+
// secret_env: TAGMA_WEBHOOK_SECRET
|
|
23
|
+
// timeout: 10m
|
|
24
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
25
|
+
// Module-level so concurrent tasks on the same (port, path) share one
|
|
26
|
+
// listener. Bun.serve refuses to bind a port twice, so this sharing is
|
|
27
|
+
// required — not just an optimization.
|
|
28
|
+
const servers = new Map();
|
|
29
|
+
function serverKey(port, path) {
|
|
30
|
+
return `${port}::${path}`;
|
|
31
|
+
}
|
|
32
|
+
function parseDurationSafe(raw, fallback) {
|
|
33
|
+
if (raw == null)
|
|
34
|
+
return fallback;
|
|
35
|
+
const str = String(raw).trim();
|
|
36
|
+
const m = str.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);
|
|
37
|
+
if (!m)
|
|
38
|
+
return fallback;
|
|
39
|
+
const n = Number(m[1]);
|
|
40
|
+
switch (m[2]) {
|
|
41
|
+
case 'ms': return n;
|
|
42
|
+
case 'm': return n * 60_000;
|
|
43
|
+
case 'h': return n * 3_600_000;
|
|
44
|
+
case 's':
|
|
45
|
+
default: return n * 1000;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function verifySignature(rawBody, header, secret) {
|
|
49
|
+
const expected = 'sha256=' + createHmac('sha256', secret).update(rawBody).digest('hex');
|
|
50
|
+
const a = Buffer.from(header);
|
|
51
|
+
const b = Buffer.from(expected);
|
|
52
|
+
if (a.length !== b.length)
|
|
53
|
+
return false;
|
|
54
|
+
return timingSafeEqual(a, b);
|
|
55
|
+
}
|
|
56
|
+
function ensureServer(port, path, secretEnv) {
|
|
57
|
+
const key = serverKey(port, path);
|
|
58
|
+
const existing = servers.get(key);
|
|
59
|
+
if (existing)
|
|
60
|
+
return existing;
|
|
61
|
+
const state = {
|
|
62
|
+
port,
|
|
63
|
+
path,
|
|
64
|
+
secretEnv,
|
|
65
|
+
waiters: [],
|
|
66
|
+
};
|
|
67
|
+
Bun.serve({
|
|
68
|
+
port,
|
|
69
|
+
async fetch(req) {
|
|
70
|
+
const url = new URL(req.url);
|
|
71
|
+
if (url.pathname !== path) {
|
|
72
|
+
return new Response('not found', { status: 404 });
|
|
73
|
+
}
|
|
74
|
+
if (req.method !== 'POST') {
|
|
75
|
+
return new Response('method not allowed', { status: 405 });
|
|
76
|
+
}
|
|
77
|
+
const rawBody = await req.text();
|
|
78
|
+
// HMAC gate — bypassed when no secret env is configured, which is
|
|
79
|
+
// acceptable for loopback dev but should always be set in production.
|
|
80
|
+
const secret = state.secretEnv ? process.env[state.secretEnv] : undefined;
|
|
81
|
+
if (state.secretEnv) {
|
|
82
|
+
if (!secret) {
|
|
83
|
+
return new Response(`env var ${state.secretEnv} not set`, { status: 500 });
|
|
84
|
+
}
|
|
85
|
+
const sigHeader = req.headers.get('x-tagma-signature') ?? '';
|
|
86
|
+
if (!verifySignature(rawBody, sigHeader, secret)) {
|
|
87
|
+
return new Response('invalid signature', { status: 401 });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Decode JSON if possible so downstream tasks get structured data.
|
|
91
|
+
// Falls back to the raw string body otherwise.
|
|
92
|
+
let payload = rawBody;
|
|
93
|
+
const contentType = req.headers.get('content-type') ?? '';
|
|
94
|
+
if (contentType.includes('application/json')) {
|
|
95
|
+
try {
|
|
96
|
+
payload = JSON.parse(rawBody);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* keep raw body */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const waiter = state.waiters.shift();
|
|
103
|
+
if (waiter) {
|
|
104
|
+
waiter(payload);
|
|
105
|
+
return new Response('ok', { status: 202 });
|
|
106
|
+
}
|
|
107
|
+
// No task is currently waiting on this endpoint — reject loudly so
|
|
108
|
+
// callers know the webhook wasn't actually consumed by a pipeline.
|
|
109
|
+
return new Response('no waiting task', { status: 409 });
|
|
110
|
+
},
|
|
111
|
+
error(err) {
|
|
112
|
+
console.error(`[webhook] server error on :${port}${path}:`, err);
|
|
113
|
+
return new Response('internal error', { status: 500 });
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
servers.set(key, state);
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
const WebhookTrigger = {
|
|
120
|
+
name: 'webhook',
|
|
121
|
+
schema: {
|
|
122
|
+
description: 'Wait for an HTTP POST to arrive on a local listener before the task runs.',
|
|
123
|
+
fields: {
|
|
124
|
+
port: {
|
|
125
|
+
type: 'number',
|
|
126
|
+
required: true,
|
|
127
|
+
default: 8787,
|
|
128
|
+
min: 1,
|
|
129
|
+
max: 65535,
|
|
130
|
+
description: 'TCP port to listen on.',
|
|
131
|
+
placeholder: '8787',
|
|
132
|
+
},
|
|
133
|
+
path: {
|
|
134
|
+
type: 'string',
|
|
135
|
+
required: true,
|
|
136
|
+
default: '/webhook',
|
|
137
|
+
description: 'URL path to match (e.g. /hooks/deploy).',
|
|
138
|
+
placeholder: '/webhook',
|
|
139
|
+
},
|
|
140
|
+
secret_env: {
|
|
141
|
+
type: 'string',
|
|
142
|
+
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
|
+
placeholder: 'TAGMA_WEBHOOK_SECRET',
|
|
144
|
+
},
|
|
145
|
+
timeout: {
|
|
146
|
+
type: 'duration',
|
|
147
|
+
description: 'Maximum wait time (e.g. 10m). Omit or 0 to wait indefinitely.',
|
|
148
|
+
placeholder: '10m',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
watch(config, ctx) {
|
|
153
|
+
const rawPort = config.port;
|
|
154
|
+
const port = typeof rawPort === 'number' ? rawPort : Number(rawPort);
|
|
155
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
156
|
+
throw new Error(`webhook trigger: "port" must be 1-65535, got ${String(rawPort)}`);
|
|
157
|
+
}
|
|
158
|
+
const path = config.path ?? '/webhook';
|
|
159
|
+
if (!path.startsWith('/')) {
|
|
160
|
+
throw new Error(`webhook trigger: "path" must start with "/", got ${path}`);
|
|
161
|
+
}
|
|
162
|
+
const secretEnv = config.secret_env;
|
|
163
|
+
const timeoutMs = config.timeout != null
|
|
164
|
+
? parseDurationSafe(config.timeout, 0)
|
|
165
|
+
: 0;
|
|
166
|
+
const state = ensureServer(port, path, secretEnv);
|
|
167
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
168
|
+
if (ctx.signal.aborted) {
|
|
169
|
+
rejectPromise(new Error('Pipeline aborted'));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let settled = false;
|
|
173
|
+
let timer = null;
|
|
174
|
+
const onFire = (payload) => {
|
|
175
|
+
if (settled)
|
|
176
|
+
return;
|
|
177
|
+
settled = true;
|
|
178
|
+
cleanup();
|
|
179
|
+
resolvePromise(payload);
|
|
180
|
+
};
|
|
181
|
+
const onAbort = () => {
|
|
182
|
+
if (settled)
|
|
183
|
+
return;
|
|
184
|
+
settled = true;
|
|
185
|
+
cleanup();
|
|
186
|
+
rejectPromise(new Error('Pipeline aborted'));
|
|
187
|
+
};
|
|
188
|
+
const cleanup = () => {
|
|
189
|
+
if (timer)
|
|
190
|
+
clearTimeout(timer);
|
|
191
|
+
ctx.signal.removeEventListener('abort', onAbort);
|
|
192
|
+
const idx = state.waiters.indexOf(onFire);
|
|
193
|
+
if (idx !== -1)
|
|
194
|
+
state.waiters.splice(idx, 1);
|
|
195
|
+
};
|
|
196
|
+
state.waiters.push(onFire);
|
|
197
|
+
ctx.signal.addEventListener('abort', onAbort, { once: true });
|
|
198
|
+
if (timeoutMs > 0) {
|
|
199
|
+
timer = setTimeout(() => {
|
|
200
|
+
if (settled)
|
|
201
|
+
return;
|
|
202
|
+
settled = true;
|
|
203
|
+
cleanup();
|
|
204
|
+
rejectPromise(new Error(`webhook trigger timeout: no POST on :${port}${path} within ${String(config.timeout)}`));
|
|
205
|
+
}, timeoutMs);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
// ═══ Plugin self-description exports ═══
|
|
211
|
+
export const pluginCategory = 'triggers';
|
|
212
|
+
export const pluginType = 'webhook';
|
|
213
|
+
export default WebhookTrigger;
|
|
214
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;A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AAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,eAAe,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tagma/trigger-webhook",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "HTTP webhook trigger plugin for tagma-sdk pipelines",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/GoTagma/tagma-mono.git",
|
|
9
|
+
"directory": "packages/trigger-webhook"
|
|
10
|
+
},
|
|
11
|
+
"bugs": "https://github.com/GoTagma/tagma-mono/issues",
|
|
12
|
+
"homepage": "https://github.com/GoTagma/tagma-mono/tree/main/packages/trigger-webhook#readme",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"tagma-plugin",
|
|
34
|
+
"tagma",
|
|
35
|
+
"trigger",
|
|
36
|
+
"webhook",
|
|
37
|
+
"http"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"bun": ">=1.3"
|
|
41
|
+
},
|
|
42
|
+
"tagmaPlugin": {
|
|
43
|
+
"category": "triggers",
|
|
44
|
+
"type": "webhook"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc -p tsconfig.json",
|
|
48
|
+
"prepublishOnly": "bun run build"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@tagma/types": "0.2.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"bun-types": "^1.3.11",
|
|
55
|
+
"typescript": "^5.8.3"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// ═══ Webhook Trigger Plugin ═══
|
|
2
|
+
//
|
|
3
|
+
// Spins up a Bun.serve HTTP listener and resolves the trigger when a POST
|
|
4
|
+
// arrives on the configured path. Optional HMAC-SHA256 validation via the
|
|
5
|
+
// `x-tagma-signature: sha256=<hex>` header protects against unauthenticated
|
|
6
|
+
// callers when the secret env var is set.
|
|
7
|
+
//
|
|
8
|
+
// Multiple tasks sharing the same `(port, path)` pair hit the same listener
|
|
9
|
+
// instance and are enqueued as waiters — the next inbound request wakes one
|
|
10
|
+
// waiter (FIFO). This keeps the plugin lightweight even when a pipeline has
|
|
11
|
+
// many webhook-triggered tasks.
|
|
12
|
+
//
|
|
13
|
+
// Usage in pipeline.yaml:
|
|
14
|
+
// plugins: ["@tagma/trigger-webhook"]
|
|
15
|
+
// tracks:
|
|
16
|
+
// - tasks:
|
|
17
|
+
// - id: deploy
|
|
18
|
+
// trigger:
|
|
19
|
+
// type: webhook
|
|
20
|
+
// port: 8787
|
|
21
|
+
// path: /hooks/deploy
|
|
22
|
+
// secret_env: TAGMA_WEBHOOK_SECRET
|
|
23
|
+
// timeout: 10m
|
|
24
|
+
|
|
25
|
+
import type { TriggerPlugin, TriggerContext } from '@tagma/types';
|
|
26
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
27
|
+
|
|
28
|
+
type Resolver = (payload: unknown) => void;
|
|
29
|
+
|
|
30
|
+
interface WebhookServerState {
|
|
31
|
+
readonly port: number;
|
|
32
|
+
readonly path: string;
|
|
33
|
+
readonly secretEnv: string | undefined;
|
|
34
|
+
readonly waiters: Resolver[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Module-level so concurrent tasks on the same (port, path) share one
|
|
38
|
+
// listener. Bun.serve refuses to bind a port twice, so this sharing is
|
|
39
|
+
// required — not just an optimization.
|
|
40
|
+
const servers = new Map<string, WebhookServerState>();
|
|
41
|
+
|
|
42
|
+
function serverKey(port: number, path: string): string {
|
|
43
|
+
return `${port}::${path}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseDurationSafe(raw: unknown, fallback: number): number {
|
|
47
|
+
if (raw == null) return fallback;
|
|
48
|
+
const str = String(raw).trim();
|
|
49
|
+
const m = str.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);
|
|
50
|
+
if (!m) return fallback;
|
|
51
|
+
const n = Number(m[1]);
|
|
52
|
+
switch (m[2]) {
|
|
53
|
+
case 'ms': return n;
|
|
54
|
+
case 'm': return n * 60_000;
|
|
55
|
+
case 'h': return n * 3_600_000;
|
|
56
|
+
case 's':
|
|
57
|
+
default: return n * 1000;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function verifySignature(rawBody: string, header: string, secret: string): boolean {
|
|
62
|
+
const expected = 'sha256=' + createHmac('sha256', secret).update(rawBody).digest('hex');
|
|
63
|
+
const a = Buffer.from(header);
|
|
64
|
+
const b = Buffer.from(expected);
|
|
65
|
+
if (a.length !== b.length) return false;
|
|
66
|
+
return timingSafeEqual(a, b);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function ensureServer(
|
|
70
|
+
port: number,
|
|
71
|
+
path: string,
|
|
72
|
+
secretEnv: string | undefined,
|
|
73
|
+
): WebhookServerState {
|
|
74
|
+
const key = serverKey(port, path);
|
|
75
|
+
const existing = servers.get(key);
|
|
76
|
+
if (existing) return existing;
|
|
77
|
+
|
|
78
|
+
const state: WebhookServerState = {
|
|
79
|
+
port,
|
|
80
|
+
path,
|
|
81
|
+
secretEnv,
|
|
82
|
+
waiters: [],
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
Bun.serve({
|
|
86
|
+
port,
|
|
87
|
+
async fetch(req) {
|
|
88
|
+
const url = new URL(req.url);
|
|
89
|
+
if (url.pathname !== path) {
|
|
90
|
+
return new Response('not found', { status: 404 });
|
|
91
|
+
}
|
|
92
|
+
if (req.method !== 'POST') {
|
|
93
|
+
return new Response('method not allowed', { status: 405 });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const rawBody = await req.text();
|
|
97
|
+
|
|
98
|
+
// HMAC gate — bypassed when no secret env is configured, which is
|
|
99
|
+
// acceptable for loopback dev but should always be set in production.
|
|
100
|
+
const secret = state.secretEnv ? process.env[state.secretEnv] : undefined;
|
|
101
|
+
if (state.secretEnv) {
|
|
102
|
+
if (!secret) {
|
|
103
|
+
return new Response(`env var ${state.secretEnv} not set`, { status: 500 });
|
|
104
|
+
}
|
|
105
|
+
const sigHeader = req.headers.get('x-tagma-signature') ?? '';
|
|
106
|
+
if (!verifySignature(rawBody, sigHeader, secret)) {
|
|
107
|
+
return new Response('invalid signature', { status: 401 });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Decode JSON if possible so downstream tasks get structured data.
|
|
112
|
+
// Falls back to the raw string body otherwise.
|
|
113
|
+
let payload: unknown = rawBody;
|
|
114
|
+
const contentType = req.headers.get('content-type') ?? '';
|
|
115
|
+
if (contentType.includes('application/json')) {
|
|
116
|
+
try {
|
|
117
|
+
payload = JSON.parse(rawBody);
|
|
118
|
+
} catch {
|
|
119
|
+
/* keep raw body */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const waiter = state.waiters.shift();
|
|
124
|
+
if (waiter) {
|
|
125
|
+
waiter(payload);
|
|
126
|
+
return new Response('ok', { status: 202 });
|
|
127
|
+
}
|
|
128
|
+
// No task is currently waiting on this endpoint — reject loudly so
|
|
129
|
+
// callers know the webhook wasn't actually consumed by a pipeline.
|
|
130
|
+
return new Response('no waiting task', { status: 409 });
|
|
131
|
+
},
|
|
132
|
+
error(err) {
|
|
133
|
+
console.error(`[webhook] server error on :${port}${path}:`, err);
|
|
134
|
+
return new Response('internal error', { status: 500 });
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
servers.set(key, state);
|
|
139
|
+
return state;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const WebhookTrigger: TriggerPlugin = {
|
|
143
|
+
name: 'webhook',
|
|
144
|
+
schema: {
|
|
145
|
+
description:
|
|
146
|
+
'Wait for an HTTP POST to arrive on a local listener before the task runs.',
|
|
147
|
+
fields: {
|
|
148
|
+
port: {
|
|
149
|
+
type: 'number',
|
|
150
|
+
required: true,
|
|
151
|
+
default: 8787,
|
|
152
|
+
min: 1,
|
|
153
|
+
max: 65535,
|
|
154
|
+
description: 'TCP port to listen on.',
|
|
155
|
+
placeholder: '8787',
|
|
156
|
+
},
|
|
157
|
+
path: {
|
|
158
|
+
type: 'string',
|
|
159
|
+
required: true,
|
|
160
|
+
default: '/webhook',
|
|
161
|
+
description: 'URL path to match (e.g. /hooks/deploy).',
|
|
162
|
+
placeholder: '/webhook',
|
|
163
|
+
},
|
|
164
|
+
secret_env: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description:
|
|
167
|
+
'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
|
+
placeholder: 'TAGMA_WEBHOOK_SECRET',
|
|
169
|
+
},
|
|
170
|
+
timeout: {
|
|
171
|
+
type: 'duration',
|
|
172
|
+
description: 'Maximum wait time (e.g. 10m). Omit or 0 to wait indefinitely.',
|
|
173
|
+
placeholder: '10m',
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
watch(config: Record<string, unknown>, ctx: TriggerContext): Promise<unknown> {
|
|
179
|
+
const rawPort = config.port;
|
|
180
|
+
const port = typeof rawPort === 'number' ? rawPort : Number(rawPort);
|
|
181
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
182
|
+
throw new Error(`webhook trigger: "port" must be 1-65535, got ${String(rawPort)}`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const path = (config.path as string | undefined) ?? '/webhook';
|
|
186
|
+
if (!path.startsWith('/')) {
|
|
187
|
+
throw new Error(`webhook trigger: "path" must start with "/", got ${path}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const secretEnv = config.secret_env as string | undefined;
|
|
191
|
+
const timeoutMs = config.timeout != null
|
|
192
|
+
? parseDurationSafe(config.timeout, 0)
|
|
193
|
+
: 0;
|
|
194
|
+
|
|
195
|
+
const state = ensureServer(port, path, secretEnv);
|
|
196
|
+
|
|
197
|
+
return new Promise<unknown>((resolvePromise, rejectPromise) => {
|
|
198
|
+
if (ctx.signal.aborted) {
|
|
199
|
+
rejectPromise(new Error('Pipeline aborted'));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let settled = false;
|
|
204
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
205
|
+
|
|
206
|
+
const onFire: Resolver = (payload) => {
|
|
207
|
+
if (settled) return;
|
|
208
|
+
settled = true;
|
|
209
|
+
cleanup();
|
|
210
|
+
resolvePromise(payload);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const onAbort = (): void => {
|
|
214
|
+
if (settled) return;
|
|
215
|
+
settled = true;
|
|
216
|
+
cleanup();
|
|
217
|
+
rejectPromise(new Error('Pipeline aborted'));
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const cleanup = (): void => {
|
|
221
|
+
if (timer) clearTimeout(timer);
|
|
222
|
+
ctx.signal.removeEventListener('abort', onAbort);
|
|
223
|
+
const idx = state.waiters.indexOf(onFire);
|
|
224
|
+
if (idx !== -1) state.waiters.splice(idx, 1);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
state.waiters.push(onFire);
|
|
228
|
+
ctx.signal.addEventListener('abort', onAbort, { once: true });
|
|
229
|
+
|
|
230
|
+
if (timeoutMs > 0) {
|
|
231
|
+
timer = setTimeout(() => {
|
|
232
|
+
if (settled) return;
|
|
233
|
+
settled = true;
|
|
234
|
+
cleanup();
|
|
235
|
+
rejectPromise(
|
|
236
|
+
new Error(
|
|
237
|
+
`webhook trigger timeout: no POST on :${port}${path} within ${String(config.timeout)}`,
|
|
238
|
+
),
|
|
239
|
+
);
|
|
240
|
+
}, timeoutMs);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// ═══ Plugin self-description exports ═══
|
|
247
|
+
export const pluginCategory = 'triggers';
|
|
248
|
+
export const pluginType = 'webhook';
|
|
249
|
+
export default WebhookTrigger;
|