opacacms 0.1.1 → 0.1.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.
Files changed (212) hide show
  1. package/package.json +36 -1
  2. package/bun.lock +0 -34
  3. package/global.d.ts +0 -11
  4. package/src/admin/api-client.ts +0 -63
  5. package/src/admin/auth-client.ts +0 -40
  6. package/src/admin/custom-field.ts +0 -179
  7. package/src/admin/index.ts +0 -15
  8. package/src/admin/react.tsx +0 -72
  9. package/src/admin/router.ts +0 -9
  10. package/src/admin/stores/admin-queries.ts +0 -121
  11. package/src/admin/stores/auth.ts +0 -61
  12. package/src/admin/stores/column-visibility.ts +0 -67
  13. package/src/admin/stores/config.ts +0 -15
  14. package/src/admin/stores/media.ts +0 -95
  15. package/src/admin/stores/query.ts +0 -13
  16. package/src/admin/stores/ui.ts +0 -29
  17. package/src/admin/ui/admin-client.tsx +0 -283
  18. package/src/admin/ui/admin-layout.tsx +0 -276
  19. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  20. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  21. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  22. package/src/admin/ui/components/Table.tsx +0 -67
  23. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  24. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  25. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  26. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  27. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  28. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  29. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  30. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  31. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  32. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  33. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  34. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  35. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  36. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  37. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  38. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  39. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  40. package/src/admin/ui/components/fields/index.tsx +0 -371
  41. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  42. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  43. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  44. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  45. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  46. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  47. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  48. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  49. package/src/admin/ui/components/fields/utils.ts +0 -1
  50. package/src/admin/ui/components/link.tsx +0 -41
  51. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  52. package/src/admin/ui/components/toast.tsx +0 -72
  53. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  54. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  55. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  56. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  57. package/src/admin/ui/components/ui/button.tsx +0 -26
  58. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  59. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  60. package/src/admin/ui/components/ui/group.tsx +0 -20
  61. package/src/admin/ui/components/ui/index.ts +0 -17
  62. package/src/admin/ui/components/ui/input.tsx +0 -12
  63. package/src/admin/ui/components/ui/join.tsx +0 -53
  64. package/src/admin/ui/components/ui/label.tsx +0 -11
  65. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  66. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  67. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  68. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  69. package/src/admin/ui/components/ui/select.tsx +0 -187
  70. package/src/admin/ui/components/ui/separator.tsx +0 -21
  71. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  72. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  73. package/src/admin/ui/components/ui/utils.ts +0 -3
  74. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  75. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  76. package/src/admin/ui/styles/accordion.scss +0 -60
  77. package/src/admin/ui/styles/animations.scss +0 -41
  78. package/src/admin/ui/styles/asset-manager.scss +0 -547
  79. package/src/admin/ui/styles/badge.scss +0 -13
  80. package/src/admin/ui/styles/base.scss +0 -22
  81. package/src/admin/ui/styles/button.scss +0 -161
  82. package/src/admin/ui/styles/card.scss +0 -13
  83. package/src/admin/ui/styles/collapsible.scss +0 -75
  84. package/src/admin/ui/styles/data-detail.scss +0 -92
  85. package/src/admin/ui/styles/dialog.scss +0 -102
  86. package/src/admin/ui/styles/empty-state.scss +0 -22
  87. package/src/admin/ui/styles/group.scss +0 -19
  88. package/src/admin/ui/styles/index.scss +0 -33
  89. package/src/admin/ui/styles/input.scss +0 -80
  90. package/src/admin/ui/styles/label.scss +0 -12
  91. package/src/admin/ui/styles/layout.scss +0 -56
  92. package/src/admin/ui/styles/lexical.scss +0 -469
  93. package/src/admin/ui/styles/loading.scss +0 -102
  94. package/src/admin/ui/styles/media-registry.scss +0 -597
  95. package/src/admin/ui/styles/pagination.scss +0 -20
  96. package/src/admin/ui/styles/radio-group.scss +0 -66
  97. package/src/admin/ui/styles/row.scss +0 -17
  98. package/src/admin/ui/styles/scrollbar.scss +0 -36
  99. package/src/admin/ui/styles/select.scss +0 -121
  100. package/src/admin/ui/styles/separator.scss +0 -14
  101. package/src/admin/ui/styles/sheet.scss +0 -152
  102. package/src/admin/ui/styles/sidebar.scss +0 -148
  103. package/src/admin/ui/styles/switch.scss +0 -59
  104. package/src/admin/ui/styles/table.scss +0 -207
  105. package/src/admin/ui/styles/tabs.scss +0 -62
  106. package/src/admin/ui/styles/toast.scss +0 -45
  107. package/src/admin/ui/styles/variables.scss +0 -24
  108. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  109. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  110. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  111. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  112. package/src/admin/ui/views/init-view.tsx +0 -182
  113. package/src/admin/ui/views/login-view.tsx +0 -123
  114. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  115. package/src/admin/ui/views/settings-view.tsx +0 -729
  116. package/src/admin/webcomponent.tsx +0 -15
  117. package/src/auth/index.ts +0 -194
  118. package/src/auth/migrations.ts +0 -87
  119. package/src/auth/premissions.ts +0 -46
  120. package/src/cli/commands/generate-types.ts +0 -116
  121. package/src/cli/commands/init.ts +0 -95
  122. package/src/cli/commands/migrate-commands.ts +0 -160
  123. package/src/cli/commands/seed-command.ts +0 -11
  124. package/src/cli/d1-mock.ts +0 -101
  125. package/src/cli/index.test.ts +0 -84
  126. package/src/cli/index.ts +0 -183
  127. package/src/cli/r2-mock.ts +0 -217
  128. package/src/cli/seeding.ts +0 -409
  129. package/src/client.ts +0 -181
  130. package/src/config-utils.ts +0 -102
  131. package/src/config.ts +0 -49
  132. package/src/db/adapter.ts +0 -53
  133. package/src/db/better-sqlite.ts +0 -630
  134. package/src/db/bun-sqlite.ts +0 -646
  135. package/src/db/d1.ts +0 -711
  136. package/src/db/index.ts +0 -2
  137. package/src/db/kysely/data-mapper.ts +0 -142
  138. package/src/db/kysely/field-mapper.ts +0 -148
  139. package/src/db/kysely/migration-generator.ts +0 -223
  140. package/src/db/kysely/query-builder.ts +0 -92
  141. package/src/db/kysely/schema-builder.ts +0 -439
  142. package/src/db/kysely/sql-utils.ts +0 -13
  143. package/src/db/migration.ts +0 -40
  144. package/src/db/postgres.ts +0 -621
  145. package/src/db/sqlite.ts +0 -658
  146. package/src/db/system-schema.ts +0 -121
  147. package/src/index.ts +0 -11
  148. package/src/runtimes/README.md +0 -59
  149. package/src/runtimes/bun.ts +0 -49
  150. package/src/runtimes/cloudflare-workers.ts +0 -38
  151. package/src/runtimes/next.ts +0 -26
  152. package/src/runtimes/node.ts +0 -52
  153. package/src/schema/collection.ts +0 -184
  154. package/src/schema/fields/base.ts +0 -164
  155. package/src/schema/fields/index.ts +0 -427
  156. package/src/schema/global.ts +0 -145
  157. package/src/schema/index.ts +0 -4
  158. package/src/schema/infer.ts +0 -72
  159. package/src/server/admin-router.ts +0 -20
  160. package/src/server/admin.ts +0 -142
  161. package/src/server/assets.ts +0 -306
  162. package/src/server/collection-router.ts +0 -55
  163. package/src/server/handlers.ts +0 -722
  164. package/src/server/middlewares/admin.ts +0 -27
  165. package/src/server/middlewares/auth.ts +0 -89
  166. package/src/server/middlewares/context.ts +0 -17
  167. package/src/server/middlewares/cors.ts +0 -24
  168. package/src/server/middlewares/database-init.ts +0 -74
  169. package/src/server/middlewares/rate-limit.ts +0 -71
  170. package/src/server/router.ts +0 -47
  171. package/src/server/setup-middlewares.ts +0 -58
  172. package/src/server/system-router.ts +0 -35
  173. package/src/server.ts +0 -9
  174. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  175. package/src/storage/adapters/local.ts +0 -146
  176. package/src/storage/adapters/s3.ts +0 -186
  177. package/src/storage/errors.ts +0 -46
  178. package/src/storage/index.ts +0 -6
  179. package/src/storage/types.ts +0 -39
  180. package/src/types.ts +0 -605
  181. package/src/utils/lexical.ts +0 -37
  182. package/src/utils/logger.ts +0 -73
  183. package/src/validation.ts +0 -429
  184. package/src/validator.ts +0 -179
  185. package/test/admin-custom-field.test.ts +0 -162
  186. package/test/admin-react-field.test.tsx +0 -134
  187. package/test/api-features.test.ts +0 -78
  188. package/test/api.test.ts +0 -178
  189. package/test/auth.test.ts +0 -62
  190. package/test/cli-integration.test.ts +0 -148
  191. package/test/cli.test.ts +0 -25
  192. package/test/db/postgres.test.ts +0 -95
  193. package/test/db/sqlite-filter.test.ts +0 -53
  194. package/test/db/sqlite.test.ts +0 -82
  195. package/test/engine-features.test.ts +0 -79
  196. package/test/globals.test.ts +0 -74
  197. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  198. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  199. package/test/integration-tmp/my-test-app/index.ts +0 -8
  200. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  201. package/test/integration-tmp/my-test-app/package.json +0 -12
  202. package/test/populate.test.ts +0 -79
  203. package/test/runtimes.test.ts +0 -43
  204. package/test/schema-builder.test.ts +0 -107
  205. package/test/schema-features.test.ts +0 -63
  206. package/test/seeding.test.ts +0 -68
  207. package/test/storage/local.test.ts +0 -72
  208. package/test/storage/s3.test.ts +0 -60
  209. package/test/structural-data.test.ts +0 -100
  210. package/test/test-setup.ts +0 -11
  211. package/test/validation.test.ts +0 -162
  212. package/tsconfig.json +0 -42
package/src/types.ts DELETED
@@ -1,605 +0,0 @@
1
- import type { Session, User } from "better-auth";
2
- import type { Context } from "hono";
3
- import type {
4
- AdminConfig,
5
- CollectionHooks,
6
- FieldType,
7
- AccessConfig as ValidationAccessConfig,
8
- ApiConfig as ValidationApiConfig,
9
- Collection as ValidationCollection,
10
- Field as ValidationField,
11
- Global as ValidationGlobal,
12
- OpacaConfig as ValidationOpacaConfig,
13
- } from "./validation";
14
-
15
- export type { FieldType };
16
-
17
- /**
18
- * Names of icons available in the OpacaCMS admin UI (subset of lucide-react).
19
- * Using a static list avoids forcing consumers to resolve the entire lucide-react module.
20
- */
21
- export type IconName =
22
- | "Activity" | "AlertCircle" | "AlertTriangle" | "Archive" | "ArrowDown"
23
- | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "BarChart" | "BarChart2"
24
- | "Bell" | "Book" | "BookOpen" | "Bookmark" | "Box"
25
- | "Calendar" | "Camera" | "Check" | "CheckCircle" | "ChevronDown"
26
- | "ChevronLeft" | "ChevronRight" | "ChevronUp" | "Circle" | "Clipboard"
27
- | "Clock" | "Cloud" | "Code" | "Columns" | "Command"
28
- | "Copy" | "CreditCard" | "Database" | "Download" | "Edit"
29
- | "ExternalLink" | "Eye" | "EyeOff" | "File" | "FileText"
30
- | "Filter" | "Flag" | "Folder" | "FolderOpen" | "Globe"
31
- | "Grid" | "Hash" | "Heart" | "Home" | "Image"
32
- | "Info" | "Key" | "Layers" | "Layout" | "LayoutDashboard"
33
- | "Link" | "List" | "Lock" | "LogIn" | "LogOut"
34
- | "Mail" | "Map" | "Menu" | "MessageCircle" | "MessageSquare"
35
- | "Minus" | "Monitor" | "Moon" | "MoreHorizontal" | "MoreVertical"
36
- | "Move" | "Navigation" | "Package" | "Paperclip" | "Pencil"
37
- | "Phone" | "PieChart" | "Pin" | "Play" | "Plus"
38
- | "PlusCircle" | "Power" | "Printer" | "RefreshCw" | "Search"
39
- | "Send" | "Server" | "Settings" | "Share" | "Shield"
40
- | "ShieldCheck" | "ShoppingCart" | "Sidebar" | "Slash" | "Sliders"
41
- | "Square" | "Star" | "Sun" | "Table" | "Tag"
42
- | "Terminal" | "Trash" | "Trash2" | "TrendingUp" | "Type"
43
- | "Undo" | "Upload" | "User" | "UserCheck" | "UserPlus"
44
- | "Users" | "Video" | "Wallet" | "Wrench" | "X"
45
- | "XCircle" | "ZoomIn" | "ZoomOut"
46
- | (string & {});
47
-
48
- // --- Field Types ---
49
-
50
- export interface BaseField {
51
- name: string;
52
- label?: string;
53
- placeholder?: string;
54
- required?: boolean;
55
- unique?: boolean;
56
- localized?: boolean;
57
- defaultValue?: unknown;
58
- validate?: (value: unknown) => boolean | string;
59
- access?: FieldAccessConfig;
60
- admin?: {
61
- description?: string;
62
- condition?: (data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean;
63
- hidden?: boolean;
64
- readOnly?: boolean;
65
- width?: string;
66
- style?: any;
67
- className?: string;
68
- components?: {
69
- Field?: string;
70
- Cell?: string;
71
- };
72
- };
73
- references?: {
74
- table: string;
75
- column: string;
76
- onDelete?: "cascade" | "set null" | "restrict" | "no action";
77
- };
78
- }
79
-
80
- export interface TextField extends BaseField {
81
- type: "text";
82
- }
83
-
84
- export interface SlugField extends BaseField {
85
- type: "slug";
86
- from: string;
87
- format?: (value: string) => string;
88
- }
89
-
90
- export interface TextAreaField extends BaseField {
91
- type: "textarea";
92
- }
93
-
94
- export interface NumberField extends BaseField {
95
- type: "number";
96
- options?: {
97
- min?: number;
98
- max?: number;
99
- step?: number;
100
- [key: string]: any;
101
- };
102
- }
103
-
104
- export interface RichTextField extends BaseField {
105
- type: "richtext";
106
- options?: {
107
- defaultMode?: "simple" | "notion";
108
- [key: string]: any;
109
- };
110
- }
111
-
112
- export interface RelationshipField extends BaseField {
113
- type: "relationship";
114
- relationTo: string;
115
- hasMany?: boolean;
116
- displayField?: string;
117
- }
118
-
119
- export interface SelectField extends BaseField {
120
- type: "select";
121
- options?: {
122
- choices: (string | { label: string; value: string })[];
123
- [key: string]: any;
124
- };
125
- }
126
-
127
- export interface RadioField extends BaseField {
128
- type: "radio";
129
- options: {
130
- choices: (string | { label: string; value: string })[];
131
- [key: string]: unknown;
132
- };
133
- }
134
-
135
- export interface DateField extends BaseField {
136
- type: "date";
137
- }
138
-
139
- export interface BooleanField extends BaseField {
140
- type: "boolean";
141
- options?: {
142
- display?: "switch" | "toggle" | "checkbox" | "select";
143
- [key: string]: unknown;
144
- };
145
- }
146
-
147
- export interface JSONField extends BaseField {
148
- type: "json";
149
- }
150
-
151
- export interface FileField extends BaseField {
152
- type: "file";
153
- bucket?: string;
154
- options?: {
155
- allowedmime_types?: string[];
156
- maxFileSize?: number;
157
- metaFields?: Field[];
158
- [key: string]: unknown;
159
- };
160
- }
161
-
162
- export interface BlocksField extends BaseField {
163
- type: "blocks";
164
- blocks: {
165
- slug: string;
166
- fields: Field[];
167
- label?: string;
168
- }[];
169
- }
170
-
171
- export interface GroupField extends BaseField {
172
- type: "group";
173
- fields: Field[];
174
- }
175
-
176
- export interface RowField extends Omit<BaseField, "name"> {
177
- type: "row";
178
- name?: string; // Allow optional name for row
179
- fields: Field[];
180
- label?: string;
181
- }
182
-
183
- export interface CollapsibleField extends Omit<BaseField, "name"> {
184
- type: "collapsible";
185
- name?: string; // Allow optional name for collapsible
186
- label: string;
187
- fields: Field[];
188
- options?: {
189
- initiallyCollapsed?: boolean;
190
- useAsTitle?: string;
191
- [key: string]: any;
192
- };
193
- }
194
-
195
- export interface ArrayField extends BaseField {
196
- type: "array";
197
- fields: Field[];
198
- }
199
-
200
- export interface TabsField extends Omit<BaseField, "name"> {
201
- type: "tabs";
202
- name?: string; // Allow optional name for tabs
203
- tabs: {
204
- label: string;
205
- fields: Field[];
206
- }[];
207
- }
208
-
209
- export interface JoinField extends Omit<BaseField, "name"> {
210
- type: "join";
211
- name?: string; // join requires name, but schema-generator tests assume optional
212
- collection: string;
213
- on: string;
214
- }
215
-
216
- export interface VirtualField extends BaseField {
217
- type: "virtual";
218
- resolve: (args: {
219
- data: any;
220
- req: any;
221
- user: User;
222
- session: Session;
223
- apiKey?: ApiKey;
224
- }) => any | Promise<any>;
225
- returnType?: "string" | "number" | "boolean" | "json";
226
- }
227
-
228
- export type Field =
229
- | TextField
230
- | SlugField
231
- | TextAreaField
232
- | NumberField
233
- | RichTextField
234
- | RelationshipField
235
- | SelectField
236
- | VirtualField
237
- | RadioField
238
- | DateField
239
- | BooleanField
240
- | JSONField
241
- | FileField
242
- | BlocksField
243
- | GroupField
244
- | RowField
245
- | CollapsibleField
246
- | TabsField
247
- | JoinField
248
- | ArrayField;
249
-
250
- export interface ApiKey {
251
- id: string;
252
- name: string | null;
253
- permissions?: Record<string, string[]> | null;
254
- referenceId: string;
255
- }
256
-
257
- export interface AccessArgs {
258
- req: Context;
259
- user: User | null;
260
- session: Session | null;
261
- apiKey?: ApiKey | null;
262
- data?: unknown;
263
- operation?: "read" | "create" | "update" | "delete";
264
- }
265
-
266
- export interface FieldAccessConfig {
267
- /** If true, the field is removed from API and UI. */
268
- hidden?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
269
- /** If true, the data is shown but cannot be edited. */
270
- readOnly?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
271
- /** If true, the input is visually disabled. */
272
- disabled?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
273
- }
274
-
275
- export interface AccessConfig
276
- extends Omit<ValidationAccessConfig, "read" | "create" | "update" | "delete"> {
277
- read?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
278
- create?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
279
- update?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
280
- delete?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
281
- }
282
-
283
- export type { CollectionHooks };
284
-
285
- export interface Collection
286
- extends Omit<
287
- ValidationCollection,
288
- "fields" | "hooks" | "access" | "admin" | "apiPath" | "versions" | "webhooks"
289
- > {
290
- fields: Field[];
291
- apiPath?: string;
292
- hooks?: CollectionHooks;
293
- access?: AccessConfig;
294
- icon?: IconName;
295
- versions?: {
296
- drafts?: boolean;
297
- maxRevisions?: number;
298
- autosave?: boolean;
299
- };
300
- webhooks?: {
301
- events: string[];
302
- url: string;
303
- headers?: Record<string, string>;
304
- }[];
305
- admin?:
306
- | {
307
- defaultColumns?: string[];
308
- useAsTitle?: string;
309
- hidden?: boolean;
310
- disableAdmin?: boolean;
311
- views?: {
312
- name: string;
313
- filter: Record<string, any>;
314
- defaultColumns?: string[];
315
- }[];
316
- bulkActions?: {
317
- label: string;
318
- action: (args: { selectedIds: string[]; db: DatabaseAdapter }) => Promise<unknown>;
319
- }[];
320
- }
321
- | boolean;
322
- }
323
-
324
- export interface Global extends Omit<ValidationGlobal, "fields" | "access"> {
325
- fields: Field[];
326
- access?: AccessConfig;
327
- label?: string;
328
- icon?: IconName;
329
- }
330
-
331
- export interface OpacaConfig<Resource extends string = string>
332
- extends Omit<
333
- ValidationOpacaConfig,
334
- "collections" | "globals" | "admin" | "api" | "access" | "trustedOrigins" | "auth" | "i18n"
335
- > {
336
- collections: Collection[];
337
- globals?: Global[];
338
- db: DatabaseAdapter;
339
- admin?: AdminConfig;
340
- api?: ApiConfig;
341
- access?: OpacaAccessConfig<Resource>;
342
- trustedOrigins?: string[] | ((request?: Request) => string[] | Promise<string[]>);
343
- auth?: OpacaAuthConfig;
344
- i18n?: {
345
- locales: string[];
346
- defaultLocale: string;
347
- };
348
- }
349
-
350
- export interface OpacaAuthConfig {
351
- /**
352
- * Defines the primary identity strategies for accessing the CMS.
353
- */
354
- strategies?: {
355
- emailPassword?: boolean; // Defaults to true
356
- magicLink?: {
357
- enabled: boolean;
358
- sendEmail: (data: { email: string; url: string; token: string }) => Promise<void>;
359
- };
360
- };
361
-
362
- /**
363
- * Strictly typed social providers.
364
- * Only the providers explicitly supported by the OpacaCMS UI are allowed.
365
- */
366
- socialProviders?: {
367
- github?: {
368
- clientId: string;
369
- clientSecret: string;
370
- };
371
- google?: {
372
- clientId: string;
373
- clientSecret: string;
374
- };
375
- };
376
-
377
- /**
378
- * Session configuration overrides.
379
- */
380
- session?: {
381
- expiresInDays?: number; // Defaults to 30
382
- updateAgeSeconds?: number; // Defaults to 86400 (1 day)
383
- };
384
-
385
- /**
386
- * Declaring plugins statically by configuration.
387
- */
388
- features?: {
389
- apiKeys?: {
390
- enabled: boolean;
391
- };
392
- mfa?: {
393
- enabled: boolean;
394
- issuer: string;
395
- };
396
- };
397
- }
398
-
399
- export interface OpacaAccessConfig<Resource extends string = string> {
400
- /**
401
- * Define roles and their permissions.
402
- * Key is the role name (e.g., 'editor').
403
- * Value is a map of resource names to allowed actions.
404
- */
405
- roles: Record<string, Partial<Record<Resource | "user" | "session", string[]>>>;
406
- }
407
-
408
- export interface ApiConfig {
409
- maxLimit?: number;
410
- rateLimit?: {
411
- windowMs?: number;
412
- limit?: number;
413
- enabled?: boolean;
414
- store?: any;
415
- provider?: (c: Context) => any;
416
- keyGenerator?: (c: Context) => string | Promise<string>;
417
- };
418
- }
419
-
420
- export type { AdminConfig };
421
-
422
- export interface FindOptions {
423
- limit?: number;
424
- page?: number;
425
- sort?: string;
426
- }
427
-
428
- export interface PaginatedResult<T> {
429
- docs: T[];
430
- folders?: string[];
431
- totalDocs: number;
432
- limit: number;
433
- totalPages: number;
434
- page: number;
435
- pagingCounter: number;
436
- hasPrevPage: boolean;
437
- hasNextPage: boolean;
438
- prevPage: number | null;
439
- nextPage: number | null;
440
- }
441
-
442
- export interface DatabaseAdapter {
443
- name: string;
444
- connect(): Promise<void>;
445
- disconnect(): Promise<void>;
446
- /**
447
- * Internal ORM instance (e.g. Drizzle instance)
448
- */
449
- readonly db?: unknown;
450
- readonly raw?: unknown;
451
- unsafe(sql: string, params?: unknown[]): Promise<unknown>;
452
- count(collection: string, query?: Record<string, unknown>): Promise<number>;
453
-
454
- // CRUD
455
- create<T extends object>(collection: string, data: Partial<T>): Promise<T>;
456
- find<T extends object>(
457
- collection: string,
458
- query?: Record<string, unknown>,
459
- options?: FindOptions,
460
- ): Promise<PaginatedResult<T>>;
461
- findOne<T extends object>(collection: string, query: Record<string, unknown>): Promise<T | null>;
462
- update<T extends object>(
463
- collection: string,
464
- query: Record<string, unknown>,
465
- data: Partial<T>,
466
- ): Promise<T>;
467
- updateMany?<T extends object>(
468
- collection: string,
469
- query: Record<string, unknown>,
470
- data: Partial<T>,
471
- ): Promise<number>;
472
- delete(collection: string, query: Record<string, unknown>): Promise<boolean>;
473
- deleteMany?(collection: string, query: Record<string, unknown>): Promise<number>;
474
-
475
- // Globals
476
- findGlobal?<T extends object>(slug: string): Promise<T | null>;
477
- updateGlobal?<T extends object>(slug: string, data: Partial<T>): Promise<T>;
478
-
479
- // Schema management
480
- migrate(collections: Collection[], globals?: Global[]): Promise<void>;
481
-
482
- /**
483
- * Run file-based migrations from the migrations directory.
484
- */
485
- runMigrations?(): Promise<void>;
486
-
487
- /**
488
- * Wether to automatically push schema changes to the database (on the fly).
489
- * Defaults to true in development, false in production.
490
- */
491
- push?: boolean;
492
- pushDestructive?: boolean;
493
- migrationDir?: string;
494
- }
495
-
496
- /**
497
- * Serializable version of a collection, safe for Next.js Client Components.
498
- * Strips out hooks and access functions.
499
- */
500
- export interface SerializableCollection {
501
- slug: string;
502
- apiPath?: string;
503
- label?: string;
504
- icon?: IconName;
505
- versions?: {
506
- drafts?: boolean;
507
- maxRevisions?: number;
508
- autosave?: boolean;
509
- };
510
- fields: {
511
- name?: string;
512
- type: FieldType;
513
- label?: string;
514
- localized?: boolean;
515
- admin?: {
516
- description?: string;
517
- hidden?: boolean;
518
- readOnly?: boolean;
519
- components?: {
520
- Field?: string;
521
- Cell?: string;
522
- };
523
- };
524
- required?: boolean;
525
- unique?: boolean;
526
- defaultValue?: unknown;
527
- options?: {
528
- defaultMode?: "simple" | "notion";
529
- [key: string]: unknown;
530
- };
531
- fields?: SerializableCollection["fields"];
532
- relationTo?: string;
533
- hasMany?: boolean;
534
- displayField?: string;
535
- collection?: string;
536
- on?: string;
537
- blocks?: {
538
- slug: string;
539
- fields: SerializableCollection["fields"];
540
- label?: string;
541
- }[];
542
- tabs?: {
543
- label: string;
544
- fields: SerializableCollection["fields"];
545
- }[];
546
- }[];
547
- timestamps?: boolean | { createdAt?: string; updatedAt?: string };
548
- auth?: boolean;
549
- admin?:
550
- | {
551
- defaultColumns?: string[];
552
- useAsTitle?: string;
553
- hidden?: boolean;
554
- disableAdmin?: boolean;
555
- views?: {
556
- name: string;
557
- filter: Record<string, any>;
558
- defaultColumns?: string[];
559
- }[];
560
- }
561
- | boolean;
562
- hidden?: boolean;
563
- }
564
-
565
- /**
566
- * Serializable version of the config, safe for Next.js Client Components.
567
- * Strips out database adapter and functions.
568
- */
569
- export interface SerializableConfig {
570
- appName?: string;
571
- serverURL?: string;
572
- i18n?: {
573
- locales: string[];
574
- defaultLocale: string;
575
- };
576
- collections: SerializableCollection[];
577
- globals?: {
578
- slug: string;
579
- label?: string;
580
- icon?: IconName;
581
- fields: {
582
- name?: string;
583
- type: FieldType;
584
- label?: string;
585
- required?: boolean;
586
- defaultValue?: unknown;
587
- options?: {
588
- defaultMode?: "simple" | "notion";
589
- [key: string]: unknown;
590
- };
591
- fields?: SerializableCollection["fields"];
592
- blocks?: {
593
- slug: string;
594
- fields: SerializableCollection["fields"];
595
- label?: string;
596
- }[];
597
- tabs?: {
598
- label: string;
599
- fields: SerializableCollection["fields"];
600
- }[];
601
- }[];
602
- }[];
603
- needsInit?: boolean;
604
- storages?: Record<string, unknown>;
605
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Converts Lexical JSON state to plain text.
3
- * Useful for displaying previews in tables or search results.
4
- */
5
- export function lexicalToPlainText(jsonString: string): string {
6
- if (!jsonString) return "";
7
-
8
- try {
9
- const data = JSON.parse(jsonString);
10
- if (!data.root || !data.root.children) return "";
11
-
12
- return traverseNodes(data.root.children);
13
- } catch (err) {
14
- // If it's not valid JSON, it might already be plain text or a different format
15
- if (typeof jsonString === "string" && !jsonString.startsWith("{")) {
16
- return jsonString;
17
- }
18
- return "";
19
- }
20
- }
21
-
22
- function traverseNodes(children: any[]): string {
23
- let text = "";
24
- for (const child of children) {
25
- if (child.text) {
26
- text += child.text;
27
- } else if (child.children) {
28
- text += traverseNodes(child.children);
29
- }
30
-
31
- // Add space for block-level elements
32
- if (child.type === "paragraph" || child.type === "heading" || child.type === "listitem") {
33
- text += " ";
34
- }
35
- }
36
- return text.trim();
37
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * Core Logger Utility for OpacaCMS.
3
- * Standardizes console output across the package with ANSI colors and standard prefixes.
4
- */
5
-
6
- const RESET = "\x1b[0m";
7
- const BLUE = "\x1b[34m";
8
- const GREEN = "\x1b[32m";
9
- const YELLOW = "\x1b[33m";
10
- const RED = "\x1b[31m";
11
- const GRAY = "\x1b[90m";
12
-
13
- const PREFIX = `${BLUE}[OpacaCMS]${RESET}`;
14
-
15
- export const logger = {
16
- /**
17
- * General information logging.
18
- * Useful for successful operations, initialization steps, etc.
19
- */
20
- info: (message: string, ...args: any[]) => {
21
- console.log(`${PREFIX} ${message}`, ...args);
22
- },
23
-
24
- /**
25
- * Action logging. Usually highlighted in green.
26
- * e.g., "Created table users", "Connected to DB"
27
- */
28
- success: (message: string, ...args: any[]) => {
29
- console.log(`${PREFIX} ${GREEN}${message}${RESET}`, ...args);
30
- },
31
-
32
- /**
33
- * Dim/Debug logging.
34
- * e.g., "Starting schema push...", "Syncing database..."
35
- */
36
- debug: (message: string, ...args: any[]) => {
37
- console.log(`${PREFIX} ${GRAY}${message}${RESET}`, ...args);
38
- },
39
-
40
- /**
41
- * Warning logging.
42
- * For non-fatal errors or deprecated warnings.
43
- */
44
- warn: (message: string, ...args: any[]) => {
45
- console.warn(`${PREFIX} ${YELLOW}Warning: ${message}${RESET}`, ...args);
46
- },
47
-
48
- /**
49
- * Error logging.
50
- * For fatal errors, exceptions, and validation failures.
51
- */
52
- error: (message: string, ...args: any[]) => {
53
- console.error(`${PREFIX} ${RED}Error: ${message}${RESET}`, ...args);
54
- },
55
-
56
- /**
57
- * Raw formatting function if manual concatenation is needed.
58
- */
59
- format: (color: "green" | "red" | "yellow" | "gray", msg: string) => {
60
- switch (color) {
61
- case "green":
62
- return `${GREEN}${msg}${RESET}`;
63
- case "red":
64
- return `${RED}${msg}${RESET}`;
65
- case "yellow":
66
- return `${YELLOW}${msg}${RESET}`;
67
- case "gray":
68
- return `${GRAY}${msg}${RESET}`;
69
- default:
70
- return msg;
71
- }
72
- },
73
- };