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

newman-collection

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

newman-collection - npm Package Compare versions

Comparing version 1.5.1 to 2.0.4

.github/workflows/npm-publish.yml

129

index.ts

@@ -0,11 +1,22 @@

/// <reference path="node_modules/postman-collection/types/index.d.ts"/>
import {
Collection,
CollectionDefinition,
//CollectionDefinition,
Item,
ItemDefinition,
//ItemDefinition,
Request,
RequestDefinition,
Event
//RequestDefinition,
Event,
RequestAuth,
Script,
RequestBody,
} from "postman-collection";
type CollectionDefinition = Collection.definition;
type ItemDefinition = Item.definition;
type RequestDefinition = Request.definition;
//import * as ps from "postman-collection/types";
import { type } from "os";
import { format } from "path";

@@ -82,8 +93,8 @@ // Basic Auth data

this.newman_collection = collection;
this.collection = { collection };
this.collection = collection.collection;
}
basic(basic) {
this.collection.authorizeUsing({ type: "basic" });
this.collection.authorizeRequestsUsing({ type: "basic" });
this.collection.auth.update(
Object.keys(basic).map(key => ({ key, value: basic[key] }))
Object.keys(basic).map((key) => ({ key, value: basic[key] }))
);

@@ -108,7 +119,16 @@ return this.newman_collection;

let { postman_element } = this;
let auth: RequestAuth;
postman_element.authorizeUsing({ type: "basic" });
postman_element.auth.update(
Object.keys(basic).map(key => ({ key, value: basic[key] }))
);
if (postman_element instanceof Collection) {
postman_element.authorizeRequestsUsing({ type: "basic" });
auth = postman_element.auth;
} else if (postman_element instanceof Item) {
postman_element.authorizeRequestUsing({ type: "basic" });
auth = postman_element.getAuth();
} else if (postman_element instanceof Request) {
postman_element.authorizeUsing({ type: "basic" });
auth = postman_element.auth;
}
auth.update(Object.keys(basic).map((key) => ({ key, value: basic[key] })));
return this.newman_element;

@@ -126,3 +146,3 @@ }

"basic",
Object.keys(basic).map(key => ({ key, value: basic[key] }))
Object.keys(basic).map((key) => ({ key, value: basic[key] }))
);

@@ -145,4 +165,6 @@ return this.newman_element;

// Collection
class NewmanCollection extends NewmanCollectionElement
implements INewmanCollection {
class NewmanCollection
extends NewmanCollectionElement
implements INewmanCollection
{
collection: Collection;

@@ -165,3 +187,3 @@ constructor(

items &&
items.forEach(element => this.collection.items.append(element.item));
items.forEach((element) => this.collection.items.append(element.item));
}

@@ -173,4 +195,6 @@ get auth() {

class NewmanItemElement extends NewmanCollectionElement
implements INewmanItemElement {
class NewmanItemElement
extends NewmanCollectionElement
implements INewmanItemElement
{
newman_item: INewmanItem;

@@ -188,9 +212,14 @@ item: Item;

super();
this.item = new Item(
typeof def === "string" ? { name: def } : (def as ItemDefinition)
);
if (typeof def === "string") {
this.item = new Item();
this.item.name = def;
} else {
this.item = new Item(def);
}
}
private request(request: RequestDefinition): INewmanRequest {
Object.assign(this.item.request, request);
return new NewmanRequest(this.item.request, this);
private request(def: Partial<RequestDefinition>): INewmanRequest {
let request = new NewmanRequest(def as RequestDefinition, this);
this.item.request = request.request;
return request;
}

@@ -230,8 +259,8 @@ get(url: string) {

listen: "test",
script: {
script: new Script({
exec: /(?<={).*(?=}$)/s
.exec(callback.toString())
.map(code => code.split("\r\n"))
.flat()
}
.map((code) => code.split("\r\n"))
.flat(),
}),
})

@@ -251,11 +280,9 @@ );

class NewmanRequest extends NewmanItemElement implements INewmanRequest {
get item() {
return this.newman_item.item;
}
request: Request;
constructor(request: Request, item: INewmanItem) {
constructor(request: Request.definition, item: INewmanItem) {
super();
this.request = request;
this.request = new Request(request);
this.newman_item = item;
this.item = this.newman_item.item;
}

@@ -266,16 +293,24 @@ get on(): INewmanScript {

body(body: string | object): INewmanRequest {
this.request.update({
body: {
mode: "raw",
raw:
typeof body === "object"
? this.headers({ "Content-Type": "application/json" }) &&
JSON.stringify(body)
: body
}
// this.request.body.update({
// mode: "raw",
// raw:
// typeof body === "object"
// ? this.headers({ "Content-Type": "application/json" }) &&
// JSON.stringify(body)
// : body,
// });
this.request.body = new RequestBody({
mode: "raw",
raw:
typeof body === "object"
? this.headers({ "Content-Type": "application/json" }) &&
JSON.stringify(body)
: body,
});
return this;
}
headers(headers: object): INewmanRequest {
Object.keys(headers).forEach(key =>
Object.keys(headers).forEach((key) =>
this.request.addHeader({ key, value: headers[key] })

@@ -291,7 +326,7 @@ );

listen: "test",
script: {
script: new Script({
exec: [`pm.test(\"${description}\", ${callback.toString()});`]
.map(code => code.split("\r\n"))
.flat()
}
.map((code) => code.split("\r\n"))
.flat(),
}),
})

@@ -301,3 +336,3 @@ );

return this;
}
},
};

@@ -304,0 +339,0 @@ }

{
"name": "newman-collection",
"version": "1.5.1",
"version": "2.0.4",
"description": "",
"main": "index.js",
"scripts": {
"test:collection": "node ./test/save-collection.js",
"test:newman": "node ./test/run-newman.js",
"build": "tsc",
"test": "npm run test:collection & npm run test:newman",
"test:collection": "ts-node ./test/save-collection.ts",
"test:newman": "ts-node ./test/run-newman.ts",
"postversion": "git push --follow-tags"

@@ -14,8 +16,11 @@ },

"dependencies": {
"@types/node": "^13.7.1",
"postman-collection": "^3.5.5"
"@types/node": "^16",
"postman-collection": "^4",
"postman-sandbox": "^4.0.8"
},
"devDependencies": {
"newman": "^4.5.7"
"newman": "^5",
"ts-node": "^10.8.1",
"typescript": "^4.7.4"
}
}

@@ -17,4 +17,6 @@ # Newman/Postman collection generator

Newman is a tool developed by a postman team works with existing files or URL in CLI mode or with a model from [postman-collection][postman-collection] module as node.js module. This module is nothing more than decoration of postman-collection calls.
Newman is a tool developed by a postman team which can run existing collections . Having postman-collection SDK available we can already generate collections on the fly, however working with this library directly developer experience was not that great. Behind the idea of this module I have personal experience of working with Express.js (get/post/head/put/delete and other https methods), fetch Web API-like headers declaration and finally writing scripts as Javascript not like strings
Same code with postman SDK will take more lines:
```js

@@ -66,3 +68,3 @@ const { Collection, Item } = require("newman-collection");

| method | description |
| :-------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|:--------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| _constructor_( _collection_?: CollectionDefinition , _items_?: Item ) | To create an instance you can provide collection definition from postman SDK. In addition to this list of items can be provided also |

@@ -94,3 +96,3 @@ | _constructor_( items\*?: Item ) | You can omit definition part providing just array of items |

You can always use these classes to build your own calls and then reuse them across your scenarios
You can always use these classes to build your own recipies and then reuse them across your scenarios

@@ -97,0 +99,0 @@ ```js

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