@frigear-nu/notify 0.3.3 → 0.4.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/dist/module.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type SlackMessage = {
|
|
2
|
+
text: string;
|
|
3
|
+
blocks?: Record<string, unknown>[];
|
|
4
|
+
mrkdwn?: boolean;
|
|
5
|
+
unfurl_links?: boolean;
|
|
6
|
+
unfurl_media?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Posts to a Slack incoming webhook. Errors never include the secret URL. */
|
|
9
|
+
export declare function postToSlack(webhookUrl: string, message: SlackMessage): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export async function postToSlack(webhookUrl, message) {
|
|
2
|
+
const url = URL.parse(webhookUrl);
|
|
3
|
+
if (!url || !["https://hooks.slack.com", "https://hooks.slack-gov.com"].includes(url.origin) || url.username || url.password || url.search || url.hash || !/^\/services\/[\w-]+\/[\w-]+\/[\w-]+$/.test(url.pathname)) {
|
|
4
|
+
throw new Error("Invalid Slack incoming webhook URL.");
|
|
5
|
+
}
|
|
6
|
+
let response;
|
|
7
|
+
try {
|
|
8
|
+
response = await fetch(url, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: { "content-type": "application/json" },
|
|
11
|
+
body: JSON.stringify(message),
|
|
12
|
+
redirect: "error",
|
|
13
|
+
signal: AbortSignal.timeout(1e4)
|
|
14
|
+
});
|
|
15
|
+
} catch {
|
|
16
|
+
throw new Error("Slack incoming webhook request failed.");
|
|
17
|
+
}
|
|
18
|
+
if (!response.ok) throw new Error(`Slack incoming webhook returned HTTP ${response.status}.`);
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/notify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Email, SMS, push and generic notification dispatch (pluggable drivers), and notifyUser: per-user channel choices over a topic registry. Shared across Frigear modules.",
|
|
6
6
|
"keywords": [
|