@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.
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/admin-registry-contract.d.ts +99 -0
- package/dist/admin-registry-contract.d.ts.map +1 -0
- package/dist/admin-view.d.ts +123 -0
- package/dist/admin-view.d.ts.map +1 -0
- package/dist/agent-permission.d.ts +161 -0
- package/dist/agent-permission.d.ts.map +1 -0
- package/dist/approvals.d.ts +164 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/automation.d.ts +175 -0
- package/dist/automation.d.ts.map +1 -0
- package/dist/block-keys.d.ts +82 -0
- package/dist/block-keys.d.ts.map +1 -0
- package/dist/code-scan.d.ts +64 -0
- package/dist/code-scan.d.ts.map +1 -0
- package/dist/comment-subjects.d.ts +129 -0
- package/dist/comment-subjects.d.ts.map +1 -0
- package/dist/connections.d.ts +96 -0
- package/dist/connections.d.ts.map +1 -0
- package/dist/constants.d.ts +37 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/content-publishing.d.ts +34 -0
- package/dist/content-publishing.d.ts.map +1 -0
- package/dist/contracts.d.ts +87 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/dataset-catalog.d.ts +91 -0
- package/dist/dataset-catalog.d.ts.map +1 -0
- package/dist/deck-analysis.d.ts +63 -0
- package/dist/deck-analysis.d.ts.map +1 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/errors.d.ts +275 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/field-types.d.ts +304 -0
- package/dist/field-types.d.ts.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7785 -0
- package/dist/kon-api.d.ts +914 -0
- package/dist/kon-api.d.ts.map +1 -0
- package/dist/kon-entities.d.ts +204 -0
- package/dist/kon-entities.d.ts.map +1 -0
- package/dist/kon-events.d.ts +103 -0
- package/dist/kon-events.d.ts.map +1 -0
- package/dist/kon-package.d.ts +124 -0
- package/dist/kon-package.d.ts.map +1 -0
- package/dist/link-relations.d.ts +73 -0
- package/dist/link-relations.d.ts.map +1 -0
- package/dist/meta-levels.d.ts +81 -0
- package/dist/meta-levels.d.ts.map +1 -0
- package/dist/models-sql.d.ts +110 -0
- package/dist/models-sql.d.ts.map +1 -0
- package/dist/models.d.ts +354 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/operations.d.ts +428 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/promotion.d.ts +244 -0
- package/dist/promotion.d.ts.map +1 -0
- package/dist/public-site.d.ts +106 -0
- package/dist/public-site.d.ts.map +1 -0
- package/dist/render-blocks.d.ts +150 -0
- package/dist/render-blocks.d.ts.map +1 -0
- package/dist/reports.d.ts +109 -0
- package/dist/reports.d.ts.map +1 -0
- package/dist/rls-builder.d.ts +136 -0
- package/dist/rls-builder.d.ts.map +1 -0
- package/dist/safe-pattern.d.ts +47 -0
- package/dist/safe-pattern.d.ts.map +1 -0
- package/dist/schemas.d.ts +977 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/sensitivity.d.ts +37 -0
- package/dist/sensitivity.d.ts.map +1 -0
- package/dist/signer.d.ts +67 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/tier-ranges.d.ts +37 -0
- package/dist/tier-ranges.d.ts.map +1 -0
- package/dist/types.d.ts +261 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +71 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/wiki-links.d.ts +56 -0
- package/dist/wiki-links.d.ts.map +1 -0
- package/package.json +53 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promotion of agent-written code — the pure CONTRACT
|
|
3
|
+
* ============================================================================
|
|
4
|
+
*
|
|
5
|
+
* An agent writes code for a `code` action (the QuickJS sandbox) and that
|
|
6
|
+
* code only becomes ACTIVE through this path:
|
|
7
|
+
*
|
|
8
|
+
* 1. DRAFT versioned: the active version is never edited in place;
|
|
9
|
+
* 2. TESTS in the sandbox, with the API and `fetch` MOCKED (the
|
|
10
|
+
* draft's own plus those the action declares);
|
|
11
|
+
* 3. SCAN local and deterministic (`code-scan.ts`) + the diff of
|
|
12
|
+
* what is DECLARED (scopes, hosts, limits) against the active one;
|
|
13
|
+
* 4. DECISION `suggestion` → always a proposal for a human (the human approval
|
|
14
|
+
* inbox); `turbo` → it activates itself ONLY if everything
|
|
15
|
+
* passes and none of `FALLBACK_REASONS` applies; otherwise, a proposal
|
|
16
|
+
* with the reason. Turbo can never widen permissions;
|
|
17
|
+
* 5. WATCH after activating, a window that counts errors and timeouts
|
|
18
|
+
* of the new version; above the threshold it returns
|
|
19
|
+
* by itself to the previous one, writes it down and audits it.
|
|
20
|
+
*
|
|
21
|
+
* What the API, the panel and the tests share lives here: types, the
|
|
22
|
+
* factory configuration (turbo OFF), the capabilities diff, the
|
|
23
|
+
* classification of what touches secrets/users/security and the DECISION
|
|
24
|
+
* TABLE. Execution is in `apps/api/src/lib/promotion.ts`; the public
|
|
25
|
+
* guide in `docs/agents/promotion.md`.
|
|
26
|
+
*/
|
|
27
|
+
/** How ONE agent's code is promoted (set by an admin; by default, `suggestion`). */
|
|
28
|
+
export type PromotionMode = "suggestion" | "turbo";
|
|
29
|
+
export declare const PROMOTION_MODES: readonly PromotionMode[];
|
|
30
|
+
export declare function isPromotionMode(v: unknown): v is PromotionMode;
|
|
31
|
+
export interface PromotionConfig {
|
|
32
|
+
/** The global CAP: without this, no agent in `turbo` activates anything by itself. Default: no. */
|
|
33
|
+
turboAllowed: boolean;
|
|
34
|
+
/** Minutes a newly activated version is watched. */
|
|
35
|
+
watchMinutes: number;
|
|
36
|
+
/** Minimum executions before judging the error rate. */
|
|
37
|
+
minExecutions: number;
|
|
38
|
+
/** Error rate (errors + timeouts / executions) that triggers the rollback. */
|
|
39
|
+
maxErrorRate: number;
|
|
40
|
+
}
|
|
41
|
+
export declare const DEFAULT_PROMOTION_CONFIG: PromotionConfig;
|
|
42
|
+
export declare const PROMOTION_CONFIG_LIMITS: {
|
|
43
|
+
readonly watchMinutes: {
|
|
44
|
+
readonly min: 1;
|
|
45
|
+
readonly max: number;
|
|
46
|
+
};
|
|
47
|
+
readonly minExecutions: {
|
|
48
|
+
readonly min: 1;
|
|
49
|
+
readonly max: 1000;
|
|
50
|
+
};
|
|
51
|
+
readonly maxErrorRate: {
|
|
52
|
+
readonly min: 0.01;
|
|
53
|
+
readonly max: 1;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/** Validates and merges a partial change. Throws `Error` with the reason (the API → 422). */
|
|
57
|
+
export declare function mergePromotionConfig(base: PromotionConfig, change: Partial<Record<keyof PromotionConfig, unknown>>): PromotionConfig;
|
|
58
|
+
/** What is stored, read defensively (an old or broken row = the factory default). */
|
|
59
|
+
export declare function readPromotionConfig(saved: unknown): PromotionConfig;
|
|
60
|
+
/**
|
|
61
|
+
* awaiting_approval proposal pending in the inbox
|
|
62
|
+
* approved a human (or turbo) approved it but it could not be activated
|
|
63
|
+
* (`ENABLE_CODE_ACTIONS` off): an admin activates it later
|
|
64
|
+
* active the one that runs (one per action)
|
|
65
|
+
* superseded it was the active one and another replaced it
|
|
66
|
+
* rolled_back it was rolled back from (by itself or by hand)
|
|
67
|
+
* rejected | expired the proposal was rejected or lapsed
|
|
68
|
+
* failed it could not be activated (the database changed underneath, the agent
|
|
69
|
+
* lost the permission…): see `activationError`
|
|
70
|
+
*/
|
|
71
|
+
export type VersionStatus = "awaiting_approval" | "approved" | "active" | "superseded" | "rolled_back" | "rejected" | "expired" | "failed";
|
|
72
|
+
export declare const VERSION_STATUSES: readonly VersionStatus[];
|
|
73
|
+
/** What the code DECLARES it needs (the only thing turbo compares). */
|
|
74
|
+
export interface CodeCapabilities {
|
|
75
|
+
scopes: string[];
|
|
76
|
+
fetchAllow: string[];
|
|
77
|
+
timeoutMs: number;
|
|
78
|
+
memoryLimitMb: number;
|
|
79
|
+
maxCalls: number;
|
|
80
|
+
/**
|
|
81
|
+
* `egress.rules` (lib/egress-policy.ts), normalized and sorted. Optional so a
|
|
82
|
+
* version stored before it existed still reads; missing = no rules.
|
|
83
|
+
*/
|
|
84
|
+
egress?: CodeEgressRule[];
|
|
85
|
+
/**
|
|
86
|
+
* Where the code runs when it is not the default QuickJS sandbox
|
|
87
|
+
* (`opensandbox:python`, `opensandbox:shell`). Optional: missing = quickjs.
|
|
88
|
+
*/
|
|
89
|
+
runtime?: string;
|
|
90
|
+
}
|
|
91
|
+
/** One egress rule as the promotion contract sees it (same shape as the sandbox's). */
|
|
92
|
+
export interface CodeEgressRule {
|
|
93
|
+
action: "allow" | "deny";
|
|
94
|
+
target?: string;
|
|
95
|
+
ports?: number[];
|
|
96
|
+
}
|
|
97
|
+
/** The same default values as the sandbox (`lib/worker-sandbox.ts`, `code-handler.ts`). */
|
|
98
|
+
export declare const DEFAULT_CODE_LIMITS: {
|
|
99
|
+
readonly timeoutMs: 5000;
|
|
100
|
+
readonly memoryLimitMb: 64;
|
|
101
|
+
readonly maxCalls: 50;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* `egress.rules` of a config, leniently normalized (lowercase targets, sorted
|
|
105
|
+
* unique ports, sorted rules). Invalid entries are dropped here: the strict
|
|
106
|
+
* check (`actionEgressProblem` in apps/api) refuses them when the action or
|
|
107
|
+
* draft is saved, so they never reach the sandbox either.
|
|
108
|
+
*/
|
|
109
|
+
export declare function egressRulesOf(config: unknown): CodeEgressRule[];
|
|
110
|
+
/** From an action's (or a draft's) `config` to its capabilities, normalized and sorted. */
|
|
111
|
+
export declare function capabilitiesOf(config: unknown): CodeCapabilities;
|
|
112
|
+
/**
|
|
113
|
+
* Does reach entry `p` cover everything `q` covers? Host part with
|
|
114
|
+
* `hostCovers` (plus `*` = any host); a port-less `p` covers any port. IP and
|
|
115
|
+
* CIDR targets only cover themselves (a conservative answer: a human looks).
|
|
116
|
+
*/
|
|
117
|
+
export declare function reachCovers(p: string, q: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Does host pattern `p` cover everything `q` covers? Same semantics as the
|
|
120
|
+
* sandbox allowlist (`a.com` exact, `*.a.com` = any subdomain).
|
|
121
|
+
*/
|
|
122
|
+
export declare function hostCovers(p: string, q: string): boolean;
|
|
123
|
+
export interface CapabilitiesDiff {
|
|
124
|
+
/** There is no active version: the draft creates the action (or it is the first to go through here). */
|
|
125
|
+
newTarget: boolean;
|
|
126
|
+
/** Scopes in the draft that the active one did NOT grant (counting their wildcards). */
|
|
127
|
+
scopesAdded: string[];
|
|
128
|
+
scopesRemoved: string[];
|
|
129
|
+
/** Denials (`!x`) of the active one that the draft removes: that also widens. */
|
|
130
|
+
denialsRemoved: string[];
|
|
131
|
+
denialsAdded: string[];
|
|
132
|
+
/**
|
|
133
|
+
* Hosts in the draft that the active one's list did not cover: `fetchAllow`
|
|
134
|
+
* entries and `egress` allow rules (`target` or `target:port`, `*` = any host).
|
|
135
|
+
*/
|
|
136
|
+
hostsAdded: string[];
|
|
137
|
+
hostsRemoved: string[];
|
|
138
|
+
/** `egress` deny rules of the active version that the draft drops: that also widens. */
|
|
139
|
+
egressDenialsRemoved: string[];
|
|
140
|
+
/** The draft runs somewhere else than the active version (quickjs ↔ opensandbox:*). */
|
|
141
|
+
runtimeChanged: boolean;
|
|
142
|
+
/** Limits that go up (time, memory, host calls). */
|
|
143
|
+
limitsIncreased: {
|
|
144
|
+
field: "timeoutMs" | "memoryLimitMb" | "maxCalls";
|
|
145
|
+
before: number;
|
|
146
|
+
after: number;
|
|
147
|
+
}[];
|
|
148
|
+
}
|
|
149
|
+
/** The diff of what is DECLARED. With no active version, everything in the draft is new. */
|
|
150
|
+
export declare function capabilitiesDiff(active: CodeCapabilities | null, draft: CodeCapabilities): CapabilitiesDiff;
|
|
151
|
+
export type SensitiveTouch = "secrets" | "users_roles" | "security_config";
|
|
152
|
+
/** What does a call to this API path touch? `null` = none of that. */
|
|
153
|
+
export declare function pathTouch(path: string): SensitiveTouch | null;
|
|
154
|
+
/** What does a scope touch? `mcp:admin` and `admin:*` count as security configuration. */
|
|
155
|
+
export declare function scopeTouch(scope: string): SensitiveTouch | null;
|
|
156
|
+
/** An environment variable name that looks like a secret (`STRIPE_KEY`, `apiToken`…). */
|
|
157
|
+
export declare function secretName(name: string): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Why a draft was NOT activated by itself (or, in `suggestion`, what the human
|
|
160
|
+
* should look at). They are contract: the agent and the panel read them.
|
|
161
|
+
*/
|
|
162
|
+
export type FallbackReason = "suggestion_mode" | "turbo_disabled_globally" | "agent_held_for_approval" | "new_target" | "no_tests" | "tests_failed" | "tests_errored" | "scan_failed" | "scope_escalation" | "new_outbound_hosts" | "limits_increased" | "touches_secrets" | "target_has_env_vars" | "target_has_credentials" | "runtime_changed" | "touches_users_or_roles" | "touches_security_config" | "sensitive_operation" | "unclassifiable_api_call";
|
|
163
|
+
export declare const FALLBACK_REASONS: readonly FallbackReason[];
|
|
164
|
+
export interface TestsSummary {
|
|
165
|
+
total: number;
|
|
166
|
+
passed: number;
|
|
167
|
+
failed: number;
|
|
168
|
+
errored: number;
|
|
169
|
+
}
|
|
170
|
+
export interface DecisionInput {
|
|
171
|
+
mode: PromotionMode;
|
|
172
|
+
config: Pick<PromotionConfig, "turboAllowed">;
|
|
173
|
+
/**
|
|
174
|
+
* Human approval is on and the agent is in `propose`:
|
|
175
|
+
* an admin wants to see EVERYTHING it writes, so turbo does not skip that.
|
|
176
|
+
*/
|
|
177
|
+
heldAgent?: boolean;
|
|
178
|
+
diff: CapabilitiesDiff;
|
|
179
|
+
tests: TestsSummary;
|
|
180
|
+
approvedScan: boolean;
|
|
181
|
+
/** What the code or its scopes touch (without repeats). */
|
|
182
|
+
touches: SensitiveTouch[];
|
|
183
|
+
/** There is a call to a sensitive operation (the approval classification). */
|
|
184
|
+
sensitiveOperation: boolean;
|
|
185
|
+
/** There is an API call that cannot be classified (dynamic path, alias). */
|
|
186
|
+
unclassifiedCall: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* The target action has environment variables, and a new version receives
|
|
189
|
+
* their real values on its next run. The scan is advice, not a proof that the
|
|
190
|
+
* code leaves them alone, so these targets always wait for a human.
|
|
191
|
+
*/
|
|
192
|
+
targetWithVariables?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* The target action has vault credentials bound (`credentials` in its config).
|
|
195
|
+
* A new version never SEES them, but its requests to the bound hosts carry
|
|
196
|
+
* them: what it does with that authority is a human's call.
|
|
197
|
+
*/
|
|
198
|
+
targetWithCredentials?: boolean;
|
|
199
|
+
}
|
|
200
|
+
export interface PromotionDecision {
|
|
201
|
+
/** `turbo` = activates now; `proposal` = waits for a human. */
|
|
202
|
+
route: "turbo" | "proposal";
|
|
203
|
+
/** ALL the reasons that apply, also in `suggestion` (what the human should look at). */
|
|
204
|
+
reasons: FallbackReason[];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* THE TABLE. Turbo only if the agent is in `turbo`, the global cap
|
|
208
|
+
* allows it and NO reason applies. Otherwise, a proposal with its reasons.
|
|
209
|
+
*/
|
|
210
|
+
export declare function decidePromotion(e: DecisionInput): PromotionDecision;
|
|
211
|
+
/** A mocked response for `kitsuden.api.*` or `fetch` inside a test. */
|
|
212
|
+
export interface MockResponse {
|
|
213
|
+
status?: number;
|
|
214
|
+
body?: unknown;
|
|
215
|
+
headers?: Record<string, string>;
|
|
216
|
+
}
|
|
217
|
+
export interface TestCase {
|
|
218
|
+
name: string;
|
|
219
|
+
/**
|
|
220
|
+
* What the code receives as `event` (in production, `{ action, trigger,
|
|
221
|
+
* event, request, timestamp }`).
|
|
222
|
+
*/
|
|
223
|
+
event?: Record<string, unknown>;
|
|
224
|
+
/** What the code receives as `env` (never the action's real values). */
|
|
225
|
+
env?: Record<string, string>;
|
|
226
|
+
/** `METHOD /api/path` → response. Anything not here responds 404 (and is noted). */
|
|
227
|
+
api?: Record<string, MockResponse>;
|
|
228
|
+
/** `METHOD https://host/path` (or just the URL, = GET) → response. */
|
|
229
|
+
fetch?: Record<string, MockResponse>;
|
|
230
|
+
expect: {
|
|
231
|
+
/** Default: `true`. */
|
|
232
|
+
success?: boolean;
|
|
233
|
+
/** Deep equality with the returned value. */
|
|
234
|
+
result?: unknown;
|
|
235
|
+
/** The result's JSON contains this text. */
|
|
236
|
+
resultContains?: string;
|
|
237
|
+
errorContains?: string;
|
|
238
|
+
logsContain?: string;
|
|
239
|
+
};
|
|
240
|
+
timeoutMs?: number;
|
|
241
|
+
}
|
|
242
|
+
export declare const MAX_TESTS_PER_DRAFT = 20;
|
|
243
|
+
export declare const MAX_CODE_BYTES: number;
|
|
244
|
+
//# sourceMappingURL=promotion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../src/promotion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,oFAAoF;AACpF,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,OAAO,CAAC;AAEnD,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAA4B,CAAC;AAEjF,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAE9D;AAED,MAAM,WAAW,eAAe;IAC9B,mGAAmG;IACnG,YAAY,EAAE,OAAO,CAAC;IACtB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,wBAAwB,EAAE,eAKtC,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;CAI1B,CAAC;AAEX,6FAA6F;AAC7F,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,OAAO,CAAC,MAAM,CA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AC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACnC,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,MAAM,EAAE;QACN,uBAAuB;QACvB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,6CAA6C;QAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,4CAA4C;QAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,cAAc,QAAa,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public site addresses
|
|
3
|
+
* ============================================================================
|
|
4
|
+
*
|
|
5
|
+
* EVERYTHING is path-based, inside the domain of its website:
|
|
6
|
+
*
|
|
7
|
+
* 1. A game lives in the first segment: `<domain>/<game>/`, and everything
|
|
8
|
+
* about it hangs from there, its wiki included (`/<game>/wiki/`).
|
|
9
|
+
* 2. So do the site's sections: `/esports/`, `/tournaments`, `/wikis`…
|
|
10
|
+
*
|
|
11
|
+
* Previously each wiki (`<wiki>.<domain>`) and esports
|
|
12
|
+
* (`esports.<domain>`) had their own subdomain. A subdomain is another origin:
|
|
13
|
+
* it shares neither session nor `localStorage`, it has to be registered in CORS and
|
|
14
|
+
* the search engine treats it almost as another site. They were removed so that everything counts toward a
|
|
15
|
+
* single domain.
|
|
16
|
+
*
|
|
17
|
+
* That is why what remains here is about PATHS: which first segment cannot be
|
|
18
|
+
* a game, what a valid slug looks like and which public URL wins. kon-games uses it
|
|
19
|
+
* when creating a game and the frontend when serving it; with a copy on each side,
|
|
20
|
+
* the panel would end up accepting a game that the site cannot open.
|
|
21
|
+
*
|
|
22
|
+
* Everything is pure: no network, no environment. The caller passes the public URL.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Why a slug is NOT valid for a wiki, or `null` if it is.
|
|
26
|
+
*
|
|
27
|
+
* A wiki's slug is no longer an address (the address comes from its game:
|
|
28
|
+
* `/<game>/wiki/`), but its name in the API: `/api/wiki/wikis/<slug>`. That is
|
|
29
|
+
* why it is enough for it to be a clean slug. It returns the reason instead of a
|
|
30
|
+
* boolean because the wiki creator shows it as is.
|
|
31
|
+
*/
|
|
32
|
+
export declare function invalidWikiSlugReason(slug: string): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* First path segments a game cannot occupy.
|
|
35
|
+
*
|
|
36
|
+
* The frontend serves each game at `/<slug>/`, and fixed routes beat
|
|
37
|
+
* dynamic ones: a game with the slug `blog` would NOT raise an error — it is just that nobody
|
|
38
|
+
* would ever reach it, because `/blog/` is the blog. That is why it is prevented when creating
|
|
39
|
+
* the game, which is the only moment when anyone can do something
|
|
40
|
+
* about it.
|
|
41
|
+
*
|
|
42
|
+
* Only the routes that ANY site built with Kitsuden has go here (those
|
|
43
|
+
* of the starters, those of Astro and the web's conventions). Each site's own
|
|
44
|
+
* pages (`/tournaments`, `/shop`…) belong to that site: they are
|
|
45
|
+
* declared in the API with `KITSUDEN_RESERVED_SEGMENTS` (comma-separated
|
|
46
|
+
* list, see `readReservedSegments`) and the frontend passes its own to
|
|
47
|
+
* `invalidGameSlugReason`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const RESERVED_SITE_SEGMENTS: ReadonlySet<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Reserved segments of ONE site, from a comma-separated list (the API's
|
|
52
|
+
* `KITSUDEN_RESERVED_SEGMENTS` variable). Ignores whitespace,
|
|
53
|
+
* uppercase and empty entries.
|
|
54
|
+
*/
|
|
55
|
+
export declare function readReservedSegments(value: string | null | undefined): ReadonlySet<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Why a slug is NOT valid for a game, or `null` if it is.
|
|
58
|
+
*
|
|
59
|
+
* `ownValues` are the reserved segments of the specific site (in addition to
|
|
60
|
+
* `SITE_RESERVED_SEGMENTS`, which apply to everyone).
|
|
61
|
+
*/
|
|
62
|
+
export declare function invalidGameSlugReason(slug: string, ownValues?: Iterable<string>): string | null;
|
|
63
|
+
/**
|
|
64
|
+
* Game slug from a title.
|
|
65
|
+
*
|
|
66
|
+
* The previous one (`toLowerCase().replace(/[^a-z0-9]+/g, "-")`) left hyphens at
|
|
67
|
+
* the ends and deleted accented letters: "¡Pokémon!" gave `-pok-mon-`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function gameSlug(title: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* The default value of `site_settings.site_url`. It exists in ALL
|
|
72
|
+
* installations even if nobody wrote it, so it cannot be treated as
|
|
73
|
+
* a decision by whoever administers.
|
|
74
|
+
*/
|
|
75
|
+
export declare const DEFAULT_PUBLIC_URL = "http://localhost:4321";
|
|
76
|
+
/**
|
|
77
|
+
* The effective public URL: the panel's (General settings → Site URL) if
|
|
78
|
+
* someone wrote it, otherwise the environment's, and otherwise the development one.
|
|
79
|
+
*
|
|
80
|
+
* The panel wins because it is where people change it. But the column is born with
|
|
81
|
+
* `http://localhost:4321` in every database: if that value always won, a
|
|
82
|
+
* deployment with `SITE_URL` set correctly and the panel untouched would announce the
|
|
83
|
+
* site at `localhost`. That is why the default value does NOT count as chosen,
|
|
84
|
+
* and neither does anything that is not an http(s) URL: a typo in the panel
|
|
85
|
+
* cannot take down the addresses.
|
|
86
|
+
*
|
|
87
|
+
* It is used by the API and the frontend. If each side prioritized differently, changing
|
|
88
|
+
* the domain in the panel would leave one of the two with the old one.
|
|
89
|
+
*/
|
|
90
|
+
export declare function effectivePublicUrl(ofThePanel: string | null | undefined, ofTheEnvironment: string | null | undefined): string;
|
|
91
|
+
/**
|
|
92
|
+
* Values `site_settings.site_name` is born with (the column's and the one the
|
|
93
|
+
* panel form wrote when left empty). Same as with the
|
|
94
|
+
* URL: being in the database does not mean someone chose it.
|
|
95
|
+
*/
|
|
96
|
+
export declare const DEFAULT_SITE_NAMES: ReadonlySet<string>;
|
|
97
|
+
/**
|
|
98
|
+
* The name the visitor sees: the panel's (General settings → Site
|
|
99
|
+
* Name) if someone wrote it; otherwise, whatever the deployment brings.
|
|
100
|
+
*
|
|
101
|
+
* "Kitsuden" is the CMS, not the site. If the default value won, a
|
|
102
|
+
* freshly installed site would introduce itself to its visitors with the name of the software
|
|
103
|
+
* that runs it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function effectiveSiteName(ofThePanel: string | null | undefined, ofTheEnvironment: string | null | undefined): string;
|
|
106
|
+
//# sourceMappingURL=public-site.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-site.d.ts","sourceRoot":"","sources":["../src/public-site.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AASH;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOjE;AAID;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAuCrD,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAO1F;AAKD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,QAAQ,CAAC,MAAM,CAAM,GAC/B,MAAM,GAAG,IAAI,CAUf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ9C;AAID;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC1C,MAAM,CAkBR;AAID;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAyC,CAAC;AAE7F;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC1C,MAAM,CAMR"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blocks → HTML. ONE renderer, two consumers.
|
|
3
|
+
* ============================================================================
|
|
4
|
+
*
|
|
5
|
+
* ── THE PROBLEM IT SOLVES ──────────────────────────────────────────────────
|
|
6
|
+
*
|
|
7
|
+
* `blog_posts.blocks` was edited, saved and served by the API… and NOBODY
|
|
8
|
+
* rendered it. Searching for `PageBlock` across the whole tree only turned up
|
|
9
|
+
* panel components: the block builder produced data that no page could
|
|
10
|
+
* show. From the editor it looked like this:
|
|
11
|
+
*
|
|
12
|
+
* · you add a gallery in the "Blocks" tab
|
|
13
|
+
* · you look at the preview
|
|
14
|
+
* · it comes out exactly like a post without blocks
|
|
15
|
+
*
|
|
16
|
+
* Which does not read as "the preview does not support them" but as "it was not
|
|
17
|
+
* saved".
|
|
18
|
+
*
|
|
19
|
+
* ── WHY IT LIVES IN `shared` ───────────────────────────────────────────────
|
|
20
|
+
*
|
|
21
|
+
* Because there has to be ONLY ONE. If the panel draws the preview with its
|
|
22
|
+
* renderer and the public site with another, the preview stops being a
|
|
23
|
+
* preview: it shows something nobody is going to publish. `@kitsuden/shared` is the
|
|
24
|
+
* only package that both the panel and `kon-blog` depend on.
|
|
25
|
+
*
|
|
26
|
+
* ── WHAT CANNOT BE RENDERED STATICALLY ─────────────────────────────────────
|
|
27
|
+
*
|
|
28
|
+
* Six of the thirteen blocks are interactive or query live data: a
|
|
29
|
+
* map with thousands of markers, a grid over a dataset, a carousel that
|
|
30
|
+
* asks for the most recent games. That is NOT solved with static HTML,
|
|
31
|
+
* and pretending it is is worse than not doing it: layout would be built on a
|
|
32
|
+
* false result.
|
|
33
|
+
*
|
|
34
|
+
* For those a container is emitted with `data-kitsuden-block` and its configuration
|
|
35
|
+
* in JSON, for the site to hydrate, plus a readable fallback content.
|
|
36
|
+
* Each one is listed in the result's `interactive` so that whoever renders knows that what they
|
|
37
|
+
* see is a gap and not the result.
|
|
38
|
+
*
|
|
39
|
+
* ── SECURITY ───────────────────────────────────────────────────────────────
|
|
40
|
+
*
|
|
41
|
+
* All user data is escaped. The only point where HTML can get in is
|
|
42
|
+
* a `richtext` block with `format: "html"`, and there an INJECTED sanitizer
|
|
43
|
+
* is needed: without it the HTML is escaped and shows as text. It fails on the
|
|
44
|
+
* safe side on purpose — whoever forgets to pass the sanitizer gets ugly content,
|
|
45
|
+
* not a stored XSS on every blog page.
|
|
46
|
+
*/
|
|
47
|
+
/** A block exactly as the editor stores it in the `blocks` column. */
|
|
48
|
+
export interface ContentBlock {
|
|
49
|
+
id: string;
|
|
50
|
+
type: string;
|
|
51
|
+
data?: Record<string, unknown>;
|
|
52
|
+
order?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface RenderOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Markdown → HTML. **It does not need to be passed**: there is a default.
|
|
57
|
+
*
|
|
58
|
+
* ── WHY THERE IS A DEFAULT AND IT IS NOT REQUIRED OF THE CALLER ──────────
|
|
59
|
+
*
|
|
60
|
+
* Because when each caller brought its own, each one left out a different
|
|
61
|
+
* half and the result diverged SILENTLY. Measured:
|
|
62
|
+
*
|
|
63
|
+
* API : <div class="ks-richtext"><pre># Hello</pre></div>
|
|
64
|
+
* Panel : <div class="ks-richtext"><h1>Hello</h1></div>
|
|
65
|
+
*
|
|
66
|
+
* The preview showed a heading and the site published the raw markdown. Nothing
|
|
67
|
+
* fails, nothing warns, and the editor makes decisions about something that
|
|
68
|
+
* will not be published — which is exactly what this module existed to
|
|
69
|
+
* prevent.
|
|
70
|
+
*
|
|
71
|
+
* A shared default turns "remember to pass the same thing in both
|
|
72
|
+
* places" into "there is nothing to pass".
|
|
73
|
+
*/
|
|
74
|
+
markdownToHtml?: (md: string) => string;
|
|
75
|
+
/**
|
|
76
|
+
* Sanitizes foreign HTML. Without it, the HTML is ESCAPED.
|
|
77
|
+
*
|
|
78
|
+
* It is not a convenience: `richtext` with `format: "html"` is text that someone
|
|
79
|
+
* wrote and that will end up on a public page. Emitting it raw is a stored
|
|
80
|
+
* XSS.
|
|
81
|
+
*
|
|
82
|
+
* NO caller passes one today, and that is deliberate: the blog's sanitizer
|
|
83
|
+
* (`sanitizeHTML`) needs `DOMParser`, which in the API runtime DOES NOT
|
|
84
|
+
* EXIST —verified in the container: `typeof DOMParser === "undefined"`—,
|
|
85
|
+
* so there it fell back to stripping all tags while the panel
|
|
86
|
+
* escaped them. Two behaviors for the same data.
|
|
87
|
+
*
|
|
88
|
+
* Until there is a sanitizer that works the same on server and browser, the
|
|
89
|
+
* HTML is escaped in both places. It looks ugly and looks the SAME.
|
|
90
|
+
*/
|
|
91
|
+
sanitizeHtml?: (html: string) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Prefix of the CSS classes. The site and the panel lay things out differently and this way they do not
|
|
94
|
+
* step on each other.
|
|
95
|
+
*/
|
|
96
|
+
prefix?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface RenderResult {
|
|
99
|
+
html: string;
|
|
100
|
+
/** Types that were emitted as a gap to hydrate, without repeats. */
|
|
101
|
+
interactive: string[];
|
|
102
|
+
/** Types this renderer does not know. */
|
|
103
|
+
unknownAll: string[];
|
|
104
|
+
}
|
|
105
|
+
/** Escapes for text and for attributes. */
|
|
106
|
+
export declare function escapeHtml(value: unknown): string;
|
|
107
|
+
/**
|
|
108
|
+
* A URL that can be put in `href`/`src` without opening a hole.
|
|
109
|
+
*
|
|
110
|
+
* `javascript:`, `data:` and `vbscript:` in an `href` execute code on click.
|
|
111
|
+
* Relative ones and those with a known scheme pass; the rest are discarded and leave the
|
|
112
|
+
* attribute empty.
|
|
113
|
+
*/
|
|
114
|
+
export declare function safeUrl(value: unknown): string;
|
|
115
|
+
/** Markdown → HTML with no injectable tags and no links that execute code. */
|
|
116
|
+
export declare function safeMarkdown(md: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* The URL that CAN be put in an `<iframe>`.
|
|
119
|
+
*
|
|
120
|
+
* ── WHY IT IS NEEDED ───────────────────────────────────────────────────────
|
|
121
|
+
*
|
|
122
|
+
* A normal YouTube link CANNOT be embedded. Verified with `curl`:
|
|
123
|
+
*
|
|
124
|
+
* GET https://www.youtube.com/watch?v=… X-Frame-Options: SAMEORIGIN
|
|
125
|
+
* GET https://www.youtube.com/embed/… (no X-Frame-Options)
|
|
126
|
+
*
|
|
127
|
+
* That is: the "Embed" block accepted the URL anyone copies from the browser
|
|
128
|
+
* bar —its own placeholder said `youtube.com/watch?v=…`—
|
|
129
|
+
* and the result was a BLANK FRAME. No error, no warning: the block
|
|
130
|
+
* saved fine and there was no video on the page.
|
|
131
|
+
*
|
|
132
|
+
* Fixing it here and not in the editor has a reason: that way blocks ALREADY SAVED
|
|
133
|
+
* with the bad URL work too, without touching them one by one.
|
|
134
|
+
*
|
|
135
|
+
* What it does not recognize is returned as is: some services do accept their
|
|
136
|
+
* normal URL, and over-guessing would break the ones that work today.
|
|
137
|
+
*/
|
|
138
|
+
export declare function embedUrl(value: unknown): string;
|
|
139
|
+
/**
|
|
140
|
+
* Draws a list of blocks.
|
|
141
|
+
*
|
|
142
|
+
* Sorts by `order` because the array can arrive in any order: it is jsonb,
|
|
143
|
+
* and whoever writes it through the API need not respect the position.
|
|
144
|
+
*/
|
|
145
|
+
export declare function renderBlocks(blocks: ContentBlock[] | null | undefined, options?: RenderOptions): RenderResult;
|
|
146
|
+
/** The types this renderer knows how to draw fully. */
|
|
147
|
+
export declare const STATIC_TYPES: readonly ["hero", "richtext", "image-gallery", "embed", "callout", "facebook-group", "divider", "streamer-widget"];
|
|
148
|
+
/** Those emitted as a gap to hydrate. */
|
|
149
|
+
export declare const INTERACTIVE_TYPES: string[];
|
|
150
|
+
//# sourceMappingURL=render-blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-blocks.d.ts","sourceRoot":"","sources":["../src/render-blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAMH,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;;OAkBG;IACH,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAExC;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAExC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,yCAAyC;IACzC,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO9C;AAgDD,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/C;AA0KD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA8D/C;AAmBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,SAAS,EACzC,OAAO,GAAE,aAAkB,GAC1B,YAAY,CA4Md;AAED,uDAAuD;AACvD,eAAO,MAAM,YAAY,oHASf,CAAC;AAEX,yCAAyC;AACzC,eAAO,MAAM,iBAAiB,UAA2B,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports: the aggregate query and the report definition (docs/reports.md)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
*
|
|
5
|
+
* Every other query surface returns ROWS. A report answers "how much, grouped
|
|
6
|
+
* by what": deals won per month, orders per product, average ticket per stage.
|
|
7
|
+
*
|
|
8
|
+
* {
|
|
9
|
+
* source: { table: "crm_deals" },
|
|
10
|
+
* measures: [{ fn: "sum", field: "amount", as: "total" }, { fn: "count" }],
|
|
11
|
+
* groupBy: [{ field: "closed_at", bucket: "month", as: "month" }],
|
|
12
|
+
* filters: [{ field: "status", op: "eq", value: "won" }],
|
|
13
|
+
* orderBy: [{ by: "month", dir: "asc" }],
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* It is DATA, not SQL: the host turns it into one statement with every
|
|
17
|
+
* identifier checked against the real columns and every value bound, and runs
|
|
18
|
+
* it as whoever asked, so row level security decides which rows are counted.
|
|
19
|
+
*
|
|
20
|
+
* This file is the shape and its checks. The SQL lives in the host.
|
|
21
|
+
*/
|
|
22
|
+
export declare const AGGREGATE_FUNCTIONS: readonly ["count", "count_distinct", "sum", "avg", "min", "max"];
|
|
23
|
+
export type AggregateFunction = (typeof AGGREGATE_FUNCTIONS)[number];
|
|
24
|
+
export declare const DATE_BUCKETS: readonly ["day", "week", "month", "quarter", "year"];
|
|
25
|
+
export type DateBucket = (typeof DATE_BUCKETS)[number];
|
|
26
|
+
export declare const AGGREGATE_FILTER_OPERATORS: readonly ["eq", "neq", "gt", "gte", "lt", "lte", "in", "contains", "is_null"];
|
|
27
|
+
export type AggregateFilterOperator = (typeof AGGREGATE_FILTER_OPERATORS)[number];
|
|
28
|
+
/** A table a kon declared as explorable, or a dataset by slug. Exactly one. */
|
|
29
|
+
export type AggregateSource = {
|
|
30
|
+
table: string;
|
|
31
|
+
dataset?: never;
|
|
32
|
+
} | {
|
|
33
|
+
dataset: string;
|
|
34
|
+
table?: never;
|
|
35
|
+
};
|
|
36
|
+
export interface AggregateMeasure {
|
|
37
|
+
fn: AggregateFunction;
|
|
38
|
+
/** Required for everything except `count`, which counts rows. */
|
|
39
|
+
field?: string;
|
|
40
|
+
/** Name of the column in the result. Default: `<fn>` or `<fn>_<field>`. */
|
|
41
|
+
as?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface AggregateDimension {
|
|
44
|
+
field: string;
|
|
45
|
+
/** Truncates a date or timestamp: `month` gives the first day of each month. */
|
|
46
|
+
bucket?: DateBucket;
|
|
47
|
+
as?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AggregateFilter {
|
|
50
|
+
field: string;
|
|
51
|
+
op: AggregateFilterOperator;
|
|
52
|
+
/** `is_null` takes `true` (default) or `false`; `in` takes a list. */
|
|
53
|
+
value?: unknown;
|
|
54
|
+
}
|
|
55
|
+
export interface AggregateOrder {
|
|
56
|
+
/** The `as` of a measure or dimension. */
|
|
57
|
+
by: string;
|
|
58
|
+
dir?: "asc" | "desc";
|
|
59
|
+
}
|
|
60
|
+
export interface AggregateQuery {
|
|
61
|
+
source: AggregateSource;
|
|
62
|
+
measures: AggregateMeasure[];
|
|
63
|
+
groupBy?: AggregateDimension[];
|
|
64
|
+
filters?: AggregateFilter[];
|
|
65
|
+
orderBy?: AggregateOrder[];
|
|
66
|
+
/** Groups returned. Default 100, at most 1000. */
|
|
67
|
+
limit?: number;
|
|
68
|
+
}
|
|
69
|
+
export declare const MAX_AGGREGATE_MEASURES = 10;
|
|
70
|
+
export declare const MAX_AGGREGATE_DIMENSIONS = 4;
|
|
71
|
+
export declare const MAX_AGGREGATE_FILTERS = 20;
|
|
72
|
+
export declare const MAX_AGGREGATE_GROUPS = 1000;
|
|
73
|
+
export declare const DEFAULT_AGGREGATE_GROUPS = 100;
|
|
74
|
+
/** A column, a jsonb key or a result alias: what may appear as an identifier. */
|
|
75
|
+
export declare const AGGREGATE_IDENTIFIER: RegExp;
|
|
76
|
+
export declare function isAggregateIdentifier(value: unknown): value is string;
|
|
77
|
+
/** The result column of a measure when it has no `as`. */
|
|
78
|
+
export declare function measureAlias(measure: AggregateMeasure): string;
|
|
79
|
+
/** The result column of a dimension when it has no `as`. */
|
|
80
|
+
export declare function dimensionAlias(dimension: AggregateDimension): string;
|
|
81
|
+
/**
|
|
82
|
+
* Why the query cannot run, or `null`. Checks SHAPE only: whether the table
|
|
83
|
+
* may be read and whether a column exists is the host's answer, because only
|
|
84
|
+
* the host knows the schema and who is asking.
|
|
85
|
+
*/
|
|
86
|
+
export declare function aggregateQueryProblem(query: unknown): string | null;
|
|
87
|
+
export declare const REPORT_CHART_TYPES: readonly ["table", "number", "bar", "line", "donut"];
|
|
88
|
+
export type ReportChartType = (typeof REPORT_CHART_TYPES)[number];
|
|
89
|
+
/** How the panel should draw the result. A hint: the data is the same either way. */
|
|
90
|
+
export interface ReportChart {
|
|
91
|
+
type: ReportChartType;
|
|
92
|
+
/** Result column for the horizontal axis or the slices. */
|
|
93
|
+
x?: string;
|
|
94
|
+
/** Result columns to plot. */
|
|
95
|
+
y?: string[];
|
|
96
|
+
}
|
|
97
|
+
/** A report a kon ships: `defineKon({ reports })`. Served as `kon:<kon id>/<id>`. */
|
|
98
|
+
export interface ReportDefinition {
|
|
99
|
+
/** Unique inside the kon: `won-per-month`. */
|
|
100
|
+
id: string;
|
|
101
|
+
name: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
query: AggregateQuery;
|
|
104
|
+
chart?: ReportChart;
|
|
105
|
+
}
|
|
106
|
+
export declare const REPORT_ID: RegExp;
|
|
107
|
+
export declare function reportChartProblem(chart: unknown): string | null;
|
|
108
|
+
export declare function reportDefinitionProblem(report: unknown): string | null;
|
|
109
|
+
//# sourceMappingURL=reports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reports.d.ts","sourceRoot":"","sources":["../src/reports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,mBAAmB,kEAAmE,CAAC;AACpG,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,YAAY,sDAAuD,CAAC;AACjF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,eAAO,MAAM,0BAA0B,+EAU7B,CAAC;AACX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAElF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,iBAAiB,CAAC;IACtB,iEAAiE;IACjE,K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