@checkstack/backend 0.8.1 → 0.9.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +280 -0
  2. package/drizzle/0001_slim_mordo.sql +34 -0
  3. package/drizzle/meta/0001_snapshot.json +444 -0
  4. package/drizzle/meta/_journal.json +7 -0
  5. package/package.json +14 -9
  6. package/src/index.ts +460 -23
  7. package/src/plugin-deregistration.test.ts +137 -0
  8. package/src/plugin-manager/api-router.ts +35 -11
  9. package/src/plugin-manager/core-services.ts +21 -2
  10. package/src/plugin-manager/plugin-loader.ts +94 -0
  11. package/src/plugin-manager.ts +324 -105
  12. package/src/router-incremental.test.ts +49 -0
  13. package/src/schema.ts +79 -1
  14. package/src/services/compatibility-checker.test.ts +146 -0
  15. package/src/services/compatibility-checker.ts +137 -0
  16. package/src/services/dev-auth.test.ts +87 -0
  17. package/src/services/dev-auth.ts +56 -0
  18. package/src/services/plugin-artifact-store.ts +131 -0
  19. package/src/services/plugin-bundle-resolver.ts +76 -0
  20. package/src/services/plugin-event-recorder.ts +87 -0
  21. package/src/services/plugin-installers/catalog-installer.ts +33 -0
  22. package/src/services/plugin-installers/github-installer.ts +207 -0
  23. package/src/services/plugin-installers/install-from-tarball.ts +69 -0
  24. package/src/services/plugin-installers/installer-registry.ts +51 -0
  25. package/src/services/plugin-installers/npm-installer.ts +156 -0
  26. package/src/services/plugin-installers/plugin-install-error.ts +37 -0
  27. package/src/services/plugin-installers/tarball-installer.ts +80 -0
  28. package/src/services/plugin-installers/tarball-utils.test.ts +200 -0
  29. package/src/services/plugin-installers/tarball-utils.ts +172 -0
  30. package/src/services/plugin-manager-orchestrator.ts +522 -0
  31. package/src/services/plugin-manager-router.ts +219 -0
  32. package/src/services/readiness-registry.test.ts +124 -0
  33. package/src/services/readiness-registry.ts +103 -0
  34. package/src/utils/plugin-discovery.test.ts +6 -0
  35. package/src/utils/plugin-discovery.ts +6 -1
  36. package/tsconfig.json +36 -1
  37. package/src/plugin-lifecycle.test.ts +0 -276
  38. package/src/plugin-manager/plugin-admin-router.ts +0 -89
  39. package/src/services/plugin-installer.test.ts +0 -90
  40. package/src/services/plugin-installer.ts +0 -70
package/CHANGELOG.md CHANGED
@@ -1,5 +1,285 @@
1
1
  # @checkstack/backend
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 50e5f5f: Add `bunx @checkstack/scripts dev` — a local Checkstack dev server for
8
+ plugin authors that runs from the plugin's own repo without a monorepo
9
+ checkout.
10
+
11
+ Mechanics:
12
+
13
+ - The dev command spawns `core/backend`'s production entry as a child
14
+ process with three env vars wired in:
15
+ - `CHECKSTACK_DEV_PLUGIN_PATH=<cwd>` — backend skips filesystem
16
+ discovery and imports the plugin at this path as a manual plugin.
17
+ - `CHECKSTACK_DEV_EXTRA_PLUGIN_PATHS=<JSON array>` — additional
18
+ backend plugins co-loaded as manual plugins. The dev command walks
19
+ the plugin under dev's `package.json#dependencies` recursively to
20
+ discover every `@checkstack/*-backend` package and pass their
21
+ module paths through. Auto-includes
22
+ `@checkstack/queue-memory-backend` +
23
+ `@checkstack/cache-memory-backend` when no other queue/cache
24
+ provider is in the dep graph, so `coreServices.queueManager` /
25
+ `coreServices.cacheManager` always have a registered strategy on
26
+ boot. Without this co-loading, plugins that depend on
27
+ `healthcheck-backend`, `notification-backend`, etc. would hit
28
+ unregistered services and the boot would deadlock.
29
+ - `CHECKSTACK_DEV_AUTH=true` — backend registers a synthetic
30
+ `AuthService` that auto-grants every registered access rule.
31
+ Refused when `NODE_ENV=production` so accidental misuse is loud.
32
+ - A file watcher under the plugin's `./src` triggers a full backend
33
+ restart (debounced) on save. Bun's startup is sub-second for a single
34
+ plugin, so the loop stays tight.
35
+ - For frontend plugins (or bundle primaries with a `-frontend`
36
+ sibling), the dev command additionally spawns a Vite dev server on
37
+ port 5173 (configurable via `--frontend-port`). Vite serves
38
+ `core/frontend`'s new `dev-main.tsx` shell — the same App.tsx,
39
+ loadPlugins(), ThemeProvider, etc. that ship in production. The
40
+ plugin module is mounted via a `virtual:checkstack-dev-plugin` alias
41
+ Vite resolves at config time. React Fast Refresh works for component
42
+ edits.
43
+ - On boot, the dev command validates the plugin's `package.json`
44
+ against the same `installPackageMetadataSchema` the runtime install
45
+ pipeline uses, so missing required fields fail fast.
46
+
47
+ Reuses 100% of the production boot code path — no parallel dev backend
48
+ to drift from. New code surfaces:
49
+
50
+ - `core/backend/src/services/dev-auth.ts` — the synthetic auth service.
51
+ Inert unless `CHECKSTACK_DEV_AUTH=true`.
52
+ - `core/scripts/src/commands/dev-server.ts` — the CLI command.
53
+ - `core/scripts/src/commands/dev-deps-resolver.ts` — pure function that
54
+ walks the plugin's deps and resolves the co-load set; covered by 8
55
+ unit tests.
56
+ - `core/scripts/src/commands/dev-frontend.ts` — Vite spawn helper.
57
+ - `core/frontend/src/dev-main.tsx` — frontend dev-shell entry.
58
+
59
+ `@checkstack/scripts` now depends on `@checkstack/backend`,
60
+ `@checkstack/frontend`, `@checkstack/frontend-api`, `@checkstack/ui`,
61
+ `vite`, and `@vitejs/plugin-react` so a `bunx` invocation pulls in
62
+ everything needed for the dev server in one shot.
63
+
64
+ Replaces the previous "three patterns" plugin-development guide with a
65
+ single `bun run dev` workflow.
66
+
67
+ A new ESLint rule branch in `no-extraneous-runtime-deps` ignores
68
+ `virtual:` module specifiers (resolved by bundler aliases at runtime,
69
+ not installed from npm).
70
+
71
+ Scaffold templates updated for one-click compatibility — `bun run create`
72
+ now produces plugin packages that pass the dev-server's
73
+ `installPackageMetadataSchema` gate and ship `dev` / `pack` scripts plus
74
+ `@checkstack/scripts` in devDependencies, so a freshly scaffolded plugin
75
+ runs `bun run dev` without any further file edits. Required metadata
76
+ (`description`, `author`, `license: "Elastic-2.0"`, `checkstack.pluginId`)
77
+ is filled in by the scaffold; `@checkstack/scripts plugin-pack
78
+ --validate-only` accepts the rendered package.json directly. Templates
79
+ also reformatted from one-line JSON-in-handlebars to readable
80
+ multi-line.
81
+
82
+ New scaffold tests in `core/scripts/src/templates.test.ts` render each
83
+ template type and assert: dev-server validation passes, `dev` script
84
+ present (backend/frontend), `pack` script present, `@checkstack/scripts`
85
+ in devDependencies.
86
+
87
+ In addition, the new `dev-internals.ts`, `dev-lifecycle.ts`,
88
+ `dev-deps-resolver.ts`, and refactored `dev-frontend.ts` ship 58
89
+ unit tests covering arg parsing, package.json validation, backend
90
+ entry resolution, frontend-spawn decision, child env construction,
91
+ the debounce watcher, the spawn → restart → shutdown lifecycle (with
92
+ hard-kill SIGKILL fallback), the dev-auth service, and the bundle
93
+ sibling resolver — all driven through injectable seams so no real
94
+ process / Postgres / Vite is needed at test time.
95
+
96
+ - 50e5f5f: Runtime plugin system: install + uninstall plugins from npm, GitHub releases
97
+ (including private GitHub Enterprise instances), or tarball uploads at
98
+ runtime, with multi-package bundles, dependency-derived compatibility checks,
99
+ multi-instance coordination via a Postgres artifact store, and
100
+ single-coordinator destructive cleanup.
101
+
102
+ Highlights:
103
+
104
+ - New `PluginSource` discriminated union and `PluginInstaller` /
105
+ `PluginInstallerRegistry` interfaces in `@checkstack/backend-api`. The
106
+ GitHub variant accepts an optional `apiBaseUrl` so deployments backed by
107
+ GitHub Enterprise can install from `https://ghe.example.com/api/v3`
108
+ instead of `api.github.com`.
109
+ - New `installPackageMetadataSchema` (Zod) in `@checkstack/common` validates
110
+ every plugin's `package.json` at install time. Required fields: `name`,
111
+ `version`, `description`, `author`, `license`, `checkstack.type`,
112
+ `checkstack.pluginId`. Optional: `checkstack.bundle`,
113
+ `checkstack.usageInstructions`, `checkstack.allowInstallScripts`.
114
+ - New `pluginManagerContract` in `@checkstack/pluginmanager-common` with
115
+ `list`, `previewInstall`, `install`, `previewUninstall`, `uninstall`, and
116
+ `events` procedures.
117
+ - New `@checkstack/pluginmanager-frontend` admin UI: installed-plugins list
118
+ with per-row uninstall (typed-confirmation modal, schema/configs/cascade
119
+ toggles), install page with NPM / Tarball Upload / GitHub Release tabs
120
+ (Catalog tab disabled — coming soon), and an events page surfacing the
121
+ install/uninstall audit log.
122
+ - New `bunx @checkstack/scripts plugin-pack` CLI for plugin authors —
123
+ per-package mode produces an npm-shaped tarball; `--bundle` mode produces
124
+ an outer tarball containing every sibling declared in
125
+ `package.json#checkstack.bundle`. Published to npm so external authors
126
+ can `bunx` it directly without a workspace checkout.
127
+ - Compatibility derived from `package.json#dependencies` ranges
128
+ (`semver.satisfies` against the platform's loaded `@checkstack/*`
129
+ versions) — no separate `compatibility` field.
130
+ - Multi-instance: originator persists artifacts + `plugins` rows + broadcasts
131
+ install/uninstall; receiving instances do in-process register/unregister
132
+ only. Destructive ops (drop schema, delete plugin_configs, delete
133
+ artifacts, delete `plugins` rows) run exactly once on the originator.
134
+ - Fresh-instance bootstrap: `loadPlugins()` hydrates any
135
+ `is_uninstallable=true` plugin missing from `node_modules` from the
136
+ artifact store before normal Phase 1 register.
137
+ - New schema: `plugin_artifacts` (tarball storage), `plugin_install_events`
138
+ (audit/error log). `plugins` extended with `version`, `metadata`,
139
+ `source`, `bundle_id`, `is_primary`. Local plugin sync now writes
140
+ `version` from each plugin's `package.json` so the admin UI shows real
141
+ versions instead of `—`.
142
+ - Tarball-upload endpoint (`POST /api/pluginmanager/upload-tarball`) for
143
+ the install UI; access-gated by `pluginmanager.plugin.manage`.
144
+ - Plugin Manager menu link added to the user menu (main grid, alongside
145
+ Profile / Notification Settings / etc.).
146
+
147
+ Cross-cutting changes:
148
+
149
+ - Backend request/response logging now flows through `rootLogger` (winston)
150
+ instead of `hono/logger`. 5xx responses include the response body inline
151
+ so swallowed early-return errors are visible in the log.
152
+ - The `/api/:pluginId/*` dispatcher now logs which core service is missing
153
+ or which `pluginId` had no metadata when it 500s.
154
+ - New `registerCorePluginMetadata` on `PluginManager` for core routers
155
+ (like the plugin manager itself) that need their metadata visible to the
156
+ RPC dispatcher without going through the full plugin lifecycle.
157
+ - ESLint: `unicorn/no-null` is now disabled globally. Drizzle distinguishes
158
+ between `null` (writes a real SQL NULL) and `undefined` (skip the column
159
+ on insert), so treating them as interchangeable produced latent bugs at
160
+ the persistence boundary. The bulk of the patch-bumped packages above
161
+ reflect lint-fix touches that landed when this rule was relaxed.
162
+ - Workspace-wide license normalization to `Elastic-2.0` (matches
163
+ `LICENSE.md`). Every `package.json` in the workspace now declares the
164
+ same SPDX identifier; the patch bumps capture this.
165
+
166
+ Plugin packages (every `plugins/*`): added a `pack` npm script
167
+ (`bunx @checkstack/scripts plugin-pack`), mirrored each plugin's
168
+ `pluginId` from `plugin-metadata.ts` into `package.json#checkstack.pluginId`
169
+ so install-time validation passes, stubbed any missing required metadata
170
+ fields (`description`, `author`, `license`), and added
171
+ `checkstack.bundle` to multi-package plugin primaries (telegram, rcon, ssh,
172
+ jira, queue-bullmq, queue-memory, cache-memory).
173
+
174
+ Breaking changes:
175
+
176
+ - The legacy single-method `PluginInstaller` interface (`install(packageName)`)
177
+ is removed. Callers must use `coreServices.pluginInstallerRegistry`.
178
+ - The old `pluginAdminContract` and `createPluginAdminRouter` are removed.
179
+ Replaced by `pluginManagerContract` in `@checkstack/pluginmanager-common`
180
+ and `createPluginManagerRouter` in `core/backend`.
181
+ - `@checkstack/test-utils-backend` no longer exports
182
+ `createMockPluginInstaller` / `MockPluginInstaller` (the legacy interface
183
+ it shimmed is gone).
184
+
185
+ Note: bumps are limited to `minor` (for packages with new public API
186
+ surface) and `patch` (for downstream consumers, license normalization,
187
+ and lint fixes). No `major` bumps despite the `PluginInstaller` removal —
188
+ the legacy interface had no third-party consumers in the wild before this
189
+ runtime plugin system landed, and the contract surface is the same shape
190
+ modulo the rename.
191
+
192
+ ### Patch Changes
193
+
194
+ - Updated dependencies [50e5f5f]
195
+ - @checkstack/auth-common@0.6.5
196
+ - @checkstack/backend-api@0.15.0
197
+ - @checkstack/common@0.8.0
198
+ - @checkstack/drizzle-helper@0.0.5
199
+ - @checkstack/pluginmanager-common@0.2.0
200
+ - @checkstack/queue-api@0.2.18
201
+ - @checkstack/signal-backend@0.2.3
202
+ - @checkstack/api-docs-common@0.1.11
203
+ - @checkstack/cache-api@0.2.4
204
+ - @checkstack/signal-common@0.2.1
205
+
206
+ ## 0.8.2
207
+
208
+ ### Patch Changes
209
+
210
+ - 302cd3f: fix: resilient startup routing + /health and /ready endpoints
211
+
212
+ Three fixes that together eliminate startup-race errors during boot and
213
+ hot-reload, plus a new readiness API for plugins.
214
+
215
+ 1. **TrieRouter swap (root cause).** Hono's default `SmartRouter` freezes
216
+ its matcher on the first request — any later `app.add()` throws
217
+ `MESSAGE_MATCHER_IS_ALREADY_BUILT`. Plugins register routes during
218
+ `init()` (and at runtime via `loadSinglePlugin`), so an early request
219
+ during boot would silently lock the matcher with only the module-load
220
+ routes, and every later route registration would fail. The backend
221
+ now uses `TrieRouter`, which is incremental — routes can be added at
222
+ any time, including after thousands of requests have been served.
223
+ This also future-proofs runtime plugin install.
224
+
225
+ 2. **Init gating + fail-loud.** Non-bypass requests now `await` an
226
+ `initPromise` (with a 30s timeout that returns 503 + Retry-After) so
227
+ no traffic reaches Hono before plugins finish registering routes.
228
+ Init failures crash the process via `process.exit(1)` so docker/k8s
229
+ restart cleanly instead of silently serving a half-initialized
230
+ backend.
231
+
232
+ 3. **`/assets/*` fall-through.** The production frontend asset handler
233
+ now calls `next()` instead of `c.notFound()` on miss, so
234
+ plugin-asset routes registered later (`/assets/plugins/:pluginName/*`)
235
+ actually get a chance to match.
236
+
237
+ ### New: platform endpoints under `/.checkstack/*`
238
+
239
+ - `GET /.checkstack/health` — liveness, always 200 once the process is up.
240
+ - `GET /.checkstack/ready` — readiness, 503 until init completes and all
241
+ critical probes pass; 200 otherwise. Returns `{ ready, checks: [...] }`
242
+ with per-probe status, message/error and duration.
243
+
244
+ The leading `.checkstack/` prefix namespaces platform-level endpoints
245
+ away from plugin `/api/*`, runtime frontend assets, and the SPA wildcard,
246
+ leaving room for additional operator endpoints in the future.
247
+
248
+ ### New: plugin readiness API
249
+
250
+ Plugins can contribute readiness probes via the new
251
+ `coreServices.readinessRegistry` service:
252
+
253
+ ```ts
254
+ registerInit({
255
+ deps: { readiness: coreServices.readinessRegistry },
256
+ async init({ readiness }) {
257
+ readiness.register({
258
+ name: "queue.connected",
259
+ critical: true,
260
+ check: async () => ({
261
+ ok: pool.isConnected(),
262
+ message: pool.isConnected() ? undefined : "queue pool not connected",
263
+ }),
264
+ });
265
+ },
266
+ });
267
+ ```
268
+
269
+ Probes run in parallel, throwing probes are reported as `ok: false`,
270
+ and non-critical probes don't block readiness.
271
+
272
+ - Updated dependencies [302cd3f]
273
+ - @checkstack/backend-api@0.14.1
274
+ - @checkstack/cache-api@0.2.3
275
+ - @checkstack/queue-api@0.2.17
276
+ - @checkstack/signal-backend@0.2.2
277
+ - @checkstack/api-docs-common@0.1.10
278
+ - @checkstack/auth-common@0.6.4
279
+ - @checkstack/common@0.7.0
280
+ - @checkstack/drizzle-helper@0.0.4
281
+ - @checkstack/signal-common@0.2.0
282
+
3
283
  ## 0.8.1
4
284
 
5
285
  ### Patch Changes
@@ -0,0 +1,34 @@
1
+ CREATE TABLE "plugin_artifacts" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "plugin_name" text NOT NULL,
4
+ "version" text NOT NULL,
5
+ "bundle_id" uuid,
6
+ "tarball" text NOT NULL,
7
+ "content_hash" text NOT NULL,
8
+ "size_bytes" integer NOT NULL,
9
+ "created_at" timestamp DEFAULT now() NOT NULL
10
+ );
11
+ --> statement-breakpoint
12
+ CREATE TABLE "plugin_install_events" (
13
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
14
+ "plugin_name" text,
15
+ "bundle_id" uuid,
16
+ "action" text NOT NULL,
17
+ "phase" text NOT NULL,
18
+ "status" text NOT NULL,
19
+ "source" jsonb,
20
+ "error" text,
21
+ "instance_id" text NOT NULL,
22
+ "user_id" text,
23
+ "created_at" timestamp DEFAULT now() NOT NULL
24
+ );
25
+ --> statement-breakpoint
26
+ ALTER TABLE "plugins" ADD COLUMN "version" text DEFAULT '' NOT NULL;--> statement-breakpoint
27
+ ALTER TABLE "plugins" ADD COLUMN "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL;--> statement-breakpoint
28
+ ALTER TABLE "plugins" ADD COLUMN "source" jsonb;--> statement-breakpoint
29
+ ALTER TABLE "plugins" ADD COLUMN "bundle_id" uuid;--> statement-breakpoint
30
+ ALTER TABLE "plugins" ADD COLUMN "is_primary" boolean DEFAULT false NOT NULL;--> statement-breakpoint
31
+ CREATE UNIQUE INDEX "plugin_artifacts_name_version_idx" ON "plugin_artifacts" USING btree ("plugin_name","version");--> statement-breakpoint
32
+ CREATE INDEX "plugin_artifacts_content_hash_idx" ON "plugin_artifacts" USING btree ("content_hash");--> statement-breakpoint
33
+ CREATE INDEX "plugin_install_events_name_created_idx" ON "plugin_install_events" USING btree ("plugin_name","created_at");--> statement-breakpoint
34
+ CREATE INDEX "plugin_install_events_status_created_idx" ON "plugin_install_events" USING btree ("status","created_at");