bkper-js 1.6.0 → 1.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/lib/index.d.ts +117 -82
- package/lib/index.js +7 -6
- package/lib/model/Bkper.js +16 -2
- package/lib/model/Book.js +73 -67
- package/lib/model/Template.js +85 -0
- package/lib/model/Transaction.js +6 -0
- package/lib/model/TransactionList.js +67 -0
- package/lib/service/account-service.js +6 -0
- package/lib/service/book-service.js +3 -2
- package/lib/service/template-service.js +25 -0
- package/lib/service/transaction-service.js +1 -1
- package/package.json +1 -1
- package/lib/model/TransactionIterator.js +0 -150
- package/lib/model/TransactionPage.js +0 -71
package/lib/index.d.ts
CHANGED
|
@@ -408,10 +408,11 @@ export declare class Bkper {
|
|
|
408
408
|
* Gets the [[Book]] with the specified bookId from url param.
|
|
409
409
|
*
|
|
410
410
|
* @param id - The universal book id - The same bookId param of URL you access at app.bkper.com
|
|
411
|
+
* @param includeAccounts - Optional parameter to include accounts in the retrieved Book
|
|
411
412
|
*
|
|
412
413
|
* @returns The retrieved Book, for chaining
|
|
413
414
|
*/
|
|
414
|
-
static getBook(id: string): Promise<Book>;
|
|
415
|
+
static getBook(id: string, includeAccounts?: boolean): Promise<Book>;
|
|
415
416
|
/**
|
|
416
417
|
* Gets all [[Books]] the user has access to.
|
|
417
418
|
*
|
|
@@ -424,6 +425,12 @@ export declare class Bkper {
|
|
|
424
425
|
* @returns The retrieved list of Apps
|
|
425
426
|
*/
|
|
426
427
|
static getApps(): Promise<App[]>;
|
|
428
|
+
/**
|
|
429
|
+
* Gets all [[Templates]] available for the user.
|
|
430
|
+
*
|
|
431
|
+
* @returns The retrieved list of Templates
|
|
432
|
+
*/
|
|
433
|
+
static getTemplates(): Promise<Template[]>;
|
|
427
434
|
/**
|
|
428
435
|
* Gets the current logged [[User]].
|
|
429
436
|
*
|
|
@@ -723,21 +730,13 @@ export declare class Book {
|
|
|
723
730
|
* @returns The updated Integration object
|
|
724
731
|
*/
|
|
725
732
|
updateIntegration(integration: bkper.Integration): Promise<Integration>;
|
|
726
|
-
/**
|
|
727
|
-
* Resumes a transaction iteration using a continuation token from a previous iterator.
|
|
728
|
-
*
|
|
729
|
-
* @param continuationToken - continuation token from a previous transaction iterator
|
|
730
|
-
*
|
|
731
|
-
* @returns a collection of transactions that remained in a previous iterator when the continuation token was generated
|
|
732
|
-
*/
|
|
733
|
-
continueTransactionIterator(query: string, continuationToken: string): TransactionIterator;
|
|
734
733
|
/**
|
|
735
734
|
* Instantiate a new [[Transaction]]
|
|
736
735
|
*
|
|
737
736
|
* Example:
|
|
738
737
|
*
|
|
739
738
|
* ```js
|
|
740
|
-
* var book =
|
|
739
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
741
740
|
*
|
|
742
741
|
* book.newTransaction()
|
|
743
742
|
* .setDate('2013-01-25')
|
|
@@ -756,7 +755,7 @@ export declare class Book {
|
|
|
756
755
|
*
|
|
757
756
|
* Example:
|
|
758
757
|
* ```js
|
|
759
|
-
* var book =
|
|
758
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
760
759
|
*
|
|
761
760
|
* book.newAccount()
|
|
762
761
|
* .setName('Some New Account')
|
|
@@ -772,7 +771,7 @@ export declare class Book {
|
|
|
772
771
|
*
|
|
773
772
|
* Example:
|
|
774
773
|
* ```js
|
|
775
|
-
* var book =
|
|
774
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
776
775
|
*
|
|
777
776
|
* book.newGroup()
|
|
778
777
|
* .setName('Some New Group')
|
|
@@ -790,7 +789,9 @@ export declare class Book {
|
|
|
790
789
|
*/
|
|
791
790
|
getAccount(idOrName?: string): Promise<Account | undefined>;
|
|
792
791
|
|
|
793
|
-
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
794
795
|
/**
|
|
795
796
|
* Gets a [[Group]] object
|
|
796
797
|
*
|
|
@@ -803,33 +804,19 @@ export declare class Book {
|
|
|
803
804
|
* Gets all [[Groups]] of this Book
|
|
804
805
|
*/
|
|
805
806
|
getGroups(): Promise<Group[]>;
|
|
807
|
+
private mapGroups;
|
|
808
|
+
getAccounts(): Promise<Account[]>;
|
|
809
|
+
private mapAccounts;
|
|
806
810
|
/**
|
|
807
|
-
*
|
|
808
|
-
*/
|
|
809
|
-
getGroupsByAccount(accountIdOrName: string): Promise<Group[]>;
|
|
810
|
-
/**
|
|
811
|
-
* Get Book transactions based on a query.
|
|
812
|
-
*
|
|
813
|
-
* See [Query Guide](https://help.bkper.com/en/articles/2569178-search-query-guide) to learn more
|
|
811
|
+
* Lists transactions in the Book based on the provided query, limit, and cursor, for pagination.
|
|
814
812
|
*
|
|
815
|
-
* @param query - The query string
|
|
816
|
-
*
|
|
817
|
-
* @
|
|
818
|
-
*
|
|
819
|
-
* Example:
|
|
813
|
+
* @param query - The query string to filter transactions
|
|
814
|
+
* @param limit - The maximum number of transactions to return. Default to 100, max to 1000;
|
|
815
|
+
* @param cursor - The cursor for pagination
|
|
820
816
|
*
|
|
821
|
-
*
|
|
822
|
-
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
823
|
-
*
|
|
824
|
-
* var transactions = book.getTransactions("account:CreditCard after:28/01/2013 before:29/01/2013");
|
|
825
|
-
*
|
|
826
|
-
* while (transactions.hasNext()) {
|
|
827
|
-
* var transaction = transactions.next();
|
|
828
|
-
* Logger.log(transaction.getDescription());
|
|
829
|
-
* }
|
|
830
|
-
* ```
|
|
817
|
+
* @returns A TransactionPage object containing the list of transactions
|
|
831
818
|
*/
|
|
832
|
-
|
|
819
|
+
listTransactions(query?: string, limit?: number, cursor?: string): Promise<TransactionPage>;
|
|
833
820
|
/**
|
|
834
821
|
* Retrieve a transaction by id
|
|
835
822
|
*/
|
|
@@ -839,7 +826,7 @@ export declare class Book {
|
|
|
839
826
|
*
|
|
840
827
|
* Example:
|
|
841
828
|
* ```js
|
|
842
|
-
* var book =
|
|
829
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
843
830
|
*
|
|
844
831
|
* book.newFile()
|
|
845
832
|
* .setBlob(UrlFetchApp.fetch('https://bkper.com/images/index/integrations4.png').getBlob())
|
|
@@ -1367,7 +1354,7 @@ export declare class Integration {
|
|
|
1367
1354
|
*
|
|
1368
1355
|
* @public
|
|
1369
1356
|
*/
|
|
1370
|
-
declare enum Month {
|
|
1357
|
+
export declare enum Month {
|
|
1371
1358
|
JANUARY = "JANUARY",
|
|
1372
1359
|
FEBRUARY = "FEBRUARY",
|
|
1373
1360
|
MARCH = "MARCH",
|
|
@@ -1387,7 +1374,7 @@ declare enum Month {
|
|
|
1387
1374
|
*
|
|
1388
1375
|
* @public
|
|
1389
1376
|
*/
|
|
1390
|
-
declare enum Period {
|
|
1377
|
+
export declare enum Period {
|
|
1391
1378
|
/**
|
|
1392
1379
|
* Monthly period
|
|
1393
1380
|
*/
|
|
@@ -1456,6 +1443,72 @@ export declare enum Permission {
|
|
|
1456
1443
|
OWNER = "OWNER"
|
|
1457
1444
|
}
|
|
1458
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* This class defines a Template.
|
|
1448
|
+
*
|
|
1449
|
+
* A Template is a pre-configured setup for [[Books]] and associated Google Sheets that provides users with a starting point for specific accounting or financial management needs.
|
|
1450
|
+
*
|
|
1451
|
+
* @public
|
|
1452
|
+
*/
|
|
1453
|
+
export declare class Template {
|
|
1454
|
+
|
|
1455
|
+
constructor(json?: bkper.Template);
|
|
1456
|
+
/**
|
|
1457
|
+
* Gets the name of the Template.
|
|
1458
|
+
*
|
|
1459
|
+
* @returns The Template's name
|
|
1460
|
+
*/
|
|
1461
|
+
getName(): string | undefined;
|
|
1462
|
+
/**
|
|
1463
|
+
* Gets the description of the Template.
|
|
1464
|
+
*
|
|
1465
|
+
* @returns The Template's description
|
|
1466
|
+
*/
|
|
1467
|
+
getDescription(): string | undefined;
|
|
1468
|
+
/**
|
|
1469
|
+
* Gets the url of the image of the Template.
|
|
1470
|
+
*
|
|
1471
|
+
* @returns The url of the Template's image
|
|
1472
|
+
*/
|
|
1473
|
+
getImageUrl(): string | undefined;
|
|
1474
|
+
/**
|
|
1475
|
+
* Gets the category of the Template.
|
|
1476
|
+
*
|
|
1477
|
+
* @returns The Template's category. Example: "PERSONAL", "BUSINESS", etc
|
|
1478
|
+
*/
|
|
1479
|
+
getCategory(): string | undefined;
|
|
1480
|
+
/**
|
|
1481
|
+
* Gets the times the Template has been used.
|
|
1482
|
+
*
|
|
1483
|
+
* @returns The number of times the Template has been used
|
|
1484
|
+
*/
|
|
1485
|
+
getTimesUsed(): number;
|
|
1486
|
+
/**
|
|
1487
|
+
* Gets the bookId of the [[Book]] associated with the Template.
|
|
1488
|
+
*
|
|
1489
|
+
* @returns The bookId of the Book associated with the Template
|
|
1490
|
+
*/
|
|
1491
|
+
getBookId(): string | undefined;
|
|
1492
|
+
/**
|
|
1493
|
+
* Gets the link of the [[Book]] associated with the Template.
|
|
1494
|
+
*
|
|
1495
|
+
* @returns The link of the Book associated with the Template
|
|
1496
|
+
*/
|
|
1497
|
+
getBookLink(): string | undefined;
|
|
1498
|
+
/**
|
|
1499
|
+
* Gets the link of the Google Sheets spreadsheet associated with the Template.
|
|
1500
|
+
*
|
|
1501
|
+
* @returns The link of the Google Sheets spreadsheet associated with the Template
|
|
1502
|
+
*/
|
|
1503
|
+
getSheetsLink(): string | undefined;
|
|
1504
|
+
/**
|
|
1505
|
+
* Gets the wrapped plain json object of the Template.
|
|
1506
|
+
*
|
|
1507
|
+
* @returns The Template wrapped plain json object
|
|
1508
|
+
*/
|
|
1509
|
+
json(): bkper.Template;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1459
1512
|
/**
|
|
1460
1513
|
*
|
|
1461
1514
|
* This class defines a Transaction between [credit and debit](http://en.wikipedia.org/wiki/Debits_and_credits) [[Accounts]].
|
|
@@ -1473,6 +1526,10 @@ export declare class Transaction {
|
|
|
1473
1526
|
* @returns The wrapped plain json object
|
|
1474
1527
|
*/
|
|
1475
1528
|
json(): bkper.Transaction;
|
|
1529
|
+
/**
|
|
1530
|
+
* @returns The book of the Transaction.
|
|
1531
|
+
*/
|
|
1532
|
+
getBook(): Book;
|
|
1476
1533
|
/**
|
|
1477
1534
|
* @returns The id of the Transaction.
|
|
1478
1535
|
*/
|
|
@@ -1790,59 +1847,37 @@ export declare class Transaction {
|
|
|
1790
1847
|
}
|
|
1791
1848
|
|
|
1792
1849
|
/**
|
|
1793
|
-
*
|
|
1794
|
-
* An iterator that allows scripts to iterate over a potentially large collection of transactions.
|
|
1795
|
-
*
|
|
1796
|
-
* Example:
|
|
1797
|
-
*
|
|
1798
|
-
* ```js
|
|
1799
|
-
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
1800
|
-
*
|
|
1801
|
-
* var transactionIterator = book.getTransactions("account:CreditCard after:28/01/2013 before:29/01/2013");
|
|
1802
|
-
*
|
|
1803
|
-
* while (transactionIterator.hasNext()) {
|
|
1804
|
-
* var transaction = transactions.next();
|
|
1805
|
-
* Logger.log(transaction.getDescription());
|
|
1806
|
-
* }
|
|
1807
|
-
* ```
|
|
1808
|
-
*
|
|
1809
|
-
* @public
|
|
1850
|
+
* A list associated with a transaction query.
|
|
1810
1851
|
*/
|
|
1811
|
-
export declare class
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1852
|
+
export declare class TransactionPage {
|
|
1853
|
+
private book;
|
|
1854
|
+
private wrapped;
|
|
1855
|
+
constructor(book: Book, transactionList: bkper.TransactionList);
|
|
1818
1856
|
/**
|
|
1819
|
-
*
|
|
1857
|
+
* @returns The cursor associated with the query for pagination.
|
|
1820
1858
|
*/
|
|
1821
|
-
|
|
1822
|
-
/**
|
|
1823
|
-
* Gets a token that can be used to resume this iteration at a later time.
|
|
1824
|
-
*
|
|
1825
|
-
* This method is useful if processing an iterator in one execution would exceed the maximum execution time.
|
|
1826
|
-
*
|
|
1827
|
-
* Continuation tokens are generally valid short period of time.
|
|
1828
|
-
*/
|
|
1829
|
-
getContinuationToken(): string | undefined;
|
|
1859
|
+
getCursor(): string | undefined;
|
|
1830
1860
|
/**
|
|
1831
|
-
*
|
|
1861
|
+
* Retrieves the account associated with the query, when filtering by account.
|
|
1832
1862
|
*/
|
|
1833
|
-
|
|
1863
|
+
getAccount(): Promise<Account | undefined>;
|
|
1834
1864
|
/**
|
|
1835
|
-
*
|
|
1865
|
+
* @returns The first Transaction in the list.
|
|
1836
1866
|
*/
|
|
1837
|
-
|
|
1867
|
+
getFirst(): Transaction | undefined;
|
|
1838
1868
|
/**
|
|
1839
|
-
*
|
|
1869
|
+
*
|
|
1870
|
+
* Get the total number of transactions in the list.
|
|
1871
|
+
*
|
|
1872
|
+
* @returns The total number of transactions.
|
|
1840
1873
|
*/
|
|
1841
|
-
|
|
1874
|
+
size(): number;
|
|
1842
1875
|
/**
|
|
1843
|
-
*
|
|
1876
|
+
* Get the transactions in the list.
|
|
1877
|
+
*
|
|
1878
|
+
* @returns An array of Transaction objects.
|
|
1844
1879
|
*/
|
|
1845
|
-
|
|
1880
|
+
getItems(): Transaction[];
|
|
1846
1881
|
}
|
|
1847
1882
|
|
|
1848
1883
|
/**
|
|
@@ -1932,7 +1967,7 @@ export declare class User {
|
|
|
1932
1967
|
*
|
|
1933
1968
|
* @public
|
|
1934
1969
|
*/
|
|
1935
|
-
declare enum Visibility {
|
|
1970
|
+
export declare enum Visibility {
|
|
1936
1971
|
/**
|
|
1937
1972
|
* The book can be accessed by anyone with the link
|
|
1938
1973
|
*/
|
package/lib/index.js
CHANGED
|
@@ -5,18 +5,19 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
export {
|
|
8
|
+
export { Account } from './model/Account.js';
|
|
9
9
|
export { Amount } from "./model/Amount.js";
|
|
10
|
+
export { App } from './model/App.js';
|
|
10
11
|
export { Bkper } from './model/Bkper.js';
|
|
11
|
-
export { Account } from './model/Account.js';
|
|
12
12
|
export { Book } from './model/Book.js';
|
|
13
13
|
export { Collection } from './model/Collection.js';
|
|
14
|
+
export { Connection } from './model/Connection.js';
|
|
14
15
|
export { File } from './model/File.js';
|
|
15
16
|
export { Group } from './model/Group.js';
|
|
17
|
+
export { Integration } from './model/Integration.js';
|
|
18
|
+
export { Template } from './model/Template.js';
|
|
16
19
|
export { Transaction } from './model/Transaction.js';
|
|
17
|
-
export {
|
|
20
|
+
export { TransactionList as TransactionPage } from './model/TransactionList.js';
|
|
18
21
|
export { User } from './model/User.js';
|
|
19
|
-
export {
|
|
20
|
-
export { Connection } from './model/Connection.js';
|
|
21
|
-
export { Periodicity, AccountType, DecimalSeparator, Permission } from './model/Enums.js';
|
|
22
|
+
export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, Period, Month } from './model/Enums.js';
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/lib/model/Bkper.js
CHANGED
|
@@ -12,8 +12,10 @@ import { App } from "./App.js";
|
|
|
12
12
|
import * as AppService from '../service/app-service.js';
|
|
13
13
|
import * as BookService from '../service/book-service.js';
|
|
14
14
|
import * as UserService from '../service/user-service.js';
|
|
15
|
+
import * as TemplateService from '../service/template-service.js';
|
|
15
16
|
import { HttpApiRequest } from '../service/http-api-request.js';
|
|
16
17
|
import { User } from "./User.js";
|
|
18
|
+
import { Template } from "./Template.js";
|
|
17
19
|
/**
|
|
18
20
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
19
21
|
*
|
|
@@ -52,12 +54,13 @@ export class Bkper {
|
|
|
52
54
|
* Gets the [[Book]] with the specified bookId from url param.
|
|
53
55
|
*
|
|
54
56
|
* @param id - The universal book id - The same bookId param of URL you access at app.bkper.com
|
|
57
|
+
* @param includeAccounts - Optional parameter to include accounts in the retrieved Book
|
|
55
58
|
*
|
|
56
59
|
* @returns The retrieved Book, for chaining
|
|
57
60
|
*/
|
|
58
|
-
static getBook(id) {
|
|
61
|
+
static getBook(id, includeAccounts) {
|
|
59
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
let book = yield BookService.loadBook(id);
|
|
63
|
+
let book = yield BookService.loadBook(id, includeAccounts);
|
|
61
64
|
return new Book(book);
|
|
62
65
|
});
|
|
63
66
|
}
|
|
@@ -83,6 +86,17 @@ export class Bkper {
|
|
|
83
86
|
return apps.map(app => new App(app));
|
|
84
87
|
});
|
|
85
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets all [[Templates]] available for the user.
|
|
91
|
+
*
|
|
92
|
+
* @returns The retrieved list of Templates
|
|
93
|
+
*/
|
|
94
|
+
static getTemplates() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
let templates = yield TemplateService.getTemplates();
|
|
97
|
+
return templates.map(template => new Template(template));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
86
100
|
/**
|
|
87
101
|
* Gets the current logged [[User]].
|
|
88
102
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -14,14 +14,13 @@ import * as FileService from '../service/file-service.js';
|
|
|
14
14
|
import * as TransactionService from '../service/transaction-service.js';
|
|
15
15
|
import * as IntegrationService from '../service/integration-service.js';
|
|
16
16
|
import * as Utils from '../utils.js';
|
|
17
|
-
import { normalizeName } from '../utils.js';
|
|
18
17
|
import { Account } from './Account.js';
|
|
19
18
|
import { Collection } from './Collection.js';
|
|
20
19
|
import { File } from './File.js';
|
|
21
20
|
import { Group } from './Group.js';
|
|
22
21
|
import { Transaction } from './Transaction.js';
|
|
23
|
-
import { TransactionIterator } from './TransactionIterator.js';
|
|
24
22
|
import { Integration } from './Integration.js';
|
|
23
|
+
import { TransactionList } from './TransactionList.js';
|
|
25
24
|
/**
|
|
26
25
|
*
|
|
27
26
|
* A Book represents [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
|
|
@@ -33,6 +32,8 @@ import { Integration } from './Integration.js';
|
|
|
33
32
|
export class Book {
|
|
34
33
|
constructor(json) {
|
|
35
34
|
this.wrapped = json || {};
|
|
35
|
+
this.mapGroups();
|
|
36
|
+
this.mapAccounts();
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* @returns The wrapped plain json object
|
|
@@ -452,25 +453,13 @@ export class Book {
|
|
|
452
453
|
return new Integration(integration);
|
|
453
454
|
});
|
|
454
455
|
}
|
|
455
|
-
/**
|
|
456
|
-
* Resumes a transaction iteration using a continuation token from a previous iterator.
|
|
457
|
-
*
|
|
458
|
-
* @param continuationToken - continuation token from a previous transaction iterator
|
|
459
|
-
*
|
|
460
|
-
* @returns a collection of transactions that remained in a previous iterator when the continuation token was generated
|
|
461
|
-
*/
|
|
462
|
-
continueTransactionIterator(query, continuationToken) {
|
|
463
|
-
var transactionIterator = new TransactionIterator(this, query);
|
|
464
|
-
transactionIterator.setContinuationToken(continuationToken);
|
|
465
|
-
return transactionIterator;
|
|
466
|
-
}
|
|
467
456
|
/**
|
|
468
457
|
* Instantiate a new [[Transaction]]
|
|
469
458
|
*
|
|
470
459
|
* Example:
|
|
471
460
|
*
|
|
472
461
|
* ```js
|
|
473
|
-
* var book =
|
|
462
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
474
463
|
*
|
|
475
464
|
* book.newTransaction()
|
|
476
465
|
* .setDate('2013-01-25')
|
|
@@ -492,7 +481,7 @@ export class Book {
|
|
|
492
481
|
*
|
|
493
482
|
* Example:
|
|
494
483
|
* ```js
|
|
495
|
-
* var book =
|
|
484
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
496
485
|
*
|
|
497
486
|
* book.newAccount()
|
|
498
487
|
* .setName('Some New Account')
|
|
@@ -512,7 +501,7 @@ export class Book {
|
|
|
512
501
|
*
|
|
513
502
|
* Example:
|
|
514
503
|
* ```js
|
|
515
|
-
* var book =
|
|
504
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
516
505
|
*
|
|
517
506
|
* book.newGroup()
|
|
518
507
|
* .setName('Some New Group')
|
|
@@ -533,16 +522,22 @@ export class Book {
|
|
|
533
522
|
*/
|
|
534
523
|
getAccount(idOrName) {
|
|
535
524
|
return __awaiter(this, void 0, void 0, function* () {
|
|
536
|
-
if (!idOrName) {
|
|
525
|
+
if (!idOrName || idOrName.trim() == '') {
|
|
537
526
|
return undefined;
|
|
538
527
|
}
|
|
539
|
-
|
|
528
|
+
let account;
|
|
529
|
+
if (this.idAccountMap) {
|
|
530
|
+
account = this.idAccountMap.get(idOrName);
|
|
531
|
+
if (account) {
|
|
532
|
+
return account;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
540
535
|
const accountPlain = yield AccountService.getAccount(this.getId(), idOrName);
|
|
541
|
-
if (
|
|
542
|
-
|
|
536
|
+
if (accountPlain) {
|
|
537
|
+
account = new Account(this, accountPlain);
|
|
538
|
+
return account;
|
|
543
539
|
}
|
|
544
|
-
|
|
545
|
-
return account;
|
|
540
|
+
return undefined;
|
|
546
541
|
});
|
|
547
542
|
}
|
|
548
543
|
/** @internal */
|
|
@@ -553,16 +548,26 @@ export class Book {
|
|
|
553
548
|
this.idGroupMap.set(id, group);
|
|
554
549
|
}
|
|
555
550
|
}
|
|
556
|
-
if (this.nameGroupMap) {
|
|
557
|
-
this.nameGroupMap.set(normalizeName(group.getName()), group);
|
|
558
|
-
}
|
|
559
551
|
}
|
|
552
|
+
/** @internal */
|
|
560
553
|
removeGroupCache(group) {
|
|
561
554
|
if (this.idGroupMap) {
|
|
562
555
|
this.idGroupMap.delete(group.getId() || '');
|
|
563
556
|
}
|
|
564
|
-
|
|
565
|
-
|
|
557
|
+
}
|
|
558
|
+
/** @internal */
|
|
559
|
+
updateAccountCache(account) {
|
|
560
|
+
if (this.idAccountMap) {
|
|
561
|
+
const id = account.getId();
|
|
562
|
+
if (id) {
|
|
563
|
+
this.idAccountMap.set(id, account);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/** @internal */
|
|
568
|
+
removeAccountCache(account) {
|
|
569
|
+
if (this.idAccountMap) {
|
|
570
|
+
this.idAccountMap.delete(account.getId() || '');
|
|
566
571
|
}
|
|
567
572
|
}
|
|
568
573
|
/**
|
|
@@ -580,9 +585,6 @@ export class Book {
|
|
|
580
585
|
idOrName = idOrName + '';
|
|
581
586
|
if (this.idGroupMap) {
|
|
582
587
|
let group = this.idGroupMap.get(idOrName);
|
|
583
|
-
if (!group && this.nameGroupMap) {
|
|
584
|
-
group = this.nameGroupMap.get(normalizeName(idOrName));
|
|
585
|
-
}
|
|
586
588
|
if (group) {
|
|
587
589
|
return group;
|
|
588
590
|
}
|
|
@@ -605,50 +607,54 @@ export class Book {
|
|
|
605
607
|
return Array.from(this.idGroupMap.values());
|
|
606
608
|
}
|
|
607
609
|
let groups = yield GroupService.getGroups(this.getId());
|
|
608
|
-
|
|
609
|
-
this.idGroupMap = new Map();
|
|
610
|
-
this.nameGroupMap = new Map();
|
|
611
|
-
for (var i = 0; i < groupsObj.length; i++) {
|
|
612
|
-
var group = groupsObj[i];
|
|
613
|
-
this.updateGroupCache(group);
|
|
614
|
-
}
|
|
615
|
-
return groupsObj;
|
|
610
|
+
return this.mapGroups(groups);
|
|
616
611
|
});
|
|
617
612
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
613
|
+
mapGroups(groups) {
|
|
614
|
+
if (!groups) {
|
|
615
|
+
return [];
|
|
616
|
+
}
|
|
617
|
+
let groupsObj = groups.map(group => new Group(this, group));
|
|
618
|
+
this.idGroupMap = new Map();
|
|
619
|
+
for (const group of groupsObj) {
|
|
620
|
+
this.updateGroupCache(group);
|
|
621
|
+
}
|
|
622
|
+
return groupsObj;
|
|
623
|
+
}
|
|
624
|
+
getAccounts() {
|
|
622
625
|
return __awaiter(this, void 0, void 0, function* () {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
+
if (this.idAccountMap) {
|
|
627
|
+
return Array.from(this.idAccountMap.values());
|
|
628
|
+
}
|
|
629
|
+
let accounts = yield AccountService.getAccounts(this.getId());
|
|
630
|
+
return this.mapAccounts(accounts);
|
|
626
631
|
});
|
|
627
632
|
}
|
|
633
|
+
mapAccounts(accounts) {
|
|
634
|
+
if (!accounts) {
|
|
635
|
+
return [];
|
|
636
|
+
}
|
|
637
|
+
let accountsObj = accounts.map(account => new Account(this, account));
|
|
638
|
+
this.idAccountMap = new Map();
|
|
639
|
+
for (const account of accountsObj) {
|
|
640
|
+
this.updateAccountCache(account);
|
|
641
|
+
}
|
|
642
|
+
return accountsObj;
|
|
643
|
+
}
|
|
628
644
|
/**
|
|
629
|
-
*
|
|
645
|
+
* Lists transactions in the Book based on the provided query, limit, and cursor, for pagination.
|
|
630
646
|
*
|
|
631
|
-
*
|
|
647
|
+
* @param query - The query string to filter transactions
|
|
648
|
+
* @param limit - The maximum number of transactions to return. Default to 100, max to 1000;
|
|
649
|
+
* @param cursor - The cursor for pagination
|
|
632
650
|
*
|
|
633
|
-
* @
|
|
634
|
-
*
|
|
635
|
-
* @returns The Transactions result as an iterator.
|
|
636
|
-
*
|
|
637
|
-
* Example:
|
|
638
|
-
*
|
|
639
|
-
* ```js
|
|
640
|
-
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
641
|
-
*
|
|
642
|
-
* var transactions = book.getTransactions("account:CreditCard after:28/01/2013 before:29/01/2013");
|
|
643
|
-
*
|
|
644
|
-
* while (transactions.hasNext()) {
|
|
645
|
-
* var transaction = transactions.next();
|
|
646
|
-
* Logger.log(transaction.getDescription());
|
|
647
|
-
* }
|
|
648
|
-
* ```
|
|
651
|
+
* @returns A TransactionPage object containing the list of transactions
|
|
649
652
|
*/
|
|
650
|
-
|
|
651
|
-
return
|
|
653
|
+
listTransactions(query, limit, cursor) {
|
|
654
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
655
|
+
const transactionsList = yield TransactionService.listTransactions(this.getId(), query, limit, cursor);
|
|
656
|
+
return new TransactionList(this, transactionsList);
|
|
657
|
+
});
|
|
652
658
|
}
|
|
653
659
|
/**
|
|
654
660
|
* Retrieve a transaction by id
|
|
@@ -668,7 +674,7 @@ export class Book {
|
|
|
668
674
|
*
|
|
669
675
|
* Example:
|
|
670
676
|
* ```js
|
|
671
|
-
* var book =
|
|
677
|
+
* var book = Bkper.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
672
678
|
*
|
|
673
679
|
* book.newFile()
|
|
674
680
|
* .setBlob(UrlFetchApp.fetch('https://bkper.com/images/index/integrations4.png').getBlob())
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class defines a Template.
|
|
3
|
+
*
|
|
4
|
+
* A Template is a pre-configured setup for [[Books]] and associated Google Sheets that provides users with a starting point for specific accounting or financial management needs.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class Template {
|
|
9
|
+
constructor(json) {
|
|
10
|
+
this.wrapped = json || {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets the name of the Template.
|
|
14
|
+
*
|
|
15
|
+
* @returns The Template's name
|
|
16
|
+
*/
|
|
17
|
+
getName() {
|
|
18
|
+
return this.wrapped.name;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the description of the Template.
|
|
22
|
+
*
|
|
23
|
+
* @returns The Template's description
|
|
24
|
+
*/
|
|
25
|
+
getDescription() {
|
|
26
|
+
return this.wrapped.description;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets the url of the image of the Template.
|
|
30
|
+
*
|
|
31
|
+
* @returns The url of the Template's image
|
|
32
|
+
*/
|
|
33
|
+
getImageUrl() {
|
|
34
|
+
return this.wrapped.imageUrl;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the category of the Template.
|
|
38
|
+
*
|
|
39
|
+
* @returns The Template's category. Example: "PERSONAL", "BUSINESS", etc
|
|
40
|
+
*/
|
|
41
|
+
getCategory() {
|
|
42
|
+
return this.wrapped.category;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the times the Template has been used.
|
|
46
|
+
*
|
|
47
|
+
* @returns The number of times the Template has been used
|
|
48
|
+
*/
|
|
49
|
+
getTimesUsed() {
|
|
50
|
+
return this.wrapped.timesUsed || 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the bookId of the [[Book]] associated with the Template.
|
|
54
|
+
*
|
|
55
|
+
* @returns The bookId of the Book associated with the Template
|
|
56
|
+
*/
|
|
57
|
+
getBookId() {
|
|
58
|
+
return this.wrapped.bookId;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the link of the [[Book]] associated with the Template.
|
|
62
|
+
*
|
|
63
|
+
* @returns The link of the Book associated with the Template
|
|
64
|
+
*/
|
|
65
|
+
getBookLink() {
|
|
66
|
+
return this.wrapped.bookLink;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the link of the Google Sheets spreadsheet associated with the Template.
|
|
70
|
+
*
|
|
71
|
+
* @returns The link of the Google Sheets spreadsheet associated with the Template
|
|
72
|
+
*/
|
|
73
|
+
getSheetsLink() {
|
|
74
|
+
return this.wrapped.sheetsLink;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Gets the wrapped plain json object of the Template.
|
|
78
|
+
*
|
|
79
|
+
* @returns The Template wrapped plain json object
|
|
80
|
+
*/
|
|
81
|
+
json() {
|
|
82
|
+
return this.wrapped;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=Template.js.map
|
package/lib/model/Transaction.js
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
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 { Transaction } from "./Transaction.js";
|
|
11
|
+
/**
|
|
12
|
+
* A list associated with a transaction query.
|
|
13
|
+
*/
|
|
14
|
+
export class TransactionList {
|
|
15
|
+
constructor(book, transactionList) {
|
|
16
|
+
this.book = book;
|
|
17
|
+
this.wrapped = transactionList;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @returns The cursor associated with the query for pagination.
|
|
21
|
+
*/
|
|
22
|
+
getCursor() {
|
|
23
|
+
return this.wrapped.cursor;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the account associated with the query, when filtering by account.
|
|
27
|
+
*/
|
|
28
|
+
getAccount() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!this.wrapped.account) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return yield this.book.getAccount(this.wrapped.account);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @returns The first Transaction in the list.
|
|
38
|
+
*/
|
|
39
|
+
getFirst() {
|
|
40
|
+
const transactions = this.getItems();
|
|
41
|
+
return transactions.length > 0 ? transactions[0] : undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* Get the total number of transactions in the list.
|
|
46
|
+
*
|
|
47
|
+
* @returns The total number of transactions.
|
|
48
|
+
*/
|
|
49
|
+
size() {
|
|
50
|
+
var _a;
|
|
51
|
+
return ((_a = this.wrapped.items) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the transactions in the list.
|
|
55
|
+
*
|
|
56
|
+
* @returns An array of Transaction objects.
|
|
57
|
+
*/
|
|
58
|
+
getItems() {
|
|
59
|
+
var _a;
|
|
60
|
+
let transactions = [];
|
|
61
|
+
for (let transaction of (_a = this.wrapped.items) !== null && _a !== void 0 ? _a : []) {
|
|
62
|
+
transactions.push(new Transaction(this.book, transaction));
|
|
63
|
+
}
|
|
64
|
+
return transactions;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=TransactionList.js.map
|
|
@@ -33,4 +33,10 @@ export function getAccount(bookId, idOrName) {
|
|
|
33
33
|
return response.data;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
export function getAccounts(bookId) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts`).setMethod('GET').fetch();
|
|
39
|
+
return response.data;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
36
42
|
//# sourceMappingURL=account-service.js.map
|
|
@@ -22,12 +22,13 @@ export function loadBooks() {
|
|
|
22
22
|
return booksJson;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
export function loadBook(bookId) {
|
|
25
|
+
export function loadBook(bookId, loadAccounts) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
if (bookId == null) {
|
|
28
28
|
throw new Error("Book id null!");
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
loadAccounts = loadAccounts || false;
|
|
31
|
+
let response = yield new HttpBooksApiV5Request(bookId).addParam('loadAccounts', loadAccounts).fetch();
|
|
31
32
|
return response.data;
|
|
32
33
|
});
|
|
33
34
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { HttpApiRequest } from "./http-api-request.js";
|
|
11
|
+
export function getTemplates() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
let response = yield new HttpApiRequest(`v5/templates`).setMethod('GET').fetch();
|
|
14
|
+
if (response.data == null) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
let templateListPlain = response.data;
|
|
18
|
+
let templatesJson = templateListPlain.items;
|
|
19
|
+
if (templatesJson == null) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return templatesJson;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=template-service.js.map
|
|
@@ -83,7 +83,7 @@ export function getTransaction(bookId, id) {
|
|
|
83
83
|
return response.data;
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
export function
|
|
86
|
+
export function listTransactions(bookId, query, limit, cursor) {
|
|
87
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
88
|
if (!query) {
|
|
89
89
|
query = "";
|
package/package.json
CHANGED
|
@@ -1,150 +0,0 @@
|
|
|
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 { TransactionPage } from "./TransactionPage.js";
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* An iterator that allows scripts to iterate over a potentially large collection of transactions.
|
|
14
|
-
*
|
|
15
|
-
* Example:
|
|
16
|
-
*
|
|
17
|
-
* ```js
|
|
18
|
-
* var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
|
|
19
|
-
*
|
|
20
|
-
* var transactionIterator = book.getTransactions("account:CreditCard after:28/01/2013 before:29/01/2013");
|
|
21
|
-
*
|
|
22
|
-
* while (transactionIterator.hasNext()) {
|
|
23
|
-
* var transaction = transactions.next();
|
|
24
|
-
* Logger.log(transaction.getDescription());
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export class TransactionIterator {
|
|
31
|
-
/** @internal */
|
|
32
|
-
constructor(book, query) {
|
|
33
|
-
this.book = book;
|
|
34
|
-
this.query = query;
|
|
35
|
-
if (this.query == null) {
|
|
36
|
-
this.query = "";
|
|
37
|
-
}
|
|
38
|
-
this.currentPage = undefined;
|
|
39
|
-
this.nextPage = undefined;
|
|
40
|
-
this.lastCursor = undefined;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Gets the Book that originate the iterator
|
|
44
|
-
*/
|
|
45
|
-
getBook() {
|
|
46
|
-
return this.book;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Gets a token that can be used to resume this iteration at a later time.
|
|
50
|
-
*
|
|
51
|
-
* This method is useful if processing an iterator in one execution would exceed the maximum execution time.
|
|
52
|
-
*
|
|
53
|
-
* Continuation tokens are generally valid short period of time.
|
|
54
|
-
*/
|
|
55
|
-
getContinuationToken() {
|
|
56
|
-
if (this.currentPage == null) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
var cursor = this.lastCursor;
|
|
60
|
-
if (cursor == null) {
|
|
61
|
-
cursor = "null";
|
|
62
|
-
}
|
|
63
|
-
var continuationToken = cursor + "_bkperpageindex_" + this.currentPage.getIndex();
|
|
64
|
-
return continuationToken;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Sets a continuation token from previous paused iteration
|
|
68
|
-
*/
|
|
69
|
-
setContinuationToken(continuationToken) {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if (continuationToken == null) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
var cursorIndexArray = continuationToken.split("_bkperpageindex_");
|
|
75
|
-
if (cursorIndexArray.length != 2) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
var cursor = cursorIndexArray[0];
|
|
79
|
-
var index = cursorIndexArray[1];
|
|
80
|
-
if ("null" != cursor) {
|
|
81
|
-
this.lastCursor = cursor;
|
|
82
|
-
}
|
|
83
|
-
let indexNum = new Number(index).valueOf();
|
|
84
|
-
this.currentPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
85
|
-
this.currentPage.setIndex(indexNum);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Determines whether calling next() will return a transaction.
|
|
90
|
-
*/
|
|
91
|
-
hasNext() {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
if (this.currentPage == null) {
|
|
94
|
-
this.currentPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
95
|
-
}
|
|
96
|
-
if (this.currentPage.hasNext()) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
else if (!this.currentPage.hasReachEnd()) {
|
|
100
|
-
this.lastCursor = this.currentPage.getCursor();
|
|
101
|
-
if (this.nextPage == null) {
|
|
102
|
-
this.nextPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
103
|
-
}
|
|
104
|
-
return this.nextPage.hasNext();
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Gets the next transaction in the collection of transactions.
|
|
113
|
-
*/
|
|
114
|
-
next() {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
if (this.currentPage == null) {
|
|
117
|
-
this.currentPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
118
|
-
}
|
|
119
|
-
if (this.currentPage.hasNext()) {
|
|
120
|
-
return this.currentPage.next();
|
|
121
|
-
}
|
|
122
|
-
else if (!this.currentPage.hasReachEnd()) {
|
|
123
|
-
this.lastCursor = this.currentPage.getCursor();
|
|
124
|
-
if (this.nextPage) {
|
|
125
|
-
this.currentPage = this.nextPage;
|
|
126
|
-
this.nextPage = undefined;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
this.currentPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
130
|
-
}
|
|
131
|
-
return this.currentPage.next();
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* @returns The account, when filtering by a single account.
|
|
140
|
-
*/
|
|
141
|
-
getAccount() {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
if (this.currentPage == null) {
|
|
144
|
-
this.currentPage = yield new TransactionPage().init(this.book, this.query, this.lastCursor);
|
|
145
|
-
}
|
|
146
|
-
return this.currentPage.getAccount();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=TransactionIterator.js.map
|
|
@@ -1,71 +0,0 @@
|
|
|
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 { Transaction } from "./Transaction.js";
|
|
11
|
-
import * as TransactionService from '../service/transaction-service.js';
|
|
12
|
-
export class TransactionPage {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.transactions = [];
|
|
15
|
-
}
|
|
16
|
-
init(book, query, lastCursor) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
var transactionList = yield TransactionService.searchTransactions(book.getId(), query, 1000, lastCursor);
|
|
19
|
-
if (!transactionList.items) {
|
|
20
|
-
transactionList.items = [];
|
|
21
|
-
}
|
|
22
|
-
this.transactions = transactionList.items.map(tx => new Transaction(book, tx));
|
|
23
|
-
this.cursor = transactionList.cursor;
|
|
24
|
-
if (transactionList.account) {
|
|
25
|
-
this.account = yield book.getAccount(transactionList.account);
|
|
26
|
-
}
|
|
27
|
-
this.index = 0;
|
|
28
|
-
if (this.transactions == null || this.transactions.length == 0 || this.cursor == null || this.cursor == "") {
|
|
29
|
-
this.reachEnd = true;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
this.reachEnd = false;
|
|
33
|
-
}
|
|
34
|
-
return this;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getCursor() {
|
|
38
|
-
return this.cursor;
|
|
39
|
-
}
|
|
40
|
-
hasNext() {
|
|
41
|
-
return (this.index != null && this.index < this.transactions.length) || false;
|
|
42
|
-
}
|
|
43
|
-
hasReachEnd() {
|
|
44
|
-
return this.reachEnd || false;
|
|
45
|
-
}
|
|
46
|
-
getIndex() {
|
|
47
|
-
if (this.index != null && this.index >= this.transactions.length) {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return this.index || 0;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
setIndex(index) {
|
|
55
|
-
this.index = index;
|
|
56
|
-
}
|
|
57
|
-
getAccount() {
|
|
58
|
-
return this.account;
|
|
59
|
-
}
|
|
60
|
-
next() {
|
|
61
|
-
if (this.index != null && this.index < this.transactions.length) {
|
|
62
|
-
var transaction = this.transactions[this.index];
|
|
63
|
-
this.index++;
|
|
64
|
-
return transaction;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=TransactionPage.js.map
|