@checkstack/common 0.7.0 → 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.
- package/CHANGELOG.md +112 -0
- package/package.json +5 -4
- package/src/chart-types.ts +65 -7
- package/src/index.ts +1 -0
- package/src/plugin-metadata.ts +102 -0
- package/src/plugin-source.ts +73 -0
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,117 @@
|
|
|
1
1
|
# @checkstack/common
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 42abfff: Add practical-significance floors to anomaly detection.
|
|
8
|
+
|
|
9
|
+
Two new schema annotations — `x-anomaly-min-absolute-delta` and `x-anomaly-min-relative-delta` — let plugin authors and operators suppress alerts whose statistical deviation is large but practical impact is negligible. Both floors must clear in addition to the existing μ ± Nσ trigger; defaults are 0 (disabled) so existing behaviour is unchanged.
|
|
10
|
+
|
|
11
|
+
This is the fix for cases like a 6 ms latency baseline whose σ ≈ 1 ms causes routine 20 ms blips to fire as anomalies despite Δ=14 ms being operationally irrelevant. With `min-absolute-delta: 50` and `min-relative-delta: 0.5`, those blips stay silent while a 6 ms → 200 ms spike still fires.
|
|
12
|
+
|
|
13
|
+
Built-in plugins ship with sensible defaults applied to every per-run field: 50 ms + 50 % for ms-unit fields, 5 percentage points for `%`-unit fields, 1 + 25 % for counter fields, 1 GB + 5 % for disk fields, 50 MB + 10 % for memory fields, 1 day for TLS expiry, 0.5 + 25 % for load average, 1 + 5 % for Minecraft TPS. Operators can override per-system or per-field via the assignment UI.
|
|
14
|
+
|
|
15
|
+
## 0.8.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 50e5f5f: Runtime plugin system: install + uninstall plugins from npm, GitHub releases
|
|
20
|
+
(including private GitHub Enterprise instances), or tarball uploads at
|
|
21
|
+
runtime, with multi-package bundles, dependency-derived compatibility checks,
|
|
22
|
+
multi-instance coordination via a Postgres artifact store, and
|
|
23
|
+
single-coordinator destructive cleanup.
|
|
24
|
+
|
|
25
|
+
Highlights:
|
|
26
|
+
|
|
27
|
+
- New `PluginSource` discriminated union and `PluginInstaller` /
|
|
28
|
+
`PluginInstallerRegistry` interfaces in `@checkstack/backend-api`. The
|
|
29
|
+
GitHub variant accepts an optional `apiBaseUrl` so deployments backed by
|
|
30
|
+
GitHub Enterprise can install from `https://ghe.example.com/api/v3`
|
|
31
|
+
instead of `api.github.com`.
|
|
32
|
+
- New `installPackageMetadataSchema` (Zod) in `@checkstack/common` validates
|
|
33
|
+
every plugin's `package.json` at install time. Required fields: `name`,
|
|
34
|
+
`version`, `description`, `author`, `license`, `checkstack.type`,
|
|
35
|
+
`checkstack.pluginId`. Optional: `checkstack.bundle`,
|
|
36
|
+
`checkstack.usageInstructions`, `checkstack.allowInstallScripts`.
|
|
37
|
+
- New `pluginManagerContract` in `@checkstack/pluginmanager-common` with
|
|
38
|
+
`list`, `previewInstall`, `install`, `previewUninstall`, `uninstall`, and
|
|
39
|
+
`events` procedures.
|
|
40
|
+
- New `@checkstack/pluginmanager-frontend` admin UI: installed-plugins list
|
|
41
|
+
with per-row uninstall (typed-confirmation modal, schema/configs/cascade
|
|
42
|
+
toggles), install page with NPM / Tarball Upload / GitHub Release tabs
|
|
43
|
+
(Catalog tab disabled — coming soon), and an events page surfacing the
|
|
44
|
+
install/uninstall audit log.
|
|
45
|
+
- New `bunx @checkstack/scripts plugin-pack` CLI for plugin authors —
|
|
46
|
+
per-package mode produces an npm-shaped tarball; `--bundle` mode produces
|
|
47
|
+
an outer tarball containing every sibling declared in
|
|
48
|
+
`package.json#checkstack.bundle`. Published to npm so external authors
|
|
49
|
+
can `bunx` it directly without a workspace checkout.
|
|
50
|
+
- Compatibility derived from `package.json#dependencies` ranges
|
|
51
|
+
(`semver.satisfies` against the platform's loaded `@checkstack/*`
|
|
52
|
+
versions) — no separate `compatibility` field.
|
|
53
|
+
- Multi-instance: originator persists artifacts + `plugins` rows + broadcasts
|
|
54
|
+
install/uninstall; receiving instances do in-process register/unregister
|
|
55
|
+
only. Destructive ops (drop schema, delete plugin_configs, delete
|
|
56
|
+
artifacts, delete `plugins` rows) run exactly once on the originator.
|
|
57
|
+
- Fresh-instance bootstrap: `loadPlugins()` hydrates any
|
|
58
|
+
`is_uninstallable=true` plugin missing from `node_modules` from the
|
|
59
|
+
artifact store before normal Phase 1 register.
|
|
60
|
+
- New schema: `plugin_artifacts` (tarball storage), `plugin_install_events`
|
|
61
|
+
(audit/error log). `plugins` extended with `version`, `metadata`,
|
|
62
|
+
`source`, `bundle_id`, `is_primary`. Local plugin sync now writes
|
|
63
|
+
`version` from each plugin's `package.json` so the admin UI shows real
|
|
64
|
+
versions instead of `—`.
|
|
65
|
+
- Tarball-upload endpoint (`POST /api/pluginmanager/upload-tarball`) for
|
|
66
|
+
the install UI; access-gated by `pluginmanager.plugin.manage`.
|
|
67
|
+
- Plugin Manager menu link added to the user menu (main grid, alongside
|
|
68
|
+
Profile / Notification Settings / etc.).
|
|
69
|
+
|
|
70
|
+
Cross-cutting changes:
|
|
71
|
+
|
|
72
|
+
- Backend request/response logging now flows through `rootLogger` (winston)
|
|
73
|
+
instead of `hono/logger`. 5xx responses include the response body inline
|
|
74
|
+
so swallowed early-return errors are visible in the log.
|
|
75
|
+
- The `/api/:pluginId/*` dispatcher now logs which core service is missing
|
|
76
|
+
or which `pluginId` had no metadata when it 500s.
|
|
77
|
+
- New `registerCorePluginMetadata` on `PluginManager` for core routers
|
|
78
|
+
(like the plugin manager itself) that need their metadata visible to the
|
|
79
|
+
RPC dispatcher without going through the full plugin lifecycle.
|
|
80
|
+
- ESLint: `unicorn/no-null` is now disabled globally. Drizzle distinguishes
|
|
81
|
+
between `null` (writes a real SQL NULL) and `undefined` (skip the column
|
|
82
|
+
on insert), so treating them as interchangeable produced latent bugs at
|
|
83
|
+
the persistence boundary. The bulk of the patch-bumped packages above
|
|
84
|
+
reflect lint-fix touches that landed when this rule was relaxed.
|
|
85
|
+
- Workspace-wide license normalization to `Elastic-2.0` (matches
|
|
86
|
+
`LICENSE.md`). Every `package.json` in the workspace now declares the
|
|
87
|
+
same SPDX identifier; the patch bumps capture this.
|
|
88
|
+
|
|
89
|
+
Plugin packages (every `plugins/*`): added a `pack` npm script
|
|
90
|
+
(`bunx @checkstack/scripts plugin-pack`), mirrored each plugin's
|
|
91
|
+
`pluginId` from `plugin-metadata.ts` into `package.json#checkstack.pluginId`
|
|
92
|
+
so install-time validation passes, stubbed any missing required metadata
|
|
93
|
+
fields (`description`, `author`, `license`), and added
|
|
94
|
+
`checkstack.bundle` to multi-package plugin primaries (telegram, rcon, ssh,
|
|
95
|
+
jira, queue-bullmq, queue-memory, cache-memory).
|
|
96
|
+
|
|
97
|
+
Breaking changes:
|
|
98
|
+
|
|
99
|
+
- The legacy single-method `PluginInstaller` interface (`install(packageName)`)
|
|
100
|
+
is removed. Callers must use `coreServices.pluginInstallerRegistry`.
|
|
101
|
+
- The old `pluginAdminContract` and `createPluginAdminRouter` are removed.
|
|
102
|
+
Replaced by `pluginManagerContract` in `@checkstack/pluginmanager-common`
|
|
103
|
+
and `createPluginManagerRouter` in `core/backend`.
|
|
104
|
+
- `@checkstack/test-utils-backend` no longer exports
|
|
105
|
+
`createMockPluginInstaller` / `MockPluginInstaller` (the legacy interface
|
|
106
|
+
it shimmed is gone).
|
|
107
|
+
|
|
108
|
+
Note: bumps are limited to `minor` (for packages with new public API
|
|
109
|
+
surface) and `patch` (for downstream consumers, license normalization,
|
|
110
|
+
and lint fixes). No `major` bumps despite the `PluginInstaller` removal —
|
|
111
|
+
the legacy interface had no third-party consumers in the wild before this
|
|
112
|
+
runtime plugin system landed, and the contract surface is the same shape
|
|
113
|
+
modulo the rename.
|
|
114
|
+
|
|
3
115
|
## 0.7.0
|
|
4
116
|
|
|
5
117
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.
|
|
22
|
-
"@checkstack/scripts": "0.
|
|
22
|
+
"@checkstack/tsconfig": "0.0.7",
|
|
23
|
+
"@checkstack/scripts": "0.3.0"
|
|
23
24
|
},
|
|
24
25
|
"scripts": {
|
|
25
|
-
"typecheck": "
|
|
26
|
+
"typecheck": "tsgo -b",
|
|
26
27
|
"lint": "bun run lint:code",
|
|
27
28
|
"lint:code": "eslint . --max-warnings 0"
|
|
28
29
|
},
|
package/src/chart-types.ts
CHANGED
|
@@ -22,6 +22,18 @@ export type ChartType =
|
|
|
22
22
|
| "text"
|
|
23
23
|
| "status";
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Numeric anomaly directions — these operate on a μ ± Nσ statistical band
|
|
27
|
+
* over a continuous metric, so practical-significance floors apply.
|
|
28
|
+
*/
|
|
29
|
+
export type NumericAnomalyDirection =
|
|
30
|
+
| "higher-is-better"
|
|
31
|
+
| "lower-is-better"
|
|
32
|
+
| "deviation";
|
|
33
|
+
|
|
34
|
+
/** Categorical anomaly direction — fires on dominance flips, no σ band. */
|
|
35
|
+
export type CategoricalAnomalyDirection = "dominance";
|
|
36
|
+
|
|
25
37
|
/**
|
|
26
38
|
* Base metadata for all health check result schema fields.
|
|
27
39
|
*/
|
|
@@ -63,14 +75,56 @@ export interface BaseHealthResultMeta {
|
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
/**
|
|
66
|
-
* Metadata for a field
|
|
78
|
+
* Metadata for a chartable field with numeric anomaly detection.
|
|
79
|
+
* Carries the practical-significance floors (`x-anomaly-min-*-delta`)
|
|
80
|
+
* because they only make sense against a μ ± Nσ band.
|
|
81
|
+
*/
|
|
82
|
+
export interface ChartMetaAnomalyNumeric extends BaseHealthResultMeta {
|
|
83
|
+
"x-chart-type": ChartType;
|
|
84
|
+
"x-anomaly-enabled": true;
|
|
85
|
+
"x-anomaly-direction": NumericAnomalyDirection;
|
|
86
|
+
/**
|
|
87
|
+
* Practical-significance floor on absolute deviation. Default 0 (disabled).
|
|
88
|
+
* An anomaly only fires when |value − μ| ≥ this floor — even if the
|
|
89
|
+
* statistical trigger (μ ± Nσ) is exceeded. Use to suppress alerts on
|
|
90
|
+
* statistically-unusual but operationally-irrelevant swings on
|
|
91
|
+
* low-baseline metrics (e.g. 6 ms → 20 ms latency).
|
|
92
|
+
* Same field unit as the metric itself.
|
|
93
|
+
*/
|
|
94
|
+
"x-anomaly-min-absolute-delta"?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Practical-significance floor on relative deviation. Default 0 (disabled).
|
|
97
|
+
* An anomaly only fires when |value − μ| / max(|μ|, ε) ≥ this floor — even
|
|
98
|
+
* if the statistical trigger is exceeded. Expressed as a fraction
|
|
99
|
+
* (e.g. 0.5 = 50%). Use to suppress alerts whose proportional change is
|
|
100
|
+
* small on high-magnitude metrics.
|
|
101
|
+
*/
|
|
102
|
+
"x-anomaly-min-relative-delta"?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Metadata for a chartable field with categorical (dominance) anomaly
|
|
107
|
+
* detection. Practical-significance floors are deliberately disallowed
|
|
108
|
+
* because they have no meaning against a categorical baseline — there's
|
|
109
|
+
* no μ to subtract from.
|
|
67
110
|
*/
|
|
68
|
-
export interface
|
|
111
|
+
export interface ChartMetaAnomalyCategorical extends BaseHealthResultMeta {
|
|
69
112
|
"x-chart-type": ChartType;
|
|
70
113
|
"x-anomaly-enabled": true;
|
|
71
|
-
"x-anomaly-direction":
|
|
114
|
+
"x-anomaly-direction": CategoricalAnomalyDirection;
|
|
115
|
+
"x-anomaly-min-absolute-delta"?: never;
|
|
116
|
+
"x-anomaly-min-relative-delta"?: never;
|
|
72
117
|
}
|
|
73
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Union of the two anomaly-enabled variants. Kept for back-compat with
|
|
121
|
+
* existing callers — new code should narrow against the discriminated
|
|
122
|
+
* union directly via `x-anomaly-direction`.
|
|
123
|
+
*/
|
|
124
|
+
export type ChartMetaAnomalyEnabled =
|
|
125
|
+
| ChartMetaAnomalyNumeric
|
|
126
|
+
| ChartMetaAnomalyCategorical;
|
|
127
|
+
|
|
74
128
|
/**
|
|
75
129
|
* Metadata for a field that exposes a chart but explicitly disables anomaly detection.
|
|
76
130
|
*/
|
|
@@ -78,6 +132,8 @@ export interface ChartMetaAnomalyDisabled extends BaseHealthResultMeta {
|
|
|
78
132
|
"x-chart-type": ChartType;
|
|
79
133
|
"x-anomaly-enabled": false;
|
|
80
134
|
"x-anomaly-direction"?: never;
|
|
135
|
+
"x-anomaly-min-absolute-delta"?: never;
|
|
136
|
+
"x-anomaly-min-relative-delta"?: never;
|
|
81
137
|
}
|
|
82
138
|
|
|
83
139
|
/**
|
|
@@ -87,6 +143,8 @@ export interface NonChartMeta extends BaseHealthResultMeta {
|
|
|
87
143
|
"x-chart-type"?: never;
|
|
88
144
|
"x-anomaly-enabled"?: never;
|
|
89
145
|
"x-anomaly-direction"?: never;
|
|
146
|
+
"x-anomaly-min-absolute-delta"?: never;
|
|
147
|
+
"x-anomaly-min-relative-delta"?: never;
|
|
90
148
|
}
|
|
91
149
|
|
|
92
150
|
/**
|
|
@@ -94,8 +152,8 @@ export interface NonChartMeta extends BaseHealthResultMeta {
|
|
|
94
152
|
* Provides autocompletion and enforces that ANY field exposing a chart
|
|
95
153
|
* MUST explicitly define its anomaly behavior.
|
|
96
154
|
*/
|
|
97
|
-
export type HealthResultMeta =
|
|
98
|
-
|
|
|
99
|
-
|
|
|
155
|
+
export type HealthResultMeta =
|
|
156
|
+
| ChartMetaAnomalyNumeric
|
|
157
|
+
| ChartMetaAnomalyCategorical
|
|
158
|
+
| ChartMetaAnomalyDisabled
|
|
100
159
|
| NonChartMeta;
|
|
101
|
-
|
package/src/index.ts
CHANGED
package/src/plugin-metadata.ts
CHANGED
|
@@ -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