UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

92 lines (91 loc) 5.33 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const apis_1 = require("../../../util/apis"); const commandline_1 = require("../../../util/commandline"); const util_1 = require("util"); const azure_blob_upload_helper_1 = require("./azure-blob-upload-helper"); // eventually we may want to support AndroidProGuard or UWP here var SymbolType; (function (SymbolType) { SymbolType["Apple"] = "Apple"; SymbolType["Breakpad"] = "Breakpad"; })(SymbolType = exports.SymbolType || (exports.SymbolType = {})); class SymbolsUploadingHelper { constructor(client, app, debug) { this.client = client; this.app = app; this.debug = debug; } uploadSymbolsZip(zip, symbolType) { return __awaiter(this, void 0, void 0, function* () { // executing API request to get an upload URL const uploadingBeginRequestResult = yield this.executeSymbolsUploadingBeginRequest(this.client, this.app, symbolType); // uploading const symbolUploadId = uploadingBeginRequestResult.symbolUploadId; try { // putting ZIP to the specified URL const uploadUrl = uploadingBeginRequestResult.uploadUrl; yield new azure_blob_upload_helper_1.default(this.debug).upload(uploadUrl, zip); // sending 'committed' API request to finish uploading yield this.executeSymbolsUploadingEndRequest(this.client, this.app, symbolUploadId, "committed"); } catch (error) { // uploading failed, aborting upload request yield this.abortUploadingRequest(this.client, this.app, symbolUploadId); throw error; } }); } executeSymbolsUploadingBeginRequest(client, app, symbolType) { return __awaiter(this, void 0, void 0, function* () { this.debug("Executing API request to get uploading URL"); const uploadingBeginResponse = yield apis_1.clientRequest((cb) => client.symbolUploads.create({ symbolType }, app.ownerName, app.appName, cb)).catch((error) => { this.debug(`Failed to start the symbol uploading - ${util_1.inspect(error)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, "failed to start the symbol uploading"); }); this.debug("Analyzing upload start request response status code"); const uploadingBeginStatusCode = uploadingBeginResponse.response.statusCode; const uploadingBeginStatusMessage = uploadingBeginResponse.response.statusMessage; if (uploadingBeginStatusCode >= 400) { throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `the symbol upload begin API request was rejected: HTTP ${uploadingBeginStatusCode} - ${uploadingBeginStatusMessage}`); } return uploadingBeginResponse.result; }); } executeSymbolsUploadingEndRequest(client, app, symbolUploadId, desiredStatus) { return __awaiter(this, void 0, void 0, function* () { this.debug(`Finishing symbols uploading with desired status: ${desiredStatus}`); const uploadingEndResponse = yield apis_1.clientRequest((cb) => client.symbolUploads.complete(symbolUploadId, app.ownerName, app.appName, desiredStatus, cb)).catch((error) => { this.debug(`Failed to finalize the symbol upload - ${util_1.inspect(error)}`); throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to finalize the symbol upload with status`); }); this.debug("Analyzing upload end request response status code"); const uploadingEndStatusCode = uploadingEndResponse.response.statusCode; const uploadingEndStatusMessage = uploadingEndResponse.response.statusMessage; if (uploadingEndStatusCode >= 400) { throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `the symbol upload end API request was rejected: HTTP ${uploadingEndStatusCode} - ${uploadingEndStatusMessage}`); } return uploadingEndResponse.result; }); } abortUploadingRequest(client, app, symbolUploadId) { return __awaiter(this, void 0, void 0, function* () { this.debug("Uploading failed, aborting upload request"); try { return yield this.executeSymbolsUploadingEndRequest(client, app, symbolUploadId, "aborted"); } catch (ex) { this.debug("Failed to correctly abort the uploading request"); } }); } } exports.default = SymbolsUploadingHelper;