azdev-automation
Version:
Azure DevOps automation framework enables access control automation of projects, pipelines and repositories configuration in Azure DevOps Services
124 lines (123 loc) • 5.21 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AzDevClient = void 0;
const iazdevclient_1 = require("./iazdevclient");
const retry_1 = require("./retry");
class AzDevClient {
constructor(client, apiType, accountName, logger) {
this.debugLogger = logger.extend(this.constructor.name);
this.client = client;
this.apiType = apiType;
this.accountName = accountName;
}
async get(path, type = this.apiType) {
const debug = this.debugLogger.extend(this.get.name);
const url = this.newUrl(path, type);
debug(url);
const response = await this.client.get(url);
return response.result;
}
async post(path, apiVersion, body, type = this.apiType) {
const debug = this.debugLogger.extend(this.post.name);
const url = this.newUrl(path, type);
debug(url);
const requestOptions = {};
if (apiVersion) {
requestOptions.acceptHeader = `api-version=${apiVersion}`;
}
const response = await this.client.create(url, body, requestOptions);
return response.result;
}
async postNoRetry(path, apiVersion, body, type = this.apiType) {
const debug = this.debugLogger.extend(this.post.name);
const url = this.newUrl(path, type);
debug(url);
const requestOptions = {};
if (apiVersion) {
requestOptions.acceptHeader = `api-version=${apiVersion}`;
}
const response = await this.client.create(url, body, requestOptions);
return response.result;
}
async patch(path, apiVersion, body, type = this.apiType) {
const debug = this.debugLogger.extend(this.patch.name);
const url = this.newUrl(path, type);
debug(url);
const requestOptions = {};
if (apiVersion) {
requestOptions.acceptHeader = `api-version=${apiVersion}`;
}
const response = await this.client.update(url, body, requestOptions);
return response.result;
}
async put(path, apiVersion, body, type = this.apiType) {
const debug = this.debugLogger.extend(this.put.name);
const url = this.newUrl(path, type);
debug(url);
const requestOptions = {};
if (apiVersion) {
requestOptions.acceptHeader = `api-version=${apiVersion}`;
}
const response = await this.client.replace(url, body, requestOptions);
return response.result;
}
async delete(path, apiVersion, type = this.apiType) {
const debug = this.debugLogger.extend(this.delete.name);
const url = this.newUrl(path, type);
debug(url);
const requestOptions = {};
if (apiVersion) {
requestOptions.acceptHeader = `api-version=${apiVersion}`;
}
const response = await this.client.del(url, requestOptions);
return response.result;
}
newUrl(path, type) {
const debug = this.debugLogger.extend(this.newUrl.name);
const prefix = type.toString();
const base = `https://${prefix}.azure.com`;
const suffix = `${this.accountName}/${path}`;
const url = `${base}${suffix}`;
return url;
}
}
__decorate([
(0, retry_1.Retryable)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], AzDevClient.prototype, "get", null);
__decorate([
(0, retry_1.Retryable)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, Object, String]),
__metadata("design:returntype", Promise)
], AzDevClient.prototype, "post", null);
__decorate([
(0, retry_1.Retryable)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, Object, String]),
__metadata("design:returntype", Promise)
], AzDevClient.prototype, "patch", null);
__decorate([
(0, retry_1.Retryable)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, Object, String]),
__metadata("design:returntype", Promise)
], AzDevClient.prototype, "put", null);
__decorate([
(0, retry_1.Retryable)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, String]),
__metadata("design:returntype", Promise)
], AzDevClient.prototype, "delete", null);
exports.AzDevClient = AzDevClient;