Leon4gr45 commited on
Commit
1477a90
·
verified ·
1 Parent(s): 048b1e8

Upload folder using huggingface_hub (part 2)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. api/spec/packages/aip-client-javascript/.gitignore +12 -0
  2. api/spec/packages/aip-client-javascript/LICENSE +202 -0
  3. api/spec/packages/aip-client-javascript/README.md +623 -0
  4. api/spec/packages/aip-client-javascript/package.json +59 -0
  5. api/spec/packages/aip-client-javascript/src/core.ts +62 -0
  6. api/spec/packages/aip-client-javascript/src/funcs/addons.ts +295 -0
  7. api/spec/packages/aip-client-javascript/src/funcs/apps.ts +199 -0
  8. api/spec/packages/aip-client-javascript/src/funcs/billing.ts +211 -0
  9. api/spec/packages/aip-client-javascript/src/funcs/currencies.ts +190 -0
  10. api/spec/packages/aip-client-javascript/src/funcs/customers.ts +1012 -0
  11. api/spec/packages/aip-client-javascript/src/funcs/defaults.ts +66 -0
  12. api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts +55 -0
  13. api/spec/packages/aip-client-javascript/src/funcs/events.ts +75 -0
  14. api/spec/packages/aip-client-javascript/src/funcs/features.ts +257 -0
  15. api/spec/packages/aip-client-javascript/src/funcs/governance.ts +62 -0
  16. api/spec/packages/aip-client-javascript/src/funcs/index.ts +19 -0
  17. api/spec/packages/aip-client-javascript/src/funcs/invoices.ts +389 -0
  18. api/spec/packages/aip-client-javascript/src/funcs/llmCost.ts +204 -0
  19. api/spec/packages/aip-client-javascript/src/funcs/meters.ts +303 -0
  20. api/spec/packages/aip-client-javascript/src/funcs/planAddons.ts +248 -0
  21. api/spec/packages/aip-client-javascript/src/funcs/plans.ts +295 -0
  22. api/spec/packages/aip-client-javascript/src/funcs/subscriptions.ts +414 -0
  23. api/spec/packages/aip-client-javascript/src/funcs/tax.ts +191 -0
  24. api/spec/packages/aip-client-javascript/src/index.ts +440 -0
  25. api/spec/packages/aip-client-javascript/src/lib/config.ts +33 -0
  26. api/spec/packages/aip-client-javascript/src/lib/encodings.ts +77 -0
  27. api/spec/packages/aip-client-javascript/src/lib/paginate.ts +99 -0
  28. api/spec/packages/aip-client-javascript/src/lib/request.ts +12 -0
  29. api/spec/packages/aip-client-javascript/src/lib/to-error.ts +18 -0
  30. api/spec/packages/aip-client-javascript/src/lib/types.ts +27 -0
  31. api/spec/packages/aip-client-javascript/src/lib/version.ts +6 -0
  32. api/spec/packages/aip-client-javascript/src/lib/wire.ts +559 -0
  33. api/spec/packages/aip-client-javascript/src/models/errors.ts +85 -0
  34. api/spec/packages/aip-client-javascript/src/models/operations/addons.ts +65 -0
  35. api/spec/packages/aip-client-javascript/src/models/operations/apps.ts +42 -0
  36. api/spec/packages/aip-client-javascript/src/models/operations/billing.ts +40 -0
  37. api/spec/packages/aip-client-javascript/src/models/operations/currencies.ts +67 -0
  38. api/spec/packages/aip-client-javascript/src/models/operations/customers.ts +225 -0
  39. api/spec/packages/aip-client-javascript/src/models/operations/defaults.ts +15 -0
  40. api/spec/packages/aip-client-javascript/src/models/operations/entitlements.ts +9 -0
  41. api/spec/packages/aip-client-javascript/src/models/operations/events.ts +44 -0
  42. api/spec/packages/aip-client-javascript/src/models/operations/features.ts +67 -0
  43. api/spec/packages/aip-client-javascript/src/models/operations/governance.ts +21 -0
  44. api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts +77 -0
  45. api/spec/packages/aip-client-javascript/src/models/operations/llmCost.ts +59 -0
  46. api/spec/packages/aip-client-javascript/src/models/operations/meters.ts +73 -0
  47. api/spec/packages/aip-client-javascript/src/models/operations/planAddons.ts +46 -0
  48. api/spec/packages/aip-client-javascript/src/models/operations/plans.ts +62 -0
  49. api/spec/packages/aip-client-javascript/src/models/operations/subscriptions.ts +99 -0
  50. api/spec/packages/aip-client-javascript/src/models/operations/tax.ts +40 -0
api/spec/packages/aip-client-javascript/.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Build output
2
+ dist/
3
+ tsconfig.tsbuildinfo
4
+
5
+ # Test coverage output
6
+ coverage/
7
+
8
+ # Dependencies
9
+ node_modules/
10
+
11
+ # Generated conformance guards (compile-time only, re-emitted by the generator)
12
+ *.assert.ts
api/spec/packages/aip-client-javascript/LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
api/spec/packages/aip-client-javascript/README.md ADDED
@@ -0,0 +1,623 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- Code generated by @openmeter/typespec-typescript. DO NOT EDIT. -->
2
+
3
+ # OpenMeter SDK
4
+
5
+ TypeScript client for the OpenMeter API — usage metering and billing for
6
+ AI and DevTool companies. This package is generated from the OpenMeter
7
+ TypeSpec definitions and ships fully-typed request and response models.
8
+
9
+ > **Important:** This SDK is a work in progress.
10
+ >
11
+ > This SDK targets the [OpenMeter API v3](https://openmeter.io/docs/api/v3),
12
+ > a rewrite of the OpenMeter API following AIP (API Improvement Proposal)
13
+ > standardization.
14
+
15
+ ## Table of Contents
16
+
17
+ - [Installation](#installation)
18
+ - [Initialization](#initialization)
19
+ - [Configuration](#configuration)
20
+ - [Usage](#usage)
21
+ - [Pagination](#pagination)
22
+ - [Available Resources and Operations](#available-resources-and-operations)
23
+ - [Events](#events)
24
+ - [Meters](#meters)
25
+ - [Customers](#customers)
26
+ - [Entitlements](#entitlements)
27
+ - [Subscriptions](#subscriptions)
28
+ - [Apps](#apps)
29
+ - [Billing](#billing)
30
+ - [Tax](#tax)
31
+ - [Features](#features)
32
+ - [LLMCost](#llmcost)
33
+ - [Plans](#plans)
34
+ - [Addons](#addons)
35
+ - [PlanAddons](#planaddons)
36
+ - [Defaults](#defaults)
37
+ - [Internal Operations](#internal-operations)
38
+ - [Internal Subscriptions](#internal-subscriptions)
39
+ - [Internal Invoices](#internal-invoices)
40
+ - [Internal Currencies](#internal-currencies)
41
+ - [Internal Governance](#internal-governance)
42
+ - [Runtime Validation (validate option)](#runtime-validation-validate-option)
43
+ - [Zod Schemas (./zod export)](#zod-schemas-zod-export)
44
+ - [Error Handling](#error-handling)
45
+ - [Standalone Functions](#standalone-functions)
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ npm install @openmeter/client
51
+ ```
52
+
53
+ Or with your package manager of choice:
54
+
55
+ ```bash
56
+ pnpm add @openmeter/client
57
+ yarn add @openmeter/client
58
+ ```
59
+
60
+ ## Initialization
61
+
62
+ Create a client with a base URL and an API key. The API key is sent as a
63
+ `Bearer` token on every request.
64
+
65
+ ```typescript
66
+ import { OpenMeter } from '@openmeter/client'
67
+
68
+ const client = new OpenMeter({
69
+ baseUrl: 'https://openmeter.cloud/api/v3',
70
+ apiKey: process.env.OPENMETER_API_KEY,
71
+ })
72
+ ```
73
+
74
+ Konnect regions are addressed with a server template and a `region`
75
+ variable:
76
+
77
+ ```typescript
78
+ import { OpenMeter, ServerList } from '@openmeter/client'
79
+
80
+ const client = new OpenMeter({
81
+ baseUrl: ServerList[0],
82
+ serverVariables: { region: 'eu' },
83
+ apiKey: process.env.OPENMETER_API_KEY,
84
+ })
85
+ ```
86
+
87
+ The `apiKey` may also be a function returning a `string` or
88
+ `Promise<string>`, so tokens can be refreshed per request.
89
+
90
+ ## Configuration
91
+
92
+ `SDKOptions` extends [ky](https://github.com/sindresorhus/ky)'s
93
+ `Options`, so every transport setting ky supports is a top-level client
94
+ option: retry policy, per-attempt timeout (ky defaults to 10 seconds),
95
+ lifecycle hooks, a custom `fetch`, and so on.
96
+
97
+ ```typescript
98
+ import { OpenMeter } from '@openmeter/client'
99
+
100
+ const client = new OpenMeter({
101
+ baseUrl: 'https://openmeter.cloud/api/v3',
102
+ apiKey: process.env.OPENMETER_API_KEY,
103
+ timeout: 30_000,
104
+ hooks: {
105
+ beforeRequest: [
106
+ ({ request }) => {
107
+ console.log(`-> ${request.method} ${request.url}`)
108
+ },
109
+ ],
110
+ },
111
+ fetch: async (input, init) => {
112
+ const start = Date.now()
113
+ const response = await fetch(input, init)
114
+ console.log(`${response.status} in ${Date.now() - start}ms`)
115
+ return response
116
+ },
117
+ })
118
+ ```
119
+
120
+ ky only retries the idempotent methods by default — `get`, `put`,
121
+ `head`, `delete`, `options`, `trace` — never `post`. That means a
122
+ dropped `client.events.ingest` call is not retried on a network error
123
+ or a 5xx response unless you opt in explicitly:
124
+
125
+ ```typescript
126
+ import { OpenMeter } from '@openmeter/client'
127
+
128
+ const client = new OpenMeter({
129
+ baseUrl: 'https://openmeter.cloud/api/v3',
130
+ apiKey: process.env.OPENMETER_API_KEY,
131
+ retry: { limit: 3, methods: ['get', 'put', 'head', 'delete', 'post'] },
132
+ })
133
+ ```
134
+
135
+ This is safe specifically for event ingestion: the event `id` is its
136
+ deduplication key server-side, so resending the same event on retry is
137
+ a no-op rather than a duplicate.
138
+
139
+ Every method also takes a per-request `RequestOptions` as its second
140
+ argument — a curated subset of ky's options (`signal`, `headers`,
141
+ `timeout`, `retry`) applied to that call only:
142
+
143
+ ```typescript
144
+ import { OpenMeter } from '@openmeter/client'
145
+
146
+ const client = new OpenMeter({
147
+ baseUrl: 'https://openmeter.cloud/api/v3',
148
+ apiKey: process.env.OPENMETER_API_KEY,
149
+ })
150
+
151
+ const controller = new AbortController()
152
+ setTimeout(() => controller.abort(), 5_000)
153
+
154
+ const meters = await client.meters.list(undefined, {
155
+ signal: controller.signal,
156
+ headers: { 'X-Request-Id': 'batch-42' },
157
+ })
158
+ ```
159
+
160
+ ## Usage
161
+
162
+ Every operation is reachable through a fluent, namespaced client and
163
+ returns a typed response (or throws an `HTTPError` on a non-2xx status).
164
+
165
+ ```typescript
166
+ import { OpenMeter } from '@openmeter/client'
167
+
168
+ const client = new OpenMeter({
169
+ baseUrl: 'https://openmeter.cloud/api/v3',
170
+ apiKey: process.env.OPENMETER_API_KEY,
171
+ })
172
+
173
+ const meter = await client.meters.create({
174
+ name: 'Tokens',
175
+ key: 'tokens',
176
+ aggregation: 'sum',
177
+ eventType: 'request',
178
+ valueProperty: '$.tokens',
179
+ })
180
+
181
+ const meters = await client.meters.list()
182
+ ```
183
+
184
+ Each method takes the request object as its first argument and an optional
185
+ per-request options object (`RequestOptions`) as its second.
186
+
187
+ Responses return date-time fields as native `Date` objects (every
188
+ `createdAt`/`updatedAt`, meter query row windows, …), and requests accept
189
+ either a `Date` or an RFC 3339 string — a meter query `from`/`to`, an
190
+ ingested event's `time`, filter operands, all alike.
191
+
192
+ ## Pagination
193
+
194
+ Every list operation that returns pages also has an `…All` companion —
195
+ `client.meters.listAll(request?)` alongside `client.meters.list(request?)` —
196
+ that returns an `AsyncIterable` of items instead of one page. It fetches
197
+ each following page lazily, only when the previous page is exhausted, so a
198
+ `break` (or a `return`) partway through never fires a request for a page
199
+ nothing consumes:
200
+
201
+ ```typescript
202
+ import { OpenMeter } from '@openmeter/client'
203
+
204
+ const client = new OpenMeter({
205
+ baseUrl: 'https://openmeter.cloud/api/v3',
206
+ apiKey: process.env.OPENMETER_API_KEY,
207
+ })
208
+
209
+ for await (const meter of client.meters.listAll()) {
210
+ console.log(meter.key)
211
+ }
212
+ ```
213
+
214
+ The request object accepts the same filters, sort, and page size as the
215
+ single-page method — only the page cursor/number itself advances between
216
+ requests:
217
+
218
+ ```typescript
219
+ for await (const meter of client.meters.listAll({ filter: { key: 'api' } })) {
220
+ if (meter.key === 'api-requests') {
221
+ break // stops iterating; no further pages are fetched
222
+ }
223
+ }
224
+ ```
225
+
226
+ Cursor-paginated resources (`events`, credit transactions) work the same
227
+ way:
228
+
229
+ ```typescript
230
+ for await (const event of client.events.listAll()) {
231
+ console.log(event.event.id)
232
+ }
233
+ ```
234
+
235
+ Auto-pagination takes the same optional `RequestOptions` as every other
236
+ method, so one `AbortSignal` cancels the whole iteration, not just the page
237
+ in flight:
238
+
239
+ ```typescript
240
+ const controller = new AbortController()
241
+ setTimeout(() => controller.abort(), 30_000)
242
+
243
+ for await (const meter of client.meters.listAll(undefined, {
244
+ signal: controller.signal,
245
+ })) {
246
+ console.log(meter.key)
247
+ }
248
+ ```
249
+
250
+ Iteration stops after the server’s last page — an empty or short-of-`size`
251
+ page for a page-number resource, or a response with no next cursor for a
252
+ cursor resource. A misbehaving server that never signals the end of the
253
+ list fails fast instead of looping forever: after 10,000 pages the
254
+ iterable throws `PaginationLimitExceededError`.
255
+
256
+ ## Available Resources and Operations
257
+
258
+ Operations are grouped by resource and exposed as methods on the client.
259
+ The full call path, HTTP route, and a short description are listed below.
260
+
261
+ ### Events
262
+
263
+ | Method | HTTP | Description |
264
+ | ---------------------- | ------------------------ | ---------------------------------------------------------------------------- |
265
+ | `client.events.list` | `GET /openmeter/events` | List ingested events. |
266
+ | `client.events.ingest` | `POST /openmeter/events` | Ingests an event or batch of events following the CloudEvents specification. |
267
+
268
+ ### Meters
269
+
270
+ | Method | HTTP | Description |
271
+ | ------------------------ | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
272
+ | `client.meters.create` | `POST /openmeter/meters` | Create a meter. |
273
+ | `client.meters.get` | `GET /openmeter/meters/{meterId}` | Get a meter by ID. |
274
+ | `client.meters.list` | `GET /openmeter/meters` | List meters. |
275
+ | `client.meters.update` | `PUT /openmeter/meters/{meterId}` | Update a meter. |
276
+ | `client.meters.delete` | `DELETE /openmeter/meters/{meterId}` | Delete a meter. |
277
+ | `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`. |
278
+ | `client.meters.queryCsv` | `POST /openmeter/meters/{meterId}/query` | |
279
+
280
+ ### Customers
281
+
282
+ | Method | HTTP | Description |
283
+ | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
284
+ | `client.customers.create` | `POST /openmeter/customers` | Create customer |
285
+ | `client.customers.get` | `GET /openmeter/customers/{customerId}` | Get customer |
286
+ | `client.customers.list` | `GET /openmeter/customers` | List customers |
287
+ | `client.customers.upsert` | `PUT /openmeter/customers/{customerId}` | Upsert customer |
288
+ | `client.customers.delete` | `DELETE /openmeter/customers/{customerId}` | Delete customer |
289
+ | `client.customers.billing.get` | `GET /openmeter/customers/{customerId}/billing` | Get customer billing data |
290
+ | `client.customers.billing.update` | `PUT /openmeter/customers/{customerId}/billing` | Update customer billing data |
291
+ | `client.customers.billing.updateAppData` | `PUT /openmeter/customers/{customerId}/billing/app-data` | Update customer billing app data |
292
+ | `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. |
293
+ | `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. |
294
+ | `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. |
295
+ | `client.customers.credits.grants.get` | `GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}` | Get a credit grant. |
296
+ | `client.customers.credits.grants.list` | `GET /openmeter/customers/{customerId}/credits/grants` | List credit grants. |
297
+ | `client.customers.credits.balance.get` | `GET /openmeter/customers/{customerId}/credits/balance` | Get a credit balance. |
298
+ | `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 |
299
+ | `client.customers.credits.grants.void` | `POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/void` | Void a credit grant, forfeiting the remaining unused balance. Voiding is a forward-looking, irreversible operation. Credits already consumed by usage remain unaffected — only the remaining balance is forfeited. The grant reads as `voided` status afterwards. Payment state is not adjusted when `payment_adjustment` is `none`, so invoice-backed or externally collected payments may still collect the original amount. Only `active` grants can be voided; voiding a pending, expired, or fully consumed grant returns a conflict. Retrying a successful void is an idempotent success. |
300
+ | `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. |
301
+ | `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. |
302
+ | `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. |
303
+ | `client.customers.charges.create` | `POST /openmeter/customers/{customerId}/charges` | Create customer charge. |
304
+
305
+ ### Entitlements
306
+
307
+ | Method | HTTP | Description |
308
+ | ---------------------------------------- | ---------------------------------------------------------- | -------------------------------- |
309
+ | `client.entitlements.listCustomerAccess` | `GET /openmeter/customers/{customerId}/entitlement-access` | List customer entitlement access |
310
+
311
+ ### Subscriptions
312
+
313
+ | Method | HTTP | Description |
314
+ | -------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
315
+ | `client.subscriptions.create` | `POST /openmeter/subscriptions` | Create subscription |
316
+ | `client.subscriptions.list` | `GET /openmeter/subscriptions` | List subscriptions |
317
+ | `client.subscriptions.get` | `GET /openmeter/subscriptions/{subscriptionId}` | Get subscription |
318
+ | `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. |
319
+ | `client.subscriptions.unscheduleCancelation` | `POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation` | Unschedules the subscription cancelation. |
320
+ | `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. |
321
+ | `client.subscriptions.listAddons` | `GET /openmeter/subscriptions/{subscriptionId}/addons` | List the add-ons of a subscription. |
322
+ | `client.subscriptions.getAddon` | `GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}` | Get an add-on association for a subscription. |
323
+
324
+ ### Apps
325
+
326
+ | Method | HTTP | Description |
327
+ | ---------------------------- | -------------------------------------- | -------------------------------- |
328
+ | `client.apps.list` | `GET /openmeter/apps` | List installed apps. |
329
+ | `client.apps.get` | `GET /openmeter/apps/{appId}` | Get an installed app. |
330
+ | `client.apps.listCatalog` | `GET /openmeter/app-catalog` | List available apps. |
331
+ | `client.apps.getCatalogItem` | `GET /openmeter/app-catalog/{appType}` | Get an app catalog item by type. |
332
+ | `client.apps.install` | `POST /openmeter/app-catalog/install` | Install an app from the catalog. |
333
+
334
+ ### Billing
335
+
336
+ | Method | HTTP | Description |
337
+ | ------------------------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
338
+ | `client.billing.listProfiles` | `GET /openmeter/profiles` | List billing profiles. |
339
+ | `client.billing.createProfile` | `POST /openmeter/profiles` | Create a new billing profile. Billing profiles contain the settings for billing and controls invoice generation. An organization can have multiple billing profiles defined. A billing profile is linked to a specific app. This association is established during the billing profile's creation and remains immutable. |
340
+ | `client.billing.getProfile` | `GET /openmeter/profiles/{id}` | Get a billing profile. |
341
+ | `client.billing.updateProfile` | `PUT /openmeter/profiles/{id}` | Update a billing profile. |
342
+ | `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 |
343
+
344
+ ### Tax
345
+
346
+ | Method | HTTP | Description |
347
+ | ----------------------- | ----------------------------------------- | --------------- |
348
+ | `client.tax.createCode` | `POST /openmeter/tax-codes` | Create tax code |
349
+ | `client.tax.getCode` | `GET /openmeter/tax-codes/{taxCodeId}` | Get tax code |
350
+ | `client.tax.listCodes` | `GET /openmeter/tax-codes` | List tax codes |
351
+ | `client.tax.upsertCode` | `PUT /openmeter/tax-codes/{taxCodeId}` | Upsert tax code |
352
+ | `client.tax.deleteCode` | `DELETE /openmeter/tax-codes/{taxCodeId}` | Delete tax code |
353
+
354
+ ### Features
355
+
356
+ | Method | HTTP | Description |
357
+ | --------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------- |
358
+ | `client.features.list` | `GET /openmeter/features` | List all features. |
359
+ | `client.features.create` | `POST /openmeter/features` | Create a feature. |
360
+ | `client.features.get` | `GET /openmeter/features/{featureId}` | Get a feature by id. |
361
+ | `client.features.update` | `PATCH /openmeter/features/{featureId}` | Update a feature by id. Currently only the unit_cost field can be updated. |
362
+ | `client.features.delete` | `DELETE /openmeter/features/{featureId}` | Delete a feature by id. |
363
+ | `client.features.queryCost` | `POST /openmeter/features/{featureId}/cost/query` | Query the cost of a feature. |
364
+
365
+ ### LLMCost
366
+
367
+ | Method | HTTP | Description |
368
+ | ------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------- |
369
+ | `client.llmCost.listPrices` | `GET /openmeter/llm-cost/prices` | List global LLM cost prices. Returns prices with overrides applied if any. |
370
+ | `client.llmCost.getPrice` | `GET /openmeter/llm-cost/prices/{priceId}` | Get a specific LLM cost price by ID. Returns the price with overrides applied if any. |
371
+ | `client.llmCost.listOverrides` | `GET /openmeter/llm-cost/overrides` | List per-namespace price overrides. |
372
+ | `client.llmCost.createOverride` | `POST /openmeter/llm-cost/overrides` | Create a per-namespace price override. |
373
+ | `client.llmCost.deleteOverride` | `DELETE /openmeter/llm-cost/overrides/{priceId}` | Delete a per-namespace price override. |
374
+
375
+ ### Plans
376
+
377
+ | Method | HTTP | Description |
378
+ | ---------------------- | ---------------------------------------- | ----------------------- |
379
+ | `client.plans.list` | `GET /openmeter/plans` | List all plans. |
380
+ | `client.plans.create` | `POST /openmeter/plans` | Create a new plan. |
381
+ | `client.plans.update` | `PUT /openmeter/plans/{planId}` | Update a plan by id. |
382
+ | `client.plans.get` | `GET /openmeter/plans/{planId}` | Get a plan by id. |
383
+ | `client.plans.delete` | `DELETE /openmeter/plans/{planId}` | Delete a plan by id. |
384
+ | `client.plans.archive` | `POST /openmeter/plans/{planId}/archive` | Archive a plan version. |
385
+ | `client.plans.publish` | `POST /openmeter/plans/{planId}/publish` | Publish a plan version. |
386
+
387
+ ### Addons
388
+
389
+ | Method | HTTP | Description |
390
+ | ----------------------- | ------------------------------------------ | -------------------------- |
391
+ | `client.addons.list` | `GET /openmeter/addons` | List all add-ons. |
392
+ | `client.addons.create` | `POST /openmeter/addons` | Create a new add-on. |
393
+ | `client.addons.update` | `PUT /openmeter/addons/{addonId}` | Update an add-on by id. |
394
+ | `client.addons.get` | `GET /openmeter/addons/{addonId}` | Get add-on by id. |
395
+ | `client.addons.delete` | `DELETE /openmeter/addons/{addonId}` | Soft delete add-on by id. |
396
+ | `client.addons.archive` | `POST /openmeter/addons/{addonId}/archive` | Archive an add-on version. |
397
+ | `client.addons.publish` | `POST /openmeter/addons/{addonId}/publish` | Publish an add-on version. |
398
+
399
+ ### PlanAddons
400
+
401
+ | Method | HTTP | Description |
402
+ | -------------------------- | ------------------------------------------------------- | ---------------------------------------- |
403
+ | `client.planAddons.list` | `GET /openmeter/plans/{planId}/addons` | List add-ons associated with a plan. |
404
+ | `client.planAddons.create` | `POST /openmeter/plans/{planId}/addons` | Add an add-on to a plan. |
405
+ | `client.planAddons.get` | `GET /openmeter/plans/{planId}/addons/{planAddonId}` | Get an add-on association for a plan. |
406
+ | `client.planAddons.update` | `PUT /openmeter/plans/{planId}/addons/{planAddonId}` | Update an add-on association for a plan. |
407
+ | `client.planAddons.delete` | `DELETE /openmeter/plans/{planId}/addons/{planAddonId}` | Remove an add-on from a plan. |
408
+
409
+ ### Defaults
410
+
411
+ | Method | HTTP | Description |
412
+ | -------------------------------------------- | ----------------------------------- | ------------------------------------- |
413
+ | `client.defaults.getOrganizationTaxCodes` | `GET /openmeter/defaults/tax-codes` | Get organization default tax codes |
414
+ | `client.defaults.updateOrganizationTaxCodes` | `PUT /openmeter/defaults/tax-codes` | Update organization default tax codes |
415
+
416
+ ## Internal Operations
417
+
418
+ Operations marked internal in the API definition are exposed under
419
+ `client.internal.*`, quarantined from the customer surface. They are not
420
+ intended for customer use: they may require additional permissions, and
421
+ they can change or be removed without notice or semver consideration.
422
+
423
+ ### Internal Subscriptions
424
+
425
+ | Method | HTTP | Description |
426
+ | ------------------------------------------- | ------------------------------------------------------- | ----------------------------- |
427
+ | `client.internal.subscriptions.createAddon` | `POST /openmeter/subscriptions/{subscriptionId}/addons` | Add add-on to a subscription. |
428
+
429
+ ### Internal Invoices
430
+
431
+ | Method | HTTP | Description |
432
+ | --------------------------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
433
+ | `client.internal.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. |
434
+ | `client.internal.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. |
435
+ | `client.internal.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. |
436
+ | `client.internal.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. |
437
+ | `client.internal.invoices.advance` | `POST /openmeter/billing/invoices/{invoiceId}/advance` | Advance a billing invoice. Advances the invoice to the next workflow state. The next state is determined by the invoice's current status and workflow configuration. Only invoices in draft or issued status can be advanced. |
438
+ | `client.internal.invoices.approve` | `POST /openmeter/billing/invoices/{invoiceId}/approve` | Approve a billing invoice. This call instantly sends the invoice to the customer using the configured billing profile app. This call is valid in two invoice statuses: - draft: the invoice will be sent to the customer, the invoice state becomes issued - manual_approval_needed: the invoice will be sent to the customer, the invoice state becomes issued |
439
+ | `client.internal.invoices.retry` | `POST /openmeter/billing/invoices/{invoiceId}/retry` | Retry sending a billing invoice. Retry advancing the invoice after a failed attempt. The action can be called when the invoice's statusDetails' actions field contain the "retry" action. |
440
+ | `client.internal.invoices.snapshotQuantities` | `POST /openmeter/billing/invoices/{invoiceId}/snapshot-quantities` | Snapshot quantities for usage-based line items. This call will snapshot the quantities for all usage based line items in the invoice. This call is only valid in draft.waiting_for_collection status, where the collection period can be skipped using this action. |
441
+
442
+ ### Internal Currencies
443
+
444
+ | Method | HTTP | Description |
445
+ | ------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
446
+ | `client.internal.currencies.list` | `GET /openmeter/currencies` | List currencies supported by the billing system. |
447
+ | `client.internal.currencies.createCustomCurrency` | `POST /openmeter/currencies/custom` | Create a custom currency. This operation allows defining your own custom currency for billing purposes. |
448
+ | `client.internal.currencies.listCostBases` | `GET /openmeter/currencies/custom/{currencyId}/cost-bases` | List cost bases for a currency. For custom currencies, there can be multiple cost bases with different `effective_from` dates. |
449
+ | `client.internal.currencies.createCostBasis` | `POST /openmeter/currencies/custom/{currencyId}/cost-bases` | Create a cost basis for a currency. |
450
+
451
+ ### Internal Governance
452
+
453
+ | Method | HTTP | Description |
454
+ | ---------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
455
+ | `client.internal.governance.queryAccess` | `POST /openmeter/governance/query` | Query feature access for a list of customers. The endpoint resolves each provided identifier to a customer and returns the access status for the requested features, plus optional credit balance availability. _Designed to be called on a fixed refresh interval and the query response is intended to be cached._ |
456
+
457
+ ## Runtime Validation (validate option)
458
+
459
+ `validate` is off by default. The SDK's normal request/response mapping
460
+ only renames keys and converts dates — it never rejects a payload — so
461
+ an additive server-side change (a new response field, a new enum value)
462
+ never breaks a client running an older SDK version.
463
+
464
+ Set `validate: true` to additionally check the wire payload — the
465
+ request body after mapping to snake_case, and the raw response before
466
+ mapping back — against the generated `…Wire` schemas. Those schemas are
467
+ strict: an unknown field or an unrecognized enum value fails validation
468
+ instead of being silently accepted. That makes `validate` a tool for
469
+ catching SDK/server contract drift in development or CI, not something
470
+ to run in production, where forward compatibility with additive server
471
+ changes matters more than strict rejection.
472
+
473
+ ```typescript
474
+ import { OpenMeter, ValidationError } from '@openmeter/client'
475
+
476
+ const client = new OpenMeter({
477
+ baseUrl: 'https://openmeter.cloud/api/v3',
478
+ apiKey: process.env.OPENMETER_API_KEY,
479
+ validate: true,
480
+ })
481
+
482
+ try {
483
+ await client.meters.get({ meterId: 'meter_123' })
484
+ } catch (error) {
485
+ if (error instanceof ValidationError) {
486
+ console.error(error.issues)
487
+ }
488
+ }
489
+ ```
490
+
491
+ The standalone functions surface the same failure as a `Result` instead
492
+ of throwing — check `result.error instanceof ValidationError`.
493
+
494
+ ## Zod Schemas (./zod export)
495
+
496
+ `@openmeter/client/zod` exports every model twice: once shaped like the
497
+ SDK's public surface (camelCase keys, `Date` for date-time fields — the
498
+ same shape `meter.eventType`/`meter.createdAt` have in TypeScript) and
499
+ once as a strict `…Wire` schema shaped like the literal JSON the server
500
+ sends and accepts (snake_case keys, RFC 3339 date-time strings, unknown
501
+ fields rejected) — the same `…Wire` schemas the `validate` option checks
502
+ internally.
503
+
504
+ Use the public schemas to validate a payload the SDK did not produce —
505
+ a webhook body, a cached record, a test fixture — before trusting its
506
+ shape:
507
+
508
+ ```typescript
509
+ import * as schemas from '@openmeter/client/zod'
510
+
511
+ const parsed = schemas.meter.safeParse({
512
+ id: '01HZY3W6VXQK6H3NPC6DFA0PJT',
513
+ name: 'Tokens',
514
+ key: 'tokens',
515
+ aggregation: 'sum',
516
+ eventType: 'request',
517
+ createdAt: new Date(),
518
+ updatedAt: new Date(),
519
+ })
520
+
521
+ if (parsed.success) {
522
+ console.log(parsed.data.eventType)
523
+ }
524
+ ```
525
+
526
+ ## Error Handling
527
+
528
+ A non-2xx response rejects with an `HTTPError` (`error.name === 'HTTPError'`)
529
+ carrying the problem-details fields (`status`, `type`, `title`, `url`)
530
+ from the response.
531
+
532
+ ```typescript
533
+ import { OpenMeter, HTTPError } from '@openmeter/client'
534
+
535
+ const client = new OpenMeter({
536
+ baseUrl: 'https://openmeter.cloud/api/v3',
537
+ apiKey: process.env.OPENMETER_API_KEY,
538
+ })
539
+
540
+ try {
541
+ await client.meters.get({ meterId: 'unknown' })
542
+ } catch (error) {
543
+ if (error instanceof HTTPError) {
544
+ console.error(error.status, error.title, error.type)
545
+ }
546
+ }
547
+ ```
548
+
549
+ `error.retryAfter` is the delta-seconds form of a numeric `Retry-After`
550
+ header (the common case on 429 and 503 responses) and `undefined`
551
+ otherwise. A 400 Bad Request additionally carries a typed
552
+ `error.invalidParameters` array describing which fields failed
553
+ validation; `error.getField(key)` is an untyped escape hatch for any
554
+ other problem-details extension member:
555
+
556
+ ```typescript
557
+ import { OpenMeter, HTTPError } from '@openmeter/client'
558
+
559
+ const client = new OpenMeter({
560
+ baseUrl: 'https://openmeter.cloud/api/v3',
561
+ apiKey: process.env.OPENMETER_API_KEY,
562
+ })
563
+
564
+ try {
565
+ await client.meters.create({
566
+ name: 'Tokens',
567
+ key: 'tokens',
568
+ aggregation: 'sum',
569
+ eventType: 'request',
570
+ })
571
+ } catch (error) {
572
+ if (error instanceof HTTPError && error.status === 400) {
573
+ for (const param of error.invalidParameters ?? []) {
574
+ console.error(param)
575
+ }
576
+ }
577
+ }
578
+ ```
579
+
580
+ The SDK's other typed errors are `ValidationError` (see
581
+ [Runtime Validation (validate option)](#runtime-validation-validate-option)), `UnsafeIntegerError`
582
+ (an `int64`/`uint64` value exceeds what JSON can represent without
583
+ precision loss), `DepthLimitExceededError` (response data nested deeper
584
+ than the mapper's safety limit), and `PaginationLimitExceededError` (an
585
+ [Pagination](#pagination) iterable exceeded
586
+ its page-count safety limit) — each distinguished the same way, by
587
+ `instanceof` or by `.name`.
588
+
589
+ ## Standalone Functions
590
+
591
+ Every method is also available as a standalone, tree-shakeable function
592
+ that takes a `Client` and returns a `Result` instead of throwing.
593
+
594
+ ```typescript
595
+ import { Client, funcs } from '@openmeter/client'
596
+
597
+ const client = new Client({
598
+ baseUrl: 'https://openmeter.cloud/api/v3',
599
+ apiKey: process.env.OPENMETER_API_KEY,
600
+ })
601
+
602
+ const result = await funcs.listMeters(client)
603
+ if (result.ok) {
604
+ console.log(result.value)
605
+ } else {
606
+ console.error(result.error)
607
+ }
608
+ ```
609
+
610
+ `ok`, `err`, and `unwrap` — the helpers `Result` is built from — are
611
+ exported too, so a func call can be unwrapped back into a throwing call
612
+ where that is more convenient:
613
+
614
+ ```typescript
615
+ import { Client, funcs, unwrap } from '@openmeter/client'
616
+
617
+ const client = new Client({
618
+ baseUrl: 'https://openmeter.cloud/api/v3',
619
+ apiKey: process.env.OPENMETER_API_KEY,
620
+ })
621
+
622
+ const meters = unwrap(await funcs.listMeters(client))
623
+ ```
api/spec/packages/aip-client-javascript/package.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@openmeter/client",
3
+ "version": "1.0.0",
4
+ "description": "Official TypeScript SDK for the OpenMeter API — usage metering and billing",
5
+ "keywords": [
6
+ "openmeter",
7
+ "metering",
8
+ "billing",
9
+ "usage-based-billing",
10
+ "entitlements",
11
+ "sdk",
12
+ "api-client"
13
+ ],
14
+ "license": "Apache-2.0",
15
+ "homepage": "https://openmeter.io",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/openmeterio/openmeter.git",
19
+ "directory": "api/spec/packages/aip-client-javascript"
20
+ },
21
+ "bugs": "https://github.com/openmeterio/openmeter/issues",
22
+ "type": "module",
23
+ "engines": {
24
+ "node": ">=22"
25
+ },
26
+ "sideEffects": false,
27
+ "dependencies": {
28
+ "ky": "^2.0.2",
29
+ "zod": "^4.4.3"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "25.9.2",
33
+ "typescript": "5.5.2"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc",
37
+ "prepack": "tsc",
38
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.tests.json"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "!dist/**/*.assert.*",
43
+ "!dist/**/*.map",
44
+ "!dist/**/*.tsbuildinfo"
45
+ ],
46
+ "main": "./dist/index.js",
47
+ "types": "./dist/index.d.ts",
48
+ "exports": {
49
+ "./zod": {
50
+ "types": "./dist/models/schemas.d.ts",
51
+ "default": "./dist/models/schemas.js"
52
+ },
53
+ ".": {
54
+ "types": "./dist/index.d.ts",
55
+ "default": "./dist/index.js"
56
+ },
57
+ "./package.json": "./package.json"
58
+ }
59
+ }
api/spec/packages/aip-client-javascript/src/core.ts ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import ky, { type KyInstance as HTTPClient } from 'ky'
4
+ import { type SDKOptions } from './lib/config.js'
5
+ import { encodePath } from './lib/encodings.js'
6
+ import { SDK_VERSION } from './lib/version.js'
7
+
8
+ export class Client {
9
+ readonly _options: SDKOptions
10
+ readonly _http: HTTPClient
11
+
12
+ constructor(options: SDKOptions) {
13
+ this._options = options
14
+
15
+ let baseUrl =
16
+ typeof options.baseUrl === 'string'
17
+ ? encodePath(options.baseUrl, options.serverVariables ?? {})
18
+ : String(options.baseUrl)
19
+ if (!baseUrl.endsWith('/')) {
20
+ baseUrl = `${baseUrl}/`
21
+ }
22
+
23
+ this._http = ky.create({
24
+ ...options,
25
+ baseUrl,
26
+ prefix: undefined,
27
+ hooks: {
28
+ ...options.hooks,
29
+ beforeRequest: [
30
+ ...(options.hooks?.beforeRequest ?? []),
31
+ async ({ request }) => {
32
+ // User-Agent is settable on the web but is not CORS-safelisted, so
33
+ // setting it would preflight otherwise-simple cross-origin requests.
34
+ // Gate on a positive Node check, not `window`: workers are also
35
+ // CORS-bound yet have no `window`.
36
+ if (
37
+ typeof process !== 'undefined' &&
38
+ process.versions?.node != null &&
39
+ !request.headers.has('User-Agent')
40
+ ) {
41
+ request.headers.set('User-Agent', `openmeter-node/${SDK_VERSION}`)
42
+ }
43
+
44
+ const token =
45
+ typeof options.apiKey === 'function'
46
+ ? await options.apiKey()
47
+ : options.apiKey
48
+ if (token) {
49
+ request.headers.set('Authorization', `Bearer ${token}`)
50
+ }
51
+ },
52
+ ],
53
+ },
54
+ })
55
+ }
56
+ }
57
+
58
+ export function http(client: Client): HTTPClient {
59
+ return client._http
60
+ }
61
+
62
+ export type { HTTPClient }
api/spec/packages/aip-client-javascript/src/funcs/addons.ts ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListAddonsRequest,
17
+ ListAddonsResponse,
18
+ CreateAddonRequest,
19
+ CreateAddonResponse,
20
+ UpdateAddonRequest,
21
+ UpdateAddonResponse,
22
+ GetAddonRequest,
23
+ GetAddonResponse,
24
+ DeleteAddonRequest,
25
+ DeleteAddonResponse,
26
+ ArchiveAddonRequest,
27
+ ArchiveAddonResponse,
28
+ PublishAddonRequest,
29
+ PublishAddonResponse,
30
+ } from '../models/operations/addons.js'
31
+
32
+ /**
33
+ * List add-ons
34
+ *
35
+ * List all add-ons.
36
+ *
37
+ * GET /openmeter/addons
38
+ */
39
+ export function listAddons(
40
+ client: Client,
41
+ req: ListAddonsRequest = {},
42
+ options?: RequestOptions,
43
+ ): Promise<Result<ListAddonsResponse>> {
44
+ return request(() => {
45
+ if (client._options.validate && req.sort !== undefined) {
46
+ assertValid(schemas.listAddonsQueryParams.shape.sort, req.sort)
47
+ }
48
+ const query = toWire(
49
+ {
50
+ page: req.page,
51
+ sort: encodeSort(req.sort, toSnakeCase),
52
+ filter: req.filter,
53
+ },
54
+ schemas.listAddonsQueryParams,
55
+ )
56
+ if (client._options.validate) {
57
+ assertValid(schemas.listAddonsQueryParamsWire, query)
58
+ }
59
+ const searchParams = toURLSearchParams(query)
60
+ return http(client)
61
+ .get('openmeter/addons', { ...options, searchParams })
62
+ .json()
63
+ .then((data) => {
64
+ if (client._options.validate) {
65
+ assertValid(schemas.listAddonsResponseWire, data)
66
+ }
67
+ return fromWire(data, schemas.listAddonsResponse)
68
+ })
69
+ })
70
+ }
71
+
72
+ /**
73
+ * Create add-on
74
+ *
75
+ * Create a new add-on.
76
+ *
77
+ * POST /openmeter/addons
78
+ */
79
+ export function createAddon(
80
+ client: Client,
81
+ req: CreateAddonRequest,
82
+ options?: RequestOptions,
83
+ ): Promise<Result<CreateAddonResponse>> {
84
+ return request(() => {
85
+ const body = toWire(req, schemas.createAddonBody)
86
+ if (client._options.validate) {
87
+ assertValid(schemas.createAddonBodyWire, body)
88
+ }
89
+ return http(client)
90
+ .post('openmeter/addons', { ...options, json: body })
91
+ .json()
92
+ .then((data) => {
93
+ if (client._options.validate) {
94
+ assertValid(schemas.createAddonResponseWire, data)
95
+ }
96
+ return fromWire(data, schemas.createAddonResponse)
97
+ })
98
+ })
99
+ }
100
+
101
+ /**
102
+ * Update add-on
103
+ *
104
+ * Update an add-on by id.
105
+ *
106
+ * PUT /openmeter/addons/{addonId}
107
+ */
108
+ export function updateAddon(
109
+ client: Client,
110
+ req: UpdateAddonRequest,
111
+ options?: RequestOptions,
112
+ ): Promise<Result<UpdateAddonResponse>> {
113
+ return request(() => {
114
+ const pathParamsInput = {
115
+ addonId: req.addonId,
116
+ }
117
+ const pathParams = client._options.validate
118
+ ? toPathWire(pathParamsInput, schemas.updateAddonPathParams)
119
+ : pathParamsInput
120
+ if (client._options.validate) {
121
+ assertValid(schemas.updateAddonPathParamsWire, pathParams)
122
+ }
123
+ const path = `openmeter/addons/${(() => {
124
+ if (pathParams.addonId === undefined) {
125
+ throw new Error('missing path parameter: addonId')
126
+ }
127
+ return encodeURIComponent(String(pathParams.addonId))
128
+ })()}`
129
+ const body = toWire(req.body, schemas.updateAddonBody)
130
+ if (client._options.validate) {
131
+ assertValid(schemas.updateAddonBodyWire, body)
132
+ }
133
+ return http(client)
134
+ .put(path, { ...options, json: body })
135
+ .json()
136
+ .then((data) => {
137
+ if (client._options.validate) {
138
+ assertValid(schemas.updateAddonResponseWire, data)
139
+ }
140
+ return fromWire(data, schemas.updateAddonResponse)
141
+ })
142
+ })
143
+ }
144
+
145
+ /**
146
+ * Get add-on
147
+ *
148
+ * Get add-on by id.
149
+ *
150
+ * GET /openmeter/addons/{addonId}
151
+ */
152
+ export function getAddon(
153
+ client: Client,
154
+ req: GetAddonRequest,
155
+ options?: RequestOptions,
156
+ ): Promise<Result<GetAddonResponse>> {
157
+ return request(() => {
158
+ const pathParamsInput = {
159
+ addonId: req.addonId,
160
+ }
161
+ const pathParams = client._options.validate
162
+ ? toPathWire(pathParamsInput, schemas.getAddonPathParams)
163
+ : pathParamsInput
164
+ if (client._options.validate) {
165
+ assertValid(schemas.getAddonPathParamsWire, pathParams)
166
+ }
167
+ const path = `openmeter/addons/${(() => {
168
+ if (pathParams.addonId === undefined) {
169
+ throw new Error('missing path parameter: addonId')
170
+ }
171
+ return encodeURIComponent(String(pathParams.addonId))
172
+ })()}`
173
+ return http(client)
174
+ .get(path, options)
175
+ .json()
176
+ .then((data) => {
177
+ if (client._options.validate) {
178
+ assertValid(schemas.getAddonResponseWire, data)
179
+ }
180
+ return fromWire(data, schemas.getAddonResponse)
181
+ })
182
+ })
183
+ }
184
+
185
+ /**
186
+ * Soft delete add-on
187
+ *
188
+ * Soft delete add-on by id.
189
+ *
190
+ * DELETE /openmeter/addons/{addonId}
191
+ */
192
+ export function deleteAddon(
193
+ client: Client,
194
+ req: DeleteAddonRequest,
195
+ options?: RequestOptions,
196
+ ): Promise<Result<DeleteAddonResponse>> {
197
+ return request(async () => {
198
+ const pathParamsInput = {
199
+ addonId: req.addonId,
200
+ }
201
+ const pathParams = client._options.validate
202
+ ? toPathWire(pathParamsInput, schemas.deleteAddonPathParams)
203
+ : pathParamsInput
204
+ if (client._options.validate) {
205
+ assertValid(schemas.deleteAddonPathParamsWire, pathParams)
206
+ }
207
+ const path = `openmeter/addons/${(() => {
208
+ if (pathParams.addonId === undefined) {
209
+ throw new Error('missing path parameter: addonId')
210
+ }
211
+ return encodeURIComponent(String(pathParams.addonId))
212
+ })()}`
213
+ await http(client).delete(path, options)
214
+ })
215
+ }
216
+
217
+ /**
218
+ * Archive add-on version
219
+ *
220
+ * Archive an add-on version.
221
+ *
222
+ * POST /openmeter/addons/{addonId}/archive
223
+ */
224
+ export function archiveAddon(
225
+ client: Client,
226
+ req: ArchiveAddonRequest,
227
+ options?: RequestOptions,
228
+ ): Promise<Result<ArchiveAddonResponse>> {
229
+ return request(() => {
230
+ const pathParamsInput = {
231
+ addonId: req.addonId,
232
+ }
233
+ const pathParams = client._options.validate
234
+ ? toPathWire(pathParamsInput, schemas.archiveAddonPathParams)
235
+ : pathParamsInput
236
+ if (client._options.validate) {
237
+ assertValid(schemas.archiveAddonPathParamsWire, pathParams)
238
+ }
239
+ const path = `openmeter/addons/${(() => {
240
+ if (pathParams.addonId === undefined) {
241
+ throw new Error('missing path parameter: addonId')
242
+ }
243
+ return encodeURIComponent(String(pathParams.addonId))
244
+ })()}/archive`
245
+ return http(client)
246
+ .post(path, options)
247
+ .json()
248
+ .then((data) => {
249
+ if (client._options.validate) {
250
+ assertValid(schemas.archiveAddonResponseWire, data)
251
+ }
252
+ return fromWire(data, schemas.archiveAddonResponse)
253
+ })
254
+ })
255
+ }
256
+
257
+ /**
258
+ * Publish add-on version
259
+ *
260
+ * Publish an add-on version.
261
+ *
262
+ * POST /openmeter/addons/{addonId}/publish
263
+ */
264
+ export function publishAddon(
265
+ client: Client,
266
+ req: PublishAddonRequest,
267
+ options?: RequestOptions,
268
+ ): Promise<Result<PublishAddonResponse>> {
269
+ return request(() => {
270
+ const pathParamsInput = {
271
+ addonId: req.addonId,
272
+ }
273
+ const pathParams = client._options.validate
274
+ ? toPathWire(pathParamsInput, schemas.publishAddonPathParams)
275
+ : pathParamsInput
276
+ if (client._options.validate) {
277
+ assertValid(schemas.publishAddonPathParamsWire, pathParams)
278
+ }
279
+ const path = `openmeter/addons/${(() => {
280
+ if (pathParams.addonId === undefined) {
281
+ throw new Error('missing path parameter: addonId')
282
+ }
283
+ return encodeURIComponent(String(pathParams.addonId))
284
+ })()}/publish`
285
+ return http(client)
286
+ .post(path, options)
287
+ .json()
288
+ .then((data) => {
289
+ if (client._options.validate) {
290
+ assertValid(schemas.publishAddonResponseWire, data)
291
+ }
292
+ return fromWire(data, schemas.publishAddonResponse)
293
+ })
294
+ })
295
+ }
api/spec/packages/aip-client-javascript/src/funcs/apps.ts ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams } from '../lib/encodings.js'
7
+ import { toWire, toPathWire, fromWire, assertValid } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ ListAppsRequest,
11
+ ListAppsResponse,
12
+ GetAppRequest,
13
+ GetAppResponse,
14
+ ListAppCatalogRequest,
15
+ ListAppCatalogResponse,
16
+ GetAppCatalogItemRequest,
17
+ GetAppCatalogItemResponse,
18
+ InstallAppRequest,
19
+ InstallAppResponse,
20
+ } from '../models/operations/apps.js'
21
+
22
+ /**
23
+ * List apps
24
+ *
25
+ * List installed apps.
26
+ *
27
+ * GET /openmeter/apps
28
+ */
29
+ export function listApps(
30
+ client: Client,
31
+ req: ListAppsRequest = {},
32
+ options?: RequestOptions,
33
+ ): Promise<Result<ListAppsResponse>> {
34
+ return request(() => {
35
+ const query = toWire(
36
+ {
37
+ page: req.page,
38
+ },
39
+ schemas.listAppsQueryParams,
40
+ )
41
+ if (client._options.validate) {
42
+ assertValid(schemas.listAppsQueryParamsWire, query)
43
+ }
44
+ const searchParams = toURLSearchParams(query)
45
+ return http(client)
46
+ .get('openmeter/apps', { ...options, searchParams })
47
+ .json()
48
+ .then((data) => {
49
+ if (client._options.validate) {
50
+ assertValid(schemas.listAppsResponseWire, data)
51
+ }
52
+ return fromWire(data, schemas.listAppsResponse)
53
+ })
54
+ })
55
+ }
56
+
57
+ /**
58
+ * Get app
59
+ *
60
+ * Get an installed app.
61
+ *
62
+ * GET /openmeter/apps/{appId}
63
+ */
64
+ export function getApp(
65
+ client: Client,
66
+ req: GetAppRequest,
67
+ options?: RequestOptions,
68
+ ): Promise<Result<GetAppResponse>> {
69
+ return request(() => {
70
+ const pathParamsInput = {
71
+ appId: req.appId,
72
+ }
73
+ const pathParams = client._options.validate
74
+ ? toPathWire(pathParamsInput, schemas.getAppPathParams)
75
+ : pathParamsInput
76
+ if (client._options.validate) {
77
+ assertValid(schemas.getAppPathParamsWire, pathParams)
78
+ }
79
+ const path = `openmeter/apps/${(() => {
80
+ if (pathParams.appId === undefined) {
81
+ throw new Error('missing path parameter: appId')
82
+ }
83
+ return encodeURIComponent(String(pathParams.appId))
84
+ })()}`
85
+ return http(client)
86
+ .get(path, options)
87
+ .json()
88
+ .then((data) => {
89
+ if (client._options.validate) {
90
+ assertValid(schemas.getAppResponseWire, data)
91
+ }
92
+ return fromWire(data, schemas.getAppResponse)
93
+ })
94
+ })
95
+ }
96
+
97
+ /**
98
+ * List app catalog
99
+ *
100
+ * List available apps.
101
+ *
102
+ * GET /openmeter/app-catalog
103
+ */
104
+ export function listAppCatalog(
105
+ client: Client,
106
+ req: ListAppCatalogRequest = {},
107
+ options?: RequestOptions,
108
+ ): Promise<Result<ListAppCatalogResponse>> {
109
+ return request(() => {
110
+ const query = toWire(
111
+ {
112
+ page: req.page,
113
+ },
114
+ schemas.listAppCatalogQueryParams,
115
+ )
116
+ if (client._options.validate) {
117
+ assertValid(schemas.listAppCatalogQueryParamsWire, query)
118
+ }
119
+ const searchParams = toURLSearchParams(query)
120
+ return http(client)
121
+ .get('openmeter/app-catalog', { ...options, searchParams })
122
+ .json()
123
+ .then((data) => {
124
+ if (client._options.validate) {
125
+ assertValid(schemas.listAppCatalogResponseWire, data)
126
+ }
127
+ return fromWire(data, schemas.listAppCatalogResponse)
128
+ })
129
+ })
130
+ }
131
+
132
+ /**
133
+ * Get app catalog item by type
134
+ *
135
+ * Get an app catalog item by type.
136
+ *
137
+ * GET /openmeter/app-catalog/{appType}
138
+ */
139
+ export function getAppCatalogItem(
140
+ client: Client,
141
+ req: GetAppCatalogItemRequest,
142
+ options?: RequestOptions,
143
+ ): Promise<Result<GetAppCatalogItemResponse>> {
144
+ return request(() => {
145
+ const pathParamsInput = {
146
+ appType: req.appType,
147
+ }
148
+ const pathParams = client._options.validate
149
+ ? toPathWire(pathParamsInput, schemas.getAppCatalogItemPathParams)
150
+ : pathParamsInput
151
+ if (client._options.validate) {
152
+ assertValid(schemas.getAppCatalogItemPathParamsWire, pathParams)
153
+ }
154
+ const path = `openmeter/app-catalog/${(() => {
155
+ if (pathParams.appType === undefined) {
156
+ throw new Error('missing path parameter: appType')
157
+ }
158
+ return encodeURIComponent(String(pathParams.appType))
159
+ })()}`
160
+ return http(client)
161
+ .get(path, options)
162
+ .json()
163
+ .then((data) => {
164
+ if (client._options.validate) {
165
+ assertValid(schemas.getAppCatalogItemResponseWire, data)
166
+ }
167
+ return fromWire(data, schemas.getAppCatalogItemResponse)
168
+ })
169
+ })
170
+ }
171
+
172
+ /**
173
+ * Install app from the catalog
174
+ *
175
+ * Install an app from the catalog.
176
+ *
177
+ * POST /openmeter/app-catalog/install
178
+ */
179
+ export function installApp(
180
+ client: Client,
181
+ req: InstallAppRequest,
182
+ options?: RequestOptions,
183
+ ): Promise<Result<InstallAppResponse>> {
184
+ return request(() => {
185
+ const body = toWire(req, schemas.installAppBody)
186
+ if (client._options.validate) {
187
+ assertValid(schemas.installAppBodyWire, body)
188
+ }
189
+ return http(client)
190
+ .post('openmeter/app-catalog/install', { ...options, json: body })
191
+ .json()
192
+ .then((data) => {
193
+ if (client._options.validate) {
194
+ assertValid(schemas.installAppResponseWire, data)
195
+ }
196
+ return fromWire(data, schemas.installAppResponse)
197
+ })
198
+ })
199
+ }
api/spec/packages/aip-client-javascript/src/funcs/billing.ts ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams } from '../lib/encodings.js'
7
+ import { toWire, toPathWire, fromWire, assertValid } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ ListBillingProfilesRequest,
11
+ ListBillingProfilesResponse,
12
+ CreateBillingProfileRequest,
13
+ CreateBillingProfileResponse,
14
+ GetBillingProfileRequest,
15
+ GetBillingProfileResponse,
16
+ UpdateBillingProfileRequest,
17
+ UpdateBillingProfileResponse,
18
+ DeleteBillingProfileRequest,
19
+ DeleteBillingProfileResponse,
20
+ } from '../models/operations/billing.js'
21
+
22
+ /**
23
+ * List billing profiles
24
+ *
25
+ * List billing profiles.
26
+ *
27
+ * GET /openmeter/profiles
28
+ */
29
+ export function listBillingProfiles(
30
+ client: Client,
31
+ req: ListBillingProfilesRequest = {},
32
+ options?: RequestOptions,
33
+ ): Promise<Result<ListBillingProfilesResponse>> {
34
+ return request(() => {
35
+ const query = toWire(
36
+ {
37
+ page: req.page,
38
+ },
39
+ schemas.listBillingProfilesQueryParams,
40
+ )
41
+ if (client._options.validate) {
42
+ assertValid(schemas.listBillingProfilesQueryParamsWire, query)
43
+ }
44
+ const searchParams = toURLSearchParams(query)
45
+ return http(client)
46
+ .get('openmeter/profiles', { ...options, searchParams })
47
+ .json()
48
+ .then((data) => {
49
+ if (client._options.validate) {
50
+ assertValid(schemas.listBillingProfilesResponseWire, data)
51
+ }
52
+ return fromWire(data, schemas.listBillingProfilesResponse)
53
+ })
54
+ })
55
+ }
56
+
57
+ /**
58
+ * Create a new billing profile
59
+ *
60
+ * Create a new billing profile.
61
+ *
62
+ * Billing profiles contain the settings for billing and controls invoice
63
+ * generation. An organization can have multiple billing profiles defined. A
64
+ * billing profile is linked to a specific app. This association is established
65
+ * during the billing profile's creation and remains immutable.
66
+ *
67
+ * POST /openmeter/profiles
68
+ */
69
+ export function createBillingProfile(
70
+ client: Client,
71
+ req: CreateBillingProfileRequest,
72
+ options?: RequestOptions,
73
+ ): Promise<Result<CreateBillingProfileResponse>> {
74
+ return request(() => {
75
+ const body = toWire(req, schemas.createBillingProfileBody)
76
+ if (client._options.validate) {
77
+ assertValid(schemas.createBillingProfileBodyWire, body)
78
+ }
79
+ return http(client)
80
+ .post('openmeter/profiles', { ...options, json: body })
81
+ .json()
82
+ .then((data) => {
83
+ if (client._options.validate) {
84
+ assertValid(schemas.createBillingProfileResponseWire, data)
85
+ }
86
+ return fromWire(data, schemas.createBillingProfileResponse)
87
+ })
88
+ })
89
+ }
90
+
91
+ /**
92
+ * Get a billing profile
93
+ *
94
+ * Get a billing profile.
95
+ *
96
+ * GET /openmeter/profiles/{id}
97
+ */
98
+ export function getBillingProfile(
99
+ client: Client,
100
+ req: GetBillingProfileRequest,
101
+ options?: RequestOptions,
102
+ ): Promise<Result<GetBillingProfileResponse>> {
103
+ return request(() => {
104
+ const pathParamsInput = {
105
+ id: req.id,
106
+ }
107
+ const pathParams = client._options.validate
108
+ ? toPathWire(pathParamsInput, schemas.getBillingProfilePathParams)
109
+ : pathParamsInput
110
+ if (client._options.validate) {
111
+ assertValid(schemas.getBillingProfilePathParamsWire, pathParams)
112
+ }
113
+ const path = `openmeter/profiles/${(() => {
114
+ if (pathParams.id === undefined) {
115
+ throw new Error('missing path parameter: id')
116
+ }
117
+ return encodeURIComponent(String(pathParams.id))
118
+ })()}`
119
+ return http(client)
120
+ .get(path, options)
121
+ .json()
122
+ .then((data) => {
123
+ if (client._options.validate) {
124
+ assertValid(schemas.getBillingProfileResponseWire, data)
125
+ }
126
+ return fromWire(data, schemas.getBillingProfileResponse)
127
+ })
128
+ })
129
+ }
130
+
131
+ /**
132
+ * Update a billing profile
133
+ *
134
+ * Update a billing profile.
135
+ *
136
+ * PUT /openmeter/profiles/{id}
137
+ */
138
+ export function updateBillingProfile(
139
+ client: Client,
140
+ req: UpdateBillingProfileRequest,
141
+ options?: RequestOptions,
142
+ ): Promise<Result<UpdateBillingProfileResponse>> {
143
+ return request(() => {
144
+ const pathParamsInput = {
145
+ id: req.id,
146
+ }
147
+ const pathParams = client._options.validate
148
+ ? toPathWire(pathParamsInput, schemas.updateBillingProfilePathParams)
149
+ : pathParamsInput
150
+ if (client._options.validate) {
151
+ assertValid(schemas.updateBillingProfilePathParamsWire, pathParams)
152
+ }
153
+ const path = `openmeter/profiles/${(() => {
154
+ if (pathParams.id === undefined) {
155
+ throw new Error('missing path parameter: id')
156
+ }
157
+ return encodeURIComponent(String(pathParams.id))
158
+ })()}`
159
+ const body = toWire(req.body, schemas.updateBillingProfileBody)
160
+ if (client._options.validate) {
161
+ assertValid(schemas.updateBillingProfileBodyWire, body)
162
+ }
163
+ return http(client)
164
+ .put(path, { ...options, json: body })
165
+ .json()
166
+ .then((data) => {
167
+ if (client._options.validate) {
168
+ assertValid(schemas.updateBillingProfileResponseWire, data)
169
+ }
170
+ return fromWire(data, schemas.updateBillingProfileResponse)
171
+ })
172
+ })
173
+ }
174
+
175
+ /**
176
+ * Delete a billing profile
177
+ *
178
+ * Delete a billing profile.
179
+ *
180
+ * Only such billing profiles can be deleted that are:
181
+ *
182
+ * - not the default profile
183
+ * - not pinned to any customer using customer overrides
184
+ * - only have finalized invoices
185
+ *
186
+ * DELETE /openmeter/profiles/{id}
187
+ */
188
+ export function deleteBillingProfile(
189
+ client: Client,
190
+ req: DeleteBillingProfileRequest,
191
+ options?: RequestOptions,
192
+ ): Promise<Result<DeleteBillingProfileResponse>> {
193
+ return request(async () => {
194
+ const pathParamsInput = {
195
+ id: req.id,
196
+ }
197
+ const pathParams = client._options.validate
198
+ ? toPathWire(pathParamsInput, schemas.deleteBillingProfilePathParams)
199
+ : pathParamsInput
200
+ if (client._options.validate) {
201
+ assertValid(schemas.deleteBillingProfilePathParamsWire, pathParams)
202
+ }
203
+ const path = `openmeter/profiles/${(() => {
204
+ if (pathParams.id === undefined) {
205
+ throw new Error('missing path parameter: id')
206
+ }
207
+ return encodeURIComponent(String(pathParams.id))
208
+ })()}`
209
+ await http(client).delete(path, options)
210
+ })
211
+ }
api/spec/packages/aip-client-javascript/src/funcs/currencies.ts ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListCurrenciesRequest,
17
+ ListCurrenciesResponse,
18
+ CreateCustomCurrencyRequest,
19
+ CreateCustomCurrencyResponse,
20
+ ListCostBasesRequest,
21
+ ListCostBasesResponse,
22
+ CreateCostBasisRequest,
23
+ CreateCostBasisResponse,
24
+ } from '../models/operations/currencies.js'
25
+
26
+ /**
27
+ * List currencies
28
+ *
29
+ * List currencies supported by the billing system.
30
+ *
31
+ * GET /openmeter/currencies
32
+ */
33
+ export function listCurrencies(
34
+ client: Client,
35
+ req: ListCurrenciesRequest = {},
36
+ options?: RequestOptions,
37
+ ): Promise<Result<ListCurrenciesResponse>> {
38
+ return request(() => {
39
+ if (client._options.validate && req.sort !== undefined) {
40
+ assertValid(schemas.listCurrenciesQueryParams.shape.sort, req.sort)
41
+ }
42
+ const query = toWire(
43
+ {
44
+ page: req.page,
45
+ sort: encodeSort(req.sort, toSnakeCase),
46
+ filter: req.filter,
47
+ },
48
+ schemas.listCurrenciesQueryParams,
49
+ )
50
+ if (client._options.validate) {
51
+ assertValid(schemas.listCurrenciesQueryParamsWire, query)
52
+ }
53
+ const searchParams = toURLSearchParams(query)
54
+ return http(client)
55
+ .get('openmeter/currencies', { ...options, searchParams })
56
+ .json()
57
+ .then((data) => {
58
+ if (client._options.validate) {
59
+ assertValid(schemas.listCurrenciesResponseWire, data)
60
+ }
61
+ return fromWire(data, schemas.listCurrenciesResponse)
62
+ })
63
+ })
64
+ }
65
+
66
+ /**
67
+ * Create custom currency
68
+ *
69
+ * Create a custom currency. This operation allows defining your own custom
70
+ * currency for billing purposes.
71
+ *
72
+ * POST /openmeter/currencies/custom
73
+ */
74
+ export function createCustomCurrency(
75
+ client: Client,
76
+ req: CreateCustomCurrencyRequest,
77
+ options?: RequestOptions,
78
+ ): Promise<Result<CreateCustomCurrencyResponse>> {
79
+ return request(() => {
80
+ const body = toWire(req, schemas.createCustomCurrencyBody)
81
+ if (client._options.validate) {
82
+ assertValid(schemas.createCustomCurrencyBodyWire, body)
83
+ }
84
+ return http(client)
85
+ .post('openmeter/currencies/custom', { ...options, json: body })
86
+ .json()
87
+ .then((data) => {
88
+ if (client._options.validate) {
89
+ assertValid(schemas.createCustomCurrencyResponseWire, data)
90
+ }
91
+ return fromWire(data, schemas.createCustomCurrencyResponse)
92
+ })
93
+ })
94
+ }
95
+
96
+ /**
97
+ * List cost bases
98
+ *
99
+ * List cost bases for a currency. For custom currencies, there can be multiple
100
+ * cost bases with different `effective_from` dates.
101
+ *
102
+ * GET /openmeter/currencies/custom/{currencyId}/cost-bases
103
+ */
104
+ export function listCostBases(
105
+ client: Client,
106
+ req: ListCostBasesRequest,
107
+ options?: RequestOptions,
108
+ ): Promise<Result<ListCostBasesResponse>> {
109
+ return request(() => {
110
+ const pathParamsInput = {
111
+ currencyId: req.currencyId,
112
+ }
113
+ const pathParams = client._options.validate
114
+ ? toPathWire(pathParamsInput, schemas.listCostBasesPathParams)
115
+ : pathParamsInput
116
+ if (client._options.validate) {
117
+ assertValid(schemas.listCostBasesPathParamsWire, pathParams)
118
+ }
119
+ const path = `openmeter/currencies/custom/${(() => {
120
+ if (pathParams.currencyId === undefined) {
121
+ throw new Error('missing path parameter: currencyId')
122
+ }
123
+ return encodeURIComponent(String(pathParams.currencyId))
124
+ })()}/cost-bases`
125
+ const query = toWire(
126
+ {
127
+ filter: req.filter,
128
+ page: req.page,
129
+ },
130
+ schemas.listCostBasesQueryParams,
131
+ )
132
+ if (client._options.validate) {
133
+ assertValid(schemas.listCostBasesQueryParamsWire, query)
134
+ }
135
+ const searchParams = toURLSearchParams(query)
136
+ return http(client)
137
+ .get(path, { ...options, searchParams })
138
+ .json()
139
+ .then((data) => {
140
+ if (client._options.validate) {
141
+ assertValid(schemas.listCostBasesResponseWire, data)
142
+ }
143
+ return fromWire(data, schemas.listCostBasesResponse)
144
+ })
145
+ })
146
+ }
147
+
148
+ /**
149
+ * Create cost basis
150
+ *
151
+ * Create a cost basis for a currency.
152
+ *
153
+ * POST /openmeter/currencies/custom/{currencyId}/cost-bases
154
+ */
155
+ export function createCostBasis(
156
+ client: Client,
157
+ req: CreateCostBasisRequest,
158
+ options?: RequestOptions,
159
+ ): Promise<Result<CreateCostBasisResponse>> {
160
+ return request(() => {
161
+ const pathParamsInput = {
162
+ currencyId: req.currencyId,
163
+ }
164
+ const pathParams = client._options.validate
165
+ ? toPathWire(pathParamsInput, schemas.createCostBasisPathParams)
166
+ : pathParamsInput
167
+ if (client._options.validate) {
168
+ assertValid(schemas.createCostBasisPathParamsWire, pathParams)
169
+ }
170
+ const path = `openmeter/currencies/custom/${(() => {
171
+ if (pathParams.currencyId === undefined) {
172
+ throw new Error('missing path parameter: currencyId')
173
+ }
174
+ return encodeURIComponent(String(pathParams.currencyId))
175
+ })()}/cost-bases`
176
+ const body = toWire(req.body, schemas.createCostBasisBody)
177
+ if (client._options.validate) {
178
+ assertValid(schemas.createCostBasisBodyWire, body)
179
+ }
180
+ return http(client)
181
+ .post(path, { ...options, json: body })
182
+ .json()
183
+ .then((data) => {
184
+ if (client._options.validate) {
185
+ assertValid(schemas.createCostBasisResponseWire, data)
186
+ }
187
+ return fromWire(data, schemas.createCostBasisResponse)
188
+ })
189
+ })
190
+ }
api/spec/packages/aip-client-javascript/src/funcs/customers.ts ADDED
@@ -0,0 +1,1012 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ CreateCustomerRequest,
17
+ CreateCustomerResponse,
18
+ GetCustomerRequest,
19
+ GetCustomerResponse,
20
+ ListCustomersRequest,
21
+ ListCustomersResponse,
22
+ UpsertCustomerRequest,
23
+ UpsertCustomerResponse,
24
+ DeleteCustomerRequest,
25
+ DeleteCustomerResponse,
26
+ GetCustomerBillingRequest,
27
+ GetCustomerBillingResponse,
28
+ UpdateCustomerBillingRequest,
29
+ UpdateCustomerBillingResponse,
30
+ UpdateCustomerBillingAppDataRequest,
31
+ UpdateCustomerBillingAppDataResponse,
32
+ CreateCustomerStripeCheckoutSessionRequest,
33
+ CreateCustomerStripeCheckoutSessionResponse,
34
+ CreateCustomerStripePortalSessionRequest,
35
+ CreateCustomerStripePortalSessionResponse,
36
+ CreateCreditGrantRequest,
37
+ CreateCreditGrantResponse,
38
+ GetCreditGrantRequest,
39
+ GetCreditGrantResponse,
40
+ ListCreditGrantsRequest,
41
+ ListCreditGrantsResponse,
42
+ GetCustomerCreditBalanceRequest,
43
+ GetCustomerCreditBalanceResponse,
44
+ CreateCreditAdjustmentRequest,
45
+ CreateCreditAdjustmentResponse,
46
+ VoidCreditGrantRequest,
47
+ VoidCreditGrantResponse,
48
+ UpdateCreditGrantExternalSettlementRequest,
49
+ UpdateCreditGrantExternalSettlementResponse,
50
+ ListCreditTransactionsRequest,
51
+ ListCreditTransactionsResponse,
52
+ ListCustomerChargesRequest,
53
+ ListCustomerChargesResponse,
54
+ CreateCustomerChargesRequest,
55
+ CreateCustomerChargesResponse,
56
+ } from '../models/operations/customers.js'
57
+
58
+ /**
59
+ * Create customer
60
+ *
61
+ * POST /openmeter/customers
62
+ */
63
+ export function createCustomer(
64
+ client: Client,
65
+ req: CreateCustomerRequest,
66
+ options?: RequestOptions,
67
+ ): Promise<Result<CreateCustomerResponse>> {
68
+ return request(() => {
69
+ const body = toWire(req, schemas.createCustomerBody)
70
+ if (client._options.validate) {
71
+ assertValid(schemas.createCustomerBodyWire, body)
72
+ }
73
+ return http(client)
74
+ .post('openmeter/customers', { ...options, json: body })
75
+ .json()
76
+ .then((data) => {
77
+ if (client._options.validate) {
78
+ assertValid(schemas.createCustomerResponseWire, data)
79
+ }
80
+ return fromWire(data, schemas.createCustomerResponse)
81
+ })
82
+ })
83
+ }
84
+
85
+ /**
86
+ * Get customer
87
+ *
88
+ * GET /openmeter/customers/{customerId}
89
+ */
90
+ export function getCustomer(
91
+ client: Client,
92
+ req: GetCustomerRequest,
93
+ options?: RequestOptions,
94
+ ): Promise<Result<GetCustomerResponse>> {
95
+ return request(() => {
96
+ const pathParamsInput = {
97
+ customerId: req.customerId,
98
+ }
99
+ const pathParams = client._options.validate
100
+ ? toPathWire(pathParamsInput, schemas.getCustomerPathParams)
101
+ : pathParamsInput
102
+ if (client._options.validate) {
103
+ assertValid(schemas.getCustomerPathParamsWire, pathParams)
104
+ }
105
+ const path = `openmeter/customers/${(() => {
106
+ if (pathParams.customerId === undefined) {
107
+ throw new Error('missing path parameter: customerId')
108
+ }
109
+ return encodeURIComponent(String(pathParams.customerId))
110
+ })()}`
111
+ return http(client)
112
+ .get(path, options)
113
+ .json()
114
+ .then((data) => {
115
+ if (client._options.validate) {
116
+ assertValid(schemas.getCustomerResponseWire, data)
117
+ }
118
+ return fromWire(data, schemas.getCustomerResponse)
119
+ })
120
+ })
121
+ }
122
+
123
+ /**
124
+ * List customers
125
+ *
126
+ * GET /openmeter/customers
127
+ */
128
+ export function listCustomers(
129
+ client: Client,
130
+ req: ListCustomersRequest = {},
131
+ options?: RequestOptions,
132
+ ): Promise<Result<ListCustomersResponse>> {
133
+ return request(() => {
134
+ if (client._options.validate && req.sort !== undefined) {
135
+ assertValid(schemas.listCustomersQueryParams.shape.sort, req.sort)
136
+ }
137
+ const query = toWire(
138
+ {
139
+ page: req.page,
140
+ sort: encodeSort(req.sort, toSnakeCase),
141
+ filter: req.filter,
142
+ },
143
+ schemas.listCustomersQueryParams,
144
+ )
145
+ if (client._options.validate) {
146
+ assertValid(schemas.listCustomersQueryParamsWire, query)
147
+ }
148
+ const searchParams = toURLSearchParams(query)
149
+ return http(client)
150
+ .get('openmeter/customers', { ...options, searchParams })
151
+ .json()
152
+ .then((data) => {
153
+ if (client._options.validate) {
154
+ assertValid(schemas.listCustomersResponseWire, data)
155
+ }
156
+ return fromWire(data, schemas.listCustomersResponse)
157
+ })
158
+ })
159
+ }
160
+
161
+ /**
162
+ * Upsert customer
163
+ *
164
+ * PUT /openmeter/customers/{customerId}
165
+ */
166
+ export function upsertCustomer(
167
+ client: Client,
168
+ req: UpsertCustomerRequest,
169
+ options?: RequestOptions,
170
+ ): Promise<Result<UpsertCustomerResponse>> {
171
+ return request(() => {
172
+ const pathParamsInput = {
173
+ customerId: req.customerId,
174
+ }
175
+ const pathParams = client._options.validate
176
+ ? toPathWire(pathParamsInput, schemas.upsertCustomerPathParams)
177
+ : pathParamsInput
178
+ if (client._options.validate) {
179
+ assertValid(schemas.upsertCustomerPathParamsWire, pathParams)
180
+ }
181
+ const path = `openmeter/customers/${(() => {
182
+ if (pathParams.customerId === undefined) {
183
+ throw new Error('missing path parameter: customerId')
184
+ }
185
+ return encodeURIComponent(String(pathParams.customerId))
186
+ })()}`
187
+ const body = toWire(req.body, schemas.upsertCustomerBody)
188
+ if (client._options.validate) {
189
+ assertValid(schemas.upsertCustomerBodyWire, body)
190
+ }
191
+ return http(client)
192
+ .put(path, { ...options, json: body })
193
+ .json()
194
+ .then((data) => {
195
+ if (client._options.validate) {
196
+ assertValid(schemas.upsertCustomerResponseWire, data)
197
+ }
198
+ return fromWire(data, schemas.upsertCustomerResponse)
199
+ })
200
+ })
201
+ }
202
+
203
+ /**
204
+ * Delete customer
205
+ *
206
+ * DELETE /openmeter/customers/{customerId}
207
+ */
208
+ export function deleteCustomer(
209
+ client: Client,
210
+ req: DeleteCustomerRequest,
211
+ options?: RequestOptions,
212
+ ): Promise<Result<DeleteCustomerResponse>> {
213
+ return request(async () => {
214
+ const pathParamsInput = {
215
+ customerId: req.customerId,
216
+ }
217
+ const pathParams = client._options.validate
218
+ ? toPathWire(pathParamsInput, schemas.deleteCustomerPathParams)
219
+ : pathParamsInput
220
+ if (client._options.validate) {
221
+ assertValid(schemas.deleteCustomerPathParamsWire, pathParams)
222
+ }
223
+ const path = `openmeter/customers/${(() => {
224
+ if (pathParams.customerId === undefined) {
225
+ throw new Error('missing path parameter: customerId')
226
+ }
227
+ return encodeURIComponent(String(pathParams.customerId))
228
+ })()}`
229
+ await http(client).delete(path, options)
230
+ })
231
+ }
232
+
233
+ /**
234
+ * Get customer billing data
235
+ *
236
+ * GET /openmeter/customers/{customerId}/billing
237
+ */
238
+ export function getCustomerBilling(
239
+ client: Client,
240
+ req: GetCustomerBillingRequest,
241
+ options?: RequestOptions,
242
+ ): Promise<Result<GetCustomerBillingResponse>> {
243
+ return request(() => {
244
+ const pathParamsInput = {
245
+ customerId: req.customerId,
246
+ }
247
+ const pathParams = client._options.validate
248
+ ? toPathWire(pathParamsInput, schemas.getCustomerBillingPathParams)
249
+ : pathParamsInput
250
+ if (client._options.validate) {
251
+ assertValid(schemas.getCustomerBillingPathParamsWire, pathParams)
252
+ }
253
+ const path = `openmeter/customers/${(() => {
254
+ if (pathParams.customerId === undefined) {
255
+ throw new Error('missing path parameter: customerId')
256
+ }
257
+ return encodeURIComponent(String(pathParams.customerId))
258
+ })()}/billing`
259
+ return http(client)
260
+ .get(path, options)
261
+ .json()
262
+ .then((data) => {
263
+ if (client._options.validate) {
264
+ assertValid(schemas.getCustomerBillingResponseWire, data)
265
+ }
266
+ return fromWire(data, schemas.getCustomerBillingResponse)
267
+ })
268
+ })
269
+ }
270
+
271
+ /**
272
+ * Update customer billing data
273
+ *
274
+ * PUT /openmeter/customers/{customerId}/billing
275
+ */
276
+ export function updateCustomerBilling(
277
+ client: Client,
278
+ req: UpdateCustomerBillingRequest,
279
+ options?: RequestOptions,
280
+ ): Promise<Result<UpdateCustomerBillingResponse>> {
281
+ return request(() => {
282
+ const pathParamsInput = {
283
+ customerId: req.customerId,
284
+ }
285
+ const pathParams = client._options.validate
286
+ ? toPathWire(pathParamsInput, schemas.updateCustomerBillingPathParams)
287
+ : pathParamsInput
288
+ if (client._options.validate) {
289
+ assertValid(schemas.updateCustomerBillingPathParamsWire, pathParams)
290
+ }
291
+ const path = `openmeter/customers/${(() => {
292
+ if (pathParams.customerId === undefined) {
293
+ throw new Error('missing path parameter: customerId')
294
+ }
295
+ return encodeURIComponent(String(pathParams.customerId))
296
+ })()}/billing`
297
+ const body = toWire(req.body, schemas.updateCustomerBillingBody)
298
+ if (client._options.validate) {
299
+ assertValid(schemas.updateCustomerBillingBodyWire, body)
300
+ }
301
+ return http(client)
302
+ .put(path, { ...options, json: body })
303
+ .json()
304
+ .then((data) => {
305
+ if (client._options.validate) {
306
+ assertValid(schemas.updateCustomerBillingResponseWire, data)
307
+ }
308
+ return fromWire(data, schemas.updateCustomerBillingResponse)
309
+ })
310
+ })
311
+ }
312
+
313
+ /**
314
+ * Update customer billing app data
315
+ *
316
+ * PUT /openmeter/customers/{customerId}/billing/app-data
317
+ */
318
+ export function updateCustomerBillingAppData(
319
+ client: Client,
320
+ req: UpdateCustomerBillingAppDataRequest,
321
+ options?: RequestOptions,
322
+ ): Promise<Result<UpdateCustomerBillingAppDataResponse>> {
323
+ return request(() => {
324
+ const pathParamsInput = {
325
+ customerId: req.customerId,
326
+ }
327
+ const pathParams = client._options.validate
328
+ ? toPathWire(
329
+ pathParamsInput,
330
+ schemas.updateCustomerBillingAppDataPathParams,
331
+ )
332
+ : pathParamsInput
333
+ if (client._options.validate) {
334
+ assertValid(
335
+ schemas.updateCustomerBillingAppDataPathParamsWire,
336
+ pathParams,
337
+ )
338
+ }
339
+ const path = `openmeter/customers/${(() => {
340
+ if (pathParams.customerId === undefined) {
341
+ throw new Error('missing path parameter: customerId')
342
+ }
343
+ return encodeURIComponent(String(pathParams.customerId))
344
+ })()}/billing/app-data`
345
+ const body = toWire(req.body, schemas.updateCustomerBillingAppDataBody)
346
+ if (client._options.validate) {
347
+ assertValid(schemas.updateCustomerBillingAppDataBodyWire, body)
348
+ }
349
+ return http(client)
350
+ .put(path, { ...options, json: body })
351
+ .json()
352
+ .then((data) => {
353
+ if (client._options.validate) {
354
+ assertValid(schemas.updateCustomerBillingAppDataResponseWire, data)
355
+ }
356
+ return fromWire(data, schemas.updateCustomerBillingAppDataResponse)
357
+ })
358
+ })
359
+ }
360
+
361
+ /**
362
+ * Create Stripe Checkout Session
363
+ *
364
+ * Create a [Stripe Checkout Session](https://docs.stripe.com/payments/checkout)
365
+ * for the customer.
366
+ *
367
+ * Creates a Checkout Session for collecting payment method information from
368
+ * customers. The session operates in "setup" mode, which collects payment details
369
+ * without charging the customer immediately. The collected payment method can be
370
+ * used for future subscription billing.
371
+ *
372
+ * For hosted checkout sessions, redirect customers to the returned URL. For
373
+ * embedded sessions, use the client_secret to initialize Stripe.js in your
374
+ * application.
375
+ *
376
+ * POST /openmeter/customers/{customerId}/billing/stripe/checkout-sessions
377
+ */
378
+ export function createCustomerStripeCheckoutSession(
379
+ client: Client,
380
+ req: CreateCustomerStripeCheckoutSessionRequest,
381
+ options?: RequestOptions,
382
+ ): Promise<Result<CreateCustomerStripeCheckoutSessionResponse>> {
383
+ return request(() => {
384
+ const pathParamsInput = {
385
+ customerId: req.customerId,
386
+ }
387
+ const pathParams = client._options.validate
388
+ ? toPathWire(
389
+ pathParamsInput,
390
+ schemas.createCustomerStripeCheckoutSessionPathParams,
391
+ )
392
+ : pathParamsInput
393
+ if (client._options.validate) {
394
+ assertValid(
395
+ schemas.createCustomerStripeCheckoutSessionPathParamsWire,
396
+ pathParams,
397
+ )
398
+ }
399
+ const path = `openmeter/customers/${(() => {
400
+ if (pathParams.customerId === undefined) {
401
+ throw new Error('missing path parameter: customerId')
402
+ }
403
+ return encodeURIComponent(String(pathParams.customerId))
404
+ })()}/billing/stripe/checkout-sessions`
405
+ const body = toWire(
406
+ req.body,
407
+ schemas.createCustomerStripeCheckoutSessionBody,
408
+ )
409
+ if (client._options.validate) {
410
+ assertValid(schemas.createCustomerStripeCheckoutSessionBodyWire, body)
411
+ }
412
+ return http(client)
413
+ .post(path, { ...options, json: body })
414
+ .json()
415
+ .then((data) => {
416
+ if (client._options.validate) {
417
+ assertValid(
418
+ schemas.createCustomerStripeCheckoutSessionResponseWire,
419
+ data,
420
+ )
421
+ }
422
+ return fromWire(
423
+ data,
424
+ schemas.createCustomerStripeCheckoutSessionResponse,
425
+ )
426
+ })
427
+ })
428
+ }
429
+
430
+ /**
431
+ * Create Stripe customer portal session
432
+ *
433
+ * Create Stripe Customer Portal Session.
434
+ *
435
+ * Useful to redirect the customer to the Stripe Customer Portal to manage their
436
+ * payment methods, change their billing address and access their invoice history.
437
+ * Only returns URL if the customer billing profile is linked to a stripe app and
438
+ * customer.
439
+ *
440
+ * POST /openmeter/customers/{customerId}/billing/stripe/portal-sessions
441
+ */
442
+ export function createCustomerStripePortalSession(
443
+ client: Client,
444
+ req: CreateCustomerStripePortalSessionRequest,
445
+ options?: RequestOptions,
446
+ ): Promise<Result<CreateCustomerStripePortalSessionResponse>> {
447
+ return request(() => {
448
+ const pathParamsInput = {
449
+ customerId: req.customerId,
450
+ }
451
+ const pathParams = client._options.validate
452
+ ? toPathWire(
453
+ pathParamsInput,
454
+ schemas.createCustomerStripePortalSessionPathParams,
455
+ )
456
+ : pathParamsInput
457
+ if (client._options.validate) {
458
+ assertValid(
459
+ schemas.createCustomerStripePortalSessionPathParamsWire,
460
+ pathParams,
461
+ )
462
+ }
463
+ const path = `openmeter/customers/${(() => {
464
+ if (pathParams.customerId === undefined) {
465
+ throw new Error('missing path parameter: customerId')
466
+ }
467
+ return encodeURIComponent(String(pathParams.customerId))
468
+ })()}/billing/stripe/portal-sessions`
469
+ const body = toWire(req.body, schemas.createCustomerStripePortalSessionBody)
470
+ if (client._options.validate) {
471
+ assertValid(schemas.createCustomerStripePortalSessionBodyWire, body)
472
+ }
473
+ return http(client)
474
+ .post(path, { ...options, json: body })
475
+ .json()
476
+ .then((data) => {
477
+ if (client._options.validate) {
478
+ assertValid(
479
+ schemas.createCustomerStripePortalSessionResponseWire,
480
+ data,
481
+ )
482
+ }
483
+ return fromWire(data, schemas.createCustomerStripePortalSessionResponse)
484
+ })
485
+ })
486
+ }
487
+
488
+ /**
489
+ * Create a new credit grant
490
+ *
491
+ * Create a new credit grant. A credit grant represents an allocation of prepaid
492
+ * credits to a customer.
493
+ *
494
+ * POST /openmeter/customers/{customerId}/credits/grants
495
+ */
496
+ export function createCreditGrant(
497
+ client: Client,
498
+ req: CreateCreditGrantRequest,
499
+ options?: RequestOptions,
500
+ ): Promise<Result<CreateCreditGrantResponse>> {
501
+ return request(() => {
502
+ const pathParamsInput = {
503
+ customerId: req.customerId,
504
+ }
505
+ const pathParams = client._options.validate
506
+ ? toPathWire(pathParamsInput, schemas.createCreditGrantPathParams)
507
+ : pathParamsInput
508
+ if (client._options.validate) {
509
+ assertValid(schemas.createCreditGrantPathParamsWire, pathParams)
510
+ }
511
+ const path = `openmeter/customers/${(() => {
512
+ if (pathParams.customerId === undefined) {
513
+ throw new Error('missing path parameter: customerId')
514
+ }
515
+ return encodeURIComponent(String(pathParams.customerId))
516
+ })()}/credits/grants`
517
+ const body = toWire(req.body, schemas.createCreditGrantBody)
518
+ if (client._options.validate) {
519
+ assertValid(schemas.createCreditGrantBodyWire, body)
520
+ }
521
+ return http(client)
522
+ .post(path, { ...options, json: body })
523
+ .json()
524
+ .then((data) => {
525
+ if (client._options.validate) {
526
+ assertValid(schemas.createCreditGrantResponseWire, data)
527
+ }
528
+ return fromWire(data, schemas.createCreditGrantResponse)
529
+ })
530
+ })
531
+ }
532
+
533
+ /**
534
+ * Get a credit grant
535
+ *
536
+ * Get a credit grant.
537
+ *
538
+ * GET /openmeter/customers/{customerId}/credits/grants/{creditGrantId}
539
+ */
540
+ export function getCreditGrant(
541
+ client: Client,
542
+ req: GetCreditGrantRequest,
543
+ options?: RequestOptions,
544
+ ): Promise<Result<GetCreditGrantResponse>> {
545
+ return request(() => {
546
+ const pathParamsInput = {
547
+ customerId: req.customerId,
548
+ creditGrantId: req.creditGrantId,
549
+ }
550
+ const pathParams = client._options.validate
551
+ ? toPathWire(pathParamsInput, schemas.getCreditGrantPathParams)
552
+ : pathParamsInput
553
+ if (client._options.validate) {
554
+ assertValid(schemas.getCreditGrantPathParamsWire, pathParams)
555
+ }
556
+ const path = `openmeter/customers/${(() => {
557
+ if (pathParams.customerId === undefined) {
558
+ throw new Error('missing path parameter: customerId')
559
+ }
560
+ return encodeURIComponent(String(pathParams.customerId))
561
+ })()}/credits/grants/${(() => {
562
+ if (pathParams.creditGrantId === undefined) {
563
+ throw new Error('missing path parameter: creditGrantId')
564
+ }
565
+ return encodeURIComponent(String(pathParams.creditGrantId))
566
+ })()}`
567
+ return http(client)
568
+ .get(path, options)
569
+ .json()
570
+ .then((data) => {
571
+ if (client._options.validate) {
572
+ assertValid(schemas.getCreditGrantResponseWire, data)
573
+ }
574
+ return fromWire(data, schemas.getCreditGrantResponse)
575
+ })
576
+ })
577
+ }
578
+
579
+ /**
580
+ * List credit grants
581
+ *
582
+ * List credit grants.
583
+ *
584
+ * GET /openmeter/customers/{customerId}/credits/grants
585
+ */
586
+ export function listCreditGrants(
587
+ client: Client,
588
+ req: ListCreditGrantsRequest,
589
+ options?: RequestOptions,
590
+ ): Promise<Result<ListCreditGrantsResponse>> {
591
+ return request(() => {
592
+ const pathParamsInput = {
593
+ customerId: req.customerId,
594
+ }
595
+ const pathParams = client._options.validate
596
+ ? toPathWire(pathParamsInput, schemas.listCreditGrantsPathParams)
597
+ : pathParamsInput
598
+ if (client._options.validate) {
599
+ assertValid(schemas.listCreditGrantsPathParamsWire, pathParams)
600
+ }
601
+ const path = `openmeter/customers/${(() => {
602
+ if (pathParams.customerId === undefined) {
603
+ throw new Error('missing path parameter: customerId')
604
+ }
605
+ return encodeURIComponent(String(pathParams.customerId))
606
+ })()}/credits/grants`
607
+ const query = toWire(
608
+ {
609
+ page: req.page,
610
+ filter: req.filter,
611
+ },
612
+ schemas.listCreditGrantsQueryParams,
613
+ )
614
+ if (client._options.validate) {
615
+ assertValid(schemas.listCreditGrantsQueryParamsWire, query)
616
+ }
617
+ const searchParams = toURLSearchParams(query)
618
+ return http(client)
619
+ .get(path, { ...options, searchParams })
620
+ .json()
621
+ .then((data) => {
622
+ if (client._options.validate) {
623
+ assertValid(schemas.listCreditGrantsResponseWire, data)
624
+ }
625
+ return fromWire(data, schemas.listCreditGrantsResponse)
626
+ })
627
+ })
628
+ }
629
+
630
+ /**
631
+ * Get a customer's credit balance
632
+ *
633
+ * Get a credit balance.
634
+ *
635
+ * GET /openmeter/customers/{customerId}/credits/balance
636
+ */
637
+ export function getCustomerCreditBalance(
638
+ client: Client,
639
+ req: GetCustomerCreditBalanceRequest,
640
+ options?: RequestOptions,
641
+ ): Promise<Result<GetCustomerCreditBalanceResponse>> {
642
+ return request(() => {
643
+ const pathParamsInput = {
644
+ customerId: req.customerId,
645
+ }
646
+ const pathParams = client._options.validate
647
+ ? toPathWire(pathParamsInput, schemas.getCustomerCreditBalancePathParams)
648
+ : pathParamsInput
649
+ if (client._options.validate) {
650
+ assertValid(schemas.getCustomerCreditBalancePathParamsWire, pathParams)
651
+ }
652
+ const path = `openmeter/customers/${(() => {
653
+ if (pathParams.customerId === undefined) {
654
+ throw new Error('missing path parameter: customerId')
655
+ }
656
+ return encodeURIComponent(String(pathParams.customerId))
657
+ })()}/credits/balance`
658
+ const query = toWire(
659
+ {
660
+ timestamp: req.timestamp,
661
+ filter: req.filter,
662
+ },
663
+ schemas.getCustomerCreditBalanceQueryParams,
664
+ )
665
+ if (client._options.validate) {
666
+ assertValid(schemas.getCustomerCreditBalanceQueryParamsWire, query)
667
+ }
668
+ const searchParams = toURLSearchParams(query)
669
+ return http(client)
670
+ .get(path, { ...options, searchParams })
671
+ .json()
672
+ .then((data) => {
673
+ if (client._options.validate) {
674
+ assertValid(schemas.getCustomerCreditBalanceResponseWire, data)
675
+ }
676
+ return fromWire(data, schemas.getCustomerCreditBalanceResponse)
677
+ })
678
+ })
679
+ }
680
+
681
+ /**
682
+ * Create a credit adjustment
683
+ *
684
+ * A credit adjustment can be used to make manual adjustments to a customer's
685
+ * credit balance.
686
+ *
687
+ * Supported use-cases:
688
+ *
689
+ * - Usage correction
690
+ *
691
+ * POST /openmeter/customers/{customerId}/credits/adjustments
692
+ */
693
+ export function createCreditAdjustment(
694
+ client: Client,
695
+ req: CreateCreditAdjustmentRequest,
696
+ options?: RequestOptions,
697
+ ): Promise<Result<CreateCreditAdjustmentResponse>> {
698
+ return request(() => {
699
+ const pathParamsInput = {
700
+ customerId: req.customerId,
701
+ }
702
+ const pathParams = client._options.validate
703
+ ? toPathWire(pathParamsInput, schemas.createCreditAdjustmentPathParams)
704
+ : pathParamsInput
705
+ if (client._options.validate) {
706
+ assertValid(schemas.createCreditAdjustmentPathParamsWire, pathParams)
707
+ }
708
+ const path = `openmeter/customers/${(() => {
709
+ if (pathParams.customerId === undefined) {
710
+ throw new Error('missing path parameter: customerId')
711
+ }
712
+ return encodeURIComponent(String(pathParams.customerId))
713
+ })()}/credits/adjustments`
714
+ const body = toWire(req.body, schemas.createCreditAdjustmentBody)
715
+ if (client._options.validate) {
716
+ assertValid(schemas.createCreditAdjustmentBodyWire, body)
717
+ }
718
+ return http(client)
719
+ .post(path, { ...options, json: body })
720
+ .json()
721
+ .then((data) => {
722
+ if (client._options.validate) {
723
+ assertValid(schemas.createCreditAdjustmentResponseWire, data)
724
+ }
725
+ return fromWire(data, schemas.createCreditAdjustmentResponse)
726
+ })
727
+ })
728
+ }
729
+
730
+ /**
731
+ * Void credit grant
732
+ *
733
+ * Void a credit grant, forfeiting the remaining unused balance.
734
+ *
735
+ * Voiding is a forward-looking, irreversible operation. Credits already consumed
736
+ * by usage remain unaffected — only the remaining balance is forfeited. The grant
737
+ * reads as `voided` status afterwards. Payment state is not adjusted when
738
+ * `payment_adjustment` is `none`, so invoice-backed or externally collected
739
+ * payments may still collect the original amount. Only `active` grants can be
740
+ * voided; voiding a pending, expired, or fully consumed grant returns a conflict.
741
+ * Retrying a successful void is an idempotent success.
742
+ *
743
+ * POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/void
744
+ */
745
+ export function voidCreditGrant(
746
+ client: Client,
747
+ req: VoidCreditGrantRequest,
748
+ options?: RequestOptions,
749
+ ): Promise<Result<VoidCreditGrantResponse>> {
750
+ return request(() => {
751
+ const pathParamsInput = {
752
+ customerId: req.customerId,
753
+ creditGrantId: req.creditGrantId,
754
+ }
755
+ const pathParams = client._options.validate
756
+ ? toPathWire(pathParamsInput, schemas.voidCreditGrantPathParams)
757
+ : pathParamsInput
758
+ if (client._options.validate) {
759
+ assertValid(schemas.voidCreditGrantPathParamsWire, pathParams)
760
+ }
761
+ const path = `openmeter/customers/${(() => {
762
+ if (pathParams.customerId === undefined) {
763
+ throw new Error('missing path parameter: customerId')
764
+ }
765
+ return encodeURIComponent(String(pathParams.customerId))
766
+ })()}/credits/grants/${(() => {
767
+ if (pathParams.creditGrantId === undefined) {
768
+ throw new Error('missing path parameter: creditGrantId')
769
+ }
770
+ return encodeURIComponent(String(pathParams.creditGrantId))
771
+ })()}/void`
772
+ const body = toWire(req.body, schemas.voidCreditGrantBody)
773
+ if (client._options.validate) {
774
+ assertValid(schemas.voidCreditGrantBodyWire, body)
775
+ }
776
+ return http(client)
777
+ .post(path, { ...options, json: body })
778
+ .json()
779
+ .then((data) => {
780
+ if (client._options.validate) {
781
+ assertValid(schemas.voidCreditGrantResponseWire, data)
782
+ }
783
+ return fromWire(data, schemas.voidCreditGrantResponse)
784
+ })
785
+ })
786
+ }
787
+
788
+ /**
789
+ * Update credit grant external settlement status
790
+ *
791
+ * Update the payment settlement status of an externally funded credit grant.
792
+ *
793
+ * Use this endpoint to synchronize the payment state of an external payment with
794
+ * the system so that revenue recognition and credit availability work as expected.
795
+ *
796
+ * POST /openmeter/customers/{customerId}/credits/grants/{creditGrantId}/settlement/external
797
+ */
798
+ export function updateCreditGrantExternalSettlement(
799
+ client: Client,
800
+ req: UpdateCreditGrantExternalSettlementRequest,
801
+ options?: RequestOptions,
802
+ ): Promise<Result<UpdateCreditGrantExternalSettlementResponse>> {
803
+ return request(() => {
804
+ const pathParamsInput = {
805
+ customerId: req.customerId,
806
+ creditGrantId: req.creditGrantId,
807
+ }
808
+ const pathParams = client._options.validate
809
+ ? toPathWire(
810
+ pathParamsInput,
811
+ schemas.updateCreditGrantExternalSettlementPathParams,
812
+ )
813
+ : pathParamsInput
814
+ if (client._options.validate) {
815
+ assertValid(
816
+ schemas.updateCreditGrantExternalSettlementPathParamsWire,
817
+ pathParams,
818
+ )
819
+ }
820
+ const path = `openmeter/customers/${(() => {
821
+ if (pathParams.customerId === undefined) {
822
+ throw new Error('missing path parameter: customerId')
823
+ }
824
+ return encodeURIComponent(String(pathParams.customerId))
825
+ })()}/credits/grants/${(() => {
826
+ if (pathParams.creditGrantId === undefined) {
827
+ throw new Error('missing path parameter: creditGrantId')
828
+ }
829
+ return encodeURIComponent(String(pathParams.creditGrantId))
830
+ })()}/settlement/external`
831
+ const body = toWire(
832
+ req.body,
833
+ schemas.updateCreditGrantExternalSettlementBody,
834
+ )
835
+ if (client._options.validate) {
836
+ assertValid(schemas.updateCreditGrantExternalSettlementBodyWire, body)
837
+ }
838
+ return http(client)
839
+ .post(path, { ...options, json: body })
840
+ .json()
841
+ .then((data) => {
842
+ if (client._options.validate) {
843
+ assertValid(
844
+ schemas.updateCreditGrantExternalSettlementResponseWire,
845
+ data,
846
+ )
847
+ }
848
+ return fromWire(
849
+ data,
850
+ schemas.updateCreditGrantExternalSettlementResponse,
851
+ )
852
+ })
853
+ })
854
+ }
855
+
856
+ /**
857
+ * List credit transactions
858
+ *
859
+ * List credit transactions for a customer.
860
+ *
861
+ * Returns an immutable, chronological record of credit movements: funded credits
862
+ * and consumed credits. Transactions are returned in reverse chronological order
863
+ * by default.
864
+ *
865
+ * GET /openmeter/customers/{customerId}/credits/transactions
866
+ */
867
+ export function listCreditTransactions(
868
+ client: Client,
869
+ req: ListCreditTransactionsRequest,
870
+ options?: RequestOptions,
871
+ ): Promise<Result<ListCreditTransactionsResponse>> {
872
+ return request(() => {
873
+ const pathParamsInput = {
874
+ customerId: req.customerId,
875
+ }
876
+ const pathParams = client._options.validate
877
+ ? toPathWire(pathParamsInput, schemas.listCreditTransactionsPathParams)
878
+ : pathParamsInput
879
+ if (client._options.validate) {
880
+ assertValid(schemas.listCreditTransactionsPathParamsWire, pathParams)
881
+ }
882
+ const path = `openmeter/customers/${(() => {
883
+ if (pathParams.customerId === undefined) {
884
+ throw new Error('missing path parameter: customerId')
885
+ }
886
+ return encodeURIComponent(String(pathParams.customerId))
887
+ })()}/credits/transactions`
888
+ const query = toWire(
889
+ {
890
+ page: req.page,
891
+ filter: req.filter,
892
+ },
893
+ schemas.listCreditTransactionsQueryParams,
894
+ )
895
+ if (client._options.validate) {
896
+ assertValid(schemas.listCreditTransactionsQueryParamsWire, query)
897
+ }
898
+ const searchParams = toURLSearchParams(query)
899
+ return http(client)
900
+ .get(path, { ...options, searchParams })
901
+ .json()
902
+ .then((data) => {
903
+ if (client._options.validate) {
904
+ assertValid(schemas.listCreditTransactionsResponseWire, data)
905
+ }
906
+ return fromWire(data, schemas.listCreditTransactionsResponse)
907
+ })
908
+ })
909
+ }
910
+
911
+ /**
912
+ * List customer charges
913
+ *
914
+ * List customer charges.
915
+ *
916
+ * Returns the customer's charges that are represented as either flat fee or
917
+ * usage-based charges.
918
+ *
919
+ * GET /openmeter/customers/{customerId}/charges
920
+ */
921
+ export function listCustomerCharges(
922
+ client: Client,
923
+ req: ListCustomerChargesRequest,
924
+ options?: RequestOptions,
925
+ ): Promise<Result<ListCustomerChargesResponse>> {
926
+ return request(() => {
927
+ const pathParamsInput = {
928
+ customerId: req.customerId,
929
+ }
930
+ const pathParams = client._options.validate
931
+ ? toPathWire(pathParamsInput, schemas.listCustomerChargesPathParams)
932
+ : pathParamsInput
933
+ if (client._options.validate) {
934
+ assertValid(schemas.listCustomerChargesPathParamsWire, pathParams)
935
+ }
936
+ const path = `openmeter/customers/${(() => {
937
+ if (pathParams.customerId === undefined) {
938
+ throw new Error('missing path parameter: customerId')
939
+ }
940
+ return encodeURIComponent(String(pathParams.customerId))
941
+ })()}/charges`
942
+ if (client._options.validate && req.sort !== undefined) {
943
+ assertValid(schemas.listCustomerChargesQueryParams.shape.sort, req.sort)
944
+ }
945
+ const query = toWire(
946
+ {
947
+ page: req.page,
948
+ sort: encodeSort(req.sort, toSnakeCase),
949
+ filter: req.filter,
950
+ expand: req.expand,
951
+ },
952
+ schemas.listCustomerChargesQueryParams,
953
+ )
954
+ if (client._options.validate) {
955
+ assertValid(schemas.listCustomerChargesQueryParamsWire, query)
956
+ }
957
+ const searchParams = toURLSearchParams(query)
958
+ return http(client)
959
+ .get(path, { ...options, searchParams })
960
+ .json()
961
+ .then((data) => {
962
+ if (client._options.validate) {
963
+ assertValid(schemas.listCustomerChargesResponseWire, data)
964
+ }
965
+ return fromWire(data, schemas.listCustomerChargesResponse)
966
+ })
967
+ })
968
+ }
969
+
970
+ /**
971
+ * Create customer charge
972
+ *
973
+ * Create customer charge.
974
+ *
975
+ * POST /openmeter/customers/{customerId}/charges
976
+ */
977
+ export function createCustomerCharges(
978
+ client: Client,
979
+ req: CreateCustomerChargesRequest,
980
+ options?: RequestOptions,
981
+ ): Promise<Result<CreateCustomerChargesResponse>> {
982
+ return request(() => {
983
+ const pathParamsInput = {
984
+ customerId: req.customerId,
985
+ }
986
+ const pathParams = client._options.validate
987
+ ? toPathWire(pathParamsInput, schemas.createCustomerChargesPathParams)
988
+ : pathParamsInput
989
+ if (client._options.validate) {
990
+ assertValid(schemas.createCustomerChargesPathParamsWire, pathParams)
991
+ }
992
+ const path = `openmeter/customers/${(() => {
993
+ if (pathParams.customerId === undefined) {
994
+ throw new Error('missing path parameter: customerId')
995
+ }
996
+ return encodeURIComponent(String(pathParams.customerId))
997
+ })()}/charges`
998
+ const body = toWire(req.body, schemas.createCustomerChargesBody)
999
+ if (client._options.validate) {
1000
+ assertValid(schemas.createCustomerChargesBodyWire, body)
1001
+ }
1002
+ return http(client)
1003
+ .post(path, { ...options, json: body })
1004
+ .json()
1005
+ .then((data) => {
1006
+ if (client._options.validate) {
1007
+ assertValid(schemas.createCustomerChargesResponseWire, data)
1008
+ }
1009
+ return fromWire(data, schemas.createCustomerChargesResponse)
1010
+ })
1011
+ })
1012
+ }
api/spec/packages/aip-client-javascript/src/funcs/defaults.ts ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toWire, fromWire, assertValid } from '../lib/wire.js'
7
+ import * as schemas from '../models/schemas.js'
8
+ import type {
9
+ GetOrganizationDefaultTaxCodesRequest,
10
+ GetOrganizationDefaultTaxCodesResponse,
11
+ UpdateOrganizationDefaultTaxCodesRequest,
12
+ UpdateOrganizationDefaultTaxCodesResponse,
13
+ } from '../models/operations/defaults.js'
14
+
15
+ /**
16
+ * Get organization default tax codes
17
+ *
18
+ * GET /openmeter/defaults/tax-codes
19
+ */
20
+ export function getOrganizationDefaultTaxCodes(
21
+ client: Client,
22
+ req: GetOrganizationDefaultTaxCodesRequest,
23
+ options?: RequestOptions,
24
+ ): Promise<Result<GetOrganizationDefaultTaxCodesResponse>> {
25
+ return request(() =>
26
+ http(client)
27
+ .get('openmeter/defaults/tax-codes', options)
28
+ .json()
29
+ .then((data) => {
30
+ if (client._options.validate) {
31
+ assertValid(schemas.getOrganizationDefaultTaxCodesResponseWire, data)
32
+ }
33
+ return fromWire(data, schemas.getOrganizationDefaultTaxCodesResponse)
34
+ }),
35
+ )
36
+ }
37
+
38
+ /**
39
+ * Update organization default tax codes
40
+ *
41
+ * PUT /openmeter/defaults/tax-codes
42
+ */
43
+ export function updateOrganizationDefaultTaxCodes(
44
+ client: Client,
45
+ req: UpdateOrganizationDefaultTaxCodesRequest,
46
+ options?: RequestOptions,
47
+ ): Promise<Result<UpdateOrganizationDefaultTaxCodesResponse>> {
48
+ return request(() => {
49
+ const body = toWire(req, schemas.updateOrganizationDefaultTaxCodesBody)
50
+ if (client._options.validate) {
51
+ assertValid(schemas.updateOrganizationDefaultTaxCodesBodyWire, body)
52
+ }
53
+ return http(client)
54
+ .put('openmeter/defaults/tax-codes', { ...options, json: body })
55
+ .json()
56
+ .then((data) => {
57
+ if (client._options.validate) {
58
+ assertValid(
59
+ schemas.updateOrganizationDefaultTaxCodesResponseWire,
60
+ data,
61
+ )
62
+ }
63
+ return fromWire(data, schemas.updateOrganizationDefaultTaxCodesResponse)
64
+ })
65
+ })
66
+ }
api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toPathWire, fromWire, assertValid } from '../lib/wire.js'
7
+ import * as schemas from '../models/schemas.js'
8
+ import type {
9
+ ListCustomerEntitlementAccessRequest,
10
+ ListCustomerEntitlementAccessResponse,
11
+ } from '../models/operations/entitlements.js'
12
+
13
+ /**
14
+ * List customer entitlement access
15
+ *
16
+ * GET /openmeter/customers/{customerId}/entitlement-access
17
+ */
18
+ export function listCustomerEntitlementAccess(
19
+ client: Client,
20
+ req: ListCustomerEntitlementAccessRequest,
21
+ options?: RequestOptions,
22
+ ): Promise<Result<ListCustomerEntitlementAccessResponse>> {
23
+ return request(() => {
24
+ const pathParamsInput = {
25
+ customerId: req.customerId,
26
+ }
27
+ const pathParams = client._options.validate
28
+ ? toPathWire(
29
+ pathParamsInput,
30
+ schemas.listCustomerEntitlementAccessPathParams,
31
+ )
32
+ : pathParamsInput
33
+ if (client._options.validate) {
34
+ assertValid(
35
+ schemas.listCustomerEntitlementAccessPathParamsWire,
36
+ pathParams,
37
+ )
38
+ }
39
+ const path = `openmeter/customers/${(() => {
40
+ if (pathParams.customerId === undefined) {
41
+ throw new Error('missing path parameter: customerId')
42
+ }
43
+ return encodeURIComponent(String(pathParams.customerId))
44
+ })()}/entitlement-access`
45
+ return http(client)
46
+ .get(path, options)
47
+ .json()
48
+ .then((data) => {
49
+ if (client._options.validate) {
50
+ assertValid(schemas.listCustomerEntitlementAccessResponseWire, data)
51
+ }
52
+ return fromWire(data, schemas.listCustomerEntitlementAccessResponse)
53
+ })
54
+ })
55
+ }
api/spec/packages/aip-client-javascript/src/funcs/events.ts ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import { toWire, fromWire, assertValid, toSnakeCase } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ ListMeteringEventsRequest,
11
+ ListMeteringEventsResponse,
12
+ IngestMeteringEventsRequest,
13
+ IngestMeteringEventsResponse,
14
+ } from '../models/operations/events.js'
15
+
16
+ /**
17
+ * List metering events
18
+ *
19
+ * List ingested events.
20
+ *
21
+ * GET /openmeter/events
22
+ */
23
+ export function listMeteringEvents(
24
+ client: Client,
25
+ req: ListMeteringEventsRequest = {},
26
+ options?: RequestOptions,
27
+ ): Promise<Result<ListMeteringEventsResponse>> {
28
+ return request(() => {
29
+ if (client._options.validate && req.sort !== undefined) {
30
+ assertValid(schemas.listMeteringEventsQueryParams.shape.sort, req.sort)
31
+ }
32
+ const query = toWire(
33
+ {
34
+ page: req.page,
35
+ filter: req.filter,
36
+ sort: encodeSort(req.sort, toSnakeCase),
37
+ },
38
+ schemas.listMeteringEventsQueryParams,
39
+ )
40
+ if (client._options.validate) {
41
+ assertValid(schemas.listMeteringEventsQueryParamsWire, query)
42
+ }
43
+ const searchParams = toURLSearchParams(query)
44
+ return http(client)
45
+ .get('openmeter/events', { ...options, searchParams })
46
+ .json()
47
+ .then((data) => {
48
+ if (client._options.validate) {
49
+ assertValid(schemas.listMeteringEventsResponseWire, data)
50
+ }
51
+ return fromWire(data, schemas.listMeteringEventsResponse)
52
+ })
53
+ })
54
+ }
55
+
56
+ /**
57
+ * Ingest metering events
58
+ *
59
+ * Ingests an event or batch of events following the CloudEvents specification.
60
+ *
61
+ * POST /openmeter/events
62
+ */
63
+ export function ingestMeteringEvents(
64
+ client: Client,
65
+ req: IngestMeteringEventsRequest,
66
+ options?: RequestOptions,
67
+ ): Promise<Result<IngestMeteringEventsResponse>> {
68
+ return request(async () => {
69
+ const body = toWire(req, schemas.ingestMeteringEventsBody)
70
+ if (client._options.validate) {
71
+ assertValid(schemas.ingestMeteringEventsBodyWire, body)
72
+ }
73
+ await http(client).post('openmeter/events', { ...options, json: body })
74
+ })
75
+ }
api/spec/packages/aip-client-javascript/src/funcs/features.ts ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListFeaturesRequest,
17
+ ListFeaturesResponse,
18
+ CreateFeatureRequest,
19
+ CreateFeatureResponse,
20
+ GetFeatureRequest,
21
+ GetFeatureResponse,
22
+ UpdateFeatureRequest,
23
+ UpdateFeatureResponse,
24
+ DeleteFeatureRequest,
25
+ DeleteFeatureResponse,
26
+ QueryFeatureCostRequest,
27
+ QueryFeatureCostResponse,
28
+ } from '../models/operations/features.js'
29
+
30
+ /**
31
+ * List features
32
+ *
33
+ * List all features.
34
+ *
35
+ * GET /openmeter/features
36
+ */
37
+ export function listFeatures(
38
+ client: Client,
39
+ req: ListFeaturesRequest = {},
40
+ options?: RequestOptions,
41
+ ): Promise<Result<ListFeaturesResponse>> {
42
+ return request(() => {
43
+ if (client._options.validate && req.sort !== undefined) {
44
+ assertValid(schemas.listFeaturesQueryParams.shape.sort, req.sort)
45
+ }
46
+ const query = toWire(
47
+ {
48
+ page: req.page,
49
+ sort: encodeSort(req.sort, toSnakeCase),
50
+ filter: req.filter,
51
+ },
52
+ schemas.listFeaturesQueryParams,
53
+ )
54
+ if (client._options.validate) {
55
+ assertValid(schemas.listFeaturesQueryParamsWire, query)
56
+ }
57
+ const searchParams = toURLSearchParams(query)
58
+ return http(client)
59
+ .get('openmeter/features', { ...options, searchParams })
60
+ .json()
61
+ .then((data) => {
62
+ if (client._options.validate) {
63
+ assertValid(schemas.listFeaturesResponseWire, data)
64
+ }
65
+ return fromWire(data, schemas.listFeaturesResponse)
66
+ })
67
+ })
68
+ }
69
+
70
+ /**
71
+ * Create feature
72
+ *
73
+ * Create a feature.
74
+ *
75
+ * POST /openmeter/features
76
+ */
77
+ export function createFeature(
78
+ client: Client,
79
+ req: CreateFeatureRequest,
80
+ options?: RequestOptions,
81
+ ): Promise<Result<CreateFeatureResponse>> {
82
+ return request(() => {
83
+ const body = toWire(req, schemas.createFeatureBody)
84
+ if (client._options.validate) {
85
+ assertValid(schemas.createFeatureBodyWire, body)
86
+ }
87
+ return http(client)
88
+ .post('openmeter/features', { ...options, json: body })
89
+ .json()
90
+ .then((data) => {
91
+ if (client._options.validate) {
92
+ assertValid(schemas.createFeatureResponseWire, data)
93
+ }
94
+ return fromWire(data, schemas.createFeatureResponse)
95
+ })
96
+ })
97
+ }
98
+
99
+ /**
100
+ * Get feature
101
+ *
102
+ * Get a feature by id.
103
+ *
104
+ * GET /openmeter/features/{featureId}
105
+ */
106
+ export function getFeature(
107
+ client: Client,
108
+ req: GetFeatureRequest,
109
+ options?: RequestOptions,
110
+ ): Promise<Result<GetFeatureResponse>> {
111
+ return request(() => {
112
+ const pathParamsInput = {
113
+ featureId: req.featureId,
114
+ }
115
+ const pathParams = client._options.validate
116
+ ? toPathWire(pathParamsInput, schemas.getFeaturePathParams)
117
+ : pathParamsInput
118
+ if (client._options.validate) {
119
+ assertValid(schemas.getFeaturePathParamsWire, pathParams)
120
+ }
121
+ const path = `openmeter/features/${(() => {
122
+ if (pathParams.featureId === undefined) {
123
+ throw new Error('missing path parameter: featureId')
124
+ }
125
+ return encodeURIComponent(String(pathParams.featureId))
126
+ })()}`
127
+ return http(client)
128
+ .get(path, options)
129
+ .json()
130
+ .then((data) => {
131
+ if (client._options.validate) {
132
+ assertValid(schemas.getFeatureResponseWire, data)
133
+ }
134
+ return fromWire(data, schemas.getFeatureResponse)
135
+ })
136
+ })
137
+ }
138
+
139
+ /**
140
+ * Update feature
141
+ *
142
+ * Update a feature by id. Currently only the unit_cost field can be updated.
143
+ *
144
+ * PATCH /openmeter/features/{featureId}
145
+ */
146
+ export function updateFeature(
147
+ client: Client,
148
+ req: UpdateFeatureRequest,
149
+ options?: RequestOptions,
150
+ ): Promise<Result<UpdateFeatureResponse>> {
151
+ return request(() => {
152
+ const pathParamsInput = {
153
+ featureId: req.featureId,
154
+ }
155
+ const pathParams = client._options.validate
156
+ ? toPathWire(pathParamsInput, schemas.updateFeaturePathParams)
157
+ : pathParamsInput
158
+ if (client._options.validate) {
159
+ assertValid(schemas.updateFeaturePathParamsWire, pathParams)
160
+ }
161
+ const path = `openmeter/features/${(() => {
162
+ if (pathParams.featureId === undefined) {
163
+ throw new Error('missing path parameter: featureId')
164
+ }
165
+ return encodeURIComponent(String(pathParams.featureId))
166
+ })()}`
167
+ const body = toWire(req.body, schemas.updateFeatureBody)
168
+ if (client._options.validate) {
169
+ assertValid(schemas.updateFeatureBodyWire, body)
170
+ }
171
+ return http(client)
172
+ .patch(path, { ...options, json: body })
173
+ .json()
174
+ .then((data) => {
175
+ if (client._options.validate) {
176
+ assertValid(schemas.updateFeatureResponseWire, data)
177
+ }
178
+ return fromWire(data, schemas.updateFeatureResponse)
179
+ })
180
+ })
181
+ }
182
+
183
+ /**
184
+ * Delete feature
185
+ *
186
+ * Delete a feature by id.
187
+ *
188
+ * DELETE /openmeter/features/{featureId}
189
+ */
190
+ export function deleteFeature(
191
+ client: Client,
192
+ req: DeleteFeatureRequest,
193
+ options?: RequestOptions,
194
+ ): Promise<Result<DeleteFeatureResponse>> {
195
+ return request(async () => {
196
+ const pathParamsInput = {
197
+ featureId: req.featureId,
198
+ }
199
+ const pathParams = client._options.validate
200
+ ? toPathWire(pathParamsInput, schemas.deleteFeaturePathParams)
201
+ : pathParamsInput
202
+ if (client._options.validate) {
203
+ assertValid(schemas.deleteFeaturePathParamsWire, pathParams)
204
+ }
205
+ const path = `openmeter/features/${(() => {
206
+ if (pathParams.featureId === undefined) {
207
+ throw new Error('missing path parameter: featureId')
208
+ }
209
+ return encodeURIComponent(String(pathParams.featureId))
210
+ })()}`
211
+ await http(client).delete(path, options)
212
+ })
213
+ }
214
+
215
+ /**
216
+ * Query feature cost
217
+ *
218
+ * Query the cost of a feature.
219
+ *
220
+ * POST /openmeter/features/{featureId}/cost/query
221
+ */
222
+ export function queryFeatureCost(
223
+ client: Client,
224
+ req: QueryFeatureCostRequest,
225
+ options?: RequestOptions,
226
+ ): Promise<Result<QueryFeatureCostResponse>> {
227
+ return request(() => {
228
+ const pathParamsInput = {
229
+ featureId: req.featureId,
230
+ }
231
+ const pathParams = client._options.validate
232
+ ? toPathWire(pathParamsInput, schemas.queryFeatureCostPathParams)
233
+ : pathParamsInput
234
+ if (client._options.validate) {
235
+ assertValid(schemas.queryFeatureCostPathParamsWire, pathParams)
236
+ }
237
+ const path = `openmeter/features/${(() => {
238
+ if (pathParams.featureId === undefined) {
239
+ throw new Error('missing path parameter: featureId')
240
+ }
241
+ return encodeURIComponent(String(pathParams.featureId))
242
+ })()}/cost/query`
243
+ const body = toWire(req.body, schemas.queryFeatureCostBody)
244
+ if (client._options.validate) {
245
+ assertValid(schemas.queryFeatureCostBodyWire, body)
246
+ }
247
+ return http(client)
248
+ .post(path, { ...options, json: body })
249
+ .json()
250
+ .then((data) => {
251
+ if (client._options.validate) {
252
+ assertValid(schemas.queryFeatureCostResponseWire, data)
253
+ }
254
+ return fromWire(data, schemas.queryFeatureCostResponse)
255
+ })
256
+ })
257
+ }
api/spec/packages/aip-client-javascript/src/funcs/governance.ts ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams } from '../lib/encodings.js'
7
+ import { toWire, fromWire, assertValid } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ QueryGovernanceAccessRequest,
11
+ QueryGovernanceAccessResponse,
12
+ } from '../models/operations/governance.js'
13
+
14
+ /**
15
+ * Query governance access
16
+ *
17
+ * Query feature access for a list of customers.
18
+ *
19
+ * The endpoint resolves each provided identifier to a customer and returns the
20
+ * access status for the requested features, plus optional credit balance
21
+ * availability.
22
+ *
23
+ * _Designed to be called on a fixed refresh interval and the query response is
24
+ * intended to be cached._
25
+ *
26
+ * POST /openmeter/governance/query
27
+ */
28
+ export function queryGovernanceAccess(
29
+ client: Client,
30
+ req: QueryGovernanceAccessRequest,
31
+ options?: RequestOptions,
32
+ ): Promise<Result<QueryGovernanceAccessResponse>> {
33
+ return request(() => {
34
+ const body = toWire(req.body, schemas.queryGovernanceAccessBody)
35
+ if (client._options.validate) {
36
+ assertValid(schemas.queryGovernanceAccessBodyWire, body)
37
+ }
38
+ const query = toWire(
39
+ {
40
+ page: req.page,
41
+ },
42
+ schemas.queryGovernanceAccessQueryParams,
43
+ )
44
+ if (client._options.validate) {
45
+ assertValid(schemas.queryGovernanceAccessQueryParamsWire, query)
46
+ }
47
+ const searchParams = toURLSearchParams(query)
48
+ return http(client)
49
+ .post('openmeter/governance/query', {
50
+ ...options,
51
+ searchParams,
52
+ json: body,
53
+ })
54
+ .json()
55
+ .then((data) => {
56
+ if (client._options.validate) {
57
+ assertValid(schemas.queryGovernanceAccessResponseWire, data)
58
+ }
59
+ return fromWire(data, schemas.queryGovernanceAccessResponse)
60
+ })
61
+ })
62
+ }
api/spec/packages/aip-client-javascript/src/funcs/index.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ export * from './events.js'
4
+ export * from './meters.js'
5
+ export * from './customers.js'
6
+ export * from './entitlements.js'
7
+ export * from './subscriptions.js'
8
+ export * from './apps.js'
9
+ export * from './billing.js'
10
+ export * from './invoices.js'
11
+ export * from './tax.js'
12
+ export * from './currencies.js'
13
+ export * from './features.js'
14
+ export * from './llmCost.js'
15
+ export * from './plans.js'
16
+ export * from './addons.js'
17
+ export * from './planAddons.js'
18
+ export * from './defaults.js'
19
+ export * from './governance.js'
api/spec/packages/aip-client-javascript/src/funcs/invoices.ts ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListInvoicesRequest,
17
+ ListInvoicesResponse,
18
+ GetInvoiceRequest,
19
+ GetInvoiceResponse,
20
+ UpdateInvoiceRequest,
21
+ UpdateInvoiceResponse,
22
+ DeleteInvoiceRequest,
23
+ DeleteInvoiceResponse,
24
+ AdvanceInvoiceRequest,
25
+ AdvanceInvoiceResponse,
26
+ ApproveInvoiceRequest,
27
+ ApproveInvoiceResponse,
28
+ RetryInvoiceRequest,
29
+ RetryInvoiceResponse,
30
+ SnapshotQuantitiesInvoiceRequest,
31
+ SnapshotQuantitiesInvoiceResponse,
32
+ } from '../models/operations/invoices.js'
33
+
34
+ /**
35
+ * List billing invoices
36
+ *
37
+ * List billing invoices.
38
+ *
39
+ * Returns a page of invoices. Gathering invoices are never included. Use `filter`
40
+ * to narrow by status, customer, dates, or service period start. Use `sort` to
41
+ * control ordering.
42
+ *
43
+ * GET /openmeter/billing/invoices
44
+ */
45
+ export function listInvoices(
46
+ client: Client,
47
+ req: ListInvoicesRequest = {},
48
+ options?: RequestOptions,
49
+ ): Promise<Result<ListInvoicesResponse>> {
50
+ return request(() => {
51
+ if (client._options.validate && req.sort !== undefined) {
52
+ assertValid(schemas.listInvoicesQueryParams.shape.sort, req.sort)
53
+ }
54
+ const query = toWire(
55
+ {
56
+ page: req.page,
57
+ sort: encodeSort(req.sort, toSnakeCase),
58
+ filter: req.filter,
59
+ },
60
+ schemas.listInvoicesQueryParams,
61
+ )
62
+ if (client._options.validate) {
63
+ assertValid(schemas.listInvoicesQueryParamsWire, query)
64
+ }
65
+ const searchParams = toURLSearchParams(query)
66
+ return http(client)
67
+ .get('openmeter/billing/invoices', { ...options, searchParams })
68
+ .json()
69
+ .then((data) => {
70
+ if (client._options.validate) {
71
+ assertValid(schemas.listInvoicesResponseWire, data)
72
+ }
73
+ return fromWire(data, schemas.listInvoicesResponse)
74
+ })
75
+ })
76
+ }
77
+
78
+ /**
79
+ * Get a billing invoice
80
+ *
81
+ * Get a billing invoice by ID.
82
+ *
83
+ * Returns the full invoice resource including line items, status details, totals,
84
+ * and workflow configuration snapshot.
85
+ *
86
+ * GET /openmeter/billing/invoices/{invoiceId}
87
+ */
88
+ export function getInvoice(
89
+ client: Client,
90
+ req: GetInvoiceRequest,
91
+ options?: RequestOptions,
92
+ ): Promise<Result<GetInvoiceResponse>> {
93
+ return request(() => {
94
+ const pathParamsInput = {
95
+ invoiceId: req.invoiceId,
96
+ }
97
+ const pathParams = client._options.validate
98
+ ? toPathWire(pathParamsInput, schemas.getInvoicePathParams)
99
+ : pathParamsInput
100
+ if (client._options.validate) {
101
+ assertValid(schemas.getInvoicePathParamsWire, pathParams)
102
+ }
103
+ const path = `openmeter/billing/invoices/${(() => {
104
+ if (pathParams.invoiceId === undefined) {
105
+ throw new Error('missing path parameter: invoiceId')
106
+ }
107
+ return encodeURIComponent(String(pathParams.invoiceId))
108
+ })()}`
109
+ return http(client)
110
+ .get(path, options)
111
+ .json()
112
+ .then((data) => {
113
+ if (client._options.validate) {
114
+ assertValid(schemas.getInvoiceResponseWire, data)
115
+ }
116
+ return fromWire(data, schemas.getInvoiceResponse)
117
+ })
118
+ })
119
+ }
120
+
121
+ /**
122
+ * Update a billing invoice
123
+ *
124
+ * Update a billing invoice.
125
+ *
126
+ * Only the mutable fields of the invoice can be edited: description, labels,
127
+ * supplier, customer, workflow settings, and top-level lines. Top-level lines are
128
+ * matched by `id`; lines without an `id` are created, and existing lines omitted
129
+ * from `lines` are deleted. Detailed (child) lines are always computed and cannot
130
+ * be edited directly. Only invoices in draft status can be updated.
131
+ *
132
+ * PUT /openmeter/billing/invoices/{invoiceId}
133
+ */
134
+ export function updateInvoice(
135
+ client: Client,
136
+ req: UpdateInvoiceRequest,
137
+ options?: RequestOptions,
138
+ ): Promise<Result<UpdateInvoiceResponse>> {
139
+ return request(() => {
140
+ const pathParamsInput = {
141
+ invoiceId: req.invoiceId,
142
+ }
143
+ const pathParams = client._options.validate
144
+ ? toPathWire(pathParamsInput, schemas.updateInvoicePathParams)
145
+ : pathParamsInput
146
+ if (client._options.validate) {
147
+ assertValid(schemas.updateInvoicePathParamsWire, pathParams)
148
+ }
149
+ const path = `openmeter/billing/invoices/${(() => {
150
+ if (pathParams.invoiceId === undefined) {
151
+ throw new Error('missing path parameter: invoiceId')
152
+ }
153
+ return encodeURIComponent(String(pathParams.invoiceId))
154
+ })()}`
155
+ const body = toWire(req.body, schemas.updateInvoiceBody)
156
+ if (client._options.validate) {
157
+ assertValid(schemas.updateInvoiceBodyWire, body)
158
+ }
159
+ return http(client)
160
+ .put(path, { ...options, json: body })
161
+ .json()
162
+ .then((data) => {
163
+ if (client._options.validate) {
164
+ assertValid(schemas.updateInvoiceResponseWire, data)
165
+ }
166
+ return fromWire(data, schemas.updateInvoiceResponse)
167
+ })
168
+ })
169
+ }
170
+
171
+ /**
172
+ * Delete a billing invoice
173
+ *
174
+ * Delete a billing invoice.
175
+ *
176
+ * Only standard invoices in draft status can be deleted. Deleting an invoice will
177
+ * also delete all associated line items and workflow configuration.
178
+ *
179
+ * DELETE /openmeter/billing/invoices/{invoiceId}
180
+ */
181
+ export function deleteInvoice(
182
+ client: Client,
183
+ req: DeleteInvoiceRequest,
184
+ options?: RequestOptions,
185
+ ): Promise<Result<DeleteInvoiceResponse>> {
186
+ return request(async () => {
187
+ const pathParamsInput = {
188
+ invoiceId: req.invoiceId,
189
+ }
190
+ const pathParams = client._options.validate
191
+ ? toPathWire(pathParamsInput, schemas.deleteInvoicePathParams)
192
+ : pathParamsInput
193
+ if (client._options.validate) {
194
+ assertValid(schemas.deleteInvoicePathParamsWire, pathParams)
195
+ }
196
+ const path = `openmeter/billing/invoices/${(() => {
197
+ if (pathParams.invoiceId === undefined) {
198
+ throw new Error('missing path parameter: invoiceId')
199
+ }
200
+ return encodeURIComponent(String(pathParams.invoiceId))
201
+ })()}`
202
+ await http(client).delete(path, options)
203
+ })
204
+ }
205
+
206
+ /**
207
+ * Advance billing invoice's next status
208
+ *
209
+ * Advance a billing invoice.
210
+ *
211
+ * Advances the invoice to the next workflow state. The next state is determined by
212
+ * the invoice's current status and workflow configuration. Only invoices in draft
213
+ * or issued status can be advanced.
214
+ *
215
+ * POST /openmeter/billing/invoices/{invoiceId}/advance
216
+ */
217
+ export function advanceInvoice(
218
+ client: Client,
219
+ req: AdvanceInvoiceRequest,
220
+ options?: RequestOptions,
221
+ ): Promise<Result<AdvanceInvoiceResponse>> {
222
+ return request(() => {
223
+ const pathParamsInput = {
224
+ invoiceId: req.invoiceId,
225
+ }
226
+ const pathParams = client._options.validate
227
+ ? toPathWire(pathParamsInput, schemas.advanceInvoicePathParams)
228
+ : pathParamsInput
229
+ if (client._options.validate) {
230
+ assertValid(schemas.advanceInvoicePathParamsWire, pathParams)
231
+ }
232
+ const path = `openmeter/billing/invoices/${(() => {
233
+ if (pathParams.invoiceId === undefined) {
234
+ throw new Error('missing path parameter: invoiceId')
235
+ }
236
+ return encodeURIComponent(String(pathParams.invoiceId))
237
+ })()}/advance`
238
+ return http(client)
239
+ .post(path, options)
240
+ .json()
241
+ .then((data) => {
242
+ if (client._options.validate) {
243
+ assertValid(schemas.advanceInvoiceResponseWire, data)
244
+ }
245
+ return fromWire(data, schemas.advanceInvoiceResponse)
246
+ })
247
+ })
248
+ }
249
+
250
+ /**
251
+ * Send the invoice to the customer
252
+ *
253
+ * Approve a billing invoice.
254
+ *
255
+ * This call instantly sends the invoice to the customer using the configured
256
+ * billing profile app.
257
+ *
258
+ * This call is valid in two invoice statuses:
259
+ *
260
+ * - draft: the invoice will be sent to the customer, the invoice state becomes
261
+ * issued
262
+ * - manual_approval_needed: the invoice will be sent to the customer, the invoice
263
+ * state becomes issued
264
+ *
265
+ * POST /openmeter/billing/invoices/{invoiceId}/approve
266
+ */
267
+ export function approveInvoice(
268
+ client: Client,
269
+ req: ApproveInvoiceRequest,
270
+ options?: RequestOptions,
271
+ ): Promise<Result<ApproveInvoiceResponse>> {
272
+ return request(() => {
273
+ const pathParamsInput = {
274
+ invoiceId: req.invoiceId,
275
+ }
276
+ const pathParams = client._options.validate
277
+ ? toPathWire(pathParamsInput, schemas.approveInvoicePathParams)
278
+ : pathParamsInput
279
+ if (client._options.validate) {
280
+ assertValid(schemas.approveInvoicePathParamsWire, pathParams)
281
+ }
282
+ const path = `openmeter/billing/invoices/${(() => {
283
+ if (pathParams.invoiceId === undefined) {
284
+ throw new Error('missing path parameter: invoiceId')
285
+ }
286
+ return encodeURIComponent(String(pathParams.invoiceId))
287
+ })()}/approve`
288
+ return http(client)
289
+ .post(path, options)
290
+ .json()
291
+ .then((data) => {
292
+ if (client._options.validate) {
293
+ assertValid(schemas.approveInvoiceResponseWire, data)
294
+ }
295
+ return fromWire(data, schemas.approveInvoiceResponse)
296
+ })
297
+ })
298
+ }
299
+
300
+ /**
301
+ * Retry advancing the invoice after a failed attempt
302
+ *
303
+ * Retry sending a billing invoice.
304
+ *
305
+ * Retry advancing the invoice after a failed attempt.
306
+ *
307
+ * The action can be called when the invoice's statusDetails' actions field contain
308
+ * the "retry" action.
309
+ *
310
+ * POST /openmeter/billing/invoices/{invoiceId}/retry
311
+ */
312
+ export function retryInvoice(
313
+ client: Client,
314
+ req: RetryInvoiceRequest,
315
+ options?: RequestOptions,
316
+ ): Promise<Result<RetryInvoiceResponse>> {
317
+ return request(() => {
318
+ const pathParamsInput = {
319
+ invoiceId: req.invoiceId,
320
+ }
321
+ const pathParams = client._options.validate
322
+ ? toPathWire(pathParamsInput, schemas.retryInvoicePathParams)
323
+ : pathParamsInput
324
+ if (client._options.validate) {
325
+ assertValid(schemas.retryInvoicePathParamsWire, pathParams)
326
+ }
327
+ const path = `openmeter/billing/invoices/${(() => {
328
+ if (pathParams.invoiceId === undefined) {
329
+ throw new Error('missing path parameter: invoiceId')
330
+ }
331
+ return encodeURIComponent(String(pathParams.invoiceId))
332
+ })()}/retry`
333
+ return http(client)
334
+ .post(path, options)
335
+ .json()
336
+ .then((data) => {
337
+ if (client._options.validate) {
338
+ assertValid(schemas.retryInvoiceResponseWire, data)
339
+ }
340
+ return fromWire(data, schemas.retryInvoiceResponse)
341
+ })
342
+ })
343
+ }
344
+
345
+ /**
346
+ * Snapshot quantities for usage based line items
347
+ *
348
+ * Snapshot quantities for usage-based line items.
349
+ *
350
+ * This call will snapshot the quantities for all usage based line items in the
351
+ * invoice.
352
+ *
353
+ * This call is only valid in draft.waiting_for_collection status, where the
354
+ * collection period can be skipped using this action.
355
+ *
356
+ * POST /openmeter/billing/invoices/{invoiceId}/snapshot-quantities
357
+ */
358
+ export function snapshotQuantitiesInvoice(
359
+ client: Client,
360
+ req: SnapshotQuantitiesInvoiceRequest,
361
+ options?: RequestOptions,
362
+ ): Promise<Result<SnapshotQuantitiesInvoiceResponse>> {
363
+ return request(() => {
364
+ const pathParamsInput = {
365
+ invoiceId: req.invoiceId,
366
+ }
367
+ const pathParams = client._options.validate
368
+ ? toPathWire(pathParamsInput, schemas.snapshotQuantitiesInvoicePathParams)
369
+ : pathParamsInput
370
+ if (client._options.validate) {
371
+ assertValid(schemas.snapshotQuantitiesInvoicePathParamsWire, pathParams)
372
+ }
373
+ const path = `openmeter/billing/invoices/${(() => {
374
+ if (pathParams.invoiceId === undefined) {
375
+ throw new Error('missing path parameter: invoiceId')
376
+ }
377
+ return encodeURIComponent(String(pathParams.invoiceId))
378
+ })()}/snapshot-quantities`
379
+ return http(client)
380
+ .post(path, options)
381
+ .json()
382
+ .then((data) => {
383
+ if (client._options.validate) {
384
+ assertValid(schemas.snapshotQuantitiesInvoiceResponseWire, data)
385
+ }
386
+ return fromWire(data, schemas.snapshotQuantitiesInvoiceResponse)
387
+ })
388
+ })
389
+ }
api/spec/packages/aip-client-javascript/src/funcs/llmCost.ts ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListLlmCostPricesRequest,
17
+ ListLlmCostPricesResponse,
18
+ GetLlmCostPriceRequest,
19
+ GetLlmCostPriceResponse,
20
+ ListLlmCostOverridesRequest,
21
+ ListLlmCostOverridesResponse,
22
+ CreateLlmCostOverrideRequest,
23
+ CreateLlmCostOverrideResponse,
24
+ DeleteLlmCostOverrideRequest,
25
+ DeleteLlmCostOverrideResponse,
26
+ } from '../models/operations/llmCost.js'
27
+
28
+ /**
29
+ * List LLM cost prices
30
+ *
31
+ * List global LLM cost prices. Returns prices with overrides applied if any.
32
+ *
33
+ * GET /openmeter/llm-cost/prices
34
+ */
35
+ export function listLlmCostPrices(
36
+ client: Client,
37
+ req: ListLlmCostPricesRequest = {},
38
+ options?: RequestOptions,
39
+ ): Promise<Result<ListLlmCostPricesResponse>> {
40
+ return request(() => {
41
+ if (client._options.validate && req.sort !== undefined) {
42
+ assertValid(schemas.listLlmCostPricesQueryParams.shape.sort, req.sort)
43
+ }
44
+ const query = toWire(
45
+ {
46
+ filter: req.filter,
47
+ sort: encodeSort(req.sort, toSnakeCase),
48
+ page: req.page,
49
+ },
50
+ schemas.listLlmCostPricesQueryParams,
51
+ )
52
+ if (client._options.validate) {
53
+ assertValid(schemas.listLlmCostPricesQueryParamsWire, query)
54
+ }
55
+ const searchParams = toURLSearchParams(query)
56
+ return http(client)
57
+ .get('openmeter/llm-cost/prices', { ...options, searchParams })
58
+ .json()
59
+ .then((data) => {
60
+ if (client._options.validate) {
61
+ assertValid(schemas.listLlmCostPricesResponseWire, data)
62
+ }
63
+ return fromWire(data, schemas.listLlmCostPricesResponse)
64
+ })
65
+ })
66
+ }
67
+
68
+ /**
69
+ * Get LLM cost price
70
+ *
71
+ * Get a specific LLM cost price by ID. Returns the price with overrides applied if
72
+ * any.
73
+ *
74
+ * GET /openmeter/llm-cost/prices/{priceId}
75
+ */
76
+ export function getLlmCostPrice(
77
+ client: Client,
78
+ req: GetLlmCostPriceRequest,
79
+ options?: RequestOptions,
80
+ ): Promise<Result<GetLlmCostPriceResponse>> {
81
+ return request(() => {
82
+ const pathParamsInput = {
83
+ priceId: req.priceId,
84
+ }
85
+ const pathParams = client._options.validate
86
+ ? toPathWire(pathParamsInput, schemas.getLlmCostPricePathParams)
87
+ : pathParamsInput
88
+ if (client._options.validate) {
89
+ assertValid(schemas.getLlmCostPricePathParamsWire, pathParams)
90
+ }
91
+ const path = `openmeter/llm-cost/prices/${(() => {
92
+ if (pathParams.priceId === undefined) {
93
+ throw new Error('missing path parameter: priceId')
94
+ }
95
+ return encodeURIComponent(String(pathParams.priceId))
96
+ })()}`
97
+ return http(client)
98
+ .get(path, options)
99
+ .json()
100
+ .then((data) => {
101
+ if (client._options.validate) {
102
+ assertValid(schemas.getLlmCostPriceResponseWire, data)
103
+ }
104
+ return fromWire(data, schemas.getLlmCostPriceResponse)
105
+ })
106
+ })
107
+ }
108
+
109
+ /**
110
+ * List LLM cost overrides
111
+ *
112
+ * List per-namespace price overrides.
113
+ *
114
+ * GET /openmeter/llm-cost/overrides
115
+ */
116
+ export function listLlmCostOverrides(
117
+ client: Client,
118
+ req: ListLlmCostOverridesRequest = {},
119
+ options?: RequestOptions,
120
+ ): Promise<Result<ListLlmCostOverridesResponse>> {
121
+ return request(() => {
122
+ const query = toWire(
123
+ {
124
+ filter: req.filter,
125
+ page: req.page,
126
+ },
127
+ schemas.listLlmCostOverridesQueryParams,
128
+ )
129
+ if (client._options.validate) {
130
+ assertValid(schemas.listLlmCostOverridesQueryParamsWire, query)
131
+ }
132
+ const searchParams = toURLSearchParams(query)
133
+ return http(client)
134
+ .get('openmeter/llm-cost/overrides', { ...options, searchParams })
135
+ .json()
136
+ .then((data) => {
137
+ if (client._options.validate) {
138
+ assertValid(schemas.listLlmCostOverridesResponseWire, data)
139
+ }
140
+ return fromWire(data, schemas.listLlmCostOverridesResponse)
141
+ })
142
+ })
143
+ }
144
+
145
+ /**
146
+ * Create LLM cost override
147
+ *
148
+ * Create a per-namespace price override.
149
+ *
150
+ * POST /openmeter/llm-cost/overrides
151
+ */
152
+ export function createLlmCostOverride(
153
+ client: Client,
154
+ req: CreateLlmCostOverrideRequest,
155
+ options?: RequestOptions,
156
+ ): Promise<Result<CreateLlmCostOverrideResponse>> {
157
+ return request(() => {
158
+ const body = toWire(req, schemas.createLlmCostOverrideBody)
159
+ if (client._options.validate) {
160
+ assertValid(schemas.createLlmCostOverrideBodyWire, body)
161
+ }
162
+ return http(client)
163
+ .post('openmeter/llm-cost/overrides', { ...options, json: body })
164
+ .json()
165
+ .then((data) => {
166
+ if (client._options.validate) {
167
+ assertValid(schemas.createLlmCostOverrideResponseWire, data)
168
+ }
169
+ return fromWire(data, schemas.createLlmCostOverrideResponse)
170
+ })
171
+ })
172
+ }
173
+
174
+ /**
175
+ * Delete LLM cost override
176
+ *
177
+ * Delete a per-namespace price override.
178
+ *
179
+ * DELETE /openmeter/llm-cost/overrides/{priceId}
180
+ */
181
+ export function deleteLlmCostOverride(
182
+ client: Client,
183
+ req: DeleteLlmCostOverrideRequest,
184
+ options?: RequestOptions,
185
+ ): Promise<Result<DeleteLlmCostOverrideResponse>> {
186
+ return request(async () => {
187
+ const pathParamsInput = {
188
+ priceId: req.priceId,
189
+ }
190
+ const pathParams = client._options.validate
191
+ ? toPathWire(pathParamsInput, schemas.deleteLlmCostOverridePathParams)
192
+ : pathParamsInput
193
+ if (client._options.validate) {
194
+ assertValid(schemas.deleteLlmCostOverridePathParamsWire, pathParams)
195
+ }
196
+ const path = `openmeter/llm-cost/overrides/${(() => {
197
+ if (pathParams.priceId === undefined) {
198
+ throw new Error('missing path parameter: priceId')
199
+ }
200
+ return encodeURIComponent(String(pathParams.priceId))
201
+ })()}`
202
+ await http(client).delete(path, options)
203
+ })
204
+ }
api/spec/packages/aip-client-javascript/src/funcs/meters.ts ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ CreateMeterRequest,
17
+ CreateMeterResponse,
18
+ GetMeterRequest,
19
+ GetMeterResponse,
20
+ ListMetersRequest,
21
+ ListMetersResponse,
22
+ UpdateMeterRequest,
23
+ UpdateMeterResponse,
24
+ DeleteMeterRequest,
25
+ DeleteMeterResponse,
26
+ QueryMeterRequest,
27
+ QueryMeterResponse,
28
+ QueryMeterCsvRequest,
29
+ QueryMeterCsvResponse,
30
+ } from '../models/operations/meters.js'
31
+
32
+ /**
33
+ * Create meter
34
+ *
35
+ * Create a meter.
36
+ *
37
+ * POST /openmeter/meters
38
+ */
39
+ export function createMeter(
40
+ client: Client,
41
+ req: CreateMeterRequest,
42
+ options?: RequestOptions,
43
+ ): Promise<Result<CreateMeterResponse>> {
44
+ return request(() => {
45
+ const body = toWire(req, schemas.createMeterBody)
46
+ if (client._options.validate) {
47
+ assertValid(schemas.createMeterBodyWire, body)
48
+ }
49
+ return http(client)
50
+ .post('openmeter/meters', { ...options, json: body })
51
+ .json()
52
+ .then((data) => {
53
+ if (client._options.validate) {
54
+ assertValid(schemas.createMeterResponseWire, data)
55
+ }
56
+ return fromWire(data, schemas.createMeterResponse)
57
+ })
58
+ })
59
+ }
60
+
61
+ /**
62
+ * Get meter
63
+ *
64
+ * Get a meter by ID.
65
+ *
66
+ * GET /openmeter/meters/{meterId}
67
+ */
68
+ export function getMeter(
69
+ client: Client,
70
+ req: GetMeterRequest,
71
+ options?: RequestOptions,
72
+ ): Promise<Result<GetMeterResponse>> {
73
+ return request(() => {
74
+ const pathParamsInput = {
75
+ meterId: req.meterId,
76
+ }
77
+ const pathParams = client._options.validate
78
+ ? toPathWire(pathParamsInput, schemas.getMeterPathParams)
79
+ : pathParamsInput
80
+ if (client._options.validate) {
81
+ assertValid(schemas.getMeterPathParamsWire, pathParams)
82
+ }
83
+ const path = `openmeter/meters/${(() => {
84
+ if (pathParams.meterId === undefined) {
85
+ throw new Error('missing path parameter: meterId')
86
+ }
87
+ return encodeURIComponent(String(pathParams.meterId))
88
+ })()}`
89
+ return http(client)
90
+ .get(path, options)
91
+ .json()
92
+ .then((data) => {
93
+ if (client._options.validate) {
94
+ assertValid(schemas.getMeterResponseWire, data)
95
+ }
96
+ return fromWire(data, schemas.getMeterResponse)
97
+ })
98
+ })
99
+ }
100
+
101
+ /**
102
+ * List meters
103
+ *
104
+ * List meters.
105
+ *
106
+ * GET /openmeter/meters
107
+ */
108
+ export function listMeters(
109
+ client: Client,
110
+ req: ListMetersRequest = {},
111
+ options?: RequestOptions,
112
+ ): Promise<Result<ListMetersResponse>> {
113
+ return request(() => {
114
+ if (client._options.validate && req.sort !== undefined) {
115
+ assertValid(schemas.listMetersQueryParams.shape.sort, req.sort)
116
+ }
117
+ const query = toWire(
118
+ {
119
+ page: req.page,
120
+ sort: encodeSort(req.sort, toSnakeCase),
121
+ filter: req.filter,
122
+ },
123
+ schemas.listMetersQueryParams,
124
+ )
125
+ if (client._options.validate) {
126
+ assertValid(schemas.listMetersQueryParamsWire, query)
127
+ }
128
+ const searchParams = toURLSearchParams(query)
129
+ return http(client)
130
+ .get('openmeter/meters', { ...options, searchParams })
131
+ .json()
132
+ .then((data) => {
133
+ if (client._options.validate) {
134
+ assertValid(schemas.listMetersResponseWire, data)
135
+ }
136
+ return fromWire(data, schemas.listMetersResponse)
137
+ })
138
+ })
139
+ }
140
+
141
+ /**
142
+ * Update meter
143
+ *
144
+ * Update a meter.
145
+ *
146
+ * PUT /openmeter/meters/{meterId}
147
+ */
148
+ export function updateMeter(
149
+ client: Client,
150
+ req: UpdateMeterRequest,
151
+ options?: RequestOptions,
152
+ ): Promise<Result<UpdateMeterResponse>> {
153
+ return request(() => {
154
+ const pathParamsInput = {
155
+ meterId: req.meterId,
156
+ }
157
+ const pathParams = client._options.validate
158
+ ? toPathWire(pathParamsInput, schemas.updateMeterPathParams)
159
+ : pathParamsInput
160
+ if (client._options.validate) {
161
+ assertValid(schemas.updateMeterPathParamsWire, pathParams)
162
+ }
163
+ const path = `openmeter/meters/${(() => {
164
+ if (pathParams.meterId === undefined) {
165
+ throw new Error('missing path parameter: meterId')
166
+ }
167
+ return encodeURIComponent(String(pathParams.meterId))
168
+ })()}`
169
+ const body = toWire(req.body, schemas.updateMeterBody)
170
+ if (client._options.validate) {
171
+ assertValid(schemas.updateMeterBodyWire, body)
172
+ }
173
+ return http(client)
174
+ .put(path, { ...options, json: body })
175
+ .json()
176
+ .then((data) => {
177
+ if (client._options.validate) {
178
+ assertValid(schemas.updateMeterResponseWire, data)
179
+ }
180
+ return fromWire(data, schemas.updateMeterResponse)
181
+ })
182
+ })
183
+ }
184
+
185
+ /**
186
+ * Delete meter
187
+ *
188
+ * Delete a meter.
189
+ *
190
+ * DELETE /openmeter/meters/{meterId}
191
+ */
192
+ export function deleteMeter(
193
+ client: Client,
194
+ req: DeleteMeterRequest,
195
+ options?: RequestOptions,
196
+ ): Promise<Result<DeleteMeterResponse>> {
197
+ return request(async () => {
198
+ const pathParamsInput = {
199
+ meterId: req.meterId,
200
+ }
201
+ const pathParams = client._options.validate
202
+ ? toPathWire(pathParamsInput, schemas.deleteMeterPathParams)
203
+ : pathParamsInput
204
+ if (client._options.validate) {
205
+ assertValid(schemas.deleteMeterPathParamsWire, pathParams)
206
+ }
207
+ const path = `openmeter/meters/${(() => {
208
+ if (pathParams.meterId === undefined) {
209
+ throw new Error('missing path parameter: meterId')
210
+ }
211
+ return encodeURIComponent(String(pathParams.meterId))
212
+ })()}`
213
+ await http(client).delete(path, options)
214
+ })
215
+ }
216
+
217
+ /**
218
+ * Query meter
219
+ *
220
+ * Query a meter for usage.
221
+ *
222
+ * Set `Accept: application/json` (the default) to get a structured JSON response.
223
+ * Set `Accept: text/csv` to download the same data as a CSV file suitable for
224
+ * spreadsheets. The CSV columns, in order, are:
225
+ *
226
+ * `from, to, [subject,] [customer_id, customer_key, customer_name,] <dimensions...>, value`
227
+ *
228
+ * The `subject` column is emitted only when `subject` is in the query's
229
+ * `group_by_dimensions`. The three `customer_*` columns are emitted together only
230
+ * when `customer_id` is in the query's `group_by_dimensions`.
231
+ *
232
+ * POST /openmeter/meters/{meterId}/query
233
+ */
234
+ export function queryMeter(
235
+ client: Client,
236
+ req: QueryMeterRequest,
237
+ options?: RequestOptions,
238
+ ): Promise<Result<QueryMeterResponse>> {
239
+ return request(() => {
240
+ const pathParamsInput = {
241
+ meterId: req.meterId,
242
+ }
243
+ const pathParams = client._options.validate
244
+ ? toPathWire(pathParamsInput, schemas.queryMeterPathParams)
245
+ : pathParamsInput
246
+ if (client._options.validate) {
247
+ assertValid(schemas.queryMeterPathParamsWire, pathParams)
248
+ }
249
+ const path = `openmeter/meters/${(() => {
250
+ if (pathParams.meterId === undefined) {
251
+ throw new Error('missing path parameter: meterId')
252
+ }
253
+ return encodeURIComponent(String(pathParams.meterId))
254
+ })()}/query`
255
+ const body = toWire(req.body, schemas.queryMeterBody)
256
+ if (client._options.validate) {
257
+ assertValid(schemas.queryMeterBodyWire, body)
258
+ }
259
+ return http(client)
260
+ .post(path, { ...options, json: body })
261
+ .json()
262
+ .then((data) => {
263
+ if (client._options.validate) {
264
+ assertValid(schemas.queryMeterResponseWire, data)
265
+ }
266
+ return fromWire(data, schemas.queryMeterResponse)
267
+ })
268
+ })
269
+ }
270
+
271
+ /** POST /openmeter/meters/{meterId}/query */
272
+ export function queryMeterCsv(
273
+ client: Client,
274
+ req: QueryMeterCsvRequest,
275
+ options?: RequestOptions,
276
+ ): Promise<Result<QueryMeterCsvResponse>> {
277
+ const headers = new Headers(options?.headers as HeadersInit | undefined)
278
+ headers.set('accept', 'text/csv')
279
+ return request(() => {
280
+ const pathParamsInput = {
281
+ meterId: req.meterId,
282
+ }
283
+ const pathParams = client._options.validate
284
+ ? toPathWire(pathParamsInput, schemas.queryMeterCsvPathParams)
285
+ : pathParamsInput
286
+ if (client._options.validate) {
287
+ assertValid(schemas.queryMeterCsvPathParamsWire, pathParams)
288
+ }
289
+ const path = `openmeter/meters/${(() => {
290
+ if (pathParams.meterId === undefined) {
291
+ throw new Error('missing path parameter: meterId')
292
+ }
293
+ return encodeURIComponent(String(pathParams.meterId))
294
+ })()}/query`
295
+ const body = toWire(req.body, schemas.queryMeterCsvBody)
296
+ if (client._options.validate) {
297
+ assertValid(schemas.queryMeterCsvBodyWire, body)
298
+ }
299
+ return http(client)
300
+ .post(path, { ...options, json: body, headers })
301
+ .text()
302
+ })
303
+ }
api/spec/packages/aip-client-javascript/src/funcs/planAddons.ts ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams } from '../lib/encodings.js'
7
+ import { toWire, toPathWire, fromWire, assertValid } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ ListPlanAddonsRequest,
11
+ ListPlanAddonsResponse,
12
+ CreatePlanAddonRequest,
13
+ CreatePlanAddonResponse,
14
+ GetPlanAddonRequest,
15
+ GetPlanAddonResponse,
16
+ UpdatePlanAddonRequest,
17
+ UpdatePlanAddonResponse,
18
+ DeletePlanAddonRequest,
19
+ DeletePlanAddonResponse,
20
+ } from '../models/operations/planAddons.js'
21
+
22
+ /**
23
+ * List add-ons for plan
24
+ *
25
+ * List add-ons associated with a plan.
26
+ *
27
+ * GET /openmeter/plans/{planId}/addons
28
+ */
29
+ export function listPlanAddons(
30
+ client: Client,
31
+ req: ListPlanAddonsRequest,
32
+ options?: RequestOptions,
33
+ ): Promise<Result<ListPlanAddonsResponse>> {
34
+ return request(() => {
35
+ const pathParamsInput = {
36
+ planId: req.planId,
37
+ }
38
+ const pathParams = client._options.validate
39
+ ? toPathWire(pathParamsInput, schemas.listPlanAddonsPathParams)
40
+ : pathParamsInput
41
+ if (client._options.validate) {
42
+ assertValid(schemas.listPlanAddonsPathParamsWire, pathParams)
43
+ }
44
+ const path = `openmeter/plans/${(() => {
45
+ if (pathParams.planId === undefined) {
46
+ throw new Error('missing path parameter: planId')
47
+ }
48
+ return encodeURIComponent(String(pathParams.planId))
49
+ })()}/addons`
50
+ const query = toWire(
51
+ {
52
+ page: req.page,
53
+ },
54
+ schemas.listPlanAddonsQueryParams,
55
+ )
56
+ if (client._options.validate) {
57
+ assertValid(schemas.listPlanAddonsQueryParamsWire, query)
58
+ }
59
+ const searchParams = toURLSearchParams(query)
60
+ return http(client)
61
+ .get(path, { ...options, searchParams })
62
+ .json()
63
+ .then((data) => {
64
+ if (client._options.validate) {
65
+ assertValid(schemas.listPlanAddonsResponseWire, data)
66
+ }
67
+ return fromWire(data, schemas.listPlanAddonsResponse)
68
+ })
69
+ })
70
+ }
71
+
72
+ /**
73
+ * Add add-on to plan
74
+ *
75
+ * Add an add-on to a plan.
76
+ *
77
+ * POST /openmeter/plans/{planId}/addons
78
+ */
79
+ export function createPlanAddon(
80
+ client: Client,
81
+ req: CreatePlanAddonRequest,
82
+ options?: RequestOptions,
83
+ ): Promise<Result<CreatePlanAddonResponse>> {
84
+ return request(() => {
85
+ const pathParamsInput = {
86
+ planId: req.planId,
87
+ }
88
+ const pathParams = client._options.validate
89
+ ? toPathWire(pathParamsInput, schemas.createPlanAddonPathParams)
90
+ : pathParamsInput
91
+ if (client._options.validate) {
92
+ assertValid(schemas.createPlanAddonPathParamsWire, pathParams)
93
+ }
94
+ const path = `openmeter/plans/${(() => {
95
+ if (pathParams.planId === undefined) {
96
+ throw new Error('missing path parameter: planId')
97
+ }
98
+ return encodeURIComponent(String(pathParams.planId))
99
+ })()}/addons`
100
+ const body = toWire(req.body, schemas.createPlanAddonBody)
101
+ if (client._options.validate) {
102
+ assertValid(schemas.createPlanAddonBodyWire, body)
103
+ }
104
+ return http(client)
105
+ .post(path, { ...options, json: body })
106
+ .json()
107
+ .then((data) => {
108
+ if (client._options.validate) {
109
+ assertValid(schemas.createPlanAddonResponseWire, data)
110
+ }
111
+ return fromWire(data, schemas.createPlanAddonResponse)
112
+ })
113
+ })
114
+ }
115
+
116
+ /**
117
+ * Get add-on association for plan
118
+ *
119
+ * Get an add-on association for a plan.
120
+ *
121
+ * GET /openmeter/plans/{planId}/addons/{planAddonId}
122
+ */
123
+ export function getPlanAddon(
124
+ client: Client,
125
+ req: GetPlanAddonRequest,
126
+ options?: RequestOptions,
127
+ ): Promise<Result<GetPlanAddonResponse>> {
128
+ return request(() => {
129
+ const pathParamsInput = {
130
+ planId: req.planId,
131
+ planAddonId: req.planAddonId,
132
+ }
133
+ const pathParams = client._options.validate
134
+ ? toPathWire(pathParamsInput, schemas.getPlanAddonPathParams)
135
+ : pathParamsInput
136
+ if (client._options.validate) {
137
+ assertValid(schemas.getPlanAddonPathParamsWire, pathParams)
138
+ }
139
+ const path = `openmeter/plans/${(() => {
140
+ if (pathParams.planId === undefined) {
141
+ throw new Error('missing path parameter: planId')
142
+ }
143
+ return encodeURIComponent(String(pathParams.planId))
144
+ })()}/addons/${(() => {
145
+ if (pathParams.planAddonId === undefined) {
146
+ throw new Error('missing path parameter: planAddonId')
147
+ }
148
+ return encodeURIComponent(String(pathParams.planAddonId))
149
+ })()}`
150
+ return http(client)
151
+ .get(path, options)
152
+ .json()
153
+ .then((data) => {
154
+ if (client._options.validate) {
155
+ assertValid(schemas.getPlanAddonResponseWire, data)
156
+ }
157
+ return fromWire(data, schemas.getPlanAddonResponse)
158
+ })
159
+ })
160
+ }
161
+
162
+ /**
163
+ * Update add-on association for plan
164
+ *
165
+ * Update an add-on association for a plan.
166
+ *
167
+ * PUT /openmeter/plans/{planId}/addons/{planAddonId}
168
+ */
169
+ export function updatePlanAddon(
170
+ client: Client,
171
+ req: UpdatePlanAddonRequest,
172
+ options?: RequestOptions,
173
+ ): Promise<Result<UpdatePlanAddonResponse>> {
174
+ return request(() => {
175
+ const pathParamsInput = {
176
+ planId: req.planId,
177
+ planAddonId: req.planAddonId,
178
+ }
179
+ const pathParams = client._options.validate
180
+ ? toPathWire(pathParamsInput, schemas.updatePlanAddonPathParams)
181
+ : pathParamsInput
182
+ if (client._options.validate) {
183
+ assertValid(schemas.updatePlanAddonPathParamsWire, pathParams)
184
+ }
185
+ const path = `openmeter/plans/${(() => {
186
+ if (pathParams.planId === undefined) {
187
+ throw new Error('missing path parameter: planId')
188
+ }
189
+ return encodeURIComponent(String(pathParams.planId))
190
+ })()}/addons/${(() => {
191
+ if (pathParams.planAddonId === undefined) {
192
+ throw new Error('missing path parameter: planAddonId')
193
+ }
194
+ return encodeURIComponent(String(pathParams.planAddonId))
195
+ })()}`
196
+ const body = toWire(req.body, schemas.updatePlanAddonBody)
197
+ if (client._options.validate) {
198
+ assertValid(schemas.updatePlanAddonBodyWire, body)
199
+ }
200
+ return http(client)
201
+ .put(path, { ...options, json: body })
202
+ .json()
203
+ .then((data) => {
204
+ if (client._options.validate) {
205
+ assertValid(schemas.updatePlanAddonResponseWire, data)
206
+ }
207
+ return fromWire(data, schemas.updatePlanAddonResponse)
208
+ })
209
+ })
210
+ }
211
+
212
+ /**
213
+ * Remove add-on from plan
214
+ *
215
+ * Remove an add-on from a plan.
216
+ *
217
+ * DELETE /openmeter/plans/{planId}/addons/{planAddonId}
218
+ */
219
+ export function deletePlanAddon(
220
+ client: Client,
221
+ req: DeletePlanAddonRequest,
222
+ options?: RequestOptions,
223
+ ): Promise<Result<DeletePlanAddonResponse>> {
224
+ return request(async () => {
225
+ const pathParamsInput = {
226
+ planId: req.planId,
227
+ planAddonId: req.planAddonId,
228
+ }
229
+ const pathParams = client._options.validate
230
+ ? toPathWire(pathParamsInput, schemas.deletePlanAddonPathParams)
231
+ : pathParamsInput
232
+ if (client._options.validate) {
233
+ assertValid(schemas.deletePlanAddonPathParamsWire, pathParams)
234
+ }
235
+ const path = `openmeter/plans/${(() => {
236
+ if (pathParams.planId === undefined) {
237
+ throw new Error('missing path parameter: planId')
238
+ }
239
+ return encodeURIComponent(String(pathParams.planId))
240
+ })()}/addons/${(() => {
241
+ if (pathParams.planAddonId === undefined) {
242
+ throw new Error('missing path parameter: planAddonId')
243
+ }
244
+ return encodeURIComponent(String(pathParams.planAddonId))
245
+ })()}`
246
+ await http(client).delete(path, options)
247
+ })
248
+ }
api/spec/packages/aip-client-javascript/src/funcs/plans.ts ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ ListPlansRequest,
17
+ ListPlansResponse,
18
+ CreatePlanRequest,
19
+ CreatePlanResponse,
20
+ UpdatePlanRequest,
21
+ UpdatePlanResponse,
22
+ GetPlanRequest,
23
+ GetPlanResponse,
24
+ DeletePlanRequest,
25
+ DeletePlanResponse,
26
+ ArchivePlanRequest,
27
+ ArchivePlanResponse,
28
+ PublishPlanRequest,
29
+ PublishPlanResponse,
30
+ } from '../models/operations/plans.js'
31
+
32
+ /**
33
+ * List plans
34
+ *
35
+ * List all plans.
36
+ *
37
+ * GET /openmeter/plans
38
+ */
39
+ export function listPlans(
40
+ client: Client,
41
+ req: ListPlansRequest = {},
42
+ options?: RequestOptions,
43
+ ): Promise<Result<ListPlansResponse>> {
44
+ return request(() => {
45
+ if (client._options.validate && req.sort !== undefined) {
46
+ assertValid(schemas.listPlansQueryParams.shape.sort, req.sort)
47
+ }
48
+ const query = toWire(
49
+ {
50
+ page: req.page,
51
+ sort: encodeSort(req.sort, toSnakeCase),
52
+ filter: req.filter,
53
+ },
54
+ schemas.listPlansQueryParams,
55
+ )
56
+ if (client._options.validate) {
57
+ assertValid(schemas.listPlansQueryParamsWire, query)
58
+ }
59
+ const searchParams = toURLSearchParams(query)
60
+ return http(client)
61
+ .get('openmeter/plans', { ...options, searchParams })
62
+ .json()
63
+ .then((data) => {
64
+ if (client._options.validate) {
65
+ assertValid(schemas.listPlansResponseWire, data)
66
+ }
67
+ return fromWire(data, schemas.listPlansResponse)
68
+ })
69
+ })
70
+ }
71
+
72
+ /**
73
+ * Create plan
74
+ *
75
+ * Create a new plan.
76
+ *
77
+ * POST /openmeter/plans
78
+ */
79
+ export function createPlan(
80
+ client: Client,
81
+ req: CreatePlanRequest,
82
+ options?: RequestOptions,
83
+ ): Promise<Result<CreatePlanResponse>> {
84
+ return request(() => {
85
+ const body = toWire(req, schemas.createPlanBody)
86
+ if (client._options.validate) {
87
+ assertValid(schemas.createPlanBodyWire, body)
88
+ }
89
+ return http(client)
90
+ .post('openmeter/plans', { ...options, json: body })
91
+ .json()
92
+ .then((data) => {
93
+ if (client._options.validate) {
94
+ assertValid(schemas.createPlanResponseWire, data)
95
+ }
96
+ return fromWire(data, schemas.createPlanResponse)
97
+ })
98
+ })
99
+ }
100
+
101
+ /**
102
+ * Update plan
103
+ *
104
+ * Update a plan by id.
105
+ *
106
+ * PUT /openmeter/plans/{planId}
107
+ */
108
+ export function updatePlan(
109
+ client: Client,
110
+ req: UpdatePlanRequest,
111
+ options?: RequestOptions,
112
+ ): Promise<Result<UpdatePlanResponse>> {
113
+ return request(() => {
114
+ const pathParamsInput = {
115
+ planId: req.planId,
116
+ }
117
+ const pathParams = client._options.validate
118
+ ? toPathWire(pathParamsInput, schemas.updatePlanPathParams)
119
+ : pathParamsInput
120
+ if (client._options.validate) {
121
+ assertValid(schemas.updatePlanPathParamsWire, pathParams)
122
+ }
123
+ const path = `openmeter/plans/${(() => {
124
+ if (pathParams.planId === undefined) {
125
+ throw new Error('missing path parameter: planId')
126
+ }
127
+ return encodeURIComponent(String(pathParams.planId))
128
+ })()}`
129
+ const body = toWire(req.body, schemas.updatePlanBody)
130
+ if (client._options.validate) {
131
+ assertValid(schemas.updatePlanBodyWire, body)
132
+ }
133
+ return http(client)
134
+ .put(path, { ...options, json: body })
135
+ .json()
136
+ .then((data) => {
137
+ if (client._options.validate) {
138
+ assertValid(schemas.updatePlanResponseWire, data)
139
+ }
140
+ return fromWire(data, schemas.updatePlanResponse)
141
+ })
142
+ })
143
+ }
144
+
145
+ /**
146
+ * Get plan
147
+ *
148
+ * Get a plan by id.
149
+ *
150
+ * GET /openmeter/plans/{planId}
151
+ */
152
+ export function getPlan(
153
+ client: Client,
154
+ req: GetPlanRequest,
155
+ options?: RequestOptions,
156
+ ): Promise<Result<GetPlanResponse>> {
157
+ return request(() => {
158
+ const pathParamsInput = {
159
+ planId: req.planId,
160
+ }
161
+ const pathParams = client._options.validate
162
+ ? toPathWire(pathParamsInput, schemas.getPlanPathParams)
163
+ : pathParamsInput
164
+ if (client._options.validate) {
165
+ assertValid(schemas.getPlanPathParamsWire, pathParams)
166
+ }
167
+ const path = `openmeter/plans/${(() => {
168
+ if (pathParams.planId === undefined) {
169
+ throw new Error('missing path parameter: planId')
170
+ }
171
+ return encodeURIComponent(String(pathParams.planId))
172
+ })()}`
173
+ return http(client)
174
+ .get(path, options)
175
+ .json()
176
+ .then((data) => {
177
+ if (client._options.validate) {
178
+ assertValid(schemas.getPlanResponseWire, data)
179
+ }
180
+ return fromWire(data, schemas.getPlanResponse)
181
+ })
182
+ })
183
+ }
184
+
185
+ /**
186
+ * Delete plan
187
+ *
188
+ * Delete a plan by id.
189
+ *
190
+ * DELETE /openmeter/plans/{planId}
191
+ */
192
+ export function deletePlan(
193
+ client: Client,
194
+ req: DeletePlanRequest,
195
+ options?: RequestOptions,
196
+ ): Promise<Result<DeletePlanResponse>> {
197
+ return request(async () => {
198
+ const pathParamsInput = {
199
+ planId: req.planId,
200
+ }
201
+ const pathParams = client._options.validate
202
+ ? toPathWire(pathParamsInput, schemas.deletePlanPathParams)
203
+ : pathParamsInput
204
+ if (client._options.validate) {
205
+ assertValid(schemas.deletePlanPathParamsWire, pathParams)
206
+ }
207
+ const path = `openmeter/plans/${(() => {
208
+ if (pathParams.planId === undefined) {
209
+ throw new Error('missing path parameter: planId')
210
+ }
211
+ return encodeURIComponent(String(pathParams.planId))
212
+ })()}`
213
+ await http(client).delete(path, options)
214
+ })
215
+ }
216
+
217
+ /**
218
+ * Archive plan version
219
+ *
220
+ * Archive a plan version.
221
+ *
222
+ * POST /openmeter/plans/{planId}/archive
223
+ */
224
+ export function archivePlan(
225
+ client: Client,
226
+ req: ArchivePlanRequest,
227
+ options?: RequestOptions,
228
+ ): Promise<Result<ArchivePlanResponse>> {
229
+ return request(() => {
230
+ const pathParamsInput = {
231
+ planId: req.planId,
232
+ }
233
+ const pathParams = client._options.validate
234
+ ? toPathWire(pathParamsInput, schemas.archivePlanPathParams)
235
+ : pathParamsInput
236
+ if (client._options.validate) {
237
+ assertValid(schemas.archivePlanPathParamsWire, pathParams)
238
+ }
239
+ const path = `openmeter/plans/${(() => {
240
+ if (pathParams.planId === undefined) {
241
+ throw new Error('missing path parameter: planId')
242
+ }
243
+ return encodeURIComponent(String(pathParams.planId))
244
+ })()}/archive`
245
+ return http(client)
246
+ .post(path, options)
247
+ .json()
248
+ .then((data) => {
249
+ if (client._options.validate) {
250
+ assertValid(schemas.archivePlanResponseWire, data)
251
+ }
252
+ return fromWire(data, schemas.archivePlanResponse)
253
+ })
254
+ })
255
+ }
256
+
257
+ /**
258
+ * Publish plan version
259
+ *
260
+ * Publish a plan version.
261
+ *
262
+ * POST /openmeter/plans/{planId}/publish
263
+ */
264
+ export function publishPlan(
265
+ client: Client,
266
+ req: PublishPlanRequest,
267
+ options?: RequestOptions,
268
+ ): Promise<Result<PublishPlanResponse>> {
269
+ return request(() => {
270
+ const pathParamsInput = {
271
+ planId: req.planId,
272
+ }
273
+ const pathParams = client._options.validate
274
+ ? toPathWire(pathParamsInput, schemas.publishPlanPathParams)
275
+ : pathParamsInput
276
+ if (client._options.validate) {
277
+ assertValid(schemas.publishPlanPathParamsWire, pathParams)
278
+ }
279
+ const path = `openmeter/plans/${(() => {
280
+ if (pathParams.planId === undefined) {
281
+ throw new Error('missing path parameter: planId')
282
+ }
283
+ return encodeURIComponent(String(pathParams.planId))
284
+ })()}/publish`
285
+ return http(client)
286
+ .post(path, options)
287
+ .json()
288
+ .then((data) => {
289
+ if (client._options.validate) {
290
+ assertValid(schemas.publishPlanResponseWire, data)
291
+ }
292
+ return fromWire(data, schemas.publishPlanResponse)
293
+ })
294
+ })
295
+ }
api/spec/packages/aip-client-javascript/src/funcs/subscriptions.ts ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams, encodeSort } from '../lib/encodings.js'
7
+ import {
8
+ toWire,
9
+ toPathWire,
10
+ fromWire,
11
+ assertValid,
12
+ toSnakeCase,
13
+ } from '../lib/wire.js'
14
+ import * as schemas from '../models/schemas.js'
15
+ import type {
16
+ CreateSubscriptionRequest,
17
+ CreateSubscriptionResponse,
18
+ ListSubscriptionsRequest,
19
+ ListSubscriptionsResponse,
20
+ GetSubscriptionRequest,
21
+ GetSubscriptionResponse,
22
+ CancelSubscriptionRequest,
23
+ CancelSubscriptionResponse,
24
+ UnscheduleCancelationRequest,
25
+ UnscheduleCancelationResponse,
26
+ ChangeSubscriptionRequest,
27
+ ChangeSubscriptionResponse,
28
+ CreateSubscriptionAddonRequest,
29
+ CreateSubscriptionAddonResponse,
30
+ ListSubscriptionAddonsRequest,
31
+ ListSubscriptionAddonsResponse,
32
+ GetSubscriptionAddonRequest,
33
+ GetSubscriptionAddonResponse,
34
+ } from '../models/operations/subscriptions.js'
35
+
36
+ /**
37
+ * Create subscription
38
+ *
39
+ * POST /openmeter/subscriptions
40
+ */
41
+ export function createSubscription(
42
+ client: Client,
43
+ req: CreateSubscriptionRequest,
44
+ options?: RequestOptions,
45
+ ): Promise<Result<CreateSubscriptionResponse>> {
46
+ return request(() => {
47
+ const body = toWire(req, schemas.createSubscriptionBody)
48
+ if (client._options.validate) {
49
+ assertValid(schemas.createSubscriptionBodyWire, body)
50
+ }
51
+ return http(client)
52
+ .post('openmeter/subscriptions', { ...options, json: body })
53
+ .json()
54
+ .then((data) => {
55
+ if (client._options.validate) {
56
+ assertValid(schemas.createSubscriptionResponseWire, data)
57
+ }
58
+ return fromWire(data, schemas.createSubscriptionResponse)
59
+ })
60
+ })
61
+ }
62
+
63
+ /**
64
+ * List subscriptions
65
+ *
66
+ * GET /openmeter/subscriptions
67
+ */
68
+ export function listSubscriptions(
69
+ client: Client,
70
+ req: ListSubscriptionsRequest = {},
71
+ options?: RequestOptions,
72
+ ): Promise<Result<ListSubscriptionsResponse>> {
73
+ return request(() => {
74
+ if (client._options.validate && req.sort !== undefined) {
75
+ assertValid(schemas.listSubscriptionsQueryParams.shape.sort, req.sort)
76
+ }
77
+ const query = toWire(
78
+ {
79
+ page: req.page,
80
+ sort: encodeSort(req.sort, toSnakeCase),
81
+ filter: req.filter,
82
+ },
83
+ schemas.listSubscriptionsQueryParams,
84
+ )
85
+ if (client._options.validate) {
86
+ assertValid(schemas.listSubscriptionsQueryParamsWire, query)
87
+ }
88
+ const searchParams = toURLSearchParams(query)
89
+ return http(client)
90
+ .get('openmeter/subscriptions', { ...options, searchParams })
91
+ .json()
92
+ .then((data) => {
93
+ if (client._options.validate) {
94
+ assertValid(schemas.listSubscriptionsResponseWire, data)
95
+ }
96
+ return fromWire(data, schemas.listSubscriptionsResponse)
97
+ })
98
+ })
99
+ }
100
+
101
+ /**
102
+ * Get subscription
103
+ *
104
+ * GET /openmeter/subscriptions/{subscriptionId}
105
+ */
106
+ export function getSubscription(
107
+ client: Client,
108
+ req: GetSubscriptionRequest,
109
+ options?: RequestOptions,
110
+ ): Promise<Result<GetSubscriptionResponse>> {
111
+ return request(() => {
112
+ const pathParamsInput = {
113
+ subscriptionId: req.subscriptionId,
114
+ }
115
+ const pathParams = client._options.validate
116
+ ? toPathWire(pathParamsInput, schemas.getSubscriptionPathParams)
117
+ : pathParamsInput
118
+ if (client._options.validate) {
119
+ assertValid(schemas.getSubscriptionPathParamsWire, pathParams)
120
+ }
121
+ const path = `openmeter/subscriptions/${(() => {
122
+ if (pathParams.subscriptionId === undefined) {
123
+ throw new Error('missing path parameter: subscriptionId')
124
+ }
125
+ return encodeURIComponent(String(pathParams.subscriptionId))
126
+ })()}`
127
+ return http(client)
128
+ .get(path, options)
129
+ .json()
130
+ .then((data) => {
131
+ if (client._options.validate) {
132
+ assertValid(schemas.getSubscriptionResponseWire, data)
133
+ }
134
+ return fromWire(data, schemas.getSubscriptionResponse)
135
+ })
136
+ })
137
+ }
138
+
139
+ /**
140
+ * Cancel subscription
141
+ *
142
+ * Cancels the subscription. Will result in a scheduling conflict if there are
143
+ * other subscriptions scheduled to start after the cancelation time.
144
+ *
145
+ * POST /openmeter/subscriptions/{subscriptionId}/cancel
146
+ */
147
+ export function cancelSubscription(
148
+ client: Client,
149
+ req: CancelSubscriptionRequest,
150
+ options?: RequestOptions,
151
+ ): Promise<Result<CancelSubscriptionResponse>> {
152
+ return request(() => {
153
+ const pathParamsInput = {
154
+ subscriptionId: req.subscriptionId,
155
+ }
156
+ const pathParams = client._options.validate
157
+ ? toPathWire(pathParamsInput, schemas.cancelSubscriptionPathParams)
158
+ : pathParamsInput
159
+ if (client._options.validate) {
160
+ assertValid(schemas.cancelSubscriptionPathParamsWire, pathParams)
161
+ }
162
+ const path = `openmeter/subscriptions/${(() => {
163
+ if (pathParams.subscriptionId === undefined) {
164
+ throw new Error('missing path parameter: subscriptionId')
165
+ }
166
+ return encodeURIComponent(String(pathParams.subscriptionId))
167
+ })()}/cancel`
168
+ const body = toWire(req.body, schemas.cancelSubscriptionBody)
169
+ if (client._options.validate) {
170
+ assertValid(schemas.cancelSubscriptionBodyWire, body)
171
+ }
172
+ return http(client)
173
+ .post(path, { ...options, json: body })
174
+ .json()
175
+ .then((data) => {
176
+ if (client._options.validate) {
177
+ assertValid(schemas.cancelSubscriptionResponseWire, data)
178
+ }
179
+ return fromWire(data, schemas.cancelSubscriptionResponse)
180
+ })
181
+ })
182
+ }
183
+
184
+ /**
185
+ * Unschedule subscription cancelation
186
+ *
187
+ * Unschedules the subscription cancelation.
188
+ *
189
+ * POST /openmeter/subscriptions/{subscriptionId}/unschedule-cancelation
190
+ */
191
+ export function unscheduleCancelation(
192
+ client: Client,
193
+ req: UnscheduleCancelationRequest,
194
+ options?: RequestOptions,
195
+ ): Promise<Result<UnscheduleCancelationResponse>> {
196
+ return request(() => {
197
+ const pathParamsInput = {
198
+ subscriptionId: req.subscriptionId,
199
+ }
200
+ const pathParams = client._options.validate
201
+ ? toPathWire(pathParamsInput, schemas.unscheduleCancelationPathParams)
202
+ : pathParamsInput
203
+ if (client._options.validate) {
204
+ assertValid(schemas.unscheduleCancelationPathParamsWire, pathParams)
205
+ }
206
+ const path = `openmeter/subscriptions/${(() => {
207
+ if (pathParams.subscriptionId === undefined) {
208
+ throw new Error('missing path parameter: subscriptionId')
209
+ }
210
+ return encodeURIComponent(String(pathParams.subscriptionId))
211
+ })()}/unschedule-cancelation`
212
+ return http(client)
213
+ .post(path, options)
214
+ .json()
215
+ .then((data) => {
216
+ if (client._options.validate) {
217
+ assertValid(schemas.unscheduleCancelationResponseWire, data)
218
+ }
219
+ return fromWire(data, schemas.unscheduleCancelationResponse)
220
+ })
221
+ })
222
+ }
223
+
224
+ /**
225
+ * Change subscription
226
+ *
227
+ * Closes a running subscription and starts a new one according to the
228
+ * specification. Can be used for upgrades, downgrades, and plan changes.
229
+ *
230
+ * POST /openmeter/subscriptions/{subscriptionId}/change
231
+ */
232
+ export function changeSubscription(
233
+ client: Client,
234
+ req: ChangeSubscriptionRequest,
235
+ options?: RequestOptions,
236
+ ): Promise<Result<ChangeSubscriptionResponse>> {
237
+ return request(() => {
238
+ const pathParamsInput = {
239
+ subscriptionId: req.subscriptionId,
240
+ }
241
+ const pathParams = client._options.validate
242
+ ? toPathWire(pathParamsInput, schemas.changeSubscriptionPathParams)
243
+ : pathParamsInput
244
+ if (client._options.validate) {
245
+ assertValid(schemas.changeSubscriptionPathParamsWire, pathParams)
246
+ }
247
+ const path = `openmeter/subscriptions/${(() => {
248
+ if (pathParams.subscriptionId === undefined) {
249
+ throw new Error('missing path parameter: subscriptionId')
250
+ }
251
+ return encodeURIComponent(String(pathParams.subscriptionId))
252
+ })()}/change`
253
+ const body = toWire(req.body, schemas.changeSubscriptionBody)
254
+ if (client._options.validate) {
255
+ assertValid(schemas.changeSubscriptionBodyWire, body)
256
+ }
257
+ return http(client)
258
+ .post(path, { ...options, json: body })
259
+ .json()
260
+ .then((data) => {
261
+ if (client._options.validate) {
262
+ assertValid(schemas.changeSubscriptionResponseWire, data)
263
+ }
264
+ return fromWire(data, schemas.changeSubscriptionResponse)
265
+ })
266
+ })
267
+ }
268
+
269
+ /**
270
+ * Create a new subscription add-on
271
+ *
272
+ * Add add-on to a subscription.
273
+ *
274
+ * POST /openmeter/subscriptions/{subscriptionId}/addons
275
+ */
276
+ export function createSubscriptionAddon(
277
+ client: Client,
278
+ req: CreateSubscriptionAddonRequest,
279
+ options?: RequestOptions,
280
+ ): Promise<Result<CreateSubscriptionAddonResponse>> {
281
+ return request(() => {
282
+ const pathParamsInput = {
283
+ subscriptionId: req.subscriptionId,
284
+ }
285
+ const pathParams = client._options.validate
286
+ ? toPathWire(pathParamsInput, schemas.createSubscriptionAddonPathParams)
287
+ : pathParamsInput
288
+ if (client._options.validate) {
289
+ assertValid(schemas.createSubscriptionAddonPathParamsWire, pathParams)
290
+ }
291
+ const path = `openmeter/subscriptions/${(() => {
292
+ if (pathParams.subscriptionId === undefined) {
293
+ throw new Error('missing path parameter: subscriptionId')
294
+ }
295
+ return encodeURIComponent(String(pathParams.subscriptionId))
296
+ })()}/addons`
297
+ const body = toWire(req.body, schemas.createSubscriptionAddonBody)
298
+ if (client._options.validate) {
299
+ assertValid(schemas.createSubscriptionAddonBodyWire, body)
300
+ }
301
+ return http(client)
302
+ .post(path, { ...options, json: body })
303
+ .json()
304
+ .then((data) => {
305
+ if (client._options.validate) {
306
+ assertValid(schemas.createSubscriptionAddonResponseWire, data)
307
+ }
308
+ return fromWire(data, schemas.createSubscriptionAddonResponse)
309
+ })
310
+ })
311
+ }
312
+
313
+ /**
314
+ * List subscription addons
315
+ *
316
+ * List the add-ons of a subscription.
317
+ *
318
+ * GET /openmeter/subscriptions/{subscriptionId}/addons
319
+ */
320
+ export function listSubscriptionAddons(
321
+ client: Client,
322
+ req: ListSubscriptionAddonsRequest,
323
+ options?: RequestOptions,
324
+ ): Promise<Result<ListSubscriptionAddonsResponse>> {
325
+ return request(() => {
326
+ const pathParamsInput = {
327
+ subscriptionId: req.subscriptionId,
328
+ }
329
+ const pathParams = client._options.validate
330
+ ? toPathWire(pathParamsInput, schemas.listSubscriptionAddonsPathParams)
331
+ : pathParamsInput
332
+ if (client._options.validate) {
333
+ assertValid(schemas.listSubscriptionAddonsPathParamsWire, pathParams)
334
+ }
335
+ const path = `openmeter/subscriptions/${(() => {
336
+ if (pathParams.subscriptionId === undefined) {
337
+ throw new Error('missing path parameter: subscriptionId')
338
+ }
339
+ return encodeURIComponent(String(pathParams.subscriptionId))
340
+ })()}/addons`
341
+ if (client._options.validate && req.sort !== undefined) {
342
+ assertValid(
343
+ schemas.listSubscriptionAddonsQueryParams.shape.sort,
344
+ req.sort,
345
+ )
346
+ }
347
+ const query = toWire(
348
+ {
349
+ page: req.page,
350
+ sort: encodeSort(req.sort, toSnakeCase),
351
+ },
352
+ schemas.listSubscriptionAddonsQueryParams,
353
+ )
354
+ if (client._options.validate) {
355
+ assertValid(schemas.listSubscriptionAddonsQueryParamsWire, query)
356
+ }
357
+ const searchParams = toURLSearchParams(query)
358
+ return http(client)
359
+ .get(path, { ...options, searchParams })
360
+ .json()
361
+ .then((data) => {
362
+ if (client._options.validate) {
363
+ assertValid(schemas.listSubscriptionAddonsResponseWire, data)
364
+ }
365
+ return fromWire(data, schemas.listSubscriptionAddonsResponse)
366
+ })
367
+ })
368
+ }
369
+
370
+ /**
371
+ * Get add-on association for subscription
372
+ *
373
+ * Get an add-on association for a subscription.
374
+ *
375
+ * GET /openmeter/subscriptions/{subscriptionId}/addons/{subscriptionAddonId}
376
+ */
377
+ export function getSubscriptionAddon(
378
+ client: Client,
379
+ req: GetSubscriptionAddonRequest,
380
+ options?: RequestOptions,
381
+ ): Promise<Result<GetSubscriptionAddonResponse>> {
382
+ return request(() => {
383
+ const pathParamsInput = {
384
+ subscriptionId: req.subscriptionId,
385
+ subscriptionAddonId: req.subscriptionAddonId,
386
+ }
387
+ const pathParams = client._options.validate
388
+ ? toPathWire(pathParamsInput, schemas.getSubscriptionAddonPathParams)
389
+ : pathParamsInput
390
+ if (client._options.validate) {
391
+ assertValid(schemas.getSubscriptionAddonPathParamsWire, pathParams)
392
+ }
393
+ const path = `openmeter/subscriptions/${(() => {
394
+ if (pathParams.subscriptionId === undefined) {
395
+ throw new Error('missing path parameter: subscriptionId')
396
+ }
397
+ return encodeURIComponent(String(pathParams.subscriptionId))
398
+ })()}/addons/${(() => {
399
+ if (pathParams.subscriptionAddonId === undefined) {
400
+ throw new Error('missing path parameter: subscriptionAddonId')
401
+ }
402
+ return encodeURIComponent(String(pathParams.subscriptionAddonId))
403
+ })()}`
404
+ return http(client)
405
+ .get(path, options)
406
+ .json()
407
+ .then((data) => {
408
+ if (client._options.validate) {
409
+ assertValid(schemas.getSubscriptionAddonResponseWire, data)
410
+ }
411
+ return fromWire(data, schemas.getSubscriptionAddonResponse)
412
+ })
413
+ })
414
+ }
api/spec/packages/aip-client-javascript/src/funcs/tax.ts ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Client, http } from '../core.js'
4
+ import { type Result, type RequestOptions } from '../lib/types.js'
5
+ import { request } from '../lib/request.js'
6
+ import { toURLSearchParams } from '../lib/encodings.js'
7
+ import { toWire, toPathWire, fromWire, assertValid } from '../lib/wire.js'
8
+ import * as schemas from '../models/schemas.js'
9
+ import type {
10
+ CreateTaxCodeRequest,
11
+ CreateTaxCodeResponse,
12
+ GetTaxCodeRequest,
13
+ GetTaxCodeResponse,
14
+ ListTaxCodesRequest,
15
+ ListTaxCodesResponse,
16
+ UpsertTaxCodeRequest,
17
+ UpsertTaxCodeResponse,
18
+ DeleteTaxCodeRequest,
19
+ DeleteTaxCodeResponse,
20
+ } from '../models/operations/tax.js'
21
+
22
+ /**
23
+ * Create tax code
24
+ *
25
+ * POST /openmeter/tax-codes
26
+ */
27
+ export function createTaxCode(
28
+ client: Client,
29
+ req: CreateTaxCodeRequest,
30
+ options?: RequestOptions,
31
+ ): Promise<Result<CreateTaxCodeResponse>> {
32
+ return request(() => {
33
+ const body = toWire(req, schemas.createTaxCodeBody)
34
+ if (client._options.validate) {
35
+ assertValid(schemas.createTaxCodeBodyWire, body)
36
+ }
37
+ return http(client)
38
+ .post('openmeter/tax-codes', { ...options, json: body })
39
+ .json()
40
+ .then((data) => {
41
+ if (client._options.validate) {
42
+ assertValid(schemas.createTaxCodeResponseWire, data)
43
+ }
44
+ return fromWire(data, schemas.createTaxCodeResponse)
45
+ })
46
+ })
47
+ }
48
+
49
+ /**
50
+ * Get tax code
51
+ *
52
+ * GET /openmeter/tax-codes/{taxCodeId}
53
+ */
54
+ export function getTaxCode(
55
+ client: Client,
56
+ req: GetTaxCodeRequest,
57
+ options?: RequestOptions,
58
+ ): Promise<Result<GetTaxCodeResponse>> {
59
+ return request(() => {
60
+ const pathParamsInput = {
61
+ taxCodeId: req.taxCodeId,
62
+ }
63
+ const pathParams = client._options.validate
64
+ ? toPathWire(pathParamsInput, schemas.getTaxCodePathParams)
65
+ : pathParamsInput
66
+ if (client._options.validate) {
67
+ assertValid(schemas.getTaxCodePathParamsWire, pathParams)
68
+ }
69
+ const path = `openmeter/tax-codes/${(() => {
70
+ if (pathParams.taxCodeId === undefined) {
71
+ throw new Error('missing path parameter: taxCodeId')
72
+ }
73
+ return encodeURIComponent(String(pathParams.taxCodeId))
74
+ })()}`
75
+ return http(client)
76
+ .get(path, options)
77
+ .json()
78
+ .then((data) => {
79
+ if (client._options.validate) {
80
+ assertValid(schemas.getTaxCodeResponseWire, data)
81
+ }
82
+ return fromWire(data, schemas.getTaxCodeResponse)
83
+ })
84
+ })
85
+ }
86
+
87
+ /**
88
+ * List tax codes
89
+ *
90
+ * GET /openmeter/tax-codes
91
+ */
92
+ export function listTaxCodes(
93
+ client: Client,
94
+ req: ListTaxCodesRequest = {},
95
+ options?: RequestOptions,
96
+ ): Promise<Result<ListTaxCodesResponse>> {
97
+ return request(() => {
98
+ const query = toWire(
99
+ {
100
+ page: req.page,
101
+ includeDeleted: req.includeDeleted,
102
+ },
103
+ schemas.listTaxCodesQueryParams,
104
+ )
105
+ if (client._options.validate) {
106
+ assertValid(schemas.listTaxCodesQueryParamsWire, query)
107
+ }
108
+ const searchParams = toURLSearchParams(query)
109
+ return http(client)
110
+ .get('openmeter/tax-codes', { ...options, searchParams })
111
+ .json()
112
+ .then((data) => {
113
+ if (client._options.validate) {
114
+ assertValid(schemas.listTaxCodesResponseWire, data)
115
+ }
116
+ return fromWire(data, schemas.listTaxCodesResponse)
117
+ })
118
+ })
119
+ }
120
+
121
+ /**
122
+ * Upsert tax code
123
+ *
124
+ * PUT /openmeter/tax-codes/{taxCodeId}
125
+ */
126
+ export function upsertTaxCode(
127
+ client: Client,
128
+ req: UpsertTaxCodeRequest,
129
+ options?: RequestOptions,
130
+ ): Promise<Result<UpsertTaxCodeResponse>> {
131
+ return request(() => {
132
+ const pathParamsInput = {
133
+ taxCodeId: req.taxCodeId,
134
+ }
135
+ const pathParams = client._options.validate
136
+ ? toPathWire(pathParamsInput, schemas.upsertTaxCodePathParams)
137
+ : pathParamsInput
138
+ if (client._options.validate) {
139
+ assertValid(schemas.upsertTaxCodePathParamsWire, pathParams)
140
+ }
141
+ const path = `openmeter/tax-codes/${(() => {
142
+ if (pathParams.taxCodeId === undefined) {
143
+ throw new Error('missing path parameter: taxCodeId')
144
+ }
145
+ return encodeURIComponent(String(pathParams.taxCodeId))
146
+ })()}`
147
+ const body = toWire(req.body, schemas.upsertTaxCodeBody)
148
+ if (client._options.validate) {
149
+ assertValid(schemas.upsertTaxCodeBodyWire, body)
150
+ }
151
+ return http(client)
152
+ .put(path, { ...options, json: body })
153
+ .json()
154
+ .then((data) => {
155
+ if (client._options.validate) {
156
+ assertValid(schemas.upsertTaxCodeResponseWire, data)
157
+ }
158
+ return fromWire(data, schemas.upsertTaxCodeResponse)
159
+ })
160
+ })
161
+ }
162
+
163
+ /**
164
+ * Delete tax code
165
+ *
166
+ * DELETE /openmeter/tax-codes/{taxCodeId}
167
+ */
168
+ export function deleteTaxCode(
169
+ client: Client,
170
+ req: DeleteTaxCodeRequest,
171
+ options?: RequestOptions,
172
+ ): Promise<Result<DeleteTaxCodeResponse>> {
173
+ return request(async () => {
174
+ const pathParamsInput = {
175
+ taxCodeId: req.taxCodeId,
176
+ }
177
+ const pathParams = client._options.validate
178
+ ? toPathWire(pathParamsInput, schemas.deleteTaxCodePathParams)
179
+ : pathParamsInput
180
+ if (client._options.validate) {
181
+ assertValid(schemas.deleteTaxCodePathParamsWire, pathParams)
182
+ }
183
+ const path = `openmeter/tax-codes/${(() => {
184
+ if (pathParams.taxCodeId === undefined) {
185
+ throw new Error('missing path parameter: taxCodeId')
186
+ }
187
+ return encodeURIComponent(String(pathParams.taxCodeId))
188
+ })()}`
189
+ await http(client).delete(path, options)
190
+ })
191
+ }
api/spec/packages/aip-client-javascript/src/index.ts ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ export { OpenMeter } from './sdk/sdk.js'
4
+ export { Events } from './sdk/events.js'
5
+ export { Meters } from './sdk/meters.js'
6
+ export { Customers } from './sdk/customers.js'
7
+ export { Entitlements } from './sdk/entitlements.js'
8
+ export { Subscriptions } from './sdk/subscriptions.js'
9
+ export { Apps } from './sdk/apps.js'
10
+ export { Billing } from './sdk/billing.js'
11
+ export { Tax } from './sdk/tax.js'
12
+ export { Features } from './sdk/features.js'
13
+ export { LLMCost } from './sdk/llmCost.js'
14
+ export { Plans } from './sdk/plans.js'
15
+ export { Addons } from './sdk/addons.js'
16
+ export { PlanAddons } from './sdk/planAddons.js'
17
+ export { Defaults } from './sdk/defaults.js'
18
+ export { Client } from './core.js'
19
+ export { HTTPError } from './models/errors.js'
20
+ export {
21
+ ValidationError,
22
+ DepthLimitExceededError,
23
+ UnsafeIntegerError,
24
+ } from './lib/wire.js'
25
+ export type { AcceptDateStrings, DateString } from './lib/wire.js'
26
+ export { PaginationLimitExceededError } from './lib/paginate.js'
27
+
28
+ export { ServerList, Regions } from './lib/config.js'
29
+ export type { SDKOptions, Region, ServerVariables } from './lib/config.js'
30
+ export { unwrap, ok, err } from './lib/types.js'
31
+ export type { Result, RequestOptions } from './lib/types.js'
32
+
33
+ export {
34
+ encodePath,
35
+ encodeSort,
36
+ querySerializer,
37
+ toURLSearchParams,
38
+ } from './lib/encodings.js'
39
+
40
+ export * as funcs from './funcs/index.js'
41
+
42
+ export type * from './models/operations/events.js'
43
+ export type * from './models/operations/meters.js'
44
+ export type * from './models/operations/customers.js'
45
+ export type * from './models/operations/entitlements.js'
46
+ export type * from './models/operations/subscriptions.js'
47
+ export type * from './models/operations/apps.js'
48
+ export type * from './models/operations/billing.js'
49
+ export type * from './models/operations/invoices.js'
50
+ export type * from './models/operations/tax.js'
51
+ export type * from './models/operations/currencies.js'
52
+ export type * from './models/operations/features.js'
53
+ export type * from './models/operations/llmCost.js'
54
+ export type * from './models/operations/plans.js'
55
+ export type * from './models/operations/addons.js'
56
+ export type * from './models/operations/planAddons.js'
57
+ export type * from './models/operations/defaults.js'
58
+ export type * from './models/operations/governance.js'
59
+
60
+ export type {
61
+ Labels,
62
+ CursorPaginationQueryPage,
63
+ SortQuery,
64
+ IngestedEventValidationError,
65
+ CursorMetaPage,
66
+ BaseError,
67
+ PageMeta,
68
+ QueryFilterString,
69
+ AppStripeCheckoutSessionCustomTextParams,
70
+ AppStripeCreateCustomerPortalSessionOptions,
71
+ CreateLabels,
72
+ TaxConfigStripe,
73
+ TaxConfigExternalInvoicing,
74
+ ChargeFlatFeeDiscounts,
75
+ PriceFree,
76
+ RateCardStaticEntitlement,
77
+ RateCardBooleanEntitlement,
78
+ InstallAppStripeWithApiKey,
79
+ InstallAppSandbox,
80
+ InstallAppExternalInvoicing,
81
+ WorkflowCollectionAlignmentSubscription,
82
+ WorkflowPaymentChargeAutomaticallySettings,
83
+ WorkflowPaymentSendInvoiceSettings,
84
+ InvoiceExternalReferences,
85
+ InvoiceAvailableActionDetails,
86
+ InvoiceWorkflowInvoicingSettings,
87
+ InvoiceLineExternalReferences,
88
+ UpdateLabels,
89
+ UpdateBillingInvoiceWorkflowInvoicingSettings,
90
+ UpdateBillingWorkflowPaymentChargeAutomaticallySettings,
91
+ UpdateBillingWorkflowPaymentSendInvoiceSettings,
92
+ UpdatePriceFree,
93
+ LlmCostProvider,
94
+ LlmCostModel,
95
+ ProductCatalogValidationError,
96
+ GovernanceQueryRequestCustomers,
97
+ GovernanceQueryRequestFeatures,
98
+ QueryFilterInteger,
99
+ QueryFilterFloat,
100
+ QueryFilterBoolean,
101
+ PagePaginationQuery,
102
+ PublicLabels,
103
+ SystemAccountAccessToken,
104
+ PersonalAccessToken,
105
+ KonnectAccessToken,
106
+ AppCustomerDataStripe,
107
+ AppCustomerDataExternalInvoicing,
108
+ CurrencyFiat,
109
+ ListCostBasesParamsFilter,
110
+ CurrencyAmount,
111
+ PriceFlat,
112
+ PriceUnit,
113
+ RateCardDiscounts,
114
+ Totals,
115
+ SpendCommitments,
116
+ InvoiceLineCreditsApplied,
117
+ UpdatePriceFlat,
118
+ UpdatePriceUnit,
119
+ UpdateDiscounts,
120
+ FeatureManualUnitCost,
121
+ FeatureLlmUnitCostPricing,
122
+ LlmCostModelPricing,
123
+ QueryFilterNumeric,
124
+ CursorPaginationQuery,
125
+ ListMetersParamsFilter,
126
+ ListLlmCostPricesParamsFilter,
127
+ LabelsFieldFilter,
128
+ CustomerReference,
129
+ ProfileReference,
130
+ CreateResourceReference,
131
+ TaxCodeReference,
132
+ CreditGrantInvoiceReference,
133
+ BillingCustomerReference,
134
+ SubscriptionReference,
135
+ AddonReference,
136
+ FeatureReference,
137
+ AppReference,
138
+ ChargeReference,
139
+ UpdateResourceReference,
140
+ Event,
141
+ MeterQueryRow,
142
+ AppStripeCreateCustomerPortalSessionResult,
143
+ ClosedPeriod,
144
+ SubscriptionAddonTimelineSegment,
145
+ UpdateClosedPeriod,
146
+ CostBasis,
147
+ FeatureCostQueryRow,
148
+ Resource,
149
+ ResourceImmutable,
150
+ QueryFilterDateTime,
151
+ CursorMeta,
152
+ InvalidParameterStandard,
153
+ InvalidParameterMinimumLength,
154
+ InvalidParameterMaximumLength,
155
+ InvalidParameterChoiceItem,
156
+ InvalidParameterDependentItem,
157
+ Unauthorized,
158
+ Forbidden,
159
+ NotFound,
160
+ Gone,
161
+ Conflict,
162
+ PayloadTooLarge,
163
+ UnsupportedMediaType,
164
+ UnprocessableContent,
165
+ TooManyRequests,
166
+ Internal,
167
+ NotImplemented,
168
+ NotAvailable,
169
+ CreateCreditGrantFilters,
170
+ CreditGrantFilters,
171
+ UpsertPlanAddonRequest,
172
+ ResourceWithKey,
173
+ Meter,
174
+ PaginatedMeta,
175
+ QueryFilterStringMapItem,
176
+ CustomerKeyReference,
177
+ CustomerUsageAttribution,
178
+ UpdateCustomerUsageAttribution,
179
+ Address,
180
+ UpdateAddress,
181
+ AppStripeCreateCheckoutSessionCustomerUpdate,
182
+ AppStripeCreateCheckoutSessionConsentCollectionPaymentMethodReuseAgreement,
183
+ AppStripeCreateCheckoutSessionTaxIdCollection,
184
+ AppStripeCreateCheckoutSessionResult,
185
+ CustomerStripeCreateCustomerPortalSessionRequest,
186
+ EntitlementAccessResult,
187
+ CreateCreditGrantPurchase,
188
+ RateCardMeteredEntitlement,
189
+ RecurringPeriod,
190
+ CreditGrantPurchase,
191
+ ListCreditGrantsParamsFilter,
192
+ GetCreditBalanceParamsFilter,
193
+ ListChargesParamsFilter,
194
+ ListPlansParamsFilter,
195
+ SubscriptionCreate,
196
+ RateCardProrationConfiguration,
197
+ Subscription,
198
+ UnitConfig,
199
+ TaxCodeAppMapping,
200
+ AppCapability,
201
+ PartyTaxIdentity,
202
+ UpdateBillingPartyTaxIdentity,
203
+ WorkflowInvoicingSettings,
204
+ InvoiceValidationIssue,
205
+ InvoiceAvailableActions,
206
+ InvoiceLineAmountDiscount,
207
+ InvoiceLineUsageDiscount,
208
+ InvoiceLineBaseDiscount,
209
+ ListCurrenciesParamsFilter,
210
+ CurrencyCustom,
211
+ CreateCurrencyCustomRequest,
212
+ GovernanceQueryRequest,
213
+ GovernanceFeatureAccessReason,
214
+ GovernanceQueryError,
215
+ AppCustomerData,
216
+ UpsertAppCustomerDataRequest,
217
+ CreditAdjustment,
218
+ CreditBalance,
219
+ ListCreditTransactionsParamsFilter,
220
+ CreditTransaction,
221
+ PriceTier,
222
+ ChargeTotals,
223
+ UpdatePriceTier,
224
+ FeatureLlmUnitCost,
225
+ LlmCostPrice,
226
+ LlmCostOverrideCreate,
227
+ ListCustomersParamsFilter,
228
+ ListSubscriptionsParamsFilter,
229
+ ListFeatureParamsFilter,
230
+ ListAddonsParamsFilter,
231
+ CreateCreditGrantTaxConfig,
232
+ CreditGrantTaxConfig,
233
+ TaxConfig,
234
+ RateCardTaxConfig,
235
+ OrganizationDefaultTaxCodes,
236
+ PlanAddon,
237
+ ProfileAppReferences,
238
+ InvoiceWorkflowAppsReferences,
239
+ UpdateRateCardTaxConfig,
240
+ ListEventsParamsFilter,
241
+ ListInvoicesParamsFilter,
242
+ ResourceFilters,
243
+ FieldFilters,
244
+ IngestedEvent,
245
+ MeterQueryResult,
246
+ FeatureCostQueryResult,
247
+ MeterPagePaginatedResponse,
248
+ CostBasisPagePaginatedResponse,
249
+ MeterQueryFilters,
250
+ FeatureMeterReference,
251
+ Customer,
252
+ PartyAddresses,
253
+ InvoiceCustomer,
254
+ UpdateBillingPartyAddresses,
255
+ UpdateInvoiceCustomer,
256
+ AppStripeCreateCheckoutSessionConsentCollection,
257
+ ListCustomerEntitlementAccessResponseData,
258
+ WorkflowCollectionAlignmentAnchored,
259
+ ChargeFlatFeeSystemIntent,
260
+ SubscriptionPagePaginatedResponse,
261
+ SubscriptionChangeResponse,
262
+ SubscriptionCancel,
263
+ SubscriptionChange,
264
+ InvoiceUsageQuantityDetail,
265
+ TaxCode,
266
+ AppCatalogItem,
267
+ InvoiceWorkflow,
268
+ InvoiceStatusDetails,
269
+ InvoiceLineDiscounts,
270
+ UpdateBillingInvoiceWorkflow,
271
+ GovernanceFeatureAccess,
272
+ CustomerData,
273
+ UpsertCustomerBillingDataRequest,
274
+ CreditBalances,
275
+ CreditTransactionPaginatedResponse,
276
+ PriceGraduated,
277
+ PriceVolume,
278
+ UpdatePriceGraduated,
279
+ UpdatePriceVolume,
280
+ PricePagePaginatedResponse,
281
+ CreditGrant,
282
+ CreateChargeFlatFeeRequest,
283
+ WorkflowTaxSettings,
284
+ PlanAddonPagePaginatedResponse,
285
+ IngestedEventPaginatedResponse,
286
+ InvalidParameters,
287
+ MeterQueryRequest,
288
+ CustomerPagePaginatedResponse,
289
+ Party,
290
+ Supplier,
291
+ UpdateSupplier,
292
+ AppStripeCreateCheckoutSessionRequestOptions,
293
+ TaxCodePagePaginatedResponse,
294
+ AppStripe,
295
+ AppSandbox,
296
+ AppExternalInvoicing,
297
+ AppCatalogItemPagePaginatedResponse,
298
+ InvoiceWorkflowSettings,
299
+ InvoiceDetailedLine,
300
+ UpdateInvoiceWorkflowSettings,
301
+ CurrencyPagePaginatedResponse,
302
+ GovernanceQueryResult,
303
+ Feature,
304
+ CreditGrantPagePaginatedResponse,
305
+ BadRequest,
306
+ InvoiceBase,
307
+ CustomerStripeCreateCheckoutSessionRequest,
308
+ WorkflowCollectionSettings,
309
+ GovernanceQueryResponse,
310
+ ChargeFlatFee,
311
+ ChargeUsageBasedSystemIntent,
312
+ CreateChargeUsageBasedRequest,
313
+ RateCard,
314
+ InvoiceLineRateCard,
315
+ UpdateInvoiceLineRateCard,
316
+ FeaturePagePaginatedResponse,
317
+ Workflow,
318
+ AppPagePaginatedResponse,
319
+ BillingInstallAppResponse,
320
+ ProfileApps,
321
+ ChargeUsageBased,
322
+ SubscriptionAddonRateCard,
323
+ PlanPhase,
324
+ Addon,
325
+ UpsertAddonRequest,
326
+ InvoiceStandardLine,
327
+ UpdateInvoiceStandardLine,
328
+ Profile,
329
+ UpsertBillingProfileRequest,
330
+ SubscriptionAddon,
331
+ Plan,
332
+ UpsertPlanRequest,
333
+ AddonPagePaginatedResponse,
334
+ ProfilePagePaginatedResponse,
335
+ ChargePagePaginatedResponse,
336
+ SubscriptionAddonPagePaginatedResponse,
337
+ PlanPagePaginatedResponse,
338
+ InvoiceStandard,
339
+ UpdateInvoiceStandardRequest,
340
+ InvoicePagePaginatedResponse,
341
+ StringFieldFilter,
342
+ MeterAggregation,
343
+ MeterQueryGranularity,
344
+ StringFieldFilterExact,
345
+ PricePaymentTerm,
346
+ BillingCurrencyCode,
347
+ CreateCurrencyCode,
348
+ UlidFieldFilter,
349
+ DateTimeFieldFilter,
350
+ SubscriptionEditTiming,
351
+ WorkflowPaymentSettings,
352
+ UpdateBillingWorkflowPaymentSettings,
353
+ InvalidParameter,
354
+ RateCardEntitlement,
355
+ Currency,
356
+ FeatureUnitCost,
357
+ WorkflowCollectionAlignment,
358
+ Price,
359
+ UpdatePrice,
360
+ App,
361
+ CreateChargeRequest,
362
+ Charge,
363
+ InvoiceLine,
364
+ UpdateInvoiceLine,
365
+ Invoice,
366
+ SortQueryInput,
367
+ BaseErrorInput,
368
+ WorkflowPaymentSendInvoiceSettingsInput,
369
+ InvoiceWorkflowInvoicingSettingsInput,
370
+ UpdateBillingInvoiceWorkflowInvoicingSettingsInput,
371
+ UpdateBillingWorkflowPaymentSendInvoiceSettingsInput,
372
+ EventInput,
373
+ UnauthorizedInput,
374
+ ForbiddenInput,
375
+ NotFoundInput,
376
+ GoneInput,
377
+ ConflictInput,
378
+ PayloadTooLargeInput,
379
+ UnsupportedMediaTypeInput,
380
+ UnprocessableContentInput,
381
+ TooManyRequestsInput,
382
+ InternalInput,
383
+ NotImplementedInput,
384
+ NotAvailableInput,
385
+ AppStripeCreateCheckoutSessionCustomerUpdateInput,
386
+ AppStripeCreateCheckoutSessionTaxIdCollectionInput,
387
+ CreateCreditGrantPurchaseInput,
388
+ RateCardMeteredEntitlementInput,
389
+ CreditGrantPurchaseInput,
390
+ VoidCreditGrantRequestInput,
391
+ UnitConfigInput,
392
+ WorkflowInvoicingSettingsInput,
393
+ GovernanceQueryRequestInput,
394
+ IngestedEventInput,
395
+ SubscriptionCancelInput,
396
+ InvoiceUsageQuantityDetailInput,
397
+ InvoiceWorkflowInput,
398
+ UpdateBillingInvoiceWorkflowInput,
399
+ CreateCreditGrantRequestInput,
400
+ CreditGrantInput,
401
+ WorkflowTaxSettingsInput,
402
+ IngestedEventPaginatedResponseInput,
403
+ MeterQueryRequestInput,
404
+ AppStripeCreateCheckoutSessionRequestOptionsInput,
405
+ InvoiceWorkflowSettingsInput,
406
+ InvoiceDetailedLineInput,
407
+ UpdateInvoiceWorkflowSettingsInput,
408
+ CreditGrantPagePaginatedResponseInput,
409
+ BadRequestInput,
410
+ CustomerStripeCreateCheckoutSessionRequestInput,
411
+ WorkflowCollectionSettingsInput,
412
+ RateCardInput,
413
+ WorkflowInput,
414
+ SubscriptionAddonRateCardInput,
415
+ PlanPhaseInput,
416
+ AddonInput,
417
+ CreateAddonRequestInput,
418
+ UpsertAddonRequestInput,
419
+ InvoiceStandardLineInput,
420
+ ProfileInput,
421
+ CreateBillingProfileRequestInput,
422
+ UpsertBillingProfileRequestInput,
423
+ SubscriptionAddonInput,
424
+ PlanInput,
425
+ CreatePlanRequestInput,
426
+ UpsertPlanRequestInput,
427
+ AddonPagePaginatedResponseInput,
428
+ ProfilePagePaginatedResponseInput,
429
+ SubscriptionAddonPagePaginatedResponseInput,
430
+ PlanPagePaginatedResponseInput,
431
+ InvoiceStandardInput,
432
+ UpdateInvoiceStandardRequestInput,
433
+ InvoicePagePaginatedResponseInput,
434
+ WorkflowPaymentSettingsInput,
435
+ UpdateBillingWorkflowPaymentSettingsInput,
436
+ RateCardEntitlementInput,
437
+ InvoiceLineInput,
438
+ InvoiceInput,
439
+ UpdateInvoiceRequestInput,
440
+ } from './models/types.js'
api/spec/packages/aip-client-javascript/src/lib/config.ts ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Options } from 'ky'
4
+
5
+ export const ServerList = [
6
+ 'https://{region}.api.konghq.com/v3',
7
+ 'http://localhost:{port}/api/v3',
8
+ 'https://openmeter.cloud/api/v3',
9
+ ] as const
10
+
11
+ export const Regions = ['in', 'me', 'au', 'eu', 'us'] as const
12
+
13
+ export type Region = (typeof Regions)[number]
14
+
15
+ export type ServerVariables = {
16
+ region?: Region
17
+ port?: string | number
18
+ }
19
+
20
+ export interface SDKOptions extends Omit<Options, 'method'> {
21
+ baseUrl: (typeof ServerList)[number] | URL | string
22
+ serverVariables?: ServerVariables
23
+ apiKey?: string | (() => string | Promise<string>)
24
+ /**
25
+ * Validate request bodies and response payloads against their schemas. Off by
26
+ * default: the SDK maps casing but does not validate, so additive server fields
27
+ * never break clients. When on, a request body or response that fails its schema
28
+ * (missing/wrong-typed field, unknown enum value) returns a failed Result whose
29
+ * `error` is a ValidationError (validation runs inside the SDK's request
30
+ * handling, so it never rejects/throws).
31
+ */
32
+ validate?: boolean
33
+ }
api/spec/packages/aip-client-javascript/src/lib/encodings.ts ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ export function encodePath(
4
+ template: string,
5
+ params: Record<string, string | number>,
6
+ ): string {
7
+ return template.replace(/\{(\w+)\}/g, (_, key: string) => {
8
+ const value = params[key]
9
+ if (value === undefined) {
10
+ throw new Error(`missing path parameter: ${key}`)
11
+ }
12
+ return encodeURIComponent(String(value))
13
+ })
14
+ }
15
+
16
+ function serializeDeepObject(
17
+ prefix: string,
18
+ value: unknown,
19
+ parts: Array<[string, string]>,
20
+ ): void {
21
+ if (value === null || value === undefined) {
22
+ return
23
+ }
24
+ if (Array.isArray(value)) {
25
+ parts.push([prefix, value.map(String).join(',')])
26
+ } else if (typeof value === 'object') {
27
+ for (const [k, v] of Object.entries(value)) {
28
+ serializeDeepObject(`${prefix}[${k}]`, v, parts)
29
+ }
30
+ } else {
31
+ parts.push([prefix, String(value)])
32
+ }
33
+ }
34
+
35
+ function serializeParams(
36
+ params: Record<string, unknown>,
37
+ ): Array<[string, string]> {
38
+ const parts: Array<[string, string]> = []
39
+ for (const [key, value] of Object.entries(params)) {
40
+ serializeDeepObject(key, value, parts)
41
+ }
42
+ return parts
43
+ }
44
+
45
+ export function querySerializer(params: Record<string, unknown>): string {
46
+ const parts = serializeParams(params).map(
47
+ ([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`,
48
+ )
49
+ return parts.length ? `?${parts.join('&')}` : ''
50
+ }
51
+
52
+ export function toURLSearchParams(
53
+ params: Record<string, unknown>,
54
+ ): URLSearchParams {
55
+ const search = new URLSearchParams()
56
+ for (const [key, value] of serializeParams(params)) {
57
+ search.append(key, value)
58
+ }
59
+ return search
60
+ }
61
+
62
+ export function encodeSort(
63
+ sort: { by?: string; order?: 'asc' | 'desc' } | undefined,
64
+ encodeField: (field: string) => string = (field) => field,
65
+ ): string | undefined {
66
+ if (!sort?.by) {
67
+ return undefined
68
+ }
69
+ const by = encodeField(sort.by)
70
+ if (sort.order === 'desc') {
71
+ return `${by} desc`
72
+ }
73
+ if (sort.order === 'asc') {
74
+ return `${by} asc`
75
+ }
76
+ return by
77
+ }
api/spec/packages/aip-client-javascript/src/lib/paginate.ts ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { unwrap, type RequestOptions, type Result } from './types.js'
4
+
5
+ // A misbehaving server — inconsistent `meta.page.total`/`size`, or a
6
+ // `meta.page.next` cursor that never resolves to an empty page — would
7
+ // otherwise make these generators loop forever. 10,000 pages is far beyond
8
+ // any real OpenMeter list, so hitting it means the server's pagination
9
+ // contract broke, not that the caller has a legitimately large list.
10
+ const MAX_PAGINATION_PAGES = 10_000
11
+
12
+ export class PaginationLimitExceededError extends Error {
13
+ constructor(limit: number) {
14
+ super(
15
+ `pagination exceeded the maximum of ${limit} pages; the server may be returning inconsistent pagination metadata`,
16
+ )
17
+ this.name = 'PaginationLimitExceededError'
18
+ }
19
+ }
20
+
21
+ interface PageNumberEnvelope<TItem> {
22
+ data: TItem[]
23
+ meta: { page: { number: number; size: number; total: number } }
24
+ }
25
+
26
+ interface PageNumberRequest {
27
+ page?: { number?: number; size?: number }
28
+ }
29
+
30
+ /**
31
+ * Iterates every item of a page-number-paginated list operation, advancing
32
+ * `page.number` from wherever the caller's own request starts. Every other
33
+ * field on `request` — filters, sort, page.size — is sent unchanged on every
34
+ * page fetch; only the page number advances. Stops on a page shorter than
35
+ * the server's own reported `size` (including an empty page) or once the
36
+ * running item count reaches the server's reported `total`, whichever comes
37
+ * first — so a final page that exactly fills `total` does not trigger one
38
+ * more, empty request.
39
+ */
40
+ export async function* paginatePages<TItem, TReq extends PageNumberRequest>(
41
+ fetchPage: (
42
+ req: TReq,
43
+ options?: RequestOptions,
44
+ ) => Promise<Result<PageNumberEnvelope<TItem>>>,
45
+ request: TReq,
46
+ options?: RequestOptions,
47
+ ): AsyncGenerator<TItem, void, undefined> {
48
+ let req = request
49
+ let seen = 0
50
+ for (let page = 0; page < MAX_PAGINATION_PAGES; page++) {
51
+ const res = unwrap(await fetchPage(req, options))
52
+ yield* res.data
53
+ seen += res.data.length
54
+ const { number, size, total } = res.meta.page
55
+ if (res.data.length === 0 || res.data.length < size || seen >= total) {
56
+ return
57
+ }
58
+ req = { ...req, page: { ...req.page, number: number + 1 } } as TReq
59
+ }
60
+ throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES)
61
+ }
62
+
63
+ interface CursorEnvelope<TItem> {
64
+ data: TItem[]
65
+ meta: { page: { next: string | null } }
66
+ }
67
+
68
+ interface CursorRequest {
69
+ page?: { after?: string; before?: string; size?: number }
70
+ }
71
+
72
+ /**
73
+ * Iterates every item of a cursor-paginated list operation, following
74
+ * `meta.page.next` until the server stops returning one. Despite carrying a
75
+ * `format: uri` annotation in the spec, `next` is the opaque cursor token the
76
+ * API expects back verbatim in `page.after` on the following request — not a
77
+ * URI to fetch directly. Every other field on `request` is sent unchanged on
78
+ * every page fetch; only `page.after` advances.
79
+ */
80
+ export async function* paginateCursor<TItem, TReq extends CursorRequest>(
81
+ fetchPage: (
82
+ req: TReq,
83
+ options?: RequestOptions,
84
+ ) => Promise<Result<CursorEnvelope<TItem>>>,
85
+ request: TReq,
86
+ options?: RequestOptions,
87
+ ): AsyncGenerator<TItem, void, undefined> {
88
+ let req = request
89
+ for (let page = 0; page < MAX_PAGINATION_PAGES; page++) {
90
+ const res = unwrap(await fetchPage(req, options))
91
+ yield* res.data
92
+ const next = res.meta.page.next
93
+ if (!next) {
94
+ return
95
+ }
96
+ req = { ...req, page: { ...req.page, after: next } } as TReq
97
+ }
98
+ throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES)
99
+ }
api/spec/packages/aip-client-javascript/src/lib/request.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { type Result, ok, err } from './types.js'
4
+ import { toError } from './to-error.js'
5
+
6
+ export async function request<T>(fn: () => Promise<T>): Promise<Result<T>> {
7
+ try {
8
+ return ok(await fn())
9
+ } catch (e) {
10
+ return err(await toError(e))
11
+ }
12
+ }
api/spec/packages/aip-client-javascript/src/lib/to-error.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { HTTPError as KyHTTPError } from 'ky'
4
+ import * as schemas from '../models/schemas.js'
5
+ import { HTTPError } from '../models/errors.js'
6
+
7
+ export async function toError(e: unknown): Promise<Error> {
8
+ if (e instanceof KyHTTPError) {
9
+ // ky consumes the body into e.data; e.response.json() would throw.
10
+ const parsed = schemas.baseError.safeParse(e.data)
11
+ const error = parsed.success ? parsed.data : undefined
12
+ return HTTPError.fromResponse({ response: e.response, error })
13
+ }
14
+ if (e instanceof Error) {
15
+ return e
16
+ }
17
+ return new Error(String(e))
18
+ }
api/spec/packages/aip-client-javascript/src/lib/types.ts ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import type { Options } from 'ky'
4
+
5
+ export type RequestOptions = Pick<
6
+ Options,
7
+ 'signal' | 'headers' | 'timeout' | 'retry'
8
+ >
9
+
10
+ export type Result<T, E = Error> =
11
+ | { ok: true; value: T; error?: never }
12
+ | { ok: false; value?: never; error: E }
13
+
14
+ export function ok<T>(value: T): Result<T, never> {
15
+ return { ok: true, value }
16
+ }
17
+
18
+ export function err<E>(error: E): Result<never, E> {
19
+ return { ok: false, error }
20
+ }
21
+
22
+ export function unwrap<T, E>(result: Result<T, E>): T {
23
+ if (result.ok) {
24
+ return result.value
25
+ }
26
+ throw result.error
27
+ }
api/spec/packages/aip-client-javascript/src/lib/version.ts ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ // The committed value is a dev placeholder. The publish flow
4
+ // (`make -C api/spec publish-aip-sdk`) stamps the real release version here
5
+ // before `pnpm publish`, after `pnpm version` updates package.json.
6
+ export const SDK_VERSION = '0.0.0'
api/spec/packages/aip-client-javascript/src/lib/wire.ts ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import type { output, ZodType } from 'zod'
4
+
5
+ export function toCamelCase(name: string): string {
6
+ return name.replace(/_([a-z0-9])/g, (_m, c: string) => c.toUpperCase())
7
+ }
8
+
9
+ export function toSnakeCase(name: string): string {
10
+ return name.replace(/([A-Z])/g, (_m, c: string) => `_${c.toLowerCase()}`)
11
+ }
12
+
13
+ type ZodDef = {
14
+ type: string
15
+ innerType?: ZodType
16
+ valueType?: ZodType
17
+ element?: ZodType
18
+ discriminator?: string
19
+ options?: ZodType[]
20
+ entries?: Record<string, string>
21
+ defaultValue?: unknown
22
+ }
23
+
24
+ function def(schema: ZodType | undefined): ZodDef | undefined {
25
+ return (schema as { def?: ZodDef } | undefined)?.def
26
+ }
27
+
28
+ // Unwrap optional/nullable/default to the schema that describes the value's
29
+ // shape. These wrappers never change keys, so the walker looks through them
30
+ // before classifying a node.
31
+ function unwrap(schema: ZodType | undefined): ZodType | undefined {
32
+ let current = schema
33
+ for (let i = 0; i < 100 && current; i++) {
34
+ const d = def(current)
35
+ if (
36
+ d &&
37
+ (d.type === 'optional' ||
38
+ d.type === 'nullable' ||
39
+ d.type === 'default') &&
40
+ d.innerType
41
+ ) {
42
+ current = d.innerType
43
+ continue
44
+ }
45
+ return current
46
+ }
47
+ /* v8 ignore next -- loop returns inside; reached only past the cycle guard */
48
+ return current
49
+ }
50
+
51
+ // The default to write for a field the caller omitted, present only when the
52
+ // field is required-with-default in the spec — emitted as `.default(x)` with no
53
+ // `.optional()` in the wrapper chain (TypeSpec `field: T = x`, not
54
+ // `field?: T = x`). Such fields must be present on the wire (e.g. a CloudEvents
55
+ // envelope's `specversion`, which the server's parser rejects when absent), yet
56
+ // the generated request type allows omitting them so callers get the documented
57
+ // default for free — toWire is the layer that has to reconcile the two.
58
+ // Spec-optional fields (`.optional().default(x)`) return undefined and stay off
59
+ // the wire: their default is the server's to apply, and materializing them
60
+ // client-side would silently overwrite server state on update requests.
61
+ function requiredDefault(
62
+ schema: ZodType | undefined,
63
+ ): { value: unknown } | undefined {
64
+ let current = schema
65
+ let found: { value: unknown } | undefined
66
+ for (let i = 0; i < 100 && current; i++) {
67
+ const d = def(current)
68
+ /* v8 ignore next 3 -- every zod schema carries a def; guards the type only */
69
+ if (!d) {
70
+ break
71
+ }
72
+ if (d.type === 'optional') {
73
+ return undefined
74
+ }
75
+ if (d.type === 'default') {
76
+ found ??= { value: d.defaultValue }
77
+ } else if (d.type !== 'nullable') {
78
+ break
79
+ }
80
+ current = d.innerType
81
+ }
82
+ return found
83
+ }
84
+
85
+ function shapeOf(
86
+ schema: ZodType | undefined,
87
+ ): Record<string, ZodType> | undefined {
88
+ return (schema as { shape?: Record<string, ZodType> } | undefined)?.shape
89
+ }
90
+
91
+ // The element schema for array data: the schema's own element when it is an
92
+ // array, or the array variant's element when it is a union of T and T[]
93
+ // (the single-or-batch body shape).
94
+ function arrayElement(schema: ZodType | undefined): ZodType | undefined {
95
+ const d = def(schema)
96
+ if (d?.type === 'array') {
97
+ return d.element
98
+ }
99
+ if (d?.type === 'union') {
100
+ for (const option of d.options ?? []) {
101
+ const od = def(unwrap(option))
102
+ if (od?.type === 'array') {
103
+ return od.element
104
+ }
105
+ }
106
+ }
107
+ return undefined
108
+ }
109
+
110
+ // Whether a record value schema needs walking: it carries renamable fields
111
+ // (object/record/array/union of such) or date-typed values that must map
112
+ // between `Date` and the RFC 3339 wire string. Other scalars, literals,
113
+ // unknown, and any are left untouched, so user data (labels, dimensions,
114
+ // event payloads) is never rewritten.
115
+ function needsWalk(schema: ZodType | undefined): boolean {
116
+ const s = unwrap(schema)
117
+ const d = def(s)
118
+ /* v8 ignore next 3 -- a record always has a value schema; defensive only */
119
+ if (!d) {
120
+ return false
121
+ }
122
+ if (
123
+ d.type === 'object' ||
124
+ d.type === 'record' ||
125
+ d.type === 'date' ||
126
+ d.type === 'bigint'
127
+ ) {
128
+ return true
129
+ }
130
+ if (d.type === 'array') {
131
+ return needsWalk(d.element)
132
+ }
133
+ if (d.type === 'union') {
134
+ return (d.options ?? []).some(needsWalk)
135
+ }
136
+ return false
137
+ }
138
+
139
+ // Thrown by toWire when a bigint value (an int64/uint64 field) is outside
140
+ // JSON's exactly-representable integer range. The wire carries int64 as a JSON
141
+ // number (the server decodes it into a Go int64), so a value beyond 2^53-1
142
+ // cannot be sent without silent precision corruption — a typed, immediate
143
+ // failure is the only honest option. request() catches it like any Error and
144
+ // surfaces it as Result.error.
145
+ export class UnsafeIntegerError extends Error {
146
+ constructor(value: bigint) {
147
+ super(
148
+ `bigint value ${value} exceeds JSON's safe integer range and cannot be sent without precision loss`,
149
+ )
150
+ this.name = 'UnsafeIntegerError'
151
+ }
152
+ }
153
+
154
+ // An RFC 3339 string standing in for a `Date` on request input. The
155
+ // `Record<never, never>` intersection keeps a plain string assignable while
156
+ // stopping the union simplifier from absorbing sibling string literals — a
157
+ // bare `| string` would collapse `'immediate' | 'next_billing_cycle' | Date |
158
+ // string` to `string | Date` and kill literal autocomplete.
159
+ export type DateString = string & Record<never, never>
160
+
161
+ // The request-side widening of a payload type: every `Date` also accepts its
162
+ // RFC 3339 string form. Applied to the generated `…Request` aliases only —
163
+ // domain interfaces and response types stay `Date`, so responses always carry
164
+ // real `Date`s. At runtime the mapper passes request strings through verbatim
165
+ // (never re-parses or normalizes them), so the wire sees exactly what was given
166
+ // and the optional wire validation still checks the string against the RFC 3339
167
+ // wire schema.
168
+ export type AcceptDateStrings<T> = T extends Date
169
+ ? Date | DateString
170
+ : T extends (infer E)[]
171
+ ? AcceptDateStrings<E>[]
172
+ : T extends object
173
+ ? { [K in keyof T]: AcceptDateStrings<T[K]> }
174
+ : T
175
+
176
+ // Literal siblings of `Date` must survive the widening. Checked at compile
177
+ // time in both the emitter build and the generated SDK's typecheck, so a
178
+ // regression to a bare `| string` arm fails the build.
179
+ type _LiteralsSurviveWidening =
180
+ 'x' extends Extract<AcceptDateStrings<'x' | Date>, 'x'>
181
+ ? true
182
+ : {
183
+ __error: 'AcceptDateStrings absorbed literal union members into string'
184
+ }
185
+ const _literalsSurviveWidening: _LiteralsSurviveWidening = true
186
+ void _literalsSurviveWidening
187
+
188
+ type Direction = {
189
+ // The wire→public or public→wire key rename for object fields.
190
+ rename: (key: string) => string
191
+ // The data key holding a discriminated union's discriminator, given the
192
+ // schema's (camelCase) discriminator key.
193
+ discriminatorKey: (camelKey: string) => string
194
+ // The value mapping at a date-typed node: public `Date` → RFC 3339 wire
195
+ // string, wire string → `Date`. Values already in the target form (or not
196
+ // convertible) pass through unchanged.
197
+ mapDate: (value: unknown) => unknown
198
+ // The value mapping at a bigint-typed (int64/uint64) node: public `bigint` →
199
+ // JSON number (throwing UnsafeIntegerError beyond 2^53-1, where JSON numbers
200
+ // lose integer precision), wire number → `bigint`. Without the public→wire
201
+ // mapping, JSON.stringify throws an opaque TypeError on any bigint. Values
202
+ // already in the target form (or not convertible) pass through unchanged.
203
+ mapBigInt: (value: unknown) => unknown
204
+ // Whether absent required-with-default fields are materialized (see
205
+ // requiredDefault). True only public→wire: requests must satisfy the wire
206
+ // contract, while responses are reported as the server sent them — fromWire
207
+ // fabricating fields would mask genuine contract violations.
208
+ applyDefaults: boolean
209
+ // JSON.stringify omits object properties and record entries whose value is
210
+ // undefined. True only public→wire so validation sees the effective JSON
211
+ // payload instead of an intermediate object that the transport cannot send.
212
+ // Array entries are deliberately unaffected: JSON serializes undefined array
213
+ // values as null rather than omitting them.
214
+ omitUndefinedObjectEntries: boolean
215
+ }
216
+
217
+ // A handful of schemas are genuinely self-referential (e.g. the `and`/`or`
218
+ // legs of a filter tree), so nesting depth is bounded only by the DATA the
219
+ // server sends, not by the schema. Without a limit, a crafted or
220
+ // accidentally-deep response recurses until the JS engine throws a raw
221
+ // `RangeError: Maximum call stack size exceeded` — still caught by request()
222
+ // and surfaced as Result.error, but as an opaque native error instead of a
223
+ // typed one. 500 levels is far beyond any real filter/record/array nesting
224
+ // in the API today; it exists to fail predictably, not to constrain valid data.
225
+ const MAX_WALK_DEPTH = 500
226
+
227
+ export class DepthLimitExceededError extends Error {
228
+ constructor() {
229
+ super(`wire mapping exceeded maximum nesting depth (${MAX_WALK_DEPTH})`)
230
+ this.name = 'DepthLimitExceededError'
231
+ }
232
+ }
233
+
234
+ function walk(
235
+ data: unknown,
236
+ schema: ZodType | undefined,
237
+ dir: Direction,
238
+ depth = 0,
239
+ ): unknown {
240
+ if (data === null || data === undefined) {
241
+ return data
242
+ }
243
+ // A Date can only ever mean its wire serialization, wherever it sits — a
244
+ // typed date field, a record value, or an unknown-schema position. Wire→
245
+ // public data never contains Date instances (it comes from JSON.parse), so
246
+ // this only rewrites public→wire. The same holds for bigint: JSON.parse
247
+ // never produces one, and public→wire it must become a JSON number wherever
248
+ // it sits.
249
+ if (data instanceof Date) {
250
+ return dir.mapDate(data)
251
+ }
252
+ if (typeof data === 'bigint') {
253
+ return dir.mapBigInt(data)
254
+ }
255
+ if (depth > MAX_WALK_DEPTH) {
256
+ throw new DepthLimitExceededError()
257
+ }
258
+ const s = unwrap(schema)
259
+ const d = def(s)
260
+ // A date-typed node maps between the public `Date` and the RFC 3339 wire
261
+ // string (fromWire revives the string; a string handed to toWire by an
262
+ // untyped caller passes through as-is).
263
+ if (d?.type === 'date') {
264
+ return dir.mapDate(data)
265
+ }
266
+ // A bigint-typed node revives the wire's JSON number into the public
267
+ // `bigint` (public→wire bigints were already mapped by the value check
268
+ // above, so only fromWire reaches a number here).
269
+ if (d?.type === 'bigint') {
270
+ return dir.mapBigInt(data)
271
+ }
272
+ if (Array.isArray(data)) {
273
+ // The schema may be the array itself or a union with an array variant
274
+ // (e.g. a single-or-batch body `T | T[]`); resolve the element schema from
275
+ // whichever applies so array items are still walked with their shape.
276
+ const element = arrayElement(s)
277
+ return data.map((item) => walk(item, element, dir, depth + 1))
278
+ }
279
+ if (typeof data !== 'object') {
280
+ // A wire datetime can sit behind a union (`DateTime | null`,
281
+ // enum-or-DateTime): revive the string only when the union's date variant
282
+ // is its sole plausible owner, so enum literals and plain-string variants
283
+ // pass through untouched.
284
+ if (
285
+ typeof data === 'string' &&
286
+ d?.type === 'union' &&
287
+ unionDateClaims(s, data)
288
+ ) {
289
+ return dir.mapDate(data)
290
+ }
291
+ return data
292
+ }
293
+ const record = data as Record<string, unknown>
294
+
295
+ if (d?.type === 'record') {
296
+ // Record keys are user data (label/dimension names) — preserved verbatim.
297
+ // Only the value is walked, and only when it needs mapping. A null
298
+ // prototype avoids the `__proto__` key silently reassigning `out`'s own
299
+ // prototype instead of becoming a visible entry (user data may contain
300
+ // any key, including reserved object-literal property names). The
301
+ // prototype is restored once every key is a plain own property, so the
302
+ // returned object still behaves normally for consumers (instanceof,
303
+ // template literals) — `Object.prototype` itself was never touched.
304
+ const valueSchema = needsWalk(d.valueType) ? d.valueType : undefined
305
+ const out: Record<string, unknown> = Object.create(null)
306
+ for (const [key, value] of Object.entries(record)) {
307
+ if (dir.omitUndefinedObjectEntries && value === undefined) {
308
+ continue
309
+ }
310
+ out[key] = valueSchema ? walk(value, valueSchema, dir, depth + 1) : value
311
+ }
312
+ Object.setPrototypeOf(out, Object.prototype)
313
+ return out
314
+ }
315
+
316
+ if (d?.type === 'union') {
317
+ const variant = selectVariant(record, s, dir)
318
+ if (!variant) {
319
+ // No confident match: leave keys untransformed rather than guess.
320
+ return data
321
+ }
322
+ return walk(data, variant, dir, depth + 1)
323
+ }
324
+
325
+ if (d?.type === 'object') {
326
+ const shape = shapeOf(s) ?? {}
327
+ // A null prototype avoids two failure modes from data-controlled keys
328
+ // like `__proto__`/`constructor`: (1) `fieldFor` below reading an
329
+ // inherited Object.prototype member instead of correctly treating the
330
+ // key as schema-undeclared, and (2) the assignment at the end of this
331
+ // loop reassigning `out`'s own prototype instead of adding a visible key.
332
+ const out: Record<string, unknown> = Object.create(null)
333
+ for (const [key, value] of Object.entries(record)) {
334
+ if (dir.omitUndefinedObjectEntries && value === undefined) {
335
+ continue
336
+ }
337
+ const fieldSchema = fieldFor(shape, key)
338
+ // Keys the schema does not declare are dropped, so the result matches the
339
+ // typed shape exactly (a server-added field has no place in the type).
340
+ if (fieldSchema === undefined) {
341
+ continue
342
+ }
343
+ out[dir.rename(key)] = walk(value, fieldSchema, dir, depth + 1)
344
+ }
345
+ if (dir.applyDefaults) {
346
+ // Shape keys are generated camelCase identifiers (never data-controlled),
347
+ // so direct indexing into `record` is safe here. Runs after the data loop
348
+ // so an explicit `key: undefined` entry is also replaced by the default.
349
+ for (const [key, fieldSchema] of Object.entries(shape)) {
350
+ if (record[key] !== undefined) {
351
+ continue
352
+ }
353
+ const dflt = requiredDefault(fieldSchema)
354
+ if (dflt !== undefined) {
355
+ out[dir.rename(key)] = walk(dflt.value, fieldSchema, dir, depth + 1)
356
+ }
357
+ }
358
+ }
359
+ Object.setPrototypeOf(out, Object.prototype)
360
+ return out
361
+ }
362
+
363
+ // Scalar or unknown schema: pass through untransformed.
364
+ return data
365
+ }
366
+
367
+ // Resolve a data key to its field schema. The schema is camelCase-keyed; a
368
+ // wire→public data key is snake, so it is camelized to index the shape.
369
+ // Own-property checks (not `shape[key]`) so a data-controlled key like
370
+ // `__proto__` or `constructor` cannot resolve to an inherited
371
+ // Object.prototype member and be mistaken for a declared schema field.
372
+ function fieldFor(
373
+ shape: Record<string, ZodType>,
374
+ dataKey: string,
375
+ ): ZodType | undefined {
376
+ if (Object.hasOwn(shape, dataKey)) {
377
+ return shape[dataKey]
378
+ }
379
+ const camelKey = toCamelCase(dataKey)
380
+ return Object.hasOwn(shape, camelKey) ? shape[camelKey] : undefined
381
+ }
382
+
383
+ function selectVariant(
384
+ data: Record<string, unknown>,
385
+ schema: ZodType | undefined,
386
+ dir: Direction,
387
+ ): ZodType | undefined {
388
+ const d = def(schema)
389
+ const options = d?.options ?? []
390
+ if (d?.discriminator && schema) {
391
+ // O(1) dispatch on the discriminator literal. The data key is the wire-name in
392
+ // fromWire (snake) and the public name in toWire (camel); the variant map is
393
+ // keyed by the literal value, which is identical in both directions.
394
+ const dataKey = dir.discriminatorKey(d.discriminator)
395
+ return variantsByDiscriminator(schema, d).get(data[dataKey])
396
+ }
397
+ // Non-discriminated union: the codegen gate guarantees at most one object
398
+ // variant (it fails the build for a mapped union with two or more), so the single
399
+ // object-shaped option is unambiguous. Other variants (scalars, arrays) reach the
400
+ // walk through their own data-kind branches, not here.
401
+ return options.find((option) => def(unwrap(option))?.type === 'object')
402
+ }
403
+
404
+ // Memoized literal→variant map for a discriminated union, built once per schema.
405
+ const variantMapCache = new WeakMap<ZodType, Map<unknown, ZodType>>()
406
+
407
+ function variantsByDiscriminator(
408
+ schema: ZodType,
409
+ d: ZodDef,
410
+ ): Map<unknown, ZodType> {
411
+ const cached = variantMapCache.get(schema)
412
+ if (cached) {
413
+ return cached
414
+ }
415
+ const map = new Map<unknown, ZodType>()
416
+ for (const option of d.options ?? []) {
417
+ const shape = shapeOf(unwrap(option))
418
+ const literal = literalValue(shape?.[d.discriminator as string])
419
+ if (literal !== undefined) {
420
+ map.set(literal, option)
421
+ }
422
+ }
423
+ variantMapCache.set(schema, map)
424
+ return map
425
+ }
426
+
427
+ function literalValue(schema: ZodType | undefined): unknown {
428
+ const s = unwrap(schema)
429
+ if (def(s)?.type === 'literal') {
430
+ return (s as { value?: unknown }).value
431
+ }
432
+ /* v8 ignore next -- a discriminated-union variant's discriminator is a literal */
433
+ return undefined
434
+ }
435
+
436
+ // Whether a union's date variant is the sole plausible owner of a string
437
+ // value: the union carries a date option, no string-capable sibling (a plain
438
+ // string variant, an enum containing the value, an equal string literal)
439
+ // claims it, and the value actually parses as a date. `DateTime | null`
440
+ // revives its RFC 3339 string; `'immediate' | DateTime` keeps the enum
441
+ // literal a string. Fail-open: an unclaimed string stays a string.
442
+ function unionDateClaims(schema: ZodType | undefined, value: string): boolean {
443
+ let hasDate = false
444
+ for (const option of def(schema)?.options ?? []) {
445
+ const od = def(unwrap(option))
446
+ if (od?.type === 'date') {
447
+ hasDate = true
448
+ } else if (od?.type === 'string') {
449
+ return false
450
+ } else if (
451
+ od?.type === 'enum' &&
452
+ Object.values(od.entries ?? {}).includes(value)
453
+ ) {
454
+ return false
455
+ } else if (od?.type === 'literal' && literalValue(option) === value) {
456
+ return false
457
+ }
458
+ }
459
+ return hasDate && !Number.isNaN(Date.parse(value))
460
+ }
461
+
462
+ const toWireDirection: Direction = {
463
+ rename: toSnakeCase,
464
+ discriminatorKey: (camelKey) => camelKey,
465
+ mapDate: (value) => (value instanceof Date ? value.toISOString() : value),
466
+ mapBigInt: (value) => {
467
+ if (typeof value !== 'bigint') {
468
+ return value
469
+ }
470
+ if (
471
+ value > BigInt(Number.MAX_SAFE_INTEGER) ||
472
+ value < -BigInt(Number.MAX_SAFE_INTEGER)
473
+ ) {
474
+ throw new UnsafeIntegerError(value)
475
+ }
476
+ return Number(value)
477
+ },
478
+ applyDefaults: true,
479
+ omitUndefinedObjectEntries: true,
480
+ }
481
+
482
+ // Path binding names are transport metadata, not JSON object member names, so
483
+ // they must remain exactly as declared while their values receive the same
484
+ // Date/bigint/default mapping used by request bodies and query parameters.
485
+ const toPathWireDirection: Direction = {
486
+ ...toWireDirection,
487
+ rename: (key) => key,
488
+ }
489
+
490
+ const fromWireDirection: Direction = {
491
+ rename: toCamelCase,
492
+ discriminatorKey: (camelKey) => toSnakeCase(camelKey),
493
+ mapDate: (value) => (typeof value === 'string' ? new Date(value) : value),
494
+ mapBigInt: (value) =>
495
+ typeof value === 'number' && Number.isInteger(value)
496
+ ? BigInt(value)
497
+ : value,
498
+ applyDefaults: false,
499
+ omitUndefinedObjectEntries: false,
500
+ }
501
+
502
+ // Rewrite a request body or query object from the camelCase public shape to the
503
+ // snake_case wire shape, driven by its schema. Record keys (label/dimension names)
504
+ // are preserved; `Date` values serialize to RFC 3339 strings; `bigint` values
505
+ // (int64 fields) become JSON numbers; omitted required-with-default fields are
506
+ // filled with their declared default (see requiredDefault); explicit undefined
507
+ // object/record entries are omitted just as JSON.stringify would omit them. The
508
+ // return is typed as the input `T` so call sites stay cast-free (the runtime object
509
+ // has snake keys and wire-encoded dates, but the value is write-only — it flows
510
+ // straight into `json:`/`toURLSearchParams`, both of which accept any object).
511
+ export function toWire<T>(data: T, schema: ZodType): T {
512
+ return walk(data, schema, toWireDirection) as T
513
+ }
514
+
515
+ // Rewrite path-parameter values to their transport representation without
516
+ // renaming the path binding keys. The returned object is subsequently validated
517
+ // against the generated `…PathParamsWire` schema and URL-encoded by the func.
518
+ export function toPathWire<T>(data: T, schema: ZodType): T {
519
+ return walk(data, schema, toPathWireDirection) as T
520
+ }
521
+
522
+ // Rewrite a response body from the snake_case wire shape to the camelCase public
523
+ // shape: renames keys and revives RFC 3339 strings into `Date`s at date-typed
524
+ // nodes — never applies defaults or any other coercion. The result is the
525
+ // schema's output shape: `walk` produces exactly the schema's known fields in
526
+ // camelCase, so the inferred `output<S>` type describes the runtime value (the
527
+ // same wire-trust boundary as a plain `.json<T>()`, with no `.parse()`).
528
+ export function fromWire<S extends ZodType>(
529
+ data: unknown,
530
+ schema: S,
531
+ ): output<S> {
532
+ return walk(data, schema, fromWireDirection) as output<S>
533
+ }
534
+
535
+ // Thrown by assertValid when the optional `validate` client option is on and data
536
+ // fails its schema. request() catches it like any Error and surfaces it as
537
+ // Result.error.
538
+ export class ValidationError extends Error {
539
+ constructor(
540
+ message: string,
541
+ public readonly issues: unknown,
542
+ ) {
543
+ super(message)
544
+ this.name = 'ValidationError'
545
+ }
546
+ }
547
+
548
+ // Opt-in schema check used by the funcs (when the validate option is on) against
549
+ // the snake_case wire payload: the request body after toWire, the raw response
550
+ // before fromWire, each against its generated `…Wire` schema. It is a GATE, not a
551
+ // transform — the safeParse output (coercions/defaults) is discarded, so validation
552
+ // never mutates the payload or return value. Off by default; the SDK does not
553
+ // validate by default (additive server fields must not break clients).
554
+ export function assertValid(schema: ZodType, data: unknown): void {
555
+ const result = schema.safeParse(data)
556
+ if (!result.success) {
557
+ throw new ValidationError('schema validation failed', result.error.issues)
558
+ }
559
+ }
api/spec/packages/aip-client-javascript/src/models/errors.ts ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from './schemas.js'
5
+
6
+ // Retry-After is either delta-seconds (an integer) or an HTTP-date. Only the
7
+ // delta-seconds form is parsed; HTTP-date values yield undefined rather than
8
+ // a parsed Date, keeping the public type a plain number.
9
+ function parseRetryAfter(header: string | null): number | undefined {
10
+ if (header === null) {
11
+ return undefined
12
+ }
13
+ const trimmed = header.trim()
14
+ return /^\d+$/.test(trimmed) ? Number(trimmed) : undefined
15
+ }
16
+
17
+ export class HTTPError extends Error {
18
+ constructor(
19
+ message: string,
20
+ public type: string,
21
+ public title: string,
22
+ public status: number,
23
+ public url: string,
24
+ public retryAfter: number | undefined,
25
+ protected __raw?: Record<string, unknown>,
26
+ ) {
27
+ super(message)
28
+ this.name = 'HTTPError'
29
+ }
30
+
31
+ static fromResponse(resp: {
32
+ response: Response
33
+ error?: z.infer<typeof schemas.baseError>
34
+ }) {
35
+ const retryAfter = parseRetryAfter(resp.response.headers.get('Retry-After'))
36
+
37
+ if (
38
+ resp.response.headers
39
+ .get('Content-Type')
40
+ ?.includes('application/problem+json') &&
41
+ resp.error
42
+ ) {
43
+ return new HTTPError(
44
+ resp.error.detail,
45
+ resp.error.type ?? resp.error.title,
46
+ resp.error.title,
47
+ resp.error.status ?? resp.response.status,
48
+ resp.response.url,
49
+ retryAfter,
50
+ resp.error,
51
+ )
52
+ }
53
+
54
+ return new HTTPError(
55
+ `Request failed: ${resp.response.statusText}`,
56
+ resp.response.statusText,
57
+ resp.response.statusText,
58
+ resp.response.status,
59
+ resp.response.url,
60
+ retryAfter,
61
+ )
62
+ }
63
+
64
+ /**
65
+ * The `invalid_parameters` problem-detail extension member, present on Bad
66
+ * Request (400) responses. Typed from the schema, not runtime-validated
67
+ * (like the rest of the SDK, this trusts the server rather than rejecting
68
+ * additive fields) — `undefined` when the response didn't carry one.
69
+ */
70
+ get invalidParameters():
71
+ | z.infer<typeof schemas.invalidParameters>
72
+ | undefined {
73
+ return this.__raw?.invalid_parameters as
74
+ | z.infer<typeof schemas.invalidParameters>
75
+ | undefined
76
+ }
77
+
78
+ /**
79
+ * Escape hatch for problem-detail extension members without a typed
80
+ * accessor above.
81
+ */
82
+ getField(key: string) {
83
+ return this.__raw?.[key]
84
+ }
85
+ }
api/spec/packages/aip-client-javascript/src/models/operations/addons.ts ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ Addon,
8
+ AddonPagePaginatedResponse,
9
+ CreateAddonRequestInput,
10
+ ListAddonsParamsFilter,
11
+ SortQueryInput,
12
+ UpsertAddonRequestInput,
13
+ } from '../types.js'
14
+
15
+ export interface ListAddonsQuery {
16
+ /** Determines which page of the collection to retrieve. */
17
+ page?: { size?: number; number?: number }
18
+ /**
19
+ * Sort add-ons returned in the response. Supported sort attributes are:
20
+ *
21
+ * - `id`
22
+ * - `key`
23
+ * - `name`
24
+ * - `created_at` (default)
25
+ * - `updated_at`
26
+ *
27
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
28
+ * suffix is used to specify a descending order.
29
+ */
30
+ sort?: SortQueryInput
31
+ /** Filter add-ons returned in the response. */
32
+ filter?: ListAddonsParamsFilter
33
+ }
34
+
35
+ export type ListAddonsRequest = AcceptDateStrings<ListAddonsQuery>
36
+ export type ListAddonsResponse = AddonPagePaginatedResponse
37
+
38
+ export type CreateAddonRequest = AcceptDateStrings<CreateAddonRequestInput>
39
+ export type CreateAddonResponse = Addon
40
+
41
+ export type UpdateAddonRequest = AcceptDateStrings<{
42
+ addonId: string
43
+ body: UpsertAddonRequestInput
44
+ }>
45
+ export type UpdateAddonResponse = Addon
46
+
47
+ export type GetAddonRequest = {
48
+ addonId: string
49
+ }
50
+ export type GetAddonResponse = Addon
51
+
52
+ export type DeleteAddonRequest = {
53
+ addonId: string
54
+ }
55
+ export type DeleteAddonResponse = void
56
+
57
+ export type ArchiveAddonRequest = {
58
+ addonId: string
59
+ }
60
+ export type ArchiveAddonResponse = Addon
61
+
62
+ export type PublishAddonRequest = {
63
+ addonId: string
64
+ }
65
+ export type PublishAddonResponse = Addon
api/spec/packages/aip-client-javascript/src/models/operations/apps.ts ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ App,
8
+ AppCatalogItem,
9
+ AppCatalogItemPagePaginatedResponse,
10
+ AppPagePaginatedResponse,
11
+ BillingInstallAppResponse,
12
+ InstallAppRequest as InstallAppRequestBody,
13
+ } from '../types.js'
14
+
15
+ export interface ListAppsQuery {
16
+ /** Determines which page of the collection to retrieve. */
17
+ page?: { size?: number; number?: number }
18
+ }
19
+
20
+ export type ListAppsRequest = AcceptDateStrings<ListAppsQuery>
21
+ export type ListAppsResponse = AppPagePaginatedResponse
22
+
23
+ export type GetAppRequest = {
24
+ appId: string
25
+ }
26
+ export type GetAppResponse = App
27
+
28
+ export interface ListAppCatalogQuery {
29
+ /** Determines which page of the collection to retrieve. */
30
+ page?: { size?: number; number?: number }
31
+ }
32
+
33
+ export type ListAppCatalogRequest = AcceptDateStrings<ListAppCatalogQuery>
34
+ export type ListAppCatalogResponse = AppCatalogItemPagePaginatedResponse
35
+
36
+ export type GetAppCatalogItemRequest = {
37
+ appType: string
38
+ }
39
+ export type GetAppCatalogItemResponse = AppCatalogItem
40
+
41
+ export type InstallAppRequest = AcceptDateStrings<InstallAppRequestBody>
42
+ export type InstallAppResponse = BillingInstallAppResponse
api/spec/packages/aip-client-javascript/src/models/operations/billing.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreateBillingProfileRequestInput,
8
+ Profile,
9
+ ProfilePagePaginatedResponse,
10
+ UpsertBillingProfileRequestInput,
11
+ } from '../types.js'
12
+
13
+ export interface ListBillingProfilesQuery {
14
+ /** Determines which page of the collection to retrieve. */
15
+ page?: { size?: number; number?: number }
16
+ }
17
+
18
+ export type ListBillingProfilesRequest =
19
+ AcceptDateStrings<ListBillingProfilesQuery>
20
+ export type ListBillingProfilesResponse = ProfilePagePaginatedResponse
21
+
22
+ export type CreateBillingProfileRequest =
23
+ AcceptDateStrings<CreateBillingProfileRequestInput>
24
+ export type CreateBillingProfileResponse = Profile
25
+
26
+ export type GetBillingProfileRequest = {
27
+ id: string
28
+ }
29
+ export type GetBillingProfileResponse = Profile
30
+
31
+ export type UpdateBillingProfileRequest = AcceptDateStrings<{
32
+ id: string
33
+ body: UpsertBillingProfileRequestInput
34
+ }>
35
+ export type UpdateBillingProfileResponse = Profile
36
+
37
+ export type DeleteBillingProfileRequest = {
38
+ id: string
39
+ }
40
+ export type DeleteBillingProfileResponse = void
api/spec/packages/aip-client-javascript/src/models/operations/currencies.ts ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CostBasis,
8
+ CostBasisPagePaginatedResponse,
9
+ CreateCostBasisRequest as CreateCostBasisRequestBody,
10
+ CreateCurrencyCustomRequest,
11
+ CurrencyCustom,
12
+ CurrencyPagePaginatedResponse,
13
+ ListCostBasesParamsFilter,
14
+ ListCurrenciesParamsFilter,
15
+ SortQueryInput,
16
+ } from '../types.js'
17
+
18
+ export interface ListCurrenciesQuery {
19
+ /** Determines which page of the collection to retrieve. */
20
+ page?: { size?: number; number?: number }
21
+ /**
22
+ * Sort currencies returned in the response. Supported sort attributes are:
23
+ *
24
+ * - `code` (default)
25
+ * - `name`
26
+ *
27
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
28
+ * suffix is used to specify a descending order.
29
+ */
30
+ sort?: SortQueryInput
31
+ /**
32
+ * Filter currencies returned in the response.
33
+ *
34
+ * To filter currencies by type add the following query param: filter[type]=custom
35
+ */
36
+ filter?: ListCurrenciesParamsFilter
37
+ }
38
+
39
+ export type ListCurrenciesRequest = AcceptDateStrings<ListCurrenciesQuery>
40
+ export type ListCurrenciesResponse = CurrencyPagePaginatedResponse
41
+
42
+ export type CreateCustomCurrencyRequest =
43
+ AcceptDateStrings<CreateCurrencyCustomRequest>
44
+ export type CreateCustomCurrencyResponse = CurrencyCustom
45
+
46
+ export interface ListCostBasesQuery {
47
+ /**
48
+ * Filter cost bases returned in the response.
49
+ *
50
+ * To filter cost bases by fiat currency code add the following query param:
51
+ * filter[fiat_code]=USD
52
+ */
53
+ filter?: ListCostBasesParamsFilter
54
+ /** Determines which page of the collection to retrieve. */
55
+ page?: { size?: number; number?: number }
56
+ }
57
+
58
+ export type ListCostBasesRequest = AcceptDateStrings<
59
+ ListCostBasesQuery & { currencyId: string }
60
+ >
61
+ export type ListCostBasesResponse = CostBasisPagePaginatedResponse
62
+
63
+ export type CreateCostBasisRequest = AcceptDateStrings<{
64
+ currencyId: string
65
+ body: CreateCostBasisRequestBody
66
+ }>
67
+ export type CreateCostBasisResponse = CostBasis
api/spec/packages/aip-client-javascript/src/models/operations/customers.ts ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ AppCustomerData,
8
+ AppStripeCreateCheckoutSessionResult,
9
+ AppStripeCreateCustomerPortalSessionResult,
10
+ Charge,
11
+ ChargePagePaginatedResponse,
12
+ CreateChargeRequest,
13
+ CreateCreditAdjustmentRequest as CreateCreditAdjustmentRequestBody,
14
+ CreateCreditGrantRequestInput,
15
+ CreateCustomerRequest as CreateCustomerRequestBody,
16
+ CreditAdjustment,
17
+ CreditBalances,
18
+ CreditGrant,
19
+ CreditGrantPagePaginatedResponse,
20
+ CreditTransactionPaginatedResponse,
21
+ CursorPaginationQueryPage,
22
+ Customer,
23
+ CustomerData,
24
+ CustomerPagePaginatedResponse,
25
+ CustomerStripeCreateCheckoutSessionRequestInput,
26
+ CustomerStripeCreateCustomerPortalSessionRequest,
27
+ GetCreditBalanceParamsFilter,
28
+ ListChargesParamsFilter,
29
+ ListCreditGrantsParamsFilter,
30
+ ListCreditTransactionsParamsFilter,
31
+ ListCustomersParamsFilter,
32
+ SortQueryInput,
33
+ UpdateCreditGrantExternalSettlementRequest as UpdateCreditGrantExternalSettlementRequestBody,
34
+ UpsertAppCustomerDataRequest,
35
+ UpsertCustomerBillingDataRequest,
36
+ UpsertCustomerRequest as UpsertCustomerRequestBody,
37
+ VoidCreditGrantRequestInput,
38
+ } from '../types.js'
39
+
40
+ export type CreateCustomerRequest = AcceptDateStrings<CreateCustomerRequestBody>
41
+ export type CreateCustomerResponse = Customer
42
+
43
+ export type GetCustomerRequest = {
44
+ customerId: string
45
+ }
46
+ export type GetCustomerResponse = Customer
47
+
48
+ export interface ListCustomersQuery {
49
+ /** Determines which page of the collection to retrieve. */
50
+ page?: { size?: number; number?: number }
51
+ /**
52
+ * Sort customers returned in the response. Supported sort attributes are:
53
+ *
54
+ * - `id`
55
+ * - `name` (default)
56
+ * - `created_at`
57
+ *
58
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
59
+ * suffix is used to specify a descending order.
60
+ */
61
+ sort?: SortQueryInput
62
+ /**
63
+ * Filter customers returned in the response.
64
+ *
65
+ * To filter customers by key add the following query param: filter[key]=my-db-id
66
+ */
67
+ filter?: ListCustomersParamsFilter
68
+ }
69
+
70
+ export type ListCustomersRequest = AcceptDateStrings<ListCustomersQuery>
71
+ export type ListCustomersResponse = CustomerPagePaginatedResponse
72
+
73
+ export type UpsertCustomerRequest = AcceptDateStrings<{
74
+ customerId: string
75
+ body: UpsertCustomerRequestBody
76
+ }>
77
+ export type UpsertCustomerResponse = Customer
78
+
79
+ export type DeleteCustomerRequest = {
80
+ customerId: string
81
+ }
82
+ export type DeleteCustomerResponse = void
83
+
84
+ export type GetCustomerBillingRequest = {
85
+ customerId: string
86
+ }
87
+ export type GetCustomerBillingResponse = CustomerData
88
+
89
+ export type UpdateCustomerBillingRequest = AcceptDateStrings<{
90
+ customerId: string
91
+ body: UpsertCustomerBillingDataRequest
92
+ }>
93
+ export type UpdateCustomerBillingResponse = CustomerData
94
+
95
+ export type UpdateCustomerBillingAppDataRequest = AcceptDateStrings<{
96
+ customerId: string
97
+ body: UpsertAppCustomerDataRequest
98
+ }>
99
+ export type UpdateCustomerBillingAppDataResponse = AppCustomerData
100
+
101
+ export type CreateCustomerStripeCheckoutSessionRequest = AcceptDateStrings<{
102
+ customerId: string
103
+ body: CustomerStripeCreateCheckoutSessionRequestInput
104
+ }>
105
+ export type CreateCustomerStripeCheckoutSessionResponse =
106
+ AppStripeCreateCheckoutSessionResult
107
+
108
+ export type CreateCustomerStripePortalSessionRequest = AcceptDateStrings<{
109
+ customerId: string
110
+ body: CustomerStripeCreateCustomerPortalSessionRequest
111
+ }>
112
+ export type CreateCustomerStripePortalSessionResponse =
113
+ AppStripeCreateCustomerPortalSessionResult
114
+
115
+ export type CreateCreditGrantRequest = AcceptDateStrings<{
116
+ customerId: string
117
+ body: CreateCreditGrantRequestInput
118
+ }>
119
+ export type CreateCreditGrantResponse = CreditGrant
120
+
121
+ export type GetCreditGrantRequest = {
122
+ customerId: string
123
+ creditGrantId: string
124
+ }
125
+ export type GetCreditGrantResponse = CreditGrant
126
+
127
+ export interface ListCreditGrantsQuery {
128
+ /** Determines which page of the collection to retrieve. */
129
+ page?: { size?: number; number?: number }
130
+ /** Filter credit grants returned in the response. */
131
+ filter?: ListCreditGrantsParamsFilter
132
+ }
133
+
134
+ export type ListCreditGrantsRequest = AcceptDateStrings<
135
+ ListCreditGrantsQuery & { customerId: string }
136
+ >
137
+ export type ListCreditGrantsResponse = CreditGrantPagePaginatedResponse
138
+
139
+ export interface GetCustomerCreditBalanceQuery {
140
+ /**
141
+ * Return the credit balance as of this timestamp.
142
+ *
143
+ * Defaults to the current time.
144
+ */
145
+ timestamp?: Date
146
+ filter?: GetCreditBalanceParamsFilter
147
+ }
148
+
149
+ export type GetCustomerCreditBalanceRequest = AcceptDateStrings<
150
+ GetCustomerCreditBalanceQuery & { customerId: string }
151
+ >
152
+ export type GetCustomerCreditBalanceResponse = CreditBalances
153
+
154
+ export type CreateCreditAdjustmentRequest = AcceptDateStrings<{
155
+ customerId: string
156
+ body: CreateCreditAdjustmentRequestBody
157
+ }>
158
+ export type CreateCreditAdjustmentResponse = CreditAdjustment
159
+
160
+ export type VoidCreditGrantRequest = AcceptDateStrings<{
161
+ customerId: string
162
+ creditGrantId: string
163
+ body: VoidCreditGrantRequestInput
164
+ }>
165
+ export type VoidCreditGrantResponse = CreditGrant
166
+
167
+ export type UpdateCreditGrantExternalSettlementRequest = AcceptDateStrings<{
168
+ customerId: string
169
+ creditGrantId: string
170
+ body: UpdateCreditGrantExternalSettlementRequestBody
171
+ }>
172
+ export type UpdateCreditGrantExternalSettlementResponse = CreditGrant
173
+
174
+ export interface ListCreditTransactionsQuery {
175
+ page?: CursorPaginationQueryPage
176
+ /** Filter credit transactions returned in the response. */
177
+ filter?: ListCreditTransactionsParamsFilter
178
+ }
179
+
180
+ export type ListCreditTransactionsRequest = AcceptDateStrings<
181
+ ListCreditTransactionsQuery & { customerId: string }
182
+ >
183
+ export type ListCreditTransactionsResponse = CreditTransactionPaginatedResponse
184
+
185
+ export interface ListCustomerChargesQuery {
186
+ /** Determines which page of the collection to retrieve. */
187
+ page?: { size?: number; number?: number }
188
+ /**
189
+ * Sort charges returned in the response.
190
+ *
191
+ * Supported sort attributes are:
192
+ *
193
+ * - `id`
194
+ * - `created_at`
195
+ * - `service_period.from`
196
+ * - `billing_period.from`
197
+ */
198
+ sort?: SortQueryInput
199
+ /**
200
+ * Filter charges.
201
+ *
202
+ * To filter charges by status add the following query param:
203
+ * `filter[status][oeq]=created,active`
204
+ */
205
+ filter?: ListChargesParamsFilter
206
+ /**
207
+ * Expand full objects for referenced entities.
208
+ *
209
+ * Supported values are:
210
+ *
211
+ * - `real_time_usage`: Expand the charge's real-time usage.
212
+ */
213
+ expand?: 'real_time_usage'[]
214
+ }
215
+
216
+ export type ListCustomerChargesRequest = AcceptDateStrings<
217
+ ListCustomerChargesQuery & { customerId: string }
218
+ >
219
+ export type ListCustomerChargesResponse = ChargePagePaginatedResponse
220
+
221
+ export type CreateCustomerChargesRequest = AcceptDateStrings<{
222
+ customerId: string
223
+ body: CreateChargeRequest
224
+ }>
225
+ export type CreateCustomerChargesResponse = Charge
api/spec/packages/aip-client-javascript/src/models/operations/defaults.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import type { AcceptDateStrings } from '../../lib/wire.js'
4
+ import type {
5
+ OrganizationDefaultTaxCodes,
6
+ UpdateOrganizationDefaultTaxCodesRequest as UpdateOrganizationDefaultTaxCodesRequestBody,
7
+ } from '../types.js'
8
+
9
+ export type GetOrganizationDefaultTaxCodesRequest = Record<string, never>
10
+ export type GetOrganizationDefaultTaxCodesResponse = OrganizationDefaultTaxCodes
11
+
12
+ export type UpdateOrganizationDefaultTaxCodesRequest =
13
+ AcceptDateStrings<UpdateOrganizationDefaultTaxCodesRequestBody>
14
+ export type UpdateOrganizationDefaultTaxCodesResponse =
15
+ OrganizationDefaultTaxCodes
api/spec/packages/aip-client-javascript/src/models/operations/entitlements.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import type { ListCustomerEntitlementAccessResponseData } from '../types.js'
4
+
5
+ export type ListCustomerEntitlementAccessRequest = {
6
+ customerId: string
7
+ }
8
+ export type ListCustomerEntitlementAccessResponse =
9
+ ListCustomerEntitlementAccessResponseData
api/spec/packages/aip-client-javascript/src/models/operations/events.ts ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CursorPaginationQueryPage,
8
+ EventInput,
9
+ IngestedEventPaginatedResponse,
10
+ ListEventsParamsFilter,
11
+ SortQueryInput,
12
+ } from '../types.js'
13
+
14
+ export interface ListMeteringEventsQuery {
15
+ page?: CursorPaginationQueryPage
16
+ /**
17
+ * Filter events returned in the response.
18
+ *
19
+ * To filter events by subject add the following query param:
20
+ * filter[subject][eq]=customer-1
21
+ */
22
+ filter?: ListEventsParamsFilter
23
+ /**
24
+ * Sort events returned in the response. Supported sort attributes are:
25
+ *
26
+ * - `time` (default)
27
+ * - `ingested_at`
28
+ * - `stored_at`
29
+ *
30
+ * When omitted, events are sorted by `time desc` (most recent first). When a sort
31
+ * field is provided without a suffix, it sorts descending. Append the `asc` suffix
32
+ * to sort ascending, or the `desc` suffix to sort descending.
33
+ */
34
+ sort?: SortQueryInput
35
+ }
36
+
37
+ export type ListMeteringEventsRequest =
38
+ AcceptDateStrings<ListMeteringEventsQuery>
39
+ export type ListMeteringEventsResponse = IngestedEventPaginatedResponse
40
+
41
+ export type IngestMeteringEventsRequest = AcceptDateStrings<
42
+ EventInput | EventInput[]
43
+ >
44
+ export type IngestMeteringEventsResponse = void
api/spec/packages/aip-client-javascript/src/models/operations/features.ts ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreateFeatureRequest as CreateFeatureRequestBody,
8
+ Feature,
9
+ FeatureCostQueryResult,
10
+ FeaturePagePaginatedResponse,
11
+ ListFeatureParamsFilter,
12
+ MeterQueryRequestInput,
13
+ SortQueryInput,
14
+ UpdateFeatureRequest as UpdateFeatureRequestBody,
15
+ } from '../types.js'
16
+
17
+ export interface ListFeaturesQuery {
18
+ /** Determines which page of the collection to retrieve. */
19
+ page?: { size?: number; number?: number }
20
+ /**
21
+ * Sort features returned in the response. Supported sort attributes are:
22
+ *
23
+ * - `key`
24
+ * - `name`
25
+ * - `created_at` (default)
26
+ * - `updated_at`
27
+ *
28
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
29
+ * suffix is used to specify a descending order.
30
+ */
31
+ sort?: SortQueryInput
32
+ /**
33
+ * Filter features returned in the response.
34
+ *
35
+ * To filter features by meter_id add the following query param:
36
+ * filter[meter_id][oeq]=<id>
37
+ */
38
+ filter?: ListFeatureParamsFilter
39
+ }
40
+
41
+ export type ListFeaturesRequest = AcceptDateStrings<ListFeaturesQuery>
42
+ export type ListFeaturesResponse = FeaturePagePaginatedResponse
43
+
44
+ export type CreateFeatureRequest = AcceptDateStrings<CreateFeatureRequestBody>
45
+ export type CreateFeatureResponse = Feature
46
+
47
+ export type GetFeatureRequest = {
48
+ featureId: string
49
+ }
50
+ export type GetFeatureResponse = Feature
51
+
52
+ export type UpdateFeatureRequest = AcceptDateStrings<{
53
+ featureId: string
54
+ body: UpdateFeatureRequestBody
55
+ }>
56
+ export type UpdateFeatureResponse = Feature
57
+
58
+ export type DeleteFeatureRequest = {
59
+ featureId: string
60
+ }
61
+ export type DeleteFeatureResponse = void
62
+
63
+ export type QueryFeatureCostRequest = AcceptDateStrings<{
64
+ featureId: string
65
+ body: MeterQueryRequestInput
66
+ }>
67
+ export type QueryFeatureCostResponse = FeatureCostQueryResult
api/spec/packages/aip-client-javascript/src/models/operations/governance.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CursorPaginationQueryPage,
8
+ GovernanceQueryRequestInput,
9
+ GovernanceQueryResponse,
10
+ } from '../types.js'
11
+
12
+ export interface QueryGovernanceAccessQuery {
13
+ page?: CursorPaginationQueryPage
14
+ }
15
+
16
+ export type QueryGovernanceAccessRequest = AcceptDateStrings<
17
+ {
18
+ body: GovernanceQueryRequestInput
19
+ } & QueryGovernanceAccessQuery
20
+ >
21
+ export type QueryGovernanceAccessResponse = GovernanceQueryResponse
api/spec/packages/aip-client-javascript/src/models/operations/invoices.ts ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ Invoice,
8
+ InvoicePagePaginatedResponse,
9
+ ListInvoicesParamsFilter,
10
+ SortQueryInput,
11
+ UpdateInvoiceRequestInput,
12
+ } from '../types.js'
13
+
14
+ export interface ListInvoicesQuery {
15
+ /** Determines which page of the collection to retrieve. */
16
+ page?: { size?: number; number?: number }
17
+ /**
18
+ * Sort invoices returned in the response. Supported sort attributes:
19
+ *
20
+ * - `issued_at`
21
+ * - `created_at` (default)
22
+ * - `service_period_start`
23
+ *
24
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
25
+ * suffix is used to specify a descending order.
26
+ */
27
+ sort?: SortQueryInput
28
+ /**
29
+ * Filter invoices returned in the response.
30
+ *
31
+ * Examples:
32
+ *
33
+ * - `filter[status][oeq]=draft,issued`
34
+ * - `filter[customer_id]=01KPDB8K...`
35
+ * - `filter[issued_at][gte]=2024-01-01T00:00:00Z`
36
+ */
37
+ filter?: ListInvoicesParamsFilter
38
+ }
39
+
40
+ export type ListInvoicesRequest = AcceptDateStrings<ListInvoicesQuery>
41
+ export type ListInvoicesResponse = InvoicePagePaginatedResponse
42
+
43
+ export type GetInvoiceRequest = {
44
+ invoiceId: string
45
+ }
46
+ export type GetInvoiceResponse = Invoice
47
+
48
+ export type UpdateInvoiceRequest = AcceptDateStrings<{
49
+ invoiceId: string
50
+ body: UpdateInvoiceRequestInput
51
+ }>
52
+ export type UpdateInvoiceResponse = Invoice
53
+
54
+ export type DeleteInvoiceRequest = {
55
+ invoiceId: string
56
+ }
57
+ export type DeleteInvoiceResponse = void
58
+
59
+ export type AdvanceInvoiceRequest = {
60
+ invoiceId: string
61
+ }
62
+ export type AdvanceInvoiceResponse = Invoice
63
+
64
+ export type ApproveInvoiceRequest = {
65
+ invoiceId: string
66
+ }
67
+ export type ApproveInvoiceResponse = Invoice
68
+
69
+ export type RetryInvoiceRequest = {
70
+ invoiceId: string
71
+ }
72
+ export type RetryInvoiceResponse = Invoice
73
+
74
+ export type SnapshotQuantitiesInvoiceRequest = {
75
+ invoiceId: string
76
+ }
77
+ export type SnapshotQuantitiesInvoiceResponse = Invoice
api/spec/packages/aip-client-javascript/src/models/operations/llmCost.ts ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ ListLlmCostPricesParamsFilter,
8
+ LlmCostOverrideCreate,
9
+ LlmCostPrice,
10
+ PricePagePaginatedResponse,
11
+ SortQueryInput,
12
+ } from '../types.js'
13
+
14
+ export interface ListLlmCostPricesQuery {
15
+ /** Filter prices. */
16
+ filter?: ListLlmCostPricesParamsFilter
17
+ /**
18
+ * Sort prices returned in the response. Supported sort attributes are:
19
+ *
20
+ * - `id`
21
+ * - `provider.id`
22
+ * - `model.id` (default)
23
+ * - `effective_from`
24
+ * - `effective_to`
25
+ *
26
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
27
+ * suffix is used to specify a descending order.
28
+ */
29
+ sort?: SortQueryInput
30
+ /** Determines which page of the collection to retrieve. */
31
+ page?: { size?: number; number?: number }
32
+ }
33
+
34
+ export type ListLlmCostPricesRequest = AcceptDateStrings<ListLlmCostPricesQuery>
35
+ export type ListLlmCostPricesResponse = PricePagePaginatedResponse
36
+
37
+ export type GetLlmCostPriceRequest = {
38
+ priceId: string
39
+ }
40
+ export type GetLlmCostPriceResponse = LlmCostPrice
41
+
42
+ export interface ListLlmCostOverridesQuery {
43
+ filter?: ListLlmCostPricesParamsFilter
44
+ /** Determines which page of the collection to retrieve. */
45
+ page?: { size?: number; number?: number }
46
+ }
47
+
48
+ export type ListLlmCostOverridesRequest =
49
+ AcceptDateStrings<ListLlmCostOverridesQuery>
50
+ export type ListLlmCostOverridesResponse = PricePagePaginatedResponse
51
+
52
+ export type CreateLlmCostOverrideRequest =
53
+ AcceptDateStrings<LlmCostOverrideCreate>
54
+ export type CreateLlmCostOverrideResponse = LlmCostPrice
55
+
56
+ export type DeleteLlmCostOverrideRequest = {
57
+ priceId: string
58
+ }
59
+ export type DeleteLlmCostOverrideResponse = void
api/spec/packages/aip-client-javascript/src/models/operations/meters.ts ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreateMeterRequest as CreateMeterRequestBody,
8
+ ListMetersParamsFilter,
9
+ Meter,
10
+ MeterPagePaginatedResponse,
11
+ MeterQueryRequestInput,
12
+ MeterQueryResult,
13
+ SortQueryInput,
14
+ UpdateMeterRequest as UpdateMeterRequestBody,
15
+ } from '../types.js'
16
+
17
+ export type CreateMeterRequest = AcceptDateStrings<CreateMeterRequestBody>
18
+ export type CreateMeterResponse = Meter
19
+
20
+ export type GetMeterRequest = {
21
+ meterId: string
22
+ }
23
+ export type GetMeterResponse = Meter
24
+
25
+ export interface ListMetersQuery {
26
+ /** Determines which page of the collection to retrieve. */
27
+ page?: { size?: number; number?: number }
28
+ /**
29
+ * Sort meters returned in the response. Supported sort attributes are:
30
+ *
31
+ * - `key`
32
+ * - `name`
33
+ * - `aggregation`
34
+ * - `created_at` (default)
35
+ * - `updated_at`
36
+ *
37
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
38
+ * suffix is used to specify a descending order.
39
+ */
40
+ sort?: SortQueryInput
41
+ /**
42
+ * Filter meters returned in the response.
43
+ *
44
+ * To filter meters by key add the following query param: filter[key]=my-meter-key
45
+ */
46
+ filter?: ListMetersParamsFilter
47
+ }
48
+
49
+ export type ListMetersRequest = AcceptDateStrings<ListMetersQuery>
50
+ export type ListMetersResponse = MeterPagePaginatedResponse
51
+
52
+ export type UpdateMeterRequest = AcceptDateStrings<{
53
+ meterId: string
54
+ body: UpdateMeterRequestBody
55
+ }>
56
+ export type UpdateMeterResponse = Meter
57
+
58
+ export type DeleteMeterRequest = {
59
+ meterId: string
60
+ }
61
+ export type DeleteMeterResponse = void
62
+
63
+ export type QueryMeterRequest = AcceptDateStrings<{
64
+ meterId: string
65
+ body: MeterQueryRequestInput
66
+ }>
67
+ export type QueryMeterResponse = MeterQueryResult
68
+
69
+ export type QueryMeterCsvRequest = AcceptDateStrings<{
70
+ meterId: string
71
+ body: MeterQueryRequestInput
72
+ }>
73
+ export type QueryMeterCsvResponse = string
api/spec/packages/aip-client-javascript/src/models/operations/planAddons.ts ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreatePlanAddonRequest as CreatePlanAddonRequestBody,
8
+ PlanAddon,
9
+ PlanAddonPagePaginatedResponse,
10
+ UpsertPlanAddonRequest,
11
+ } from '../types.js'
12
+
13
+ export interface ListPlanAddonsQuery {
14
+ /** Determines which page of the collection to retrieve. */
15
+ page?: { size?: number; number?: number }
16
+ }
17
+
18
+ export type ListPlanAddonsRequest = AcceptDateStrings<
19
+ ListPlanAddonsQuery & { planId: string }
20
+ >
21
+ export type ListPlanAddonsResponse = PlanAddonPagePaginatedResponse
22
+
23
+ export type CreatePlanAddonRequest = AcceptDateStrings<{
24
+ planId: string
25
+ body: CreatePlanAddonRequestBody
26
+ }>
27
+ export type CreatePlanAddonResponse = PlanAddon
28
+
29
+ export type GetPlanAddonRequest = {
30
+ planId: string
31
+ planAddonId: string
32
+ }
33
+ export type GetPlanAddonResponse = PlanAddon
34
+
35
+ export type UpdatePlanAddonRequest = AcceptDateStrings<{
36
+ planId: string
37
+ planAddonId: string
38
+ body: UpsertPlanAddonRequest
39
+ }>
40
+ export type UpdatePlanAddonResponse = PlanAddon
41
+
42
+ export type DeletePlanAddonRequest = {
43
+ planId: string
44
+ planAddonId: string
45
+ }
46
+ export type DeletePlanAddonResponse = void
api/spec/packages/aip-client-javascript/src/models/operations/plans.ts ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreatePlanRequestInput,
8
+ ListPlansParamsFilter,
9
+ Plan,
10
+ PlanPagePaginatedResponse,
11
+ SortQueryInput,
12
+ UpsertPlanRequestInput,
13
+ } from '../types.js'
14
+
15
+ export interface ListPlansQuery {
16
+ /** Determines which page of the collection to retrieve. */
17
+ page?: { size?: number; number?: number }
18
+ /**
19
+ * Sort plans returned in the response. Supported sort attributes are:
20
+ *
21
+ * - `id`
22
+ * - `key`
23
+ * - `version`
24
+ * - `created_at` (default)
25
+ * - `updated_at`
26
+ */
27
+ sort?: SortQueryInput
28
+ /** Filter plans returned in the response. */
29
+ filter?: ListPlansParamsFilter
30
+ }
31
+
32
+ export type ListPlansRequest = AcceptDateStrings<ListPlansQuery>
33
+ export type ListPlansResponse = PlanPagePaginatedResponse
34
+
35
+ export type CreatePlanRequest = AcceptDateStrings<CreatePlanRequestInput>
36
+ export type CreatePlanResponse = Plan
37
+
38
+ export type UpdatePlanRequest = AcceptDateStrings<{
39
+ planId: string
40
+ body: UpsertPlanRequestInput
41
+ }>
42
+ export type UpdatePlanResponse = Plan
43
+
44
+ export type GetPlanRequest = {
45
+ planId: string
46
+ }
47
+ export type GetPlanResponse = Plan
48
+
49
+ export type DeletePlanRequest = {
50
+ planId: string
51
+ }
52
+ export type DeletePlanResponse = void
53
+
54
+ export type ArchivePlanRequest = {
55
+ planId: string
56
+ }
57
+ export type ArchivePlanResponse = Plan
58
+
59
+ export type PublishPlanRequest = {
60
+ planId: string
61
+ }
62
+ export type PublishPlanResponse = Plan
api/spec/packages/aip-client-javascript/src/models/operations/subscriptions.ts ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreateSubscriptionAddonRequest as CreateSubscriptionAddonRequestBody,
8
+ ListSubscriptionsParamsFilter,
9
+ SortQueryInput,
10
+ Subscription,
11
+ SubscriptionAddon,
12
+ SubscriptionAddonPagePaginatedResponse,
13
+ SubscriptionCancelInput,
14
+ SubscriptionChange,
15
+ SubscriptionChangeResponse,
16
+ SubscriptionCreate,
17
+ SubscriptionPagePaginatedResponse,
18
+ } from '../types.js'
19
+
20
+ export type CreateSubscriptionRequest = AcceptDateStrings<SubscriptionCreate>
21
+ export type CreateSubscriptionResponse = Subscription
22
+
23
+ export interface ListSubscriptionsQuery {
24
+ /** Determines which page of the collection to retrieve. */
25
+ page?: { size?: number; number?: number }
26
+ /**
27
+ * Sort subscriptions returned in the response. Supported sort attributes are:
28
+ *
29
+ * - `id`
30
+ * - `active_from` (default)
31
+ * - `active_to`
32
+ *
33
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
34
+ * suffix is used to specify a descending order.
35
+ */
36
+ sort?: SortQueryInput
37
+ /** Filter subscriptions. */
38
+ filter?: ListSubscriptionsParamsFilter
39
+ }
40
+
41
+ export type ListSubscriptionsRequest = AcceptDateStrings<ListSubscriptionsQuery>
42
+ export type ListSubscriptionsResponse = SubscriptionPagePaginatedResponse
43
+
44
+ export type GetSubscriptionRequest = {
45
+ subscriptionId: string
46
+ }
47
+ export type GetSubscriptionResponse = Subscription
48
+
49
+ export type CancelSubscriptionRequest = AcceptDateStrings<{
50
+ subscriptionId: string
51
+ body: SubscriptionCancelInput
52
+ }>
53
+ export type CancelSubscriptionResponse = Subscription
54
+
55
+ export type UnscheduleCancelationRequest = {
56
+ subscriptionId: string
57
+ }
58
+ export type UnscheduleCancelationResponse = Subscription
59
+
60
+ export type ChangeSubscriptionRequest = AcceptDateStrings<{
61
+ subscriptionId: string
62
+ body: SubscriptionChange
63
+ }>
64
+ export type ChangeSubscriptionResponse = SubscriptionChangeResponse
65
+
66
+ export type CreateSubscriptionAddonRequest = AcceptDateStrings<{
67
+ subscriptionId: string
68
+ body: CreateSubscriptionAddonRequestBody
69
+ }>
70
+ export type CreateSubscriptionAddonResponse = SubscriptionAddon
71
+
72
+ export interface ListSubscriptionAddonsQuery {
73
+ /** Determines which page of the collection to retrieve. */
74
+ page?: { size?: number; number?: number }
75
+ /**
76
+ * Sort subscription addons returned in the response. Supported sort attributes
77
+ * are:
78
+ *
79
+ * - `id`
80
+ * - `created_at` (default)
81
+ * - `updated_at`
82
+ *
83
+ * The `asc` suffix is optional as the default sort order is ascending. The `desc`
84
+ * suffix is used to specify a descending order.
85
+ */
86
+ sort?: SortQueryInput
87
+ }
88
+
89
+ export type ListSubscriptionAddonsRequest = AcceptDateStrings<
90
+ ListSubscriptionAddonsQuery & { subscriptionId: string }
91
+ >
92
+ export type ListSubscriptionAddonsResponse =
93
+ SubscriptionAddonPagePaginatedResponse
94
+
95
+ export type GetSubscriptionAddonRequest = {
96
+ subscriptionId: string
97
+ subscriptionAddonId: string
98
+ }
99
+ export type GetSubscriptionAddonResponse = SubscriptionAddon
api/spec/packages/aip-client-javascript/src/models/operations/tax.ts ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+
3
+ import { z } from 'zod'
4
+ import * as schemas from '../schemas.js'
5
+ import type { AcceptDateStrings } from '../../lib/wire.js'
6
+ import type {
7
+ CreateTaxCodeRequest as CreateTaxCodeRequestBody,
8
+ TaxCode,
9
+ TaxCodePagePaginatedResponse,
10
+ UpsertTaxCodeRequest as UpsertTaxCodeRequestBody,
11
+ } from '../types.js'
12
+
13
+ export type CreateTaxCodeRequest = AcceptDateStrings<CreateTaxCodeRequestBody>
14
+ export type CreateTaxCodeResponse = TaxCode
15
+
16
+ export type GetTaxCodeRequest = {
17
+ taxCodeId: string
18
+ }
19
+ export type GetTaxCodeResponse = TaxCode
20
+
21
+ export interface ListTaxCodesQuery {
22
+ /** Determines which page of the collection to retrieve. */
23
+ page?: { size?: number; number?: number }
24
+ /** Include deleted tax codes in the response. */
25
+ includeDeleted?: boolean
26
+ }
27
+
28
+ export type ListTaxCodesRequest = AcceptDateStrings<ListTaxCodesQuery>
29
+ export type ListTaxCodesResponse = TaxCodePagePaginatedResponse
30
+
31
+ export type UpsertTaxCodeRequest = AcceptDateStrings<{
32
+ taxCodeId: string
33
+ body: UpsertTaxCodeRequestBody
34
+ }>
35
+ export type UpsertTaxCodeResponse = TaxCode
36
+
37
+ export type DeleteTaxCodeRequest = {
38
+ taxCodeId: string
39
+ }
40
+ export type DeleteTaxCodeResponse = void