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

@remult/server

Package Overview
Dependencies
Maintainers
2
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remult/server - npm Package Compare versions

Comparing version 2.2.2 to 2.2.4

16

expressBridge.d.ts

@@ -1,12 +0,10 @@

import { DataApi, DataApiResponse, DataApiRequest, DataApiServer, UserInfo, DataProvider, DataProviderFactoryBuilder, ServerContext, queuedJobInfoResponse, IdEntity, StringColumn, BoolColumn, DateTimeColumn, NumberColumn, SpecificEntityHelper } from '@remult/core';
import { DataApi, DataApiResponse, DataApiRequest, UserInfo, DataProvider, DataProviderFactoryBuilder, ServerContext, queuedJobInfoResponse, IdEntity, StringColumn, BoolColumn, DateTimeColumn, NumberColumn, SpecificEntityHelper } from '@remult/core';
import * as express from 'express';
export declare function initExpress(app: express.Express, dataProvider: DataProvider | DataProviderFactoryBuilder, disableHttpsForDevOnly_or_args?: boolean | {
disableHttpsForDevOnly?: boolean;
limit?: string;
export declare function initExpress(app: express.Express, dataProvider: DataProvider | DataProviderFactoryBuilder, options: {
bodySizeLimit?: string;
disableAutoApi?: boolean;
queueStorage?: QueueStorage;
jwtTokenSignKey?: string;
jwtTokenExpiresIn?: number;
tokenProvider?: TokenProvider;
}): ExpressBridge;
export declare class ExpressBridge implements DataApiServer {
export declare class ExpressBridge {
private app;

@@ -91,2 +89,6 @@ queue: inProcessQueueHandler;

}
export interface TokenProvider {
createToken(info: UserInfo): string;
verifyToken(token: string): UserInfo | any;
}
export {};

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

var bodyParser = require("body-parser");
var compression = require("compression");
// @ts-ignore:
var secure = require("express-force-https");
var register_actions_on_server_1 = require("./register-actions-on-server");

@@ -14,24 +11,15 @@ var register_entities_on_server_1 = require("./register-entities-on-server");

var core_2 = require("@remult/core");
var jwt_cookie_authoerization_helper_1 = require("./jwt-cookie-authoerization-helper");
function initExpress(app, dataProvider, disableHttpsForDevOnly_or_args) {
if (util_1.isBoolean(disableHttpsForDevOnly_or_args)) {
disableHttpsForDevOnly_or_args = {
disableHttpsForDevOnly: disableHttpsForDevOnly_or_args
};
function initExpress(app, dataProvider, options) {
var _this = this;
if (!options) {
options = {};
}
else if (disableHttpsForDevOnly_or_args === undefined) {
disableHttpsForDevOnly_or_args = {};
if (options.bodySizeLimit === undefined) {
options.bodySizeLimit = '10mb';
}
if (disableHttpsForDevOnly_or_args.limit === undefined) {
disableHttpsForDevOnly_or_args.limit = '10mb';
if (!options.queueStorage) {
options.queueStorage = new InMemoryQueueStorage();
}
if (!disableHttpsForDevOnly_or_args.queueStorage) {
disableHttpsForDevOnly_or_args.queueStorage = new InMemoryQueueStorage();
}
app.use(compression());
if (!disableHttpsForDevOnly_or_args.disableHttpsForDevOnly) {
app.use(secure);
}
app.use(bodyParser.json({ limit: disableHttpsForDevOnly_or_args.limit }));
app.use(bodyParser.urlencoded({ extended: true, limit: disableHttpsForDevOnly_or_args.limit }));
app.use(bodyParser.json({ limit: options.bodySizeLimit }));
app.use(bodyParser.urlencoded({ extended: true, limit: options.bodySizeLimit }));
var builder;

@@ -42,5 +30,5 @@ if (util_1.isFunction(dataProvider))

builder = function () { return dataProvider; };
var result = new ExpressBridge(app, new inProcessQueueHandler(disableHttpsForDevOnly_or_args.queueStorage));
var result = new ExpressBridge(app, new inProcessQueueHandler(options.queueStorage));
var apiArea = result.addArea('/' + core_1.Context.apiBaseUrl);
if (!disableHttpsForDevOnly_or_args.disableAutoApi) {
if (!options.disableAutoApi) {
apiArea.setDataProviderFactory(builder);

@@ -50,13 +38,31 @@ register_actions_on_server_1.registerActionsOnServer(apiArea, builder);

}
if (!disableHttpsForDevOnly_or_args.jwtTokenSignKey) {
disableHttpsForDevOnly_or_args.jwtTokenSignKey = process.env.TOKEN_SIGN_KEY;
if (options.tokenProvider) {
var x_1 = new JWTCookieAuthorizationHelper(options.tokenProvider);
result.addRequestProcessor(function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var token, _a, h, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
token = req.getHeader(x_1.authCookieName);
if (token && token.startsWith('Bearer '))
token = token.substring(7);
if (!token) return [3 /*break*/, 2];
_a = req;
return [4 /*yield*/, x_1.validateToken(token)];
case 1:
_a.user = _c.sent();
return [3 /*break*/, 4];
case 2:
h = req.getHeader('cookie');
_b = req;
return [4 /*yield*/, x_1.authenticateCookie(h)];
case 3:
_b.user = _c.sent();
_c.label = 4;
case 4: return [2 /*return*/, !!req.user];
}
});
}); });
core_2.JwtSessionService.createTokenOnServer = function (user) { return x_1.createSecuredTokenBasedOn(user); };
}
if (disableHttpsForDevOnly_or_args.jwtTokenSignKey) {
var a_1 = new jwt_cookie_authoerization_helper_1.JWTCookieAuthorizationHelper(result, disableHttpsForDevOnly_or_args.jwtTokenSignKey);
var options_1 = undefined;
if (disableHttpsForDevOnly_or_args.jwtTokenExpiresIn) {
options_1 = { expiresIn: disableHttpsForDevOnly_or_args.jwtTokenExpiresIn };
}
core_2.JwtSessionService.createTokenOnServer = function (user) { return a_1.createSecuredTokenBasedOn(user, options_1); };
}
return result;

@@ -545,2 +551,66 @@ }

exports.JobsInQueueEntity = JobsInQueueEntity;
var JWTCookieAuthorizationHelper = /** @class */ (function () {
function JWTCookieAuthorizationHelper(provider, authCookieName) {
var _this = this;
this.provider = provider;
this.authCookieName = authCookieName;
this.validateToken = function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var result;
return tslib_1.__generator(this, function (_a) {
try {
result = this.provider.verifyToken(x);
}
catch (err) { }
return [2 /*return*/, result];
});
}); };
if (!authCookieName) {
this.authCookieName = 'authorization';
}
}
JWTCookieAuthorizationHelper.prototype.authenticateCookie = function (cookieHeader) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var e_1, _a, _b, _c, iterator, itemInfo, e_1_1;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!cookieHeader) return [3 /*break*/, 9];
_d.label = 1;
case 1:
_d.trys.push([1, 6, 7, 8]);
_b = tslib_1.__values(cookieHeader.split(';')), _c = _b.next();
_d.label = 2;
case 2:
if (!!_c.done) return [3 /*break*/, 5];
iterator = _c.value;
itemInfo = iterator.split('=');
if (!(itemInfo && itemInfo[0].trim() == this.authCookieName)) return [3 /*break*/, 4];
if (!this.validateToken) return [3 /*break*/, 4];
return [4 /*yield*/, this.validateToken(itemInfo[1])];
case 3: return [2 /*return*/, _d.sent()];
case 4:
_c = _b.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8: return [2 /*return*/, undefined];
case 9: return [2 /*return*/];
}
});
});
};
JWTCookieAuthorizationHelper.prototype.createSecuredTokenBasedOn = function (what) {
return this.provider.createToken(what);
};
return JWTCookieAuthorizationHelper;
}());
//# sourceMappingURL=expressBridge.js.map
export * from './JsonEntityFileStorage';
export * from './expressBridge';
export * from './register-entities-on-server';
export * from './jwt-cookie-authoerization-helper';
export * from './register-actions-on-server';

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

tslib_1.__exportStar(require("./register-entities-on-server"), exports);
tslib_1.__exportStar(require("./jwt-cookie-authoerization-helper"), exports);
tslib_1.__exportStar(require("./register-actions-on-server"), exports);
//# sourceMappingURL=index.js.map

@@ -1,95 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var jwt = require("jsonwebtoken");
var JWTCookieAuthorizationHelper = /** @class */ (function () {
function JWTCookieAuthorizationHelper(server, tokenSignKey, authCookieName) {
var _this = this;
this.tokenSignKey = tokenSignKey;
this.authCookieName = authCookieName;
this.validateToken = function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var result;
return tslib_1.__generator(this, function (_a) {
try {
result = jwt.verify(x, this.tokenSignKey);
}
catch (err) { }
return [2 /*return*/, result];
});
}); };
if (!authCookieName) {
this.authCookieName = 'authorization';
}
server.addRequestProcessor(function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var token, _a, h, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
token = req.getHeader(this.authCookieName);
if (token && token.startsWith('Bearer '))
token = token.substring(7);
if (!token) return [3 /*break*/, 2];
_a = req;
return [4 /*yield*/, this.validateToken(token)];
case 1:
_a.user = _c.sent();
return [3 /*break*/, 4];
case 2:
h = req.getHeader('cookie');
_b = req;
return [4 /*yield*/, this.authenticateCookie(h)];
case 3:
_b.user = _c.sent();
_c.label = 4;
case 4: return [2 /*return*/, !!req.user];
}
});
}); });
}
JWTCookieAuthorizationHelper.prototype.authenticateCookie = function (cookieHeader) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var e_1, _a, _b, _c, iterator, itemInfo, e_1_1;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!cookieHeader) return [3 /*break*/, 9];
_d.label = 1;
case 1:
_d.trys.push([1, 6, 7, 8]);
_b = tslib_1.__values(cookieHeader.split(';')), _c = _b.next();
_d.label = 2;
case 2:
if (!!_c.done) return [3 /*break*/, 5];
iterator = _c.value;
itemInfo = iterator.split('=');
if (!(itemInfo && itemInfo[0].trim() == this.authCookieName)) return [3 /*break*/, 4];
if (!this.validateToken) return [3 /*break*/, 4];
return [4 /*yield*/, this.validateToken(itemInfo[1])];
case 3: return [2 /*return*/, _d.sent()];
case 4:
_c = _b.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8: return [2 /*return*/, undefined];
case 9: return [2 /*return*/];
}
});
});
};
JWTCookieAuthorizationHelper.prototype.createSecuredTokenBasedOn = function (what, options) {
return jwt.sign(what, this.tokenSignKey, options);
};
return JWTCookieAuthorizationHelper;
}());
exports.JWTCookieAuthorizationHelper = JWTCookieAuthorizationHelper;
//# sourceMappingURL=jwt-cookie-authoerization-helper.js.map
{
"name": "@remult/server",
"version": "2.2.2",
"version": "2.2.4",
"main": "index.js",

@@ -5,0 +5,0 @@ "Dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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