bkper-js 2.7.0 → 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 +8 -5
- 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 +78 -71
- package/lib/service/http-request.js +31 -9
- 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 -2
package/lib/model/Collection.js
CHANGED
|
@@ -8,23 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Book } from "./Book.js";
|
|
11
|
-
import
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
12
|
+
import { Bkper } from "./Bkper.js";
|
|
13
|
+
import * as CollectionService from "../service/collection-service.js";
|
|
12
14
|
/**
|
|
13
15
|
* This class defines a Collection of [[Books]].
|
|
14
16
|
*
|
|
15
17
|
* @public
|
|
16
18
|
*/
|
|
17
|
-
export class Collection {
|
|
18
|
-
constructor(payload) {
|
|
19
|
-
|
|
19
|
+
export class Collection extends Resource {
|
|
20
|
+
constructor(payload, config) {
|
|
21
|
+
super(payload);
|
|
22
|
+
this.config = config;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
* @returns The wrapped plain json object
|
|
25
|
-
*/
|
|
26
|
-
json() {
|
|
27
|
-
return Object.assign({}, this.payload);
|
|
24
|
+
getConfig() {
|
|
25
|
+
return this.config || Bkper.globalConfig;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Gets the unique identifier of this Collection.
|
|
@@ -67,7 +65,9 @@ export class Collection {
|
|
|
67
65
|
* @returns The permission for the current user
|
|
68
66
|
*/
|
|
69
67
|
getPermission() {
|
|
70
|
-
return this.payload.permission
|
|
68
|
+
return this.payload.permission
|
|
69
|
+
? this.payload.permission
|
|
70
|
+
: undefined;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Gets all Books of this collection.
|
|
@@ -96,9 +96,9 @@ export class Collection {
|
|
|
96
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
97
|
const collectionId = this.getId();
|
|
98
98
|
if (collectionId && books.length > 0) {
|
|
99
|
-
const bookList = { items: books.map(b => b.json()) };
|
|
100
|
-
let addedBooks = yield CollectionService.addBooksToCollection(collectionId, bookList);
|
|
101
|
-
return addedBooks.map(book => new Book(book));
|
|
99
|
+
const bookList = { items: books.map((b) => b.json()) };
|
|
100
|
+
let addedBooks = yield CollectionService.addBooksToCollection(collectionId, bookList, this.getConfig());
|
|
101
|
+
return addedBooks.map((book) => new Book(book));
|
|
102
102
|
}
|
|
103
103
|
return [];
|
|
104
104
|
});
|
|
@@ -114,9 +114,9 @@ export class Collection {
|
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
115
|
const collectionId = this.getId();
|
|
116
116
|
if (collectionId && books.length > 0) {
|
|
117
|
-
const bookList = { items: books.map(b => b.json()) };
|
|
118
|
-
let removedBooks = yield CollectionService.removeBooksFromCollection(collectionId, bookList);
|
|
119
|
-
return removedBooks.map(book => new Book(book));
|
|
117
|
+
const bookList = { items: books.map((b) => b.json()) };
|
|
118
|
+
let removedBooks = yield CollectionService.removeBooksFromCollection(collectionId, bookList, this.getConfig());
|
|
119
|
+
return removedBooks.map((book) => new Book(book));
|
|
120
120
|
}
|
|
121
121
|
return [];
|
|
122
122
|
});
|
|
@@ -136,7 +136,7 @@ export class Collection {
|
|
|
136
136
|
*/
|
|
137
137
|
create() {
|
|
138
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
this.payload = yield CollectionService.createCollection(this.payload);
|
|
139
|
+
this.payload = yield CollectionService.createCollection(this.payload, this.getConfig());
|
|
140
140
|
return this;
|
|
141
141
|
});
|
|
142
142
|
}
|
|
@@ -147,7 +147,7 @@ export class Collection {
|
|
|
147
147
|
*/
|
|
148
148
|
update() {
|
|
149
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
this.payload = yield CollectionService.updateCollection(this.payload);
|
|
150
|
+
this.payload = yield CollectionService.updateCollection(this.payload, this.getConfig());
|
|
151
151
|
return this;
|
|
152
152
|
});
|
|
153
153
|
}
|
|
@@ -158,8 +158,8 @@ export class Collection {
|
|
|
158
158
|
*/
|
|
159
159
|
remove() {
|
|
160
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
let books = yield CollectionService.deleteCollection(this.payload);
|
|
162
|
-
return books.map(book => new Book(book));
|
|
161
|
+
let books = yield CollectionService.deleteCollection(this.payload, this.getConfig());
|
|
162
|
+
return books.map((book) => new Book(book));
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
}
|
package/lib/model/Connection.js
CHANGED
|
@@ -7,24 +7,22 @@ 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
|
|
11
|
-
import {
|
|
10
|
+
import { Resource } from "./Resource.js";
|
|
11
|
+
import { Bkper } from "./Bkper.js";
|
|
12
|
+
import * as ConnectionService from "../service/connection-service.js";
|
|
13
|
+
import { Integration } from "./Integration.js";
|
|
12
14
|
/**
|
|
13
15
|
* This class defines a Connection from an [[User]] to an external service.
|
|
14
16
|
*
|
|
15
17
|
* @public
|
|
16
18
|
*/
|
|
17
|
-
export class Connection {
|
|
18
|
-
constructor(payload) {
|
|
19
|
-
|
|
19
|
+
export class Connection extends Resource {
|
|
20
|
+
constructor(payload, config) {
|
|
21
|
+
super(payload);
|
|
22
|
+
this.config = config;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
* @returns An immutable copy of the json payload
|
|
25
|
-
*/
|
|
26
|
-
json() {
|
|
27
|
-
return Object.assign({}, this.payload);
|
|
24
|
+
getConfig() {
|
|
25
|
+
return this.config || Bkper.globalConfig;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Gets the id of the Connection.
|
|
@@ -140,7 +138,8 @@ export class Connection {
|
|
|
140
138
|
* @returns Object with key/value pair properties
|
|
141
139
|
*/
|
|
142
140
|
getProperties() {
|
|
143
|
-
return this.payload.properties != null
|
|
141
|
+
return this.payload.properties != null
|
|
142
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
144
143
|
}
|
|
145
144
|
/**
|
|
146
145
|
* Sets the custom properties of the Connection.
|
|
@@ -164,7 +163,7 @@ export class Connection {
|
|
|
164
163
|
for (let index = 0; index < keys.length; index++) {
|
|
165
164
|
const key = keys[index];
|
|
166
165
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
167
|
-
if (value != null && value.trim() !=
|
|
166
|
+
if (value != null && value.trim() != "") {
|
|
168
167
|
return value;
|
|
169
168
|
}
|
|
170
169
|
}
|
|
@@ -179,14 +178,14 @@ export class Connection {
|
|
|
179
178
|
* @returns The Connection, for chaining
|
|
180
179
|
*/
|
|
181
180
|
setProperty(key, value) {
|
|
182
|
-
if (key == null || key.trim() ==
|
|
181
|
+
if (key == null || key.trim() == "") {
|
|
183
182
|
return this;
|
|
184
183
|
}
|
|
185
184
|
if (this.payload.properties == null) {
|
|
186
185
|
this.payload.properties = {};
|
|
187
186
|
}
|
|
188
187
|
if (!value) {
|
|
189
|
-
value =
|
|
188
|
+
value = "";
|
|
190
189
|
}
|
|
191
190
|
this.payload.properties[key] = value;
|
|
192
191
|
return this;
|
|
@@ -206,7 +205,9 @@ export class Connection {
|
|
|
206
205
|
* Cleans any token property stored in the Connection.
|
|
207
206
|
*/
|
|
208
207
|
clearTokenProperties() {
|
|
209
|
-
this.getPropertyKeys()
|
|
208
|
+
this.getPropertyKeys()
|
|
209
|
+
.filter((key) => key.includes("token"))
|
|
210
|
+
.forEach((key) => this.deleteProperty(key));
|
|
210
211
|
}
|
|
211
212
|
/**
|
|
212
213
|
* Gets the custom properties keys stored in the Connection.
|
|
@@ -233,8 +234,12 @@ export class Connection {
|
|
|
233
234
|
*/
|
|
234
235
|
getIntegrations() {
|
|
235
236
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const
|
|
237
|
-
|
|
237
|
+
const id = this.getId();
|
|
238
|
+
if (!id) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
const integrationsPlain = yield ConnectionService.listIntegrations(id, this.getConfig());
|
|
242
|
+
const integrations = integrationsPlain.map((i) => new Integration(i));
|
|
238
243
|
return integrations;
|
|
239
244
|
});
|
|
240
245
|
}
|
|
@@ -245,7 +250,7 @@ export class Connection {
|
|
|
245
250
|
*/
|
|
246
251
|
create() {
|
|
247
252
|
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
-
this.payload = yield ConnectionService.createConnection(this.payload);
|
|
253
|
+
this.payload = yield ConnectionService.createConnection(this.payload, this.getConfig());
|
|
249
254
|
return this;
|
|
250
255
|
});
|
|
251
256
|
}
|
|
@@ -258,7 +263,7 @@ export class Connection {
|
|
|
258
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
259
264
|
const connectionId = this.getId();
|
|
260
265
|
if (connectionId) {
|
|
261
|
-
this.payload = yield ConnectionService.deleteConnection(connectionId);
|
|
266
|
+
this.payload = yield ConnectionService.deleteConnection(connectionId, this.getConfig());
|
|
262
267
|
}
|
|
263
268
|
return this;
|
|
264
269
|
});
|
|
@@ -10,6 +10,8 @@ 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 { Message } from "./Message.js";
|
|
13
|
+
import { Resource } from "./Resource.js";
|
|
14
|
+
import { Bkper } from "./Bkper.js";
|
|
13
15
|
/**
|
|
14
16
|
* Defines a Conversation on Bkper.
|
|
15
17
|
*
|
|
@@ -17,18 +19,14 @@ import { Message } from "./Message.js";
|
|
|
17
19
|
*
|
|
18
20
|
* @public
|
|
19
21
|
*/
|
|
20
|
-
export class Conversation {
|
|
21
|
-
constructor(agent, payload) {
|
|
22
|
+
export class Conversation extends Resource {
|
|
23
|
+
constructor(agent, payload, config) {
|
|
24
|
+
super(payload || {});
|
|
22
25
|
this.agent = agent;
|
|
23
|
-
this.
|
|
26
|
+
this.config = config;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @returns The wrapped plain json object
|
|
29
|
-
*/
|
|
30
|
-
json() {
|
|
31
|
-
return Object.assign({}, this.payload);
|
|
28
|
+
getConfig() {
|
|
29
|
+
return this.config || Bkper.globalConfig;
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
34
32
|
* Gets the Agent associated to this Conversation.
|
|
@@ -60,7 +58,9 @@ export class Conversation {
|
|
|
60
58
|
* @returns The Date the Conversation was created
|
|
61
59
|
*/
|
|
62
60
|
getCreatedAt() {
|
|
63
|
-
return this.payload.createdAt
|
|
61
|
+
return this.payload.createdAt
|
|
62
|
+
? new Date(new Number(this.payload.createdAt).valueOf())
|
|
63
|
+
: undefined;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Gets the Date the Conversation was last updated.
|
|
@@ -68,7 +68,9 @@ export class Conversation {
|
|
|
68
68
|
* @returns The Date the Conversation was last updated
|
|
69
69
|
*/
|
|
70
70
|
getUpdatedAt() {
|
|
71
|
-
return this.payload.updatedAt
|
|
71
|
+
return this.payload.updatedAt
|
|
72
|
+
? new Date(new Number(this.payload.updatedAt).valueOf())
|
|
73
|
+
: undefined;
|
|
72
74
|
}
|
|
73
75
|
/**
|
|
74
76
|
* Gets the Messages that compose this Conversation.
|
|
@@ -82,12 +84,12 @@ export class Conversation {
|
|
|
82
84
|
}
|
|
83
85
|
const conversationId = this.getId();
|
|
84
86
|
if (!conversationId) {
|
|
85
|
-
throw new Error(
|
|
87
|
+
throw new Error("Conversation id null!");
|
|
86
88
|
}
|
|
87
89
|
if (!this.messagesMap) {
|
|
88
90
|
this.messagesMap = new Map();
|
|
89
91
|
}
|
|
90
|
-
const messagePayloads = yield ConversationService.getMessages(conversationId);
|
|
92
|
+
const messagePayloads = yield ConversationService.getMessages(conversationId, this.getConfig());
|
|
91
93
|
for (const payload of messagePayloads) {
|
|
92
94
|
this.updateMessagesCache(new Message(this, payload));
|
|
93
95
|
}
|
|
@@ -117,9 +119,9 @@ export class Conversation {
|
|
|
117
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
120
|
const agentId = this.agent.getId();
|
|
119
121
|
if (!agentId) {
|
|
120
|
-
throw new Error(
|
|
122
|
+
throw new Error("Agent id null!");
|
|
121
123
|
}
|
|
122
|
-
this.payload = yield ConversationService.createConversation(agentId, this.payload);
|
|
124
|
+
this.payload = yield ConversationService.createConversation(agentId, this.payload, this.getConfig());
|
|
123
125
|
// Update agent
|
|
124
126
|
if (this.payload.agent) {
|
|
125
127
|
this.agent = new Agent(this.payload.agent);
|
package/lib/model/File.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 FileService from
|
|
10
|
+
import * as FileService from "../service/file-service.js";
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
11
12
|
/**
|
|
12
13
|
*
|
|
13
14
|
* This class defines a File uploaded to a [[Book]].
|
|
@@ -16,21 +17,13 @@ import * as FileService from '../service/file-service.js';
|
|
|
16
17
|
*
|
|
17
18
|
* @public
|
|
18
19
|
*/
|
|
19
|
-
export class File {
|
|
20
|
+
export class File extends Resource {
|
|
20
21
|
constructor(book, payload) {
|
|
22
|
+
super(payload || { createdAt: `${Date.now()}` });
|
|
21
23
|
this.book = book;
|
|
22
|
-
this.payload = payload || {
|
|
23
|
-
createdAt: `${Date.now()}`
|
|
24
|
-
};
|
|
25
|
-
;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
* @returns An immutable copy of the json payload
|
|
31
|
-
*/
|
|
32
|
-
json() {
|
|
33
|
-
return Object.assign({}, this.payload);
|
|
25
|
+
getConfig() {
|
|
26
|
+
return this.book.getConfig();
|
|
34
27
|
}
|
|
35
28
|
/**
|
|
36
29
|
* Gets the File id.
|
|
@@ -86,8 +79,11 @@ export class File {
|
|
|
86
79
|
getContent() {
|
|
87
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
81
|
const id = this.getId();
|
|
89
|
-
if (this.getId() != null &&
|
|
90
|
-
this.payload
|
|
82
|
+
if (this.getId() != null &&
|
|
83
|
+
(this.payload == null || this.payload.content == null) &&
|
|
84
|
+
this.book &&
|
|
85
|
+
id) {
|
|
86
|
+
this.payload = yield FileService.getFile(this.book.getId(), id, this.getConfig());
|
|
91
87
|
}
|
|
92
88
|
return this.payload.content;
|
|
93
89
|
});
|
|
@@ -125,7 +121,8 @@ export class File {
|
|
|
125
121
|
* @returns The custom properties object
|
|
126
122
|
*/
|
|
127
123
|
getProperties() {
|
|
128
|
-
return this.payload.properties != null
|
|
124
|
+
return this.payload.properties != null
|
|
125
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
129
126
|
}
|
|
130
127
|
/**
|
|
131
128
|
* Sets the custom properties of the File.
|
|
@@ -149,7 +146,7 @@ export class File {
|
|
|
149
146
|
for (let index = 0; index < keys.length; index++) {
|
|
150
147
|
const key = keys[index];
|
|
151
148
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
152
|
-
if (value != null && value.trim() !=
|
|
149
|
+
if (value != null && value.trim() != "") {
|
|
153
150
|
return value;
|
|
154
151
|
}
|
|
155
152
|
}
|
|
@@ -164,14 +161,14 @@ export class File {
|
|
|
164
161
|
* @returns This File, for chaining
|
|
165
162
|
*/
|
|
166
163
|
setProperty(key, value) {
|
|
167
|
-
if (key == null || key.trim() ==
|
|
164
|
+
if (key == null || key.trim() == "") {
|
|
168
165
|
return this;
|
|
169
166
|
}
|
|
170
167
|
if (this.payload.properties == null) {
|
|
171
168
|
this.payload.properties = {};
|
|
172
169
|
}
|
|
173
170
|
if (!value) {
|
|
174
|
-
value =
|
|
171
|
+
value = "";
|
|
175
172
|
}
|
|
176
173
|
this.payload.properties[key] = value;
|
|
177
174
|
return this;
|
|
@@ -195,7 +192,7 @@ export class File {
|
|
|
195
192
|
create() {
|
|
196
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
197
194
|
if (this.book) {
|
|
198
|
-
this.payload = yield FileService.createFile(this.book.getId(), this.payload);
|
|
195
|
+
this.payload = yield FileService.createFile(this.book.getId(), this.payload, this.getConfig());
|
|
199
196
|
}
|
|
200
197
|
return this;
|
|
201
198
|
});
|
package/lib/model/Group.js
CHANGED
|
@@ -7,9 +7,10 @@ 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 GroupService from
|
|
10
|
+
import * as GroupService from "../service/group-service.js";
|
|
11
11
|
import { normalizeText } from "../utils.js";
|
|
12
|
-
import { Account } from
|
|
12
|
+
import { Account } from "./Account.js";
|
|
13
|
+
import { Resource } from "./Resource.js";
|
|
13
14
|
/**
|
|
14
15
|
* This class defines a Group of [[Accounts]].
|
|
15
16
|
*
|
|
@@ -19,22 +20,15 @@ import { Account } from './Account.js';
|
|
|
19
20
|
*
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
|
-
export class Group {
|
|
23
|
+
export class Group extends Resource {
|
|
23
24
|
constructor(book, payload) {
|
|
25
|
+
super(payload || { createdAt: `${Date.now()}` });
|
|
24
26
|
/** @internal */
|
|
25
27
|
this.children = new Map();
|
|
26
28
|
this.book = book;
|
|
27
|
-
this.payload = payload || {
|
|
28
|
-
createdAt: `${Date.now()}`
|
|
29
|
-
};
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
* @returns An immutable copy of the json payload
|
|
35
|
-
*/
|
|
36
|
-
json() {
|
|
37
|
-
return Object.assign({}, this.payload);
|
|
30
|
+
getConfig() {
|
|
31
|
+
return this.book.getConfig();
|
|
38
32
|
}
|
|
39
33
|
/**
|
|
40
34
|
* Gets the id of this Group.
|
|
@@ -108,11 +102,15 @@ export class Group {
|
|
|
108
102
|
if (this.accounts) {
|
|
109
103
|
return Array.from(this.accounts.values());
|
|
110
104
|
}
|
|
111
|
-
|
|
105
|
+
const id = this.getId();
|
|
106
|
+
if (!id) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
let accountsPlain = yield GroupService.getAccounts(this.book.getId(), id, this.getConfig());
|
|
112
110
|
if (!accountsPlain) {
|
|
113
111
|
return [];
|
|
114
112
|
}
|
|
115
|
-
let accounts = accountsPlain.map(acc => new Account(this.book, acc));
|
|
113
|
+
let accounts = accountsPlain.map((acc) => new Account(this.book, acc));
|
|
116
114
|
return accounts;
|
|
117
115
|
});
|
|
118
116
|
}
|
|
@@ -130,7 +128,8 @@ export class Group {
|
|
|
130
128
|
* @returns The custom properties as a key/value object
|
|
131
129
|
*/
|
|
132
130
|
getProperties() {
|
|
133
|
-
return this.payload.properties != null
|
|
131
|
+
return this.payload.properties != null
|
|
132
|
+
? Object.assign({}, this.payload.properties) : {};
|
|
134
133
|
}
|
|
135
134
|
/**
|
|
136
135
|
* Sets the custom properties of the Group
|
|
@@ -154,7 +153,7 @@ export class Group {
|
|
|
154
153
|
for (let index = 0; index < keys.length; index++) {
|
|
155
154
|
const key = keys[index];
|
|
156
155
|
let value = this.payload.properties != null ? this.payload.properties[key] : null;
|
|
157
|
-
if (value != null && value.trim() !=
|
|
156
|
+
if (value != null && value.trim() != "") {
|
|
158
157
|
return value;
|
|
159
158
|
}
|
|
160
159
|
}
|
|
@@ -169,14 +168,14 @@ export class Group {
|
|
|
169
168
|
* @returns This Group, for chaining
|
|
170
169
|
*/
|
|
171
170
|
setProperty(key, value) {
|
|
172
|
-
if (key == null || key.trim() ==
|
|
171
|
+
if (key == null || key.trim() == "") {
|
|
173
172
|
return this;
|
|
174
173
|
}
|
|
175
174
|
if (this.payload.properties == null) {
|
|
176
175
|
this.payload.properties = {};
|
|
177
176
|
}
|
|
178
177
|
if (!value) {
|
|
179
|
-
value =
|
|
178
|
+
value = "";
|
|
180
179
|
}
|
|
181
180
|
this.payload.properties[key] = value;
|
|
182
181
|
return this;
|
|
@@ -252,7 +251,11 @@ export class Group {
|
|
|
252
251
|
*/
|
|
253
252
|
setParent(group) {
|
|
254
253
|
if (group) {
|
|
255
|
-
this.payload.parent = {
|
|
254
|
+
this.payload.parent = {
|
|
255
|
+
id: group.getId(),
|
|
256
|
+
name: group.getName(),
|
|
257
|
+
normalizedName: group.getNormalizedName(),
|
|
258
|
+
};
|
|
256
259
|
}
|
|
257
260
|
else {
|
|
258
261
|
this.payload.parent = undefined;
|
|
@@ -298,7 +301,7 @@ export class Group {
|
|
|
298
301
|
* @returns A set of descendant Group IDs
|
|
299
302
|
*/
|
|
300
303
|
getDescendantTreeIds() {
|
|
301
|
-
return new Set(Array.from(this.getDescendants()).map(g => g.getId() || ""));
|
|
304
|
+
return new Set(Array.from(this.getDescendants()).map((g) => g.getId() || ""));
|
|
302
305
|
}
|
|
303
306
|
/**
|
|
304
307
|
* Checks if the Group has any children.
|
|
@@ -416,7 +419,7 @@ export class Group {
|
|
|
416
419
|
*/
|
|
417
420
|
create() {
|
|
418
421
|
return __awaiter(this, void 0, void 0, function* () {
|
|
419
|
-
this.payload = yield GroupService.createGroup(this.book.getId(), this.payload);
|
|
422
|
+
this.payload = yield GroupService.createGroup(this.book.getId(), this.payload, this.getConfig());
|
|
420
423
|
this.updateGroupCache();
|
|
421
424
|
return this;
|
|
422
425
|
});
|
|
@@ -428,7 +431,7 @@ export class Group {
|
|
|
428
431
|
*/
|
|
429
432
|
update() {
|
|
430
433
|
return __awaiter(this, void 0, void 0, function* () {
|
|
431
|
-
this.payload = yield GroupService.updateGroup(this.book.getId(), this.payload);
|
|
434
|
+
this.payload = yield GroupService.updateGroup(this.book.getId(), this.payload, this.getConfig());
|
|
432
435
|
this.updateGroupCache();
|
|
433
436
|
return this;
|
|
434
437
|
});
|
|
@@ -440,7 +443,7 @@ export class Group {
|
|
|
440
443
|
*/
|
|
441
444
|
remove() {
|
|
442
445
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
-
this.payload = yield GroupService.deleteGroup(this.book.getId(), this.payload);
|
|
446
|
+
this.payload = yield GroupService.deleteGroup(this.book.getId(), this.payload, this.getConfig());
|
|
444
447
|
this.updateGroupCache(true);
|
|
445
448
|
return this;
|
|
446
449
|
});
|
package/lib/model/Integration.js
CHANGED
|
@@ -7,23 +7,21 @@ 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 IntegrationService from
|
|
10
|
+
import * as IntegrationService from "../service/integration-service.js";
|
|
11
|
+
import { Resource } from "./Resource.js";
|
|
12
|
+
import { Bkper } from "./Bkper.js";
|
|
11
13
|
/**
|
|
12
14
|
* This class defines a Integration from an [[User]] to an external service.
|
|
13
15
|
*
|
|
14
16
|
* @public
|
|
15
17
|
*/
|
|
16
|
-
export class Integration {
|
|
17
|
-
constructor(payload) {
|
|
18
|
-
|
|
18
|
+
export class Integration extends Resource {
|
|
19
|
+
constructor(payload, config) {
|
|
20
|
+
super(payload || {});
|
|
21
|
+
this.config = config;
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @returns An immutable copy of the json payload
|
|
24
|
-
*/
|
|
25
|
-
json() {
|
|
26
|
-
return Object.assign({}, this.payload);
|
|
23
|
+
getConfig() {
|
|
24
|
+
return this.config || Bkper.globalConfig;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Gets the [[Book]] id of the Integration.
|
|
@@ -95,7 +93,8 @@ export class Integration {
|
|
|
95
93
|
* @returns Object with key/value pair properties
|
|
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 Integration.
|
|
@@ -119,7 +118,7 @@ export class Integration {
|
|
|
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 Integration {
|
|
|
134
133
|
* @returns The Integration, 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;
|
|
@@ -167,7 +166,7 @@ export class Integration {
|
|
|
167
166
|
const bookId = this.getBookId();
|
|
168
167
|
const integrationId = this.getId();
|
|
169
168
|
if (bookId && integrationId) {
|
|
170
|
-
this.payload = yield IntegrationService.deleteIntegration(bookId, integrationId);
|
|
169
|
+
this.payload = yield IntegrationService.deleteIntegration(bookId, integrationId, this.getConfig());
|
|
171
170
|
}
|
|
172
171
|
return this;
|
|
173
172
|
});
|