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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +365 -76
  3. package/dist/core.d.ts +0 -1
  4. package/dist/core.js +11 -1
  5. package/dist/funcs/addons.d.ts +49 -1
  6. package/dist/funcs/addons.js +109 -12
  7. package/dist/funcs/apps.d.ts +55 -2
  8. package/dist/funcs/apps.js +179 -4
  9. package/dist/funcs/billing.d.ts +46 -1
  10. package/dist/funcs/billing.js +81 -8
  11. package/dist/funcs/currencies.d.ts +39 -2
  12. package/dist/funcs/currencies.js +93 -6
  13. package/dist/funcs/customers.d.ts +165 -2
  14. package/dist/funcs/customers.js +402 -40
  15. package/dist/funcs/defaults.d.ts +10 -1
  16. package/dist/funcs/defaults.js +11 -1
  17. package/dist/funcs/entitlements.d.ts +5 -1
  18. package/dist/funcs/entitlements.js +18 -4
  19. package/dist/funcs/events.d.ts +14 -1
  20. package/dist/funcs/events.js +18 -1
  21. package/dist/funcs/features.d.ts +42 -1
  22. package/dist/funcs/features.js +91 -10
  23. package/dist/funcs/governance.d.ts +14 -1
  24. package/dist/funcs/governance.js +15 -1
  25. package/dist/funcs/index.d.ts +0 -1
  26. package/dist/funcs/index.js +1 -1
  27. package/dist/funcs/invoices.d.ts +102 -2
  28. package/dist/funcs/invoices.js +247 -8
  29. package/dist/funcs/llmCost.d.ts +36 -1
  30. package/dist/funcs/llmCost.js +63 -6
  31. package/dist/funcs/meters.d.ts +53 -1
  32. package/dist/funcs/meters.js +113 -12
  33. package/dist/funcs/planAddons.d.ts +35 -1
  34. package/dist/funcs/planAddons.js +101 -18
  35. package/dist/funcs/plans.d.ts +49 -1
  36. package/dist/funcs/plans.js +109 -12
  37. package/dist/funcs/subscriptions.d.ts +59 -1
  38. package/dist/funcs/subscriptions.js +147 -18
  39. package/dist/funcs/tax.d.ts +25 -1
  40. package/dist/funcs/tax.js +60 -8
  41. package/dist/index.d.ts +4 -7
  42. package/dist/index.js +4 -6
  43. package/dist/lib/config.d.ts +2 -3
  44. package/dist/lib/config.js +1 -1
  45. package/dist/lib/encodings.d.ts +0 -1
  46. package/dist/lib/encodings.js +1 -1
  47. package/dist/lib/paginate.d.ts +56 -0
  48. package/dist/lib/paginate.js +60 -0
  49. package/dist/lib/request.d.ts +0 -1
  50. package/dist/lib/request.js +1 -1
  51. package/dist/lib/to-error.d.ts +0 -1
  52. package/dist/lib/to-error.js +1 -1
  53. package/dist/lib/types.d.ts +0 -1
  54. package/dist/lib/types.js +1 -1
  55. package/dist/lib/version.d.ts +1 -0
  56. package/dist/lib/version.js +5 -0
  57. package/dist/lib/wire.d.ts +4 -1
  58. package/dist/lib/wire.js +118 -7
  59. package/dist/models/errors.d.ts +13 -2
  60. package/dist/models/errors.js +31 -4
  61. package/dist/models/operations/addons.d.ts +0 -1
  62. package/dist/models/operations/addons.js +1 -1
  63. package/dist/models/operations/apps.d.ts +26 -5
  64. package/dist/models/operations/apps.js +1 -1
  65. package/dist/models/operations/billing.d.ts +0 -1
  66. package/dist/models/operations/billing.js +1 -1
  67. package/dist/models/operations/currencies.d.ts +10 -1
  68. package/dist/models/operations/currencies.js +1 -1
  69. package/dist/models/operations/customers.d.ts +11 -7
  70. package/dist/models/operations/customers.js +1 -1
  71. package/dist/models/operations/defaults.d.ts +0 -1
  72. package/dist/models/operations/defaults.js +1 -1
  73. package/dist/models/operations/entitlements.d.ts +0 -1
  74. package/dist/models/operations/entitlements.js +1 -1
  75. package/dist/models/operations/events.d.ts +0 -1
  76. package/dist/models/operations/events.js +1 -1
  77. package/dist/models/operations/features.d.ts +0 -1
  78. package/dist/models/operations/features.js +1 -1
  79. package/dist/models/operations/governance.d.ts +0 -1
  80. package/dist/models/operations/governance.js +1 -1
  81. package/dist/models/operations/invoices.d.ts +20 -7
  82. package/dist/models/operations/invoices.js +1 -1
  83. package/dist/models/operations/llmCost.d.ts +0 -1
  84. package/dist/models/operations/llmCost.js +1 -1
  85. package/dist/models/operations/meters.d.ts +0 -1
  86. package/dist/models/operations/meters.js +1 -1
  87. package/dist/models/operations/planAddons.d.ts +0 -1
  88. package/dist/models/operations/planAddons.js +1 -1
  89. package/dist/models/operations/plans.d.ts +0 -1
  90. package/dist/models/operations/plans.js +1 -1
  91. package/dist/models/operations/subscriptions.d.ts +0 -1
  92. package/dist/models/operations/subscriptions.js +1 -1
  93. package/dist/models/operations/tax.d.ts +0 -1
  94. package/dist/models/operations/tax.js +1 -1
  95. package/dist/models/schemas.d.ts +11651 -6090
  96. package/dist/models/schemas.js +991 -468
  97. package/dist/models/types.d.ts +941 -810
  98. package/dist/models/types.js +1 -1
  99. package/dist/sdk/addons.d.ts +60 -1
  100. package/dist/sdk/addons.js +63 -1
  101. package/dist/sdk/apps.d.ts +68 -2
  102. package/dist/sdk/apps.js +81 -2
  103. package/dist/sdk/billing.d.ts +57 -1
  104. package/dist/sdk/billing.js +60 -1
  105. package/dist/sdk/customers.d.ts +211 -2
  106. package/dist/sdk/customers.js +222 -2
  107. package/dist/sdk/defaults.d.ts +10 -1
  108. package/dist/sdk/defaults.js +11 -1
  109. package/dist/sdk/entitlements.d.ts +5 -1
  110. package/dist/sdk/entitlements.js +6 -1
  111. package/dist/sdk/events.d.ts +25 -1
  112. package/dist/sdk/events.js +28 -1
  113. package/dist/sdk/features.d.ts +53 -1
  114. package/dist/sdk/features.js +56 -1
  115. package/dist/sdk/internal.d.ts +328 -0
  116. package/dist/sdk/internal.js +404 -0
  117. package/dist/sdk/invoices.d.ts +5 -2
  118. package/dist/sdk/invoices.js +13 -2
  119. package/dist/sdk/llmCost.d.ts +57 -1
  120. package/dist/sdk/llmCost.js +62 -1
  121. package/dist/sdk/meters.d.ts +64 -1
  122. package/dist/sdk/meters.js +67 -1
  123. package/dist/sdk/planAddons.d.ts +46 -1
  124. package/dist/sdk/planAddons.js +49 -1
  125. package/dist/sdk/plans.d.ts +60 -1
  126. package/dist/sdk/plans.js +63 -1
  127. package/dist/sdk/sdk.d.ts +9 -13
  128. package/dist/sdk/sdk.js +11 -20
  129. package/dist/sdk/subscriptions.d.ts +72 -3
  130. package/dist/sdk/subscriptions.js +77 -5
  131. package/dist/sdk/tax.d.ts +34 -1
  132. package/dist/sdk/tax.js +37 -1
  133. package/package.json +30 -6
  134. package/dist/sdk/currencies.d.ts +0 -12
  135. package/dist/sdk/currencies.js +0 -21
  136. package/dist/sdk/governance.d.ts +0 -9
  137. package/dist/sdk/governance.js +0 -12
@@ -0,0 +1,56 @@
1
+ import { type RequestOptions, type Result } from './types.js';
2
+ export declare class PaginationLimitExceededError extends Error {
3
+ constructor(limit: number);
4
+ }
5
+ interface PageNumberEnvelope<TItem> {
6
+ data: TItem[];
7
+ meta: {
8
+ page: {
9
+ number: number;
10
+ size: number;
11
+ total: number;
12
+ };
13
+ };
14
+ }
15
+ interface PageNumberRequest {
16
+ page?: {
17
+ number?: number;
18
+ size?: number;
19
+ };
20
+ }
21
+ /**
22
+ * Iterates every item of a page-number-paginated list operation, advancing
23
+ * `page.number` from wherever the caller's own request starts. Every other
24
+ * field on `request` — filters, sort, page.size — is sent unchanged on every
25
+ * page fetch; only the page number advances. Stops on a page shorter than
26
+ * the server's own reported `size` (including an empty page) or once the
27
+ * running item count reaches the server's reported `total`, whichever comes
28
+ * first — so a final page that exactly fills `total` does not trigger one
29
+ * more, empty request.
30
+ */
31
+ export declare function paginatePages<TItem, TReq extends PageNumberRequest>(fetchPage: (req: TReq, options?: RequestOptions) => Promise<Result<PageNumberEnvelope<TItem>>>, request: TReq, options?: RequestOptions): AsyncGenerator<TItem, void, undefined>;
32
+ interface CursorEnvelope<TItem> {
33
+ data: TItem[];
34
+ meta: {
35
+ page: {
36
+ next: string | null;
37
+ };
38
+ };
39
+ }
40
+ interface CursorRequest {
41
+ page?: {
42
+ after?: string;
43
+ before?: string;
44
+ size?: number;
45
+ };
46
+ }
47
+ /**
48
+ * Iterates every item of a cursor-paginated list operation, following
49
+ * `meta.page.next` until the server stops returning one. Despite carrying a
50
+ * `format: uri` annotation in the spec, `next` is the opaque cursor token the
51
+ * API expects back verbatim in `page.after` on the following request — not a
52
+ * URI to fetch directly. Every other field on `request` is sent unchanged on
53
+ * every page fetch; only `page.after` advances.
54
+ */
55
+ export declare function paginateCursor<TItem, TReq extends CursorRequest>(fetchPage: (req: TReq, options?: RequestOptions) => Promise<Result<CursorEnvelope<TItem>>>, request: TReq, options?: RequestOptions): AsyncGenerator<TItem, void, undefined>;
56
+ export {};
@@ -0,0 +1,60 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+ import { unwrap } from './types.js';
3
+ // A misbehaving server — inconsistent `meta.page.total`/`size`, or a
4
+ // `meta.page.next` cursor that never resolves to an empty page — would
5
+ // otherwise make these generators loop forever. 10,000 pages is far beyond
6
+ // any real OpenMeter list, so hitting it means the server's pagination
7
+ // contract broke, not that the caller has a legitimately large list.
8
+ const MAX_PAGINATION_PAGES = 10_000;
9
+ export class PaginationLimitExceededError extends Error {
10
+ constructor(limit) {
11
+ super(`pagination exceeded the maximum of ${limit} pages; the server may be returning inconsistent pagination metadata`);
12
+ this.name = 'PaginationLimitExceededError';
13
+ }
14
+ }
15
+ /**
16
+ * Iterates every item of a page-number-paginated list operation, advancing
17
+ * `page.number` from wherever the caller's own request starts. Every other
18
+ * field on `request` — filters, sort, page.size — is sent unchanged on every
19
+ * page fetch; only the page number advances. Stops on a page shorter than
20
+ * the server's own reported `size` (including an empty page) or once the
21
+ * running item count reaches the server's reported `total`, whichever comes
22
+ * first — so a final page that exactly fills `total` does not trigger one
23
+ * more, empty request.
24
+ */
25
+ export async function* paginatePages(fetchPage, request, options) {
26
+ let req = request;
27
+ let seen = 0;
28
+ for (let page = 0; page < MAX_PAGINATION_PAGES; page++) {
29
+ const res = unwrap(await fetchPage(req, options));
30
+ yield* res.data;
31
+ seen += res.data.length;
32
+ const { number, size, total } = res.meta.page;
33
+ if (res.data.length === 0 || res.data.length < size || seen >= total) {
34
+ return;
35
+ }
36
+ req = { ...req, page: { ...req.page, number: number + 1 } };
37
+ }
38
+ throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES);
39
+ }
40
+ /**
41
+ * Iterates every item of a cursor-paginated list operation, following
42
+ * `meta.page.next` until the server stops returning one. Despite carrying a
43
+ * `format: uri` annotation in the spec, `next` is the opaque cursor token the
44
+ * API expects back verbatim in `page.after` on the following request — not a
45
+ * URI to fetch directly. Every other field on `request` is sent unchanged on
46
+ * every page fetch; only `page.after` advances.
47
+ */
48
+ export async function* paginateCursor(fetchPage, request, options) {
49
+ let req = request;
50
+ for (let page = 0; page < MAX_PAGINATION_PAGES; page++) {
51
+ const res = unwrap(await fetchPage(req, options));
52
+ yield* res.data;
53
+ const next = res.meta.page.next;
54
+ if (!next) {
55
+ return;
56
+ }
57
+ req = { ...req, page: { ...req.page, after: next } };
58
+ }
59
+ throw new PaginationLimitExceededError(MAX_PAGINATION_PAGES);
60
+ }
@@ -1,3 +1,2 @@
1
1
  import { type Result } from './types.js';
2
2
  export declare function request<T>(fn: () => Promise<T>): Promise<Result<T>>;
3
- //# sourceMappingURL=request.d.ts.map
@@ -1,3 +1,4 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  import { ok, err } from './types.js';
2
3
  import { toError } from './to-error.js';
3
4
  export async function request(fn) {
@@ -8,4 +9,3 @@ export async function request(fn) {
8
9
  return err(await toError(e));
9
10
  }
10
11
  }
11
- //# sourceMappingURL=request.js.map
@@ -1,2 +1 @@
1
1
  export declare function toError(e: unknown): Promise<Error>;
2
- //# sourceMappingURL=to-error.d.ts.map
@@ -1,3 +1,4 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  import { HTTPError as KyHTTPError } from 'ky';
2
3
  import * as schemas from '../models/schemas.js';
3
4
  import { HTTPError } from '../models/errors.js';
@@ -13,4 +14,3 @@ export async function toError(e) {
13
14
  }
14
15
  return new Error(String(e));
15
16
  }
16
- //# sourceMappingURL=to-error.js.map
@@ -12,4 +12,3 @@ export type Result<T, E = Error> = {
12
12
  export declare function ok<T>(value: T): Result<T, never>;
13
13
  export declare function err<E>(error: E): Result<never, E>;
14
14
  export declare function unwrap<T, E>(result: Result<T, E>): T;
15
- //# sourceMappingURL=types.d.ts.map
package/dist/lib/types.js CHANGED
@@ -1,3 +1,4 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export function ok(value) {
2
3
  return { ok: true, value };
3
4
  }
@@ -10,4 +11,3 @@ export function unwrap(result) {
10
11
  }
11
12
  throw result.error;
12
13
  }
13
- //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "v1.0.0-beta.232";
@@ -0,0 +1,5 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+ // The committed value is a dev placeholder. The publish flow
3
+ // (`make -C api/spec publish-aip-sdk`) stamps the real release version here
4
+ // before `pnpm publish`, after `pnpm version` updates package.json.
5
+ export const SDK_VERSION = 'v1.0.0-beta.232';
@@ -1,6 +1,9 @@
1
1
  import type { output, ZodType } from 'zod';
2
2
  export declare function toCamelCase(name: string): string;
3
3
  export declare function toSnakeCase(name: string): string;
4
+ export declare class UnsafeIntegerError extends Error {
5
+ constructor(value: bigint);
6
+ }
4
7
  export type DateString = string & Record<never, never>;
5
8
  export type AcceptDateStrings<T> = T extends Date ? Date | DateString : T extends (infer E)[] ? AcceptDateStrings<E>[] : T extends object ? {
6
9
  [K in keyof T]: AcceptDateStrings<T[K]>;
@@ -9,10 +12,10 @@ export declare class DepthLimitExceededError extends Error {
9
12
  constructor();
10
13
  }
11
14
  export declare function toWire<T>(data: T, schema: ZodType): T;
15
+ export declare function toPathWire<T>(data: T, schema: ZodType): T;
12
16
  export declare function fromWire<S extends ZodType>(data: unknown, schema: S): output<S>;
13
17
  export declare class ValidationError extends Error {
14
18
  readonly issues: unknown;
15
19
  constructor(message: string, issues: unknown);
16
20
  }
17
21
  export declare function assertValid(schema: ZodType, data: unknown): void;
18
- //# sourceMappingURL=wire.d.ts.map
package/dist/lib/wire.js CHANGED
@@ -1,3 +1,4 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export function toCamelCase(name) {
2
3
  return name.replace(/_([a-z0-9])/g, (_m, c) => c.toUpperCase());
3
4
  }
@@ -27,6 +28,38 @@ function unwrap(schema) {
27
28
  /* v8 ignore next -- loop returns inside; reached only past the cycle guard */
28
29
  return current;
29
30
  }
31
+ // The default to write for a field the caller omitted, present only when the
32
+ // field is required-with-default in the spec — emitted as `.default(x)` with no
33
+ // `.optional()` in the wrapper chain (TypeSpec `field: T = x`, not
34
+ // `field?: T = x`). Such fields must be present on the wire (e.g. a CloudEvents
35
+ // envelope's `specversion`, which the server's parser rejects when absent), yet
36
+ // the generated request type allows omitting them so callers get the documented
37
+ // default for free — toWire is the layer that has to reconcile the two.
38
+ // Spec-optional fields (`.optional().default(x)`) return undefined and stay off
39
+ // the wire: their default is the server's to apply, and materializing them
40
+ // client-side would silently overwrite server state on update requests.
41
+ function requiredDefault(schema) {
42
+ let current = schema;
43
+ let found;
44
+ for (let i = 0; i < 100 && current; i++) {
45
+ const d = def(current);
46
+ /* v8 ignore next 3 -- every zod schema carries a def; guards the type only */
47
+ if (!d) {
48
+ break;
49
+ }
50
+ if (d.type === 'optional') {
51
+ return undefined;
52
+ }
53
+ if (d.type === 'default') {
54
+ found ??= { value: d.defaultValue };
55
+ }
56
+ else if (d.type !== 'nullable') {
57
+ break;
58
+ }
59
+ current = d.innerType;
60
+ }
61
+ return found;
62
+ }
30
63
  function shapeOf(schema) {
31
64
  return schema?.shape;
32
65
  }
@@ -60,7 +93,10 @@ function needsWalk(schema) {
60
93
  if (!d) {
61
94
  return false;
62
95
  }
63
- if (d.type === 'object' || d.type === 'record' || d.type === 'date') {
96
+ if (d.type === 'object' ||
97
+ d.type === 'record' ||
98
+ d.type === 'date' ||
99
+ d.type === 'bigint') {
64
100
  return true;
65
101
  }
66
102
  if (d.type === 'array') {
@@ -71,6 +107,18 @@ function needsWalk(schema) {
71
107
  }
72
108
  return false;
73
109
  }
110
+ // Thrown by toWire when a bigint value (an int64/uint64 field) is outside
111
+ // JSON's exactly-representable integer range. The wire carries int64 as a JSON
112
+ // number (the server decodes it into a Go int64), so a value beyond 2^53-1
113
+ // cannot be sent without silent precision corruption — a typed, immediate
114
+ // failure is the only honest option. request() catches it like any Error and
115
+ // surfaces it as Result.error.
116
+ export class UnsafeIntegerError extends Error {
117
+ constructor(value) {
118
+ super(`bigint value ${value} exceeds JSON's safe integer range and cannot be sent without precision loss`);
119
+ this.name = 'UnsafeIntegerError';
120
+ }
121
+ }
74
122
  const _literalsSurviveWidening = true;
75
123
  void _literalsSurviveWidening;
76
124
  // A handful of schemas are genuinely self-referential (e.g. the `and`/`or`
@@ -95,10 +143,15 @@ function walk(data, schema, dir, depth = 0) {
95
143
  // A Date can only ever mean its wire serialization, wherever it sits — a
96
144
  // typed date field, a record value, or an unknown-schema position. Wire→
97
145
  // public data never contains Date instances (it comes from JSON.parse), so
98
- // this only rewrites public→wire.
146
+ // this only rewrites public→wire. The same holds for bigint: JSON.parse
147
+ // never produces one, and public→wire it must become a JSON number wherever
148
+ // it sits.
99
149
  if (data instanceof Date) {
100
150
  return dir.mapDate(data);
101
151
  }
152
+ if (typeof data === 'bigint') {
153
+ return dir.mapBigInt(data);
154
+ }
102
155
  if (depth > MAX_WALK_DEPTH) {
103
156
  throw new DepthLimitExceededError();
104
157
  }
@@ -110,6 +163,12 @@ function walk(data, schema, dir, depth = 0) {
110
163
  if (d?.type === 'date') {
111
164
  return dir.mapDate(data);
112
165
  }
166
+ // A bigint-typed node revives the wire's JSON number into the public
167
+ // `bigint` (public→wire bigints were already mapped by the value check
168
+ // above, so only fromWire reaches a number here).
169
+ if (d?.type === 'bigint') {
170
+ return dir.mapBigInt(data);
171
+ }
113
172
  if (Array.isArray(data)) {
114
173
  // The schema may be the array itself or a union with an array variant
115
174
  // (e.g. a single-or-batch body `T | T[]`); resolve the element schema from
@@ -142,6 +201,9 @@ function walk(data, schema, dir, depth = 0) {
142
201
  const valueSchema = needsWalk(d.valueType) ? d.valueType : undefined;
143
202
  const out = Object.create(null);
144
203
  for (const [key, value] of Object.entries(record)) {
204
+ if (dir.omitUndefinedObjectEntries && value === undefined) {
205
+ continue;
206
+ }
145
207
  out[key] = valueSchema ? walk(value, valueSchema, dir, depth + 1) : value;
146
208
  }
147
209
  Object.setPrototypeOf(out, Object.prototype);
@@ -164,6 +226,9 @@ function walk(data, schema, dir, depth = 0) {
164
226
  // loop reassigning `out`'s own prototype instead of adding a visible key.
165
227
  const out = Object.create(null);
166
228
  for (const [key, value] of Object.entries(record)) {
229
+ if (dir.omitUndefinedObjectEntries && value === undefined) {
230
+ continue;
231
+ }
167
232
  const fieldSchema = fieldFor(shape, key);
168
233
  // Keys the schema does not declare are dropped, so the result matches the
169
234
  // typed shape exactly (a server-added field has no place in the type).
@@ -172,6 +237,20 @@ function walk(data, schema, dir, depth = 0) {
172
237
  }
173
238
  out[dir.rename(key)] = walk(value, fieldSchema, dir, depth + 1);
174
239
  }
240
+ if (dir.applyDefaults) {
241
+ // Shape keys are generated camelCase identifiers (never data-controlled),
242
+ // so direct indexing into `record` is safe here. Runs after the data loop
243
+ // so an explicit `key: undefined` entry is also replaced by the default.
244
+ for (const [key, fieldSchema] of Object.entries(shape)) {
245
+ if (record[key] !== undefined) {
246
+ continue;
247
+ }
248
+ const dflt = requiredDefault(fieldSchema);
249
+ if (dflt !== undefined) {
250
+ out[dir.rename(key)] = walk(dflt.value, fieldSchema, dir, depth + 1);
251
+ }
252
+ }
253
+ }
175
254
  Object.setPrototypeOf(out, Object.prototype);
176
255
  return out;
177
256
  }
@@ -262,21 +341,54 @@ const toWireDirection = {
262
341
  rename: toSnakeCase,
263
342
  discriminatorKey: (camelKey) => camelKey,
264
343
  mapDate: (value) => (value instanceof Date ? value.toISOString() : value),
344
+ mapBigInt: (value) => {
345
+ if (typeof value !== 'bigint') {
346
+ return value;
347
+ }
348
+ if (value > BigInt(Number.MAX_SAFE_INTEGER) ||
349
+ value < -BigInt(Number.MAX_SAFE_INTEGER)) {
350
+ throw new UnsafeIntegerError(value);
351
+ }
352
+ return Number(value);
353
+ },
354
+ applyDefaults: true,
355
+ omitUndefinedObjectEntries: true,
356
+ };
357
+ // Path binding names are transport metadata, not JSON object member names, so
358
+ // they must remain exactly as declared while their values receive the same
359
+ // Date/bigint/default mapping used by request bodies and query parameters.
360
+ const toPathWireDirection = {
361
+ ...toWireDirection,
362
+ rename: (key) => key,
265
363
  };
266
364
  const fromWireDirection = {
267
365
  rename: toCamelCase,
268
366
  discriminatorKey: (camelKey) => toSnakeCase(camelKey),
269
367
  mapDate: (value) => (typeof value === 'string' ? new Date(value) : value),
368
+ mapBigInt: (value) => typeof value === 'number' && Number.isInteger(value)
369
+ ? BigInt(value)
370
+ : value,
371
+ applyDefaults: false,
372
+ omitUndefinedObjectEntries: false,
270
373
  };
271
374
  // Rewrite a request body or query object from the camelCase public shape to the
272
375
  // snake_case wire shape, driven by its schema. Record keys (label/dimension names)
273
- // are preserved; `Date` values serialize to RFC 3339 strings. The return is typed
274
- // as the input `T` so call sites stay cast-free (the runtime object has snake keys
275
- // and wire-encoded dates, but the value is write-only — it flows straight into
276
- // `json:`/`toURLSearchParams`, both of which accept any object).
376
+ // are preserved; `Date` values serialize to RFC 3339 strings; `bigint` values
377
+ // (int64 fields) become JSON numbers; omitted required-with-default fields are
378
+ // filled with their declared default (see requiredDefault); explicit undefined
379
+ // object/record entries are omitted just as JSON.stringify would omit them. The
380
+ // return is typed as the input `T` so call sites stay cast-free (the runtime object
381
+ // has snake keys and wire-encoded dates, but the value is write-only — it flows
382
+ // straight into `json:`/`toURLSearchParams`, both of which accept any object).
277
383
  export function toWire(data, schema) {
278
384
  return walk(data, schema, toWireDirection);
279
385
  }
386
+ // Rewrite path-parameter values to their transport representation without
387
+ // renaming the path binding keys. The returned object is subsequently validated
388
+ // against the generated `…PathParamsWire` schema and URL-encoded by the func.
389
+ export function toPathWire(data, schema) {
390
+ return walk(data, schema, toPathWireDirection);
391
+ }
280
392
  // Rewrite a response body from the snake_case wire shape to the camelCase public
281
393
  // shape: renames keys and revives RFC 3339 strings into `Date`s at date-typed
282
394
  // nodes — never applies defaults or any other coercion. The result is the
@@ -309,4 +421,3 @@ export function assertValid(schema, data) {
309
421
  throw new ValidationError('schema validation failed', result.error.issues);
310
422
  }
311
423
  }
312
- //# sourceMappingURL=wire.js.map
@@ -5,12 +5,23 @@ export declare class HTTPError extends Error {
5
5
  title: string;
6
6
  status: number;
7
7
  url: string;
8
+ retryAfter: number | undefined;
8
9
  protected __raw?: Record<string, unknown> | undefined;
9
- constructor(message: string, type: string, title: string, status: number, url: string, __raw?: Record<string, unknown> | undefined);
10
+ constructor(message: string, type: string, title: string, status: number, url: string, retryAfter: number | undefined, __raw?: Record<string, unknown> | undefined);
10
11
  static fromResponse(resp: {
11
12
  response: Response;
12
13
  error?: z.infer<typeof schemas.baseError>;
13
14
  }): HTTPError;
15
+ /**
16
+ * The `invalid_parameters` problem-detail extension member, present on Bad
17
+ * Request (400) responses. Typed from the schema, not runtime-validated
18
+ * (like the rest of the SDK, this trusts the server rather than rejecting
19
+ * additive fields) — `undefined` when the response didn't carry one.
20
+ */
21
+ get invalidParameters(): z.infer<typeof schemas.invalidParameters> | undefined;
22
+ /**
23
+ * Escape hatch for problem-detail extension members without a typed
24
+ * accessor above.
25
+ */
14
26
  getField(key: string): unknown;
15
27
  }
16
- //# sourceMappingURL=errors.d.ts.map
@@ -1,28 +1,55 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
2
+ // Retry-After is either delta-seconds (an integer) or an HTTP-date. Only the
3
+ // delta-seconds form is parsed; HTTP-date values yield undefined rather than
4
+ // a parsed Date, keeping the public type a plain number.
5
+ function parseRetryAfter(header) {
6
+ if (header === null) {
7
+ return undefined;
8
+ }
9
+ const trimmed = header.trim();
10
+ return /^\d+$/.test(trimmed) ? Number(trimmed) : undefined;
11
+ }
1
12
  export class HTTPError extends Error {
2
13
  type;
3
14
  title;
4
15
  status;
5
16
  url;
17
+ retryAfter;
6
18
  __raw;
7
- constructor(message, type, title, status, url, __raw) {
19
+ constructor(message, type, title, status, url, retryAfter, __raw) {
8
20
  super(message);
9
21
  this.type = type;
10
22
  this.title = title;
11
23
  this.status = status;
12
24
  this.url = url;
25
+ this.retryAfter = retryAfter;
13
26
  this.__raw = __raw;
27
+ this.name = 'HTTPError';
14
28
  }
15
29
  static fromResponse(resp) {
30
+ const retryAfter = parseRetryAfter(resp.response.headers.get('Retry-After'));
16
31
  if (resp.response.headers
17
32
  .get('Content-Type')
18
33
  ?.includes('application/problem+json') &&
19
34
  resp.error) {
20
- return new HTTPError(resp.error.detail, resp.error.type ?? resp.error.title, resp.error.title, resp.error.status ?? resp.response.status, resp.response.url, resp.error);
35
+ return new HTTPError(resp.error.detail, resp.error.type ?? resp.error.title, resp.error.title, resp.error.status ?? resp.response.status, resp.response.url, retryAfter, resp.error);
21
36
  }
22
- return new HTTPError(`Request failed: ${resp.response.statusText}`, resp.response.statusText, resp.response.statusText, resp.response.status, resp.response.url);
37
+ return new HTTPError(`Request failed: ${resp.response.statusText}`, resp.response.statusText, resp.response.statusText, resp.response.status, resp.response.url, retryAfter);
38
+ }
39
+ /**
40
+ * The `invalid_parameters` problem-detail extension member, present on Bad
41
+ * Request (400) responses. Typed from the schema, not runtime-validated
42
+ * (like the rest of the SDK, this trusts the server rather than rejecting
43
+ * additive fields) — `undefined` when the response didn't carry one.
44
+ */
45
+ get invalidParameters() {
46
+ return this.__raw?.invalid_parameters;
23
47
  }
48
+ /**
49
+ * Escape hatch for problem-detail extension members without a typed
50
+ * accessor above.
51
+ */
24
52
  getField(key) {
25
53
  return this.__raw?.[key];
26
54
  }
27
55
  }
28
- //# sourceMappingURL=errors.js.map
@@ -47,4 +47,3 @@ export type PublishAddonRequest = {
47
47
  addonId: string;
48
48
  };
49
49
  export type PublishAddonResponse = Addon;
50
- //# sourceMappingURL=addons.d.ts.map
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=addons.js.map
@@ -1,7 +1,5 @@
1
- import { z } from 'zod';
2
- import * as schemas from '../schemas.js';
3
1
  import type { AcceptDateStrings } from '../../lib/wire.js';
4
- import type { AppPagePaginatedResponse } from '../types.js';
2
+ import type { App, AppCatalogItem, AppCatalogItemPagePaginatedResponse, AppPagePaginatedResponse, BillingInstallAppResponse, InstallAppRequest as InstallAppRequestBody, UpdateAppRequest as UpdateAppRequestBody } from '../types.js';
5
3
  export interface ListAppsQuery {
6
4
  /** Determines which page of the collection to retrieve. */
7
5
  page?: {
@@ -14,5 +12,28 @@ export type ListAppsResponse = AppPagePaginatedResponse;
14
12
  export type GetAppRequest = {
15
13
  appId: string;
16
14
  };
17
- export type GetAppResponse = z.output<typeof schemas.getAppResponse>;
18
- //# sourceMappingURL=apps.d.ts.map
15
+ export type GetAppResponse = App;
16
+ export type UninstallAppRequest = {
17
+ appId: string;
18
+ };
19
+ export type UninstallAppResponse = void;
20
+ export type UpdateAppRequest = AcceptDateStrings<{
21
+ appId: string;
22
+ body: UpdateAppRequestBody;
23
+ }>;
24
+ export type UpdateAppResponse = App;
25
+ export interface ListAppCatalogQuery {
26
+ /** Determines which page of the collection to retrieve. */
27
+ page?: {
28
+ size?: number;
29
+ number?: number;
30
+ };
31
+ }
32
+ export type ListAppCatalogRequest = AcceptDateStrings<ListAppCatalogQuery>;
33
+ export type ListAppCatalogResponse = AppCatalogItemPagePaginatedResponse;
34
+ export type GetAppCatalogItemRequest = {
35
+ appType: string;
36
+ };
37
+ export type GetAppCatalogItemResponse = AppCatalogItem;
38
+ export type InstallAppRequest = AcceptDateStrings<InstallAppRequestBody>;
39
+ export type InstallAppResponse = BillingInstallAppResponse;
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=apps.js.map
@@ -24,4 +24,3 @@ export type DeleteBillingProfileRequest = {
24
24
  id: string;
25
25
  };
26
26
  export type DeleteBillingProfileResponse = void;
27
- //# sourceMappingURL=billing.d.ts.map
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=billing.js.map
@@ -22,11 +22,21 @@ export interface ListCurrenciesQuery {
22
22
  * To filter currencies by type add the following query param: filter[type]=custom
23
23
  */
24
24
  filter?: ListCurrenciesParamsFilter;
25
+ /**
26
+ * Expand the currencies returned in the response.
27
+ *
28
+ * To include the active and scheduled cost basis add: expand=cost_basis
29
+ */
30
+ expand?: 'cost_basis'[];
25
31
  }
26
32
  export type ListCurrenciesRequest = AcceptDateStrings<ListCurrenciesQuery>;
27
33
  export type ListCurrenciesResponse = CurrencyPagePaginatedResponse;
28
34
  export type CreateCustomCurrencyRequest = AcceptDateStrings<CreateCurrencyCustomRequest>;
29
35
  export type CreateCustomCurrencyResponse = CurrencyCustom;
36
+ export type GetCustomCurrencyRequest = {
37
+ currencyId: string;
38
+ };
39
+ export type GetCustomCurrencyResponse = CurrencyCustom;
30
40
  export interface ListCostBasesQuery {
31
41
  /**
32
42
  * Filter cost bases returned in the response.
@@ -50,4 +60,3 @@ export type CreateCostBasisRequest = AcceptDateStrings<{
50
60
  body: CreateCostBasisRequestBody;
51
61
  }>;
52
62
  export type CreateCostBasisResponse = CostBasis;
53
- //# sourceMappingURL=currencies.d.ts.map
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=currencies.js.map
@@ -1,7 +1,5 @@
1
- import { z } from 'zod';
2
- import * as schemas from '../schemas.js';
3
1
  import type { AcceptDateStrings } from '../../lib/wire.js';
4
- import type { AppCustomerData, AppStripeCreateCheckoutSessionResult, AppStripeCreateCustomerPortalSessionResult, ChargePagePaginatedResponse, CreateChargeFlatFeeRequest, CreateChargeUsageBasedRequest, CreateCreditAdjustmentRequest as CreateCreditAdjustmentRequestBody, CreateCreditGrantRequestInput, CreateCustomerRequest as CreateCustomerRequestBody, CreditAdjustment, CreditBalances, CreditGrant, CreditGrantPagePaginatedResponse, CreditTransactionPaginatedResponse, CursorPaginationQueryPage, Customer, CustomerData, CustomerPagePaginatedResponse, CustomerStripeCreateCheckoutSessionRequestInput, CustomerStripeCreateCustomerPortalSessionRequest, GetCreditBalanceParamsFilter, ListChargesParamsFilter, ListCreditGrantsParamsFilter, ListCreditTransactionsParamsFilter, ListCustomersParamsFilter, SortQueryInput, UpdateCreditGrantExternalSettlementRequest as UpdateCreditGrantExternalSettlementRequestBody, UpsertAppCustomerDataRequest, UpsertCustomerBillingDataRequest, UpsertCustomerRequest as UpsertCustomerRequestBody } from '../types.js';
2
+ import type { AppCustomerData, AppStripeCreateCheckoutSessionResult, AppStripeCreateCustomerPortalSessionResult, Charge, ChargePagePaginatedResponse, CreateChargeRequest, CreateCreditAdjustmentRequest as CreateCreditAdjustmentRequestBody, CreateCreditGrantRequestInput, CreateCustomerRequest as CreateCustomerRequestBody, CreditAdjustment, CreditBalances, CreditGrant, CreditGrantPagePaginatedResponse, CreditTransactionPaginatedResponse, CursorPaginationQueryPage, Customer, CustomerData, CustomerPagePaginatedResponse, CustomerStripeCreateCheckoutSessionRequestInput, CustomerStripeCreateCustomerPortalSessionRequest, GetCreditBalanceParamsFilter, ListChargesParamsFilter, ListCreditGrantsParamsFilter, ListCreditTransactionsParamsFilter, ListCustomersParamsFilter, SortQueryInput, UpdateCreditGrantExternalSettlementRequest as UpdateCreditGrantExternalSettlementRequestBody, UpsertAppCustomerDataRequest, UpsertCustomerBillingDataRequest, UpsertCustomerRequest as UpsertCustomerRequestBody, VoidCreditGrantRequestInput } from '../types.js';
5
3
  export type CreateCustomerRequest = AcceptDateStrings<CreateCustomerRequestBody>;
6
4
  export type CreateCustomerResponse = Customer;
7
5
  export type GetCustomerRequest = {
@@ -94,7 +92,8 @@ export interface GetCustomerCreditBalanceQuery {
94
92
  /**
95
93
  * Return the credit balance as of this timestamp.
96
94
  *
97
- * Defaults to the current time.
95
+ * Defaults to the current time. Historical responses return `live` as zero because
96
+ * live charge impacts are only available for current balances.
98
97
  */
99
98
  timestamp?: Date;
100
99
  filter?: GetCreditBalanceParamsFilter;
@@ -108,6 +107,12 @@ export type CreateCreditAdjustmentRequest = AcceptDateStrings<{
108
107
  body: CreateCreditAdjustmentRequestBody;
109
108
  }>;
110
109
  export type CreateCreditAdjustmentResponse = CreditAdjustment;
110
+ export type VoidCreditGrantRequest = AcceptDateStrings<{
111
+ customerId: string;
112
+ creditGrantId: string;
113
+ body: VoidCreditGrantRequestInput;
114
+ }>;
115
+ export type VoidCreditGrantResponse = CreditGrant;
111
116
  export type UpdateCreditGrantExternalSettlementRequest = AcceptDateStrings<{
112
117
  customerId: string;
113
118
  creditGrantId: string;
@@ -162,7 +167,6 @@ export type ListCustomerChargesRequest = AcceptDateStrings<ListCustomerChargesQu
162
167
  export type ListCustomerChargesResponse = ChargePagePaginatedResponse;
163
168
  export type CreateCustomerChargesRequest = AcceptDateStrings<{
164
169
  customerId: string;
165
- body: CreateChargeFlatFeeRequest | CreateChargeUsageBasedRequest;
170
+ body: CreateChargeRequest;
166
171
  }>;
167
- export type CreateCustomerChargesResponse = z.output<typeof schemas.createCustomerChargesResponse>;
168
- //# sourceMappingURL=customers.d.ts.map
172
+ export type CreateCustomerChargesResponse = Charge;
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=customers.js.map
@@ -4,4 +4,3 @@ export type GetOrganizationDefaultTaxCodesRequest = Record<string, never>;
4
4
  export type GetOrganizationDefaultTaxCodesResponse = OrganizationDefaultTaxCodes;
5
5
  export type UpdateOrganizationDefaultTaxCodesRequest = AcceptDateStrings<UpdateOrganizationDefaultTaxCodesRequestBody>;
6
6
  export type UpdateOrganizationDefaultTaxCodesResponse = OrganizationDefaultTaxCodes;
7
- //# sourceMappingURL=defaults.d.ts.map
@@ -1,2 +1,2 @@
1
+ // Code generated by @openmeter/typespec-typescript. DO NOT EDIT.
1
2
  export {};
2
- //# sourceMappingURL=defaults.js.map