Socket
Socket
Sign inDemoInstall

exegesis

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exegesis - npm Package Compare versions

Comparing version 4.1.1 to 4.1.2

27

lib/controllers/loadControllers.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -8,3 +31,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const fs_1 = __importDefault(require("fs"));
const glob_1 = __importDefault(require("glob"));
const glob = __importStar(require("glob"));
const path_1 = __importDefault(require("path"));

@@ -26,3 +49,3 @@ /**

function loadControllersSync(folder, pattern = '**/*.js', loader = require) {
const controllerNames = glob_1.default.sync(pattern, { cwd: folder });
const controllerNames = glob.sync(pattern, { cwd: folder });
return controllerNames.reduce((result, controllerName) => {

@@ -29,0 +52,0 @@ const fullPath = path_1.default.resolve(folder, controllerName);

105

lib/core/exegesisRunner.js

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

status: err.status,
headers: { 'content-type': 'application/json' },
headers: err.headers || { 'content-type': 'application/json' },
body: (0, stringToStream_1.default)(JSON.stringify({ message: err.message }), 'utf-8'),

@@ -133,2 +133,11 @@ };

}
if (!resolved.operation) {
const error = new Error(`Method ${method} not allowed for ${url}`);
error.status = 405;
error.headers = {
allow: resolved.allowedMethods.join(',').toUpperCase(),
'content-type': 'application/json',
};
return handleError(error);
}
const context = new ExegesisContextImpl_1.default(req, res, resolved.api, options.originalOptions);

@@ -138,54 +147,52 @@ if (!context.isResponseFinished()) {

}
if (resolved.operation) {
const { operation } = resolved;
context._setOperation(resolved.baseUrl, resolved.path, operation);
if (!operation.controller) {
throw new Error(`No controller found for ${method} ${url}`);
}
yield handleSecurity(operation, context);
if (!context.isResponseFinished()) {
yield plugins.postSecurity(context);
}
if (!context.isResponseFinished()) {
// Fill in context.params and context.requestBody.
yield context.getParams();
yield context.getRequestBody();
}
if (!context.isResponseFinished()) {
yield (0, invoke_1.invokeController)(operation.controllerModule, operation.controller, context);
}
if (!context.origRes.headersSent) {
// Set _afterController to allow postController() plugins to
// modify the response.
context.res._afterController = true;
yield plugins.postController(context);
}
if (!context.origRes.headersSent) {
// Before response validation, if there is a body and no
// content-type has been set, set a reasonable default.
setDefaultContentType(context.res);
if (options.onResponseValidationError) {
const responseValidationResult = resolved.operation.validateResponse(context.res, options.validateDefaultResponses);
try {
if (responseValidationResult.errors &&
responseValidationResult.errors.length) {
options.onResponseValidationError({
errors: responseValidationResult.errors,
isDefault: responseValidationResult.isDefault,
context,
});
}
const { operation } = resolved;
context._setOperation(resolved.baseUrl, resolved.path, operation);
if (!operation.controller) {
throw new Error(`No controller found for ${method} ${url}`);
}
yield handleSecurity(operation, context);
if (!context.isResponseFinished()) {
yield plugins.postSecurity(context);
}
if (!context.isResponseFinished()) {
// Fill in context.params and context.requestBody.
yield context.getParams();
yield context.getRequestBody();
}
if (!context.isResponseFinished()) {
yield (0, invoke_1.invokeController)(operation.controllerModule, operation.controller, context);
}
if (!context.origRes.headersSent) {
// Set _afterController to allow postController() plugins to
// modify the response.
context.res._afterController = true;
yield plugins.postController(context);
}
if (!context.origRes.headersSent) {
// Before response validation, if there is a body and no
// content-type has been set, set a reasonable default.
setDefaultContentType(context.res);
if (options.onResponseValidationError) {
const responseValidationResult = resolved.operation.validateResponse(context.res, options.validateDefaultResponses);
try {
if (responseValidationResult.errors &&
responseValidationResult.errors.length) {
options.onResponseValidationError({
errors: responseValidationResult.errors,
isDefault: responseValidationResult.isDefault,
context,
});
}
catch (e) {
const err = (0, errors_1.asError)(e);
err.status = err.status || 500;
throw err;
}
}
yield plugins.postResponseValidation(context);
catch (e) {
const err = (0, errors_1.asError)(e);
err.status = err.status || 500;
throw err;
}
}
if (!context.origRes.headersSent) {
result = resultToHttpResponse(context, context.res.body);
}
yield plugins.postResponseValidation(context);
}
if (!context.origRes.headersSent) {
result = resultToHttpResponse(context, context.res.body);
}
return result;

@@ -192,0 +199,0 @@ }

@@ -6,4 +6,4 @@ import * as oas3 from 'openapi3-ts';

*/
export declare type JsonPath = string[];
export declare type ReadOnlyJsonPath = readonly string[];
export type JsonPath = string[];
export type ReadOnlyJsonPath = readonly string[];
/**

@@ -10,0 +10,0 @@ * This has common stuff that we want to pass all the way down through the OAS

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

const httpUtils_1 = require("../utils/httpUtils");
const Path_1 = require("./Path");
class OpenApi {

@@ -138,2 +139,3 @@ /**

}
const allowedMethods = Path_1.HTTP_METHODS.filter((method) => path.getOperation(method));
return {

@@ -143,3 +145,3 @@ operation: resolvedOperation,

openApiDoc: this.openApiDoc,
serverPtr: undefined,
serverPtr: undefined, // FIXME
serverObject: oaServer,

@@ -153,2 +155,3 @@ pathItemPtr: path.context.jsonPointer,

},
allowedMethods,
path: resolvedPath.pathKey,

@@ -155,0 +158,0 @@ baseUrl,

@@ -25,3 +25,4 @@ "use strict";

const SecuritySchemes_1 = __importDefault(require("./SecuritySchemes"));
const METHODS_WITH_BODY = ['post', 'put', 'patch'];
// `delete` might have a body. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
const METHODS_WITH_BODY = ['post', 'put', 'patch', 'delete'];
function isAuthenticationFailure(result) {

@@ -28,0 +29,0 @@ return !!(result.type === 'invalid' || result.type === 'missing');

@@ -24,3 +24,3 @@ import { ParametersMap, ParameterLocation, StringParser } from '../../types';

}
export declare type ParameterDescriptor = StyledParameterDescriptor | MediaTypeParameterDescriptor;
export type ParameterDescriptor = StyledParameterDescriptor | MediaTypeParameterDescriptor;
/**

@@ -35,3 +35,3 @@ * A dictionary where names are parameter names, and values are unparsed strings

*/
export declare type RawValues = ParametersMap<string | string[] | undefined>;
export type RawValues = ParametersMap<string | string[] | undefined>;
/**

@@ -38,0 +38,0 @@ * A parameter parser that takes in a string and returns a value.

import Operation from './Operation';
import Oas3CompileContext from './Oas3CompileContext';
import * as oas3 from 'openapi3-ts';
export declare const HTTP_METHODS: readonly ["get", "head", "post", "put", "delete", "options", "trace", "patch"];
export default class Path {

@@ -5,0 +6,0 @@ readonly context: Oas3CompileContext;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.HTTP_METHODS = void 0;
const Operation_1 = __importDefault(require("./Operation"));

@@ -11,3 +12,12 @@ const Parameter_1 = __importDefault(require("./Parameter"));

// CONNECT not included, as it is not valid for OpenAPI 3.0.1.
const HTTP_METHODS = ['get', 'head', 'post', 'put', 'delete', 'options', 'trace', 'patch'];
exports.HTTP_METHODS = [
'get',
'head',
'post',
'put',
'delete',
'options',
'trace',
'patch',
];
class Path {

@@ -24,3 +34,3 @@ constructor(context, oaPath, exegesisController) {

exegesisController = oaPath[extensions_1.EXEGESIS_CONTROLLER] || exegesisController;
this._operations = HTTP_METHODS.reduce((result, method) => {
this._operations = exports.HTTP_METHODS.reduce((result, method) => {
const operation = oaPath[method];

@@ -27,0 +37,0 @@ if (operation) {

import { ParametersMap } from '../../types';
export declare type PathParserFunction = (pathname: string) => {
export type PathParserFunction = (pathname: string) => {
matched: string;

@@ -4,0 +4,0 @@ rawPathParams: ParametersMap<any>;

/// <reference types="node" />
import * as http from 'http';
export declare type Callback<T> = (err?: Error | null | undefined, value?: T) => void;
export declare type MiddlewareFunction = (req: HttpIncomingMessage, res: http.ServerResponse, next: Callback<void>) => void;
export type Callback<T> = (err?: Error | null | undefined, value?: T) => void;
export type MiddlewareFunction = (req: HttpIncomingMessage, res: http.ServerResponse, next: Callback<void>) => void;
export interface Dictionary<T> {

@@ -6,0 +6,0 @@ [key: string]: T;

/// <reference types="node" />
import * as http from 'http';
import { Callback, HttpIncomingMessage } from './basicTypes';
export declare type ReqParserFunction = (req: HttpIncomingMessage, res: http.ServerResponse, next: Callback<any>) => void;
export declare type StringParserFunction = (encoded: string) => any;
export type ReqParserFunction = (req: HttpIncomingMessage, res: http.ServerResponse, next: Callback<any>) => void;
export type StringParserFunction = (encoded: string) => any;
export interface StringParser {

@@ -7,0 +7,0 @@ /**

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

}
export declare type PromiseController = (context: ExegesisContext) => any;
export declare type CallbackController = (context: ExegesisContext, done: Callback<any>) => void;
export declare type Controller = PromiseController | CallbackController;
export type PromiseController = (context: ExegesisContext) => any;
export type CallbackController = (context: ExegesisContext, done: Callback<any>) => void;
export type Controller = PromiseController | CallbackController;
export interface ControllerModule {

@@ -130,3 +130,3 @@ [operationId: string]: Controller;

}
export declare type AuthenticationResult = AuthenticationSuccess | AuthenticationFailure;
export type AuthenticationResult = AuthenticationSuccess | AuthenticationFailure;
export interface AuthenticatorInfo {

@@ -137,5 +137,5 @@ in?: 'query' | 'header' | 'cookie';

}
export declare type PromiseAuthenticator = (context: ExegesisPluginContext, info: AuthenticatorInfo) => AuthenticationResult | undefined | Promise<AuthenticationResult | undefined>;
export declare type CallbackAuthenticator = (context: ExegesisPluginContext, info: AuthenticatorInfo, done: Callback<AuthenticationResult | undefined>) => void;
export declare type Authenticator = PromiseAuthenticator | CallbackAuthenticator;
export type PromiseAuthenticator = (context: ExegesisPluginContext, info: AuthenticatorInfo) => AuthenticationResult | undefined | Promise<AuthenticationResult | undefined>;
export type CallbackAuthenticator = (context: ExegesisPluginContext, info: AuthenticatorInfo, done: Callback<AuthenticationResult | undefined>) => void;
export type Authenticator = PromiseAuthenticator | CallbackAuthenticator;
export interface Authenticators {

@@ -159,4 +159,4 @@ [scheme: string]: Authenticator;

*/
export declare type ExegesisRunner = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<HttpResult | undefined>;
export declare type ParsedParameterValidator = (parameterValues: ParametersByLocation<ParametersMap<any>>) => IValidationError[] | null;
export type ExegesisRunner = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<HttpResult | undefined>;
export type ParsedParameterValidator = (parameterValues: ParametersByLocation<ParametersMap<any>>) => IValidationError[] | null;
export interface ResolvedOperation {

@@ -180,2 +180,4 @@ parseParameters: () => ParametersByLocation<ParametersMap<any>>;

api: T;
/** List of methods the client is allowed to send to this path. e.g. `['get', 'post']`. */
allowedMethods: string[];
/** The path of the operation being accessed. e.g. "/users/1234". */

@@ -182,0 +184,0 @@ path: string;

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

*/
export declare type CustomFormatChecker = RegExp | ((value: string) => boolean);
export declare type HandleErrorFunction = (err: Error, context: {
export type CustomFormatChecker = RegExp | ((value: string) => boolean);
export type HandleErrorFunction = (err: Error, context: {
req: http.IncomingMessage;

@@ -13,0 +13,0 @@ }) => any;

import { ExegesisContext } from '.';
import * as ajv from 'ajv';
export declare type ParameterLocationIn = 'path' | 'server' | 'query' | 'cookie' | 'header' | 'request' | 'response';
export type ParameterLocationIn = 'path' | 'server' | 'query' | 'cookie' | 'header' | 'request' | 'response';
/**

@@ -5,0 +5,0 @@ * The location of a parameter or property within a request.

{
"name": "exegesis",
"version": "4.1.1",
"version": "4.1.2",
"description": "Parses OpenAPI documents",

@@ -51,3 +51,2 @@ "main": "lib/index.js",

"@types/deep-freeze": "^0.1.1",
"@types/glob": "^7.1.1",
"@types/json-schema": "^7.0.3",

@@ -60,18 +59,18 @@ "@types/lodash": "^4.14.132",

"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.2",
"eslint": "^8.3.0",
"eslint": "^8.57.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^10.1.0",
"nyc": "^15.0.0",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"pretty-quick": "^3.0.0",
"semantic-release": "^19.0.2",
"semantic-release": "^21.0.1",
"supertest-fetch": "^1.2.2",
"ts-node": "^10.4.0",
"typescript": "^4.0.2"
"typescript": "^5.0.3"
},

@@ -86,3 +85,3 @@ "dependencies": {

"events-listener": "^1.1.0",
"glob": "^7.1.3",
"glob": "^10.3.10",
"json-ptr": "^3.0.1",

@@ -89,0 +88,0 @@ "json-schema-traverse": "^1.0.0",

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

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

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

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

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