@intranefr/superbackend 1.7.7 → 1.7.9

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 +8 -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,556 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Direct CLI - Main entry point
5
+ * Connects directly to MongoDB and executes operations using backend models
6
+ */
7
+
8
+ require("dotenv").config(
9
+ process.env.MODE ? { path: `.env.${process.env.MODE}` } : {},
10
+ );
11
+
12
+ const { ScriptBase } = require("../helpers/scriptBase");
13
+ const { parseArgs, formatOutput, colorize } = require("./direct/cli-utils");
14
+ const { printHelp } = require("./direct/help");
15
+
16
+ // Import all resource handlers
17
+ const {
18
+ agents,
19
+ settings,
20
+ users,
21
+ jsonConfigs,
22
+ } = require("./direct/resources-core");
23
+ const {
24
+ blogPosts,
25
+ pages,
26
+ assets,
27
+ forms,
28
+ i18n,
29
+ markdowns,
30
+ } = require("./direct/resources-cms");
31
+ const {
32
+ orgs,
33
+ rbacRoles,
34
+ rbacGroups,
35
+ invites,
36
+ orgMembers,
37
+ } = require("./direct/resources-org-rbac");
38
+ const {
39
+ crons,
40
+ errors,
41
+ scripts,
42
+ workflows,
43
+ healthChecks,
44
+ } = require("./direct/resources-system");
45
+ const {
46
+ notifications,
47
+ cache,
48
+ auditLogs,
49
+ consoleLogs,
50
+ activityLogs,
51
+ emailLogs,
52
+ waitingList,
53
+ } = require("./direct/resources-logs");
54
+ const {
55
+ telegram,
56
+ webhooks,
57
+ stripeItems,
58
+ stripeEvents,
59
+ externalDbs,
60
+ } = require("./direct/resources-integrations");
61
+ const {
62
+ demos,
63
+ experiments,
64
+ experimentAssignments,
65
+ rateLimits,
66
+ demoProjects,
67
+ demoSteps,
68
+ blogAutomationLocks,
69
+ blogAutomationRuns,
70
+ cronExecutions,
71
+ workflowExecutions,
72
+ scriptRuns,
73
+ } = require("./direct/resources-execution");
74
+ const {
75
+ pageCollections,
76
+ blockDefinitions,
77
+ contextBlocks,
78
+ uiComponents,
79
+ headlessModels,
80
+ headlessTokens,
81
+ } = require("./direct/resources-cms-advanced");
82
+ const {
83
+ healthIncidents,
84
+ healthAttempts,
85
+ errorAggregates,
86
+ metricBuckets,
87
+ virtualEjsFiles,
88
+ virtualEjsGroups,
89
+ } = require("./direct/resources-health");
90
+ const {
91
+ dbStats,
92
+ dbIndexes,
93
+ dbCleanup,
94
+ batchDelete,
95
+ batchUpdate,
96
+ collectionCount,
97
+ collectionSchema,
98
+ exportCollection,
99
+ findDuplicates,
100
+ removeDuplicates,
101
+ validateRefs,
102
+ repairRefs,
103
+ addIndex,
104
+ dropIndex,
105
+ reindex,
106
+ compact,
107
+ validateCollection,
108
+ renameCollection,
109
+ listCollections,
110
+ createCollection,
111
+ dropCollection,
112
+ } = require("./direct/db-utils");
113
+ const {
114
+ dbInfo,
115
+ dbUsers,
116
+ slowQueries,
117
+ enableProfiling,
118
+ disableProfiling,
119
+ } = require("./direct/db-admin");
120
+ const {
121
+ userPermissions,
122
+ grantRole,
123
+ revokeRole,
124
+ groupMembers,
125
+ addToGroup,
126
+ removeFromGroup,
127
+ } = require("./direct/rbac-advanced");
128
+ const {
129
+ agentStats,
130
+ agentSessions,
131
+ clearAgentSessions,
132
+ } = require("./direct/agent-utils");
133
+ const {
134
+ migrationStatus,
135
+ addTimestamps,
136
+ dataDigest,
137
+ } = require("./direct/migration");
138
+ const {
139
+ agentMessages,
140
+ actionEvents,
141
+ experimentEvents,
142
+ experimentMetricBuckets,
143
+ fileEntries,
144
+ i18nLocales,
145
+ proxyEntries,
146
+ rateLimitMetricBuckets,
147
+ rbacGrants,
148
+ rbacGroupRoles,
149
+ rbacUserRoles,
150
+ uiComponentProjects,
151
+ uiComponentProjectComponents,
152
+ virtualEjsFileVersions,
153
+ virtualEjsGroupChanges,
154
+ healthCheckRuns,
155
+ consoleEntries,
156
+ } = require("./direct/resources-additional");
157
+ const {
158
+ collectionStats,
159
+ topCollections,
160
+ emptyCollections,
161
+ findLargeDocuments,
162
+ analyzeFieldTypes,
163
+ findNullFields,
164
+ fillNullFields,
165
+ removeField,
166
+ renameField,
167
+ convertFieldTypes,
168
+ sampleDocuments,
169
+ distinctValues,
170
+ fieldCardinality,
171
+ } = require("./direct/db-advanced");
172
+ const {
173
+ seedUsers,
174
+ seedSettings,
175
+ seedAgents,
176
+ clearAllData,
177
+ importJson,
178
+ exportJson,
179
+ exportAllCollections,
180
+ countByField,
181
+ findOrphanedDocuments,
182
+ deleteOrphanedDocuments,
183
+ generateTestData,
184
+ } = require("./direct/data-seeding");
185
+
186
+ // Build handlers registry
187
+ const handlers = {
188
+ agents,
189
+ settings,
190
+ users,
191
+ "json-configs": jsonConfigs,
192
+ "blog-posts": blogPosts,
193
+ pages,
194
+ assets,
195
+ forms,
196
+ i18n,
197
+ markdowns,
198
+ orgs,
199
+ "rbac-roles": rbacRoles,
200
+ "rbac-groups": rbacGroups,
201
+ invites,
202
+ "org-members": orgMembers,
203
+ crons,
204
+ errors,
205
+ scripts,
206
+ workflows,
207
+ "health-checks": healthChecks,
208
+ notifications,
209
+ cache,
210
+ "audit-logs": auditLogs,
211
+ "console-logs": consoleLogs,
212
+ "activity-logs": activityLogs,
213
+ "email-logs": emailLogs,
214
+ "waiting-list": waitingList,
215
+ telegram,
216
+ webhooks,
217
+ "stripe-items": stripeItems,
218
+ "stripe-events": stripeEvents,
219
+ "external-dbs": externalDbs,
220
+ demos,
221
+ experiments,
222
+ "experiment-assignments": experimentAssignments,
223
+ "rate-limits": rateLimits,
224
+ "demo-projects": demoProjects,
225
+ "demo-steps": demoSteps,
226
+ "blog-automation-locks": blogAutomationLocks,
227
+ "blog-automation-runs": blogAutomationRuns,
228
+ "cron-executions": cronExecutions,
229
+ "workflow-executions": workflowExecutions,
230
+ "script-runs": scriptRuns,
231
+ "page-collections": pageCollections,
232
+ "block-definitions": blockDefinitions,
233
+ "context-blocks": contextBlocks,
234
+ "ui-components": uiComponents,
235
+ "headless-models": headlessModels,
236
+ "headless-tokens": headlessTokens,
237
+ "health-incidents": healthIncidents,
238
+ "health-attempts": healthAttempts,
239
+ "error-aggregates": errorAggregates,
240
+ "metric-buckets": metricBuckets,
241
+ "virtual-ejs-files": virtualEjsFiles,
242
+ "virtual-ejs-groups": virtualEjsGroups,
243
+ "db-stats": dbStats,
244
+ "db-indexes": dbIndexes,
245
+ "db-cleanup": dbCleanup,
246
+ "batch-delete": batchDelete,
247
+ "batch-update": batchUpdate,
248
+ "collection-count": collectionCount,
249
+ "collection-schema": collectionSchema,
250
+ "export-collection": exportCollection,
251
+ "find-duplicates": findDuplicates,
252
+ "remove-duplicates": removeDuplicates,
253
+ "validate-refs": validateRefs,
254
+ "repair-refs": repairRefs,
255
+ "add-index": addIndex,
256
+ "drop-index": dropIndex,
257
+ reindex,
258
+ compact,
259
+ "validate-collection": validateCollection,
260
+ "rename-collection": renameCollection,
261
+ "list-collections": listCollections,
262
+ "create-collection": createCollection,
263
+ "drop-collection": dropCollection,
264
+ "db-info": dbInfo,
265
+ "db-users": dbUsers,
266
+ "slow-queries": slowQueries,
267
+ "enable-profiling": enableProfiling,
268
+ "disable-profiling": disableProfiling,
269
+ "user-permissions": userPermissions,
270
+ "grant-role": grantRole,
271
+ "revoke-role": revokeRole,
272
+ "group-members": groupMembers,
273
+ "add-to-group": addToGroup,
274
+ "remove-from-group": removeFromGroup,
275
+ "agent-stats": agentStats,
276
+ "agent-sessions": agentSessions,
277
+ "clear-agent-sessions": clearAgentSessions,
278
+ "migration-status": migrationStatus,
279
+ "add-timestamps": addTimestamps,
280
+ "data-digest": dataDigest,
281
+ // Additional resources
282
+ "agent-messages": agentMessages,
283
+ "action-events": actionEvents,
284
+ "experiment-events": experimentEvents,
285
+ "experiment-metric-buckets": experimentMetricBuckets,
286
+ "file-entries": fileEntries,
287
+ "i18n-locales": i18nLocales,
288
+ "proxy-entries": proxyEntries,
289
+ "rate-limit-metric-buckets": rateLimitMetricBuckets,
290
+ "rbac-grants": rbacGrants,
291
+ "rbac-group-roles": rbacGroupRoles,
292
+ "rbac-user-roles": rbacUserRoles,
293
+ "ui-component-projects": uiComponentProjects,
294
+ "ui-component-project-components": uiComponentProjectComponents,
295
+ "virtual-ejs-file-versions": virtualEjsFileVersions,
296
+ "virtual-ejs-group-changes": virtualEjsGroupChanges,
297
+ "health-check-runs": healthCheckRuns,
298
+ "console-entries": consoleEntries,
299
+ // DB Advanced
300
+ "collection-stats": collectionStats,
301
+ "top-collections": topCollections,
302
+ "empty-collections": emptyCollections,
303
+ "find-large-documents": findLargeDocuments,
304
+ "analyze-field-types": analyzeFieldTypes,
305
+ "find-null-fields": findNullFields,
306
+ "fill-null-fields": fillNullFields,
307
+ "remove-field": removeField,
308
+ "rename-field": renameField,
309
+ "convert-field-types": convertFieldTypes,
310
+ "sample-documents": sampleDocuments,
311
+ "distinct-values": distinctValues,
312
+ "field-cardinality": fieldCardinality,
313
+ // Data seeding
314
+ "seed-users": seedUsers,
315
+ "seed-settings": seedSettings,
316
+ "seed-agents": seedAgents,
317
+ "clear-all-data": clearAllData,
318
+ "import-json": importJson,
319
+ "export-json": exportJson,
320
+ "export-all-collections": exportAllCollections,
321
+ "count-by-field": countByField,
322
+ "find-orphaned-documents": findOrphanedDocuments,
323
+ "delete-orphaned-documents": deleteOrphanedDocuments,
324
+ "generate-test-data": generateTestData,
325
+ };
326
+
327
+ class DirectCLI extends ScriptBase {
328
+ constructor(options) {
329
+ super({ name: "DirectCLI", autoDisconnect: true, timeout: 30000 }); // 30s timeout for CLI
330
+ this.cliOptions = options;
331
+ }
332
+
333
+ async run() {
334
+ // Faster connection handling for CLI
335
+ const mongoose = require("mongoose");
336
+ const mongooseHelper = require("../helpers/mongooseHelper").mongooseHelper;
337
+
338
+ try {
339
+ console.log("[DirectCLI] Connecting to MongoDB...");
340
+
341
+ // Load all models to register schemas (with error handling)
342
+ const modelFiles = [
343
+ "User",
344
+ "Agent",
345
+ "AgentMessage",
346
+ "GlobalSetting",
347
+ "JsonConfig",
348
+ "BlogPost",
349
+ "Page",
350
+ "Asset",
351
+ "FormSubmission",
352
+ "I18nEntry",
353
+ "I18nLocale",
354
+ "Markdown",
355
+ "Organization",
356
+ "OrganizationMember",
357
+ "CronJob",
358
+ "ErrorAggregate",
359
+ "ScriptDefinition",
360
+ "Workflow",
361
+ "HealthCheck",
362
+ "Notification",
363
+ "CacheEntry",
364
+ "AuditEvent",
365
+ "ConsoleLog",
366
+ "ActivityLog",
367
+ "EmailLog",
368
+ "WaitingList",
369
+ "TelegramBot",
370
+ "Webhook",
371
+ "StripeCatalogItem",
372
+ "StripeWebhookEvent",
373
+ "ExternalDbConnection",
374
+ "Experiment",
375
+ "ExperimentAssignment",
376
+ "ExperimentEvent",
377
+ "ExperimentMetricBucket",
378
+ "SuperDemo",
379
+ "SuperDemoProject",
380
+ "SuperDemoStep",
381
+ "BlogAutomationLock",
382
+ "BlogAutomationRun",
383
+ "CronExecution",
384
+ "WorkflowExecution",
385
+ "ScriptRun",
386
+ "PageCollection",
387
+ "BlockDefinition",
388
+ "ContextBlockDefinition",
389
+ "UiComponent",
390
+ "HeadlessModelDefinition",
391
+ "HeadlessApiToken",
392
+ "HealthIncident",
393
+ "HealthAutoHealAttempt",
394
+ "RateLimitMetricBucket",
395
+ "VirtualEjsFile",
396
+ "VirtualEjsFileVersion",
397
+ "VirtualEjsGroupChange",
398
+ "ActionEvent",
399
+ "FileEntry",
400
+ "ProxyEntry",
401
+ "RateLimitCounter",
402
+ "RbacGrant",
403
+ "RbacGroup",
404
+ "RbacGroupMember",
405
+ "RbacGroupRole",
406
+ "RbacRole",
407
+ "RbacUserRole",
408
+ "Invite",
409
+ "UiComponentProject",
410
+ "UiComponentProjectComponent",
411
+ "ConsoleEntry",
412
+ "HealthCheckRun",
413
+ ];
414
+
415
+ for (const model of modelFiles) {
416
+ try {
417
+ require(`../models/${model}`);
418
+ } catch (e) {
419
+ // Skip missing models
420
+ }
421
+ }
422
+
423
+ // Override connection options for CLI (faster timeouts)
424
+ mongooseHelper.connectionOptions = {
425
+ serverSelectionTimeoutMS: 5000,
426
+ maxPoolSize: 2,
427
+ bufferCommands: false,
428
+ retryWrites: true,
429
+ retryReads: true,
430
+ socketTimeoutMS: 30000,
431
+ connectTimeoutMS: 10000,
432
+ };
433
+
434
+ // Connect with timeout
435
+ const connectPromise = mongooseHelper.connect();
436
+ const timeoutPromise = new Promise((_, reject) => {
437
+ setTimeout(
438
+ () => reject(new Error("MongoDB connection timeout (10s)")),
439
+ 10000,
440
+ );
441
+ });
442
+
443
+ await Promise.race([connectPromise, timeoutPromise]);
444
+
445
+ console.log("[DirectCLI] ✅ Connected");
446
+
447
+ const context = {
448
+ mongoose,
449
+ models: mongoose.models,
450
+ connection: mongoose.connection,
451
+ db: mongoose.connection.db,
452
+ script: { name: "DirectCLI", startTime: Date.now() },
453
+ };
454
+
455
+ console.log(
456
+ `[DirectCLI] Executing ${options.resource} ${options.command || ""}...`,
457
+ );
458
+ const result = await this.execute(context);
459
+
460
+ // Quick disconnect
461
+ await mongoose.disconnect();
462
+ console.log("[DirectCLI] ✅ Disconnected");
463
+
464
+ return result;
465
+ } catch (error) {
466
+ console.error(colorize("red", "\n✗ Error:"), error.message);
467
+ console.error(
468
+ colorize("gray", "Hint: Check MONGODB_URI and MongoDB connectivity"),
469
+ );
470
+
471
+ try {
472
+ await mongoose.disconnect();
473
+ } catch (e) {
474
+ // Ignore disconnect errors
475
+ }
476
+
477
+ process.exit(1);
478
+ }
479
+ }
480
+
481
+ async execute(context) {
482
+ const options = this.cliOptions;
483
+ const { quiet, output } = options;
484
+
485
+ if (!handlers[options.resource]) {
486
+ const available = Object.keys(handlers).join(", ");
487
+ throw new Error(
488
+ `Unknown resource: ${options.resource}\nAvailable: ${available}`,
489
+ );
490
+ }
491
+
492
+ const result = await handlers[options.resource].execute(options, context);
493
+
494
+ if (quiet) {
495
+ console.log(formatOutput(result, output));
496
+ } else {
497
+ console.log(
498
+ colorize("green", `\n✓ ${options.resource} ${options.command}`),
499
+ );
500
+ console.log();
501
+ console.log(formatOutput(result, output));
502
+ }
503
+
504
+ return result;
505
+ }
506
+ }
507
+
508
+ // Main execution
509
+ const args = process.argv.slice(2);
510
+ const options = parseArgs(args);
511
+
512
+ if (options.help || (!options.resource && !options.command)) {
513
+ printHelp();
514
+ process.exit(0);
515
+ }
516
+
517
+ if (!options.resource) {
518
+ console.error(colorize("red", "Error: Resource is required"));
519
+ printHelp();
520
+ process.exit(1);
521
+ }
522
+
523
+ // Resources that don't require a command (they have a single operation)
524
+ const noCommandResources = [
525
+ "db-stats",
526
+ "db-info",
527
+ "db-users",
528
+ "data-digest",
529
+ "migration-status",
530
+ "empty-collections",
531
+ "top-collections",
532
+ "collection-count",
533
+ "slow-queries",
534
+ ];
535
+
536
+ if (!options.command && !noCommandResources.includes(options.resource)) {
537
+ console.error(colorize("red", "Error: Command is required"));
538
+ printHelp();
539
+ process.exit(1);
540
+ }
541
+
542
+ // Auto-set command for no-command resources
543
+ if (!options.command && noCommandResources.includes(options.resource)) {
544
+ options.command = "execute";
545
+ }
546
+
547
+ const cli = new DirectCLI(options);
548
+ cli.run().catch((err) => {
549
+ if (!options.quiet) {
550
+ console.error(colorize("red", "\n✗ Error:"), err.message);
551
+ if (options.verbose) console.error(err);
552
+ } else {
553
+ console.error(colorize("red", `Error: ${err.message}`));
554
+ }
555
+ process.exit(1);
556
+ });
@@ -58,6 +58,10 @@ const registerUser = asyncHandler(async (req, res) => {
58
58
  return res.status(400).json({ error: 'Password must be at least 6 characters' });
59
59
  }
60
60
 
61
+ if (role !== 'user' && role !== 'admin') {
62
+ return res.status(400).json({ error: 'Role must be either "user" or "admin"' });
63
+ }
64
+
61
65
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
62
66
  if (!emailRegex.test(email)) {
63
67
  return res.status(400).json({ error: 'Invalid email format' });