@openmeter/client 1.0.0-beta.229 → 1.0.0-beta.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +364 -66
  3. package/dist/core.d.ts +0 -1
  4. package/dist/core.js +8 -1
  5. package/dist/funcs/addons.d.ts +49 -1
  6. package/dist/funcs/addons.js +161 -29
  7. package/dist/funcs/apps.d.ts +14 -1
  8. package/dist/funcs/apps.js +52 -9
  9. package/dist/funcs/billing.d.ts +46 -1
  10. package/dist/funcs/billing.js +126 -17
  11. package/dist/funcs/currencies.d.ts +30 -1
  12. package/dist/funcs/currencies.js +113 -23
  13. package/dist/funcs/customers.d.ts +167 -2
  14. package/dist/funcs/customers.js +580 -90
  15. package/dist/funcs/defaults.d.ts +10 -1
  16. package/dist/funcs/defaults.js +35 -5
  17. package/dist/funcs/entitlements.d.ts +5 -1
  18. package/dist/funcs/entitlements.js +25 -6
  19. package/dist/funcs/events.d.ts +14 -1
  20. package/dist/funcs/events.js +41 -9
  21. package/dist/funcs/features.d.ts +42 -1
  22. package/dist/funcs/features.js +142 -28
  23. package/dist/funcs/governance.d.ts +14 -1
  24. package/dist/funcs/governance.js +42 -10
  25. package/dist/funcs/index.d.ts +1 -1
  26. package/dist/funcs/index.js +2 -1
  27. package/dist/funcs/invoices.d.ts +51 -0
  28. package/dist/funcs/invoices.js +125 -0
  29. package/dist/funcs/llmCost.d.ts +36 -1
  30. package/dist/funcs/llmCost.js +114 -24
  31. package/dist/funcs/meters.d.ts +55 -2
  32. package/dist/funcs/meters.js +172 -28
  33. package/dist/funcs/planAddons.d.ts +35 -1
  34. package/dist/funcs/planAddons.js +139 -29
  35. package/dist/funcs/plans.d.ts +49 -1
  36. package/dist/funcs/plans.js +163 -25
  37. package/dist/funcs/subscriptions.d.ts +61 -2
  38. package/dist/funcs/subscriptions.js +238 -40
  39. package/dist/funcs/tax.d.ts +25 -1
  40. package/dist/funcs/tax.js +104 -22
  41. package/dist/index.d.ts +6 -4
  42. package/dist/index.js +4 -3
  43. package/dist/lib/config.d.ts +9 -1
  44. package/dist/lib/config.js +1 -1
  45. package/dist/lib/encodings.d.ts +1 -2
  46. package/dist/lib/encodings.js +6 -5
  47. package/dist/lib/paginate.d.ts +56 -0
  48. package/dist/lib/paginate.js +60 -0
  49. package/dist/lib/request.d.ts +0 -1
  50. package/dist/lib/request.js +1 -1
  51. package/dist/lib/to-error.d.ts +0 -1
  52. package/dist/lib/to-error.js +1 -1
  53. package/dist/lib/types.d.ts +0 -1
  54. package/dist/lib/types.js +1 -1
  55. package/dist/lib/version.d.ts +1 -0
  56. package/dist/lib/version.js +5 -0
  57. package/dist/lib/wire.d.ts +20 -0
  58. package/dist/lib/wire.js +401 -0
  59. package/dist/models/errors.d.ts +13 -2
  60. package/dist/models/errors.js +31 -4
  61. package/dist/models/operations/addons.d.ts +17 -6
  62. package/dist/models/operations/addons.js +1 -1
  63. package/dist/models/operations/apps.d.ts +4 -6
  64. package/dist/models/operations/apps.js +1 -1
  65. package/dist/models/operations/billing.d.ts +5 -5
  66. package/dist/models/operations/billing.js +1 -1
  67. package/dist/models/operations/currencies.d.ts +27 -10
  68. package/dist/models/operations/currencies.js +1 -1
  69. package/dist/models/operations/customers.d.ts +87 -33
  70. package/dist/models/operations/customers.js +1 -1
  71. package/dist/models/operations/defaults.d.ts +2 -2
  72. package/dist/models/operations/defaults.js +1 -1
  73. package/dist/models/operations/entitlements.d.ts +0 -1
  74. package/dist/models/operations/entitlements.js +1 -1
  75. package/dist/models/operations/events.d.ts +20 -5
  76. package/dist/models/operations/events.js +1 -1
  77. package/dist/models/operations/features.d.ts +24 -9
  78. package/dist/models/operations/features.js +1 -1
  79. package/dist/models/operations/governance.d.ts +3 -3
  80. package/dist/models/operations/governance.js +1 -1
  81. package/dist/models/operations/invoices.d.ts +45 -0
  82. package/dist/models/operations/invoices.js +2 -0
  83. package/dist/models/operations/llmCost.d.ts +16 -5
  84. package/dist/models/operations/llmCost.js +1 -1
  85. package/dist/models/operations/meters.d.ts +29 -9
  86. package/dist/models/operations/meters.js +1 -1
  87. package/dist/models/operations/planAddons.d.ts +7 -7
  88. package/dist/models/operations/planAddons.js +1 -1
  89. package/dist/models/operations/plans.d.ts +14 -6
  90. package/dist/models/operations/plans.js +1 -1
  91. package/dist/models/operations/subscriptions.d.ts +36 -11
  92. package/dist/models/operations/subscriptions.js +1 -1
  93. package/dist/models/operations/tax.d.ts +6 -6
  94. package/dist/models/operations/tax.js +1 -1
  95. package/dist/models/schemas.d.ts +27484 -3125
  96. package/dist/models/schemas.js +6247 -495
  97. package/dist/models/types.d.ts +4548 -1398
  98. package/dist/models/types.js +1 -1
  99. package/dist/sdk/addons.d.ts +60 -1
  100. package/dist/sdk/addons.js +63 -1
  101. package/dist/sdk/apps.d.ts +25 -1
  102. package/dist/sdk/apps.js +28 -1
  103. package/dist/sdk/billing.d.ts +57 -1
  104. package/dist/sdk/billing.js +60 -1
  105. package/dist/sdk/customers.d.ts +213 -2
  106. package/dist/sdk/customers.js +228 -2
  107. package/dist/sdk/defaults.d.ts +10 -1
  108. package/dist/sdk/defaults.js +11 -1
  109. package/dist/sdk/entitlements.d.ts +5 -1
  110. package/dist/sdk/entitlements.js +6 -1
  111. package/dist/sdk/events.d.ts +25 -1
  112. package/dist/sdk/events.js +28 -1
  113. package/dist/sdk/features.d.ts +53 -1
  114. package/dist/sdk/features.js +56 -1
  115. package/dist/sdk/internal.d.ts +180 -0
  116. package/dist/sdk/internal.js +224 -0
  117. package/dist/sdk/llmCost.d.ts +57 -1
  118. package/dist/sdk/llmCost.js +62 -1
  119. package/dist/sdk/meters.d.ts +66 -2
  120. package/dist/sdk/meters.js +71 -2
  121. package/dist/sdk/planAddons.d.ts +46 -1
  122. package/dist/sdk/planAddons.js +49 -1
  123. package/dist/sdk/plans.d.ts +60 -1
  124. package/dist/sdk/plans.js +63 -1
  125. package/dist/sdk/sdk.d.ts +9 -7
  126. package/dist/sdk/sdk.js +11 -10
  127. package/dist/sdk/subscriptions.d.ts +71 -1
  128. package/dist/sdk/subscriptions.js +76 -1
  129. package/dist/sdk/tax.d.ts +34 -1
  130. package/dist/sdk/tax.js +37 -1
  131. package/package.json +31 -6
  132. package/dist/sdk/currencies.d.ts +0 -12
  133. package/dist/sdk/currencies.js +0 -21
  134. package/dist/sdk/governance.d.ts +0 -9
  135. package/dist/sdk/governance.js +0 -12
@@ -1,141 +1,631 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  import { http } from '../core.js';
2
3
  import { request } from '../lib/request.js';
3
- import { encodePath, toURLSearchParams, encodeSort } from '../lib/encodings.js';
4
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js';
5
+ import { toWire, fromWire, assertValid, toSnakeCase } from '../lib/wire.js';
6
+ import * as schemas from '../models/schemas.js';
7
+ /**
8
+ * Create customer
9
+ *
10
+ * POST /openmeter/customers
11
+ */
4
12
  export function createCustomer(client, req, options) {
5
- return request(() => http(client)
6
- .post('openmeter/customers', { ...options, json: req })
7
- .json());
13
+ return request(() => {
14
+ const body = toWire(req, schemas.createCustomerBody);
15
+ if (client._options.validate) {
16
+ assertValid(schemas.createCustomerBodyWire, body);
17
+ }
18
+ return http(client)
19
+ .post('openmeter/customers', { ...options, json: body })
20
+ .json()
21
+ .then((data) => {
22
+ if (client._options.validate) {
23
+ assertValid(schemas.createCustomerResponseWire, data);
24
+ }
25
+ return fromWire(data, schemas.createCustomerResponse);
26
+ });
27
+ });
8
28
  }
29
+ /**
30
+ * Get customer
31
+ *
32
+ * GET /openmeter/customers/{customerId}
33
+ */
9
34
  export function getCustomer(client, req, options) {
10
- const path = encodePath('openmeter/customers/{customerId}', {
11
- customerId: req.customerId,
35
+ return request(() => {
36
+ const path = `openmeter/customers/${(() => {
37
+ if (req.customerId === undefined) {
38
+ throw new Error('missing path parameter: customerId');
39
+ }
40
+ return encodeURIComponent(String(req.customerId));
41
+ })()}`;
42
+ return http(client)
43
+ .get(path, options)
44
+ .json()
45
+ .then((data) => {
46
+ if (client._options.validate) {
47
+ assertValid(schemas.getCustomerResponseWire, data);
48
+ }
49
+ return fromWire(data, schemas.getCustomerResponse);
50
+ });
12
51
  });
13
- return request(() => http(client).get(path, options).json());
14
52
  }
53
+ /**
54
+ * List customers
55
+ *
56
+ * GET /openmeter/customers
57
+ */
15
58
  export function listCustomers(client, req = {}, options) {
16
- const searchParams = toURLSearchParams({
17
- page: req.page,
18
- sort: encodeSort(req.sort),
19
- filter: req.filter,
59
+ return request(() => {
60
+ const query = toWire({
61
+ page: req.page,
62
+ sort: encodeSort(req.sort, toSnakeCase),
63
+ filter: req.filter,
64
+ }, schemas.listCustomersQueryParams);
65
+ if (client._options.validate) {
66
+ assertValid(schemas.listCustomersQueryParamsWire, query);
67
+ }
68
+ const searchParams = toURLSearchParams(query);
69
+ return http(client)
70
+ .get('openmeter/customers', { ...options, searchParams })
71
+ .json()
72
+ .then((data) => {
73
+ if (client._options.validate) {
74
+ assertValid(schemas.listCustomersResponseWire, data);
75
+ }
76
+ return fromWire(data, schemas.listCustomersResponse);
77
+ });
20
78
  });
21
- return request(() => http(client)
22
- .get('openmeter/customers', { ...options, searchParams })
23
- .json());
24
79
  }
80
+ /**
81
+ * Upsert customer
82
+ *
83
+ * PUT /openmeter/customers/{customerId}
84
+ */
25
85
  export function upsertCustomer(client, req, options) {
26
- const path = encodePath('openmeter/customers/{customerId}', {
27
- customerId: req.customerId,
86
+ return request(() => {
87
+ const path = `openmeter/customers/${(() => {
88
+ if (req.customerId === undefined) {
89
+ throw new Error('missing path parameter: customerId');
90
+ }
91
+ return encodeURIComponent(String(req.customerId));
92
+ })()}`;
93
+ const body = toWire(req.body, schemas.upsertCustomerBody);
94
+ if (client._options.validate) {
95
+ assertValid(schemas.upsertCustomerBodyWire, body);
96
+ }
97
+ return http(client)
98
+ .put(path, { ...options, json: body })
99
+ .json()
100
+ .then((data) => {
101
+ if (client._options.validate) {
102
+ assertValid(schemas.upsertCustomerResponseWire, data);
103
+ }
104
+ return fromWire(data, schemas.upsertCustomerResponse);
105
+ });
28
106
  });
29
- return request(() => http(client)
30
- .put(path, { ...options, json: req.body })
31
- .json());
32
107
  }
108
+ /**
109
+ * Delete customer
110
+ *
111
+ * DELETE /openmeter/customers/{customerId}
112
+ */
33
113
  export function deleteCustomer(client, req, options) {
34
- const path = encodePath('openmeter/customers/{customerId}', {
35
- customerId: req.customerId,
36
- });
37
114
  return request(async () => {
115
+ const path = `openmeter/customers/${(() => {
116
+ if (req.customerId === undefined) {
117
+ throw new Error('missing path parameter: customerId');
118
+ }
119
+ return encodeURIComponent(String(req.customerId));
120
+ })()}`;
38
121
  await http(client).delete(path, options);
39
122
  });
40
123
  }
124
+ /**
125
+ * Get customer billing data
126
+ *
127
+ * GET /openmeter/customers/{customerId}/billing
128
+ */
41
129
  export function getCustomerBilling(client, req, options) {
42
- const path = encodePath('openmeter/customers/{customerId}/billing', {
43
- customerId: req.customerId,
130
+ return request(() => {
131
+ const path = `openmeter/customers/${(() => {
132
+ if (req.customerId === undefined) {
133
+ throw new Error('missing path parameter: customerId');
134
+ }
135
+ return encodeURIComponent(String(req.customerId));
136
+ })()}/billing`;
137
+ return http(client)
138
+ .get(path, options)
139
+ .json()
140
+ .then((data) => {
141
+ if (client._options.validate) {
142
+ assertValid(schemas.getCustomerBillingResponseWire, data);
143
+ }
144
+ return fromWire(data, schemas.getCustomerBillingResponse);
145
+ });
44
146
  });
45
- return request(() => http(client).get(path, options).json());
46
147
  }
148
+ /**
149
+ * Update customer billing data
150
+ *
151
+ * PUT /openmeter/customers/{customerId}/billing
152
+ */
47
153
  export function updateCustomerBilling(client, req, options) {
48
- const path = encodePath('openmeter/customers/{customerId}/billing', {
49
- customerId: req.customerId,
154
+ return request(() => {
155
+ const path = `openmeter/customers/${(() => {
156
+ if (req.customerId === undefined) {
157
+ throw new Error('missing path parameter: customerId');
158
+ }
159
+ return encodeURIComponent(String(req.customerId));
160
+ })()}/billing`;
161
+ const body = toWire(req.body, schemas.updateCustomerBillingBody);
162
+ if (client._options.validate) {
163
+ assertValid(schemas.updateCustomerBillingBodyWire, body);
164
+ }
165
+ return http(client)
166
+ .put(path, { ...options, json: body })
167
+ .json()
168
+ .then((data) => {
169
+ if (client._options.validate) {
170
+ assertValid(schemas.updateCustomerBillingResponseWire, data);
171
+ }
172
+ return fromWire(data, schemas.updateCustomerBillingResponse);
173
+ });
50
174
  });
51
- return request(() => http(client)
52
- .put(path, { ...options, json: req.body })
53
- .json());
54
175
  }
176
+ /**
177
+ * Update customer billing app data
178
+ *
179
+ * PUT /openmeter/customers/{customerId}/billing/app-data
180
+ */
55
181
  export function updateCustomerBillingAppData(client, req, options) {
56
- const path = encodePath('openmeter/customers/{customerId}/billing/app-data', {
57
- customerId: req.customerId,
182
+ return request(() => {
183
+ const path = `openmeter/customers/${(() => {
184
+ if (req.customerId === undefined) {
185
+ throw new Error('missing path parameter: customerId');
186
+ }
187
+ return encodeURIComponent(String(req.customerId));
188
+ })()}/billing/app-data`;
189
+ const body = toWire(req.body, schemas.updateCustomerBillingAppDataBody);
190
+ if (client._options.validate) {
191
+ assertValid(schemas.updateCustomerBillingAppDataBodyWire, body);
192
+ }
193
+ return http(client)
194
+ .put(path, { ...options, json: body })
195
+ .json()
196
+ .then((data) => {
197
+ if (client._options.validate) {
198
+ assertValid(schemas.updateCustomerBillingAppDataResponseWire, data);
199
+ }
200
+ return fromWire(data, schemas.updateCustomerBillingAppDataResponse);
201
+ });
58
202
  });
59
- return request(() => http(client)
60
- .put(path, { ...options, json: req.body })
61
- .json());
62
203
  }
204
+ /**
205
+ * Create Stripe Checkout Session
206
+ *
207
+ * Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout)
208
+ * for the customer.
209
+ *
210
+ * Creates a Checkout Session for collecting payment method information from
211
+ * customers. The session operates in "setup" mode, which collects payment details
212
+ * without charging the customer immediately. The collected payment method can be
213
+ * used for future subscription billing.
214
+ *
215
+ * For hosted checkout sessions, redirect customers to the returned URL. For
216
+ * embedded sessions, use the client_secret to initialize Stripe.js in your
217
+ * application.
218
+ *
219
+ * POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions
220
+ */
63
221
  export function createCustomerStripeCheckoutSession(client, req, options) {
64
- const path = encodePath('openmeter/customers/{customerId}/billing/stripe/checkout-sessions', { customerId: req.customerId });
65
- return request(() => http(client)
66
- .post(path, { ...options, json: req.body })
67
- .json());
222
+ return request(() => {
223
+ const path = `openmeter/customers/${(() => {
224
+ if (req.customerId === undefined) {
225
+ throw new Error('missing path parameter: customerId');
226
+ }
227
+ return encodeURIComponent(String(req.customerId));
228
+ })()}/billing/stripe/checkout-sessions`;
229
+ const body = toWire(req.body, schemas.createCustomerStripeCheckoutSessionBody);
230
+ if (client._options.validate) {
231
+ assertValid(schemas.createCustomerStripeCheckoutSessionBodyWire, body);
232
+ }
233
+ return http(client)
234
+ .post(path, { ...options, json: body })
235
+ .json()
236
+ .then((data) => {
237
+ if (client._options.validate) {
238
+ assertValid(schemas.createCustomerStripeCheckoutSessionResponseWire, data);
239
+ }
240
+ return fromWire(data, schemas.createCustomerStripeCheckoutSessionResponse);
241
+ });
242
+ });
68
243
  }
244
+ /**
245
+ * Create Stripe customer portal session
246
+ *
247
+ * Create Stripe Customer Portal Session.
248
+ *
249
+ * Useful to redirect the customer to the Stripe Customer Portal to manage their
250
+ * payment methods, change their billing address and access their invoice history.
251
+ * Only returns URL if the customer billing profile is linked to a stripe app and
252
+ * customer.
253
+ *
254
+ * POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions
255
+ */
69
256
  export function createCustomerStripePortalSession(client, req, options) {
70
- const path = encodePath('openmeter/customers/{customerId}/billing/stripe/portal-sessions', { customerId: req.customerId });
71
- return request(() => http(client)
72
- .post(path, { ...options, json: req.body })
73
- .json());
257
+ return request(() => {
258
+ const path = `openmeter/customers/${(() => {
259
+ if (req.customerId === undefined) {
260
+ throw new Error('missing path parameter: customerId');
261
+ }
262
+ return encodeURIComponent(String(req.customerId));
263
+ })()}/billing/stripe/portal-sessions`;
264
+ const body = toWire(req.body, schemas.createCustomerStripePortalSessionBody);
265
+ if (client._options.validate) {
266
+ assertValid(schemas.createCustomerStripePortalSessionBodyWire, body);
267
+ }
268
+ return http(client)
269
+ .post(path, { ...options, json: body })
270
+ .json()
271
+ .then((data) => {
272
+ if (client._options.validate) {
273
+ assertValid(schemas.createCustomerStripePortalSessionResponseWire, data);
274
+ }
275
+ return fromWire(data, schemas.createCustomerStripePortalSessionResponse);
276
+ });
277
+ });
74
278
  }
279
+ /**
280
+ * Create a new credit grant
281
+ *
282
+ * Create a new credit grant. A credit grant represents an allocation of prepaid
283
+ * credits to a customer.
284
+ *
285
+ * POST /openmeter/customers/{customerId}/credits/grants
286
+ */
75
287
  export function createCreditGrant(client, req, options) {
76
- const path = encodePath('openmeter/customers/{customerId}/credits/grants', {
77
- customerId: req.customerId,
288
+ return request(() => {
289
+ const path = `openmeter/customers/${(() => {
290
+ if (req.customerId === undefined) {
291
+ throw new Error('missing path parameter: customerId');
292
+ }
293
+ return encodeURIComponent(String(req.customerId));
294
+ })()}/credits/grants`;
295
+ const body = toWire(req.body, schemas.createCreditGrantBody);
296
+ if (client._options.validate) {
297
+ assertValid(schemas.createCreditGrantBodyWire, body);
298
+ }
299
+ return http(client)
300
+ .post(path, { ...options, json: body })
301
+ .json()
302
+ .then((data) => {
303
+ if (client._options.validate) {
304
+ assertValid(schemas.createCreditGrantResponseWire, data);
305
+ }
306
+ return fromWire(data, schemas.createCreditGrantResponse);
307
+ });
78
308
  });
79
- return request(() => http(client)
80
- .post(path, { ...options, json: req.body })
81
- .json());
82
309
  }
310
+ /**
311
+ * Get a credit grant
312
+ *
313
+ * Get a credit grant.
314
+ *
315
+ * GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}
316
+ */
83
317
  export function getCreditGrant(client, req, options) {
84
- const path = encodePath('openmeter/customers/{customerId}/credits/grants/{creditGrantId}', { customerId: req.customerId, creditGrantId: req.creditGrantId });
85
- return request(() => http(client).get(path, options).json());
318
+ return request(() => {
319
+ const path = `openmeter/customers/${(() => {
320
+ if (req.customerId === undefined) {
321
+ throw new Error('missing path parameter: customerId');
322
+ }
323
+ return encodeURIComponent(String(req.customerId));
324
+ })()}/credits/grants/${(() => {
325
+ if (req.creditGrantId === undefined) {
326
+ throw new Error('missing path parameter: creditGrantId');
327
+ }
328
+ return encodeURIComponent(String(req.creditGrantId));
329
+ })()}`;
330
+ return http(client)
331
+ .get(path, options)
332
+ .json()
333
+ .then((data) => {
334
+ if (client._options.validate) {
335
+ assertValid(schemas.getCreditGrantResponseWire, data);
336
+ }
337
+ return fromWire(data, schemas.getCreditGrantResponse);
338
+ });
339
+ });
86
340
  }
341
+ /**
342
+ * List credit grants
343
+ *
344
+ * List credit grants.
345
+ *
346
+ * GET /openmeter/customers/{customerId}/credits/grants
347
+ */
87
348
  export function listCreditGrants(client, req, options) {
88
- const searchParams = toURLSearchParams({
89
- page: req.page,
90
- filter: req.filter,
91
- });
92
- const path = encodePath('openmeter/customers/{customerId}/credits/grants', {
93
- customerId: req.customerId,
349
+ return request(() => {
350
+ const path = `openmeter/customers/${(() => {
351
+ if (req.customerId === undefined) {
352
+ throw new Error('missing path parameter: customerId');
353
+ }
354
+ return encodeURIComponent(String(req.customerId));
355
+ })()}/credits/grants`;
356
+ const query = toWire({
357
+ page: req.page,
358
+ filter: req.filter,
359
+ }, schemas.listCreditGrantsQueryParams);
360
+ if (client._options.validate) {
361
+ assertValid(schemas.listCreditGrantsQueryParamsWire, query);
362
+ }
363
+ const searchParams = toURLSearchParams(query);
364
+ return http(client)
365
+ .get(path, { ...options, searchParams })
366
+ .json()
367
+ .then((data) => {
368
+ if (client._options.validate) {
369
+ assertValid(schemas.listCreditGrantsResponseWire, data);
370
+ }
371
+ return fromWire(data, schemas.listCreditGrantsResponse);
372
+ });
94
373
  });
95
- return request(() => http(client)
96
- .get(path, { ...options, searchParams })
97
- .json());
98
374
  }
375
+ /**
376
+ * Get a customer's credit balance
377
+ *
378
+ * Get a credit balance.
379
+ *
380
+ * GET /openmeter/customers/{customerId}/credits/balance
381
+ */
99
382
  export function getCustomerCreditBalance(client, req, options) {
100
- const searchParams = toURLSearchParams({
101
- timestamp: req.timestamp,
102
- filter: req.filter,
103
- });
104
- const path = encodePath('openmeter/customers/{customerId}/credits/balance', {
105
- customerId: req.customerId,
383
+ return request(() => {
384
+ const path = `openmeter/customers/${(() => {
385
+ if (req.customerId === undefined) {
386
+ throw new Error('missing path parameter: customerId');
387
+ }
388
+ return encodeURIComponent(String(req.customerId));
389
+ })()}/credits/balance`;
390
+ const query = toWire({
391
+ timestamp: req.timestamp,
392
+ filter: req.filter,
393
+ }, schemas.getCustomerCreditBalanceQueryParams);
394
+ if (client._options.validate) {
395
+ assertValid(schemas.getCustomerCreditBalanceQueryParamsWire, query);
396
+ }
397
+ const searchParams = toURLSearchParams(query);
398
+ return http(client)
399
+ .get(path, { ...options, searchParams })
400
+ .json()
401
+ .then((data) => {
402
+ if (client._options.validate) {
403
+ assertValid(schemas.getCustomerCreditBalanceResponseWire, data);
404
+ }
405
+ return fromWire(data, schemas.getCustomerCreditBalanceResponse);
406
+ });
106
407
  });
107
- return request(() => http(client)
108
- .get(path, { ...options, searchParams })
109
- .json());
110
408
  }
409
+ /**
410
+ * Create a credit adjustment
411
+ *
412
+ * A credit adjustment can be used to make manual adjustments to a customer's
413
+ * credit balance.
414
+ *
415
+ * Supported use-cases:
416
+ *
417
+ * - Usage correction
418
+ *
419
+ * POST /openmeter/customers/{customerId}/credits/adjustments
420
+ */
111
421
  export function createCreditAdjustment(client, req, options) {
112
- const path = encodePath('openmeter/customers/{customerId}/credits/adjustments', { customerId: req.customerId });
113
- return request(() => http(client)
114
- .post(path, { ...options, json: req.body })
115
- .json());
422
+ return request(() => {
423
+ const path = `openmeter/customers/${(() => {
424
+ if (req.customerId === undefined) {
425
+ throw new Error('missing path parameter: customerId');
426
+ }
427
+ return encodeURIComponent(String(req.customerId));
428
+ })()}/credits/adjustments`;
429
+ const body = toWire(req.body, schemas.createCreditAdjustmentBody);
430
+ if (client._options.validate) {
431
+ assertValid(schemas.createCreditAdjustmentBodyWire, body);
432
+ }
433
+ return http(client)
434
+ .post(path, { ...options, json: body })
435
+ .json()
436
+ .then((data) => {
437
+ if (client._options.validate) {
438
+ assertValid(schemas.createCreditAdjustmentResponseWire, data);
439
+ }
440
+ return fromWire(data, schemas.createCreditAdjustmentResponse);
441
+ });
442
+ });
443
+ }
444
+ /**
445
+ * Void credit grant
446
+ *
447
+ * Void a credit grant, forfeiting the remaining unused balance.
448
+ *
449
+ * Voiding is a forward-looking, irreversible operation. Credits already consumed
450
+ * by usage remain unaffected — only the remaining balance is forfeited. The grant
451
+ * reads as `voided` status afterwards. Payment state is not adjusted when
452
+ * `payment_adjustment` is `none`, so invoice-backed or externally collected
453
+ * payments may still collect the original amount. Only `active` grants can be
454
+ * voided; voiding a pending, expired, or fully consumed grant returns a conflict.
455
+ * Retrying a successful void is an idempotent success.
456
+ *
457
+ * POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/void
458
+ */
459
+ export function voidCreditGrant(client, req, options) {
460
+ return request(() => {
461
+ const path = `openmeter/customers/${(() => {
462
+ if (req.customerId === undefined) {
463
+ throw new Error('missing path parameter: customerId');
464
+ }
465
+ return encodeURIComponent(String(req.customerId));
466
+ })()}/credits/grants/${(() => {
467
+ if (req.creditGrantId === undefined) {
468
+ throw new Error('missing path parameter: creditGrantId');
469
+ }
470
+ return encodeURIComponent(String(req.creditGrantId));
471
+ })()}/void`;
472
+ const body = toWire(req.body, schemas.voidCreditGrantBody);
473
+ if (client._options.validate) {
474
+ assertValid(schemas.voidCreditGrantBodyWire, body);
475
+ }
476
+ return http(client)
477
+ .post(path, { ...options, json: body })
478
+ .json()
479
+ .then((data) => {
480
+ if (client._options.validate) {
481
+ assertValid(schemas.voidCreditGrantResponseWire, data);
482
+ }
483
+ return fromWire(data, schemas.voidCreditGrantResponse);
484
+ });
485
+ });
116
486
  }
487
+ /**
488
+ * Update credit grant external settlement status
489
+ *
490
+ * Update the payment settlement status of an externally funded credit grant.
491
+ *
492
+ * Use this endpoint to synchronize the payment state of an external payment with
493
+ * the system so that revenue recognition and credit availability work as expected.
494
+ *
495
+ * POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external
496
+ */
497
+ export function updateCreditGrantExternalSettlement(client, req, options) {
498
+ return request(() => {
499
+ const path = `openmeter/customers/${(() => {
500
+ if (req.customerId === undefined) {
501
+ throw new Error('missing path parameter: customerId');
502
+ }
503
+ return encodeURIComponent(String(req.customerId));
504
+ })()}/credits/grants/${(() => {
505
+ if (req.creditGrantId === undefined) {
506
+ throw new Error('missing path parameter: creditGrantId');
507
+ }
508
+ return encodeURIComponent(String(req.creditGrantId));
509
+ })()}/settlement/external`;
510
+ const body = toWire(req.body, schemas.updateCreditGrantExternalSettlementBody);
511
+ if (client._options.validate) {
512
+ assertValid(schemas.updateCreditGrantExternalSettlementBodyWire, body);
513
+ }
514
+ return http(client)
515
+ .post(path, { ...options, json: body })
516
+ .json()
517
+ .then((data) => {
518
+ if (client._options.validate) {
519
+ assertValid(schemas.updateCreditGrantExternalSettlementResponseWire, data);
520
+ }
521
+ return fromWire(data, schemas.updateCreditGrantExternalSettlementResponse);
522
+ });
523
+ });
524
+ }
525
+ /**
526
+ * List credit transactions
527
+ *
528
+ * List credit transactions for a customer.
529
+ *
530
+ * Returns an immutable, chronological record of credit movements: funded credits
531
+ * and consumed credits. Transactions are returned in reverse chronological order
532
+ * by default.
533
+ *
534
+ * GET /openmeter/customers/{customerId}/credits/transactions
535
+ */
117
536
  export function listCreditTransactions(client, req, options) {
118
- const searchParams = toURLSearchParams({
119
- page: req.page,
120
- filter: req.filter,
537
+ return request(() => {
538
+ const path = `openmeter/customers/${(() => {
539
+ if (req.customerId === undefined) {
540
+ throw new Error('missing path parameter: customerId');
541
+ }
542
+ return encodeURIComponent(String(req.customerId));
543
+ })()}/credits/transactions`;
544
+ const query = toWire({
545
+ page: req.page,
546
+ filter: req.filter,
547
+ }, schemas.listCreditTransactionsQueryParams);
548
+ if (client._options.validate) {
549
+ assertValid(schemas.listCreditTransactionsQueryParamsWire, query);
550
+ }
551
+ const searchParams = toURLSearchParams(query);
552
+ return http(client)
553
+ .get(path, { ...options, searchParams })
554
+ .json()
555
+ .then((data) => {
556
+ if (client._options.validate) {
557
+ assertValid(schemas.listCreditTransactionsResponseWire, data);
558
+ }
559
+ return fromWire(data, schemas.listCreditTransactionsResponse);
560
+ });
121
561
  });
122
- const path = encodePath('openmeter/customers/{customerId}/credits/transactions', { customerId: req.customerId });
123
- return request(() => http(client)
124
- .get(path, { ...options, searchParams })
125
- .json());
126
562
  }
563
+ /**
564
+ * List customer charges
565
+ *
566
+ * List customer charges.
567
+ *
568
+ * Returns the customer's charges that are represented as either flat fee or
569
+ * usage-based charges.
570
+ *
571
+ * GET /openmeter/customers/{customerId}/charges
572
+ */
127
573
  export function listCustomerCharges(client, req, options) {
128
- const searchParams = toURLSearchParams({
129
- page: req.page,
130
- sort: encodeSort(req.sort),
131
- filter: req.filter,
132
- expand: req.expand,
574
+ return request(() => {
575
+ const path = `openmeter/customers/${(() => {
576
+ if (req.customerId === undefined) {
577
+ throw new Error('missing path parameter: customerId');
578
+ }
579
+ return encodeURIComponent(String(req.customerId));
580
+ })()}/charges`;
581
+ const query = toWire({
582
+ page: req.page,
583
+ sort: encodeSort(req.sort, toSnakeCase),
584
+ filter: req.filter,
585
+ expand: req.expand,
586
+ }, schemas.listCustomerChargesQueryParams);
587
+ if (client._options.validate) {
588
+ assertValid(schemas.listCustomerChargesQueryParamsWire, query);
589
+ }
590
+ const searchParams = toURLSearchParams(query);
591
+ return http(client)
592
+ .get(path, { ...options, searchParams })
593
+ .json()
594
+ .then((data) => {
595
+ if (client._options.validate) {
596
+ assertValid(schemas.listCustomerChargesResponseWire, data);
597
+ }
598
+ return fromWire(data, schemas.listCustomerChargesResponse);
599
+ });
133
600
  });
134
- const path = encodePath('openmeter/customers/{customerId}/charges', {
135
- customerId: req.customerId,
601
+ }
602
+ /**
603
+ * Create customer charge
604
+ *
605
+ * Create customer charge.
606
+ *
607
+ * POST /openmeter/customers/{customerId}/charges
608
+ */
609
+ export function createCustomerCharges(client, req, options) {
610
+ return request(() => {
611
+ const path = `openmeter/customers/${(() => {
612
+ if (req.customerId === undefined) {
613
+ throw new Error('missing path parameter: customerId');
614
+ }
615
+ return encodeURIComponent(String(req.customerId));
616
+ })()}/charges`;
617
+ const body = toWire(req.body, schemas.createCustomerChargesBody);
618
+ if (client._options.validate) {
619
+ assertValid(schemas.createCustomerChargesBodyWire, body);
620
+ }
621
+ return http(client)
622
+ .post(path, { ...options, json: body })
623
+ .json()
624
+ .then((data) => {
625
+ if (client._options.validate) {
626
+ assertValid(schemas.createCustomerChargesResponseWire, data);
627
+ }
628
+ return fromWire(data, schemas.createCustomerChargesResponse);
629
+ });
136
630
  });
137
- return request(() => http(client)
138
- .get(path, { ...options, searchParams })
139
- .json());
140
631
  }
141
- //# sourceMappingURL=customers.js.map