@smythos/sre 1.5.4 → 1.5.6
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/index.js +122 -22317
- package/dist/index.js.map +1 -1
- package/dist/types/helpers/Sysconfig.helper.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/subsystems/IO/Log.service/connectors/ConsoleLog.class.d.ts +1 -1
- package/dist/types/subsystems/IO/NKV.service/NKVConnector.d.ts +2 -0
- package/dist/types/subsystems/IO/NKV.service/connectors/NKVLocalStorage.class.d.ts +34 -0
- package/dist/types/subsystems/IO/Storage.service/connectors/LocalStorage.class.d.ts +1 -0
- package/package.json +1 -1
- package/src/Components/DataSourceLookup.class.ts +1 -1
- package/src/Core/SmythRuntime.class.ts +3 -66
- package/src/helpers/Sysconfig.helper.ts +67 -0
- package/src/index.ts +2 -0
- package/src/index.ts.bak +178 -176
- package/src/subsystems/AgentManager/AgentLogger.class.ts +1 -1
- package/src/subsystems/IO/Log.service/connectors/ConsoleLog.class.ts +1 -1
- package/src/subsystems/IO/NKV.service/NKVConnector.ts +2 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVLocalStorage.class.ts +211 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRAM.class.ts +1 -1
- package/src/subsystems/IO/NKV.service/index.ts +2 -0
- package/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts +21 -1
- package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +11 -11
|
@@ -4,9 +4,11 @@ import { ConnectorService, ConnectorServiceProvider } from '@sre/Core/Connectors
|
|
|
4
4
|
import { TConnectorService } from '@sre/types/SRE.types';
|
|
5
5
|
import { NKVRedis } from './connectors/NKVRedis.class';
|
|
6
6
|
import { NKVRAM } from './connectors/NKVRAM.class';
|
|
7
|
+
import { NKVLocalStorage } from './connectors/NKVLocalStorage.class';
|
|
7
8
|
export class NKVService extends ConnectorServiceProvider {
|
|
8
9
|
public register() {
|
|
9
10
|
ConnectorService.register(TConnectorService.NKV, 'Redis', NKVRedis);
|
|
10
11
|
ConnectorService.register(TConnectorService.NKV, 'RAM', NKVRAM);
|
|
12
|
+
ConnectorService.register(TConnectorService.NKV, 'LocalStorage', NKVLocalStorage);
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -11,6 +11,7 @@ import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
|
11
11
|
import fs, { existsSync } from 'fs';
|
|
12
12
|
import os from 'os';
|
|
13
13
|
import path from 'path';
|
|
14
|
+
import { findSmythPath } from '../../../..';
|
|
14
15
|
|
|
15
16
|
const console = Logger('LocalStorage');
|
|
16
17
|
|
|
@@ -35,7 +36,7 @@ export class LocalStorage extends StorageConnector {
|
|
|
35
36
|
super(_settings);
|
|
36
37
|
//if (!SmythRuntime.Instance) throw new Error('SRE not initialized');
|
|
37
38
|
|
|
38
|
-
this.folder = _settings?.folder
|
|
39
|
+
this.folder = this.findStorageFolder(_settings?.folder);
|
|
39
40
|
this.initialize();
|
|
40
41
|
if (!fs.existsSync(this.folder)) {
|
|
41
42
|
//throw new Error('Invalid folder provided');
|
|
@@ -43,6 +44,25 @@ export class LocalStorage extends StorageConnector {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
private findStorageFolder(folder) {
|
|
48
|
+
let _storageFolder = folder;
|
|
49
|
+
|
|
50
|
+
if (fs.existsSync(_storageFolder)) {
|
|
51
|
+
return _storageFolder;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_storageFolder = findSmythPath('storage');
|
|
55
|
+
|
|
56
|
+
if (fs.existsSync(_storageFolder)) {
|
|
57
|
+
console.warn('Using alternative storage folder found in : ', _storageFolder);
|
|
58
|
+
return _storageFolder;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.warn('!!! All attempts to find an existing storage folder failed !!!');
|
|
62
|
+
console.warn('!!! I will use this folder: ', _storageFolder);
|
|
63
|
+
return _storageFolder;
|
|
64
|
+
}
|
|
65
|
+
|
|
46
66
|
/**
|
|
47
67
|
* Reads an object from the local storage.
|
|
48
68
|
*
|
|
@@ -13,6 +13,7 @@ import crypto from 'crypto';
|
|
|
13
13
|
import fs from 'fs';
|
|
14
14
|
import * as readlineSync from 'readline-sync';
|
|
15
15
|
import path from 'path';
|
|
16
|
+
import { findSmythPath } from '../../../../helpers/Sysconfig.helper';
|
|
16
17
|
|
|
17
18
|
const console = Logger('JSONFileVault');
|
|
18
19
|
|
|
@@ -57,6 +58,8 @@ export class JSONFileVault extends VaultConnector {
|
|
|
57
58
|
this.vaultData = JSON.parse(fs.readFileSync(vaultFile).toString());
|
|
58
59
|
}
|
|
59
60
|
} catch (e) {
|
|
61
|
+
console.error('Error parsing vault file:', e);
|
|
62
|
+
console.error('!!! Vault features might not work properly !!!');
|
|
60
63
|
this.vaultData = {};
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -82,24 +85,21 @@ export class JSONFileVault extends VaultConnector {
|
|
|
82
85
|
if (fs.existsSync(_vaultFile)) {
|
|
83
86
|
return _vaultFile;
|
|
84
87
|
}
|
|
85
|
-
console.warn('Vault file not found in:', _vaultFile
|
|
88
|
+
console.warn('Vault file not found in:', _vaultFile);
|
|
86
89
|
|
|
87
|
-
//try
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
//try to find the .smyth directory and check if it contains a valid vault
|
|
91
|
+
|
|
92
|
+
_vaultFile = findSmythPath('.sre/vault.json', (dir, success, nextDir) => {
|
|
93
|
+
if (!success) {
|
|
94
|
+
console.warn('Vault file not found in:', nextDir);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
93
97
|
|
|
94
|
-
console.warn('Vault file not found in:', _vaultFile, 'trying to find in user home directory');
|
|
95
|
-
//try to find the vault file in the .smyth directory
|
|
96
|
-
_vaultFile = path.join(os.homedir(), '.smyth', '.sre', 'vault.json');
|
|
97
98
|
if (fs.existsSync(_vaultFile)) {
|
|
98
99
|
console.warn('Using alternative vault file found in : ', _vaultFile);
|
|
99
100
|
return _vaultFile;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
console.warn('Vault file not found in:', _vaultFile);
|
|
103
103
|
console.warn('!!! All attempts to find the vault file failed !!!');
|
|
104
104
|
console.warn('!!! Will continue without vault !!!');
|
|
105
105
|
console.warn('!!! Many features might not work !!!');
|