lsh-framework 3.2.5 → 3.5.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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -34
  3. package/dist/commands/ipfs.js +7 -12
  4. package/dist/commands/sync.js +49 -38
  5. package/dist/constants/config.js +3 -0
  6. package/dist/lib/floating-point-arithmetic.js +2 -2
  7. package/dist/lib/ipfs-client-manager.js +51 -13
  8. package/dist/lib/ipfs-secrets-storage.js +21 -16
  9. package/dist/lib/ipfs-sync.js +88 -14
  10. package/dist/lib/secrets-manager.js +117 -47
  11. package/dist/lib/sync-key-store.js +87 -0
  12. package/dist/services/secrets/secrets.js +77 -39
  13. package/package.json +16 -16
  14. package/dist/__tests__/fixtures/job-fixtures.js +0 -204
  15. package/dist/__tests__/fixtures/supabase-mocks.js +0 -252
  16. package/dist/daemon/job-registry.js +0 -556
  17. package/dist/daemon/lshd.js +0 -968
  18. package/dist/daemon/saas-api-routes.js +0 -599
  19. package/dist/daemon/saas-api-server.js +0 -231
  20. package/dist/examples/supabase-integration.js +0 -106
  21. package/dist/lib/api-response.js +0 -226
  22. package/dist/lib/base-command-registrar.js +0 -287
  23. package/dist/lib/base-job-manager.js +0 -295
  24. package/dist/lib/cloud-config-manager.js +0 -348
  25. package/dist/lib/cron-job-manager.js +0 -368
  26. package/dist/lib/daemon-client-helper.js +0 -145
  27. package/dist/lib/daemon-client.js +0 -513
  28. package/dist/lib/database-persistence.js +0 -727
  29. package/dist/lib/database-schema.js +0 -259
  30. package/dist/lib/database-types.js +0 -90
  31. package/dist/lib/enhanced-history-system.js +0 -247
  32. package/dist/lib/history-system.js +0 -246
  33. package/dist/lib/job-manager.js +0 -436
  34. package/dist/lib/job-storage-database.js +0 -164
  35. package/dist/lib/job-storage-memory.js +0 -73
  36. package/dist/lib/local-storage-adapter.js +0 -507
  37. package/dist/lib/optimized-job-scheduler.js +0 -356
  38. package/dist/lib/saas-audit.js +0 -215
  39. package/dist/lib/saas-auth.js +0 -465
  40. package/dist/lib/saas-billing.js +0 -503
  41. package/dist/lib/saas-email.js +0 -403
  42. package/dist/lib/saas-encryption.js +0 -221
  43. package/dist/lib/saas-organizations.js +0 -662
  44. package/dist/lib/saas-secrets.js +0 -408
  45. package/dist/lib/saas-types.js +0 -165
  46. package/dist/lib/supabase-client.js +0 -125
  47. package/dist/lib/supabase-utils.js +0 -396
  48. package/dist/services/cron/cron-registrar.js +0 -240
  49. package/dist/services/cron/cron.js +0 -9
  50. package/dist/services/daemon/daemon-registrar.js +0 -585
  51. package/dist/services/daemon/daemon.js +0 -9
  52. package/dist/services/supabase/supabase-registrar.js +0 -375
  53. package/dist/services/supabase/supabase.js +0 -9
@@ -1,348 +0,0 @@
1
- /**
2
- * Cloud Configuration Manager
3
- * Manages shell configuration with Supabase persistence
4
- */
5
- import DatabasePersistence from './database-persistence.js';
6
- import * as fs from 'fs';
7
- import * as path from 'path';
8
- import * as os from 'os';
9
- import { DEFAULTS } from '../constants/index.js';
10
- export class CloudConfigManager {
11
- databasePersistence;
12
- options;
13
- localConfig = new Map();
14
- cloudConfig = new Map();
15
- syncTimer;
16
- constructor(options = {}) {
17
- this.options = {
18
- userId: undefined,
19
- enableCloudSync: true,
20
- localConfigPath: path.join(os.homedir(), '.lshrc'),
21
- syncInterval: DEFAULTS.CLOUD_CONFIG_SYNC_INTERVAL_MS,
22
- ...options,
23
- };
24
- this.databasePersistence = new DatabasePersistence(this.options.userId);
25
- this.loadLocalConfig();
26
- if (this.options.enableCloudSync) {
27
- this.initializeCloudSync();
28
- }
29
- }
30
- /**
31
- * Load local configuration file
32
- */
33
- loadLocalConfig() {
34
- try {
35
- if (fs.existsSync(this.options.localConfigPath)) {
36
- const content = fs.readFileSync(this.options.localConfigPath, 'utf8');
37
- const config = JSON.parse(content);
38
- Object.entries(config).forEach(([key, value]) => {
39
- this.localConfig.set(key, {
40
- key,
41
- value,
42
- type: this.getType(value),
43
- isDefault: false,
44
- });
45
- });
46
- }
47
- }
48
- catch (error) {
49
- console.error('Failed to load local config:', error);
50
- }
51
- }
52
- /**
53
- * Save local configuration file
54
- */
55
- saveLocalConfig() {
56
- try {
57
- const config = {};
58
- this.localConfig.forEach((configValue, key) => {
59
- config[key] = configValue.value;
60
- });
61
- fs.writeFileSync(this.options.localConfigPath, JSON.stringify(config, null, 2));
62
- }
63
- catch (error) {
64
- console.error('Failed to save local config:', error);
65
- }
66
- }
67
- /**
68
- * Get type of a value
69
- */
70
- getType(value) {
71
- if (typeof value === 'string')
72
- return 'string';
73
- if (typeof value === 'number')
74
- return 'number';
75
- if (typeof value === 'boolean')
76
- return 'boolean';
77
- if (Array.isArray(value))
78
- return 'array';
79
- if (typeof value === 'object' && value !== null)
80
- return 'object';
81
- return 'string';
82
- }
83
- /**
84
- * Initialize cloud synchronization
85
- */
86
- async initializeCloudSync() {
87
- try {
88
- const isConnected = await this.databasePersistence.testConnection();
89
- if (isConnected) {
90
- console.log('✅ Cloud config sync enabled');
91
- await this.loadCloudConfig();
92
- this.startSyncTimer();
93
- }
94
- else {
95
- console.log('⚠️ Cloud config sync disabled - database not available');
96
- }
97
- }
98
- catch (error) {
99
- console.error('Failed to initialize cloud config sync:', error);
100
- }
101
- }
102
- /**
103
- * Load configuration from cloud
104
- */
105
- async loadCloudConfig() {
106
- try {
107
- const cloudConfigs = await this.databasePersistence.getConfiguration();
108
- cloudConfigs.forEach(config => {
109
- this.cloudConfig.set(config.config_key, {
110
- key: config.config_key,
111
- value: this.parseConfigValue(config.config_value, config.config_type),
112
- type: config.config_type,
113
- description: config.description,
114
- isDefault: config.is_default,
115
- });
116
- });
117
- // Merge cloud config with local config
118
- this.mergeConfigurations();
119
- }
120
- catch (error) {
121
- console.error('Failed to load cloud config:', error);
122
- }
123
- }
124
- /**
125
- * Parse configuration value based on type
126
- */
127
- parseConfigValue(value, type) {
128
- try {
129
- switch (type) {
130
- case 'string':
131
- return value;
132
- case 'number':
133
- return parseFloat(value);
134
- case 'boolean':
135
- return value === 'true';
136
- case 'array':
137
- case 'object':
138
- return JSON.parse(value);
139
- default:
140
- return value;
141
- }
142
- }
143
- catch (error) {
144
- console.error(`Failed to parse config value ${value} as ${type}:`, error);
145
- return value;
146
- }
147
- }
148
- /**
149
- * Serialize configuration value to string
150
- */
151
- serializeConfigValue(value, type) {
152
- switch (type) {
153
- case 'string':
154
- case 'number':
155
- case 'boolean':
156
- return String(value);
157
- case 'array':
158
- case 'object':
159
- return JSON.stringify(value);
160
- default:
161
- return String(value);
162
- }
163
- }
164
- /**
165
- * Merge cloud and local configurations
166
- */
167
- mergeConfigurations() {
168
- // Cloud config takes precedence for non-local overrides
169
- this.cloudConfig.forEach((cloudValue, key) => {
170
- if (!this.localConfig.has(key)) {
171
- this.localConfig.set(key, cloudValue);
172
- }
173
- });
174
- }
175
- /**
176
- * Start periodic synchronization timer
177
- */
178
- startSyncTimer() {
179
- this.syncTimer = setInterval(() => {
180
- this.syncToCloud();
181
- }, this.options.syncInterval);
182
- }
183
- /**
184
- * Stop synchronization timer
185
- */
186
- stopSyncTimer() {
187
- if (this.syncTimer) {
188
- clearInterval(this.syncTimer);
189
- this.syncTimer = undefined;
190
- }
191
- }
192
- /**
193
- * Synchronize local configuration to cloud
194
- */
195
- async syncToCloud() {
196
- if (!this.options.enableCloudSync) {
197
- return;
198
- }
199
- try {
200
- for (const [key, configValue] of this.localConfig) {
201
- await this.databasePersistence.saveConfiguration({
202
- config_key: key,
203
- config_value: this.serializeConfigValue(configValue.value, configValue.type),
204
- config_type: configValue.type,
205
- description: configValue.description,
206
- is_default: configValue.isDefault,
207
- });
208
- }
209
- }
210
- catch (error) {
211
- console.error('Failed to sync config to cloud:', error);
212
- }
213
- }
214
- /**
215
- * Get configuration value
216
- */
217
- get(key, defaultValue) {
218
- const configValue = this.localConfig.get(key);
219
- return configValue ? configValue.value : defaultValue;
220
- }
221
- /**
222
- * Set configuration value
223
- */
224
- set(key, value, description) {
225
- const configValue = {
226
- key,
227
- value,
228
- type: this.getType(value),
229
- description,
230
- isDefault: false,
231
- };
232
- this.localConfig.set(key, configValue);
233
- this.saveLocalConfig();
234
- // Sync to cloud if enabled
235
- if (this.options.enableCloudSync) {
236
- this.syncToCloud().catch(error => {
237
- console.error('Failed to sync config to cloud:', error);
238
- });
239
- }
240
- }
241
- /**
242
- * Get all configuration keys
243
- */
244
- getKeys() {
245
- return Array.from(this.localConfig.keys());
246
- }
247
- /**
248
- * Get all configuration entries
249
- */
250
- getAll() {
251
- return Array.from(this.localConfig.values());
252
- }
253
- /**
254
- * Check if configuration key exists
255
- */
256
- has(key) {
257
- return this.localConfig.has(key);
258
- }
259
- /**
260
- * Delete configuration key
261
- */
262
- delete(key) {
263
- this.localConfig.delete(key);
264
- this.saveLocalConfig();
265
- // Sync to cloud if enabled
266
- if (this.options.enableCloudSync) {
267
- this.syncToCloud().catch(error => {
268
- console.error('Failed to sync config deletion to cloud:', error);
269
- });
270
- }
271
- }
272
- /**
273
- * Reset configuration to defaults
274
- */
275
- reset() {
276
- this.localConfig.clear();
277
- this.saveLocalConfig();
278
- if (this.options.enableCloudSync) {
279
- this.syncToCloud().catch(error => {
280
- console.error('Failed to sync config reset to cloud:', error);
281
- });
282
- }
283
- }
284
- /**
285
- * Export configuration to JSON
286
- */
287
- export() {
288
- const config = {};
289
- this.localConfig.forEach((configValue, key) => {
290
- config[key] = configValue.value;
291
- });
292
- return JSON.stringify(config, null, 2);
293
- }
294
- /**
295
- * Import configuration from JSON
296
- */
297
- import(configJson) {
298
- try {
299
- const config = JSON.parse(configJson);
300
- Object.entries(config).forEach(([key, value]) => {
301
- this.set(key, value);
302
- });
303
- }
304
- catch (error) {
305
- console.error('Failed to import configuration:', error);
306
- throw new Error('Invalid configuration JSON');
307
- }
308
- }
309
- /**
310
- * Get configuration statistics
311
- */
312
- getStats() {
313
- const types = {};
314
- this.localConfig.forEach(configValue => {
315
- types[configValue.type] = (types[configValue.type] || 0) + 1;
316
- });
317
- return {
318
- totalKeys: this.localConfig.size,
319
- localKeys: this.localConfig.size,
320
- cloudKeys: this.cloudConfig.size,
321
- types,
322
- };
323
- }
324
- /**
325
- * Enable or disable cloud sync
326
- */
327
- setCloudSyncEnabled(enabled) {
328
- this.options.enableCloudSync = enabled;
329
- if (enabled) {
330
- this.initializeCloudSync();
331
- }
332
- else {
333
- this.stopSyncTimer();
334
- }
335
- }
336
- /**
337
- * Cleanup resources
338
- */
339
- destroy() {
340
- this.stopSyncTimer();
341
- if (this.options.enableCloudSync) {
342
- this.syncToCloud().catch(error => {
343
- console.error('Failed to final config sync on destroy:', error);
344
- });
345
- }
346
- }
347
- }
348
- export default CloudConfigManager;