bkper-js 1.34.6 → 1.35.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 +31 -0
- package/lib/model/App.js +24 -0
- package/lib/model/Book.js +76 -22
- package/lib/model/Group.js +18 -6
- package/lib/service/account-service.js +7 -0
- package/lib/service/group-service.js +7 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -386,6 +386,10 @@ export declare class App {
|
|
|
386
386
|
* @return The events bound to this App
|
|
387
387
|
*/
|
|
388
388
|
getEvents(): EventType[] | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* @return True if this App is published
|
|
391
|
+
*/
|
|
392
|
+
isPublished(): boolean;
|
|
389
393
|
/**
|
|
390
394
|
* @return True if this App is conversational
|
|
391
395
|
*/
|
|
@@ -408,6 +412,18 @@ export declare class App {
|
|
|
408
412
|
* @returns This App for chaining
|
|
409
413
|
*/
|
|
410
414
|
setUserEmails(emails?: string): App;
|
|
415
|
+
/**
|
|
416
|
+
* @return The name of the owner of this App
|
|
417
|
+
*/
|
|
418
|
+
getOwnerName(): string | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* @return The logo url of the owner of this App
|
|
421
|
+
*/
|
|
422
|
+
getOwnerLogoUrl(): string | undefined;
|
|
423
|
+
/**
|
|
424
|
+
* @return The file patterns the App handles - E.g *.pdf *.csv
|
|
425
|
+
*/
|
|
426
|
+
getFilePatterns(): string[] | undefined;
|
|
411
427
|
/**
|
|
412
428
|
* Sets the developer email
|
|
413
429
|
*
|
|
@@ -952,6 +968,18 @@ export declare class Book {
|
|
|
952
968
|
* Replay [[Events]] on the Book, in batch.
|
|
953
969
|
*/
|
|
954
970
|
batchReplayEvents(events: Event[], errorOnly?: boolean): Promise<void>;
|
|
971
|
+
/**
|
|
972
|
+
* Create [[Accounts]] on the Book, in batch.
|
|
973
|
+
*
|
|
974
|
+
* @return The created Accounts
|
|
975
|
+
*/
|
|
976
|
+
batchCreateAccounts(accounts: Account[]): Promise<Account[]>;
|
|
977
|
+
/**
|
|
978
|
+
* Create [[Groups]] on the Book, in batch.
|
|
979
|
+
*
|
|
980
|
+
* @return The created Groups
|
|
981
|
+
*/
|
|
982
|
+
batchCreateGroups(groups: Group[]): Promise<Group[]>;
|
|
955
983
|
/**
|
|
956
984
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
957
985
|
*/
|
|
@@ -998,6 +1026,8 @@ export declare class Book {
|
|
|
998
1026
|
|
|
999
1027
|
|
|
1000
1028
|
|
|
1029
|
+
|
|
1030
|
+
|
|
1001
1031
|
/**
|
|
1002
1032
|
* Gets a [[Group]] object
|
|
1003
1033
|
*
|
|
@@ -1874,6 +1904,7 @@ export declare class Group {
|
|
|
1874
1904
|
|
|
1875
1905
|
|
|
1876
1906
|
|
|
1907
|
+
|
|
1877
1908
|
/**
|
|
1878
1909
|
* @returns True if this group has any account in it
|
|
1879
1910
|
*/
|
package/lib/model/App.js
CHANGED
|
@@ -71,6 +71,12 @@ export class App {
|
|
|
71
71
|
getEvents() {
|
|
72
72
|
return this.payload.events;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @return True if this App is published
|
|
76
|
+
*/
|
|
77
|
+
isPublished() {
|
|
78
|
+
return this.payload.published || false;
|
|
79
|
+
}
|
|
74
80
|
/**
|
|
75
81
|
* @return True if this App is conversational
|
|
76
82
|
*/
|
|
@@ -104,6 +110,24 @@ export class App {
|
|
|
104
110
|
this.payload.userEmails = emails;
|
|
105
111
|
return this;
|
|
106
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* @return The name of the owner of this App
|
|
115
|
+
*/
|
|
116
|
+
getOwnerName() {
|
|
117
|
+
return this.payload.ownerName;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @return The logo url of the owner of this App
|
|
121
|
+
*/
|
|
122
|
+
getOwnerLogoUrl() {
|
|
123
|
+
return this.payload.ownerLogoUrl;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @return The file patterns the App handles - E.g *.pdf *.csv
|
|
127
|
+
*/
|
|
128
|
+
getFilePatterns() {
|
|
129
|
+
return this.payload.filePatterns;
|
|
130
|
+
}
|
|
107
131
|
/**
|
|
108
132
|
* Sets the developer email
|
|
109
133
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -436,6 +436,51 @@ export class Book {
|
|
|
436
436
|
yield EventService.replayEventsBatch(this, eventList, errorOnly);
|
|
437
437
|
});
|
|
438
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Create [[Accounts]] on the Book, in batch.
|
|
441
|
+
*
|
|
442
|
+
* @return The created Accounts
|
|
443
|
+
*/
|
|
444
|
+
batchCreateAccounts(accounts) {
|
|
445
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
if (accounts.length > 0) {
|
|
447
|
+
const accountList = { items: accounts.map(a => a.json()) };
|
|
448
|
+
const payloads = yield AccountService.createAccounts(this.getId(), accountList);
|
|
449
|
+
const createdAccounts = [];
|
|
450
|
+
for (const payload of payloads) {
|
|
451
|
+
const account = new Account(this, payload);
|
|
452
|
+
createdAccounts.push(account);
|
|
453
|
+
this.updateAccountCache(account);
|
|
454
|
+
}
|
|
455
|
+
return createdAccounts;
|
|
456
|
+
}
|
|
457
|
+
return [];
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Create [[Groups]] on the Book, in batch.
|
|
462
|
+
*
|
|
463
|
+
* @return The created Groups
|
|
464
|
+
*/
|
|
465
|
+
batchCreateGroups(groups) {
|
|
466
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
+
if (groups.length > 0) {
|
|
468
|
+
const groupList = { items: groups.map(g => g.json()) };
|
|
469
|
+
const payloads = yield GroupService.createGroups(this.getId(), groupList);
|
|
470
|
+
const createdGroups = [];
|
|
471
|
+
for (const payload of payloads) {
|
|
472
|
+
const group = new Group(this, payload);
|
|
473
|
+
createdGroups.push(group);
|
|
474
|
+
this.updateGroupCache(group);
|
|
475
|
+
if (this.idGroupMap) {
|
|
476
|
+
group.buildGroupTree(this.idGroupMap);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return createdGroups;
|
|
480
|
+
}
|
|
481
|
+
return [];
|
|
482
|
+
});
|
|
483
|
+
}
|
|
439
484
|
/**
|
|
440
485
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
441
486
|
*/
|
|
@@ -517,22 +562,23 @@ export class Book {
|
|
|
517
562
|
if (!idOrName || idOrName.trim() == '') {
|
|
518
563
|
return undefined;
|
|
519
564
|
}
|
|
520
|
-
let account;
|
|
521
565
|
if (this.idAccountMap) {
|
|
522
|
-
|
|
523
|
-
if (account) {
|
|
524
|
-
return account;
|
|
525
|
-
}
|
|
566
|
+
return this.idAccountMap.get(idOrName);
|
|
526
567
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
568
|
+
else {
|
|
569
|
+
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName);
|
|
570
|
+
if (accountPayload) {
|
|
571
|
+
return new Account(this, accountPayload);
|
|
572
|
+
}
|
|
531
573
|
}
|
|
532
574
|
return undefined;
|
|
533
575
|
});
|
|
534
576
|
}
|
|
535
577
|
/** @internal */
|
|
578
|
+
getGroupsMap() {
|
|
579
|
+
return this.idGroupMap;
|
|
580
|
+
}
|
|
581
|
+
/** @internal */
|
|
536
582
|
updateGroupCache(group) {
|
|
537
583
|
if (this.idGroupMap) {
|
|
538
584
|
const id = group.getId();
|
|
@@ -570,10 +616,22 @@ export class Book {
|
|
|
570
616
|
}
|
|
571
617
|
}
|
|
572
618
|
/** @internal */
|
|
619
|
+
unlinkAccountsAndGroups(account) {
|
|
620
|
+
var _a;
|
|
621
|
+
const groupPayloads = account.payload.groups || [];
|
|
622
|
+
for (const groupPayload of groupPayloads) {
|
|
623
|
+
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || "");
|
|
624
|
+
if (group != null) {
|
|
625
|
+
group.removeAccount(account);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
/** @internal */
|
|
573
630
|
removeAccountCache(account) {
|
|
574
631
|
if (this.idAccountMap) {
|
|
575
632
|
this.idAccountMap.delete(account.getId() || '');
|
|
576
633
|
}
|
|
634
|
+
this.unlinkAccountsAndGroups(account);
|
|
577
635
|
}
|
|
578
636
|
/** @internal */
|
|
579
637
|
getMostRecentLockDate_() {
|
|
@@ -604,23 +662,19 @@ export class Book {
|
|
|
604
662
|
*/
|
|
605
663
|
getGroup(idOrName) {
|
|
606
664
|
return __awaiter(this, void 0, void 0, function* () {
|
|
607
|
-
if (!idOrName) {
|
|
665
|
+
if (!idOrName || idOrName.trim() == '') {
|
|
608
666
|
return undefined;
|
|
609
667
|
}
|
|
610
|
-
idOrName = idOrName + '';
|
|
611
668
|
if (this.idGroupMap) {
|
|
612
|
-
|
|
613
|
-
if (group) {
|
|
614
|
-
return group;
|
|
615
|
-
}
|
|
669
|
+
return this.idGroupMap.get(idOrName);
|
|
616
670
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
671
|
+
else {
|
|
672
|
+
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName);
|
|
673
|
+
if (groupPayload) {
|
|
674
|
+
return new Group(this, groupPayload);
|
|
675
|
+
}
|
|
620
676
|
}
|
|
621
|
-
|
|
622
|
-
this.updateGroupCache(group);
|
|
623
|
-
return group;
|
|
677
|
+
return undefined;
|
|
624
678
|
});
|
|
625
679
|
}
|
|
626
680
|
/**
|
|
@@ -682,7 +736,7 @@ export class Book {
|
|
|
682
736
|
if (this.idGroupMap) {
|
|
683
737
|
for (const group of this.idGroupMap.values()) {
|
|
684
738
|
if (group.accounts == null) {
|
|
685
|
-
group.accounts = new
|
|
739
|
+
group.accounts = new Map();
|
|
686
740
|
}
|
|
687
741
|
}
|
|
688
742
|
}
|
package/lib/model/Group.js
CHANGED
|
@@ -71,7 +71,7 @@ export class Group {
|
|
|
71
71
|
getAccounts() {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
73
|
if (this.accounts) {
|
|
74
|
-
return Array.from(this.accounts);
|
|
74
|
+
return Array.from(this.accounts.values());
|
|
75
75
|
}
|
|
76
76
|
let accountsPlain = yield GroupService.getAccounts(this.book.getId(), this.getId());
|
|
77
77
|
if (!accountsPlain) {
|
|
@@ -327,13 +327,21 @@ export class Group {
|
|
|
327
327
|
}
|
|
328
328
|
/** @internal */
|
|
329
329
|
addAccount(account) {
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
const id = account === null || account === void 0 ? void 0 : account.getId();
|
|
331
|
+
if (id) {
|
|
332
|
+
if (!this.accounts) {
|
|
333
|
+
this.accounts = new Map();
|
|
334
|
+
}
|
|
335
|
+
this.accounts.set(id, account);
|
|
332
336
|
}
|
|
333
|
-
|
|
334
|
-
|
|
337
|
+
}
|
|
338
|
+
/** @internal */
|
|
339
|
+
removeAccount(account) {
|
|
340
|
+
var _a;
|
|
341
|
+
const id = account === null || account === void 0 ? void 0 : account.getId();
|
|
342
|
+
if (id) {
|
|
343
|
+
(_a = this.accounts) === null || _a === void 0 ? void 0 : _a.delete(id);
|
|
335
344
|
}
|
|
336
|
-
this.accounts.add(account);
|
|
337
345
|
}
|
|
338
346
|
/**
|
|
339
347
|
* @returns True if this group has any account in it
|
|
@@ -348,6 +356,10 @@ export class Group {
|
|
|
348
356
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
357
|
this.payload = yield GroupService.createGroup(this.book.getId(), this.payload);
|
|
350
358
|
this.book.updateGroupCache(this);
|
|
359
|
+
const bookGroupsMap = this.book.getGroupsMap();
|
|
360
|
+
if (bookGroupsMap) {
|
|
361
|
+
this.buildGroupTree(bookGroupsMap);
|
|
362
|
+
}
|
|
351
363
|
return this;
|
|
352
364
|
});
|
|
353
365
|
}
|
|
@@ -14,6 +14,13 @@ export function createAccount(bookId, account) {
|
|
|
14
14
|
return response.data;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
export function createAccounts(bookId, payload) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/accounts/batch`).setMethod('POST').setPayload(payload).fetch();
|
|
21
|
+
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
17
24
|
export function updateAccount(bookId, account) {
|
|
18
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
26
|
var payload = account;
|
|
@@ -14,6 +14,13 @@ export function createGroup(bookId, group) {
|
|
|
14
14
|
return response.data;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
export function createGroups(bookId, payload) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/groups/batch`).setMethod('POST').setPayload(payload).fetch();
|
|
21
|
+
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
17
24
|
export function updateGroup(bookId, group) {
|
|
18
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
26
|
var response = yield new HttpBooksApiV5Request(`${bookId}/groups`).setMethod('PUT').setPayload(group).fetch();
|