bkper-js 1.8.1 → 1.8.2
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 +45 -55
- package/lib/model/Account.js +44 -42
- package/lib/model/Amount.js +53 -53
- package/lib/model/App.js +18 -18
- package/lib/model/Book.js +46 -46
- package/lib/model/Collection.js +12 -13
- package/lib/model/Connection.js +21 -23
- package/lib/model/File.js +16 -17
- package/lib/model/Group.js +26 -27
- package/lib/model/Integration.js +13 -15
- package/lib/model/Template.js +15 -17
- package/lib/model/Transaction.js +69 -70
- package/lib/model/TransactionList.js +7 -7
- package/lib/model/User.js +14 -15
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -17,12 +17,11 @@
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export declare class Account {
|
|
20
|
+
payload: bkper.Account;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
constructor(book: Book, json?: bkper.Account);
|
|
22
|
+
constructor(book: Book, payload?: bkper.Account);
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @returns The wrapped plain json object
|
|
24
|
+
* @returns An immutable copy of the json payload
|
|
26
25
|
*/
|
|
27
26
|
json(): bkper.Account;
|
|
28
27
|
/**
|
|
@@ -314,8 +313,12 @@ export declare class Amount {
|
|
|
314
313
|
* @public
|
|
315
314
|
*/
|
|
316
315
|
export declare class App {
|
|
317
|
-
|
|
318
|
-
constructor(
|
|
316
|
+
payload: bkper.App;
|
|
317
|
+
constructor(payload?: bkper.App);
|
|
318
|
+
/**
|
|
319
|
+
* @returns The wrapped plain json object
|
|
320
|
+
*/
|
|
321
|
+
json(): bkper.App;
|
|
319
322
|
/**
|
|
320
323
|
*
|
|
321
324
|
* Sets the webhook url for development.
|
|
@@ -366,10 +369,6 @@ export declare class App {
|
|
|
366
369
|
* Perform update App, applying pending changes.
|
|
367
370
|
*/
|
|
368
371
|
update(): Promise<App>;
|
|
369
|
-
/**
|
|
370
|
-
* @returns The wrapped plain json object
|
|
371
|
-
*/
|
|
372
|
-
json(): bkper.App;
|
|
373
372
|
}
|
|
374
373
|
|
|
375
374
|
/**
|
|
@@ -470,13 +469,13 @@ export declare class Bkper {
|
|
|
470
469
|
* @public
|
|
471
470
|
*/
|
|
472
471
|
export declare class Book {
|
|
472
|
+
payload: bkper.Book;
|
|
473
473
|
|
|
474
474
|
|
|
475
475
|
|
|
476
|
-
|
|
477
|
-
constructor(json?: bkper.Book);
|
|
476
|
+
constructor(payload?: bkper.Book);
|
|
478
477
|
/**
|
|
479
|
-
* @returns
|
|
478
|
+
* @returns An immutable copy of the json payload
|
|
480
479
|
*/
|
|
481
480
|
json(): bkper.Book;
|
|
482
481
|
/**
|
|
@@ -856,8 +855,12 @@ export declare class Book {
|
|
|
856
855
|
* @public
|
|
857
856
|
*/
|
|
858
857
|
export declare class Collection {
|
|
859
|
-
|
|
860
|
-
|
|
858
|
+
payload: bkper.Collection;
|
|
859
|
+
constructor(payload?: bkper.Collection);
|
|
860
|
+
/**
|
|
861
|
+
* @returns The wrapped plain json object
|
|
862
|
+
*/
|
|
863
|
+
json(): bkper.Collection;
|
|
861
864
|
/**
|
|
862
865
|
* @returns The id of this Collection
|
|
863
866
|
*/
|
|
@@ -870,10 +873,6 @@ export declare class Collection {
|
|
|
870
873
|
* @returns All Books of this collection.
|
|
871
874
|
*/
|
|
872
875
|
getBooks(): Book[];
|
|
873
|
-
/**
|
|
874
|
-
* @returns The wrapped plain json object
|
|
875
|
-
*/
|
|
876
|
-
json(): bkper.Collection;
|
|
877
876
|
}
|
|
878
877
|
|
|
879
878
|
/**
|
|
@@ -927,12 +926,10 @@ export declare interface Config {
|
|
|
927
926
|
* @public
|
|
928
927
|
*/
|
|
929
928
|
export declare class Connection {
|
|
930
|
-
|
|
931
|
-
constructor(
|
|
929
|
+
payload: bkper.Connection;
|
|
930
|
+
constructor(payload?: bkper.Connection);
|
|
932
931
|
/**
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* @returns The Connection wrapped plain json object
|
|
932
|
+
* @returns An immutable copy of the json payload
|
|
936
933
|
*/
|
|
937
934
|
json(): bkper.Connection;
|
|
938
935
|
/**
|
|
@@ -1095,14 +1092,13 @@ export declare enum DecimalSeparator {
|
|
|
1095
1092
|
* @public
|
|
1096
1093
|
*/
|
|
1097
1094
|
export declare class File {
|
|
1095
|
+
payload: bkper.File;
|
|
1098
1096
|
|
|
1099
|
-
|
|
1100
|
-
constructor(book: Book, json?: bkper.File);
|
|
1097
|
+
constructor(book: Book, payload?: bkper.File);
|
|
1101
1098
|
/**
|
|
1102
|
-
*
|
|
1103
|
-
* @returns The wrapped plain json object
|
|
1099
|
+
* @returns An immutable copy of the json payload
|
|
1104
1100
|
*/
|
|
1105
|
-
json(): bkper.
|
|
1101
|
+
json(): bkper.File;
|
|
1106
1102
|
/**
|
|
1107
1103
|
* Gets the File id
|
|
1108
1104
|
*/
|
|
@@ -1164,13 +1160,12 @@ export declare class File {
|
|
|
1164
1160
|
* @public
|
|
1165
1161
|
*/
|
|
1166
1162
|
export declare class Group {
|
|
1163
|
+
payload: bkper.Group;
|
|
1167
1164
|
|
|
1168
1165
|
|
|
1169
|
-
|
|
1170
|
-
constructor(book: Book, json?: bkper.Group);
|
|
1166
|
+
constructor(book: Book, payload?: bkper.Group);
|
|
1171
1167
|
/**
|
|
1172
|
-
*
|
|
1173
|
-
* @returns The wrapped plain json object
|
|
1168
|
+
* @returns An immutable copy of the json payload
|
|
1174
1169
|
*/
|
|
1175
1170
|
json(): bkper.Group;
|
|
1176
1171
|
/**
|
|
@@ -1278,12 +1273,10 @@ export declare class Group {
|
|
|
1278
1273
|
* @public
|
|
1279
1274
|
*/
|
|
1280
1275
|
export declare class Integration {
|
|
1281
|
-
|
|
1282
|
-
constructor(
|
|
1276
|
+
payload: bkper.Integration;
|
|
1277
|
+
constructor(payload?: bkper.Integration);
|
|
1283
1278
|
/**
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1286
|
-
* @returns The Integration wrapped plain json object
|
|
1279
|
+
* @returns An immutable copy of the json payload
|
|
1287
1280
|
*/
|
|
1288
1281
|
json(): bkper.Integration;
|
|
1289
1282
|
/**
|
|
@@ -1451,8 +1444,12 @@ export declare enum Permission {
|
|
|
1451
1444
|
* @public
|
|
1452
1445
|
*/
|
|
1453
1446
|
export declare class Template {
|
|
1454
|
-
|
|
1447
|
+
payload: bkper.Template;
|
|
1455
1448
|
constructor(json?: bkper.Template);
|
|
1449
|
+
/**
|
|
1450
|
+
* @returns An immutable copy of the json payload
|
|
1451
|
+
*/
|
|
1452
|
+
json(): bkper.Template;
|
|
1456
1453
|
/**
|
|
1457
1454
|
* Gets the name of the Template.
|
|
1458
1455
|
*
|
|
@@ -1501,12 +1498,6 @@ export declare class Template {
|
|
|
1501
1498
|
* @returns The link of the Google Sheets spreadsheet associated with the Template
|
|
1502
1499
|
*/
|
|
1503
1500
|
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
1501
|
}
|
|
1511
1502
|
|
|
1512
1503
|
/**
|
|
@@ -1518,12 +1509,11 @@ export declare class Template {
|
|
|
1518
1509
|
* @public
|
|
1519
1510
|
*/
|
|
1520
1511
|
export declare class Transaction {
|
|
1512
|
+
payload: bkper.Transaction;
|
|
1521
1513
|
|
|
1522
|
-
|
|
1523
|
-
constructor(book: Book, json?: bkper.Transaction);
|
|
1514
|
+
constructor(book: Book, payload?: bkper.Transaction);
|
|
1524
1515
|
/**
|
|
1525
|
-
*
|
|
1526
|
-
* @returns The wrapped plain json object
|
|
1516
|
+
* @returns An immutable copy of the json payload
|
|
1527
1517
|
*/
|
|
1528
1518
|
json(): bkper.Transaction;
|
|
1529
1519
|
/**
|
|
@@ -1850,9 +1840,9 @@ export declare class Transaction {
|
|
|
1850
1840
|
* A list associated with a transaction query.
|
|
1851
1841
|
*/
|
|
1852
1842
|
export declare class TransactionPage {
|
|
1853
|
-
private
|
|
1854
|
-
|
|
1855
|
-
constructor(book: Book,
|
|
1843
|
+
private payload;
|
|
1844
|
+
|
|
1845
|
+
constructor(book: Book, payload: bkper.TransactionList);
|
|
1856
1846
|
/**
|
|
1857
1847
|
* @returns The cursor associated with the query for pagination.
|
|
1858
1848
|
*/
|
|
@@ -1886,10 +1876,10 @@ export declare class TransactionPage {
|
|
|
1886
1876
|
* @public
|
|
1887
1877
|
*/
|
|
1888
1878
|
export declare class User {
|
|
1889
|
-
|
|
1890
|
-
constructor(
|
|
1879
|
+
payload: bkper.User;
|
|
1880
|
+
constructor(payload?: bkper.User);
|
|
1891
1881
|
/**
|
|
1892
|
-
* @returns
|
|
1882
|
+
* @returns An immutable copy of the json payload
|
|
1893
1883
|
*/
|
|
1894
1884
|
json(): bkper.User;
|
|
1895
1885
|
/**
|
package/lib/model/Account.js
CHANGED
|
@@ -23,28 +23,27 @@ import { Amount } from './Amount.js';
|
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
export class Account {
|
|
26
|
-
constructor(book,
|
|
26
|
+
constructor(book, payload) {
|
|
27
27
|
this.book = book;
|
|
28
|
-
this.
|
|
28
|
+
this.payload = payload || {};
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @returns The wrapped plain json object
|
|
31
|
+
* @returns An immutable copy of the json payload
|
|
33
32
|
*/
|
|
34
33
|
json() {
|
|
35
|
-
return this.
|
|
34
|
+
return Object.assign({}, this.payload);
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* Gets the account internal id.
|
|
39
38
|
*/
|
|
40
39
|
getId() {
|
|
41
|
-
return this.
|
|
40
|
+
return this.payload.id;
|
|
42
41
|
}
|
|
43
42
|
/**
|
|
44
43
|
* Gets the account name.
|
|
45
44
|
*/
|
|
46
45
|
getName() {
|
|
47
|
-
return this.
|
|
46
|
+
return this.payload.name;
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
*
|
|
@@ -53,15 +52,15 @@ export class Account {
|
|
|
53
52
|
* @returns This Account, for chainning.
|
|
54
53
|
*/
|
|
55
54
|
setName(name) {
|
|
56
|
-
this.
|
|
55
|
+
this.payload.name = name;
|
|
57
56
|
return this;
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* @returns The name of this account without spaces or special characters.
|
|
61
60
|
*/
|
|
62
61
|
getNormalizedName() {
|
|
63
|
-
if (this.
|
|
64
|
-
return this.
|
|
62
|
+
if (this.payload.normalizedName) {
|
|
63
|
+
return this.payload.normalizedName;
|
|
65
64
|
}
|
|
66
65
|
else {
|
|
67
66
|
return normalizeText(this.getName());
|
|
@@ -71,7 +70,7 @@ export class Account {
|
|
|
71
70
|
* @returns The type for of this account.
|
|
72
71
|
*/
|
|
73
72
|
getType() {
|
|
74
|
-
return this.
|
|
73
|
+
return this.payload.type;
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
77
76
|
*
|
|
@@ -80,14 +79,14 @@ export class Account {
|
|
|
80
79
|
* @returns This Account, for chainning
|
|
81
80
|
*/
|
|
82
81
|
setType(type) {
|
|
83
|
-
this.
|
|
82
|
+
this.payload.type = type;
|
|
84
83
|
return this;
|
|
85
84
|
}
|
|
86
85
|
/**
|
|
87
86
|
* Gets the custom properties stored in this Account.
|
|
88
87
|
*/
|
|
89
88
|
getProperties() {
|
|
90
|
-
return this.
|
|
89
|
+
return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
|
|
91
90
|
}
|
|
92
91
|
/**
|
|
93
92
|
* Sets the custom properties of the Account
|
|
@@ -97,7 +96,7 @@ export class Account {
|
|
|
97
96
|
* @returns This Account, for chainning.
|
|
98
97
|
*/
|
|
99
98
|
setProperties(properties) {
|
|
100
|
-
this.
|
|
99
|
+
this.payload.properties = Object.assign({}, properties);
|
|
101
100
|
return this;
|
|
102
101
|
}
|
|
103
102
|
/**
|
|
@@ -108,7 +107,7 @@ export class Account {
|
|
|
108
107
|
getProperty(...keys) {
|
|
109
108
|
for (let index = 0; index < keys.length; index++) {
|
|
110
109
|
const key = keys[index];
|
|
111
|
-
let value = this.
|
|
110
|
+
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
112
111
|
if (value != null && value.trim() != '') {
|
|
113
112
|
return value;
|
|
114
113
|
}
|
|
@@ -127,13 +126,13 @@ export class Account {
|
|
|
127
126
|
if (key == null || key.trim() == '') {
|
|
128
127
|
return this;
|
|
129
128
|
}
|
|
130
|
-
if (this.
|
|
131
|
-
this.
|
|
129
|
+
if (this.payload.properties == null) {
|
|
130
|
+
this.payload.properties = {};
|
|
132
131
|
}
|
|
133
132
|
if (!value) {
|
|
134
133
|
value = '';
|
|
135
134
|
}
|
|
136
|
-
this.
|
|
135
|
+
this.payload.properties[key] = value;
|
|
137
136
|
return this;
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
@@ -154,8 +153,8 @@ export class Account {
|
|
|
154
153
|
*/
|
|
155
154
|
getBalance() {
|
|
156
155
|
var balance = new Amount('0');
|
|
157
|
-
if (this.
|
|
158
|
-
balance = round(this.
|
|
156
|
+
if (this.payload.balance != null) {
|
|
157
|
+
balance = round(this.payload.balance, this.book.getFractionDigits());
|
|
159
158
|
}
|
|
160
159
|
return balance;
|
|
161
160
|
}
|
|
@@ -166,8 +165,8 @@ export class Account {
|
|
|
166
165
|
*/
|
|
167
166
|
getBalanceRaw() {
|
|
168
167
|
var balance = new Amount('0');
|
|
169
|
-
if (this.
|
|
170
|
-
balance = round(this.
|
|
168
|
+
if (this.payload.balance != null) {
|
|
169
|
+
balance = round(this.payload.balance, this.book.getFractionDigits());
|
|
171
170
|
}
|
|
172
171
|
return balance;
|
|
173
172
|
}
|
|
@@ -175,7 +174,7 @@ export class Account {
|
|
|
175
174
|
* Tell if this account is archived.
|
|
176
175
|
*/
|
|
177
176
|
isArchived() {
|
|
178
|
-
return this.
|
|
177
|
+
return this.payload.archived;
|
|
179
178
|
}
|
|
180
179
|
/**
|
|
181
180
|
* Set account archived/unarchived.
|
|
@@ -183,7 +182,7 @@ export class Account {
|
|
|
183
182
|
* @returns This Account, for chainning.
|
|
184
183
|
*/
|
|
185
184
|
setArchived(archived) {
|
|
186
|
-
this.
|
|
185
|
+
this.payload.archived = archived;
|
|
187
186
|
return this;
|
|
188
187
|
}
|
|
189
188
|
/**
|
|
@@ -192,7 +191,7 @@ export class Account {
|
|
|
192
191
|
* Accounts with transaction posted, even with zero balance, can only be archived.
|
|
193
192
|
*/
|
|
194
193
|
hasTransactionPosted() {
|
|
195
|
-
return this.
|
|
194
|
+
return this.payload.hasTransactionPosted;
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
197
|
*
|
|
@@ -207,7 +206,7 @@ export class Account {
|
|
|
207
206
|
* @returns True if its a permanent Account
|
|
208
207
|
*/
|
|
209
208
|
isPermanent() {
|
|
210
|
-
return this.
|
|
209
|
+
return this.payload.permanent;
|
|
211
210
|
}
|
|
212
211
|
/**
|
|
213
212
|
* Tell if the account has a Credit nature or Debit otherwise
|
|
@@ -230,7 +229,7 @@ export class Account {
|
|
|
230
229
|
* As a rule of thumb, and for simple understanding, almost all accounts are Debit nature (NOT credit), except the ones that "offers" amount for the books, like revenue accounts.
|
|
231
230
|
*/
|
|
232
231
|
isCredit() {
|
|
233
|
-
return this.
|
|
232
|
+
return this.payload.credit;
|
|
234
233
|
}
|
|
235
234
|
/**
|
|
236
235
|
* Get the [[Groups]] of this account.
|
|
@@ -252,7 +251,7 @@ export class Account {
|
|
|
252
251
|
* @returns This Account, for chainning.
|
|
253
252
|
*/
|
|
254
253
|
setGroups(groups) {
|
|
255
|
-
this.
|
|
254
|
+
this.payload.groups = undefined;
|
|
256
255
|
if (groups != null) {
|
|
257
256
|
groups.forEach(group => this.addGroup(group));
|
|
258
257
|
}
|
|
@@ -264,14 +263,14 @@ export class Account {
|
|
|
264
263
|
* @returns This Account, for chainning.
|
|
265
264
|
*/
|
|
266
265
|
addGroup(group) {
|
|
267
|
-
if (!this.
|
|
268
|
-
this.
|
|
266
|
+
if (!this.payload.groups) {
|
|
267
|
+
this.payload.groups = [];
|
|
269
268
|
}
|
|
270
269
|
if (group instanceof Group) {
|
|
271
|
-
this.
|
|
270
|
+
this.payload.groups.push(group.json());
|
|
272
271
|
}
|
|
273
272
|
else {
|
|
274
|
-
this.
|
|
273
|
+
this.payload.groups.push(group);
|
|
275
274
|
}
|
|
276
275
|
return this;
|
|
277
276
|
}
|
|
@@ -280,7 +279,7 @@ export class Account {
|
|
|
280
279
|
*/
|
|
281
280
|
removeGroup(group) {
|
|
282
281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
if (this.
|
|
282
|
+
if (this.payload.groups != null) {
|
|
284
283
|
let groupObject = undefined;
|
|
285
284
|
if (group instanceof Group) {
|
|
286
285
|
groupObject = group;
|
|
@@ -289,10 +288,10 @@ export class Account {
|
|
|
289
288
|
groupObject = yield this.book.getGroup(group);
|
|
290
289
|
}
|
|
291
290
|
if (groupObject) {
|
|
292
|
-
for (let i = 0; i < this.
|
|
293
|
-
const groupId = this.
|
|
291
|
+
for (let i = 0; i < this.payload.groups.length; i++) {
|
|
292
|
+
const groupId = this.payload.groups[i];
|
|
294
293
|
if (groupId == groupObject.getId()) {
|
|
295
|
-
this.
|
|
294
|
+
this.payload.groups.splice(i, 1);
|
|
296
295
|
}
|
|
297
296
|
}
|
|
298
297
|
}
|
|
@@ -324,11 +323,11 @@ export class Account {
|
|
|
324
323
|
}
|
|
325
324
|
/** @internal */
|
|
326
325
|
isInGroupObject_(group) {
|
|
327
|
-
if (this.
|
|
326
|
+
if (this.payload.groups == null) {
|
|
328
327
|
return false;
|
|
329
328
|
}
|
|
330
|
-
for (var i = 0; i < this.
|
|
331
|
-
if (this.
|
|
329
|
+
for (var i = 0; i < this.payload.groups.length; i++) {
|
|
330
|
+
if (this.payload.groups[i] == group.getId()) {
|
|
332
331
|
return true;
|
|
333
332
|
}
|
|
334
333
|
}
|
|
@@ -339,7 +338,8 @@ export class Account {
|
|
|
339
338
|
*/
|
|
340
339
|
create() {
|
|
341
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
-
this.
|
|
341
|
+
this.payload = yield AccountService.createAccount(this.book.getId(), this.payload);
|
|
342
|
+
this.book.updateAccountCache(this);
|
|
343
343
|
return this;
|
|
344
344
|
});
|
|
345
345
|
}
|
|
@@ -348,7 +348,8 @@ export class Account {
|
|
|
348
348
|
*/
|
|
349
349
|
update() {
|
|
350
350
|
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
-
this.
|
|
351
|
+
this.payload = yield AccountService.updateAccount(this.book.getId(), this.payload);
|
|
352
|
+
this.book.updateAccountCache(this);
|
|
352
353
|
return this;
|
|
353
354
|
});
|
|
354
355
|
}
|
|
@@ -357,7 +358,8 @@ export class Account {
|
|
|
357
358
|
*/
|
|
358
359
|
remove() {
|
|
359
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
-
this.
|
|
361
|
+
this.payload = yield AccountService.deleteAccount(this.book.getId(), this.payload);
|
|
362
|
+
this.book.removeAccountCache(this);
|
|
361
363
|
return this;
|
|
362
364
|
});
|
|
363
365
|
}
|