@checkstack/notification-discord-backend 0.1.28 → 0.1.29
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/CHANGELOG.md +34 -0
- package/package.json +3 -3
- package/src/index.ts +32 -63
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @checkstack/notification-discord-backend
|
|
2
2
|
|
|
3
|
+
## 0.1.29
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a06b899: Dead-code audit cleanup and a small platform of shared notification helpers.
|
|
8
|
+
|
|
9
|
+
**Removed (dead code)**
|
|
10
|
+
|
|
11
|
+
- `core/backend/src/plugin-manager/deregistration-guard.ts` deleted. The exported `assertCanDeregister()` was never called and was a less-complete version of the dependents+isUninstallable checks already done inline by `previewUninstallOriginator` / `uninstallOriginator` in `plugin-manager-orchestrator.ts`.
|
|
12
|
+
- `createMockQueueFactory` deprecated alias removed from `@checkstack/test-utils-backend`. Use `createMockQueueManager` directly.
|
|
13
|
+
|
|
14
|
+
**New shared helpers**
|
|
15
|
+
|
|
16
|
+
- `@checkstack/backend-api` now exports `requestTimeoutMs()` — a Zod field builder for outbound HTTP request timeouts (1s..60s, default 10s). Replaces hand-rolled `configNumber({}).min(1000).max(60_000).default(10_000)` in `integration-webhook-backend`, `integration-script-backend`, and `healthcheck-script-backend`'s inline collector.
|
|
17
|
+
- `@checkstack/notification-common` now exports `SubjectStatusSchema` / `SubjectStatus`, mirroring the existing `ImportanceSchema`.
|
|
18
|
+
- `@checkstack/notification-backend` now exports:
|
|
19
|
+
- `SUBJECT_STATUS_EMOJI` / `IMPORTANCE_EMOJI` — the shared status / importance emoji maps that Discord, Slack, Teams, Webex and Telegram previously each redefined inline.
|
|
20
|
+
- `postJson(opts)` — a timeout-bounded `fetch` wrapper that handles non-2xx logging and error mapping for webhook-style POSTs. Returns `{ ok: true, response } | { ok: false, error }`.
|
|
21
|
+
|
|
22
|
+
**Migrated to shared helpers**
|
|
23
|
+
|
|
24
|
+
- Discord, Slack, Gotify, Pushover notification backends now use `postJson`. Outer try/catch + per-plugin error mapping deleted (~140 LOC).
|
|
25
|
+
- Discord, Slack, Teams, Telegram, Webex notification backends now use `IMPORTANCE_EMOJI`. Discord, Slack, Teams use `SUBJECT_STATUS_EMOJI`.
|
|
26
|
+
- Teams, Webex, Backstage, Telegram kept their inline fetch/Bot logic: their error strings surface server response bodies to operators, or the transport isn't raw `fetch` (Telegram uses `grammy`'s `Bot`).
|
|
27
|
+
|
|
28
|
+
**API surface tightening**
|
|
29
|
+
|
|
30
|
+
- Per-plugin test-only re-exports in 6 notification backends (Pushover, Gotify, Backstage, Slack, Discord, Teams) and the `CertificateInfo` interface in `healthcheck-tls-backend/strategy.ts` are now JSDoc-tagged `@internal`. No behaviour change; signals that downstream consumers must not depend on them.
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [a06b899]
|
|
33
|
+
- Updated dependencies [a06b899]
|
|
34
|
+
- @checkstack/backend-api@0.16.0
|
|
35
|
+
- @checkstack/notification-backend@1.1.0
|
|
36
|
+
|
|
3
37
|
## 0.1.28
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/notification-discord-backend",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"checkstack": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"pack": "bunx @checkstack/scripts plugin-pack"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@checkstack/backend-api": "0.15.
|
|
21
|
+
"@checkstack/backend-api": "0.15.3",
|
|
22
22
|
"@checkstack/common": "0.10.0",
|
|
23
|
-
"@checkstack/notification-backend": "1.0.
|
|
23
|
+
"@checkstack/notification-backend": "1.0.5",
|
|
24
24
|
"zod": "^4.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -9,9 +9,13 @@ import {
|
|
|
9
9
|
type NotificationSubject,
|
|
10
10
|
markdownToPlainText,
|
|
11
11
|
} from "@checkstack/backend-api";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
notificationStrategyExtensionPoint,
|
|
14
|
+
postJson,
|
|
15
|
+
SUBJECT_STATUS_EMOJI,
|
|
16
|
+
IMPORTANCE_EMOJI,
|
|
17
|
+
} from "@checkstack/notification-backend";
|
|
13
18
|
import { pluginMetadata } from "./plugin-metadata";
|
|
14
|
-
import { extractErrorMessage } from "@checkstack/common";
|
|
15
19
|
|
|
16
20
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
17
21
|
// Configuration Schemas
|
|
@@ -79,13 +83,6 @@ interface DiscordEmbed {
|
|
|
79
83
|
timestamp?: string;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
const SUBJECT_STATUS_EMOJI = {
|
|
83
|
-
healthy: "🟢",
|
|
84
|
-
degraded: "🟡",
|
|
85
|
-
unhealthy: "🔴",
|
|
86
|
-
unknown: "⚪",
|
|
87
|
-
} as const;
|
|
88
|
-
|
|
89
86
|
function buildDiscordEmbed(options: DiscordEmbedOptions): DiscordEmbed {
|
|
90
87
|
const { title, body, importance, action, subjects } = options;
|
|
91
88
|
|
|
@@ -96,14 +93,8 @@ function buildDiscordEmbed(options: DiscordEmbedOptions): DiscordEmbed {
|
|
|
96
93
|
critical: 0xEF_44_44, // Red
|
|
97
94
|
};
|
|
98
95
|
|
|
99
|
-
const importanceEmoji: Record<string, string> = {
|
|
100
|
-
info: "ℹ️",
|
|
101
|
-
warning: "⚠️",
|
|
102
|
-
critical: "🚨",
|
|
103
|
-
};
|
|
104
|
-
|
|
105
96
|
const embed: DiscordEmbed = {
|
|
106
|
-
title: `${
|
|
97
|
+
title: `${IMPORTANCE_EMOJI[importance]} ${title}`,
|
|
107
98
|
color: importanceColors[importance],
|
|
108
99
|
timestamp: new Date().toISOString(),
|
|
109
100
|
};
|
|
@@ -192,52 +183,25 @@ const discordStrategy: NotificationStrategy<DiscordConfig, DiscordUserConfig> =
|
|
|
192
183
|
};
|
|
193
184
|
}
|
|
194
185
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
signal: AbortSignal.timeout(10_000),
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
if (!response.ok) {
|
|
218
|
-
const errorText = await response.text();
|
|
219
|
-
logger.error("Failed to send Discord message", {
|
|
220
|
-
status: response.status,
|
|
221
|
-
error: errorText.slice(0, 500),
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
success: false,
|
|
225
|
-
error: `Failed to send Discord message: ${response.status}`,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Discord webhooks return 204 No Content on success
|
|
230
|
-
return {
|
|
231
|
-
success: true,
|
|
232
|
-
};
|
|
233
|
-
} catch (error) {
|
|
234
|
-
const message = extractErrorMessage(error, "Unknown Discord API error");
|
|
235
|
-
logger.error("Discord notification error", { error: message });
|
|
236
|
-
return {
|
|
237
|
-
success: false,
|
|
238
|
-
error: `Failed to send Discord notification: ${message}`,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
186
|
+
// Build the embed
|
|
187
|
+
const embed = buildDiscordEmbed({
|
|
188
|
+
title: notification.title,
|
|
189
|
+
body: notification.body,
|
|
190
|
+
importance: notification.importance,
|
|
191
|
+
action: notification.action,
|
|
192
|
+
subjects: notification.subjects,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Send to Discord webhook
|
|
196
|
+
const result = await postJson({
|
|
197
|
+
url: userConfig.webhookUrl,
|
|
198
|
+
body: { embeds: [embed] },
|
|
199
|
+
serviceName: "Discord",
|
|
200
|
+
logger,
|
|
201
|
+
});
|
|
202
|
+
return result.ok
|
|
203
|
+
? { success: true }
|
|
204
|
+
: { success: false, error: result.error };
|
|
241
205
|
},
|
|
242
206
|
};
|
|
243
207
|
|
|
@@ -259,6 +223,11 @@ export default createBackendPlugin({
|
|
|
259
223
|
},
|
|
260
224
|
});
|
|
261
225
|
|
|
262
|
-
|
|
226
|
+
/**
|
|
227
|
+
* Internal exports for the package's own unit tests. Not part of the plugin's
|
|
228
|
+
* public API surface.
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
263
231
|
export { discordConfigSchemaV1, discordUserConfigSchema, buildDiscordEmbed };
|
|
232
|
+
/** @internal */
|
|
264
233
|
export type { DiscordConfig, DiscordUserConfig, DiscordEmbedOptions };
|