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

har2postman

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

har2postman - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

test/0.5.0/test.js

87

lib/har-to-postman.js

@@ -24,27 +24,19 @@ const HarToPostman = () => { };

const items = [];
harContent.log.entries.map( (e) => {
items.push(generateItem(e, includeTest));
});
return items;
};
const generateItem = (harContentEntries, includeTest) => {
const harRequest = harContentEntries.request;
const generateItem = (harContentEntry, includeTest) => {
const harRequest = harContentEntry.request;
const harRequestUrl = new URL(harRequest.url);
const harResponse = harContentEntries.response;
const harResponse = harContentEntry.response;
const item = {
name: generateItemName(harRequest.method, harRequestUrl.pathname, harResponse.status, includeTest),
event: generateItemEvent(harResponse, harRequestUrl),
request: generateItemRequest(harRequest),
};
if (!includeTest) {
delete item.event;
if (includeTest) {
item.event = generateItemEvent(harResponse, harRequestUrl);
}
if (harRequest.queryString.length == 0) {
delete item.request.url.query;
}
return item;

@@ -76,6 +68,14 @@ };

const harRequestUrl = new URL(harRequest.url);
return {
const itemRequest = {
method: harRequest.method,
url: generateItemRequestUrl(harRequestUrl, harRequest.queryString),
header: generateItemRequestHeaders(harRequest.headers, Boolean(harRequest.bodySize)),
};
if (harRequest.bodySize > 0) {
itemRequest.body = generateItemRequestBody(harRequest.postData);
}
if (itemRequest.header.length == 0) {
delete itemRequest.header;
}
return itemRequest;
};

@@ -85,3 +85,3 @@

const harPathnameArray = harRequestUrl.pathname.split('/');
return {
const itemRequestUrl = {
raw: harRequestUrl.toString(),

@@ -91,19 +91,54 @@ protocol: harRequestUrl.protocol.slice(0, -1),

path: harPathnameArray.slice(1),
query: generateQueryParams(queryString),
};
if (queryString.length > 0) {
itemRequestUrl.query = generateQueryParams(queryString);
}
return itemRequestUrl;
};
const generateQueryParams = (queryString) => {
queryString.forEach((queryParam) => {
queryParam.key = queryParam.name;
delete queryParam.name;
});
return queryString;
};
const generateItemRequestHeaders = (harRequestHeaders, requestHasBody) => {
const relevantHarHeaders = [];
if (requestHasBody) {
relevantHarHeaders.push('Content-Type');
}
return filterAndRenameRelevantHeaders(harRequestHeaders, relevantHarHeaders);
};
const filterAndRenameRelevantHeaders = (harRequestHeaders, relevantHarHeaders) => {
const itemRequestHeaders = [];
relevantHarHeaders.map((relevantHeader) => {
itemRequestHeaders.push(harRequestHeaders.find((header) => header.name === relevantHeader));
});
itemRequestHeaders.forEach((header) => {
header.key = header.name;
delete header.name;
});
return itemRequestHeaders;
};
const generateItemRequestBody = (requestBody) => {
return {
mode: 'raw',
raw: requestBody.text,
options: {'raw': {'language': 'json'}},
};
};
const generateScript = (response, harRequestUrl) => {
let exec = [];
exec = exec.concat(generateStatusCodeAssertion(response.status));
if (responseContainsId(response, harRequestUrl)) {
exec = exec.concat(generateIdAssertion(harRequestUrl));
}
if (responseIsArray(response)) {
exec = exec.concat(generateArrayAssertion());
}
return {

@@ -114,10 +149,2 @@ exec: exec,

const generateQueryParams = (queryString) => {
queryString.forEach((queryParam) => {
queryParam.key = queryParam.name;
delete queryParam.name;
});
return queryString;
};
const generateIdAssertion = (harRequestUrl) => {

@@ -144,7 +171,7 @@ const id = getIdFromUrl(harRequestUrl);

const id = getIdFromUrl(harRequestUrl);
return response.content != null && 'text' in response.content && parseInt(JSON.parse(response.content.text).id) === id;
return response.content && response.content.text && parseInt(JSON.parse(response.content.text).id) === id;
};
const responseIsArray = (response) => {
return response.content != null && 'text' in response.content && Array.isArray(JSON.parse(response.content.text));
return response.content && response.content.text && Array.isArray(JSON.parse(response.content.text));
};

@@ -151,0 +178,0 @@

{
"name": "har2postman",
"version": "0.4.0",
"version": "0.5.0",
"description": "Har to postman converter",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,3 +8,3 @@ {

{
"name": "POST /pet",
"name": "POST /v2/pet successfully",
"event": [

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

"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
"value": "application/json"
}

@@ -36,3 +34,3 @@ ],

"mode": "raw",
"raw": "{\r\n \"id\": 0,\r\n \"category\": {\r\n \"id\": 0,\r\n \"name\": \"string\"\r\n },\r\n \"name\": \"doggie\",\r\n \"photoUrls\": [\r\n \"string\"\r\n ],\r\n \"tags\": [\r\n {\r\n \"id\": 0,\r\n \"name\": \"string\"\r\n }\r\n ],\r\n \"status\": \"available\"\r\n}\r\n",
"raw": "{\n \"id\": 0,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"available\"\n}",
"options": {

@@ -60,3 +58,3 @@ "raw": {

{
"name": "GET /pet/2",
"name": "GET /v2/pet/6969696984 successfully",
"event": [

@@ -69,2 +67,6 @@ {

" pm.response.to.have.status(200);",
"});",
"pm.test(\"Fetched object should be the expected one\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.id).to.eql(6969696984);",
"});"

@@ -77,22 +79,5 @@ ],

"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"id\": 6969696984,\r\n \"category\": {\r\n \"id\": 0,\r\n \"name\": \"string\"\r\n },\r\n \"name\": \"doggie\",\r\n \"photoUrls\": [\r\n \"string\"\r\n ],\r\n \"tags\": [\r\n {\r\n \"id\": 0,\r\n \"name\": \"string\"\r\n }\r\n ],\r\n \"status\": \"available\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"method": "GET",
"url": {
"raw": "https://petstore.swagger.io/v2/pet",
"raw": "https://petstore.swagger.io/v2/pet/6969696984",
"protocol": "https",

@@ -106,3 +91,4 @@ "host": [

"v2",
"pet"
"pet",
"6969696984"
]

@@ -113,3 +99,3 @@ }

{
"name": "GET /pet/6969696984",
"name": "PUT /v2/pet successfully",
"event": [

@@ -122,7 +108,2 @@ {

" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"Fetched object should be the expected one\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData.id).to.eql(6969696984);",
"});"

@@ -135,5 +116,20 @@ ],

"request": {
"method": "GET",
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"id\": 6969696984,\n \"category\": {\n \"id\": 0,\n \"name\": \"string\"\n },\n \"name\": \"doggie\",\n \"photoUrls\": [\n \"string\"\n ],\n \"tags\": [\n {\n \"id\": 0,\n \"name\": \"string\"\n }\n ],\n \"status\": \"available\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://petstore.swagger.io/v2/pet/6969696984",
"raw": "https://petstore.swagger.io/v2/pet",
"protocol": "https",

@@ -147,4 +143,3 @@ "host": [

"v2",
"pet",
"6969696984"
"pet"
]

@@ -155,3 +150,3 @@ }

{
"name": "DELETE /pet/6969696984",
"name": "DELETE /v2/pet/6969696984 successfully",
"event": [

@@ -158,0 +153,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