lsh-framework 3.2.5 → 3.5.1

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 (54) 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/self.js +22 -16
  5. package/dist/commands/sync.js +49 -38
  6. package/dist/constants/config.js +3 -0
  7. package/dist/lib/floating-point-arithmetic.js +2 -2
  8. package/dist/lib/ipfs-client-manager.js +51 -13
  9. package/dist/lib/ipfs-secrets-storage.js +21 -16
  10. package/dist/lib/ipfs-sync.js +88 -14
  11. package/dist/lib/secrets-manager.js +117 -47
  12. package/dist/lib/sync-key-store.js +87 -0
  13. package/dist/services/secrets/secrets.js +77 -39
  14. package/package.json +16 -16
  15. package/dist/__tests__/fixtures/job-fixtures.js +0 -204
  16. package/dist/__tests__/fixtures/supabase-mocks.js +0 -252
  17. package/dist/daemon/job-registry.js +0 -556
  18. package/dist/daemon/lshd.js +0 -968
  19. package/dist/daemon/saas-api-routes.js +0 -599
  20. package/dist/daemon/saas-api-server.js +0 -231
  21. package/dist/examples/supabase-integration.js +0 -106
  22. package/dist/lib/api-response.js +0 -226
  23. package/dist/lib/base-command-registrar.js +0 -287
  24. package/dist/lib/base-job-manager.js +0 -295
  25. package/dist/lib/cloud-config-manager.js +0 -348
  26. package/dist/lib/cron-job-manager.js +0 -368
  27. package/dist/lib/daemon-client-helper.js +0 -145
  28. package/dist/lib/daemon-client.js +0 -513
  29. package/dist/lib/database-persistence.js +0 -727
  30. package/dist/lib/database-schema.js +0 -259
  31. package/dist/lib/database-types.js +0 -90
  32. package/dist/lib/enhanced-history-system.js +0 -247
  33. package/dist/lib/history-system.js +0 -246
  34. package/dist/lib/job-manager.js +0 -436
  35. package/dist/lib/job-storage-database.js +0 -164
  36. package/dist/lib/job-storage-memory.js +0 -73
  37. package/dist/lib/local-storage-adapter.js +0 -507
  38. package/dist/lib/optimized-job-scheduler.js +0 -356
  39. package/dist/lib/saas-audit.js +0 -215
  40. package/dist/lib/saas-auth.js +0 -465
  41. package/dist/lib/saas-billing.js +0 -503
  42. package/dist/lib/saas-email.js +0 -403
  43. package/dist/lib/saas-encryption.js +0 -221
  44. package/dist/lib/saas-organizations.js +0 -662
  45. package/dist/lib/saas-secrets.js +0 -408
  46. package/dist/lib/saas-types.js +0 -165
  47. package/dist/lib/supabase-client.js +0 -125
  48. package/dist/lib/supabase-utils.js +0 -396
  49. package/dist/services/cron/cron-registrar.js +0 -240
  50. package/dist/services/cron/cron.js +0 -9
  51. package/dist/services/daemon/daemon-registrar.js +0 -585
  52. package/dist/services/daemon/daemon.js +0 -9
  53. package/dist/services/supabase/supabase-registrar.js +0 -375
  54. package/dist/services/supabase/supabase.js +0 -9
@@ -1,164 +0,0 @@
1
- /**
2
- * Database Job Storage
3
- * Persistent storage for jobs and executions using DatabasePersistence
4
- * Used by CronJobManager and other database-backed managers
5
- */
6
- import DatabasePersistence from './database-persistence.js';
7
- export class DatabaseJobStorage {
8
- persistence;
9
- userId;
10
- constructor(userId) {
11
- this.userId = userId;
12
- this.persistence = new DatabasePersistence(userId);
13
- }
14
- async save(job) {
15
- // Map BaseJobSpec to database format (ShellJob structure)
16
- const dbJob = {
17
- job_id: job.id,
18
- session_id: `job-storage-${Date.now()}`,
19
- command: job.command,
20
- working_directory: process.cwd(),
21
- started_at: job.startedAt?.toISOString() || new Date().toISOString(),
22
- completed_at: job.completedAt?.toISOString(),
23
- status: job.status,
24
- pid: job.pid,
25
- exit_code: job.exitCode,
26
- output: job.stdout,
27
- error: job.stderr,
28
- };
29
- // Save using available method
30
- await this.persistence.saveJob(dbJob);
31
- }
32
- async get(_jobId) {
33
- // This would require adding a method to DatabasePersistence
34
- // For now, return null and rely on list() filtering
35
- return null;
36
- }
37
- async list(_filter) {
38
- // Get active jobs from database
39
- const dbJobs = await this.persistence.getActiveJobs();
40
- // Convert to BaseJobSpec format
41
- const jobs = dbJobs.map(dbJob => ({
42
- id: dbJob.job_id,
43
- name: dbJob.job_id, // Using job_id as name since name field doesn't exist
44
- command: dbJob.command,
45
- status: this.mapDbStatusToJobStatus(dbJob.status),
46
- createdAt: new Date(dbJob.started_at),
47
- startedAt: new Date(dbJob.started_at),
48
- completedAt: dbJob.completed_at ? new Date(dbJob.completed_at) : undefined,
49
- user: this.userId,
50
- tags: [],
51
- priority: 5,
52
- maxRetries: 3,
53
- retryCount: 0,
54
- databaseSync: true,
55
- exitCode: dbJob.exit_code,
56
- stdout: dbJob.output,
57
- stderr: dbJob.error,
58
- }));
59
- return jobs;
60
- }
61
- mapDbStatusToJobStatus(dbStatus) {
62
- switch (dbStatus) {
63
- case 'running':
64
- return 'running';
65
- case 'completed':
66
- case 'success':
67
- return 'completed';
68
- case 'stopped':
69
- return 'stopped';
70
- case 'paused':
71
- return 'paused';
72
- case 'failed':
73
- case 'timeout':
74
- return 'failed';
75
- case 'killed':
76
- return 'killed';
77
- default:
78
- return 'created';
79
- }
80
- }
81
- async update(jobId, updates) {
82
- // Update by saving again (upsert behavior)
83
- if (updates.command) {
84
- const dbJob = {
85
- job_id: jobId,
86
- session_id: `job-storage-${Date.now()}`,
87
- command: updates.command,
88
- working_directory: process.cwd(),
89
- started_at: updates.startedAt?.toISOString() || new Date().toISOString(),
90
- completed_at: updates.completedAt?.toISOString(),
91
- status: (updates.status || 'running'),
92
- pid: updates.pid,
93
- exit_code: updates.exitCode,
94
- output: updates.stdout,
95
- error: updates.stderr,
96
- };
97
- await this.persistence.saveJob(dbJob);
98
- }
99
- }
100
- async delete(jobId) {
101
- // DatabasePersistence doesn't have a delete method yet
102
- // This would need to be added
103
- console.warn(`Delete not implemented for job ${jobId}`);
104
- }
105
- async saveExecution(execution) {
106
- // Map to database format and save as job (ShellJob structure)
107
- const dbJob = {
108
- job_id: execution.jobId,
109
- session_id: `execution-${Date.now()}`,
110
- command: execution.command,
111
- working_directory: process.cwd(),
112
- started_at: execution.startTime.toISOString(),
113
- completed_at: execution.endTime?.toISOString(),
114
- status: execution.status,
115
- exit_code: execution.exitCode,
116
- output: execution.stdout,
117
- error: execution.stderr || execution.errorMessage,
118
- };
119
- await this.persistence.saveJob(dbJob);
120
- }
121
- async getExecutions(jobId, limit = 50) {
122
- // Get active jobs (no specific history method available yet)
123
- const dbJobs = await this.persistence.getActiveJobs();
124
- const jobExecutions = dbJobs.filter(job => job.job_id === jobId);
125
- return jobExecutions.slice(0, limit).map(dbExec => ({
126
- executionId: `exec_${dbExec.job_id}_${Date.now()}`,
127
- jobId: dbExec.job_id,
128
- jobName: dbExec.job_id,
129
- command: dbExec.command,
130
- startTime: new Date(dbExec.started_at),
131
- endTime: dbExec.completed_at ? new Date(dbExec.completed_at) : undefined,
132
- duration: dbExec.completed_at
133
- ? new Date(dbExec.completed_at).getTime() - new Date(dbExec.started_at).getTime()
134
- : undefined,
135
- status: this.mapDbStatus(dbExec.status),
136
- exitCode: dbExec.exit_code,
137
- stdout: dbExec.output,
138
- stderr: dbExec.error,
139
- errorMessage: dbExec.error,
140
- }));
141
- }
142
- mapDbStatus(dbStatus) {
143
- switch (dbStatus) {
144
- case 'running':
145
- return 'running';
146
- case 'completed':
147
- case 'success':
148
- return 'completed';
149
- case 'failed':
150
- return 'failed';
151
- case 'killed':
152
- return 'killed';
153
- case 'timeout':
154
- return 'timeout';
155
- default:
156
- return 'failed';
157
- }
158
- }
159
- async cleanup() {
160
- // DatabasePersistence maintains its own connections
161
- // No cleanup needed here
162
- }
163
- }
164
- export default DatabaseJobStorage;
@@ -1,73 +0,0 @@
1
- /**
2
- * In-Memory Job Storage
3
- * Fast, volatile storage for jobs and executions
4
- * Used by JobManager for runtime job tracking
5
- */
6
- export class MemoryJobStorage {
7
- jobs = new Map();
8
- executions = new Map();
9
- maxExecutionsPerJob;
10
- constructor(maxExecutionsPerJob = 100) {
11
- this.maxExecutionsPerJob = maxExecutionsPerJob;
12
- }
13
- async save(job) {
14
- this.jobs.set(job.id, { ...job });
15
- }
16
- async get(jobId) {
17
- const job = this.jobs.get(jobId);
18
- return job ? { ...job } : null;
19
- }
20
- async list(filter) {
21
- let jobs = Array.from(this.jobs.values()).map(job => ({ ...job }));
22
- // Basic filtering (additional filters applied by BaseJobManager)
23
- if (filter?.status) {
24
- const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
25
- jobs = jobs.filter(job => statuses.includes(job.status));
26
- }
27
- return jobs;
28
- }
29
- async update(jobId, updates) {
30
- const job = this.jobs.get(jobId);
31
- if (!job) {
32
- throw new Error(`Job ${jobId} not found`);
33
- }
34
- Object.assign(job, updates);
35
- this.jobs.set(jobId, job);
36
- }
37
- async delete(jobId) {
38
- this.jobs.delete(jobId);
39
- this.executions.delete(jobId);
40
- }
41
- async saveExecution(execution) {
42
- const jobExecutions = this.executions.get(execution.jobId) || [];
43
- // Add new execution at the beginning
44
- jobExecutions.unshift(execution);
45
- // Limit number of executions stored
46
- if (jobExecutions.length > this.maxExecutionsPerJob) {
47
- jobExecutions.length = this.maxExecutionsPerJob;
48
- }
49
- this.executions.set(execution.jobId, jobExecutions);
50
- }
51
- async getExecutions(jobId, limit) {
52
- const jobExecutions = this.executions.get(jobId) || [];
53
- if (limit && limit < jobExecutions.length) {
54
- return jobExecutions.slice(0, limit);
55
- }
56
- return jobExecutions.map(e => ({ ...e }));
57
- }
58
- async cleanup() {
59
- this.jobs.clear();
60
- this.executions.clear();
61
- }
62
- // Additional utility methods
63
- getJobCount() {
64
- return this.jobs.size;
65
- }
66
- getExecutionCount(jobId) {
67
- if (jobId) {
68
- return this.executions.get(jobId)?.length || 0;
69
- }
70
- return Array.from(this.executions.values()).reduce((sum, execs) => sum + execs.length, 0);
71
- }
72
- }
73
- export default MemoryJobStorage;