-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathapps.ts
More file actions
335 lines (302 loc) · 8.47 KB
/
apps.ts
File metadata and controls
335 lines (302 loc) · 8.47 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import type { Client } from 'openapi-fetch'
import type { RequestOptions } from './common.js'
import type {
AppReplaceUpdate,
CreateStripeCheckoutSessionRequest,
operations,
paths,
} from './schemas.js'
import { transformResponse } from './utils.js'
/**
* Apps
* Manage integrations for extending OpenMeter's functionality.
*/
export class Apps {
public marketplace: AppMarketplace
public stripe: AppStripe
public customInvoicing: AppCustomInvoicing
constructor(private client: Client<paths, `${string}/${string}`>) {
this.marketplace = new AppMarketplace(client)
this.stripe = new AppStripe(client)
this.customInvoicing = new AppCustomInvoicing(client)
}
/**
* List apps
* @param query - The query parameters
* @param signal - An optional abort signal
* @returns The apps
*/
public async list(
query?: operations['listApps']['parameters']['query'],
options?: RequestOptions,
) {
const resp = await this.client.GET('/api/v1/apps', {
params: { query },
...options,
})
return transformResponse(resp)
}
/**
* Get an app
* @param id - The ID of the app
* @param signal - An optional abort signal
* @returns The app
*/
public async get(
id: operations['getApp']['parameters']['path']['id'],
options?: RequestOptions,
) {
const resp = await this.client.GET('/api/v1/apps/{id}', {
params: { path: { id } },
...options,
})
return transformResponse(resp)
}
/**
* Update an app
* @param id - The ID of the app
* @param body - The body of the request
* @param signal - An optional abort signal
* @returns The app
*/
public async update(
id: operations['updateApp']['parameters']['path']['id'],
body: AppReplaceUpdate,
options?: RequestOptions,
) {
const resp = await this.client.PUT('/api/v1/apps/{id}', {
body,
params: { path: { id } },
...options,
})
return transformResponse(resp)
}
/**
* Uninstall an app
* @param id - The ID of the app
* @param signal - An optional abort signal
* @returns The app
*/
public async uninstall(
id: operations['uninstallApp']['parameters']['path']['id'],
options?: RequestOptions,
) {
const resp = await this.client.DELETE('/api/v1/apps/{id}', {
params: { path: { id } },
...options,
})
return transformResponse(resp)
}
}
/**
* App Marketplace
* Available apps from the OpenMeter Marketplace.
*/
export class AppMarketplace {
constructor(private client: Client<paths, `${string}/${string}`>) {}
/**
* List available apps
* @param query - The query parameters
* @param signal - An optional abort signal
* @returns The apps
*/
public async list(
query?: operations['listMarketplaceListings']['parameters']['query'],
options?: RequestOptions,
) {
const resp = await this.client.GET('/api/v1/marketplace/listings', {
params: { query },
...options,
})
return transformResponse(resp)
}
/**
* Get details for a listing
* @param type - The type of the listing
* @param signal - An optional abort signal
* @returns The listing
*/
public async get(
type: operations['getMarketplaceListing']['parameters']['path']['type'],
options?: RequestOptions,
) {
const resp = await this.client.GET('/api/v1/marketplace/listings/{type}', {
params: { path: { type } },
...options,
})
return transformResponse(resp)
}
/**
* Install an app via OAuth. Returns a URL to start the OAuth 2.0 flow.
* @param type - The type of the listing
* @param signal - An optional abort signal
* @returns The OAuth2 install URL
*/
public async getOauth2InstallUrl(
type: operations['marketplaceOAuth2InstallGetURL']['parameters']['path']['type'],
options?: RequestOptions,
) {
const resp = await this.client.GET(
'/api/v1/marketplace/listings/{type}/install/oauth2',
{
params: { path: { type } },
...options,
},
)
return transformResponse(resp)
}
/**
* Authorize OAuth2 code. Verifies the OAuth code and exchanges it for a token and refresh token
* @param type - The type of the listing
* @param signal - An optional abort signal
* @returns The authorization URL
*/
public async authorizeOauth2(
type: operations['marketplaceOAuth2InstallAuthorize']['parameters']['path']['type'],
options?: RequestOptions,
) {
const resp = await this.client.GET(
'/api/v1/marketplace/listings/{type}/install/oauth2/authorize',
{
params: { path: { type } },
...options,
},
)
return transformResponse(resp)
}
/**
* Install an app via API key.
* @param type - The type of the listing
* @param signal - An optional abort signal
* @returns The installation
*/
public async installWithAPIKey(
type: operations['marketplaceAppAPIKeyInstall']['parameters']['path']['type'],
body: operations['marketplaceAppAPIKeyInstall']['requestBody']['content']['application/json'],
options?: RequestOptions,
) {
const resp = await this.client.POST(
'/api/v1/marketplace/listings/{type}/install/apikey',
{
body,
params: { path: { type } },
...options,
},
)
return transformResponse(resp)
}
}
/**
* Stripe App
*/
export class AppStripe {
constructor(private client: Client<paths, `${string}/${string}`>) {}
/**
* Create a checkout session
* @param body - The body of the request
* @param signal - An optional abort signal
* @returns The checkout session
*/
public async createCheckoutSession(
body: CreateStripeCheckoutSessionRequest,
options?: RequestOptions,
) {
const resp = await this.client.POST('/api/v1/stripe/checkout/sessions', {
body,
...options,
})
return transformResponse(resp)
}
/**
* Update Stripe API key
* @param id - The ID of the app
* @param body - The API key data
* @param options - The request options
* @returns The updated API key
* @deprecated
*/
public async updateApiKey(
id: string,
body: operations['updateStripeAPIKey']['requestBody']['content']['application/json'],
options?: RequestOptions,
) {
const resp = await this.client.PUT('/api/v1/apps/{id}/stripe/api-key', {
body,
params: { path: { id } },
...options,
})
return transformResponse(resp)
}
}
/**
* Custom Invoicing App
*/
export class AppCustomInvoicing {
constructor(private client: Client<paths, `${string}/${string}`>) {}
/**
* Submit draft synchronization results
* @param invoiceId - The ID of the invoice
* @param body - The body of the request
* @param options - The request options
* @returns The synchronization result
*/
public async draftSynchronized(
invoiceId: string,
body: operations['appCustomInvoicingDraftSynchronized']['requestBody']['content']['application/json'],
options?: RequestOptions,
) {
const resp = await this.client.POST(
'/api/v1/apps/custom-invoicing/{invoiceId}/draft/synchronized',
{
body,
params: { path: { invoiceId } },
...options,
},
)
return transformResponse(resp)
}
/**
* Submit issuing synchronization results
* @param invoiceId - The ID of the invoice
* @param body - The body of the request
* @param options - The request options
* @returns The synchronization result
*/
public async issuingSynchronized(
invoiceId: string,
body: operations['appCustomInvoicingIssuingSynchronized']['requestBody']['content']['application/json'],
options?: RequestOptions,
) {
const resp = await this.client.POST(
'/api/v1/apps/custom-invoicing/{invoiceId}/issuing/synchronized',
{
body,
params: { path: { invoiceId } },
...options,
},
)
return transformResponse(resp)
}
/**
* Update payment status
* @param invoiceId - The ID of the invoice
* @param body - The body of the request
* @param options - The request options
* @returns The payment status update result
*/
public async updatePaymentStatus(
invoiceId: string,
body: operations['appCustomInvoicingUpdatePaymentStatus']['requestBody']['content']['application/json'],
options?: RequestOptions,
) {
const resp = await this.client.POST(
'/api/v1/apps/custom-invoicing/{invoiceId}/payment/status',
{
body,
params: { path: { invoiceId } },
...options,
},
)
return transformResponse(resp)
}
}