@capybara-hq/kernel 0.1.0-rc.13 → 0.1.0-rc.15

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.
Files changed (170) hide show
  1. package/dist/admin/admin.schemas.d.ts +5 -13
  2. package/dist/catalog/admin-catalog.controller.d.ts +39 -5
  3. package/dist/catalog/admin-catalog.controller.js +75 -6
  4. package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
  5. package/dist/catalog/admin-catalog.schemas.js +7 -0
  6. package/dist/catalog/appearance.schemas.d.ts +10 -0
  7. package/dist/catalog/appearance.schemas.js +20 -0
  8. package/dist/catalog/appearance.service.d.ts +105 -0
  9. package/dist/catalog/appearance.service.js +306 -0
  10. package/dist/catalog/catalog-content.d.ts +9 -1
  11. package/dist/catalog/catalog-content.js +2 -1
  12. package/dist/catalog/catalog-files.d.ts +3 -2
  13. package/dist/catalog/catalog-files.js +8 -5
  14. package/dist/catalog/catalog-import.module.js +3 -0
  15. package/dist/catalog/catalog-items.d.ts +11 -0
  16. package/dist/catalog/catalog-items.js +21 -0
  17. package/dist/catalog/catalog-scope.service.d.ts +7 -0
  18. package/dist/catalog/catalog-scope.service.js +55 -15
  19. package/dist/catalog/catalog.service.js +10 -2
  20. package/dist/catalog/cli.js +3 -0
  21. package/dist/catalog/component-scope.service.d.ts +14 -1
  22. package/dist/catalog/component-scope.service.js +12 -2
  23. package/dist/catalog/marketplaces.service.d.ts +1 -1
  24. package/dist/catalog/org-catalog.controller.d.ts +5 -4
  25. package/dist/catalog/org-catalog.controller.js +5 -4
  26. package/dist/catalog/org-catalog.schemas.d.ts +18 -2
  27. package/dist/catalog/org-catalog.schemas.js +16 -2
  28. package/dist/catalog/org-catalog.service.js +8 -2
  29. package/dist/catalog/org-extension.controller.d.ts +27 -7
  30. package/dist/catalog/org-extension.controller.js +48 -6
  31. package/dist/catalog/plugin-import.d.ts +28 -4
  32. package/dist/catalog/plugin-import.js +96 -20
  33. package/dist/catalog/plugin-package.d.ts +4 -2
  34. package/dist/catalog/plugin-package.js +66 -12
  35. package/dist/catalog/plugin-upgrade.d.ts +15 -1
  36. package/dist/catalog/plugin-upgrade.js +18 -5
  37. package/dist/channels/connections.controller.d.ts +1 -1
  38. package/dist/channels/connections.controller.js +1 -1
  39. package/dist/channels/connections.service.d.ts +22 -5
  40. package/dist/channels/connections.service.js +56 -10
  41. package/dist/channels/webhook.d.ts +21 -1
  42. package/dist/channels/webhook.js +39 -4
  43. package/dist/client/client-access.service.d.ts +101 -0
  44. package/dist/client/client-access.service.js +294 -0
  45. package/dist/client/client-builds.service.d.ts +109 -0
  46. package/dist/client/client-builds.service.js +229 -0
  47. package/dist/client/client-delivery.controller.d.ts +25 -0
  48. package/dist/client/client-delivery.controller.js +66 -0
  49. package/dist/client/client-files.d.ts +48 -0
  50. package/dist/client/client-files.js +136 -0
  51. package/dist/client/client-reports.cron.d.ts +13 -0
  52. package/dist/client/client-reports.cron.js +42 -0
  53. package/dist/client/client-reports.service.d.ts +30 -0
  54. package/dist/client/client-reports.service.js +102 -0
  55. package/dist/client/client.controller.d.ts +45 -0
  56. package/dist/client/client.controller.js +121 -0
  57. package/dist/client/client.module.d.ts +7 -0
  58. package/dist/client/client.module.js +26 -0
  59. package/dist/client/client.schemas.d.ts +55 -0
  60. package/dist/client/client.schemas.js +27 -0
  61. package/dist/ctx/create-ctx.d.ts +19 -4
  62. package/dist/ctx/create-ctx.js +51 -3
  63. package/dist/db/kernel-schema.d.ts +58 -2
  64. package/dist/errors.d.ts +33 -0
  65. package/dist/errors.js +33 -0
  66. package/dist/extensions/admin-ops.d.ts +4 -1
  67. package/dist/extensions/admin-ops.js +22 -1
  68. package/dist/extensions/admin-view.d.ts +8 -0
  69. package/dist/extensions/admin-view.js +78 -0
  70. package/dist/extensions/blobs.d.ts +14 -1
  71. package/dist/extensions/blobs.js +48 -5
  72. package/dist/extensions/guide-places.d.ts +66 -0
  73. package/dist/extensions/guide-places.js +152 -0
  74. package/dist/extensions/host.d.ts +6 -1
  75. package/dist/extensions/host.js +23 -12
  76. package/dist/extensions/instance.d.ts +5 -1
  77. package/dist/extensions/instance.js +8 -0
  78. package/dist/extensions/ledger.d.ts +1 -1
  79. package/dist/extensions/package.d.ts +4 -3
  80. package/dist/extensions/package.js +5 -1
  81. package/dist/extensions/permission-set.d.ts +35 -5
  82. package/dist/extensions/permission-set.js +36 -5
  83. package/dist/extensions/permission-view.d.ts +38 -7
  84. package/dist/extensions/permission-view.js +27 -8
  85. package/dist/extensions/plugin-guides.d.ts +207 -54
  86. package/dist/extensions/plugin-guides.js +436 -165
  87. package/dist/extensions/sources.d.ts +6 -0
  88. package/dist/extensions/sources.js +2 -0
  89. package/dist/extensions/state.module.js +9 -1
  90. package/dist/http/api.module.js +16 -0
  91. package/dist/identity/settings.d.ts +41 -26
  92. package/dist/identity/settings.js +87 -4
  93. package/dist/infra/lock/lock.service.d.ts +8 -0
  94. package/dist/infra/lock/lock.service.js +27 -0
  95. package/dist/infra/throttler/named-throttlers.d.ts +8 -1
  96. package/dist/infra/throttler/named-throttlers.js +30 -1
  97. package/dist/infra/throttler/throttler.guard.js +1 -1
  98. package/dist/kernel.module.js +3 -0
  99. package/dist/orgs/settings.service.d.ts +2 -26
  100. package/dist/overrides.d.ts +3 -1
  101. package/dist/overrides.js +2 -0
  102. package/dist/platform/exclusions.js +37 -6
  103. package/dist/platform/operation.js +4 -0
  104. package/dist/platform/ops/admin.ops.js +17 -2
  105. package/dist/platform/ops/catalog-admin.ops.d.ts +19 -1
  106. package/dist/platform/ops/catalog-admin.ops.js +85 -2
  107. package/dist/platform/ops/connectors.ops.js +2 -0
  108. package/dist/platform/ops/org-plugins.ops.d.ts +7 -1
  109. package/dist/platform/ops/org-plugins.ops.js +63 -4
  110. package/dist/platform/ops/org-settings.ops.js +2 -2
  111. package/dist/platform/ops/orgs.ops.js +1 -0
  112. package/dist/platform/ops/setup.ops.d.ts +24 -0
  113. package/dist/platform/ops/setup.ops.js +212 -0
  114. package/dist/platform/ops/ui.ops.js +1 -1
  115. package/dist/platform/platform-ops.module.d.ts +2 -1
  116. package/dist/platform/platform-ops.module.js +7 -0
  117. package/dist/platform/route-schemas.js +8 -0
  118. package/dist/roles/worker.module.js +4 -0
  119. package/dist/setup/kernel-checks.d.ts +91 -0
  120. package/dist/setup/kernel-checks.js +295 -0
  121. package/dist/setup/oauth-token-probe.d.ts +47 -0
  122. package/dist/setup/oauth-token-probe.js +108 -0
  123. package/dist/setup/redact-check.d.ts +18 -0
  124. package/dist/setup/redact-check.js +46 -0
  125. package/dist/setup/setup-check-registry.d.ts +86 -0
  126. package/dist/setup/setup-check-registry.js +75 -0
  127. package/dist/setup/setup-checks.controller.d.ts +28 -0
  128. package/dist/setup/setup-checks.controller.js +78 -0
  129. package/dist/setup/setup-checks.schemas.d.ts +38 -0
  130. package/dist/setup/setup-checks.schemas.js +43 -0
  131. package/dist/setup/setup-checks.service.d.ts +144 -0
  132. package/dist/setup/setup-checks.service.js +683 -0
  133. package/dist/setup/setup-guides.controller.d.ts +18 -0
  134. package/dist/setup/setup-guides.controller.js +48 -0
  135. package/dist/setup/setup-guides.schemas.d.ts +10 -0
  136. package/dist/setup/setup-guides.schemas.js +6 -0
  137. package/dist/setup/setup-guides.service.d.ts +126 -0
  138. package/dist/setup/setup-guides.service.js +315 -0
  139. package/dist/setup/setup.module.d.ts +8 -0
  140. package/dist/setup/setup.module.js +31 -0
  141. package/dist/themes/render-css.d.ts +2 -1
  142. package/dist/themes/render-css.js +5 -2
  143. package/dist/themes/theme-delivery.service.d.ts +4 -2
  144. package/dist/themes/theme-delivery.service.js +8 -3
  145. package/dist/themes/theme-state.d.ts +28 -7
  146. package/dist/themes/theme-state.js +24 -6
  147. package/dist/themes/themes-public.controller.d.ts +7 -2
  148. package/dist/themes/themes-public.controller.js +11 -5
  149. package/dist/themes/themes.service.js +2 -2
  150. package/dist/tools/connectors.controller.d.ts +28 -11
  151. package/dist/tools/connectors.controller.js +49 -14
  152. package/dist/tools/connectors.schemas.d.ts +4 -0
  153. package/dist/tools/connectors.schemas.js +4 -0
  154. package/dist/tools/connectors.service.d.ts +30 -2
  155. package/dist/tools/connectors.service.js +98 -3
  156. package/dist/tools/credentials.d.ts +20 -0
  157. package/dist/tools/credentials.js +90 -1
  158. package/dist/tools/oauth/tokens.d.ts +20 -0
  159. package/dist/tools/oauth/tokens.js +49 -24
  160. package/dist/tools/pipeline.d.ts +3 -2
  161. package/dist/ui/arrangement.d.ts +41 -50
  162. package/dist/ui/arrangement.js +88 -15
  163. package/dist/ui/registry.d.ts +13 -3
  164. package/dist/ui/registry.js +15 -4
  165. package/dist/ui/ui.schemas.d.ts +4 -0
  166. package/dist/ui/views.d.ts +36 -9
  167. package/dist/ui/views.js +58 -28
  168. package/package.json +3 -3
  169. package/src/migrations/0106_setup_guides_v2.sql +10 -0
  170. package/src/migrations/0107_extension_client_builds.sql +50 -0
@@ -0,0 +1,66 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Get, Inject, Req, Res } from "@nestjs/common";
11
+ import { CurrentPrincipal, requireUser } from "../identity/principal.js";
12
+ import { ClientAccess } from "./client-access.service.js";
13
+ /** The route prefix, as the raw request path starts with it. */
14
+ const PREFIX = "/api/v1/client/";
15
+ /** A build's files never change (the package sha256 is in the URL); only its viewers may cache them. */
16
+ const IMMUTABLE_PRIVATE = "private, max-age=31536000, immutable";
17
+ /**
18
+ * Client file delivery (client extensions spec §9.3): `GET /api/v1/client/<plugin>/<build>/<path>`
19
+ * serves the entry, a stylesheet or an asset of a client build to a signed-in person allowed to load
20
+ * it ({@link ClientAccess.file}: one PG query per request, nothing cached); anything else is 404
21
+ * `client.not_found`. The web's document CSP allows scripts from this prefix only, so the route
22
+ * never redirects (no trailing-slash or case redirect either): a redirect would leave the path the
23
+ * policy checked.
24
+ *
25
+ * The file is named by the raw request path, never by the decoded wildcard parameter: the path is
26
+ * matched segment by segment against the manifest key's charset, so `..`, encoded separators and
27
+ * backslashes name nothing.
28
+ *
29
+ * Headers: `Cache-Control: private, max-age=31536000, immutable`, `X-Content-Type-Options: nosniff`,
30
+ * `Cross-Origin-Resource-Policy: same-origin`, the content type of the file's kind
31
+ * (`text/javascript`, `text/css; charset=utf-8`, the asset type), and for an SVG asset
32
+ * `Content-Security-Policy: default-src 'none'; sandbox`.
33
+ */
34
+ let ClientDeliveryController = class ClientDeliveryController {
35
+ access;
36
+ constructor(access) {
37
+ this.access = access;
38
+ }
39
+ async file(principal, req, reply) {
40
+ const p = requireUser(principal);
41
+ const raw = req.raw.url ?? "";
42
+ const q = raw.indexOf("?");
43
+ const path = q < 0 ? raw : raw.slice(0, q);
44
+ const f = await this.access.file(p.account.id, p.account.isSuperAdmin, path.startsWith(PREFIX) ? path.slice(PREFIX.length) : "");
45
+ reply
46
+ .header("content-type", f.contentType)
47
+ .header("cache-control", IMMUTABLE_PRIVATE)
48
+ .header("x-content-type-options", "nosniff")
49
+ .header("cross-origin-resource-policy", "same-origin");
50
+ if (f.contentType === "image/svg+xml") {
51
+ reply.header("content-security-policy", "default-src 'none'; sandbox");
52
+ }
53
+ await reply.send(Buffer.from(f.data.buffer, f.data.byteOffset, f.data.byteLength));
54
+ }
55
+ };
56
+ __decorate([
57
+ Get(":plugin/:build/*"),
58
+ __param(0, CurrentPrincipal()),
59
+ __param(1, Req()),
60
+ __param(2, Res())
61
+ ], ClientDeliveryController.prototype, "file", null);
62
+ ClientDeliveryController = __decorate([
63
+ Controller("api/v1/client"),
64
+ __param(0, Inject(ClientAccess))
65
+ ], ClientDeliveryController);
66
+ export { ClientDeliveryController };
@@ -0,0 +1,48 @@
1
+ import { type PluginClientSection } from "@capybara-hq/plugin-sdk";
2
+ /**
3
+ * The client files of a plugin package (client extensions spec §4.1, §9.1), checked against its
4
+ * `extension.client` section: the import review and the store both run {@link checkClientFiles} on
5
+ * the bytes they hold, so nothing reaches object storage, and no integrity reaches a browser, that
6
+ * was not recomputed from the bytes.
7
+ *
8
+ * Files are known only by their manifest key (`./dist/client/<path>`): the object key and, later,
9
+ * the delivery lookup use the exact key, never a decoded or joined path. Every segment of a key is
10
+ * made of `[A-Za-z0-9._-]` only (no `%`, space, `?`, `#`, backslash or non-ASCII character, which a
11
+ * browser would encode or split), is not `.` or `..`, and the file name has a stem: refused here
12
+ * even when the SDK validator lets it through.
13
+ */
14
+ /** The directory of client files inside the package (relative to the package root). */
15
+ export declare const CLIENT_DIR = "dist/client/";
16
+ /** The object prefix of a build, relative to `deployment/`: `platform/client/<plugin>/<sha256>/`. */
17
+ export declare const clientBuildPrefix: (plugin: string, sha256: string) => string;
18
+ /** The path of a manifest key inside `dist/client/` (`./dist/client/styles/a.css` -> `styles/a.css`). */
19
+ export declare const clientRelPath: (key: string) => string;
20
+ /** The content type a client file is stored and served with (by its manifest key). */
21
+ export declare function clientContentType(key: string): string;
22
+ /** One checked client file. */
23
+ export interface CheckedClientFile {
24
+ /** The manifest key (`./dist/client/...`). */
25
+ key: string;
26
+ data: Uint8Array;
27
+ size: number;
28
+ /** `sha384-<base64>`, equal to the section's value. */
29
+ integrity: string;
30
+ }
31
+ /** The checked client files of a section, in section order (entry, styles, assets). */
32
+ export interface CheckedClient {
33
+ files: CheckedClientFile[];
34
+ total: number;
35
+ }
36
+ /**
37
+ * Checks the client files of a package against its section and returns them. `files` holds the
38
+ * package's files keyed by their path relative to the package root (`dist/client/client.mjs`);
39
+ * files outside `dist/client/` are ignored. Refuses the whole package with:
40
+ * - `client.invalid` (details `[{ file, reason }]`): the section fails `validateClientSection`
41
+ * (file `plugin.json`), a key cannot be looked up exactly, a listed file is missing, a file
42
+ * under `dist/client/` is not listed, a size limit is exceeded, or a stylesheet fails the CSS
43
+ * check (`clientCssProblem` from `@capybara-hq/plugin-sdk`);
44
+ * - `client.integrity_mismatch` (details `[{ file }]`): a file's sha384 is not the section's;
45
+ * - `client.api_unsupported` (details `[{ apiVersion, supported }]`): the section's `apiVersion`
46
+ * is newer than the kernel's `CLIENT_API_VERSION` (the host could not run it).
47
+ */
48
+ export declare function checkClientFiles(section: PluginClientSection, files: ReadonlyMap<string, Uint8Array>): CheckedClient;
@@ -0,0 +1,136 @@
1
+ import { createHash } from "node:crypto";
2
+ import { CLIENT_API_VERSION, CLIENT_ASSET_TYPES, CLIENT_ENTRY_PATH, CLIENT_LIMITS, clientCssProblem, validateClientSection, } from "@capybara-hq/plugin-sdk";
3
+ import { ApiError } from "../errors.js";
4
+ /**
5
+ * The client files of a plugin package (client extensions spec §4.1, §9.1), checked against its
6
+ * `extension.client` section: the import review and the store both run {@link checkClientFiles} on
7
+ * the bytes they hold, so nothing reaches object storage, and no integrity reaches a browser, that
8
+ * was not recomputed from the bytes.
9
+ *
10
+ * Files are known only by their manifest key (`./dist/client/<path>`): the object key and, later,
11
+ * the delivery lookup use the exact key, never a decoded or joined path. Every segment of a key is
12
+ * made of `[A-Za-z0-9._-]` only (no `%`, space, `?`, `#`, backslash or non-ASCII character, which a
13
+ * browser would encode or split), is not `.` or `..`, and the file name has a stem: refused here
14
+ * even when the SDK validator lets it through.
15
+ */
16
+ /** The directory of client files inside the package (relative to the package root). */
17
+ export const CLIENT_DIR = "dist/client/";
18
+ const KEY_PREFIX = `./${CLIENT_DIR}`;
19
+ /** The object prefix of a build, relative to `deployment/`: `platform/client/<plugin>/<sha256>/`. */
20
+ export const clientBuildPrefix = (plugin, sha256) => `platform/client/${plugin}/${sha256}/`;
21
+ /** The path of a manifest key inside `dist/client/` (`./dist/client/styles/a.css` -> `styles/a.css`). */
22
+ export const clientRelPath = (key) => key.slice(KEY_PREFIX.length);
23
+ /** The content type a client file is stored and served with (by its manifest key). */
24
+ export function clientContentType(key) {
25
+ if (key === CLIENT_ENTRY_PATH)
26
+ return "text/javascript";
27
+ if (key.endsWith(".css"))
28
+ return "text/css";
29
+ const dot = key.lastIndexOf(".");
30
+ return CLIENT_ASSET_TYPES[key.slice(dot).toLowerCase()] ?? "application/octet-stream";
31
+ }
32
+ const invalid = (file, reason) => new ApiError("client.invalid", `The plugin's client file ${file} is invalid: ${reason}`, [
33
+ { file, reason },
34
+ ]);
35
+ /** One segment of a client file key: plain characters only (no decoding is ever needed). */
36
+ const SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
37
+ /** Why a manifest key cannot be stored and looked up by its exact spelling, or undefined. */
38
+ function keyProblem(key) {
39
+ if (!key.startsWith(KEY_PREFIX))
40
+ return `it must be under ${KEY_PREFIX}`;
41
+ const segs = clientRelPath(key).split("/");
42
+ if (segs.some((s) => s === "" || s === "." || s === "..")) {
43
+ return "the path has an empty, . or .. segment";
44
+ }
45
+ if (!segs.every((s) => SEGMENT_RE.test(s))) {
46
+ return "the path may use only letters, digits, . _ - and / (no %, spaces, ? or #)";
47
+ }
48
+ const name = segs[segs.length - 1];
49
+ if (name.lastIndexOf(".") <= 0)
50
+ return "the file name has an empty stem or no extension";
51
+ return undefined;
52
+ }
53
+ const sha384 = (data) => `sha384-${createHash("sha384").update(data).digest("base64")}`;
54
+ const utf8 = (data) => {
55
+ try {
56
+ return new TextDecoder("utf-8", { fatal: true }).decode(data);
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ };
62
+ /**
63
+ * Checks the client files of a package against its section and returns them. `files` holds the
64
+ * package's files keyed by their path relative to the package root (`dist/client/client.mjs`);
65
+ * files outside `dist/client/` are ignored. Refuses the whole package with:
66
+ * - `client.invalid` (details `[{ file, reason }]`): the section fails `validateClientSection`
67
+ * (file `plugin.json`), a key cannot be looked up exactly, a listed file is missing, a file
68
+ * under `dist/client/` is not listed, a size limit is exceeded, or a stylesheet fails the CSS
69
+ * check (`clientCssProblem` from `@capybara-hq/plugin-sdk`);
70
+ * - `client.integrity_mismatch` (details `[{ file }]`): a file's sha384 is not the section's;
71
+ * - `client.api_unsupported` (details `[{ apiVersion, supported }]`): the section's `apiVersion`
72
+ * is newer than the kernel's `CLIENT_API_VERSION` (the host could not run it).
73
+ */
74
+ export function checkClientFiles(section, files) {
75
+ const sectionIssues = validateClientSection(section);
76
+ if (sectionIssues.length > 0) {
77
+ throw invalid("plugin.json", sectionIssues[0]);
78
+ }
79
+ if (section.apiVersion > CLIENT_API_VERSION) {
80
+ throw new ApiError("client.api_unsupported", `The plugin's client code was built for client API ${section.apiVersion}; this deployment ` +
81
+ `supports ${CLIENT_API_VERSION}. Upgrade Capybara, or build the plugin against ` +
82
+ `@capybara-hq/plugin-client for client API ${CLIENT_API_VERSION}.`, [{ apiVersion: section.apiVersion, supported: CLIENT_API_VERSION }]);
83
+ }
84
+ const styles = section.styles ?? [];
85
+ const keys = [
86
+ ...(section.entry !== undefined ? [section.entry] : []),
87
+ ...styles,
88
+ ...(section.assets ?? []),
89
+ ];
90
+ for (const key of keys) {
91
+ const problem = keyProblem(key);
92
+ if (problem !== undefined)
93
+ throw invalid(key, problem);
94
+ }
95
+ const listed = new Set(keys);
96
+ // the URLs a stylesheet may use: ../assets/<path> of a listed asset
97
+ const assetPaths = new Set((section.assets ?? []).map((k) => k.slice(`${KEY_PREFIX}assets/`.length)));
98
+ for (const path of [...files.keys()].sort()) {
99
+ if (path.startsWith(CLIENT_DIR) && !listed.has(`./${path}`)) {
100
+ throw invalid(`./${path}`, "the file is not listed in the plugin's client section");
101
+ }
102
+ }
103
+ const out = [];
104
+ let total = 0;
105
+ for (const key of keys) {
106
+ const data = files.get(key.slice(2));
107
+ if (data === undefined)
108
+ throw invalid(key, "the file is missing from the package");
109
+ const size = data.byteLength;
110
+ const limit = key === section.entry
111
+ ? CLIENT_LIMITS.entryBytes
112
+ : styles.includes(key)
113
+ ? CLIENT_LIMITS.styleBytes
114
+ : CLIENT_LIMITS.assetBytes;
115
+ if (size > limit)
116
+ throw invalid(key, `the file is ${size} bytes; the limit is ${limit}`);
117
+ total += size;
118
+ const integrity = sha384(data);
119
+ if (integrity !== section.integrity[key]) {
120
+ throw new ApiError("client.integrity_mismatch", `The plugin's client file ${key} does not match the integrity recorded in its plugin.json`, [{ file: key }]);
121
+ }
122
+ if (styles.includes(key)) {
123
+ const css = utf8(data);
124
+ if (css === undefined)
125
+ throw invalid(key, "the stylesheet is not valid UTF-8 text");
126
+ const problem = clientCssProblem(css, assetPaths);
127
+ if (problem !== undefined)
128
+ throw invalid(key, problem);
129
+ }
130
+ out.push({ key, data, size, integrity });
131
+ }
132
+ if (total > CLIENT_LIMITS.totalBytes) {
133
+ throw invalid("plugin.json", `the client files are ${total} bytes in total; the limit is ${CLIENT_LIMITS.totalBytes}`);
134
+ }
135
+ return { files: out, total };
136
+ }
@@ -0,0 +1,13 @@
1
+ import { LockService } from "../infra/lock/lock.service.js";
2
+ import type { KernelLogger } from "../log.js";
3
+ import { ClientReports } from "./client-reports.service.js";
4
+ /** The daily prune of client reports (`@LockedCron`). */
5
+ export declare const CLIENT_REPORTS_PRUNE_JOB = "client-reports-prune";
6
+ /** Deletes client reports not seen for 30 days (spec §10.4), once per tick across replicas; the worker role's. */
7
+ export declare class ClientReportsCron {
8
+ private readonly reports;
9
+ readonly lockService: LockService;
10
+ readonly log: KernelLogger;
11
+ constructor(reports: ClientReports, lockService: LockService, log: KernelLogger);
12
+ prune(): Promise<void>;
13
+ }
@@ -0,0 +1,42 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { LockService } from "../infra/lock/lock.service.js";
12
+ import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
13
+ import { KERNEL_LOGGER } from "../infra/tokens.js";
14
+ import { ClientReports } from "./client-reports.service.js";
15
+ /** The daily prune of client reports (`@LockedCron`). */
16
+ export const CLIENT_REPORTS_PRUNE_JOB = "client-reports-prune";
17
+ /** Deletes client reports not seen for 30 days (spec §10.4), once per tick across replicas; the worker role's. */
18
+ let ClientReportsCron = class ClientReportsCron {
19
+ reports;
20
+ lockService;
21
+ log;
22
+ constructor(reports, lockService, log) {
23
+ this.reports = reports;
24
+ this.lockService = lockService;
25
+ this.log = log;
26
+ }
27
+ async prune() {
28
+ const n = await this.reports.prune();
29
+ if (n > 0)
30
+ this.log.info("client reports pruned", { count: n });
31
+ }
32
+ };
33
+ __decorate([
34
+ LockedCron("50 3 * * *", { name: CLIENT_REPORTS_PRUNE_JOB })
35
+ ], ClientReportsCron.prototype, "prune", null);
36
+ ClientReportsCron = __decorate([
37
+ Injectable(),
38
+ __param(0, Inject(ClientReports)),
39
+ __param(1, Inject(LockService)),
40
+ __param(2, Inject(KERNEL_LOGGER))
41
+ ], ClientReportsCron);
42
+ export { ClientReportsCron };
@@ -0,0 +1,30 @@
1
+ import { KernelDb } from "../infra/database/kernel-db.js";
2
+ import { TransactionHost } from "../infra/database/transaction-host.js";
3
+ import type { ReportBodyInput } from "./client.schemas.js";
4
+ import { ClientAccess } from "./client-access.service.js";
5
+ /** Reports older than this (by `last_at`) are deleted by the daily prune (spec §10.4). */
6
+ export declare const REPORT_RETENTION_DAYS = 30;
7
+ /**
8
+ * Crash and load reports of client code (client extensions spec §10.4): one row per (plugin,
9
+ * build, org, contribution, kind), upserted so a crash loop is one row with a count. A report is
10
+ * accepted only for a build the reporter could fetch ({@link ClientAccess.fetchable}), in an org
11
+ * an extension enabled there, and a `contribution` that is null or a component of that build's
12
+ * manifest, so nobody writes rows about plugins or orgs they cannot see and the key bounds the
13
+ * rows (a made-up contribution cannot add one); anything else is the same 404
14
+ * `client.not_found` the delivery route answers.
15
+ */
16
+ export declare class ClientReports {
17
+ private readonly db;
18
+ readonly txHost: TransactionHost;
19
+ private readonly access;
20
+ constructor(db: KernelDb, txHost: TransactionHost, access: ClientAccess);
21
+ /** A report from a workspace page of org `orgId`. */
22
+ recordForOrg(accountId: string, orgId: string, body: ReportBodyInput): Promise<void>;
23
+ /** A report from the admin console (no org; super admins only, the caller checks that). */
24
+ recordForAdmin(accountId: string, body: ReportBodyInput): Promise<void>;
25
+ /** The build must be fetchable and the contribution null or one of its components. */
26
+ private check;
27
+ private upsert;
28
+ /** Deletes the reports last seen more than {@link REPORT_RETENTION_DAYS} days ago; the count. */
29
+ prune(): Promise<number>;
30
+ }
@@ -0,0 +1,102 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { sql } from "kysely";
12
+ import { ApiError } from "../errors.js";
13
+ import { enabledExtensionsQuery } from "../extensions/enabled.js";
14
+ import { KernelDb } from "../infra/database/kernel-db.js";
15
+ import { TransactionHost } from "../infra/database/transaction-host.js";
16
+ import { Transactional } from "../infra/database/transactional.decorator.js";
17
+ import { ClientAccess } from "./client-access.service.js";
18
+ /** Reports older than this (by `last_at`) are deleted by the daily prune (spec §10.4). */
19
+ export const REPORT_RETENTION_DAYS = 30;
20
+ /**
21
+ * Crash and load reports of client code (client extensions spec §10.4): one row per (plugin,
22
+ * build, org, contribution, kind), upserted so a crash loop is one row with a count. A report is
23
+ * accepted only for a build the reporter could fetch ({@link ClientAccess.fetchable}), in an org
24
+ * an extension enabled there, and a `contribution` that is null or a component of that build's
25
+ * manifest, so nobody writes rows about plugins or orgs they cannot see and the key bounds the
26
+ * rows (a made-up contribution cannot add one); anything else is the same 404
27
+ * `client.not_found` the delivery route answers.
28
+ */
29
+ let ClientReports = class ClientReports {
30
+ db;
31
+ txHost;
32
+ access;
33
+ constructor(db, txHost, access) {
34
+ this.db = db;
35
+ this.txHost = txHost;
36
+ this.access = access;
37
+ }
38
+ /** A report from a workspace page of org `orgId`. */
39
+ async recordForOrg(accountId, orgId, body) {
40
+ const enabled = await this.db.db
41
+ .selectFrom(enabledExtensionsQuery(this.db.db, orgId).as("en"))
42
+ .select("en.plugin")
43
+ .where("en.plugin", "=", body.plugin)
44
+ .executeTakeFirst();
45
+ if (enabled === undefined)
46
+ throw notFound();
47
+ await this.check(accountId, false, body);
48
+ await this.upsert(orgId, body);
49
+ }
50
+ /** A report from the admin console (no org; super admins only, the caller checks that). */
51
+ async recordForAdmin(accountId, body) {
52
+ await this.check(accountId, true, body);
53
+ await this.upsert(null, body);
54
+ }
55
+ /** The build must be fetchable and the contribution null or one of its components. */
56
+ async check(accountId, superAdmin, b) {
57
+ const build = await this.access.fetchable(accountId, superAdmin, b.plugin, b.build);
58
+ if (build === null)
59
+ throw notFound();
60
+ if (b.contribution !== null && !build.components.has(b.contribution))
61
+ throw notFound();
62
+ }
63
+ async upsert(orgId, b) {
64
+ await this.db.db
65
+ .insertInto("extension_client_reports")
66
+ .values({
67
+ plugin: b.plugin,
68
+ build: b.build,
69
+ org_id: orgId,
70
+ contribution: b.contribution,
71
+ kind: b.kind,
72
+ last_message: b.message,
73
+ })
74
+ .onConflict((oc) => oc
75
+ .expression(sql `plugin, build, (coalesce(org_id, '')), (coalesce(contribution, '')), kind`)
76
+ .doUpdateSet({
77
+ count: sql `extension_client_reports.count + 1`,
78
+ last_at: sql `now()`,
79
+ last_message: b.message,
80
+ }))
81
+ .execute();
82
+ }
83
+ /** Deletes the reports last seen more than {@link REPORT_RETENTION_DAYS} days ago; the count. */
84
+ async prune() {
85
+ const r = await this.db.db
86
+ .deleteFrom("extension_client_reports")
87
+ .where("last_at", "<", sql `now() - make_interval(days => ${REPORT_RETENTION_DAYS})`)
88
+ .executeTakeFirst();
89
+ return Number(r.numDeletedRows);
90
+ }
91
+ };
92
+ __decorate([
93
+ Transactional()
94
+ ], ClientReports.prototype, "upsert", null);
95
+ ClientReports = __decorate([
96
+ Injectable(),
97
+ __param(0, Inject(KernelDb)),
98
+ __param(1, Inject(TransactionHost)),
99
+ __param(2, Inject(ClientAccess))
100
+ ], ClientReports);
101
+ export { ClientReports };
102
+ const notFound = () => new ApiError("client.not_found", "Client file not found");
@@ -0,0 +1,45 @@
1
+ import type { z } from "zod";
2
+ import { type Principal } from "../identity/principal.js";
3
+ import { type OrgContext } from "../orgs/org.guard.js";
4
+ import { AdminClientQuery, type ClientExtensionsResponse, ReportBody } from "./client.schemas.js";
5
+ import { ClientAccess } from "./client-access.service.js";
6
+ import { ClientReports } from "./client-reports.service.js";
7
+ /**
8
+ * The workspace shell read of client extensions (client extensions spec §9.2), `ui.use` (guest and
9
+ * up; a person, not a service token): `GET /api/v1/orgs/:orgId/ui/client` →
10
+ * {@link ClientExtensionsResponse}: the extensions enabled in the org that run with an approved
11
+ * client build, their file URLs and integrity, and the components the caller's role may use;
12
+ * `enabled: false` with no items under the kill switch. `no-store`: the set changes with an org
13
+ * switch, an upgrade or the kill switch.
14
+ */
15
+ export declare class OrgClientController {
16
+ private readonly access;
17
+ private readonly reports;
18
+ constructor(access: ClientAccess, reports: ClientReports);
19
+ list(principal: Principal, org: OrgContext): Promise<ClientExtensionsResponse>;
20
+ /**
21
+ * `POST /api/v1/orgs/:orgId/ui/client/reports` (spec §10.4), `ui.use`, a person, 20 per minute
22
+ * per account (`client-reports`): a crash or load report of client code → 204. 404
23
+ * `client.not_found` for an extension not on in the org or a build the caller cannot fetch; 400
24
+ * for a message over 500 characters.
25
+ */
26
+ report(principal: Principal, org: OrgContext, body: z.infer<typeof ReportBody>): Promise<void>;
27
+ }
28
+ /**
29
+ * The admin console's client set (spec §9.6), super admins only: `GET /api/v1/admin/ui/client
30
+ * ?plugin=` → {@link ClientExtensionsResponse} with only `platform.page` components and no
31
+ * stylesheets (the admin console runs no org client code); with `plugin`, at most that one (the
32
+ * page `/admin/p/<plugin>/<id>` reads its own). `no-store`.
33
+ */
34
+ export declare class AdminClientController {
35
+ private readonly access;
36
+ private readonly reports;
37
+ constructor(access: ClientAccess, reports: ClientReports);
38
+ list(principal: Principal, q: z.infer<typeof AdminClientQuery>): Promise<ClientExtensionsResponse>;
39
+ /**
40
+ * `POST /api/v1/admin/ui/client/reports` (spec §10.4), super admins, 20 per minute per account:
41
+ * a report from an admin page (stored with no org) → 204; 404 `client.not_found` for a build
42
+ * that has no `platform.page` component or is not served.
43
+ */
44
+ report(principal: Principal, body: z.infer<typeof ReportBody>): Promise<void>;
45
+ }
@@ -0,0 +1,121 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Get, Header, HttpCode, Inject, Post } from "@nestjs/common";
11
+ import { CurrentPrincipal, requireUser, SuperAdmin, } from "../identity/principal.js";
12
+ import { Throttled } from "../infra/throttler/throttler.guard.js";
13
+ import { createZodDto } from "../infra/validation/create-zod-dto.js";
14
+ import { ZBody, ZQuery } from "../infra/validation/zod-params.js";
15
+ import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
16
+ import { AdminClientQuery, ReportBody } from "./client.schemas.js";
17
+ import { ClientAccess } from "./client-access.service.js";
18
+ import { ClientReports } from "./client-reports.service.js";
19
+ class AdminClientQueryDto extends createZodDto(AdminClientQuery, "AdminClientQuery") {
20
+ }
21
+ class ReportBodyDto extends createZodDto(ReportBody, "ClientReportBody") {
22
+ }
23
+ /**
24
+ * The workspace shell read of client extensions (client extensions spec §9.2), `ui.use` (guest and
25
+ * up; a person, not a service token): `GET /api/v1/orgs/:orgId/ui/client` →
26
+ * {@link ClientExtensionsResponse}: the extensions enabled in the org that run with an approved
27
+ * client build, their file URLs and integrity, and the components the caller's role may use;
28
+ * `enabled: false` with no items under the kill switch. `no-store`: the set changes with an org
29
+ * switch, an upgrade or the kill switch.
30
+ */
31
+ let OrgClientController = class OrgClientController {
32
+ access;
33
+ reports;
34
+ constructor(access, reports) {
35
+ this.access = access;
36
+ this.reports = reports;
37
+ }
38
+ async list(principal, org) {
39
+ requireUser(principal);
40
+ return this.access.orgSet(org.orgId, org.role);
41
+ }
42
+ /**
43
+ * `POST /api/v1/orgs/:orgId/ui/client/reports` (spec §10.4), `ui.use`, a person, 20 per minute
44
+ * per account (`client-reports`): a crash or load report of client code → 204. 404
45
+ * `client.not_found` for an extension not on in the org or a build the caller cannot fetch; 400
46
+ * for a message over 500 characters.
47
+ */
48
+ async report(principal, org, body) {
49
+ const user = requireUser(principal);
50
+ await this.reports.recordForOrg(user.account.id, org.orgId, body);
51
+ }
52
+ };
53
+ __decorate([
54
+ Get(),
55
+ OrgAction("ui.use"),
56
+ Header("cache-control", "no-store"),
57
+ __param(0, CurrentPrincipal()),
58
+ __param(1, CurrentOrg())
59
+ ], OrgClientController.prototype, "list", null);
60
+ __decorate([
61
+ Post("reports"),
62
+ OrgAction("ui.use"),
63
+ HttpCode(204),
64
+ Throttled("client-reports"),
65
+ __param(0, CurrentPrincipal()),
66
+ __param(1, CurrentOrg()),
67
+ __param(2, ZBody(ReportBodyDto))
68
+ ], OrgClientController.prototype, "report", null);
69
+ OrgClientController = __decorate([
70
+ Controller("api/v1/orgs/:orgId/ui/client"),
71
+ __param(0, Inject(ClientAccess)),
72
+ __param(1, Inject(ClientReports))
73
+ ], OrgClientController);
74
+ export { OrgClientController };
75
+ /**
76
+ * The admin console's client set (spec §9.6), super admins only: `GET /api/v1/admin/ui/client
77
+ * ?plugin=` → {@link ClientExtensionsResponse} with only `platform.page` components and no
78
+ * stylesheets (the admin console runs no org client code); with `plugin`, at most that one (the
79
+ * page `/admin/p/<plugin>/<id>` reads its own). `no-store`.
80
+ */
81
+ let AdminClientController = class AdminClientController {
82
+ access;
83
+ reports;
84
+ constructor(access, reports) {
85
+ this.access = access;
86
+ this.reports = reports;
87
+ }
88
+ async list(principal, q) {
89
+ requireUser(principal);
90
+ return this.access.platformSet(q.plugin);
91
+ }
92
+ /**
93
+ * `POST /api/v1/admin/ui/client/reports` (spec §10.4), super admins, 20 per minute per account:
94
+ * a report from an admin page (stored with no org) → 204; 404 `client.not_found` for a build
95
+ * that has no `platform.page` component or is not served.
96
+ */
97
+ async report(principal, body) {
98
+ const user = requireUser(principal);
99
+ await this.reports.recordForAdmin(user.account.id, body);
100
+ }
101
+ };
102
+ __decorate([
103
+ Get(),
104
+ Header("cache-control", "no-store"),
105
+ __param(0, CurrentPrincipal()),
106
+ __param(1, ZQuery(AdminClientQueryDto))
107
+ ], AdminClientController.prototype, "list", null);
108
+ __decorate([
109
+ Post("reports"),
110
+ HttpCode(204),
111
+ Throttled("client-reports"),
112
+ __param(0, CurrentPrincipal()),
113
+ __param(1, ZBody(ReportBodyDto))
114
+ ], AdminClientController.prototype, "report", null);
115
+ AdminClientController = __decorate([
116
+ Controller("api/v1/admin/ui/client"),
117
+ SuperAdmin(),
118
+ __param(0, Inject(ClientAccess)),
119
+ __param(1, Inject(ClientReports))
120
+ ], AdminClientController);
121
+ export { AdminClientController };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Client extensions (spec 2026-11-09-client-extensions-design.md): the client builds stored with
3
+ * extension packages ({@link ClientBuilds}) and who may load them ({@link ClientAccess}: the
4
+ * delivery route and the shell reads, whose controllers the api role lists).
5
+ */
6
+ export declare class ClientModule {
7
+ }
@@ -0,0 +1,26 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Module } from "@nestjs/common";
8
+ import { StorageModule } from "../storage/storage.module.js";
9
+ import { ClientAccess } from "./client-access.service.js";
10
+ import { ClientBuilds } from "./client-builds.service.js";
11
+ import { ClientReports } from "./client-reports.service.js";
12
+ /**
13
+ * Client extensions (spec 2026-11-09-client-extensions-design.md): the client builds stored with
14
+ * extension packages ({@link ClientBuilds}) and who may load them ({@link ClientAccess}: the
15
+ * delivery route and the shell reads, whose controllers the api role lists).
16
+ */
17
+ let ClientModule = class ClientModule {
18
+ };
19
+ ClientModule = __decorate([
20
+ Module({
21
+ imports: [StorageModule],
22
+ providers: [ClientBuilds, ClientAccess, ClientReports],
23
+ exports: [ClientBuilds, ClientAccess, ClientReports],
24
+ })
25
+ ], ClientModule);
26
+ export { ClientModule };