@checkstack/dependency-backend 0.3.3 → 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 +134 -0
- package/package.json +13 -12
- package/src/index.ts +6 -0
- package/src/notifications.ts +43 -104
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,139 @@
|
|
|
1
1
|
# @checkstack/dependency-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
|
+
- @checkstack/notification-common@1.0.0
|
|
128
|
+
- @checkstack/catalog-backend@1.0.0
|
|
129
|
+
- @checkstack/catalog-common@2.0.0
|
|
130
|
+
- @checkstack/incident-common@1.0.0
|
|
131
|
+
- @checkstack/maintenance-common@1.0.0
|
|
132
|
+
- @checkstack/healthcheck-common@1.0.0
|
|
133
|
+
- @checkstack/healthcheck-backend@1.0.0
|
|
134
|
+
- @checkstack/dependency-common@1.0.0
|
|
135
|
+
- @checkstack/backend-api@0.14.0
|
|
136
|
+
|
|
3
137
|
## 0.3.3
|
|
4
138
|
|
|
5
139
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/dependency-backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"checkstack": {
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"lint:code": "eslint . --max-warnings 0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@checkstack/backend-api": "0.13.
|
|
17
|
-
"@checkstack/dependency-common": "0.
|
|
18
|
-
"@checkstack/catalog-common": "1.5.
|
|
19
|
-
"@checkstack/catalog-backend": "0.7.
|
|
20
|
-
"@checkstack/healthcheck-common": "0.
|
|
21
|
-
"@checkstack/healthcheck-backend": "0.18.
|
|
22
|
-
"@checkstack/maintenance-common": "0.
|
|
23
|
-
"@checkstack/incident-common": "0.
|
|
24
|
-
"@checkstack/notification-common": "0.
|
|
25
|
-
"@checkstack/signal-common": "0.
|
|
16
|
+
"@checkstack/backend-api": "0.13.1",
|
|
17
|
+
"@checkstack/dependency-common": "0.3.0",
|
|
18
|
+
"@checkstack/catalog-common": "1.5.3",
|
|
19
|
+
"@checkstack/catalog-backend": "0.7.1",
|
|
20
|
+
"@checkstack/healthcheck-common": "0.13.0",
|
|
21
|
+
"@checkstack/healthcheck-backend": "0.18.1",
|
|
22
|
+
"@checkstack/maintenance-common": "0.5.0",
|
|
23
|
+
"@checkstack/incident-common": "0.5.0",
|
|
24
|
+
"@checkstack/notification-common": "0.3.0",
|
|
25
|
+
"@checkstack/signal-common": "0.2.0",
|
|
26
26
|
"@checkstack/common": "0.7.0",
|
|
27
27
|
"drizzle-orm": "^0.45.0",
|
|
28
28
|
"zod": "^4.2.1",
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@checkstack/drizzle-helper": "0.0.4",
|
|
33
33
|
"@checkstack/scripts": "0.1.2",
|
|
34
|
-
"@checkstack/test-utils-backend": "0.1.
|
|
34
|
+
"@checkstack/test-utils-backend": "0.1.21",
|
|
35
35
|
"@checkstack/tsconfig": "0.0.5",
|
|
36
36
|
"@types/bun": "^1.0.0",
|
|
37
|
+
"drizzle-kit": "^0.31.10",
|
|
37
38
|
"typescript": "^5.0.0"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
dependencyAccessRules,
|
|
5
5
|
pluginMetadata,
|
|
6
6
|
dependencyContract,
|
|
7
|
+
dependencySystemSubscription,
|
|
8
|
+
dependencyGroupSubscription,
|
|
7
9
|
} from "@checkstack/dependency-common";
|
|
8
10
|
import { createBackendPlugin, coreServices } from "@checkstack/backend-api";
|
|
9
11
|
import { DependencyService } from "./services/dependency-service";
|
|
@@ -27,6 +29,10 @@ export default createBackendPlugin({
|
|
|
27
29
|
metadata: pluginMetadata,
|
|
28
30
|
register(env) {
|
|
29
31
|
env.registerAccessRules(dependencyAccessRules);
|
|
32
|
+
env.registerSubscriptionSpecs([
|
|
33
|
+
dependencySystemSubscription,
|
|
34
|
+
dependencyGroupSubscription,
|
|
35
|
+
]);
|
|
30
36
|
|
|
31
37
|
env.registerInit({
|
|
32
38
|
schema,
|
package/src/notifications.ts
CHANGED
|
@@ -2,10 +2,14 @@ import type { Logger } from "@checkstack/backend-api";
|
|
|
2
2
|
import type { InferClient } from "@checkstack/common";
|
|
3
3
|
import { resolveRoute } from "@checkstack/common";
|
|
4
4
|
import type { CatalogApi } from "@checkstack/catalog-common";
|
|
5
|
-
import { catalogRoutes } from "@checkstack/catalog-common";
|
|
5
|
+
import { catalogRoutes, createSystemSubject } from "@checkstack/catalog-common";
|
|
6
6
|
import type { MaintenanceApi } from "@checkstack/maintenance-common";
|
|
7
7
|
import type { IncidentApi } from "@checkstack/incident-common";
|
|
8
8
|
import type { NotificationApi } from "@checkstack/notification-common";
|
|
9
|
+
import {
|
|
10
|
+
dependencyUpstreamCollapseKey,
|
|
11
|
+
dependencySystemSubscription,
|
|
12
|
+
} from "@checkstack/dependency-common";
|
|
9
13
|
import type { DerivedState } from "@checkstack/dependency-common";
|
|
10
14
|
import { DEPENDENCY_WARNINGS_CHANGED } from "@checkstack/dependency-common";
|
|
11
15
|
import type { DependencyService } from "./services/dependency-service";
|
|
@@ -395,13 +399,13 @@ export async function evaluateAndNotifyDownstream({
|
|
|
395
399
|
}
|
|
396
400
|
|
|
397
401
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
402
|
+
* Dispatch one notification per impacted downstream system using the
|
|
403
|
+
* platform spec contract. Subscribers to each downstream system (and its
|
|
404
|
+
* parent catalog groups, resolved server-side via stored target edges)
|
|
405
|
+
* receive a notification describing the upstream impact. Multi-system
|
|
406
|
+
* dispatches collapse on the *upstream* changedSystemId so a recipient
|
|
407
|
+
* subscribed to several downstreams sees one card per upstream event,
|
|
408
|
+
* not one per downstream.
|
|
405
409
|
*/
|
|
406
410
|
async function sendBatchedNotifications({
|
|
407
411
|
systemsToNotify,
|
|
@@ -418,57 +422,9 @@ async function sendBatchedNotifications({
|
|
|
418
422
|
notificationClient: InferClient<typeof NotificationApi>;
|
|
419
423
|
logger: Logger;
|
|
420
424
|
}): Promise<void> {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
for (const system of systemsToNotify) {
|
|
424
|
-
const groupIds = [`catalog.system.${system.systemId}`];
|
|
425
|
-
|
|
426
|
-
try {
|
|
427
|
-
const { groupIds: catalogGroupIds } =
|
|
428
|
-
await catalogClient.getSystemGroupIds({
|
|
429
|
-
systemId: system.systemId,
|
|
430
|
-
});
|
|
431
|
-
groupIds.push(
|
|
432
|
-
...catalogGroupIds.map((gid) => `catalog.group.${gid}`),
|
|
433
|
-
);
|
|
434
|
-
} catch (error) {
|
|
435
|
-
logger.warn(
|
|
436
|
-
`Failed to resolve group IDs for system ${system.systemId}:`,
|
|
437
|
-
error,
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
systemToGroupIds.set(system.systemId, groupIds);
|
|
442
|
-
}
|
|
425
|
+
void catalogClient;
|
|
426
|
+
if (systemsToNotify.length === 0) return;
|
|
443
427
|
|
|
444
|
-
// Phase 2: Resolve subscribers per group → build user → systems reverse map
|
|
445
|
-
const userSystems = new Map<string, Set<string>>();
|
|
446
|
-
for (const system of systemsToNotify) {
|
|
447
|
-
const groupIds = systemToGroupIds.get(system.systemId) ?? [];
|
|
448
|
-
for (const groupId of groupIds) {
|
|
449
|
-
try {
|
|
450
|
-
const { userIds } =
|
|
451
|
-
await notificationClient.getGroupSubscribers({ groupId });
|
|
452
|
-
for (const userId of userIds) {
|
|
453
|
-
if (!userSystems.has(userId)) {
|
|
454
|
-
userSystems.set(userId, new Set());
|
|
455
|
-
}
|
|
456
|
-
userSystems.get(userId)!.add(system.systemId);
|
|
457
|
-
}
|
|
458
|
-
} catch (error) {
|
|
459
|
-
logger.warn(
|
|
460
|
-
`Failed to resolve subscribers for group ${groupId}:`,
|
|
461
|
-
error,
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (userSystems.size === 0) {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// Phase 3: Send one personalized notification per user
|
|
472
428
|
const upstreamName =
|
|
473
429
|
statuses.get(changedSystemId)?.systemName ?? changedSystemId;
|
|
474
430
|
const upstreamSystemDetailPath = resolveRoute(
|
|
@@ -476,65 +432,48 @@ async function sendBatchedNotifications({
|
|
|
476
432
|
{ systemId: changedSystemId },
|
|
477
433
|
);
|
|
478
434
|
|
|
479
|
-
for (const
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
// Single system — use detailed title/body
|
|
493
|
-
const entry = relevantSystems[0];
|
|
494
|
-
title = buildNotificationTitle({
|
|
495
|
-
derivedState: entry.derivedState,
|
|
496
|
-
isRecovery: entry.isRecovery,
|
|
497
|
-
systemName: entry.systemName,
|
|
498
|
-
});
|
|
499
|
-
body = buildNotificationBody({
|
|
500
|
-
upstreamNames: entry.upstreamNames,
|
|
501
|
-
derivedState: entry.derivedState,
|
|
502
|
-
isRecovery: entry.isRecovery,
|
|
503
|
-
systemName: entry.systemName,
|
|
504
|
-
});
|
|
505
|
-
} else if (allRecovery) {
|
|
506
|
-
title = `Dependency impact resolved: ${upstreamName}`;
|
|
507
|
-
body = `All upstream dependencies of **${systemNames.join("**, **")}** have recovered.`;
|
|
508
|
-
} else {
|
|
509
|
-
title = `Upstream dependency issue: ${upstreamName} — ${relevantSystems.length} systems affected`;
|
|
510
|
-
const systemLines = relevantSystems
|
|
511
|
-
.map((entry) => formatSystemImpactLine(entry))
|
|
512
|
-
.join("\n");
|
|
513
|
-
body = `An upstream dependency (**${upstreamName}**) is affecting:\n\n${systemLines}`;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
const importance = allRecovery
|
|
435
|
+
for (const entry of systemsToNotify) {
|
|
436
|
+
const title = buildNotificationTitle({
|
|
437
|
+
derivedState: entry.derivedState,
|
|
438
|
+
isRecovery: entry.isRecovery,
|
|
439
|
+
systemName: entry.systemName,
|
|
440
|
+
});
|
|
441
|
+
const body = buildNotificationBody({
|
|
442
|
+
upstreamNames: entry.upstreamNames,
|
|
443
|
+
derivedState: entry.derivedState,
|
|
444
|
+
isRecovery: entry.isRecovery,
|
|
445
|
+
systemName: entry.systemName,
|
|
446
|
+
});
|
|
447
|
+
const importance = entry.isRecovery
|
|
517
448
|
? ("info" as const)
|
|
518
|
-
: resolveWorstImportance(
|
|
449
|
+
: resolveWorstImportance([entry]);
|
|
519
450
|
|
|
520
451
|
try {
|
|
521
|
-
await notificationClient.
|
|
522
|
-
|
|
452
|
+
await notificationClient.notifyForSubscription({
|
|
453
|
+
specId: dependencySystemSubscription.specId,
|
|
454
|
+
resourceKeys: [entry.systemId],
|
|
523
455
|
title,
|
|
524
456
|
body,
|
|
525
457
|
importance,
|
|
526
458
|
action: { label: "View Root Cause", url: upstreamSystemDetailPath },
|
|
459
|
+
collapseKey: dependencyUpstreamCollapseKey(changedSystemId),
|
|
460
|
+
subjects: [
|
|
461
|
+
createSystemSubject({
|
|
462
|
+
id: entry.systemId,
|
|
463
|
+
name: entry.systemName,
|
|
464
|
+
url: resolveRoute(catalogRoutes.routes.systemDetail, {
|
|
465
|
+
systemId: entry.systemId,
|
|
466
|
+
}),
|
|
467
|
+
}),
|
|
468
|
+
],
|
|
527
469
|
});
|
|
528
|
-
logger.debug(
|
|
529
|
-
`Dependency notification sent to user ${userId}: ${relevantSystems.length} system(s)`,
|
|
530
|
-
);
|
|
531
470
|
} catch (error) {
|
|
532
|
-
// Notifications are best-effort
|
|
533
471
|
logger.warn(
|
|
534
|
-
`Failed to
|
|
472
|
+
`Failed to dispatch dependency notification for ${entry.systemId}:`,
|
|
535
473
|
error,
|
|
536
474
|
);
|
|
537
475
|
}
|
|
538
476
|
}
|
|
477
|
+
void upstreamName;
|
|
539
478
|
}
|
|
540
479
|
|