@stoplight/prism-cli
Advanced tools
| import * as E from 'fp-ts/Either'; | ||
| export declare const sequenceSEither: <E, NER extends Record<string, E.Either<E, any>>>(r: (keyof NER extends never ? never : NER) & Record<string, E.Either<E, any>>) => E.Either<E, { [K in keyof NER]: [NER[K]] extends [E.Either<any, infer A>] ? A : never; }>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.sequenceSEither = void 0; | ||
| const E = require("fp-ts/Either"); | ||
| const Apply_1 = require("fp-ts/Apply"); | ||
| exports.sequenceSEither = (0, Apply_1.sequenceS)(E.Apply); |
| import { CommandModule } from 'yargs'; | ||
| declare const mockCommand: CommandModule; | ||
| export default mockCommand; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const createServer_1 = require("../util/createServer"); | ||
| const sharedOptions_1 = require("./sharedOptions"); | ||
| const runner_1 = require("../util/runner"); | ||
| const mockCommand = { | ||
| describe: 'Start a mock server with the given document file', | ||
| command: 'mock <document>', | ||
| builder: yargs => yargs | ||
| .positional('document', { | ||
| description: 'Path to a document file. Can be both a file or a fetchable resource on the web.', | ||
| type: 'string', | ||
| }) | ||
| .options({ | ||
| ...sharedOptions_1.default, | ||
| dynamic: { | ||
| alias: 'd', | ||
| description: 'Dynamically generate examples.', | ||
| boolean: true, | ||
| default: false, | ||
| }, | ||
| 'json-schema-faker-fillProperties': { | ||
| description: 'Generate additional properties when using dynamic generation.', | ||
| default: undefined, | ||
| boolean: true, | ||
| }, | ||
| ignoreExamples: { | ||
| description: `Tell Prism to treat the spec as though it has no examples. When in static mode, | ||
| returns an example that has not been generated using json-schema-faker, but was | ||
| created by Prism. When in dynamic mode, this flag is ignored, since in dynamic mode, | ||
| examples are not consulted and json-schema-faker is used to generate a response based | ||
| on the schema defined in the spec`, | ||
| boolean: true, | ||
| default: false, | ||
| }, | ||
| seed: { | ||
| description: `Provide a seed so that Prism generates dynamic examples deterministically`, | ||
| string: true, | ||
| demandOption: true, | ||
| default: null | ||
| }, | ||
| }), | ||
| handler: async (parsedArgs) => { | ||
| parsedArgs.jsonSchemaFakerFillProperties = parsedArgs['json-schema-faker-fillProperties']; | ||
| const { multiprocess, dynamic, port, host, cors, document, errors, verboseLevel, ignoreExamples, seed, jsonSchemaFakerFillProperties } = parsedArgs; | ||
| const createPrism = multiprocess ? createServer_1.createMultiProcessPrism : createServer_1.createSingleProcessPrism; | ||
| const options = { | ||
| cors, | ||
| dynamic, | ||
| port, | ||
| host, | ||
| document, | ||
| multiprocess, | ||
| errors, | ||
| verboseLevel, | ||
| ignoreExamples, | ||
| seed, | ||
| jsonSchemaFakerFillProperties, | ||
| }; | ||
| await (0, runner_1.runPrismAndSetupWatcher)(createPrism, options); | ||
| }, | ||
| }; | ||
| exports.default = mockCommand; |
| import { CommandModule } from 'yargs'; | ||
| declare const proxyCommand: CommandModule; | ||
| export default proxyCommand; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const lodash_1 = require("lodash"); | ||
| const createServer_1 = require("../util/createServer"); | ||
| const sharedOptions_1 = require("./sharedOptions"); | ||
| const runner_1 = require("../util/runner"); | ||
| const proxyCommand = { | ||
| describe: 'Start a proxy server with the given document file', | ||
| command: 'proxy <document> <upstream>', | ||
| builder: yargs => yargs | ||
| .positional('document', { | ||
| description: 'Path to a document file. Can be both a file or a fetchable resource on the web.', | ||
| type: 'string', | ||
| }) | ||
| .positional('upstream', { | ||
| description: 'URL to a target server.', | ||
| type: 'string', | ||
| }) | ||
| .coerce('upstream', (value) => { | ||
| try { | ||
| return new URL(value); | ||
| } | ||
| catch (e) { | ||
| throw new Error(`Invalid upstream URL provided: ${value}`); | ||
| } | ||
| }) | ||
| .options({ | ||
| ...sharedOptions_1.default, | ||
| 'validate-request': { | ||
| description: 'Validate incoming HTTP requests.', | ||
| boolean: true, | ||
| default: true, | ||
| }, | ||
| 'upstream-proxy': { | ||
| description: 'If an http proxy is required to reach upstream, formatted as "{protocol}://[{user}[:{password}]@]{host}[:{port}]". eg "http://myUser:myPassword@proxy.example.com:1234"', | ||
| string: true, | ||
| }, | ||
| }), | ||
| handler: async (parsedArgs) => { | ||
| parsedArgs.validateRequest = parsedArgs['validate-request']; | ||
| const p = (0, lodash_1.pick)(parsedArgs, 'dynamic', 'cors', 'host', 'port', 'document', 'multiprocess', 'upstream', 'errors', 'validateRequest', 'verboseLevel', 'ignoreExamples', 'seed', 'upstreamProxy', 'jsonSchemaFakerFillProperties'); | ||
| const createPrism = p.multiprocess ? createServer_1.createMultiProcessPrism : createServer_1.createSingleProcessPrism; | ||
| await (0, runner_1.runPrismAndSetupWatcher)(createPrism, p); | ||
| }, | ||
| }; | ||
| exports.default = proxyCommand; |
| import { Dictionary } from '@stoplight/types'; | ||
| import { Options } from 'yargs'; | ||
| declare const sharedOptions: Dictionary<Options>; | ||
| export default sharedOptions; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const pino = require("pino"); | ||
| const sharedOptions = { | ||
| port: { | ||
| alias: 'p', | ||
| description: 'Port that Prism will run on.', | ||
| default: 4010, | ||
| demandOption: true, | ||
| number: true, | ||
| }, | ||
| host: { | ||
| alias: 'h', | ||
| description: 'Host that Prism will listen to.', | ||
| default: '127.0.0.1', | ||
| demandOption: true, | ||
| string: true, | ||
| }, | ||
| cors: { | ||
| description: 'Enables CORS headers.', | ||
| boolean: true, | ||
| default: true, | ||
| }, | ||
| multiprocess: { | ||
| alias: 'm', | ||
| description: 'Forks the http server from the CLI for faster log processing.', | ||
| boolean: true, | ||
| default: process.env.NODE_ENV === 'production', | ||
| }, | ||
| errors: { | ||
| description: 'Specifies whether request/response violations marked as errors will produce an error response', | ||
| required: true, | ||
| boolean: true, | ||
| default: false, | ||
| }, | ||
| verboseLevel: { | ||
| alias: 'v', | ||
| description: 'Turns on verbose logging.', | ||
| default: 'info', | ||
| demandOption: true, | ||
| choices: Object.keys(pino.levels.values).concat('silent'), | ||
| }, | ||
| }; | ||
| exports.default = sharedOptions; |
| import * as chalk from 'chalk'; | ||
| export declare const LOG_COLOR_MAP: { | ||
| CLI: { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| 'HTTP SERVER': { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| NEGOTIATOR: { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| VALIDATOR: { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| CALLBACK: { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| PROXY: { | ||
| index: number; | ||
| color: chalk.Chalk; | ||
| }; | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.LOG_COLOR_MAP = void 0; | ||
| const chalk = require("chalk"); | ||
| exports.LOG_COLOR_MAP = { | ||
| CLI: { index: 0, color: chalk.bgWhiteBright }, | ||
| 'HTTP SERVER': { index: 0, color: chalk.bgYellowBright }, | ||
| NEGOTIATOR: { index: 1, color: chalk.bgCyanBright }, | ||
| VALIDATOR: { index: 1, color: chalk.bgGreenBright }, | ||
| CALLBACK: { index: 1, color: chalk.bgBlue }, | ||
| PROXY: { index: 1, color: chalk.bgMagentaBright }, | ||
| }; |
| export declare function configureExtensionsUserProvided(specFilePathOrObject: string | object, cliParamOptions: { | ||
| [option: string]: any; | ||
| }): Promise<void>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.configureExtensionsUserProvided = void 0; | ||
| const $RefParser = require("@stoplight/json-schema-ref-parser"); | ||
| const json_1 = require("@stoplight/json"); | ||
| const lodash_1 = require("lodash"); | ||
| const json_schema_faker_1 = require("json-schema-faker"); | ||
| const prism_http_1 = require("@stoplight/prism-http"); | ||
| async function configureExtensionsUserProvided(specFilePathOrObject, cliParamOptions) { | ||
| const result = (0, json_1.decycle)(await new $RefParser().dereference(specFilePathOrObject)); | ||
| (0, prism_http_1.resetJSONSchemaGenerator)(); | ||
| (0, lodash_1.forOwn)((0, lodash_1.get)(result, 'x-json-schema-faker', {}), (value, option) => { | ||
| setFakerValue(option, value); | ||
| }); | ||
| for (const param in cliParamOptions) { | ||
| if (cliParamOptions[param] !== undefined) { | ||
| setFakerValue(param, cliParamOptions[param]); | ||
| } | ||
| } | ||
| } | ||
| exports.configureExtensionsUserProvided = configureExtensionsUserProvided; | ||
| function setFakerValue(option, value) { | ||
| if (option === 'locale') { | ||
| return json_schema_faker_1.JSONSchemaFaker.locate('faker').setLocale(value); | ||
| } | ||
| json_schema_faker_1.JSONSchemaFaker.option((0, lodash_1.camelCase)(option), value); | ||
| } |
| #!/usr/bin/env node | ||
| export {}; |
| #!/usr/bin/env node | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const yargs = require("yargs"); | ||
| const mock_1 = require("./commands/mock"); | ||
| const proxy_1 = require("./commands/proxy"); | ||
| yargs | ||
| .scriptName('prism') | ||
| .version() | ||
| .help(true) | ||
| .strict() | ||
| .wrap(yargs.terminalWidth()) | ||
| .command(mock_1.default) | ||
| .command(proxy_1.default) | ||
| .demandCommand(1, '').argv; |
| export { getHttpOperationsFromSpec } from '@stoplight/prism-http'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getHttpOperationsFromSpec = void 0; | ||
| var prism_http_1 = require("@stoplight/prism-http"); | ||
| Object.defineProperty(exports, "getHttpOperationsFromSpec", { enumerable: true, get: function () { return prism_http_1.getHttpOperationsFromSpec; } }); |
| import { Dictionary } from '@stoplight/types'; | ||
| export type ValuesTransformer = (values: Dictionary<unknown>) => Dictionary<string | string[] | object>; | ||
| export declare const PRE_PARAM_VALUE_TAG = "~pre~"; | ||
| export declare const POST_PARAM_VALUE_TAG = "~post~"; | ||
| export declare const transformPathParamsValues: (path: string, transform: (aString: string) => string) => string; | ||
| export declare const attachTagsToParamsValues: ValuesTransformer; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.attachTagsToParamsValues = exports.transformPathParamsValues = exports.POST_PARAM_VALUE_TAG = exports.PRE_PARAM_VALUE_TAG = void 0; | ||
| const lodash_1 = require("lodash"); | ||
| exports.PRE_PARAM_VALUE_TAG = '~pre~'; | ||
| exports.POST_PARAM_VALUE_TAG = '~post~'; | ||
| const taggedParamsValues = new RegExp(`${exports.PRE_PARAM_VALUE_TAG}(.*?)${exports.POST_PARAM_VALUE_TAG}`, 'gm'); | ||
| const transformPathParamsValues = (path, transform) => { | ||
| return path.replace(taggedParamsValues, transform('$1')); | ||
| }; | ||
| exports.transformPathParamsValues = transformPathParamsValues; | ||
| const attachTagsToParamsValues = values => { | ||
| return (0, lodash_1.mapValues)(values, attachPrePostTags); | ||
| }; | ||
| exports.attachTagsToParamsValues = attachTagsToParamsValues; | ||
| const attachPrePostTags = (paramValue) => { | ||
| if ((0, lodash_1.isArray)(paramValue)) { | ||
| return paramValue.map(v => `${exports.PRE_PARAM_VALUE_TAG}${v}${exports.POST_PARAM_VALUE_TAG}`); | ||
| } | ||
| else if (paramValue && typeof paramValue === 'object') { | ||
| for (const key of Object.keys(paramValue)) { | ||
| paramValue[key] = `${exports.PRE_PARAM_VALUE_TAG}${paramValue[key]}${exports.POST_PARAM_VALUE_TAG}`; | ||
| } | ||
| return paramValue; | ||
| } | ||
| else { | ||
| return `${exports.PRE_PARAM_VALUE_TAG}${paramValue}${exports.POST_PARAM_VALUE_TAG}`; | ||
| } | ||
| }; |
| import { CreatePrism } from './runner'; | ||
| declare const createMultiProcessPrism: CreatePrism; | ||
| declare const createSingleProcessPrism: CreatePrism; | ||
| type CreateBaseServerOptions = { | ||
| dynamic: boolean; | ||
| cors: boolean; | ||
| host: string; | ||
| port: number; | ||
| document: string; | ||
| multiprocess: boolean; | ||
| errors: boolean; | ||
| verboseLevel: string; | ||
| ignoreExamples: boolean; | ||
| seed: string; | ||
| jsonSchemaFakerFillProperties: boolean; | ||
| }; | ||
| export interface CreateProxyServerOptions extends CreateBaseServerOptions { | ||
| upstream: URL; | ||
| validateRequest: boolean; | ||
| upstreamProxy: string | undefined; | ||
| } | ||
| export type CreateMockServerOptions = CreateBaseServerOptions; | ||
| export { createMultiProcessPrism, createSingleProcessPrism }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createSingleProcessPrism = exports.createMultiProcessPrism = void 0; | ||
| const prism_core_1 = require("@stoplight/prism-core"); | ||
| const prism_http_server_1 = require("@stoplight/prism-http-server"); | ||
| const chalk = require("chalk"); | ||
| const node_cluster_1 = require("node:cluster"); | ||
| const E = require("fp-ts/Either"); | ||
| const function_1 = require("fp-ts/function"); | ||
| const pino = require("pino"); | ||
| const signale = require("signale"); | ||
| const split = require("split2"); | ||
| const stream_1 = require("stream"); | ||
| const options_1 = require("../const/options"); | ||
| const prism_http_1 = require("@stoplight/prism-http"); | ||
| const paths_1 = require("./paths"); | ||
| const colorizer_1 = require("./colorizer"); | ||
| const extensions_1 = require("../extensions"); | ||
| const jsonrepair_1 = require("jsonrepair"); | ||
| signale.config({ displayTimestamp: true }); | ||
| const cliSpecificLoggerOptions = { | ||
| customLevels: { start: pino.levels.values['info'] + 1 }, | ||
| level: 'start', | ||
| formatters: { | ||
| level: level => ({ level }), | ||
| }, | ||
| }; | ||
| const createMultiProcessPrism = async (options) => { | ||
| if (node_cluster_1.default.isPrimary) { | ||
| node_cluster_1.default.setupPrimary({ silent: true }); | ||
| signale.await({ prefix: chalk.bgWhiteBright.black('[CLI]'), message: 'Starting Prism…' }); | ||
| const worker = node_cluster_1.default.fork(); | ||
| if (worker.process.stdout) { | ||
| pipeOutputToSignale(worker.process.stdout); | ||
| } | ||
| return; | ||
| } | ||
| else { | ||
| const logInstance = (0, prism_core_1.createLogger)('CLI', { ...cliSpecificLoggerOptions, level: options.verboseLevel }); | ||
| return createPrismServerWithLogger(options, logInstance).catch((e) => { | ||
| logInstance.fatal(e.message); | ||
| node_cluster_1.default.worker.kill(); | ||
| throw e; | ||
| }); | ||
| } | ||
| }; | ||
| exports.createMultiProcessPrism = createMultiProcessPrism; | ||
| const createSingleProcessPrism = options => { | ||
| signale.await({ prefix: chalk.bgWhiteBright.black('[CLI]'), message: 'Starting Prism…' }); | ||
| const logStream = new stream_1.PassThrough(); | ||
| const logInstance = (0, prism_core_1.createLogger)('CLI', { ...cliSpecificLoggerOptions, level: options.verboseLevel }, logStream); | ||
| pipeOutputToSignale(logStream); | ||
| return createPrismServerWithLogger(options, logInstance).catch((e) => { | ||
| logInstance.fatal(e.message); | ||
| throw e; | ||
| }); | ||
| }; | ||
| exports.createSingleProcessPrism = createSingleProcessPrism; | ||
| async function createPrismServerWithLogger(options, logInstance) { | ||
| const operations = await (0, prism_http_1.getHttpOperationsFromSpec)(options.document); | ||
| const jsonSchemaFakerCliParams = { | ||
| ['fillProperties']: options.jsonSchemaFakerFillProperties, | ||
| }; | ||
| await (0, extensions_1.configureExtensionsUserProvided)(options.document, jsonSchemaFakerCliParams); | ||
| if (operations.length === 0) { | ||
| throw new Error('No operations found in the current file.'); | ||
| } | ||
| const validateRequest = isProxyServerOptions(options) ? options.validateRequest : true; | ||
| const shared = { | ||
| validateRequest, | ||
| validateResponse: true, | ||
| checkSecurity: true, | ||
| errors: options.errors, | ||
| upstreamProxy: undefined, | ||
| mock: { dynamic: options.dynamic, ignoreExamples: options.ignoreExamples, seed: options.seed }, | ||
| }; | ||
| const config = isProxyServerOptions(options) | ||
| ? { | ||
| ...shared, | ||
| isProxy: true, | ||
| upstream: options.upstream, | ||
| upstreamProxy: options.upstreamProxy, | ||
| } | ||
| : { ...shared, isProxy: false }; | ||
| const server = (0, prism_http_server_1.createServer)(operations, { | ||
| cors: options.cors, | ||
| config, | ||
| components: { logger: logInstance.child({ name: 'HTTP SERVER' }) }, | ||
| }); | ||
| const address = await server.listen(options.port, options.host); | ||
| operations.forEach(resource => { | ||
| const path = (0, function_1.pipe)((0, paths_1.createExamplePath)(resource, colorizer_1.attachTagsToParamsValues), E.getOrElse(() => resource.path)); | ||
| logInstance.info(`${resource.method.toUpperCase().padEnd(10)} ${address}${(0, colorizer_1.transformPathParamsValues)(path, chalk.bold.cyan)}`); | ||
| }); | ||
| logInstance.start(`Prism is listening on ${address}`); | ||
| return server; | ||
| } | ||
| function pipeOutputToSignale(stream) { | ||
| function constructPrefix(logLine) { | ||
| const logOptions = options_1.LOG_COLOR_MAP[logLine.name]; | ||
| const prefix = ' ' | ||
| .repeat(logOptions.index + (logLine.offset || 0)) | ||
| .concat(logOptions.color.black(`[${logLine.name}]`)); | ||
| return logLine.input | ||
| ? prefix.concat(' ' + chalk.bold.white(`${logLine.input.method} ${logLine.input.url.path}`)) | ||
| : prefix; | ||
| } | ||
| stream | ||
| .pipe(split(chunk => { | ||
| try { | ||
| const repairedJson = (0, jsonrepair_1.jsonrepair)(chunk); | ||
| return JSON.parse(repairedJson); | ||
| } | ||
| catch (error) { | ||
| signale.await({ prefix: chalk.bgWhiteBright.black('[CLI]'), message: 'Invalid JSON and unable to correct' }); | ||
| } | ||
| })) | ||
| .on('data', (logLine) => { | ||
| signale[logLine.level]({ prefix: constructPrefix(logLine), message: logLine.msg }); | ||
| }); | ||
| } | ||
| function isProxyServerOptions(options) { | ||
| return 'upstream' in options; | ||
| } |
| import { IHttpOperation } from '@stoplight/types'; | ||
| import * as E from 'fp-ts/Either'; | ||
| import { ValuesTransformer } from './colorizer'; | ||
| export declare function createExamplePath(operation: IHttpOperation, transformValues?: ValuesTransformer): E.Either<Error, string>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createExamplePath = void 0; | ||
| const prism_http_1 = require("@stoplight/prism-http"); | ||
| const types_1 = require("@stoplight/types"); | ||
| const A = require("fp-ts/Array"); | ||
| const E = require("fp-ts/Either"); | ||
| const O = require("fp-ts/Option"); | ||
| const ROA = require("fp-ts/ReadonlyArray"); | ||
| const function_1 = require("fp-ts/function"); | ||
| const lodash_1 = require("lodash"); | ||
| const uri_template_lite_1 = require("uri-template-lite"); | ||
| const combinators_1 = require("../combinators"); | ||
| function createExamplePath(operation, transformValues = lodash_1.identity) { | ||
| return (0, function_1.pipe)(E.Do, E.bind('pathData', () => generateTemplateAndValuesForPathParams(operation)), E.bind('queryData', ({ pathData }) => generateTemplateAndValuesForQueryParams(pathData.template, operation)), E.map(({ pathData, queryData }) => uri_template_lite_1.URI.expand(queryData.template, transformValues({ ...pathData.values, ...queryData.values }))), E.map(path => path.replace(/\?$/, ''))); | ||
| } | ||
| exports.createExamplePath = createExamplePath; | ||
| function generateParamValue(spec) { | ||
| return (0, function_1.pipe)((0, prism_http_1.generateHttpParam)(spec), E.fromOption(() => new Error(`Cannot generate value for: ${spec.name}`)), E.chain(value => { | ||
| switch (spec.style) { | ||
| case types_1.HttpParamStyles.DeepObject: | ||
| return (0, function_1.pipe)(value, E.fromPredicate((value) => typeof value === 'string' || typeof value === 'object', () => new Error('Expected string parameter')), E.map(value => (0, prism_http_1.serializeWithDeepObjectStyle)(spec.name, value))); | ||
| case types_1.HttpParamStyles.PipeDelimited: | ||
| return (0, function_1.pipe)(value, E.fromPredicate(Array.isArray, () => new Error('Pipe delimited style is only applicable to array parameter')), E.map(v => (0, prism_http_1.serializeWithPipeDelimitedStyle)(spec.name, v, spec.explode))); | ||
| case types_1.HttpParamStyles.SpaceDelimited: | ||
| return (0, function_1.pipe)(value, E.fromPredicate(Array.isArray, () => new Error('Space delimited style is only applicable to array parameter')), E.map(v => (0, prism_http_1.serializeWithSpaceDelimitedStyle)(spec.name, v, spec.explode))); | ||
| default: | ||
| return E.right(value); | ||
| } | ||
| })); | ||
| } | ||
| function generateParamValues(specs) { | ||
| return (0, function_1.pipe)(specs, A.map(O.fromNullable), A.compact, E.traverseArray(spec => (0, function_1.pipe)(generateParamValue(spec), E.map(value => [encodeURI(spec.name), value]), E.map(O.fromPredicate(([_, value]) => value !== null)))), E.map(ROA.compact), E.map(lodash_1.fromPairs)); | ||
| } | ||
| function generateTemplateAndValuesForPathParams(operation) { | ||
| var _a; | ||
| const specs = ((_a = operation.request) === null || _a === void 0 ? void 0 : _a.path) || []; | ||
| return (0, combinators_1.sequenceSEither)({ | ||
| values: generateParamValues(specs), | ||
| template: createPathUriTemplate(operation.path, specs), | ||
| }); | ||
| } | ||
| function generateTemplateAndValuesForQueryParams(template, operation) { | ||
| var _a; | ||
| const specs = ((_a = operation.request) === null || _a === void 0 ? void 0 : _a.query) || []; | ||
| return (0, function_1.pipe)(generateParamValues(specs), E.map(values => ({ template: createQueryUriTemplate(template, specs), values }))); | ||
| } | ||
| function createPathUriTemplate(inputPath, specs) { | ||
| return (0, function_1.pipe)(specs.filter(spec => spec.required !== false), E.traverseArray(spec => (0, function_1.pipe)(createParamUriTemplate(spec.name, spec.style || types_1.HttpParamStyles.Simple, spec.explode || false), E.map(param => ({ param, name: spec.name })))), E.map(values => values.reduce((acc, current) => acc.replace(`{${current.name}}`, current.param), inputPath))); | ||
| } | ||
| function createParamUriTemplate(name, style, explode) { | ||
| const starOrVoid = explode ? '*' : ''; | ||
| switch (style) { | ||
| case types_1.HttpParamStyles.Simple: | ||
| return E.right(`{${name}${starOrVoid}}`); | ||
| case types_1.HttpParamStyles.Label: | ||
| return E.right(`{.${name}${starOrVoid}}`); | ||
| case types_1.HttpParamStyles.Matrix: | ||
| return E.right(`{;${name}${starOrVoid}}`); | ||
| default: | ||
| return E.left(new Error(`Unsupported parameter style: ${style}`)); | ||
| } | ||
| } | ||
| function createQueryUriTemplate(path, specs) { | ||
| const formSpecs = specs | ||
| .filter(spec => (spec.style || types_1.HttpParamStyles.Form) === types_1.HttpParamStyles.Form) | ||
| .map(spec => { | ||
| spec.name = encodeURI(spec.name); | ||
| if (spec.explode === undefined) { | ||
| spec.explode = true; | ||
| } | ||
| return spec; | ||
| }); | ||
| const formExplodedParams = formSpecs | ||
| .filter(spec => spec.required !== false) | ||
| .filter(spec => spec.explode) | ||
| .map(spec => spec.name) | ||
| .join(','); | ||
| const formImplodedParams = formSpecs | ||
| .filter(spec => spec.required !== false) | ||
| .filter(spec => !spec.explode) | ||
| .map(spec => spec.name) | ||
| .join(','); | ||
| const restParams = specs | ||
| .filter(spec => spec.required !== false) | ||
| .filter(spec => [types_1.HttpParamStyles.DeepObject, types_1.HttpParamStyles.SpaceDelimited, types_1.HttpParamStyles.PipeDelimited].includes(spec.style)) | ||
| .map(spec => spec.name) | ||
| .map(name => `{+${name}}`) | ||
| .join('&'); | ||
| if (formExplodedParams) { | ||
| path += `{?${formExplodedParams}*}`; | ||
| } | ||
| if (formImplodedParams) { | ||
| path += `{${formExplodedParams ? '&' : '?'}${formImplodedParams}}`; | ||
| } | ||
| if (restParams) { | ||
| path += `${formExplodedParams || formImplodedParams ? '&' : '?'}${restParams}`; | ||
| } | ||
| return path; | ||
| } |
| import type { IPrismHttpServer } from '@stoplight/prism-http-server/src/types'; | ||
| import { CreateMockServerOptions } from './createServer'; | ||
| export type CreatePrism = (options: CreateMockServerOptions) => Promise<IPrismHttpServer | void>; | ||
| export declare function runPrismAndSetupWatcher(createPrism: CreatePrism, options: CreateMockServerOptions): Promise<IPrismHttpServer | void>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.runPrismAndSetupWatcher = void 0; | ||
| const chokidar = require("chokidar"); | ||
| const os = require("os"); | ||
| const prism_http_1 = require("@stoplight/prism-http"); | ||
| function runPrismAndSetupWatcher(createPrism, options) { | ||
| return createPrism(options).then(possibleServer => { | ||
| if (possibleServer) { | ||
| let server = possibleServer; | ||
| const watcher = chokidar.watch(options.document, { | ||
| persistent: os.platform() === 'darwin', | ||
| disableGlobbing: true, | ||
| awaitWriteFinish: { stabilityThreshold: 500, pollInterval: 100 }, | ||
| }); | ||
| watcher.on('change', () => { | ||
| server.logger.info('Restarting Prism...'); | ||
| (0, prism_http_1.getHttpOperationsFromSpec)(options.document) | ||
| .then(operations => { | ||
| if (operations.length === 0) { | ||
| server.logger.info('No operations found in the current file, continuing with the previously loaded spec.'); | ||
| } | ||
| else { | ||
| return server | ||
| .close() | ||
| .then(() => { | ||
| server.logger.info('Loading the updated operations...'); | ||
| return createPrism(options); | ||
| }) | ||
| .then(newServer => { | ||
| if (newServer) { | ||
| server = newServer; | ||
| } | ||
| }); | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| server.logger.warn('Something went terribly wrong, trying to start Prism with the original document.'); | ||
| return server | ||
| .close() | ||
| .then(() => createPrism(options)) | ||
| .catch(() => process.exit(1)); | ||
| }); | ||
| }); | ||
| return new Promise(resolve => watcher.once('ready', () => resolve(server))); | ||
| } | ||
| }); | ||
| } | ||
| exports.runPrismAndSetupWatcher = runPrismAndSetupWatcher; |
+5
-5
| { | ||
| "name": "@stoplight/prism-cli", | ||
| "version": "5.15.9", | ||
| "version": "5.15.10", | ||
| "author": "Stoplight <support@stoplight.io>", | ||
@@ -12,5 +12,5 @@ "bin": { | ||
| "@stoplight/json-schema-ref-parser": "10.0.0", | ||
| "@stoplight/prism-core": "^5.15.9", | ||
| "@stoplight/prism-http": "^5.15.9", | ||
| "@stoplight/prism-http-server": "^5.15.9", | ||
| "@stoplight/prism-core": "^5.15.10", | ||
| "@stoplight/prism-http": "^5.15.10", | ||
| "@stoplight/prism-http-server": "^5.15.10", | ||
| "@stoplight/types": "^14.1.0", | ||
@@ -58,3 +58,3 @@ "chalk": "^4.1.2", | ||
| }, | ||
| "gitHead": "e1ee14d3ac07fa3678a2d61bf635923df37d8d86" | ||
| "gitHead": "cd599a52d1725f622f464e0c7325de8664e8bc88" | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
39406
205.09%27
800%605
Infinity%2
Infinity%