@billkit-eu/sdk 0.3.0 → 0.5.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;
@@ -1010,6 +1025,18 @@ declare class WebhookEndpoints extends BaseResource {
1010
1025
  pageSize?: number;
1011
1026
  }): AsyncIterableIterator<T>;
1012
1027
  /** Fetch one delivery row for inspection before deciding to redeliver. */
1028
+ retrieveDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T>;
1029
+ /**
1030
+ * @deprecated Renamed to {@link WebhookEndpoints.retrieveDelivery}.
1031
+ *
1032
+ * Every other single-row fetch in every BillKit SDK is `retrieve`; this
1033
+ * one method was `get`, which meant reaching for the obvious name and
1034
+ * getting a type error. The python and php clients already spell it
1035
+ * `retrieve_delivery` / `retrieveDelivery`, so node was the outlier.
1036
+ *
1037
+ * Kept as an alias because removing it would break callers for a naming
1038
+ * preference. It will go in the next major.
1039
+ */
1013
1040
  getDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T>;
1014
1041
  /**
1015
1042
  * Re-enqueue a delivery row for the dispatcher.
@@ -1131,6 +1158,47 @@ declare class Invoices extends BaseResource {
1131
1158
  iter<T = unknown>(options?: {
1132
1159
  pageSize?: number;
1133
1160
  }): AsyncIterableIterator<T>;
1161
+ /**
1162
+ * Void an invoice: state that the sale was never owed.
1163
+ *
1164
+ * The invoice keeps its number and stays readable — a gapless series
1165
+ * cannot lose a row — and stops being a receivable. Use it for an
1166
+ * invoice that should not have been issued.
1167
+ *
1168
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
1169
+ * `"invoice_not_voidable"`. That is deliberate rather than a
1170
+ * limitation: once the money has moved, "never owed" is false, and the
1171
+ * document that reverses a real sale is a credit note — refund the
1172
+ * payment and one is issued when the refund settles.
1173
+ *
1174
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
1175
+ */
1176
+ void<T = unknown>(id: string, params?: VoidInvoiceParams): Promise<T>;
1177
+ }
1178
+ /**
1179
+ * Read-only access to credit notes — the documents that reverse an
1180
+ * issued invoice.
1181
+ *
1182
+ * There is no create: a credit note is issued for you when a refund
1183
+ * settles, never on request, so that a numbered legal record is only
1184
+ * minted once the money has actually moved. A refund that is still
1185
+ * pending, one that fails, and a refund of a one-off charge that was
1186
+ * never invoiced all produce none.
1187
+ */
1188
+ declare class CreditNotes extends BaseResource {
1189
+ retrieve<T = unknown>(id: string): Promise<T>;
1190
+ /**
1191
+ * Download the rendered credit note PDF as raw bytes. Same storage
1192
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
1193
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
1194
+ */
1195
+ retrievePdf(id: string): Promise<ArrayBuffer>;
1196
+ list<T = unknown>(params?: CreditNotesListParams): Promise<ListResponseEnvelope<T>>;
1197
+ iter<T = unknown>(options?: {
1198
+ pageSize?: number;
1199
+ invoice_id?: string;
1200
+ customer_id?: string;
1201
+ }): AsyncIterableIterator<T>;
1134
1202
  }
1135
1203
  /**
1136
1204
  * Read-only access to the per-tenant audit log.
@@ -1205,6 +1273,7 @@ declare class BillKit {
1205
1273
  readonly coupons: Coupons;
1206
1274
  readonly taxRates: TaxRates;
1207
1275
  readonly invoices: Invoices;
1276
+ readonly creditNotes: CreditNotes;
1208
1277
  readonly auditLogs: AuditLogs;
1209
1278
  readonly payments: Payments;
1210
1279
  readonly billingPortalSessions: BillingPortalSessions;
@@ -1261,7 +1330,7 @@ declare class RateLimitError extends BillKitError {
1261
1330
  });
1262
1331
  }
1263
1332
 
1264
- declare const VERSION = "0.3.0";
1333
+ declare const VERSION = "0.5.0";
1265
1334
 
1266
1335
  /**
1267
1336
  * Verify `BillKit-Signature: t=<unix>,v1=<hex>` headers.
@@ -1293,4 +1362,4 @@ interface VerifyWebhookOptions {
1293
1362
  }
1294
1363
  declare function verifyWebhookSignature<T = unknown>(options: VerifyWebhookOptions): Promise<T>;
1295
1364
 
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 };
1365
+ 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, type CustomerListParams, 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;
@@ -1010,6 +1025,18 @@ declare class WebhookEndpoints extends BaseResource {
1010
1025
  pageSize?: number;
1011
1026
  }): AsyncIterableIterator<T>;
1012
1027
  /** Fetch one delivery row for inspection before deciding to redeliver. */
1028
+ retrieveDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T>;
1029
+ /**
1030
+ * @deprecated Renamed to {@link WebhookEndpoints.retrieveDelivery}.
1031
+ *
1032
+ * Every other single-row fetch in every BillKit SDK is `retrieve`; this
1033
+ * one method was `get`, which meant reaching for the obvious name and
1034
+ * getting a type error. The python and php clients already spell it
1035
+ * `retrieve_delivery` / `retrieveDelivery`, so node was the outlier.
1036
+ *
1037
+ * Kept as an alias because removing it would break callers for a naming
1038
+ * preference. It will go in the next major.
1039
+ */
1013
1040
  getDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T>;
1014
1041
  /**
1015
1042
  * Re-enqueue a delivery row for the dispatcher.
@@ -1131,6 +1158,47 @@ declare class Invoices extends BaseResource {
1131
1158
  iter<T = unknown>(options?: {
1132
1159
  pageSize?: number;
1133
1160
  }): AsyncIterableIterator<T>;
1161
+ /**
1162
+ * Void an invoice: state that the sale was never owed.
1163
+ *
1164
+ * The invoice keeps its number and stays readable — a gapless series
1165
+ * cannot lose a row — and stops being a receivable. Use it for an
1166
+ * invoice that should not have been issued.
1167
+ *
1168
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
1169
+ * `"invoice_not_voidable"`. That is deliberate rather than a
1170
+ * limitation: once the money has moved, "never owed" is false, and the
1171
+ * document that reverses a real sale is a credit note — refund the
1172
+ * payment and one is issued when the refund settles.
1173
+ *
1174
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
1175
+ */
1176
+ void<T = unknown>(id: string, params?: VoidInvoiceParams): Promise<T>;
1177
+ }
1178
+ /**
1179
+ * Read-only access to credit notes — the documents that reverse an
1180
+ * issued invoice.
1181
+ *
1182
+ * There is no create: a credit note is issued for you when a refund
1183
+ * settles, never on request, so that a numbered legal record is only
1184
+ * minted once the money has actually moved. A refund that is still
1185
+ * pending, one that fails, and a refund of a one-off charge that was
1186
+ * never invoiced all produce none.
1187
+ */
1188
+ declare class CreditNotes extends BaseResource {
1189
+ retrieve<T = unknown>(id: string): Promise<T>;
1190
+ /**
1191
+ * Download the rendered credit note PDF as raw bytes. Same storage
1192
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
1193
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
1194
+ */
1195
+ retrievePdf(id: string): Promise<ArrayBuffer>;
1196
+ list<T = unknown>(params?: CreditNotesListParams): Promise<ListResponseEnvelope<T>>;
1197
+ iter<T = unknown>(options?: {
1198
+ pageSize?: number;
1199
+ invoice_id?: string;
1200
+ customer_id?: string;
1201
+ }): AsyncIterableIterator<T>;
1134
1202
  }
1135
1203
  /**
1136
1204
  * Read-only access to the per-tenant audit log.
@@ -1205,6 +1273,7 @@ declare class BillKit {
1205
1273
  readonly coupons: Coupons;
1206
1274
  readonly taxRates: TaxRates;
1207
1275
  readonly invoices: Invoices;
1276
+ readonly creditNotes: CreditNotes;
1208
1277
  readonly auditLogs: AuditLogs;
1209
1278
  readonly payments: Payments;
1210
1279
  readonly billingPortalSessions: BillingPortalSessions;
@@ -1261,7 +1330,7 @@ declare class RateLimitError extends BillKitError {
1261
1330
  });
1262
1331
  }
1263
1332
 
1264
- declare const VERSION = "0.3.0";
1333
+ declare const VERSION = "0.5.0";
1265
1334
 
1266
1335
  /**
1267
1336
  * Verify `BillKit-Signature: t=<unix>,v1=<hex>` headers.
@@ -1293,4 +1362,4 @@ interface VerifyWebhookOptions {
1293
1362
  }
1294
1363
  declare function verifyWebhookSignature<T = unknown>(options: VerifyWebhookOptions): Promise<T>;
1295
1364
 
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 };
1365
+ 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, type CustomerListParams, 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
@@ -460,9 +460,23 @@ var WebhookEndpoints = class extends BaseResource {
460
460
  );
461
461
  }
462
462
  /** Fetch one delivery row for inspection before deciding to redeliver. */
463
- getDelivery(endpointId, deliveryId) {
463
+ retrieveDelivery(endpointId, deliveryId) {
464
464
  return this.get(`/v1/webhook_endpoints/${endpointId}/deliveries/${deliveryId}`);
465
465
  }
466
+ /**
467
+ * @deprecated Renamed to {@link WebhookEndpoints.retrieveDelivery}.
468
+ *
469
+ * Every other single-row fetch in every BillKit SDK is `retrieve`; this
470
+ * one method was `get`, which meant reaching for the obvious name and
471
+ * getting a type error. The python and php clients already spell it
472
+ * `retrieve_delivery` / `retrieveDelivery`, so node was the outlier.
473
+ *
474
+ * Kept as an alias because removing it would break callers for a naming
475
+ * preference. It will go in the next major.
476
+ */
477
+ getDelivery(endpointId, deliveryId) {
478
+ return this.retrieveDelivery(endpointId, deliveryId);
479
+ }
466
480
  /**
467
481
  * Re-enqueue a delivery row for the dispatcher.
468
482
  *
@@ -618,6 +632,46 @@ var Invoices = class extends BaseResource {
618
632
  iter(options = {}) {
619
633
  return paginate((p) => this.get("/v1/invoices", p), { pageSize: options.pageSize });
620
634
  }
635
+ /**
636
+ * Void an invoice: state that the sale was never owed.
637
+ *
638
+ * The invoice keeps its number and stays readable — a gapless series
639
+ * cannot lose a row — and stops being a receivable. Use it for an
640
+ * invoice that should not have been issued.
641
+ *
642
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
643
+ * `"invoice_not_voidable"`. That is deliberate rather than a
644
+ * limitation: once the money has moved, "never owed" is false, and the
645
+ * document that reverses a real sale is a credit note — refund the
646
+ * payment and one is issued when the refund settles.
647
+ *
648
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
649
+ */
650
+ void(id, params = {}) {
651
+ return this.post(`/v1/invoices/${id}/void`, params);
652
+ }
653
+ };
654
+ var CreditNotes = class extends BaseResource {
655
+ retrieve(id) {
656
+ return this.get(`/v1/credit_notes/${id}`);
657
+ }
658
+ /**
659
+ * Download the rendered credit note PDF as raw bytes. Same storage
660
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
661
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
662
+ */
663
+ retrievePdf(id) {
664
+ return this.t.requestBinary({ method: "GET", path: `/v1/credit_notes/${id}/pdf` });
665
+ }
666
+ list(params = {}) {
667
+ return this.get("/v1/credit_notes", params);
668
+ }
669
+ iter(options = {}) {
670
+ return paginate((p) => this.get("/v1/credit_notes", p), {
671
+ pageSize: options.pageSize,
672
+ filters: { invoice_id: options.invoice_id, customer_id: options.customer_id }
673
+ });
674
+ }
621
675
  };
622
676
  var AuditLogs = class extends BaseResource {
623
677
  retrieve(id) {
@@ -795,7 +849,7 @@ function sleep(ms) {
795
849
  }
796
850
 
797
851
  // src/version.ts
798
- var VERSION = "0.3.0";
852
+ var VERSION = "0.5.0";
799
853
 
800
854
  // src/transport.ts
801
855
  var DEFAULT_BASE_URL = "https://api.billkit.eu";
@@ -1029,6 +1083,7 @@ var BillKit = class {
1029
1083
  coupons;
1030
1084
  taxRates;
1031
1085
  invoices;
1086
+ creditNotes;
1032
1087
  auditLogs;
1033
1088
  payments;
1034
1089
  billingPortalSessions;
@@ -1051,6 +1106,7 @@ var BillKit = class {
1051
1106
  this.coupons = new Coupons(transport);
1052
1107
  this.taxRates = new TaxRates(transport);
1053
1108
  this.invoices = new Invoices(transport);
1109
+ this.creditNotes = new CreditNotes(transport);
1054
1110
  this.auditLogs = new AuditLogs(transport);
1055
1111
  this.payments = new Payments(transport);
1056
1112
  this.billingPortalSessions = new BillingPortalSessions(transport);