bkper-js 2.7.1 → 2.8.1
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/CHANGELOG.md +26 -0
- package/lib/index.d.ts +172 -99
- package/lib/model/Account.js +20 -21
- package/lib/model/App.js +72 -21
- package/lib/model/Bkper.js +42 -30
- package/lib/model/Book.js +109 -99
- package/lib/model/BotResponse.js +2 -2
- package/lib/model/Collaborator.js +12 -11
- package/lib/model/Collection.js +24 -19
- package/lib/model/Connection.js +28 -18
- package/lib/model/Conversation.js +20 -13
- package/lib/model/File.js +19 -17
- package/lib/model/Group.js +29 -21
- package/lib/model/Integration.js +17 -13
- package/lib/model/Message.js +20 -16
- package/lib/model/Query.js +12 -11
- package/lib/model/Resource.js +23 -0
- package/lib/model/Template.js +10 -7
- package/lib/model/Transaction.js +61 -43
- package/lib/model/User.js +14 -12
- package/lib/service/account-service.js +12 -12
- package/lib/service/app-service.js +8 -8
- package/lib/service/balances-service.js +2 -2
- package/lib/service/book-service.js +14 -14
- package/lib/service/collaborator-service.js +6 -6
- package/lib/service/collection-service.js +12 -12
- package/lib/service/connection-service.js +12 -15
- package/lib/service/conversation-service.js +10 -10
- package/lib/service/event-service.js +8 -8
- package/lib/service/file-service.js +4 -4
- package/lib/service/group-service.js +16 -16
- package/lib/service/http-api-request.js +54 -45
- package/lib/service/integration-service.js +8 -8
- package/lib/service/query-service.js +8 -8
- package/lib/service/template-service.js +2 -2
- package/lib/service/transaction-service.js +32 -32
- package/lib/service/user-service.js +4 -4
- package/package.json +1 -1
package/lib/model/Book.js
CHANGED
|
@@ -7,30 +7,32 @@ 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
|
|
11
|
-
import * as BookService from
|
|
12
|
-
import * as QueryService from
|
|
13
|
-
import * as BalancesService from
|
|
14
|
-
import * as FileService from
|
|
15
|
-
import * as GroupService from
|
|
16
|
-
import * as IntegrationService from
|
|
17
|
-
import * as TransactionService from
|
|
18
|
-
import * as EventService from
|
|
19
|
-
import * as CollaboratorService from
|
|
20
|
-
import * as Utils from
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
10
|
+
import * as AccountService from "../service/account-service.js";
|
|
11
|
+
import * as BookService from "../service/book-service.js";
|
|
12
|
+
import * as QueryService from "../service/query-service.js";
|
|
13
|
+
import * as BalancesService from "../service/balances-service.js";
|
|
14
|
+
import * as FileService from "../service/file-service.js";
|
|
15
|
+
import * as GroupService from "../service/group-service.js";
|
|
16
|
+
import * as IntegrationService from "../service/integration-service.js";
|
|
17
|
+
import * as TransactionService from "../service/transaction-service.js";
|
|
18
|
+
import * as EventService from "../service/event-service.js";
|
|
19
|
+
import * as CollaboratorService from "../service/collaborator-service.js";
|
|
20
|
+
import * as Utils from "../utils.js";
|
|
21
|
+
import { Resource } from "./Resource.js";
|
|
22
|
+
import { Account } from "./Account.js";
|
|
23
|
+
import { Collaborator } from "./Collaborator.js";
|
|
24
|
+
import { Collection } from "./Collection.js";
|
|
25
|
+
import { Permission, } from "./Enums.js";
|
|
26
|
+
import { EventList } from "./EventList.js";
|
|
27
|
+
import { File } from "./File.js";
|
|
28
|
+
import { Group } from "./Group.js";
|
|
29
|
+
import { Integration } from "./Integration.js";
|
|
30
|
+
import { Transaction } from "./Transaction.js";
|
|
31
|
+
import { TransactionList } from "./TransactionList.js";
|
|
32
|
+
import { BalancesReport } from "./BalancesReport.js";
|
|
33
|
+
import { App } from "./App.js";
|
|
34
|
+
import { Query } from "./Query.js";
|
|
35
|
+
import { Bkper } from "./Bkper.js";
|
|
34
36
|
/**
|
|
35
37
|
* A Book represents a [General Ledger](https://en.wikipedia.org/wiki/General_ledger) for a company or business, but can also represent a [Ledger](https://en.wikipedia.org/wiki/Ledger) for a project or department
|
|
36
38
|
*
|
|
@@ -38,9 +40,10 @@ import { Query } from './Query.js';
|
|
|
38
40
|
*
|
|
39
41
|
* @public
|
|
40
42
|
*/
|
|
41
|
-
export class Book {
|
|
42
|
-
constructor(payload) {
|
|
43
|
-
|
|
43
|
+
export class Book extends Resource {
|
|
44
|
+
constructor(payload, config) {
|
|
45
|
+
super(payload);
|
|
46
|
+
this.config = config;
|
|
44
47
|
if (this.payload.permission == Permission.RECORDER) {
|
|
45
48
|
this.payload.groups = this.payload.groups || [];
|
|
46
49
|
this.payload.accounts = this.payload.accounts || [];
|
|
@@ -49,12 +52,12 @@ export class Book {
|
|
|
49
52
|
this.mapAccounts(this.payload.accounts);
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
* Gets
|
|
55
|
+
* Gets the configuration object for this Book.
|
|
53
56
|
*
|
|
54
|
-
* @returns
|
|
57
|
+
* @returns The Config object for this Book or the global config
|
|
55
58
|
*/
|
|
56
|
-
|
|
57
|
-
return
|
|
59
|
+
getConfig() {
|
|
60
|
+
return this.config || Bkper.globalConfig;
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
63
|
* Gets the unique identifier of this Book.
|
|
@@ -62,7 +65,7 @@ export class Book {
|
|
|
62
65
|
* @returns This Book's unique identifier
|
|
63
66
|
*/
|
|
64
67
|
getId() {
|
|
65
|
-
return this.payload.id ||
|
|
68
|
+
return this.payload.id || "";
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
71
|
* Gets the name of this Book.
|
|
@@ -336,7 +339,7 @@ export class Book {
|
|
|
336
339
|
* @returns The total number of posted transactions
|
|
337
340
|
*/
|
|
338
341
|
getTotalTransactions() {
|
|
339
|
-
return this.payload.totalTransactions ? +
|
|
342
|
+
return this.payload.totalTransactions ? +this.payload.totalTransactions : 0;
|
|
340
343
|
}
|
|
341
344
|
/**
|
|
342
345
|
* Gets the total number of posted transactions on current month.
|
|
@@ -344,7 +347,9 @@ export class Book {
|
|
|
344
347
|
* @returns The total number of posted transactions on current month
|
|
345
348
|
*/
|
|
346
349
|
getTotalTransactionsCurrentMonth() {
|
|
347
|
-
return this.payload.totalTransactionsCurrentMonth
|
|
350
|
+
return this.payload.totalTransactionsCurrentMonth
|
|
351
|
+
? +this.payload.totalTransactionsCurrentMonth
|
|
352
|
+
: 0;
|
|
348
353
|
}
|
|
349
354
|
/**
|
|
350
355
|
* Gets the total number of posted transactions on current year.
|
|
@@ -352,7 +357,9 @@ export class Book {
|
|
|
352
357
|
* @returns The total number of posted transactions on current year
|
|
353
358
|
*/
|
|
354
359
|
getTotalTransactionsCurrentYear() {
|
|
355
|
-
return this.payload.totalTransactionsCurrentYear
|
|
360
|
+
return this.payload.totalTransactionsCurrentYear
|
|
361
|
+
? +this.payload.totalTransactionsCurrentYear
|
|
362
|
+
: 0;
|
|
356
363
|
}
|
|
357
364
|
/**
|
|
358
365
|
* Gets the visibility of the book.
|
|
@@ -379,7 +386,8 @@ export class Book {
|
|
|
379
386
|
* @returns The custom properties object
|
|
380
387
|
*/
|
|
381
388
|
getProperties() {
|
|
382
|
-
return this.payload.properties != null
|
|
389
|
+
return this.payload.properties != null
|
|
390
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
383
391
|
}
|
|
384
392
|
/**
|
|
385
393
|
* Gets the property value for given keys. First property found will be retrieved.
|
|
@@ -392,7 +400,7 @@ export class Book {
|
|
|
392
400
|
for (let index = 0; index < keys.length; index++) {
|
|
393
401
|
const key = keys[index];
|
|
394
402
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
395
|
-
if (value != null && value.trim() !=
|
|
403
|
+
if (value != null && value.trim() != "") {
|
|
396
404
|
return value;
|
|
397
405
|
}
|
|
398
406
|
}
|
|
@@ -418,14 +426,14 @@ export class Book {
|
|
|
418
426
|
* @returns This Book, for chaining
|
|
419
427
|
*/
|
|
420
428
|
setProperty(key, value) {
|
|
421
|
-
if (key == null || key.trim() ==
|
|
429
|
+
if (key == null || key.trim() == "") {
|
|
422
430
|
return this;
|
|
423
431
|
}
|
|
424
432
|
if (this.payload.properties == null) {
|
|
425
433
|
this.payload.properties = {};
|
|
426
434
|
}
|
|
427
435
|
if (!value) {
|
|
428
|
-
value =
|
|
436
|
+
value = "";
|
|
429
437
|
}
|
|
430
438
|
this.payload.properties[key] = value;
|
|
431
439
|
return this;
|
|
@@ -463,7 +471,7 @@ export class Book {
|
|
|
463
471
|
*/
|
|
464
472
|
formatValue(value) {
|
|
465
473
|
if (!value) {
|
|
466
|
-
return
|
|
474
|
+
return "";
|
|
467
475
|
}
|
|
468
476
|
return Utils.formatValue(value, this.getDecimalSeparator(), this.getFractionDigits());
|
|
469
477
|
}
|
|
@@ -497,9 +505,9 @@ export class Book {
|
|
|
497
505
|
batchCreateTransactions(transactions) {
|
|
498
506
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
507
|
let transactionPayloads = [];
|
|
500
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
501
|
-
transactionPayloads = yield TransactionService.createTransactionsBatch(this.getId(), transactionPayloads);
|
|
502
|
-
transactions = transactionPayloads.map(tx => new Transaction(this, tx));
|
|
508
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
509
|
+
transactionPayloads = yield TransactionService.createTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
510
|
+
transactions = transactionPayloads.map((tx) => new Transaction(this, tx));
|
|
503
511
|
return transactions;
|
|
504
512
|
});
|
|
505
513
|
}
|
|
@@ -511,8 +519,8 @@ export class Book {
|
|
|
511
519
|
batchPostTransactions(transactions) {
|
|
512
520
|
return __awaiter(this, void 0, void 0, function* () {
|
|
513
521
|
let transactionPayloads = [];
|
|
514
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
515
|
-
yield TransactionService.postTransactionsBatch(this.getId(), transactionPayloads);
|
|
522
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
523
|
+
yield TransactionService.postTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
516
524
|
});
|
|
517
525
|
}
|
|
518
526
|
/**
|
|
@@ -527,9 +535,9 @@ export class Book {
|
|
|
527
535
|
batchUpdateTransactions(transactions, updateChecked) {
|
|
528
536
|
return __awaiter(this, void 0, void 0, function* () {
|
|
529
537
|
let transactionPayloads = [];
|
|
530
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
531
|
-
transactionPayloads = yield TransactionService.updateTransactionsBatch(this.getId(), transactionPayloads, updateChecked);
|
|
532
|
-
transactions = transactionPayloads.map(tx => new Transaction(this, tx));
|
|
538
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
539
|
+
transactionPayloads = yield TransactionService.updateTransactionsBatch(this.getId(), transactionPayloads, updateChecked, this.getConfig());
|
|
540
|
+
transactions = transactionPayloads.map((tx) => new Transaction(this, tx));
|
|
533
541
|
return transactions;
|
|
534
542
|
});
|
|
535
543
|
}
|
|
@@ -541,8 +549,8 @@ export class Book {
|
|
|
541
549
|
batchCheckTransactions(transactions) {
|
|
542
550
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
551
|
let transactionPayloads = [];
|
|
544
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
545
|
-
yield TransactionService.checkTransactionsBatch(this.getId(), transactionPayloads);
|
|
552
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
553
|
+
yield TransactionService.checkTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
546
554
|
});
|
|
547
555
|
}
|
|
548
556
|
/**
|
|
@@ -553,8 +561,8 @@ export class Book {
|
|
|
553
561
|
batchUncheckTransactions(transactions) {
|
|
554
562
|
return __awaiter(this, void 0, void 0, function* () {
|
|
555
563
|
let transactionPayloads = [];
|
|
556
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
557
|
-
yield TransactionService.uncheckTransactionsBatch(this.getId(), transactionPayloads);
|
|
564
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
565
|
+
yield TransactionService.uncheckTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
558
566
|
});
|
|
559
567
|
}
|
|
560
568
|
/**
|
|
@@ -566,8 +574,8 @@ export class Book {
|
|
|
566
574
|
batchTrashTransactions(transactions, trashChecked) {
|
|
567
575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
568
576
|
let transactionPayloads = [];
|
|
569
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
570
|
-
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads, trashChecked);
|
|
577
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
578
|
+
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads, trashChecked, this.getConfig());
|
|
571
579
|
});
|
|
572
580
|
}
|
|
573
581
|
/**
|
|
@@ -578,8 +586,8 @@ export class Book {
|
|
|
578
586
|
batchUntrashTransactions(transactions) {
|
|
579
587
|
return __awaiter(this, void 0, void 0, function* () {
|
|
580
588
|
let transactionPayloads = [];
|
|
581
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
582
|
-
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads);
|
|
589
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
590
|
+
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
583
591
|
});
|
|
584
592
|
}
|
|
585
593
|
/**
|
|
@@ -590,10 +598,10 @@ export class Book {
|
|
|
590
598
|
*/
|
|
591
599
|
batchReplayEvents(events, errorOnly) {
|
|
592
600
|
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
-
const eventIds = events.map(event => event.getId());
|
|
594
|
-
const eventPayloads = eventIds.map(id => ({ id: id }));
|
|
601
|
+
const eventIds = events.map((event) => event.getId());
|
|
602
|
+
const eventPayloads = eventIds.map((id) => ({ id: id }));
|
|
595
603
|
const eventList = { items: eventPayloads };
|
|
596
|
-
yield EventService.replayEventsBatch(this, eventList, errorOnly);
|
|
604
|
+
yield EventService.replayEventsBatch(this, eventList, errorOnly, this.getConfig());
|
|
597
605
|
});
|
|
598
606
|
}
|
|
599
607
|
/**
|
|
@@ -606,8 +614,10 @@ export class Book {
|
|
|
606
614
|
batchCreateAccounts(accounts) {
|
|
607
615
|
return __awaiter(this, void 0, void 0, function* () {
|
|
608
616
|
if (accounts.length > 0) {
|
|
609
|
-
const accountList = {
|
|
610
|
-
|
|
617
|
+
const accountList = {
|
|
618
|
+
items: accounts.map((a) => a.json()),
|
|
619
|
+
};
|
|
620
|
+
const payloads = yield AccountService.createAccounts(this.getId(), accountList, this.getConfig());
|
|
611
621
|
const createdAccounts = [];
|
|
612
622
|
for (const payload of payloads) {
|
|
613
623
|
const account = new Account(this, payload);
|
|
@@ -630,8 +640,8 @@ export class Book {
|
|
|
630
640
|
batchCreateGroups(groups) {
|
|
631
641
|
return __awaiter(this, void 0, void 0, function* () {
|
|
632
642
|
if (groups.length > 0) {
|
|
633
|
-
const groupList = { items: groups.map(g => g.json()) };
|
|
634
|
-
const payloads = yield GroupService.createGroups(this.getId(), groupList);
|
|
643
|
+
const groupList = { items: groups.map((g) => g.json()) };
|
|
644
|
+
const payloads = yield GroupService.createGroups(this.getId(), groupList, this.getConfig());
|
|
635
645
|
const createdGroups = [];
|
|
636
646
|
for (const payload of payloads) {
|
|
637
647
|
const group = new Group(this, payload);
|
|
@@ -648,7 +658,7 @@ export class Book {
|
|
|
648
658
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
649
659
|
*/
|
|
650
660
|
audit() {
|
|
651
|
-
BookService.audit(this.getId());
|
|
661
|
+
BookService.audit(this.getId(), this.getConfig());
|
|
652
662
|
}
|
|
653
663
|
/**
|
|
654
664
|
* Retrieve installed [[Apps]] for this Book.
|
|
@@ -660,8 +670,8 @@ export class Book {
|
|
|
660
670
|
if (this.apps != null) {
|
|
661
671
|
return this.apps;
|
|
662
672
|
}
|
|
663
|
-
const appsPlain = yield BookService.getApps(this.getId());
|
|
664
|
-
this.apps = appsPlain.map(a => new App(a));
|
|
673
|
+
const appsPlain = yield BookService.getApps(this.getId(), this.getConfig());
|
|
674
|
+
this.apps = appsPlain.map((a) => new App(a));
|
|
665
675
|
return this.apps;
|
|
666
676
|
});
|
|
667
677
|
}
|
|
@@ -672,8 +682,8 @@ export class Book {
|
|
|
672
682
|
*/
|
|
673
683
|
getIntegrations() {
|
|
674
684
|
return __awaiter(this, void 0, void 0, function* () {
|
|
675
|
-
const integrationsPlain = yield IntegrationService.listIntegrations(this.getId());
|
|
676
|
-
const integrations = integrationsPlain.map(i => new Integration(i));
|
|
685
|
+
const integrationsPlain = yield IntegrationService.listIntegrations(this.getId(), this.getConfig());
|
|
686
|
+
const integrations = integrationsPlain.map((i) => new Integration(i));
|
|
677
687
|
return integrations;
|
|
678
688
|
});
|
|
679
689
|
}
|
|
@@ -687,10 +697,10 @@ export class Book {
|
|
|
687
697
|
createIntegration(integration) {
|
|
688
698
|
return __awaiter(this, void 0, void 0, function* () {
|
|
689
699
|
if (integration instanceof Integration) {
|
|
690
|
-
integration = yield IntegrationService.createIntegration(this.getId(), integration.json());
|
|
700
|
+
integration = yield IntegrationService.createIntegration(this.getId(), integration.json(), this.getConfig());
|
|
691
701
|
}
|
|
692
702
|
else {
|
|
693
|
-
integration = yield IntegrationService.createIntegration(this.getId(), integration);
|
|
703
|
+
integration = yield IntegrationService.createIntegration(this.getId(), integration, this.getConfig());
|
|
694
704
|
}
|
|
695
705
|
return new Integration(integration);
|
|
696
706
|
});
|
|
@@ -705,10 +715,10 @@ export class Book {
|
|
|
705
715
|
updateIntegration(integration) {
|
|
706
716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
707
717
|
if (integration instanceof Integration) {
|
|
708
|
-
integration = yield IntegrationService.updateIntegration(this.getId(), integration.json());
|
|
718
|
+
integration = yield IntegrationService.updateIntegration(this.getId(), integration.json(), this.getConfig());
|
|
709
719
|
}
|
|
710
720
|
else {
|
|
711
|
-
integration = yield IntegrationService.updateIntegration(this.getId(), integration);
|
|
721
|
+
integration = yield IntegrationService.updateIntegration(this.getId(), integration, this.getConfig());
|
|
712
722
|
}
|
|
713
723
|
return new Integration(integration);
|
|
714
724
|
});
|
|
@@ -722,7 +732,7 @@ export class Book {
|
|
|
722
732
|
*/
|
|
723
733
|
getAccount(idOrName) {
|
|
724
734
|
return __awaiter(this, void 0, void 0, function* () {
|
|
725
|
-
if (!idOrName || idOrName.trim() ==
|
|
735
|
+
if (!idOrName || idOrName.trim() == "") {
|
|
726
736
|
return undefined;
|
|
727
737
|
}
|
|
728
738
|
let account;
|
|
@@ -736,7 +746,7 @@ export class Book {
|
|
|
736
746
|
}
|
|
737
747
|
// Try to fetch account from server
|
|
738
748
|
if (!account) {
|
|
739
|
-
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName);
|
|
749
|
+
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName, this.getConfig());
|
|
740
750
|
if (accountPayload) {
|
|
741
751
|
account = new Account(this, accountPayload);
|
|
742
752
|
}
|
|
@@ -799,7 +809,7 @@ export class Book {
|
|
|
799
809
|
/** @internal */
|
|
800
810
|
linkAccountsAndGroups(account) {
|
|
801
811
|
var _a;
|
|
802
|
-
const groupPayloads = account.
|
|
812
|
+
const groupPayloads = account.json().groups || [];
|
|
803
813
|
for (const groupPayload of groupPayloads) {
|
|
804
814
|
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || "");
|
|
805
815
|
if (group != null) {
|
|
@@ -836,7 +846,7 @@ export class Book {
|
|
|
836
846
|
*/
|
|
837
847
|
getGroup(idOrName) {
|
|
838
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
|
-
if (!idOrName || idOrName.trim() ==
|
|
849
|
+
if (!idOrName || idOrName.trim() == "") {
|
|
840
850
|
return undefined;
|
|
841
851
|
}
|
|
842
852
|
let group;
|
|
@@ -850,7 +860,7 @@ export class Book {
|
|
|
850
860
|
}
|
|
851
861
|
// Try to fetch group from server
|
|
852
862
|
if (!group) {
|
|
853
|
-
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName);
|
|
863
|
+
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName, this.getConfig());
|
|
854
864
|
if (groupPayload) {
|
|
855
865
|
group = new Group(this, groupPayload);
|
|
856
866
|
}
|
|
@@ -868,7 +878,7 @@ export class Book {
|
|
|
868
878
|
if (this.idGroupMap) {
|
|
869
879
|
return Array.from(this.idGroupMap.values());
|
|
870
880
|
}
|
|
871
|
-
let groups = yield GroupService.getGroups(this.getId());
|
|
881
|
+
let groups = yield GroupService.getGroups(this.getId(), this.getConfig());
|
|
872
882
|
return this.mapGroups(groups);
|
|
873
883
|
});
|
|
874
884
|
}
|
|
@@ -877,7 +887,7 @@ export class Book {
|
|
|
877
887
|
if (!groups) {
|
|
878
888
|
return [];
|
|
879
889
|
}
|
|
880
|
-
let groupsObj = groups.map(group => new Group(this, group));
|
|
890
|
+
let groupsObj = groups.map((group) => new Group(this, group));
|
|
881
891
|
this.idGroupMap = new Map();
|
|
882
892
|
this.nameGroupMap = new Map();
|
|
883
893
|
for (const group of groupsObj) {
|
|
@@ -898,7 +908,7 @@ export class Book {
|
|
|
898
908
|
if (this.idAccountMap) {
|
|
899
909
|
return Array.from(this.idAccountMap.values());
|
|
900
910
|
}
|
|
901
|
-
let accounts = yield AccountService.getAccounts(this.getId());
|
|
911
|
+
let accounts = yield AccountService.getAccounts(this.getId(), this.getConfig());
|
|
902
912
|
return this.mapAccounts(accounts);
|
|
903
913
|
});
|
|
904
914
|
}
|
|
@@ -907,7 +917,7 @@ export class Book {
|
|
|
907
917
|
if (!accounts) {
|
|
908
918
|
return [];
|
|
909
919
|
}
|
|
910
|
-
let accountsObj = accounts.map(account => new Account(this, account));
|
|
920
|
+
let accountsObj = accounts.map((account) => new Account(this, account));
|
|
911
921
|
this.idAccountMap = new Map();
|
|
912
922
|
this.nameAccountMap = new Map();
|
|
913
923
|
for (const account of accountsObj) {
|
|
@@ -949,12 +959,12 @@ export class Book {
|
|
|
949
959
|
setAccount(account, remove) {
|
|
950
960
|
const accountPayloads = this.payload.accounts || [];
|
|
951
961
|
if (remove) {
|
|
952
|
-
this.payload.accounts = accountPayloads.filter(a => a.id !== account.id);
|
|
962
|
+
this.payload.accounts = accountPayloads.filter((a) => a.id !== account.id);
|
|
953
963
|
}
|
|
954
964
|
else {
|
|
955
|
-
const existingAccount = accountPayloads.find(a => a.id === account.id);
|
|
965
|
+
const existingAccount = accountPayloads.find((a) => a.id === account.id);
|
|
956
966
|
if (existingAccount) {
|
|
957
|
-
this.payload.accounts = accountPayloads.map(a => a.id === account.id ? account : a);
|
|
967
|
+
this.payload.accounts = accountPayloads.map((a) => a.id === account.id ? account : a);
|
|
958
968
|
}
|
|
959
969
|
else {
|
|
960
970
|
this.payload.accounts = [...accountPayloads, account];
|
|
@@ -965,12 +975,12 @@ export class Book {
|
|
|
965
975
|
setGroup(group, remove) {
|
|
966
976
|
const groupPayloads = this.payload.groups || [];
|
|
967
977
|
if (remove) {
|
|
968
|
-
this.payload.groups = groupPayloads.filter(g => g.id !== group.id);
|
|
978
|
+
this.payload.groups = groupPayloads.filter((g) => g.id !== group.id);
|
|
969
979
|
}
|
|
970
980
|
else {
|
|
971
|
-
const existingGroup = groupPayloads.find(g => g.id === group.id);
|
|
981
|
+
const existingGroup = groupPayloads.find((g) => g.id === group.id);
|
|
972
982
|
if (existingGroup) {
|
|
973
|
-
this.payload.groups = groupPayloads.map(g => g.id === group.id ? group : g);
|
|
983
|
+
this.payload.groups = groupPayloads.map((g) => g.id === group.id ? group : g);
|
|
974
984
|
}
|
|
975
985
|
else {
|
|
976
986
|
this.payload.groups = [...groupPayloads, group];
|
|
@@ -988,7 +998,7 @@ export class Book {
|
|
|
988
998
|
*/
|
|
989
999
|
listTransactions(query, limit, cursor) {
|
|
990
1000
|
return __awaiter(this, void 0, void 0, function* () {
|
|
991
|
-
const transactionsList = yield TransactionService.listTransactions(this.getId(), query, limit, cursor);
|
|
1001
|
+
const transactionsList = yield TransactionService.listTransactions(this.getId(), query, limit, cursor, this.getConfig());
|
|
992
1002
|
return new TransactionList(this, transactionsList);
|
|
993
1003
|
});
|
|
994
1004
|
}
|
|
@@ -1006,7 +1016,7 @@ export class Book {
|
|
|
1006
1016
|
*/
|
|
1007
1017
|
listEvents(afterDate, beforeDate, onError, resourceId, limit, cursor) {
|
|
1008
1018
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1009
|
-
const eventsList = yield EventService.listEvents(this, afterDate, beforeDate, onError, resourceId, limit, cursor);
|
|
1019
|
+
const eventsList = yield EventService.listEvents(this, afterDate, beforeDate, onError, resourceId, limit, cursor, this.getConfig());
|
|
1010
1020
|
return new EventList(this, eventsList);
|
|
1011
1021
|
});
|
|
1012
1022
|
}
|
|
@@ -1019,7 +1029,7 @@ export class Book {
|
|
|
1019
1029
|
*/
|
|
1020
1030
|
getTransaction(id) {
|
|
1021
1031
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1022
|
-
let wrapped = yield TransactionService.getTransaction(this.getId(), id);
|
|
1032
|
+
let wrapped = yield TransactionService.getTransaction(this.getId(), id, this.getConfig());
|
|
1023
1033
|
if (!wrapped) {
|
|
1024
1034
|
return undefined;
|
|
1025
1035
|
}
|
|
@@ -1036,7 +1046,7 @@ export class Book {
|
|
|
1036
1046
|
*/
|
|
1037
1047
|
getFile(id) {
|
|
1038
1048
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1039
|
-
let wrapped = yield FileService.getFile(this.getId(), id);
|
|
1049
|
+
let wrapped = yield FileService.getFile(this.getId(), id, this.getConfig());
|
|
1040
1050
|
if (!wrapped) {
|
|
1041
1051
|
return undefined;
|
|
1042
1052
|
}
|
|
@@ -1051,7 +1061,7 @@ export class Book {
|
|
|
1051
1061
|
*/
|
|
1052
1062
|
create() {
|
|
1053
1063
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1054
|
-
this.payload = yield BookService.createBook(this.payload);
|
|
1064
|
+
this.payload = yield BookService.createBook(this.payload, this.getConfig());
|
|
1055
1065
|
return this;
|
|
1056
1066
|
});
|
|
1057
1067
|
}
|
|
@@ -1066,7 +1076,7 @@ export class Book {
|
|
|
1066
1076
|
*/
|
|
1067
1077
|
copy(name, copyTransactions, fromDate) {
|
|
1068
1078
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1069
|
-
const copiedBookPayload = yield BookService.copyBook(this.getId(), name, copyTransactions, fromDate);
|
|
1079
|
+
const copiedBookPayload = yield BookService.copyBook(this.getId(), name, copyTransactions, fromDate, this.getConfig());
|
|
1070
1080
|
return new Book(copiedBookPayload);
|
|
1071
1081
|
});
|
|
1072
1082
|
}
|
|
@@ -1077,7 +1087,7 @@ export class Book {
|
|
|
1077
1087
|
*/
|
|
1078
1088
|
update() {
|
|
1079
1089
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1080
|
-
this.payload = yield BookService.updateBook(this.getId(), this.payload);
|
|
1090
|
+
this.payload = yield BookService.updateBook(this.getId(), this.payload, this.getConfig());
|
|
1081
1091
|
return this;
|
|
1082
1092
|
});
|
|
1083
1093
|
}
|
|
@@ -1102,7 +1112,7 @@ export class Book {
|
|
|
1102
1112
|
*/
|
|
1103
1113
|
getBalancesReport(query) {
|
|
1104
1114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1105
|
-
const balances = yield BalancesService.getBalances(this.getId(), query);
|
|
1115
|
+
const balances = yield BalancesService.getBalances(this.getId(), query, this.getConfig());
|
|
1106
1116
|
return new BalancesReport(this, balances);
|
|
1107
1117
|
});
|
|
1108
1118
|
}
|
|
@@ -1114,8 +1124,8 @@ export class Book {
|
|
|
1114
1124
|
getSavedQueries() {
|
|
1115
1125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1116
1126
|
if (this.queries == null) {
|
|
1117
|
-
const queryPayloads = yield QueryService.getSavedQueries(this.getId());
|
|
1118
|
-
this.queries = queryPayloads.map(payload => new Query(this, payload));
|
|
1127
|
+
const queryPayloads = yield QueryService.getSavedQueries(this.getId(), this.getConfig());
|
|
1128
|
+
this.queries = queryPayloads.map((payload) => new Query(this, payload));
|
|
1119
1129
|
}
|
|
1120
1130
|
return this.queries;
|
|
1121
1131
|
});
|
|
@@ -1128,8 +1138,8 @@ export class Book {
|
|
|
1128
1138
|
getCollaborators() {
|
|
1129
1139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1130
1140
|
if (!this.collaborators) {
|
|
1131
|
-
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId());
|
|
1132
|
-
this.collaborators = collaboratorPayloads.map(payload => new Collaborator(this, payload));
|
|
1141
|
+
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId(), this.getConfig());
|
|
1142
|
+
this.collaborators = collaboratorPayloads.map((payload) => new Collaborator(this, payload));
|
|
1133
1143
|
}
|
|
1134
1144
|
return this.collaborators;
|
|
1135
1145
|
});
|
package/lib/model/BotResponse.js
CHANGED
|
@@ -74,7 +74,7 @@ export class BotResponse {
|
|
|
74
74
|
if (agentId == null) {
|
|
75
75
|
throw new Error("Agent id null!");
|
|
76
76
|
}
|
|
77
|
-
const updatedEventPayload = yield EventService.replayBotResponse(this.event.getBook(), eventId, agentId);
|
|
77
|
+
const updatedEventPayload = yield EventService.replayBotResponse(this.event.getBook(), eventId, agentId, this.event.getBook().getConfig());
|
|
78
78
|
this.event.payload = updatedEventPayload;
|
|
79
79
|
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
80
80
|
return this;
|
|
@@ -95,7 +95,7 @@ export class BotResponse {
|
|
|
95
95
|
if (agentId == null) {
|
|
96
96
|
throw new Error("Agent id null!");
|
|
97
97
|
}
|
|
98
|
-
const updatedEventPayload = yield EventService.deleteBotResponse(this.event.getBook(), eventId, agentId);
|
|
98
|
+
const updatedEventPayload = yield EventService.deleteBotResponse(this.event.getBook(), eventId, agentId, this.event.getBook().getConfig());
|
|
99
99
|
this.event.payload = updatedEventPayload;
|
|
100
100
|
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
101
101
|
return this;
|
|
@@ -7,7 +7,8 @@ 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 CollaboratorService from
|
|
10
|
+
import * as CollaboratorService from "../service/collaborator-service.js";
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
11
12
|
/**
|
|
12
13
|
* This class defines a Collaborator of a [[Book]].
|
|
13
14
|
*
|
|
@@ -15,18 +16,18 @@ import * as CollaboratorService from '../service/collaborator-service.js';
|
|
|
15
16
|
*
|
|
16
17
|
* @public
|
|
17
18
|
*/
|
|
18
|
-
export class Collaborator {
|
|
19
|
+
export class Collaborator extends Resource {
|
|
19
20
|
constructor(book, payload) {
|
|
21
|
+
super(payload);
|
|
20
22
|
this.book = book;
|
|
21
|
-
this.payload = payload || {};
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
|
-
* Gets
|
|
25
|
+
* Gets the configuration object for this Collaborator.
|
|
25
26
|
*
|
|
26
|
-
* @returns
|
|
27
|
+
* @returns The Config object from the parent Book
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
-
return
|
|
29
|
+
getConfig() {
|
|
30
|
+
return this.book.getConfig();
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Gets the Collaborator internal id.
|
|
@@ -81,7 +82,7 @@ export class Collaborator {
|
|
|
81
82
|
*/
|
|
82
83
|
create(message) {
|
|
83
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, message);
|
|
85
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, message, this.getConfig());
|
|
85
86
|
this.book.clearCollaboratorCache();
|
|
86
87
|
return this;
|
|
87
88
|
});
|
|
@@ -93,7 +94,7 @@ export class Collaborator {
|
|
|
93
94
|
*/
|
|
94
95
|
update() {
|
|
95
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload);
|
|
97
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, undefined, this.getConfig());
|
|
97
98
|
this.book.clearCollaboratorCache();
|
|
98
99
|
return this;
|
|
99
100
|
});
|
|
@@ -107,9 +108,9 @@ export class Collaborator {
|
|
|
107
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
109
|
const email = this.getEmail();
|
|
109
110
|
if (!email) {
|
|
110
|
-
throw new Error(
|
|
111
|
+
throw new Error("Collaborator email is required");
|
|
111
112
|
}
|
|
112
|
-
this.payload = yield CollaboratorService.removeCollaborator(this.book.getId(), email);
|
|
113
|
+
this.payload = yield CollaboratorService.removeCollaborator(this.book.getId(), email, this.getConfig());
|
|
113
114
|
this.book.clearCollaboratorCache();
|
|
114
115
|
return this;
|
|
115
116
|
});
|