@mablhq/mabl-cli 1.62.1 → 2.1.0
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/api/basicApiClient.js +10 -10
- package/api/mablApiClient.js +39 -1
- package/browserLauncher/playwrightBrowserLauncher/playwrightBrowser.js +6 -6
- package/cli.js +1 -0
- package/commands/app-files/app-files.js +5 -0
- package/commands/app-files/app-files_cmds/create.js +98 -0
- package/commands/app-files/app-files_cmds/delete.js +31 -0
- package/commands/app-files/app-files_cmds/download.js +50 -0
- package/commands/app-files/app-files_cmds/list.js +72 -0
- package/commands/config/config_cmds/install.js +92 -0
- package/commands/constants.js +9 -2
- package/commands/tests/testsUtil.js +9 -1
- package/commands/tests/tests_cmds/run-mobile.js +218 -0
- package/commands/tests/tests_cmds/run.js +1 -1
- package/core/util.js +36 -2
- package/env/defaultEnv.js +2 -1
- package/env/dev.js +2 -1
- package/env/env.js +3 -1
- package/env/local.js +2 -1
- package/env/prod.js +2 -1
- package/execution/index.js +13 -1
- package/execution/runAppiumServer.js +133 -0
- package/http/MablHttpAgent.js +1 -4
- package/http/RequestFilteringHttpAgent.js +3 -3
- package/http/axiosProxyConfig.js +10 -7
- package/http/httpUtil.js +10 -6
- package/index.js +3 -2
- package/mablApi/index.js +1 -1
- package/mablscript/MablAction.js +6 -2
- package/mablscript/MablStep.js +41 -5
- package/mablscript/MablStepV2.js +57 -0
- package/mablscript/MablSymbol.js +6 -2
- package/mablscript/actions/AwaitDownloadAction.js +1 -1
- package/mablscript/actions/ConditionAction.js +1 -1
- package/mablscript/actions/CountAction.js +1 -1
- package/mablscript/actions/ExtractAction.js +12 -7
- package/mablscript/actions/FindAction.js +6 -6
- package/mablscript/actions/GenerateEmailAddressAction.js +1 -1
- package/mablscript/actions/GenerateRandomStringAction.js +1 -1
- package/mablscript/actions/GetUrlAction.js +1 -1
- package/mablscript/actions/GetVariableValue.js +1 -1
- package/mablscript/actions/JavaScriptAction.js +25 -14
- package/mablscript/importer.js +99 -16
- package/mablscript/mobile/steps/CreateVariableMobileStep.js +53 -0
- package/mablscript/mobile/steps/EnterTextStep.js +41 -0
- package/mablscript/mobile/steps/NavigateBackStep.js +20 -0
- package/mablscript/mobile/steps/NavigateHomeStep.js +21 -0
- package/mablscript/mobile/steps/ScrollStep.js +37 -0
- package/mablscript/mobile/steps/SetOrientationStep.js +20 -0
- package/mablscript/mobile/steps/TapStep.js +37 -0
- package/mablscript/mobile/steps/actions/MobileFindAction.js +23 -0
- package/mablscript/mobile/steps/stepUtil.js +74 -0
- package/mablscript/mobile/tests/StepTestsUtil.js +20 -0
- package/mablscript/mobile/tests/TestMobileFindDescriptors.js +215 -0
- package/mablscript/mobile/tests/steps/CreateVariableMobileStep.mobiletest.js +298 -0
- package/mablscript/mobile/tests/steps/EnterTextStep.mobiletest.js +79 -0
- package/mablscript/mobile/tests/steps/GeneralHumanization.mobiletest.js +167 -0
- package/mablscript/mobile/tests/steps/NavigateBackStep.mobiletest.js +27 -0
- package/mablscript/mobile/tests/steps/NavigateHomeStep.mobiletest.js +27 -0
- package/mablscript/mobile/tests/steps/ScrollStep.mobiletest.js +121 -0
- package/mablscript/mobile/tests/steps/SetOrientationStep.mobiletest.js +32 -0
- package/mablscript/mobile/tests/steps/TapStep.mobiletest.js +57 -0
- package/mablscript/steps/AccessibilityCheck.js +20 -9
- package/mablscript/steps/AssertStep.js +54 -39
- package/mablscript/steps/AssertStepOld.js +35 -4
- package/mablscript/steps/AwaitTabStep.js +5 -2
- package/mablscript/steps/AwaitUploadsStep.js +6 -4
- package/mablscript/steps/ClearCookiesStep.js +6 -4
- package/mablscript/steps/ClickAndHoldStep.js +10 -3
- package/mablscript/steps/ClickStep.js +10 -3
- package/mablscript/steps/CreateVariableStep.js +25 -8
- package/mablscript/steps/DoubleClickStep.js +10 -3
- package/mablscript/steps/DownloadStep.js +4 -2
- package/mablscript/steps/EchoStep.js +8 -5
- package/mablscript/steps/ElseIfConditionStep.js +14 -4
- package/mablscript/steps/ElseStep.js +8 -5
- package/mablscript/steps/EndStep.js +8 -5
- package/mablscript/steps/EnterAuthCodeStep.js +10 -3
- package/mablscript/steps/EnterTextStep.js +8 -2
- package/mablscript/steps/EvaluateFlowStep.js +5 -2
- package/mablscript/steps/EvaluateJavaScriptStep.js +15 -4
- package/mablscript/steps/HoverStep.js +10 -3
- package/mablscript/steps/IfConditionStep.js +25 -12
- package/mablscript/steps/NavigateStep.js +5 -2
- package/mablscript/steps/OpenEmailStep.js +5 -2
- package/mablscript/steps/ReleaseStep.js +10 -3
- package/mablscript/steps/RemoveCookieStep.js +5 -2
- package/mablscript/steps/RightClickStep.js +10 -3
- package/mablscript/steps/SelectStep.js +9 -3
- package/mablscript/steps/SendHttpRequestStep.js +8 -4
- package/mablscript/steps/SendKeyStep.js +10 -3
- package/mablscript/steps/SetCookieStep.js +5 -2
- package/mablscript/steps/SetFilesStep.js +9 -3
- package/mablscript/steps/SetViewportStep.js +5 -3
- package/mablscript/steps/SwitchContextStep.js +14 -3
- package/mablscript/steps/SyntheticStep.js +1 -1
- package/mablscript/steps/VisitUrlStep.js +5 -2
- package/mablscript/steps/WaitStep.js +8 -4
- package/mablscript/steps/WaitUntilStep.js +6 -3
- package/mablscript/types/GetVariableDescriptor.js +8 -3
- package/mablscript/types/mobile/CreateVariableMobileStepDescriptor.js +9 -0
- package/mablscript/types/mobile/EnterTextStepDescriptor.js +2 -0
- package/mablscript/types/mobile/NavigateBackStepDescriptor.js +2 -0
- package/mablscript/types/mobile/NavigateHomeStepDescriptor.js +2 -0
- package/mablscript/types/mobile/ScrollStepDescriptor.js +2 -0
- package/mablscript/types/mobile/SetOrientationStepDescriptor.js +8 -0
- package/mablscript/types/mobile/StepWithMobileFindDescriptor.js +2 -0
- package/mablscript/types/mobile/TapStepDescriptor.js +8 -0
- package/mablscriptFind/index.js +1 -1
- package/observers/ObserverBase.js +9 -0
- package/observers/mockObserver.js +3 -3
- package/package.json +11 -6
- package/resources/webdriver.js +21 -0
- package/upload/index.js +5 -0
- package/util/FileCache.js +180 -0
- package/util/Lazy.js +90 -0
- package/util/MobileAppFileCache.js +102 -0
- package/util/RichPromise.js +3 -1
- package/util/javaScriptStepMigration.js +1 -0
- package/webdriver/index.js +41 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
const defaultEnv_1 = require("../../../env/defaultEnv");
|
|
28
|
+
const execution_1 = require("../../../execution");
|
|
29
|
+
const mablApi_1 = require("../../../mablApi");
|
|
30
|
+
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
31
|
+
const util_1 = require("../../commandUtil/util");
|
|
32
|
+
const constants_1 = require("../../constants");
|
|
33
|
+
const testsUtil_1 = require("../testsUtil");
|
|
34
|
+
const runUtils_1 = require("./runUtils");
|
|
35
|
+
const MobileAppFileCache_1 = require("../../../util/MobileAppFileCache");
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const resourceUtil_1 = require("../../../util/resourceUtil");
|
|
38
|
+
const chalk = require('chalk');
|
|
39
|
+
const execution = require('../../../execution/index');
|
|
40
|
+
exports.command = `run-mobile`;
|
|
41
|
+
exports.describe = false;
|
|
42
|
+
exports.builder = (yargs) => {
|
|
43
|
+
yargs
|
|
44
|
+
.example('$0 tests run-mobile --id <id> --app-file <path> --platform <platform>', 'run mobile test locally by id')
|
|
45
|
+
.option(constants_1.CommandArgId, {
|
|
46
|
+
describe: 'The id of the test to run',
|
|
47
|
+
type: 'string',
|
|
48
|
+
})
|
|
49
|
+
.option(constants_1.CommandArgMobileAppFile, {
|
|
50
|
+
describe: 'The path to the mobile application binary',
|
|
51
|
+
type: 'string',
|
|
52
|
+
})
|
|
53
|
+
.option(constants_1.CommandArgMobileAppFileId, {
|
|
54
|
+
describe: 'The ID of a previously uploaded mobile app file',
|
|
55
|
+
type: 'string',
|
|
56
|
+
})
|
|
57
|
+
.option(constants_1.CommandArgMobilePlatform, {
|
|
58
|
+
describe: 'The mobile platform',
|
|
59
|
+
defaultDescription: 'inferred from app binary extension',
|
|
60
|
+
type: 'string',
|
|
61
|
+
choices: [mablApi_1.MobilePlatformEnum.Android, mablApi_1.MobilePlatformEnum.Ios],
|
|
62
|
+
})
|
|
63
|
+
.option(constants_1.CommandArgWorkspaceId, {
|
|
64
|
+
alias: constants_1.CommandArgAliases.WorkspaceId,
|
|
65
|
+
describe: 'Workspace to run against',
|
|
66
|
+
nargs: 1,
|
|
67
|
+
type: 'string',
|
|
68
|
+
})
|
|
69
|
+
.option(constants_1.CommandArgReporter, {
|
|
70
|
+
describe: 'Output test run information for specified reporter',
|
|
71
|
+
hidden: true,
|
|
72
|
+
type: 'string',
|
|
73
|
+
choices: [constants_1.ReporterOptions.Mochawesome],
|
|
74
|
+
})
|
|
75
|
+
.option(constants_1.CommandArgReporterOptions, {
|
|
76
|
+
describe: 'Reporter options as comma separated key/values pairs. e.g. "reportDir=path/to,json=true"',
|
|
77
|
+
hidden: true,
|
|
78
|
+
type: 'string',
|
|
79
|
+
})
|
|
80
|
+
.option(constants_1.CommandArgMobileDeviceName, {
|
|
81
|
+
describe: 'Full name of the device to use for the test',
|
|
82
|
+
hidden: false,
|
|
83
|
+
type: 'string',
|
|
84
|
+
})
|
|
85
|
+
.implies(constants_1.CommandArgReporterOptions, constants_1.CommandArgReporter)
|
|
86
|
+
.middleware(inferMobilePlatform);
|
|
87
|
+
};
|
|
88
|
+
const exitCodeOnError = 1;
|
|
89
|
+
exports.handler = (0, util_1.failWrapper)(run, exitCodeOnError);
|
|
90
|
+
function validateMobileCommand(id, appFile, appFileId, platform) {
|
|
91
|
+
if (!id || (!appFile && !appFileId) || !platform) {
|
|
92
|
+
loggingProvider_1.logger.error(chalk.red(`Please provide the arguments --${constants_1.CommandArgId}, --${constants_1.CommandArgMobileAppFile} or --${constants_1.CommandArgMobileAppFileId}, and --${constants_1.CommandArgMobilePlatform}`));
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (appFile && appFileId) {
|
|
96
|
+
loggingProvider_1.logger.error(chalk.red(`Only one of { --${constants_1.CommandArgMobileAppFile}, --${constants_1.CommandArgMobileAppFileId} } may be specified`));
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
async function run(parsed) {
|
|
102
|
+
if (!validateMobileCommand(parsed[constants_1.CommandArgId], parsed[constants_1.CommandArgMobileAppFile], parsed[constants_1.CommandArgMobileAppFileId], parsed[constants_1.CommandArgMobilePlatform])) {
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const commandStartTime = Date.now();
|
|
106
|
+
let workspaceId;
|
|
107
|
+
try {
|
|
108
|
+
workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
}
|
|
112
|
+
const parentDirOfNodeModulesDir = (0, resourceUtil_1.findNodeModulesDirectories)()[0];
|
|
113
|
+
const mobileToolsInstalled = fs.existsSync((0, path_1.resolve)(parentDirOfNodeModulesDir, 'node_modules/appium-uiautomator2-driver'));
|
|
114
|
+
if (!mobileToolsInstalled) {
|
|
115
|
+
loggingProvider_1.logger.error(`[ERROR] Missing the mobile tools for running tests, run ${chalk.magenta('mabl config install mobile-tools')} to install them`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const platformName = (0, execution_1.parsePlatformName)(parsed[constants_1.CommandArgMobilePlatform]);
|
|
119
|
+
await validateSystemRequirements(platformName, parsed[constants_1.CommandArgMobileDeviceName]);
|
|
120
|
+
const testRunnerConfig = {
|
|
121
|
+
_cliCreated: true,
|
|
122
|
+
filterHttpRequests: false,
|
|
123
|
+
testId: parsed.id,
|
|
124
|
+
workspaceId,
|
|
125
|
+
mobileConfig: {
|
|
126
|
+
mobileAppFileId: parsed[constants_1.CommandArgMobileAppFileId],
|
|
127
|
+
path: parsed[constants_1.CommandArgMobileAppFile],
|
|
128
|
+
platformName,
|
|
129
|
+
avdName: parsed[constants_1.CommandArgMobileDeviceName],
|
|
130
|
+
udid: parsed[constants_1.CommandArgMobileDeviceName],
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
loggingProvider_1.logger.info('Warming up test runner...');
|
|
134
|
+
const mablTestsRunner = await execution.createMobileTestsRunner(testRunnerConfig);
|
|
135
|
+
const results = await mablTestsRunner.run();
|
|
136
|
+
if ((mablTestsRunner === null || mablTestsRunner === void 0 ? void 0 : mablTestsRunner.mablTestRunners) !== undefined) {
|
|
137
|
+
mablTestsRunner.mablTestRunners
|
|
138
|
+
.filter((tr) => tr instanceof execution_1.MablTestRunner)
|
|
139
|
+
.forEach((tr) => {
|
|
140
|
+
const testContext = tr.testContext;
|
|
141
|
+
(0, testsUtil_1.cleanupTestResources)(testContext);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
await (0, runUtils_1.logTestResults)(results, parsed, commandStartTime, generateRunCommandTemplate(parsed, results));
|
|
145
|
+
if (!results.success && !testRunnerConfig.keepBrowserOpen) {
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function generateRunCommandTemplate(parsed, testResults) {
|
|
150
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
151
|
+
const testResult = testResults.testResults[0];
|
|
152
|
+
let templateCommand = `${defaultEnv_1.SCRIPT_NAME} ${parsed._.join(' ')} \\\n`;
|
|
153
|
+
if ((_a = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _a === void 0 ? void 0 : _a.environmentId) {
|
|
154
|
+
templateCommand = `${templateCommand} --${constants_1.CommandArgEnvironmentId} ${(_b = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _b === void 0 ? void 0 : _b.environmentId} \\\n`;
|
|
155
|
+
}
|
|
156
|
+
if ((_c = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _c === void 0 ? void 0 : _c.credentialsId) {
|
|
157
|
+
templateCommand = `${templateCommand} --${constants_1.CommandArgCredentials} ${(_d = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _d === void 0 ? void 0 : _d.credentialsId} \\\n`;
|
|
158
|
+
}
|
|
159
|
+
if ((_e = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _e === void 0 ? void 0 : _e.url) {
|
|
160
|
+
templateCommand = `${templateCommand} --${constants_1.CommandArgUrl} ${(_f = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _f === void 0 ? void 0 : _f.url} \\\n`;
|
|
161
|
+
}
|
|
162
|
+
if ((_g = testResult === null || testResult === void 0 ? void 0 : testResult.rerunConfig) === null || _g === void 0 ? void 0 : _g.branch) {
|
|
163
|
+
templateCommand = `${templateCommand} --${constants_1.CommandArgMablBranch} ${testResult.rerunConfig.branch} \\\n`;
|
|
164
|
+
}
|
|
165
|
+
const testIdVal = parsed.id ? parsed.id : '<TEST-ID>';
|
|
166
|
+
templateCommand = `${templateCommand} --${constants_1.CommandArgId} ${testIdVal}`;
|
|
167
|
+
return templateCommand;
|
|
168
|
+
}
|
|
169
|
+
async function validateSystemRequirements(platform, deviceName) {
|
|
170
|
+
let requirements;
|
|
171
|
+
if (platform === mablApi_1.MobilePlatformEnum.Ios) {
|
|
172
|
+
requirements = await (0, execution_1.systemIsSimulatorReady)(deviceName);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
requirements = await (0, execution_1.systemIsEmulatorReady)(deviceName);
|
|
176
|
+
}
|
|
177
|
+
if (!requirements.requirementsMet) {
|
|
178
|
+
const errorMessages = [];
|
|
179
|
+
Object.values(requirements.checks).forEach((requirement) => {
|
|
180
|
+
if (!requirement.requirementsMet && requirement.informationalText) {
|
|
181
|
+
errorMessages.push(requirement.informationalText);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
loggingProvider_1.logger.error('Failed while checking system requirements for testing mobile code. Errors: ');
|
|
185
|
+
for (const errorMessage of errorMessages) {
|
|
186
|
+
loggingProvider_1.logger.error(` * ${errorMessage}`);
|
|
187
|
+
}
|
|
188
|
+
process.exit(exitCodeOnError);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function inferMobilePlatform(argv) {
|
|
192
|
+
if (!argv[constants_1.CommandArgMobilePlatform] && argv[constants_1.CommandArgMobileAppFileId]) {
|
|
193
|
+
if (argv[constants_1.CommandArgMobileAppFileId]) {
|
|
194
|
+
try {
|
|
195
|
+
const { platform } = await new MobileAppFileCache_1.MobileAppFileCache().getMobileAppFileImmutableFields(argv[constants_1.CommandArgMobileAppFileId]);
|
|
196
|
+
if (platform) {
|
|
197
|
+
argv[constants_1.CommandArgMobilePlatform] = platform.toString().toLowerCase();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
loggingProvider_1.logger.warn(chalk.yellow(`Warning: Unable to fetch mobile app file ${argv[constants_1.CommandArgMobileAppFile]}: ${error}`));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const extension = (0, path_1.extname)(argv[constants_1.CommandArgMobileAppFile]).toLowerCase();
|
|
206
|
+
switch (extension) {
|
|
207
|
+
case '.apk':
|
|
208
|
+
argv[constants_1.CommandArgMobilePlatform] = mablApi_1.MobilePlatformEnum.Android;
|
|
209
|
+
break;
|
|
210
|
+
case '.ipa':
|
|
211
|
+
case '.app':
|
|
212
|
+
argv[constants_1.CommandArgMobilePlatform] = mablApi_1.MobilePlatformEnum.Ios;
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
loggingProvider_1.logger.warn(chalk.yellow(`Warning: Unable to infer the mobile platform from the file extension: '${extension}' Please provide a --platform command line argument.`));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -272,7 +272,7 @@ async function run(parsed) {
|
|
|
272
272
|
workspaceId,
|
|
273
273
|
};
|
|
274
274
|
loggingProvider_1.logger.info('Warming up test runner...');
|
|
275
|
-
const mablTestsRunner = await execution.
|
|
275
|
+
const mablTestsRunner = await execution.createBrowserTestsRunner(testRunnerConfig);
|
|
276
276
|
const results = await mablTestsRunner.run();
|
|
277
277
|
if ((mablTestsRunner === null || mablTestsRunner === void 0 ? void 0 : mablTestsRunner.mablTestRunners) !== undefined) {
|
|
278
278
|
mablTestsRunner.mablTestRunners
|
package/core/util.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiClientFromOptions = void 0;
|
|
6
|
+
exports.validateAuthentication = exports.getApiClientFromOptions = exports.getApiClient = exports.INVALID_AUTH_ERROR = void 0;
|
|
4
7
|
const mablApiClientFactory_1 = require("../api/mablApiClientFactory");
|
|
8
|
+
const asyncUtil_1 = require("../util/asyncUtil");
|
|
9
|
+
const authenticationProvider_1 = require("../providers/authenticationProvider");
|
|
10
|
+
const types_1 = require("../api/types");
|
|
11
|
+
const mablApi_1 = require("../mablApi");
|
|
12
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
+
const DEFAULT_ASYNC_TIMEOUT_MILLIS = 120000;
|
|
14
|
+
exports.INVALID_AUTH_ERROR = `Auth with user credentials required. Please run ${chalk_1.default.magenta('mabl auth login')} to log in with your mabl account`;
|
|
15
|
+
async function getApiClient(options = {}) {
|
|
16
|
+
const { asyncTimeoutMillis, authenticationConfig, runOptions, userAuthOnly, validateAuth, } = options;
|
|
17
|
+
const apiClient = await (0, asyncUtil_1.promiseWithTimeout)(getApiClientFromOptions(runOptions, userAuthOnly), asyncTimeoutMillis !== null && asyncTimeoutMillis !== void 0 ? asyncTimeoutMillis : DEFAULT_ASYNC_TIMEOUT_MILLIS, 'Get API client from options');
|
|
18
|
+
if (validateAuth !== null && validateAuth !== void 0 ? validateAuth : true) {
|
|
19
|
+
await (0, asyncUtil_1.promiseWithTimeout)(validateAuthentication(apiClient, authenticationConfig !== null && authenticationConfig !== void 0 ? authenticationConfig : (await (0, asyncUtil_1.promiseWithTimeout)(new authenticationProvider_1.AuthenticationProvider().getAuthConfigWithAutoRenew(), DEFAULT_ASYNC_TIMEOUT_MILLIS, 'Get auth config with auto renew'))), asyncTimeoutMillis !== null && asyncTimeoutMillis !== void 0 ? asyncTimeoutMillis : DEFAULT_ASYNC_TIMEOUT_MILLIS, 'Validate auth');
|
|
20
|
+
}
|
|
21
|
+
return apiClient;
|
|
22
|
+
}
|
|
23
|
+
exports.getApiClient = getApiClient;
|
|
5
24
|
async function getApiClientFromOptions(trainingSessionOptions, userAuthOnly) {
|
|
6
|
-
if (trainingSessionOptions.authToken) {
|
|
25
|
+
if (trainingSessionOptions === null || trainingSessionOptions === void 0 ? void 0 : trainingSessionOptions.authToken) {
|
|
7
26
|
return mablApiClientFactory_1.MablApiClientFactory.createApiClientForAccessToken(trainingSessionOptions.authToken);
|
|
8
27
|
}
|
|
9
28
|
if (userAuthOnly) {
|
|
@@ -12,3 +31,18 @@ async function getApiClientFromOptions(trainingSessionOptions, userAuthOnly) {
|
|
|
12
31
|
return mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
13
32
|
}
|
|
14
33
|
exports.getApiClientFromOptions = getApiClientFromOptions;
|
|
34
|
+
async function validateAuthentication(apiClient, authConfig) {
|
|
35
|
+
if (authConfig.authType !== types_1.AuthType.ApiKey) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const keyDetails = await apiClient.getApiKeyDetails();
|
|
40
|
+
if (keyDetails.type === mablApi_1.ApiKeyType.CommandLineInterface) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (_) {
|
|
45
|
+
}
|
|
46
|
+
throw new Error(exports.INVALID_AUTH_ERROR);
|
|
47
|
+
}
|
|
48
|
+
exports.validateAuthentication = validateAuthentication;
|
package/env/defaultEnv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
3
|
+
exports.UPLOAD_SERVICE_URL = exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
4
4
|
exports.BASE_API_URL = 'https://api.mabl.com';
|
|
5
5
|
exports.BASE_APP_URL = 'https://app.mabl.com';
|
|
6
6
|
exports.CONF_FILE_PROJECT_NAME = 'mabl-cli';
|
|
@@ -15,3 +15,4 @@ exports.OKTA_URL = 'https://auth2.mabl.com';
|
|
|
15
15
|
exports.SCRIPT_NAME = 'mabl';
|
|
16
16
|
exports.ELECTRON_PROTOCOL = 'mabl-app';
|
|
17
17
|
exports.FIND_OVERRIDE_PATH = undefined;
|
|
18
|
+
exports.UPLOAD_SERVICE_URL = 'https://upload.mabl.com';
|
package/env/dev.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
3
|
+
exports.UPLOAD_SERVICE_URL = exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
4
4
|
exports.BASE_API_URL = 'https://api-dev.mabl.com';
|
|
5
5
|
exports.BASE_APP_URL = 'https://app-dev.mabl.com';
|
|
6
6
|
exports.CONF_FILE_PROJECT_NAME = 'mabl-cli-dev';
|
|
@@ -15,3 +15,4 @@ exports.OKTA_URL = 'https://auth2-dev.mabl.com';
|
|
|
15
15
|
exports.SCRIPT_NAME = 'mabl-dev';
|
|
16
16
|
exports.ELECTRON_PROTOCOL = 'mabl-app-dev';
|
|
17
17
|
exports.FIND_OVERRIDE_PATH = undefined;
|
|
18
|
+
exports.UPLOAD_SERVICE_URL = 'https://upload-dev.mabl.com';
|
package/env/env.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.setConfigFileProjectName = exports.setGlobalConfigEnv = exports.EnvOption = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.FIND_OVERRIDE_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
26
|
+
exports.setConfigFileProjectName = exports.setGlobalConfigEnv = exports.EnvOption = exports.UPLOAD_SERVICE_URL = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.FIND_OVERRIDE_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
27
27
|
const localEnv = __importStar(require("./local"));
|
|
28
28
|
const devEnv = __importStar(require("./dev"));
|
|
29
29
|
const prodEnv = __importStar(require("./prod"));
|
|
@@ -42,6 +42,7 @@ exports.OKTA_CLIENT_ID = defaultEnv.OKTA_CLIENT_ID;
|
|
|
42
42
|
exports.OKTA_URL = defaultEnv.OKTA_URL;
|
|
43
43
|
exports.SCRIPT_NAME = defaultEnv.SCRIPT_NAME;
|
|
44
44
|
exports.ELECTRON_PROTOCOL = defaultEnv.ELECTRON_PROTOCOL;
|
|
45
|
+
exports.UPLOAD_SERVICE_URL = defaultEnv.UPLOAD_SERVICE_URL;
|
|
45
46
|
var EnvOption;
|
|
46
47
|
(function (EnvOption) {
|
|
47
48
|
EnvOption["dev"] = "dev";
|
|
@@ -68,6 +69,7 @@ function setGlobalConfigEnv(env) {
|
|
|
68
69
|
exports.SCRIPT_NAME = envMap[env].SCRIPT_NAME;
|
|
69
70
|
exports.ELECTRON_PROTOCOL = envMap[env].ELECTRON_PROTOCOL;
|
|
70
71
|
exports.FIND_OVERRIDE_PATH = envMap[env].FIND_OVERRIDE_PATH;
|
|
72
|
+
exports.UPLOAD_SERVICE_URL = envMap[env].UPLOAD_SERVICE_URL;
|
|
71
73
|
}
|
|
72
74
|
exports.setGlobalConfigEnv = setGlobalConfigEnv;
|
|
73
75
|
function setConfigFileProjectName(projectName) {
|
package/env/local.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
3
|
+
exports.UPLOAD_SERVICE_URL = exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
4
4
|
exports.BASE_API_URL = 'http://localhost:8080';
|
|
5
5
|
exports.BASE_APP_URL = 'https://app-local.mabl.com:3000';
|
|
6
6
|
exports.CONF_FILE_PROJECT_NAME = 'mabl-cli-local';
|
|
@@ -15,3 +15,4 @@ exports.OKTA_URL = 'https://auth2-dev.mabl.com';
|
|
|
15
15
|
exports.SCRIPT_NAME = 'mabl-local';
|
|
16
16
|
exports.ELECTRON_PROTOCOL = 'mabl-app-local';
|
|
17
17
|
exports.FIND_OVERRIDE_PATH = undefined;
|
|
18
|
+
exports.UPLOAD_SERVICE_URL = 'https://upload-dev.mabl.com';
|
package/env/prod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
3
|
+
exports.UPLOAD_SERVICE_URL = exports.FIND_OVERRIDE_PATH = exports.ELECTRON_PROTOCOL = exports.SCRIPT_NAME = exports.OKTA_URL = exports.OKTA_CLIENT_ID = exports.LOCAL_TRAINER_PATH = exports.EXTENSION_ID = exports.ENV = exports.DEBUG_EVENT_EMITTER = exports.CONSOLE_LOGGING_LEVEL = exports.CONF_FILE_VERSION = exports.CONF_FILE_PROJECT_NAME = exports.BASE_APP_URL = exports.BASE_API_URL = void 0;
|
|
4
4
|
exports.BASE_API_URL = 'https://api.mabl.com';
|
|
5
5
|
exports.BASE_APP_URL = 'https://app.mabl.com';
|
|
6
6
|
exports.CONF_FILE_PROJECT_NAME = 'mabl-cli';
|
|
@@ -15,3 +15,4 @@ exports.OKTA_URL = 'https://auth2.mabl.com';
|
|
|
15
15
|
exports.SCRIPT_NAME = 'mabl';
|
|
16
16
|
exports.ELECTRON_PROTOCOL = 'mabl-app';
|
|
17
17
|
exports.FIND_OVERRIDE_PATH = undefined;
|
|
18
|
+
exports.UPLOAD_SERVICE_URL = 'https://upload.mabl.com';
|