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