bkper-js 1.16.1 → 1.18.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
@@ -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
  *
@@ -788,6 +789,19 @@ export declare class Book {
788
789
  * @returns A TransactionPage object containing the list of transactions
789
790
  */
790
791
  listTransactions(query?: string, limit?: number, cursor?: string): Promise<TransactionList>;
792
+ /**
793
+ * Lists events in the Book based on the provided parameters.
794
+ *
795
+ * @param afterDate - The start date (inclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format. Can be null.
796
+ * @param beforeDate - The end date (exclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format. Can be null.
797
+ * @param onError - True to search only for events on error.
798
+ * @param resourceId - The ID of the event's resource (Transaction, Account, or Group). Can be null.
799
+ * @param limit - The maximum number of events to return.
800
+ * @param cursor - The cursor for pagination. Can be null.
801
+ *
802
+ * @returns An EventList object containing the list of events.
803
+ */
804
+ listEvents(afterDate: string | null, beforeDate: string | null, onError: boolean, resourceId: string | null, limit: number, cursor?: string): Promise<EventList>;
791
805
  /**
792
806
  * Retrieve a transaction by id
793
807
  */
@@ -1116,6 +1130,50 @@ export declare enum DecimalSeparator {
1116
1130
  DOT = "DOT"
1117
1131
  }
1118
1132
 
1133
+ /**
1134
+ * Represents an Event in the system.
1135
+ *
1136
+ * @public
1137
+ */
1138
+ export declare class Event {
1139
+ payload: bkper.Event;
1140
+ constructor(payload?: bkper.Event);
1141
+ /**
1142
+ * @returns The wrapped plain json object
1143
+ */
1144
+ json(): bkper.Event;
1145
+ }
1146
+
1147
+ /**
1148
+ * A list associated with an event query.
1149
+ */
1150
+ export declare class EventList {
1151
+ private payload;
1152
+
1153
+ constructor(book: Book, payload: bkper.EventList);
1154
+ /**
1155
+ * @returns The cursor associated with the query for pagination.
1156
+ */
1157
+ getCursor(): string | undefined;
1158
+ /**
1159
+ * @returns The first Event in the list.
1160
+ */
1161
+ getFirst(): Event | undefined;
1162
+ /**
1163
+ *
1164
+ * Get the total number of events in the list.
1165
+ *
1166
+ * @returns The total number of events.
1167
+ */
1168
+ size(): number;
1169
+ /**
1170
+ * Get the events in the list.
1171
+ *
1172
+ * @returns An array of Event objects.
1173
+ */
1174
+ getItems(): Event[];
1175
+ }
1176
+
1119
1177
  /**
1120
1178
  *
1121
1179
  * This class defines a File uploaded to a [[Book]].
@@ -1194,6 +1252,10 @@ export declare class File {
1194
1252
  */
1195
1253
  export declare class Group {
1196
1254
  payload: bkper.Group;
1255
+ private parent?;
1256
+ private depth?;
1257
+ private root?;
1258
+ private children;
1197
1259
 
1198
1260
 
1199
1261
  constructor(book: Book, payload?: bkper.Group);
@@ -1205,16 +1267,6 @@ export declare class Group {
1205
1267
  * @returns The id of this Group
1206
1268
  */
1207
1269
  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
1270
  /**
1219
1271
  * @returns The name of this Group
1220
1272
  */
@@ -1233,10 +1285,6 @@ export declare class Group {
1233
1285
  * @returns All Accounts of this group.
1234
1286
  */
1235
1287
  getAccounts(): Promise<Account[]>;
1236
- /**
1237
- * @returns True if this group has any account in it
1238
- */
1239
- hasAccounts(): boolean | undefined;
1240
1288
  /**
1241
1289
  * @returns The type for of the accounts of this group. Null if mixed
1242
1290
  */
@@ -1286,6 +1334,87 @@ export declare class Group {
1286
1334
  * Hide/Show group on main menu.
1287
1335
  */
1288
1336
  setHidden(hidden: boolean): Group;
1337
+ /**
1338
+ * Tell if the Group is permanent
1339
+ */
1340
+ isPermanent(): boolean | undefined;
1341
+ /**
1342
+ * @returns The parent Group
1343
+ */
1344
+ getParent(): Group | undefined;
1345
+ /**
1346
+ * Sets the parent Group.
1347
+ *
1348
+ * @returns This Group, for chainning.
1349
+ */
1350
+ setParent(group: Group | null | undefined): Group;
1351
+ /**
1352
+ * Checks if the Group has a parent.
1353
+ *
1354
+ * @returns True if the Group has a parent, otherwise false.
1355
+ */
1356
+ hasParent(): boolean;
1357
+ /**
1358
+ * Retrieves the children of the Group.
1359
+ *
1360
+ * @returns An array of child Groups.
1361
+ */
1362
+ getChildren(): Group[];
1363
+ /**
1364
+ * Retrieves all descendant Groups of the current Group.
1365
+ *
1366
+ * @returns A set of descendant Groups.
1367
+ */
1368
+ getDescendants(): Set<Group>;
1369
+ /**
1370
+ * Retrieves the IDs of all descendant Groups in a tree structure.
1371
+ *
1372
+ * @returns A set of descendant Group IDs.
1373
+ */
1374
+ getDescendantTreeIds(): Set<string>;
1375
+ /**
1376
+ * Checks if the Group has any children.
1377
+ *
1378
+ * @returns True if the Group has children, otherwise false.
1379
+ */
1380
+ hasChildren(): boolean;
1381
+ /**
1382
+ * Checks if the Group is a leaf node (i.e., has no children).
1383
+ *
1384
+ * @returns True if the Group is a leaf, otherwise false.
1385
+ */
1386
+ isLeaf(): boolean;
1387
+ /**
1388
+ * Checks if the Group is a root node (i.e., has no parent).
1389
+ *
1390
+ * @returns True if the Group is a root, otherwise false.
1391
+ */
1392
+ isRoot(): boolean;
1393
+ /**
1394
+ * Retrieves the depth of the Group in the hierarchy.
1395
+ *
1396
+ * @returns The depth of the Group.
1397
+ */
1398
+ getDepth(): number;
1399
+ /**
1400
+ * Retrieves the root Group of the current Group.
1401
+ *
1402
+ * @returns The root Group.
1403
+ */
1404
+ getRoot(): Group;
1405
+ /**
1406
+ * Retrieves the name of the root Group.
1407
+ *
1408
+ * @returns The name of the root Group.
1409
+ */
1410
+ getRootName(): string;
1411
+
1412
+
1413
+
1414
+ /**
1415
+ * @returns True if this group has any account in it
1416
+ */
1417
+ hasAccounts(): boolean | undefined;
1289
1418
  /**
1290
1419
  * Perform create new group.
1291
1420
  */
package/lib/index.js CHANGED
@@ -18,6 +18,8 @@ export { Integration } from './model/Integration.js';
18
18
  export { Template } from './model/Template.js';
19
19
  export { Transaction } from './model/Transaction.js';
20
20
  export { TransactionList } from './model/TransactionList.js';
21
+ export { Event } from './model/Event.js';
22
+ export { EventList } from './model/EventList.js';
21
23
  export { User } from './model/User.js';
22
24
  export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, Period, Month } from './model/Enums.js';
23
25
  //# sourceMappingURL=index.js.map
package/lib/model/Book.js CHANGED
@@ -13,9 +13,11 @@ import * as FileService from '../service/file-service.js';
13
13
  import * as GroupService from '../service/group-service.js';
14
14
  import * as IntegrationService from '../service/integration-service.js';
15
15
  import * as TransactionService from '../service/transaction-service.js';
16
+ import * as EventService from '../service/event-service.js';
16
17
  import * as Utils from '../utils.js';
17
18
  import { Account } from './Account.js';
18
19
  import { Collection } from './Collection.js';
20
+ import { EventList } from './EventList.js';
19
21
  import { File } from './File.js';
20
22
  import { Group } from './Group.js';
21
23
  import { Integration } from './Integration.js';
@@ -502,6 +504,19 @@ export class Book {
502
504
  if (id) {
503
505
  this.idAccountMap.set(id, account);
504
506
  }
507
+ this.linkAccountsAndGroups(account);
508
+ }
509
+ }
510
+ /** @internal */
511
+ linkAccountsAndGroups(account) {
512
+ var _a;
513
+ const groupPayloads = account.payload.groups || [];
514
+ for (const groupPayload of groupPayloads) {
515
+ const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || "");
516
+ if (group != null) {
517
+ group.addAccount(account);
518
+ //TODO add known group to account
519
+ }
505
520
  }
506
521
  }
507
522
  /** @internal */
@@ -581,6 +596,9 @@ export class Book {
581
596
  for (const group of groupsObj) {
582
597
  this.updateGroupCache(group);
583
598
  }
599
+ for (const group of groupsObj) {
600
+ group.buildGroupTree(this.idGroupMap);
601
+ }
584
602
  return groupsObj;
585
603
  }
586
604
  /**
@@ -623,6 +641,24 @@ export class Book {
623
641
  return new TransactionList(this, transactionsList);
624
642
  });
625
643
  }
644
+ /**
645
+ * Lists events in the Book based on the provided parameters.
646
+ *
647
+ * @param afterDate - The start date (inclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format. Can be null.
648
+ * @param beforeDate - The end date (exclusive) for the events search range, in [RFC3339](https://en.wikipedia.org/wiki/ISO_8601#RFC_3339) format. Can be null.
649
+ * @param onError - True to search only for events on error.
650
+ * @param resourceId - The ID of the event's resource (Transaction, Account, or Group). Can be null.
651
+ * @param limit - The maximum number of events to return.
652
+ * @param cursor - The cursor for pagination. Can be null.
653
+ *
654
+ * @returns An EventList object containing the list of events.
655
+ */
656
+ listEvents(afterDate, beforeDate, onError, resourceId, limit, cursor) {
657
+ return __awaiter(this, void 0, void 0, function* () {
658
+ const eventsList = yield EventService.listEvents(this, afterDate, beforeDate, onError, resourceId, limit, cursor);
659
+ return new EventList(this, eventsList);
660
+ });
661
+ }
626
662
  /**
627
663
  * Retrieve a transaction by id
628
664
  */
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Represents an Event in the system.
3
+ *
4
+ * @public
5
+ */
6
+ export class Event {
7
+ constructor(payload) {
8
+ this.payload = payload || {};
9
+ }
10
+ /**
11
+ * @returns The wrapped plain json object
12
+ */
13
+ json() {
14
+ return Object.assign({}, this.payload);
15
+ }
16
+ }
17
+ //# sourceMappingURL=Event.js.map
@@ -0,0 +1,43 @@
1
+ import { Event } from "./Event.js";
2
+ /**
3
+ * A list associated with an event query.
4
+ */
5
+ export class EventList {
6
+ constructor(book, payload) {
7
+ this.book = book;
8
+ this.payload = payload || {};
9
+ }
10
+ /**
11
+ * @returns The cursor associated with the query for pagination.
12
+ */
13
+ getCursor() {
14
+ return this.payload.cursor;
15
+ }
16
+ /**
17
+ * @returns The first Event in the list.
18
+ */
19
+ getFirst() {
20
+ const events = this.getItems();
21
+ return events.length > 0 ? events[0] : undefined;
22
+ }
23
+ /**
24
+ *
25
+ * Get the total number of events in the list.
26
+ *
27
+ * @returns The total number of events.
28
+ */
29
+ size() {
30
+ var _a;
31
+ return ((_a = this.payload.items) === null || _a === void 0 ? void 0 : _a.length) || 0;
32
+ }
33
+ /**
34
+ * Get the events in the list.
35
+ *
36
+ * @returns An array of Event objects.
37
+ */
38
+ getItems() {
39
+ var _a;
40
+ return ((_a = this.payload.items) === null || _a === void 0 ? void 0 : _a.map(event => new Event(event))) || [];
41
+ }
42
+ }
43
+ //# sourceMappingURL=EventList.js.map
@@ -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
  */
@@ -0,0 +1,26 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { HttpBooksApiV5Request } from "./http-api-request.js";
11
+ export function listEvents(book, afterDate, beforeDate, onError, resourceId, limit, cursor) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ let request = new HttpBooksApiV5Request(`${book.getId()}/events`);
14
+ request.addParam('after', afterDate);
15
+ request.addParam('before', beforeDate);
16
+ request.addParam('error', onError);
17
+ request.addParam('resoureId', resourceId);
18
+ request.addParam('limit', limit);
19
+ if (cursor != null) {
20
+ request.setHeader('cursor', cursor);
21
+ }
22
+ var response = yield request.fetch();
23
+ return response.data;
24
+ });
25
+ }
26
+ //# sourceMappingURL=event-service.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.16.1",
3
+ "version": "1.18.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",