@kidecms/core 0.16.0 → 0.16.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/admin/components/ContentEditor.tsx +1 -1
- package/admin/components/RichTextEditor.tsx +2 -2
- package/admin/components/ui/button.tsx +2 -2
- package/admin/components/ui/checkbox.tsx +1 -1
- package/admin/components/ui/input.tsx +1 -1
- package/admin/components/ui/select.tsx +1 -1
- package/admin/components/ui/textarea.tsx +1 -1
- package/core/define.ts +0 -7
- package/core/index.ts +0 -1
- package/core/runtime.ts +2 -0
- package/internals/integration.ts +9 -8
- package/middleware/auth.ts +10 -3
- package/package.json +1 -1
- package/routes/uploads/[...path].ts +61 -0
- package/platform/cloudflare/uploads-route.ts +0 -37
|
@@ -565,7 +565,7 @@ export default function ContentEditor({
|
|
|
565
565
|
className={cn(
|
|
566
566
|
isFullscreen
|
|
567
567
|
? "bg-background fixed inset-0 z-50 flex flex-col"
|
|
568
|
-
: "border-input hover:border-foreground/20 bg-muted/30 dark:bg-input/
|
|
568
|
+
: "border-input hover:border-foreground/20 bg-muted/30 dark:bg-input/10 relative overflow-hidden rounded-lg border transition-colors",
|
|
569
569
|
)}
|
|
570
570
|
>
|
|
571
571
|
<input ref={hiddenRef} type="hidden" name={name} value={cmsJson} />
|
|
@@ -320,7 +320,7 @@ export function LinkDialog({
|
|
|
320
320
|
role="combobox"
|
|
321
321
|
aria-expanded={comboOpen}
|
|
322
322
|
size="lg"
|
|
323
|
-
className="border-input bg-muted/30 hover:bg-muted dark:bg-input/
|
|
323
|
+
className="border-input bg-muted/30 hover:bg-muted dark:bg-input/20 dark:hover:bg-input/40 w-full justify-between text-sm font-normal"
|
|
324
324
|
>
|
|
325
325
|
<span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
|
|
326
326
|
{selectedLabel || "Search documents..."}
|
|
@@ -514,7 +514,7 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
|
|
|
514
514
|
<input ref={hiddenRef} type="hidden" name={name} value={cmsJson} />
|
|
515
515
|
|
|
516
516
|
{/* Toolbar */}
|
|
517
|
-
<div className="bg-muted/40 dark:bg-input/
|
|
517
|
+
<div className="bg-muted/40 dark:bg-input/10 flex flex-wrap items-center gap-0.5 border-b px-2 py-1.5">
|
|
518
518
|
<ToolbarButton
|
|
519
519
|
onClick={() => editor?.chain().focus().toggleBold().run()}
|
|
520
520
|
active={editor?.isActive("bold")}
|
|
@@ -11,8 +11,8 @@ const buttonVariants = cva(
|
|
|
11
11
|
default:
|
|
12
12
|
"bg-indigo-100 hover:bg-indigo-200/70 text-indigo-900 border-indigo-300 dark:bg-indigo-500/30 dark:hover:bg-indigo-500/40 dark:border-indigo-600 dark:text-indigo-100",
|
|
13
13
|
outline:
|
|
14
|
-
"border-input hover:border-foreground/20 bg-muted-strong/40 hover:bg-muted-strong/60 hover:text-foreground aria-expanded:bg-muted-strong/60 aria-expanded:text-foreground dark:border-input dark:hover:border-foreground/20 dark:bg-input/
|
|
15
|
-
input: "border-input hover:border-foreground/25 bg-muted/30 dark:bg-input/
|
|
14
|
+
"border-input hover:border-foreground/20 bg-muted-strong/40 hover:bg-muted-strong/60 hover:text-foreground aria-expanded:bg-muted-strong/60 aria-expanded:text-foreground dark:border-input dark:hover:border-foreground/20 dark:bg-input/20 dark:hover:bg-input/40",
|
|
15
|
+
input: "border-input hover:border-foreground/25 bg-muted/30 dark:bg-input/20 dark:hover:border-foreground/25",
|
|
16
16
|
secondary:
|
|
17
17
|
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
18
18
|
publish:
|
|
@@ -10,7 +10,7 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
|
|
|
10
10
|
<CheckboxPrimitive.Root
|
|
11
11
|
data-slot="checkbox"
|
|
12
12
|
className={cn(
|
|
13
|
-
"peer border-foreground/35 hover:border-primary/60 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/
|
|
13
|
+
"peer border-foreground/35 hover:border-primary/60 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/10 dark:border-foreground/40 dark:hover:border-primary/60 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary disabled:hover:border-foreground/35 relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
14
14
|
className,
|
|
15
15
|
)}
|
|
16
16
|
{...props}
|
|
@@ -9,7 +9,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
|
9
9
|
type={type}
|
|
10
10
|
data-slot="input"
|
|
11
11
|
className={cn(
|
|
12
|
-
"border-input hover:border-foreground/25 file:text-foreground placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/
|
|
12
|
+
"border-input hover:border-foreground/25 file:text-foreground placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/10 dark:disabled:bg-input/60 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 read-only:hover:border-input read-only:text-muted-foreground h-9 w-full min-w-0 rounded-lg border px-3 py-1.5 text-sm transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:font-medium read-only:cursor-not-allowed disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
13
13
|
className,
|
|
14
14
|
)}
|
|
15
15
|
{...props}
|
|
@@ -29,7 +29,7 @@ function SelectTrigger({
|
|
|
29
29
|
data-slot="select-trigger"
|
|
30
30
|
data-size={size}
|
|
31
31
|
className={cn(
|
|
32
|
-
"border-input hover:border-foreground/25 dark:hover:border-foreground/25 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:bg-input/
|
|
32
|
+
"border-input hover:border-foreground/25 dark:hover:border-foreground/25 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:bg-input/10 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 flex w-fit items-center justify-between gap-1.5 rounded-lg border py-1.5 pr-3 pl-3 text-sm whitespace-nowrap transition-colors outline-none select-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 data-[size=default]:h-9 data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
33
33
|
className,
|
|
34
34
|
)}
|
|
35
35
|
{...props}
|
|
@@ -7,7 +7,7 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|
|
7
7
|
<textarea
|
|
8
8
|
data-slot="textarea"
|
|
9
9
|
className={cn(
|
|
10
|
-
"border-input hover:border-foreground/25 placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/
|
|
10
|
+
"border-input hover:border-foreground/25 placeholder:text-muted-foreground disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:bg-input/10 dark:disabled:bg-input/60 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/30 read-only:hover:border-input read-only:text-muted-foreground flex field-sizing-content min-h-16 w-full rounded-lg border px-3 py-2.5 text-sm transition-colors outline-none read-only:cursor-not-allowed disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3",
|
|
11
11
|
className,
|
|
12
12
|
)}
|
|
13
13
|
{...props}
|
package/core/define.ts
CHANGED
|
@@ -3,11 +3,6 @@ export type CollectionLabels = {
|
|
|
3
3
|
plural: string;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
export type DatabaseConfig = {
|
|
7
|
-
dialect: "sqlite" | "postgres";
|
|
8
|
-
url?: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
6
|
export type LocaleConfig = {
|
|
12
7
|
default: string;
|
|
13
8
|
supported: string[];
|
|
@@ -42,7 +37,6 @@ type BaseFieldConfig<TType extends string, TValue = unknown> = {
|
|
|
42
37
|
description?: string;
|
|
43
38
|
required?: boolean;
|
|
44
39
|
defaultValue?: TValue;
|
|
45
|
-
indexed?: boolean;
|
|
46
40
|
unique?: boolean;
|
|
47
41
|
translatable?: boolean;
|
|
48
42
|
condition?: FieldCondition;
|
|
@@ -446,7 +440,6 @@ export const isApprover = (config: CMSConfig, role: string | null | undefined):
|
|
|
446
440
|
};
|
|
447
441
|
|
|
448
442
|
export type CMSConfig = {
|
|
449
|
-
database?: DatabaseConfig;
|
|
450
443
|
locales?: LocaleConfig;
|
|
451
444
|
admin?: AdminConfig;
|
|
452
445
|
images?: ImagesConfig;
|
package/core/index.ts
CHANGED
package/core/runtime.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type CmsStorageAdapter = {
|
|
|
2
2
|
putFile: (storagePath: string, data: ArrayBuffer | Uint8Array) => Promise<void>;
|
|
3
3
|
getFile: (storagePath: string) => Promise<ArrayBuffer | null>;
|
|
4
4
|
deleteFile: (storagePath: string) => Promise<void>;
|
|
5
|
+
/** Optional streaming read — the /uploads route buffers via getFile when absent. */
|
|
6
|
+
getFileStream?: (storagePath: string) => Promise<{ body: ReadableStream; size: number } | null>;
|
|
5
7
|
};
|
|
6
8
|
|
|
7
9
|
export type CmsEmailAdapter = {
|
package/internals/integration.ts
CHANGED
|
@@ -107,7 +107,8 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
|
|
|
107
107
|
const generatedPath = options?.generatedPath ?? "src/cms/.generated";
|
|
108
108
|
const adaptersPath = options?.adaptersPath ?? "src/cms/adapters";
|
|
109
109
|
const generatorPath = options?.generatorPath ?? packagePath("internals", "generator.ts");
|
|
110
|
-
|
|
110
|
+
// options.platform stays accepted for compat (CF configs pass it) but nothing
|
|
111
|
+
// branches on it anymore — the /uploads route now serves both platforms.
|
|
111
112
|
|
|
112
113
|
return {
|
|
113
114
|
name: "kide-cms",
|
|
@@ -255,13 +256,13 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
|
|
|
255
256
|
entrypoint: new URL("../routes/admin/[...path].astro", import.meta.url),
|
|
256
257
|
});
|
|
257
258
|
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
259
|
+
// /uploads/* streams from the storage adapter (Node: uploads dir, CF: R2).
|
|
260
|
+
// Both platforms need it: Node's static layer only serves files that
|
|
261
|
+
// existed at build time, so runtime uploads 404 in production without it.
|
|
262
|
+
injectRoute({
|
|
263
|
+
pattern: "/uploads/[...path]",
|
|
264
|
+
entrypoint: new URL("../routes/uploads/[...path].ts", import.meta.url),
|
|
265
|
+
});
|
|
265
266
|
|
|
266
267
|
// Inject API routes
|
|
267
268
|
injectRoute({
|
package/middleware/auth.ts
CHANGED
|
@@ -148,11 +148,18 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
|
|
|
148
148
|
hasUsers = true;
|
|
149
149
|
}
|
|
150
150
|
} catch (error) {
|
|
151
|
-
//
|
|
152
|
-
// (corruption, I/O) must surface, not funnel visitors to /admin/setup.
|
|
151
|
+
// Anything but a missing users table (corruption, I/O) must surface.
|
|
153
152
|
const message = error instanceof Error ? error.message : String(error);
|
|
154
153
|
if (!/no such table: cms_users/i.test(message)) throw error;
|
|
155
|
-
|
|
154
|
+
// Schema not pushed. Setup can't succeed against a table-less database
|
|
155
|
+
// (its INSERT would fail too), so say what's actually wrong instead of
|
|
156
|
+
// redirecting there. Typical cause: `pnpm build && pnpm preview` without
|
|
157
|
+
// a prior `pnpm cms:push` (dev pushes on boot, production never does).
|
|
158
|
+
// hasUsers stays unset so the check re-runs once the schema exists.
|
|
159
|
+
return new Response(
|
|
160
|
+
"Database schema is not initialized. Run `pnpm cms:push` against this environment's database (Cloudflare D1: apply your migrations), then reload.",
|
|
161
|
+
{ status: 503, headers: { "Content-Type": "text/plain", "Cache-Control": "no-store" } },
|
|
162
|
+
);
|
|
156
163
|
}
|
|
157
164
|
}
|
|
158
165
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { APIRoute } from "astro";
|
|
2
|
+
// Narrow import (not the core barrel): this route compiles in the Cloudflare
|
|
3
|
+
// profile too, and the barrel drags in Node-only modules.
|
|
4
|
+
import { getStorage } from "../../core/runtime";
|
|
5
|
+
|
|
6
|
+
export const prerender = false;
|
|
7
|
+
|
|
8
|
+
const MIME_TYPES: Record<string, string> = {
|
|
9
|
+
".jpg": "image/jpeg",
|
|
10
|
+
".jpeg": "image/jpeg",
|
|
11
|
+
".png": "image/png",
|
|
12
|
+
".gif": "image/gif",
|
|
13
|
+
".webp": "image/webp",
|
|
14
|
+
".avif": "image/avif",
|
|
15
|
+
".svg": "image/svg+xml",
|
|
16
|
+
".pdf": "application/pdf",
|
|
17
|
+
".mp4": "video/mp4",
|
|
18
|
+
".webm": "video/webm",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Serves runtime-uploaded files through the storage adapter (Node: uploads dir,
|
|
22
|
+
// Cloudflare: R2). Node's static layer only knows files present at build time,
|
|
23
|
+
// so anything uploaded after `astro build` is invisible to it; this route is the
|
|
24
|
+
// fallback that makes production uploads servable. Static files win when both
|
|
25
|
+
// exist — same bytes either way.
|
|
26
|
+
export const GET: APIRoute = async ({ params }) => {
|
|
27
|
+
const storagePath = `/uploads/${params.path}`;
|
|
28
|
+
const storage = getStorage();
|
|
29
|
+
|
|
30
|
+
let body: ReadableStream | ArrayBuffer | null;
|
|
31
|
+
let size: number;
|
|
32
|
+
try {
|
|
33
|
+
if (storage.getFileStream) {
|
|
34
|
+
const file = await storage.getFileStream(storagePath);
|
|
35
|
+
body = file?.body ?? null;
|
|
36
|
+
size = file?.size ?? 0;
|
|
37
|
+
} else {
|
|
38
|
+
// Custom adapters implement only the three-method contract — buffer instead.
|
|
39
|
+
body = await storage.getFile(storagePath);
|
|
40
|
+
size = body instanceof ArrayBuffer ? body.byteLength : 0;
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
body = null; // traversal attempt or adapter error — same 404 as a missing file
|
|
44
|
+
size = 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!body) {
|
|
48
|
+
return new Response("Not found", { status: 404 });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ext = storagePath.substring(storagePath.lastIndexOf(".")).toLowerCase();
|
|
52
|
+
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
53
|
+
|
|
54
|
+
return new Response(body, {
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": contentType,
|
|
57
|
+
"Content-Length": String(size),
|
|
58
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { APIRoute } from "astro";
|
|
2
|
-
import { getFileStream } from "./storage";
|
|
3
|
-
|
|
4
|
-
export const prerender = false;
|
|
5
|
-
|
|
6
|
-
const MIME_TYPES: Record<string, string> = {
|
|
7
|
-
".jpg": "image/jpeg",
|
|
8
|
-
".jpeg": "image/jpeg",
|
|
9
|
-
".png": "image/png",
|
|
10
|
-
".gif": "image/gif",
|
|
11
|
-
".webp": "image/webp",
|
|
12
|
-
".avif": "image/avif",
|
|
13
|
-
".svg": "image/svg+xml",
|
|
14
|
-
".pdf": "application/pdf",
|
|
15
|
-
".mp4": "video/mp4",
|
|
16
|
-
".webm": "video/webm",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const GET: APIRoute = async ({ params }) => {
|
|
20
|
-
const filePath = `/uploads/${params.path}`;
|
|
21
|
-
const file = await getFileStream(filePath);
|
|
22
|
-
|
|
23
|
-
if (!file) {
|
|
24
|
-
return new Response("Not found", { status: 404 });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const ext = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
|
|
28
|
-
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
29
|
-
|
|
30
|
-
return new Response(file.body, {
|
|
31
|
-
headers: {
|
|
32
|
-
"Content-Type": contentType,
|
|
33
|
-
"Content-Length": String(file.size),
|
|
34
|
-
"Cache-Control": "public, max-age=31536000, immutable",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
};
|