@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
package/README.md CHANGED
@@ -24,6 +24,7 @@ TypeSpec definitions and ships fully-typed request and response models.
24
24
  - [Subscriptions](#subscriptions)
25
25
  - [Apps](#apps)
26
26
  - [Billing](#billing)
27
+ - [Invoices](#invoices)
27
28
  - [Tax](#tax)
28
29
  - [Currencies](#currencies)
29
30
  - [Features](#features)
@@ -96,8 +97,8 @@ const meter = await client.meters.create({
96
97
  name: 'Tokens',
97
98
  key: 'tokens',
98
99
  aggregation: 'sum',
99
- event_type: 'request',
100
- value_property: '$.tokens',
100
+ eventType: 'request',
101
+ valueProperty: '$.tokens',
101
102
  })
102
103
 
103
104
  const meters = await client.meters.list()
@@ -106,6 +107,11 @@ const meters = await client.meters.list()
106
107
  Each method takes the request object as its first argument and an optional
107
108
  per-request options object (`RequestOptions`) as its second.
108
109
 
110
+ Responses return date-time fields as native `Date` objects (every
111
+ `createdAt`/`updatedAt`, meter query row windows, …), and requests accept
112
+ either a `Date` or an RFC 3339 string — a meter query `from`/`to`, an
113
+ ingested event's `time`, filter operands, all alike.
114
+
109
115
  ## Available Resources and Operations
110
116
 
111
117
  Operations are grouped by resource and exposed as methods on the client.
@@ -120,36 +126,39 @@ The full call path, HTTP route, and a short description are listed below.
120
126
 
121
127
  ### Meters
122
128
 
123
- | Method | HTTP | Description |
124
- | ---------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
125
- | `client.meters.create` | `POST /openmeter/meters` | Create a meter. |
126
- | `client.meters.get` | `GET /openmeter/meters/{meterId}` | Get a meter by ID. |
127
- | `client.meters.list` | `GET /openmeter/meters` | List meters. |
128
- | `client.meters.update` | `PUT /openmeter/meters/{meterId}` | Update a meter. |
129
- | `client.meters.delete` | `DELETE /openmeter/meters/{meterId}` | Delete a meter. |
130
- | `client.meters.query` | `POST /openmeter/meters/{meterId}/query` | Query a meter for usage. Set `Accept: application/json` (the default) to get a structured JSON response. Set `Accept: text/csv` to download the same data as a CSV file suitable for spreadsheets. The CSV columns, in order, are: `from, to, [subject,] [customer_id, customer_key, customer_name,] <dimensions...>, value` The `subject` column is emitted only when `subject` is in the query's `group_by_dimensions`. The three `customer_*` columns are emitted together only when `customer_id` is in the query's `group_by_dimensions`. |
129
+ | Method | HTTP | Description |
130
+ | ------------------------ | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
131
+ | `client.meters.create` | `POST /openmeter/meters` | Create a meter. |
132
+ | `client.meters.get` | `GET /openmeter/meters/{meterId}` | Get a meter by ID. |
133
+ | `client.meters.list` | `GET /openmeter/meters` | List meters. |
134
+ | `client.meters.update` | `PUT /openmeter/meters/{meterId}` | Update a meter. |
135
+ | `client.meters.delete` | `DELETE /openmeter/meters/{meterId}` | Delete a meter. |
136
+ | `client.meters.query` | `POST /openmeter/meters/{meterId}/query` | Query a meter for usage. Set `Accept: application/json` (the default) to get a structured JSON response. Set `Accept: text/csv` to download the same data as a CSV file suitable for spreadsheets. The CSV columns, in order, are: `from, to, [subject,] [customer_id, customer_key, customer_name,] <dimensions...>, value` The `subject` column is emitted only when `subject` is in the query's `group_by_dimensions`. The three `customer_*` columns are emitted together only when `customer_id` is in the query's `group_by_dimensions`. |
137
+ | `client.meters.queryCsv` | `POST /openmeter/meters/{meterId}/query` | |
131
138
 
132
139
  ### Customers
133
140
 
134
- | Method | HTTP | Description |
135
- | ------------------------------------------------------ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
136
- | `client.customers.create` | `POST /openmeter/customers` | |
137
- | `client.customers.get` | `GET /openmeter/customers/{customerId}` | |
138
- | `client.customers.list` | `GET /openmeter/customers` | |
139
- | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | |
140
- | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | |
141
- | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | |
142
- | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | |
143
- | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | |
144
- | `client.customers.billing.createStripeCheckoutSession` | `POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions` | Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout) for the customer. Creates a Checkout Session for collecting payment method information from customers. The session operates in "setup" mode, which collects payment details without charging the customer immediately. The collected payment method can be used for future subscription billing. For hosted checkout sessions, redirect customers to the returned URL. For embedded sessions, use the client_secret to initialize Stripe.js in your application. |
145
- | `client.customers.billing.createStripePortalSession` | `POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions` | Create Stripe Customer Portal Session. Useful to redirect the customer to the Stripe Customer Portal to manage their payment methods, change their billing address and access their invoice history. Only returns URL if the customer billing profile is linked to a stripe app and customer. |
146
- | `client.customers.credits.grants.create` | `POST /openmeter/customers/{customerId}/credits/grants` | Create a new credit grant. A credit grant represents an allocation of prepaid credits to a customer. |
147
- | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
148
- | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
149
- | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
150
- | `client.customers.credits.adjustments.create` | `POST /openmeter/customers/{customerId}/credits/adjustments` | A credit adjustment can be used to make manual adjustments to a customer's credit balance. Supported use-cases: - Usage correction |
151
- | `client.customers.credits.transactions.list` | `GET /openmeter/customers/{customerId}/credits/transactions` | List credit transactions for a customer. Returns an immutable, chronological record of credit movements: funded credits and consumed credits. Transactions are returned in reverse chronological order by default. |
152
- | `client.customers.charges.list` | `GET /openmeter/customers/{customerId}/charges` | List customer charges. Returns the customer's charges that are represented as either flat fee or usage-based charges. |
141
+ | Method | HTTP | Description |
142
+ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143
+ | `client.customers.create` | `POST /openmeter/customers` | |
144
+ | `client.customers.get` | `GET /openmeter/customers/{customerId}` | |
145
+ | `client.customers.list` | `GET /openmeter/customers` | |
146
+ | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | |
147
+ | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | |
148
+ | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | |
149
+ | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | |
150
+ | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | |
151
+ | `client.customers.billing.createStripeCheckoutSession` | `POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions` | Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout) for the customer. Creates a Checkout Session for collecting payment method information from customers. The session operates in "setup" mode, which collects payment details without charging the customer immediately. The collected payment method can be used for future subscription billing. For hosted checkout sessions, redirect customers to the returned URL. For embedded sessions, use the client_secret to initialize Stripe.js in your application. |
152
+ | `client.customers.billing.createStripePortalSession` | `POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions` | Create Stripe Customer Portal Session. Useful to redirect the customer to the Stripe Customer Portal to manage their payment methods, change their billing address and access their invoice history. Only returns URL if the customer billing profile is linked to a stripe app and customer. |
153
+ | `client.customers.credits.grants.create` | `POST /openmeter/customers/{customerId}/credits/grants` | Create a new credit grant. A credit grant represents an allocation of prepaid credits to a customer. |
154
+ | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
155
+ | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
156
+ | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
157
+ | `client.customers.credits.adjustments.create` | `POST /openmeter/customers/{customerId}/credits/adjustments` | A credit adjustment can be used to make manual adjustments to a customer's credit balance. Supported use-cases: - Usage correction |
158
+ | `client.customers.credits.grants.updateExternalSettlement` | `POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external` | Update the payment settlement status of an externally funded credit grant. Use this endpoint to synchronize the payment state of an external payment with the system so that revenue recognition and credit availability work as expected. |
159
+ | `client.customers.credits.transactions.list` | `GET /openmeter/customers/{customerId}/credits/transactions` | List credit transactions for a customer. Returns an immutable, chronological record of credit movements: funded credits and consumed credits. Transactions are returned in reverse chronological order by default. |
160
+ | `client.customers.charges.list` | `GET /openmeter/customers/{customerId}/charges` | List customer charges. Returns the customer's charges that are represented as either flat fee or usage-based charges. |
161
+ | `client.customers.charges.create` | `POST /openmeter/customers/{customerId}/charges` | Create customer charge. |
153
162
 
154
163
  ### Entitlements
155
164
 
@@ -167,7 +176,8 @@ The full call path, HTTP route, and a short description are listed below.
167
176
  | `client.subscriptions.cancel` | `POST /openmeter/subscriptions/{subscriptionId}/cancel` | Cancels the subscription. Will result in a scheduling conflict if there are other subscriptions scheduled to start after the cancelation time. |
168
177
  | `client.subscriptions.unscheduleCancelation` | `POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation` | Unschedules the subscription cancelation. |
169
178
  | `client.subscriptions.change` | `POST /openmeter/subscriptions/{subscriptionId}/change` | Closes a running subscription and starts a new one according to the specification. Can be used for upgrades, downgrades, and plan changes. |
170
- | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the addons of a subscription. |
179
+ | `client.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
180
+ | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the add-ons of a subscription. |
171
181
  | `client.subscriptions.getAddon` | `GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}` | Get an add-on association for a subscription. |
172
182
 
173
183
  ### Apps
@@ -187,6 +197,15 @@ The full call path, HTTP route, and a short description are listed below.
187
197
  | `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
188
198
  | `client.billing.deleteProfile` | `DELETE /openmeter/profiles/{id}` | Delete a billing profile. Only such billing profiles can be deleted that are: - not the default profile - not pinned to any customer using customer overrides - only have finalized invoices |
189
199
 
200
+ ### Invoices
201
+
202
+ | Method | HTTP | Description |
203
+ | ------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
204
+ | `client.invoices.list` | `GET /openmeter/billing/invoices` | List billing invoices. Returns a page of invoices. Gathering invoices are never included. Use `filter` to narrow by status, customer, dates, or service period start. Use `sort` to control ordering. |
205
+ | `client.invoices.get` | `GET /openmeter/billing/invoices/{invoiceId}` | Get a billing invoice by ID. Returns the full invoice resource including line items, status details, totals, and workflow configuration snapshot. |
206
+ | `client.invoices.update` | `PUT /openmeter/billing/invoices/{invoiceId}` | Update a billing invoice. Only the mutable fields of the invoice can be edited: description, labels, supplier, customer, workflow settings, and top-level lines. Top-level lines are matched by `id`; lines without an `id` are created, and existing lines omitted from `lines` are deleted. Detailed (child) lines are always computed and cannot be edited directly. Only invoices in draft status can be updated. |
207
+ | `client.invoices.delete` | `DELETE /openmeter/billing/invoices/{invoiceId}` | Delete a billing invoice. Only standard invoices in draft status can be deleted. Deleting an invoice will also delete all associated line items and workflow configuration. |
208
+
190
209
  ### Tax
191
210
 
192
211
  | Method | HTTP | Description |
@@ -1,53 +1,136 @@
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 listAddons(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.listAddonsQueryParams);
13
+ if (client._options.validate) {
14
+ assertValid(schemas.listAddonsQueryParamsWire, query);
15
+ }
16
+ const searchParams = toURLSearchParams(query);
17
+ return http(client)
18
+ .get('openmeter/addons', { ...options, searchParams })
19
+ .json()
20
+ .then((data) => {
21
+ if (client._options.validate) {
22
+ assertValid(schemas.listAddonsResponseWire, data);
23
+ }
24
+ return fromWire(data, schemas.listAddonsResponse);
25
+ });
9
26
  });
10
- return request(() => http(client)
11
- .get('openmeter/addons', { ...options, searchParams })
12
- .json());
13
27
  }
14
28
  export function createAddon(client, req, options) {
15
- return request(() => http(client)
16
- .post('openmeter/addons', { ...options, json: req })
17
- .json());
29
+ return request(() => {
30
+ const body = toWire(req, schemas.createAddonBody);
31
+ if (client._options.validate) {
32
+ assertValid(schemas.createAddonBodyWire, body);
33
+ }
34
+ return http(client)
35
+ .post('openmeter/addons', { ...options, json: body })
36
+ .json()
37
+ .then((data) => {
38
+ if (client._options.validate) {
39
+ assertValid(schemas.createAddonResponseWire, data);
40
+ }
41
+ return fromWire(data, schemas.createAddonResponse);
42
+ });
43
+ });
18
44
  }
19
45
  export function updateAddon(client, req, options) {
20
- const path = encodePath('openmeter/addons/{addonId}', {
21
- addonId: req.addonId,
46
+ return request(() => {
47
+ const path = `openmeter/addons/${(() => {
48
+ if (req.addonId === undefined) {
49
+ throw new Error('missing path parameter: addonId');
50
+ }
51
+ return encodeURIComponent(String(req.addonId));
52
+ })()}`;
53
+ const body = toWire(req.body, schemas.updateAddonBody);
54
+ if (client._options.validate) {
55
+ assertValid(schemas.updateAddonBodyWire, body);
56
+ }
57
+ return http(client)
58
+ .put(path, { ...options, json: body })
59
+ .json()
60
+ .then((data) => {
61
+ if (client._options.validate) {
62
+ assertValid(schemas.updateAddonResponseWire, data);
63
+ }
64
+ return fromWire(data, schemas.updateAddonResponse);
65
+ });
22
66
  });
23
- return request(() => http(client)
24
- .put(path, { ...options, json: req.body })
25
- .json());
26
67
  }
27
68
  export function getAddon(client, req, options) {
28
- const path = encodePath('openmeter/addons/{addonId}', {
29
- addonId: req.addonId,
69
+ return request(() => {
70
+ const path = `openmeter/addons/${(() => {
71
+ if (req.addonId === undefined) {
72
+ throw new Error('missing path parameter: addonId');
73
+ }
74
+ return encodeURIComponent(String(req.addonId));
75
+ })()}`;
76
+ return http(client)
77
+ .get(path, options)
78
+ .json()
79
+ .then((data) => {
80
+ if (client._options.validate) {
81
+ assertValid(schemas.getAddonResponseWire, data);
82
+ }
83
+ return fromWire(data, schemas.getAddonResponse);
84
+ });
30
85
  });
31
- return request(() => http(client).get(path, options).json());
32
86
  }
33
87
  export function deleteAddon(client, req, options) {
34
- const path = encodePath('openmeter/addons/{addonId}', {
35
- addonId: req.addonId,
36
- });
37
88
  return request(async () => {
89
+ const path = `openmeter/addons/${(() => {
90
+ if (req.addonId === undefined) {
91
+ throw new Error('missing path parameter: addonId');
92
+ }
93
+ return encodeURIComponent(String(req.addonId));
94
+ })()}`;
38
95
  await http(client).delete(path, options);
39
96
  });
40
97
  }
41
98
  export function archiveAddon(client, req, options) {
42
- const path = encodePath('openmeter/addons/{addonId}/archive', {
43
- addonId: req.addonId,
99
+ return request(() => {
100
+ const path = `openmeter/addons/${(() => {
101
+ if (req.addonId === undefined) {
102
+ throw new Error('missing path parameter: addonId');
103
+ }
104
+ return encodeURIComponent(String(req.addonId));
105
+ })()}/archive`;
106
+ return http(client)
107
+ .post(path, options)
108
+ .json()
109
+ .then((data) => {
110
+ if (client._options.validate) {
111
+ assertValid(schemas.archiveAddonResponseWire, data);
112
+ }
113
+ return fromWire(data, schemas.archiveAddonResponse);
114
+ });
44
115
  });
45
- return request(() => http(client).post(path, options).json());
46
116
  }
47
117
  export function publishAddon(client, req, options) {
48
- const path = encodePath('openmeter/addons/{addonId}/publish', {
49
- addonId: req.addonId,
118
+ return request(() => {
119
+ const path = `openmeter/addons/${(() => {
120
+ if (req.addonId === undefined) {
121
+ throw new Error('missing path parameter: addonId');
122
+ }
123
+ return encodeURIComponent(String(req.addonId));
124
+ })()}/publish`;
125
+ return http(client)
126
+ .post(path, options)
127
+ .json()
128
+ .then((data) => {
129
+ if (client._options.validate) {
130
+ assertValid(schemas.publishAddonResponseWire, data);
131
+ }
132
+ return fromWire(data, schemas.publishAddonResponse);
133
+ });
50
134
  });
51
- return request(() => http(client).post(path, options).json());
52
135
  }
53
136
  //# sourceMappingURL=addons.js.map
@@ -1,16 +1,45 @@
1
1
  import { http } from '../core.js';
2
2
  import { request } from '../lib/request.js';
3
- import { encodePath, toURLSearchParams } from '../lib/encodings.js';
3
+ import { toURLSearchParams } from '../lib/encodings.js';
4
+ import { toWire, fromWire, assertValid } from '../lib/wire.js';
5
+ import * as schemas from '../models/schemas.js';
4
6
  export function listApps(client, req = {}, options) {
5
- const searchParams = toURLSearchParams({
6
- page: req.page,
7
+ return request(() => {
8
+ const query = toWire({
9
+ page: req.page,
10
+ }, schemas.listAppsQueryParams);
11
+ if (client._options.validate) {
12
+ assertValid(schemas.listAppsQueryParamsWire, query);
13
+ }
14
+ const searchParams = toURLSearchParams(query);
15
+ return http(client)
16
+ .get('openmeter/apps', { ...options, searchParams })
17
+ .json()
18
+ .then((data) => {
19
+ if (client._options.validate) {
20
+ assertValid(schemas.listAppsResponseWire, data);
21
+ }
22
+ return fromWire(data, schemas.listAppsResponse);
23
+ });
7
24
  });
8
- return request(() => http(client)
9
- .get('openmeter/apps', { ...options, searchParams })
10
- .json());
11
25
  }
12
26
  export function getApp(client, req, options) {
13
- const path = encodePath('openmeter/apps/{appId}', { appId: req.appId });
14
- return request(() => http(client).get(path, options).json());
27
+ return request(() => {
28
+ const path = `openmeter/apps/${(() => {
29
+ if (req.appId === undefined) {
30
+ throw new Error('missing path parameter: appId');
31
+ }
32
+ return encodeURIComponent(String(req.appId));
33
+ })()}`;
34
+ return http(client)
35
+ .get(path, options)
36
+ .json()
37
+ .then((data) => {
38
+ if (client._options.validate) {
39
+ assertValid(schemas.getAppResponseWire, data);
40
+ }
41
+ return fromWire(data, schemas.getAppResponse);
42
+ });
43
+ });
15
44
  }
16
45
  //# sourceMappingURL=apps.js.map
@@ -1,32 +1,95 @@
1
1
  import { http } from '../core.js';
2
2
  import { request } from '../lib/request.js';
3
- import { encodePath, toURLSearchParams } from '../lib/encodings.js';
3
+ import { toURLSearchParams } from '../lib/encodings.js';
4
+ import { toWire, fromWire, assertValid } from '../lib/wire.js';
5
+ import * as schemas from '../models/schemas.js';
4
6
  export function listBillingProfiles(client, req = {}, options) {
5
- const searchParams = toURLSearchParams({
6
- page: req.page,
7
+ return request(() => {
8
+ const query = toWire({
9
+ page: req.page,
10
+ }, schemas.listBillingProfilesQueryParams);
11
+ if (client._options.validate) {
12
+ assertValid(schemas.listBillingProfilesQueryParamsWire, query);
13
+ }
14
+ const searchParams = toURLSearchParams(query);
15
+ return http(client)
16
+ .get('openmeter/profiles', { ...options, searchParams })
17
+ .json()
18
+ .then((data) => {
19
+ if (client._options.validate) {
20
+ assertValid(schemas.listBillingProfilesResponseWire, data);
21
+ }
22
+ return fromWire(data, schemas.listBillingProfilesResponse);
23
+ });
7
24
  });
8
- return request(() => http(client)
9
- .get('openmeter/profiles', { ...options, searchParams })
10
- .json());
11
25
  }
12
26
  export function createBillingProfile(client, req, options) {
13
- return request(() => http(client)
14
- .post('openmeter/profiles', { ...options, json: req })
15
- .json());
27
+ return request(() => {
28
+ const body = toWire(req, schemas.createBillingProfileBody);
29
+ if (client._options.validate) {
30
+ assertValid(schemas.createBillingProfileBodyWire, body);
31
+ }
32
+ return http(client)
33
+ .post('openmeter/profiles', { ...options, json: body })
34
+ .json()
35
+ .then((data) => {
36
+ if (client._options.validate) {
37
+ assertValid(schemas.createBillingProfileResponseWire, data);
38
+ }
39
+ return fromWire(data, schemas.createBillingProfileResponse);
40
+ });
41
+ });
16
42
  }
17
43
  export function getBillingProfile(client, req, options) {
18
- const path = encodePath('openmeter/profiles/{id}', { id: req.id });
19
- return request(() => http(client).get(path, options).json());
44
+ return request(() => {
45
+ const path = `openmeter/profiles/${(() => {
46
+ if (req.id === undefined) {
47
+ throw new Error('missing path parameter: id');
48
+ }
49
+ return encodeURIComponent(String(req.id));
50
+ })()}`;
51
+ return http(client)
52
+ .get(path, options)
53
+ .json()
54
+ .then((data) => {
55
+ if (client._options.validate) {
56
+ assertValid(schemas.getBillingProfileResponseWire, data);
57
+ }
58
+ return fromWire(data, schemas.getBillingProfileResponse);
59
+ });
60
+ });
20
61
  }
21
62
  export function updateBillingProfile(client, req, options) {
22
- const path = encodePath('openmeter/profiles/{id}', { id: req.id });
23
- return request(() => http(client)
24
- .put(path, { ...options, json: req.body })
25
- .json());
63
+ return request(() => {
64
+ const path = `openmeter/profiles/${(() => {
65
+ if (req.id === undefined) {
66
+ throw new Error('missing path parameter: id');
67
+ }
68
+ return encodeURIComponent(String(req.id));
69
+ })()}`;
70
+ const body = toWire(req.body, schemas.updateBillingProfileBody);
71
+ if (client._options.validate) {
72
+ assertValid(schemas.updateBillingProfileBodyWire, body);
73
+ }
74
+ return http(client)
75
+ .put(path, { ...options, json: body })
76
+ .json()
77
+ .then((data) => {
78
+ if (client._options.validate) {
79
+ assertValid(schemas.updateBillingProfileResponseWire, data);
80
+ }
81
+ return fromWire(data, schemas.updateBillingProfileResponse);
82
+ });
83
+ });
26
84
  }
27
85
  export function deleteBillingProfile(client, req, options) {
28
- const path = encodePath('openmeter/profiles/{id}', { id: req.id });
29
86
  return request(async () => {
87
+ const path = `openmeter/profiles/${(() => {
88
+ if (req.id === undefined) {
89
+ throw new Error('missing path parameter: id');
90
+ }
91
+ return encodeURIComponent(String(req.id));
92
+ })()}`;
30
93
  await http(client).delete(path, options);
31
94
  });
32
95
  }