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