bkper-js 2.29.0 → 2.29.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
@@ -125,6 +125,10 @@ export declare class Account extends ResourceProperty<bkper.Account> {
125
125
  /**
126
126
  * Gets the [[Groups]] of this Account.
127
127
  *
128
+ * When groups are already embedded in the account payload (e.g. from
129
+ * {@link Bkper.getBook} with includeGroups), resolves them from the
130
+ * book's cache instead of making API calls.
131
+ *
128
132
  * @returns Promise with the [[Groups]] of this Account
129
133
  */
130
134
  getGroups(): Promise<Group[]>;
@@ -7,11 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import * as AccountService from "../service/account-service.js";
11
- import * as GroupService from "../service/group-service.js";
12
- import { Group } from "./Group.js";
13
- import { normalizeText } from "../utils.js";
14
- import { ResourceProperty } from "./ResourceProperty.js";
10
+ import * as AccountService from '../service/account-service.js';
11
+ import { Group } from './Group.js';
12
+ import { normalizeText } from '../utils.js';
13
+ import { ResourceProperty } from './ResourceProperty.js';
15
14
  /**
16
15
  * This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].
17
16
  *
@@ -168,6 +167,10 @@ export class Account extends ResourceProperty {
168
167
  /**
169
168
  * Gets the [[Groups]] of this Account.
170
169
  *
170
+ * When groups are already embedded in the account payload (e.g. from
171
+ * {@link Bkper.getBook} with includeGroups), resolves them from the
172
+ * book's cache instead of making API calls.
173
+ *
171
174
  * @returns Promise with the [[Groups]] of this Account
172
175
  */
173
176
  getGroups() {
@@ -176,9 +179,20 @@ export class Account extends ResourceProperty {
176
179
  if (!id) {
177
180
  return [];
178
181
  }
179
- let groups = yield GroupService.getGroupsByAccountId(this.book.getId(), id, this.getConfig());
180
- let groupsObj = groups.map((group) => new Group(this.book, group));
181
- return groupsObj;
182
+ //Ensure groups are pre-loaded in the book cache to avoid multiple API calls when resolving groups from the payload
183
+ yield this.book.getGroups();
184
+ // resolve them from the book's group cache to get properly tree-linked Group objects
185
+ if (this.payload.groups != null) {
186
+ const groups = [];
187
+ for (const groupPayload of this.payload.groups) {
188
+ const group = yield this.book.getGroup(groupPayload.id);
189
+ if (group) {
190
+ groups.push(group);
191
+ }
192
+ }
193
+ return groups;
194
+ }
195
+ return [];
182
196
  });
183
197
  }
184
198
  /**
@@ -191,7 +205,7 @@ export class Account extends ResourceProperty {
191
205
  setGroups(groups) {
192
206
  this.payload.groups = undefined;
193
207
  if (groups != null) {
194
- groups.forEach((group) => this.addGroup(group));
208
+ groups.forEach(group => this.addGroup(group));
195
209
  }
196
210
  return this;
197
211
  }
@@ -228,7 +242,7 @@ export class Account extends ResourceProperty {
228
242
  if (group instanceof Group) {
229
243
  groupObject = group;
230
244
  }
231
- else if (typeof group == "string") {
245
+ else if (typeof group == 'string') {
232
246
  groupObject = yield this.book.getGroup(group);
233
247
  }
234
248
  if (groupObject) {
package/lib/model/App.js CHANGED
@@ -261,7 +261,7 @@ export class App extends Resource {
261
261
  * @returns The readme text
262
262
  */
263
263
  getReadme() {
264
- return this.payload.readme;
264
+ return this.payload.readmeMd || this.payload.readme;
265
265
  }
266
266
  /**
267
267
  * Sets the readme.md file as text.
@@ -271,7 +271,7 @@ export class App extends Resource {
271
271
  * @returns This App, for chaining
272
272
  */
273
273
  setReadme(readme) {
274
- this.payload.readme = readme;
274
+ this.payload.readmeMd = readme;
275
275
  return this;
276
276
  }
277
277
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.29.0",
3
+ "version": "2.29.2",
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
  "postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
36
36
  },
37
37
  "dependencies": {
38
- "@bkper/bkper-api-types": "^5.35.0",
38
+ "@bkper/bkper-api-types": "^5.36.0",
39
39
  "big.js": "^6.0.3",
40
40
  "dayjs": "^1.10.3",
41
41
  "luxon": "^1.25.0",