bkper-js 2.32.1 → 2.32.2

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
@@ -1836,6 +1836,7 @@ export declare class Book extends ResourceProperty<bkper.Book> {
1836
1836
  * @returns The created Accounts
1837
1837
  */
1838
1838
  batchCreateAccounts(accounts: Account[]): Promise<Account[]>;
1839
+
1839
1840
  /**
1840
1841
  * Update [[Accounts]] on the Book, in batch.
1841
1842
  *
package/lib/model/Book.js CHANGED
@@ -567,7 +567,7 @@ export class Book extends ResourceProperty {
567
567
  return __awaiter(this, void 0, void 0, function* () {
568
568
  if (accounts.length > 0) {
569
569
  const accountList = {
570
- items: accounts.map(a => a.json()),
570
+ items: yield Promise.all(accounts.map(account => this.normalizeAccountPayloadForBatchCreate_(account))),
571
571
  };
572
572
  const payloads = yield AccountService.createAccounts(this.getId(), accountList, this.getConfig());
573
573
  const createdAccounts = [];
@@ -582,6 +582,29 @@ export class Book extends ResourceProperty {
582
582
  return [];
583
583
  });
584
584
  }
585
+ /** @internal */
586
+ normalizeAccountPayloadForBatchCreate_(account) {
587
+ return __awaiter(this, void 0, void 0, function* () {
588
+ const payload = account.json();
589
+ if (!payload.groups || payload.groups.length === 0) {
590
+ return payload;
591
+ }
592
+ const normalizedGroups = [];
593
+ for (const groupPayload of payload.groups) {
594
+ const idOrName = groupPayload.id || groupPayload.name;
595
+ if (!idOrName || idOrName.trim() === '') {
596
+ throw new Error('Account group reference must include id or name');
597
+ }
598
+ const group = yield this.getGroup(idOrName);
599
+ if (!group) {
600
+ throw new Error(`Group not found: ${idOrName}`);
601
+ }
602
+ normalizedGroups.push(group.json());
603
+ }
604
+ payload.groups = normalizedGroups;
605
+ return payload;
606
+ });
607
+ }
585
608
  /**
586
609
  * Update [[Accounts]] on the Book, in batch.
587
610
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.32.1",
3
+ "version": "2.32.2",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",