@intranefr/superbackend 1.6.7 → 1.7.8

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 (119) hide show
  1. package/.beads/.br_history/issues.20260314_212352_900045509.jsonl +0 -0
  2. package/.beads/.br_history/issues.20260314_212352_900045509.jsonl.meta.json +1 -0
  3. package/.beads/.br_history/issues.20260314_212353_087140743.jsonl +1 -0
  4. package/.beads/.br_history/issues.20260314_212353_087140743.jsonl.meta.json +1 -0
  5. package/.beads/.br_history/issues.20260314_212353_285881504.jsonl +2 -0
  6. package/.beads/.br_history/issues.20260314_212353_285881504.jsonl.meta.json +1 -0
  7. package/.beads/.br_history/issues.20260314_212353_473915419.jsonl +3 -0
  8. package/.beads/.br_history/issues.20260314_212353_473915419.jsonl.meta.json +1 -0
  9. package/.beads/.br_history/issues.20260314_212353_659476307.jsonl +4 -0
  10. package/.beads/.br_history/issues.20260314_212353_659476307.jsonl.meta.json +1 -0
  11. package/.beads/.br_history/issues.20260314_212353_869998925.jsonl +5 -0
  12. package/.beads/.br_history/issues.20260314_212353_869998925.jsonl.meta.json +1 -0
  13. package/.beads/.br_history/issues.20260314_212354_054785029.jsonl +6 -0
  14. package/.beads/.br_history/issues.20260314_212354_054785029.jsonl.meta.json +1 -0
  15. package/.beads/.br_history/issues.20260314_213336_175893691.jsonl +7 -0
  16. package/.beads/.br_history/issues.20260314_213336_175893691.jsonl.meta.json +1 -0
  17. package/.beads/.br_history/issues.20260314_213336_338509797.jsonl +7 -0
  18. package/.beads/.br_history/issues.20260314_213336_338509797.jsonl.meta.json +1 -0
  19. package/.beads/.br_history/issues.20260314_213336_515443192.jsonl +7 -0
  20. package/.beads/.br_history/issues.20260314_213336_515443192.jsonl.meta.json +1 -0
  21. package/.beads/.br_history/issues.20260314_213336_676417592.jsonl +7 -0
  22. package/.beads/.br_history/issues.20260314_213336_676417592.jsonl.meta.json +1 -0
  23. package/.beads/.br_history/issues.20260314_213336_839182422.jsonl +7 -0
  24. package/.beads/.br_history/issues.20260314_213336_839182422.jsonl.meta.json +1 -0
  25. package/.beads/.br_history/issues.20260314_213337_004349113.jsonl +7 -0
  26. package/.beads/.br_history/issues.20260314_213337_004349113.jsonl.meta.json +1 -0
  27. package/.beads/.br_history/issues.20260314_213337_179824080.jsonl +7 -0
  28. package/.beads/.br_history/issues.20260314_213337_179824080.jsonl.meta.json +1 -0
  29. package/.beads/.br_history/issues.20260314_213701_705075332.jsonl +7 -0
  30. package/.beads/.br_history/issues.20260314_213701_705075332.jsonl.meta.json +1 -0
  31. package/.beads/.br_history/issues.20260314_213706_783128702.jsonl +8 -0
  32. package/.beads/.br_history/issues.20260314_213706_783128702.jsonl.meta.json +1 -0
  33. package/.beads/config.yaml +4 -0
  34. package/.beads/issues.jsonl +8 -0
  35. package/.beads/metadata.json +4 -0
  36. package/.env.example +8 -0
  37. package/autochangelog/.env.example +36 -0
  38. package/autochangelog/README.md +412 -0
  39. package/autochangelog/config/database.js +27 -0
  40. package/autochangelog/package.json +47 -0
  41. package/autochangelog/public/landing.html +581 -0
  42. package/autochangelog/server.js +104 -0
  43. package/autochangelog/src/app.js +181 -0
  44. package/autochangelog/src/config/database.js +26 -0
  45. package/autochangelog/src/controllers/auth.js +488 -0
  46. package/autochangelog/src/controllers/changelog.js +682 -0
  47. package/autochangelog/src/controllers/project.js +580 -0
  48. package/autochangelog/src/controllers/repository.js +780 -0
  49. package/autochangelog/src/middleware/auth.js +386 -0
  50. package/autochangelog/src/models/Changelog.js +443 -0
  51. package/autochangelog/src/models/Project.js +226 -0
  52. package/autochangelog/src/models/Repository.js +366 -0
  53. package/autochangelog/src/models/User.js +223 -0
  54. package/autochangelog/src/routes/auth.routes.js +32 -0
  55. package/autochangelog/src/routes/changelog.routes.js +42 -0
  56. package/autochangelog/src/routes/github-auth.routes.js +102 -0
  57. package/autochangelog/src/routes/project.routes.js +50 -0
  58. package/autochangelog/src/routes/repository.routes.js +54 -0
  59. package/autochangelog/src/services/changelog.js +722 -0
  60. package/autochangelog/src/services/github.js +243 -0
  61. package/autochangelog/utils/logger.js +77 -0
  62. package/autochangelog/views/404.ejs +18 -0
  63. package/autochangelog/views/dashboard.ejs +596 -0
  64. package/autochangelog/views/index.ejs +231 -0
  65. package/autochangelog/views/layouts/main.ejs +44 -0
  66. package/autochangelog/views/login.ejs +104 -0
  67. package/autochangelog/views/partials/footer.ejs +20 -0
  68. package/autochangelog/views/partials/navbar.ejs +51 -0
  69. package/autochangelog/views/register.ejs +109 -0
  70. package/autochangelog-cli/README.md +266 -0
  71. package/autochangelog-cli/bin/autochangelog +120 -0
  72. package/autochangelog-cli/package.json +46 -0
  73. package/autochangelog-cli/src/cli/commands/auth.js +291 -0
  74. package/autochangelog-cli/src/cli/commands/changelog.js +619 -0
  75. package/autochangelog-cli/src/cli/commands/project.js +427 -0
  76. package/autochangelog-cli/src/cli/commands/repo.js +557 -0
  77. package/autochangelog-cli/src/cli/commands/stats.js +706 -0
  78. package/autochangelog-cli/src/cli/utils/config.js +277 -0
  79. package/autochangelog-cli/src/cli/utils/errors.js +307 -0
  80. package/autochangelog-cli/src/cli/utils/logger.js +75 -0
  81. package/autochangelog-cli/src/cli/utils/output.js +357 -0
  82. package/package.json +9 -3
  83. package/plugins/supercli/README.md +108 -0
  84. package/plugins/supercli/plugin.json +123 -0
  85. package/server.js +1 -1
  86. package/src/cli/api.js +380 -0
  87. package/src/cli/direct/agent-utils.js +61 -0
  88. package/src/cli/direct/cli-utils.js +112 -0
  89. package/src/cli/direct/data-seeding.js +307 -0
  90. package/src/cli/direct/db-admin.js +84 -0
  91. package/src/cli/direct/db-advanced.js +372 -0
  92. package/src/cli/direct/db-utils.js +558 -0
  93. package/src/cli/direct/help.js +195 -0
  94. package/src/cli/direct/migration.js +107 -0
  95. package/src/cli/direct/rbac-advanced.js +132 -0
  96. package/src/cli/direct/resources-additional.js +400 -0
  97. package/src/cli/direct/resources-cms-advanced.js +173 -0
  98. package/src/cli/direct/resources-cms.js +247 -0
  99. package/src/cli/direct/resources-core.js +253 -0
  100. package/src/cli/direct/resources-execution.js +367 -0
  101. package/src/cli/direct/resources-health.js +152 -0
  102. package/src/cli/direct/resources-integrations.js +182 -0
  103. package/src/cli/direct/resources-logs.js +204 -0
  104. package/src/cli/direct/resources-org-rbac.js +187 -0
  105. package/src/cli/direct/resources-system.js +236 -0
  106. package/src/cli/direct.js +556 -0
  107. package/src/controllers/admin.controller.js +4 -0
  108. package/src/controllers/auth.controller.js +148 -1
  109. package/src/controllers/waitingList.controller.js +130 -1
  110. package/src/models/RbacRole.js +1 -1
  111. package/src/models/User.js +39 -5
  112. package/src/routes/auth.routes.js +6 -0
  113. package/src/routes/waitingList.routes.js +12 -2
  114. package/src/routes/waitingListAdmin.routes.js +3 -0
  115. package/src/services/email.service.js +1 -0
  116. package/src/services/github.service.js +255 -0
  117. package/src/services/rateLimiter.service.js +29 -1
  118. package/src/services/waitingListJson.service.js +32 -3
  119. package/views/admin-waiting-list.ejs +386 -3
@@ -0,0 +1,400 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Additional resources not covered in other modules
5
+ */
6
+
7
+ const mongoose = require('mongoose');
8
+
9
+ const agentMessages = {
10
+ async execute(options) {
11
+ const AgentMessage = mongoose.model('AgentMessage');
12
+ switch (options.command) {
13
+ case 'list': {
14
+ const limit = parseInt(options.value) || 50;
15
+ const messages = await AgentMessage.find().sort({ createdAt: -1 }).limit(limit).lean();
16
+ return { items: messages, count: messages.length };
17
+ }
18
+ case 'get': {
19
+ if (!options.id) throw new Error('Message ID is required');
20
+ const message = await AgentMessage.findById(options.id).lean();
21
+ if (!message) throw new Error('Message not found');
22
+ return message;
23
+ }
24
+ case 'delete': {
25
+ if (!options.id) throw new Error('Message ID is required');
26
+ const message = await AgentMessage.findByIdAndDelete(options.id);
27
+ if (!message) throw new Error('Message not found');
28
+ return { success: true, id: options.id };
29
+ }
30
+ case 'clear': {
31
+ const result = await AgentMessage.deleteMany({});
32
+ return { success: true, deletedCount: result.deletedCount };
33
+ }
34
+ default:
35
+ throw new Error(`Unknown agent-messages command: ${options.command}`);
36
+ }
37
+ },
38
+ };
39
+
40
+ const actionEvents = {
41
+ async execute(options) {
42
+ const ActionEvent = mongoose.model('ActionEvent');
43
+ switch (options.command) {
44
+ case 'list': {
45
+ const limit = parseInt(options.value) || 50;
46
+ const events = await ActionEvent.find().sort({ createdAt: -1 }).limit(limit).lean();
47
+ return { items: events, count: events.length };
48
+ }
49
+ case 'get': {
50
+ if (!options.id) throw new Error('Action event ID is required');
51
+ const event = await ActionEvent.findById(options.id).lean();
52
+ if (!event) throw new Error('Action event not found');
53
+ return event;
54
+ }
55
+ case 'clear': {
56
+ const result = await ActionEvent.deleteMany({});
57
+ return { success: true, deletedCount: result.deletedCount };
58
+ }
59
+ default:
60
+ throw new Error(`Unknown action-events command: ${options.command}`);
61
+ }
62
+ },
63
+ };
64
+
65
+ const experimentEvents = {
66
+ async execute(options) {
67
+ const ExperimentEvent = mongoose.model('ExperimentEvent');
68
+ switch (options.command) {
69
+ case 'list': {
70
+ const limit = parseInt(options.value) || 50;
71
+ const events = await ExperimentEvent.find().sort({ createdAt: -1 }).limit(limit).lean();
72
+ return { items: events, count: events.length };
73
+ }
74
+ case 'clear': {
75
+ const result = await ExperimentEvent.deleteMany({});
76
+ return { success: true, deletedCount: result.deletedCount };
77
+ }
78
+ default:
79
+ throw new Error(`Unknown experiment-events command: ${options.command}`);
80
+ }
81
+ },
82
+ };
83
+
84
+ const experimentMetricBuckets = {
85
+ async execute(options) {
86
+ const ExperimentMetricBucket = mongoose.model('ExperimentMetricBucket');
87
+ switch (options.command) {
88
+ case 'list': {
89
+ const limit = parseInt(options.value) || 50;
90
+ const buckets = await ExperimentMetricBucket.find().sort({ createdAt: -1 }).limit(limit).lean();
91
+ return { items: buckets, count: buckets.length };
92
+ }
93
+ case 'clear': {
94
+ const result = await ExperimentMetricBucket.deleteMany({});
95
+ return { success: true, deletedCount: result.deletedCount };
96
+ }
97
+ default:
98
+ throw new Error(`Unknown experiment-metric-buckets command: ${options.command}`);
99
+ }
100
+ },
101
+ };
102
+
103
+ const fileEntries = {
104
+ async execute(options) {
105
+ const FileEntry = mongoose.model('FileEntry');
106
+ switch (options.command) {
107
+ case 'list': {
108
+ const limit = parseInt(options.value) || 50;
109
+ const files = await FileEntry.find().sort({ createdAt: -1 }).limit(limit).lean();
110
+ return { items: files, count: files.length };
111
+ }
112
+ case 'get': {
113
+ if (!options.id) throw new Error('File entry ID is required');
114
+ const file = await FileEntry.findById(options.id).lean();
115
+ if (!file) throw new Error('File entry not found');
116
+ return file;
117
+ }
118
+ case 'delete': {
119
+ if (!options.id) throw new Error('File entry ID is required');
120
+ const file = await FileEntry.findByIdAndDelete(options.id);
121
+ if (!file) throw new Error('File entry not found');
122
+ return { success: true, id: options.id };
123
+ }
124
+ case 'clear': {
125
+ const result = await FileEntry.deleteMany({});
126
+ return { success: true, deletedCount: result.deletedCount };
127
+ }
128
+ default:
129
+ throw new Error(`Unknown file-entries command: ${options.command}`);
130
+ }
131
+ },
132
+ };
133
+
134
+ const i18nLocales = {
135
+ async execute(options) {
136
+ const I18nLocale = mongoose.model('I18nLocale');
137
+ switch (options.command) {
138
+ case 'list': {
139
+ const locales = await I18nLocale.find().lean();
140
+ return { items: locales, count: locales.length };
141
+ }
142
+ case 'get': {
143
+ if (!options.id) throw new Error('Locale ID is required');
144
+ const locale = await I18nLocale.findById(options.id).lean();
145
+ if (!locale) throw new Error('Locale not found');
146
+ return locale;
147
+ }
148
+ case 'create': {
149
+ if (!options.name) throw new Error('--name (locale code) is required');
150
+ const locale = await I18nLocale.create({
151
+ code: options.name,
152
+ name: options.description || options.name,
153
+ enabled: true,
154
+ });
155
+ return locale;
156
+ }
157
+ case 'delete': {
158
+ if (!options.id) throw new Error('Locale ID is required');
159
+ const locale = await I18nLocale.findByIdAndDelete(options.id);
160
+ if (!locale) throw new Error('Locale not found');
161
+ return { success: true, id: options.id };
162
+ }
163
+ default:
164
+ throw new Error(`Unknown i18n-locales command: ${options.command}`);
165
+ }
166
+ },
167
+ };
168
+
169
+ const proxyEntries = {
170
+ async execute(options) {
171
+ const ProxyEntry = mongoose.model('ProxyEntry');
172
+ switch (options.command) {
173
+ case 'list': {
174
+ const entries = await ProxyEntry.find().lean();
175
+ return { items: entries, count: entries.length };
176
+ }
177
+ case 'get': {
178
+ if (!options.id) throw new Error('Proxy entry ID is required');
179
+ const entry = await ProxyEntry.findById(options.id).lean();
180
+ if (!entry) throw new Error('Proxy entry not found');
181
+ return entry;
182
+ }
183
+ case 'delete': {
184
+ if (!options.id) throw new Error('Proxy entry ID is required');
185
+ const entry = await ProxyEntry.findByIdAndDelete(options.id);
186
+ if (!entry) throw new Error('Proxy entry not found');
187
+ return { success: true, id: options.id };
188
+ }
189
+ default:
190
+ throw new Error(`Unknown proxy-entries command: ${options.command}`);
191
+ }
192
+ },
193
+ };
194
+
195
+ const rateLimitMetricBuckets = {
196
+ async execute(options) {
197
+ const RateLimitMetricBucket = mongoose.model('RateLimitMetricBucket');
198
+ switch (options.command) {
199
+ case 'list': {
200
+ const limit = parseInt(options.value) || 50;
201
+ const buckets = await RateLimitMetricBucket.find().sort({ createdAt: -1 }).limit(limit).lean();
202
+ return { items: buckets, count: buckets.length };
203
+ }
204
+ case 'clear': {
205
+ const result = await RateLimitMetricBucket.deleteMany({});
206
+ return { success: true, deletedCount: result.deletedCount };
207
+ }
208
+ default:
209
+ throw new Error(`Unknown rate-limit-metric-buckets command: ${options.command}`);
210
+ }
211
+ },
212
+ };
213
+
214
+ const rbacGrants = {
215
+ async execute(options) {
216
+ const RbacGrant = mongoose.model('RbacGrant');
217
+ switch (options.command) {
218
+ case 'list': {
219
+ const grants = await RbacGrant.find().lean();
220
+ return { items: grants, count: grants.length };
221
+ }
222
+ case 'clear': {
223
+ const result = await RbacGrant.deleteMany({});
224
+ return { success: true, deletedCount: result.deletedCount };
225
+ }
226
+ default:
227
+ throw new Error(`Unknown rbac-grants command: ${options.command}`);
228
+ }
229
+ },
230
+ };
231
+
232
+ const rbacGroupRoles = {
233
+ async execute(options) {
234
+ const RbacGroupRole = mongoose.model('RbacGroupRole');
235
+ switch (options.command) {
236
+ case 'list': {
237
+ const groupRoles = await RbacGroupRole.find().populate('groupId roleId').lean();
238
+ return { items: groupRoles, count: groupRoles.length };
239
+ }
240
+ case 'delete': {
241
+ if (!options.id) throw new Error('Group role ID is required');
242
+ const groupRole = await RbacGroupRole.findByIdAndDelete(options.id);
243
+ if (!groupRole) throw new Error('Group role not found');
244
+ return { success: true, id: options.id };
245
+ }
246
+ default:
247
+ throw new Error(`Unknown rbac-group-roles command: ${options.command}`);
248
+ }
249
+ },
250
+ };
251
+
252
+ const rbacUserRoles = {
253
+ async execute(options) {
254
+ const RbacUserRole = mongoose.model('RbacUserRole');
255
+ switch (options.command) {
256
+ case 'list': {
257
+ const userRoles = await RbacUserRole.find().populate('userId roleId').lean();
258
+ return { items: userRoles, count: userRoles.length };
259
+ }
260
+ case 'delete': {
261
+ if (!options.id) throw new Error('User role ID is required');
262
+ const userRole = await RbacUserRole.findByIdAndDelete(options.id);
263
+ if (!userRole) throw new Error('User role not found');
264
+ return { success: true, id: options.id };
265
+ }
266
+ default:
267
+ throw new Error(`Unknown rbac-user-roles command: ${options.command}`);
268
+ }
269
+ },
270
+ };
271
+
272
+ const uiComponentProjects = {
273
+ async execute(options) {
274
+ const UiComponentProject = mongoose.model('UiComponentProject');
275
+ switch (options.command) {
276
+ case 'list': {
277
+ const projects = await UiComponentProject.find().lean();
278
+ return { items: projects, count: projects.length };
279
+ }
280
+ case 'get': {
281
+ if (!options.id) throw new Error('UI component project ID is required');
282
+ const project = await UiComponentProject.findById(options.id).lean();
283
+ if (!project) throw new Error('UI component project not found');
284
+ return project;
285
+ }
286
+ case 'delete': {
287
+ if (!options.id) throw new Error('UI component project ID is required');
288
+ const project = await UiComponentProject.findByIdAndDelete(options.id);
289
+ if (!project) throw new Error('UI component project not found');
290
+ return { success: true, id: options.id };
291
+ }
292
+ default:
293
+ throw new Error(`Unknown ui-component-projects command: ${options.command}`);
294
+ }
295
+ },
296
+ };
297
+
298
+ const uiComponentProjectComponents = {
299
+ async execute(options) {
300
+ const UiComponentProjectComponent = mongoose.model('UiComponentProjectComponent');
301
+ switch (options.command) {
302
+ case 'list': {
303
+ const components = await UiComponentProjectComponent.find().lean();
304
+ return { items: components, count: components.length };
305
+ }
306
+ case 'delete': {
307
+ if (!options.id) throw new Error('Component ID is required');
308
+ const component = await UiComponentProjectComponent.findByIdAndDelete(options.id);
309
+ if (!component) throw new Error('Component not found');
310
+ return { success: true, id: options.id };
311
+ }
312
+ default:
313
+ throw new Error(`Unknown ui-component-project-components command: ${options.command}`);
314
+ }
315
+ },
316
+ };
317
+
318
+ const virtualEjsFileVersions = {
319
+ async execute(options) {
320
+ const VirtualEjsFileVersion = mongoose.model('VirtualEjsFileVersion');
321
+ switch (options.command) {
322
+ case 'list': {
323
+ const limit = parseInt(options.value) || 50;
324
+ const versions = await VirtualEjsFileVersion.find().sort({ createdAt: -1 }).limit(limit).lean();
325
+ return { items: versions, count: versions.length };
326
+ }
327
+ case 'clear': {
328
+ const result = await VirtualEjsFileVersion.deleteMany({});
329
+ return { success: true, deletedCount: result.deletedCount };
330
+ }
331
+ default:
332
+ throw new Error(`Unknown virtual-ejs-file-versions command: ${options.command}`);
333
+ }
334
+ },
335
+ };
336
+
337
+ const virtualEjsGroupChanges = {
338
+ async execute(options) {
339
+ const VirtualEjsGroupChange = mongoose.model('VirtualEjsGroupChange');
340
+ switch (options.command) {
341
+ case 'list': {
342
+ const changes = await VirtualEjsGroupChange.find().lean();
343
+ return { items: changes, count: changes.length };
344
+ }
345
+ case 'clear': {
346
+ const result = await VirtualEjsGroupChange.deleteMany({});
347
+ return { success: true, deletedCount: result.deletedCount };
348
+ }
349
+ default:
350
+ throw new Error(`Unknown virtual-ejs-group-changes command: ${options.command}`);
351
+ }
352
+ },
353
+ };
354
+
355
+ const healthCheckRuns = {
356
+ async execute(options) {
357
+ const HealthCheckRun = mongoose.model('HealthCheckRun');
358
+ switch (options.command) {
359
+ case 'list': {
360
+ const limit = parseInt(options.value) || 50;
361
+ const runs = await HealthCheckRun.find().sort({ createdAt: -1 }).limit(limit).lean();
362
+ return { items: runs, count: runs.length };
363
+ }
364
+ case 'clear': {
365
+ const result = await HealthCheckRun.deleteMany({});
366
+ return { success: true, deletedCount: result.deletedCount };
367
+ }
368
+ default:
369
+ throw new Error(`Unknown health-check-runs command: ${options.command}`);
370
+ }
371
+ },
372
+ };
373
+
374
+ const consoleEntries = {
375
+ async execute(options) {
376
+ const ConsoleEntry = mongoose.model('ConsoleEntry');
377
+ switch (options.command) {
378
+ case 'list': {
379
+ const limit = parseInt(options.value) || 50;
380
+ const entries = await ConsoleEntry.find().sort({ createdAt: -1 }).limit(limit).lean();
381
+ return { items: entries, count: entries.length };
382
+ }
383
+ case 'clear': {
384
+ const result = await ConsoleEntry.deleteMany({});
385
+ return { success: true, deletedCount: result.deletedCount };
386
+ }
387
+ default:
388
+ throw new Error(`Unknown console-entries command: ${options.command}`);
389
+ }
390
+ },
391
+ };
392
+
393
+ module.exports = {
394
+ agentMessages, actionEvents, experimentEvents, experimentMetricBuckets,
395
+ fileEntries, i18nLocales, proxyEntries, rateLimitMetricBuckets,
396
+ rbacGrants, rbacGroupRoles, rbacUserRoles,
397
+ uiComponentProjects, uiComponentProjectComponents,
398
+ virtualEjsFileVersions, virtualEjsGroupChanges,
399
+ healthCheckRuns, consoleEntries,
400
+ };
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CMS Advanced: page-collections, block-definitions, context-blocks, ui-components, headless-*
5
+ */
6
+
7
+ const mongoose = require('mongoose');
8
+
9
+ const pageCollections = {
10
+ async execute(options) {
11
+ const PageCollection = mongoose.model('PageCollection');
12
+ switch (options.command) {
13
+ case 'list': {
14
+ const collections = await PageCollection.find().lean();
15
+ return { items: collections, count: collections.length };
16
+ }
17
+ case 'get': {
18
+ if (!options.id) throw new Error('Page collection ID is required');
19
+ const collection = await PageCollection.findById(options.id).lean();
20
+ if (!collection) throw new Error('Page collection not found');
21
+ return collection;
22
+ }
23
+ case 'create': {
24
+ if (!options.name) throw new Error('--name is required');
25
+ const collection = await PageCollection.create({ name: options.name, description: options.description || '' });
26
+ return collection;
27
+ }
28
+ case 'delete': {
29
+ if (!options.id) throw new Error('Page collection ID is required');
30
+ const collection = await PageCollection.findByIdAndDelete(options.id);
31
+ if (!collection) throw new Error('Page collection not found');
32
+ return { success: true, id: options.id };
33
+ }
34
+ default:
35
+ throw new Error(`Unknown page-collections command: ${options.command}`);
36
+ }
37
+ },
38
+ };
39
+
40
+ const blockDefinitions = {
41
+ async execute(options) {
42
+ const BlockDefinition = mongoose.model('BlockDefinition');
43
+ switch (options.command) {
44
+ case 'list': {
45
+ const blocks = await BlockDefinition.find().lean();
46
+ return { items: blocks, count: blocks.length };
47
+ }
48
+ case 'get': {
49
+ if (!options.id) throw new Error('Block definition ID is required');
50
+ const block = await BlockDefinition.findById(options.id).lean();
51
+ if (!block) throw new Error('Block definition not found');
52
+ return block;
53
+ }
54
+ case 'delete': {
55
+ if (!options.id) throw new Error('Block definition ID is required');
56
+ const block = await BlockDefinition.findByIdAndDelete(options.id);
57
+ if (!block) throw new Error('Block definition not found');
58
+ return { success: true, id: options.id };
59
+ }
60
+ default:
61
+ throw new Error(`Unknown block-definitions command: ${options.command}`);
62
+ }
63
+ },
64
+ };
65
+
66
+ const contextBlocks = {
67
+ async execute(options) {
68
+ const ContextBlockDefinition = mongoose.model('ContextBlockDefinition');
69
+ switch (options.command) {
70
+ case 'list': {
71
+ const blocks = await ContextBlockDefinition.find().lean();
72
+ return { items: blocks, count: blocks.length };
73
+ }
74
+ case 'get': {
75
+ if (!options.id) throw new Error('Context block ID is required');
76
+ const block = await ContextBlockDefinition.findById(options.id).lean();
77
+ if (!block) throw new Error('Context block not found');
78
+ return block;
79
+ }
80
+ case 'delete': {
81
+ if (!options.id) throw new Error('Context block ID is required');
82
+ const block = await ContextBlockDefinition.findByIdAndDelete(options.id);
83
+ if (!block) throw new Error('Context block not found');
84
+ return { success: true, id: options.id };
85
+ }
86
+ default:
87
+ throw new Error(`Unknown context-blocks command: ${options.command}`);
88
+ }
89
+ },
90
+ };
91
+
92
+ const uiComponents = {
93
+ async execute(options) {
94
+ const UiComponent = mongoose.model('UiComponent');
95
+ switch (options.command) {
96
+ case 'list': {
97
+ const components = await UiComponent.find().lean();
98
+ return { items: components, count: components.length };
99
+ }
100
+ case 'get': {
101
+ if (!options.id) throw new Error('UI component ID is required');
102
+ const component = await UiComponent.findById(options.id).lean();
103
+ if (!component) throw new Error('UI component not found');
104
+ return component;
105
+ }
106
+ case 'delete': {
107
+ if (!options.id) throw new Error('UI component ID is required');
108
+ const component = await UiComponent.findByIdAndDelete(options.id);
109
+ if (!component) throw new Error('UI component not found');
110
+ return { success: true, id: options.id };
111
+ }
112
+ default:
113
+ throw new Error(`Unknown ui-components command: ${options.command}`);
114
+ }
115
+ },
116
+ };
117
+
118
+ const headlessModels = {
119
+ async execute(options) {
120
+ const HeadlessModelDefinition = mongoose.model('HeadlessModelDefinition');
121
+ switch (options.command) {
122
+ case 'list': {
123
+ const models = await HeadlessModelDefinition.find().lean();
124
+ return { items: models, count: models.length };
125
+ }
126
+ case 'get': {
127
+ if (!options.id) throw new Error('Headless model ID is required');
128
+ const model = await HeadlessModelDefinition.findById(options.id).lean();
129
+ if (!model) throw new Error('Headless model not found');
130
+ return model;
131
+ }
132
+ case 'create': {
133
+ if (!options.name) throw new Error('--name is required');
134
+ const model = await HeadlessModelDefinition.create({ name: options.name, description: options.description || '' });
135
+ return model;
136
+ }
137
+ case 'delete': {
138
+ if (!options.id) throw new Error('Headless model ID is required');
139
+ const model = await HeadlessModelDefinition.findByIdAndDelete(options.id);
140
+ if (!model) throw new Error('Headless model not found');
141
+ return { success: true, id: options.id };
142
+ }
143
+ default:
144
+ throw new Error(`Unknown headless-models command: ${options.command}`);
145
+ }
146
+ },
147
+ };
148
+
149
+ const headlessTokens = {
150
+ async execute(options) {
151
+ const HeadlessApiToken = mongoose.model('HeadlessApiToken');
152
+ switch (options.command) {
153
+ case 'list': {
154
+ const tokens = await HeadlessApiToken.find().lean();
155
+ return { items: tokens, count: tokens.length };
156
+ }
157
+ case 'delete': {
158
+ if (!options.id) throw new Error('Token ID is required');
159
+ const token = await HeadlessApiToken.findByIdAndDelete(options.id);
160
+ if (!token) throw new Error('Token not found');
161
+ return { success: true, id: options.id };
162
+ }
163
+ case 'clear': {
164
+ const result = await HeadlessApiToken.deleteMany({});
165
+ return { success: true, deletedCount: result.deletedCount };
166
+ }
167
+ default:
168
+ throw new Error(`Unknown headless-tokens command: ${options.command}`);
169
+ }
170
+ },
171
+ };
172
+
173
+ module.exports = { pageCollections, blockDefinitions, contextBlocks, uiComponents, headlessModels, headlessTokens };