@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.
- package/LICENSE +202 -0
- package/README.md +365 -76
- package/dist/core.d.ts +0 -1
- package/dist/core.js +11 -1
- package/dist/funcs/addons.d.ts +49 -1
- package/dist/funcs/addons.js +109 -12
- package/dist/funcs/apps.d.ts +55 -2
- package/dist/funcs/apps.js +179 -4
- package/dist/funcs/billing.d.ts +46 -1
- package/dist/funcs/billing.js +81 -8
- package/dist/funcs/currencies.d.ts +39 -2
- package/dist/funcs/currencies.js +93 -6
- package/dist/funcs/customers.d.ts +165 -2
- package/dist/funcs/customers.js +402 -40
- package/dist/funcs/defaults.d.ts +10 -1
- package/dist/funcs/defaults.js +11 -1
- package/dist/funcs/entitlements.d.ts +5 -1
- package/dist/funcs/entitlements.js +18 -4
- package/dist/funcs/events.d.ts +14 -1
- package/dist/funcs/events.js +18 -1
- package/dist/funcs/features.d.ts +42 -1
- package/dist/funcs/features.js +91 -10
- package/dist/funcs/governance.d.ts +14 -1
- package/dist/funcs/governance.js +15 -1
- package/dist/funcs/index.d.ts +0 -1
- package/dist/funcs/index.js +1 -1
- package/dist/funcs/invoices.d.ts +102 -2
- package/dist/funcs/invoices.js +247 -8
- package/dist/funcs/llmCost.d.ts +36 -1
- package/dist/funcs/llmCost.js +63 -6
- package/dist/funcs/meters.d.ts +53 -1
- package/dist/funcs/meters.js +113 -12
- package/dist/funcs/planAddons.d.ts +35 -1
- package/dist/funcs/planAddons.js +101 -18
- package/dist/funcs/plans.d.ts +49 -1
- package/dist/funcs/plans.js +109 -12
- package/dist/funcs/subscriptions.d.ts +59 -1
- package/dist/funcs/subscriptions.js +147 -18
- package/dist/funcs/tax.d.ts +25 -1
- package/dist/funcs/tax.js +60 -8
- package/dist/index.d.ts +4 -7
- package/dist/index.js +4 -6
- package/dist/lib/config.d.ts +2 -3
- package/dist/lib/config.js +1 -1
- package/dist/lib/encodings.d.ts +0 -1
- package/dist/lib/encodings.js +1 -1
- package/dist/lib/paginate.d.ts +56 -0
- package/dist/lib/paginate.js +60 -0
- package/dist/lib/request.d.ts +0 -1
- package/dist/lib/request.js +1 -1
- package/dist/lib/to-error.d.ts +0 -1
- package/dist/lib/to-error.js +1 -1
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/version.d.ts +1 -0
- package/dist/lib/version.js +5 -0
- package/dist/lib/wire.d.ts +4 -1
- package/dist/lib/wire.js +118 -7
- package/dist/models/errors.d.ts +13 -2
- package/dist/models/errors.js +31 -4
- package/dist/models/operations/addons.d.ts +0 -1
- package/dist/models/operations/addons.js +1 -1
- package/dist/models/operations/apps.d.ts +26 -5
- package/dist/models/operations/apps.js +1 -1
- package/dist/models/operations/billing.d.ts +0 -1
- package/dist/models/operations/billing.js +1 -1
- package/dist/models/operations/currencies.d.ts +10 -1
- package/dist/models/operations/currencies.js +1 -1
- package/dist/models/operations/customers.d.ts +11 -7
- package/dist/models/operations/customers.js +1 -1
- package/dist/models/operations/defaults.d.ts +0 -1
- package/dist/models/operations/defaults.js +1 -1
- package/dist/models/operations/entitlements.d.ts +0 -1
- package/dist/models/operations/entitlements.js +1 -1
- package/dist/models/operations/events.d.ts +0 -1
- package/dist/models/operations/events.js +1 -1
- package/dist/models/operations/features.d.ts +0 -1
- package/dist/models/operations/features.js +1 -1
- package/dist/models/operations/governance.d.ts +0 -1
- package/dist/models/operations/governance.js +1 -1
- package/dist/models/operations/invoices.d.ts +20 -7
- package/dist/models/operations/invoices.js +1 -1
- package/dist/models/operations/llmCost.d.ts +0 -1
- package/dist/models/operations/llmCost.js +1 -1
- package/dist/models/operations/meters.d.ts +0 -1
- package/dist/models/operations/meters.js +1 -1
- package/dist/models/operations/planAddons.d.ts +0 -1
- package/dist/models/operations/planAddons.js +1 -1
- package/dist/models/operations/plans.d.ts +0 -1
- package/dist/models/operations/plans.js +1 -1
- package/dist/models/operations/subscriptions.d.ts +0 -1
- package/dist/models/operations/subscriptions.js +1 -1
- package/dist/models/operations/tax.d.ts +0 -1
- package/dist/models/operations/tax.js +1 -1
- package/dist/models/schemas.d.ts +11651 -6090
- package/dist/models/schemas.js +991 -468
- package/dist/models/types.d.ts +941 -810
- package/dist/models/types.js +1 -1
- package/dist/sdk/addons.d.ts +60 -1
- package/dist/sdk/addons.js +63 -1
- package/dist/sdk/apps.d.ts +68 -2
- package/dist/sdk/apps.js +81 -2
- package/dist/sdk/billing.d.ts +57 -1
- package/dist/sdk/billing.js +60 -1
- package/dist/sdk/customers.d.ts +211 -2
- package/dist/sdk/customers.js +222 -2
- package/dist/sdk/defaults.d.ts +10 -1
- package/dist/sdk/defaults.js +11 -1
- package/dist/sdk/entitlements.d.ts +5 -1
- package/dist/sdk/entitlements.js +6 -1
- package/dist/sdk/events.d.ts +25 -1
- package/dist/sdk/events.js +28 -1
- package/dist/sdk/features.d.ts +53 -1
- package/dist/sdk/features.js +56 -1
- package/dist/sdk/internal.d.ts +328 -0
- package/dist/sdk/internal.js +404 -0
- package/dist/sdk/invoices.d.ts +5 -2
- package/dist/sdk/invoices.js +13 -2
- package/dist/sdk/llmCost.d.ts +57 -1
- package/dist/sdk/llmCost.js +62 -1
- package/dist/sdk/meters.d.ts +64 -1
- package/dist/sdk/meters.js +67 -1
- package/dist/sdk/planAddons.d.ts +46 -1
- package/dist/sdk/planAddons.js +49 -1
- package/dist/sdk/plans.d.ts +60 -1
- package/dist/sdk/plans.js +63 -1
- package/dist/sdk/sdk.d.ts +9 -13
- package/dist/sdk/sdk.js +11 -20
- package/dist/sdk/subscriptions.d.ts +72 -3
- package/dist/sdk/subscriptions.js +77 -5
- package/dist/sdk/tax.d.ts +34 -1
- package/dist/sdk/tax.js +37 -1
- package/package.json +30 -6
- package/dist/sdk/currencies.d.ts +0 -12
- package/dist/sdk/currencies.js +0 -21
- package/dist/sdk/governance.d.ts +0 -9
- 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
|
+
}
|
package/dist/lib/request.d.ts
CHANGED
package/dist/lib/request.js
CHANGED
|
@@ -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
|
package/dist/lib/to-error.d.ts
CHANGED
package/dist/lib/to-error.js
CHANGED
|
@@ -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
|
package/dist/lib/types.d.ts
CHANGED
package/dist/lib/types.js
CHANGED
|
@@ -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';
|
package/dist/lib/wire.d.ts
CHANGED
|
@@ -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' ||
|
|
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
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
//
|
|
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
|
package/dist/models/errors.d.ts
CHANGED
|
@@ -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
|
package/dist/models/errors.js
CHANGED
|
@@ -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
|
|
@@ -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 =
|
|
18
|
-
|
|
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;
|
|
@@ -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,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,
|
|
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:
|
|
170
|
+
body: CreateChargeRequest;
|
|
166
171
|
}>;
|
|
167
|
-
export type CreateCustomerChargesResponse =
|
|
168
|
-
//# sourceMappingURL=customers.d.ts.map
|
|
172
|
+
export type CreateCustomerChargesResponse = Charge;
|
|
@@ -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
|