bkper-js 1.0.0 → 1.2.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/lib/index.js CHANGED
@@ -1,42 +1,22 @@
1
- "use strict";
2
1
  /**
3
- * Bkper REST API Node client.
2
+ * Bkper REST API Javascript client for Node.js and browsers.
4
3
  *
5
4
  * Learn more at https://bkper.com/docs
6
5
  *
7
6
  * @packageDocumentation
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Permission = exports.DecimalSeparator = exports.AccountType = exports.Periodicity = exports.Connection = exports.Integration = exports.User = exports.TransactionIterator = exports.Transaction = exports.Group = exports.File = exports.Collection = exports.Book = exports.Account = exports.Bkper = exports.Amount = exports.App = void 0;
11
- var App_1 = require("./model/App");
12
- Object.defineProperty(exports, "App", { enumerable: true, get: function () { return App_1.App; } });
13
- var Amount_1 = require("./model/Amount");
14
- Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return Amount_1.Amount; } });
15
- var Bkper_1 = require("./model/Bkper");
16
- Object.defineProperty(exports, "Bkper", { enumerable: true, get: function () { return Bkper_1.Bkper; } });
17
- var Account_1 = require("./model/Account");
18
- Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return Account_1.Account; } });
19
- var Book_1 = require("./model/Book");
20
- Object.defineProperty(exports, "Book", { enumerable: true, get: function () { return Book_1.Book; } });
21
- var Collection_1 = require("./model/Collection");
22
- Object.defineProperty(exports, "Collection", { enumerable: true, get: function () { return Collection_1.Collection; } });
23
- var File_1 = require("./model/File");
24
- Object.defineProperty(exports, "File", { enumerable: true, get: function () { return File_1.File; } });
25
- var Group_1 = require("./model/Group");
26
- Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return Group_1.Group; } });
27
- var Transaction_1 = require("./model/Transaction");
28
- Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return Transaction_1.Transaction; } });
29
- var TransactionIterator_1 = require("./model/TransactionIterator");
30
- Object.defineProperty(exports, "TransactionIterator", { enumerable: true, get: function () { return TransactionIterator_1.TransactionIterator; } });
31
- var User_1 = require("./model/User");
32
- Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
33
- var Integration_1 = require("./model/Integration");
34
- Object.defineProperty(exports, "Integration", { enumerable: true, get: function () { return Integration_1.Integration; } });
35
- var Connection_1 = require("./model/Connection");
36
- Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return Connection_1.Connection; } });
37
- var Enums_1 = require("./model/Enums");
38
- Object.defineProperty(exports, "Periodicity", { enumerable: true, get: function () { return Enums_1.Periodicity; } });
39
- Object.defineProperty(exports, "AccountType", { enumerable: true, get: function () { return Enums_1.AccountType; } });
40
- Object.defineProperty(exports, "DecimalSeparator", { enumerable: true, get: function () { return Enums_1.DecimalSeparator; } });
41
- Object.defineProperty(exports, "Permission", { enumerable: true, get: function () { return Enums_1.Permission; } });
8
+ export { App } from './model/App.js';
9
+ export { Amount } from "./model/Amount.js";
10
+ export { Bkper } from './model/Bkper.js';
11
+ export { Account } from './model/Account.js';
12
+ export { Book } from './model/Book.js';
13
+ export { Collection } from './model/Collection.js';
14
+ export { File } from './model/File.js';
15
+ export { Group } from './model/Group.js';
16
+ export { Transaction } from './model/Transaction.js';
17
+ export { TransactionIterator } from './model/TransactionIterator.js';
18
+ export { User } from './model/User.js';
19
+ export { Integration } from './model/Integration.js';
20
+ export { Connection } from './model/Connection.js';
21
+ export { Periodicity, AccountType, DecimalSeparator, Permission } from './model/Enums.js';
42
22
  //# sourceMappingURL=index.js.map
@@ -1,27 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,14 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
8
  });
33
9
  };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Account = void 0;
36
- const AccountService = __importStar(require("../service/account-service"));
37
- const GroupService = __importStar(require("../service/group-service"));
38
- const Group_1 = require("./Group");
39
- const utils_1 = require("../utils");
40
- const Amount_1 = require("./Amount");
41
- const Utils = __importStar(require("../utils"));
10
+ import * as AccountService from '../service/account-service.js';
11
+ import * as GroupService from '../service/group-service.js';
12
+ import { Group } from './Group.js';
13
+ import { normalizeText, round } from '../utils.js';
14
+ import { Amount } from './Amount.js';
42
15
  /**
43
16
  *
44
17
  * This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].
@@ -49,7 +22,11 @@ const Utils = __importStar(require("../utils"));
49
22
  *
50
23
  * @public
51
24
  */
52
- class Account {
25
+ export class Account {
26
+ constructor(book, json) {
27
+ this.book = book;
28
+ this.wrapped = json || {};
29
+ }
53
30
  /**
54
31
  *
55
32
  * @returns The wrapped plain json object
@@ -87,7 +64,7 @@ class Account {
87
64
  return this.wrapped.normalizedName;
88
65
  }
89
66
  else {
90
- return (0, utils_1.normalizeText)(this.getName());
67
+ return normalizeText(this.getName());
91
68
  }
92
69
  }
93
70
  /**
@@ -136,7 +113,7 @@ class Account {
136
113
  return value;
137
114
  }
138
115
  }
139
- return null;
116
+ return undefined;
140
117
  }
141
118
  /**
142
119
  * Sets a custom property in the Account.
@@ -153,6 +130,9 @@ class Account {
153
130
  if (this.wrapped.properties == null) {
154
131
  this.wrapped.properties = {};
155
132
  }
133
+ if (!value) {
134
+ value = '';
135
+ }
156
136
  this.wrapped.properties[key] = value;
157
137
  return this;
158
138
  }
@@ -173,9 +153,9 @@ class Account {
173
153
  * @returns The balance of this account.
174
154
  */
175
155
  getBalance() {
176
- var balance = new Amount_1.Amount('0');
156
+ var balance = new Amount('0');
177
157
  if (this.wrapped.balance != null) {
178
- balance = (0, utils_1.round)(this.wrapped.balance, this.book.getFractionDigits());
158
+ balance = round(this.wrapped.balance, this.book.getFractionDigits());
179
159
  }
180
160
  return balance;
181
161
  }
@@ -185,9 +165,9 @@ class Account {
185
165
  * @returns The balance of this account.
186
166
  */
187
167
  getBalanceRaw() {
188
- var balance = new Amount_1.Amount('0');
168
+ var balance = new Amount('0');
189
169
  if (this.wrapped.balance != null) {
190
- balance = (0, utils_1.round)(this.wrapped.balance, this.book.getFractionDigits());
170
+ balance = round(this.wrapped.balance, this.book.getFractionDigits());
191
171
  }
192
172
  return balance;
193
173
  }
@@ -257,11 +237,12 @@ class Account {
257
237
  */
258
238
  getGroups() {
259
239
  return __awaiter(this, void 0, void 0, function* () {
260
- let groups = yield GroupService.getGroupsByAccountId(this.book.getId(), this.getId());
261
- let groupsObj = Utils.wrapObjects(new Group_1.Group(), groups);
262
- for (const group of groupsObj) {
263
- group.book = this.book;
240
+ const id = this.getId();
241
+ if (!id) {
242
+ return [];
264
243
  }
244
+ let groups = yield GroupService.getGroupsByAccountId(this.book.getId(), id);
245
+ let groupsObj = groups.map(group => new Group(this.book, group));
265
246
  return groupsObj;
266
247
  });
267
248
  }
@@ -271,7 +252,7 @@ class Account {
271
252
  * @returns This Account, for chainning.
272
253
  */
273
254
  setGroups(groups) {
274
- this.wrapped.groups = null;
255
+ this.wrapped.groups = undefined;
275
256
  if (groups != null) {
276
257
  groups.forEach(group => this.addGroup(group));
277
258
  }
@@ -283,10 +264,10 @@ class Account {
283
264
  * @returns This Account, for chainning.
284
265
  */
285
266
  addGroup(group) {
286
- if (this.wrapped.groups == null) {
267
+ if (!this.wrapped.groups) {
287
268
  this.wrapped.groups = [];
288
269
  }
289
- if (group instanceof Group_1.Group) {
270
+ if (group instanceof Group) {
290
271
  this.wrapped.groups.push(group.json());
291
272
  }
292
273
  else {
@@ -300,8 +281,8 @@ class Account {
300
281
  removeGroup(group) {
301
282
  return __awaiter(this, void 0, void 0, function* () {
302
283
  if (this.wrapped.groups != null) {
303
- let groupObject = null;
304
- if (group instanceof Group_1.Group) {
284
+ let groupObject = undefined;
285
+ if (group instanceof Group) {
305
286
  groupObject = group;
306
287
  }
307
288
  else if (typeof group == "string") {
@@ -330,7 +311,7 @@ class Account {
330
311
  return false;
331
312
  }
332
313
  //Group object
333
- if (group instanceof Group_1.Group) {
314
+ if (group instanceof Group) {
334
315
  return this.isInGroupObject_(group);
335
316
  }
336
317
  //id or name
@@ -381,5 +362,4 @@ class Account {
381
362
  });
382
363
  }
383
364
  }
384
- exports.Account = Account;
385
365
  //# sourceMappingURL=Account.js.map
@@ -1,10 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Amount = void 0;
7
- const big_js_1 = __importDefault(require("big.js"));
1
+ import Big from "big.js";
8
2
  /**
9
3
  * This class defines an Amount for arbitrary-precision decimal arithmetic.
10
4
  *
@@ -12,23 +6,23 @@ const big_js_1 = __importDefault(require("big.js"));
12
6
  *
13
7
  * @public
14
8
  */
15
- class Amount {
9
+ export class Amount {
16
10
  /**
17
11
  * The Amount constructor.
18
12
  */
19
13
  constructor(n) {
20
14
  this.checkNumberNotNull(n);
21
15
  if (typeof n == "string") {
22
- this.wrapped = new big_js_1.default(n);
16
+ this.wrapped = new Big(n);
23
17
  }
24
18
  else if (n instanceof Amount) {
25
- this.wrapped = new big_js_1.default(n.wrapped);
19
+ this.wrapped = new Big(n.wrapped);
26
20
  }
27
21
  else if (n.toString) {
28
- this.wrapped = new big_js_1.default(n.toString());
22
+ this.wrapped = new Big(n.toString());
29
23
  }
30
24
  else {
31
- this.wrapped = new big_js_1.default(+n);
25
+ this.wrapped = new Big(+n);
32
26
  }
33
27
  }
34
28
  /**
@@ -291,5 +285,4 @@ class Amount {
291
285
  return amount;
292
286
  }
293
287
  }
294
- exports.Amount = Amount;
295
288
  //# sourceMappingURL=Amount.js.map
package/lib/model/App.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,9 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.App = void 0;
13
- const app_service_1 = require("../service/app-service");
10
+ import { createApp, patchApp, updateApp } from "../service/app-service.js";
14
11
  /**
15
12
  * Defines an App on Bkper.
16
13
  *
@@ -18,9 +15,9 @@ const app_service_1 = require("../service/app-service");
18
15
  *
19
16
  * @public
20
17
  */
21
- class App {
18
+ export class App {
22
19
  constructor(json) {
23
- this.wrapped = json;
20
+ this.wrapped = json || {};
24
21
  }
25
22
  /**
26
23
  *
@@ -87,7 +84,7 @@ class App {
87
84
  */
88
85
  create() {
89
86
  return __awaiter(this, void 0, void 0, function* () {
90
- yield (0, app_service_1.createApp)(this.wrapped);
87
+ yield createApp(this.wrapped);
91
88
  return this;
92
89
  });
93
90
  }
@@ -96,7 +93,7 @@ class App {
96
93
  */
97
94
  patch() {
98
95
  return __awaiter(this, void 0, void 0, function* () {
99
- yield (0, app_service_1.patchApp)(this.wrapped);
96
+ yield patchApp(this.wrapped);
100
97
  return this;
101
98
  });
102
99
  }
@@ -105,10 +102,9 @@ class App {
105
102
  */
106
103
  update() {
107
104
  return __awaiter(this, void 0, void 0, function* () {
108
- yield (0, app_service_1.updateApp)(this.wrapped);
105
+ yield updateApp(this.wrapped);
109
106
  return this;
110
107
  });
111
108
  }
112
109
  }
113
- exports.App = App;
114
110
  //# sourceMappingURL=App.js.map
@@ -1,27 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,20 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
8
  });
33
9
  };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Bkper = void 0;
36
- const Book_1 = require("./Book");
37
- const App_1 = require("./App");
38
- const BookService = __importStar(require("../service/book-service"));
39
- const UserService = __importStar(require("../service/user-service"));
40
- const http_api_request_1 = require("../service/http-api-request");
41
- const User_1 = require("./User");
10
+ import { Book } from "./Book.js";
11
+ import { App } from "./App.js";
12
+ import * as BookService from '../service/book-service.js';
13
+ import * as UserService from '../service/user-service.js';
14
+ import { HttpApiRequest } from '../service/http-api-request.js';
15
+ import { User } from "./User.js";
42
16
  /**
43
- * This is the main Entry Point of the [bkper-node](https://www.npmjs.com/package/bkper) library.
17
+ * This is the main Entry Point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
44
18
  *
45
19
  * @public
46
20
  */
47
- class Bkper {
21
+ export class Bkper {
48
22
  /**
49
23
  * Gets the [[Book]] with the specified bookId from url param.
50
24
  *
@@ -55,7 +29,7 @@ class Bkper {
55
29
  static getBook(id) {
56
30
  return __awaiter(this, void 0, void 0, function* () {
57
31
  let book = yield BookService.loadBook(id);
58
- return new Book_1.Book(book);
32
+ return new Book(book);
59
33
  });
60
34
  }
61
35
  /**
@@ -66,7 +40,7 @@ class Bkper {
66
40
  static getUser() {
67
41
  return __awaiter(this, void 0, void 0, function* () {
68
42
  let user = yield UserService.getUser();
69
- return new User_1.User(user);
43
+ return new User(user);
70
44
  });
71
45
  }
72
46
  /**
@@ -75,7 +49,7 @@ class Bkper {
75
49
  * @param config - The Config object
76
50
  */
77
51
  static setConfig(config) {
78
- http_api_request_1.HttpApiRequest.config = config;
52
+ HttpApiRequest.config = config;
79
53
  }
80
54
  /**
81
55
  * Sets the API key to identify the agent.
@@ -87,8 +61,8 @@ class Bkper {
87
61
  * @deprecated Use `setConfig()` instead
88
62
  */
89
63
  static setApiKey(key) {
90
- http_api_request_1.HttpApiRequest.config.apiKeyProvider = () => __awaiter(this, void 0, void 0, function* () { return key; });
91
- return new App_1.App({});
64
+ HttpApiRequest.config.apiKeyProvider = () => __awaiter(this, void 0, void 0, function* () { return key; });
65
+ return new App({});
92
66
  }
93
67
  /**
94
68
  * Sets the provider of the valid OAuth2 access token
@@ -97,9 +71,8 @@ class Bkper {
97
71
  */
98
72
  static setOAuthTokenProvider(oauthTokenProvider) {
99
73
  return __awaiter(this, void 0, void 0, function* () {
100
- http_api_request_1.HttpApiRequest.config.oauthTokenProvider = oauthTokenProvider;
74
+ HttpApiRequest.config.oauthTokenProvider = oauthTokenProvider;
101
75
  });
102
76
  }
103
77
  }
104
- exports.Bkper = Bkper;
105
78
  //# sourceMappingURL=Bkper.js.map