@gatling.io/postman 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +585 -0
- package/jest.config.js +5 -0
- package/package.json +30 -0
- package/src/index.ts +1 -0
- package/src/jvm.ts +7 -0
- package/src/postman/index.ts +114 -0
- package/src/postman/request.ts +104 -0
- package/src/postman/utils.ts +48 -0
- package/src/typings/postman-collection.d.ts +2702 -0
- package/target/index.d.ts +1 -0
- package/target/index.js +5 -0
- package/target/jvm.d.ts +3 -0
- package/target/jvm.js +9 -0
- package/target/postman/index.d.ts +51 -0
- package/target/postman/index.js +46 -0
- package/target/postman/request.d.ts +3 -0
- package/target/postman/request.js +115 -0
- package/target/postman/utils.d.ts +18 -0
- package/target/postman/utils.js +35 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Postman, PostmanCollection, PostmanCollectionFolder, postman } from "./postman";
|
package/target/index.js
ADDED
package/target/jvm.d.ts
ADDED
package/target/jvm.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onExecute = exports.wrapUrl = exports.onInit = void 0;
|
|
4
|
+
const Usage = Java.type("io.gatling.postman.enterprise.Usage");
|
|
5
|
+
const onInit = () => Usage.onInit((msg) => console.log(msg));
|
|
6
|
+
exports.onInit = onInit;
|
|
7
|
+
exports.wrapUrl = Usage.wrapUrl;
|
|
8
|
+
const onExecute = (userId) => Usage.onExecute(userId);
|
|
9
|
+
exports.onExecute = onExecute;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Duration, ScenarioBuilder } from "@gatling.io/core";
|
|
2
|
+
import { HttpRequestActionBuilder } from "@gatling.io/http";
|
|
3
|
+
export interface Postman {
|
|
4
|
+
/**
|
|
5
|
+
* @param collectionPath - Path to an exported collection file in the project resources
|
|
6
|
+
*/
|
|
7
|
+
fromResource(collectionPath: string): PostmanCollection;
|
|
8
|
+
}
|
|
9
|
+
export interface PostmanCollection extends PostmanCollectionFolder {
|
|
10
|
+
/**
|
|
11
|
+
* Inject an environment in the collection.
|
|
12
|
+
*
|
|
13
|
+
* @param variables - A dictionary of variables, or the path to an exported environment file in the project resources
|
|
14
|
+
*/
|
|
15
|
+
environment(variables: Record<string, string> | string): PostmanCollection;
|
|
16
|
+
/**
|
|
17
|
+
* Inject global variables in the collection.
|
|
18
|
+
*
|
|
19
|
+
* @param variables - A dictionary of variables, or the path to an exported environment file in the project resources
|
|
20
|
+
*/
|
|
21
|
+
globals(variables: Record<string, string> | string): PostmanCollection;
|
|
22
|
+
}
|
|
23
|
+
export interface PostmanCollectionFolder {
|
|
24
|
+
/**
|
|
25
|
+
* Move down one level to a folder contained in the current folder.
|
|
26
|
+
*
|
|
27
|
+
* @param folder - Name of a folder contained in the current folder
|
|
28
|
+
*/
|
|
29
|
+
folder(folder: string): PostmanCollectionFolder;
|
|
30
|
+
/**
|
|
31
|
+
* Create a Gatling HTTP request from a Postman request contained in the current folder.
|
|
32
|
+
*
|
|
33
|
+
* @param request - Name of a request contained in the current folder
|
|
34
|
+
* @param overrideName - Optionally override the Gatling request name, otherwise the Postman request name will be used
|
|
35
|
+
*/
|
|
36
|
+
request(request: string, overrideName?: string): HttpRequestActionBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* Create a Gatling scenario from the list of requests contained in the current folder.
|
|
39
|
+
*
|
|
40
|
+
* @param name - Name of the scenario
|
|
41
|
+
* @param options -
|
|
42
|
+
*/
|
|
43
|
+
scenario(name: string, options?: ScenarioOptions): ScenarioBuilder;
|
|
44
|
+
}
|
|
45
|
+
export interface ScenarioOptions {
|
|
46
|
+
/** Include requests in sub-folders, false by default. */
|
|
47
|
+
recursive?: boolean;
|
|
48
|
+
/** Include this pause time between requests, no pause by default. */
|
|
49
|
+
pauses?: Duration;
|
|
50
|
+
}
|
|
51
|
+
export declare const postman: Postman;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postman = void 0;
|
|
4
|
+
const core_1 = require("@gatling.io/core");
|
|
5
|
+
const jvm_1 = require("../jvm");
|
|
6
|
+
const request_1 = require("./request");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
(0, jvm_1.onInit)();
|
|
9
|
+
exports.postman = {
|
|
10
|
+
fromResource: (collectionPath) => postmanCollectionImpl((0, utils_1.readCollectionFromResource)(collectionPath), {}, {})
|
|
11
|
+
};
|
|
12
|
+
const postmanCollectionImpl = (collection, environment, globals) => ({
|
|
13
|
+
environment: (variables) => postmanCollectionImpl(collection, resolveEnvironment(variables), globals),
|
|
14
|
+
globals: (variables) => postmanCollectionImpl(collection, environment, resolveEnvironment(variables)),
|
|
15
|
+
...postmanCollectionFolder(collection, collection, environment, globals)
|
|
16
|
+
});
|
|
17
|
+
const resolveEnvironment = (variables) => typeof variables === "string" ? (0, utils_1.readEnvironmentFromResource)(variables) : variables;
|
|
18
|
+
const postmanCollectionFolder = (collection, currentItemGroup, environment, globals) => ({
|
|
19
|
+
folder: (folder) => {
|
|
20
|
+
const newItemGroup = (0, utils_1.findItemGroup)(currentItemGroup, folder);
|
|
21
|
+
if (newItemGroup === undefined) {
|
|
22
|
+
throw Error(`Postman folder '${folder}' not found`);
|
|
23
|
+
}
|
|
24
|
+
return postmanCollectionFolder(collection, newItemGroup, environment, globals);
|
|
25
|
+
},
|
|
26
|
+
request: (request, overrideName) => {
|
|
27
|
+
const name = overrideName !== undefined ? overrideName : request;
|
|
28
|
+
const item = (0, utils_1.findItem)(currentItemGroup, request);
|
|
29
|
+
if (item === undefined) {
|
|
30
|
+
throw Error(`Postman request '${request}' not found`);
|
|
31
|
+
}
|
|
32
|
+
return (0, request_1.postmanRequest)(name, collection, item, environment, globals);
|
|
33
|
+
},
|
|
34
|
+
scenario: (name, options) => {
|
|
35
|
+
let scn = (0, core_1.scenario)(name);
|
|
36
|
+
const recursive = options?.recursive || false;
|
|
37
|
+
const pauses = options?.pauses;
|
|
38
|
+
(0, utils_1.listItems)(currentItemGroup, recursive).forEach((item, idx) => {
|
|
39
|
+
if (pauses !== undefined && idx > 0) {
|
|
40
|
+
scn = scn.pause(pauses);
|
|
41
|
+
}
|
|
42
|
+
scn = scn.exec((0, request_1.postmanRequest)(item.name, collection, item, environment, globals));
|
|
43
|
+
});
|
|
44
|
+
return scn;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as pm from "postman-collection";
|
|
2
|
+
import { HttpRequestActionBuilder } from "@gatling.io/http";
|
|
3
|
+
export declare const postmanRequest: (name: string, collection: pm.Collection, item: pm.Item, environment: Record<string, string>, globals: Record<string, string>) => HttpRequestActionBuilder;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.postmanRequest = void 0;
|
|
27
|
+
const mime_types_1 = require("mime-types");
|
|
28
|
+
const pm = __importStar(require("postman-collection"));
|
|
29
|
+
const core_1 = require("@gatling.io/core");
|
|
30
|
+
const http_1 = require("@gatling.io/http");
|
|
31
|
+
const jvm_1 = require("../jvm");
|
|
32
|
+
const postmanRequest = (name, collection, item, environment, globals) => {
|
|
33
|
+
const variableDefinitions = [environment, collection.variables, globals];
|
|
34
|
+
const resolvedItem = new pm.Item(item.toObjectResolved(null, variableDefinitions, { ignoreOwnVariables: true }));
|
|
35
|
+
const method = resolvedItem.request.method;
|
|
36
|
+
const url = resolvedItem.request.url.toString();
|
|
37
|
+
const w = jvm_1.wrapUrl;
|
|
38
|
+
let gatlingRequest = w !== undefined
|
|
39
|
+
? (0, http_1.http)(name).httpRequest(method, (session) => w(url, session.userId()))
|
|
40
|
+
: (0, http_1.http)(name).httpRequest(method, url);
|
|
41
|
+
// Body
|
|
42
|
+
if (resolvedItem.request.body !== undefined) {
|
|
43
|
+
gatlingRequest = setBody(gatlingRequest, resolvedItem.request.body);
|
|
44
|
+
}
|
|
45
|
+
// Headers
|
|
46
|
+
resolvedItem.request.headers.each((h) => {
|
|
47
|
+
if (!h.disabled) {
|
|
48
|
+
gatlingRequest = gatlingRequest.header(h.key, h.value);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return gatlingRequest;
|
|
52
|
+
};
|
|
53
|
+
exports.postmanRequest = postmanRequest;
|
|
54
|
+
const setBody = (gatlingRequest, body) => {
|
|
55
|
+
switch (body.mode) {
|
|
56
|
+
case "formdata":
|
|
57
|
+
gatlingRequest = gatlingRequest.asMultipartForm();
|
|
58
|
+
if (body.formdata) {
|
|
59
|
+
body.formdata.each((param) => {
|
|
60
|
+
if (!param.disabled) {
|
|
61
|
+
if (param.type === "file") {
|
|
62
|
+
const filePath = resolveFile(param.src);
|
|
63
|
+
gatlingRequest = gatlingRequest.formUpload(param.key, filePath);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
gatlingRequest = gatlingRequest.formParam(param.key, param.value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return gatlingRequest;
|
|
72
|
+
case "urlencoded":
|
|
73
|
+
gatlingRequest = gatlingRequest.asFormUrlEncoded();
|
|
74
|
+
if (body.urlencoded) {
|
|
75
|
+
body.urlencoded.each((param) => {
|
|
76
|
+
if (!param.disabled) {
|
|
77
|
+
gatlingRequest = gatlingRequest.formParam(param.key, param.value);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return gatlingRequest;
|
|
82
|
+
case "raw":
|
|
83
|
+
const language = body.options?.raw?.language || "text";
|
|
84
|
+
return gatlingRequest.body((0, core_1.StringBody)(body.raw || "")).header("content-type", rawContentTypes[language]);
|
|
85
|
+
case "file":
|
|
86
|
+
const src = resolveFile(body.file?.src || "");
|
|
87
|
+
const mimeType = (0, mime_types_1.lookup)(src) || "application/octet-stream";
|
|
88
|
+
return gatlingRequest.body((0, core_1.RawFileBody)(src)).header("content-type", mimeType);
|
|
89
|
+
case "graphql":
|
|
90
|
+
const query = body.graphql?.query;
|
|
91
|
+
const jsonBody = body.graphql?.variables !== undefined && body.graphql.variables.length > 0
|
|
92
|
+
? { query, variables: JSON.parse(body.graphql.variables) }
|
|
93
|
+
: { query };
|
|
94
|
+
return gatlingRequest.body((0, core_1.StringBody)(JSON.stringify(jsonBody))).asJson();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const rawContentTypes = {
|
|
98
|
+
text: "text/plain",
|
|
99
|
+
javascript: "application/javascript",
|
|
100
|
+
json: "application/json",
|
|
101
|
+
html: "text/html",
|
|
102
|
+
xml: "application/xml"
|
|
103
|
+
};
|
|
104
|
+
const resolveFile = (src) => {
|
|
105
|
+
if (src.startsWith("postman-cloud://")) {
|
|
106
|
+
// TODO implement downloading files from Postman Cloud
|
|
107
|
+
throw Error("Downloading files from Postman Cloud is not implemented yet, unable to retrieve " + src);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// TODO check if file exists
|
|
111
|
+
// File is assumed to be in the project resources by default
|
|
112
|
+
// TODO allow configuring location of Postman working directory in the protocol
|
|
113
|
+
return src;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Collection, Item, ItemGroup } from "postman-collection";
|
|
2
|
+
interface Environment {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
values: EnvironmentValue[];
|
|
6
|
+
}
|
|
7
|
+
interface EnvironmentValue {
|
|
8
|
+
key: string;
|
|
9
|
+
value: string;
|
|
10
|
+
type: "default" | "secret";
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const readEnvironmentFromResource: (filePath: string) => Record<string, string>;
|
|
14
|
+
export declare const readCollectionFromResource: (filePath: string, environment?: Environment) => Collection;
|
|
15
|
+
export declare const findItemGroup: (parent: ItemGroup, name: string) => ItemGroup | undefined;
|
|
16
|
+
export declare const findItem: (parent: ItemGroup, name: string) => Item | undefined;
|
|
17
|
+
export declare const listItems: (parent: ItemGroup, recursive: boolean) => Item[];
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listItems = exports.findItem = exports.findItemGroup = exports.readCollectionFromResource = exports.readEnvironmentFromResource = void 0;
|
|
4
|
+
const postman_collection_1 = require("postman-collection");
|
|
5
|
+
const core_1 = require("@gatling.io/core");
|
|
6
|
+
const readEnvironmentFromResource = (filePath) => {
|
|
7
|
+
const env = JSON.parse((0, core_1.readResourceAsString)(filePath)); // TODO validate format
|
|
8
|
+
return Object.fromEntries(env.values.filter((v) => v.enabled).map((v) => [v.key, v.value]));
|
|
9
|
+
};
|
|
10
|
+
exports.readEnvironmentFromResource = readEnvironmentFromResource;
|
|
11
|
+
const readCollectionFromResource = (filePath, environment) => new postman_collection_1.Collection(JSON.parse((0, core_1.readResourceAsString)(filePath)), environment?.values);
|
|
12
|
+
exports.readCollectionFromResource = readCollectionFromResource;
|
|
13
|
+
const findItemGroup = (parent, name) => {
|
|
14
|
+
return parent.items.find((i) => isItemGroup(i) && i.name === name);
|
|
15
|
+
};
|
|
16
|
+
exports.findItemGroup = findItemGroup;
|
|
17
|
+
const findItem = (parent, name) => {
|
|
18
|
+
return parent.items.find((i) => isItem(i) && i.name === name);
|
|
19
|
+
};
|
|
20
|
+
exports.findItem = findItem;
|
|
21
|
+
const listItems = (parent, recursive) => {
|
|
22
|
+
const items = [];
|
|
23
|
+
parent.items.each((item) => {
|
|
24
|
+
if (isItem(item)) {
|
|
25
|
+
items.push(item);
|
|
26
|
+
}
|
|
27
|
+
else if (recursive && isItemGroup(item)) {
|
|
28
|
+
items.concat((0, exports.listItems)(item, true));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return items;
|
|
32
|
+
};
|
|
33
|
+
exports.listItems = listItems;
|
|
34
|
+
const isItem = (i) => postman_collection_1.Item.isItem(i);
|
|
35
|
+
const isItemGroup = (i) => postman_collection_1.ItemGroup.isItemGroup(i);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "./",
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"outDir": "target",
|
|
6
|
+
"lib": ["es2021"],
|
|
7
|
+
"target": "es2021",
|
|
8
|
+
"module": "node16",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"moduleResolution": "node16",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"typeRoots": [
|
|
16
|
+
"src/typings",
|
|
17
|
+
"node_modules/@types"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts"],
|
|
21
|
+
"exclude": ["**/*.test.ts", "jest.config.ts"]
|
|
22
|
+
}
|