@stoplight/prism-core
Advanced tools
Comparing version 3.3.3 to 3.3.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const E = require("fp-ts/lib/Either"); | ||
const A = require("fp-ts/lib/Array"); | ||
const lodash_1 = require("lodash"); | ||
const TE = require("fp-ts/lib/TaskEither"); | ||
const pipeable_1 = require("fp-ts/lib/pipeable"); | ||
const lodash_1 = require("lodash"); | ||
const Apply_1 = require("fp-ts/lib/Apply"); | ||
const lodash_2 = require("lodash"); | ||
const NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); | ||
const types_1 = require("@stoplight/types"); | ||
const sequenceValidation = Apply_1.sequenceT(E.getValidation(NonEmptyArray_1.getSemigroup())); | ||
const function_1 = require("fp-ts/lib/function"); | ||
const eitherSequence = A.array.sequence(E.getValidation(NonEmptyArray_1.getSemigroup())); | ||
function isProxyConfig(p) { | ||
@@ -29,12 +31,15 @@ return !p.mock; | ||
function factory(defaultConfig, components) { | ||
const inputValidation = (resource, input, config) => pipeable_1.pipe(sequenceValidation(config.validateRequest ? components.validateInput({ resource, element: input }) : E.right(input), config.checkSecurity ? components.validateSecurity({ resource, element: input }) : E.right(input)), E.fold(validations => validations, () => []), validations => TE.right({ resource, validations })); | ||
const mockOrForward = (resource, input, config, validations) => { | ||
const inputValidation = (resource, input, config) => { | ||
const validations = lodash_1.compact([ | ||
config.checkSecurity ? components.validateSecurity({ resource, element: input }) : undefined, | ||
config.validateRequest ? components.validateInput({ resource, element: input }) : undefined, | ||
]); | ||
return pipeable_1.pipe(eitherSequence(validations), E.fold(function_1.identity, () => []), validations => E.right({ resource, validations })); | ||
}; | ||
const mockOrForward = (resource, data, config, validations) => { | ||
const produceOutput = isProxyConfig(config) | ||
? components.forward(input, config.upstream.href)(components.logger.child({ name: 'PROXY' })) | ||
? components.forward({ validations: config.errors ? validations : [], data }, config.upstream.href)(components.logger.child({ name: 'PROXY' })) | ||
: TE.fromEither(components.mock({ | ||
resource, | ||
input: { | ||
validations, | ||
data: input, | ||
}, | ||
input: { data, validations }, | ||
config: config.mock, | ||
@@ -46,10 +51,10 @@ })(components.logger.child({ name: 'NEGOTIATOR' }))); | ||
request: (input, resources, c) => { | ||
const config = lodash_1.defaults(c, defaultConfig); | ||
const config = lodash_2.defaults(c, defaultConfig); | ||
return pipeable_1.pipe(TE.fromEither(components.route({ resources, input })), TE.fold(error => { | ||
if (!config.errors && isProxyConfig(config)) { | ||
return pipeable_1.pipe(components.forward(input, config.upstream.href)(components.logger.child({ name: 'PROXY' })), TE.map(createWarningOutput)); | ||
return pipeable_1.pipe(components.forward({ data: input, validations: [] }, config.upstream.href)(components.logger.child({ name: 'PROXY' })), TE.map(createWarningOutput)); | ||
} | ||
else | ||
return TE.left(error); | ||
}, resource => pipeable_1.pipe(inputValidation(resource, input, config), TE.chain(({ resource, validations }) => mockOrForward(resource, input, config, validations)), TE.map(({ output, resource, validations: inputValidations }) => { | ||
}, resource => pipeable_1.pipe(TE.fromEither(inputValidation(resource, input, config)), TE.chain(({ resource, validations }) => mockOrForward(resource, input, config, validations)), TE.map(({ output, resource, validations: inputValidations }) => { | ||
const outputValidations = config.validateResponse | ||
@@ -56,0 +61,0 @@ ? pipeable_1.pipe(E.swap(components.validateOutput({ resource, element: output })), E.getOrElse(() => [])) |
@@ -37,3 +37,3 @@ import { IDiagnostic } from '@stoplight/types'; | ||
validateOutput: ValidatorFn<Resource, Output>; | ||
forward: (input: Input, baseUrl: string) => ReaderTaskEither<Logger, Error, Output>; | ||
forward: (input: IPrismInput<Input>, baseUrl: string) => ReaderTaskEither<Logger, Error, Output>; | ||
mock: (opts: { | ||
@@ -40,0 +40,0 @@ resource: Resource; |
{ | ||
"name": "@stoplight/prism-core", | ||
"version": "3.3.3", | ||
"version": "3.3.4", | ||
"main": "dist/index.js", | ||
@@ -21,3 +21,3 @@ "types": "dist/index.d.ts", | ||
"lodash": "^4.17.15", | ||
"pino": "^5.13.2", | ||
"pino": "^6.2.1", | ||
"tslib": "^1.10.0" | ||
@@ -28,3 +28,3 @@ }, | ||
}, | ||
"gitHead": "678acbdeaa92925cf80304910aa20740a144dc5d" | ||
"gitHead": "435278e18f248c6d15495af5dec0c214ce39a6d5" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18288
161
+ Addedfast-redact@3.5.0(transitive)
+ Addedpino@6.14.0(transitive)
+ Addedpino-std-serializers@3.2.0(transitive)
+ Addedprocess-warning@1.0.0(transitive)
+ Addedquick-format-unescaped@4.0.4(transitive)
+ Addedsonic-boom@1.4.1(transitive)
- Removedfast-redact@2.1.0(transitive)
- Removedpino@5.17.0(transitive)
- Removedpino-std-serializers@2.5.0(transitive)
- Removedquick-format-unescaped@3.0.3(transitive)
- Removedsonic-boom@0.7.7(transitive)
Updatedpino@^6.2.1