/
UserInfo.ts
53 lines (48 loc) · 1.29 KB
/
UserInfo.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
import { TerraUser } from '../models/TerraUser';
import { TerraPayload } from './WebhookEvents';
import fetch from 'cross-fetch';
import { RequestWrapper } from './Helpers';
export interface TerraUserResponse {
status: string;
user: TerraUser;
is_authenticated: boolean;
}
export function GetUser(
devId: string,
apiKey: string,
userID?: string,
referenceID?: string,
): Promise<TerraUserResponse> {
const requestOptions = {
method: 'GET',
headers: {
'X-API-Key': apiKey,
'dev-id': devId,
'Content-Type': 'application/json',
},
};
if (userID) {
return RequestWrapper<TerraUserResponse>('userInfo', requestOptions, {
user_id: userID,
});
} else {
return RequestWrapper<TerraUserResponse>('userInfo', requestOptions, {
reference_id: referenceID,
});
}
}
export function DeauthUser(devId: string, apiKey: string, userId: string): Promise<void> {
const requestOptions = {
method: 'DELETE',
headers: {
'X-API-Key': apiKey,
'dev-id': devId,
'Content-Type': 'application/json',
},
};
return new Promise<void>((res, rej) => {
fetch(`https://api.tryterra.co/v2/auth/deauthenticateUser?user_id=${userId}`, requestOptions)
.then((_) => res())
.catch((error) => rej(error as TerraPayload));
});
}