@brightsideoy/kama 1.0.0-alpha.3 → 1.0.0-alpha.31
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/README.md +25 -7
- package/bin/cli.js +539 -359
- package/content/definitions/blocks/button.yaml +15 -5
- package/content/definitions/blocks/form.yaml +20 -0
- package/content/definitions/blocks/image-gallery.yaml +34 -0
- package/content/definitions/blocks/node-list.yaml +75 -0
- package/content/definitions/blocks/youtube.yaml +8 -0
- package/content/definitions/field-sets/access.yaml +14 -0
- package/content/definitions/field-sets/page-base.yaml +19 -1
- package/content/definitions/forms/.gitkeep +0 -0
- package/content/definitions/forms/contact.yaml +38 -0
- package/content/definitions/forms/subscription.yaml +26 -0
- package/content/definitions/nodes/article.yaml +19 -1
- package/content/definitions/taxonomies/categories.yaml +5 -2
- package/content/definitions/taxonomies/media-tag.yaml +15 -0
- package/content/definitions/taxonomies/tags.yaml +5 -2
- package/definitions/editor/default.ts +19 -2
- package/dist/assets/AssetEditor-CAvQEsBT.js +1 -0
- package/dist/assets/AssetEditor-CQtKSOjX.css +1 -0
- package/dist/assets/CmsAccordion-91I5Rx5D.css +1 -0
- package/dist/assets/CmsAccordion-BgdaB8QZ.js +1 -0
- package/dist/assets/CmsBadge-BT2jTJUu.js +1 -0
- package/dist/assets/CmsBadge-Ip5hXw8G.css +1 -0
- package/dist/assets/CmsButton-DATGQeoC.css +1 -0
- package/dist/assets/CmsButton-DnhPsHXA.js +1 -0
- package/dist/assets/CmsFieldTaxonomy-CNY3-MbD.js +1 -0
- package/dist/assets/CmsFieldTaxonomy-CVlKL-l2.css +1 -0
- package/dist/assets/CmsHelp-BO_vWABq.css +1 -0
- package/dist/assets/CmsHelp-DtPeURCv.js +1 -0
- package/dist/assets/CmsImagePreview-BhM7S_v8.js +1 -0
- package/dist/assets/CmsImagePreview-CujwG8r_.css +1 -0
- package/dist/assets/CmsPublisher-BcrQAr1m.css +1 -0
- package/dist/assets/CmsPublisher-DiQhfPID.js +3 -0
- package/dist/assets/CmsUserCenter-CAaiCweN.js +1 -0
- package/dist/assets/CmsUserCenter-D3OZYHD0.css +1 -0
- package/dist/assets/EditorSplitPreview-BfGni85I.js +1 -0
- package/dist/assets/EditorSplitPreview-CMoTjLW5.css +1 -0
- package/dist/assets/FormsWorkspace-CGs6eUjz.css +1 -0
- package/dist/assets/FormsWorkspace-CUK-y2dR.js +2 -0
- package/dist/assets/NodeContextMenu-C5RTK0sr.js +1 -0
- package/dist/assets/NodeContextMenu-Cj-2TvQC.css +1 -0
- package/dist/assets/NodeEditor-C2meZIvc.css +1 -0
- package/dist/assets/NodeEditor-C5VQu52a.js +161 -0
- package/dist/assets/SettingsDashboard-XBOgYUn3.css +1 -0
- package/dist/assets/SettingsDashboard-gzHzxsIc.js +1 -0
- package/dist/assets/StatusPill-Dlm6uvGe.css +1 -0
- package/dist/assets/StatusPill-HY1gCP9c.js +1 -0
- package/dist/assets/TrashWorkspace-DtMgxg13.css +1 -0
- package/dist/assets/TrashWorkspace-t0lOrFRK.js +1 -0
- package/dist/assets/_plugin-vue_export-helper-BK_c4R_m.js +5 -0
- package/dist/assets/circle-check-CksZGUB7.js +1 -0
- package/dist/assets/database--QlkzG9u.js +1 -0
- package/dist/assets/file-U7h4eOhG.js +1 -0
- package/dist/assets/globe-TuZP0v6A.js +1 -0
- package/dist/assets/history-CIbqkRx3.js +1 -0
- package/dist/assets/index-C171UGo4.css +1 -0
- package/dist/assets/index-_Tc6Vb8T.js +14 -0
- package/dist/assets/layers-BwACvD_U.js +1 -0
- package/dist/assets/loader-circle-DYEFqbD4.js +1 -0
- package/dist/assets/panel-left-close-Cpq52HZy.js +1 -0
- package/dist/assets/plus-7rv1C56N.js +1 -0
- package/dist/assets/preload-helper-BB8Wl1va.js +1 -0
- package/dist/assets/preload-helper-BxFQpwa9.css +1 -0
- package/dist/assets/rotate-ccw-DvjWccJd.js +1 -0
- package/dist/assets/save-Dwhm8QNL.js +1 -0
- package/dist/assets/schema-helpers-uuDCw8Rb.js +1 -0
- package/dist/assets/send-Bs4eROle.js +1 -0
- package/dist/assets/smartphone-i429gh5p.js +1 -0
- package/dist/assets/trash-2-BbKTm8cC.js +1 -0
- package/dist/assets/useCmsState-CDENPbKL.js +1 -0
- package/dist/assets/useNodes-D-Vuwq5_.js +1 -0
- package/dist/assets/user-DKryA1QU.js +1 -0
- package/dist/assets/x-DOWbsdzd.js +1 -0
- package/dist/build-seed.js +495 -0
- package/dist/{dist-cK3xGnBZ.js → dist-DKRU6nhX.js} +9254 -5762
- package/dist/index.html +32 -2
- package/dist/index.js +9179 -5689
- package/dist/nodemailer-Ccic7tRm-Dw2jwzbm.js +7877 -0
- package/dist/nodemailer-Ccic7tRm.js +7908 -0
- package/dist/rolldown-runtime-B0aSnxlc.js +20 -0
- package/dist/schema-compiler.js +1 -1
- package/documentation/FORMS.md +261 -0
- package/documentation/SCHEMAS.md +450 -119
- package/package.json +14 -6
- package/schema.sql +46 -1
- package/templates/astro-starter/astro-preview-dev-integration.mjs +83 -0
- package/templates/astro-starter/astro.config.mjs +11 -0
- package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +17 -0
- package/templates/astro-starter/src/components/blocks/Form.astro +313 -0
- package/templates/astro-starter/src/components/blocks/HeaderImage.astro +6 -12
- package/templates/astro-starter/src/components/blocks/ImageBlock.astro +5 -6
- package/templates/astro-starter/src/components/blocks/NodeList.astro +274 -0
- package/templates/astro-starter/src/components/global/NavigationMenu.astro +17 -8
- package/templates/astro-starter/src/components/ui/KamaImage.astro +13 -5
- package/templates/astro-starter/src/layouts/StandardLayout.astro +4 -3
- package/templates/astro-starter/src/lib/cms-fetch.ts +22 -0
- package/templates/astro-starter/src/lib/cms.ts +18 -9
- package/templates/astro-starter/src/lib/media/kama-image-service.ts +15 -4
- package/templates/astro-starter/src/lib/media/media-proxy.ts +22 -3
- package/templates/astro-starter/src/lib/media/media-url.ts +17 -3
- package/templates/astro-starter/src/middleware.ts +199 -71
- package/templates/astro-starter/src/pages/[...slug].astro +122 -45
- package/templates/astro-starter/src/pages/api/forms/[...path].ts +57 -0
- package/templates/astro-starter/src/pages/api/load-nodes.ts +68 -0
- package/templates/astro-starter/src/pages/api/partials/node-cards.astro +98 -0
- package/templates/astro-starter/src/pages/partials/nav.astro +6 -5
- package/templates/kama-worker/index.js +22 -12
- package/templates/kama-worker/setup-local-db.mjs +17 -0
- package/wrangler.json +19 -0
- package/dist/assets/index-C3LzwJjY.css +0 -1
- package/dist/assets/index-DhguVxzs.js +0 -164
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { APIRoute } from "astro";
|
|
2
|
+
import { fetchCmsRequest } from "../../../lib/cms-fetch";
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
7
|
+
const path = params.path?.split("/").filter(Boolean) || [];
|
|
8
|
+
if (path.length !== 2 || path[1] !== "submissions") {
|
|
9
|
+
return new Response("Not Found", { status: 404 });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const safeEnv = (locals as any).safeEnv || {};
|
|
13
|
+
const cmsWorker = safeEnv.CMS_WORKER;
|
|
14
|
+
const apiUrl = String(
|
|
15
|
+
import.meta.env.DEV && !cmsWorker
|
|
16
|
+
? "http://localhost:8787"
|
|
17
|
+
: import.meta.env.PUBLIC_API_URL || safeEnv.PUBLIC_API_URL || "http://localhost:8787"
|
|
18
|
+
).replace(/\/$/, "");
|
|
19
|
+
const formId = encodeURIComponent(path[0]);
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const contentType = request.headers.get("content-type") || "";
|
|
23
|
+
const payload = contentType.includes("application/json")
|
|
24
|
+
? await request.text()
|
|
25
|
+
: JSON.stringify(Object.fromEntries(new URLSearchParams(await request.text()).entries()));
|
|
26
|
+
const backendRequest = new Request(
|
|
27
|
+
`${apiUrl}/api/v1/forms/${formId}/submissions`,
|
|
28
|
+
{
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
Accept: "application/json",
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
},
|
|
34
|
+
body: payload,
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
const response = await fetchCmsRequest(backendRequest, cmsWorker);
|
|
38
|
+
if (request.headers.get("accept")?.includes("text/html")) {
|
|
39
|
+
const result = await response.clone().json().catch(() => ({}));
|
|
40
|
+
const redirectUrl = new URL(request.headers.get("referer") || "/", request.url);
|
|
41
|
+
if (redirectUrl.origin !== new URL(request.url).origin) {
|
|
42
|
+
redirectUrl.pathname = "/";
|
|
43
|
+
redirectUrl.search = "";
|
|
44
|
+
}
|
|
45
|
+
redirectUrl.searchParams.set("formId", path[0]);
|
|
46
|
+
redirectUrl.searchParams.set("formStatus", response.ok && result.success ? "success" : "error");
|
|
47
|
+
if (!(response.ok && result.success)) {
|
|
48
|
+
redirectUrl.searchParams.set("formMessage", result.error || "Form submission failed.");
|
|
49
|
+
}
|
|
50
|
+
return Response.redirect(redirectUrl, 303);
|
|
51
|
+
}
|
|
52
|
+
return response;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("[Forms Proxy] Failed to forward form submission:", error);
|
|
55
|
+
return Response.json({ error: "Could not reach the form submission service." }, { status: 502 });
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/pages/api/load-nodes.ts
|
|
2
|
+
import type { APIRoute } from "astro";
|
|
3
|
+
|
|
4
|
+
export const prerender = false; // Required to ensure this runs server-side on Cloudflare
|
|
5
|
+
|
|
6
|
+
export const GET: APIRoute = async ({ request, locals }) => {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
const searchParams = url.searchParams;
|
|
9
|
+
|
|
10
|
+
// 1. Get Environment Variables securely via middleware
|
|
11
|
+
const cfEnv = (locals as any).safeEnv || {};
|
|
12
|
+
|
|
13
|
+
const cmsWorker = cfEnv.CMS_WORKER;
|
|
14
|
+
const apiUrl = cfEnv.PUBLIC_API_URL || import.meta.env.PUBLIC_API_URL || "http://localhost:8787";
|
|
15
|
+
const secret = cfEnv.FRONTEND_API_SECRET || import.meta.env.FRONTEND_API_SECRET;
|
|
16
|
+
|
|
17
|
+
if (!secret) {
|
|
18
|
+
console.error("🚨 [Load Nodes Proxy] Critical Error: FRONTEND_API_SECRET is missing from the environment!");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 2. Construct the actual backend URL
|
|
22
|
+
const cleanApiUrl = apiUrl.replace(/\/$/, "");
|
|
23
|
+
const backendUrl = `${cleanApiUrl}/api/v1/nodes?${searchParams.toString()}`;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
// 3. Prepare the secure headers
|
|
27
|
+
const reqHeaders: Record<string, string> = {
|
|
28
|
+
"Accept": "application/json",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (secret) {
|
|
32
|
+
reqHeaders["Authorization"] = `Bearer ${secret}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const backendReq = new Request(backendUrl, {
|
|
36
|
+
method: "GET",
|
|
37
|
+
headers: reqHeaders
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 4. Fetch from the CMS securely (Bypass Cloudflare Access via Service Binding)
|
|
41
|
+
let response;
|
|
42
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function") {
|
|
43
|
+
response = await cmsWorker.fetch(backendReq);
|
|
44
|
+
} else {
|
|
45
|
+
response = await fetch(backendReq);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
console.error(`[Load Nodes Proxy] Backend rejected request with status: ${response.status}`);
|
|
50
|
+
return new Response(JSON.stringify({ error: "Failed to fetch nodes" }), { status: response.status });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
|
|
55
|
+
// 5. Return to the browser
|
|
56
|
+
return new Response(JSON.stringify(data), {
|
|
57
|
+
status: 200,
|
|
58
|
+
headers: {
|
|
59
|
+
"Content-Type": "application/json",
|
|
60
|
+
// 🎯 ARCHITECTURE FIX: Cache at the Cloudflare Edge for 60 seconds to eliminate redundant DB queries.
|
|
61
|
+
"Cache-Control": "public, max-age=0, s-maxage=60, stale-while-revalidate=120"
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error("[Load Nodes Proxy] Failed to load nodes:", err);
|
|
66
|
+
return new Response(JSON.stringify({ error: "Internal Server Error" }), { status: 500 });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
// src/pages/api/partials/node-cards.astro
|
|
3
|
+
export const partial = true; // Tells Astro not to inject DOCTYPE or <head> tags
|
|
4
|
+
|
|
5
|
+
import KamaImage from "@/components/ui/KamaImage.astro";
|
|
6
|
+
|
|
7
|
+
const { request, locals } = Astro;
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
const searchParams = url.searchParams;
|
|
10
|
+
|
|
11
|
+
// 1. Get Environment Variables securely via middleware
|
|
12
|
+
const cfEnv = (locals as any).safeEnv || {};
|
|
13
|
+
const cmsWorker = cfEnv.CMS_WORKER;
|
|
14
|
+
const apiUrl =
|
|
15
|
+
cfEnv.PUBLIC_API_URL ||
|
|
16
|
+
import.meta.env.PUBLIC_API_URL ||
|
|
17
|
+
"http://localhost:8787";
|
|
18
|
+
const secret = cfEnv.FRONTEND_API_SECRET || import.meta.env.FRONTEND_API_SECRET;
|
|
19
|
+
|
|
20
|
+
// 2. Construct the actual backend URL
|
|
21
|
+
const cleanApiUrl = apiUrl.replace(/\/$/, "");
|
|
22
|
+
const backendUrl = `${cleanApiUrl}/api/v1/nodes?${searchParams.toString()}`;
|
|
23
|
+
|
|
24
|
+
// 3. Prepare the secure headers
|
|
25
|
+
const reqHeaders: Record<string, string> = { Accept: "application/json" };
|
|
26
|
+
if (secret) reqHeaders["Authorization"] = `Bearer ${secret}`;
|
|
27
|
+
|
|
28
|
+
const backendReq = new Request(backendUrl, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: reqHeaders,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 4. Fetch securely using Service Binding
|
|
34
|
+
let response;
|
|
35
|
+
if (cmsWorker && typeof cmsWorker.fetch === "function") {
|
|
36
|
+
response = await cmsWorker.fetch(backendReq);
|
|
37
|
+
} else {
|
|
38
|
+
response = await fetch(backendReq);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let itemsArray: any[] = [];
|
|
42
|
+
let limit = 12;
|
|
43
|
+
let consumedRows = 0;
|
|
44
|
+
|
|
45
|
+
if (response.ok) {
|
|
46
|
+
const data = await response.json();
|
|
47
|
+
itemsArray = Array.isArray(data)
|
|
48
|
+
? data
|
|
49
|
+
: data.items || data.nodes || data.data || [];
|
|
50
|
+
limit = data.limit || 12;
|
|
51
|
+
consumedRows =
|
|
52
|
+
data.rawCount !== undefined ? data.rawCount : itemsArray.length;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 5. Send pagination data back to the frontend script via custom HTTP Headers
|
|
56
|
+
Astro.response.headers.set("X-Consumed-Rows", consumedRows.toString());
|
|
57
|
+
Astro.response.headers.set("X-Limit", limit.toString());
|
|
58
|
+
Astro.response.headers.set("Cache-Control", "no-store");
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
itemsArray.map((item: any) => {
|
|
63
|
+
const dateStr = item.createdAt
|
|
64
|
+
? new Date(item.createdAt).toLocaleDateString("en-GB", {
|
|
65
|
+
day: "numeric",
|
|
66
|
+
month: "short",
|
|
67
|
+
year: "numeric",
|
|
68
|
+
})
|
|
69
|
+
: "";
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<article class="node-card">
|
|
73
|
+
<a href={`/${item.slug}`} class="node-card-link">
|
|
74
|
+
{item.image ? (
|
|
75
|
+
<KamaImage
|
|
76
|
+
image={item.image}
|
|
77
|
+
sizes="(max-width: 639px) 100vw, (max-width: 1023px) 50vw, 33vw"
|
|
78
|
+
desktopWidths={[320, 640, 768, 1024]}
|
|
79
|
+
idealWidth={429}
|
|
80
|
+
loading="lazy"
|
|
81
|
+
/>
|
|
82
|
+
) : (
|
|
83
|
+
<div class="image-placeholder" />
|
|
84
|
+
)}
|
|
85
|
+
<div class="node-card-content">
|
|
86
|
+
<h3 class="node-card-title">{item.title}</h3>
|
|
87
|
+
{dateStr && (
|
|
88
|
+
<time datetime={item.createdAt} class="node-card-date">
|
|
89
|
+
{dateStr}
|
|
90
|
+
</time>
|
|
91
|
+
)}
|
|
92
|
+
{item.excerpt && <p class="node-card-excerpt">{item.excerpt}</p>}
|
|
93
|
+
</div>
|
|
94
|
+
</a>
|
|
95
|
+
</article>
|
|
96
|
+
);
|
|
97
|
+
})
|
|
98
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export const partial = true; // 🎯 Tells Astro not to wrap this in <html><body>
|
|
4
4
|
|
|
5
5
|
import { getTree, getTreeId, getChannelId } from "@/lib/cms";
|
|
6
|
-
import type
|
|
6
|
+
import { getTreeNodeMenuTitle, type TreeNode } from "@/lib/cms";
|
|
7
7
|
|
|
8
8
|
const safeEnv = (Astro.locals as any).safeEnv || {};
|
|
9
9
|
const cmsWorker = safeEnv.CMS_WORKER;
|
|
@@ -75,6 +75,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
75
75
|
<ul class="nav-list">
|
|
76
76
|
{
|
|
77
77
|
topLevelNavItems.map(item => {
|
|
78
|
+
const menuTitle = getTreeNodeMenuTitle(item);
|
|
78
79
|
const hasChildren = item.children && item.children.length > 0;
|
|
79
80
|
const isParentActive = isPathActive(item.path);
|
|
80
81
|
|
|
@@ -89,7 +90,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
89
90
|
{ active: isParentActive },
|
|
90
91
|
]}
|
|
91
92
|
>
|
|
92
|
-
<span>{
|
|
93
|
+
<span>{menuTitle}</span>
|
|
93
94
|
<span class="indicator">▼</span>
|
|
94
95
|
</summary>
|
|
95
96
|
<div class="submenu-container">
|
|
@@ -103,7 +104,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
103
104
|
{ active: isExactActive(item.path) },
|
|
104
105
|
]}
|
|
105
106
|
>
|
|
106
|
-
{
|
|
107
|
+
{menuTitle} Overview
|
|
107
108
|
</a>
|
|
108
109
|
</li>
|
|
109
110
|
{item.children?.map(child => (
|
|
@@ -115,7 +116,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
115
116
|
{ active: isExactActive(child.path) },
|
|
116
117
|
]}
|
|
117
118
|
>
|
|
118
|
-
{child
|
|
119
|
+
{getTreeNodeMenuTitle(child)}
|
|
119
120
|
</a>
|
|
120
121
|
</li>
|
|
121
122
|
))}
|
|
@@ -132,7 +133,7 @@ const isExactActive = (itemPath?: string) => {
|
|
|
132
133
|
href={item.path}
|
|
133
134
|
class:list={["nav-button", { active: isExactActive(item.path) }]}
|
|
134
135
|
>
|
|
135
|
-
{
|
|
136
|
+
{menuTitle}
|
|
136
137
|
</a>
|
|
137
138
|
</li>
|
|
138
139
|
);
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
// templates/kama-worker/index.js
|
|
2
|
+
import { Hono } from 'hono';
|
|
1
3
|
import kamaWorker from '@brightsideoy/kama';
|
|
2
4
|
import * as localBundle from './bundled-definitions.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
async fetch(request, env, ctx) {
|
|
6
|
-
const schemas = localBundle.BUNDLED_DEFINITIONS || localBundle.default || localBundle;
|
|
7
|
-
const customEnv = { ...env, BUNDLED_DEFINITIONS: schemas, KAMA_RUNTIME: 'cloudflare' };
|
|
6
|
+
const app = new Hono();
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// Mount the precompiled core CMS.
|
|
9
|
+
app.all('*', async (c) => {
|
|
10
|
+
const schemas = localBundle.BUNDLED_DEFINITIONS || localBundle.default || localBundle;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const customEnv = {
|
|
13
|
+
...c.env,
|
|
14
|
+
BUNDLED_DEFINITIONS: schemas,
|
|
15
|
+
KAMA_RUNTIME: 'cloudflare'
|
|
16
|
+
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
if (kamaWorker && typeof kamaWorker.fetch === 'function') {
|
|
19
|
+
return kamaWorker.fetch(c.req.raw, customEnv, c.executionCtx);
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
if (kamaWorker && kamaWorker.app && typeof kamaWorker.app.fetch === 'function') {
|
|
23
|
+
return kamaWorker.app.fetch(c.req.raw, customEnv, c.executionCtx);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new Response('KAMA • ENGINE Ready', { status: 200 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export default app;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { createClient } from '@libsql/client';
|
|
4
|
+
|
|
5
|
+
const mode = process.argv[2] || 'schema';
|
|
6
|
+
const databasePath = process.env.DB_PATH || './kama.db';
|
|
7
|
+
const client = createClient({ url: `file:${databasePath}` });
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const files = mode === 'seed'
|
|
11
|
+
? (await readdir('.')).filter(file => /^seed.*\.sql$/.test(file)).sort()
|
|
12
|
+
: ['../node_modules/@brightsideoy/kama/schema.sql'];
|
|
13
|
+
if (files.length === 0) throw new Error('No generated seed SQL files found.');
|
|
14
|
+
for (const file of files) await client.executeMultiple(await readFile(join(process.cwd(), file), 'utf8'));
|
|
15
|
+
} finally {
|
|
16
|
+
await client.close();
|
|
17
|
+
}
|
package/wrangler.json
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"assets": {
|
|
3
|
+
"directory": "./dist",
|
|
4
|
+
"binding": "ASSETS"
|
|
5
|
+
},
|
|
6
|
+
"images": {
|
|
7
|
+
"binding": "IMAGES"
|
|
8
|
+
},
|
|
9
|
+
"observability": {
|
|
10
|
+
"enabled": true,
|
|
11
|
+
"redact_query_string": true,
|
|
12
|
+
"logs": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"head_sampling_rate": 0.1
|
|
15
|
+
},
|
|
16
|
+
"traces": {
|
|
17
|
+
"enabled": true,
|
|
18
|
+
"head_sampling_rate": 0.02
|
|
19
|
+
}
|
|
20
|
+
},
|
|
2
21
|
"$schema": "node_modules/wrangler/config-schema.json",
|
|
3
22
|
"name": "kama",
|
|
4
23
|
"main": "server/index.ts",
|