@caelo-cms/shared 0.2.2
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/dist/ai-tools.d.ts +571 -0
- package/dist/ai-tools.d.ts.map +1 -0
- package/dist/ai-tools.js +696 -0
- package/dist/ai-tools.js.map +1 -0
- package/dist/auth-forms.d.ts +24 -0
- package/dist/auth-forms.d.ts.map +1 -0
- package/dist/auth-forms.js +27 -0
- package/dist/auth-forms.js.map +1 -0
- package/dist/cap-failures.d.ts +17 -0
- package/dist/cap-failures.d.ts.map +1 -0
- package/dist/cap-failures.js +58 -0
- package/dist/cap-failures.js.map +1 -0
- package/dist/content.d.ts +111 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +137 -0
- package/dist/content.js.map +1 -0
- package/dist/context.d.ts +40 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +3 -0
- package/dist/context.js.map +1 -0
- package/dist/i18n.d.ts +49 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +154 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +56 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +84 -0
- package/dist/logger.js.map +1 -0
- package/dist/media.d.ts +143 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +168 -0
- package/dist/media.js.map +1 -0
- package/dist/preview-compose.d.ts +84 -0
- package/dist/preview-compose.d.ts.map +1 -0
- package/dist/preview-compose.js +385 -0
- package/dist/preview-compose.js.map +1 -0
- package/dist/preview-scanner.d.ts +44 -0
- package/dist/preview-scanner.d.ts.map +1 -0
- package/dist/preview-scanner.js +177 -0
- package/dist/preview-scanner.js.map +1 -0
- package/dist/result.d.ts +21 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +14 -0
- package/dist/result.js.map +1 -0
- package/dist/seo.d.ts +128 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +176 -0
- package/dist/seo.js.map +1 -0
- package/dist/skills.d.ts +88 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +127 -0
- package/dist/skills.js.map +1 -0
- package/dist/snapshots.d.ts +54 -0
- package/dist/snapshots.d.ts.map +1 -0
- package/dist/snapshots.js +59 -0
- package/dist/snapshots.js.map +1 -0
- package/dist/structured-sets.d.ts +116 -0
- package/dist/structured-sets.d.ts.map +1 -0
- package/dist/structured-sets.js +154 -0
- package/dist/structured-sets.js.map +1 -0
- package/dist/subagents.d.ts +123 -0
- package/dist/subagents.d.ts.map +1 -0
- package/dist/subagents.js +202 -0
- package/dist/subagents.js.map +1 -0
- package/dist/translation.d.ts +127 -0
- package/dist/translation.d.ts.map +1 -0
- package/dist/translation.js +208 -0
- package/dist/translation.js.map +1 -0
- package/dist/version.d.ts +46 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +46 -0
- package/dist/version.js.map +1 -0
- package/package.json +38 -0
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* P9 — i18n primitives shared between the static generator, the
|
|
4
|
+
* preview op, and the admin UI:
|
|
5
|
+
*
|
|
6
|
+
* computeContentHash(page, modules) — sha256 of canonical-JSON
|
|
7
|
+
* content. Drives `pages.content_hash` + the translation_status
|
|
8
|
+
* recompute path.
|
|
9
|
+
*
|
|
10
|
+
* resolveLocaleUrl(locale, slug, defaultLocaleCode, siteBaseUrl) —
|
|
11
|
+
* builds the public URL for a (locale, slug) tuple given the
|
|
12
|
+
* locale's url_strategy + url_host. Used by:
|
|
13
|
+
* - hreflang emitter
|
|
14
|
+
* - sitemap.xml emitter (when extended for i18n)
|
|
15
|
+
* - language-selector module
|
|
16
|
+
*
|
|
17
|
+
* buildHreflangLinks(currentLocale, perLocaleUrls, defaultLocaleCode) —
|
|
18
|
+
* emits the `<link rel="alternate" hreflang=...>` markup.
|
|
19
|
+
*
|
|
20
|
+
* lintLocaleConfig(locales, advancedUrlRouting) — surfaces config
|
|
21
|
+
* warnings (mixed strategies, missing url_host for subdomain/
|
|
22
|
+
* domain, default locale using `none` alongside subdirectory
|
|
23
|
+
* siblings, advanced strategy chosen while toggle is off).
|
|
24
|
+
*/
|
|
25
|
+
const TEXT_ENCODER = new TextEncoder();
|
|
26
|
+
/**
|
|
27
|
+
* Build a public-facing URL for a (locale, slug) tuple. Pure function —
|
|
28
|
+
* no DB access — so the static generator can call it for every page
|
|
29
|
+
* without round-trips.
|
|
30
|
+
*
|
|
31
|
+
* @param locale The target locale's full config row.
|
|
32
|
+
* @param slug Path component (e.g. "about", "blog/post-1"). No leading slash.
|
|
33
|
+
* @param siteBaseUrl Default base URL when the strategy is `none` or
|
|
34
|
+
* `subdirectory` (e.g. "https://example.com").
|
|
35
|
+
* @returns Absolute URL, including scheme + host.
|
|
36
|
+
*/
|
|
37
|
+
export function resolveLocaleUrl(locale, slug, siteBaseUrl) {
|
|
38
|
+
const stripped = slug.replace(/^\/+|\/+$/g, "");
|
|
39
|
+
// Home slug + empty/index variants render as the locale root.
|
|
40
|
+
// Non-home slugs get a trailing slash so the URL matches what the
|
|
41
|
+
// static host serves (clean URLs: every page is `<slug>/index.html`,
|
|
42
|
+
// browsers request `<slug>/`). Without this, redirect rows insert
|
|
43
|
+
// `/de/about` while users navigate to `/de/about/` and 301 misses.
|
|
44
|
+
const isHome = stripped === "" || stripped === "home" || stripped === "index";
|
|
45
|
+
const tail = isHome ? "" : `${stripped}/`;
|
|
46
|
+
const base = siteBaseUrl.replace(/\/+$/, "");
|
|
47
|
+
switch (locale.urlStrategy) {
|
|
48
|
+
case "none":
|
|
49
|
+
return tail ? `${base}/${tail}` : `${base}/`;
|
|
50
|
+
case "subdirectory":
|
|
51
|
+
// Default locale with strategy `subdirectory` still gets the prefix
|
|
52
|
+
// unless the migration set strategy=none for it. The decision is
|
|
53
|
+
// explicit per locale row, not implicit on isDefault.
|
|
54
|
+
return tail ? `${base}/${locale.code}/${tail}` : `${base}/${locale.code}/`;
|
|
55
|
+
case "subdomain": {
|
|
56
|
+
if (!locale.urlHost) {
|
|
57
|
+
throw new Error(`locale '${locale.code}' uses url_strategy='subdomain' without url_host — config invalid`);
|
|
58
|
+
}
|
|
59
|
+
const protocol = base.startsWith("http://") ? "http://" : "https://";
|
|
60
|
+
return tail ? `${protocol}${locale.urlHost}/${tail}` : `${protocol}${locale.urlHost}/`;
|
|
61
|
+
}
|
|
62
|
+
case "domain": {
|
|
63
|
+
if (!locale.urlHost) {
|
|
64
|
+
throw new Error(`locale '${locale.code}' uses url_strategy='domain' without url_host — config invalid`);
|
|
65
|
+
}
|
|
66
|
+
const protocol = base.startsWith("http://") ? "http://" : "https://";
|
|
67
|
+
return tail ? `${protocol}${locale.urlHost}/${tail}` : `${protocol}${locale.urlHost}/`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Emit `<link rel="alternate" hreflang="…">` tags for every locale
|
|
73
|
+
* that has a published variant of this page. The default locale also
|
|
74
|
+
* gets an `x-default` entry per Google's i18n guidance.
|
|
75
|
+
*
|
|
76
|
+
* Returned as a single string suitable for splicing into <head>.
|
|
77
|
+
*/
|
|
78
|
+
export function buildHreflangLinks(perLocaleUrls) {
|
|
79
|
+
if (perLocaleUrls.length === 0)
|
|
80
|
+
return "";
|
|
81
|
+
const lines = [];
|
|
82
|
+
for (const v of perLocaleUrls) {
|
|
83
|
+
lines.push(`<link rel="alternate" hreflang="${escapeAttr(v.localeCode)}" href="${escapeAttr(v.url)}" />`);
|
|
84
|
+
}
|
|
85
|
+
const def = perLocaleUrls.find((v) => v.isDefault);
|
|
86
|
+
if (def) {
|
|
87
|
+
lines.push(`<link rel="alternate" hreflang="x-default" href="${escapeAttr(def.url)}" />`);
|
|
88
|
+
}
|
|
89
|
+
return lines.join("\n");
|
|
90
|
+
}
|
|
91
|
+
function escapeAttr(s) {
|
|
92
|
+
return s
|
|
93
|
+
.replace(/&/g, "&")
|
|
94
|
+
.replace(/"/g, """)
|
|
95
|
+
.replace(/</g, "<")
|
|
96
|
+
.replace(/>/g, ">");
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Canonical-JSON serializer + sha256 → hex. Stable across runs because
|
|
100
|
+
* keys are sorted. The output is used for `pages.content_hash` so that
|
|
101
|
+
* a Mode-2 translation can detect whether its source has changed.
|
|
102
|
+
*/
|
|
103
|
+
export async function computeContentHash(value) {
|
|
104
|
+
const canonical = JSON.stringify(value, (_key, val) => {
|
|
105
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
106
|
+
const sorted = {};
|
|
107
|
+
for (const k of Object.keys(val).sort())
|
|
108
|
+
sorted[k] = val[k];
|
|
109
|
+
return sorted;
|
|
110
|
+
}
|
|
111
|
+
return val;
|
|
112
|
+
});
|
|
113
|
+
const digest = await crypto.subtle.digest("SHA-256", TEXT_ENCODER.encode(canonical));
|
|
114
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Cross-row config sanity checks. Run at:
|
|
118
|
+
* - propose-time (warnings stored on the proposal preview)
|
|
119
|
+
* - render-time (no fail-loudly per CLAUDE.md §2 since the renderer
|
|
120
|
+
* can still emit; surfaced in admin UI as banners)
|
|
121
|
+
*/
|
|
122
|
+
export function lintLocaleConfig(locales, advancedUrlRouting) {
|
|
123
|
+
const warnings = [];
|
|
124
|
+
const usingAdvanced = locales.some((l) => l.urlStrategy === "subdomain" || l.urlStrategy === "domain");
|
|
125
|
+
if (usingAdvanced && !advancedUrlRouting) {
|
|
126
|
+
warnings.push({
|
|
127
|
+
code: "advanced-routing-disabled",
|
|
128
|
+
message: "one or more locales use 'subdomain' or 'domain' strategy but Advanced URL Routing is disabled — enable it under /security/locales",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
for (const l of locales) {
|
|
132
|
+
if ((l.urlStrategy === "subdomain" || l.urlStrategy === "domain") && !l.urlHost) {
|
|
133
|
+
warnings.push({
|
|
134
|
+
code: "missing-url-host",
|
|
135
|
+
message: `locale '${l.code}' uses url_strategy='${l.urlStrategy}' without url_host`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Default-locale 'none' alongside subdirectory siblings is a common
|
|
140
|
+
// mixed config; surface it so users know the default's URL stays bare
|
|
141
|
+
// while siblings get prefixed.
|
|
142
|
+
const def = locales.find((l) => l.isDefault);
|
|
143
|
+
const subdirSiblings = locales.filter((l) => !l.isDefault && l.urlStrategy === "subdirectory");
|
|
144
|
+
if (def && def.urlStrategy === "none" && subdirSiblings.length > 0) {
|
|
145
|
+
warnings.push({
|
|
146
|
+
code: "mixed-default-none-subdir",
|
|
147
|
+
message: `default locale '${def.code}' uses 'none' while ${subdirSiblings
|
|
148
|
+
.map((l) => l.code)
|
|
149
|
+
.join(", ")} use 'subdirectory' — this is valid but unusual; verify hreflang renders correctly`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return warnings;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AAUvC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB,EAAE,IAAY,EAAE,WAAmB;IACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAChD,8DAA8D;IAC9D,kEAAkE;IAClE,qEAA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CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const PROJECT_NAME = "caelo-cms";
|
|
2
|
+
export * from "./ai-tools.js";
|
|
3
|
+
export * from "./auth-forms.js";
|
|
4
|
+
export * from "./cap-failures.js";
|
|
5
|
+
export * from "./content.js";
|
|
6
|
+
export * from "./context.js";
|
|
7
|
+
export * from "./i18n.js";
|
|
8
|
+
export { type LogContext, type Logger, type LoggerOptions, type LogLevel, makeLogger, mintRequestId, redact, type ServiceName, type StructuredLogEntry, } from "./logger.js";
|
|
9
|
+
export * from "./media.js";
|
|
10
|
+
export * from "./preview-compose.js";
|
|
11
|
+
export * from "./preview-scanner.js";
|
|
12
|
+
export * from "./result.js";
|
|
13
|
+
export * from "./seo.js";
|
|
14
|
+
export * from "./skills.js";
|
|
15
|
+
export * from "./snapshots.js";
|
|
16
|
+
export * from "./structured-sets.js";
|
|
17
|
+
export * from "./subagents.js";
|
|
18
|
+
export * from "./translation.js";
|
|
19
|
+
export { CAELO_VERSION, CALEO_VERSION, type CaeloVersion, parseVersion } from "./version.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,UAAU,EACV,aAAa,EACb,MAAM,EACN,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
export const PROJECT_NAME = "caelo-cms";
|
|
3
|
+
export * from "./ai-tools.js";
|
|
4
|
+
export * from "./auth-forms.js";
|
|
5
|
+
export * from "./cap-failures.js";
|
|
6
|
+
export * from "./content.js";
|
|
7
|
+
export * from "./context.js";
|
|
8
|
+
export * from "./i18n.js";
|
|
9
|
+
export { makeLogger, mintRequestId, redact, } from "./logger.js";
|
|
10
|
+
export * from "./media.js";
|
|
11
|
+
export * from "./preview-compose.js";
|
|
12
|
+
export * from "./preview-scanner.js";
|
|
13
|
+
export * from "./result.js";
|
|
14
|
+
export * from "./seo.js";
|
|
15
|
+
export * from "./skills.js";
|
|
16
|
+
export * from "./snapshots.js";
|
|
17
|
+
export * from "./structured-sets.js";
|
|
18
|
+
export * from "./subagents.js";
|
|
19
|
+
export * from "./translation.js";
|
|
20
|
+
export { CAELO_VERSION, CALEO_VERSION, parseVersion } from "./version.js";
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AAExC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAKL,UAAU,EACV,aAAa,EACb,MAAM,GAGP,MAAM,aAAa,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAqB,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P16 — structured logger. JSON-per-line to stderr; the host environment
|
|
3
|
+
* (operator's log aggregator: Loki/Datadog/CloudWatch/etc.) ships from
|
|
4
|
+
* there. Stable shape across every Caelo service so a single
|
|
5
|
+
* `request_id` query reconstructs the full timeline.
|
|
6
|
+
*
|
|
7
|
+
* Redaction pass replaces values for keys matching common-secret regex
|
|
8
|
+
* with `***` so a stray `{password: "..."}` extra never lands in logs.
|
|
9
|
+
*
|
|
10
|
+
* NOT a replacement for `audit_events` — audit captures intent (op,
|
|
11
|
+
* actor, succeeded), structured logs capture trace (request_id,
|
|
12
|
+
* service-to-service hops, latency, errors). Cross-correlate via the
|
|
13
|
+
* shared `request_id` column.
|
|
14
|
+
*/
|
|
15
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
16
|
+
export type ServiceName = "admin" | "gateway" | "orchestrator" | "plugin-host" | "static-gen";
|
|
17
|
+
export interface LogContext {
|
|
18
|
+
readonly requestId: string;
|
|
19
|
+
readonly actorId?: string;
|
|
20
|
+
readonly actorKind?: "human" | "ai" | "system" | "plugin";
|
|
21
|
+
readonly opName?: string;
|
|
22
|
+
readonly chatSessionId?: string;
|
|
23
|
+
readonly pluginSlug?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface StructuredLogEntry {
|
|
26
|
+
readonly ts: string;
|
|
27
|
+
readonly level: LogLevel;
|
|
28
|
+
readonly msg: string;
|
|
29
|
+
readonly service: ServiceName;
|
|
30
|
+
readonly env: string;
|
|
31
|
+
readonly ctx: LogContext;
|
|
32
|
+
readonly extra?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export declare function redact(input: unknown): unknown;
|
|
35
|
+
export interface Logger {
|
|
36
|
+
with(ctx: Partial<LogContext>): Logger;
|
|
37
|
+
debug(msg: string, extra?: Record<string, unknown>): void;
|
|
38
|
+
info(msg: string, extra?: Record<string, unknown>): void;
|
|
39
|
+
warn(msg: string, extra?: Record<string, unknown>): void;
|
|
40
|
+
error(msg: string, extra?: Record<string, unknown>): void;
|
|
41
|
+
}
|
|
42
|
+
export interface LoggerOptions {
|
|
43
|
+
readonly service: ServiceName;
|
|
44
|
+
readonly env?: string;
|
|
45
|
+
/** Defaults to console.error so structured logs flow to stderr. */
|
|
46
|
+
readonly sink?: (entry: StructuredLogEntry) => void;
|
|
47
|
+
/** Minimum level to emit; default 'info' (suppresses 'debug'). */
|
|
48
|
+
readonly minLevel?: LogLevel;
|
|
49
|
+
}
|
|
50
|
+
export declare function makeLogger(opts: LoggerOptions): Logger;
|
|
51
|
+
/**
|
|
52
|
+
* Mint a fresh request_id at a request boundary. Caller threads through
|
|
53
|
+
* ExecutionContext + outbound HTTP headers (`X-Caelo-Request-Id`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function mintRequestId(): string;
|
|
56
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAA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,GAAG,IAAI,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3D;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACpD,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AASD,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAqDtD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
// Word-anchored — without the boundaries `key` would match `monkey`,
|
|
3
|
+
// `token` would match `tokenizer`, `secret` would match `secretary`.
|
|
4
|
+
// Whole-key match is the right semantic for log-field redaction.
|
|
5
|
+
const SECRET_KEY_RE = /^(password|passwd|secret|secrets|token|tokens|api[-_]?key|api[-_]?keys|cookie|cookies|authorization|bearer|x[-_]api[-_]?key|csrf[-_]?secret|cookie[-_]?secret)$/i;
|
|
6
|
+
export function redact(input) {
|
|
7
|
+
if (input === null || typeof input !== "object")
|
|
8
|
+
return input;
|
|
9
|
+
if (Array.isArray(input))
|
|
10
|
+
return input.map(redact);
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [k, v] of Object.entries(input)) {
|
|
13
|
+
if (SECRET_KEY_RE.test(k)) {
|
|
14
|
+
out[k] = "***";
|
|
15
|
+
}
|
|
16
|
+
else if (v && typeof v === "object") {
|
|
17
|
+
out[k] = redact(v);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
out[k] = v;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
const LEVEL_RANK = {
|
|
26
|
+
debug: 10,
|
|
27
|
+
info: 20,
|
|
28
|
+
warn: 30,
|
|
29
|
+
error: 40,
|
|
30
|
+
};
|
|
31
|
+
export function makeLogger(opts) {
|
|
32
|
+
const env = opts.env ?? process.env.CAELO_ENV ?? "dev";
|
|
33
|
+
const minRank = LEVEL_RANK[opts.minLevel ?? "info"];
|
|
34
|
+
const sink = opts.sink ??
|
|
35
|
+
((entry) => {
|
|
36
|
+
// biome-ignore lint/suspicious/noConsole: structured logger sink
|
|
37
|
+
process.stderr.write(`${JSON.stringify(entry)}\n`);
|
|
38
|
+
});
|
|
39
|
+
function emit(ctx, level, msg, extra) {
|
|
40
|
+
if (LEVEL_RANK[level] < minRank)
|
|
41
|
+
return;
|
|
42
|
+
const entry = {
|
|
43
|
+
ts: new Date().toISOString(),
|
|
44
|
+
level,
|
|
45
|
+
msg,
|
|
46
|
+
service: opts.service,
|
|
47
|
+
env,
|
|
48
|
+
ctx,
|
|
49
|
+
extra: extra ? redact(extra) : undefined,
|
|
50
|
+
};
|
|
51
|
+
sink(entry);
|
|
52
|
+
}
|
|
53
|
+
function buildLogger(ctx) {
|
|
54
|
+
return {
|
|
55
|
+
with(extraCtx) {
|
|
56
|
+
return buildLogger({ ...ctx, ...extraCtx });
|
|
57
|
+
},
|
|
58
|
+
debug(msg, extra) {
|
|
59
|
+
emit(ctx, "debug", msg, extra);
|
|
60
|
+
},
|
|
61
|
+
info(msg, extra) {
|
|
62
|
+
emit(ctx, "info", msg, extra);
|
|
63
|
+
},
|
|
64
|
+
warn(msg, extra) {
|
|
65
|
+
emit(ctx, "warn", msg, extra);
|
|
66
|
+
},
|
|
67
|
+
error(msg, extra) {
|
|
68
|
+
emit(ctx, "error", msg, extra);
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Default ctx has a synthetic request_id so a logger created outside
|
|
73
|
+
// of any request boundary still produces correlatable output (visible
|
|
74
|
+
// in the log stream as `synthetic-…`).
|
|
75
|
+
return buildLogger({ requestId: `synthetic-${crypto.randomUUID().slice(0, 8)}` });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Mint a fresh request_id at a request boundary. Caller threads through
|
|
79
|
+
* ExecutionContext + outbound HTTP headers (`X-Caelo-Request-Id`).
|
|
80
|
+
*/
|
|
81
|
+
export function mintRequestId() {
|
|
82
|
+
return crypto.randomUUID();
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAwCnC,qEAAqE;AACrE,qEAAqE;AACrE,iEAAiE;AACjE,MAAM,aAAa,GACjB,kKAAkK,CAAC;AAErK,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACnD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1B,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QACjB,CAAC;aAAM,IAAI,CAAC,IAAI,OAAO,CAAC,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CAAC,GAAe;QAClC,OAAO;YACL,IAAI,CAAC,QAAQ;gBACX,OAAO,WAAW,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;YAC9C,CAAC;YACD,KAAK,CAAC,GAAG,EAAE,KAAK;gBACd,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YACjC,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,KAAK;gBACb,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,CAAC,GAAG,EAAE,KAAK;gBACb,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;YACD,KAAK,CAAC,GAAG,EAAE,KAAK;gBACd,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;YACjC,CAAC;SACF,CAAC;IACJ,CAAC;IAED,qEAAqE;IACrE,sEAAsE;IACtE,uCAAuC;IACvC,OAAO,WAAW,CAAC,EAAE,SAAS,EAAE,aAAa,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media library — shared primitives.
|
|
3
|
+
*
|
|
4
|
+
* Browser-safe: Zod schemas, MIME allowlist, size caps, the variant
|
|
5
|
+
* convention. Sharp + filesystem adapters live in `@caelo-cms/admin-core`
|
|
6
|
+
* (server-only). The storage-key shape is stable here so the static
|
|
7
|
+
* generator's URL rewriter and the admin's iframe resolver agree on
|
|
8
|
+
* the canonical form `<sha>/<variant>.<ext>`.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
/**
|
|
12
|
+
* Allowlisted MIME types. Anything outside this set is rejected at the
|
|
13
|
+
* upload endpoint with `415 Unsupported Media Type`. SVG is allowed
|
|
14
|
+
* but capped tight to discourage XSS via embedded scripts; the upload
|
|
15
|
+
* pipeline strips `<script>` and event-handler attributes before
|
|
16
|
+
* persisting (see {@link sanitizeSvg} in admin-core).
|
|
17
|
+
*/
|
|
18
|
+
export declare const MEDIA_ALLOWED_MIMES: readonly ["image/jpeg", "image/png", "image/webp", "image/avif", "image/gif", "image/svg+xml", "application/pdf", "video/mp4"];
|
|
19
|
+
export type MediaMime = (typeof MEDIA_ALLOWED_MIMES)[number];
|
|
20
|
+
/** Per-MIME size caps (bytes). Server enforces; client display only. */
|
|
21
|
+
export declare const MEDIA_SIZE_CAPS: Record<MediaMime, number>;
|
|
22
|
+
/** Hard ceiling on the multipart body. Per-MIME caps narrow further. */
|
|
23
|
+
export declare const MEDIA_HARD_LIMIT_BYTES: number;
|
|
24
|
+
/**
|
|
25
|
+
* Variant tags. `orig` is always present (re-encoded only for SVG
|
|
26
|
+
* sanitisation). Image-only WebP variants are emitted at breakpoints
|
|
27
|
+
* the source can satisfy — a 600px-wide source skips webp-1200 +
|
|
28
|
+
* webp-1600 entirely.
|
|
29
|
+
*/
|
|
30
|
+
export declare const MEDIA_VARIANT_TAGS: readonly ["orig", "webp-1600", "webp-1200", "webp-800", "webp-400"];
|
|
31
|
+
export type MediaVariantTag = (typeof MEDIA_VARIANT_TAGS)[number];
|
|
32
|
+
/** Width-in-pixels target for each WebP variant. */
|
|
33
|
+
export declare const MEDIA_VARIANT_WIDTHS: Record<Exclude<MediaVariantTag, "orig">, number>;
|
|
34
|
+
/**
|
|
35
|
+
* Renderer-agnostic asset URL used in module HTML. Both the SvelteKit
|
|
36
|
+
* admin endpoint and the static generator's media-pass parse this
|
|
37
|
+
* shape; the static generator rewrites to `/_assets/...` (or a CDN
|
|
38
|
+
* URL) at deploy time.
|
|
39
|
+
*
|
|
40
|
+
* Format: `/_caelo/media/<asset-id>/<variant>`. The asset id, not the
|
|
41
|
+
* sha, so URLs survive a re-upload of the same content under a new id.
|
|
42
|
+
*/
|
|
43
|
+
export declare const MEDIA_URL_PREFIX = "/_caelo/media";
|
|
44
|
+
export declare function buildMediaUrl(assetId: string, variant: MediaVariantTag): string;
|
|
45
|
+
/**
|
|
46
|
+
* Extract every (assetId, variant) pair referenced in an HTML string.
|
|
47
|
+
* Used by the post-write usage-tracker and by the static-generator
|
|
48
|
+
* media-pass. Returns a deduped list to keep callers' work proportional
|
|
49
|
+
* to unique assets, not raw match count.
|
|
50
|
+
*/
|
|
51
|
+
export declare function extractMediaRefs(html: string): {
|
|
52
|
+
assetId: string;
|
|
53
|
+
variant: string;
|
|
54
|
+
}[];
|
|
55
|
+
export declare const mediaUploadInputSchema: z.ZodObject<{
|
|
56
|
+
sha256: z.ZodString;
|
|
57
|
+
originalName: z.ZodString;
|
|
58
|
+
mime: z.ZodEnum<{
|
|
59
|
+
"image/jpeg": "image/jpeg";
|
|
60
|
+
"image/png": "image/png";
|
|
61
|
+
"image/webp": "image/webp";
|
|
62
|
+
"image/avif": "image/avif";
|
|
63
|
+
"image/gif": "image/gif";
|
|
64
|
+
"image/svg+xml": "image/svg+xml";
|
|
65
|
+
"application/pdf": "application/pdf";
|
|
66
|
+
"video/mp4": "video/mp4";
|
|
67
|
+
}>;
|
|
68
|
+
sizeBytes: z.ZodNumber;
|
|
69
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
70
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
71
|
+
alt: z.ZodDefault<z.ZodString>;
|
|
72
|
+
storageKey: z.ZodString;
|
|
73
|
+
storageProvider: z.ZodDefault<z.ZodString>;
|
|
74
|
+
variants: z.ZodArray<z.ZodObject<{
|
|
75
|
+
variant: z.ZodString;
|
|
76
|
+
format: z.ZodString;
|
|
77
|
+
width: z.ZodNullable<z.ZodNumber>;
|
|
78
|
+
height: z.ZodNullable<z.ZodNumber>;
|
|
79
|
+
sizeBytes: z.ZodNumber;
|
|
80
|
+
storageKey: z.ZodString;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
}, z.core.$strict>;
|
|
83
|
+
export type MediaUploadInput = z.infer<typeof mediaUploadInputSchema>;
|
|
84
|
+
export declare const mediaListInputSchema: z.ZodObject<{
|
|
85
|
+
query: z.ZodOptional<z.ZodString>;
|
|
86
|
+
mime: z.ZodOptional<z.ZodEnum<{
|
|
87
|
+
"image/jpeg": "image/jpeg";
|
|
88
|
+
"image/png": "image/png";
|
|
89
|
+
"image/webp": "image/webp";
|
|
90
|
+
"image/avif": "image/avif";
|
|
91
|
+
"image/gif": "image/gif";
|
|
92
|
+
"image/svg+xml": "image/svg+xml";
|
|
93
|
+
"application/pdf": "application/pdf";
|
|
94
|
+
"video/mp4": "video/mp4";
|
|
95
|
+
}>>;
|
|
96
|
+
sort: z.ZodDefault<z.ZodEnum<{
|
|
97
|
+
recent: "recent";
|
|
98
|
+
most_used: "most_used";
|
|
99
|
+
}>>;
|
|
100
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
101
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
102
|
+
}, z.core.$strict>;
|
|
103
|
+
export type MediaListInput = z.infer<typeof mediaListInputSchema>;
|
|
104
|
+
export declare const mediaUpdateAltInputSchema: z.ZodObject<{
|
|
105
|
+
assetId: z.ZodString;
|
|
106
|
+
alt: z.ZodString;
|
|
107
|
+
}, z.core.$strict>;
|
|
108
|
+
export type MediaUpdateAltInput = z.infer<typeof mediaUpdateAltInputSchema>;
|
|
109
|
+
export declare const mediaDeleteInputSchema: z.ZodObject<{
|
|
110
|
+
assetId: z.ZodString;
|
|
111
|
+
force: z.ZodDefault<z.ZodBoolean>;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
export declare const mediaRecordUsageInputSchema: z.ZodObject<{
|
|
114
|
+
deltas: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
115
|
+
}, z.core.$strict>;
|
|
116
|
+
export type MediaRecordUsageInput = z.infer<typeof mediaRecordUsageInputSchema>;
|
|
117
|
+
export declare const mediaRecentForAiInputSchema: z.ZodObject<{
|
|
118
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
119
|
+
}, z.core.$strict>;
|
|
120
|
+
export declare const mediaSetCdnInputSchema: z.ZodObject<{
|
|
121
|
+
enabled: z.ZodBoolean;
|
|
122
|
+
threshold: z.ZodNumber;
|
|
123
|
+
}, z.core.$strict>;
|
|
124
|
+
export type MediaSetCdnInput = z.infer<typeof mediaSetCdnInputSchema>;
|
|
125
|
+
/**
|
|
126
|
+
* Object-storage abstraction. The DB never holds blob bytes — only
|
|
127
|
+
* metadata + the storage key. Adapters are responsible for the full
|
|
128
|
+
* key→bytes round-trip; the URL form they expose is renderer-agnostic
|
|
129
|
+
* (LocalVolumeAdapter returns `/_caelo/media/<assetId>/<variant>` so
|
|
130
|
+
* the SvelteKit endpoint can resolve; cloud adapters can return CDN
|
|
131
|
+
* URLs directly).
|
|
132
|
+
*/
|
|
133
|
+
export interface MediaStorageAdapter {
|
|
134
|
+
put(key: string, body: Uint8Array, contentType: string): Promise<void>;
|
|
135
|
+
get(key: string): Promise<Uint8Array>;
|
|
136
|
+
delete(key: string): Promise<void>;
|
|
137
|
+
exists(key: string): Promise<boolean>;
|
|
138
|
+
/** Bytes-on-disk for capacity reporting. */
|
|
139
|
+
totalSizeBytes(): Promise<number>;
|
|
140
|
+
}
|
|
141
|
+
/** Build the canonical storage key for a given asset variant. */
|
|
142
|
+
export declare function buildStorageKey(sha256: string, variant: MediaVariantTag | string, ext: string): string;
|
|
143
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,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