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.
- package/LICENSE +201 -0
- package/README.md +27 -0
- package/lib/index.d.ts +1804 -0
- package/lib/index.js +42 -0
- package/lib/model/Account.js +385 -0
- package/lib/model/Amount.js +295 -0
- package/lib/model/App.js +114 -0
- package/lib/model/Bkper.js +105 -0
- package/lib/model/Book.js +717 -0
- package/lib/model/Collection.js +43 -0
- package/lib/model/Config.js +3 -0
- package/lib/model/Connection.js +261 -0
- package/lib/model/Enums.js +138 -0
- package/lib/model/File.js +128 -0
- package/lib/model/Group.js +248 -0
- package/lib/model/Integration.js +112 -0
- package/lib/model/Transaction.js +719 -0
- package/lib/model/TransactionIterator.js +154 -0
- package/lib/model/TransactionPage.js +97 -0
- package/lib/model/User.js +97 -0
- package/lib/service/account-service.js +42 -0
- package/lib/service/app-service.js +34 -0
- package/lib/service/balances-service.js +20 -0
- package/lib/service/book-service.js +36 -0
- package/lib/service/connection-service.js +71 -0
- package/lib/service/file-service.js +27 -0
- package/lib/service/group-service.js +71 -0
- package/lib/service/http-api-request.js +165 -0
- package/lib/service/integration-service.js +52 -0
- package/lib/service/transaction-service.js +114 -0
- package/lib/service/user-service.js +20 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/utils.js +341 -0
- package/package.json +58 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpApiV5Request = exports.HttpBooksApiV5Request = exports.HttpApiRequest = void 0;
|
|
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 {
|
|
21
|
+
constructor(path) {
|
|
22
|
+
this.params = [];
|
|
23
|
+
this.headers = {};
|
|
24
|
+
this.method = 'GET';
|
|
25
|
+
this.payload = null;
|
|
26
|
+
this.url = `${HttpApiRequest.config.apiBaseUrl || "https://app.bkper.com/_ah/api/bkper"}/${path}`;
|
|
27
|
+
}
|
|
28
|
+
setMethod(method) {
|
|
29
|
+
this.method = method;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setHeader(name, value) {
|
|
33
|
+
if (value) {
|
|
34
|
+
this.headers[name] = value;
|
|
35
|
+
}
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
addParam(name, value) {
|
|
39
|
+
if (value) {
|
|
40
|
+
this.params.push({ name, value });
|
|
41
|
+
}
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
setPayload(payload) {
|
|
45
|
+
this.payload = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the result url, with query params appended.
|
|
50
|
+
*/
|
|
51
|
+
getUrl() {
|
|
52
|
+
let url = this.url;
|
|
53
|
+
if (this.params != null) {
|
|
54
|
+
let i = 0;
|
|
55
|
+
if (url.indexOf('?') < 0) {
|
|
56
|
+
url += '?';
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
i++;
|
|
60
|
+
}
|
|
61
|
+
for (const param of this.params) {
|
|
62
|
+
if (i > 0) {
|
|
63
|
+
url += "&";
|
|
64
|
+
}
|
|
65
|
+
var key = param.name;
|
|
66
|
+
var value = param.value;
|
|
67
|
+
if (value != null) {
|
|
68
|
+
url += key + "=" + encodeURIComponent(value);
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return url;
|
|
74
|
+
}
|
|
75
|
+
fetch() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
var _a;
|
|
78
|
+
this.addCustomHeaders();
|
|
79
|
+
this.headers['Authorization'] = `Bearer ${yield getAccessToken()}`;
|
|
80
|
+
this.addParam('key', yield getApiKey());
|
|
81
|
+
// this.httpRequest.setMuteHttpExceptions(true);
|
|
82
|
+
const url = this.getUrl();
|
|
83
|
+
try {
|
|
84
|
+
return yield (0, gaxios_1.request)({
|
|
85
|
+
url: url,
|
|
86
|
+
method: this.method,
|
|
87
|
+
headers: this.headers,
|
|
88
|
+
body: this.payload,
|
|
89
|
+
agent: url.startsWith('https') ? httpsAgent : null,
|
|
90
|
+
retryConfig: {
|
|
91
|
+
httpMethodsToRetry: ['GET', 'PUT', 'POST', 'PATCH', 'HEAD', 'OPTIONS', 'DELETE'],
|
|
92
|
+
statusCodesToRetry: [[100, 199], [429, 429], [500, 599]],
|
|
93
|
+
retry: process.env.NODE_ENV == utils_1.NODE_ENV_DEV ? 0 : 3,
|
|
94
|
+
onRetryAttempt: (err) => { console.log(`${err.message} - Retrying... `); }
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
const customError = HttpApiRequest.config.requestErrorHandler ? HttpApiRequest.config.requestErrorHandler(e) : undefined;
|
|
100
|
+
if (customError) {
|
|
101
|
+
throw customError;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
//Default error handler
|
|
105
|
+
let error = (_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error;
|
|
106
|
+
if (error) {
|
|
107
|
+
if (error.code == 404) {
|
|
108
|
+
return { data: null };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
throw error.message;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw e.message;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
addCustomHeaders() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (HttpApiRequest.config.requestHeadersProvider) {
|
|
124
|
+
const headers = yield HttpApiRequest.config.requestHeadersProvider();
|
|
125
|
+
Object.entries(headers).forEach(([key, value]) => this.setHeader(key, value));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.HttpApiRequest = HttpApiRequest;
|
|
131
|
+
HttpApiRequest.config = {};
|
|
132
|
+
function getApiKey() {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (HttpApiRequest.config.apiKeyProvider) {
|
|
135
|
+
return yield HttpApiRequest.config.apiKeyProvider();
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getAccessToken() {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
let token = null;
|
|
143
|
+
if (HttpApiRequest.config.oauthTokenProvider) {
|
|
144
|
+
token = yield HttpApiRequest.config.oauthTokenProvider();
|
|
145
|
+
}
|
|
146
|
+
if (token) {
|
|
147
|
+
token = token.replace('Bearer ', '');
|
|
148
|
+
token = token.replace('bearer ', '');
|
|
149
|
+
}
|
|
150
|
+
return token;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
class HttpBooksApiV5Request extends HttpApiRequest {
|
|
154
|
+
constructor(service) {
|
|
155
|
+
super(`v5/books/${service}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.HttpBooksApiV5Request = HttpBooksApiV5Request;
|
|
159
|
+
class HttpApiV5Request extends HttpApiRequest {
|
|
160
|
+
constructor(service) {
|
|
161
|
+
super(`v5/${service}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.HttpApiV5Request = HttpApiV5Request;
|
|
165
|
+
//# sourceMappingURL=http-api-request.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.listIntegrations = listIntegrations;
|
|
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) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
|
+
const res = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
21
|
+
.setMethod('GET')
|
|
22
|
+
.fetch();
|
|
23
|
+
return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function createIntegration(bookId, integration) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const res = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
29
|
+
.setPayload(integration)
|
|
30
|
+
.setMethod('POST')
|
|
31
|
+
.fetch();
|
|
32
|
+
return res.data;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function updateIntegration(bookId, integration) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const res = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/integrations`)
|
|
38
|
+
.setPayload(integration)
|
|
39
|
+
.setMethod('PUT')
|
|
40
|
+
.fetch();
|
|
41
|
+
return res.data;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function deleteIntegration(bookId, id) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const res = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/integrations/${id}`)
|
|
47
|
+
.setMethod('DELETE')
|
|
48
|
+
.fetch();
|
|
49
|
+
return res.data;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=integration-service.js.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createTransaction = createTransaction;
|
|
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) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions`).setMethod('POST').setPayload(transaction).fetch();
|
|
27
|
+
return response.data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function createTransactionsBatch(bookId, transactions) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
let transactionList = {
|
|
33
|
+
items: transactions
|
|
34
|
+
};
|
|
35
|
+
var payload = JSON.stringify(transactionList);
|
|
36
|
+
let response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/batch`)
|
|
37
|
+
.setMethod('POST')
|
|
38
|
+
.setPayload(payload)
|
|
39
|
+
.fetch();
|
|
40
|
+
transactionList = yield response.data;
|
|
41
|
+
return transactionList != null && transactionList.items != null ? transactionList.items : [];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function trashTransactionsBatch(bookId, transactions) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
let transactionList = {
|
|
47
|
+
items: transactions
|
|
48
|
+
};
|
|
49
|
+
var payload = JSON.stringify(transactionList);
|
|
50
|
+
let response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/trash/batch`)
|
|
51
|
+
.setMethod('PATCH')
|
|
52
|
+
.setPayload(payload)
|
|
53
|
+
.fetch();
|
|
54
|
+
transactionList = yield response.data;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function updateTransaction(bookId, transaction) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions`).setMethod('PUT').setPayload(transaction).fetch();
|
|
60
|
+
return response.data;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function postTransaction(bookId, transaction) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/post`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
66
|
+
return response.data;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function checkTransaction(bookId, transaction) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/check`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
72
|
+
return response.data;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function uncheckTransaction(bookId, transaction) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/uncheck`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
78
|
+
return response.data;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function trashTransaction(bookId, transaction) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/trash`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
84
|
+
return response.data;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function restoreTransaction(bookId, transaction) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/restore`).setMethod('PATCH').setPayload(transaction).fetch();
|
|
90
|
+
return response.data;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function getTransaction(bookId, id) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
var response = yield new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions/${id}`).setMethod('GET').fetch();
|
|
96
|
+
return response.data;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function searchTransactions(bookId, query, limit, cursor) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
if (query == null) {
|
|
102
|
+
query = "";
|
|
103
|
+
}
|
|
104
|
+
var request = new http_api_request_1.HttpBooksApiV5Request(`${bookId}/transactions`);
|
|
105
|
+
request.addParam('query', query);
|
|
106
|
+
request.addParam('limit', limit);
|
|
107
|
+
if (cursor != null) {
|
|
108
|
+
request.setHeader('cursor', cursor);
|
|
109
|
+
}
|
|
110
|
+
var response = yield request.fetch();
|
|
111
|
+
return response.data;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=transaction-service.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUser = getUser;
|
|
13
|
+
const http_api_request_1 = require("./http-api-request");
|
|
14
|
+
function getUser() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const res = yield new http_api_request_1.HttpApiV5Request(`user`).setMethod('GET').fetch();
|
|
17
|
+
return res.data;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=user-service.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.47.7"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|