@mablhq/mabl-cli 2.19.13 → 2.20.7
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/README.md +2 -2
- package/api/mablApiClient.js +2 -2
- package/commands/tests/tests_cmds/run-cloud.js +1 -1
- package/core/execution/PostmanUtils.js +53 -0
- package/core/execution/VariableUtils.js +144 -0
- package/execution/index.js +1 -1
- package/mablscript/steps/IfConditionStep.js +3 -1
- package/package.json +1 -1
- package/util/pureUtil.js +10 -1
package/README.md
CHANGED
|
@@ -195,8 +195,8 @@ Use the:
|
|
|
195
195
|
- `--auto-branch` flag to automatically create the specified branch if it
|
|
196
196
|
doesn't exist already
|
|
197
197
|
- `--width` and `--height` flags to specify the viewport sizes of the browser
|
|
198
|
-
- `--creds` or `--credentials` flag to specify a testing credential set to
|
|
199
|
-
during edit (`mabl credentials list` to see available ones)
|
|
198
|
+
- `--creds` or `--credentials-id` flag to specify a testing credential set to
|
|
199
|
+
use during edit (`mabl credentials list` to see available ones)
|
|
200
200
|
|
|
201
201
|
_Note: required IDs can be found by using the CLI list commands or on the test
|
|
202
202
|
details or test output pages inside the mabl web app_
|
package/api/mablApiClient.js
CHANGED
|
@@ -843,14 +843,14 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
843
843
|
timeout: 3600000,
|
|
844
844
|
});
|
|
845
845
|
}
|
|
846
|
-
async
|
|
846
|
+
async getEnabledAccountFeaturesByWorkspaceId(workspaceId) {
|
|
847
847
|
var _a;
|
|
848
848
|
try {
|
|
849
849
|
const account = await this.getAccountByWorkspaceId(workspaceId);
|
|
850
850
|
return new featureSet_1.FeatureSet(new Set((_a = account.effective_features) !== null && _a !== void 0 ? _a : []));
|
|
851
851
|
}
|
|
852
852
|
catch (error) {
|
|
853
|
-
throw toApiError(`Failed to get
|
|
853
|
+
throw toApiError(`Failed to get effective account features for workspace ${workspaceId}`, error);
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
856
|
async getEnabledLabsFeaturesForWorkspace(workspaceId) {
|
|
@@ -223,7 +223,7 @@ async function executeRunCloudTest(test, browsers, branchName, apiClient, maybeD
|
|
|
223
223
|
? test === null || test === void 0 ? void 0 : test.url
|
|
224
224
|
: undefined);
|
|
225
225
|
const effectiveApiUrl = apiUrl !== null && apiUrl !== void 0 ? apiUrl : (test.test_type && test.test_type !== mablApi_1.TestTypeEnum.Browser
|
|
226
|
-
? test === null || test === void 0 ? void 0 : test.
|
|
226
|
+
? test === null || test === void 0 ? void 0 : test.api_url
|
|
227
227
|
: undefined);
|
|
228
228
|
const workspaceId = test.organization_id;
|
|
229
229
|
const testId = test.invariant_id;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeExportedVariables = exports.exportVariables = exports.convertVariablesSummaryToPostmanFormat = void 0;
|
|
4
|
+
const VariableUtils_1 = require("./VariableUtils");
|
|
5
|
+
const domUtil_1 = require("../../domUtil");
|
|
6
|
+
function convertVariablesSummaryToPostmanFormat(summary) {
|
|
7
|
+
const effectiveVariables = { ...summary.effective };
|
|
8
|
+
const values = Object.keys(effectiveVariables).map((key) => ({
|
|
9
|
+
key,
|
|
10
|
+
value: effectiveVariables[key],
|
|
11
|
+
}));
|
|
12
|
+
return {
|
|
13
|
+
values,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.convertVariablesSummaryToPostmanFormat = convertVariablesSummaryToPostmanFormat;
|
|
17
|
+
function exportVariables(postmanResult) {
|
|
18
|
+
const variablePrecedence = [
|
|
19
|
+
postmanResult === null || postmanResult === void 0 ? void 0 : postmanResult.globals.values,
|
|
20
|
+
postmanResult === null || postmanResult === void 0 ? void 0 : postmanResult.collection.variables,
|
|
21
|
+
postmanResult === null || postmanResult === void 0 ? void 0 : postmanResult.environment.values,
|
|
22
|
+
].filter((variables) => !!variables);
|
|
23
|
+
const exportedVariables = {};
|
|
24
|
+
variablePrecedence
|
|
25
|
+
.map((variableList) => variableList.all())
|
|
26
|
+
.forEach((variables) => variables.forEach((variable) => (exportedVariables[variable.key] = variable.value)));
|
|
27
|
+
return exportedVariables;
|
|
28
|
+
}
|
|
29
|
+
exports.exportVariables = exportVariables;
|
|
30
|
+
function sanitizeExportedVariables(variables) {
|
|
31
|
+
const normalized = {};
|
|
32
|
+
if (variables) {
|
|
33
|
+
return normalizeExportedVariables(filterExportedVariables(variables));
|
|
34
|
+
}
|
|
35
|
+
return normalized;
|
|
36
|
+
}
|
|
37
|
+
exports.sanitizeExportedVariables = sanitizeExportedVariables;
|
|
38
|
+
function normalizeExportedVariables(variables) {
|
|
39
|
+
const normalized = {};
|
|
40
|
+
Object.keys(variables).forEach((name) => {
|
|
41
|
+
normalized[(0, VariableUtils_1.addUserNamespace)(name)] = variables[name];
|
|
42
|
+
});
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
function filterExportedVariables(variables) {
|
|
46
|
+
const filtered = {};
|
|
47
|
+
Object.keys(variables)
|
|
48
|
+
.filter((name) => (0, domUtil_1.isValidUserVariableName)(name))
|
|
49
|
+
.forEach((name) => {
|
|
50
|
+
filtered[name] = variables[name];
|
|
51
|
+
});
|
|
52
|
+
return filtered;
|
|
53
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addUserNamespace = exports.generateVariablesSummaryForExport = exports.generateVariablesSummaryForImport = exports.API_CREDENTIALS_PASSWORD_VARIABLE_NAME = exports.API_CREDENTIALS_USERNAME_VARIABLE_NAME = exports.API_CREDENTIALS_NAMESPACE = exports.API_URL_VARIABLE_NAME = exports.API_NAMESPACE = exports.FLOW_NAMESPACE = exports.USER_NAMESPACE = void 0;
|
|
4
|
+
const domUtil_1 = require("../../domUtil");
|
|
5
|
+
exports.USER_NAMESPACE = 'user.';
|
|
6
|
+
exports.FLOW_NAMESPACE = 'flow.';
|
|
7
|
+
exports.API_NAMESPACE = 'api.';
|
|
8
|
+
exports.API_URL_VARIABLE_NAME = `${exports.API_NAMESPACE}url`;
|
|
9
|
+
exports.API_CREDENTIALS_NAMESPACE = `${exports.API_NAMESPACE}credentials.`;
|
|
10
|
+
exports.API_CREDENTIALS_USERNAME_VARIABLE_NAME = `${exports.API_CREDENTIALS_NAMESPACE}username`;
|
|
11
|
+
exports.API_CREDENTIALS_PASSWORD_VARIABLE_NAME = `${exports.API_CREDENTIALS_NAMESPACE}password`;
|
|
12
|
+
function generateVariablesSummaryForImport(variableSources) {
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
14
|
+
const { environment, scenario, url, credentials, plan, flow, journeyRun, previousFlowVariables, } = variableSources;
|
|
15
|
+
const summary = {
|
|
16
|
+
dataDriven: {},
|
|
17
|
+
effective: {},
|
|
18
|
+
environment: {},
|
|
19
|
+
flow: {},
|
|
20
|
+
journey: {},
|
|
21
|
+
parameters: {},
|
|
22
|
+
};
|
|
23
|
+
const environmentVariables = (environment === null || environment === void 0 ? void 0 : environment.variables) || {};
|
|
24
|
+
Object.keys(environmentVariables).forEach((key) => (summary.environment[removeUserNamespace(key)] =
|
|
25
|
+
environmentVariables[key]));
|
|
26
|
+
const planParameters = extractValueParameters(plan === null || plan === void 0 ? void 0 : plan.parameters);
|
|
27
|
+
planParameters.forEach((parameter) => (summary.parameters[removeUserNamespace(parameter.name)] =
|
|
28
|
+
parameter.value));
|
|
29
|
+
const journeyParameters = extractValueParameters(journeyRun &&
|
|
30
|
+
(plan === null || plan === void 0 ? void 0 : plan.execution_stages) &&
|
|
31
|
+
((_c = (_b = (_a = plan.execution_stages[journeyRun.stage_index]) === null || _a === void 0 ? void 0 : _a.journeys) === null || _b === void 0 ? void 0 : _b.find((journey) => journey.journey_id)) === null || _c === void 0 ? void 0 : _c.parameters));
|
|
32
|
+
journeyParameters.forEach((parameter) => (summary.parameters[removeUserNamespace(parameter.name)] =
|
|
33
|
+
parameter.value));
|
|
34
|
+
const journeyInputs = ((_d = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _d === void 0 ? void 0 : _d.imported_variables) || {};
|
|
35
|
+
Object.keys(journeyInputs).forEach((key) => (summary.journey[removeUserNamespace(key)] = journeyInputs[key]));
|
|
36
|
+
const ddtVariables = ((_f = (_e = journeyRun === null || journeyRun === void 0 ? void 0 : journeyRun.journey_parameters) === null || _e === void 0 ? void 0 : _e.user_variables) === null || _f === void 0 ? void 0 : _f.row) ||
|
|
37
|
+
(scenario === null || scenario === void 0 ? void 0 : scenario.variables) ||
|
|
38
|
+
[];
|
|
39
|
+
ddtVariables.forEach((variable) => (summary.dataDriven[removeUserNamespace(variable.name)] =
|
|
40
|
+
variable.value));
|
|
41
|
+
const precedence = [
|
|
42
|
+
summary.environment,
|
|
43
|
+
summary.parameters,
|
|
44
|
+
summary.journey,
|
|
45
|
+
summary.dataDriven,
|
|
46
|
+
];
|
|
47
|
+
precedence.forEach((variables) => Object.keys(variables).forEach((name) => (summary.effective[name] = variables[name])));
|
|
48
|
+
if (flow === null || flow === void 0 ? void 0 : flow.parameters) {
|
|
49
|
+
flow.parameters.forEach((parameter) => {
|
|
50
|
+
const parameterName = removePrefix(parameter.name, exports.FLOW_NAMESPACE);
|
|
51
|
+
summary.flow[parameterName] = parameter.default_value;
|
|
52
|
+
if (!summary.effective[parameterName]) {
|
|
53
|
+
summary.effective[parameterName] = parameter.default_value;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const exportedVariables = previousFlowVariables || {};
|
|
58
|
+
Object.keys(exportedVariables).forEach((key) => {
|
|
59
|
+
summary.dataDriven[key] = exportedVariables[key];
|
|
60
|
+
summary.effective[key] = exportedVariables[key];
|
|
61
|
+
});
|
|
62
|
+
if (url) {
|
|
63
|
+
summary.effective[exports.API_URL_VARIABLE_NAME] = url;
|
|
64
|
+
}
|
|
65
|
+
if (credentials) {
|
|
66
|
+
summary.effective[exports.API_CREDENTIALS_USERNAME_VARIABLE_NAME] =
|
|
67
|
+
(_g = credentials.properties) === null || _g === void 0 ? void 0 : _g.username;
|
|
68
|
+
summary.effective[exports.API_CREDENTIALS_PASSWORD_VARIABLE_NAME] =
|
|
69
|
+
(_h = credentials.properties) === null || _h === void 0 ? void 0 : _h.password;
|
|
70
|
+
}
|
|
71
|
+
return summary;
|
|
72
|
+
}
|
|
73
|
+
exports.generateVariablesSummaryForImport = generateVariablesSummaryForImport;
|
|
74
|
+
function generateVariablesSummaryForExport(testContext, plan, flow, journeyRun, exportedVariables) {
|
|
75
|
+
return normalizeVariablesSummaryForExport(generateVariablesSummaryForImport({
|
|
76
|
+
environment: testContext.environment,
|
|
77
|
+
url: testContext.url,
|
|
78
|
+
credentials: testContext.credentials,
|
|
79
|
+
scenario: testContext.getScenario(),
|
|
80
|
+
plan,
|
|
81
|
+
flow,
|
|
82
|
+
journeyRun,
|
|
83
|
+
previousFlowVariables: exportedVariables,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
exports.generateVariablesSummaryForExport = generateVariablesSummaryForExport;
|
|
87
|
+
function normalizeVariablesSummaryForExport(summary) {
|
|
88
|
+
return {
|
|
89
|
+
dataDriven: addUserNamespaceToVariableNames(sanitizeVariables(summary.dataDriven)),
|
|
90
|
+
effective: sanitizeVariables(summary.effective),
|
|
91
|
+
environment: addUserNamespaceToVariableNames(sanitizeVariables(summary.environment)),
|
|
92
|
+
flow: addPrefixToVariableNames(sanitizeVariables(summary.flow), exports.FLOW_NAMESPACE),
|
|
93
|
+
journey: addUserNamespaceToVariableNames(sanitizeVariables(summary.journey)),
|
|
94
|
+
parameters: addUserNamespaceToVariableNames(sanitizeVariables(summary.parameters)),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function sanitizeVariables(variables) {
|
|
98
|
+
const sanitizedVariables = {};
|
|
99
|
+
Object.keys(variables)
|
|
100
|
+
.filter((name) => (0, domUtil_1.isValidUserVariableName)(name))
|
|
101
|
+
.forEach((name) => (sanitizedVariables[name] = variables[name]));
|
|
102
|
+
return sanitizedVariables;
|
|
103
|
+
}
|
|
104
|
+
function addUserNamespaceToVariableNames(variables) {
|
|
105
|
+
return addPrefixToVariableNames(variables, exports.USER_NAMESPACE);
|
|
106
|
+
}
|
|
107
|
+
function addPrefixToVariableNames(variables, prefix) {
|
|
108
|
+
return mapVariables(variables, (variable) => ({
|
|
109
|
+
name: addPrefix(variable.name, prefix),
|
|
110
|
+
value: variable.value,
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
function mapVariables(variables, mapper) {
|
|
114
|
+
const mappedVariables = {};
|
|
115
|
+
Object.keys(variables)
|
|
116
|
+
.map((name) => mapper({ name, value: variables[name] }))
|
|
117
|
+
.forEach((variable) => (mappedVariables[variable.name] = variable.value));
|
|
118
|
+
return mappedVariables;
|
|
119
|
+
}
|
|
120
|
+
function extractValueParameters(parameters) {
|
|
121
|
+
if (!parameters) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
return parameters.filter((parameter) => { var _a; return ((_a = parameter.type) === null || _a === void 0 ? void 0 : _a.toString()) === 'value'; });
|
|
125
|
+
}
|
|
126
|
+
function removeUserNamespace(variableName) {
|
|
127
|
+
return removePrefix(variableName, exports.USER_NAMESPACE);
|
|
128
|
+
}
|
|
129
|
+
function removePrefix(variableName, prefix) {
|
|
130
|
+
if (variableName.startsWith(prefix)) {
|
|
131
|
+
return variableName.substring(prefix.length);
|
|
132
|
+
}
|
|
133
|
+
return variableName;
|
|
134
|
+
}
|
|
135
|
+
function addUserNamespace(variableName) {
|
|
136
|
+
return addPrefix(variableName, exports.USER_NAMESPACE);
|
|
137
|
+
}
|
|
138
|
+
exports.addUserNamespace = addUserNamespace;
|
|
139
|
+
function addPrefix(variableName, prefix) {
|
|
140
|
+
if (variableName.startsWith(prefix)) {
|
|
141
|
+
return variableName;
|
|
142
|
+
}
|
|
143
|
+
return `${prefix}${variableName}`;
|
|
144
|
+
}
|