@applogico/blipr-mcp 0.1.2 → 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/dist/publish.js +17 -8
- package/package.json +1 -1
package/dist/publish.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
/** Blipr publish client — the one piece of real logic, kept pure for testing. */
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Publish a message to a Blipr topic. Returns the resolved topic on success.
|
|
4
|
+
*
|
|
5
|
+
* Uses the JSON publish endpoint (`POST /api/notify`) rather than the
|
|
6
|
+
* header-based one. The JSON body is UTF-8, so titles/messages with emoji or
|
|
7
|
+
* accents work — HTTP headers are Latin-1 only and would corrupt or reject them.
|
|
8
|
+
*/
|
|
3
9
|
export async function publish(opts, cfg) {
|
|
4
10
|
const topic = (opts.topic ?? cfg.defaultTopic ?? "").trim();
|
|
5
11
|
if (!topic) {
|
|
6
12
|
throw new Error("No topic given and BLIPR_TOPIC is not set. Pass `topic`, or set the BLIPR_TOPIC env var.");
|
|
7
13
|
}
|
|
8
|
-
const
|
|
14
|
+
const payload = { topic, message: opts.message };
|
|
9
15
|
if (opts.title)
|
|
10
|
-
|
|
16
|
+
payload.title = opts.title;
|
|
11
17
|
if (opts.priority)
|
|
12
|
-
|
|
18
|
+
payload.priority = opts.priority;
|
|
13
19
|
if (opts.tags?.length)
|
|
14
|
-
|
|
20
|
+
payload.tags = opts.tags;
|
|
15
21
|
if (opts.click)
|
|
16
|
-
|
|
22
|
+
payload.click = opts.click;
|
|
17
23
|
const base = cfg.bliprUrl.replace(/\/+$/, "");
|
|
18
|
-
const url = `${base}/api/notify/${encodeURIComponent(topic)}`;
|
|
19
24
|
let res;
|
|
20
25
|
try {
|
|
21
|
-
res = await fetch(
|
|
26
|
+
res = await fetch(`${base}/api/notify`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { "Content-Type": "application/json" },
|
|
29
|
+
body: JSON.stringify(payload),
|
|
30
|
+
});
|
|
22
31
|
}
|
|
23
32
|
catch (e) {
|
|
24
33
|
throw new Error(`Could not reach Blipr at ${base}: ${e.message}`);
|