@optimizely/ocp-local-env 1.0.0-beta.10
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 +51 -0
- package/dist/package.json +112 -0
- package/dist/public/bundle.82dc5d29fffb9f205051.js +3 -0
- package/dist/public/bundle.82dc5d29fffb9f205051.js.LICENSE.txt +92 -0
- package/dist/public/bundle.82dc5d29fffb9f205051.js.map +1 -0
- package/dist/public/index.html +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +115 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/executor/DestinationExecutor.d.ts +19 -0
- package/dist/src/executor/DestinationExecutor.js +72 -0
- package/dist/src/executor/DestinationExecutor.js.map +1 -0
- package/dist/src/executor/FunctionExecutor.d.ts +67 -0
- package/dist/src/executor/FunctionExecutor.js +189 -0
- package/dist/src/executor/FunctionExecutor.js.map +1 -0
- package/dist/src/executor/JobExecutor.d.ts +79 -0
- package/dist/src/executor/JobExecutor.js +215 -0
- package/dist/src/executor/JobExecutor.js.map +1 -0
- package/dist/src/executor/LifecycleExecutor.d.ts +64 -0
- package/dist/src/executor/LifecycleExecutor.js +167 -0
- package/dist/src/executor/LifecycleExecutor.js.map +1 -0
- 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/executor/watcher.d.ts +62 -0
- package/dist/src/executor/watcher.js +213 -0
- package/dist/src/executor/watcher.js.map +1 -0
- package/dist/src/functions/hello.d.ts +4 -0
- package/dist/src/functions/hello.js +8 -0
- package/dist/src/functions/hello.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jobs/dailyJob.d.ts +4 -0
- package/dist/src/jobs/dailyJob.js +8 -0
- package/dist/src/jobs/dailyJob.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 +67 -0
- package/dist/src/local_engine/LocalJobApi.js +205 -0
- package/dist/src/local_engine/LocalJobApi.js.map +1 -0
- package/dist/src/local_engine/LocalNotifier.d.ts +9 -0
- package/dist/src/local_engine/LocalNotifier.js +26 -0
- package/dist/src/local_engine/LocalNotifier.js.map +1 -0
- package/dist/src/local_engine/local-engine-child-base.d.ts +110 -0
- package/dist/src/local_engine/local-engine-child-base.js +607 -0
- package/dist/src/local_engine/local-engine-child-base.js.map +1 -0
- package/dist/src/local_engine/local-engine-client.d.ts +161 -0
- package/dist/src/local_engine/local-engine-client.js +888 -0
- package/dist/src/local_engine/local-engine-client.js.map +1 -0
- package/dist/src/local_engine/local-engine-types.d.ts +245 -0
- package/dist/src/local_engine/local-engine-types.js +6 -0
- package/dist/src/local_engine/local-engine-types.js.map +1 -0
- package/dist/src/local_engine/local-engine-unified.d.ts +71 -0
- package/dist/src/local_engine/local-engine-unified.js +723 -0
- package/dist/src/local_engine/local-engine-unified.js.map +1 -0
- package/dist/src/local_engine/local-engine-utils.d.ts +68 -0
- package/dist/src/local_engine/local-engine-utils.js +219 -0
- package/dist/src/local_engine/local-engine-utils.js.map +1 -0
- package/dist/src/local_engine/localSDKConfig.d.ts +40 -0
- package/dist/src/local_engine/localSDKConfig.js +247 -0
- package/dist/src/local_engine/localSDKConfig.js.map +1 -0
- package/dist/src/local_engine/storage/BaseKVStoreWrapper.d.ts +37 -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 +74 -0
- package/dist/src/local_engine/storage/LocalConfigStore.js +178 -0
- package/dist/src/local_engine/storage/LocalConfigStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalJobStore.d.ts +111 -0
- package/dist/src/local_engine/storage/LocalJobStore.js +249 -0
- package/dist/src/local_engine/storage/LocalJobStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalKVStore.d.ts +106 -0
- package/dist/src/local_engine/storage/LocalKVStore.js +1061 -0
- package/dist/src/local_engine/storage/LocalKVStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.d.ts +28 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.js +149 -0
- package/dist/src/local_engine/storage/LocalNotificationStore.js.map +1 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.d.ts +115 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.js +350 -0
- package/dist/src/local_engine/storage/LocalSecretsStore.js.map +1 -0
- 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 +168 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.js +509 -0
- package/dist/src/local_engine/storage/LocalSettingsStore.js.map +1 -0
- 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/NumberSet.d.ts +21 -0
- package/dist/src/local_engine/storage/NumberSet.js +32 -0
- package/dist/src/local_engine/storage/NumberSet.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/storage/StringSet.d.ts +21 -0
- package/dist/src/local_engine/storage/StringSet.js +32 -0
- package/dist/src/local_engine/storage/StringSet.js.map +1 -0
- package/dist/src/local_engine/types.d.ts +53 -0
- package/dist/src/local_engine/types.js +6 -0
- package/dist/src/local_engine/types.js.map +1 -0
- package/dist/src/local_engine/utils.d.ts +33 -0
- package/dist/src/local_engine/utils.js +143 -0
- package/dist/src/local_engine/utils.js.map +1 -0
- package/dist/src/logging/LogManager.d.ts +246 -0
- package/dist/src/logging/LogManager.js +343 -0
- package/dist/src/logging/LogManager.js.map +1 -0
- package/dist/src/server/api/destinations.d.ts +7 -0
- package/dist/src/server/api/destinations.js +170 -0
- package/dist/src/server/api/destinations.js.map +1 -0
- package/dist/src/server/api/functions.d.ts +7 -0
- package/dist/src/server/api/functions.js +80 -0
- package/dist/src/server/api/functions.js.map +1 -0
- package/dist/src/server/api/jobs.d.ts +10 -0
- package/dist/src/server/api/jobs.js +244 -0
- package/dist/src/server/api/jobs.js.map +1 -0
- package/dist/src/server/api/settings.d.ts +6 -0
- package/dist/src/server/api/settings.js +116 -0
- package/dist/src/server/api/settings.js.map +1 -0
- 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/stores.d.ts +2 -0
- package/dist/src/server/api/stores.js +341 -0
- package/dist/src/server/api/stores.js.map +1 -0
- package/dist/src/server/api/v1.d.ts +10 -0
- package/dist/src/server/api/v1.js +718 -0
- package/dist/src/server/api/v1.js.map +1 -0
- package/dist/src/server/api.d.ts +8 -0
- package/dist/src/server/api.js +217 -0
- package/dist/src/server/api.js.map +1 -0
- package/dist/src/server/app-discovery.d.ts +5 -0
- package/dist/src/server/app-discovery.js +113 -0
- package/dist/src/server/app-discovery.js.map +1 -0
- package/dist/src/server/config.d.ts +26 -0
- package/dist/src/server/config.js +112 -0
- package/dist/src/server/config.js.map +1 -0
- package/dist/src/server/mockDataGenerator.d.ts +1 -0
- package/dist/src/server/mockDataGenerator.js +154 -0
- package/dist/src/server/mockDataGenerator.js.map +1 -0
- package/dist/src/server/websocket.d.ts +0 -0
- package/dist/src/server/websocket.js +2 -0
- package/dist/src/server/websocket.js.map +1 -0
- package/dist/src/server.d.ts +2 -0
- package/dist/src/server.js +735 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/types/app.d.ts +154 -0
- package/dist/src/types/app.js +24 -0
- package/dist/src/types/app.js.map +1 -0
- package/dist/src/types/kvstore.d.ts +320 -0
- package/dist/src/types/kvstore.js +5 -0
- package/dist/src/types/kvstore.js.map +1 -0
- package/dist/src/ui/components/App.d.ts +6 -0
- package/dist/src/ui/components/App.js +432 -0
- package/dist/src/ui/components/App.js.map +1 -0
- package/dist/src/ui/components/DestinationBatchEditor.d.ts +7 -0
- package/dist/src/ui/components/DestinationBatchEditor.js +160 -0
- package/dist/src/ui/components/DestinationBatchEditor.js.map +1 -0
- package/dist/src/ui/components/DestinationSchemaViewer.d.ts +7 -0
- package/dist/src/ui/components/DestinationSchemaViewer.js +61 -0
- package/dist/src/ui/components/DestinationSchemaViewer.js.map +1 -0
- package/dist/src/ui/components/DestinationsView.d.ts +14 -0
- package/dist/src/ui/components/DestinationsView.js +68 -0
- package/dist/src/ui/components/DestinationsView.js.map +1 -0
- package/dist/src/ui/components/FunctionsView.d.ts +13 -0
- package/dist/src/ui/components/FunctionsView.js +288 -0
- package/dist/src/ui/components/FunctionsView.js.map +1 -0
- package/dist/src/ui/components/JobsView.d.ts +13 -0
- package/dist/src/ui/components/JobsView.js +320 -0
- package/dist/src/ui/components/JobsView.js.map +1 -0
- package/dist/src/ui/components/KVStoreViewer.d.ts +11 -0
- package/dist/src/ui/components/KVStoreViewer.js +168 -0
- package/dist/src/ui/components/KVStoreViewer.js.map +1 -0
- package/dist/src/ui/components/MetadataModal.d.ts +14 -0
- package/dist/src/ui/components/MetadataModal.js +28 -0
- package/dist/src/ui/components/MetadataModal.js.map +1 -0
- package/dist/src/ui/components/MetadataModal.test.d.ts +1 -0
- package/dist/src/ui/components/MetadataModal.test.js +143 -0
- package/dist/src/ui/components/MetadataModal.test.js.map +1 -0
- package/dist/src/ui/components/NotificationViewer.d.ts +16 -0
- package/dist/src/ui/components/NotificationViewer.js +69 -0
- package/dist/src/ui/components/NotificationViewer.js.map +1 -0
- package/dist/src/ui/components/SecretsStoreViewer.d.ts +11 -0
- package/dist/src/ui/components/SecretsStoreViewer.js +179 -0
- package/dist/src/ui/components/SecretsStoreViewer.js.map +1 -0
- package/dist/src/ui/components/SettingsStoreViewer.d.ts +24 -0
- package/dist/src/ui/components/SettingsStoreViewer.js +132 -0
- package/dist/src/ui/components/SettingsStoreViewer.js.map +1 -0
- 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 +181 -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/StoreViewer.d.ts +16 -0
- package/dist/src/ui/components/StoreViewer.js +86 -0
- package/dist/src/ui/components/StoreViewer.js.map +1 -0
- package/dist/src/ui/components/TabbedConsole.d.ts +17 -0
- package/dist/src/ui/components/TabbedConsole.js +163 -0
- package/dist/src/ui/components/TabbedConsole.js.map +1 -0
- package/dist/src/ui/components/common/DataTree.d.ts +15 -0
- package/dist/src/ui/components/common/DataTree.js +95 -0
- package/dist/src/ui/components/common/DataTree.js.map +1 -0
- package/dist/src/ui/components/common/EyeIcon.d.ts +11 -0
- package/dist/src/ui/components/common/EyeIcon.js +11 -0
- package/dist/src/ui/components/common/EyeIcon.js.map +1 -0
- 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.d.ts +1 -0
- package/dist/src/ui/index.js +23 -0
- package/dist/src/ui/index.js.map +1 -0
- package/dist/src/ui/store/formStateSlice.d.ts +54 -0
- package/dist/src/ui/store/formStateSlice.js +94 -0
- package/dist/src/ui/store/formStateSlice.js.map +1 -0
- package/dist/src/ui/store/hooks.d.ts +6 -0
- package/dist/src/ui/store/hooks.js +8 -0
- package/dist/src/ui/store/hooks.js.map +1 -0
- package/dist/src/ui/store/index.d.ts +11 -0
- package/dist/src/ui/store/index.js +107 -0
- package/dist/src/ui/store/index.js.map +1 -0
- 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 +112 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createDestinationRoutes = createDestinationRoutes;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const LogManager_1 = require("../../logging/LogManager");
|
|
9
|
+
const DestinationExecutor_1 = require("../../executor/DestinationExecutor");
|
|
10
|
+
const local_engine_client_1 = require("../../local_engine/local-engine-client");
|
|
11
|
+
const mockDataGenerator_1 = require("../mockDataGenerator");
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
const logger = LogManager_1.LogManager.getInstance();
|
|
14
|
+
/**
|
|
15
|
+
* Create app configuration object for IPC communication
|
|
16
|
+
*/
|
|
17
|
+
function createAppConfig(app) {
|
|
18
|
+
return {
|
|
19
|
+
manifest: app.manifest,
|
|
20
|
+
path: app.path,
|
|
21
|
+
isBuilt: true,
|
|
22
|
+
isValid: true,
|
|
23
|
+
baseUrl: `http://${config_1.config.server.host}:${config_1.config.server.port}`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create API routes for destination testing
|
|
28
|
+
*/
|
|
29
|
+
function createDestinationRoutes(app, watcher) {
|
|
30
|
+
const router = express_1.default.Router();
|
|
31
|
+
const destinationExecutor = new DestinationExecutor_1.DestinationExecutor(app, watcher);
|
|
32
|
+
const localEngineClient = local_engine_client_1.LocalEngineClient.getInstance();
|
|
33
|
+
/**
|
|
34
|
+
* GET /destinations - List all destinations from app manifest
|
|
35
|
+
*/
|
|
36
|
+
router.get('/', (req, res) => {
|
|
37
|
+
try {
|
|
38
|
+
const destinations = app.manifest.destinations || {};
|
|
39
|
+
const destinationList = Object.keys(destinations).map(id => ({
|
|
40
|
+
id,
|
|
41
|
+
description: destinations[id].description,
|
|
42
|
+
entry_point: destinations[id].entry_point,
|
|
43
|
+
schema: destinations[id].schema
|
|
44
|
+
}));
|
|
45
|
+
res.json({ destinations: destinationList });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger.error(LogManager_1.LogSource.System, LogManager_1.LogCategory.Destination, 'Failed to fetch destinations', {
|
|
49
|
+
id: 'unknown',
|
|
50
|
+
operation: 'ready',
|
|
51
|
+
error
|
|
52
|
+
});
|
|
53
|
+
res.status(500).json({ error: 'Failed to fetch destinations' });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* GET /destinations/:destinationId/schema - Get destination schema
|
|
58
|
+
*/
|
|
59
|
+
router.get('/:destinationId/schema', async (req, res) => {
|
|
60
|
+
try {
|
|
61
|
+
const { destinationId } = req.params;
|
|
62
|
+
const destinations = app.manifest.destinations || {};
|
|
63
|
+
if (!destinations[destinationId]) {
|
|
64
|
+
return res.status(404).json({ error: `Destination ${destinationId} not found` });
|
|
65
|
+
}
|
|
66
|
+
// Always delegate to local-engine via IPC
|
|
67
|
+
const schema = await localEngineClient.executeDestinationSchema(destinationId, createAppConfig(app));
|
|
68
|
+
res.json({ schema });
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const destinationId = req.params.destinationId;
|
|
72
|
+
logger.error(LogManager_1.LogSource.System, LogManager_1.LogCategory.Destination, 'Failed to fetch destination schema', {
|
|
73
|
+
id: destinationId,
|
|
74
|
+
operation: 'schema',
|
|
75
|
+
error
|
|
76
|
+
});
|
|
77
|
+
res.status(500).json({
|
|
78
|
+
error: 'Failed to fetch destination schema',
|
|
79
|
+
details: error instanceof Error ? error.message : String(error)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* POST /destinations/:destinationId/ready - Test destination ready
|
|
85
|
+
*/
|
|
86
|
+
router.post('/:destinationId/ready', async (req, res) => {
|
|
87
|
+
try {
|
|
88
|
+
const { destinationId } = req.params;
|
|
89
|
+
const destinations = app.manifest.destinations || {};
|
|
90
|
+
if (!destinations[destinationId]) {
|
|
91
|
+
return res.status(404).json({ error: `Destination ${destinationId} not found` });
|
|
92
|
+
}
|
|
93
|
+
const result = await destinationExecutor.executeReady(destinationId);
|
|
94
|
+
res.json({ result });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const destinationId = req.params.destinationId;
|
|
98
|
+
logger.error(LogManager_1.LogSource.System, LogManager_1.LogCategory.Destination, 'Failed to execute destination ready', {
|
|
99
|
+
id: destinationId,
|
|
100
|
+
operation: 'ready',
|
|
101
|
+
error
|
|
102
|
+
});
|
|
103
|
+
res.status(500).json({
|
|
104
|
+
error: 'Failed to execute destination ready',
|
|
105
|
+
details: error instanceof Error ? error.message : String(error)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* POST /destinations/:destinationId/deliver - Deliver batch to destination
|
|
111
|
+
*/
|
|
112
|
+
router.post('/:destinationId/deliver', async (req, res) => {
|
|
113
|
+
try {
|
|
114
|
+
const { destinationId } = req.params;
|
|
115
|
+
const { batch } = req.body;
|
|
116
|
+
const destinations = app.manifest.destinations || {};
|
|
117
|
+
if (!destinations[destinationId]) {
|
|
118
|
+
return res.status(404).json({ error: `Destination ${destinationId} not found` });
|
|
119
|
+
}
|
|
120
|
+
if (!batch) {
|
|
121
|
+
return res.status(400).json({ error: 'Missing batch in request body' });
|
|
122
|
+
}
|
|
123
|
+
const result = await destinationExecutor.executeDeliver(destinationId, batch);
|
|
124
|
+
res.json({ result });
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const destinationId = req.params.destinationId;
|
|
128
|
+
logger.error(LogManager_1.LogSource.System, LogManager_1.LogCategory.Destination, 'Failed to deliver batch to destination', {
|
|
129
|
+
id: destinationId,
|
|
130
|
+
operation: 'deliver',
|
|
131
|
+
error
|
|
132
|
+
});
|
|
133
|
+
res.status(500).json({
|
|
134
|
+
error: 'Failed to deliver batch',
|
|
135
|
+
details: error instanceof Error ? error.message : String(error)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* POST /destinations/:destinationId/generate-mock - Generate mock batch data
|
|
141
|
+
*/
|
|
142
|
+
router.post('/:destinationId/generate-mock', async (req, res) => {
|
|
143
|
+
try {
|
|
144
|
+
const { destinationId } = req.params;
|
|
145
|
+
const { itemCount = 1 } = req.body;
|
|
146
|
+
const destinations = app.manifest.destinations || {};
|
|
147
|
+
if (!destinations[destinationId]) {
|
|
148
|
+
return res.status(404).json({ error: `Destination ${destinationId} not found` });
|
|
149
|
+
}
|
|
150
|
+
// Always delegate to local-engine via IPC (no duplication!)
|
|
151
|
+
const schema = await localEngineClient.executeDestinationSchema(destinationId, createAppConfig(app));
|
|
152
|
+
const mockBatch = (0, mockDataGenerator_1.generateMockBatch)(schema, itemCount);
|
|
153
|
+
res.json({ batch: mockBatch });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const destinationId = req.params.destinationId;
|
|
157
|
+
logger.error(LogManager_1.LogSource.System, LogManager_1.LogCategory.Destination, 'Failed to generate mock batch', {
|
|
158
|
+
id: destinationId,
|
|
159
|
+
operation: 'schema',
|
|
160
|
+
error
|
|
161
|
+
});
|
|
162
|
+
res.status(500).json({
|
|
163
|
+
error: 'Failed to generate mock batch',
|
|
164
|
+
details: error instanceof Error ? error.message : String(error)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return router;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=destinations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destinations.js","sourceRoot":"","sources":["../../../../src/server/api/destinations.ts"],"names":[],"mappings":";;;;;AA2BA,0DAgKC;AA3LD,sDAAqD;AAErD,yDAA8E;AAC9E,4EAAyE;AACzE,gFAA2E;AAC3E,4DAAyD;AAEzD,sCAAmC;AAEnC,MAAM,MAAM,GAAG,uBAAU,CAAC,WAAW,EAAE,CAAC;AAExC;;GAEG;AACH,SAAS,eAAe,CAAC,GAAQ;IAC/B,OAAO;QACL,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,IAAI,EAAE,GAAG,CAAC,I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AAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { App } from '../../types/app';
|
|
3
|
+
import { LocalConfigStore } from "../../local_engine/storage/LocalConfigStore";
|
|
4
|
+
/**
|
|
5
|
+
* Create API routes for function execution
|
|
6
|
+
*/
|
|
7
|
+
export declare function createFunctionRoutes(app: App, configStore?: LocalConfigStore): express.Router;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createFunctionRoutes = createFunctionRoutes;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
/**
|
|
10
|
+
* Create API routes for function execution
|
|
11
|
+
*/
|
|
12
|
+
function createFunctionRoutes(app, configStore) {
|
|
13
|
+
const router = express_1.default.Router();
|
|
14
|
+
// List all functions
|
|
15
|
+
router.get('/', (req, res) => {
|
|
16
|
+
const functions = app.manifest.functions || {};
|
|
17
|
+
const protocol = req.secure ? 'https' : 'http';
|
|
18
|
+
const host = req.get('host') || `${config_1.config.server.host}:${config_1.config.server.port}`;
|
|
19
|
+
const result = Object.entries(functions).map(([id, func]) => {
|
|
20
|
+
let functionUrl = '';
|
|
21
|
+
if (configStore && configStore.isInstalled()) {
|
|
22
|
+
if (func.global) {
|
|
23
|
+
// Global functions don't have GUID in the URL
|
|
24
|
+
functionUrl = `${protocol}://${host}/functions/${app.manifest.meta.app_id}/${id}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Non-global functions have GUID in the URL
|
|
28
|
+
const guid = configStore.getFunctionGuid(id);
|
|
29
|
+
functionUrl = `${protocol}://${host}/functions/${app.manifest.meta.app_id}/${id}/${guid}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
id,
|
|
34
|
+
entry_point: func.entry_point,
|
|
35
|
+
description: func.description,
|
|
36
|
+
global: func.global || false,
|
|
37
|
+
url: functionUrl
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
res.json(result);
|
|
41
|
+
});
|
|
42
|
+
// Get function details
|
|
43
|
+
router.get('/:functionId', (req, res) => {
|
|
44
|
+
const { functionId } = req.params;
|
|
45
|
+
const functions = app.manifest.functions || {};
|
|
46
|
+
if (!functions[functionId]) {
|
|
47
|
+
return res.status(404).json({
|
|
48
|
+
error: `Function '${functionId}' not found`
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
res.json({
|
|
52
|
+
id: functionId,
|
|
53
|
+
...functions[functionId]
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
// Execute function
|
|
57
|
+
router.post('/:functionId/execute', async (req, res) => {
|
|
58
|
+
const { functionId } = req.params;
|
|
59
|
+
const payload = req.body;
|
|
60
|
+
const functions = app.manifest.functions || {};
|
|
61
|
+
if (!functions[functionId]) {
|
|
62
|
+
return res.status(404).json({
|
|
63
|
+
error: `Function '${functionId}' not found`
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// For now, just return a placeholder response
|
|
67
|
+
// This will be replaced with actual code execution later
|
|
68
|
+
res.json({
|
|
69
|
+
result: `Function '${functionId}' executed (placeholder)`,
|
|
70
|
+
input: payload,
|
|
71
|
+
logs: [
|
|
72
|
+
`Function ${functionId} execution started`,
|
|
73
|
+
`Function ${functionId} execution completed`
|
|
74
|
+
],
|
|
75
|
+
executionTime: 0
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return router;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +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AAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,KAAK,EAAE,aAAa,UAAU,aAAa;aAC5C,CAAC,CAAC;QACL,CAAC;QAED,8CAA8C;QAC9C,yDAAyD;QACzD,GAAG,CAAC,IAAI,CAAC;YACP,MAAM,EAAE,aAAa,UAAU,0BAA0B;YACzD,KAAK,EAAE,OAAO;YACd,IAAI,EAAE;gBACJ,YAAY,UAAU,oBAAoB;gBAC1C,YAAY,UAAU,sBAAsB;aAC7C;YACD,aAAa,EAAE,CAAC;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { App } from '../../types/app';
|
|
3
|
+
import { AccountConfig } from '../../executor/JobExecutor';
|
|
4
|
+
import { LocalSettingsStore } from '../../local_engine/storage/LocalSettingsStore';
|
|
5
|
+
import { LocalConfigStore } from '../../local_engine/storage/LocalConfigStore';
|
|
6
|
+
import { AppWatcher } from '../../executor/watcher';
|
|
7
|
+
/**
|
|
8
|
+
* Create API routes for job execution
|
|
9
|
+
*/
|
|
10
|
+
export declare function createJobRoutes(app: App, settingsStore: LocalSettingsStore, configStore: LocalConfigStore, appDir: string, accountConfig?: AccountConfig, watcher?: AppWatcher): express.Router;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createJobRoutes = createJobRoutes;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const JobExecutor_1 = require("../../executor/JobExecutor");
|
|
9
|
+
const LocalJobStore_1 = require("../../local_engine/storage/LocalJobStore");
|
|
10
|
+
const local_engine_client_1 = require("../../local_engine/local-engine-client");
|
|
11
|
+
/**
|
|
12
|
+
* Create API routes for job execution
|
|
13
|
+
*/
|
|
14
|
+
function createJobRoutes(app, settingsStore, configStore, appDir, accountConfig, watcher) {
|
|
15
|
+
const router = express_1.default.Router();
|
|
16
|
+
const jobExecutor = new JobExecutor_1.JobExecutor(appDir, app, accountConfig, watcher);
|
|
17
|
+
const jobStore = LocalJobStore_1.LocalJobStore.getInstance(appDir);
|
|
18
|
+
// Set JobExecutor on singleton LocalEngineClient for IPC job trigger handling
|
|
19
|
+
local_engine_client_1.LocalEngineClient.getInstance().setJobExecutor(jobExecutor);
|
|
20
|
+
/**
|
|
21
|
+
* GET /jobs - List all jobs from app manifest
|
|
22
|
+
*/
|
|
23
|
+
router.get('/', (req, res) => {
|
|
24
|
+
try {
|
|
25
|
+
const jobs = jobExecutor.getJobs();
|
|
26
|
+
res.json({
|
|
27
|
+
success: true,
|
|
28
|
+
jobs: jobs.map(job => ({
|
|
29
|
+
...job,
|
|
30
|
+
validation: jobExecutor.validateJob(job.id)
|
|
31
|
+
}))
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
res.status(500).json({
|
|
36
|
+
success: false,
|
|
37
|
+
error: {
|
|
38
|
+
message: error.message,
|
|
39
|
+
stack: error.stack
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* GET /jobs/executions - List recent job executions
|
|
46
|
+
*/
|
|
47
|
+
router.get('/executions', (req, res) => {
|
|
48
|
+
try {
|
|
49
|
+
const jobId = req.query.jobId;
|
|
50
|
+
const limit = parseInt(req.query.limit) || 50;
|
|
51
|
+
let executions = jobExecutor.getExecutions(jobId);
|
|
52
|
+
// Limit results
|
|
53
|
+
if (limit > 0) {
|
|
54
|
+
executions = executions.slice(0, limit);
|
|
55
|
+
}
|
|
56
|
+
res.json({
|
|
57
|
+
success: true,
|
|
58
|
+
executions,
|
|
59
|
+
stats: jobExecutor.getStats()
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
res.status(500).json({
|
|
64
|
+
success: false,
|
|
65
|
+
error: {
|
|
66
|
+
message: error.message,
|
|
67
|
+
stack: error.stack
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* GET /jobs/executions/:executionId - Get specific execution details
|
|
74
|
+
*/
|
|
75
|
+
router.get('/executions/:executionId', (req, res) => {
|
|
76
|
+
try {
|
|
77
|
+
const { executionId } = req.params;
|
|
78
|
+
const execution = jobExecutor.getExecution(executionId);
|
|
79
|
+
if (!execution) {
|
|
80
|
+
return res.status(404).json({
|
|
81
|
+
success: false,
|
|
82
|
+
error: {
|
|
83
|
+
message: `Execution not found: ${executionId}`
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
res.json({
|
|
88
|
+
success: true,
|
|
89
|
+
execution
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
res.status(500).json({
|
|
94
|
+
success: false,
|
|
95
|
+
error: {
|
|
96
|
+
message: error.message,
|
|
97
|
+
stack: error.stack
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* GET /jobs/executions/:executionId/states - Get execution state history
|
|
104
|
+
*/
|
|
105
|
+
router.get('/executions/:executionId/states', (req, res) => {
|
|
106
|
+
try {
|
|
107
|
+
const { executionId } = req.params;
|
|
108
|
+
const states = jobExecutor.getExecutionStates(executionId);
|
|
109
|
+
res.json({
|
|
110
|
+
success: true,
|
|
111
|
+
states
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
res.status(500).json({
|
|
116
|
+
success: false,
|
|
117
|
+
error: {
|
|
118
|
+
message: error.message,
|
|
119
|
+
stack: error.stack
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* POST /jobs/:jobId/start - Start job execution
|
|
126
|
+
*/
|
|
127
|
+
router.post('/:jobId/start', async (req, res) => {
|
|
128
|
+
try {
|
|
129
|
+
const { jobId } = req.params;
|
|
130
|
+
const { parameters, dataSyncId, sourceKey } = req.body;
|
|
131
|
+
// Validate job exists
|
|
132
|
+
const jobs = jobExecutor.getJobs();
|
|
133
|
+
const jobDef = jobs.find(j => j.id === jobId);
|
|
134
|
+
if (!jobDef) {
|
|
135
|
+
return res.status(404).json({
|
|
136
|
+
success: false,
|
|
137
|
+
error: {
|
|
138
|
+
message: `Job not found: ${jobId}`
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// Validate job is built
|
|
143
|
+
const validation = jobExecutor.validateJob(jobId);
|
|
144
|
+
if (!validation.valid) {
|
|
145
|
+
return res.status(400).json({
|
|
146
|
+
success: false,
|
|
147
|
+
error: {
|
|
148
|
+
message: validation.error
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
// Create execution request
|
|
153
|
+
const request = {
|
|
154
|
+
jobId,
|
|
155
|
+
parameters: parameters || {},
|
|
156
|
+
dataSyncId,
|
|
157
|
+
sourceKey
|
|
158
|
+
};
|
|
159
|
+
// Execute job asynchronously
|
|
160
|
+
const response = await jobExecutor.executeJob(request);
|
|
161
|
+
res.json({
|
|
162
|
+
success: response.success,
|
|
163
|
+
execution: {
|
|
164
|
+
id: response.executionId,
|
|
165
|
+
status: response.status,
|
|
166
|
+
startedAt: response.startedAt,
|
|
167
|
+
completedAt: response.completedAt,
|
|
168
|
+
executionTime: response.executionTime,
|
|
169
|
+
stateCount: response.stateCount
|
|
170
|
+
},
|
|
171
|
+
error: response.error
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
res.status(500).json({
|
|
176
|
+
success: false,
|
|
177
|
+
error: {
|
|
178
|
+
message: error.message,
|
|
179
|
+
stack: error.stack
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* GET /jobs/:jobId - Get specific job definition
|
|
186
|
+
*/
|
|
187
|
+
router.get('/:jobId', (req, res) => {
|
|
188
|
+
try {
|
|
189
|
+
const { jobId } = req.params;
|
|
190
|
+
const jobs = jobExecutor.getJobs();
|
|
191
|
+
const job = jobs.find(j => j.id === jobId);
|
|
192
|
+
if (!job) {
|
|
193
|
+
return res.status(404).json({
|
|
194
|
+
success: false,
|
|
195
|
+
error: {
|
|
196
|
+
message: `Job not found: ${jobId}`
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
const validation = jobExecutor.validateJob(jobId);
|
|
201
|
+
const executions = jobExecutor.getExecutions(jobId);
|
|
202
|
+
res.json({
|
|
203
|
+
success: true,
|
|
204
|
+
job: {
|
|
205
|
+
...job,
|
|
206
|
+
validation
|
|
207
|
+
},
|
|
208
|
+
recentExecutions: executions.slice(0, 10) // Last 10 executions
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
res.status(500).json({
|
|
213
|
+
success: false,
|
|
214
|
+
error: {
|
|
215
|
+
message: error.message,
|
|
216
|
+
stack: error.stack
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* POST /jobs/cleanup - Clean up old executions
|
|
223
|
+
*/
|
|
224
|
+
router.post('/cleanup', (req, res) => {
|
|
225
|
+
try {
|
|
226
|
+
jobExecutor.cleanup();
|
|
227
|
+
res.json({
|
|
228
|
+
success: true,
|
|
229
|
+
message: 'Job execution cleanup completed'
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
res.status(500).json({
|
|
234
|
+
success: false,
|
|
235
|
+
error: {
|
|
236
|
+
message: error.message,
|
|
237
|
+
stack: error.stack
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return router;
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=jobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../../../src/server/api/jobs.ts"],"names":[],"mappings":";;;;;AAYA,0CA+PC;AA3QD,sDAAqD;AAErD,4DAAwE;AACxE,4EAAyE;AAIzE,gFAA2E;AAE3E;;GAEG;AACH,SAAgB,eAAe,CAC7B,GAAQ,EACR,aAAiC,EACjC,WAA6B,EAC7B,MAAc,EACd,aAA6B,EAC7B,OAAoB;IAEpB,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,WAAW,GAAG,IAAI,yBAAW,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,6BAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEnD,8EAA8E;IAC9E,uCAAiB,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IAE5D;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QAC9C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;YACnC,GAAG,CAAC,IAAI,CAAC;gBACP,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACrB,GAAG,GAAG;oBACN,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;iBAC5C,CAAC,CAA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CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSettingsRoutes = createSettingsRoutes;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
// Store settings in memory for simplicity in this implementation
|
|
11
|
+
// In a real implementation, this would use a proper storage system
|
|
12
|
+
let currentSettings = {};
|
|
13
|
+
/**
|
|
14
|
+
* Create API routes for settings management
|
|
15
|
+
*/
|
|
16
|
+
function createSettingsRoutes(app) {
|
|
17
|
+
const router = express_1.default.Router();
|
|
18
|
+
// Get a specific setting
|
|
19
|
+
router.get('/:key', (req, res) => {
|
|
20
|
+
const { key } = req.params;
|
|
21
|
+
if (currentSettings[key] === undefined) {
|
|
22
|
+
return res.status(404).json({
|
|
23
|
+
success: false,
|
|
24
|
+
error: `Setting '${key}' not found`
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
res.json({
|
|
28
|
+
success: true,
|
|
29
|
+
key,
|
|
30
|
+
value: currentSettings[key]
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
// Reset settings to default
|
|
34
|
+
router.post('/reset', (req, res) => {
|
|
35
|
+
// Reset to empty settings
|
|
36
|
+
currentSettings = {};
|
|
37
|
+
// Save empty settings to file
|
|
38
|
+
saveSettingsToFile(app.path, {});
|
|
39
|
+
res.json({
|
|
40
|
+
success: true,
|
|
41
|
+
settings: {}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
// Initialize settings from file if it exists
|
|
45
|
+
try {
|
|
46
|
+
const savedSettings = loadSettingsFromFile(app.path);
|
|
47
|
+
if (savedSettings) {
|
|
48
|
+
currentSettings = savedSettings;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error('Error loading settings from file:', error);
|
|
53
|
+
}
|
|
54
|
+
return router;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validate settings against schema
|
|
58
|
+
*/
|
|
59
|
+
function validateSettings(settings, schema) {
|
|
60
|
+
const errors = [];
|
|
61
|
+
// Check required fields
|
|
62
|
+
if (schema.required) {
|
|
63
|
+
for (const requiredField of schema.required) {
|
|
64
|
+
if (settings[requiredField] === undefined) {
|
|
65
|
+
errors.push(`Missing required field: ${requiredField}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Check that all settings are defined in schema
|
|
70
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
71
|
+
if (!schema.properties[key]) {
|
|
72
|
+
errors.push(`Unknown setting: ${key}`);
|
|
73
|
+
}
|
|
74
|
+
// Basic type checking could be added here
|
|
75
|
+
// For simplicity, we're skipping it in this implementation
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
valid: errors.length === 0,
|
|
79
|
+
errors: errors.length > 0 ? errors : undefined
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Save settings to a file
|
|
84
|
+
*/
|
|
85
|
+
function saveSettingsToFile(appPath, settings) {
|
|
86
|
+
try {
|
|
87
|
+
const settingsDir = path_1.default.join(appPath, '.ocp-local');
|
|
88
|
+
// Create directory if it doesn't exist
|
|
89
|
+
if (!fs_1.default.existsSync(settingsDir)) {
|
|
90
|
+
fs_1.default.mkdirSync(settingsDir, { recursive: true });
|
|
91
|
+
}
|
|
92
|
+
const settingsPath = path_1.default.join(settingsDir, 'settings.json');
|
|
93
|
+
fs_1.default.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
console.error('Error saving settings to file:', error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Load settings from a file
|
|
101
|
+
*/
|
|
102
|
+
function loadSettingsFromFile(appPath) {
|
|
103
|
+
const settingsPath = path_1.default.join(appPath, '.ocp-local', 'settings.json');
|
|
104
|
+
if (!fs_1.default.existsSync(settingsPath)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const settingsContent = fs_1.default.readFileSync(settingsPath, 'utf8');
|
|
109
|
+
return JSON.parse(settingsContent);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error('Error loading settings from file:', error);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=settings.js.map
|