-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.ts
52 lines (44 loc) · 1.29 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
import makeDebug from 'debug'
import type Bottleneck from 'bottleneck'
import type { Credentials } from '../interfaces.js'
import { rateLimitedClient as withRateLimit } from '../rate-limit.js'
import {
createInvoice,
deleteInvoice,
listInvoices,
listInvoicesAsyncGenerator,
retrieveInvoice
} from './api.js'
import type {
CreateRequestBody,
DeleteRequestBody,
ListOptions,
RetrieveConfig
} from './interfaces.js'
const debug = makeDebug('fattureincloud-client/invoices/client')
export const basicClient = (credentials: Credentials) => {
debug('make FattureInCloud invoices API client')
return {
create: (config: CreateRequestBody) => {
return createInvoice(credentials, config)
},
delete: (config: DeleteRequestBody) => {
return deleteInvoice(credentials, config)
},
list: (options?: ListOptions) => {
return listInvoices(credentials, options)
},
listAsyncGenerator: (options?: ListOptions) => {
return listInvoicesAsyncGenerator(credentials, options)
},
retrieve: (config: RetrieveConfig) => {
return retrieveInvoice(credentials, config)
}
}
}
export const rateLimitedClient = (
credentials: Credentials,
options?: Bottleneck.ConstructorOptions
) => {
return withRateLimit(basicClient(credentials), options)
}