Socket
Socket
Sign inDemoInstall

postman-collection

Package Overview
Dependencies
Maintainers
6
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postman-collection - npm Package Compare versions

Comparing version 3.4.2-beta.2 to 3.4.2-beta.3

3

CHANGELOG.md
# Postman Collection SDK Changelog
#### v3.4.2 (unreleased)
* #781 Added function `Request~size` to calculate request size
* #769 Avoid substitution of disabled variables
* #770 Added an option to exclude disabled listeners in `EventList~listeners` and `EventList~listenersOwn`
* #773 Added an option to exclude headers with falsy keys in `Request~getHeaders`
* #777 Handle disabled events in `EventList~listeners` and `EventList~listenersOwn` correctly
* Updated dependencies

@@ -8,0 +9,0 @@

@@ -29,12 +29,14 @@ var _ = require('../util').lodash,

*
* @note
* If one needs to access disabled events, use {@link PropertyList#all} or
* any other similar {@link PropertyList} method.
*
* @param {String} name
* @param {?Object} options - Set of options
* @param {?Boolean} options.excludeDisabled - When set to true, disabled events are excluded
* @returns {Array<Event>}
*/
listeners: function (name, options) {
listeners: function (name) {
var all;
// we first procure all matching events from this list
all = this.listenersOwn(name, options);
all = this.listenersOwn(name);

@@ -48,3 +50,3 @@ this.eachParent(function (parent) {

(parent !== this.__parent) && EventList.isEventList(parent.events) &&
(parentEvents = parent.events.listenersOwn(name, options)) && parentEvents.length &&
(parentEvents = parent.events.listenersOwn(name)) && parentEvents.length &&
all.unshift.apply(all, parentEvents); // eslint-disable-line prefer-spread

@@ -61,15 +63,7 @@ }, this);

* @param {string} name
* @param {?Object} options - Set of options
* @param {?Boolean} options.excludeDisabled - When set to true, disabled events are excluded
* @returns {Array<Event>}
*/
listenersOwn: function (name, options) {
if (options && options.excludeDisabled) {
return this.filter(function (event) {
return (!event.disabled && event.listen === name);
});
}
listenersOwn: function (name) {
return this.filter(function (event) {
return (event.listen === name);
return (!event.disabled && event.listen === name);
});

@@ -76,0 +70,0 @@ }

@@ -35,5 +35,12 @@ var _ = require('../util').lodash,

var raw = E;
raw += Header.unparse(this, CRLF);
raw += (CRLF + CRLF);
var raw = this.reduce(function (acc, header) {
// unparse header only if it has a valid key and is not disabled
if (header && !header.disabled) {
// *( header-field CRLF )
acc += Header.unparseSingle(header) + CRLF;
}
return acc;
}, E);
return raw.length;

@@ -40,0 +47,0 @@ }

@@ -8,3 +8,2 @@ var _ = require('../util').lodash,

DEFAULT_INDEXMULTI_ATTR = false,
DEFAULT_INDEXSANITIZE_ATTR = false,

@@ -62,6 +61,2 @@ PropertyList;

// if the type doesn't allow falsy key, set the flag
_.getOwn(type, '_postman_propertySanitizeKeys') && (this._postman_listSanitizeKeys =
type._postman_propertySanitizeKeys);
// prepopulate

@@ -104,10 +99,2 @@ populate && this.populate(populate);

/**
* Holds the attribute whether indexing of falsy index is allowed or not
*
* @private
* @type {String}
*/
_postman_listSanitizeKeys: DEFAULT_INDEXSANITIZE_ATTR,
/**
* Insert an element at the end of this list. When a reference member specified via second parameter is found, the

@@ -444,2 +431,13 @@ * member is inserted at an index before the reference member.

/**
* Iterates over the property list and accumulates the result.
*
* @param {Function} iterator Function to call on each item.
* @param {*} accumulator Accumulator initial value
* @param {Object} context Optional context, defaults to the PropertyList itself.
*/
reduce: function (iterator, accumulator, context) {
return _.reduce(this.members, _.isFunction(iterator) ? iterator.bind(context || this) : iterator, accumulator);
},
/**
* Returns the length of the PropertyList

@@ -565,3 +563,3 @@ *

key = this._postman_listIndexKey,
sanitiseKeys = this._postman_listSanitizeKeys || sanitizeKeys,
sanitiseKeys = this._postman_sanitizeKeys || sanitizeKeys,
sensitive = !this._postman_listIndexCaseInsensitive || caseSensitive,

@@ -568,0 +566,0 @@ multivalue = this._postman_listAllowsMultipleValues || multiValue;

@@ -147,2 +147,4 @@ var _ = require('../util').lodash,

* @returns {string}
*
* @todo - remove disabled arg and flatten params (retain back compat)
*/

@@ -149,0 +151,0 @@ unparse: function (params, options) {

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

var _ = require('../util').lodash,
var util = require('../util'),
_ = util.lodash,
PropertyBase = require('./property-base').PropertyBase,

@@ -12,4 +13,85 @@ Property = require('./property').Property,

Request,
DEFAULT_REQ_METHOD = 'GET';
/**
* Default request method
*
* @private
* @const
* @type {String}
*/
DEFAULT_REQ_METHOD = 'GET',
/**
* Content length header name
*
* @private
* @const
* @type {String}
*/
CONTENT_LENGTH = 'Content-Length',
/**
* Single space
*
* @private
* @const
* @type {String}
*/
SP = ' ',
/**
* Carriage return + line feed
*
* @private
* @const
* @type {String}
*/
CRLF = '\r\n',
/**
* HTTP version
*
* @private
* @const
* @type {String}
*/
HTTP_X_X = 'HTTP/X.X',
/**
* Connection header
*
* @private
* @const
* @type {String}
*/
CONNECTION_KEEP_ALIVE = 'Connection: keep-alive',
/**
* Connection header key name
*
* @private
* @const
* @type {String}
*/
CONNECTION_HEADER_KEY = 'connection',
/**
* @private
* @type {Boolean}
*/
supportsBuffer = (typeof Buffer !== undefined) && _.isFunction(Buffer.byteLength),
/**
* Source of request body size calculation.
* Either computed from body or used Content-Length header value.
*
* @private
* @const
* @type {Object}
*/
SIZE_SOURCE = {
computed: 'COMPUTED',
contentLength: 'CONTENT-LENGTH'
};
/**

@@ -256,2 +338,52 @@ * @typedef Request~definition

/**
* Get the request size by computing the headers and body or using the
* actual content length header once the request is sent.
*
* @returns {Object}
*/
size: function () {
var contentLength = this.headers.get(CONTENT_LENGTH),
requestTarget = this.url.getPathWithQuery(),
bodyString,
sizeInfo = {
body: 0,
header: 0,
total: 0,
source: SIZE_SOURCE.computed
};
// if 'Content-Length' header is present, we take body as declared by
// the client(postman-request or user-defined). else we need to compute the same.
if (contentLength && util.isNumeric(contentLength)) {
sizeInfo.body = parseInt(contentLength, 10);
sizeInfo.source = SIZE_SOURCE.contentLength;
}
// otherwise, if body is defined, we calculate the length of the body
else if (this.body) {
// @note body.toString() returns E for formdata or file mode
bodyString = this.body.toString();
sizeInfo.body = supportsBuffer ? Buffer.byteLength(bodyString) : bodyString.length;
}
// https://tools.ietf.org/html/rfc7230#section-3
// HTTP-message = start-line (request-line / status-line)
// *( header-field CRLF )
// CRLF
// [ message-body ]
// request-line = method SP request-target SP HTTP-version CRLF
sizeInfo.header = (this.method + SP + requestTarget + SP + HTTP_X_X + CRLF + CRLF).length +
this.headers.contentSize();
// account for connection header which will be added by Node's HTTP Agent
// since its not added back via Request~upsertHeader.
// @note requester.keepAlive is true by default in postman-runtime
if (!this.headers.has(CONNECTION_HEADER_KEY)) {
sizeInfo.header += (CONNECTION_KEEP_ALIVE + CRLF).length;
}
// compute the approximate total body size by adding size of header and body
sizeInfo.total = (sizeInfo.body || 0) + (sizeInfo.header || 0);
return sizeInfo;
},
/**
* Converts the Request to a plain JavaScript object, which is also how the request is

@@ -258,0 +390,0 @@ * represented in a collection file.

@@ -98,3 +98,3 @@ var util = require('../util'),

*/
HTTP_X_X = 'HTTP/X.X ',
HTTP_X_X = 'HTTP/X.X',

@@ -104,2 +104,16 @@ /**

* @const
* @type {String}
*/
SP = ' ',
/**
* @private
* @const
* @type {String}
*/
CRLF = '\r\n',
/**
* @private
* @const
* @type {RegExp}

@@ -463,5 +477,10 @@ */

// size of header is added
// https://tools.ietf.org/html/rfc7230#section-3.1.2
// https://tools.ietf.org/html/rfc7230#section-3
// HTTP-message = start-line (request-line / status-line)
// *( header-field CRLF )
// CRLF
// [ message-body ]
// status-line = HTTP-version SP status-code SP reason-phrase CRLF
sizeInfo.header = (HTTP_X_X + this.code + ' ' + this.reason() + '\r\n').length + this.headers.contentSize();
sizeInfo.header = (HTTP_X_X + SP + this.code + SP + this.reason() + CRLF + CRLF).length +
this.headers.contentSize();

@@ -468,0 +487,0 @@ // compute the approximate total body size by adding size of header and body

@@ -8,2 +8,3 @@ var _ = require('../util').lodash,

E = '',
OBJECT = 'object',
PROTOCOL_HTTPS = 'https',

@@ -242,21 +243,35 @@ PROTOCOL_HTTP = 'http',

*
* @param {Object=} options
* @param {Object} options.unresolved If set to true, path variables will not be processed
* @param {?Boolean=} [unresolved=false]
* @returns {string}
*
* @note deprecated variant in v3.4:
* - param {Object} options
* - param {Object} options.unresolved If set to true, path variables will not be processed
*/
getPath: function (options) {
getPath: function (unresolved) {
if (typeof unresolved === OBJECT) { // @todo discontinue in v4
unresolved = unresolved.unresolved;
}
// for unresolved case, this is super simple as that is how raw data is stored
if (unresolved) {
return PATH_SEPARATOR + this.path.join(PATH_SEPARATOR);
}
var self = this,
// eslint-disable-next-line max-len
segmentArray = (options && options.unresolved) ? this.path : _.transform(this.path, function (res, segment) {
var variable;
// check if the segment has path variable prefix followed by the variable name.
if (_.startsWith(segment, PATH_VARIABLE_IDENTIFIER) && segment !== PATH_VARIABLE_IDENTIFIER) {
variable = self.variables.one(segment.slice(1)); // remove path variable prefix.
}
segments;
variable = variable && variable.valueOf && variable.valueOf();
res.push(_.isString(variable) ? variable : segment);
}, []),
path = segmentArray.join(PATH_SEPARATOR);
return PATH_SEPARATOR + path; // add leading slash
segments = _.transform(this.path, function (res, segment) {
var variable;
// check if the segment has path variable prefix followed by the variable name.
if (_.startsWith(segment, PATH_VARIABLE_IDENTIFIER) && segment !== PATH_VARIABLE_IDENTIFIER) {
variable = self.variables.one(segment.slice(1)); // remove path variable prefix.
}
variable = variable && variable.valueOf && variable.valueOf();
res.push(_.isString(variable) ? variable : segment);
}, []);
return PATH_SEPARATOR + segments.join(PATH_SEPARATOR); // add leading slash
},

@@ -267,13 +282,20 @@

*
* @param {?Object} [options={}]
* @param {?Boolean} options.encode - Enables URL encoding when processing the query string.
* @param {?Boolean} options.ignoreDisabled - Prevents disabled query parameters from showing up in the unparsed
* result.
* @param {?Boolean} [encode=false] - Enables URL encoding when processing the query string
* @returns {String}
*
* @note Deprecated variant of this function is as follows:
* - param {?Object} [options={}]
* - param {?Boolean} options.encode - Enables URL encoding when processing the query string.
* - param {?Boolean} options.ignoreDisabled - Prevents disabled query parameters from showing up in the unparsed
*/
getQueryString: function (options) {
if (this.query.count()) {
return QueryParam.unparse(this.query.all(), options);
getQueryString: function (encode) {
if (!this.query.count()) {
return E;
}
return '';
if (typeof encode === OBJECT) { // @todo discontinue in v4
return QueryParam.unparse(this.query.all(), encode);
}
return QueryParam.unparse(this.query.all(), { encode: encode });
},

@@ -284,9 +306,15 @@

*
* @example /something/postman?hi=notbye
* @param {?Boolean} [encodeQuery=false] - when set to `true` the query string part will be URL encoded
*
* @returns {*|string}
* @example /something/postman?hi=notbye
*/
getPathWithQuery: function () {
getPathWithQuery: function (encodeQuery) {
var path = this.getPath();
this.query.count() && (path += (QUERY_SEPARATOR + this.getQueryString()));
// check count first so that, we can ensure that ba `?` is always appended, even if a blank query string exists
if (this.query.count()) {
path += (QUERY_SEPARATOR + this.getQueryString(encodeQuery));
}
return path;

@@ -296,3 +324,3 @@ },

/**
* Returns the host only
* Returns the host part of the URL
*

@@ -303,4 +331,5 @@ * @returns {string}

if (!this.host) {
return '';
return E;
}
return _.isArray(this.host) ? this.host.join(DOMAIN_SEPARATOR) : this.host.toString();

@@ -312,12 +341,19 @@ },

*
* @param {Object} options
* @param {Boolean} options.forcePort
* @param {?Boolean} [forcePort=false] - forces the port to be added even for the protocol default ones (89, 443)
* @returns {String}
*
* @note deprecated variant since v3.5
* - param {Object} options
* - param {Boolean} options.forcePort
*/
getRemote: function (options) {
var forcePort = options && options.forcePort,
host = this.getHost(),
getRemote: function (forcePort) {
var host = this.getHost(),
port = this.port && this.port.toString();
if (forcePort && !port) {
// @todo remove when v4 is released and this is discontinued
if (typeof forcePort === OBJECT) {
forcePort = forcePort.forcePort;
}
if (forcePort && !port) { // this (!port) works since it assumes port as a string
port = this.protocol && (this.protocol === PROTOCOL_HTTPS) ? HTTPS_PORT : HTTP_PORT;

@@ -335,2 +371,8 @@ }

* we currently are.
*
* @private
* @returns {String}
*
* @deprecated since v3.5 in favour of getBaseUrl
* @todo discontinue in v4.0
*/

@@ -337,0 +379,0 @@ getOAuth1BaseUrl: function () {

@@ -6,2 +6,3 @@ var _ = require('../util').lodash,

ANY = 'any',
NULL = 'null',
STRING = 'string',

@@ -232,3 +233,3 @@

*/
'string': String,
string: String,

@@ -239,3 +240,3 @@ /**

*/
'boolean': Boolean,
boolean: Boolean,

@@ -246,8 +247,9 @@ /**

*/
'number': Number,
number: Number,
/**
* A "json" type value stores JSON data format
* @deprecated Use "object" or "array" type instead. To be removed in 4.0.
*/
'json': {
json: {
/**

@@ -259,7 +261,7 @@ * @param {Object|Array} val

try {
// @todo: shoud we check if `val` is a valid JSON string?
// @todo: should we check if `val` is a valid JSON string?
val = typeof val === STRING ? val : JSON.stringify(val);
}
catch (e) {
val = 'null';
val = NULL;
}

@@ -289,6 +291,90 @@

/**
* A "array" type value stores Array data format
*/
array: {
/**
* @param {Array} val
* @returns {String}
*/
in: function (val) {
var value;
try {
// @todo: should we check if `val` is a valid Array or Array string?
value = typeof val === STRING ? val : JSON.stringify(val);
}
catch (e) {
value = NULL;
}
return value;
},
/**
* A "array" type value stores Array data format
*
* @param {String} val
* @returns {Object}
*/
out: function (val) {
var value;
try {
value = JSON.parse(val);
}
catch (e) {
value = undefined;
}
return Array.isArray(value) ? value : undefined;
}
},
/**
* A "object" type value stores Object data format
*/
object: {
/**
* @param {Object} val
* @returns {String}
*/
in: function (val) {
var value;
try {
// @todo: should we check if `val` is a valid JSON string?
value = typeof val === STRING ? val : JSON.stringify(val);
}
catch (e) {
value = NULL;
}
return value;
},
/**
* A "object" type value stores Object data format
*
* @param {String} val
* @returns {Object}
*/
out: function (val) {
var value;
try {
value = JSON.parse(val);
}
catch (e) {
value = undefined;
}
return (value instanceof Object && !Array.isArray(value)) ? value : undefined;
}
},
/**
* Free-form type of a value. This is the default for any variable, unless specified otherwise. It ensures that
* the variable can store data in any type and no conversion is done while using {@link Variable#get}.
*/
'any': {
any: {
/**

@@ -295,0 +381,0 @@ * @param {*} val

@@ -5,3 +5,3 @@ {

"author": "Postman Labs <help@getpostman.com>",
"version": "3.4.2-beta.2",
"version": "3.4.2-beta.3",
"keywords": [

@@ -54,11 +54,11 @@ "postman"

"chai": "4.2.0",
"chalk": "2.4.1",
"chalk": "2.4.2",
"dependency-check": "3.3.0",
"eslint": "5.8.0",
"eslint-plugin-jsdoc": "3.15.0",
"eslint": "5.12.1",
"eslint-plugin-jsdoc": "4.1.0",
"eslint-plugin-lodash": "5.0.1",
"eslint-plugin-mocha": "5.2.0",
"eslint-plugin-mocha": "5.2.1",
"eslint-plugin-security": "1.4.0",
"istanbul": "0.4.5",
"js-yaml": "3.12.0",
"js-yaml": "3.12.1",
"jsdoc": "3.5.5",

@@ -65,0 +65,0 @@ "jsdoc-to-markdown": "4.0.1",

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