New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-boot-http-server

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-boot-http-server - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

endpoints/HeaderEndPoint.d.ts

10

endpoints/CrossDomainHeaderEndPoint.d.ts

@@ -5,11 +5,11 @@ import { EndPoint } from './EndPoint';

export declare type CrossDomainHeaderEndPointConfig = {
accessControlAllowOrigin: string | string[];
accessControlAllowMethods: string | string[];
accessControlAllowHeaders: string | string[];
accessControlAllowOrigin?: string | string[];
accessControlAllowMethods?: string | string[];
accessControlAllowHeaders?: string | string[];
};
export declare class CrossDomainHeaderEndPoint implements EndPoint {
private config;
constructor(config: CrossDomainHeaderEndPointConfig);
private config?;
constructor(config?: CrossDomainHeaderEndPointConfig | undefined);
endPoint(rr: RequestResponse, app: SimpleBootHttpServer): Promise<void>;
onInit(app: SimpleBootHttpServer): Promise<void>;
}

@@ -46,11 +46,12 @@ "use strict";

CrossDomainHeaderEndPoint.prototype.endPoint = function (rr, app) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (this.config.accessControlAllowOrigin) {
return __generator(this, function (_d) {
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.accessControlAllowOrigin) {
rr.resSetHeader(HttpHeaders_1.HttpHeaders.AccessControlAllowOrigin, Array.isArray(this.config.accessControlAllowOrigin) ? this.config.accessControlAllowOrigin.join(', ') : this.config.accessControlAllowOrigin);
}
if (this.config.accessControlAllowMethods) {
if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.accessControlAllowMethods) {
rr.resSetHeader(HttpHeaders_1.HttpHeaders.AccessControlAllowMethods, Array.isArray(this.config.accessControlAllowMethods) ? this.config.accessControlAllowMethods.join(', ') : this.config.accessControlAllowMethods);
}
if (this.config.accessControlAllowHeaders) {
if ((_c = this.config) === null || _c === void 0 ? void 0 : _c.accessControlAllowHeaders) {
rr.resSetHeader(HttpHeaders_1.HttpHeaders.AccessControlAllowHeaders, Array.isArray(this.config.accessControlAllowHeaders) ? this.config.accessControlAllowHeaders.join(', ') : this.config.accessControlAllowHeaders);

@@ -57,0 +58,0 @@ }

@@ -14,9 +14,12 @@ /// <reference types="node" />

import { HttpStatus } from '../codes/HttpStatus';
import { SessionManager } from '../session/SessionManager';
export declare class RequestResponse {
protected req: IncomingMessage;
protected res: ServerResponse;
private sessionManager;
protected resWriteChunk: any;
protected reqBodyChunk?: Buffer;
protected req: IncomingMessage;
protected res: ServerResponse;
constructor(req: IncomingMessage, res: ServerResponse);
constructor(req: RequestResponse);
constructor(req: IncomingMessage, res: ServerResponse, sessionManager: SessionManager);
get reqCookieMap(): Map<string, string>;
reqCookieGet(key: string): string | undefined;
get reqRemoteAddress(): string | undefined;

@@ -48,3 +51,3 @@ get reqUrl(): string;

reqMethod(): string | undefined;
reqHeader(key: HttpHeaders | string, defaultValue?: string): string | string[] | undefined;
reqHeader(key: HttpHeaders | string): string | string[] | undefined;
get reqHeaderObj(): ReqHeader;

@@ -57,5 +60,5 @@ reqHeaderFirst(key: HttpHeaders | string, defaultValue?: string): string | undefined;

resHeaderFirst(key: HttpHeaders | string, defaultValue?: string): string | number | undefined;
reqSession(): {
reqSession(): Promise<{
[key: string]: any;
};
}>;
reqSessionSet(key: string, value: any): void;

@@ -80,3 +83,3 @@ reqSessionGet<T = any>(key: string): T | undefined;

result?: T | undefined;
constructor(req: IncomingMessage, res: ServerResponse, result?: T | undefined);
constructor(req: IncomingMessage, res: ServerResponse, sessionManager: SessionManager, result?: T | undefined);
}

@@ -67,12 +67,26 @@ "use strict";

var RequestResponse = (function () {
function RequestResponse(req, res) {
if (req instanceof RequestResponse) {
this.req = req.req;
this.res = req.res;
}
else {
this.req = req;
this.res = res;
}
function RequestResponse(req, res, sessionManager) {
this.req = req;
this.res = res;
this.sessionManager = sessionManager;
}
Object.defineProperty(RequestResponse.prototype, "reqCookieMap", {
get: function () {
var _a;
var cookies = (_a = this.reqHeader(HttpHeaders_1.HttpHeaders.Cookie)) !== null && _a !== void 0 ? _a : '';
if (Array.isArray(cookies)) {
cookies = cookies.join(';');
}
var map = new Map();
cookies.split(';').map(function (it) { return it.trim().split('='); }).forEach(function (it) {
map.set(it[0], it[1]);
});
return map;
},
enumerable: false,
configurable: true
});
RequestResponse.prototype.reqCookieGet = function (key) {
return this.reqCookieMap.get(key);
};
Object.defineProperty(RequestResponse.prototype, "reqRemoteAddress", {

@@ -183,3 +197,3 @@ get: function () {

var data = '';
_this.req.on('data', function (chunk) { return data += chunk; });
_this.req.on('data', function (chunk) { data += chunk; });
_this.req.on('error', function (err) { return reject(err); });

@@ -326,5 +340,4 @@ _this.req.on('end', function () {

};
RequestResponse.prototype.reqHeader = function (key, defaultValue) {
var _a;
return (_a = this.req.headers[key.toLowerCase()]) !== null && _a !== void 0 ? _a : defaultValue;
RequestResponse.prototype.reqHeader = function (key) {
return this.req.headers[key.toLowerCase()];
};

@@ -362,3 +375,3 @@ Object.defineProperty(RequestResponse.prototype, "reqHeaderObj", {

this.res.statusCode = code;
return new RequestResponseChain(this.req, this.res, this.res.statusCode);
return new RequestResponseChain(this.req, this.res, this.sessionManager, this.res.statusCode);
}

@@ -380,6 +393,10 @@ else {

RequestResponse.prototype.reqSession = function () {
if (this.req.simpleboot_session === undefined) {
this.req.simpleboot_session = {};
}
return this.req.simpleboot_session;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.sessionManager.session(this)];
case 1: return [2, (_a.sent()).dataSet.data];
}
});
});
};

@@ -470,3 +487,3 @@ RequestResponse.prototype.reqSessionSet = function (key, value) {

RequestResponse.prototype.createRequestResponseChain = function (data) {
var requestResponseChain = new RequestResponseChain(this.req, this.res, data);
var requestResponseChain = new RequestResponseChain(this.req, this.res, this.sessionManager, data);
requestResponseChain.resWriteChunk = this.resWriteChunk;

@@ -481,4 +498,4 @@ requestResponseChain.reqBodyChunk = this.reqBodyChunk;

__extends(RequestResponseChain, _super);
function RequestResponseChain(req, res, result) {
var _this = _super.call(this, req, res) || this;
function RequestResponseChain(req, res, sessionManager, result) {
var _this = _super.call(this, req, res, sessionManager) || this;
_this.result = result;

@@ -485,0 +502,0 @@ return _this;

@@ -28,5 +28,21 @@ /// <reference types="node" />

errorEndPoints?: (EndPoint | ConstructorType<EndPoint>)[];
sessionOption: {
key: string;
expiredTime: number;
provider?: {
uuids: () => Promise<string[]>;
delete: (uuid: string) => Promise<void>;
get: (uuid: string) => Promise<{
access: number;
data?: any;
}>;
set: (uuid: string, data: {
access: number;
data?: any;
}) => Promise<void>;
};
};
globalAdvice?: any | ConstructorType<any>;
noSuchRouteEndPointMappingThrow?: (rr: RequestResponse) => any;
constructor({ serverOption, listen, filters, requestEndPoints, closeEndPoints, errorEndPoints, globalAdvice, noSuchRouteEndPointMappingThrow }?: {
constructor({ serverOption, listen, filters, requestEndPoints, closeEndPoints, errorEndPoints, sessionOption, globalAdvice, noSuchRouteEndPointMappingThrow }?: {
serverOption?: ServerOptions;

@@ -38,2 +54,18 @@ listen?: Listen;

errorEndPoints?: (EndPoint | ConstructorType<EndPoint>)[];
sessionOption?: {
key?: string;
expiredTime?: number;
provider?: {
uuids: () => Promise<string[]>;
delete: (uuid: string) => Promise<void>;
get: (uuid: string) => Promise<{
access: number;
data?: any;
}>;
set: (uuid: string, data: {
access: number;
data?: any;
}) => Promise<void>;
};
};
globalAdvice?: any | ConstructorType<any>;

@@ -40,0 +72,0 @@ noSuchRouteEndPointMappingThrow?: (rr: RequestResponse) => any;

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

function HttpServerOption(_a, advice) {
var _b = _a === void 0 ? {} : _a, serverOption = _b.serverOption, listen = _b.listen, filters = _b.filters, requestEndPoints = _b.requestEndPoints, closeEndPoints = _b.closeEndPoints, errorEndPoints = _b.errorEndPoints, globalAdvice = _b.globalAdvice, noSuchRouteEndPointMappingThrow = _b.noSuchRouteEndPointMappingThrow;
var _b = _a === void 0 ? {} : _a, serverOption = _b.serverOption, listen = _b.listen, filters = _b.filters, requestEndPoints = _b.requestEndPoints, closeEndPoints = _b.closeEndPoints, errorEndPoints = _b.errorEndPoints, sessionOption = _b.sessionOption, globalAdvice = _b.globalAdvice, noSuchRouteEndPointMappingThrow = _b.noSuchRouteEndPointMappingThrow;
if (advice === void 0) { advice = []; }

@@ -33,2 +33,3 @@ var _this = _super.call(this, advice) || this;

_this.errorEndPoints = errorEndPoints;
_this.sessionOption = Object.assign({ key: 'SBSESSIONID', expiredTime: 1000 * 60 * 30 }, sessionOption);
_this.globalAdvice = globalAdvice;

@@ -35,0 +36,0 @@ _this.noSuchRouteEndPointMappingThrow = noSuchRouteEndPointMappingThrow;

{
"name": "simple-boot-http-server",
"version": "1.0.11",
"version": "1.0.12",
"main": "SimpleBootHttpServer.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -10,2 +10,3 @@ /// <reference types="node" />

server?: Server;
private sessionManager;
constructor(rootRouter: ConstructorType<Object>, option?: HttpServerOption);

@@ -12,0 +13,0 @@ run(otherInstanceSim?: Map<ConstructorType<any>, any>): import("simple-boot-core/simstance/SimstanceManager").SimstanceManager;

@@ -86,2 +86,3 @@ "use strict";

var HttpMethod_1 = require("./codes/HttpMethod");
var SessionManager_1 = require("./session/SessionManager");
var SimpleBootHttpServer = (function (_super) {

@@ -94,2 +95,3 @@ __extends(SimpleBootHttpServer, _super);

_this.option = option;
_this.sessionManager = new SessionManager_1.SessionManager(_this.option);
return _this;

@@ -112,3 +114,3 @@ }

server.on('request', function (req, res) { return __awaiter(_this, void 0, void 0, function () {
var rr, otherStorage, _i, _a, it_1, execute, filter, i, it_2, execute, sw, routerModule, moduleInstance_1, methods, map, it_3, paramTypes, injects, validIndexs, isJson, isFormUrl, siturationContainers, data_1, inValid, data_2, inValid, _b, paramTypes_1, paramType, _c, _d, _e, _f, _g, _h, data, execute, status, headers, _j, _k, it_4, _l, e_1, execute, target;
var rr, cookie, session, otherStorage, _i, _a, it_1, execute, filter, i, it_2, execute, sw, routerModule, moduleInstance_1, methods, map, it_3, paramTypes, injects, validIndexs, isJson, isFormUrl, siturationContainers, data_1, inValid, data_2, inValid, _b, paramTypes_1, paramType, _c, _d, _e, _f, _g, _h, data, execute, status, headers, _j, _k, it_4, _l, e_1, execute, target;
var _this = this;

@@ -191,4 +193,12 @@ var _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;

}); });
rr = new RequestResponse_1.RequestResponse(req, res);
rr = new RequestResponse_1.RequestResponse(req, res, this.sessionManager);
rr.resSetHeader(HttpHeaders_1.HttpHeaders.Server, 'simple-boot-http-server');
cookie = rr.reqCookieGet(this.option.sessionOption.key);
if (!!cookie) return [3, 2];
return [4, this.sessionManager.session()];
case 1:
session = _11.sent();
rr.resSetHeader(HttpHeaders_1.HttpHeaders.SetCookie, "".concat(this.option.sessionOption.key, "=").concat(session.uuid, "; Path=/; HttpOnly"));
_11.label = 2;
case 2:
otherStorage = new Map();

@@ -198,5 +208,5 @@ otherStorage.set(RequestResponse_1.RequestResponse, rr);

otherStorage.set(http_1.ServerResponse, res);
_11.label = 1;
case 1:
_11.trys.push([1, 30, , 33]);
_11.label = 3;
case 3:
_11.trys.push([3, 32, , 35]);
if (this.option.requestEndPoints) {

@@ -215,26 +225,26 @@ for (_i = 0, _a = this.option.requestEndPoints; _i < _a.length; _i++) {

i = 0;
_11.label = 2;
case 2:
if (!(this.option.filters && i < this.option.filters.length)) return [3, 6];
_11.label = 4;
case 4:
if (!(this.option.filters && i < this.option.filters.length)) return [3, 8];
it_2 = this.option.filters[i];
execute = (typeof it_2 === 'function' ? this.simstanceManager.getOrNewSim(it_2) : it_2);
sw = true;
if (!(execute === null || execute === void 0 ? void 0 : execute.before)) return [3, 4];
if (!(execute === null || execute === void 0 ? void 0 : execute.before)) return [3, 6];
return [4, execute.before(rr, this)];
case 3:
case 5:
sw = _11.sent();
filter.push({ filter: execute, sw: sw });
_11.label = 4;
case 4:
_11.label = 6;
case 6:
if (!sw) {
return [3, 6];
return [3, 8];
}
_11.label = 5;
case 5:
_11.label = 7;
case 7:
i++;
return [3, 2];
case 6:
if (!!rr.resIsDone()) return [3, 24];
return [3, 4];
case 8:
if (!!rr.resIsDone()) return [3, 26];
return [4, _super.prototype.routing.call(this, rr.reqIntent)];
case 7:
case 9:
routerModule = _11.sent();

@@ -244,3 +254,3 @@ otherStorage.set(RouterModule_1.RouterModule, routerModule);

methods = [];
if (!(routerModule && moduleInstance_1)) return [3, 23];
if (!(routerModule && moduleInstance_1)) return [3, 25];
if (routerModule.propertyKeys) {

@@ -267,3 +277,3 @@ map = (_o = routerModule.propertyKeys) === null || _o === void 0 ? void 0 : _o.map(function (it) {

.filter(function (it) { var _a, _b, _c, _d, _e; return ((_b = (_a = it.config) === null || _a === void 0 ? void 0 : _a.req) === null || _b === void 0 ? void 0 : _b.accept) ? (!!((_e = (_d = (_c = it.config) === null || _c === void 0 ? void 0 : _c.req) === null || _d === void 0 ? void 0 : _d.accept) === null || _e === void 0 ? void 0 : _e.find(function (sit) { return rr.reqHasAcceptHeader(sit); }))) : true; });
if (!methods[0]) return [3, 23];
if (!methods[0]) return [3, 25];
it_3 = methods[0];

@@ -273,9 +283,9 @@ paramTypes = ReflectUtils_1.ReflectUtils.getParameterTypes(moduleInstance_1, it_3.propertyKey);

validIndexs = (0, Validation_1.getValidIndex)(moduleInstance_1, it_3.propertyKey);
if (!injects) return [3, 12];
if (!injects) return [3, 14];
isJson = injects.find(function (it) { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.situationType) === MethodMapping_1.UrlMappingSituationType.REQ_JSON_BODY; });
isFormUrl = injects.find(function (it) { var _a; return ((_a = it.config) === null || _a === void 0 ? void 0 : _a.situationType) === MethodMapping_1.UrlMappingSituationType.REQ_FORM_URL_BODY; });
siturationContainers = new Inject_1.SituationTypeContainers();
if (!isJson) return [3, 9];
if (!isJson) return [3, 11];
return [4, rr.reqBodyJsonData()];
case 8:
case 10:
data_1 = _11.sent();

@@ -295,7 +305,7 @@ if (isJson.type) {

}));
_11.label = 9;
case 9:
if (!isFormUrl) return [3, 11];
_11.label = 11;
case 11:
if (!isFormUrl) return [3, 13];
return [4, rr.reqBodyFormUrlData()];
case 10:
case 12:
data_2 = _11.sent();

@@ -312,30 +322,30 @@ if (isFormUrl.type) {

siturationContainers.push(new Inject_1.SituationTypeContainer({ situationType: MethodMapping_1.UrlMappingSituationType.REQ_FORM_URL_BODY, data: data_2 }));
_11.label = 11;
case 11:
_11.label = 13;
case 13:
if (siturationContainers.length) {
otherStorage.set(Inject_1.SituationTypeContainers, siturationContainers);
}
_11.label = 12;
case 12:
_11.label = 14;
case 14:
_b = 0, paramTypes_1 = paramTypes;
_11.label = 13;
case 13:
if (!(_b < paramTypes_1.length)) return [3, 19];
_11.label = 15;
case 15:
if (!(_b < paramTypes_1.length)) return [3, 21];
paramType = paramTypes_1[_b];
if (!(paramType === ReqFormUrlBody_1.ReqFormUrlBody)) return [3, 15];
if (!(paramType === ReqFormUrlBody_1.ReqFormUrlBody)) return [3, 17];
_d = (_c = otherStorage).set;
_e = [ReqFormUrlBody_1.ReqFormUrlBody];
return [4, rr.reqBodyReqFormUrlBody()];
case 14:
case 16:
_d.apply(_c, _e.concat([_11.sent()]));
return [3, 18];
case 15:
if (!(paramType === ReqJsonBody_1.ReqJsonBody)) return [3, 17];
return [3, 20];
case 17:
if (!(paramType === ReqJsonBody_1.ReqJsonBody)) return [3, 19];
_g = (_f = otherStorage).set;
_h = [ReqJsonBody_1.ReqJsonBody];
return [4, rr.reqBodyReqJsonBody()];
case 16:
case 18:
_g.apply(_f, _h.concat([_11.sent()]));
return [3, 18];
case 17:
return [3, 20];
case 19:
if (paramType === url_1.URLSearchParams) {

@@ -350,19 +360,19 @@ otherStorage.set(url_1.URLSearchParams, rr.reqUrlSearchParamsType);

}
_11.label = 18;
case 18:
_11.label = 20;
case 20:
_b++;
return [3, 13];
case 19: return [4, this.simstanceManager.executeBindParameterSimPromise({
return [3, 15];
case 21: return [4, this.simstanceManager.executeBindParameterSimPromise({
target: moduleInstance_1,
targetKey: it_3.propertyKey
}, otherStorage)];
case 20:
case 22:
data = _11.sent();
if (!((_t = it_3.config) === null || _t === void 0 ? void 0 : _t.resolver)) return [3, 22];
if (!((_t = it_3.config) === null || _t === void 0 ? void 0 : _t.resolver)) return [3, 24];
execute = typeof it_3.config.resolver === 'function' ? this.simstanceManager.getOrNewSim(it_3.config.resolver) : it_3.config.resolver;
return [4, ((_u = execute === null || execute === void 0 ? void 0 : execute.resolve) === null || _u === void 0 ? void 0 : _u.call(execute, data, rr))];
case 21:
case 23:
data = _11.sent();
_11.label = 22;
case 22:
_11.label = 24;
case 24:
status = (_x = (_w = (_v = it_3.config) === null || _v === void 0 ? void 0 : _v.res) === null || _w === void 0 ? void 0 : _w.status) !== null && _x !== void 0 ? _x : HttpStatus_1.HttpStatus.Ok;

@@ -382,30 +392,30 @@ headers = (_0 = (_z = (_y = it_3.config) === null || _y === void 0 ? void 0 : _y.res) === null || _z === void 0 ? void 0 : _z.header) !== null && _0 !== void 0 ? _0 : {};

rr.resWrite(data);
_11.label = 23;
case 23:
_11.label = 25;
case 25:
if (this.option.noSuchRouteEndPointMappingThrow && methods.length <= 0 && ((_9 = rr.reqMethod()) === null || _9 === void 0 ? void 0 : _9.toUpperCase()) !== HttpMethod_1.HttpMethod.OPTIONS) {
throw this.option.noSuchRouteEndPointMappingThrow(rr);
}
_11.label = 24;
case 24:
_11.label = 26;
case 26:
_j = 0, _k = filter.reverse();
_11.label = 25;
case 25:
if (!(_j < _k.length)) return [3, 29];
_11.label = 27;
case 27:
if (!(_j < _k.length)) return [3, 31];
it_4 = _k[_j];
_l = ((_10 = it_4.filter) === null || _10 === void 0 ? void 0 : _10.after);
if (!_l) return [3, 27];
if (!_l) return [3, 29];
return [4, it_4.filter.after(rr, this, it_4.sw)];
case 26:
case 28:
_l = !(_11.sent());
_11.label = 27;
case 27:
_11.label = 29;
case 29:
if (_l) {
return [3, 29];
return [3, 31];
}
_11.label = 28;
case 28:
_11.label = 30;
case 30:
_j++;
return [3, 25];
case 29: return [3, 33];
case 30:
return [3, 27];
case 31: return [3, 35];
case 32:
e_1 = _11.sent();

@@ -426,3 +436,3 @@ rr.resStatusCode(e_1 instanceof HttpError_1.HttpError ? e_1.status : HttpStatus_1.HttpStatus.InternalServerError);

target = (0, ExceptionDecorator_1.targetExceptionHandler)(execute, e_1);
if (!target) return [3, 32];
if (!target) return [3, 34];
return [4, this.simstanceManager.executeBindParameterSimPromise({

@@ -432,7 +442,7 @@ target: execute,

}, otherStorage)];
case 31:
case 33:
_11.sent();
_11.label = 32;
case 32: return [3, 33];
case 33:
_11.label = 34;
case 34: return [3, 35];
case 35:
if (!rr.resIsDone()) {

@@ -439,0 +449,0 @@ rr.resEnd();

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