@skyramp/skyramp 1.3.14 → 1.3.15

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": "@skyramp/skyramp",
3
- "version": "1.3.14",
3
+ "version": "1.3.15",
4
4
  "description": "module for leveraging skyramp cli functionality",
5
5
  "scripts": {
6
6
  "lint": "eslint 'src/**/*.js' 'src/**/*.ts' --fix",
@@ -36,6 +36,11 @@ export class MockV2 {
36
36
  */
37
37
  requestBody?: string | null;
38
38
 
39
+ /**
40
+ * Optional request form params for request-aware matching
41
+ */
42
+ requestFormParams?: Record<string, unknown> | null;
43
+
39
44
  /**
40
45
  * Optional data override object
41
46
  */
@@ -83,6 +88,7 @@ export class MockV2 {
83
88
  status_code: number;
84
89
  response_body: string;
85
90
  request_body?: string;
91
+ request_form_params?: Record<string, unknown>;
86
92
  data_override?: Record<string, unknown>;
87
93
  client_id?: string;
88
94
  };
@@ -38,6 +38,7 @@ class MockV2 {
38
38
  this.statusCode = options.statusCode || 201;
39
39
  this.responseBody = (options.body !== undefined ? options.body : options.responseBody) || '';
40
40
  this.requestBody = options.requestBody || null;
41
+ this.requestFormParams = options.requestFormParams || null;
41
42
  this.dataOverride = options.dataOverride || null;
42
43
  this.clientID = options.clientID || null;
43
44
  } else {
@@ -48,6 +49,7 @@ class MockV2 {
48
49
  this.statusCode = statusCode;
49
50
  this.responseBody = responseBody;
50
51
  this.requestBody = requestBody;
52
+ this.requestFormParams = null;
51
53
  this.dataOverride = dataOverride;
52
54
  this.clientID = null;
53
55
  }
@@ -70,6 +72,10 @@ class MockV2 {
70
72
  result.request_body = this.requestBody;
71
73
  }
72
74
 
75
+ if (this.requestFormParams !== null) {
76
+ result.request_form_params = this.requestFormParams;
77
+ }
78
+
73
79
  if (this.dataOverride !== null) {
74
80
  result.data_override = this.dataOverride;
75
81
  }
@@ -1,3 +1,6 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
1
4
  /**
2
5
  * The `MultipartParam` class represents a multipart/form-data parameter for file uploads or value-based content.
3
6
  * @class
@@ -8,21 +11,22 @@ class MultipartParam {
8
11
  * @constructor
9
12
  * @param {Object} options - An options object containing all parameters.
10
13
  * @param {string} options.name - The name of the multipart parameter (required).
11
- * @param {string} [options.filename=""] - The filename for file uploads.
14
+ * @param {string} [options.filename=""] - Filename for file uploads. When this is a path to an
15
+ * existing file on disk, the file is read and base64-encoded automatically and the basename
16
+ * is used as the Content-Disposition filename sent to the server.
12
17
  * @param {boolean} [options.decoded=false] - Whether the content should be decoded.
13
18
  * @param {string} [options.value=null] - The value for value-based parameters.
14
- *
19
+ *
15
20
  * @example
16
- * // File upload parameter
17
- * new MultipartParam({
21
+ * // File upload — filename is a local path, content is read automatically
22
+ * new MultipartParam({
18
23
  * name: 'file',
19
- * filename: 'document.pdf',
20
- * decoded: true
24
+ * filename: '/path/to/document.pdf'
21
25
  * })
22
- *
26
+ *
23
27
  * @example
24
28
  * // Value-based parameter
25
- * new MultipartParam({
29
+ * new MultipartParam({
26
30
  * name: 'attributes',
27
31
  * value: '{"product_id": 3}',
28
32
  * filename: '',
@@ -33,11 +37,21 @@ class MultipartParam {
33
37
  if (typeof options !== 'object' || options === null || !('name' in options)) {
34
38
  throw new Error('MultipartParam requires an options object with a name property')
35
39
  }
36
-
37
- this.name = options.name
38
- this.value = options.value || null
39
- this.filename = options.filename || ""
40
+
41
+ this.name = options.name
40
42
  this.decoded = options.decoded || false
43
+
44
+ const filenameOpt = options.filename || ""
45
+
46
+ if (filenameOpt && fs.existsSync(filenameOpt)) {
47
+ // filename is a local filesystem path — read content and use basename as display name
48
+ this.value = fs.readFileSync(filenameOpt).toString('base64')
49
+ this.decoded = false
50
+ this.filename = path.basename(filenameOpt)
51
+ } else {
52
+ this.filename = filenameOpt
53
+ this.value = options.value || null
54
+ }
41
55
  }
42
56
 
43
57
  toJson() {
@@ -36,7 +36,7 @@ class RequestV2 {
36
36
  this.pathParams = options.pathParams || {};
37
37
  this.queryParams = options.queryParams || {};
38
38
  this.formParams = options.formParams || {};
39
- this.multipartParams = options.multipartParams || [];
39
+ this.multipartParams = options.multipartParams || options.multipart_params || [];
40
40
  this.expectedCode = options.expectedCode || '';
41
41
  this.description = options.description || '';
42
42
  this.insecure = options.insecure || false;
@@ -140,6 +140,7 @@ interface GenerateRestTestOptions {
140
140
  chainingKey?: string;
141
141
  parentRequestData?: Record<string, string> | string;
142
142
  parentStatusCode?: Record<string, string> | string;
143
+ parentFormParams?: Record<string, string> | string;
143
144
  requestAware?: boolean;
144
145
  providerMode?: boolean;
145
146
  consumerMode?: boolean;
@@ -104,6 +104,7 @@ const generateRestTestWrapper = lib.func('generateRestTestWrapper', 'string', [
104
104
  'string', // chainingKey
105
105
  'string', // parentRequestData
106
106
  'string', // parentStatusCode
107
+ 'string', // parentFormParams
107
108
  'bool', // requestAware
108
109
  'bool', // providerMode
109
110
  'bool', // consumerMode
@@ -896,6 +897,9 @@ class SkyrampClient {
896
897
  const parentStatusCode = typeof options.parentStatusCode === 'string'
897
898
  ? options.parentStatusCode
898
899
  : JSON.stringify(options.parentStatusCode || {});
900
+ const parentFormParams = typeof options.parentFormParams === 'string'
901
+ ? options.parentFormParams
902
+ : JSON.stringify(options.parentFormParams || {});
899
903
 
900
904
  generateRestTestWrapper.async(
901
905
  options.testType || "",
@@ -948,6 +952,7 @@ class SkyrampClient {
948
952
  options.chainingKey || "",
949
953
  parentRequestData || "",
950
954
  parentStatusCode || "",
955
+ parentFormParams || "",
951
956
  options.requestAware || false,
952
957
  options.providerMode || false,
953
958
  options.consumerMode || false,