Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
justinject
Advanced tools
Node module for DI in Typescript
It is lightweight and very easy to use.
To install it type:
npm i justinject -S
And it is necessary to enable:
"experimentalDecorators": true "emitDecoratorMetadata": true
in tsconfig.json file
@Service()
export class FirstService {
private time: any;
constructor() {
this.time = new Date();
}
public method() {
return this.time;
}
}
@Service()
export class SecondService {
constructor(public first: FirstService) { }
public method() {
return this.first.method();
}
}
import { Container } from 'justinject';
import { SecondService } from './SecondService';
const second = Container.resolve<SecondService>(SecondService);
console.log(second.method());
// retruns date
To specify Service as singleton add singelton key word in decorator @Service('singleton')
To mock Service is pretty easy, example:
@Service()
export class FirstServiceMock extends FirstService{
private time: any;
constructor() {
this.time = new Date();
}
public method() {
return `${this.time} mocked`;
}
}
Container.mock([
{
service: FirstService,
mockWith: FirstServiceMock,
override: false,
type: 'default'
}
])
const second = Container.resolve<SecondService>(SecondService);
console.log(second.method());
// retruns date mocked
Hemera is node microservices framework. You can find more details here: https://github.com/hemerajs/hemera
Justinject has support for hemera actions. You can declare new action like this:
@Service()
export class ActionService {
constructor(public hemera: HemeraService, public validate: ValidateService) { }
@Action({
topic: 'new.topic',
cmd: 'gogo'
}, { additionalPattern: 'dothat', newAdditionalPattern: 'dothis' })
public action(msg: any, done: any) {
console.log('Action message', msg.data);
done(null, 'Hemera action called!');
}
}
ActionService must have 2 properties hemera and validator.
HemeraService must have instance getter which returns Hemera instance.
ValidateService must have schema getter which returns validation.
FAQs
Light DI for typescript
We found that justinject 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.