@mushi-mushi/plugin-zapier 0.2.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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/chunk-4NOWCHTE.js +46 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +7 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +45 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kenji Sakuramoto
|
|
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,45 @@
|
|
|
1
|
+
# `@mushi-mushi/plugin-zapier`
|
|
2
|
+
|
|
3
|
+
Reference Mushi Mushi plugin: forward any Mushi event to a Zapier "Catch
|
|
4
|
+
Hook" trigger so non-engineers can wire Mushi into the rest of the org's
|
|
5
|
+
automation surface (Notion, Sheets, Mailchimp, Slack channels, etc.).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @mushi-mushi/plugin-zapier
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Run as a stand-alone server
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ZAPIER_HOOK_URL=https://hooks.zapier.com/hooks/catch/.../...
|
|
17
|
+
MUSHI_PLUGIN_SECRET=...
|
|
18
|
+
ALLOW_EVENTS=report.classified,sla.breached # optional
|
|
19
|
+
DENY_EVENTS=report.dedup_grouped # optional
|
|
20
|
+
PORT=3000
|
|
21
|
+
npx mushi-plugin-zapier
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The handler subscribes to `*` and forwards a flattened payload that Zapier
|
|
25
|
+
can parse without diving into nested objects:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"event": "report.classified",
|
|
30
|
+
"delivery_id": "...",
|
|
31
|
+
"occurred_at": "...",
|
|
32
|
+
"project_id": "...",
|
|
33
|
+
"plugin_slug": "zapier",
|
|
34
|
+
"report_id": "...",
|
|
35
|
+
"report_status": "classified",
|
|
36
|
+
"report_category": "bug",
|
|
37
|
+
"report_severity": "high",
|
|
38
|
+
"report_title": "Login button does nothing",
|
|
39
|
+
"raw": { /* full Mushi envelope */ }
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { createPluginHandler } from "@mushi-mushi/plugin-sdk";
|
|
5
|
+
function createZapierPlugin(cfg) {
|
|
6
|
+
const f = cfg.fetchImpl ?? fetch;
|
|
7
|
+
const allow = new Set(cfg.allowEvents ?? []);
|
|
8
|
+
const deny = new Set(cfg.denyEvents ?? []);
|
|
9
|
+
return createPluginHandler({
|
|
10
|
+
secret: cfg.mushiSecret,
|
|
11
|
+
on: {
|
|
12
|
+
"*": async (e) => {
|
|
13
|
+
if (allow.size > 0 && !allow.has(e.event)) return;
|
|
14
|
+
if (deny.has(e.event)) return;
|
|
15
|
+
const flat = flattenForZapier(e);
|
|
16
|
+
const res = await f(cfg.zapierHookUrl, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "Content-Type": "application/json" },
|
|
19
|
+
body: JSON.stringify(flat)
|
|
20
|
+
});
|
|
21
|
+
if (!res.ok) throw new Error(`Zapier hook ${res.status}: ${await res.text()}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function flattenForZapier(e) {
|
|
27
|
+
const data = e.data ?? {};
|
|
28
|
+
const report = data.report ?? {};
|
|
29
|
+
return {
|
|
30
|
+
event: e.event,
|
|
31
|
+
delivery_id: e.deliveryId,
|
|
32
|
+
occurred_at: e.occurredAt,
|
|
33
|
+
project_id: e.projectId,
|
|
34
|
+
plugin_slug: e.pluginSlug,
|
|
35
|
+
report_id: report.id,
|
|
36
|
+
report_status: report.status,
|
|
37
|
+
report_category: report.category,
|
|
38
|
+
report_severity: report.severity,
|
|
39
|
+
report_title: report.title,
|
|
40
|
+
raw: e
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
createZapierPlugin
|
|
46
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _mushi_mushi_plugin_sdk from '@mushi-mushi/plugin-sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zapier plugin for Mushi Mushi.
|
|
5
|
+
*
|
|
6
|
+
* Subscribes to all events (`*`). For each, POSTs a flattened JSON payload
|
|
7
|
+
* (Zapier dislikes deep nesting in trigger samples) to the configured Zapier
|
|
8
|
+
* "Catch Hook" URL. Optional event allow/deny lists let users gate which
|
|
9
|
+
* triggers fire which Zaps.
|
|
10
|
+
*/
|
|
11
|
+
interface ZapierPluginConfig {
|
|
12
|
+
zapierHookUrl: string;
|
|
13
|
+
mushiSecret: string;
|
|
14
|
+
/** Only forward these events (whitelist). If empty, forward everything. */
|
|
15
|
+
allowEvents?: string[];
|
|
16
|
+
/** Drop these events (blacklist). Applied after `allowEvents`. */
|
|
17
|
+
denyEvents?: string[];
|
|
18
|
+
fetchImpl?: typeof fetch;
|
|
19
|
+
}
|
|
20
|
+
declare function createZapierPlugin(cfg: ZapierPluginConfig): (input: _mushi_mushi_plugin_sdk.HandlePluginRequestInput) => Promise<_mushi_mushi_plugin_sdk.HandlePluginResult>;
|
|
21
|
+
|
|
22
|
+
export { type ZapierPluginConfig, createZapierPlugin };
|
package/dist/index.js
ADDED
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
createZapierPlugin
|
|
4
|
+
} from "./chunk-4NOWCHTE.js";
|
|
5
|
+
|
|
6
|
+
// src/server.ts
|
|
7
|
+
import { createServer } from "http";
|
|
8
|
+
var port = Number(process.env.PORT ?? 3e3);
|
|
9
|
+
var handler = createZapierPlugin({
|
|
10
|
+
zapierHookUrl: required("ZAPIER_HOOK_URL"),
|
|
11
|
+
mushiSecret: required("MUSHI_PLUGIN_SECRET"),
|
|
12
|
+
allowEvents: parseList(process.env.ALLOW_EVENTS),
|
|
13
|
+
denyEvents: parseList(process.env.DENY_EVENTS)
|
|
14
|
+
});
|
|
15
|
+
createServer(async (req, res) => {
|
|
16
|
+
if (req.method !== "POST" || req.url !== "/mushi/webhook") {
|
|
17
|
+
res.statusCode = 404;
|
|
18
|
+
res.end();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const chunks = [];
|
|
22
|
+
req.on("data", (c) => chunks.push(c));
|
|
23
|
+
req.on("end", async () => {
|
|
24
|
+
const rawBody = Buffer.concat(chunks).toString("utf8");
|
|
25
|
+
const headers = {};
|
|
26
|
+
for (const [k, v] of Object.entries(req.headers)) headers[k] = Array.isArray(v) ? v[0] : v;
|
|
27
|
+
const result = await handler({ rawBody, headers });
|
|
28
|
+
res.statusCode = result.status;
|
|
29
|
+
res.setHeader("Content-Type", "application/json");
|
|
30
|
+
res.end(JSON.stringify(result.body));
|
|
31
|
+
});
|
|
32
|
+
}).listen(port, () => {
|
|
33
|
+
console.log(`mushi-plugin-zapier listening on :${port}`);
|
|
34
|
+
});
|
|
35
|
+
function required(name) {
|
|
36
|
+
const v = process.env[name];
|
|
37
|
+
if (!v) {
|
|
38
|
+
console.error(`Missing required env var: ${name}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
return v;
|
|
42
|
+
}
|
|
43
|
+
function parseList(v) {
|
|
44
|
+
return v ? v.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mushi-mushi/plugin-zapier",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Reference Mushi Mushi plugin: fan out any Mushi event to a Zapier-style incoming webhook.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"mushi-plugin-zapier": "./dist/server.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@mushi-mushi/plugin-sdk": "^0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"eslint": "^10.2.0",
|
|
29
|
+
"tsup": "^8.4.0",
|
|
30
|
+
"typescript": "^6.0.2",
|
|
31
|
+
"vitest": "^4.1.4",
|
|
32
|
+
"@mushi-mushi/eslint-config": "0.0.0"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/kensaurus/mushi-mushi.git",
|
|
37
|
+
"directory": "packages/plugin-zapier"
|
|
38
|
+
},
|
|
39
|
+
"author": "Kenji Sakuramoto",
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"keywords": [
|
|
45
|
+
"mushi-mushi",
|
|
46
|
+
"plugin",
|
|
47
|
+
"zapier",
|
|
48
|
+
"webhook",
|
|
49
|
+
"automation"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup",
|
|
53
|
+
"dev": "tsup --watch",
|
|
54
|
+
"lint": "eslint src/",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|