bkper-js 2.32.1 → 2.33.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/lib/index.d.ts CHANGED
@@ -1821,6 +1821,18 @@ export declare class Book extends ResourceProperty<bkper.Book> {
1821
1821
  * @param transactions - The transactions to be untrashed
1822
1822
  */
1823
1823
  batchUntrashTransactions(transactions: Transaction[]): Promise<void>;
1824
+ /**
1825
+ * Merge two [[Transactions]] into a single new canonical transaction.
1826
+ *
1827
+ * The merged transaction is created synchronously. Cleanup of the two
1828
+ * originals is scheduled asynchronously by the backend.
1829
+ *
1830
+ * @param transaction1 - The first transaction to merge
1831
+ * @param transaction2 - The second transaction to merge
1832
+ *
1833
+ * @returns The merged Transaction
1834
+ */
1835
+ mergeTransactions(transaction1: Transaction, transaction2: Transaction): Promise<Transaction>;
1824
1836
  /**
1825
1837
  * Replay [[Events]] on the Book, in batch.
1826
1838
  *
@@ -1836,6 +1848,7 @@ export declare class Book extends ResourceProperty<bkper.Book> {
1836
1848
  * @returns The created Accounts
1837
1849
  */
1838
1850
  batchCreateAccounts(accounts: Account[]): Promise<Account[]>;
1851
+
1839
1852
  /**
1840
1853
  * Update [[Accounts]] on the Book, in batch.
1841
1854
  *
package/lib/model/Book.js CHANGED
@@ -542,6 +542,26 @@ export class Book extends ResourceProperty {
542
542
  yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
543
543
  });
544
544
  }
545
+ /**
546
+ * Merge two [[Transactions]] into a single new canonical transaction.
547
+ *
548
+ * The merged transaction is created synchronously. Cleanup of the two
549
+ * originals is scheduled asynchronously by the backend.
550
+ *
551
+ * @param transaction1 - The first transaction to merge
552
+ * @param transaction2 - The second transaction to merge
553
+ *
554
+ * @returns The merged Transaction
555
+ */
556
+ mergeTransactions(transaction1, transaction2) {
557
+ return __awaiter(this, void 0, void 0, function* () {
558
+ const payload = {
559
+ items: [transaction1.json(), transaction2.json()],
560
+ };
561
+ let operation = yield TransactionService.mergeTransactions(this.getId(), payload, this.getConfig());
562
+ return new Transaction(this, operation.transaction || {});
563
+ });
564
+ }
545
565
  /**
546
566
  * Replay [[Events]] on the Book, in batch.
547
567
  *
@@ -567,7 +587,7 @@ export class Book extends ResourceProperty {
567
587
  return __awaiter(this, void 0, void 0, function* () {
568
588
  if (accounts.length > 0) {
569
589
  const accountList = {
570
- items: accounts.map(a => a.json()),
590
+ items: yield Promise.all(accounts.map(account => this.normalizeAccountPayloadForBatchCreate_(account))),
571
591
  };
572
592
  const payloads = yield AccountService.createAccounts(this.getId(), accountList, this.getConfig());
573
593
  const createdAccounts = [];
@@ -582,6 +602,29 @@ export class Book extends ResourceProperty {
582
602
  return [];
583
603
  });
584
604
  }
605
+ /** @internal */
606
+ normalizeAccountPayloadForBatchCreate_(account) {
607
+ return __awaiter(this, void 0, void 0, function* () {
608
+ const payload = account.json();
609
+ if (!payload.groups || payload.groups.length === 0) {
610
+ return payload;
611
+ }
612
+ const normalizedGroups = [];
613
+ for (const groupPayload of payload.groups) {
614
+ const idOrName = groupPayload.id || groupPayload.name;
615
+ if (!idOrName || idOrName.trim() === '') {
616
+ throw new Error('Account group reference must include id or name');
617
+ }
618
+ const group = yield this.getGroup(idOrName);
619
+ if (!group) {
620
+ throw new Error(`Group not found: ${idOrName}`);
621
+ }
622
+ normalizedGroups.push(group.json());
623
+ }
624
+ payload.groups = normalizedGroups;
625
+ return payload;
626
+ });
627
+ }
585
628
  /**
586
629
  * Update [[Accounts]] on the Book, in batch.
587
630
  *
@@ -126,6 +126,13 @@ export function listTransactions(bookId, query, limit, cursor, config) {
126
126
  return response.data;
127
127
  });
128
128
  }
129
+ export function mergeTransactions(bookId, transactions, config) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ const payload = Object.assign({}, transactions);
132
+ const response = yield new HttpBooksApiV5Request(`${bookId}/transactions/merge`, config).setMethod('PATCH').setPayload(payload).fetch();
133
+ return response.data;
134
+ });
135
+ }
129
136
  export function countTransactions(bookId, query, config) {
130
137
  return __awaiter(this, void 0, void 0, function* () {
131
138
  const request = new HttpBooksApiV5Request(`${bookId}/transactions/count`, config).setMethod('GET').addParam('query', query);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.32.1",
3
+ "version": "2.33.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -35,7 +35,7 @@
35
35
  "upgrade:api": "bun update @bkper/bkper-api-types --latest"
36
36
  },
37
37
  "dependencies": {
38
- "@bkper/bkper-api-types": "^5.39.1",
38
+ "@bkper/bkper-api-types": "^5.40.0",
39
39
  "big.js": "^6.0.3",
40
40
  "dayjs": "^1.10.3",
41
41
  "luxon": "^1.25.0",