newman-collection
Advanced tools
Comparing version 1.5.1 to 2.0.4
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14
151
60493
3
3
334
2
+ Addedpostman-sandbox@^4.0.8
+ Added@faker-js/faker@5.5.3(transitive)
+ Added@types/node@16.18.119(transitive)
+ Addedflatted@3.2.6(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedpostman-collection@4.4.04.5.0(transitive)
+ Addedpostman-sandbox@4.7.1(transitive)
+ Addedpostman-url-encoder@3.0.5(transitive)
+ Addedsemver@7.5.47.6.3(transitive)
+ Addedteleport-javascript@1.0.0(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addeduvm@2.1.1(transitive)
- Removed@types/node@13.13.52(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddom-serializer@0.2.2(transitive)
- Removeddomelementtype@1.3.12.3.0(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.7.0(transitive)
- Removedentities@1.1.22.2.0(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfaker@5.5.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removediconv-lite@0.6.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.escaperegexp@4.1.2(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlodash.mergewith@4.6.2(transitive)
- Removedmarked@2.0.1(transitive)
- Removedmime-db@1.47.0(transitive)
- Removedmime-types@2.1.30(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedpostman-collection@3.6.11(transitive)
- Removedpostman-url-encoder@3.0.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsanitize-html@1.20.1(transitive)
- Removedsemver@7.3.5(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsrcset@1.0.0(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removeduuid@3.4.0(transitive)
- Removedxtend@4.0.2(transitive)
Updated@types/node@^16
Updatedpostman-collection@^4