bkper-js 2.31.1 → 2.31.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/model/Book.js CHANGED
@@ -989,9 +989,27 @@ export class Book extends ResourceProperty {
989
989
  }
990
990
  }
991
991
  }
992
- /** @internal */
992
+ /**
993
+ * Ensures every group has a cached `.accounts` Map after accounts are loaded.
994
+ *
995
+ * `linkAccountsAndGroups()` populates `.accounts` on groups that have accounts
996
+ * linked to them. Groups with zero accounts keep `.accounts = undefined`. This
997
+ * method fills that gap by initializing an empty Map on those groups.
998
+ *
999
+ * Without this, `Group.getAccounts()` sees `undefined`, skips the cache check,
1000
+ * and falls through to a network request per group — causing hundreds of
1001
+ * redundant `/groups/{id}/accounts` calls on books with many groups.
1002
+ *
1003
+ * IMPORTANT: This method must NOT be guarded by `allGroupsLoaded` or any
1004
+ * similar flag. It runs inside `mapAccounts()`, which is always called after
1005
+ * `mapGroups()` sets `allGroupsLoaded = true`. A guard like
1006
+ * `if (!this.allGroupsLoaded)` would make this method dead code, silently
1007
+ * reintroducing the redundant network requests.
1008
+ *
1009
+ * @internal
1010
+ */
993
1011
  ensureGroupsAccountMapsLoaded() {
994
- if (this.idGroupMap && !this.allGroupsLoaded) {
1012
+ if (this.idGroupMap) {
995
1013
  for (const group of this.idGroupMap.values()) {
996
1014
  if (group.accounts == null) {
997
1015
  group.accounts = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.31.1",
3
+ "version": "2.31.2",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",