145 lines
19 KiB
JavaScript
145 lines
19 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const prompts_1 = __importDefault(require("prompts"));
|
|
const chalk_1 = __importDefault(require("chalk"));
|
|
const connector_1 = __importDefault(require("./connector"));
|
|
const email_validator_1 = __importDefault(require("email-validator"));
|
|
const messages_1 = __importDefault(require("./messages"));
|
|
const get_default_project_link_1 = __importDefault(require("./get-default-project-link"));
|
|
const config_storage_1 = __importDefault(require("../dashboard/config-storage"));
|
|
const formatting_1 = require("./formatting");
|
|
const documentation_url_1 = __importDefault(require("./documentation-url"));
|
|
const dashboardConnector = new connector_1.default();
|
|
const dashboardConfigStorage = new config_storage_1.default();
|
|
async function registerInDashboard() {
|
|
(0, formatting_1.info)(messages_1.default.REGISTRATION_ENTER_EMAIL_INVITATION);
|
|
const { email } = await (0, prompts_1.default)({
|
|
type: 'text',
|
|
name: 'email',
|
|
message: messages_1.default.PROMPT_EMAIL_CAPTION,
|
|
validate: (input) => {
|
|
if (!email_validator_1.default.validate(input))
|
|
return messages_1.default.PROMPT_INVALID_EMAIL;
|
|
return true;
|
|
},
|
|
});
|
|
if (!email) {
|
|
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
|
|
return;
|
|
}
|
|
const sendEmailResult = await dashboardConnector.sendEmail(email);
|
|
if (!sendEmailResult.success) {
|
|
const sendEmailErrorMessage = sendEmailResult.isDashboardError
|
|
? sendEmailResult.errorMessage
|
|
: messages_1.default.REGISTRATION_EMAIL_SENDING_NETWORK_ERROR;
|
|
(0, formatting_1.error)(sendEmailErrorMessage);
|
|
return;
|
|
}
|
|
(0, formatting_1.info)(messages_1.default.REGISTRATION_EMAIL_SENT);
|
|
const { token } = await (0, prompts_1.default)({
|
|
type: 'text',
|
|
name: 'token',
|
|
message: messages_1.default.PROMPT_TOKEN_CAPTION,
|
|
});
|
|
if (!token) {
|
|
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
|
|
return;
|
|
}
|
|
const validationResult = await dashboardConnector.validateToken(token);
|
|
if (!validationResult.success) {
|
|
const validationResultErrorMessage = validationResult.isDashboardError
|
|
? validationResult.errorMessage
|
|
: messages_1.default.TOKEN_VALIDATION_NETWORK_ERROR;
|
|
(0, formatting_1.error)(validationResultErrorMessage);
|
|
return;
|
|
}
|
|
dashboardConfigStorage.options.sendReport = true;
|
|
await saveNewToken(token);
|
|
(0, formatting_1.success)(messages_1.default.REGISTRATION_FINISHED);
|
|
(0, formatting_1.info)('View test results at:\n' +
|
|
`${chalk_1.default.underline.blueBright((0, get_default_project_link_1.default)(token))}`);
|
|
(0, formatting_1.info)(`Run ${chalk_1.default.black.bgWhiteBright('testcafe dashboard off')} to disable this behavior.` +
|
|
`Learn more at:\n${chalk_1.default.underline.blueBright(documentation_url_1.default)}`);
|
|
}
|
|
async function saveNewToken(token) {
|
|
dashboardConfigStorage.options.token = token;
|
|
await dashboardConfigStorage.save();
|
|
}
|
|
async function updateDefaultToken() {
|
|
if (!dashboardConfigStorage.options.sendReport)
|
|
(0, formatting_1.warning)(messages_1.default.TOKEN_UPDATING_NOT_SEND_REPORT);
|
|
// NOTE: for the formatting reason
|
|
(0, formatting_1.info)('');
|
|
const { doYouWantToUpdateDefaultToken } = await (0, prompts_1.default)({
|
|
type: 'confirm',
|
|
name: 'doYouWantToUpdateDefaultToken',
|
|
message: 'Your setup includes a default Dashboard token. Do you want to change it?:',
|
|
});
|
|
if (!doYouWantToUpdateDefaultToken) {
|
|
(0, formatting_1.error)(messages_1.default.TOKEN_UPDATE_CANCELLED);
|
|
return;
|
|
}
|
|
// NOTE: for the formatting reason
|
|
(0, formatting_1.info)('');
|
|
const { newToken } = await (0, prompts_1.default)({
|
|
type: 'text',
|
|
name: 'newToken',
|
|
message: 'Enter the new default token value:',
|
|
});
|
|
if (!newToken) {
|
|
(0, formatting_1.error)(messages_1.default.TOKEN_UPDATE_CANCELLED);
|
|
return;
|
|
}
|
|
const validationResult = await dashboardConnector.validateToken(newToken);
|
|
if (!validationResult.success) {
|
|
const validationResultErrorMessage = validationResult.isDashboardError
|
|
? validationResult.errorMessage
|
|
: messages_1.default.TOKEN_VALIDATION_NETWORK_ERROR;
|
|
(0, formatting_1.error)(validationResultErrorMessage);
|
|
return;
|
|
}
|
|
await saveNewToken(newToken);
|
|
(0, formatting_1.success)(messages_1.default.TOKEN_UPDATED);
|
|
}
|
|
async function setSendReportState(state) {
|
|
const sendReportAsBoolean = state === 'on';
|
|
dashboardConfigStorage.options.sendReport = sendReportAsBoolean;
|
|
await dashboardConfigStorage.save();
|
|
const resultMessage = sendReportAsBoolean ? messages_1.default.SEND_REPORT_STATE_ON : messages_1.default.SEND_REPORT_STATE_OFF;
|
|
(0, formatting_1.success)(resultMessage);
|
|
}
|
|
async function tryToRegisterInDashboard() {
|
|
(0, formatting_1.info)(messages_1.default.TOKEN_NO_DEFAULT_FOUND);
|
|
const { launchConfigurationWizard } = await (0, prompts_1.default)({
|
|
type: 'confirm',
|
|
name: 'launchConfigurationWizard',
|
|
message: 'Do you want to launch the configuration wizard?',
|
|
initial: true,
|
|
});
|
|
if (!launchConfigurationWizard) {
|
|
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
|
|
return;
|
|
}
|
|
await registerInDashboard();
|
|
}
|
|
async function default_1(sendReportState) {
|
|
const storageExists = await dashboardConfigStorage.load();
|
|
if (sendReportState !== void 0) {
|
|
if (storageExists)
|
|
await setSendReportState(sendReportState);
|
|
else
|
|
await tryToRegisterInDashboard();
|
|
return;
|
|
}
|
|
const thereIsDefaultToken = !!dashboardConfigStorage.options.token;
|
|
if (thereIsDefaultToken)
|
|
await updateDefaultToken();
|
|
else
|
|
await registerInDashboard();
|
|
}
|
|
exports.default = default_1;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJ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