@contrast/core 1.47.0 → 1.48.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.
- package/lib/ioc/core.js +94 -0
- package/package.json +6 -5
package/lib/ioc/core.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2025 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const EventEmitter = require('events');
|
|
19
|
+
const Perf = require('@contrast/perf');
|
|
20
|
+
|
|
21
|
+
const kComponentName = Symbol('kComponentName');
|
|
22
|
+
|
|
23
|
+
class Core {
|
|
24
|
+
constructor(initData = {}) {
|
|
25
|
+
const core = this;
|
|
26
|
+
// setup perf tools
|
|
27
|
+
|
|
28
|
+
this.Perf = Perf;
|
|
29
|
+
this.perf = new Perf('core');
|
|
30
|
+
Perf.setInterval();
|
|
31
|
+
|
|
32
|
+
// setup messaging
|
|
33
|
+
this.messages = new EventEmitter();
|
|
34
|
+
// pad for number of components that listen for server-settings-update messages
|
|
35
|
+
this.messages.setMaxListeners(10 + this.messages.getMaxListeners());
|
|
36
|
+
|
|
37
|
+
// merge init data
|
|
38
|
+
Object.assign(this, { ...initData });
|
|
39
|
+
|
|
40
|
+
if (process.env.CONTRAST_EXT_PATH) {
|
|
41
|
+
require(process.env.CONTRAST_EXT_PATH)(this);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.messages.on('ext:core.init', (fullName) => {
|
|
45
|
+
// if scopes is composed, then run our event handlers in a no-instrumentation scope
|
|
46
|
+
if (fullName == 'scopes') {
|
|
47
|
+
const store = { name: 'core.messages.emit', lock: true };
|
|
48
|
+
const emit = core.messages.emit.bind(core.messages);
|
|
49
|
+
core.messages.emit = function(...args) {
|
|
50
|
+
return core.scopes.instrumentation.isLocked() ?
|
|
51
|
+
core.scopes.instrumentation.run(store, emit, ...args) :
|
|
52
|
+
emit(...args);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Given a component factory and spec name will initialize the factory using perf.
|
|
60
|
+
* @param {function} factory the component factory function
|
|
61
|
+
* @param {string} specName id used by perf
|
|
62
|
+
*/
|
|
63
|
+
initComponentFactory(factory, specName) {
|
|
64
|
+
this.perf.wrapInit(factory, specName)(this);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* If component factory is decorated with metadata, then we can
|
|
69
|
+
* use the metadata to hook into core's extension events.
|
|
70
|
+
* @param {function} component
|
|
71
|
+
* @param {string} component.fullName
|
|
72
|
+
* @throws {Error} if component doesn't have appropriate metadata
|
|
73
|
+
*/
|
|
74
|
+
initComponentSync(component) {
|
|
75
|
+
this.perf.wrapInit(component, component[kComponentName])(this);
|
|
76
|
+
this.messages.emit('ext:core.init', component[kComponentName]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static isComponent(target) {
|
|
80
|
+
return typeof target == 'function' && target[kComponentName]?.length > 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static makeComponent(meta) {
|
|
84
|
+
if (!meta.factory || !meta.name) throw new Error('makeComponent requires factory and name');
|
|
85
|
+
|
|
86
|
+
// decorate with metadata
|
|
87
|
+
meta.factory[kComponentName] = meta.name;
|
|
88
|
+
|
|
89
|
+
return meta.factory;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = Core;
|
|
94
|
+
module.exports.Core = Core;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "Preconfigured Contrast agent core services and models",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
"test": "../scripts/test.sh"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@contrast/common": "1.
|
|
23
|
-
"@contrast/config": "1.
|
|
22
|
+
"@contrast/common": "1.32.0",
|
|
23
|
+
"@contrast/config": "1.43.0",
|
|
24
24
|
"@contrast/find-package-json": "^1.1.0",
|
|
25
25
|
"@contrast/fn-inspect": "^4.3.0",
|
|
26
|
-
"@contrast/logger": "1.
|
|
27
|
-
"@contrast/patcher": "1.
|
|
26
|
+
"@contrast/logger": "1.21.0",
|
|
27
|
+
"@contrast/patcher": "1.20.0",
|
|
28
|
+
"@contrast/perf": "1.3.1",
|
|
28
29
|
"@tsxper/crc32": "^2.1.3",
|
|
29
30
|
"axios": "^1.7.4",
|
|
30
31
|
"semver": "^7.6.0"
|