@kitsuden/shared 0.0.0-stage → 0.9.0-beta

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/dist/admin-registry-contract.d.ts +99 -0
  4. package/dist/admin-registry-contract.d.ts.map +1 -0
  5. package/dist/admin-view.d.ts +123 -0
  6. package/dist/admin-view.d.ts.map +1 -0
  7. package/dist/agent-permission.d.ts +161 -0
  8. package/dist/agent-permission.d.ts.map +1 -0
  9. package/dist/approvals.d.ts +164 -0
  10. package/dist/approvals.d.ts.map +1 -0
  11. package/dist/automation.d.ts +175 -0
  12. package/dist/automation.d.ts.map +1 -0
  13. package/dist/block-keys.d.ts +82 -0
  14. package/dist/block-keys.d.ts.map +1 -0
  15. package/dist/code-scan.d.ts +64 -0
  16. package/dist/code-scan.d.ts.map +1 -0
  17. package/dist/comment-subjects.d.ts +129 -0
  18. package/dist/comment-subjects.d.ts.map +1 -0
  19. package/dist/connections.d.ts +96 -0
  20. package/dist/connections.d.ts.map +1 -0
  21. package/dist/constants.d.ts +37 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/content-publishing.d.ts +34 -0
  24. package/dist/content-publishing.d.ts.map +1 -0
  25. package/dist/contracts.d.ts +87 -0
  26. package/dist/contracts.d.ts.map +1 -0
  27. package/dist/dataset-catalog.d.ts +91 -0
  28. package/dist/dataset-catalog.d.ts.map +1 -0
  29. package/dist/deck-analysis.d.ts +63 -0
  30. package/dist/deck-analysis.d.ts.map +1 -0
  31. package/dist/env.d.ts +2 -0
  32. package/dist/env.d.ts.map +1 -0
  33. package/dist/errors.d.ts +275 -0
  34. package/dist/errors.d.ts.map +1 -0
  35. package/dist/field-types.d.ts +304 -0
  36. package/dist/field-types.d.ts.map +1 -0
  37. package/dist/index.d.ts +79 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +7785 -0
  40. package/dist/kon-api.d.ts +914 -0
  41. package/dist/kon-api.d.ts.map +1 -0
  42. package/dist/kon-entities.d.ts +204 -0
  43. package/dist/kon-entities.d.ts.map +1 -0
  44. package/dist/kon-events.d.ts +103 -0
  45. package/dist/kon-events.d.ts.map +1 -0
  46. package/dist/kon-package.d.ts +124 -0
  47. package/dist/kon-package.d.ts.map +1 -0
  48. package/dist/link-relations.d.ts +73 -0
  49. package/dist/link-relations.d.ts.map +1 -0
  50. package/dist/meta-levels.d.ts +81 -0
  51. package/dist/meta-levels.d.ts.map +1 -0
  52. package/dist/models-sql.d.ts +110 -0
  53. package/dist/models-sql.d.ts.map +1 -0
  54. package/dist/models.d.ts +354 -0
  55. package/dist/models.d.ts.map +1 -0
  56. package/dist/operations.d.ts +428 -0
  57. package/dist/operations.d.ts.map +1 -0
  58. package/dist/promotion.d.ts +244 -0
  59. package/dist/promotion.d.ts.map +1 -0
  60. package/dist/public-site.d.ts +106 -0
  61. package/dist/public-site.d.ts.map +1 -0
  62. package/dist/render-blocks.d.ts +150 -0
  63. package/dist/render-blocks.d.ts.map +1 -0
  64. package/dist/reports.d.ts +109 -0
  65. package/dist/reports.d.ts.map +1 -0
  66. package/dist/rls-builder.d.ts +136 -0
  67. package/dist/rls-builder.d.ts.map +1 -0
  68. package/dist/safe-pattern.d.ts +47 -0
  69. package/dist/safe-pattern.d.ts.map +1 -0
  70. package/dist/schemas.d.ts +977 -0
  71. package/dist/schemas.d.ts.map +1 -0
  72. package/dist/sensitivity.d.ts +37 -0
  73. package/dist/sensitivity.d.ts.map +1 -0
  74. package/dist/signer.d.ts +67 -0
  75. package/dist/signer.d.ts.map +1 -0
  76. package/dist/tier-ranges.d.ts +37 -0
  77. package/dist/tier-ranges.d.ts.map +1 -0
  78. package/dist/types.d.ts +261 -0
  79. package/dist/types.d.ts.map +1 -0
  80. package/dist/utils.d.ts +71 -0
  81. package/dist/utils.d.ts.map +1 -0
  82. package/dist/wiki-links.d.ts +56 -0
  83. package/dist/wiki-links.d.ts.map +1 -0
  84. package/package.json +53 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Victor Antinori Broce
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,66 @@
1
- # Temporary Holding Version
1
+ # @kitsuden/shared
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared types, schemas, and utilities for Kitsuden: the kon API (`defineKon`, `defineOperation`, `defineModel`), the error catalogue, permission and approval contracts, Zod schemas and small helpers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @kitsuden/shared@beta
9
+ ```
10
+
11
+ Inside the Kitsuden monorepo it is a workspace package (`"@kitsuden/shared": "workspace:*"`):
12
+ `pnpm install` at the root builds it (its `prepare` script uses Bun); after changing
13
+ `src/`, rebuild it with `pnpm --filter @kitsuden/shared build`.
14
+
15
+ ## Usage
16
+
17
+ Everything is exported from the package root (`exports` has a single entry point).
18
+
19
+ ### Types
20
+
21
+ ```typescript
22
+ import type { DataSet, DataEntry, Game, BlogPost, SiteSettings } from "@kitsuden/shared";
23
+ ```
24
+
25
+ ### Schemas (Zod)
26
+
27
+ ```typescript
28
+ import { safeValidateDataset } from "@kitsuden/shared";
29
+
30
+ // Validate data without throwing
31
+ const result = safeValidateDataset(data);
32
+ if (result.success) {
33
+ console.log("Valid:", result.data);
34
+ } else {
35
+ console.error("Invalid:", result.error);
36
+ }
37
+ ```
38
+
39
+ `validateDatasetDefinition(data)` does the same but throws a `ZodError`.
40
+
41
+ ### Utilities
42
+
43
+ ```typescript
44
+ import { formatDate, truncate, buildCmsUrl, gameJsonLd } from "@kitsuden/shared";
45
+
46
+ const formatted = formatDate(new Date());
47
+ const excerpt = truncate(longText, 100);
48
+ const structuredData = gameJsonLd(game);
49
+ ```
50
+
51
+ ### Constants
52
+
53
+ ```typescript
54
+ import { SITE_CONFIG, BREAKPOINTS, NEON_COLORS } from "@kitsuden/shared";
55
+ ```
56
+
57
+ ## Exports
58
+
59
+ | Export Path | Description |
60
+ | ------------------------------- | --------------------------------------- |
61
+ | `@kitsuden/shared` | Types, schemas, utilities and constants |
62
+ | `@kitsuden/shared/package.json` | The package manifest |
63
+
64
+ ## License
65
+
66
+ MIT © Kitsuden Contributors
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Public contract of the Admin Registry
3
+ * ============================================================================
4
+ *
5
+ * `GET /api/admin/registry` is what makes the Kitsuden panel
6
+ * **replaceable**: it describes which kons exist, which tables they expose and
7
+ * which views they offer, without the client knowing anything about the backend.
8
+ *
9
+ * That matters strategically. Directus and Strapi lock you into their admin;
10
+ * here the official panel is a CLIENT of this API, just as one written in
11
+ * React by someone else would be. But that is only true if the contract is
12
+ * versioned: without a version, any internal change silently breaks whoever
13
+ * has built on top.
14
+ *
15
+ * ─────────────────────────────────────────────────────────────────────────────
16
+ * Evolution rules
17
+ *
18
+ * Within a single version ONLY the following is allowed:
19
+ * - adding optional fields
20
+ * - adding values to an enum that the client already handles with a `default`
21
+ *
22
+ * Requires bumping `ADMIN_REGISTRY_VERSION`:
23
+ * - removing or renaming a field
24
+ * - changing the type or meaning of an existing one
25
+ * - making something mandatory that was optional
26
+ *
27
+ * The server sends the version in the body and in the `X-Kitsuden-Contract`
28
+ * header, so a client can decide without parsing.
29
+ * ─────────────────────────────────────────────────────────────────────────────
30
+ */
31
+ /** Current version of the registry contract. */
32
+ export declare const ADMIN_REGISTRY_VERSION: 1;
33
+ /** Header the server uses to announce the version. */
34
+ export declare const CONTRACT_HEADER = "X-Kitsuden-Contract";
35
+ export interface AdminRegistryTable {
36
+ name: string;
37
+ label: string;
38
+ icon?: string;
39
+ description?: string;
40
+ primaryKey?: string;
41
+ searchableFields?: string[];
42
+ filterableFields?: string[];
43
+ readonly?: boolean;
44
+ }
45
+ export interface AdminRegistryView {
46
+ id: string;
47
+ /**
48
+ * A client that does not recognize a type must fall back to `grid`, not break:
49
+ * that is why adding new types does NOT bump the contract version.
50
+ */
51
+ type: "grid" | "kanban" | "calendar" | "custom" | "element";
52
+ title: string;
53
+ table?: string;
54
+ /** @deprecated Svelte view coupled to the admin's framework. Use `element`. */
55
+ component?: string;
56
+ /** Framework-agnostic Web Component: tag name. */
57
+ element?: string;
58
+ /** Compiled artifact, relative to the kon's package. */
59
+ src?: string;
60
+ icon?: string;
61
+ groupBy?: string;
62
+ dateField?: string;
63
+ titleField?: string;
64
+ }
65
+ export interface AdminRegistryKon {
66
+ id: string;
67
+ name: string;
68
+ icon?: string;
69
+ category: "core" | "content" | "data" | "esports";
70
+ hasCustomView: boolean;
71
+ tables: AdminRegistryTable[];
72
+ views: AdminRegistryView[];
73
+ defaultView: string;
74
+ apiBase?: string;
75
+ }
76
+ /** Response of `GET /api/admin/registry`. */
77
+ export interface AdminRegistryResponse {
78
+ success: true;
79
+ /** Contract version. Check it before assuming the shape of the rest. */
80
+ contract: typeof ADMIN_REGISTRY_VERSION;
81
+ kons: AdminRegistryKon[];
82
+ total: number;
83
+ withCustomViews: number;
84
+ generatedAt: string;
85
+ }
86
+ /** Response of `GET /api/admin/registry/:konId`. */
87
+ export interface AdminRegistryKonResponse {
88
+ success: true;
89
+ contract: typeof ADMIN_REGISTRY_VERSION;
90
+ kon: AdminRegistryKon;
91
+ }
92
+ /**
93
+ * Checks that the response comes from a version the client understands.
94
+ *
95
+ * Meant so that a third-party panel fails CLEARLY and early instead of breaking
96
+ * halfway through a render on a field that no longer exists.
97
+ */
98
+ export declare function assertSupportedContract(received: unknown, supported?: number): void;
99
+ //# sourceMappingURL=admin-registry-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-registry-contract.d.ts","sourceRoot":"","sources":["../src/admin-registry-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,gDAAgD;AAChD,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AAEjD,sDAAsD;AACtD,eAAO,MAAM,eAAe,wBAAwB,CAAC;AAErD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IAClD,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,6CAA6C;AAC7C,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,IAAI,CAAC;IACd,wEAAwE;IACxE,QAAQ,EAAE,OAAO,sBAAsB,CAAC;IACxC,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,oDAAoD;AACpD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,EAAE,OAAO,sBAAsB,CAAC;IACxC,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,OAAO,EACjB,SAAS,GAAE,MAA+B,GACzC,IAAI,CAeN"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Framework-agnostic admin views
3
+ * ============================================================================
4
+ *
5
+ * The contract that lets a kon contribute a custom view WITHOUT writing
6
+ * Svelte and without entering the admin's build.
7
+ *
8
+ * The previous mechanism did `import("…/admin.svelte")` from the admin: that
9
+ * puts foreign source code into the host's compilation graph. It has three
10
+ * consequences, all bad:
11
+ *
12
+ * 1. Whoever extends is forced to use the admin's framework.
13
+ * 2. Vite resolves the dynamic import as a glob, so the admin ends up
14
+ * bundling the view of ALL kons even if nobody opens them.
15
+ * 3. Two kons with different versions of a dependency break the host's
16
+ * build — and that happens even if both use Svelte.
17
+ *
18
+ * The agnostic form reverses the relationship: the kon publishes an ALREADY
19
+ * COMPILED ARTIFACT (with its runtime inside, whether React, Svelte, Vue or
20
+ * nothing) and the admin loads it by URL at runtime. The admin's bundler sees
21
+ * nothing foreign.
22
+ *
23
+ * This module is deliberately pure: it validates and resolves descriptors,
24
+ * without touching the DOM. That way it can be tested without a browser, and
25
+ * the part that does touch the DOM is reduced to a few lines.
26
+ */
27
+ export interface CustomViewDescriptor {
28
+ /** Kon that contributes the view. Determines where the artifact is served from. */
29
+ konId: string;
30
+ /** Name of the custom element. It must contain a hyphen (required by the spec). */
31
+ element: string;
32
+ /** Path of the bundle, relative to the root of the kon's package. */
33
+ src: string;
34
+ }
35
+ export interface ResolvedCustomView {
36
+ descriptor: CustomViewDescriptor;
37
+ /** Absolute URL (relative to the host) to load the module from. */
38
+ url: string;
39
+ }
40
+ export declare class CustomViewError extends Error {
41
+ readonly code: "INVALID_ELEMENT" | "INVALID_SRC" | "INVALID_KON" | "LOAD_FAILED" | "NOT_REGISTERED";
42
+ constructor(message: string, code: "INVALID_ELEMENT" | "INVALID_SRC" | "INVALID_KON" | "LOAD_FAILED" | "NOT_REGISTERED");
43
+ }
44
+ export declare function isValidElementName(name: string): boolean;
45
+ /**
46
+ * A safe `src`: relative, inside the kon's package and with an allowed
47
+ * extension.
48
+ *
49
+ * This is where path traversal is cut off. The `src` comes from a `kon.json`,
50
+ * which in a marketplace is third-party content: without this check, a
51
+ * `../../../../etc/passwd` or an absolute URL to another domain turns the
52
+ * extension point into a vulnerability. It is validated on the CLIENT and again
53
+ * on the SERVER — whoever serves the file cannot trust this layer.
54
+ */
55
+ export declare function isSafeAssetPath(src: string, options?: {
56
+ allowHtml?: boolean;
57
+ }): boolean;
58
+ /**
59
+ * The admin artifacts a kon may hand out: what its declared views need, and
60
+ * nothing else from its package.
61
+ *
62
+ * Until 2026-11-04 `GET /api/kons/:konId/admin-asset/*` served ANY `.js`,
63
+ * `.mjs`, `.css` or `.map` in the kon's directory, without a session: server
64
+ * code compiled to JS, a `config.js`, the source maps of everything
65
+ * (security review 2026-11-03). Now a path is served only if it is:
66
+ *
67
+ * · the `src` of a view declared in `admin.views[]`, or its `.map`;
68
+ * · under the directory of such a `src`, when that is not the package root
69
+ * (`./admin/scoreboard.js` → anything under `admin/`: its chunks, styles
70
+ * and maps);
71
+ * · under `dist/admin/`, the conventional output of a view's build.
72
+ *
73
+ * `requested` and each `src` are relative paths already checked by
74
+ * `isSafeAssetPath` (no `..`, no absolute path).
75
+ */
76
+ export declare const ADMIN_ASSET_DIR = "dist/admin/";
77
+ export declare function isDeclaredAdminAsset(requested: string, declaredSrcs: readonly string[]): boolean;
78
+ /** The `src` of every view a manifest declares in `admin.views[]`. */
79
+ export declare function declaredViewSources(manifest: unknown): string[];
80
+ /** Kon id usable in a path: no separators or line breaks. */
81
+ export declare function isValidKonId(id: string): boolean;
82
+ /** URL under which the API serves a kon's admin artifacts. */
83
+ export declare function adminAssetUrl(konId: string, src: string, baseUrl?: string): string;
84
+ /**
85
+ * Validates a descriptor and returns the load URL.
86
+ * Throws `CustomViewError` with an actionable code instead of an opaque error:
87
+ * whoever writes the view needs to know WHAT is wrong.
88
+ */
89
+ export declare function resolveCustomView(descriptor: CustomViewDescriptor, baseUrl?: string): ResolvedCustomView;
90
+ /**
91
+ * Extracts the descriptor of a view declared in `kon.json`.
92
+ * Returns `null` if the view is not of the agnostic type — so the caller can
93
+ * fall back to the legacy path or to the generic DataExplorer without handling errors.
94
+ */
95
+ export declare function descriptorFromView(konId: string, view: {
96
+ type?: string;
97
+ element?: string;
98
+ src?: string;
99
+ }): CustomViewDescriptor | null;
100
+ /**
101
+ * What the admin hands to a custom element when mounting it, through the
102
+ * `context` property. It is the public CONTRACT: changing it breaks third-party
103
+ * views, so it is versioned.
104
+ */
105
+ export interface AdminViewContext {
106
+ /** Contract version. A view can reject what it does not understand. */
107
+ version: 1;
108
+ konId: string;
109
+ viewId: string;
110
+ /** API base so the view can make its own calls. */
111
+ apiBase: string;
112
+ /** Active theme, in case the view wants to branch beyond CSS. */
113
+ theme: "light" | "dark";
114
+ locale: string;
115
+ }
116
+ export declare function createViewContext(init: {
117
+ konId: string;
118
+ viewId: string;
119
+ apiBase?: string;
120
+ theme?: "light" | "dark";
121
+ locale?: string;
122
+ }): AdminViewContext;
123
+ //# sourceMappingURL=admin-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-view.d.ts","sourceRoot":"","sources":["../src/admin-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,oBAAoB,CAAC;IACjC,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,IAAI,EACX,iBAAiB,GAAG,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,gBAAgB;gBAFtF,OAAO,EAAE,MAAM,EACN,IAAI,EACX,iBAAiB,GAAG,aAAa,GAAG,aAAa,GAAG,aAAa,GAAG,gBAAgB;CAKzF;AAuBD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAkB3F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAahG;AAED,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,CAM/D;AAED,6DAA6D;AAC7D,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEhD;AAID,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,SAAK,GAAG,MAAM,CAG9E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,oBAAoB,EAChC,OAAO,SAAK,GACX,kBAAkB,CAoBpB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,oBAAoB,GAAG,IAAI,CAI7B;AAID;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAMhB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,gBAAgB,CASnB"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Agent permissions — ONE reading of the scopes
3
+ * ============================================================================
4
+ *
5
+ * An agent carries a list of scopes. There used to be three copies of
6
+ * the rule that reads them (the API, the engine and the kon SDK) and a fourth
7
+ * in the MCP tools. Now they all call here.
8
+ *
9
+ * ── WHAT CAN BE IN THE LIST ────────────────────────────────────────────────
10
+ *
11
+ * broad `admin`, `mcp:write`, `content:edit`, `crm:*`… (the old ones)
12
+ * fine `kon:blog:create-post` one operation of the kon SDK
13
+ * `datasets:clients:read` one dataset, one action
14
+ * wildcards `x:*` everything that starts with `x:` (one or more segments)
15
+ * `*:y` everything that ends in `:y`
16
+ * `a:*:c` any one segment in the middle (`datasets:*:read`)
17
+ * deny `!kon:crm:delete-contact`, `!datasets:clients:*`
18
+ *
19
+ * ── THE RULE ───────────────────────────────────────────────────────────────
20
+ *
21
+ * 1. What is granted is the UNION: it is enough for one scope to cover what
22
+ * is requested. A fine scope never takes anything away from a broad one.
23
+ * 2. A denial (`!pattern`) BEATS any grant, `admin` included. It is the only
24
+ * way to take away: "the whole CRM except delete".
25
+ * 3. `admin` / `admin:*` cover everything (except what is denied).
26
+ *
27
+ * Wildcards only EXPAND within what they already covered before: `*:*`, `*` and
28
+ * any pattern made only of wildcards cover nothing (they did not before either).
29
+ *
30
+ * Public guide: docs/agents/permissions.md.
31
+ */
32
+ /** Prefix of a denial. */
33
+ export declare const DENIAL_PREFIX = "!";
34
+ export declare function isDenial(scope: string): boolean;
35
+ /** Separates grants and denials (the latter without the `!`). */
36
+ export declare function splitScopes(scopes: readonly string[] | undefined): {
37
+ grants: string[];
38
+ denials: string[];
39
+ };
40
+ /**
41
+ * Does the PATTERN cover the required scope? Without the `admin` shortcut (that
42
+ * is `scopeCovers`' job). It is what denials use.
43
+ *
44
+ * exact `blog:read` covers `blog:read`
45
+ * first segment `*` suffix: `*:read` covers `x:read` and `x:y:read`
46
+ * last segment `*` prefix: `crm:*` covers `crm:a` and `crm:a:b`
47
+ * `*` in the middle one segment: `datasets:*:read` covers
48
+ * `datasets:clients:read`
49
+ */
50
+ export declare function patternCovers(pattern: string, required: string): boolean;
51
+ /** Does `granted` grant the scope `required`? `admin` covers everything. Without denials. */
52
+ export declare function scopeCovers(granted: string, required: string): boolean;
53
+ /** The denial in the list that covers any of `required`, or `null`. */
54
+ export declare function denialThatCovers(scopes: readonly string[] | undefined, requiredValues: readonly (string | null | undefined)[]): string | null;
55
+ /** The granted scope that covers `required` (ignoring denials), or `null`. */
56
+ export declare function grantThatCovers(scopes: readonly string[] | undefined, required: string): string | null;
57
+ /**
58
+ * THE question: can these scopes do `required`? Union of grants, and a denial
59
+ * that covers it always wins.
60
+ */
61
+ export declare function concedeScope(scopes: readonly string[] | undefined, required: string): boolean;
62
+ /** Maximum scopes per agent: nobody reviews an agent with 500 permissions. */
63
+ export declare const MAX_SCOPES_PER_AGENT = 200;
64
+ /**
65
+ * `null` if the scope can be stored; otherwise, the reason (in English: it is
66
+ * read by whoever calls the API). Lowercase, digits, `_`, `-`, `.`, `*`;
67
+ * segments separated by `:`; at most 5 segments and 200 characters.
68
+ */
69
+ export declare function invalidScopeReason(scope: unknown): string | null;
70
+ /** Normalizes and validates a list: no duplicates, in order. Throws with the first reason. */
71
+ export declare function normalizeScopes(scopes: unknown): string[];
72
+ export type DatasetAction = "read" | "write" | "delete";
73
+ export declare const DATASET_ACTIONS: readonly DatasetAction[];
74
+ /** `datasets:<slug>:<action>`. */
75
+ export declare function datasetScope(slug: string, action: DatasetAction): string;
76
+ /**
77
+ * What the SCOPES say about a specific dataset:
78
+ *
79
+ * "denied" a denial covers it: not even the dataset's policy opens it
80
+ * for this key;
81
+ * "granted" a scope covers it (`datasets:<slug>:read`, `datasets:*:read`,
82
+ * `datasets:*`, `admin`…);
83
+ * null the scopes say nothing: the policy (`policyJson`) decides.
84
+ *
85
+ * What is seen INSIDE the dataset is still filtered by `policyJson.rlsRules` and
86
+ * Postgres RLS: the scope opens the dataset's door, not the rows.
87
+ */
88
+ export declare function accessToDataset(scopes: readonly string[] | undefined, slug: string | null | undefined, action: DatasetAction): "denied" | "granted" | null;
89
+ /**
90
+ * Can an agent whose scopes say nothing about THIS dataset write in it because
91
+ * of the dataset's policy? A session passes `writeAccess: "authenticated"`, but
92
+ * an agent key is not a session: a `datasets:*:read` key must not write. Same
93
+ * rule as `kitsuden_agent_opens_by_policy(id, 'write')` (rls-policies.sql)
94
+ * and as the MCP tools: `mcp:write`, a policy that lets a session read (or
95
+ * `dataset:view`), and one that lets a session write (or `dataset-entry:create`).
96
+ * Call it after `accessToDataset`, which settles grants and denies.
97
+ */
98
+ export declare function agentWritesByPolicy(scopes: readonly string[] | undefined, policy: {
99
+ readAccess?: unknown;
100
+ writeAccess?: unknown;
101
+ } | null | undefined): boolean;
102
+ /**
103
+ * The "broad" groups the panel offers. The text (name and what it grants)
104
+ * lives in the panel's dictionaries; here only the list of scopes, which is what
105
+ * gets stored. Choosing a preset REPLACES the agent's list.
106
+ */
107
+ export declare const AGENT_PRESETS: readonly [{
108
+ readonly id: "connect-only";
109
+ readonly scopes: readonly ["mcp:connect"];
110
+ }, {
111
+ readonly id: "read-only";
112
+ readonly scopes: readonly ["mcp:connect", "mcp:read", "datasets:*:read"];
113
+ }, {
114
+ readonly id: "content-editor";
115
+ readonly scopes: readonly ["mcp:connect", "mcp:read", "content:edit", "kon:blog:*", "kon:blocks:*", "kon:media:*"];
116
+ }, {
117
+ readonly id: "data-editor";
118
+ readonly scopes: readonly ["mcp:connect", "mcp:read", "mcp:write", "datasets:*:read", "datasets:*:write"];
119
+ }, {
120
+ readonly id: "full-admin";
121
+ readonly scopes: readonly ["admin"];
122
+ }];
123
+ export type AgentPreset = (typeof AGENT_PRESETS)[number]["id"];
124
+ /**
125
+ * The known broad scopes of the core (each kon's own, `<kon>:*`, are
126
+ * added by the API with the mounted kons). The panel explains each one.
127
+ */
128
+ export declare const BROAD_CORE_SCOPES: readonly ["admin", "mcp:connect", "mcp:read", "mcp:write", "mcp:admin", "content:edit", "memory:read", "memory:write", "brain:read", "brain:write", "promotion:propose", "mail:send", "user:act", "kon:*", "datasets:*:read", "datasets:*:write", "datasets:*:delete"];
129
+ /**
130
+ * ── AN AGENT KEY IS NOT AN ACCOUNT (an earlier audit) ──────────────────────
131
+ *
132
+ * Routes that only ask for "being authenticated" (commenting, signing up for a
133
+ * tournament, saving a build…) accepted ANY agent, even if its key
134
+ * only carried `datasets:x:read`. Now a key counts as a signed-in user
135
+ * only with this scope (or `admin`). SDK operations with
136
+ * `permission` still decide by their permission.
137
+ */
138
+ export declare const SCOPE_ACT_AS_USER = "user:act";
139
+ export declare function agentActsAsUser(scopes: readonly string[] | undefined): boolean;
140
+ /**
141
+ * ── THE WHOLE KON: `<kon>:*` ───────────────────────────────
142
+ *
143
+ * The guide promises that `<kon>:*` gives "that whole kon" (docs/agents/permissions.md),
144
+ * but only the SDK operations honored it: a kon's LEGACY routes
145
+ * went through the prefix gates (`ADMIN_ONLY_ROUTES`), which only knew
146
+ * `admin`, and through each kon's policies and RLS, which asked about the HUMAN
147
+ * role. A `crm:*` agent got 403 "Insufficient role" when creating a
148
+ * company; an `admin` one saw empty lists in dms, members and booking.
149
+ *
150
+ * Do these scopes open the ENTIRE kon `shortKon` (without `kon-`)? Yes with:
151
+ *
152
+ * · `admin` / `admin:*`;
153
+ * · `<kon>:*` or `kon:<kon>:*`, LITERAL. `kon:*` does NOT: it means "every SDK
154
+ * operation of any kon" and is not widened to every kon's legacy routes.
155
+ *
156
+ * A denial that covers `<kon>:*` or `kon:<kon>:*` (`!crm:*`, `!kon:*`…)
157
+ * wins, `admin` included. The same in SQL: `kitsuden_agent_opens_kon()`
158
+ * (apps/api/src/db/agent-functions.sql); a test compares the two.
159
+ */
160
+ export declare function opensWholeKon(scopes: readonly string[] | undefined, shortKon: string): boolean;
161
+ //# sourceMappingURL=agent-permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-permission.d.ts","sourceRoot":"","sources":["../src/agent-permission.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Human approval of what agents request — the pure CONTRACT
3
+ * ============================================================================
4
+ *
5
+ * A request from an AGENT that "needs approval" is not executed: it is stored
6
+ * as a PROPOSAL and the API responds `202` with `KITSUDEN_E_APPROVAL_REQUIRED`,
7
+ * the id and the URL where its status can be checked. A human on the team
8
+ * approves it (and then it runs with the agent's identity, recording the
9
+ * human) or rejects it (and it never runs). Humans never go through here.
10
+ *
11
+ * What the API, the panel and the tests share lives here: the types, the
12
+ * default configuration (OFF: nothing changes until an admin turns it
13
+ * on), the legacy route patterns and the DECISION TABLE. Execution is in
14
+ * `apps/api/src/lib/approvals.ts`; the public guide in
15
+ * `docs/agents/approvals.md`.
16
+ *
17
+ * ── THE DECISION (operation → agent → global) ─────────────────────────────
18
+ *
19
+ * 1. The OPERATION: is it sensitive? Whatever the admin said for that
20
+ * operation; if they said nothing, whatever the kon declares (`sensitive`,
21
+ * by default only DELETE); on a legacy route (no SDK), its method + pattern
22
+ * rules; on a core MCP tool, by default the delete ones.
23
+ * 2. The GLOBAL is the MASTER SWITCH (owner decision):
24
+ * off, NO agent asks for approval, not even those
25
+ * in `propose`. The panel warns about it when turning it off.
26
+ * 3. The AGENT (with the global on): `direct` → it is never asked for
27
+ * approval; `inherit` → its sensitive operations become a
28
+ * proposal; `propose` → also its writes, depending on the RETENTION:
29
+ * · `selective` (default): every write except the POSTs that the
30
+ * SDK operation declares `readOnly` (validate, compare…);
31
+ * · `strict`: every write (POST/PUT/PATCH/DELETE), no exceptions.
32
+ * Legacy routes (no SDK) declare nothing: they are held in both.
33
+ *
34
+ * With the global off (the default) the API behaves exactly as
35
+ * before human approval.
36
+ *
37
+ * ── UNATTENDED RUNS (deny with an alternative) ────────────────────────────
38
+ *
39
+ * A proposal waits for a human. When nobody is waiting for the answer either
40
+ * (a cron or event action, an agent run started by such a trigger, or an
41
+ * agent that says so with `Kitsuden-Unattended: true`), the agent cannot act
42
+ * on a 202 and the inbox fills with requests nobody asked for. In that case a
43
+ * request that WOULD be held can be refused instead (`403
44
+ * KITSUDEN_E_DENIED_UNATTENDED`) with an `alternative`: what to do instead.
45
+ *
46
+ * · `unattended` (global, default `hold`): `hold` keeps the 202; `deny`
47
+ * refuses. Each agent can override it (`hold` | `deny`; NULL = global).
48
+ * · The alternative text: the operation's or the legacy rule's, else the
49
+ * agent's, else the global one, else `DEFAULT_UNATTENDED_ALTERNATIVE`.
50
+ *
51
+ * It never lets through what would be held: it only changes how it is refused.
52
+ */
53
+ /** How human approval treats an agent. */
54
+ export type ApprovalMode = "inherit" | "propose" | "direct";
55
+ export declare const APPROVAL_MODES: readonly ApprovalMode[];
56
+ export declare function isApprovalMode(v: unknown): v is ApprovalMode;
57
+ /** What `propose` mode holds back (see the header). */
58
+ export type ProposalRetention = "selective" | "strict";
59
+ export declare const PROPOSAL_RETENTIONS: readonly ProposalRetention[];
60
+ export declare function isProposalRetention(v: unknown): v is ProposalRetention;
61
+ /**
62
+ * A rule for LEGACY ROUTES (those that are not SDK operations): method
63
+ * (`*` = any) and path pattern. In the pattern, `*` is ONE segment and
64
+ * `**` any remainder (`/api/**`, `/api/games/*\/blocks/**`).
65
+ */
66
+ export interface LegacyApprovalRule {
67
+ method: string;
68
+ path: string;
69
+ /** What an unattended run is told to do instead (see the header). */
70
+ alternative?: string;
71
+ }
72
+ /** What happens, in an unattended run, to a request that would be held. */
73
+ export type UnattendedMode = "hold" | "deny";
74
+ export declare const UNATTENDED_MODES: readonly UnattendedMode[];
75
+ export declare function isUnattendedMode(v: unknown): v is UnattendedMode;
76
+ /** The longest alternative text (characters). */
77
+ export declare const ALTERNATIVE_MAX = 1000;
78
+ /** What an unattended run is told when nobody wrote anything more specific. */
79
+ export declare const DEFAULT_UNATTENDED_ALTERNATIVE: string;
80
+ export interface ApprovalsConfig {
81
+ /** The MASTER switch. Default: off (nobody asks for approval). */
82
+ enabled: boolean;
83
+ /** What `propose` mode holds back. Default: `selective`. */
84
+ proposeRetention: ProposalRetention;
85
+ /** How long a proposal lives undecided (hours). Default: 168 (7 days). */
86
+ ttlHours: number;
87
+ /**
88
+ * What the admin changed per operation: key → sensitive or not. Keys
89
+ * are the fine scope of the SDK operation (`kon:blog:delete-post`) or,
90
+ * for MCP tools that are not SDK ones, `mcp:<name>`. No key =
91
+ * whatever the operation declares.
92
+ */
93
+ operations: Record<string, boolean>;
94
+ /** Legacy routes that count as sensitive. */
95
+ legacyRules: LegacyApprovalRule[];
96
+ /** In an unattended run: hold (202, the default) or deny with an alternative (403). */
97
+ unattended: UnattendedMode;
98
+ /** The global alternative text; `null` = `DEFAULT_UNATTENDED_ALTERNATIVE`. */
99
+ unattendedAlternative: string | null;
100
+ /** Alternative per operation key (the same keys as `operations`). */
101
+ alternatives: Record<string, string>;
102
+ }
103
+ export declare const TTL_MIN_HOURS = 1;
104
+ export declare const TTL_MAX_HOURS: number;
105
+ export declare const DEFAULT_APPROVALS_CONFIG: ApprovalsConfig;
106
+ export type ProposalStatus = "pending" | "executing" | "executed" | "failed" | "rejected" | "expired";
107
+ export declare const PROPOSAL_STATUSES: readonly ProposalStatus[];
108
+ /** Why a request ended up as a proposal. */
109
+ export type ProposalReason = "sensitive" | "propose_only";
110
+ export declare function isWriteMethod(method: string): boolean;
111
+ /**
112
+ * THE TABLE. `null` = runs now; otherwise, the reason for the proposal. With the
113
+ * global OFF, always `null` (master switch). When on:
114
+ *
115
+ * mode sensitive normal write POST readOnly read
116
+ * direct — — — —
117
+ * propose proposal proposal strict ? proposal —
118
+ * inherit proposal — — —
119
+ */
120
+ export declare function decideApproval(p: {
121
+ mode: ApprovalMode;
122
+ globalActive: boolean;
123
+ sensitive: boolean;
124
+ write: boolean;
125
+ /** A POST of the SDK declared `readOnly`. */
126
+ readOnly?: boolean;
127
+ /** Default: `selective`. */
128
+ retention?: ProposalRetention;
129
+ }): ProposalReason | null;
130
+ /**
131
+ * A request that `decideApproval` holds: in an unattended run, is it held or
132
+ * denied? The agent's setting wins over the global one; attended, always held.
133
+ */
134
+ export declare function decideUnattended(p: {
135
+ unattended: boolean;
136
+ global: UnattendedMode;
137
+ agent?: UnattendedMode | null;
138
+ }): UnattendedMode;
139
+ /** The first alternative written, from the most specific to the default. */
140
+ export declare function pickAlternative(...candidates: Array<string | null | undefined>): string;
141
+ /** The reason an alternative text is not valid, or `null` (`null`/absent is valid). */
142
+ export declare function invalidAlternativeReason(v: unknown): string | null;
143
+ /** The pattern as a regular expression (`*` = one segment, `**` = the rest). */
144
+ export declare function patternRegex(pattern: string): RegExp;
145
+ /** Does `METHOD path` match the rule? */
146
+ export declare function legacyHouseRule(rule: LegacyApprovalRule, method: string, path: string): boolean;
147
+ /** The reason a rule is not valid, or `null`. */
148
+ export declare function invalidRuleReason(rule: unknown): string | null;
149
+ /**
150
+ * Validates and normalizes a partial configuration on top of another. Throws an
151
+ * `Error` with the reason (the API returns it as 422).
152
+ */
153
+ export declare function mergeApprovalsConfig(base: ApprovalsConfig, change: Partial<Record<keyof ApprovalsConfig, unknown>>): ApprovalsConfig;
154
+ /** What is stored in the database, read defensively (an old or half-written row breaks nothing). */
155
+ export declare function readApprovalsConfig(saved: unknown): ApprovalsConfig;
156
+ /** Configuration key of an MCP tool that is not an SDK one. */
157
+ export declare function mcpToolKey(name: string): string;
158
+ /**
159
+ * Sensitive by default for the core MCP tools: those that delete
160
+ * and the one that queues emails (it sends to any address on behalf of the site:
161
+ * earlier audit).
162
+ */
163
+ export declare function defaultSensitiveMcpTool(name: string): boolean;
164
+ //# sourceMappingURL=approvals.d.ts.map