bkper-js 1.8.0 → 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.
@@ -21,16 +21,17 @@ import { Amount } from './Amount.js';
21
21
  * @public
22
22
  */
23
23
  export class Transaction {
24
- constructor(book, json) {
24
+ constructor(book, payload) {
25
25
  this.book = book;
26
- this.wrapped = json || {};
26
+ this.payload = payload || {
27
+ createdAt: `${Date.now()}`
28
+ };
27
29
  }
28
30
  /**
29
- *
30
- * @returns The wrapped plain json object
31
+ * @returns An immutable copy of the json payload
31
32
  */
32
33
  json() {
33
- return this.wrapped;
34
+ return Object.assign({}, this.payload);
34
35
  }
35
36
  /**
36
37
  * @returns The book of the Transaction.
@@ -42,13 +43,13 @@ export class Transaction {
42
43
  * @returns The id of the Transaction.
43
44
  */
44
45
  getId() {
45
- return this.wrapped.id;
46
+ return this.payload.id;
46
47
  }
47
48
  /**
48
49
  * @returns The id of the agent that created this transaction
49
50
  */
50
51
  getAgentId() {
51
- return this.wrapped.agentId;
52
+ return this.payload.agentId;
52
53
  }
53
54
  /**
54
55
  * Remote ids are used to avoid duplication.
@@ -56,7 +57,7 @@ export class Transaction {
56
57
  * @returns The remote ids of the Transaction.
57
58
  */
58
59
  getRemoteIds() {
59
- return this.wrapped.remoteIds || [];
60
+ return this.payload.remoteIds || [];
60
61
  }
61
62
  /**
62
63
  * Add a remote id to the Transaction.
@@ -66,11 +67,11 @@ export class Transaction {
66
67
  * @returns This Transaction, for chainning.
67
68
  */
68
69
  addRemoteId(remoteId) {
69
- if (this.wrapped.remoteIds == null) {
70
- this.wrapped.remoteIds = [];
70
+ if (this.payload.remoteIds == null) {
71
+ this.payload.remoteIds = [];
71
72
  }
72
73
  if (remoteId) {
73
- this.wrapped.remoteIds.push(remoteId);
74
+ this.payload.remoteIds.push(remoteId);
74
75
  }
75
76
  return this;
76
77
  }
@@ -78,13 +79,13 @@ export class Transaction {
78
79
  * @returns True if transaction was already posted to the accounts. False if is still a Draft.
79
80
  */
80
81
  isPosted() {
81
- return this.wrapped.posted;
82
+ return this.payload.posted;
82
83
  }
83
84
  /**
84
85
  * @returns True if transaction is checked.
85
86
  */
86
87
  isChecked() {
87
- return this.wrapped.checked;
88
+ return this.payload.checked;
88
89
  }
89
90
  /**
90
91
  * Set the check state of the Transaction.
@@ -94,26 +95,26 @@ export class Transaction {
94
95
  * @returns This Transaction, for chainning.
95
96
  */
96
97
  setChecked(checked) {
97
- this.wrapped.checked = checked;
98
+ this.payload.checked = checked;
98
99
  return this;
99
100
  }
100
101
  /**
101
102
  * @returns True if transaction is in trash.
102
103
  */
103
104
  isTrashed() {
104
- return this.wrapped.trashed;
105
+ return this.payload.trashed;
105
106
  }
106
107
  /**
107
108
  * @returns All #hashtags used on the transaction.
108
109
  */
109
110
  getTags() {
110
- return this.wrapped.tags || [];
111
+ return this.payload.tags || [];
111
112
  }
112
113
  /**
113
114
  * @returns All urls of the transaction.
114
115
  */
115
116
  getUrls() {
116
- return this.wrapped.urls || [];
117
+ return this.payload.urls || [];
117
118
  }
118
119
  /**
119
120
  * Sets the Transaction urls. Url starts with https://
@@ -123,7 +124,7 @@ export class Transaction {
123
124
  * @returns This Transaction, for chainning.
124
125
  */
125
126
  setUrls(urls) {
126
- this.wrapped.urls = undefined;
127
+ this.payload.urls = undefined;
127
128
  if (urls) {
128
129
  urls.forEach(url => {
129
130
  this.addUrl(url);
@@ -139,11 +140,11 @@ export class Transaction {
139
140
  * @returns This Transaction, for chainning.
140
141
  */
141
142
  addUrl(url) {
142
- if (this.wrapped.urls == null) {
143
- this.wrapped.urls = [];
143
+ if (this.payload.urls == null) {
144
+ this.payload.urls = [];
144
145
  }
145
146
  if (url) {
146
- this.wrapped.urls.push(url);
147
+ this.payload.urls.push(url);
147
148
  }
148
149
  return this;
149
150
  }
@@ -151,8 +152,8 @@ export class Transaction {
151
152
  * @returns The files attached to the transaction.
152
153
  */
153
154
  getFiles() {
154
- if (this.wrapped.files && this.wrapped.files.length > 0) {
155
- const files = this.wrapped.files.map(file => new File(this.book, file));
155
+ if (this.payload.files && this.payload.files.length > 0) {
156
+ const files = this.payload.files.map(file => new File(this.book, file));
156
157
  return files;
157
158
  }
158
159
  else {
@@ -171,14 +172,14 @@ export class Transaction {
171
172
  */
172
173
  addFile(file) {
173
174
  return __awaiter(this, void 0, void 0, function* () {
174
- if (this.wrapped.files == null) {
175
- this.wrapped.files = [];
175
+ if (this.payload.files == null) {
176
+ this.payload.files = [];
176
177
  }
177
178
  //Make sure file is already created
178
179
  if (file.getId() == null) {
179
180
  file = yield file.create();
180
181
  }
181
- this.wrapped.files.push(file.json());
182
+ this.payload.files.push(file.json());
182
183
  return this;
183
184
  });
184
185
  }
@@ -198,7 +199,7 @@ export class Transaction {
198
199
  * Gets the custom properties stored in this Transaction.
199
200
  */
200
201
  getProperties() {
201
- return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
202
+ return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
202
203
  }
203
204
  /**
204
205
  * Sets the custom properties of the Transaction
@@ -208,7 +209,7 @@ export class Transaction {
208
209
  * @returns This Transaction, for chainning.
209
210
  */
210
211
  setProperties(properties) {
211
- this.wrapped.properties = Object.assign({}, properties);
212
+ this.payload.properties = Object.assign({}, properties);
212
213
  return this;
213
214
  }
214
215
  /**
@@ -219,7 +220,7 @@ export class Transaction {
219
220
  getProperty(...keys) {
220
221
  for (let index = 0; index < keys.length; index++) {
221
222
  const key = keys[index];
222
- let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
223
+ let value = this.payload.properties != null ? this.payload.properties[key] : null;
223
224
  if (value != null && value.trim() != '') {
224
225
  return value;
225
226
  }
@@ -254,13 +255,13 @@ export class Transaction {
254
255
  if (key == null || key.trim() == '') {
255
256
  return this;
256
257
  }
257
- if (this.wrapped.properties == null) {
258
- this.wrapped.properties = {};
258
+ if (this.payload.properties == null) {
259
+ this.payload.properties = {};
259
260
  }
260
261
  if (!value) {
261
262
  value = '';
262
263
  }
263
- this.wrapped.properties[key] = value;
264
+ this.payload.properties[key] = value;
264
265
  return this;
265
266
  }
266
267
  /**
@@ -280,10 +281,10 @@ export class Transaction {
280
281
  */
281
282
  getCreditAccount() {
282
283
  return __awaiter(this, void 0, void 0, function* () {
283
- if (!this.wrapped.creditAccount) {
284
+ if (!this.payload.creditAccount) {
284
285
  return undefined;
285
286
  }
286
- return yield this.book.getAccount(this.wrapped.creditAccount.id);
287
+ return yield this.book.getAccount(this.payload.creditAccount.id);
287
288
  });
288
289
  }
289
290
  /**
@@ -311,12 +312,12 @@ export class Transaction {
311
312
  setCreditAccount(account) {
312
313
  if (account instanceof Account) {
313
314
  if (account != null && account.getId() != null) {
314
- this.wrapped.creditAccount = account.json();
315
+ this.payload.creditAccount = account.json();
315
316
  }
316
317
  }
317
318
  else {
318
319
  if (account != null && account.id != null) {
319
- this.wrapped.creditAccount = account;
320
+ this.payload.creditAccount = account;
320
321
  }
321
322
  }
322
323
  return this;
@@ -339,10 +340,10 @@ export class Transaction {
339
340
  */
340
341
  getDebitAccount() {
341
342
  return __awaiter(this, void 0, void 0, function* () {
342
- if (!this.wrapped.debitAccount) {
343
+ if (!this.payload.debitAccount) {
343
344
  return undefined;
344
345
  }
345
- return yield this.book.getAccount(this.wrapped.debitAccount.id);
346
+ return yield this.book.getAccount(this.payload.debitAccount.id);
346
347
  });
347
348
  }
348
349
  /**
@@ -370,12 +371,12 @@ export class Transaction {
370
371
  setDebitAccount(account) {
371
372
  if (account instanceof Account) {
372
373
  if (account != null && account.getId() != null) {
373
- this.wrapped.debitAccount = account.json();
374
+ this.payload.debitAccount = account.json();
374
375
  }
375
376
  }
376
377
  else {
377
378
  if (account != null && account.id != null) {
378
- this.wrapped.debitAccount = account;
379
+ this.payload.debitAccount = account;
379
380
  }
380
381
  }
381
382
  return this;
@@ -396,7 +397,7 @@ export class Transaction {
396
397
  * @returns The amount of the transaction.
397
398
  */
398
399
  getAmount() {
399
- return this.wrapped.amount != null && this.wrapped.amount.trim() != '' ? new Amount(this.wrapped.amount) : undefined;
400
+ return this.payload.amount != null && this.payload.amount.trim() != '' ? new Amount(this.payload.amount) : undefined;
400
401
  }
401
402
  /**
402
403
  *
@@ -407,15 +408,15 @@ export class Transaction {
407
408
  setAmount(amount) {
408
409
  if (typeof amount == "string") {
409
410
  amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) + '';
410
- this.wrapped.amount = amount.toString();
411
+ this.payload.amount = amount.toString();
411
412
  return this;
412
413
  }
413
414
  amount = new Amount(amount);
414
415
  if (amount.eq(0)) {
415
- this.wrapped.amount = undefined;
416
+ this.payload.amount = undefined;
416
417
  return this;
417
418
  }
418
- this.wrapped.amount = amount.abs().toString();
419
+ this.payload.amount = amount.abs().toString();
419
420
  return this;
420
421
  }
421
422
  /**
@@ -518,10 +519,10 @@ export class Transaction {
518
519
  * @returns The description of this transaction.
519
520
  */
520
521
  getDescription() {
521
- if (this.wrapped.description == null) {
522
+ if (this.payload.description == null) {
522
523
  return "";
523
524
  }
524
- return this.wrapped.description;
525
+ return this.payload.description;
525
526
  }
526
527
  /**
527
528
  *
@@ -530,7 +531,7 @@ export class Transaction {
530
531
  * @returns This Transaction, for chainning.
531
532
  */
532
533
  setDescription(description) {
533
- this.wrapped.description = description;
534
+ this.payload.description = description;
534
535
  return this;
535
536
  }
536
537
  //DATE
@@ -538,7 +539,7 @@ export class Transaction {
538
539
  * @returns The Transaction date, in ISO format yyyy-MM-dd.
539
540
  */
540
541
  getDate() {
541
- return this.wrapped.date;
542
+ return this.payload.date;
542
543
  }
543
544
  /**
544
545
  *
@@ -550,14 +551,14 @@ export class Transaction {
550
551
  if (typeof date == "string") {
551
552
  if (date.indexOf('/') > 0) {
552
553
  let dateObject = Utils.parseDate(date, this.book.getDatePattern(), this.book.getTimeZone());
553
- this.wrapped.date = Utils.formatDateISO(dateObject, this.book.getTimeZone());
554
+ this.payload.date = Utils.formatDateISO(dateObject, this.book.getTimeZone());
554
555
  }
555
556
  else if (date.indexOf('-')) {
556
- this.wrapped.date = date;
557
+ this.payload.date = date;
557
558
  }
558
559
  }
559
560
  else if (Object.prototype.toString.call(date) === '[object Date]') {
560
- this.wrapped.date = Utils.formatDateISO(date, this.book.getTimeZone());
561
+ this.payload.date = Utils.formatDateISO(date, this.book.getTimeZone());
561
562
  }
562
563
  return this;
563
564
  }
@@ -571,19 +572,19 @@ export class Transaction {
571
572
  * @returns The Transaction date number, in format YYYYMMDD.
572
573
  */
573
574
  getDateValue() {
574
- return this.wrapped.dateValue;
575
+ return this.payload.dateValue;
575
576
  }
576
577
  /**
577
578
  * @returns The Transaction date, formatted on the date pattern of the [[Book]].
578
579
  */
579
580
  getDateFormatted() {
580
- return this.wrapped.dateFormatted;
581
+ return this.payload.dateFormatted;
581
582
  }
582
583
  /**
583
584
  * @returns The date the transaction was created.
584
585
  */
585
586
  getCreatedAt() {
586
- return new Date(new Number(this.wrapped.createdAt).valueOf());
587
+ return new Date(new Number(this.payload.createdAt).valueOf());
587
588
  }
588
589
  /**
589
590
  * @returns The date the transaction was created, formatted according to the date pattern of [[Book]].
@@ -594,11 +595,11 @@ export class Transaction {
594
595
  //EVOLVED BALANCES
595
596
  /** @internal */
596
597
  getCaEvolvedBalance_() {
597
- return this.wrapped.creditAccount != null && this.wrapped.creditAccount.balance != null ? new Amount(this.wrapped.creditAccount.balance) : undefined;
598
+ return this.payload.creditAccount != null && this.payload.creditAccount.balance != null ? new Amount(this.payload.creditAccount.balance) : undefined;
598
599
  }
599
600
  /** @internal */
600
601
  getDaEvolvedBalance_() {
601
- return this.wrapped.debitAccount != null && this.wrapped.debitAccount.balance != null ? new Amount(this.wrapped.debitAccount.balance) : undefined;
602
+ return this.payload.debitAccount != null && this.payload.debitAccount.balance != null ? new Amount(this.payload.debitAccount.balance) : undefined;
602
603
  }
603
604
  /**
604
605
  * Gets the balance that the [[Account]] has at that day, when listing transactions of that Account.
@@ -634,8 +635,8 @@ export class Transaction {
634
635
  */
635
636
  create() {
636
637
  return __awaiter(this, void 0, void 0, function* () {
637
- let operation = yield TransactionService.createTransaction(this.book.getId(), this.wrapped);
638
- this.wrapped = operation.transaction || {};
638
+ let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload);
639
+ this.payload = operation.transaction || {};
639
640
  return this;
640
641
  });
641
642
  }
@@ -644,8 +645,8 @@ export class Transaction {
644
645
  */
645
646
  update() {
646
647
  return __awaiter(this, void 0, void 0, function* () {
647
- let operation = yield TransactionService.updateTransaction(this.book.getId(), this.wrapped);
648
- this.wrapped = operation.transaction || {};
648
+ let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload);
649
+ this.payload = operation.transaction || {};
649
650
  return this;
650
651
  });
651
652
  }
@@ -655,8 +656,8 @@ export class Transaction {
655
656
  check() {
656
657
  return __awaiter(this, void 0, void 0, function* () {
657
658
  var _a;
658
- let operation = yield TransactionService.checkTransaction(this.book.getId(), this.wrapped);
659
- this.wrapped.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
659
+ let operation = yield TransactionService.checkTransaction(this.book.getId(), this.payload);
660
+ this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
660
661
  return this;
661
662
  });
662
663
  }
@@ -666,8 +667,8 @@ export class Transaction {
666
667
  uncheck() {
667
668
  return __awaiter(this, void 0, void 0, function* () {
668
669
  var _a;
669
- let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.wrapped);
670
- this.wrapped.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
670
+ let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.payload);
671
+ this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
671
672
  return this;
672
673
  });
673
674
  }
@@ -676,8 +677,8 @@ export class Transaction {
676
677
  */
677
678
  post() {
678
679
  return __awaiter(this, void 0, void 0, function* () {
679
- let operation = yield TransactionService.postTransaction(this.book.getId(), this.wrapped);
680
- this.wrapped = operation.transaction || {};
680
+ let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload);
681
+ this.payload = operation.transaction || {};
681
682
  return this;
682
683
  });
683
684
  }
@@ -687,8 +688,8 @@ export class Transaction {
687
688
  remove() {
688
689
  return __awaiter(this, void 0, void 0, function* () {
689
690
  var _a;
690
- let operation = yield TransactionService.trashTransaction(this.book.getId(), this.wrapped);
691
- this.wrapped.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
691
+ let operation = yield TransactionService.trashTransaction(this.book.getId(), this.payload);
692
+ this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
692
693
  return this;
693
694
  });
694
695
  }
@@ -698,8 +699,8 @@ export class Transaction {
698
699
  restore() {
699
700
  return __awaiter(this, void 0, void 0, function* () {
700
701
  var _a;
701
- let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.wrapped);
702
- this.wrapped.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
702
+ let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.payload);
703
+ this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
703
704
  return this;
704
705
  });
705
706
  }
@@ -12,25 +12,25 @@ import { Transaction } from "./Transaction.js";
12
12
  * A list associated with a transaction query.
13
13
  */
14
14
  export class TransactionList {
15
- constructor(book, transactionList) {
15
+ constructor(book, payload) {
16
16
  this.book = book;
17
- this.wrapped = transactionList;
17
+ this.payload = payload;
18
18
  }
19
19
  /**
20
20
  * @returns The cursor associated with the query for pagination.
21
21
  */
22
22
  getCursor() {
23
- return this.wrapped.cursor;
23
+ return this.payload.cursor;
24
24
  }
25
25
  /**
26
26
  * Retrieves the account associated with the query, when filtering by account.
27
27
  */
28
28
  getAccount() {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- if (!this.wrapped.account) {
30
+ if (!this.payload.account) {
31
31
  return undefined;
32
32
  }
33
- return yield this.book.getAccount(this.wrapped.account);
33
+ return yield this.book.getAccount(this.payload.account);
34
34
  });
35
35
  }
36
36
  /**
@@ -48,7 +48,7 @@ export class TransactionList {
48
48
  */
49
49
  size() {
50
50
  var _a;
51
- return ((_a = this.wrapped.items) === null || _a === void 0 ? void 0 : _a.length) || 0;
51
+ return ((_a = this.payload.items) === null || _a === void 0 ? void 0 : _a.length) || 0;
52
52
  }
53
53
  /**
54
54
  * Get the transactions in the list.
@@ -58,7 +58,7 @@ export class TransactionList {
58
58
  getItems() {
59
59
  var _a;
60
60
  let transactions = [];
61
- for (let transaction of (_a = this.wrapped.items) !== null && _a !== void 0 ? _a : []) {
61
+ for (let transaction of (_a = this.payload.items) !== null && _a !== void 0 ? _a : []) {
62
62
  transactions.push(new Transaction(this.book, transaction));
63
63
  }
64
64
  return transactions;
package/lib/model/User.js CHANGED
@@ -15,16 +15,15 @@ import * as ConnectionService from '../service/connection-service.js';
15
15
  * @public
16
16
  */
17
17
  export class User {
18
- constructor(json) {
19
- /** @internal */
20
- this.wrapped = {};
21
- this.wrapped = json || {};
18
+ constructor(payload) {
19
+ this.payload = {};
20
+ this.payload = payload || {};
22
21
  }
23
22
  /**
24
- * @returns The wrapped plain json object
23
+ * @returns An immutable copy of the json payload
25
24
  */
26
25
  json() {
27
- return this.wrapped;
26
+ return Object.assign({}, this.payload);
28
27
  }
29
28
  /**
30
29
  * Gets the id of the User.
@@ -32,7 +31,7 @@ export class User {
32
31
  * @returns The User's id
33
32
  */
34
33
  getId() {
35
- return this.wrapped.id;
34
+ return this.payload.id;
36
35
  }
37
36
  /**
38
37
  * Gets the name of the User.
@@ -40,7 +39,7 @@ export class User {
40
39
  * @returns The User's name
41
40
  */
42
41
  getName() {
43
- return this.wrapped.name;
42
+ return this.payload.name;
44
43
  }
45
44
  /**
46
45
  * Gets the full name of the User.
@@ -48,7 +47,7 @@ export class User {
48
47
  * @returns The User's full name
49
48
  */
50
49
  getFullName() {
51
- return this.wrapped.fullName;
50
+ return this.payload.fullName;
52
51
  }
53
52
  /**
54
53
  * Gets the email of the User.
@@ -56,7 +55,7 @@ export class User {
56
55
  * @returns The User's email
57
56
  */
58
57
  getEmail() {
59
- return this.wrapped.email;
58
+ return this.payload.email;
60
59
  }
61
60
  /**
62
61
  * Gets the hosted domain of the User.
@@ -64,7 +63,7 @@ export class User {
64
63
  * @returns The User's hosted domain
65
64
  */
66
65
  getHostedDomain() {
67
- return this.wrapped.hostedDomain;
66
+ return this.payload.hostedDomain;
68
67
  }
69
68
  /**
70
69
  * Tells if the User is in the free plan.
@@ -72,7 +71,7 @@ export class User {
72
71
  * @returns True if the User is in the free plan
73
72
  */
74
73
  isFree() {
75
- return this.wrapped.free;
74
+ return this.payload.free;
76
75
  }
77
76
  /**
78
77
  * Tells if the User has started the trial.
@@ -80,7 +79,7 @@ export class User {
80
79
  * @returns True if the User has started the trial
81
80
  */
82
81
  hasStartedTrial() {
83
- return this.wrapped.startedTrial;
82
+ return this.payload.startedTrial;
84
83
  }
85
84
  /**
86
85
  * Gets the days left in User's trial.
@@ -88,7 +87,7 @@ export class User {
88
87
  * @returns The User's days left in trial
89
88
  */
90
89
  getDaysLeftInTrial() {
91
- return this.wrapped.daysLeftInTrial;
90
+ return this.payload.daysLeftInTrial;
92
91
  }
93
92
  /**
94
93
  * Tells if the User has already used [[Connections]].
@@ -96,7 +95,7 @@ export class User {
96
95
  * @returns True if the User has already used Connections
97
96
  */
98
97
  hasUsedConnections() {
99
- return this.wrapped.bankConnections;
98
+ return this.payload.bankConnections;
100
99
  }
101
100
  /**
102
101
  * Gets the [[Connections]] of the User.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",