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