@sentry/wizard
Version:
Sentry wizard helping you to configure your project
74 lines • 3.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenSentry = void 0;
const node_url_1 = require("node:url");
const Constants_1 = require("../Constants");
const BottomBar_1 = require("../Helper/BottomBar");
const Logging_1 = require("../Helper/Logging");
const Wizard_1 = require("../Helper/Wizard");
const BaseStep_1 = require("./BaseStep");
const opn_1 = __importDefault(require("opn"));
class OpenSentry extends BaseStep_1.BaseStep {
async emit(answers) {
if (!(await (0, Wizard_1.getCurrentIntegration)(answers).shouldEmit(answers))) {
(0, Logging_1.dim)('Skipping connection to Sentry due files already patched');
return {};
}
if (this._argv.skipConnect) {
(0, Logging_1.dim)('Skipping connection to Sentry');
return {};
}
const baseUrl = this._argv.url;
BottomBar_1.BottomBar.show('Loading wizard...');
this.debug(`Loading wizard for ${baseUrl}`);
try {
const response = await fetch(`${baseUrl}api/0/wizard/`);
if (!response.ok) {
throw new Error(`Failed to connect to Sentry: ${response.status} ${response.statusText}`);
}
const data = (await response.json());
BottomBar_1.BottomBar.hide();
const urlObj = new node_url_1.URL(`${baseUrl}account/settings/wizard/${data.hash}/`);
if (this._argv.signup) {
urlObj.searchParams.set('signup', '1');
// integration maps to platform in the wizard
if (this._argv.integration) {
const platform = (0, Constants_1.mapIntegrationToPlatform)(this._argv.integration);
if (platform) {
urlObj.searchParams.set('project_platform', platform);
}
}
if (this._argv.promoCode) {
urlObj.searchParams.set('code', this._argv.promoCode);
}
}
if (this._argv.comingFrom) {
// Used to display login/signup instructions when the user is coming from a partner site (e.g. Vercel)
urlObj.searchParams.set('partner', this._argv.comingFrom);
}
const urlToOpen = urlObj.toString();
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
const noop = () => { }; // eslint-disable-line @typescript-eslint/no-empty-function
(0, opn_1.default)(urlToOpen, { wait: false }).then((cp) => cp.on('error', noop), noop);
(0, Logging_1.nl)();
(0, Logging_1.l)('Please open');
(0, Logging_1.green)(urlToOpen);
(0, Logging_1.l)("in your browser (if it's not open already)");
(0, Logging_1.nl)();
return { hash: data.hash };
}
catch (e) {
this._argv.skipConnect = true;
BottomBar_1.BottomBar.hide();
(0, Logging_1.nl)();
(0, Logging_1.red)(`Wizard couldn't connect to ${baseUrl}\nmake sure the url is correct`);
(0, Logging_1.l)('But no worries, we fall back to asking you stuff instead, so here we go:');
return {};
}
}
}
exports.OpenSentry = OpenSentry;
//# sourceMappingURL=OpenSentry.js.map