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

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 (62) hide show
  1. package/README.md +49 -30
  2. package/dist/funcs/addons.js +111 -28
  3. package/dist/funcs/apps.js +37 -8
  4. package/dist/funcs/billing.js +79 -16
  5. package/dist/funcs/currencies.js +82 -22
  6. package/dist/funcs/customers.d.ts +3 -1
  7. package/dist/funcs/customers.js +390 -91
  8. package/dist/funcs/defaults.js +24 -4
  9. package/dist/funcs/entitlements.js +19 -5
  10. package/dist/funcs/events.js +26 -8
  11. package/dist/funcs/features.js +99 -27
  12. package/dist/funcs/governance.js +27 -9
  13. package/dist/funcs/index.d.ts +1 -0
  14. package/dist/funcs/index.js +1 -0
  15. package/dist/funcs/invoices.d.ts +8 -0
  16. package/dist/funcs/invoices.js +81 -0
  17. package/dist/funcs/llmCost.js +77 -23
  18. package/dist/funcs/meters.d.ts +2 -1
  19. package/dist/funcs/meters.js +118 -27
  20. package/dist/funcs/planAddons.js +103 -28
  21. package/dist/funcs/plans.js +113 -24
  22. package/dist/funcs/subscriptions.d.ts +2 -1
  23. package/dist/funcs/subscriptions.js +178 -39
  24. package/dist/funcs/tax.js +78 -21
  25. package/dist/index.d.ts +5 -1
  26. package/dist/index.js +2 -0
  27. package/dist/lib/config.d.ts +9 -0
  28. package/dist/lib/encodings.d.ts +1 -1
  29. package/dist/lib/encodings.js +5 -4
  30. package/dist/lib/wire.d.ts +18 -0
  31. package/dist/lib/wire.js +312 -0
  32. package/dist/models/operations/addons.d.ts +17 -5
  33. package/dist/models/operations/apps.d.ts +2 -1
  34. package/dist/models/operations/billing.d.ts +5 -4
  35. package/dist/models/operations/currencies.d.ts +27 -9
  36. package/dist/models/operations/customers.d.ts +83 -32
  37. package/dist/models/operations/defaults.d.ts +2 -1
  38. package/dist/models/operations/events.d.ts +20 -4
  39. package/dist/models/operations/features.d.ts +24 -8
  40. package/dist/models/operations/governance.d.ts +3 -2
  41. package/dist/models/operations/invoices.d.ts +48 -0
  42. package/dist/models/operations/invoices.js +2 -0
  43. package/dist/models/operations/llmCost.d.ts +16 -4
  44. package/dist/models/operations/meters.d.ts +29 -8
  45. package/dist/models/operations/planAddons.d.ts +7 -6
  46. package/dist/models/operations/plans.d.ts +14 -5
  47. package/dist/models/operations/subscriptions.d.ts +36 -10
  48. package/dist/models/operations/tax.d.ts +6 -5
  49. package/dist/models/schemas.d.ts +27210 -3012
  50. package/dist/models/schemas.js +6212 -492
  51. package/dist/models/types.d.ts +4240 -977
  52. package/dist/sdk/customers.d.ts +3 -1
  53. package/dist/sdk/customers.js +7 -1
  54. package/dist/sdk/invoices.d.ts +12 -0
  55. package/dist/sdk/invoices.js +21 -0
  56. package/dist/sdk/meters.d.ts +2 -1
  57. package/dist/sdk/meters.js +4 -1
  58. package/dist/sdk/sdk.d.ts +3 -0
  59. package/dist/sdk/sdk.js +5 -0
  60. package/dist/sdk/subscriptions.d.ts +2 -1
  61. package/dist/sdk/subscriptions.js +4 -1
  62. package/package.json +4 -3
@@ -1,35 +1,95 @@
1
1
  import { http } from '../core.js';
2
2
  import { request } from '../lib/request.js';
3
- import { encodePath, toURLSearchParams, encodeSort } from '../lib/encodings.js';
3
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js';
4
+ import { toWire, fromWire, assertValid, toSnakeCase } from '../lib/wire.js';
5
+ import * as schemas from '../models/schemas.js';
4
6
  export function listCurrencies(client, req = {}, options) {
5
- const searchParams = toURLSearchParams({
6
- page: req.page,
7
- sort: encodeSort(req.sort),
8
- filter: req.filter,
7
+ return request(() => {
8
+ const query = toWire({
9
+ page: req.page,
10
+ sort: encodeSort(req.sort, toSnakeCase),
11
+ filter: req.filter,
12
+ }, schemas.listCurrenciesQueryParams);
13
+ if (client._options.validate) {
14
+ assertValid(schemas.listCurrenciesQueryParamsWire, query);
15
+ }
16
+ const searchParams = toURLSearchParams(query);
17
+ return http(client)
18
+ .get('openmeter/currencies', { ...options, searchParams })
19
+ .json()
20
+ .then((data) => {
21
+ if (client._options.validate) {
22
+ assertValid(schemas.listCurrenciesResponseWire, data);
23
+ }
24
+ return fromWire(data, schemas.listCurrenciesResponse);
25
+ });
9
26
  });
10
- return request(() => http(client)
11
- .get('openmeter/currencies', { ...options, searchParams })
12
- .json());
13
27
  }
14
28
  export function createCustomCurrency(client, req, options) {
15
- return request(() => http(client)
16
- .post('openmeter/currencies/custom', { ...options, json: req })
17
- .json());
29
+ return request(() => {
30
+ const body = toWire(req, schemas.createCustomCurrencyBody);
31
+ if (client._options.validate) {
32
+ assertValid(schemas.createCustomCurrencyBodyWire, body);
33
+ }
34
+ return http(client)
35
+ .post('openmeter/currencies/custom', { ...options, json: body })
36
+ .json()
37
+ .then((data) => {
38
+ if (client._options.validate) {
39
+ assertValid(schemas.createCustomCurrencyResponseWire, data);
40
+ }
41
+ return fromWire(data, schemas.createCustomCurrencyResponse);
42
+ });
43
+ });
18
44
  }
19
45
  export function listCostBases(client, req, options) {
20
- const searchParams = toURLSearchParams({
21
- filter: req.filter,
22
- page: req.page,
46
+ return request(() => {
47
+ const path = `openmeter/currencies/custom/${(() => {
48
+ if (req.currencyId === undefined) {
49
+ throw new Error('missing path parameter: currencyId');
50
+ }
51
+ return encodeURIComponent(String(req.currencyId));
52
+ })()}/cost-bases`;
53
+ const query = toWire({
54
+ filter: req.filter,
55
+ page: req.page,
56
+ }, schemas.listCostBasesQueryParams);
57
+ if (client._options.validate) {
58
+ assertValid(schemas.listCostBasesQueryParamsWire, query);
59
+ }
60
+ const searchParams = toURLSearchParams(query);
61
+ return http(client)
62
+ .get(path, { ...options, searchParams })
63
+ .json()
64
+ .then((data) => {
65
+ if (client._options.validate) {
66
+ assertValid(schemas.listCostBasesResponseWire, data);
67
+ }
68
+ return fromWire(data, schemas.listCostBasesResponse);
69
+ });
23
70
  });
24
- const path = encodePath('openmeter/currencies/custom/{currencyId}/cost-bases', { currencyId: req.currencyId });
25
- return request(() => http(client)
26
- .get(path, { ...options, searchParams })
27
- .json());
28
71
  }
29
72
  export function createCostBasis(client, req, options) {
30
- const path = encodePath('openmeter/currencies/custom/{currencyId}/cost-bases', { currencyId: req.currencyId });
31
- return request(() => http(client)
32
- .post(path, { ...options, json: req.body })
33
- .json());
73
+ return request(() => {
74
+ const path = `openmeter/currencies/custom/${(() => {
75
+ if (req.currencyId === undefined) {
76
+ throw new Error('missing path parameter: currencyId');
77
+ }
78
+ return encodeURIComponent(String(req.currencyId));
79
+ })()}/cost-bases`;
80
+ const body = toWire(req.body, schemas.createCostBasisBody);
81
+ if (client._options.validate) {
82
+ assertValid(schemas.createCostBasisBodyWire, body);
83
+ }
84
+ return http(client)
85
+ .post(path, { ...options, json: body })
86
+ .json()
87
+ .then((data) => {
88
+ if (client._options.validate) {
89
+ assertValid(schemas.createCostBasisResponseWire, data);
90
+ }
91
+ return fromWire(data, schemas.createCostBasisResponse);
92
+ });
93
+ });
34
94
  }
35
95
  //# sourceMappingURL=currencies.js.map
@@ -1,6 +1,6 @@
1
1
  import { type Client } from '../core.js';
2
2
  import { type Result, type RequestOptions } from '../lib/types.js';
3
- import type { CreateCustomerRequest, CreateCustomerResponse, GetCustomerRequest, GetCustomerResponse, ListCustomersRequest, ListCustomersResponse, UpsertCustomerRequest, UpsertCustomerResponse, DeleteCustomerRequest, DeleteCustomerResponse, GetCustomerBillingRequest, GetCustomerBillingResponse, UpdateCustomerBillingRequest, UpdateCustomerBillingResponse, UpdateCustomerBillingAppDataRequest, UpdateCustomerBillingAppDataResponse, CreateCustomerStripeCheckoutSessionRequest, CreateCustomerStripeCheckoutSessionResponse, CreateCustomerStripePortalSessionRequest, CreateCustomerStripePortalSessionResponse, CreateCreditGrantRequest, CreateCreditGrantResponse, GetCreditGrantRequest, GetCreditGrantResponse, ListCreditGrantsRequest, ListCreditGrantsResponse, GetCustomerCreditBalanceRequest, GetCustomerCreditBalanceResponse, CreateCreditAdjustmentRequest, CreateCreditAdjustmentResponse, ListCreditTransactionsRequest, ListCreditTransactionsResponse, ListCustomerChargesRequest, ListCustomerChargesResponse } from '../models/operations/customers.js';
3
+ import type { CreateCustomerRequest, CreateCustomerResponse, GetCustomerRequest, GetCustomerResponse, ListCustomersRequest, ListCustomersResponse, UpsertCustomerRequest, UpsertCustomerResponse, DeleteCustomerRequest, DeleteCustomerResponse, GetCustomerBillingRequest, GetCustomerBillingResponse, UpdateCustomerBillingRequest, UpdateCustomerBillingResponse, UpdateCustomerBillingAppDataRequest, UpdateCustomerBillingAppDataResponse, CreateCustomerStripeCheckoutSessionRequest, CreateCustomerStripeCheckoutSessionResponse, CreateCustomerStripePortalSessionRequest, CreateCustomerStripePortalSessionResponse, CreateCreditGrantRequest, CreateCreditGrantResponse, GetCreditGrantRequest, GetCreditGrantResponse, ListCreditGrantsRequest, ListCreditGrantsResponse, GetCustomerCreditBalanceRequest, GetCustomerCreditBalanceResponse, CreateCreditAdjustmentRequest, CreateCreditAdjustmentResponse, UpdateCreditGrantExternalSettlementRequest, UpdateCreditGrantExternalSettlementResponse, ListCreditTransactionsRequest, ListCreditTransactionsResponse, ListCustomerChargesRequest, ListCustomerChargesResponse, CreateCustomerChargesRequest, CreateCustomerChargesResponse } from '../models/operations/customers.js';
4
4
  export declare function createCustomer(client: Client, req: CreateCustomerRequest, options?: RequestOptions): Promise<Result<CreateCustomerResponse>>;
5
5
  export declare function getCustomer(client: Client, req: GetCustomerRequest, options?: RequestOptions): Promise<Result<GetCustomerResponse>>;
6
6
  export declare function listCustomers(client: Client, req?: ListCustomersRequest, options?: RequestOptions): Promise<Result<ListCustomersResponse>>;
@@ -16,6 +16,8 @@ export declare function getCreditGrant(client: Client, req: GetCreditGrantReques
16
16
  export declare function listCreditGrants(client: Client, req: ListCreditGrantsRequest, options?: RequestOptions): Promise<Result<ListCreditGrantsResponse>>;
17
17
  export declare function getCustomerCreditBalance(client: Client, req: GetCustomerCreditBalanceRequest, options?: RequestOptions): Promise<Result<GetCustomerCreditBalanceResponse>>;
18
18
  export declare function createCreditAdjustment(client: Client, req: CreateCreditAdjustmentRequest, options?: RequestOptions): Promise<Result<CreateCreditAdjustmentResponse>>;
19
+ export declare function updateCreditGrantExternalSettlement(client: Client, req: UpdateCreditGrantExternalSettlementRequest, options?: RequestOptions): Promise<Result<UpdateCreditGrantExternalSettlementResponse>>;
19
20
  export declare function listCreditTransactions(client: Client, req: ListCreditTransactionsRequest, options?: RequestOptions): Promise<Result<ListCreditTransactionsResponse>>;
20
21
  export declare function listCustomerCharges(client: Client, req: ListCustomerChargesRequest, options?: RequestOptions): Promise<Result<ListCustomerChargesResponse>>;
22
+ export declare function createCustomerCharges(client: Client, req: CreateCustomerChargesRequest, options?: RequestOptions): Promise<Result<CreateCustomerChargesResponse>>;
21
23
  //# sourceMappingURL=customers.d.ts.map
@@ -1,141 +1,440 @@
1
1
  import { http } from '../core.js';
2
2
  import { request } from '../lib/request.js';
3
- import { encodePath, toURLSearchParams, encodeSort } from '../lib/encodings.js';
3
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js';
4
+ import { toWire, fromWire, assertValid, toSnakeCase } from '../lib/wire.js';
5
+ import * as schemas from '../models/schemas.js';
4
6
  export function createCustomer(client, req, options) {
5
- return request(() => http(client)
6
- .post('openmeter/customers', { ...options, json: req })
7
- .json());
7
+ return request(() => {
8
+ const body = toWire(req, schemas.createCustomerBody);
9
+ if (client._options.validate) {
10
+ assertValid(schemas.createCustomerBodyWire, body);
11
+ }
12
+ return http(client)
13
+ .post('openmeter/customers', { ...options, json: body })
14
+ .json()
15
+ .then((data) => {
16
+ if (client._options.validate) {
17
+ assertValid(schemas.createCustomerResponseWire, data);
18
+ }
19
+ return fromWire(data, schemas.createCustomerResponse);
20
+ });
21
+ });
8
22
  }
9
23
  export function getCustomer(client, req, options) {
10
- const path = encodePath('openmeter/customers/{customerId}', {
11
- customerId: req.customerId,
24
+ return request(() => {
25
+ const path = `openmeter/customers/${(() => {
26
+ if (req.customerId === undefined) {
27
+ throw new Error('missing path parameter: customerId');
28
+ }
29
+ return encodeURIComponent(String(req.customerId));
30
+ })()}`;
31
+ return http(client)
32
+ .get(path, options)
33
+ .json()
34
+ .then((data) => {
35
+ if (client._options.validate) {
36
+ assertValid(schemas.getCustomerResponseWire, data);
37
+ }
38
+ return fromWire(data, schemas.getCustomerResponse);
39
+ });
12
40
  });
13
- return request(() => http(client).get(path, options).json());
14
41
  }
15
42
  export function listCustomers(client, req = {}, options) {
16
- const searchParams = toURLSearchParams({
17
- page: req.page,
18
- sort: encodeSort(req.sort),
19
- filter: req.filter,
43
+ return request(() => {
44
+ const query = toWire({
45
+ page: req.page,
46
+ sort: encodeSort(req.sort, toSnakeCase),
47
+ filter: req.filter,
48
+ }, schemas.listCustomersQueryParams);
49
+ if (client._options.validate) {
50
+ assertValid(schemas.listCustomersQueryParamsWire, query);
51
+ }
52
+ const searchParams = toURLSearchParams(query);
53
+ return http(client)
54
+ .get('openmeter/customers', { ...options, searchParams })
55
+ .json()
56
+ .then((data) => {
57
+ if (client._options.validate) {
58
+ assertValid(schemas.listCustomersResponseWire, data);
59
+ }
60
+ return fromWire(data, schemas.listCustomersResponse);
61
+ });
20
62
  });
21
- return request(() => http(client)
22
- .get('openmeter/customers', { ...options, searchParams })
23
- .json());
24
63
  }
25
64
  export function upsertCustomer(client, req, options) {
26
- const path = encodePath('openmeter/customers/{customerId}', {
27
- customerId: req.customerId,
65
+ return request(() => {
66
+ const path = `openmeter/customers/${(() => {
67
+ if (req.customerId === undefined) {
68
+ throw new Error('missing path parameter: customerId');
69
+ }
70
+ return encodeURIComponent(String(req.customerId));
71
+ })()}`;
72
+ const body = toWire(req.body, schemas.upsertCustomerBody);
73
+ if (client._options.validate) {
74
+ assertValid(schemas.upsertCustomerBodyWire, body);
75
+ }
76
+ return http(client)
77
+ .put(path, { ...options, json: body })
78
+ .json()
79
+ .then((data) => {
80
+ if (client._options.validate) {
81
+ assertValid(schemas.upsertCustomerResponseWire, data);
82
+ }
83
+ return fromWire(data, schemas.upsertCustomerResponse);
84
+ });
28
85
  });
29
- return request(() => http(client)
30
- .put(path, { ...options, json: req.body })
31
- .json());
32
86
  }
33
87
  export function deleteCustomer(client, req, options) {
34
- const path = encodePath('openmeter/customers/{customerId}', {
35
- customerId: req.customerId,
36
- });
37
88
  return request(async () => {
89
+ const path = `openmeter/customers/${(() => {
90
+ if (req.customerId === undefined) {
91
+ throw new Error('missing path parameter: customerId');
92
+ }
93
+ return encodeURIComponent(String(req.customerId));
94
+ })()}`;
38
95
  await http(client).delete(path, options);
39
96
  });
40
97
  }
41
98
  export function getCustomerBilling(client, req, options) {
42
- const path = encodePath('openmeter/customers/{customerId}/billing', {
43
- customerId: req.customerId,
99
+ return request(() => {
100
+ const path = `openmeter/customers/${(() => {
101
+ if (req.customerId === undefined) {
102
+ throw new Error('missing path parameter: customerId');
103
+ }
104
+ return encodeURIComponent(String(req.customerId));
105
+ })()}/billing`;
106
+ return http(client)
107
+ .get(path, options)
108
+ .json()
109
+ .then((data) => {
110
+ if (client._options.validate) {
111
+ assertValid(schemas.getCustomerBillingResponseWire, data);
112
+ }
113
+ return fromWire(data, schemas.getCustomerBillingResponse);
114
+ });
44
115
  });
45
- return request(() => http(client).get(path, options).json());
46
116
  }
47
117
  export function updateCustomerBilling(client, req, options) {
48
- const path = encodePath('openmeter/customers/{customerId}/billing', {
49
- customerId: req.customerId,
118
+ return request(() => {
119
+ const path = `openmeter/customers/${(() => {
120
+ if (req.customerId === undefined) {
121
+ throw new Error('missing path parameter: customerId');
122
+ }
123
+ return encodeURIComponent(String(req.customerId));
124
+ })()}/billing`;
125
+ const body = toWire(req.body, schemas.updateCustomerBillingBody);
126
+ if (client._options.validate) {
127
+ assertValid(schemas.updateCustomerBillingBodyWire, body);
128
+ }
129
+ return http(client)
130
+ .put(path, { ...options, json: body })
131
+ .json()
132
+ .then((data) => {
133
+ if (client._options.validate) {
134
+ assertValid(schemas.updateCustomerBillingResponseWire, data);
135
+ }
136
+ return fromWire(data, schemas.updateCustomerBillingResponse);
137
+ });
50
138
  });
51
- return request(() => http(client)
52
- .put(path, { ...options, json: req.body })
53
- .json());
54
139
  }
55
140
  export function updateCustomerBillingAppData(client, req, options) {
56
- const path = encodePath('openmeter/customers/{customerId}/billing/app-data', {
57
- customerId: req.customerId,
141
+ return request(() => {
142
+ const path = `openmeter/customers/${(() => {
143
+ if (req.customerId === undefined) {
144
+ throw new Error('missing path parameter: customerId');
145
+ }
146
+ return encodeURIComponent(String(req.customerId));
147
+ })()}/billing/app-data`;
148
+ const body = toWire(req.body, schemas.updateCustomerBillingAppDataBody);
149
+ if (client._options.validate) {
150
+ assertValid(schemas.updateCustomerBillingAppDataBodyWire, body);
151
+ }
152
+ return http(client)
153
+ .put(path, { ...options, json: body })
154
+ .json()
155
+ .then((data) => {
156
+ if (client._options.validate) {
157
+ assertValid(schemas.updateCustomerBillingAppDataResponseWire, data);
158
+ }
159
+ return fromWire(data, schemas.updateCustomerBillingAppDataResponse);
160
+ });
58
161
  });
59
- return request(() => http(client)
60
- .put(path, { ...options, json: req.body })
61
- .json());
62
162
  }
63
163
  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());
164
+ return request(() => {
165
+ const path = `openmeter/customers/${(() => {
166
+ if (req.customerId === undefined) {
167
+ throw new Error('missing path parameter: customerId');
168
+ }
169
+ return encodeURIComponent(String(req.customerId));
170
+ })()}/billing/stripe/checkout-sessions`;
171
+ const body = toWire(req.body, schemas.createCustomerStripeCheckoutSessionBody);
172
+ if (client._options.validate) {
173
+ assertValid(schemas.createCustomerStripeCheckoutSessionBodyWire, body);
174
+ }
175
+ return http(client)
176
+ .post(path, { ...options, json: body })
177
+ .json()
178
+ .then((data) => {
179
+ if (client._options.validate) {
180
+ assertValid(schemas.createCustomerStripeCheckoutSessionResponseWire, data);
181
+ }
182
+ return fromWire(data, schemas.createCustomerStripeCheckoutSessionResponse);
183
+ });
184
+ });
68
185
  }
69
186
  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());
187
+ return request(() => {
188
+ const path = `openmeter/customers/${(() => {
189
+ if (req.customerId === undefined) {
190
+ throw new Error('missing path parameter: customerId');
191
+ }
192
+ return encodeURIComponent(String(req.customerId));
193
+ })()}/billing/stripe/portal-sessions`;
194
+ const body = toWire(req.body, schemas.createCustomerStripePortalSessionBody);
195
+ if (client._options.validate) {
196
+ assertValid(schemas.createCustomerStripePortalSessionBodyWire, body);
197
+ }
198
+ return http(client)
199
+ .post(path, { ...options, json: body })
200
+ .json()
201
+ .then((data) => {
202
+ if (client._options.validate) {
203
+ assertValid(schemas.createCustomerStripePortalSessionResponseWire, data);
204
+ }
205
+ return fromWire(data, schemas.createCustomerStripePortalSessionResponse);
206
+ });
207
+ });
74
208
  }
75
209
  export function createCreditGrant(client, req, options) {
76
- const path = encodePath('openmeter/customers/{customerId}/credits/grants', {
77
- customerId: req.customerId,
210
+ return request(() => {
211
+ const path = `openmeter/customers/${(() => {
212
+ if (req.customerId === undefined) {
213
+ throw new Error('missing path parameter: customerId');
214
+ }
215
+ return encodeURIComponent(String(req.customerId));
216
+ })()}/credits/grants`;
217
+ const body = toWire(req.body, schemas.createCreditGrantBody);
218
+ if (client._options.validate) {
219
+ assertValid(schemas.createCreditGrantBodyWire, body);
220
+ }
221
+ return http(client)
222
+ .post(path, { ...options, json: body })
223
+ .json()
224
+ .then((data) => {
225
+ if (client._options.validate) {
226
+ assertValid(schemas.createCreditGrantResponseWire, data);
227
+ }
228
+ return fromWire(data, schemas.createCreditGrantResponse);
229
+ });
78
230
  });
79
- return request(() => http(client)
80
- .post(path, { ...options, json: req.body })
81
- .json());
82
231
  }
83
232
  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());
233
+ return request(() => {
234
+ const path = `openmeter/customers/${(() => {
235
+ if (req.customerId === undefined) {
236
+ throw new Error('missing path parameter: customerId');
237
+ }
238
+ return encodeURIComponent(String(req.customerId));
239
+ })()}/credits/grants/${(() => {
240
+ if (req.creditGrantId === undefined) {
241
+ throw new Error('missing path parameter: creditGrantId');
242
+ }
243
+ return encodeURIComponent(String(req.creditGrantId));
244
+ })()}`;
245
+ return http(client)
246
+ .get(path, options)
247
+ .json()
248
+ .then((data) => {
249
+ if (client._options.validate) {
250
+ assertValid(schemas.getCreditGrantResponseWire, data);
251
+ }
252
+ return fromWire(data, schemas.getCreditGrantResponse);
253
+ });
254
+ });
86
255
  }
87
256
  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,
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
+ })()}/credits/grants`;
264
+ const query = toWire({
265
+ page: req.page,
266
+ filter: req.filter,
267
+ }, schemas.listCreditGrantsQueryParams);
268
+ if (client._options.validate) {
269
+ assertValid(schemas.listCreditGrantsQueryParamsWire, query);
270
+ }
271
+ const searchParams = toURLSearchParams(query);
272
+ return http(client)
273
+ .get(path, { ...options, searchParams })
274
+ .json()
275
+ .then((data) => {
276
+ if (client._options.validate) {
277
+ assertValid(schemas.listCreditGrantsResponseWire, data);
278
+ }
279
+ return fromWire(data, schemas.listCreditGrantsResponse);
280
+ });
94
281
  });
95
- return request(() => http(client)
96
- .get(path, { ...options, searchParams })
97
- .json());
98
282
  }
99
283
  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,
284
+ return request(() => {
285
+ const path = `openmeter/customers/${(() => {
286
+ if (req.customerId === undefined) {
287
+ throw new Error('missing path parameter: customerId');
288
+ }
289
+ return encodeURIComponent(String(req.customerId));
290
+ })()}/credits/balance`;
291
+ const query = toWire({
292
+ timestamp: req.timestamp,
293
+ filter: req.filter,
294
+ }, schemas.getCustomerCreditBalanceQueryParams);
295
+ if (client._options.validate) {
296
+ assertValid(schemas.getCustomerCreditBalanceQueryParamsWire, query);
297
+ }
298
+ const searchParams = toURLSearchParams(query);
299
+ return http(client)
300
+ .get(path, { ...options, searchParams })
301
+ .json()
302
+ .then((data) => {
303
+ if (client._options.validate) {
304
+ assertValid(schemas.getCustomerCreditBalanceResponseWire, data);
305
+ }
306
+ return fromWire(data, schemas.getCustomerCreditBalanceResponse);
307
+ });
106
308
  });
107
- return request(() => http(client)
108
- .get(path, { ...options, searchParams })
109
- .json());
110
309
  }
111
310
  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());
311
+ return request(() => {
312
+ const path = `openmeter/customers/${(() => {
313
+ if (req.customerId === undefined) {
314
+ throw new Error('missing path parameter: customerId');
315
+ }
316
+ return encodeURIComponent(String(req.customerId));
317
+ })()}/credits/adjustments`;
318
+ const body = toWire(req.body, schemas.createCreditAdjustmentBody);
319
+ if (client._options.validate) {
320
+ assertValid(schemas.createCreditAdjustmentBodyWire, body);
321
+ }
322
+ return http(client)
323
+ .post(path, { ...options, json: body })
324
+ .json()
325
+ .then((data) => {
326
+ if (client._options.validate) {
327
+ assertValid(schemas.createCreditAdjustmentResponseWire, data);
328
+ }
329
+ return fromWire(data, schemas.createCreditAdjustmentResponse);
330
+ });
331
+ });
332
+ }
333
+ export function updateCreditGrantExternalSettlement(client, req, options) {
334
+ return request(() => {
335
+ const path = `openmeter/customers/${(() => {
336
+ if (req.customerId === undefined) {
337
+ throw new Error('missing path parameter: customerId');
338
+ }
339
+ return encodeURIComponent(String(req.customerId));
340
+ })()}/credits/grants/${(() => {
341
+ if (req.creditGrantId === undefined) {
342
+ throw new Error('missing path parameter: creditGrantId');
343
+ }
344
+ return encodeURIComponent(String(req.creditGrantId));
345
+ })()}/settlement/external`;
346
+ const body = toWire(req.body, schemas.updateCreditGrantExternalSettlementBody);
347
+ if (client._options.validate) {
348
+ assertValid(schemas.updateCreditGrantExternalSettlementBodyWire, body);
349
+ }
350
+ return http(client)
351
+ .post(path, { ...options, json: body })
352
+ .json()
353
+ .then((data) => {
354
+ if (client._options.validate) {
355
+ assertValid(schemas.updateCreditGrantExternalSettlementResponseWire, data);
356
+ }
357
+ return fromWire(data, schemas.updateCreditGrantExternalSettlementResponse);
358
+ });
359
+ });
116
360
  }
117
361
  export function listCreditTransactions(client, req, options) {
118
- const searchParams = toURLSearchParams({
119
- page: req.page,
120
- filter: req.filter,
362
+ return request(() => {
363
+ const path = `openmeter/customers/${(() => {
364
+ if (req.customerId === undefined) {
365
+ throw new Error('missing path parameter: customerId');
366
+ }
367
+ return encodeURIComponent(String(req.customerId));
368
+ })()}/credits/transactions`;
369
+ const query = toWire({
370
+ page: req.page,
371
+ filter: req.filter,
372
+ }, schemas.listCreditTransactionsQueryParams);
373
+ if (client._options.validate) {
374
+ assertValid(schemas.listCreditTransactionsQueryParamsWire, query);
375
+ }
376
+ const searchParams = toURLSearchParams(query);
377
+ return http(client)
378
+ .get(path, { ...options, searchParams })
379
+ .json()
380
+ .then((data) => {
381
+ if (client._options.validate) {
382
+ assertValid(schemas.listCreditTransactionsResponseWire, data);
383
+ }
384
+ return fromWire(data, schemas.listCreditTransactionsResponse);
385
+ });
121
386
  });
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
387
  }
127
388
  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,
133
- });
134
- const path = encodePath('openmeter/customers/{customerId}/charges', {
135
- customerId: req.customerId,
136
- });
137
- return request(() => http(client)
138
- .get(path, { ...options, searchParams })
139
- .json());
389
+ return request(() => {
390
+ const path = `openmeter/customers/${(() => {
391
+ if (req.customerId === undefined) {
392
+ throw new Error('missing path parameter: customerId');
393
+ }
394
+ return encodeURIComponent(String(req.customerId));
395
+ })()}/charges`;
396
+ const query = toWire({
397
+ page: req.page,
398
+ sort: encodeSort(req.sort, toSnakeCase),
399
+ filter: req.filter,
400
+ expand: req.expand,
401
+ }, schemas.listCustomerChargesQueryParams);
402
+ if (client._options.validate) {
403
+ assertValid(schemas.listCustomerChargesQueryParamsWire, query);
404
+ }
405
+ const searchParams = toURLSearchParams(query);
406
+ return http(client)
407
+ .get(path, { ...options, searchParams })
408
+ .json()
409
+ .then((data) => {
410
+ if (client._options.validate) {
411
+ assertValid(schemas.listCustomerChargesResponseWire, data);
412
+ }
413
+ return fromWire(data, schemas.listCustomerChargesResponse);
414
+ });
415
+ });
416
+ }
417
+ export function createCustomerCharges(client, req, options) {
418
+ return request(() => {
419
+ const path = `openmeter/customers/${(() => {
420
+ if (req.customerId === undefined) {
421
+ throw new Error('missing path parameter: customerId');
422
+ }
423
+ return encodeURIComponent(String(req.customerId));
424
+ })()}/charges`;
425
+ const body = toWire(req.body, schemas.createCustomerChargesBody);
426
+ if (client._options.validate) {
427
+ assertValid(schemas.createCustomerChargesBodyWire, body);
428
+ }
429
+ return http(client)
430
+ .post(path, { ...options, json: body })
431
+ .json()
432
+ .then((data) => {
433
+ if (client._options.validate) {
434
+ assertValid(schemas.createCustomerChargesResponseWire, data);
435
+ }
436
+ return fromWire(data, schemas.createCustomerChargesResponse);
437
+ });
438
+ });
140
439
  }
141
440
  //# sourceMappingURL=customers.js.map