@checkstack/catalog-common 1.5.3 → 2.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,185 @@
1
1
  # @checkstack/catalog-common
2
2
 
3
+ ## 2.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
+ ### Minor 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
+ - 32d52c6: feat: unified notification-subscription manager dialog driven by spec registry
123
+
124
+ Replaces the bell-toggle UX (which only managed a single legacy
125
+ catalog group) with a modal that lists every notification type
126
+ registered against a target — system or group — and exposes both
127
+ per-type toggles and a bulk "Subscribe to all / Unsubscribe from all"
128
+ action. Both surfaces (system detail page header bell, dashboard group
129
+ header bell) now open the same `NotificationSubscriptionsManager`
130
+ component.
131
+
132
+ **Key change vs. the prior slot-based approach**: rows are now driven
133
+ by `notificationClient.listSubscriptionSpecs` — the backend's spec
134
+ registry is the single source of truth. Previously, a row only
135
+ appeared if a frontend plugin had remembered to register a
136
+ `createNotificationSubscriptionExtension`; this caused silent drift
137
+ (healthcheck and dependency registered backend specs without frontend
138
+ extensions, so the dialog counted them but never rendered rows). Now,
139
+ every spec the platform knows about renders a row using the spec's
140
+ `display` metadata (title, description, iconName resolved via
141
+ `DynamicIcon`).
142
+
143
+ **Sub-controls registry** (`@checkstack/notification-frontend`):
144
+ plugins that want sub-granularity (anomaly's per-field mute list,
145
+ future severity / channel filters) call
146
+ `registerSubscriptionSubControls(spec, Component)` at module load —
147
+ the manager looks the component up by `specId` when expanding a row.
148
+
149
+ **Removed (no compat)**:
150
+
151
+ - `createNotificationSubscriptionExtension` (replaced by the
152
+ spec-driven manager + the SubControls registry)
153
+ - `target.slot` field on `NotificationTarget` and the
154
+ `NotificationTargetInput.slot` parameter on
155
+ `defineNotificationTarget`
156
+ - `SystemNotificationSubscriptionsSlot` and
157
+ `GroupNotificationSubscriptionsSlot` from `@checkstack/catalog-common`
158
+ - `SystemNotificationsCard` from the system detail page's main column
159
+ - `SubscribeButton` wiring on dashboard group cards and the system
160
+ detail page header
161
+
162
+ **Migrated frontends**: anomaly (now registers `AnomalyFieldMuteList`
163
+ via the SubControls registry), incident, maintenance — all dropped
164
+ their `createNotificationSubscriptionExtension` calls. healthcheck and
165
+ dependency now show up automatically via the spec registry — no
166
+ frontend changes needed for them to render.
167
+
168
+ The trigger button reflects aggregate state — filled bell when at
169
+ least one spec is subscribed for the resource, ghost bell when none.
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies [32d52c6]
174
+ - Updated dependencies [32d52c6]
175
+ - Updated dependencies [32d52c6]
176
+ - Updated dependencies [32d52c6]
177
+ - Updated dependencies [32d52c6]
178
+ - Updated dependencies [32d52c6]
179
+ - @checkstack/notification-common@1.0.0
180
+ - @checkstack/frontend-api@0.4.1
181
+ - @checkstack/auth-common@0.6.4
182
+
3
183
  ## 1.5.3
4
184
 
5
185
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/catalog-common",
3
- "version": "1.5.3",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -10,7 +10,8 @@
10
10
  "dependencies": {
11
11
  "@checkstack/common": "0.7.0",
12
12
  "@checkstack/auth-common": "0.6.3",
13
- "@checkstack/frontend-api": "0.3.11",
13
+ "@checkstack/frontend-api": "0.4.0",
14
+ "@checkstack/notification-common": "0.3.0",
14
15
  "@orpc/contract": "^1.13.14",
15
16
  "zod": "^4.2.1"
16
17
  },
package/src/index.ts CHANGED
@@ -3,4 +3,5 @@ export * from "./rpc-contract";
3
3
  export * from "./types";
4
4
  export * from "./slots";
5
5
  export * from "./plugin-metadata";
6
+ export * from "./notifications";
6
7
  export { catalogRoutes } from "./routes";
@@ -0,0 +1,71 @@
1
+ import {
2
+ createSubjectKindBuilder,
3
+ defineNotificationTarget,
4
+ } from "@checkstack/notification-common";
5
+ import { pluginMetadata } from "./plugin-metadata";
6
+
7
+ /**
8
+ * Builders for the catalog plugin's notification subject kinds. Use these
9
+ * instead of constructing `NotificationSubject` literals so the kind
10
+ * namespace stays in sync with the plugin id.
11
+ */
12
+ export const createSystemSubject = createSubjectKindBuilder(
13
+ pluginMetadata,
14
+ "system",
15
+ );
16
+
17
+ export const createGroupSubject = createSubjectKindBuilder(
18
+ pluginMetadata,
19
+ "group",
20
+ );
21
+
22
+ // ─── Notification targets ────────────────────────────────────────────────────
23
+ // Catalog owns the platform's "system" and "group" target types. Emitting
24
+ // plugins (anomaly, incident, maintenance, healthcheck, ...) reference
25
+ // these objects directly when defining their subscription specs — no
26
+ // strings, no per-plugin lifecycle code.
27
+
28
+ export interface CatalogSystemResource {
29
+ systemId: string;
30
+ systemName: string;
31
+ }
32
+
33
+ export interface CatalogGroupResource {
34
+ groupId: string;
35
+ groupName: string;
36
+ }
37
+
38
+ /**
39
+ * The "system" target type. Resources are the entries of catalog's
40
+ * `systems` table; the catalog backend pushes them to notification-
41
+ * backend whenever a system is created, renamed, or deleted, and
42
+ * declares each system's parent catalog groups.
43
+ *
44
+ * `legacy.legacyGroupIdTemplate` covers users who were already
45
+ * subscribed to the pre-pattern `catalog.system.<id>` group — the
46
+ * notification backend seeds new spec groups from those subscribers
47
+ * exactly once per (spec × resource) pair.
48
+ */
49
+ export const catalogSystemTarget = defineNotificationTarget<CatalogSystemResource>({
50
+ pluginMetadata,
51
+ localId: "system",
52
+ resourceKind: "system",
53
+ keyOf: ({ systemId }) => systemId,
54
+ labelOf: ({ systemName }) => systemName,
55
+ parents: { targetTypeId: `${pluginMetadata.pluginId}.group` },
56
+ legacy: { legacyGroupIdTemplate: "catalog.system.{resourceKey}" },
57
+ });
58
+
59
+ /**
60
+ * The "group" target type. Catalog groups don't currently have parent
61
+ * resources; emitting plugins targeting groups deliver only to direct
62
+ * subscribers of the group.
63
+ */
64
+ export const catalogGroupTarget = defineNotificationTarget<CatalogGroupResource>({
65
+ pluginMetadata,
66
+ localId: "group",
67
+ resourceKind: "group",
68
+ keyOf: ({ groupId }) => groupId,
69
+ labelOf: ({ groupName }) => groupName,
70
+ legacy: { legacyGroupIdTemplate: "catalog.group.{resourceKey}" },
71
+ });
@@ -83,6 +83,21 @@ export const catalogContract = {
83
83
  access: [catalogAccess.group.read],
84
84
  }).output(z.array(GroupSchema)),
85
85
 
86
+ /**
87
+ * Returns the catalog groups a system belongs to. Used by host plugins
88
+ * (catalog) and emitting plugins (e.g. anomaly) to walk parent
89
+ * subscriptions and surface inheritance hints. Server-side join — no
90
+ * client-side filtering of `getGroups()` needed.
91
+ */
92
+ getSystemGroups: proc({
93
+ operationType: "query",
94
+ userType: "public",
95
+ access: [catalogAccess.system.read],
96
+ instanceAccess: { idParam: "systemId" },
97
+ })
98
+ .input(z.object({ systemId: z.string() }))
99
+ .output(z.array(GroupSchema)),
100
+
86
101
  // ==========================================================================
87
102
  // SYSTEM MANAGEMENT (userType: "authenticated" with manage access)
88
103
  // ==========================================================================
@@ -229,44 +244,6 @@ export const catalogContract = {
229
244
  // SERVICE INTERFACE (userType: "service" - backend-to-backend only)
230
245
  // ==========================================================================
231
246
 
232
- /**
233
- * Notify all users subscribed to a system (and optionally its groups).
234
- * This is used by other plugins (e.g., maintenance) to send notifications
235
- * to system subscribers without needing direct access to the notification service.
236
- *
237
- * Deduplication: If includeGroupSubscribers is true, subscribers are
238
- * deduplicated so users subscribed to both the system AND its groups
239
- * receive only one notification.
240
- */
241
- notifySystemSubscribers: proc({
242
- operationType: "mutation",
243
- userType: "service",
244
- access: [], // Service-to-service, no access rules needed
245
- })
246
- .input(
247
- z.object({
248
- systemId: z
249
- .string()
250
- .describe("The system ID to notify subscribers for"),
251
- title: z.string().describe("Notification title"),
252
- body: z.string().describe("Notification body (supports markdown)"),
253
- importance: z.enum(["info", "warning", "critical"]).optional(),
254
- action: z
255
- .object({
256
- label: z.string(),
257
- url: z.string(),
258
- })
259
- .optional(),
260
- includeGroupSubscribers: z
261
- .boolean()
262
- .optional()
263
- .describe(
264
- "If true, also notify subscribers of groups that contain this system",
265
- ),
266
- }),
267
- )
268
- .output(z.object({ notifiedCount: z.number() })),
269
-
270
247
  /**
271
248
  * Get the catalog group IDs that contain a specific system.
272
249
  * Returns raw group IDs (not namespaced with notification prefix).