@nodestackapp/server 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -28
- package/dist/NodeStack.d.ts +5 -1
- package/dist/NodeStack.d.ts.map +1 -1
- package/dist/NodeStack.js +117 -18
- package/dist/NodeStack.js.map +1 -1
- package/dist/admin/AdminUIBundler.d.ts.map +1 -1
- package/dist/admin/AdminUIBundler.js +2 -0
- package/dist/admin/AdminUIBundler.js.map +1 -1
- package/dist/admin/ui/css/main.css +40 -3
- package/dist/admin/ui/css/webhooks.css +8 -0
- package/dist/admin/ui/index.html +21479 -17251
- package/dist/admin/ui/js/api-keys.js +1381 -0
- package/dist/admin/ui/js/api.js +8 -0
- package/dist/admin/ui/js/app.js +698 -641
- package/dist/admin/ui/js/apps.js +514 -489
- package/dist/admin/ui/js/collections.js +486 -484
- package/dist/admin/ui/js/command-palette.js +693 -673
- package/dist/admin/ui/js/cron.js +1706 -0
- package/dist/admin/ui/js/database.js +10 -0
- package/dist/admin/ui/js/flows-designer.js +1219 -1076
- package/dist/admin/ui/js/flows.js +947 -890
- package/dist/admin/ui/js/functions-tester.js +1 -1
- package/dist/admin/ui/js/functions-workbench.js +1162 -1101
- package/dist/admin/ui/js/functions.js +983 -979
- package/dist/admin/ui/js/rules.js +1080 -775
- package/dist/admin/ui/js/schema.js +346 -304
- package/dist/admin/ui/js/snapshots.js +338 -0
- package/dist/admin/ui/js/views.js +1 -1
- package/dist/apps/AppManager.d.ts +1 -1
- package/dist/apps/AppManager.d.ts.map +1 -1
- package/dist/apps/AppManager.js +11 -21
- package/dist/apps/AppManager.js.map +1 -1
- package/dist/apps/AppRegistry.d.ts +1 -0
- package/dist/apps/AppRegistry.d.ts.map +1 -1
- package/dist/apps/AppRegistry.js +78 -23
- package/dist/apps/AppRegistry.js.map +1 -1
- package/dist/apps/AppScope.d.ts +2 -1
- package/dist/apps/AppScope.d.ts.map +1 -1
- package/dist/apps/AppScope.js +27 -17
- package/dist/apps/AppScope.js.map +1 -1
- package/dist/auth/ApiKeyService.d.ts +63 -2
- package/dist/auth/ApiKeyService.d.ts.map +1 -1
- package/dist/auth/ApiKeyService.js +518 -8
- package/dist/auth/ApiKeyService.js.map +1 -1
- package/dist/auth/AuthService.d.ts +30 -1
- package/dist/auth/AuthService.d.ts.map +1 -1
- package/dist/auth/AuthService.js +468 -65
- package/dist/auth/AuthService.js.map +1 -1
- package/dist/auth/oauth/AppleProvider.d.ts +2 -0
- package/dist/auth/oauth/AppleProvider.d.ts.map +1 -1
- package/dist/auth/oauth/AppleProvider.js +40 -3
- package/dist/auth/oauth/AppleProvider.js.map +1 -1
- package/dist/auth/oauth/BaseOAuthProvider.d.ts +3 -2
- package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -1
- package/dist/auth/oauth/BaseOAuthProvider.js +29 -3
- package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -1
- package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -1
- package/dist/auth/oauth/DiscordProvider.js +4 -1
- package/dist/auth/oauth/DiscordProvider.js.map +1 -1
- package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -1
- package/dist/auth/oauth/GitHubProvider.js +4 -1
- package/dist/auth/oauth/GitHubProvider.js.map +1 -1
- package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -1
- package/dist/auth/oauth/GoogleProvider.js +4 -1
- package/dist/auth/oauth/GoogleProvider.js.map +1 -1
- package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -1
- package/dist/auth/oauth/MicrosoftProvider.js +4 -1
- package/dist/auth/oauth/MicrosoftProvider.js.map +1 -1
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts +6 -2
- package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -1
- package/dist/auth/oauth/OAuthProviderRegistry.js +25 -10
- package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -1
- package/dist/auth/oauth/types.d.ts +4 -2
- package/dist/auth/oauth/types.d.ts.map +1 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +228 -12
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/config/ConfigService.d.ts.map +1 -1
- package/dist/core/config/ConfigService.js +5 -3
- package/dist/core/config/ConfigService.js.map +1 -1
- package/dist/core/config/EnvLoader.d.ts +14 -0
- package/dist/core/config/EnvLoader.d.ts.map +1 -1
- package/dist/core/config/EnvLoader.js +44 -0
- package/dist/core/config/EnvLoader.js.map +1 -1
- package/dist/core/container/Container.d.ts +14 -0
- package/dist/core/container/Container.d.ts.map +1 -1
- package/dist/core/container/Container.js +32 -0
- package/dist/core/container/Container.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/errors/AppError.d.ts +7 -7
- package/dist/core/errors/AppError.d.ts.map +1 -1
- package/dist/core/errors/AppError.js +18 -14
- package/dist/core/errors/AppError.js.map +1 -1
- package/dist/core/events/EventBus.d.ts.map +1 -1
- package/dist/core/events/EventBus.js +36 -6
- package/dist/core/events/EventBus.js.map +1 -1
- package/dist/core/maintenance/MaintenanceGate.d.ts +47 -0
- package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -1
- package/dist/core/maintenance/MaintenanceGate.js +265 -7
- package/dist/core/maintenance/MaintenanceGate.js.map +1 -1
- package/dist/core/plugins/PluginManager.d.ts +20 -1
- package/dist/core/plugins/PluginManager.d.ts.map +1 -1
- package/dist/core/plugins/PluginManager.js +231 -146
- package/dist/core/plugins/PluginManager.js.map +1 -1
- package/dist/core/plugins/types.d.ts +48 -31
- package/dist/core/plugins/types.d.ts.map +1 -1
- package/dist/cron/CronParser.d.ts +83 -0
- package/dist/cron/CronParser.d.ts.map +1 -0
- package/dist/cron/CronParser.js +538 -0
- package/dist/cron/CronParser.js.map +1 -0
- package/dist/cron/CronService.d.ts +74 -0
- package/dist/cron/CronService.d.ts.map +1 -0
- package/dist/cron/CronService.js +1254 -0
- package/dist/cron/CronService.js.map +1 -0
- package/dist/cron/types.d.ts +98 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/database/DatabaseService.d.ts +4 -1
- package/dist/database/DatabaseService.d.ts.map +1 -1
- package/dist/database/DatabaseService.js +34 -9
- package/dist/database/DatabaseService.js.map +1 -1
- package/dist/database/config/DatabaseConfigService.d.ts +1 -0
- package/dist/database/config/DatabaseConfigService.d.ts.map +1 -1
- package/dist/database/config/DatabaseConfigService.js +4 -2
- package/dist/database/config/DatabaseConfigService.js.map +1 -1
- package/dist/database/drivers/DriverPackageLoader.d.ts +11 -0
- package/dist/database/drivers/DriverPackageLoader.d.ts.map +1 -0
- package/dist/database/drivers/DriverPackageLoader.js +112 -0
- package/dist/database/drivers/DriverPackageLoader.js.map +1 -0
- package/dist/database/drivers/DriverRegistry.d.ts +1 -0
- package/dist/database/drivers/DriverRegistry.d.ts.map +1 -1
- package/dist/database/drivers/DriverRegistry.js +29 -0
- package/dist/database/drivers/DriverRegistry.js.map +1 -1
- package/dist/database/drivers/IDatabaseDriver.d.ts +1 -0
- package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -1
- package/dist/database/drivers/MssqlDriver.d.ts.map +1 -1
- package/dist/database/drivers/MssqlDriver.js +10 -5
- package/dist/database/drivers/MssqlDriver.js.map +1 -1
- package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -1
- package/dist/database/drivers/NodeSqliteDriver.js +15 -1
- package/dist/database/drivers/NodeSqliteDriver.js.map +1 -1
- package/dist/database/drivers/PostgresDriver.d.ts.map +1 -1
- package/dist/database/drivers/PostgresDriver.js +4 -5
- package/dist/database/drivers/PostgresDriver.js.map +1 -1
- package/dist/database/migration/DatabaseMigrationService.d.ts +1 -0
- package/dist/database/migration/DatabaseMigrationService.d.ts.map +1 -1
- package/dist/database/migration/DatabaseMigrationService.js +51 -0
- package/dist/database/migration/DatabaseMigrationService.js.map +1 -1
- package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
- package/dist/database/migrations/SystemMigrations.js +200 -5
- package/dist/database/migrations/SystemMigrations.js.map +1 -1
- package/dist/flows/FlowEngine.js.map +1 -1
- package/dist/flows/FlowService.d.ts +10 -1
- package/dist/flows/FlowService.d.ts.map +1 -1
- package/dist/flows/FlowService.js +227 -14
- package/dist/flows/FlowService.js.map +1 -1
- package/dist/flows/FlowValidator.d.ts +2 -1
- package/dist/flows/FlowValidator.d.ts.map +1 -1
- package/dist/flows/FlowValidator.js +89 -4
- package/dist/flows/FlowValidator.js.map +1 -1
- package/dist/flows/types.d.ts +20 -3
- package/dist/flows/types.d.ts.map +1 -1
- package/dist/functions/FunctionService.d.ts +10 -2
- package/dist/functions/FunctionService.d.ts.map +1 -1
- package/dist/functions/FunctionService.js +271 -37
- package/dist/functions/FunctionService.js.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
- package/dist/functions/runtime/QuickJsWasmRuntime.js +189 -177
- package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
- package/dist/functions/types.d.ts +31 -2
- package/dist/functions/types.d.ts.map +1 -1
- package/dist/http/HttpServer.d.ts +7 -1
- package/dist/http/HttpServer.d.ts.map +1 -1
- package/dist/http/HttpServer.js +187 -8
- package/dist/http/HttpServer.js.map +1 -1
- package/dist/http/controllers/ApiKeyController.d.ts +1 -0
- package/dist/http/controllers/ApiKeyController.d.ts.map +1 -1
- package/dist/http/controllers/ApiKeyController.js +47 -1
- package/dist/http/controllers/ApiKeyController.js.map +1 -1
- package/dist/http/controllers/AuthController.d.ts +12 -0
- package/dist/http/controllers/AuthController.d.ts.map +1 -1
- package/dist/http/controllers/AuthController.js +40 -2
- package/dist/http/controllers/AuthController.js.map +1 -1
- package/dist/http/controllers/CronController.d.ts +63 -0
- package/dist/http/controllers/CronController.d.ts.map +1 -0
- package/dist/http/controllers/CronController.js +92 -0
- package/dist/http/controllers/CronController.js.map +1 -0
- package/dist/http/controllers/DatabaseController.d.ts.map +1 -1
- package/dist/http/controllers/DatabaseController.js +53 -0
- package/dist/http/controllers/DatabaseController.js.map +1 -1
- package/dist/http/controllers/FlowController.d.ts.map +1 -1
- package/dist/http/controllers/FlowController.js +45 -4
- package/dist/http/controllers/FlowController.js.map +1 -1
- package/dist/http/controllers/FunctionController.d.ts.map +1 -1
- package/dist/http/controllers/FunctionController.js +16 -2
- package/dist/http/controllers/FunctionController.js.map +1 -1
- package/dist/http/controllers/HealthController.js +2 -2
- package/dist/http/middleware/AppResolutionMiddleware.d.ts +1 -1
- package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -1
- package/dist/http/middleware/AppResolutionMiddleware.js +2 -3
- package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -1
- package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
- package/dist/http/middleware/AuthMiddleware.js +6 -3
- package/dist/http/middleware/AuthMiddleware.js.map +1 -1
- package/dist/http/middleware/ChaosMiddleware.js +6 -6
- package/dist/http/middleware/ChaosMiddleware.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/queue/QueueService.d.ts +9 -0
- package/dist/queue/QueueService.d.ts.map +1 -1
- package/dist/queue/QueueService.js +143 -60
- package/dist/queue/QueueService.js.map +1 -1
- package/dist/queue/drivers/SqliteQueueDriver.d.ts +3 -0
- package/dist/queue/drivers/SqliteQueueDriver.d.ts.map +1 -1
- package/dist/queue/drivers/SqliteQueueDriver.js +315 -255
- package/dist/queue/drivers/SqliteQueueDriver.js.map +1 -1
- package/dist/records/FtsService.d.ts +7 -3
- package/dist/records/FtsService.d.ts.map +1 -1
- package/dist/records/FtsService.js +69 -5
- package/dist/records/FtsService.js.map +1 -1
- package/dist/records/QueryFilterParser.d.ts.map +1 -1
- package/dist/records/QueryFilterParser.js +58 -20
- package/dist/records/QueryFilterParser.js.map +1 -1
- package/dist/records/RecordSanitizer.d.ts.map +1 -1
- package/dist/records/RecordSanitizer.js +32 -4
- package/dist/records/RecordSanitizer.js.map +1 -1
- package/dist/records/RecordService.d.ts +6 -0
- package/dist/records/RecordService.d.ts.map +1 -1
- package/dist/records/RecordService.js +95 -14
- package/dist/records/RecordService.js.map +1 -1
- package/dist/records/RecordValidator.d.ts +10 -0
- package/dist/records/RecordValidator.d.ts.map +1 -1
- package/dist/records/RecordValidator.js +110 -2
- package/dist/records/RecordValidator.js.map +1 -1
- package/dist/records/fts/IFtsDriver.d.ts +7 -6
- package/dist/records/fts/IFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/MssqlFtsDriver.d.ts +5 -1
- package/dist/records/fts/MssqlFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/MssqlFtsDriver.js +35 -3
- package/dist/records/fts/MssqlFtsDriver.js.map +1 -1
- package/dist/records/fts/PostgresFtsDriver.d.ts +9 -2
- package/dist/records/fts/PostgresFtsDriver.d.ts.map +1 -1
- package/dist/records/fts/PostgresFtsDriver.js +116 -11
- package/dist/records/fts/PostgresFtsDriver.js.map +1 -1
- package/dist/records/fts/SqliteFts5Driver.d.ts +7 -1
- package/dist/records/fts/SqliteFts5Driver.d.ts.map +1 -1
- package/dist/records/fts/SqliteFts5Driver.js +66 -6
- package/dist/records/fts/SqliteFts5Driver.js.map +1 -1
- package/dist/schema/OpenApiGenerator.d.ts.map +1 -1
- package/dist/schema/OpenApiGenerator.js +103 -3
- package/dist/schema/OpenApiGenerator.js.map +1 -1
- package/dist/schema/models/Field.d.ts +1 -0
- package/dist/schema/models/Field.d.ts.map +1 -1
- package/dist/snapshots/SnapshotService.d.ts.map +1 -1
- package/dist/snapshots/SnapshotService.js +21 -9
- package/dist/snapshots/SnapshotService.js.map +1 -1
- package/dist/snapshots/drivers/LogicalSnapshotDriver.d.ts.map +1 -1
- package/dist/snapshots/drivers/LogicalSnapshotDriver.js +2 -0
- package/dist/snapshots/drivers/LogicalSnapshotDriver.js.map +1 -1
- package/dist/templates/definitions/ecommerce.js +6 -6
- package/dist/templates/definitions/ecommerce.js.map +1 -1
- package/dist/webhooks/WebhookService.js +1 -1
- package/package.json +5 -3
|
@@ -1,979 +1,983 @@
|
|
|
1
|
-
// Serverless Functions Manager Module for NodeStack Admin UI
|
|
2
|
-
// Core state, functions overview list, and global execution logs
|
|
3
|
-
|
|
4
|
-
// ==========================================
|
|
5
|
-
// 1. State & Constants
|
|
6
|
-
// ==========================================
|
|
7
|
-
|
|
8
|
-
let functionsState = {
|
|
9
|
-
currentView: 'list', // 'list' | 'editor'
|
|
10
|
-
subTab: 'functions', // 'functions' | 'logs'
|
|
11
|
-
editorTab: 'code', // 'code' | 'test' | 'config' | 'logs'
|
|
12
|
-
isCtxRefExpanded: false, // vertically collapsible, collapsed by default
|
|
13
|
-
cmEditor: null, // active CodeMirror instance
|
|
14
|
-
functions: [],
|
|
15
|
-
stats: {
|
|
16
|
-
totalFunctions: 0,
|
|
17
|
-
activeFunctions: 0,
|
|
18
|
-
totalExecutions: 0,
|
|
19
|
-
successExecutions: 0,
|
|
20
|
-
failedExecutions: 0,
|
|
21
|
-
successRate: '100%',
|
|
22
|
-
},
|
|
23
|
-
logs: [],
|
|
24
|
-
editorLogs: [],
|
|
25
|
-
logFilter: {
|
|
26
|
-
functionId: '',
|
|
27
|
-
status: 'all',
|
|
28
|
-
page: 1,
|
|
29
|
-
perPage: 25,
|
|
30
|
-
totalItems: 0,
|
|
31
|
-
totalPages: 1,
|
|
32
|
-
},
|
|
33
|
-
activeFunctionForEdit: null,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
if (typeof window !== 'undefined') {
|
|
37
|
-
window.functionsState = functionsState;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const STARTER_RECIPES = {
|
|
41
|
-
starter: `// Serverless Function Starter
|
|
42
|
-
export default async function(core, context) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
<span
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
document.getElementById('tab-btn-fn-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
if (
|
|
254
|
-
if (
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
sidebarBadge.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
sidebarBadge.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
<
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
<
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
<
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
</td>
|
|
366
|
-
<td style="padding: 12px 16px;
|
|
367
|
-
${
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
<button class="btn btn-secondary btn-sm" onclick="openFunctionEditor('${fn.id}', true, '
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">
|
|
412
|
-
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
toast(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
<
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
function
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
<
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
<div class="confirm-dialog-banner
|
|
564
|
-
<
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
function
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
<td style="padding: 10px 14px;
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
<
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">
|
|
736
|
-
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">
|
|
737
|
-
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
<
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
<div>
|
|
831
|
-
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">
|
|
832
|
-
<pre style="background:
|
|
833
|
-
</div>
|
|
834
|
-
<div>
|
|
835
|
-
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">
|
|
836
|
-
<pre style="background: var(--bg-card-hover); padding: 10px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height:
|
|
837
|
-
</div>
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
<
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
function
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
window.
|
|
953
|
-
window.
|
|
954
|
-
window.
|
|
955
|
-
window.
|
|
956
|
-
window.
|
|
957
|
-
window.
|
|
958
|
-
window.
|
|
959
|
-
window.
|
|
960
|
-
window.
|
|
961
|
-
window.
|
|
962
|
-
window.
|
|
963
|
-
window.
|
|
964
|
-
window.
|
|
965
|
-
window.
|
|
966
|
-
window.
|
|
967
|
-
window.
|
|
968
|
-
window.
|
|
969
|
-
window.
|
|
970
|
-
window.
|
|
971
|
-
window.
|
|
972
|
-
window.
|
|
973
|
-
window.
|
|
974
|
-
window.
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
1
|
+
// Serverless Functions Manager Module for NodeStack Admin UI
|
|
2
|
+
// Core state, functions overview list, and global execution logs
|
|
3
|
+
|
|
4
|
+
// ==========================================
|
|
5
|
+
// 1. State & Constants
|
|
6
|
+
// ==========================================
|
|
7
|
+
|
|
8
|
+
let functionsState = {
|
|
9
|
+
currentView: 'list', // 'list' | 'editor'
|
|
10
|
+
subTab: 'functions', // 'functions' | 'logs'
|
|
11
|
+
editorTab: 'code', // 'code' | 'test' | 'config' | 'logs'
|
|
12
|
+
isCtxRefExpanded: false, // vertically collapsible, collapsed by default
|
|
13
|
+
cmEditor: null, // active CodeMirror instance
|
|
14
|
+
functions: [],
|
|
15
|
+
stats: {
|
|
16
|
+
totalFunctions: 0,
|
|
17
|
+
activeFunctions: 0,
|
|
18
|
+
totalExecutions: 0,
|
|
19
|
+
successExecutions: 0,
|
|
20
|
+
failedExecutions: 0,
|
|
21
|
+
successRate: '100%',
|
|
22
|
+
},
|
|
23
|
+
logs: [],
|
|
24
|
+
editorLogs: [],
|
|
25
|
+
logFilter: {
|
|
26
|
+
functionId: '',
|
|
27
|
+
status: 'all',
|
|
28
|
+
page: 1,
|
|
29
|
+
perPage: 25,
|
|
30
|
+
totalItems: 0,
|
|
31
|
+
totalPages: 1,
|
|
32
|
+
},
|
|
33
|
+
activeFunctionForEdit: null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (typeof window !== 'undefined') {
|
|
37
|
+
window.functionsState = functionsState;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const STARTER_RECIPES = {
|
|
41
|
+
starter: `// Serverless Function Starter
|
|
42
|
+
export default async function(core, context) {
|
|
43
|
+
const logger = core.observability.logger;
|
|
44
|
+
logger.log("Invoked function in app:", context.app.slug);
|
|
45
|
+
const name = context.request?.body?.name || "World";
|
|
46
|
+
return {
|
|
47
|
+
status: 200,
|
|
48
|
+
body: { message: "Hello, " + name + "!" }
|
|
49
|
+
};
|
|
50
|
+
}`,
|
|
51
|
+
discount: `// Calculate cart discount with RuleEngine access rules preserved
|
|
52
|
+
export default async function(core, context) {
|
|
53
|
+
const { cartTotal, couponCode } = context.request?.body || {};
|
|
54
|
+
let discountRate = 0;
|
|
55
|
+
|
|
56
|
+
if (couponCode === "SAVE20") {
|
|
57
|
+
discountRate = 0.20;
|
|
58
|
+
} else if (couponCode === "VIP50" && context.request?.auth) {
|
|
59
|
+
discountRate = 0.50;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const discount = (cartTotal || 0) * discountRate;
|
|
63
|
+
const finalTotal = Math.max(0, (cartTotal || 0) - discount);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
status: 200,
|
|
67
|
+
headers: { 'x-applied-rate': (discountRate * 100) + '%' },
|
|
68
|
+
body: {
|
|
69
|
+
originalTotal: cartTotal,
|
|
70
|
+
discount: discount,
|
|
71
|
+
finalTotal: finalTotal
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}`,
|
|
75
|
+
hook: `// Lifecycle Hook: validate and enrich records before creation
|
|
76
|
+
export default async function(core, context) {
|
|
77
|
+
if (context.event && context.event.record) {
|
|
78
|
+
const record = context.event.record;
|
|
79
|
+
|
|
80
|
+
// 1. Validation guardrail
|
|
81
|
+
if (record.amount !== undefined && record.amount < 0) {
|
|
82
|
+
return { status: 400, body: { cancel: true, reason: "Amount cannot be negative" } };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 2. Data enrichment / normalization
|
|
86
|
+
if (record.title) {
|
|
87
|
+
record.slug = record.title.toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
88
|
+
}
|
|
89
|
+
record.status = "processed";
|
|
90
|
+
|
|
91
|
+
return { status: 200, body: { record: record } };
|
|
92
|
+
}
|
|
93
|
+
return { status: 200 };
|
|
94
|
+
}`,
|
|
95
|
+
fetch: `// Outbound HTTP Integration with SSRF Guardrails
|
|
96
|
+
export default async function(core, context) {
|
|
97
|
+
// Guarded fetch rejects private IPs, loopback, and cloud metadata
|
|
98
|
+
const res = await core.network.http.fetch('https://httpbin.org/json');
|
|
99
|
+
const data = await res.json();
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
status: 200,
|
|
103
|
+
body: {
|
|
104
|
+
origin: data.origin,
|
|
105
|
+
url: data.url,
|
|
106
|
+
timestamp: new Date().toISOString()
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}`
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (typeof window !== 'undefined') {
|
|
113
|
+
window.STARTER_RECIPES = STARTER_RECIPES;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ==========================================
|
|
117
|
+
// 2. Functions Overview Page & Statistics
|
|
118
|
+
// ==========================================
|
|
119
|
+
|
|
120
|
+
function renderFunctionsView() {
|
|
121
|
+
if (functionsState.currentView === 'editor' && functionsState.activeFunctionForEdit) {
|
|
122
|
+
if (typeof renderFunctionEditorView === 'function') {
|
|
123
|
+
renderFunctionEditorView(functionsState.activeFunctionForEdit);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const container = document.getElementById('page-view-functions') || document.getElementById('main-body');
|
|
129
|
+
if (!container) return;
|
|
130
|
+
|
|
131
|
+
container.innerHTML = `
|
|
132
|
+
<div class="webhooks-container" style="max-width: 1400px; margin: 0 auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem;">
|
|
133
|
+
<!-- Header -->
|
|
134
|
+
<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem;">
|
|
135
|
+
<div>
|
|
136
|
+
<h2 style="font-size: 1.35rem; font-weight: 700; color: var(--text-main); margin: 0 0 0.25rem 0; display: flex; align-items: center; gap: 0.5rem;">
|
|
137
|
+
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
138
|
+
<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>
|
|
139
|
+
</svg>
|
|
140
|
+
Serverless Functions
|
|
141
|
+
</h2>
|
|
142
|
+
<p style="font-size: 0.85rem; color: var(--text-muted); margin: 0;">
|
|
143
|
+
Sandboxed in-engine JavaScript/TypeScript lambda functions wired to API endpoints and lifecycle hooks.
|
|
144
|
+
</p>
|
|
145
|
+
</div>
|
|
146
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
147
|
+
<button class="btn btn-secondary btn-sm" onclick="refreshFunctionsView()" title="Refresh Functions & Stats">
|
|
148
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 4v6h-6M1 20v-6h6"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>
|
|
149
|
+
Refresh
|
|
150
|
+
</button>
|
|
151
|
+
<button class="btn btn-primary btn-sm" onclick="openCreateFunctionPage()">
|
|
152
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
|
153
|
+
New Function
|
|
154
|
+
</button>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<!-- Stats Grid -->
|
|
159
|
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;">
|
|
160
|
+
<div class="webhook-stat-card">
|
|
161
|
+
<span class="webhook-stat-label">Active Functions</span>
|
|
162
|
+
<div class="webhook-stat-value">
|
|
163
|
+
<span id="fn-stat-active">0</span>
|
|
164
|
+
<span class="webhook-stat-subtext" id="fn-stat-total">/ 0 total</span>
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
<div class="webhook-stat-card">
|
|
168
|
+
<span class="webhook-stat-label">Total Executions</span>
|
|
169
|
+
<div class="webhook-stat-value" id="fn-stat-executions">0</div>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="webhook-stat-card">
|
|
172
|
+
<span class="webhook-stat-label">Success Rate</span>
|
|
173
|
+
<div class="webhook-stat-value" style="color: var(--accent-success);" id="fn-stat-rate">100%</div>
|
|
174
|
+
</div>
|
|
175
|
+
<div class="webhook-stat-card">
|
|
176
|
+
<span class="webhook-stat-label">Failed Runs</span>
|
|
177
|
+
<div class="webhook-stat-value" style="color: var(--accent-danger);" id="fn-stat-failed">0</div>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
<!-- Subtabs Bar -->
|
|
182
|
+
<div class="webhooks-tabs-bar" style="display: flex; align-items: center; gap: 0.5rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.5rem;">
|
|
183
|
+
<button class="webhook-tab-btn ${functionsState.subTab === 'functions' ? 'active' : ''}" id="tab-btn-fn-list" onclick="switchFunctionsTab('functions')">
|
|
184
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
|
|
185
|
+
Configured Functions
|
|
186
|
+
</button>
|
|
187
|
+
<button class="webhook-tab-btn ${functionsState.subTab === 'logs' ? 'active' : ''}" id="tab-btn-fn-logs" onclick="switchFunctionsTab('logs')">
|
|
188
|
+
<svg width="14" height="14" 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>
|
|
189
|
+
Execution History & Logs
|
|
190
|
+
</button>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<!-- Tab Content Area -->
|
|
194
|
+
<div id="functions-tab-content"></div>
|
|
195
|
+
</div>
|
|
196
|
+
`;
|
|
197
|
+
|
|
198
|
+
loadFunctionStats();
|
|
199
|
+
if (functionsState.subTab === 'functions') {
|
|
200
|
+
loadFunctionsList();
|
|
201
|
+
} else {
|
|
202
|
+
loadFunctionLogs();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function switchFunctionsTab(tab, pushState = true) {
|
|
207
|
+
functionsState.subTab = tab;
|
|
208
|
+
document.getElementById('tab-btn-fn-list')?.classList.toggle('active', tab === 'functions');
|
|
209
|
+
document.getElementById('tab-btn-fn-logs')?.classList.toggle('active', tab === 'logs');
|
|
210
|
+
|
|
211
|
+
if (pushState) {
|
|
212
|
+
const path = (tab === 'logs') ? '/_/functions/logs' : '/_/functions';
|
|
213
|
+
if (typeof updateUrl === 'function') {
|
|
214
|
+
updateUrl(path);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (typeof updateBreadcrumbs === 'function') {
|
|
219
|
+
updateBreadcrumbs();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (tab === 'functions') {
|
|
223
|
+
loadFunctionsList();
|
|
224
|
+
} else {
|
|
225
|
+
loadFunctionLogs();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function refreshFunctionsView() {
|
|
230
|
+
await loadFunctionStats();
|
|
231
|
+
if (functionsState.subTab === 'functions') {
|
|
232
|
+
await loadFunctionsList();
|
|
233
|
+
} else {
|
|
234
|
+
await loadFunctionLogs();
|
|
235
|
+
}
|
|
236
|
+
toast('Functions data refreshed', 'info');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function loadFunctionStats() {
|
|
240
|
+
try {
|
|
241
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
242
|
+
const endpoint = slug && slug !== 'default' ? `/api/apps/${slug}/functions/stats` : '/api/functions/stats';
|
|
243
|
+
const res = await api(endpoint);
|
|
244
|
+
if (res) {
|
|
245
|
+
functionsState.stats = res;
|
|
246
|
+
const elActive = document.getElementById('fn-stat-active');
|
|
247
|
+
const elTotal = document.getElementById('fn-stat-total');
|
|
248
|
+
const elExec = document.getElementById('fn-stat-executions');
|
|
249
|
+
const elRate = document.getElementById('fn-stat-rate');
|
|
250
|
+
const elFailed = document.getElementById('fn-stat-failed');
|
|
251
|
+
|
|
252
|
+
if (elActive) elActive.textContent = res.activeFunctions || 0;
|
|
253
|
+
if (elTotal) elTotal.textContent = `/ ${res.totalFunctions || 0} total`;
|
|
254
|
+
if (elExec) elExec.textContent = res.totalExecutions || 0;
|
|
255
|
+
if (elRate) elRate.textContent = res.successRate || '100%';
|
|
256
|
+
if (elFailed) elFailed.textContent = res.failedExecutions || 0;
|
|
257
|
+
|
|
258
|
+
// Update sidebar counter badge
|
|
259
|
+
const sidebarBadge = document.getElementById('sidebar-functions-count');
|
|
260
|
+
if (sidebarBadge) {
|
|
261
|
+
sidebarBadge.textContent = res.totalFunctions || 0;
|
|
262
|
+
sidebarBadge.style.display = (res.totalFunctions > 0) ? 'inline-block' : 'none';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const homeFnEl = document.getElementById('home-stat-functions');
|
|
266
|
+
const homeFnSubEl = document.getElementById('home-stat-functions-sub');
|
|
267
|
+
if (homeFnEl) {
|
|
268
|
+
homeFnEl.textContent = (res.totalFunctions !== undefined ? res.totalFunctions : (res.activeFunctions || 0)).toString();
|
|
269
|
+
}
|
|
270
|
+
if (homeFnSubEl) {
|
|
271
|
+
const active = res.activeFunctions || 0;
|
|
272
|
+
const execs = res.totalExecutions || 0;
|
|
273
|
+
homeFnSubEl.textContent = `${active} active${execs > 0 ? ` • ${execs} runs` : ' • 0 runs'}`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
console.warn('Failed to load function stats:', err);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function loadFunctionsList() {
|
|
282
|
+
const container = document.getElementById('functions-tab-content');
|
|
283
|
+
if (!container) return;
|
|
284
|
+
|
|
285
|
+
container.innerHTML = `
|
|
286
|
+
<div style="display: flex; align-items: center; justify-content: center; padding: 4rem; color: var(--text-muted);">
|
|
287
|
+
<span class="spinner" style="margin-right: 8px;"></span> Loading serverless functions...
|
|
288
|
+
</div>
|
|
289
|
+
`;
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
293
|
+
const endpoint = slug && slug !== 'default' ? `/api/apps/${slug}/functions` : '/api/functions';
|
|
294
|
+
const list = await api(endpoint);
|
|
295
|
+
functionsState.functions = Array.isArray(list) ? list : [];
|
|
296
|
+
|
|
297
|
+
// Sync count badge
|
|
298
|
+
const count = functionsState.functions.length;
|
|
299
|
+
const sidebarBadge = document.getElementById('sidebar-functions-count');
|
|
300
|
+
if (sidebarBadge) {
|
|
301
|
+
sidebarBadge.textContent = count;
|
|
302
|
+
sidebarBadge.style.display = count > 0 ? 'inline-block' : 'none';
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
renderFunctionsTable(functionsState.functions);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
container.innerHTML = `
|
|
308
|
+
<div class="card" style="padding: 2rem; text-align: center; color: var(--accent-danger);">
|
|
309
|
+
<p>Failed to load functions: ${escapeHtml(err.message || String(err))}</p>
|
|
310
|
+
<button class="btn btn-secondary btn-sm" onclick="loadFunctionsList()">Try Again</button>
|
|
311
|
+
</div>
|
|
312
|
+
`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function renderFunctionsTable(functions) {
|
|
317
|
+
const container = document.getElementById('functions-tab-content');
|
|
318
|
+
if (!container) return;
|
|
319
|
+
|
|
320
|
+
if (!functions || functions.length === 0) {
|
|
321
|
+
container.innerHTML = `
|
|
322
|
+
<div class="card" style="padding: 3.5rem 1.5rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1rem;">
|
|
323
|
+
<div style="width: 56px; height: 56px; border-radius: 50%; background: var(--bg-card-hover); display: flex; align-items: center; justify-content: center; color: var(--accent-primary);">
|
|
324
|
+
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
|
|
325
|
+
</div>
|
|
326
|
+
<div>
|
|
327
|
+
<h3 style="margin: 0 0 0.5rem 0; font-size: 1.25rem; font-weight: 600;">No Serverless Functions Yet</h3>
|
|
328
|
+
<p style="margin: 0; color: var(--text-muted); font-size: 0.875rem; max-width: 480px;">
|
|
329
|
+
Create lightweight, sandboxed functions to implement custom backend logic, third-party webhooks, and database triggers.
|
|
330
|
+
</p>
|
|
331
|
+
</div>
|
|
332
|
+
<button class="btn btn-primary btn-sm" onclick="openCreateFunctionPage()">
|
|
333
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
|
334
|
+
Create First Function
|
|
335
|
+
</button>
|
|
336
|
+
</div>
|
|
337
|
+
`;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
342
|
+
const invokePrefix = slug && slug !== 'default' ? `/api/apps/${slug}/functions` : '/api/functions';
|
|
343
|
+
|
|
344
|
+
const rows = functions.map(fn => {
|
|
345
|
+
const isEnabled = fn.enabled !== false;
|
|
346
|
+
const authBadgeClass = fn.authPolicy === 'public' ? 'badge-success' : (fn.authPolicy === 'admin' ? 'badge-danger' : (fn.authPolicy === 'custom' ? 'badge-warning' : 'badge-primary'));
|
|
347
|
+
const authLabel = fn.authPolicy === 'custom' ? 'CUSTOM RULE' : (fn.authPolicy || 'public').toUpperCase();
|
|
348
|
+
const invokePath = `${invokePrefix}/${fn.name}/invoke`;
|
|
349
|
+
|
|
350
|
+
return `
|
|
351
|
+
<tr style="border-bottom: 1px solid var(--border-subtle); transition: background 0.15s ease;">
|
|
352
|
+
<td style="padding: 12px 16px;">
|
|
353
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
354
|
+
<span class="status-indicator ${isEnabled ? 'status-active' : 'status-inactive'}" title="${isEnabled ? 'Active' : 'Disabled'}"></span>
|
|
355
|
+
<div>
|
|
356
|
+
<div style="display: flex; align-items: center; gap: 6px;">
|
|
357
|
+
<a href="javascript:void(0)" onclick="openFunctionEditor('${fn.id}')" style="font-weight: 600; color: var(--accent-primary); text-decoration: none; font-size: 13.5px; font-family: monospace;">
|
|
358
|
+
${escapeHtml(fn.name)}
|
|
359
|
+
</a>
|
|
360
|
+
<code style="font-size: 10px; color: var(--text-muted); background: var(--bg-card-hover); padding: 1px 5px; border-radius: 4px;" title="Unique Function ID">${escapeHtml(fn.id)}</code>
|
|
361
|
+
</div>
|
|
362
|
+
${fn.description ? `<div style="font-size: 11.5px; color: var(--text-muted); margin-top: 2px;">${escapeHtml(fn.description)}</div>` : ''}
|
|
363
|
+
</div>
|
|
364
|
+
</div>
|
|
365
|
+
</td>
|
|
366
|
+
<td style="padding: 12px 16px;">
|
|
367
|
+
<span class="badge ${authBadgeClass}" style="font-size: 11px;">${authLabel}</span>
|
|
368
|
+
${fn.elevated ? '<span class="badge" style="background: rgba(239, 68, 68, 0.15); color: #ef4444; font-size: 10px; margin-left: 4px;" title="Runs with elevated privileges">Elevated</span>' : ''}
|
|
369
|
+
</td>
|
|
370
|
+
<td style="padding: 12px 16px; font-size: 12px;">
|
|
371
|
+
${fn.eventTrigger ? `<code style="font-size: 11.5px; background: var(--bg-card-hover); padding: 2px 6px; border-radius: 4px; color: var(--text-heading);">${escapeHtml(fn.eventTrigger)}</code>` : '<span style="color: var(--text-muted);">None (HTTP only)</span>'}
|
|
372
|
+
</td>
|
|
373
|
+
<td style="padding: 12px 16px; font-size: 11.5px; font-family: monospace; color: var(--text-muted);">
|
|
374
|
+
<div style="display: flex; align-items: center; gap: 6px;">
|
|
375
|
+
<span>ANY ${escapeHtml(invokePath)}</span>
|
|
376
|
+
<button class="btn btn-secondary btn-sm" onclick="copyFunctionEndpoint('${invokePath}')" style="padding: 1px 6px; font-size: 10px;" title="Copy endpoint">
|
|
377
|
+
📋
|
|
378
|
+
</button>
|
|
379
|
+
</div>
|
|
380
|
+
</td>
|
|
381
|
+
<td style="padding: 12px 16px; font-size: 12px; color: var(--text-muted);">
|
|
382
|
+
${fn.timeoutMs || 1000}ms / ${fn.memoryLimitMb || 32}MB
|
|
383
|
+
</td>
|
|
384
|
+
<td style="padding: 12px 16px; text-align: right;">
|
|
385
|
+
<div style="display: inline-flex; align-items: center; gap: 6px;">
|
|
386
|
+
<button class="btn btn-secondary btn-sm" onclick="openFunctionEditor('${fn.id}', true, 'test')" title="Test Function in Sandbox">
|
|
387
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
|
388
|
+
Test
|
|
389
|
+
</button>
|
|
390
|
+
<button class="btn btn-secondary btn-sm" onclick="openFunctionEditor('${fn.id}', true, 'code')" title="Edit Code & Configuration">
|
|
391
|
+
Edit
|
|
392
|
+
</button>
|
|
393
|
+
<button class="btn btn-secondary btn-sm" onclick="toggleFunctionEnabled('${fn.id}', ${!isEnabled})" title="${isEnabled ? 'Disable function' : 'Enable function'}">
|
|
394
|
+
${isEnabled ? 'Disable' : 'Enable'}
|
|
395
|
+
</button>
|
|
396
|
+
<button class="btn btn-secondary btn-sm" data-fn-id="${escapeHtml(fn.id)}" data-fn-name="${escapeHtml(fn.name)}" onclick="deleteFunctionPrompt(this.getAttribute('data-fn-id'), this.getAttribute('data-fn-name'))" style="color: var(--accent-danger);" title="Delete function">
|
|
397
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
|
|
398
|
+
</button>
|
|
399
|
+
</div>
|
|
400
|
+
</td>
|
|
401
|
+
</tr>
|
|
402
|
+
`;
|
|
403
|
+
}).join('');
|
|
404
|
+
|
|
405
|
+
container.innerHTML = `
|
|
406
|
+
<div class="card" style="padding: 0; overflow: hidden;">
|
|
407
|
+
<div style="overflow-x: auto;">
|
|
408
|
+
<table class="table" style="width: 100%; border-collapse: collapse; text-align: left;">
|
|
409
|
+
<thead>
|
|
410
|
+
<tr style="border-bottom: 1px solid var(--border-subtle); background: var(--bg-card-hover);">
|
|
411
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Function</th>
|
|
412
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Auth Policy</th>
|
|
413
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Hook Trigger</th>
|
|
414
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Invoke Endpoint</th>
|
|
415
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Limits</th>
|
|
416
|
+
<th style="padding: 12px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; text-align: right;">Actions</th>
|
|
417
|
+
</tr>
|
|
418
|
+
</thead>
|
|
419
|
+
<tbody>
|
|
420
|
+
${rows}
|
|
421
|
+
</tbody>
|
|
422
|
+
</table>
|
|
423
|
+
</div>
|
|
424
|
+
</div>
|
|
425
|
+
`;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function toggleFunctionEnabled(id, enabled) {
|
|
429
|
+
try {
|
|
430
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
431
|
+
const endpoint = slug && slug !== 'default' ? `/api/apps/${slug}/functions/${id}` : `/api/functions/${id}`;
|
|
432
|
+
await api(endpoint, {
|
|
433
|
+
method: 'PATCH',
|
|
434
|
+
headers: { 'Content-Type': 'application/json' },
|
|
435
|
+
body: JSON.stringify({ enabled }),
|
|
436
|
+
});
|
|
437
|
+
toast(`Function ${enabled ? 'enabled' : 'disabled'}`, 'info');
|
|
438
|
+
await loadFunctionStats();
|
|
439
|
+
await loadFunctionsList();
|
|
440
|
+
} catch (err) {
|
|
441
|
+
toast(err.message || 'Failed to toggle status', 'error');
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function openDeleteFunctionModal(id, name) {
|
|
446
|
+
let modalRoot = document.getElementById('modal-root');
|
|
447
|
+
if (!modalRoot) {
|
|
448
|
+
modalRoot = document.createElement('div');
|
|
449
|
+
modalRoot.id = 'modal-root';
|
|
450
|
+
document.body.appendChild(modalRoot);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const safeId = typeof escapeHtml === 'function' ? escapeHtml(id) : id;
|
|
454
|
+
const safeName = typeof escapeHtml === 'function' ? escapeHtml(name) : name;
|
|
455
|
+
|
|
456
|
+
modalRoot.innerHTML = `
|
|
457
|
+
<div class="modal-backdrop" id="delete-function-backdrop" onclick="if(event.target===this)closeDeleteFunctionModal()">
|
|
458
|
+
<div class="modal confirm-dialog">
|
|
459
|
+
<div class="modal-header" style="border-bottom-color: rgba(239, 68, 68, 0.2);">
|
|
460
|
+
<div style="display: flex; align-items: center; gap: 0.5rem;">
|
|
461
|
+
<span style="font-size: 18px;">⚠️</span>
|
|
462
|
+
<h2 class="modal-title danger" style="font-size: 16px;">Delete Function</h2>
|
|
463
|
+
</div>
|
|
464
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="closeDeleteFunctionModal()" aria-label="Close">✕</button>
|
|
465
|
+
</div>
|
|
466
|
+
<div class="modal-body" id="delete-function-modal-body" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
467
|
+
<p style="font-size: 13px; color: var(--text-main, #cbd5e1); line-height: 1.5; margin: 0;">
|
|
468
|
+
Are you sure you want to delete function <strong style="color: var(--text-heading); font-family: var(--font-mono);">${safeName}</strong>? All invocation history and logs will be permanently removed.
|
|
469
|
+
</p>
|
|
470
|
+
<div class="confirm-dialog-banner danger">
|
|
471
|
+
This action cannot be undone. Invocations to <code>/api/functions/${safeName}/invoke</code> will return 404 Not Found.
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
<div class="modal-footer" id="delete-function-modal-footer" style="padding: 0.75rem 1.25rem;">
|
|
475
|
+
<button type="button" class="btn btn-secondary" onclick="closeDeleteFunctionModal()">Cancel</button>
|
|
476
|
+
<button type="button" class="btn btn-danger" id="btn-confirm-delete-function" data-fn-id="${safeId}">
|
|
477
|
+
Delete Function
|
|
478
|
+
</button>
|
|
479
|
+
</div>
|
|
480
|
+
</div>
|
|
481
|
+
</div>
|
|
482
|
+
`;
|
|
483
|
+
|
|
484
|
+
const deleteBtn = document.getElementById('btn-confirm-delete-function');
|
|
485
|
+
if (deleteBtn) {
|
|
486
|
+
deleteBtn.addEventListener('click', () => confirmDeleteFunction(id, name, false));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
setTimeout(() => {
|
|
490
|
+
document.getElementById('btn-confirm-delete-function')?.focus();
|
|
491
|
+
}, 50);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function closeDeleteFunctionModal() {
|
|
495
|
+
const modalRoot = document.getElementById('modal-root');
|
|
496
|
+
if (modalRoot) modalRoot.innerHTML = '';
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
async function confirmDeleteFunction(id, name, force = false) {
|
|
500
|
+
const actionBtnId = force ? 'btn-force-delete-function' : 'btn-confirm-delete-function';
|
|
501
|
+
const btn = document.getElementById(actionBtnId);
|
|
502
|
+
if (btn) {
|
|
503
|
+
btn.disabled = true;
|
|
504
|
+
btn.textContent = force ? 'Force Deleting...' : 'Deleting...';
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
508
|
+
const basePath = slug && slug !== 'default' ? `/api/apps/${slug}/functions/${id}` : `/api/functions/${id}`;
|
|
509
|
+
const endpoint = force ? `${basePath}?force=true` : basePath;
|
|
510
|
+
|
|
511
|
+
try {
|
|
512
|
+
await api(endpoint, { method: 'DELETE' });
|
|
513
|
+
closeDeleteFunctionModal();
|
|
514
|
+
toast(`Function '${name}' deleted${force ? ' (forced)' : ''}`, 'info');
|
|
515
|
+
if (typeof closeFunctionEditor === 'function') {
|
|
516
|
+
closeFunctionEditor();
|
|
517
|
+
}
|
|
518
|
+
await loadFunctionStats();
|
|
519
|
+
await loadFunctionsList();
|
|
520
|
+
} catch (err) {
|
|
521
|
+
if (err.status === 409 && !force) {
|
|
522
|
+
renderConflictModalState(id, name, err.message);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (btn) {
|
|
526
|
+
btn.disabled = false;
|
|
527
|
+
btn.textContent = force ? 'Force Delete Anyway' : 'Delete Function';
|
|
528
|
+
}
|
|
529
|
+
const body = document.getElementById('delete-function-modal-body');
|
|
530
|
+
if (body) {
|
|
531
|
+
const errBox = document.createElement('div');
|
|
532
|
+
errBox.style.cssText = 'background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.35); border-radius: 6px; padding: 0.75rem; font-size: 12px; color: #ef4444;';
|
|
533
|
+
errBox.textContent = err.message || 'Failed to delete function';
|
|
534
|
+
body.prepend(errBox);
|
|
535
|
+
}
|
|
536
|
+
toast(err.message || 'Failed to delete function', 'error');
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function renderConflictModalState(id, name, conflictMessage) {
|
|
541
|
+
const safeId = typeof escapeHtml === 'function' ? escapeHtml(id) : id;
|
|
542
|
+
const safeName = typeof escapeHtml === 'function' ? escapeHtml(name) : name;
|
|
543
|
+
const safeMsg = typeof escapeHtml === 'function' ? escapeHtml(conflictMessage) : conflictMessage;
|
|
544
|
+
|
|
545
|
+
const modal = document.querySelector('#modal-root .modal');
|
|
546
|
+
if (!modal) return;
|
|
547
|
+
|
|
548
|
+
const header = modal.querySelector('.modal-header');
|
|
549
|
+
if (header) {
|
|
550
|
+
header.style.borderBottomColor = 'rgba(245, 158, 11, 0.3)';
|
|
551
|
+
header.innerHTML = `
|
|
552
|
+
<div style="display: flex; align-items: center; gap: 0.5rem;">
|
|
553
|
+
<span style="font-size: 18px;">⚠️</span>
|
|
554
|
+
<h2 class="modal-title warning" style="font-size: 16px;">Cannot Delete: Flow Dependencies</h2>
|
|
555
|
+
</div>
|
|
556
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="closeDeleteFunctionModal()" aria-label="Close">✕</button>
|
|
557
|
+
`;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const body = document.getElementById('delete-function-modal-body');
|
|
561
|
+
if (body) {
|
|
562
|
+
body.innerHTML = `
|
|
563
|
+
<div class="confirm-dialog-banner warning">
|
|
564
|
+
<div class="confirm-dialog-banner-title">Cannot Delete: Function in Use</div>
|
|
565
|
+
<div>${safeMsg}</div>
|
|
566
|
+
</div>
|
|
567
|
+
<div class="confirm-dialog-banner danger">
|
|
568
|
+
<strong>Warning:</strong> Force deleting function <strong style="font-family: var(--font-mono);">${safeName}</strong> will remove it immediately. Subsequent executions of referencing flows will fail during state execution.
|
|
569
|
+
</div>
|
|
570
|
+
`;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const footer = document.getElementById('delete-function-modal-footer');
|
|
574
|
+
if (footer) {
|
|
575
|
+
footer.innerHTML = `
|
|
576
|
+
<button type="button" class="btn btn-secondary" onclick="closeDeleteFunctionModal()">Cancel (Keep Function)</button>
|
|
577
|
+
<button type="button" class="btn btn-danger" id="btn-force-delete-function" data-fn-id="${safeId}">
|
|
578
|
+
Force Delete Anyway
|
|
579
|
+
</button>
|
|
580
|
+
`;
|
|
581
|
+
const forceBtn = document.getElementById('btn-force-delete-function');
|
|
582
|
+
if (forceBtn) {
|
|
583
|
+
forceBtn.addEventListener('click', () => confirmDeleteFunction(id, name, true));
|
|
584
|
+
}
|
|
585
|
+
setTimeout(() => {
|
|
586
|
+
document.getElementById('btn-force-delete-function')?.focus();
|
|
587
|
+
}, 50);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function deleteFunctionPrompt(id, name) {
|
|
592
|
+
openDeleteFunctionModal(id, name);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function copyFunctionEndpoint(path) {
|
|
596
|
+
const fullUrl = window.location.origin + path;
|
|
597
|
+
if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
|
|
598
|
+
navigator.clipboard.writeText(fullUrl).then(() => {
|
|
599
|
+
toast('Copied function endpoint URL to clipboard', 'info');
|
|
600
|
+
}).catch(() => {
|
|
601
|
+
prompt('Copy function endpoint URL:', fullUrl);
|
|
602
|
+
});
|
|
603
|
+
} else {
|
|
604
|
+
prompt('Copy function endpoint URL:', fullUrl);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// ==========================================
|
|
609
|
+
// 3. Global Execution History & Logs
|
|
610
|
+
// ==========================================
|
|
611
|
+
|
|
612
|
+
async function loadFunctionLogs(page = 1) {
|
|
613
|
+
const container = document.getElementById('functions-tab-content');
|
|
614
|
+
if (!container) return;
|
|
615
|
+
|
|
616
|
+
container.innerHTML = `
|
|
617
|
+
<div style="display: flex; align-items: center; justify-content: center; padding: 4rem; color: var(--text-muted);">
|
|
618
|
+
<span class="spinner" style="margin-right: 8px;"></span> Loading invocation logs...
|
|
619
|
+
</div>
|
|
620
|
+
`;
|
|
621
|
+
|
|
622
|
+
try {
|
|
623
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
624
|
+
const baseUrl = slug && slug !== 'default' ? `/api/apps/${slug}/functions/logs` : '/api/functions/logs';
|
|
625
|
+
const params = new URLSearchParams({
|
|
626
|
+
page: String(page),
|
|
627
|
+
perPage: String(functionsState.logFilter.perPage || 25),
|
|
628
|
+
});
|
|
629
|
+
if (functionsState.logFilter.functionId) {
|
|
630
|
+
params.append('functionId', functionsState.logFilter.functionId);
|
|
631
|
+
}
|
|
632
|
+
if (functionsState.logFilter.status && functionsState.logFilter.status !== 'all') {
|
|
633
|
+
params.append('status', functionsState.logFilter.status);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const res = await api(`${baseUrl}?${params.toString()}`);
|
|
637
|
+
functionsState.logs = res.items || [];
|
|
638
|
+
functionsState.logFilter.page = res.page || 1;
|
|
639
|
+
functionsState.logFilter.totalItems = res.totalItems || 0;
|
|
640
|
+
functionsState.logFilter.totalPages = res.totalPages || 1;
|
|
641
|
+
|
|
642
|
+
renderFunctionLogsTable(functionsState.logs);
|
|
643
|
+
} catch (err) {
|
|
644
|
+
container.innerHTML = `
|
|
645
|
+
<div class="card" style="padding: 2rem; text-align: center; color: var(--accent-danger);">
|
|
646
|
+
<p>Failed to load logs: ${escapeHtml(err.message || String(err))}</p>
|
|
647
|
+
<button class="btn btn-secondary btn-sm" onclick="loadFunctionLogs()">Try Again</button>
|
|
648
|
+
</div>
|
|
649
|
+
`;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function renderFunctionLogsTable(logs) {
|
|
654
|
+
const container = document.getElementById('functions-tab-content');
|
|
655
|
+
if (!container) return;
|
|
656
|
+
|
|
657
|
+
const fnOptions = (functionsState.functions || []).map(f => `
|
|
658
|
+
<option value="${f.id}" ${functionsState.logFilter.functionId === f.id ? 'selected' : ''}>
|
|
659
|
+
${escapeHtml(f.name)}
|
|
660
|
+
</option>
|
|
661
|
+
`).join('');
|
|
662
|
+
|
|
663
|
+
if (!logs || logs.length === 0) {
|
|
664
|
+
container.innerHTML = `
|
|
665
|
+
<div class="card" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
666
|
+
<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;">
|
|
667
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
668
|
+
<select class="input" style="font-size: 12px; padding: 4px 8px;" onchange="filterFunctionLogs(this.value)">
|
|
669
|
+
<option value="">All Functions</option>
|
|
670
|
+
${fnOptions}
|
|
671
|
+
</select>
|
|
672
|
+
</div>
|
|
673
|
+
</div>
|
|
674
|
+
<div style="padding: 3rem 1rem; text-align: center; color: var(--text-muted);">
|
|
675
|
+
No execution logs recorded yet.
|
|
676
|
+
</div>
|
|
677
|
+
</div>
|
|
678
|
+
`;
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const rows = logs.map(l => {
|
|
683
|
+
const isOk = l.status === 'success';
|
|
684
|
+
const statusBadge = isOk
|
|
685
|
+
? `<span class="badge" style="background: rgba(16, 185, 129, 0.15); color: #10b981; font-size: 11px;">${l.statusCode || 200} OK</span>`
|
|
686
|
+
: `<span class="badge" style="background: rgba(239, 68, 68, 0.15); color: #ef4444; font-size: 11px;">${escapeHtml(l.status.toUpperCase())}</span>`;
|
|
687
|
+
|
|
688
|
+
return `
|
|
689
|
+
<tr style="border-bottom: 1px solid var(--border-subtle);">
|
|
690
|
+
<td style="padding: 10px 14px; font-size: 12px; color: var(--text-muted);">${formatTimestamp(l.timestamp || l.createdAt)}</td>
|
|
691
|
+
<td style="padding: 10px 14px;">
|
|
692
|
+
<a href="javascript:void(0)" onclick="openFunctionEditor('${l.functionId}', true, 'logs')" style="font-weight: 600; color: var(--accent-primary); text-decoration: none; font-family: monospace; font-size: 12px;">
|
|
693
|
+
${escapeHtml(l.functionName || l.functionId)}
|
|
694
|
+
</a>
|
|
695
|
+
</td>
|
|
696
|
+
<td style="padding: 10px 14px;">${statusBadge}</td>
|
|
697
|
+
<td style="padding: 10px 14px; font-size: 12px; font-weight: 600;">${l.durationMs}ms</td>
|
|
698
|
+
<td style="padding: 10px 14px;"><code style="font-size: 11px;">${escapeHtml(l.trigger || l.method || 'http')}</code></td>
|
|
699
|
+
<td style="padding: 10px 14px; font-size: 12px; color: var(--text-muted);">${escapeHtml(l.actorId || 'public')}</td>
|
|
700
|
+
<td style="padding: 10px 14px; text-align: right;">
|
|
701
|
+
<button class="btn btn-secondary btn-sm" onclick="viewLogPayload('${l.id}')" title="Inspect Request/Response payload" style="font-size: 11px; padding: 2px 8px;">
|
|
702
|
+
Inspect
|
|
703
|
+
</button>
|
|
704
|
+
</td>
|
|
705
|
+
</tr>
|
|
706
|
+
`;
|
|
707
|
+
}).join('');
|
|
708
|
+
|
|
709
|
+
container.innerHTML = `
|
|
710
|
+
<div class="card" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
711
|
+
<div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;">
|
|
712
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
713
|
+
<select class="input" style="font-size: 12px; padding: 4px 8px;" onchange="filterFunctionLogs(this.value)">
|
|
714
|
+
<option value="">All Functions</option>
|
|
715
|
+
${fnOptions}
|
|
716
|
+
</select>
|
|
717
|
+
<span style="font-size: 12px; color: var(--text-muted);">
|
|
718
|
+
Showing ${logs.length} of ${functionsState.logFilter.totalItems || logs.length} logs
|
|
719
|
+
</span>
|
|
720
|
+
</div>
|
|
721
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
722
|
+
<button class="btn btn-secondary btn-sm" onclick="loadFunctionLogs(${functionsState.logFilter.page || 1})">
|
|
723
|
+
Refresh
|
|
724
|
+
</button>
|
|
725
|
+
<button class="btn btn-danger btn-sm" onclick="openClearLogsModal()">
|
|
726
|
+
Clear Logs
|
|
727
|
+
</button>
|
|
728
|
+
</div>
|
|
729
|
+
</div>
|
|
730
|
+
|
|
731
|
+
<div style="overflow-x: auto; border: 1px solid var(--border-subtle); border-radius: 6px;">
|
|
732
|
+
<table class="table" style="width: 100%; border-collapse: collapse; text-align: left; font-size: 13px;">
|
|
733
|
+
<thead>
|
|
734
|
+
<tr style="border-bottom: 1px solid var(--border-subtle); background: var(--bg-card-hover);">
|
|
735
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Timestamp</th>
|
|
736
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Function</th>
|
|
737
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Status</th>
|
|
738
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Latency</th>
|
|
739
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Trigger / Method</th>
|
|
740
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase;">Caller</th>
|
|
741
|
+
<th style="padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; text-align: right;">Payload</th>
|
|
742
|
+
</tr>
|
|
743
|
+
</thead>
|
|
744
|
+
<tbody>
|
|
745
|
+
${rows}
|
|
746
|
+
</tbody>
|
|
747
|
+
</table>
|
|
748
|
+
</div>
|
|
749
|
+
</div>
|
|
750
|
+
`;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function filterFunctionLogs(fnId) {
|
|
754
|
+
functionsState.logFilter.functionId = fnId || '';
|
|
755
|
+
loadFunctionLogs(1);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function viewFunctionLogs(functionId) {
|
|
759
|
+
switchFunctionsTab('logs');
|
|
760
|
+
filterFunctionLogs(functionId);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
async function viewLogPayload(logId) {
|
|
764
|
+
let log = (functionsState.editorLogs || []).find(l => l.id === logId)
|
|
765
|
+
|| (functionsState.logs || []).find(l => l.id === logId);
|
|
766
|
+
|
|
767
|
+
if (!log) {
|
|
768
|
+
try {
|
|
769
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
770
|
+
const baseUrl = slug && slug !== 'default' ? `/api/apps/${slug}/functions/logs` : '/api/functions/logs';
|
|
771
|
+
const res = await api(`${baseUrl}?perPage=100`);
|
|
772
|
+
if (res && res.items) {
|
|
773
|
+
log = res.items.find(l => l.id === logId);
|
|
774
|
+
}
|
|
775
|
+
} catch (_) {}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (!log) {
|
|
779
|
+
if (typeof toast === 'function') toast('Execution log details not found', 'warning');
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
let modalRoot = document.getElementById('modal-root');
|
|
784
|
+
if (!modalRoot) {
|
|
785
|
+
modalRoot = document.createElement('div');
|
|
786
|
+
modalRoot.id = 'modal-root';
|
|
787
|
+
document.body.appendChild(modalRoot);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
let consoleOutput = '(No console output logged)';
|
|
791
|
+
if (log.logs) {
|
|
792
|
+
if (Array.isArray(log.logs) && log.logs.length > 0) {
|
|
793
|
+
consoleOutput = log.logs.join('\n');
|
|
794
|
+
} else if (typeof log.logs === 'string' && log.logs.trim().length > 0) {
|
|
795
|
+
consoleOutput = log.logs;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
let reqFormatted = '{}';
|
|
800
|
+
if (log.requestPayload) {
|
|
801
|
+
try {
|
|
802
|
+
reqFormatted = JSON.stringify(typeof log.requestPayload === 'string' ? JSON.parse(log.requestPayload) : log.requestPayload, null, 2);
|
|
803
|
+
} catch {
|
|
804
|
+
reqFormatted = String(log.requestPayload);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
let resFormatted = '{}';
|
|
809
|
+
if (log.responsePayload) {
|
|
810
|
+
try {
|
|
811
|
+
resFormatted = JSON.stringify(typeof log.responsePayload === 'string' ? JSON.parse(log.responsePayload) : log.responsePayload, null, 2);
|
|
812
|
+
} catch {
|
|
813
|
+
resFormatted = String(log.error || log.responsePayload);
|
|
814
|
+
}
|
|
815
|
+
} else if (log.error) {
|
|
816
|
+
resFormatted = String(log.error);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
modalRoot.innerHTML = `
|
|
820
|
+
<div class="modal-backdrop" onclick="this.remove()">
|
|
821
|
+
<div class="modal-dialog" style="max-width: 720px; width: 95%; max-height: 85vh; display: flex; flex-direction: column; background: var(--bg-card); border-radius: 12px; border: 1px solid var(--border-subtle); overflow: hidden;" onclick="event.stopPropagation()">
|
|
822
|
+
<div style="display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border-subtle);">
|
|
823
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
824
|
+
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 600;">Execution Payload Inspector</h3>
|
|
825
|
+
<span class="badge" style="font-size: 11px;">${log.durationMs}ms</span>
|
|
826
|
+
</div>
|
|
827
|
+
<button class="btn btn-secondary btn-sm" onclick="this.closest('.modal-backdrop').remove()" style="border: none; font-size: 18px; line-height: 1;">✕</button>
|
|
828
|
+
</div>
|
|
829
|
+
<div style="flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px;">
|
|
830
|
+
<div>
|
|
831
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Console Output Logs</label>
|
|
832
|
+
<pre style="background: #0f172a; color: #38bdf8; padding: 10px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height: 140px; overflow-y: auto; margin: 0; white-space: pre-wrap;">${escapeHtml(consoleOutput)}</pre>
|
|
833
|
+
</div>
|
|
834
|
+
<div>
|
|
835
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Request Payload</label>
|
|
836
|
+
<pre style="background: var(--bg-card-hover); padding: 10px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height: 160px; overflow-y: auto; margin: 0;">${escapeHtml(reqFormatted)}</pre>
|
|
837
|
+
</div>
|
|
838
|
+
<div>
|
|
839
|
+
<label style="display: block; font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted);">Response Payload</label>
|
|
840
|
+
<pre style="background: var(--bg-card-hover); padding: 10px; border-radius: 6px; font-family: monospace; font-size: 11px; max-height: 180px; overflow-y: auto; margin: 0; color: ${log.status === 'success' ? '#a7f3d0' : '#f87171'};">${escapeHtml(resFormatted)}</pre>
|
|
841
|
+
</div>
|
|
842
|
+
</div>
|
|
843
|
+
<div style="padding: 12px 20px; border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end;">
|
|
844
|
+
<button class="btn btn-secondary btn-sm" onclick="this.closest('.modal-backdrop').remove()">Close</button>
|
|
845
|
+
</div>
|
|
846
|
+
</div>
|
|
847
|
+
</div>
|
|
848
|
+
`;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function openClearLogsModal() {
|
|
852
|
+
let modalRoot = document.getElementById('modal-root');
|
|
853
|
+
if (!modalRoot) {
|
|
854
|
+
modalRoot = document.createElement('div');
|
|
855
|
+
modalRoot.id = 'modal-root';
|
|
856
|
+
document.body.appendChild(modalRoot);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
modalRoot.innerHTML = `
|
|
860
|
+
<div class="modal-backdrop" id="clear-logs-backdrop" onclick="if(event.target===this)closeClearLogsModal()">
|
|
861
|
+
<div class="modal confirm-dialog">
|
|
862
|
+
<div class="modal-header" style="border-bottom-color: rgba(239, 68, 68, 0.2);">
|
|
863
|
+
<div style="display: flex; align-items: center; gap: 0.5rem;">
|
|
864
|
+
<span style="font-size: 18px;">⚠️</span>
|
|
865
|
+
<h2 class="modal-title danger" style="font-size: 16px;">Clear Execution Logs</h2>
|
|
866
|
+
</div>
|
|
867
|
+
<button type="button" class="btn btn-secondary btn-sm" onclick="closeClearLogsModal()" aria-label="Close">✕</button>
|
|
868
|
+
</div>
|
|
869
|
+
<div class="modal-body" style="padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem;">
|
|
870
|
+
<p style="font-size: 13px; color: var(--text-main, #cbd5e1); line-height: 1.5; margin: 0;">
|
|
871
|
+
Are you sure you want to permanently clear all function invocation logs?
|
|
872
|
+
</p>
|
|
873
|
+
<div class="confirm-dialog-banner danger">
|
|
874
|
+
This will delete all historical logs, timestamps, status codes, and console logs. This action cannot be undone.
|
|
875
|
+
</div>
|
|
876
|
+
</div>
|
|
877
|
+
<div class="modal-footer" style="padding: 0.75rem 1.25rem;">
|
|
878
|
+
<button type="button" class="btn btn-secondary" onclick="closeClearLogsModal()">Cancel</button>
|
|
879
|
+
<button type="button" class="btn btn-danger" id="btn-confirm-clear-logs" onclick="confirmClearAllLogs()">
|
|
880
|
+
Clear All Logs
|
|
881
|
+
</button>
|
|
882
|
+
</div>
|
|
883
|
+
</div>
|
|
884
|
+
</div>
|
|
885
|
+
`;
|
|
886
|
+
|
|
887
|
+
setTimeout(() => {
|
|
888
|
+
document.getElementById('btn-confirm-clear-logs')?.focus();
|
|
889
|
+
}, 50);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function closeClearLogsModal() {
|
|
893
|
+
const modalRoot = document.getElementById('modal-root');
|
|
894
|
+
if (modalRoot) modalRoot.innerHTML = '';
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
async function confirmClearAllLogs() {
|
|
898
|
+
const btn = document.getElementById('btn-confirm-clear-logs');
|
|
899
|
+
if (btn) {
|
|
900
|
+
btn.disabled = true;
|
|
901
|
+
btn.textContent = 'Clearing...';
|
|
902
|
+
}
|
|
903
|
+
try {
|
|
904
|
+
const slug = typeof getActiveAppSlug === 'function' ? getActiveAppSlug() : 'default';
|
|
905
|
+
const endpoint = slug && slug !== 'default' ? `/api/apps/${slug}/functions/logs` : '/api/functions/logs';
|
|
906
|
+
await api(endpoint, { method: 'DELETE' });
|
|
907
|
+
closeClearLogsModal();
|
|
908
|
+
toast('Execution logs cleared', 'info');
|
|
909
|
+
await loadFunctionLogs();
|
|
910
|
+
} catch (err) {
|
|
911
|
+
if (btn) {
|
|
912
|
+
btn.disabled = false;
|
|
913
|
+
btn.textContent = 'Clear All Logs';
|
|
914
|
+
}
|
|
915
|
+
toast(err.message || 'Failed to clear logs', 'error');
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function clearAllFunctionLogs() {
|
|
920
|
+
openClearLogsModal();
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function formatTimestamp(iso) {
|
|
924
|
+
if (!iso) return '-';
|
|
925
|
+
try {
|
|
926
|
+
const d = new Date(iso);
|
|
927
|
+
if (isNaN(d.getTime())) return iso;
|
|
928
|
+
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' }) + ' ' + d.toLocaleDateString();
|
|
929
|
+
} catch {
|
|
930
|
+
return iso;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// Forwarders for workbench functions
|
|
935
|
+
function openFunctionEditor(idOrName = 'new', pushState = true, initialTab = 'code') {
|
|
936
|
+
if (typeof window.openFunctionEditor === 'function' && window.openFunctionEditor !== openFunctionEditor) {
|
|
937
|
+
return window.openFunctionEditor(idOrName, pushState, initialTab);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
function openCreateFunctionPage() {
|
|
942
|
+
if (typeof window.openCreateFunctionPage === 'function' && window.openCreateFunctionPage !== openCreateFunctionPage) {
|
|
943
|
+
return window.openCreateFunctionPage();
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// ==========================================
|
|
948
|
+
// 4. Global Exports & Startup Hook
|
|
949
|
+
// ==========================================
|
|
950
|
+
|
|
951
|
+
if (typeof window !== 'undefined') {
|
|
952
|
+
window.functionsState = functionsState;
|
|
953
|
+
window.STARTER_RECIPES = STARTER_RECIPES;
|
|
954
|
+
window.renderFunctionsView = renderFunctionsView;
|
|
955
|
+
window.switchFunctionsTab = switchFunctionsTab;
|
|
956
|
+
window.refreshFunctionsView = refreshFunctionsView;
|
|
957
|
+
window.loadFunctionStats = loadFunctionStats;
|
|
958
|
+
window.loadFunctionsList = loadFunctionsList;
|
|
959
|
+
window.renderFunctionsTable = renderFunctionsTable;
|
|
960
|
+
window.toggleFunctionEnabled = toggleFunctionEnabled;
|
|
961
|
+
window.deleteFunctionPrompt = deleteFunctionPrompt;
|
|
962
|
+
window.openDeleteFunctionModal = openDeleteFunctionModal;
|
|
963
|
+
window.closeDeleteFunctionModal = closeDeleteFunctionModal;
|
|
964
|
+
window.confirmDeleteFunction = confirmDeleteFunction;
|
|
965
|
+
window.renderConflictModalState = renderConflictModalState;
|
|
966
|
+
window.openClearLogsModal = openClearLogsModal;
|
|
967
|
+
window.closeClearLogsModal = closeClearLogsModal;
|
|
968
|
+
window.confirmClearAllLogs = confirmClearAllLogs;
|
|
969
|
+
window.copyFunctionEndpoint = copyFunctionEndpoint;
|
|
970
|
+
window.openFunctionEditor = window.openFunctionEditor || openFunctionEditor;
|
|
971
|
+
window.openCreateFunctionPage = window.openCreateFunctionPage || openCreateFunctionPage;
|
|
972
|
+
window.loadFunctionLogs = loadFunctionLogs;
|
|
973
|
+
window.renderFunctionLogsTable = renderFunctionLogsTable;
|
|
974
|
+
window.filterFunctionLogs = filterFunctionLogs;
|
|
975
|
+
window.viewFunctionLogs = viewFunctionLogs;
|
|
976
|
+
window.viewLogPayload = viewLogPayload;
|
|
977
|
+
window.clearAllFunctionLogs = clearAllFunctionLogs;
|
|
978
|
+
window.formatTimestamp = formatTimestamp;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
if (typeof state !== 'undefined' && state.token && typeof loadFunctionStats === 'function') {
|
|
982
|
+
loadFunctionStats();
|
|
983
|
+
}
|