@checkstack/common 0.6.5 → 0.8.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,115 @@
1
1
  # @checkstack/common
2
2
 
3
+ ## 0.8.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
+ ## 0.7.0
104
+
105
+ ### Minor Changes
106
+
107
+ - 8d1ef12: Phase 2 of anomaly detection: trend drift detection.
108
+
109
+ The background baseline analyzer now computes a linear regression slope across each field's chronologically-ordered history and runs a `detectDrift` evaluator that catches gradual "creeping degradation" never reaching the 3σ spike threshold. Drifts share the same `anomalies` table as spike anomalies via a new `kind` column (`spike` | `drift`, default `spike`); the existing suspicious → anomaly → recovered lifecycle is reused, ticking at the analyzer's hourly cadence with a default 2-run confirmation window.
110
+
111
+ User-facing additions: a Trend Drift toggle and threshold slider on both the template and assignment anomaly settings panels (with per-field overrides), drift rows in the System Anomaly widget, dashed regression-line overlays on the auto-generated line charts, and a new `ANOMALY_TREND_DETECTED` signal for live UI updates. Plugin authors can disable drift per chartable field via `x-anomaly-drift-enabled: false` or tighten/loosen it via `x-anomaly-drift-threshold`.
112
+
3
113
  ## 0.6.5
4
114
 
5
115
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@checkstack/common",
3
- "version": "0.6.5",
3
+ "version": "0.8.0",
4
+ "license": "Elastic-2.0",
4
5
  "type": "module",
5
6
  "main": "./src/index.ts",
6
7
  "types": "./src/index.ts",
@@ -18,11 +19,11 @@
18
19
  },
19
20
  "devDependencies": {
20
21
  "typescript": "^5.7.2",
21
- "@checkstack/tsconfig": "0.0.5",
22
+ "@checkstack/tsconfig": "0.0.6",
22
23
  "@checkstack/scripts": "0.1.2"
23
24
  },
24
25
  "scripts": {
25
- "typecheck": "tsc --noEmit",
26
+ "typecheck": "tsgo -b",
26
27
  "lint": "bun run lint:code",
27
28
  "lint:code": "eslint . --max-warnings 0"
28
29
  },
@@ -23,12 +23,9 @@ export type ChartType =
23
23
  | "status";
24
24
 
25
25
  /**
26
- * Metadata type for health check result schemas.
27
- * Provides autocompletion for chart-related metadata on result fields.
26
+ * Base metadata for all health check result schema fields.
28
27
  */
29
- export interface HealthResultMeta {
30
- /** The type of chart to render for this field */
31
- "x-chart-type"?: ChartType;
28
+ export interface BaseHealthResultMeta {
32
29
  /** Human-readable label for the chart (defaults to field name) */
33
30
  "x-chart-label"?: string;
34
31
  /** Unit suffix for values (e.g., 'ms', '%', 'req/s') */
@@ -40,4 +37,65 @@ export interface HealthResultMeta {
40
37
  * Ephemeral fields are stripped before storing results in the database.
41
38
  */
42
39
  "x-ephemeral"?: boolean;
40
+ /**
41
+ * Sensitivity multiplier for this field (default: 1.0).
42
+ * Higher values = fewer alerts (wider threshold).
43
+ * Lower values = more alerts (tighter threshold).
44
+ * Applied as: threshold = μ ± (3σ × sensitivity)
45
+ */
46
+ "x-anomaly-sensitivity"?: number;
47
+ /**
48
+ * Override the default confirmation window for this field.
49
+ * Number of consecutive anomalous data points required before an alert is raised.
50
+ */
51
+ "x-anomaly-confirmation-window"?: number;
52
+ /**
53
+ * Enable trend drift detection for this field. Default true (when anomaly
54
+ * detection is enabled). Set false to suppress drift alerts but keep spike
55
+ * detection active.
56
+ */
57
+ "x-anomaly-drift-enabled"?: boolean;
58
+ /**
59
+ * Sigma multiplier on the drift trigger band (default 2). Drift fires when
60
+ * |slope × sampleCount| > threshold × σ × sensitivity.
61
+ */
62
+ "x-anomaly-drift-threshold"?: number;
63
+ }
64
+
65
+ /**
66
+ * Metadata for a field that exposes a chart AND has anomaly detection enabled.
67
+ */
68
+ export interface ChartMetaAnomalyEnabled extends BaseHealthResultMeta {
69
+ "x-chart-type": ChartType;
70
+ "x-anomaly-enabled": true;
71
+ "x-anomaly-direction": "higher-is-better" | "lower-is-better" | "deviation" | "dominance";
43
72
  }
73
+
74
+ /**
75
+ * Metadata for a field that exposes a chart but explicitly disables anomaly detection.
76
+ */
77
+ export interface ChartMetaAnomalyDisabled extends BaseHealthResultMeta {
78
+ "x-chart-type": ChartType;
79
+ "x-anomaly-enabled": false;
80
+ "x-anomaly-direction"?: never;
81
+ }
82
+
83
+ /**
84
+ * Metadata for a field that does NOT expose a chart.
85
+ */
86
+ export interface NonChartMeta extends BaseHealthResultMeta {
87
+ "x-chart-type"?: never;
88
+ "x-anomaly-enabled"?: never;
89
+ "x-anomaly-direction"?: never;
90
+ }
91
+
92
+ /**
93
+ * Metadata type for health check result schemas.
94
+ * Provides autocompletion and enforces that ANY field exposing a chart
95
+ * MUST explicitly define its anomaly behavior.
96
+ */
97
+ export type HealthResultMeta =
98
+ | ChartMetaAnomalyEnabled
99
+ | ChartMetaAnomalyDisabled
100
+ | NonChartMeta;
101
+
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./types";
2
2
  export * from "./pagination";
3
3
  export * from "./routes";
4
4
  export * from "./plugin-metadata";
5
+ export * from "./plugin-source";
5
6
  export * from "./client-definition";
6
7
  export * from "./access-utils";
7
8
  export * from "./icons";
@@ -1,3 +1,5 @@
1
+ import { z } from "zod";
2
+
1
3
  /**
2
4
  * Plugin metadata interface for backend plugins.
3
5
  *
@@ -26,3 +28,103 @@ export interface PluginMetadata {
26
28
  export function definePluginMetadata<T extends PluginMetadata>(metadata: T): T {
27
29
  return metadata;
28
30
  }
31
+
32
+ // ─────────────────────────────────────────────────────────────────────────────
33
+ // Install-time metadata (validated when a plugin is installed at runtime)
34
+ // ─────────────────────────────────────────────────────────────────────────────
35
+
36
+ export const pluginPackageTypeSchema = z.enum(["backend", "frontend", "common"]);
37
+ export type PluginPackageType = z.infer<typeof pluginPackageTypeSchema>;
38
+
39
+ /**
40
+ * Author shape — matches standard package.json `author` / `contributors`
41
+ * (string OR object form).
42
+ */
43
+ export const pluginAuthorSchema = z.union([
44
+ z.string().min(1),
45
+ z.object({
46
+ name: z.string().min(1),
47
+ email: z.string().email().optional(),
48
+ url: z.string().url().optional(),
49
+ }),
50
+ ]);
51
+ export type PluginAuthor = z.infer<typeof pluginAuthorSchema>;
52
+
53
+ /**
54
+ * `package.json#checkstack` block schema.
55
+ *
56
+ * Required:
57
+ * - `type`: which kind of package this is.
58
+ * - `pluginId`: the runtime plugin id (must match the source const).
59
+ *
60
+ * Optional:
61
+ * - `bundle`: list of sibling package names that must install/uninstall together.
62
+ * Set on the *primary* package only.
63
+ * - `usageInstructions`: markdown shown in the install UI.
64
+ * - `allowInstallScripts`: opt in to running `postinstall` etc. for this plugin's
65
+ * `bun install`. Default false (we pass `--ignore-scripts`).
66
+ */
67
+ export const pluginCheckstackBlockSchema = z.object({
68
+ type: pluginPackageTypeSchema,
69
+ pluginId: z.string().min(1).optional(),
70
+ bundle: z.array(z.string().min(1)).optional(),
71
+ usageInstructions: z.string().optional(),
72
+ allowInstallScripts: z.boolean().optional(),
73
+ });
74
+ export type PluginCheckstackBlock = z.infer<typeof pluginCheckstackBlockSchema>;
75
+
76
+ /**
77
+ * Schema applied to the *full* package.json of a plugin at install time.
78
+ *
79
+ * We re-use standard package.json fields (name, version, description, author,
80
+ * license, homepage, repository) and only require what's strictly necessary
81
+ * for displaying + validating an installable plugin. Compatibility is *not*
82
+ * declared explicitly — it's derived from the `dependencies` section at
83
+ * install time (semver.satisfies against the platform's loaded
84
+ * `@checkstack/*` package versions).
85
+ */
86
+ export const installPackageMetadataSchema = z.object({
87
+ name: z.string().min(1, "package.json `name` is required"),
88
+ version: z.string().min(1, "package.json `version` is required"),
89
+ description: z.string().min(1, "package.json `description` is required"),
90
+ author: pluginAuthorSchema,
91
+ contributors: z.array(pluginAuthorSchema).optional(),
92
+ license: z.string().min(1, "package.json `license` is required"),
93
+ homepage: z.string().url().optional(),
94
+ repository: z
95
+ .union([
96
+ z.string(),
97
+ z.object({
98
+ type: z.string().optional(),
99
+ url: z.string(),
100
+ }),
101
+ ])
102
+ .optional(),
103
+ dependencies: z.record(z.string(), z.string()).optional(),
104
+ peerDependencies: z.record(z.string(), z.string()).optional(),
105
+ checkstack: pluginCheckstackBlockSchema,
106
+ });
107
+ export type InstallPackageMetadata = z.infer<typeof installPackageMetadataSchema>;
108
+
109
+ /**
110
+ * Bundle manifest written into a `--bundle`-mode tarball.
111
+ *
112
+ * Structure:
113
+ * bundle.tgz
114
+ * bundle.json ← this manifest
115
+ * packages/
116
+ * <pkg-1>-<version>.tgz
117
+ * <pkg-2>-<version>.tgz
118
+ */
119
+ export const pluginBundleManifestSchema = z.object({
120
+ bundleVersion: z.literal(1),
121
+ primary: z.string().min(1),
122
+ packages: z.array(
123
+ z.object({
124
+ name: z.string().min(1),
125
+ version: z.string().min(1),
126
+ tarball: z.string().min(1), // path inside the outer tarball
127
+ }),
128
+ ),
129
+ });
130
+ export type PluginBundleManifest = z.infer<typeof pluginBundleManifestSchema>;
@@ -0,0 +1,73 @@
1
+ import { z } from "zod";
2
+
3
+ // ─────────────────────────────────────────────────────────────────────────────
4
+ // PluginSource — discriminated union describing where a plugin came from.
5
+ // One installer per `type`. Persisted on the `plugins` row so fresh-instance
6
+ // bootstrap and reinstall can recreate the artifact from the same source.
7
+ //
8
+ // Lives in `@checkstack/common` (not `backend-api`) so it can be referenced
9
+ // from contracts (which must remain importable from frontend & common
10
+ // packages).
11
+ // ─────────────────────────────────────────────────────────────────────────────
12
+
13
+ export const npmPluginSourceSchema = z.object({
14
+ type: z.literal("npm"),
15
+ packageName: z.string().min(1),
16
+ version: z.string().optional(),
17
+ registry: z.string().url().optional(),
18
+ });
19
+ export type NpmPluginSource = z.infer<typeof npmPluginSourceSchema>;
20
+
21
+ export const tarballPluginSourceSchema = z.object({
22
+ type: z.literal("tarball"),
23
+ /**
24
+ * The plugin_artifacts row id. The tarball bytes themselves live in
25
+ * Postgres — only the artifact reference is stored on the `plugins` row.
26
+ * On fresh-instance bootstrap, this is what's used to re-fetch the bytes.
27
+ */
28
+ artifactId: z.string().min(1),
29
+ /** Original filename for display in the UI. */
30
+ filename: z.string().optional(),
31
+ });
32
+ export type TarballPluginSource = z.infer<typeof tarballPluginSourceSchema>;
33
+
34
+ export const githubPluginSourceSchema = z.object({
35
+ type: z.literal("github"),
36
+ owner: z.string().min(1),
37
+ repo: z.string().min(1),
38
+ tag: z.string().min(1),
39
+ /**
40
+ * Optional explicit asset filename. When omitted, the installer picks the
41
+ * single `.tgz` asset on the release (and errors if there are zero or many).
42
+ */
43
+ assetName: z.string().optional(),
44
+ /**
45
+ * Optional API base URL for GitHub Enterprise installs (e.g.
46
+ * `https://github.example.com/api/v3`). When omitted, the public
47
+ * `https://api.github.com` endpoint is used. Asset download URLs are
48
+ * always taken from the release response, so they automatically point
49
+ * at the same host as the API.
50
+ */
51
+ apiBaseUrl: z.string().url().optional(),
52
+ /**
53
+ * Optional name of an env var holding a Personal Access Token. Defaults
54
+ * to `GITHUB_TOKEN`. Useful when the platform needs to talk to several
55
+ * different GitHub instances with different tokens.
56
+ */
57
+ tokenEnvVar: z.string().optional(),
58
+ });
59
+ export type GithubPluginSource = z.infer<typeof githubPluginSourceSchema>;
60
+
61
+ export const catalogPluginSourceSchema = z.object({
62
+ type: z.literal("catalog"),
63
+ catalogId: z.string().min(1),
64
+ });
65
+ export type CatalogPluginSource = z.infer<typeof catalogPluginSourceSchema>;
66
+
67
+ export const pluginSourceSchema = z.discriminatedUnion("type", [
68
+ npmPluginSourceSchema,
69
+ tarballPluginSourceSchema,
70
+ githubPluginSourceSchema,
71
+ catalogPluginSourceSchema,
72
+ ]);
73
+ export type PluginSource = z.infer<typeof pluginSourceSchema>;
package/tsconfig.json CHANGED
@@ -3,4 +3,4 @@
3
3
  "include": [
4
4
  "src"
5
5
  ]
6
- }
6
+ }