Socket
Socket
Sign inDemoInstall

mockttp

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockttp - npm Package Compare versions

Comparing version 0.8.1 to 0.9.0

custom-typings/asynciterator.d.ts

7

dist/rules/handlers.d.ts

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

}
export interface SerializedCallbackHandlerData extends SerializedStreamBackedHandlerData {
name?: string;
}
export declare class CallbackHandlerData extends Serializable {

@@ -43,4 +46,4 @@ callback: (request: CompletedRequest) => CallbackHandlerResult | Promise<CallbackHandlerResult>;

};
serialize(options?: SerializationOptions): SerializedStreamBackedHandlerData;
static deserialize({topicId}: SerializedStreamBackedHandlerData, options?: SerializationOptions): CallbackHandlerData;
serialize(options?: SerializationOptions): SerializedCallbackHandlerData;
static deserialize({topicId, name}: SerializedCallbackHandlerData, options?: SerializationOptions): CallbackHandlerData;
}

@@ -47,0 +50,0 @@ export interface SerializedStreamHandlerData extends SerializedStreamBackedHandlerData {

@@ -200,6 +200,6 @@ "use strict";

}); });
return { type: this.type, topicId: topicId };
return { type: this.type, topicId: topicId, name: this.callback.name };
};
CallbackHandlerData.deserialize = function (_a, options) {
var topicId = _a.topicId;
var topicId = _a.topicId, name = _a.name;
if (!options || !options.clientStream) {

@@ -220,5 +220,3 @@ throw new Error('Client-side callback handlers require a streaming client connection.');

clientStream.on('data', responseListener);
// Call the client's callback (via stream), and save a handler on our end for
// the response that comes back.
return new CallbackHandlerData(function (request) {
var rpcCallback = function (request) {
return new Promise(function (resolve, reject) {

@@ -241,3 +239,8 @@ var requestId = uuid();

});
});
};
// Pass across the name from the real callback
Object.defineProperty(rpcCallback, "name", { value: name });
// Call the client's callback (via stream), and save a handler on our end for
// the response that comes back.
return new CallbackHandlerData(rpcCallback);
};

@@ -244,0 +247,0 @@ return CallbackHandlerData;

@@ -46,2 +46,14 @@ import { OngoingRequest, Method } from "../types";

}
export declare class QueryMatcherData extends Serializable {
queryObject: {
[key: string]: string | number;
};
readonly type: 'query';
constructor(queryObject: {
[key: string]: string | number;
});
buildMatcher(): ((request: OngoingRequest) => boolean) & {
explain: () => string;
};
}
export declare class FormDataMatcherData extends Serializable {

@@ -67,3 +79,3 @@ formData: {

}
export declare type MatcherData = (WildcardMatcherData | MethodMatcherData | SimplePathMatcherData | RegexPathMatcherData | HeaderMatcherData | FormDataMatcherData | RawBodyMatcherData);
export declare type MatcherData = (WildcardMatcherData | MethodMatcherData | SimplePathMatcherData | RegexPathMatcherData | HeaderMatcherData | QueryMatcherData | FormDataMatcherData | RawBodyMatcherData);
export declare const MatcherDataLookup: {

@@ -75,2 +87,3 @@ 'wildcard': typeof WildcardMatcherData;

'header': typeof HeaderMatcherData;
'query': typeof QueryMatcherData;
'form-data': typeof FormDataMatcherData;

@@ -77,0 +90,0 @@ 'raw-body': typeof RawBodyMatcherData;

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

})();
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -53,5 +57,7 @@ return new (P || (P = Promise))(function (resolve, reject) {

var _ = require("lodash");
var url = require("url");
var types_1 = require("../types");
var serialization_1 = require("../util/serialization");
var normalize_url_1 = require("../util/normalize-url");
var common_tags_1 = require("common-tags");
var WildcardMatcherData = /** @class */ (function (_super) {

@@ -93,2 +99,7 @@ __extends(WildcardMatcherData, _super);

_this.type = 'simple-path';
var _a = url.parse(_this.path, true), search = _a.search, query = _a.query;
if (search) {
throw new Error(common_tags_1.stripIndent(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n Tried to match a path that contained a query (", "). ", "To match query parameters, add .withQuery(", ") instead.\n "], ["\n Tried to match a path that contained a query (", "). ",
"To match query parameters, add .withQuery(", ") instead.\n "])), search, '', JSON.stringify(query)));
}
return _this;

@@ -140,2 +151,21 @@ }

exports.HeaderMatcherData = HeaderMatcherData;
var QueryMatcherData = /** @class */ (function (_super) {
__extends(QueryMatcherData, _super);
function QueryMatcherData(queryObject) {
var _this = _super.call(this) || this;
_this.queryObject = queryObject;
_this.type = 'query';
return _this;
}
QueryMatcherData.prototype.buildMatcher = function () {
var _this = this;
var expectedQuery = _.mapValues(this.queryObject, function (v) { return v.toString(); });
return _.assign(function (request) {
var query = url.parse(request.url, true).query;
return _.isMatch(query, expectedQuery);
}, { explain: function () { return "with a query including " + JSON.stringify(_this.queryObject); } });
};
return QueryMatcherData;
}(serialization_1.Serializable));
exports.QueryMatcherData = QueryMatcherData;
var FormDataMatcherData = /** @class */ (function (_super) {

@@ -198,2 +228,3 @@ __extends(FormDataMatcherData, _super);

'header': HeaderMatcherData,
'query': QueryMatcherData,
'form-data': FormDataMatcherData,

@@ -237,2 +268,3 @@ 'raw-body': RawBodyMatcherData

;
var templateObject_1;
//# sourceMappingURL=matchers.js.map

@@ -42,2 +42,8 @@ /// <reference types="node" />

/**
* Match only requests that include the given query parameters
*/
withQuery(query: {
[key: string]: string | number;
}): MockRuleBuilder;
/**
* Match only requests whose bodies include the given form data

@@ -44,0 +50,0 @@ */

@@ -95,2 +95,9 @@ "use strict";

/**
* Match only requests that include the given query parameters
*/
MockRuleBuilder.prototype.withQuery = function (query) {
this.matchers.push(new matchers_1.QueryMatcherData(query));
return this;
};
/**
* Match only requests whose bodies include the given form data

@@ -97,0 +104,0 @@ */

@@ -0,1 +1,2 @@

/// <reference path="../../custom-typings/asynciterator.d.ts" />
export interface StandaloneServerOptions {

@@ -2,0 +3,0 @@ debug?: boolean;

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

Object.defineProperty(exports, "__esModule", { value: true });
/// <reference path="../../custom-typings/asynciterator.d.ts" />
var path = require("path");

@@ -43,0 +44,0 @@ var fs = require("../util/fs");

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

stripWWW: false,
removeQueryParameters: [],
removeTrailingSlash: false,
removeQueryParameters: [/.*/g],
});

@@ -13,0 +14,0 @@ }

@@ -6,6 +6,8 @@ /// <reference types="node" />

buffer: Buffer;
text: undefined;
json: undefined;
formData: undefined;
text: string | undefined;
json: object | undefined;
formData: {
[key: string]: string;
} | undefined;
};
}>;
{
"name": "mockttp",
"version": "0.8.1",
"version": "0.9.0",
"description": "Mock HTTP server for testing HTTP clients and stubbing webservices",

@@ -60,3 +60,2 @@ "main": "dist/main.js",

"@types/cors": "^2.8.1",
"@types/es6-promise": "0.0.32",
"@types/graphql": "^0.10.2",

@@ -78,3 +77,3 @@ "@types/lodash": "^4.14.37",

"chai-as-promised": "^6.0.0",
"chai-fetch": "^0.3.0",
"chai-fetch": "^0.3.1",
"http-proxy-agent": "^2.0.0",

@@ -81,0 +80,0 @@ "karma": "^1.7.1",

@@ -45,3 +45,3 @@ /**

response.writeHead(this.status, this.headers);
if (isSerializedBuffer(this.data)) {

@@ -54,3 +54,3 @@ this.data = new Buffer(<any> this.data);

`respond with status ${this.status}` +
(this.headers ? `, headers ${JSON.stringify(this.headers)}` : "") +
(this.headers ? `, headers ${JSON.stringify(this.headers)}` : "") +
(this.data ? ` and body "${this.data}"` : "")

@@ -79,2 +79,6 @@ });

export interface SerializedCallbackHandlerData extends SerializedStreamBackedHandlerData {
name?: string;
}
interface CallbackRequestMessage extends StreamMessage {

@@ -131,3 +135,3 @@ requestId: string;

serialize(options?: SerializationOptions): SerializedStreamBackedHandlerData {
serialize(options?: SerializationOptions): SerializedCallbackHandlerData {
if (!options || !options.clientStream) {

@@ -168,6 +172,6 @@ throw new Error('Client-side callback handlers require a streaming client connection.');

return { type: this.type, topicId };
return { type: this.type, topicId, name: this.callback.name };
}
static deserialize({ topicId }: SerializedStreamBackedHandlerData, options?: SerializationOptions): CallbackHandlerData {
static deserialize({ topicId, name }: SerializedCallbackHandlerData, options?: SerializationOptions): CallbackHandlerData {
if (!options || !options.clientStream) {

@@ -181,3 +185,3 @@ throw new Error('Client-side callback handlers require a streaming client connection.');

const responseListener = (streamMsg: string | Buffer) => {
const responseListener = (streamMsg: string | Buffer) => {
let clientResponse: CallbackResponseMessage = JSON.parse(streamMsg.toString());

@@ -195,5 +199,3 @@ let { requestId } = clientResponse;

// Call the client's callback (via stream), and save a handler on our end for
// the response that comes back.
return new CallbackHandlerData((request) => {
const rpcCallback = (request: CompletedRequest) => {
return new Promise((resolve, reject) => {

@@ -216,3 +218,9 @@ let requestId = uuid();

});
});
};
// Pass across the name from the real callback
Object.defineProperty(rpcCallback, "name", { value: name });
// Call the client's callback (via stream), and save a handler on our end for
// the response that comes back.
return new CallbackHandlerData(rpcCallback);
}

@@ -287,3 +295,3 @@ }

_.isBuffer(chunk) ? { type: 'buffer', value: chunk.toString('base64') } :
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk)) ? { type: 'arraybuffer', value: encodeBase64(chunk) } :
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk)) ? { type: 'arraybuffer', value: encodeBase64(<any> chunk) } :
_.isNil(chunk) && { type: 'nil' };

@@ -341,4 +349,4 @@

transform: function (this: Transform, chunk, encoding, callback) {
let clientMessage: StreamHandlerMessage = JSON.parse(chunk.toString());
let clientMessage: StreamHandlerMessage = JSON.parse(chunk.toString());
const { topicId, event, content } = clientMessage;

@@ -372,3 +380,3 @@

});
return new StreamHandlerData(

@@ -375,0 +383,0 @@ handlerData.status,

@@ -5,3 +5,4 @@ /**

import * as _ from "lodash";
import * as _ from 'lodash';
import * as url from 'url';

@@ -13,2 +14,3 @@ import { OngoingRequest, Method } from "../types";

import normalizeUrl from "../util/normalize-url";
import { stripIndent } from 'common-tags';

@@ -34,3 +36,3 @@ export class WildcardMatcherData extends Serializable {

}
buildMatcher() {

@@ -52,2 +54,10 @@ let methodName = Method[this.method];

super();
let { search, query } = url.parse(this.path, true);
if (search) {
throw new Error(stripIndent`
Tried to match a path that contained a query (${search}). ${''
}To match query parameters, add .withQuery(${JSON.stringify(query)}) instead.
`);
}
}

@@ -99,2 +109,23 @@

export class QueryMatcherData extends Serializable {
readonly type: 'query' = 'query';
constructor(
public queryObject: { [key: string]: string | number },
) {
super();
}
buildMatcher() {
const expectedQuery = _.mapValues(this.queryObject, (v) => v.toString());
return _.assign(
(request: OngoingRequest) => {
let { query } = url.parse(request.url, true);
return _.isMatch(query, expectedQuery);
}
, { explain: () => `with a query including ${JSON.stringify(this.queryObject)}` });
}
}
export class FormDataMatcherData extends Serializable {

@@ -140,2 +171,3 @@ readonly type: 'form-data' = 'form-data';

HeaderMatcherData |
QueryMatcherData |
FormDataMatcherData |

@@ -151,2 +183,3 @@ RawBodyMatcherData

'header': HeaderMatcherData,
'query': QueryMatcherData,
'form-data': FormDataMatcherData,

@@ -153,0 +186,0 @@ 'raw-body': RawBodyMatcherData

@@ -27,3 +27,3 @@ /**

import {
MatcherData,
MatcherData,
MethodMatcherData,

@@ -33,2 +33,3 @@ SimplePathMatcherData,

HeaderMatcherData,
QueryMatcherData,
FormDataMatcherData,

@@ -39,3 +40,3 @@ RawBodyMatcherData,

import {
import {
SimpleHandlerData,

@@ -93,3 +94,3 @@ PassThroughHandlerData,

this.matchers.push(new MethodMatcherData(methodOrAddRule));
if (path instanceof RegExp) {

@@ -116,2 +117,10 @@ this.matchers.push(new RegexPathMatcherData(path));

/**
* Match only requests that include the given query parameters
*/
withQuery(query: { [key: string]: string | number }): MockRuleBuilder {
this.matchers.push(new QueryMatcherData(query));
return this;
}
/**
* Match only requests whose bodies include the given form data

@@ -118,0 +127,0 @@ */

@@ -5,2 +5,4 @@ /**

/// <reference path="../../custom-typings/asynciterator.d.ts" />
import * as path from 'path';

@@ -207,3 +209,3 @@ import * as fs from '../util/fs';

stop(): Promise<void> {
if (!this.server) return Promise.resolve<void>();
if (!this.server) return Promise.resolve();

@@ -210,0 +212,0 @@ return Promise.all([

@@ -10,4 +10,5 @@ /**

stripWWW: false,
removeQueryParameters: [],
removeTrailingSlash: false,
removeQueryParameters: [/.*/g],
});
}

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 too big to display

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

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