bkper 2.5.0 → 2.5.3
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 +17 -0
- package/lib/model/Book.js +30 -0
- package/lib/service/HttpApiRequest.js +9 -3
- package/lib/service/account-service.js +3 -23
- package/lib/service/group-service.js +6 -29
- package/lib/utils.js +8 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -490,6 +490,17 @@ export declare class Book {
|
|
|
490
490
|
* @returns This Book, for chainning.
|
|
491
491
|
*/
|
|
492
492
|
setLockDate(lockDate: string): Book;
|
|
493
|
+
/**
|
|
494
|
+
* @returns The closing date of the Book in ISO format yyyy-MM-dd
|
|
495
|
+
*/
|
|
496
|
+
getClosingDate(): string;
|
|
497
|
+
/**
|
|
498
|
+
*
|
|
499
|
+
* Sets the closing date of the Book in ISO format yyyy-MM-dd.
|
|
500
|
+
*
|
|
501
|
+
* @returns This Book, for chainning.
|
|
502
|
+
*/
|
|
503
|
+
setClosingDate(closingDate: string): Book;
|
|
493
504
|
/**
|
|
494
505
|
* @returns The decimal separator of the Book
|
|
495
506
|
*/
|
|
@@ -560,6 +571,12 @@ export declare class Book {
|
|
|
560
571
|
* @returns The date formated
|
|
561
572
|
*/
|
|
562
573
|
formatDate(date: Date, timeZone?: string): string;
|
|
574
|
+
/**
|
|
575
|
+
* Parse a date string according to date pattern and timezone of the Book.
|
|
576
|
+
*
|
|
577
|
+
* Also parse ISO yyyy-mm-dd format.
|
|
578
|
+
*/
|
|
579
|
+
parseDate(date: string): Date;
|
|
563
580
|
/**
|
|
564
581
|
* Formats a value according to [[DecimalSeparator]] and fraction digits of the Book.
|
|
565
582
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -206,6 +206,25 @@ class Book {
|
|
|
206
206
|
this.wrapped.lockDate = lockDate;
|
|
207
207
|
return this;
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* @returns The closing date of the Book in ISO format yyyy-MM-dd
|
|
211
|
+
*/
|
|
212
|
+
getClosingDate() {
|
|
213
|
+
return this.wrapped.closingDate;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* Sets the closing date of the Book in ISO format yyyy-MM-dd.
|
|
218
|
+
*
|
|
219
|
+
* @returns This Book, for chainning.
|
|
220
|
+
*/
|
|
221
|
+
setClosingDate(closingDate) {
|
|
222
|
+
if (closingDate == null) {
|
|
223
|
+
closingDate = "1900-00-00";
|
|
224
|
+
}
|
|
225
|
+
this.wrapped.closingDate = closingDate;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
209
228
|
/**
|
|
210
229
|
* @returns The decimal separator of the Book
|
|
211
230
|
*/
|
|
@@ -314,6 +333,14 @@ class Book {
|
|
|
314
333
|
}
|
|
315
334
|
return Utils.formatDate(date, this.getDatePattern(), timeZone);
|
|
316
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Parse a date string according to date pattern and timezone of the Book.
|
|
338
|
+
*
|
|
339
|
+
* Also parse ISO yyyy-mm-dd format.
|
|
340
|
+
*/
|
|
341
|
+
parseDate(date) {
|
|
342
|
+
return Utils.parseDate(date, this.getDatePattern(), this.getTimeZone());
|
|
343
|
+
}
|
|
317
344
|
/**
|
|
318
345
|
* Formats a value according to [[DecimalSeparator]] and fraction digits of the Book.
|
|
319
346
|
*
|
|
@@ -575,6 +602,9 @@ class Book {
|
|
|
575
602
|
getTransaction(id) {
|
|
576
603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
577
604
|
let wrapped = yield TransactionService.getTransaction(this.getId(), id);
|
|
605
|
+
if (!wrapped) {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
578
608
|
let transaction = Utils.wrapObject(new Transaction_1.Transaction(), wrapped);
|
|
579
609
|
this.configureTransaction_(transaction);
|
|
580
610
|
return transaction;
|
|
@@ -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
|
|
97
|
-
|
|
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.
|
|
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
|
-
|
|
55
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
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
|
|
70
|
+
if (!(accountsPlain === null || accountsPlain === void 0 ? void 0 : accountsPlain.items)) {
|
|
94
71
|
return [];
|
|
95
72
|
}
|
|
96
73
|
return accountsPlain.items;
|
package/lib/utils.js
CHANGED
|
@@ -127,7 +127,14 @@ function formatDateISO(date, timeZone) {
|
|
|
127
127
|
}
|
|
128
128
|
exports.formatDateISO = formatDateISO;
|
|
129
129
|
function parseDate(date, pattern, timeZone) {
|
|
130
|
-
|
|
130
|
+
let dateObject = luxon_1.DateTime.fromFormat(date, pattern, { zone: timeZone }).toJSDate();
|
|
131
|
+
if (dateObject instanceof Date && !isNaN(dateObject.getTime())) {
|
|
132
|
+
console.log(dateObject);
|
|
133
|
+
return dateObject;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return luxon_1.DateTime.fromFormat(date, 'yyyy-MM-dd', { zone: timeZone }).toJSDate();
|
|
137
|
+
}
|
|
131
138
|
}
|
|
132
139
|
exports.parseDate = parseDate;
|
|
133
140
|
function getDateFormatterPattern(datePattern, periodicity) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Node.js client for Bkper REST API",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"open": "^7.3.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@bkper/bkper-api-types": "^5.
|
|
49
|
+
"@bkper/bkper-api-types": "^5.1.4",
|
|
50
50
|
"@microsoft/api-extractor": "^7.12.1",
|
|
51
51
|
"@types/big.js": "^6.0.2",
|
|
52
52
|
"@types/chai": "^4.2.14",
|