@checkstack/pluginmanager-common 0.2.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 ADDED
@@ -0,0 +1,106 @@
1
+ # @checkstack/pluginmanager-common
2
+
3
+ ## 0.2.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
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@checkstack/pluginmanager-common",
3
+ "version": "0.2.0",
4
+ "license": "Elastic-2.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./src/index.ts",
9
+ "import": "./src/index.ts"
10
+ }
11
+ },
12
+ "dependencies": {
13
+ "@checkstack/common": "0.7.0",
14
+ "zod": "^4.0.0"
15
+ },
16
+ "devDependencies": {
17
+ "@checkstack/tsconfig": "0.0.6",
18
+ "@checkstack/scripts": "0.1.2",
19
+ "typescript": "^5.7.2"
20
+ },
21
+ "scripts": {
22
+ "typecheck": "tsgo -b",
23
+ "lint": "bun run lint:code",
24
+ "lint:code": "eslint . --max-warnings 0"
25
+ },
26
+ "checkstack": {
27
+ "type": "common"
28
+ }
29
+ }
package/src/access.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { access } from "@checkstack/common";
2
+
3
+ /**
4
+ * Access rules for the Plugin Manager.
5
+ *
6
+ * The plugin system runs arbitrary code with full platform access — only
7
+ * trusted operators should hold the `manage` rule.
8
+ */
9
+ export const pluginManagerAccess = {
10
+ view: access("plugin", "read", "View installed plugins and install events"),
11
+ install: access("plugin", "manage", "Install plugins from any source"),
12
+ uninstall: access("plugin", "manage", "Uninstall plugins"),
13
+ };
14
+
15
+ export const pluginManagerAccessRules = [
16
+ pluginManagerAccess.view,
17
+ pluginManagerAccess.install,
18
+ pluginManagerAccess.uninstall,
19
+ ];
package/src/index.ts ADDED
@@ -0,0 +1,37 @@
1
+ export { pluginMetadata } from "./plugin-metadata";
2
+ export { pluginManagerRoutes } from "./routes";
3
+ export { pluginManagerAccess, pluginManagerAccessRules } from "./access";
4
+ export {
5
+ pluginManagerContract,
6
+ PluginManagerApi,
7
+ type PluginManagerContract,
8
+ } from "./rpc-contract";
9
+ // Re-export source types from `@checkstack/common` so consumers only need
10
+ // one import for the contract + its inputs/outputs.
11
+ export {
12
+ pluginSourceSchema,
13
+ type PluginSource,
14
+ type NpmPluginSource,
15
+ type TarballPluginSource,
16
+ type GithubPluginSource,
17
+ type CatalogPluginSource,
18
+ } from "@checkstack/common";
19
+
20
+ export {
21
+ compatibilityIssueSchema,
22
+ installPreviewSchema,
23
+ uninstallPreviewSchema,
24
+ installedPluginSchema,
25
+ installEventSchema,
26
+ installEventActionEnum,
27
+ installEventPhaseEnum,
28
+ installEventStatusEnum,
29
+ type CompatibilityIssue,
30
+ type InstallPreview,
31
+ type UninstallPreview,
32
+ type InstalledPlugin,
33
+ type InstallEvent,
34
+ type InstallEventAction,
35
+ type InstallEventPhase,
36
+ type InstallEventStatus,
37
+ } from "./schemas";
@@ -0,0 +1,5 @@
1
+ import { definePluginMetadata } from "@checkstack/common";
2
+
3
+ export const pluginMetadata = definePluginMetadata({
4
+ pluginId: "pluginmanager",
5
+ });
package/src/routes.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { createRoutes } from "@checkstack/common";
2
+
3
+ /**
4
+ * Route definitions for the plugin manager admin UI.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * import { pluginManagerRoutes } from "@checkstack/pluginmanager-common";
9
+ *
10
+ * createFrontendPlugin({
11
+ * routes: [
12
+ * { route: pluginManagerRoutes.routes.installed, element: <InstalledPluginsPage /> },
13
+ * ],
14
+ * });
15
+ * ```
16
+ */
17
+ export const pluginManagerRoutes = createRoutes("pluginmanager", {
18
+ installed: "/",
19
+ install: "/install",
20
+ events: "/events",
21
+ });
@@ -0,0 +1,136 @@
1
+ import { z } from "zod";
2
+ import {
3
+ createClientDefinition,
4
+ proc,
5
+ pluginSourceSchema,
6
+ } from "@checkstack/common";
7
+ import { pluginManagerAccess } from "./access";
8
+ import { pluginMetadata } from "./plugin-metadata";
9
+ import {
10
+ installPreviewSchema,
11
+ uninstallPreviewSchema,
12
+ installedPluginSchema,
13
+ installEventSchema,
14
+ } from "./schemas";
15
+
16
+ // Confirmation tokens: the UI must echo back a typed phrase before destructive
17
+ // or potentially-malicious mutations are accepted. Mirrors the strong typed
18
+ // confirmation modal pattern used in the install/uninstall UI.
19
+ const installConfirmTokenSchema = z
20
+ .string()
21
+ .min(1, "Typed confirmation is required");
22
+ const uninstallConfirmTokenSchema = z
23
+ .string()
24
+ .min(1, "Typed confirmation is required");
25
+
26
+ export const pluginManagerContract = {
27
+ /**
28
+ * List all installed plugins (local monorepo + runtime-installed).
29
+ */
30
+ list: proc({
31
+ operationType: "query",
32
+ userType: "user",
33
+ access: [pluginManagerAccess.view],
34
+ })
35
+ .input(z.void())
36
+ .output(z.object({ plugins: z.array(installedPluginSchema) })),
37
+
38
+ /**
39
+ * Resolve a `PluginSource` to its full bundle metadata + compatibility
40
+ * issues. Performs no destructive ops — pure preview for the UI's
41
+ * typed-confirmation modal.
42
+ */
43
+ previewInstall: proc({
44
+ operationType: "mutation",
45
+ userType: "user",
46
+ access: [pluginManagerAccess.install],
47
+ })
48
+ .input(z.object({ source: pluginSourceSchema }))
49
+ .output(installPreviewSchema),
50
+
51
+ /**
52
+ * Install a plugin (or bundle) from a source. Re-runs validation and
53
+ * compatibility — the preview is non-binding. Persists the artifact to
54
+ * `plugin_artifacts` and broadcasts to all instances.
55
+ */
56
+ install: proc({
57
+ operationType: "mutation",
58
+ userType: "user",
59
+ access: [pluginManagerAccess.install],
60
+ })
61
+ .input(
62
+ z.object({
63
+ source: pluginSourceSchema,
64
+ confirm: installConfirmTokenSchema,
65
+ }),
66
+ )
67
+ .output(
68
+ z.object({
69
+ success: z.boolean(),
70
+ bundleId: z.string().nullable(),
71
+ installedPackages: z.array(z.string()),
72
+ }),
73
+ ),
74
+
75
+ /**
76
+ * Resolve a plugin id to the cleanup picture: siblings, dependents, what
77
+ * data will be deleted. Used by the uninstall typed-confirmation modal.
78
+ */
79
+ previewUninstall: proc({
80
+ operationType: "query",
81
+ userType: "user",
82
+ access: [pluginManagerAccess.uninstall],
83
+ })
84
+ .input(z.object({ pluginName: z.string().min(1) }))
85
+ .output(uninstallPreviewSchema),
86
+
87
+ /**
88
+ * Uninstall a plugin (and its bundle siblings). Originator owns destructive
89
+ * cleanup; receiving instances do in-process teardown only.
90
+ */
91
+ uninstall: proc({
92
+ operationType: "mutation",
93
+ userType: "user",
94
+ access: [pluginManagerAccess.uninstall],
95
+ })
96
+ .input(
97
+ z.object({
98
+ pluginName: z.string().min(1),
99
+ deleteSchema: z.boolean(),
100
+ deleteConfigs: z.boolean(),
101
+ cascade: z.boolean(),
102
+ confirm: uninstallConfirmTokenSchema,
103
+ }),
104
+ )
105
+ .output(
106
+ z.object({
107
+ success: z.boolean(),
108
+ uninstalledPackages: z.array(z.string()),
109
+ }),
110
+ ),
111
+
112
+ /**
113
+ * Audit/error event log. Used by the admin Events page to surface partial
114
+ * failures (originator died mid-install, instance failed in-process load,
115
+ * etc.) for manual remediation.
116
+ */
117
+ events: proc({
118
+ operationType: "query",
119
+ userType: "user",
120
+ access: [pluginManagerAccess.view],
121
+ })
122
+ .input(
123
+ z.object({
124
+ pluginName: z.string().optional(),
125
+ limit: z.number().int().positive().max(500).default(100),
126
+ }),
127
+ )
128
+ .output(z.object({ events: z.array(installEventSchema) })),
129
+ };
130
+
131
+ export type PluginManagerContract = typeof pluginManagerContract;
132
+
133
+ export const PluginManagerApi = createClientDefinition(
134
+ pluginManagerContract,
135
+ pluginMetadata,
136
+ );
package/src/schemas.ts ADDED
@@ -0,0 +1,123 @@
1
+ import { z } from "zod";
2
+ import {
3
+ pluginSourceSchema,
4
+ installPackageMetadataSchema,
5
+ pluginCheckstackBlockSchema,
6
+ pluginPackageTypeSchema,
7
+ } from "@checkstack/common";
8
+
9
+ // ─────────────────────────────────────────────────────────────────────────────
10
+ // Compatibility issue surfaced by `previewInstall` / re-validated on `install`.
11
+ // ─────────────────────────────────────────────────────────────────────────────
12
+
13
+ export const compatibilityIssueSchema = z.object({
14
+ pluginName: z.string(),
15
+ kind: z.enum([
16
+ "missing-dependency",
17
+ "version-mismatch",
18
+ "platform-version-mismatch",
19
+ ]),
20
+ dependency: z.string(),
21
+ declared: z.string(),
22
+ actual: z.string().optional(),
23
+ message: z.string(),
24
+ });
25
+ export type CompatibilityIssue = z.infer<typeof compatibilityIssueSchema>;
26
+
27
+ // ─────────────────────────────────────────────────────────────────────────────
28
+ // Preview-install / preview-uninstall result shapes.
29
+ // ─────────────────────────────────────────────────────────────────────────────
30
+
31
+ export const installPreviewSchema = z.object({
32
+ /** Validated package.json of the primary package. */
33
+ primary: installPackageMetadataSchema,
34
+ /** Validated package.json for every package in the bundle (including primary). */
35
+ packages: z.array(installPackageMetadataSchema),
36
+ /** Compatibility issues — non-empty means install will be rejected. */
37
+ compatibilityIssues: z.array(compatibilityIssueSchema),
38
+ /** Aggregate tarball size in bytes (sum of all packages in the bundle). */
39
+ totalSizeBytes: z.number().int().nonnegative(),
40
+ /** True when at least one package has `checkstack.allowInstallScripts: true`. */
41
+ hasInstallScripts: z.boolean(),
42
+ });
43
+ export type InstallPreview = z.infer<typeof installPreviewSchema>;
44
+
45
+ export const uninstallPreviewSchema = z.object({
46
+ pluginName: z.string(),
47
+ /** All sibling packages that share this plugin's bundleId. */
48
+ siblings: z.array(z.string()),
49
+ /** Other plugins (NOT in this bundle) that depend on this plugin. */
50
+ dependents: z.array(z.string()),
51
+ /** Will this drop the plugin's Postgres schema? */
52
+ schemasToDrop: z.array(z.string()),
53
+ /** How many plugin_configs rows will be deleted? */
54
+ pluginConfigCount: z.number().int().nonnegative(),
55
+ });
56
+ export type UninstallPreview = z.infer<typeof uninstallPreviewSchema>;
57
+
58
+ // ─────────────────────────────────────────────────────────────────────────────
59
+ // Installed-plugin row returned from `list`.
60
+ // ─────────────────────────────────────────────────────────────────────────────
61
+
62
+ export const installedPluginSchema = z.object({
63
+ name: z.string(),
64
+ version: z.string(),
65
+ type: pluginPackageTypeSchema,
66
+ enabled: z.boolean(),
67
+ isUninstallable: z.boolean(),
68
+ isPrimary: z.boolean(),
69
+ bundleId: z.string().nullable(),
70
+ source: pluginSourceSchema.nullable(),
71
+ metadata: z
72
+ .object({
73
+ description: z.string().optional(),
74
+ author: z.unknown().optional(),
75
+ license: z.string().optional(),
76
+ homepage: z.string().optional(),
77
+ repository: z.unknown().optional(),
78
+ checkstack: pluginCheckstackBlockSchema.partial().optional(),
79
+ })
80
+ .partial()
81
+ .optional(),
82
+ });
83
+ export type InstalledPlugin = z.infer<typeof installedPluginSchema>;
84
+
85
+ // ─────────────────────────────────────────────────────────────────────────────
86
+ // Audit/error event row.
87
+ // ─────────────────────────────────────────────────────────────────────────────
88
+
89
+ export const installEventActionEnum = z.enum(["install", "uninstall"]);
90
+ export type InstallEventAction = z.infer<typeof installEventActionEnum>;
91
+
92
+ export const installEventPhaseEnum = z.enum([
93
+ "validate",
94
+ "persist",
95
+ "broadcast",
96
+ "in-process-load",
97
+ "in-process-unload",
98
+ "destructive-cleanup",
99
+ "audit",
100
+ ]);
101
+ export type InstallEventPhase = z.infer<typeof installEventPhaseEnum>;
102
+
103
+ export const installEventStatusEnum = z.enum([
104
+ "started",
105
+ "succeeded",
106
+ "failed",
107
+ ]);
108
+ export type InstallEventStatus = z.infer<typeof installEventStatusEnum>;
109
+
110
+ export const installEventSchema = z.object({
111
+ id: z.string(),
112
+ pluginName: z.string().nullable(),
113
+ bundleId: z.string().nullable(),
114
+ action: installEventActionEnum,
115
+ phase: installEventPhaseEnum,
116
+ status: installEventStatusEnum,
117
+ source: pluginSourceSchema.nullable(),
118
+ error: z.string().nullable(),
119
+ instanceId: z.string(),
120
+ userId: z.string().nullable(),
121
+ createdAt: z.string(),
122
+ });
123
+ export type InstallEvent = z.infer<typeof installEventSchema>;
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@checkstack/tsconfig/common.json",
3
+ "include": [
4
+ "src"
5
+ ],
6
+ "references": [
7
+ {
8
+ "path": "../common"
9
+ }
10
+ ]
11
+ }