bintray.js 2.1 KB

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