UI for Zipcoin Blue

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const http_1 = require("./http");
  5. const guards_1 = require("../guards");
  6. class App {
  7. constructor(token, client) {
  8. this.token = token;
  9. this.client = client;
  10. }
  11. load(app_id) {
  12. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  13. const { req } = yield this.client.make('GET', `/apps/${app_id}`);
  14. req.set('Authorization', `Bearer ${this.token}`).send({});
  15. const res = yield this.client.do(req);
  16. if (!guards_1.isAppResponse(res)) {
  17. throw http_1.createFatalAPIFormat(req, res);
  18. }
  19. return res.data;
  20. });
  21. }
  22. paginate() {
  23. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  24. return this.client.paginate({
  25. reqgen: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
  26. const { req } = yield this.client.make('GET', '/apps');
  27. req.set('Authorization', `Bearer ${this.token}`);
  28. return { req };
  29. }),
  30. guard: guards_1.isAppsResponse,
  31. });
  32. });
  33. }
  34. create({ name }) {
  35. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  36. const { req } = yield this.client.make('POST', '/apps');
  37. req.set('Authorization', `Bearer ${this.token}`).send({ name });
  38. const res = yield this.client.do(req);
  39. if (!guards_1.isAppResponse(res)) {
  40. throw http_1.createFatalAPIFormat(req, res);
  41. }
  42. return res.data;
  43. });
  44. }
  45. createAssociation(id, association) {
  46. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  47. const { req } = yield this.client.make('POST', `/apps/${id}/repository`);
  48. req
  49. .set('Authorization', `Bearer ${this.token}`)
  50. .send({
  51. repository_id: association.repoId,
  52. type: association.type,
  53. branches: association.branches,
  54. });
  55. const res = yield this.client.do(req);
  56. if (!guards_1.isAppAssociationResponse(res)) {
  57. throw http_1.createFatalAPIFormat(req, res);
  58. }
  59. return res.data;
  60. });
  61. }
  62. deleteAssociation(id) {
  63. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  64. const { req } = yield this.client.make('DELETE', `/apps/${id}/repository`);
  65. req
  66. .set('Authorization', `Bearer ${this.token}`)
  67. .send({});
  68. yield req;
  69. });
  70. }
  71. }
  72. exports.App = App;