New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@stoplight/prism-core

Package Overview
Dependencies
Maintainers
20
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/prism-core - npm Package Compare versions

Comparing version 3.2.0-beta.11 to 3.2.0-beta.12

36

dist/factory.js

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

const lodash_1 = require("lodash");
const security_1 = require("./utils/security");
const Apply_1 = require("fp-ts/lib/Apply");
const NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray");
const types_1 = require("@stoplight/types");
const sequenceValidation = Apply_1.sequenceT(Either.getValidation(NonEmptyArray_1.getSemigroup()));

@@ -17,10 +17,10 @@ function isProxyConfig(p) {

function factory(defaultConfig, components) {
const inputValidation = (resource, input, config) => pipeable_1.pipe(sequenceValidation(config.validateRequest ? components.validateInput({ resource, element: input }) : Either.right(input), config.checkSecurity ? security_1.validateSecurity(input, resource) : Either.right(input)), Either.fold(inputValidations => inputValidations, () => []), inputValidations => TaskEither.right({ resource, inputValidations }));
const mockOrForward = (resource, input, config, inputValidations) => {
const inputValidation = (resource, input, config) => pipeable_1.pipe(sequenceValidation(config.validateRequest ? components.validateInput({ resource, element: input }) : Either.right(input), config.checkSecurity ? components.validateSecurity({ resource, element: input }) : Either.right(input)), Either.fold(validations => validations, () => []), validations => TaskEither.right({ resource, validations }));
const mockOrForward = (resource, input, config, validations) => {
const produceOutput = isProxyConfig(config)
? components.forward(input, config.upstream.href)
? components.forward(input, config.upstream.href)(components.logger.child({ name: 'PROXY' }))
: TaskEither.fromEither(components.mock({
resource,
input: {
validations: inputValidations,
validations,
data: input,

@@ -30,3 +30,3 @@ },

})(components.logger.child({ name: 'NEGOTIATOR' })));
return pipeable_1.pipe(produceOutput, TaskEither.map(output => ({ output, resource, inputValidations })));
return pipeable_1.pipe(produceOutput, TaskEither.map(output => ({ output, resource, validations })));
};

@@ -36,3 +36,21 @@ return {

const config = lodash_1.defaults(c, defaultConfig);
return pipeable_1.pipe(TaskEither.fromEither(components.route({ resources, input })), TaskEither.chain(resource => inputValidation(resource, input, config)), TaskEither.chain(({ resource, inputValidations }) => mockOrForward(resource, input, config, inputValidations)), TaskEither.map(({ output, resource, inputValidations }) => {
return pipeable_1.pipe(TaskEither.fromEither(components.route({ resources, input })), TaskEither.fold(error => {
if (!config.errors && isProxyConfig(config)) {
return pipeable_1.pipe(components.forward(input, config.upstream.href)(components.logger.child({ name: 'PROXY' })), TaskEither.map(output => ({
input,
output,
validations: {
input: [
{
message: "The selected route hasn't been found and the errors is set false. Prism has proxied the request to the upstream server but no validation will happen",
severity: types_1.DiagnosticSeverity.Warning,
},
],
output: [],
},
})));
}
else
return TaskEither.left(error);
}, resource => pipeable_1.pipe(inputValidation(resource, input, config), TaskEither.chain(({ resource, validations }) => mockOrForward(resource, input, config, validations)), TaskEither.map(({ output, resource, validations: inputValidations }) => {
const outputValidations = config.validateResponse

@@ -49,5 +67,3 @@ ? pipeable_1.pipe(Option.fromEither(Either.swap(components.validateOutput({ resource, element: output }))), Option.getOrElse(() => []))

};
}))().then(v => pipeable_1.pipe(v, Either.fold(e => {
throw e;
}, o => o)));
}))));
},

@@ -54,0 +70,0 @@ };

import { IDiagnostic } from '@stoplight/types';
import { Either } from 'fp-ts/lib/Either';
import { ReaderEither } from 'fp-ts/lib/ReaderEither';
import { ReaderTaskEither } from 'fp-ts/lib/ReaderTaskEither';
import { TaskEither } from 'fp-ts/lib/TaskEither';

@@ -11,3 +12,3 @@ import { Logger } from 'pino';

export interface IPrism<Resource, Input, Output, Config extends IPrismConfig> {
request: (input: Input, resources: Resource[], config?: Config) => Promise<IPrismOutput<Input, Output>>;
request: (input: Input, resources: Resource[], config?: Config) => TaskEither<Error, IPrismOutput<Output>>;
}

@@ -19,2 +20,3 @@ export interface IPrismConfig {

validateResponse: boolean;
errors: boolean;
}

@@ -35,4 +37,5 @@ export declare type ValidatorFn<Resource, T> = (opts: {

validateInput: ValidatorFn<Resource, Input>;
validateSecurity: ValidatorFn<Resource, Input>;
validateOutput: ValidatorFn<Resource, Output>;
forward: (input: Input, baseUrl: string) => TaskEither<Error, Output>;
forward: (input: Input, baseUrl: string) => ReaderTaskEither<Logger, Error, Output>;
mock: (opts: {

@@ -49,4 +52,3 @@ resource: Resource;

}
export interface IPrismOutput<I, O> {
input: I;
export interface IPrismOutput<O> {
output: O;

@@ -53,0 +55,0 @@ validations: {

{
"name": "@stoplight/prism-core",
"version": "3.2.0-beta.11",
"version": "3.2.0-beta.12",
"main": "dist/index.js",

@@ -26,3 +26,3 @@ "types": "dist/index.d.ts",

},
"gitHead": "58b32c0b6d12e231e96e7e65c7aa54c232ecd860"
"gitHead": "de9ee1d341a6df1394a130f40fb78eedac9743d3"
}
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