@checkstack/notification-discord-backend 0.1.28 → 0.1.30

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 CHANGED
@@ -1,5 +1,52 @@
1
1
  # @checkstack/notification-discord-backend
2
2
 
3
+ ## 0.1.30
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [f23f3c9]
8
+ - Updated dependencies [f23f3c9]
9
+ - Updated dependencies [f23f3c9]
10
+ - Updated dependencies [f23f3c9]
11
+ - Updated dependencies [f23f3c9]
12
+ - @checkstack/common@0.11.0
13
+ - @checkstack/backend-api@0.17.0
14
+ - @checkstack/notification-backend@1.2.0
15
+
16
+ ## 0.1.29
17
+
18
+ ### Patch Changes
19
+
20
+ - a06b899: Dead-code audit cleanup and a small platform of shared notification helpers.
21
+
22
+ **Removed (dead code)**
23
+
24
+ - `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`.
25
+ - `createMockQueueFactory` deprecated alias removed from `@checkstack/test-utils-backend`. Use `createMockQueueManager` directly.
26
+
27
+ **New shared helpers**
28
+
29
+ - `@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.
30
+ - `@checkstack/notification-common` now exports `SubjectStatusSchema` / `SubjectStatus`, mirroring the existing `ImportanceSchema`.
31
+ - `@checkstack/notification-backend` now exports:
32
+ - `SUBJECT_STATUS_EMOJI` / `IMPORTANCE_EMOJI` — the shared status / importance emoji maps that Discord, Slack, Teams, Webex and Telegram previously each redefined inline.
33
+ - `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 }`.
34
+
35
+ **Migrated to shared helpers**
36
+
37
+ - Discord, Slack, Gotify, Pushover notification backends now use `postJson`. Outer try/catch + per-plugin error mapping deleted (~140 LOC).
38
+ - Discord, Slack, Teams, Telegram, Webex notification backends now use `IMPORTANCE_EMOJI`. Discord, Slack, Teams use `SUBJECT_STATUS_EMOJI`.
39
+ - 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`).
40
+
41
+ **API surface tightening**
42
+
43
+ - 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.
44
+
45
+ - Updated dependencies [a06b899]
46
+ - Updated dependencies [a06b899]
47
+ - @checkstack/backend-api@0.16.0
48
+ - @checkstack/notification-backend@1.1.0
49
+
3
50
  ## 0.1.28
4
51
 
5
52
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/notification-discord-backend",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
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.2",
21
+ "@checkstack/backend-api": "0.16.0",
22
22
  "@checkstack/common": "0.10.0",
23
- "@checkstack/notification-backend": "1.0.4",
23
+ "@checkstack/notification-backend": "1.1.0",
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 { notificationStrategyExtensionPoint } from "@checkstack/notification-backend";
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: `${importanceEmoji[importance]} ${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
- try {
196
- // Build the embed
197
- const embed = buildDiscordEmbed({
198
- title: notification.title,
199
- body: notification.body,
200
- importance: notification.importance,
201
- action: notification.action,
202
- subjects: notification.subjects,
203
- });
204
-
205
- // Send to Discord webhook
206
- const response = await fetch(userConfig.webhookUrl, {
207
- method: "POST",
208
- headers: {
209
- "Content-Type": "application/json",
210
- },
211
- body: JSON.stringify({
212
- embeds: [embed],
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
- // Export for testing
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 };