runner-runtime 1.0.90 → 1.0.91

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/libs/2har.js DELETED
@@ -1,161 +0,0 @@
1
- /**
2
- * Converts a Postman-style request configuration into HAR format JSON.
3
- *
4
- * @param {Object} options - Request options based on Postman format.
5
- * {
6
- * url: string,
7
- * method: string,
8
- * headers: array,
9
- * queryParams: array,
10
- * body: {
11
- * mode: string, // none | urlencoded | formdata | raw | json
12
- * [urlencoded]: array, // For urlencoded form data
13
- * [formdata]: array, // For multipart/form-data
14
- * [raw]: string, // For raw (text or binary)
15
- * [json]: object // For JSON body
16
- * }
17
- * }
18
- * @returns {Object} HAR format JSON object.
19
- */
20
- function generateHarFromRequest(options) {
21
- const {
22
- // url,
23
- method = 'GET',
24
- headers = [], // Array of { key, value }
25
- queryParams = [], // Array of { key, value }
26
- body = { mode: 'none' }, // Body in Postman format
27
- } = options;
28
-
29
- const har = {
30
- log: {
31
- version: '1.2',
32
- creator: {
33
- name: 'Custom Node Request to HAR Converter',
34
- version: '1.0',
35
- },
36
- entries: [
37
- {
38
- request: {
39
- method: method.toUpperCase(),
40
- httpVersion: "HTTP/1.1",
41
- url: String(options?.url || 'http://'),
42
- headers: processHeaders(headers),
43
- queryString: processQueryString(queryParams),
44
- postData: processBody(body),
45
- headersSize: -1, // Optional, usually auto-calculated
46
- bodySize: -1, // Optional, usually auto-calculated
47
- },
48
- response: {
49
- status: 200,
50
- statusText: "OK",
51
- httpVersion: "HTTP/1.1",
52
- cookies: [],
53
- headers: [],
54
- content: {
55
- size: 0,
56
- mimeType: "application/json", // Assume JSON, update as necessary
57
- },
58
- redirectURL: "",
59
- headersSize: -1,
60
- bodySize: -1,
61
- },
62
- cache: {},
63
- timings: {
64
- send: 0,
65
- wait: 0,
66
- receive: 0,
67
- },
68
- startedDateTime: new Date().toISOString(),
69
- time: 0, // Mock timing data (replace with actual timing if needed)
70
- },
71
- ],
72
- },
73
- };
74
-
75
- return har;
76
- }
77
-
78
- /**
79
- * Converts Postman-style headers into HAR format.
80
- * @param {Array} headers - Array of { key: string, value: string }.
81
- * @returns {Array} Array of HAR headers.
82
- */
83
- function processHeaders(headers) {
84
- return (headers || []).map(({ key, value }) => ({
85
- name: key,
86
- value: value,
87
- }));
88
- }
89
-
90
- /**
91
- * Converts Postman-style query parameters into HAR format.
92
- * @param {Array} queryParams - Array of { key: string, value: string }.
93
- * @returns {Array} Array of HAR query parameters.
94
- */
95
- function processQueryString(queryParams) {
96
- return (queryParams || []).map(({ key, value }) => ({
97
- name: key,
98
- value: String(value),
99
- }));
100
- }
101
-
102
- /**
103
- * Processes the body into HAR format based on its mode.
104
- * @param {Object} body - Postman-style body object with a defined mode.
105
- * @returns {Object|undefined} HAR postData object.
106
- */
107
- function processBody(body) {
108
- const { mode } = body;
109
-
110
- if (mode === 'none') {
111
- return {
112
- "mimeType": "none",
113
- "params": [],
114
- "text": ""
115
- }
116
- // return undefined; // No body
117
- }
118
-
119
- if (mode === 'urlencoded') {
120
- return {
121
- mimeType: 'application/x-www-form-urlencoded',
122
- params: (body.urlencoded || []).map(({ key, value }) => ({
123
- name: key,
124
- value: String(value),
125
- })),
126
- };
127
- }
128
-
129
- if (mode === 'formdata') {
130
- return {
131
- mimeType: 'multipart/form-data',
132
- params: (body.formdata || []).map(({ key, value, type = 'text' }) => {
133
- const param = { name: key, value: String(value) };
134
- if (type === 'file') param.fileName = value; // File handling
135
- return param;
136
- }),
137
- };
138
- }
139
-
140
- if (mode === 'raw') {
141
- return {
142
- mimeType: 'text/plain',
143
- text: String(body.raw),
144
- };
145
- }
146
-
147
- if (mode === 'json') {
148
- return {
149
- mimeType: 'application/json',
150
- text: JSON.stringify(body.json || {}),
151
- };
152
- }
153
-
154
- return {
155
- "mimeType": "none",
156
- "params": [],
157
- "text": ""
158
- }
159
- }
160
-
161
- module.exports = { generateHarFromRequest };