bkper 2.3.1 → 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/index.d.ts CHANGED
@@ -168,13 +168,13 @@ export declare class Account {
168
168
  *
169
169
  * @returns This Account, for chainning.
170
170
  */
171
- setGroups(groups: string[] | Group[]): Account;
171
+ setGroups(groups: Group[] | bkper.Group[]): Account;
172
172
  /**
173
173
  * Add a group to the Account.
174
174
  *
175
175
  * @returns This Account, for chainning.
176
176
  */
177
- addGroup(group: string | Group): Promise<Account>;
177
+ addGroup(group: Group | bkper.Group): Account;
178
178
  /**
179
179
  * Remove a group from the Account.
180
180
  */
@@ -338,26 +338,6 @@ export declare class App {
338
338
 
339
339
 
340
340
 
341
- }
342
-
343
- /**
344
- * Enum that represents balance types.
345
- *
346
- * @public
347
- */
348
- export declare enum BalanceType {
349
- /**
350
- * Total balance
351
- */
352
- TOTAL = "TOTAL",
353
- /**
354
- * Period balance
355
- */
356
- PERIOD = "PERIOD",
357
- /**
358
- * Cumulative balance
359
- */
360
- CUMULATIVE = "CUMULATIVE"
361
341
  }
362
342
 
363
343
  /**
package/lib/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Permission = exports.DecimalSeparator = exports.BalanceType = exports.AccountType = exports.Periodicity = exports.TransactionIterator = exports.Transaction = exports.Group = exports.File = exports.Collection = exports.Book = exports.Account = exports.Bkper = exports.Amount = exports.App = void 0;
10
+ exports.Permission = exports.DecimalSeparator = exports.AccountType = exports.Periodicity = exports.TransactionIterator = exports.Transaction = exports.Group = exports.File = exports.Collection = exports.Book = exports.Account = exports.Bkper = exports.Amount = exports.App = void 0;
11
11
  var App_1 = require("./model/App");
12
12
  Object.defineProperty(exports, "App", { enumerable: true, get: function () { return App_1.App; } });
13
13
  var Amount_1 = require("./model/Amount");
@@ -31,7 +31,6 @@ Object.defineProperty(exports, "TransactionIterator", { enumerable: true, get: f
31
31
  var Enums_1 = require("./model/Enums");
32
32
  Object.defineProperty(exports, "Periodicity", { enumerable: true, get: function () { return Enums_1.Periodicity; } });
33
33
  Object.defineProperty(exports, "AccountType", { enumerable: true, get: function () { return Enums_1.AccountType; } });
34
- Object.defineProperty(exports, "BalanceType", { enumerable: true, get: function () { return Enums_1.BalanceType; } });
35
34
  Object.defineProperty(exports, "DecimalSeparator", { enumerable: true, get: function () { return Enums_1.DecimalSeparator; } });
36
35
  Object.defineProperty(exports, "Permission", { enumerable: true, get: function () { return Enums_1.Permission; } });
37
36
  //# sourceMappingURL=index.js.map
@@ -276,7 +276,7 @@ class Account {
276
276
  setGroups(groups) {
277
277
  this.wrapped.groups = null;
278
278
  if (groups != null) {
279
- groups.forEach((group) => this.addGroup(group));
279
+ groups.forEach(group => this.addGroup(group));
280
280
  }
281
281
  return this;
282
282
  }
@@ -286,22 +286,16 @@ class Account {
286
286
  * @returns This Account, for chainning.
287
287
  */
288
288
  addGroup(group) {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- if (this.wrapped.groups == null) {
291
- this.wrapped.groups = [];
292
- }
293
- let groupObject = null;
294
- if (group instanceof Group_1.Group) {
295
- groupObject = group;
296
- }
297
- else if (typeof group == "string") {
298
- groupObject = yield this.book.getGroup(group);
299
- }
300
- if (groupObject) {
301
- this.wrapped.groups.push(groupObject.wrapped);
302
- }
303
- return this;
304
- });
289
+ if (this.wrapped.groups == null) {
290
+ this.wrapped.groups = [];
291
+ }
292
+ if (group instanceof Group_1.Group) {
293
+ this.wrapped.groups.push(group.wrapped);
294
+ }
295
+ else {
296
+ this.wrapped.groups.push(group);
297
+ }
298
+ return this;
305
299
  }
306
300
  /**
307
301
  * Remove a group from the Account.
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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Month = exports.Period = exports.BalanceType = exports.AccountType = exports.Permission = exports.DecimalSeparator = exports.Periodicity = void 0;
3
+ exports.Month = exports.Period = exports.AccountType = exports.Permission = exports.DecimalSeparator = exports.Periodicity = void 0;
4
4
  /**
5
5
  * The Periodicity of the query. It may depend on the level of granularity you write the range params.
6
6
  *
@@ -95,26 +95,6 @@ var AccountType;
95
95
  */
96
96
  AccountType["OUTGOING"] = "OUTGOING";
97
97
  })(AccountType = exports.AccountType || (exports.AccountType = {}));
98
- /**
99
- * Enum that represents balance types.
100
- *
101
- * @public
102
- */
103
- var BalanceType;
104
- (function (BalanceType) {
105
- /**
106
- * Total balance
107
- */
108
- BalanceType["TOTAL"] = "TOTAL";
109
- /**
110
- * Period balance
111
- */
112
- BalanceType["PERIOD"] = "PERIOD";
113
- /**
114
- * Cumulative balance
115
- */
116
- BalanceType["CUMULATIVE"] = "CUMULATIVE";
117
- })(BalanceType = exports.BalanceType || (exports.BalanceType = {}));
118
98
  /**
119
99
  * Enum that represents a period slice.
120
100
  *
@@ -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.3.1",
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",