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.7 to 0.1.8

bld/library/log.d.ts

14

bld/library/gateway.d.ts
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Server } from 'http';
import { ListenOptions } from 'net';
import Session from 'koa-session';
import { LogFunction } from './log';
import { GatewayTargetDescriptor } from './target';

@@ -12,3 +14,3 @@ export interface GatewayOptions {

}
export declare class Gateway {
export declare class Gateway extends EventEmitter {
private options;

@@ -20,5 +22,15 @@ private koa;

serve(): Server;
protected log: LogFunction;
private middleware;
}
export interface Gateway {
emit(event: 'log', data: LogEventData): boolean;
on(event: 'log', listener: (data: LogEventData) => void): this;
}
export interface GatewaySessionOptions extends Partial<Omit<Session.opts, 'autoCommit'>> {
}
export interface LogEventData {
/** The event that triggers this log. */
event: string;
[key: string]: unknown;
}

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

const assert_1 = tslib_1.__importDefault(require("assert"));
const events_1 = require("events");
const koa_1 = tslib_1.__importDefault(require("koa"));

@@ -13,7 +14,14 @@ const koa_session_1 = tslib_1.__importDefault(require("koa-session"));

};
class Gateway {
class Gateway extends events_1.EventEmitter {
constructor(options) {
super();
this.options = options;
this.koa = new koa_1.default();
this.targets = [];
this.log = (event, data) => {
this.emit('log', {
event,
...data,
});
};
this.middleware = async (context, next) => {

@@ -67,3 +75,3 @@ let target;

let Target = target_1.GATEWAY_TARGET_CONSTRUCTOR_DICT[descriptor.type];
targets.push(new Target(descriptor));
targets.push(new Target(descriptor, this.log));
}

@@ -70,0 +78,0 @@ koa.use(this.middleware);

3

bld/library/target/file-target.d.ts
import { Context, Next } from 'koa';
import Compress from 'koa-compress';
import { SendOptions } from 'koa-send';
import { LogFunction } from '../log';
import { AbstractGatewayTarget, IGatewayTargetDescriptor } from './target';

@@ -13,5 +14,5 @@ export interface FileTargetDescriptor extends IGatewayTargetDescriptor {

private middleware;
constructor(descriptor: FileTargetDescriptor);
constructor(descriptor: FileTargetDescriptor, log: LogFunction);
handle(context: Context, next: Next): Promise<void>;
}
export declare function createIndexFileFallbackMatchPathRegex(prefix?: string): RegExp;

@@ -17,4 +17,4 @@ "use strict";

class FileTarget extends target_1.AbstractGatewayTarget {
constructor(descriptor) {
super(descriptor);
constructor(descriptor, log) {
super(descriptor, log);
let { target, compress: compressOptions = FILE_TARGET_DESCRIPTOR_DEFAULT.compress, send: sendOptions, } = descriptor;

@@ -21,0 +21,0 @@ let middlewareArray = [];

import { ServerOptions } from 'http-proxy';
import { Context, Next } from 'koa';
import { LogFunction } from '../log';
import { AbstractGatewayTarget, IGatewayTargetDescriptor } from './target';

@@ -12,3 +13,3 @@ export interface ProxyTargetDescriptor extends IGatewayTargetDescriptor {

private websocketUpgradeInitialized;
constructor(descriptor: ProxyTargetDescriptor);
constructor(descriptor: ProxyTargetDescriptor, log: LogFunction);
handle(context: Context, _next: Next, base: string): Promise<void>;

@@ -15,0 +16,0 @@ private ensureWebsocketUpgrade;

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

class ProxyTarget extends target_1.AbstractGatewayTarget {
constructor(descriptor) {
super(descriptor);
constructor(descriptor, log) {
super(descriptor, log);
this.websocketUpgradeInitialized = false;
let { options } = descriptor;
this.proxy = http_proxy_1.createProxyServer({ ...options, ignorePath: true });
this.proxy.on('error', error => this.log('proxy-server-error', { error }));
}

@@ -16,0 +17,0 @@ async handle(context, _next, base) {

import { Context, Next } from 'koa';
import Compress from 'koa-compress';
import Static from 'koa-static';
import { LogFunction } from '../log';
import { AbstractGatewayTarget, IGatewayTargetDescriptor } from './target';

@@ -14,5 +15,5 @@ export interface StaticTargetDescriptor extends IGatewayTargetDescriptor {

private baseToMountMap;
constructor(descriptor: StaticTargetDescriptor);
constructor(descriptor: StaticTargetDescriptor, log: LogFunction);
get sessionEnabled(): boolean;
handle(context: Context, next: Next, base: string): Promise<void>;
}

@@ -18,4 +18,4 @@ "use strict";

class StaticTarget extends target_1.AbstractGatewayTarget {
constructor(descriptor) {
super(descriptor);
constructor(descriptor, log) {
super(descriptor, log);
this.koa = new koa_1.default();

@@ -22,0 +22,0 @@ this.baseToMountMap = new Map();

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

import { Dict } from 'tslang';
import { LogFunction } from '../log';
export interface GatewayTargetMatchContext {

@@ -22,3 +23,4 @@ url: string;

readonly descriptor: TDescriptor;
constructor(descriptor: TDescriptor);
protected readonly log: LogFunction;
constructor(descriptor: TDescriptor, log: LogFunction);
get sessionEnabled(): boolean;

@@ -30,3 +32,3 @@ abstract handle(context: Context, next: Next, base: string): Promise<void>;

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

@@ -9,4 +9,5 @@ "use strict";

class GatewayTarget {
constructor(descriptor) {
constructor(descriptor, log) {
this.descriptor = descriptor;
this.log = log;
}

@@ -13,0 +14,0 @@ get sessionEnabled() {

{
"name": "@makeflow/gateway",
"version": "0.1.7",
"version": "0.1.8",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

import assert from 'assert';
import {EventEmitter} from 'events';
import {Server} from 'http';

@@ -8,2 +9,3 @@ import {ListenOptions} from 'net';

import {LogFunction} from './log';
import {

@@ -27,3 +29,3 @@ GATEWAY_TARGET_CONSTRUCTOR_DICT,

export class Gateway {
export class Gateway extends EventEmitter {
private koa: Koa = new Koa();

@@ -36,2 +38,4 @@

constructor(private options: GatewayOptions) {
super();
let {

@@ -73,3 +77,3 @@ keys,

targets.push(new Target(descriptor));
targets.push(new Target(descriptor, this.log));
}

@@ -86,2 +90,9 @@

protected log: LogFunction = (event, data) => {
this.emit('log', {
event,
...data,
});
};
private middleware = async (context: Context, next: Next): Promise<void> => {

@@ -123,3 +134,15 @@ let target: IGatewayTarget<IGatewayTargetDescriptor> | undefined;

export interface Gateway {
emit(event: 'log', data: LogEventData): boolean;
on(event: 'log', listener: (data: LogEventData) => void): this;
}
export interface GatewaySessionOptions
extends Partial<Omit<Session.opts, 'autoCommit'>> {}
export interface LogEventData {
/** The event that triggers this log. */
event: string;
[key: string]: unknown;
}

@@ -8,2 +8,4 @@ import assert from 'assert';

import {LogFunction} from '../log';
import {AbstractGatewayTarget, IGatewayTargetDescriptor} from './target';

@@ -28,4 +30,4 @@

constructor(descriptor: FileTargetDescriptor) {
super(descriptor);
constructor(descriptor: FileTargetDescriptor, log: LogFunction) {
super(descriptor, log);

@@ -32,0 +34,0 @@ let {

@@ -6,2 +6,4 @@ import {IncomingMessage, OutgoingMessage, Server as HTTPServer} from 'http';

import {LogFunction} from '../log';
import {AbstractGatewayTarget, IGatewayTargetDescriptor} from './target';

@@ -22,4 +24,4 @@

constructor(descriptor: ProxyTargetDescriptor) {
super(descriptor);
constructor(descriptor: ProxyTargetDescriptor, log: LogFunction) {
super(descriptor, log);

@@ -29,2 +31,4 @@ let {options} = descriptor;

this.proxy = createProxyServer({...options, ignorePath: true});
this.proxy.on('error', error => this.log('proxy-server-error', {error}));
}

@@ -31,0 +35,0 @@

@@ -6,2 +6,4 @@ import Koa, {Context, Middleware, Next} from 'koa';

import {LogFunction} from '../log';
import {AbstractGatewayTarget, IGatewayTargetDescriptor} from './target';

@@ -31,4 +33,4 @@

constructor(descriptor: StaticTargetDescriptor) {
super(descriptor);
constructor(descriptor: StaticTargetDescriptor, log: LogFunction) {
super(descriptor, log);

@@ -35,0 +37,0 @@ let {

@@ -6,2 +6,4 @@ import {IncomingHttpHeaders} from 'http';

import {LogFunction} from '../log';
const hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -38,3 +40,6 @@

abstract class GatewayTarget<TDescriptor extends IGatewayTargetDescriptor> {
constructor(readonly descriptor: TDescriptor) {}
constructor(
readonly descriptor: TDescriptor,
protected readonly log: LogFunction,
) {}

@@ -99,3 +104,5 @@ get sessionEnabled(): boolean {

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

@@ -102,0 +109,0 @@ function matchPath(

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