Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postman-collection

Package Overview
Dependencies
Maintainers
5
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.0.4-beta.1 to 3.0.4

20

CHANGELOG.md
# Postman Collection SDK Changelog
#### v3.0.4-beta,1 (November 9, 2017)
#### Unreleased
#### 3.0.4
* :tada: Get and set objects in variables with `json` variable type
```js
var variable = new Variable({ type: 'json' });
// set objects as values for `json types`
variable.set({ version: 'v1' });
// get object values
console.log(variable.get()); // { version: 'v1' }
console.log(typeof variable.get()); // object
```
* #502 Added support for system property in query parameters
* #503 `request~toJSON` no longer converts `url` to string
* Made sure all Script instances have an id
* :bug: Fixed a bug where updating types in a variable removed value functions
* :bug: `auth` is now included in `collection.toJSON`
* :bug: Fixed a bug where `item.getAuth` would return an empty `RequestAuth`, instead of looking up in the parent
* :bug: Fixed a bug where empty `auth` was created for `new {Request,ItemGroup,Collection}({auth: null})`. This affected the auth lookup in parents.

@@ -7,0 +25,0 @@ #### v3.0.3 (November 8, 2017)

5

lib/collection/certificate-list.js

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

* @example <caption>Create a new CertificateList</caption>
* var certificateList = new CertificateList({}, [
* var CertificateList = require('postman-collection').CertificateList,
* certificateList = new CertificateList({}, [
* {

@@ -32,3 +33,3 @@ * name: 'my certificate for example.com',

* }
* ])
* ]);
*/

@@ -35,0 +36,0 @@ CertificateList = function (parent, list) {

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

* @property {{ src: (String) }} [key] Object with path on the file system for private key file, as src
* @property {{ src: (String) }} [cert] Object with path on the file system fot certificate file, as src
* @property {{ src: (String) }} [cert] Object with path on the file system for certificate file, as src
* @property {String} [passphrase] The passphrase for the certificate key

@@ -26,7 +26,7 @@ *

* {
* name: 'My certificate for example.com',
* matches: ['https://example.com/*'],
* key: { src: '/path/to/key' },
* cert: { src: '/User/path/to/certificate' },
* passphrase: 'iampassphrase'
* "name": "My certificate for example.com",
* "matches": ["https://example.com/*"],
* "key": { "src": "/path/to/key" },
* "cert": { "src": "/User/path/to/certificate" },
* "passphrase": "iampassphrase"
* }

@@ -33,0 +33,0 @@ */

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

* that are a *part of the collection*, as opposed to environments, which are separate entities.
* @property {Object<RequestAuth~definition>=} [auth] Collection auth allows you to define an authentication,
* that *applies to all items* in the collection.
* @property {Array<Event~definition>=} [event] Postman allows you to configure scripts to run when specific events
* occur.
* @property {String|Version~definition=} [version] Version of the collection expressed in [semver](http://semver.org/)

@@ -88,3 +92,3 @@ * format.

* // log items at root level of the collection
* console.log(inspect(myCollection));
* console.log(pretty(myCollection));
*

@@ -103,3 +107,3 @@ * @example <caption>Create a blank collection and write to file</caption>

* // log the collection to console to see its contents
* fs.writeFileSync('myCollection.postman_collection', myCollection.toString());
* fs.writeFileSync('myCollection.postman_collection', JSON.stringify(myCollection, null, 2));
*/

@@ -193,13 +197,17 @@ Collection = function PostmanCollection (definition, environments) {

toJSON: function () {
return {
info: {
id: this.id,
name: this.name,
version: this.version,
schema: SCHEMA_URL
},
event: this.events ? this.events.toJSON() : undefined,
variable: this.variables ? this.variables.toJSON() : undefined,
item: this.items.toJSON()
var json = ItemGroup.prototype.toJSON.apply(this);
// move ids and stuff from root level to `info` object
json.info = {
id: this.id,
name: this.name,
version: this.version,
schema: SCHEMA_URL
};
delete json.id;
delete json.name;
delete json.version;
return json;
}

@@ -206,0 +214,0 @@ });

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

* @property {String=} [value] The value stored in the Cookie
* @property {String=} [expires] Expires sets an expiry date for when a coo0kie gets deleted. It should either be a
* @property {String=} [expires] Expires sets an expiry date for when a cookie gets deleted. It should either be a
* date object or timestamp string of date.

@@ -54,16 +54,18 @@ * @property {Number=} [maxAge] Max-age sets the time in seconds for when a cookie will be deleted.

*
* @example <caption>JSON definition of an example collection</caption>
* @example <caption>JSON definition of an example cookie</caption>
* {
* key: 'my-cookie-name',
* expires: '1464769543832', // UNIX timestamp, in *milliseconds*
* maxAge: '300' // In seconds. In this case, the Cookie is valid for 5 minutes
* domain: 'something.example.com',
* path: '/',
* secure: false,
* httpOnly: true,
* session: false,
* value: 'my-cookie-value',
* extensions: [{
* key: 'Priority',
* value: 'HIGH'
* "key": "my-cookie-name",
* "expires": "1464769543832",
* // UNIX timestamp, in *milliseconds*
* "maxAge": "300",
* // In seconds. In this case, the Cookie is valid for 5 minutes
* "domain": "something.example.com",
* "path": "/",
* "secure": false,
* "httpOnly": true,
* "session": false,
* "value": "my-cookie-value",
* "extensions": [{
* "key": "Priority",
* "value": "HIGH"
* }]

@@ -86,3 +88,3 @@ * }

* expires: '1464769543832', // UNIX timestamp, in *milliseconds*
* maxAge: '300' // In seconds. In this case, the Cookie is valid for 5 minutes
* maxAge: '300', // In seconds. In this case, the Cookie is valid for 5 minutes
* domain: 'something.example.com',

@@ -89,0 +91,0 @@ * path: '/',

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

*
* @example Create a header
* @example <caption>Create a header</caption>
* var Header = require('postman-collection').Header,

@@ -52,3 +52,16 @@ * header = new Header({

*
* assert headerString === Header.unparse(headers);
* function assert(condition, message) {
* if (!condition) {
* message = message || "Assertion failed";
* if (typeof Error !== "undefined") {
* throw new Error(message);
* }
* throw message; //fallback
* }
* else {
* console.log("Assertion passed");
* }
* }
*
* assert(headerString.trim() === Header.unparse(headers).trim());
*/

@@ -55,0 +68,0 @@ Header = function PostmanHeader (options, name) {

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

* "listen": "prerequest",
* "script: {
* "script": {
* "type": "text/javascript",

@@ -71,3 +71,3 @@ * "exec": "console.log(new Date())"

* myCollection = new Collection(); // create an empty collection
* myCollection.add(new ItemGroup({ // add a folder called "blank folder"
* myCollection.items.add(new ItemGroup({ // add a folder called "blank folder"
* "name": "This is a blank folder"

@@ -134,3 +134,5 @@ * }));

*/
auth: _.createDefined(definition, 'auth', RequestAuth),
// auth is a special case, empty RequestAuth should not be created for falsy values
// to allow inheritance from parent
auth: definition && definition.auth ? new RequestAuth(definition.auth) : undefined,

@@ -137,0 +139,0 @@ /**

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

Request = require('./request').Request,
RequestAuth = require('./request-auth').RequestAuth,
Response = require('./response').Response,
Item;
Item,
/**
* Extracts `auth` from an entity. Checks if `auth` is present and it is not falsy type.
*
* @private
*
* @param {Object} [entity]
*/
extractAuth = function (entity) {
var auth;
return (entity && (auth = entity.auth) && RequestAuth.isValidType(auth.type)) ? auth : undefined;
};
/**

@@ -64,7 +78,7 @@ * The following defines the object (or JSON) structure that one can pass to the Item while creating a new Item

* // add a request to "my-folder-1" that sends a GET request
* myCollection.items.one("my-folder-1").add(new Item({
* myCollection.items.one("my-folder-1").items.add(new Item({
* "name": "Send a GET request",
* "id": "my-get-request"
* "id": "my-get-request",
* "request": {
* "url": 'https://postman-echo.com/get",
* "url": "https://postman-echo.com/get",
* "method": "GET"

@@ -108,5 +122,5 @@ * }

* "name": "Send a GET request",
* "id": "my-get-request"
* "id": "my-get-request",
* "request": {
* "url": 'https://postman-echo.com/get",
* "url": "https://postman-echo.com/get",
* "method": "GET"

@@ -142,3 +156,3 @@ * }

*
* returns {RequestAuth}
* @returns {RequestAuth}
*

@@ -148,3 +162,6 @@ * @note Since v3.0 release, this returns the entire auth RequestAuth, instead of just the parameters

getAuth: function () {
return this.request && this.request.auth || this.findInParents('auth');
var requestAuth;
// find auth on request, if not found or empty auth, lookup in the parents
return (requestAuth = extractAuth(this.request)) ? requestAuth : this.findInParents('auth', extractAuth);
},

@@ -151,0 +168,0 @@

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

* Tries to find the given property locally, and then proceeds to lookup in each parent,
* going up the chain as necessary.
* going up the chain as necessary. Lookup will continue until `customizer` returns a truthy value. If used
* without a customizer, the lookup will stop at the first parent that contains the property.
*
* @param {String} property
* @param {Function} [customizer]
*
* @returns {*|undefined}
*/
findInParents: function (property) {
var owner = this.findParentContaining(property);
findInParents: function (property, customizer) {
var owner = this.findParentContaining(property, customizer);
return owner ? owner[property] : undefined;

@@ -72,23 +76,38 @@ },

/**
* Looks up the closest parent which has a truthy value for the given property.
* Looks up the closest parent which has a truthy value for the given property. Lookup will continue
* until `customizer` returns a truthy value. If used without a customizer,
* the lookup will stop at the first parent that contains the property.
*
* @param {String} property
* @param {Function} [customizer]
*
* @returns {PropertyBase|undefined}
* @private
*/
findParentContaining: function (property) {
var parent;
findParentContaining: function (property, customizer) {
var parent = this;
// If the required property is present locally, `this` is the owner
if (this[property]) {
return this;
// if customizer is present test with it
if (customizer) {
customizer = customizer.bind(this);
do {
// else check for existence
if (customizer(parent)) {
return parent;
}
parent = parent.__parent;
} while (parent);
}
// Start travelling up the parent chain, to find the required property.
parent = this.__parent;
// else check for existence
else {
do {
if (parent[property]) {
return parent;
}
while (parent) {
if (parent[property]) {
return parent;
}
parent = parent.__parent;
parent = parent.__parent;
} while (parent);
}

@@ -95,0 +114,0 @@ },

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

* @param {PropertyList|Array} source
* @param {Boolean=false} prune Setting this to `true` will cause the extra items from the list to be deleted
* @param {Boolean} [prune=false] Setting this to `true` will cause the extra items from the list to be deleted
*/

@@ -325,0 +325,0 @@ assimilate: function (source, prune) {

@@ -32,7 +32,7 @@ var _ = require('../util').lodash,

* {
* match: 'http+https://example.com/*',
* host: 'proxy.com',
* port: 8080
* tunnel: true,
* disabled: false
* "match": "http+https://example.com/*",
* "host": "proxy.com",
* "port": "8080",
* "tunnel": true,
* "disabled": false
* }

@@ -39,0 +39,0 @@ */

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

// Although a similar check is being done in the .update call below, this handles falsy options as well.
/**

@@ -59,3 +60,2 @@ * @type {String}

*/
// Although a similar check is being done in the .update call below, this handles falsy options as well.
method: ((options && options.method) || DEFAULT_REQ_METHOD).toUpperCase()

@@ -95,6 +95,8 @@ });

// auth is a special case, empty RequestAuth should not be created for falsy values
// to allow inheritance from parent
/**
* @type {RequestAuth}
*/
auth: _.createDefined(options, 'auth', RequestAuth),
auth: options.auth ? new RequestAuth(options.auth) : undefined,

@@ -101,0 +103,0 @@ /**

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

/**
* Defines whether this property instances requires an id
* @private
* @readOnly
* @type {Boolean}
*/
_postman_propertyRequiresId: true,
/**
* Converts the script lines array to a single source string.

@@ -56,0 +64,0 @@ *

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

* @param {Boolean=} track
* @param {Boolean=true} prune
* @param {Boolean} [prune=true]
*

@@ -70,0 +70,0 @@ * @returns {Object}

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

* @example <caption>Iterate on all variables</caption>
* var env = new VariableScope([{
* var VariableScope = require('postman-collection').VariableScope,
* env = new VariableScope([{
* key: 'var1',

@@ -112,0 +113,0 @@ * value: 'one'

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

ANY = 'any',
STRING = 'string',

@@ -60,3 +61,3 @@ Variable;

if (!((definition === undefined) || (definition === null))) {
if (!_.isNil(definition)) {
/**

@@ -80,3 +81,3 @@ * The name of the variable. This is used for referencing this variable from other locations and scripts

get: function () {
return _.isFunction(this.value) ? this.cast(this.value()) : this.value;
return _.isFunction(this.value) ? this.castOut(this.value()) : this.castOut(this.value);
},

@@ -91,3 +92,3 @@

// @todo - figure out how secure is this!
this.value = _.isFunction(value) ? value : this.cast(value);
this.value = _.isFunction(value) ? value : this.castIn(value);
},

@@ -122,22 +123,60 @@

cast: function (value) {
return (Variable.types[this.type] || Variable.types.any)(value);
return this.castOut(value);
},
/**
* Typecasts a value to the {@link Variable.types} of this {@link Variable}. Returns the value of the variable
* converted to the type specified in {@link Variable#type}.
*
* @private
* @param {*} value
* @returns {*}
*/
castIn: function (value) {
var handler = Variable.types[this.type] || Variable.types.any;
return _.isFunction(handler) ? handler(value) : handler.in(value);
},
/**
* Typecasts a value from the {@link Variable.types} of this {@link Variable}. Returns the value of the variable
* converted to the type specified in {@link Variable#type}.
*
* @private
* @param {*} value
* @returns {*}
*/
castOut: function (value) {
var handler = Variable.types[this.type] || Variable.types.any;
return _.isFunction(handler) ? handler(value) : handler.out(value);
},
/**
* Sets or gets the type of the value.
*
* @param {String} typeName
* @param {Boolean} _nocast
* @param {Boolean} _noCast
* @returns {String} - returns the current type of the variable from the list of {@link Variable.types}
*/
valueType: function (typeName, _nocast) {
if (!typeName || !Variable.types[(typeName = typeName && typeName.toString().toLowerCase())]) {
valueType: function (typeName, _noCast) {
!_.isNil(typeName) && (typeName = typeName.toString().toLowerCase()); // sanitize
if (!Variable.types[typeName]) {
return this.type || ANY; // @todo: throw new Error('Invalid variable type.');
}
// set the new type if it is valid and cast the stored value
// set type if it is valid
this.type = typeName;
!_nocast && (this.value = this.cast(this.value));
return typeName;
// 1. get the current value
// 2. set the new type if it is valid and cast the stored value
// 3. then set the interstitial value
var interstitialCastValue;
// do not touch value functions
if (!(_noCast || _.isFunction(this.value))) {
interstitialCastValue = this.get();
this.set(interstitialCastValue);
interstitialCastValue = null; // just a precaution
}
return this.type;
},

@@ -207,10 +246,59 @@

/**
* A "json" type value stores JSON data format
*/
'json': {
/**
* @param {Object|Array} val
* @returns {String}
*/
in: function (val) {
try {
// @todo: shoud we check if `val` is a valid JSON string?
val = typeof val === STRING ? val : JSON.stringify(val);
}
catch (e) {
val = 'null';
}
return val;
},
/**
* A "json" type value stores JSON data format
*
* @param {String} val
* @returns {Object}
*/
out: function (val) {
try {
val = JSON.parse(val);
}
catch (e) {
val = null;
}
return val;
}
},
/**
* 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}.
*
* @param {*} val
* @returns {*}
*/
'any': function (val) {
return val; // pass through
'any': {
/**
* @param {*} val
* @returns {*}
*/
in: function (val) {
return val; // pass through
},
/**
* @param {*} val
* @returns {*}
*/
out: function (val) {
return val; // pass through
}
}

@@ -217,0 +305,0 @@ },

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

"author": "Postman Labs <help@getpostman.com>",
"version": "3.0.4-beta.1",
"version": "3.0.4",
"keywords": [

@@ -40,3 +40,3 @@ "postman"

"liquid-json": "0.3.1",
"lodash": "4.17.2",
"lodash": "4.17.4",
"8fold-marked": "0.3.8",

@@ -56,3 +56,3 @@ "mime-format": "2.0.0",

"dependency-check": "2.9.1",
"eslint": "4.10.0",
"eslint": "4.11.0",
"eslint-plugin-jsdoc": "3.2.0",

@@ -66,5 +66,5 @@ "eslint-plugin-lodash": "2.5.0",

"jsdoc": "3.5.5",
"jsdoc-to-markdown": "3.0.1",
"jsdoc-to-markdown": "3.0.2",
"karma": "1.7.1",
"karma-browserify": "5.1.1",
"karma-browserify": "5.1.2",
"karma-chrome-launcher": "2.2.0",

@@ -71,0 +71,0 @@ "karma-mocha": "1.3.0",

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