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.
A simple PDF generator module for nestjs framework.
Installation is as simple as running:
npm install nestjs-pdf
or
yarn add nestjs-pdf
.
A basic usage example:
app.module.ts
import { Module } from '@nestjs/common';
import { PDFModule } from 'nestjs-pdf';
@Module({
imports: [
// ... other modules
PDFModule.register({
view: {
root: '/path/to/template',
engine: 'pug',
},
}),
]
})
export class AppModule { };
The module could also be registered asynchronously using the registerAsync
method.
Examples below:
import { Module } from '@nestjs/common';
import { PDFModule, PDFModuleOptions, } from 'nestjs-pdf';
@Module({
imports: [
// ... other modules
PDFModule.registerAsync({
useFactory: (): PDFModuleOptions => ({
view: {
root: '/path/to/template',
engine: 'pug',
},
})
}),
]
})
export class AppModule { };
./pdf-config.service.ts
import { Injectable } from '@nestjs/common';
import { PDFOptionsFactory, PDFModuleOptions } from 'nestjs-pdf';
@Injectable()
export class PdfConfigService implements PDFOptionsFactory {
createPdfOptions(): PDFModuleOptions {
return {
view: {
root: 'path/to/template',
engine: 'pug',
},
};
}
}
The PdfConfigService
SHOULD implement the PDFOptionsFactory
, MUST declare the createPdfOptions
method and MUST return PDFModuleOptions
object.
import { Module } from '@nestjs/common';
import { PdfConfigService } from './pdf-config.service';
import { PDFModule, PDFModuleOptions, } from 'nestjs-pdf';
@Module({
imports: [
// ... other modules
PDFModule.registerAsync({
useClass: PdfConfigService
}),
]
})
export class AppModule { };
app.service.ts
import { Injectable } from "@nestjs/common";
@Injectable()
export class AppService {
constructor(
// ...other dependencies...
@InjectPdf() pdf: PDF,
) { }
async generatePdf() {
await this.pdf({
filename: './filename.pdf', // where pdf will be generated. Generally comprises of the path and filename
template: 'templateName',
}); // This will generate the pdf file at process.cwd() + './filename.pdf'.
}
}
This library uses the html-pdf npm package by marcbachmann under the hood which in turn uses phantomjs by ariya for the html-to-pdf conversion, consolidate by tj as html engine parser allowing users to specify their desired engine, as well as juice by Automattic for inlining resources.
The configuration object received by the register
method is as below:
export interface PDFModuleOptions {
name?: string;
view: ViewOptions;
juice?: JuiceOptions;
}
The name
option would be the name of the module used for retrieval from the dependencies tree.
The ViewOptions
can be further broken down into:
export interface ViewOptions {
root: string;
engine: engine;
extension?: string;
engineOptions?: ViewEngineOptions;
}
where:
root
(required) is the location of the template(s). This MUST be a directory.engine
(required) MUST be a string name of the engines supported by the consolidate
engine parser listed here.extension
(optional) SHOULD be provided where the file extension of the engine used is different from its name. e.g. a swig
template would use .html
as its file extension which is quite different from the engine name. Detailed example found hereengineOptions
(optional) is a JavaScript object representation of the configuration options of engine used.The JuiceOptions
is exactly the same as required in the juice
package specifications here.
The options received by the pdf function is as below:
import { CreateOptions } from 'html-pdf';
export interface PdfOptions extends CreateOptions {
filename?: string;
template: string;
viewportSize?: ViewPortSize;
locals?: {
[key: string]: any;
};
}
This is an extension of the CreateOptions
as provided by the @types/html-pdf.
The filename
(optional) options MUST be a string. This should be the path to the pdf file (created when pdf is generated) to be generated. Where filename
is not given the file will be generated at:
import { join } from "path";
import { tmpdir } from "os";
join(tmpdir(), `html-pdf-${process.pid}.pdf`);
The template
(required) option is the name the directory housing the template html
. This MUST be a directory (name) available in the root
directory provided in the ViewOptions
. The directory must provide a html.<extension>
file. i.e. if using pug engine, the directory must provide a html.pug
file.
The viewportSize
(optional) option is used to simulate the view of the screen when the pdf is grabbed.
The locals
(optional) option is an object that provides variables accessible within the html template(s).
Contributions are welcome.
FAQs
PDF generator for nestjs framework.
The npm package nestjs-pdf receives a total of 47 weekly downloads. As such, nestjs-pdf popularity was classified as not popular.
We found that nestjs-pdf 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.