bkper 2.5.8 → 2.6.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/lib/cli.js +4 -2
- package/lib/index.d.ts +246 -38
- package/lib/index.js +7 -1
- package/lib/model/Account.js +5 -12
- package/lib/model/Bkper.js +21 -16
- package/lib/model/Book.js +44 -1
- package/lib/{auth/OAuthTokenProvider.js → model/Config.js} +1 -1
- package/lib/model/Connection.js +220 -0
- package/lib/model/Integration.js +95 -0
- package/lib/model/Transaction.js +5 -5
- package/lib/model/User.js +78 -0
- package/lib/service/HttpApiRequest.js +53 -23
- package/lib/service/account-service.js +1 -2
- package/lib/service/app-service.js +3 -6
- package/lib/service/book-service.js +1 -2
- package/lib/service/connection-service.js +72 -0
- package/lib/service/file-service.js +1 -2
- package/lib/service/group-service.js +4 -9
- package/lib/service/integration-service.js +53 -0
- package/lib/service/transaction-service.js +24 -17
- package/lib/service/user-service.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.Connection = void 0;
|
|
32
|
+
const ConnectionService = __importStar(require("../service/connection-service"));
|
|
33
|
+
const Integration_1 = require("./Integration");
|
|
34
|
+
/**
|
|
35
|
+
* This class defines a Connection from an User to an external service.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
class Connection {
|
|
40
|
+
constructor(json) {
|
|
41
|
+
this.wrapped = json || {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @returns The wrapped plain json object
|
|
45
|
+
*/
|
|
46
|
+
json() {
|
|
47
|
+
return this.wrapped;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @returns The id of this User
|
|
51
|
+
*/
|
|
52
|
+
getId() {
|
|
53
|
+
return this.wrapped.id;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @returns The Connection agentId
|
|
57
|
+
*/
|
|
58
|
+
getAgentId() {
|
|
59
|
+
return this.wrapped.agentId;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the Connection agentId
|
|
63
|
+
*
|
|
64
|
+
* @returns This Connection, for chainning.
|
|
65
|
+
*/
|
|
66
|
+
setAgentId(agentId) {
|
|
67
|
+
this.wrapped.agentId = agentId;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @returns The name of this Connection
|
|
72
|
+
*/
|
|
73
|
+
getName() {
|
|
74
|
+
return this.wrapped.name;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns The email of the owner of this Connection
|
|
78
|
+
*/
|
|
79
|
+
getEmail() {
|
|
80
|
+
return this.wrapped.email;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets the name of the Connection.
|
|
84
|
+
*
|
|
85
|
+
* @returns This Connection, for chainning.
|
|
86
|
+
*/
|
|
87
|
+
setName(name) {
|
|
88
|
+
this.wrapped.name = name;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Sets the universal unique identifier of this connection.
|
|
93
|
+
*
|
|
94
|
+
* @returns This Connection, for chainning.
|
|
95
|
+
*/
|
|
96
|
+
setUUID(uuid) {
|
|
97
|
+
this.wrapped.uuid = uuid;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @returns The name of universal unique identifier of the connection
|
|
102
|
+
*/
|
|
103
|
+
getUUID() {
|
|
104
|
+
return this.wrapped.uuid;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @returns The connection type
|
|
108
|
+
*/
|
|
109
|
+
getType() {
|
|
110
|
+
return this.wrapped.type;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sets the connection type.
|
|
114
|
+
*
|
|
115
|
+
* @returns This Connection, for chainning.
|
|
116
|
+
*/
|
|
117
|
+
setType(type) {
|
|
118
|
+
this.wrapped.type = type;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the custom properties stored in this Connection
|
|
123
|
+
*/
|
|
124
|
+
getProperties() {
|
|
125
|
+
return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sets the custom properties of the Connection
|
|
129
|
+
*
|
|
130
|
+
* @param properties - Object with key/value pair properties
|
|
131
|
+
*
|
|
132
|
+
* @returns This Connection, for chainning.
|
|
133
|
+
*/
|
|
134
|
+
setProperties(properties) {
|
|
135
|
+
this.wrapped.properties = Object.assign({}, properties);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets the property value for given keys. First property found will be retrieved
|
|
140
|
+
*
|
|
141
|
+
* @param keys - The property key
|
|
142
|
+
*/
|
|
143
|
+
getProperty(...keys) {
|
|
144
|
+
for (let index = 0; index < keys.length; index++) {
|
|
145
|
+
const key = keys[index];
|
|
146
|
+
let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
|
|
147
|
+
if (value != null && value.trim() != '') {
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sets a custom property in the Connection.
|
|
155
|
+
*
|
|
156
|
+
* @param key - The property key
|
|
157
|
+
* @param value - The property value
|
|
158
|
+
*/
|
|
159
|
+
setProperty(key, value) {
|
|
160
|
+
if (key == null || key.trim() == '') {
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
if (this.wrapped.properties == null) {
|
|
164
|
+
this.wrapped.properties = {};
|
|
165
|
+
}
|
|
166
|
+
this.wrapped.properties[key] = value;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Delete a custom property
|
|
171
|
+
*
|
|
172
|
+
* @param key - The property key
|
|
173
|
+
*
|
|
174
|
+
* @returns This Connection, for chainning.
|
|
175
|
+
*/
|
|
176
|
+
deleteProperty(key) {
|
|
177
|
+
this.setProperty(key, null);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Clean any token property
|
|
182
|
+
*/
|
|
183
|
+
clearTokenProperties() {
|
|
184
|
+
this.getPropertyKeys().filter(key => key.includes("token")).forEach(key => this.deleteProperty(key));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Gets the custom properties keys stored in the Connection.
|
|
188
|
+
*/
|
|
189
|
+
getPropertyKeys() {
|
|
190
|
+
let properties = this.getProperties();
|
|
191
|
+
let propertyKeys = [];
|
|
192
|
+
if (properties) {
|
|
193
|
+
for (var key in properties) {
|
|
194
|
+
if (Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
195
|
+
propertyKeys.push(key);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
propertyKeys = propertyKeys.sort();
|
|
200
|
+
return propertyKeys;
|
|
201
|
+
}
|
|
202
|
+
getIntegrations() {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const integrationsPlain = yield ConnectionService.listIntegrations(this.getId());
|
|
205
|
+
const integrations = integrationsPlain.map(i => new Integration_1.Integration(i));
|
|
206
|
+
return integrations;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Perform create new connection.
|
|
211
|
+
*/
|
|
212
|
+
create() {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
this.wrapped = yield ConnectionService.createConnection(this.wrapped);
|
|
215
|
+
return this;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.Connection = Connection;
|
|
220
|
+
//# sourceMappingURL=Connection.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
* @returns The wrapped plain json object
|
|
15
|
+
*/
|
|
16
|
+
json() {
|
|
17
|
+
return this.wrapped;
|
|
18
|
+
}
|
|
19
|
+
getBookId() {
|
|
20
|
+
return this.wrapped.bookId;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @returns The id of this User
|
|
24
|
+
*/
|
|
25
|
+
getId() {
|
|
26
|
+
return this.wrapped.id;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @returns The name of this Integration
|
|
30
|
+
*/
|
|
31
|
+
getName() {
|
|
32
|
+
return this.wrapped.name;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gets the custom properties stored in this Integration
|
|
36
|
+
*/
|
|
37
|
+
getProperties() {
|
|
38
|
+
return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the custom properties of the Integration
|
|
42
|
+
*
|
|
43
|
+
* @param properties - Object with key/value pair properties
|
|
44
|
+
*
|
|
45
|
+
* @returns This Integration, for chainning.
|
|
46
|
+
*/
|
|
47
|
+
setProperties(properties) {
|
|
48
|
+
this.wrapped.properties = Object.assign({}, properties);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the property value for given keys. First property found will be retrieved
|
|
53
|
+
*
|
|
54
|
+
* @param keys - The property key
|
|
55
|
+
*/
|
|
56
|
+
getProperty(...keys) {
|
|
57
|
+
for (let index = 0; index < keys.length; index++) {
|
|
58
|
+
const key = keys[index];
|
|
59
|
+
let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
|
|
60
|
+
if (value != null && value.trim() != '') {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets a custom property in the Integration.
|
|
68
|
+
*
|
|
69
|
+
* @param key - The property key
|
|
70
|
+
* @param value - The property value
|
|
71
|
+
*/
|
|
72
|
+
setProperty(key, value) {
|
|
73
|
+
if (key == null || key.trim() == '') {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
if (this.wrapped.properties == null) {
|
|
77
|
+
this.wrapped.properties = {};
|
|
78
|
+
}
|
|
79
|
+
this.wrapped.properties[key] = value;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Delete a custom property
|
|
84
|
+
*
|
|
85
|
+
* @param key - The property key
|
|
86
|
+
*
|
|
87
|
+
* @returns This Integration, for chainning.
|
|
88
|
+
*/
|
|
89
|
+
deleteProperty(key) {
|
|
90
|
+
this.setProperty(key, null);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.Integration = Integration;
|
|
95
|
+
//# sourceMappingURL=Integration.js.map
|
package/lib/model/Transaction.js
CHANGED
|
@@ -314,7 +314,7 @@ class Transaction {
|
|
|
314
314
|
setCreditAccount(account) {
|
|
315
315
|
if (account instanceof Account_1.Account) {
|
|
316
316
|
if (account != null && account.getId() != null) {
|
|
317
|
-
this.wrapped.creditAccount = account.
|
|
317
|
+
this.wrapped.creditAccount = account.json();
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
@@ -363,7 +363,7 @@ class Transaction {
|
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
365
365
|
*
|
|
366
|
-
* Sets the debit/
|
|
366
|
+
* Sets the debit/destination Account of the Transaction. Same as to().
|
|
367
367
|
*
|
|
368
368
|
* @param account - Account id, name or object.
|
|
369
369
|
*
|
|
@@ -372,7 +372,7 @@ class Transaction {
|
|
|
372
372
|
setDebitAccount(account) {
|
|
373
373
|
if (account instanceof Account_1.Account) {
|
|
374
374
|
if (account != null && account.getId() != null) {
|
|
375
|
-
this.wrapped.debitAccount = account.
|
|
375
|
+
this.wrapped.debitAccount = account.json();
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
else {
|
|
@@ -384,7 +384,7 @@ class Transaction {
|
|
|
384
384
|
}
|
|
385
385
|
/**
|
|
386
386
|
*
|
|
387
|
-
* Sets the debit/
|
|
387
|
+
* Sets the debit/destination Account of the Transaction. Same as setDebitAccount().
|
|
388
388
|
*
|
|
389
389
|
* @param account - Account id, name or object.
|
|
390
390
|
*
|
|
@@ -684,7 +684,7 @@ class Transaction {
|
|
|
684
684
|
*/
|
|
685
685
|
remove() {
|
|
686
686
|
return __awaiter(this, void 0, void 0, function* () {
|
|
687
|
-
let operation = yield TransactionService.
|
|
687
|
+
let operation = yield TransactionService.trashTransaction(this.book.getId(), this.wrapped);
|
|
688
688
|
this.wrapped.trashed = operation.transaction.trashed;
|
|
689
689
|
return this;
|
|
690
690
|
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.User = void 0;
|
|
32
|
+
const Connection_1 = require("./Connection");
|
|
33
|
+
const ConnectionService = __importStar(require("../service/connection-service"));
|
|
34
|
+
/**
|
|
35
|
+
* This class defines a User.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
class User {
|
|
40
|
+
constructor(wrapped) {
|
|
41
|
+
this.wrapped = wrapped;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @returns The id of the User
|
|
45
|
+
*/
|
|
46
|
+
getId() {
|
|
47
|
+
return this.wrapped.id;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @returns The name of the User
|
|
51
|
+
*/
|
|
52
|
+
getName() {
|
|
53
|
+
return this.wrapped.name;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @returns The full name of the User
|
|
57
|
+
*/
|
|
58
|
+
getFullName() {
|
|
59
|
+
return this.wrapped.fullName;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @returns The User connections
|
|
63
|
+
*/
|
|
64
|
+
getConnections() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const json = yield ConnectionService.listConnections();
|
|
67
|
+
return json.map(c => new Connection_1.Connection(c));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getConnection(id) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const json = yield ConnectionService.getConnection(id);
|
|
73
|
+
return new Connection_1.Connection(json);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.User = User;
|
|
78
|
+
//# sourceMappingURL=User.js.map
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.HttpApiV5Request = exports.HttpBooksApiV5Request = exports.HttpApiRequest = void 0;
|
|
16
16
|
const local_auth_service_1 = require("../auth/local-auth-service");
|
|
17
17
|
const gaxios_1 = require("gaxios");
|
|
18
18
|
const https_1 = __importDefault(require("https"));
|
|
@@ -24,22 +24,26 @@ class HttpApiRequest {
|
|
|
24
24
|
this.headers = {};
|
|
25
25
|
this.method = 'GET';
|
|
26
26
|
this.payload = null;
|
|
27
|
-
this.url =
|
|
27
|
+
this.url = `${HttpApiRequest.config.apiBaseUrl || "https://app.bkper.com/_ah/api/bkper"}/${path}`;
|
|
28
28
|
}
|
|
29
29
|
setMethod(method) {
|
|
30
30
|
this.method = method;
|
|
31
31
|
return this;
|
|
32
32
|
}
|
|
33
33
|
setHeader(name, value) {
|
|
34
|
-
|
|
34
|
+
if (value) {
|
|
35
|
+
this.headers[name] = value;
|
|
36
|
+
}
|
|
35
37
|
return this;
|
|
36
38
|
}
|
|
37
39
|
addParam(name, value) {
|
|
38
|
-
|
|
40
|
+
if (value) {
|
|
41
|
+
this.params.push({ name, value });
|
|
42
|
+
}
|
|
39
43
|
return this;
|
|
40
44
|
}
|
|
41
45
|
setPayload(payload) {
|
|
42
|
-
this.payload = payload;
|
|
46
|
+
this.payload = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
43
47
|
return this;
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
@@ -72,8 +76,9 @@ class HttpApiRequest {
|
|
|
72
76
|
fetch() {
|
|
73
77
|
var _a;
|
|
74
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
this.addCustomHeaders();
|
|
75
80
|
this.headers['Authorization'] = `Bearer ${yield getAccessToken()}`;
|
|
76
|
-
this.addParam('key',
|
|
81
|
+
this.addParam('key', yield getApiKey());
|
|
77
82
|
// this.httpRequest.setMuteHttpExceptions(true);
|
|
78
83
|
const url = this.getUrl();
|
|
79
84
|
try {
|
|
@@ -82,7 +87,7 @@ class HttpApiRequest {
|
|
|
82
87
|
method: this.method,
|
|
83
88
|
headers: this.headers,
|
|
84
89
|
body: this.payload,
|
|
85
|
-
agent: httpsAgent,
|
|
90
|
+
agent: url.startsWith('https') ? httpsAgent : null,
|
|
86
91
|
retryConfig: {
|
|
87
92
|
httpMethodsToRetry: ['GET', 'PUT', 'POST', 'PATCH', 'HEAD', 'OPTIONS', 'DELETE'],
|
|
88
93
|
statusCodesToRetry: [[100, 199], [429, 429], [500, 599]],
|
|
@@ -93,45 +98,70 @@ class HttpApiRequest {
|
|
|
93
98
|
});
|
|
94
99
|
}
|
|
95
100
|
catch (e) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
if (HttpApiRequest.config.requestErrorHandler) {
|
|
102
|
+
throw HttpApiRequest.config.requestErrorHandler(e);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
//Default error handler
|
|
106
|
+
let error = (_a = e.response.data) === null || _a === void 0 ? void 0 : _a.error;
|
|
107
|
+
if (error) {
|
|
108
|
+
if (error.code == 404) {
|
|
109
|
+
return { data: null };
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw error.message;
|
|
113
|
+
}
|
|
100
114
|
}
|
|
101
115
|
else {
|
|
102
|
-
throw
|
|
116
|
+
throw e.message;
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
addCustomHeaders() {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
if (HttpApiRequest.config.requestHeadersProvider) {
|
|
125
|
+
const headers = yield HttpApiRequest.config.requestHeadersProvider();
|
|
126
|
+
Object.entries(headers).forEach(([key, value]) => this.setHeader(key, value));
|
|
108
127
|
}
|
|
109
128
|
});
|
|
110
129
|
}
|
|
111
130
|
}
|
|
112
131
|
exports.HttpApiRequest = HttpApiRequest;
|
|
132
|
+
HttpApiRequest.config = {};
|
|
133
|
+
function getApiKey() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
if (HttpApiRequest.config.apiKeyProvider) {
|
|
136
|
+
return yield HttpApiRequest.config.apiKeyProvider();
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
113
141
|
function getAccessToken() {
|
|
114
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
143
|
let token = null;
|
|
116
|
-
if (HttpApiRequest.
|
|
117
|
-
token = yield HttpApiRequest.
|
|
144
|
+
if (HttpApiRequest.config.oauthTokenProvider) {
|
|
145
|
+
token = yield HttpApiRequest.config.oauthTokenProvider();
|
|
118
146
|
}
|
|
119
147
|
if (local_auth_service_1.isLoggedIn() && token == null) {
|
|
120
148
|
token = yield local_auth_service_1.getOAuthToken();
|
|
121
149
|
}
|
|
150
|
+
token = token.replace('Bearer ', '');
|
|
151
|
+
token = token.replace('bearer ', '');
|
|
122
152
|
return token;
|
|
123
153
|
});
|
|
124
154
|
}
|
|
125
|
-
class HttpBooksApiV2Request extends HttpApiRequest {
|
|
126
|
-
constructor(service) {
|
|
127
|
-
super(`v2/ledgers/${service}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.HttpBooksApiV2Request = HttpBooksApiV2Request;
|
|
131
155
|
class HttpBooksApiV5Request extends HttpApiRequest {
|
|
132
156
|
constructor(service) {
|
|
133
157
|
super(`v5/books/${service}`);
|
|
134
158
|
}
|
|
135
159
|
}
|
|
136
160
|
exports.HttpBooksApiV5Request = HttpBooksApiV5Request;
|
|
161
|
+
class HttpApiV5Request extends HttpApiRequest {
|
|
162
|
+
constructor(service) {
|
|
163
|
+
super(`v5/${service}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.HttpApiV5Request = HttpApiV5Request;
|
|
137
167
|
//# sourceMappingURL=HttpApiRequest.js.map
|
|
@@ -13,8 +13,7 @@ exports.getAccount = exports.deleteAccount = exports.updateAccount = exports.cre
|
|
|
13
13
|
const HttpApiRequest_1 = require("./HttpApiRequest");
|
|
14
14
|
function createAccount(bookId, account) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
var
|
|
17
|
-
var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts`).setMethod('POST').setPayload(payload).fetch();
|
|
16
|
+
var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}/accounts`).setMethod('POST').setPayload(account).fetch();
|
|
18
17
|
return response.data;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
@@ -13,24 +13,21 @@ exports.patchApp = exports.updateApp = exports.createApp = void 0;
|
|
|
13
13
|
const HttpApiRequest_1 = require("./HttpApiRequest");
|
|
14
14
|
function createApp(app) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
var
|
|
17
|
-
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('POST').setPayload(payload).fetch();
|
|
16
|
+
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('POST').setPayload(app).fetch();
|
|
18
17
|
return response.data;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
20
|
exports.createApp = createApp;
|
|
22
21
|
function updateApp(app) {
|
|
23
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var
|
|
25
|
-
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('PUT').setPayload(payload).fetch();
|
|
23
|
+
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('PUT').setPayload(app).fetch();
|
|
26
24
|
return response.data;
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
exports.updateApp = updateApp;
|
|
30
28
|
function patchApp(app) {
|
|
31
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
var
|
|
33
|
-
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('PATCH').setPayload(payload).fetch();
|
|
30
|
+
var response = yield new HttpApiRequest_1.HttpApiRequest(`v5/apps`).setMethod('PATCH').setPayload(app).fetch();
|
|
34
31
|
return response.data;
|
|
35
32
|
});
|
|
36
33
|
}
|
|
@@ -23,8 +23,7 @@ function loadBook(bookId) {
|
|
|
23
23
|
exports.loadBook = loadBook;
|
|
24
24
|
function updateBook(bookId, book) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var
|
|
27
|
-
var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}`).setMethod('PUT').setPayload(payload).fetch();
|
|
26
|
+
var response = yield new HttpApiRequest_1.HttpBooksApiV5Request(`${bookId}`).setMethod('PUT').setPayload(book).fetch();
|
|
28
27
|
return response.data;
|
|
29
28
|
});
|
|
30
29
|
}
|