bkper-js 2.12.4 → 2.14.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 +5 -1
- package/lib/index.d.ts +15 -5
- package/lib/model/Book.js +13 -0
- package/lib/model/Transaction.js +60 -12
- package/lib/service/transaction-service.js +7 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ See what's new and what has changed in bkper-js
|
|
|
4
4
|
|
|
5
5
|
## 2025
|
|
6
6
|
|
|
7
|
+
**October 2025**
|
|
8
|
+
|
|
9
|
+
- Files attached to transactions are now created internally when transaction is persisted
|
|
10
|
+
- Added `Transaction.removeFile`
|
|
11
|
+
|
|
7
12
|
**September 2025**
|
|
8
13
|
|
|
9
14
|
- **v2.8.0 - INTERNAL REFACTOR:**
|
|
@@ -42,7 +47,6 @@ See what's new and what has changed in bkper-js
|
|
|
42
47
|
|
|
43
48
|
**August 2025**
|
|
44
49
|
|
|
45
|
-
- Added `Transaction.setFiles`
|
|
46
50
|
- Added `File.getProperties`
|
|
47
51
|
- Added `File.setProperties`
|
|
48
52
|
- Added `File.getProperty`
|
package/lib/index.d.ts
CHANGED
|
@@ -1850,6 +1850,14 @@ export declare class Book extends Resource<bkper.Book> {
|
|
|
1850
1850
|
* @returns A [[TransactionList]] object containing the list of transactions
|
|
1851
1851
|
*/
|
|
1852
1852
|
listTransactions(query?: string, limit?: number, cursor?: string): Promise<TransactionList>;
|
|
1853
|
+
/**
|
|
1854
|
+
* Retrieve the number of transactions based on a query.
|
|
1855
|
+
*
|
|
1856
|
+
* @param query - The query string
|
|
1857
|
+
*
|
|
1858
|
+
* @returns The number of matching transactions
|
|
1859
|
+
*/
|
|
1860
|
+
countTransactions(query?: string): Promise<number | undefined>;
|
|
1853
1861
|
/**
|
|
1854
1862
|
* Lists events in the Book based on the provided parameters.
|
|
1855
1863
|
*
|
|
@@ -3297,6 +3305,7 @@ export declare class Template extends Resource<bkper.Template> {
|
|
|
3297
3305
|
*/
|
|
3298
3306
|
export declare class Transaction extends Resource<bkper.Transaction> {
|
|
3299
3307
|
|
|
3308
|
+
|
|
3300
3309
|
constructor(book: Book, payload?: bkper.Transaction);
|
|
3301
3310
|
|
|
3302
3311
|
/**
|
|
@@ -3416,23 +3425,24 @@ export declare class Transaction extends Resource<bkper.Transaction> {
|
|
|
3416
3425
|
*/
|
|
3417
3426
|
getFiles(): File[];
|
|
3418
3427
|
/**
|
|
3419
|
-
*
|
|
3428
|
+
* Removes a file attachment from the Transaction.
|
|
3420
3429
|
*
|
|
3421
|
-
* @param
|
|
3430
|
+
* @param file - The File to remove from this Transaction
|
|
3422
3431
|
*
|
|
3423
3432
|
* @returns This Transaction, for chaining
|
|
3424
3433
|
*/
|
|
3425
|
-
|
|
3434
|
+
removeFile(file: File): Transaction;
|
|
3426
3435
|
/**
|
|
3427
3436
|
* Adds a file attachment to the Transaction.
|
|
3428
3437
|
*
|
|
3429
|
-
* Files
|
|
3438
|
+
* Files not previously created in the Book will be automatically created when the transaction is persisted.
|
|
3430
3439
|
*
|
|
3431
|
-
* @param file - The
|
|
3440
|
+
* @param file - The File to add to this Transaction
|
|
3432
3441
|
*
|
|
3433
3442
|
* @returns This Transaction, for chaining
|
|
3434
3443
|
*/
|
|
3435
3444
|
addFile(file: File): Transaction;
|
|
3445
|
+
|
|
3436
3446
|
/**
|
|
3437
3447
|
* Check if the transaction has the specified tag.
|
|
3438
3448
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -1070,6 +1070,19 @@ export class Book extends Resource {
|
|
|
1070
1070
|
return new TransactionList(this, transactionsList);
|
|
1071
1071
|
});
|
|
1072
1072
|
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Retrieve the number of transactions based on a query.
|
|
1075
|
+
*
|
|
1076
|
+
* @param query - The query string
|
|
1077
|
+
*
|
|
1078
|
+
* @returns The number of matching transactions
|
|
1079
|
+
*/
|
|
1080
|
+
countTransactions(query) {
|
|
1081
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1082
|
+
const count = yield TransactionService.countTransactions(this.getId(), query, this.getConfig());
|
|
1083
|
+
return count.total;
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1073
1086
|
/**
|
|
1074
1087
|
* Lists events in the Book based on the provided parameters.
|
|
1075
1088
|
*
|
package/lib/model/Transaction.js
CHANGED
|
@@ -13,6 +13,7 @@ import { Resource } from "./Resource.js";
|
|
|
13
13
|
import * as TransactionService from "../service/transaction-service.js";
|
|
14
14
|
import * as Utils from "../utils.js";
|
|
15
15
|
import { Amount } from "./Amount.js";
|
|
16
|
+
import { v4 as uuidv4 } from "uuid";
|
|
16
17
|
/**
|
|
17
18
|
*
|
|
18
19
|
* This class defines a Transaction between [credit and debit](http://en.wikipedia.org/wiki/Debits_and_credits) [[Accounts]].
|
|
@@ -24,6 +25,8 @@ import { Amount } from "./Amount.js";
|
|
|
24
25
|
export class Transaction extends Resource {
|
|
25
26
|
constructor(book, payload) {
|
|
26
27
|
super(payload || { createdAt: `${Date.now()}` });
|
|
28
|
+
/** @internal */
|
|
29
|
+
this.pendingFiles = new Map();
|
|
27
30
|
this.book = book;
|
|
28
31
|
}
|
|
29
32
|
/** @internal */
|
|
@@ -219,38 +222,80 @@ export class Transaction extends Resource {
|
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
/**
|
|
222
|
-
*
|
|
225
|
+
* Removes a file attachment from the Transaction.
|
|
223
226
|
*
|
|
224
|
-
* @param
|
|
227
|
+
* @param file - The File to remove from this Transaction
|
|
225
228
|
*
|
|
226
229
|
* @returns This Transaction, for chaining
|
|
227
230
|
*/
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
removeFile(file) {
|
|
232
|
+
const fileId = file.getId();
|
|
233
|
+
if (fileId) {
|
|
234
|
+
if (this.payload.files != null) {
|
|
235
|
+
this.payload.files = this.payload.files.filter(f => f.id !== fileId);
|
|
236
|
+
}
|
|
237
|
+
this.pendingFiles.delete(fileId);
|
|
238
|
+
}
|
|
236
239
|
return this;
|
|
237
240
|
}
|
|
238
241
|
/**
|
|
239
242
|
* Adds a file attachment to the Transaction.
|
|
240
243
|
*
|
|
241
|
-
* Files
|
|
244
|
+
* Files not previously created in the Book will be automatically created when the transaction is persisted.
|
|
242
245
|
*
|
|
243
|
-
* @param file - The
|
|
246
|
+
* @param file - The File to add to this Transaction
|
|
244
247
|
*
|
|
245
248
|
* @returns This Transaction, for chaining
|
|
246
249
|
*/
|
|
247
250
|
addFile(file) {
|
|
251
|
+
var _a;
|
|
248
252
|
if (this.payload.files == null) {
|
|
249
253
|
this.payload.files = [];
|
|
250
254
|
}
|
|
255
|
+
// Store file reference for later creation if needed
|
|
256
|
+
const fileId = file.getId();
|
|
257
|
+
const fileBookId = (_a = file.getBook()) === null || _a === void 0 ? void 0 : _a.getId();
|
|
258
|
+
if (fileId == null || fileBookId != this.book.getId()) {
|
|
259
|
+
// Generate temporary ID if file doesn't have one
|
|
260
|
+
if (fileId == null) {
|
|
261
|
+
file.payload.id = `temporary_${uuidv4()}`;
|
|
262
|
+
}
|
|
263
|
+
this.pendingFiles.set(file.getId(), file);
|
|
264
|
+
}
|
|
251
265
|
this.payload.files.push(file.json());
|
|
252
266
|
return this;
|
|
253
267
|
}
|
|
268
|
+
/** @internal */
|
|
269
|
+
createPendingFiles() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
if (this.pendingFiles.size === 0) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.payload.files == null) {
|
|
275
|
+
this.payload.files = [];
|
|
276
|
+
}
|
|
277
|
+
// Create all pending files in parallel
|
|
278
|
+
const promises = Array.from(this.pendingFiles.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([fileId, file]) {
|
|
279
|
+
file.book = this.book;
|
|
280
|
+
file.setProperty('upload_method_', 'attachment');
|
|
281
|
+
const createdFile = yield file.create();
|
|
282
|
+
return { fileId, createdFile };
|
|
283
|
+
}));
|
|
284
|
+
const results = yield Promise.all(promises);
|
|
285
|
+
// Update payload with all created files
|
|
286
|
+
for (const { fileId, createdFile } of results) {
|
|
287
|
+
const fileIndex = this.payload.files.findIndex(f => f.id === fileId);
|
|
288
|
+
if (fileIndex >= 0) {
|
|
289
|
+
this.payload.files[fileIndex] = createdFile.json();
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
this.payload.files.push(createdFile.json());
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// Clear pending files after creation
|
|
296
|
+
this.pendingFiles.clear();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
254
299
|
/**
|
|
255
300
|
* Check if the transaction has the specified tag.
|
|
256
301
|
*
|
|
@@ -795,6 +840,7 @@ export class Transaction extends Resource {
|
|
|
795
840
|
*/
|
|
796
841
|
create() {
|
|
797
842
|
return __awaiter(this, void 0, void 0, function* () {
|
|
843
|
+
yield this.createPendingFiles();
|
|
798
844
|
let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
799
845
|
this.payload = operation.transaction || {};
|
|
800
846
|
return this;
|
|
@@ -807,6 +853,7 @@ export class Transaction extends Resource {
|
|
|
807
853
|
*/
|
|
808
854
|
update() {
|
|
809
855
|
return __awaiter(this, void 0, void 0, function* () {
|
|
856
|
+
yield this.createPendingFiles();
|
|
810
857
|
let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
811
858
|
this.payload = operation.transaction || {};
|
|
812
859
|
return this;
|
|
@@ -845,6 +892,7 @@ export class Transaction extends Resource {
|
|
|
845
892
|
*/
|
|
846
893
|
post() {
|
|
847
894
|
return __awaiter(this, void 0, void 0, function* () {
|
|
895
|
+
yield this.createPendingFiles();
|
|
848
896
|
let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
849
897
|
this.payload = operation.transaction || {};
|
|
850
898
|
return this;
|
|
@@ -126,4 +126,11 @@ export function listTransactions(bookId, query, limit, cursor, config) {
|
|
|
126
126
|
return response.data;
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
+
export function countTransactions(bookId, query, config) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const request = new HttpBooksApiV5Request(`${bookId}/transactions/count`, config).setMethod('GET').addParam('query', query);
|
|
132
|
+
const response = yield request.fetch();
|
|
133
|
+
return response.data;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
129
136
|
//# sourceMappingURL=transaction-service.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"big.js": "^6.0.3",
|
|
42
42
|
"dayjs": "^1.10.3",
|
|
43
|
-
"luxon": "^1.25.0"
|
|
43
|
+
"luxon": "^1.25.0",
|
|
44
|
+
"uuid": "^11.0.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@microsoft/api-extractor": "^7.52.12",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"@types/mocha": "^8.2.0",
|
|
51
52
|
"@types/node": "^14.14.20",
|
|
52
53
|
"@types/node-fetch": "^2.5.8",
|
|
54
|
+
"@types/uuid": "^10.0.0",
|
|
53
55
|
"chai": "^5.1.1",
|
|
54
56
|
"gts": "^3.0.3",
|
|
55
57
|
"mocha": "^10.7.3",
|