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

@makeflow/gateway

Package Overview
Dependencies
Maintainers
7
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@makeflow/gateway - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

LICENSE

105

bld/library/gateway.js

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

const tslib_1 = require("tslib");
const assert_1 = tslib_1.__importDefault(require("assert"));
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
const events_1 = require("events");
const koa_1 = tslib_1.__importDefault(require("koa"));
const koa_session_1 = tslib_1.__importDefault(require("koa-session"));
const koa_1 = (0, tslib_1.__importDefault)(require("koa"));
const koa_session_1 = (0, tslib_1.__importDefault)(require("koa-session"));
const target_1 = require("./target");

@@ -17,38 +17,69 @@ const GATEWAY_OPTIONS_DEFAULT = {

super();
this.options = options;
this.koa = new koa_1.default();
this.targets = [];
this.log = (level, event, data) => {
this.emit('log', {
level,
event,
...data,
});
};
this.middleware = async (context, next) => {
let target;
let base;
for (let candidateTarget of this.targets) {
let candidateBase = candidateTarget.match(context);
if (typeof candidateBase === 'string') {
assert_1.default(context.url.startsWith(candidateBase));
target = candidateTarget;
base = candidateBase;
break;
}
Object.defineProperty(this, "options", {
enumerable: true,
configurable: true,
writable: true,
value: options
});
Object.defineProperty(this, "koa", {
enumerable: true,
configurable: true,
writable: true,
value: new koa_1.default()
});
Object.defineProperty(this, "sessionEnabled", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "targets", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
Object.defineProperty(this, "log", {
enumerable: true,
configurable: true,
writable: true,
value: (level, event, data) => {
this.emit('log', {
level,
event,
...data,
});
}
if (!target) {
context.body = 'No gateway target matched';
return;
}
if (this.sessionEnabled && target.sessionEnabled) {
let session = context.session;
if (!session._sessCtx.prevHash) {
// If session has never been set.
session.save();
});
Object.defineProperty(this, "middleware", {
enumerable: true,
configurable: true,
writable: true,
value: async (context, next) => {
let target;
let base;
for (let candidateTarget of this.targets) {
let candidateBase = candidateTarget.match(context);
if (typeof candidateBase === 'string') {
(0, assert_1.default)(context.url.startsWith(candidateBase));
target = candidateTarget;
base = candidateBase;
break;
}
}
await context.session.manuallyCommit();
if (!target) {
context.body = 'No gateway target matched';
return;
}
if (this.sessionEnabled && target.sessionEnabled) {
let session = context.session;
if (!session._sessCtx.prevHash) {
// If session has never been set.
session.save();
}
await context.session.manuallyCommit();
}
await target.handle(context, next, base);
}
await target.handle(context, next, base);
};
});
let { keys, session: sessionOptions = GATEWAY_OPTIONS_DEFAULT.session, targets: targetDescriptors, } = options;

@@ -61,3 +92,3 @@ let koa = this.koa;

this.sessionEnabled = true;
koa.use(koa_session_1.default({
koa.use((0, koa_session_1.default)({
...(sessionOptions === true ? undefined : sessionOptions),

@@ -64,0 +95,0 @@ // By calling `save()` it marked session force save on commit. However,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./gateway"), exports);
tslib_1.__exportStar(require("./target"), exports);
tslib_1.__exportStar(require("./log"), exports);
(0, tslib_1.__exportStar)(require("./gateway"), exports);
(0, tslib_1.__exportStar)(require("./target"), exports);
(0, tslib_1.__exportStar)(require("./log"), exports);
//# sourceMappingURL=index.js.map
import { Context, Next } from 'koa';
import Compress from 'koa-compress';
import { CompressOptions } from 'koa-compress';
import { SendOptions } from 'koa-send';

@@ -9,3 +9,3 @@ import { LogFunction } from '../log';

target: string;
compress?: Compress.CompressOptions | boolean;
compress?: CompressOptions | boolean;
send?: SendOptions;

@@ -12,0 +12,0 @@ }

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

const tslib_1 = require("tslib");
const assert_1 = tslib_1.__importDefault(require("assert"));
const koa_compose_1 = tslib_1.__importDefault(require("koa-compose"));
const koa_compress_1 = tslib_1.__importDefault(require("koa-compress"));
const koa_send_1 = tslib_1.__importDefault(require("koa-send"));
const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
const koa_compose_1 = (0, tslib_1.__importDefault)(require("koa-compose"));
const koa_compress_1 = (0, tslib_1.__importDefault)(require("koa-compress"));
const koa_send_1 = (0, tslib_1.__importDefault)(require("koa-send"));
const target_1 = require("./target");

@@ -20,6 +20,12 @@ const FILE_TARGET_DESCRIPTOR_DEFAULT = {

super(descriptor, log);
Object.defineProperty(this, "middleware", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
let { target, compress: compressOptions = FILE_TARGET_DESCRIPTOR_DEFAULT.compress, send: sendOptions, } = descriptor;
let middlewareArray = [];
if (compressOptions) {
middlewareArray.push(koa_compress_1.default(compressOptions === true
middlewareArray.push((0, koa_compress_1.default)(compressOptions === true
? FILE_TARGET_DESCRIPTOR_DEFAULT.compress

@@ -29,5 +35,5 @@ : compressOptions));

middlewareArray.push(async (context) => {
return koa_send_1.default(context, target, sendOptions);
return (0, koa_send_1.default)(context, target, sendOptions);
});
this.middleware = koa_compose_1.default(middlewareArray);
this.middleware = (0, koa_compose_1.default)(middlewareArray);
}

@@ -42,4 +48,4 @@ async handle(context, next) {

if (prefix) {
assert_1.default(prefix.startsWith('/'));
assert_1.default(!prefix.endsWith('/'));
(0, assert_1.default)(prefix.startsWith('/'));
(0, assert_1.default)(!prefix.endsWith('/'));
}

@@ -46,0 +52,0 @@ return new RegExp(`^${prefix}(?=(?:/[^.]*)?(?:\\?|$))`);

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

};
tslib_1.__exportStar(require("./target"), exports);
tslib_1.__exportStar(require("./proxy-target"), exports);
tslib_1.__exportStar(require("./static-target"), exports);
tslib_1.__exportStar(require("./file-target"), exports);
(0, tslib_1.__exportStar)(require("./target"), exports);
(0, tslib_1.__exportStar)(require("./proxy-target"), exports);
(0, tslib_1.__exportStar)(require("./static-target"), exports);
(0, tslib_1.__exportStar)(require("./file-target"), exports);
//# sourceMappingURL=index.js.map

@@ -7,9 +7,20 @@ "use strict";

const target_1 = require("./target");
const setHeader = http_1.OutgoingMessage.prototype.setHeader;
const setHeader = http_1.ServerResponse.prototype.setHeader;
class ProxyTarget extends target_1.AbstractGatewayTarget {
constructor(descriptor, log) {
super(descriptor, log);
this.websocketUpgradeInitialized = false;
Object.defineProperty(this, "proxy", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "websocketUpgradeInitialized", {
enumerable: true,
configurable: true,
writable: true,
value: false
});
let { options } = descriptor;
this.proxy = http_proxy_1.createProxyServer({ ...options, ignorePath: true });
this.proxy = (0, http_proxy_1.createProxyServer)({ ...options, ignorePath: true });
this.proxy.on('error', error => this.log('error', 'proxy-server-error', { error }));

@@ -16,0 +27,0 @@ }

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

const tslib_1 = require("tslib");
const koa_1 = tslib_1.__importDefault(require("koa"));
const koa_compress_1 = tslib_1.__importDefault(require("koa-compress"));
const koa_mount_1 = tslib_1.__importDefault(require("koa-mount"));
const koa_static_1 = tslib_1.__importDefault(require("koa-static"));
const koa_1 = (0, tslib_1.__importDefault)(require("koa"));
const koa_compress_1 = (0, tslib_1.__importDefault)(require("koa-compress"));
const koa_mount_1 = (0, tslib_1.__importDefault)(require("koa-mount"));
const koa_static_1 = (0, tslib_1.__importDefault)(require("koa-static"));
const target_1 = require("./target");

@@ -21,15 +21,25 @@ const STATIC_TARGET_DESCRIPTOR_DEFAULT = {

super(descriptor, log);
this.koa = new koa_1.default();
this.baseToMountMap = new Map();
Object.defineProperty(this, "koa", {
enumerable: true,
configurable: true,
writable: true,
value: new koa_1.default()
});
Object.defineProperty(this, "baseToMountMap", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
let { target, compress: compressOptions = STATIC_TARGET_DESCRIPTOR_DEFAULT.compress, static: staticOptions, } = descriptor;
let koa = this.koa;
if (compressOptions) {
koa.use(koa_compress_1.default(compressOptions === true
koa.use((0, koa_compress_1.default)(compressOptions === true
? STATIC_TARGET_DESCRIPTOR_DEFAULT.compress
: compressOptions));
}
koa.use(koa_static_1.default(target, staticOptions));
koa.use((0, koa_static_1.default)(target, staticOptions));
}
get sessionEnabled() {
let { session: sessionEnabled = STATIC_TARGET_DESCRIPTOR_DEFAULT.session, } = this.descriptor;
let { session: sessionEnabled = STATIC_TARGET_DESCRIPTOR_DEFAULT.session } = this.descriptor;
return sessionEnabled;

@@ -44,3 +54,3 @@ }

if (!middleware) {
middleware = koa_mount_1.default(base, this.koa);
middleware = (0, koa_mount_1.default)(base, this.koa);
baseToMountMap.set(base, middleware);

@@ -47,0 +57,0 @@ }

@@ -10,7 +10,17 @@ "use strict";

constructor(descriptor, log) {
this.descriptor = descriptor;
this.log = log;
Object.defineProperty(this, "descriptor", {
enumerable: true,
configurable: true,
writable: true,
value: descriptor
});
Object.defineProperty(this, "log", {
enumerable: true,
configurable: true,
writable: true,
value: log
});
}
get sessionEnabled() {
let { session: sessionEnabled = GATEWAY_TARGET_DESCRIPTOR_DEFAULT.session, } = this.descriptor;
let { session: sessionEnabled = GATEWAY_TARGET_DESCRIPTOR_DEFAULT.session } = this.descriptor;
return sessionEnabled;

@@ -17,0 +27,0 @@ }

{
"name": "@makeflow/gateway",
"version": "0.1.11",
"repository": {
"type": "git",
"url": "https://github.com/makeflow/gateway.git"
},
"version": "0.1.12",
"license": "MIT",
"author": "Chengdu Mufan Technology Co., Ltd.",
"repository": "https://github.com/makeflow/gateway.git",
"publishConfig": {
"access": "public"
},
"license": "MIT",
"author": {
"name": "Chengdu Mufan Technology Co., Ltd.",
"email": "support@mufan.com",
"url": "https://www.mufan.com"
},
"main": "bld/library/index.js",
"types": "bld/library/index.d.ts",
"files": [

@@ -24,44 +19,41 @@ "src/**/*.ts",

],
"main": "bld/library/index.js",
"types": "bld/library/index.d.ts",
"scripts": {
"build": "rimraf bld && tsc --build tsconfig.json",
"lint": "run-in-every eslint-project --echo --parallel -- eslint --config {configFileName} .",
"lint-prettier": "prettier --list-different '**/*.{ts,tsx,js,jsx,json,md}'",
"build": "rimraf ./bld && tsc --build",
"lint": "eslint .",
"lint-prettier": "prettier --check .",
"test": "yarn lint-prettier && yarn build && yarn lint && jest"
},
"dependencies": {
"@types/http-proxy": "^1.17.7",
"@types/koa": "^2.13.4",
"@types/koa-compose": "^3.2.5",
"@types/koa-compress": "^4.0.3",
"@types/koa-mount": "^4.0.1",
"@types/koa-send": "^4.1.3",
"@types/koa-session": "^5.10.4",
"@types/koa-static": "^4.0.2",
"http-proxy": "^1.18.1",
"koa": "^2.13.0",
"koa": "^2.13.3",
"koa-compose": "^4.1.0",
"koa-compress": "^5.0.1",
"koa-compress": "^5.1.0",
"koa-mount": "^4.0.0",
"koa-send": "^5.0.1",
"koa-session": "^6.0.0",
"koa-session": "^6.2.0",
"koa-static": "^5.0.0",
"tslang": "^0.1.22",
"tslib": "^2.0.0"
"tslang": "^0.1.23",
"tslib": "^2.3.1"
},
"devDependencies": {
"@magicspace/configs": "^0.2.5",
"@magicspace/eslint-plugin": "^0.1.31",
"@types/http-proxy": "^1.17.4",
"@types/jest": "^26.0.4",
"@types/koa": "^2.11.3",
"@types/koa-compose": "^3.2.5",
"@types/koa-compress": "^4.0.0",
"@types/koa-mount": "^4.0.0",
"@types/koa-send": "^4.1.2",
"@types/koa-session": "^5.10.2",
"@types/koa-static": "^4.0.1",
"@types/node": "^14.0.22",
"@types/node-fetch": "^2.5.7",
"eslint": "^7.4.0",
"jest": "^26.1.0",
"node-fetch": "^2.6.0",
"prettier": "^2.0.5",
"@mufan/code": "^0.2.9",
"@mufan/eslint-plugin": "^0.1.41",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.1",
"@types/node-fetch": "2",
"eslint": "^7.32.0",
"jest": "^27.2.2",
"node-fetch": "2",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"run-in-every": "^0.1.3",
"typescript": "3.9.6"
"typescript": "^4.4.3"
}
}

@@ -97,1 +97,5 @@ # Makeflow Gateway

```
## License
MIT License.

@@ -5,3 +5,3 @@ import assert from 'assert';

import compose from 'koa-compose';
import Compress from 'koa-compress';
import compress, {CompressOptions} from 'koa-compress';
import send, {SendOptions} from 'koa-send';

@@ -23,3 +23,3 @@

target: string;
compress?: Compress.CompressOptions | boolean;
compress?: CompressOptions | boolean;
send?: SendOptions;

@@ -44,3 +44,3 @@ }

middlewareArray.push(
Compress(
compress(
compressOptions === true

@@ -47,0 +47,0 @@ ? FILE_TARGET_DESCRIPTOR_DEFAULT.compress

@@ -13,5 +13,5 @@ import {Dict} from 'tslang';

export const GATEWAY_TARGET_CONSTRUCTOR_DICT: Dict<GatewayTargetConstructor<
IGatewayTargetDescriptor
>> = {
export const GATEWAY_TARGET_CONSTRUCTOR_DICT: Dict<
GatewayTargetConstructor<IGatewayTargetDescriptor>
> = {
proxy: ProxyTarget,

@@ -18,0 +18,0 @@ static: StaticTarget,

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

import {IncomingMessage, OutgoingMessage, Server as HTTPServer} from 'http';
import {IncomingMessage, Server as HTTPServer, ServerResponse} from 'http';

@@ -10,3 +10,3 @@ import Server, {ServerOptions, createProxyServer} from 'http-proxy';

const setHeader = OutgoingMessage.prototype.setHeader;
const setHeader = ServerResponse.prototype.setHeader;

@@ -135,6 +135,6 @@ export interface ProxyTargetDescriptor extends IGatewayTargetDescriptor {

function setHeaderOverride(
this: OutgoingMessage,
this: ServerResponse,
name: string,
value: string | number | string[],
): void {
): ServerResponse {
if (name.toLowerCase() === 'set-cookie') {

@@ -141,0 +141,0 @@ let originalValue = this.getHeader('set-cookie');

@@ -25,5 +25,3 @@ import Koa, {Context, Middleware, Next} from 'koa';

export class StaticTarget extends AbstractGatewayTarget<
StaticTargetDescriptor
> {
export class StaticTarget extends AbstractGatewayTarget<StaticTargetDescriptor> {
private koa = new Koa();

@@ -58,5 +56,4 @@

get sessionEnabled(): boolean {
let {
session: sessionEnabled = STATIC_TARGET_DESCRIPTOR_DEFAULT.session,
} = this.descriptor;
let {session: sessionEnabled = STATIC_TARGET_DESCRIPTOR_DEFAULT.session} =
this.descriptor;

@@ -63,0 +60,0 @@ return sessionEnabled;

@@ -45,5 +45,4 @@ import {IncomingHttpHeaders} from 'http';

get sessionEnabled(): boolean {
let {
session: sessionEnabled = GATEWAY_TARGET_DESCRIPTOR_DEFAULT.session,
} = this.descriptor;
let {session: sessionEnabled = GATEWAY_TARGET_DESCRIPTOR_DEFAULT.session} =
this.descriptor;

@@ -97,11 +96,11 @@ return sessionEnabled;

export type IGatewayTarget<
TDescriptor extends IGatewayTargetDescriptor
> = GatewayTarget<TDescriptor>;
export type IGatewayTarget<TDescriptor extends IGatewayTargetDescriptor> =
GatewayTarget<TDescriptor>;
export type GatewayTargetConstructor<
TDescriptor extends IGatewayTargetDescriptor
> = new (descriptor: TDescriptor, log: LogFunction) => IGatewayTarget<
TDescriptor
>;
TDescriptor extends IGatewayTargetDescriptor,
> = new (
descriptor: TDescriptor,
log: LogFunction,
) => IGatewayTarget<TDescriptor>;

@@ -108,0 +107,0 @@ function matchPath(

@@ -33,4 +33,4 @@ import * as Path from 'path';

session: {
prevHash: !!context.session._sessCtx.prevHash,
populated: context.session.populated,
prevHash: !!context.session!._sessCtx.prevHash,
populated: context.session!.populated,
},

@@ -37,0 +37,0 @@ url: context.url,

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

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

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