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
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { HttpBooksApiV5Request } from "./http-api-request.js";
11
11
  import { HttpRequest } from "./http-request.js";
12
- export function getBalances(bookId, query) {
12
+ export function getBalances(bookId, query, config) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  var _a;
15
- let response = yield new HttpBooksApiV5Request(`${bookId}/balances`).addParam('query', query).addParam('time', Date.now()).fetch();
15
+ let response = yield new HttpBooksApiV5Request(`${bookId}/balances`, config).addParam('query', query).addParam('time', Date.now()).fetch();
16
16
  const balancesUrl = (_a = response.data) === null || _a === void 0 ? void 0 : _a.balancesUrl; // Expected for large payloads
17
17
  if (balancesUrl) {
18
18
  const balancesResponse = yield new HttpRequest(balancesUrl).setMethod('GET').execute();
@@ -8,9 +8,9 @@ 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 loadBooks(query) {
11
+ export function loadBooks(query, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
- let request = new HttpBooksApiV5Request('');
13
+ let request = new HttpBooksApiV5Request('', config);
14
14
  if (query) {
15
15
  request.addParam('query', query);
16
16
  }
@@ -26,44 +26,44 @@ export function loadBooks(query) {
26
26
  return booksJson;
27
27
  });
28
28
  }
29
- export function loadBook(bookId, loadAccounts, loadGroups) {
29
+ export function loadBook(bookId, loadAccounts, loadGroups, config) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  if (bookId == null) {
32
32
  throw new Error("Book id null!");
33
33
  }
34
34
  loadAccounts = loadAccounts || false;
35
35
  loadGroups = loadGroups || false;
36
- let response = yield new HttpBooksApiV5Request(bookId).addParam('loadAccounts', loadAccounts).addParam('loadGroups', loadGroups).fetch();
36
+ let response = yield new HttpBooksApiV5Request(bookId, config).addParam('loadAccounts', loadAccounts).addParam('loadGroups', loadGroups).fetch();
37
37
  return response.data;
38
38
  });
39
39
  }
40
- export function createBook(book) {
40
+ export function createBook(book, config) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
- let response = yield new HttpBooksApiV5Request('').setMethod('POST').setPayload(book).fetch();
42
+ let response = yield new HttpBooksApiV5Request('', config).setMethod('POST').setPayload(book).fetch();
43
43
  return response.data;
44
44
  });
45
45
  }
46
- export function updateBook(bookId, book) {
46
+ export function updateBook(bookId, book, config) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- var response = yield new HttpBooksApiV5Request(`${bookId}`).setMethod('PUT').setPayload(book).fetch();
48
+ var response = yield new HttpBooksApiV5Request(`${bookId}`, config).setMethod('PUT').setPayload(book).fetch();
49
49
  return response.data;
50
50
  });
51
51
  }
52
- export function audit(bookId) {
52
+ export function audit(bookId, config) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- new HttpBooksApiV5Request(`${bookId}/audit`).setMethod('PATCH').fetch();
54
+ new HttpBooksApiV5Request(`${bookId}/audit`, config).setMethod('PATCH').fetch();
55
55
  });
56
56
  }
57
- export function getApps(bookId) {
57
+ export function getApps(bookId, config) {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
59
  var _a;
60
- let response = yield new HttpBooksApiV5Request(`${bookId}/apps`).setMethod('GET').fetch();
60
+ let response = yield new HttpBooksApiV5Request(`${bookId}/apps`, config).setMethod('GET').fetch();
61
61
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
62
62
  });
63
63
  }
64
- export function copyBook(bookId, name, copyTransactions, fromDate) {
64
+ export function copyBook(bookId, name, copyTransactions, fromDate, config) {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
- const request = new HttpBooksApiV5Request(`${bookId}/copy`).setMethod('POST').addParam('name', name);
66
+ const request = new HttpBooksApiV5Request(`${bookId}/copy`, config).setMethod('POST').addParam('name', name);
67
67
  if (copyTransactions) {
68
68
  request.addParam('copyTransactions', copyTransactions);
69
69
  if (fromDate) {
@@ -8,16 +8,16 @@ 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 listCollaborators(bookId) {
11
+ export function listCollaborators(bookId, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
13
  var _a;
14
- const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators`).setMethod('GET').fetch();
14
+ const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators`, config).setMethod('GET').fetch();
15
15
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
16
16
  });
17
17
  }
18
- export function addOrUpdateCollaborator(bookId, collaborator, message) {
18
+ export function addOrUpdateCollaborator(bookId, collaborator, message, config) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- let request = new HttpBooksApiV5Request(`${bookId}/collaborators`).setMethod('POST').setPayload(collaborator);
20
+ let request = new HttpBooksApiV5Request(`${bookId}/collaborators`, config).setMethod('POST').setPayload(collaborator);
21
21
  if (message) {
22
22
  request = request.addParam('message', message);
23
23
  }
@@ -25,9 +25,9 @@ export function addOrUpdateCollaborator(bookId, collaborator, message) {
25
25
  return response.data;
26
26
  });
27
27
  }
28
- export function removeCollaborator(bookId, email) {
28
+ export function removeCollaborator(bookId, email, config) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/${email}`).setMethod('DELETE').fetch();
30
+ const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/${email}`, config).setMethod('DELETE').fetch();
31
31
  return response.data;
32
32
  });
33
33
  }
@@ -8,43 +8,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { HttpApiV5Request } from "./http-api-request.js";
11
- export function loadCollections() {
11
+ export function loadCollections(config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
13
  var _a;
14
- let response = yield new HttpApiV5Request('collections').fetch();
14
+ let response = yield new HttpApiV5Request('collections', config).fetch();
15
15
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
16
16
  });
17
17
  }
18
- export function createCollection(payload) {
18
+ export function createCollection(payload, config) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- let response = yield new HttpApiV5Request('collections').setMethod('POST').setPayload(payload).fetch();
20
+ let response = yield new HttpApiV5Request('collections', config).setMethod('POST').setPayload(payload).fetch();
21
21
  return response.data;
22
22
  });
23
23
  }
24
- export function updateCollection(payload) {
24
+ export function updateCollection(payload, config) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- let response = yield new HttpApiV5Request('collections').setMethod('PUT').setPayload(payload).fetch();
26
+ let response = yield new HttpApiV5Request('collections', config).setMethod('PUT').setPayload(payload).fetch();
27
27
  return response.data;
28
28
  });
29
29
  }
30
- export function deleteCollection(payload) {
30
+ export function deleteCollection(payload, config) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  var _a;
33
- let response = yield new HttpApiV5Request(`collections/${payload.id}`).setMethod('DELETE').fetch();
33
+ let response = yield new HttpApiV5Request(`collections/${payload.id}`, config).setMethod('DELETE').fetch();
34
34
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
35
35
  });
36
36
  }
37
- export function addBooksToCollection(collectionId, payload) {
37
+ export function addBooksToCollection(collectionId, payload, config) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
39
  var _a;
40
- let response = yield new HttpApiV5Request(`collections/${collectionId}/books/add`).setMethod('PATCH').setPayload(payload).fetch();
40
+ let response = yield new HttpApiV5Request(`collections/${collectionId}/books/add`, config).setMethod('PATCH').setPayload(payload).fetch();
41
41
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
42
42
  });
43
43
  }
44
- export function removeBooksFromCollection(collectionId, payload) {
44
+ export function removeBooksFromCollection(collectionId, payload, config) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  var _a;
47
- let response = yield new HttpApiV5Request(`collections/${collectionId}/books/remove`).setMethod('PATCH').setPayload(payload).fetch();
47
+ let response = yield new HttpApiV5Request(`collections/${collectionId}/books/remove`, config).setMethod('PATCH').setPayload(payload).fetch();
48
48
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
49
49
  });
50
50
  }
@@ -8,56 +8,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { HttpApiV5Request } from "./http-api-request.js";
11
- export function getConnection(id) {
11
+ export function getConnection(id, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
- const res = yield new HttpApiV5Request(`user/connections/${id}`)
13
+ const res = yield new HttpApiV5Request(`user/connections/${id}`, config)
14
14
  .setMethod('GET')
15
15
  .fetch();
16
16
  return res.data;
17
17
  });
18
18
  }
19
- export function listConnections() {
19
+ export function listConnections(config) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  var _a;
22
- const res = yield new HttpApiV5Request(`user/connections`)
22
+ const res = yield new HttpApiV5Request(`user/connections`, config)
23
23
  .setMethod('GET')
24
24
  .fetch();
25
25
  return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || [];
26
26
  });
27
27
  }
28
- export function createConnection(connection) {
28
+ export function createConnection(connection, config) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- const res = yield new HttpApiV5Request(`user/connections`)
30
+ const res = yield new HttpApiV5Request(`user/connections`, config)
31
31
  .setPayload(connection)
32
32
  .setMethod('POST')
33
33
  .fetch();
34
34
  return res.data;
35
35
  });
36
36
  }
37
- export function updateConnection(connection) {
37
+ export function updateConnection(connection, config) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- const res = yield new HttpApiV5Request(`user/connections`)
39
+ const res = yield new HttpApiV5Request(`user/connections`, config)
40
40
  .setPayload(connection)
41
41
  .setMethod('PUT')
42
42
  .fetch();
43
43
  return res.data;
44
44
  });
45
45
  }
46
- export function deleteConnection(id) {
46
+ export function deleteConnection(id, config) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- const res = yield new HttpApiV5Request(`user/connections/${id}`)
48
+ const res = yield new HttpApiV5Request(`user/connections/${id}`, config)
49
49
  .setMethod('DELETE')
50
50
  .fetch();
51
51
  return res.data;
52
52
  });
53
53
  }
54
- export function listIntegrations(connectionId) {
54
+ export function listIntegrations(connectionId, config) {
55
55
  return __awaiter(this, void 0, void 0, function* () {
56
56
  var _a;
57
- if (!connectionId) {
58
- return [];
59
- }
60
- const res = yield new HttpApiV5Request(`user/connections/${connectionId}/integrations`)
57
+ const res = yield new HttpApiV5Request(`user/connections/${connectionId}/integrations`, config)
61
58
  .setMethod('GET')
62
59
  .fetch();
63
60
  return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || [];
@@ -8,35 +8,35 @@ 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 getConversations() {
11
+ export function getConversations(config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
13
  var _a;
14
- const response = yield new HttpApiRequest(`v5/apps/conversations`).setMethod('GET').fetch();
14
+ const response = yield new HttpApiRequest(`v5/apps/conversations`, config).setMethod('GET').fetch();
15
15
  return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
16
16
  });
17
17
  }
18
- export function createConversation(agentId, conversation) {
18
+ export function createConversation(agentId, conversation, config) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const response = yield new HttpApiRequest(`v5/apps/${agentId}/conversations`).setMethod('POST').setPayload(conversation).fetch();
20
+ const response = yield new HttpApiRequest(`v5/apps/${agentId}/conversations`, config).setMethod('POST').setPayload(conversation).fetch();
21
21
  return response.data;
22
22
  });
23
23
  }
24
- export function getMessages(conversationId) {
24
+ export function getMessages(conversationId, config) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  var _a;
27
- const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`).setMethod('GET').fetch();
27
+ const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`, config).setMethod('GET').fetch();
28
28
  return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
29
29
  });
30
30
  }
31
- export function createMessage(conversationId, message) {
31
+ export function createMessage(conversationId, message, config) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`).setMethod('POST').setPayload(message).fetch();
33
+ const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`, config).setMethod('POST').setPayload(message).fetch();
34
34
  return response.data;
35
35
  });
36
36
  }
37
- export function streamMessage(conversationId, message) {
37
+ export function streamMessage(conversationId, message, config) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- new HttpApiRequest(`v5/apps/conversations/${conversationId}/stream`).setMethod('POST').setPayload(message).fetch();
39
+ new HttpApiRequest(`v5/apps/conversations/${conversationId}/stream`, config).setMethod('POST').setPayload(message).fetch();
40
40
  });
41
41
  }
42
42
  //# sourceMappingURL=conversation-service.js.map
@@ -8,9 +8,9 @@ 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 listEvents(book, afterDate, beforeDate, onError, resourceId, limit, cursor) {
11
+ export function listEvents(book, afterDate, beforeDate, onError, resourceId, limit, cursor, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
- let request = new HttpBooksApiV5Request(`${book.getId()}/events`);
13
+ let request = new HttpBooksApiV5Request(`${book.getId()}/events`, config);
14
14
  request.addParam('after', afterDate);
15
15
  request.addParam('before', beforeDate);
16
16
  request.addParam('error', onError);
@@ -23,21 +23,21 @@ export function listEvents(book, afterDate, beforeDate, onError, resourceId, lim
23
23
  return response.data;
24
24
  });
25
25
  }
26
- export function replayBotResponse(book, eventId, agentId) {
26
+ export function replayBotResponse(book, eventId, agentId, config) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`).setMethod('PUT').fetch();
28
+ const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`, config).setMethod('PUT').fetch();
29
29
  return response.data;
30
30
  });
31
31
  }
32
- export function deleteBotResponse(book, eventId, agentId) {
32
+ export function deleteBotResponse(book, eventId, agentId, config) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`).setMethod('DELETE').fetch();
34
+ const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`, config).setMethod('DELETE').fetch();
35
35
  return response.data;
36
36
  });
37
37
  }
38
- export function replayEventsBatch(book, eventList, errorsOnly) {
38
+ export function replayEventsBatch(book, eventList, errorsOnly, config) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
- let request = new HttpBooksApiV5Request(`${book.getId()}/events/replay/batch`).setMethod('PATCH').setPayload(eventList);
40
+ let request = new HttpBooksApiV5Request(`${book.getId()}/events/replay/batch`, config).setMethod('PATCH').setPayload(eventList);
41
41
  if (errorsOnly) {
42
42
  request.addParam('errorsOnly', errorsOnly);
43
43
  }
@@ -8,15 +8,15 @@ 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 createFile(bookId, file) {
11
+ export function createFile(bookId, file, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
- var response = yield new HttpBooksApiV5Request(`${bookId}/files`).setMethod('POST').setPayload(file).fetch();
13
+ var response = yield new HttpBooksApiV5Request(`${bookId}/files`, config).setMethod('POST').setPayload(file).fetch();
14
14
  return response.data;
15
15
  });
16
16
  }
17
- export function getFile(bookId, id) {
17
+ export function getFile(bookId, id, config) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- var response = yield new HttpBooksApiV5Request(`${bookId}/files/${id}`).setMethod('GET').fetch();
19
+ var response = yield new HttpBooksApiV5Request(`${bookId}/files/${id}`, config).setMethod('GET').fetch();
20
20
  return response.data;
21
21
  });
22
22
  }
@@ -8,41 +8,41 @@ 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 createGroup(bookId, group) {
11
+ export function createGroup(bookId, group, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups`).setMethod('POST').setPayload(group).fetch();
13
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups`, config).setMethod('POST').setPayload(group).fetch();
14
14
  return response.data;
15
15
  });
16
16
  }
17
- export function createGroups(bookId, payload) {
17
+ export function createGroups(bookId, payload, config) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  var _a;
20
- const response = yield new HttpBooksApiV5Request(`${bookId}/groups/batch`).setMethod('POST').setPayload(payload).fetch();
20
+ const response = yield new HttpBooksApiV5Request(`${bookId}/groups/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 updateGroup(bookId, group) {
24
+ export function updateGroup(bookId, group, config) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups`).setMethod('PUT').setPayload(group).fetch();
26
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups`, config).setMethod('PUT').setPayload(group).fetch();
27
27
  return response.data;
28
28
  });
29
29
  }
30
- export function deleteGroup(bookId, group) {
30
+ export function deleteGroup(bookId, group, config) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${group.id}`).setMethod('DELETE').fetch();
32
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${group.id}`, config).setMethod('DELETE').fetch();
33
33
  return response.data;
34
34
  });
35
35
  }
36
- export function getGroupsByAccountId(bookId, accountId) {
36
+ export function getGroupsByAccountId(bookId, accountId, config) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  var _a;
39
- var response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${accountId}/groups`).setMethod('GET').fetch();
39
+ var response = yield new HttpBooksApiV5Request(`${bookId}/accounts/${accountId}/groups`, config).setMethod('GET').fetch();
40
40
  return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
41
41
  });
42
42
  }
43
- export function getGroups(bookId) {
43
+ export function getGroups(bookId, config) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups`).setMethod('GET').fetch();
45
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups`, config).setMethod('GET').fetch();
46
46
  var groupsPlain = response.data;
47
47
  if (!(groupsPlain === null || groupsPlain === void 0 ? void 0 : groupsPlain.items)) {
48
48
  return [];
@@ -50,18 +50,18 @@ export function getGroups(bookId) {
50
50
  return groupsPlain.items;
51
51
  });
52
52
  }
53
- export function getGroup(bookId, idOrName) {
53
+ export function getGroup(bookId, idOrName, config) {
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}`).setMethod('GET').fetch();
55
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}`, config).setMethod('GET').fetch();
56
56
  return response.data;
57
57
  });
58
58
  }
59
- export function getAccounts(bookId, idOrName) {
59
+ export function getAccounts(bookId, idOrName, config) {
60
60
  return __awaiter(this, void 0, void 0, function* () {
61
61
  if (!idOrName) {
62
62
  return [];
63
63
  }
64
- var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}/accounts`).setMethod('GET').fetch();
64
+ var response = yield new HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}/accounts`, config).setMethod('GET').fetch();
65
65
  var accountsPlain = response.data;
66
66
  if (!(accountsPlain === null || accountsPlain === void 0 ? void 0 : accountsPlain.items)) {
67
67
  return [];
@@ -7,11 +7,13 @@ 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 { HttpRequest } from './http-request.js';
10
+ import { HttpRequest } from "./http-request.js";
11
11
  export class HttpApiRequest extends HttpRequest {
12
- constructor(path) {
13
- super(`${HttpApiRequest.config.apiBaseUrl || "https://app.bkper.com/_ah/api/bkper"}/${path}`);
12
+ constructor(path, config) {
13
+ const effectiveConfig = config;
14
+ super(`${effectiveConfig.apiBaseUrl || "https://app.bkper.com/_ah/api/bkper"}/${path}`);
14
15
  this.retry = 0;
16
+ this.config = config;
15
17
  }
16
18
  fetch() {
17
19
  const _super = Object.create(null, {
@@ -19,8 +21,8 @@ export class HttpApiRequest extends HttpRequest {
19
21
  });
20
22
  return __awaiter(this, void 0, void 0, function* () {
21
23
  this.addCustomHeaders();
22
- this.setHeader('Authorization', `Bearer ${yield getAccessToken()}`);
23
- this.addParam('key', yield getApiKey());
24
+ this.setHeader("Authorization", `Bearer ${yield this.getAccessToken()}`);
25
+ this.addParam("key", yield this.getApiKey());
24
26
  try {
25
27
  let resp = yield _super.execute.call(this);
26
28
  if (resp.status >= 200 && resp.status < 300) {
@@ -31,8 +33,9 @@ export class HttpApiRequest extends HttpRequest {
31
33
  }
32
34
  else if (resp.status != 400 && this.retry <= 3) {
33
35
  this.retry++;
34
- if (HttpApiRequest.config.requestRetryHandler) {
35
- yield HttpApiRequest.config.requestRetryHandler(resp.status, resp.data, this.retry);
36
+ const effectiveConfig = this.config;
37
+ if (effectiveConfig.requestRetryHandler) {
38
+ yield effectiveConfig.requestRetryHandler(resp.status, resp.data, this.retry);
36
39
  }
37
40
  else {
38
41
  console.log(`${JSON.stringify(resp.data)} - Retrying... `);
@@ -44,8 +47,8 @@ export class HttpApiRequest extends HttpRequest {
44
47
  const errorObj = {
45
48
  response: {
46
49
  status: resp.status,
47
- data: resp.data
48
- }
50
+ data: resp.data,
51
+ },
49
52
  };
50
53
  throw this.handleError(errorObj);
51
54
  }
@@ -56,12 +59,13 @@ export class HttpApiRequest extends HttpRequest {
56
59
  throw error;
57
60
  }
58
61
  // Network error or fetch failure
59
- if (error instanceof TypeError && error.message.includes('fetch')) {
62
+ if (error instanceof TypeError && error.message.includes("fetch")) {
60
63
  // Network error - retry if within retry limit
61
64
  if (this.retry <= 3) {
62
65
  this.retry++;
63
- if (HttpApiRequest.config.requestRetryHandler) {
64
- yield HttpApiRequest.config.requestRetryHandler(520, undefined, this.retry);
66
+ const effectiveConfig = this.config;
67
+ if (effectiveConfig.requestRetryHandler) {
68
+ yield effectiveConfig.requestRetryHandler(520, undefined, this.retry);
65
69
  }
66
70
  else {
67
71
  console.log(`Network error - Retrying... `);
@@ -70,14 +74,17 @@ export class HttpApiRequest extends HttpRequest {
70
74
  }
71
75
  }
72
76
  // Other errors
73
- console.log('Error', error.message);
77
+ console.log("Error", error.message);
74
78
  throw this.handleError(error);
75
79
  }
76
80
  });
77
81
  }
78
82
  handleError(err) {
79
83
  var _a, _b, _c;
80
- const customError = HttpApiRequest.config.requestErrorHandler ? HttpApiRequest.config.requestErrorHandler(err) : undefined;
84
+ const effectiveConfig = this.config;
85
+ const customError = effectiveConfig.requestErrorHandler
86
+ ? effectiveConfig.requestErrorHandler(err)
87
+ : undefined;
81
88
  if (customError) {
82
89
  return customError;
83
90
  }
@@ -94,46 +101,48 @@ export class HttpApiRequest extends HttpRequest {
94
101
  }
95
102
  addCustomHeaders() {
96
103
  return __awaiter(this, void 0, void 0, function* () {
97
- if (HttpApiRequest.config.requestHeadersProvider) {
98
- const headers = yield HttpApiRequest.config.requestHeadersProvider();
104
+ const effectiveConfig = this.config;
105
+ if (effectiveConfig.requestHeadersProvider) {
106
+ const headers = yield effectiveConfig.requestHeadersProvider();
99
107
  Object.entries(headers).forEach(([key, value]) => this.setHeader(key, value));
100
108
  }
101
109
  });
102
110
  }
103
- }
104
- HttpApiRequest.config = {};
105
- function getApiKey() {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- if (HttpApiRequest.config.apiKeyProvider) {
108
- return yield HttpApiRequest.config.apiKeyProvider();
109
- }
110
- return null;
111
- });
112
- }
113
- function getAccessToken() {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- let token = undefined;
116
- if (HttpApiRequest.config.oauthTokenProvider) {
117
- token = yield HttpApiRequest.config.oauthTokenProvider();
118
- }
119
- else {
120
- console.warn(`Token provider NOT configured!`);
121
- }
122
- if (token) {
123
- token = token.replace('Bearer ', '');
124
- token = token.replace('bearer ', '');
125
- }
126
- return token;
127
- });
111
+ getApiKey() {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const effectiveConfig = this.config;
114
+ if (effectiveConfig.apiKeyProvider) {
115
+ return yield effectiveConfig.apiKeyProvider();
116
+ }
117
+ return null;
118
+ });
119
+ }
120
+ getAccessToken() {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ let token = undefined;
123
+ const effectiveConfig = this.config;
124
+ if (effectiveConfig.oauthTokenProvider) {
125
+ token = yield effectiveConfig.oauthTokenProvider();
126
+ }
127
+ else {
128
+ console.warn(`Token provider NOT configured!`);
129
+ }
130
+ if (token) {
131
+ token = token.replace("Bearer ", "");
132
+ token = token.replace("bearer ", "");
133
+ }
134
+ return token;
135
+ });
136
+ }
128
137
  }
129
138
  export class HttpBooksApiV5Request extends HttpApiRequest {
130
- constructor(service) {
131
- super(`v5/books/${service}`);
139
+ constructor(service, config) {
140
+ super(`v5/books/${service}`, config);
132
141
  }
133
142
  }
134
143
  export class HttpApiV5Request extends HttpApiRequest {
135
- constructor(service) {
136
- super(`v5/${service}`);
144
+ constructor(service, config) {
145
+ super(`v5/${service}`, config);
137
146
  }
138
147
  }
139
148
  //# sourceMappingURL=http-api-request.js.map
@@ -8,36 +8,36 @@ 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 listIntegrations(bookId) {
11
+ export function listIntegrations(bookId, config) {
12
12
  return __awaiter(this, void 0, void 0, function* () {
13
13
  var _a;
14
- const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
14
+ const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`, config)
15
15
  .setMethod('GET')
16
16
  .fetch();
17
17
  return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || [];
18
18
  });
19
19
  }
20
- export function createIntegration(bookId, integration) {
20
+ export function createIntegration(bookId, integration, config) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
22
+ const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`, config)
23
23
  .setPayload(integration)
24
24
  .setMethod('POST')
25
25
  .fetch();
26
26
  return res.data;
27
27
  });
28
28
  }
29
- export function updateIntegration(bookId, integration) {
29
+ export function updateIntegration(bookId, integration, config) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
31
+ const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`, config)
32
32
  .setPayload(integration)
33
33
  .setMethod('PUT')
34
34
  .fetch();
35
35
  return res.data;
36
36
  });
37
37
  }
38
- export function deleteIntegration(bookId, id) {
38
+ export function deleteIntegration(bookId, id, config) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
- const res = yield new HttpBooksApiV5Request(`${bookId}/integrations/${id}`).setMethod('DELETE').fetch();
40
+ const res = yield new HttpBooksApiV5Request(`${bookId}/integrations/${id}`, config).setMethod('DELETE').fetch();
41
41
  return res.data;
42
42
  });
43
43
  }