Socket
Socket
Sign inDemoInstall

postman-collection-transformer

Package Overview
Dependencies
20
Maintainers
4
Versions
148
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.0.1

122

lib/normalizers/v1.js

@@ -34,18 +34,19 @@ /* eslint-disable object-shorthand */

/**
* Normalizes a list of v1 entities.
* Normalizes `description` field of an entity.
* If `description` field is absent, this is a no-op.
* Will mutate the entity.
*
* @param {Object[]} entities - The list of entities to be normalized.
* @param {?Object} [options] - The set of options for the current normalization.
* @param {?Boolean} [options.retainEmptyValues=false] - When set to true, appropriate empty values are set to ''
* instead of being removed.
* @returns {Object[]} - The normalized list of entities.
* @param {Object} entity - Wrapper object, possibly containing a description field
* @param {Object} builder - Builder instance that will be called to perform normalization
* @param {Object} utilOptions - Options to be passed to util fn
*/
normalizeEntities = function (entities, options) {
var retainEmpty = options && options.retainEmptyValues;
normalizeDescription = function (entity, builder, utilOptions) {
var retainEmptyValues = _.get(utilOptions, 'retainEmptyValues');
_.forEach(entities, function (entity) {
util.cleanEmptyValue(entity, 'description', retainEmpty);
});
if (_.has(entity, 'description')) {
entity.description = builder.description(entity.description);
}
util.cleanEmptyValue(entity, 'description', retainEmptyValues);
return entities;
return entity;
};

@@ -144,3 +145,14 @@

variables: function (entity, options) {
return util.handleVars(entity, options);
var self = this,
// Use builder's own options if override is not requested
results = util.handleVars(entity, options || this.options);
// Normalize descriptions that may have been passed in as objects
results = _.map(results, function (item) {
return normalizeDescription(item, self, options || self.options);
});
if (results.length) {
return results;
}
},

@@ -157,3 +169,4 @@

var mode = requestV1.dataMode,
var self = this,
mode = requestV1.dataMode,
noDefaults = this.options.noDefaults,

@@ -172,3 +185,3 @@ retainEmptyValues = this.options.retainEmptyValues;

util.cleanEmptyValue(datum, 'description', retainEmptyValues);
normalizeDescription(datum, self, self.options);
});

@@ -186,2 +199,5 @@

headerData: function (requestV1) {
var self = this,
normalizedHeaderData;
if (!requestV1) { return; }

@@ -194,3 +210,9 @@ if (requestV1.headers && _.isEmpty(requestV1.headerData)) {

// however, if non empty headerData already exists, sanitize it.
return normalizeEntities(requestV1.headerData, this.options);
normalizedHeaderData = _.map(requestV1.headerData, function (entity) {
return normalizeDescription(entity, self, self.options);
});
if (normalizedHeaderData.length) {
return normalizedHeaderData;
}
},

@@ -201,3 +223,5 @@

var urlObj;
var self = this,
normalizedQueryParams,
urlObj;

@@ -208,3 +232,9 @@ if (!requestV1.queryParams) {

return normalizeEntities(requestV1.queryParams, this.options);
normalizedQueryParams = _.map(requestV1.queryParams, function (entity) {
return normalizeDescription(entity, self, self.options);
});
if (normalizedQueryParams.length) {
return normalizedQueryParams;
}
},

@@ -225,3 +255,13 @@

pathVariableData: function (entity, options) {
return util.handleVars(entity, options, { isV1: true });
var self = this,
results = util.handleVars(entity, options, { isV1: true });
// Normalize descriptions that may have been passed in as objects
results = _.map(results, function (item) {
return normalizeDescription(item, self, self.options);
});
if (results.length) {
return results;
}
},

@@ -262,4 +302,5 @@

!((options.retainIds && requestV1.id) || options.noDefaults) && (requestV1.id = util.uid());
util.cleanEmptyValue(requestV1, 'description', retainEmpty);
normalizeDescription(requestV1, self, self.options);
units.forEach(function (unit) {

@@ -447,2 +488,4 @@ var result = self[unit](requestV1, self.options);

!((self.options.retainIds && folder.id) || self.options.noDefaults) && (folder.id = util.uid());
folder.description = self.description(folder.description);
util.cleanEmptyValue(folder, 'description', retainEmpty);

@@ -482,2 +525,34 @@

return _.compact(collectionV1.requests);
},
/**
* Creates the v1.0.0 compatible description string.
*
* @param {Object} maybeObjectDescription - The description to be converted
*
* @returns {String} - The resultant v1 description.
*/
description: function (maybeObjectDescription) {
var description,
retainEmpty = _.get(this.options, 'retainEmptyValues'),
createDefaultValue = !_.get(this.options, 'noDefaults', false);
if (_.isObject(maybeObjectDescription)) {
description = _.toString(_.get(maybeObjectDescription, 'content'));
}
else {
description = maybeObjectDescription;
}
if (description) {
return description;
}
else if (description === undefined && createDefaultValue) {
return null;
}
else if (_.isEmpty(description) && retainEmpty) {
return null;
}
return undefined;
}

@@ -573,3 +648,2 @@ });

builders = new Builders(options),
retainEmpty = options.retainEmptyValues,
units = ['events', 'variables', 'order', 'folders_order', 'folders', 'requests'];

@@ -583,3 +657,3 @@

util.cleanEmptyValue(collection, 'description', retainEmpty);
normalizeDescription(collection, builders, options);

@@ -591,3 +665,3 @@ // remove invalid protocolProfileBehavior property

auth = builders.auth(collection, authOptions);
if (auth) {
if (auth || (options.retainEmptyValues && auth === null)) {
collection.auth = auth;

@@ -604,3 +678,3 @@ }

if (unit === 'variables') {
_options = { retainIds: options.retainIds };
_options = { retainIds: options.retainIds, noDefaults: options.noDefaults };
}

@@ -607,0 +681,0 @@

10

lib/util.js

@@ -72,6 +72,10 @@ /* eslint-disable object-shorthand */

// add id only when retainIds is set
if (retainIds) {
result.id = (noDefaults || item.id) ? item.id : self.uid();
// retain id only when retainIds is set, and `id` field is present
if (retainIds && _.has(item, 'id')) {
result.id = item.id;
}
// create a new id if noDefaults is false
else if (!noDefaults) {
result.id = self.uid();
}

@@ -78,0 +82,0 @@ result.key = item.key || item.id;

{
"name": "postman-collection-transformer",
"version": "4.0.0",
"version": "4.0.1",
"description": "Perform rapid conversation and validation of JSON structure between Postman Collection Format v1 and v2",

@@ -48,3 +48,3 @@ "author": "Postman Inc.",

"eslint": "^7.14.0",
"eslint-plugin-jsdoc": "^30.7.8",
"eslint-plugin-jsdoc": "^31.6.0",
"eslint-plugin-lodash": "^7.1.0",

@@ -54,3 +54,3 @@ "eslint-plugin-mocha": "^8.0.0",

"js-yaml": "^3.14.0",
"karma": "^5.2.3",
"karma": "^6.1.0",
"karma-browserify": "^7.0.0",

@@ -57,0 +57,0 @@ "karma-chrome-launcher": "^3.1.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc