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