bkper-js 2.7.1 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/lib/index.d.ts +172 -99
- package/lib/model/Account.js +20 -21
- package/lib/model/App.js +72 -21
- package/lib/model/Bkper.js +42 -30
- package/lib/model/Book.js +109 -99
- package/lib/model/BotResponse.js +2 -2
- package/lib/model/Collaborator.js +12 -11
- package/lib/model/Collection.js +24 -19
- package/lib/model/Connection.js +28 -18
- package/lib/model/Conversation.js +20 -13
- package/lib/model/File.js +19 -17
- package/lib/model/Group.js +29 -21
- package/lib/model/Integration.js +17 -13
- package/lib/model/Message.js +20 -16
- package/lib/model/Query.js +12 -11
- package/lib/model/Resource.js +23 -0
- package/lib/model/Template.js +10 -7
- package/lib/model/Transaction.js +61 -43
- package/lib/model/User.js +14 -12
- package/lib/service/account-service.js +12 -12
- package/lib/service/app-service.js +8 -8
- package/lib/service/balances-service.js +2 -2
- package/lib/service/book-service.js +14 -14
- package/lib/service/collaborator-service.js +6 -6
- package/lib/service/collection-service.js +12 -12
- package/lib/service/connection-service.js +12 -15
- package/lib/service/conversation-service.js +10 -10
- package/lib/service/event-service.js +8 -8
- package/lib/service/file-service.js +4 -4
- package/lib/service/group-service.js +16 -16
- package/lib/service/http-api-request.js +54 -45
- package/lib/service/integration-service.js +8 -8
- package/lib/service/query-service.js +8 -8
- package/lib/service/template-service.js +2 -2
- package/lib/service/transaction-service.js +32 -32
- package/lib/service/user-service.js +4 -4
- package/package.json +1 -1
package/lib/model/Message.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import * as ConversationService from "../service/conversation-service.js";
|
|
11
11
|
import { Agent } from "./Agent.js";
|
|
12
12
|
import { User } from "./User.js";
|
|
13
|
+
import { Resource } from "./Resource.js";
|
|
13
14
|
/**
|
|
14
15
|
* Defines a Message on Bkper.
|
|
15
16
|
*
|
|
@@ -17,18 +18,18 @@ import { User } from "./User.js";
|
|
|
17
18
|
*
|
|
18
19
|
* @public
|
|
19
20
|
*/
|
|
20
|
-
export class Message {
|
|
21
|
-
constructor(conversation, payload) {
|
|
21
|
+
export class Message extends Resource {
|
|
22
|
+
constructor(conversation, payload, config) {
|
|
23
|
+
super(payload || {});
|
|
22
24
|
this.conversation = conversation;
|
|
23
|
-
this.payload = payload || {};
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* Gets the
|
|
27
|
+
* Gets the configuration object for this Message.
|
|
27
28
|
*
|
|
28
|
-
* @returns The
|
|
29
|
+
* @returns The Config object from the parent Conversation
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
return
|
|
31
|
+
getConfig() {
|
|
32
|
+
return this.conversation.getConfig();
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Gets the Message universal identifier.
|
|
@@ -68,7 +69,9 @@ export class Message {
|
|
|
68
69
|
* @returns The Date the Message was created
|
|
69
70
|
*/
|
|
70
71
|
getCreatedAt() {
|
|
71
|
-
return this.payload.createdAt
|
|
72
|
+
return this.payload.createdAt
|
|
73
|
+
? new Date(new Number(this.payload.createdAt).valueOf())
|
|
74
|
+
: undefined;
|
|
72
75
|
}
|
|
73
76
|
/**
|
|
74
77
|
* Gets the text content of the Message.
|
|
@@ -95,7 +98,8 @@ export class Message {
|
|
|
95
98
|
* @returns The custom properties stored in this Message
|
|
96
99
|
*/
|
|
97
100
|
getProperties() {
|
|
98
|
-
return this.payload.properties != null
|
|
101
|
+
return this.payload.properties != null
|
|
102
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
99
103
|
}
|
|
100
104
|
/**
|
|
101
105
|
* Sets the custom properties of the Message
|
|
@@ -119,7 +123,7 @@ export class Message {
|
|
|
119
123
|
for (let index = 0; index < keys.length; index++) {
|
|
120
124
|
const key = keys[index];
|
|
121
125
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
122
|
-
if (value != null && value.trim() !=
|
|
126
|
+
if (value != null && value.trim() != "") {
|
|
123
127
|
return value;
|
|
124
128
|
}
|
|
125
129
|
}
|
|
@@ -134,14 +138,14 @@ export class Message {
|
|
|
134
138
|
* @returns This Message, for chaining
|
|
135
139
|
*/
|
|
136
140
|
setProperty(key, value) {
|
|
137
|
-
if (key == null || key.trim() ==
|
|
141
|
+
if (key == null || key.trim() == "") {
|
|
138
142
|
return this;
|
|
139
143
|
}
|
|
140
144
|
if (this.payload.properties == null) {
|
|
141
145
|
this.payload.properties = {};
|
|
142
146
|
}
|
|
143
147
|
if (!value) {
|
|
144
|
-
value =
|
|
148
|
+
value = "";
|
|
145
149
|
}
|
|
146
150
|
this.payload.properties[key] = value;
|
|
147
151
|
return this;
|
|
@@ -166,9 +170,9 @@ export class Message {
|
|
|
166
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
171
|
const conversationId = this.conversation.getId();
|
|
168
172
|
if (!conversationId) {
|
|
169
|
-
throw new Error(
|
|
173
|
+
throw new Error("Conversation id null!");
|
|
170
174
|
}
|
|
171
|
-
const responsePayload = yield ConversationService.createMessage(conversationId, this.payload);
|
|
175
|
+
const responsePayload = yield ConversationService.createMessage(conversationId, this.payload, this.getConfig());
|
|
172
176
|
if (responsePayload.parent) {
|
|
173
177
|
this.payload = responsePayload.parent;
|
|
174
178
|
}
|
|
@@ -191,9 +195,9 @@ export class Message {
|
|
|
191
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
196
|
const conversationId = this.conversation.getId();
|
|
193
197
|
if (!conversationId) {
|
|
194
|
-
throw new Error(
|
|
198
|
+
throw new Error("Conversation id null!");
|
|
195
199
|
}
|
|
196
|
-
ConversationService.streamMessage(conversationId, this.payload);
|
|
200
|
+
ConversationService.streamMessage(conversationId, this.payload, this.getConfig());
|
|
197
201
|
});
|
|
198
202
|
}
|
|
199
203
|
}
|
package/lib/model/Query.js
CHANGED
|
@@ -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 QueryService from
|
|
10
|
+
import * as QueryService from "../service/query-service.js";
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
11
12
|
/**
|
|
12
13
|
* Defines a saved Query in a [[Book]].
|
|
13
14
|
*
|
|
@@ -15,18 +16,18 @@ import * as QueryService from '../service/query-service.js';
|
|
|
15
16
|
*
|
|
16
17
|
* @public
|
|
17
18
|
*/
|
|
18
|
-
export class Query {
|
|
19
|
+
export class Query extends Resource {
|
|
19
20
|
constructor(book, payload) {
|
|
21
|
+
super(payload);
|
|
20
22
|
this.book = book;
|
|
21
|
-
this.payload = payload || {};
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
|
-
* Gets the
|
|
25
|
+
* Gets the configuration object for this Query.
|
|
25
26
|
*
|
|
26
|
-
* @returns The
|
|
27
|
+
* @returns The Config object from the parent Book
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
-
return
|
|
29
|
+
getConfig() {
|
|
30
|
+
return this.book.getConfig();
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* Gets the Query universal identifier.
|
|
@@ -81,7 +82,7 @@ export class Query {
|
|
|
81
82
|
*/
|
|
82
83
|
create() {
|
|
83
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
this.payload = yield QueryService.createSavedQuery(this.book.getId(), this.payload);
|
|
85
|
+
this.payload = yield QueryService.createSavedQuery(this.book.getId(), this.payload, this.getConfig());
|
|
85
86
|
this.updateQueryCache();
|
|
86
87
|
return this;
|
|
87
88
|
});
|
|
@@ -93,7 +94,7 @@ export class Query {
|
|
|
93
94
|
*/
|
|
94
95
|
update() {
|
|
95
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.payload = yield QueryService.updateSavedQuery(this.book.getId(), this.payload);
|
|
97
|
+
this.payload = yield QueryService.updateSavedQuery(this.book.getId(), this.payload, this.getConfig());
|
|
97
98
|
this.updateQueryCache();
|
|
98
99
|
return this;
|
|
99
100
|
});
|
|
@@ -109,7 +110,7 @@ export class Query {
|
|
|
109
110
|
if (!queryId) {
|
|
110
111
|
throw new Error("Query id null!");
|
|
111
112
|
}
|
|
112
|
-
this.payload = yield QueryService.deleteSavedQuery(this.book.getId(), queryId);
|
|
113
|
+
this.payload = yield QueryService.deleteSavedQuery(this.book.getId(), queryId, this.getConfig());
|
|
113
114
|
this.updateQueryCache(true);
|
|
114
115
|
return this;
|
|
115
116
|
});
|
|
@@ -117,7 +118,7 @@ export class Query {
|
|
|
117
118
|
/** @internal */
|
|
118
119
|
updateQueryCache(deleted) {
|
|
119
120
|
if (this.book.queries) {
|
|
120
|
-
this.book.queries = this.book.queries.filter(q => q.getId() !== this.getId());
|
|
121
|
+
this.book.queries = this.book.queries.filter((q) => q.getId() !== this.getId());
|
|
121
122
|
if (!deleted) {
|
|
122
123
|
this.book.queries.push(this);
|
|
123
124
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for all Bkper resources.
|
|
3
|
+
* Provides common functionality for config management and JSON serialization.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class Resource {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new Resource
|
|
10
|
+
* @param payload - The data payload for this resource
|
|
11
|
+
*/
|
|
12
|
+
constructor(payload) {
|
|
13
|
+
this.payload = payload || {};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets an immutable copy of the JSON payload for this resource.
|
|
17
|
+
* @returns An immutable copy of the json payload
|
|
18
|
+
*/
|
|
19
|
+
json() {
|
|
20
|
+
return Object.assign({}, this.payload);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Resource.js.map
|
package/lib/model/Template.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Resource } from "./Resource.js";
|
|
2
|
+
import { Bkper } from "./Bkper.js";
|
|
1
3
|
/**
|
|
2
4
|
* This class defines a Template.
|
|
3
5
|
*
|
|
@@ -5,17 +7,18 @@
|
|
|
5
7
|
*
|
|
6
8
|
* @public
|
|
7
9
|
*/
|
|
8
|
-
export class Template {
|
|
9
|
-
constructor(json) {
|
|
10
|
-
|
|
10
|
+
export class Template extends Resource {
|
|
11
|
+
constructor(json, config) {
|
|
12
|
+
super(json);
|
|
13
|
+
this.config = config;
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
|
-
* Gets
|
|
16
|
+
* Gets the configuration object for this Template.
|
|
14
17
|
*
|
|
15
|
-
* @returns
|
|
18
|
+
* @returns The Config object for this Template or the global config
|
|
16
19
|
*/
|
|
17
|
-
|
|
18
|
-
return
|
|
20
|
+
getConfig() {
|
|
21
|
+
return this.config || Bkper.globalConfig;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Gets the name of the Template.
|
package/lib/model/Transaction.js
CHANGED
|
@@ -9,9 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { File } from "./File.js";
|
|
11
11
|
import { Account } from "./Account.js";
|
|
12
|
-
import
|
|
13
|
-
import * as
|
|
14
|
-
import
|
|
12
|
+
import { Resource } from "./Resource.js";
|
|
13
|
+
import * as TransactionService from "../service/transaction-service.js";
|
|
14
|
+
import * as Utils from "../utils.js";
|
|
15
|
+
import { Amount } from "./Amount.js";
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
18
|
* This class defines a Transaction between [credit and debit](http://en.wikipedia.org/wiki/Debits_and_credits) [[Accounts]].
|
|
@@ -20,20 +21,18 @@ import { Amount } from './Amount.js';
|
|
|
20
21
|
*
|
|
21
22
|
* @public
|
|
22
23
|
*/
|
|
23
|
-
export class Transaction {
|
|
24
|
+
export class Transaction extends Resource {
|
|
24
25
|
constructor(book, payload) {
|
|
26
|
+
super(payload || { createdAt: `${Date.now()}` });
|
|
25
27
|
this.book = book;
|
|
26
|
-
this.payload = payload || {
|
|
27
|
-
createdAt: `${Date.now()}`
|
|
28
|
-
};
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
|
-
* Gets the
|
|
30
|
+
* Gets the configuration object for this Transaction.
|
|
32
31
|
*
|
|
33
|
-
* @returns
|
|
32
|
+
* @returns The Config object from the parent Book
|
|
34
33
|
*/
|
|
35
|
-
|
|
36
|
-
return
|
|
34
|
+
getConfig() {
|
|
35
|
+
return this.book.getConfig();
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Gets the book associated with this transaction.
|
|
@@ -124,12 +123,12 @@ export class Transaction {
|
|
|
124
123
|
return this.payload.checked;
|
|
125
124
|
}
|
|
126
125
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
* Set the check state of the Transaction.
|
|
127
|
+
*
|
|
128
|
+
* @param checked - The check state
|
|
129
|
+
*
|
|
130
|
+
* @returns This Transaction, for chaining
|
|
131
|
+
*/
|
|
133
132
|
setChecked(checked) {
|
|
134
133
|
this.payload.checked = checked;
|
|
135
134
|
return this;
|
|
@@ -148,9 +147,11 @@ export class Transaction {
|
|
|
148
147
|
* @returns True if a transaction is locked by the book lock/closing date
|
|
149
148
|
*/
|
|
150
149
|
isLocked() {
|
|
151
|
-
const date = this.getDate() ||
|
|
150
|
+
const date = this.getDate() ||
|
|
151
|
+
Utils.formatDateISO(new Date(), this.book.getTimeZone());
|
|
152
152
|
const lockOrClosingDate = this.book.getMostRecentLockDate_();
|
|
153
|
-
return lockOrClosingDate != null &&
|
|
153
|
+
return (lockOrClosingDate != null &&
|
|
154
|
+
Utils.getIsoDateValue(lockOrClosingDate) >= Utils.getIsoDateValue(date));
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
156
157
|
* Gets all hashtags used in the transaction.
|
|
@@ -178,7 +179,7 @@ export class Transaction {
|
|
|
178
179
|
setUrls(urls) {
|
|
179
180
|
this.payload.urls = undefined;
|
|
180
181
|
if (urls) {
|
|
181
|
-
urls.forEach(url => {
|
|
182
|
+
urls.forEach((url) => {
|
|
182
183
|
this.addUrl(url);
|
|
183
184
|
});
|
|
184
185
|
}
|
|
@@ -207,7 +208,7 @@ export class Transaction {
|
|
|
207
208
|
*/
|
|
208
209
|
getFiles() {
|
|
209
210
|
if (this.payload.files && this.payload.files.length > 0) {
|
|
210
|
-
const files = this.payload.files.map(file => new File(this.book, file));
|
|
211
|
+
const files = this.payload.files.map((file) => new File(this.book, file));
|
|
211
212
|
return files;
|
|
212
213
|
}
|
|
213
214
|
else {
|
|
@@ -222,7 +223,7 @@ export class Transaction {
|
|
|
222
223
|
* @returns This Transaction, for chaining
|
|
223
224
|
*/
|
|
224
225
|
setFiles(files) {
|
|
225
|
-
const filePayloads = files.map(file => file.
|
|
226
|
+
const filePayloads = files.map((file) => file.json());
|
|
226
227
|
this.payload.files = [...filePayloads];
|
|
227
228
|
return this;
|
|
228
229
|
}
|
|
@@ -264,7 +265,8 @@ export class Transaction {
|
|
|
264
265
|
* @returns Object with key/value pair properties
|
|
265
266
|
*/
|
|
266
267
|
getProperties() {
|
|
267
|
-
return this.payload.properties != null
|
|
268
|
+
return this.payload.properties != null
|
|
269
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
268
270
|
}
|
|
269
271
|
/**
|
|
270
272
|
* Sets the custom properties of the Transaction
|
|
@@ -288,7 +290,7 @@ export class Transaction {
|
|
|
288
290
|
for (let index = 0; index < keys.length; index++) {
|
|
289
291
|
const key = keys[index];
|
|
290
292
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
291
|
-
if (value != null && value.trim() !=
|
|
293
|
+
if (value != null && value.trim() != "") {
|
|
292
294
|
return value;
|
|
293
295
|
}
|
|
294
296
|
}
|
|
@@ -321,14 +323,14 @@ export class Transaction {
|
|
|
321
323
|
* @returns This Transaction, for chaining
|
|
322
324
|
*/
|
|
323
325
|
setProperty(key, value) {
|
|
324
|
-
if (key == null || key.trim() ==
|
|
326
|
+
if (key == null || key.trim() == "") {
|
|
325
327
|
return this;
|
|
326
328
|
}
|
|
327
329
|
if (this.payload.properties == null) {
|
|
328
330
|
this.payload.properties = {};
|
|
329
331
|
}
|
|
330
332
|
if (!value) {
|
|
331
|
-
value =
|
|
333
|
+
value = "";
|
|
332
334
|
}
|
|
333
335
|
this.payload.properties[key] = value;
|
|
334
336
|
return this;
|
|
@@ -468,7 +470,9 @@ export class Transaction {
|
|
|
468
470
|
* @returns The amount of this Transaction
|
|
469
471
|
*/
|
|
470
472
|
getAmount() {
|
|
471
|
-
return this.payload.amount != null && this.payload.amount.trim() !=
|
|
473
|
+
return this.payload.amount != null && this.payload.amount.trim() != ""
|
|
474
|
+
? new Amount(this.payload.amount)
|
|
475
|
+
: undefined;
|
|
472
476
|
}
|
|
473
477
|
/**
|
|
474
478
|
* Gets the formatted amount of this Transaction according to the Book format.
|
|
@@ -491,7 +495,7 @@ export class Transaction {
|
|
|
491
495
|
*/
|
|
492
496
|
setAmount(amount) {
|
|
493
497
|
if (typeof amount == "string") {
|
|
494
|
-
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) +
|
|
498
|
+
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) + "";
|
|
495
499
|
this.payload.amount = amount.toString();
|
|
496
500
|
return this;
|
|
497
501
|
}
|
|
@@ -582,7 +586,10 @@ export class Transaction {
|
|
|
582
586
|
isCredit(account) {
|
|
583
587
|
return __awaiter(this, void 0, void 0, function* () {
|
|
584
588
|
var _a;
|
|
585
|
-
return (yield this.getCreditAccount()) != null &&
|
|
589
|
+
return ((yield this.getCreditAccount()) != null &&
|
|
590
|
+
account != null &&
|
|
591
|
+
((_a = (yield this.getCreditAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
592
|
+
account.getNormalizedName());
|
|
586
593
|
});
|
|
587
594
|
}
|
|
588
595
|
/**
|
|
@@ -595,7 +602,10 @@ export class Transaction {
|
|
|
595
602
|
isDebit(account) {
|
|
596
603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
597
604
|
var _a;
|
|
598
|
-
return (yield this.getDebitAccount()) != null &&
|
|
605
|
+
return ((yield this.getDebitAccount()) != null &&
|
|
606
|
+
account != null &&
|
|
607
|
+
((_a = (yield this.getDebitAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
608
|
+
account.getNormalizedName());
|
|
599
609
|
});
|
|
600
610
|
}
|
|
601
611
|
/** @internal */
|
|
@@ -646,15 +656,15 @@ export class Transaction {
|
|
|
646
656
|
*/
|
|
647
657
|
setDate(date) {
|
|
648
658
|
if (typeof date == "string") {
|
|
649
|
-
if (date.indexOf(
|
|
659
|
+
if (date.indexOf("/") > 0) {
|
|
650
660
|
let dateObject = Utils.parseDate(date, this.book.getDatePattern(), this.book.getTimeZone());
|
|
651
661
|
this.payload.date = Utils.formatDateISO(dateObject, this.book.getTimeZone());
|
|
652
662
|
}
|
|
653
|
-
else if (date.indexOf(
|
|
663
|
+
else if (date.indexOf("-")) {
|
|
654
664
|
this.payload.date = date;
|
|
655
665
|
}
|
|
656
666
|
}
|
|
657
|
-
else if (Object.prototype.toString.call(date) ===
|
|
667
|
+
else if (Object.prototype.toString.call(date) === "[object Date]") {
|
|
658
668
|
this.payload.date = Utils.formatDateISO(date, this.book.getTimeZone());
|
|
659
669
|
}
|
|
660
670
|
return this;
|
|
@@ -717,11 +727,17 @@ export class Transaction {
|
|
|
717
727
|
}
|
|
718
728
|
/** @internal */
|
|
719
729
|
getCaEvolvedBalance_() {
|
|
720
|
-
return this.payload.creditAccount != null &&
|
|
730
|
+
return this.payload.creditAccount != null &&
|
|
731
|
+
this.payload.creditAccount.balance != null
|
|
732
|
+
? new Amount(this.payload.creditAccount.balance)
|
|
733
|
+
: undefined;
|
|
721
734
|
}
|
|
722
735
|
/** @internal */
|
|
723
736
|
getDaEvolvedBalance_() {
|
|
724
|
-
return this.payload.debitAccount != null &&
|
|
737
|
+
return this.payload.debitAccount != null &&
|
|
738
|
+
this.payload.debitAccount.balance != null
|
|
739
|
+
? new Amount(this.payload.debitAccount.balance)
|
|
740
|
+
: undefined;
|
|
725
741
|
}
|
|
726
742
|
/**
|
|
727
743
|
* Gets the balance that the [[Account]] has at that day, when listing transactions of that Account.
|
|
@@ -744,7 +760,9 @@ export class Transaction {
|
|
|
744
760
|
}
|
|
745
761
|
if (accountBalance != null) {
|
|
746
762
|
if (!raw) {
|
|
747
|
-
var account = isCa
|
|
763
|
+
var account = isCa
|
|
764
|
+
? yield this.getCreditAccount()
|
|
765
|
+
: yield this.getDebitAccount();
|
|
748
766
|
accountBalance = Utils.getRepresentativeValue(accountBalance, account === null || account === void 0 ? void 0 : account.isCredit());
|
|
749
767
|
}
|
|
750
768
|
return Utils.round(accountBalance, this.book.getFractionDigits());
|
|
@@ -761,7 +779,7 @@ export class Transaction {
|
|
|
761
779
|
*/
|
|
762
780
|
create() {
|
|
763
781
|
return __awaiter(this, void 0, void 0, function* () {
|
|
764
|
-
let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload);
|
|
782
|
+
let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
765
783
|
this.payload = operation.transaction || {};
|
|
766
784
|
return this;
|
|
767
785
|
});
|
|
@@ -773,7 +791,7 @@ export class Transaction {
|
|
|
773
791
|
*/
|
|
774
792
|
update() {
|
|
775
793
|
return __awaiter(this, void 0, void 0, function* () {
|
|
776
|
-
let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload);
|
|
794
|
+
let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
777
795
|
this.payload = operation.transaction || {};
|
|
778
796
|
return this;
|
|
779
797
|
});
|
|
@@ -786,7 +804,7 @@ export class Transaction {
|
|
|
786
804
|
check() {
|
|
787
805
|
return __awaiter(this, void 0, void 0, function* () {
|
|
788
806
|
var _a;
|
|
789
|
-
let operation = yield TransactionService.checkTransaction(this.book.getId(), this.payload);
|
|
807
|
+
let operation = yield TransactionService.checkTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
790
808
|
this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
|
|
791
809
|
return this;
|
|
792
810
|
});
|
|
@@ -799,7 +817,7 @@ export class Transaction {
|
|
|
799
817
|
uncheck() {
|
|
800
818
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
819
|
var _a;
|
|
802
|
-
let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.payload);
|
|
820
|
+
let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
803
821
|
this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
|
|
804
822
|
return this;
|
|
805
823
|
});
|
|
@@ -811,7 +829,7 @@ export class Transaction {
|
|
|
811
829
|
*/
|
|
812
830
|
post() {
|
|
813
831
|
return __awaiter(this, void 0, void 0, function* () {
|
|
814
|
-
let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload);
|
|
832
|
+
let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
815
833
|
this.payload = operation.transaction || {};
|
|
816
834
|
return this;
|
|
817
835
|
});
|
|
@@ -824,7 +842,7 @@ export class Transaction {
|
|
|
824
842
|
trash() {
|
|
825
843
|
return __awaiter(this, void 0, void 0, function* () {
|
|
826
844
|
var _a;
|
|
827
|
-
let operation = yield TransactionService.trashTransaction(this.book.getId(), this.payload);
|
|
845
|
+
let operation = yield TransactionService.trashTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
828
846
|
this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
|
|
829
847
|
return this;
|
|
830
848
|
});
|
|
@@ -837,7 +855,7 @@ export class Transaction {
|
|
|
837
855
|
untrash() {
|
|
838
856
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
857
|
var _a;
|
|
840
|
-
let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.payload);
|
|
858
|
+
let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
841
859
|
this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
|
|
842
860
|
return this;
|
|
843
861
|
});
|
package/lib/model/User.js
CHANGED
|
@@ -8,7 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Connection } from "./Connection.js";
|
|
11
|
-
import
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
12
|
+
import { Bkper } from "./Bkper.js";
|
|
13
|
+
import * as ConnectionService from "../service/connection-service.js";
|
|
12
14
|
/**
|
|
13
15
|
* This class defines a User on the Bkper platform.
|
|
14
16
|
*
|
|
@@ -18,18 +20,18 @@ import * as ConnectionService from '../service/connection-service.js';
|
|
|
18
20
|
*
|
|
19
21
|
* @public
|
|
20
22
|
*/
|
|
21
|
-
export class User {
|
|
22
|
-
constructor(payload) {
|
|
23
|
-
|
|
24
|
-
this.
|
|
23
|
+
export class User extends Resource {
|
|
24
|
+
constructor(payload, config) {
|
|
25
|
+
super(payload);
|
|
26
|
+
this.config = config;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
|
-
* Gets
|
|
29
|
+
* Gets the configuration object for this User.
|
|
28
30
|
*
|
|
29
|
-
* @returns
|
|
31
|
+
* @returns The Config object for this User or the global config
|
|
30
32
|
*/
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
+
getConfig() {
|
|
34
|
+
return this.config || Bkper.globalConfig;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* Gets the id of the User.
|
|
@@ -134,8 +136,8 @@ export class User {
|
|
|
134
136
|
*/
|
|
135
137
|
getConnections() {
|
|
136
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const json = yield ConnectionService.listConnections();
|
|
138
|
-
return json.map(c => new Connection(c));
|
|
139
|
+
const json = yield ConnectionService.listConnections(this.getConfig());
|
|
140
|
+
return json.map((c) => new Connection(c));
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
/**
|
|
@@ -147,7 +149,7 @@ export class User {
|
|
|
147
149
|
*/
|
|
148
150
|
getConnection(id) {
|
|
149
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const json = yield ConnectionService.getConnection(id);
|
|
152
|
+
const json = yield ConnectionService.getConnection(id, this.getConfig());
|
|
151
153
|
return new Connection(json);
|
|
152
154
|
});
|
|
153
155
|
}
|
|
@@ -8,42 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { HttpBooksApiV5Request } from './http-api-request.js';
|
|
11
|
-
export function createAccount(bookId, account) {
|
|
11
|
+
export function createAccount(bookId, account, config) {
|
|
12
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts
|
|
13
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts`, config).setMethod('POST').setPayload(account).fetch();
|
|
14
14
|
return response.data;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
export function createAccounts(bookId, payload) {
|
|
17
|
+
export function createAccounts(bookId, payload, config) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
var _a;
|
|
20
|
-
const response = yield new HttpBooksApiV5Request(`${bookId}/accounts/batch
|
|
20
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/accounts/batch`, config).setMethod('POST').setPayload(payload).fetch();
|
|
21
21
|
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
export function updateAccount(bookId, account) {
|
|
24
|
+
export function updateAccount(bookId, account, config) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
var payload = account;
|
|
27
|
-
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts
|
|
27
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts`, config).setMethod('PUT').setPayload(payload).fetch();
|
|
28
28
|
return response.data;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
export function deleteAccount(bookId, account) {
|
|
31
|
+
export function deleteAccount(bookId, account, config) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${account.id}
|
|
33
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${account.id}`, config).setMethod('DELETE').fetch();
|
|
34
34
|
return response.data;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
export function getAccount(bookId, idOrName) {
|
|
37
|
+
export function getAccount(bookId, idOrName, config) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
let response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${encodeURIComponent(idOrName)}
|
|
39
|
+
let response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${encodeURIComponent(idOrName)}`, config).setMethod('GET').fetch();
|
|
40
40
|
return response.data;
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
export function getAccounts(bookId) {
|
|
43
|
+
export function getAccounts(bookId, config) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
45
|
var _a;
|
|
46
|
-
let response = yield new HttpBooksApiV5Request(`${bookId}/accounts
|
|
46
|
+
let response = yield new HttpBooksApiV5Request(`${bookId}/accounts`, config).setMethod('GET').fetch();
|
|
47
47
|
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { HttpApiRequest } from "./http-api-request.js";
|
|
11
|
-
export function getApps() {
|
|
11
|
+
export function getApps(config) {
|
|
12
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
let response = yield new HttpApiRequest(`v5/apps
|
|
13
|
+
let response = yield new HttpApiRequest(`v5/apps`, config).setMethod('GET').fetch();
|
|
14
14
|
if (response.data == null) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
@@ -22,21 +22,21 @@ export function getApps() {
|
|
|
22
22
|
return appsJson;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
export function createApp(app) {
|
|
25
|
+
export function createApp(app, config) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
var response = yield new HttpApiRequest(`v5/apps
|
|
27
|
+
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('POST').setPayload(app).fetch();
|
|
28
28
|
return response.data;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
export function updateApp(app) {
|
|
31
|
+
export function updateApp(app, config) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
var response = yield new HttpApiRequest(`v5/apps
|
|
33
|
+
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('PUT').setPayload(app).fetch();
|
|
34
34
|
return response.data;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
export function patchApp(app) {
|
|
37
|
+
export function patchApp(app, config) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
var response = yield new HttpApiRequest(`v5/apps
|
|
39
|
+
var response = yield new HttpApiRequest(`v5/apps`, config).setMethod('PATCH').setPayload(app).fetch();
|
|
40
40
|
return response.data;
|
|
41
41
|
});
|
|
42
42
|
}
|