From a6e00d2711112af1b764948b1f46ee79e626e4db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 17:14:00 +0000 Subject: [PATCH] feat(api)!: update SDKs to meteroid 0.1.0 BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/coupons`: added `#/components/schemas/CreditDiscount` to the `data/items/discount` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/coupons/{coupon_id}`: added `#/components/schemas/CreditDiscount` to the `discount` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/plans`: added `#/components/schemas/CreditPlanFee` to the `data/items/price_components/items/fee/oneOf[#/components/schemas/Fee]/` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/plans/{plan_id}`: added `#/components/schemas/CreditPlanFee` to the `price_components/items/fee/oneOf[#/components/schemas/Fee]/` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/products`: added `#/components/schemas/CreditFeeStructure` to the `data/items/fee_structure` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/products/{product_id}`: added `#/components/schemas/CreditFeeStructure` to the `fee_structure` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/subscriptions/{subscription_id}`: added `#/components/schemas/CreditDiscount` to the `applied_coupons/items/coupon/discount` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/subscriptions/{subscription_id}`: added `#/components/schemas/CreditFee` to the `add_ons/items/fee` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `GET /api/v1/subscriptions/{subscription_id}`: added `#/components/schemas/CreditFee` to the `components/items/fee` response property `oneOf` list for the response status `200` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: `PATCH /api/v1/coupons/{coupon_id}`: added the new required request property `discount/oneOf[#/components/schemas/CouponDiscount]/oneOf[#/components/schemas/FixedDiscount]/type` END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api)!: 90 more breaking changes END_NESTED_COMMIT BEGIN_NESTED_COMMIT feat(api): update the API definitions END_NESTED_COMMIT --- api.md | 107 ++++++- src/api/budgets.ts | 182 +++++++++++ src/api/checks.ts | 75 +++++ src/api/connect.ts | 12 +- src/api/creditUnits.ts | 109 +++++++ src/api/creditUnitsPrices.ts | 100 ++++++ src/api/credits.ts | 142 +++++++++ src/api/creditsGrants.ts | 137 ++++++++ src/api/creditsWallets.ts | 144 +++++++++ src/api/features.ts | 10 +- src/api/plans.ts | 4 +- src/api/usage.ts | 35 +-- src/api/usageCosts.ts | 25 ++ src/api/usageCostsCustomer.ts | 118 +++++++ src/api/usageCostsSubscription.ts | 114 +++++++ src/api/usageCustomer.ts | 82 +++++ src/index.ts | 72 ++++- src/models/actor.ts | 34 ++ src/models/actorType.ts | 22 ++ src/models/allComponentsScope.ts | 15 +- src/models/autoTopUp.ts | 166 ++++++++++ src/models/autoTopUpCapReachedEvent.ts | 77 +++++ src/models/autoTopUpCapReachedEventData.ts | 79 +++++ src/models/autoTopUpConsentChangedEvent.ts | 85 +++++ .../autoTopUpConsentChangedEventData.ts | 112 +++++++ src/models/autoTopUpEvent.ts | 73 +++++ src/models/autoTopUpEventData.ts | 81 +++++ src/models/autoTopUpMethod.ts | 21 ++ src/models/autoTopUpStatus.ts | 22 ++ src/models/autoTopUpWriteRequest.ts | 152 +++++++++ src/models/bankTransferPaymentMethodConfig.ts | 12 +- src/models/billingCycleResetPeriod.ts | 15 +- src/models/booleanConfigValue.ts | 12 +- .../booleanEffectiveEntitlementValue.ts | 12 +- src/models/booleanEntitlementValue.ts | 12 +- src/models/booleanFeatureType.ts | 15 +- src/models/booleanResolvedEntitlementValue.ts | 12 +- src/models/budget.ts | 178 +++++++++++ src/models/budgetAuthor.ts | 21 ++ src/models/budgetBehavior.ts | 26 ++ src/models/budgetListResponse.ts | 38 +++ src/models/budgetPeriod.ts | 29 ++ src/models/calendarResetPeriod.ts | 12 +- src/models/capacityFee.ts | 37 ++- src/models/capacityFeeStructure.ts | 12 +- src/models/capacityPlanFee.ts | 40 ++- src/models/capacityPricing.ts | 10 +- src/models/componentsScope.ts | 10 +- src/models/configEffectiveEntitlementValue.ts | 12 +- src/models/configEntitlementValue.ts | 12 +- src/models/configFeatureType.ts | 10 +- src/models/configResolvedEntitlementValue.ts | 12 +- src/models/coupon.ts | 6 + src/models/couponCreditScope.ts | 21 ++ src/models/couponDiscount.ts | 19 +- src/models/createBudgetRequest.ts | 98 ++++++ src/models/createCheckoutSessionRequest.ts | 6 + src/models/createConnectedAccountRequest.ts | 81 ++--- src/models/createConnectedAccountResponse.ts | 101 ++++++ src/models/createCouponRequest.ts | 8 + src/models/createCreditGrantRequest.ts | 191 ++++++++++++ src/models/createMetricRequest.ts | 25 ++ src/models/createPlanRequest.ts | 18 ++ src/models/createTopUpRequest.ts | 118 +++++++ src/models/createWebhookEndpointRequest.ts | 5 +- src/models/creditAppliesTo.ts | 21 ++ src/models/creditCap.ts | 30 ++ src/models/creditCaps.ts | 35 +++ src/models/creditCost.ts | 30 ++ src/models/creditCostRequest.ts | 30 ++ src/models/creditDiscount.ts | 71 +++++ src/models/creditExhaustedRule.ts | 79 +++++ .../creditExhaustedRuleInvoiceVariant.ts | 28 ++ src/models/creditExhaustedRulePauseVariant.ts | 28 ++ src/models/creditExpiryUnit.ts | 22 ++ src/models/creditFee.ts | 118 +++++++ src/models/creditFeeStructure.ts | 28 ++ src/models/creditGrant.ts | 293 ++++++++++++++++++ src/models/creditGrantExpiredEvent.ts | 97 ++++++ src/models/creditGrantExpiredEventData.ts | 151 +++++++++ src/models/creditGrantId.ts | 15 + src/models/creditGrantKind.ts | 30 ++ src/models/creditGrantLapseReason.ts | 21 ++ src/models/creditGrantListResponse.ts | 38 +++ src/models/creditGrantSource.ts | 28 ++ src/models/creditGrantStatus.ts | 23 ++ src/models/creditGrantType.ts | 26 ++ src/models/creditPackExpiry.ts | 31 ++ src/models/creditPackRollover.ts | 40 +++ src/models/creditPackUnit.ts | 37 +++ src/models/creditPlanFee.ts | 124 ++++++++ src/models/creditUnit.ts | 104 +++++++ src/models/creditUnitCreateRequest.ts | 48 +++ src/models/creditUnitListResponse.ts | 28 ++ src/models/creditUnitPrice.ts | 60 ++++ src/models/creditUnitPriceListResponse.ts | 28 ++ src/models/creditUnitPriceSetRequest.ts | 29 ++ src/models/creditUnitUpdateRequest.ts | 76 +++++ src/models/declineKind.ts | 1 + src/models/doubleSegmentationMatrix.ts | 12 +- src/models/entitlementCheck.ts | 191 ++++++++++++ src/models/entitlementCheckFeature.ts | 29 ++ src/models/entitlementCheckLimit.ts | 85 +++++ src/models/entitlementCheckLimitBehavior.ts | 22 ++ src/models/entitlementCheckPeriod.ts | 29 ++ src/models/entitlementCheckReason.ts | 26 ++ src/models/entitlementOverageBehavior.ts | 21 ++ src/models/eventType.ts | 13 + src/models/existingPriceRef.ts | 12 +- src/models/existingProductRef.ts | 12 +- src/models/externalPaymentMethodConfig.ts | 15 +- src/models/extraRecurringFeeStructure.ts | 12 +- src/models/extraRecurringPlanFee.ts | 22 +- src/models/extraRecurringPricing.ts | 10 +- src/models/fee.ts | 17 +- src/models/feeCreditUnit.ts | 47 +++ src/models/fixedDiscount.ts | 10 +- src/models/fixedWindowResetPeriod.ts | 12 +- src/models/index.ts | 205 ++++++++++++ src/models/invoice.ts | 43 +++ src/models/invoiceEvent.ts | 4 + src/models/invoiceEventData.ts | 14 + src/models/invoiceLineCreditUnit.ts | 66 ++++ src/models/invoiceLineItem.ts | 18 ++ src/models/jsonConfigValue.ts | 12 +- src/models/ledgerEntry.ts | 177 +++++++++++ src/models/ledgerEntryId.ts | 15 + src/models/ledgerEntryType.ts | 26 ++ src/models/ledgerListResponse.ts | 38 +++ src/models/linkedSegmentationMatrix.ts | 10 +- .../listCustomerUsageCostsGranularity.ts | 22 ++ .../listSubscriptionUsageCostsGranularity.ts | 22 ++ src/models/matrixPlanPricing.ts | 12 +- src/models/matrixPricing.ts | 12 +- .../meteredEffectiveEntitlementValue.ts | 12 +- src/models/meteredEntitlementSpec.ts | 86 ++++- src/models/meteredEntitlementUsage.ts | 16 +- src/models/meteredEntitlementValue.ts | 98 +++++- src/models/meteredFeatureType.ts | 12 +- src/models/meteredResolvedEntitlementValue.ts | 90 +++++- src/models/metric.ts | 18 ++ src/models/metricEvent.ts | 8 + src/models/metricEventData.ts | 18 ++ src/models/metricSummary.ts | 18 ++ src/models/metricUsage.ts | 18 ++ src/models/neverResetPeriod.ts | 15 +- src/models/newProductRef.ts | 10 +- src/models/numberConfigValue.ts | 10 +- src/models/oneTimeFee.ts | 10 +- src/models/oneTimeFeeStructure.ts | 15 +- src/models/oneTimePlanFee.ts | 10 +- src/models/oneTimePricing.ts | 10 +- src/models/onlinePaymentMethodConfig.ts | 12 +- src/models/packagePlanPricing.ts | 10 +- src/models/packagePricing.ts | 10 +- src/models/patchBudgetRequest.ts | 53 ++++ src/models/patchWalletRequest.ts | 96 ++++++ src/models/paymentEvent.ts | 8 + src/models/perUnitPlanPricing.ts | 10 +- src/models/perUnitPricing.ts | 10 +- src/models/percentageDiscount.ts | 10 +- src/models/plan.ts | 18 ++ src/models/planFeeCreditUnit.ts | 33 ++ src/models/priceInput.ts | 10 +- src/models/productFeeStructure.ts | 20 +- src/models/productFeeTypeEnum.ts | 1 + src/models/productsScope.ts | 10 +- src/models/rateFee.ts | 10 +- src/models/rateFeeStructure.ts | 15 +- src/models/ratePlanFee.ts | 12 +- src/models/ratePricing.ts | 10 +- src/models/recurringFee.ts | 10 +- src/models/refundEventData.ts | 21 ++ src/models/replacePlanRequest.ts | 18 ++ src/models/slidingWindowResetPeriod.ts | 18 +- src/models/slotFee.ts | 8 + src/models/slotFeeStructure.ts | 20 +- src/models/slotPlanFee.ts | 22 +- src/models/slotPricing.ts | 10 +- src/models/subscription.ts | 31 ++ .../subscriptionAddOnParameterization.ts | 10 +- src/models/subscriptionAddOnPriceOverride.ts | 10 +- src/models/subscriptionCreateRequest.ts | 25 ++ src/models/subscriptionCredit.ts | 33 ++ src/models/subscriptionDetails.ts | 31 ++ src/models/subscriptionFee.ts | 17 +- src/models/subscriptionUpdateRequest.ts | 15 + src/models/textConfigValue.ts | 10 +- src/models/tieredPlanPricing.ts | 18 +- src/models/tieredPricing.ts | 18 +- src/models/topUpCollection.ts | 24 ++ src/models/topUpResponse.ts | 92 ++++++ src/models/topUpStatus.ts | 21 ++ src/models/transaction.ts | 24 ++ src/models/unattributedMetricUsage.ts | 61 ++++ src/models/unattributedUsageResponse.ts | 39 +++ src/models/unitConversion.ts | 8 +- src/models/updateMetricRequest.ts | 22 ++ src/models/updateWebhookEndpointRequest.ts | 5 +- src/models/usageAtZero.ts | 23 ++ src/models/usageCost.ts | 36 +++ src/models/usageCostListResponse.ts | 28 ++ src/models/usageCostRow.ts | 59 ++++ src/models/usageCostUnit.ts | 21 ++ src/models/usageEvent.ts | 59 ++++ src/models/usageEventListResponse.ts | 35 +++ src/models/usageFee.ts | 25 +- src/models/usageFeeStructure.ts | 12 +- src/models/usageFilter.ts | 38 +++ src/models/usageLimitId.ts | 15 + src/models/usagePlanFee.ts | 34 +- src/models/usagePricing.ts | 12 +- src/models/usageResponse.ts | 52 +++- src/models/volumePlanPricing.ts | 18 +- src/models/volumePricing.ts | 18 +- src/models/wallet.ts | 256 +++++++++++++++ src/models/walletBalanceLowEvent.ts | 77 +++++ src/models/walletBalanceLowEventData.ts | 91 ++++++ src/models/walletCheck.ts | 140 +++++++++ src/models/walletCreditRecoveredEvent.ts | 89 ++++++ src/models/walletCreditRecoveredEventData.ts | 136 ++++++++ src/models/walletCreditUnrecoveredEvent.ts | 93 ++++++ .../walletCreditUnrecoveredEventData.ts | 153 +++++++++ src/models/walletDebitedEvent.ts | 105 +++++++ src/models/walletDebitedEventData.ts | 167 ++++++++++ src/models/walletDepletedEvent.ts | 65 ++++ src/models/walletDepletedEventData.ts | 63 ++++ src/models/walletFundedEvent.ts | 105 +++++++ src/models/walletFundedEventData.ts | 175 +++++++++++ src/models/walletListResponse.ts | 28 ++ src/models/walletRecoveredEvent.ts | 69 +++++ src/models/walletRecoveredEventData.ts | 73 +++++ src/models/webhookEndpoint.ts | 5 +- tests/api/budgets.test.ts | 14 + tests/api/checks.test.ts | 16 + tests/api/connect.test.ts | 4 +- tests/api/creditNotes.test.ts | 6 +- tests/api/creditUnits.test.ts | 58 ++++ tests/api/creditUnitsPrices.test.ts | 39 +++ tests/api/credits.test.ts | 14 + tests/api/creditsGrants.test.ts | 14 + tests/api/creditsWallets.test.ts | 24 ++ tests/api/invoices.test.ts | 8 +- tests/api/plans.test.ts | 14 +- tests/api/products.test.ts | 8 +- tests/api/usage.test.ts | 2 +- tests/api/usageCustomer.test.ts | 14 + 247 files changed, 10577 insertions(+), 300 deletions(-) create mode 100644 src/api/budgets.ts create mode 100644 src/api/checks.ts create mode 100644 src/api/creditUnits.ts create mode 100644 src/api/creditUnitsPrices.ts create mode 100644 src/api/credits.ts create mode 100644 src/api/creditsGrants.ts create mode 100644 src/api/creditsWallets.ts create mode 100644 src/api/usageCosts.ts create mode 100644 src/api/usageCostsCustomer.ts create mode 100644 src/api/usageCostsSubscription.ts create mode 100644 src/api/usageCustomer.ts create mode 100644 src/models/actor.ts create mode 100644 src/models/actorType.ts create mode 100644 src/models/autoTopUp.ts create mode 100644 src/models/autoTopUpCapReachedEvent.ts create mode 100644 src/models/autoTopUpCapReachedEventData.ts create mode 100644 src/models/autoTopUpConsentChangedEvent.ts create mode 100644 src/models/autoTopUpConsentChangedEventData.ts create mode 100644 src/models/autoTopUpEvent.ts create mode 100644 src/models/autoTopUpEventData.ts create mode 100644 src/models/autoTopUpMethod.ts create mode 100644 src/models/autoTopUpStatus.ts create mode 100644 src/models/autoTopUpWriteRequest.ts create mode 100644 src/models/budget.ts create mode 100644 src/models/budgetAuthor.ts create mode 100644 src/models/budgetBehavior.ts create mode 100644 src/models/budgetListResponse.ts create mode 100644 src/models/budgetPeriod.ts create mode 100644 src/models/couponCreditScope.ts create mode 100644 src/models/createBudgetRequest.ts create mode 100644 src/models/createConnectedAccountResponse.ts create mode 100644 src/models/createCreditGrantRequest.ts create mode 100644 src/models/createTopUpRequest.ts create mode 100644 src/models/creditAppliesTo.ts create mode 100644 src/models/creditCap.ts create mode 100644 src/models/creditCaps.ts create mode 100644 src/models/creditCost.ts create mode 100644 src/models/creditCostRequest.ts create mode 100644 src/models/creditDiscount.ts create mode 100644 src/models/creditExhaustedRule.ts create mode 100644 src/models/creditExhaustedRuleInvoiceVariant.ts create mode 100644 src/models/creditExhaustedRulePauseVariant.ts create mode 100644 src/models/creditExpiryUnit.ts create mode 100644 src/models/creditFee.ts create mode 100644 src/models/creditFeeStructure.ts create mode 100644 src/models/creditGrant.ts create mode 100644 src/models/creditGrantExpiredEvent.ts create mode 100644 src/models/creditGrantExpiredEventData.ts create mode 100644 src/models/creditGrantId.ts create mode 100644 src/models/creditGrantKind.ts create mode 100644 src/models/creditGrantLapseReason.ts create mode 100644 src/models/creditGrantListResponse.ts create mode 100644 src/models/creditGrantSource.ts create mode 100644 src/models/creditGrantStatus.ts create mode 100644 src/models/creditGrantType.ts create mode 100644 src/models/creditPackExpiry.ts create mode 100644 src/models/creditPackRollover.ts create mode 100644 src/models/creditPackUnit.ts create mode 100644 src/models/creditPlanFee.ts create mode 100644 src/models/creditUnit.ts create mode 100644 src/models/creditUnitCreateRequest.ts create mode 100644 src/models/creditUnitListResponse.ts create mode 100644 src/models/creditUnitPrice.ts create mode 100644 src/models/creditUnitPriceListResponse.ts create mode 100644 src/models/creditUnitPriceSetRequest.ts create mode 100644 src/models/creditUnitUpdateRequest.ts create mode 100644 src/models/entitlementCheck.ts create mode 100644 src/models/entitlementCheckFeature.ts create mode 100644 src/models/entitlementCheckLimit.ts create mode 100644 src/models/entitlementCheckLimitBehavior.ts create mode 100644 src/models/entitlementCheckPeriod.ts create mode 100644 src/models/entitlementCheckReason.ts create mode 100644 src/models/entitlementOverageBehavior.ts create mode 100644 src/models/feeCreditUnit.ts create mode 100644 src/models/invoiceLineCreditUnit.ts create mode 100644 src/models/ledgerEntry.ts create mode 100644 src/models/ledgerEntryId.ts create mode 100644 src/models/ledgerEntryType.ts create mode 100644 src/models/ledgerListResponse.ts create mode 100644 src/models/listCustomerUsageCostsGranularity.ts create mode 100644 src/models/listSubscriptionUsageCostsGranularity.ts create mode 100644 src/models/patchBudgetRequest.ts create mode 100644 src/models/patchWalletRequest.ts create mode 100644 src/models/planFeeCreditUnit.ts create mode 100644 src/models/subscriptionCredit.ts create mode 100644 src/models/topUpCollection.ts create mode 100644 src/models/topUpResponse.ts create mode 100644 src/models/topUpStatus.ts create mode 100644 src/models/unattributedMetricUsage.ts create mode 100644 src/models/unattributedUsageResponse.ts create mode 100644 src/models/usageAtZero.ts create mode 100644 src/models/usageCost.ts create mode 100644 src/models/usageCostListResponse.ts create mode 100644 src/models/usageCostRow.ts create mode 100644 src/models/usageCostUnit.ts create mode 100644 src/models/usageEvent.ts create mode 100644 src/models/usageEventListResponse.ts create mode 100644 src/models/usageFilter.ts create mode 100644 src/models/usageLimitId.ts create mode 100644 src/models/wallet.ts create mode 100644 src/models/walletBalanceLowEvent.ts create mode 100644 src/models/walletBalanceLowEventData.ts create mode 100644 src/models/walletCheck.ts create mode 100644 src/models/walletCreditRecoveredEvent.ts create mode 100644 src/models/walletCreditRecoveredEventData.ts create mode 100644 src/models/walletCreditUnrecoveredEvent.ts create mode 100644 src/models/walletCreditUnrecoveredEventData.ts create mode 100644 src/models/walletDebitedEvent.ts create mode 100644 src/models/walletDebitedEventData.ts create mode 100644 src/models/walletDepletedEvent.ts create mode 100644 src/models/walletDepletedEventData.ts create mode 100644 src/models/walletFundedEvent.ts create mode 100644 src/models/walletFundedEventData.ts create mode 100644 src/models/walletListResponse.ts create mode 100644 src/models/walletRecoveredEvent.ts create mode 100644 src/models/walletRecoveredEventData.ts create mode 100644 tests/api/budgets.test.ts create mode 100644 tests/api/checks.test.ts create mode 100644 tests/api/creditUnits.test.ts create mode 100644 tests/api/creditUnitsPrices.test.ts create mode 100644 tests/api/credits.test.ts create mode 100644 tests/api/creditsGrants.test.ts create mode 100644 tests/api/creditsWallets.test.ts create mode 100644 tests/api/usageCustomer.test.ts diff --git a/api.md b/api.md index 707ba08..91e4e48 100644 --- a/api.md +++ b/api.md @@ -11,7 +11,7 @@ List methods return a `PagePromise`. Awaited, it gives the first `Page`: the res properties read on the page, with `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`. Iterated with `for await`, it yields every item of every page. -[Add ons](#add-ons) · [Add ons entitlements](#add-ons-entitlements) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Plans versions](#plans-versions) · [Product families](#product-families) · [Products](#products) · [Products entitlements](#products-entitlements) · [Subscriptions](#subscriptions) · [Usage](#usage) · [Webhook endpoints](#webhook-endpoints) · [Webhook endpoints endpoints](#webhook-endpoints-endpoints) +[Add ons](#add-ons) · [Add ons entitlements](#add-ons-entitlements) · [Batch jobs](#batch-jobs) · [Budgets](#budgets) · [Checkout sessions](#checkout-sessions) · [Checks](#checks) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Credit units](#credit-units) · [Credit units prices](#credit-units-prices) · [Credits](#credits) · [Credits grants](#credits-grants) · [Credits wallets](#credits-wallets) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Plans versions](#plans-versions) · [Product families](#product-families) · [Products](#products) · [Products entitlements](#products-entitlements) · [Subscriptions](#subscriptions) · [Usage](#usage) · [Usage customer](#usage-customer) · [Usage costs](#usage-costs) · [Usage costs customer](#usage-costs-customer) · [Usage costs subscription](#usage-costs-subscription) · [Webhook endpoints](#webhook-endpoints) · [Webhook endpoints endpoints](#webhook-endpoints-endpoints) ## Add ons @@ -45,6 +45,17 @@ Iterated with `for await`, it yields every item of every page. | `client.batchJobs.retrieve(batchJobId: string): APIPromise` | `GET /api/v1/batch-jobs/{batch_job_id}` | [`BatchJobDetailResponse`](src/models/batchJobDetailResponse.ts) | | `client.batchJobs.listFailures(batchJobId: string, options?: BatchJobsListFailuresOptions): PagePromise` | `GET /api/v1/batch-jobs/{batch_job_id}/failures` | [`BatchJobFailuresResponse`](src/models/batchJobFailuresResponse.ts) pages of [`BatchJobItemFailureResponse`](src/models/batchJobItemFailureResponse.ts) | +## Budgets + +[`client.budgets`](src/api/budgets.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.budgets.list(idOrAlias: string, options?: BudgetsListOptions): PagePromise` | `GET /api/v1/customers/{id_or_alias}/budgets` | [`BudgetListResponse`](src/models/budgetListResponse.ts) pages of [`Budget`](src/models/budget.ts) | +| `client.budgets.create(idOrAlias: string, createBudgetRequest: CreateBudgetRequest, options: BudgetsCreateOptions): APIPromise` | `POST /api/v1/customers/{id_or_alias}/budgets` | [`Budget`](src/models/budget.ts) | +| `client.budgets.update(idOrAlias: string, budgetId: string, patchBudgetRequest: PatchBudgetRequest, options: BudgetsUpdateOptions): APIPromise` | `PATCH /api/v1/customers/{id_or_alias}/budgets/{budget_id}` | [`Budget`](src/models/budget.ts) | +| `client.budgets.archive(idOrAlias: string, budgetId: string, options: BudgetsArchiveOptions): APIPromise` | `POST /api/v1/customers/{id_or_alias}/budgets/{budget_id}/archive` | [`Budget`](src/models/budget.ts) | + ## Checkout sessions [`client.checkoutSessions`](src/api/checkoutSessions.ts) @@ -56,6 +67,14 @@ Iterated with `for await`, it yields every item of every page. | `client.checkoutSessions.retrieve(id: string): APIPromise` | `GET /api/v1/checkout-sessions/{id}` | [`GetCheckoutSessionResponse`](src/models/getCheckoutSessionResponse.ts) | | `client.checkoutSessions.cancel(id: string): APIPromise` | `POST /api/v1/checkout-sessions/{id}/cancel` | [`CancelCheckoutSessionResponse`](src/models/cancelCheckoutSessionResponse.ts) | +## Checks + +[`client.checks`](src/api/checks.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.checks.checkEntitlement(idOrAlias: string, featureIdOrCode: string, options?: ChecksCheckEntitlementOptions): APIPromise` | `GET /api/v1/customers/{id_or_alias}/entitlements/{feature_id_or_code}/check` | [`EntitlementCheck`](src/models/entitlementCheck.ts) | + ## Connect [`client.connect`](src/api/connect.ts) @@ -63,7 +82,7 @@ Iterated with `for await`, it yields every item of every page. | Method | Request | Returns | | --- | --- | --- | | `client.connect.listConnectedAccounts(): APIPromise` | `GET /api/v1/connected-accounts` | [`ConnectedAccountsResponse`](src/models/connectedAccountsResponse.ts) | -| `client.connect.createConnectedAccount(createConnectedAccountRequest: CreateConnectedAccountRequest): APIPromise` | `POST /api/v1/connected-accounts` | [`ConnectedAccount`](src/models/connectedAccount.ts) | +| `client.connect.createConnectedAccount(createConnectedAccountRequest: CreateConnectedAccountRequest): APIPromise` | `POST /api/v1/connected-accounts` | [`CreateConnectedAccountResponse`](src/models/createConnectedAccountResponse.ts) | | `client.connect.retrieveConnectedAccount(id: string): APIPromise` | `GET /api/v1/connected-accounts/{id}` | [`ConnectedAccount`](src/models/connectedAccount.ts) | | `client.connect.disconnectAccount(id: string): APIPromise` | `DELETE /api/v1/connected-accounts/{id}` | nothing | | `client.connect.createOnboardingLink(id: string, createOnboardingLinkRequest: CreateOnboardingLinkRequest): APIPromise` | `POST /api/v1/connected-accounts/{id}/onboarding` | [`OnboardingLinkResponse`](src/models/onboardingLinkResponse.ts) | @@ -95,6 +114,55 @@ Iterated with `for await`, it yields every item of every page. | `client.creditNotes.download(creditNoteId: string): APIPromise` | `GET /api/v1/credit-notes/{credit_note_id}/download` | bytes | | `client.creditNotes.downloadXml(creditNoteId: string): APIPromise` | `GET /api/v1/credit-notes/{credit_note_id}/xml` | bytes | +## Credit units + +[`client.creditUnits`](src/api/creditUnits.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.creditUnits.list(options?: CreditUnitsListOptions): APIPromise` | `GET /api/v1/credit-units` | [`CreditUnitListResponse`](src/models/creditUnitListResponse.ts) | +| `client.creditUnits.create(creditUnitCreateRequest: CreditUnitCreateRequest): APIPromise` | `POST /api/v1/credit-units` | [`CreditUnit`](src/models/creditUnit.ts) | +| `client.creditUnits.retrieve(id: string): APIPromise` | `GET /api/v1/credit-units/{id}` | [`CreditUnit`](src/models/creditUnit.ts) | +| `client.creditUnits.update(id: string, creditUnitUpdateRequest: CreditUnitUpdateRequest): APIPromise` | `PATCH /api/v1/credit-units/{id}` | [`CreditUnit`](src/models/creditUnit.ts) | + +### Credit units prices + +[`client.creditUnits.prices`](src/api/creditUnitsPrices.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.creditUnits.prices.list(id: string, options?: CreditUnitsPricesListOptions): APIPromise` | `GET /api/v1/credit-units/{id}/prices` | [`CreditUnitPriceListResponse`](src/models/creditUnitPriceListResponse.ts) | +| `client.creditUnits.prices.update(id: string, currency: string, creditUnitPriceSetRequest: CreditUnitPriceSetRequest): APIPromise` | `PUT /api/v1/credit-units/{id}/prices/{currency}` | [`CreditUnitPrice`](src/models/creditUnitPrice.ts) | +| `client.creditUnits.prices.archive(id: string, currency: string): APIPromise` | `DELETE /api/v1/credit-units/{id}/prices/{currency}` | [`CreditUnitPrice`](src/models/creditUnitPrice.ts) | + +## Credits + +[`client.credits`](src/api/credits.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.credits.listCustomerCreditLedger(idOrAlias: string, options?: CreditsListCustomerCreditLedgerOptions): PagePromise` | `GET /api/v1/customers/{id_or_alias}/credit-ledger` | [`LedgerListResponse`](src/models/ledgerListResponse.ts) pages of [`LedgerEntry`](src/models/ledgerEntry.ts) | +| `client.credits.createCustomerTopUp(idOrAlias: string, createTopUpRequest: CreateTopUpRequest, options: CreditsCreateCustomerTopUpOptions): APIPromise` | `POST /api/v1/customers/{id_or_alias}/top-ups` | [`TopUpResponse`](src/models/topUpResponse.ts) | + +### Credits grants + +[`client.credits.grants`](src/api/creditsGrants.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.credits.grants.list(idOrAlias: string, options?: CreditsGrantsListOptions): PagePromise` | `GET /api/v1/customers/{id_or_alias}/credit-grants` | [`CreditGrantListResponse`](src/models/creditGrantListResponse.ts) pages of [`CreditGrant`](src/models/creditGrant.ts) | +| `client.credits.grants.create(idOrAlias: string, createCreditGrantRequest: CreateCreditGrantRequest, options: CreditsGrantsCreateOptions): APIPromise` | `POST /api/v1/customers/{id_or_alias}/credit-grants` | [`CreditGrant`](src/models/creditGrant.ts) | + +### Credits wallets + +[`client.credits.wallets`](src/api/creditsWallets.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.credits.wallets.list(idOrAlias: string, options?: CreditsWalletsListOptions): APIPromise` | `GET /api/v1/customers/{id_or_alias}/wallets` | [`WalletListResponse`](src/models/walletListResponse.ts) | +| `client.credits.wallets.check(idOrAlias: string, options?: CreditsWalletsCheckOptions): APIPromise` | `GET /api/v1/customers/{id_or_alias}/wallets/check` | [`WalletCheck`](src/models/walletCheck.ts) | +| `client.credits.wallets.update(idOrAlias: string, currency: string, patchWalletRequest: PatchWalletRequest, options: CreditsWalletsUpdateOptions): APIPromise` | `PATCH /api/v1/customers/{id_or_alias}/wallets/{currency}` | [`Wallet`](src/models/wallet.ts) | + ## Custom properties [`client.customProperties`](src/api/customProperties.ts) @@ -281,10 +349,43 @@ Iterated with `for await`, it yields every item of every page. | Method | Request | Returns | | --- | --- | --- | -| `client.usage.retrieveCustomer(customerId: string, options: UsageRetrieveCustomerOptions): APIPromise` | `GET /api/v1/usage/customer/{customer_id}` | [`UsageResponse`](src/models/usageResponse.ts) | | `client.usage.retrieveSubscription(subscriptionId: string, options?: UsageRetrieveSubscriptionOptions): APIPromise` | `GET /api/v1/usage/subscription/{subscription_id}` | [`UsageResponse`](src/models/usageResponse.ts) | | `client.usage.retrieveSummary(options: UsageRetrieveSummaryOptions): APIPromise` | `GET /api/v1/usage/summary` | [`UsageResponse`](src/models/usageResponse.ts) | +### Usage customer + +[`client.usage.customer`](src/api/usageCustomer.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.usage.customer.retrieve(customerId: string, options: UsageCustomerRetrieveOptions): APIPromise` | `GET /api/v1/usage/customer/{customer_id}` | [`UsageResponse`](src/models/usageResponse.ts) | +| `client.usage.customer.retrieveUnattributed(customerId: string, options?: UsageCustomerRetrieveUnattributedOptions): APIPromise` | `GET /api/v1/usage/customer/{customer_id}/unattributed` | [`UnattributedUsageResponse`](src/models/unattributedUsageResponse.ts) | + +## Usage costs + +[`client.usageCosts`](src/api/usageCosts.ts) + +| Method | Request | Returns | +| --- | --- | --- | + +### Usage costs customer + +[`client.usageCosts.customer`](src/api/usageCostsCustomer.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.usageCosts.customer.listCosts(customerId: string, options: UsageCostsCustomerListCostsOptions): APIPromise` | `GET /api/v1/usage/customer/{customer_id}/costs` | [`UsageCostListResponse`](src/models/usageCostListResponse.ts) | +| `client.usageCosts.customer.listEvents(customerId: string, options: UsageCostsCustomerListEventsOptions): APIPromise` | `GET /api/v1/usage/customer/{customer_id}/events` | [`UsageEventListResponse`](src/models/usageEventListResponse.ts) | + +### Usage costs subscription + +[`client.usageCosts.subscription`](src/api/usageCostsSubscription.ts) + +| Method | Request | Returns | +| --- | --- | --- | +| `client.usageCosts.subscription.listCosts(subscriptionId: string, options: UsageCostsSubscriptionListCostsOptions): APIPromise` | `GET /api/v1/usage/subscription/{subscription_id}/costs` | [`UsageCostListResponse`](src/models/usageCostListResponse.ts) | +| `client.usageCosts.subscription.listEvents(subscriptionId: string, options: UsageCostsSubscriptionListEventsOptions): APIPromise` | `GET /api/v1/usage/subscription/{subscription_id}/events` | [`UsageEventListResponse`](src/models/usageEventListResponse.ts) | + ## Webhook endpoints [`client.webhookEndpoints`](src/api/webhookEndpoints.ts) diff --git a/src/api/budgets.ts b/src/api/budgets.ts new file mode 100644 index 0000000..ac6a3b8 --- /dev/null +++ b/src/api/budgets.ts @@ -0,0 +1,182 @@ +// this file is @generated + +import { type Budget, BudgetSerializer } from "../models/budget.js"; +import { + type BudgetListResponse, + BudgetListResponseSerializer, +} from "../models/budgetListResponse.js"; +import { + type CreateBudgetRequest, + CreateBudgetRequestSerializer, +} from "../models/createBudgetRequest.js"; +import { + type PatchBudgetRequest, + PatchBudgetRequestSerializer, +} from "../models/patchBudgetRequest.js"; +import type { APIPromise } from "../apiPromise.js"; +import { PagePromise } from "../pagination.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `list`. */ +export interface BudgetsListOptions { + /** Defaults to false. */ + includeArchived?: boolean | undefined; + /** Page number (0-indexed) */ + page?: number | undefined; + /** Number of items per page */ + perPage?: number | undefined; +} + +/** The query and header parameters of `create`. */ +export interface BudgetsCreateOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The query and header parameters of `update`. */ +export interface BudgetsUpdateOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The query and header parameters of `archive`. */ +export interface BudgetsArchiveOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The budgets operations, reached through the client's `budgets`. */ +export class Budgets { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List budgets + * + * A customer's budgets, oldest first, with their estimated spend in the current billing period. + * Archived ones are left out unless requested. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + * + * Await it for the first page: the response body, its properties read on the page, with + * `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`. Or iterate it with `for await` + * over every item of every page, fetched on demand. + */ + public list( + idOrAlias: string, + options?: BudgetsListOptions, + requestOptions?: RequestOptions + ): PagePromise { + return new PagePromise( + { + style: "page", + items: (page) => page.data, + totalPages: (page) => page.paginationMeta?.totalPages, + firstPage: 0, + fetch: (page) => + this.#list(idOrAlias, { ...options, page: page }, requestOptions), + }, + options?.page + ); + } + + #list( + idOrAlias: string, + options?: BudgetsListOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/customers/{id_or_alias}/budgets"); + + request.setPathParam("id_or_alias", idOrAlias); + request.setQueryParam("include_archived", options?.includeArchived); + request.setQueryParam("page", options?.page); + request.setQueryParam("per_page", options?.perPage); + return request.send( + this.requestCtx, + BudgetListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Create a budget + * + * Sets a spending limit for one currency the customer is billed in, with alerts at percentages + * of it, on the customer's whole spend or on one subscription's. A customer has one active + * budget per currency, and per subscription. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public create( + idOrAlias: string, + createBudgetRequest: CreateBudgetRequest, + options: BudgetsCreateOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "POST", + "/api/v1/customers/{id_or_alias}/budgets" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + request.setBody(CreateBudgetRequestSerializer.serialize(createBudgetRequest)); + return request.send(this.requestCtx, BudgetSerializer.parse, requestOptions); + } + + /** + * Update a budget + * + * Changes the amount, thresholds or behavior. Send the `version` you read as `expected_version`; a newer + * stored version, for instance after the customer edited it, is refused with 409. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public update( + idOrAlias: string, + budgetId: string, + patchBudgetRequest: PatchBudgetRequest, + options: BudgetsUpdateOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "PATCH", + "/api/v1/customers/{id_or_alias}/budgets/{budget_id}" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setPathParam("budget_id", budgetId); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + request.setBody(PatchBudgetRequestSerializer.serialize(patchBudgetRequest)); + return request.send(this.requestCtx, BudgetSerializer.parse, requestOptions); + } + + /** + * Archive a budget + * + * Stops the budget from sending alerts and, for a HARD budget, from refusing access. Archiving an + * archived budget returns it unchanged. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public archive( + idOrAlias: string, + budgetId: string, + options: BudgetsArchiveOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "POST", + "/api/v1/customers/{id_or_alias}/budgets/{budget_id}/archive" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setPathParam("budget_id", budgetId); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + return request.send(this.requestCtx, BudgetSerializer.parse, requestOptions); + } +} diff --git a/src/api/checks.ts b/src/api/checks.ts new file mode 100644 index 0000000..08cb7f5 --- /dev/null +++ b/src/api/checks.ts @@ -0,0 +1,75 @@ +// this file is @generated + +import { + type EntitlementCheck, + EntitlementCheckSerializer, +} from "../models/entitlementCheck.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `checkEntitlement`. */ +export interface ChecksCheckEntitlementOptions { + /** Units the customer is about to consume. Defaults to 1. */ + requested?: string | undefined; + /** + * The subscription (`sub_…`) the usage belongs to: only its own budgets and the customer-wide + * ones apply. Without it, a budget on one subscription refuses only once every subscription + * charging the feature's metric is refused by its own budget. + */ + subscriptionId?: string | undefined; + /** The group to check, as `group[]=`: required when the entitlement is grouped */ + group?: { [key: string]: string } | undefined; +} + +/** The checks operations, reached through the client's `checks`. */ +export class Checks { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * Check customer entitlement + * + * Whether the customer may consume `requested` more of a feature right now, given their + * entitlement, the hard budgets that count the feature's usage, and their prepaid credit. + * Boolean features answer from their enabled state; config features grant access and return + * their `value`. An `ALLOW` limit never refuses: `in_overage` tells when the requested units go + * beyond it. Sliding windows send no threshold webhooks. Pass the group as + * `group[]=`: it is required when the entitlement is grouped. Pass + * `subscription_id` when the usage belongs to one subscription, so that a hard budget on another + * subscription does not refuse it. + * + * The answer reflects usage up to `as_of`: typically less than a minute old, and less than 10 + * seconds old once `near_limit` is true. A hard limit can therefore be exceeded by the usage of + * those few seconds. While `near_limit` is true, check before every request with its actual + * `requested` and do not cache the answer; `retry_after_ms` says when to check again. Use the + * check to gate access, not to bill. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public checkEntitlement( + idOrAlias: string, + featureIdOrCode: string, + options?: ChecksCheckEntitlementOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/customers/{id_or_alias}/entitlements/{feature_id_or_code}/check" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setPathParam("feature_id_or_code", featureIdOrCode); + request.setQueryParam("requested", options?.requested); + request.setQueryParam("subscription_id", options?.subscriptionId); + request.setStructuredQueryParam("group", options?.group, true, true); + return request.send( + this.requestCtx, + EntitlementCheckSerializer.parse, + requestOptions + ); + } +} diff --git a/src/api/connect.ts b/src/api/connect.ts index 192a941..1a5fd44 100644 --- a/src/api/connect.ts +++ b/src/api/connect.ts @@ -12,6 +12,10 @@ import { type CreateConnectedAccountRequest, CreateConnectedAccountRequestSerializer, } from "../models/createConnectedAccountRequest.js"; +import { + type CreateConnectedAccountResponse, + CreateConnectedAccountResponseSerializer, +} from "../models/createConnectedAccountResponse.js"; import { type CreateOnboardingLinkRequest, CreateOnboardingLinkRequestSerializer, @@ -52,13 +56,13 @@ export class Connect { /** * Create connected account * - * Create a new connected account (Express flow). Returns the account - * and an onboarding link for the user to complete setup. + * Create a new pending connected account (Express flow). Returns the + * account and an onboarding link for the user to complete setup. */ public createConnectedAccount( createConnectedAccountRequest: CreateConnectedAccountRequest, requestOptions?: RequestOptions - ): APIPromise { + ): APIPromise { const request = new MeteroidRequest("POST", "/api/v1/connected-accounts"); request.setBody( @@ -66,7 +70,7 @@ export class Connect { ); return request.send( this.requestCtx, - ConnectedAccountSerializer.parse, + CreateConnectedAccountResponseSerializer.parse, requestOptions ); } diff --git a/src/api/creditUnits.ts b/src/api/creditUnits.ts new file mode 100644 index 0000000..7a30098 --- /dev/null +++ b/src/api/creditUnits.ts @@ -0,0 +1,109 @@ +// this file is @generated + +import { type CreditUnit, CreditUnitSerializer } from "../models/creditUnit.js"; +import { + type CreditUnitCreateRequest, + CreditUnitCreateRequestSerializer, +} from "../models/creditUnitCreateRequest.js"; +import { + type CreditUnitListResponse, + CreditUnitListResponseSerializer, +} from "../models/creditUnitListResponse.js"; +import { + type CreditUnitUpdateRequest, + CreditUnitUpdateRequestSerializer, +} from "../models/creditUnitUpdateRequest.js"; +import { CreditUnitsPrices } from "./creditUnitsPrices.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `list`. */ +export interface CreditUnitsListOptions { + /** Include archived units. Defaults to false. */ + includeArchived?: boolean | undefined; +} + +/** The credit units operations, reached through the client's `creditUnits`. */ +export class CreditUnits { + private _prices?: CreditUnitsPrices; + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** The prices operations. */ + public get prices(): CreditUnitsPrices { + this._prices ??= new CreditUnitsPrices(this.requestCtx); + return this._prices; + } + + /** + * List credit units + * + * The tenant's credit units (e.g. "Halyard credits"): denominations usage can be priced and + * credit granted in, instead of money, each with its selling prices. + */ + public list( + options?: CreditUnitsListOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/credit-units"); + + request.setQueryParam("include_archived", options?.includeArchived); + return request.send( + this.requestCtx, + CreditUnitListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Create a credit unit + * + * `code` and `precision` are immutable once created. Price usage in the unit with a plan fee's + * `credit_unit`, grant it with a credit pack or a credit grant, and sell it with a top-up once + * it has a `product_id` and a selling price. + */ + public create( + creditUnitCreateRequest: CreditUnitCreateRequest, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("POST", "/api/v1/credit-units"); + + request.setBody(CreditUnitCreateRequestSerializer.serialize(creditUnitCreateRequest)); + return request.send(this.requestCtx, CreditUnitSerializer.parse, requestOptions); + } + + /** + * Get a credit unit + * + * The unit with its active selling prices. + */ + public retrieve(id: string, requestOptions?: RequestOptions): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/credit-units/{id}"); + + request.setPathParam("id", id); + return request.send(this.requestCtx, CreditUnitSerializer.parse, requestOptions); + } + + /** + * Update a credit unit + * + * Partial update: an absent field is left unchanged. `code` and `precision` are immutable and + * cannot be changed here. Setting `archived: true` blocks the unit from new prices, packs and + * grants; existing ones keep working. + */ + public update( + id: string, + creditUnitUpdateRequest: CreditUnitUpdateRequest, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("PATCH", "/api/v1/credit-units/{id}"); + + request.setPathParam("id", id); + request.setBody(CreditUnitUpdateRequestSerializer.serialize(creditUnitUpdateRequest)); + return request.send(this.requestCtx, CreditUnitSerializer.parse, requestOptions); + } +} diff --git a/src/api/creditUnitsPrices.ts b/src/api/creditUnitsPrices.ts new file mode 100644 index 0000000..b56f928 --- /dev/null +++ b/src/api/creditUnitsPrices.ts @@ -0,0 +1,100 @@ +// this file is @generated + +import { + type CreditUnitPrice, + CreditUnitPriceSerializer, +} from "../models/creditUnitPrice.js"; +import { + type CreditUnitPriceListResponse, + CreditUnitPriceListResponseSerializer, +} from "../models/creditUnitPriceListResponse.js"; +import { + type CreditUnitPriceSetRequest, + CreditUnitPriceSetRequestSerializer, +} from "../models/creditUnitPriceSetRequest.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `list`. */ +export interface CreditUnitsPricesListOptions { + /** Include archived prices. Defaults to false. */ + includeArchived?: boolean | undefined; +} + +/** The credit units prices operations, reached through the client's `creditUnits.prices`. */ +export class CreditUnitsPrices { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List a credit unit's selling prices + * + * The active price per currency, and archived ones when asked, newest first. + */ + public list( + id: string, + options?: CreditUnitsPricesListOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/credit-units/{id}/prices"); + + request.setPathParam("id", id); + request.setQueryParam("include_archived", options?.includeArchived); + return request.send( + this.requestCtx, + CreditUnitPriceListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Set a credit unit's selling price + * + * The price of one credit in a currency, used to sell the unit through top-ups and automatic + * top-ups (taxed at purchase under the unit's `product_id`). Replaces the active price in that + * currency, which is archived: a top-up already priced keeps its terms. + */ + public update( + id: string, + currency: string, + creditUnitPriceSetRequest: CreditUnitPriceSetRequest, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "PUT", + "/api/v1/credit-units/{id}/prices/{currency}" + ); + + request.setPathParam("id", id); + request.setPathParam("currency", currency); + request.setBody( + CreditUnitPriceSetRequestSerializer.serialize(creditUnitPriceSetRequest) + ); + return request.send(this.requestCtx, CreditUnitPriceSerializer.parse, requestOptions); + } + + /** + * Remove a credit unit's selling price + * + * Archives the active price in a currency: the unit can no longer be sold in it (top-ups and + * automatic top-ups included) until a new price is set. + */ + public archive( + id: string, + currency: string, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "DELETE", + "/api/v1/credit-units/{id}/prices/{currency}" + ); + + request.setPathParam("id", id); + request.setPathParam("currency", currency); + return request.send(this.requestCtx, CreditUnitPriceSerializer.parse, requestOptions); + } +} diff --git a/src/api/credits.ts b/src/api/credits.ts new file mode 100644 index 0000000..19a4091 --- /dev/null +++ b/src/api/credits.ts @@ -0,0 +1,142 @@ +// this file is @generated + +import { + type CreateTopUpRequest, + CreateTopUpRequestSerializer, +} from "../models/createTopUpRequest.js"; +import type { Currency } from "../models/currency.js"; +import type { LedgerEntry } from "../models/ledgerEntry.js"; +import { + type LedgerListResponse, + LedgerListResponseSerializer, +} from "../models/ledgerListResponse.js"; +import { type TopUpResponse, TopUpResponseSerializer } from "../models/topUpResponse.js"; +import { CreditsGrants } from "./creditsGrants.js"; +import { CreditsWallets } from "./creditsWallets.js"; +import type { APIPromise } from "../apiPromise.js"; +import { PagePromise } from "../pagination.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `listCustomerCreditLedger`. */ +export interface CreditsListCustomerCreditLedgerOptions { + /** Defaults to the customer's currency. */ + currency?: Currency | undefined; + /** The ledger of this credit unit (its code) instead of a currency; excludes `currency`. */ + creditUnit?: string | undefined; + /** Page number (0-indexed) */ + page?: number | undefined; + /** Number of items per page */ + perPage?: number | undefined; +} + +/** The query and header parameters of `createCustomerTopUp`. */ +export interface CreditsCreateCustomerTopUpOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The credits operations, reached through the client's `credits`. */ +export class Credits { + private _grants?: CreditsGrants; + private _wallets?: CreditsWallets; + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** The grants operations. */ + public get grants(): CreditsGrants { + this._grants ??= new CreditsGrants(this.requestCtx); + return this._grants; + } + + /** The wallets operations. */ + public get wallets(): CreditsWallets { + this._wallets ??= new CreditsWallets(this.requestCtx); + return this._wallets; + } + + /** + * List credit ledger entries + * + * Every movement of a customer's credit in one currency or credit unit, newest first, with the + * credit on account after it: credit granted, applied to invoices, given back, expired or + * rolled over. + * + * Await it for the first page: the response body, its properties read on the page, with + * `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`. Or iterate it with `for await` + * over every item of every page, fetched on demand. + */ + public listCustomerCreditLedger( + idOrAlias: string, + options?: CreditsListCustomerCreditLedgerOptions, + requestOptions?: RequestOptions + ): PagePromise { + return new PagePromise( + { + style: "page", + items: (page) => page.data, + totalPages: (page) => page.paginationMeta?.totalPages, + firstPage: 0, + fetch: (page) => + this.#listCustomerCreditLedger( + idOrAlias, + { ...options, page: page }, + requestOptions + ), + }, + options?.page + ); + } + + #listCustomerCreditLedger( + idOrAlias: string, + options?: CreditsListCustomerCreditLedgerOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/customers/{id_or_alias}/credit-ledger" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setQueryParam("currency", options?.currency); + request.setQueryParam("credit_unit", options?.creditUnit); + request.setQueryParam("page", options?.page); + request.setQueryParam("per_page", options?.perPage); + return request.send( + this.requestCtx, + LedgerListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Create a top-up + * + * Sells credit: CHARGE bills a saved payment method now, SEND_INVOICE grants it once paid. The + * credit is PAID and applies to ALL charges. Currency credit is sold one for one, untaxed, as + * its usage is taxed when invoiced. With `credit_unit`, sells credits of that unit at its + * selling price in the customer's currency, taxed at purchase under the unit's product; refused + * when the unit has no price in that currency or no product. Without a saved payment method, + * CHARGE returns a hosted `checkout_url` where the customer pays. + */ + public createCustomerTopUp( + idOrAlias: string, + createTopUpRequest: CreateTopUpRequest, + options: CreditsCreateCustomerTopUpOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "POST", + "/api/v1/customers/{id_or_alias}/top-ups" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + request.setBody(CreateTopUpRequestSerializer.serialize(createTopUpRequest)); + return request.send(this.requestCtx, TopUpResponseSerializer.parse, requestOptions); + } +} diff --git a/src/api/creditsGrants.ts b/src/api/creditsGrants.ts new file mode 100644 index 0000000..59cb3d4 --- /dev/null +++ b/src/api/creditsGrants.ts @@ -0,0 +1,137 @@ +// this file is @generated + +import { + type CreateCreditGrantRequest, + CreateCreditGrantRequestSerializer, +} from "../models/createCreditGrantRequest.js"; +import { type CreditGrant, CreditGrantSerializer } from "../models/creditGrant.js"; +import { + type CreditGrantListResponse, + CreditGrantListResponseSerializer, +} from "../models/creditGrantListResponse.js"; +import type { CreditGrantStatus } from "../models/creditGrantStatus.js"; +import type { Currency } from "../models/currency.js"; +import type { APIPromise } from "../apiPromise.js"; +import { PagePromise } from "../pagination.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `list`. */ +export interface CreditsGrantsListOptions { + /** Only grants in this currency. */ + currency?: Currency | undefined; + /** Only grants in this credit unit (its code); excludes `currency`. */ + creditUnit?: string | undefined; + status?: CreditGrantStatus | undefined; + /** + * Only the grants that belong to this subscription (`sub_…`); excludes + * `usable_by_subscription_id`. + */ + subscriptionId?: string | undefined; + /** + * Only the credit this subscription (`sub_…`) can use: its own grants and the customer's + * grants that belong to no subscription. Excludes `subscription_id`. + */ + usableBySubscriptionId?: string | undefined; + /** Page number (0-indexed) */ + page?: number | undefined; + /** Number of items per page */ + perPage?: number | undefined; +} + +/** The query and header parameters of `create`. */ +export interface CreditsGrantsCreateOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The credits grants operations, reached through the client's `credits.grants`. */ +export class CreditsGrants { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List credit grants + * + * A customer's credit grants, newest first, in every currency and credit unit unless filtered. + * + * Await it for the first page: the response body, its properties read on the page, with + * `items`, `hasNextPage()`, `getNextPage()` and `iterPages()`. Or iterate it with `for await` + * over every item of every page, fetched on demand. + */ + public list( + idOrAlias: string, + options?: CreditsGrantsListOptions, + requestOptions?: RequestOptions + ): PagePromise { + return new PagePromise( + { + style: "page", + items: (page) => page.data, + totalPages: (page) => page.paginationMeta?.totalPages, + firstPage: 0, + fetch: (page) => + this.#list(idOrAlias, { ...options, page: page }, requestOptions), + }, + options?.page + ); + } + + #list( + idOrAlias: string, + options?: CreditsGrantsListOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/customers/{id_or_alias}/credit-grants" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setQueryParam("currency", options?.currency); + request.setQueryParam("credit_unit", options?.creditUnit); + request.setQueryParam("status", options?.status); + request.setQueryParam("subscription_id", options?.subscriptionId); + request.setQueryParam("usable_by_subscription_id", options?.usableBySubscriptionId); + request.setQueryParam("page", options?.page); + request.setQueryParam("per_page", options?.perPage); + return request.send( + this.requestCtx, + CreditGrantListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Create a credit grant + * + * Grants credit without charging or invoicing: PROMOTIONAL credit for free, or PAID credit the + * customer paid for outside Meteroid ("Paid outside Meteroid"). A PAID currency grant whose + * `cost` is below its `amount` is split into a PAID grant for the cost and a PROMOTIONAL bonus + * grant for the rest, returned as `bonus_grant_id`; a `cost` above the `amount` is refused. + * For a customer of a French invoicing entity, PAID credit that cost more than zero needs a + * `reference` to the invoice or receipt of its payment. Sell credit through Meteroid with a + * top-up. + */ + public create( + idOrAlias: string, + createCreditGrantRequest: CreateCreditGrantRequest, + options: CreditsGrantsCreateOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "POST", + "/api/v1/customers/{id_or_alias}/credit-grants" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + request.setBody( + CreateCreditGrantRequestSerializer.serialize(createCreditGrantRequest) + ); + return request.send(this.requestCtx, CreditGrantSerializer.parse, requestOptions); + } +} diff --git a/src/api/creditsWallets.ts b/src/api/creditsWallets.ts new file mode 100644 index 0000000..a50d9a4 --- /dev/null +++ b/src/api/creditsWallets.ts @@ -0,0 +1,144 @@ +// this file is @generated + +import type { Currency } from "../models/currency.js"; +import { + type PatchWalletRequest, + PatchWalletRequestSerializer, +} from "../models/patchWalletRequest.js"; +import type { ProductId } from "../models/productId.js"; +import type { SubscriptionId } from "../models/subscriptionId.js"; +import { type Wallet, WalletSerializer } from "../models/wallet.js"; +import { type WalletCheck, WalletCheckSerializer } from "../models/walletCheck.js"; +import { + type WalletListResponse, + WalletListResponseSerializer, +} from "../models/walletListResponse.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `list`. */ +export interface CreditsWalletsListOptions { + /** + * Only the credit this subscription (`sub_…`) can use: the credit that belongs to it and + * the customer's credit that belongs to no subscription. Every wallet is still listed. + */ + subscriptionId?: SubscriptionId | undefined; +} + +/** The query and header parameters of `check`. */ +export interface CreditsWalletsCheckOptions { + /** Defaults to the customer's currency. */ + currency?: Currency | undefined; + /** Checks the wallet of this credit unit (its code) instead of a currency. */ + creditUnit?: string | undefined; + /** + * Checks only the credit that can pay for this product: credit not restricted to products, + * and credit restricted to it. Absent checks all credit. + */ + productId?: ProductId | undefined; + /** + * Checks only the credit this subscription (`sub_…`) can spend, net of its own usage no + * credit pays: the credit that belongs to it and the customer's credit that belongs to no + * subscription, once every subscription's unbilled usage is paid. `has_access` is then the + * decision the access gate makes for that subscription's usage. Absent checks the + * customer's credit as a whole. + */ + subscriptionId?: SubscriptionId | undefined; +} + +/** The query and header parameters of `update`. */ +export interface CreditsWalletsUpdateOptions { + /** Sent as the `Idempotency-Key` header. */ + idempotencyKey: string; +} + +/** The credits wallets operations, reached through the client's `credits.wallets`. */ +export class CreditsWallets { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List wallets + * + * A customer's credit per currency and credit unit: the credit on account, the usage not + * invoiced yet and the balance left after it, with the wallet's alerts and automatic top-up. The + * customer's own currency comes first, even when empty. With `subscription_id`, each wallet + * counts only the credit that subscription can use. + */ + public list( + idOrAlias: string, + options?: CreditsWalletsListOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/customers/{id_or_alias}/wallets"); + + request.setPathParam("id_or_alias", idOrAlias); + request.setQueryParam("subscription_id", options?.subscriptionId); + return request.send( + this.requestCtx, + WalletListResponseSerializer.parse, + requestOptions + ); + } + + /** + * Check wallet access + * + * Whether the customer's prepaid credit in a currency or credit unit still covers them, net of + * usage not invoiced yet. Denies only when the wallet blocks usage once its credit is used up; + * otherwise access stays allowed and `exhausted` signals the empty balance on its own. With + * `subscription_id`, only the credit that subscription can use counts: pass it when the + * customer has several subscriptions, since one subscription's credit cannot pay another's + * usage. The balance follows usage within a few seconds near zero or a threshold, within a + * minute otherwise, and the answer is cached for one second: use it to gate consumption, not + * to bill. + */ + public check( + idOrAlias: string, + options?: CreditsWalletsCheckOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/customers/{id_or_alias}/wallets/check" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setQueryParam("currency", options?.currency); + request.setQueryParam("credit_unit", options?.creditUnit); + request.setQueryParam("product_id", options?.productId); + request.setQueryParam("subscription_id", options?.subscriptionId); + return request.send(this.requestCtx, WalletCheckSerializer.parse, requestOptions); + } + + /** + * Configure a wallet + * + * Settings of a customer's wallet in one currency or credit unit: whether usage is refused + * once its credit is used up, the balances that fire `wallet.balance_low`, and its automatic + * top-up. Opens the wallet if it does not exist yet. Partial update: omit a field to leave it + * unchanged. + */ + public update( + idOrAlias: string, + currency: string, + patchWalletRequest: PatchWalletRequest, + options: CreditsWalletsUpdateOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "PATCH", + "/api/v1/customers/{id_or_alias}/wallets/{currency}" + ); + + request.setPathParam("id_or_alias", idOrAlias); + request.setPathParam("currency", currency); + request.setHeaderParam("Idempotency-Key", options.idempotencyKey); + request.setBody(PatchWalletRequestSerializer.serialize(patchWalletRequest)); + return request.send(this.requestCtx, WalletSerializer.parse, requestOptions); + } +} diff --git a/src/api/features.ts b/src/api/features.ts index 35a4665..52c5254 100644 --- a/src/api/features.ts +++ b/src/api/features.ts @@ -125,7 +125,8 @@ export class Features { /** * Archive a feature * - * Keeps the feature and its entitlements but hides them from resolution. + * Turns the feature off and hides it and its entitlements until it is unarchived, and frees its + * code for a new feature. */ public archive(idOrCode: string, requestOptions?: RequestOptions): APIPromise { const request = new MeteroidRequest("POST", "/api/v1/features/{id_or_code}/archive"); @@ -134,7 +135,12 @@ export class Features { return request.sendNoResponseBody(this.requestCtx, requestOptions); } - /** Unarchive a feature */ + /** + * Unarchive a feature + * + * Makes the feature active again with all its entitlements. Fails while another feature uses its + * code. + */ public unarchive(idOrCode: string, requestOptions?: RequestOptions): APIPromise { const request = new MeteroidRequest( "POST", diff --git a/src/api/plans.ts b/src/api/plans.ts index 033c3de..115e52d 100644 --- a/src/api/plans.ts +++ b/src/api/plans.ts @@ -202,7 +202,9 @@ export class Plans { * * Full replacement of a plan's version. On a draft plan, updates in-place. * On a published plan, creates a new version. Set `status` to `DRAFT` to - * stage as a new draft without publishing. + * stage as a new draft without publishing. A usage or capacity component priced in a credit + * unit must be sent with its `credit_unit`, or the request is refused: omitting it would bill + * its credits as money. */ public replace( planId: string, diff --git a/src/api/usage.ts b/src/api/usage.ts index d658c66..cd6fe11 100644 --- a/src/api/usage.ts +++ b/src/api/usage.ts @@ -2,6 +2,7 @@ import type { BillableMetricId } from "../models/billableMetricId.js"; import { type UsageResponse, UsageResponseSerializer } from "../models/usageResponse.js"; +import { UsageCustomer } from "./usageCustomer.js"; import type { APIPromise } from "../apiPromise.js"; import { MeteroidRequest, @@ -9,13 +10,6 @@ import { type RequestOptions, } from "../request.js"; -/** The query and header parameters of `retrieveCustomer`. */ -export interface UsageRetrieveCustomerOptions { - startDate: string; - endDate: string; - metricId?: BillableMetricId | undefined; -} - /** The query and header parameters of `retrieveSubscription`. */ export interface UsageRetrieveSubscriptionOptions { startDate?: string | undefined; @@ -32,33 +26,24 @@ export interface UsageRetrieveSummaryOptions { /** The usage operations, reached through the client's `usage`. */ export class Usage { + private _customer?: UsageCustomer; /** @internal */ public constructor(private readonly requestCtx: MeteroidRequestContext) {} - /** - * Get customer usage - * - * Retrieve aggregated usage data for a customer over a specified period. - */ - public retrieveCustomer( - customerId: string, - options: UsageRetrieveCustomerOptions, - requestOptions?: RequestOptions - ): APIPromise { - const request = new MeteroidRequest("GET", "/api/v1/usage/customer/{customer_id}"); - - request.setPathParam("customer_id", customerId); - request.setQueryParam("start_date", options.startDate); - request.setQueryParam("end_date", options.endDate); - request.setQueryParam("metric_id", options?.metricId); - return request.send(this.requestCtx, UsageResponseSerializer.parse, requestOptions); + /** The customer operations. */ + public get customer(): UsageCustomer { + this._customer ??= new UsageCustomer(this.requestCtx); + return this._customer; } /** * Get subscription usage * * Retrieve aggregated usage data for a subscription's usage-based components. - * If start_date/end_date are omitted, defaults to the current billing period. + * If start_date/end_date are omitted, defaults to the current billing period, and the response + * then carries the running total (beta): what each metric's usage adds so far to the next invoice, + * and what they add up to, before discounts and credits. That reading is shared for up to 30 + * seconds (see `computed_at`). Counts towards the usage cost reads' rate limit. */ public retrieveSubscription( subscriptionId: string, diff --git a/src/api/usageCosts.ts b/src/api/usageCosts.ts new file mode 100644 index 0000000..ac1a261 --- /dev/null +++ b/src/api/usageCosts.ts @@ -0,0 +1,25 @@ +// this file is @generated + +import { UsageCostsCustomer } from "./usageCostsCustomer.js"; +import { UsageCostsSubscription } from "./usageCostsSubscription.js"; +import type { MeteroidRequestContext } from "../request.js"; + +/** The usage costs operations, reached through the client's `usageCosts`. */ +export class UsageCosts { + private _customer?: UsageCostsCustomer; + private _subscription?: UsageCostsSubscription; + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** The customer operations. */ + public get customer(): UsageCostsCustomer { + this._customer ??= new UsageCostsCustomer(this.requestCtx); + return this._customer; + } + + /** The subscription operations. */ + public get subscription(): UsageCostsSubscription { + this._subscription ??= new UsageCostsSubscription(this.requestCtx); + return this._subscription; + } +} diff --git a/src/api/usageCostsCustomer.ts b/src/api/usageCostsCustomer.ts new file mode 100644 index 0000000..f0fb861 --- /dev/null +++ b/src/api/usageCostsCustomer.ts @@ -0,0 +1,118 @@ +// this file is @generated + +import type { ListCustomerUsageCostsGranularity } from "../models/listCustomerUsageCostsGranularity.js"; +import { + type UsageCostListResponse, + UsageCostListResponseSerializer, +} from "../models/usageCostListResponse.js"; +import { + type UsageEventListResponse, + UsageEventListResponseSerializer, +} from "../models/usageEventListResponse.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `listCosts`. */ +export interface UsageCostsCustomerListCostsOptions { + /** Billable metric, by ID or code. */ + metric: string; + /** Event property to split the usage by. */ + groupBy?: string | undefined; + granularity: ListCustomerUsageCostsGranularity; + /** Start of the range, inclusive. */ + from: Date; + /** End of the range, exclusive. At most 93 days after `from`. */ + to: Date; +} + +/** The query and header parameters of `listEvents`. */ +export interface UsageCostsCustomerListEventsOptions { + /** Billable metric, by ID or code. */ + metric: string; + /** Start of the range, inclusive. */ + from: Date; + /** End of the range, exclusive. At most 93 days after `from`. */ + to: Date; + /** The `next_cursor` of the previous page. */ + cursor?: string | undefined; + /** Page size, 100 by default and 500 at most. */ + limit?: number | undefined; +} + +/** The usage costs customer operations, reached through the client's `usageCosts.customer`. */ +export class UsageCostsCustomer { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List a customer's usage costs over time + * + * A customer's usage of one billable metric and what it costs, per hour, day or month, optionally + * split by an event property, summed across the subscriptions that bill it. Buckets are cut at UTC + * boundaries and only cover the customer's billing periods. Per-unit and matrix pricing give exact + * costs. For pricing that depends on the whole period's usage (tiered, volume, package, capacity), + * a bucket's cost is what it adds to the period's price so far and `exact` is false. The range is + * at most 93 days. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public listCosts( + customerId: string, + options: UsageCostsCustomerListCostsOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/usage/customer/{customer_id}/costs" + ); + + request.setPathParam("customer_id", customerId); + request.setQueryParam("metric", options.metric); + request.setQueryParam("group_by", options?.groupBy); + request.setQueryParam("granularity", options.granularity); + request.setQueryParam("from", options.from); + request.setQueryParam("to", options.to); + return request.send( + this.requestCtx, + UsageCostListResponseSerializer.parse, + requestOptions + ); + } + + /** + * List a customer's usage events with their cost + * + * A customer's events for one billable metric, oldest first, each with the units it adds and what + * they cost at the price in force. The cost is exact for per-unit and matrix pricing and absent + * for pricing that depends on the whole period's usage (tiered, volume, package, capacity) and for + * aggregations that cannot be split per event. The range is at most 93 days. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public listEvents( + customerId: string, + options: UsageCostsCustomerListEventsOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/usage/customer/{customer_id}/events" + ); + + request.setPathParam("customer_id", customerId); + request.setQueryParam("metric", options.metric); + request.setQueryParam("from", options.from); + request.setQueryParam("to", options.to); + request.setQueryParam("cursor", options?.cursor); + request.setQueryParam("limit", options?.limit); + return request.send( + this.requestCtx, + UsageEventListResponseSerializer.parse, + requestOptions + ); + } +} diff --git a/src/api/usageCostsSubscription.ts b/src/api/usageCostsSubscription.ts new file mode 100644 index 0000000..dd75a19 --- /dev/null +++ b/src/api/usageCostsSubscription.ts @@ -0,0 +1,114 @@ +// this file is @generated + +import type { ListSubscriptionUsageCostsGranularity } from "../models/listSubscriptionUsageCostsGranularity.js"; +import { + type UsageCostListResponse, + UsageCostListResponseSerializer, +} from "../models/usageCostListResponse.js"; +import { + type UsageEventListResponse, + UsageEventListResponseSerializer, +} from "../models/usageEventListResponse.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `listCosts`. */ +export interface UsageCostsSubscriptionListCostsOptions { + /** Billable metric, by ID or code. */ + metric: string; + /** Event property to split the usage by. */ + groupBy?: string | undefined; + granularity: ListSubscriptionUsageCostsGranularity; + /** Start of the range, inclusive. */ + from: Date; + /** End of the range, exclusive. At most 93 days after `from`. */ + to: Date; +} + +/** The query and header parameters of `listEvents`. */ +export interface UsageCostsSubscriptionListEventsOptions { + /** Billable metric, by ID or code. */ + metric: string; + /** Start of the range, inclusive. */ + from: Date; + /** End of the range, exclusive. At most 93 days after `from`. */ + to: Date; + /** The `next_cursor` of the previous page. */ + cursor?: string | undefined; + /** Page size, 100 by default and 500 at most. */ + limit?: number | undefined; +} + +/** The usage costs subscription operations, reached through the client's `usageCosts.subscription`. */ +export class UsageCostsSubscription { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * List a subscription's usage costs over time + * + * The subscription's usage of one billable metric and what it costs, as for a customer but + * counting only the events the subscription bills (see its usage filter) and only its own billing + * periods. The range is at most 93 days. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public listCosts( + subscriptionId: string, + options: UsageCostsSubscriptionListCostsOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/usage/subscription/{subscription_id}/costs" + ); + + request.setPathParam("subscription_id", subscriptionId); + request.setQueryParam("metric", options.metric); + request.setQueryParam("group_by", options?.groupBy); + request.setQueryParam("granularity", options.granularity); + request.setQueryParam("from", options.from); + request.setQueryParam("to", options.to); + return request.send( + this.requestCtx, + UsageCostListResponseSerializer.parse, + requestOptions + ); + } + + /** + * List a subscription's usage events with their cost + * + * The events of one billable metric that the subscription bills, oldest first: with a usage + * filter, only the customer's events matching it; without, those no other subscription's filter + * claims. Costs are as for the customer's events. The range is at most 93 days. + * + * Beta: the request and response shapes of this endpoint may change before general availability. + */ + public listEvents( + subscriptionId: string, + options: UsageCostsSubscriptionListEventsOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/usage/subscription/{subscription_id}/events" + ); + + request.setPathParam("subscription_id", subscriptionId); + request.setQueryParam("metric", options.metric); + request.setQueryParam("from", options.from); + request.setQueryParam("to", options.to); + request.setQueryParam("cursor", options?.cursor); + request.setQueryParam("limit", options?.limit); + return request.send( + this.requestCtx, + UsageEventListResponseSerializer.parse, + requestOptions + ); + } +} diff --git a/src/api/usageCustomer.ts b/src/api/usageCustomer.ts new file mode 100644 index 0000000..449764f --- /dev/null +++ b/src/api/usageCustomer.ts @@ -0,0 +1,82 @@ +// this file is @generated + +import type { BillableMetricId } from "../models/billableMetricId.js"; +import { + type UnattributedUsageResponse, + UnattributedUsageResponseSerializer, +} from "../models/unattributedUsageResponse.js"; +import { type UsageResponse, UsageResponseSerializer } from "../models/usageResponse.js"; +import type { APIPromise } from "../apiPromise.js"; +import { + MeteroidRequest, + type MeteroidRequestContext, + type RequestOptions, +} from "../request.js"; + +/** The query and header parameters of `retrieve`. */ +export interface UsageCustomerRetrieveOptions { + startDate: string; + endDate: string; + metricId?: BillableMetricId | undefined; +} + +/** The query and header parameters of `retrieveUnattributed`. */ +export interface UsageCustomerRetrieveUnattributedOptions { + /** First day of the range. Defaults to the first day of the current month (UTC). */ + startDate?: string | undefined; + /** Day after the range (exclusive). Defaults to the first day of the next month. */ + endDate?: string | undefined; +} + +/** The usage customer operations, reached through the client's `usage.customer`. */ +export class UsageCustomer { + /** @internal */ + public constructor(private readonly requestCtx: MeteroidRequestContext) {} + + /** + * Get customer usage + * + * Retrieve aggregated usage data for a customer over a specified period. + */ + public retrieve( + customerId: string, + options: UsageCustomerRetrieveOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest("GET", "/api/v1/usage/customer/{customer_id}"); + + request.setPathParam("customer_id", customerId); + request.setQueryParam("start_date", options.startDate); + request.setQueryParam("end_date", options.endDate); + request.setQueryParam("metric_id", options?.metricId); + return request.send(this.requestCtx, UsageResponseSerializer.parse, requestOptions); + } + + /** + * Get unattributed usage + * + * Retrieve a customer's usage that no subscription bills. When subscriptions of the customer + * pricing a metric set a usage filter, events matching none of the filters are billed by a + * subscription without one; when every such subscription has a filter, those events are kept + * and reported here instead of being billed. + */ + public retrieveUnattributed( + customerId: string, + options?: UsageCustomerRetrieveUnattributedOptions, + requestOptions?: RequestOptions + ): APIPromise { + const request = new MeteroidRequest( + "GET", + "/api/v1/usage/customer/{customer_id}/unattributed" + ); + + request.setPathParam("customer_id", customerId); + request.setQueryParam("start_date", options?.startDate); + request.setQueryParam("end_date", options?.endDate); + return request.send( + this.requestCtx, + UnattributedUsageResponseSerializer.parse, + requestOptions + ); + } +} diff --git a/src/index.ts b/src/index.ts index 1517939..88a61a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,14 @@ // this file is @generated import { AddOns } from "./api/addOns.js"; import { BatchJobs } from "./api/batchJobs.js"; +import { Budgets } from "./api/budgets.js"; import { CheckoutSessions } from "./api/checkoutSessions.js"; +import { Checks } from "./api/checks.js"; import { Connect } from "./api/connect.js"; import { Coupons } from "./api/coupons.js"; import { CreditNotes } from "./api/creditNotes.js"; +import { CreditUnits } from "./api/creditUnits.js"; +import { Credits } from "./api/credits.js"; import { CustomProperties } from "./api/customProperties.js"; import { Customers } from "./api/customers.js"; import { Entitlements } from "./api/entitlements.js"; @@ -19,6 +23,7 @@ import { ProductFamilies } from "./api/productFamilies.js"; import { Products } from "./api/products.js"; import { Subscriptions } from "./api/subscriptions.js"; import { Usage } from "./api/usage.js"; +import { UsageCosts } from "./api/usageCosts.js"; import { WebhookEndpoints } from "./api/webhookEndpoints.js"; import type { Security, SecurityScheme } from "./auth.js"; import type { Middleware } from "./middleware.js"; @@ -79,13 +84,34 @@ export { AddOnsEntitlements } from "./api/addOnsEntitlements.js"; export { BatchJobs } from "./api/batchJobs.js"; export type { BatchJobsListOptions } from "./api/batchJobs.js"; export type { BatchJobsListFailuresOptions } from "./api/batchJobs.js"; +export { Budgets } from "./api/budgets.js"; +export type { BudgetsListOptions } from "./api/budgets.js"; +export type { BudgetsCreateOptions } from "./api/budgets.js"; +export type { BudgetsUpdateOptions } from "./api/budgets.js"; +export type { BudgetsArchiveOptions } from "./api/budgets.js"; export { CheckoutSessions } from "./api/checkoutSessions.js"; export type { CheckoutSessionsListOptions } from "./api/checkoutSessions.js"; +export { Checks } from "./api/checks.js"; +export type { ChecksCheckEntitlementOptions } from "./api/checks.js"; export { Connect } from "./api/connect.js"; export { Coupons } from "./api/coupons.js"; export type { CouponsListOptions } from "./api/coupons.js"; export { CreditNotes } from "./api/creditNotes.js"; export type { CreditNotesListOptions } from "./api/creditNotes.js"; +export { CreditUnits } from "./api/creditUnits.js"; +export type { CreditUnitsListOptions } from "./api/creditUnits.js"; +export { CreditUnitsPrices } from "./api/creditUnitsPrices.js"; +export type { CreditUnitsPricesListOptions } from "./api/creditUnitsPrices.js"; +export { Credits } from "./api/credits.js"; +export type { CreditsListCustomerCreditLedgerOptions } from "./api/credits.js"; +export type { CreditsCreateCustomerTopUpOptions } from "./api/credits.js"; +export { CreditsGrants } from "./api/creditsGrants.js"; +export type { CreditsGrantsListOptions } from "./api/creditsGrants.js"; +export type { CreditsGrantsCreateOptions } from "./api/creditsGrants.js"; +export { CreditsWallets } from "./api/creditsWallets.js"; +export type { CreditsWalletsListOptions } from "./api/creditsWallets.js"; +export type { CreditsWalletsCheckOptions } from "./api/creditsWallets.js"; +export type { CreditsWalletsUpdateOptions } from "./api/creditsWallets.js"; export { CustomProperties } from "./api/customProperties.js"; export type { CustomPropertiesListCustomPropertyDefinitionsOptions } from "./api/customProperties.js"; export { Customers } from "./api/customers.js"; @@ -113,9 +139,18 @@ export { ProductsEntitlements } from "./api/productsEntitlements.js"; export { Subscriptions } from "./api/subscriptions.js"; export type { SubscriptionsListOptions } from "./api/subscriptions.js"; export { Usage } from "./api/usage.js"; -export type { UsageRetrieveCustomerOptions } from "./api/usage.js"; export type { UsageRetrieveSubscriptionOptions } from "./api/usage.js"; export type { UsageRetrieveSummaryOptions } from "./api/usage.js"; +export { UsageCustomer } from "./api/usageCustomer.js"; +export type { UsageCustomerRetrieveOptions } from "./api/usageCustomer.js"; +export type { UsageCustomerRetrieveUnattributedOptions } from "./api/usageCustomer.js"; +export { UsageCosts } from "./api/usageCosts.js"; +export { UsageCostsCustomer } from "./api/usageCostsCustomer.js"; +export type { UsageCostsCustomerListCostsOptions } from "./api/usageCostsCustomer.js"; +export type { UsageCostsCustomerListEventsOptions } from "./api/usageCostsCustomer.js"; +export { UsageCostsSubscription } from "./api/usageCostsSubscription.js"; +export type { UsageCostsSubscriptionListCostsOptions } from "./api/usageCostsSubscription.js"; +export type { UsageCostsSubscriptionListEventsOptions } from "./api/usageCostsSubscription.js"; export { WebhookEndpoints } from "./api/webhookEndpoints.js"; export { WebhookEndpointsEndpoints } from "./api/webhookEndpointsEndpoints.js"; export type { WebhookEndpointsEndpointsListDeliveriesOptions } from "./api/webhookEndpointsEndpoints.js"; @@ -198,10 +233,14 @@ export class Meteroid { private readonly requestCtx: MeteroidRequestContext; private _addOns?: AddOns; private _batchJobs?: BatchJobs; + private _budgets?: Budgets; private _checkoutSessions?: CheckoutSessions; + private _checks?: Checks; private _connect?: Connect; private _coupons?: Coupons; private _creditNotes?: CreditNotes; + private _creditUnits?: CreditUnits; + private _credits?: Credits; private _customProperties?: CustomProperties; private _customers?: Customers; private _entitlements?: Entitlements; @@ -216,6 +255,7 @@ export class Meteroid { private _products?: Products; private _subscriptions?: Subscriptions; private _usage?: Usage; + private _usageCosts?: UsageCosts; private _webhookEndpoints?: WebhookEndpoints; /** @@ -255,12 +295,24 @@ export class Meteroid { return this._batchJobs; } + /** The budgets API. */ + public get budgets(): Budgets { + this._budgets ??= new Budgets(this.requestCtx); + return this._budgets; + } + /** The checkout sessions API. */ public get checkoutSessions(): CheckoutSessions { this._checkoutSessions ??= new CheckoutSessions(this.requestCtx); return this._checkoutSessions; } + /** The checks API. */ + public get checks(): Checks { + this._checks ??= new Checks(this.requestCtx); + return this._checks; + } + /** The connect API. */ public get connect(): Connect { this._connect ??= new Connect(this.requestCtx); @@ -279,6 +331,18 @@ export class Meteroid { return this._creditNotes; } + /** The credit units API. */ + public get creditUnits(): CreditUnits { + this._creditUnits ??= new CreditUnits(this.requestCtx); + return this._creditUnits; + } + + /** The credits API. */ + public get credits(): Credits { + this._credits ??= new Credits(this.requestCtx); + return this._credits; + } + /** The custom properties API. */ public get customProperties(): CustomProperties { this._customProperties ??= new CustomProperties(this.requestCtx); @@ -363,6 +427,12 @@ export class Meteroid { return this._usage; } + /** The usage costs API. */ + public get usageCosts(): UsageCosts { + this._usageCosts ??= new UsageCosts(this.requestCtx); + return this._usageCosts; + } + /** The webhook endpoints API. */ public get webhookEndpoints(): WebhookEndpoints { this._webhookEndpoints ??= new WebhookEndpoints(this.requestCtx); diff --git a/src/models/actor.ts b/src/models/actor.ts new file mode 100644 index 0000000..ba13813 --- /dev/null +++ b/src/models/actor.ts @@ -0,0 +1,34 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; +import { type ActorType, ActorTypeSerializer } from "./actorType.js"; +/** Who made a change. */ +export interface Actor { + /** + * The user's id (`usr_…`) for USER, the customer's (`cus_…`) for CUSTOMER, the API key's + * or app's for API_KEY and OAUTH_APP; absent for SYSTEM. + */ + id?: string | null | undefined; + /** USER, CUSTOMER, API_KEY, OAUTH_APP or SYSTEM. */ + type: ActorType; +} + +/** Converts `Actor` values from (`parse`) and to (`serialize`) their JSON form. */ +export const ActorSerializer = { + parse(json: any, path = "$"): Actor { + decodeObject(json, path); + return { + ...extraProperties(json, ["id", "type"]), + id: json["id"] != null ? decodeString(json["id"], path, "id") : json["id"], + type: ActorTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: Actor): any { + return { + ...extraProperties(value, ["id", "type"]), + id: value.id, + type: ActorTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/actorType.ts b/src/models/actorType.ts new file mode 100644 index 0000000..2e1b88d --- /dev/null +++ b/src/models/actorType.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const ActorType = { + User: "USER", + Customer: "CUSTOMER", + System: "SYSTEM", + ApiKey: "API_KEY", + OauthApp: "OAUTH_APP", +} as const; +export type ActorType = (typeof ActorType)[keyof typeof ActorType] | (string & {}); + +/** Converts `ActorType` values from (`parse`) and to (`serialize`) their JSON form. */ +export const ActorTypeSerializer = { + parse(json: any, path = "$"): ActorType { + return decodeString(json, path); + }, + + serialize(value: ActorType): any { + return value; + }, +}; diff --git a/src/models/allComponentsScope.ts b/src/models/allComponentsScope.ts index 0f3440f..7d789fa 100644 --- a/src/models/allComponentsScope.ts +++ b/src/models/allComponentsScope.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; /** Every revenue line counts toward the floor. */ -export interface AllComponentsScope {} +export interface AllComponentsScope { + type: "all_components"; +} /** Converts `AllComponentsScope` values from (`parse`) and to (`serialize`) their JSON form. */ export const AllComponentsScopeSerializer = { parse(json: any, path = "$"): AllComponentsScope { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "all_components") + : "all_components", }; }, serialize(value: AllComponentsScope): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "all_components", }; }, }; diff --git a/src/models/autoTopUp.ts b/src/models/autoTopUp.ts new file mode 100644 index 0000000..24c0f11 --- /dev/null +++ b/src/models/autoTopUp.ts @@ -0,0 +1,166 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type AutoTopUpMethod, AutoTopUpMethodSerializer } from "./autoTopUpMethod.js"; +import { type AutoTopUpStatus, AutoTopUpStatusSerializer } from "./autoTopUpStatus.js"; +/** + * Automatic top-up of the credit that applies to ALL charges: it charges the customer's payment + * method when the balance falls below `threshold`. + */ +export interface AutoTopUp { + /** FIXED only: credit bought each time, in minor units of the wallet. */ + amount?: number | null | undefined; + /** + * When an operator attested that the customer agreed to automatic charges on exactly these + * terms. Absent when the customer confirmed them in their portal, or the terms changed since. + */ + customerConsentAttestedAt?: Date | null | undefined; + /** + * Most charged in a rolling day, tax included. For a credit unit wallet caps are money, in + * minor units of the customer's currency. + */ + dailyCap?: number | null | undefined; + /** Why the last charge failed; may carry payment provider detail. */ + lastError?: string | null | undefined; + /** The last charge that succeeded. */ + lastSucceededAt?: Date | null | undefined; + /** Largest single charge, in the same money as `minimum`. */ + maximum?: number | null | undefined; + /** FIXED buys `amount` each time; TO_TARGET buys back up to `target`. */ + method: AutoTopUpMethod; + /** + * Smallest single charge. For a credit unit wallet it is money (the price before tax, in + * minor units of the customer's currency), like the caps; the threshold, amount and target + * are credits. + */ + minimum?: number | null | undefined; + /** Most charged in a calendar month (UTC), tax included. */ + monthlyCap?: number | null | undefined; + /** Absent charges the customer's default payment method. */ + paymentMethodId?: string | null | undefined; + /** ACTIVE, DISABLED (terms kept) or SUSPENDED after repeated failed charges. */ + status: AutoTopUpStatus; + /** Set while SUSPENDED: since when. */ + suspendedAt?: Date | null | undefined; + /** TO_TARGET only: the balance a top-up brings the wallet back to, in minor units. */ + target?: number | null | undefined; + /** Tops up once the balance is at or below this, in minor units of the wallet. */ + threshold: number; +} + +/** Converts `AutoTopUp` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpSerializer = { + parse(json: any, path = "$"): AutoTopUp { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "customer_consent_attested_at", + "daily_cap", + "last_error", + "last_succeeded_at", + "maximum", + "method", + "minimum", + "monthly_cap", + "payment_method_id", + "status", + "suspended_at", + "target", + "threshold", + ]), + amount: + json["amount"] != null + ? decodeInteger(json["amount"], path, "amount") + : json["amount"], + customerConsentAttestedAt: + json["customer_consent_attested_at"] != null + ? decodeDateTime( + json["customer_consent_attested_at"], + path, + "customer_consent_attested_at" + ) + : json["customer_consent_attested_at"], + dailyCap: + json["daily_cap"] != null + ? decodeInteger(json["daily_cap"], path, "daily_cap") + : json["daily_cap"], + lastError: + json["last_error"] != null + ? decodeString(json["last_error"], path, "last_error") + : json["last_error"], + lastSucceededAt: + json["last_succeeded_at"] != null + ? decodeDateTime(json["last_succeeded_at"], path, "last_succeeded_at") + : json["last_succeeded_at"], + maximum: + json["maximum"] != null + ? decodeInteger(json["maximum"], path, "maximum") + : json["maximum"], + method: AutoTopUpMethodSerializer.parse(json["method"], decodePath(path, "method")), + minimum: + json["minimum"] != null + ? decodeInteger(json["minimum"], path, "minimum") + : json["minimum"], + monthlyCap: + json["monthly_cap"] != null + ? decodeInteger(json["monthly_cap"], path, "monthly_cap") + : json["monthly_cap"], + paymentMethodId: + json["payment_method_id"] != null + ? decodeString(json["payment_method_id"], path, "payment_method_id") + : json["payment_method_id"], + status: AutoTopUpStatusSerializer.parse(json["status"], decodePath(path, "status")), + suspendedAt: + json["suspended_at"] != null + ? decodeDateTime(json["suspended_at"], path, "suspended_at") + : json["suspended_at"], + target: + json["target"] != null + ? decodeInteger(json["target"], path, "target") + : json["target"], + threshold: decodeInteger(json["threshold"], path, "threshold"), + }; + }, + + serialize(value: AutoTopUp): any { + return { + ...extraProperties(value, [ + "amount", + "customerConsentAttestedAt", + "dailyCap", + "lastError", + "lastSucceededAt", + "maximum", + "method", + "minimum", + "monthlyCap", + "paymentMethodId", + "status", + "suspendedAt", + "target", + "threshold", + ]), + amount: value.amount, + customer_consent_attested_at: value.customerConsentAttestedAt, + daily_cap: value.dailyCap, + last_error: value.lastError, + last_succeeded_at: value.lastSucceededAt, + maximum: value.maximum, + method: AutoTopUpMethodSerializer.serialize(value.method), + minimum: value.minimum, + monthly_cap: value.monthlyCap, + payment_method_id: value.paymentMethodId, + status: AutoTopUpStatusSerializer.serialize(value.status), + suspended_at: value.suspendedAt, + target: value.target, + threshold: value.threshold, + }; + }, +}; diff --git a/src/models/autoTopUpCapReachedEvent.ts b/src/models/autoTopUpCapReachedEvent.ts new file mode 100644 index 0000000..49ef556 --- /dev/null +++ b/src/models/autoTopUpCapReachedEvent.ts @@ -0,0 +1,77 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { + type AutoTopUpCapReachedEventData, + AutoTopUpCapReachedEventDataSerializer, +} from "./autoTopUpCapReachedEventData.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; + +export interface AutoTopUpCapReachedEvent extends AutoTopUpCapReachedEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `AutoTopUpCapReachedEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpCapReachedEventSerializer = { + parse(json: any, path = "$"): AutoTopUpCapReachedEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "attempted_amount", + "cap", + "currency", + "customer_id", + "period", + "period_end", + "period_start", + ]), + ...pickProperties(AutoTopUpCapReachedEventDataSerializer.parse(json, path), [ + "attemptedAmount", + "cap", + "currency", + "customerId", + "period", + "periodEnd", + "periodStart", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: AutoTopUpCapReachedEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "attemptedAmount", + "cap", + "currency", + "customerId", + "period", + "periodEnd", + "periodStart", + ]), + ...pickProperties(AutoTopUpCapReachedEventDataSerializer.serialize(value), [ + "attempted_amount", + "cap", + "currency", + "customer_id", + "period", + "period_end", + "period_start", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/autoTopUpCapReachedEventData.ts b/src/models/autoTopUpCapReachedEventData.ts new file mode 100644 index 0000000..f971101 --- /dev/null +++ b/src/models/autoTopUpCapReachedEventData.ts @@ -0,0 +1,79 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** A spending cap stopped an automatic top-up. */ +export interface AutoTopUpCapReachedEventData { + /** + * What the suppressed top-up would have charged, tax included once it was quoted (before + * tax when the cap stopped it before then). Caps are always money: for a credit unit wallet, + * `currency` is the customer's currency. + */ + attemptedAmount: number; + /** The cap, tax included, in minor units of `currency`. */ + cap: number; + /** The currency the cap and the charge are in (ISO 4217). */ + currency: string; + customerId: CustomerId; + /** `DAILY` (rolling day) or `MONTHLY` (calendar month, UTC). */ + period: string; + /** End of the capped period. */ + periodEnd: Date; + /** Start of the capped period. */ + periodStart: Date; +} + +/** Converts `AutoTopUpCapReachedEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpCapReachedEventDataSerializer = { + parse(json: any, path = "$"): AutoTopUpCapReachedEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "attempted_amount", + "cap", + "currency", + "customer_id", + "period", + "period_end", + "period_start", + ]), + attemptedAmount: decodeInteger(json["attempted_amount"], path, "attempted_amount"), + cap: decodeInteger(json["cap"], path, "cap"), + currency: decodeString(json["currency"], path, "currency"), + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + period: decodeString(json["period"], path, "period"), + periodEnd: decodeDateTime(json["period_end"], path, "period_end"), + periodStart: decodeDateTime(json["period_start"], path, "period_start"), + }; + }, + + serialize(value: AutoTopUpCapReachedEventData): any { + return { + ...extraProperties(value, [ + "attemptedAmount", + "cap", + "currency", + "customerId", + "period", + "periodEnd", + "periodStart", + ]), + attempted_amount: value.attemptedAmount, + cap: value.cap, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + period: value.period, + period_end: value.periodEnd, + period_start: value.periodStart, + }; + }, +}; diff --git a/src/models/autoTopUpConsentChangedEvent.ts b/src/models/autoTopUpConsentChangedEvent.ts new file mode 100644 index 0000000..57cf3d5 --- /dev/null +++ b/src/models/autoTopUpConsentChangedEvent.ts @@ -0,0 +1,85 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { + type AutoTopUpConsentChangedEventData, + AutoTopUpConsentChangedEventDataSerializer, +} from "./autoTopUpConsentChangedEventData.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; + +export interface AutoTopUpConsentChangedEvent extends AutoTopUpConsentChangedEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `AutoTopUpConsentChangedEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpConsentChangedEventSerializer = { + parse(json: any, path = "$"): AutoTopUpConsentChangedEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "actor", + "changed_at", + "configuration_revision", + "consent_attested_at", + "consent_attested_by", + "currency", + "customer_id", + "enabled", + "previous_configuration_revision", + ]), + ...pickProperties(AutoTopUpConsentChangedEventDataSerializer.parse(json, path), [ + "actor", + "changedAt", + "configurationRevision", + "consentAttestedAt", + "consentAttestedBy", + "currency", + "customerId", + "enabled", + "previousConfigurationRevision", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: AutoTopUpConsentChangedEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "actor", + "changedAt", + "configurationRevision", + "consentAttestedAt", + "consentAttestedBy", + "currency", + "customerId", + "enabled", + "previousConfigurationRevision", + ]), + ...pickProperties(AutoTopUpConsentChangedEventDataSerializer.serialize(value), [ + "actor", + "changed_at", + "configuration_revision", + "consent_attested_at", + "consent_attested_by", + "currency", + "customer_id", + "enabled", + "previous_configuration_revision", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/autoTopUpConsentChangedEventData.ts b/src/models/autoTopUpConsentChangedEventData.ts new file mode 100644 index 0000000..8af491a --- /dev/null +++ b/src/models/autoTopUpConsentChangedEventData.ts @@ -0,0 +1,112 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type Actor, ActorSerializer } from "./actor.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** The authorization of a wallet's automatic top-up was given, changed or withdrawn. */ +export interface AutoTopUpConsentChangedEventData { + /** Who gave, changed or withdrew the authorization. */ + actor: Actor; + /** When the authorization changed. */ + changedAt: Date; + /** + * Identifies the terms authorized now, without disclosing payment details; absent when + * withdrawn. + */ + configurationRevision?: string | null | undefined; + /** When that attestation was made. */ + consentAttestedAt?: Date | null | undefined; + consentAttestedBy?: Actor | null | undefined; + /** The wallet's currency (ISO 4217) or credit unit code. */ + currency: string; + customerId: CustomerId; + /** Whether automatic top-up is authorized after this change. */ + enabled: boolean; + /** Identifies the terms authorized before the change; absent when none were. */ + previousConfigurationRevision?: string | null | undefined; +} + +/** Converts `AutoTopUpConsentChangedEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpConsentChangedEventDataSerializer = { + parse(json: any, path = "$"): AutoTopUpConsentChangedEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "actor", + "changed_at", + "configuration_revision", + "consent_attested_at", + "consent_attested_by", + "currency", + "customer_id", + "enabled", + "previous_configuration_revision", + ]), + actor: ActorSerializer.parse(json["actor"], decodePath(path, "actor")), + changedAt: decodeDateTime(json["changed_at"], path, "changed_at"), + configurationRevision: + json["configuration_revision"] != null + ? decodeString(json["configuration_revision"], path, "configuration_revision") + : json["configuration_revision"], + consentAttestedAt: + json["consent_attested_at"] != null + ? decodeDateTime(json["consent_attested_at"], path, "consent_attested_at") + : json["consent_attested_at"], + consentAttestedBy: + json["consent_attested_by"] != null + ? ActorSerializer.parse( + json["consent_attested_by"], + decodePath(path, "consent_attested_by") + ) + : json["consent_attested_by"], + currency: decodeString(json["currency"], path, "currency"), + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + enabled: decodeBoolean(json["enabled"], path, "enabled"), + previousConfigurationRevision: + json["previous_configuration_revision"] != null + ? decodeString( + json["previous_configuration_revision"], + path, + "previous_configuration_revision" + ) + : json["previous_configuration_revision"], + }; + }, + + serialize(value: AutoTopUpConsentChangedEventData): any { + return { + ...extraProperties(value, [ + "actor", + "changedAt", + "configurationRevision", + "consentAttestedAt", + "consentAttestedBy", + "currency", + "customerId", + "enabled", + "previousConfigurationRevision", + ]), + actor: ActorSerializer.serialize(value.actor), + changed_at: value.changedAt, + configuration_revision: value.configurationRevision, + consent_attested_at: value.consentAttestedAt, + consent_attested_by: + value.consentAttestedBy != null + ? ActorSerializer.serialize(value.consentAttestedBy) + : value.consentAttestedBy, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + enabled: value.enabled, + previous_configuration_revision: value.previousConfigurationRevision, + }; + }, +}; diff --git a/src/models/autoTopUpEvent.ts b/src/models/autoTopUpEvent.ts new file mode 100644 index 0000000..7d00f6e --- /dev/null +++ b/src/models/autoTopUpEvent.ts @@ -0,0 +1,73 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { + type AutoTopUpEventData, + AutoTopUpEventDataSerializer, +} from "./autoTopUpEventData.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; + +export interface AutoTopUpEvent extends AutoTopUpEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `AutoTopUpEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpEventSerializer = { + parse(json: any, path = "$"): AutoTopUpEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "amount", + "consecutive_failures", + "currency", + "customer_id", + "error", + "suspended_at", + ]), + ...pickProperties(AutoTopUpEventDataSerializer.parse(json, path), [ + "amount", + "consecutiveFailures", + "currency", + "customerId", + "error", + "suspendedAt", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: AutoTopUpEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "amount", + "consecutiveFailures", + "currency", + "customerId", + "error", + "suspendedAt", + ]), + ...pickProperties(AutoTopUpEventDataSerializer.serialize(value), [ + "amount", + "consecutive_failures", + "currency", + "customer_id", + "error", + "suspended_at", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/autoTopUpEventData.ts b/src/models/autoTopUpEventData.ts new file mode 100644 index 0000000..a7dcc0c --- /dev/null +++ b/src/models/autoTopUpEventData.ts @@ -0,0 +1,81 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** An automatic top-up charge failed, or the automatic top-up was suspended. */ +export interface AutoTopUpEventData { + /** + * The charge in minor units of `currency`: the credit it would have added, or for a credit + * unit wallet the price of those credits in the customer's currency. When the credits could + * not be priced (no selling price), the credits themselves, with `currency` the unit code. On + * a suspension after a top-up payment was refunded or disputed: that payment's top-up. + */ + amount: number; + /** Failed charges in a row, this one included. */ + consecutiveFailures: number; + /** The currency charged (ISO 4217), or the credit unit code when the credits had no price. */ + currency: string; + customerId: CustomerId; + /** May carry payment provider detail. */ + error: string; + /** Set on `wallet.auto_top_up_suspended`: when it was suspended. */ + suspendedAt?: Date | null | undefined; +} + +/** Converts `AutoTopUpEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpEventDataSerializer = { + parse(json: any, path = "$"): AutoTopUpEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "consecutive_failures", + "currency", + "customer_id", + "error", + "suspended_at", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + consecutiveFailures: decodeInteger( + json["consecutive_failures"], + path, + "consecutive_failures" + ), + currency: decodeString(json["currency"], path, "currency"), + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + error: decodeString(json["error"], path, "error"), + suspendedAt: + json["suspended_at"] != null + ? decodeDateTime(json["suspended_at"], path, "suspended_at") + : json["suspended_at"], + }; + }, + + serialize(value: AutoTopUpEventData): any { + return { + ...extraProperties(value, [ + "amount", + "consecutiveFailures", + "currency", + "customerId", + "error", + "suspendedAt", + ]), + amount: value.amount, + consecutive_failures: value.consecutiveFailures, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + error: value.error, + suspended_at: value.suspendedAt, + }; + }, +}; diff --git a/src/models/autoTopUpMethod.ts b/src/models/autoTopUpMethod.ts new file mode 100644 index 0000000..264899e --- /dev/null +++ b/src/models/autoTopUpMethod.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const AutoTopUpMethod = { + Fixed: "FIXED", + ToTarget: "TO_TARGET", +} as const; +export type AutoTopUpMethod = + | (typeof AutoTopUpMethod)[keyof typeof AutoTopUpMethod] + | (string & {}); + +/** Converts `AutoTopUpMethod` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpMethodSerializer = { + parse(json: any, path = "$"): AutoTopUpMethod { + return decodeString(json, path); + }, + + serialize(value: AutoTopUpMethod): any { + return value; + }, +}; diff --git a/src/models/autoTopUpStatus.ts b/src/models/autoTopUpStatus.ts new file mode 100644 index 0000000..57a546a --- /dev/null +++ b/src/models/autoTopUpStatus.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const AutoTopUpStatus = { + Active: "ACTIVE", + Disabled: "DISABLED", + Suspended: "SUSPENDED", +} as const; +export type AutoTopUpStatus = + | (typeof AutoTopUpStatus)[keyof typeof AutoTopUpStatus] + | (string & {}); + +/** Converts `AutoTopUpStatus` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpStatusSerializer = { + parse(json: any, path = "$"): AutoTopUpStatus { + return decodeString(json, path); + }, + + serialize(value: AutoTopUpStatus): any { + return value; + }, +}; diff --git a/src/models/autoTopUpWriteRequest.ts b/src/models/autoTopUpWriteRequest.ts new file mode 100644 index 0000000..2b5ce0f --- /dev/null +++ b/src/models/autoTopUpWriteRequest.ts @@ -0,0 +1,152 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type AutoTopUpMethod, AutoTopUpMethodSerializer } from "./autoTopUpMethod.js"; +/** + * An automatic top-up's terms, replaced as a whole. FIXED needs `amount` and no `target`; + * TO_TARGET needs `target` above `threshold` and no `amount`; amounts are positive. + */ +export interface AutoTopUpWriteRequest { + /** FIXED only: credit bought each time, in minor units of the wallet. */ + amount?: number | null | undefined; + /** + * Credit unit wallets: authorize today's price per credit for these terms, which lifts a + * stop caused by a price increase. When false (the default) the terms keep the price they + * were authorized at, and a rule stopped by a price increase stays stopped. + * A price at or below the authorized one never stops the rule: top-ups charge it. + */ + atCurrentPrice?: boolean | undefined; + /** + * Attests that the customer agreed to automatic charges on these terms; recorded with the + * API key and the time. Required (true) when the terms turn automatic top-up on, including + * one the customer turned off, or change what it charges. Not needed to resend the stored + * terms unchanged, nor to change terms the customer confirmed in their portal: those stop + * until the customer confirms the new ones. + */ + customerConsentAttested?: boolean | undefined; + /** + * Most charged in a rolling day, tax included. For a credit unit wallet caps are money, in + * minor units of the customer's currency. + */ + dailyCap?: number | null | undefined; + /** Largest single charge, in the same money as `minimum`. */ + maximum?: number | null | undefined; + /** FIXED buys `amount` each time; TO_TARGET buys back up to `target`. */ + method: AutoTopUpMethod; + /** + * Smallest single charge. For a credit unit wallet it is money (the price before tax, in + * minor units of the customer's currency), like the caps; the threshold, amount and target + * are credits. + */ + minimum?: number | null | undefined; + /** Most charged in a calendar month (UTC), tax included. */ + monthlyCap?: number | null | undefined; + /** + * Defaults to the customer's default payment method: the customer's agreement, and your + * attestation of it, then cover whichever method is their default at each top-up. + */ + paymentMethodId?: string | null | undefined; + /** TO_TARGET only: the balance a top-up brings the wallet back to; must exceed `threshold`. */ + target?: number | null | undefined; + /** Tops up once the balance is at or below this, in minor units of the wallet. */ + threshold: number; +} + +/** Converts `AutoTopUpWriteRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const AutoTopUpWriteRequestSerializer = { + parse(json: any, path = "$"): AutoTopUpWriteRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "at_current_price", + "customer_consent_attested", + "daily_cap", + "maximum", + "method", + "minimum", + "monthly_cap", + "payment_method_id", + "target", + "threshold", + ]), + amount: + json["amount"] != null + ? decodeInteger(json["amount"], path, "amount") + : json["amount"], + atCurrentPrice: + json["at_current_price"] != null + ? decodeBoolean(json["at_current_price"], path, "at_current_price") + : undefined, + customerConsentAttested: + json["customer_consent_attested"] != null + ? decodeBoolean( + json["customer_consent_attested"], + path, + "customer_consent_attested" + ) + : undefined, + dailyCap: + json["daily_cap"] != null + ? decodeInteger(json["daily_cap"], path, "daily_cap") + : json["daily_cap"], + maximum: + json["maximum"] != null + ? decodeInteger(json["maximum"], path, "maximum") + : json["maximum"], + method: AutoTopUpMethodSerializer.parse(json["method"], decodePath(path, "method")), + minimum: + json["minimum"] != null + ? decodeInteger(json["minimum"], path, "minimum") + : json["minimum"], + monthlyCap: + json["monthly_cap"] != null + ? decodeInteger(json["monthly_cap"], path, "monthly_cap") + : json["monthly_cap"], + paymentMethodId: + json["payment_method_id"] != null + ? decodeString(json["payment_method_id"], path, "payment_method_id") + : json["payment_method_id"], + target: + json["target"] != null + ? decodeInteger(json["target"], path, "target") + : json["target"], + threshold: decodeInteger(json["threshold"], path, "threshold"), + }; + }, + + serialize(value: AutoTopUpWriteRequest): any { + return { + ...extraProperties(value, [ + "amount", + "atCurrentPrice", + "customerConsentAttested", + "dailyCap", + "maximum", + "method", + "minimum", + "monthlyCap", + "paymentMethodId", + "target", + "threshold", + ]), + amount: value.amount, + at_current_price: value.atCurrentPrice, + customer_consent_attested: value.customerConsentAttested, + daily_cap: value.dailyCap, + maximum: value.maximum, + method: AutoTopUpMethodSerializer.serialize(value.method), + minimum: value.minimum, + monthly_cap: value.monthlyCap, + payment_method_id: value.paymentMethodId, + target: value.target, + threshold: value.threshold, + }; + }, +}; diff --git a/src/models/bankTransferPaymentMethodConfig.ts b/src/models/bankTransferPaymentMethodConfig.ts index c2c125b..fda8c41 100644 --- a/src/models/bankTransferPaymentMethodConfig.ts +++ b/src/models/bankTransferPaymentMethodConfig.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BankAccountId, BankAccountIdSerializer } from "./bankAccountId.js"; export interface BankTransferPaymentMethodConfig { accountId?: BankAccountId | null | undefined; + type: "bank_transfer"; } /** Converts `BankTransferPaymentMethodConfig` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,7 +13,7 @@ export const BankTransferPaymentMethodConfigSerializer = { parse(json: any, path = "$"): BankTransferPaymentMethodConfig { decodeObject(json, path); return { - ...extraProperties(json, ["account_id"]), + ...extraProperties(json, ["account_id", "type"]), accountId: json["account_id"] != null ? BankAccountIdSerializer.parse( @@ -20,16 +21,21 @@ export const BankTransferPaymentMethodConfigSerializer = { decodePath(path, "account_id") ) : json["account_id"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "bank_transfer") + : "bank_transfer", }; }, serialize(value: BankTransferPaymentMethodConfig): any { return { - ...extraProperties(value, ["accountId"]), + ...extraProperties(value, ["accountId", "type"]), account_id: value.accountId != null ? BankAccountIdSerializer.serialize(value.accountId) : value.accountId, + type: value.type ?? "bank_transfer", }; }, }; diff --git a/src/models/billingCycleResetPeriod.ts b/src/models/billingCycleResetPeriod.ts index bc9cfe2..8e4b802 100644 --- a/src/models/billingCycleResetPeriod.ts +++ b/src/models/billingCycleResetPeriod.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; /** Resets each time your subscription renews — anchored to your billing cycle. */ -export interface BillingCycleResetPeriod {} +export interface BillingCycleResetPeriod { + type: "BILLING_CYCLE"; +} /** Converts `BillingCycleResetPeriod` values from (`parse`) and to (`serialize`) their JSON form. */ export const BillingCycleResetPeriodSerializer = { parse(json: any, path = "$"): BillingCycleResetPeriod { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "BILLING_CYCLE") + : "BILLING_CYCLE", }; }, serialize(value: BillingCycleResetPeriod): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "BILLING_CYCLE", }; }, }; diff --git a/src/models/booleanConfigValue.ts b/src/models/booleanConfigValue.ts index 93d8ead..a15c343 100644 --- a/src/models/booleanConfigValue.ts +++ b/src/models/booleanConfigValue.ts @@ -1,8 +1,9 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject } from "../decode.js"; +import { decodeBoolean, decodeObject, decodeString } from "../decode.js"; /** A boolean config value. */ export interface BooleanConfigValue { + kind: "BOOLEAN"; value: boolean; } @@ -11,14 +12,19 @@ export const BooleanConfigValueSerializer = { parse(json: any, path = "$"): BooleanConfigValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["kind", "value"]), + kind: + json["kind"] != null + ? (decodeString(json["kind"], path, "kind") as "BOOLEAN") + : "BOOLEAN", value: decodeBoolean(json["value"], path, "value"), }; }, serialize(value: BooleanConfigValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["kind", "value"]), + kind: value.kind ?? "BOOLEAN", value: value.value, }; }, diff --git a/src/models/booleanEffectiveEntitlementValue.ts b/src/models/booleanEffectiveEntitlementValue.ts index 620a820..b2bcdda 100644 --- a/src/models/booleanEffectiveEntitlementValue.ts +++ b/src/models/booleanEffectiveEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject } from "../decode.js"; +import { decodeBoolean, decodeObject, decodeString } from "../decode.js"; export interface BooleanEffectiveEntitlementValue { enabled: boolean; + type: "BOOLEAN"; } /** Converts `BooleanEffectiveEntitlementValue` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const BooleanEffectiveEntitlementValueSerializer = { parse(json: any, path = "$"): BooleanEffectiveEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["enabled"]), + ...extraProperties(json, ["enabled", "type"]), enabled: decodeBoolean(json["enabled"], path, "enabled"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "BOOLEAN") + : "BOOLEAN", }; }, serialize(value: BooleanEffectiveEntitlementValue): any { return { - ...extraProperties(value, ["enabled"]), + ...extraProperties(value, ["enabled", "type"]), enabled: value.enabled, + type: value.type ?? "BOOLEAN", }; }, }; diff --git a/src/models/booleanEntitlementValue.ts b/src/models/booleanEntitlementValue.ts index c4681d2..637560a 100644 --- a/src/models/booleanEntitlementValue.ts +++ b/src/models/booleanEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject } from "../decode.js"; +import { decodeBoolean, decodeObject, decodeString } from "../decode.js"; export interface BooleanEntitlementValue { enabled: boolean; + type: "BOOLEAN"; } /** Converts `BooleanEntitlementValue` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const BooleanEntitlementValueSerializer = { parse(json: any, path = "$"): BooleanEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["enabled"]), + ...extraProperties(json, ["enabled", "type"]), enabled: decodeBoolean(json["enabled"], path, "enabled"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "BOOLEAN") + : "BOOLEAN", }; }, serialize(value: BooleanEntitlementValue): any { return { - ...extraProperties(value, ["enabled"]), + ...extraProperties(value, ["enabled", "type"]), enabled: value.enabled, + type: value.type ?? "BOOLEAN", }; }, }; diff --git a/src/models/booleanFeatureType.ts b/src/models/booleanFeatureType.ts index d038f71..a2e4bfc 100644 --- a/src/models/booleanFeatureType.ts +++ b/src/models/booleanFeatureType.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; -export interface BooleanFeatureType {} +export interface BooleanFeatureType { + type: "BOOLEAN"; +} /** Converts `BooleanFeatureType` values from (`parse`) and to (`serialize`) their JSON form. */ export const BooleanFeatureTypeSerializer = { parse(json: any, path = "$"): BooleanFeatureType { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "BOOLEAN") + : "BOOLEAN", }; }, serialize(value: BooleanFeatureType): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "BOOLEAN", }; }, }; diff --git a/src/models/booleanResolvedEntitlementValue.ts b/src/models/booleanResolvedEntitlementValue.ts index 3e5705b..6569b33 100644 --- a/src/models/booleanResolvedEntitlementValue.ts +++ b/src/models/booleanResolvedEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject } from "../decode.js"; +import { decodeBoolean, decodeObject, decodeString } from "../decode.js"; export interface BooleanResolvedEntitlementValue { enabled: boolean; + type: "BOOLEAN"; } /** Converts `BooleanResolvedEntitlementValue` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const BooleanResolvedEntitlementValueSerializer = { parse(json: any, path = "$"): BooleanResolvedEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["enabled"]), + ...extraProperties(json, ["enabled", "type"]), enabled: decodeBoolean(json["enabled"], path, "enabled"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "BOOLEAN") + : "BOOLEAN", }; }, serialize(value: BooleanResolvedEntitlementValue): any { return { - ...extraProperties(value, ["enabled"]), + ...extraProperties(value, ["enabled", "type"]), enabled: value.enabled, + type: value.type ?? "BOOLEAN", }; }, }; diff --git a/src/models/budget.ts b/src/models/budget.ts new file mode 100644 index 0000000..814a51c --- /dev/null +++ b/src/models/budget.ts @@ -0,0 +1,178 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type BudgetAuthor, BudgetAuthorSerializer } from "./budgetAuthor.js"; +import { type BudgetBehavior, BudgetBehaviorSerializer } from "./budgetBehavior.js"; +import { type BudgetPeriod, BudgetPeriodSerializer } from "./budgetPeriod.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +/** + * A spending limit for one currency, set by you or by the customer, with alerts at percentages + * of it. It counts the customer's whole spend, or one subscription's. A HARD budget also refuses + * access once reached. A budget never charges the customer. + */ +export interface Budget { + /** In minor units of the currency or credit unit. */ + amount: number; + archivedAt?: Date | null | undefined; + /** When `estimated_spend` was last measured. */ + asOf?: Date | null | undefined; + behavior: BudgetBehavior; + createdAt: Date; + createdBy: BudgetAuthor; + /** The credit unit (its code) whose usage the budget counts; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + currency?: Currency | null | undefined; + /** + * Spend in the current billing period, including usage not invoiced yet, in minor units. + * Absent until first measured. + */ + estimatedSpend?: number | null | undefined; + /** Always false: the estimate prices usage that is not yet invoiced. */ + exact: boolean; + id: string; + period?: BudgetPeriod | null | undefined; + /** The subscription whose spend the budget counts; null when it counts the whole customer's. */ + subscriptionId?: string | null | undefined; + /** Percentages of the amount at which an alert is sent. */ + thresholds: number[]; + updatedAt: Date; + /** Send it back as `expected_version` when patching. */ + version: number; +} + +/** Converts `Budget` values from (`parse`) and to (`serialize`) their JSON form. */ +export const BudgetSerializer = { + parse(json: any, path = "$"): Budget { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "archived_at", + "as_of", + "behavior", + "created_at", + "created_by", + "credit_unit", + "credit_unit_precision", + "currency", + "estimated_spend", + "exact", + "id", + "period", + "subscription_id", + "thresholds", + "updated_at", + "version", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + archivedAt: + json["archived_at"] != null + ? decodeDateTime(json["archived_at"], path, "archived_at") + : json["archived_at"], + asOf: + json["as_of"] != null + ? decodeDateTime(json["as_of"], path, "as_of") + : json["as_of"], + behavior: BudgetBehaviorSerializer.parse( + json["behavior"], + decodePath(path, "behavior") + ), + createdAt: decodeDateTime(json["created_at"], path, "created_at"), + createdBy: BudgetAuthorSerializer.parse( + json["created_by"], + decodePath(path, "created_by") + ), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + estimatedSpend: + json["estimated_spend"] != null + ? decodeInteger(json["estimated_spend"], path, "estimated_spend") + : json["estimated_spend"], + exact: decodeBoolean(json["exact"], path, "exact"), + id: decodeString(json["id"], path, "id"), + period: + json["period"] != null + ? BudgetPeriodSerializer.parse(json["period"], decodePath(path, "period")) + : json["period"], + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + thresholds: decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ), + updatedAt: decodeDateTime(json["updated_at"], path, "updated_at"), + version: decodeInteger(json["version"], path, "version"), + }; + }, + + serialize(value: Budget): any { + return { + ...extraProperties(value, [ + "amount", + "archivedAt", + "asOf", + "behavior", + "createdAt", + "createdBy", + "creditUnit", + "creditUnitPrecision", + "currency", + "estimatedSpend", + "exact", + "id", + "period", + "subscriptionId", + "thresholds", + "updatedAt", + "version", + ]), + amount: value.amount, + archived_at: value.archivedAt, + as_of: value.asOf, + behavior: BudgetBehaviorSerializer.serialize(value.behavior), + created_at: value.createdAt, + created_by: BudgetAuthorSerializer.serialize(value.createdBy), + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + estimated_spend: value.estimatedSpend, + exact: value.exact, + id: value.id, + period: + value.period != null + ? BudgetPeriodSerializer.serialize(value.period) + : value.period, + subscription_id: value.subscriptionId, + thresholds: value.thresholds, + updated_at: value.updatedAt, + version: value.version, + }; + }, +}; diff --git a/src/models/budgetAuthor.ts b/src/models/budgetAuthor.ts new file mode 100644 index 0000000..fd392fa --- /dev/null +++ b/src/models/budgetAuthor.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** Who set the budget: you (TENANT) or the customer, from the portal (CUSTOMER). */ +export const BudgetAuthor = { + Tenant: "TENANT", + Customer: "CUSTOMER", +} as const; +export type BudgetAuthor = + | (typeof BudgetAuthor)[keyof typeof BudgetAuthor] + | (string & {}); + +/** Converts `BudgetAuthor` values from (`parse`) and to (`serialize`) their JSON form. */ +export const BudgetAuthorSerializer = { + parse(json: any, path = "$"): BudgetAuthor { + return decodeString(json, path); + }, + + serialize(value: BudgetAuthor): any { + return value; + }, +}; diff --git a/src/models/budgetBehavior.ts b/src/models/budgetBehavior.ts new file mode 100644 index 0000000..f0912cf --- /dev/null +++ b/src/models/budgetBehavior.ts @@ -0,0 +1,26 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** + * What reaching the amount does. A SOFT budget only sends alerts; a HARD budget also makes the + * entitlement check answer BUDGET_EXCEEDED for the features whose usage counts in its spend. A + * HARD budget on one subscription refuses the checks naming that subscription, and the checks + * naming none once every subscription charging the feature's metric is refused by its own. + */ +export const BudgetBehavior = { + Soft: "SOFT", + Hard: "HARD", +} as const; +export type BudgetBehavior = + | (typeof BudgetBehavior)[keyof typeof BudgetBehavior] + | (string & {}); + +/** Converts `BudgetBehavior` values from (`parse`) and to (`serialize`) their JSON form. */ +export const BudgetBehaviorSerializer = { + parse(json: any, path = "$"): BudgetBehavior { + return decodeString(json, path); + }, + + serialize(value: BudgetBehavior): any { + return value; + }, +}; diff --git a/src/models/budgetListResponse.ts b/src/models/budgetListResponse.ts new file mode 100644 index 0000000..14d27c2 --- /dev/null +++ b/src/models/budgetListResponse.ts @@ -0,0 +1,38 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type Budget, BudgetSerializer } from "./budget.js"; +import { + type PaginationResponse, + PaginationResponseSerializer, +} from "./paginationResponse.js"; + +export interface BudgetListResponse { + data: Budget[]; + paginationMeta: PaginationResponse; +} + +/** Converts `BudgetListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const BudgetListResponseSerializer = { + parse(json: any, path = "$"): BudgetListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data", "pagination_meta"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + BudgetSerializer.parse(item, decodePath(p, i)) + ), + paginationMeta: PaginationResponseSerializer.parse( + json["pagination_meta"], + decodePath(path, "pagination_meta") + ), + }; + }, + + serialize(value: BudgetListResponse): any { + return { + ...extraProperties(value, ["data", "paginationMeta"]), + data: value.data.map((item: any) => BudgetSerializer.serialize(item)), + pagination_meta: PaginationResponseSerializer.serialize(value.paginationMeta), + }; + }, +}; diff --git a/src/models/budgetPeriod.ts b/src/models/budgetPeriod.ts new file mode 100644 index 0000000..a1643fa --- /dev/null +++ b/src/models/budgetPeriod.ts @@ -0,0 +1,29 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; + +export interface BudgetPeriod { + /** Absent when the period never ends. */ + end?: string | null | undefined; + start: string; +} + +/** Converts `BudgetPeriod` values from (`parse`) and to (`serialize`) their JSON form. */ +export const BudgetPeriodSerializer = { + parse(json: any, path = "$"): BudgetPeriod { + decodeObject(json, path); + return { + ...extraProperties(json, ["end", "start"]), + end: json["end"] != null ? decodeString(json["end"], path, "end") : json["end"], + start: decodeString(json["start"], path, "start"), + }; + }, + + serialize(value: BudgetPeriod): any { + return { + ...extraProperties(value, ["end", "start"]), + end: value.end, + start: value.start, + }; + }, +}; diff --git a/src/models/calendarResetPeriod.ts b/src/models/calendarResetPeriod.ts index 2652439..bd436c3 100644 --- a/src/models/calendarResetPeriod.ts +++ b/src/models/calendarResetPeriod.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; import { type CalendarUnit, CalendarUnitSerializer } from "./calendarUnit.js"; /** Resets on calendar boundaries (e.g. the 1st of every month) — not tied to subscription start date. */ export interface CalendarResetPeriod { interval: number; + type: "CALENDAR"; unit: CalendarUnit; } @@ -13,16 +14,21 @@ export const CalendarResetPeriodSerializer = { parse(json: any, path = "$"): CalendarResetPeriod { decodeObject(json, path); return { - ...extraProperties(json, ["interval", "unit"]), + ...extraProperties(json, ["interval", "type", "unit"]), interval: decodeInteger(json["interval"], path, "interval"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CALENDAR") + : "CALENDAR", unit: CalendarUnitSerializer.parse(json["unit"], decodePath(path, "unit")), }; }, serialize(value: CalendarResetPeriod): any { return { - ...extraProperties(value, ["interval", "unit"]), + ...extraProperties(value, ["interval", "type", "unit"]), interval: value.interval, + type: value.type ?? "CALENDAR", unit: CalendarUnitSerializer.serialize(value.unit), }; }, diff --git a/src/models/capacityFee.ts b/src/models/capacityFee.ts index bb9f926..3221a9c 100644 --- a/src/models/capacityFee.ts +++ b/src/models/capacityFee.ts @@ -2,12 +2,15 @@ import { extraProperties } from "../json.js"; import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; +import { type FeeCreditUnit, FeeCreditUnitSerializer } from "./feeCreditUnit.js"; export interface CapacityFee { + creditUnit?: FeeCreditUnit | null | undefined; included: number; metricId: BillableMetricId; overageRate: string; rate: string; + type: "CAPACITY"; } /** Converts `CapacityFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -15,7 +18,21 @@ export const CapacityFeeSerializer = { parse(json: any, path = "$"): CapacityFee { decodeObject(json, path); return { - ...extraProperties(json, ["included", "metric_id", "overage_rate", "rate"]), + ...extraProperties(json, [ + "credit_unit", + "included", + "metric_id", + "overage_rate", + "rate", + "type", + ]), + creditUnit: + json["credit_unit"] != null + ? FeeCreditUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], included: decodeInteger(json["included"], path, "included"), metricId: BillableMetricIdSerializer.parse( json["metric_id"], @@ -23,16 +40,32 @@ export const CapacityFeeSerializer = { ), overageRate: decodeString(json["overage_rate"], path, "overage_rate"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CAPACITY") + : "CAPACITY", }; }, serialize(value: CapacityFee): any { return { - ...extraProperties(value, ["included", "metricId", "overageRate", "rate"]), + ...extraProperties(value, [ + "creditUnit", + "included", + "metricId", + "overageRate", + "rate", + "type", + ]), + credit_unit: + value.creditUnit != null + ? FeeCreditUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, included: value.included, metric_id: BillableMetricIdSerializer.serialize(value.metricId), overage_rate: value.overageRate, rate: value.rate, + type: value.type ?? "CAPACITY", }; }, }; diff --git a/src/models/capacityFeeStructure.ts b/src/models/capacityFeeStructure.ts index a7db7eb..8a82a3c 100644 --- a/src/models/capacityFeeStructure.ts +++ b/src/models/capacityFeeStructure.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; export interface CapacityFeeStructure { metricId: BillableMetricId; + type: "CAPACITY"; } /** Converts `CapacityFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,18 +13,23 @@ export const CapacityFeeStructureSerializer = { parse(json: any, path = "$"): CapacityFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, ["metric_id"]), + ...extraProperties(json, ["metric_id", "type"]), metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CAPACITY") + : "CAPACITY", }; }, serialize(value: CapacityFeeStructure): any { return { - ...extraProperties(value, ["metricId"]), + ...extraProperties(value, ["metricId", "type"]), metric_id: BillableMetricIdSerializer.serialize(value.metricId), + type: value.type ?? "CAPACITY", }; }, }; diff --git a/src/models/capacityPlanFee.ts b/src/models/capacityPlanFee.ts index 7aaf3d9..0358417 100644 --- a/src/models/capacityPlanFee.ts +++ b/src/models/capacityPlanFee.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; import { type BillingPeriodEnum, @@ -10,11 +10,17 @@ import { type CapacityThreshold, CapacityThresholdSerializer, } from "./capacityThreshold.js"; +import { + type PlanFeeCreditUnit, + PlanFeeCreditUnitSerializer, +} from "./planFeeCreditUnit.js"; /** Capacity-based fee with included committed usage and overage */ export interface CapacityPlanFee { cadence: BillingPeriodEnum; + creditUnit?: PlanFeeCreditUnit | null | undefined; metricId: BillableMetricId; thresholds: CapacityThreshold[]; + type: "CAPACITY"; } /** Converts `CapacityPlanFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -22,11 +28,24 @@ export const CapacityPlanFeeSerializer = { parse(json: any, path = "$"): CapacityPlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["cadence", "metric_id", "thresholds"]), + ...extraProperties(json, [ + "cadence", + "credit_unit", + "metric_id", + "thresholds", + "type", + ]), cadence: BillingPeriodEnumSerializer.parse( json["cadence"], decodePath(path, "cadence") ), + creditUnit: + json["credit_unit"] != null + ? PlanFeeCreditUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") @@ -38,17 +57,32 @@ export const CapacityPlanFeeSerializer = { (item: any, p: string, i: number) => CapacityThresholdSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CAPACITY") + : "CAPACITY", }; }, serialize(value: CapacityPlanFee): any { return { - ...extraProperties(value, ["cadence", "metricId", "thresholds"]), + ...extraProperties(value, [ + "cadence", + "creditUnit", + "metricId", + "thresholds", + "type", + ]), cadence: BillingPeriodEnumSerializer.serialize(value.cadence), + credit_unit: + value.creditUnit != null + ? PlanFeeCreditUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, metric_id: BillableMetricIdSerializer.serialize(value.metricId), thresholds: value.thresholds.map((item: any) => CapacityThresholdSerializer.serialize(item) ), + type: value.type ?? "CAPACITY", }; }, }; diff --git a/src/models/capacityPricing.ts b/src/models/capacityPricing.ts index 45dcc4c..c0eb4b6 100644 --- a/src/models/capacityPricing.ts +++ b/src/models/capacityPricing.ts @@ -6,6 +6,7 @@ export interface CapacityPricing { included: number; overageRate: string; rate: string; + type: "CAPACITY"; } /** Converts `CapacityPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,19 +14,24 @@ export const CapacityPricingSerializer = { parse(json: any, path = "$"): CapacityPricing { decodeObject(json, path); return { - ...extraProperties(json, ["included", "overage_rate", "rate"]), + ...extraProperties(json, ["included", "overage_rate", "rate", "type"]), included: decodeInteger(json["included"], path, "included"), overageRate: decodeString(json["overage_rate"], path, "overage_rate"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CAPACITY") + : "CAPACITY", }; }, serialize(value: CapacityPricing): any { return { - ...extraProperties(value, ["included", "overageRate", "rate"]), + ...extraProperties(value, ["included", "overageRate", "rate", "type"]), included: value.included, overage_rate: value.overageRate, rate: value.rate, + type: value.type ?? "CAPACITY", }; }, }; diff --git a/src/models/componentsScope.ts b/src/models/componentsScope.ts index 74be49f..1c91611 100644 --- a/src/models/componentsScope.ts +++ b/src/models/componentsScope.ts @@ -4,6 +4,7 @@ import { decodeList, decodeObject, decodeString } from "../decode.js"; /** Component names — matched against `ReplacePlanRequest::components[].name`. */ export interface ComponentsScope { componentNames: string[]; + type: "components"; } /** Converts `ComponentsScope` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,20 +12,25 @@ export const ComponentsScopeSerializer = { parse(json: any, path = "$"): ComponentsScope { decodeObject(json, path); return { - ...extraProperties(json, ["component_names"]), + ...extraProperties(json, ["component_names", "type"]), componentNames: decodeList( json["component_names"], path, "component_names", (item: any, p: string, i: number) => decodeString(item, p, i) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "components") + : "components", }; }, serialize(value: ComponentsScope): any { return { - ...extraProperties(value, ["componentNames"]), + ...extraProperties(value, ["componentNames", "type"]), component_names: value.componentNames, + type: value.type ?? "components", }; }, }; diff --git a/src/models/configEffectiveEntitlementValue.ts b/src/models/configEffectiveEntitlementValue.ts index 40d65c9..842c606 100644 --- a/src/models/configEffectiveEntitlementValue.ts +++ b/src/models/configEffectiveEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type ConfigValue, ConfigValueSerializer } from "./configValue.js"; export interface ConfigEffectiveEntitlementValue { + type: "CONFIG"; value: ConfigValue; } @@ -12,14 +13,19 @@ export const ConfigEffectiveEntitlementValueSerializer = { parse(json: any, path = "$"): ConfigEffectiveEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["type", "value"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CONFIG") + : "CONFIG", value: ConfigValueSerializer.parse(json["value"], decodePath(path, "value")), }; }, serialize(value: ConfigEffectiveEntitlementValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["type", "value"]), + type: value.type ?? "CONFIG", value: ConfigValueSerializer.serialize(value.value), }; }, diff --git a/src/models/configEntitlementValue.ts b/src/models/configEntitlementValue.ts index d60933b..64e0506 100644 --- a/src/models/configEntitlementValue.ts +++ b/src/models/configEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type ConfigValue, ConfigValueSerializer } from "./configValue.js"; export interface ConfigEntitlementValue { + type: "CONFIG"; value: ConfigValue; } @@ -12,14 +13,19 @@ export const ConfigEntitlementValueSerializer = { parse(json: any, path = "$"): ConfigEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["type", "value"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CONFIG") + : "CONFIG", value: ConfigValueSerializer.parse(json["value"], decodePath(path, "value")), }; }, serialize(value: ConfigEntitlementValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["type", "value"]), + type: value.type ?? "CONFIG", value: ConfigValueSerializer.serialize(value.value), }; }, diff --git a/src/models/configFeatureType.ts b/src/models/configFeatureType.ts index 7236b45..08312d2 100644 --- a/src/models/configFeatureType.ts +++ b/src/models/configFeatureType.ts @@ -6,6 +6,7 @@ import { type ConfigValueType, ConfigValueTypeSerializer } from "./configValueTy export interface ConfigFeatureType { /** Allowed values when `value_type = SELECT`. Empty otherwise. */ options?: string[] | undefined; + type: "CONFIG"; /** The feature's value type, fixed at creation. */ valueType: ConfigValueType; } @@ -15,7 +16,7 @@ export const ConfigFeatureTypeSerializer = { parse(json: any, path = "$"): ConfigFeatureType { decodeObject(json, path); return { - ...extraProperties(json, ["options", "value_type"]), + ...extraProperties(json, ["options", "type", "value_type"]), options: json["options"] != null ? decodeList( @@ -25,6 +26,10 @@ export const ConfigFeatureTypeSerializer = { (item: any, p: string, i: number) => decodeString(item, p, i) ) : undefined, + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CONFIG") + : "CONFIG", valueType: ConfigValueTypeSerializer.parse( json["value_type"], decodePath(path, "value_type") @@ -34,8 +39,9 @@ export const ConfigFeatureTypeSerializer = { serialize(value: ConfigFeatureType): any { return { - ...extraProperties(value, ["options", "valueType"]), + ...extraProperties(value, ["options", "type", "valueType"]), options: value.options, + type: value.type ?? "CONFIG", value_type: ConfigValueTypeSerializer.serialize(value.valueType), }; }, diff --git a/src/models/configResolvedEntitlementValue.ts b/src/models/configResolvedEntitlementValue.ts index 10a72f2..36ddcd4 100644 --- a/src/models/configResolvedEntitlementValue.ts +++ b/src/models/configResolvedEntitlementValue.ts @@ -1,9 +1,10 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type ConfigValue, ConfigValueSerializer } from "./configValue.js"; export interface ConfigResolvedEntitlementValue { + type: "CONFIG"; value: ConfigValue; } @@ -12,14 +13,19 @@ export const ConfigResolvedEntitlementValueSerializer = { parse(json: any, path = "$"): ConfigResolvedEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["type", "value"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CONFIG") + : "CONFIG", value: ConfigValueSerializer.parse(json["value"], decodePath(path, "value")), }; }, serialize(value: ConfigResolvedEntitlementValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["type", "value"]), + type: value.type ?? "CONFIG", value: ConfigValueSerializer.serialize(value.value), }; }, diff --git a/src/models/coupon.ts b/src/models/coupon.ts index aaf6d23..6ecb2d9 100644 --- a/src/models/coupon.ts +++ b/src/models/coupon.ts @@ -15,6 +15,12 @@ import { type PlanId, PlanIdSerializer } from "./planId.js"; export interface Coupon { archivedAt?: Date | null | undefined; + /** + * A promotional-credit (`CREDIT`) code is stored upper-case; other codes as written. A code + * is redeemed by the coupon with exactly that code, else by the only live coupon equal to it + * ignoring the case of ASCII letters; several such coupons and no exact match make it + * ambiguous. + */ code: string; createdAt: Date; description?: string | null | undefined; diff --git a/src/models/couponCreditScope.ts b/src/models/couponCreditScope.ts new file mode 100644 index 0000000..d30e202 --- /dev/null +++ b/src/models/couponCreditScope.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** Which subscriptions a promotional credit coupon's credit pays. */ +export const CouponCreditScope = { + Customer: "CUSTOMER", + Subscription: "SUBSCRIPTION", +} as const; +export type CouponCreditScope = + | (typeof CouponCreditScope)[keyof typeof CouponCreditScope] + | (string & {}); + +/** Converts `CouponCreditScope` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CouponCreditScopeSerializer = { + parse(json: any, path = "$"): CouponCreditScope { + return decodeString(json, path); + }, + + serialize(value: CouponCreditScope): any { + return value; + }, +}; diff --git a/src/models/couponDiscount.ts b/src/models/couponDiscount.ts index c83bac6..13c21eb 100644 --- a/src/models/couponDiscount.ts +++ b/src/models/couponDiscount.ts @@ -1,5 +1,6 @@ // this file is @generated import { decodeObject } from "../decode.js"; +import { type CreditDiscount, CreditDiscountSerializer } from "./creditDiscount.js"; import { type FixedDiscount, FixedDiscountSerializer } from "./fixedDiscount.js"; import { type PercentageDiscount, @@ -12,8 +13,14 @@ export interface CouponDiscountPercentage extends PercentageDiscount { export interface CouponDiscountFixed extends FixedDiscount { type: "FIXED"; } +export interface CouponDiscountCredit extends CreditDiscount { + type: "CREDIT"; +} -export type CouponDiscount = CouponDiscountPercentage | CouponDiscountFixed; +export type CouponDiscount = + | CouponDiscountPercentage + | CouponDiscountFixed + | CouponDiscountCredit; /** Converts `CouponDiscount` values from (`parse`) and to (`serialize`) their JSON form. */ export const CouponDiscountSerializer = { @@ -30,6 +37,11 @@ export const CouponDiscountSerializer = { ...FixedDiscountSerializer.parse(json, path), type: "FIXED", }; + case "CREDIT": + return { + ...CreditDiscountSerializer.parse(json, path), + type: "CREDIT", + }; default: // A variant added to the API after this SDK was generated, kept as received. return json; @@ -48,6 +60,11 @@ export const CouponDiscountSerializer = { ...FixedDiscountSerializer.serialize(value), type: "FIXED", }; + case "CREDIT": + return { + ...CreditDiscountSerializer.serialize(value), + type: "CREDIT", + }; default: return value; } diff --git a/src/models/createBudgetRequest.ts b/src/models/createBudgetRequest.ts new file mode 100644 index 0000000..9212edf --- /dev/null +++ b/src/models/createBudgetRequest.ts @@ -0,0 +1,98 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type BudgetBehavior, BudgetBehaviorSerializer } from "./budgetBehavior.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; + +export interface CreateBudgetRequest { + /** In minor units of the currency or credit unit. */ + amount: number; + behavior?: BudgetBehavior | null | undefined; + /** + * A credit unit (its code): the budget counts the usage priced in that unit, in its minor + * units. + */ + creditUnit?: string | null | undefined; + currency?: Currency | null | undefined; + /** + * An active subscription of the customer (`sub_…`): the budget then counts only that + * subscription's spend, in its currency. Absent counts the whole customer's. + */ + subscriptionId?: string | null | undefined; + /** Percentages of the amount (1 to 100, at most 10). Defaults to 50, 80 and 100. */ + thresholds?: number[] | null | undefined; +} + +/** Converts `CreateBudgetRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreateBudgetRequestSerializer = { + parse(json: any, path = "$"): CreateBudgetRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "behavior", + "credit_unit", + "currency", + "subscription_id", + "thresholds", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + behavior: + json["behavior"] != null + ? BudgetBehaviorSerializer.parse(json["behavior"], decodePath(path, "behavior")) + : json["behavior"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + thresholds: + json["thresholds"] != null + ? decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["thresholds"], + }; + }, + + serialize(value: CreateBudgetRequest): any { + return { + ...extraProperties(value, [ + "amount", + "behavior", + "creditUnit", + "currency", + "subscriptionId", + "thresholds", + ]), + amount: value.amount, + behavior: + value.behavior != null + ? BudgetBehaviorSerializer.serialize(value.behavior) + : value.behavior, + credit_unit: value.creditUnit, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + subscription_id: value.subscriptionId, + thresholds: value.thresholds, + }; + }, +}; diff --git a/src/models/createCheckoutSessionRequest.ts b/src/models/createCheckoutSessionRequest.ts index 3d669e4..61aa7fa 100644 --- a/src/models/createCheckoutSessionRequest.ts +++ b/src/models/createCheckoutSessionRequest.ts @@ -34,6 +34,12 @@ export interface CreateCheckoutSessionRequest { /** Automatically try to charge the customer's configured payment method on finalize. Default is true. */ chargeAutomatically?: boolean | null | undefined; components?: CreateSubscriptionComponents | null | undefined; + /** + * Code of the coupon to apply, used only when `coupon_ids` is empty. It names the coupon with + * exactly that code, else the only live coupon equal to it ignoring the case of ASCII + * letters. An unknown or ambiguous code is refused with 400. If the code no longer names a + * usable coupon when the customer pays, the payment is refused and nothing is charged. + */ couponCode?: string | null | undefined; couponIds?: CouponId[] | undefined; /** Customer ID or alias */ diff --git a/src/models/createConnectedAccountRequest.ts b/src/models/createConnectedAccountRequest.ts index d22f9c5..9b7c362 100644 --- a/src/models/createConnectedAccountRequest.ts +++ b/src/models/createConnectedAccountRequest.ts @@ -1,14 +1,16 @@ // this file is @generated import { extraProperties } from "../json.js"; import { decodeObject, decodePath, decodeString } from "../decode.js"; -import { type ConnectionType, ConnectionTypeSerializer } from "./connectionType.js"; -import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type CountryCode, CountryCodeSerializer } from "./countryCode.js"; +import { type OnboardingMode, OnboardingModeSerializer } from "./onboardingMode.js"; export interface CreateConnectedAccountRequest { - connectedOrganizationId: string; - connectionType?: ConnectionType | null | undefined; + country?: CountryCode | null | undefined; + email: string; metadata?: unknown | undefined; - platformCustomerId?: CustomerId | null | undefined; + mode?: OnboardingMode | null | undefined; + organizationName: string; + redirectUrl?: string | null | undefined; } /** Converts `CreateConnectedAccountRequest` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -17,52 +19,55 @@ export const CreateConnectedAccountRequestSerializer = { decodeObject(json, path); return { ...extraProperties(json, [ - "connected_organization_id", - "connection_type", + "country", + "email", "metadata", - "platform_customer_id", + "mode", + "organization_name", + "redirect_url", ]), - connectedOrganizationId: decodeString( - json["connected_organization_id"], + country: + json["country"] != null + ? CountryCodeSerializer.parse(json["country"], decodePath(path, "country")) + : json["country"], + email: decodeString(json["email"], path, "email"), + metadata: json["metadata"], + mode: + json["mode"] != null + ? OnboardingModeSerializer.parse(json["mode"], decodePath(path, "mode")) + : json["mode"], + organizationName: decodeString( + json["organization_name"], path, - "connected_organization_id" + "organization_name" ), - connectionType: - json["connection_type"] != null - ? ConnectionTypeSerializer.parse( - json["connection_type"], - decodePath(path, "connection_type") - ) - : json["connection_type"], - metadata: json["metadata"], - platformCustomerId: - json["platform_customer_id"] != null - ? CustomerIdSerializer.parse( - json["platform_customer_id"], - decodePath(path, "platform_customer_id") - ) - : json["platform_customer_id"], + redirectUrl: + json["redirect_url"] != null + ? decodeString(json["redirect_url"], path, "redirect_url") + : json["redirect_url"], }; }, serialize(value: CreateConnectedAccountRequest): any { return { ...extraProperties(value, [ - "connectedOrganizationId", - "connectionType", + "country", + "email", "metadata", - "platformCustomerId", + "mode", + "organizationName", + "redirectUrl", ]), - connected_organization_id: value.connectedOrganizationId, - connection_type: - value.connectionType != null - ? ConnectionTypeSerializer.serialize(value.connectionType) - : value.connectionType, + country: + value.country != null + ? CountryCodeSerializer.serialize(value.country) + : value.country, + email: value.email, metadata: value.metadata, - platform_customer_id: - value.platformCustomerId != null - ? CustomerIdSerializer.serialize(value.platformCustomerId) - : value.platformCustomerId, + mode: + value.mode != null ? OnboardingModeSerializer.serialize(value.mode) : value.mode, + organization_name: value.organizationName, + redirect_url: value.redirectUrl, }; }, }; diff --git a/src/models/createConnectedAccountResponse.ts b/src/models/createConnectedAccountResponse.ts new file mode 100644 index 0000000..5503e52 --- /dev/null +++ b/src/models/createConnectedAccountResponse.ts @@ -0,0 +1,101 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeObject, decodePath } from "../decode.js"; +import { type ConnectedAccount, ConnectedAccountSerializer } from "./connectedAccount.js"; +import { + type OnboardingLinkResponse, + OnboardingLinkResponseSerializer, +} from "./onboardingLinkResponse.js"; +/** The created account (same fields as `ConnectedAccount`) plus its onboarding link. */ +export interface CreateConnectedAccountResponse extends ConnectedAccount { + onboardingLink: OnboardingLinkResponse; +} + +/** Converts `CreateConnectedAccountResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreateConnectedAccountResponseSerializer = { + parse(json: any, path = "$"): CreateConnectedAccountResponse { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "onboarding_link", + "connected_organization_id", + "connected_tenant_id", + "connection_type", + "created_at", + "id", + "metadata", + "onboarding_completed_at", + "onboarding_mode", + "pending_country", + "pending_email", + "pending_organization_name", + "platform_customer_id", + "platform_organization_id", + "revoked_at", + "status", + ]), + ...pickProperties(ConnectedAccountSerializer.parse(json, path), [ + "connectedOrganizationId", + "connectedTenantId", + "connectionType", + "createdAt", + "id", + "metadata", + "onboardingCompletedAt", + "onboardingMode", + "pendingCountry", + "pendingEmail", + "pendingOrganizationName", + "platformCustomerId", + "platformOrganizationId", + "revokedAt", + "status", + ]), + onboardingLink: OnboardingLinkResponseSerializer.parse( + json["onboarding_link"], + decodePath(path, "onboarding_link") + ), + }; + }, + + serialize(value: CreateConnectedAccountResponse): any { + return { + ...extraProperties(value, [ + "onboardingLink", + "connectedOrganizationId", + "connectedTenantId", + "connectionType", + "createdAt", + "id", + "metadata", + "onboardingCompletedAt", + "onboardingMode", + "pendingCountry", + "pendingEmail", + "pendingOrganizationName", + "platformCustomerId", + "platformOrganizationId", + "revokedAt", + "status", + ]), + ...pickProperties(ConnectedAccountSerializer.serialize(value), [ + "connected_organization_id", + "connected_tenant_id", + "connection_type", + "created_at", + "id", + "metadata", + "onboarding_completed_at", + "onboarding_mode", + "pending_country", + "pending_email", + "pending_organization_name", + "platform_customer_id", + "platform_organization_id", + "revoked_at", + "status", + ]), + onboarding_link: OnboardingLinkResponseSerializer.serialize(value.onboardingLink), + }; + }, +}; diff --git a/src/models/createCouponRequest.ts b/src/models/createCouponRequest.ts index cae22e5..29d20d1 100644 --- a/src/models/createCouponRequest.ts +++ b/src/models/createCouponRequest.ts @@ -13,6 +13,10 @@ import { type CouponDiscount, CouponDiscountSerializer } from "./couponDiscount. import { type PlanId, PlanIdSerializer } from "./planId.js"; export interface CreateCouponRequest { + /** + * 1 to 64 ASCII letters, digits, hyphens or underscores. A promotional-credit (`CREDIT`) code + * is stored upper-case. Codes are matched as described on `Coupon.code`. + */ code: string; description?: string | null | undefined; discount: CouponDiscount; @@ -20,6 +24,10 @@ export interface CreateCouponRequest { planIds?: PlanId[] | undefined; recurringValue?: number | null | undefined; redemptionLimit?: number | null | undefined; + /** + * Whether one customer may redeem the coupon more than once. Must be false for a + * promotional-credit (`CREDIT`) coupon. + */ reusable?: boolean | undefined; } diff --git a/src/models/createCreditGrantRequest.ts b/src/models/createCreditGrantRequest.ts new file mode 100644 index 0000000..a12b37c --- /dev/null +++ b/src/models/createCreditGrantRequest.ts @@ -0,0 +1,191 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { + type CreditCostRequest, + CreditCostRequestSerializer, +} from "./creditCostRequest.js"; +import { type CreditGrantType, CreditGrantTypeSerializer } from "./creditGrantType.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { type ProductId, ProductIdSerializer } from "./productId.js"; +/** Credit granted without charging or invoicing. */ +export interface CreateCreditGrantRequest { + /** + * Credit granted, in minor units of `currency`, or of `credit_unit` when set (e.g. 500000 + * is 5,000.00 credits of a unit with precision 2). Positive. + */ + amount: number; + /** + * Restricts the credit to charges of these products; absent applies to every product. + * Combined with `applies_to`. Not available for credit units. + */ + applicableProductIds?: ProductId[] | null | undefined; + /** ALL pays any charge on an invoice; USAGE only usage charges. */ + appliesTo?: CreditAppliesTo | undefined; + cost?: CreditCostRequest | null | undefined; + /** + * Grants in this credit unit (its code) instead of a currency; excludes `currency`. Credit in + * a credit unit pays the usage priced in that unit, so `applies_to` must stay ALL. + */ + creditUnit?: string | null | undefined; + currency?: Currency | null | undefined; + /** When unspent credit lapses; absent never expires. */ + expiresAt?: Date | null | undefined; + /** + * Lower values are drawn first among grants of the same type that pay the same charges; + * defaults to 100. + */ + priority?: number | null | undefined; + /** Shown on the credit ledger. */ + reason?: string | null | undefined; + /** + * Your own reference, e.g. a contract or support ticket. Required for PAID credit that cost + * more than zero when the customer's invoicing entity is in France: the number of the invoice + * or receipt for the payment, as French law requires a supporting document for every + * accounting entry. Refused with 400 when missing. + */ + reference?: string | null | undefined; + /** + * The customer's subscription (`sub_…`) the credit belongs to: it pays only that + * subscription's charges and lapses when the subscription ends. It must not have ended, + * and its currency must be the grant's. Absent pays any of the customer's subscriptions. + */ + subscriptionId?: string | null | undefined; + /** + * PROMOTIONAL gives credit for free (a goodwill or marketing grant). PAID records credit + * the customer paid for outside of Meteroid: nothing is charged or invoiced, and the grant + * is shown as "Paid outside Meteroid". Usage paid with PAID currency credit is taxed on the + * invoice that bills it, so do not charge tax on the external sale of currency credit, or + * the customer is taxed twice. Credit in a credit unit is the exception: its usage is billed + * in credits, untaxed, so tax its sale as you would any other. Use a top-up to sell credit + * through Meteroid. + */ + type: CreditGrantType; +} + +/** Converts `CreateCreditGrantRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreateCreditGrantRequestSerializer = { + parse(json: any, path = "$"): CreateCreditGrantRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "applicable_product_ids", + "applies_to", + "cost", + "credit_unit", + "currency", + "expires_at", + "priority", + "reason", + "reference", + "subscription_id", + "type", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + applicableProductIds: + json["applicable_product_ids"] != null + ? decodeList( + json["applicable_product_ids"], + path, + "applicable_product_ids", + (item: any, p: string, i: number) => + ProductIdSerializer.parse(item, decodePath(p, i)) + ) + : json["applicable_product_ids"], + appliesTo: + json["applies_to"] != null + ? CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ) + : undefined, + cost: + json["cost"] != null + ? CreditCostRequestSerializer.parse(json["cost"], decodePath(path, "cost")) + : json["cost"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + expiresAt: + json["expires_at"] != null + ? decodeDateTime(json["expires_at"], path, "expires_at") + : json["expires_at"], + priority: + json["priority"] != null + ? decodeInteger(json["priority"], path, "priority") + : json["priority"], + reason: + json["reason"] != null + ? decodeString(json["reason"], path, "reason") + : json["reason"], + reference: + json["reference"] != null + ? decodeString(json["reference"], path, "reference") + : json["reference"], + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + type: CreditGrantTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: CreateCreditGrantRequest): any { + return { + ...extraProperties(value, [ + "amount", + "applicableProductIds", + "appliesTo", + "cost", + "creditUnit", + "currency", + "expiresAt", + "priority", + "reason", + "reference", + "subscriptionId", + "type", + ]), + amount: value.amount, + applicable_product_ids: + value.applicableProductIds != null + ? value.applicableProductIds.map((item: any) => + ProductIdSerializer.serialize(item) + ) + : value.applicableProductIds, + applies_to: + value.appliesTo != null + ? CreditAppliesToSerializer.serialize(value.appliesTo) + : undefined, + cost: + value.cost != null + ? CreditCostRequestSerializer.serialize(value.cost) + : value.cost, + credit_unit: value.creditUnit, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + expires_at: value.expiresAt, + priority: value.priority, + reason: value.reason, + reference: value.reference, + subscription_id: value.subscriptionId, + type: CreditGrantTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/createMetricRequest.ts b/src/models/createMetricRequest.ts index e37ffff..504e0df 100644 --- a/src/models/createMetricRequest.ts +++ b/src/models/createMetricRequest.ts @@ -26,6 +26,17 @@ export interface CreateMetricRequest { productId?: ProductId | null | undefined; segmentationMatrix?: MetricSegmentationMatrix | null | undefined; unitConversion?: UnitConversion | null | undefined; + /** + * What several units of the metric are called, e.g. `tokens`. Set together with + * `unit_singular`. Trimmed; at most 32 characters. + */ + unitPlural?: string | null | undefined; + /** + * What one unit of the metric is called, e.g. `token`, used to label quantities and + * prices ("$12.00 per 1M tokens"). Set both `unit_singular` and `unit_plural`, or neither. + * Trimmed; at most 32 characters. + */ + unitSingular?: string | null | undefined; usageGroupKey?: string | null | undefined; } @@ -45,6 +56,8 @@ export const CreateMetricRequestSerializer = { "product_id", "segmentation_matrix", "unit_conversion", + "unit_plural", + "unit_singular", "usage_group_key", ]), aggregationKey: @@ -93,6 +106,14 @@ export const CreateMetricRequestSerializer = { decodePath(path, "unit_conversion") ) : json["unit_conversion"], + unitPlural: + json["unit_plural"] != null + ? decodeString(json["unit_plural"], path, "unit_plural") + : json["unit_plural"], + unitSingular: + json["unit_singular"] != null + ? decodeString(json["unit_singular"], path, "unit_singular") + : json["unit_singular"], usageGroupKey: json["usage_group_key"] != null ? decodeString(json["usage_group_key"], path, "usage_group_key") @@ -113,6 +134,8 @@ export const CreateMetricRequestSerializer = { "productId", "segmentationMatrix", "unitConversion", + "unitPlural", + "unitSingular", "usageGroupKey", ]), aggregation_key: value.aggregationKey, @@ -139,6 +162,8 @@ export const CreateMetricRequestSerializer = { value.unitConversion != null ? UnitConversionSerializer.serialize(value.unitConversion) : value.unitConversion, + unit_plural: value.unitPlural, + unit_singular: value.unitSingular, usage_group_key: value.usageGroupKey, }; }, diff --git a/src/models/createPlanRequest.ts b/src/models/createPlanRequest.ts index 2ba0799..b701ce8 100644 --- a/src/models/createPlanRequest.ts +++ b/src/models/createPlanRequest.ts @@ -9,6 +9,10 @@ import { decodeString, } from "../decode.js"; import { type BillingConfig, BillingConfigSerializer } from "./billingConfig.js"; +import { + type CreditExhaustedRule, + CreditExhaustedRuleSerializer, +} from "./creditExhaustedRule.js"; import { type EntitlementSpecRequest, EntitlementSpecRequestSerializer, @@ -27,6 +31,7 @@ export interface CreatePlanRequest { addOns?: PlanAddOnInput[] | undefined; billing?: BillingConfig | null | undefined; components: PriceComponentInput[]; + creditExhaustedRule?: CreditExhaustedRule | null | undefined; currency: string; description?: string | null | undefined; /** @@ -59,6 +64,7 @@ export const CreatePlanRequestSerializer = { "add_ons", "billing", "components", + "credit_exhausted_rule", "currency", "description", "entitlements", @@ -91,6 +97,13 @@ export const CreatePlanRequestSerializer = { (item: any, p: string, i: number) => PriceComponentInputSerializer.parse(item, decodePath(p, i)) ), + creditExhaustedRule: + json["credit_exhausted_rule"] != null + ? CreditExhaustedRuleSerializer.parse( + json["credit_exhausted_rule"], + decodePath(path, "credit_exhausted_rule") + ) + : json["credit_exhausted_rule"], currency: decodeString(json["currency"], path, "currency"), description: json["description"] != null @@ -137,6 +150,7 @@ export const CreatePlanRequestSerializer = { "addOns", "billing", "components", + "creditExhaustedRule", "currency", "description", "entitlements", @@ -159,6 +173,10 @@ export const CreatePlanRequestSerializer = { components: value.components.map((item: any) => PriceComponentInputSerializer.serialize(item) ), + credit_exhausted_rule: + value.creditExhaustedRule != null + ? CreditExhaustedRuleSerializer.serialize(value.creditExhaustedRule) + : value.creditExhaustedRule, currency: value.currency, description: value.description, entitlements: diff --git a/src/models/createTopUpRequest.ts b/src/models/createTopUpRequest.ts new file mode 100644 index 0000000..2ddbada --- /dev/null +++ b/src/models/createTopUpRequest.ts @@ -0,0 +1,118 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { type TopUpCollection, TopUpCollectionSerializer } from "./topUpCollection.js"; +/** Credit sold to the customer, charged or invoiced. */ +export interface CreateTopUpRequest { + /** + * Credit to buy, positive, applying to ALL charges. In minor units of `currency`, charged + * one for one without tax: the usage it pays is taxed on the invoice that bills it. With + * `credit_unit`, in minor units of that unit (e.g. 500000 is 5,000.00 credits of a unit with + * precision 2), charged at the unit's price per credit in the customer's currency, plus tax + * under the unit's product. + */ + amount: number; + /** + * CHARGE (default) charges a saved payment method now; SEND_INVOICE issues an invoice and + * grants the credit once it is paid. + */ + collection?: TopUpCollection | undefined; + /** + * Buy credits of this credit unit (its code) instead of money; excludes `currency`. They are + * charged in the customer's currency at the customer's agreed price for the unit (the + * wallet's `unit_price`), else its list price, plus tax, under the unit's product. + */ + creditUnit?: string | null | undefined; + currency?: Currency | null | undefined; + /** Absolute expiry of the purchased credit; unset never expires. */ + expiresAt?: Date | null | undefined; + /** CHARGE only; defaults to the customer's default payment method. */ + paymentMethodId?: string | null | undefined; + /** + * With `credit_unit`: the negotiated price of one credit for this purchase, in major units of + * the customer's currency, as a decimal string (e.g. "0.0008"). Defaults to the wallet's + * `unit_price` when set, else the list price; the unit must still have a list price in that + * currency. + */ + unitPrice?: string | null | undefined; +} + +/** Converts `CreateTopUpRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreateTopUpRequestSerializer = { + parse(json: any, path = "$"): CreateTopUpRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "collection", + "credit_unit", + "currency", + "expires_at", + "payment_method_id", + "unit_price", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + collection: + json["collection"] != null + ? TopUpCollectionSerializer.parse( + json["collection"], + decodePath(path, "collection") + ) + : undefined, + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + expiresAt: + json["expires_at"] != null + ? decodeDateTime(json["expires_at"], path, "expires_at") + : json["expires_at"], + paymentMethodId: + json["payment_method_id"] != null + ? decodeString(json["payment_method_id"], path, "payment_method_id") + : json["payment_method_id"], + unitPrice: + json["unit_price"] != null + ? decodeString(json["unit_price"], path, "unit_price") + : json["unit_price"], + }; + }, + + serialize(value: CreateTopUpRequest): any { + return { + ...extraProperties(value, [ + "amount", + "collection", + "creditUnit", + "currency", + "expiresAt", + "paymentMethodId", + "unitPrice", + ]), + amount: value.amount, + collection: + value.collection != null + ? TopUpCollectionSerializer.serialize(value.collection) + : undefined, + credit_unit: value.creditUnit, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + expires_at: value.expiresAt, + payment_method_id: value.paymentMethodId, + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/createWebhookEndpointRequest.ts b/src/models/createWebhookEndpointRequest.ts index 57a17bc..0744e6b 100644 --- a/src/models/createWebhookEndpointRequest.ts +++ b/src/models/createWebhookEndpointRequest.ts @@ -14,7 +14,10 @@ import { export interface CreateWebhookEndpointRequest { description?: string | null | undefined; - /** Event types to subscribe to. Omit or leave empty to receive every event type. */ + /** + * Event types to subscribe to. Omit or leave empty to receive every event type except Beta + * ones, which are sent only to endpoints that list them. + */ eventTypes?: string[] | undefined; /** Custom headers sent with every delivery. */ headers?: WebhookHeaderInput[] | undefined; diff --git a/src/models/creditAppliesTo.ts b/src/models/creditAppliesTo.ts new file mode 100644 index 0000000..9568707 --- /dev/null +++ b/src/models/creditAppliesTo.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** Which charges credit pays: ALL pays any part of an invoice, USAGE only its usage charges. */ +export const CreditAppliesTo = { + All: "ALL", + Usage: "USAGE", +} as const; +export type CreditAppliesTo = + | (typeof CreditAppliesTo)[keyof typeof CreditAppliesTo] + | (string & {}); + +/** Converts `CreditAppliesTo` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditAppliesToSerializer = { + parse(json: any, path = "$"): CreditAppliesTo { + return decodeString(json, path); + }, + + serialize(value: CreditAppliesTo): any { + return value; + }, +}; diff --git a/src/models/creditCap.ts b/src/models/creditCap.ts new file mode 100644 index 0000000..806215c --- /dev/null +++ b/src/models/creditCap.ts @@ -0,0 +1,30 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; + +export interface CreditCap { + /** Usage beyond the credit invoiced per billing period, in minor units of `denomination`. */ + amount: number; + /** A currency or credit unit code. */ + denomination: string; +} + +/** Converts `CreditCap` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditCapSerializer = { + parse(json: any, path = "$"): CreditCap { + decodeObject(json, path); + return { + ...extraProperties(json, ["amount", "denomination"]), + amount: decodeInteger(json["amount"], path, "amount"), + denomination: decodeString(json["denomination"], path, "denomination"), + }; + }, + + serialize(value: CreditCap): any { + return { + ...extraProperties(value, ["amount", "denomination"]), + amount: value.amount, + denomination: value.denomination, + }; + }, +}; diff --git a/src/models/creditCaps.ts b/src/models/creditCaps.ts new file mode 100644 index 0000000..1163c6e --- /dev/null +++ b/src/models/creditCaps.ts @@ -0,0 +1,35 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CreditCap, CreditCapSerializer } from "./creditCap.js"; + +export interface CreditCaps { + /** One per denomination; usage charged in a denomination without a cap pauses at zero. */ + caps: CreditCap[]; + type: "invoice_up_to"; +} + +/** Converts `CreditCaps` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditCapsSerializer = { + parse(json: any, path = "$"): CreditCaps { + decodeObject(json, path); + return { + ...extraProperties(json, ["caps", "type"]), + caps: decodeList(json["caps"], path, "caps", (item: any, p: string, i: number) => + CreditCapSerializer.parse(item, decodePath(p, i)) + ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "invoice_up_to") + : "invoice_up_to", + }; + }, + + serialize(value: CreditCaps): any { + return { + ...extraProperties(value, ["caps", "type"]), + caps: value.caps.map((item: any) => CreditCapSerializer.serialize(item)), + type: value.type ?? "invoice_up_to", + }; + }, +}; diff --git a/src/models/creditCost.ts b/src/models/creditCost.ts new file mode 100644 index 0000000..6e6b8b5 --- /dev/null +++ b/src/models/creditCost.ts @@ -0,0 +1,30 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +/** Money in minor units of `currency`, net of tax. */ +export interface CreditCost { + /** In minor units of `currency`. */ + amount: number; + currency: Currency; +} + +/** Converts `CreditCost` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditCostSerializer = { + parse(json: any, path = "$"): CreditCost { + decodeObject(json, path); + return { + ...extraProperties(json, ["amount", "currency"]), + amount: decodeInteger(json["amount"], path, "amount"), + currency: CurrencySerializer.parse(json["currency"], decodePath(path, "currency")), + }; + }, + + serialize(value: CreditCost): any { + return { + ...extraProperties(value, ["amount", "currency"]), + amount: value.amount, + currency: CurrencySerializer.serialize(value.currency), + }; + }, +}; diff --git a/src/models/creditCostRequest.ts b/src/models/creditCostRequest.ts new file mode 100644 index 0000000..85c80f0 --- /dev/null +++ b/src/models/creditCostRequest.ts @@ -0,0 +1,30 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +/** Money in minor units of `currency`, net of tax. */ +export interface CreditCostRequest { + /** In minor units of `currency`; zero or positive. */ + amount: number; + currency: Currency; +} + +/** Converts `CreditCostRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditCostRequestSerializer = { + parse(json: any, path = "$"): CreditCostRequest { + decodeObject(json, path); + return { + ...extraProperties(json, ["amount", "currency"]), + amount: decodeInteger(json["amount"], path, "amount"), + currency: CurrencySerializer.parse(json["currency"], decodePath(path, "currency")), + }; + }, + + serialize(value: CreditCostRequest): any { + return { + ...extraProperties(value, ["amount", "currency"]), + amount: value.amount, + currency: CurrencySerializer.serialize(value.currency), + }; + }, +}; diff --git a/src/models/creditDiscount.ts b/src/models/creditDiscount.ts new file mode 100644 index 0000000..f581d8a --- /dev/null +++ b/src/models/creditDiscount.ts @@ -0,0 +1,71 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + type CouponCreditScope, + CouponCreditScopeSerializer, +} from "./couponCreditScope.js"; +/** + * Promotional credit added to the customer's credit balance when the subscription the coupon is + * redeemed on starts. It never discounts an invoice and applies before tax. A customer redeems + * it at most once, so the coupon cannot be `reusable`. Its code is case-insensitive: it is stored + * upper-case and redeemed whatever the case. + */ +export interface CreditDiscount { + /** Credit added per redemption, in major units (e.g. "25.00"). */ + amount: string; + /** ISO 4217 code; it must match the currency of the subscription the coupon is redeemed on. */ + currency: string; + /** Days the credit stays spendable after redemption, 1 to 3660. Absent: it never expires. */ + expiresInDays?: number | null | undefined; + /** + * CUSTOMER (default): the credit pays any of the customer's subscriptions. SUBSCRIPTION: the + * credit pays only the subscription the code is redeemed on, and ends with it. + */ + scope?: CouponCreditScope | undefined; + type: "CREDIT"; +} + +/** Converts `CreditDiscount` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditDiscountSerializer = { + parse(json: any, path = "$"): CreditDiscount { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "currency", + "expires_in_days", + "scope", + "type", + ]), + amount: decodeString(json["amount"], path, "amount"), + currency: decodeString(json["currency"], path, "currency"), + expiresInDays: + json["expires_in_days"] != null + ? decodeInteger(json["expires_in_days"], path, "expires_in_days") + : json["expires_in_days"], + scope: + json["scope"] != null + ? CouponCreditScopeSerializer.parse(json["scope"], decodePath(path, "scope")) + : undefined, + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CREDIT") + : "CREDIT", + }; + }, + + serialize(value: CreditDiscount): any { + return { + ...extraProperties(value, ["amount", "currency", "expiresInDays", "scope", "type"]), + amount: value.amount, + currency: value.currency, + expires_in_days: value.expiresInDays, + scope: + value.scope != null + ? CouponCreditScopeSerializer.serialize(value.scope) + : undefined, + type: value.type ?? "CREDIT", + }; + }, +}; diff --git a/src/models/creditExhaustedRule.ts b/src/models/creditExhaustedRule.ts new file mode 100644 index 0000000..e5d21e2 --- /dev/null +++ b/src/models/creditExhaustedRule.ts @@ -0,0 +1,79 @@ +// this file is @generated +import { decodeObject } from "../decode.js"; +import { type CreditCaps, CreditCapsSerializer } from "./creditCaps.js"; +import { + type CreditExhaustedRuleInvoiceVariant, + CreditExhaustedRuleInvoiceVariantSerializer, +} from "./creditExhaustedRuleInvoiceVariant.js"; +import { + type CreditExhaustedRulePauseVariant, + CreditExhaustedRulePauseVariantSerializer, +} from "./creditExhaustedRulePauseVariant.js"; + +export interface CreditExhaustedRuleInvoice extends CreditExhaustedRuleInvoiceVariant { + type: "invoice"; +} +export interface CreditExhaustedRulePause extends CreditExhaustedRulePauseVariant { + type: "pause"; +} +export interface CreditExhaustedRuleInvoiceUpTo extends CreditCaps { + type: "invoice_up_to"; +} + +/** + * What usage does once the credit it draws on runs out, for every denomination (currency or + * credit unit) the plan charges usage in. A customer's wallet can override it. + */ +export type CreditExhaustedRule = + | CreditExhaustedRuleInvoice + | CreditExhaustedRulePause + | CreditExhaustedRuleInvoiceUpTo; + +/** Converts `CreditExhaustedRule` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditExhaustedRuleSerializer = { + parse(json: any, path = "$"): CreditExhaustedRule { + decodeObject(json, path); + switch (json["type"]) { + case "invoice": + return { + ...CreditExhaustedRuleInvoiceVariantSerializer.parse(json, path), + type: "invoice", + }; + case "pause": + return { + ...CreditExhaustedRulePauseVariantSerializer.parse(json, path), + type: "pause", + }; + case "invoice_up_to": + return { + ...CreditCapsSerializer.parse(json, path), + type: "invoice_up_to", + }; + default: + // A variant added to the API after this SDK was generated, kept as received. + return json; + } + }, + + serialize(value: CreditExhaustedRule): any { + switch (value.type) { + case "invoice": + return { + ...CreditExhaustedRuleInvoiceVariantSerializer.serialize(value), + type: "invoice", + }; + case "pause": + return { + ...CreditExhaustedRulePauseVariantSerializer.serialize(value), + type: "pause", + }; + case "invoice_up_to": + return { + ...CreditCapsSerializer.serialize(value), + type: "invoice_up_to", + }; + default: + return value; + } + }, +}; diff --git a/src/models/creditExhaustedRuleInvoiceVariant.ts b/src/models/creditExhaustedRuleInvoiceVariant.ts new file mode 100644 index 0000000..c1706bc --- /dev/null +++ b/src/models/creditExhaustedRuleInvoiceVariant.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; +/** Usage beyond the credit is invoiced. */ +export interface CreditExhaustedRuleInvoiceVariant { + type: "invoice"; +} + +/** Converts `CreditExhaustedRuleInvoiceVariant` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditExhaustedRuleInvoiceVariantSerializer = { + parse(json: any, path = "$"): CreditExhaustedRuleInvoiceVariant { + decodeObject(json, path); + return { + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "invoice") + : "invoice", + }; + }, + + serialize(value: CreditExhaustedRuleInvoiceVariant): any { + return { + ...extraProperties(value, ["type"]), + type: value.type ?? "invoice", + }; + }, +}; diff --git a/src/models/creditExhaustedRulePauseVariant.ts b/src/models/creditExhaustedRulePauseVariant.ts new file mode 100644 index 0000000..09f79b8 --- /dev/null +++ b/src/models/creditExhaustedRulePauseVariant.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; +/** Access checks refuse usage once the credit the subscription can spend is used up. */ +export interface CreditExhaustedRulePauseVariant { + type: "pause"; +} + +/** Converts `CreditExhaustedRulePauseVariant` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditExhaustedRulePauseVariantSerializer = { + parse(json: any, path = "$"): CreditExhaustedRulePauseVariant { + decodeObject(json, path); + return { + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "pause") + : "pause", + }; + }, + + serialize(value: CreditExhaustedRulePauseVariant): any { + return { + ...extraProperties(value, ["type"]), + type: value.type ?? "pause", + }; + }, +}; diff --git a/src/models/creditExpiryUnit.ts b/src/models/creditExpiryUnit.ts new file mode 100644 index 0000000..bead290 --- /dev/null +++ b/src/models/creditExpiryUnit.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const CreditExpiryUnit = { + Day: "DAY", + Month: "MONTH", + BillingPeriod: "BILLING_PERIOD", +} as const; +export type CreditExpiryUnit = + | (typeof CreditExpiryUnit)[keyof typeof CreditExpiryUnit] + | (string & {}); + +/** Converts `CreditExpiryUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditExpiryUnitSerializer = { + parse(json: any, path = "$"): CreditExpiryUnit { + return decodeString(json, path); + }, + + serialize(value: CreditExpiryUnit): any { + return value; + }, +}; diff --git a/src/models/creditFee.ts b/src/models/creditFee.ts new file mode 100644 index 0000000..d62e618 --- /dev/null +++ b/src/models/creditFee.ts @@ -0,0 +1,118 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditPackExpiry, CreditPackExpirySerializer } from "./creditPackExpiry.js"; +import { + type CreditPackRollover, + CreditPackRolloverSerializer, +} from "./creditPackRollover.js"; +import { type CreditPackUnit, CreditPackUnitSerializer } from "./creditPackUnit.js"; +/** + * A credit pack: charged like a fixed fee, it grants `credit_amount` × `quantity` of credit once + * paid, in the subscription currency or in `credit_unit`. A zero `unit_price` makes it credit + * included with the plan (promotional). A currency pack priced below its credit grants the price + * paid as paid credit and the difference as promotional bonus credit, which applies before tax. + */ +export interface CreditFee { + /** + * Credit granted per pack, in major units of the subscription currency, or a number of + * credits of `credit_unit` when set. + */ + creditAmount: string; + creditUnit?: CreditPackUnit | null | undefined; + expiry?: CreditPackExpiry | null | undefined; + /** + * When true, billed and granted once, on the subscription's first invoice, instead of every + * period. + */ + once?: boolean | undefined; + /** Packs billed and granted each time. */ + quantity: number; + rollover?: CreditPackRollover | null | undefined; + type: "CREDIT"; + /** Price of one pack, in major units of the subscription currency. */ + unitPrice: string; +} + +/** Converts `CreditFee` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditFeeSerializer = { + parse(json: any, path = "$"): CreditFee { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "credit_amount", + "credit_unit", + "expiry", + "once", + "quantity", + "rollover", + "type", + "unit_price", + ]), + creditAmount: decodeString(json["credit_amount"], path, "credit_amount"), + creditUnit: + json["credit_unit"] != null + ? CreditPackUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], + expiry: + json["expiry"] != null + ? CreditPackExpirySerializer.parse(json["expiry"], decodePath(path, "expiry")) + : json["expiry"], + once: json["once"] != null ? decodeBoolean(json["once"], path, "once") : undefined, + quantity: decodeInteger(json["quantity"], path, "quantity"), + rollover: + json["rollover"] != null + ? CreditPackRolloverSerializer.parse( + json["rollover"], + decodePath(path, "rollover") + ) + : json["rollover"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CREDIT") + : "CREDIT", + unitPrice: decodeString(json["unit_price"], path, "unit_price"), + }; + }, + + serialize(value: CreditFee): any { + return { + ...extraProperties(value, [ + "creditAmount", + "creditUnit", + "expiry", + "once", + "quantity", + "rollover", + "type", + "unitPrice", + ]), + credit_amount: value.creditAmount, + credit_unit: + value.creditUnit != null + ? CreditPackUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, + expiry: + value.expiry != null + ? CreditPackExpirySerializer.serialize(value.expiry) + : value.expiry, + once: value.once, + quantity: value.quantity, + rollover: + value.rollover != null + ? CreditPackRolloverSerializer.serialize(value.rollover) + : value.rollover, + type: value.type ?? "CREDIT", + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/creditFeeStructure.ts b/src/models/creditFeeStructure.ts new file mode 100644 index 0000000..797b865 --- /dev/null +++ b/src/models/creditFeeStructure.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; + +export interface CreditFeeStructure { + type: "CREDIT"; +} + +/** Converts `CreditFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditFeeStructureSerializer = { + parse(json: any, path = "$"): CreditFeeStructure { + decodeObject(json, path); + return { + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CREDIT") + : "CREDIT", + }; + }, + + serialize(value: CreditFeeStructure): any { + return { + ...extraProperties(value, ["type"]), + type: value.type ?? "CREDIT", + }; + }, +}; diff --git a/src/models/creditGrant.ts b/src/models/creditGrant.ts new file mode 100644 index 0000000..fbb774b --- /dev/null +++ b/src/models/creditGrant.ts @@ -0,0 +1,293 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { type CreditCost, CreditCostSerializer } from "./creditCost.js"; +import { type CreditGrantKind, CreditGrantKindSerializer } from "./creditGrantKind.js"; +import { + type CreditGrantSource, + CreditGrantSourceSerializer, +} from "./creditGrantSource.js"; +import { + type CreditGrantStatus, + CreditGrantStatusSerializer, +} from "./creditGrantStatus.js"; +import { type CreditGrantType, CreditGrantTypeSerializer } from "./creditGrantType.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { type ProductId, ProductIdSerializer } from "./productId.js"; +/** + * A lot of credit given to or bought by a customer. An invoice applies promotional currency + * credit before tax and paid credit after it. Within each, it draws the grants that belong to + * the invoiced subscription first, then grants restricted to products (the fewest products + * first), then usage-only grants, then the others; then by lowest `priority`, then the soonest + * to lapse. + */ +export interface CreditGrant { + /** Amount granted, in minor units of `currency` or `credit_unit`. */ + amount: number; + /** + * The products whose charges the credit pays, combined with `applies_to`; empty when it + * applies to every product. + */ + applicableProductIds: ProductId[]; + /** ALL pays any charge on an invoice; USAGE only usage charges. */ + appliesTo: CreditAppliesTo; + /** + * Only on the response that created a PAID currency grant whose `cost` was below its + * amount: the PROMOTIONAL "Bonus credit" grant created beside it for the difference, with + * the same expiry, scope and priority. + */ + bonusGrantId?: string | null | undefined; + cost?: CreditCost | null | undefined; + /** + * `cost` per one major unit of credit, in major units of the cost currency (e.g. "0.008"), + * rounded to 12 decimal places, for display only. + */ + costBasis?: string | null | undefined; + /** When the grant was recorded. */ + createdAt: Date; + /** The credit note that gave the credit back. */ + creditNoteId?: string | null | undefined; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + currency?: Currency | null | undefined; + /** When the credit became spendable. */ + effectiveAt: Date; + /** + * When the subscription the grant belongs to ended, if it ended. Unspent credit lapses then + * (status EXPIRED), even before `expires_at`. + */ + endedAt?: Date | null | undefined; + /** Lost to expiry; present only on an expired grant. */ + expiredAmount?: number | null | undefined; + /** When unspent credit lapses; absent never expires. */ + expiresAt?: Date | null | undefined; + /** The grant's id (`cgr_…`). */ + id: string; + /** The invoice that sold the credit, or whose void or negative total gave it back. */ + invoiceId?: string | null | undefined; + /** The group the grant is shown in: INCLUDED, PREPAID, BONUS or ACCOUNT_BALANCE. */ + kind: CreditGrantKind; + /** + * The group's name as Meteroid shows it: "Included with ", "Purchased credit", "Free + * credit" or "Account balance". + */ + kindLabel: string; + /** + * Lower values are drawn first among grants of the same type that pay the same charges; 100 + * by default. + */ + priority: number; + /** Shown on the credit ledger. */ + reason: string; + /** Your own reference, e.g. a contract or support ticket. */ + reference?: string | null | undefined; + /** Not spent yet, in the same minor units. */ + remaining: number; + /** Where the credit came from. */ + source: CreditGrantSource; + /** PENDING until `effective_at`, then ACTIVE, DEPLETED once spent, or EXPIRED. */ + status: CreditGrantStatus; + /** + * The subscription the grant belongs to (`sub_…`): it pays only that subscription's + * charges, and lapses when the subscription ends. Null when it pays any of the customer's + * subscriptions. + */ + subscriptionId?: string | null | undefined; + /** PAID or PROMOTIONAL: whether it applies after or before tax. */ + type: CreditGrantType; +} + +/** Converts `CreditGrant` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantSerializer = { + parse(json: any, path = "$"): CreditGrant { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "applicable_product_ids", + "applies_to", + "bonus_grant_id", + "cost", + "cost_basis", + "created_at", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "effective_at", + "ended_at", + "expired_amount", + "expires_at", + "id", + "invoice_id", + "kind", + "kind_label", + "priority", + "reason", + "reference", + "remaining", + "source", + "status", + "subscription_id", + "type", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + applicableProductIds: decodeList( + json["applicable_product_ids"], + path, + "applicable_product_ids", + (item: any, p: string, i: number) => + ProductIdSerializer.parse(item, decodePath(p, i)) + ), + appliesTo: CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ), + bonusGrantId: + json["bonus_grant_id"] != null + ? decodeString(json["bonus_grant_id"], path, "bonus_grant_id") + : json["bonus_grant_id"], + cost: + json["cost"] != null + ? CreditCostSerializer.parse(json["cost"], decodePath(path, "cost")) + : json["cost"], + costBasis: + json["cost_basis"] != null + ? decodeString(json["cost_basis"], path, "cost_basis") + : json["cost_basis"], + createdAt: decodeDateTime(json["created_at"], path, "created_at"), + creditNoteId: + json["credit_note_id"] != null + ? decodeString(json["credit_note_id"], path, "credit_note_id") + : json["credit_note_id"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + effectiveAt: decodeDateTime(json["effective_at"], path, "effective_at"), + endedAt: + json["ended_at"] != null + ? decodeDateTime(json["ended_at"], path, "ended_at") + : json["ended_at"], + expiredAmount: + json["expired_amount"] != null + ? decodeInteger(json["expired_amount"], path, "expired_amount") + : json["expired_amount"], + expiresAt: + json["expires_at"] != null + ? decodeDateTime(json["expires_at"], path, "expires_at") + : json["expires_at"], + id: decodeString(json["id"], path, "id"), + invoiceId: + json["invoice_id"] != null + ? decodeString(json["invoice_id"], path, "invoice_id") + : json["invoice_id"], + kind: CreditGrantKindSerializer.parse(json["kind"], decodePath(path, "kind")), + kindLabel: decodeString(json["kind_label"], path, "kind_label"), + priority: decodeInteger(json["priority"], path, "priority"), + reason: decodeString(json["reason"], path, "reason"), + reference: + json["reference"] != null + ? decodeString(json["reference"], path, "reference") + : json["reference"], + remaining: decodeInteger(json["remaining"], path, "remaining"), + source: CreditGrantSourceSerializer.parse( + json["source"], + decodePath(path, "source") + ), + status: CreditGrantStatusSerializer.parse( + json["status"], + decodePath(path, "status") + ), + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + type: CreditGrantTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: CreditGrant): any { + return { + ...extraProperties(value, [ + "amount", + "applicableProductIds", + "appliesTo", + "bonusGrantId", + "cost", + "costBasis", + "createdAt", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "effectiveAt", + "endedAt", + "expiredAmount", + "expiresAt", + "id", + "invoiceId", + "kind", + "kindLabel", + "priority", + "reason", + "reference", + "remaining", + "source", + "status", + "subscriptionId", + "type", + ]), + amount: value.amount, + applicable_product_ids: value.applicableProductIds.map((item: any) => + ProductIdSerializer.serialize(item) + ), + applies_to: CreditAppliesToSerializer.serialize(value.appliesTo), + bonus_grant_id: value.bonusGrantId, + cost: value.cost != null ? CreditCostSerializer.serialize(value.cost) : value.cost, + cost_basis: value.costBasis, + created_at: value.createdAt, + credit_note_id: value.creditNoteId, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + effective_at: value.effectiveAt, + ended_at: value.endedAt, + expired_amount: value.expiredAmount, + expires_at: value.expiresAt, + id: value.id, + invoice_id: value.invoiceId, + kind: CreditGrantKindSerializer.serialize(value.kind), + kind_label: value.kindLabel, + priority: value.priority, + reason: value.reason, + reference: value.reference, + remaining: value.remaining, + source: CreditGrantSourceSerializer.serialize(value.source), + status: CreditGrantStatusSerializer.serialize(value.status), + subscription_id: value.subscriptionId, + type: CreditGrantTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/creditGrantExpiredEvent.ts b/src/models/creditGrantExpiredEvent.ts new file mode 100644 index 0000000..fa36142 --- /dev/null +++ b/src/models/creditGrantExpiredEvent.ts @@ -0,0 +1,97 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { + type CreditGrantExpiredEventData, + CreditGrantExpiredEventDataSerializer, +} from "./creditGrantExpiredEventData.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; + +export interface CreditGrantExpiredEvent extends CreditGrantExpiredEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `CreditGrantExpiredEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantExpiredEventSerializer = { + parse(json: any, path = "$"): CreditGrantExpiredEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "expired_amount", + "expired_at", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + ...pickProperties(CreditGrantExpiredEventDataSerializer.parse(json, path), [ + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "expiredAmount", + "expiredAt", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: CreditGrantExpiredEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "expiredAmount", + "expiredAt", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + ...pickProperties(CreditGrantExpiredEventDataSerializer.serialize(value), [ + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "expired_amount", + "expired_at", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/creditGrantExpiredEventData.ts b/src/models/creditGrantExpiredEventData.ts new file mode 100644 index 0000000..e309164 --- /dev/null +++ b/src/models/creditGrantExpiredEventData.ts @@ -0,0 +1,151 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { type CreditGrantId, CreditGrantIdSerializer } from "./creditGrantId.js"; +import { + type CreditGrantLapseReason, + CreditGrantLapseReasonSerializer, +} from "./creditGrantLapseReason.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type LedgerEntryId, LedgerEntryIdSerializer } from "./ledgerEntryId.js"; +/** + * A credit grant expired, or the subscription it belongs to ended, with credit left, which + * lapsed. + */ +export interface CreditGrantExpiredEventData { + /** The products whose charges the grant pays; empty when it pays every product. */ + applicableProductIds: string[]; + /** What the grant pays: ALL any charge, USAGE only usage charges. */ + appliesTo: CreditAppliesTo; + /** The grant that expired. */ + creditGrantId: CreditGrantId; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + /** Unspent credit that lapsed, in minor units of `currency` or `credit_unit`. */ + expiredAmount: number; + /** When the grant expired, or its subscription ended. */ + expiredAt: Date; + /** The credit ledger entry recording the expiry. */ + ledgerEntryId: LedgerEntryId; + /** + * SUBSCRIPTION_ENDED when the subscription the grant belongs to ended at or before the grant's + * expiry, EXPIRED otherwise. + */ + reason: CreditGrantLapseReason; + /** + * The subscription the grant belongs to: it pays only that subscription's charges. Null when + * it pays any of the customer's subscriptions. + */ + subscriptionId?: string | null | undefined; +} + +/** Converts `CreditGrantExpiredEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantExpiredEventDataSerializer = { + parse(json: any, path = "$"): CreditGrantExpiredEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "expired_amount", + "expired_at", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + applicableProductIds: decodeList( + json["applicable_product_ids"], + path, + "applicable_product_ids", + (item: any, p: string, i: number) => decodeString(item, p, i) + ), + appliesTo: CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ), + creditGrantId: CreditGrantIdSerializer.parse( + json["credit_grant_id"], + decodePath(path, "credit_grant_id") + ), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + expiredAmount: decodeInteger(json["expired_amount"], path, "expired_amount"), + expiredAt: decodeDateTime(json["expired_at"], path, "expired_at"), + ledgerEntryId: LedgerEntryIdSerializer.parse( + json["ledger_entry_id"], + decodePath(path, "ledger_entry_id") + ), + reason: CreditGrantLapseReasonSerializer.parse( + json["reason"], + decodePath(path, "reason") + ), + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + }; + }, + + serialize(value: CreditGrantExpiredEventData): any { + return { + ...extraProperties(value, [ + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "expiredAmount", + "expiredAt", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + applicable_product_ids: value.applicableProductIds, + applies_to: CreditAppliesToSerializer.serialize(value.appliesTo), + credit_grant_id: CreditGrantIdSerializer.serialize(value.creditGrantId), + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + expired_amount: value.expiredAmount, + expired_at: value.expiredAt, + ledger_entry_id: LedgerEntryIdSerializer.serialize(value.ledgerEntryId), + reason: CreditGrantLapseReasonSerializer.serialize(value.reason), + subscription_id: value.subscriptionId, + }; + }, +}; diff --git a/src/models/creditGrantId.ts b/src/models/creditGrantId.ts new file mode 100644 index 0000000..30fda1a --- /dev/null +++ b/src/models/creditGrantId.ts @@ -0,0 +1,15 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export type CreditGrantId = string; + +/** Converts `CreditGrantId` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantIdSerializer = { + parse(json: any, path = "$"): CreditGrantId { + return decodeString(json, path); + }, + + serialize(value: CreditGrantId): any { + return value; + }, +}; diff --git a/src/models/creditGrantKind.ts b/src/models/creditGrantKind.ts new file mode 100644 index 0000000..1bd98b0 --- /dev/null +++ b/src/models/creditGrantKind.ts @@ -0,0 +1,30 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** + * The group a grant is shown in, from where it came from and what it pays: + * - INCLUDED: credit a subscription's plan includes, which renews with it; + * - PREPAID: credit bought (purchases, top-ups, paid packs, credit paid for outside Meteroid); + * - BONUS: credit given (the bonus part of discounted credit, promo codes, welcome credit); + * - ACCOUNT_BALANCE: the customer's money that pays any invoice (credit notes, returned invoices, + * the balance carried from before credit grants, credit added for any charge). + */ +export const CreditGrantKind = { + Included: "INCLUDED", + Prepaid: "PREPAID", + Bonus: "BONUS", + AccountBalance: "ACCOUNT_BALANCE", +} as const; +export type CreditGrantKind = + | (typeof CreditGrantKind)[keyof typeof CreditGrantKind] + | (string & {}); + +/** Converts `CreditGrantKind` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantKindSerializer = { + parse(json: any, path = "$"): CreditGrantKind { + return decodeString(json, path); + }, + + serialize(value: CreditGrantKind): any { + return value; + }, +}; diff --git a/src/models/creditGrantLapseReason.ts b/src/models/creditGrantLapseReason.ts new file mode 100644 index 0000000..8ace39c --- /dev/null +++ b/src/models/creditGrantLapseReason.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** Why a credit grant's unspent credit lapsed. */ +export const CreditGrantLapseReason = { + Expired: "EXPIRED", + SubscriptionEnded: "SUBSCRIPTION_ENDED", +} as const; +export type CreditGrantLapseReason = + | (typeof CreditGrantLapseReason)[keyof typeof CreditGrantLapseReason] + | (string & {}); + +/** Converts `CreditGrantLapseReason` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantLapseReasonSerializer = { + parse(json: any, path = "$"): CreditGrantLapseReason { + return decodeString(json, path); + }, + + serialize(value: CreditGrantLapseReason): any { + return value; + }, +}; diff --git a/src/models/creditGrantListResponse.ts b/src/models/creditGrantListResponse.ts new file mode 100644 index 0000000..054cfbe --- /dev/null +++ b/src/models/creditGrantListResponse.ts @@ -0,0 +1,38 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type CreditGrant, CreditGrantSerializer } from "./creditGrant.js"; +import { + type PaginationResponse, + PaginationResponseSerializer, +} from "./paginationResponse.js"; +/** A page of credit grants. */ +export interface CreditGrantListResponse { + data: CreditGrant[]; + paginationMeta: PaginationResponse; +} + +/** Converts `CreditGrantListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantListResponseSerializer = { + parse(json: any, path = "$"): CreditGrantListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data", "pagination_meta"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + CreditGrantSerializer.parse(item, decodePath(p, i)) + ), + paginationMeta: PaginationResponseSerializer.parse( + json["pagination_meta"], + decodePath(path, "pagination_meta") + ), + }; + }, + + serialize(value: CreditGrantListResponse): any { + return { + ...extraProperties(value, ["data", "paginationMeta"]), + data: value.data.map((item: any) => CreditGrantSerializer.serialize(item)), + pagination_meta: PaginationResponseSerializer.serialize(value.paginationMeta), + }; + }, +}; diff --git a/src/models/creditGrantSource.ts b/src/models/creditGrantSource.ts new file mode 100644 index 0000000..2c1b220 --- /dev/null +++ b/src/models/creditGrantSource.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const CreditGrantSource = { + Manual: "MANUAL", + Purchase: "PURCHASE", + Plan: "PLAN", + CreditNote: "CREDIT_NOTE", + Adjustment: "ADJUSTMENT", + Migrated: "MIGRATED", + Rollover: "ROLLOVER", + Coupon: "COUPON", + Overpayment: "OVERPAYMENT", +} as const; +export type CreditGrantSource = + | (typeof CreditGrantSource)[keyof typeof CreditGrantSource] + | (string & {}); + +/** Converts `CreditGrantSource` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantSourceSerializer = { + parse(json: any, path = "$"): CreditGrantSource { + return decodeString(json, path); + }, + + serialize(value: CreditGrantSource): any { + return value; + }, +}; diff --git a/src/models/creditGrantStatus.ts b/src/models/creditGrantStatus.ts new file mode 100644 index 0000000..e764c75 --- /dev/null +++ b/src/models/creditGrantStatus.ts @@ -0,0 +1,23 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const CreditGrantStatus = { + Pending: "PENDING", + Active: "ACTIVE", + Depleted: "DEPLETED", + Expired: "EXPIRED", +} as const; +export type CreditGrantStatus = + | (typeof CreditGrantStatus)[keyof typeof CreditGrantStatus] + | (string & {}); + +/** Converts `CreditGrantStatus` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantStatusSerializer = { + parse(json: any, path = "$"): CreditGrantStatus { + return decodeString(json, path); + }, + + serialize(value: CreditGrantStatus): any { + return value; + }, +}; diff --git a/src/models/creditGrantType.ts b/src/models/creditGrantType.ts new file mode 100644 index 0000000..464e6dc --- /dev/null +++ b/src/models/creditGrantType.ts @@ -0,0 +1,26 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** + * PAID credit was bought, through Meteroid or outside it, and applies after tax like a payment. + * PROMOTIONAL credit was given (included with a plan, a coupon, bonus credit, a goodwill grant): + * it applies before tax, like a discount, so it is spent before paid credit. Credit-unit grants + * are drawn together, whatever their type. + */ +export const CreditGrantType = { + Paid: "PAID", + Promotional: "PROMOTIONAL", +} as const; +export type CreditGrantType = + | (typeof CreditGrantType)[keyof typeof CreditGrantType] + | (string & {}); + +/** Converts `CreditGrantType` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditGrantTypeSerializer = { + parse(json: any, path = "$"): CreditGrantType { + return decodeString(json, path); + }, + + serialize(value: CreditGrantType): any { + return value; + }, +}; diff --git a/src/models/creditPackExpiry.ts b/src/models/creditPackExpiry.ts new file mode 100644 index 0000000..87752cd --- /dev/null +++ b/src/models/creditPackExpiry.ts @@ -0,0 +1,31 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { type CreditExpiryUnit, CreditExpiryUnitSerializer } from "./creditExpiryUnit.js"; +/** How long funded credit stays spendable. BILLING_PERIOD takes value 1. */ +export interface CreditPackExpiry { + /** DAY, MONTH or BILLING_PERIOD. */ + unit: CreditExpiryUnit; + /** How many days or months; 1 for BILLING_PERIOD. */ + value: number; +} + +/** Converts `CreditPackExpiry` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditPackExpirySerializer = { + parse(json: any, path = "$"): CreditPackExpiry { + decodeObject(json, path); + return { + ...extraProperties(json, ["unit", "value"]), + unit: CreditExpiryUnitSerializer.parse(json["unit"], decodePath(path, "unit")), + value: decodeInteger(json["value"], path, "value"), + }; + }, + + serialize(value: CreditPackExpiry): any { + return { + ...extraProperties(value, ["unit", "value"]), + unit: CreditExpiryUnitSerializer.serialize(value.unit), + value: value.value, + }; + }, +}; diff --git a/src/models/creditPackRollover.ts b/src/models/creditPackRollover.ts new file mode 100644 index 0000000..dde8a30 --- /dev/null +++ b/src/models/creditPackRollover.ts @@ -0,0 +1,40 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CreditPackExpiry, CreditPackExpirySerializer } from "./creditPackExpiry.js"; +/** + * Unspent included credit carried once into a new grant when it expires, spent before the next + * period's credit. + */ +export interface CreditPackRollover { + /** Term of the rolled credit from the original expiry: DAY or MONTH. */ + expiry: CreditPackExpiry; + /** Cap per pack, in the pack's credit; absent carries all that is left. */ + maxAmount?: string | null | undefined; +} + +/** Converts `CreditPackRollover` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditPackRolloverSerializer = { + parse(json: any, path = "$"): CreditPackRollover { + decodeObject(json, path); + return { + ...extraProperties(json, ["expiry", "max_amount"]), + expiry: CreditPackExpirySerializer.parse( + json["expiry"], + decodePath(path, "expiry") + ), + maxAmount: + json["max_amount"] != null + ? decodeString(json["max_amount"], path, "max_amount") + : json["max_amount"], + }; + }, + + serialize(value: CreditPackRollover): any { + return { + ...extraProperties(value, ["expiry", "maxAmount"]), + expiry: CreditPackExpirySerializer.serialize(value.expiry), + max_amount: value.maxAmount, + }; + }, +}; diff --git a/src/models/creditPackUnit.ts b/src/models/creditPackUnit.ts new file mode 100644 index 0000000..80b6c32 --- /dev/null +++ b/src/models/creditPackUnit.ts @@ -0,0 +1,37 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; +/** The credit unit a credit pack grants. */ +export interface CreditPackUnit { + /** The credit unit's code, e.g. `CREDITS`. */ + code: string; + /** The credit unit's id (`cun_…`). */ + creditUnitId: string; + /** + * Decimal places of the unit: credit balances and ledger amounts in it are integers of + * 10^-precision credit. + */ + precision: number; +} + +/** Converts `CreditPackUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditPackUnitSerializer = { + parse(json: any, path = "$"): CreditPackUnit { + decodeObject(json, path); + return { + ...extraProperties(json, ["code", "credit_unit_id", "precision"]), + code: decodeString(json["code"], path, "code"), + creditUnitId: decodeString(json["credit_unit_id"], path, "credit_unit_id"), + precision: decodeInteger(json["precision"], path, "precision"), + }; + }, + + serialize(value: CreditPackUnit): any { + return { + ...extraProperties(value, ["code", "creditUnitId", "precision"]), + code: value.code, + credit_unit_id: value.creditUnitId, + precision: value.precision, + }; + }, +}; diff --git a/src/models/creditPlanFee.ts b/src/models/creditPlanFee.ts new file mode 100644 index 0000000..455f105 --- /dev/null +++ b/src/models/creditPlanFee.ts @@ -0,0 +1,124 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { + type BillingPeriodEnum, + BillingPeriodEnumSerializer, +} from "./billingPeriodEnum.js"; +import { type CreditPackExpiry, CreditPackExpirySerializer } from "./creditPackExpiry.js"; +import { + type CreditPackRollover, + CreditPackRolloverSerializer, +} from "./creditPackRollover.js"; +/** + * Credit pack: charged `unit_price` × `quantity` in advance each billing period, it grants + * `credit_amount` × `quantity` of credit, in the plan currency or in `credit_unit_id`, once paid. + * A zero `unit_price` makes it credit included with the plan (promotional). A currency pack + * priced below its credit (e.g. 500.00 buys 550.00) grants the price paid as paid credit and the + * difference as promotional bonus credit, which applies before tax. + */ +export interface CreditPlanFee { + cadence: BillingPeriodEnum; + creditAmount: string; + /** + * The credit unit `credit_amount` is granted in; absent grants the plan currency. The pack is + * paid in the plan currency, and taxed when sold if it grants a credit unit. + */ + creditUnitId?: string | null | undefined; + expiry?: CreditPackExpiry | null | undefined; + /** + * When true, the pack is billed and its credit granted once, on the subscription's first + * invoice, instead of every period (e.g. a welcome credit). A plan change grants it on the + * next invoice only if the subscription never received a one-time credit of the same + * product; credit packs billed every period don't count. Cannot be combined with `rollover`. + */ + once?: boolean | undefined; + quantity: number; + rollover?: CreditPackRollover | null | undefined; + type: "CREDIT"; + unitPrice: string; +} + +/** Converts `CreditPlanFee` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditPlanFeeSerializer = { + parse(json: any, path = "$"): CreditPlanFee { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "cadence", + "credit_amount", + "credit_unit_id", + "expiry", + "once", + "quantity", + "rollover", + "type", + "unit_price", + ]), + cadence: BillingPeriodEnumSerializer.parse( + json["cadence"], + decodePath(path, "cadence") + ), + creditAmount: decodeString(json["credit_amount"], path, "credit_amount"), + creditUnitId: + json["credit_unit_id"] != null + ? decodeString(json["credit_unit_id"], path, "credit_unit_id") + : json["credit_unit_id"], + expiry: + json["expiry"] != null + ? CreditPackExpirySerializer.parse(json["expiry"], decodePath(path, "expiry")) + : json["expiry"], + once: json["once"] != null ? decodeBoolean(json["once"], path, "once") : undefined, + quantity: decodeInteger(json["quantity"], path, "quantity"), + rollover: + json["rollover"] != null + ? CreditPackRolloverSerializer.parse( + json["rollover"], + decodePath(path, "rollover") + ) + : json["rollover"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "CREDIT") + : "CREDIT", + unitPrice: decodeString(json["unit_price"], path, "unit_price"), + }; + }, + + serialize(value: CreditPlanFee): any { + return { + ...extraProperties(value, [ + "cadence", + "creditAmount", + "creditUnitId", + "expiry", + "once", + "quantity", + "rollover", + "type", + "unitPrice", + ]), + cadence: BillingPeriodEnumSerializer.serialize(value.cadence), + credit_amount: value.creditAmount, + credit_unit_id: value.creditUnitId, + expiry: + value.expiry != null + ? CreditPackExpirySerializer.serialize(value.expiry) + : value.expiry, + once: value.once, + quantity: value.quantity, + rollover: + value.rollover != null + ? CreditPackRolloverSerializer.serialize(value.rollover) + : value.rollover, + type: value.type ?? "CREDIT", + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/creditUnit.ts b/src/models/creditUnit.ts new file mode 100644 index 0000000..1834d20 --- /dev/null +++ b/src/models/creditUnit.ts @@ -0,0 +1,104 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditUnitPrice, CreditUnitPriceSerializer } from "./creditUnitPrice.js"; +/** + * A tenant-defined denomination usage can be priced or credit granted in, instead of money. + * `code` and `precision` are immutable once created. + */ +export interface CreditUnit { + /** Archived units take no new prices, packs or grants; existing ones keep working. */ + archived: boolean; + /** Upper-case code naming the unit in wallets, grants and webhooks, e.g. `CREDITS`. */ + code: string; + /** The unit's id (`cun_…`). */ + id: string; + /** Singular display name, e.g. "Credit". */ + name: string; + /** Plural display name, e.g. "Credits". */ + pluralName: string; + /** Minor-unit exponent: amounts of this unit are integers of 10^-precision credit. */ + precision: number; + /** The active selling prices, one per currency. */ + prices: CreditUnitPrice[]; + /** + * The product sales of this unit are booked under: their tax category and accounting code. + * The unit can be sold (top-ups) only once it is set. + */ + productId?: string | null | undefined; + /** Short display symbol, e.g. "cr". */ + symbol?: string | null | undefined; +} + +/** Converts `CreditUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitSerializer = { + parse(json: any, path = "$"): CreditUnit { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "archived", + "code", + "id", + "name", + "plural_name", + "precision", + "prices", + "product_id", + "symbol", + ]), + archived: decodeBoolean(json["archived"], path, "archived"), + code: decodeString(json["code"], path, "code"), + id: decodeString(json["id"], path, "id"), + name: decodeString(json["name"], path, "name"), + pluralName: decodeString(json["plural_name"], path, "plural_name"), + precision: decodeInteger(json["precision"], path, "precision"), + prices: decodeList( + json["prices"], + path, + "prices", + (item: any, p: string, i: number) => + CreditUnitPriceSerializer.parse(item, decodePath(p, i)) + ), + productId: + json["product_id"] != null + ? decodeString(json["product_id"], path, "product_id") + : json["product_id"], + symbol: + json["symbol"] != null + ? decodeString(json["symbol"], path, "symbol") + : json["symbol"], + }; + }, + + serialize(value: CreditUnit): any { + return { + ...extraProperties(value, [ + "archived", + "code", + "id", + "name", + "pluralName", + "precision", + "prices", + "productId", + "symbol", + ]), + archived: value.archived, + code: value.code, + id: value.id, + name: value.name, + plural_name: value.pluralName, + precision: value.precision, + prices: value.prices.map((item: any) => CreditUnitPriceSerializer.serialize(item)), + product_id: value.productId, + symbol: value.symbol, + }; + }, +}; diff --git a/src/models/creditUnitCreateRequest.ts b/src/models/creditUnitCreateRequest.ts new file mode 100644 index 0000000..70b022f --- /dev/null +++ b/src/models/creditUnitCreateRequest.ts @@ -0,0 +1,48 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; +/** A new credit unit. */ +export interface CreditUnitCreateRequest { + /** + * Immutable once created: 4 to 16 characters, A-Z/0-9/_, starting with a letter. Never an + * ISO currency code (those are always 3 letters). + */ + code: string; + /** Singular display name, 1 to 64 characters, e.g. "Credit". */ + name: string; + /** Plural display name, 1 to 64 characters, e.g. "Credits". */ + pluralName: string; + /** Immutable once created: 0 to 6. */ + precision: number; + /** Short display symbol, at most 8 characters. */ + symbol?: string | null | undefined; +} + +/** Converts `CreditUnitCreateRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitCreateRequestSerializer = { + parse(json: any, path = "$"): CreditUnitCreateRequest { + decodeObject(json, path); + return { + ...extraProperties(json, ["code", "name", "plural_name", "precision", "symbol"]), + code: decodeString(json["code"], path, "code"), + name: decodeString(json["name"], path, "name"), + pluralName: decodeString(json["plural_name"], path, "plural_name"), + precision: decodeInteger(json["precision"], path, "precision"), + symbol: + json["symbol"] != null + ? decodeString(json["symbol"], path, "symbol") + : json["symbol"], + }; + }, + + serialize(value: CreditUnitCreateRequest): any { + return { + ...extraProperties(value, ["code", "name", "pluralName", "precision", "symbol"]), + code: value.code, + name: value.name, + plural_name: value.pluralName, + precision: value.precision, + symbol: value.symbol, + }; + }, +}; diff --git a/src/models/creditUnitListResponse.ts b/src/models/creditUnitListResponse.ts new file mode 100644 index 0000000..b3697bb --- /dev/null +++ b/src/models/creditUnitListResponse.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type CreditUnit, CreditUnitSerializer } from "./creditUnit.js"; +/** The tenant's credit units. */ +export interface CreditUnitListResponse { + data: CreditUnit[]; +} + +/** Converts `CreditUnitListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitListResponseSerializer = { + parse(json: any, path = "$"): CreditUnitListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + CreditUnitSerializer.parse(item, decodePath(p, i)) + ), + }; + }, + + serialize(value: CreditUnitListResponse): any { + return { + ...extraProperties(value, ["data"]), + data: value.data.map((item: any) => CreditUnitSerializer.serialize(item)), + }; + }, +}; diff --git a/src/models/creditUnitPrice.ts b/src/models/creditUnitPrice.ts new file mode 100644 index 0000000..6799474 --- /dev/null +++ b/src/models/creditUnitPrice.ts @@ -0,0 +1,60 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodeString } from "../decode.js"; +/** + * What one credit sells for in a currency. A price is never edited: setting a new one for the + * same currency archives it. + */ +export interface CreditUnitPrice { + /** When a newer price, or its removal, replaced it; absent while active. */ + archivedAt?: Date | null | undefined; + /** When the price was set. */ + createdAt: Date; + /** ISO 4217 code of the currency the unit sells in. */ + currency: string; + /** The price's id (`cup_…`). */ + id: string; + /** Major units of `currency` per credit, as a decimal string (e.g. "0.001"). */ + unitPrice: string; +} + +/** Converts `CreditUnitPrice` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitPriceSerializer = { + parse(json: any, path = "$"): CreditUnitPrice { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "archived_at", + "created_at", + "currency", + "id", + "unit_price", + ]), + archivedAt: + json["archived_at"] != null + ? decodeDateTime(json["archived_at"], path, "archived_at") + : json["archived_at"], + createdAt: decodeDateTime(json["created_at"], path, "created_at"), + currency: decodeString(json["currency"], path, "currency"), + id: decodeString(json["id"], path, "id"), + unitPrice: decodeString(json["unit_price"], path, "unit_price"), + }; + }, + + serialize(value: CreditUnitPrice): any { + return { + ...extraProperties(value, [ + "archivedAt", + "createdAt", + "currency", + "id", + "unitPrice", + ]), + archived_at: value.archivedAt, + created_at: value.createdAt, + currency: value.currency, + id: value.id, + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/creditUnitPriceListResponse.ts b/src/models/creditUnitPriceListResponse.ts new file mode 100644 index 0000000..12c239b --- /dev/null +++ b/src/models/creditUnitPriceListResponse.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type CreditUnitPrice, CreditUnitPriceSerializer } from "./creditUnitPrice.js"; +/** A credit unit's selling prices, newest first. */ +export interface CreditUnitPriceListResponse { + data: CreditUnitPrice[]; +} + +/** Converts `CreditUnitPriceListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitPriceListResponseSerializer = { + parse(json: any, path = "$"): CreditUnitPriceListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + CreditUnitPriceSerializer.parse(item, decodePath(p, i)) + ), + }; + }, + + serialize(value: CreditUnitPriceListResponse): any { + return { + ...extraProperties(value, ["data"]), + data: value.data.map((item: any) => CreditUnitPriceSerializer.serialize(item)), + }; + }, +}; diff --git a/src/models/creditUnitPriceSetRequest.ts b/src/models/creditUnitPriceSetRequest.ts new file mode 100644 index 0000000..f08e0de --- /dev/null +++ b/src/models/creditUnitPriceSetRequest.ts @@ -0,0 +1,29 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; +/** The new price of one credit in a currency. */ +export interface CreditUnitPriceSetRequest { + /** + * Major units of the currency per credit, as a decimal string: positive, at most 12 decimal + * places. + */ + unitPrice: string; +} + +/** Converts `CreditUnitPriceSetRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitPriceSetRequestSerializer = { + parse(json: any, path = "$"): CreditUnitPriceSetRequest { + decodeObject(json, path); + return { + ...extraProperties(json, ["unit_price"]), + unitPrice: decodeString(json["unit_price"], path, "unit_price"), + }; + }, + + serialize(value: CreditUnitPriceSetRequest): any { + return { + ...extraProperties(value, ["unitPrice"]), + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/creditUnitUpdateRequest.ts b/src/models/creditUnitUpdateRequest.ts new file mode 100644 index 0000000..20b8070 --- /dev/null +++ b/src/models/creditUnitUpdateRequest.ts @@ -0,0 +1,76 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeBoolean, decodeObject, decodeString } from "../decode.js"; +/** + * Partial update: an absent field is left unchanged. `code` and `precision` have no field here, + * they are immutable. `symbol` set to `null` clears it. + */ +export interface CreditUnitUpdateRequest { + /** Blocks the unit from new prices, packs and grants; existing ones keep working. */ + archived?: boolean | null | undefined; + /** Singular display name, 1 to 64 characters. */ + name?: string | null | undefined; + /** Plural display name, 1 to 64 characters. */ + pluralName?: string | null | undefined; + /** + * The product sales of the unit are booked under; `null` clears it, which stops the unit + * from being sold. + */ + productId?: string | null | undefined; + /** + * Validated by the store (trimmed, at most 8 characters) rather than here: `validator` has + * no built-in support for a double `Option`. + */ + symbol?: string | null | undefined; +} + +/** Converts `CreditUnitUpdateRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const CreditUnitUpdateRequestSerializer = { + parse(json: any, path = "$"): CreditUnitUpdateRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "archived", + "name", + "plural_name", + "product_id", + "symbol", + ]), + archived: + json["archived"] != null + ? decodeBoolean(json["archived"], path, "archived") + : json["archived"], + name: + json["name"] != null ? decodeString(json["name"], path, "name") : json["name"], + pluralName: + json["plural_name"] != null + ? decodeString(json["plural_name"], path, "plural_name") + : json["plural_name"], + productId: + json["product_id"] != null + ? decodeString(json["product_id"], path, "product_id") + : json["product_id"], + symbol: + json["symbol"] != null + ? decodeString(json["symbol"], path, "symbol") + : json["symbol"], + }; + }, + + serialize(value: CreditUnitUpdateRequest): any { + return { + ...extraProperties(value, [ + "archived", + "name", + "pluralName", + "productId", + "symbol", + ]), + archived: value.archived, + name: value.name, + plural_name: value.pluralName, + product_id: value.productId, + symbol: value.symbol, + }; + }, +}; diff --git a/src/models/declineKind.ts b/src/models/declineKind.ts index 5e2c179..6fe57e4 100644 --- a/src/models/declineKind.ts +++ b/src/models/declineKind.ts @@ -10,6 +10,7 @@ export const DeclineKind = { Fraud: "FRAUD", ProcessingError: "PROCESSING_ERROR", Other: "OTHER", + DoNotRetry: "DO_NOT_RETRY", } as const; export type DeclineKind = (typeof DeclineKind)[keyof typeof DeclineKind] | (string & {}); diff --git a/src/models/doubleSegmentationMatrix.ts b/src/models/doubleSegmentationMatrix.ts index 03ae0fa..e41769d 100644 --- a/src/models/doubleSegmentationMatrix.ts +++ b/src/models/doubleSegmentationMatrix.ts @@ -1,11 +1,12 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type MetricDimension, MetricDimensionSerializer } from "./metricDimension.js"; export interface DoubleSegmentationMatrix { dimension1: MetricDimension; dimension2: MetricDimension; + type: "DOUBLE"; } /** Converts `DoubleSegmentationMatrix` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,7 +14,7 @@ export const DoubleSegmentationMatrixSerializer = { parse(json: any, path = "$"): DoubleSegmentationMatrix { decodeObject(json, path); return { - ...extraProperties(json, ["dimension1", "dimension2"]), + ...extraProperties(json, ["dimension1", "dimension2", "type"]), dimension1: MetricDimensionSerializer.parse( json["dimension1"], decodePath(path, "dimension1") @@ -22,14 +23,19 @@ export const DoubleSegmentationMatrixSerializer = { json["dimension2"], decodePath(path, "dimension2") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "DOUBLE") + : "DOUBLE", }; }, serialize(value: DoubleSegmentationMatrix): any { return { - ...extraProperties(value, ["dimension1", "dimension2"]), + ...extraProperties(value, ["dimension1", "dimension2", "type"]), dimension1: MetricDimensionSerializer.serialize(value.dimension1), dimension2: MetricDimensionSerializer.serialize(value.dimension2), + type: value.type ?? "DOUBLE", }; }, }; diff --git a/src/models/entitlementCheck.ts b/src/models/entitlementCheck.ts new file mode 100644 index 0000000..f94772f --- /dev/null +++ b/src/models/entitlementCheck.ts @@ -0,0 +1,191 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type ConfigValue, ConfigValueSerializer } from "./configValue.js"; +import { + type EntitlementCheckFeature, + EntitlementCheckFeatureSerializer, +} from "./entitlementCheckFeature.js"; +import { + type EntitlementCheckLimit, + EntitlementCheckLimitSerializer, +} from "./entitlementCheckLimit.js"; +import { + type EntitlementCheckPeriod, + EntitlementCheckPeriodSerializer, +} from "./entitlementCheckPeriod.js"; +import { + type EntitlementCheckReason, + EntitlementCheckReasonSerializer, +} from "./entitlementCheckReason.js"; +/** Whether a customer may consume more of a feature now. */ +export interface EntitlementCheck { + /** When the usage behind the answer was measured. */ + asOf: Date; + /** Always false: the answer reflects usage up to `as_of`. */ + exact: boolean; + feature: EntitlementCheckFeature; + hasAccess: boolean; + /** + * The entitlement allows overage (`ALLOW`) and the requested units go beyond its limit: + * access is granted, and the overage is billed. + */ + inOverage: boolean; + /** Age of that usage, in milliseconds. */ + lagMs: number; + limit?: string | null | undefined; + /** + * Deprecated: always empty. Customer-specific limits are entitlement overrides, reported in + * `used`, `limit` and `remaining`. + */ + limits: EntitlementCheckLimit[]; + /** + * True when a hard limit is within 5% of being reached, reached, or refuses the request. + * While true, check before every request with its actual `requested`, and do not cache an + * answer that grants access. + */ + nearLimit: boolean; + period?: EntitlementCheckPeriod | null | undefined; + reason: EntitlementCheckReason; + /** + * Units left before the limit, grace excluded: 0 while `has_access` is true when usage is + * within the grace allowance. + */ + remaining?: string | null | undefined; + /** + * When to check again, in milliseconds. After a refusal by a limit whose period ends within + * 24 hours: the time until it ends (a smaller `requested` may still be allowed sooner); + * absent after a refusal by a sliding window, whose usage leaves it gradually. While + * `near_limit` is true and access is granted: 1000. + */ + retryAfterMs?: number | null | undefined; + /** + * `used`, `limit`, `remaining` and `period` report the entitlement's limit. Absent when the + * entitlement has no limit. + */ + used?: string | null | undefined; + value?: ConfigValue | null | undefined; +} + +/** Converts `EntitlementCheck` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckSerializer = { + parse(json: any, path = "$"): EntitlementCheck { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "as_of", + "exact", + "feature", + "has_access", + "in_overage", + "lag_ms", + "limit", + "limits", + "near_limit", + "period", + "reason", + "remaining", + "retry_after_ms", + "used", + "value", + ]), + asOf: decodeDateTime(json["as_of"], path, "as_of"), + exact: decodeBoolean(json["exact"], path, "exact"), + feature: EntitlementCheckFeatureSerializer.parse( + json["feature"], + decodePath(path, "feature") + ), + hasAccess: decodeBoolean(json["has_access"], path, "has_access"), + inOverage: decodeBoolean(json["in_overage"], path, "in_overage"), + lagMs: decodeInteger(json["lag_ms"], path, "lag_ms"), + limit: + json["limit"] != null + ? decodeString(json["limit"], path, "limit") + : json["limit"], + limits: decodeList( + json["limits"], + path, + "limits", + (item: any, p: string, i: number) => + EntitlementCheckLimitSerializer.parse(item, decodePath(p, i)) + ), + nearLimit: decodeBoolean(json["near_limit"], path, "near_limit"), + period: + json["period"] != null + ? EntitlementCheckPeriodSerializer.parse( + json["period"], + decodePath(path, "period") + ) + : json["period"], + reason: EntitlementCheckReasonSerializer.parse( + json["reason"], + decodePath(path, "reason") + ), + remaining: + json["remaining"] != null + ? decodeString(json["remaining"], path, "remaining") + : json["remaining"], + retryAfterMs: + json["retry_after_ms"] != null + ? decodeInteger(json["retry_after_ms"], path, "retry_after_ms") + : json["retry_after_ms"], + used: + json["used"] != null ? decodeString(json["used"], path, "used") : json["used"], + value: + json["value"] != null + ? ConfigValueSerializer.parse(json["value"], decodePath(path, "value")) + : json["value"], + }; + }, + + serialize(value: EntitlementCheck): any { + return { + ...extraProperties(value, [ + "asOf", + "exact", + "feature", + "hasAccess", + "inOverage", + "lagMs", + "limit", + "limits", + "nearLimit", + "period", + "reason", + "remaining", + "retryAfterMs", + "used", + "value", + ]), + as_of: value.asOf, + exact: value.exact, + feature: EntitlementCheckFeatureSerializer.serialize(value.feature), + has_access: value.hasAccess, + in_overage: value.inOverage, + lag_ms: value.lagMs, + limit: value.limit, + limits: value.limits.map((item: any) => + EntitlementCheckLimitSerializer.serialize(item) + ), + near_limit: value.nearLimit, + period: + value.period != null + ? EntitlementCheckPeriodSerializer.serialize(value.period) + : value.period, + reason: EntitlementCheckReasonSerializer.serialize(value.reason), + remaining: value.remaining, + retry_after_ms: value.retryAfterMs, + used: value.used, + value: + value.value != null ? ConfigValueSerializer.serialize(value.value) : value.value, + }; + }, +}; diff --git a/src/models/entitlementCheckFeature.ts b/src/models/entitlementCheckFeature.ts new file mode 100644 index 0000000..0c46d8f --- /dev/null +++ b/src/models/entitlementCheckFeature.ts @@ -0,0 +1,29 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; +import { type FeatureId, FeatureIdSerializer } from "./featureId.js"; + +export interface EntitlementCheckFeature { + code: string; + id: FeatureId; +} + +/** Converts `EntitlementCheckFeature` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckFeatureSerializer = { + parse(json: any, path = "$"): EntitlementCheckFeature { + decodeObject(json, path); + return { + ...extraProperties(json, ["code", "id"]), + code: decodeString(json["code"], path, "code"), + id: FeatureIdSerializer.parse(json["id"], decodePath(path, "id")), + }; + }, + + serialize(value: EntitlementCheckFeature): any { + return { + ...extraProperties(value, ["code", "id"]), + code: value.code, + id: FeatureIdSerializer.serialize(value.id), + }; + }, +}; diff --git a/src/models/entitlementCheckLimit.ts b/src/models/entitlementCheckLimit.ts new file mode 100644 index 0000000..6cd9df8 --- /dev/null +++ b/src/models/entitlementCheckLimit.ts @@ -0,0 +1,85 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeMap, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { + type EntitlementCheckLimitBehavior, + EntitlementCheckLimitBehaviorSerializer, +} from "./entitlementCheckLimitBehavior.js"; +import { type UsageLimitId, UsageLimitIdSerializer } from "./usageLimitId.js"; +/** Deprecated: customer usage limits were replaced by entitlement overrides; never returned. */ +export interface EntitlementCheckLimit { + behavior: EntitlementCheckLimitBehavior; + /** The group the limit was evaluated for, when the limit is grouped. */ + group?: { [key: string]: string } | null | undefined; + hasAccess: boolean; + limit: string; + remaining: string; + usageLimitId: UsageLimitId; + used: string; +} + +/** Converts `EntitlementCheckLimit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckLimitSerializer = { + parse(json: any, path = "$"): EntitlementCheckLimit { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "behavior", + "group", + "has_access", + "limit", + "remaining", + "usage_limit_id", + "used", + ]), + behavior: EntitlementCheckLimitBehaviorSerializer.parse( + json["behavior"], + decodePath(path, "behavior") + ), + group: + json["group"] != null + ? decodeMap( + json["group"], + path, + "group", + (entry: any, p: string, key: string) => decodeString(entry, p, key) + ) + : json["group"], + hasAccess: decodeBoolean(json["has_access"], path, "has_access"), + limit: decodeString(json["limit"], path, "limit"), + remaining: decodeString(json["remaining"], path, "remaining"), + usageLimitId: UsageLimitIdSerializer.parse( + json["usage_limit_id"], + decodePath(path, "usage_limit_id") + ), + used: decodeString(json["used"], path, "used"), + }; + }, + + serialize(value: EntitlementCheckLimit): any { + return { + ...extraProperties(value, [ + "behavior", + "group", + "hasAccess", + "limit", + "remaining", + "usageLimitId", + "used", + ]), + behavior: EntitlementCheckLimitBehaviorSerializer.serialize(value.behavior), + group: value.group, + has_access: value.hasAccess, + limit: value.limit, + remaining: value.remaining, + usage_limit_id: UsageLimitIdSerializer.serialize(value.usageLimitId), + used: value.used, + }; + }, +}; diff --git a/src/models/entitlementCheckLimitBehavior.ts b/src/models/entitlementCheckLimitBehavior.ts new file mode 100644 index 0000000..ee08e65 --- /dev/null +++ b/src/models/entitlementCheckLimitBehavior.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const EntitlementCheckLimitBehavior = { + Track: "TRACK", + Soft: "SOFT", + Hard: "HARD", +} as const; +export type EntitlementCheckLimitBehavior = + | (typeof EntitlementCheckLimitBehavior)[keyof typeof EntitlementCheckLimitBehavior] + | (string & {}); + +/** Converts `EntitlementCheckLimitBehavior` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckLimitBehaviorSerializer = { + parse(json: any, path = "$"): EntitlementCheckLimitBehavior { + return decodeString(json, path); + }, + + serialize(value: EntitlementCheckLimitBehavior): any { + return value; + }, +}; diff --git a/src/models/entitlementCheckPeriod.ts b/src/models/entitlementCheckPeriod.ts new file mode 100644 index 0000000..a9a6fc7 --- /dev/null +++ b/src/models/entitlementCheckPeriod.ts @@ -0,0 +1,29 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeDateTime, decodeObject } from "../decode.js"; + +export interface EntitlementCheckPeriod { + /** Absent when the period never ends. */ + end?: Date | null | undefined; + start: Date; +} + +/** Converts `EntitlementCheckPeriod` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckPeriodSerializer = { + parse(json: any, path = "$"): EntitlementCheckPeriod { + decodeObject(json, path); + return { + ...extraProperties(json, ["end", "start"]), + end: json["end"] != null ? decodeDateTime(json["end"], path, "end") : json["end"], + start: decodeDateTime(json["start"], path, "start"), + }; + }, + + serialize(value: EntitlementCheckPeriod): any { + return { + ...extraProperties(value, ["end", "start"]), + end: value.end, + start: value.start, + }; + }, +}; diff --git a/src/models/entitlementCheckReason.ts b/src/models/entitlementCheckReason.ts new file mode 100644 index 0000000..57cd8a7 --- /dev/null +++ b/src/models/entitlementCheckReason.ts @@ -0,0 +1,26 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const EntitlementCheckReason = { + WithinLimit: "WITHIN_LIMIT", + LimitReached: "LIMIT_REACHED", + NoEntitlement: "NO_ENTITLEMENT", + Disabled: "DISABLED", + BudgetExceeded: "BUDGET_EXCEEDED", + InsufficientBalance: "INSUFFICIENT_BALANCE", + TooManyGroups: "TOO_MANY_GROUPS", +} as const; +export type EntitlementCheckReason = + | (typeof EntitlementCheckReason)[keyof typeof EntitlementCheckReason] + | (string & {}); + +/** Converts `EntitlementCheckReason` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementCheckReasonSerializer = { + parse(json: any, path = "$"): EntitlementCheckReason { + return decodeString(json, path); + }, + + serialize(value: EntitlementCheckReason): any { + return value; + }, +}; diff --git a/src/models/entitlementOverageBehavior.ts b/src/models/entitlementOverageBehavior.ts new file mode 100644 index 0000000..6df9f76 --- /dev/null +++ b/src/models/entitlementOverageBehavior.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** What happens once usage reaches the limit. */ +export const EntitlementOverageBehavior = { + Block: "BLOCK", + Allow: "ALLOW", +} as const; +export type EntitlementOverageBehavior = + | (typeof EntitlementOverageBehavior)[keyof typeof EntitlementOverageBehavior] + | (string & {}); + +/** Converts `EntitlementOverageBehavior` values from (`parse`) and to (`serialize`) their JSON form. */ +export const EntitlementOverageBehaviorSerializer = { + parse(json: any, path = "$"): EntitlementOverageBehavior { + return decodeString(json, path); + }, + + serialize(value: EntitlementOverageBehavior): any { + return value; + }, +}; diff --git a/src/models/eventType.ts b/src/models/eventType.ts index c64aea8..f352117 100644 --- a/src/models/eventType.ts +++ b/src/models/eventType.ts @@ -39,7 +39,20 @@ export const EventType = { RefundSettled: "refund.settled", RefundFailed: "refund.failed", PaymentReversed: "payment.reversed", + PaymentReinstated: "payment.reinstated", PaymentFailed: "payment.failed", + WalletFunded: "wallet.funded", + WalletDebited: "wallet.debited", + WalletBalanceLow: "wallet.balance_low", + WalletCreditUnrecovered: "wallet.credit_unrecovered", + WalletCreditRecovered: "wallet.credit_recovered", + WalletAutoTopUpFailed: "wallet.auto_top_up_failed", + WalletAutoTopUpSuspended: "wallet.auto_top_up_suspended", + WalletAutoTopUpConsentChanged: "wallet.auto_top_up_consent_changed", + WalletDepleted: "wallet.depleted", + WalletRecovered: "wallet.recovered", + WalletAutoTopUpCapReached: "wallet.auto_top_up_cap_reached", + CreditGrantExpired: "credit_grant.expired", } as const; export type EventType = (typeof EventType)[keyof typeof EventType] | (string & {}); diff --git a/src/models/existingPriceRef.ts b/src/models/existingPriceRef.ts index 848f988..f93a4fc 100644 --- a/src/models/existingPriceRef.ts +++ b/src/models/existingPriceRef.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type PriceId, PriceIdSerializer } from "./priceId.js"; export interface ExistingPriceRef { id: PriceId; + type: "EXISTING"; } /** Converts `ExistingPriceRef` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,15 +13,20 @@ export const ExistingPriceRefSerializer = { parse(json: any, path = "$"): ExistingPriceRef { decodeObject(json, path); return { - ...extraProperties(json, ["id"]), + ...extraProperties(json, ["id", "type"]), id: PriceIdSerializer.parse(json["id"], decodePath(path, "id")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "EXISTING") + : "EXISTING", }; }, serialize(value: ExistingPriceRef): any { return { - ...extraProperties(value, ["id"]), + ...extraProperties(value, ["id", "type"]), id: PriceIdSerializer.serialize(value.id), + type: value.type ?? "EXISTING", }; }, }; diff --git a/src/models/existingProductRef.ts b/src/models/existingProductRef.ts index f3e8582..b2d7357 100644 --- a/src/models/existingProductRef.ts +++ b/src/models/existingProductRef.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type ProductId, ProductIdSerializer } from "./productId.js"; export interface ExistingProductRef { id: ProductId; + type: "EXISTING"; } /** Converts `ExistingProductRef` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,15 +13,20 @@ export const ExistingProductRefSerializer = { parse(json: any, path = "$"): ExistingProductRef { decodeObject(json, path); return { - ...extraProperties(json, ["id"]), + ...extraProperties(json, ["id", "type"]), id: ProductIdSerializer.parse(json["id"], decodePath(path, "id")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "EXISTING") + : "EXISTING", }; }, serialize(value: ExistingProductRef): any { return { - ...extraProperties(value, ["id"]), + ...extraProperties(value, ["id", "type"]), id: ProductIdSerializer.serialize(value.id), + type: value.type ?? "EXISTING", }; }, }; diff --git a/src/models/externalPaymentMethodConfig.ts b/src/models/externalPaymentMethodConfig.ts index 383aee0..566cec1 100644 --- a/src/models/externalPaymentMethodConfig.ts +++ b/src/models/externalPaymentMethodConfig.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; -export interface ExternalPaymentMethodConfig {} +export interface ExternalPaymentMethodConfig { + type: "external"; +} /** Converts `ExternalPaymentMethodConfig` values from (`parse`) and to (`serialize`) their JSON form. */ export const ExternalPaymentMethodConfigSerializer = { parse(json: any, path = "$"): ExternalPaymentMethodConfig { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "external") + : "external", }; }, serialize(value: ExternalPaymentMethodConfig): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "external", }; }, }; diff --git a/src/models/extraRecurringFeeStructure.ts b/src/models/extraRecurringFeeStructure.ts index 2fb2da4..921b3ad 100644 --- a/src/models/extraRecurringFeeStructure.ts +++ b/src/models/extraRecurringFeeStructure.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type ExtraRecurringBillingTypeEnum, ExtraRecurringBillingTypeEnumSerializer, @@ -8,6 +8,7 @@ import { export interface ExtraRecurringFeeStructure { billingType: ExtraRecurringBillingTypeEnum; + type: "EXTRA_RECURRING"; } /** Converts `ExtraRecurringFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -15,18 +16,23 @@ export const ExtraRecurringFeeStructureSerializer = { parse(json: any, path = "$"): ExtraRecurringFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, ["billing_type"]), + ...extraProperties(json, ["billing_type", "type"]), billingType: ExtraRecurringBillingTypeEnumSerializer.parse( json["billing_type"], decodePath(path, "billing_type") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "EXTRA_RECURRING") + : "EXTRA_RECURRING", }; }, serialize(value: ExtraRecurringFeeStructure): any { return { - ...extraProperties(value, ["billingType"]), + ...extraProperties(value, ["billingType", "type"]), billing_type: ExtraRecurringBillingTypeEnumSerializer.serialize(value.billingType), + type: value.type ?? "EXTRA_RECURRING", }; }, }; diff --git a/src/models/extraRecurringPlanFee.ts b/src/models/extraRecurringPlanFee.ts index 779797e..84e590b 100644 --- a/src/models/extraRecurringPlanFee.ts +++ b/src/models/extraRecurringPlanFee.ts @@ -11,6 +11,7 @@ export interface ExtraRecurringPlanFee { billingType: BillingType; cadence: BillingPeriodEnum; quantity: number; + type: "EXTRA_RECURRING"; unitPrice: string; } @@ -19,7 +20,13 @@ export const ExtraRecurringPlanFeeSerializer = { parse(json: any, path = "$"): ExtraRecurringPlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["billing_type", "cadence", "quantity", "unit_price"]), + ...extraProperties(json, [ + "billing_type", + "cadence", + "quantity", + "type", + "unit_price", + ]), billingType: BillingTypeSerializer.parse( json["billing_type"], decodePath(path, "billing_type") @@ -29,16 +36,27 @@ export const ExtraRecurringPlanFeeSerializer = { decodePath(path, "cadence") ), quantity: decodeInteger(json["quantity"], path, "quantity"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "EXTRA_RECURRING") + : "EXTRA_RECURRING", unitPrice: decodeString(json["unit_price"], path, "unit_price"), }; }, serialize(value: ExtraRecurringPlanFee): any { return { - ...extraProperties(value, ["billingType", "cadence", "quantity", "unitPrice"]), + ...extraProperties(value, [ + "billingType", + "cadence", + "quantity", + "type", + "unitPrice", + ]), billing_type: BillingTypeSerializer.serialize(value.billingType), cadence: BillingPeriodEnumSerializer.serialize(value.cadence), quantity: value.quantity, + type: value.type ?? "EXTRA_RECURRING", unit_price: value.unitPrice, }; }, diff --git a/src/models/extraRecurringPricing.ts b/src/models/extraRecurringPricing.ts index 830bb65..4e734d5 100644 --- a/src/models/extraRecurringPricing.ts +++ b/src/models/extraRecurringPricing.ts @@ -4,6 +4,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface ExtraRecurringPricing { quantity: number; + type: "EXTRA_RECURRING"; unitPrice: string; } @@ -12,16 +13,21 @@ export const ExtraRecurringPricingSerializer = { parse(json: any, path = "$"): ExtraRecurringPricing { decodeObject(json, path); return { - ...extraProperties(json, ["quantity", "unit_price"]), + ...extraProperties(json, ["quantity", "type", "unit_price"]), quantity: decodeInteger(json["quantity"], path, "quantity"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "EXTRA_RECURRING") + : "EXTRA_RECURRING", unitPrice: decodeString(json["unit_price"], path, "unit_price"), }; }, serialize(value: ExtraRecurringPricing): any { return { - ...extraProperties(value, ["quantity", "unitPrice"]), + ...extraProperties(value, ["quantity", "type", "unitPrice"]), quantity: value.quantity, + type: value.type ?? "EXTRA_RECURRING", unit_price: value.unitPrice, }; }, diff --git a/src/models/fee.ts b/src/models/fee.ts index 0c0549c..daea76f 100644 --- a/src/models/fee.ts +++ b/src/models/fee.ts @@ -1,6 +1,7 @@ // this file is @generated import { decodeObject } from "../decode.js"; import { type CapacityPlanFee, CapacityPlanFeeSerializer } from "./capacityPlanFee.js"; +import { type CreditPlanFee, CreditPlanFeeSerializer } from "./creditPlanFee.js"; import { type ExtraRecurringPlanFee, ExtraRecurringPlanFeeSerializer, @@ -28,6 +29,9 @@ export interface FeeExtraRecurring extends ExtraRecurringPlanFee { export interface FeeOneTime extends OneTimePlanFee { type: "ONE_TIME"; } +export interface FeeCredit extends CreditPlanFee { + type: "CREDIT"; +} export type Fee = | FeeRate @@ -35,7 +39,8 @@ export type Fee = | FeeCapacity | FeeUsage | FeeExtraRecurring - | FeeOneTime; + | FeeOneTime + | FeeCredit; /** Converts `Fee` values from (`parse`) and to (`serialize`) their JSON form. */ export const FeeSerializer = { @@ -72,6 +77,11 @@ export const FeeSerializer = { ...OneTimePlanFeeSerializer.parse(json, path), type: "ONE_TIME", }; + case "CREDIT": + return { + ...CreditPlanFeeSerializer.parse(json, path), + type: "CREDIT", + }; default: // A variant added to the API after this SDK was generated, kept as received. return json; @@ -110,6 +120,11 @@ export const FeeSerializer = { ...OneTimePlanFeeSerializer.serialize(value), type: "ONE_TIME", }; + case "CREDIT": + return { + ...CreditPlanFeeSerializer.serialize(value), + type: "CREDIT", + }; default: return value; } diff --git a/src/models/feeCreditUnit.ts b/src/models/feeCreditUnit.ts new file mode 100644 index 0000000..e04e1b5 --- /dev/null +++ b/src/models/feeCreditUnit.ts @@ -0,0 +1,47 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; +/** + * The credit unit a usage fee's amounts are expressed in, with its value in the subscription + * currency. + */ +export interface FeeCreditUnit { + /** The credit unit's code, e.g. `CREDITS`. */ + code: string; + /** The credit unit's id (`cun_…`). */ + creditUnitId: string; + /** + * Decimal places of the unit: credit balances and ledger amounts in it are integers of + * 10^-precision credit. + */ + precision: number; + /** + * Subscription-currency major units per credit: the money billed, before tax, for each + * credit the customer's balance in the unit does not cover. + */ + rate: string; +} + +/** Converts `FeeCreditUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const FeeCreditUnitSerializer = { + parse(json: any, path = "$"): FeeCreditUnit { + decodeObject(json, path); + return { + ...extraProperties(json, ["code", "credit_unit_id", "precision", "rate"]), + code: decodeString(json["code"], path, "code"), + creditUnitId: decodeString(json["credit_unit_id"], path, "credit_unit_id"), + precision: decodeInteger(json["precision"], path, "precision"), + rate: decodeString(json["rate"], path, "rate"), + }; + }, + + serialize(value: FeeCreditUnit): any { + return { + ...extraProperties(value, ["code", "creditUnitId", "precision", "rate"]), + code: value.code, + credit_unit_id: value.creditUnitId, + precision: value.precision, + rate: value.rate, + }; + }, +}; diff --git a/src/models/fixedDiscount.ts b/src/models/fixedDiscount.ts index 57291db..5b5f45d 100644 --- a/src/models/fixedDiscount.ts +++ b/src/models/fixedDiscount.ts @@ -5,6 +5,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface FixedDiscount { amount: string; currency: string; + type: "FIXED"; } /** Converts `FixedDiscount` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const FixedDiscountSerializer = { parse(json: any, path = "$"): FixedDiscount { decodeObject(json, path); return { - ...extraProperties(json, ["amount", "currency"]), + ...extraProperties(json, ["amount", "currency", "type"]), amount: decodeString(json["amount"], path, "amount"), currency: decodeString(json["currency"], path, "currency"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "FIXED") + : "FIXED", }; }, serialize(value: FixedDiscount): any { return { - ...extraProperties(value, ["amount", "currency"]), + ...extraProperties(value, ["amount", "currency", "type"]), amount: value.amount, currency: value.currency, + type: value.type ?? "FIXED", }; }, }; diff --git a/src/models/fixedWindowResetPeriod.ts b/src/models/fixedWindowResetPeriod.ts index df6b1e1..189610f 100644 --- a/src/models/fixedWindowResetPeriod.ts +++ b/src/models/fixedWindowResetPeriod.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; import { type CalendarUnit, CalendarUnitSerializer } from "./calendarUnit.js"; /** Resets at regular intervals — anchored to your subscription's exact activation time. */ export interface FixedWindowResetPeriod { interval: number; + type: "FIXED_WINDOW"; unit: CalendarUnit; } @@ -13,16 +14,21 @@ export const FixedWindowResetPeriodSerializer = { parse(json: any, path = "$"): FixedWindowResetPeriod { decodeObject(json, path); return { - ...extraProperties(json, ["interval", "unit"]), + ...extraProperties(json, ["interval", "type", "unit"]), interval: decodeInteger(json["interval"], path, "interval"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "FIXED_WINDOW") + : "FIXED_WINDOW", unit: CalendarUnitSerializer.parse(json["unit"], decodePath(path, "unit")), }; }, serialize(value: FixedWindowResetPeriod): any { return { - ...extraProperties(value, ["interval", "unit"]), + ...extraProperties(value, ["interval", "type", "unit"]), interval: value.interval, + type: value.type ?? "FIXED_WINDOW", unit: CalendarUnitSerializer.serialize(value.unit), }; }, diff --git a/src/models/index.ts b/src/models/index.ts index 1072570..9a1e8e7 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,7 @@ // this file is @generated +export type { Actor } from "./actor.js"; +export { ActorSerializer } from "./actor.js"; +export { ActorType, ActorTypeSerializer } from "./actorType.js"; export type { AddOn } from "./addOn.js"; export { AddOnSerializer } from "./addOn.js"; export type { AddOnEvent } from "./addOnEvent.js"; @@ -19,6 +22,24 @@ export type { AppliedCouponDetailed } from "./appliedCouponDetailed.js"; export { AppliedCouponDetailedSerializer } from "./appliedCouponDetailed.js"; export type { AppliedCouponId } from "./appliedCouponId.js"; export { AppliedCouponIdSerializer } from "./appliedCouponId.js"; +export type { AutoTopUp } from "./autoTopUp.js"; +export { AutoTopUpSerializer } from "./autoTopUp.js"; +export type { AutoTopUpCapReachedEvent } from "./autoTopUpCapReachedEvent.js"; +export { AutoTopUpCapReachedEventSerializer } from "./autoTopUpCapReachedEvent.js"; +export type { AutoTopUpCapReachedEventData } from "./autoTopUpCapReachedEventData.js"; +export { AutoTopUpCapReachedEventDataSerializer } from "./autoTopUpCapReachedEventData.js"; +export type { AutoTopUpConsentChangedEvent } from "./autoTopUpConsentChangedEvent.js"; +export { AutoTopUpConsentChangedEventSerializer } from "./autoTopUpConsentChangedEvent.js"; +export type { AutoTopUpConsentChangedEventData } from "./autoTopUpConsentChangedEventData.js"; +export { AutoTopUpConsentChangedEventDataSerializer } from "./autoTopUpConsentChangedEventData.js"; +export type { AutoTopUpEvent } from "./autoTopUpEvent.js"; +export { AutoTopUpEventSerializer } from "./autoTopUpEvent.js"; +export type { AutoTopUpEventData } from "./autoTopUpEventData.js"; +export { AutoTopUpEventDataSerializer } from "./autoTopUpEventData.js"; +export { AutoTopUpMethod, AutoTopUpMethodSerializer } from "./autoTopUpMethod.js"; +export { AutoTopUpStatus, AutoTopUpStatusSerializer } from "./autoTopUpStatus.js"; +export type { AutoTopUpWriteRequest } from "./autoTopUpWriteRequest.js"; +export { AutoTopUpWriteRequestSerializer } from "./autoTopUpWriteRequest.js"; export type { AvailableParameters } from "./availableParameters.js"; export { AvailableParametersSerializer } from "./availableParameters.js"; export type { BankAccountId } from "./bankAccountId.js"; @@ -64,6 +85,14 @@ export type { BooleanFeatureType } from "./booleanFeatureType.js"; export { BooleanFeatureTypeSerializer } from "./booleanFeatureType.js"; export type { BooleanResolvedEntitlementValue } from "./booleanResolvedEntitlementValue.js"; export { BooleanResolvedEntitlementValueSerializer } from "./booleanResolvedEntitlementValue.js"; +export type { Budget } from "./budget.js"; +export { BudgetSerializer } from "./budget.js"; +export { BudgetAuthor, BudgetAuthorSerializer } from "./budgetAuthor.js"; +export { BudgetBehavior, BudgetBehaviorSerializer } from "./budgetBehavior.js"; +export type { BudgetListResponse } from "./budgetListResponse.js"; +export { BudgetListResponseSerializer } from "./budgetListResponse.js"; +export type { BudgetPeriod } from "./budgetPeriod.js"; +export { BudgetPeriodSerializer } from "./budgetPeriod.js"; export type { CalendarResetPeriod } from "./calendarResetPeriod.js"; export { CalendarResetPeriodSerializer } from "./calendarResetPeriod.js"; export { CalendarUnit, CalendarUnitSerializer } from "./calendarUnit.js"; @@ -123,6 +152,7 @@ export type { CountryCode } from "./countryCode.js"; export { CountryCodeSerializer } from "./countryCode.js"; export type { Coupon } from "./coupon.js"; export { CouponSerializer } from "./coupon.js"; +export { CouponCreditScope, CouponCreditScopeSerializer } from "./couponCreditScope.js"; export type { CouponDiscount } from "./couponDiscount.js"; export { CouponDiscountSerializer } from "./couponDiscount.js"; export type { CouponEvent } from "./couponEvent.js"; @@ -138,14 +168,20 @@ export type { CouponListResponse } from "./couponListResponse.js"; export { CouponListResponseSerializer } from "./couponListResponse.js"; export type { CreateAddOnRequest } from "./createAddOnRequest.js"; export { CreateAddOnRequestSerializer } from "./createAddOnRequest.js"; +export type { CreateBudgetRequest } from "./createBudgetRequest.js"; +export { CreateBudgetRequestSerializer } from "./createBudgetRequest.js"; export type { CreateCheckoutSessionRequest } from "./createCheckoutSessionRequest.js"; export { CreateCheckoutSessionRequestSerializer } from "./createCheckoutSessionRequest.js"; export type { CreateCheckoutSessionResponse } from "./createCheckoutSessionResponse.js"; export { CreateCheckoutSessionResponseSerializer } from "./createCheckoutSessionResponse.js"; export type { CreateConnectedAccountRequest } from "./createConnectedAccountRequest.js"; export { CreateConnectedAccountRequestSerializer } from "./createConnectedAccountRequest.js"; +export type { CreateConnectedAccountResponse } from "./createConnectedAccountResponse.js"; +export { CreateConnectedAccountResponseSerializer } from "./createConnectedAccountResponse.js"; export type { CreateCouponRequest } from "./createCouponRequest.js"; export { CreateCouponRequestSerializer } from "./createCouponRequest.js"; +export type { CreateCreditGrantRequest } from "./createCreditGrantRequest.js"; +export { CreateCreditGrantRequestSerializer } from "./createCreditGrantRequest.js"; export type { CreateEntitlementsRequest } from "./createEntitlementsRequest.js"; export { CreateEntitlementsRequestSerializer } from "./createEntitlementsRequest.js"; export type { CreateFeatureRequest } from "./createFeatureRequest.js"; @@ -164,10 +200,52 @@ export type { CreateSubscriptionAddOn } from "./createSubscriptionAddOn.js"; export { CreateSubscriptionAddOnSerializer } from "./createSubscriptionAddOn.js"; export type { CreateSubscriptionComponents } from "./createSubscriptionComponents.js"; export { CreateSubscriptionComponentsSerializer } from "./createSubscriptionComponents.js"; +export type { CreateTopUpRequest } from "./createTopUpRequest.js"; +export { CreateTopUpRequestSerializer } from "./createTopUpRequest.js"; export type { CreateWebhookEndpointRequest } from "./createWebhookEndpointRequest.js"; export { CreateWebhookEndpointRequestSerializer } from "./createWebhookEndpointRequest.js"; export type { CreatedWebhookEndpoint } from "./createdWebhookEndpoint.js"; export { CreatedWebhookEndpointSerializer } from "./createdWebhookEndpoint.js"; +export { CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +export type { CreditCap } from "./creditCap.js"; +export { CreditCapSerializer } from "./creditCap.js"; +export type { CreditCaps } from "./creditCaps.js"; +export { CreditCapsSerializer } from "./creditCaps.js"; +export type { CreditCost } from "./creditCost.js"; +export { CreditCostSerializer } from "./creditCost.js"; +export type { CreditCostRequest } from "./creditCostRequest.js"; +export { CreditCostRequestSerializer } from "./creditCostRequest.js"; +export type { CreditDiscount } from "./creditDiscount.js"; +export { CreditDiscountSerializer } from "./creditDiscount.js"; +export type { CreditExhaustedRule } from "./creditExhaustedRule.js"; +export { CreditExhaustedRuleSerializer } from "./creditExhaustedRule.js"; +export type { CreditExhaustedRuleInvoiceVariant } from "./creditExhaustedRuleInvoiceVariant.js"; +export { CreditExhaustedRuleInvoiceVariantSerializer } from "./creditExhaustedRuleInvoiceVariant.js"; +export type { CreditExhaustedRulePauseVariant } from "./creditExhaustedRulePauseVariant.js"; +export { CreditExhaustedRulePauseVariantSerializer } from "./creditExhaustedRulePauseVariant.js"; +export { CreditExpiryUnit, CreditExpiryUnitSerializer } from "./creditExpiryUnit.js"; +export type { CreditFee } from "./creditFee.js"; +export { CreditFeeSerializer } from "./creditFee.js"; +export type { CreditFeeStructure } from "./creditFeeStructure.js"; +export { CreditFeeStructureSerializer } from "./creditFeeStructure.js"; +export type { CreditGrant } from "./creditGrant.js"; +export { CreditGrantSerializer } from "./creditGrant.js"; +export type { CreditGrantExpiredEvent } from "./creditGrantExpiredEvent.js"; +export { CreditGrantExpiredEventSerializer } from "./creditGrantExpiredEvent.js"; +export type { CreditGrantExpiredEventData } from "./creditGrantExpiredEventData.js"; +export { CreditGrantExpiredEventDataSerializer } from "./creditGrantExpiredEventData.js"; +export type { CreditGrantId } from "./creditGrantId.js"; +export { CreditGrantIdSerializer } from "./creditGrantId.js"; +export { CreditGrantKind, CreditGrantKindSerializer } from "./creditGrantKind.js"; +export { + CreditGrantLapseReason, + CreditGrantLapseReasonSerializer, +} from "./creditGrantLapseReason.js"; +export type { CreditGrantListResponse } from "./creditGrantListResponse.js"; +export { CreditGrantListResponseSerializer } from "./creditGrantListResponse.js"; +export { CreditGrantSource, CreditGrantSourceSerializer } from "./creditGrantSource.js"; +export { CreditGrantStatus, CreditGrantStatusSerializer } from "./creditGrantStatus.js"; +export { CreditGrantType, CreditGrantTypeSerializer } from "./creditGrantType.js"; export type { CreditNote } from "./creditNote.js"; export { CreditNoteSerializer } from "./creditNote.js"; export type { CreditNoteCustomPropertiesRequest } from "./creditNoteCustomPropertiesRequest.js"; @@ -181,7 +259,29 @@ export { CreditNoteIdSerializer } from "./creditNoteId.js"; export type { CreditNoteListResponse } from "./creditNoteListResponse.js"; export { CreditNoteListResponseSerializer } from "./creditNoteListResponse.js"; export { CreditNoteStatus, CreditNoteStatusSerializer } from "./creditNoteStatus.js"; +export type { CreditPackExpiry } from "./creditPackExpiry.js"; +export { CreditPackExpirySerializer } from "./creditPackExpiry.js"; +export type { CreditPackRollover } from "./creditPackRollover.js"; +export { CreditPackRolloverSerializer } from "./creditPackRollover.js"; +export type { CreditPackUnit } from "./creditPackUnit.js"; +export { CreditPackUnitSerializer } from "./creditPackUnit.js"; +export type { CreditPlanFee } from "./creditPlanFee.js"; +export { CreditPlanFeeSerializer } from "./creditPlanFee.js"; export { CreditType, CreditTypeSerializer } from "./creditType.js"; +export type { CreditUnit } from "./creditUnit.js"; +export { CreditUnitSerializer } from "./creditUnit.js"; +export type { CreditUnitCreateRequest } from "./creditUnitCreateRequest.js"; +export { CreditUnitCreateRequestSerializer } from "./creditUnitCreateRequest.js"; +export type { CreditUnitListResponse } from "./creditUnitListResponse.js"; +export { CreditUnitListResponseSerializer } from "./creditUnitListResponse.js"; +export type { CreditUnitPrice } from "./creditUnitPrice.js"; +export { CreditUnitPriceSerializer } from "./creditUnitPrice.js"; +export type { CreditUnitPriceListResponse } from "./creditUnitPriceListResponse.js"; +export { CreditUnitPriceListResponseSerializer } from "./creditUnitPriceListResponse.js"; +export type { CreditUnitPriceSetRequest } from "./creditUnitPriceSetRequest.js"; +export { CreditUnitPriceSetRequestSerializer } from "./creditUnitPriceSetRequest.js"; +export type { CreditUnitUpdateRequest } from "./creditUnitUpdateRequest.js"; +export { CreditUnitUpdateRequestSerializer } from "./creditUnitUpdateRequest.js"; export { Currency, CurrencySerializer } from "./currency.js"; export type { CustomPropertyDefinition } from "./customPropertyDefinition.js"; export { CustomPropertyDefinitionSerializer } from "./customPropertyDefinition.js"; @@ -246,10 +346,30 @@ export type { EffectiveEntitlementValue } from "./effectiveEntitlementValue.js"; export { EffectiveEntitlementValueSerializer } from "./effectiveEntitlementValue.js"; export type { Entitlement } from "./entitlement.js"; export { EntitlementSerializer } from "./entitlement.js"; +export type { EntitlementCheck } from "./entitlementCheck.js"; +export { EntitlementCheckSerializer } from "./entitlementCheck.js"; +export type { EntitlementCheckFeature } from "./entitlementCheckFeature.js"; +export { EntitlementCheckFeatureSerializer } from "./entitlementCheckFeature.js"; +export type { EntitlementCheckLimit } from "./entitlementCheckLimit.js"; +export { EntitlementCheckLimitSerializer } from "./entitlementCheckLimit.js"; +export { + EntitlementCheckLimitBehavior, + EntitlementCheckLimitBehaviorSerializer, +} from "./entitlementCheckLimitBehavior.js"; +export type { EntitlementCheckPeriod } from "./entitlementCheckPeriod.js"; +export { EntitlementCheckPeriodSerializer } from "./entitlementCheckPeriod.js"; +export { + EntitlementCheckReason, + EntitlementCheckReasonSerializer, +} from "./entitlementCheckReason.js"; export type { EntitlementId } from "./entitlementId.js"; export { EntitlementIdSerializer } from "./entitlementId.js"; export type { EntitlementListResponse } from "./entitlementListResponse.js"; export { EntitlementListResponseSerializer } from "./entitlementListResponse.js"; +export { + EntitlementOverageBehavior, + EntitlementOverageBehaviorSerializer, +} from "./entitlementOverageBehavior.js"; export type { EntitlementProductRef } from "./entitlementProductRef.js"; export { EntitlementProductRefSerializer } from "./entitlementProductRef.js"; export type { EntitlementSpecRequest } from "./entitlementSpecRequest.js"; @@ -293,6 +413,8 @@ export type { FeatureType } from "./featureType.js"; export { FeatureTypeSerializer } from "./featureType.js"; export type { Fee } from "./fee.js"; export { FeeSerializer } from "./fee.js"; +export type { FeeCreditUnit } from "./feeCreditUnit.js"; +export { FeeCreditUnitSerializer } from "./feeCreditUnit.js"; export type { FixedDiscount } from "./fixedDiscount.js"; export { FixedDiscountSerializer } from "./fixedDiscount.js"; export type { FixedWindowResetPeriod } from "./fixedWindowResetPeriod.js"; @@ -323,6 +445,8 @@ export type { InvoiceEventData } from "./invoiceEventData.js"; export { InvoiceEventDataSerializer } from "./invoiceEventData.js"; export type { InvoiceId } from "./invoiceId.js"; export { InvoiceIdSerializer } from "./invoiceId.js"; +export type { InvoiceLineCreditUnit } from "./invoiceLineCreditUnit.js"; +export { InvoiceLineCreditUnitSerializer } from "./invoiceLineCreditUnit.js"; export type { InvoiceLineItem } from "./invoiceLineItem.js"; export { InvoiceLineItemSerializer } from "./invoiceLineItem.js"; export type { InvoiceListResponse } from "./invoiceListResponse.js"; @@ -337,10 +461,25 @@ export type { InvoicingEntityId } from "./invoicingEntityId.js"; export { InvoicingEntityIdSerializer } from "./invoicingEntityId.js"; export type { JsonConfigValue } from "./jsonConfigValue.js"; export { JsonConfigValueSerializer } from "./jsonConfigValue.js"; +export type { LedgerEntry } from "./ledgerEntry.js"; +export { LedgerEntrySerializer } from "./ledgerEntry.js"; +export type { LedgerEntryId } from "./ledgerEntryId.js"; +export { LedgerEntryIdSerializer } from "./ledgerEntryId.js"; +export { LedgerEntryType, LedgerEntryTypeSerializer } from "./ledgerEntryType.js"; +export type { LedgerListResponse } from "./ledgerListResponse.js"; +export { LedgerListResponseSerializer } from "./ledgerListResponse.js"; export type { LinkedSegmentationMatrix } from "./linkedSegmentationMatrix.js"; export { LinkedSegmentationMatrixSerializer } from "./linkedSegmentationMatrix.js"; export type { ListCheckoutSessionsResponse } from "./listCheckoutSessionsResponse.js"; export { ListCheckoutSessionsResponseSerializer } from "./listCheckoutSessionsResponse.js"; +export { + ListCustomerUsageCostsGranularity, + ListCustomerUsageCostsGranularitySerializer, +} from "./listCustomerUsageCostsGranularity.js"; +export { + ListSubscriptionUsageCostsGranularity, + ListSubscriptionUsageCostsGranularitySerializer, +} from "./listSubscriptionUsageCostsGranularity.js"; export type { MatrixDimension } from "./matrixDimension.js"; export { MatrixDimensionSerializer } from "./matrixDimension.js"; export type { MatrixPlanPricing } from "./matrixPlanPricing.js"; @@ -433,8 +572,12 @@ export type { PackagePricing } from "./packagePricing.js"; export { PackagePricingSerializer } from "./packagePricing.js"; export type { PaginationResponse } from "./paginationResponse.js"; export { PaginationResponseSerializer } from "./paginationResponse.js"; +export type { PatchBudgetRequest } from "./patchBudgetRequest.js"; +export { PatchBudgetRequestSerializer } from "./patchBudgetRequest.js"; export type { PatchPlanRequest } from "./patchPlanRequest.js"; export { PatchPlanRequestSerializer } from "./patchPlanRequest.js"; +export type { PatchWalletRequest } from "./patchWalletRequest.js"; +export { PatchWalletRequestSerializer } from "./patchWalletRequest.js"; export type { PaymentEvent } from "./paymentEvent.js"; export { PaymentEventSerializer } from "./paymentEvent.js"; export type { PaymentMethodInfo } from "./paymentMethodInfo.js"; @@ -463,6 +606,8 @@ export type { PlanEvent } from "./planEvent.js"; export { PlanEventSerializer } from "./planEvent.js"; export type { PlanEventData } from "./planEventData.js"; export { PlanEventDataSerializer } from "./planEventData.js"; +export type { PlanFeeCreditUnit } from "./planFeeCreditUnit.js"; +export { PlanFeeCreditUnitSerializer } from "./planFeeCreditUnit.js"; export type { PlanId } from "./planId.js"; export { PlanIdSerializer } from "./planId.js"; export type { PlanListResponse } from "./planListResponse.js"; @@ -603,6 +748,8 @@ export type { SubscriptionCoupon } from "./subscriptionCoupon.js"; export { SubscriptionCouponSerializer } from "./subscriptionCoupon.js"; export type { SubscriptionCreateRequest } from "./subscriptionCreateRequest.js"; export { SubscriptionCreateRequestSerializer } from "./subscriptionCreateRequest.js"; +export type { SubscriptionCredit } from "./subscriptionCredit.js"; +export { SubscriptionCreditSerializer } from "./subscriptionCredit.js"; export type { SubscriptionDetails } from "./subscriptionDetails.js"; export { SubscriptionDetailsSerializer } from "./subscriptionDetails.js"; export type { SubscriptionEvent } from "./subscriptionEvent.js"; @@ -652,10 +799,18 @@ export type { TokenRequest } from "./tokenRequest.js"; export { TokenRequestSerializer } from "./tokenRequest.js"; export type { TokenResponse } from "./tokenResponse.js"; export { TokenResponseSerializer } from "./tokenResponse.js"; +export { TopUpCollection, TopUpCollectionSerializer } from "./topUpCollection.js"; +export type { TopUpResponse } from "./topUpResponse.js"; +export { TopUpResponseSerializer } from "./topUpResponse.js"; +export { TopUpStatus, TopUpStatusSerializer } from "./topUpStatus.js"; export type { Transaction } from "./transaction.js"; export { TransactionSerializer } from "./transaction.js"; export type { TrialConfig } from "./trialConfig.js"; export { TrialConfigSerializer } from "./trialConfig.js"; +export type { UnattributedMetricUsage } from "./unattributedMetricUsage.js"; +export { UnattributedMetricUsageSerializer } from "./unattributedMetricUsage.js"; +export type { UnattributedUsageResponse } from "./unattributedUsageResponse.js"; +export { UnattributedUsageResponseSerializer } from "./unattributedUsageResponse.js"; export type { UnitConversion } from "./unitConversion.js"; export { UnitConversionSerializer } from "./unitConversion.js"; export { @@ -676,10 +831,26 @@ export type { UpdateProductRequest } from "./updateProductRequest.js"; export { UpdateProductRequestSerializer } from "./updateProductRequest.js"; export type { UpdateWebhookEndpointRequest } from "./updateWebhookEndpointRequest.js"; export { UpdateWebhookEndpointRequestSerializer } from "./updateWebhookEndpointRequest.js"; +export { UsageAtZero, UsageAtZeroSerializer } from "./usageAtZero.js"; +export type { UsageCost } from "./usageCost.js"; +export { UsageCostSerializer } from "./usageCost.js"; +export type { UsageCostListResponse } from "./usageCostListResponse.js"; +export { UsageCostListResponseSerializer } from "./usageCostListResponse.js"; +export type { UsageCostRow } from "./usageCostRow.js"; +export { UsageCostRowSerializer } from "./usageCostRow.js"; +export { UsageCostUnit, UsageCostUnitSerializer } from "./usageCostUnit.js"; +export type { UsageEvent } from "./usageEvent.js"; +export { UsageEventSerializer } from "./usageEvent.js"; +export type { UsageEventListResponse } from "./usageEventListResponse.js"; +export { UsageEventListResponseSerializer } from "./usageEventListResponse.js"; export type { UsageFee } from "./usageFee.js"; export { UsageFeeSerializer } from "./usageFee.js"; export type { UsageFeeStructure } from "./usageFeeStructure.js"; export { UsageFeeStructureSerializer } from "./usageFeeStructure.js"; +export type { UsageFilter } from "./usageFilter.js"; +export { UsageFilterSerializer } from "./usageFilter.js"; +export type { UsageLimitId } from "./usageLimitId.js"; +export { UsageLimitIdSerializer } from "./usageLimitId.js"; export { UsageModelEnum, UsageModelEnumSerializer } from "./usageModelEnum.js"; export type { UsagePlanFee } from "./usagePlanFee.js"; export { UsagePlanFeeSerializer } from "./usagePlanFee.js"; @@ -693,6 +864,40 @@ export type { VolumePlanPricing } from "./volumePlanPricing.js"; export { VolumePlanPricingSerializer } from "./volumePlanPricing.js"; export type { VolumePricing } from "./volumePricing.js"; export { VolumePricingSerializer } from "./volumePricing.js"; +export type { Wallet } from "./wallet.js"; +export { WalletSerializer } from "./wallet.js"; +export type { WalletBalanceLowEvent } from "./walletBalanceLowEvent.js"; +export { WalletBalanceLowEventSerializer } from "./walletBalanceLowEvent.js"; +export type { WalletBalanceLowEventData } from "./walletBalanceLowEventData.js"; +export { WalletBalanceLowEventDataSerializer } from "./walletBalanceLowEventData.js"; +export type { WalletCheck } from "./walletCheck.js"; +export { WalletCheckSerializer } from "./walletCheck.js"; +export type { WalletCreditRecoveredEvent } from "./walletCreditRecoveredEvent.js"; +export { WalletCreditRecoveredEventSerializer } from "./walletCreditRecoveredEvent.js"; +export type { WalletCreditRecoveredEventData } from "./walletCreditRecoveredEventData.js"; +export { WalletCreditRecoveredEventDataSerializer } from "./walletCreditRecoveredEventData.js"; +export type { WalletCreditUnrecoveredEvent } from "./walletCreditUnrecoveredEvent.js"; +export { WalletCreditUnrecoveredEventSerializer } from "./walletCreditUnrecoveredEvent.js"; +export type { WalletCreditUnrecoveredEventData } from "./walletCreditUnrecoveredEventData.js"; +export { WalletCreditUnrecoveredEventDataSerializer } from "./walletCreditUnrecoveredEventData.js"; +export type { WalletDebitedEvent } from "./walletDebitedEvent.js"; +export { WalletDebitedEventSerializer } from "./walletDebitedEvent.js"; +export type { WalletDebitedEventData } from "./walletDebitedEventData.js"; +export { WalletDebitedEventDataSerializer } from "./walletDebitedEventData.js"; +export type { WalletDepletedEvent } from "./walletDepletedEvent.js"; +export { WalletDepletedEventSerializer } from "./walletDepletedEvent.js"; +export type { WalletDepletedEventData } from "./walletDepletedEventData.js"; +export { WalletDepletedEventDataSerializer } from "./walletDepletedEventData.js"; +export type { WalletFundedEvent } from "./walletFundedEvent.js"; +export { WalletFundedEventSerializer } from "./walletFundedEvent.js"; +export type { WalletFundedEventData } from "./walletFundedEventData.js"; +export { WalletFundedEventDataSerializer } from "./walletFundedEventData.js"; +export type { WalletListResponse } from "./walletListResponse.js"; +export { WalletListResponseSerializer } from "./walletListResponse.js"; +export type { WalletRecoveredEvent } from "./walletRecoveredEvent.js"; +export { WalletRecoveredEventSerializer } from "./walletRecoveredEvent.js"; +export type { WalletRecoveredEventData } from "./walletRecoveredEventData.js"; +export { WalletRecoveredEventDataSerializer } from "./walletRecoveredEventData.js"; export type { WebhookDelivery } from "./webhookDelivery.js"; export { WebhookDeliverySerializer } from "./webhookDelivery.js"; export type { WebhookDeliveryId } from "./webhookDeliveryId.js"; diff --git a/src/models/invoice.ts b/src/models/invoice.ts index f400cd4..e385972 100644 --- a/src/models/invoice.ts +++ b/src/models/invoice.ts @@ -28,6 +28,10 @@ import { type Transaction, TransactionSerializer } from "./transaction.js"; export interface Invoice { amountDue: number; + /** + * Paid credit applied after tax, in minor units of the invoice currency: it settles part of + * `total` like a payment, and `amount_due` is net of it. + */ appliedCredits: number; /** * The period/moment this invoice is about — the subscription period start, or the invoice's @@ -56,9 +60,26 @@ export interface Invoice { netTerms: number; paidAt?: Date | null | undefined; parentInvoiceId?: InvoiceId | null | undefined; + /** + * When a dispute or chargeback first took money still lost on this invoice's payments. The + * invoice stays paid; absent when nothing is disputed. + */ + paymentDisputedAt?: Date | null | undefined; paymentStatus: InvoicePaymentStatus; + /** + * Promotional credit applied before tax (credit included with the plan, coupon credit, bonus + * credit), in minor units of the invoice currency. Like a discount, it reduces the taxable + * amount: `tax_amount` and `total` already exclude it, `subtotal` does not. Unlike + * `applied_credits`, which settles part of the `total` after tax. + */ + promotionalCredits?: number | undefined; purchaseOrder?: string | null | undefined; reference?: string | null | undefined; + /** + * True when the invoice is `PAID` without any payment: finalized credit notes cancelled its + * whole total. Nothing was collected, so it books no cash. + */ + settledByCreditNotes: boolean; status: InvoiceStatus; subscriptionId?: SubscriptionId | null | undefined; subtotal: number; @@ -105,9 +126,12 @@ export const InvoiceSerializer = { "net_terms", "paid_at", "parent_invoice_id", + "payment_disputed_at", "payment_status", + "promotional_credits", "purchase_order", "reference", + "settled_by_credit_notes", "status", "subscription_id", "subtotal", @@ -202,10 +226,18 @@ export const InvoiceSerializer = { decodePath(path, "parent_invoice_id") ) : json["parent_invoice_id"], + paymentDisputedAt: + json["payment_disputed_at"] != null + ? decodeDateTime(json["payment_disputed_at"], path, "payment_disputed_at") + : json["payment_disputed_at"], paymentStatus: InvoicePaymentStatusSerializer.parse( json["payment_status"], decodePath(path, "payment_status") ), + promotionalCredits: + json["promotional_credits"] != null + ? decodeInteger(json["promotional_credits"], path, "promotional_credits") + : undefined, purchaseOrder: json["purchase_order"] != null ? decodeString(json["purchase_order"], path, "purchase_order") @@ -214,6 +246,11 @@ export const InvoiceSerializer = { json["reference"] != null ? decodeString(json["reference"], path, "reference") : json["reference"], + settledByCreditNotes: decodeBoolean( + json["settled_by_credit_notes"], + path, + "settled_by_credit_notes" + ), status: InvoiceStatusSerializer.parse(json["status"], decodePath(path, "status")), subscriptionId: json["subscription_id"] != null @@ -282,9 +319,12 @@ export const InvoiceSerializer = { "netTerms", "paidAt", "parentInvoiceId", + "paymentDisputedAt", "paymentStatus", + "promotionalCredits", "purchaseOrder", "reference", + "settledByCreditNotes", "status", "subscriptionId", "subtotal", @@ -331,9 +371,12 @@ export const InvoiceSerializer = { value.parentInvoiceId != null ? InvoiceIdSerializer.serialize(value.parentInvoiceId) : value.parentInvoiceId, + payment_disputed_at: value.paymentDisputedAt, payment_status: InvoicePaymentStatusSerializer.serialize(value.paymentStatus), + promotional_credits: value.promotionalCredits, purchase_order: value.purchaseOrder, reference: value.reference, + settled_by_credit_notes: value.settledByCreditNotes, status: InvoiceStatusSerializer.serialize(value.status), subscription_id: value.subscriptionId != null diff --git a/src/models/invoiceEvent.ts b/src/models/invoiceEvent.ts index 4788db8..4120850 100644 --- a/src/models/invoiceEvent.ts +++ b/src/models/invoiceEvent.ts @@ -28,6 +28,7 @@ export const InvoiceEventSerializer = { "invoice_id", "invoice_number", "parent_invoice_id", + "settled_by_credit_notes", "status", "tax_amount", "total", @@ -41,6 +42,7 @@ export const InvoiceEventSerializer = { "invoiceId", "invoiceNumber", "parentInvoiceId", + "settledByCreditNotes", "status", "taxAmount", "total", @@ -65,6 +67,7 @@ export const InvoiceEventSerializer = { "invoiceId", "invoiceNumber", "parentInvoiceId", + "settledByCreditNotes", "status", "taxAmount", "total", @@ -78,6 +81,7 @@ export const InvoiceEventSerializer = { "invoice_id", "invoice_number", "parent_invoice_id", + "settled_by_credit_notes", "status", "tax_amount", "total", diff --git a/src/models/invoiceEventData.ts b/src/models/invoiceEventData.ts index 8828586..a20bc2f 100644 --- a/src/models/invoiceEventData.ts +++ b/src/models/invoiceEventData.ts @@ -1,6 +1,7 @@ // this file is @generated import { extraProperties } from "../json.js"; import { + decodeBoolean, decodeDateTime, decodeInteger, decodeObject, @@ -22,6 +23,11 @@ export interface InvoiceEventData { /** Absent while the invoice is a draft — the number is assigned at finalization. */ invoiceNumber?: string | null | undefined; parentInvoiceId?: InvoiceId | null | undefined; + /** + * On `invoice.paid`: true when finalized credit notes, not a payment, settled the invoice's + * whole total. Nothing was collected, so it books no cash. False on every other event. + */ + settledByCreditNotes: boolean; status: InvoiceStatus; taxAmount: number; total: number; @@ -41,6 +47,7 @@ export const InvoiceEventDataSerializer = { "invoice_id", "invoice_number", "parent_invoice_id", + "settled_by_credit_notes", "status", "tax_amount", "total", @@ -74,6 +81,11 @@ export const InvoiceEventDataSerializer = { decodePath(path, "parent_invoice_id") ) : json["parent_invoice_id"], + settledByCreditNotes: decodeBoolean( + json["settled_by_credit_notes"], + path, + "settled_by_credit_notes" + ), status: InvoiceStatusSerializer.parse(json["status"], decodePath(path, "status")), taxAmount: decodeInteger(json["tax_amount"], path, "tax_amount"), total: decodeInteger(json["total"], path, "total"), @@ -91,6 +103,7 @@ export const InvoiceEventDataSerializer = { "invoiceId", "invoiceNumber", "parentInvoiceId", + "settledByCreditNotes", "status", "taxAmount", "total", @@ -109,6 +122,7 @@ export const InvoiceEventDataSerializer = { value.parentInvoiceId != null ? InvoiceIdSerializer.serialize(value.parentInvoiceId) : value.parentInvoiceId, + settled_by_credit_notes: value.settledByCreditNotes, status: InvoiceStatusSerializer.serialize(value.status), tax_amount: value.taxAmount, total: value.total, diff --git a/src/models/invoiceLineCreditUnit.ts b/src/models/invoiceLineCreditUnit.ts new file mode 100644 index 0000000..2931981 --- /dev/null +++ b/src/models/invoiceLineCreditUnit.ts @@ -0,0 +1,66 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; +/** + * How a usage line priced in a credit unit was paid: the credits it consumed, those the + * customer's balance in the unit covered, and the rate the rest was billed at. + */ +export interface InvoiceLineCreditUnit { + /** The credit unit's code, e.g. `CREDITS`. */ + code: string; + /** Credits the usage priced. */ + consumed: number; + /** Of which paid by the customer's credit wallet. */ + covered: number; + /** Credit amounts are integers in 10^-precision credit. */ + precision: number; + /** Invoice-currency major units per credit. */ + rate: string; + /** Credits per usage unit. */ + unitPrice?: string | null | undefined; +} + +/** Converts `InvoiceLineCreditUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const InvoiceLineCreditUnitSerializer = { + parse(json: any, path = "$"): InvoiceLineCreditUnit { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "code", + "consumed", + "covered", + "precision", + "rate", + "unit_price", + ]), + code: decodeString(json["code"], path, "code"), + consumed: decodeInteger(json["consumed"], path, "consumed"), + covered: decodeInteger(json["covered"], path, "covered"), + precision: decodeInteger(json["precision"], path, "precision"), + rate: decodeString(json["rate"], path, "rate"), + unitPrice: + json["unit_price"] != null + ? decodeString(json["unit_price"], path, "unit_price") + : json["unit_price"], + }; + }, + + serialize(value: InvoiceLineCreditUnit): any { + return { + ...extraProperties(value, [ + "code", + "consumed", + "covered", + "precision", + "rate", + "unitPrice", + ]), + code: value.code, + consumed: value.consumed, + covered: value.covered, + precision: value.precision, + rate: value.rate, + unit_price: value.unitPrice, + }; + }, +}; diff --git a/src/models/invoiceLineItem.ts b/src/models/invoiceLineItem.ts index ae2eeb3..18c9eb2 100644 --- a/src/models/invoiceLineItem.ts +++ b/src/models/invoiceLineItem.ts @@ -7,10 +7,15 @@ import { decodePath, decodeString, } from "../decode.js"; +import { + type InvoiceLineCreditUnit, + InvoiceLineCreditUnitSerializer, +} from "./invoiceLineCreditUnit.js"; import { type SubLineItem, SubLineItemSerializer } from "./subLineItem.js"; export interface InvoiceLineItem { amountTotal: number; + creditUnit?: InvoiceLineCreditUnit | null | undefined; description?: string | null | undefined; endDate: string; name: string; @@ -33,6 +38,7 @@ export const InvoiceLineItemSerializer = { return { ...extraProperties(json, [ "amount_total", + "credit_unit", "description", "end_date", "name", @@ -44,6 +50,13 @@ export const InvoiceLineItemSerializer = { "unit_price", ]), amountTotal: decodeInteger(json["amount_total"], path, "amount_total"), + creditUnit: + json["credit_unit"] != null + ? InvoiceLineCreditUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], description: json["description"] != null ? decodeString(json["description"], path, "description") @@ -78,6 +91,7 @@ export const InvoiceLineItemSerializer = { return { ...extraProperties(value, [ "amountTotal", + "creditUnit", "description", "endDate", "name", @@ -89,6 +103,10 @@ export const InvoiceLineItemSerializer = { "unitPrice", ]), amount_total: value.amountTotal, + credit_unit: + value.creditUnit != null + ? InvoiceLineCreditUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, description: value.description, end_date: value.endDate, name: value.name, diff --git a/src/models/jsonConfigValue.ts b/src/models/jsonConfigValue.ts index 59df13a..f1bf712 100644 --- a/src/models/jsonConfigValue.ts +++ b/src/models/jsonConfigValue.ts @@ -1,8 +1,9 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; /** A structured (JSON) config value — the "metadata" case, several fields in one entitlement. */ export interface JsonConfigValue { + kind: "JSON"; value: unknown; } @@ -11,14 +12,19 @@ export const JsonConfigValueSerializer = { parse(json: any, path = "$"): JsonConfigValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["kind", "value"]), + kind: + json["kind"] != null + ? (decodeString(json["kind"], path, "kind") as "JSON") + : "JSON", value: json["value"], }; }, serialize(value: JsonConfigValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["kind", "value"]), + kind: value.kind ?? "JSON", value: value.value, }; }, diff --git a/src/models/ledgerEntry.ts b/src/models/ledgerEntry.ts new file mode 100644 index 0000000..101711b --- /dev/null +++ b/src/models/ledgerEntry.ts @@ -0,0 +1,177 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { type CreditCost, CreditCostSerializer } from "./creditCost.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { type LedgerEntryType, LedgerEntryTypeSerializer } from "./ledgerEntryType.js"; +/** One movement of a customer's credit. */ +export interface LedgerEntry { + /** Signed change to the credit on account, in minor units. */ + amount: number; + /** What the moved credit's grant pays: ALL any charge, USAGE only usage charges. */ + appliesTo: CreditAppliesTo; + /** The credit on account after this entry, whatever it applies to. */ + balanceAfter: number; + cost?: CreditCost | null | undefined; + /** The grant the credit moved in or out of. */ + creditGrantId: string; + /** The credit note that gave the credit back or took it back. */ + creditNoteId?: string | null | undefined; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + currency?: Currency | null | undefined; + /** When the movement took effect; the ledger is ordered by it. */ + effectiveAt: Date; + /** The entry's id (`wle_…`). */ + id: string; + /** The invoice the credit was applied to, bought on, or given back by. */ + invoiceId?: string | null | undefined; + /** Why the credit moved, as shown on the ledger. */ + reason: string; + /** When the movement was recorded. */ + recordedAt: Date; + /** Your own reference, e.g. a contract or support ticket. */ + reference?: string | null | undefined; + /** + * Position within the currency's ledger in the order the movements took effect, from 1. A + * movement recorded later with an earlier date shifts the positions after it: identify an + * entry by its `id`. + */ + sequence: number; + /** + * The subscription the moved credit's grant belongs to; null when it pays any of the + * customer's subscriptions. + */ + subscriptionId?: string | null | undefined; + /** What moved the credit. */ + type: LedgerEntryType; +} + +/** Converts `LedgerEntry` values from (`parse`) and to (`serialize`) their JSON form. */ +export const LedgerEntrySerializer = { + parse(json: any, path = "$"): LedgerEntry { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "applies_to", + "balance_after", + "cost", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "effective_at", + "id", + "invoice_id", + "reason", + "recorded_at", + "reference", + "sequence", + "subscription_id", + "type", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + appliesTo: CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ), + balanceAfter: decodeInteger(json["balance_after"], path, "balance_after"), + cost: + json["cost"] != null + ? CreditCostSerializer.parse(json["cost"], decodePath(path, "cost")) + : json["cost"], + creditGrantId: decodeString(json["credit_grant_id"], path, "credit_grant_id"), + creditNoteId: + json["credit_note_id"] != null + ? decodeString(json["credit_note_id"], path, "credit_note_id") + : json["credit_note_id"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + effectiveAt: decodeDateTime(json["effective_at"], path, "effective_at"), + id: decodeString(json["id"], path, "id"), + invoiceId: + json["invoice_id"] != null + ? decodeString(json["invoice_id"], path, "invoice_id") + : json["invoice_id"], + reason: decodeString(json["reason"], path, "reason"), + recordedAt: decodeDateTime(json["recorded_at"], path, "recorded_at"), + reference: + json["reference"] != null + ? decodeString(json["reference"], path, "reference") + : json["reference"], + sequence: decodeInteger(json["sequence"], path, "sequence"), + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + type: LedgerEntryTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: LedgerEntry): any { + return { + ...extraProperties(value, [ + "amount", + "appliesTo", + "balanceAfter", + "cost", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "effectiveAt", + "id", + "invoiceId", + "reason", + "recordedAt", + "reference", + "sequence", + "subscriptionId", + "type", + ]), + amount: value.amount, + applies_to: CreditAppliesToSerializer.serialize(value.appliesTo), + balance_after: value.balanceAfter, + cost: value.cost != null ? CreditCostSerializer.serialize(value.cost) : value.cost, + credit_grant_id: value.creditGrantId, + credit_note_id: value.creditNoteId, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + effective_at: value.effectiveAt, + id: value.id, + invoice_id: value.invoiceId, + reason: value.reason, + recorded_at: value.recordedAt, + reference: value.reference, + sequence: value.sequence, + subscription_id: value.subscriptionId, + type: LedgerEntryTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/ledgerEntryId.ts b/src/models/ledgerEntryId.ts new file mode 100644 index 0000000..7a249fa --- /dev/null +++ b/src/models/ledgerEntryId.ts @@ -0,0 +1,15 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export type LedgerEntryId = string; + +/** Converts `LedgerEntryId` values from (`parse`) and to (`serialize`) their JSON form. */ +export const LedgerEntryIdSerializer = { + parse(json: any, path = "$"): LedgerEntryId { + return decodeString(json, path); + }, + + serialize(value: LedgerEntryId): any { + return value; + }, +}; diff --git a/src/models/ledgerEntryType.ts b/src/models/ledgerEntryType.ts new file mode 100644 index 0000000..3435df4 --- /dev/null +++ b/src/models/ledgerEntryType.ts @@ -0,0 +1,26 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const LedgerEntryType = { + Credit: "CREDIT", + InvoiceApplication: "INVOICE_APPLICATION", + InvoiceReturn: "INVOICE_RETURN", + CreditReversal: "CREDIT_REVERSAL", + CreditReinstatement: "CREDIT_REINSTATEMENT", + CreditExpiry: "CREDIT_EXPIRY", + CreditRollover: "CREDIT_ROLLOVER", +} as const; +export type LedgerEntryType = + | (typeof LedgerEntryType)[keyof typeof LedgerEntryType] + | (string & {}); + +/** Converts `LedgerEntryType` values from (`parse`) and to (`serialize`) their JSON form. */ +export const LedgerEntryTypeSerializer = { + parse(json: any, path = "$"): LedgerEntryType { + return decodeString(json, path); + }, + + serialize(value: LedgerEntryType): any { + return value; + }, +}; diff --git a/src/models/ledgerListResponse.ts b/src/models/ledgerListResponse.ts new file mode 100644 index 0000000..b997d01 --- /dev/null +++ b/src/models/ledgerListResponse.ts @@ -0,0 +1,38 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type LedgerEntry, LedgerEntrySerializer } from "./ledgerEntry.js"; +import { + type PaginationResponse, + PaginationResponseSerializer, +} from "./paginationResponse.js"; +/** A page of ledger entries, newest first. */ +export interface LedgerListResponse { + data: LedgerEntry[]; + paginationMeta: PaginationResponse; +} + +/** Converts `LedgerListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const LedgerListResponseSerializer = { + parse(json: any, path = "$"): LedgerListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data", "pagination_meta"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + LedgerEntrySerializer.parse(item, decodePath(p, i)) + ), + paginationMeta: PaginationResponseSerializer.parse( + json["pagination_meta"], + decodePath(path, "pagination_meta") + ), + }; + }, + + serialize(value: LedgerListResponse): any { + return { + ...extraProperties(value, ["data", "paginationMeta"]), + data: value.data.map((item: any) => LedgerEntrySerializer.serialize(item)), + pagination_meta: PaginationResponseSerializer.serialize(value.paginationMeta), + }; + }, +}; diff --git a/src/models/linkedSegmentationMatrix.ts b/src/models/linkedSegmentationMatrix.ts index 6a51e8e..299dc22 100644 --- a/src/models/linkedSegmentationMatrix.ts +++ b/src/models/linkedSegmentationMatrix.ts @@ -5,6 +5,7 @@ import { decodeList, decodeMap, decodeObject, decodeString } from "../decode.js" export interface LinkedSegmentationMatrix { dimension1Key: string; dimension2Key: string; + type: "LINKED"; values: { [key: string]: string[] }; } @@ -13,9 +14,13 @@ export const LinkedSegmentationMatrixSerializer = { parse(json: any, path = "$"): LinkedSegmentationMatrix { decodeObject(json, path); return { - ...extraProperties(json, ["dimension1_key", "dimension2_key", "values"]), + ...extraProperties(json, ["dimension1_key", "dimension2_key", "type", "values"]), dimension1Key: decodeString(json["dimension1_key"], path, "dimension1_key"), dimension2Key: decodeString(json["dimension2_key"], path, "dimension2_key"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "LINKED") + : "LINKED", values: decodeMap( json["values"], path, @@ -30,9 +35,10 @@ export const LinkedSegmentationMatrixSerializer = { serialize(value: LinkedSegmentationMatrix): any { return { - ...extraProperties(value, ["dimension1Key", "dimension2Key", "values"]), + ...extraProperties(value, ["dimension1Key", "dimension2Key", "type", "values"]), dimension1_key: value.dimension1Key, dimension2_key: value.dimension2Key, + type: value.type ?? "LINKED", values: value.values, }; }, diff --git a/src/models/listCustomerUsageCostsGranularity.ts b/src/models/listCustomerUsageCostsGranularity.ts new file mode 100644 index 0000000..1e6ee04 --- /dev/null +++ b/src/models/listCustomerUsageCostsGranularity.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const ListCustomerUsageCostsGranularity = { + Hour: "HOUR", + Day: "DAY", + Month: "MONTH", +} as const; +export type ListCustomerUsageCostsGranularity = + | (typeof ListCustomerUsageCostsGranularity)[keyof typeof ListCustomerUsageCostsGranularity] + | (string & {}); + +/** Converts `ListCustomerUsageCostsGranularity` values from (`parse`) and to (`serialize`) their JSON form. */ +export const ListCustomerUsageCostsGranularitySerializer = { + parse(json: any, path = "$"): ListCustomerUsageCostsGranularity { + return decodeString(json, path); + }, + + serialize(value: ListCustomerUsageCostsGranularity): any { + return value; + }, +}; diff --git a/src/models/listSubscriptionUsageCostsGranularity.ts b/src/models/listSubscriptionUsageCostsGranularity.ts new file mode 100644 index 0000000..b0a5fc5 --- /dev/null +++ b/src/models/listSubscriptionUsageCostsGranularity.ts @@ -0,0 +1,22 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const ListSubscriptionUsageCostsGranularity = { + Hour: "HOUR", + Day: "DAY", + Month: "MONTH", +} as const; +export type ListSubscriptionUsageCostsGranularity = + | (typeof ListSubscriptionUsageCostsGranularity)[keyof typeof ListSubscriptionUsageCostsGranularity] + | (string & {}); + +/** Converts `ListSubscriptionUsageCostsGranularity` values from (`parse`) and to (`serialize`) their JSON form. */ +export const ListSubscriptionUsageCostsGranularitySerializer = { + parse(json: any, path = "$"): ListSubscriptionUsageCostsGranularity { + return decodeString(json, path); + }, + + serialize(value: ListSubscriptionUsageCostsGranularity): any { + return value; + }, +}; diff --git a/src/models/matrixPlanPricing.ts b/src/models/matrixPlanPricing.ts index d955f36..fc0f147 100644 --- a/src/models/matrixPlanPricing.ts +++ b/src/models/matrixPlanPricing.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; import { type MatrixRow, MatrixRowSerializer } from "./matrixRow.js"; export interface MatrixPlanPricing { rates: MatrixRow[]; + type: "MATRIX"; } /** Converts `MatrixPlanPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const MatrixPlanPricingSerializer = { parse(json: any, path = "$"): MatrixPlanPricing { decodeObject(json, path); return { - ...extraProperties(json, ["rates"]), + ...extraProperties(json, ["rates", "type"]), rates: decodeList(json["rates"], path, "rates", (item: any, p: string, i: number) => MatrixRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "MATRIX") + : "MATRIX", }; }, serialize(value: MatrixPlanPricing): any { return { - ...extraProperties(value, ["rates"]), + ...extraProperties(value, ["rates", "type"]), rates: value.rates.map((item: any) => MatrixRowSerializer.serialize(item)), + type: value.type ?? "MATRIX", }; }, }; diff --git a/src/models/matrixPricing.ts b/src/models/matrixPricing.ts index 5eb9baf..01b69d1 100644 --- a/src/models/matrixPricing.ts +++ b/src/models/matrixPricing.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; import { type MatrixRow, MatrixRowSerializer } from "./matrixRow.js"; export interface MatrixPricing { rates: MatrixRow[]; + type: "MATRIX"; } /** Converts `MatrixPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const MatrixPricingSerializer = { parse(json: any, path = "$"): MatrixPricing { decodeObject(json, path); return { - ...extraProperties(json, ["rates"]), + ...extraProperties(json, ["rates", "type"]), rates: decodeList(json["rates"], path, "rates", (item: any, p: string, i: number) => MatrixRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "MATRIX") + : "MATRIX", }; }, serialize(value: MatrixPricing): any { return { - ...extraProperties(value, ["rates"]), + ...extraProperties(value, ["rates", "type"]), rates: value.rates.map((item: any) => MatrixRowSerializer.serialize(item)), + type: value.type ?? "MATRIX", }; }, }; diff --git a/src/models/meteredEffectiveEntitlementValue.ts b/src/models/meteredEffectiveEntitlementValue.ts index fcf378a..2bd2308 100644 --- a/src/models/meteredEffectiveEntitlementValue.ts +++ b/src/models/meteredEffectiveEntitlementValue.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type MeteredEntitlementSpec, MeteredEntitlementSpecSerializer, @@ -12,6 +12,7 @@ import { export interface MeteredEffectiveEntitlementValue { spec: MeteredEntitlementSpec; + type: "METERED"; usage: MeteredEntitlementUsage; } @@ -20,11 +21,15 @@ export const MeteredEffectiveEntitlementValueSerializer = { parse(json: any, path = "$"): MeteredEffectiveEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["spec", "usage"]), + ...extraProperties(json, ["spec", "type", "usage"]), spec: MeteredEntitlementSpecSerializer.parse( json["spec"], decodePath(path, "spec") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "METERED") + : "METERED", usage: MeteredEntitlementUsageSerializer.parse( json["usage"], decodePath(path, "usage") @@ -34,8 +39,9 @@ export const MeteredEffectiveEntitlementValueSerializer = { serialize(value: MeteredEffectiveEntitlementValue): any { return { - ...extraProperties(value, ["spec", "usage"]), + ...extraProperties(value, ["spec", "type", "usage"]), spec: MeteredEntitlementSpecSerializer.serialize(value.spec), + type: value.type ?? "METERED", usage: MeteredEntitlementUsageSerializer.serialize(value.usage), }; }, diff --git a/src/models/meteredEntitlementSpec.ts b/src/models/meteredEntitlementSpec.ts index 6340165..9f87555 100644 --- a/src/models/meteredEntitlementSpec.ts +++ b/src/models/meteredEntitlementSpec.ts @@ -1,14 +1,38 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + decodeBoolean, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; +import { + type EntitlementOverageBehavior, + EntitlementOverageBehaviorSerializer, +} from "./entitlementOverageBehavior.js"; import { type ResetPeriod, ResetPeriodSerializer } from "./resetPeriod.js"; export interface MeteredEntitlementSpec { + /** + * False when switched off, or once a `BLOCK` limit (plus its grace) is reached. An `ALLOW` + * limit never turns it off. + */ enabled: boolean; + /** `BLOCK` only: usage allowed beyond the limit before it is refused, in percent of it. */ + gracePct?: number | null | undefined; + /** Event property the limit applies to separately; usage is then the largest value's. */ + groupBy?: string | null | undefined; limit?: string | null | undefined; metricId: BillableMetricId; + overageBehavior?: EntitlementOverageBehavior | null | undefined; resetPeriod: ResetPeriod; + /** Percents of the limit at which an alert is sent, ascending. */ + thresholds?: number[] | null | undefined; + /** Deprecated: the lowest of `thresholds`. */ + warningThresholdPct?: number | null | undefined; } /** Converts `MeteredEntitlementSpec` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -16,8 +40,26 @@ export const MeteredEntitlementSpecSerializer = { parse(json: any, path = "$"): MeteredEntitlementSpec { decodeObject(json, path); return { - ...extraProperties(json, ["enabled", "limit", "metric_id", "reset_period"]), + ...extraProperties(json, [ + "enabled", + "grace_pct", + "group_by", + "limit", + "metric_id", + "overage_behavior", + "reset_period", + "thresholds", + "warning_threshold_pct", + ]), enabled: decodeBoolean(json["enabled"], path, "enabled"), + gracePct: + json["grace_pct"] != null + ? decodeInteger(json["grace_pct"], path, "grace_pct") + : json["grace_pct"], + groupBy: + json["group_by"] != null + ? decodeString(json["group_by"], path, "group_by") + : json["group_by"], limit: json["limit"] != null ? decodeString(json["limit"], path, "limit") @@ -26,20 +68,58 @@ export const MeteredEntitlementSpecSerializer = { json["metric_id"], decodePath(path, "metric_id") ), + overageBehavior: + json["overage_behavior"] != null + ? EntitlementOverageBehaviorSerializer.parse( + json["overage_behavior"], + decodePath(path, "overage_behavior") + ) + : json["overage_behavior"], resetPeriod: ResetPeriodSerializer.parse( json["reset_period"], decodePath(path, "reset_period") ), + thresholds: + json["thresholds"] != null + ? decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["thresholds"], + warningThresholdPct: + json["warning_threshold_pct"] != null + ? decodeInteger(json["warning_threshold_pct"], path, "warning_threshold_pct") + : json["warning_threshold_pct"], }; }, serialize(value: MeteredEntitlementSpec): any { return { - ...extraProperties(value, ["enabled", "limit", "metricId", "resetPeriod"]), + ...extraProperties(value, [ + "enabled", + "gracePct", + "groupBy", + "limit", + "metricId", + "overageBehavior", + "resetPeriod", + "thresholds", + "warningThresholdPct", + ]), enabled: value.enabled, + grace_pct: value.gracePct, + group_by: value.groupBy, limit: value.limit, metric_id: BillableMetricIdSerializer.serialize(value.metricId), + overage_behavior: + value.overageBehavior != null + ? EntitlementOverageBehaviorSerializer.serialize(value.overageBehavior) + : value.overageBehavior, reset_period: ResetPeriodSerializer.serialize(value.resetPeriod), + thresholds: value.thresholds, + warning_threshold_pct: value.warningThresholdPct, }; }, }; diff --git a/src/models/meteredEntitlementUsage.ts b/src/models/meteredEntitlementUsage.ts index d7e17f0..b9af42d 100644 --- a/src/models/meteredEntitlementUsage.ts +++ b/src/models/meteredEntitlementUsage.ts @@ -1,9 +1,14 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeDateTime, decodeObject, decodeString } from "../decode.js"; +import { decodeBoolean, decodeDateTime, decodeObject, decodeString } from "../decode.js"; export interface MeteredEntitlementUsage { consumed?: string | null | undefined; + /** + * Switched on, but refused: the `BLOCK` limit (plus its grace) is reached, so `enabled` is + * false until the window resets. Never set for a limit grouped by a property. + */ + limitReached?: boolean | null | undefined; remaining?: string | null | undefined; resetAt?: Date | null | undefined; } @@ -13,11 +18,15 @@ export const MeteredEntitlementUsageSerializer = { parse(json: any, path = "$"): MeteredEntitlementUsage { decodeObject(json, path); return { - ...extraProperties(json, ["consumed", "remaining", "reset_at"]), + ...extraProperties(json, ["consumed", "limit_reached", "remaining", "reset_at"]), consumed: json["consumed"] != null ? decodeString(json["consumed"], path, "consumed") : json["consumed"], + limitReached: + json["limit_reached"] != null + ? decodeBoolean(json["limit_reached"], path, "limit_reached") + : json["limit_reached"], remaining: json["remaining"] != null ? decodeString(json["remaining"], path, "remaining") @@ -31,8 +40,9 @@ export const MeteredEntitlementUsageSerializer = { serialize(value: MeteredEntitlementUsage): any { return { - ...extraProperties(value, ["consumed", "remaining", "resetAt"]), + ...extraProperties(value, ["consumed", "limitReached", "remaining", "resetAt"]), consumed: value.consumed, + limit_reached: value.limitReached, remaining: value.remaining, reset_at: value.resetAt, }; diff --git a/src/models/meteredEntitlementValue.ts b/src/models/meteredEntitlementValue.ts index f41b42e..4c6941d 100644 --- a/src/models/meteredEntitlementValue.ts +++ b/src/models/meteredEntitlementValue.ts @@ -1,14 +1,45 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + decodeBoolean, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { + type EntitlementOverageBehavior, + EntitlementOverageBehaviorSerializer, +} from "./entitlementOverageBehavior.js"; import { type ResetPeriod, ResetPeriodSerializer } from "./resetPeriod.js"; export interface MeteredEntitlementValue { /** Per-entitlement kill switch. `false` means disabled. */ enabled?: boolean | undefined; + /** + * `BLOCK` only: usage allowed beyond the limit before it is refused, in percent of the + * limit (1 to 1000). + */ + gracePct?: number | null | undefined; + /** Event property the limit applies to separately, one limit per value (e.g. `user_id`). */ + groupBy?: string | null | undefined; /** Cap on usage. Null means unlimited. */ limit?: string | null | undefined; + overageBehavior?: EntitlementOverageBehavior | null | undefined; resetPeriod?: ResetPeriod | undefined; + /** + * Percents of the limit (1 to 100, at most 10) at which an alert is sent, once per period: + * `entitlement.usage_threshold_reached`, or `entitlement.limit_reached` at 100. Requires a + * limit and a window that is not sliding. + */ + thresholds?: number[] | null | undefined; + type: "METERED"; + /** + * Deprecated: use `thresholds`. A single alert threshold, read only when `thresholds` is + * omitted; returned as the lowest of `thresholds`. + */ + warningThresholdPct?: number | null | undefined; } /** Converts `MeteredEntitlementValue` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -16,15 +47,40 @@ export const MeteredEntitlementValueSerializer = { parse(json: any, path = "$"): MeteredEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["enabled", "limit", "reset_period"]), + ...extraProperties(json, [ + "enabled", + "grace_pct", + "group_by", + "limit", + "overage_behavior", + "reset_period", + "thresholds", + "type", + "warning_threshold_pct", + ]), enabled: json["enabled"] != null ? decodeBoolean(json["enabled"], path, "enabled") : undefined, + gracePct: + json["grace_pct"] != null + ? decodeInteger(json["grace_pct"], path, "grace_pct") + : json["grace_pct"], + groupBy: + json["group_by"] != null + ? decodeString(json["group_by"], path, "group_by") + : json["group_by"], limit: json["limit"] != null ? decodeString(json["limit"], path, "limit") : json["limit"], + overageBehavior: + json["overage_behavior"] != null + ? EntitlementOverageBehaviorSerializer.parse( + json["overage_behavior"], + decodePath(path, "overage_behavior") + ) + : json["overage_behavior"], resetPeriod: json["reset_period"] != null ? ResetPeriodSerializer.parse( @@ -32,18 +88,54 @@ export const MeteredEntitlementValueSerializer = { decodePath(path, "reset_period") ) : undefined, + thresholds: + json["thresholds"] != null + ? decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["thresholds"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "METERED") + : "METERED", + warningThresholdPct: + json["warning_threshold_pct"] != null + ? decodeInteger(json["warning_threshold_pct"], path, "warning_threshold_pct") + : json["warning_threshold_pct"], }; }, serialize(value: MeteredEntitlementValue): any { return { - ...extraProperties(value, ["enabled", "limit", "resetPeriod"]), + ...extraProperties(value, [ + "enabled", + "gracePct", + "groupBy", + "limit", + "overageBehavior", + "resetPeriod", + "thresholds", + "type", + "warningThresholdPct", + ]), enabled: value.enabled, + grace_pct: value.gracePct, + group_by: value.groupBy, limit: value.limit, + overage_behavior: + value.overageBehavior != null + ? EntitlementOverageBehaviorSerializer.serialize(value.overageBehavior) + : value.overageBehavior, reset_period: value.resetPeriod != null ? ResetPeriodSerializer.serialize(value.resetPeriod) : undefined, + thresholds: value.thresholds, + type: value.type ?? "METERED", + warning_threshold_pct: value.warningThresholdPct, }; }, }; diff --git a/src/models/meteredFeatureType.ts b/src/models/meteredFeatureType.ts index ad65eef..a0fb64b 100644 --- a/src/models/meteredFeatureType.ts +++ b/src/models/meteredFeatureType.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; export interface MeteredFeatureType { metricId: BillableMetricId; + type: "METERED"; } /** Converts `MeteredFeatureType` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,18 +13,23 @@ export const MeteredFeatureTypeSerializer = { parse(json: any, path = "$"): MeteredFeatureType { decodeObject(json, path); return { - ...extraProperties(json, ["metric_id"]), + ...extraProperties(json, ["metric_id", "type"]), metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "METERED") + : "METERED", }; }, serialize(value: MeteredFeatureType): any { return { - ...extraProperties(value, ["metricId"]), + ...extraProperties(value, ["metricId", "type"]), metric_id: BillableMetricIdSerializer.serialize(value.metricId), + type: value.type ?? "METERED", }; }, }; diff --git a/src/models/meteredResolvedEntitlementValue.ts b/src/models/meteredResolvedEntitlementValue.ts index 803782a..a03e0fd 100644 --- a/src/models/meteredResolvedEntitlementValue.ts +++ b/src/models/meteredResolvedEntitlementValue.ts @@ -1,14 +1,35 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeBoolean, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + decodeBoolean, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; +import { + type EntitlementOverageBehavior, + EntitlementOverageBehaviorSerializer, +} from "./entitlementOverageBehavior.js"; import { type ResetPeriod, ResetPeriodSerializer } from "./resetPeriod.js"; export interface MeteredResolvedEntitlementValue { enabled: boolean; + /** `BLOCK` only: usage allowed beyond the limit before it is refused, in percent of it. */ + gracePct?: number | null | undefined; + /** Event property the limit applies to separately; usage is then the largest value's. */ + groupBy?: string | null | undefined; limit?: string | null | undefined; metricId: BillableMetricId; + overageBehavior?: EntitlementOverageBehavior | null | undefined; resetPeriod: ResetPeriod; + /** Percents of the limit at which an alert is sent, ascending. */ + thresholds?: number[] | null | undefined; + type: "METERED"; + /** Deprecated: the lowest of `thresholds`. */ + warningThresholdPct?: number | null | undefined; } /** Converts `MeteredResolvedEntitlementValue` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -16,8 +37,27 @@ export const MeteredResolvedEntitlementValueSerializer = { parse(json: any, path = "$"): MeteredResolvedEntitlementValue { decodeObject(json, path); return { - ...extraProperties(json, ["enabled", "limit", "metric_id", "reset_period"]), + ...extraProperties(json, [ + "enabled", + "grace_pct", + "group_by", + "limit", + "metric_id", + "overage_behavior", + "reset_period", + "thresholds", + "type", + "warning_threshold_pct", + ]), enabled: decodeBoolean(json["enabled"], path, "enabled"), + gracePct: + json["grace_pct"] != null + ? decodeInteger(json["grace_pct"], path, "grace_pct") + : json["grace_pct"], + groupBy: + json["group_by"] != null + ? decodeString(json["group_by"], path, "group_by") + : json["group_by"], limit: json["limit"] != null ? decodeString(json["limit"], path, "limit") @@ -26,20 +66,64 @@ export const MeteredResolvedEntitlementValueSerializer = { json["metric_id"], decodePath(path, "metric_id") ), + overageBehavior: + json["overage_behavior"] != null + ? EntitlementOverageBehaviorSerializer.parse( + json["overage_behavior"], + decodePath(path, "overage_behavior") + ) + : json["overage_behavior"], resetPeriod: ResetPeriodSerializer.parse( json["reset_period"], decodePath(path, "reset_period") ), + thresholds: + json["thresholds"] != null + ? decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["thresholds"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "METERED") + : "METERED", + warningThresholdPct: + json["warning_threshold_pct"] != null + ? decodeInteger(json["warning_threshold_pct"], path, "warning_threshold_pct") + : json["warning_threshold_pct"], }; }, serialize(value: MeteredResolvedEntitlementValue): any { return { - ...extraProperties(value, ["enabled", "limit", "metricId", "resetPeriod"]), + ...extraProperties(value, [ + "enabled", + "gracePct", + "groupBy", + "limit", + "metricId", + "overageBehavior", + "resetPeriod", + "thresholds", + "type", + "warningThresholdPct", + ]), enabled: value.enabled, + grace_pct: value.gracePct, + group_by: value.groupBy, limit: value.limit, metric_id: BillableMetricIdSerializer.serialize(value.metricId), + overage_behavior: + value.overageBehavior != null + ? EntitlementOverageBehaviorSerializer.serialize(value.overageBehavior) + : value.overageBehavior, reset_period: ResetPeriodSerializer.serialize(value.resetPeriod), + thresholds: value.thresholds, + type: value.type ?? "METERED", + warning_threshold_pct: value.warningThresholdPct, }; }, }; diff --git a/src/models/metric.ts b/src/models/metric.ts index 1838173..8405af2 100644 --- a/src/models/metric.ts +++ b/src/models/metric.ts @@ -35,6 +35,10 @@ export interface Metric { productId?: ProductId | null | undefined; segmentationMatrix?: MetricSegmentationMatrix | null | undefined; unitConversion?: UnitConversion | null | undefined; + /** What several units of the metric are called, e.g. `tokens`. */ + unitPlural?: string | null | undefined; + /** What one unit of the metric is called, e.g. `token`. Set together with `unit_plural`. */ + unitSingular?: string | null | undefined; usageGroupKey?: string | null | undefined; } @@ -57,6 +61,8 @@ export const MetricSerializer = { "product_id", "segmentation_matrix", "unit_conversion", + "unit_plural", + "unit_singular", "usage_group_key", ]), aggregationKey: @@ -111,6 +117,14 @@ export const MetricSerializer = { decodePath(path, "unit_conversion") ) : json["unit_conversion"], + unitPlural: + json["unit_plural"] != null + ? decodeString(json["unit_plural"], path, "unit_plural") + : json["unit_plural"], + unitSingular: + json["unit_singular"] != null + ? decodeString(json["unit_singular"], path, "unit_singular") + : json["unit_singular"], usageGroupKey: json["usage_group_key"] != null ? decodeString(json["usage_group_key"], path, "usage_group_key") @@ -134,6 +148,8 @@ export const MetricSerializer = { "productId", "segmentationMatrix", "unitConversion", + "unitPlural", + "unitSingular", "usageGroupKey", ]), aggregation_key: value.aggregationKey, @@ -163,6 +179,8 @@ export const MetricSerializer = { value.unitConversion != null ? UnitConversionSerializer.serialize(value.unitConversion) : value.unitConversion, + unit_plural: value.unitPlural, + unit_singular: value.unitSingular, usage_group_key: value.usageGroupKey, }; }, diff --git a/src/models/metricEvent.ts b/src/models/metricEvent.ts index a7b141b..0d5ff65 100644 --- a/src/models/metricEvent.ts +++ b/src/models/metricEvent.ts @@ -32,6 +32,8 @@ export const MetricEventSerializer = { "segmentation_matrix", "unit_conversion_factor", "unit_conversion_rounding", + "unit_plural", + "unit_singular", "usage_group_key", ]), ...pickProperties(MetricEventDataSerializer.parse(json, path), [ @@ -47,6 +49,8 @@ export const MetricEventSerializer = { "segmentationMatrix", "unitConversionFactor", "unitConversionRounding", + "unitPlural", + "unitSingular", "usageGroupKey", ]), id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), @@ -73,6 +77,8 @@ export const MetricEventSerializer = { "segmentationMatrix", "unitConversionFactor", "unitConversionRounding", + "unitPlural", + "unitSingular", "usageGroupKey", ]), ...pickProperties(MetricEventDataSerializer.serialize(value), [ @@ -88,6 +94,8 @@ export const MetricEventSerializer = { "segmentation_matrix", "unit_conversion_factor", "unit_conversion_rounding", + "unit_plural", + "unit_singular", "usage_group_key", ]), id: EventIdSerializer.serialize(value.id), diff --git a/src/models/metricEventData.ts b/src/models/metricEventData.ts index c8548e1..09bd945 100644 --- a/src/models/metricEventData.ts +++ b/src/models/metricEventData.ts @@ -36,6 +36,10 @@ export interface MetricEventData { segmentationMatrix?: MetricSegmentationMatrix | null | undefined; unitConversionFactor?: number | null | undefined; unitConversionRounding?: UnitConversionRoundingEnum | null | undefined; + /** What several units of the metric are called, e.g. `tokens`. */ + unitPlural?: string | null | undefined; + /** What one unit of the metric is called, e.g. `token`. */ + unitSingular?: string | null | undefined; usageGroupKey?: string | null | undefined; } @@ -57,6 +61,8 @@ export const MetricEventDataSerializer = { "segmentation_matrix", "unit_conversion_factor", "unit_conversion_rounding", + "unit_plural", + "unit_singular", "usage_group_key", ]), aggregationKey: @@ -104,6 +110,14 @@ export const MetricEventDataSerializer = { decodePath(path, "unit_conversion_rounding") ) : json["unit_conversion_rounding"], + unitPlural: + json["unit_plural"] != null + ? decodeString(json["unit_plural"], path, "unit_plural") + : json["unit_plural"], + unitSingular: + json["unit_singular"] != null + ? decodeString(json["unit_singular"], path, "unit_singular") + : json["unit_singular"], usageGroupKey: json["usage_group_key"] != null ? decodeString(json["usage_group_key"], path, "usage_group_key") @@ -126,6 +140,8 @@ export const MetricEventDataSerializer = { "segmentationMatrix", "unitConversionFactor", "unitConversionRounding", + "unitPlural", + "unitSingular", "usageGroupKey", ]), aggregation_key: value.aggregationKey, @@ -151,6 +167,8 @@ export const MetricEventDataSerializer = { value.unitConversionRounding != null ? UnitConversionRoundingEnumSerializer.serialize(value.unitConversionRounding) : value.unitConversionRounding, + unit_plural: value.unitPlural, + unit_singular: value.unitSingular, usage_group_key: value.usageGroupKey, }; }, diff --git a/src/models/metricSummary.ts b/src/models/metricSummary.ts index 9516ec7..6167b7a 100644 --- a/src/models/metricSummary.ts +++ b/src/models/metricSummary.ts @@ -16,6 +16,10 @@ export interface MetricSummary { description?: string | null | undefined; id: BillableMetricId; name: string; + /** What several units of the metric are called, e.g. `tokens`. */ + unitPlural?: string | null | undefined; + /** What one unit of the metric is called, e.g. `token`. */ + unitSingular?: string | null | undefined; } /** Converts `MetricSummary` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -32,6 +36,8 @@ export const MetricSummarySerializer = { "description", "id", "name", + "unit_plural", + "unit_singular", ]), aggregationKey: json["aggregation_key"] != null @@ -53,6 +59,14 @@ export const MetricSummarySerializer = { : json["description"], id: BillableMetricIdSerializer.parse(json["id"], decodePath(path, "id")), name: decodeString(json["name"], path, "name"), + unitPlural: + json["unit_plural"] != null + ? decodeString(json["unit_plural"], path, "unit_plural") + : json["unit_plural"], + unitSingular: + json["unit_singular"] != null + ? decodeString(json["unit_singular"], path, "unit_singular") + : json["unit_singular"], }; }, @@ -67,6 +81,8 @@ export const MetricSummarySerializer = { "description", "id", "name", + "unitPlural", + "unitSingular", ]), aggregation_key: value.aggregationKey, aggregation_type: BillingMetricAggregateEnumSerializer.serialize( @@ -78,6 +94,8 @@ export const MetricSummarySerializer = { description: value.description, id: BillableMetricIdSerializer.serialize(value.id), name: value.name, + unit_plural: value.unitPlural, + unit_singular: value.unitSingular, }; }, }; diff --git a/src/models/metricUsage.ts b/src/models/metricUsage.ts index f5f2923..86e36fd 100644 --- a/src/models/metricUsage.ts +++ b/src/models/metricUsage.ts @@ -3,8 +3,14 @@ import { extraProperties } from "../json.js"; import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; import { type GroupedUsage, GroupedUsageSerializer } from "./groupedUsage.js"; +import { type UsageCost, UsageCostSerializer } from "./usageCost.js"; export interface MetricUsage { + /** + * Beta: what the metric's usage adds so far to the subscription's next invoice, per currency + * or credit unit; empty while it bills nothing, as during a free trial or once cancelled. + */ + costs?: UsageCost[] | null | undefined; groupedUsage: GroupedUsage[]; metricCode: string; metricId: BillableMetricId; @@ -18,12 +24,19 @@ export const MetricUsageSerializer = { decodeObject(json, path); return { ...extraProperties(json, [ + "costs", "grouped_usage", "metric_code", "metric_id", "metric_name", "total_value", ]), + costs: + json["costs"] != null + ? decodeList(json["costs"], path, "costs", (item: any, p: string, i: number) => + UsageCostSerializer.parse(item, decodePath(p, i)) + ) + : json["costs"], groupedUsage: decodeList( json["grouped_usage"], path, @@ -44,12 +57,17 @@ export const MetricUsageSerializer = { serialize(value: MetricUsage): any { return { ...extraProperties(value, [ + "costs", "groupedUsage", "metricCode", "metricId", "metricName", "totalValue", ]), + costs: + value.costs != null + ? value.costs.map((item: any) => UsageCostSerializer.serialize(item)) + : value.costs, grouped_usage: value.groupedUsage.map((item: any) => GroupedUsageSerializer.serialize(item) ), diff --git a/src/models/neverResetPeriod.ts b/src/models/neverResetPeriod.ts index a4e8964..a3ac54e 100644 --- a/src/models/neverResetPeriod.ts +++ b/src/models/neverResetPeriod.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; /** Never resets — counts all usage since the subscription was activated. */ -export interface NeverResetPeriod {} +export interface NeverResetPeriod { + type: "NEVER"; +} /** Converts `NeverResetPeriod` values from (`parse`) and to (`serialize`) their JSON form. */ export const NeverResetPeriodSerializer = { parse(json: any, path = "$"): NeverResetPeriod { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "NEVER") + : "NEVER", }; }, serialize(value: NeverResetPeriod): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "NEVER", }; }, }; diff --git a/src/models/newProductRef.ts b/src/models/newProductRef.ts index b73a1dc..4c8b62a 100644 --- a/src/models/newProductRef.ts +++ b/src/models/newProductRef.ts @@ -14,6 +14,7 @@ export interface NewProductRef { feeStructure: ProductFeeStructure; feeType: ProductFeeTypeEnum; name: string; + type: "NEW"; } /** Converts `NewProductRef` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -21,7 +22,7 @@ export const NewProductRefSerializer = { parse(json: any, path = "$"): NewProductRef { decodeObject(json, path); return { - ...extraProperties(json, ["fee_structure", "fee_type", "name"]), + ...extraProperties(json, ["fee_structure", "fee_type", "name", "type"]), feeStructure: ProductFeeStructureSerializer.parse( json["fee_structure"], decodePath(path, "fee_structure") @@ -31,15 +32,20 @@ export const NewProductRefSerializer = { decodePath(path, "fee_type") ), name: decodeString(json["name"], path, "name"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "NEW") + : "NEW", }; }, serialize(value: NewProductRef): any { return { - ...extraProperties(value, ["feeStructure", "feeType", "name"]), + ...extraProperties(value, ["feeStructure", "feeType", "name", "type"]), fee_structure: ProductFeeStructureSerializer.serialize(value.feeStructure), fee_type: ProductFeeTypeEnumSerializer.serialize(value.feeType), name: value.name, + type: value.type ?? "NEW", }; }, }; diff --git a/src/models/numberConfigValue.ts b/src/models/numberConfigValue.ts index 03e8cce..88d4747 100644 --- a/src/models/numberConfigValue.ts +++ b/src/models/numberConfigValue.ts @@ -3,6 +3,7 @@ import { extraProperties } from "../json.js"; import { decodeObject, decodeString } from "../decode.js"; /** A number config value (decimal, encoded as a string). */ export interface NumberConfigValue { + kind: "NUMBER"; value: string; } @@ -11,14 +12,19 @@ export const NumberConfigValueSerializer = { parse(json: any, path = "$"): NumberConfigValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["kind", "value"]), + kind: + json["kind"] != null + ? (decodeString(json["kind"], path, "kind") as "NUMBER") + : "NUMBER", value: decodeString(json["value"], path, "value"), }; }, serialize(value: NumberConfigValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["kind", "value"]), + kind: value.kind ?? "NUMBER", value: value.value, }; }, diff --git a/src/models/oneTimeFee.ts b/src/models/oneTimeFee.ts index 8779b9a..1ab24a8 100644 --- a/src/models/oneTimeFee.ts +++ b/src/models/oneTimeFee.ts @@ -5,6 +5,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface OneTimeFee { quantity: number; rate: string; + type: "ONE_TIME"; } /** Converts `OneTimeFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const OneTimeFeeSerializer = { parse(json: any, path = "$"): OneTimeFee { decodeObject(json, path); return { - ...extraProperties(json, ["quantity", "rate"]), + ...extraProperties(json, ["quantity", "rate", "type"]), quantity: decodeInteger(json["quantity"], path, "quantity"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "ONE_TIME") + : "ONE_TIME", }; }, serialize(value: OneTimeFee): any { return { - ...extraProperties(value, ["quantity", "rate"]), + ...extraProperties(value, ["quantity", "rate", "type"]), quantity: value.quantity, rate: value.rate, + type: value.type ?? "ONE_TIME", }; }, }; diff --git a/src/models/oneTimeFeeStructure.ts b/src/models/oneTimeFeeStructure.ts index 769cd18..c1ae0d0 100644 --- a/src/models/oneTimeFeeStructure.ts +++ b/src/models/oneTimeFeeStructure.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; -export interface OneTimeFeeStructure {} +export interface OneTimeFeeStructure { + type: "ONE_TIME"; +} /** Converts `OneTimeFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ export const OneTimeFeeStructureSerializer = { parse(json: any, path = "$"): OneTimeFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "ONE_TIME") + : "ONE_TIME", }; }, serialize(value: OneTimeFeeStructure): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "ONE_TIME", }; }, }; diff --git a/src/models/oneTimePlanFee.ts b/src/models/oneTimePlanFee.ts index ebd4b19..c10899b 100644 --- a/src/models/oneTimePlanFee.ts +++ b/src/models/oneTimePlanFee.ts @@ -4,6 +4,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; /** One-time fee */ export interface OneTimePlanFee { quantity: number; + type: "ONE_TIME"; unitPrice: string; } @@ -12,16 +13,21 @@ export const OneTimePlanFeeSerializer = { parse(json: any, path = "$"): OneTimePlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["quantity", "unit_price"]), + ...extraProperties(json, ["quantity", "type", "unit_price"]), quantity: decodeInteger(json["quantity"], path, "quantity"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "ONE_TIME") + : "ONE_TIME", unitPrice: decodeString(json["unit_price"], path, "unit_price"), }; }, serialize(value: OneTimePlanFee): any { return { - ...extraProperties(value, ["quantity", "unitPrice"]), + ...extraProperties(value, ["quantity", "type", "unitPrice"]), quantity: value.quantity, + type: value.type ?? "ONE_TIME", unit_price: value.unitPrice, }; }, diff --git a/src/models/oneTimePricing.ts b/src/models/oneTimePricing.ts index 4edbe7d..f1cb3e2 100644 --- a/src/models/oneTimePricing.ts +++ b/src/models/oneTimePricing.ts @@ -4,6 +4,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface OneTimePricing { quantity: number; + type: "ONE_TIME"; unitPrice: string; } @@ -12,16 +13,21 @@ export const OneTimePricingSerializer = { parse(json: any, path = "$"): OneTimePricing { decodeObject(json, path); return { - ...extraProperties(json, ["quantity", "unit_price"]), + ...extraProperties(json, ["quantity", "type", "unit_price"]), quantity: decodeInteger(json["quantity"], path, "quantity"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "ONE_TIME") + : "ONE_TIME", unitPrice: decodeString(json["unit_price"], path, "unit_price"), }; }, serialize(value: OneTimePricing): any { return { - ...extraProperties(value, ["quantity", "unitPrice"]), + ...extraProperties(value, ["quantity", "type", "unitPrice"]), quantity: value.quantity, + type: value.type ?? "ONE_TIME", unit_price: value.unitPrice, }; }, diff --git a/src/models/onlinePaymentMethodConfig.ts b/src/models/onlinePaymentMethodConfig.ts index 06611ee..0e955ea 100644 --- a/src/models/onlinePaymentMethodConfig.ts +++ b/src/models/onlinePaymentMethodConfig.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type OnlineMethodsConfig, OnlineMethodsConfigSerializer, @@ -8,6 +8,7 @@ import { export interface OnlinePaymentMethodConfig { config?: OnlineMethodsConfig | null | undefined; + type: "online"; } /** Converts `OnlinePaymentMethodConfig` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -15,7 +16,7 @@ export const OnlinePaymentMethodConfigSerializer = { parse(json: any, path = "$"): OnlinePaymentMethodConfig { decodeObject(json, path); return { - ...extraProperties(json, ["config"]), + ...extraProperties(json, ["config", "type"]), config: json["config"] != null ? OnlineMethodsConfigSerializer.parse( @@ -23,16 +24,21 @@ export const OnlinePaymentMethodConfigSerializer = { decodePath(path, "config") ) : json["config"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "online") + : "online", }; }, serialize(value: OnlinePaymentMethodConfig): any { return { - ...extraProperties(value, ["config"]), + ...extraProperties(value, ["config", "type"]), config: value.config != null ? OnlineMethodsConfigSerializer.serialize(value.config) : value.config, + type: value.type ?? "online", }; }, }; diff --git a/src/models/packagePlanPricing.ts b/src/models/packagePlanPricing.ts index 44eb88c..0f70bfe 100644 --- a/src/models/packagePlanPricing.ts +++ b/src/models/packagePlanPricing.ts @@ -5,6 +5,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface PackagePlanPricing { blockSize: number; rate: string; + type: "PACKAGE"; } /** Converts `PackagePlanPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const PackagePlanPricingSerializer = { parse(json: any, path = "$"): PackagePlanPricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "rate"]), + ...extraProperties(json, ["block_size", "rate", "type"]), blockSize: decodeInteger(json["block_size"], path, "block_size"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PACKAGE") + : "PACKAGE", }; }, serialize(value: PackagePlanPricing): any { return { - ...extraProperties(value, ["blockSize", "rate"]), + ...extraProperties(value, ["blockSize", "rate", "type"]), block_size: value.blockSize, rate: value.rate, + type: value.type ?? "PACKAGE", }; }, }; diff --git a/src/models/packagePricing.ts b/src/models/packagePricing.ts index 7e9b714..c584f19 100644 --- a/src/models/packagePricing.ts +++ b/src/models/packagePricing.ts @@ -5,6 +5,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface PackagePricing { blockSize: number; rate: string; + type: "PACKAGE"; } /** Converts `PackagePricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const PackagePricingSerializer = { parse(json: any, path = "$"): PackagePricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "rate"]), + ...extraProperties(json, ["block_size", "rate", "type"]), blockSize: decodeInteger(json["block_size"], path, "block_size"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PACKAGE") + : "PACKAGE", }; }, serialize(value: PackagePricing): any { return { - ...extraProperties(value, ["blockSize", "rate"]), + ...extraProperties(value, ["blockSize", "rate", "type"]), block_size: value.blockSize, rate: value.rate, + type: value.type ?? "PACKAGE", }; }, }; diff --git a/src/models/patchBudgetRequest.ts b/src/models/patchBudgetRequest.ts new file mode 100644 index 0000000..f845c52 --- /dev/null +++ b/src/models/patchBudgetRequest.ts @@ -0,0 +1,53 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeList, decodeObject, decodePath } from "../decode.js"; +import { type BudgetBehavior, BudgetBehaviorSerializer } from "./budgetBehavior.js"; +/** The currency or credit unit, and the subscription, are fixed at creation. */ +export interface PatchBudgetRequest { + amount?: number | null | undefined; + behavior?: BudgetBehavior | null | undefined; + /** The `version` you read; a newer stored version is refused with 409. */ + expectedVersion: number; + thresholds?: number[] | null | undefined; +} + +/** Converts `PatchBudgetRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const PatchBudgetRequestSerializer = { + parse(json: any, path = "$"): PatchBudgetRequest { + decodeObject(json, path); + return { + ...extraProperties(json, ["amount", "behavior", "expected_version", "thresholds"]), + amount: + json["amount"] != null + ? decodeInteger(json["amount"], path, "amount") + : json["amount"], + behavior: + json["behavior"] != null + ? BudgetBehaviorSerializer.parse(json["behavior"], decodePath(path, "behavior")) + : json["behavior"], + expectedVersion: decodeInteger(json["expected_version"], path, "expected_version"), + thresholds: + json["thresholds"] != null + ? decodeList( + json["thresholds"], + path, + "thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["thresholds"], + }; + }, + + serialize(value: PatchBudgetRequest): any { + return { + ...extraProperties(value, ["amount", "behavior", "expectedVersion", "thresholds"]), + amount: value.amount, + behavior: + value.behavior != null + ? BudgetBehaviorSerializer.serialize(value.behavior) + : value.behavior, + expected_version: value.expectedVersion, + thresholds: value.thresholds, + }; + }, +}; diff --git a/src/models/patchWalletRequest.ts b/src/models/patchWalletRequest.ts new file mode 100644 index 0000000..40be867 --- /dev/null +++ b/src/models/patchWalletRequest.ts @@ -0,0 +1,96 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { + type AutoTopUpWriteRequest, + AutoTopUpWriteRequestSerializer, +} from "./autoTopUpWriteRequest.js"; +import { type UsageAtZero, UsageAtZeroSerializer } from "./usageAtZero.js"; +/** Partial update of a wallet's configuration: omit a field to leave it unchanged. */ +export interface PatchWalletRequest { + autoTopUp?: AutoTopUpWriteRequest | null | undefined; + /** + * Ascending, distinct, at most 5, non-negative. Omit to leave unchanged; an empty list + * clears every threshold. + */ + lowBalanceThresholds?: number[] | null | undefined; + /** + * Credit unit wallets: the price this customer agreed for one credit, in major units of the + * customer's currency, as a decimal string (positive, at most 12 decimal places). Purchases + * and automatic top-ups default to it instead of the list price. Omit to leave it unchanged; + * `null` returns the customer to the list price. A change applies to purchases quoted after + * it. An automatic top-up keeps running at the new price when it is at or below the price + * its terms were authorized at, and stops until they are confirmed again when it is above. + */ + unitPrice?: string | null | undefined; + usageAtZero?: UsageAtZero | null | undefined; +} + +/** Converts `PatchWalletRequest` values from (`parse`) and to (`serialize`) their JSON form. */ +export const PatchWalletRequestSerializer = { + parse(json: any, path = "$"): PatchWalletRequest { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "auto_top_up", + "low_balance_thresholds", + "unit_price", + "usage_at_zero", + ]), + autoTopUp: + json["auto_top_up"] != null + ? AutoTopUpWriteRequestSerializer.parse( + json["auto_top_up"], + decodePath(path, "auto_top_up") + ) + : json["auto_top_up"], + lowBalanceThresholds: + json["low_balance_thresholds"] != null + ? decodeList( + json["low_balance_thresholds"], + path, + "low_balance_thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ) + : json["low_balance_thresholds"], + unitPrice: + json["unit_price"] != null + ? decodeString(json["unit_price"], path, "unit_price") + : json["unit_price"], + usageAtZero: + json["usage_at_zero"] != null + ? UsageAtZeroSerializer.parse( + json["usage_at_zero"], + decodePath(path, "usage_at_zero") + ) + : json["usage_at_zero"], + }; + }, + + serialize(value: PatchWalletRequest): any { + return { + ...extraProperties(value, [ + "autoTopUp", + "lowBalanceThresholds", + "unitPrice", + "usageAtZero", + ]), + auto_top_up: + value.autoTopUp != null + ? AutoTopUpWriteRequestSerializer.serialize(value.autoTopUp) + : value.autoTopUp, + low_balance_thresholds: value.lowBalanceThresholds, + unit_price: value.unitPrice, + usage_at_zero: + value.usageAtZero != null + ? UsageAtZeroSerializer.serialize(value.usageAtZero) + : value.usageAtZero, + }; + }, +}; diff --git a/src/models/paymentEvent.ts b/src/models/paymentEvent.ts index 129208c..25d2db8 100644 --- a/src/models/paymentEvent.ts +++ b/src/models/paymentEvent.ts @@ -21,8 +21,10 @@ export const PaymentEventSerializer = { "timestamp", "type", "amount", + "amount_disputed", "amount_refunded", "amount_reversed", + "amount_reversed_excess", "credit_note_id", "currency", "decline_kind", @@ -39,8 +41,10 @@ export const PaymentEventSerializer = { ]), ...pickProperties(RefundEventDataSerializer.parse(json, path), [ "amount", + "amountDisputed", "amountRefunded", "amountReversed", + "amountReversedExcess", "creditNoteId", "currency", "declineKind", @@ -68,8 +72,10 @@ export const PaymentEventSerializer = { "timestamp", "type", "amount", + "amountDisputed", "amountRefunded", "amountReversed", + "amountReversedExcess", "creditNoteId", "currency", "declineKind", @@ -86,8 +92,10 @@ export const PaymentEventSerializer = { ]), ...pickProperties(RefundEventDataSerializer.serialize(value), [ "amount", + "amount_disputed", "amount_refunded", "amount_reversed", + "amount_reversed_excess", "credit_note_id", "currency", "decline_kind", diff --git a/src/models/perUnitPlanPricing.ts b/src/models/perUnitPlanPricing.ts index 45fcd56..12dc219 100644 --- a/src/models/perUnitPlanPricing.ts +++ b/src/models/perUnitPlanPricing.ts @@ -4,6 +4,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface PerUnitPlanPricing { rate: string; + type: "PER_UNIT"; } /** Converts `PerUnitPlanPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const PerUnitPlanPricingSerializer = { parse(json: any, path = "$"): PerUnitPlanPricing { decodeObject(json, path); return { - ...extraProperties(json, ["rate"]), + ...extraProperties(json, ["rate", "type"]), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PER_UNIT") + : "PER_UNIT", }; }, serialize(value: PerUnitPlanPricing): any { return { - ...extraProperties(value, ["rate"]), + ...extraProperties(value, ["rate", "type"]), rate: value.rate, + type: value.type ?? "PER_UNIT", }; }, }; diff --git a/src/models/perUnitPricing.ts b/src/models/perUnitPricing.ts index 22a7d0e..e01bff1 100644 --- a/src/models/perUnitPricing.ts +++ b/src/models/perUnitPricing.ts @@ -4,6 +4,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface PerUnitPricing { rate: string; + type: "PER_UNIT"; } /** Converts `PerUnitPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const PerUnitPricingSerializer = { parse(json: any, path = "$"): PerUnitPricing { decodeObject(json, path); return { - ...extraProperties(json, ["rate"]), + ...extraProperties(json, ["rate", "type"]), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PER_UNIT") + : "PER_UNIT", }; }, serialize(value: PerUnitPricing): any { return { - ...extraProperties(value, ["rate"]), + ...extraProperties(value, ["rate", "type"]), rate: value.rate, + type: value.type ?? "PER_UNIT", }; }, }; diff --git a/src/models/percentageDiscount.ts b/src/models/percentageDiscount.ts index 86304d8..77fa5ba 100644 --- a/src/models/percentageDiscount.ts +++ b/src/models/percentageDiscount.ts @@ -4,6 +4,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface PercentageDiscount { percentage: string; + type: "PERCENTAGE"; } /** Converts `PercentageDiscount` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const PercentageDiscountSerializer = { parse(json: any, path = "$"): PercentageDiscount { decodeObject(json, path); return { - ...extraProperties(json, ["percentage"]), + ...extraProperties(json, ["percentage", "type"]), percentage: decodeString(json["percentage"], path, "percentage"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PERCENTAGE") + : "PERCENTAGE", }; }, serialize(value: PercentageDiscount): any { return { - ...extraProperties(value, ["percentage"]), + ...extraProperties(value, ["percentage", "type"]), percentage: value.percentage, + type: value.type ?? "PERCENTAGE", }; }, }; diff --git a/src/models/plan.ts b/src/models/plan.ts index fdcfca3..1254511 100644 --- a/src/models/plan.ts +++ b/src/models/plan.ts @@ -13,6 +13,10 @@ import { type AvailableParameters, AvailableParametersSerializer, } from "./availableParameters.js"; +import { + type CreditExhaustedRule, + CreditExhaustedRuleSerializer, +} from "./creditExhaustedRule.js"; import { type Currency, CurrencySerializer } from "./currency.js"; import { type Entitlement, EntitlementSerializer } from "./entitlement.js"; import { @@ -31,6 +35,7 @@ export interface Plan { availableParameters: AvailableParameters; billingCycles?: number | null | undefined; createdAt: Date; + creditExhaustedRule?: CreditExhaustedRule | null | undefined; currency: Currency; description?: string | null | undefined; entitlements?: Entitlement[] | undefined; @@ -65,6 +70,7 @@ export const PlanSerializer = { "available_parameters", "billing_cycles", "created_at", + "credit_exhausted_rule", "currency", "description", "entitlements", @@ -92,6 +98,13 @@ export const PlanSerializer = { ? decodeInteger(json["billing_cycles"], path, "billing_cycles") : json["billing_cycles"], createdAt: decodeDateTime(json["created_at"], path, "created_at"), + creditExhaustedRule: + json["credit_exhausted_rule"] != null + ? CreditExhaustedRuleSerializer.parse( + json["credit_exhausted_rule"], + decodePath(path, "credit_exhausted_rule") + ) + : json["credit_exhausted_rule"], currency: CurrencySerializer.parse(json["currency"], decodePath(path, "currency")), description: json["description"] != null @@ -160,6 +173,7 @@ export const PlanSerializer = { "availableParameters", "billingCycles", "createdAt", + "creditExhaustedRule", "currency", "description", "entitlements", @@ -183,6 +197,10 @@ export const PlanSerializer = { ), billing_cycles: value.billingCycles, created_at: value.createdAt, + credit_exhausted_rule: + value.creditExhaustedRule != null + ? CreditExhaustedRuleSerializer.serialize(value.creditExhaustedRule) + : value.creditExhaustedRule, currency: CurrencySerializer.serialize(value.currency), description: value.description, entitlements: diff --git a/src/models/planFeeCreditUnit.ts b/src/models/planFeeCreditUnit.ts new file mode 100644 index 0000000..fb4a309 --- /dev/null +++ b/src/models/planFeeCreditUnit.ts @@ -0,0 +1,33 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; +/** The credit unit a plan's usage price is expressed in, with its value in the plan currency. */ +export interface PlanFeeCreditUnit { + /** An active credit unit of the tenant (`GET /api/v1/credit-units`). */ + creditUnitId: string; + /** + * Plan-currency major units per credit (e.g. "0.01"), positive: the money billed for each + * credit the customer's balance in the unit does not cover, before tax. + */ + rate: string; +} + +/** Converts `PlanFeeCreditUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const PlanFeeCreditUnitSerializer = { + parse(json: any, path = "$"): PlanFeeCreditUnit { + decodeObject(json, path); + return { + ...extraProperties(json, ["credit_unit_id", "rate"]), + creditUnitId: decodeString(json["credit_unit_id"], path, "credit_unit_id"), + rate: decodeString(json["rate"], path, "rate"), + }; + }, + + serialize(value: PlanFeeCreditUnit): any { + return { + ...extraProperties(value, ["creditUnitId", "rate"]), + credit_unit_id: value.creditUnitId, + rate: value.rate, + }; + }, +}; diff --git a/src/models/priceInput.ts b/src/models/priceInput.ts index e8ff56f..6dfc29e 100644 --- a/src/models/priceInput.ts +++ b/src/models/priceInput.ts @@ -11,6 +11,7 @@ export interface PriceInput { cadence: BillingPeriodEnum; currency: string; pricing: Pricing; + type: "NEW"; } /** Converts `PriceInput` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -18,22 +19,27 @@ export const PriceInputSerializer = { parse(json: any, path = "$"): PriceInput { decodeObject(json, path); return { - ...extraProperties(json, ["cadence", "currency", "pricing"]), + ...extraProperties(json, ["cadence", "currency", "pricing", "type"]), cadence: BillingPeriodEnumSerializer.parse( json["cadence"], decodePath(path, "cadence") ), currency: decodeString(json["currency"], path, "currency"), pricing: PricingSerializer.parse(json["pricing"], decodePath(path, "pricing")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "NEW") + : "NEW", }; }, serialize(value: PriceInput): any { return { - ...extraProperties(value, ["cadence", "currency", "pricing"]), + ...extraProperties(value, ["cadence", "currency", "pricing", "type"]), cadence: BillingPeriodEnumSerializer.serialize(value.cadence), currency: value.currency, pricing: PricingSerializer.serialize(value.pricing), + type: value.type ?? "NEW", }; }, }; diff --git a/src/models/productFeeStructure.ts b/src/models/productFeeStructure.ts index 52b8cf7..75b1a0b 100644 --- a/src/models/productFeeStructure.ts +++ b/src/models/productFeeStructure.ts @@ -4,6 +4,10 @@ import { type CapacityFeeStructure, CapacityFeeStructureSerializer, } from "./capacityFeeStructure.js"; +import { + type CreditFeeStructure, + CreditFeeStructureSerializer, +} from "./creditFeeStructure.js"; import { type ExtraRecurringFeeStructure, ExtraRecurringFeeStructureSerializer, @@ -37,6 +41,9 @@ export interface ProductFeeStructureExtraRecurring extends ExtraRecurringFeeStru export interface ProductFeeStructureOneTime extends OneTimeFeeStructure { type: "ONE_TIME"; } +export interface ProductFeeStructureCredit extends CreditFeeStructure { + type: "CREDIT"; +} export type ProductFeeStructure = | ProductFeeStructureRate @@ -44,7 +51,8 @@ export type ProductFeeStructure = | ProductFeeStructureCapacity | ProductFeeStructureUsage | ProductFeeStructureExtraRecurring - | ProductFeeStructureOneTime; + | ProductFeeStructureOneTime + | ProductFeeStructureCredit; /** Converts `ProductFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ export const ProductFeeStructureSerializer = { @@ -81,6 +89,11 @@ export const ProductFeeStructureSerializer = { ...OneTimeFeeStructureSerializer.parse(json, path), type: "ONE_TIME", }; + case "CREDIT": + return { + ...CreditFeeStructureSerializer.parse(json, path), + type: "CREDIT", + }; default: // A variant added to the API after this SDK was generated, kept as received. return json; @@ -119,6 +132,11 @@ export const ProductFeeStructureSerializer = { ...OneTimeFeeStructureSerializer.serialize(value), type: "ONE_TIME", }; + case "CREDIT": + return { + ...CreditFeeStructureSerializer.serialize(value), + type: "CREDIT", + }; default: return value; } diff --git a/src/models/productFeeTypeEnum.ts b/src/models/productFeeTypeEnum.ts index 0d64c11..68cbc52 100644 --- a/src/models/productFeeTypeEnum.ts +++ b/src/models/productFeeTypeEnum.ts @@ -8,6 +8,7 @@ export const ProductFeeTypeEnum = { Usage: "USAGE", ExtraRecurring: "EXTRA_RECURRING", OneTime: "ONE_TIME", + Credit: "CREDIT", } as const; export type ProductFeeTypeEnum = | (typeof ProductFeeTypeEnum)[keyof typeof ProductFeeTypeEnum] diff --git a/src/models/productsScope.ts b/src/models/productsScope.ts index 281f201..244d7a7 100644 --- a/src/models/productsScope.ts +++ b/src/models/productsScope.ts @@ -7,6 +7,7 @@ import { decodeList, decodeObject, decodeString } from "../decode.js"; */ export interface ProductsScope { productIds: string[]; + type: "products"; } /** Converts `ProductsScope` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -14,20 +15,25 @@ export const ProductsScopeSerializer = { parse(json: any, path = "$"): ProductsScope { decodeObject(json, path); return { - ...extraProperties(json, ["product_ids"]), + ...extraProperties(json, ["product_ids", "type"]), productIds: decodeList( json["product_ids"], path, "product_ids", (item: any, p: string, i: number) => decodeString(item, p, i) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "products") + : "products", }; }, serialize(value: ProductsScope): any { return { - ...extraProperties(value, ["productIds"]), + ...extraProperties(value, ["productIds", "type"]), product_ids: value.productIds, + type: value.type ?? "products", }; }, }; diff --git a/src/models/rateFee.ts b/src/models/rateFee.ts index 76789da..07b3378 100644 --- a/src/models/rateFee.ts +++ b/src/models/rateFee.ts @@ -4,6 +4,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface RateFee { rate: string; + type: "RATE"; } /** Converts `RateFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const RateFeeSerializer = { parse(json: any, path = "$"): RateFee { decodeObject(json, path); return { - ...extraProperties(json, ["rate"]), + ...extraProperties(json, ["rate", "type"]), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "RATE") + : "RATE", }; }, serialize(value: RateFee): any { return { - ...extraProperties(value, ["rate"]), + ...extraProperties(value, ["rate", "type"]), rate: value.rate, + type: value.type ?? "RATE", }; }, }; diff --git a/src/models/rateFeeStructure.ts b/src/models/rateFeeStructure.ts index cdcc6b4..782aea7 100644 --- a/src/models/rateFeeStructure.ts +++ b/src/models/rateFeeStructure.ts @@ -1,21 +1,28 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject } from "../decode.js"; +import { decodeObject, decodeString } from "../decode.js"; -export interface RateFeeStructure {} +export interface RateFeeStructure { + type: "RATE"; +} /** Converts `RateFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ export const RateFeeStructureSerializer = { parse(json: any, path = "$"): RateFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, []), + ...extraProperties(json, ["type"]), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "RATE") + : "RATE", }; }, serialize(value: RateFeeStructure): any { return { - ...extraProperties(value, []), + ...extraProperties(value, ["type"]), + type: value.type ?? "RATE", }; }, }; diff --git a/src/models/ratePlanFee.ts b/src/models/ratePlanFee.ts index cdaef6c..4d384c2 100644 --- a/src/models/ratePlanFee.ts +++ b/src/models/ratePlanFee.ts @@ -1,10 +1,11 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; import { type TermRate, TermRateSerializer } from "./termRate.js"; /** Recurring rate fee (e.g., monthly subscription) */ export interface RatePlanFee { rates: TermRate[]; + type: "RATE"; } /** Converts `RatePlanFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -12,17 +13,22 @@ export const RatePlanFeeSerializer = { parse(json: any, path = "$"): RatePlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["rates"]), + ...extraProperties(json, ["rates", "type"]), rates: decodeList(json["rates"], path, "rates", (item: any, p: string, i: number) => TermRateSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "RATE") + : "RATE", }; }, serialize(value: RatePlanFee): any { return { - ...extraProperties(value, ["rates"]), + ...extraProperties(value, ["rates", "type"]), rates: value.rates.map((item: any) => TermRateSerializer.serialize(item)), + type: value.type ?? "RATE", }; }, }; diff --git a/src/models/ratePricing.ts b/src/models/ratePricing.ts index 11b4ccb..ae1eaba 100644 --- a/src/models/ratePricing.ts +++ b/src/models/ratePricing.ts @@ -4,6 +4,7 @@ import { decodeObject, decodeString } from "../decode.js"; export interface RatePricing { rate: string; + type: "RATE"; } /** Converts `RatePricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -11,15 +12,20 @@ export const RatePricingSerializer = { parse(json: any, path = "$"): RatePricing { decodeObject(json, path); return { - ...extraProperties(json, ["rate"]), + ...extraProperties(json, ["rate", "type"]), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "RATE") + : "RATE", }; }, serialize(value: RatePricing): any { return { - ...extraProperties(value, ["rate"]), + ...extraProperties(value, ["rate", "type"]), rate: value.rate, + type: value.type ?? "RATE", }; }, }; diff --git a/src/models/recurringFee.ts b/src/models/recurringFee.ts index 379dc23..743e902 100644 --- a/src/models/recurringFee.ts +++ b/src/models/recurringFee.ts @@ -7,6 +7,7 @@ export interface RecurringFee { billingType: BillingTypeEnum; quantity: number; rate: string; + type: "RECURRING"; } /** Converts `RecurringFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -14,22 +15,27 @@ export const RecurringFeeSerializer = { parse(json: any, path = "$"): RecurringFee { decodeObject(json, path); return { - ...extraProperties(json, ["billing_type", "quantity", "rate"]), + ...extraProperties(json, ["billing_type", "quantity", "rate", "type"]), billingType: BillingTypeEnumSerializer.parse( json["billing_type"], decodePath(path, "billing_type") ), quantity: decodeInteger(json["quantity"], path, "quantity"), rate: decodeString(json["rate"], path, "rate"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "RECURRING") + : "RECURRING", }; }, serialize(value: RecurringFee): any { return { - ...extraProperties(value, ["billingType", "quantity", "rate"]), + ...extraProperties(value, ["billingType", "quantity", "rate", "type"]), billing_type: BillingTypeEnumSerializer.serialize(value.billingType), quantity: value.quantity, rate: value.rate, + type: value.type ?? "RECURRING", }; }, }; diff --git a/src/models/refundEventData.ts b/src/models/refundEventData.ts index c2b2cca..ce49bda 100644 --- a/src/models/refundEventData.ts +++ b/src/models/refundEventData.ts @@ -28,8 +28,15 @@ import { type ReversalKind, ReversalKindSerializer } from "./reversalKind.js"; */ export interface RefundEventData { amount: number; + /** The part of `amount_reversed` lost to disputes or chargebacks: the invoice stays paid. */ + amountDisputed?: number | undefined; amountRefunded: number; amountReversed: number; + /** + * What the provider withdrew above what the payment still held (refunded before); never + * applied to the invoice or credit. Contest it with the provider. + */ + amountReversedExcess?: number | undefined; creditNoteId?: CreditNoteId | null | undefined; currency: string; declineKind?: DeclineKind | null | undefined; @@ -52,8 +59,10 @@ export const RefundEventDataSerializer = { return { ...extraProperties(json, [ "amount", + "amount_disputed", "amount_refunded", "amount_reversed", + "amount_reversed_excess", "credit_note_id", "currency", "decline_kind", @@ -69,8 +78,16 @@ export const RefundEventDataSerializer = { "transaction_id", ]), amount: decodeInteger(json["amount"], path, "amount"), + amountDisputed: + json["amount_disputed"] != null + ? decodeInteger(json["amount_disputed"], path, "amount_disputed") + : undefined, amountRefunded: decodeInteger(json["amount_refunded"], path, "amount_refunded"), amountReversed: decodeInteger(json["amount_reversed"], path, "amount_reversed"), + amountReversedExcess: + json["amount_reversed_excess"] != null + ? decodeInteger(json["amount_reversed_excess"], path, "amount_reversed_excess") + : undefined, creditNoteId: json["credit_note_id"] != null ? CreditNoteIdSerializer.parse( @@ -142,8 +159,10 @@ export const RefundEventDataSerializer = { return { ...extraProperties(value, [ "amount", + "amountDisputed", "amountRefunded", "amountReversed", + "amountReversedExcess", "creditNoteId", "currency", "declineKind", @@ -159,8 +178,10 @@ export const RefundEventDataSerializer = { "transactionId", ]), amount: value.amount, + amount_disputed: value.amountDisputed, amount_refunded: value.amountRefunded, amount_reversed: value.amountReversed, + amount_reversed_excess: value.amountReversedExcess, credit_note_id: value.creditNoteId != null ? CreditNoteIdSerializer.serialize(value.creditNoteId) diff --git a/src/models/replacePlanRequest.ts b/src/models/replacePlanRequest.ts index bc3d723..7f91292 100644 --- a/src/models/replacePlanRequest.ts +++ b/src/models/replacePlanRequest.ts @@ -8,6 +8,10 @@ import { decodeString, } from "../decode.js"; import { type BillingConfig, BillingConfigSerializer } from "./billingConfig.js"; +import { + type CreditExhaustedRule, + CreditExhaustedRuleSerializer, +} from "./creditExhaustedRule.js"; import { type EntitlementSpecRequest, EntitlementSpecRequestSerializer, @@ -28,6 +32,7 @@ export interface ReplacePlanRequest { addOns?: PlanAddOnInput[] | undefined; billing?: BillingConfig | null | undefined; components: PriceComponentInput[]; + creditExhaustedRule?: CreditExhaustedRule | null | undefined; currency: string; description?: string | null | undefined; /** @@ -58,6 +63,7 @@ export const ReplacePlanRequestSerializer = { "add_ons", "billing", "components", + "credit_exhausted_rule", "currency", "description", "entitlements", @@ -88,6 +94,13 @@ export const ReplacePlanRequestSerializer = { (item: any, p: string, i: number) => PriceComponentInputSerializer.parse(item, decodePath(p, i)) ), + creditExhaustedRule: + json["credit_exhausted_rule"] != null + ? CreditExhaustedRuleSerializer.parse( + json["credit_exhausted_rule"], + decodePath(path, "credit_exhausted_rule") + ) + : json["credit_exhausted_rule"], currency: decodeString(json["currency"], path, "currency"), description: json["description"] != null @@ -132,6 +145,7 @@ export const ReplacePlanRequestSerializer = { "addOns", "billing", "components", + "creditExhaustedRule", "currency", "description", "entitlements", @@ -152,6 +166,10 @@ export const ReplacePlanRequestSerializer = { components: value.components.map((item: any) => PriceComponentInputSerializer.serialize(item) ), + credit_exhausted_rule: + value.creditExhaustedRule != null + ? CreditExhaustedRuleSerializer.serialize(value.creditExhaustedRule) + : value.creditExhaustedRule, currency: value.currency, description: value.description, entitlements: diff --git a/src/models/slidingWindowResetPeriod.ts b/src/models/slidingWindowResetPeriod.ts index b874c1d..3f32c6d 100644 --- a/src/models/slidingWindowResetPeriod.ts +++ b/src/models/slidingWindowResetPeriod.ts @@ -1,10 +1,15 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; import { type CalendarUnit, CalendarUnitSerializer } from "./calendarUnit.js"; -/** Always ends at now — e.g. 30 days means the last 30 days, old usage drops off automatically. */ +/** + * Always ends at now — e.g. 30 days means the last 30 days, old usage drops off automatically. + * A sliding window has no reset moment (`reset_at` is absent) and sends no threshold or + * limit-reached webhooks; it is enforced by the entitlement check. + */ export interface SlidingWindowResetPeriod { interval: number; + type: "SLIDING_WINDOW"; unit: CalendarUnit; } @@ -13,16 +18,21 @@ export const SlidingWindowResetPeriodSerializer = { parse(json: any, path = "$"): SlidingWindowResetPeriod { decodeObject(json, path); return { - ...extraProperties(json, ["interval", "unit"]), + ...extraProperties(json, ["interval", "type", "unit"]), interval: decodeInteger(json["interval"], path, "interval"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "SLIDING_WINDOW") + : "SLIDING_WINDOW", unit: CalendarUnitSerializer.parse(json["unit"], decodePath(path, "unit")), }; }, serialize(value: SlidingWindowResetPeriod): any { return { - ...extraProperties(value, ["interval", "unit"]), + ...extraProperties(value, ["interval", "type", "unit"]), interval: value.interval, + type: value.type ?? "SLIDING_WINDOW", unit: CalendarUnitSerializer.serialize(value.unit), }; }, diff --git a/src/models/slotFee.ts b/src/models/slotFee.ts index 36fb81e..878b2c5 100644 --- a/src/models/slotFee.ts +++ b/src/models/slotFee.ts @@ -6,6 +6,7 @@ export interface SlotFee { initialSlots: number; maxSlots?: number | null | undefined; minSlots?: number | null | undefined; + type: "SLOT"; unit: string; unitRate: string; } @@ -19,6 +20,7 @@ export const SlotFeeSerializer = { "initial_slots", "max_slots", "min_slots", + "type", "unit", "unit_rate", ]), @@ -31,6 +33,10 @@ export const SlotFeeSerializer = { json["min_slots"] != null ? decodeInteger(json["min_slots"], path, "min_slots") : json["min_slots"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "SLOT") + : "SLOT", unit: decodeString(json["unit"], path, "unit"), unitRate: decodeString(json["unit_rate"], path, "unit_rate"), }; @@ -42,12 +48,14 @@ export const SlotFeeSerializer = { "initialSlots", "maxSlots", "minSlots", + "type", "unit", "unitRate", ]), initial_slots: value.initialSlots, max_slots: value.maxSlots, min_slots: value.minSlots, + type: value.type ?? "SLOT", unit: value.unit, unit_rate: value.unitRate, }; diff --git a/src/models/slotFeeStructure.ts b/src/models/slotFeeStructure.ts index bfb28f1..9fac41d 100644 --- a/src/models/slotFeeStructure.ts +++ b/src/models/slotFeeStructure.ts @@ -13,6 +13,7 @@ import { export interface SlotFeeStructure { downgradePolicy: SlotDowngradePolicyEnum; slotUnitName: string; + type: "SLOT"; upgradePolicy: SlotUpgradePolicyEnum; } @@ -21,12 +22,21 @@ export const SlotFeeStructureSerializer = { parse(json: any, path = "$"): SlotFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, ["downgrade_policy", "slot_unit_name", "upgrade_policy"]), + ...extraProperties(json, [ + "downgrade_policy", + "slot_unit_name", + "type", + "upgrade_policy", + ]), downgradePolicy: SlotDowngradePolicyEnumSerializer.parse( json["downgrade_policy"], decodePath(path, "downgrade_policy") ), slotUnitName: decodeString(json["slot_unit_name"], path, "slot_unit_name"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "SLOT") + : "SLOT", upgradePolicy: SlotUpgradePolicyEnumSerializer.parse( json["upgrade_policy"], decodePath(path, "upgrade_policy") @@ -36,11 +46,17 @@ export const SlotFeeStructureSerializer = { serialize(value: SlotFeeStructure): any { return { - ...extraProperties(value, ["downgradePolicy", "slotUnitName", "upgradePolicy"]), + ...extraProperties(value, [ + "downgradePolicy", + "slotUnitName", + "type", + "upgradePolicy", + ]), downgrade_policy: SlotDowngradePolicyEnumSerializer.serialize( value.downgradePolicy ), slot_unit_name: value.slotUnitName, + type: value.type ?? "SLOT", upgrade_policy: SlotUpgradePolicyEnumSerializer.serialize(value.upgradePolicy), }; }, diff --git a/src/models/slotPlanFee.ts b/src/models/slotPlanFee.ts index 4237ee0..b47b2d9 100644 --- a/src/models/slotPlanFee.ts +++ b/src/models/slotPlanFee.ts @@ -14,6 +14,7 @@ export interface SlotPlanFee { quota?: number | null | undefined; rates: TermRate[]; slotUnitName: string; + type: "SLOT"; } /** Converts `SlotPlanFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -21,7 +22,13 @@ export const SlotPlanFeeSerializer = { parse(json: any, path = "$"): SlotPlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["minimum_count", "quota", "rates", "slot_unit_name"]), + ...extraProperties(json, [ + "minimum_count", + "quota", + "rates", + "slot_unit_name", + "type", + ]), minimumCount: json["minimum_count"] != null ? decodeInteger(json["minimum_count"], path, "minimum_count") @@ -34,16 +41,27 @@ export const SlotPlanFeeSerializer = { TermRateSerializer.parse(item, decodePath(p, i)) ), slotUnitName: decodeString(json["slot_unit_name"], path, "slot_unit_name"), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "SLOT") + : "SLOT", }; }, serialize(value: SlotPlanFee): any { return { - ...extraProperties(value, ["minimumCount", "quota", "rates", "slotUnitName"]), + ...extraProperties(value, [ + "minimumCount", + "quota", + "rates", + "slotUnitName", + "type", + ]), minimum_count: value.minimumCount, quota: value.quota, rates: value.rates.map((item: any) => TermRateSerializer.serialize(item)), slot_unit_name: value.slotUnitName, + type: value.type ?? "SLOT", }; }, }; diff --git a/src/models/slotPricing.ts b/src/models/slotPricing.ts index 1e10897..a1901c4 100644 --- a/src/models/slotPricing.ts +++ b/src/models/slotPricing.ts @@ -5,6 +5,7 @@ import { decodeInteger, decodeObject, decodeString } from "../decode.js"; export interface SlotPricing { maxSlots?: number | null | undefined; minSlots?: number | null | undefined; + type: "SLOT"; unitRate: string; } @@ -13,7 +14,7 @@ export const SlotPricingSerializer = { parse(json: any, path = "$"): SlotPricing { decodeObject(json, path); return { - ...extraProperties(json, ["max_slots", "min_slots", "unit_rate"]), + ...extraProperties(json, ["max_slots", "min_slots", "type", "unit_rate"]), maxSlots: json["max_slots"] != null ? decodeInteger(json["max_slots"], path, "max_slots") @@ -22,15 +23,20 @@ export const SlotPricingSerializer = { json["min_slots"] != null ? decodeInteger(json["min_slots"], path, "min_slots") : json["min_slots"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "SLOT") + : "SLOT", unitRate: decodeString(json["unit_rate"], path, "unit_rate"), }; }, serialize(value: SlotPricing): any { return { - ...extraProperties(value, ["maxSlots", "minSlots", "unitRate"]), + ...extraProperties(value, ["maxSlots", "minSlots", "type", "unitRate"]), max_slots: value.maxSlots, min_slots: value.minSlots, + type: value.type ?? "SLOT", unit_rate: value.unitRate, }; }, diff --git a/src/models/subscription.ts b/src/models/subscription.ts index bd434de..ed002ae 100644 --- a/src/models/subscription.ts +++ b/src/models/subscription.ts @@ -25,6 +25,7 @@ import { type SubscriptionStatusEnum, SubscriptionStatusEnumSerializer, } from "./subscriptionStatusEnum.js"; +import { type UsageFilter, UsageFilterSerializer } from "./usageFilter.js"; export interface Subscription { /** When the subscription was activated (first payment or activation condition met) */ @@ -73,6 +74,12 @@ export interface Subscription { taxInclusive: boolean; /** Trial duration in days */ trialDuration?: number | null | undefined; + usageFilter?: UsageFilter | null | undefined; + /** + * When the current usage filter, or its removal, started to apply: the start of the usage + * neither this subscription nor the customer's others had invoiced when it was set. + */ + usageFilterEffectiveFrom?: Date | null | undefined; } /** Converts `Subscription` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -111,6 +118,8 @@ export const SubscriptionSerializer = { "status", "tax_inclusive", "trial_duration", + "usage_filter", + "usage_filter_effective_from", ]), activatedAt: json["activated_at"] != null @@ -203,6 +212,21 @@ export const SubscriptionSerializer = { json["trial_duration"] != null ? decodeInteger(json["trial_duration"], path, "trial_duration") : json["trial_duration"], + usageFilter: + json["usage_filter"] != null + ? UsageFilterSerializer.parse( + json["usage_filter"], + decodePath(path, "usage_filter") + ) + : json["usage_filter"], + usageFilterEffectiveFrom: + json["usage_filter_effective_from"] != null + ? decodeDateTime( + json["usage_filter_effective_from"], + path, + "usage_filter_effective_from" + ) + : json["usage_filter_effective_from"], }; }, @@ -239,6 +263,8 @@ export const SubscriptionSerializer = { "status", "taxInclusive", "trialDuration", + "usageFilter", + "usageFilterEffectiveFrom", ]), activated_at: value.activatedAt, auto_advance_invoices: value.autoAdvanceInvoices, @@ -273,6 +299,11 @@ export const SubscriptionSerializer = { status: SubscriptionStatusEnumSerializer.serialize(value.status), tax_inclusive: value.taxInclusive, trial_duration: value.trialDuration, + usage_filter: + value.usageFilter != null + ? UsageFilterSerializer.serialize(value.usageFilter) + : value.usageFilter, + usage_filter_effective_from: value.usageFilterEffectiveFrom, }; }, }; diff --git a/src/models/subscriptionAddOnParameterization.ts b/src/models/subscriptionAddOnParameterization.ts index a3d07ee..1b38e33 100644 --- a/src/models/subscriptionAddOnParameterization.ts +++ b/src/models/subscriptionAddOnParameterization.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeObject, decodePath } from "../decode.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillingPeriodEnum, BillingPeriodEnumSerializer, @@ -10,6 +10,7 @@ export interface SubscriptionAddOnParameterization { billingPeriod?: BillingPeriodEnum | null | undefined; committedCapacity?: number | null | undefined; initialSlotCount?: number | null | undefined; + type: "PARAMETERIZATION"; } /** Converts `SubscriptionAddOnParameterization` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -21,6 +22,7 @@ export const SubscriptionAddOnParameterizationSerializer = { "billing_period", "committed_capacity", "initial_slot_count", + "type", ]), billingPeriod: json["billing_period"] != null @@ -37,6 +39,10 @@ export const SubscriptionAddOnParameterizationSerializer = { json["initial_slot_count"] != null ? decodeInteger(json["initial_slot_count"], path, "initial_slot_count") : json["initial_slot_count"], + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PARAMETERIZATION") + : "PARAMETERIZATION", }; }, @@ -46,6 +52,7 @@ export const SubscriptionAddOnParameterizationSerializer = { "billingPeriod", "committedCapacity", "initialSlotCount", + "type", ]), billing_period: value.billingPeriod != null @@ -53,6 +60,7 @@ export const SubscriptionAddOnParameterizationSerializer = { : value.billingPeriod, committed_capacity: value.committedCapacity, initial_slot_count: value.initialSlotCount, + type: value.type ?? "PARAMETERIZATION", }; }, }; diff --git a/src/models/subscriptionAddOnPriceOverride.ts b/src/models/subscriptionAddOnPriceOverride.ts index 2cb4b58..c72377b 100644 --- a/src/models/subscriptionAddOnPriceOverride.ts +++ b/src/models/subscriptionAddOnPriceOverride.ts @@ -6,6 +6,7 @@ import { type PriceEntry, PriceEntrySerializer } from "./priceEntry.js"; export interface SubscriptionAddOnPriceOverride { name?: string | null | undefined; priceEntry: PriceEntry; + type: "PRICE_OVERRIDE"; } /** Converts `SubscriptionAddOnPriceOverride` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,21 +14,26 @@ export const SubscriptionAddOnPriceOverrideSerializer = { parse(json: any, path = "$"): SubscriptionAddOnPriceOverride { decodeObject(json, path); return { - ...extraProperties(json, ["name", "price_entry"]), + ...extraProperties(json, ["name", "price_entry", "type"]), name: json["name"] != null ? decodeString(json["name"], path, "name") : json["name"], priceEntry: PriceEntrySerializer.parse( json["price_entry"], decodePath(path, "price_entry") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "PRICE_OVERRIDE") + : "PRICE_OVERRIDE", }; }, serialize(value: SubscriptionAddOnPriceOverride): any { return { - ...extraProperties(value, ["name", "priceEntry"]), + ...extraProperties(value, ["name", "priceEntry", "type"]), name: value.name, price_entry: PriceEntrySerializer.serialize(value.priceEntry), + type: value.type ?? "PRICE_OVERRIDE", }; }, }; diff --git a/src/models/subscriptionCreateRequest.ts b/src/models/subscriptionCreateRequest.ts index d94109b..2267a75 100644 --- a/src/models/subscriptionCreateRequest.ts +++ b/src/models/subscriptionCreateRequest.ts @@ -25,6 +25,7 @@ import { type SubscriptionActivationConditionEnum, SubscriptionActivationConditionEnumSerializer, } from "./subscriptionActivationConditionEnum.js"; +import { type UsageFilter, UsageFilterSerializer } from "./usageFilter.js"; export interface SubscriptionCreateRequest { activationCondition: SubscriptionActivationConditionEnum; @@ -37,6 +38,12 @@ export interface SubscriptionCreateRequest { backdateInvoices?: boolean | undefined; billingDayAnchor?: number | null | undefined; chargeAutomatically?: boolean | undefined; + /** + * Codes of the coupons to apply. A code matches whatever the case of its ASCII letters; when + * several coupons differ from it only in that case, the one with exactly that code applies. A + * code that names no live coupon, or several differing only in case, refuses the request with + * 400 listing the codes (unknown codes used to be ignored silently). + */ couponCodes?: string[] | undefined; /** * User-defined custom property values, keyed by definition `key`. Validated against the @@ -59,6 +66,11 @@ export interface SubscriptionCreateRequest { skipPastInvoices?: boolean | undefined; startDate: string; trialDays?: number | undefined; + /** + * Bill only the customer's events whose property has this value. Omit to bill the events + * no usage filter of the customer's other subscriptions matches. + */ + usageFilter?: UsageFilter | undefined; version?: number | undefined; } @@ -87,6 +99,7 @@ export const SubscriptionCreateRequestSerializer = { "skip_past_invoices", "start_date", "trial_days", + "usage_filter", "version", ]), activationCondition: SubscriptionActivationConditionEnumSerializer.parse( @@ -174,6 +187,13 @@ export const SubscriptionCreateRequestSerializer = { json["trial_days"] != null ? decodeInteger(json["trial_days"], path, "trial_days") : undefined, + usageFilter: + json["usage_filter"] != null + ? UsageFilterSerializer.parse( + json["usage_filter"], + decodePath(path, "usage_filter") + ) + : undefined, version: json["version"] != null ? decodeInteger(json["version"], path, "version") @@ -203,6 +223,7 @@ export const SubscriptionCreateRequestSerializer = { "skipPastInvoices", "startDate", "trialDays", + "usageFilter", "version", ]), activation_condition: SubscriptionActivationConditionEnumSerializer.serialize( @@ -237,6 +258,10 @@ export const SubscriptionCreateRequestSerializer = { skip_past_invoices: value.skipPastInvoices, start_date: value.startDate, trial_days: value.trialDays, + usage_filter: + value.usageFilter != null + ? UsageFilterSerializer.serialize(value.usageFilter) + : undefined, version: value.version, }; }, diff --git a/src/models/subscriptionCredit.ts b/src/models/subscriptionCredit.ts new file mode 100644 index 0000000..60b8d7f --- /dev/null +++ b/src/models/subscriptionCredit.ts @@ -0,0 +1,33 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodeString } from "../decode.js"; +/** Credit on account that only one subscription can use. */ +export interface SubscriptionCredit { + /** In minor units of the wallet. */ + creditOnAccount: number; + subscriptionId: string; +} + +/** Converts `SubscriptionCredit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const SubscriptionCreditSerializer = { + parse(json: any, path = "$"): SubscriptionCredit { + decodeObject(json, path); + return { + ...extraProperties(json, ["credit_on_account", "subscription_id"]), + creditOnAccount: decodeInteger( + json["credit_on_account"], + path, + "credit_on_account" + ), + subscriptionId: decodeString(json["subscription_id"], path, "subscription_id"), + }; + }, + + serialize(value: SubscriptionCredit): any { + return { + ...extraProperties(value, ["creditOnAccount", "subscriptionId"]), + credit_on_account: value.creditOnAccount, + subscription_id: value.subscriptionId, + }; + }, +}; diff --git a/src/models/subscriptionDetails.ts b/src/models/subscriptionDetails.ts index 535a799..9e243e3 100644 --- a/src/models/subscriptionDetails.ts +++ b/src/models/subscriptionDetails.ts @@ -43,6 +43,7 @@ import { type SubscriptionStatusEnum, SubscriptionStatusEnumSerializer, } from "./subscriptionStatusEnum.js"; +import { type UsageFilter, UsageFilterSerializer } from "./usageFilter.js"; export interface SubscriptionDetails { /** When the subscription was activated (first payment or activation condition met) */ @@ -94,6 +95,12 @@ export interface SubscriptionDetails { taxInclusive: boolean; /** Trial duration in days */ trialDuration?: number | null | undefined; + usageFilter?: UsageFilter | null | undefined; + /** + * When the current usage filter, or its removal, started to apply: the start of the usage + * neither this subscription nor the customer's others had invoiced when it was set. + */ + usageFilterEffectiveFrom?: Date | null | undefined; } /** Converts `SubscriptionDetails` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -137,6 +144,8 @@ export const SubscriptionDetailsSerializer = { "status", "tax_inclusive", "trial_duration", + "usage_filter", + "usage_filter_effective_from", ]), activatedAt: json["activated_at"] != null @@ -267,6 +276,21 @@ export const SubscriptionDetailsSerializer = { json["trial_duration"] != null ? decodeInteger(json["trial_duration"], path, "trial_duration") : json["trial_duration"], + usageFilter: + json["usage_filter"] != null + ? UsageFilterSerializer.parse( + json["usage_filter"], + decodePath(path, "usage_filter") + ) + : json["usage_filter"], + usageFilterEffectiveFrom: + json["usage_filter_effective_from"] != null + ? decodeDateTime( + json["usage_filter_effective_from"], + path, + "usage_filter_effective_from" + ) + : json["usage_filter_effective_from"], }; }, @@ -308,6 +332,8 @@ export const SubscriptionDetailsSerializer = { "status", "taxInclusive", "trialDuration", + "usageFilter", + "usageFilterEffectiveFrom", ]), activated_at: value.activatedAt, add_ons: value.addOns.map((item: any) => @@ -359,6 +385,11 @@ export const SubscriptionDetailsSerializer = { status: SubscriptionStatusEnumSerializer.serialize(value.status), tax_inclusive: value.taxInclusive, trial_duration: value.trialDuration, + usage_filter: + value.usageFilter != null + ? UsageFilterSerializer.serialize(value.usageFilter) + : value.usageFilter, + usage_filter_effective_from: value.usageFilterEffectiveFrom, }; }, }; diff --git a/src/models/subscriptionFee.ts b/src/models/subscriptionFee.ts index 4844eef..11ba935 100644 --- a/src/models/subscriptionFee.ts +++ b/src/models/subscriptionFee.ts @@ -1,6 +1,7 @@ // this file is @generated import { decodeObject } from "../decode.js"; import { type CapacityFee, CapacityFeeSerializer } from "./capacityFee.js"; +import { type CreditFee, CreditFeeSerializer } from "./creditFee.js"; import { type OneTimeFee, OneTimeFeeSerializer } from "./oneTimeFee.js"; import { type RateFee, RateFeeSerializer } from "./rateFee.js"; import { type RecurringFee, RecurringFeeSerializer } from "./recurringFee.js"; @@ -25,6 +26,9 @@ export interface SubscriptionFeeSlot extends SlotFee { export interface SubscriptionFeeUsage extends UsageFee { type: "USAGE"; } +export interface SubscriptionFeeCredit extends CreditFee { + type: "CREDIT"; +} export type SubscriptionFee = | SubscriptionFeeRate @@ -32,7 +36,8 @@ export type SubscriptionFee = | SubscriptionFeeRecurring | SubscriptionFeeCapacity | SubscriptionFeeSlot - | SubscriptionFeeUsage; + | SubscriptionFeeUsage + | SubscriptionFeeCredit; /** Converts `SubscriptionFee` values from (`parse`) and to (`serialize`) their JSON form. */ export const SubscriptionFeeSerializer = { @@ -69,6 +74,11 @@ export const SubscriptionFeeSerializer = { ...UsageFeeSerializer.parse(json, path), type: "USAGE", }; + case "CREDIT": + return { + ...CreditFeeSerializer.parse(json, path), + type: "CREDIT", + }; default: // A variant added to the API after this SDK was generated, kept as received. return json; @@ -107,6 +117,11 @@ export const SubscriptionFeeSerializer = { ...UsageFeeSerializer.serialize(value), type: "USAGE", }; + case "CREDIT": + return { + ...CreditFeeSerializer.serialize(value), + type: "CREDIT", + }; default: return value; } diff --git a/src/models/subscriptionUpdateRequest.ts b/src/models/subscriptionUpdateRequest.ts index da4dfff..fdf5568 100644 --- a/src/models/subscriptionUpdateRequest.ts +++ b/src/models/subscriptionUpdateRequest.ts @@ -11,6 +11,7 @@ import { type PaymentMethodsConfig, PaymentMethodsConfigSerializer, } from "./paymentMethodsConfig.js"; +import { type UsageFilter, UsageFilterSerializer } from "./usageFilter.js"; export interface SubscriptionUpdateRequest { /** If false, invoices will stay in Draft until manually reviewed and finalized. */ @@ -29,6 +30,7 @@ export interface SubscriptionUpdateRequest { paymentMethodsConfig?: PaymentMethodsConfig | null | undefined; /** Purchase order number */ purchaseOrder?: string | null | undefined; + usageFilter?: UsageFilter | null | undefined; } /** Converts `SubscriptionUpdateRequest` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -44,6 +46,7 @@ export const SubscriptionUpdateRequestSerializer = { "net_terms", "payment_methods_config", "purchase_order", + "usage_filter", ]), autoAdvanceInvoices: json["auto_advance_invoices"] != null @@ -73,6 +76,13 @@ export const SubscriptionUpdateRequestSerializer = { json["purchase_order"] != null ? decodeString(json["purchase_order"], path, "purchase_order") : json["purchase_order"], + usageFilter: + json["usage_filter"] != null + ? UsageFilterSerializer.parse( + json["usage_filter"], + decodePath(path, "usage_filter") + ) + : json["usage_filter"], }; }, @@ -86,6 +96,7 @@ export const SubscriptionUpdateRequestSerializer = { "netTerms", "paymentMethodsConfig", "purchaseOrder", + "usageFilter", ]), auto_advance_invoices: value.autoAdvanceInvoices, charge_automatically: value.chargeAutomatically, @@ -97,6 +108,10 @@ export const SubscriptionUpdateRequestSerializer = { ? PaymentMethodsConfigSerializer.serialize(value.paymentMethodsConfig) : value.paymentMethodsConfig, purchase_order: value.purchaseOrder, + usage_filter: + value.usageFilter != null + ? UsageFilterSerializer.serialize(value.usageFilter) + : value.usageFilter, }; }, }; diff --git a/src/models/textConfigValue.ts b/src/models/textConfigValue.ts index 6800f52..350240c 100644 --- a/src/models/textConfigValue.ts +++ b/src/models/textConfigValue.ts @@ -3,6 +3,7 @@ import { extraProperties } from "../json.js"; import { decodeObject, decodeString } from "../decode.js"; /** A text config value. */ export interface TextConfigValue { + kind: "TEXT"; value: string; } @@ -11,14 +12,19 @@ export const TextConfigValueSerializer = { parse(json: any, path = "$"): TextConfigValue { decodeObject(json, path); return { - ...extraProperties(json, ["value"]), + ...extraProperties(json, ["kind", "value"]), + kind: + json["kind"] != null + ? (decodeString(json["kind"], path, "kind") as "TEXT") + : "TEXT", value: decodeString(json["value"], path, "value"), }; }, serialize(value: TextConfigValue): any { return { - ...extraProperties(value, ["value"]), + ...extraProperties(value, ["kind", "value"]), + kind: value.kind ?? "TEXT", value: value.value, }; }, diff --git a/src/models/tieredPlanPricing.ts b/src/models/tieredPlanPricing.ts index 5551852..f998b0d 100644 --- a/src/models/tieredPlanPricing.ts +++ b/src/models/tieredPlanPricing.ts @@ -1,11 +1,18 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeList, decodeObject, decodePath } from "../decode.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type TierRow, TierRowSerializer } from "./tierRow.js"; export interface TieredPlanPricing { blockSize?: number | null | undefined; tiers: TierRow[]; + type: "TIERED"; } /** Converts `TieredPlanPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,7 +20,7 @@ export const TieredPlanPricingSerializer = { parse(json: any, path = "$"): TieredPlanPricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "tiers"]), + ...extraProperties(json, ["block_size", "tiers", "type"]), blockSize: json["block_size"] != null ? decodeInteger(json["block_size"], path, "block_size") @@ -21,14 +28,19 @@ export const TieredPlanPricingSerializer = { tiers: decodeList(json["tiers"], path, "tiers", (item: any, p: string, i: number) => TierRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "TIERED") + : "TIERED", }; }, serialize(value: TieredPlanPricing): any { return { - ...extraProperties(value, ["blockSize", "tiers"]), + ...extraProperties(value, ["blockSize", "tiers", "type"]), block_size: value.blockSize, tiers: value.tiers.map((item: any) => TierRowSerializer.serialize(item)), + type: value.type ?? "TIERED", }; }, }; diff --git a/src/models/tieredPricing.ts b/src/models/tieredPricing.ts index b0cddc3..564f2ab 100644 --- a/src/models/tieredPricing.ts +++ b/src/models/tieredPricing.ts @@ -1,11 +1,18 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeList, decodeObject, decodePath } from "../decode.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type TierRow, TierRowSerializer } from "./tierRow.js"; export interface TieredPricing { blockSize?: number | null | undefined; tiers: TierRow[]; + type: "TIERED"; } /** Converts `TieredPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,7 +20,7 @@ export const TieredPricingSerializer = { parse(json: any, path = "$"): TieredPricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "tiers"]), + ...extraProperties(json, ["block_size", "tiers", "type"]), blockSize: json["block_size"] != null ? decodeInteger(json["block_size"], path, "block_size") @@ -21,14 +28,19 @@ export const TieredPricingSerializer = { tiers: decodeList(json["tiers"], path, "tiers", (item: any, p: string, i: number) => TierRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "TIERED") + : "TIERED", }; }, serialize(value: TieredPricing): any { return { - ...extraProperties(value, ["blockSize", "tiers"]), + ...extraProperties(value, ["blockSize", "tiers", "type"]), block_size: value.blockSize, tiers: value.tiers.map((item: any) => TierRowSerializer.serialize(item)), + type: value.type ?? "TIERED", }; }, }; diff --git a/src/models/topUpCollection.ts b/src/models/topUpCollection.ts new file mode 100644 index 0000000..8250e8e --- /dev/null +++ b/src/models/topUpCollection.ts @@ -0,0 +1,24 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** + * How a top-up is paid: CHARGE a saved payment method now, or SEND_INVOICE and grant the credit + * once the invoice is paid. + */ +export const TopUpCollection = { + Charge: "CHARGE", + SendInvoice: "SEND_INVOICE", +} as const; +export type TopUpCollection = + | (typeof TopUpCollection)[keyof typeof TopUpCollection] + | (string & {}); + +/** Converts `TopUpCollection` values from (`parse`) and to (`serialize`) their JSON form. */ +export const TopUpCollectionSerializer = { + parse(json: any, path = "$"): TopUpCollection { + return decodeString(json, path); + }, + + serialize(value: TopUpCollection): any { + return value; + }, +}; diff --git a/src/models/topUpResponse.ts b/src/models/topUpResponse.ts new file mode 100644 index 0000000..222f130 --- /dev/null +++ b/src/models/topUpResponse.ts @@ -0,0 +1,92 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { type TopUpStatus, TopUpStatusSerializer } from "./topUpStatus.js"; +/** Where a top-up stands. Its credit is granted once it is paid; `wallet.funded` reports it. */ +export interface TopUpResponse { + /** Credit bought, in minor units of `currency`, or of `credit_unit` when set. */ + amount: number; + /** + * Charged to the payment method, tax included, in minor units of `currency`; absent until a + * charge is made. + */ + chargedAmount?: number | null | undefined; + /** Hosted page where the customer completes the payment; present while it awaits them. */ + checkoutUrl?: string | null | undefined; + /** Set when credits of this credit unit were bought: `amount` is in its minor units. */ + creditUnit?: string | null | undefined; + /** The money the top-up is charged in. */ + currency: Currency; + /** The invoice documenting the purchase. */ + invoiceId?: string | null | undefined; + /** The charge made on the payment method; absent until a charge is made. */ + paymentTransactionId?: string | null | undefined; + /** SUCCEEDED once paid; otherwise what the payment is waiting for. */ + status: TopUpStatus; +} + +/** Converts `TopUpResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const TopUpResponseSerializer = { + parse(json: any, path = "$"): TopUpResponse { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "charged_amount", + "checkout_url", + "credit_unit", + "currency", + "invoice_id", + "payment_transaction_id", + "status", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + chargedAmount: + json["charged_amount"] != null + ? decodeInteger(json["charged_amount"], path, "charged_amount") + : json["charged_amount"], + checkoutUrl: + json["checkout_url"] != null + ? decodeString(json["checkout_url"], path, "checkout_url") + : json["checkout_url"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + currency: CurrencySerializer.parse(json["currency"], decodePath(path, "currency")), + invoiceId: + json["invoice_id"] != null + ? decodeString(json["invoice_id"], path, "invoice_id") + : json["invoice_id"], + paymentTransactionId: + json["payment_transaction_id"] != null + ? decodeString(json["payment_transaction_id"], path, "payment_transaction_id") + : json["payment_transaction_id"], + status: TopUpStatusSerializer.parse(json["status"], decodePath(path, "status")), + }; + }, + + serialize(value: TopUpResponse): any { + return { + ...extraProperties(value, [ + "amount", + "chargedAmount", + "checkoutUrl", + "creditUnit", + "currency", + "invoiceId", + "paymentTransactionId", + "status", + ]), + amount: value.amount, + charged_amount: value.chargedAmount, + checkout_url: value.checkoutUrl, + credit_unit: value.creditUnit, + currency: CurrencySerializer.serialize(value.currency), + invoice_id: value.invoiceId, + payment_transaction_id: value.paymentTransactionId, + status: TopUpStatusSerializer.serialize(value.status), + }; + }, +}; diff --git a/src/models/topUpStatus.ts b/src/models/topUpStatus.ts new file mode 100644 index 0000000..757d8c8 --- /dev/null +++ b/src/models/topUpStatus.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export const TopUpStatus = { + Succeeded: "SUCCEEDED", + Pending: "PENDING", + RequiresCustomerAction: "REQUIRES_CUSTOMER_ACTION", + AwaitingPayment: "AWAITING_PAYMENT", +} as const; +export type TopUpStatus = (typeof TopUpStatus)[keyof typeof TopUpStatus] | (string & {}); + +/** Converts `TopUpStatus` values from (`parse`) and to (`serialize`) their JSON form. */ +export const TopUpStatusSerializer = { + parse(json: any, path = "$"): TopUpStatus { + return decodeString(json, path); + }, + + serialize(value: TopUpStatus): any { + return value; + }, +}; diff --git a/src/models/transaction.ts b/src/models/transaction.ts index 30e1889..3dbff99 100644 --- a/src/models/transaction.ts +++ b/src/models/transaction.ts @@ -30,6 +30,11 @@ import { type ReversalKind, ReversalKindSerializer } from "./reversalKind.js"; export interface Transaction { amount: number; + /** + * On a PAYMENT: the part of `amount_reversed` lost to disputes or chargebacks. The invoice + * stays paid; only the rest of `amount_reversed` (a failed collection) reopens it. + */ + amountDisputed?: number | undefined; /** * On a PAYMENT: how much was voluntarily given back (the sum of its settled REFUND * children). The invoice stays paid — the Refund credit note is what reduces it. @@ -40,6 +45,11 @@ export interface Transaction { * dispute). This is what the invoice nets out, reopening it. */ amountReversed: number; + /** + * On a PAYMENT: what the provider withdrew above what the payment still held (refunded + * before). Never applied to the invoice or credit: contest it with the provider. + */ + amountReversedExcess?: number | undefined; creditNoteId?: CreditNoteId | null | undefined; currency: string; error?: string | null | undefined; @@ -64,8 +74,10 @@ export const TransactionSerializer = { return { ...extraProperties(json, [ "amount", + "amount_disputed", "amount_refunded", "amount_reversed", + "amount_reversed_excess", "credit_note_id", "currency", "error", @@ -82,8 +94,16 @@ export const TransactionSerializer = { "status", ]), amount: decodeInteger(json["amount"], path, "amount"), + amountDisputed: + json["amount_disputed"] != null + ? decodeInteger(json["amount_disputed"], path, "amount_disputed") + : undefined, amountRefunded: decodeInteger(json["amount_refunded"], path, "amount_refunded"), amountReversed: decodeInteger(json["amount_reversed"], path, "amount_reversed"), + amountReversedExcess: + json["amount_reversed_excess"] != null + ? decodeInteger(json["amount_reversed_excess"], path, "amount_reversed_excess") + : undefined, creditNoteId: json["credit_note_id"] != null ? CreditNoteIdSerializer.parse( @@ -159,8 +179,10 @@ export const TransactionSerializer = { return { ...extraProperties(value, [ "amount", + "amountDisputed", "amountRefunded", "amountReversed", + "amountReversedExcess", "creditNoteId", "currency", "error", @@ -177,8 +199,10 @@ export const TransactionSerializer = { "status", ]), amount: value.amount, + amount_disputed: value.amountDisputed, amount_refunded: value.amountRefunded, amount_reversed: value.amountReversed, + amount_reversed_excess: value.amountReversedExcess, credit_note_id: value.creditNoteId != null ? CreditNoteIdSerializer.serialize(value.creditNoteId) diff --git a/src/models/unattributedMetricUsage.ts b/src/models/unattributedMetricUsage.ts new file mode 100644 index 0000000..5c4c5f0 --- /dev/null +++ b/src/models/unattributedMetricUsage.ts @@ -0,0 +1,61 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; +/** + * A metric's usage over `[from, until)` that no subscription bills: it matches none of the + * usage filters of the subscriptions pricing the metric, and none of them bills without one. + */ +export interface UnattributedMetricUsage { + from: Date; + metricCode: string; + metricId: BillableMetricId; + metricName: string; + totalValue: string; + until: Date; +} + +/** Converts `UnattributedMetricUsage` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UnattributedMetricUsageSerializer = { + parse(json: any, path = "$"): UnattributedMetricUsage { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "from", + "metric_code", + "metric_id", + "metric_name", + "total_value", + "until", + ]), + from: decodeDateTime(json["from"], path, "from"), + metricCode: decodeString(json["metric_code"], path, "metric_code"), + metricId: BillableMetricIdSerializer.parse( + json["metric_id"], + decodePath(path, "metric_id") + ), + metricName: decodeString(json["metric_name"], path, "metric_name"), + totalValue: decodeString(json["total_value"], path, "total_value"), + until: decodeDateTime(json["until"], path, "until"), + }; + }, + + serialize(value: UnattributedMetricUsage): any { + return { + ...extraProperties(value, [ + "from", + "metricCode", + "metricId", + "metricName", + "totalValue", + "until", + ]), + from: value.from, + metric_code: value.metricCode, + metric_id: BillableMetricIdSerializer.serialize(value.metricId), + metric_name: value.metricName, + total_value: value.totalValue, + until: value.until, + }; + }, +}; diff --git a/src/models/unattributedUsageResponse.ts b/src/models/unattributedUsageResponse.ts new file mode 100644 index 0000000..e3d96fb --- /dev/null +++ b/src/models/unattributedUsageResponse.ts @@ -0,0 +1,39 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + type UnattributedMetricUsage, + UnattributedMetricUsageSerializer, +} from "./unattributedMetricUsage.js"; + +export interface UnattributedUsageResponse { + periodEnd: string; + periodStart: string; + usage: UnattributedMetricUsage[]; +} + +/** Converts `UnattributedUsageResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UnattributedUsageResponseSerializer = { + parse(json: any, path = "$"): UnattributedUsageResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["period_end", "period_start", "usage"]), + periodEnd: decodeString(json["period_end"], path, "period_end"), + periodStart: decodeString(json["period_start"], path, "period_start"), + usage: decodeList(json["usage"], path, "usage", (item: any, p: string, i: number) => + UnattributedMetricUsageSerializer.parse(item, decodePath(p, i)) + ), + }; + }, + + serialize(value: UnattributedUsageResponse): any { + return { + ...extraProperties(value, ["periodEnd", "periodStart", "usage"]), + period_end: value.periodEnd, + period_start: value.periodStart, + usage: value.usage.map((item: any) => + UnattributedMetricUsageSerializer.serialize(item) + ), + }; + }, +}; diff --git a/src/models/unitConversion.ts b/src/models/unitConversion.ts index 1434130..a8e56bd 100644 --- a/src/models/unitConversion.ts +++ b/src/models/unitConversion.ts @@ -5,8 +5,14 @@ import { type UnitConversionRoundingEnum, UnitConversionRoundingEnumSerializer, } from "./unitConversionRoundingEnum.js"; - +/** + * Converts the aggregated usage into the unit prices are set in, e.g. tokens priced per 1M. + * The usage is divided by `factor`, then rounded. Rounding applies to each priced group's + * total for the billing period: each group of a segmented or grouped metric, and each matrix + * cell, is rounded on its own, never each event. + */ export interface UnitConversion { + /** Raw units per priced unit, e.g. `1000000` to price per 1M. */ factor: number; rounding: UnitConversionRoundingEnum; } diff --git a/src/models/updateMetricRequest.ts b/src/models/updateMetricRequest.ts index e8bb35f..7eb9007 100644 --- a/src/models/updateMetricRequest.ts +++ b/src/models/updateMetricRequest.ts @@ -15,6 +15,14 @@ export interface UpdateMetricRequest { name?: string | null | undefined; segmentationMatrix?: MetricSegmentationMatrix | null | undefined; unitConversion?: UnitConversion | null | undefined; + /** What several units of the metric are called, e.g. `tokens`. See `unit_singular`. */ + unitPlural?: string | null | undefined; + /** + * What one unit of the metric is called, e.g. `token`. Send `unit_singular` and + * `unit_plural` together; omit both to leave the label unchanged, or send both as empty + * strings to remove it. Trimmed; at most 32 characters. + */ + unitSingular?: string | null | undefined; } /** Converts `UpdateMetricRequest` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -28,6 +36,8 @@ export const UpdateMetricRequestSerializer = { "name", "segmentation_matrix", "unit_conversion", + "unit_plural", + "unit_singular", ]), description: json["description"] != null @@ -59,6 +69,14 @@ export const UpdateMetricRequestSerializer = { decodePath(path, "unit_conversion") ) : json["unit_conversion"], + unitPlural: + json["unit_plural"] != null + ? decodeString(json["unit_plural"], path, "unit_plural") + : json["unit_plural"], + unitSingular: + json["unit_singular"] != null + ? decodeString(json["unit_singular"], path, "unit_singular") + : json["unit_singular"], }; }, @@ -70,6 +88,8 @@ export const UpdateMetricRequestSerializer = { "name", "segmentationMatrix", "unitConversion", + "unitPlural", + "unitSingular", ]), description: value.description, filters: @@ -85,6 +105,8 @@ export const UpdateMetricRequestSerializer = { value.unitConversion != null ? UnitConversionSerializer.serialize(value.unitConversion) : value.unitConversion, + unit_plural: value.unitPlural, + unit_singular: value.unitSingular, }; }, }; diff --git a/src/models/updateWebhookEndpointRequest.ts b/src/models/updateWebhookEndpointRequest.ts index 5723452..2a34a17 100644 --- a/src/models/updateWebhookEndpointRequest.ts +++ b/src/models/updateWebhookEndpointRequest.ts @@ -18,7 +18,10 @@ export interface UpdateWebhookEndpointRequest { description?: string | null | undefined; /** Re-enabling an endpoint also resets its consecutive failure count. */ disabled?: boolean | null | undefined; - /** Replaces the subscription list. An empty array subscribes to every event type. */ + /** + * Replaces the subscription list. An empty array subscribes to every event type except Beta + * ones, which are sent only to endpoints that list them. + */ eventTypes?: string[] | null | undefined; /** Replaces the custom header list. An empty array removes every header. */ headers?: WebhookHeaderInput[] | null | undefined; diff --git a/src/models/usageAtZero.ts b/src/models/usageAtZero.ts new file mode 100644 index 0000000..224bbdf --- /dev/null +++ b/src/models/usageAtZero.ts @@ -0,0 +1,23 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** + * What a customer's usage does once the credit it can use runs out: what the subscription's plan + * says (`FOLLOW_PLAN`), or always or never refused for this customer. + */ +export const UsageAtZero = { + FollowPlan: "FOLLOW_PLAN", + AlwaysPause: "ALWAYS_PAUSE", + NeverPause: "NEVER_PAUSE", +} as const; +export type UsageAtZero = (typeof UsageAtZero)[keyof typeof UsageAtZero] | (string & {}); + +/** Converts `UsageAtZero` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageAtZeroSerializer = { + parse(json: any, path = "$"): UsageAtZero { + return decodeString(json, path); + }, + + serialize(value: UsageAtZero): any { + return value; + }, +}; diff --git a/src/models/usageCost.ts b/src/models/usageCost.ts new file mode 100644 index 0000000..8ec0aa7 --- /dev/null +++ b/src/models/usageCost.ts @@ -0,0 +1,36 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; +import { type UsageCostUnit, UsageCostUnitSerializer } from "./usageCostUnit.js"; +/** + * Usage priced as its invoice line prices it, before discounts and credits: tax-inclusive when + * the subscription's prices are. + */ +export interface UsageCost { + amount: string; + /** A currency code, or a credit unit code when `unit` is `CREDIT_UNIT`. */ + currency: string; + unit: UsageCostUnit; +} + +/** Converts `UsageCost` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageCostSerializer = { + parse(json: any, path = "$"): UsageCost { + decodeObject(json, path); + return { + ...extraProperties(json, ["amount", "currency", "unit"]), + amount: decodeString(json["amount"], path, "amount"), + currency: decodeString(json["currency"], path, "currency"), + unit: UsageCostUnitSerializer.parse(json["unit"], decodePath(path, "unit")), + }; + }, + + serialize(value: UsageCost): any { + return { + ...extraProperties(value, ["amount", "currency", "unit"]), + amount: value.amount, + currency: value.currency, + unit: UsageCostUnitSerializer.serialize(value.unit), + }; + }, +}; diff --git a/src/models/usageCostListResponse.ts b/src/models/usageCostListResponse.ts new file mode 100644 index 0000000..680ed9a --- /dev/null +++ b/src/models/usageCostListResponse.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type UsageCostRow, UsageCostRowSerializer } from "./usageCostRow.js"; + +export interface UsageCostListResponse { + data: UsageCostRow[]; +} + +/** Converts `UsageCostListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageCostListResponseSerializer = { + parse(json: any, path = "$"): UsageCostListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + UsageCostRowSerializer.parse(item, decodePath(p, i)) + ), + }; + }, + + serialize(value: UsageCostListResponse): any { + return { + ...extraProperties(value, ["data"]), + data: value.data.map((item: any) => UsageCostRowSerializer.serialize(item)), + }; + }, +}; diff --git a/src/models/usageCostRow.ts b/src/models/usageCostRow.ts new file mode 100644 index 0000000..6ea2901 --- /dev/null +++ b/src/models/usageCostRow.ts @@ -0,0 +1,59 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type UsageCost, UsageCostSerializer } from "./usageCost.js"; + +export interface UsageCostRow { + bucketStart: Date; + cost?: UsageCost | null | undefined; + /** + * False when the price depends on the whole period's usage (tiered, volume, package, + * capacity): the cost is then what the bucket adds to the period's price so far. A period's + * rows still add up to its invoiced amount. + */ + exact: boolean; + /** + * The value of `group_by` for the row. Absent when the request is not grouped, or the usage + * has no value for the property. + */ + group?: string | null | undefined; + quantity: string; +} + +/** Converts `UsageCostRow` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageCostRowSerializer = { + parse(json: any, path = "$"): UsageCostRow { + decodeObject(json, path); + return { + ...extraProperties(json, ["bucket_start", "cost", "exact", "group", "quantity"]), + bucketStart: decodeDateTime(json["bucket_start"], path, "bucket_start"), + cost: + json["cost"] != null + ? UsageCostSerializer.parse(json["cost"], decodePath(path, "cost")) + : json["cost"], + exact: decodeBoolean(json["exact"], path, "exact"), + group: + json["group"] != null + ? decodeString(json["group"], path, "group") + : json["group"], + quantity: decodeString(json["quantity"], path, "quantity"), + }; + }, + + serialize(value: UsageCostRow): any { + return { + ...extraProperties(value, ["bucketStart", "cost", "exact", "group", "quantity"]), + bucket_start: value.bucketStart, + cost: value.cost != null ? UsageCostSerializer.serialize(value.cost) : value.cost, + exact: value.exact, + group: value.group, + quantity: value.quantity, + }; + }, +}; diff --git a/src/models/usageCostUnit.ts b/src/models/usageCostUnit.ts new file mode 100644 index 0000000..a162f79 --- /dev/null +++ b/src/models/usageCostUnit.ts @@ -0,0 +1,21 @@ +// this file is @generated +import { decodeString } from "../decode.js"; +/** What a cost is counted in. */ +export const UsageCostUnit = { + Currency: "CURRENCY", + CreditUnit: "CREDIT_UNIT", +} as const; +export type UsageCostUnit = + | (typeof UsageCostUnit)[keyof typeof UsageCostUnit] + | (string & {}); + +/** Converts `UsageCostUnit` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageCostUnitSerializer = { + parse(json: any, path = "$"): UsageCostUnit { + return decodeString(json, path); + }, + + serialize(value: UsageCostUnit): any { + return value; + }, +}; diff --git a/src/models/usageEvent.ts b/src/models/usageEvent.ts new file mode 100644 index 0000000..623d7a4 --- /dev/null +++ b/src/models/usageEvent.ts @@ -0,0 +1,59 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeDateTime, + decodeMap, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type UsageCost, UsageCostSerializer } from "./usageCost.js"; + +export interface UsageEvent { + cost?: UsageCost | null | undefined; + id: string; + properties: { [key: string]: string }; + /** + * Billed units the event adds. Absent when the metric's aggregation cannot be split per + * event, or when the event does not count towards the metric. + */ + quantity?: string | null | undefined; + timestamp: Date; +} + +/** Converts `UsageEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageEventSerializer = { + parse(json: any, path = "$"): UsageEvent { + decodeObject(json, path); + return { + ...extraProperties(json, ["cost", "id", "properties", "quantity", "timestamp"]), + cost: + json["cost"] != null + ? UsageCostSerializer.parse(json["cost"], decodePath(path, "cost")) + : json["cost"], + id: decodeString(json["id"], path, "id"), + properties: decodeMap( + json["properties"], + path, + "properties", + (entry: any, p: string, key: string) => decodeString(entry, p, key) + ), + quantity: + json["quantity"] != null + ? decodeString(json["quantity"], path, "quantity") + : json["quantity"], + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + }; + }, + + serialize(value: UsageEvent): any { + return { + ...extraProperties(value, ["cost", "id", "properties", "quantity", "timestamp"]), + cost: value.cost != null ? UsageCostSerializer.serialize(value.cost) : value.cost, + id: value.id, + properties: value.properties, + quantity: value.quantity, + timestamp: value.timestamp, + }; + }, +}; diff --git a/src/models/usageEventListResponse.ts b/src/models/usageEventListResponse.ts new file mode 100644 index 0000000..5e1e932 --- /dev/null +++ b/src/models/usageEventListResponse.ts @@ -0,0 +1,35 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type UsageEvent, UsageEventSerializer } from "./usageEvent.js"; + +export interface UsageEventListResponse { + data: UsageEvent[]; + /** Absent on the last page. */ + nextCursor?: string | null | undefined; +} + +/** Converts `UsageEventListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageEventListResponseSerializer = { + parse(json: any, path = "$"): UsageEventListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data", "next_cursor"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + UsageEventSerializer.parse(item, decodePath(p, i)) + ), + nextCursor: + json["next_cursor"] != null + ? decodeString(json["next_cursor"], path, "next_cursor") + : json["next_cursor"], + }; + }, + + serialize(value: UsageEventListResponse): any { + return { + ...extraProperties(value, ["data", "nextCursor"]), + data: value.data.map((item: any) => UsageEventSerializer.serialize(item)), + next_cursor: value.nextCursor, + }; + }, +}; diff --git a/src/models/usageFee.ts b/src/models/usageFee.ts index 402e940..d8b871d 100644 --- a/src/models/usageFee.ts +++ b/src/models/usageFee.ts @@ -1,15 +1,18 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; +import { type FeeCreditUnit, FeeCreditUnitSerializer } from "./feeCreditUnit.js"; import { type UsagePricingModel, UsagePricingModelSerializer, } from "./usagePricingModel.js"; export interface UsageFee { + creditUnit?: FeeCreditUnit | null | undefined; metricId: BillableMetricId; model: UsagePricingModel; + type: "USAGE"; } /** Converts `UsageFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -17,20 +20,36 @@ export const UsageFeeSerializer = { parse(json: any, path = "$"): UsageFee { decodeObject(json, path); return { - ...extraProperties(json, ["metric_id", "model"]), + ...extraProperties(json, ["credit_unit", "metric_id", "model", "type"]), + creditUnit: + json["credit_unit"] != null + ? FeeCreditUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") ), model: UsagePricingModelSerializer.parse(json["model"], decodePath(path, "model")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "USAGE") + : "USAGE", }; }, serialize(value: UsageFee): any { return { - ...extraProperties(value, ["metricId", "model"]), + ...extraProperties(value, ["creditUnit", "metricId", "model", "type"]), + credit_unit: + value.creditUnit != null + ? FeeCreditUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, metric_id: BillableMetricIdSerializer.serialize(value.metricId), model: UsagePricingModelSerializer.serialize(value.model), + type: value.type ?? "USAGE", }; }, }; diff --git a/src/models/usageFeeStructure.ts b/src/models/usageFeeStructure.ts index 0cd0ab9..dea4a5d 100644 --- a/src/models/usageFeeStructure.ts +++ b/src/models/usageFeeStructure.ts @@ -1,12 +1,13 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; import { type UsageModelEnum, UsageModelEnumSerializer } from "./usageModelEnum.js"; export interface UsageFeeStructure { metricId: BillableMetricId; model: UsageModelEnum; + type: "USAGE"; } /** Converts `UsageFeeStructure` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -14,20 +15,25 @@ export const UsageFeeStructureSerializer = { parse(json: any, path = "$"): UsageFeeStructure { decodeObject(json, path); return { - ...extraProperties(json, ["metric_id", "model"]), + ...extraProperties(json, ["metric_id", "model", "type"]), metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") ), model: UsageModelEnumSerializer.parse(json["model"], decodePath(path, "model")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "USAGE") + : "USAGE", }; }, serialize(value: UsageFeeStructure): any { return { - ...extraProperties(value, ["metricId", "model"]), + ...extraProperties(value, ["metricId", "model", "type"]), metric_id: BillableMetricIdSerializer.serialize(value.metricId), model: UsageModelEnumSerializer.serialize(value.model), + type: value.type ?? "USAGE", }; }, }; diff --git a/src/models/usageFilter.ts b/src/models/usageFilter.ts new file mode 100644 index 0000000..756b875 --- /dev/null +++ b/src/models/usageFilter.ts @@ -0,0 +1,38 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeObject, decodeString } from "../decode.js"; +/** + * Restricts the customer's usage events a subscription bills to those whose `property` equals + * `value` (for example `api_key` = `key-A`). Among the customer's subscriptions pricing the same + * metric, one with a usage filter bills the events matching it (an event two filters match goes + * to the older subscription); one without bills the events matching no other subscription's + * filter. Two subscriptions without a usage filter both bill every such event. Events matching + * no filter while every subscription pricing their metric has one are billed by none and + * reported as unattributed usage. + */ +export interface UsageFilter { + /** Event property name, e.g. `api_key`. */ + property: string; + /** Value the property must have. */ + value: string; +} + +/** Converts `UsageFilter` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageFilterSerializer = { + parse(json: any, path = "$"): UsageFilter { + decodeObject(json, path); + return { + ...extraProperties(json, ["property", "value"]), + property: decodeString(json["property"], path, "property"), + value: decodeString(json["value"], path, "value"), + }; + }, + + serialize(value: UsageFilter): any { + return { + ...extraProperties(value, ["property", "value"]), + property: value.property, + value: value.value, + }; + }, +}; diff --git a/src/models/usageLimitId.ts b/src/models/usageLimitId.ts new file mode 100644 index 0000000..150f5a6 --- /dev/null +++ b/src/models/usageLimitId.ts @@ -0,0 +1,15 @@ +// this file is @generated +import { decodeString } from "../decode.js"; + +export type UsageLimitId = string; + +/** Converts `UsageLimitId` values from (`parse`) and to (`serialize`) their JSON form. */ +export const UsageLimitIdSerializer = { + parse(json: any, path = "$"): UsageLimitId { + return decodeString(json, path); + }, + + serialize(value: UsageLimitId): any { + return value; + }, +}; diff --git a/src/models/usagePlanFee.ts b/src/models/usagePlanFee.ts index e0d6b67..f31d952 100644 --- a/src/models/usagePlanFee.ts +++ b/src/models/usagePlanFee.ts @@ -1,11 +1,15 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type BillableMetricId, BillableMetricIdSerializer } from "./billableMetricId.js"; import { type BillingPeriodEnum, BillingPeriodEnumSerializer, } from "./billingPeriodEnum.js"; +import { + type PlanFeeCreditUnit, + PlanFeeCreditUnitSerializer, +} from "./planFeeCreditUnit.js"; import { type PlanUsagePricingModel, PlanUsagePricingModelSerializer, @@ -13,8 +17,10 @@ import { /** Usage-based fee */ export interface UsagePlanFee { cadence: BillingPeriodEnum; + creditUnit?: PlanFeeCreditUnit | null | undefined; metricId: BillableMetricId; pricing: PlanUsagePricingModel; + type: "USAGE"; } /** Converts `UsagePlanFee` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -22,11 +28,24 @@ export const UsagePlanFeeSerializer = { parse(json: any, path = "$"): UsagePlanFee { decodeObject(json, path); return { - ...extraProperties(json, ["cadence", "metric_id", "pricing"]), + ...extraProperties(json, [ + "cadence", + "credit_unit", + "metric_id", + "pricing", + "type", + ]), cadence: BillingPeriodEnumSerializer.parse( json["cadence"], decodePath(path, "cadence") ), + creditUnit: + json["credit_unit"] != null + ? PlanFeeCreditUnitSerializer.parse( + json["credit_unit"], + decodePath(path, "credit_unit") + ) + : json["credit_unit"], metricId: BillableMetricIdSerializer.parse( json["metric_id"], decodePath(path, "metric_id") @@ -35,15 +54,24 @@ export const UsagePlanFeeSerializer = { json["pricing"], decodePath(path, "pricing") ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "USAGE") + : "USAGE", }; }, serialize(value: UsagePlanFee): any { return { - ...extraProperties(value, ["cadence", "metricId", "pricing"]), + ...extraProperties(value, ["cadence", "creditUnit", "metricId", "pricing", "type"]), cadence: BillingPeriodEnumSerializer.serialize(value.cadence), + credit_unit: + value.creditUnit != null + ? PlanFeeCreditUnitSerializer.serialize(value.creditUnit) + : value.creditUnit, metric_id: BillableMetricIdSerializer.serialize(value.metricId), pricing: PlanUsagePricingModelSerializer.serialize(value.pricing), + type: value.type ?? "USAGE", }; }, }; diff --git a/src/models/usagePricing.ts b/src/models/usagePricing.ts index 363a083..aa01759 100644 --- a/src/models/usagePricing.ts +++ b/src/models/usagePricing.ts @@ -1,6 +1,6 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeObject, decodePath } from "../decode.js"; +import { decodeObject, decodePath, decodeString } from "../decode.js"; import { type UsagePricingModel, UsagePricingModelSerializer, @@ -8,6 +8,7 @@ import { export interface UsagePricing { model: UsagePricingModel; + type: "USAGE"; } /** Converts `UsagePricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -15,15 +16,20 @@ export const UsagePricingSerializer = { parse(json: any, path = "$"): UsagePricing { decodeObject(json, path); return { - ...extraProperties(json, ["model"]), + ...extraProperties(json, ["model", "type"]), model: UsagePricingModelSerializer.parse(json["model"], decodePath(path, "model")), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "USAGE") + : "USAGE", }; }, serialize(value: UsagePricing): any { return { - ...extraProperties(value, ["model"]), + ...extraProperties(value, ["model", "type"]), model: UsagePricingModelSerializer.serialize(value.model), + type: value.type ?? "USAGE", }; }, }; diff --git a/src/models/usageResponse.ts b/src/models/usageResponse.ts index 7298b49..96f1e77 100644 --- a/src/models/usageResponse.ts +++ b/src/models/usageResponse.ts @@ -1,11 +1,26 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeList, decodeObject, decodePath, decodeString } from "../decode.js"; +import { + decodeDateTime, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type MetricUsage, MetricUsageSerializer } from "./metricUsage.js"; +import { type UsageCost, UsageCostSerializer } from "./usageCost.js"; export interface UsageResponse { + /** + * Beta: when `totals` and the metrics' `costs` were computed. These are present only when a + * subscription's current billing period is read (no `start_date` nor `end_date`) and its + * usage could be priced. + */ + computedAt?: Date | null | undefined; periodEnd: string; periodStart: string; + /** Beta: the sum of the metrics' `costs`, per currency or credit unit. */ + totals?: UsageCost[] | null | undefined; usage: MetricUsage[]; } @@ -14,9 +29,29 @@ export const UsageResponseSerializer = { parse(json: any, path = "$"): UsageResponse { decodeObject(json, path); return { - ...extraProperties(json, ["period_end", "period_start", "usage"]), + ...extraProperties(json, [ + "computed_at", + "period_end", + "period_start", + "totals", + "usage", + ]), + computedAt: + json["computed_at"] != null + ? decodeDateTime(json["computed_at"], path, "computed_at") + : json["computed_at"], periodEnd: decodeString(json["period_end"], path, "period_end"), periodStart: decodeString(json["period_start"], path, "period_start"), + totals: + json["totals"] != null + ? decodeList( + json["totals"], + path, + "totals", + (item: any, p: string, i: number) => + UsageCostSerializer.parse(item, decodePath(p, i)) + ) + : json["totals"], usage: decodeList(json["usage"], path, "usage", (item: any, p: string, i: number) => MetricUsageSerializer.parse(item, decodePath(p, i)) ), @@ -25,9 +60,20 @@ export const UsageResponseSerializer = { serialize(value: UsageResponse): any { return { - ...extraProperties(value, ["periodEnd", "periodStart", "usage"]), + ...extraProperties(value, [ + "computedAt", + "periodEnd", + "periodStart", + "totals", + "usage", + ]), + computed_at: value.computedAt, period_end: value.periodEnd, period_start: value.periodStart, + totals: + value.totals != null + ? value.totals.map((item: any) => UsageCostSerializer.serialize(item)) + : value.totals, usage: value.usage.map((item: any) => MetricUsageSerializer.serialize(item)), }; }, diff --git a/src/models/volumePlanPricing.ts b/src/models/volumePlanPricing.ts index 2393c99..394b1a9 100644 --- a/src/models/volumePlanPricing.ts +++ b/src/models/volumePlanPricing.ts @@ -1,11 +1,18 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeList, decodeObject, decodePath } from "../decode.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type TierRow, TierRowSerializer } from "./tierRow.js"; export interface VolumePlanPricing { blockSize?: number | null | undefined; tiers: TierRow[]; + type: "VOLUME"; } /** Converts `VolumePlanPricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,7 +20,7 @@ export const VolumePlanPricingSerializer = { parse(json: any, path = "$"): VolumePlanPricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "tiers"]), + ...extraProperties(json, ["block_size", "tiers", "type"]), blockSize: json["block_size"] != null ? decodeInteger(json["block_size"], path, "block_size") @@ -21,14 +28,19 @@ export const VolumePlanPricingSerializer = { tiers: decodeList(json["tiers"], path, "tiers", (item: any, p: string, i: number) => TierRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "VOLUME") + : "VOLUME", }; }, serialize(value: VolumePlanPricing): any { return { - ...extraProperties(value, ["blockSize", "tiers"]), + ...extraProperties(value, ["blockSize", "tiers", "type"]), block_size: value.blockSize, tiers: value.tiers.map((item: any) => TierRowSerializer.serialize(item)), + type: value.type ?? "VOLUME", }; }, }; diff --git a/src/models/volumePricing.ts b/src/models/volumePricing.ts index 84904d0..8dd57f9 100644 --- a/src/models/volumePricing.ts +++ b/src/models/volumePricing.ts @@ -1,11 +1,18 @@ // this file is @generated import { extraProperties } from "../json.js"; -import { decodeInteger, decodeList, decodeObject, decodePath } from "../decode.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; import { type TierRow, TierRowSerializer } from "./tierRow.js"; export interface VolumePricing { blockSize?: number | null | undefined; tiers: TierRow[]; + type: "VOLUME"; } /** Converts `VolumePricing` values from (`parse`) and to (`serialize`) their JSON form. */ @@ -13,7 +20,7 @@ export const VolumePricingSerializer = { parse(json: any, path = "$"): VolumePricing { decodeObject(json, path); return { - ...extraProperties(json, ["block_size", "tiers"]), + ...extraProperties(json, ["block_size", "tiers", "type"]), blockSize: json["block_size"] != null ? decodeInteger(json["block_size"], path, "block_size") @@ -21,14 +28,19 @@ export const VolumePricingSerializer = { tiers: decodeList(json["tiers"], path, "tiers", (item: any, p: string, i: number) => TierRowSerializer.parse(item, decodePath(p, i)) ), + type: + json["type"] != null + ? (decodeString(json["type"], path, "type") as "VOLUME") + : "VOLUME", }; }, serialize(value: VolumePricing): any { return { - ...extraProperties(value, ["blockSize", "tiers"]), + ...extraProperties(value, ["blockSize", "tiers", "type"]), block_size: value.blockSize, tiers: value.tiers.map((item: any) => TierRowSerializer.serialize(item)), + type: value.type ?? "VOLUME", }; }, }; diff --git a/src/models/wallet.ts b/src/models/wallet.ts new file mode 100644 index 0000000..30d0c9c --- /dev/null +++ b/src/models/wallet.ts @@ -0,0 +1,256 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type AutoTopUp, AutoTopUpSerializer } from "./autoTopUp.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +import { + type SubscriptionCredit, + SubscriptionCreditSerializer, +} from "./subscriptionCredit.js"; +import { type UsageAtZero, UsageAtZeroSerializer } from "./usageAtZero.js"; +/** + * A customer's credit in one currency or credit unit. Amounts are minor units of it. Read with + * `subscription_id`, every amount counts only the credit that subscription can use. + */ +export interface Wallet { + /** + * When `balance` and `unbilled_usage` were computed. They follow usage within a few seconds + * while the balance is near zero or a threshold, and within a minute otherwise. + */ + asOf?: Date | null | undefined; + autoTopUp?: AutoTopUp | null | undefined; + /** + * What the customer has left: `credit_on_account` minus the part of `unbilled_usage` that + * credit will pay. Never negative: usage beyond the credit stays in `unbilled_usage`, to be + * invoiced. Low-balance alerts use it; automatic top-ups watch only its part that pays any + * charge (credit that belongs to no subscription and is not limited to usage or products). + * Absent, with `unbilled_usage` and `as_of`, until the customer's usage has been priced once. + * With `subscription_id`: the credit that subscription can spend once every subscription's + * unbilled usage is paid, minus its own unbilled usage no credit pays (negative then), as + * `GET /wallets/check` reads it. Credit restricted to products it is not charged for is + * left out. Credit that belongs to no subscription counts in the balance of every + * subscription that can use it (see `shared_balance`): never add subscriptions' balances up. + */ + balance?: number | null | undefined; + /** + * The ledger total: credit granted and effective, not yet applied to an invoice or expired, + * whatever it applies to. Usage not invoiced yet is not deducted (see `balance`). + */ + creditOnAccount: number; + /** The part of `credit_on_account` that pays only usage charges. */ + creditOnAccountUsageOnly: number; + /** The credit unit (its code) the wallet holds; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + currency?: Currency | null | undefined; + /** + * Ascending, distinct, at most 5. `wallet.balance_low` fires once when `balance` falls below + * one; a drop below several at once fires once, for the lowest. All credit counts, including + * credit that belongs to a subscription or is limited to usage or products, which + * `wallet.depleted` leaves out: a wallet can be depleted without an alert firing. + */ + lowBalanceThresholds: number[]; + /** + * Usage stops as soon as the credit is used up, for at least one active subscription: by + * `usage_at_zero`, or by the plan of a subscription charging usage in this wallet. + */ + pausesAtZero: boolean; + /** + * With `subscription_id` only: the part of `balance` that belongs to no subscription, which + * the customer's other subscriptions can spend too. + */ + sharedBalance?: number | null | undefined; + /** + * The part of `credit_on_account` that belongs to a subscription, which only that + * subscription's charges can use, per subscription. The rest pays any subscription. + */ + subscriptionCredit: SubscriptionCredit[]; + /** + * Usage recorded and priced but not invoiced yet, tax included, in minor units: what the + * next invoices will charge for it, paid from credit as far as the credit goes. With + * `subscription_id`, that subscription's usage only; other subscriptions' usage paid from + * shared credit still lowers `balance`. + */ + unbilledUsage?: number | null | undefined; + /** + * Credit unit wallets: the price this customer agreed for one credit, in major units of + * `unit_price_currency`, as a decimal string (e.g. "0.0008"). Purchases and automatic + * top-ups in that currency charge it instead of the list price, unless a purchase sets its + * own `unit_price`. Absent: the list price applies. + */ + unitPrice?: string | null | undefined; + unitPriceCurrency?: Currency | null | undefined; + /** Credit granted that takes effect later. */ + upcomingCredit: number; + /** + * What this customer's usage does once the credit a subscription can use for it is used up + * (its own credit, credit that belongs to no subscription, and credit limited to the product: + * the `balance` of `GET /wallets/check`). `FOLLOW_PLAN` applies the "when credit runs out" + * rule of each subscription's plan. + */ + usageAtZero: UsageAtZero; +} + +/** Converts `Wallet` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletSerializer = { + parse(json: any, path = "$"): Wallet { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "as_of", + "auto_top_up", + "balance", + "credit_on_account", + "credit_on_account_usage_only", + "credit_unit", + "credit_unit_precision", + "currency", + "low_balance_thresholds", + "pauses_at_zero", + "shared_balance", + "subscription_credit", + "unbilled_usage", + "unit_price", + "unit_price_currency", + "upcoming_credit", + "usage_at_zero", + ]), + asOf: + json["as_of"] != null + ? decodeDateTime(json["as_of"], path, "as_of") + : json["as_of"], + autoTopUp: + json["auto_top_up"] != null + ? AutoTopUpSerializer.parse( + json["auto_top_up"], + decodePath(path, "auto_top_up") + ) + : json["auto_top_up"], + balance: + json["balance"] != null + ? decodeInteger(json["balance"], path, "balance") + : json["balance"], + creditOnAccount: decodeInteger( + json["credit_on_account"], + path, + "credit_on_account" + ), + creditOnAccountUsageOnly: decodeInteger( + json["credit_on_account_usage_only"], + path, + "credit_on_account_usage_only" + ), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + lowBalanceThresholds: decodeList( + json["low_balance_thresholds"], + path, + "low_balance_thresholds", + (item: any, p: string, i: number) => decodeInteger(item, p, i) + ), + pausesAtZero: decodeBoolean(json["pauses_at_zero"], path, "pauses_at_zero"), + sharedBalance: + json["shared_balance"] != null + ? decodeInteger(json["shared_balance"], path, "shared_balance") + : json["shared_balance"], + subscriptionCredit: decodeList( + json["subscription_credit"], + path, + "subscription_credit", + (item: any, p: string, i: number) => + SubscriptionCreditSerializer.parse(item, decodePath(p, i)) + ), + unbilledUsage: + json["unbilled_usage"] != null + ? decodeInteger(json["unbilled_usage"], path, "unbilled_usage") + : json["unbilled_usage"], + unitPrice: + json["unit_price"] != null + ? decodeString(json["unit_price"], path, "unit_price") + : json["unit_price"], + unitPriceCurrency: + json["unit_price_currency"] != null + ? CurrencySerializer.parse( + json["unit_price_currency"], + decodePath(path, "unit_price_currency") + ) + : json["unit_price_currency"], + upcomingCredit: decodeInteger(json["upcoming_credit"], path, "upcoming_credit"), + usageAtZero: UsageAtZeroSerializer.parse( + json["usage_at_zero"], + decodePath(path, "usage_at_zero") + ), + }; + }, + + serialize(value: Wallet): any { + return { + ...extraProperties(value, [ + "asOf", + "autoTopUp", + "balance", + "creditOnAccount", + "creditOnAccountUsageOnly", + "creditUnit", + "creditUnitPrecision", + "currency", + "lowBalanceThresholds", + "pausesAtZero", + "sharedBalance", + "subscriptionCredit", + "unbilledUsage", + "unitPrice", + "unitPriceCurrency", + "upcomingCredit", + "usageAtZero", + ]), + as_of: value.asOf, + auto_top_up: + value.autoTopUp != null + ? AutoTopUpSerializer.serialize(value.autoTopUp) + : value.autoTopUp, + balance: value.balance, + credit_on_account: value.creditOnAccount, + credit_on_account_usage_only: value.creditOnAccountUsageOnly, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + low_balance_thresholds: value.lowBalanceThresholds, + pauses_at_zero: value.pausesAtZero, + shared_balance: value.sharedBalance, + subscription_credit: value.subscriptionCredit.map((item: any) => + SubscriptionCreditSerializer.serialize(item) + ), + unbilled_usage: value.unbilledUsage, + unit_price: value.unitPrice, + unit_price_currency: + value.unitPriceCurrency != null + ? CurrencySerializer.serialize(value.unitPriceCurrency) + : value.unitPriceCurrency, + upcoming_credit: value.upcomingCredit, + usage_at_zero: UsageAtZeroSerializer.serialize(value.usageAtZero), + }; + }, +}; diff --git a/src/models/walletBalanceLowEvent.ts b/src/models/walletBalanceLowEvent.ts new file mode 100644 index 0000000..c062da2 --- /dev/null +++ b/src/models/walletBalanceLowEvent.ts @@ -0,0 +1,77 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletBalanceLowEventData, + WalletBalanceLowEventDataSerializer, +} from "./walletBalanceLowEventData.js"; + +export interface WalletBalanceLowEvent extends WalletBalanceLowEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletBalanceLowEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletBalanceLowEventSerializer = { + parse(json: any, path = "$"): WalletBalanceLowEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "shared_balance", + "threshold", + ]), + ...pickProperties(WalletBalanceLowEventDataSerializer.parse(json, path), [ + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "sharedBalance", + "threshold", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletBalanceLowEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "sharedBalance", + "threshold", + ]), + ...pickProperties(WalletBalanceLowEventDataSerializer.serialize(value), [ + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "shared_balance", + "threshold", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletBalanceLowEventData.ts b/src/models/walletBalanceLowEventData.ts new file mode 100644 index 0000000..851c9b1 --- /dev/null +++ b/src/models/walletBalanceLowEventData.ts @@ -0,0 +1,91 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** A wallet's balance fell below one of its low-balance thresholds. */ +export interface WalletBalanceLowEventData { + /** + * The balance when it fell below `threshold`, in minor units: the wallet's `balance`, all + * its credit on account net of the unbilled usage it pays, including credit that belongs to + * a subscription or is limited to usage or products. Sent once per crossing, for the lowest + * threshold crossed; it re-arms once the balance is back at the threshold. Because that + * credit counts here and not in `wallet.depleted`, a wallet can be depleted without this + * event firing. + */ + balance: number; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + /** + * The part of `balance` that pays any charge of any subscription: what automatic top-ups + * refill and `wallet.depleted` watches. Absent on events recorded before it was reported. + */ + sharedBalance?: number | null | undefined; + /** The low-balance threshold crossed, in the same minor units. */ + threshold: number; +} + +/** Converts `WalletBalanceLowEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletBalanceLowEventDataSerializer = { + parse(json: any, path = "$"): WalletBalanceLowEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "shared_balance", + "threshold", + ]), + balance: decodeInteger(json["balance"], path, "balance"), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + sharedBalance: + json["shared_balance"] != null + ? decodeInteger(json["shared_balance"], path, "shared_balance") + : json["shared_balance"], + threshold: decodeInteger(json["threshold"], path, "threshold"), + }; + }, + + serialize(value: WalletBalanceLowEventData): any { + return { + ...extraProperties(value, [ + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "sharedBalance", + "threshold", + ]), + balance: value.balance, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + shared_balance: value.sharedBalance, + threshold: value.threshold, + }; + }, +}; diff --git a/src/models/walletCheck.ts b/src/models/walletCheck.ts new file mode 100644 index 0000000..9802552 --- /dev/null +++ b/src/models/walletCheck.ts @@ -0,0 +1,140 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeBoolean, + decodeDateTime, + decodeInteger, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type Currency, CurrencySerializer } from "./currency.js"; +/** Whether a customer may keep consuming what their prepaid credit pays for. */ +export interface WalletCheck { + /** When `balance` was computed. */ + asOf: Date; + /** + * The balance: credit on account net of the usage not invoiced yet that it will pay, in + * minor units of `currency` or `credit_unit`; never negative for the customer as a whole, + * as `balance` of `GET /wallets`. With `product_id`, only the credit that can pay for that + * product, net of its usage no credit covers. With `subscription_id`, only the credit that + * subscription can spend (credit restricted to products it is not charged for left out), + * net of its usage no credit covers; credit that belongs to no subscription counts in every + * subscription's balance (see `shared_balance`). + */ + balance: number; + /** The credit unit (its code) checked; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: `balance` is in integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + currency?: Currency | null | undefined; + /** + * Always false: `balance` may lag usage by a few seconds (see `as_of`), and the answer is + * cached for one second. + */ + exact: boolean; + /** + * True once `balance` is at or below zero, or, with `subscription_id`, once no credit is + * left for some of its usage. Independent of `has_access`: a wallet that allows overage + * still reports this, so the caller can warn without refusing. + */ + exhausted: boolean; + /** + * False only once `balance` is at or below zero and `blocks_when_exhausted` is true. + * Customers without a wallet in `currency` do not prepay, and always have access. With + * `subscription_id`: false when `blocks_when_exhausted` is true and no credit that + * subscription can spend is left for some of its usage (of `product_id` when given), as the + * access gate refuses it; a subscription charged no usage in the wallet keeps access. + */ + hasAccess: boolean; + /** Age of `balance`, in milliseconds. */ + lagMs: number; + /** + * Whether usage is refused as soon as the credit is used up: the wallet's `usage_at_zero`, + * else the plan of the subscription checked (of any active subscription without one). A plan + * that invoices usage up to a cap refuses it past the cap only, as `has_access` reports. + */ + pausesAtZero: boolean; + /** + * With `subscription_id` only: the part of `balance` that belongs to no subscription, which + * the customer's other subscriptions can spend too. + */ + sharedBalance?: number | null | undefined; +} + +/** Converts `WalletCheck` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletCheckSerializer = { + parse(json: any, path = "$"): WalletCheck { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "as_of", + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "exact", + "exhausted", + "has_access", + "lag_ms", + "pauses_at_zero", + "shared_balance", + ]), + asOf: decodeDateTime(json["as_of"], path, "as_of"), + balance: decodeInteger(json["balance"], path, "balance"), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? CurrencySerializer.parse(json["currency"], decodePath(path, "currency")) + : json["currency"], + exact: decodeBoolean(json["exact"], path, "exact"), + exhausted: decodeBoolean(json["exhausted"], path, "exhausted"), + hasAccess: decodeBoolean(json["has_access"], path, "has_access"), + lagMs: decodeInteger(json["lag_ms"], path, "lag_ms"), + pausesAtZero: decodeBoolean(json["pauses_at_zero"], path, "pauses_at_zero"), + sharedBalance: + json["shared_balance"] != null + ? decodeInteger(json["shared_balance"], path, "shared_balance") + : json["shared_balance"], + }; + }, + + serialize(value: WalletCheck): any { + return { + ...extraProperties(value, [ + "asOf", + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "exact", + "exhausted", + "hasAccess", + "lagMs", + "pausesAtZero", + "sharedBalance", + ]), + as_of: value.asOf, + balance: value.balance, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: + value.currency != null + ? CurrencySerializer.serialize(value.currency) + : value.currency, + exact: value.exact, + exhausted: value.exhausted, + has_access: value.hasAccess, + lag_ms: value.lagMs, + pauses_at_zero: value.pausesAtZero, + shared_balance: value.sharedBalance, + }; + }, +}; diff --git a/src/models/walletCreditRecoveredEvent.ts b/src/models/walletCreditRecoveredEvent.ts new file mode 100644 index 0000000..83ec634 --- /dev/null +++ b/src/models/walletCreditRecoveredEvent.ts @@ -0,0 +1,89 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletCreditRecoveredEventData, + WalletCreditRecoveredEventDataSerializer, +} from "./walletCreditRecoveredEventData.js"; + +export interface WalletCreditRecoveredEvent extends WalletCreditRecoveredEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletCreditRecoveredEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletCreditRecoveredEventSerializer = { + parse(json: any, path = "$"): WalletCreditRecoveredEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "cause", + "credit_note_id", + "credit_recovered", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + ...pickProperties(WalletCreditRecoveredEventDataSerializer.parse(json, path), [ + "cause", + "creditNoteId", + "creditRecovered", + "creditUnit", + "creditUnitPrecision", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletCreditRecoveredEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "cause", + "creditNoteId", + "creditRecovered", + "creditUnit", + "creditUnitPrecision", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + ...pickProperties(WalletCreditRecoveredEventDataSerializer.serialize(value), [ + "cause", + "credit_note_id", + "credit_recovered", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletCreditRecoveredEventData.ts b/src/models/walletCreditRecoveredEventData.ts new file mode 100644 index 0000000..a59cb57 --- /dev/null +++ b/src/models/walletCreditRecoveredEventData.ts @@ -0,0 +1,136 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CreditNoteId, CreditNoteIdSerializer } from "./creditNoteId.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type InvoiceId, InvoiceIdSerializer } from "./invoiceId.js"; +import { + type PaymentTransactionId, + PaymentTransactionIdSerializer, +} from "./paymentTransactionId.js"; +/** Spent credit reported by `wallet.credit_unrecovered` is backed again. */ +export interface WalletCreditRecoveredEventData { + /** + * Cause of the loss this recovers: `PAYMENT_DISPUTED`, `PAYMENT_REVERSED`, + * `PAYMENT_REFUNDED` or `CREDIT_NOTE_REFUNDED`. + */ + cause: string; + creditNoteId?: CreditNoteId | null | undefined; + /** + * Spent credit an earlier `wallet.credit_unrecovered` reported that is backed again, in + * minor units: the money came back, or the credit was returned and taken back. + */ + creditRecovered: number; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** + * The loss of this money flow (an invoice's payments, a credit note, or a payment) once + * this event applies. + */ + creditUnrecoveredTotal: number; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + invoiceId?: InvoiceId | null | undefined; + paymentId?: PaymentTransactionId | null | undefined; +} + +/** Converts `WalletCreditRecoveredEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletCreditRecoveredEventDataSerializer = { + parse(json: any, path = "$"): WalletCreditRecoveredEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "cause", + "credit_note_id", + "credit_recovered", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + cause: decodeString(json["cause"], path, "cause"), + creditNoteId: + json["credit_note_id"] != null + ? CreditNoteIdSerializer.parse( + json["credit_note_id"], + decodePath(path, "credit_note_id") + ) + : json["credit_note_id"], + creditRecovered: decodeInteger(json["credit_recovered"], path, "credit_recovered"), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + creditUnrecoveredTotal: decodeInteger( + json["credit_unrecovered_total"], + path, + "credit_unrecovered_total" + ), + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + invoiceId: + json["invoice_id"] != null + ? InvoiceIdSerializer.parse(json["invoice_id"], decodePath(path, "invoice_id")) + : json["invoice_id"], + paymentId: + json["payment_id"] != null + ? PaymentTransactionIdSerializer.parse( + json["payment_id"], + decodePath(path, "payment_id") + ) + : json["payment_id"], + }; + }, + + serialize(value: WalletCreditRecoveredEventData): any { + return { + ...extraProperties(value, [ + "cause", + "creditNoteId", + "creditRecovered", + "creditUnit", + "creditUnitPrecision", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + cause: value.cause, + credit_note_id: + value.creditNoteId != null + ? CreditNoteIdSerializer.serialize(value.creditNoteId) + : value.creditNoteId, + credit_recovered: value.creditRecovered, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + credit_unrecovered_total: value.creditUnrecoveredTotal, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + invoice_id: + value.invoiceId != null + ? InvoiceIdSerializer.serialize(value.invoiceId) + : value.invoiceId, + payment_id: + value.paymentId != null + ? PaymentTransactionIdSerializer.serialize(value.paymentId) + : value.paymentId, + }; + }, +}; diff --git a/src/models/walletCreditUnrecoveredEvent.ts b/src/models/walletCreditUnrecoveredEvent.ts new file mode 100644 index 0000000..9d45797 --- /dev/null +++ b/src/models/walletCreditUnrecoveredEvent.ts @@ -0,0 +1,93 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletCreditUnrecoveredEventData, + WalletCreditUnrecoveredEventDataSerializer, +} from "./walletCreditUnrecoveredEventData.js"; + +export interface WalletCreditUnrecoveredEvent extends WalletCreditUnrecoveredEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletCreditUnrecoveredEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletCreditUnrecoveredEventSerializer = { + parse(json: any, path = "$"): WalletCreditUnrecoveredEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "cause", + "credit_note_id", + "credit_taken_back", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + ...pickProperties(WalletCreditUnrecoveredEventDataSerializer.parse(json, path), [ + "cause", + "creditNoteId", + "creditTakenBack", + "creditUnit", + "creditUnitPrecision", + "creditUnrecovered", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletCreditUnrecoveredEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "cause", + "creditNoteId", + "creditTakenBack", + "creditUnit", + "creditUnitPrecision", + "creditUnrecovered", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + ...pickProperties(WalletCreditUnrecoveredEventDataSerializer.serialize(value), [ + "cause", + "credit_note_id", + "credit_taken_back", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletCreditUnrecoveredEventData.ts b/src/models/walletCreditUnrecoveredEventData.ts new file mode 100644 index 0000000..41c55c0 --- /dev/null +++ b/src/models/walletCreditUnrecoveredEventData.ts @@ -0,0 +1,153 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CreditNoteId, CreditNoteIdSerializer } from "./creditNoteId.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type InvoiceId, InvoiceIdSerializer } from "./invoiceId.js"; +import { + type PaymentTransactionId, + PaymentTransactionIdSerializer, +} from "./paymentTransactionId.js"; +/** Purchased credit was already spent when its money came back. */ +export interface WalletCreditUnrecoveredEventData { + /** + * `PAYMENT_DISPUTED` (lost to a dispute or chargeback), `PAYMENT_REVERSED` (a failed + * collection clawed back), `PAYMENT_REFUNDED` (a payment refunded without a credit note, at + * the provider or as an overpayment, after the credit it backed was spent) or + * `CREDIT_NOTE_REFUNDED`. + */ + cause: string; + creditNoteId?: CreditNoteId | null | undefined; + /** Unspent credit taken back from the wallet at the same time, in minor units. */ + creditTakenBack: number; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** + * Spent credit this event adds to the loss, in minor units. A failed collection reopens its + * invoice, which collects it again; a dispute's loss stays unless the dispute is won. + * `wallet.credit_recovered` reports what comes back. + */ + creditUnrecovered: number; + /** + * The loss of this money flow (an invoice's payments, a credit note, or a payment) once + * this event applies. + */ + creditUnrecoveredTotal: number; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + invoiceId?: InvoiceId | null | undefined; + paymentId?: PaymentTransactionId | null | undefined; +} + +/** Converts `WalletCreditUnrecoveredEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletCreditUnrecoveredEventDataSerializer = { + parse(json: any, path = "$"): WalletCreditUnrecoveredEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "cause", + "credit_note_id", + "credit_taken_back", + "credit_unit", + "credit_unit_precision", + "credit_unrecovered", + "credit_unrecovered_total", + "currency", + "customer_id", + "invoice_id", + "payment_id", + ]), + cause: decodeString(json["cause"], path, "cause"), + creditNoteId: + json["credit_note_id"] != null + ? CreditNoteIdSerializer.parse( + json["credit_note_id"], + decodePath(path, "credit_note_id") + ) + : json["credit_note_id"], + creditTakenBack: decodeInteger( + json["credit_taken_back"], + path, + "credit_taken_back" + ), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + creditUnrecovered: decodeInteger( + json["credit_unrecovered"], + path, + "credit_unrecovered" + ), + creditUnrecoveredTotal: decodeInteger( + json["credit_unrecovered_total"], + path, + "credit_unrecovered_total" + ), + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + invoiceId: + json["invoice_id"] != null + ? InvoiceIdSerializer.parse(json["invoice_id"], decodePath(path, "invoice_id")) + : json["invoice_id"], + paymentId: + json["payment_id"] != null + ? PaymentTransactionIdSerializer.parse( + json["payment_id"], + decodePath(path, "payment_id") + ) + : json["payment_id"], + }; + }, + + serialize(value: WalletCreditUnrecoveredEventData): any { + return { + ...extraProperties(value, [ + "cause", + "creditNoteId", + "creditTakenBack", + "creditUnit", + "creditUnitPrecision", + "creditUnrecovered", + "creditUnrecoveredTotal", + "currency", + "customerId", + "invoiceId", + "paymentId", + ]), + cause: value.cause, + credit_note_id: + value.creditNoteId != null + ? CreditNoteIdSerializer.serialize(value.creditNoteId) + : value.creditNoteId, + credit_taken_back: value.creditTakenBack, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + credit_unrecovered: value.creditUnrecovered, + credit_unrecovered_total: value.creditUnrecoveredTotal, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + invoice_id: + value.invoiceId != null + ? InvoiceIdSerializer.serialize(value.invoiceId) + : value.invoiceId, + payment_id: + value.paymentId != null + ? PaymentTransactionIdSerializer.serialize(value.paymentId) + : value.paymentId, + }; + }, +}; diff --git a/src/models/walletDebitedEvent.ts b/src/models/walletDebitedEvent.ts new file mode 100644 index 0000000..d359169 --- /dev/null +++ b/src/models/walletDebitedEvent.ts @@ -0,0 +1,105 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletDebitedEventData, + WalletDebitedEventDataSerializer, +} from "./walletDebitedEventData.js"; + +export interface WalletDebitedEvent extends WalletDebitedEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletDebitedEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletDebitedEventSerializer = { + parse(json: any, path = "$"): WalletDebitedEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "actor", + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "invoice_id", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + ...pickProperties(WalletDebitedEventDataSerializer.parse(json, path), [ + "actor", + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "invoiceId", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletDebitedEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "actor", + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "invoiceId", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + ...pickProperties(WalletDebitedEventDataSerializer.serialize(value), [ + "actor", + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "invoice_id", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletDebitedEventData.ts b/src/models/walletDebitedEventData.ts new file mode 100644 index 0000000..2307eec --- /dev/null +++ b/src/models/walletDebitedEventData.ts @@ -0,0 +1,167 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type Actor, ActorSerializer } from "./actor.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { type CreditGrantId, CreditGrantIdSerializer } from "./creditGrantId.js"; +import { type CreditNoteId, CreditNoteIdSerializer } from "./creditNoteId.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type InvoiceId, InvoiceIdSerializer } from "./invoiceId.js"; +import { type LedgerEntryId, LedgerEntryIdSerializer } from "./ledgerEntryId.js"; +/** Credit left a customer's wallet. */ +export interface WalletDebitedEventData { + actor?: Actor | null | undefined; + /** In minor units of `currency` or `credit_unit`. */ + amount: number; + /** The products whose charges the grant pays; empty when it pays every product. */ + applicableProductIds: string[]; + /** What the grant pays: ALL any charge, USAGE only usage charges. */ + appliesTo: CreditAppliesTo; + /** The grant the credit left. */ + creditGrantId: CreditGrantId; + creditNoteId?: CreditNoteId | null | undefined; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + invoiceId?: InvoiceId | null | undefined; + /** The credit ledger entry recording the movement. */ + ledgerEntryId: LedgerEntryId; + /** Why the credit moved, as shown on the ledger. */ + reason: string; + /** + * The subscription the grant belongs to: it pays only that subscription's charges. Null when + * it pays any of the customer's subscriptions. + */ + subscriptionId?: string | null | undefined; +} + +/** Converts `WalletDebitedEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletDebitedEventDataSerializer = { + parse(json: any, path = "$"): WalletDebitedEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "actor", + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "invoice_id", + "ledger_entry_id", + "reason", + "subscription_id", + ]), + actor: + json["actor"] != null + ? ActorSerializer.parse(json["actor"], decodePath(path, "actor")) + : json["actor"], + amount: decodeInteger(json["amount"], path, "amount"), + applicableProductIds: decodeList( + json["applicable_product_ids"], + path, + "applicable_product_ids", + (item: any, p: string, i: number) => decodeString(item, p, i) + ), + appliesTo: CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ), + creditGrantId: CreditGrantIdSerializer.parse( + json["credit_grant_id"], + decodePath(path, "credit_grant_id") + ), + creditNoteId: + json["credit_note_id"] != null + ? CreditNoteIdSerializer.parse( + json["credit_note_id"], + decodePath(path, "credit_note_id") + ) + : json["credit_note_id"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + invoiceId: + json["invoice_id"] != null + ? InvoiceIdSerializer.parse(json["invoice_id"], decodePath(path, "invoice_id")) + : json["invoice_id"], + ledgerEntryId: LedgerEntryIdSerializer.parse( + json["ledger_entry_id"], + decodePath(path, "ledger_entry_id") + ), + reason: decodeString(json["reason"], path, "reason"), + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + }; + }, + + serialize(value: WalletDebitedEventData): any { + return { + ...extraProperties(value, [ + "actor", + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "invoiceId", + "ledgerEntryId", + "reason", + "subscriptionId", + ]), + actor: value.actor != null ? ActorSerializer.serialize(value.actor) : value.actor, + amount: value.amount, + applicable_product_ids: value.applicableProductIds, + applies_to: CreditAppliesToSerializer.serialize(value.appliesTo), + credit_grant_id: CreditGrantIdSerializer.serialize(value.creditGrantId), + credit_note_id: + value.creditNoteId != null + ? CreditNoteIdSerializer.serialize(value.creditNoteId) + : value.creditNoteId, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + invoice_id: + value.invoiceId != null + ? InvoiceIdSerializer.serialize(value.invoiceId) + : value.invoiceId, + ledger_entry_id: LedgerEntryIdSerializer.serialize(value.ledgerEntryId), + reason: value.reason, + subscription_id: value.subscriptionId, + }; + }, +}; diff --git a/src/models/walletDepletedEvent.ts b/src/models/walletDepletedEvent.ts new file mode 100644 index 0000000..1be3c16 --- /dev/null +++ b/src/models/walletDepletedEvent.ts @@ -0,0 +1,65 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletDepletedEventData, + WalletDepletedEventDataSerializer, +} from "./walletDepletedEventData.js"; + +export interface WalletDepletedEvent extends WalletDepletedEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletDepletedEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletDepletedEventSerializer = { + parse(json: any, path = "$"): WalletDepletedEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + ...pickProperties(WalletDepletedEventDataSerializer.parse(json, path), [ + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletDepletedEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + ...pickProperties(WalletDepletedEventDataSerializer.serialize(value), [ + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletDepletedEventData.ts b/src/models/walletDepletedEventData.ts new file mode 100644 index 0000000..fcab02e --- /dev/null +++ b/src/models/walletDepletedEventData.ts @@ -0,0 +1,63 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** + * A wallet's balance (credit that pays any charge of any of the customer's subscriptions, net of + * unbilled usage) reached zero; credit included with a subscription may remain. + */ +export interface WalletDepletedEventData { + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; +} + +/** Converts `WalletDepletedEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletDepletedEventDataSerializer = { + parse(json: any, path = "$"): WalletDepletedEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + }; + }, + + serialize(value: WalletDepletedEventData): any { + return { + ...extraProperties(value, [ + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + }; + }, +}; diff --git a/src/models/walletFundedEvent.ts b/src/models/walletFundedEvent.ts new file mode 100644 index 0000000..314fa71 --- /dev/null +++ b/src/models/walletFundedEvent.ts @@ -0,0 +1,105 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletFundedEventData, + WalletFundedEventDataSerializer, +} from "./walletFundedEventData.js"; + +export interface WalletFundedEvent extends WalletFundedEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletFundedEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletFundedEventSerializer = { + parse(json: any, path = "$"): WalletFundedEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "grant_type", + "invoice_id", + "ledger_entry_id", + "source", + "subscription_id", + ]), + ...pickProperties(WalletFundedEventDataSerializer.parse(json, path), [ + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "grantType", + "invoiceId", + "ledgerEntryId", + "source", + "subscriptionId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletFundedEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "grantType", + "invoiceId", + "ledgerEntryId", + "source", + "subscriptionId", + ]), + ...pickProperties(WalletFundedEventDataSerializer.serialize(value), [ + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "grant_type", + "invoice_id", + "ledger_entry_id", + "source", + "subscription_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletFundedEventData.ts b/src/models/walletFundedEventData.ts new file mode 100644 index 0000000..0297bae --- /dev/null +++ b/src/models/walletFundedEventData.ts @@ -0,0 +1,175 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { + decodeInteger, + decodeList, + decodeObject, + decodePath, + decodeString, +} from "../decode.js"; +import { type CreditAppliesTo, CreditAppliesToSerializer } from "./creditAppliesTo.js"; +import { type CreditGrantId, CreditGrantIdSerializer } from "./creditGrantId.js"; +import { + type CreditGrantSource, + CreditGrantSourceSerializer, +} from "./creditGrantSource.js"; +import { type CreditGrantType, CreditGrantTypeSerializer } from "./creditGrantType.js"; +import { type CreditNoteId, CreditNoteIdSerializer } from "./creditNoteId.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +import { type InvoiceId, InvoiceIdSerializer } from "./invoiceId.js"; +import { type LedgerEntryId, LedgerEntryIdSerializer } from "./ledgerEntryId.js"; +/** Credit entered a customer's wallet. */ +export interface WalletFundedEventData { + /** In minor units of `currency` or `credit_unit`. */ + amount: number; + /** The products whose charges the grant pays; empty when it pays every product. */ + applicableProductIds: string[]; + /** What the grant pays: ALL any charge, USAGE only usage charges. */ + appliesTo: CreditAppliesTo; + /** The grant the credit entered. */ + creditGrantId: CreditGrantId; + creditNoteId?: CreditNoteId | null | undefined; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; + /** PAID or PROMOTIONAL: whether the credit applies after or before tax. */ + grantType: CreditGrantType; + invoiceId?: InvoiceId | null | undefined; + /** The credit ledger entry recording the movement. */ + ledgerEntryId: LedgerEntryId; + /** Where the credit came from. */ + source: CreditGrantSource; + /** + * The subscription the grant belongs to: it pays only that subscription's charges. Null when + * it pays any of the customer's subscriptions. + */ + subscriptionId?: string | null | undefined; +} + +/** Converts `WalletFundedEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletFundedEventDataSerializer = { + parse(json: any, path = "$"): WalletFundedEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "amount", + "applicable_product_ids", + "applies_to", + "credit_grant_id", + "credit_note_id", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + "grant_type", + "invoice_id", + "ledger_entry_id", + "source", + "subscription_id", + ]), + amount: decodeInteger(json["amount"], path, "amount"), + applicableProductIds: decodeList( + json["applicable_product_ids"], + path, + "applicable_product_ids", + (item: any, p: string, i: number) => decodeString(item, p, i) + ), + appliesTo: CreditAppliesToSerializer.parse( + json["applies_to"], + decodePath(path, "applies_to") + ), + creditGrantId: CreditGrantIdSerializer.parse( + json["credit_grant_id"], + decodePath(path, "credit_grant_id") + ), + creditNoteId: + json["credit_note_id"] != null + ? CreditNoteIdSerializer.parse( + json["credit_note_id"], + decodePath(path, "credit_note_id") + ) + : json["credit_note_id"], + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + grantType: CreditGrantTypeSerializer.parse( + json["grant_type"], + decodePath(path, "grant_type") + ), + invoiceId: + json["invoice_id"] != null + ? InvoiceIdSerializer.parse(json["invoice_id"], decodePath(path, "invoice_id")) + : json["invoice_id"], + ledgerEntryId: LedgerEntryIdSerializer.parse( + json["ledger_entry_id"], + decodePath(path, "ledger_entry_id") + ), + source: CreditGrantSourceSerializer.parse( + json["source"], + decodePath(path, "source") + ), + subscriptionId: + json["subscription_id"] != null + ? decodeString(json["subscription_id"], path, "subscription_id") + : json["subscription_id"], + }; + }, + + serialize(value: WalletFundedEventData): any { + return { + ...extraProperties(value, [ + "amount", + "applicableProductIds", + "appliesTo", + "creditGrantId", + "creditNoteId", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + "grantType", + "invoiceId", + "ledgerEntryId", + "source", + "subscriptionId", + ]), + amount: value.amount, + applicable_product_ids: value.applicableProductIds, + applies_to: CreditAppliesToSerializer.serialize(value.appliesTo), + credit_grant_id: CreditGrantIdSerializer.serialize(value.creditGrantId), + credit_note_id: + value.creditNoteId != null + ? CreditNoteIdSerializer.serialize(value.creditNoteId) + : value.creditNoteId, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + grant_type: CreditGrantTypeSerializer.serialize(value.grantType), + invoice_id: + value.invoiceId != null + ? InvoiceIdSerializer.serialize(value.invoiceId) + : value.invoiceId, + ledger_entry_id: LedgerEntryIdSerializer.serialize(value.ledgerEntryId), + source: CreditGrantSourceSerializer.serialize(value.source), + subscription_id: value.subscriptionId, + }; + }, +}; diff --git a/src/models/walletListResponse.ts b/src/models/walletListResponse.ts new file mode 100644 index 0000000..9326c1c --- /dev/null +++ b/src/models/walletListResponse.ts @@ -0,0 +1,28 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeList, decodeObject, decodePath } from "../decode.js"; +import { type Wallet, WalletSerializer } from "./wallet.js"; +/** A customer's wallets, the customer's own currency first. */ +export interface WalletListResponse { + data: Wallet[]; +} + +/** Converts `WalletListResponse` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletListResponseSerializer = { + parse(json: any, path = "$"): WalletListResponse { + decodeObject(json, path); + return { + ...extraProperties(json, ["data"]), + data: decodeList(json["data"], path, "data", (item: any, p: string, i: number) => + WalletSerializer.parse(item, decodePath(p, i)) + ), + }; + }, + + serialize(value: WalletListResponse): any { + return { + ...extraProperties(value, ["data"]), + data: value.data.map((item: any) => WalletSerializer.serialize(item)), + }; + }, +}; diff --git a/src/models/walletRecoveredEvent.ts b/src/models/walletRecoveredEvent.ts new file mode 100644 index 0000000..7b775fe --- /dev/null +++ b/src/models/walletRecoveredEvent.ts @@ -0,0 +1,69 @@ +// this file is @generated +import { extraProperties, pickProperties } from "../json.js"; +import { decodeDateTime, decodeObject, decodePath } from "../decode.js"; +import { type EventId, EventIdSerializer } from "./eventId.js"; +import { type EventType, EventTypeSerializer } from "./eventType.js"; +import { + type WalletRecoveredEventData, + WalletRecoveredEventDataSerializer, +} from "./walletRecoveredEventData.js"; + +export interface WalletRecoveredEvent extends WalletRecoveredEventData { + id: EventId; + timestamp: Date; + type: EventType; +} + +/** Converts `WalletRecoveredEvent` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletRecoveredEventSerializer = { + parse(json: any, path = "$"): WalletRecoveredEvent { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "id", + "timestamp", + "type", + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + ...pickProperties(WalletRecoveredEventDataSerializer.parse(json, path), [ + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + id: EventIdSerializer.parse(json["id"], decodePath(path, "id")), + timestamp: decodeDateTime(json["timestamp"], path, "timestamp"), + type: EventTypeSerializer.parse(json["type"], decodePath(path, "type")), + }; + }, + + serialize(value: WalletRecoveredEvent): any { + return { + ...extraProperties(value, [ + "id", + "timestamp", + "type", + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + ...pickProperties(WalletRecoveredEventDataSerializer.serialize(value), [ + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + id: EventIdSerializer.serialize(value.id), + timestamp: value.timestamp, + type: EventTypeSerializer.serialize(value.type), + }; + }, +}; diff --git a/src/models/walletRecoveredEventData.ts b/src/models/walletRecoveredEventData.ts new file mode 100644 index 0000000..3a0fd3c --- /dev/null +++ b/src/models/walletRecoveredEventData.ts @@ -0,0 +1,73 @@ +// this file is @generated +import { extraProperties } from "../json.js"; +import { decodeInteger, decodeObject, decodePath, decodeString } from "../decode.js"; +import { type CustomerId, CustomerIdSerializer } from "./customerId.js"; +/** + * A wallet's balance (credit that pays any charge of any of the customer's subscriptions, net of + * unbilled usage) came back above zero. + */ +export interface WalletRecoveredEventData { + /** + * The balance (credit on account that pays any charge of any of the customer's subscriptions, + * net of unbilled usage) now that it is back above zero, in + * minor units. + */ + balance: number; + /** The credit unit (its code) the amounts are in; absent for a currency. */ + creditUnit?: string | null | undefined; + /** Decimal places of `credit_unit`: amounts are integers of 10^-precision credit. */ + creditUnitPrecision?: number | null | undefined; + /** Absent when the amounts are in a credit unit. */ + currency?: string | null | undefined; + customerId: CustomerId; +} + +/** Converts `WalletRecoveredEventData` values from (`parse`) and to (`serialize`) their JSON form. */ +export const WalletRecoveredEventDataSerializer = { + parse(json: any, path = "$"): WalletRecoveredEventData { + decodeObject(json, path); + return { + ...extraProperties(json, [ + "balance", + "credit_unit", + "credit_unit_precision", + "currency", + "customer_id", + ]), + balance: decodeInteger(json["balance"], path, "balance"), + creditUnit: + json["credit_unit"] != null + ? decodeString(json["credit_unit"], path, "credit_unit") + : json["credit_unit"], + creditUnitPrecision: + json["credit_unit_precision"] != null + ? decodeInteger(json["credit_unit_precision"], path, "credit_unit_precision") + : json["credit_unit_precision"], + currency: + json["currency"] != null + ? decodeString(json["currency"], path, "currency") + : json["currency"], + customerId: CustomerIdSerializer.parse( + json["customer_id"], + decodePath(path, "customer_id") + ), + }; + }, + + serialize(value: WalletRecoveredEventData): any { + return { + ...extraProperties(value, [ + "balance", + "creditUnit", + "creditUnitPrecision", + "currency", + "customerId", + ]), + balance: value.balance, + credit_unit: value.creditUnit, + credit_unit_precision: value.creditUnitPrecision, + currency: value.currency, + customer_id: CustomerIdSerializer.serialize(value.customerId), + }; + }, +}; diff --git a/src/models/webhookEndpoint.ts b/src/models/webhookEndpoint.ts index 123f4ea..34a9d1c 100644 --- a/src/models/webhookEndpoint.ts +++ b/src/models/webhookEndpoint.ts @@ -26,7 +26,10 @@ export interface WebhookEndpoint { description?: string | null | undefined; disabled: boolean; disabledReason?: WebhookEndpointDisabledReason | null | undefined; - /** Subscribed event types. Empty means every event type. */ + /** + * Subscribed event types. Empty means every event type except Beta ones, which are sent + * only to endpoints that list them. + */ eventTypes: string[]; /** Custom headers sent with every delivery. */ headers: WebhookHeader[]; diff --git a/tests/api/budgets.test.ts b/tests/api/budgets.test.ts new file mode 100644 index 0000000..b7232ae --- /dev/null +++ b/tests/api/budgets.test.ts @@ -0,0 +1,14 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("budgets.list", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"amount":-9007199254740993,"behavior":"SOFT","created_at":"2023-12-31T23:59:59.999-05:30","created_by":"TENANT","exact":false,"id":"sample","thresholds":[-123456789],"updated_at":"2024-03-15T10:30:45.123+02:00","version":123456789}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + }); + await client.budgets.list("id_or_alias"); + assert.deepEqual(requests, ["GET /api/v1/customers/id_or_alias/budgets"]); +}); diff --git a/tests/api/checks.test.ts b/tests/api/checks.test.ts new file mode 100644 index 0000000..e488e87 --- /dev/null +++ b/tests/api/checks.test.ts @@ -0,0 +1,16 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("checks.check_entitlement", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"as_of":"2023-12-31T23:59:59.999-05:30","exact":true,"feature":{"code":"sample","id":"feature_id_19"},"has_access":true,"in_overage":false,"lag_ms":9007199254740993,"limits":[{"behavior":"HARD","has_access":false,"limit":"-0.000123","remaining":"12345.6789","usage_limit_id":"usage_limit_id_23","used":"12345.6789"}],"near_limit":false,"reason":"INSUFFICIENT_BALANCE"}', + }); + await client.checks.checkEntitlement("id_or_alias", "feature_id_or_code"); + assert.deepEqual(requests, [ + "GET /api/v1/customers/id_or_alias/entitlements/feature_id_or_code/check", + ]); +}); diff --git a/tests/api/connect.test.ts b/tests/api/connect.test.ts index 7166cdd..f1d86cf 100644 --- a/tests/api/connect.test.ts +++ b/tests/api/connect.test.ts @@ -22,11 +22,11 @@ test("connect.create_connected_account", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"connection_type":"express","created_at":"2024-03-15T10:30:45.123+02:00","id":"connected_account_id_47","onboarding_mode":"express","platform_organization_id":"organization_id_83","status":"active"}', + body: '{"connection_type":"standard","created_at":"2024-03-15T10:30:45.123+02:00","id":"connected_account_id_67","onboarding_mode":"full","platform_organization_id":"organization_id_23","status":"active","onboarding_link":{"expires_at":"2023-12-31T23:59:59.999-05:30","url":"sample"}}', }); await client.connect.createConnectedAccount( CreateConnectedAccountRequestSerializer.parse( - parseJson('{"connected_organization_id":"00000000-0000-0000-0000-000000000000"}') + parseJson('{"email":"alice@example.com","organization_name":"sample"}') ) ); assert.deepEqual(requests, ["POST /api/v1/connected-accounts"]); diff --git a/tests/api/creditNotes.test.ts b/tests/api/creditNotes.test.ts index 50b680d..f563e34 100644 --- a/tests/api/creditNotes.test.ts +++ b/tests/api/creditNotes.test.ts @@ -11,7 +11,7 @@ test("credit_notes.list", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"data":[{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"DEBT_CANCELLATION","credited_amount_cents":9007199254740993,"currency":"TMT","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_78","id":"credit_note_id_47","invoice_id":"invoice_id_67","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"refunded_amount_cents":9007199254740993,"status":"DRAFT","subtotal":-9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":-9007199254740993,"tax_rate":"-0.000123","taxable_amount":-9007199254740993}],"total":-9007199254740993}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + body: '{"data":[{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"DEBT_CANCELLATION","credited_amount_cents":9007199254740993,"currency":"TMT","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_78","id":"credit_note_id_47","invoice_id":"invoice_id_67","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"-0.000123","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"-0.000123"}],"refunded_amount_cents":9007199254740993,"status":"DRAFT","subtotal":-9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":-9007199254740993,"tax_rate":"-0.000123","taxable_amount":-9007199254740993}],"total":-9007199254740993}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', }); await client.creditNotes.list(); assert.deepEqual(requests, ["GET /api/v1/credit-notes"]); @@ -21,7 +21,7 @@ test("credit_notes.retrieve", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"REFUND","credited_amount_cents":9007199254740993,"currency":"MMK","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_13","id":"credit_note_id_99","invoice_id":"invoice_id_90","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"-0.000123"}],"tax_rate":"12345.6789"}],"refunded_amount_cents":-9007199254740993,"status":"DRAFT","subtotal":9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"total":-9007199254740993}', + body: '{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"REFUND","credited_amount_cents":9007199254740993,"currency":"MMK","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_13","id":"credit_note_id_99","invoice_id":"invoice_id_90","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"-0.000123","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"refunded_amount_cents":-9007199254740993,"status":"DRAFT","subtotal":9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"total":-9007199254740993}', }); await client.creditNotes.retrieve("credit_note_id"); assert.deepEqual(requests, ["GET /api/v1/credit-notes/credit_note_id"]); @@ -31,7 +31,7 @@ test("credit_notes.update_custom_properties", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"REFUND","credited_amount_cents":9007199254740993,"currency":"MMK","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_13","id":"credit_note_id_99","invoice_id":"invoice_id_90","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"-0.000123"}],"tax_rate":"12345.6789"}],"refunded_amount_cents":-9007199254740993,"status":"DRAFT","subtotal":9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"total":-9007199254740993}', + body: '{"created_at":"2023-12-31T23:59:59.999-05:30","credit_note_number":"sample","credit_type":"REFUND","credited_amount_cents":9007199254740993,"currency":"MMK","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_id":"customer_id_13","id":"credit_note_id_99","invoice_id":"invoice_id_90","invoice_number":"sample","line_items":[{"amount_total":-9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"-0.000123","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"refunded_amount_cents":-9007199254740993,"status":"DRAFT","subtotal":9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"total":-9007199254740993}', }); await client.creditNotes.updateCustomProperties( "credit_note_id", diff --git a/tests/api/creditUnits.test.ts b/tests/api/creditUnits.test.ts new file mode 100644 index 0000000..8766315 --- /dev/null +++ b/tests/api/creditUnits.test.ts @@ -0,0 +1,58 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { + parseJson, + CreditUnitCreateRequestSerializer, + CreditUnitUpdateRequestSerializer, +} from "../../src/index.js"; +import { mock } from "./mock.js"; + +test("credit_units.list", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"archived":false,"code":"sample","id":"sample","name":"sample","plural_name":"sample","precision":123456789,"prices":[{"created_at":"2023-12-31T23:59:59.999-05:30","currency":"sample","id":"sample","unit_price":"sample"}]}]}', + }); + await client.creditUnits.list(); + assert.deepEqual(requests, ["GET /api/v1/credit-units"]); +}); + +test("credit_units.create", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"archived":false,"code":"sample","id":"sample","name":"sample","plural_name":"sample","precision":2147483647,"prices":[{"created_at":"2024-03-15T10:30:45.123+02:00","currency":"sample","id":"sample","unit_price":"sample"}]}', + }); + await client.creditUnits.create( + CreditUnitCreateRequestSerializer.parse( + parseJson( + '{"code":"sample","name":"sample","plural_name":"sample","precision":123456789}' + ) + ) + ); + assert.deepEqual(requests, ["POST /api/v1/credit-units"]); +}); + +test("credit_units.retrieve", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"archived":false,"code":"sample","id":"sample","name":"sample","plural_name":"sample","precision":2147483647,"prices":[{"created_at":"2024-03-15T10:30:45.123+02:00","currency":"sample","id":"sample","unit_price":"sample"}]}', + }); + await client.creditUnits.retrieve("id"); + assert.deepEqual(requests, ["GET /api/v1/credit-units/id"]); +}); + +test("credit_units.update", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"archived":false,"code":"sample","id":"sample","name":"sample","plural_name":"sample","precision":2147483647,"prices":[{"created_at":"2024-03-15T10:30:45.123+02:00","currency":"sample","id":"sample","unit_price":"sample"}]}', + }); + await client.creditUnits.update( + "id", + CreditUnitUpdateRequestSerializer.parse(parseJson("{}")) + ); + assert.deepEqual(requests, ["PATCH /api/v1/credit-units/id"]); +}); diff --git a/tests/api/creditUnitsPrices.test.ts b/tests/api/creditUnitsPrices.test.ts new file mode 100644 index 0000000..2ac3007 --- /dev/null +++ b/tests/api/creditUnitsPrices.test.ts @@ -0,0 +1,39 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { parseJson, CreditUnitPriceSetRequestSerializer } from "../../src/index.js"; +import { mock } from "./mock.js"; + +test("credit_units.prices.list", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"created_at":"2023-12-31T23:59:59.999-05:30","currency":"sample","id":"sample","unit_price":"sample"}]}', + }); + await client.creditUnits.prices.list("id"); + assert.deepEqual(requests, ["GET /api/v1/credit-units/id/prices"]); +}); + +test("credit_units.prices.update", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"created_at":"2024-03-15T10:30:45.123+02:00","currency":"sample","id":"sample","unit_price":"sample"}', + }); + await client.creditUnits.prices.update( + "id", + "currency", + CreditUnitPriceSetRequestSerializer.parse(parseJson('{"unit_price":"sample"}')) + ); + assert.deepEqual(requests, ["PUT /api/v1/credit-units/id/prices/currency"]); +}); + +test("credit_units.prices.archive", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"created_at":"2024-03-15T10:30:45.123+02:00","currency":"sample","id":"sample","unit_price":"sample"}', + }); + await client.creditUnits.prices.archive("id", "currency"); + assert.deepEqual(requests, ["DELETE /api/v1/credit-units/id/prices/currency"]); +}); diff --git a/tests/api/credits.test.ts b/tests/api/credits.test.ts new file mode 100644 index 0000000..fbaeff2 --- /dev/null +++ b/tests/api/credits.test.ts @@ -0,0 +1,14 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("credits.list_customer_credit_ledger", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"amount":-9007199254740993,"applies_to":"USAGE","balance_after":9007199254740993,"credit_grant_id":"sample","effective_at":"2023-12-31T23:59:59.999-05:30","id":"sample","reason":"sample","recorded_at":"2023-12-31T23:59:59.999-05:30","sequence":9007199254740993,"type":"CREDIT"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + }); + await client.credits.listCustomerCreditLedger("id_or_alias"); + assert.deepEqual(requests, ["GET /api/v1/customers/id_or_alias/credit-ledger"]); +}); diff --git a/tests/api/creditsGrants.test.ts b/tests/api/creditsGrants.test.ts new file mode 100644 index 0000000..057a0fe --- /dev/null +++ b/tests/api/creditsGrants.test.ts @@ -0,0 +1,14 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("credits.grants.list", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"amount":-9007199254740993,"applicable_product_ids":["product_id_39"],"applies_to":"ALL","created_at":"2024-03-15T10:30:45.123+02:00","effective_at":"2023-12-31T23:59:59.999-05:30","id":"sample","kind":"ACCOUNT_BALANCE","kind_label":"sample","priority":123456789,"reason":"sample","remaining":-9007199254740993,"source":"OVERPAYMENT","status":"ACTIVE","type":"PAID"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + }); + await client.credits.grants.list("id_or_alias"); + assert.deepEqual(requests, ["GET /api/v1/customers/id_or_alias/credit-grants"]); +}); diff --git a/tests/api/creditsWallets.test.ts b/tests/api/creditsWallets.test.ts new file mode 100644 index 0000000..56af355 --- /dev/null +++ b/tests/api/creditsWallets.test.ts @@ -0,0 +1,24 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("credits.wallets.list", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"data":[{"credit_on_account":9007199254740993,"credit_on_account_usage_only":-9007199254740993,"low_balance_thresholds":[-9007199254740993],"pauses_at_zero":false,"subscription_credit":[{"credit_on_account":-9007199254740993,"subscription_id":"sample"}],"upcoming_credit":9007199254740993,"usage_at_zero":"FOLLOW_PLAN"}]}', + }); + await client.credits.wallets.list("id_or_alias"); + assert.deepEqual(requests, ["GET /api/v1/customers/id_or_alias/wallets"]); +}); + +test("credits.wallets.check", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"as_of":"2023-12-31T23:59:59.999-05:30","balance":9007199254740993,"exact":true,"exhausted":false,"has_access":true,"lag_ms":-9007199254740993,"pauses_at_zero":true}', + }); + await client.credits.wallets.check("id_or_alias"); + assert.deepEqual(requests, ["GET /api/v1/customers/id_or_alias/wallets/check"]); +}); diff --git a/tests/api/invoices.test.ts b/tests/api/invoices.test.ts index 29c2158..fb0766b 100644 --- a/tests/api/invoices.test.ts +++ b/tests/api/invoices.test.ts @@ -8,7 +8,7 @@ test("invoices.list", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"data":[{"amount_due":-9007199254740993,"applied_credits":-9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"CNY","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_39","name":"sample","snapshot_at":"2023-12-31T23:59:59.999-05:30"},"customer_id":"customer_id_67","id":"invoice_id_67","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"RECURRING","line_items":[{"amount_total":9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"-0.000123","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"net_terms":-2147483648,"payment_status":"PARTIALLY_PAID","status":"FINALIZED","subtotal":-9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":-9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"tax_inclusive":false,"total":-9007199254740993,"transactions":[{"amount":9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":-9007199254740993,"currency":"sample","id":"payment_transaction_id_94","payment_type":"PAYMENT","status":"READY"}]}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + body: '{"data":[{"amount_due":-9007199254740993,"applied_credits":-9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"CNY","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_39","name":"sample","snapshot_at":"2023-12-31T23:59:59.999-05:30"},"customer_id":"customer_id_67","id":"invoice_id_67","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"RECURRING","line_items":[{"amount_total":9007199254740993,"end_date":"2024-02-29","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"-0.000123"}],"net_terms":-2147483648,"payment_status":"ERRORED","settled_by_credit_notes":false,"status":"FINALIZED","subtotal":9007199254740993,"subtotal_recurring":-9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"12345.6789","taxable_amount":9007199254740993}],"tax_inclusive":true,"total":-9007199254740993,"transactions":[{"amount":9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":9007199254740993,"currency":"sample","id":"payment_transaction_id_30","payment_type":"REFUND","status":"READY"}]}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', }); await client.invoices.list(); assert.deepEqual(requests, ["GET /api/v1/invoices"]); @@ -18,7 +18,7 @@ test("invoices.retrieve", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":-9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"-0.000123"}],"net_terms":-2147483648,"payment_status":"UNPAID","status":"DRAFT","subtotal":9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":9007199254740993}],"tax_inclusive":true,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":-9007199254740993,"currency":"sample","id":"payment_transaction_id_7","payment_type":"PAYMENT","status":"CANCELLED"}]}', + body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"net_terms":-2147483648,"payment_status":"PARTIALLY_PAID","settled_by_credit_notes":true,"status":"VOID","subtotal":-9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":-9007199254740993}],"tax_inclusive":false,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":9007199254740993,"currency":"sample","id":"payment_transaction_id_88","payment_type":"REFUND","status":"PENDING"}]}', }); await client.invoices.retrieve("invoice_id"); assert.deepEqual(requests, ["GET /api/v1/invoices/invoice_id"]); @@ -28,7 +28,7 @@ test("invoices.update_custom_properties", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":-9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"-0.000123"}],"net_terms":-2147483648,"payment_status":"UNPAID","status":"DRAFT","subtotal":9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":9007199254740993}],"tax_inclusive":true,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":-9007199254740993,"currency":"sample","id":"payment_transaction_id_7","payment_type":"PAYMENT","status":"CANCELLED"}]}', + body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"net_terms":-2147483648,"payment_status":"PARTIALLY_PAID","settled_by_credit_notes":true,"status":"VOID","subtotal":-9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":-9007199254740993}],"tax_inclusive":false,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":9007199254740993,"currency":"sample","id":"payment_transaction_id_88","payment_type":"REFUND","status":"PENDING"}]}', }); await client.invoices.updateCustomProperties( "invoice_id", @@ -55,7 +55,7 @@ test("invoices.refresh", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"2024-02-29","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":-9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"-0.000123"}],"net_terms":-2147483648,"payment_status":"UNPAID","status":"DRAFT","subtotal":9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":9007199254740993}],"tax_inclusive":true,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":-9007199254740993,"currency":"sample","id":"payment_transaction_id_7","payment_type":"PAYMENT","status":"CANCELLED"}]}', + body: '{"amount_due":-9007199254740993,"applied_credits":9007199254740993,"coupons":[{"coupon_id":"sample","name":"sample","total":-9007199254740993}],"created_at":"2024-03-15T10:30:45.123+02:00","currency":"NAD","custom_properties":{"key":"value","count":3,"ratio":0.5,"flags":[true,false],"nested":{"ok":true}},"customer_details":{"id":"customer_id_62","name":"sample","snapshot_at":"2024-03-15T10:30:45.123+02:00"},"customer_id":"customer_id_90","id":"invoice_id_31","invoice_date":"1999-12-31","invoice_number":"sample","invoice_type":"ONE_OFF","line_items":[{"amount_total":9007199254740993,"end_date":"1999-12-31","name":"sample","start_date":"1999-12-31","sub_line_items":[{"id":"sample","name":"sample","quantity":"12345.6789","total":9007199254740993,"unit_price":"12345.6789"}],"tax_rate":"12345.6789"}],"net_terms":-2147483648,"payment_status":"PARTIALLY_PAID","settled_by_credit_notes":true,"status":"VOID","subtotal":-9007199254740993,"subtotal_recurring":9007199254740993,"tax_amount":-9007199254740993,"tax_breakdown":[{"name":"sample","tax_amount":9007199254740993,"tax_rate":"-0.000123","taxable_amount":-9007199254740993}],"tax_inclusive":false,"total":-9007199254740993,"transactions":[{"amount":-9007199254740993,"amount_refunded":9007199254740993,"amount_reversed":9007199254740993,"currency":"sample","id":"payment_transaction_id_88","payment_type":"REFUND","status":"PENDING"}]}', }); await client.invoices.refresh("invoice_id"); assert.deepEqual(requests, ["POST /api/v1/invoices/invoice_id/refresh"]); diff --git a/tests/api/plans.test.ts b/tests/api/plans.test.ts index d1fe03e..ca7c1f3 100644 --- a/tests/api/plans.test.ts +++ b/tests/api/plans.test.ts @@ -41,7 +41,7 @@ test("plans.list", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"data":[{"available_parameters":{},"created_at":"2024-03-15T10:30:45.123+02:00","currency":"WST","id":"plan_id_78","name":"sample","net_terms":-2147483648,"plan_type":"FREE","price_components":[{"id":"price_component_id_82","name":"sample"}],"product_family":{"id":"product_family_id_59","name":"sample"},"status":"INACTIVE","tax_inclusive":true,"version":-2147483648,"version_id":"plan_version_id_92"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + body: '{"data":[{"available_parameters":{},"created_at":"2024-03-15T10:30:45.123+02:00","currency":"TMT","id":"plan_id_25","name":"sample","net_terms":-2147483648,"plan_type":"CUSTOM","price_components":[{"id":"price_component_id_8","name":"sample"}],"product_family":{"id":"product_family_id_2","name":"sample"},"status":"DRAFT","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_3"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', }); await client.plans.list(); assert.deepEqual(requests, ["GET /api/v1/plans"]); @@ -51,12 +51,12 @@ test("plans.create", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"COP","id":"plan_id_13","name":"sample","net_terms":2147483647,"plan_type":"FREE","price_components":[{"id":"price_component_id_38","name":"sample"}],"product_family":{"id":"product_family_id_66","name":"sample"},"status":"ARCHIVED","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_84"}', + body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"MMK","id":"plan_id_40","name":"sample","net_terms":-123456789,"plan_type":"STANDARD","price_components":[{"id":"price_component_id_88","name":"sample"}],"product_family":{"id":"product_family_id_15","name":"sample"},"status":"ACTIVE","tax_inclusive":true,"version":123456789,"version_id":"plan_version_id_79"}', }); await client.plans.create( CreatePlanRequestSerializer.parse( parseJson( - '{"components":[{"fee":{"type":"RATE","rates":[{"price":"-0.000123","term":"ANNUAL"}]},"name":"sample"}],"currency":"sample","name":"sample","plan_type":"CUSTOM","product_family_id":"product_family_id_99","status":"ACTIVE"}' + '{"components":[{"fee":{"type":"RATE","rates":[{"price":"-0.000123","term":"ANNUAL"}]},"name":"sample"}],"currency":"sample","name":"sample","plan_type":"CUSTOM","product_family_id":"product_family_id_90","status":"INACTIVE"}' ) ) ); @@ -67,7 +67,7 @@ test("plans.retrieve", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"COP","id":"plan_id_13","name":"sample","net_terms":2147483647,"plan_type":"FREE","price_components":[{"id":"price_component_id_38","name":"sample"}],"product_family":{"id":"product_family_id_66","name":"sample"},"status":"ARCHIVED","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_84"}', + body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"MMK","id":"plan_id_40","name":"sample","net_terms":-123456789,"plan_type":"STANDARD","price_components":[{"id":"price_component_id_88","name":"sample"}],"product_family":{"id":"product_family_id_15","name":"sample"},"status":"ACTIVE","tax_inclusive":true,"version":123456789,"version_id":"plan_version_id_79"}', }); await client.plans.retrieve("plan_id"); assert.deepEqual(requests, ["GET /api/v1/plans/plan_id"]); @@ -77,7 +77,7 @@ test("plans.replace", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"COP","id":"plan_id_13","name":"sample","net_terms":2147483647,"plan_type":"FREE","price_components":[{"id":"price_component_id_38","name":"sample"}],"product_family":{"id":"product_family_id_66","name":"sample"},"status":"ARCHIVED","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_84"}', + body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"MMK","id":"plan_id_40","name":"sample","net_terms":-123456789,"plan_type":"STANDARD","price_components":[{"id":"price_component_id_88","name":"sample"}],"product_family":{"id":"product_family_id_15","name":"sample"},"status":"ACTIVE","tax_inclusive":true,"version":123456789,"version_id":"plan_version_id_79"}', }); await client.plans.replace( "plan_id", @@ -94,7 +94,7 @@ test("plans.update", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"COP","id":"plan_id_13","name":"sample","net_terms":2147483647,"plan_type":"FREE","price_components":[{"id":"price_component_id_38","name":"sample"}],"product_family":{"id":"product_family_id_66","name":"sample"},"status":"ARCHIVED","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_84"}', + body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"MMK","id":"plan_id_40","name":"sample","net_terms":-123456789,"plan_type":"STANDARD","price_components":[{"id":"price_component_id_88","name":"sample"}],"product_family":{"id":"product_family_id_15","name":"sample"},"status":"ACTIVE","tax_inclusive":true,"version":123456789,"version_id":"plan_version_id_79"}', }); await client.plans.update("plan_id", PatchPlanRequestSerializer.parse(parseJson("{}"))); assert.deepEqual(requests, ["PATCH /api/v1/plans/plan_id"]); @@ -114,7 +114,7 @@ test("plans.publish", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"COP","id":"plan_id_13","name":"sample","net_terms":2147483647,"plan_type":"FREE","price_components":[{"id":"price_component_id_38","name":"sample"}],"product_family":{"id":"product_family_id_66","name":"sample"},"status":"ARCHIVED","tax_inclusive":false,"version":123456789,"version_id":"plan_version_id_84"}', + body: '{"available_parameters":{},"created_at":"2023-12-31T23:59:59.999-05:30","currency":"MMK","id":"plan_id_40","name":"sample","net_terms":-123456789,"plan_type":"STANDARD","price_components":[{"id":"price_component_id_88","name":"sample"}],"product_family":{"id":"product_family_id_15","name":"sample"},"status":"ACTIVE","tax_inclusive":true,"version":123456789,"version_id":"plan_version_id_79"}', }); await client.plans.publish("plan_id"); assert.deepEqual(requests, ["POST /api/v1/plans/plan_id/publish"]); diff --git a/tests/api/products.test.ts b/tests/api/products.test.ts index 909b842..ab778fb 100644 --- a/tests/api/products.test.ts +++ b/tests/api/products.test.ts @@ -12,7 +12,7 @@ test("products.list", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"data":[{"catalog":false,"created_at":"2024-03-15T10:30:45.123+02:00","fee_structure":{"type":"RATE"},"fee_type":"CAPACITY","id":"product_id_78","name":"sample","product_family_id":"product_family_id_47"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', + body: '{"data":[{"catalog":false,"created_at":"2024-03-15T10:30:45.123+02:00","fee_structure":{"type":"RATE"},"fee_type":"USAGE","id":"product_id_78","name":"sample","product_family_id":"product_family_id_47"}],"pagination_meta":{"page":-123456789,"per_page":-123456789,"total_items":-9007199254740993,"total_pages":123456789}}', }); await client.products.list(); assert.deepEqual(requests, ["GET /api/v1/products"]); @@ -22,7 +22,7 @@ test("products.create", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"RATE","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', + body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"CAPACITY","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', }); await client.products.create( CreateProductRequestSerializer.parse( @@ -38,7 +38,7 @@ test("products.retrieve", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"RATE","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', + body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"CAPACITY","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', }); await client.products.retrieve("product_id"); assert.deepEqual(requests, ["GET /api/v1/products/product_id"]); @@ -48,7 +48,7 @@ test("products.update", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"RATE","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', + body: '{"catalog":true,"created_at":"2023-12-31T23:59:59.999-05:30","fee_structure":{"type":"RATE"},"fee_type":"CAPACITY","id":"product_id_13","name":"sample","product_family_id":"product_family_id_99"}', }); await client.products.update( "product_id", diff --git a/tests/api/usage.test.ts b/tests/api/usage.test.ts index e26233b..c356cfd 100644 --- a/tests/api/usage.test.ts +++ b/tests/api/usage.test.ts @@ -7,7 +7,7 @@ test("usage.retrieve_subscription", async () => { const { client, requests } = mock({ status: 200, contentType: "application/json", - body: '{"period_end":"1999-12-31","period_start":"2024-02-29","usage":[{"grouped_usage":[{"dimensions":{"alpha":"sample"},"value":"12345.6789"}],"metric_code":"sample","metric_id":"billable_metric_id_44","metric_name":"sample","total_value":"12345.6789"}]}', + body: '{"period_end":"2024-02-29","period_start":"1999-12-31","usage":[{"grouped_usage":[{"dimensions":{"alpha":"sample"},"value":"-0.000123"}],"metric_code":"sample","metric_id":"billable_metric_id_52","metric_name":"sample","total_value":"12345.6789"}]}', }); await client.usage.retrieveSubscription("subscription_id"); assert.deepEqual(requests, ["GET /api/v1/usage/subscription/subscription_id"]); diff --git a/tests/api/usageCustomer.test.ts b/tests/api/usageCustomer.test.ts new file mode 100644 index 0000000..8517ffa --- /dev/null +++ b/tests/api/usageCustomer.test.ts @@ -0,0 +1,14 @@ +// this file is @generated +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mock } from "./mock.js"; + +test("usage.customer.retrieve_unattributed", async () => { + const { client, requests } = mock({ + status: 200, + contentType: "application/json", + body: '{"period_end":"1999-12-31","period_start":"2024-02-29","usage":[{"from":"2024-03-15T10:30:45.123+02:00","metric_code":"sample","metric_id":"billable_metric_id_44","metric_name":"sample","total_value":"12345.6789","until":"2023-12-31T23:59:59.999-05:30"}]}', + }); + await client.usage.customer.retrieveUnattributed("customer_id"); + assert.deepEqual(requests, ["GET /api/v1/usage/customer/customer_id/unattributed"]); +});