@checkstack/backend-api 0.14.1 → 0.15.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,114 @@
1
1
  # @checkstack/backend-api
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 50e5f5f: Runtime plugin system: install + uninstall plugins from npm, GitHub releases
8
+ (including private GitHub Enterprise instances), or tarball uploads at
9
+ runtime, with multi-package bundles, dependency-derived compatibility checks,
10
+ multi-instance coordination via a Postgres artifact store, and
11
+ single-coordinator destructive cleanup.
12
+
13
+ Highlights:
14
+
15
+ - New `PluginSource` discriminated union and `PluginInstaller` /
16
+ `PluginInstallerRegistry` interfaces in `@checkstack/backend-api`. The
17
+ GitHub variant accepts an optional `apiBaseUrl` so deployments backed by
18
+ GitHub Enterprise can install from `https://ghe.example.com/api/v3`
19
+ instead of `api.github.com`.
20
+ - New `installPackageMetadataSchema` (Zod) in `@checkstack/common` validates
21
+ every plugin's `package.json` at install time. Required fields: `name`,
22
+ `version`, `description`, `author`, `license`, `checkstack.type`,
23
+ `checkstack.pluginId`. Optional: `checkstack.bundle`,
24
+ `checkstack.usageInstructions`, `checkstack.allowInstallScripts`.
25
+ - New `pluginManagerContract` in `@checkstack/pluginmanager-common` with
26
+ `list`, `previewInstall`, `install`, `previewUninstall`, `uninstall`, and
27
+ `events` procedures.
28
+ - New `@checkstack/pluginmanager-frontend` admin UI: installed-plugins list
29
+ with per-row uninstall (typed-confirmation modal, schema/configs/cascade
30
+ toggles), install page with NPM / Tarball Upload / GitHub Release tabs
31
+ (Catalog tab disabled — coming soon), and an events page surfacing the
32
+ install/uninstall audit log.
33
+ - New `bunx @checkstack/scripts plugin-pack` CLI for plugin authors —
34
+ per-package mode produces an npm-shaped tarball; `--bundle` mode produces
35
+ an outer tarball containing every sibling declared in
36
+ `package.json#checkstack.bundle`. Published to npm so external authors
37
+ can `bunx` it directly without a workspace checkout.
38
+ - Compatibility derived from `package.json#dependencies` ranges
39
+ (`semver.satisfies` against the platform's loaded `@checkstack/*`
40
+ versions) — no separate `compatibility` field.
41
+ - Multi-instance: originator persists artifacts + `plugins` rows + broadcasts
42
+ install/uninstall; receiving instances do in-process register/unregister
43
+ only. Destructive ops (drop schema, delete plugin_configs, delete
44
+ artifacts, delete `plugins` rows) run exactly once on the originator.
45
+ - Fresh-instance bootstrap: `loadPlugins()` hydrates any
46
+ `is_uninstallable=true` plugin missing from `node_modules` from the
47
+ artifact store before normal Phase 1 register.
48
+ - New schema: `plugin_artifacts` (tarball storage), `plugin_install_events`
49
+ (audit/error log). `plugins` extended with `version`, `metadata`,
50
+ `source`, `bundle_id`, `is_primary`. Local plugin sync now writes
51
+ `version` from each plugin's `package.json` so the admin UI shows real
52
+ versions instead of `—`.
53
+ - Tarball-upload endpoint (`POST /api/pluginmanager/upload-tarball`) for
54
+ the install UI; access-gated by `pluginmanager.plugin.manage`.
55
+ - Plugin Manager menu link added to the user menu (main grid, alongside
56
+ Profile / Notification Settings / etc.).
57
+
58
+ Cross-cutting changes:
59
+
60
+ - Backend request/response logging now flows through `rootLogger` (winston)
61
+ instead of `hono/logger`. 5xx responses include the response body inline
62
+ so swallowed early-return errors are visible in the log.
63
+ - The `/api/:pluginId/*` dispatcher now logs which core service is missing
64
+ or which `pluginId` had no metadata when it 500s.
65
+ - New `registerCorePluginMetadata` on `PluginManager` for core routers
66
+ (like the plugin manager itself) that need their metadata visible to the
67
+ RPC dispatcher without going through the full plugin lifecycle.
68
+ - ESLint: `unicorn/no-null` is now disabled globally. Drizzle distinguishes
69
+ between `null` (writes a real SQL NULL) and `undefined` (skip the column
70
+ on insert), so treating them as interchangeable produced latent bugs at
71
+ the persistence boundary. The bulk of the patch-bumped packages above
72
+ reflect lint-fix touches that landed when this rule was relaxed.
73
+ - Workspace-wide license normalization to `Elastic-2.0` (matches
74
+ `LICENSE.md`). Every `package.json` in the workspace now declares the
75
+ same SPDX identifier; the patch bumps capture this.
76
+
77
+ Plugin packages (every `plugins/*`): added a `pack` npm script
78
+ (`bunx @checkstack/scripts plugin-pack`), mirrored each plugin's
79
+ `pluginId` from `plugin-metadata.ts` into `package.json#checkstack.pluginId`
80
+ so install-time validation passes, stubbed any missing required metadata
81
+ fields (`description`, `author`, `license`), and added
82
+ `checkstack.bundle` to multi-package plugin primaries (telegram, rcon, ssh,
83
+ jira, queue-bullmq, queue-memory, cache-memory).
84
+
85
+ Breaking changes:
86
+
87
+ - The legacy single-method `PluginInstaller` interface (`install(packageName)`)
88
+ is removed. Callers must use `coreServices.pluginInstallerRegistry`.
89
+ - The old `pluginAdminContract` and `createPluginAdminRouter` are removed.
90
+ Replaced by `pluginManagerContract` in `@checkstack/pluginmanager-common`
91
+ and `createPluginManagerRouter` in `core/backend`.
92
+ - `@checkstack/test-utils-backend` no longer exports
93
+ `createMockPluginInstaller` / `MockPluginInstaller` (the legacy interface
94
+ it shimmed is gone).
95
+
96
+ Note: bumps are limited to `minor` (for packages with new public API
97
+ surface) and `patch` (for downstream consumers, license normalization,
98
+ and lint fixes). No `major` bumps despite the `PluginInstaller` removal —
99
+ the legacy interface had no third-party consumers in the wild before this
100
+ runtime plugin system landed, and the contract surface is the same shape
101
+ modulo the rename.
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [50e5f5f]
106
+ - @checkstack/common@0.8.0
107
+ - @checkstack/queue-api@0.2.18
108
+ - @checkstack/cache-api@0.2.4
109
+ - @checkstack/healthcheck-common@1.0.1
110
+ - @checkstack/signal-common@0.2.1
111
+
3
112
  ## 0.14.1
4
113
 
5
114
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@checkstack/backend-api",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
+ "license": "Elastic-2.0",
4
5
  "type": "module",
5
6
  "main": "./src/index.ts",
6
7
  "scripts": {
@@ -11,8 +12,8 @@
11
12
  "dependencies": {
12
13
  "@checkstack/common": "0.7.0",
13
14
  "@checkstack/healthcheck-common": "1.0.0",
14
- "@checkstack/cache-api": "0.2.2",
15
- "@checkstack/queue-api": "0.2.16",
15
+ "@checkstack/cache-api": "0.2.3",
16
+ "@checkstack/queue-api": "0.2.17",
16
17
  "@checkstack/signal-common": "0.2.0",
17
18
  "@orpc/client": "^1.13.14",
18
19
  "@orpc/contract": "^1.13.14",
@@ -26,7 +27,7 @@
26
27
  },
27
28
  "devDependencies": {
28
29
  "@types/bun": "latest",
29
- "@checkstack/tsconfig": "0.0.5",
30
+ "@checkstack/tsconfig": "0.0.6",
30
31
  "@checkstack/scripts": "0.1.2"
31
32
  },
32
33
  "peerDependencies": {
package/src/assertions.ts CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint-disable unicorn/no-null */
1
+
2
2
  import { z } from "zod";
3
3
 
4
4
  // ============================================================================
@@ -10,13 +10,9 @@ import type {
10
10
  import type { ConfigService } from "./config-service";
11
11
  import type { SignalService } from "@checkstack/signal-common";
12
12
  import { SafeDatabase } from "./plugin-system";
13
- import {
14
- Logger,
15
- Fetch,
16
- AuthService,
17
- PluginInstaller,
18
- RpcClient,
19
- } from "./types";
13
+ import { Logger, Fetch, AuthService, RpcClient } from "./types";
14
+ import type { PluginInstallerRegistry } from "./plugin-source";
15
+ import type { PluginArtifactStore } from "./plugin-artifact-store";
20
16
  import type { EventBus } from "./event-bus-types";
21
17
  import type { WebSocketRouteRegistry } from "./ws-registry";
22
18
  import type { ReadinessRegistry } from "./readiness-registry";
@@ -39,7 +35,20 @@ export const coreServices = {
39
35
  collectorRegistry: createServiceRef<CollectorRegistry>(
40
36
  "core.collectorRegistry",
41
37
  ),
42
- pluginInstaller: createServiceRef<PluginInstaller>("core.pluginInstaller"),
38
+ /**
39
+ * Per-source installer registry used by the runtime plugin system.
40
+ * Indexed by `PluginSource["type"]` (npm, tarball, github, catalog).
41
+ */
42
+ pluginInstallerRegistry: createServiceRef<PluginInstallerRegistry>(
43
+ "core.pluginInstallerRegistry",
44
+ ),
45
+ /**
46
+ * Persistent tarball store backing fresh-instance bootstrap and
47
+ * cross-instance artifact sharing.
48
+ */
49
+ pluginArtifactStore: createServiceRef<PluginArtifactStore>(
50
+ "core.pluginArtifactStore",
51
+ ),
43
52
  rpc: createServiceRef<RpcService>("core.rpc"),
44
53
  rpcClient: createServiceRef<RpcClient>("core.rpcClient"),
45
54
  queuePluginRegistry: createServiceRef<QueuePluginRegistry>(
package/src/index.ts CHANGED
@@ -15,7 +15,8 @@ export * from "./rpc";
15
15
  export * from "./test-utils";
16
16
  export * from "./hooks";
17
17
  export * from "./event-bus-types";
18
- export * from "./plugin-admin-contract";
18
+ export * from "./plugin-source";
19
+ export * from "./plugin-artifact-store";
19
20
  export * from "./notification-strategy";
20
21
  export * from "./oauth-handler";
21
22
  export * from "./markdown";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Persistent storage for plugin tarballs.
3
+ *
4
+ * Implementations must be **shared across all instances** so that a freshly
5
+ * spun-up replica can recover any plugin that was installed at runtime
6
+ * without re-fetching from the original source. The default implementation
7
+ * uses a Postgres `plugin_artifacts` table (bytea); an S3 implementation
8
+ * can drop in via env config later.
9
+ *
10
+ * Lifecycle:
11
+ * 1. Originator's install handler calls `store(...)` after fetching the
12
+ * tarball from the source. This commits in the same DB transaction
13
+ * as the `plugins` row insert.
14
+ * 2. Every instance handling the install broadcast (incl. originator)
15
+ * calls `fetch(...)` to get the tarball bytes, then runs `bun install`.
16
+ * 3. On uninstall, originator calls `delete(...)` to drop the row.
17
+ */
18
+ export interface PluginArtifactStore {
19
+ store(input: {
20
+ pluginName: string;
21
+ version: string;
22
+ /** `null` for single-package installs; `string` for bundle siblings. */
23
+ bundleId?: string | null;
24
+ tarball: Uint8Array;
25
+ }): Promise<{ artifactId: string; contentHash: string }>;
26
+
27
+ /**
28
+ * Fetch by `(pluginName, version)`. Returns `undefined` if not present
29
+ * (e.g. the artifact has been pruned but the `plugins` row still exists —
30
+ * the caller is expected to fall back to refetching from the original
31
+ * `PluginSource`).
32
+ */
33
+ fetch(input: {
34
+ pluginName: string;
35
+ version: string;
36
+ }): Promise<{ tarball: Uint8Array; contentHash: string } | undefined>;
37
+
38
+ fetchById(artifactId: string): Promise<
39
+ | {
40
+ tarball: Uint8Array;
41
+ contentHash: string;
42
+ pluginName: string;
43
+ version: string;
44
+ }
45
+ | undefined
46
+ >;
47
+
48
+ /** Delete artifacts for a plugin (all versions). Used on uninstall. */
49
+ delete(input: { pluginName: string }): Promise<void>;
50
+
51
+ /** Delete artifacts for a whole bundle. */
52
+ deleteByBundle(input: { bundleId: string }): Promise<void>;
53
+
54
+ /** Hard cap (in bytes) the store will accept. Used for UI feedback. */
55
+ readonly maxArtifactSize: number;
56
+ }
@@ -0,0 +1,84 @@
1
+ import {
2
+
3
+
4
+
5
+ type InstallPackageMetadata,
6
+ type PluginBundleManifest,
7
+ type PluginSource,
8
+ } from "@checkstack/common";
9
+
10
+ // ─────────────────────────────────────────────────────────────────────────────
11
+ // Runtime-only types for the plugin installer pipeline.
12
+ //
13
+ // `PluginSource` (the discriminated union itself) lives in `@checkstack/common`
14
+ // because it must be referenceable from contracts. The interfaces below are
15
+ // implemented by services running on the backend, so they live here.
16
+ // ─────────────────────────────────────────────────────────────────────────────
17
+
18
+ export interface FetchedTarball {
19
+ tarball: Uint8Array;
20
+ packageJson: InstallPackageMetadata;
21
+ /**
22
+ * Set when the fetched tarball is a bundle (outer `.tgz` containing
23
+ * sibling tarballs and a `bundle.json`). The siblings array contains
24
+ * already-extracted per-package tarballs.
25
+ */
26
+ bundle?: {
27
+ manifest: PluginBundleManifest;
28
+ siblings: Array<{
29
+ tarball: Uint8Array;
30
+ packageJson: InstallPackageMetadata;
31
+ }>;
32
+ };
33
+ }
34
+
35
+ export interface InstalledArtifact {
36
+ /** The npm package name (matches `packageJson.name`) */
37
+ name: string;
38
+ /** Absolute path to the installed plugin under the runtime dir */
39
+ path: string;
40
+ /** The installed version */
41
+ version: string;
42
+ }
43
+
44
+ /**
45
+ * Per-source installer.
46
+ *
47
+ * Two-phase by design:
48
+ * 1. fetchTarball(source) — pulls bytes; does NOT install anything.
49
+ * Originator runs this once, persists the
50
+ * bytes to plugin_artifacts, then broadcasts.
51
+ * 2. installFromArtifact({ ... }) — extracts the tarball into the plugin
52
+ * runtime dir via `bun install ... --no-save
53
+ * --ignore-scripts` (unless allowInstallScripts).
54
+ * Every instance runs this when handling
55
+ * the broadcast.
56
+ */
57
+ export interface PluginInstaller {
58
+ fetchTarball(source: PluginSource): Promise<FetchedTarball>;
59
+ installFromArtifact(input: {
60
+ tarball: Uint8Array;
61
+ pluginName: string;
62
+ allowInstallScripts?: boolean;
63
+ }): Promise<InstalledArtifact>;
64
+ }
65
+
66
+ /**
67
+ * Registry of per-source installers. Indexed by `PluginSource["type"]`.
68
+ */
69
+ export interface PluginInstallerRegistry {
70
+ forSource(type: PluginSource["type"]): PluginInstaller;
71
+ fetchTarball(source: PluginSource): Promise<FetchedTarball>;
72
+ }
73
+
74
+ // Re-export the source-related schemas/types from `@checkstack/common` so
75
+ // backend code only needs one import path.
76
+
77
+ export type {
78
+ NpmPluginSource,
79
+ TarballPluginSource,
80
+ GithubPluginSource,
81
+ CatalogPluginSource, PluginSource, InstallPackageMetadata, PluginBundleManifest,
82
+ } from "@checkstack/common";
83
+
84
+ export {installPackageMetadataSchema, pluginBundleManifestSchema, pluginSourceSchema} from "@checkstack/common";
package/src/types.ts CHANGED
@@ -105,9 +105,8 @@ export interface AuthenticationStrategy {
105
105
  validate(request: Request): Promise<RealUser | ApplicationUser | undefined>;
106
106
  }
107
107
 
108
- export interface PluginInstaller {
109
- install(packageName: string): Promise<{ name: string; path: string }>;
110
- }
108
+ // Runtime-plugin installer types live in ./plugin-source.ts and are
109
+ // re-exported via the package index.
111
110
 
112
111
  /**
113
112
  * Options for declarative route definitions (Deprecated, will be replaced by oRPC procedures).
@@ -1,59 +0,0 @@
1
- import { z } from "zod";
2
- import { access, proc } from "@checkstack/common";
3
-
4
- // ─────────────────────────────────────────────────────────────────────────────
5
- // Access Rules
6
- // ─────────────────────────────────────────────────────────────────────────────
7
-
8
- export const pluginAdminAccess = {
9
- install: access("plugin", "manage", "Install new plugins from npm"),
10
- deregister: access("plugin", "manage", "Deregister (uninstall) plugins"),
11
- };
12
-
13
- export const pluginAdminAccessRules = [
14
- pluginAdminAccess.install,
15
- pluginAdminAccess.deregister,
16
- ];
17
-
18
- // ─────────────────────────────────────────────────────────────────────────────
19
- // Contract
20
- // ─────────────────────────────────────────────────────────────────────────────
21
-
22
- export const pluginAdminContract = {
23
- /**
24
- * Install a plugin from npm and load it across all instances.
25
- */
26
- install: proc({
27
- operationType: "mutation",
28
- userType: "user",
29
- access: [pluginAdminAccess.install],
30
- })
31
- .input(
32
- z.object({
33
- packageName: z.string().min(1, "Package name is required"),
34
- })
35
- )
36
- .output(
37
- z.object({
38
- success: z.boolean(),
39
- pluginId: z.string(),
40
- path: z.string(),
41
- })
42
- ),
43
-
44
- /**
45
- * Deregister a plugin across all instances.
46
- */
47
- deregister: proc({
48
- operationType: "mutation",
49
- userType: "user",
50
- access: [pluginAdminAccess.deregister],
51
- })
52
- .input(
53
- z.object({
54
- pluginId: z.string().min(1, "Plugin ID is required"),
55
- deleteSchema: z.boolean().default(false),
56
- })
57
- )
58
- .output(z.object({ success: z.boolean() })),
59
- };