1 | "use strict";
|
2 | var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
3 | if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
4 | return cooked;
|
5 | };
|
6 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
7 | if (k2 === undefined) k2 = k;
|
8 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
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 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27 | return new (P || (P = Promise))(function (resolve, reject) {
|
28 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32 | });
|
33 | };
|
34 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
35 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
36 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
37 | function verb(n) { return function (v) { return step([n, v]); }; }
|
38 | function step(op) {
|
39 | if (f) throw new TypeError("Generator is already executing.");
|
40 | while (_) try {
|
41 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
42 | if (y = 0, t) op = [op[0] & 2, t.value];
|
43 | switch (op[0]) {
|
44 | case 0: case 1: t = op; break;
|
45 | case 4: _.label++; return { value: op[1], done: false };
|
46 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
47 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
48 | default:
|
49 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
50 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
51 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
52 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
53 | if (t[2]) _.ops.pop();
|
54 | _.trys.pop(); continue;
|
55 | }
|
56 | op = body.call(thisArg, _);
|
57 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
58 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
59 | }
|
60 | };
|
61 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
62 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
63 | };
|
64 | var fs = __importStar(require("fs"));
|
65 | var path = __importStar(require("path"));
|
66 | var slash = require("slash");
|
67 | var recursiveFs = __importStar(require("recursive-fs"));
|
68 | var yazl = __importStar(require("yazl"));
|
69 | var adapter_1 = __importDefault(require("../utils/adapter/adapter"));
|
70 | var request_manager_1 = __importDefault(require("../utils/request-manager"));
|
71 | var code_push_error_1 = require("./code-push-error");
|
72 | var appcenter_file_upload_client_1 = __importDefault(require("appcenter-file-upload-client"));
|
73 |
|
74 | function urlEncode(strings) {
|
75 | var values = [];
|
76 | for (var _i = 1; _i < arguments.length; _i++) {
|
77 | values[_i - 1] = arguments[_i];
|
78 | }
|
79 | var result = "";
|
80 | for (var i = 0; i < strings.length; i++) {
|
81 | result += strings[i];
|
82 | if (i < values.length) {
|
83 | result += encodeURIComponent(values[i]);
|
84 | }
|
85 | }
|
86 | return result;
|
87 | }
|
88 | var AccountManager = (function () {
|
89 | function AccountManager(accessKey, customHeaders, serverUrl, proxy) {
|
90 | if (!accessKey)
|
91 | throw new code_push_error_1.CodePushUnauthorizedError("A token must be specified.");
|
92 | this._accessKey = accessKey;
|
93 | this._requestManager = new request_manager_1.default(accessKey, customHeaders, serverUrl, proxy);
|
94 | this._adapter = new adapter_1.default(this._requestManager);
|
95 | this._fileUploadClient = new appcenter_file_upload_client_1.default();
|
96 | }
|
97 | Object.defineProperty(AccountManager.prototype, "accessKey", {
|
98 | get: function () {
|
99 | return this._accessKey;
|
100 | },
|
101 | enumerable: false,
|
102 | configurable: true
|
103 | });
|
104 | AccountManager.prototype.isAuthenticated = function (throwIfUnauthorized) {
|
105 | return __awaiter(this, void 0, void 0, function () {
|
106 | var res, codePushError, error_1, authenticated;
|
107 | return __generator(this, function (_a) {
|
108 | switch (_a.label) {
|
109 | case 0:
|
110 | _a.trys.push([0, 2, , 3]);
|
111 | return [4 , this._requestManager.get(urlEncode(templateObject_1 || (templateObject_1 = __makeTemplateObject(["/user"], ["/user"]))), false)];
|
112 | case 1:
|
113 | res = _a.sent();
|
114 | return [3 , 3];
|
115 | case 2:
|
116 | error_1 = _a.sent();
|
117 | codePushError = error_1;
|
118 | if (codePushError && (codePushError.statusCode !== request_manager_1.default.ERROR_UNAUTHORIZED || throwIfUnauthorized)) {
|
119 | throw codePushError;
|
120 | }
|
121 | return [3 , 3];
|
122 | case 3:
|
123 | authenticated = !!res && !!res.body;
|
124 | return [2 , authenticated];
|
125 | }
|
126 | });
|
127 | });
|
128 | };
|
129 |
|
130 | AccountManager.prototype.addAccessKey = function (friendlyName, ttl) {
|
131 | return __awaiter(this, void 0, void 0, function () {
|
132 | var accessKeyRequest, res, accessKey;
|
133 | return __generator(this, function (_a) {
|
134 | switch (_a.label) {
|
135 | case 0:
|
136 | if (!friendlyName) {
|
137 | throw new code_push_error_1.CodePushUnauthorizedError("A name must be specified when adding an access key.");
|
138 | }
|
139 | accessKeyRequest = {
|
140 | description: friendlyName
|
141 | };
|
142 | return [4 , this._requestManager.post(urlEncode(templateObject_2 || (templateObject_2 = __makeTemplateObject(["/api_tokens"], ["/api_tokens"]))), JSON.stringify(accessKeyRequest), true)];
|
143 | case 1:
|
144 | res = _a.sent();
|
145 | accessKey = this._adapter.toLegacyAccessKey(res.body);
|
146 | return [2 , accessKey];
|
147 | }
|
148 | });
|
149 | });
|
150 | };
|
151 | AccountManager.prototype.getAccessKeys = function () {
|
152 | return __awaiter(this, void 0, void 0, function () {
|
153 | var res, accessKeys;
|
154 | return __generator(this, function (_a) {
|
155 | switch (_a.label) {
|
156 | case 0: return [4 , this._requestManager.get(urlEncode(templateObject_3 || (templateObject_3 = __makeTemplateObject(["/api_tokens"], ["/api_tokens"]))))];
|
157 | case 1:
|
158 | res = _a.sent();
|
159 | accessKeys = this._adapter.toLegacyAccessKeyList(res.body);
|
160 | return [2 , accessKeys];
|
161 | }
|
162 | });
|
163 | });
|
164 | };
|
165 | AccountManager.prototype.removeAccessKey = function (name) {
|
166 | return __awaiter(this, void 0, void 0, function () {
|
167 | var accessKey;
|
168 | return __generator(this, function (_a) {
|
169 | switch (_a.label) {
|
170 | case 0: return [4 , this._adapter.resolveAccessKey(name)];
|
171 | case 1:
|
172 | accessKey = _a.sent();
|
173 | return [4 , this._requestManager.del(urlEncode(templateObject_4 || (templateObject_4 = __makeTemplateObject(["/api_tokens/", ""], ["/api_tokens/", ""])), accessKey.id))];
|
174 | case 2:
|
175 | _a.sent();
|
176 | return [2 , null];
|
177 | }
|
178 | });
|
179 | });
|
180 | };
|
181 |
|
182 | AccountManager.prototype.getAccountInfo = function () {
|
183 | return __awaiter(this, void 0, void 0, function () {
|
184 | var res, accountInfo;
|
185 | return __generator(this, function (_a) {
|
186 | switch (_a.label) {
|
187 | case 0: return [4 , this._requestManager.get(urlEncode(templateObject_5 || (templateObject_5 = __makeTemplateObject(["/user"], ["/user"]))))];
|
188 | case 1:
|
189 | res = _a.sent();
|
190 | accountInfo = this._adapter.toLegacyAccount(res.body);
|
191 | return [2 , accountInfo];
|
192 | }
|
193 | });
|
194 | });
|
195 | };
|
196 |
|
197 | AccountManager.prototype.getApps = function () {
|
198 | return __awaiter(this, void 0, void 0, function () {
|
199 | var res, apps;
|
200 | return __generator(this, function (_a) {
|
201 | switch (_a.label) {
|
202 | case 0: return [4 , this._requestManager.get(urlEncode(templateObject_6 || (templateObject_6 = __makeTemplateObject(["/apps"], ["/apps"]))))];
|
203 | case 1:
|
204 | res = _a.sent();
|
205 | return [4 , this._adapter.toLegacyApps(res.body)];
|
206 | case 2:
|
207 | apps = _a.sent();
|
208 | return [2 , apps];
|
209 | }
|
210 | });
|
211 | });
|
212 | };
|
213 | AccountManager.prototype.getApp = function (appName) {
|
214 | return __awaiter(this, void 0, void 0, function () {
|
215 | var appParams, res, app;
|
216 | return __generator(this, function (_a) {
|
217 | switch (_a.label) {
|
218 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
219 | case 1:
|
220 | appParams = _a.sent();
|
221 | return [4 , this._requestManager.get(urlEncode(templateObject_7 || (templateObject_7 = __makeTemplateObject(["/apps/", "/", ""], ["/apps/", "/", ""])), appParams.appOwner, appParams.appName))];
|
222 | case 2:
|
223 | res = _a.sent();
|
224 | return [4 , this._adapter.toLegacyApp(res.body)];
|
225 | case 3:
|
226 | app = _a.sent();
|
227 | return [2 , app];
|
228 | }
|
229 | });
|
230 | });
|
231 | };
|
232 | AccountManager.prototype.addApp = function (appName, appOs, appPlatform, manuallyProvisionDeployments) {
|
233 | if (manuallyProvisionDeployments === void 0) { manuallyProvisionDeployments = false; }
|
234 | return __awaiter(this, void 0, void 0, function () {
|
235 | var app, apigatewayAppCreationRequest, path;
|
236 | return __generator(this, function (_a) {
|
237 | switch (_a.label) {
|
238 | case 0:
|
239 | app = {
|
240 | name: appName,
|
241 | os: appOs,
|
242 | platform: appPlatform,
|
243 | manuallyProvisionDeployments: manuallyProvisionDeployments
|
244 | };
|
245 | apigatewayAppCreationRequest = this._adapter.toApigatewayAppCreationRequest(app);
|
246 | path = apigatewayAppCreationRequest.org ? "/orgs/" + apigatewayAppCreationRequest.org + "/apps" : "/apps";
|
247 | return [4 , this._requestManager.post(path, JSON.stringify(apigatewayAppCreationRequest.appcenterClientApp), false)];
|
248 | case 1:
|
249 | _a.sent();
|
250 | if (!!manuallyProvisionDeployments) return [3 , 3];
|
251 | return [4 , this._adapter.addStandardDeployments(appName)];
|
252 | case 2:
|
253 | _a.sent();
|
254 | _a.label = 3;
|
255 | case 3: return [2 , app];
|
256 | }
|
257 | });
|
258 | });
|
259 | };
|
260 | AccountManager.prototype.removeApp = function (appName) {
|
261 | return __awaiter(this, void 0, void 0, function () {
|
262 | var appParams;
|
263 | return __generator(this, function (_a) {
|
264 | switch (_a.label) {
|
265 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
266 | case 1:
|
267 | appParams = _a.sent();
|
268 | return [4 , this._requestManager.del(urlEncode(templateObject_8 || (templateObject_8 = __makeTemplateObject(["/apps/", "/", ""], ["/apps/", "/", ""])), appParams.appOwner, appParams.appName))];
|
269 | case 2:
|
270 | _a.sent();
|
271 | return [2 , null];
|
272 | }
|
273 | });
|
274 | });
|
275 | };
|
276 | AccountManager.prototype.renameApp = function (oldAppName, newAppName) {
|
277 | return __awaiter(this, void 0, void 0, function () {
|
278 | var _a, appOwner, appName, updatedApp;
|
279 | return __generator(this, function (_b) {
|
280 | switch (_b.label) {
|
281 | case 0: return [4 , this._adapter.parseApiAppName(oldAppName)];
|
282 | case 1:
|
283 | _a = _b.sent(), appOwner = _a.appOwner, appName = _a.appName;
|
284 | return [4 , this._adapter.getRenamedApp(newAppName, appOwner, appName)];
|
285 | case 2:
|
286 | updatedApp = _b.sent();
|
287 | return [4 , this._requestManager.patch(urlEncode(templateObject_9 || (templateObject_9 = __makeTemplateObject(["/apps/", "/", ""], ["/apps/", "/", ""])), appOwner, appName), JSON.stringify(updatedApp))];
|
288 | case 3:
|
289 | _b.sent();
|
290 | return [2 , null];
|
291 | }
|
292 | });
|
293 | });
|
294 | };
|
295 | AccountManager.prototype.transferApp = function (appName, orgName) {
|
296 | return __awaiter(this, void 0, void 0, function () {
|
297 | var appParams;
|
298 | return __generator(this, function (_a) {
|
299 | switch (_a.label) {
|
300 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
301 | case 1:
|
302 | appParams = _a.sent();
|
303 | return [4 , this._requestManager.post(urlEncode(templateObject_10 || (templateObject_10 = __makeTemplateObject(["/apps/", "/", "/transfer/", ""], ["/apps/", "/", "/transfer/", ""])), appParams.appOwner, appParams.appName, orgName), null, false)];
|
304 | case 2:
|
305 | _a.sent();
|
306 | return [2 , null];
|
307 | }
|
308 | });
|
309 | });
|
310 | };
|
311 |
|
312 | AccountManager.prototype.getCollaborators = function (appName) {
|
313 | return __awaiter(this, void 0, void 0, function () {
|
314 | var appParams, res, collaborators;
|
315 | return __generator(this, function (_a) {
|
316 | switch (_a.label) {
|
317 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
318 | case 1:
|
319 | appParams = _a.sent();
|
320 | return [4 , this._requestManager.get(urlEncode(templateObject_11 || (templateObject_11 = __makeTemplateObject(["/apps/", "/", "/users"], ["/apps/", "/", "/users"])), appParams.appOwner, appParams.appName))];
|
321 | case 2:
|
322 | res = _a.sent();
|
323 | return [4 , this._adapter.toLegacyCollaborators(res.body, appParams.appOwner)];
|
324 | case 3:
|
325 | collaborators = _a.sent();
|
326 | return [2 , collaborators];
|
327 | }
|
328 | });
|
329 | });
|
330 | };
|
331 | AccountManager.prototype.addCollaborator = function (appName, email) {
|
332 | return __awaiter(this, void 0, void 0, function () {
|
333 | var appParams, userEmailRequest;
|
334 | return __generator(this, function (_a) {
|
335 | switch (_a.label) {
|
336 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
337 | case 1:
|
338 | appParams = _a.sent();
|
339 | userEmailRequest = {
|
340 | user_email: email
|
341 | };
|
342 | return [4 , this._requestManager.post(urlEncode(templateObject_12 || (templateObject_12 = __makeTemplateObject(["/apps/", "/", "/invitations"], ["/apps/", "/", "/invitations"])), appParams.appOwner, appParams.appName), JSON.stringify(userEmailRequest), false)];
|
343 | case 2:
|
344 | _a.sent();
|
345 | return [2 , null];
|
346 | }
|
347 | });
|
348 | });
|
349 | };
|
350 | AccountManager.prototype.removeCollaborator = function (appName, email) {
|
351 | return __awaiter(this, void 0, void 0, function () {
|
352 | var appParams;
|
353 | return __generator(this, function (_a) {
|
354 | switch (_a.label) {
|
355 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
356 | case 1:
|
357 | appParams = _a.sent();
|
358 | return [4 , this._requestManager.del(urlEncode(templateObject_13 || (templateObject_13 = __makeTemplateObject(["/apps/", "/", "/invitations/", ""], ["/apps/", "/", "/invitations/", ""])), appParams.appOwner, appParams.appName, email))];
|
359 | case 2:
|
360 | _a.sent();
|
361 | return [2 , null];
|
362 | }
|
363 | });
|
364 | });
|
365 | };
|
366 |
|
367 | AccountManager.prototype.addDeployment = function (appName, deploymentName) {
|
368 | return __awaiter(this, void 0, void 0, function () {
|
369 | var deployment, appParams, res;
|
370 | return __generator(this, function (_a) {
|
371 | switch (_a.label) {
|
372 | case 0:
|
373 | deployment = { name: deploymentName };
|
374 | return [4 , this._adapter.parseApiAppName(appName)];
|
375 | case 1:
|
376 | appParams = _a.sent();
|
377 | return [4 , this._requestManager.post(urlEncode(templateObject_14 || (templateObject_14 = __makeTemplateObject(["/apps/", "/", "/deployments/"], ["/apps/", "/", "/deployments/"])), appParams.appOwner, appParams.appName), JSON.stringify(deployment), true)];
|
378 | case 2:
|
379 | res = _a.sent();
|
380 | return [2 , this._adapter.toLegacyDeployment(res.body)];
|
381 | }
|
382 | });
|
383 | });
|
384 | };
|
385 | AccountManager.prototype.clearDeploymentHistory = function (appName, deploymentName) {
|
386 | return __awaiter(this, void 0, void 0, function () {
|
387 | var appParams;
|
388 | return __generator(this, function (_a) {
|
389 | switch (_a.label) {
|
390 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
391 | case 1:
|
392 | appParams = _a.sent();
|
393 | return [4 , this._requestManager.del(urlEncode(templateObject_15 || (templateObject_15 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/releases"], ["/apps/", "/", "/deployments/", "/releases"])), appParams.appOwner, appParams.appName, deploymentName))];
|
394 | case 2:
|
395 | _a.sent();
|
396 | return [2 , null];
|
397 | }
|
398 | });
|
399 | });
|
400 | };
|
401 | AccountManager.prototype.getDeployments = function (appName) {
|
402 | return __awaiter(this, void 0, void 0, function () {
|
403 | var appParams, res;
|
404 | return __generator(this, function (_a) {
|
405 | switch (_a.label) {
|
406 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
407 | case 1:
|
408 | appParams = _a.sent();
|
409 | return [4 , this._requestManager.get(urlEncode(templateObject_16 || (templateObject_16 = __makeTemplateObject(["/apps/", "/", "/deployments/"], ["/apps/", "/", "/deployments/"])), appParams.appOwner, appParams.appName))];
|
410 | case 2:
|
411 | res = _a.sent();
|
412 | return [2 , this._adapter.toLegacyDeployments(res.body)];
|
413 | }
|
414 | });
|
415 | });
|
416 | };
|
417 | AccountManager.prototype.getDeployment = function (appName, deploymentName) {
|
418 | return __awaiter(this, void 0, void 0, function () {
|
419 | var appParams, res;
|
420 | return __generator(this, function (_a) {
|
421 | switch (_a.label) {
|
422 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
423 | case 1:
|
424 | appParams = _a.sent();
|
425 | return [4 , this._requestManager.get(urlEncode(templateObject_17 || (templateObject_17 = __makeTemplateObject(["/apps/", "/", "/deployments/", ""], ["/apps/", "/", "/deployments/", ""])), appParams.appOwner, appParams.appName, deploymentName))];
|
426 | case 2:
|
427 | res = _a.sent();
|
428 | return [2 , this._adapter.toLegacyDeployment(res.body)];
|
429 | }
|
430 | });
|
431 | });
|
432 | };
|
433 | AccountManager.prototype.renameDeployment = function (appName, oldDeploymentName, newDeploymentName) {
|
434 | return __awaiter(this, void 0, void 0, function () {
|
435 | var appParams;
|
436 | return __generator(this, function (_a) {
|
437 | switch (_a.label) {
|
438 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
439 | case 1:
|
440 | appParams = _a.sent();
|
441 | return [4 , this._requestManager.patch(urlEncode(templateObject_18 || (templateObject_18 = __makeTemplateObject(["/apps/", "/", "/deployments/", ""], ["/apps/", "/", "/deployments/", ""])), appParams.appOwner, appParams.appName, oldDeploymentName), JSON.stringify({ name: newDeploymentName }))];
|
442 | case 2:
|
443 | _a.sent();
|
444 | return [2 , null];
|
445 | }
|
446 | });
|
447 | });
|
448 | };
|
449 | AccountManager.prototype.removeDeployment = function (appName, deploymentName) {
|
450 | return __awaiter(this, void 0, void 0, function () {
|
451 | var appParams;
|
452 | return __generator(this, function (_a) {
|
453 | switch (_a.label) {
|
454 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
455 | case 1:
|
456 | appParams = _a.sent();
|
457 | return [4 , this._requestManager.del(urlEncode(templateObject_19 || (templateObject_19 = __makeTemplateObject(["/apps/", "/", "/deployments/", ""], ["/apps/", "/", "/deployments/", ""])), appParams.appOwner, appParams.appName, deploymentName))];
|
458 | case 2:
|
459 | _a.sent();
|
460 | return [2 , null];
|
461 | }
|
462 | });
|
463 | });
|
464 | };
|
465 | AccountManager.prototype.getDeploymentMetrics = function (appName, deploymentName) {
|
466 | return __awaiter(this, void 0, void 0, function () {
|
467 | var appParams, res, deploymentMetrics;
|
468 | return __generator(this, function (_a) {
|
469 | switch (_a.label) {
|
470 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
471 | case 1:
|
472 | appParams = _a.sent();
|
473 | return [4 , this._requestManager.get(urlEncode(templateObject_20 || (templateObject_20 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/metrics"], ["/apps/", "/", "/deployments/", "/metrics"])), appParams.appOwner, appParams.appName, deploymentName))];
|
474 | case 2:
|
475 | res = _a.sent();
|
476 | deploymentMetrics = this._adapter.toLegacyDeploymentMetrics(res.body);
|
477 | return [2 , deploymentMetrics];
|
478 | }
|
479 | });
|
480 | });
|
481 | };
|
482 | AccountManager.prototype.getDeploymentHistory = function (appName, deploymentName) {
|
483 | return __awaiter(this, void 0, void 0, function () {
|
484 | var appParams, res;
|
485 | return __generator(this, function (_a) {
|
486 | switch (_a.label) {
|
487 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
488 | case 1:
|
489 | appParams = _a.sent();
|
490 | return [4 , this._requestManager.get(urlEncode(templateObject_21 || (templateObject_21 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/releases"], ["/apps/", "/", "/deployments/", "/releases"])), appParams.appOwner, appParams.appName, deploymentName))];
|
491 | case 2:
|
492 | res = _a.sent();
|
493 | return [2 , this._adapter.toLegacyDeploymentHistory(res.body)];
|
494 | }
|
495 | });
|
496 | });
|
497 | };
|
498 |
|
499 | AccountManager.prototype.release = function (appName, deploymentName, filePath, targetBinaryVersion, updateMetadata, uploadProgressCallback) {
|
500 | return __awaiter(this, void 0, void 0, function () {
|
501 | var packageFile, appParams, assetJsonResponse, assets, releaseUploadProperties, releaseJsonResponse, releasePackage;
|
502 | return __generator(this, function (_a) {
|
503 | switch (_a.label) {
|
504 | case 0:
|
505 | updateMetadata.appVersion = targetBinaryVersion;
|
506 | return [4 , this.packageFileFromPath(filePath)];
|
507 | case 1:
|
508 | packageFile = _a.sent();
|
509 | return [4 , this._adapter.parseApiAppName(appName)];
|
510 | case 2:
|
511 | appParams = _a.sent();
|
512 | return [4 , this._requestManager.post(urlEncode(templateObject_22 || (templateObject_22 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/uploads"], ["/apps/", "/", "/deployments/", "/uploads"])), appParams.appOwner, appParams.appName, deploymentName), null, true)];
|
513 | case 3:
|
514 | assetJsonResponse = _a.sent();
|
515 | assets = assetJsonResponse.body;
|
516 | return [4 , this._fileUploadClient.upload({
|
517 | assetId: assets.id,
|
518 | assetDomain: assets.upload_domain,
|
519 | assetToken: assets.token,
|
520 | file: packageFile.path,
|
521 | onProgressChanged: function (progressData) {
|
522 | if (uploadProgressCallback) {
|
523 | uploadProgressCallback(progressData.percentCompleted);
|
524 | }
|
525 | },
|
526 | })];
|
527 | case 4:
|
528 | _a.sent();
|
529 | releaseUploadProperties = this._adapter.toReleaseUploadProperties(updateMetadata, assets, deploymentName);
|
530 | return [4 , this._requestManager.post(urlEncode(templateObject_23 || (templateObject_23 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/releases"], ["/apps/", "/", "/deployments/", "/releases"])), appParams.appOwner, appParams.appName, deploymentName), JSON.stringify(releaseUploadProperties), true)];
|
531 | case 5:
|
532 | releaseJsonResponse = _a.sent();
|
533 | releasePackage = this._adapter.releaseToPackage(releaseJsonResponse.body);
|
534 | return [2 , releasePackage];
|
535 | }
|
536 | });
|
537 | });
|
538 | };
|
539 | AccountManager.prototype.patchRelease = function (appName, deploymentName, label, updateMetadata) {
|
540 | return __awaiter(this, void 0, void 0, function () {
|
541 | var appParams, requestBody;
|
542 | return __generator(this, function (_a) {
|
543 | switch (_a.label) {
|
544 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
545 | case 1:
|
546 | appParams = _a.sent();
|
547 | requestBody = this._adapter.toRestReleaseModification(updateMetadata);
|
548 | return [4 , this._requestManager.patch(urlEncode(templateObject_24 || (templateObject_24 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/releases/", ""], ["/apps/", "/", "/deployments/", "/releases/", ""])), appParams.appOwner, appParams.appName, deploymentName, label), JSON.stringify(requestBody), false)];
|
549 | case 2:
|
550 | _a.sent();
|
551 | return [2 , null];
|
552 | }
|
553 | });
|
554 | });
|
555 | };
|
556 | AccountManager.prototype.promote = function (appName, sourceDeploymentName, destinationDeploymentName, updateMetadata) {
|
557 | return __awaiter(this, void 0, void 0, function () {
|
558 | var appParams, requestBody, res, releasePackage;
|
559 | return __generator(this, function (_a) {
|
560 | switch (_a.label) {
|
561 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
562 | case 1:
|
563 | appParams = _a.sent();
|
564 | requestBody = this._adapter.toRestReleaseModification(updateMetadata);
|
565 | return [4 , this._requestManager.post(urlEncode(templateObject_25 || (templateObject_25 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/promote_release/", ""], ["/apps/", "/", "/deployments/", "/promote_release/", ""])), appParams.appOwner, appParams.appName, sourceDeploymentName, destinationDeploymentName), JSON.stringify(requestBody), true)];
|
566 | case 2:
|
567 | res = _a.sent();
|
568 | releasePackage = this._adapter.releaseToPackage(res.body);
|
569 | return [2 , releasePackage];
|
570 | }
|
571 | });
|
572 | });
|
573 | };
|
574 | AccountManager.prototype.rollback = function (appName, deploymentName, targetRelease) {
|
575 | return __awaiter(this, void 0, void 0, function () {
|
576 | var appParams, requestBody;
|
577 | return __generator(this, function (_a) {
|
578 | switch (_a.label) {
|
579 | case 0: return [4 , this._adapter.parseApiAppName(appName)];
|
580 | case 1:
|
581 | appParams = _a.sent();
|
582 | requestBody = targetRelease ? {
|
583 | label: targetRelease
|
584 | } : {};
|
585 | return [4 , this._requestManager.post(urlEncode(templateObject_26 || (templateObject_26 = __makeTemplateObject(["/apps/", "/", "/deployments/", "/rollback_release"], ["/apps/", "/", "/deployments/", "/rollback_release"])), appParams.appOwner, appParams.appName, deploymentName), JSON.stringify(requestBody), false)];
|
586 | case 2:
|
587 | _a.sent();
|
588 | return [2 , null];
|
589 | }
|
590 | });
|
591 | });
|
592 | };
|
593 |
|
594 | AccountManager.prototype.getAccessKey = function (accessKeyName) {
|
595 | throw {
|
596 | message: 'Method is deprecated',
|
597 | statusCode: 404
|
598 | };
|
599 | };
|
600 |
|
601 | AccountManager.prototype.getSessions = function () {
|
602 | throw this.getDeprecatedMethodError();
|
603 | };
|
604 |
|
605 | AccountManager.prototype.patchAccessKey = function (oldName, newName, ttl) {
|
606 | throw this.getDeprecatedMethodError();
|
607 | };
|
608 |
|
609 | AccountManager.prototype.removeSession = function (machineName) {
|
610 | throw this.getDeprecatedMethodError();
|
611 | };
|
612 | AccountManager.prototype.packageFileFromPath = function (filePath) {
|
613 | var _this = this;
|
614 | var getPackageFilePromise;
|
615 | if (fs.lstatSync(filePath).isDirectory()) {
|
616 | getPackageFilePromise = new Promise(function (resolve, reject) {
|
617 | var directoryPath = filePath;
|
618 | recursiveFs.readdirr(directoryPath, function (error, directories, files) {
|
619 | if (error) {
|
620 | reject(error);
|
621 | return;
|
622 | }
|
623 | var baseDirectoryPath = path.dirname(directoryPath);
|
624 | var fileName = _this.generateRandomFilename(15) + ".zip";
|
625 | var zipFile = new yazl.ZipFile();
|
626 | var writeStream = fs.createWriteStream(fileName);
|
627 | zipFile.outputStream.pipe(writeStream)
|
628 | .on("error", function (error) {
|
629 | reject(error);
|
630 | })
|
631 | .on("close", function () {
|
632 | filePath = path.join(process.cwd(), fileName);
|
633 | resolve({ isTemporary: true, path: filePath });
|
634 | });
|
635 | for (var i = 0; i < files.length; ++i) {
|
636 | var file = files[i];
|
637 | var relativePath = path.relative(baseDirectoryPath, file);
|
638 |
|
639 | relativePath = slash(relativePath);
|
640 | zipFile.addFile(file, relativePath);
|
641 | }
|
642 | zipFile.end();
|
643 | });
|
644 | });
|
645 | }
|
646 | else {
|
647 | getPackageFilePromise = new Promise(function (resolve, reject) {
|
648 | resolve({ isTemporary: false, path: filePath });
|
649 | });
|
650 | }
|
651 | return getPackageFilePromise;
|
652 | };
|
653 | AccountManager.prototype.generateRandomFilename = function (length) {
|
654 | var filename = "";
|
655 | var validChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
656 | for (var i = 0; i < length; i++) {
|
657 | filename += validChar.charAt(Math.floor(Math.random() * validChar.length));
|
658 | }
|
659 | return filename;
|
660 | };
|
661 | AccountManager.prototype.getDeprecatedMethodError = function () {
|
662 | return {
|
663 | message: 'Method is deprecated',
|
664 | statusCode: 404
|
665 | };
|
666 | };
|
667 | AccountManager.AppPermission = {
|
668 | OWNER: "Owner",
|
669 | COLLABORATOR: "Collaborator"
|
670 | };
|
671 | return AccountManager;
|
672 | }());
|
673 | var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26;
|
674 | module.exports = AccountManager;
|