@leaflow/sdk 0.109.0 → 0.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/billing/v1/generated/functions.d.ts +172 -12
  2. package/dist/billing/v1/generated/functions.js +210 -11
  3. package/dist/billing/v1/generated/models.d.ts +115 -3
  4. package/dist/billing/v1/generated/models.js +5 -0
  5. package/dist/billing/v1/generated/schemas.zod.d.ts +116 -10
  6. package/dist/billing/v1/generated/schemas.zod.js +130 -10
  7. package/dist/billing/v1/generated/validators/cancelSubscriptionRequest.zod.d.ts +21 -0
  8. package/dist/billing/v1/generated/validators/cancelSubscriptionRequest.zod.js +21 -0
  9. package/dist/billing/v1/generated/validators/cancellationCreate.zod.js +1 -1
  10. package/dist/billing/v1/generated/validators/creditNote.zod.d.ts +24 -0
  11. package/dist/billing/v1/generated/validators/creditNote.zod.js +28 -0
  12. package/dist/billing/v1/generated/validators/creditNoteItem.zod.d.ts +17 -0
  13. package/dist/billing/v1/generated/validators/creditNoteItem.zod.js +16 -0
  14. package/dist/billing/v1/generated/validators/creditNoteItemList.zod.d.ts +24 -0
  15. package/dist/billing/v1/generated/validators/creditNoteItemList.zod.js +14 -0
  16. package/dist/billing/v1/generated/validators/creditNoteList.zod.d.ts +31 -0
  17. package/dist/billing/v1/generated/validators/creditNoteList.zod.js +14 -0
  18. package/dist/billing/v1/generated/validators/invoice.zod.d.ts +2 -0
  19. package/dist/billing/v1/generated/validators/invoice.zod.js +3 -1
  20. package/dist/billing/v1/generated/validators/invoiceList.zod.d.ts +2 -0
  21. package/dist/billing/v1/generated/validators/invoiceSummary.zod.d.ts +2 -0
  22. package/dist/billing/v1/generated/validators/invoiceSummary.zod.js +4 -1
  23. package/dist/billing/v1/generated/validators/listCreditNoteItemsParams.zod.d.ts +18 -0
  24. package/dist/billing/v1/generated/validators/listCreditNoteItemsParams.zod.js +24 -0
  25. package/dist/billing/v1/generated/validators/listCreditNotesParams.zod.d.ts +20 -0
  26. package/dist/billing/v1/generated/validators/listCreditNotesParams.zod.js +26 -0
  27. package/dist/billing/v1/generated/validators/order.zod.d.ts +2 -1
  28. package/dist/billing/v1/generated/validators/order.zod.js +0 -1
  29. package/dist/billing/v1/generated/validators/orderCancel.zod.d.ts +14 -0
  30. package/dist/billing/v1/generated/validators/orderCancel.zod.js +17 -0
  31. package/dist/billing/v1/generated/validators/orderList.zod.d.ts +2 -1
  32. package/dist/billing/v1/generated/validators/subscription.zod.d.ts +1 -0
  33. package/dist/billing/v1/generated/validators/subscription.zod.js +1 -1
  34. package/dist/billing/v1/generated/validators/subscriptionList.zod.d.ts +1 -0
  35. package/dist/billing/v1/generated/validators/terminateSubscriptionRequest.zod.d.ts +15 -0
  36. package/dist/billing/v1/generated/validators/terminateSubscriptionRequest.zod.js +16 -0
  37. package/dist/routes.d.ts +48 -0
  38. package/dist/routes.js +54 -0
  39. package/package.json +1 -1
@@ -5,7 +5,7 @@
5
5
  * Products, prices, orders, subscriptions and account billing. Financial operations require an account access token and billing-account authorization. Public catalogue operations declare no security requirement.
6
6
  * OpenAPI spec version: v1
7
7
  */
8
- import type { AccountBalance, ActiveResourceList, AllowanceList, AutoRenewSet, BillingAccount, BillingAccountCreate, BillingAccountList, BillingAccountUpdate, Cancellation, CancellationCreate, CancellationList, CheckoutOrderRequest, CreditGrantList, CurrencyList, DiscountList, EntitlementList, Error, ErrorResponse, GetPlanHeaders, GetPriceHeaders, GetProductHeaders, Invoice, InvoiceItemList, InvoiceList, ListAccountDiscountsParams, ListActiveResourcesParams, ListAllowancesParams, ListBillingAccountsParams, ListCancellationsParams, ListCreditGrantsParams, ListCurrenciesParams, ListEntitlementsParams, ListInvoiceItemsParams, ListInvoicesParams, ListOrderItemsParams, ListOrdersParams, ListPaymentMethodsParams, ListPaymentOptionsParams, ListPlansHeaders, ListPlansParams, ListPricesByPlanHeaders, ListPricesByPlanParams, ListPricesHeaders, ListPricesParams, ListProductsHeaders, ListProductsParams, ListProjectAssignmentsParams, ListRatesHeaders, ListRatesParams, ListRefundsParams, ListRenewalPricesParams, ListSpendParams, ListSubscriptionsParams, ListTopUpsParams, ListTransactionsParams, ListUsageChargesParams, MeteredUsage, NotModifiedResponse, Order, OrderItemList, OrderList, PayInvoiceRequest, PayTogetherRequest, PaymentMethod, PaymentMethodList, PaymentMethodSetup, PaymentMethodSetupResult, PaymentOptionList, PaymentPreview, PaymentResult, Plan, PlanList, PreviewInvoicePaymentParams, Price, PriceList, Product, ProductID, ProductList, ProjectAssignment, ProjectAssignmentList, Quote, QuoteRequest, RateList, RefundList, RenewRequest, RenewalOrderRequest, RenewalPriceList, SetProjectAssignmentRequest, SpendRowList, Subscription, SubscriptionList, TopUp, TopUpCreate, TopUpList, TransactionList, UsageChargeList } from "./models.js";
8
+ import type { AccountBalance, ActiveResourceList, AllowanceList, AutoRenewSet, BillingAccount, BillingAccountCreate, BillingAccountList, BillingAccountUpdate, CancelSubscriptionRequest, Cancellation, CancellationCreate, CancellationList, CheckoutOrderRequest, CreditGrantList, CreditNote, CreditNoteItemList, CreditNoteList, CurrencyList, DiscountList, EntitlementList, Error, ErrorResponse, GetPlanHeaders, GetPriceHeaders, GetProductHeaders, Invoice, InvoiceItemList, InvoiceList, ListAccountDiscountsParams, ListActiveResourcesParams, ListAllowancesParams, ListBillingAccountsParams, ListCancellationsParams, ListCreditGrantsParams, ListCreditNoteItemsParams, ListCreditNotesParams, ListCurrenciesParams, ListEntitlementsParams, ListInvoiceItemsParams, ListInvoicesParams, ListOrderItemsParams, ListOrdersParams, ListPaymentMethodsParams, ListPaymentOptionsParams, ListPlansHeaders, ListPlansParams, ListPricesByPlanHeaders, ListPricesByPlanParams, ListPricesHeaders, ListPricesParams, ListProductsHeaders, ListProductsParams, ListProjectAssignmentsParams, ListRatesHeaders, ListRatesParams, ListRefundsParams, ListRenewalPricesParams, ListSpendParams, ListSubscriptionsParams, ListTopUpsParams, ListTransactionsParams, ListUsageChargesParams, MeteredUsage, NotModifiedResponse, Order, OrderCancel, OrderItemList, OrderList, PayInvoiceRequest, PayTogetherRequest, PaymentMethod, PaymentMethodList, PaymentMethodSetup, PaymentMethodSetupResult, PaymentOptionList, PaymentPreview, PaymentResult, Plan, PlanList, PreviewInvoicePaymentParams, Price, PriceList, Product, ProductID, ProductList, ProjectAssignment, ProjectAssignmentList, Quote, QuoteRequest, RateList, RefundList, RenewRequest, RenewalOrderRequest, RenewalPriceList, SetProjectAssignmentRequest, SpendRowList, Subscription, SubscriptionList, TerminateSubscriptionRequest, TopUp, TopUpCreate, TopUpList, TransactionList, UsageChargeList } from "./models.js";
9
9
  export type HTTPStatusCode1xx = 100 | 101 | 102 | 103;
10
10
  export type HTTPStatusCode2xx = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207;
11
11
  export type HTTPStatusCode3xx = 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308;
@@ -729,6 +729,69 @@ export declare const getListCreditGrantsUrl: (params?: ListCreditGrantsParams) =
729
729
  * @summary List credit grants
730
730
  */
731
731
  export declare const listCreditGrants: (params?: ListCreditGrantsParams, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<listCreditGrantsResponse>;
732
+ export type listCreditNotesResponse200 = {
733
+ data: CreditNoteList;
734
+ status: 200;
735
+ };
736
+ export type listCreditNotesResponseDefault = {
737
+ data: ErrorResponse;
738
+ status: Exclude<HTTPStatusCodes, 200>;
739
+ };
740
+ export type listCreditNotesResponseSuccess = listCreditNotesResponse200 & {
741
+ headers: Headers;
742
+ };
743
+ export type listCreditNotesResponseError = listCreditNotesResponseDefault & {
744
+ headers: Headers;
745
+ };
746
+ export type listCreditNotesResponse = listCreditNotesResponseSuccess | listCreditNotesResponseError;
747
+ export declare const getListCreditNotesUrl: (params?: ListCreditNotesParams) => string;
748
+ /**
749
+ * Newest issued_at first, then ID. Requires authorization for the invoice's billing account. Filters narrow authorized results and apply before counting and paging.
750
+ * @summary List credit notes
751
+ */
752
+ export declare const listCreditNotes: (params?: ListCreditNotesParams, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<listCreditNotesResponse>;
753
+ export type getCreditNoteResponse200 = {
754
+ data: CreditNote;
755
+ status: 200;
756
+ };
757
+ export type getCreditNoteResponseDefault = {
758
+ data: ErrorResponse;
759
+ status: Exclude<HTTPStatusCodes, 200>;
760
+ };
761
+ export type getCreditNoteResponseSuccess = getCreditNoteResponse200 & {
762
+ headers: Headers;
763
+ };
764
+ export type getCreditNoteResponseError = getCreditNoteResponseDefault & {
765
+ headers: Headers;
766
+ };
767
+ export type getCreditNoteResponse = getCreditNoteResponseSuccess | getCreditNoteResponseError;
768
+ export declare const getGetCreditNoteUrl: (creditNoteId: string) => string;
769
+ /**
770
+ * Requires authorization for the invoice's billing account.
771
+ * @summary Get credit note
772
+ */
773
+ export declare const getCreditNote: (creditNoteId: string, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<getCreditNoteResponse>;
774
+ export type listCreditNoteItemsResponse200 = {
775
+ data: CreditNoteItemList;
776
+ status: 200;
777
+ };
778
+ export type listCreditNoteItemsResponseDefault = {
779
+ data: ErrorResponse;
780
+ status: Exclude<HTTPStatusCodes, 200>;
781
+ };
782
+ export type listCreditNoteItemsResponseSuccess = listCreditNoteItemsResponse200 & {
783
+ headers: Headers;
784
+ };
785
+ export type listCreditNoteItemsResponseError = listCreditNoteItemsResponseDefault & {
786
+ headers: Headers;
787
+ };
788
+ export type listCreditNoteItemsResponse = listCreditNoteItemsResponseSuccess | listCreditNoteItemsResponseError;
789
+ export declare const getListCreditNoteItemsUrl: (creditNoteId: string, params?: ListCreditNoteItemsParams) => string;
790
+ /**
791
+ * The original invoice lines reduced by this note. Requires authorization for their invoice's billing account.
792
+ * @summary List credit note items
793
+ */
794
+ export declare const listCreditNoteItems: (creditNoteId: string, params?: ListCreditNoteItemsParams, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<listCreditNoteItemsResponse>;
732
795
  export type listRefundsResponse200 = {
733
796
  data: RefundList;
734
797
  status: 200;
@@ -815,6 +878,96 @@ export declare const getGetSubscriptionUrl: (subscriptionId: string) => string;
815
878
  * @summary Get subscription
816
879
  */
817
880
  export declare const getSubscription: (subscriptionId: string, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<getSubscriptionResponse>;
881
+ export type deleteSubscriptionResponse204 = {
882
+ data: void;
883
+ status: 204;
884
+ };
885
+ export type deleteSubscriptionResponseDefault = {
886
+ data: ErrorResponse;
887
+ status: Exclude<HTTPStatusCodes, 204>;
888
+ };
889
+ export type deleteSubscriptionResponseSuccess = deleteSubscriptionResponse204 & {
890
+ headers: Headers;
891
+ };
892
+ export type deleteSubscriptionResponseError = deleteSubscriptionResponseDefault & {
893
+ headers: Headers;
894
+ };
895
+ export type deleteSubscriptionResponse = deleteSubscriptionResponseSuccess | deleteSubscriptionResponseError;
896
+ export declare const getDeleteSubscriptionUrl: (subscriptionId: string) => string;
897
+ /**
898
+ * Hides an already terminated subscription from your subscription list and detail. Your account
899
+ * access token must authorize the subscription's current billing account. Billing and financial
900
+ * history remain available. This operation cannot force termination, skip cleanup, or delete a
901
+ * pending, provisioning, active or suspended subscription. Other states, including canceled, are
902
+ * refused with 409 BILLING_SUBSCRIPTION_NOT_TERMINATED and status in error params. A canceled
903
+ * subscription must first be converted to terminated. Sends no cleanup command and creates no refund.
904
+ * @summary Delete subscription
905
+ */
906
+ export declare const deleteSubscription: (subscriptionId: string, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<deleteSubscriptionResponse>;
907
+ export type cancelSubscriptionResponse202 = {
908
+ data: Cancellation;
909
+ status: 202;
910
+ };
911
+ export type cancelSubscriptionResponseDefault = {
912
+ data: ErrorResponse;
913
+ status: Exclude<HTTPStatusCodes, 202>;
914
+ };
915
+ export type cancelSubscriptionResponseSuccess = cancelSubscriptionResponse202 & {
916
+ headers: Headers;
917
+ };
918
+ export type cancelSubscriptionResponseError = cancelSubscriptionResponseDefault & {
919
+ headers: Headers;
920
+ };
921
+ export type cancelSubscriptionResponse = cancelSubscriptionResponseSuccess | cancelSubscriptionResponseError;
922
+ export declare const getCancelSubscriptionUrl: (subscriptionId: string) => string;
923
+ /**
924
+ * Requests cancellation on the purchase's agreed terms. Uses the same quotation, eligibility,
925
+ * metering and original-payment-source refund rules as creating a cancellation.
926
+ * Supply the refund amount from create-quote with this subscription in cancellation.subscription_ids.
927
+ * Your account access token must authorize the subscription's current billing account.
928
+ *
929
+ * Immediate cancellation asks the owning service to clean up now. Period-end cancellation keeps
930
+ * the subscription active or suspended until the paid term ends. Neither payment nor acceptance
931
+ * of this request proves cleanup. The subscription becomes canceled only after the service
932
+ * confirms release and the end of metering; follow the returned cancellation for progress.
933
+ *
934
+ * Related subscriptions released together must be submitted as one group to create-cancellation.
935
+ * Pending or provisioning purchases are canceled through their order, not this operation.
936
+ * Repeating the same open cancellation returns it without another refund or command.
937
+ * @summary Cancel subscription
938
+ */
939
+ export declare const cancelSubscription: (subscriptionId: string, cancelSubscriptionRequest: CancelSubscriptionRequest, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<cancelSubscriptionResponse>;
940
+ export type terminateSubscriptionResponse200 = {
941
+ data: Subscription;
942
+ status: 200;
943
+ };
944
+ export type terminateSubscriptionResponseDefault = {
945
+ data: ErrorResponse;
946
+ status: Exclude<HTTPStatusCodes, 200>;
947
+ };
948
+ export type terminateSubscriptionResponseSuccess = terminateSubscriptionResponse200 & {
949
+ headers: Headers;
950
+ };
951
+ export type terminateSubscriptionResponseError = terminateSubscriptionResponseDefault & {
952
+ headers: Headers;
953
+ };
954
+ export type terminateSubscriptionResponse = terminateSubscriptionResponseSuccess | terminateSubscriptionResponseError;
955
+ export declare const getTerminateSubscriptionUrl: (subscriptionId: string) => string;
956
+ /**
957
+ * Converts an already canceled subscription to terminated so it can subsequently be hidden.
958
+ * Your account access token must authorize the subscription's current billing account. Preserves
959
+ * the original billing end and financial history, sends no new cleanup command, and creates no
960
+ * credit note or refund. A terminated subscription is returned unchanged on repeat; a deleted
961
+ * subscription remains hidden from tenant reads.
962
+ *
963
+ * Account holders cannot force termination of pending, provisioning, active or suspended
964
+ * subscriptions. These states are refused with 400 BILLING_SUBSCRIPTION_INVALID and status in
965
+ * error params. Use cancellation under the agreed terms to end service. Immediate commercial
966
+ * termination is reserved for administrators and the owning service. The audited reason does
967
+ * not grant permission to terminate. No force, skip-cleanup or refund options are accepted.
968
+ * @summary Terminate subscription
969
+ */
970
+ export declare const terminateSubscription: (subscriptionId: string, terminateSubscriptionRequest: TerminateSubscriptionRequest, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<terminateSubscriptionResponse>;
818
971
  export type createQuoteResponse200 = {
819
972
  data: Quote;
820
973
  status: 200;
@@ -1228,20 +1381,27 @@ export type cancelOrderResponseError = (cancelOrderResponse409 | cancelOrderResp
1228
1381
  export type cancelOrderResponse = cancelOrderResponseSuccess | cancelOrderResponseError;
1229
1382
  export declare const getCancelOrderUrl: (orderId: string) => string;
1230
1383
  /**
1231
- * Withdraws an unaccepted order without recording a delivery failure. Payment may be absent,
1232
- * partial or complete; the order becomes canceled and any collected amount is automatically
1233
- * returned to its original payment sources. External payment-method refunds can finish
1234
- * asynchronously. Canceling an already canceled order returns it unchanged. A previously failed
1235
- * order keeps its failure outcome. The order and financial history are retained.
1384
+ * Cancels the selected, still-undelivered items of an unaccepted order without recording a
1385
+ * delivery failure. Omit order_item_ids to select every still-pending item, or name one or
1386
+ * more items. Successful items remain delivered and are not refunded. Whole-order and partial
1387
+ * cancellation both require confirmed non-delivery and necessary cleanup. The order keeps
1388
+ * its existing pending phase while any item is still pending; its final outcome follows all
1389
+ * item outcomes. Previously failed items keep their failure outcome.
1390
+ *
1391
+ * Payment may be absent, partial or complete. Confirmed checkout keeps the selected items'
1392
+ * agreed amounts and discounts; credit notes reduce issued invoices, and collected amounts
1393
+ * are returned to their original payment sources. When checkout has not been confirmed, the
1394
+ * remaining items are quoted again. External payment-method refunds can finish asynchronously.
1395
+ * The order and financial history are retained; the same cancellation does not refund twice.
1236
1396
  *
1237
- * Refused once the order is accepted: its owning service must coordinate cancellation during
1238
- * provisioning and confirm non-delivery and necessary cleanup before recording cancellation.
1239
- * Delivered items are ended through subscription cancellation. An unknown or in-flight payment
1240
- * outcome must first be reconciled; it is not assumed to be unpaid. Scheduled changes continue
1241
- * to be canceled through the service that owns them. Refund quotations use CreateQuote.refund.
1397
+ * Once the order is accepted, its owning service coordinates cancellation and confirms
1398
+ * non-delivery and cleanup through the cancellation RPC. Delivered items are ended through
1399
+ * subscription cancellation. Unknown delivery or payment outcomes are not refund evidence;
1400
+ * in-flight or unknown payments must be reconciled first. Scheduled changes continue to be
1401
+ * canceled through the owning service. Refund quotations use CreateQuote.refund.
1242
1402
  * @summary Cancel order
1243
1403
  */
1244
- export declare const cancelOrder: (orderId: string, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<cancelOrderResponse>;
1404
+ export declare const cancelOrder: (orderId: string, orderCancel?: OrderCancel, options?: RequestInit, fetchFn?: typeof globalThis.fetch) => Promise<cancelOrderResponse>;
1245
1405
  export type listOrderItemsResponse200 = {
1246
1406
  data: OrderItemList;
1247
1407
  status: 200;
@@ -805,6 +805,72 @@ export const listCreditGrants = async (params, options, fetchFn) => {
805
805
  const data = body ? JSON.parse(body) : {};
806
806
  return { data, status: res.status, headers: res.headers };
807
807
  };
808
+ export const getListCreditNotesUrl = (params) => {
809
+ const normalizedParams = new URLSearchParams();
810
+ Object.entries(params || {}).forEach(([key, value]) => {
811
+ if (value !== undefined) {
812
+ normalizedParams.append(key, value === null ? "null" : String(value));
813
+ }
814
+ });
815
+ const stringifiedParams = normalizedParams.toString();
816
+ return stringifiedParams.length > 0
817
+ ? `https://billing.leaflow.cloud/api/v1/credit-notes?${stringifiedParams}`
818
+ : `https://billing.leaflow.cloud/api/v1/credit-notes`;
819
+ };
820
+ /**
821
+ * Newest issued_at first, then ID. Requires authorization for the invoice's billing account. Filters narrow authorized results and apply before counting and paging.
822
+ * @summary List credit notes
823
+ */
824
+ export const listCreditNotes = async (params, options, fetchFn) => {
825
+ const res = await (fetchFn ?? fetch)(getListCreditNotesUrl(params), {
826
+ ...options,
827
+ method: "GET",
828
+ });
829
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
830
+ const data = body ? JSON.parse(body) : {};
831
+ return { data, status: res.status, headers: res.headers };
832
+ };
833
+ export const getGetCreditNoteUrl = (creditNoteId) => {
834
+ return `https://billing.leaflow.cloud/api/v1/credit-notes/${encodeURIComponent(String(creditNoteId))}`;
835
+ };
836
+ /**
837
+ * Requires authorization for the invoice's billing account.
838
+ * @summary Get credit note
839
+ */
840
+ export const getCreditNote = async (creditNoteId, options, fetchFn) => {
841
+ const res = await (fetchFn ?? fetch)(getGetCreditNoteUrl(creditNoteId), {
842
+ ...options,
843
+ method: "GET",
844
+ });
845
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
846
+ const data = body ? JSON.parse(body) : {};
847
+ return { data, status: res.status, headers: res.headers };
848
+ };
849
+ export const getListCreditNoteItemsUrl = (creditNoteId, params) => {
850
+ const normalizedParams = new URLSearchParams();
851
+ Object.entries(params || {}).forEach(([key, value]) => {
852
+ if (value !== undefined) {
853
+ normalizedParams.append(key, value === null ? "null" : String(value));
854
+ }
855
+ });
856
+ const stringifiedParams = normalizedParams.toString();
857
+ return stringifiedParams.length > 0
858
+ ? `https://billing.leaflow.cloud/api/v1/credit-notes/${encodeURIComponent(String(creditNoteId))}/items?${stringifiedParams}`
859
+ : `https://billing.leaflow.cloud/api/v1/credit-notes/${encodeURIComponent(String(creditNoteId))}/items`;
860
+ };
861
+ /**
862
+ * The original invoice lines reduced by this note. Requires authorization for their invoice's billing account.
863
+ * @summary List credit note items
864
+ */
865
+ export const listCreditNoteItems = async (creditNoteId, params, options, fetchFn) => {
866
+ const res = await (fetchFn ?? fetch)(getListCreditNoteItemsUrl(creditNoteId, params), {
867
+ ...options,
868
+ method: "GET",
869
+ });
870
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
871
+ const data = body ? JSON.parse(body) : {};
872
+ return { data, status: res.status, headers: res.headers };
873
+ };
808
874
  export const getListRefundsUrl = (params) => {
809
875
  const normalizedParams = new URLSearchParams();
810
876
  Object.entries(params || {}).forEach(([key, value]) => {
@@ -898,6 +964,115 @@ export const getSubscription = async (subscriptionId, options, fetchFn) => {
898
964
  const data = body ? JSON.parse(body) : {};
899
965
  return { data, status: res.status, headers: res.headers };
900
966
  };
967
+ export const getDeleteSubscriptionUrl = (subscriptionId) => {
968
+ return `https://billing.leaflow.cloud/api/v1/subscriptions/${encodeURIComponent(String(subscriptionId))}`;
969
+ };
970
+ /**
971
+ * Hides an already terminated subscription from your subscription list and detail. Your account
972
+ * access token must authorize the subscription's current billing account. Billing and financial
973
+ * history remain available. This operation cannot force termination, skip cleanup, or delete a
974
+ * pending, provisioning, active or suspended subscription. Other states, including canceled, are
975
+ * refused with 409 BILLING_SUBSCRIPTION_NOT_TERMINATED and status in error params. A canceled
976
+ * subscription must first be converted to terminated. Sends no cleanup command and creates no refund.
977
+ * @summary Delete subscription
978
+ */
979
+ export const deleteSubscription = async (subscriptionId, options, fetchFn) => {
980
+ const res = await (fetchFn ?? fetch)(getDeleteSubscriptionUrl(subscriptionId), {
981
+ ...options,
982
+ method: "DELETE",
983
+ });
984
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
985
+ const data = body ? JSON.parse(body) : undefined;
986
+ return { data, status: res.status, headers: res.headers };
987
+ };
988
+ export const getCancelSubscriptionUrl = (subscriptionId) => {
989
+ return `https://billing.leaflow.cloud/api/v1/subscriptions/${encodeURIComponent(String(subscriptionId))}/cancel`;
990
+ };
991
+ /**
992
+ * Requests cancellation on the purchase's agreed terms. Uses the same quotation, eligibility,
993
+ * metering and original-payment-source refund rules as creating a cancellation.
994
+ * Supply the refund amount from create-quote with this subscription in cancellation.subscription_ids.
995
+ * Your account access token must authorize the subscription's current billing account.
996
+ *
997
+ * Immediate cancellation asks the owning service to clean up now. Period-end cancellation keeps
998
+ * the subscription active or suspended until the paid term ends. Neither payment nor acceptance
999
+ * of this request proves cleanup. The subscription becomes canceled only after the service
1000
+ * confirms release and the end of metering; follow the returned cancellation for progress.
1001
+ *
1002
+ * Related subscriptions released together must be submitted as one group to create-cancellation.
1003
+ * Pending or provisioning purchases are canceled through their order, not this operation.
1004
+ * Repeating the same open cancellation returns it without another refund or command.
1005
+ * @summary Cancel subscription
1006
+ */
1007
+ export const cancelSubscription = async (subscriptionId, cancelSubscriptionRequest, options, fetchFn) => {
1008
+ const getHeaders = (h) => {
1009
+ if (!h)
1010
+ return {};
1011
+ if (h instanceof Headers)
1012
+ return Object.fromEntries(h.entries());
1013
+ if (Symbol.iterator in h) {
1014
+ return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1015
+ }
1016
+ const headers = {};
1017
+ for (const [name, value] of Object.entries(h)) {
1018
+ if (value !== undefined)
1019
+ headers[name] = value;
1020
+ }
1021
+ return headers;
1022
+ };
1023
+ const res = await (fetchFn ?? fetch)(getCancelSubscriptionUrl(subscriptionId), {
1024
+ ...options,
1025
+ method: "POST",
1026
+ headers: { "Content-Type": "application/json", ...getHeaders(options?.headers) },
1027
+ body: JSON.stringify(cancelSubscriptionRequest),
1028
+ });
1029
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
1030
+ const data = body ? JSON.parse(body) : {};
1031
+ return { data, status: res.status, headers: res.headers };
1032
+ };
1033
+ export const getTerminateSubscriptionUrl = (subscriptionId) => {
1034
+ return `https://billing.leaflow.cloud/api/v1/subscriptions/${encodeURIComponent(String(subscriptionId))}/terminate`;
1035
+ };
1036
+ /**
1037
+ * Converts an already canceled subscription to terminated so it can subsequently be hidden.
1038
+ * Your account access token must authorize the subscription's current billing account. Preserves
1039
+ * the original billing end and financial history, sends no new cleanup command, and creates no
1040
+ * credit note or refund. A terminated subscription is returned unchanged on repeat; a deleted
1041
+ * subscription remains hidden from tenant reads.
1042
+ *
1043
+ * Account holders cannot force termination of pending, provisioning, active or suspended
1044
+ * subscriptions. These states are refused with 400 BILLING_SUBSCRIPTION_INVALID and status in
1045
+ * error params. Use cancellation under the agreed terms to end service. Immediate commercial
1046
+ * termination is reserved for administrators and the owning service. The audited reason does
1047
+ * not grant permission to terminate. No force, skip-cleanup or refund options are accepted.
1048
+ * @summary Terminate subscription
1049
+ */
1050
+ export const terminateSubscription = async (subscriptionId, terminateSubscriptionRequest, options, fetchFn) => {
1051
+ const getHeaders = (h) => {
1052
+ if (!h)
1053
+ return {};
1054
+ if (h instanceof Headers)
1055
+ return Object.fromEntries(h.entries());
1056
+ if (Symbol.iterator in h) {
1057
+ return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1058
+ }
1059
+ const headers = {};
1060
+ for (const [name, value] of Object.entries(h)) {
1061
+ if (value !== undefined)
1062
+ headers[name] = value;
1063
+ }
1064
+ return headers;
1065
+ };
1066
+ const res = await (fetchFn ?? fetch)(getTerminateSubscriptionUrl(subscriptionId), {
1067
+ ...options,
1068
+ method: "POST",
1069
+ headers: { "Content-Type": "application/json", ...getHeaders(options?.headers) },
1070
+ body: JSON.stringify(terminateSubscriptionRequest),
1071
+ });
1072
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
1073
+ const data = body ? JSON.parse(body) : {};
1074
+ return { data, status: res.status, headers: res.headers };
1075
+ };
901
1076
  export const getCreateQuoteUrl = () => {
902
1077
  return `https://billing.leaflow.cloud/api/v1/quotes`;
903
1078
  };
@@ -1351,23 +1526,47 @@ export const getCancelOrderUrl = (orderId) => {
1351
1526
  return `https://billing.leaflow.cloud/api/v1/orders/${encodeURIComponent(String(orderId))}/cancel`;
1352
1527
  };
1353
1528
  /**
1354
- * Withdraws an unaccepted order without recording a delivery failure. Payment may be absent,
1355
- * partial or complete; the order becomes canceled and any collected amount is automatically
1356
- * returned to its original payment sources. External payment-method refunds can finish
1357
- * asynchronously. Canceling an already canceled order returns it unchanged. A previously failed
1358
- * order keeps its failure outcome. The order and financial history are retained.
1529
+ * Cancels the selected, still-undelivered items of an unaccepted order without recording a
1530
+ * delivery failure. Omit order_item_ids to select every still-pending item, or name one or
1531
+ * more items. Successful items remain delivered and are not refunded. Whole-order and partial
1532
+ * cancellation both require confirmed non-delivery and necessary cleanup. The order keeps
1533
+ * its existing pending phase while any item is still pending; its final outcome follows all
1534
+ * item outcomes. Previously failed items keep their failure outcome.
1535
+ *
1536
+ * Payment may be absent, partial or complete. Confirmed checkout keeps the selected items'
1537
+ * agreed amounts and discounts; credit notes reduce issued invoices, and collected amounts
1538
+ * are returned to their original payment sources. When checkout has not been confirmed, the
1539
+ * remaining items are quoted again. External payment-method refunds can finish asynchronously.
1540
+ * The order and financial history are retained; the same cancellation does not refund twice.
1359
1541
  *
1360
- * Refused once the order is accepted: its owning service must coordinate cancellation during
1361
- * provisioning and confirm non-delivery and necessary cleanup before recording cancellation.
1362
- * Delivered items are ended through subscription cancellation. An unknown or in-flight payment
1363
- * outcome must first be reconciled; it is not assumed to be unpaid. Scheduled changes continue
1364
- * to be canceled through the service that owns them. Refund quotations use CreateQuote.refund.
1542
+ * Once the order is accepted, its owning service coordinates cancellation and confirms
1543
+ * non-delivery and cleanup through the cancellation RPC. Delivered items are ended through
1544
+ * subscription cancellation. Unknown delivery or payment outcomes are not refund evidence;
1545
+ * in-flight or unknown payments must be reconciled first. Scheduled changes continue to be
1546
+ * canceled through the owning service. Refund quotations use CreateQuote.refund.
1365
1547
  * @summary Cancel order
1366
1548
  */
1367
- export const cancelOrder = async (orderId, options, fetchFn) => {
1549
+ export const cancelOrder = async (orderId, orderCancel, options, fetchFn) => {
1550
+ const getHeaders = (h) => {
1551
+ if (!h)
1552
+ return {};
1553
+ if (h instanceof Headers)
1554
+ return Object.fromEntries(h.entries());
1555
+ if (Symbol.iterator in h) {
1556
+ return Object.fromEntries(Array.from(h, (entry) => Array.from(entry)));
1557
+ }
1558
+ const headers = {};
1559
+ for (const [name, value] of Object.entries(h)) {
1560
+ if (value !== undefined)
1561
+ headers[name] = value;
1562
+ }
1563
+ return headers;
1564
+ };
1368
1565
  const res = await (fetchFn ?? fetch)(getCancelOrderUrl(orderId), {
1369
1566
  ...options,
1370
1567
  method: "POST",
1568
+ headers: { "Content-Type": "application/json", ...getHeaders(options?.headers) },
1569
+ body: JSON.stringify(orderCancel),
1371
1570
  });
1372
1571
  const body = [204, 205, 304].includes(res.status) ? null : await res.text();
1373
1572
  const data = body ? JSON.parse(body) : {};
@@ -30,6 +30,14 @@ export declare const RefundPolicy: {
30
30
  readonly none: "none";
31
31
  readonly prorated: "prorated";
32
32
  };
33
+ export interface OrderCancel {
34
+ /**
35
+ * Omit to select all still-pending items. Explicit selections name one or more items of this order; successful items cannot be reversed here.
36
+ * @minItems 1
37
+ * @maxItems 100
38
+ */
39
+ order_item_ids?: string[];
40
+ }
33
41
  /**
34
42
  * A decimal string, in the currency stated alongside it.
35
43
  *
@@ -1304,7 +1312,11 @@ export interface Invoice {
1304
1312
  /** Subtotal less discount plus tax. Balance and credit grants are payment sources, not reductions of the receivable. */
1305
1313
  total: Money;
1306
1314
  amount_paid?: Money;
1307
- /** What is still collectible after applied credits and successful payments; never below zero. A draft order invoice is not collectible until checkout confirms it, and a paid or void invoice has none. */
1315
+ /** Issued, non-void credit notes that reduced unpaid receivables. Does not rewrite the original invoice total. */
1316
+ unpaid_credit_notes_amount: Money;
1317
+ /** Issued credit notes against payments already received. This is a return obligation, not evidence of completed refunds. */
1318
+ paid_credit_notes_amount: Money;
1319
+ /** What is still collectible after unpaid credit notes and successful payments; never below zero. A draft order invoice is not collectible until checkout confirms it, and a paid or void invoice has none. */
1308
1320
  amount_due: Money;
1309
1321
  /** @nullable */
1310
1322
  period_start?: string | null;
@@ -1416,6 +1428,50 @@ export interface CreditGrantList {
1416
1428
  items: CreditGrant[];
1417
1429
  pagination: OffsetPagination;
1418
1430
  }
1431
+ export type CreditNoteStatus = (typeof CreditNoteStatus)[keyof typeof CreditNoteStatus];
1432
+ export declare const CreditNoteStatus: {
1433
+ readonly issued: "issued";
1434
+ readonly void: "void";
1435
+ };
1436
+ /**
1437
+ * An issued invoice reduction. Its credited amount is unpaid_amount plus paid_amount. A paid credit records a return obligation; refund_id identifies its refund, whose outcome may still be pending. Original invoice amounts remain unchanged.
1438
+ */
1439
+ export interface CreditNote {
1440
+ id: string;
1441
+ invoice_id: string;
1442
+ currency: string;
1443
+ issued_at: string;
1444
+ status: CreditNoteStatus;
1445
+ /**
1446
+ * When this note was voided; null while issued.
1447
+ * @nullable
1448
+ */
1449
+ voided_at: string | null;
1450
+ /** The reduction of unpaid receivables. A void note no longer reduces what is due. */
1451
+ unpaid_amount: Money;
1452
+ /** The credited part of payments already received. This is not proof that its refund has completed. */
1453
+ paid_amount: Money;
1454
+ /**
1455
+ * The refund to the original payment sources, or null when no paid amount was credited.
1456
+ * @nullable
1457
+ */
1458
+ refund_id: string | null;
1459
+ }
1460
+ export interface CreditNoteItem {
1461
+ id: string;
1462
+ credit_note_id: string;
1463
+ invoice_item_id: string;
1464
+ unpaid_amount: Money;
1465
+ paid_amount: Money;
1466
+ }
1467
+ export interface CreditNoteList {
1468
+ items: CreditNote[];
1469
+ pagination: OffsetPagination;
1470
+ }
1471
+ export interface CreditNoteItemList {
1472
+ items: CreditNoteItem[];
1473
+ pagination: OffsetPagination;
1474
+ }
1419
1475
  /**
1420
1476
  * Use balance_amount, credit_amount and gateway_amount, which also show a refund split between several destinations.
1421
1477
  * @deprecated
@@ -1623,6 +1679,7 @@ export declare const SubscriptionStatus: {
1623
1679
  readonly suspended: "suspended";
1624
1680
  readonly canceled: "canceled";
1625
1681
  readonly terminated: "terminated";
1682
+ readonly deleted: "deleted";
1626
1683
  };
1627
1684
  /**
1628
1685
  * An independently billed purchase relationship, separate from the owning service's resource.
@@ -1911,8 +1968,12 @@ export interface InvoiceSummary {
1911
1968
  tax_amount: string;
1912
1969
  total: string;
1913
1970
  amount_paid: string;
1971
+ /** Issued, non-void credit notes that reduced unpaid receivables. Does not rewrite the original invoice total. */
1972
+ unpaid_credit_notes_amount: Money;
1973
+ /** Issued credit notes against payments already received. This is a return obligation, not evidence of completed refunds. */
1974
+ paid_credit_notes_amount: Money;
1914
1975
  /**
1915
- * What is still collectible after applied credits and successful payments; never below zero.
1976
+ * What is still collectible after unpaid credit notes and successful payments; never below zero.
1916
1977
  * @pattern ^\d+(\.\d{1,10})?$
1917
1978
  */
1918
1979
  amount_due: string;
@@ -2046,7 +2107,6 @@ export interface Order {
2046
2107
  /** How the order was paid. Absent until it is paid. */
2047
2108
  paid_with?: PaidWith;
2048
2109
  account?: AccountIdentity;
2049
- cancel_reason?: string;
2050
2110
  change_effective_at?: string;
2051
2111
  id: string;
2052
2112
  /**
@@ -2587,6 +2647,22 @@ export interface CursorPagination {
2587
2647
  /** @nullable */
2588
2648
  next_cursor?: string | null;
2589
2649
  }
2650
+ export interface TerminateSubscriptionRequest {
2651
+ /**
2652
+ * @minLength 8
2653
+ * @maxLength 1024
2654
+ */
2655
+ reason: string;
2656
+ }
2657
+ export interface CancelSubscriptionRequest {
2658
+ mode: TerminationPolicy;
2659
+ /** For immediate cancellation, the quoted whole-second refund basis. Now when omitted. */
2660
+ proration_date?: string;
2661
+ /** The cancellation quote's refundable amount, including an explicit zero. */
2662
+ expected_refundable_amount: Money & string;
2663
+ /** @maxLength 1024 */
2664
+ reason?: string;
2665
+ }
2590
2666
  /**
2591
2667
  * Error
2592
2668
  */
@@ -2834,6 +2910,42 @@ export declare const ListCreditGrantsStatus: {
2834
2910
  readonly expired: "expired";
2835
2911
  readonly voided: "voided";
2836
2912
  };
2913
+ export type ListCreditNotesParams = {
2914
+ /**
2915
+ * 1-based page number. Defaults to 1.
2916
+ * @minimum 1
2917
+ * @maximum 2147483647
2918
+ */
2919
+ page?: number;
2920
+ /**
2921
+ * Items per page. Defaults to 50; at most 200.
2922
+ * @minimum 1
2923
+ * @maximum 200
2924
+ */
2925
+ page_size?: number;
2926
+ /**
2927
+ * Restrict to one of your accounts. All of them when omitted.
2928
+ */
2929
+ billing_account_id?: AccountIdQueryParameter;
2930
+ /**
2931
+ * Only the notes for this invoice.
2932
+ */
2933
+ invoice_id?: string;
2934
+ };
2935
+ export type ListCreditNoteItemsParams = {
2936
+ /**
2937
+ * 1-based page number. Defaults to 1.
2938
+ * @minimum 1
2939
+ * @maximum 2147483647
2940
+ */
2941
+ page?: number;
2942
+ /**
2943
+ * Items per page. Defaults to 50; at most 200.
2944
+ * @minimum 1
2945
+ * @maximum 200
2946
+ */
2947
+ page_size?: number;
2948
+ };
2837
2949
  export type ListRefundsParams = {
2838
2950
  /**
2839
2951
  * 1-based page number. Defaults to 1.
@@ -160,6 +160,10 @@ export const CreditGrantStatus = {
160
160
  expired: "expired",
161
161
  voided: "voided",
162
162
  };
163
+ export const CreditNoteStatus = {
164
+ issued: "issued",
165
+ void: "void",
166
+ };
163
167
  export const RefundDestination = {
164
168
  balance: "balance",
165
169
  gateway: "gateway",
@@ -201,6 +205,7 @@ export const SubscriptionStatus = {
201
205
  suspended: "suspended",
202
206
  canceled: "canceled",
203
207
  terminated: "terminated",
208
+ deleted: "deleted",
204
209
  };
205
210
  export const RenewalPriceInterval = {
206
211
  day: "day",