@billionaire-sh/node-sdk 0.1.1 → 1.0.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/README.md +30 -1
- package/dist/client.cjs +96 -3
- package/dist/client.d.cts +306 -55
- package/dist/client.d.mts +306 -55
- package/dist/client.mjs +96 -3
- package/dist/schemas.cjs +450 -221
- package/dist/schemas.d.cts +1321 -384
- package/dist/schemas.d.mts +1321 -384
- package/dist/schemas.mjs +450 -221
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -48,6 +48,9 @@ const preview = await client.platformInvoices.preview({
|
|
|
48
48
|
issuedAt: new Date().toISOString(),
|
|
49
49
|
grossAmount: 11781,
|
|
50
50
|
lines: [/* … each line's net, tax and rate, as it will be charged */],
|
|
51
|
+
// Whom for, described as on `process` — its tax is read by the same rule;
|
|
52
|
+
// null where the customer cannot be described yet
|
|
53
|
+
customer: { /* reference, partyType, name, email, vatId, taxNumber, address */ },
|
|
51
54
|
})
|
|
52
55
|
// preview.invoice?.netAmount, .taxAmount, .grossAmount, .byRate, .lines
|
|
53
56
|
|
|
@@ -64,7 +67,21 @@ await client.platformInvoices.processVoid('in_1QxYz…', { voidedAt })
|
|
|
64
67
|
await client.platformInvoices.processCredit('in_1QxYz…', {
|
|
65
68
|
stripeCreditNoteId: 'cn_1QxYz…',
|
|
66
69
|
creditedAt,
|
|
67
|
-
grossAmount:
|
|
70
|
+
grossAmount: 2380,
|
|
71
|
+
netAmount: 2000,
|
|
72
|
+
// A credit note for part of the invoice corrects it by these lines
|
|
73
|
+
lines: [
|
|
74
|
+
{
|
|
75
|
+
invoiceLineIndex: 1,
|
|
76
|
+
description: 'Module',
|
|
77
|
+
quantity: 1,
|
|
78
|
+
netAmount: 2000,
|
|
79
|
+
taxAmount: 380,
|
|
80
|
+
taxRatePercent: 19,
|
|
81
|
+
isReverseCharge: false,
|
|
82
|
+
taxCountry: null,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
68
85
|
})
|
|
69
86
|
|
|
70
87
|
// The platform's invoices the entity still shows as unpaid, for a
|
|
@@ -74,6 +91,17 @@ const open = await client.platformInvoices.listOpen({
|
|
|
74
91
|
pagination: { page: 1, pageSize: 100 },
|
|
75
92
|
})
|
|
76
93
|
for (const invoice of open) console.log(invoice.stripeInvoiceId)
|
|
94
|
+
|
|
95
|
+
// A paying customer's details changed: the entity's party for it takes them
|
|
96
|
+
const { partyId } = await client.platformCustomers.process({
|
|
97
|
+
platform: 'order3000',
|
|
98
|
+
customer, // its reference, legal name, email, VAT ID and invoice address
|
|
99
|
+
})
|
|
100
|
+
// … and reads back as the books keep it (HTTP 404 while none is kept)
|
|
101
|
+
const party = await client.platformCustomers.get({
|
|
102
|
+
platform: 'order3000',
|
|
103
|
+
reference: customer.reference,
|
|
104
|
+
})
|
|
77
105
|
```
|
|
78
106
|
|
|
79
107
|
## Type naming convention
|
|
@@ -108,6 +136,7 @@ billionaire-node-sdk/
|
|
|
108
136
|
│ ├── token-manager.ts # OAuth2 token management and refresh logic
|
|
109
137
|
│ ├── resources/
|
|
110
138
|
│ │ ├── index.ts # Base resource class for API calls
|
|
139
|
+
│ │ ├── platformCustomers.ts # Platform customers resource implementation
|
|
111
140
|
│ │ └── platformInvoices.ts # Platform invoices resource implementation
|
|
112
141
|
│ └── types/
|
|
113
142
|
│ ├── index.ts # Type exports
|
package/dist/client.cjs
CHANGED
|
@@ -171,6 +171,43 @@ class BaseResource {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
class PlatformCustomersResource extends BaseResource {
|
|
175
|
+
constructor(tokenManager, baseUrl) {
|
|
176
|
+
super(tokenManager, baseUrl, "/customers");
|
|
177
|
+
}
|
|
178
|
+
rootPath() {
|
|
179
|
+
return "/platform";
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Hand over a paying customer's details as they stand after a change;
|
|
183
|
+
* the entity's party for the customer takes them, or is filed with them.
|
|
184
|
+
* Idempotent: the same details again change nothing.
|
|
185
|
+
* @param request - The platform's name and its customer's details
|
|
186
|
+
* @returns The party the customer is in the entity's books
|
|
187
|
+
*/
|
|
188
|
+
async process(request) {
|
|
189
|
+
return this.request("POST", "", request);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Read back the party a customer is in the entity's books, as the books
|
|
193
|
+
* keep it today (BLNR-1979). Throws `HTTP 404` where the platform has
|
|
194
|
+
* handed over no customer of the reference.
|
|
195
|
+
* @param customer - The platform, as it names itself, and its own
|
|
196
|
+
* reference of its customer
|
|
197
|
+
* @returns The party: its name, email, VAT ID, tax number and billing
|
|
198
|
+
* address
|
|
199
|
+
*/
|
|
200
|
+
async get({
|
|
201
|
+
platform,
|
|
202
|
+
reference
|
|
203
|
+
}) {
|
|
204
|
+
return this.request(
|
|
205
|
+
"GET",
|
|
206
|
+
`/${encodeURIComponent(reference)}?${new URLSearchParams({ platform })}`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
174
211
|
class PlatformInvoicesResource extends BaseResource {
|
|
175
212
|
constructor(tokenManager, baseUrl) {
|
|
176
213
|
super(tokenManager, baseUrl, "/invoices");
|
|
@@ -234,6 +271,51 @@ class PlatformInvoicesResource extends BaseResource {
|
|
|
234
271
|
request
|
|
235
272
|
);
|
|
236
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* The invoices the entity issued to the tenants of one of the platform's
|
|
276
|
+
* accounts, the newest first — what the platform shows the account as its
|
|
277
|
+
* invoices (BLNR-626).
|
|
278
|
+
* @param request - The platform (`filters.platform`) and its own ids of
|
|
279
|
+
* the account's tenants (`filters.tenantIds`)
|
|
280
|
+
* @returns Each invoice's number, dates, amount, state, the tenant it is
|
|
281
|
+
* addressed to, and whether its PDF is kept
|
|
282
|
+
*/
|
|
283
|
+
async listForCustomers(request) {
|
|
284
|
+
return this.request(
|
|
285
|
+
"POST",
|
|
286
|
+
"/customers",
|
|
287
|
+
request
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* What the entity invoiced the platform's customers since a day, summed
|
|
292
|
+
* per month of issue, currency and state (KLVR-2470) — what the
|
|
293
|
+
* platform's Revenue tab shows of the entity's books.
|
|
294
|
+
* @param request - The platform (`filters.platform`) and the first day of
|
|
295
|
+
* issue read (`filters.since`)
|
|
296
|
+
* @returns Per month, currency and state what was invoiced, tax included
|
|
297
|
+
*/
|
|
298
|
+
async listMonths(request) {
|
|
299
|
+
return this.request(
|
|
300
|
+
"POST",
|
|
301
|
+
"/months",
|
|
302
|
+
request
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* A link to the PDF of an invoice the entity issued to one of these
|
|
307
|
+
* tenants, valid for a few minutes — asked for the moment the account
|
|
308
|
+
* opens it (BLNR-626). An invoice of any other tenant answers 404.
|
|
309
|
+
* @param stripeInvoiceId - The payment provider's id of the platform's invoice
|
|
310
|
+
* @param request - The platform and its own ids of the account's tenants
|
|
311
|
+
*/
|
|
312
|
+
async documentUrl(stripeInvoiceId, request) {
|
|
313
|
+
return this.request(
|
|
314
|
+
"POST",
|
|
315
|
+
`/${encodeURIComponent(stripeInvoiceId)}/document`,
|
|
316
|
+
request
|
|
317
|
+
);
|
|
318
|
+
}
|
|
237
319
|
/**
|
|
238
320
|
* Get the entity's invoice for a platform invoice.
|
|
239
321
|
* @param stripeInvoiceId - The payment provider's id of the platform's invoice
|
|
@@ -275,10 +357,16 @@ class PlatformInvoicesResource extends BaseResource {
|
|
|
275
357
|
* Hand over a credit note the payment provider issued for a platform
|
|
276
358
|
* invoice — money back to the card, a credit on the customer's balance.
|
|
277
359
|
* One for all of it cancels the entity's invoice, and what the customer
|
|
278
|
-
* had paid becomes their credit; one for part of it
|
|
279
|
-
*
|
|
360
|
+
* had paid becomes their credit; one for part of it corrects the invoice
|
|
361
|
+
* by the lines it takes back, by a correction invoice of its own
|
|
362
|
+
* (`corrected`). One whose lines do not say which part it takes back is
|
|
363
|
+
* answered `partial_credit` and changes nothing. What it sent back to the
|
|
364
|
+
* card (`refundedAmount`, with the `paymentProviderAccount` it left) is
|
|
365
|
+
* recorded as an outgoing payment on the money account of that balance
|
|
366
|
+
* and pays back the customer's credit; `refund` answers what became of
|
|
367
|
+
* it.
|
|
280
368
|
* @param stripeInvoiceId - The payment provider's id of the credited invoice
|
|
281
|
-
* @param request - The credit note, when it was issued
|
|
369
|
+
* @param request - The credit note, when it was issued, what it takes back and what it refunded
|
|
282
370
|
*/
|
|
283
371
|
async processCredit(stripeInvoiceId, request) {
|
|
284
372
|
return this.request(
|
|
@@ -294,6 +382,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
294
382
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
295
383
|
class BLNRClient {
|
|
296
384
|
constructor(config) {
|
|
385
|
+
__publicField(this, "platformCustomers");
|
|
297
386
|
__publicField(this, "platformInvoices");
|
|
298
387
|
__publicField(this, "baseUrl");
|
|
299
388
|
__publicField(this, "tokenManager");
|
|
@@ -305,6 +394,10 @@ class BLNRClient {
|
|
|
305
394
|
tokenUrl,
|
|
306
395
|
config.entityId
|
|
307
396
|
);
|
|
397
|
+
this.platformCustomers = new PlatformCustomersResource(
|
|
398
|
+
this.tokenManager,
|
|
399
|
+
this.baseUrl
|
|
400
|
+
);
|
|
308
401
|
this.platformInvoices = new PlatformInvoicesResource(
|
|
309
402
|
this.tokenManager,
|
|
310
403
|
this.baseUrl
|