Repository navigation
Expand file tree
/
Copy pathcms-types.ts
More file actions
142 lines (125 loc) · 4.28 KB
/
Copy pathcms-types.ts
File metadata and controls
142 lines (125 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ============================================================================
CMS Type Definitions
Multi-author publishing platform types for Firestore collections
============================================================================ */
/* -------------------------------------------------------------------------- */
/* Roles & Permissions */
/* -------------------------------------------------------------------------- */
export type UserRole = "owner" | "admin" | "author";
export type PostStatus = "draft" | "review" | "scheduled" | "published" | "archived";
export type CmsPermission =
| "posts.create"
| "posts.edit_own"
| "posts.edit_any"
| "posts.publish"
| "posts.delete"
| "posts.archive"
| "categories.manage"
| "series.manage"
| "users.manage";
const ROLE_PERMISSIONS: Record<UserRole, CmsPermission[]> = {
owner: [
"posts.create", "posts.edit_own", "posts.edit_any", "posts.publish",
"posts.delete", "posts.archive", "categories.manage", "series.manage",
"users.manage",
],
admin: [
"posts.create", "posts.edit_own", "posts.edit_any", "posts.publish",
"posts.delete", "posts.archive", "categories.manage", "series.manage",
],
author: [
"posts.create", "posts.edit_own",
],
};
export function hasPermission(role: UserRole | null, permission: CmsPermission): boolean {
if (!role) return false;
return ROLE_PERMISSIONS[role].includes(permission);
}
/* -------------------------------------------------------------------------- */
/* User */
/* -------------------------------------------------------------------------- */
export interface CmsUser {
uid: string;
email: string;
displayName: string;
avatarUrl: string;
bio: string;
role: UserRole;
socialLinks: {
github?: string;
twitter?: string;
linkedin?: string;
};
createdAt: string;
updatedAt: string;
disabled: boolean;
}
/** Placeholder for invited users who haven't signed in yet */
export interface UserInvite {
email: string;
role: UserRole;
invitedAt: string;
invitedBy: string;
}
/* -------------------------------------------------------------------------- */
/* Post */
/* -------------------------------------------------------------------------- */
export interface CmsPost {
slug: string;
title: string;
description: string;
body: string;
coverImageUrl: string;
category: string;
tags: string[];
series: string | null;
seriesOrder: number | null;
seoTitle: string;
seoDescription: string;
status: PostStatus;
publishedAt: string | null;
scheduledAt: string | null;
authorId: string;
authorName: string;
authorAvatar: string;
featured: boolean;
createdAt: string;
updatedAt: string;
lastSavedAt: string;
}
/** Validation result for publish-readiness */
export interface PostValidation {
valid: boolean;
errors: string[];
}
export function validatePostForPublish(post: Partial<CmsPost>): PostValidation {
const errors: string[] = [];
if (!post.title?.trim()) errors.push("Title is required");
if (!post.slug?.trim()) errors.push("Slug is required");
if (!post.description?.trim()) errors.push("Excerpt is required");
if (!post.category?.trim()) errors.push("Category is required");
if (!post.coverImageUrl?.trim()) errors.push("Cover image is required");
if (!post.body?.trim()) errors.push("Content is required");
return { valid: errors.length === 0, errors };
}
/* -------------------------------------------------------------------------- */
/* Category */
/* -------------------------------------------------------------------------- */
export interface CmsCategory {
id: string;
name: string;
slug: string;
description: string;
order: number;
createdAt: string;
}
/* -------------------------------------------------------------------------- */
/* Series */
/* -------------------------------------------------------------------------- */
export interface CmsSeries {
id: string;
name: string;
slug: string;
description: string;
createdAt: string;
}