-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateWebhooks.mjs
40 lines (36 loc) · 1.2 KB
/
updateWebhooks.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function main() {
const files = fs.readdirSync(path.join(__dirname, './webhooks'));
const webhookFiles = files.filter((file) => !file.includes('test'));
for (const webhookFile of webhookFiles) {
const [, name, webhookId] = webhookFile.match(/(\w+)\.([\w-]+)/);
const fileContents = fs.readFileSync(
path.join(__dirname, './webhooks/', webhookFile)
);
const response = await fetch(
`https://api.inngest.com/v1/webhooks/${webhookId}`,
{
method: 'PUT',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`,
},
body: JSON.stringify({
name,
transform: fileContents.toString(),
}),
}
);
if (response.status !== 200) {
const body = await response.json();
throw new Error(body.error || 'unknown error');
}
}
console.log(`Updated ${webhookFiles.length} webhook transforms`);
}
main();