@indra.ai/deva.security 0.37.7 → 0.37.9
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 +1 -1
- package/index.js +76 -76
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ Help lives in Feecting files. `help/main.feecting` is the main help page, with t
|
|
|
138
138
|
| Name | Kind | What it does |
|
|
139
139
|
| --- | --- | --- |
|
|
140
140
|
| `write_log` | func | Inserts a packet into a named collection in the log database, as described above. It lives in `index.js`. |
|
|
141
|
-
| `
|
|
141
|
+
| `uid`, `sign`, `hash`, `encrypt`, `decrypt`, `date`, `time` | feature methods | The commands in `feature/methods.js`, bound at runtime. |
|
|
142
142
|
| `translate`, `parse`, `process` | utils | Each returns its input trimmed. |
|
|
143
143
|
| `onReady` | lifecycle | Builds the MongoDB client from the security feature's `global.mongo` and prompts the ready message. |
|
|
144
144
|
| `onStop` | lifecycle | Closes the MongoDB client, if there is one, then calls `this.close(data, resolve)`. |
|
package/index.js
CHANGED
|
@@ -17,84 +17,84 @@ import {fileURLToPath} from 'node:url';
|
|
|
17
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
18
|
|
|
19
19
|
const info = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
id: pkg.id,
|
|
21
|
+
name: pkg.name,
|
|
22
|
+
describe: pkg.description,
|
|
23
|
+
version: pkg.version,
|
|
24
|
+
url: pkg.homepage,
|
|
25
|
+
dir: __dirname,
|
|
26
|
+
git: pkg.repository.url,
|
|
27
|
+
bugs: pkg.bugs.url,
|
|
28
|
+
author: pkg.author,
|
|
29
|
+
license: pkg.license,
|
|
30
|
+
VLA: pkg.VLA,
|
|
31
|
+
copyright: pkg.copyright,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const SecurityDeva = new Deva({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
35
|
+
info,
|
|
36
|
+
agent,
|
|
37
|
+
vars,
|
|
38
|
+
utils: {
|
|
39
|
+
translate(input) {return input.trim();},
|
|
40
|
+
parse(input) {return input.trim();},
|
|
41
|
+
process(input) {return input.trim();}
|
|
42
|
+
},
|
|
43
|
+
listeners: {
|
|
44
|
+
// log the answer on finish
|
|
45
|
+
'devacore:finish'(packet) {
|
|
46
|
+
if (!this._active) return;
|
|
47
|
+
this.func.write_log('finish', this.lib.copy(packet));
|
|
48
|
+
},
|
|
49
|
+
// log the answer on complete
|
|
50
|
+
'devacore:complete'(packet) {
|
|
51
|
+
if (!this._active) return;
|
|
52
|
+
this.func.write_log('complete', this.lib.copy(packet));
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
modules: {},
|
|
56
|
+
devas: {},
|
|
57
|
+
func: {
|
|
58
|
+
/**************
|
|
59
|
+
func: write_log
|
|
60
|
+
params: type, packet
|
|
61
|
+
describe: this is the log file writer function that handles
|
|
62
|
+
writing for finish and complete for complete chain of custody.
|
|
63
|
+
***************/
|
|
64
|
+
async write_log(type, packet) {
|
|
65
|
+
let result = false;
|
|
66
|
+
if (!this.modules.client) return;
|
|
67
|
+
try {
|
|
68
|
+
const database = this.modules.client.db(this.vars.log);
|
|
69
|
+
const collection = database.collection(type);
|
|
70
|
+
result = await collection.insertOne(packet);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return this.err(err, packet);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
},
|
|
79
|
+
methods: {},
|
|
80
|
+
onReady(data, resolve) {
|
|
81
|
+
const {VLA} = this.info();
|
|
82
|
+
const {uri, database, log} = this.security().global?.mongo || {};
|
|
83
|
+
if (database) this.vars.database = database; // set the main database
|
|
84
|
+
if (log) this.vars.log = log; // set the logging database
|
|
85
|
+
if (uri) this.modules.client = new MongoClient(uri); // build the client if uri is set
|
|
86
|
+
this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
|
|
87
|
+
return resolve(data);
|
|
88
|
+
},
|
|
89
|
+
onStop(data, resolve) {
|
|
90
|
+
const {client} = this.modules;
|
|
91
|
+
if (!client) return this.close(data, resolve);
|
|
92
|
+
return client.close().then(() => this.close(data, resolve)); // close the database before shutdown
|
|
93
|
+
},
|
|
94
|
+
onError(err, data, reject) {
|
|
95
|
+
this.prompt(this.vars.messages.error);
|
|
96
|
+
console.error(err);
|
|
97
|
+
return reject ? reject(err) : Promise.reject(err);
|
|
98
|
+
}
|
|
99
99
|
});
|
|
100
100
|
export default SecurityDeva
|