@optimizely/ocp-local-env 1.0.0-beta.6 → 1.0.0-beta.8
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/dist/package.json +2 -1
- package/dist/public/bundle.0a495807b6ef336cb500.js +3 -0
- package/dist/public/{bundle.932ab47a0dbf0319bc8b.js.LICENSE.txt → bundle.0a495807b6ef336cb500.js.LICENSE.txt} +33 -0
- package/dist/public/bundle.0a495807b6ef336cb500.js.map +1 -0
- package/dist/public/index.html +1 -1
- package/dist/src/cli.js +46 -19
- package/dist/src/cli.js.map +1 -1
- package/dist/src/executor/DestinationExecutor.js +13 -8
- package/dist/src/executor/DestinationExecutor.js.map +1 -1
- package/dist/src/executor/FunctionExecutor.js +4 -2
- package/dist/src/executor/FunctionExecutor.js.map +1 -1
- package/dist/src/executor/JobExecutor.js +1 -1
- package/dist/src/executor/JobExecutor.js.map +1 -1
- package/dist/src/executor/LifecycleExecutor.js +4 -2
- package/dist/src/executor/LifecycleExecutor.js.map +1 -1
- package/dist/src/executor/SourceExecutor.d.ts +32 -0
- package/dist/src/executor/SourceExecutor.js +163 -0
- package/dist/src/executor/SourceExecutor.js.map +1 -0
- package/dist/src/local_engine/LocalFunctionApi.d.ts +17 -0
- package/dist/src/local_engine/LocalFunctionApi.js +54 -0
- package/dist/src/local_engine/LocalFunctionApi.js.map +1 -0
- package/dist/src/local_engine/LocalJobApi.d.ts +38 -0
- package/dist/src/local_engine/LocalJobApi.js +180 -0
- package/dist/src/local_engine/LocalJobApi.js.map +1 -0
- package/dist/src/local_engine/local-engine-child-base.d.ts +16 -0
- package/dist/src/local_engine/local-engine-child-base.js +201 -14
- package/dist/src/local_engine/local-engine-child-base.js.map +1 -1
- package/dist/src/local_engine/local-engine-client.d.ts +70 -1
- package/dist/src/local_engine/local-engine-client.js +545 -26
- package/dist/src/local_engine/local-engine-client.js.map +1 -1
- package/dist/src/local_engine/local-engine-types.d.ts +99 -2
- package/dist/src/local_engine/local-engine-unified.d.ts +18 -0
- package/dist/src/local_engine/local-engine-unified.js +228 -2
- package/dist/src/local_engine/local-engine-unified.js.map +1 -1
- package/dist/src/local_engine/local-engine-utils.js +34 -7
- package/dist/src/local_engine/local-engine-utils.js.map +1 -1
- package/dist/src/local_engine/localSDKConfig.d.ts +2 -1
- package/dist/src/local_engine/localSDKConfig.js +95 -249
- package/dist/src/local_engine/localSDKConfig.js.map +1 -1
- package/dist/src/local_engine/storage/BaseKVStoreWrapper.d.ts +38 -0
- package/dist/src/local_engine/storage/BaseKVStoreWrapper.js +110 -0
- package/dist/src/local_engine/storage/BaseKVStoreWrapper.js.map +1 -0
- package/dist/src/local_engine/storage/LocalConfigStore.d.ts +18 -0
- package/dist/src/local_engine/storage/LocalConfigStore.js +52 -3
- package/dist/src/local_engine/storage/LocalConfigStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalJobStore.d.ts +1 -0
- package/dist/src/local_engine/storage/LocalJobStore.js +12 -2
- package/dist/src/local_engine/storage/LocalJobStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalKVStore.d.ts +1 -0
- package/dist/src/local_engine/storage/LocalKVStore.js +134 -75
- package/dist/src/local_engine/storage/LocalKVStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalNotificationStore.d.ts +1 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.js +17 -3
- package/dist/src/local_engine/storage/LocalNotificationStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalSecretsStore.d.ts +1 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.js +37 -6
- package/dist/src/local_engine/storage/LocalSecretsStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalSecretsStoreWrapper.d.ts +19 -0
- package/dist/src/local_engine/storage/LocalSecretsStoreWrapper.js +52 -0
- package/dist/src/local_engine/storage/LocalSecretsStoreWrapper.js.map +1 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.d.ts +1 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.js +61 -11
- package/dist/src/local_engine/storage/LocalSettingsStore.js.map +1 -1
- package/dist/src/local_engine/storage/LocalSettingsStoreWrapper.d.ts +15 -0
- package/dist/src/local_engine/storage/LocalSettingsStoreWrapper.js +28 -0
- package/dist/src/local_engine/storage/LocalSettingsStoreWrapper.js.map +1 -0
- package/dist/src/local_engine/storage/SourceDataStore.d.ts +23 -0
- package/dist/src/local_engine/storage/SourceDataStore.js +83 -0
- package/dist/src/local_engine/storage/SourceDataStore.js.map +1 -0
- package/dist/src/local_engine/storage/SourceJobExecutionStore.d.ts +25 -0
- package/dist/src/local_engine/storage/SourceJobExecutionStore.js +61 -0
- package/dist/src/local_engine/storage/SourceJobExecutionStore.js.map +1 -0
- package/dist/src/local_engine/types.d.ts +1 -0
- package/dist/src/local_engine/utils.js +20 -4
- package/dist/src/local_engine/utils.js.map +1 -1
- package/dist/src/logging/LogManager.d.ts +191 -34
- package/dist/src/logging/LogManager.js +209 -103
- package/dist/src/logging/LogManager.js.map +1 -1
- package/dist/src/server/api/destinations.js +33 -7
- package/dist/src/server/api/destinations.js.map +1 -1
- package/dist/src/server/api/functions.js +2 -1
- package/dist/src/server/api/functions.js.map +1 -1
- package/dist/src/server/api/jobs.js +3 -0
- package/dist/src/server/api/jobs.js.map +1 -1
- package/dist/src/server/api/sources.d.ts +7 -0
- package/dist/src/server/api/sources.js +382 -0
- package/dist/src/server/api/sources.js.map +1 -0
- package/dist/src/server/api/v1.js +54 -3
- package/dist/src/server/api/v1.js.map +1 -1
- package/dist/src/server/api.js +64 -3
- package/dist/src/server/api.js.map +1 -1
- package/dist/src/server.js +213 -23
- package/dist/src/server.js.map +1 -1
- package/dist/src/ui/components/App.js +195 -24
- package/dist/src/ui/components/App.js.map +1 -1
- package/dist/src/ui/components/DestinationsView.d.ts +8 -0
- package/dist/src/ui/components/DestinationsView.js +30 -9
- package/dist/src/ui/components/DestinationsView.js.map +1 -1
- package/dist/src/ui/components/FunctionsView.d.ts +7 -0
- package/dist/src/ui/components/FunctionsView.js +69 -9
- package/dist/src/ui/components/FunctionsView.js.map +1 -1
- package/dist/src/ui/components/JobsView.d.ts +7 -0
- package/dist/src/ui/components/JobsView.js +55 -15
- package/dist/src/ui/components/JobsView.js.map +1 -1
- package/dist/src/ui/components/SourceDataViewer.d.ts +8 -0
- package/dist/src/ui/components/SourceDataViewer.js +84 -0
- package/dist/src/ui/components/SourceDataViewer.js.map +1 -0
- package/dist/src/ui/components/SourceJobsSection.d.ts +8 -0
- package/dist/src/ui/components/SourceJobsSection.js +99 -0
- package/dist/src/ui/components/SourceJobsSection.js.map +1 -0
- package/dist/src/ui/components/SourceLifecycleSection.d.ts +7 -0
- package/dist/src/ui/components/SourceLifecycleSection.js +58 -0
- package/dist/src/ui/components/SourceLifecycleSection.js.map +1 -0
- package/dist/src/ui/components/SourceSchemaViewer.d.ts +7 -0
- package/dist/src/ui/components/SourceSchemaViewer.js +65 -0
- package/dist/src/ui/components/SourceSchemaViewer.js.map +1 -0
- package/dist/src/ui/components/SourceWebhookEditor.d.ts +8 -0
- package/dist/src/ui/components/SourceWebhookEditor.js +168 -0
- package/dist/src/ui/components/SourceWebhookEditor.js.map +1 -0
- package/dist/src/ui/components/SourcesView.d.ts +14 -0
- package/dist/src/ui/components/SourcesView.js +74 -0
- package/dist/src/ui/components/SourcesView.js.map +1 -0
- package/dist/src/ui/components/TabbedConsole.d.ts +3 -1
- package/dist/src/ui/components/TabbedConsole.js +81 -11
- package/dist/src/ui/components/TabbedConsole.js.map +1 -1
- package/dist/src/ui/hooks/useEntityNavigation.d.ts +72 -0
- package/dist/src/ui/hooks/useEntityNavigation.js +150 -0
- package/dist/src/ui/hooks/useEntityNavigation.js.map +1 -0
- package/dist/src/ui/hooks/useQueryParams.d.ts +6 -0
- package/dist/src/ui/hooks/useQueryParams.js +39 -0
- package/dist/src/ui/hooks/useQueryParams.js.map +1 -0
- package/dist/src/ui/index.js +3 -2
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/utils/functionEndpoints.d.ts +24 -0
- package/dist/src/utils/functionEndpoints.js +45 -0
- package/dist/src/utils/functionEndpoints.js.map +1 -0
- package/package.json +2 -1
- package/dist/public/bundle.932ab47a0dbf0319bc8b.js +0 -3
- package/dist/public/bundle.932ab47a0dbf0319bc8b.js.map +0 -1
- package/dist/src/server/api/lifecycle.d.ts +0 -6
- package/dist/src/server/api/lifecycle.js +0 -72
- package/dist/src/server/api/lifecycle.js.map +0 -1
|
@@ -2,15 +2,164 @@
|
|
|
2
2
|
* Centralized logging system for the OCP Local Environment
|
|
3
3
|
* Captures logs from builds, function executions, lifecycle hooks, and general operations
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Log source types - reduced to 2 sources
|
|
7
|
+
*/
|
|
8
|
+
export declare enum LogSource {
|
|
9
|
+
App = "app",
|
|
10
|
+
System = "system"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Log category types - specific categories for different log types
|
|
14
|
+
*/
|
|
15
|
+
export declare enum LogCategory {
|
|
16
|
+
Build = "build",
|
|
17
|
+
Function = "function",
|
|
18
|
+
Lifecycle = "lifecycle",
|
|
19
|
+
Destination = "destination",
|
|
20
|
+
Source = "source",
|
|
21
|
+
Jobs = "jobs",
|
|
22
|
+
Notifications = "notifications",
|
|
23
|
+
KVStore = "kvstore",
|
|
24
|
+
Settings = "settings",
|
|
25
|
+
Secrets = "secrets",
|
|
26
|
+
Config = "config",
|
|
27
|
+
AppRunner = "app-runner"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Log levels
|
|
31
|
+
*/
|
|
32
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
33
|
+
/**
|
|
34
|
+
* Base context interface - common fields for all log contexts
|
|
35
|
+
*/
|
|
36
|
+
export interface BaseLogContext {
|
|
37
|
+
id: string;
|
|
38
|
+
error?: any;
|
|
39
|
+
errorMessage?: string;
|
|
40
|
+
stack?: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Empty context for categories that don't need specific context
|
|
45
|
+
*/
|
|
46
|
+
export interface EmptyLogContext extends BaseLogContext {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Function execution context
|
|
50
|
+
* id = function identifier (e.g., 'my-function')
|
|
51
|
+
*/
|
|
52
|
+
export interface FunctionLogContext extends BaseLogContext {
|
|
53
|
+
method?: string;
|
|
54
|
+
path?: string;
|
|
55
|
+
executionTime?: number;
|
|
56
|
+
status?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lifecycle execution context
|
|
60
|
+
* id = hook name (e.g., 'onInstall')
|
|
61
|
+
*/
|
|
62
|
+
export interface LifecycleLogContext extends BaseLogContext {
|
|
63
|
+
executionTime?: number;
|
|
64
|
+
status?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Destination execution context
|
|
68
|
+
* id = destination identifier (e.g., 'analytics-destination')
|
|
69
|
+
*/
|
|
70
|
+
export interface DestinationLogContext extends BaseLogContext {
|
|
71
|
+
operation?: 'ready' | 'deliver' | 'schema';
|
|
72
|
+
batchSize?: number;
|
|
73
|
+
ready?: boolean;
|
|
74
|
+
retryable?: boolean;
|
|
75
|
+
failureReason?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Source execution context
|
|
79
|
+
* id = source identifier (e.g., 'my-source')
|
|
80
|
+
*/
|
|
81
|
+
export interface SourceLogContext extends BaseLogContext {
|
|
82
|
+
operation?: string;
|
|
83
|
+
error?: any;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Job operation context
|
|
87
|
+
* id = job identifier or 'unknown'
|
|
88
|
+
*/
|
|
89
|
+
export interface JobLogContext extends BaseLogContext {
|
|
90
|
+
operation?: 'schedule' | 'execute' | 'cancel' | 'list';
|
|
91
|
+
status?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Notification operation context
|
|
95
|
+
* id = notification identifier or 'unknown'
|
|
96
|
+
*/
|
|
97
|
+
export interface NotificationLogContext extends BaseLogContext {
|
|
98
|
+
operation?: 'send' | 'list' | 'clear';
|
|
99
|
+
recipient?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Storage operation context (kvstore, settings, secrets, config)
|
|
103
|
+
* id = key identifier (e.g., 'user:123') or 'unknown'
|
|
104
|
+
*/
|
|
105
|
+
export interface StorageLogContext extends BaseLogContext {
|
|
106
|
+
store: string;
|
|
107
|
+
operation: 'get' | 'set' | 'delete' | 'exists' | 'list' | 'clear';
|
|
108
|
+
key?: string;
|
|
109
|
+
value?: any;
|
|
110
|
+
ttl?: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* IPC communication context
|
|
114
|
+
* id = request identifier or 'unknown'
|
|
115
|
+
*/
|
|
116
|
+
export interface IPCLogContext extends BaseLogContext {
|
|
117
|
+
messageType?: string;
|
|
118
|
+
connectionId?: string;
|
|
119
|
+
timeout?: number;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Process management context
|
|
123
|
+
* id = process identifier or 'unknown'
|
|
124
|
+
*/
|
|
125
|
+
export interface ProcessLogContext extends BaseLogContext {
|
|
126
|
+
connectionId?: string;
|
|
127
|
+
operation?: string;
|
|
128
|
+
exitCode?: number;
|
|
129
|
+
signal?: string;
|
|
130
|
+
processId?: string;
|
|
131
|
+
appId?: string;
|
|
132
|
+
port?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Map each category to its context type
|
|
136
|
+
*/
|
|
137
|
+
export type CategoryContextMap = {
|
|
138
|
+
[LogCategory.Build]: EmptyLogContext;
|
|
139
|
+
[LogCategory.Function]: FunctionLogContext;
|
|
140
|
+
[LogCategory.Lifecycle]: LifecycleLogContext;
|
|
141
|
+
[LogCategory.Destination]: DestinationLogContext;
|
|
142
|
+
[LogCategory.Source]: SourceLogContext;
|
|
143
|
+
[LogCategory.Jobs]: JobLogContext;
|
|
144
|
+
[LogCategory.Notifications]: NotificationLogContext;
|
|
145
|
+
[LogCategory.KVStore]: StorageLogContext;
|
|
146
|
+
[LogCategory.Settings]: StorageLogContext;
|
|
147
|
+
[LogCategory.Secrets]: StorageLogContext;
|
|
148
|
+
[LogCategory.Config]: StorageLogContext;
|
|
149
|
+
[LogCategory.AppRunner]: ProcessLogContext | IPCLogContext;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Type-safe log entry
|
|
153
|
+
*/
|
|
154
|
+
export type LogEntry<C extends LogCategory = LogCategory> = {
|
|
6
155
|
id: string;
|
|
7
156
|
timestamp: string;
|
|
8
|
-
source:
|
|
9
|
-
|
|
10
|
-
|
|
157
|
+
source: LogSource;
|
|
158
|
+
category: C;
|
|
159
|
+
level: LogLevel;
|
|
11
160
|
message: string;
|
|
12
|
-
|
|
13
|
-
}
|
|
161
|
+
context?: CategoryContextMap[C];
|
|
162
|
+
};
|
|
14
163
|
export declare class LogManager {
|
|
15
164
|
private static instance;
|
|
16
165
|
private logs;
|
|
@@ -22,60 +171,68 @@ export declare class LogManager {
|
|
|
22
171
|
*/
|
|
23
172
|
static getInstance(): LogManager;
|
|
24
173
|
/**
|
|
25
|
-
*
|
|
174
|
+
* Core log method - accepts type-safe log entries
|
|
26
175
|
*/
|
|
27
|
-
log(entry: Omit<LogEntry
|
|
176
|
+
log<C extends LogCategory>(entry: Omit<LogEntry<C>, 'id' | 'timestamp'>): void;
|
|
28
177
|
/**
|
|
29
|
-
* Convenience methods
|
|
178
|
+
* Convenience methods with type-safe contexts
|
|
30
179
|
*/
|
|
31
|
-
debug(source:
|
|
32
|
-
info(source:
|
|
33
|
-
warn(source:
|
|
34
|
-
error(source:
|
|
180
|
+
debug<C extends LogCategory>(source: LogSource, category: C, message: string, context?: CategoryContextMap[C]): void;
|
|
181
|
+
info<C extends LogCategory>(source: LogSource, category: C, message: string, context?: CategoryContextMap[C]): void;
|
|
182
|
+
warn<C extends LogCategory>(source: LogSource, category: C, message: string, context?: CategoryContextMap[C]): void;
|
|
183
|
+
error<C extends LogCategory>(source: LogSource, category: C, message: string, context?: CategoryContextMap[C]): void;
|
|
35
184
|
/**
|
|
36
|
-
*
|
|
185
|
+
* Specialized convenience method for function execution
|
|
37
186
|
*/
|
|
38
|
-
|
|
39
|
-
limit?: number;
|
|
40
|
-
source?: LogEntry['source'];
|
|
41
|
-
level?: LogEntry['level'];
|
|
42
|
-
since?: string;
|
|
43
|
-
category?: string;
|
|
44
|
-
}): LogEntry[];
|
|
187
|
+
logFunctionExecution(functionId: string, status: 'started' | 'success' | 'error', details?: Partial<FunctionLogContext>): void;
|
|
45
188
|
/**
|
|
46
|
-
*
|
|
189
|
+
* Specialized convenience method for lifecycle execution
|
|
47
190
|
*/
|
|
48
|
-
|
|
191
|
+
logLifecycleExecution(hookName: string, status: 'started' | 'success' | 'error', details?: Partial<LifecycleLogContext>): void;
|
|
49
192
|
/**
|
|
50
|
-
*
|
|
193
|
+
* Specialized convenience method for destination execution
|
|
51
194
|
*/
|
|
52
|
-
|
|
195
|
+
logDestinationExecution(destinationId: string, operation: 'ready' | 'deliver' | 'schema', status: 'started' | 'success' | 'error', details?: Partial<DestinationLogContext>): void;
|
|
53
196
|
/**
|
|
54
|
-
*
|
|
197
|
+
* Specialized convenience method for build events
|
|
55
198
|
*/
|
|
56
|
-
|
|
199
|
+
logBuildEvent(status: 'started' | 'success' | 'error', details?: any): void;
|
|
57
200
|
/**
|
|
58
201
|
* Log function output/console logs
|
|
59
202
|
*/
|
|
60
203
|
logFunctionOutput(functionId: string, output: string, isError?: boolean): void;
|
|
61
204
|
/**
|
|
62
|
-
* Log
|
|
205
|
+
* Log build output
|
|
63
206
|
*/
|
|
64
|
-
|
|
207
|
+
logBuildOutput(output: string, isError?: boolean): void;
|
|
65
208
|
/**
|
|
66
|
-
* Log
|
|
209
|
+
* Log source execution events
|
|
67
210
|
*/
|
|
68
|
-
|
|
211
|
+
logSourceExecution(sourceId: string, operation: string, status: 'started' | 'success' | 'error', additionalContext?: any): void;
|
|
69
212
|
/**
|
|
70
|
-
*
|
|
213
|
+
* Get logs with optional filtering
|
|
71
214
|
*/
|
|
72
|
-
|
|
215
|
+
getLogs(options?: {
|
|
216
|
+
limit?: number;
|
|
217
|
+
source?: LogSource;
|
|
218
|
+
level?: LogLevel;
|
|
219
|
+
since?: string;
|
|
220
|
+
category?: LogCategory;
|
|
221
|
+
}): LogEntry[];
|
|
222
|
+
/**
|
|
223
|
+
* Clear all logs
|
|
224
|
+
*/
|
|
225
|
+
clearLogs(): void;
|
|
226
|
+
/**
|
|
227
|
+
* Add a listener for new log entries
|
|
228
|
+
*/
|
|
229
|
+
addListener(listener: (log: LogEntry) => void): () => void;
|
|
73
230
|
/**
|
|
74
231
|
* Generate a unique ID for log entries
|
|
75
232
|
*/
|
|
76
233
|
private generateId;
|
|
77
234
|
/**
|
|
78
|
-
* Log to console with
|
|
235
|
+
* Log to console with new format
|
|
79
236
|
*/
|
|
80
237
|
private logToConsole;
|
|
81
238
|
/**
|
|
@@ -4,7 +4,37 @@
|
|
|
4
4
|
* Captures logs from builds, function executions, lifecycle hooks, and general operations
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.LogManager = void 0;
|
|
7
|
+
exports.LogManager = exports.LogCategory = exports.LogSource = void 0;
|
|
8
|
+
// ===== TYPE DEFINITIONS =====
|
|
9
|
+
/**
|
|
10
|
+
* Log source types - reduced to 2 sources
|
|
11
|
+
*/
|
|
12
|
+
var LogSource;
|
|
13
|
+
(function (LogSource) {
|
|
14
|
+
LogSource["App"] = "app";
|
|
15
|
+
LogSource["System"] = "system";
|
|
16
|
+
})(LogSource || (exports.LogSource = LogSource = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Log category types - specific categories for different log types
|
|
19
|
+
*/
|
|
20
|
+
var LogCategory;
|
|
21
|
+
(function (LogCategory) {
|
|
22
|
+
// Core application
|
|
23
|
+
LogCategory["Build"] = "build";
|
|
24
|
+
LogCategory["Function"] = "function";
|
|
25
|
+
LogCategory["Lifecycle"] = "lifecycle";
|
|
26
|
+
LogCategory["Destination"] = "destination";
|
|
27
|
+
LogCategory["Source"] = "source";
|
|
28
|
+
LogCategory["Jobs"] = "jobs";
|
|
29
|
+
LogCategory["Notifications"] = "notifications";
|
|
30
|
+
// System infrastructure
|
|
31
|
+
LogCategory["KVStore"] = "kvstore";
|
|
32
|
+
LogCategory["Settings"] = "settings";
|
|
33
|
+
LogCategory["Secrets"] = "secrets";
|
|
34
|
+
LogCategory["Config"] = "config";
|
|
35
|
+
LogCategory["AppRunner"] = "app-runner";
|
|
36
|
+
})(LogCategory || (exports.LogCategory = LogCategory = {}));
|
|
37
|
+
// ===== LOG MANAGER =====
|
|
8
38
|
class LogManager {
|
|
9
39
|
constructor() {
|
|
10
40
|
this.logs = [];
|
|
@@ -22,7 +52,7 @@ class LogManager {
|
|
|
22
52
|
return this.instance;
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
25
|
-
*
|
|
55
|
+
* Core log method - accepts type-safe log entries
|
|
26
56
|
*/
|
|
27
57
|
log(entry) {
|
|
28
58
|
const logEntry = {
|
|
@@ -31,11 +61,9 @@ class LogManager {
|
|
|
31
61
|
timestamp: new Date().toISOString()
|
|
32
62
|
};
|
|
33
63
|
this.logs.push(logEntry);
|
|
34
|
-
// Keep only the most recent logs
|
|
35
64
|
if (this.logs.length > this.maxLogs) {
|
|
36
65
|
this.logs = this.logs.slice(-this.maxLogs);
|
|
37
66
|
}
|
|
38
|
-
// Notify listeners
|
|
39
67
|
this.logListeners.forEach(listener => {
|
|
40
68
|
try {
|
|
41
69
|
listener(logEntry);
|
|
@@ -44,150 +72,208 @@ class LogManager {
|
|
|
44
72
|
console.error('Error notifying log listener:', error);
|
|
45
73
|
}
|
|
46
74
|
});
|
|
47
|
-
// Also log to console for debugging
|
|
48
75
|
this.logToConsole(logEntry);
|
|
49
76
|
}
|
|
50
77
|
/**
|
|
51
|
-
* Convenience methods
|
|
78
|
+
* Convenience methods with type-safe contexts
|
|
52
79
|
*/
|
|
53
|
-
debug(source,
|
|
54
|
-
this.log({ source, level: 'debug', message,
|
|
80
|
+
debug(source, category, message, context) {
|
|
81
|
+
this.log({ source, category, level: 'debug', message, context });
|
|
55
82
|
}
|
|
56
|
-
info(source,
|
|
57
|
-
this.log({ source, level: 'info', message,
|
|
83
|
+
info(source, category, message, context) {
|
|
84
|
+
this.log({ source, category, level: 'info', message, context });
|
|
58
85
|
}
|
|
59
|
-
warn(source,
|
|
60
|
-
this.log({ source, level: 'warn', message,
|
|
86
|
+
warn(source, category, message, context) {
|
|
87
|
+
this.log({ source, category, level: 'warn', message, context });
|
|
61
88
|
}
|
|
62
|
-
error(source,
|
|
63
|
-
this.log({ source, level: 'error', message,
|
|
89
|
+
error(source, category, message, context) {
|
|
90
|
+
this.log({ source, category, level: 'error', message, context });
|
|
64
91
|
}
|
|
65
92
|
/**
|
|
66
|
-
*
|
|
93
|
+
* Specialized convenience method for function execution
|
|
67
94
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
filteredLogs = filteredLogs.filter(log => log.category === options.category);
|
|
85
|
-
}
|
|
86
|
-
// Apply limit
|
|
87
|
-
const limit = options?.limit || 100;
|
|
88
|
-
return filteredLogs.slice(-limit);
|
|
95
|
+
logFunctionExecution(functionId, status, details) {
|
|
96
|
+
const messages = {
|
|
97
|
+
started: 'Function execution started',
|
|
98
|
+
success: 'Function execution completed successfully',
|
|
99
|
+
error: 'Function execution failed'
|
|
100
|
+
};
|
|
101
|
+
this.log({
|
|
102
|
+
source: LogSource.App,
|
|
103
|
+
category: LogCategory.Function,
|
|
104
|
+
level: status === 'error' ? 'error' : 'info',
|
|
105
|
+
message: messages[status],
|
|
106
|
+
context: {
|
|
107
|
+
id: functionId,
|
|
108
|
+
...details
|
|
109
|
+
}
|
|
110
|
+
});
|
|
89
111
|
}
|
|
90
112
|
/**
|
|
91
|
-
*
|
|
113
|
+
* Specialized convenience method for lifecycle execution
|
|
92
114
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
logLifecycleExecution(hookName, status, details) {
|
|
116
|
+
const messages = {
|
|
117
|
+
started: 'Lifecycle hook execution started',
|
|
118
|
+
success: 'Lifecycle hook execution completed successfully',
|
|
119
|
+
error: 'Lifecycle hook execution failed'
|
|
120
|
+
};
|
|
121
|
+
this.log({
|
|
122
|
+
source: LogSource.App,
|
|
123
|
+
category: LogCategory.Lifecycle,
|
|
124
|
+
level: status === 'error' ? 'error' : 'info',
|
|
125
|
+
message: messages[status],
|
|
126
|
+
context: {
|
|
127
|
+
id: hookName,
|
|
128
|
+
...details
|
|
129
|
+
}
|
|
130
|
+
});
|
|
96
131
|
}
|
|
97
132
|
/**
|
|
98
|
-
*
|
|
133
|
+
* Specialized convenience method for destination execution
|
|
99
134
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
135
|
+
logDestinationExecution(destinationId, operation, status, details) {
|
|
136
|
+
const messages = {
|
|
137
|
+
started: {
|
|
138
|
+
ready: 'Executing ready() for destination',
|
|
139
|
+
deliver: 'Delivering batch to destination',
|
|
140
|
+
schema: 'Loading schema for destination'
|
|
141
|
+
},
|
|
142
|
+
success: {
|
|
143
|
+
ready: 'Destination ready() completed successfully',
|
|
144
|
+
deliver: 'Batch delivered successfully',
|
|
145
|
+
schema: 'Schema loaded successfully'
|
|
146
|
+
},
|
|
147
|
+
error: {
|
|
148
|
+
ready: 'Destination ready() failed',
|
|
149
|
+
deliver: 'Batch delivery failed',
|
|
150
|
+
schema: 'Schema loading failed'
|
|
107
151
|
}
|
|
108
152
|
};
|
|
153
|
+
this.log({
|
|
154
|
+
source: LogSource.System,
|
|
155
|
+
category: LogCategory.AppRunner,
|
|
156
|
+
level: status === 'error' ? 'error' : 'info',
|
|
157
|
+
message: messages[status][operation],
|
|
158
|
+
context: {
|
|
159
|
+
id: destinationId,
|
|
160
|
+
operation,
|
|
161
|
+
...details
|
|
162
|
+
}
|
|
163
|
+
});
|
|
109
164
|
}
|
|
110
165
|
/**
|
|
111
|
-
*
|
|
166
|
+
* Specialized convenience method for build events
|
|
112
167
|
*/
|
|
113
|
-
|
|
168
|
+
logBuildEvent(status, details) {
|
|
114
169
|
const messages = {
|
|
115
|
-
started:
|
|
116
|
-
success:
|
|
117
|
-
error:
|
|
170
|
+
started: 'Build started',
|
|
171
|
+
success: 'Build completed successfully',
|
|
172
|
+
error: 'Build failed'
|
|
118
173
|
};
|
|
119
|
-
const level = status === 'error' ? 'error' : 'info';
|
|
120
174
|
this.log({
|
|
121
|
-
source:
|
|
122
|
-
|
|
175
|
+
source: LogSource.System,
|
|
176
|
+
category: LogCategory.Build,
|
|
177
|
+
level: status === 'error' ? 'error' : 'info',
|
|
123
178
|
message: messages[status],
|
|
124
|
-
|
|
125
|
-
|
|
179
|
+
context: {
|
|
180
|
+
id: 'build',
|
|
181
|
+
...details
|
|
182
|
+
}
|
|
126
183
|
});
|
|
127
184
|
}
|
|
128
185
|
/**
|
|
129
186
|
* Log function output/console logs
|
|
130
187
|
*/
|
|
131
188
|
logFunctionOutput(functionId, output, isError = false) {
|
|
132
|
-
// Split output into lines and log each line
|
|
133
189
|
const lines = output.split('\n').filter(line => line.trim());
|
|
134
190
|
lines.forEach(line => {
|
|
135
191
|
this.log({
|
|
136
|
-
source:
|
|
192
|
+
source: LogSource.App,
|
|
193
|
+
category: LogCategory.Function,
|
|
137
194
|
level: isError ? 'error' : 'info',
|
|
138
195
|
message: line.trim(),
|
|
139
|
-
|
|
196
|
+
context: { id: functionId }
|
|
140
197
|
});
|
|
141
198
|
});
|
|
142
199
|
}
|
|
143
200
|
/**
|
|
144
|
-
* Log
|
|
201
|
+
* Log build output
|
|
145
202
|
*/
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
message: messages[status],
|
|
157
|
-
category: hookName,
|
|
158
|
-
details
|
|
203
|
+
logBuildOutput(output, isError = false) {
|
|
204
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
205
|
+
lines.forEach(line => {
|
|
206
|
+
this.log({
|
|
207
|
+
source: LogSource.System,
|
|
208
|
+
category: LogCategory.Build,
|
|
209
|
+
level: isError ? 'error' : 'info',
|
|
210
|
+
message: line.trim(),
|
|
211
|
+
context: { id: 'build' }
|
|
212
|
+
});
|
|
159
213
|
});
|
|
160
214
|
}
|
|
161
215
|
/**
|
|
162
|
-
* Log
|
|
216
|
+
* Log source execution events
|
|
163
217
|
*/
|
|
164
|
-
|
|
165
|
-
const messages = {
|
|
166
|
-
started: `Build started`,
|
|
167
|
-
success: `Build completed successfully`,
|
|
168
|
-
error: `Build failed`
|
|
169
|
-
};
|
|
218
|
+
logSourceExecution(sourceId, operation, status, additionalContext) {
|
|
170
219
|
const level = status === 'error' ? 'error' : 'info';
|
|
220
|
+
const message = `Source ${operation} ${status}`;
|
|
171
221
|
this.log({
|
|
172
|
-
source:
|
|
222
|
+
source: LogSource.System,
|
|
223
|
+
category: LogCategory.Source,
|
|
173
224
|
level,
|
|
174
|
-
message
|
|
175
|
-
|
|
225
|
+
message,
|
|
226
|
+
context: {
|
|
227
|
+
id: sourceId,
|
|
228
|
+
operation,
|
|
229
|
+
...additionalContext
|
|
230
|
+
}
|
|
176
231
|
});
|
|
177
232
|
}
|
|
178
233
|
/**
|
|
179
|
-
*
|
|
234
|
+
* Get logs with optional filtering
|
|
180
235
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
236
|
+
getLogs(options) {
|
|
237
|
+
let filteredLogs = this.logs;
|
|
238
|
+
// Apply filters
|
|
239
|
+
if (options?.source) {
|
|
240
|
+
filteredLogs = filteredLogs.filter(log => log.source === options.source);
|
|
241
|
+
}
|
|
242
|
+
if (options?.level) {
|
|
243
|
+
const levels = ['debug', 'info', 'warn', 'error'];
|
|
244
|
+
const minLevelIndex = levels.indexOf(options.level);
|
|
245
|
+
filteredLogs = filteredLogs.filter(log => levels.indexOf(log.level) >= minLevelIndex);
|
|
246
|
+
}
|
|
247
|
+
if (options?.since) {
|
|
248
|
+
const sinceTime = new Date(options.since).getTime();
|
|
249
|
+
filteredLogs = filteredLogs.filter(log => new Date(log.timestamp).getTime() >= sinceTime);
|
|
250
|
+
}
|
|
251
|
+
if (options?.category) {
|
|
252
|
+
filteredLogs = filteredLogs.filter(log => log.category === options.category);
|
|
253
|
+
}
|
|
254
|
+
// Apply limit
|
|
255
|
+
const limit = options?.limit || 100;
|
|
256
|
+
return filteredLogs.slice(-limit);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Clear all logs
|
|
260
|
+
*/
|
|
261
|
+
clearLogs() {
|
|
262
|
+
this.logs = [];
|
|
263
|
+
this.info(LogSource.System, LogCategory.AppRunner, 'Logs cleared', { id: 'unknown' });
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Add a listener for new log entries
|
|
267
|
+
*/
|
|
268
|
+
addListener(listener) {
|
|
269
|
+
this.logListeners.push(listener);
|
|
270
|
+
// Return unsubscribe function
|
|
271
|
+
return () => {
|
|
272
|
+
const index = this.logListeners.indexOf(listener);
|
|
273
|
+
if (index > -1) {
|
|
274
|
+
this.logListeners.splice(index, 1);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
191
277
|
}
|
|
192
278
|
/**
|
|
193
279
|
* Generate a unique ID for log entries
|
|
@@ -196,23 +282,43 @@ class LogManager {
|
|
|
196
282
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
197
283
|
}
|
|
198
284
|
/**
|
|
199
|
-
* Log to console with
|
|
285
|
+
* Log to console with new format
|
|
200
286
|
*/
|
|
201
287
|
logToConsole(entry) {
|
|
202
|
-
|
|
203
|
-
|
|
288
|
+
if (process.env.DISABLE_LOGMANAGER_CONSOLE === 'true') {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
// New format: [timestamp] - [source:category:id] - [level] - [message]
|
|
292
|
+
const timestamp = entry.timestamp;
|
|
293
|
+
const id = entry.context?.id || 'unknown';
|
|
294
|
+
const sourceCategoryId = `${entry.source}:${entry.category}:${id}`;
|
|
295
|
+
const level = entry.level;
|
|
296
|
+
const prefix = `[${timestamp}] - [${sourceCategoryId}] - [${level}]`;
|
|
297
|
+
// Escape newlines for single-line console output
|
|
298
|
+
const escapedMessage = entry.message
|
|
299
|
+
.replace(/\n/g, '\\n')
|
|
300
|
+
.replace(/\r/g, '\\r');
|
|
301
|
+
// Include context if present (excluding id since it's in the prefix)
|
|
302
|
+
let contextStr = '';
|
|
303
|
+
if (entry.context && Object.keys(entry.context).length > 0) {
|
|
304
|
+
const { id: _, ...contextWithoutId } = entry.context;
|
|
305
|
+
if (Object.keys(contextWithoutId).length > 0) {
|
|
306
|
+
contextStr = ` ${JSON.stringify(contextWithoutId)}`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const fullMessage = `${prefix} - ${escapedMessage}${contextStr}`;
|
|
204
310
|
switch (entry.level) {
|
|
205
311
|
case 'error':
|
|
206
|
-
console.error(
|
|
312
|
+
console.error(fullMessage);
|
|
207
313
|
break;
|
|
208
314
|
case 'warn':
|
|
209
|
-
console.warn(
|
|
315
|
+
console.warn(fullMessage);
|
|
210
316
|
break;
|
|
211
317
|
case 'debug':
|
|
212
|
-
console.debug(
|
|
318
|
+
console.debug(fullMessage);
|
|
213
319
|
break;
|
|
214
320
|
default:
|
|
215
|
-
console.log(
|
|
321
|
+
console.log(fullMessage);
|
|
216
322
|
}
|
|
217
323
|
}
|
|
218
324
|
/**
|