@sentry/wizard
Version:
Sentry wizard helping you to configure your project
50 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitForSentry = void 0;
const BottomBar_1 = require("../Helper/BottomBar");
const Wizard_1 = require("../Helper/Wizard");
const BaseStep_1 = require("./BaseStep");
class WaitForSentry extends BaseStep_1.BaseStep {
async emit(answers) {
if (!(await (0, Wizard_1.getCurrentIntegration)(answers).shouldEmit(answers))) {
return {};
}
if (this._argv.skipConnect) {
return {};
}
if (!answers.hash) {
throw new Error('No wizard hash found.');
}
return new Promise((resolve, _reject) => {
this.debug(answers);
BottomBar_1.BottomBar.show('Waiting for Sentry...');
const baseUrl = this._argv.url;
const pingSentry = async () => {
const response = await fetch(`${baseUrl}api/0/wizard/${answers.hash ? answers.hash + '/' : ''}`);
this.debug('Polling received data');
if (!response.ok) {
throw new Error(`Received status ${response.status} ${response.statusText}`);
}
const data = await response.json();
// Delete the wizard hash since we were able to fetch the data
await fetch(`${baseUrl}api/0/wizard/${answers.hash ? answers.hash + '/' : ''}`, {
method: 'DELETE',
});
BottomBar_1.BottomBar.hide();
this.debug('Polling Success!');
resolve({ wizard: data });
};
const poll = () => {
this.debug(`Polling: ${baseUrl}api/0/wizard/${answers.hash ? answers.hash + '/' : ''}`);
pingSentry().catch((e) => {
this.debug('Polling received:');
this.debug(e);
setTimeout(poll, 1000);
});
};
poll();
});
}
}
exports.WaitForSentry = WaitForSentry;
//# sourceMappingURL=WaitForSentry.js.map