-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccountClient.ts
More file actions
101 lines (90 loc) · 3 KB
/
accountClient.ts
File metadata and controls
101 lines (90 loc) · 3 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { IdempotentRequest, NitteiBaseClient } from './baseClient'
import type {
AccountSearchEventsRequestBody,
SearchEventsAPIResponse,
} from './gen_types'
import type { AccountResponse } from './gen_types/AccountResponse'
import type { AddAccountIntegrationRequestBody } from './gen_types/AddAccountIntegrationRequestBody'
import type { CreateAccountRequestBody } from './gen_types/CreateAccountRequestBody'
import type { CreateAccountResponseBody } from './gen_types/CreateAccountResponseBody'
import { replaceEventStringsToDates } from './helpers/datesConverters'
const ACCOUNT_SEARCH_EVENTS_ENDPOINT = '/account/events/search'
/**
* Client for the account endpoints
* This is an admin client
*/
export class NitteiAccountClient extends NitteiBaseClient {
/**
* Create an account
* @param data - data for creating the account
* @returns CreateAccountResponse - created account
*/
public async create(data: CreateAccountRequestBody) {
return await this.post<CreateAccountResponseBody>('/account', data)
}
/**
* Update the public signing key for the account
* @param publicSigningKey - new key
* @returns AccountResponse - updated account
*/
public async setPublicSigningKey(publicSigningKey?: string) {
return await this.put<AccountResponse>('/account/pubkey', {
publicJwtKey: publicSigningKey,
})
}
/**
* Remove the public signing key for the account
* @returns AccountResponse - updated account
*/
public async removePublicSigningKey() {
return await this.setPublicSigningKey()
}
/**
* Set the webhook for the account
* @param url - url to set as webhook
* @returns {@see AccountResponse} - updated account
*/
public async setWebhook(url: string) {
return await this.put<AccountResponse>('/account/webhook', {
webhookUrl: url,
})
}
/**
* Enable/connect Google integration
* @param data - data for connecting Google integration
* @returns AccountResponse - updated account
*/
public async connectGoogle(data: AddAccountIntegrationRequestBody) {
return await this.put<AccountResponse>('/account/integration/google', data)
}
/**
* Remove the Webhook for the account
* @returns AccountResponse - updated account
*/
public async removeWebhook() {
return await this.delete<AccountResponse>('/account/webhook')
}
/**
* Get the current account
* @returns AccountResponse - account
*/
public async me() {
return await this.get<AccountResponse>('/account')
}
/**
* Search events in the account
* @param params - search parameters, check {@link AccountSearchEventsRequestBody} for more details
* @returns - the events found
*/
@IdempotentRequest(ACCOUNT_SEARCH_EVENTS_ENDPOINT)
public async searchEventsInAccount(params: AccountSearchEventsRequestBody) {
const res = await this.post<SearchEventsAPIResponse>(
ACCOUNT_SEARCH_EVENTS_ENDPOINT,
params
)
for (const event of res.events) {
replaceEventStringsToDates(event)
}
return res
}
}