UNPKG

stash-connector

Version:

Module to handle and work with Atlassian Stash projects and repositories throug REST API. Admin your repositories and projects in Stash easy. This project is not an Atlassian official project but use the Atlassian Stash REST API

145 lines 5.86 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Avatar = exports.Page = exports.StashError = exports.EndpointService = exports.Basic = void 0; var http_1 = require("../core/http"); var Basic = /** @class */ (function () { function Basic(auth) { this.API_ENDPOINT = '/rest/api/1.0'; this.user = auth.user; this.password = auth.password; this.host = auth.host; this.apiEndpoint = this.processURL(auth.host) + this.API_ENDPOINT; } Basic.prototype.encode = function () { return btoa(this.user + ':' + this.password); }; Basic.prototype.header = function () { return 'Basic ' + this.encode(); }; Basic.prototype.processURL = function (url) { if (url.endsWith('/')) { return url.substring(0, url.length - 1); } return url; }; return Basic; }()); exports.Basic = Basic; var EndpointService = /** @class */ (function () { function EndpointService(auth, path) { this.AUTH_HEADER = 'Authorization'; this.auth = new Basic({ host: auth.host, user: auth.user, password: auth.password }); this.auth.apiEndpoint = auth.apiEndpoint; this.path = path; this.auth.apiEndpoint += path; } EndpointService.prototype.setPageOptions = function (request, pageOptions) { this.processOptions(request, pageOptions); }; EndpointService.prototype.getEndpoint = function (options) { var endpoint = this.auth.apiEndpoint; if (options === null || options === void 0 ? void 0 : options.param) { endpoint += '/' + (options === null || options === void 0 ? void 0 : options.param); } return endpoint; }; EndpointService.prototype.processOptions = function (request, options) { if (options) { for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) { var key = _a[_i]; var value = options[key]; if (key !== 'pageOptions' && value !== undefined) { request.addQueryParam(key, value); } } } }; EndpointService.prototype.doGet = function (options) { var endpoint = this.getEndpoint(options); var request = http_1.HTTP.get(endpoint).addHeader(this.AUTH_HEADER, this.auth.header()); this.setPageOptions(request, options === null || options === void 0 ? void 0 : options.pageOptions); return request; }; EndpointService.prototype.doPost = function (options) { var endpoint = this.getEndpoint(options); var request = http_1.HTTP.post(endpoint).addHeader(this.AUTH_HEADER, this.auth.header()); this.setPageOptions(request, options === null || options === void 0 ? void 0 : options.pageOptions); return request; }; EndpointService.prototype.doPut = function (options) { var endpoint = this.getEndpoint(options); var request = http_1.HTTP.put(endpoint).addHeader(this.AUTH_HEADER, this.auth.header()); this.setPageOptions(request, options === null || options === void 0 ? void 0 : options.pageOptions); return request; }; EndpointService.prototype.doDelete = function (options) { var endpoint = this.getEndpoint(options); var request = http_1.HTTP.delete(endpoint).addHeader(this.AUTH_HEADER, this.auth.header()); this.setPageOptions(request, options === null || options === void 0 ? void 0 : options.pageOptions); return request; }; return EndpointService; }()); exports.EndpointService = EndpointService; var StashError = /** @class */ (function (_super) { __extends(StashError, _super); function StashError(error) { var _a, _b; var _this = _super.call(this, error.message) || this; _this.statusCode = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) || 400; _this.name = 'StashError'; _this.stack = error.stack; _this.status = error.status; _this.statusText = (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText; if (error.response && error.response.data) { var data = error.response.data; if (data.errors) { _this.errors = data.errors; } } return _this; } return StashError; }(Error)); exports.StashError = StashError; var Page = /** @class */ (function () { function Page() { this.size = 0; this.limit = 0; this.isLastPage = true; this.values = []; this.start = 0; this.nextPageStart = 0; } return Page; }()); exports.Page = Page; var Avatar = /** @class */ (function () { function Avatar(type, content) { this.type = type; this.content = content; } Avatar.prototype.getAvatar = function () { return 'data:image/' + this.type + ';base64,' + this.content + ''; }; return Avatar; }()); exports.Avatar = Avatar; //# sourceMappingURL=index.js.map