artes 1.4.7 → 1.4.9

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.
Files changed (40) hide show
  1. package/README.md +668 -668
  2. package/cucumber.config.js +223 -223
  3. package/docs/emulationDevicesList.md +152 -152
  4. package/docs/functionDefinitions.md +2401 -2401
  5. package/docs/stepDefinitions.md +402 -402
  6. package/executer.js +479 -479
  7. package/index.js +50 -50
  8. package/package.json +52 -52
  9. package/src/helper/contextManager/browserManager.js +74 -74
  10. package/src/helper/contextManager/requestManager.js +23 -23
  11. package/src/helper/controller/elementController.js +203 -185
  12. package/src/helper/controller/pomCollector.js +82 -82
  13. package/src/helper/executers/cleaner.js +19 -19
  14. package/src/helper/executers/exporter.js +15 -15
  15. package/src/helper/executers/helper.js +110 -110
  16. package/src/helper/executers/projectCreator.js +206 -206
  17. package/src/helper/executers/reportGenerator.js +70 -70
  18. package/src/helper/executers/testRunner.js +28 -28
  19. package/src/helper/executers/versionChecker.js +31 -31
  20. package/src/helper/imports/commons.js +57 -57
  21. package/src/helper/stepFunctions/APIActions.js +495 -495
  22. package/src/helper/stepFunctions/assertions.js +989 -989
  23. package/src/helper/stepFunctions/browserActions.js +22 -22
  24. package/src/helper/stepFunctions/elementInteractions.js +60 -60
  25. package/src/helper/stepFunctions/exporter.js +19 -19
  26. package/src/helper/stepFunctions/frameActions.js +72 -72
  27. package/src/helper/stepFunctions/keyboardActions.js +66 -66
  28. package/src/helper/stepFunctions/mouseActions.js +83 -83
  29. package/src/helper/stepFunctions/pageActions.js +43 -43
  30. package/src/hooks/context.js +15 -15
  31. package/src/hooks/hooks.js +215 -215
  32. package/src/stepDefinitions/API.steps.js +310 -310
  33. package/src/stepDefinitions/assertions.steps.js +1092 -1092
  34. package/src/stepDefinitions/browser.steps.js +7 -7
  35. package/src/stepDefinitions/frameActions.steps.js +76 -76
  36. package/src/stepDefinitions/keyboardActions.steps.js +265 -265
  37. package/src/stepDefinitions/mouseActions.steps.js +378 -378
  38. package/src/stepDefinitions/page.steps.js +71 -71
  39. package/src/stepDefinitions/random.steps.js +188 -188
  40. package/status-formatter.js +138 -138
@@ -1,495 +1,495 @@
1
- const path = require("path");
2
- const fs = require("fs");
3
- const {
4
- context,
5
- selector,
6
- resolveVariable,
7
- moduleConfig,
8
- } = require("../imports/commons");
9
-
10
- function getMimeType(filePath) {
11
- const ext = path.extname(filePath).toLowerCase();
12
- const mimeTypes = {
13
- ".jpg": "image/jpeg",
14
- ".jpeg": "image/jpeg",
15
- ".png": "image/png",
16
- ".gif": "image/gif",
17
- ".pdf": "application/pdf",
18
- ".txt": "text/plain",
19
- ".json": "application/json",
20
- ".xml": "application/xml",
21
- ".zip": "application/zip",
22
- ".doc": "application/msword",
23
- ".docx":
24
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
25
- ".csv": "text/csv",
26
- };
27
-
28
- return mimeTypes[ext] || "application/octet-stream";
29
- }
30
-
31
- function curlExtractor(url, method, headers, body, requestDataType) {
32
- let curlCommand = `curl -X ${method} '${url}'`;
33
-
34
- if (headers && Object.keys(headers).length > 0) {
35
- for (const [key, value] of Object.entries(headers)) {
36
- curlCommand += ` \\\n -H '${key}: ${value}'`;
37
- }
38
- }
39
-
40
- if (body && Object.keys(body).length > 0) {
41
- switch (requestDataType) {
42
- case "multipart":
43
- for (const [key, value] of Object.entries(body)) {
44
- if (typeof value === "object" && value.buffer) {
45
- curlCommand += ` \\\n -F '${key}=@${value.name}'`;
46
- } else {
47
- curlCommand += ` \\\n -F '${key}=${value}'`;
48
- }
49
- }
50
- break;
51
-
52
- case "urlencoded":
53
- case "application/x-www-form-urlencoded":
54
- const urlEncodedData = new URLSearchParams(body).toString();
55
- curlCommand += ` \\\n --data-urlencode '${urlEncodedData}'`;
56
- break;
57
-
58
- case "form":
59
- for (const [key, value] of Object.entries(body)) {
60
- curlCommand += ` \\\n -F '${key}=${value}'`;
61
- }
62
- break;
63
-
64
- default:
65
- const hasContentType =
66
- headers &&
67
- Object.keys(headers).some(
68
- (key) => key.toLowerCase() === "content-type",
69
- );
70
-
71
- if (!hasContentType) {
72
- curlCommand += ` \\\n -H 'Content-Type: application/json'`;
73
- }
74
-
75
- curlCommand += ` \\\n --data-raw '${JSON.stringify(body)}'`;
76
- break;
77
- }
78
- }
79
-
80
- return curlCommand;
81
- }
82
-
83
- function processForm(requestBody) {
84
- let formData = {};
85
- for (const [key, value] of Object.entries(requestBody)) {
86
- if (value === null || value === undefined) {
87
- continue;
88
- }
89
-
90
- if (typeof value === "object") {
91
- if (value.contentType) {
92
- const content =
93
- typeof value.data === "object"
94
- ? JSON.stringify(value.data)
95
- : String(value.data);
96
-
97
- formData[key] = {
98
- name: value.filename || key,
99
- mimeType: value.contentType,
100
- buffer: Buffer.from(content, "utf8"),
101
- };
102
- continue;
103
- } else {
104
- formData[key] = JSON.stringify(value);
105
- continue;
106
- }
107
- }
108
-
109
- if (
110
- typeof value === "string" &&
111
- (value.endsWith(".pdf") ||
112
- value.endsWith(".jpg") ||
113
- value.endsWith(".png") ||
114
- value.endsWith(".txt") ||
115
- value.endsWith(".doc") ||
116
- value.endsWith(".docx") ||
117
- value.includes("/"))
118
- ) {
119
- try {
120
- const filePath = path.join(moduleConfig.projectPath, value);
121
- if (fs.existsSync(filePath)) {
122
- formData[key] = {
123
- name: path.basename(filePath),
124
- mimeType: getMimeType(filePath),
125
- buffer: fs.readFileSync(filePath),
126
- };
127
- continue;
128
- }
129
- } catch (error) {
130
- console.log(error);
131
- }
132
- }
133
-
134
- formData[key] = value;
135
- }
136
- return formData;
137
- }
138
-
139
- async function requestMaker(headers, data, requestDataType) {
140
- let request = {};
141
-
142
- Object.assign(request, { headers: headers });
143
-
144
- switch (requestDataType) {
145
- case "multipart":
146
- Object.assign(request, { multipart: data });
147
- break;
148
- case "urlencoded":
149
- case "application/x-www-form-urlencoded":
150
- const urlEncodedData = new URLSearchParams(data).toString();
151
- Object.assign(request, { data: urlEncodedData });
152
- break;
153
- case "form":
154
- Object.assign(request, { form: data });
155
- break;
156
- default:
157
- Object.assign(request, { data: data });
158
- }
159
-
160
- return request;
161
- }
162
-
163
- async function responseMaker(request, response, duration, curlCommand) {
164
- const responseObject = {};
165
-
166
- response &&
167
- Object.assign(responseObject, {
168
- "Response Params": `URL: ${response.url()}
169
- Response Status: ${await response.status()}
170
- Response Time: ${Math.round(duration)} ms`,
171
- });
172
-
173
- request?.headers &&
174
- Object.assign(responseObject, { "Request Headers": await request.headers });
175
-
176
- request?.body &&
177
- Object.assign(responseObject, { "Request Body": await request.body });
178
-
179
- response && Object.assign(responseObject, { Response: await response });
180
-
181
- response &&
182
- Object.assign(responseObject, {
183
- "Response Headers": await response.headers(),
184
- });
185
-
186
- if (response) {
187
- try {
188
- Object.assign(responseObject, { "Response Body": await response.json() });
189
- } catch (e) {
190
- Object.assign(responseObject, { "Response Body": await response.text() });
191
- }
192
- }
193
-
194
- curlCommand && Object.assign(responseObject, { "cURL Command": curlCommand });
195
-
196
- return responseObject;
197
- }
198
-
199
- const api = {
200
- get: async (url, payload, options) => {
201
- const URL = await selector(url);
202
-
203
- options = options ?? {};
204
-
205
- const resolvedPayload = (await payload) && resolveVariable(payload);
206
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
207
-
208
- const req = await requestMaker(payloadJSON?.headers || {});
209
-
210
- const requestStarts = performance.now();
211
-
212
- const res = await context.request.get(URL, req, options);
213
-
214
- const duration = performance.now() - requestStarts;
215
-
216
- const curlCommand = curlExtractor(
217
- res.url(),
218
- "GET",
219
- payloadJSON?.headers || {},
220
- null,
221
- null,
222
- );
223
-
224
- const response = responseMaker(payloadJSON, res, duration, curlCommand);
225
-
226
- context.response = await response;
227
- },
228
- head: async (url, options) => {
229
- const URL = await selector(url);
230
-
231
- options = options ?? {};
232
-
233
- const requestStarts = performance.now();
234
-
235
- const res = await context.request.head(URL, options);
236
-
237
- const duration = performance.now() - requestStarts;
238
-
239
- const curlCommand = curlExtractor(res.url(), "HEAD", {}, null, null);
240
-
241
- const response = responseMaker(null, res, duration, curlCommand);
242
-
243
- context.response = await response;
244
- },
245
- post: async (url, payload, requestDataType, options) => {
246
- const URL = await selector(url);
247
-
248
- options = options ?? {};
249
-
250
- const resolvedPayload = (await payload) && resolveVariable(payload);
251
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
252
-
253
- let req;
254
- let bodyForCurl = payloadJSON?.body || {};
255
-
256
- switch (requestDataType) {
257
- case "multipart":
258
- const formRequest = processForm(payloadJSON?.body || {});
259
-
260
- req = await requestMaker(
261
- payloadJSON?.headers || {},
262
- formRequest || {},
263
- requestDataType,
264
- );
265
- bodyForCurl = formRequest;
266
- break;
267
- case "urlencoded":
268
- case "application/x-www-form-urlencoded":
269
- req = await requestMaker(
270
- {
271
- ...payloadJSON?.headers,
272
- "Content-Type": "application/x-www-form-urlencoded",
273
- },
274
- payloadJSON?.body || {},
275
- requestDataType,
276
- );
277
- break;
278
- case "form":
279
- req = await requestMaker(
280
- payloadJSON?.headers || {},
281
- payloadJSON?.body || {},
282
- requestDataType,
283
- );
284
- break;
285
- default:
286
- req = await requestMaker(
287
- payloadJSON?.headers || {},
288
- payloadJSON?.body || {},
289
- );
290
- }
291
-
292
- const requestStarts = performance.now();
293
-
294
- const res = await context.request.post(URL, req, options);
295
-
296
- const duration = performance.now() - requestStarts;
297
-
298
- const curlCommand = curlExtractor(
299
- res.url(),
300
- "POST",
301
- req.headers,
302
- bodyForCurl,
303
- requestDataType,
304
- );
305
-
306
- const response = await responseMaker(
307
- payloadJSON,
308
- res,
309
- duration,
310
- curlCommand,
311
- );
312
-
313
- context.response = response;
314
- },
315
- put: async (url, payload, requestDataType, options) => {
316
- const URL = await selector(url);
317
-
318
- options = options ?? {};
319
-
320
- const resolvedPayload = (await payload) && resolveVariable(payload);
321
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
322
-
323
- let req;
324
- let bodyForCurl = payloadJSON?.body || {};
325
-
326
- switch (requestDataType) {
327
- case "multipart":
328
- const formRequest = processForm(payloadJSON?.body || {});
329
-
330
- req = await requestMaker(
331
- payloadJSON?.headers || {},
332
- formRequest || {},
333
- requestDataType,
334
- );
335
- bodyForCurl = formRequest;
336
- break;
337
- case "urlencoded":
338
- case "application/x-www-form-urlencoded":
339
- req = await requestMaker(
340
- {
341
- ...payloadJSON?.headers,
342
- "Content-Type": "application/x-www-form-urlencoded",
343
- },
344
- payloadJSON?.body || {},
345
- requestDataType,
346
- );
347
- break;
348
- case "form":
349
- req = await requestMaker(
350
- payloadJSON?.headers || {},
351
- payloadJSON?.body || {},
352
- requestDataType,
353
- );
354
- break;
355
- default:
356
- req = await requestMaker(
357
- payloadJSON?.headers || {},
358
- payloadJSON?.body || {},
359
- );
360
- }
361
-
362
- const requestStarts = performance.now();
363
-
364
- const res = await context.request.put(URL, req, options);
365
-
366
- const duration = performance.now() - requestStarts;
367
-
368
- const curlCommand = curlExtractor(
369
- res.url(),
370
- "PUT",
371
- req.headers,
372
- bodyForCurl,
373
- requestDataType,
374
- );
375
-
376
- const response = await responseMaker(
377
- payloadJSON,
378
- res,
379
- duration,
380
- curlCommand,
381
- );
382
-
383
- context.response = response;
384
- },
385
- patch: async (url, payload, requestDataType, options) => {
386
- const URL = await selector(url);
387
-
388
- options = options ?? {};
389
-
390
- const resolvedPayload = (await payload) && resolveVariable(payload);
391
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
392
-
393
- let req;
394
- let bodyForCurl = payloadJSON?.body || {};
395
-
396
- switch (requestDataType) {
397
- case "multipart":
398
- const formRequest = processForm(payloadJSON?.body || {});
399
-
400
- req = await requestMaker(
401
- payloadJSON?.headers || {},
402
- formRequest || {},
403
- requestDataType,
404
- );
405
- bodyForCurl = formRequest;
406
- break;
407
- case "urlencoded":
408
- case "application/x-www-form-urlencoded":
409
- req = await requestMaker(
410
- {
411
- ...payloadJSON?.headers,
412
- "Content-Type": "application/x-www-form-urlencoded",
413
- },
414
- payloadJSON?.body || {},
415
- requestDataType,
416
- );
417
- break;
418
- case "form":
419
- req = await requestMaker(
420
- payloadJSON?.headers || {},
421
- payloadJSON?.body || {},
422
- requestDataType,
423
- );
424
- break;
425
- default:
426
- req = await requestMaker(
427
- payloadJSON?.headers || {},
428
- payloadJSON?.body || {},
429
- );
430
- }
431
-
432
- const requestStarts = performance.now();
433
-
434
- const res = await context.request.patch(URL, req, options);
435
-
436
- const duration = performance.now() - requestStarts;
437
-
438
- const curlCommand = curlExtractor(
439
- res.url(),
440
- "PATCH",
441
- req.headers,
442
- bodyForCurl,
443
- requestDataType,
444
- );
445
-
446
- const response = await responseMaker(
447
- payloadJSON,
448
- res,
449
- duration,
450
- curlCommand,
451
- );
452
-
453
- context.response = response;
454
- },
455
- delete: async (url, payload, options) => {
456
- const URL = await selector(url);
457
-
458
- options = options ?? {};
459
-
460
- const resolvedPayload = (await payload) && resolveVariable(payload);
461
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
462
-
463
- const req = await requestMaker(
464
- payloadJSON?.headers || {},
465
- payloadJSON?.body || {},
466
- );
467
-
468
- const requestStarts = performance.now();
469
-
470
- const res = await context.request.delete(URL, req, options);
471
-
472
- const duration = performance.now() - requestStarts;
473
-
474
- const curlCommand = curlExtractor(
475
- res.url(),
476
- "DELETE",
477
- payloadJSON?.headers || {},
478
- payloadJSON?.body || {},
479
- null,
480
- );
481
-
482
- const response = responseMaker(payloadJSON, res, duration, curlCommand);
483
-
484
- context.response = await response;
485
- },
486
- vars: (variable) => {
487
- if(!variable){
488
- return context.vars;
489
- }else{
490
- return { [variable]: context.vars[variable] };
491
- }
492
- },
493
- };
494
-
495
- module.exports = { api };
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const {
4
+ context,
5
+ selector,
6
+ resolveVariable,
7
+ moduleConfig,
8
+ } = require("../imports/commons");
9
+
10
+ function getMimeType(filePath) {
11
+ const ext = path.extname(filePath).toLowerCase();
12
+ const mimeTypes = {
13
+ ".jpg": "image/jpeg",
14
+ ".jpeg": "image/jpeg",
15
+ ".png": "image/png",
16
+ ".gif": "image/gif",
17
+ ".pdf": "application/pdf",
18
+ ".txt": "text/plain",
19
+ ".json": "application/json",
20
+ ".xml": "application/xml",
21
+ ".zip": "application/zip",
22
+ ".doc": "application/msword",
23
+ ".docx":
24
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
25
+ ".csv": "text/csv",
26
+ };
27
+
28
+ return mimeTypes[ext] || "application/octet-stream";
29
+ }
30
+
31
+ function curlExtractor(url, method, headers, body, requestDataType) {
32
+ let curlCommand = `curl -X ${method} '${url}'`;
33
+
34
+ if (headers && Object.keys(headers).length > 0) {
35
+ for (const [key, value] of Object.entries(headers)) {
36
+ curlCommand += ` \\\n -H '${key}: ${value}'`;
37
+ }
38
+ }
39
+
40
+ if (body && Object.keys(body).length > 0) {
41
+ switch (requestDataType) {
42
+ case "multipart":
43
+ for (const [key, value] of Object.entries(body)) {
44
+ if (typeof value === "object" && value.buffer) {
45
+ curlCommand += ` \\\n -F '${key}=@${value.name}'`;
46
+ } else {
47
+ curlCommand += ` \\\n -F '${key}=${value}'`;
48
+ }
49
+ }
50
+ break;
51
+
52
+ case "urlencoded":
53
+ case "application/x-www-form-urlencoded":
54
+ const urlEncodedData = new URLSearchParams(body).toString();
55
+ curlCommand += ` \\\n --data-urlencode '${urlEncodedData}'`;
56
+ break;
57
+
58
+ case "form":
59
+ for (const [key, value] of Object.entries(body)) {
60
+ curlCommand += ` \\\n -F '${key}=${value}'`;
61
+ }
62
+ break;
63
+
64
+ default:
65
+ const hasContentType =
66
+ headers &&
67
+ Object.keys(headers).some(
68
+ (key) => key.toLowerCase() === "content-type",
69
+ );
70
+
71
+ if (!hasContentType) {
72
+ curlCommand += ` \\\n -H 'Content-Type: application/json'`;
73
+ }
74
+
75
+ curlCommand += ` \\\n --data-raw '${JSON.stringify(body)}'`;
76
+ break;
77
+ }
78
+ }
79
+
80
+ return curlCommand;
81
+ }
82
+
83
+ function processForm(requestBody) {
84
+ let formData = {};
85
+ for (const [key, value] of Object.entries(requestBody)) {
86
+ if (value === null || value === undefined) {
87
+ continue;
88
+ }
89
+
90
+ if (typeof value === "object") {
91
+ if (value.contentType) {
92
+ const content =
93
+ typeof value.data === "object"
94
+ ? JSON.stringify(value.data)
95
+ : String(value.data);
96
+
97
+ formData[key] = {
98
+ name: value.filename || key,
99
+ mimeType: value.contentType,
100
+ buffer: Buffer.from(content, "utf8"),
101
+ };
102
+ continue;
103
+ } else {
104
+ formData[key] = JSON.stringify(value);
105
+ continue;
106
+ }
107
+ }
108
+
109
+ if (
110
+ typeof value === "string" &&
111
+ (value.endsWith(".pdf") ||
112
+ value.endsWith(".jpg") ||
113
+ value.endsWith(".png") ||
114
+ value.endsWith(".txt") ||
115
+ value.endsWith(".doc") ||
116
+ value.endsWith(".docx") ||
117
+ value.includes("/"))
118
+ ) {
119
+ try {
120
+ const filePath = path.join(moduleConfig.projectPath, value);
121
+ if (fs.existsSync(filePath)) {
122
+ formData[key] = {
123
+ name: path.basename(filePath),
124
+ mimeType: getMimeType(filePath),
125
+ buffer: fs.readFileSync(filePath),
126
+ };
127
+ continue;
128
+ }
129
+ } catch (error) {
130
+ console.log(error);
131
+ }
132
+ }
133
+
134
+ formData[key] = value;
135
+ }
136
+ return formData;
137
+ }
138
+
139
+ async function requestMaker(headers, data, requestDataType) {
140
+ let request = {};
141
+
142
+ Object.assign(request, { headers: headers });
143
+
144
+ switch (requestDataType) {
145
+ case "multipart":
146
+ Object.assign(request, { multipart: data });
147
+ break;
148
+ case "urlencoded":
149
+ case "application/x-www-form-urlencoded":
150
+ const urlEncodedData = new URLSearchParams(data).toString();
151
+ Object.assign(request, { data: urlEncodedData });
152
+ break;
153
+ case "form":
154
+ Object.assign(request, { form: data });
155
+ break;
156
+ default:
157
+ Object.assign(request, { data: data });
158
+ }
159
+
160
+ return request;
161
+ }
162
+
163
+ async function responseMaker(request, response, duration, curlCommand) {
164
+ const responseObject = {};
165
+
166
+ response &&
167
+ Object.assign(responseObject, {
168
+ "Response Params": `URL: ${response.url()}
169
+ Response Status: ${await response.status()}
170
+ Response Time: ${Math.round(duration)} ms`,
171
+ });
172
+
173
+ request?.headers &&
174
+ Object.assign(responseObject, { "Request Headers": await request.headers });
175
+
176
+ request?.body &&
177
+ Object.assign(responseObject, { "Request Body": await request.body });
178
+
179
+ response && Object.assign(responseObject, { Response: await response });
180
+
181
+ response &&
182
+ Object.assign(responseObject, {
183
+ "Response Headers": await response.headers(),
184
+ });
185
+
186
+ if (response) {
187
+ try {
188
+ Object.assign(responseObject, { "Response Body": await response.json() });
189
+ } catch (e) {
190
+ Object.assign(responseObject, { "Response Body": await response.text() });
191
+ }
192
+ }
193
+
194
+ curlCommand && Object.assign(responseObject, { "cURL Command": curlCommand });
195
+
196
+ return responseObject;
197
+ }
198
+
199
+ const api = {
200
+ get: async (url, payload, options) => {
201
+ const URL = await selector(url);
202
+
203
+ options = options ?? {};
204
+
205
+ const resolvedPayload = (await payload) && resolveVariable(payload);
206
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
207
+
208
+ const req = await requestMaker(payloadJSON?.headers || {});
209
+
210
+ const requestStarts = performance.now();
211
+
212
+ const res = await context.request.get(URL, req, options);
213
+
214
+ const duration = performance.now() - requestStarts;
215
+
216
+ const curlCommand = curlExtractor(
217
+ res.url(),
218
+ "GET",
219
+ payloadJSON?.headers || {},
220
+ null,
221
+ null,
222
+ );
223
+
224
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
225
+
226
+ context.response = await response;
227
+ },
228
+ head: async (url, options) => {
229
+ const URL = await selector(url);
230
+
231
+ options = options ?? {};
232
+
233
+ const requestStarts = performance.now();
234
+
235
+ const res = await context.request.head(URL, options);
236
+
237
+ const duration = performance.now() - requestStarts;
238
+
239
+ const curlCommand = curlExtractor(res.url(), "HEAD", {}, null, null);
240
+
241
+ const response = responseMaker(null, res, duration, curlCommand);
242
+
243
+ context.response = await response;
244
+ },
245
+ post: async (url, payload, requestDataType, options) => {
246
+ const URL = await selector(url);
247
+
248
+ options = options ?? {};
249
+
250
+ const resolvedPayload = (await payload) && resolveVariable(payload);
251
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
252
+
253
+ let req;
254
+ let bodyForCurl = payloadJSON?.body || {};
255
+
256
+ switch (requestDataType) {
257
+ case "multipart":
258
+ const formRequest = processForm(payloadJSON?.body || {});
259
+
260
+ req = await requestMaker(
261
+ payloadJSON?.headers || {},
262
+ formRequest || {},
263
+ requestDataType,
264
+ );
265
+ bodyForCurl = formRequest;
266
+ break;
267
+ case "urlencoded":
268
+ case "application/x-www-form-urlencoded":
269
+ req = await requestMaker(
270
+ {
271
+ ...payloadJSON?.headers,
272
+ "Content-Type": "application/x-www-form-urlencoded",
273
+ },
274
+ payloadJSON?.body || {},
275
+ requestDataType,
276
+ );
277
+ break;
278
+ case "form":
279
+ req = await requestMaker(
280
+ payloadJSON?.headers || {},
281
+ payloadJSON?.body || {},
282
+ requestDataType,
283
+ );
284
+ break;
285
+ default:
286
+ req = await requestMaker(
287
+ payloadJSON?.headers || {},
288
+ payloadJSON?.body || {},
289
+ );
290
+ }
291
+
292
+ const requestStarts = performance.now();
293
+
294
+ const res = await context.request.post(URL, req, options);
295
+
296
+ const duration = performance.now() - requestStarts;
297
+
298
+ const curlCommand = curlExtractor(
299
+ res.url(),
300
+ "POST",
301
+ req.headers,
302
+ bodyForCurl,
303
+ requestDataType,
304
+ );
305
+
306
+ const response = await responseMaker(
307
+ payloadJSON,
308
+ res,
309
+ duration,
310
+ curlCommand,
311
+ );
312
+
313
+ context.response = response;
314
+ },
315
+ put: async (url, payload, requestDataType, options) => {
316
+ const URL = await selector(url);
317
+
318
+ options = options ?? {};
319
+
320
+ const resolvedPayload = (await payload) && resolveVariable(payload);
321
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
322
+
323
+ let req;
324
+ let bodyForCurl = payloadJSON?.body || {};
325
+
326
+ switch (requestDataType) {
327
+ case "multipart":
328
+ const formRequest = processForm(payloadJSON?.body || {});
329
+
330
+ req = await requestMaker(
331
+ payloadJSON?.headers || {},
332
+ formRequest || {},
333
+ requestDataType,
334
+ );
335
+ bodyForCurl = formRequest;
336
+ break;
337
+ case "urlencoded":
338
+ case "application/x-www-form-urlencoded":
339
+ req = await requestMaker(
340
+ {
341
+ ...payloadJSON?.headers,
342
+ "Content-Type": "application/x-www-form-urlencoded",
343
+ },
344
+ payloadJSON?.body || {},
345
+ requestDataType,
346
+ );
347
+ break;
348
+ case "form":
349
+ req = await requestMaker(
350
+ payloadJSON?.headers || {},
351
+ payloadJSON?.body || {},
352
+ requestDataType,
353
+ );
354
+ break;
355
+ default:
356
+ req = await requestMaker(
357
+ payloadJSON?.headers || {},
358
+ payloadJSON?.body || {},
359
+ );
360
+ }
361
+
362
+ const requestStarts = performance.now();
363
+
364
+ const res = await context.request.put(URL, req, options);
365
+
366
+ const duration = performance.now() - requestStarts;
367
+
368
+ const curlCommand = curlExtractor(
369
+ res.url(),
370
+ "PUT",
371
+ req.headers,
372
+ bodyForCurl,
373
+ requestDataType,
374
+ );
375
+
376
+ const response = await responseMaker(
377
+ payloadJSON,
378
+ res,
379
+ duration,
380
+ curlCommand,
381
+ );
382
+
383
+ context.response = response;
384
+ },
385
+ patch: async (url, payload, requestDataType, options) => {
386
+ const URL = await selector(url);
387
+
388
+ options = options ?? {};
389
+
390
+ const resolvedPayload = (await payload) && resolveVariable(payload);
391
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
392
+
393
+ let req;
394
+ let bodyForCurl = payloadJSON?.body || {};
395
+
396
+ switch (requestDataType) {
397
+ case "multipart":
398
+ const formRequest = processForm(payloadJSON?.body || {});
399
+
400
+ req = await requestMaker(
401
+ payloadJSON?.headers || {},
402
+ formRequest || {},
403
+ requestDataType,
404
+ );
405
+ bodyForCurl = formRequest;
406
+ break;
407
+ case "urlencoded":
408
+ case "application/x-www-form-urlencoded":
409
+ req = await requestMaker(
410
+ {
411
+ ...payloadJSON?.headers,
412
+ "Content-Type": "application/x-www-form-urlencoded",
413
+ },
414
+ payloadJSON?.body || {},
415
+ requestDataType,
416
+ );
417
+ break;
418
+ case "form":
419
+ req = await requestMaker(
420
+ payloadJSON?.headers || {},
421
+ payloadJSON?.body || {},
422
+ requestDataType,
423
+ );
424
+ break;
425
+ default:
426
+ req = await requestMaker(
427
+ payloadJSON?.headers || {},
428
+ payloadJSON?.body || {},
429
+ );
430
+ }
431
+
432
+ const requestStarts = performance.now();
433
+
434
+ const res = await context.request.patch(URL, req, options);
435
+
436
+ const duration = performance.now() - requestStarts;
437
+
438
+ const curlCommand = curlExtractor(
439
+ res.url(),
440
+ "PATCH",
441
+ req.headers,
442
+ bodyForCurl,
443
+ requestDataType,
444
+ );
445
+
446
+ const response = await responseMaker(
447
+ payloadJSON,
448
+ res,
449
+ duration,
450
+ curlCommand,
451
+ );
452
+
453
+ context.response = response;
454
+ },
455
+ delete: async (url, payload, options) => {
456
+ const URL = await selector(url);
457
+
458
+ options = options ?? {};
459
+
460
+ const resolvedPayload = (await payload) && resolveVariable(payload);
461
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
462
+
463
+ const req = await requestMaker(
464
+ payloadJSON?.headers || {},
465
+ payloadJSON?.body || {},
466
+ );
467
+
468
+ const requestStarts = performance.now();
469
+
470
+ const res = await context.request.delete(URL, req, options);
471
+
472
+ const duration = performance.now() - requestStarts;
473
+
474
+ const curlCommand = curlExtractor(
475
+ res.url(),
476
+ "DELETE",
477
+ payloadJSON?.headers || {},
478
+ payloadJSON?.body || {},
479
+ null,
480
+ );
481
+
482
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
483
+
484
+ context.response = await response;
485
+ },
486
+ vars: (variable) => {
487
+ if(!variable){
488
+ return context.vars;
489
+ }else{
490
+ return { [variable]: context.vars[variable] };
491
+ }
492
+ },
493
+ };
494
+
495
+ module.exports = { api };