@mablhq/mabl-cli 1.50.0 → 1.50.4

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.
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.variableRowAsScenario = exports.scenarioAsVariableRow = exports.dataTableAsVariableTable = exports.isScenarioArray = exports.inferFileFormat = exports.jsonToScenarios = exports.parseJsonScenarios = exports.csvScenarioFormatToScenarios = exports.parseCsvScenarios = exports.sanitizeCsvCellInput = void 0;
7
+ const constants_1 = require("../constants");
8
+ const path_1 = require("path");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const csv_parser_1 = __importDefault(require("csv-parser"));
11
+ const MALICIOUS_LINE_PREFIX_MATCHER = /^([+\-@=])/;
12
+ const SANITIZED_LINE_PREFIX_MATCHER = /^(`[+\-@=])/;
13
+ function sanitizeCsvCellInput(input) {
14
+ return MALICIOUS_LINE_PREFIX_MATCHER.test(input)
15
+ ? `\`${input}`.trim()
16
+ : input.trim();
17
+ }
18
+ exports.sanitizeCsvCellInput = sanitizeCsvCellInput;
19
+ function desanitizeCsvCellOutput(input) {
20
+ return SANITIZED_LINE_PREFIX_MATCHER.test(input)
21
+ ? input.slice(1).trim()
22
+ : input.trim();
23
+ }
24
+ var AllowedInputExtensions;
25
+ (function (AllowedInputExtensions) {
26
+ AllowedInputExtensions["Csv"] = ".csv";
27
+ AllowedInputExtensions["Json"] = ".json";
28
+ })(AllowedInputExtensions || (AllowedInputExtensions = {}));
29
+ async function parseCsvScenarios(fileName) {
30
+ const readCsv = await fileToCsvScenarioFormat(fileName);
31
+ return csvScenarioFormatToScenarios(readCsv);
32
+ }
33
+ exports.parseCsvScenarios = parseCsvScenarios;
34
+ async function fileToCsvScenarioFormat(fileName) {
35
+ const csvInput = [];
36
+ await new Promise((resolve) => {
37
+ fs_1.default.createReadStream(fileName)
38
+ .pipe((0, csv_parser_1.default)())
39
+ .on('data', (data) => csvInput.push(data))
40
+ .on('end', () => resolve());
41
+ });
42
+ return csvInput;
43
+ }
44
+ function csvScenarioFormatToScenarios(input) {
45
+ if (input.length === 0) {
46
+ return [];
47
+ }
48
+ return input.map((rowItem) => ({
49
+ id: rowItem[constants_1.SCENARIO_ID_HEADER] || undefined,
50
+ name: desanitizeCsvCellOutput(rowItem[constants_1.SCENARIO_NAME_HEADER]),
51
+ variables: Object.entries(rowItem)
52
+ .filter(([key, _]) => key !== constants_1.SCENARIO_NAME_HEADER && key !== constants_1.SCENARIO_ID_HEADER)
53
+ .map(([key, value]) => ({
54
+ name: desanitizeCsvCellOutput(key),
55
+ value: desanitizeCsvCellOutput(value),
56
+ })),
57
+ }));
58
+ }
59
+ exports.csvScenarioFormatToScenarios = csvScenarioFormatToScenarios;
60
+ function parseJsonScenarios(fileName) {
61
+ const readJson = fs_1.default.readFileSync(fileName, 'utf-8');
62
+ return jsonToScenarios(readJson);
63
+ }
64
+ exports.parseJsonScenarios = parseJsonScenarios;
65
+ function jsonToScenarios(input) {
66
+ const parsedJson = JSON.parse(input);
67
+ if (isScenarioArray(parsedJson)) {
68
+ return parsedJson;
69
+ }
70
+ throw Error('Json input was not formatted correctly');
71
+ }
72
+ exports.jsonToScenarios = jsonToScenarios;
73
+ function inferFileFormat(fileName) {
74
+ const extension = (0, path_1.extname)(fileName);
75
+ switch (extension) {
76
+ case AllowedInputExtensions.Csv:
77
+ return constants_1.OutputFormats.Csv;
78
+ case AllowedInputExtensions.Json:
79
+ return constants_1.OutputFormats.Json;
80
+ default:
81
+ throw new Error('The file format could be inferred from the extension, please specify a format for your input data.');
82
+ }
83
+ }
84
+ exports.inferFileFormat = inferFileFormat;
85
+ function isScenario(arg) {
86
+ return ((typeof arg.id === 'string' || arg.id === undefined) &&
87
+ typeof arg.name === 'string' &&
88
+ Array.isArray(arg.variables) &&
89
+ arg.variables.every((col) => typeof col.name === 'string' && typeof col.value === 'string'));
90
+ }
91
+ function isScenarioArray(arg) {
92
+ return Array.isArray(arg) && arg.every((scenario) => isScenario(scenario));
93
+ }
94
+ exports.isScenarioArray = isScenarioArray;
95
+ function dataTableAsVariableTable(dataTable) {
96
+ return {
97
+ id: dataTable.id,
98
+ organization_id: dataTable.workspace_id,
99
+ name: dataTable.name,
100
+ created_time: dataTable.created_time,
101
+ created_by_id: dataTable.created_by_id,
102
+ last_updated_time: dataTable.last_updated_time,
103
+ last_updated_by_id: dataTable.last_updated_by_id,
104
+ row_ids: dataTable.scenario_ids,
105
+ };
106
+ }
107
+ exports.dataTableAsVariableTable = dataTableAsVariableTable;
108
+ function scenarioAsVariableRow(scenario) {
109
+ return {
110
+ id: scenario === null || scenario === void 0 ? void 0 : scenario.id,
111
+ table_id: scenario === null || scenario === void 0 ? void 0 : scenario.table_id,
112
+ created_time: scenario === null || scenario === void 0 ? void 0 : scenario.created_time,
113
+ created_by_id: scenario === null || scenario === void 0 ? void 0 : scenario.created_by_id,
114
+ last_updated_time: scenario === null || scenario === void 0 ? void 0 : scenario.last_updated_time,
115
+ last_updated_by_id: scenario === null || scenario === void 0 ? void 0 : scenario.last_updated_by_id,
116
+ organization_id: scenario === null || scenario === void 0 ? void 0 : scenario.workspace_id,
117
+ scenario_id: scenario === null || scenario === void 0 ? void 0 : scenario.name,
118
+ row: scenario === null || scenario === void 0 ? void 0 : scenario.variables,
119
+ };
120
+ }
121
+ exports.scenarioAsVariableRow = scenarioAsVariableRow;
122
+ function variableRowAsScenario(variableRow) {
123
+ if (isScenario(variableRow)) {
124
+ return variableRow;
125
+ }
126
+ return {
127
+ id: variableRow.id,
128
+ table_id: variableRow.table_id,
129
+ created_time: variableRow.created_time,
130
+ created_by_id: variableRow.created_by_id,
131
+ last_updated_time: variableRow.last_updated_time,
132
+ last_updated_by_id: variableRow.last_updated_by_id,
133
+ workspace_id: variableRow.organization_id,
134
+ name: variableRow.scenario_id,
135
+ variables: variableRow.row,
136
+ };
137
+ }
138
+ exports.variableRowAsScenario = variableRowAsScenario;
@@ -42,6 +42,7 @@ const logUtils_1 = require("../../util/logUtils");
42
42
  const browserTypes_1 = require("../browserTypes");
43
43
  const constants_1 = require("../constants");
44
44
  const trainerUtil_1 = require("./tests_cmds/trainerUtil");
45
+ const utils_1 = require("../datatables/utils");
45
46
  const chalk = require('chalk');
46
47
  let RUNNING_TEST = false;
47
48
  function getFinalUrl(test, parsedUrl) {
@@ -394,31 +395,33 @@ function validateRunCommandWithLabels(testId, suppliedLabelsInclude, suppliedLab
394
395
  }
395
396
  exports.validateRunCommandWithLabels = validateRunCommandWithLabels;
396
397
  async function pullDownTestRunConfig(testRunId, apiClient) {
397
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
398
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
398
399
  const journeyRun = await apiClient.getTestRun(testRunId);
399
400
  const planRun = await apiClient.getPlanRun(journeyRun.parent_execution);
401
+ const testDatatablevariables = ((_a = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _a === void 0 ? void 0 : _a.user_variables) &&
402
+ (0, utils_1.variableRowAsScenario)((_b = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _b === void 0 ? void 0 : _b.user_variables);
400
403
  return {
401
- basicAuthCredentialsId: ((_a = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _a === void 0 ? void 0 : _a.http_auth_credentials_required)
402
- ? (_b = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _b === void 0 ? void 0 : _b.http_auth_credentials_id
404
+ basicAuthCredentialsId: ((_c = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _c === void 0 ? void 0 : _c.http_auth_credentials_required)
405
+ ? (_d = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _d === void 0 ? void 0 : _d.http_auth_credentials_id
403
406
  : undefined,
404
- branchName: (_c = journeyRun.journey_parameters) === null || _c === void 0 ? void 0 : _c.source_control_tag,
405
- credentialsId: ((_d = planRun.run_policy) === null || _d === void 0 ? void 0 : _d.credentials_required)
406
- ? (_e = planRun.run_policy) === null || _e === void 0 ? void 0 : _e.credentials_id
407
+ branchName: (_e = journeyRun.journey_parameters) === null || _e === void 0 ? void 0 : _e.source_control_tag,
408
+ credentialsId: ((_f = planRun.run_policy) === null || _f === void 0 ? void 0 : _f.credentials_required)
409
+ ? (_g = planRun.run_policy) === null || _g === void 0 ? void 0 : _g.credentials_id
407
410
  : undefined,
408
- dataTableVariables: (_f = journeyRun.journey_parameters) === null || _f === void 0 ? void 0 : _f.user_variables,
409
- deviceEmulation: (_g = journeyRun.journey_parameters) === null || _g === void 0 ? void 0 : _g.device_emulation,
410
- environmentId: (_j = (_h = journeyRun.journey_parameters) === null || _h === void 0 ? void 0 : _h.deployment) === null || _j === void 0 ? void 0 : _j.environment_id,
411
+ dataTableVariables: testDatatablevariables,
412
+ deviceEmulation: (_h = journeyRun.journey_parameters) === null || _h === void 0 ? void 0 : _h.device_emulation,
413
+ environmentId: (_k = (_j = journeyRun.journey_parameters) === null || _j === void 0 ? void 0 : _j.deployment) === null || _k === void 0 ? void 0 : _k.environment_id,
411
414
  filterHttpRequests: false,
412
- importedVariables: (_k = journeyRun.journey_parameters) === null || _k === void 0 ? void 0 : _k.imported_variables,
413
- pageLoadWait: (_l = journeyRun.journey_parameters) === null || _l === void 0 ? void 0 : _l.page_load_wait,
415
+ importedVariables: (_l = journeyRun.journey_parameters) === null || _l === void 0 ? void 0 : _l.imported_variables,
416
+ pageLoadWait: (_m = journeyRun.journey_parameters) === null || _m === void 0 ? void 0 : _m.page_load_wait,
414
417
  runId: journeyRun.id,
415
- testId: (_m = journeyRun.journey) === null || _m === void 0 ? void 0 : _m.invariant_id,
416
- url: (_p = (_o = journeyRun.journey_parameters) === null || _o === void 0 ? void 0 : _o.deployment) === null || _p === void 0 ? void 0 : _p.uri,
418
+ testId: (_o = journeyRun.journey) === null || _o === void 0 ? void 0 : _o.invariant_id,
419
+ url: (_q = (_p = journeyRun.journey_parameters) === null || _p === void 0 ? void 0 : _p.deployment) === null || _q === void 0 ? void 0 : _q.uri,
417
420
  };
418
421
  }
419
422
  exports.pullDownTestRunConfig = pullDownTestRunConfig;
420
423
  async function extractTestRunConfig(executionMessage, apiClient) {
421
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
424
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
422
425
  const journeyRun = (_a = executionMessage.journey_run) !== null && _a !== void 0 ? _a : (await apiClient.getTestRun(executionMessage.journey_run_id));
423
426
  const planRun = executionMessage.plan_run;
424
427
  const maybeRunnerType = ((_b = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _b === void 0 ? void 0 : _b.nodejs_runtime_variant)
@@ -430,16 +433,17 @@ async function extractTestRunConfig(executionMessage, apiClient) {
430
433
  credentialsId: ((_e = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _e === void 0 ? void 0 : _e.credentials_required)
431
434
  ? (_f = planRun === null || planRun === void 0 ? void 0 : planRun.run_policy) === null || _f === void 0 ? void 0 : _f.credentials_id
432
435
  : undefined,
433
- dataTableVariables: (_g = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _g === void 0 ? void 0 : _g.user_variables,
434
- deviceEmulation: (_h = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _h === void 0 ? void 0 : _h.device_emulation,
435
- environmentId: (_k = (_j = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _j === void 0 ? void 0 : _j.deployment) === null || _k === void 0 ? void 0 : _k.environment_id,
436
+ dataTableVariables: ((_g = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _g === void 0 ? void 0 : _g.user_variables) &&
437
+ (0, utils_1.variableRowAsScenario)((_h = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _h === void 0 ? void 0 : _h.user_variables),
438
+ deviceEmulation: (_j = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _j === void 0 ? void 0 : _j.device_emulation,
439
+ environmentId: (_l = (_k = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _k === void 0 ? void 0 : _k.deployment) === null || _l === void 0 ? void 0 : _l.environment_id,
436
440
  filterHttpRequests: true,
437
- importedVariables: (_l = journeyRun.journey_parameters) === null || _l === void 0 ? void 0 : _l.imported_variables,
438
- pageLoadWait: (_m = journeyRun.journey_parameters) === null || _m === void 0 ? void 0 : _m.page_load_wait,
441
+ importedVariables: (_m = journeyRun.journey_parameters) === null || _m === void 0 ? void 0 : _m.imported_variables,
442
+ pageLoadWait: (_o = journeyRun.journey_parameters) === null || _o === void 0 ? void 0 : _o.page_load_wait,
439
443
  runId: journeyRun.id,
440
444
  runnerType: maybeRunnerType,
441
- testId: (_o = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey) === null || _o === void 0 ? void 0 : _o.invariant_id,
442
- url: (_q = (_p = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _p === void 0 ? void 0 : _p.deployment) === null || _q === void 0 ? void 0 : _q.uri,
445
+ testId: (_p = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey) === null || _p === void 0 ? void 0 : _p.invariant_id,
446
+ url: (_r = (_q = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _q === void 0 ? void 0 : _q.deployment) === null || _r === void 0 ? void 0 : _r.uri,
443
447
  };
444
448
  }
445
449
  exports.extractTestRunConfig = extractTestRunConfig;