bkper-js 1.0.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.
@@ -0,0 +1,248 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Group = void 0;
36
+ const GroupService = __importStar(require("../service/group-service"));
37
+ const utils_1 = require("../utils");
38
+ const Account_1 = require("./Account");
39
+ const Utils = __importStar(require("../utils"));
40
+ /**
41
+ * This class defines a Group of [[Accounts]].
42
+ *
43
+ * Accounts can be grouped by different meaning, like Expenses, Revenue, Assets, Liabilities and so on
44
+ *
45
+ * Its useful to keep organized and for high level analysis.
46
+ *
47
+ * @public
48
+ */
49
+ class Group {
50
+ /**
51
+ *
52
+ * @returns The wrapped plain json object
53
+ */
54
+ json() {
55
+ return this.wrapped;
56
+ }
57
+ /**
58
+ * @returns The id of this Group
59
+ */
60
+ getId() {
61
+ return this.wrapped.id;
62
+ }
63
+ /**
64
+ * @returns The parent Group
65
+ */
66
+ getParent() {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (this.wrapped.parent) {
69
+ return yield this.book.getGroup(this.wrapped.parent.id);
70
+ }
71
+ else {
72
+ return null;
73
+ }
74
+ });
75
+ }
76
+ /**
77
+ * Sets the parent Group.
78
+ *
79
+ * @returns This Group, for chainning.
80
+ */
81
+ setParent(group) {
82
+ if (group) {
83
+ this.wrapped.parent = { id: group.getId(), name: group.getName(), normalizedName: group.getNormalizedName() };
84
+ }
85
+ else {
86
+ this.wrapped.parent = null;
87
+ }
88
+ return this;
89
+ }
90
+ /**
91
+ * @returns The name of this Group
92
+ */
93
+ getName() {
94
+ return this.wrapped.name;
95
+ }
96
+ /**
97
+ * Sets the name of the Group.
98
+ *
99
+ * @returns This Group, for chainning.
100
+ */
101
+ setName(name) {
102
+ this.wrapped.name = name;
103
+ return this;
104
+ }
105
+ /**
106
+ * @returns The name of this group without spaces and special characters
107
+ */
108
+ getNormalizedName() {
109
+ if (this.wrapped.normalizedName) {
110
+ return this.wrapped.normalizedName;
111
+ }
112
+ else {
113
+ return (0, utils_1.normalizeText)(this.getName());
114
+ }
115
+ }
116
+ /**
117
+ * @returns All Accounts of this group.
118
+ */
119
+ getAccounts() {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ let accountsPlain = yield GroupService.getAccounts(this.book.getId(), this.getId());
122
+ if (!accountsPlain) {
123
+ return [];
124
+ }
125
+ let accounts = Utils.wrapObjects(new Account_1.Account(), accountsPlain);
126
+ for (const account of accounts) {
127
+ account.book = this.book;
128
+ }
129
+ return accounts;
130
+ });
131
+ }
132
+ /**
133
+ * @returns True if this group has any account in it
134
+ */
135
+ hasAccounts() {
136
+ return this.wrapped.hasAccounts;
137
+ }
138
+ /**
139
+ * @returns The type for of the accounts of this group. Null if mixed
140
+ */
141
+ getType() {
142
+ return this.wrapped.type;
143
+ }
144
+ /**
145
+ * Gets the custom properties stored in this Group
146
+ */
147
+ getProperties() {
148
+ return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
149
+ }
150
+ /**
151
+ * Sets the custom properties of the Group
152
+ *
153
+ * @param properties - Object with key/value pair properties
154
+ *
155
+ * @returns This Group, for chainning.
156
+ */
157
+ setProperties(properties) {
158
+ this.wrapped.properties = Object.assign({}, properties);
159
+ return this;
160
+ }
161
+ /**
162
+ * Gets the property value for given keys. First property found will be retrieved
163
+ *
164
+ * @param keys - The property key
165
+ */
166
+ getProperty(...keys) {
167
+ for (let index = 0; index < keys.length; index++) {
168
+ const key = keys[index];
169
+ let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
170
+ if (value != null && value.trim() != '') {
171
+ return value;
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+ /**
177
+ * Sets a custom property in the Group.
178
+ *
179
+ * @param key - The property key
180
+ * @param value - The property value
181
+ */
182
+ setProperty(key, value) {
183
+ if (key == null || key.trim() == '') {
184
+ return this;
185
+ }
186
+ if (this.wrapped.properties == null) {
187
+ this.wrapped.properties = {};
188
+ }
189
+ this.wrapped.properties[key] = value;
190
+ return this;
191
+ }
192
+ /**
193
+ * Delete a custom property
194
+ *
195
+ * @param key - The property key
196
+ *
197
+ * @returns This Group, for chainning.
198
+ */
199
+ deleteProperty(key) {
200
+ this.setProperty(key, null);
201
+ return this;
202
+ }
203
+ /**
204
+ * Tell if the Group is hidden on main transactions menu
205
+ */
206
+ isHidden() {
207
+ return this.wrapped.hidden;
208
+ }
209
+ /**
210
+ * Hide/Show group on main menu.
211
+ */
212
+ setHidden(hidden) {
213
+ this.wrapped.hidden = hidden;
214
+ return this;
215
+ }
216
+ /**
217
+ * Perform create new group.
218
+ */
219
+ create() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ this.wrapped = yield GroupService.createGroup(this.book.getId(), this.wrapped);
222
+ this.book.updateGroupCache(this);
223
+ return this;
224
+ });
225
+ }
226
+ /**
227
+ * Perform update group, applying pending changes.
228
+ */
229
+ update() {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ this.wrapped = yield GroupService.updateGroup(this.book.getId(), this.wrapped);
232
+ this.book.updateGroupCache(this);
233
+ return this;
234
+ });
235
+ }
236
+ /**
237
+ * Perform delete group.
238
+ */
239
+ remove() {
240
+ return __awaiter(this, void 0, void 0, function* () {
241
+ this.wrapped = yield GroupService.deleteGroup(this.book.getId(), this.wrapped);
242
+ this.book.removeGroupCache(this);
243
+ return this;
244
+ });
245
+ }
246
+ }
247
+ exports.Group = Group;
248
+ //# sourceMappingURL=Group.js.map
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Integration = void 0;
4
+ /**
5
+ * This class defines a Integration from an [[User]] to an external service.
6
+ *
7
+ * @public
8
+ */
9
+ class Integration {
10
+ constructor(json) {
11
+ this.wrapped = json;
12
+ }
13
+ /**
14
+ * Gets the wrapped plain json object of the Integration.
15
+ *
16
+ * @returns The Integration wrapped plain json object
17
+ */
18
+ json() {
19
+ return this.wrapped;
20
+ }
21
+ /**
22
+ * Gets the [[Book]] id of the Integration.
23
+ *
24
+ * @returns The Integration's Book id
25
+ */
26
+ getBookId() {
27
+ return this.wrapped.bookId;
28
+ }
29
+ /**
30
+ * Gets the id of the Integration.
31
+ *
32
+ * @returns This Integration's id
33
+ */
34
+ getId() {
35
+ return this.wrapped.id;
36
+ }
37
+ /**
38
+ * Gets the name of the Integration.
39
+ *
40
+ * @returns The Integration's name
41
+ */
42
+ getName() {
43
+ return this.wrapped.name;
44
+ }
45
+ /**
46
+ * Gets the custom properties stored in the Integration.
47
+ *
48
+ * @returns Object with key/value pair properties
49
+ */
50
+ getProperties() {
51
+ return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
52
+ }
53
+ /**
54
+ * Sets the custom properties of the Integration.
55
+ *
56
+ * @param properties - Object with key/value pair properties
57
+ *
58
+ * @returns The Integration, for chainning
59
+ */
60
+ setProperties(properties) {
61
+ this.wrapped.properties = Object.assign({}, properties);
62
+ return this;
63
+ }
64
+ /**
65
+ * Gets the property value for given keys. First property found will be retrieved.
66
+ *
67
+ * @param keys - The property key
68
+ *
69
+ * @returns The retrieved property value
70
+ */
71
+ getProperty(...keys) {
72
+ for (let index = 0; index < keys.length; index++) {
73
+ const key = keys[index];
74
+ let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
75
+ if (value != null && value.trim() != '') {
76
+ return value;
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+ /**
82
+ * Sets a custom property in the Integration.
83
+ *
84
+ * @param key - The property key
85
+ * @param value - The property value
86
+ *
87
+ * @returns The Integration, for chaining
88
+ */
89
+ setProperty(key, value) {
90
+ if (key == null || key.trim() == '') {
91
+ return this;
92
+ }
93
+ if (this.wrapped.properties == null) {
94
+ this.wrapped.properties = {};
95
+ }
96
+ this.wrapped.properties[key] = value;
97
+ return this;
98
+ }
99
+ /**
100
+ * Deletes a custom property stored in the Integration.
101
+ *
102
+ * @param key - The property key
103
+ *
104
+ * @returns The Integration, for chainning
105
+ */
106
+ deleteProperty(key) {
107
+ this.setProperty(key, null);
108
+ return this;
109
+ }
110
+ }
111
+ exports.Integration = Integration;
112
+ //# sourceMappingURL=Integration.js.map