@gatling.io/postman 3.14.300 → 3.14.302
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/package.json +6 -5
- package/target/index.d.ts +1 -1
- package/target/index.js +2 -1
- package/target/postman/index.d.ts +24 -3
- package/target/postman/index.js +54 -18
- package/target/postman/jvm.d.ts +27 -0
- package/target/postman/jvm.js +6 -0
- package/target/postman/runtimeData.d.ts +32 -0
- package/target/postman/runtimeData.js +5 -0
- package/target/postman/utils.d.ts +24 -14
- package/target/postman/utils.js +22 -18
- package/target/postman/request.d.ts +0 -3
- package/target/postman/request.js +0 -125
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gatling.io/postman",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.302",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"homepage": "https://gatling.io",
|
|
6
6
|
"bugs": "https://github.com/gatling/gatling/issues",
|
|
@@ -20,20 +20,21 @@
|
|
|
20
20
|
"main": "target/index.js",
|
|
21
21
|
"types": "target/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@gatling.io/core": "3.14.
|
|
24
|
-
"@gatling.io/http": "3.14.
|
|
23
|
+
"@gatling.io/core": "3.14.302",
|
|
24
|
+
"@gatling.io/http": "3.14.302",
|
|
25
25
|
"mime-types": "3.0.1",
|
|
26
26
|
"postman-collection": "5.0.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/mime-types": "2.1.4",
|
|
30
30
|
"@types/jest": "29.5.14",
|
|
31
|
+
"crypto-js": "4.2.0",
|
|
31
32
|
"jest": "29.7.0",
|
|
32
33
|
"prettier": "3.5.3",
|
|
34
|
+
"moment": "2.30.1",
|
|
33
35
|
"rimraf": "6.0.1",
|
|
34
36
|
"ts-jest": "29.3.4",
|
|
35
|
-
"typescript": "5.8.3"
|
|
36
|
-
"workspace-version": "0.1.4"
|
|
37
|
+
"typescript": "5.8.3"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"clean": "rimraf target",
|
package/target/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Postman, PostmanCollection, PostmanCollectionFolder, postman } from "./postman";
|
|
1
|
+
export { Postman, PostmanCollection, PostmanCollectionFolder, PostmanProtocolBuilder, postman, postmanProtocol } from "./postman";
|
package/target/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postman = void 0;
|
|
3
|
+
exports.postmanProtocol = exports.postman = void 0;
|
|
4
4
|
var postman_1 = require("./postman");
|
|
5
5
|
Object.defineProperty(exports, "postman", { enumerable: true, get: function () { return postman_1.postman; } });
|
|
6
|
+
Object.defineProperty(exports, "postmanProtocol", { enumerable: true, get: function () { return postman_1.postmanProtocol; } });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Duration, ScenarioBuilder } from "@gatling.io/core";
|
|
2
|
-
import { HttpRequestActionBuilder } from "@gatling.io/http";
|
|
1
|
+
import { ActionBuilder, ChainBuilder, Duration, ScenarioBuilder, ProtocolBuilder } from "@gatling.io/core";
|
|
3
2
|
export interface Postman {
|
|
4
3
|
/**
|
|
5
4
|
* @param collectionPath - Path to an exported collection file in the project resources
|
|
@@ -19,6 +18,25 @@ export interface PostmanCollection extends PostmanCollectionFolder {
|
|
|
19
18
|
* @param variables - A dictionary of variables, or the path to an exported environment file in the project resources
|
|
20
19
|
*/
|
|
21
20
|
globals(variables: Record<string, string> | string): PostmanCollection;
|
|
21
|
+
/**
|
|
22
|
+
* Inject a CSV data file in the collection.
|
|
23
|
+
*/
|
|
24
|
+
csvDataFile(path: string): PostmanCollection;
|
|
25
|
+
/**
|
|
26
|
+
* Inject a JSON data file in the collection.
|
|
27
|
+
*/
|
|
28
|
+
jsonDataFile(path: string): PostmanCollection;
|
|
29
|
+
/**
|
|
30
|
+
* Call at the start of a scenario to initialize variables.
|
|
31
|
+
*/
|
|
32
|
+
initVariables: ChainBuilder;
|
|
33
|
+
export: PostmanCollectionExports;
|
|
34
|
+
}
|
|
35
|
+
export interface PostmanCollectionExports {
|
|
36
|
+
id: string;
|
|
37
|
+
collection: string;
|
|
38
|
+
environment: string;
|
|
39
|
+
globals: string;
|
|
22
40
|
}
|
|
23
41
|
export interface PostmanCollectionFolder {
|
|
24
42
|
/**
|
|
@@ -33,7 +51,7 @@ export interface PostmanCollectionFolder {
|
|
|
33
51
|
* @param request - Name of a request contained in the current folder
|
|
34
52
|
* @param overrideName - Optionally override the Gatling request name, otherwise the Postman request name will be used
|
|
35
53
|
*/
|
|
36
|
-
request(request: string, overrideName?: string):
|
|
54
|
+
request(request: string, overrideName?: string): ActionBuilder;
|
|
37
55
|
/**
|
|
38
56
|
* Create a Gatling scenario from the list of requests contained in the current folder.
|
|
39
57
|
*
|
|
@@ -49,3 +67,6 @@ export interface ScenarioOptions {
|
|
|
49
67
|
pauses?: Duration;
|
|
50
68
|
}
|
|
51
69
|
export declare const postman: Postman;
|
|
70
|
+
export interface PostmanProtocolBuilder extends ProtocolBuilder {
|
|
71
|
+
}
|
|
72
|
+
export declare const postmanProtocol: (...collections: PostmanCollection[]) => PostmanProtocolBuilder;
|
package/target/postman/index.js
CHANGED
|
@@ -1,45 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postman = void 0;
|
|
3
|
+
exports.postmanProtocol = exports.postman = void 0;
|
|
4
4
|
const core_1 = require("@gatling.io/core");
|
|
5
5
|
const jvm_1 = require("../jvm");
|
|
6
|
-
const
|
|
6
|
+
const runtimeData_1 = require("./runtimeData");
|
|
7
|
+
const jvm_2 = require("./jvm");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
(0, jvm_1.onInit)();
|
|
9
10
|
exports.postman = {
|
|
10
|
-
fromResource: (collectionPath) => postmanCollectionImpl((0,
|
|
11
|
+
fromResource: (collectionPath) => postmanCollectionImpl((0, core_1.readResourceAsString)(collectionPath), {}, {}, undefined)
|
|
12
|
+
};
|
|
13
|
+
const postmanCollectionImpl = (collection, environment, globals, dataFile) => {
|
|
14
|
+
const jsonCollection = (0, utils_1.parseCollection)(collection);
|
|
15
|
+
const runtimeDataKey = `postman-runtime-data-coll-${jsonCollection.info._postman_id}`;
|
|
16
|
+
const feeder = buildFeeder(dataFile);
|
|
17
|
+
const initVariables = (0, core_1.exec)((session) => {
|
|
18
|
+
const data = feeder !== undefined ? jvm_2.PostmanDataFile.feed(feeder) : {};
|
|
19
|
+
const newJvmSession = runtimeData_1.PostmanRuntimeData.createInSession(session._underlying, runtimeDataKey, globals, jsonCollection.variable.reduce((acc, v) => (v.disabled === true ? acc : { ...acc, [v.key]: v.value }), {}), environment, data, {});
|
|
20
|
+
return (0, core_1.wrapSession)(newJvmSession);
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
environment: (variables) => postmanCollectionImpl(collection, resolveEnvironment(variables), globals, dataFile),
|
|
24
|
+
globals: (variables) => postmanCollectionImpl(collection, environment, resolveEnvironment(variables), dataFile),
|
|
25
|
+
csvDataFile: (path) => postmanCollectionImpl(collection, environment, globals, { path, type: "csv" }),
|
|
26
|
+
jsonDataFile: (path) => postmanCollectionImpl(collection, environment, globals, { path, type: "json" }),
|
|
27
|
+
initVariables,
|
|
28
|
+
export: {
|
|
29
|
+
id: jsonCollection.info._postman_id,
|
|
30
|
+
collection,
|
|
31
|
+
environment: JSON.stringify(environment),
|
|
32
|
+
globals: JSON.stringify(globals)
|
|
33
|
+
},
|
|
34
|
+
...postmanCollectionFolder(jsonCollection.info._postman_id, [], jsonCollection, initVariables, runtimeDataKey)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const buildFeeder = (dataFile) => {
|
|
38
|
+
if (dataFile === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const builder = dataFile?.type === "csv" ? (0, core_1.csv)(dataFile.path) : (0, core_1.jsonFile)(dataFile.path);
|
|
43
|
+
return builder.circular()._underlying.asScala().apply();
|
|
44
|
+
}
|
|
11
45
|
};
|
|
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
46
|
const resolveEnvironment = (variables) => typeof variables === "string" ? (0, utils_1.readEnvironmentFromResource)(variables) : variables;
|
|
18
|
-
const
|
|
47
|
+
const postmanProtocol = (...collections) => ({
|
|
48
|
+
_underlying: jvm_2.PostmanDsl.postmanProtocol(collections.map((c) => c.export))
|
|
49
|
+
});
|
|
50
|
+
exports.postmanProtocol = postmanProtocol;
|
|
51
|
+
const postmanRequest = (requestName, collectionId, itemPath, runtimeDataKey) => (0, core_1.wrapActionBuilder)(jvm_2.PostmanDsl.postmanRequest(requestName, collectionId, itemPath, runtimeDataKey));
|
|
52
|
+
const postmanCollectionFolder = (collectionId, currentItemGroupPath, currentItemGroup, initVariables, runtimeDataKey) => ({
|
|
19
53
|
folder: (folder) => {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
54
|
+
const found = (0, utils_1.findItemGroup)(currentItemGroup, folder);
|
|
55
|
+
if (found === undefined) {
|
|
22
56
|
throw Error(`Postman folder '${folder}' not found`);
|
|
23
57
|
}
|
|
24
|
-
|
|
58
|
+
const [newItemGroup, newIndex] = found;
|
|
59
|
+
return postmanCollectionFolder(collectionId, [...currentItemGroupPath, newIndex], newItemGroup, initVariables, runtimeDataKey);
|
|
25
60
|
},
|
|
26
61
|
request: (request, overrideName) => {
|
|
27
62
|
const name = overrideName !== undefined ? overrideName : request;
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
63
|
+
const found = (0, utils_1.findItem)(currentItemGroup, request);
|
|
64
|
+
if (found === undefined) {
|
|
30
65
|
throw Error(`Postman request '${request}' not found`);
|
|
31
66
|
}
|
|
32
|
-
|
|
67
|
+
const [_, itemIndex] = found;
|
|
68
|
+
return postmanRequest(name, collectionId, [...currentItemGroupPath, itemIndex], runtimeDataKey);
|
|
33
69
|
},
|
|
34
70
|
scenario: (name, options) => {
|
|
35
|
-
let scn = (0, core_1.scenario)(name);
|
|
71
|
+
let scn = (0, core_1.scenario)(name).exec(initVariables);
|
|
36
72
|
const recursive = options?.recursive || false;
|
|
37
73
|
const pauses = options?.pauses;
|
|
38
|
-
(0, utils_1.listItems)(currentItemGroup, recursive).forEach((item, idx) => {
|
|
74
|
+
(0, utils_1.listItems)(currentItemGroup, currentItemGroupPath, recursive).forEach(([item, itemPath], idx) => {
|
|
39
75
|
if (pauses !== undefined && idx > 0) {
|
|
40
76
|
scn = scn.pause(pauses);
|
|
41
77
|
}
|
|
42
|
-
scn = scn.exec(
|
|
78
|
+
scn = scn.exec(postmanRequest(item.name, collectionId, itemPath, runtimeDataKey));
|
|
43
79
|
});
|
|
44
80
|
return scn;
|
|
45
81
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "@gatling.io/jvm-types";
|
|
2
|
+
import { ActionBuilder } from "@gatling.io/core";
|
|
3
|
+
import JvmProtocolBuilder = io.gatling.javaapi.core.ProtocolBuilder;
|
|
4
|
+
import JvmActionBuilder = io.gatling.javaapi.core.ActionBuilder;
|
|
5
|
+
import JvmChainBuilder = io.gatling.javaapi.core.ChainBuilder;
|
|
6
|
+
import { PostmanCollectionExports } from "./index";
|
|
7
|
+
export interface JvmPostmanProtocolBuilder extends JvmProtocolBuilder {
|
|
8
|
+
}
|
|
9
|
+
interface JvmPostmanRequestActionBuilder extends JvmActionBuilder {
|
|
10
|
+
asScala(): any;
|
|
11
|
+
toChainBuilder(): JvmChainBuilder;
|
|
12
|
+
}
|
|
13
|
+
export interface PostmanDslStatic {
|
|
14
|
+
postmanProtocol(collectionExports: PostmanCollectionExports[]): JvmPostmanProtocolBuilder;
|
|
15
|
+
postmanRequest(requestName: string, collectionId: string, itemPath: number[], runtimeDataKey: string): JvmPostmanRequestActionBuilder;
|
|
16
|
+
}
|
|
17
|
+
export declare const PostmanDsl: PostmanDslStatic;
|
|
18
|
+
export interface PostmanRequestActionBuilder extends ActionBuilder {
|
|
19
|
+
}
|
|
20
|
+
export interface ScalaFeeder {
|
|
21
|
+
next(): Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
export interface PostmanDataFileStatic {
|
|
24
|
+
feed(feeder: ScalaFeeder): Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
export declare const PostmanDataFile: PostmanDataFileStatic;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostmanDataFile = exports.PostmanDsl = void 0;
|
|
4
|
+
require("@gatling.io/jvm-types");
|
|
5
|
+
exports.PostmanDsl = Java.type("io.gatling.javaapi.postman.PostmanDsl");
|
|
6
|
+
exports.PostmanDataFile = Java.type("io.gatling.postman.PostmanDataFile");
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "@gatling.io/jvm-types";
|
|
2
|
+
import JvmSession = io.gatling.javaapi.core.Session;
|
|
3
|
+
import { MutationTracker, Variable } from "postman-collection";
|
|
4
|
+
export interface PostmanRuntimeDataStatic {
|
|
5
|
+
createInSession(session: JvmSession, key: string, globalVariables: Record<string, any>, collectionVariables: Record<string, any>, environmentVariables: Record<string, any>, dataVariables: Record<string, any>, localVariables: Record<string, any>): JvmSession;
|
|
6
|
+
}
|
|
7
|
+
export interface PostmanVariableScope {
|
|
8
|
+
toObject(excludeDisabled: boolean, caseSensitive: boolean): any;
|
|
9
|
+
has(key: string): boolean;
|
|
10
|
+
get(key: string): any;
|
|
11
|
+
set(key: string, value: any, type?: Variable.types): void;
|
|
12
|
+
unset(key: string): void;
|
|
13
|
+
clear(): void;
|
|
14
|
+
replaceIn(template: string | any): string | any;
|
|
15
|
+
enableTracking(options?: MutationTracker.definition): void;
|
|
16
|
+
disableTracking(): void;
|
|
17
|
+
toJSON(): any;
|
|
18
|
+
}
|
|
19
|
+
export interface JvmPostmanInfo {
|
|
20
|
+
eventName: string;
|
|
21
|
+
iteration: number;
|
|
22
|
+
iterationCount: number;
|
|
23
|
+
requestName: string;
|
|
24
|
+
requestId: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PostmanRuntimeData {
|
|
27
|
+
globalVariables: PostmanVariableScope;
|
|
28
|
+
collectionVariables: PostmanVariableScope;
|
|
29
|
+
environmentVariables: PostmanVariableScope;
|
|
30
|
+
localVariables: PostmanVariableScope;
|
|
31
|
+
}
|
|
32
|
+
export declare const PostmanRuntimeData: PostmanRuntimeDataStatic;
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
interface
|
|
3
|
-
|
|
1
|
+
export type IndexPath = number[];
|
|
2
|
+
export interface JsonCollection extends ItemGroupLike {
|
|
3
|
+
info: {
|
|
4
|
+
_postman_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
event: unknown[];
|
|
8
|
+
variable: Array<{
|
|
9
|
+
key: string;
|
|
10
|
+
value: string;
|
|
11
|
+
type: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export interface ItemGroup extends ItemGroupLike {
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Item {
|
|
4
19
|
name: string;
|
|
5
|
-
values: EnvironmentValue[];
|
|
6
20
|
}
|
|
7
|
-
interface
|
|
8
|
-
|
|
9
|
-
value: string;
|
|
10
|
-
type: "default" | "secret";
|
|
11
|
-
enabled: boolean;
|
|
21
|
+
export interface ItemGroupLike {
|
|
22
|
+
item: (Item | ItemGroup)[];
|
|
12
23
|
}
|
|
13
24
|
export declare const readEnvironmentFromResource: (filePath: string) => Record<string, string>;
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const findItemGroup: (parent:
|
|
16
|
-
export declare const findItem: (parent:
|
|
17
|
-
export declare const listItems: (parent:
|
|
18
|
-
export {};
|
|
25
|
+
export declare const parseCollection: (json: string) => JsonCollection;
|
|
26
|
+
export declare const findItemGroup: (parent: ItemGroupLike, name: string) => [ItemGroup, number] | undefined;
|
|
27
|
+
export declare const findItem: (parent: ItemGroupLike, name: string) => [Item, number] | undefined;
|
|
28
|
+
export declare const listItems: (parent: ItemGroupLike, currentPath: IndexPath, recursive: boolean) => Array<[Item, IndexPath]>;
|
package/target/postman/utils.js
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listItems = exports.findItem = exports.findItemGroup = exports.
|
|
4
|
-
const postman_collection_1 = require("postman-collection");
|
|
3
|
+
exports.listItems = exports.findItem = exports.findItemGroup = exports.parseCollection = exports.readEnvironmentFromResource = void 0;
|
|
5
4
|
const core_1 = require("@gatling.io/core");
|
|
6
5
|
const readEnvironmentFromResource = (filePath) => {
|
|
6
|
+
// TODO generate ids so it's "easier" to get items later on?
|
|
7
7
|
const env = JSON.parse((0, core_1.readResourceAsString)(filePath)); // TODO validate format
|
|
8
8
|
return Object.fromEntries(env.values.filter((v) => v.enabled).map((v) => [v.key, v.value]));
|
|
9
9
|
};
|
|
10
10
|
exports.readEnvironmentFromResource = readEnvironmentFromResource;
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
11
|
+
const parseCollection = (json) => JSON.parse(json);
|
|
12
|
+
exports.parseCollection = parseCollection;
|
|
13
13
|
const findItemGroup = (parent, name) => {
|
|
14
|
-
|
|
14
|
+
const index = parent.item.findIndex((i) => isItemGroup(i) && i.name === name);
|
|
15
|
+
return index >= 0 ? [parent.item[index], index] : undefined;
|
|
15
16
|
};
|
|
16
17
|
exports.findItemGroup = findItemGroup;
|
|
17
18
|
const findItem = (parent, name) => {
|
|
18
|
-
|
|
19
|
+
const index = parent.item.findIndex((i) => isItem(i) && i.name === name);
|
|
20
|
+
return index >= 0 ? [parent.item[index], index] : undefined;
|
|
19
21
|
};
|
|
20
22
|
exports.findItem = findItem;
|
|
21
|
-
const listItems = (parent, recursive) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const listItems = (parent, currentPath, recursive) => parent.item.flatMap((i, index) => {
|
|
24
|
+
if (isItem(i)) {
|
|
25
|
+
return [[i, [...currentPath, index]]];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
// i is an ItemGroup
|
|
29
|
+
if (recursive) {
|
|
30
|
+
return (0, exports.listItems)(i, [...currentPath, index], true);
|
|
26
31
|
}
|
|
27
|
-
else
|
|
28
|
-
|
|
32
|
+
else {
|
|
33
|
+
return [];
|
|
29
34
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
33
37
|
exports.listItems = listItems;
|
|
34
|
-
const
|
|
35
|
-
const
|
|
38
|
+
const isItemGroup = (i) => i.item !== undefined;
|
|
39
|
+
const isItem = (i) => !isItemGroup(i);
|
|
@@ -1,3 +0,0 @@
|
|
|
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;
|
|
@@ -1,125 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.postmanRequest = void 0;
|
|
37
|
-
const mime_types_1 = require("mime-types");
|
|
38
|
-
const pm = __importStar(require("postman-collection"));
|
|
39
|
-
const core_1 = require("@gatling.io/core");
|
|
40
|
-
const http_1 = require("@gatling.io/http");
|
|
41
|
-
const jvm_1 = require("../jvm");
|
|
42
|
-
const postmanRequest = (name, collection, item, environment, globals) => {
|
|
43
|
-
const variableDefinitions = [environment, collection.variables, globals];
|
|
44
|
-
const resolvedItem = new pm.Item(item.toObjectResolved(null, variableDefinitions, { ignoreOwnVariables: true }));
|
|
45
|
-
const method = resolvedItem.request.method;
|
|
46
|
-
const url = resolvedItem.request.url.toString();
|
|
47
|
-
const w = jvm_1.wrapUrl;
|
|
48
|
-
let gatlingRequest = w !== undefined
|
|
49
|
-
? (0, http_1.http)(name).httpRequest(method, (session) => w(url, session.userId()))
|
|
50
|
-
: (0, http_1.http)(name).httpRequest(method, url);
|
|
51
|
-
// Body
|
|
52
|
-
if (resolvedItem.request.body !== undefined) {
|
|
53
|
-
gatlingRequest = setBody(gatlingRequest, resolvedItem.request.body);
|
|
54
|
-
}
|
|
55
|
-
// Headers
|
|
56
|
-
resolvedItem.request.headers.each((h) => {
|
|
57
|
-
if (!h.disabled) {
|
|
58
|
-
gatlingRequest = gatlingRequest.header(h.key, h.value);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return gatlingRequest;
|
|
62
|
-
};
|
|
63
|
-
exports.postmanRequest = postmanRequest;
|
|
64
|
-
const setBody = (gatlingRequest, body) => {
|
|
65
|
-
switch (body.mode) {
|
|
66
|
-
case "formdata":
|
|
67
|
-
gatlingRequest = gatlingRequest.asMultipartForm();
|
|
68
|
-
if (body.formdata) {
|
|
69
|
-
body.formdata.each((param) => {
|
|
70
|
-
if (!param.disabled) {
|
|
71
|
-
if (param.type === "file") {
|
|
72
|
-
const filePath = resolveFile(param.src);
|
|
73
|
-
gatlingRequest = gatlingRequest.formUpload(param.key, filePath);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
gatlingRequest = gatlingRequest.formParam(param.key, param.value);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return gatlingRequest;
|
|
82
|
-
case "urlencoded":
|
|
83
|
-
gatlingRequest = gatlingRequest.asFormUrlEncoded();
|
|
84
|
-
if (body.urlencoded) {
|
|
85
|
-
body.urlencoded.each((param) => {
|
|
86
|
-
if (!param.disabled) {
|
|
87
|
-
gatlingRequest = gatlingRequest.formParam(param.key, param.value);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return gatlingRequest;
|
|
92
|
-
case "raw":
|
|
93
|
-
const language = body.options?.raw?.language || "text";
|
|
94
|
-
return gatlingRequest.body((0, core_1.StringBody)(body.raw || "")).header("content-type", rawContentTypes[language]);
|
|
95
|
-
case "file":
|
|
96
|
-
const src = resolveFile(body.file?.src || "");
|
|
97
|
-
const mimeType = (0, mime_types_1.lookup)(src) || "application/octet-stream";
|
|
98
|
-
return gatlingRequest.body((0, core_1.RawFileBody)(src)).header("content-type", mimeType);
|
|
99
|
-
case "graphql":
|
|
100
|
-
const query = body.graphql?.query;
|
|
101
|
-
const jsonBody = body.graphql?.variables !== undefined && body.graphql.variables.length > 0
|
|
102
|
-
? { query, variables: JSON.parse(body.graphql.variables) }
|
|
103
|
-
: { query };
|
|
104
|
-
return gatlingRequest.body((0, core_1.StringBody)(JSON.stringify(jsonBody))).asJson();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const rawContentTypes = {
|
|
108
|
-
text: "text/plain",
|
|
109
|
-
javascript: "application/javascript",
|
|
110
|
-
json: "application/json",
|
|
111
|
-
html: "text/html",
|
|
112
|
-
xml: "application/xml"
|
|
113
|
-
};
|
|
114
|
-
const resolveFile = (src) => {
|
|
115
|
-
if (src.startsWith("postman-cloud://")) {
|
|
116
|
-
// TODO implement downloading files from Postman Cloud
|
|
117
|
-
throw Error("Downloading files from Postman Cloud is not implemented yet, unable to retrieve " + src);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// TODO check if file exists
|
|
121
|
-
// File is assumed to be in the project resources by default
|
|
122
|
-
// TODO allow configuring location of Postman working directory in the protocol
|
|
123
|
-
return src;
|
|
124
|
-
}
|
|
125
|
-
};
|