@checkstack/notification-backend 0.2.0 → 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,182 @@
1
1
  # @checkstack/notification-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
+ ### Minor Changes
113
+
114
+ - 32d52c6: feat(anomaly): per-system and per-field notification mute
115
+
116
+ Anomaly notifications now flow through their own subscription group
117
+ (`anomaly.system.<systemId>`) instead of the shared catalog system group, so
118
+ users can opt out of anomaly noise without losing incident or healthcheck
119
+ alerts for the same system. On first deploy, existing subscribers of each
120
+ `catalog.system.<id>` group are seeded onto the new anomaly group so no one
121
+ silently stops getting alerts.
122
+
123
+ A new mute table (`anomaly_notification_mutes`) backs two granularities:
124
+
125
+ - **Per-field**: silence a single noisy metric on one system.
126
+ - **Per-system**: silence every anomaly for one system in one click.
127
+
128
+ The system anomaly widget now exposes a bell icon on each anomaly row plus a
129
+ `Mute all` toggle in the card header. Mutes are user-scoped and persist
130
+ across sessions.
131
+
132
+ Catalog gains a `systemCreated` hook so anomaly (and any future plugin) can
133
+ provision per-system state on creation rather than waiting for a restart.
134
+ The notification service gains a `bulkSubscribe` service-RPC used by the
135
+ one-time migration described above.
136
+
137
+ - 32d52c6: Bulk notifications affecting multiple systems and collapse lifecycle events into a single card.
138
+
139
+ 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.
140
+
141
+ 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.
142
+
143
+ 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.).
144
+
145
+ ### Patch Changes
146
+
147
+ - 32d52c6: Fix and improve password reset flow + email branding:
148
+
149
+ - **Fix**: password reset emails were failing with "Malformed password reset URL: missing token parameter". Better-auth puts the reset token in the URL path (`/reset-password/{token}`), not as a `?token=` query param, so the previous URL-parsing logic always failed. Now uses the `token` argument better-auth passes to `sendResetPassword` directly.
150
+ - **UX**: the reset password page now validates the token on load via a new anonymous `validateResetToken` endpoint, so users see "Invalid Link" / "Link Expired" before typing a password rather than after submitting. Tokens are 24-char nanoid-style values (~143 bits of entropy), so exposing validity does not enable enumeration.
151
+ - **Fix**: transactional notifications were hardcoded to `importance: "critical"`, causing password reset emails to display a misleading "CRITICAL" badge. The `sendTransactional` contract now accepts an optional `importance` field that defaults to `"info"`.
152
+ - **Branding**: redesigned the email layout (`wrapInEmailLayout`) with a Checkstack-style engineering aesthetic — dark header with grid pattern, monospace importance badge, hardened CTA button (Outlook VML fallback + explicit text color), and force-light color scheme to prevent client auto-inversion from breaking text legibility.
153
+
154
+ - Updated dependencies [32d52c6]
155
+ - Updated dependencies [32d52c6]
156
+ - Updated dependencies [32d52c6]
157
+ - Updated dependencies [32d52c6]
158
+ - Updated dependencies [32d52c6]
159
+ - @checkstack/notification-common@1.0.0
160
+ - @checkstack/backend-api@0.14.0
161
+ - @checkstack/auth-backend@0.4.22
162
+ - @checkstack/auth-common@0.6.4
163
+ - @checkstack/cache-api@0.2.2
164
+ - @checkstack/queue-api@0.2.16
165
+ - @checkstack/cache-utils@0.2.2
166
+
167
+ ## 0.2.1
168
+
169
+ ### Patch Changes
170
+
171
+ - Updated dependencies [208ad71]
172
+ - @checkstack/signal-common@0.2.0
173
+ - @checkstack/notification-common@0.3.0
174
+ - @checkstack/backend-api@0.13.1
175
+ - @checkstack/auth-backend@0.4.21
176
+ - @checkstack/cache-api@0.2.1
177
+ - @checkstack/queue-api@0.2.15
178
+ - @checkstack/cache-utils@0.2.1
179
+
3
180
  ## 0.2.0
4
181
 
5
182
  ### Minor Changes
@@ -0,0 +1,3 @@
1
+ ALTER TABLE "notifications" ADD COLUMN "subjects" jsonb;--> statement-breakpoint
2
+ CREATE INDEX IF NOT EXISTS "notifications_user_collapse_idx" ON "notifications" USING btree ("user_id","group_id");--> statement-breakpoint
3
+ CREATE INDEX IF NOT EXISTS "notifications_user_created_idx" ON "notifications" USING btree ("user_id","created_at");
@@ -0,0 +1,46 @@
1
+ CREATE TABLE "notification_resource_parents" (
2
+ "child_target_type_id" text NOT NULL,
3
+ "child_resource_key" text NOT NULL,
4
+ "parent_target_type_id" text NOT NULL,
5
+ "parent_resource_key" text NOT NULL,
6
+ CONSTRAINT "notification_resource_parents_child_target_type_id_child_resource_key_parent_target_type_id_parent_resource_key_pk" PRIMARY KEY("child_target_type_id","child_resource_key","parent_target_type_id","parent_resource_key")
7
+ );
8
+ --> statement-breakpoint
9
+ CREATE TABLE "notification_resources" (
10
+ "target_type_id" text NOT NULL,
11
+ "resource_key" text NOT NULL,
12
+ "display_label" text NOT NULL,
13
+ "upserted_at" timestamp DEFAULT now() NOT NULL,
14
+ CONSTRAINT "notification_resources_target_type_id_resource_key_pk" PRIMARY KEY("target_type_id","resource_key")
15
+ );
16
+ --> statement-breakpoint
17
+ CREATE TABLE "notification_targets" (
18
+ "target_type_id" text PRIMARY KEY NOT NULL,
19
+ "owner_plugin" text NOT NULL,
20
+ "resource_kind" text NOT NULL,
21
+ "parent_target_type_id" text,
22
+ "legacy_group_id_template" text,
23
+ "registered_at" timestamp DEFAULT now() NOT NULL
24
+ );
25
+ --> statement-breakpoint
26
+ CREATE TABLE "subscription_migrations" (
27
+ "spec_id" text NOT NULL,
28
+ "resource_key" text NOT NULL,
29
+ "migrated_at" timestamp DEFAULT now() NOT NULL,
30
+ CONSTRAINT "subscription_migrations_spec_id_resource_key_pk" PRIMARY KEY("spec_id","resource_key")
31
+ );
32
+ --> statement-breakpoint
33
+ CREATE TABLE "subscription_specs" (
34
+ "spec_id" text PRIMARY KEY NOT NULL,
35
+ "owner_plugin" text NOT NULL,
36
+ "local_id" text NOT NULL,
37
+ "target_type_id" text NOT NULL,
38
+ "display_title" text NOT NULL,
39
+ "display_description" text NOT NULL,
40
+ "display_icon_name" text,
41
+ "registered_at" timestamp DEFAULT now() NOT NULL
42
+ );
43
+ --> statement-breakpoint
44
+ ALTER TABLE "notification_resources" ADD CONSTRAINT "notification_resources_target_type_id_notification_targets_target_type_id_fk" FOREIGN KEY ("target_type_id") REFERENCES "notification_targets"("target_type_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
45
+ ALTER TABLE "subscription_specs" ADD CONSTRAINT "subscription_specs_target_type_id_notification_targets_target_type_id_fk" FOREIGN KEY ("target_type_id") REFERENCES "notification_targets"("target_type_id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
46
+ CREATE INDEX "notification_resource_parents_child_idx" ON "notification_resource_parents" USING btree ("child_target_type_id","child_resource_key");
@@ -0,0 +1,237 @@
1
+ {
2
+ "id": "487b48a4-723f-478c-ab7b-4512c095a7c4",
3
+ "prevId": "5899e448-f29a-46e2-b75d-51c7832c432b",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.notification_groups": {
8
+ "name": "notification_groups",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "name": {
18
+ "name": "name",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "description": {
24
+ "name": "description",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": true
28
+ },
29
+ "owner_plugin": {
30
+ "name": "owner_plugin",
31
+ "type": "text",
32
+ "primaryKey": false,
33
+ "notNull": true
34
+ },
35
+ "created_at": {
36
+ "name": "created_at",
37
+ "type": "timestamp",
38
+ "primaryKey": false,
39
+ "notNull": true,
40
+ "default": "now()"
41
+ }
42
+ },
43
+ "indexes": {},
44
+ "foreignKeys": {},
45
+ "compositePrimaryKeys": {},
46
+ "uniqueConstraints": {},
47
+ "policies": {},
48
+ "checkConstraints": {},
49
+ "isRLSEnabled": false
50
+ },
51
+ "public.notification_subscriptions": {
52
+ "name": "notification_subscriptions",
53
+ "schema": "",
54
+ "columns": {
55
+ "user_id": {
56
+ "name": "user_id",
57
+ "type": "text",
58
+ "primaryKey": false,
59
+ "notNull": true
60
+ },
61
+ "group_id": {
62
+ "name": "group_id",
63
+ "type": "text",
64
+ "primaryKey": false,
65
+ "notNull": true
66
+ },
67
+ "subscribed_at": {
68
+ "name": "subscribed_at",
69
+ "type": "timestamp",
70
+ "primaryKey": false,
71
+ "notNull": true,
72
+ "default": "now()"
73
+ }
74
+ },
75
+ "indexes": {},
76
+ "foreignKeys": {
77
+ "notification_subscriptions_group_id_notification_groups_id_fk": {
78
+ "name": "notification_subscriptions_group_id_notification_groups_id_fk",
79
+ "tableFrom": "notification_subscriptions",
80
+ "tableTo": "notification_groups",
81
+ "columnsFrom": [
82
+ "group_id"
83
+ ],
84
+ "columnsTo": [
85
+ "id"
86
+ ],
87
+ "onDelete": "cascade",
88
+ "onUpdate": "no action"
89
+ }
90
+ },
91
+ "compositePrimaryKeys": {
92
+ "notification_subscriptions_user_id_group_id_pk": {
93
+ "name": "notification_subscriptions_user_id_group_id_pk",
94
+ "columns": [
95
+ "user_id",
96
+ "group_id"
97
+ ]
98
+ }
99
+ },
100
+ "uniqueConstraints": {},
101
+ "policies": {},
102
+ "checkConstraints": {},
103
+ "isRLSEnabled": false
104
+ },
105
+ "public.notifications": {
106
+ "name": "notifications",
107
+ "schema": "",
108
+ "columns": {
109
+ "id": {
110
+ "name": "id",
111
+ "type": "uuid",
112
+ "primaryKey": true,
113
+ "notNull": true,
114
+ "default": "gen_random_uuid()"
115
+ },
116
+ "user_id": {
117
+ "name": "user_id",
118
+ "type": "text",
119
+ "primaryKey": false,
120
+ "notNull": true
121
+ },
122
+ "title": {
123
+ "name": "title",
124
+ "type": "text",
125
+ "primaryKey": false,
126
+ "notNull": true
127
+ },
128
+ "body": {
129
+ "name": "body",
130
+ "type": "text",
131
+ "primaryKey": false,
132
+ "notNull": true
133
+ },
134
+ "action": {
135
+ "name": "action",
136
+ "type": "jsonb",
137
+ "primaryKey": false,
138
+ "notNull": false
139
+ },
140
+ "importance": {
141
+ "name": "importance",
142
+ "type": "text",
143
+ "primaryKey": false,
144
+ "notNull": true,
145
+ "default": "'info'"
146
+ },
147
+ "is_read": {
148
+ "name": "is_read",
149
+ "type": "boolean",
150
+ "primaryKey": false,
151
+ "notNull": true,
152
+ "default": false
153
+ },
154
+ "group_id": {
155
+ "name": "group_id",
156
+ "type": "text",
157
+ "primaryKey": false,
158
+ "notNull": false
159
+ },
160
+ "subjects": {
161
+ "name": "subjects",
162
+ "type": "jsonb",
163
+ "primaryKey": false,
164
+ "notNull": false
165
+ },
166
+ "created_at": {
167
+ "name": "created_at",
168
+ "type": "timestamp",
169
+ "primaryKey": false,
170
+ "notNull": true,
171
+ "default": "now()"
172
+ }
173
+ },
174
+ "indexes": {
175
+ "notifications_user_collapse_idx": {
176
+ "name": "notifications_user_collapse_idx",
177
+ "columns": [
178
+ {
179
+ "expression": "user_id",
180
+ "isExpression": false,
181
+ "asc": true,
182
+ "nulls": "last"
183
+ },
184
+ {
185
+ "expression": "group_id",
186
+ "isExpression": false,
187
+ "asc": true,
188
+ "nulls": "last"
189
+ }
190
+ ],
191
+ "isUnique": false,
192
+ "concurrently": false,
193
+ "method": "btree",
194
+ "with": {}
195
+ },
196
+ "notifications_user_created_idx": {
197
+ "name": "notifications_user_created_idx",
198
+ "columns": [
199
+ {
200
+ "expression": "user_id",
201
+ "isExpression": false,
202
+ "asc": true,
203
+ "nulls": "last"
204
+ },
205
+ {
206
+ "expression": "created_at",
207
+ "isExpression": false,
208
+ "asc": true,
209
+ "nulls": "last"
210
+ }
211
+ ],
212
+ "isUnique": false,
213
+ "concurrently": false,
214
+ "method": "btree",
215
+ "with": {}
216
+ }
217
+ },
218
+ "foreignKeys": {},
219
+ "compositePrimaryKeys": {},
220
+ "uniqueConstraints": {},
221
+ "policies": {},
222
+ "checkConstraints": {},
223
+ "isRLSEnabled": false
224
+ }
225
+ },
226
+ "enums": {},
227
+ "schemas": {},
228
+ "sequences": {},
229
+ "roles": {},
230
+ "policies": {},
231
+ "views": {},
232
+ "_meta": {
233
+ "columns": {},
234
+ "schemas": {},
235
+ "tables": {}
236
+ }
237
+ }