Gathering detailed insights and metrics for inversify-express-postman
Gathering detailed insights and metrics for inversify-express-postman
Gathering detailed insights and metrics for inversify-express-postman
Gathering detailed insights and metrics for inversify-express-postman
npm install inversify-express-postman
Typescript
Module System
Node Version
NPM Version
50.5
Supply Chain
89.4
Quality
69.6
Maintenance
50
Vulnerability
95.3
License
TypeScript (96.25%)
JavaScript (3.75%)
Total Downloads
6,194
Last Day
2
Last Week
5
Last Month
19
Last Year
261
1 Stars
55 Commits
1 Watching
12 Branches
2 Contributors
Latest Version
0.6.3
Package Id
inversify-express-postman@0.6.3
Unpacked Size
162.33 kB
Size
28.26 kB
File Count
72
NPM Version
6.13.4
Node Version
10.18.1
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
150%
5
Compared to previous week
Last month
90%
19
Compared to previous month
Last year
-27.3%
261
Compared to previous year
2
Package is not finished yet and breaking changes are likely until v1.0.0
is released.
Export inversify-express-utils metadata to a Postman Collection and sync with the Postman API
Contents | Examples |
---|---|
Getting Started | Container to JSON |
Decorators | Decorator Example |
Syncing with Postman API | PostmanApi Example |
Adding Test Scripts | Test Script Example |
Once a container has been setup, use one of the top level functions to convert the metadata from the container's express endpoints to a Postman Collection or a JSON of the Collection.
In this example, a container is passed in and a JSON string is returned and logged to the console.
1import { Container } from 'inversify'; 2import * as IEPostman from 'inversify-express-postman'; 3 4const container = new Container(); 5 6container.bind<SomeAPIModel>(TYPES.SomeAPIModelService) 7 .to(SomeAPIModelService).inSingletonScope(); 8 9const server = new InversifyExpressServer(diContainer, ...); 10// Start the server before passing the container to inversify-express-postman 11// Prints to console the JSON with 2 space indentation 12IEPostman.ContainerToCollectionJSON(container, false, 2) 13 .then(console.log) 14 .catch(console.error);
All of the endpoints are split up by their controllers as folders and the endpoints as children of the controllers.
To add more information about an endpoint, utilize the @Decorators included with inversify-express-utils. (Some Decorator metadata isn't handled yet)
The PostmanData decorator allows the entry of some more Postman Collection supported items. There are a variety of decorators that can be used jointly. A few decorators can be applied to the class controllers. Console warnings should appear if a decorator is not supported. Typescript typings should give an error for any Decorators that won't work on a class.
The example below shows some valid usage of the included decorators.
1import {PostmanBodyRaw, PostmanName, PostmanHeader, PostmanDescription, PostmanResponse } from 'inversify-express-postman/decorators'; 2 3@controller("/api/v1/example", LOGGER_TYPES.LoggerMiddleWare) 4@PostmanName("API v1 | Example") // Names the Folder 5@PostmanDescription(path.join(__dirname, "store.md"), "path") // Read in a markdown file and set it as the description 6export class ExampleAPIv1Controller extends ControllerBase { 7 ... 8 9 @PostmanName("Store Data") // Names the Request 10 @PostmanBodyRaw(JSON.stringify({bodyText: "Here is the body text", environmentVariable: "{{ENVIRONMENT_VARIABLE}}"}, null, 2)) 11 @PostmanHeader('Content-Type', 'application/json', false) // False so the value does not get wrapped as an environment variable 12 @PostmanDescription("An example endpoint that stores something") 13 @PostmanResponse({code: 200, responseTime: 200, body: "{'success': true}"}, name: "Store Data Example"}) // Example response 14 15 @httpGet("/store") 16 async Store(@request() req: Request, @response() res: Response){ 17 ... 18 } 19}
The PostmanApi service provides methods for handling requests to the Postman API to create / update items (e.g. Collections and Environments). In order to create an instance of the PostmanApi class, a Postman API Key must be passed into the constructor. Visit Postman's API documentation to get a better understanding of what is happening when using the PostmanApi class.
If you need an API key, generate the key in your Postman Integrations Dashboard
The example below shows how to sync collections and create them using the git branch it was executed from. A similar method can be used for environment variables.
1...
2IEPostman.ContainerToCollection(container, {name: collectionName}).then(async collection => {
3 const pmAPI = new IEPostman.Services.PostmanApi("{{POSTMAN API KEY HERE}}");
4
5 // Get the name of the current branch
6 const gitPath = path.join(__dirname, "../../.git/HEAD");
7 function parseBranch(buf: any) {
8 const match = /ref: refs\/heads\/([^\n]+)/.exec(buf.toString());
9 return match ? match[1] : null;
10 }
11 const collectionName = `MY API | ${parseBranch(fs.readFileSync(gitPath))}`;
12 const collections = await pmAPI.ListCollections();
13
14 // Maintain Creation and Updating based on matching collection names
15 const matches = collections.collections.filter((value) => value.name === collectionName);
16 if(matches.length <= 0)
17 {
18 pmAPI.CreateCollection(collection, "{{POSTMAN WORKSPACE ID}}").catch(error => console.error(`Failed to create collection`, error));
19 }
20 else
21 {
22 for(const match of matches)
23 {
24 pmAPI.UpdateCollection(collection, match.uid).catch(error => console.error(`Failed to update collection`, error));
25 }
26 }
27
28
29}).catch(console.error);
30
Test scripts are supported and can be associated with an endpoint by using the PostmanTestFunction decorators.
In this example, an endpoint has a prerequest and a test function.
1import * as IEPostman from 'inversify-express-postman'; 2 3@controller("/api/v1/example", LOGGER_TYPES.LoggerMiddleWare) 4export class ExampleAPIv1Controller extends ControllerBase { 5 6 static PREREQUEST_store() 7 { 8 const json = JSON.stringify({ 9 pre: "request", 10 obj: "example" 11 }); 12 13 pm.variables.set("PreRequestBody"); 14 } 15 16 ... 17 18 @httpGet("/store") 19 20 // Write the function in line 21 @IEPostman.Decorators.PostmanTestFunction("test", (pm: any, responseBody: any) => { 22 23 var response = JSON.parse(responseBody) 24 pm.test("Success?", function () {pm.expect(response.success).to.equal(true)} ); 25 }) 26 27 // Pass in the function object 28 @IEPostman.Decorators.PostmanTestFunction("prerequest", ExampleAPIv1Controller.PREREQUEST_store) 29 async Store(@request() req: Request, @response() res: Response){ 30 ... 31 } 32}
When using a class static
method for a test function, the name of the function should start with either PREREQUEST
or TEST
or function
. See the functionStripper util to see how the stripper is working.
The PostmanTestFunction decorators support the use of absolute paths to files. This can be a remote resource and will be acquired using the request-promise package. Local resources are read using fs.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
35 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More