-
Notifications
You must be signed in to change notification settings - Fork 2
/
scopes.ts
60 lines (56 loc) · 1.73 KB
/
scopes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { ScopeList, Message } from "./deps.ts";
export class Scopes {
constructor(private _credentials: string, private _apiUrl: string) {}
private apiPath = "/v1/projects";
/**
* Retrieves scopes of the specified member in the specified project.
* @param projectId Unique identifier of the project
* @param memberId Unique identifier of the member
*/
async get(projectId: string, memberId: string): Promise<ScopeList> {
const response = await fetch(
`https://${this._apiUrl}${this.apiPath}/${projectId}/members/${memberId}/scopes`,
{
method: "GET",
headers: {
Authorization: `token ${this._credentials}`,
"Content-Type": "application/json",
"X-DG-Agent": window.dgAgent,
},
}
);
if (response.ok) {
return response.json();
}
throw new Error(`DG: ${response.status} ${response.statusText}`);
}
/**
* Updates the scope for the specified member in the specified project.
* @param projectId Unique identifier of the project
* @param memberId Unique identifier of the member being updated
* @param scope string of the scope to update to
*/
async update(
projectId: string,
memberId: string,
scope: string
): Promise<Message> {
const response = await fetch(
`https://${this._apiUrl}${this.apiPath}/${projectId}/members/${memberId}/scopes`,
{
method: "PUT",
headers: {
Authorization: `token ${this._credentials}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
scope,
}),
}
);
if (response.ok) {
return response.json();
}
throw new Error(`DG: ${response.status} ${response.statusText}`);
}
}