@checkstack/healthcheck-backend 0.18.1 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # @checkstack/healthcheck-backend
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 32d52c6: feat: notification target pattern + per-spec subscriptions
8
+
9
+ Replaces the all-or-nothing catalog system/group notification model with a
10
+ platform-level target pattern. Each notification-emitting plugin declares
11
+ _subscription specs_ against typed _target_ objects exported from the
12
+ target's owning plugin (catalog ships `catalogSystemTarget` and
13
+ `catalogGroupTarget`). Notification-backend handles every per-resource
14
+ group lifecycle, parent-edge inheritance, and legacy-subscription seeding
15
+ — plugins never author groupId helpers, lifecycle hooks, or migration
16
+ code again.
17
+
18
+ **Plugin-author surface area is now ~12 lines per emitter:**
19
+
20
+ ```ts
21
+ // <plugin>-common
22
+ const { defineSubscription } = createSubscriptionFactory(pluginMetadata);
23
+ export const fooSystemSubscription = defineSubscription({
24
+ localId: "system",
25
+ target: catalogSystemTarget,
26
+ display: { title: "Foo Alerts", description: "...", iconName: "Bell" },
27
+ });
28
+
29
+ // <plugin>-backend register()
30
+ env.registerSubscriptionSpecs([fooSystemSubscription]);
31
+ // ^ feeds the plugin loader's dependency sorter — each spec's
32
+ // target.ownerPlugin becomes an implicit init-order dep, so this
33
+ // plugin automatically waits for catalog (the target owner) to
34
+ // finish init + afterPluginsReady before its own runs.
35
+
36
+ // <plugin>-backend afterPluginsReady
37
+ await notificationClient.registerSubscriptionSpec(
38
+ specToRegistration(fooSystemSubscription)
39
+ );
40
+ // dispatch
41
+ await notificationClient.notifyForSubscription({
42
+ specId: fooSystemSubscription.specId,
43
+ resourceKeys: [systemId],
44
+ title,
45
+ body,
46
+ importance,
47
+ action,
48
+ collapseKey,
49
+ subjects,
50
+ });
51
+
52
+ // <plugin>-frontend
53
+ createNotificationSubscriptionExtension({ spec: fooSystemSubscription });
54
+ ```
55
+
56
+ **Migrated plugins**: anomaly, incident, maintenance, healthcheck,
57
+ dependency. Each lost its bespoke `notification-groups.ts`,
58
+ `bootstrap*NotificationGroups`, `ensure*Group`, and inheritance walk —
59
+ all of that is now centralized in notification-backend's
60
+ `subscription-engine`.
61
+
62
+ **Plugin loader change** (`@checkstack/backend-api`,
63
+ `@checkstack/backend`): the register-time API gains
64
+ `env.registerSubscriptionSpecs([...specs])`. The dependency sorter
65
+ walks `spec.target.ownerPlugin` for every declared spec and adds the
66
+ target owner as an init-order dependency of the emitting plugin. This
67
+ guarantees that catalog (the owner of the platform's `system` and
68
+ `group` targets) completes init + afterPluginsReady before any
69
+ emitting plugin tries to register its specs against the notification
70
+ service — no string-prefix heuristics, no manual `dependsOnPlugins`
71
+ list, no stub rows. Plugins that fail to declare their specs at
72
+ register time get a clear `Target type X is not registered. Did the
73
+ emitting plugin declare this spec via env.registerSubscriptionSpecs?`
74
+ error from the dispatcher.
75
+
76
+ **Removed** (no backwards compat):
77
+
78
+ - `catalogClient.notifySystemSubscribers` and
79
+ `catalogClient.notifyManySystemSubscribers`
80
+ - `notificationClient.notifyUsers` and `notificationClient.notifyGroups`
81
+ as direct dispatch primitives — replaced by spec-bound
82
+ `notifyForSubscription`
83
+ - catalog's `bootstrapNotificationGroups` (replaced by
84
+ `bootstrapNotificationTargets`)
85
+
86
+ **Enforcement**: the dispatcher rejects calls referencing unregistered
87
+ specIds, specs owned by other plugins, or resourceKeys that haven't been
88
+ pushed via `upsertNotificationResource`. Display metadata for any
89
+ groupId is recoverable via the spec registry, so audit lists render
90
+ correct labels even when an emitter's frontend isn't loaded.
91
+
92
+ **Per-field anomaly mute** keeps working — it now lives inside the
93
+ generic SubscriptionRow's optional `SubControls` panel
94
+ (`AnomalyFieldMuteList`), exposed through the catalog system detail
95
+ page's notifications card.
96
+
97
+ The catalog system detail page renders a "Notifications" card hosting
98
+ `SystemNotificationSubscriptionsSlot`. The matching group surface is
99
+ not yet rendered — group-level subscriptions are wired end-to-end on
100
+ the backend; a follow-up will add the host UI.
101
+
102
+ **Migration of existing subscribers**: target types declare a
103
+ `legacyGroupIdTemplate`; on first registration of each spec,
104
+ notification-backend reads subscribers from the legacy
105
+ `catalog.system.<id>` / `catalog.group.<id>` groups and seeds the new
106
+ spec groups exactly once per (spec × resource) pair, tracked in
107
+ `subscription_migrations`. Anomaly stays opt-in (its target also
108
+ declares the template, but the user-explicit nature of the original
109
+ opt-in flow means the seeding produces the same set of subscribers
110
+ they already had).
111
+
112
+ ### Patch Changes
113
+
114
+ - 32d52c6: Bulk notifications affecting multiple systems and collapse lifecycle events into a single card.
115
+
116
+ Notifications now carry an optional `subjects` array (the entities they affect) and an optional `collapseKey` (so related notifications collapse into one row per recipient). Incidents, maintenances, anomalies, healthchecks, and dependency-impact events route through these new fields, so an incident affecting three systems produces one in-app notification + one external send per subscriber instead of three. Lifecycle updates for the same entity (created → updated → resolved) also collapse, with an expandable "+N updates" timeline.
117
+
118
+ Subject kinds are namespaced as `<pluginId>.<localKind>` and built via type-safe helpers exported from each domain's common package (`createSystemSubject`, `incidentCollapseKey`, etc.). The frontend kind registry (`registerSubjectKind`) lets plugins bind icon + label for their kinds; unknown kinds fall back to a generic chip.
119
+
120
+ All notification strategies (SMTP, Slack, Discord, Teams, Telegram, Pushover, Gotify, Webex, Backstage) render the affected subjects natively in their format (HTML cards, Slack blocks, Discord embed fields, adaptive cards, markdown lists, etc.).
121
+
122
+ - Updated dependencies [32d52c6]
123
+ - Updated dependencies [32d52c6]
124
+ - Updated dependencies [32d52c6]
125
+ - Updated dependencies [32d52c6]
126
+ - Updated dependencies [32d52c6]
127
+ - Updated dependencies [32d52c6]
128
+ - @checkstack/gitops-backend@0.2.6
129
+ - @checkstack/integration-backend@0.1.22
130
+ - @checkstack/satellite-backend@0.2.18
131
+ - @checkstack/notification-common@1.0.0
132
+ - @checkstack/catalog-backend@1.0.0
133
+ - @checkstack/catalog-common@2.0.0
134
+ - @checkstack/incident-common@1.0.0
135
+ - @checkstack/maintenance-common@1.0.0
136
+ - @checkstack/healthcheck-common@1.0.0
137
+ - @checkstack/backend-api@0.14.0
138
+ - @checkstack/cache-api@0.2.2
139
+ - @checkstack/command-backend@0.1.22
140
+ - @checkstack/queue-api@0.2.16
141
+ - @checkstack/cache-utils@0.2.2
142
+
3
143
  ## 0.18.1
4
144
 
5
145
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/healthcheck-backend",
3
- "version": "0.18.1",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "checkstack": {
@@ -13,22 +13,23 @@
13
13
  "lint:code": "eslint . --max-warnings 0"
14
14
  },
15
15
  "dependencies": {
16
- "@checkstack/backend-api": "0.13.0",
17
- "@checkstack/cache-api": "0.2.0",
18
- "@checkstack/cache-utils": "0.2.0",
19
- "@checkstack/catalog-backend": "0.7.0",
20
- "@checkstack/catalog-common": "1.5.2",
21
- "@checkstack/command-backend": "0.1.20",
16
+ "@checkstack/backend-api": "0.13.1",
17
+ "@checkstack/cache-api": "0.2.1",
18
+ "@checkstack/cache-utils": "0.2.1",
19
+ "@checkstack/catalog-backend": "0.7.1",
20
+ "@checkstack/catalog-common": "1.5.3",
21
+ "@checkstack/command-backend": "0.1.21",
22
22
  "@checkstack/common": "0.7.0",
23
- "@checkstack/gitops-backend": "0.2.4",
23
+ "@checkstack/gitops-backend": "0.2.5",
24
24
  "@checkstack/gitops-common": "0.2.1",
25
- "@checkstack/healthcheck-common": "0.12.0",
26
- "@checkstack/incident-common": "0.4.9",
27
- "@checkstack/integration-backend": "0.1.20",
28
- "@checkstack/maintenance-common": "0.4.11",
29
- "@checkstack/queue-api": "0.2.14",
30
- "@checkstack/satellite-backend": "0.2.16",
31
- "@checkstack/signal-common": "0.1.10",
25
+ "@checkstack/healthcheck-common": "0.13.0",
26
+ "@checkstack/incident-common": "0.5.0",
27
+ "@checkstack/integration-backend": "0.1.21",
28
+ "@checkstack/maintenance-common": "0.5.0",
29
+ "@checkstack/notification-common": "0.3.0",
30
+ "@checkstack/queue-api": "0.2.15",
31
+ "@checkstack/satellite-backend": "0.2.17",
32
+ "@checkstack/signal-common": "0.2.0",
32
33
  "@hono/zod-validator": "^0.7.6",
33
34
  "drizzle-orm": "^0.45.0",
34
35
  "hono": "^4.12.14",
@@ -39,11 +40,12 @@
39
40
  "devDependencies": {
40
41
  "@checkstack/drizzle-helper": "0.0.4",
41
42
  "@checkstack/scripts": "0.1.2",
42
- "@checkstack/test-utils-backend": "0.1.20",
43
+ "@checkstack/test-utils-backend": "0.1.21",
43
44
  "@checkstack/tsconfig": "0.0.5",
44
45
  "@types/bun": "^1.0.0",
45
46
  "@types/tdigest": "^0.1.5",
46
47
  "date-fns": "^4.1.0",
48
+ "drizzle-kit": "^0.31.10",
47
49
  "typescript": "^5.0.0"
48
50
  }
49
51
  }
package/src/index.ts CHANGED
@@ -10,7 +10,13 @@ import {
10
10
  pluginMetadata,
11
11
  healthCheckContract,
12
12
  healthcheckRoutes,
13
+ healthcheckSystemSubscription,
14
+ healthcheckGroupSubscription,
13
15
  } from "@checkstack/healthcheck-common";
16
+ import {
17
+ NotificationApi,
18
+ specToRegistration,
19
+ } from "@checkstack/notification-common";
14
20
  import {
15
21
  createBackendPlugin,
16
22
  coreServices,
@@ -67,6 +73,10 @@ export default createBackendPlugin({
67
73
  metadata: pluginMetadata,
68
74
  register(env) {
69
75
  env.registerAccessRules(healthCheckAccessRules);
76
+ env.registerSubscriptionSpecs([
77
+ healthcheckSystemSubscription,
78
+ healthcheckGroupSubscription,
79
+ ]);
70
80
 
71
81
  // Register hooks as integration events
72
82
  const integrationEvents = env.getExtensionPoint(
@@ -179,6 +189,9 @@ export default createBackendPlugin({
179
189
  // Create incident client for notification suppression checks
180
190
  const incidentClient = rpcClient.forPlugin(IncidentApi);
181
191
 
192
+ // Notification client for spec-bound dispatch
193
+ const notificationClient = rpcClient.forPlugin(NotificationApi);
194
+
182
195
  // Create gitops client for provenance lock checks
183
196
  const gitOpsClient = rpcClient.forPlugin(GitOpsApi);
184
197
 
@@ -191,6 +204,7 @@ export default createBackendPlugin({
191
204
 
192
205
  // Setup queue-based health check worker
193
206
  await setupHealthCheckWorker({
207
+ notificationClient,
194
208
  db: database,
195
209
  registry: healthCheckRegistry,
196
210
  collectorRegistry,
@@ -255,6 +269,7 @@ export default createBackendPlugin({
255
269
  logger,
256
270
  onHook,
257
271
  emitHook,
272
+ rpcClient,
258
273
  healthCheckRegistry,
259
274
  collectorRegistry,
260
275
  }) => {
@@ -267,6 +282,19 @@ export default createBackendPlugin({
267
282
  logger,
268
283
  });
269
284
 
285
+ // Notification subscription specs. Per-resource group lifecycle
286
+ // is owned by notification-backend now — healthcheck just
287
+ // declares the specs it dispatches under.
288
+ const afterNotificationClient = rpcClient.forPlugin(NotificationApi);
289
+ await Promise.all([
290
+ afterNotificationClient.registerSubscriptionSpec(
291
+ specToRegistration(healthcheckSystemSubscription),
292
+ ),
293
+ afterNotificationClient.registerSubscriptionSpec(
294
+ specToRegistration(healthcheckGroupSubscription),
295
+ ),
296
+ ]);
297
+
270
298
  // Register GitOps documentation now that registries are populated
271
299
  registerHealthcheckGitOpsDocumentation({
272
300
  kindRegistry,
@@ -189,6 +189,9 @@ describe("Queue-Based Health Check Executor", () => {
189
189
  catalogClient: mockCatalogClient as unknown as Parameters<
190
190
  typeof setupHealthCheckWorker
191
191
  >[0]["catalogClient"],
192
+ notificationClient: { notifyForSubscription: () => Promise.resolve({ notifiedCount: 0 }) } as unknown as Parameters<
193
+ typeof setupHealthCheckWorker
194
+ >[0]["notificationClient"],
192
195
  maintenanceClient: mockMaintenanceClient as unknown as Parameters<
193
196
  typeof setupHealthCheckWorker
194
197
  >[0]["maintenanceClient"],
@@ -383,6 +386,9 @@ describe("Queue-Based Health Check Executor", () => {
383
386
  catalogClient: mockCatalogClient as unknown as Parameters<
384
387
  typeof setupHealthCheckWorker
385
388
  >[0]["catalogClient"],
389
+ notificationClient: { notifyForSubscription: () => Promise.resolve({ notifiedCount: 0 }) } as unknown as Parameters<
390
+ typeof setupHealthCheckWorker
391
+ >[0]["notificationClient"],
386
392
  maintenanceClient: mockMaintenanceClient as unknown as Parameters<
387
393
  typeof setupHealthCheckWorker
388
394
  >[0]["maintenanceClient"],
@@ -24,9 +24,16 @@ import {
24
24
  type HealthCheckStatus,
25
25
  stripEphemeralFields,
26
26
  } from "@checkstack/healthcheck-common";
27
- import { CatalogApi, catalogRoutes } from "@checkstack/catalog-common";
27
+ import {
28
+ CatalogApi,
29
+ catalogRoutes,
30
+ createSystemSubject,
31
+ } from "@checkstack/catalog-common";
32
+ import { systemHealthCollapseKey } from "@checkstack/healthcheck-common";
28
33
  import { MaintenanceApi } from "@checkstack/maintenance-common";
29
34
  import { IncidentApi } from "@checkstack/incident-common";
35
+ import { NotificationApi } from "@checkstack/notification-common";
36
+ import { healthcheckSystemSubscription } from "@checkstack/healthcheck-common";
30
37
  import { resolveRoute, type InferClient, extractErrorMessage} from "@checkstack/common";
31
38
  import { HealthCheckService } from "./service";
32
39
  import { healthCheckHooks } from "./hooks";
@@ -37,6 +44,7 @@ type Db = SafeDatabase<typeof schema>;
37
44
  type CatalogClient = InferClient<typeof CatalogApi>;
38
45
  type MaintenanceClient = InferClient<typeof MaintenanceApi>;
39
46
  type IncidentClient = InferClient<typeof IncidentApi>;
47
+ type NotificationClient = InferClient<typeof NotificationApi>;
40
48
 
41
49
  /**
42
50
  * Emit the checkCompleted hook if available.
@@ -138,6 +146,7 @@ async function notifyStateChange(props: {
138
146
  previousStatus: HealthCheckStatus;
139
147
  newStatus: HealthCheckStatus;
140
148
  catalogClient: CatalogClient;
149
+ notificationClient: NotificationClient;
141
150
  maintenanceClient: MaintenanceClient;
142
151
  incidentClient: IncidentClient;
143
152
  logger: Logger;
@@ -148,6 +157,7 @@ async function notifyStateChange(props: {
148
157
  previousStatus,
149
158
  newStatus,
150
159
  catalogClient,
160
+ notificationClient,
151
161
  maintenanceClient,
152
162
  incidentClient,
153
163
  logger,
@@ -225,14 +235,25 @@ async function notifyStateChange(props: {
225
235
  systemId,
226
236
  });
227
237
 
238
+ void catalogClient; // parents are resolved server-side via stored target edges
239
+
228
240
  try {
229
- await catalogClient.notifySystemSubscribers({
230
- systemId,
241
+ await notificationClient.notifyForSubscription({
242
+ specId: healthcheckSystemSubscription.specId,
243
+ resourceKeys: [systemId],
231
244
  title,
232
245
  body,
233
246
  importance,
234
247
  action: { label: "View System", url: systemDetailPath },
235
- includeGroupSubscribers: true,
248
+ collapseKey: systemHealthCollapseKey(systemId),
249
+ subjects: [
250
+ createSystemSubject({
251
+ id: systemId,
252
+ name: systemName,
253
+ url: systemDetailPath,
254
+ status: newStatus,
255
+ }),
256
+ ],
236
257
  });
237
258
  logger.debug(
238
259
  `Notified subscribers: ${previousStatus} → ${newStatus} for system ${systemId}`,
@@ -257,6 +278,7 @@ async function executeHealthCheckJob(props: {
257
278
  logger: Logger;
258
279
  signalService: SignalService;
259
280
  catalogClient: CatalogClient;
281
+ notificationClient: NotificationClient;
260
282
  maintenanceClient: MaintenanceClient;
261
283
  incidentClient: IncidentClient;
262
284
  getEmitHook: () => EmitHookFn | undefined;
@@ -270,6 +292,7 @@ async function executeHealthCheckJob(props: {
270
292
  logger,
271
293
  signalService,
272
294
  catalogClient,
295
+ notificationClient,
273
296
  maintenanceClient,
274
297
  incidentClient,
275
298
  getEmitHook,
@@ -575,6 +598,7 @@ async function executeHealthCheckJob(props: {
575
598
  const newState = await service.getSystemHealthStatus(systemId);
576
599
  if (newState.status !== previousStatus) {
577
600
  await notifyStateChange({
601
+ notificationClient,
578
602
  systemId,
579
603
  systemName,
580
604
  previousStatus,
@@ -669,6 +693,7 @@ async function executeHealthCheckJob(props: {
669
693
  const newState = await service.getSystemHealthStatus(systemId);
670
694
  if (newState.status !== previousStatus) {
671
695
  await notifyStateChange({
696
+ notificationClient,
672
697
  systemId,
673
698
  systemName,
674
699
  previousStatus,
@@ -800,6 +825,7 @@ async function executeHealthCheckJob(props: {
800
825
  const newState = await service.getSystemHealthStatus(systemId);
801
826
  if (newState.status !== previousStatus) {
802
827
  await notifyStateChange({
828
+ notificationClient,
803
829
  systemId,
804
830
  systemName,
805
831
  previousStatus,
@@ -868,6 +894,7 @@ export async function setupHealthCheckWorker(props: {
868
894
  queueManager: QueueManager;
869
895
  signalService: SignalService;
870
896
  catalogClient: CatalogClient;
897
+ notificationClient: NotificationClient;
871
898
  maintenanceClient: MaintenanceClient;
872
899
  incidentClient: IncidentClient;
873
900
  getEmitHook: () => EmitHookFn | undefined;
@@ -881,6 +908,7 @@ export async function setupHealthCheckWorker(props: {
881
908
  queueManager,
882
909
  signalService,
883
910
  catalogClient,
911
+ notificationClient,
884
912
  maintenanceClient,
885
913
  incidentClient,
886
914
  getEmitHook,
@@ -901,6 +929,7 @@ export async function setupHealthCheckWorker(props: {
901
929
  logger,
902
930
  signalService,
903
931
  catalogClient,
932
+ notificationClient,
904
933
  maintenanceClient,
905
934
  incidentClient,
906
935
  getEmitHook,