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/README.md +4 -4
- package/lib/index.d.ts +115 -97
- package/lib/index.js +15 -35
- package/lib/model/Account.js +30 -50
- package/lib/model/Amount.js +6 -13
- package/lib/model/App.js +6 -10
- package/lib/model/Bkper.js +14 -41
- package/lib/model/Book.js +64 -103
- package/lib/model/Collection.js +5 -9
- package/lib/model/Config.js +1 -2
- package/lib/model/Connection.js +8 -32
- package/lib/model/Enums.js +12 -15
- package/lib/model/File.js +19 -32
- package/lib/model/Group.js +16 -40
- package/lib/model/Integration.js +6 -7
- package/lib/model/Transaction.js +59 -77
- package/lib/model/TransactionIterator.js +15 -19
- package/lib/model/TransactionPage.js +14 -40
- package/lib/model/User.js +9 -34
- package/lib/service/account-service.js +9 -15
- package/lib/service/app-service.js +7 -12
- package/lib/service/balances-service.js +3 -6
- package/lib/service/book-service.js +7 -12
- package/lib/service/connection-service.js +16 -21
- package/lib/service/file-service.js +5 -9
- package/lib/service/group-service.js +18 -24
- package/lib/service/http-api-request.js +50 -101
- package/lib/service/http-request.js +78 -0
- package/lib/service/integration-service.js +9 -15
- package/lib/service/transaction-service.js +27 -37
- package/lib/service/user-service.js +3 -6
- package/lib/utils.js +72 -85
- package/package.json +9 -7
package/lib/utils.js
CHANGED
|
@@ -1,51 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.round = round;
|
|
7
|
-
exports.formatValue = formatValue;
|
|
8
|
-
exports.parseValue = parseValue;
|
|
9
|
-
exports.convertValueToDate = convertValueToDate;
|
|
10
|
-
exports.isString = isString;
|
|
11
|
-
exports.createDate = createDate;
|
|
12
|
-
exports.formatDate = formatDate;
|
|
13
|
-
exports.formatDateISO = formatDateISO;
|
|
14
|
-
exports.parseDate = parseDate;
|
|
15
|
-
exports.getDateFormatterPattern = getDateFormatterPattern;
|
|
16
|
-
exports.getRepresentativeValue = getRepresentativeValue;
|
|
17
|
-
exports.wrapObjects = wrapObjects;
|
|
18
|
-
exports.wrapObject = wrapObject;
|
|
19
|
-
exports.buildURLParams = buildURLParams;
|
|
20
|
-
exports.convertInMatrix = convertInMatrix;
|
|
21
|
-
exports.normalizeName = normalizeName;
|
|
22
|
-
exports.normalizeText = normalizeText;
|
|
23
|
-
const luxon_1 = require("luxon");
|
|
24
|
-
const Amount_1 = require("./model/Amount");
|
|
25
|
-
const Enums_1 = require("./model/Enums");
|
|
26
|
-
exports.NODE_ENV_DEV = 'development';
|
|
27
|
-
function sleep(ms) {
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import { Amount } from './model/Amount.js';
|
|
3
|
+
import { DecimalSeparator, Periodicity } from './model/Enums.js';
|
|
4
|
+
export const NODE_ENV_DEV = 'development';
|
|
5
|
+
export function sleep(ms) {
|
|
28
6
|
return new Promise((resolve) => {
|
|
29
7
|
setTimeout(resolve, ms);
|
|
30
8
|
});
|
|
31
9
|
}
|
|
32
|
-
function base64Decode(data) {
|
|
10
|
+
export function base64Decode(data) {
|
|
33
11
|
return Buffer.from(data, 'base64');
|
|
34
12
|
}
|
|
35
13
|
//SAME AS bkper-app
|
|
36
14
|
var diacriticsMap_ = null;
|
|
37
|
-
function round(number, fractionDigits) {
|
|
15
|
+
export function round(number, fractionDigits) {
|
|
38
16
|
if (number == null) {
|
|
39
|
-
number = new
|
|
17
|
+
number = new Amount('0');
|
|
40
18
|
}
|
|
41
|
-
if (fractionDigits
|
|
42
|
-
return new
|
|
19
|
+
if (fractionDigits) {
|
|
20
|
+
return new Amount(number).round(fractionDigits);
|
|
43
21
|
}
|
|
44
22
|
else {
|
|
45
|
-
return new
|
|
23
|
+
return new Amount(number).round(2);
|
|
46
24
|
}
|
|
47
25
|
}
|
|
48
|
-
function formatValue(value, decimalSeparator, fractionDigits) {
|
|
26
|
+
export function formatValue(value, decimalSeparator, fractionDigits) {
|
|
49
27
|
if (value == null) {
|
|
50
28
|
return "";
|
|
51
29
|
}
|
|
@@ -53,44 +31,44 @@ function formatValue(value, decimalSeparator, fractionDigits) {
|
|
|
53
31
|
if (value.trim() == '') {
|
|
54
32
|
return "";
|
|
55
33
|
}
|
|
56
|
-
value = new
|
|
34
|
+
value = new Amount(value);
|
|
57
35
|
}
|
|
58
36
|
if (value == null) {
|
|
59
37
|
return "";
|
|
60
38
|
}
|
|
61
|
-
if (fractionDigits
|
|
39
|
+
if (!fractionDigits) {
|
|
62
40
|
fractionDigits = 2;
|
|
63
41
|
}
|
|
64
42
|
var formattedValue = (value.toFixed(fractionDigits)) + "";
|
|
65
|
-
if (decimalSeparator ==
|
|
43
|
+
if (decimalSeparator == DecimalSeparator.DOT) {
|
|
66
44
|
return formattedValue.replace(/\,/g, '.');
|
|
67
45
|
}
|
|
68
46
|
else {
|
|
69
47
|
return formattedValue.replace(/\./g, ',');
|
|
70
48
|
}
|
|
71
49
|
}
|
|
72
|
-
function parseValue(value, decimalSeparator) {
|
|
50
|
+
export function parseValue(value, decimalSeparator) {
|
|
73
51
|
if (value == null) {
|
|
74
|
-
return
|
|
52
|
+
return undefined;
|
|
75
53
|
}
|
|
76
54
|
if (!isNaN(+value) && isFinite(+value)) {
|
|
77
|
-
return new
|
|
55
|
+
return new Amount(value);
|
|
78
56
|
}
|
|
79
|
-
if (decimalSeparator ==
|
|
57
|
+
if (decimalSeparator == DecimalSeparator.DOT) {
|
|
80
58
|
value = value.replace(/\,/g, '');
|
|
81
59
|
}
|
|
82
60
|
else {
|
|
83
61
|
value = value.replace(/\./g, '').replace(/\,/g, '.');
|
|
84
62
|
}
|
|
85
63
|
try {
|
|
86
|
-
return new
|
|
64
|
+
return new Amount(value);
|
|
87
65
|
}
|
|
88
66
|
catch (err) {
|
|
89
|
-
return
|
|
67
|
+
return undefined;
|
|
90
68
|
}
|
|
91
69
|
}
|
|
92
|
-
function convertValueToDate(dateValue, offsetInMinutes) {
|
|
93
|
-
if (dateValue
|
|
70
|
+
export function convertValueToDate(dateValue, offsetInMinutes) {
|
|
71
|
+
if (!dateValue) {
|
|
94
72
|
return new Date();
|
|
95
73
|
}
|
|
96
74
|
var year = dateValue / 10000;
|
|
@@ -99,7 +77,7 @@ function convertValueToDate(dateValue, offsetInMinutes) {
|
|
|
99
77
|
var date = createDate(year, month, day, offsetInMinutes);
|
|
100
78
|
return date;
|
|
101
79
|
}
|
|
102
|
-
function isString(obj) {
|
|
80
|
+
export function isString(obj) {
|
|
103
81
|
if (obj == null) {
|
|
104
82
|
return false;
|
|
105
83
|
}
|
|
@@ -110,79 +88,88 @@ function isString(obj) {
|
|
|
110
88
|
return false;
|
|
111
89
|
}
|
|
112
90
|
}
|
|
113
|
-
function createDate(year, month, day, offsetInMinutes) {
|
|
91
|
+
export function createDate(year, month, day, offsetInMinutes) {
|
|
114
92
|
var date = new Date(year, month - 1, day);
|
|
93
|
+
if (!offsetInMinutes) {
|
|
94
|
+
offsetInMinutes = 0;
|
|
95
|
+
}
|
|
115
96
|
date.setTime(date.getTime() + offsetInMinutes * 60 * 1000);
|
|
116
97
|
return date;
|
|
117
98
|
}
|
|
118
|
-
function formatDate(date, pattern, timeZone) {
|
|
99
|
+
export function formatDate(date, pattern, timeZone) {
|
|
119
100
|
if (date == null || !(Object.prototype.toString.call(date) === '[object Date]')) {
|
|
120
101
|
return '';
|
|
121
102
|
}
|
|
122
|
-
if (timeZone
|
|
103
|
+
if (!timeZone || timeZone == "") {
|
|
123
104
|
timeZone = "UTC";
|
|
124
105
|
}
|
|
125
|
-
|
|
106
|
+
if (!pattern) {
|
|
107
|
+
return formatDateISO(date, timeZone);
|
|
108
|
+
}
|
|
109
|
+
var formatedDate = DateTime.fromJSDate(date, { zone: timeZone }).toFormat(pattern);
|
|
126
110
|
return formatedDate;
|
|
127
111
|
}
|
|
128
|
-
function formatDateISO(date, timeZone) {
|
|
112
|
+
export function formatDateISO(date, timeZone) {
|
|
129
113
|
if (date == null || !(Object.prototype.toString.call(date) === '[object Date]')) {
|
|
130
114
|
return '';
|
|
131
115
|
}
|
|
132
|
-
if (timeZone
|
|
116
|
+
if (!timeZone || timeZone == "") {
|
|
133
117
|
timeZone = "UTC";
|
|
134
118
|
}
|
|
135
|
-
var formatedDate =
|
|
119
|
+
var formatedDate = DateTime.fromJSDate(date, { zone: timeZone }).toISODate();
|
|
136
120
|
return formatedDate;
|
|
137
121
|
}
|
|
138
|
-
function parseDate(date, pattern, timeZone) {
|
|
139
|
-
|
|
122
|
+
export function parseDate(date, pattern, timeZone) {
|
|
123
|
+
if (!pattern) {
|
|
124
|
+
pattern = 'yyyy-MM-dd';
|
|
125
|
+
}
|
|
126
|
+
let dateObject = DateTime.fromFormat(date, pattern, { zone: timeZone }).toJSDate();
|
|
140
127
|
if (dateObject instanceof Date && !isNaN(dateObject.getTime())) {
|
|
141
128
|
console.log(dateObject);
|
|
142
129
|
return dateObject;
|
|
143
130
|
}
|
|
144
131
|
else {
|
|
145
|
-
return
|
|
132
|
+
return DateTime.fromFormat(date, 'yyyy-MM-dd', { zone: timeZone }).toJSDate();
|
|
146
133
|
}
|
|
147
134
|
}
|
|
148
|
-
function getDateFormatterPattern(datePattern, periodicity) {
|
|
135
|
+
export function getDateFormatterPattern(datePattern, periodicity) {
|
|
149
136
|
var pattern = datePattern;
|
|
150
|
-
if (periodicity ==
|
|
137
|
+
if (periodicity == Periodicity.MONTHLY) {
|
|
151
138
|
pattern = "MM/yyyy";
|
|
152
139
|
}
|
|
153
|
-
if (periodicity ==
|
|
140
|
+
if (periodicity == Periodicity.YEARLY) {
|
|
154
141
|
pattern = "yyyy";
|
|
155
142
|
}
|
|
156
143
|
return pattern;
|
|
157
144
|
}
|
|
158
|
-
function getRepresentativeValue(value, credit) {
|
|
145
|
+
export function getRepresentativeValue(value, credit) {
|
|
159
146
|
if (value == null) {
|
|
160
|
-
return new
|
|
147
|
+
return new Amount(0);
|
|
161
148
|
}
|
|
162
149
|
if (credit != null && !credit) {
|
|
163
150
|
return value.times(-1);
|
|
164
151
|
}
|
|
165
152
|
return value;
|
|
166
153
|
}
|
|
167
|
-
function wrapObjects(wrapper, wrappeds) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
function wrapObject(wrapper, wrapped) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
function buildURLParams(params) {
|
|
154
|
+
// export function wrapObjects<E extends Object>(wrapper: E, wrappeds: Array<Object>): Array<E> {
|
|
155
|
+
// var newObjects = [];
|
|
156
|
+
// if (wrappeds != null) {
|
|
157
|
+
// for (var i = 0; i < wrappeds.length; i++) {
|
|
158
|
+
// var newObject = wrapObject(wrapper, wrappeds[i]);
|
|
159
|
+
// newObjects.push(newObject);
|
|
160
|
+
// }
|
|
161
|
+
// }
|
|
162
|
+
// return newObjects;
|
|
163
|
+
// }
|
|
164
|
+
// export function wrapObject<E extends Object>(wrapper: E, wrapped: Object): E {
|
|
165
|
+
// if (wrapped == null) {
|
|
166
|
+
// wrapped = new Object();
|
|
167
|
+
// }
|
|
168
|
+
// var w = Object.create(wrapper);
|
|
169
|
+
// w.wrapped = wrapped;
|
|
170
|
+
// return w;
|
|
171
|
+
// }
|
|
172
|
+
export function buildURLParams(params) {
|
|
186
173
|
var urlSegment = "";
|
|
187
174
|
var i = 0;
|
|
188
175
|
for (var prop in params) {
|
|
@@ -200,7 +187,7 @@ function buildURLParams(params) {
|
|
|
200
187
|
}
|
|
201
188
|
return urlSegment;
|
|
202
189
|
}
|
|
203
|
-
function convertInMatrix(array) {
|
|
190
|
+
export function convertInMatrix(array) {
|
|
204
191
|
var maxLength = 0;
|
|
205
192
|
for (var i = 0; i < array.length; i++) {
|
|
206
193
|
if (array[i].length > maxLength) {
|
|
@@ -214,12 +201,12 @@ function convertInMatrix(array) {
|
|
|
214
201
|
}
|
|
215
202
|
return array;
|
|
216
203
|
}
|
|
217
|
-
function normalizeName(name) {
|
|
204
|
+
export function normalizeName(name) {
|
|
218
205
|
return normalizeText(name, "_");
|
|
219
206
|
}
|
|
220
|
-
function normalizeText(text, spaceReplacement) {
|
|
221
|
-
if (text
|
|
222
|
-
return
|
|
207
|
+
export function normalizeText(text, spaceReplacement) {
|
|
208
|
+
if (!text || typeof text != 'string') {
|
|
209
|
+
return '';
|
|
223
210
|
}
|
|
224
211
|
if (spaceReplacement) {
|
|
225
212
|
text = text.replace(new RegExp(spaceReplacement, 'g'), " ");
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
7
9
|
"files": [
|
|
8
10
|
"lib/**/*"
|
|
9
11
|
],
|
|
@@ -17,8 +19,8 @@
|
|
|
17
19
|
"clean": "rm -rf ./lib & rm -rf ./node_modules & wait",
|
|
18
20
|
"build": "run-s build:*",
|
|
19
21
|
"build:clean": "gts clean",
|
|
20
|
-
"build:test": "bun run test",
|
|
21
22
|
"build:compile": "tsc",
|
|
23
|
+
"build:test": "bun run test",
|
|
22
24
|
"build:api": "api-extractor run --local",
|
|
23
25
|
"build:cleanup": "rimraf lib/**/*.map lib/*.map lib/**/*.d.ts lib/*.d.ts",
|
|
24
26
|
"build:dts": "cp dist/bkper-js-public.d.ts lib/index.d.ts",
|
|
@@ -33,9 +35,9 @@
|
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"@google-cloud/local-auth": "^3.0.1",
|
|
38
|
+
"axios": "^1.7.7",
|
|
36
39
|
"big.js": "^6.0.3",
|
|
37
40
|
"dayjs": "^1.10.3",
|
|
38
|
-
"gaxios": "^4.3.0",
|
|
39
41
|
"luxon": "^1.25.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
@@ -47,9 +49,9 @@
|
|
|
47
49
|
"@types/mocha": "^8.2.0",
|
|
48
50
|
"@types/node": "^14.14.20",
|
|
49
51
|
"@types/node-fetch": "^2.5.8",
|
|
50
|
-
"chai": "^
|
|
52
|
+
"chai": "^5.1.1",
|
|
51
53
|
"gts": "^3.0.3",
|
|
52
|
-
"mocha": "^
|
|
54
|
+
"mocha": "^10.7.3",
|
|
53
55
|
"npm-run-all": "^4.1.5",
|
|
54
56
|
"rimraf": "^3.0.2",
|
|
55
57
|
"ts-node": "^10.9.2",
|