@checkstack/gitops-common 0.2.2 → 0.4.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,92 @@
1
1
  # @checkstack/gitops-common
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9016526: Add a `/rest/:pluginId/*` HTTP mount that serves every plugin's oRPC contract
8
+ through the REST/OpenAPI shape described by `/api/openapi.json`. Queries are
9
+ `GET` with query parameters, mutations are `POST` with the input as the raw
10
+ JSON body. The existing `/api/:pluginId/*` mount continues to serve oRPC's
11
+ native wire protocol unchanged, so existing clients are not affected.
12
+
13
+ The OpenAPI spec at `/api/openapi.json` now reflects the real mount: every
14
+ `paths` entry is prefixed with `/rest` instead of `/api`.
15
+
16
+ Also fixes a SPA-fallback bug: the backend's `/api-docs` route previously
17
+ returned 404 on production deployments because the static-file middleware
18
+ skipped any path starting with `/api`, capturing `/api-docs` along with real
19
+ API routes. The skip now requires a trailing slash (`/api/`, `/rest/`).
20
+
21
+ Required access rules are now visible in the API Docs UI. The OpenAPI spec
22
+ generator was reading a non-existent `accessRules` field on procedure
23
+ metadata; the real field is `access: AccessRule[]`. Each procedure's access
24
+ rules are now flattened to fully-qualified IDs (e.g. `catalog.system.read`)
25
+ and emitted under `x-orpc-meta.accessRules`, which the existing
26
+ `Required Access Rules` section in the docs UI already knew how to render.
27
+
28
+ The API Docs schema renderer now handles record types (zod `z.record`),
29
+ `$ref`s into `components.schemas`, `oneOf`/`anyOf`/`allOf`, nullable union
30
+ types (`type: ["string", "null"]`), and `format` qualifiers. Previously
31
+ record outputs like `{ statuses: object }` masked the actual value type;
32
+ they now render as `{ [key]: <ResolvedType> { ... } }` with the inner
33
+ schema expanded, capped at 12 levels with cycle detection.
34
+
35
+ **REST method conventions.** `proc()` now defaults to `GET` for queries and
36
+ `POST` for mutations on the `/rest` mount, using bracket-notation query
37
+ params (`?filter[status]=active&ids[0]=a`) for GET inputs. Existing
38
+ procedures were updated to follow REST semantics:
39
+
40
+ - `update*` mutations → `PATCH`
41
+ - `delete*` / `remove*` mutations → `DELETE`
42
+ - `getBulk*` queries and any query taking a large array input → `POST`
43
+ (because `@orpc/openapi@1.13.x` has no GET→POST URL-length fallback)
44
+
45
+ GET endpoints require an `object` input — bare scalars like
46
+ `.input(z.string())` are not valid on GET. `getSystemConfigurations` was
47
+ refactored from `.input(z.string())` to `.input(z.object({ systemId: ... }))`
48
+ to fit the GET shape; the only call-site update was the in-process router
49
+ unpacking `input.systemId` instead of passing `input` directly.
50
+
51
+ The API Docs UI now renders query parameters (path/query/header/cookie) in a
52
+ dedicated table for GET endpoints, and the fetch example shows them in the
53
+ URL with `<required>` / `<optional>` placeholders.
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [9016526]
58
+ - @checkstack/common@0.10.0
59
+
60
+ ## 0.3.0
61
+
62
+ ### Minor Changes
63
+
64
+ - f6f9a5c: Surface the source repository for GitOps-managed entities and gate the
65
+ system→group remove button on the system's lock state.
66
+
67
+ - `provenanceSchema` now carries a `sourceUrl` field, derived on the
68
+ backend from the provider type, baseUrl, repository and filePath. URLs
69
+ are constructed for github.com / gitlab.com and self-hosted
70
+ GitHub/GitLab where the API base ends in `/api/v3` or `/api/v4`. Other
71
+ baseUrls fall back to `null` so the UI keeps showing the raw path.
72
+ - New `useProvenanceLocks` hook (bulk variant of `useProvenanceLock`)
73
+ for views that render many entities and need to look up locks
74
+ client-side.
75
+ - New `<GitOpsSourceBadge>` popover component that replaces the bare
76
+ GitBranch icon on system and group catalog cards. The popover
77
+ surfaces the repository, file path, and a "View in source provider"
78
+ deep link.
79
+ - `<GitOpsLockBanner>` repo line is now a real link when a sourceUrl is
80
+ available.
81
+ - The system→group remove button in the catalog now disables itself
82
+ when the system is GitOps-managed, matching the backend lock that was
83
+ already in place.
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [42abfff]
88
+ - @checkstack/common@0.9.0
89
+
3
90
  ## 0.2.2
4
91
 
5
92
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/gitops-common",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,14 +9,14 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@checkstack/common": "0.7.0",
12
+ "@checkstack/common": "0.9.0",
13
13
  "@orpc/contract": "^1.13.14",
14
14
  "zod": "^4.2.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "^5.7.2",
18
- "@checkstack/tsconfig": "0.0.6",
19
- "@checkstack/scripts": "0.1.2"
18
+ "@checkstack/tsconfig": "0.0.7",
19
+ "@checkstack/scripts": "0.3.1"
20
20
  },
21
21
  "scripts": {
22
22
  "typecheck": "tsgo -b",
package/src/index.ts CHANGED
@@ -36,3 +36,7 @@ export {
36
36
  type DeletionPolicy,
37
37
  } from "./provenance-types";
38
38
  export { gitopsContract, GitOpsApi, type GitOpsContract } from "./rpc-contract";
39
+ export {
40
+ deriveSourceUrl,
41
+ type DeriveSourceUrlInput,
42
+ } from "./source-url";
@@ -16,6 +16,12 @@ export const provenanceSchema = z.object({
16
16
  providerId: z.string(),
17
17
  repository: z.string(),
18
18
  filePath: z.string(),
19
+ /**
20
+ * Browsable web URL pointing to the entity's defining file in its source
21
+ * provider, derived from the provider type, baseUrl, repository and filePath.
22
+ * Null when the URL cannot be safely derived (unknown baseUrl shape, etc.).
23
+ */
24
+ sourceUrl: z.string().nullable(),
19
25
  lastSyncHash: z.string(),
20
26
  status: provenanceStatusSchema,
21
27
  errorMessage: z.string().nullable(),
@@ -96,6 +96,7 @@ export const gitopsContract = {
96
96
  userType: "authenticated",
97
97
  access: [gitopsAccess.provider.manage],
98
98
  })
99
+ .route({ method: "PATCH" })
99
100
  .input(
100
101
  z.object({
101
102
  id: z.string(),
@@ -117,6 +118,7 @@ export const gitopsContract = {
117
118
  userType: "authenticated",
118
119
  access: [gitopsAccess.provider.manage],
119
120
  })
121
+ .route({ method: "DELETE" })
120
122
  .input(z.object({ id: z.string() }))
121
123
  .output(z.object({ success: z.boolean() })),
122
124
 
@@ -203,6 +205,7 @@ export const gitopsContract = {
203
205
  userType: "authenticated",
204
206
  access: [gitopsAccess.secret.manage],
205
207
  })
208
+ .route({ method: "DELETE" })
206
209
  .input(z.object({ id: z.string() }))
207
210
  .output(z.object({ success: z.boolean() })),
208
211
 
@@ -0,0 +1,152 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { deriveSourceUrl } from "./source-url";
3
+
4
+ describe("deriveSourceUrl", () => {
5
+ test("public github.com", () => {
6
+ expect(
7
+ deriveSourceUrl({
8
+ providerType: "github",
9
+ baseUrl: null,
10
+ repository: "acme/checkstack",
11
+ filePath: "catalog/system.yaml",
12
+ }),
13
+ ).toBe("https://github.com/acme/checkstack/blob/HEAD/catalog/system.yaml");
14
+ });
15
+
16
+ test("public gitlab.com", () => {
17
+ expect(
18
+ deriveSourceUrl({
19
+ providerType: "gitlab",
20
+ baseUrl: null,
21
+ repository: "acme/checkstack",
22
+ filePath: "catalog/system.yaml",
23
+ }),
24
+ ).toBe(
25
+ "https://gitlab.com/acme/checkstack/-/blob/HEAD/catalog/system.yaml",
26
+ );
27
+ });
28
+
29
+ test("api.github.com baseUrl maps to public host", () => {
30
+ expect(
31
+ deriveSourceUrl({
32
+ providerType: "github",
33
+ baseUrl: "https://api.github.com",
34
+ repository: "acme/checkstack",
35
+ filePath: "catalog/system.yaml",
36
+ }),
37
+ ).toBe("https://github.com/acme/checkstack/blob/HEAD/catalog/system.yaml");
38
+ });
39
+
40
+ test("github enterprise baseUrl strips /api/v3", () => {
41
+ expect(
42
+ deriveSourceUrl({
43
+ providerType: "github",
44
+ baseUrl: "https://github.example.com/api/v3",
45
+ repository: "acme/checkstack",
46
+ filePath: "catalog/system.yaml",
47
+ }),
48
+ ).toBe(
49
+ "https://github.example.com/acme/checkstack/blob/HEAD/catalog/system.yaml",
50
+ );
51
+ });
52
+
53
+ test("self-hosted gitlab baseUrl strips /api/v4", () => {
54
+ expect(
55
+ deriveSourceUrl({
56
+ providerType: "gitlab",
57
+ baseUrl: "https://gitlab.example.com/api/v4",
58
+ repository: "team/sub/checkstack",
59
+ filePath: "catalog/system.yaml",
60
+ }),
61
+ ).toBe(
62
+ "https://gitlab.example.com/team/sub/checkstack/-/blob/HEAD/catalog/system.yaml",
63
+ );
64
+ });
65
+
66
+ test("nested gitlab namespaces preserved", () => {
67
+ expect(
68
+ deriveSourceUrl({
69
+ providerType: "gitlab",
70
+ baseUrl: null,
71
+ repository: "group/sub/project",
72
+ filePath: "a/b.yaml",
73
+ }),
74
+ ).toBe("https://gitlab.com/group/sub/project/-/blob/HEAD/a/b.yaml");
75
+ });
76
+
77
+ test("encodes spaces and special characters in path segments", () => {
78
+ expect(
79
+ deriveSourceUrl({
80
+ providerType: "github",
81
+ baseUrl: null,
82
+ repository: "acme/checkstack",
83
+ filePath: "catalog/my system.yaml",
84
+ }),
85
+ ).toBe(
86
+ "https://github.com/acme/checkstack/blob/HEAD/catalog/my%20system.yaml",
87
+ );
88
+ });
89
+
90
+ test("strips leading slashes from filePath", () => {
91
+ expect(
92
+ deriveSourceUrl({
93
+ providerType: "github",
94
+ baseUrl: null,
95
+ repository: "acme/checkstack",
96
+ filePath: "/catalog/system.yaml",
97
+ }),
98
+ ).toBe("https://github.com/acme/checkstack/blob/HEAD/catalog/system.yaml");
99
+ });
100
+
101
+ test("returns null for unknown self-hosted baseUrl", () => {
102
+ expect(
103
+ deriveSourceUrl({
104
+ providerType: "github",
105
+ baseUrl: "https://github.example.com/some/weird/path",
106
+ repository: "acme/checkstack",
107
+ filePath: "catalog/system.yaml",
108
+ }),
109
+ ).toBeNull();
110
+ });
111
+
112
+ test("returns null for traversal attempts", () => {
113
+ expect(
114
+ deriveSourceUrl({
115
+ providerType: "github",
116
+ baseUrl: null,
117
+ repository: "acme/checkstack",
118
+ filePath: "../etc/passwd",
119
+ }),
120
+ ).toBeNull();
121
+ });
122
+
123
+ test("returns null for empty inputs", () => {
124
+ expect(
125
+ deriveSourceUrl({
126
+ providerType: "github",
127
+ baseUrl: null,
128
+ repository: "",
129
+ filePath: "x.yaml",
130
+ }),
131
+ ).toBeNull();
132
+ expect(
133
+ deriveSourceUrl({
134
+ providerType: "github",
135
+ baseUrl: null,
136
+ repository: "a/b",
137
+ filePath: "",
138
+ }),
139
+ ).toBeNull();
140
+ });
141
+
142
+ test("returns null for malformed baseUrl", () => {
143
+ expect(
144
+ deriveSourceUrl({
145
+ providerType: "github",
146
+ baseUrl: "not a url",
147
+ repository: "acme/checkstack",
148
+ filePath: "x.yaml",
149
+ }),
150
+ ).toBeNull();
151
+ });
152
+ });
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Derive a human-browsable source URL for a GitOps-managed entity.
3
+ *
4
+ * Returns null when we don't have enough information to construct a stable URL
5
+ * (e.g., unknown provider type or a malformed `repository` value). Callers
6
+ * should fall back to displaying the raw `repository`/`filePath` text.
7
+ *
8
+ * The URL points at the file on the default branch via the `HEAD` ref so we
9
+ * don't need to know the branch name. Both GitHub and GitLab resolve `HEAD`
10
+ * server-side for blob URLs.
11
+ */
12
+ export interface DeriveSourceUrlInput {
13
+ providerType: "github" | "gitlab";
14
+ /** The provider's `baseUrl` (API base) — null for public github.com/gitlab.com. */
15
+ baseUrl: string | null;
16
+ /** GitHub: `owner/repo`. GitLab: `group/project` (or nested `group/sub/project`). */
17
+ repository: string;
18
+ filePath: string;
19
+ }
20
+
21
+ const GITHUB_PUBLIC_HOST = "https://github.com";
22
+ const GITLAB_PUBLIC_HOST = "https://gitlab.com";
23
+
24
+ const stripApiSuffix = ({
25
+ providerType,
26
+ baseUrl,
27
+ }: {
28
+ providerType: "github" | "gitlab";
29
+ baseUrl: string;
30
+ }): string | null => {
31
+ // We only know how to strip the well-known API path suffixes. Anything else
32
+ // we treat as untrusted and bail out — better to fall back to text than to
33
+ // construct a broken link.
34
+ try {
35
+ const url = new URL(baseUrl);
36
+ if (providerType === "github") {
37
+ // api.github.com → github.com (public host has no API path component)
38
+ if (url.host === "api.github.com") return GITHUB_PUBLIC_HOST;
39
+ // GitHub Enterprise: https://github.example.com/api/v3
40
+ if (url.pathname.replace(/\/$/, "") === "/api/v3") {
41
+ return `${url.protocol}//${url.host}`;
42
+ }
43
+ return null;
44
+ }
45
+ // GitLab: https://gitlab.example.com/api/v4
46
+ if (url.pathname.replace(/\/$/, "") === "/api/v4") {
47
+ return `${url.protocol}//${url.host}`;
48
+ }
49
+ return null;
50
+ } catch {
51
+ return null;
52
+ }
53
+ };
54
+
55
+ const encodeFilePath = (filePath: string) =>
56
+ filePath
57
+ .replace(/^\/+/, "")
58
+ .split("/")
59
+ .map((segment) => encodeURIComponent(segment))
60
+ .join("/");
61
+
62
+ export const deriveSourceUrl = ({
63
+ providerType,
64
+ baseUrl,
65
+ repository,
66
+ filePath,
67
+ }: DeriveSourceUrlInput): string | null => {
68
+ if (!repository || !filePath) return null;
69
+ // Reject backslashes and absolute-looking paths to keep things tidy.
70
+ if (repository.includes("..") || filePath.includes("..")) return null;
71
+
72
+ const host = baseUrl
73
+ ? stripApiSuffix({ providerType, baseUrl })
74
+ : providerType === "github"
75
+ ? GITHUB_PUBLIC_HOST
76
+ : GITLAB_PUBLIC_HOST;
77
+ if (!host) return null;
78
+
79
+ const repoPath = repository
80
+ .split("/")
81
+ .map((segment) => encodeURIComponent(segment))
82
+ .join("/");
83
+ const encodedFile = encodeFilePath(filePath);
84
+
85
+ if (providerType === "github") {
86
+ return `${host}/${repoPath}/blob/HEAD/${encodedFile}`;
87
+ }
88
+ return `${host}/${repoPath}/-/blob/HEAD/${encodedFile}`;
89
+ };