opacacms 0.1.0 → 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 (247) hide show
  1. package/dist/admin/index.js +49 -0
  2. package/dist/{chunk-2zm8cy1w.js → admin/webcomponent.js} +116 -168
  3. package/dist/{chunk-6dhs73zq.js → chunk-2yz1nsxs.js} +1 -1
  4. package/dist/chunk-fa5mg0hr.js +96 -0
  5. package/dist/{chunk-kwp83w8b.js → chunk-m09hahe2.js} +7 -7
  6. package/dist/{chunk-hmhcense.js → chunk-ry15hke8.js} +253 -4
  7. package/dist/chunk-vtvqfhgy.js +2442 -0
  8. package/dist/{chunk-f3nvxn63.js → chunk-y8hc6nm4.js} +1 -1
  9. package/dist/{src/cli → cli}/index.js +10 -10
  10. package/dist/{src/client.js → client.js} +2 -2
  11. package/dist/{src/db → db}/bun-sqlite.js +10 -10
  12. package/dist/{src/db → db}/d1.js +8 -8
  13. package/dist/db/index.d.ts +2 -0
  14. package/dist/db/index.js +7 -0
  15. package/dist/db/migration.d.ts +39 -0
  16. package/dist/{src/db → db}/postgres.js +10 -10
  17. package/dist/{src/db → db}/sqlite.js +8 -8
  18. package/dist/index.d.ts +0 -2
  19. package/dist/index.js +13 -0
  20. package/dist/{src/runtimes → runtimes}/bun.js +5 -6
  21. package/dist/{src/runtimes → runtimes}/cloudflare-workers.js +5 -6
  22. package/dist/{src/runtimes → runtimes}/next.js +5 -6
  23. package/dist/{src/runtimes → runtimes}/node.js +5 -6
  24. package/dist/{src/server.js → server.js} +7 -8
  25. package/dist/storage/index.d.ts +0 -3
  26. package/dist/storage/index.js +35 -0
  27. package/dist/types.d.ts +5 -2
  28. package/package.json +161 -39
  29. package/bun.lock +0 -34
  30. package/dist/api.d.ts +0 -6
  31. package/dist/chunk-8gkhn1d4.js +0 -309
  32. package/dist/chunk-dy5t83hr.js +0 -261
  33. package/dist/src/admin/index.js +0 -176
  34. package/dist/src/admin/webcomponent.js +0 -19
  35. package/dist/src/api.js +0 -27
  36. package/dist/src/index.js +0 -20
  37. package/dist/src/storage/index.js +0 -355
  38. package/global.d.ts +0 -11
  39. package/src/admin/api-client.ts +0 -63
  40. package/src/admin/auth-client.ts +0 -40
  41. package/src/admin/custom-field.ts +0 -179
  42. package/src/admin/index.ts +0 -15
  43. package/src/admin/react.tsx +0 -72
  44. package/src/admin/router.ts +0 -9
  45. package/src/admin/stores/admin-queries.ts +0 -121
  46. package/src/admin/stores/auth.ts +0 -61
  47. package/src/admin/stores/column-visibility.ts +0 -67
  48. package/src/admin/stores/config.ts +0 -15
  49. package/src/admin/stores/media.ts +0 -95
  50. package/src/admin/stores/query.ts +0 -13
  51. package/src/admin/stores/ui.ts +0 -29
  52. package/src/admin/ui/admin-client.tsx +0 -283
  53. package/src/admin/ui/admin-layout.tsx +0 -276
  54. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  56. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  57. package/src/admin/ui/components/Table.tsx +0 -67
  58. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  59. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  60. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  61. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  62. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  63. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  64. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  65. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  66. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  67. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  68. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  69. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  70. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  71. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  72. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  73. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  74. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  75. package/src/admin/ui/components/fields/index.tsx +0 -371
  76. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  78. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  83. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  84. package/src/admin/ui/components/fields/utils.ts +0 -1
  85. package/src/admin/ui/components/link.tsx +0 -41
  86. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  87. package/src/admin/ui/components/toast.tsx +0 -72
  88. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  89. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  90. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  91. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  92. package/src/admin/ui/components/ui/button.tsx +0 -26
  93. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  94. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  95. package/src/admin/ui/components/ui/group.tsx +0 -20
  96. package/src/admin/ui/components/ui/index.ts +0 -17
  97. package/src/admin/ui/components/ui/input.tsx +0 -12
  98. package/src/admin/ui/components/ui/join.tsx +0 -53
  99. package/src/admin/ui/components/ui/label.tsx +0 -11
  100. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  101. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  102. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  103. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  104. package/src/admin/ui/components/ui/select.tsx +0 -187
  105. package/src/admin/ui/components/ui/separator.tsx +0 -21
  106. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  107. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  108. package/src/admin/ui/components/ui/utils.ts +0 -3
  109. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  110. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  111. package/src/admin/ui/styles/accordion.scss +0 -60
  112. package/src/admin/ui/styles/animations.scss +0 -41
  113. package/src/admin/ui/styles/asset-manager.scss +0 -547
  114. package/src/admin/ui/styles/badge.scss +0 -13
  115. package/src/admin/ui/styles/base.scss +0 -22
  116. package/src/admin/ui/styles/button.scss +0 -161
  117. package/src/admin/ui/styles/card.scss +0 -13
  118. package/src/admin/ui/styles/collapsible.scss +0 -75
  119. package/src/admin/ui/styles/data-detail.scss +0 -92
  120. package/src/admin/ui/styles/dialog.scss +0 -102
  121. package/src/admin/ui/styles/empty-state.scss +0 -22
  122. package/src/admin/ui/styles/group.scss +0 -19
  123. package/src/admin/ui/styles/index.scss +0 -33
  124. package/src/admin/ui/styles/input.scss +0 -80
  125. package/src/admin/ui/styles/label.scss +0 -12
  126. package/src/admin/ui/styles/layout.scss +0 -56
  127. package/src/admin/ui/styles/lexical.scss +0 -469
  128. package/src/admin/ui/styles/loading.scss +0 -102
  129. package/src/admin/ui/styles/media-registry.scss +0 -597
  130. package/src/admin/ui/styles/pagination.scss +0 -20
  131. package/src/admin/ui/styles/radio-group.scss +0 -66
  132. package/src/admin/ui/styles/row.scss +0 -17
  133. package/src/admin/ui/styles/scrollbar.scss +0 -36
  134. package/src/admin/ui/styles/select.scss +0 -121
  135. package/src/admin/ui/styles/separator.scss +0 -14
  136. package/src/admin/ui/styles/sheet.scss +0 -152
  137. package/src/admin/ui/styles/sidebar.scss +0 -148
  138. package/src/admin/ui/styles/switch.scss +0 -59
  139. package/src/admin/ui/styles/table.scss +0 -207
  140. package/src/admin/ui/styles/tabs.scss +0 -62
  141. package/src/admin/ui/styles/toast.scss +0 -45
  142. package/src/admin/ui/styles/variables.scss +0 -24
  143. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  144. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  145. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  146. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  147. package/src/admin/ui/views/init-view.tsx +0 -182
  148. package/src/admin/ui/views/login-view.tsx +0 -123
  149. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  150. package/src/admin/ui/views/settings-view.tsx +0 -729
  151. package/src/admin/webcomponent.tsx +0 -15
  152. package/src/api.ts +0 -9
  153. package/src/auth/index.ts +0 -194
  154. package/src/auth/migrations.ts +0 -87
  155. package/src/auth/premissions.ts +0 -46
  156. package/src/cli/commands/generate-types.ts +0 -116
  157. package/src/cli/commands/init.ts +0 -95
  158. package/src/cli/commands/migrate-commands.ts +0 -160
  159. package/src/cli/commands/seed-command.ts +0 -11
  160. package/src/cli/d1-mock.ts +0 -101
  161. package/src/cli/index.test.ts +0 -84
  162. package/src/cli/index.ts +0 -183
  163. package/src/cli/r2-mock.ts +0 -217
  164. package/src/cli/seeding.ts +0 -405
  165. package/src/client.ts +0 -181
  166. package/src/config-utils.ts +0 -102
  167. package/src/config.ts +0 -49
  168. package/src/db/adapter.ts +0 -53
  169. package/src/db/better-sqlite.ts +0 -630
  170. package/src/db/bun-sqlite.ts +0 -646
  171. package/src/db/d1.ts +0 -711
  172. package/src/db/kysely/data-mapper.ts +0 -142
  173. package/src/db/kysely/field-mapper.ts +0 -148
  174. package/src/db/kysely/migration-generator.ts +0 -223
  175. package/src/db/kysely/query-builder.ts +0 -92
  176. package/src/db/kysely/schema-builder.ts +0 -439
  177. package/src/db/kysely/sql-utils.ts +0 -13
  178. package/src/db/postgres.ts +0 -621
  179. package/src/db/sqlite.ts +0 -658
  180. package/src/db/system-schema.ts +0 -121
  181. package/src/index.ts +0 -13
  182. package/src/runtimes/README.md +0 -59
  183. package/src/runtimes/bun.ts +0 -49
  184. package/src/runtimes/cloudflare-workers.ts +0 -38
  185. package/src/runtimes/next.ts +0 -26
  186. package/src/runtimes/node.ts +0 -52
  187. package/src/schema/collection.ts +0 -184
  188. package/src/schema/fields/base.ts +0 -164
  189. package/src/schema/fields/index.ts +0 -427
  190. package/src/schema/global.ts +0 -145
  191. package/src/schema/index.ts +0 -4
  192. package/src/schema/infer.ts +0 -72
  193. package/src/server/admin-router.ts +0 -20
  194. package/src/server/admin.ts +0 -142
  195. package/src/server/assets.ts +0 -306
  196. package/src/server/collection-router.ts +0 -55
  197. package/src/server/handlers.ts +0 -722
  198. package/src/server/middlewares/admin.ts +0 -27
  199. package/src/server/middlewares/auth.ts +0 -89
  200. package/src/server/middlewares/context.ts +0 -17
  201. package/src/server/middlewares/cors.ts +0 -24
  202. package/src/server/middlewares/database-init.ts +0 -74
  203. package/src/server/middlewares/rate-limit.ts +0 -71
  204. package/src/server/router.ts +0 -47
  205. package/src/server/setup-middlewares.ts +0 -58
  206. package/src/server/system-router.ts +0 -35
  207. package/src/server.ts +0 -9
  208. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  209. package/src/storage/adapters/local.ts +0 -146
  210. package/src/storage/adapters/s3.ts +0 -186
  211. package/src/storage/errors.ts +0 -46
  212. package/src/storage/index.ts +0 -5
  213. package/src/storage/types.ts +0 -39
  214. package/src/types.ts +0 -577
  215. package/src/utils/lexical.ts +0 -37
  216. package/src/utils/logger.ts +0 -73
  217. package/src/validation.ts +0 -429
  218. package/src/validator.ts +0 -179
  219. package/test/admin-custom-field.test.ts +0 -162
  220. package/test/admin-react-field.test.tsx +0 -134
  221. package/test/api-features.test.ts +0 -78
  222. package/test/api.test.ts +0 -178
  223. package/test/auth.test.ts +0 -62
  224. package/test/cli-integration.test.ts +0 -146
  225. package/test/cli.test.ts +0 -25
  226. package/test/db/postgres.test.ts +0 -95
  227. package/test/db/sqlite-filter.test.ts +0 -53
  228. package/test/db/sqlite.test.ts +0 -82
  229. package/test/engine-features.test.ts +0 -79
  230. package/test/globals.test.ts +0 -74
  231. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  232. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  233. package/test/integration-tmp/my-test-app/index.ts +0 -8
  234. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  235. package/test/integration-tmp/my-test-app/package.json +0 -12
  236. package/test/populate.test.ts +0 -79
  237. package/test/runtimes.test.ts +0 -43
  238. package/test/schema-builder.test.ts +0 -107
  239. package/test/schema-features.test.ts +0 -63
  240. package/test/seeding.test.ts +0 -68
  241. package/test/storage/local.test.ts +0 -72
  242. package/test/storage/s3.test.ts +0 -60
  243. package/test/structural-data.test.ts +0 -100
  244. package/test/test-setup.ts +0 -11
  245. package/test/validation.test.ts +0 -162
  246. package/tsconfig.json +0 -42
  247. /package/dist/{src/admin/index.css → admin/webcomponent.css} +0 -0
@@ -1,355 +0,0 @@
1
- import {
2
- __require
3
- } from "../../chunk-8sqjbsgt.js";
4
-
5
- // src/storage/errors.ts
6
- class StorageError extends Error {
7
- provider;
8
- operation;
9
- originalError;
10
- constructor(provider, operation, message, originalError) {
11
- const originalMessage = originalError instanceof Error ? `: ${originalError.message}` : originalError ? `: ${String(originalError)}` : "";
12
- super(`[OpacaStorage::${provider}] Failed to ${operation}: ${message}${originalMessage}`);
13
- this.name = "StorageError";
14
- this.provider = provider;
15
- this.operation = operation;
16
- this.originalError = originalError;
17
- }
18
- }
19
-
20
- class FileTooLargeError extends StorageError {
21
- constructor(provider, maxBytes, actualBytes) {
22
- super(provider, "upload", `File size (${actualBytes} bytes) exceeds the maximum allowed (${maxBytes} bytes).`);
23
- this.name = "FileTooLargeError";
24
- }
25
- }
26
-
27
- class Invalidmime_typeError extends StorageError {
28
- constructor(provider, allowedTypes, actualType) {
29
- super(provider, "upload", `MIME type '${actualType}' is not allowed. Expected one of: ${allowedTypes.join(", ")}.`);
30
- this.name = "Invalidmime_typeError";
31
- }
32
- }
33
-
34
- // src/storage/adapters/cloudflare-r2.ts
35
- function createR2Storage(config) {
36
- const getFullKey = (filename) => {
37
- return config.prefix ? `${config.prefix.replace(/\/$/, "")}/${filename}` : filename;
38
- };
39
- const getPublicUrl = (filename) => {
40
- if (!config.publicUrl) {
41
- throw new Error("Cloudflare R2 requires a 'publicUrl' (custom domain) configured in the adapter to return accessible URLs.");
42
- }
43
- return `${config.publicUrl.replace(/\/$/, "")}/${getFullKey(filename)}`;
44
- };
45
- return {
46
- name: "cloudflare-r2",
47
- async upload(file, options) {
48
- try {
49
- if (options?.allowedmime_types && !options.allowedmime_types.includes(file.mime_type)) {
50
- throw new Invalidmime_typeError("cloudflare-r2", options.allowedmime_types, file.mime_type);
51
- }
52
- if (options?.maxFileSize && file.filesize > options.maxFileSize) {
53
- throw new FileTooLargeError("cloudflare-r2", options.maxFileSize, file.filesize);
54
- }
55
- let finalFilename = file.filename;
56
- if (options?.generateUniqueName) {
57
- const ext = file.original_filename.split(".").pop() || "";
58
- const hash = crypto.randomUUID().split("-")[0];
59
- finalFilename = `${finalFilename.replace(`.${ext}`, "")}-${hash}.${ext}`;
60
- }
61
- const key = getFullKey(finalFilename);
62
- const body = file.buffer || file.stream;
63
- if (!body) {
64
- throw new StorageError("cloudflare-r2", "upload", `No content provided for file ${file.filename}`);
65
- }
66
- await config.bucketBinding.put(key, body, {
67
- httpMetadata: {
68
- contentType: file.mime_type
69
- }
70
- });
71
- return {
72
- filename: finalFilename,
73
- mime_type: file.mime_type,
74
- filesize: file.filesize,
75
- url: getPublicUrl(finalFilename)
76
- };
77
- } catch (error) {
78
- if (error instanceof StorageError)
79
- throw error;
80
- throw new StorageError("cloudflare-r2", "upload", `Failed to upload ${file.filename} to R2 bucket`, error);
81
- }
82
- },
83
- async delete(filename) {
84
- try {
85
- await config.bucketBinding.delete(getFullKey(filename));
86
- } catch (error) {
87
- throw new StorageError("cloudflare-r2", "delete", `Failed to delete ${filename} from R2 bucket`, error);
88
- }
89
- },
90
- async exists(filename) {
91
- try {
92
- const head = await config.bucketBinding.head(getFullKey(filename));
93
- return head !== null;
94
- } catch (error) {
95
- throw new StorageError("cloudflare-r2", "exists", `Failed to check existence of ${filename} in R2 bucket`, error);
96
- }
97
- },
98
- async download(filename) {
99
- try {
100
- const object = await config.bucketBinding.get(getFullKey(filename));
101
- if (!object) {
102
- throw new StorageError("cloudflare-r2", "download", `File not found: ${filename}`);
103
- }
104
- return object.body;
105
- } catch (error) {
106
- if (error instanceof StorageError)
107
- throw error;
108
- throw new StorageError("cloudflare-r2", "download", `Failed to download ${filename} from R2 bucket`, error);
109
- }
110
- }
111
- };
112
- }
113
- // src/storage/adapters/local.ts
114
- import fs from "node:fs/promises";
115
- import path from "node:path";
116
- function createLocalAdapter(config) {
117
- fs.mkdir(config.uploadDir, { recursive: true }).catch((err) => {
118
- console.error(`[OpacaCMS:LocalAdapter] Failed to create upload directory ${config.uploadDir}:`, err);
119
- });
120
- const getFullPath = (filename) => {
121
- return path.join(config.uploadDir, filename);
122
- };
123
- const getPublicUrl = (filename) => {
124
- const base = config.publicUrl.replace(/\/$/, "");
125
- return `${base}/${filename}`;
126
- };
127
- return {
128
- name: "local",
129
- async upload(file, options) {
130
- try {
131
- if (options?.allowedmime_types && !options.allowedmime_types.includes(file.mime_type)) {
132
- throw new Invalidmime_typeError("local", options.allowedmime_types, file.mime_type);
133
- }
134
- if (options?.maxFileSize && file.filesize > options.maxFileSize) {
135
- throw new FileTooLargeError("local", options.maxFileSize, file.filesize);
136
- }
137
- let finalFilename = file.filename;
138
- if (options?.generateUniqueName) {
139
- const ext = path.extname(file.original_filename);
140
- const hash = crypto.randomUUID().split("-")[0];
141
- const base = path.basename(finalFilename, ext).replace(/[^a-z0-9]/gi, "-").toLowerCase();
142
- finalFilename = `${base}-${hash}${ext}`;
143
- }
144
- const sanitizedFilename = path.basename(finalFilename);
145
- const fullPath = path.resolve(config.uploadDir, sanitizedFilename);
146
- if (!fullPath.startsWith(path.resolve(config.uploadDir))) {
147
- throw new StorageError("local", "upload", "Path traversal attempt detected.");
148
- }
149
- if (file.buffer && typeof Bun !== "undefined") {
150
- await Bun.write(fullPath, file.buffer);
151
- } else if (file.buffer) {
152
- await fs.writeFile(fullPath, file.buffer);
153
- } else if (file.stream) {
154
- const writeStream = __require("node:fs").createWriteStream(fullPath);
155
- const reader = file.stream.getReader();
156
- try {
157
- while (true) {
158
- const { done, value } = await reader.read();
159
- if (done)
160
- break;
161
- if (value) {
162
- writeStream.write(Buffer.from(value));
163
- }
164
- }
165
- } finally {
166
- writeStream.end();
167
- reader.releaseLock();
168
- }
169
- } else {
170
- throw new Error("Neither Buffer nor Stream provided.");
171
- }
172
- return {
173
- filename: sanitizedFilename,
174
- mime_type: file.mime_type,
175
- filesize: file.filesize,
176
- url: getPublicUrl(sanitizedFilename)
177
- };
178
- } catch (error) {
179
- if (error instanceof StorageError)
180
- throw error;
181
- throw new StorageError("local", "upload", `Failed to write ${file.filename} to disk`, error);
182
- }
183
- },
184
- async delete(filename) {
185
- try {
186
- const fullPath = getFullPath(path.basename(filename));
187
- await fs.unlink(fullPath);
188
- } catch (error) {
189
- if (error.code !== "ENOENT") {
190
- throw new StorageError("local", "delete", `Failed to delete ${filename}`, error);
191
- }
192
- }
193
- },
194
- async exists(filename) {
195
- try {
196
- await fs.access(getFullPath(path.basename(filename)), __require("node:fs").constants.F_OK);
197
- return true;
198
- } catch {
199
- return false;
200
- }
201
- },
202
- async download(filename) {
203
- const fullPath = getFullPath(path.basename(filename));
204
- if (typeof Bun !== "undefined") {
205
- return Bun.file(fullPath).stream();
206
- }
207
- const nodeStream = __require("node:fs").createReadStream(fullPath);
208
- return new ReadableStream({
209
- start(controller) {
210
- nodeStream.on("data", (chunk) => controller.enqueue(new Uint8Array(chunk)));
211
- nodeStream.on("end", () => controller.close());
212
- nodeStream.on("error", (err) => controller.error(err));
213
- },
214
- cancel() {
215
- nodeStream.destroy();
216
- }
217
- });
218
- }
219
- };
220
- }
221
- // src/storage/adapters/s3.ts
222
- import {
223
- DeleteObjectCommand,
224
- GetObjectCommand,
225
- HeadObjectCommand,
226
- PutObjectCommand,
227
- S3Client
228
- } from "@aws-sdk/client-s3";
229
- import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
230
- function createS3Adapter(config) {
231
- const s3Client = new S3Client({
232
- region: config.region,
233
- endpoint: config.endpoint,
234
- credentials: config.credentials,
235
- forcePathStyle: config.forcePathStyle
236
- });
237
- const getFullKey = (filename) => {
238
- if (config.prefix) {
239
- const p = config.prefix.replace(/\/$/, "");
240
- return `${p}/${filename}`;
241
- }
242
- return filename;
243
- };
244
- const getPublicUrl = (filename) => {
245
- if (config.publicUrl) {
246
- const base = config.publicUrl.replace(/\/$/, "");
247
- return `${base}/${getFullKey(filename)}`;
248
- }
249
- return `https://${config.bucket}.s3.${config.region}.amazonaws.com/${getFullKey(filename)}`;
250
- };
251
- return {
252
- name: "s3",
253
- async upload(file, options) {
254
- try {
255
- if (options?.allowedmime_types && !options.allowedmime_types.includes(file.mime_type)) {
256
- throw new Invalidmime_typeError("s3", options.allowedmime_types, file.mime_type);
257
- }
258
- if (options?.maxFileSize && file.filesize > options.maxFileSize) {
259
- throw new FileTooLargeError("s3", options.maxFileSize, file.filesize);
260
- }
261
- let finalFilename = file.filename;
262
- if (options?.generateUniqueName) {
263
- const ext = file.original_filename.split(".").pop() || "";
264
- const hash = crypto.randomUUID().split("-")[0];
265
- const base = finalFilename.replace(`.${ext}`, "").replace(/[^a-z0-9]/gi, "-").toLowerCase();
266
- finalFilename = `${base}-${hash}.${ext}`;
267
- }
268
- const key = getFullKey(finalFilename);
269
- const body = file.buffer || file.stream;
270
- const command = new PutObjectCommand({
271
- Bucket: config.bucket,
272
- Key: key,
273
- Body: body,
274
- ContentType: file.mime_type,
275
- ContentLength: file.filesize,
276
- ACL: config.acl || "private"
277
- });
278
- await s3Client.send(command);
279
- return {
280
- filename: finalFilename,
281
- mime_type: file.mime_type,
282
- filesize: file.filesize,
283
- url: getPublicUrl(finalFilename)
284
- };
285
- } catch (error) {
286
- if (error instanceof StorageError)
287
- throw error;
288
- throw new StorageError("s3", "upload", `Failed to upload ${file.filename} to S3 bucket ${config.bucket}`, error);
289
- }
290
- },
291
- async delete(filename) {
292
- try {
293
- const command = new DeleteObjectCommand({
294
- Bucket: config.bucket,
295
- Key: getFullKey(filename)
296
- });
297
- await s3Client.send(command);
298
- } catch (error) {
299
- throw new StorageError("s3", "delete", `Failed to delete ${filename} from S3 bucket ${config.bucket}`, error);
300
- }
301
- },
302
- async exists(filename) {
303
- try {
304
- const command = new HeadObjectCommand({
305
- Bucket: config.bucket,
306
- Key: getFullKey(filename)
307
- });
308
- await s3Client.send(command);
309
- return true;
310
- } catch (error) {
311
- if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404)
312
- return false;
313
- throw new StorageError("s3", "download", `Failed to check existence of ${filename}`, error);
314
- }
315
- },
316
- async generatePresignedUrl(filename, operation, expiresInSeconds = 3600) {
317
- try {
318
- let command;
319
- if (operation === "write") {
320
- command = new PutObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
321
- } else {
322
- command = new GetObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
323
- }
324
- return await getSignedUrl(s3Client, command, { expiresIn: expiresInSeconds });
325
- } catch (error) {
326
- throw new StorageError("s3", "presign", `Failed to generate presigned URL for ${filename}`, error);
327
- }
328
- },
329
- async download(filename) {
330
- try {
331
- const command = new GetObjectCommand({
332
- Bucket: config.bucket,
333
- Key: getFullKey(filename)
334
- });
335
- const response = await s3Client.send(command);
336
- if (!response.Body) {
337
- throw new StorageError("s3", "download", `File not found: ${filename}`);
338
- }
339
- return response.Body.transformToWebStream();
340
- } catch (error) {
341
- if (error instanceof StorageError)
342
- throw error;
343
- throw new StorageError("s3", "download", `Failed to download ${filename} from S3 bucket ${config.bucket}`, error);
344
- }
345
- }
346
- };
347
- }
348
- export {
349
- createS3Adapter,
350
- createR2Storage,
351
- createLocalAdapter,
352
- StorageError,
353
- Invalidmime_typeError,
354
- FileTooLargeError
355
- };
package/global.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import "hono";
2
- import type { OpacaConfig, User } from "./src/types";
3
- import type { Auth } from "./src/auth/index";
4
-
5
- declare module "hono" {
6
- interface ContextVariableMap {
7
- config: OpacaConfig;
8
- auth: Auth;
9
- user: User;
10
- }
11
- }
@@ -1,63 +0,0 @@
1
- import ky from "ky";
2
-
3
- let client: typeof ky | null = null;
4
- let currentBaseURL: string | null = null;
5
-
6
- export const configureAPI = (serverUrl: string) => {
7
- if (!serverUrl || !serverUrl.startsWith("http")) return;
8
- const url = serverUrl;
9
- const baseURL = url.replace(/\/$/, "");
10
- if (client && currentBaseURL === baseURL) return;
11
-
12
- currentBaseURL = baseURL;
13
- client = ky.create({
14
- prefixUrl: baseURL,
15
- credentials: "include",
16
- retry: 0,
17
- hooks: {
18
- afterResponse: [
19
- async (_request, _options, response) => {
20
- if (response.status === 401 || response.status === 403) {
21
- // Se o auth handler do backend falhar globalmente em qualquer requisição da API (sessão morreu/expirada)
22
- // Lançamos a revalidação da store local para despachar o usuário pra tela de login.
23
- try {
24
- const { $session } = await import("./stores/auth");
25
- const { notify } = await import("./stores/ui");
26
- $session.set(null);
27
- notify("Session expired. Please log in again.", "error");
28
- } catch (e) {}
29
- }
30
- },
31
- ],
32
- },
33
- });
34
- };
35
-
36
- export const getCurrentBaseURL = () => {
37
- if (!currentBaseURL) {
38
- throw new Error("API client not configured. Did you provide a valid serverUrl?");
39
- }
40
- return currentBaseURL as string;
41
- };
42
-
43
- /**
44
- * A proxy for ky that allows us to configure the baseURL late
45
- * (e.g. after we have the serverURL from props).
46
- * @param prop: string
47
- */
48
- export const api = new Proxy({} as typeof ky, {
49
- get(_, prop) {
50
- if (!client) {
51
- // No auto-fallback for web components.
52
- throw new Error("API client not configured. Did you provide a valid serverUrl?");
53
- }
54
-
55
- if (!client) throw new Error("API client not configured");
56
-
57
- const c = client;
58
- if (c) {
59
- return c[prop as keyof typeof ky];
60
- }
61
- return undefined;
62
- },
63
- });
@@ -1,40 +0,0 @@
1
- import { createAuthClient } from "better-auth/client";
2
- import { adminClient } from "better-auth/client/plugins";
3
- import { logger } from "@/utils/logger";
4
-
5
- let client: ReturnType<typeof createAuthClient> | null = null;
6
- let currentURL: string | null = null;
7
-
8
- export const configureAuth = (serverUrl: string) => {
9
- if (!serverUrl || !serverUrl.startsWith("http")) return;
10
- const url = serverUrl;
11
- const baseURL = url.replace(/\/$/, "") + "/api/auth";
12
- if (client && currentURL === baseURL) return;
13
-
14
- currentURL = baseURL;
15
- client = createAuthClient({
16
- baseURL,
17
- autoRefresh: true,
18
- fetchOptions: {
19
- credentials: "include",
20
- },
21
- plugins: [adminClient()],
22
- });
23
- };
24
-
25
- /**
26
- * A proxy for the authClient that allows us to configure it late
27
- * (e.g. after we have the user's config with serverURL).
28
- */
29
- export const authClient = new Proxy({} as ReturnType<typeof createAuthClient>, {
30
- get(_, prop) {
31
- if (!client) {
32
- // No auto-fallback to origin for web components.
33
- // AdminClient will call configureAuth when it has the correct prop.
34
- throw new Error("Auth client not configured. Did you provide a valid serverUrl?");
35
- }
36
- return (client as ReturnType<typeof createAuthClient>)[
37
- prop as keyof ReturnType<typeof createAuthClient>
38
- ];
39
- },
40
- });
@@ -1,179 +0,0 @@
1
- export interface CustomFieldProps<TValue = any, TConfig = Record<string, any>> {
2
- /** The current value of the field from the CMS database */
3
- value: TValue;
4
- /** The full schema configuration of the field */
5
- fieldConfig: TConfig;
6
- /** Whether the field is currently disabled by access control */
7
- disabled: boolean;
8
- /** Whether the field is currently read-only by access control */
9
- readOnly: boolean;
10
- /** A validation error message from the CMS, if any */
11
- error?: string;
12
- /** The current full state of the parent form or row */
13
- parentData?: Record<string, unknown>;
14
- /** Callback to notify the CMS that the data has changed */
15
- onChange: (value: TValue) => void;
16
- }
17
-
18
- export interface CustomFieldAdapter {
19
- /**
20
- * Called exactly once when the field is inserted into the CMS Admin UI.
21
- * Use this to render your React root, Vue app, or Vanilla DOM nodes.
22
- *
23
- * @param container The DOM element acting as the wrapper for your component.
24
- * @param props The initial properties (value, config, onChange) from the CMS.
25
- */
26
- mount: (container: HTMLElement, props: CustomFieldProps) => void;
27
-
28
- /**
29
- * Called whenever the CMS pushes new data to the field (e.g. form resets,
30
- * external value changes).
31
- *
32
- * @param container The same DOM element wrapper.
33
- * @param props The updated properties.
34
- */
35
- update?: (container: HTMLElement, props: CustomFieldProps) => void;
36
-
37
- /**
38
- * Called exactly once when the field is removed from the DOM (e.g., navigating away).
39
- * Use this to unmount your React root or Vue app to prevent memory leaks.
40
- *
41
- * @param container The same DOM element wrapper.
42
- */
43
- unmount?: (container: HTMLElement) => void;
44
- }
45
-
46
- /**
47
- * A built-in utility to register framework-agnostic Custom Web Components for the OpacaCMS Admin UI.
48
- *
49
- * It acts as an adapter, translating the Web Component lifecycle (`connectedCallback`, `disconnectedCallback`,
50
- * property setters) into a simple `mount` / `update` / `unmount` paradigm that can easily wrap React, Vue, Angular,
51
- * or plain Javascript applications.
52
- *
53
- * @example
54
- * ```tsx
55
- * import { defineCustomField } from 'opacacms/admin';
56
- * import { createRoot } from 'react-dom/client';
57
- *
58
- * defineCustomField('my-react-picker', {
59
- * mount: (container, props) => {
60
- * (container as any)._root = createRoot(container);
61
- * (container as any)._root.render(<MyPicker {...props} />);
62
- * },
63
- * update: (container, props) => {
64
- * (container as any)._root.render(<MyPicker {...props} />);
65
- * },
66
- * unmount: (container) => {
67
- * (container as any)._root.unmount();
68
- * }
69
- * });
70
- * ```
71
- *
72
- * @param tagName The tag name to register in the browser (e.g., `opaca-color-picker`). Must contain a hyphen.
73
- * @param adapter The adapter containing `mount`, optional `update`, and optional `unmount` lifecycle methods.
74
- */
75
- export function defineCustomField(tagName: string, adapter: CustomFieldAdapter) {
76
- if (typeof window === "undefined") return;
77
-
78
- if (customElements.get(tagName)) {
79
- console.warn(`[OpacaCMS] Custom field tag "${tagName}" is already defined.`);
80
- return;
81
- }
82
-
83
- class OpacaCustomFieldElement extends HTMLElement {
84
- private _value: any;
85
- private _fieldConfig: any;
86
- private _error?: string;
87
- private _parentData?: Record<string, unknown>;
88
- private _isMounted = false;
89
-
90
- // Helper to abstract the complex CustomEvent away from the user's DX
91
- private handleChange = (newValue: any) => {
92
- this.dispatchEvent(
93
- new CustomEvent("opacachange", {
94
- detail: { value: newValue },
95
- bubbles: true,
96
- composed: true,
97
- }),
98
- );
99
- };
100
-
101
- private getProps(): CustomFieldProps {
102
- return {
103
- value: this._value,
104
- fieldConfig: this._fieldConfig,
105
- disabled: this.getAttribute("data-disabled") === "true",
106
- readOnly: this.getAttribute("data-readonly") === "true",
107
- error: this._error,
108
- parentData: this._parentData,
109
- onChange: this.handleChange,
110
- };
111
- }
112
-
113
- set error(err: string | undefined) {
114
- if (this._error !== err) {
115
- this._error = err;
116
- if (this._isMounted && adapter.update) {
117
- adapter.update(this, this.getProps());
118
- }
119
- }
120
- }
121
-
122
- get error() {
123
- return this._error;
124
- }
125
-
126
- set parentData(data: Record<string, unknown> | undefined) {
127
- this._parentData = data;
128
- if (this._isMounted && adapter.update) {
129
- adapter.update(this, this.getProps());
130
- }
131
- }
132
-
133
- get parentData() {
134
- return this._parentData;
135
- }
136
-
137
- set value(val: any) {
138
- const oldValue = this._value;
139
- this._value = val;
140
- // Only call update if the value actually changed and the component is mounted
141
- if (this._isMounted && adapter.update && oldValue !== val) {
142
- adapter.update(this, this.getProps());
143
- }
144
- }
145
-
146
- get value() {
147
- return this._value;
148
- }
149
-
150
- set fieldConfig(config: any) {
151
- this._fieldConfig = config;
152
- if (this._isMounted && adapter.update) {
153
- adapter.update(this, this.getProps());
154
- }
155
- }
156
-
157
- get fieldConfig() {
158
- return this._fieldConfig;
159
- }
160
-
161
- connectedCallback() {
162
- if (!this._isMounted) {
163
- adapter.mount(this, this.getProps());
164
- this._isMounted = true;
165
- }
166
- }
167
-
168
- disconnectedCallback() {
169
- if (this._isMounted) {
170
- if (adapter.unmount) {
171
- adapter.unmount(this);
172
- }
173
- this._isMounted = false;
174
- }
175
- }
176
- }
177
-
178
- customElements.define(tagName, OpacaCustomFieldElement);
179
- }
@@ -1,15 +0,0 @@
1
- export {
2
- type CustomFieldAdapter,
3
- type CustomFieldProps,
4
- defineCustomField,
5
- } from "./custom-field";
6
- export { defineReactField } from "./react";
7
- export * from "./router";
8
- export * from "./stores/config";
9
- export * from "./stores/query";
10
- export * from "./stores/ui";
11
- export { AdminClient } from "./ui/admin-client";
12
- export { AdminLayout } from "./ui/admin-layout";
13
- export { Breadcrumbs } from "./ui/components/ui/breadcrumbs";
14
- export { Link } from "./ui/components/link";
15
- export { Toast, ToastContainer } from "./ui/components/toast";