bkper-js 1.0.0 → 1.1.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 +103 -96
- package/lib/index.js +14 -34
- 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 +14 -20
- 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 +8 -6
|
@@ -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,16 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const gaxios_1 = require("gaxios");
|
|
17
|
-
const https_1 = __importDefault(require("https"));
|
|
18
|
-
const utils_1 = require("../utils");
|
|
19
|
-
const httpsAgent = new https_1.default.Agent({ keepAlive: true });
|
|
20
|
-
class HttpApiRequest {
|
|
10
|
+
import { request } from 'gaxios';
|
|
11
|
+
import https from 'https';
|
|
12
|
+
import { NODE_ENV_DEV } from '../utils.js';
|
|
13
|
+
const httpsAgent = https && https.Agent ? new https.Agent({ keepAlive: true }) : undefined;
|
|
14
|
+
export class HttpApiRequest {
|
|
21
15
|
constructor(path) {
|
|
22
16
|
this.params = [];
|
|
23
17
|
this.headers = {};
|
|
@@ -81,16 +75,16 @@ class HttpApiRequest {
|
|
|
81
75
|
// this.httpRequest.setMuteHttpExceptions(true);
|
|
82
76
|
const url = this.getUrl();
|
|
83
77
|
try {
|
|
84
|
-
return yield
|
|
78
|
+
return yield request({
|
|
85
79
|
url: url,
|
|
86
80
|
method: this.method,
|
|
87
81
|
headers: this.headers,
|
|
88
82
|
body: this.payload,
|
|
89
|
-
agent: url.startsWith('https') ? httpsAgent :
|
|
83
|
+
agent: url.startsWith('https') ? httpsAgent : undefined,
|
|
90
84
|
retryConfig: {
|
|
91
85
|
httpMethodsToRetry: ['GET', 'PUT', 'POST', 'PATCH', 'HEAD', 'OPTIONS', 'DELETE'],
|
|
92
86
|
statusCodesToRetry: [[100, 199], [429, 429], [500, 599]],
|
|
93
|
-
retry: process.env.NODE_ENV ==
|
|
87
|
+
retry: process.env.NODE_ENV == NODE_ENV_DEV ? 0 : 3,
|
|
94
88
|
onRetryAttempt: (err) => { console.log(`${err.message} - Retrying... `); }
|
|
95
89
|
}
|
|
96
90
|
});
|
|
@@ -127,7 +121,6 @@ class HttpApiRequest {
|
|
|
127
121
|
});
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
|
-
exports.HttpApiRequest = HttpApiRequest;
|
|
131
124
|
HttpApiRequest.config = {};
|
|
132
125
|
function getApiKey() {
|
|
133
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -139,10 +132,13 @@ function getApiKey() {
|
|
|
139
132
|
}
|
|
140
133
|
function getAccessToken() {
|
|
141
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
let token =
|
|
135
|
+
let token = undefined;
|
|
143
136
|
if (HttpApiRequest.config.oauthTokenProvider) {
|
|
144
137
|
token = yield HttpApiRequest.config.oauthTokenProvider();
|
|
145
138
|
}
|
|
139
|
+
else {
|
|
140
|
+
console.warn(`Token provider NOT configured!`);
|
|
141
|
+
}
|
|
146
142
|
if (token) {
|
|
147
143
|
token = token.replace('Bearer ', '');
|
|
148
144
|
token = token.replace('bearer ', '');
|
|
@@ -150,16 +146,14 @@ function getAccessToken() {
|
|
|
150
146
|
return token;
|
|
151
147
|
});
|
|
152
148
|
}
|
|
153
|
-
class HttpBooksApiV5Request extends HttpApiRequest {
|
|
149
|
+
export class HttpBooksApiV5Request extends HttpApiRequest {
|
|
154
150
|
constructor(service) {
|
|
155
151
|
super(`v5/books/${service}`);
|
|
156
152
|
}
|
|
157
153
|
}
|
|
158
|
-
|
|
159
|
-
class HttpApiV5Request extends HttpApiRequest {
|
|
154
|
+
export class HttpApiV5Request extends HttpApiRequest {
|
|
160
155
|
constructor(service) {
|
|
161
156
|
super(`v5/${service}`);
|
|
162
157
|
}
|
|
163
158
|
}
|
|
164
|
-
exports.HttpApiV5Request = HttpApiV5Request;
|
|
165
159
|
//# sourceMappingURL=http-api-request.js.map
|
|
@@ -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,42 +7,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.createIntegration = createIntegration;
|
|
14
|
-
exports.updateIntegration = updateIntegration;
|
|
15
|
-
exports.deleteIntegration = deleteIntegration;
|
|
16
|
-
const http_api_request_1 = require("./http-api-request");
|
|
17
|
-
function listIntegrations(bookId) {
|
|
10
|
+
import { HttpBooksApiV5Request } from "./http-api-request.js";
|
|
11
|
+
export function listIntegrations(bookId) {
|
|
18
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
13
|
var _a;
|
|
20
|
-
const res = yield new
|
|
14
|
+
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
21
15
|
.setMethod('GET')
|
|
22
16
|
.fetch();
|
|
23
17
|
return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
24
18
|
});
|
|
25
19
|
}
|
|
26
|
-
function createIntegration(bookId, integration) {
|
|
20
|
+
export function createIntegration(bookId, integration) {
|
|
27
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const res = yield new
|
|
22
|
+
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
29
23
|
.setPayload(integration)
|
|
30
24
|
.setMethod('POST')
|
|
31
25
|
.fetch();
|
|
32
26
|
return res.data;
|
|
33
27
|
});
|
|
34
28
|
}
|
|
35
|
-
function updateIntegration(bookId, integration) {
|
|
29
|
+
export function updateIntegration(bookId, integration) {
|
|
36
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const res = yield new
|
|
31
|
+
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
38
32
|
.setPayload(integration)
|
|
39
33
|
.setMethod('PUT')
|
|
40
34
|
.fetch();
|
|
41
35
|
return res.data;
|
|
42
36
|
});
|
|
43
37
|
}
|
|
44
|
-
function deleteIntegration(bookId, id) {
|
|
38
|
+
export function deleteIntegration(bookId, id) {
|
|
45
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const res = yield new
|
|
40
|
+
const res = yield new HttpBooksApiV5Request(`${bookId}/integrations/${id}`)
|
|
47
41
|
.setMethod('DELETE')
|
|
48
42
|
.fetch();
|
|
49
43
|
return res.data;
|
|
@@ -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,32 +7,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.createTransactionsBatch = createTransactionsBatch;
|
|
14
|
-
exports.trashTransactionsBatch = trashTransactionsBatch;
|
|
15
|
-
exports.updateTransaction = updateTransaction;
|
|
16
|
-
exports.postTransaction = postTransaction;
|
|
17
|
-
exports.checkTransaction = checkTransaction;
|
|
18
|
-
exports.uncheckTransaction = uncheckTransaction;
|
|
19
|
-
exports.trashTransaction = trashTransaction;
|
|
20
|
-
exports.restoreTransaction = restoreTransaction;
|
|
21
|
-
exports.getTransaction = getTransaction;
|
|
22
|
-
exports.searchTransactions = searchTransactions;
|
|
23
|
-
const http_api_request_1 = require("./http-api-request");
|
|
24
|
-
function createTransaction(bookId, transaction) {
|
|
10
|
+
import { HttpBooksApiV5Request } from "./http-api-request.js";
|
|
11
|
+
export function createTransaction(bookId, transaction) {
|
|
25
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var response = yield new
|
|
13
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions`).setMethod('POST').setPayload(transaction).fetch();
|
|
27
14
|
return response.data;
|
|
28
15
|
});
|
|
29
16
|
}
|
|
30
|
-
function createTransactionsBatch(bookId, transactions) {
|
|
17
|
+
export function createTransactionsBatch(bookId, transactions) {
|
|
31
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
19
|
let transactionList = {
|
|
33
20
|
items: transactions
|
|
34
21
|
};
|
|
35
22
|
var payload = JSON.stringify(transactionList);
|
|
36
|
-
let response = yield new
|
|
23
|
+
let response = yield new HttpBooksApiV5Request(`${bookId}/transactions/batch`)
|
|
37
24
|
.setMethod('POST')
|
|
38
25
|
.setPayload(payload)
|
|
39
26
|
.fetch();
|
|
@@ -41,67 +28,70 @@ function createTransactionsBatch(bookId, transactions) {
|
|
|
41
28
|
return transactionList != null && transactionList.items != null ? transactionList.items : [];
|
|
42
29
|
});
|
|
43
30
|
}
|
|
44
|
-
function trashTransactionsBatch(bookId, transactions) {
|
|
31
|
+
export function trashTransactionsBatch(bookId, transactions) {
|
|
45
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
33
|
let transactionList = {
|
|
47
34
|
items: transactions
|
|
48
35
|
};
|
|
49
36
|
var payload = JSON.stringify(transactionList);
|
|
50
|
-
let response = yield new
|
|
37
|
+
let response = yield new HttpBooksApiV5Request(`${bookId}/transactions/trash/batch`)
|
|
51
38
|
.setMethod('PATCH')
|
|
52
39
|
.setPayload(payload)
|
|
53
40
|
.fetch();
|
|
54
41
|
transactionList = yield response.data;
|
|
55
42
|
});
|
|
56
43
|
}
|
|
57
|
-
function updateTransaction(bookId, transaction) {
|
|
44
|
+
export function updateTransaction(bookId, transaction) {
|
|
58
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
var response = yield new
|
|
46
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions`).setMethod('PUT').setPayload(transaction).fetch();
|
|
60
47
|
return response.data;
|
|
61
48
|
});
|
|
62
49
|
}
|
|
63
|
-
function postTransaction(bookId, transaction) {
|
|
50
|
+
export function postTransaction(bookId, transaction) {
|
|
64
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
var response = yield new
|
|
52
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/post`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
66
53
|
return response.data;
|
|
67
54
|
});
|
|
68
55
|
}
|
|
69
|
-
function checkTransaction(bookId, transaction) {
|
|
56
|
+
export function checkTransaction(bookId, transaction) {
|
|
70
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
var response = yield new
|
|
58
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/check`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
72
59
|
return response.data;
|
|
73
60
|
});
|
|
74
61
|
}
|
|
75
|
-
function uncheckTransaction(bookId, transaction) {
|
|
62
|
+
export function uncheckTransaction(bookId, transaction) {
|
|
76
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
var response = yield new
|
|
64
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/uncheck`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
78
65
|
return response.data;
|
|
79
66
|
});
|
|
80
67
|
}
|
|
81
|
-
function trashTransaction(bookId, transaction) {
|
|
68
|
+
export function trashTransaction(bookId, transaction) {
|
|
82
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var response = yield new
|
|
70
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/trash`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
84
71
|
return response.data;
|
|
85
72
|
});
|
|
86
73
|
}
|
|
87
|
-
function restoreTransaction(bookId, transaction) {
|
|
74
|
+
export function restoreTransaction(bookId, transaction) {
|
|
88
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
var response = yield new
|
|
76
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/restore`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
90
77
|
return response.data;
|
|
91
78
|
});
|
|
92
79
|
}
|
|
93
|
-
function getTransaction(bookId, id) {
|
|
80
|
+
export function getTransaction(bookId, id) {
|
|
94
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
var response = yield new
|
|
82
|
+
var response = yield new HttpBooksApiV5Request(`${bookId}/transactions/${id}`).setMethod('GET').fetch();
|
|
96
83
|
return response.data;
|
|
97
84
|
});
|
|
98
85
|
}
|
|
99
|
-
function searchTransactions(bookId, query, limit, cursor) {
|
|
86
|
+
export function searchTransactions(bookId, query, limit, cursor) {
|
|
100
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
if (query
|
|
88
|
+
if (!query) {
|
|
102
89
|
query = "";
|
|
103
90
|
}
|
|
104
|
-
|
|
91
|
+
if (!limit) {
|
|
92
|
+
limit = 100;
|
|
93
|
+
}
|
|
94
|
+
var request = new HttpBooksApiV5Request(`${bookId}/transactions`);
|
|
105
95
|
request.addParam('query', query);
|
|
106
96
|
request.addParam('limit', limit);
|
|
107
97
|
if (cursor != null) {
|
|
@@ -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,12 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const http_api_request_1 = require("./http-api-request");
|
|
14
|
-
function getUser() {
|
|
10
|
+
import { HttpApiV5Request } from "./http-api-request.js";
|
|
11
|
+
export function getUser() {
|
|
15
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const res = yield new
|
|
13
|
+
const res = yield new HttpApiV5Request(`user`).setMethod('GET').fetch();
|
|
17
14
|
return res.data;
|
|
18
15
|
});
|
|
19
16
|
}
|
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.1.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",
|
|
@@ -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",
|