@arch-cadre/blog-module 1.0.9 → 1.0.10
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/package.json +5 -5
- package/src/actions/index.d.ts +0 -67
- package/src/actions/index.js +0 -149
- package/src/components/BlogStatsWidget.d.ts +0 -1
- package/src/components/BlogStatsWidget.js +0 -17
- package/src/components/RecentCommentsWidget.d.ts +0 -1
- package/src/components/RecentCommentsWidget.js +0 -24
- package/src/components/RecentPostsWidget.d.ts +0 -1
- package/src/components/RecentPostsWidget.js +0 -24
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -98
- package/src/lib/utils.d.ts +0 -2
- package/src/lib/utils.js +0 -5
- package/src/lib/validation.d.ts +0 -24
- package/src/lib/validation.js +0 -11
- package/src/navigation.d.ts +0 -2
- package/src/navigation.js +0 -21
- package/src/routes.d.ts +0 -3
- package/src/routes.js +0 -55
- package/src/schema.d.ts +0 -736
- package/src/schema.js +0 -60
- package/src/ui/views.d.ts +0 -15
- package/src/ui/views.js +0 -119
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arch-cadre/blog-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A sample module for Kryo framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "pnpm clean && tsc --module esnext"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@arch-cadre/modules": "^0.0.
|
|
27
|
+
"@arch-cadre/modules": "^0.0.79",
|
|
28
28
|
"@hookform/resolvers": "^3.10.0",
|
|
29
29
|
"@radix-ui/react-slot": "^1.2.3",
|
|
30
30
|
"class-variance-authority": "^0.7.1",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"unbuild": "^3.6.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@arch-cadre/core": "^0.0.
|
|
51
|
-
"@arch-cadre/intl": "^0.0.
|
|
52
|
-
"@arch-cadre/ui": "^0.0.
|
|
50
|
+
"@arch-cadre/core": "^0.0.53",
|
|
51
|
+
"@arch-cadre/intl": "^0.0.53",
|
|
52
|
+
"@arch-cadre/ui": "^0.0.53",
|
|
53
53
|
"react": "^19.0.0"
|
|
54
54
|
},
|
|
55
55
|
"main": "./dist/index.mjs"
|
package/src/actions/index.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
|
-
import { commentSchema, postSchema } from "../lib/validation.js";
|
|
3
|
-
export declare function createPost(data: z.infer<typeof postSchema>): Promise<{
|
|
4
|
-
success: boolean;
|
|
5
|
-
error?: undefined;
|
|
6
|
-
} | {
|
|
7
|
-
success: boolean;
|
|
8
|
-
error: any;
|
|
9
|
-
}>;
|
|
10
|
-
export declare function getPosts(): Promise<{
|
|
11
|
-
id: string;
|
|
12
|
-
title: string;
|
|
13
|
-
slug: string;
|
|
14
|
-
content: string;
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
author: {
|
|
17
|
-
name: string;
|
|
18
|
-
};
|
|
19
|
-
}[]>;
|
|
20
|
-
export declare function getPostBySlug(slug: string): Promise<{
|
|
21
|
-
id: string;
|
|
22
|
-
title: string;
|
|
23
|
-
slug: string;
|
|
24
|
-
content: string;
|
|
25
|
-
createdAt: Date;
|
|
26
|
-
author: {
|
|
27
|
-
name: string;
|
|
28
|
-
};
|
|
29
|
-
}>;
|
|
30
|
-
export declare function getPostById(id: string): Promise<{
|
|
31
|
-
id: string;
|
|
32
|
-
title: string;
|
|
33
|
-
slug: string;
|
|
34
|
-
content: string;
|
|
35
|
-
authorId: string;
|
|
36
|
-
createdAt: Date;
|
|
37
|
-
}>;
|
|
38
|
-
export declare function getComments(postId: string): Promise<{
|
|
39
|
-
id: string;
|
|
40
|
-
content: string;
|
|
41
|
-
createdAt: Date;
|
|
42
|
-
author: {
|
|
43
|
-
name: string;
|
|
44
|
-
image: string | null;
|
|
45
|
-
};
|
|
46
|
-
}[]>;
|
|
47
|
-
export declare function createComment(data: z.infer<typeof commentSchema>): Promise<{
|
|
48
|
-
success: boolean;
|
|
49
|
-
error?: undefined;
|
|
50
|
-
} | {
|
|
51
|
-
success: boolean;
|
|
52
|
-
error: any;
|
|
53
|
-
}>;
|
|
54
|
-
export declare function deletePost(id: string): Promise<{
|
|
55
|
-
success: boolean;
|
|
56
|
-
error?: undefined;
|
|
57
|
-
} | {
|
|
58
|
-
success: boolean;
|
|
59
|
-
error: any;
|
|
60
|
-
}>;
|
|
61
|
-
export declare function updatePost(id: string, data: z.infer<typeof postSchema>): Promise<{
|
|
62
|
-
success: boolean;
|
|
63
|
-
error?: undefined;
|
|
64
|
-
} | {
|
|
65
|
-
success: boolean;
|
|
66
|
-
error: any;
|
|
67
|
-
}>;
|
package/src/actions/index.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { db, getCurrentSession, userTable } from "@arch-cadre/core/server";
|
|
3
|
-
import { desc, eq } from "drizzle-orm";
|
|
4
|
-
import { revalidatePath } from "next/cache";
|
|
5
|
-
import { commentSchema, postSchema } from "../lib/validation.js";
|
|
6
|
-
import { commentsTable, postsTable } from "../schema.js";
|
|
7
|
-
// --- Posts ---
|
|
8
|
-
export async function createPost(data) {
|
|
9
|
-
try {
|
|
10
|
-
const { user } = await getCurrentSession();
|
|
11
|
-
if (!user)
|
|
12
|
-
throw new Error("Unauthorized");
|
|
13
|
-
const validated = postSchema.parse(data);
|
|
14
|
-
await db.insert(postsTable).values({
|
|
15
|
-
...validated,
|
|
16
|
-
authorId: user.id,
|
|
17
|
-
});
|
|
18
|
-
revalidatePath("/blog");
|
|
19
|
-
return { success: true };
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.error("[BlogModule:Actions] createPost failed:", error);
|
|
23
|
-
return { success: false, error: error.message };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export async function getPosts() {
|
|
27
|
-
try {
|
|
28
|
-
return await db
|
|
29
|
-
.select({
|
|
30
|
-
id: postsTable.id,
|
|
31
|
-
title: postsTable.title,
|
|
32
|
-
slug: postsTable.slug,
|
|
33
|
-
content: postsTable.content,
|
|
34
|
-
createdAt: postsTable.createdAt,
|
|
35
|
-
author: {
|
|
36
|
-
name: userTable.name,
|
|
37
|
-
},
|
|
38
|
-
})
|
|
39
|
-
.from(postsTable)
|
|
40
|
-
.innerJoin(userTable, eq(postsTable.authorId, userTable.id))
|
|
41
|
-
.orderBy(desc(postsTable.createdAt));
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
console.error("[BlogModule:Actions] getPosts failed:", error);
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export async function getPostBySlug(slug) {
|
|
49
|
-
try {
|
|
50
|
-
const [post] = await db
|
|
51
|
-
.select({
|
|
52
|
-
id: postsTable.id,
|
|
53
|
-
title: postsTable.title,
|
|
54
|
-
slug: postsTable.slug,
|
|
55
|
-
content: postsTable.content,
|
|
56
|
-
createdAt: postsTable.createdAt,
|
|
57
|
-
author: {
|
|
58
|
-
name: userTable.name,
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
.from(postsTable)
|
|
62
|
-
.innerJoin(userTable, eq(postsTable.authorId, userTable.id))
|
|
63
|
-
.where(eq(postsTable.slug, slug));
|
|
64
|
-
return post || null;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.error("[BlogModule:Actions] getPostBySlug failed:", error);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export async function getPostById(id) {
|
|
72
|
-
try {
|
|
73
|
-
const [post] = await db
|
|
74
|
-
.select()
|
|
75
|
-
.from(postsTable)
|
|
76
|
-
.where(eq(postsTable.id, id));
|
|
77
|
-
return post || null;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.error("[BlogModule:Actions] getPostById failed:", error);
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// --- Comments ---
|
|
85
|
-
export async function getComments(postId) {
|
|
86
|
-
try {
|
|
87
|
-
return await db
|
|
88
|
-
.select({
|
|
89
|
-
id: commentsTable.id,
|
|
90
|
-
content: commentsTable.content,
|
|
91
|
-
createdAt: commentsTable.createdAt,
|
|
92
|
-
author: {
|
|
93
|
-
name: userTable.name,
|
|
94
|
-
image: userTable.image,
|
|
95
|
-
},
|
|
96
|
-
})
|
|
97
|
-
.from(commentsTable)
|
|
98
|
-
.innerJoin(userTable, eq(commentsTable.authorId, userTable.id))
|
|
99
|
-
.where(eq(commentsTable.postId, postId))
|
|
100
|
-
.orderBy(desc(commentsTable.createdAt));
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
console.error("[BlogModule:Actions] getComments failed:", error);
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export async function createComment(data) {
|
|
108
|
-
try {
|
|
109
|
-
const { user } = await getCurrentSession();
|
|
110
|
-
if (!user)
|
|
111
|
-
throw new Error("Must be logged in to comment");
|
|
112
|
-
const validated = commentSchema.parse(data);
|
|
113
|
-
await db.insert(commentsTable).values({
|
|
114
|
-
content: validated.content,
|
|
115
|
-
postId: validated.postId,
|
|
116
|
-
authorId: user.id,
|
|
117
|
-
});
|
|
118
|
-
revalidatePath(`/blog`);
|
|
119
|
-
return { success: true };
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
console.error("[BlogModule:Actions] createComment failed:", error);
|
|
123
|
-
return { success: false, error: error.message };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
export async function deletePost(id) {
|
|
127
|
-
try {
|
|
128
|
-
await db.delete(postsTable).where(eq(postsTable.id, id));
|
|
129
|
-
revalidatePath("/blog");
|
|
130
|
-
return { success: true };
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
console.error("[BlogModule:Actions] deletePost failed:", error);
|
|
134
|
-
return { success: false, error: error.message };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export async function updatePost(id, data) {
|
|
138
|
-
try {
|
|
139
|
-
const validated = postSchema.parse(data);
|
|
140
|
-
await db.update(postsTable).set(validated).where(eq(postsTable.id, id));
|
|
141
|
-
revalidatePath("/blog");
|
|
142
|
-
revalidatePath(`/blog/${validated.slug}`);
|
|
143
|
-
return { success: true };
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
console.error("[BlogModule:Actions] updatePost failed:", error);
|
|
147
|
-
return { success: false, error: error.message };
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function BlogStatsWidget(): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { db } from "@arch-cadre/core/server";
|
|
3
|
-
import { getTranslation } from "@arch-cadre/intl/server";
|
|
4
|
-
import { Card, CardContent, CardHeader, CardTitle } from "@arch-cadre/ui";
|
|
5
|
-
import { sql } from "drizzle-orm";
|
|
6
|
-
import { FileText, MessageSquare } from "lucide-react";
|
|
7
|
-
import { commentsTable, postsTable } from "../schema.js";
|
|
8
|
-
export default async function BlogStatsWidget() {
|
|
9
|
-
const { t } = await getTranslation();
|
|
10
|
-
const [postsCount] = await db
|
|
11
|
-
.select({ count: sql `count(*)` })
|
|
12
|
-
.from(postsTable);
|
|
13
|
-
const [commentsCount] = await db
|
|
14
|
-
.select({ count: sql `count(*)` })
|
|
15
|
-
.from(commentsTable);
|
|
16
|
-
return (_jsxs("div", { className: "grid gap-4 md:grid-cols-2 lg:grid-cols-2", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Posts") }), _jsx(FileText, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: postsCount?.count || 0 }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Comments") }), _jsx(MessageSquare, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: commentsCount?.count || 0 }) })] })] }));
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function RecentCommentsWidget(): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { db, userTable } from "@arch-cadre/core/server";
|
|
3
|
-
import { getTranslation } from "@arch-cadre/intl/server";
|
|
4
|
-
import { Avatar, AvatarFallback, AvatarImage, Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@arch-cadre/ui";
|
|
5
|
-
import { desc, eq } from "drizzle-orm";
|
|
6
|
-
import { commentsTable } from "../schema.js";
|
|
7
|
-
export default async function RecentCommentsWidget() {
|
|
8
|
-
const { t } = await getTranslation();
|
|
9
|
-
const comments = await db
|
|
10
|
-
.select({
|
|
11
|
-
id: commentsTable.id,
|
|
12
|
-
content: commentsTable.content,
|
|
13
|
-
createdAt: commentsTable.createdAt,
|
|
14
|
-
author: {
|
|
15
|
-
name: userTable.name,
|
|
16
|
-
image: userTable.image,
|
|
17
|
-
},
|
|
18
|
-
})
|
|
19
|
-
.from(commentsTable)
|
|
20
|
-
.leftJoin(userTable, eq(commentsTable.authorId, userTable.id))
|
|
21
|
-
.orderBy(desc(commentsTable.createdAt))
|
|
22
|
-
.limit(5);
|
|
23
|
-
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("Recent Comments") }), _jsx(CardDescription, { children: t("What readers are saying about your posts.") })] }), _jsxs(CardContent, { className: "grid gap-8", children: [comments.map((comment) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs(Avatar, { className: "h-9 w-9", children: [_jsx(AvatarImage, { src: comment.author?.image || "", alt: "Avatar" }), _jsx(AvatarFallback, { children: comment.author?.name?.substring(0, 2).toUpperCase() || "CM" })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx("p", { className: "text-sm font-medium leading-none line-clamp-1", children: comment.content }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [comment.author?.name || t("Anonymous"), " \u2022", " ", new Date(comment.createdAt).toLocaleDateString()] })] })] }, comment.id))), comments.length === 0 && (_jsx("div", { className: "text-center py-4 text-muted-foreground", children: t("No comments yet.") }))] })] }));
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function RecentPostsWidget(): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { db, userTable } from "@arch-cadre/core/server";
|
|
3
|
-
import { getTranslation } from "@arch-cadre/intl/server";
|
|
4
|
-
import { Avatar, AvatarFallback, AvatarImage, Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@arch-cadre/ui";
|
|
5
|
-
import { desc, eq } from "drizzle-orm";
|
|
6
|
-
import { postsTable } from "../schema.js";
|
|
7
|
-
export default async function RecentPostsWidget() {
|
|
8
|
-
const { t } = await getTranslation();
|
|
9
|
-
const posts = await db
|
|
10
|
-
.select({
|
|
11
|
-
id: postsTable.id,
|
|
12
|
-
title: postsTable.title,
|
|
13
|
-
createdAt: postsTable.createdAt,
|
|
14
|
-
author: {
|
|
15
|
-
name: userTable.name,
|
|
16
|
-
image: userTable.image,
|
|
17
|
-
},
|
|
18
|
-
})
|
|
19
|
-
.from(postsTable)
|
|
20
|
-
.leftJoin(userTable, eq(postsTable.authorId, userTable.id))
|
|
21
|
-
.orderBy(desc(postsTable.createdAt))
|
|
22
|
-
.limit(5);
|
|
23
|
-
return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("Recent Posts") }), _jsx(CardDescription, { children: t("The latest articles published on your blog.") })] }), _jsxs(CardContent, { className: "grid gap-8", children: [posts.map((post) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs(Avatar, { className: "h-9 w-9", children: [_jsx(AvatarImage, { src: post.author?.image || "", alt: "Avatar" }), _jsx(AvatarFallback, { children: post.author?.name?.substring(0, 2).toUpperCase() || "AU" })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx("p", { className: "text-sm font-medium leading-none", children: post.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: new Date(post.createdAt).toLocaleDateString() })] })] }, post.id))), posts.length === 0 && (_jsx("div", { className: "text-center py-4 text-muted-foreground", children: t("No posts found.") }))] })] }));
|
|
24
|
-
}
|
package/src/index.d.ts
DELETED
package/src/index.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { assignPermissionToRole, createPermission, db, getRoles, permissionsTable, } from "@arch-cadre/core/server";
|
|
2
|
-
import { inArray, sql } from "drizzle-orm";
|
|
3
|
-
import manifest from "../manifest.json" with { type: "json" };
|
|
4
|
-
import BlogStatsWidget from "./components/BlogStatsWidget.js";
|
|
5
|
-
import RecentCommentsWidget from "./components/RecentCommentsWidget.js";
|
|
6
|
-
import RecentPostsWidget from "./components/RecentPostsWidget.js";
|
|
7
|
-
import { navigation } from "./navigation.js";
|
|
8
|
-
import { privateRoutes, publicRoutes } from "./routes.js";
|
|
9
|
-
const BLOG_PERMISSIONS = [
|
|
10
|
-
{ name: "post:create", description: "Allow creating blog posts" },
|
|
11
|
-
{ name: "post:update", description: "Allow updating blog posts" },
|
|
12
|
-
{ name: "post:delete", description: "Allow deleting blog posts" },
|
|
13
|
-
{ name: "comment:create", description: "Allow creating comments" },
|
|
14
|
-
{ name: "comment:update", description: "Allow updating comments" },
|
|
15
|
-
{ name: "comment:delete", description: "Allow deleting comments" },
|
|
16
|
-
];
|
|
17
|
-
// --- Module Definition ---
|
|
18
|
-
const blogModule = {
|
|
19
|
-
manifest: manifest,
|
|
20
|
-
init: async () => {
|
|
21
|
-
console.log("[BlogModule] ready.");
|
|
22
|
-
},
|
|
23
|
-
widgets: [
|
|
24
|
-
{
|
|
25
|
-
id: "blog-stats",
|
|
26
|
-
name: "Blog Stats",
|
|
27
|
-
area: "dashboard-stats",
|
|
28
|
-
component: BlogStatsWidget,
|
|
29
|
-
priority: 20,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: "recent-posts",
|
|
33
|
-
name: "Recent Posts",
|
|
34
|
-
area: "dashboard-main",
|
|
35
|
-
component: RecentPostsWidget,
|
|
36
|
-
priority: 20,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: "recent-comments",
|
|
40
|
-
name: "Recent Comments",
|
|
41
|
-
area: "dashboard-main",
|
|
42
|
-
component: RecentCommentsWidget,
|
|
43
|
-
priority: 30,
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
onEnable: async () => {
|
|
47
|
-
console.log("[BlogModule] enabling and registering permissions...");
|
|
48
|
-
try {
|
|
49
|
-
// 1. Create permissions
|
|
50
|
-
for (const perm of BLOG_PERMISSIONS) {
|
|
51
|
-
await createPermission(perm.name, perm.description);
|
|
52
|
-
}
|
|
53
|
-
// 2. Assign to admin role
|
|
54
|
-
const roles = await getRoles();
|
|
55
|
-
const adminRole = roles.find((r) => r.name === "admin");
|
|
56
|
-
if (adminRole) {
|
|
57
|
-
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
58
|
-
const blogPerms = await db
|
|
59
|
-
.select()
|
|
60
|
-
.from(permissionsTable)
|
|
61
|
-
.where(inArray(permissionsTable.name, blogPermNames));
|
|
62
|
-
for (const p of blogPerms) {
|
|
63
|
-
await assignPermissionToRole(adminRole.id, p.id);
|
|
64
|
-
}
|
|
65
|
-
console.log("[BlogModule] Permissions assigned to admin role.");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
console.error("[BlogModule] Error during permission registration:", error);
|
|
70
|
-
}
|
|
71
|
-
console.log("[BlogModule] enabled.");
|
|
72
|
-
},
|
|
73
|
-
onDisable: async () => {
|
|
74
|
-
console.log("[Blog] onDisable: Cleaning up tables and permissions...");
|
|
75
|
-
try {
|
|
76
|
-
// 1. Remove permissions (cascades to role-permission mappings)
|
|
77
|
-
const blogPermNames = BLOG_PERMISSIONS.map((p) => p.name);
|
|
78
|
-
await db
|
|
79
|
-
.delete(permissionsTable)
|
|
80
|
-
.where(inArray(permissionsTable.name, blogPermNames));
|
|
81
|
-
console.log("[BlogModule] Permissions and mappings removed.");
|
|
82
|
-
// 2. Drop tables
|
|
83
|
-
const tables = ["blog_posts", "blog_comments"];
|
|
84
|
-
for (const table of tables) {
|
|
85
|
-
await db.execute(sql.raw(`DROP TABLE IF EXISTS ${table} CASCADE`));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
console.error("[Blog] onDisable Error:", e);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
routes: {
|
|
93
|
-
public: publicRoutes,
|
|
94
|
-
private: privateRoutes,
|
|
95
|
-
},
|
|
96
|
-
navigation: navigation,
|
|
97
|
-
};
|
|
98
|
-
export default blogModule;
|
package/src/lib/utils.d.ts
DELETED
package/src/lib/utils.js
DELETED
package/src/lib/validation.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const postSchema: z.ZodObject<{
|
|
3
|
-
title: z.ZodString;
|
|
4
|
-
content: z.ZodString;
|
|
5
|
-
slug: z.ZodString;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
title: string;
|
|
8
|
-
slug: string;
|
|
9
|
-
content: string;
|
|
10
|
-
}, {
|
|
11
|
-
title: string;
|
|
12
|
-
slug: string;
|
|
13
|
-
content: string;
|
|
14
|
-
}>;
|
|
15
|
-
export declare const commentSchema: z.ZodObject<{
|
|
16
|
-
content: z.ZodString;
|
|
17
|
-
postId: z.ZodString;
|
|
18
|
-
}, "strip", z.ZodTypeAny, {
|
|
19
|
-
content: string;
|
|
20
|
-
postId: string;
|
|
21
|
-
}, {
|
|
22
|
-
content: string;
|
|
23
|
-
postId: string;
|
|
24
|
-
}>;
|
package/src/lib/validation.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
// --- Validation Schemas ---
|
|
3
|
-
export const postSchema = z.object({
|
|
4
|
-
title: z.string().min(3, "Title must be at least 3 characters"),
|
|
5
|
-
content: z.string().min(10, "Content must be at least 10 characters"),
|
|
6
|
-
slug: z.string().min(3, "Slug is required"),
|
|
7
|
-
});
|
|
8
|
-
export const commentSchema = z.object({
|
|
9
|
-
content: z.string().min(2, "Comment is too short"),
|
|
10
|
-
postId: z.string().uuid(),
|
|
11
|
-
});
|
package/src/navigation.d.ts
DELETED
package/src/navigation.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { i18n } from "@arch-cadre/intl";
|
|
2
|
-
export const navigation = {
|
|
3
|
-
public: [
|
|
4
|
-
{
|
|
5
|
-
title: i18n("Blog"),
|
|
6
|
-
url: "/blog",
|
|
7
|
-
icon: "solar:pen-2-broken",
|
|
8
|
-
},
|
|
9
|
-
],
|
|
10
|
-
admin: {
|
|
11
|
-
[i18n("CMS")]: [
|
|
12
|
-
{
|
|
13
|
-
title: i18n("Blog Manager"),
|
|
14
|
-
url: "/blog",
|
|
15
|
-
icon: "solar:posts-carousel-vertical-broken",
|
|
16
|
-
roles: ["admin"],
|
|
17
|
-
permissions: ["post:create", "post:update", "post:delete"],
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
};
|
package/src/routes.d.ts
DELETED
package/src/routes.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getCurrentSession } from "@arch-cadre/core/server";
|
|
3
|
-
import { getComments, getPostById, getPostBySlug, getPosts } from "./actions/index.js";
|
|
4
|
-
import { BlogAdminPage, BlogListPage, CreatePostForm, EditPostForm, PostDetailPage, } from "./ui/views.js";
|
|
5
|
-
export const publicRoutes = [
|
|
6
|
-
{
|
|
7
|
-
path: "/blog",
|
|
8
|
-
component: async () => {
|
|
9
|
-
const posts = await getPosts();
|
|
10
|
-
return _jsx(BlogListPage, { posts: posts });
|
|
11
|
-
},
|
|
12
|
-
auth: false,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
path: "/blog/:slug",
|
|
16
|
-
component: async ({ params }) => {
|
|
17
|
-
const { slug } = await params;
|
|
18
|
-
const post = await getPostBySlug(slug);
|
|
19
|
-
const comments = post ? await getComments(post.id) : [];
|
|
20
|
-
const session = await getCurrentSession();
|
|
21
|
-
return (_jsx(PostDetailPage, { post: post, comments: comments, currentUser: session?.user }));
|
|
22
|
-
},
|
|
23
|
-
auth: false,
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
export const privateRoutes = [
|
|
27
|
-
{
|
|
28
|
-
path: "/blog",
|
|
29
|
-
component: async () => {
|
|
30
|
-
const posts = await getPosts();
|
|
31
|
-
return _jsx(BlogAdminPage, { posts: posts });
|
|
32
|
-
},
|
|
33
|
-
auth: true,
|
|
34
|
-
roles: ["admin"],
|
|
35
|
-
permissions: ["post:create", "post:update", "post:delete"],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
path: "/blog/new",
|
|
39
|
-
component: CreatePostForm,
|
|
40
|
-
auth: true,
|
|
41
|
-
roles: ["admin"],
|
|
42
|
-
permissions: ["post:create"],
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
path: "/blog/edit/:id",
|
|
46
|
-
component: async ({ params }) => {
|
|
47
|
-
const { id } = await params;
|
|
48
|
-
const post = await getPostById(id);
|
|
49
|
-
return _jsx(EditPostForm, { post: post });
|
|
50
|
-
},
|
|
51
|
-
auth: true,
|
|
52
|
-
roles: ["admin"],
|
|
53
|
-
permissions: ["post:update"],
|
|
54
|
-
},
|
|
55
|
-
];
|