@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@billkit-eu/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official Node.js SDK for BillKit: a Stripe-Billing-shape multi-tenant SaaS API on Mollie.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
package/src/client.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  BillingPortalSessions,
13
13
  CheckoutSessions,
14
14
  Coupons,
15
+ CreditNotes,
15
16
  Customers,
16
17
  Disputes,
17
18
  Events,
@@ -58,6 +59,7 @@ export class BillKit {
58
59
  readonly coupons: Coupons;
59
60
  readonly taxRates: TaxRates;
60
61
  readonly invoices: Invoices;
62
+ readonly creditNotes: CreditNotes;
61
63
  readonly auditLogs: AuditLogs;
62
64
  readonly payments: Payments;
63
65
  readonly billingPortalSessions: BillingPortalSessions;
@@ -81,6 +83,7 @@ export class BillKit {
81
83
  this.coupons = new Coupons(transport);
82
84
  this.taxRates = new TaxRates(transport);
83
85
  this.invoices = new Invoices(transport);
86
+ this.creditNotes = new CreditNotes(transport);
84
87
  this.auditLogs = new AuditLogs(transport);
85
88
  this.payments = new Payments(transport);
86
89
  this.billingPortalSessions = new BillingPortalSessions(transport);
package/src/index.ts CHANGED
@@ -81,6 +81,7 @@ export type {
81
81
  CreateTaxRateParams,
82
82
  CreateUsageRecordParams,
83
83
  CreateWebhookEndpointParams,
84
+ CreditNotesListParams,
84
85
  EventsListParams,
85
86
  IdempotencyOptions,
86
87
  ListParams,
@@ -96,6 +97,7 @@ export type {
96
97
  UpdateWebhookEndpointParams,
97
98
  UsageRecordsListParams,
98
99
  ValidateCouponParams,
100
+ VoidInvoiceParams,
99
101
  } from "./resources.js";
100
102
  export { DEFAULT_RETRY_POLICY, type RetryPolicy } from "./retry.js";
101
103
  export { VERSION } from "./version.js";
package/src/resources.ts CHANGED
@@ -566,6 +566,23 @@ export interface AuditLogsListParams extends BaseListParams {
566
566
  actor_id?: string;
567
567
  }
568
568
 
569
+ /**
570
+ * `creditNotes.list` params.
571
+ *
572
+ * `invoice_id` answers "was this sale credited, and by how much", which is
573
+ * the question when reconciling one invoice; `customer_id` answers it for
574
+ * everything credited back to one buyer.
575
+ */
576
+ export interface CreditNotesListParams extends BaseListParams {
577
+ invoice_id?: string;
578
+ customer_id?: string;
579
+ }
580
+
581
+ /** `invoices.void` params. `reason` is recorded on the audit row only. */
582
+ export interface VoidInvoiceParams extends IdempotencyOptions {
583
+ reason?: string;
584
+ }
585
+
569
586
  export interface CreateBillingPortalSessionParams extends IdempotencyOptions {
570
587
  subscription_id: string;
571
588
  return_url: string;
@@ -1354,6 +1371,63 @@ export class Invoices extends BaseResource {
1354
1371
  iter<T = unknown>(options: { pageSize?: number } = {}): AsyncIterableIterator<T> {
1355
1372
  return paginate<T>((p) => this.get("/v1/invoices", p), { pageSize: options.pageSize });
1356
1373
  }
1374
+
1375
+ /**
1376
+ * Void an invoice: state that the sale was never owed.
1377
+ *
1378
+ * The invoice keeps its number and stays readable — a gapless series
1379
+ * cannot lose a row — and stops being a receivable. Use it for an
1380
+ * invoice that should not have been issued.
1381
+ *
1382
+ * A **paid** invoice is refused with a `ConflictError` whose `code` is
1383
+ * `"invoice_not_voidable"`. That is deliberate rather than a
1384
+ * limitation: once the money has moved, "never owed" is false, and the
1385
+ * document that reverses a real sale is a credit note — refund the
1386
+ * payment and one is issued when the refund settles.
1387
+ *
1388
+ * Idempotent: re-voiding an already-void invoice returns it unchanged.
1389
+ */
1390
+ void<T = unknown>(id: string, params: VoidInvoiceParams = {}): Promise<T> {
1391
+ return this.post<T, VoidInvoiceParams>(`/v1/invoices/${id}/void`, params);
1392
+ }
1393
+ }
1394
+
1395
+ /**
1396
+ * Read-only access to credit notes — the documents that reverse an
1397
+ * issued invoice.
1398
+ *
1399
+ * There is no create: a credit note is issued for you when a refund
1400
+ * settles, never on request, so that a numbered legal record is only
1401
+ * minted once the money has actually moved. A refund that is still
1402
+ * pending, one that fails, and a refund of a one-off charge that was
1403
+ * never invoiced all produce none.
1404
+ */
1405
+ export class CreditNotes extends BaseResource {
1406
+ retrieve<T = unknown>(id: string): Promise<T> {
1407
+ return this.get<T>(`/v1/credit_notes/${id}`);
1408
+ }
1409
+
1410
+ /**
1411
+ * Download the rendered credit note PDF as raw bytes. Same storage
1412
+ * split as {@link Invoices.retrievePdf}: bytes inline or a followed
1413
+ * `302`, and `501 rendering_pending` on a deployment with no renderer.
1414
+ */
1415
+ retrievePdf(id: string): Promise<ArrayBuffer> {
1416
+ return this.t.requestBinary({ method: "GET", path: `/v1/credit_notes/${id}/pdf` });
1417
+ }
1418
+
1419
+ list<T = unknown>(params: CreditNotesListParams = {}): Promise<ListResponseEnvelope<T>> {
1420
+ return this.get<ListResponseEnvelope<T>>("/v1/credit_notes", params);
1421
+ }
1422
+
1423
+ iter<T = unknown>(
1424
+ options: { pageSize?: number; invoice_id?: string; customer_id?: string } = {},
1425
+ ): AsyncIterableIterator<T> {
1426
+ return paginate<T>((p) => this.get("/v1/credit_notes", p), {
1427
+ pageSize: options.pageSize,
1428
+ filters: { invoice_id: options.invoice_id, customer_id: options.customer_id },
1429
+ });
1430
+ }
1357
1431
  }
1358
1432
 
1359
1433
  /**
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.3.0";
1
+ export const VERSION = "0.4.0";