bkper-js 2.7.1 → 2.8.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/CHANGELOG.md +15 -0
- package/lib/index.d.ts +142 -144
- package/lib/model/Account.js +18 -24
- package/lib/model/App.js +70 -24
- package/lib/model/Bkper.js +42 -30
- package/lib/model/Book.js +107 -102
- package/lib/model/BotResponse.js +2 -2
- package/lib/model/Collaborator.js +10 -14
- package/lib/model/Collection.js +22 -22
- package/lib/model/Connection.js +26 -21
- package/lib/model/Conversation.js +18 -16
- package/lib/model/File.js +17 -20
- package/lib/model/Group.js +27 -24
- package/lib/model/Integration.js +15 -16
- package/lib/model/Message.js +18 -19
- package/lib/model/Query.js +10 -14
- package/lib/model/Resource.js +23 -0
- package/lib/model/Template.js +8 -10
- package/lib/model/Transaction.js +59 -46
- package/lib/model/User.js +12 -15
- 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 || [];
|
|
@@ -48,13 +51,8 @@ export class Book {
|
|
|
48
51
|
this.mapGroups(this.payload.groups);
|
|
49
52
|
this.mapAccounts(this.payload.accounts);
|
|
50
53
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
* @returns An immutable copy of the JSON payload
|
|
55
|
-
*/
|
|
56
|
-
json() {
|
|
57
|
-
return Object.assign({}, this.payload);
|
|
54
|
+
getConfig() {
|
|
55
|
+
return this.config || Bkper.globalConfig;
|
|
58
56
|
}
|
|
59
57
|
/**
|
|
60
58
|
* Gets the unique identifier of this Book.
|
|
@@ -62,7 +60,7 @@ export class Book {
|
|
|
62
60
|
* @returns This Book's unique identifier
|
|
63
61
|
*/
|
|
64
62
|
getId() {
|
|
65
|
-
return this.payload.id ||
|
|
63
|
+
return this.payload.id || "";
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* Gets the name of this Book.
|
|
@@ -336,7 +334,7 @@ export class Book {
|
|
|
336
334
|
* @returns The total number of posted transactions
|
|
337
335
|
*/
|
|
338
336
|
getTotalTransactions() {
|
|
339
|
-
return this.payload.totalTransactions ? +
|
|
337
|
+
return this.payload.totalTransactions ? +this.payload.totalTransactions : 0;
|
|
340
338
|
}
|
|
341
339
|
/**
|
|
342
340
|
* Gets the total number of posted transactions on current month.
|
|
@@ -344,7 +342,9 @@ export class Book {
|
|
|
344
342
|
* @returns The total number of posted transactions on current month
|
|
345
343
|
*/
|
|
346
344
|
getTotalTransactionsCurrentMonth() {
|
|
347
|
-
return this.payload.totalTransactionsCurrentMonth
|
|
345
|
+
return this.payload.totalTransactionsCurrentMonth
|
|
346
|
+
? +this.payload.totalTransactionsCurrentMonth
|
|
347
|
+
: 0;
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
350
|
* Gets the total number of posted transactions on current year.
|
|
@@ -352,7 +352,9 @@ export class Book {
|
|
|
352
352
|
* @returns The total number of posted transactions on current year
|
|
353
353
|
*/
|
|
354
354
|
getTotalTransactionsCurrentYear() {
|
|
355
|
-
return this.payload.totalTransactionsCurrentYear
|
|
355
|
+
return this.payload.totalTransactionsCurrentYear
|
|
356
|
+
? +this.payload.totalTransactionsCurrentYear
|
|
357
|
+
: 0;
|
|
356
358
|
}
|
|
357
359
|
/**
|
|
358
360
|
* Gets the visibility of the book.
|
|
@@ -379,7 +381,8 @@ export class Book {
|
|
|
379
381
|
* @returns The custom properties object
|
|
380
382
|
*/
|
|
381
383
|
getProperties() {
|
|
382
|
-
return this.payload.properties != null
|
|
384
|
+
return this.payload.properties != null
|
|
385
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
383
386
|
}
|
|
384
387
|
/**
|
|
385
388
|
* Gets the property value for given keys. First property found will be retrieved.
|
|
@@ -392,7 +395,7 @@ export class Book {
|
|
|
392
395
|
for (let index = 0; index < keys.length; index++) {
|
|
393
396
|
const key = keys[index];
|
|
394
397
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
395
|
-
if (value != null && value.trim() !=
|
|
398
|
+
if (value != null && value.trim() != "") {
|
|
396
399
|
return value;
|
|
397
400
|
}
|
|
398
401
|
}
|
|
@@ -418,14 +421,14 @@ export class Book {
|
|
|
418
421
|
* @returns This Book, for chaining
|
|
419
422
|
*/
|
|
420
423
|
setProperty(key, value) {
|
|
421
|
-
if (key == null || key.trim() ==
|
|
424
|
+
if (key == null || key.trim() == "") {
|
|
422
425
|
return this;
|
|
423
426
|
}
|
|
424
427
|
if (this.payload.properties == null) {
|
|
425
428
|
this.payload.properties = {};
|
|
426
429
|
}
|
|
427
430
|
if (!value) {
|
|
428
|
-
value =
|
|
431
|
+
value = "";
|
|
429
432
|
}
|
|
430
433
|
this.payload.properties[key] = value;
|
|
431
434
|
return this;
|
|
@@ -463,7 +466,7 @@ export class Book {
|
|
|
463
466
|
*/
|
|
464
467
|
formatValue(value) {
|
|
465
468
|
if (!value) {
|
|
466
|
-
return
|
|
469
|
+
return "";
|
|
467
470
|
}
|
|
468
471
|
return Utils.formatValue(value, this.getDecimalSeparator(), this.getFractionDigits());
|
|
469
472
|
}
|
|
@@ -497,9 +500,9 @@ export class Book {
|
|
|
497
500
|
batchCreateTransactions(transactions) {
|
|
498
501
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
502
|
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));
|
|
503
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
504
|
+
transactionPayloads = yield TransactionService.createTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
505
|
+
transactions = transactionPayloads.map((tx) => new Transaction(this, tx));
|
|
503
506
|
return transactions;
|
|
504
507
|
});
|
|
505
508
|
}
|
|
@@ -511,8 +514,8 @@ export class Book {
|
|
|
511
514
|
batchPostTransactions(transactions) {
|
|
512
515
|
return __awaiter(this, void 0, void 0, function* () {
|
|
513
516
|
let transactionPayloads = [];
|
|
514
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
515
|
-
yield TransactionService.postTransactionsBatch(this.getId(), transactionPayloads);
|
|
517
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
518
|
+
yield TransactionService.postTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
516
519
|
});
|
|
517
520
|
}
|
|
518
521
|
/**
|
|
@@ -527,9 +530,9 @@ export class Book {
|
|
|
527
530
|
batchUpdateTransactions(transactions, updateChecked) {
|
|
528
531
|
return __awaiter(this, void 0, void 0, function* () {
|
|
529
532
|
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));
|
|
533
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
534
|
+
transactionPayloads = yield TransactionService.updateTransactionsBatch(this.getId(), transactionPayloads, updateChecked, this.getConfig());
|
|
535
|
+
transactions = transactionPayloads.map((tx) => new Transaction(this, tx));
|
|
533
536
|
return transactions;
|
|
534
537
|
});
|
|
535
538
|
}
|
|
@@ -541,8 +544,8 @@ export class Book {
|
|
|
541
544
|
batchCheckTransactions(transactions) {
|
|
542
545
|
return __awaiter(this, void 0, void 0, function* () {
|
|
543
546
|
let transactionPayloads = [];
|
|
544
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
545
|
-
yield TransactionService.checkTransactionsBatch(this.getId(), transactionPayloads);
|
|
547
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
548
|
+
yield TransactionService.checkTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
546
549
|
});
|
|
547
550
|
}
|
|
548
551
|
/**
|
|
@@ -553,8 +556,8 @@ export class Book {
|
|
|
553
556
|
batchUncheckTransactions(transactions) {
|
|
554
557
|
return __awaiter(this, void 0, void 0, function* () {
|
|
555
558
|
let transactionPayloads = [];
|
|
556
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
557
|
-
yield TransactionService.uncheckTransactionsBatch(this.getId(), transactionPayloads);
|
|
559
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
560
|
+
yield TransactionService.uncheckTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
558
561
|
});
|
|
559
562
|
}
|
|
560
563
|
/**
|
|
@@ -566,8 +569,8 @@ export class Book {
|
|
|
566
569
|
batchTrashTransactions(transactions, trashChecked) {
|
|
567
570
|
return __awaiter(this, void 0, void 0, function* () {
|
|
568
571
|
let transactionPayloads = [];
|
|
569
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
570
|
-
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads, trashChecked);
|
|
572
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
573
|
+
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads, trashChecked, this.getConfig());
|
|
571
574
|
});
|
|
572
575
|
}
|
|
573
576
|
/**
|
|
@@ -578,8 +581,8 @@ export class Book {
|
|
|
578
581
|
batchUntrashTransactions(transactions) {
|
|
579
582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
580
583
|
let transactionPayloads = [];
|
|
581
|
-
transactions.forEach(tx => transactionPayloads.push(tx.json()));
|
|
582
|
-
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads);
|
|
584
|
+
transactions.forEach((tx) => transactionPayloads.push(tx.json()));
|
|
585
|
+
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
583
586
|
});
|
|
584
587
|
}
|
|
585
588
|
/**
|
|
@@ -590,10 +593,10 @@ export class Book {
|
|
|
590
593
|
*/
|
|
591
594
|
batchReplayEvents(events, errorOnly) {
|
|
592
595
|
return __awaiter(this, void 0, void 0, function* () {
|
|
593
|
-
const eventIds = events.map(event => event.getId());
|
|
594
|
-
const eventPayloads = eventIds.map(id => ({ id: id }));
|
|
596
|
+
const eventIds = events.map((event) => event.getId());
|
|
597
|
+
const eventPayloads = eventIds.map((id) => ({ id: id }));
|
|
595
598
|
const eventList = { items: eventPayloads };
|
|
596
|
-
yield EventService.replayEventsBatch(this, eventList, errorOnly);
|
|
599
|
+
yield EventService.replayEventsBatch(this, eventList, errorOnly, this.getConfig());
|
|
597
600
|
});
|
|
598
601
|
}
|
|
599
602
|
/**
|
|
@@ -606,8 +609,10 @@ export class Book {
|
|
|
606
609
|
batchCreateAccounts(accounts) {
|
|
607
610
|
return __awaiter(this, void 0, void 0, function* () {
|
|
608
611
|
if (accounts.length > 0) {
|
|
609
|
-
const accountList = {
|
|
610
|
-
|
|
612
|
+
const accountList = {
|
|
613
|
+
items: accounts.map((a) => a.json()),
|
|
614
|
+
};
|
|
615
|
+
const payloads = yield AccountService.createAccounts(this.getId(), accountList, this.getConfig());
|
|
611
616
|
const createdAccounts = [];
|
|
612
617
|
for (const payload of payloads) {
|
|
613
618
|
const account = new Account(this, payload);
|
|
@@ -630,8 +635,8 @@ export class Book {
|
|
|
630
635
|
batchCreateGroups(groups) {
|
|
631
636
|
return __awaiter(this, void 0, void 0, function* () {
|
|
632
637
|
if (groups.length > 0) {
|
|
633
|
-
const groupList = { items: groups.map(g => g.json()) };
|
|
634
|
-
const payloads = yield GroupService.createGroups(this.getId(), groupList);
|
|
638
|
+
const groupList = { items: groups.map((g) => g.json()) };
|
|
639
|
+
const payloads = yield GroupService.createGroups(this.getId(), groupList, this.getConfig());
|
|
635
640
|
const createdGroups = [];
|
|
636
641
|
for (const payload of payloads) {
|
|
637
642
|
const group = new Group(this, payload);
|
|
@@ -648,7 +653,7 @@ export class Book {
|
|
|
648
653
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
649
654
|
*/
|
|
650
655
|
audit() {
|
|
651
|
-
BookService.audit(this.getId());
|
|
656
|
+
BookService.audit(this.getId(), this.getConfig());
|
|
652
657
|
}
|
|
653
658
|
/**
|
|
654
659
|
* Retrieve installed [[Apps]] for this Book.
|
|
@@ -660,8 +665,8 @@ export class Book {
|
|
|
660
665
|
if (this.apps != null) {
|
|
661
666
|
return this.apps;
|
|
662
667
|
}
|
|
663
|
-
const appsPlain = yield BookService.getApps(this.getId());
|
|
664
|
-
this.apps = appsPlain.map(a => new App(a));
|
|
668
|
+
const appsPlain = yield BookService.getApps(this.getId(), this.getConfig());
|
|
669
|
+
this.apps = appsPlain.map((a) => new App(a));
|
|
665
670
|
return this.apps;
|
|
666
671
|
});
|
|
667
672
|
}
|
|
@@ -672,8 +677,8 @@ export class Book {
|
|
|
672
677
|
*/
|
|
673
678
|
getIntegrations() {
|
|
674
679
|
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));
|
|
680
|
+
const integrationsPlain = yield IntegrationService.listIntegrations(this.getId(), this.getConfig());
|
|
681
|
+
const integrations = integrationsPlain.map((i) => new Integration(i));
|
|
677
682
|
return integrations;
|
|
678
683
|
});
|
|
679
684
|
}
|
|
@@ -687,10 +692,10 @@ export class Book {
|
|
|
687
692
|
createIntegration(integration) {
|
|
688
693
|
return __awaiter(this, void 0, void 0, function* () {
|
|
689
694
|
if (integration instanceof Integration) {
|
|
690
|
-
integration = yield IntegrationService.createIntegration(this.getId(), integration.json());
|
|
695
|
+
integration = yield IntegrationService.createIntegration(this.getId(), integration.json(), this.getConfig());
|
|
691
696
|
}
|
|
692
697
|
else {
|
|
693
|
-
integration = yield IntegrationService.createIntegration(this.getId(), integration);
|
|
698
|
+
integration = yield IntegrationService.createIntegration(this.getId(), integration, this.getConfig());
|
|
694
699
|
}
|
|
695
700
|
return new Integration(integration);
|
|
696
701
|
});
|
|
@@ -705,10 +710,10 @@ export class Book {
|
|
|
705
710
|
updateIntegration(integration) {
|
|
706
711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
707
712
|
if (integration instanceof Integration) {
|
|
708
|
-
integration = yield IntegrationService.updateIntegration(this.getId(), integration.json());
|
|
713
|
+
integration = yield IntegrationService.updateIntegration(this.getId(), integration.json(), this.getConfig());
|
|
709
714
|
}
|
|
710
715
|
else {
|
|
711
|
-
integration = yield IntegrationService.updateIntegration(this.getId(), integration);
|
|
716
|
+
integration = yield IntegrationService.updateIntegration(this.getId(), integration, this.getConfig());
|
|
712
717
|
}
|
|
713
718
|
return new Integration(integration);
|
|
714
719
|
});
|
|
@@ -722,7 +727,7 @@ export class Book {
|
|
|
722
727
|
*/
|
|
723
728
|
getAccount(idOrName) {
|
|
724
729
|
return __awaiter(this, void 0, void 0, function* () {
|
|
725
|
-
if (!idOrName || idOrName.trim() ==
|
|
730
|
+
if (!idOrName || idOrName.trim() == "") {
|
|
726
731
|
return undefined;
|
|
727
732
|
}
|
|
728
733
|
let account;
|
|
@@ -736,7 +741,7 @@ export class Book {
|
|
|
736
741
|
}
|
|
737
742
|
// Try to fetch account from server
|
|
738
743
|
if (!account) {
|
|
739
|
-
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName);
|
|
744
|
+
const accountPayload = yield AccountService.getAccount(this.getId(), idOrName, this.getConfig());
|
|
740
745
|
if (accountPayload) {
|
|
741
746
|
account = new Account(this, accountPayload);
|
|
742
747
|
}
|
|
@@ -799,7 +804,7 @@ export class Book {
|
|
|
799
804
|
/** @internal */
|
|
800
805
|
linkAccountsAndGroups(account) {
|
|
801
806
|
var _a;
|
|
802
|
-
const groupPayloads = account.
|
|
807
|
+
const groupPayloads = account.json().groups || [];
|
|
803
808
|
for (const groupPayload of groupPayloads) {
|
|
804
809
|
const group = (_a = this.idGroupMap) === null || _a === void 0 ? void 0 : _a.get(groupPayload.id || "");
|
|
805
810
|
if (group != null) {
|
|
@@ -836,7 +841,7 @@ export class Book {
|
|
|
836
841
|
*/
|
|
837
842
|
getGroup(idOrName) {
|
|
838
843
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
|
-
if (!idOrName || idOrName.trim() ==
|
|
844
|
+
if (!idOrName || idOrName.trim() == "") {
|
|
840
845
|
return undefined;
|
|
841
846
|
}
|
|
842
847
|
let group;
|
|
@@ -850,7 +855,7 @@ export class Book {
|
|
|
850
855
|
}
|
|
851
856
|
// Try to fetch group from server
|
|
852
857
|
if (!group) {
|
|
853
|
-
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName);
|
|
858
|
+
const groupPayload = yield GroupService.getGroup(this.getId(), idOrName, this.getConfig());
|
|
854
859
|
if (groupPayload) {
|
|
855
860
|
group = new Group(this, groupPayload);
|
|
856
861
|
}
|
|
@@ -868,7 +873,7 @@ export class Book {
|
|
|
868
873
|
if (this.idGroupMap) {
|
|
869
874
|
return Array.from(this.idGroupMap.values());
|
|
870
875
|
}
|
|
871
|
-
let groups = yield GroupService.getGroups(this.getId());
|
|
876
|
+
let groups = yield GroupService.getGroups(this.getId(), this.getConfig());
|
|
872
877
|
return this.mapGroups(groups);
|
|
873
878
|
});
|
|
874
879
|
}
|
|
@@ -877,7 +882,7 @@ export class Book {
|
|
|
877
882
|
if (!groups) {
|
|
878
883
|
return [];
|
|
879
884
|
}
|
|
880
|
-
let groupsObj = groups.map(group => new Group(this, group));
|
|
885
|
+
let groupsObj = groups.map((group) => new Group(this, group));
|
|
881
886
|
this.idGroupMap = new Map();
|
|
882
887
|
this.nameGroupMap = new Map();
|
|
883
888
|
for (const group of groupsObj) {
|
|
@@ -898,7 +903,7 @@ export class Book {
|
|
|
898
903
|
if (this.idAccountMap) {
|
|
899
904
|
return Array.from(this.idAccountMap.values());
|
|
900
905
|
}
|
|
901
|
-
let accounts = yield AccountService.getAccounts(this.getId());
|
|
906
|
+
let accounts = yield AccountService.getAccounts(this.getId(), this.getConfig());
|
|
902
907
|
return this.mapAccounts(accounts);
|
|
903
908
|
});
|
|
904
909
|
}
|
|
@@ -907,7 +912,7 @@ export class Book {
|
|
|
907
912
|
if (!accounts) {
|
|
908
913
|
return [];
|
|
909
914
|
}
|
|
910
|
-
let accountsObj = accounts.map(account => new Account(this, account));
|
|
915
|
+
let accountsObj = accounts.map((account) => new Account(this, account));
|
|
911
916
|
this.idAccountMap = new Map();
|
|
912
917
|
this.nameAccountMap = new Map();
|
|
913
918
|
for (const account of accountsObj) {
|
|
@@ -949,12 +954,12 @@ export class Book {
|
|
|
949
954
|
setAccount(account, remove) {
|
|
950
955
|
const accountPayloads = this.payload.accounts || [];
|
|
951
956
|
if (remove) {
|
|
952
|
-
this.payload.accounts = accountPayloads.filter(a => a.id !== account.id);
|
|
957
|
+
this.payload.accounts = accountPayloads.filter((a) => a.id !== account.id);
|
|
953
958
|
}
|
|
954
959
|
else {
|
|
955
|
-
const existingAccount = accountPayloads.find(a => a.id === account.id);
|
|
960
|
+
const existingAccount = accountPayloads.find((a) => a.id === account.id);
|
|
956
961
|
if (existingAccount) {
|
|
957
|
-
this.payload.accounts = accountPayloads.map(a => a.id === account.id ? account : a);
|
|
962
|
+
this.payload.accounts = accountPayloads.map((a) => a.id === account.id ? account : a);
|
|
958
963
|
}
|
|
959
964
|
else {
|
|
960
965
|
this.payload.accounts = [...accountPayloads, account];
|
|
@@ -965,12 +970,12 @@ export class Book {
|
|
|
965
970
|
setGroup(group, remove) {
|
|
966
971
|
const groupPayloads = this.payload.groups || [];
|
|
967
972
|
if (remove) {
|
|
968
|
-
this.payload.groups = groupPayloads.filter(g => g.id !== group.id);
|
|
973
|
+
this.payload.groups = groupPayloads.filter((g) => g.id !== group.id);
|
|
969
974
|
}
|
|
970
975
|
else {
|
|
971
|
-
const existingGroup = groupPayloads.find(g => g.id === group.id);
|
|
976
|
+
const existingGroup = groupPayloads.find((g) => g.id === group.id);
|
|
972
977
|
if (existingGroup) {
|
|
973
|
-
this.payload.groups = groupPayloads.map(g => g.id === group.id ? group : g);
|
|
978
|
+
this.payload.groups = groupPayloads.map((g) => g.id === group.id ? group : g);
|
|
974
979
|
}
|
|
975
980
|
else {
|
|
976
981
|
this.payload.groups = [...groupPayloads, group];
|
|
@@ -988,7 +993,7 @@ export class Book {
|
|
|
988
993
|
*/
|
|
989
994
|
listTransactions(query, limit, cursor) {
|
|
990
995
|
return __awaiter(this, void 0, void 0, function* () {
|
|
991
|
-
const transactionsList = yield TransactionService.listTransactions(this.getId(), query, limit, cursor);
|
|
996
|
+
const transactionsList = yield TransactionService.listTransactions(this.getId(), query, limit, cursor, this.getConfig());
|
|
992
997
|
return new TransactionList(this, transactionsList);
|
|
993
998
|
});
|
|
994
999
|
}
|
|
@@ -1006,7 +1011,7 @@ export class Book {
|
|
|
1006
1011
|
*/
|
|
1007
1012
|
listEvents(afterDate, beforeDate, onError, resourceId, limit, cursor) {
|
|
1008
1013
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1009
|
-
const eventsList = yield EventService.listEvents(this, afterDate, beforeDate, onError, resourceId, limit, cursor);
|
|
1014
|
+
const eventsList = yield EventService.listEvents(this, afterDate, beforeDate, onError, resourceId, limit, cursor, this.getConfig());
|
|
1010
1015
|
return new EventList(this, eventsList);
|
|
1011
1016
|
});
|
|
1012
1017
|
}
|
|
@@ -1019,7 +1024,7 @@ export class Book {
|
|
|
1019
1024
|
*/
|
|
1020
1025
|
getTransaction(id) {
|
|
1021
1026
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1022
|
-
let wrapped = yield TransactionService.getTransaction(this.getId(), id);
|
|
1027
|
+
let wrapped = yield TransactionService.getTransaction(this.getId(), id, this.getConfig());
|
|
1023
1028
|
if (!wrapped) {
|
|
1024
1029
|
return undefined;
|
|
1025
1030
|
}
|
|
@@ -1036,7 +1041,7 @@ export class Book {
|
|
|
1036
1041
|
*/
|
|
1037
1042
|
getFile(id) {
|
|
1038
1043
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1039
|
-
let wrapped = yield FileService.getFile(this.getId(), id);
|
|
1044
|
+
let wrapped = yield FileService.getFile(this.getId(), id, this.getConfig());
|
|
1040
1045
|
if (!wrapped) {
|
|
1041
1046
|
return undefined;
|
|
1042
1047
|
}
|
|
@@ -1051,7 +1056,7 @@ export class Book {
|
|
|
1051
1056
|
*/
|
|
1052
1057
|
create() {
|
|
1053
1058
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1054
|
-
this.payload = yield BookService.createBook(this.payload);
|
|
1059
|
+
this.payload = yield BookService.createBook(this.payload, this.getConfig());
|
|
1055
1060
|
return this;
|
|
1056
1061
|
});
|
|
1057
1062
|
}
|
|
@@ -1066,7 +1071,7 @@ export class Book {
|
|
|
1066
1071
|
*/
|
|
1067
1072
|
copy(name, copyTransactions, fromDate) {
|
|
1068
1073
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1069
|
-
const copiedBookPayload = yield BookService.copyBook(this.getId(), name, copyTransactions, fromDate);
|
|
1074
|
+
const copiedBookPayload = yield BookService.copyBook(this.getId(), name, copyTransactions, fromDate, this.getConfig());
|
|
1070
1075
|
return new Book(copiedBookPayload);
|
|
1071
1076
|
});
|
|
1072
1077
|
}
|
|
@@ -1077,7 +1082,7 @@ export class Book {
|
|
|
1077
1082
|
*/
|
|
1078
1083
|
update() {
|
|
1079
1084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1080
|
-
this.payload = yield BookService.updateBook(this.getId(), this.payload);
|
|
1085
|
+
this.payload = yield BookService.updateBook(this.getId(), this.payload, this.getConfig());
|
|
1081
1086
|
return this;
|
|
1082
1087
|
});
|
|
1083
1088
|
}
|
|
@@ -1102,7 +1107,7 @@ export class Book {
|
|
|
1102
1107
|
*/
|
|
1103
1108
|
getBalancesReport(query) {
|
|
1104
1109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1105
|
-
const balances = yield BalancesService.getBalances(this.getId(), query);
|
|
1110
|
+
const balances = yield BalancesService.getBalances(this.getId(), query, this.getConfig());
|
|
1106
1111
|
return new BalancesReport(this, balances);
|
|
1107
1112
|
});
|
|
1108
1113
|
}
|
|
@@ -1114,8 +1119,8 @@ export class Book {
|
|
|
1114
1119
|
getSavedQueries() {
|
|
1115
1120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1116
1121
|
if (this.queries == null) {
|
|
1117
|
-
const queryPayloads = yield QueryService.getSavedQueries(this.getId());
|
|
1118
|
-
this.queries = queryPayloads.map(payload => new Query(this, payload));
|
|
1122
|
+
const queryPayloads = yield QueryService.getSavedQueries(this.getId(), this.getConfig());
|
|
1123
|
+
this.queries = queryPayloads.map((payload) => new Query(this, payload));
|
|
1119
1124
|
}
|
|
1120
1125
|
return this.queries;
|
|
1121
1126
|
});
|
|
@@ -1128,8 +1133,8 @@ export class Book {
|
|
|
1128
1133
|
getCollaborators() {
|
|
1129
1134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1130
1135
|
if (!this.collaborators) {
|
|
1131
|
-
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId());
|
|
1132
|
-
this.collaborators = collaboratorPayloads.map(payload => new Collaborator(this, payload));
|
|
1136
|
+
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId(), this.getConfig());
|
|
1137
|
+
this.collaborators = collaboratorPayloads.map((payload) => new Collaborator(this, payload));
|
|
1133
1138
|
}
|
|
1134
1139
|
return this.collaborators;
|
|
1135
1140
|
});
|
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,13 @@ 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
|
-
|
|
25
|
-
*
|
|
26
|
-
* @returns An immutable copy of the json payload
|
|
27
|
-
*/
|
|
28
|
-
json() {
|
|
29
|
-
return Object.assign({}, this.payload);
|
|
24
|
+
getConfig() {
|
|
25
|
+
return this.book.getConfig();
|
|
30
26
|
}
|
|
31
27
|
/**
|
|
32
28
|
* Gets the Collaborator internal id.
|
|
@@ -81,7 +77,7 @@ export class Collaborator {
|
|
|
81
77
|
*/
|
|
82
78
|
create(message) {
|
|
83
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, message);
|
|
80
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, message, this.getConfig());
|
|
85
81
|
this.book.clearCollaboratorCache();
|
|
86
82
|
return this;
|
|
87
83
|
});
|
|
@@ -93,7 +89,7 @@ export class Collaborator {
|
|
|
93
89
|
*/
|
|
94
90
|
update() {
|
|
95
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload);
|
|
92
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, undefined, this.getConfig());
|
|
97
93
|
this.book.clearCollaboratorCache();
|
|
98
94
|
return this;
|
|
99
95
|
});
|
|
@@ -107,9 +103,9 @@ export class Collaborator {
|
|
|
107
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
104
|
const email = this.getEmail();
|
|
109
105
|
if (!email) {
|
|
110
|
-
throw new Error(
|
|
106
|
+
throw new Error("Collaborator email is required");
|
|
111
107
|
}
|
|
112
|
-
this.payload = yield CollaboratorService.removeCollaborator(this.book.getId(), email);
|
|
108
|
+
this.payload = yield CollaboratorService.removeCollaborator(this.book.getId(), email, this.getConfig());
|
|
113
109
|
this.book.clearCollaboratorCache();
|
|
114
110
|
return this;
|
|
115
111
|
});
|