1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.BintrayClient = void 0;
|
7 |
|
8 | function _httpExecutor() {
|
9 | const data = require("./httpExecutor");
|
10 |
|
11 | _httpExecutor = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | class BintrayClient {
|
19 | constructor(options, httpExecutor, cancellationToken, apiKey) {
|
20 | this.httpExecutor = httpExecutor;
|
21 | this.cancellationToken = cancellationToken;
|
22 | this.requestHeaders = null;
|
23 |
|
24 | if (options.owner == null) {
|
25 | throw new Error("owner is not specified");
|
26 | }
|
27 |
|
28 | if (options.package == null) {
|
29 | throw new Error("package is not specified");
|
30 | }
|
31 |
|
32 | this.repo = options.repo || "generic";
|
33 | this.packageName = options.package;
|
34 | this.owner = options.owner;
|
35 | this.user = options.user || options.owner;
|
36 | this.component = options.component || null;
|
37 | this.distribution = options.distribution || "stable";
|
38 | this.auth = apiKey == null ? null : `Basic ${Buffer.from(`${this.user}:${apiKey}`).toString("base64")}`;
|
39 | this.basePath = `/packages/${this.owner}/${this.repo}/${this.packageName}`;
|
40 | }
|
41 |
|
42 | setRequestHeaders(value) {
|
43 | this.requestHeaders = value;
|
44 | }
|
45 |
|
46 | bintrayRequest(path, auth, data = null, cancellationToken, method) {
|
47 | return (0, _httpExecutor().parseJson)(this.httpExecutor.request((0, _httpExecutor().configureRequestOptions)({
|
48 | hostname: "api.bintray.com",
|
49 | path,
|
50 | headers: this.requestHeaders || undefined
|
51 | }, auth, method), cancellationToken, data));
|
52 | }
|
53 |
|
54 | getVersion(version) {
|
55 | return this.bintrayRequest(`${this.basePath}/versions/${version}`, this.auth, null, this.cancellationToken);
|
56 | }
|
57 |
|
58 | getVersionFiles(version) {
|
59 | return this.bintrayRequest(`${this.basePath}/versions/${version}/files`, this.auth, null, this.cancellationToken);
|
60 | }
|
61 |
|
62 | createVersion(version) {
|
63 | return this.bintrayRequest(`${this.basePath}/versions`, this.auth, {
|
64 | name: version
|
65 | }, this.cancellationToken);
|
66 | }
|
67 |
|
68 | deleteVersion(version) {
|
69 | return this.bintrayRequest(`${this.basePath}/versions/${version}`, this.auth, null, this.cancellationToken, "DELETE");
|
70 | }
|
71 |
|
72 | } exports.BintrayClient = BintrayClient;
|
73 |
|
74 |
|
\ | No newline at end of file |