@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/CHANGELOG.md +30 -0
- package/README.md +9 -5
- package/dist/index.cjs +58 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -2
- package/dist/index.d.ts +71 -2
- package/dist/index.js +58 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +3 -0
- package/src/index.ts +3 -0
- package/src/resources.ts +90 -1
- package/src/version.ts +1 -1
package/package.json
CHANGED
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,8 @@ export type {
|
|
|
81
81
|
CreateTaxRateParams,
|
|
82
82
|
CreateUsageRecordParams,
|
|
83
83
|
CreateWebhookEndpointParams,
|
|
84
|
+
CreditNotesListParams,
|
|
85
|
+
CustomerListParams,
|
|
84
86
|
EventsListParams,
|
|
85
87
|
IdempotencyOptions,
|
|
86
88
|
ListParams,
|
|
@@ -96,6 +98,7 @@ export type {
|
|
|
96
98
|
UpdateWebhookEndpointParams,
|
|
97
99
|
UsageRecordsListParams,
|
|
98
100
|
ValidateCouponParams,
|
|
101
|
+
VoidInvoiceParams,
|
|
99
102
|
} from "./resources.js";
|
|
100
103
|
export { DEFAULT_RETRY_POLICY, type RetryPolicy } from "./retry.js";
|
|
101
104
|
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;
|
|
@@ -1150,10 +1167,25 @@ export class WebhookEndpoints extends BaseResource {
|
|
|
1150
1167
|
}
|
|
1151
1168
|
|
|
1152
1169
|
/** Fetch one delivery row for inspection before deciding to redeliver. */
|
|
1153
|
-
|
|
1170
|
+
retrieveDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T> {
|
|
1154
1171
|
return this.get<T>(`/v1/webhook_endpoints/${endpointId}/deliveries/${deliveryId}`);
|
|
1155
1172
|
}
|
|
1156
1173
|
|
|
1174
|
+
/**
|
|
1175
|
+
* @deprecated Renamed to {@link WebhookEndpoints.retrieveDelivery}.
|
|
1176
|
+
*
|
|
1177
|
+
* Every other single-row fetch in every BillKit SDK is `retrieve`; this
|
|
1178
|
+
* one method was `get`, which meant reaching for the obvious name and
|
|
1179
|
+
* getting a type error. The python and php clients already spell it
|
|
1180
|
+
* `retrieve_delivery` / `retrieveDelivery`, so node was the outlier.
|
|
1181
|
+
*
|
|
1182
|
+
* Kept as an alias because removing it would break callers for a naming
|
|
1183
|
+
* preference. It will go in the next major.
|
|
1184
|
+
*/
|
|
1185
|
+
getDelivery<T = unknown>(endpointId: string, deliveryId: string): Promise<T> {
|
|
1186
|
+
return this.retrieveDelivery<T>(endpointId, deliveryId);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1157
1189
|
/**
|
|
1158
1190
|
* Re-enqueue a delivery row for the dispatcher.
|
|
1159
1191
|
*
|
|
@@ -1354,6 +1386,63 @@ export class Invoices extends BaseResource {
|
|
|
1354
1386
|
iter<T = unknown>(options: { pageSize?: number } = {}): AsyncIterableIterator<T> {
|
|
1355
1387
|
return paginate<T>((p) => this.get("/v1/invoices", p), { pageSize: options.pageSize });
|
|
1356
1388
|
}
|
|
1389
|
+
|
|
1390
|
+
/**
|
|
1391
|
+
* Void an invoice: state that the sale was never owed.
|
|
1392
|
+
*
|
|
1393
|
+
* The invoice keeps its number and stays readable — a gapless series
|
|
1394
|
+
* cannot lose a row — and stops being a receivable. Use it for an
|
|
1395
|
+
* invoice that should not have been issued.
|
|
1396
|
+
*
|
|
1397
|
+
* A **paid** invoice is refused with a `ConflictError` whose `code` is
|
|
1398
|
+
* `"invoice_not_voidable"`. That is deliberate rather than a
|
|
1399
|
+
* limitation: once the money has moved, "never owed" is false, and the
|
|
1400
|
+
* document that reverses a real sale is a credit note — refund the
|
|
1401
|
+
* payment and one is issued when the refund settles.
|
|
1402
|
+
*
|
|
1403
|
+
* Idempotent: re-voiding an already-void invoice returns it unchanged.
|
|
1404
|
+
*/
|
|
1405
|
+
void<T = unknown>(id: string, params: VoidInvoiceParams = {}): Promise<T> {
|
|
1406
|
+
return this.post<T, VoidInvoiceParams>(`/v1/invoices/${id}/void`, params);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Read-only access to credit notes — the documents that reverse an
|
|
1412
|
+
* issued invoice.
|
|
1413
|
+
*
|
|
1414
|
+
* There is no create: a credit note is issued for you when a refund
|
|
1415
|
+
* settles, never on request, so that a numbered legal record is only
|
|
1416
|
+
* minted once the money has actually moved. A refund that is still
|
|
1417
|
+
* pending, one that fails, and a refund of a one-off charge that was
|
|
1418
|
+
* never invoiced all produce none.
|
|
1419
|
+
*/
|
|
1420
|
+
export class CreditNotes extends BaseResource {
|
|
1421
|
+
retrieve<T = unknown>(id: string): Promise<T> {
|
|
1422
|
+
return this.get<T>(`/v1/credit_notes/${id}`);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* Download the rendered credit note PDF as raw bytes. Same storage
|
|
1427
|
+
* split as {@link Invoices.retrievePdf}: bytes inline or a followed
|
|
1428
|
+
* `302`, and `501 rendering_pending` on a deployment with no renderer.
|
|
1429
|
+
*/
|
|
1430
|
+
retrievePdf(id: string): Promise<ArrayBuffer> {
|
|
1431
|
+
return this.t.requestBinary({ method: "GET", path: `/v1/credit_notes/${id}/pdf` });
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
list<T = unknown>(params: CreditNotesListParams = {}): Promise<ListResponseEnvelope<T>> {
|
|
1435
|
+
return this.get<ListResponseEnvelope<T>>("/v1/credit_notes", params);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
iter<T = unknown>(
|
|
1439
|
+
options: { pageSize?: number; invoice_id?: string; customer_id?: string } = {},
|
|
1440
|
+
): AsyncIterableIterator<T> {
|
|
1441
|
+
return paginate<T>((p) => this.get("/v1/credit_notes", p), {
|
|
1442
|
+
pageSize: options.pageSize,
|
|
1443
|
+
filters: { invoice_id: options.invoice_id, customer_id: options.customer_id },
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1357
1446
|
}
|
|
1358
1447
|
|
|
1359
1448
|
/**
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.5.0";
|