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

@meeshkanml/express-middleware

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meeshkanml/express-middleware - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

9

dist/index.d.ts
import { Request, Response, NextFunction } from "express";
interface Options {
path: string;
import { HttpExchange } from "http-types";
export declare type HttpExchangeTransport = (httpExchange: HttpExchange) => Promise<void>;
export interface Options {
transports?: HttpExchangeTransport[];
}
declare const _default: (options: Options) => (req: Request<import("express-serve-static-core").ParamsDictionary>, res: Response, next: NextFunction) => void;
export declare const LocalFileSystemTransport: (filename: string) => HttpExchangeTransport;
declare const _default: (options: Options) => (req: Request<import("express-serve-static-core").ParamsDictionary>, res: Response, next: NextFunction) => Promise<void>;
export default _default;
//# sourceMappingURL=index.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var url_1 = __importDefault(require("url"));
exports.default = (function (options) { return function (req, res, next) {
var oldWrite = res.write;
var oldEnd = res.end;
var chunks = [];
res.write = function (thingOne, thingTwo, thingThree) {
chunks.push(Buffer.from(thingOne));
return oldWrite.apply(res, [
thingOne,
typeof thingTwo === "string" ? thingTwo : "utf8",
thingThree === undefined &&
thingTwo !== undefined &&
typeof thingTwo !== "string"
? thingTwo
: thingThree
]);
};
res.end = function (thingOne, thingTwo, thingThree) {
if (thingOne) {
var fs = __importStar(require("fs"));
var http_types_1 = require("http-types");
exports.LocalFileSystemTransport = function (filename) { return function (httpExchange) {
return new Promise(function (resolve, reject) {
try {
fs.appendFileSync(filename, JSON.stringify(httpExchange) + "\n");
resolve();
}
catch (err) {
reject(err);
}
});
}; };
exports.default = (function (options) { return function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
var oldWrite, oldEnd, transports, chunks;
return __generator(this, function (_a) {
oldWrite = res.write;
oldEnd = res.end;
transports = options.transports || [];
chunks = [];
res.write = function (thingOne, thingTwo, thingThree) {
chunks.push(Buffer.from(thingOne));
}
var body = Buffer.concat(chunks).toString("utf8");
var output = {
request: {
return oldWrite.apply(res, [
thingOne,
typeof thingTwo === "string" ? thingTwo : "utf8",
thingThree === undefined &&
thingTwo !== undefined &&
typeof thingTwo !== "string"
? thingTwo
: thingThree
]);
};
res.end = function (thingOne, thingTwo, thingThree) {
if (thingOne) {
chunks.push(Buffer.from(thingOne));
}
var body = Buffer.concat(chunks).toString("utf8");
var request = http_types_1.HttpRequestBuilder.fromPathnameAndQuery({
headers: req.headers,
host: req.hostname,
method: req.method,
path: url_1.default.parse(req.url).path || req.path,
pathname: url_1.default.parse(req.url).pathname || req.path,
method: req.method.toLowerCase(),
pathname: req.path,
query: req.query,
protocol: req.protocol,
protocol: req.protocol.toLowerCase(),
body: typeof req.body === "string" ? req.body : JSON.stringify(req.body)
},
response: {
});
var response = http_types_1.HttpResponseBuilder.from({
statusCode: res.statusCode,
body: body,
headers: res.getHeaders()
}
});
var exchange = { request: request, response: response };
transports.forEach(function (transport) { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, transport(exchange)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
return oldEnd.apply(res, [
thingOne,
typeof thingTwo === "string" ? thingTwo : "utf8",
thingThree === undefined &&
thingTwo !== undefined &&
typeof thingTwo !== "string"
? thingTwo
: thingThree
]);
};
fs_1.default.appendFileSync(options.path, JSON.stringify(output) + "\n");
return oldEnd.apply(res, [
thingOne,
typeof thingTwo === "string" ? thingTwo : "utf8",
thingThree === undefined &&
thingTwo !== undefined &&
typeof thingTwo !== "string"
? thingTwo
: thingThree
]);
};
next();
}; });
next();
return [2 /*return*/];
});
}); }; });
//# sourceMappingURL=index.js.map
{
"name": "@meeshkanml/express-middleware",
"version": "0.0.0",
"version": "0.0.1",
"description": "Express middleware to create .jsonl files for consumption by Meeshkan.",
"main": "dist/index.js",
"repository": "https://github.com/meeshkan/express-middleware",
"author": "Mike Solomon",
"author": "Meeshkan",
"license": "MIT",

@@ -22,3 +22,3 @@ "private": false,

"typescript": "^3.7.5",
"unmock-types": "^0.3.12"
"http-types": "^0.5.0"
},

@@ -25,0 +25,0 @@ "scripts": {

[![CircleCI](https://circleci.com/gh/Meeshkan/express-middleware.svg?style=svg)](https://circleci.com/gh/Meeshkan/express-middleware)
[![npm version](https://img.shields.io/npm/v/@meeshkanml/express-middleware)](https://npmjs.org/package/@meeshkanml/express-middleware)
# Meeshkan express middleware
Middleware to log requests and responses for `express` servers.
Express server middleware to log requests and responses in [http-types](https://meeshkan.github.io/http-types/) format.
## Usage
Add this middleware before adding routes, otherwise it won't work.
```javascript
const mw = require('@meeshkan/express-middleware');
app.use(mw({ path: 'log.jsonl' }));
const mw, { LocalFileSystemTransport } = require("@meeshkan/express-middleware");
// Add custom transports with signature
// `type HttpExchangeTransport = (httpExchange: HttpExchange) => Promise<void>;`
// Here `HttpExchange` is defined in `ts-http-types`
const customTransport = async httpExchange => {
console.log("Got http exchange", httpExchange);
};
// Add middleware
app.use(
middleware({
transports: [LocalFileSystemTransport("http-exchanges.jsonl"), customTransport],
})
);
// add routes
```
```
## Development
Install dependencies:
```bash
$ yarn
```
Run tests:
```bash
$ yarn test
```
Compile TypeScript:
```bash
$ yarn compile
```
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"es2017"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"resolveJsonModule": true,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [
"./node_modules/@types",
"./src/typings"
] /* List of folders to include type definitions from. */,
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["node_modules", "test", "dist"]
}
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"es2017"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"resolveJsonModule": true,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [
"./node_modules/@types",
"./src/typings"
] /* List of folders to include type definitions from. */,
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["src/**/*"]
}

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