Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jimpex

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jimpex - npm Package Compare versions

Comparing version 5.1.1 to 5.2.0

12

documents/services.md

@@ -94,3 +94,3 @@ # Built-in Services

class App extends Jimpex {
boot() {
boot() {
// Register the service

@@ -156,3 +156,3 @@ this.register(appError);

// The HTTP status associated to the error, this is for the error handler.
status: statuses.unauthorized,
status: 401,
// Extra context information for the error handler to add to the response.

@@ -226,3 +226,3 @@ response: {},

class App extends Jimpex {
boot() {
boot() {
// Register the service

@@ -260,3 +260,3 @@ this.register(httpError);

class App extends Jimpex {
boot() {
boot() {
// Register the service

@@ -315,3 +315,3 @@ this.register(sendFile);

class App extends Jimpex {
boot() {
boot() {
// Register the service

@@ -487,4 +487,4 @@ this.register(frontendFs);

// How many ms should it wait before closing the window, if `options.close` is `true`.
closeDelay: 700,
closeDelay: 700,
}
```

@@ -5,3 +5,3 @@ {

"homepage": "https://homer0.github.io/jimpex/",
"version": "5.1.1",
"version": "5.2.0",
"repository": "homer0/jimpex",

@@ -11,3 +11,3 @@ "author": "Leonardo Apiwan (@homer0) <me@homer0.com>",

"dependencies": {
"wootils": "^3.0.3",
"wootils": "^3.0.4",
"jimple": "^1.5.0",

@@ -19,12 +19,12 @@ "express": "^4.17.1",

"urijs": "^1.19.2",
"statuses": "^1.5.0",
"fs-extra": "^9.0.0",
"statuses": "^2.0.0",
"fs-extra": "^9.0.1",
"multer": "^1.4.2",
"mime": "^2.4.4"
"mime": "^2.4.6"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-homer0": "^3.0.3",
"jest-ex": "^8.0.1",
"jest-cli": "^25.3.0",
"eslint": "^7.3.1",
"eslint-plugin-homer0": "^4.0.0",
"jest-ex": "^9.0.0",
"jest-cli": "^26.1.0",
"jasmine-expect": "^4.0.3",

@@ -34,4 +34,5 @@ "esdoc": "^1.1.0",

"esdoc-node": "1.0.4",
"leasot": "^10.2.0",
"coveralls": "^3.0.11",
"leasot": "^11.0.0",
"lint-staged": "^10.2.11",
"coveralls": "^3.1.0",
"husky": "^4.2.5"

@@ -50,2 +51,5 @@ },

},
"lint-staged": {
"*.js": "eslint"
},
"scripts": {

@@ -52,0 +56,0 @@ "hooks": "./utils/hooks/install",

@@ -7,2 +7,3 @@ const Jimple = require('jimple');

const multer = require('multer');
const statuses = require('statuses');

@@ -407,2 +408,7 @@ const {

this.set('events', () => new EventsHub());
/**
* This package is heavily used when implementing a Jimpex app, so it makes sense to register
* it on the container, so the implementations won't need to manually install it.
*/
this.set('statuses', () => statuses);
}

@@ -409,0 +415,0 @@ /**

@@ -1,2 +0,2 @@

const statuses = require('statuses');
const { code: statuses } = require('statuses');
const { controller } = require('../../utils/wrappers');

@@ -3,0 +3,0 @@ /**

const ObjectUtils = require('wootils/shared/objectUtils');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const { middlewareCreator } = require('../../utils/wrappers');

@@ -117,3 +117,3 @@

// Try to obtain the response status from the error
status = err.status || statuses['Bad Request'];
status = err.status || statuses['bad request'];
}

@@ -120,0 +120,0 @@ // If the `showErrors` flag is enabled...

const ObjectUtils = require('wootils/shared/objectUtils');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const { middlewareCreator } = require('../../utils/wrappers');

@@ -4,0 +4,0 @@

@@ -0,1 +1,2 @@

const { code: statuses } = require('statuses');
const { provider } = require('../../utils/wrappers');

@@ -23,3 +24,3 @@ /**

*/
this._context = Object.freeze(context);
this._context = Object.freeze(this._parseContext(context));
/**

@@ -69,2 +70,19 @@ * The date of when the error was generated.

}
/**
* Utility method that formats the context before saving it in the instance:
* - If the context includes a `status` as a `string`, it will try to replace it with its status
* code from the `statuses` package.
* @param {Object} original The original context to format.
* @return {Object}
* @access protected
* @ignore
*/
_parseContext(original) {
const result = Object.assign({}, original);
if (typeof result.status === 'string') {
result.status = statuses[result.status.toLowerCase()] || result.status;
}
return result;
}
}

@@ -71,0 +89,0 @@ /**

@@ -1,2 +0,2 @@

const statuses = require('statuses');
const { code: statuses } = require('statuses');
const ObjectUtils = require('wootils/shared/objectUtils');

@@ -3,0 +3,0 @@ const { provider } = require('../../utils/wrappers');

@@ -1,2 +0,2 @@

const statuses = require('statuses');
const { code: statuses } = require('statuses');
const { provider } = require('../../utils/wrappers');

@@ -43,18 +43,15 @@ /**

* ```
* @param {ExpressResponse} res The Express response object necessary to write
* the JSON.
* @param {Object} data The information for the `data` key.
* @param {number} [status=statuses.ok] The HTTP status. Jimpex uses the `statuses`
* package to reference HTTP statuses, that's why
* the default is `statuses.ok`(200).
* @param {Object} [metadata={}] Extra information to include on the `metadata`
* key.
* @param {ExpressResponse} res The Express response object necessary to write the JSON.
* @param {Object} data The information for the `data` key.
* @param {number} [status=200] The HTTP status.
* @param {Object} [metadata={}] Extra information to include on the `metadata` key.
*/
json(res, data, status = statuses.ok, metadata = {}) {
const useStatus = this._normalizeStatus(status);
res
.status(status)
.status(useStatus)
.json({
metadata: Object.assign({
version: this._appConfiguration.get('version'),
status,
status: useStatus,
}, metadata),

@@ -69,14 +66,8 @@ data,

* `postMessagesPrefix`.
* @param {ExpressResponse} res The Express response object
* necessary to write the HTML.
* @param {string} title The title for the HTML.
* @param {string} message The contents of the post
* message.
* @param {number} [status=statuses.ok] The HTTP status. Jimpex uses
* the `statuses` package to
* reference HTTP statuses,
* that's why the default is
* `statuses.ok`(200). Custom
* options for the HTML.
* @param {ResponsesBuilderPostMessageOptions} [options={}] Options to customize the HTML.
* @param {ExpressResponse} res The Express response object
* necessary to write the HTML.
* @param {string} title The title for the HTML.
* @param {string} message The contents of the post message.
* @param {number} [status=200] The HTTP status.
* @param {ResponsesBuilderPostMessageOptions} [options={}] Options to customize the HTML.
*/

@@ -109,3 +100,3 @@ htmlPostMessage(

res.setHeader('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');
res.status(status);
res.status(this._normalizeStatus(status));
res.write(html);

@@ -140,2 +131,22 @@ res.end();

}
/**
* Utility method used to make sure a recevied status is a valid status code. If the status
* is a string, the method will try to find the code from the `statuses` package.
* @param {string|number} status The status to normalize.
* @return {string|number} If `status` is a string, but there's no valid code, it will return it
* as it was received.
* @access protected
* @ignore
* @todo On the next breaking version, if there's no valid code, it will be transformed to `200`.
*/
_normalizeStatus(status) {
let result;
if (typeof status === 'string') {
result = statuses[status] || status;
} else {
result = status;
}
return result;
}
}

@@ -142,0 +153,0 @@ /**

@@ -1,2 +0,2 @@

const statuses = require('statuses');
const { code: statuses } = require('statuses');
const ObjectUtils = require('wootils/shared/objectUtils');

@@ -3,0 +3,0 @@ const { providerCreator } = require('../../utils/wrappers');

@@ -21,2 +21,3 @@ const JimpleMock = require('/tests/mocks/jimple.mock');

const path = require('path');
const statuses = require('statuses');
require('jasmine-expect');

@@ -72,2 +73,3 @@

let eventsService = null;
let statusesService = null;
const expectedServices = [

@@ -87,2 +89,3 @@ 'appLogger',

'events',
'statuses',
];

@@ -134,4 +137,5 @@ const expectedStaticsFolder = 'app/statics';

expect(sut.set).toHaveBeenCalledWith('events', expect.any(Function));
[, [, eventsService]] = sut.set.mock.calls;
[, [, eventsService], [, statusesService]] = sut.set.mock.calls;
expect(eventsService()).toBeInstanceOf(EventsHub);
expect(statusesService()).toEqual(statuses);
expect(wootilsMock.appConfiguration).toHaveBeenCalledTimes(1);

@@ -138,0 +142,0 @@ expect(wootilsMock.appConfiguration).toHaveBeenCalledWith(

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/wrappers');

require('jasmine-expect');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const {

@@ -8,0 +8,0 @@ HealthController,

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/functions');

const statuses = require('statuses');
const { code: statuses } = require('statuses');
require('jasmine-expect');

@@ -8,0 +8,0 @@ const {

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/wrappers');

require('jasmine-expect');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const {

@@ -73,3 +73,3 @@ ErrorHandler,

};
const expectedStatus = statuses['Bad Request'];
const expectedStatus = statuses['bad request'];
// When

@@ -113,3 +113,3 @@ sut = new ErrorHandler(appLogger, responsesBuilder, showErrors, AppError);

};
const expectedStatus = statuses['Internal Server Error'];
const expectedStatus = statuses['internal server error'];
// When

@@ -155,3 +155,3 @@ sut = new ErrorHandler(appLogger, responsesBuilder, showErrors, AppError, options);

};
const expectedStatus = statuses['Internal Server Error'];
const expectedStatus = statuses['internal server error'];
// When

@@ -158,0 +158,0 @@ sut = new ErrorHandler(appLogger, responsesBuilder, showErrors, AppError);

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/wrappers');

require('jasmine-expect');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const {

@@ -8,0 +8,0 @@ VersionValidator,

jest.unmock('/src/utils/wrappers');
jest.unmock('/src/services/common/appError');
const { code: statuses } = require('statuses');
require('jasmine-expect');

@@ -52,2 +53,31 @@ const {

it('should format a status code sent as string', () => {
// Given
const message = 'Something went wrong!';
const context = {
status: 'internal server error',
};
let sut = null;
// When
sut = new AppError(message, context);
// Then
expect(sut).toBeInstanceOf(AppError);
expect(sut.status).toBeNumber();
expect(sut.status).toBe(statuses[context.status]);
});
it('shouldn\'t format a status code sent as string if is not a valid status', () => {
// Given
const message = 'Something went wrong!';
const context = {
status: 'wooo',
};
let sut = null;
// When
sut = new AppError(message, context);
// Then
expect(sut).toBeInstanceOf(AppError);
expect(sut.status).toBe(context.status);
});
it('should use `captureStackTrace` when avaiable', () => {

@@ -54,0 +84,0 @@ // Given

@@ -1,2 +0,2 @@

const statuses = require('statuses');
const { code: statuses } = require('statuses');

@@ -3,0 +3,0 @@ jest.unmock('/src/utils/wrappers');

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/wrappers');

require('jasmine-expect');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const {

@@ -56,2 +56,70 @@ ResponsesBuilder,

it('should normalize a status sent as string', () => {
// Given
const version = 'latest';
const appConfiguration = {
get: jest.fn(() => version),
};
const response = {
status: jest.fn(() => response),
json: jest.fn(() => response),
end: jest.fn(() => response),
};
const data = {
dataProp: 'dataValue',
};
const status = 'bad request';
let sut = null;
const expectedResponse = {
metadata: {
version,
status: statuses[status],
},
data,
};
// When
sut = new ResponsesBuilder(appConfiguration);
sut.json(response, data, status);
// Then
expect(response.status).toHaveBeenCalledTimes(1);
expect(response.status).toHaveBeenCalledWith(statuses[status]);
expect(response.json).toHaveBeenCalledTimes(1);
expect(response.json).toHaveBeenCalledWith(expectedResponse);
expect(response.end).toHaveBeenCalledTimes(1);
});
it('shouldn\'t normalize an invalid string status', () => {
// Given
const version = 'latest';
const appConfiguration = {
get: jest.fn(() => version),
};
const response = {
status: jest.fn(() => response),
json: jest.fn(() => response),
end: jest.fn(() => response),
};
const data = {
dataProp: 'dataValue',
};
const status = 'woo';
let sut = null;
const expectedResponse = {
metadata: {
version,
status,
},
data,
};
// When
sut = new ResponsesBuilder(appConfiguration);
sut.json(response, data, status);
// Then
expect(response.status).toHaveBeenCalledTimes(1);
expect(response.status).toHaveBeenCalledWith(status);
expect(response.json).toHaveBeenCalledTimes(1);
expect(response.json).toHaveBeenCalledWith(expectedResponse);
expect(response.end).toHaveBeenCalledTimes(1);
});
it('should generate and send a JSON response with custom status and metadata', () => {

@@ -58,0 +126,0 @@ // Given

@@ -5,3 +5,3 @@ jest.unmock('/src/utils/wrappers');

require('jasmine-expect');
const statuses = require('statuses');
const { code: statuses } = require('statuses');
const {

@@ -8,0 +8,0 @@ EnsureBearerToken,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc