Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Usage of older version presentation on MNUG bounded to MVCJS.
Example of CMS app on older version.
Dependency injection provides you ioc and great testing features. Module returns single instance of dependency injection.
While using di-node, do not load anything via require, except di-node otherwise you will not be able to mock that object or provide custom implementation of that object when it's needed.
VERY IMPORTANT is to pass local require resolver to correctly resolve dependencies
let DI = require('di-node');
let di = new DI(require);
/// do something here
di.setAlias('mypath', __dirname + '/mypath');
module.exports = di;
let di = require('./di');
let Type = di.load('typed-js');
let fs = di.load('fs');
class D extends Type {
constructor(name) {
super(
{
name: Type.STRING
}
);
this.name = name;
}
}
module.exports = new D('Igor');
it('mock', () => {
class A {
constructor(config) {
expect(config).toEqual({name: 'str'});
}
}
A.STRING = 'str';
di.setAlias('b', __dirname + '/b');
let val = di.load('@{b}/di-test');
expect(val instanceof Type).toBe(true);
let valMock = di.mock('@{b}/di-test', {
'typed-js': A
});
expect(valMock instanceof A).toBe(true);
});
While using di-node do not load anything via require except di-node otherwise you will not be able to mock that object or provide custom implementation of that object when it's needed.
'use strict';
let di = require('./di');
let Type = di.load('typed-js');
let fs = di.load('fs');
class D extends Type {
constructor(name) {
super(
{
name: Type.STRING
}
);
this.name = name;
}
}
Because you will not be able to mock fs when it's needed
'use strict';
let di = require('./di');
let Type = di.load('typed-js');
let fs = require('fs');
class D extends Type {
constructor(name) {
super(
{
name: Type.STRING
}
);
this.name = name;
}
}
Mock is used for testing purposes {string} module {Object} definition of modules
it('mock', () => {
class A {
constructor(config) {
expect(config).toEqual({name: 'str'});
}
}
A.STRING = 'str';
di.setAlias('b', __dirname + '/b');
let val = di.load('@{b}/di-test');
expect(val instanceof Type).toBe(true);
let valMock = di.mock('@{b}/di-test', {
'typed-js': A
});
expect(valMock instanceof A).toBe(true);
});
Sets specific path alias which can be used in load method {string} key {string} value
// set aliases
di.setAlias('app', __dirname + '/app');
di.setAlias('components', '@{app}/components');
// usage
di.load('@{app}/module');
di.load('@{components}/redis');
Get specific alias {string} key return {string}
di.setAlias('app', __dirname + '/app');
di.getAlias('app'); // returns __dirname/app
Check if alias is setted return {boolean}
di.setAlias('app', __dirname + '/app');
di.hasAlias('app'); // true
Normalize path return {string}
di.setAlias('app', '/app');
di.setAlias('components', '@{app}/components');
di.normalize('@{components}/path'); // returns /app/components/path
Set specific module {string} key {Object|Any} value
// My fs implementation
di.setModule('fs', {
readFileSync: {
}
});
di.setModule('app/info', '@{app}/core/info');
// usage
di.load('fs'); // will load custom implementation
di.load('app/info'); // will load appPath/core/info.js
Get specific module {string} key return {Object|Any} value
di.setModule('fs', {
readFileSync: {
}
});
di.getModule('fs'); // returns custom fs module
Check if module is registered in di return {boolean}
di.setModule('custom', {
readFileSync: {
}
});
di.hasModule('custom'); // true
FAQs
Dependency injection for node js
The npm package di-node receives a total of 0 weekly downloads. As such, di-node popularity was classified as not popular.
We found that di-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.