@skyramp/skyramp 1.2.8 → 1.2.10
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 +1 -1
- package/src/classes/MultipartParam.d.ts +16 -0
- package/src/classes/MultipartParam.js +65 -0
- package/src/classes/RequestV2.d.ts +3 -0
- package/src/classes/RequestV2.js +43 -2
- package/src/classes/SkyrampClient.d.ts +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface MultipartParamOptions {
|
|
2
|
+
name: string;
|
|
3
|
+
value?: string | object;
|
|
4
|
+
filename?: string;
|
|
5
|
+
decoded?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare class MultipartParam {
|
|
9
|
+
name: string;
|
|
10
|
+
value: string | object | null;
|
|
11
|
+
filename: string;
|
|
12
|
+
decoded: boolean;
|
|
13
|
+
|
|
14
|
+
constructor(options: MultipartParamOptions);
|
|
15
|
+
toJson(): object;
|
|
16
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `MultipartParam` class represents a multipart/form-data parameter for file uploads or value-based content.
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
class MultipartParam {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes a new instance of the MultipartParam class.
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {Object} options - An options object containing all parameters.
|
|
10
|
+
* @param {string} options.name - The name of the multipart parameter (required).
|
|
11
|
+
* @param {string} [options.filename=""] - The filename for file uploads.
|
|
12
|
+
* @param {boolean} [options.decoded=false] - Whether the content should be decoded.
|
|
13
|
+
* @param {string} [options.value=null] - The value for value-based parameters.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // File upload parameter
|
|
17
|
+
* new MultipartParam({
|
|
18
|
+
* name: 'file',
|
|
19
|
+
* filename: 'document.pdf',
|
|
20
|
+
* decoded: true
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Value-based parameter
|
|
25
|
+
* new MultipartParam({
|
|
26
|
+
* name: 'attributes',
|
|
27
|
+
* value: '{"product_id": 3}',
|
|
28
|
+
* filename: '',
|
|
29
|
+
* decoded: false
|
|
30
|
+
* })
|
|
31
|
+
*/
|
|
32
|
+
constructor(options) {
|
|
33
|
+
if (typeof options !== 'object' || options === null || !('name' in options)) {
|
|
34
|
+
throw new Error('MultipartParam requires an options object with a name property')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.name = options.name
|
|
38
|
+
this.value = options.value || null
|
|
39
|
+
this.filename = options.filename || ""
|
|
40
|
+
this.decoded = options.decoded || false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toJson() {
|
|
44
|
+
const result = {
|
|
45
|
+
name: this.name,
|
|
46
|
+
in: 'multipart'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.value !== null) {
|
|
50
|
+
result.value = this.value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (this.filename && this.filename !== "") {
|
|
54
|
+
result.filepath = this.filename
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.decoded) {
|
|
58
|
+
result.decoded = this.decoded
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = MultipartParam;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MultipartParam } from './MultipartParam';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Represents a REST request.
|
|
3
5
|
*/
|
|
@@ -13,6 +15,7 @@ interface RequestV2Options {
|
|
|
13
15
|
pathParams?: {[pathName: string]: string | number | boolean | object};
|
|
14
16
|
queryParams?: {[queryName: string]: string | number | boolean | object};
|
|
15
17
|
formParams?: {[formParamName: string]: string | number | boolean | object};
|
|
18
|
+
multipartParams?: Array<MultipartParam>;
|
|
16
19
|
expectedCode?: string;
|
|
17
20
|
funcHandler?: string;
|
|
18
21
|
funcHandlerType?: string;
|
package/src/classes/RequestV2.js
CHANGED
|
@@ -18,6 +18,7 @@ class RequestV2 {
|
|
|
18
18
|
* @param {Object.<string, *>} [options.pathParams={}] - The path parameters for the request.
|
|
19
19
|
* @param {Object.<string, *>} [options.queryParams={}] - The query parameters for the request.
|
|
20
20
|
* @param {Object.<string, *>} [options.formParams={}] - The form parameters of the request.
|
|
21
|
+
* @param {Array} [options.multipartParams=[]] - The multipart parameters for the request.
|
|
21
22
|
* @param {string} [options.expectedCode=''] - The expected HTTP status code of the response.
|
|
22
23
|
* @param {string} [options.funcHandler=''] - The dynamic handler function for the request.
|
|
23
24
|
* @param {string} [options.funcHandlerType=''] - The type of the dynamic handler (e.g., 'python', 'javascript').
|
|
@@ -35,6 +36,7 @@ class RequestV2 {
|
|
|
35
36
|
this.pathParams = options.pathParams || {};
|
|
36
37
|
this.queryParams = options.queryParams || {};
|
|
37
38
|
this.formParams = options.formParams || {};
|
|
39
|
+
this.multipartParams = options.multipartParams || [];
|
|
38
40
|
this.expectedCode = options.expectedCode || '';
|
|
39
41
|
this.description = options.description || '';
|
|
40
42
|
this.insecure = options.insecure || false;
|
|
@@ -56,6 +58,7 @@ class RequestV2 {
|
|
|
56
58
|
pathParams: 'path_params',
|
|
57
59
|
queryParams: 'query_params',
|
|
58
60
|
formParams: 'form_params',
|
|
61
|
+
multipartParams: 'multipart_params',
|
|
59
62
|
expectedCode: 'expected_code',
|
|
60
63
|
description: 'description',
|
|
61
64
|
insecure: 'insecure',
|
|
@@ -70,7 +73,20 @@ class RequestV2 {
|
|
|
70
73
|
if (value && (typeof value !== 'object' || Object.keys(value).length > 0)) {
|
|
71
74
|
// Use snake_case key if mapping exists, otherwise use original key
|
|
72
75
|
const snakeKey = fieldMappings[key] || key;
|
|
73
|
-
|
|
76
|
+
|
|
77
|
+
// Special handling for multipartParams
|
|
78
|
+
if (key === 'multipartParams' && Array.isArray(value)) {
|
|
79
|
+
acc[snakeKey] = value.map(param => {
|
|
80
|
+
// If it's a MultipartParam object with toJson method, call it
|
|
81
|
+
if (param && typeof param.toJson === 'function') {
|
|
82
|
+
return param.toJson();
|
|
83
|
+
}
|
|
84
|
+
// Otherwise return as-is (already a plain object)
|
|
85
|
+
return param;
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
acc[snakeKey] = value;
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
return acc;
|
|
76
92
|
}, {});
|
|
@@ -97,6 +113,7 @@ class RequestV2 {
|
|
|
97
113
|
pathParams: 'path_params',
|
|
98
114
|
queryParams: 'query_params',
|
|
99
115
|
formParams: 'form_params',
|
|
116
|
+
multipartParams: 'multipart_params',
|
|
100
117
|
expectedCode: 'expected_code',
|
|
101
118
|
description: 'description',
|
|
102
119
|
insecure: 'insecure',
|
|
@@ -109,7 +126,20 @@ class RequestV2 {
|
|
|
109
126
|
const jsonObject = Object.entries(rest).reduce((acc, [key, value]) => {
|
|
110
127
|
if (value && (typeof value !== 'object' || Object.keys(value).length > 0)) {
|
|
111
128
|
const snakeKey = fieldMappings[key] || key;
|
|
112
|
-
|
|
129
|
+
|
|
130
|
+
// Special handling for multipartParams
|
|
131
|
+
if (key === 'multipartParams' && Array.isArray(value)) {
|
|
132
|
+
acc[snakeKey] = value.map(param => {
|
|
133
|
+
// If it's a MultipartParam object with toJson method, call it
|
|
134
|
+
if (param && typeof param.toJson === 'function') {
|
|
135
|
+
return param.toJson();
|
|
136
|
+
}
|
|
137
|
+
// Otherwise return as-is (already a plain object)
|
|
138
|
+
return param;
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
acc[snakeKey] = value;
|
|
142
|
+
}
|
|
113
143
|
}
|
|
114
144
|
return acc;
|
|
115
145
|
}, {});
|
|
@@ -161,6 +191,17 @@ class RequestV2 {
|
|
|
161
191
|
if (this.formParams !== undefined && this.formParams !== null && Object.keys(this.formParams).length > 0) {
|
|
162
192
|
requestDict.formParams = this.formParams;
|
|
163
193
|
}
|
|
194
|
+
if (this.multipartParams !== undefined && this.multipartParams !== null && this.multipartParams.length > 0) {
|
|
195
|
+
// Convert MultipartParam objects to their JSON representation
|
|
196
|
+
requestDict.multipartParams = this.multipartParams.map(param => {
|
|
197
|
+
// If it's a MultipartParam object with toJson method, call it
|
|
198
|
+
if (param && typeof param.toJson === 'function') {
|
|
199
|
+
return param.toJson();
|
|
200
|
+
}
|
|
201
|
+
// Otherwise return as-is (already a plain object)
|
|
202
|
+
return param;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
164
205
|
if (this.expectedCode !== undefined && this.expectedCode !== null && this.expectedCode !== '') {
|
|
165
206
|
requestDict.expectedCode = this.expectedCode;
|
|
166
207
|
}
|
|
@@ -6,6 +6,7 @@ import { Protocol } from './Protocol';
|
|
|
6
6
|
import { AsyncScenario } from './AsyncScenario';
|
|
7
7
|
import { LoadTestConfig } from './LoadTestConfig';
|
|
8
8
|
import { AsyncTestStatus } from './AsyncTestStatus';
|
|
9
|
+
import { MultipartParam } from './MultipartParam';
|
|
9
10
|
|
|
10
11
|
export enum Language {
|
|
11
12
|
PYTHON = 'python'
|
|
@@ -44,6 +45,7 @@ interface SendRequestV2Options {
|
|
|
44
45
|
pathParams?: {[pathName: string]: string | number | boolean | object | null};
|
|
45
46
|
queryParams?: {[queryName: string]: string | number | boolean | object | null};
|
|
46
47
|
formParams?: {[formParamName: string]: string | number | boolean | object | null};
|
|
48
|
+
multipartParams?: Array<MultipartParam>;
|
|
47
49
|
expectedCode?: string;
|
|
48
50
|
description?: string;
|
|
49
51
|
insecure?: boolean;
|
package/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './classes/SkyrampClient';
|
|
|
6
6
|
export * from './classes/RequestValue';
|
|
7
7
|
export * from './classes/ResponseValue';
|
|
8
8
|
export * from './classes/RestParam';
|
|
9
|
+
export * from './classes/MultipartParam';
|
|
9
10
|
export * from './classes/TrafficConfig';
|
|
10
11
|
export * from './classes/DelayConfig';
|
|
11
12
|
export * from './classes/Protocol';
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const Scenario = require('./classes/Scenario');
|
|
|
5
5
|
const RequestValue = require('./classes/RequestValue');
|
|
6
6
|
const ResponseValue = require('./classes/ResponseValue');
|
|
7
7
|
const RestParam = require('./classes/RestParam');
|
|
8
|
+
const MultipartParam = require('./classes/MultipartParam');
|
|
8
9
|
const TrafficConfig = require('./classes/TrafficConfig');
|
|
9
10
|
const DelayConfig = require('./classes/DelayConfig');
|
|
10
11
|
const Protocol = require('./classes/Protocol');
|
|
@@ -28,6 +29,7 @@ module.exports = {
|
|
|
28
29
|
RequestValue,
|
|
29
30
|
ResponseValue,
|
|
30
31
|
RestParam,
|
|
32
|
+
MultipartParam,
|
|
31
33
|
TrafficConfig,
|
|
32
34
|
DelayConfig,
|
|
33
35
|
Protocol,
|