@billkit-eu/sdk 0.3.0 → 0.4.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.
package/dist/index.d.cts CHANGED
@@ -705,6 +705,21 @@ interface AuditLogsListParams extends BaseListParams {
705
705
  resource_type?: string;
706
706
  actor_id?: string;
707
707
  }
708
+ /**
709
+ * `creditNotes.list` params.
710
+ *
711
+ * `invoice_id` answers "was this sale credited, and by how much", which is
712
+ * the question when reconciling one invoice; `customer_id` answers it for
713
+ * everything credited back to one buyer.
714
+ */
715
+ interface CreditNotesListParams extends BaseListParams {
716
+ invoice_id?: string;
717
+ customer_id?: string;
718
+ }
719
+ /** `invoices.void` params. `reason` is recorded on the audit row only. */
720
+ interface VoidInvoiceParams extends IdempotencyOptions {
721
+ reason?: string;
722
+ }
708
723
  interface CreateBillingPortalSessionParams extends IdempotencyOptions {
709
724
  subscription_id: string;
710
725
  return_url: string;
@@ -1131,6 +1146,47 @@ declare class Invoices extends BaseResource {
1131
1146
  iter<T = unknown>(options?: {
1132
1147
  pageSize?: number;
1133
1148
  }): AsyncIterableIterator<T>;
1149
+ /**
1150
+ * Void an invoice: state that the sale was never owed.
1151
+ *
1152
+ * The invoice keeps its number and stays readable — a gapless series
1153
+ * cannot lose a row — and stops being a receivable. Use it for an
1154
+ * invoice that should not have been issued.
1155
+ *
1156
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
1157
+ * `"invoice_not_voidable"`. That is deliberate rather than a
1158
+ * limitation: once the money has moved, "never owed" is false, and the
1159
+ * document that reverses a real sale is a credit note — refund the
1160
+ * payment and one is issued when the refund settles.
1161
+ *
1162
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
1163
+ */
1164
+ void<T = unknown>(id: string, params?: VoidInvoiceParams): Promise<T>;
1165
+ }
1166
+ /**
1167
+ * Read-only access to credit notes — the documents that reverse an
1168
+ * issued invoice.
1169
+ *
1170
+ * There is no create: a credit note is issued for you when a refund
1171
+ * settles, never on request, so that a numbered legal record is only
1172
+ * minted once the money has actually moved. A refund that is still
1173
+ * pending, one that fails, and a refund of a one-off charge that was
1174
+ * never invoiced all produce none.
1175
+ */
1176
+ declare class CreditNotes extends BaseResource {
1177
+ retrieve<T = unknown>(id: string): Promise<T>;
1178
+ /**
1179
+ * Download the rendered credit note PDF as raw bytes. Same storage
1180
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
1181
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
1182
+ */
1183
+ retrievePdf(id: string): Promise<ArrayBuffer>;
1184
+ list<T = unknown>(params?: CreditNotesListParams): Promise<ListResponseEnvelope<T>>;
1185
+ iter<T = unknown>(options?: {
1186
+ pageSize?: number;
1187
+ invoice_id?: string;
1188
+ customer_id?: string;
1189
+ }): AsyncIterableIterator<T>;
1134
1190
  }
1135
1191
  /**
1136
1192
  * Read-only access to the per-tenant audit log.
@@ -1205,6 +1261,7 @@ declare class BillKit {
1205
1261
  readonly coupons: Coupons;
1206
1262
  readonly taxRates: TaxRates;
1207
1263
  readonly invoices: Invoices;
1264
+ readonly creditNotes: CreditNotes;
1208
1265
  readonly auditLogs: AuditLogs;
1209
1266
  readonly payments: Payments;
1210
1267
  readonly billingPortalSessions: BillingPortalSessions;
@@ -1261,7 +1318,7 @@ declare class RateLimitError extends BillKitError {
1261
1318
  });
1262
1319
  }
1263
1320
 
1264
- declare const VERSION = "0.3.0";
1321
+ declare const VERSION = "0.4.0";
1265
1322
 
1266
1323
  /**
1267
1324
  * Verify `BillKit-Signature: t=<unix>,v1=<hex>` headers.
@@ -1293,4 +1350,4 @@ interface VerifyWebhookOptions {
1293
1350
  }
1294
1351
  declare function verifyWebhookSignature<T = unknown>(options: VerifyWebhookOptions): Promise<T>;
1295
1352
 
1296
- export { APIConnectionError, APIError, type AuditLogsListParams, AuthenticationError, type BaseListParams, BillKit, BillKitError, type BillKitLogger, type BillKitOptions, ConflictError, type CreateBillingPortalSessionParams, type CreateCheckoutSessionParams, type CreateCouponParams, type CreateCustomerParams, type CreateOneShotPaymentParams, type CreatePriceParams, type CreateProductParams, type CreateRefundParams, type CreateTaxRateParams, type CreateUsageRecordParams, type CreateWebhookEndpointParams, DEFAULT_RETRY_POLICY, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, type EventsListParams, type IdempotencyOptions, InvalidRequestError, type ListParams, type ListResponseEnvelope, type LogContext, NOOP_LOGGER, type PaginateOptions, PermissionError, type PriceTier, type PricesListParams, RateLimitError, ResourceMissingError, type RetryPolicy, type RotateProviderCredentialParams, ServerError, type SetPortalBrandingParams, type SubscriptionsListParams, type UpdateCouponParams, type UpdateCustomerParams, type UpdateProductParams, type UpdateTaxRateParams, type UpdateWebhookEndpointParams, type UsageRecordsListParams, VERSION, type ValidateCouponParams, type VerifyWebhookOptions, WebhookVerificationError, paginate, verifyWebhookSignature };
1353
+ export { APIConnectionError, APIError, type AuditLogsListParams, AuthenticationError, type BaseListParams, BillKit, BillKitError, type BillKitLogger, type BillKitOptions, ConflictError, type CreateBillingPortalSessionParams, type CreateCheckoutSessionParams, type CreateCouponParams, type CreateCustomerParams, type CreateOneShotPaymentParams, type CreatePriceParams, type CreateProductParams, type CreateRefundParams, type CreateTaxRateParams, type CreateUsageRecordParams, type CreateWebhookEndpointParams, type CreditNotesListParams, DEFAULT_RETRY_POLICY, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, type EventsListParams, type IdempotencyOptions, InvalidRequestError, type ListParams, type ListResponseEnvelope, type LogContext, NOOP_LOGGER, type PaginateOptions, PermissionError, type PriceTier, type PricesListParams, RateLimitError, ResourceMissingError, type RetryPolicy, type RotateProviderCredentialParams, ServerError, type SetPortalBrandingParams, type SubscriptionsListParams, type UpdateCouponParams, type UpdateCustomerParams, type UpdateProductParams, type UpdateTaxRateParams, type UpdateWebhookEndpointParams, type UsageRecordsListParams, VERSION, type ValidateCouponParams, type VerifyWebhookOptions, type VoidInvoiceParams, WebhookVerificationError, paginate, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -705,6 +705,21 @@ interface AuditLogsListParams extends BaseListParams {
705
705
  resource_type?: string;
706
706
  actor_id?: string;
707
707
  }
708
+ /**
709
+ * `creditNotes.list` params.
710
+ *
711
+ * `invoice_id` answers "was this sale credited, and by how much", which is
712
+ * the question when reconciling one invoice; `customer_id` answers it for
713
+ * everything credited back to one buyer.
714
+ */
715
+ interface CreditNotesListParams extends BaseListParams {
716
+ invoice_id?: string;
717
+ customer_id?: string;
718
+ }
719
+ /** `invoices.void` params. `reason` is recorded on the audit row only. */
720
+ interface VoidInvoiceParams extends IdempotencyOptions {
721
+ reason?: string;
722
+ }
708
723
  interface CreateBillingPortalSessionParams extends IdempotencyOptions {
709
724
  subscription_id: string;
710
725
  return_url: string;
@@ -1131,6 +1146,47 @@ declare class Invoices extends BaseResource {
1131
1146
  iter<T = unknown>(options?: {
1132
1147
  pageSize?: number;
1133
1148
  }): AsyncIterableIterator<T>;
1149
+ /**
1150
+ * Void an invoice: state that the sale was never owed.
1151
+ *
1152
+ * The invoice keeps its number and stays readable — a gapless series
1153
+ * cannot lose a row — and stops being a receivable. Use it for an
1154
+ * invoice that should not have been issued.
1155
+ *
1156
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
1157
+ * `"invoice_not_voidable"`. That is deliberate rather than a
1158
+ * limitation: once the money has moved, "never owed" is false, and the
1159
+ * document that reverses a real sale is a credit note — refund the
1160
+ * payment and one is issued when the refund settles.
1161
+ *
1162
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
1163
+ */
1164
+ void<T = unknown>(id: string, params?: VoidInvoiceParams): Promise<T>;
1165
+ }
1166
+ /**
1167
+ * Read-only access to credit notes — the documents that reverse an
1168
+ * issued invoice.
1169
+ *
1170
+ * There is no create: a credit note is issued for you when a refund
1171
+ * settles, never on request, so that a numbered legal record is only
1172
+ * minted once the money has actually moved. A refund that is still
1173
+ * pending, one that fails, and a refund of a one-off charge that was
1174
+ * never invoiced all produce none.
1175
+ */
1176
+ declare class CreditNotes extends BaseResource {
1177
+ retrieve<T = unknown>(id: string): Promise<T>;
1178
+ /**
1179
+ * Download the rendered credit note PDF as raw bytes. Same storage
1180
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
1181
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
1182
+ */
1183
+ retrievePdf(id: string): Promise<ArrayBuffer>;
1184
+ list<T = unknown>(params?: CreditNotesListParams): Promise<ListResponseEnvelope<T>>;
1185
+ iter<T = unknown>(options?: {
1186
+ pageSize?: number;
1187
+ invoice_id?: string;
1188
+ customer_id?: string;
1189
+ }): AsyncIterableIterator<T>;
1134
1190
  }
1135
1191
  /**
1136
1192
  * Read-only access to the per-tenant audit log.
@@ -1205,6 +1261,7 @@ declare class BillKit {
1205
1261
  readonly coupons: Coupons;
1206
1262
  readonly taxRates: TaxRates;
1207
1263
  readonly invoices: Invoices;
1264
+ readonly creditNotes: CreditNotes;
1208
1265
  readonly auditLogs: AuditLogs;
1209
1266
  readonly payments: Payments;
1210
1267
  readonly billingPortalSessions: BillingPortalSessions;
@@ -1261,7 +1318,7 @@ declare class RateLimitError extends BillKitError {
1261
1318
  });
1262
1319
  }
1263
1320
 
1264
- declare const VERSION = "0.3.0";
1321
+ declare const VERSION = "0.4.0";
1265
1322
 
1266
1323
  /**
1267
1324
  * Verify `BillKit-Signature: t=<unix>,v1=<hex>` headers.
@@ -1293,4 +1350,4 @@ interface VerifyWebhookOptions {
1293
1350
  }
1294
1351
  declare function verifyWebhookSignature<T = unknown>(options: VerifyWebhookOptions): Promise<T>;
1295
1352
 
1296
- export { APIConnectionError, APIError, type AuditLogsListParams, AuthenticationError, type BaseListParams, BillKit, BillKitError, type BillKitLogger, type BillKitOptions, ConflictError, type CreateBillingPortalSessionParams, type CreateCheckoutSessionParams, type CreateCouponParams, type CreateCustomerParams, type CreateOneShotPaymentParams, type CreatePriceParams, type CreateProductParams, type CreateRefundParams, type CreateTaxRateParams, type CreateUsageRecordParams, type CreateWebhookEndpointParams, DEFAULT_RETRY_POLICY, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, type EventsListParams, type IdempotencyOptions, InvalidRequestError, type ListParams, type ListResponseEnvelope, type LogContext, NOOP_LOGGER, type PaginateOptions, PermissionError, type PriceTier, type PricesListParams, RateLimitError, ResourceMissingError, type RetryPolicy, type RotateProviderCredentialParams, ServerError, type SetPortalBrandingParams, type SubscriptionsListParams, type UpdateCouponParams, type UpdateCustomerParams, type UpdateProductParams, type UpdateTaxRateParams, type UpdateWebhookEndpointParams, type UsageRecordsListParams, VERSION, type ValidateCouponParams, type VerifyWebhookOptions, WebhookVerificationError, paginate, verifyWebhookSignature };
1353
+ export { APIConnectionError, APIError, type AuditLogsListParams, AuthenticationError, type BaseListParams, BillKit, BillKitError, type BillKitLogger, type BillKitOptions, ConflictError, type CreateBillingPortalSessionParams, type CreateCheckoutSessionParams, type CreateCouponParams, type CreateCustomerParams, type CreateOneShotPaymentParams, type CreatePriceParams, type CreateProductParams, type CreateRefundParams, type CreateTaxRateParams, type CreateUsageRecordParams, type CreateWebhookEndpointParams, type CreditNotesListParams, DEFAULT_RETRY_POLICY, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, type EventsListParams, type IdempotencyOptions, InvalidRequestError, type ListParams, type ListResponseEnvelope, type LogContext, NOOP_LOGGER, type PaginateOptions, PermissionError, type PriceTier, type PricesListParams, RateLimitError, ResourceMissingError, type RetryPolicy, type RotateProviderCredentialParams, ServerError, type SetPortalBrandingParams, type SubscriptionsListParams, type UpdateCouponParams, type UpdateCustomerParams, type UpdateProductParams, type UpdateTaxRateParams, type UpdateWebhookEndpointParams, type UsageRecordsListParams, VERSION, type ValidateCouponParams, type VerifyWebhookOptions, type VoidInvoiceParams, WebhookVerificationError, paginate, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -618,6 +618,46 @@ var Invoices = class extends BaseResource {
618
618
  iter(options = {}) {
619
619
  return paginate((p) => this.get("/v1/invoices", p), { pageSize: options.pageSize });
620
620
  }
621
+ /**
622
+ * Void an invoice: state that the sale was never owed.
623
+ *
624
+ * The invoice keeps its number and stays readable — a gapless series
625
+ * cannot lose a row — and stops being a receivable. Use it for an
626
+ * invoice that should not have been issued.
627
+ *
628
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
629
+ * `"invoice_not_voidable"`. That is deliberate rather than a
630
+ * limitation: once the money has moved, "never owed" is false, and the
631
+ * document that reverses a real sale is a credit note — refund the
632
+ * payment and one is issued when the refund settles.
633
+ *
634
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
635
+ */
636
+ void(id, params = {}) {
637
+ return this.post(`/v1/invoices/${id}/void`, params);
638
+ }
639
+ };
640
+ var CreditNotes = class extends BaseResource {
641
+ retrieve(id) {
642
+ return this.get(`/v1/credit_notes/${id}`);
643
+ }
644
+ /**
645
+ * Download the rendered credit note PDF as raw bytes. Same storage
646
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
647
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
648
+ */
649
+ retrievePdf(id) {
650
+ return this.t.requestBinary({ method: "GET", path: `/v1/credit_notes/${id}/pdf` });
651
+ }
652
+ list(params = {}) {
653
+ return this.get("/v1/credit_notes", params);
654
+ }
655
+ iter(options = {}) {
656
+ return paginate((p) => this.get("/v1/credit_notes", p), {
657
+ pageSize: options.pageSize,
658
+ filters: { invoice_id: options.invoice_id, customer_id: options.customer_id }
659
+ });
660
+ }
621
661
  };
622
662
  var AuditLogs = class extends BaseResource {
623
663
  retrieve(id) {
@@ -795,7 +835,7 @@ function sleep(ms) {
795
835
  }
796
836
 
797
837
  // src/version.ts
798
- var VERSION = "0.3.0";
838
+ var VERSION = "0.4.0";
799
839
 
800
840
  // src/transport.ts
801
841
  var DEFAULT_BASE_URL = "https://api.billkit.eu";
@@ -1029,6 +1069,7 @@ var BillKit = class {
1029
1069
  coupons;
1030
1070
  taxRates;
1031
1071
  invoices;
1072
+ creditNotes;
1032
1073
  auditLogs;
1033
1074
  payments;
1034
1075
  billingPortalSessions;
@@ -1051,6 +1092,7 @@ var BillKit = class {
1051
1092
  this.coupons = new Coupons(transport);
1052
1093
  this.taxRates = new TaxRates(transport);
1053
1094
  this.invoices = new Invoices(transport);
1095
+ this.creditNotes = new CreditNotes(transport);
1054
1096
  this.auditLogs = new AuditLogs(transport);
1055
1097
  this.payments = new Payments(transport);
1056
1098
  this.billingPortalSessions = new BillingPortalSessions(transport);