@nodestackapp/server 2.5.0 → 2.7.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 (269) hide show
  1. package/README.md +42 -28
  2. package/dist/NodeStack.d.ts +5 -1
  3. package/dist/NodeStack.d.ts.map +1 -1
  4. package/dist/NodeStack.js +117 -18
  5. package/dist/NodeStack.js.map +1 -1
  6. package/dist/admin/AdminUIBundler.d.ts.map +1 -1
  7. package/dist/admin/AdminUIBundler.js +2 -0
  8. package/dist/admin/AdminUIBundler.js.map +1 -1
  9. package/dist/admin/ui/css/main.css +40 -3
  10. package/dist/admin/ui/css/webhooks.css +8 -0
  11. package/dist/admin/ui/index.html +21479 -17251
  12. package/dist/admin/ui/js/api-keys.js +1381 -0
  13. package/dist/admin/ui/js/api.js +8 -0
  14. package/dist/admin/ui/js/app.js +698 -641
  15. package/dist/admin/ui/js/apps.js +514 -489
  16. package/dist/admin/ui/js/collections.js +486 -484
  17. package/dist/admin/ui/js/command-palette.js +693 -673
  18. package/dist/admin/ui/js/cron.js +1706 -0
  19. package/dist/admin/ui/js/database.js +10 -0
  20. package/dist/admin/ui/js/flows-designer.js +1219 -1076
  21. package/dist/admin/ui/js/flows.js +947 -890
  22. package/dist/admin/ui/js/functions-tester.js +1 -1
  23. package/dist/admin/ui/js/functions-workbench.js +1162 -1101
  24. package/dist/admin/ui/js/functions.js +983 -979
  25. package/dist/admin/ui/js/rules.js +1080 -775
  26. package/dist/admin/ui/js/schema.js +346 -304
  27. package/dist/admin/ui/js/snapshots.js +338 -0
  28. package/dist/admin/ui/js/views.js +1 -1
  29. package/dist/apps/AppManager.d.ts +1 -1
  30. package/dist/apps/AppManager.d.ts.map +1 -1
  31. package/dist/apps/AppManager.js +11 -21
  32. package/dist/apps/AppManager.js.map +1 -1
  33. package/dist/apps/AppRegistry.d.ts +1 -0
  34. package/dist/apps/AppRegistry.d.ts.map +1 -1
  35. package/dist/apps/AppRegistry.js +78 -23
  36. package/dist/apps/AppRegistry.js.map +1 -1
  37. package/dist/apps/AppScope.d.ts +2 -1
  38. package/dist/apps/AppScope.d.ts.map +1 -1
  39. package/dist/apps/AppScope.js +27 -17
  40. package/dist/apps/AppScope.js.map +1 -1
  41. package/dist/auth/ApiKeyService.d.ts +63 -2
  42. package/dist/auth/ApiKeyService.d.ts.map +1 -1
  43. package/dist/auth/ApiKeyService.js +518 -8
  44. package/dist/auth/ApiKeyService.js.map +1 -1
  45. package/dist/auth/AuthService.d.ts +30 -1
  46. package/dist/auth/AuthService.d.ts.map +1 -1
  47. package/dist/auth/AuthService.js +468 -65
  48. package/dist/auth/AuthService.js.map +1 -1
  49. package/dist/auth/oauth/AppleProvider.d.ts +2 -0
  50. package/dist/auth/oauth/AppleProvider.d.ts.map +1 -1
  51. package/dist/auth/oauth/AppleProvider.js +40 -3
  52. package/dist/auth/oauth/AppleProvider.js.map +1 -1
  53. package/dist/auth/oauth/BaseOAuthProvider.d.ts +3 -2
  54. package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -1
  55. package/dist/auth/oauth/BaseOAuthProvider.js +29 -3
  56. package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -1
  57. package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -1
  58. package/dist/auth/oauth/DiscordProvider.js +4 -1
  59. package/dist/auth/oauth/DiscordProvider.js.map +1 -1
  60. package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -1
  61. package/dist/auth/oauth/GitHubProvider.js +4 -1
  62. package/dist/auth/oauth/GitHubProvider.js.map +1 -1
  63. package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -1
  64. package/dist/auth/oauth/GoogleProvider.js +4 -1
  65. package/dist/auth/oauth/GoogleProvider.js.map +1 -1
  66. package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -1
  67. package/dist/auth/oauth/MicrosoftProvider.js +4 -1
  68. package/dist/auth/oauth/MicrosoftProvider.js.map +1 -1
  69. package/dist/auth/oauth/OAuthProviderRegistry.d.ts +6 -2
  70. package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -1
  71. package/dist/auth/oauth/OAuthProviderRegistry.js +25 -10
  72. package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -1
  73. package/dist/auth/oauth/types.d.ts +4 -2
  74. package/dist/auth/oauth/types.d.ts.map +1 -1
  75. package/dist/cli/cli.d.ts.map +1 -1
  76. package/dist/cli/cli.js +228 -12
  77. package/dist/cli/cli.js.map +1 -1
  78. package/dist/core/config/ConfigService.d.ts.map +1 -1
  79. package/dist/core/config/ConfigService.js +5 -3
  80. package/dist/core/config/ConfigService.js.map +1 -1
  81. package/dist/core/config/EnvLoader.d.ts +14 -0
  82. package/dist/core/config/EnvLoader.d.ts.map +1 -1
  83. package/dist/core/config/EnvLoader.js +44 -0
  84. package/dist/core/config/EnvLoader.js.map +1 -1
  85. package/dist/core/container/Container.d.ts +14 -0
  86. package/dist/core/container/Container.d.ts.map +1 -1
  87. package/dist/core/container/Container.js +32 -0
  88. package/dist/core/container/Container.js.map +1 -1
  89. package/dist/core/container/Tokens.d.ts +2 -0
  90. package/dist/core/container/Tokens.d.ts.map +1 -1
  91. package/dist/core/container/Tokens.js +2 -0
  92. package/dist/core/container/Tokens.js.map +1 -1
  93. package/dist/core/errors/AppError.d.ts +7 -7
  94. package/dist/core/errors/AppError.d.ts.map +1 -1
  95. package/dist/core/errors/AppError.js +18 -14
  96. package/dist/core/errors/AppError.js.map +1 -1
  97. package/dist/core/events/EventBus.d.ts.map +1 -1
  98. package/dist/core/events/EventBus.js +36 -6
  99. package/dist/core/events/EventBus.js.map +1 -1
  100. package/dist/core/maintenance/MaintenanceGate.d.ts +47 -0
  101. package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -1
  102. package/dist/core/maintenance/MaintenanceGate.js +265 -7
  103. package/dist/core/maintenance/MaintenanceGate.js.map +1 -1
  104. package/dist/core/plugins/PluginManager.d.ts +20 -1
  105. package/dist/core/plugins/PluginManager.d.ts.map +1 -1
  106. package/dist/core/plugins/PluginManager.js +231 -146
  107. package/dist/core/plugins/PluginManager.js.map +1 -1
  108. package/dist/core/plugins/types.d.ts +48 -31
  109. package/dist/core/plugins/types.d.ts.map +1 -1
  110. package/dist/cron/CronParser.d.ts +83 -0
  111. package/dist/cron/CronParser.d.ts.map +1 -0
  112. package/dist/cron/CronParser.js +538 -0
  113. package/dist/cron/CronParser.js.map +1 -0
  114. package/dist/cron/CronService.d.ts +74 -0
  115. package/dist/cron/CronService.d.ts.map +1 -0
  116. package/dist/cron/CronService.js +1254 -0
  117. package/dist/cron/CronService.js.map +1 -0
  118. package/dist/cron/types.d.ts +98 -0
  119. package/dist/cron/types.d.ts.map +1 -0
  120. package/dist/cron/types.js +3 -0
  121. package/dist/cron/types.js.map +1 -0
  122. package/dist/database/DatabaseService.d.ts +4 -1
  123. package/dist/database/DatabaseService.d.ts.map +1 -1
  124. package/dist/database/DatabaseService.js +34 -9
  125. package/dist/database/DatabaseService.js.map +1 -1
  126. package/dist/database/config/DatabaseConfigService.d.ts +1 -0
  127. package/dist/database/config/DatabaseConfigService.d.ts.map +1 -1
  128. package/dist/database/config/DatabaseConfigService.js +4 -2
  129. package/dist/database/config/DatabaseConfigService.js.map +1 -1
  130. package/dist/database/drivers/DriverPackageLoader.d.ts +11 -0
  131. package/dist/database/drivers/DriverPackageLoader.d.ts.map +1 -0
  132. package/dist/database/drivers/DriverPackageLoader.js +112 -0
  133. package/dist/database/drivers/DriverPackageLoader.js.map +1 -0
  134. package/dist/database/drivers/DriverRegistry.d.ts +1 -0
  135. package/dist/database/drivers/DriverRegistry.d.ts.map +1 -1
  136. package/dist/database/drivers/DriverRegistry.js +29 -0
  137. package/dist/database/drivers/DriverRegistry.js.map +1 -1
  138. package/dist/database/drivers/IDatabaseDriver.d.ts +1 -0
  139. package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -1
  140. package/dist/database/drivers/MssqlDriver.d.ts.map +1 -1
  141. package/dist/database/drivers/MssqlDriver.js +10 -5
  142. package/dist/database/drivers/MssqlDriver.js.map +1 -1
  143. package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -1
  144. package/dist/database/drivers/NodeSqliteDriver.js +15 -1
  145. package/dist/database/drivers/NodeSqliteDriver.js.map +1 -1
  146. package/dist/database/drivers/PostgresDriver.d.ts.map +1 -1
  147. package/dist/database/drivers/PostgresDriver.js +4 -5
  148. package/dist/database/drivers/PostgresDriver.js.map +1 -1
  149. package/dist/database/migration/DatabaseMigrationService.d.ts +1 -0
  150. package/dist/database/migration/DatabaseMigrationService.d.ts.map +1 -1
  151. package/dist/database/migration/DatabaseMigrationService.js +51 -0
  152. package/dist/database/migration/DatabaseMigrationService.js.map +1 -1
  153. package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
  154. package/dist/database/migrations/SystemMigrations.js +200 -5
  155. package/dist/database/migrations/SystemMigrations.js.map +1 -1
  156. package/dist/flows/FlowEngine.js.map +1 -1
  157. package/dist/flows/FlowService.d.ts +10 -1
  158. package/dist/flows/FlowService.d.ts.map +1 -1
  159. package/dist/flows/FlowService.js +227 -14
  160. package/dist/flows/FlowService.js.map +1 -1
  161. package/dist/flows/FlowValidator.d.ts +2 -1
  162. package/dist/flows/FlowValidator.d.ts.map +1 -1
  163. package/dist/flows/FlowValidator.js +89 -4
  164. package/dist/flows/FlowValidator.js.map +1 -1
  165. package/dist/flows/types.d.ts +20 -3
  166. package/dist/flows/types.d.ts.map +1 -1
  167. package/dist/functions/FunctionService.d.ts +10 -2
  168. package/dist/functions/FunctionService.d.ts.map +1 -1
  169. package/dist/functions/FunctionService.js +271 -37
  170. package/dist/functions/FunctionService.js.map +1 -1
  171. package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
  172. package/dist/functions/runtime/QuickJsWasmRuntime.js +189 -177
  173. package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
  174. package/dist/functions/types.d.ts +31 -2
  175. package/dist/functions/types.d.ts.map +1 -1
  176. package/dist/http/HttpServer.d.ts +7 -1
  177. package/dist/http/HttpServer.d.ts.map +1 -1
  178. package/dist/http/HttpServer.js +187 -8
  179. package/dist/http/HttpServer.js.map +1 -1
  180. package/dist/http/controllers/ApiKeyController.d.ts +1 -0
  181. package/dist/http/controllers/ApiKeyController.d.ts.map +1 -1
  182. package/dist/http/controllers/ApiKeyController.js +47 -1
  183. package/dist/http/controllers/ApiKeyController.js.map +1 -1
  184. package/dist/http/controllers/AuthController.d.ts +12 -0
  185. package/dist/http/controllers/AuthController.d.ts.map +1 -1
  186. package/dist/http/controllers/AuthController.js +40 -2
  187. package/dist/http/controllers/AuthController.js.map +1 -1
  188. package/dist/http/controllers/CronController.d.ts +63 -0
  189. package/dist/http/controllers/CronController.d.ts.map +1 -0
  190. package/dist/http/controllers/CronController.js +92 -0
  191. package/dist/http/controllers/CronController.js.map +1 -0
  192. package/dist/http/controllers/DatabaseController.d.ts.map +1 -1
  193. package/dist/http/controllers/DatabaseController.js +53 -0
  194. package/dist/http/controllers/DatabaseController.js.map +1 -1
  195. package/dist/http/controllers/FlowController.d.ts.map +1 -1
  196. package/dist/http/controllers/FlowController.js +45 -4
  197. package/dist/http/controllers/FlowController.js.map +1 -1
  198. package/dist/http/controllers/FunctionController.d.ts.map +1 -1
  199. package/dist/http/controllers/FunctionController.js +16 -2
  200. package/dist/http/controllers/FunctionController.js.map +1 -1
  201. package/dist/http/controllers/HealthController.js +2 -2
  202. package/dist/http/middleware/AppResolutionMiddleware.d.ts +1 -1
  203. package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -1
  204. package/dist/http/middleware/AppResolutionMiddleware.js +2 -3
  205. package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -1
  206. package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
  207. package/dist/http/middleware/AuthMiddleware.js +6 -3
  208. package/dist/http/middleware/AuthMiddleware.js.map +1 -1
  209. package/dist/http/middleware/ChaosMiddleware.js +6 -6
  210. package/dist/http/middleware/ChaosMiddleware.js.map +1 -1
  211. package/dist/index.d.ts +2 -2
  212. package/dist/index.d.ts.map +1 -1
  213. package/dist/index.js +6 -2
  214. package/dist/index.js.map +1 -1
  215. package/dist/queue/QueueService.d.ts +9 -0
  216. package/dist/queue/QueueService.d.ts.map +1 -1
  217. package/dist/queue/QueueService.js +143 -60
  218. package/dist/queue/QueueService.js.map +1 -1
  219. package/dist/queue/drivers/SqliteQueueDriver.d.ts +3 -0
  220. package/dist/queue/drivers/SqliteQueueDriver.d.ts.map +1 -1
  221. package/dist/queue/drivers/SqliteQueueDriver.js +315 -255
  222. package/dist/queue/drivers/SqliteQueueDriver.js.map +1 -1
  223. package/dist/records/FtsService.d.ts +7 -3
  224. package/dist/records/FtsService.d.ts.map +1 -1
  225. package/dist/records/FtsService.js +69 -5
  226. package/dist/records/FtsService.js.map +1 -1
  227. package/dist/records/QueryFilterParser.d.ts.map +1 -1
  228. package/dist/records/QueryFilterParser.js +58 -20
  229. package/dist/records/QueryFilterParser.js.map +1 -1
  230. package/dist/records/RecordSanitizer.d.ts.map +1 -1
  231. package/dist/records/RecordSanitizer.js +32 -4
  232. package/dist/records/RecordSanitizer.js.map +1 -1
  233. package/dist/records/RecordService.d.ts +6 -0
  234. package/dist/records/RecordService.d.ts.map +1 -1
  235. package/dist/records/RecordService.js +95 -14
  236. package/dist/records/RecordService.js.map +1 -1
  237. package/dist/records/RecordValidator.d.ts +10 -0
  238. package/dist/records/RecordValidator.d.ts.map +1 -1
  239. package/dist/records/RecordValidator.js +110 -2
  240. package/dist/records/RecordValidator.js.map +1 -1
  241. package/dist/records/fts/IFtsDriver.d.ts +7 -6
  242. package/dist/records/fts/IFtsDriver.d.ts.map +1 -1
  243. package/dist/records/fts/MssqlFtsDriver.d.ts +5 -1
  244. package/dist/records/fts/MssqlFtsDriver.d.ts.map +1 -1
  245. package/dist/records/fts/MssqlFtsDriver.js +35 -3
  246. package/dist/records/fts/MssqlFtsDriver.js.map +1 -1
  247. package/dist/records/fts/PostgresFtsDriver.d.ts +9 -2
  248. package/dist/records/fts/PostgresFtsDriver.d.ts.map +1 -1
  249. package/dist/records/fts/PostgresFtsDriver.js +116 -11
  250. package/dist/records/fts/PostgresFtsDriver.js.map +1 -1
  251. package/dist/records/fts/SqliteFts5Driver.d.ts +7 -1
  252. package/dist/records/fts/SqliteFts5Driver.d.ts.map +1 -1
  253. package/dist/records/fts/SqliteFts5Driver.js +66 -6
  254. package/dist/records/fts/SqliteFts5Driver.js.map +1 -1
  255. package/dist/schema/OpenApiGenerator.d.ts.map +1 -1
  256. package/dist/schema/OpenApiGenerator.js +103 -3
  257. package/dist/schema/OpenApiGenerator.js.map +1 -1
  258. package/dist/schema/models/Field.d.ts +1 -0
  259. package/dist/schema/models/Field.d.ts.map +1 -1
  260. package/dist/snapshots/SnapshotService.d.ts.map +1 -1
  261. package/dist/snapshots/SnapshotService.js +21 -9
  262. package/dist/snapshots/SnapshotService.js.map +1 -1
  263. package/dist/snapshots/drivers/LogicalSnapshotDriver.d.ts.map +1 -1
  264. package/dist/snapshots/drivers/LogicalSnapshotDriver.js +2 -0
  265. package/dist/snapshots/drivers/LogicalSnapshotDriver.js.map +1 -1
  266. package/dist/templates/definitions/ecommerce.js +6 -6
  267. package/dist/templates/definitions/ecommerce.js.map +1 -1
  268. package/dist/webhooks/WebhookService.js +1 -1
  269. package/package.json +5 -3
@@ -1,673 +1,693 @@
1
- // ==========================================
2
- // Global Command Palette (Ctrl + K / Cmd + K)
3
- // ==========================================
4
-
5
- let commandPaletteActiveIndex = 0;
6
- let commandPaletteFilteredItems = [];
7
-
8
- function getAllCommandPaletteItems() {
9
- const items = [];
10
-
11
- // 1. Collections (User & System)
12
- for (const col of state.collections || []) {
13
- const isSys = typeof isSystemCollection === 'function' ? isSystemCollection(col) : Boolean(col.system || col.name?.startsWith('_'));
14
- items.push({
15
- id: `col-${col.name}`,
16
- title: col.name,
17
- description: `Jump to ${col.name} (${col.type}) collection`,
18
- category: isSys ? 'System Tables' : 'Collections',
19
- badge: col.type.toUpperCase(),
20
- icon: isSys ? '⚙️' : '📁',
21
- keywords: [col.name, col.name.toLowerCase(), 'collection', 'jump', col.type, isSys ? 'system' : 'user'],
22
- action: () => {
23
- if (typeof selectCollection === 'function') {
24
- selectCollection(col.name);
25
- }
26
- }
27
- });
28
- }
29
-
30
- // 2. Navigation items
31
- items.push({
32
- id: 'nav-home',
33
- title: 'Overview',
34
- description: 'Server status, collections list, quick stats',
35
- category: 'Navigation',
36
- badge: 'PAGE',
37
- icon: '🏠',
38
- keywords: ['home', 'dashboard', 'overview'],
39
- action: () => selectNav('home')
40
- });
41
-
42
- items.push({
43
- id: 'nav-collections',
44
- title: 'Collections',
45
- description: 'Dedicated database collections directory, tables & schema',
46
- category: 'Navigation',
47
- badge: 'PAGE',
48
- icon: '📦',
49
- keywords: ['collections', 'database', 'tables', 'schema', 'records'],
50
- action: () => selectNav('collections')
51
- });
52
-
53
- items.push({
54
- id: 'nav-plugins',
55
- title: 'Plugins',
56
- description: 'Dedicated official extensions & community plugins directory',
57
- category: 'Navigation',
58
- badge: 'PAGE',
59
- icon: '🧩',
60
- keywords: ['plugins', 'extensions', 'addons', 'stripe', 's3', 'resend', 'chat notifications', 'discord', 'slack', 'webhooks', 'algolia'],
61
- action: () => selectNav('plugins')
62
- });
63
-
64
- items.push({
65
- id: 'nav-webhooks',
66
- title: 'Webhooks Manager',
67
- description: 'Configure outbound webhooks, signatures and retry delivery logs',
68
- category: 'Navigation',
69
- badge: 'PAGE',
70
- icon: '🔗',
71
- keywords: ['webhooks', 'webhook', 'outbound', 'events', 'deliveries', 'retry'],
72
- action: () => selectNav('webhooks')
73
- });
74
-
75
- items.push({
76
- id: 'nav-functions',
77
- title: 'Serverless Functions',
78
- description: 'Sandboxed QuickJS serverless functions, API routes and event hooks',
79
- category: 'Navigation',
80
- badge: 'PAGE',
81
- icon: '⚡',
82
- keywords: ['functions', 'serverless', 'lambda', 'quickjs', 'wasm', 'sandbox', 'api', 'hooks', 'code'],
83
- action: () => selectNav('functions')
84
- });
85
-
86
- items.push({
87
- id: 'nav-flows',
88
- title: 'Functions Flow',
89
- description: 'Visual state machine orchestrator and pipeline designer',
90
- category: 'Navigation',
91
- badge: 'PAGE',
92
- icon: '🔀',
93
- keywords: ['flows', 'flow', 'pipeline', 'workflow', 'orchestrator', 'state machine', 'designer'],
94
- action: () => selectNav('flows')
95
- },
96
- {
97
- id: 'nav-queues',
98
- title: 'Queues Manager',
99
- description: 'Configure message queues, serverless function workers, DLQs and inspect messages',
100
- category: 'Navigation',
101
- badge: 'PAGE',
102
- icon: '📬',
103
- keywords: ['queues', 'queue', 'jobs', 'messages', 'dlq', 'dead letter', 'worker', 'background', 'concurrency'],
104
- action: () => selectNav('queues')
105
- },
106
- {
107
- id: 'nav-analytics',
108
- title: 'Analytics',
109
- description: 'Realtime telemetry, latency and request throughput',
110
- category: 'Navigation',
111
- badge: 'PAGE',
112
- icon: '📊',
113
- keywords: ['metrics', 'analytics', 'telemetry', 'stats', 'traffic', 'latency', 'uptime', 'system'],
114
- action: () => selectNav('analytics')
115
- });
116
-
117
- items.push({
118
- id: 'nav-snapshots',
119
- title: 'Snapshots',
120
- description: 'Capture or restore application state snapshots',
121
-
122
- category: 'Navigation',
123
- badge: 'PAGE',
124
- icon: '📸',
125
- keywords: ['snapshots', 'snapshot', 'backup', 'restore', 'demo'],
126
- action: () => selectNav('snapshots')
127
- });
128
-
129
- items.push({
130
- id: 'nav-logs',
131
- title: 'Audit Logs',
132
- description: 'Live HTTP request activity, errors and slow queries',
133
- category: 'Navigation',
134
- badge: 'PAGE',
135
- icon: '📝',
136
- keywords: ['audit', 'logs', 'traffic', 'requests', 'errors', 'debug'],
137
- action: () => selectNav('logs')
138
- });
139
-
140
- items.push({
141
- id: "nav-database",
142
- title: "Database Engine Settings",
143
- description: "Configure and switch between SQLite, PostgreSQL, and SQL Server",
144
- category: "System",
145
- badge: "CONFIG",
146
- icon: "🗄️",
147
- keywords: ["database", "db", "postgres", "postgresql", "mssql", "sql server", "sqlite", "cluster", "migrate", "switch database"],
148
- action: () => selectNav('database')
149
- });
150
-
151
- // 2.5 Plugin navigation items
152
- if (state.pluginNavItems && state.pluginNavItems.length > 0) {
153
- for (const p of state.pluginNavItems) {
154
- items.push({
155
- id: 'plugin-' + p.id,
156
- title: p.title,
157
- description: (p.view && typeof p.view === 'object' && p.view.description) ? p.view.description : `Plugin extension: ${p.title}`,
158
- category: 'Plugins',
159
- badge: p.badge || 'PLUGIN',
160
- icon: '🧩',
161
- keywords: [p.id, p.title.toLowerCase(), 'plugin', 'extension'],
162
- action: () => selectNav(p.id)
163
- });
164
- }
165
- }
166
-
167
- // 2.8 Application Switcher & Actions
168
- if (Array.isArray(state.apps) && state.apps.length > 0) {
169
- for (const app of state.apps) {
170
- items.push({
171
- id: `app-switch-${app.slug}`,
172
- title: `Switch App: ${app.name}`,
173
- description: `Switch active application context to ${app.name} (${app.slug})`,
174
- category: 'Applications',
175
- badge: app.isDefault ? 'DEFAULT' : 'APP',
176
- icon: app.isDefault ? '⚡' : '🚀',
177
- keywords: ['app', 'application', 'switch', app.name.toLowerCase(), app.slug.toLowerCase()],
178
- action: () => {
179
- if (typeof selectApp === 'function') {
180
- selectApp(app.slug);
181
- }
182
- }
183
- });
184
- if (!app.isDefault && app.slug !== 'default') {
185
- items.push({
186
- id: `app-delete-${app.slug}`,
187
- title: `Delete App: ${app.name}`,
188
- description: `Permanently delete application ${app.name} (${app.slug}) and its database`,
189
- category: 'Applications',
190
- badge: 'DANGER',
191
- icon: '🗑️',
192
- keywords: ['delete app', 'remove app', 'delete application', 'drop app', app.slug.toLowerCase(), app.name.toLowerCase()],
193
- action: () => {
194
- if (typeof promptDeleteApp === 'function') {
195
- promptDeleteApp(app.slug, app.name);
196
- }
197
- }
198
- });
199
- }
200
- }
201
- }
202
-
203
- items.push({
204
- id: 'action-create-app',
205
- title: 'Create New Application...',
206
- description: 'Create a new isolated application scope with dedicated database and storage',
207
- category: 'Applications',
208
- badge: 'NEW',
209
- icon: '➕',
210
- keywords: ['create app', 'new app', 'new application', 'application', 'tenant'],
211
- action: () => {
212
- if (typeof openCreateAppModal === 'function') {
213
- openCreateAppModal();
214
- }
215
- }
216
- });
217
-
218
- // 3. Actions: Export
219
- if (state.activeCollection) {
220
- items.push({
221
- id: 'action-export-json',
222
- title: `Export ${state.activeCollection.name} (JSON)`,
223
- description: `Download ${state.activeCollection.name} records as JSON format`,
224
- category: 'Actions',
225
- badge: 'EXPORT',
226
- icon: '📥',
227
- keywords: ['export', 'export json', 'download', 'json', 'current collection', state.activeCollection.name],
228
- action: () => {
229
- if (typeof exportData === 'function') {
230
- exportData('json');
231
- }
232
- }
233
- });
234
- items.push({
235
- id: 'action-export-csv',
236
- title: `Export ${state.activeCollection.name} (CSV)`,
237
- description: `Download ${state.activeCollection.name} records as CSV spreadsheet`,
238
- category: 'Actions',
239
- badge: 'EXPORT',
240
- icon: '📄',
241
- keywords: ['export', 'export csv', 'download', 'csv', 'current collection', state.activeCollection.name],
242
- action: () => {
243
- if (typeof exportData === 'function') {
244
- exportData('csv');
245
- }
246
- }
247
- });
248
- } else {
249
- items.push({
250
- id: 'action-export',
251
- title: 'Export Collection Records',
252
- description: 'Trigger data export (requires active collection)',
253
- category: 'Actions',
254
- badge: 'EXPORT',
255
- icon: '📥',
256
- keywords: ['export', 'download', 'json', 'csv'],
257
- action: () => {
258
- toast('Please select a collection first to export records', 'info');
259
- }
260
- });
261
- }
262
-
263
- // 4. Actions: New Collection
264
- items.push({
265
- id: 'action-new-collection',
266
- title: 'New Collection',
267
- description: 'Create a new schema from scratch',
268
- category: 'Actions',
269
- badge: 'CREATE',
270
- icon: '➕',
271
- keywords: ['new', 'create', 'collection', 'add collection', 'new collection'],
272
- action: () => {
273
- if (typeof openNewCollectionModal === 'function') {
274
- openNewCollectionModal();
275
- }
276
- }
277
- });
278
-
279
- items.push({
280
- id: 'action-new-webhook',
281
- title: 'New Webhook',
282
- description: 'Configure an outbound HTTP webhook on collection events',
283
- category: 'Actions',
284
- badge: 'CREATE',
285
- icon: '⚡',
286
- keywords: ['new webhook', 'create webhook', 'webhook', 'outbound', 'signature'],
287
- action: () => {
288
- selectNav('webhooks');
289
- setTimeout(() => {
290
- if (typeof openCreateWebhookModal === 'function') openCreateWebhookModal();
291
- }, 50);
292
- }
293
- });
294
-
295
- // 5. Actions: Starter Templates
296
- items.push({
297
- id: 'action-templates',
298
- title: 'Starter Templates',
299
- description: 'Pre-seeded recipes (E-Commerce, Blog, CRM)',
300
- category: 'Actions',
301
- badge: 'RECIPE',
302
- icon: '✨',
303
- keywords: ['templates', 'starter templates', 'ecommerce', 'blog', 'crm', 'recipe'],
304
- action: () => {
305
- if (typeof openTemplatesModal === 'function') {
306
- openTemplatesModal();
307
- }
308
- }
309
- });
310
-
311
- // 6. Actions: Import JSON
312
- items.push({
313
- id: 'action-import-json',
314
- title: 'Import JSON Schema',
315
- description: 'Generate database schema from JSON sample',
316
- category: 'Actions',
317
- badge: 'IMPORT',
318
- icon: '📥',
319
- keywords: ['import', 'json', 'schema', 'upload'],
320
- action: () => {
321
- if (typeof openImportJsonModal === 'function') {
322
- openImportJsonModal();
323
- }
324
- }
325
- });
326
-
327
- // 7. Action: New Record (if collection active)
328
- if (state.activeCollection) {
329
- items.push({
330
- id: 'action-new-record',
331
- title: `Create Record in ${state.activeCollection.name}`,
332
- description: `Insert a new row into ${state.activeCollection.name}`,
333
- category: 'Actions',
334
- badge: 'RECORD',
335
- icon: '📝',
336
- keywords: ['new record', 'create record', 'add record', 'insert', 'row'],
337
- action: () => {
338
- if (typeof openNewRecordModal === 'function') {
339
- openNewRecordModal();
340
- }
341
- }
342
- });
343
- }
344
-
345
- // 8. Action: OpenAPI Docs
346
- items.push({
347
- id: 'action-docs',
348
- title: 'API Docs (OpenAPI)',
349
- description: 'Interactive OpenAPI 3.0 Reference & testing sandbox',
350
- category: 'Documentation',
351
- badge: 'DOCS',
352
- icon: '📖',
353
- keywords: ['docs', 'openapi', 'swagger', 'api reference'],
354
- action: () => {
355
- if (typeof openDocsWithApp === 'function') {
356
- openDocsWithApp();
357
- } else {
358
- const slug = (typeof getActiveAppSlug === 'function')
359
- ? getActiveAppSlug()
360
- : (state?.activeApp?.slug || (typeof state?.activeApp === 'string' ? state.activeApp : 'default'));
361
- const app = slug && slug !== 'default' ? `?app=${encodeURIComponent(slug)}` : '';
362
- window.open(`/_/docs${app}`, '_blank');
363
- }
364
- }
365
- });
366
-
367
-
368
- // 9. Appearance & Theme
369
- items.push({
370
- id: 'theme-system',
371
- title: 'Theme: System (Auto)',
372
- description: 'Sync admin appearance with your operating system preference',
373
- category: 'Appearance',
374
- badge: 'THEME',
375
- icon: '💻',
376
- keywords: ['theme', 'appearance', 'system', 'auto', 'mode', 'color'],
377
- action: () => {
378
- if (typeof setTheme === 'function') setTheme('system');
379
- }
380
- });
381
-
382
- items.push({
383
- id: 'theme-light',
384
- title: 'Theme: Light Mode',
385
- description: 'Switch admin portal to clean light appearance',
386
- category: 'Appearance',
387
- badge: 'THEME',
388
- icon: '☀️',
389
- keywords: ['theme', 'appearance', 'light', 'white', 'day', 'mode', 'color'],
390
- action: () => {
391
- if (typeof setTheme === 'function') setTheme('light');
392
- }
393
- });
394
-
395
- items.push({
396
- id: 'theme-dark',
397
- title: 'Theme: Dark Mode',
398
- description: 'Switch admin portal to dark night appearance',
399
- category: 'Appearance',
400
- badge: 'THEME',
401
- icon: '🌙',
402
- keywords: ['theme', 'appearance', 'dark', 'black', 'night', 'mode', 'color'],
403
- action: () => {
404
- if (typeof setTheme === 'function') setTheme('dark');
405
- }
406
- });
407
-
408
- return items;
409
- }
410
-
411
- function filterCommandPaletteItems(query) {
412
- const all = getAllCommandPaletteItems();
413
- const q = (query || '').trim().toLowerCase();
414
- if (!q) {
415
- return all;
416
- }
417
-
418
- const scored = [];
419
- for (const item of all) {
420
- let score = 0;
421
- const titleLower = item.title.toLowerCase();
422
-
423
- if (titleLower === q) {
424
- score += 100;
425
- } else if (titleLower.startsWith(q)) {
426
- score += 70;
427
- } else if (titleLower.includes(q)) {
428
- score += 40;
429
- }
430
-
431
- for (const kw of item.keywords || []) {
432
- if (kw === q) {
433
- score = Math.max(score, 90);
434
- } else if (kw.startsWith(q)) {
435
- score = Math.max(score, 60);
436
- } else if (kw.includes(q)) {
437
- score = Math.max(score, 30);
438
- }
439
- }
440
-
441
- if (item.description && item.description.toLowerCase().includes(q)) {
442
- score = Math.max(score, 20);
443
- }
444
-
445
- if (score > 0) {
446
- scored.push({ item, score });
447
- }
448
- }
449
-
450
- scored.sort((a, b) => b.score - a.score);
451
- return scored.map(s => s.item);
452
- }
453
-
454
- function renderCommandPaletteResultsHtml(items, selectedIndex) {
455
- if (!items || items.length === 0) {
456
- return `<div class="command-palette-empty">No matching commands or collections found</div>`;
457
- }
458
-
459
- return items.map((item, idx) => `
460
- <div
461
- class="command-palette-item ${idx === selectedIndex ? 'selected' : ''}"
462
- id="command-palette-item-${idx}"
463
- onclick="executeCommandPaletteItem(${idx})"
464
- onmouseenter="setCommandPaletteActiveIndex(${idx})"
465
- data-index="${idx}"
466
- role="option"
467
- aria-selected="${idx === selectedIndex ? 'true' : 'false'}"
468
- tabindex="-1"
469
- >
470
- <div class="command-palette-item-left">
471
- <div class="command-palette-item-icon" aria-hidden="true">${item.icon || '▶'}</div>
472
- <div class="command-palette-item-text">
473
- <div class="command-palette-item-title">${escapeHtml(item.title)}</div>
474
- <div class="command-palette-item-desc">${escapeHtml(item.description)}</div>
475
- </div>
476
- </div>
477
- <div class="command-palette-item-badge">${escapeHtml(item.badge || item.category)}</div>
478
- </div>
479
- `).join('');
480
- }
481
-
482
- function openCommandPalette() {
483
- commandPaletteActiveIndex = 0;
484
- commandPaletteFilteredItems = filterCommandPaletteItems('');
485
- const root = document.getElementById('command-palette-root');
486
- if (!root) return;
487
-
488
- root.innerHTML = `
489
- <div class="command-palette-backdrop" id="command-palette-backdrop" onclick="handleCommandPaletteBackdrop(event)" onkeydown="if(event.key==='Escape'){event.preventDefault();event.stopPropagation();closeCommandPalette();}">
490
- <div class="command-palette-modal" role="dialog" aria-modal="true" aria-label="Command Palette">
491
- <div class="command-palette-header">
492
- <svg class="command-palette-search-icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
493
- <circle cx="11" cy="11" r="8"></circle>
494
- <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
495
- </svg>
496
- <input
497
- type="text"
498
- id="command-palette-input"
499
- class="command-palette-input"
500
- placeholder="Type a command or jump to... (e.g. users, metrics, export, new)"
501
- autocomplete="off"
502
- spellcheck="false"
503
- role="combobox"
504
- aria-autocomplete="list"
505
- aria-expanded="${commandPaletteFilteredItems.length > 0 ? 'true' : 'false'}"
506
- aria-haspopup="listbox"
507
- aria-controls="command-palette-results"
508
- ${commandPaletteFilteredItems.length > 0 ? 'aria-activedescendant="command-palette-item-0"' : ''}
509
- oninput="handleCommandPaletteInput(this.value)"
510
- onkeydown="handleCommandPaletteKeyDown(event)"
511
- />
512
- <span class="command-palette-esc-badge" onclick="closeCommandPalette()" role="button" aria-label="Close command palette">ESC</span>
513
- </div>
514
- <div class="command-palette-results" id="command-palette-results" role="listbox" aria-label="Commands and collections">
515
- ${renderCommandPaletteResultsHtml(commandPaletteFilteredItems, 0)}
516
- </div>
517
- <div class="command-palette-footer">
518
- <div class="command-palette-footer-shortcuts">
519
- <span><kbd class="palette-kbd">↑</kbd><kbd class="palette-kbd">↓</kbd> navigate</span>
520
- <span><kbd class="palette-kbd">↵</kbd> select</span>
521
- <span><kbd class="palette-kbd">esc</kbd> close</span>
522
- </div>
523
- <div style="font-size:10px; opacity:0.7;">NodeStack Quick Jump</div>
524
- </div>
525
- </div>
526
- </div>
527
- `;
528
-
529
- setTimeout(() => {
530
- const input = document.getElementById('command-palette-input');
531
- if (input) input.focus();
532
- }, 20);
533
- }
534
-
535
- function closeCommandPalette() {
536
- const root = document.getElementById('command-palette-root');
537
- if (root) root.innerHTML = '';
538
- }
539
-
540
- function handleCommandPaletteBackdrop(e) {
541
- if (e.target && e.target.id === 'command-palette-backdrop') {
542
- closeCommandPalette();
543
- }
544
- }
545
-
546
- function toggleCommandPalette() {
547
- const root = document.getElementById('command-palette-root');
548
- if (root && root.innerHTML.trim().length > 0) {
549
- closeCommandPalette();
550
- } else {
551
- openCommandPalette();
552
- }
553
- }
554
-
555
- function handleCommandPaletteInput(val) {
556
- commandPaletteActiveIndex = 0;
557
- commandPaletteFilteredItems = filterCommandPaletteItems(val);
558
- const container = document.getElementById('command-palette-results');
559
- const input = document.getElementById('command-palette-input');
560
-
561
- if (container) {
562
- container.innerHTML = renderCommandPaletteResultsHtml(commandPaletteFilteredItems, 0);
563
- }
564
-
565
- if (input) {
566
- if (commandPaletteFilteredItems.length > 0) {
567
- input.setAttribute('aria-expanded', 'true');
568
- input.setAttribute('aria-activedescendant', 'command-palette-item-0');
569
- } else {
570
- input.setAttribute('aria-expanded', 'false');
571
- input.removeAttribute('aria-activedescendant');
572
- }
573
- }
574
- }
575
-
576
- function handleCommandPaletteKeyDown(e) {
577
- if (e.key === 'ArrowDown') {
578
- e.preventDefault();
579
- if (commandPaletteFilteredItems.length > 0) {
580
- commandPaletteActiveIndex = (commandPaletteActiveIndex + 1) % commandPaletteFilteredItems.length;
581
- updateCommandPaletteActiveItem();
582
- }
583
- } else if (e.key === 'ArrowUp') {
584
- e.preventDefault();
585
- if (commandPaletteFilteredItems.length > 0) {
586
- commandPaletteActiveIndex = (commandPaletteActiveIndex - 1 + commandPaletteFilteredItems.length) % commandPaletteFilteredItems.length;
587
- updateCommandPaletteActiveItem();
588
- }
589
- } else if (e.key === 'Enter') {
590
- e.preventDefault();
591
- executeCommandPaletteItem(commandPaletteActiveIndex);
592
- } else if (e.key === 'Escape') {
593
- e.preventDefault();
594
- e.stopPropagation();
595
- closeCommandPalette();
596
- }
597
- }
598
-
599
- function updateCommandPaletteActiveItem() {
600
- const input = document.getElementById('command-palette-input');
601
- const items = document.querySelectorAll('.command-palette-item');
602
- let activeId = null;
603
-
604
- items.forEach((el, idx) => {
605
- if (idx === commandPaletteActiveIndex) {
606
- el.classList.add('selected');
607
- el.setAttribute('aria-selected', 'true');
608
- activeId = el.id;
609
- if (typeof el.scrollIntoView === 'function') {
610
- el.scrollIntoView({ block: 'nearest' });
611
- }
612
- } else {
613
- el.classList.remove('selected');
614
- el.setAttribute('aria-selected', 'false');
615
- }
616
- });
617
-
618
- if (input) {
619
- if (activeId) {
620
- input.setAttribute('aria-activedescendant', activeId);
621
- } else {
622
- input.removeAttribute('aria-activedescendant');
623
- }
624
- }
625
- }
626
-
627
- function setCommandPaletteActiveIndex(idx) {
628
- commandPaletteActiveIndex = idx;
629
- const input = document.getElementById('command-palette-input');
630
- const items = document.querySelectorAll('.command-palette-item');
631
- let activeId = null;
632
-
633
- items.forEach((el, i) => {
634
- if (i === idx) {
635
- el.classList.add('selected');
636
- el.setAttribute('aria-selected', 'true');
637
- activeId = el.id;
638
- } else {
639
- el.classList.remove('selected');
640
- el.setAttribute('aria-selected', 'false');
641
- }
642
- });
643
-
644
- if (input) {
645
- if (activeId) {
646
- input.setAttribute('aria-activedescendant', activeId);
647
- } else {
648
- input.removeAttribute('aria-activedescendant');
649
- }
650
- }
651
- }
652
-
653
- function executeCommandPaletteItem(index) {
654
- const item = commandPaletteFilteredItems[index];
655
- if (!item) return;
656
- closeCommandPalette();
657
- if (typeof item.action === 'function') {
658
- item.action();
659
- }
660
- }
661
-
662
- // Expose helpers on window for browser event handlers & tests
663
- if (typeof window !== 'undefined') {
664
- window.openCommandPalette = openCommandPalette;
665
- window.closeCommandPalette = closeCommandPalette;
666
- window.toggleCommandPalette = toggleCommandPalette;
667
- window.getAllCommandPaletteItems = getAllCommandPaletteItems;
668
- window.filterCommandPaletteItems = filterCommandPaletteItems;
669
- window.executeCommandPaletteItem = executeCommandPaletteItem;
670
- window.handleCommandPaletteInput = handleCommandPaletteInput;
671
- window.handleCommandPaletteKeyDown = handleCommandPaletteKeyDown;
672
- window.setCommandPaletteActiveIndex = setCommandPaletteActiveIndex;
673
- }
1
+ // ==========================================
2
+ // Global Command Palette (Ctrl + K / Cmd + K)
3
+ // ==========================================
4
+
5
+ let commandPaletteActiveIndex = 0;
6
+ let commandPaletteFilteredItems = [];
7
+
8
+ function getAllCommandPaletteItems() {
9
+ const items = [];
10
+
11
+ // 1. Collections (User & System)
12
+ for (const col of state.collections || []) {
13
+ const isSys = typeof isSystemCollection === 'function' ? isSystemCollection(col) : Boolean(col.system || col.name?.startsWith('_'));
14
+ items.push({
15
+ id: `col-${col.name}`,
16
+ title: col.name,
17
+ description: `Jump to ${col.name} (${col.type}) collection`,
18
+ category: isSys ? 'System Tables' : 'Collections',
19
+ badge: col.type.toUpperCase(),
20
+ icon: isSys ? '⚙️' : '📁',
21
+ keywords: [col.name, col.name.toLowerCase(), 'collection', 'jump', col.type, isSys ? 'system' : 'user'],
22
+ action: () => {
23
+ if (typeof selectCollection === 'function') {
24
+ selectCollection(col.name);
25
+ }
26
+ }
27
+ });
28
+ }
29
+
30
+ // 2. Navigation items
31
+ items.push({
32
+ id: 'nav-home',
33
+ title: 'Overview',
34
+ description: 'Server status, collections list, quick stats',
35
+ category: 'Navigation',
36
+ badge: 'PAGE',
37
+ icon: '🏠',
38
+ keywords: ['home', 'dashboard', 'overview'],
39
+ action: () => selectNav('home')
40
+ });
41
+
42
+ items.push({
43
+ id: 'nav-collections',
44
+ title: 'Collections',
45
+ description: 'Dedicated database collections directory, tables & schema',
46
+ category: 'Navigation',
47
+ badge: 'PAGE',
48
+ icon: '📦',
49
+ keywords: ['collections', 'database', 'tables', 'schema', 'records'],
50
+ action: () => selectNav('collections')
51
+ });
52
+
53
+ items.push({
54
+ id: 'nav-plugins',
55
+ title: 'Plugins',
56
+ description: 'Dedicated official extensions & community plugins directory',
57
+ category: 'Navigation',
58
+ badge: 'PAGE',
59
+ icon: '🧩',
60
+ keywords: ['plugins', 'extensions', 'addons', 'stripe', 's3', 'resend', 'chat notifications', 'discord', 'slack', 'webhooks', 'algolia'],
61
+ action: () => selectNav('plugins')
62
+ });
63
+
64
+ items.push({
65
+ id: 'nav-webhooks',
66
+ title: 'Webhooks Manager',
67
+ description: 'Configure outbound webhooks, signatures and retry delivery logs',
68
+ category: 'Navigation',
69
+ badge: 'PAGE',
70
+ icon: '🔗',
71
+ keywords: ['webhooks', 'webhook', 'outbound', 'events', 'deliveries', 'retry'],
72
+ action: () => selectNav('webhooks')
73
+ });
74
+
75
+ items.push({
76
+ id: 'nav-functions',
77
+ title: 'Serverless Functions',
78
+ description: 'Sandboxed QuickJS serverless functions, API routes and event hooks',
79
+ category: 'Navigation',
80
+ badge: 'PAGE',
81
+ icon: '⚡',
82
+ keywords: ['functions', 'serverless', 'lambda', 'quickjs', 'wasm', 'sandbox', 'api', 'hooks', 'code'],
83
+ action: () => selectNav('functions')
84
+ });
85
+
86
+ items.push({
87
+ id: 'nav-flows',
88
+ title: 'Functions Flow',
89
+ description: 'Visual state machine orchestrator and pipeline designer',
90
+ category: 'Navigation',
91
+ badge: 'PAGE',
92
+ icon: '🔀',
93
+ keywords: ['flows', 'flow', 'pipeline', 'workflow', 'orchestrator', 'state machine', 'designer'],
94
+ action: () => selectNav('flows')
95
+ },
96
+ {
97
+ id: 'nav-queues',
98
+ title: 'Queues Manager',
99
+ description: 'Configure message queues, serverless function workers, DLQs and inspect messages',
100
+ category: 'Navigation',
101
+ badge: 'PAGE',
102
+ icon: '📬',
103
+ keywords: ['queues', 'queue', 'jobs', 'messages', 'dlq', 'dead letter', 'worker', 'background', 'concurrency'],
104
+ action: () => selectNav('queues')
105
+ },
106
+ {
107
+ id: 'nav-schedules',
108
+ title: 'Schedules Manager',
109
+ description: 'Configure cron schedules, timezone wall-clock triggers, and automated background jobs',
110
+ category: 'Navigation',
111
+ badge: 'PAGE',
112
+ icon: '⏱️',
113
+ keywords: ['schedules', 'cron', 'timer', 'scheduled', 'triggers', 'backup', 'automation', 'misfire'],
114
+ action: () => selectNav('schedules')
115
+ },
116
+ {
117
+ id: 'nav-api-keys',
118
+ title: 'API Keys',
119
+ description: 'Create scoped machine-to-machine API keys across Collections, Functions, Flows and Queues',
120
+ category: 'Navigation',
121
+ badge: 'PAGE',
122
+ icon: '🔑',
123
+ keywords: ['api', 'keys', 'tokens', 'm2m', 'scopes', 'permissions', 'auth'],
124
+ action: () => selectNav('api-keys')
125
+ },
126
+ {
127
+ id: 'nav-analytics',
128
+ title: 'Analytics',
129
+ description: 'Realtime telemetry, latency and request throughput',
130
+ category: 'Navigation',
131
+ badge: 'PAGE',
132
+ icon: '📊',
133
+ keywords: ['metrics', 'analytics', 'telemetry', 'stats', 'traffic', 'latency', 'uptime', 'system'],
134
+ action: () => selectNav('analytics')
135
+ });
136
+
137
+ items.push({
138
+ id: 'nav-snapshots',
139
+ title: 'Snapshots',
140
+ description: 'Capture or restore application state snapshots',
141
+
142
+ category: 'Navigation',
143
+ badge: 'PAGE',
144
+ icon: '📸',
145
+ keywords: ['snapshots', 'snapshot', 'backup', 'restore', 'demo'],
146
+ action: () => selectNav('snapshots')
147
+ });
148
+
149
+ items.push({
150
+ id: 'nav-logs',
151
+ title: 'Audit Logs',
152
+ description: 'Live HTTP request activity, errors and slow queries',
153
+ category: 'Navigation',
154
+ badge: 'PAGE',
155
+ icon: '📝',
156
+ keywords: ['audit', 'logs', 'traffic', 'requests', 'errors', 'debug'],
157
+ action: () => selectNav('logs')
158
+ });
159
+
160
+ items.push({
161
+ id: "nav-database",
162
+ title: "Database Engine Settings",
163
+ description: "Configure and switch between SQLite, PostgreSQL, and SQL Server",
164
+ category: "System",
165
+ badge: "CONFIG",
166
+ icon: "🗄️",
167
+ keywords: ["database", "db", "postgres", "postgresql", "mssql", "sql server", "sqlite", "cluster", "migrate", "switch database"],
168
+ action: () => selectNav('database')
169
+ });
170
+
171
+ // 2.5 Plugin navigation items
172
+ if (state.pluginNavItems && state.pluginNavItems.length > 0) {
173
+ for (const p of state.pluginNavItems) {
174
+ items.push({
175
+ id: 'plugin-' + p.id,
176
+ title: p.title,
177
+ description: (p.view && typeof p.view === 'object' && p.view.description) ? p.view.description : `Plugin extension: ${p.title}`,
178
+ category: 'Plugins',
179
+ badge: p.badge || 'PLUGIN',
180
+ icon: '🧩',
181
+ keywords: [p.id, p.title.toLowerCase(), 'plugin', 'extension'],
182
+ action: () => selectNav(p.id)
183
+ });
184
+ }
185
+ }
186
+
187
+ // 2.8 Application Switcher & Actions
188
+ if (Array.isArray(state.apps) && state.apps.length > 0) {
189
+ for (const app of state.apps) {
190
+ items.push({
191
+ id: `app-switch-${app.slug}`,
192
+ title: `Switch App: ${app.name}`,
193
+ description: `Switch active application context to ${app.name} (${app.slug})`,
194
+ category: 'Applications',
195
+ badge: app.isDefault ? 'DEFAULT' : 'APP',
196
+ icon: app.isDefault ? '⚡' : '🚀',
197
+ keywords: ['app', 'application', 'switch', app.name.toLowerCase(), app.slug.toLowerCase()],
198
+ action: () => {
199
+ if (typeof selectApp === 'function') {
200
+ selectApp(app.slug);
201
+ }
202
+ }
203
+ });
204
+ if (!app.isDefault && app.slug !== 'default') {
205
+ items.push({
206
+ id: `app-delete-${app.slug}`,
207
+ title: `Delete App: ${app.name}`,
208
+ description: `Permanently delete application ${app.name} (${app.slug}) and its database`,
209
+ category: 'Applications',
210
+ badge: 'DANGER',
211
+ icon: '🗑️',
212
+ keywords: ['delete app', 'remove app', 'delete application', 'drop app', app.slug.toLowerCase(), app.name.toLowerCase()],
213
+ action: () => {
214
+ if (typeof promptDeleteApp === 'function') {
215
+ promptDeleteApp(app.slug, app.name);
216
+ }
217
+ }
218
+ });
219
+ }
220
+ }
221
+ }
222
+
223
+ items.push({
224
+ id: 'action-create-app',
225
+ title: 'Create New Application...',
226
+ description: 'Create a new isolated application scope with dedicated database and storage',
227
+ category: 'Applications',
228
+ badge: 'NEW',
229
+ icon: '➕',
230
+ keywords: ['create app', 'new app', 'new application', 'application', 'tenant'],
231
+ action: () => {
232
+ if (typeof openCreateAppModal === 'function') {
233
+ openCreateAppModal();
234
+ }
235
+ }
236
+ });
237
+
238
+ // 3. Actions: Export
239
+ if (state.activeCollection) {
240
+ items.push({
241
+ id: 'action-export-json',
242
+ title: `Export ${state.activeCollection.name} (JSON)`,
243
+ description: `Download ${state.activeCollection.name} records as JSON format`,
244
+ category: 'Actions',
245
+ badge: 'EXPORT',
246
+ icon: '📥',
247
+ keywords: ['export', 'export json', 'download', 'json', 'current collection', state.activeCollection.name],
248
+ action: () => {
249
+ if (typeof exportData === 'function') {
250
+ exportData('json');
251
+ }
252
+ }
253
+ });
254
+ items.push({
255
+ id: 'action-export-csv',
256
+ title: `Export ${state.activeCollection.name} (CSV)`,
257
+ description: `Download ${state.activeCollection.name} records as CSV spreadsheet`,
258
+ category: 'Actions',
259
+ badge: 'EXPORT',
260
+ icon: '📄',
261
+ keywords: ['export', 'export csv', 'download', 'csv', 'current collection', state.activeCollection.name],
262
+ action: () => {
263
+ if (typeof exportData === 'function') {
264
+ exportData('csv');
265
+ }
266
+ }
267
+ });
268
+ } else {
269
+ items.push({
270
+ id: 'action-export',
271
+ title: 'Export Collection Records',
272
+ description: 'Trigger data export (requires active collection)',
273
+ category: 'Actions',
274
+ badge: 'EXPORT',
275
+ icon: '📥',
276
+ keywords: ['export', 'download', 'json', 'csv'],
277
+ action: () => {
278
+ toast('Please select a collection first to export records', 'info');
279
+ }
280
+ });
281
+ }
282
+
283
+ // 4. Actions: New Collection
284
+ items.push({
285
+ id: 'action-new-collection',
286
+ title: 'New Collection',
287
+ description: 'Create a new schema from scratch',
288
+ category: 'Actions',
289
+ badge: 'CREATE',
290
+ icon: '➕',
291
+ keywords: ['new', 'create', 'collection', 'add collection', 'new collection'],
292
+ action: () => {
293
+ if (typeof openNewCollectionModal === 'function') {
294
+ openNewCollectionModal();
295
+ }
296
+ }
297
+ });
298
+
299
+ items.push({
300
+ id: 'action-new-webhook',
301
+ title: 'New Webhook',
302
+ description: 'Configure an outbound HTTP webhook on collection events',
303
+ category: 'Actions',
304
+ badge: 'CREATE',
305
+ icon: '⚡',
306
+ keywords: ['new webhook', 'create webhook', 'webhook', 'outbound', 'signature'],
307
+ action: () => {
308
+ selectNav('webhooks');
309
+ setTimeout(() => {
310
+ if (typeof openCreateWebhookModal === 'function') openCreateWebhookModal();
311
+ }, 50);
312
+ }
313
+ });
314
+
315
+ // 5. Actions: Starter Templates
316
+ items.push({
317
+ id: 'action-templates',
318
+ title: 'Starter Templates',
319
+ description: 'Pre-seeded recipes (E-Commerce, Blog, CRM)',
320
+ category: 'Actions',
321
+ badge: 'RECIPE',
322
+ icon: '✨',
323
+ keywords: ['templates', 'starter templates', 'ecommerce', 'blog', 'crm', 'recipe'],
324
+ action: () => {
325
+ if (typeof openTemplatesModal === 'function') {
326
+ openTemplatesModal();
327
+ }
328
+ }
329
+ });
330
+
331
+ // 6. Actions: Import JSON
332
+ items.push({
333
+ id: 'action-import-json',
334
+ title: 'Import JSON Schema',
335
+ description: 'Generate database schema from JSON sample',
336
+ category: 'Actions',
337
+ badge: 'IMPORT',
338
+ icon: '📥',
339
+ keywords: ['import', 'json', 'schema', 'upload'],
340
+ action: () => {
341
+ if (typeof openImportJsonModal === 'function') {
342
+ openImportJsonModal();
343
+ }
344
+ }
345
+ });
346
+
347
+ // 7. Action: New Record (if collection active)
348
+ if (state.activeCollection) {
349
+ items.push({
350
+ id: 'action-new-record',
351
+ title: `Create Record in ${state.activeCollection.name}`,
352
+ description: `Insert a new row into ${state.activeCollection.name}`,
353
+ category: 'Actions',
354
+ badge: 'RECORD',
355
+ icon: '📝',
356
+ keywords: ['new record', 'create record', 'add record', 'insert', 'row'],
357
+ action: () => {
358
+ if (typeof openNewRecordModal === 'function') {
359
+ openNewRecordModal();
360
+ }
361
+ }
362
+ });
363
+ }
364
+
365
+ // 8. Action: OpenAPI Docs
366
+ items.push({
367
+ id: 'action-docs',
368
+ title: 'API Docs (OpenAPI)',
369
+ description: 'Interactive OpenAPI 3.0 Reference & testing sandbox',
370
+ category: 'Documentation',
371
+ badge: 'DOCS',
372
+ icon: '📖',
373
+ keywords: ['docs', 'openapi', 'swagger', 'api reference'],
374
+ action: () => {
375
+ if (typeof openDocsWithApp === 'function') {
376
+ openDocsWithApp();
377
+ } else {
378
+ const slug = (typeof getActiveAppSlug === 'function')
379
+ ? getActiveAppSlug()
380
+ : (state?.activeApp?.slug || (typeof state?.activeApp === 'string' ? state.activeApp : 'default'));
381
+ const app = slug && slug !== 'default' ? `?app=${encodeURIComponent(slug)}` : '';
382
+ window.open(`/_/docs${app}`, '_blank');
383
+ }
384
+ }
385
+ });
386
+
387
+
388
+ // 9. Appearance & Theme
389
+ items.push({
390
+ id: 'theme-system',
391
+ title: 'Theme: System (Auto)',
392
+ description: 'Sync admin appearance with your operating system preference',
393
+ category: 'Appearance',
394
+ badge: 'THEME',
395
+ icon: '💻',
396
+ keywords: ['theme', 'appearance', 'system', 'auto', 'mode', 'color'],
397
+ action: () => {
398
+ if (typeof setTheme === 'function') setTheme('system');
399
+ }
400
+ });
401
+
402
+ items.push({
403
+ id: 'theme-light',
404
+ title: 'Theme: Light Mode',
405
+ description: 'Switch admin portal to clean light appearance',
406
+ category: 'Appearance',
407
+ badge: 'THEME',
408
+ icon: '☀️',
409
+ keywords: ['theme', 'appearance', 'light', 'white', 'day', 'mode', 'color'],
410
+ action: () => {
411
+ if (typeof setTheme === 'function') setTheme('light');
412
+ }
413
+ });
414
+
415
+ items.push({
416
+ id: 'theme-dark',
417
+ title: 'Theme: Dark Mode',
418
+ description: 'Switch admin portal to dark night appearance',
419
+ category: 'Appearance',
420
+ badge: 'THEME',
421
+ icon: '🌙',
422
+ keywords: ['theme', 'appearance', 'dark', 'black', 'night', 'mode', 'color'],
423
+ action: () => {
424
+ if (typeof setTheme === 'function') setTheme('dark');
425
+ }
426
+ });
427
+
428
+ return items;
429
+ }
430
+
431
+ function filterCommandPaletteItems(query) {
432
+ const all = getAllCommandPaletteItems();
433
+ const q = (query || '').trim().toLowerCase();
434
+ if (!q) {
435
+ return all;
436
+ }
437
+
438
+ const scored = [];
439
+ for (const item of all) {
440
+ let score = 0;
441
+ const titleLower = item.title.toLowerCase();
442
+
443
+ if (titleLower === q) {
444
+ score += 100;
445
+ } else if (titleLower.startsWith(q)) {
446
+ score += 70;
447
+ } else if (titleLower.includes(q)) {
448
+ score += 40;
449
+ }
450
+
451
+ for (const kw of item.keywords || []) {
452
+ if (kw === q) {
453
+ score = Math.max(score, 90);
454
+ } else if (kw.startsWith(q)) {
455
+ score = Math.max(score, 60);
456
+ } else if (kw.includes(q)) {
457
+ score = Math.max(score, 30);
458
+ }
459
+ }
460
+
461
+ if (item.description && item.description.toLowerCase().includes(q)) {
462
+ score = Math.max(score, 20);
463
+ }
464
+
465
+ if (score > 0) {
466
+ scored.push({ item, score });
467
+ }
468
+ }
469
+
470
+ scored.sort((a, b) => b.score - a.score);
471
+ return scored.map(s => s.item);
472
+ }
473
+
474
+ function renderCommandPaletteResultsHtml(items, selectedIndex) {
475
+ if (!items || items.length === 0) {
476
+ return `<div class="command-palette-empty">No matching commands or collections found</div>`;
477
+ }
478
+
479
+ return items.map((item, idx) => `
480
+ <div
481
+ class="command-palette-item ${idx === selectedIndex ? 'selected' : ''}"
482
+ id="command-palette-item-${idx}"
483
+ onclick="executeCommandPaletteItem(${idx})"
484
+ onmouseenter="setCommandPaletteActiveIndex(${idx})"
485
+ data-index="${idx}"
486
+ role="option"
487
+ aria-selected="${idx === selectedIndex ? 'true' : 'false'}"
488
+ tabindex="-1"
489
+ >
490
+ <div class="command-palette-item-left">
491
+ <div class="command-palette-item-icon" aria-hidden="true">${item.icon || '▶'}</div>
492
+ <div class="command-palette-item-text">
493
+ <div class="command-palette-item-title">${escapeHtml(item.title)}</div>
494
+ <div class="command-palette-item-desc">${escapeHtml(item.description)}</div>
495
+ </div>
496
+ </div>
497
+ <div class="command-palette-item-badge">${escapeHtml(item.badge || item.category)}</div>
498
+ </div>
499
+ `).join('');
500
+ }
501
+
502
+ function openCommandPalette() {
503
+ commandPaletteActiveIndex = 0;
504
+ commandPaletteFilteredItems = filterCommandPaletteItems('');
505
+ const root = document.getElementById('command-palette-root');
506
+ if (!root) return;
507
+
508
+ root.innerHTML = `
509
+ <div class="command-palette-backdrop" id="command-palette-backdrop" onclick="handleCommandPaletteBackdrop(event)" onkeydown="if(event.key==='Escape'){event.preventDefault();event.stopPropagation();closeCommandPalette();}">
510
+ <div class="command-palette-modal" role="dialog" aria-modal="true" aria-label="Command Palette">
511
+ <div class="command-palette-header">
512
+ <svg class="command-palette-search-icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
513
+ <circle cx="11" cy="11" r="8"></circle>
514
+ <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
515
+ </svg>
516
+ <input
517
+ type="text"
518
+ id="command-palette-input"
519
+ class="command-palette-input"
520
+ placeholder="Type a command or jump to... (e.g. users, metrics, export, new)"
521
+ autocomplete="off"
522
+ spellcheck="false"
523
+ role="combobox"
524
+ aria-autocomplete="list"
525
+ aria-expanded="${commandPaletteFilteredItems.length > 0 ? 'true' : 'false'}"
526
+ aria-haspopup="listbox"
527
+ aria-controls="command-palette-results"
528
+ ${commandPaletteFilteredItems.length > 0 ? 'aria-activedescendant="command-palette-item-0"' : ''}
529
+ oninput="handleCommandPaletteInput(this.value)"
530
+ onkeydown="handleCommandPaletteKeyDown(event)"
531
+ />
532
+ <span class="command-palette-esc-badge" onclick="closeCommandPalette()" role="button" aria-label="Close command palette">ESC</span>
533
+ </div>
534
+ <div class="command-palette-results" id="command-palette-results" role="listbox" aria-label="Commands and collections">
535
+ ${renderCommandPaletteResultsHtml(commandPaletteFilteredItems, 0)}
536
+ </div>
537
+ <div class="command-palette-footer">
538
+ <div class="command-palette-footer-shortcuts">
539
+ <span><kbd class="palette-kbd">↑</kbd><kbd class="palette-kbd">↓</kbd> navigate</span>
540
+ <span><kbd class="palette-kbd">↵</kbd> select</span>
541
+ <span><kbd class="palette-kbd">esc</kbd> close</span>
542
+ </div>
543
+ <div style="font-size:10px; opacity:0.7;">NodeStack Quick Jump</div>
544
+ </div>
545
+ </div>
546
+ </div>
547
+ `;
548
+
549
+ setTimeout(() => {
550
+ const input = document.getElementById('command-palette-input');
551
+ if (input) input.focus();
552
+ }, 20);
553
+ }
554
+
555
+ function closeCommandPalette() {
556
+ const root = document.getElementById('command-palette-root');
557
+ if (root) root.innerHTML = '';
558
+ }
559
+
560
+ function handleCommandPaletteBackdrop(e) {
561
+ if (e.target && e.target.id === 'command-palette-backdrop') {
562
+ closeCommandPalette();
563
+ }
564
+ }
565
+
566
+ function toggleCommandPalette() {
567
+ const root = document.getElementById('command-palette-root');
568
+ if (root && root.innerHTML.trim().length > 0) {
569
+ closeCommandPalette();
570
+ } else {
571
+ openCommandPalette();
572
+ }
573
+ }
574
+
575
+ function handleCommandPaletteInput(val) {
576
+ commandPaletteActiveIndex = 0;
577
+ commandPaletteFilteredItems = filterCommandPaletteItems(val);
578
+ const container = document.getElementById('command-palette-results');
579
+ const input = document.getElementById('command-palette-input');
580
+
581
+ if (container) {
582
+ container.innerHTML = renderCommandPaletteResultsHtml(commandPaletteFilteredItems, 0);
583
+ }
584
+
585
+ if (input) {
586
+ if (commandPaletteFilteredItems.length > 0) {
587
+ input.setAttribute('aria-expanded', 'true');
588
+ input.setAttribute('aria-activedescendant', 'command-palette-item-0');
589
+ } else {
590
+ input.setAttribute('aria-expanded', 'false');
591
+ input.removeAttribute('aria-activedescendant');
592
+ }
593
+ }
594
+ }
595
+
596
+ function handleCommandPaletteKeyDown(e) {
597
+ if (e.key === 'ArrowDown') {
598
+ e.preventDefault();
599
+ if (commandPaletteFilteredItems.length > 0) {
600
+ commandPaletteActiveIndex = (commandPaletteActiveIndex + 1) % commandPaletteFilteredItems.length;
601
+ updateCommandPaletteActiveItem();
602
+ }
603
+ } else if (e.key === 'ArrowUp') {
604
+ e.preventDefault();
605
+ if (commandPaletteFilteredItems.length > 0) {
606
+ commandPaletteActiveIndex = (commandPaletteActiveIndex - 1 + commandPaletteFilteredItems.length) % commandPaletteFilteredItems.length;
607
+ updateCommandPaletteActiveItem();
608
+ }
609
+ } else if (e.key === 'Enter') {
610
+ e.preventDefault();
611
+ executeCommandPaletteItem(commandPaletteActiveIndex);
612
+ } else if (e.key === 'Escape') {
613
+ e.preventDefault();
614
+ e.stopPropagation();
615
+ closeCommandPalette();
616
+ }
617
+ }
618
+
619
+ function updateCommandPaletteActiveItem() {
620
+ const input = document.getElementById('command-palette-input');
621
+ const items = document.querySelectorAll('.command-palette-item');
622
+ let activeId = null;
623
+
624
+ items.forEach((el, idx) => {
625
+ if (idx === commandPaletteActiveIndex) {
626
+ el.classList.add('selected');
627
+ el.setAttribute('aria-selected', 'true');
628
+ activeId = el.id;
629
+ if (typeof el.scrollIntoView === 'function') {
630
+ el.scrollIntoView({ block: 'nearest' });
631
+ }
632
+ } else {
633
+ el.classList.remove('selected');
634
+ el.setAttribute('aria-selected', 'false');
635
+ }
636
+ });
637
+
638
+ if (input) {
639
+ if (activeId) {
640
+ input.setAttribute('aria-activedescendant', activeId);
641
+ } else {
642
+ input.removeAttribute('aria-activedescendant');
643
+ }
644
+ }
645
+ }
646
+
647
+ function setCommandPaletteActiveIndex(idx) {
648
+ commandPaletteActiveIndex = idx;
649
+ const input = document.getElementById('command-palette-input');
650
+ const items = document.querySelectorAll('.command-palette-item');
651
+ let activeId = null;
652
+
653
+ items.forEach((el, i) => {
654
+ if (i === idx) {
655
+ el.classList.add('selected');
656
+ el.setAttribute('aria-selected', 'true');
657
+ activeId = el.id;
658
+ } else {
659
+ el.classList.remove('selected');
660
+ el.setAttribute('aria-selected', 'false');
661
+ }
662
+ });
663
+
664
+ if (input) {
665
+ if (activeId) {
666
+ input.setAttribute('aria-activedescendant', activeId);
667
+ } else {
668
+ input.removeAttribute('aria-activedescendant');
669
+ }
670
+ }
671
+ }
672
+
673
+ function executeCommandPaletteItem(index) {
674
+ const item = commandPaletteFilteredItems[index];
675
+ if (!item) return;
676
+ closeCommandPalette();
677
+ if (typeof item.action === 'function') {
678
+ item.action();
679
+ }
680
+ }
681
+
682
+ // Expose helpers on window for browser event handlers & tests
683
+ if (typeof window !== 'undefined') {
684
+ window.openCommandPalette = openCommandPalette;
685
+ window.closeCommandPalette = closeCommandPalette;
686
+ window.toggleCommandPalette = toggleCommandPalette;
687
+ window.getAllCommandPaletteItems = getAllCommandPaletteItems;
688
+ window.filterCommandPaletteItems = filterCommandPaletteItems;
689
+ window.executeCommandPaletteItem = executeCommandPaletteItem;
690
+ window.handleCommandPaletteInput = handleCommandPaletteInput;
691
+ window.handleCommandPaletteKeyDown = handleCommandPaletteKeyDown;
692
+ window.setCommandPaletteActiveIndex = setCommandPaletteActiveIndex;
693
+ }