bkper-js 2.7.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/lib/index.d.ts +142 -144
- package/lib/model/Account.js +18 -24
- package/lib/model/App.js +70 -24
- package/lib/model/Bkper.js +42 -30
- package/lib/model/Book.js +107 -102
- package/lib/model/BotResponse.js +2 -2
- package/lib/model/Collaborator.js +10 -14
- package/lib/model/Collection.js +22 -22
- package/lib/model/Connection.js +26 -21
- package/lib/model/Conversation.js +18 -16
- package/lib/model/File.js +17 -20
- package/lib/model/Group.js +27 -24
- package/lib/model/Integration.js +15 -16
- package/lib/model/Message.js +18 -19
- package/lib/model/Query.js +10 -14
- package/lib/model/Resource.js +23 -0
- package/lib/model/Template.js +8 -10
- package/lib/model/Transaction.js +59 -46
- package/lib/model/User.js +12 -15
- package/lib/service/account-service.js +12 -12
- package/lib/service/app-service.js +8 -8
- package/lib/service/balances-service.js +2 -2
- package/lib/service/book-service.js +14 -14
- package/lib/service/collaborator-service.js +6 -6
- package/lib/service/collection-service.js +12 -12
- package/lib/service/connection-service.js +12 -15
- package/lib/service/conversation-service.js +10 -10
- package/lib/service/event-service.js +8 -8
- package/lib/service/file-service.js +4 -4
- package/lib/service/group-service.js +16 -16
- package/lib/service/http-api-request.js +54 -45
- package/lib/service/integration-service.js +8 -8
- package/lib/service/query-service.js +8 -8
- package/lib/service/template-service.js +2 -2
- package/lib/service/transaction-service.js +32 -32
- package/lib/service/user-service.js +4 -4
- package/package.json +1 -1
package/lib/model/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,13 @@ 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
|
-
|
|
27
|
-
*
|
|
28
|
-
* @returns The wrapped plain json object
|
|
29
|
-
*/
|
|
30
|
-
json() {
|
|
31
|
-
return Object.assign({}, this.payload);
|
|
26
|
+
getConfig() {
|
|
27
|
+
return this.conversation.getConfig();
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* Gets the Message universal identifier.
|
|
@@ -68,7 +64,9 @@ export class Message {
|
|
|
68
64
|
* @returns The Date the Message was created
|
|
69
65
|
*/
|
|
70
66
|
getCreatedAt() {
|
|
71
|
-
return this.payload.createdAt
|
|
67
|
+
return this.payload.createdAt
|
|
68
|
+
? new Date(new Number(this.payload.createdAt).valueOf())
|
|
69
|
+
: undefined;
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Gets the text content of the Message.
|
|
@@ -95,7 +93,8 @@ export class Message {
|
|
|
95
93
|
* @returns The custom properties stored in this Message
|
|
96
94
|
*/
|
|
97
95
|
getProperties() {
|
|
98
|
-
return this.payload.properties != null
|
|
96
|
+
return this.payload.properties != null
|
|
97
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
99
98
|
}
|
|
100
99
|
/**
|
|
101
100
|
* Sets the custom properties of the Message
|
|
@@ -119,7 +118,7 @@ export class Message {
|
|
|
119
118
|
for (let index = 0; index < keys.length; index++) {
|
|
120
119
|
const key = keys[index];
|
|
121
120
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
122
|
-
if (value != null && value.trim() !=
|
|
121
|
+
if (value != null && value.trim() != "") {
|
|
123
122
|
return value;
|
|
124
123
|
}
|
|
125
124
|
}
|
|
@@ -134,14 +133,14 @@ export class Message {
|
|
|
134
133
|
* @returns This Message, for chaining
|
|
135
134
|
*/
|
|
136
135
|
setProperty(key, value) {
|
|
137
|
-
if (key == null || key.trim() ==
|
|
136
|
+
if (key == null || key.trim() == "") {
|
|
138
137
|
return this;
|
|
139
138
|
}
|
|
140
139
|
if (this.payload.properties == null) {
|
|
141
140
|
this.payload.properties = {};
|
|
142
141
|
}
|
|
143
142
|
if (!value) {
|
|
144
|
-
value =
|
|
143
|
+
value = "";
|
|
145
144
|
}
|
|
146
145
|
this.payload.properties[key] = value;
|
|
147
146
|
return this;
|
|
@@ -166,9 +165,9 @@ export class Message {
|
|
|
166
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
166
|
const conversationId = this.conversation.getId();
|
|
168
167
|
if (!conversationId) {
|
|
169
|
-
throw new Error(
|
|
168
|
+
throw new Error("Conversation id null!");
|
|
170
169
|
}
|
|
171
|
-
const responsePayload = yield ConversationService.createMessage(conversationId, this.payload);
|
|
170
|
+
const responsePayload = yield ConversationService.createMessage(conversationId, this.payload, this.getConfig());
|
|
172
171
|
if (responsePayload.parent) {
|
|
173
172
|
this.payload = responsePayload.parent;
|
|
174
173
|
}
|
|
@@ -191,9 +190,9 @@ export class Message {
|
|
|
191
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
191
|
const conversationId = this.conversation.getId();
|
|
193
192
|
if (!conversationId) {
|
|
194
|
-
throw new Error(
|
|
193
|
+
throw new Error("Conversation id null!");
|
|
195
194
|
}
|
|
196
|
-
ConversationService.streamMessage(conversationId, this.payload);
|
|
195
|
+
ConversationService.streamMessage(conversationId, this.payload, this.getConfig());
|
|
197
196
|
});
|
|
198
197
|
}
|
|
199
198
|
}
|
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,13 @@ 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
|
-
|
|
25
|
-
*
|
|
26
|
-
* @returns The wrapped plain json object
|
|
27
|
-
*/
|
|
28
|
-
json() {
|
|
29
|
-
return Object.assign({}, this.payload);
|
|
24
|
+
getConfig() {
|
|
25
|
+
return this.book.getConfig();
|
|
30
26
|
}
|
|
31
27
|
/**
|
|
32
28
|
* Gets the Query universal identifier.
|
|
@@ -81,7 +77,7 @@ export class Query {
|
|
|
81
77
|
*/
|
|
82
78
|
create() {
|
|
83
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
this.payload = yield QueryService.createSavedQuery(this.book.getId(), this.payload);
|
|
80
|
+
this.payload = yield QueryService.createSavedQuery(this.book.getId(), this.payload, this.getConfig());
|
|
85
81
|
this.updateQueryCache();
|
|
86
82
|
return this;
|
|
87
83
|
});
|
|
@@ -93,7 +89,7 @@ export class Query {
|
|
|
93
89
|
*/
|
|
94
90
|
update() {
|
|
95
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.payload = yield QueryService.updateSavedQuery(this.book.getId(), this.payload);
|
|
92
|
+
this.payload = yield QueryService.updateSavedQuery(this.book.getId(), this.payload, this.getConfig());
|
|
97
93
|
this.updateQueryCache();
|
|
98
94
|
return this;
|
|
99
95
|
});
|
|
@@ -109,7 +105,7 @@ export class Query {
|
|
|
109
105
|
if (!queryId) {
|
|
110
106
|
throw new Error("Query id null!");
|
|
111
107
|
}
|
|
112
|
-
this.payload = yield QueryService.deleteSavedQuery(this.book.getId(), queryId);
|
|
108
|
+
this.payload = yield QueryService.deleteSavedQuery(this.book.getId(), queryId, this.getConfig());
|
|
113
109
|
this.updateQueryCache(true);
|
|
114
110
|
return this;
|
|
115
111
|
});
|
|
@@ -117,7 +113,7 @@ export class Query {
|
|
|
117
113
|
/** @internal */
|
|
118
114
|
updateQueryCache(deleted) {
|
|
119
115
|
if (this.book.queries) {
|
|
120
|
-
this.book.queries = this.book.queries.filter(q => q.getId() !== this.getId());
|
|
116
|
+
this.book.queries = this.book.queries.filter((q) => q.getId() !== this.getId());
|
|
121
117
|
if (!deleted) {
|
|
122
118
|
this.book.queries.push(this);
|
|
123
119
|
}
|
|
@@ -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,13 @@
|
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @returns An immutable copy of the json payload
|
|
16
|
-
*/
|
|
17
|
-
json() {
|
|
18
|
-
return Object.assign({}, this.payload);
|
|
15
|
+
getConfig() {
|
|
16
|
+
return this.config || Bkper.globalConfig;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* 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,13 @@ 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
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* @returns An immutable copy of the json payload
|
|
34
|
-
*/
|
|
35
|
-
json() {
|
|
36
|
-
return Object.assign({}, this.payload);
|
|
29
|
+
getConfig() {
|
|
30
|
+
return this.book.getConfig();
|
|
37
31
|
}
|
|
38
32
|
/**
|
|
39
33
|
* Gets the book associated with this transaction.
|
|
@@ -124,12 +118,12 @@ export class Transaction {
|
|
|
124
118
|
return this.payload.checked;
|
|
125
119
|
}
|
|
126
120
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
* Set the check state of the Transaction.
|
|
122
|
+
*
|
|
123
|
+
* @param checked - The check state
|
|
124
|
+
*
|
|
125
|
+
* @returns This Transaction, for chaining
|
|
126
|
+
*/
|
|
133
127
|
setChecked(checked) {
|
|
134
128
|
this.payload.checked = checked;
|
|
135
129
|
return this;
|
|
@@ -148,9 +142,11 @@ export class Transaction {
|
|
|
148
142
|
* @returns True if a transaction is locked by the book lock/closing date
|
|
149
143
|
*/
|
|
150
144
|
isLocked() {
|
|
151
|
-
const date = this.getDate() ||
|
|
145
|
+
const date = this.getDate() ||
|
|
146
|
+
Utils.formatDateISO(new Date(), this.book.getTimeZone());
|
|
152
147
|
const lockOrClosingDate = this.book.getMostRecentLockDate_();
|
|
153
|
-
return lockOrClosingDate != null &&
|
|
148
|
+
return (lockOrClosingDate != null &&
|
|
149
|
+
Utils.getIsoDateValue(lockOrClosingDate) >= Utils.getIsoDateValue(date));
|
|
154
150
|
}
|
|
155
151
|
/**
|
|
156
152
|
* Gets all hashtags used in the transaction.
|
|
@@ -178,7 +174,7 @@ export class Transaction {
|
|
|
178
174
|
setUrls(urls) {
|
|
179
175
|
this.payload.urls = undefined;
|
|
180
176
|
if (urls) {
|
|
181
|
-
urls.forEach(url => {
|
|
177
|
+
urls.forEach((url) => {
|
|
182
178
|
this.addUrl(url);
|
|
183
179
|
});
|
|
184
180
|
}
|
|
@@ -207,7 +203,7 @@ export class Transaction {
|
|
|
207
203
|
*/
|
|
208
204
|
getFiles() {
|
|
209
205
|
if (this.payload.files && this.payload.files.length > 0) {
|
|
210
|
-
const files = this.payload.files.map(file => new File(this.book, file));
|
|
206
|
+
const files = this.payload.files.map((file) => new File(this.book, file));
|
|
211
207
|
return files;
|
|
212
208
|
}
|
|
213
209
|
else {
|
|
@@ -222,7 +218,7 @@ export class Transaction {
|
|
|
222
218
|
* @returns This Transaction, for chaining
|
|
223
219
|
*/
|
|
224
220
|
setFiles(files) {
|
|
225
|
-
const filePayloads = files.map(file => file.
|
|
221
|
+
const filePayloads = files.map((file) => file.json());
|
|
226
222
|
this.payload.files = [...filePayloads];
|
|
227
223
|
return this;
|
|
228
224
|
}
|
|
@@ -264,7 +260,8 @@ export class Transaction {
|
|
|
264
260
|
* @returns Object with key/value pair properties
|
|
265
261
|
*/
|
|
266
262
|
getProperties() {
|
|
267
|
-
return this.payload.properties != null
|
|
263
|
+
return this.payload.properties != null
|
|
264
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
268
265
|
}
|
|
269
266
|
/**
|
|
270
267
|
* Sets the custom properties of the Transaction
|
|
@@ -288,7 +285,7 @@ export class Transaction {
|
|
|
288
285
|
for (let index = 0; index < keys.length; index++) {
|
|
289
286
|
const key = keys[index];
|
|
290
287
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
291
|
-
if (value != null && value.trim() !=
|
|
288
|
+
if (value != null && value.trim() != "") {
|
|
292
289
|
return value;
|
|
293
290
|
}
|
|
294
291
|
}
|
|
@@ -321,14 +318,14 @@ export class Transaction {
|
|
|
321
318
|
* @returns This Transaction, for chaining
|
|
322
319
|
*/
|
|
323
320
|
setProperty(key, value) {
|
|
324
|
-
if (key == null || key.trim() ==
|
|
321
|
+
if (key == null || key.trim() == "") {
|
|
325
322
|
return this;
|
|
326
323
|
}
|
|
327
324
|
if (this.payload.properties == null) {
|
|
328
325
|
this.payload.properties = {};
|
|
329
326
|
}
|
|
330
327
|
if (!value) {
|
|
331
|
-
value =
|
|
328
|
+
value = "";
|
|
332
329
|
}
|
|
333
330
|
this.payload.properties[key] = value;
|
|
334
331
|
return this;
|
|
@@ -468,7 +465,9 @@ export class Transaction {
|
|
|
468
465
|
* @returns The amount of this Transaction
|
|
469
466
|
*/
|
|
470
467
|
getAmount() {
|
|
471
|
-
return this.payload.amount != null && this.payload.amount.trim() !=
|
|
468
|
+
return this.payload.amount != null && this.payload.amount.trim() != ""
|
|
469
|
+
? new Amount(this.payload.amount)
|
|
470
|
+
: undefined;
|
|
472
471
|
}
|
|
473
472
|
/**
|
|
474
473
|
* Gets the formatted amount of this Transaction according to the Book format.
|
|
@@ -491,7 +490,7 @@ export class Transaction {
|
|
|
491
490
|
*/
|
|
492
491
|
setAmount(amount) {
|
|
493
492
|
if (typeof amount == "string") {
|
|
494
|
-
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) +
|
|
493
|
+
amount = Utils.parseValue(amount, this.book.getDecimalSeparator()) + "";
|
|
495
494
|
this.payload.amount = amount.toString();
|
|
496
495
|
return this;
|
|
497
496
|
}
|
|
@@ -582,7 +581,10 @@ export class Transaction {
|
|
|
582
581
|
isCredit(account) {
|
|
583
582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
584
583
|
var _a;
|
|
585
|
-
return (yield this.getCreditAccount()) != null &&
|
|
584
|
+
return ((yield this.getCreditAccount()) != null &&
|
|
585
|
+
account != null &&
|
|
586
|
+
((_a = (yield this.getCreditAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
587
|
+
account.getNormalizedName());
|
|
586
588
|
});
|
|
587
589
|
}
|
|
588
590
|
/**
|
|
@@ -595,7 +597,10 @@ export class Transaction {
|
|
|
595
597
|
isDebit(account) {
|
|
596
598
|
return __awaiter(this, void 0, void 0, function* () {
|
|
597
599
|
var _a;
|
|
598
|
-
return (yield this.getDebitAccount()) != null &&
|
|
600
|
+
return ((yield this.getDebitAccount()) != null &&
|
|
601
|
+
account != null &&
|
|
602
|
+
((_a = (yield this.getDebitAccount())) === null || _a === void 0 ? void 0 : _a.getNormalizedName()) ==
|
|
603
|
+
account.getNormalizedName());
|
|
599
604
|
});
|
|
600
605
|
}
|
|
601
606
|
/** @internal */
|
|
@@ -646,15 +651,15 @@ export class Transaction {
|
|
|
646
651
|
*/
|
|
647
652
|
setDate(date) {
|
|
648
653
|
if (typeof date == "string") {
|
|
649
|
-
if (date.indexOf(
|
|
654
|
+
if (date.indexOf("/") > 0) {
|
|
650
655
|
let dateObject = Utils.parseDate(date, this.book.getDatePattern(), this.book.getTimeZone());
|
|
651
656
|
this.payload.date = Utils.formatDateISO(dateObject, this.book.getTimeZone());
|
|
652
657
|
}
|
|
653
|
-
else if (date.indexOf(
|
|
658
|
+
else if (date.indexOf("-")) {
|
|
654
659
|
this.payload.date = date;
|
|
655
660
|
}
|
|
656
661
|
}
|
|
657
|
-
else if (Object.prototype.toString.call(date) ===
|
|
662
|
+
else if (Object.prototype.toString.call(date) === "[object Date]") {
|
|
658
663
|
this.payload.date = Utils.formatDateISO(date, this.book.getTimeZone());
|
|
659
664
|
}
|
|
660
665
|
return this;
|
|
@@ -717,11 +722,17 @@ export class Transaction {
|
|
|
717
722
|
}
|
|
718
723
|
/** @internal */
|
|
719
724
|
getCaEvolvedBalance_() {
|
|
720
|
-
return this.payload.creditAccount != null &&
|
|
725
|
+
return this.payload.creditAccount != null &&
|
|
726
|
+
this.payload.creditAccount.balance != null
|
|
727
|
+
? new Amount(this.payload.creditAccount.balance)
|
|
728
|
+
: undefined;
|
|
721
729
|
}
|
|
722
730
|
/** @internal */
|
|
723
731
|
getDaEvolvedBalance_() {
|
|
724
|
-
return this.payload.debitAccount != null &&
|
|
732
|
+
return this.payload.debitAccount != null &&
|
|
733
|
+
this.payload.debitAccount.balance != null
|
|
734
|
+
? new Amount(this.payload.debitAccount.balance)
|
|
735
|
+
: undefined;
|
|
725
736
|
}
|
|
726
737
|
/**
|
|
727
738
|
* Gets the balance that the [[Account]] has at that day, when listing transactions of that Account.
|
|
@@ -744,7 +755,9 @@ export class Transaction {
|
|
|
744
755
|
}
|
|
745
756
|
if (accountBalance != null) {
|
|
746
757
|
if (!raw) {
|
|
747
|
-
var account = isCa
|
|
758
|
+
var account = isCa
|
|
759
|
+
? yield this.getCreditAccount()
|
|
760
|
+
: yield this.getDebitAccount();
|
|
748
761
|
accountBalance = Utils.getRepresentativeValue(accountBalance, account === null || account === void 0 ? void 0 : account.isCredit());
|
|
749
762
|
}
|
|
750
763
|
return Utils.round(accountBalance, this.book.getFractionDigits());
|
|
@@ -761,7 +774,7 @@ export class Transaction {
|
|
|
761
774
|
*/
|
|
762
775
|
create() {
|
|
763
776
|
return __awaiter(this, void 0, void 0, function* () {
|
|
764
|
-
let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload);
|
|
777
|
+
let operation = yield TransactionService.createTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
765
778
|
this.payload = operation.transaction || {};
|
|
766
779
|
return this;
|
|
767
780
|
});
|
|
@@ -773,7 +786,7 @@ export class Transaction {
|
|
|
773
786
|
*/
|
|
774
787
|
update() {
|
|
775
788
|
return __awaiter(this, void 0, void 0, function* () {
|
|
776
|
-
let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload);
|
|
789
|
+
let operation = yield TransactionService.updateTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
777
790
|
this.payload = operation.transaction || {};
|
|
778
791
|
return this;
|
|
779
792
|
});
|
|
@@ -786,7 +799,7 @@ export class Transaction {
|
|
|
786
799
|
check() {
|
|
787
800
|
return __awaiter(this, void 0, void 0, function* () {
|
|
788
801
|
var _a;
|
|
789
|
-
let operation = yield TransactionService.checkTransaction(this.book.getId(), this.payload);
|
|
802
|
+
let operation = yield TransactionService.checkTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
790
803
|
this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
|
|
791
804
|
return this;
|
|
792
805
|
});
|
|
@@ -799,7 +812,7 @@ export class Transaction {
|
|
|
799
812
|
uncheck() {
|
|
800
813
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
814
|
var _a;
|
|
802
|
-
let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.payload);
|
|
815
|
+
let operation = yield TransactionService.uncheckTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
803
816
|
this.payload.checked = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.checked;
|
|
804
817
|
return this;
|
|
805
818
|
});
|
|
@@ -811,7 +824,7 @@ export class Transaction {
|
|
|
811
824
|
*/
|
|
812
825
|
post() {
|
|
813
826
|
return __awaiter(this, void 0, void 0, function* () {
|
|
814
|
-
let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload);
|
|
827
|
+
let operation = yield TransactionService.postTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
815
828
|
this.payload = operation.transaction || {};
|
|
816
829
|
return this;
|
|
817
830
|
});
|
|
@@ -824,7 +837,7 @@ export class Transaction {
|
|
|
824
837
|
trash() {
|
|
825
838
|
return __awaiter(this, void 0, void 0, function* () {
|
|
826
839
|
var _a;
|
|
827
|
-
let operation = yield TransactionService.trashTransaction(this.book.getId(), this.payload);
|
|
840
|
+
let operation = yield TransactionService.trashTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
828
841
|
this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
|
|
829
842
|
return this;
|
|
830
843
|
});
|
|
@@ -837,7 +850,7 @@ export class Transaction {
|
|
|
837
850
|
untrash() {
|
|
838
851
|
return __awaiter(this, void 0, void 0, function* () {
|
|
839
852
|
var _a;
|
|
840
|
-
let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.payload);
|
|
853
|
+
let operation = yield TransactionService.restoreTransaction(this.book.getId(), this.payload, this.getConfig());
|
|
841
854
|
this.payload.trashed = (_a = operation.transaction) === null || _a === void 0 ? void 0 : _a.trashed;
|
|
842
855
|
return this;
|
|
843
856
|
});
|
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,13 @@ 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
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @returns An immutable copy of the json payload
|
|
30
|
-
*/
|
|
31
|
-
json() {
|
|
32
|
-
return Object.assign({}, this.payload);
|
|
28
|
+
getConfig() {
|
|
29
|
+
return this.config || Bkper.globalConfig;
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* Gets the id of the User.
|
|
@@ -134,8 +131,8 @@ export class User {
|
|
|
134
131
|
*/
|
|
135
132
|
getConnections() {
|
|
136
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
const json = yield ConnectionService.listConnections();
|
|
138
|
-
return json.map(c => new Connection(c));
|
|
134
|
+
const json = yield ConnectionService.listConnections(this.getConfig());
|
|
135
|
+
return json.map((c) => new Connection(c));
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
@@ -147,7 +144,7 @@ export class User {
|
|
|
147
144
|
*/
|
|
148
145
|
getConnection(id) {
|
|
149
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const json = yield ConnectionService.getConnection(id);
|
|
147
|
+
const json = yield ConnectionService.getConnection(id, this.getConfig());
|
|
151
148
|
return new Connection(json);
|
|
152
149
|
});
|
|
153
150
|
}
|
|
@@ -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
|
}
|