-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.ts
58 lines (49 loc) · 1.5 KB
/
clients.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
import makeDebug from 'debug'
import type Bottleneck from 'bottleneck'
import type { Credentials } from '../interfaces.js'
import { rateLimitedClient as withRateLimit } from '../rate-limit.js'
import {
create as createCustomer,
deleteCustomer,
list as listCustomers,
listAsyncGenerator as listCustomersAsyncGenerator,
retrieve as retrieveCustomer,
update as updateCustomer
} from './api.js'
import type {
CreateRequestBody,
ListOptions,
DeleteRequestBody,
RetrieveConfig,
UpdateRequestBody
} from './interfaces.js'
const debug = makeDebug('fattureincloud-client/customers/client')
export const basicClient = (credentials: Credentials) => {
debug('make FattureInCloud customers API client')
return {
create: (config: CreateRequestBody) => {
return createCustomer(credentials, config)
},
delete: (config: DeleteRequestBody) => {
return deleteCustomer(credentials, config)
},
list: (options?: ListOptions) => {
return listCustomers(credentials, options)
},
listAsyncGenerator: (options?: ListOptions) => {
return listCustomersAsyncGenerator(credentials, options)
},
retrieve: (config: RetrieveConfig) => {
return retrieveCustomer(credentials, config)
},
update: (config: UpdateRequestBody) => {
return updateCustomer(credentials, config)
}
}
}
export const rateLimitedClient = (
credentials: Credentials,
options?: Bottleneck.ConstructorOptions
) => {
return withRateLimit(basicClient(credentials), options)
}