@openmeter/client 1.0.0-beta-fdbfe20cc6cb → 1.0.0-beta-be2666bd959f

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.
package/README.md CHANGED
@@ -97,8 +97,8 @@ const meter = await client.meters.create({
97
97
  name: 'Tokens',
98
98
  key: 'tokens',
99
99
  aggregation: 'sum',
100
- event_type: 'request',
101
- value_property: '$.tokens',
100
+ eventType: 'request',
101
+ valueProperty: '$.tokens',
102
102
  })
103
103
 
104
104
  const meters = await client.meters.list()
@@ -194,10 +194,11 @@ The full call path, HTTP route, and a short description are listed below.
194
194
 
195
195
  ### Invoices
196
196
 
197
- | Method | HTTP | Description |
198
- | ---------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199
- | `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. |
200
- | `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. |
197
+ | Method | HTTP | Description |
198
+ | ------------------------ | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199
+ | `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. |
200
+ | `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. |
201
+ | `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. |
201
202
 
202
203
  ### Tax
203
204
 
@@ -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
  }
@@ -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