@sonicjs-cms/core 2.0.10 → 2.2.0

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 (75) hide show
  1. package/dist/{chunk-Q7SL7U43.cjs → chunk-2DIWLDCA.cjs} +12001 -10740
  2. package/dist/chunk-2DIWLDCA.cjs.map +1 -0
  3. package/dist/{chunk-LW33AOBF.js → chunk-5RKQB2JG.js} +6 -222
  4. package/dist/chunk-5RKQB2JG.js.map +1 -0
  5. package/dist/{chunk-DOR2IU73.cjs → chunk-AINTFRTC.cjs} +2 -2
  6. package/dist/{chunk-DOR2IU73.cjs.map → chunk-AINTFRTC.cjs.map} +1 -1
  7. package/dist/chunk-HV2I6API.cjs +1049 -0
  8. package/dist/chunk-HV2I6API.cjs.map +1 -0
  9. package/dist/chunk-K4Z3IHOK.js +1031 -0
  10. package/dist/chunk-K4Z3IHOK.js.map +1 -0
  11. package/dist/{chunk-6FR25MPC.js → chunk-L232U757.js} +2 -2
  12. package/dist/{chunk-6FR25MPC.js.map → chunk-L232U757.js.map} +1 -1
  13. package/dist/chunk-NMVOTNSL.js +61 -0
  14. package/dist/chunk-NMVOTNSL.js.map +1 -0
  15. package/dist/{chunk-YHG45LMU.js → chunk-OORGXYDA.js} +48 -5
  16. package/dist/chunk-OORGXYDA.js.map +1 -0
  17. package/dist/{chunk-FTMKKKNH.js → chunk-QNWYQZ55.js} +3 -3
  18. package/dist/{chunk-FTMKKKNH.js.map → chunk-QNWYQZ55.js.map} +1 -1
  19. package/dist/{chunk-Z4H6DBVF.js → chunk-R57VFNP3.js} +11991 -10731
  20. package/dist/chunk-R57VFNP3.js.map +1 -0
  21. package/dist/{chunk-COBUPOMD.js → chunk-T7IYBGGO.cjs} +5 -770
  22. package/dist/chunk-T7IYBGGO.cjs.map +1 -0
  23. package/dist/{chunk-HXA5QSI3.cjs → chunk-UEYMFNBN.cjs} +51 -6
  24. package/dist/chunk-UEYMFNBN.cjs.map +1 -0
  25. package/dist/chunk-WBX5YMTB.cjs +70 -0
  26. package/dist/chunk-WBX5YMTB.cjs.map +1 -0
  27. package/dist/{chunk-3PHG75W4.cjs → chunk-YTMFJLJZ.cjs} +7 -5
  28. package/dist/chunk-YTMFJLJZ.cjs.map +1 -0
  29. package/dist/{chunk-MU3MR2QR.cjs → chunk-YU6QFFI4.cjs} +5 -222
  30. package/dist/chunk-YU6QFFI4.cjs.map +1 -0
  31. package/dist/{chunk-CAP6QQR2.cjs → chunk-ZMSYKV62.cjs} +5 -5
  32. package/dist/{chunk-CAP6QQR2.cjs.map → chunk-ZMSYKV62.cjs.map} +1 -1
  33. package/dist/{chunk-NBDPIRQS.cjs → chunk-ZPMFT2JW.js} +4 -786
  34. package/dist/chunk-ZPMFT2JW.js.map +1 -0
  35. package/dist/{chunk-MXJJN4IA.js → chunk-ZUK55KZB.js} +7 -5
  36. package/dist/chunk-ZUK55KZB.js.map +1 -0
  37. package/dist/index.cjs +542 -145
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.js +389 -12
  40. package/dist/index.js.map +1 -1
  41. package/dist/middleware.cjs +33 -23
  42. package/dist/middleware.js +4 -2
  43. package/dist/migrations-IHERIQVD.js +4 -0
  44. package/dist/migrations-IHERIQVD.js.map +1 -0
  45. package/dist/migrations-POFD5KNG.cjs +13 -0
  46. package/dist/migrations-POFD5KNG.cjs.map +1 -0
  47. package/dist/routes.cjs +31 -29
  48. package/dist/routes.js +8 -6
  49. package/dist/services.cjs +44 -26
  50. package/dist/services.js +4 -2
  51. package/dist/templates.cjs +17 -21
  52. package/dist/templates.js +2 -2
  53. package/dist/utils.cjs +44 -11
  54. package/dist/utils.js +2 -1
  55. package/migrations/001_initial_schema.sql +2 -2
  56. package/migrations/007_demo_login_plugin.sql +1 -1
  57. package/migrations/020_add_email_plugin.sql +22 -0
  58. package/migrations/021_add_magic_link_auth_plugin.sql +42 -0
  59. package/migrations/021_add_otp_login.sql +42 -0
  60. package/migrations/022_add_tinymce_plugin.sql +25 -0
  61. package/migrations/023_add_easy_mdx_plugin.sql +25 -0
  62. package/migrations/024_add_quill_editor_plugin.sql +25 -0
  63. package/migrations/025_rename_mdxeditor_to_easy_mdx.sql +22 -0
  64. package/package.json +5 -3
  65. package/dist/chunk-3PHG75W4.cjs.map +0 -1
  66. package/dist/chunk-COBUPOMD.js.map +0 -1
  67. package/dist/chunk-HXA5QSI3.cjs.map +0 -1
  68. package/dist/chunk-LW33AOBF.js.map +0 -1
  69. package/dist/chunk-MU3MR2QR.cjs.map +0 -1
  70. package/dist/chunk-MXJJN4IA.js.map +0 -1
  71. package/dist/chunk-NBDPIRQS.cjs.map +0 -1
  72. package/dist/chunk-Q7SL7U43.cjs.map +0 -1
  73. package/dist/chunk-YHG45LMU.js.map +0 -1
  74. package/dist/chunk-Z4H6DBVF.js.map +0 -1
  75. package/migrations/002_faq_plugin.sql +0 -86
@@ -1,268 +1,4 @@
1
- // src/services/collection-loader.ts
2
- var registeredCollections = [];
3
- function registerCollections(collections) {
4
- for (const config of collections) {
5
- if (!config.name || !config.displayName || !config.schema) {
6
- console.error(`Invalid collection config: missing required fields`, config);
7
- continue;
8
- }
9
- const normalizedConfig = {
10
- ...config,
11
- managed: config.managed !== void 0 ? config.managed : true,
12
- isActive: config.isActive !== void 0 ? config.isActive : true
13
- };
14
- registeredCollections.push(normalizedConfig);
15
- console.log(`\u2713 Registered collection: ${config.name}`);
16
- }
17
- }
18
- async function loadCollectionConfigs() {
19
- const collections = [...registeredCollections];
20
- try {
21
- const modules = import.meta.glob?.("../collections/*.collection.ts", { eager: true }) || {};
22
- for (const [path, module] of Object.entries(modules)) {
23
- try {
24
- const configModule = module;
25
- if (!configModule.default) {
26
- console.warn(`Collection file ${path} does not export a default config`);
27
- continue;
28
- }
29
- const config = configModule.default;
30
- if (!config.name || !config.displayName || !config.schema) {
31
- console.error(`Invalid collection config in ${path}: missing required fields`);
32
- continue;
33
- }
34
- const normalizedConfig = {
35
- ...config,
36
- managed: config.managed !== void 0 ? config.managed : true,
37
- isActive: config.isActive !== void 0 ? config.isActive : true
38
- };
39
- collections.push(normalizedConfig);
40
- console.log(`\u2713 Loaded collection config: ${config.name}`);
41
- } catch (error) {
42
- console.error(`Error loading collection from ${path}:`, error);
43
- }
44
- }
45
- console.log(`Loaded ${collections.length} total collection configuration(s) (${registeredCollections.length} registered, ${collections.length - registeredCollections.length} from core)`);
46
- return collections;
47
- } catch (error) {
48
- console.error("Error loading collection configurations:", error);
49
- return collections;
50
- }
51
- }
52
- async function loadCollectionConfig(name) {
53
- try {
54
- console.warn("loadCollectionConfig requires implementation in consuming application");
55
- return null;
56
- } catch (error) {
57
- console.error(`Error loading collection ${name}:`, error);
58
- return null;
59
- }
60
- }
61
- async function getAvailableCollectionNames() {
62
- try {
63
- const modules = import.meta.glob?.("../collections/*.collection.ts") || {};
64
- const names = [];
65
- for (const path of Object.keys(modules)) {
66
- const match = path.match(/\/([^/]+)\.collection\.ts$/);
67
- if (match && match[1]) {
68
- names.push(match[1]);
69
- }
70
- }
71
- return names;
72
- } catch (error) {
73
- console.error("Error getting collection names:", error);
74
- return [];
75
- }
76
- }
77
- function validateCollectionConfig(config) {
78
- const errors = [];
79
- if (!config.name) {
80
- errors.push("Collection name is required");
81
- } else if (!/^[a-z0-9_]+$/.test(config.name)) {
82
- errors.push("Collection name must contain only lowercase letters, numbers, and underscores");
83
- }
84
- if (!config.displayName) {
85
- errors.push("Display name is required");
86
- }
87
- if (!config.schema) {
88
- errors.push("Schema is required");
89
- } else {
90
- if (config.schema.type !== "object") {
91
- errors.push('Schema type must be "object"');
92
- }
93
- if (!config.schema.properties || typeof config.schema.properties !== "object") {
94
- errors.push("Schema must have properties");
95
- }
96
- for (const [fieldName, fieldConfig] of Object.entries(config.schema.properties || {})) {
97
- if (!fieldConfig.type) {
98
- errors.push(`Field "${fieldName}" is missing type`);
99
- }
100
- if (fieldConfig.type === "reference" && !fieldConfig.collection) {
101
- errors.push(`Reference field "${fieldName}" is missing collection property`);
102
- }
103
- if (["select", "multiselect", "radio"].includes(fieldConfig.type) && !fieldConfig.enum) {
104
- errors.push(`Select field "${fieldName}" is missing enum options`);
105
- }
106
- }
107
- }
108
- return {
109
- valid: errors.length === 0,
110
- errors
111
- };
112
- }
113
-
114
- // src/services/collection-sync.ts
115
- async function syncCollections(db) {
116
- console.log("\u{1F504} Starting collection sync...");
117
- const results = [];
118
- const configs = await loadCollectionConfigs();
119
- if (configs.length === 0) {
120
- console.log("\u26A0\uFE0F No collection configurations found");
121
- return results;
122
- }
123
- for (const config of configs) {
124
- const result = await syncCollection(db, config);
125
- results.push(result);
126
- }
127
- const created = results.filter((r) => r.status === "created").length;
128
- const updated = results.filter((r) => r.status === "updated").length;
129
- const unchanged = results.filter((r) => r.status === "unchanged").length;
130
- const errors = results.filter((r) => r.status === "error").length;
131
- console.log(`\u2705 Collection sync complete: ${created} created, ${updated} updated, ${unchanged} unchanged, ${errors} errors`);
132
- return results;
133
- }
134
- async function syncCollection(db, config) {
135
- try {
136
- const validation = validateCollectionConfig(config);
137
- if (!validation.valid) {
138
- return {
139
- name: config.name,
140
- status: "error",
141
- error: `Validation failed: ${validation.errors.join(", ")}`
142
- };
143
- }
144
- const existingStmt = db.prepare("SELECT * FROM collections WHERE name = ?");
145
- const existing = await existingStmt.bind(config.name).first();
146
- const now = Date.now();
147
- const collectionId = existing?.id || `col-${config.name}-${crypto.randomUUID().slice(0, 8)}`;
148
- const schemaJson = JSON.stringify(config.schema);
149
- const isActive = config.isActive !== false ? 1 : 0;
150
- const managed = config.managed !== false ? 1 : 0;
151
- if (!existing) {
152
- const insertStmt = db.prepare(`
153
- INSERT INTO collections (id, name, display_name, description, schema, is_active, managed, created_at, updated_at)
154
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
155
- `);
156
- await insertStmt.bind(
157
- collectionId,
158
- config.name,
159
- config.displayName,
160
- config.description || null,
161
- schemaJson,
162
- isActive,
163
- managed,
164
- now,
165
- now
166
- ).run();
167
- console.log(` \u2713 Created collection: ${config.name}`);
168
- return {
169
- name: config.name,
170
- status: "created",
171
- message: `Created collection "${config.displayName}"`
172
- };
173
- } else {
174
- const existingSchema = existing.schema ? JSON.stringify(existing.schema) : "{}";
175
- const existingDisplayName = existing.display_name;
176
- const existingDescription = existing.description;
177
- const existingIsActive = existing.is_active;
178
- const existingManaged = existing.managed;
179
- const needsUpdate = schemaJson !== existingSchema || config.displayName !== existingDisplayName || (config.description || null) !== existingDescription || isActive !== existingIsActive || managed !== existingManaged;
180
- if (!needsUpdate) {
181
- return {
182
- name: config.name,
183
- status: "unchanged",
184
- message: `Collection "${config.displayName}" is up to date`
185
- };
186
- }
187
- const updateStmt = db.prepare(`
188
- UPDATE collections
189
- SET display_name = ?, description = ?, schema = ?, is_active = ?, managed = ?, updated_at = ?
190
- WHERE name = ?
191
- `);
192
- await updateStmt.bind(
193
- config.displayName,
194
- config.description || null,
195
- schemaJson,
196
- isActive,
197
- managed,
198
- now,
199
- config.name
200
- ).run();
201
- console.log(` \u2713 Updated collection: ${config.name}`);
202
- return {
203
- name: config.name,
204
- status: "updated",
205
- message: `Updated collection "${config.displayName}"`
206
- };
207
- }
208
- } catch (error) {
209
- console.error(` \u2717 Error syncing collection ${config.name}:`, error);
210
- return {
211
- name: config.name,
212
- status: "error",
213
- error: error instanceof Error ? error.message : "Unknown error"
214
- };
215
- }
216
- }
217
- async function isCollectionManaged(db, collectionName) {
218
- try {
219
- const stmt = db.prepare("SELECT managed FROM collections WHERE name = ?");
220
- const result = await stmt.bind(collectionName).first();
221
- return result?.managed === 1;
222
- } catch (error) {
223
- console.error(`Error checking if collection is managed:`, error);
224
- return false;
225
- }
226
- }
227
- async function getManagedCollections(db) {
228
- try {
229
- const stmt = db.prepare("SELECT name FROM collections WHERE managed = 1");
230
- const { results } = await stmt.all();
231
- return (results || []).map((row) => row.name);
232
- } catch (error) {
233
- console.error("Error getting managed collections:", error);
234
- return [];
235
- }
236
- }
237
- async function cleanupRemovedCollections(db) {
238
- try {
239
- const configs = await loadCollectionConfigs();
240
- const configNames = new Set(configs.map((c) => c.name));
241
- const managedCollections = await getManagedCollections(db);
242
- const removed = [];
243
- for (const managedName of managedCollections) {
244
- if (!configNames.has(managedName)) {
245
- const updateStmt = db.prepare(`
246
- UPDATE collections
247
- SET is_active = 0, updated_at = ?
248
- WHERE name = ? AND managed = 1
249
- `);
250
- await updateStmt.bind(Date.now(), managedName).run();
251
- removed.push(managedName);
252
- console.log(` \u26A0\uFE0F Deactivated removed collection: ${managedName}`);
253
- }
254
- }
255
- return removed;
256
- } catch (error) {
257
- console.error("Error cleaning up removed collections:", error);
258
- return [];
259
- }
260
- }
261
- async function fullCollectionSync(db) {
262
- const results = await syncCollections(db);
263
- const removed = await cleanupRemovedCollections(db);
264
- return { results, removed };
265
- }
1
+ 'use strict';
266
2
 
267
3
  // src/services/migrations.ts
268
4
  var MigrationService = class {
@@ -704,7 +440,7 @@ CREATE INDEX IF NOT EXISTS idx_api_tokens_token ON api_tokens(token);
704
440
  CREATE INDEX IF NOT EXISTS idx_workflow_history_content ON workflow_history(content_id);
705
441
  CREATE INDEX IF NOT EXISTS idx_workflow_history_user ON workflow_history(user_id);
706
442
 
707
- -- Insert default admin user (password: admin123)
443
+ -- Insert default admin user (password: sonicjs!)
708
444
  INSERT OR IGNORE INTO users (
709
445
  id, email, username, first_name, last_name, password_hash,
710
446
  role, is_active, created_at, updated_at
@@ -1005,507 +741,6 @@ INSERT OR IGNORE INTO content (
1005
741
  }
1006
742
  };
1007
743
 
1008
- // src/services/plugin-service.ts
1009
- var PluginService = class {
1010
- constructor(db) {
1011
- this.db = db;
1012
- }
1013
- async getAllPlugins() {
1014
- await this.ensureAllPluginsExist();
1015
- const stmt = this.db.prepare(`
1016
- SELECT * FROM plugins
1017
- ORDER BY is_core DESC, display_name ASC
1018
- `);
1019
- const { results } = await stmt.all();
1020
- return (results || []).map(this.mapPluginFromDb);
1021
- }
1022
- /**
1023
- * Ensure all plugins from the registry exist in the database
1024
- * Auto-installs any newly detected plugins with inactive status
1025
- *
1026
- * Note: This method should be overridden or configured with a plugin registry
1027
- * in the consuming application
1028
- */
1029
- async ensureAllPluginsExist() {
1030
- console.log("[PluginService] ensureAllPluginsExist - requires PLUGIN_REGISTRY configuration");
1031
- }
1032
- async getPlugin(pluginId) {
1033
- const stmt = this.db.prepare("SELECT * FROM plugins WHERE id = ?");
1034
- const plugin = await stmt.bind(pluginId).first();
1035
- if (!plugin) return null;
1036
- return this.mapPluginFromDb(plugin);
1037
- }
1038
- async getPluginByName(name) {
1039
- const stmt = this.db.prepare("SELECT * FROM plugins WHERE name = ?");
1040
- const plugin = await stmt.bind(name).first();
1041
- if (!plugin) return null;
1042
- return this.mapPluginFromDb(plugin);
1043
- }
1044
- async getPluginStats() {
1045
- const stmt = this.db.prepare(`
1046
- SELECT
1047
- COUNT(*) as total,
1048
- COUNT(CASE WHEN status = 'active' THEN 1 END) as active,
1049
- COUNT(CASE WHEN status = 'inactive' THEN 1 END) as inactive,
1050
- COUNT(CASE WHEN status = 'error' THEN 1 END) as errors
1051
- FROM plugins
1052
- `);
1053
- const stats = await stmt.first();
1054
- return {
1055
- total: stats.total || 0,
1056
- active: stats.active || 0,
1057
- inactive: stats.inactive || 0,
1058
- errors: stats.errors || 0
1059
- };
1060
- }
1061
- async installPlugin(pluginData) {
1062
- const id = pluginData.id || `plugin-${Date.now()}`;
1063
- const now = Math.floor(Date.now() / 1e3);
1064
- const stmt = this.db.prepare(`
1065
- INSERT INTO plugins (
1066
- id, name, display_name, description, version, author, category, icon,
1067
- status, is_core, settings, permissions, dependencies, download_count,
1068
- rating, installed_at, last_updated
1069
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1070
- `);
1071
- await stmt.bind(
1072
- id,
1073
- pluginData.name || id,
1074
- pluginData.display_name || "Unnamed Plugin",
1075
- pluginData.description || "",
1076
- pluginData.version || "1.0.0",
1077
- pluginData.author || "Unknown",
1078
- pluginData.category || "utilities",
1079
- pluginData.icon || "\u{1F50C}",
1080
- "inactive",
1081
- pluginData.is_core || false,
1082
- JSON.stringify(pluginData.settings || {}),
1083
- JSON.stringify(pluginData.permissions || []),
1084
- JSON.stringify(pluginData.dependencies || []),
1085
- pluginData.download_count || 0,
1086
- pluginData.rating || 0,
1087
- now,
1088
- now
1089
- ).run();
1090
- await this.logActivity(id, "installed", null, { version: pluginData.version });
1091
- const installed = await this.getPlugin(id);
1092
- if (!installed) throw new Error("Failed to install plugin");
1093
- return installed;
1094
- }
1095
- async uninstallPlugin(pluginId) {
1096
- const plugin = await this.getPlugin(pluginId);
1097
- if (!plugin) throw new Error("Plugin not found");
1098
- if (plugin.is_core) throw new Error("Cannot uninstall core plugins");
1099
- if (plugin.status === "active") {
1100
- await this.deactivatePlugin(pluginId);
1101
- }
1102
- const stmt = this.db.prepare("DELETE FROM plugins WHERE id = ?");
1103
- await stmt.bind(pluginId).run();
1104
- await this.logActivity(pluginId, "uninstalled", null, { name: plugin.name });
1105
- }
1106
- async activatePlugin(pluginId) {
1107
- const plugin = await this.getPlugin(pluginId);
1108
- if (!plugin) throw new Error("Plugin not found");
1109
- if (plugin.dependencies && plugin.dependencies.length > 0) {
1110
- await this.checkDependencies(plugin.dependencies);
1111
- }
1112
- const now = Math.floor(Date.now() / 1e3);
1113
- const stmt = this.db.prepare(`
1114
- UPDATE plugins
1115
- SET status = 'active', activated_at = ?, error_message = NULL
1116
- WHERE id = ?
1117
- `);
1118
- await stmt.bind(now, pluginId).run();
1119
- await this.logActivity(pluginId, "activated", null);
1120
- }
1121
- async deactivatePlugin(pluginId) {
1122
- const plugin = await this.getPlugin(pluginId);
1123
- if (!plugin) throw new Error("Plugin not found");
1124
- await this.checkDependents(plugin.name);
1125
- const stmt = this.db.prepare(`
1126
- UPDATE plugins
1127
- SET status = 'inactive', activated_at = NULL
1128
- WHERE id = ?
1129
- `);
1130
- await stmt.bind(pluginId).run();
1131
- await this.logActivity(pluginId, "deactivated", null);
1132
- }
1133
- async updatePluginSettings(pluginId, settings) {
1134
- const plugin = await this.getPlugin(pluginId);
1135
- if (!plugin) throw new Error("Plugin not found");
1136
- const stmt = this.db.prepare(`
1137
- UPDATE plugins
1138
- SET settings = ?, updated_at = unixepoch()
1139
- WHERE id = ?
1140
- `);
1141
- await stmt.bind(JSON.stringify(settings), pluginId).run();
1142
- await this.logActivity(pluginId, "settings_updated", null);
1143
- }
1144
- async setPluginError(pluginId, error) {
1145
- const stmt = this.db.prepare(`
1146
- UPDATE plugins
1147
- SET status = 'error', error_message = ?
1148
- WHERE id = ?
1149
- `);
1150
- await stmt.bind(error, pluginId).run();
1151
- await this.logActivity(pluginId, "error", null, { error });
1152
- }
1153
- async getPluginActivity(pluginId, limit = 10) {
1154
- const stmt = this.db.prepare(`
1155
- SELECT * FROM plugin_activity_log
1156
- WHERE plugin_id = ?
1157
- ORDER BY timestamp DESC
1158
- LIMIT ?
1159
- `);
1160
- const { results } = await stmt.bind(pluginId, limit).all();
1161
- return (results || []).map((row) => ({
1162
- id: row.id,
1163
- action: row.action,
1164
- userId: row.user_id,
1165
- details: row.details ? JSON.parse(row.details) : null,
1166
- timestamp: row.timestamp
1167
- }));
1168
- }
1169
- async registerHook(pluginId, hookName, handlerName, priority = 10) {
1170
- const id = `hook-${Date.now()}`;
1171
- const stmt = this.db.prepare(`
1172
- INSERT INTO plugin_hooks (id, plugin_id, hook_name, handler_name, priority)
1173
- VALUES (?, ?, ?, ?, ?)
1174
- `);
1175
- await stmt.bind(id, pluginId, hookName, handlerName, priority).run();
1176
- }
1177
- async registerRoute(pluginId, path, method, handlerName, middleware) {
1178
- const id = `route-${Date.now()}`;
1179
- const stmt = this.db.prepare(`
1180
- INSERT INTO plugin_routes (id, plugin_id, path, method, handler_name, middleware)
1181
- VALUES (?, ?, ?, ?, ?, ?)
1182
- `);
1183
- await stmt.bind(
1184
- id,
1185
- pluginId,
1186
- path,
1187
- method,
1188
- handlerName,
1189
- JSON.stringify(middleware || [])
1190
- ).run();
1191
- }
1192
- async getPluginHooks(pluginId) {
1193
- const stmt = this.db.prepare(`
1194
- SELECT * FROM plugin_hooks
1195
- WHERE plugin_id = ? AND is_active = TRUE
1196
- ORDER BY priority ASC
1197
- `);
1198
- const { results } = await stmt.bind(pluginId).all();
1199
- return results || [];
1200
- }
1201
- async getPluginRoutes(pluginId) {
1202
- const stmt = this.db.prepare(`
1203
- SELECT * FROM plugin_routes
1204
- WHERE plugin_id = ? AND is_active = TRUE
1205
- `);
1206
- const { results } = await stmt.bind(pluginId).all();
1207
- return results || [];
1208
- }
1209
- async checkDependencies(dependencies) {
1210
- for (const dep of dependencies) {
1211
- const plugin = await this.getPluginByName(dep);
1212
- if (!plugin || plugin.status !== "active") {
1213
- throw new Error(`Required dependency '${dep}' is not active`);
1214
- }
1215
- }
1216
- }
1217
- async checkDependents(pluginName) {
1218
- const stmt = this.db.prepare(`
1219
- SELECT id, display_name FROM plugins
1220
- WHERE status = 'active'
1221
- AND dependencies LIKE ?
1222
- `);
1223
- const { results } = await stmt.bind(`%"${pluginName}"%`).all();
1224
- if (results && results.length > 0) {
1225
- const names = results.map((p) => p.display_name).join(", ");
1226
- throw new Error(`Cannot deactivate. The following plugins depend on this one: ${names}`);
1227
- }
1228
- }
1229
- async logActivity(pluginId, action, userId, details) {
1230
- const id = `activity-${Date.now()}`;
1231
- const stmt = this.db.prepare(`
1232
- INSERT INTO plugin_activity_log (id, plugin_id, action, user_id, details)
1233
- VALUES (?, ?, ?, ?, ?)
1234
- `);
1235
- await stmt.bind(
1236
- id,
1237
- pluginId,
1238
- action,
1239
- userId,
1240
- details ? JSON.stringify(details) : null
1241
- ).run();
1242
- }
1243
- mapPluginFromDb(row) {
1244
- return {
1245
- id: row.id,
1246
- name: row.name,
1247
- display_name: row.display_name,
1248
- description: row.description,
1249
- version: row.version,
1250
- author: row.author,
1251
- category: row.category,
1252
- icon: row.icon,
1253
- status: row.status,
1254
- is_core: row.is_core === 1,
1255
- settings: row.settings ? JSON.parse(row.settings) : void 0,
1256
- permissions: row.permissions ? JSON.parse(row.permissions) : void 0,
1257
- dependencies: row.dependencies ? JSON.parse(row.dependencies) : void 0,
1258
- download_count: row.download_count || 0,
1259
- rating: row.rating || 0,
1260
- installed_at: row.installed_at,
1261
- activated_at: row.activated_at,
1262
- last_updated: row.last_updated,
1263
- error_message: row.error_message
1264
- };
1265
- }
1266
- };
1267
-
1268
- // src/services/plugin-bootstrap.ts
1269
- var PluginBootstrapService = class {
1270
- constructor(db) {
1271
- this.db = db;
1272
- this.pluginService = new PluginService(db);
1273
- }
1274
- pluginService;
1275
- /**
1276
- * Core plugins that should always be available in the system
1277
- */
1278
- CORE_PLUGINS = [
1279
- {
1280
- id: "core-auth",
1281
- name: "core-auth",
1282
- display_name: "Authentication System",
1283
- description: "Core authentication and user management system",
1284
- version: "1.0.0",
1285
- author: "SonicJS Team",
1286
- category: "security",
1287
- icon: "\u{1F510}",
1288
- permissions: ["manage:users", "manage:roles", "manage:permissions"],
1289
- dependencies: [],
1290
- settings: {
1291
- requiredFields: {
1292
- email: { required: true, minLength: 5, label: "Email", type: "email" },
1293
- password: { required: true, minLength: 8, label: "Password", type: "password" },
1294
- username: { required: true, minLength: 3, label: "Username", type: "text" },
1295
- firstName: { required: true, minLength: 1, label: "First Name", type: "text" },
1296
- lastName: { required: true, minLength: 1, label: "Last Name", type: "text" }
1297
- },
1298
- validation: {
1299
- emailFormat: true,
1300
- allowDuplicateUsernames: false,
1301
- passwordRequirements: {
1302
- requireUppercase: false,
1303
- requireLowercase: false,
1304
- requireNumbers: false,
1305
- requireSpecialChars: false
1306
- }
1307
- },
1308
- registration: {
1309
- enabled: true,
1310
- requireEmailVerification: false,
1311
- defaultRole: "viewer"
1312
- }
1313
- }
1314
- },
1315
- {
1316
- id: "core-media",
1317
- name: "core-media",
1318
- display_name: "Media Manager",
1319
- description: "Core media upload and management system",
1320
- version: "1.0.0",
1321
- author: "SonicJS Team",
1322
- category: "media",
1323
- icon: "\u{1F4F8}",
1324
- permissions: ["manage:media", "upload:files"],
1325
- dependencies: [],
1326
- settings: {}
1327
- },
1328
- {
1329
- id: "database-tools",
1330
- name: "database-tools",
1331
- display_name: "Database Tools",
1332
- description: "Database management tools including truncate, backup, and validation",
1333
- version: "1.0.0",
1334
- author: "SonicJS Team",
1335
- category: "system",
1336
- icon: "\u{1F5C4}\uFE0F",
1337
- permissions: ["manage:database", "admin"],
1338
- dependencies: [],
1339
- settings: {
1340
- enableTruncate: true,
1341
- enableBackup: true,
1342
- enableValidation: true,
1343
- requireConfirmation: true
1344
- }
1345
- },
1346
- {
1347
- id: "seed-data",
1348
- name: "seed-data",
1349
- display_name: "Seed Data",
1350
- description: "Generate realistic example users and content for testing and development",
1351
- version: "1.0.0",
1352
- author: "SonicJS Team",
1353
- category: "development",
1354
- icon: "\u{1F331}",
1355
- permissions: ["admin"],
1356
- dependencies: [],
1357
- settings: {
1358
- userCount: 20,
1359
- contentCount: 200,
1360
- defaultPassword: "password123"
1361
- }
1362
- },
1363
- {
1364
- id: "core-cache",
1365
- name: "core-cache",
1366
- display_name: "Cache System",
1367
- description: "Three-tiered caching system with memory, KV, and database layers",
1368
- version: "1.0.0",
1369
- author: "SonicJS Team",
1370
- category: "performance",
1371
- icon: "\u26A1",
1372
- permissions: ["manage:cache", "view:stats"],
1373
- dependencies: [],
1374
- settings: {
1375
- enableMemoryCache: true,
1376
- enableKVCache: true,
1377
- enableDatabaseCache: true,
1378
- defaultTTL: 3600
1379
- }
1380
- },
1381
- {
1382
- id: "workflow-plugin",
1383
- name: "workflow-plugin",
1384
- display_name: "Workflow Management",
1385
- description: "Content workflow management with approval chains, scheduling, and automation",
1386
- version: "1.0.0-beta.1",
1387
- author: "SonicJS Team",
1388
- category: "content",
1389
- icon: "\u{1F504}",
1390
- permissions: ["manage:workflows", "view:workflows", "transition:content"],
1391
- dependencies: ["content-plugin"],
1392
- settings: {
1393
- enableApprovalChains: true,
1394
- enableScheduling: true,
1395
- enableAutomation: true,
1396
- enableNotifications: true
1397
- }
1398
- }
1399
- ];
1400
- /**
1401
- * Bootstrap all core plugins - install them if they don't exist
1402
- */
1403
- async bootstrapCorePlugins() {
1404
- console.log("[PluginBootstrap] Starting core plugin bootstrap process...");
1405
- try {
1406
- for (const corePlugin of this.CORE_PLUGINS) {
1407
- await this.ensurePluginInstalled(corePlugin);
1408
- }
1409
- console.log(
1410
- "[PluginBootstrap] Core plugin bootstrap completed successfully"
1411
- );
1412
- } catch (error) {
1413
- console.error("[PluginBootstrap] Error during plugin bootstrap:", error);
1414
- throw error;
1415
- }
1416
- }
1417
- /**
1418
- * Ensure a specific plugin is installed
1419
- */
1420
- async ensurePluginInstalled(plugin) {
1421
- try {
1422
- const existingPlugin = await this.pluginService.getPlugin(plugin.id);
1423
- if (existingPlugin) {
1424
- console.log(
1425
- `[PluginBootstrap] Plugin already installed: ${plugin.display_name} (status: ${existingPlugin.status})`
1426
- );
1427
- if (existingPlugin.version !== plugin.version) {
1428
- console.log(
1429
- `[PluginBootstrap] Updating plugin version: ${plugin.display_name} from ${existingPlugin.version} to ${plugin.version}`
1430
- );
1431
- await this.updatePlugin(plugin);
1432
- }
1433
- if (plugin.id === "core-auth" && existingPlugin.status !== "active") {
1434
- console.log(
1435
- `[PluginBootstrap] Core-auth plugin is inactive, activating it now...`
1436
- );
1437
- await this.pluginService.activatePlugin(plugin.id);
1438
- }
1439
- } else {
1440
- console.log(
1441
- `[PluginBootstrap] Installing plugin: ${plugin.display_name}`
1442
- );
1443
- await this.pluginService.installPlugin({
1444
- ...plugin,
1445
- is_core: plugin.name.startsWith("core-")
1446
- });
1447
- if (plugin.name.startsWith("core-")) {
1448
- console.log(
1449
- `[PluginBootstrap] Activating newly installed core plugin: ${plugin.display_name}`
1450
- );
1451
- await this.pluginService.activatePlugin(plugin.id);
1452
- }
1453
- }
1454
- } catch (error) {
1455
- console.error(
1456
- `[PluginBootstrap] Error ensuring plugin ${plugin.display_name}:`,
1457
- error
1458
- );
1459
- }
1460
- }
1461
- /**
1462
- * Update an existing plugin
1463
- */
1464
- async updatePlugin(plugin) {
1465
- const now = Math.floor(Date.now() / 1e3);
1466
- const stmt = this.db.prepare(`
1467
- UPDATE plugins
1468
- SET
1469
- version = ?,
1470
- description = ?,
1471
- permissions = ?,
1472
- settings = ?,
1473
- last_updated = ?
1474
- WHERE id = ?
1475
- `);
1476
- await stmt.bind(
1477
- plugin.version,
1478
- plugin.description,
1479
- JSON.stringify(plugin.permissions),
1480
- JSON.stringify(plugin.settings || {}),
1481
- now,
1482
- plugin.id
1483
- ).run();
1484
- }
1485
- /**
1486
- * Check if bootstrap is needed (first run detection)
1487
- */
1488
- async isBootstrapNeeded() {
1489
- try {
1490
- for (const corePlugin of this.CORE_PLUGINS.filter(
1491
- (p) => p.name.startsWith("core-")
1492
- )) {
1493
- const exists = await this.pluginService.getPlugin(corePlugin.id);
1494
- if (!exists) {
1495
- return true;
1496
- }
1497
- }
1498
- return false;
1499
- } catch (error) {
1500
- console.error(
1501
- "[PluginBootstrap] Error checking bootstrap status:",
1502
- error
1503
- );
1504
- return true;
1505
- }
1506
- }
1507
- };
1508
-
1509
- export { MigrationService, PluginBootstrapService, PluginService, cleanupRemovedCollections, fullCollectionSync, getAvailableCollectionNames, getManagedCollections, isCollectionManaged, loadCollectionConfig, loadCollectionConfigs, registerCollections, syncCollection, syncCollections, validateCollectionConfig };
1510
- //# sourceMappingURL=chunk-COBUPOMD.js.map
1511
- //# sourceMappingURL=chunk-COBUPOMD.js.map
744
+ exports.MigrationService = MigrationService;
745
+ //# sourceMappingURL=chunk-T7IYBGGO.cjs.map
746
+ //# sourceMappingURL=chunk-T7IYBGGO.cjs.map