1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const guards_1 = require("../guards");
|
4 | const http_1 = require("./http");
|
5 | class UserClient extends http_1.ResourceClient {
|
6 | constructor(token, e) {
|
7 | super();
|
8 | this.token = token;
|
9 | this.e = e;
|
10 | }
|
11 | async load(id, modifiers) {
|
12 | const { req } = await this.e.client.make('GET', `/users/${id}`);
|
13 | this.applyAuthentication(req, this.token);
|
14 | this.applyModifiers(req, modifiers);
|
15 | const res = await this.e.client.do(req);
|
16 | if (!guards_1.isUserResponse(res)) {
|
17 | throw http_1.createFatalAPIFormat(req, res);
|
18 | }
|
19 | return res.data;
|
20 | }
|
21 | async loadSelf() {
|
22 | const { req } = await this.e.client.make('GET', '/users/self');
|
23 | this.applyAuthentication(req, this.token);
|
24 | const res = await this.e.client.do(req);
|
25 | if (!guards_1.isUserResponse(res)) {
|
26 | throw http_1.createFatalAPIFormat(req, res);
|
27 | }
|
28 | return res.data;
|
29 | }
|
30 | async oAuthGithubLogin(id) {
|
31 | const { req } = await this.e.client.make('POST', `/users/${id}/oauth/github`);
|
32 | this.applyAuthentication(req, this.token);
|
33 | req.send({ source: 'cli' });
|
34 | const res = await this.e.client.do(req);
|
35 | if (!guards_1.isOAuthLoginResponse(res)) {
|
36 | throw http_1.createFatalAPIFormat(req, res);
|
37 | }
|
38 | return res.data.redirect_url;
|
39 | }
|
40 | paginateGithubRepositories(id) {
|
41 | return new http_1.TokenPaginator({
|
42 | client: this.e.client,
|
43 | reqgen: async () => {
|
44 | const { req } = await this.e.client.make('GET', `/users/${id}/oauth/github/repositories`);
|
45 | req.set('Authorization', `Bearer ${this.token}`);
|
46 | return { req };
|
47 | },
|
48 | guard: guards_1.isGithubRepoListResponse,
|
49 | });
|
50 | }
|
51 | paginateGithubBranches(userId, repoId) {
|
52 | return new http_1.TokenPaginator({
|
53 | client: this.e.client,
|
54 | reqgen: async () => {
|
55 | const { req } = await this.e.client.make('GET', `/users/${userId}/oauth/github/repositories/${repoId}/branches`);
|
56 | req.set('Authorization', `Bearer ${this.token}`);
|
57 | return { req };
|
58 | },
|
59 | guard: guards_1.isGithubBranchListResponse,
|
60 | });
|
61 | }
|
62 | }
|
63 | exports.UserClient = UserClient;
|