Socket
Socket
Sign inDemoInstall

@foal/core

Package Overview
Dependencies
108
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.6 to 0.8.7

lib/common/hooks/validate-cookies.hook.d.ts

1

lib/common/hooks/index.d.ts
export { Log, LogOptions } from './log.hook';
export { ValidateBody } from './validate-body.hook';
export { ValidateCookies } from './validate-cookies.hook';
export { ValidateHeaders } from './validate-headers.hook';
export { ValidateParams } from './validate-params.hook';
export { ValidateQuery } from './validate-query.hook';

@@ -7,2 +7,4 @@ "use strict";

exports.ValidateBody = validate_body_hook_1.ValidateBody;
var validate_cookies_hook_1 = require("./validate-cookies.hook");
exports.ValidateCookies = validate_cookies_hook_1.ValidateCookies;
var validate_headers_hook_1 = require("./validate-headers.hook");

@@ -9,0 +11,0 @@ exports.ValidateHeaders = validate_headers_hook_1.ValidateHeaders;

@@ -50,2 +50,9 @@ /**

abstract statusMessage: string;
/**
* Specify if the body property is a stream.
*
* @type {boolean}
* @memberof HttpResponse
*/
readonly stream: boolean;
private cookies;

@@ -58,3 +65,5 @@ private headers;

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
/**

@@ -155,3 +164,5 @@ * Add or replace a header in the response.

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -193,3 +204,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -211,2 +224,22 @@ /**

/**
* Create an HttpResponseOK whose content is the specified file. If returned in a controller,
* the server sends the file in streaming.
*
* @param {Object} options - The options used to create the HttpResponseOK.
* @param {string} options.directory - Directory where the file is located.
* @param {string} options.file - Name of the file with its extension. If a path is given,
* only the basename is kept.
* @param {boolean} [options.forceDownload=false] - Indicate if the browser should download
* the file directly without trying to display it in the window.
* @param {filename} [options.string=options.file] - Default name used by the browser when
* saving the file to the disk.
* @returns {Promise<HttpResponseOK>}
*/
export declare function createHttpResponseFile(options: {
directory: string;
file: string;
forceDownload?: boolean;
filename?: string;
}): Promise<HttpResponseOK>;
/**
* Represent an HTTP response with the status 201 - CREATED.

@@ -232,3 +265,5 @@ *

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -305,3 +340,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -346,3 +383,5 @@ /**

*/
constructor(path: string, body?: any);
constructor(path: string, body?: any, options?: {
stream?: boolean;
});
}

@@ -383,3 +422,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -422,3 +463,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -461,3 +504,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -500,3 +545,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -538,3 +585,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -576,3 +625,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -615,3 +666,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -647,3 +700,5 @@ /**

readonly isHttpResponseServerError: boolean;
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -686,3 +741,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -725,3 +782,5 @@ /**

*/
constructor(body?: any);
constructor(body?: any, options?: {
stream?: boolean;
});
}

@@ -728,0 +787,0 @@ /**

112

lib/core/http/http-responses.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// std
const fs_1 = require("fs");
const path_1 = require("path");
const util_1 = require("util");
// 3p
const mime_1 = require("mime");
/**

@@ -18,3 +24,3 @@ * Reprensent an HTTP response. This class must be extended.

*/
constructor(body) {
constructor(body, options = {}) {
this.body = body;

@@ -27,4 +33,12 @@ /**

this.isHttpResponse = true;
/**
* Specify if the body property is a stream.
*
* @type {boolean}
* @memberof HttpResponse
*/
this.stream = false;
this.cookies = {};
this.headers = {};
this.stream = options.stream || false;
}

@@ -138,4 +152,4 @@ /**

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -181,4 +195,4 @@ * Property used internally by isHttpResponseSuccess.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -214,2 +228,38 @@ * Property used internally by isHttpResponOK.

/**
* Create an HttpResponseOK whose content is the specified file. If returned in a controller,
* the server sends the file in streaming.
*
* @param {Object} options - The options used to create the HttpResponseOK.
* @param {string} options.directory - Directory where the file is located.
* @param {string} options.file - Name of the file with its extension. If a path is given,
* only the basename is kept.
* @param {boolean} [options.forceDownload=false] - Indicate if the browser should download
* the file directly without trying to display it in the window.
* @param {filename} [options.string=options.file] - Default name used by the browser when
* saving the file to the disk.
* @returns {Promise<HttpResponseOK>}
*/
async function createHttpResponseFile(options) {
const file = path_1.basename(options.file);
const filePath = path_1.join(options.directory, file);
if (!await new Promise(resolve => fs_1.exists(filePath, resolve))) {
throw new Error(`The file "${filePath}" does not exist.`);
}
const stats = await util_1.promisify(fs_1.stat)(filePath);
if (stats.isDirectory()) {
throw new Error(`The directory "${filePath}" is not a file.`);
}
const stream = fs_1.createReadStream(filePath);
const response = new HttpResponseOK(stream, { stream: true });
const mimeType = mime_1.getType(options.file);
if (mimeType) {
response.setHeader('Content-Type', mimeType);
}
response.setHeader('Content-Length', stats.size.toString());
response.setHeader('Content-Disposition', (options.forceDownload ? 'attachement' : 'inline')
+ `; filename="${options.filename || file}"`);
return response;
}
exports.createHttpResponseFile = createHttpResponseFile;
/**
* Represent an HTTP response with the status 201 - CREATED.

@@ -227,4 +277,4 @@ *

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -317,4 +367,4 @@ * Property used internally by isHttpResponseCreated.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -362,4 +412,4 @@ * Property used internally by isHttpResponseRediction.

*/
constructor(path, body) {
super(body);
constructor(path, body, options = {}) {
super(body, options);
this.path = path;

@@ -410,4 +460,4 @@ /**

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -454,4 +504,4 @@ * Property used internally by isHttpResponseClientError.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -500,4 +550,4 @@ * Property used internally by isHttpResponseBadRequest.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -547,4 +597,4 @@ * Property used internally by isHttpResponseUnauthorized.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -592,4 +642,4 @@ * Property used internally by isHttpResponseForbidden.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -637,4 +687,4 @@ * Property used internally by isHttpResponseNotFound.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -683,4 +733,4 @@ * Property used internally by isHttpResponseMethodNotAllowed.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -725,4 +775,4 @@ * Property used internally by isHttpResponseConflict.

class HttpResponseServerError extends HttpResponse {
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -769,4 +819,4 @@ * Property used internally by isHttpResponseServerError.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -815,4 +865,4 @@ * Property used internally by isHttpResponseInternalServerError.

*/
constructor(body) {
super(body);
constructor(body, options = {}) {
super(body, options);
/**

@@ -819,0 +869,0 @@ * Property used internally by isHttpResponseNotImplemented.

@@ -6,3 +6,4 @@ export * from './class.interface';

export * from './routes';
export { ConfigMock } from './config-mock';
export { Config } from './config';
export { createService, dependency, ServiceManager } from './service-manager';

@@ -11,2 +11,4 @@ "use strict";

__export(require("./routes"));
var config_mock_1 = require("./config-mock");
exports.ConfigMock = config_mock_1.ConfigMock;
var config_1 = require("./config");

@@ -13,0 +15,0 @@ exports.Config = config_1.Config;

@@ -28,3 +28,3 @@ "use strict";

app.use(logger(loggerFormat));
app.use(express.static(core_1.Config.get('settings.staticUrl', 'public')));
app.use(core_1.Config.get('settings.staticPathPrefix', ''), express.static(core_1.Config.get('settings.staticUrl', 'public')));
app.use(helmet());

@@ -45,3 +45,3 @@ app.use(express.json());

resave: core_1.Config.get('settings.session.resave', false),
saveUninitialized: core_1.Config.get('settings.session.saveUninitialized', true),
saveUninitialized: core_1.Config.get('settings.session.saveUninitialized', false),
secret: core_1.Config.get('settings.session.secret', 'default_secret'),

@@ -51,3 +51,3 @@ store: options.store ? options.store(session) : undefined,

if (core_1.Config.get('settings.csrf', false)) {
app.use(csurf());
app.use(csurf({ cookie: core_1.Config.get('settings.csrfOptions.cookie', false) }));
}

@@ -54,0 +54,0 @@ else {

@@ -51,2 +51,6 @@ "use strict";

}
if (response.stream === true) {
response.body.pipe(res);
return;
}
res.send(response.body);

@@ -53,0 +57,0 @@ }

@@ -13,3 +13,3 @@ "use strict";

+ `<pre>${stack}</pre>`
+ 'You are seeing this error because you have debug set to true in your config/settings.js file.'
+ 'You are seeing this error because you have debug set to true in your configuration file.'
+ '</body>'

@@ -16,0 +16,0 @@ + '</html>';

{
"name": "@foal/core",
"version": "0.8.6",
"version": "0.8.7",
"description": "High level web framework to create enterprise-grade Node.JS applications.",

@@ -86,2 +86,3 @@ "main": "./lib/index.js",

"helmet": "^3.12.1",
"mime": "^2.4.0",
"morgan": "^1.9.0",

@@ -91,3 +92,3 @@ "reflect-metadata": "^0.1.10"

"devDependencies": {
"@foal/ejs": "^0.8.6",
"@foal/ejs": "^0.8.7",
"@types/mocha": "^2.2.43",

@@ -94,0 +95,0 @@ "@types/node": "^10.1.2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc