@nodestackapp/server 2.0.0 → 2.1.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.
- package/README.md +4 -3
- package/dist/NodeStack.d.ts +9 -0
- package/dist/NodeStack.d.ts.map +1 -1
- package/dist/NodeStack.js +24 -3
- package/dist/NodeStack.js.map +1 -1
- package/dist/admin/AdminUIBundler.d.ts.map +1 -1
- package/dist/admin/AdminUIBundler.js +9 -5
- package/dist/admin/AdminUIBundler.js.map +1 -1
- package/dist/admin/ui/css/codemirror.css +98 -0
- package/dist/admin/ui/css/main.css +2309 -2189
- package/dist/admin/ui/index.html +8331 -5295
- package/dist/admin/ui/js/api.js +44 -14
- package/dist/admin/ui/js/app.js +480 -254
- package/dist/admin/ui/js/apps.js +29 -14
- package/dist/admin/ui/js/codemirror.js +15 -0
- package/dist/admin/ui/js/collections.js +38 -9
- package/dist/admin/ui/js/command-palette.js +12 -1
- package/dist/admin/ui/js/functions-tester.js +432 -0
- package/dist/admin/ui/js/functions-workbench.js +1038 -0
- package/dist/admin/ui/js/functions.js +765 -0
- package/dist/admin/ui/js/modals.js +6 -2
- package/dist/admin/ui/js/plugin-tester.js +562 -559
- package/dist/admin/ui/js/plugins.js +198 -77
- package/dist/admin/ui/js/records.js +89 -54
- package/dist/admin/ui/js/schema.js +23 -9
- package/dist/admin/ui/js/views.js +82 -34
- package/dist/admin/ui/js/webhooks.js +1111 -1104
- package/dist/apps/AppScope.d.ts +4 -0
- package/dist/apps/AppScope.d.ts.map +1 -1
- package/dist/apps/AppScope.js +33 -1
- package/dist/apps/AppScope.js.map +1 -1
- package/dist/auth/ApiKeyService.d.ts +91 -0
- package/dist/auth/ApiKeyService.d.ts.map +1 -0
- package/dist/auth/ApiKeyService.js +414 -0
- package/dist/auth/ApiKeyService.js.map +1 -0
- package/dist/auth/AuthService.d.ts +33 -1
- package/dist/auth/AuthService.d.ts.map +1 -1
- package/dist/auth/AuthService.js +219 -1
- package/dist/auth/AuthService.js.map +1 -1
- package/dist/auth/oauth/AppleProvider.d.ts +23 -0
- package/dist/auth/oauth/AppleProvider.d.ts.map +1 -0
- package/dist/auth/oauth/AppleProvider.js +161 -0
- package/dist/auth/oauth/AppleProvider.js.map +1 -0
- package/dist/auth/oauth/BaseOAuthProvider.d.ts +18 -0
- package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -0
- package/dist/auth/oauth/BaseOAuthProvider.js +79 -0
- package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -0
- package/dist/auth/oauth/DiscordProvider.d.ts +11 -0
- package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -0
- package/dist/auth/oauth/DiscordProvider.js +47 -0
- package/dist/auth/oauth/DiscordProvider.js.map +1 -0
- package/dist/auth/oauth/GitHubProvider.d.ts +13 -0
- package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -0
- package/dist/auth/oauth/GitHubProvider.js +90 -0
- package/dist/auth/oauth/GitHubProvider.js.map +1 -0
- package/dist/auth/oauth/GoogleProvider.d.ts +11 -0
- package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -0
- package/dist/auth/oauth/GoogleProvider.js +43 -0
- package/dist/auth/oauth/GoogleProvider.js.map +1 -0
- package/dist/auth/oauth/MicrosoftProvider.d.ts +11 -0
- package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -0
- package/dist/auth/oauth/MicrosoftProvider.js +83 -0
- package/dist/auth/oauth/MicrosoftProvider.js.map +1 -0
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts +32 -0
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -0
- package/dist/auth/oauth/OAuthProviderRegistry.js +232 -0
- package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -0
- package/dist/auth/oauth/types.d.ts +63 -0
- package/dist/auth/oauth/types.d.ts.map +1 -0
- package/dist/auth/oauth/types.js +3 -0
- package/dist/auth/oauth/types.js.map +1 -0
- package/dist/cli/cli.js +10 -10
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/container/Tokens.d.ts +2 -0
- package/dist/core/container/Tokens.d.ts.map +1 -1
- package/dist/core/container/Tokens.js +2 -0
- package/dist/core/container/Tokens.js.map +1 -1
- package/dist/core/plugins/PluginManager.d.ts.map +1 -1
- package/dist/core/plugins/PluginManager.js +73 -19
- package/dist/core/plugins/PluginManager.js.map +1 -1
- package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
- package/dist/database/migrations/SystemMigrations.js +40 -0
- package/dist/database/migrations/SystemMigrations.js.map +1 -1
- package/dist/functions/FunctionService.d.ts +80 -0
- package/dist/functions/FunctionService.d.ts.map +1 -0
- package/dist/functions/FunctionService.js +610 -0
- package/dist/functions/FunctionService.js.map +1 -0
- package/dist/functions/runtime/IFunctionRuntime.d.ts +23 -0
- package/dist/functions/runtime/IFunctionRuntime.d.ts.map +1 -0
- package/dist/functions/runtime/IFunctionRuntime.js +3 -0
- package/dist/functions/runtime/IFunctionRuntime.js.map +1 -0
- package/dist/functions/runtime/QuickJsWasmRuntime.d.ts +21 -0
- package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -0
- package/dist/functions/runtime/QuickJsWasmRuntime.js +418 -0
- package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -0
- package/dist/functions/runtime/SandboxedRunner.d.ts +31 -0
- package/dist/functions/runtime/SandboxedRunner.d.ts.map +1 -0
- package/dist/functions/runtime/SandboxedRunner.js +61 -0
- package/dist/functions/runtime/SandboxedRunner.js.map +1 -0
- package/dist/functions/security/SsrfGuard.d.ts +41 -0
- package/dist/functions/security/SsrfGuard.d.ts.map +1 -0
- package/dist/functions/security/SsrfGuard.js +470 -0
- package/dist/functions/security/SsrfGuard.js.map +1 -0
- package/dist/functions/types.d.ts +109 -0
- package/dist/functions/types.d.ts.map +1 -0
- package/dist/functions/types.js +3 -0
- package/dist/functions/types.js.map +1 -0
- package/dist/http/HttpServer.d.ts +7 -1
- package/dist/http/HttpServer.d.ts.map +1 -1
- package/dist/http/HttpServer.js +66 -1
- package/dist/http/HttpServer.js.map +1 -1
- package/dist/http/controllers/ApiKeyController.d.ts +31 -0
- package/dist/http/controllers/ApiKeyController.d.ts.map +1 -0
- package/dist/http/controllers/ApiKeyController.js +52 -0
- package/dist/http/controllers/ApiKeyController.js.map +1 -0
- package/dist/http/controllers/AuthController.d.ts +29 -1
- package/dist/http/controllers/AuthController.d.ts.map +1 -1
- package/dist/http/controllers/AuthController.js +42 -1
- package/dist/http/controllers/AuthController.js.map +1 -1
- package/dist/http/controllers/FunctionController.d.ts +64 -0
- package/dist/http/controllers/FunctionController.d.ts.map +1 -0
- package/dist/http/controllers/FunctionController.js +202 -0
- package/dist/http/controllers/FunctionController.js.map +1 -0
- package/dist/http/controllers/RecordController.d.ts.map +1 -1
- package/dist/http/controllers/RecordController.js +4 -0
- package/dist/http/controllers/RecordController.js.map +1 -1
- package/dist/http/middleware/AuthMiddleware.d.ts +6 -1
- package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
- package/dist/http/middleware/AuthMiddleware.js +79 -8
- package/dist/http/middleware/AuthMiddleware.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/plugins/chat-notifications.d.ts +51 -0
- package/dist/plugins/chat-notifications.d.ts.map +1 -0
- package/dist/plugins/chat-notifications.js +545 -0
- package/dist/plugins/chat-notifications.js.map +1 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/webhooks.d.ts +5 -34
- package/dist/plugins/webhooks.d.ts.map +1 -1
- package/dist/plugins/webhooks.js +11 -412
- package/dist/plugins/webhooks.js.map +1 -1
- package/dist/records/MockDataService.d.ts.map +1 -1
- package/dist/records/MockDataService.js +3 -0
- package/dist/records/MockDataService.js.map +1 -1
- package/dist/records/RecordService.d.ts.map +1 -1
- package/dist/records/RecordService.js +39 -30
- package/dist/records/RecordService.js.map +1 -1
- package/dist/records/RecordValidator.d.ts +6 -0
- package/dist/records/RecordValidator.d.ts.map +1 -0
- package/dist/records/RecordValidator.js +100 -0
- package/dist/records/RecordValidator.js.map +1 -0
- package/package.json +89 -88
package/dist/admin/ui/js/app.js
CHANGED
|
@@ -1,254 +1,480 @@
|
|
|
1
|
-
// Application Navigation & Lifecycle
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
} else
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (typeof
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
1
|
+
// Application Navigation & Lifecycle
|
|
2
|
+
|
|
3
|
+
// URL Routing, Deep Linking & History API
|
|
4
|
+
|
|
5
|
+
function getAppQueryParam() {
|
|
6
|
+
if (typeof window === 'undefined' || !window.location) return '';
|
|
7
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
8
|
+
const activeSlug = getActiveAppSlug();
|
|
9
|
+
if (activeSlug && activeSlug !== 'default') {
|
|
10
|
+
searchParams.set('app', activeSlug);
|
|
11
|
+
} else {
|
|
12
|
+
searchParams.delete('app');
|
|
13
|
+
}
|
|
14
|
+
const q = searchParams.toString();
|
|
15
|
+
return q ? `?${q}` : '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function updateUrl(targetPath, replace = false) {
|
|
19
|
+
if (typeof window === 'undefined' || !window.history || !window.location) return;
|
|
20
|
+
const targetUrl = targetPath + getAppQueryParam();
|
|
21
|
+
const currentUrl = window.location.pathname + window.location.search;
|
|
22
|
+
if (currentUrl === targetUrl) return;
|
|
23
|
+
|
|
24
|
+
if (replace) {
|
|
25
|
+
window.history.replaceState({ path: targetPath }, '', targetUrl);
|
|
26
|
+
} else {
|
|
27
|
+
window.history.pushState({ path: targetPath }, '', targetUrl);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function parseUrlAndNavigate(initial = false) {
|
|
32
|
+
if (typeof window === 'undefined' || !window.location) return;
|
|
33
|
+
|
|
34
|
+
// Resolve and synchronize active application from URL query parameter (?app=<slugOrId>)
|
|
35
|
+
const searchParams = new URLSearchParams(window.location.search || '');
|
|
36
|
+
const requestedAppSlug = searchParams.get('app');
|
|
37
|
+
|
|
38
|
+
if (requestedAppSlug) {
|
|
39
|
+
let targetApp = (state.apps || []).find(a => a.slug === requestedAppSlug || a.id === requestedAppSlug || (requestedAppSlug === 'default' && a.isDefault));
|
|
40
|
+
if (!targetApp) {
|
|
41
|
+
try {
|
|
42
|
+
await fetchApps();
|
|
43
|
+
targetApp = (state.apps || []).find(a => a.slug === requestedAppSlug || a.id === requestedAppSlug || (requestedAppSlug === 'default' && a.isDefault));
|
|
44
|
+
} catch (_) {}
|
|
45
|
+
}
|
|
46
|
+
const currentSlug = getActiveAppSlug();
|
|
47
|
+
if (targetApp && currentSlug !== targetApp.slug) {
|
|
48
|
+
state.activeApp = targetApp;
|
|
49
|
+
try {
|
|
50
|
+
localStorage.setItem('nodestack_active_app', JSON.stringify(targetApp));
|
|
51
|
+
} catch (_) {}
|
|
52
|
+
updateAppSwitcherUI();
|
|
53
|
+
updateDocsLinks(targetApp.slug);
|
|
54
|
+
try {
|
|
55
|
+
await loadCollections();
|
|
56
|
+
} catch (_) {}
|
|
57
|
+
}
|
|
58
|
+
} else if (!initial && state.activeApp && state.activeApp.slug !== 'default') {
|
|
59
|
+
// Navigating back/forward (popstate) to a route without ?app= query parameter; restore default app
|
|
60
|
+
const defaultApp = (state.apps || []).find(a => a.isDefault || a.slug === 'default') || { id: 'app_default', slug: 'default', name: 'Default App', isDefault: true };
|
|
61
|
+
if (state.activeApp.slug !== defaultApp.slug) {
|
|
62
|
+
state.activeApp = defaultApp;
|
|
63
|
+
try {
|
|
64
|
+
localStorage.setItem('nodestack_active_app', JSON.stringify(defaultApp));
|
|
65
|
+
} catch (_) {}
|
|
66
|
+
updateAppSwitcherUI();
|
|
67
|
+
updateDocsLinks(defaultApp.slug);
|
|
68
|
+
try {
|
|
69
|
+
await loadCollections();
|
|
70
|
+
} catch (_) {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const pathname = window.location.pathname || '/';
|
|
75
|
+
|
|
76
|
+
// Normalise route:
|
|
77
|
+
// e.g. '/_/' -> ''
|
|
78
|
+
// '/_/collections' -> 'collections'
|
|
79
|
+
// '/_/collections/users/schema' -> 'collections/users/schema'
|
|
80
|
+
let route = pathname;
|
|
81
|
+
if (route.startsWith('/_')) {
|
|
82
|
+
route = route.slice(2);
|
|
83
|
+
}
|
|
84
|
+
if (route.startsWith('/')) {
|
|
85
|
+
route = route.slice(1);
|
|
86
|
+
}
|
|
87
|
+
if (route.endsWith('/')) {
|
|
88
|
+
route = route.slice(0, -1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const parts = route ? route.split('/').map(p => decodeURIComponent(p)) : [];
|
|
92
|
+
|
|
93
|
+
if (parts.length === 0 || parts[0] === 'home') {
|
|
94
|
+
await selectNav('home', false);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const root = parts[0];
|
|
99
|
+
|
|
100
|
+
if (root === 'collections') {
|
|
101
|
+
if (parts.length === 1) {
|
|
102
|
+
await selectNav('collections', false);
|
|
103
|
+
} else {
|
|
104
|
+
const colName = parts[1];
|
|
105
|
+
const tab = (parts[2] === 'schema') ? 'schema' : 'records';
|
|
106
|
+
const allCols = Array.isArray(state.collections)
|
|
107
|
+
? state.collections
|
|
108
|
+
: (state.collections && Array.isArray(state.collections.items) ? state.collections.items : []);
|
|
109
|
+
const colExists = allCols.some(c => c.name === colName);
|
|
110
|
+
if (colExists) {
|
|
111
|
+
state.collectionTab = tab;
|
|
112
|
+
await selectCollection(colName, false);
|
|
113
|
+
if (tab === 'schema') {
|
|
114
|
+
switchCollectionTab('schema', false);
|
|
115
|
+
} else {
|
|
116
|
+
switchCollectionTab('records', false);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
await selectNav('collections', false);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else if (root === 'functions') {
|
|
123
|
+
await selectNav('functions', false);
|
|
124
|
+
if (parts.length >= 2 && parts[1] && parts[1] !== 'logs') {
|
|
125
|
+
if (typeof openFunctionEditor === 'function') {
|
|
126
|
+
await openFunctionEditor(parts[1], false);
|
|
127
|
+
}
|
|
128
|
+
} else if (parts[1] === 'logs') {
|
|
129
|
+
if (typeof switchFunctionsTab === 'function') switchFunctionsTab('logs', false);
|
|
130
|
+
} else {
|
|
131
|
+
if (typeof switchFunctionsTab === 'function') switchFunctionsTab('functions', false);
|
|
132
|
+
}
|
|
133
|
+
} else if (root === 'webhooks') {
|
|
134
|
+
await selectNav('webhooks', false);
|
|
135
|
+
if (parts[1] === 'deliveries') {
|
|
136
|
+
if (typeof switchWebhooksTab === 'function') switchWebhooksTab('deliveries', false);
|
|
137
|
+
} else {
|
|
138
|
+
if (typeof switchWebhooksTab === 'function') switchWebhooksTab('webhooks', false);
|
|
139
|
+
}
|
|
140
|
+
} else if (root === 'plugins') {
|
|
141
|
+
if (parts.length >= 2 && state.pluginNavItems && state.pluginNavItems.some(p => p.id === parts[1])) {
|
|
142
|
+
await selectNav(parts[1], false);
|
|
143
|
+
} else {
|
|
144
|
+
await selectNav('plugins', false);
|
|
145
|
+
}
|
|
146
|
+
} else if (root === 'analytics') {
|
|
147
|
+
await selectNav('analytics', false);
|
|
148
|
+
} else if (root === 'snapshots') {
|
|
149
|
+
await selectNav('snapshots', false);
|
|
150
|
+
} else if (root === 'logs') {
|
|
151
|
+
await selectNav('logs', false);
|
|
152
|
+
if (parts[1] === 'audit') {
|
|
153
|
+
if (typeof switchLogsSubTab === 'function') switchLogsSubTab('audit', false);
|
|
154
|
+
} else {
|
|
155
|
+
if (typeof switchLogsSubTab === 'function') switchLogsSubTab('traffic', false);
|
|
156
|
+
}
|
|
157
|
+
} else if (state.pluginNavItems && state.pluginNavItems.some(p => p.id === root)) {
|
|
158
|
+
await selectNav(root, false);
|
|
159
|
+
} else {
|
|
160
|
+
await selectNav('home', false);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let isRouterInitialized = false;
|
|
165
|
+
|
|
166
|
+
function initRouter() {
|
|
167
|
+
if (typeof window === 'undefined' || isRouterInitialized) return;
|
|
168
|
+
isRouterInitialized = true;
|
|
169
|
+
|
|
170
|
+
window.addEventListener('popstate', async () => {
|
|
171
|
+
// Gracefully dismiss open modals, drawers, or command palette on Back/Forward navigation
|
|
172
|
+
if (typeof closeModal === 'function') closeModal();
|
|
173
|
+
if (typeof closeRecordDrawer === 'function') closeRecordDrawer();
|
|
174
|
+
if (typeof closeWebhookModal === 'function') closeWebhookModal();
|
|
175
|
+
if (typeof closeWebhookDrawer === 'function') closeWebhookDrawer();
|
|
176
|
+
if (typeof closeFunctionModal === 'function') closeFunctionModal();
|
|
177
|
+
if (typeof closeCommandPalette === 'function') closeCommandPalette();
|
|
178
|
+
|
|
179
|
+
await parseUrlAndNavigate(false);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
function showPageView(viewName) {
|
|
185
|
+
const views = ['home', 'collections', 'plugins', 'webhooks', 'functions', 'analytics', 'snapshots', 'logs'];
|
|
186
|
+
for (const v of views) {
|
|
187
|
+
const el = document.getElementById('page-view-' + v);
|
|
188
|
+
if (el) {
|
|
189
|
+
if (v === 'collections' || v === 'plugins') {
|
|
190
|
+
el.style.display = (v === viewName) ? 'flex' : 'none';
|
|
191
|
+
} else {
|
|
192
|
+
el.style.display = (v === viewName) ? 'block' : 'none';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function clearSidebarNavActive() {
|
|
199
|
+
const navIds = ['nav-home', 'nav-collections', 'nav-plugins', 'nav-webhooks', 'nav-functions', 'nav-analytics', 'nav-snapshots', 'nav-logs'];
|
|
200
|
+
for (const id of navIds) {
|
|
201
|
+
document.getElementById(id)?.classList.remove('active');
|
|
202
|
+
}
|
|
203
|
+
if (state.pluginNavItems && Array.isArray(state.pluginNavItems)) {
|
|
204
|
+
for (const item of state.pluginNavItems) {
|
|
205
|
+
document.getElementById('nav-' + item.id)?.classList.remove('active');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
document.querySelectorAll('.sidebar-nav-item.active').forEach(el => el.classList.remove('active'));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function selectNav(nav, pushState = true) {
|
|
212
|
+
state.activeNav = nav;
|
|
213
|
+
|
|
214
|
+
if (typeof stopAnalyticsAutoRefresh === 'function') {
|
|
215
|
+
stopAnalyticsAutoRefresh();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
clearSidebarNavActive();
|
|
219
|
+
|
|
220
|
+
const colActions = document.getElementById('collection-actions');
|
|
221
|
+
if (colActions && nav !== 'collection') {
|
|
222
|
+
colActions.innerHTML = '';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (nav === 'home') {
|
|
226
|
+
state.activeCollection = null;
|
|
227
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
228
|
+
showPageView('home');
|
|
229
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
230
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
231
|
+
document.getElementById('nav-home')?.classList.add('active');
|
|
232
|
+
document.getElementById('view-title').textContent = 'Overview';
|
|
233
|
+
document.getElementById('view-actions').innerHTML = '';
|
|
234
|
+
if (typeof renderHomeView === 'function') renderHomeView();
|
|
235
|
+
} else if (nav === 'collections') {
|
|
236
|
+
state.activeCollection = null;
|
|
237
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
238
|
+
showPageView('collections');
|
|
239
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
240
|
+
document.getElementById('nav-collections')?.classList.add('active');
|
|
241
|
+
document.getElementById('view-title').textContent = 'Collections';
|
|
242
|
+
document.getElementById('view-title').style.display = 'inline-block';
|
|
243
|
+
const count = state.collections ? state.collections.length : 0;
|
|
244
|
+
const badgeEl = document.getElementById('view-badge');
|
|
245
|
+
badgeEl.textContent = count + ' Tables';
|
|
246
|
+
badgeEl.className = 'badge badge-get';
|
|
247
|
+
badgeEl.style.display = 'inline-block';
|
|
248
|
+
document.getElementById('view-actions').innerHTML = '';
|
|
249
|
+
if (typeof renderCollectionsHubView === 'function') renderCollectionsHubView();
|
|
250
|
+
} else if (nav === 'plugins') {
|
|
251
|
+
state.activeCollection = null;
|
|
252
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
253
|
+
showPageView('plugins');
|
|
254
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
255
|
+
document.getElementById('nav-plugins')?.classList.add('active');
|
|
256
|
+
document.getElementById('view-title').textContent = 'Plugins';
|
|
257
|
+
document.getElementById('view-title').style.display = 'inline-block';
|
|
258
|
+
const pCount = (state.pluginNavItems || []).length;
|
|
259
|
+
const badgeEl = document.getElementById('view-badge');
|
|
260
|
+
badgeEl.textContent = pCount + ' Active';
|
|
261
|
+
badgeEl.className = 'badge badge-primary';
|
|
262
|
+
badgeEl.style.display = pCount > 0 ? 'inline-block' : 'none';
|
|
263
|
+
document.getElementById('view-actions').innerHTML = `
|
|
264
|
+
<a href="/_/docs" target="_blank" onclick="openDocsWithApp(event)" class="btn btn-secondary btn-sm" style="text-decoration:none;">OpenAPI Specs ↗</a>
|
|
265
|
+
`;
|
|
266
|
+
if (typeof renderPluginNavItems === 'function') renderPluginNavItems();
|
|
267
|
+
if (typeof renderPluginsHubView === 'function') renderPluginsHubView();
|
|
268
|
+
} else if (nav === 'webhooks') {
|
|
269
|
+
state.activeCollection = null;
|
|
270
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
271
|
+
showPageView('webhooks');
|
|
272
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
273
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
274
|
+
document.getElementById('nav-webhooks')?.classList.add('active');
|
|
275
|
+
document.getElementById('view-title').textContent = 'Webhooks Manager';
|
|
276
|
+
document.getElementById('view-title').style.display = 'none';
|
|
277
|
+
document.getElementById('view-actions').innerHTML = '';
|
|
278
|
+
if (typeof renderWebhooksView === 'function') renderWebhooksView();
|
|
279
|
+
} else if (nav === 'functions') {
|
|
280
|
+
state.activeCollection = null;
|
|
281
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
282
|
+
showPageView('functions');
|
|
283
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
284
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
285
|
+
document.getElementById('nav-functions')?.classList.add('active');
|
|
286
|
+
document.getElementById('view-title').textContent = 'Functions';
|
|
287
|
+
document.getElementById('view-title').style.display = 'none';
|
|
288
|
+
document.getElementById('view-actions').innerHTML = '';
|
|
289
|
+
if (typeof renderFunctionsView === 'function') renderFunctionsView();
|
|
290
|
+
} else if (nav === 'analytics') {
|
|
291
|
+
state.activeCollection = null;
|
|
292
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
293
|
+
showPageView('analytics');
|
|
294
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
295
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
296
|
+
document.getElementById('nav-analytics')?.classList.add('active');
|
|
297
|
+
document.getElementById('view-title').textContent = 'Analytics';
|
|
298
|
+
document.getElementById('view-actions').innerHTML = '';
|
|
299
|
+
if (typeof renderAnalyticsView === 'function') renderAnalyticsView();
|
|
300
|
+
if (typeof loadAnalytics === 'function') loadAnalytics();
|
|
301
|
+
if (typeof analyticsState !== 'undefined' && analyticsState.autoRefreshEnabled && typeof startAnalyticsAutoRefresh === 'function') {
|
|
302
|
+
startAnalyticsAutoRefresh();
|
|
303
|
+
}
|
|
304
|
+
} else if (nav === 'snapshots') {
|
|
305
|
+
state.activeCollection = null;
|
|
306
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
307
|
+
showPageView('snapshots');
|
|
308
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
309
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
310
|
+
document.getElementById('nav-snapshots')?.classList.add('active');
|
|
311
|
+
document.getElementById('view-title').textContent = 'Snapshots';
|
|
312
|
+
document.getElementById('view-actions').innerHTML = `
|
|
313
|
+
<button class="btn btn-primary btn-sm" onclick="openCreateSnapshotModal()" style="font-weight:600;">
|
|
314
|
+
+ Create Snapshot
|
|
315
|
+
</button>
|
|
316
|
+
`;
|
|
317
|
+
if (typeof renderSnapshotsView === 'function') renderSnapshotsView();
|
|
318
|
+
} else if (nav === 'logs') {
|
|
319
|
+
state.activeCollection = null;
|
|
320
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
321
|
+
showPageView('logs');
|
|
322
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
323
|
+
document.getElementById('view-badge').style.display = 'none';
|
|
324
|
+
document.getElementById('nav-logs')?.classList.add('active');
|
|
325
|
+
document.getElementById('view-title').textContent = 'Audit Logs';
|
|
326
|
+
if (typeof renderLogsView === 'function') renderLogsView();
|
|
327
|
+
if (typeof loadLogsSubTab === 'function') {
|
|
328
|
+
loadLogsSubTab();
|
|
329
|
+
} else if (typeof loadLogs === 'function') {
|
|
330
|
+
loadLogs();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
} else if (state.pluginNavItems && state.pluginNavItems.some(p => p.id === nav || (nav === 'resend' && p.id === 'resend-email'))) {
|
|
334
|
+
state.activeCollection = null;
|
|
335
|
+
if (typeof renderCollectionsList === 'function') renderCollectionsList();
|
|
336
|
+
showPageView('plugins');
|
|
337
|
+
document.getElementById('collection-tabs').style.display = 'none';
|
|
338
|
+
document.getElementById('nav-plugins')?.classList.add('active');
|
|
339
|
+
document.getElementById('nav-' + nav)?.classList.add('active');
|
|
340
|
+
const pluginItem = state.pluginNavItems.find(p => p.id === nav || (nav === 'resend' && p.id === 'resend-email'));
|
|
341
|
+
if (typeof renderPluginView === 'function') renderPluginView(pluginItem);
|
|
342
|
+
}
|
|
343
|
+
if (typeof updateBreadcrumbs === 'function') updateBreadcrumbs();
|
|
344
|
+
|
|
345
|
+
if (pushState) {
|
|
346
|
+
if (nav === 'home') {
|
|
347
|
+
updateUrl('/_/');
|
|
348
|
+
} else if (nav === 'collections') {
|
|
349
|
+
updateUrl('/_/collections');
|
|
350
|
+
} else if (nav === 'webhooks') {
|
|
351
|
+
const sub = (typeof webhooksState !== 'undefined' && webhooksState.subTab === 'deliveries') ? '/deliveries' : '';
|
|
352
|
+
updateUrl('/_/webhooks' + sub);
|
|
353
|
+
} else if (nav === 'functions') {
|
|
354
|
+
const sub = (typeof functionsState !== 'undefined' && functionsState.currentView === 'editor' && functionsState.activeFunctionForEdit)
|
|
355
|
+
? '/' + (functionsState.activeFunctionForEdit.isNew ? 'new' : encodeURIComponent(functionsState.activeFunctionForEdit.name || functionsState.activeFunctionForEdit.id))
|
|
356
|
+
: (typeof functionsState !== 'undefined' && functionsState.subTab === 'logs') ? '/logs' : '';
|
|
357
|
+
updateUrl('/_/functions' + sub);
|
|
358
|
+
} else if (nav === 'analytics') {
|
|
359
|
+
updateUrl('/_/analytics');
|
|
360
|
+
} else if (nav === 'snapshots') {
|
|
361
|
+
updateUrl('/_/snapshots');
|
|
362
|
+
} else if (nav === 'logs') {
|
|
363
|
+
const sub = (typeof auditState !== 'undefined' && auditState.subTab === 'audit') ? '/audit' : '';
|
|
364
|
+
updateUrl('/_/logs' + sub);
|
|
365
|
+
} else if (nav === 'plugins') {
|
|
366
|
+
updateUrl('/_/plugins');
|
|
367
|
+
} else if (state.pluginNavItems && state.pluginNavItems.some(p => p.id === nav || (nav === 'resend' && p.id === 'resend-email'))) {
|
|
368
|
+
updateUrl('/_/plugins/' + encodeURIComponent(nav));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Close dropdown menu when clicking outside
|
|
374
|
+
window.addEventListener('click', (e) => {
|
|
375
|
+
const menu = document.getElementById('collection-create-menu');
|
|
376
|
+
if (menu && !e.target.closest('#btn-collection-new-dropdown') && !e.target.closest('#collection-create-menu')) {
|
|
377
|
+
menu.style.display = 'none';
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Global Keydown shortcuts: Ctrl+K / Cmd+K and Escape
|
|
382
|
+
window.addEventListener('keydown', (e) => {
|
|
383
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === 'k' || e.key === 'K')) {
|
|
384
|
+
e.preventDefault();
|
|
385
|
+
if (typeof toggleCommandPalette === 'function') {
|
|
386
|
+
toggleCommandPalette();
|
|
387
|
+
}
|
|
388
|
+
} else if (e.key === 'Escape') {
|
|
389
|
+
if (typeof closeCollectionCreateMenu === 'function') {
|
|
390
|
+
closeCollectionCreateMenu();
|
|
391
|
+
}
|
|
392
|
+
const root = document.getElementById('command-palette-root');
|
|
393
|
+
if (root && root.innerHTML.trim().length > 0) {
|
|
394
|
+
e.preventDefault();
|
|
395
|
+
e.stopImmediatePropagation();
|
|
396
|
+
if (typeof closeCommandPalette === 'function') {
|
|
397
|
+
closeCommandPalette();
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const drawerRoot = document.getElementById('drawer-root');
|
|
402
|
+
if (drawerRoot && drawerRoot.innerHTML.trim().length > 0) {
|
|
403
|
+
e.preventDefault();
|
|
404
|
+
e.stopImmediatePropagation();
|
|
405
|
+
if (typeof closePluginTesterDrawer === 'function') {
|
|
406
|
+
closePluginTesterDrawer();
|
|
407
|
+
}
|
|
408
|
+
if (typeof closeRecordDrawer === 'function') {
|
|
409
|
+
closeRecordDrawer();
|
|
410
|
+
}
|
|
411
|
+
if (typeof closeWebhookDrawer === 'function') {
|
|
412
|
+
closeWebhookDrawer();
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const modalRoot = document.getElementById('modal-root');
|
|
417
|
+
if (modalRoot && modalRoot.innerHTML.trim().length > 0) {
|
|
418
|
+
e.preventDefault();
|
|
419
|
+
e.stopImmediatePropagation();
|
|
420
|
+
if (typeof closeWebhookModal === 'function') {
|
|
421
|
+
closeWebhookModal();
|
|
422
|
+
}
|
|
423
|
+
if (typeof closeModal === 'function') {
|
|
424
|
+
closeModal();
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// Expose core navigation & lifecycle helpers on window
|
|
432
|
+
if (typeof window !== 'undefined') {
|
|
433
|
+
window.showPageView = showPageView;
|
|
434
|
+
window.clearSidebarNavActive = clearSidebarNavActive;
|
|
435
|
+
window.selectNav = selectNav;
|
|
436
|
+
window.getAppQueryParam = getAppQueryParam;
|
|
437
|
+
window.updateUrl = updateUrl;
|
|
438
|
+
window.parseUrlAndNavigate = parseUrlAndNavigate;
|
|
439
|
+
window.initRouter = initRouter;
|
|
440
|
+
|
|
441
|
+
// Mirror modular exports to window if present
|
|
442
|
+
if (typeof selectCollection !== 'undefined') window.selectCollection = selectCollection;
|
|
443
|
+
if (typeof switchCollectionTab !== 'undefined') window.switchCollectionTab = switchCollectionTab;
|
|
444
|
+
if (typeof renderCollectionsList !== 'undefined') window.renderCollectionsList = renderCollectionsList;
|
|
445
|
+
if (typeof toggleCollectionSection !== 'undefined') window.toggleCollectionSection = toggleCollectionSection;
|
|
446
|
+
if (typeof handleCollectionFilterInput !== 'undefined') window.handleCollectionFilterInput = handleCollectionFilterInput;
|
|
447
|
+
if (typeof clearCollectionFilter !== 'undefined') window.clearCollectionFilter = clearCollectionFilter;
|
|
448
|
+
if (typeof updateBreadcrumbs !== 'undefined') window.updateBreadcrumbs = updateBreadcrumbs;
|
|
449
|
+
if (typeof handleBreadcrumbClick !== 'undefined') window.handleBreadcrumbClick = handleBreadcrumbClick;
|
|
450
|
+
if (typeof openCommandPalette !== 'undefined') window.openCommandPalette = openCommandPalette;
|
|
451
|
+
if (typeof closeCommandPalette !== 'undefined') window.closeCommandPalette = closeCommandPalette;
|
|
452
|
+
if (typeof toggleCommandPalette !== 'undefined') window.toggleCommandPalette = toggleCommandPalette;
|
|
453
|
+
if (typeof getAllCommandPaletteItems !== 'undefined') window.getAllCommandPaletteItems = getAllCommandPaletteItems;
|
|
454
|
+
if (typeof filterCommandPaletteItems !== 'undefined') window.filterCommandPaletteItems = filterCommandPaletteItems;
|
|
455
|
+
if (typeof executeCommandPaletteItem !== 'undefined') window.executeCommandPaletteItem = executeCommandPaletteItem;
|
|
456
|
+
if (typeof handleCommandPaletteInput !== 'undefined') window.handleCommandPaletteInput = handleCommandPaletteInput;
|
|
457
|
+
if (typeof handleCommandPaletteKeyDown !== 'undefined') window.handleCommandPaletteKeyDown = handleCommandPaletteKeyDown;
|
|
458
|
+
if (typeof setCommandPaletteActiveIndex !== 'undefined') window.setCommandPaletteActiveIndex = setCommandPaletteActiveIndex;
|
|
459
|
+
if (typeof renderPluginNavItems !== 'undefined') window.renderPluginNavItems = renderPluginNavItems;
|
|
460
|
+
if (typeof renderPluginView !== 'undefined') window.renderPluginView = renderPluginView;
|
|
461
|
+
if (typeof openPluginTesterDrawer !== 'undefined') window.openPluginTesterDrawer = openPluginTesterDrawer;
|
|
462
|
+
if (typeof closePluginTesterDrawer !== 'undefined') window.closePluginTesterDrawer = closePluginTesterDrawer;
|
|
463
|
+
if (typeof executePluginTest !== 'undefined') window.executePluginTest = executePluginTest;
|
|
464
|
+
if (typeof checkPluginTesterStatus !== 'undefined') window.checkPluginTesterStatus = checkPluginTesterStatus;
|
|
465
|
+
if (typeof runStripeCheckoutTest !== 'undefined') window.runStripeCheckoutTest = runStripeCheckoutTest;
|
|
466
|
+
if (typeof runStripeWebhookSimulation !== 'undefined') window.runStripeWebhookSimulation = runStripeWebhookSimulation;
|
|
467
|
+
if (typeof runS3PresignedUrlTest !== 'undefined') window.runS3PresignedUrlTest = runS3PresignedUrlTest;
|
|
468
|
+
if (typeof runS3StatusTest !== 'undefined') window.runS3StatusTest = runS3StatusTest;
|
|
469
|
+
if (typeof runResendSendTest !== 'undefined') window.runResendSendTest = runResendSendTest;
|
|
470
|
+
if (typeof runWebhookDispatchTest !== 'undefined') window.runWebhookDispatchTest = runWebhookDispatchTest;
|
|
471
|
+
if (typeof runAlgoliaReindexTest !== 'undefined') window.runAlgoliaReindexTest = runAlgoliaReindexTest;
|
|
472
|
+
if (typeof runAlgoliaProcessQueueTest !== 'undefined') window.runAlgoliaProcessQueueTest = runAlgoliaProcessQueueTest;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (typeof window !== 'undefined') {
|
|
476
|
+
initRouter();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Run on startup
|
|
480
|
+
window.addEventListener('DOMContentLoaded', init);
|