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.14 to 0.1.15

2

bld/library/gateway.d.ts

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

keys?: string[];
listen: ListenOptions;
listen?: ListenOptions;
session?: GatewaySessionOptions | boolean;

@@ -14,0 +14,0 @@ targets: GatewayTargetDescriptor[];

/// <reference types="node" />
import { IncomingHttpHeaders } from 'http';
import { Context, Next } from 'koa';
import { Next } from 'koa';
import { Dict } from 'tslang';

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

}
export declare type GatewayTargetMatchFunction = (context: GatewayTargetMatchContext | Context) => string | undefined;
export declare type GatewayTargetMatchFunction = (context: GatewayTargetMatchContext) => string | undefined;
export declare type GatewayTargetMatchPattern = string | string[] | RegExp | GatewayTargetMatchFunction | {
path?: string | string[] | RegExp;
headers?: Dict<string | RegExp | boolean>;
};
export interface IGatewayTargetDescriptor {
type: string;
match?: string | string[] | RegExp | GatewayTargetMatchFunction | {
path?: string | string[] | RegExp;
headers?: Dict<string | RegExp | boolean>;
};
match?: GatewayTargetMatchPattern;
session?: boolean;

@@ -26,3 +27,3 @@ }

get sessionEnabled(): boolean;
abstract handle(context: Context, next: Next, base: string): Promise<void>;
abstract handle(context: GatewayTargetMatchContext, next: Next, base: string): Promise<void>;
match(context: GatewayTargetMatchContext): string | undefined;

@@ -33,2 +34,3 @@ }

export declare type GatewayTargetConstructor<TDescriptor extends IGatewayTargetDescriptor> = new (descriptor: TDescriptor, log: LogFunction) => IGatewayTarget<TDescriptor>;
export declare function matchContext(context: GatewayTargetMatchContext, match?: GatewayTargetMatchPattern): string | undefined;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractGatewayTarget = void 0;
exports.matchContext = exports.AbstractGatewayTarget = void 0;
const hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -28,29 +28,32 @@ const GATEWAY_TARGET_DESCRIPTOR_DEFAULT = {

match(context) {
let { match = '' } = this.descriptor;
if (typeof match === 'string' ||
Array.isArray(match) ||
match instanceof RegExp) {
match = {
path: match,
};
}
if (typeof match === 'function') {
return match(context);
}
let { path: pathPattern, headers: headerPatternDict } = match;
let base = '';
if (pathPattern) {
base = matchPath(context.path, pathPattern);
if (base === undefined) {
return undefined;
}
}
if (headerPatternDict &&
!matchHeaders(context.headers, headerPatternDict)) {
let { match } = this.descriptor;
return matchContext(context, match);
}
}
exports.AbstractGatewayTarget = GatewayTarget;
function matchContext(context, match = '') {
if (typeof match === 'string' ||
Array.isArray(match) ||
match instanceof RegExp) {
match = {
path: match,
};
}
if (typeof match === 'function') {
return match(context);
}
let { path: pathPattern, headers: headerPatternDict } = match;
let base = '';
if (pathPattern) {
base = matchPath(context.path, pathPattern);
if (base === undefined) {
return undefined;
}
return base;
}
if (headerPatternDict && !matchHeaders(context.headers, headerPatternDict)) {
return undefined;
}
return base;
}
exports.AbstractGatewayTarget = GatewayTarget;
exports.matchContext = matchContext;
function matchPath(path, pattern) {

@@ -57,0 +60,0 @@ var _a;

{
"name": "@makeflow/gateway",
"version": "0.1.14",
"version": "0.1.15",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "Chengdu Mufan Technology Co., Ltd.",

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

keys?: string[];
listen: ListenOptions;
listen?: ListenOptions;
session?: GatewaySessionOptions | boolean;

@@ -26,0 +26,0 @@ targets: GatewayTargetDescriptor[];

import {IncomingHttpHeaders} from 'http';
import {Context, Next} from 'koa';
import {Next} from 'koa';
import {Dict} from 'tslang';

@@ -21,16 +21,18 @@

export type GatewayTargetMatchFunction = (
context: GatewayTargetMatchContext | Context,
context: GatewayTargetMatchContext,
) => string | undefined;
export type GatewayTargetMatchPattern =
| string
| string[]
| RegExp
| GatewayTargetMatchFunction
| {
path?: string | string[] | RegExp;
headers?: Dict<string | RegExp | boolean>;
};
export interface IGatewayTargetDescriptor {
type: string;
match?:
| string
| string[]
| RegExp
| GatewayTargetMatchFunction
| {
path?: string | string[] | RegExp;
headers?: Dict<string | RegExp | boolean>;
};
match?: GatewayTargetMatchPattern;
session?: boolean;

@@ -52,41 +54,11 @@ }

abstract handle(context: Context, next: Next, base: string): Promise<void>;
abstract handle(
context: GatewayTargetMatchContext,
next: Next,
base: string,
): Promise<void>;
match(context: GatewayTargetMatchContext): string | undefined {
let {match = ''} = this.descriptor;
if (
typeof match === 'string' ||
Array.isArray(match) ||
match instanceof RegExp
) {
match = {
path: match,
};
}
if (typeof match === 'function') {
return match(context);
}
let {path: pathPattern, headers: headerPatternDict} = match;
let base: string | undefined = '';
if (pathPattern) {
base = matchPath(context.path, pathPattern);
if (base === undefined) {
return undefined;
}
}
if (
headerPatternDict &&
!matchHeaders(context.headers, headerPatternDict)
) {
return undefined;
}
return base;
let {match} = this.descriptor;
return matchContext(context, match);
}

@@ -107,2 +79,39 @@ }

export function matchContext(
context: GatewayTargetMatchContext,
match: GatewayTargetMatchPattern = '',
): string | undefined {
if (
typeof match === 'string' ||
Array.isArray(match) ||
match instanceof RegExp
) {
match = {
path: match,
};
}
if (typeof match === 'function') {
return match(context);
}
let {path: pathPattern, headers: headerPatternDict} = match;
let base: string | undefined = '';
if (pathPattern) {
base = matchPath(context.path, pathPattern);
if (base === undefined) {
return undefined;
}
}
if (headerPatternDict && !matchHeaders(context.headers, headerPatternDict)) {
return undefined;
}
return base;
}
function matchPath(

@@ -109,0 +118,0 @@ path: string,

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