@gatling.io/postman 3.14.301 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gatling.io/postman",
3
- "version": "3.14.301",
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,8 +20,8 @@
20
20
  "main": "target/index.js",
21
21
  "types": "target/index.d.ts",
22
22
  "dependencies": {
23
- "@gatling.io/core": "3.14.301",
24
- "@gatling.io/http": "3.14.301",
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
  },
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,4 +1,4 @@
1
- import { ActionBuilder, ChainBuilder, Duration, ScenarioBuilder } from "@gatling.io/core";
1
+ import { ActionBuilder, ChainBuilder, Duration, ScenarioBuilder, ProtocolBuilder } from "@gatling.io/core";
2
2
  export interface Postman {
3
3
  /**
4
4
  * @param collectionPath - Path to an exported collection file in the project resources
@@ -30,6 +30,13 @@ export interface PostmanCollection extends PostmanCollectionFolder {
30
30
  * Call at the start of a scenario to initialize variables.
31
31
  */
32
32
  initVariables: ChainBuilder;
33
+ export: PostmanCollectionExports;
34
+ }
35
+ export interface PostmanCollectionExports {
36
+ id: string;
37
+ collection: string;
38
+ environment: string;
39
+ globals: string;
33
40
  }
34
41
  export interface PostmanCollectionFolder {
35
42
  /**
@@ -60,3 +67,6 @@ export interface ScenarioOptions {
60
67
  pauses?: Duration;
61
68
  }
62
69
  export declare const postman: Postman;
70
+ export interface PostmanProtocolBuilder extends ProtocolBuilder {
71
+ }
72
+ export declare const postmanProtocol: (...collections: PostmanCollection[]) => PostmanProtocolBuilder;
@@ -1,21 +1,22 @@
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
6
  const runtimeData_1 = require("./runtimeData");
7
- const request_1 = require("./request");
7
+ const jvm_2 = require("./jvm");
8
8
  const utils_1 = require("./utils");
9
9
  (0, jvm_1.onInit)();
10
10
  exports.postman = {
11
- fromResource: (collectionPath) => postmanCollectionImpl((0, utils_1.readCollectionFromResource)(collectionPath), {}, {}, undefined)
11
+ fromResource: (collectionPath) => postmanCollectionImpl((0, core_1.readResourceAsString)(collectionPath), {}, {}, undefined)
12
12
  };
13
13
  const postmanCollectionImpl = (collection, environment, globals, dataFile) => {
14
- const runtimeDataKey = `postman-runtime-data-coll-${collection.id}`;
14
+ const jsonCollection = (0, utils_1.parseCollection)(collection);
15
+ const runtimeDataKey = `postman-runtime-data-coll-${jsonCollection.info._postman_id}`;
15
16
  const feeder = buildFeeder(dataFile);
16
17
  const initVariables = (0, core_1.exec)((session) => {
17
- const data = feeder !== undefined ? request_1.PostmanDataFile.feed(feeder) : {};
18
- const newJvmSession = runtimeData_1.PostmanRuntimeData.createInSession(session._underlying, runtimeDataKey, globals, collection.variables.toObject(true), environment, data, {});
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, {});
19
20
  return (0, core_1.wrapSession)(newJvmSession);
20
21
  });
21
22
  return {
@@ -24,7 +25,13 @@ const postmanCollectionImpl = (collection, environment, globals, dataFile) => {
24
25
  csvDataFile: (path) => postmanCollectionImpl(collection, environment, globals, { path, type: "csv" }),
25
26
  jsonDataFile: (path) => postmanCollectionImpl(collection, environment, globals, { path, type: "json" }),
26
27
  initVariables,
27
- ...postmanCollectionFolder(collection, collection, environment, globals, initVariables, runtimeDataKey)
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)
28
35
  };
29
36
  };
30
37
  const buildFeeder = (dataFile) => {
@@ -37,32 +44,38 @@ const buildFeeder = (dataFile) => {
37
44
  }
38
45
  };
39
46
  const resolveEnvironment = (variables) => typeof variables === "string" ? (0, utils_1.readEnvironmentFromResource)(variables) : variables;
40
- const postmanRequest = (requestName, postmanItem, runtimeDataKey) => (0, core_1.wrapActionBuilder)(request_1.PostmanDsl.postmanRequest(requestName, postmanItem, runtimeDataKey));
41
- const postmanCollectionFolder = (collection, currentItemGroup, environment, globals, initVariables, runtimeDataKey) => ({
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) => ({
42
53
  folder: (folder) => {
43
- const newItemGroup = (0, utils_1.findItemGroup)(currentItemGroup, folder);
44
- if (newItemGroup === undefined) {
54
+ const found = (0, utils_1.findItemGroup)(currentItemGroup, folder);
55
+ if (found === undefined) {
45
56
  throw Error(`Postman folder '${folder}' not found`);
46
57
  }
47
- return postmanCollectionFolder(collection, newItemGroup, environment, globals, initVariables, runtimeDataKey);
58
+ const [newItemGroup, newIndex] = found;
59
+ return postmanCollectionFolder(collectionId, [...currentItemGroupPath, newIndex], newItemGroup, initVariables, runtimeDataKey);
48
60
  },
49
61
  request: (request, overrideName) => {
50
62
  const name = overrideName !== undefined ? overrideName : request;
51
- const item = (0, utils_1.findItem)(currentItemGroup, request);
52
- if (item === undefined) {
63
+ const found = (0, utils_1.findItem)(currentItemGroup, request);
64
+ if (found === undefined) {
53
65
  throw Error(`Postman request '${request}' not found`);
54
66
  }
55
- return postmanRequest(name, item, runtimeDataKey);
67
+ const [_, itemIndex] = found;
68
+ return postmanRequest(name, collectionId, [...currentItemGroupPath, itemIndex], runtimeDataKey);
56
69
  },
57
70
  scenario: (name, options) => {
58
71
  let scn = (0, core_1.scenario)(name).exec(initVariables);
59
72
  const recursive = options?.recursive || false;
60
73
  const pauses = options?.pauses;
61
- (0, utils_1.listItems)(currentItemGroup, recursive).forEach((item, idx) => {
74
+ (0, utils_1.listItems)(currentItemGroup, currentItemGroupPath, recursive).forEach(([item, itemPath], idx) => {
62
75
  if (pauses !== undefined && idx > 0) {
63
76
  scn = scn.pause(pauses);
64
77
  }
65
- scn = scn.exec(postmanRequest(item.name, item, runtimeDataKey));
78
+ scn = scn.exec(postmanRequest(item.name, collectionId, itemPath, runtimeDataKey));
66
79
  });
67
80
  return scn;
68
81
  }
@@ -1,14 +1,18 @@
1
1
  import "@gatling.io/jvm-types";
2
2
  import { ActionBuilder } from "@gatling.io/core";
3
- import * as pm from "postman-collection";
3
+ import JvmProtocolBuilder = io.gatling.javaapi.core.ProtocolBuilder;
4
4
  import JvmActionBuilder = io.gatling.javaapi.core.ActionBuilder;
5
5
  import JvmChainBuilder = io.gatling.javaapi.core.ChainBuilder;
6
+ import { PostmanCollectionExports } from "./index";
7
+ export interface JvmPostmanProtocolBuilder extends JvmProtocolBuilder {
8
+ }
6
9
  interface JvmPostmanRequestActionBuilder extends JvmActionBuilder {
7
10
  asScala(): any;
8
11
  toChainBuilder(): JvmChainBuilder;
9
12
  }
10
13
  export interface PostmanDslStatic {
11
- postmanRequest(requestName: string, postmanItem: pm.Item, runtimeDataKey: string): JvmPostmanRequestActionBuilder;
14
+ postmanProtocol(collectionExports: PostmanCollectionExports[]): JvmPostmanProtocolBuilder;
15
+ postmanRequest(requestName: string, collectionId: string, itemPath: number[], runtimeDataKey: string): JvmPostmanRequestActionBuilder;
12
16
  }
13
17
  export declare const PostmanDsl: PostmanDslStatic;
14
18
  export interface PostmanRequestActionBuilder extends ActionBuilder {
@@ -1,18 +1,28 @@
1
- import { Collection, Item, ItemGroup } from "postman-collection";
2
- interface Environment {
3
- id: string;
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 EnvironmentValue {
8
- key: string;
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 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 {};
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]>;
@@ -1,35 +1,39 @@
1
1
  "use strict";
2
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");
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 readCollectionFromResource = (filePath, environment) => new postman_collection_1.Collection(JSON.parse((0, core_1.readResourceAsString)(filePath)), environment?.values);
12
- exports.readCollectionFromResource = readCollectionFromResource;
11
+ const parseCollection = (json) => JSON.parse(json);
12
+ exports.parseCollection = parseCollection;
13
13
  const findItemGroup = (parent, name) => {
14
- return parent.items.find((i) => isItemGroup(i) && i.name === name);
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
- return parent.items.find((i) => isItem(i) && i.name === name);
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
- const items = [];
23
- parent.items.each((item) => {
24
- if (isItem(item)) {
25
- items.push(item);
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 if (recursive && isItemGroup(item)) {
28
- items.push(...(0, exports.listItems)(item, true));
32
+ else {
33
+ return [];
29
34
  }
30
- });
31
- return items;
32
- };
35
+ }
36
+ });
33
37
  exports.listItems = listItems;
34
- const isItem = (i) => postman_collection_1.Item.isItem(i);
35
- const isItemGroup = (i) => postman_collection_1.ItemGroup.isItemGroup(i);
38
+ const isItemGroup = (i) => i.item !== undefined;
39
+ const isItem = (i) => !isItemGroup(i);
File without changes