@skyramp/skyramp 1.0.0-sha.b2dfe11 → 1.2.2
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 +21 -0
- package/README.md +10 -17
- package/package.json +14 -5
- package/scripts/download-binary.js +189 -0
- package/src/classes/Asserts.d.ts +16 -0
- package/src/classes/Asserts.js +41 -0
- package/src/classes/AsyncScenario.d.ts +133 -0
- package/src/classes/AsyncScenario.js +324 -0
- package/src/classes/AsyncTestStatus.d.ts +172 -0
- package/src/classes/AsyncTestStatus.js +488 -0
- package/src/classes/DelayConfig.d.ts +4 -0
- package/src/classes/DelayConfig.js +25 -0
- package/src/classes/Endpoint.d.ts +2 -2
- package/src/classes/Endpoint.js +81 -43
- package/src/classes/GrpcEndpoint.d.ts +1 -1
- package/src/classes/GrpcEndpoint.js +24 -3
- package/src/classes/LoadTestConfig.d.ts +131 -0
- package/src/classes/LoadTestConfig.js +186 -0
- package/src/classes/Protocol.d.ts +5 -0
- package/src/classes/Protocol.js +8 -0
- package/src/classes/RequestV2.d.ts +30 -0
- package/src/classes/RequestV2.js +181 -0
- package/src/classes/RequestValue.d.ts +24 -0
- package/src/classes/RequestValue.js +113 -0
- package/src/classes/ResponseV2.d.ts +24 -0
- package/src/classes/ResponseV2.js +96 -0
- package/src/classes/ResponseValue.d.ts +21 -0
- package/src/classes/ResponseValue.js +93 -0
- package/src/classes/RestEndpoint.d.ts +11 -2
- package/src/classes/RestEndpoint.js +90 -5
- package/src/classes/RestParam.d.ts +4 -0
- package/src/classes/RestParam.js +32 -0
- package/src/classes/Scenario.d.ts +48 -0
- package/src/classes/Scenario.js +208 -0
- package/src/classes/SkyrampClient.d.ts +184 -4
- package/src/classes/SkyrampClient.js +774 -40
- package/src/classes/Step.d.ts +28 -0
- package/src/classes/Step.js +113 -0
- package/src/classes/TrafficConfig.d.ts +6 -0
- package/src/classes/TrafficConfig.js +28 -0
- package/src/function.js +46 -0
- package/src/index.d.ts +14 -1
- package/src/index.js +36 -3
- package/src/lib.js +6 -6
- package/src/utils.js +180 -20
- package/src/utils.d.ts +0 -5
|
@@ -2,10 +2,31 @@ const Endpoint = require('./Endpoint');
|
|
|
2
2
|
const lib = require('../lib');
|
|
3
3
|
const newGrpcEndpointWrapper = lib.func('newGrpcEndpointWrapper', 'string', ['string', 'string', 'int', 'string']);
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The `GrpcEndpoint` class represents a gRPC API Endpoint.
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
5
9
|
class GrpcEndpoint extends Endpoint {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Intialize a new instance of a gRPC endpoint.
|
|
12
|
+
* @constructor
|
|
13
|
+
* @param {string} name - The name of the endpoint.
|
|
14
|
+
* @param {string} service - The name of the service.
|
|
15
|
+
* @param {number} port - The port number.
|
|
16
|
+
* @param {string} pbFile - The protocol buffer file containing the API schema definition.
|
|
17
|
+
* @param {string} endpointAddress - The endpoint address.
|
|
18
|
+
*/
|
|
19
|
+
constructor(...args) {
|
|
20
|
+
let name, service, port, pbFile, endpointAddress;
|
|
21
|
+
if (args.length === 1 && typeof args[0] === 'object') {
|
|
22
|
+
({ name, service, port, pbFile, endpointAddress } = args[0]);
|
|
23
|
+
} else if (args.length >= 4) {
|
|
24
|
+
[name, service, port, pbFile, endpointAddress] = args;
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error('Invalid arguments for GrpcEndpoint constructor');
|
|
27
|
+
}
|
|
28
|
+
const grpcEndPointData = newGrpcEndpointWrapper(name, service, port, pbFile, endpointAddress);
|
|
29
|
+
super(grpcEndPointData, endpointAddress);
|
|
9
30
|
}
|
|
10
31
|
}
|
|
11
32
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
export interface LoadTestConfigOptions {
|
|
2
|
+
loadDuration?: number;
|
|
3
|
+
loadNumThreads?: number;
|
|
4
|
+
loadTargetRPS?: number;
|
|
5
|
+
loadCount?: number;
|
|
6
|
+
loadAtOnce?: number;
|
|
7
|
+
loadStopOnFailure?: boolean;
|
|
8
|
+
loadRampupDuration?: number;
|
|
9
|
+
loadRampupInterval?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export class LoadTestConfig {
|
|
14
|
+
duration?: number;
|
|
15
|
+
numThreads?: number;
|
|
16
|
+
targetRPS?: number;
|
|
17
|
+
count?: number;
|
|
18
|
+
atOnce?: number;
|
|
19
|
+
stopOnFailure?: boolean;
|
|
20
|
+
rampupDuration?: number;
|
|
21
|
+
rampupInterval?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Constructor for LoadTestConfig with options object
|
|
25
|
+
* @param options Configuration options
|
|
26
|
+
*/
|
|
27
|
+
constructor(options?: LoadTestConfigOptions);
|
|
28
|
+
|
|
29
|
+
// Getters
|
|
30
|
+
/**
|
|
31
|
+
* Gets the duration of the load test
|
|
32
|
+
* @returns The duration in seconds
|
|
33
|
+
*/
|
|
34
|
+
getDuration(): number | undefined;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the number of threads
|
|
38
|
+
* @returns The number of threads
|
|
39
|
+
*/
|
|
40
|
+
getNumThreads(): number | undefined;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the target requests per second
|
|
44
|
+
* @returns The target RPS
|
|
45
|
+
*/
|
|
46
|
+
getTargetRPS(): number | undefined;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the count of requests
|
|
50
|
+
* @returns The request count
|
|
51
|
+
*/
|
|
52
|
+
getCount(): number | undefined;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets the atOnce value
|
|
56
|
+
* @returns The atOnce value
|
|
57
|
+
*/
|
|
58
|
+
getAtOnce(): number | undefined;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets whether to stop on failure
|
|
62
|
+
* @returns The stopOnFailure boolean
|
|
63
|
+
*/
|
|
64
|
+
getStopOnFailure(): boolean | undefined;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Gets the ramp up duration
|
|
68
|
+
* @returns The ramp up duration in seconds
|
|
69
|
+
*/
|
|
70
|
+
getRampupDuration(): number | undefined;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets the ramp up interval
|
|
74
|
+
* @returns The ramp up interval in seconds
|
|
75
|
+
*/
|
|
76
|
+
getRampupInterval(): number | undefined;
|
|
77
|
+
|
|
78
|
+
// Setters
|
|
79
|
+
/**
|
|
80
|
+
* Sets the duration of the load test
|
|
81
|
+
* @param duration The duration in seconds
|
|
82
|
+
*/
|
|
83
|
+
setDuration(duration: number): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sets the number of threads
|
|
87
|
+
* @param numThreads The number of threads
|
|
88
|
+
*/
|
|
89
|
+
setNumThreads(numThreads: number): void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Sets the target requests per second
|
|
93
|
+
* @param targetRPS The target RPS
|
|
94
|
+
*/
|
|
95
|
+
setTargetRPS(targetRPS: number): void;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sets the count of requests
|
|
99
|
+
* @param count The request count
|
|
100
|
+
*/
|
|
101
|
+
setCount(count: number): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Sets the atOnce value
|
|
105
|
+
* @param atOnce The atOnce value
|
|
106
|
+
*/
|
|
107
|
+
setAtOnce(atOnce: number): void;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sets whether to stop on failure
|
|
111
|
+
* @param stopOnFailure The stopOnFailure boolean
|
|
112
|
+
*/
|
|
113
|
+
setStopOnFailure(stopOnFailure: boolean): void;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets the ramp up duration
|
|
117
|
+
* @param rampUpDuration The ramp up duration in seconds
|
|
118
|
+
*/
|
|
119
|
+
setRampupDuration(rampUpDuration: number): void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Sets the ramp up interval
|
|
123
|
+
* @param rampUpInterval The ramp up interval in seconds
|
|
124
|
+
*/
|
|
125
|
+
setRampupInterval(rampUpInterval: number): void;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Converts the configuration to JSON string
|
|
129
|
+
*/
|
|
130
|
+
toJson(): string;
|
|
131
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration class for load testing parameters
|
|
3
|
+
*/
|
|
4
|
+
class LoadTestConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new LoadTestConfig instance
|
|
7
|
+
* @param {Object} options - Configuration options
|
|
8
|
+
* @param {number} [options.duration] - Duration of the load test in seconds
|
|
9
|
+
* @param {number} [options.numThreads] - Number of threads to use for the load test
|
|
10
|
+
* @param {number} [options.targetRPS] - Target requests per second
|
|
11
|
+
* @param {number} [options.count] - Number of requests to make
|
|
12
|
+
* @param {number} [options.atOnce] - Number of requests to send at once
|
|
13
|
+
* @param {boolean} [options.stopOnFailure=true] - Whether to stop on failure
|
|
14
|
+
* @param {number} [options.rampUpDuration] - Duration of the ramp up period in seconds
|
|
15
|
+
* @param {number} [options.rampUpInterval] - Interval between ramp up steps in seconds
|
|
16
|
+
*/
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
{
|
|
19
|
+
this.duration = options.loadDuration;
|
|
20
|
+
this.numThreads = options.loadNumThreads;
|
|
21
|
+
this.targetRPS = options.loadTargetRPS;
|
|
22
|
+
this.count = options.loadCount;
|
|
23
|
+
this.atOnce = options.loadAtOnce;
|
|
24
|
+
this.stopOnFailure = options.loadStopOnFailure || true;
|
|
25
|
+
this.rampupDuration = options.loadRampupDuration;
|
|
26
|
+
this.rampupInterval = options.loadRampupInterval;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Getters
|
|
31
|
+
/**
|
|
32
|
+
* Gets the duration of the load test
|
|
33
|
+
* @returns {number|undefined} The duration in seconds
|
|
34
|
+
*/
|
|
35
|
+
getDuration() {
|
|
36
|
+
return this.duration;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the number of threads
|
|
41
|
+
* @returns {number|undefined} The number of threads
|
|
42
|
+
*/
|
|
43
|
+
getNumThreads() {
|
|
44
|
+
return this.numThreads;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Gets the target requests per second
|
|
49
|
+
* @returns {number|undefined} The target RPS
|
|
50
|
+
*/
|
|
51
|
+
getTargetRPS() {
|
|
52
|
+
return this.targetRPS;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Gets the count of requests
|
|
57
|
+
* @returns {number|undefined} The request count
|
|
58
|
+
*/
|
|
59
|
+
getCount() {
|
|
60
|
+
return this.count;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets the atOnce value
|
|
65
|
+
* @returns {number|undefined} The atOnce value
|
|
66
|
+
*/
|
|
67
|
+
getAtOnce() {
|
|
68
|
+
return this.atOnce;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets whether to stop on failure
|
|
73
|
+
* @returns {boolean|undefined} The stopOnFailure boolean
|
|
74
|
+
*/
|
|
75
|
+
getStopOnFailure() {
|
|
76
|
+
return this.stopOnFailure;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Gets the ramp up duration
|
|
81
|
+
* @returns {number|undefined} The ramp up duration in seconds
|
|
82
|
+
*/
|
|
83
|
+
getRampupDuration() {
|
|
84
|
+
return this.rampupDuration;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Gets the ramp up interval
|
|
89
|
+
* @returns {number|undefined} The ramp up interval in seconds
|
|
90
|
+
*/
|
|
91
|
+
getRampupInterval() {
|
|
92
|
+
return this.rampupInterval;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Setters
|
|
96
|
+
/**
|
|
97
|
+
* Sets the duration of the load test
|
|
98
|
+
* @param {number} duration - The duration in seconds
|
|
99
|
+
*/
|
|
100
|
+
setDuration(duration) {
|
|
101
|
+
this.duration = duration;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets the number of threads
|
|
106
|
+
* @param {number} numThreads - The number of threads
|
|
107
|
+
*/
|
|
108
|
+
setNumThreads(numThreads) {
|
|
109
|
+
this.numThreads = numThreads;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sets the target requests per second
|
|
114
|
+
* @param {number} targetRPS - The target RPS
|
|
115
|
+
*/
|
|
116
|
+
setTargetRPS(targetRPS) {
|
|
117
|
+
this.targetRPS = targetRPS;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sets the count of requests
|
|
122
|
+
* @param {number} count - The request count
|
|
123
|
+
*/
|
|
124
|
+
setCount(count) {
|
|
125
|
+
this.count = count;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Sets the atOnce value
|
|
130
|
+
* @param {number} atOnce - The atOnce value
|
|
131
|
+
*/
|
|
132
|
+
setAtOnce(atOnce) {
|
|
133
|
+
this.atOnce = atOnce;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sets whether to stop on failure
|
|
138
|
+
* @param {boolean} stopOnFailure - The stopOnFailure boolean
|
|
139
|
+
*/
|
|
140
|
+
setStopOnFailure(stopOnFailure) {
|
|
141
|
+
this.stopOnFailure = stopOnFailure;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Sets the ramp up duration
|
|
146
|
+
* @param {number} rampupDuration - The ramp up duration in seconds
|
|
147
|
+
*/
|
|
148
|
+
setRampupDuration(rampupDuration) {
|
|
149
|
+
this.rampupDuration = rampupDuration;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Sets the ramp up interval
|
|
154
|
+
* @param {number} rampUpInterval - The ramp up interval in seconds
|
|
155
|
+
*/
|
|
156
|
+
setRampupInterval(rampupInterval) {
|
|
157
|
+
this.rampupInterval = rampupInterval;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Converts the configuration to JSON string
|
|
162
|
+
* @returns {string} JSON string representation of the configuration
|
|
163
|
+
*/
|
|
164
|
+
toJson() {
|
|
165
|
+
const result = {
|
|
166
|
+
duration: this.duration,
|
|
167
|
+
numThreads: this.numThreads,
|
|
168
|
+
targetRPS: this.targetRPS,
|
|
169
|
+
count: this.count,
|
|
170
|
+
atOnce: this.atOnce,
|
|
171
|
+
stopOnFailure: this.stopOnFailure,
|
|
172
|
+
};
|
|
173
|
+
if (this.rampupDuration || this.rampupInterval) {
|
|
174
|
+
result.rampUp = {
|
|
175
|
+
duration: this.rampupDuration,
|
|
176
|
+
interval: this.rampupInterval
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return JSON.stringify(result);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
module.exports = {
|
|
185
|
+
LoadTestConfig
|
|
186
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a REST request.
|
|
3
|
+
*/
|
|
4
|
+
interface RequestV2Options {
|
|
5
|
+
name?: string;
|
|
6
|
+
url: string;
|
|
7
|
+
path: string;
|
|
8
|
+
method: string;
|
|
9
|
+
body?: string;
|
|
10
|
+
headers?: {[headerName: string]: string};
|
|
11
|
+
cookies?: {[cookieName: string]: string};
|
|
12
|
+
dataOverride?: {[dataName: string]: string | number | boolean | object};
|
|
13
|
+
pathParams?: {[pathName: string]: string | number | boolean | object};
|
|
14
|
+
queryParams?: {[queryName: string]: string | number | boolean | object};
|
|
15
|
+
formParams?: {[formParamName: string]: string | number | boolean | object};
|
|
16
|
+
expectedCode?: string;
|
|
17
|
+
funcHandler?: string;
|
|
18
|
+
funcHandlerType?: string;
|
|
19
|
+
insecure?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class RequestV2 {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of RequestV2.
|
|
24
|
+
* @param options - The options for creating the request.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: RequestV2Options);
|
|
27
|
+
toYaml(): string;
|
|
28
|
+
toJson(): string;
|
|
29
|
+
asRequestDict(): {[key: string]: string | number | boolean | object | null};
|
|
30
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const yaml = require('js-yaml');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a REST request.
|
|
5
|
+
*/
|
|
6
|
+
class RequestV2 {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of RequestV2.
|
|
9
|
+
* @param {Object} [options={}] - The options for creating the request.
|
|
10
|
+
* @param {string} [options.name=''] - The name of the request.
|
|
11
|
+
* @param {string} [options.url=''] - The URL of the request.
|
|
12
|
+
* @param {string} [options.path=''] - The REST path of the request.
|
|
13
|
+
* @param {string} [options.method=''] - The HTTP method of the request.
|
|
14
|
+
* @param {string} [options.body=''] - The request body in JSON format.
|
|
15
|
+
* @param {Object.<string, string>} [options.headers={}] - The HTTP headers of the request.
|
|
16
|
+
* @param {Object.<string, string>} [options.cookies={}] - The HTTP cookies of the request.
|
|
17
|
+
* @param {Object.<string, *>} [options.dataOverride={}] - The data override for the request.
|
|
18
|
+
* @param {Object.<string, *>} [options.pathParams={}] - The path parameters for the request.
|
|
19
|
+
* @param {Object.<string, *>} [options.queryParams={}] - The query parameters for the request.
|
|
20
|
+
* @param {Object.<string, *>} [options.formParams={}] - The form parameters of the request.
|
|
21
|
+
* @param {string} [options.expectedCode=''] - The expected HTTP status code of the response.
|
|
22
|
+
* @param {string} [options.funcHandler=''] - The dynamic handler function for the request.
|
|
23
|
+
* @param {string} [options.funcHandlerType=''] - The type of the dynamic handler (e.g., 'python', 'javascript').
|
|
24
|
+
* @param {boolean} [options.insecure=false] - Skip cert verification if set.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
this.name = options.name || '';
|
|
28
|
+
this.url = options.url || '';
|
|
29
|
+
this.path = options.path || '';
|
|
30
|
+
this.method = options.method || '';
|
|
31
|
+
this.body = options.body || '';
|
|
32
|
+
this.headers = options.headers || {};
|
|
33
|
+
this.cookies = options.cookies || {};
|
|
34
|
+
this.dataOverride = options.dataOverride || {};
|
|
35
|
+
this.pathParams = options.pathParams || {};
|
|
36
|
+
this.queryParams = options.queryParams || {};
|
|
37
|
+
this.formParams = options.formParams || {};
|
|
38
|
+
this.expectedCode = options.expectedCode || '';
|
|
39
|
+
this.description = options.description || '';
|
|
40
|
+
this.insecure = options.insecure || false;
|
|
41
|
+
this.funcHandler = options.funcHandler || '';
|
|
42
|
+
this.funcHandlerType = options.funcHandlerType || '';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
toYaml() {
|
|
46
|
+
// Map of camelCase to snake_case field names
|
|
47
|
+
const fieldMappings = {
|
|
48
|
+
name: 'name',
|
|
49
|
+
url: 'url',
|
|
50
|
+
path: 'path',
|
|
51
|
+
method: 'method',
|
|
52
|
+
body: 'body',
|
|
53
|
+
headers: 'headers',
|
|
54
|
+
cookies: 'cookies',
|
|
55
|
+
dataOverride: 'data_override',
|
|
56
|
+
pathParams: 'path_params',
|
|
57
|
+
queryParams: 'query_params',
|
|
58
|
+
formParams: 'form_params',
|
|
59
|
+
expectedCode: 'expected_code',
|
|
60
|
+
description: 'description',
|
|
61
|
+
insecure: 'insecure',
|
|
62
|
+
funcHandler: 'func_handler',
|
|
63
|
+
funcHandlerType: 'func_handler_type'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const { body, ...rest } = this;
|
|
67
|
+
// Create object with non-empty values and convert to snake_case
|
|
68
|
+
const yamlObject = Object.entries(rest).reduce((acc, [key, value]) => {
|
|
69
|
+
// Include field only if it's not empty (empty string, empty object, or empty array)
|
|
70
|
+
if (value && (typeof value !== 'object' || Object.keys(value).length > 0)) {
|
|
71
|
+
// Use snake_case key if mapping exists, otherwise use original key
|
|
72
|
+
const snakeKey = fieldMappings[key] || key;
|
|
73
|
+
acc[snakeKey] = value;
|
|
74
|
+
}
|
|
75
|
+
return acc;
|
|
76
|
+
}, {});
|
|
77
|
+
|
|
78
|
+
// Add body if it exists
|
|
79
|
+
if (body) {
|
|
80
|
+
yamlObject.body = JSON.stringify(body, null, 2);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return yaml.dump(yamlObject);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
toJson() {
|
|
87
|
+
// Use the same field mappings as toYaml for consistency
|
|
88
|
+
const fieldMappings = {
|
|
89
|
+
name: 'name',
|
|
90
|
+
url: 'url',
|
|
91
|
+
path: 'path',
|
|
92
|
+
method: 'method',
|
|
93
|
+
body: 'body',
|
|
94
|
+
headers: 'headers',
|
|
95
|
+
cookies: 'cookies',
|
|
96
|
+
dataOverride: 'data_override',
|
|
97
|
+
pathParams: 'path_params',
|
|
98
|
+
queryParams: 'query_params',
|
|
99
|
+
formParams: 'form_params',
|
|
100
|
+
expectedCode: 'expected_code',
|
|
101
|
+
description: 'description',
|
|
102
|
+
insecure: 'insecure',
|
|
103
|
+
funcHandler: 'func_handler',
|
|
104
|
+
funcHandlerType: 'func_handler_type'
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const { ...rest } = this;
|
|
108
|
+
// Create object with non-empty values and convert to snake_case
|
|
109
|
+
const jsonObject = Object.entries(rest).reduce((acc, [key, value]) => {
|
|
110
|
+
if (value && (typeof value !== 'object' || Object.keys(value).length > 0)) {
|
|
111
|
+
const snakeKey = fieldMappings[key] || key;
|
|
112
|
+
acc[snakeKey] = value;
|
|
113
|
+
}
|
|
114
|
+
return acc;
|
|
115
|
+
}, {});
|
|
116
|
+
return JSON.stringify(jsonObject, null, 2);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Returns the request as a dictionary object suitable for async scenarios
|
|
121
|
+
* @param {Object} [globalHeaders] - Global headers to merge with request headers
|
|
122
|
+
* @returns {Object} The request dictionary
|
|
123
|
+
*/
|
|
124
|
+
asRequestDict(globalHeaders = undefined) {
|
|
125
|
+
const requestDict = {
|
|
126
|
+
requestName: this.name,
|
|
127
|
+
url: this.url,
|
|
128
|
+
path: this.path,
|
|
129
|
+
method: this.method
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Add description if available
|
|
133
|
+
if (this.description !== undefined && this.description !== null && this.description !== '') {
|
|
134
|
+
requestDict.description = this.description;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Handle headers
|
|
138
|
+
if (globalHeaders !== undefined && globalHeaders !== null) {
|
|
139
|
+
requestDict.headers = { ...globalHeaders };
|
|
140
|
+
}
|
|
141
|
+
if (this.headers !== undefined && this.headers !== null && Object.keys(this.headers).length > 0) {
|
|
142
|
+
requestDict.headers = { ...requestDict.headers, ...this.headers };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Add other fields if they exist
|
|
146
|
+
if (this.body !== undefined && this.body !== null && this.body !== '') {
|
|
147
|
+
requestDict.body = this.body;
|
|
148
|
+
}
|
|
149
|
+
if (this.cookies !== undefined && this.cookies !== null && Object.keys(this.cookies).length > 0) {
|
|
150
|
+
requestDict.cookies = this.cookies;
|
|
151
|
+
}
|
|
152
|
+
if (this.dataOverride !== undefined && this.dataOverride !== null && Object.keys(this.dataOverride).length > 0) {
|
|
153
|
+
requestDict.dataOverride = this.dataOverride;
|
|
154
|
+
}
|
|
155
|
+
if (this.pathParams !== undefined && this.pathParams !== null && Object.keys(this.pathParams).length > 0) {
|
|
156
|
+
requestDict.pathParams = this.pathParams;
|
|
157
|
+
}
|
|
158
|
+
if (this.queryParams !== undefined && this.queryParams !== null && Object.keys(this.queryParams).length > 0) {
|
|
159
|
+
requestDict.queryParams = this.queryParams;
|
|
160
|
+
}
|
|
161
|
+
if (this.formParams !== undefined && this.formParams !== null && Object.keys(this.formParams).length > 0) {
|
|
162
|
+
requestDict.formParams = this.formParams;
|
|
163
|
+
}
|
|
164
|
+
if (this.expectedCode !== undefined && this.expectedCode !== null && this.expectedCode !== '') {
|
|
165
|
+
requestDict.expectedCode = this.expectedCode;
|
|
166
|
+
}
|
|
167
|
+
if (this.funcHandler !== undefined && this.funcHandler !== null && this.funcHandler !== '') {
|
|
168
|
+
requestDict.funcHandler = this.funcHandler;
|
|
169
|
+
}
|
|
170
|
+
if (this.funcHandlerType !== undefined && this.funcHandlerType !== null && this.funcHandlerType !== '') {
|
|
171
|
+
requestDict.funcHandlerType = this.funcHandlerType;
|
|
172
|
+
}
|
|
173
|
+
if (this.insecure !== undefined && this.insecure !== null && this.insecure !== false) {
|
|
174
|
+
requestDict.insecure = this.insecure;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return requestDict;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = RequestV2;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Endpoint } from './Endpoint';
|
|
2
|
+
import { RestParam } from './RestParam';
|
|
3
|
+
import { ResponseValue } from './ResponseValue';
|
|
4
|
+
interface RequestValueOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
endpoint: Endpoint;
|
|
7
|
+
methodType?: string;
|
|
8
|
+
methodName?: string;
|
|
9
|
+
params?: RestParam[];
|
|
10
|
+
headers?: {[headerName: string]: string},
|
|
11
|
+
vars?: {[ var_: string]: string | number};
|
|
12
|
+
blob?: string;
|
|
13
|
+
graphqlParam?: string;
|
|
14
|
+
javascriptPath?: string;
|
|
15
|
+
javascriptFunction?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class RequestValue {
|
|
18
|
+
constructor(options: RequestValueOptions)
|
|
19
|
+
asRequestDict() : RequestValue
|
|
20
|
+
setCookieValue(cookieValue: string) : void
|
|
21
|
+
setResponse(responseValue: ResponseValue) : void
|
|
22
|
+
toJson() : string
|
|
23
|
+
setOverrides(requestDict: RequestValue ) : void
|
|
24
|
+
}
|