bkper-js 1.16.0 → 1.17.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 +86 -14
- package/lib/model/Book.js +16 -0
- package/lib/model/Group.js +171 -33
- package/lib/service/http-api-request.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -756,6 +756,7 @@ export declare class Book {
|
|
|
756
756
|
|
|
757
757
|
|
|
758
758
|
|
|
759
|
+
|
|
759
760
|
/**
|
|
760
761
|
* Gets a [[Group]] object
|
|
761
762
|
*
|
|
@@ -1194,6 +1195,10 @@ export declare class File {
|
|
|
1194
1195
|
*/
|
|
1195
1196
|
export declare class Group {
|
|
1196
1197
|
payload: bkper.Group;
|
|
1198
|
+
private parent?;
|
|
1199
|
+
private depth?;
|
|
1200
|
+
private root?;
|
|
1201
|
+
private children;
|
|
1197
1202
|
|
|
1198
1203
|
|
|
1199
1204
|
constructor(book: Book, payload?: bkper.Group);
|
|
@@ -1205,16 +1210,6 @@ export declare class Group {
|
|
|
1205
1210
|
* @returns The id of this Group
|
|
1206
1211
|
*/
|
|
1207
1212
|
getId(): string | undefined;
|
|
1208
|
-
/**
|
|
1209
|
-
* @returns The parent Group
|
|
1210
|
-
*/
|
|
1211
|
-
getParent(): Promise<Group | undefined>;
|
|
1212
|
-
/**
|
|
1213
|
-
* Sets the parent Group.
|
|
1214
|
-
*
|
|
1215
|
-
* @returns This Group, for chainning.
|
|
1216
|
-
*/
|
|
1217
|
-
setParent(group: Group | null | undefined): Group;
|
|
1218
1213
|
/**
|
|
1219
1214
|
* @returns The name of this Group
|
|
1220
1215
|
*/
|
|
@@ -1233,10 +1228,6 @@ export declare class Group {
|
|
|
1233
1228
|
* @returns All Accounts of this group.
|
|
1234
1229
|
*/
|
|
1235
1230
|
getAccounts(): Promise<Account[]>;
|
|
1236
|
-
/**
|
|
1237
|
-
* @returns True if this group has any account in it
|
|
1238
|
-
*/
|
|
1239
|
-
hasAccounts(): boolean | undefined;
|
|
1240
1231
|
/**
|
|
1241
1232
|
* @returns The type for of the accounts of this group. Null if mixed
|
|
1242
1233
|
*/
|
|
@@ -1286,6 +1277,87 @@ export declare class Group {
|
|
|
1286
1277
|
* Hide/Show group on main menu.
|
|
1287
1278
|
*/
|
|
1288
1279
|
setHidden(hidden: boolean): Group;
|
|
1280
|
+
/**
|
|
1281
|
+
* Tell if the Group is permanent
|
|
1282
|
+
*/
|
|
1283
|
+
isPermanent(): boolean | undefined;
|
|
1284
|
+
/**
|
|
1285
|
+
* @returns The parent Group
|
|
1286
|
+
*/
|
|
1287
|
+
getParent(): Group | undefined;
|
|
1288
|
+
/**
|
|
1289
|
+
* Sets the parent Group.
|
|
1290
|
+
*
|
|
1291
|
+
* @returns This Group, for chainning.
|
|
1292
|
+
*/
|
|
1293
|
+
setParent(group: Group | null | undefined): Group;
|
|
1294
|
+
/**
|
|
1295
|
+
* Checks if the Group has a parent.
|
|
1296
|
+
*
|
|
1297
|
+
* @returns True if the Group has a parent, otherwise false.
|
|
1298
|
+
*/
|
|
1299
|
+
hasParent(): boolean;
|
|
1300
|
+
/**
|
|
1301
|
+
* Retrieves the children of the Group.
|
|
1302
|
+
*
|
|
1303
|
+
* @returns An array of child Groups.
|
|
1304
|
+
*/
|
|
1305
|
+
getChildren(): Group[];
|
|
1306
|
+
/**
|
|
1307
|
+
* Retrieves all descendant Groups of the current Group.
|
|
1308
|
+
*
|
|
1309
|
+
* @returns A set of descendant Groups.
|
|
1310
|
+
*/
|
|
1311
|
+
getDescendants(): Set<Group>;
|
|
1312
|
+
/**
|
|
1313
|
+
* Retrieves the IDs of all descendant Groups in a tree structure.
|
|
1314
|
+
*
|
|
1315
|
+
* @returns A set of descendant Group IDs.
|
|
1316
|
+
*/
|
|
1317
|
+
getDescendantTreeIds(): Set<string>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Checks if the Group has any children.
|
|
1320
|
+
*
|
|
1321
|
+
* @returns True if the Group has children, otherwise false.
|
|
1322
|
+
*/
|
|
1323
|
+
hasChildren(): boolean;
|
|
1324
|
+
/**
|
|
1325
|
+
* Checks if the Group is a leaf node (i.e., has no children).
|
|
1326
|
+
*
|
|
1327
|
+
* @returns True if the Group is a leaf, otherwise false.
|
|
1328
|
+
*/
|
|
1329
|
+
isLeaf(): boolean;
|
|
1330
|
+
/**
|
|
1331
|
+
* Checks if the Group is a root node (i.e., has no parent).
|
|
1332
|
+
*
|
|
1333
|
+
* @returns True if the Group is a root, otherwise false.
|
|
1334
|
+
*/
|
|
1335
|
+
isRoot(): boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* Retrieves the depth of the Group in the hierarchy.
|
|
1338
|
+
*
|
|
1339
|
+
* @returns The depth of the Group.
|
|
1340
|
+
*/
|
|
1341
|
+
getDepth(): number;
|
|
1342
|
+
/**
|
|
1343
|
+
* Retrieves the root Group of the current Group.
|
|
1344
|
+
*
|
|
1345
|
+
* @returns The root Group.
|
|
1346
|
+
*/
|
|
1347
|
+
getRoot(): Group;
|
|
1348
|
+
/**
|
|
1349
|
+
* Retrieves the name of the root Group.
|
|
1350
|
+
*
|
|
1351
|
+
* @returns The name of the root Group.
|
|
1352
|
+
*/
|
|
1353
|
+
getRootName(): string;
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* @returns True if this group has any account in it
|
|
1359
|
+
*/
|
|
1360
|
+
hasAccounts(): boolean | undefined;
|
|
1289
1361
|
/**
|
|
1290
1362
|
* Perform create new group.
|
|
1291
1363
|
*/
|
package/lib/model/Book.js
CHANGED
|
@@ -502,6 +502,19 @@ export class Book {
|
|
|
502
502
|
if (id) {
|
|
503
503
|
this.idAccountMap.set(id, account);
|
|
504
504
|
}
|
|
505
|
+
this.linkAccountsAndGroups(account);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/** @internal */
|
|
509
|
+
linkAccountsAndGroups(account) {
|
|
510
|
+
var _a;
|
|
511
|
+
const groupPayloads = account.payload.groups || [];
|
|
512
|
+
for (const groupPayload of groupPayloads) {
|
|
513
|
+
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || "");
|
|
514
|
+
if (group != null) {
|
|
515
|
+
group.addAccount(account);
|
|
516
|
+
//TODO add known group to account
|
|
517
|
+
}
|
|
505
518
|
}
|
|
506
519
|
}
|
|
507
520
|
/** @internal */
|
|
@@ -581,6 +594,9 @@ export class Book {
|
|
|
581
594
|
for (const group of groupsObj) {
|
|
582
595
|
this.updateGroupCache(group);
|
|
583
596
|
}
|
|
597
|
+
for (const group of groupsObj) {
|
|
598
|
+
group.buildGroupTree(this.idGroupMap);
|
|
599
|
+
}
|
|
584
600
|
return groupsObj;
|
|
585
601
|
}
|
|
586
602
|
/**
|
package/lib/model/Group.js
CHANGED
|
@@ -21,6 +21,7 @@ import { Account } from './Account.js';
|
|
|
21
21
|
*/
|
|
22
22
|
export class Group {
|
|
23
23
|
constructor(book, payload) {
|
|
24
|
+
this.children = [];
|
|
24
25
|
this.book = book;
|
|
25
26
|
this.payload = payload || {
|
|
26
27
|
createdAt: `${Date.now()}`
|
|
@@ -38,33 +39,6 @@ export class Group {
|
|
|
38
39
|
getId() {
|
|
39
40
|
return this.payload.id;
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
-
* @returns The parent Group
|
|
43
|
-
*/
|
|
44
|
-
getParent() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (this.payload.parent) {
|
|
47
|
-
return yield this.book.getGroup(this.payload.parent.id);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the parent Group.
|
|
56
|
-
*
|
|
57
|
-
* @returns This Group, for chainning.
|
|
58
|
-
*/
|
|
59
|
-
setParent(group) {
|
|
60
|
-
if (group) {
|
|
61
|
-
this.payload.parent = { id: group.getId(), name: group.getName(), normalizedName: group.getNormalizedName() };
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.payload.parent = undefined;
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
42
|
/**
|
|
69
43
|
* @returns The name of this Group
|
|
70
44
|
*/
|
|
@@ -96,6 +70,9 @@ export class Group {
|
|
|
96
70
|
*/
|
|
97
71
|
getAccounts() {
|
|
98
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (this.accounts) {
|
|
74
|
+
return Array.from(this.accounts);
|
|
75
|
+
}
|
|
99
76
|
let accountsPlain = yield GroupService.getAccounts(this.book.getId(), this.getId());
|
|
100
77
|
if (!accountsPlain) {
|
|
101
78
|
return [];
|
|
@@ -104,12 +81,6 @@ export class Group {
|
|
|
104
81
|
return accounts;
|
|
105
82
|
});
|
|
106
83
|
}
|
|
107
|
-
/**
|
|
108
|
-
* @returns True if this group has any account in it
|
|
109
|
-
*/
|
|
110
|
-
hasAccounts() {
|
|
111
|
-
return this.payload.hasAccounts;
|
|
112
|
-
}
|
|
113
84
|
/**
|
|
114
85
|
* @returns The type for of the accounts of this group. Null if mixed
|
|
115
86
|
*/
|
|
@@ -191,6 +162,173 @@ export class Group {
|
|
|
191
162
|
this.payload.hidden = hidden;
|
|
192
163
|
return this;
|
|
193
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Tell if the Group is permanent
|
|
167
|
+
*/
|
|
168
|
+
isPermanent() {
|
|
169
|
+
return this.payload.permanent;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @returns The parent Group
|
|
173
|
+
*/
|
|
174
|
+
getParent() {
|
|
175
|
+
return this.parent;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Sets the parent Group.
|
|
179
|
+
*
|
|
180
|
+
* @returns This Group, for chainning.
|
|
181
|
+
*/
|
|
182
|
+
setParent(group) {
|
|
183
|
+
if (group) {
|
|
184
|
+
this.payload.parent = { id: group.getId(), name: group.getName(), normalizedName: group.getNormalizedName() };
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.payload.parent = undefined;
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Checks if the Group has a parent.
|
|
193
|
+
*
|
|
194
|
+
* @returns True if the Group has a parent, otherwise false.
|
|
195
|
+
*/
|
|
196
|
+
hasParent() {
|
|
197
|
+
return this.payload.parent != null;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves the children of the Group.
|
|
201
|
+
*
|
|
202
|
+
* @returns An array of child Groups.
|
|
203
|
+
*/
|
|
204
|
+
getChildren() {
|
|
205
|
+
return this.children || [];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Retrieves all descendant Groups of the current Group.
|
|
209
|
+
*
|
|
210
|
+
* @returns A set of descendant Groups.
|
|
211
|
+
*/
|
|
212
|
+
getDescendants() {
|
|
213
|
+
const descendants = new Set();
|
|
214
|
+
this.traverseDescendants(this, descendants);
|
|
215
|
+
return descendants;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves the IDs of all descendant Groups in a tree structure.
|
|
219
|
+
*
|
|
220
|
+
* @returns A set of descendant Group IDs.
|
|
221
|
+
*/
|
|
222
|
+
getDescendantTreeIds() {
|
|
223
|
+
return new Set(Array.from(this.getDescendants()).map(g => g.getId() || ""));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Checks if the Group has any children.
|
|
227
|
+
*
|
|
228
|
+
* @returns True if the Group has children, otherwise false.
|
|
229
|
+
*/
|
|
230
|
+
hasChildren() {
|
|
231
|
+
return this.getChildren().length > 0;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Checks if the Group is a leaf node (i.e., has no children).
|
|
235
|
+
*
|
|
236
|
+
* @returns True if the Group is a leaf, otherwise false.
|
|
237
|
+
*/
|
|
238
|
+
isLeaf() {
|
|
239
|
+
return this.getChildren().length === 0;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Checks if the Group is a root node (i.e., has no parent).
|
|
243
|
+
*
|
|
244
|
+
* @returns True if the Group is a root, otherwise false.
|
|
245
|
+
*/
|
|
246
|
+
isRoot() {
|
|
247
|
+
return this.getParent() == undefined;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Retrieves the depth of the Group in the hierarchy.
|
|
251
|
+
*
|
|
252
|
+
* @returns The depth of the Group.
|
|
253
|
+
*/
|
|
254
|
+
getDepth() {
|
|
255
|
+
if (this.depth == undefined) {
|
|
256
|
+
if (this.parent) {
|
|
257
|
+
this.depth = this.parent.getDepth() + 1;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this.depth = 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return this.depth;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Retrieves the root Group of the current Group.
|
|
267
|
+
*
|
|
268
|
+
* @returns The root Group.
|
|
269
|
+
*/
|
|
270
|
+
getRoot() {
|
|
271
|
+
if (this.root == undefined) {
|
|
272
|
+
if (this.parent != undefined) {
|
|
273
|
+
this.root = this.parent.getRoot();
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.root = this;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return this.root;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Retrieves the name of the root Group.
|
|
283
|
+
*
|
|
284
|
+
* @returns The name of the root Group.
|
|
285
|
+
*/
|
|
286
|
+
getRootName() {
|
|
287
|
+
const root = this.getRoot();
|
|
288
|
+
if (root != null) {
|
|
289
|
+
return root.getName() || "";
|
|
290
|
+
}
|
|
291
|
+
return "";
|
|
292
|
+
}
|
|
293
|
+
/** @internal */
|
|
294
|
+
traverseDescendants(group, descendants) {
|
|
295
|
+
descendants.add(group);
|
|
296
|
+
const children = group.getChildren();
|
|
297
|
+
if (children.length > 0) {
|
|
298
|
+
for (const child of children) {
|
|
299
|
+
this.traverseDescendants(child, descendants);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** @internal */
|
|
304
|
+
buildGroupTree(groupsMap) {
|
|
305
|
+
this.parent = undefined;
|
|
306
|
+
this.depth = undefined;
|
|
307
|
+
this.root = undefined;
|
|
308
|
+
if (this.payload.parent) {
|
|
309
|
+
const parentGroup = groupsMap.get(this.payload.parent.id || "");
|
|
310
|
+
if (parentGroup) {
|
|
311
|
+
this.parent = parentGroup;
|
|
312
|
+
parentGroup.getChildren().push(this);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/** @internal */
|
|
317
|
+
addAccount(account) {
|
|
318
|
+
if (account == null) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (!this.accounts) {
|
|
322
|
+
this.accounts = new Set();
|
|
323
|
+
}
|
|
324
|
+
this.accounts.add(account);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* @returns True if this group has any account in it
|
|
328
|
+
*/
|
|
329
|
+
hasAccounts() {
|
|
330
|
+
return this.payload.hasAccounts;
|
|
331
|
+
}
|
|
194
332
|
/**
|
|
195
333
|
* Perform create new group.
|
|
196
334
|
*/
|
|
@@ -42,7 +42,7 @@ export class HttpApiRequest extends HttpRequest {
|
|
|
42
42
|
if (errorResp.status == 404) {
|
|
43
43
|
return { data: null };
|
|
44
44
|
}
|
|
45
|
-
else if (this.retry <= 3) {
|
|
45
|
+
else if (errorResp.status != 400 && this.retry <= 3) {
|
|
46
46
|
this.retry++;
|
|
47
47
|
if (HttpApiRequest.config.requestRetryHandler) {
|
|
48
48
|
yield HttpApiRequest.config.requestRetryHandler(errorResp.status, errorResp.data, this.retry);
|