12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const tslib_1 = require("tslib");
- const http_1 = require("./http");
- const guards_1 = require("../guards");
- class App {
- constructor(token, client) {
- this.token = token;
- this.client = client;
- }
- load(app_id) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield this.client.make('GET', `/apps/${app_id}`);
- req.set('Authorization', `Bearer ${this.token}`).send({});
- const res = yield this.client.do(req);
- if (!guards_1.isAppResponse(res)) {
- throw http_1.createFatalAPIFormat(req, res);
- }
- return res.data;
- });
- }
- paginate() {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- return this.client.paginate({
- reqgen: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield this.client.make('GET', '/apps');
- req.set('Authorization', `Bearer ${this.token}`);
- return { req };
- }),
- guard: guards_1.isAppsResponse,
- });
- });
- }
- create({ name }) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield this.client.make('POST', '/apps');
- req.set('Authorization', `Bearer ${this.token}`).send({ name });
- const res = yield this.client.do(req);
- if (!guards_1.isAppResponse(res)) {
- throw http_1.createFatalAPIFormat(req, res);
- }
- return res.data;
- });
- }
- createAssociation(id, association) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield this.client.make('POST', `/apps/${id}/repository`);
- req
- .set('Authorization', `Bearer ${this.token}`)
- .send({
- repository_id: association.repoId,
- type: association.type,
- branches: association.branches,
- });
- const res = yield this.client.do(req);
- if (!guards_1.isAppAssociationResponse(res)) {
- throw http_1.createFatalAPIFormat(req, res);
- }
- return res.data;
- });
- }
- deleteAssociation(id) {
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
- const { req } = yield this.client.make('DELETE', `/apps/${id}/repository`);
- req
- .set('Authorization', `Bearer ${this.token}`)
- .send({});
- yield req;
- });
- }
- }
- exports.App = App;
|