bkper 2.5.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/model/Book.js CHANGED
@@ -575,6 +575,9 @@ class Book {
575
575
  getTransaction(id) {
576
576
  return __awaiter(this, void 0, void 0, function* () {
577
577
  let wrapped = yield TransactionService.getTransaction(this.getId(), id);
578
+ if (!wrapped) {
579
+ return null;
580
+ }
578
581
  let transaction = Utils.wrapObject(new Transaction_1.Transaction(), wrapped);
579
582
  this.configureTransaction_(transaction);
580
583
  return transaction;
@@ -70,6 +70,7 @@ class HttpApiRequest {
70
70
  return url;
71
71
  }
72
72
  fetch() {
73
+ var _a;
73
74
  return __awaiter(this, void 0, void 0, function* () {
74
75
  this.headers['Authorization'] = `Bearer ${yield getAccessToken()}`;
75
76
  this.addParam('key', HttpApiRequest.API_KEY);
@@ -92,9 +93,14 @@ class HttpApiRequest {
92
93
  });
93
94
  }
94
95
  catch (e) {
95
- let error = e.response.data;
96
- if (error.error) {
97
- throw error.error.message;
96
+ let error = (_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error;
97
+ if (error) {
98
+ if (error.code == 404) {
99
+ return { data: null };
100
+ }
101
+ else {
102
+ throw error.message;
103
+ }
98
104
  }
99
105
  else {
100
106
  throw e.message;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getAccount = exports.createAccounts = exports.deleteAccount = exports.updateAccount = exports.createAccount = void 0;
12
+ exports.getAccount = exports.deleteAccount = exports.updateAccount = exports.createAccount = void 0;
13
13
  const HttpApiRequest_1 = require("./HttpApiRequest");
14
14
  function createAccount(bookId, account) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
@@ -34,30 +34,10 @@ function deleteAccount(bookId, account) {
34
34
  });
35
35
  }
36
36
  exports.deleteAccount = deleteAccount;
37
- function createAccounts(bookId, accounts) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- let accountList = {
40
- items: accounts
41
- };
42
- var accountSaveBatchJSON = JSON.stringify(accountList);
43
- var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts/batch`).setMethod('POST').setPayload(accountSaveBatchJSON).fetch();
44
- var accountsPlain = yield response.data;
45
- if (accountsPlain.items == null) {
46
- return [];
47
- }
48
- return accountsPlain;
49
- });
50
- }
51
- exports.createAccounts = createAccounts;
52
37
  function getAccount(bookId, idOrName) {
53
38
  return __awaiter(this, void 0, void 0, function* () {
54
- try {
55
- var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts/${encodeURIComponent(idOrName)}`).setMethod('GET').fetch();
56
- return response.data;
57
- }
58
- catch (error) {
59
- return null;
60
- }
39
+ var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts/${encodeURIComponent(idOrName)}`).setMethod('GET').fetch();
40
+ return response.data;
61
41
  });
62
42
  }
63
43
  exports.getAccount = getAccount;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getAccounts = exports.getGroup = exports.getGroups = exports.getGroupsByAccountId = exports.createGroups = exports.deleteGroup = exports.updateGroup = exports.createGroup = void 0;
12
+ exports.getAccounts = exports.getGroup = exports.getGroups = exports.getGroupsByAccountId = exports.deleteGroup = exports.updateGroup = exports.createGroup = void 0;
13
13
  const HttpApiRequest_1 = require("./HttpApiRequest");
14
14
  function createGroup(bookId, group) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
@@ -34,29 +34,11 @@ function deleteGroup(bookId, group) {
34
34
  });
35
35
  }
36
36
  exports.deleteGroup = deleteGroup;
37
- function createGroups(bookId, groups) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- let groupList = {
40
- items: groups
41
- };
42
- var groupsBatchJSON = JSON.stringify(groupList);
43
- var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/groups/batch`).setMethod('POST').setPayload(groupsBatchJSON).fetch();
44
- if (response == null) {
45
- return [];
46
- }
47
- var groupsPlain = response.data;
48
- if (groupsPlain.items == null) {
49
- return [];
50
- }
51
- return groupsPlain.items;
52
- });
53
- }
54
- exports.createGroups = createGroups;
55
37
  function getGroupsByAccountId(bookId, accountId) {
56
38
  return __awaiter(this, void 0, void 0, function* () {
57
39
  var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts/${accountId}/groups`).setMethod('GET').fetch();
58
40
  var groupsPlain = response.data;
59
- if (groupsPlain.items == null) {
41
+ if (!(groupsPlain === null || groupsPlain === void 0 ? void 0 : groupsPlain.items)) {
60
42
  return [];
61
43
  }
62
44
  return groupsPlain.items;
@@ -67,7 +49,7 @@ function getGroups(bookId) {
67
49
  return __awaiter(this, void 0, void 0, function* () {
68
50
  var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/groups`).setMethod('GET').fetch();
69
51
  var groupsPlain = response.data;
70
- if (groupsPlain.items == null) {
52
+ if (!(groupsPlain === null || groupsPlain === void 0 ? void 0 : groupsPlain.items)) {
71
53
  return [];
72
54
  }
73
55
  return groupsPlain.items;
@@ -76,13 +58,8 @@ function getGroups(bookId) {
76
58
  exports.getGroups = getGroups;
77
59
  function getGroup(bookId, idOrName) {
78
60
  return __awaiter(this, void 0, void 0, function* () {
79
- try {
80
- var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}`).setMethod('GET').fetch();
81
- return response.data;
82
- }
83
- catch (error) {
84
- return null;
85
- }
61
+ var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}`).setMethod('GET').fetch();
62
+ return response.data;
86
63
  });
87
64
  }
88
65
  exports.getGroup = getGroup;
@@ -90,7 +67,7 @@ function getAccounts(bookId, idOrName) {
90
67
  return __awaiter(this, void 0, void 0, function* () {
91
68
  var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/groups/${encodeURIComponent(idOrName)}/accounts`).setMethod('GET').fetch();
92
69
  var accountsPlain = response.data;
93
- if (accountsPlain.items == null) {
70
+ if (!(accountsPlain === null || accountsPlain === void 0 ? void 0 : accountsPlain.items)) {
94
71
  return [];
95
72
  }
96
73
  return accountsPlain.items;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Node.js client for Bkper REST API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",