@openmeter/client 1.0.0-beta-4ffb0202fcfc → 1.0.0-beta-be2666bd959f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export { Defaults } from './sdk/defaults.js';
18
18
  export { Governance } from './sdk/governance.js';
19
19
  export { Client } from './core.js';
20
20
  export { HTTPError } from './models/errors.js';
21
+ export { ValidationError, DepthLimitExceededError } from './lib/wire.js';
21
22
  export { ServerList, Regions } from './lib/config.js';
22
23
  export type { SDKOptions, Region, ServerVariables } from './lib/config.js';
23
24
  export type { Result, RequestOptions } from './lib/types.js';
@@ -40,5 +41,5 @@ export type * from './models/operations/addons.js';
40
41
  export type * from './models/operations/planAddons.js';
41
42
  export type * from './models/operations/defaults.js';
42
43
  export type * from './models/operations/governance.js';
43
- export type { Labels, CursorPaginationQueryPage, SortQuery, IngestedEventValidationError, CursorMetaPage, BaseError, PageMeta, QueryFilterString, AppStripeCheckoutSessionCustomTextParams, AppStripeCreateCustomerPortalSessionOptions, CreateLabels, TaxConfigStripe, TaxConfigExternalInvoicing, ChargeFlatFeeDiscounts, PriceFree, RateCardStaticEntitlement, RateCardBooleanEntitlement, WorkflowCollectionAlignmentSubscription, WorkflowPaymentChargeAutomaticallySettings, WorkflowPaymentSendInvoiceSettings, InvoiceExternalReferences, InvoiceAvailableActionDetails, InvoiceWorkflowInvoicingSettings, InvoiceLineExternalReferences, LlmCostProvider, LlmCostModel, ProductCatalogValidationError, GovernanceQueryRequestCustomers, GovernanceQueryRequestFeatures, QueryFilterInteger, QueryFilterFloat, QueryFilterBoolean, PagePaginationQuery, PublicLabels, SystemAccountAccessToken, PersonalAccessToken, KonnectAccessToken, UpdateMeterRequest, AppCustomerDataStripe, AppCustomerDataExternalInvoicing, CurrencyFiat, ListCostBasesParamsFilter, CurrencyAmount, PriceFlat, PriceUnit, RateCardDiscounts, Totals, SpendCommitments, InvoiceLineCreditsApplied, FeatureManualUnitCost, FeatureLlmUnitCostPricing, LlmCostModelPricing, QueryFilterNumeric, CursorPaginationQuery, ListMetersParamsFilter, ListLlmCostPricesParamsFilter, LabelsFieldFilter, CustomerReference, ProfileReference, CreateResourceReference, TaxCodeReference, CreditGrantInvoiceReference, BillingCustomerReference, SubscriptionReference, AddonReference, FeatureReference, AppReference, ChargeReference, Event, MeterQueryRow, AppStripeCreateCustomerPortalSessionResult, ClosedPeriod, SubscriptionAddonTimelineSegment, CostBasis, CreateCostBasisRequest, FeatureCostQueryRow, Resource, ResourceImmutable, QueryFilterDateTime, CursorMeta, InvalidParameterStandard, InvalidParameterMinimumLength, InvalidParameterMaximumLength, InvalidParameterChoiceItem, InvalidParameterDependentItem, Unauthorized, Forbidden, NotFound, Gone, Conflict, PayloadTooLarge, UnsupportedMediaType, UnprocessableContent, TooManyRequests, Internal, NotImplemented, NotAvailable, CreateCreditGrantFilters, CreditGrantFilters, UpsertPlanAddonRequest, ResourceWithKey, CreateMeterRequest, Meter, PaginatedMeta, QueryFilterStringMapItem, CustomerKeyReference, CustomerUsageAttribution, Address, AppStripeCreateCheckoutSessionCustomerUpdate, AppStripeCreateCheckoutSessionConsentCollectionPaymentMethodReuseAgreement, AppStripeCreateCheckoutSessionTaxIdCollection, AppStripeCreateCheckoutSessionResult, CustomerStripeCreateCustomerPortalSessionRequest, EntitlementAccessResult, CreateCreditGrantPurchase, RateCardMeteredEntitlement, RecurringPeriod, CreditGrantPurchase, UpdateCreditGrantExternalSettlementRequest, ListCreditGrantsParamsFilter, GetCreditBalanceParamsFilter, ListChargesParamsFilter, ListPlansParamsFilter, SubscriptionCreate, RateCardProrationConfiguration, Subscription, UnitConfig, AppCatalogItem, TaxCodeAppMapping, PartyTaxIdentity, WorkflowInvoicingSettings, InvoiceValidationIssue, InvoiceAvailableActions, InvoiceLineAmountDiscount, InvoiceLineUsageDiscount, InvoiceLineBaseDiscount, ListCurrenciesParamsFilter, CurrencyCustom, CreateCurrencyCustomRequest, GovernanceQueryRequest, GovernanceFeatureAccessReason, GovernanceQueryError, AppCustomerData, UpsertAppCustomerDataRequest, CreditAdjustment, CreditBalance, CreateCreditAdjustmentRequest, ListCreditTransactionsParamsFilter, CreditTransaction, PriceTier, ChargeTotals, FeatureLlmUnitCost, LlmCostPrice, LlmCostOverrideCreate, ListCustomersParamsFilter, ListSubscriptionsParamsFilter, ListFeatureParamsFilter, ListAddonsParamsFilter, CreateCreditGrantTaxConfig, CreditGrantTaxConfig, TaxConfig, RateCardTaxConfig, OrganizationDefaultTaxCodes, UpdateOrganizationDefaultTaxCodesRequest, PlanAddon, CreatePlanAddonRequest, ProfileAppReferences, InvoiceWorkflowAppsReferences, ListEventsParamsFilter, ListInvoicesParamsFilter, ResourceFilters, FieldFilters, IngestedEvent, MeterQueryResult, FeatureCostQueryResult, MeterPagePaginatedResponse, CostBasisPagePaginatedResponse, MeterQueryFilters, FeatureMeterReference, CreateCustomerRequest, Customer, UpsertCustomerRequest, PartyAddresses, InvoiceCustomer, AppStripeCreateCheckoutSessionConsentCollection, ListCustomerEntitlementAccessResponseData, WorkflowCollectionAlignmentAnchored, ChargeFlatFeeSystemIntent, SubscriptionPagePaginatedResponse, SubscriptionChangeResponse, SubscriptionCancel, SubscriptionChange, CreateSubscriptionAddonRequest, InvoiceUsageQuantityDetail, AppStripe, AppSandbox, AppExternalInvoicing, CreateTaxCodeRequest, TaxCode, UpsertTaxCodeRequest, InvoiceWorkflow, InvoiceStatusDetails, InvoiceLineDiscounts, GovernanceFeatureAccess, CustomerData, UpsertCustomerBillingDataRequest, CreditBalances, CreditTransactionPaginatedResponse, PriceGraduated, PriceVolume, PricePagePaginatedResponse, CreateCreditGrantRequest, CreditGrant, CreateChargeFlatFeeRequest, WorkflowTaxSettings, PlanAddonPagePaginatedResponse, IngestedEventPaginatedResponse, InvalidParameters, MeterQueryRequest, CustomerPagePaginatedResponse, Party, Supplier, AppStripeCreateCheckoutSessionRequestOptions, TaxCodePagePaginatedResponse, InvoiceWorkflowSettings, InvoiceDetailedLine, CurrencyPagePaginatedResponse, GovernanceQueryResult, Feature, CreateFeatureRequest, UpdateFeatureRequest, CreditGrantPagePaginatedResponse, BadRequest, InvoiceBase, CustomerStripeCreateCheckoutSessionRequest, WorkflowCollectionSettings, AppPagePaginatedResponse, ProfileApps, GovernanceQueryResponse, ChargeFlatFee, ChargeUsageBasedSystemIntent, CreateChargeUsageBasedRequest, RateCard, InvoiceLineRateCard, FeaturePagePaginatedResponse, Workflow, ChargeUsageBased, SubscriptionAddonRateCard, PlanPhase, Addon, CreateAddonRequest, UpsertAddonRequest, InvoiceStandardLine, Profile, CreateBillingProfileRequest, UpsertBillingProfileRequest, SubscriptionAddon, Plan, CreatePlanRequest, UpsertPlanRequest, AddonPagePaginatedResponse, ProfilePagePaginatedResponse, ChargePagePaginatedResponse, SubscriptionAddonPagePaginatedResponse, PlanPagePaginatedResponse, InvoiceStandard, InvoicePagePaginatedResponse, SortQueryInput, BaseErrorInput, WorkflowPaymentSendInvoiceSettingsInput, InvoiceWorkflowInvoicingSettingsInput, EventInput, UnauthorizedInput, ForbiddenInput, NotFoundInput, GoneInput, ConflictInput, PayloadTooLargeInput, UnsupportedMediaTypeInput, UnprocessableContentInput, TooManyRequestsInput, InternalInput, NotImplementedInput, NotAvailableInput, AppStripeCreateCheckoutSessionCustomerUpdateInput, AppStripeCreateCheckoutSessionTaxIdCollectionInput, CreateCreditGrantPurchaseInput, RateCardMeteredEntitlementInput, CreditGrantPurchaseInput, UnitConfigInput, WorkflowInvoicingSettingsInput, GovernanceQueryRequestInput, IngestedEventInput, SubscriptionCancelInput, InvoiceUsageQuantityDetailInput, InvoiceWorkflowInput, CreateCreditGrantRequestInput, CreditGrantInput, WorkflowTaxSettingsInput, IngestedEventPaginatedResponseInput, MeterQueryRequestInput, AppStripeCreateCheckoutSessionRequestOptionsInput, InvoiceWorkflowSettingsInput, InvoiceDetailedLineInput, CreditGrantPagePaginatedResponseInput, BadRequestInput, CustomerStripeCreateCheckoutSessionRequestInput, WorkflowCollectionSettingsInput, RateCardInput, WorkflowInput, SubscriptionAddonRateCardInput, PlanPhaseInput, AddonInput, CreateAddonRequestInput, UpsertAddonRequestInput, InvoiceStandardLineInput, ProfileInput, CreateBillingProfileRequestInput, UpsertBillingProfileRequestInput, SubscriptionAddonInput, PlanInput, CreatePlanRequestInput, UpsertPlanRequestInput, AddonPagePaginatedResponseInput, ProfilePagePaginatedResponseInput, SubscriptionAddonPagePaginatedResponseInput, PlanPagePaginatedResponseInput, InvoiceStandardInput, InvoicePagePaginatedResponseInput, } from './models/types.js';
44
+ export type { Labels, CursorPaginationQueryPage, SortQuery, IngestedEventValidationError, CursorMetaPage, BaseError, PageMeta, QueryFilterString, AppStripeCheckoutSessionCustomTextParams, AppStripeCreateCustomerPortalSessionOptions, CreateLabels, TaxConfigStripe, TaxConfigExternalInvoicing, ChargeFlatFeeDiscounts, PriceFree, RateCardStaticEntitlement, RateCardBooleanEntitlement, WorkflowCollectionAlignmentSubscription, WorkflowPaymentChargeAutomaticallySettings, WorkflowPaymentSendInvoiceSettings, InvoiceExternalReferences, InvoiceAvailableActionDetails, InvoiceWorkflowInvoicingSettings, InvoiceLineExternalReferences, UpdateLabels, UpdateBillingInvoiceWorkflowInvoicingSettings, UpdateBillingWorkflowPaymentChargeAutomaticallySettings, UpdateBillingWorkflowPaymentSendInvoiceSettings, UpdatePriceFree, LlmCostProvider, LlmCostModel, ProductCatalogValidationError, GovernanceQueryRequestCustomers, GovernanceQueryRequestFeatures, QueryFilterInteger, QueryFilterFloat, QueryFilterBoolean, PagePaginationQuery, PublicLabels, SystemAccountAccessToken, PersonalAccessToken, KonnectAccessToken, UpdateMeterRequest, AppCustomerDataStripe, AppCustomerDataExternalInvoicing, CurrencyFiat, ListCostBasesParamsFilter, CurrencyAmount, PriceFlat, PriceUnit, RateCardDiscounts, Totals, SpendCommitments, InvoiceLineCreditsApplied, UpdatePriceFlat, UpdatePriceUnit, UpdateDiscounts, FeatureManualUnitCost, FeatureLlmUnitCostPricing, LlmCostModelPricing, QueryFilterNumeric, CursorPaginationQuery, ListMetersParamsFilter, ListLlmCostPricesParamsFilter, LabelsFieldFilter, CustomerReference, ProfileReference, CreateResourceReference, TaxCodeReference, CreditGrantInvoiceReference, BillingCustomerReference, SubscriptionReference, AddonReference, FeatureReference, AppReference, ChargeReference, UpdateResourceReference, Event, MeterQueryRow, AppStripeCreateCustomerPortalSessionResult, ClosedPeriod, SubscriptionAddonTimelineSegment, UpdateClosedPeriod, CostBasis, CreateCostBasisRequest, FeatureCostQueryRow, Resource, ResourceImmutable, QueryFilterDateTime, CursorMeta, InvalidParameterStandard, InvalidParameterMinimumLength, InvalidParameterMaximumLength, InvalidParameterChoiceItem, InvalidParameterDependentItem, Unauthorized, Forbidden, NotFound, Gone, Conflict, PayloadTooLarge, UnsupportedMediaType, UnprocessableContent, TooManyRequests, Internal, NotImplemented, NotAvailable, CreateCreditGrantFilters, CreditGrantFilters, UpsertPlanAddonRequest, ResourceWithKey, CreateMeterRequest, Meter, PaginatedMeta, QueryFilterStringMapItem, CustomerKeyReference, CustomerUsageAttribution, UpdateCustomerUsageAttribution, Address, UpdateAddress, AppStripeCreateCheckoutSessionCustomerUpdate, AppStripeCreateCheckoutSessionConsentCollectionPaymentMethodReuseAgreement, AppStripeCreateCheckoutSessionTaxIdCollection, AppStripeCreateCheckoutSessionResult, CustomerStripeCreateCustomerPortalSessionRequest, EntitlementAccessResult, CreateCreditGrantPurchase, RateCardMeteredEntitlement, RecurringPeriod, CreditGrantPurchase, UpdateCreditGrantExternalSettlementRequest, ListCreditGrantsParamsFilter, GetCreditBalanceParamsFilter, ListChargesParamsFilter, ListPlansParamsFilter, SubscriptionCreate, RateCardProrationConfiguration, Subscription, UnitConfig, AppCatalogItem, TaxCodeAppMapping, PartyTaxIdentity, UpdateBillingPartyTaxIdentity, WorkflowInvoicingSettings, InvoiceValidationIssue, InvoiceAvailableActions, InvoiceLineAmountDiscount, InvoiceLineUsageDiscount, InvoiceLineBaseDiscount, ListCurrenciesParamsFilter, CurrencyCustom, CreateCurrencyCustomRequest, GovernanceQueryRequest, GovernanceFeatureAccessReason, GovernanceQueryError, AppCustomerData, UpsertAppCustomerDataRequest, CreditAdjustment, CreditBalance, CreateCreditAdjustmentRequest, ListCreditTransactionsParamsFilter, CreditTransaction, PriceTier, ChargeTotals, UpdatePriceTier, FeatureLlmUnitCost, LlmCostPrice, LlmCostOverrideCreate, ListCustomersParamsFilter, ListSubscriptionsParamsFilter, ListFeatureParamsFilter, ListAddonsParamsFilter, CreateCreditGrantTaxConfig, CreditGrantTaxConfig, TaxConfig, RateCardTaxConfig, OrganizationDefaultTaxCodes, UpdateOrganizationDefaultTaxCodesRequest, PlanAddon, CreatePlanAddonRequest, ProfileAppReferences, InvoiceWorkflowAppsReferences, UpdateRateCardTaxConfig, ListEventsParamsFilter, ListInvoicesParamsFilter, ResourceFilters, FieldFilters, IngestedEvent, MeterQueryResult, FeatureCostQueryResult, MeterPagePaginatedResponse, CostBasisPagePaginatedResponse, MeterQueryFilters, FeatureMeterReference, CreateCustomerRequest, Customer, UpsertCustomerRequest, PartyAddresses, InvoiceCustomer, UpdateBillingPartyAddresses, UpdateInvoiceCustomer, AppStripeCreateCheckoutSessionConsentCollection, ListCustomerEntitlementAccessResponseData, WorkflowCollectionAlignmentAnchored, ChargeFlatFeeSystemIntent, SubscriptionPagePaginatedResponse, SubscriptionChangeResponse, SubscriptionCancel, SubscriptionChange, CreateSubscriptionAddonRequest, InvoiceUsageQuantityDetail, AppStripe, AppSandbox, AppExternalInvoicing, CreateTaxCodeRequest, TaxCode, UpsertTaxCodeRequest, InvoiceWorkflow, InvoiceStatusDetails, InvoiceLineDiscounts, UpdateBillingInvoiceWorkflow, GovernanceFeatureAccess, CustomerData, UpsertCustomerBillingDataRequest, CreditBalances, CreditTransactionPaginatedResponse, PriceGraduated, PriceVolume, UpdatePriceGraduated, UpdatePriceVolume, PricePagePaginatedResponse, CreateCreditGrantRequest, CreditGrant, CreateChargeFlatFeeRequest, WorkflowTaxSettings, PlanAddonPagePaginatedResponse, IngestedEventPaginatedResponse, InvalidParameters, MeterQueryRequest, CustomerPagePaginatedResponse, Party, Supplier, UpdateSupplier, AppStripeCreateCheckoutSessionRequestOptions, TaxCodePagePaginatedResponse, InvoiceWorkflowSettings, InvoiceDetailedLine, UpdateInvoiceWorkflowSettings, CurrencyPagePaginatedResponse, GovernanceQueryResult, Feature, CreateFeatureRequest, UpdateFeatureRequest, CreditGrantPagePaginatedResponse, BadRequest, InvoiceBase, CustomerStripeCreateCheckoutSessionRequest, WorkflowCollectionSettings, AppPagePaginatedResponse, ProfileApps, GovernanceQueryResponse, ChargeFlatFee, ChargeUsageBasedSystemIntent, CreateChargeUsageBasedRequest, RateCard, InvoiceLineRateCard, UpdateInvoiceLineRateCard, FeaturePagePaginatedResponse, Workflow, ChargeUsageBased, SubscriptionAddonRateCard, PlanPhase, Addon, CreateAddonRequest, UpsertAddonRequest, InvoiceStandardLine, UpdateInvoiceStandardLine, Profile, CreateBillingProfileRequest, UpsertBillingProfileRequest, SubscriptionAddon, Plan, CreatePlanRequest, UpsertPlanRequest, AddonPagePaginatedResponse, ProfilePagePaginatedResponse, ChargePagePaginatedResponse, SubscriptionAddonPagePaginatedResponse, PlanPagePaginatedResponse, InvoiceStandard, UpdateInvoiceStandardRequest, InvoicePagePaginatedResponse, SortQueryInput, BaseErrorInput, WorkflowPaymentSendInvoiceSettingsInput, InvoiceWorkflowInvoicingSettingsInput, UpdateBillingInvoiceWorkflowInvoicingSettingsInput, UpdateBillingWorkflowPaymentSendInvoiceSettingsInput, EventInput, UnauthorizedInput, ForbiddenInput, NotFoundInput, GoneInput, ConflictInput, PayloadTooLargeInput, UnsupportedMediaTypeInput, UnprocessableContentInput, TooManyRequestsInput, InternalInput, NotImplementedInput, NotAvailableInput, AppStripeCreateCheckoutSessionCustomerUpdateInput, AppStripeCreateCheckoutSessionTaxIdCollectionInput, CreateCreditGrantPurchaseInput, RateCardMeteredEntitlementInput, CreditGrantPurchaseInput, UnitConfigInput, WorkflowInvoicingSettingsInput, GovernanceQueryRequestInput, IngestedEventInput, SubscriptionCancelInput, InvoiceUsageQuantityDetailInput, InvoiceWorkflowInput, UpdateBillingInvoiceWorkflowInput, CreateCreditGrantRequestInput, CreditGrantInput, WorkflowTaxSettingsInput, IngestedEventPaginatedResponseInput, MeterQueryRequestInput, AppStripeCreateCheckoutSessionRequestOptionsInput, InvoiceWorkflowSettingsInput, InvoiceDetailedLineInput, UpdateInvoiceWorkflowSettingsInput, CreditGrantPagePaginatedResponseInput, BadRequestInput, CustomerStripeCreateCheckoutSessionRequestInput, WorkflowCollectionSettingsInput, RateCardInput, WorkflowInput, SubscriptionAddonRateCardInput, PlanPhaseInput, AddonInput, CreateAddonRequestInput, UpsertAddonRequestInput, InvoiceStandardLineInput, ProfileInput, CreateBillingProfileRequestInput, UpsertBillingProfileRequestInput, SubscriptionAddonInput, PlanInput, CreatePlanRequestInput, UpsertPlanRequestInput, AddonPagePaginatedResponseInput, ProfilePagePaginatedResponseInput, SubscriptionAddonPagePaginatedResponseInput, PlanPagePaginatedResponseInput, InvoiceStandardInput, UpdateInvoiceStandardRequestInput, InvoicePagePaginatedResponseInput, } from './models/types.js';
44
45
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export { Defaults } from './sdk/defaults.js';
18
18
  export { Governance } from './sdk/governance.js';
19
19
  export { Client } from './core.js';
20
20
  export { HTTPError } from './models/errors.js';
21
+ export { ValidationError, DepthLimitExceededError } from './lib/wire.js';
21
22
  export { ServerList, Regions } from './lib/config.js';
22
23
  export { encodePath, encodeSort, querySerializer, toURLSearchParams, } from './lib/encodings.js';
23
24
  export * as funcs from './funcs/index.js';
@@ -10,5 +10,14 @@ export interface SDKOptions extends Omit<Options, 'method'> {
10
10
  baseUrl: (typeof ServerList)[number] | URL | string;
11
11
  serverVariables?: ServerVariables;
12
12
  apiKey?: string | (() => string | Promise<string>);
13
+ /**
14
+ * Validate request bodies and response payloads against their schemas. Off by
15
+ * default: the SDK maps casing but does not validate, so additive server fields
16
+ * never break clients. When on, a request body or response that fails its schema
17
+ * (missing/wrong-typed field, unknown enum value) returns a failed Result whose
18
+ * `error` is a ValidationError (validation runs inside the SDK's request
19
+ * handling, so it never rejects/throws).
20
+ */
21
+ validate?: boolean;
13
22
  }
14
23
  //# sourceMappingURL=config.d.ts.map
@@ -4,5 +4,5 @@ export declare function toURLSearchParams(params: Record<string, unknown>): URLS
4
4
  export declare function encodeSort(sort: {
5
5
  by?: string;
6
6
  order?: 'asc' | 'desc';
7
- } | undefined): string | undefined;
7
+ } | undefined, encodeField?: (field: string) => string): string | undefined;
8
8
  //# sourceMappingURL=encodings.d.ts.map
@@ -41,16 +41,17 @@ export function toURLSearchParams(params) {
41
41
  }
42
42
  return search;
43
43
  }
44
- export function encodeSort(sort) {
44
+ export function encodeSort(sort, encodeField = (field) => field) {
45
45
  if (!sort?.by) {
46
46
  return undefined;
47
47
  }
48
+ const by = encodeField(sort.by);
48
49
  if (sort.order === 'desc') {
49
- return `${sort.by} desc`;
50
+ return `${by} desc`;
50
51
  }
51
52
  if (sort.order === 'asc') {
52
- return `${sort.by} asc`;
53
+ return `${by} asc`;
53
54
  }
54
- return sort.by;
55
+ return by;
55
56
  }
56
57
  //# sourceMappingURL=encodings.js.map
@@ -0,0 +1,14 @@
1
+ import type { output, ZodType } from 'zod';
2
+ export declare function toCamelCase(name: string): string;
3
+ export declare function toSnakeCase(name: string): string;
4
+ export declare class DepthLimitExceededError extends Error {
5
+ constructor();
6
+ }
7
+ export declare function toWire<T>(data: T, schema: ZodType): T;
8
+ export declare function fromWire<S extends ZodType>(data: unknown, schema: S): output<S>;
9
+ export declare class ValidationError extends Error {
10
+ readonly issues: unknown;
11
+ constructor(message: string, issues: unknown);
12
+ }
13
+ export declare function assertValid(schema: ZodType, data: unknown): void;
14
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1,256 @@
1
+ export function toCamelCase(name) {
2
+ return name.replace(/_([a-z0-9])/g, (_m, c) => c.toUpperCase());
3
+ }
4
+ export function toSnakeCase(name) {
5
+ return name.replace(/([A-Z])/g, (_m, c) => `_${c.toLowerCase()}`);
6
+ }
7
+ function def(schema) {
8
+ return schema?.def;
9
+ }
10
+ // Unwrap optional/nullable/default to the schema that describes the value's
11
+ // shape. These wrappers never change keys, so the walker looks through them
12
+ // before classifying a node.
13
+ function unwrap(schema) {
14
+ let current = schema;
15
+ for (let i = 0; i < 100 && current; i++) {
16
+ const d = def(current);
17
+ if (d &&
18
+ (d.type === 'optional' ||
19
+ d.type === 'nullable' ||
20
+ d.type === 'default') &&
21
+ d.innerType) {
22
+ current = d.innerType;
23
+ continue;
24
+ }
25
+ return current;
26
+ }
27
+ /* v8 ignore next -- loop returns inside; reached only past the cycle guard */
28
+ return current;
29
+ }
30
+ function shapeOf(schema) {
31
+ return schema?.shape;
32
+ }
33
+ // The element schema for array data: the schema's own element when it is an
34
+ // array, or the array variant's element when it is a union of T and T[]
35
+ // (the single-or-batch body shape).
36
+ function arrayElement(schema) {
37
+ const d = def(schema);
38
+ if (d?.type === 'array') {
39
+ return d.element;
40
+ }
41
+ if (d?.type === 'union') {
42
+ for (const option of d.options ?? []) {
43
+ const od = def(unwrap(option));
44
+ if (od?.type === 'array') {
45
+ return od.element;
46
+ }
47
+ }
48
+ }
49
+ return undefined;
50
+ }
51
+ // Whether a value schema carries renamable fields (object/record/array/union of
52
+ // such), so a record value is recursed only when it is model-shaped. Scalars,
53
+ // literals, unknown, and any are left untouched.
54
+ function hasRenamableShape(schema) {
55
+ const s = unwrap(schema);
56
+ const d = def(s);
57
+ /* v8 ignore next 3 -- a record always has a value schema; defensive only */
58
+ if (!d) {
59
+ return false;
60
+ }
61
+ if (d.type === 'object' || d.type === 'record') {
62
+ return true;
63
+ }
64
+ if (d.type === 'array') {
65
+ return hasRenamableShape(d.element);
66
+ }
67
+ if (d.type === 'union') {
68
+ return (d.options ?? []).some(hasRenamableShape);
69
+ }
70
+ return false;
71
+ }
72
+ // A handful of schemas are genuinely self-referential (e.g. the `and`/`or`
73
+ // legs of a filter tree), so nesting depth is bounded only by the DATA the
74
+ // server sends, not by the schema. Without a limit, a crafted or
75
+ // accidentally-deep response recurses until the JS engine throws a raw
76
+ // `RangeError: Maximum call stack size exceeded` — still caught by request()
77
+ // and surfaced as Result.error, but as an opaque native error instead of a
78
+ // typed one. 500 levels is far beyond any real filter/record/array nesting
79
+ // in the API today; it exists to fail predictably, not to constrain valid data.
80
+ const MAX_WALK_DEPTH = 500;
81
+ export class DepthLimitExceededError extends Error {
82
+ constructor() {
83
+ super(`wire mapping exceeded maximum nesting depth (${MAX_WALK_DEPTH})`);
84
+ this.name = 'DepthLimitExceededError';
85
+ }
86
+ }
87
+ function walk(data, schema, dir, depth = 0) {
88
+ if (data === null || data === undefined) {
89
+ return data;
90
+ }
91
+ if (depth > MAX_WALK_DEPTH) {
92
+ throw new DepthLimitExceededError();
93
+ }
94
+ const s = unwrap(schema);
95
+ const d = def(s);
96
+ if (Array.isArray(data)) {
97
+ // The schema may be the array itself or a union with an array variant
98
+ // (e.g. a single-or-batch body `T | T[]`); resolve the element schema from
99
+ // whichever applies so array items are still walked with their shape.
100
+ const element = arrayElement(s);
101
+ return data.map((item) => walk(item, element, dir, depth + 1));
102
+ }
103
+ if (typeof data !== 'object') {
104
+ return data;
105
+ }
106
+ const record = data;
107
+ if (d?.type === 'record') {
108
+ // Record keys are user data (label/dimension names) — preserved verbatim.
109
+ // Only the value is walked, and only when it is model-shaped. A null
110
+ // prototype avoids the `__proto__` key silently reassigning `out`'s own
111
+ // prototype instead of becoming a visible entry (user data may contain
112
+ // any key, including reserved object-literal property names). The
113
+ // prototype is restored once every key is a plain own property, so the
114
+ // returned object still behaves normally for consumers (instanceof,
115
+ // template literals) — `Object.prototype` itself was never touched.
116
+ const valueSchema = hasRenamableShape(d.valueType) ? d.valueType : undefined;
117
+ const out = Object.create(null);
118
+ for (const [key, value] of Object.entries(record)) {
119
+ out[key] = valueSchema ? walk(value, valueSchema, dir, depth + 1) : value;
120
+ }
121
+ Object.setPrototypeOf(out, Object.prototype);
122
+ return out;
123
+ }
124
+ if (d?.type === 'union') {
125
+ const variant = selectVariant(record, s, dir);
126
+ if (!variant) {
127
+ // No confident match: leave keys untransformed rather than guess.
128
+ return data;
129
+ }
130
+ return walk(data, variant, dir, depth + 1);
131
+ }
132
+ if (d?.type === 'object') {
133
+ const shape = shapeOf(s) ?? {};
134
+ // A null prototype avoids two failure modes from data-controlled keys
135
+ // like `__proto__`/`constructor`: (1) `fieldFor` below reading an
136
+ // inherited Object.prototype member instead of correctly treating the
137
+ // key as schema-undeclared, and (2) the assignment at the end of this
138
+ // loop reassigning `out`'s own prototype instead of adding a visible key.
139
+ const out = Object.create(null);
140
+ for (const [key, value] of Object.entries(record)) {
141
+ const fieldSchema = fieldFor(shape, key);
142
+ // Keys the schema does not declare are dropped, so the result matches the
143
+ // typed shape exactly (a server-added field has no place in the type).
144
+ if (fieldSchema === undefined) {
145
+ continue;
146
+ }
147
+ out[dir.rename(key)] = walk(value, fieldSchema, dir, depth + 1);
148
+ }
149
+ Object.setPrototypeOf(out, Object.prototype);
150
+ return out;
151
+ }
152
+ // Scalar or unknown schema: pass through untransformed.
153
+ return data;
154
+ }
155
+ // Resolve a data key to its field schema. The schema is camelCase-keyed; a
156
+ // wire→public data key is snake, so it is camelized to index the shape.
157
+ // Own-property checks (not `shape[key]`) so a data-controlled key like
158
+ // `__proto__` or `constructor` cannot resolve to an inherited
159
+ // Object.prototype member and be mistaken for a declared schema field.
160
+ function fieldFor(shape, dataKey) {
161
+ if (Object.hasOwn(shape, dataKey)) {
162
+ return shape[dataKey];
163
+ }
164
+ const camelKey = toCamelCase(dataKey);
165
+ return Object.hasOwn(shape, camelKey) ? shape[camelKey] : undefined;
166
+ }
167
+ function selectVariant(data, schema, dir) {
168
+ const d = def(schema);
169
+ const options = d?.options ?? [];
170
+ if (d?.discriminator && schema) {
171
+ // O(1) dispatch on the discriminator literal. The data key is the wire-name in
172
+ // fromWire (snake) and the public name in toWire (camel); the variant map is
173
+ // keyed by the literal value, which is identical in both directions.
174
+ const dataKey = dir.discriminatorKey(d.discriminator);
175
+ return variantsByDiscriminator(schema, d).get(data[dataKey]);
176
+ }
177
+ // Non-discriminated union: the codegen gate guarantees at most one object
178
+ // variant (it fails the build for a mapped union with two or more), so the single
179
+ // object-shaped option is unambiguous. Other variants (scalars, arrays) reach the
180
+ // walk through their own data-kind branches, not here.
181
+ return options.find((option) => def(unwrap(option))?.type === 'object');
182
+ }
183
+ // Memoized literal→variant map for a discriminated union, built once per schema.
184
+ const variantMapCache = new WeakMap();
185
+ function variantsByDiscriminator(schema, d) {
186
+ const cached = variantMapCache.get(schema);
187
+ if (cached) {
188
+ return cached;
189
+ }
190
+ const map = new Map();
191
+ for (const option of d.options ?? []) {
192
+ const shape = shapeOf(unwrap(option));
193
+ const literal = literalValue(shape?.[d.discriminator]);
194
+ if (literal !== undefined) {
195
+ map.set(literal, option);
196
+ }
197
+ }
198
+ variantMapCache.set(schema, map);
199
+ return map;
200
+ }
201
+ function literalValue(schema) {
202
+ const s = unwrap(schema);
203
+ if (def(s)?.type === 'literal') {
204
+ return s.value;
205
+ }
206
+ /* v8 ignore next -- a discriminated-union variant's discriminator is a literal */
207
+ return undefined;
208
+ }
209
+ const toWireDirection = {
210
+ rename: toSnakeCase,
211
+ discriminatorKey: (camelKey) => camelKey,
212
+ };
213
+ const fromWireDirection = {
214
+ rename: toCamelCase,
215
+ discriminatorKey: (camelKey) => toSnakeCase(camelKey),
216
+ };
217
+ // Rewrite a request body or query object from the camelCase public shape to the
218
+ // snake_case wire shape, driven by its schema. Record keys (label/dimension names)
219
+ // are preserved. The return is typed as the input `T` so call sites stay cast-free
220
+ // (the runtime object has snake keys, but the value is write-only — it flows
221
+ // straight into `json:`/`toURLSearchParams`, both of which accept any object).
222
+ export function toWire(data, schema) {
223
+ return walk(data, schema, toWireDirection);
224
+ }
225
+ // Rewrite a response body from the snake_case wire shape to the camelCase public
226
+ // shape. Renames keys only — never coerces values or applies defaults. The result
227
+ // is the schema's output shape: `walk` produces exactly the schema's known fields
228
+ // in camelCase, so the inferred `output<S>` type describes the runtime value (the
229
+ // same wire-trust boundary as a plain `.json<T>()`, with no `.parse()`).
230
+ export function fromWire(data, schema) {
231
+ return walk(data, schema, fromWireDirection);
232
+ }
233
+ // Thrown by assertValid when the optional `validate` client option is on and data
234
+ // fails its schema. request() catches it like any Error and surfaces it as
235
+ // Result.error.
236
+ export class ValidationError extends Error {
237
+ issues;
238
+ constructor(message, issues) {
239
+ super(message);
240
+ this.issues = issues;
241
+ this.name = 'ValidationError';
242
+ }
243
+ }
244
+ // Opt-in schema check used by the funcs (when the validate option is on) against
245
+ // the snake_case wire payload: the request body after toWire, the raw response
246
+ // before fromWire, each against its generated `…Wire` schema. It is a GATE, not a
247
+ // transform — the safeParse output (coercions/defaults) is discarded, so validation
248
+ // never mutates the payload or return value. Off by default; the SDK does not
249
+ // validate by default (additive server fields must not break clients).
250
+ export function assertValid(schema, data) {
251
+ const result = schema.safeParse(data);
252
+ if (!result.success) {
253
+ throw new ValidationError('schema validation failed', result.error.issues);
254
+ }
255
+ }
256
+ //# sourceMappingURL=wire.js.map
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import * as schemas from '../schemas.js';
3
- import type { InvoicePagePaginatedResponse, ListInvoicesParamsFilter, SortQueryInput } from '../types.js';
3
+ import type { InvoicePagePaginatedResponse, ListInvoicesParamsFilter, SortQueryInput, UpdateInvoiceStandardRequestInput } from '../types.js';
4
4
  export interface ListInvoicesQuery {
5
5
  /** Determines which page of the collection to retrieve. */
6
6
  page?: {
@@ -35,4 +35,9 @@ export type GetInvoiceRequest = {
35
35
  invoiceId: string;
36
36
  };
37
37
  export type GetInvoiceResponse = z.output<typeof schemas.getInvoiceResponse>;
38
+ export type UpdateInvoiceRequest = {
39
+ invoiceId: string;
40
+ body: UpdateInvoiceStandardRequestInput;
41
+ };
42
+ export type UpdateInvoiceResponse = z.output<typeof schemas.updateInvoiceResponse>;
38
43
  //# sourceMappingURL=invoices.d.ts.map
@@ -12,7 +12,7 @@ export interface ListTaxCodesQuery {
12
12
  number?: number;
13
13
  };
14
14
  /** Include deleted tax codes in the response. */
15
- include_deleted?: boolean;
15
+ includeDeleted?: boolean;
16
16
  }
17
17
  export type ListTaxCodesRequest = ListTaxCodesQuery;
18
18
  export type ListTaxCodesResponse = TaxCodePagePaginatedResponse;