@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
|
@@ -13,30 +13,30 @@ function renderCollectionsHubView() {
|
|
|
13
13
|
<div class="hub-hero-banner">
|
|
14
14
|
<div style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:0.75rem;">
|
|
15
15
|
<div>
|
|
16
|
-
<h2 style="font-size:18px; font-weight:800; color
|
|
16
|
+
<h2 style="font-size:18px; font-weight:800; color:var(--text-heading); letter-spacing:-0.02em;">Collections & Schema Directory</h2>
|
|
17
17
|
<p style="font-size:12px; color:var(--text-muted); margin-top:3px;">
|
|
18
18
|
Embedded SQLite database tables with instant REST API, CRUD endpoints, and realtime subscriptions.
|
|
19
19
|
</p>
|
|
20
20
|
</div>
|
|
21
21
|
<div style="display:flex; align-items:center; gap:0.5rem;">
|
|
22
22
|
<button class="btn btn-primary btn-sm" onclick="openNewCollectionModal()">+ New Collection</button>
|
|
23
|
-
<button class="btn btn-secondary btn-sm" onclick="openTemplatesModal()"
|
|
24
|
-
<button class="btn btn-secondary btn-sm" onclick="
|
|
23
|
+
<button class="btn btn-secondary btn-sm" onclick="openTemplatesModal()"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>Starter Recipes</button>
|
|
24
|
+
<button class="btn btn-secondary btn-sm" onclick="openImportJsonModal()"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:-1px; margin-right:4px; color:var(--accent-primary);"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>Import JSON</button>
|
|
25
25
|
</div>
|
|
26
26
|
</div>
|
|
27
27
|
|
|
28
28
|
<div class="hub-stats-row" style="margin-top:0.5rem;">
|
|
29
29
|
<div class="hub-stat-card">
|
|
30
30
|
<span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">Total Collections</span>
|
|
31
|
-
<span style="font-size:20px; font-weight:800; color
|
|
31
|
+
<span style="font-size:20px; font-weight:800; color:var(--text-heading);">${allCols.length}</span>
|
|
32
32
|
</div>
|
|
33
33
|
<div class="hub-stat-card">
|
|
34
34
|
<span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">User Collections</span>
|
|
35
|
-
<span style="font-size:20px; font-weight:800; color
|
|
35
|
+
<span style="font-size:20px; font-weight:800; color:var(--text-heading);">${userCols.length}</span>
|
|
36
36
|
</div>
|
|
37
37
|
<div class="hub-stat-card">
|
|
38
38
|
<span style="font-size:11px; font-weight:700; color:var(--text-muted); text-transform:uppercase;">System Tables</span>
|
|
39
|
-
<span style="font-size:20px; font-weight:800; color
|
|
39
|
+
<span style="font-size:20px; font-weight:800; color:var(--text-heading);">${systemCols.length}</span>
|
|
40
40
|
</div>
|
|
41
41
|
</div>
|
|
42
42
|
</div>
|
|
@@ -53,7 +53,9 @@ function renderCollectionsHubView() {
|
|
|
53
53
|
<div class="hub-card" onclick="selectCollection('${escapeHtml(col.name)}')">
|
|
54
54
|
<div class="hub-card-header">
|
|
55
55
|
<div class="hub-card-title">
|
|
56
|
-
|
|
56
|
+
${isSys
|
|
57
|
+
? '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--text-muted);"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>'
|
|
58
|
+
: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent-primary);"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path></svg>'}
|
|
57
59
|
<span>${escapeHtml(col.name)}</span>
|
|
58
60
|
</div>
|
|
59
61
|
<div style="display:flex; align-items:center; gap:4px;">
|
|
@@ -233,7 +235,7 @@ function renderCollectionsList() {
|
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
// Select Collection
|
|
236
|
-
async function selectCollection(name) {
|
|
238
|
+
async function selectCollection(name, pushState = true) {
|
|
237
239
|
state.activeNav = 'collection';
|
|
238
240
|
const allCols = Array.isArray(state.collections)
|
|
239
241
|
? state.collections
|
|
@@ -275,16 +277,30 @@ async function selectCollection(name) {
|
|
|
275
277
|
} else {
|
|
276
278
|
renderSchemaView();
|
|
277
279
|
}
|
|
280
|
+
|
|
281
|
+
if (pushState) {
|
|
282
|
+
const sub = (state.collectionTab === 'schema') ? '/schema' : '';
|
|
283
|
+
if (typeof updateUrl === 'function') {
|
|
284
|
+
updateUrl('/_/collections/' + encodeURIComponent(name) + sub);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
278
287
|
}
|
|
279
288
|
|
|
280
289
|
// Collection Tabs
|
|
281
|
-
function switchCollectionTab(tab) {
|
|
290
|
+
function switchCollectionTab(tab, pushState = true) {
|
|
282
291
|
state.collectionTab = tab;
|
|
283
292
|
document.getElementById('tab-records').className = tab === 'records' ? 'tab-btn active' : 'tab-btn';
|
|
284
293
|
document.getElementById('tab-schema').className = tab === 'schema' ? 'tab-btn active' : 'tab-btn';
|
|
285
294
|
|
|
286
295
|
updateBreadcrumbs();
|
|
287
296
|
|
|
297
|
+
if (pushState && state.activeCollection) {
|
|
298
|
+
const sub = (tab === 'schema') ? '/schema' : '';
|
|
299
|
+
if (typeof updateUrl === 'function') {
|
|
300
|
+
updateUrl('/_/collections/' + encodeURIComponent(state.activeCollection.name) + sub);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
288
304
|
if (tab === 'records') {
|
|
289
305
|
renderRecordsView();
|
|
290
306
|
loadRecords();
|
|
@@ -343,6 +359,19 @@ function updateBreadcrumbs() {
|
|
|
343
359
|
} else {
|
|
344
360
|
crumbs.push({ label: 'Webhooks', active: true });
|
|
345
361
|
}
|
|
362
|
+
} else if (state.activeNav === 'functions') {
|
|
363
|
+
if (typeof functionsState !== 'undefined' && functionsState.currentView === 'editor' && functionsState.activeFunctionForEdit) {
|
|
364
|
+
crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof closeFunctionEditor === 'function') closeFunctionEditor(); } });
|
|
365
|
+
const editLabel = functionsState.activeFunctionForEdit.isNew
|
|
366
|
+
? (functionsState.activeFunctionForEdit.name || 'New Function')
|
|
367
|
+
: functionsState.activeFunctionForEdit.name;
|
|
368
|
+
crumbs.push({ label: editLabel, active: true });
|
|
369
|
+
} else if (typeof functionsState !== 'undefined' && functionsState.subTab === 'logs') {
|
|
370
|
+
crumbs.push({ label: 'Functions', clickable: true, action: () => { if (typeof switchFunctionsTab === 'function') switchFunctionsTab('functions'); } });
|
|
371
|
+
crumbs.push({ label: 'Execution Logs', active: true });
|
|
372
|
+
} else {
|
|
373
|
+
crumbs.push({ label: 'Functions', active: true });
|
|
374
|
+
}
|
|
346
375
|
} else if (state.activeNav === 'home') {
|
|
347
376
|
crumbs.push({ label: 'Overview', active: true });
|
|
348
377
|
} else if (state.activeNav === 'analytics') {
|
|
@@ -57,7 +57,7 @@ function getAllCommandPaletteItems() {
|
|
|
57
57
|
category: 'Navigation',
|
|
58
58
|
badge: 'PAGE',
|
|
59
59
|
icon: '🧩',
|
|
60
|
-
keywords: ['plugins', 'extensions', 'addons', 'stripe', 's3', 'resend', 'webhooks', 'algolia'],
|
|
60
|
+
keywords: ['plugins', 'extensions', 'addons', 'stripe', 's3', 'resend', 'chat notifications', 'discord', 'slack', 'webhooks', 'algolia'],
|
|
61
61
|
action: () => selectNav('plugins')
|
|
62
62
|
});
|
|
63
63
|
|
|
@@ -72,6 +72,17 @@ function getAllCommandPaletteItems() {
|
|
|
72
72
|
action: () => selectNav('webhooks')
|
|
73
73
|
});
|
|
74
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
|
+
|
|
75
86
|
items.push({
|
|
76
87
|
id: 'nav-analytics',
|
|
77
88
|
title: 'Analytics',
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// Serverless Functions Live Sandbox Test Runner & Workbench Logs Module
|
|
2
|
+
// Companion module for NodeStack Admin UI Functions Workbench
|
|
3
|
+
|
|
4
|
+
// ==========================================
|
|
5
|
+
// 1. Sandbox Test Runner Sub-Renderer
|
|
6
|
+
// ==========================================
|
|
7
|
+
|
|
8
|
+
function renderWorkbenchTestPane(fn, isNew) {
|
|
9
|
+
if (isNew) {
|
|
10
|
+
return `
|
|
11
|
+
<div id="fn-editor-pane-test" class="fn-editor-pane" style="display: ${functionsState.editorTab === 'test' ? 'flex' : 'none'}; width: 100%;">
|
|
12
|
+
<div class="card" style="padding: 3.5rem 1.5rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; width: 100%;">
|
|
13
|
+
<div style="width: 54px; height: 54px; border-radius: 50%; background: rgba(99, 102, 241, 0.12); display: flex; align-items: center; justify-content: center; color: var(--accent-primary);">
|
|
14
|
+
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
|
15
|
+
</div>
|
|
16
|
+
<div>
|
|
17
|
+
<h3 style="margin: 0 0 0.5rem 0; font-size: 1.2rem; font-weight: 600;">Function Not Yet Created</h3>
|
|
18
|
+
<p style="margin: 0; color: var(--text-muted); font-size: 0.875rem; max-width: 480px;">
|
|
19
|
+
Create this function first to unlock live sandboxed HTTP executions and real-time response inspecting.
|
|
20
|
+
</p>
|
|
21
|
+
</div>
|
|
22
|
+
<button class="btn btn-primary btn-sm" onclick="saveFunctionEditor()" style="display: flex; align-items: center; gap: 6px; font-weight: 600; margin-top: 4px;">
|
|
23
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
|
|
24
|
+
<span>Create Function & Unlock Runner</span>
|
|
25
|
+
</button>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return `
|
|
32
|
+
<div id="fn-editor-pane-test" class="fn-editor-pane" style="display: ${functionsState.editorTab === 'test' ? 'grid' : 'none'}; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start;">
|
|
33
|
+
<!-- Left: Test Request Builder -->
|
|
34
|
+
<div class="card" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
35
|
+
<div style="font-weight: 600; font-size: 13px; color: var(--text-heading); display: flex; align-items: center; justify-content: space-between;">
|
|
36
|
+
<span>Simulate Invocation</span>
|
|
37
|
+
<span style="font-size: 11px; font-weight: normal; color: var(--text-muted);">QuickJS Sandbox Execution</span>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div style="display: grid; grid-template-columns: 110px 1fr; gap: 10px;">
|
|
41
|
+
<div>
|
|
42
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px;">Method</label>
|
|
43
|
+
<select id="editor-test-method" class="input" style="width: 100%;">
|
|
44
|
+
<option value="POST">POST</option>
|
|
45
|
+
<option value="GET">GET</option>
|
|
46
|
+
<option value="PUT">PUT</option>
|
|
47
|
+
<option value="PATCH">PATCH</option>
|
|
48
|
+
<option value="DELETE">DELETE</option>
|
|
49
|
+
</select>
|
|
50
|
+
</div>
|
|
51
|
+
<div>
|
|
52
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px;">Simulated Caller Role / Auth</label>
|
|
53
|
+
<select id="editor-test-auth" class="input" style="width: 100%;" onchange="toggleEditorTestAuthCustom(this.value)">
|
|
54
|
+
<option value="none">Public (No Authorization Header)</option>
|
|
55
|
+
<option value="admin">Current Admin Session (Bearer Token)</option>
|
|
56
|
+
<option value="custom">Custom Token...</option>
|
|
57
|
+
</select>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div id="editor-test-custom-auth-row" style="display: none;">
|
|
62
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px;">Custom Token (JWT / API Key)</label>
|
|
63
|
+
<input type="text" id="editor-test-custom-token" class="input" placeholder="eyJhbGciOi..." style="width: 100%; font-family: monospace; font-size: 11px;">
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div>
|
|
67
|
+
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;">
|
|
68
|
+
<label style="font-size: 11px; font-weight: 600;">Custom Request Headers (JSON)</label>
|
|
69
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="setEditorTestSampleHeaders()" style="font-size: 10px; padding: 1px 6px;">Sample Headers</button>
|
|
70
|
+
</div>
|
|
71
|
+
<textarea id="editor-test-headers-input" style="width: 100%; height: 60px; font-family: monospace; font-size: 11px; padding: 8px; border-radius: 6px; border: 1px solid var(--border-subtle); background: var(--bg-input); color: var(--text-main);" placeholder='{ "Content-Type": "application/json" }'></textarea>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<div>
|
|
75
|
+
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;">
|
|
76
|
+
<label style="font-size: 11px; font-weight: 600;">Request Body (JSON)</label>
|
|
77
|
+
<div style="display: flex; align-items: center; gap: 6px;">
|
|
78
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="setEditorTestSampleBody('empty')" style="font-size: 10px; padding: 1px 6px;">{}</button>
|
|
79
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="setEditorTestSampleBody('sample')" style="font-size: 10px; padding: 1px 6px;">Sample Data</button>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<textarea id="editor-test-body" style="width: 100%; height: 160px; font-family: 'JetBrains Mono', Consolas, Monaco, monospace; font-size: 12px; line-height: 1.4; padding: 10px; border-radius: 6px; border: 1px solid var(--border-subtle); background: #0f172a; color: #f8fafc;" placeholder='{ "items": [{ "id": "p1", "price": 49.99 }] }'>{ "name": "NodeStack Developer" }</textarea>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<div>
|
|
86
|
+
<button class="btn btn-primary" id="btn-run-editor-test" onclick="executeFunctionEditorTest()" style="width: 100%; justify-content: center; font-weight: 600; padding: 8px;">
|
|
87
|
+
⚡ Run Sandbox Test
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<!-- Right: Execution Output -->
|
|
93
|
+
<div class="card" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; min-height: 480px;">
|
|
94
|
+
<div id="editor-test-empty-state" style="display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; padding: 3rem 1rem; text-align: center; color: var(--text-muted); gap: 10px;">
|
|
95
|
+
<div style="width: 48px; height: 48px; border-radius: 50%; background: var(--bg-card-hover); display: flex; align-items: center; justify-content: center; color: var(--accent-primary);">
|
|
96
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
|
97
|
+
</div>
|
|
98
|
+
<div style="font-weight: 600; font-size: 13px; color: var(--text-heading);">Ready to Test</div>
|
|
99
|
+
<p style="margin: 0; font-size: 12px; max-width: 320px;">
|
|
100
|
+
Click <strong>Run Sandbox Test</strong> to execute this function isolated in QuickJS and inspect return values, logs, and headers.
|
|
101
|
+
</p>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div id="editor-test-result-pane" style="display: none; flex-direction: column; gap: 12px;">
|
|
105
|
+
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-subtle); padding-bottom: 8px;">
|
|
106
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
107
|
+
<span id="editor-test-badge-status" class="badge" style="font-size: 12px; font-weight: 700; border: 1px solid transparent;">HTTP 200</span>
|
|
108
|
+
<span id="editor-test-badge-duration" class="badge" style="background: var(--bg-card-hover); color: var(--text-muted); font-size: 11px;">0ms</span>
|
|
109
|
+
</div>
|
|
110
|
+
<span style="font-size: 11px; color: var(--text-muted);">Sandbox Invocation</span>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<div>
|
|
114
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Captured Logs (ctx.log & console.log):</label>
|
|
115
|
+
<pre id="editor-test-logs" style="background: #0f172a; color: #38bdf8; padding: 10px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height: 120px; overflow-y: auto; margin: 0; white-space: pre-wrap;"></pre>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div>
|
|
119
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Response Body:</label>
|
|
120
|
+
<pre id="editor-test-response" style="background: #0f172a; color: #a7f3d0; padding: 12px; border-radius: 6px; font-family: monospace; font-size: 12px; max-height: 240px; overflow-y: auto; margin: 0; white-space: pre-wrap;"></pre>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<div>
|
|
124
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Response Headers:</label>
|
|
125
|
+
<pre id="editor-test-headers" style="background: var(--bg-input); color: var(--text-muted); padding: 8px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height: 80px; overflow-y: auto; margin: 0;"></pre>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ==========================================
|
|
134
|
+
// 2. Test Parameter Helpers
|
|
135
|
+
// ==========================================
|
|
136
|
+
|
|
137
|
+
function setEditorTestSampleHeaders() {
|
|
138
|
+
const el = document.getElementById('editor-test-headers-input');
|
|
139
|
+
if (el) el.value = JSON.stringify({ "x-custom-source": "admin-sandbox", "Content-Type": "application/json" }, null, 2);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function setEditorTestSampleBody(type) {
|
|
143
|
+
const el = document.getElementById('editor-test-body');
|
|
144
|
+
if (!el) return;
|
|
145
|
+
if (type === 'empty') el.value = '{}';
|
|
146
|
+
else if (type === 'sample') el.value = JSON.stringify({ name: 'NodeStack', amount: 150, items: ['item_1', 'item_2'] }, null, 2);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function toggleEditorTestAuthCustom(val) {
|
|
150
|
+
const row = document.getElementById('editor-test-custom-auth-row');
|
|
151
|
+
if (row) row.style.display = val === 'custom' ? 'block' : 'none';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ==========================================
|
|
155
|
+
// 3. Sandbox Execution Engine
|
|
156
|
+
// ==========================================
|
|
157
|
+
|
|
158
|
+
async function executeFunctionEditorTest() {
|
|
159
|
+
const btn = document.getElementById('btn-run-editor-test');
|
|
160
|
+
if (btn) {
|
|
161
|
+
btn.disabled = true;
|
|
162
|
+
btn.textContent = 'Executing...';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const fn = functionsState.activeFunctionForEdit;
|
|
166
|
+
if (!fn) return;
|
|
167
|
+
|
|
168
|
+
const outputEmpty = document.getElementById('editor-test-empty-state');
|
|
169
|
+
const outputResult = document.getElementById('editor-test-result-pane');
|
|
170
|
+
const badgeStatus = document.getElementById('editor-test-badge-status');
|
|
171
|
+
const badgeDuration = document.getElementById('editor-test-badge-duration');
|
|
172
|
+
const logsPre = document.getElementById('editor-test-logs');
|
|
173
|
+
const resPre = document.getElementById('editor-test-response');
|
|
174
|
+
const headersPre = document.getElementById('editor-test-headers');
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
const method = document.getElementById('editor-test-method')?.value || 'POST';
|
|
178
|
+
const authType = document.getElementById('editor-test-auth')?.value || 'none';
|
|
179
|
+
const customAuthToken = document.getElementById('editor-test-custom-token')?.value || '';
|
|
180
|
+
|
|
181
|
+
let body = {};
|
|
182
|
+
const bodyRaw = document.getElementById('editor-test-body')?.value.trim();
|
|
183
|
+
if (bodyRaw) {
|
|
184
|
+
try {
|
|
185
|
+
body = JSON.parse(bodyRaw);
|
|
186
|
+
} catch {
|
|
187
|
+
throw new Error('Mock request body must be valid JSON');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
let headers = {};
|
|
192
|
+
const headersRaw = document.getElementById('editor-test-headers-input')?.value.trim();
|
|
193
|
+
if (headersRaw) {
|
|
194
|
+
try {
|
|
195
|
+
headers = JSON.parse(headersRaw);
|
|
196
|
+
} catch {
|
|
197
|
+
throw new Error('Request headers must be valid JSON');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (authType === 'admin' && typeof state !== 'undefined' && state.token) {
|
|
202
|
+
headers['authorization'] = `Bearer ${state.token}`;
|
|
203
|
+
} else if (authType === 'custom' && customAuthToken) {
|
|
204
|
+
headers['authorization'] = `Bearer ${customAuthToken.trim()}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
208
|
+
const endpoint = slug && slug !== 'default'
|
|
209
|
+
? `/api/apps/${slug}/functions/${fn.id}/test`
|
|
210
|
+
: `/api/functions/${fn.id}/test`;
|
|
211
|
+
|
|
212
|
+
const res = await api(endpoint, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: { 'Content-Type': 'application/json' },
|
|
215
|
+
body: JSON.stringify({ method, body, headers }),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (outputEmpty) outputEmpty.style.display = 'none';
|
|
219
|
+
if (outputResult) outputResult.style.display = 'flex';
|
|
220
|
+
|
|
221
|
+
const isOk = res.status === 'success';
|
|
222
|
+
const statusColor = isOk ? 'var(--accent-success)' : 'var(--accent-danger)';
|
|
223
|
+
if (badgeStatus) {
|
|
224
|
+
badgeStatus.textContent = `HTTP ${res.statusCode || 200}`;
|
|
225
|
+
badgeStatus.style.color = statusColor;
|
|
226
|
+
badgeStatus.style.borderColor = statusColor;
|
|
227
|
+
}
|
|
228
|
+
if (badgeDuration) {
|
|
229
|
+
badgeDuration.textContent = `${res.durationMs || 0}ms`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (logsPre) {
|
|
233
|
+
logsPre.textContent = (res.logs && res.logs.length > 0) ? res.logs.join('\n') : '(No console output logged)';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (resPre) {
|
|
237
|
+
if (res.error) {
|
|
238
|
+
resPre.style.color = 'var(--accent-danger)';
|
|
239
|
+
resPre.textContent = res.error;
|
|
240
|
+
} else {
|
|
241
|
+
resPre.style.color = '#a7f3d0';
|
|
242
|
+
resPre.textContent = typeof res.body === 'object' ? JSON.stringify(res.body, null, 2) : String(res.body);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (headersPre) {
|
|
247
|
+
headersPre.textContent = res.headers ? JSON.stringify(res.headers, null, 2) : '{}';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (typeof loadFunctionStats === 'function') {
|
|
251
|
+
await loadFunctionStats();
|
|
252
|
+
}
|
|
253
|
+
} catch (err) {
|
|
254
|
+
if (outputEmpty) outputEmpty.style.display = 'none';
|
|
255
|
+
if (outputResult) outputResult.style.display = 'flex';
|
|
256
|
+
if (badgeStatus) {
|
|
257
|
+
badgeStatus.textContent = 'ERROR';
|
|
258
|
+
badgeStatus.style.color = 'var(--accent-danger)';
|
|
259
|
+
}
|
|
260
|
+
if (resPre) {
|
|
261
|
+
resPre.style.color = 'var(--accent-danger)';
|
|
262
|
+
resPre.textContent = err.message || String(err);
|
|
263
|
+
}
|
|
264
|
+
} finally {
|
|
265
|
+
if (btn) {
|
|
266
|
+
btn.disabled = false;
|
|
267
|
+
btn.textContent = '⚡ Run Sandbox Test';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ==========================================
|
|
273
|
+
// 4. Workbench Function Logs Sub-Renderer & Loader
|
|
274
|
+
// ==========================================
|
|
275
|
+
|
|
276
|
+
function renderWorkbenchLogsPane(fn, isNew) {
|
|
277
|
+
if (isNew) {
|
|
278
|
+
return `
|
|
279
|
+
<div id="fn-editor-pane-logs" class="fn-editor-pane" style="display: ${functionsState.editorTab === 'logs' ? 'flex' : 'none'}; flex-direction: column; gap: 1rem; width: 100%;">
|
|
280
|
+
<div class="card" style="padding: 3.5rem 1.5rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem; width: 100%;">
|
|
281
|
+
<div style="width: 54px; height: 54px; border-radius: 50%; background: var(--bg-card-hover); display: flex; align-items: center; justify-content: center; color: var(--text-muted);">
|
|
282
|
+
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>
|
|
283
|
+
</div>
|
|
284
|
+
<div>
|
|
285
|
+
<h3 style="margin: 0 0 0.5rem 0; font-size: 1.2rem; font-weight: 600;">No Logs Available</h3>
|
|
286
|
+
<p style="margin: 0; color: var(--text-muted); font-size: 0.875rem; max-width: 440px;">
|
|
287
|
+
Execution history and stdout/stderr traces will be recorded here once this function is deployed and invoked.
|
|
288
|
+
</p>
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return `
|
|
296
|
+
<div id="fn-editor-pane-logs" class="fn-editor-pane" style="display: ${functionsState.editorTab === 'logs' ? 'flex' : 'none'}; flex-direction: column; gap: 1rem; width: 100%;">
|
|
297
|
+
<div class="card" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
298
|
+
<div style="display: flex; align-items: center; justify-content: space-between;">
|
|
299
|
+
<div style="font-weight: 600; font-size: 13px; color: var(--text-heading);">
|
|
300
|
+
Execution History for <code style="color: var(--accent-primary);">${escapeHtml(fn.name)}</code>
|
|
301
|
+
</div>
|
|
302
|
+
<button class="btn btn-secondary btn-sm" onclick="loadFunctionEditorLogs()">
|
|
303
|
+
Refresh Logs
|
|
304
|
+
</button>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
<div id="fn-editor-logs-container">
|
|
308
|
+
<div style="display: flex; align-items: center; justify-content: center; padding: 3rem; color: var(--text-muted);">
|
|
309
|
+
<span class="spinner" style="margin-right: 8px;"></span> Loading logs...
|
|
310
|
+
</div>
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function formatTimestampSafe(iso) {
|
|
318
|
+
if (typeof formatTimestamp === 'function') {
|
|
319
|
+
return formatTimestamp(iso);
|
|
320
|
+
}
|
|
321
|
+
if (!iso) return '-';
|
|
322
|
+
try {
|
|
323
|
+
const d = new Date(iso);
|
|
324
|
+
if (isNaN(d.getTime())) return iso;
|
|
325
|
+
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' }) + ' ' + d.toLocaleDateString();
|
|
326
|
+
} catch {
|
|
327
|
+
return iso;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function loadFunctionEditorLogs() {
|
|
332
|
+
const container = document.getElementById('fn-editor-logs-container');
|
|
333
|
+
if (!container) return;
|
|
334
|
+
|
|
335
|
+
const fn = functionsState.activeFunctionForEdit;
|
|
336
|
+
if (!fn) return;
|
|
337
|
+
|
|
338
|
+
container.innerHTML = `
|
|
339
|
+
<div style="display: flex; align-items: center; justify-content: center; padding: 3rem; color: var(--text-muted);">
|
|
340
|
+
<span class="spinner" style="margin-right: 8px;"></span> Loading logs for ${escapeHtml(fn.name)}...
|
|
341
|
+
</div>
|
|
342
|
+
`;
|
|
343
|
+
|
|
344
|
+
try {
|
|
345
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
346
|
+
const baseUrl = slug && slug !== 'default' ? `/api/apps/${slug}/functions/logs` : '/api/functions/logs';
|
|
347
|
+
const params = new URLSearchParams({
|
|
348
|
+
functionId: fn.id,
|
|
349
|
+
page: '1',
|
|
350
|
+
perPage: '50',
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const res = await api(`${baseUrl}?${params.toString()}`);
|
|
354
|
+
const items = res.items || [];
|
|
355
|
+
functionsState.editorLogs = items;
|
|
356
|
+
renderFunctionEditorLogsTable(items);
|
|
357
|
+
} catch (err) {
|
|
358
|
+
container.innerHTML = `
|
|
359
|
+
<div class="card" style="padding: 2rem; text-align: center; color: var(--accent-danger);">
|
|
360
|
+
Failed to load logs: ${escapeHtml(err.message || String(err))}
|
|
361
|
+
</div>
|
|
362
|
+
`;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function renderFunctionEditorLogsTable(logs) {
|
|
367
|
+
const container = document.getElementById('fn-editor-logs-container');
|
|
368
|
+
if (!container) return;
|
|
369
|
+
|
|
370
|
+
if (!logs || logs.length === 0) {
|
|
371
|
+
container.innerHTML = `
|
|
372
|
+
<div style="padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); font-size: 13px;">
|
|
373
|
+
No execution logs recorded for this function yet. Switch to the <strong>Live Test Runner</strong> tab to run a sandbox test.
|
|
374
|
+
</div>
|
|
375
|
+
`;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const rows = logs.map(l => {
|
|
380
|
+
const isOk = l.status === 'success';
|
|
381
|
+
const statusBadge = isOk
|
|
382
|
+
? `<span class="badge" style="background: rgba(16, 185, 129, 0.15); color: #10b981;">${l.statusCode || 200} OK</span>`
|
|
383
|
+
: `<span class="badge" style="background: rgba(239, 68, 68, 0.15); color: #ef4444;">${escapeHtml(l.status.toUpperCase())}</span>`;
|
|
384
|
+
|
|
385
|
+
return `
|
|
386
|
+
<tr>
|
|
387
|
+
<td style="font-size: 12px; color: var(--text-muted);">${formatTimestampSafe(l.timestamp || l.createdAt)}</td>
|
|
388
|
+
<td>${statusBadge}</td>
|
|
389
|
+
<td style="font-size: 12px; font-weight: 600;">${l.durationMs}ms</td>
|
|
390
|
+
<td><code style="font-size: 11px;">${escapeHtml(l.method || 'POST')}</code></td>
|
|
391
|
+
<td style="font-size: 12px; color: var(--text-muted);">${escapeHtml(l.actorId || 'public')}</td>
|
|
392
|
+
<td style="text-align: right;">
|
|
393
|
+
<button class="btn btn-secondary btn-sm" onclick="viewLogPayload('${l.id}')" title="Inspect Request/Response payload" style="font-size: 11px; padding: 2px 7px;">
|
|
394
|
+
Inspect
|
|
395
|
+
</button>
|
|
396
|
+
</td>
|
|
397
|
+
</tr>
|
|
398
|
+
`;
|
|
399
|
+
}).join('');
|
|
400
|
+
|
|
401
|
+
container.innerHTML = `
|
|
402
|
+
<div style="overflow-x: auto;">
|
|
403
|
+
<table class="table" style="width: 100%; border-collapse: collapse; font-size: 13px;">
|
|
404
|
+
<thead>
|
|
405
|
+
<tr style="border-bottom: 1px solid var(--border-subtle); background: var(--bg-card-hover);">
|
|
406
|
+
<th style="text-align: left; padding: 8px 12px;">Timestamp</th>
|
|
407
|
+
<th style="text-align: left; padding: 8px 12px;">Status</th>
|
|
408
|
+
<th style="text-align: left; padding: 8px 12px;">Latency</th>
|
|
409
|
+
<th style="text-align: left; padding: 8px 12px;">Method</th>
|
|
410
|
+
<th style="text-align: left; padding: 8px 12px;">Caller</th>
|
|
411
|
+
<th style="text-align: right; padding: 8px 12px;">Payload</th>
|
|
412
|
+
</tr>
|
|
413
|
+
</thead>
|
|
414
|
+
<tbody>
|
|
415
|
+
${rows}
|
|
416
|
+
</tbody>
|
|
417
|
+
</table>
|
|
418
|
+
</div>
|
|
419
|
+
`;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Global Exports
|
|
423
|
+
if (typeof window !== 'undefined') {
|
|
424
|
+
window.renderWorkbenchTestPane = renderWorkbenchTestPane;
|
|
425
|
+
window.setEditorTestSampleHeaders = setEditorTestSampleHeaders;
|
|
426
|
+
window.setEditorTestSampleBody = setEditorTestSampleBody;
|
|
427
|
+
window.toggleEditorTestAuthCustom = toggleEditorTestAuthCustom;
|
|
428
|
+
window.executeFunctionEditorTest = executeFunctionEditorTest;
|
|
429
|
+
window.renderWorkbenchLogsPane = renderWorkbenchLogsPane;
|
|
430
|
+
window.loadFunctionEditorLogs = loadFunctionEditorLogs;
|
|
431
|
+
window.renderFunctionEditorLogsTable = renderFunctionEditorLogsTable;
|
|
432
|
+
}
|