bkper-js 2.6.0 → 2.7.1
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 +87 -0
- package/lib/index.js +1 -0
- package/lib/model/Book.js +31 -0
- package/lib/model/Collaborator.js +118 -0
- package/lib/service/balances-service.js +7 -4
- package/lib/service/collaborator-service.js +34 -0
- package/lib/service/http-api-request.js +30 -32
- package/lib/service/http-request.js +31 -9
- package/package.json +2 -4
package/lib/index.d.ts
CHANGED
|
@@ -1271,6 +1271,7 @@ export declare class Book {
|
|
|
1271
1271
|
|
|
1272
1272
|
|
|
1273
1273
|
|
|
1274
|
+
|
|
1274
1275
|
constructor(payload?: bkper.Book);
|
|
1275
1276
|
/**
|
|
1276
1277
|
* Gets an immutable copy of the JSON payload for this Book.
|
|
@@ -1498,6 +1499,14 @@ export declare class Book {
|
|
|
1498
1499
|
* @returns The visibility of the book
|
|
1499
1500
|
*/
|
|
1500
1501
|
getVisibility(): Visibility;
|
|
1502
|
+
/**
|
|
1503
|
+
* Sets the visibility of the book.
|
|
1504
|
+
*
|
|
1505
|
+
* @param visibility - The visibility to set
|
|
1506
|
+
*
|
|
1507
|
+
* @returns This Book, for chaining
|
|
1508
|
+
*/
|
|
1509
|
+
setVisibility(visibility: Visibility): Book;
|
|
1501
1510
|
/**
|
|
1502
1511
|
* Gets the custom properties stored in this Book.
|
|
1503
1512
|
*
|
|
@@ -1722,6 +1731,7 @@ export declare class Book {
|
|
|
1722
1731
|
|
|
1723
1732
|
|
|
1724
1733
|
|
|
1734
|
+
|
|
1725
1735
|
/**
|
|
1726
1736
|
* Lists transactions in the Book based on the provided query, limit, and cursor, for pagination.
|
|
1727
1737
|
*
|
|
@@ -1809,6 +1819,12 @@ export declare class Book {
|
|
|
1809
1819
|
* @returns The saved queries from this book
|
|
1810
1820
|
*/
|
|
1811
1821
|
getSavedQueries(): Promise<Query[]>;
|
|
1822
|
+
/**
|
|
1823
|
+
* Gets all collaborators of this Book.
|
|
1824
|
+
*
|
|
1825
|
+
* @returns Array of Collaborator objects
|
|
1826
|
+
*/
|
|
1827
|
+
getCollaborators(): Promise<Collaborator[]>;
|
|
1812
1828
|
}
|
|
1813
1829
|
|
|
1814
1830
|
/**
|
|
@@ -1886,6 +1902,77 @@ export declare enum BotResponseType {
|
|
|
1886
1902
|
ERROR = "ERROR"
|
|
1887
1903
|
}
|
|
1888
1904
|
|
|
1905
|
+
/**
|
|
1906
|
+
* This class defines a Collaborator of a [[Book]].
|
|
1907
|
+
*
|
|
1908
|
+
* A Collaborator represents a user that has been granted access to a Book with specific permissions.
|
|
1909
|
+
*
|
|
1910
|
+
* @public
|
|
1911
|
+
*/
|
|
1912
|
+
export declare class Collaborator {
|
|
1913
|
+
payload: bkper.Collaborator;
|
|
1914
|
+
|
|
1915
|
+
constructor(book: Book, payload?: bkper.Collaborator);
|
|
1916
|
+
/**
|
|
1917
|
+
* Gets an immutable copy of the JSON payload.
|
|
1918
|
+
*
|
|
1919
|
+
* @returns An immutable copy of the json payload
|
|
1920
|
+
*/
|
|
1921
|
+
json(): bkper.Collaborator;
|
|
1922
|
+
/**
|
|
1923
|
+
* Gets the Collaborator internal id.
|
|
1924
|
+
*
|
|
1925
|
+
* @returns The Collaborator internal id
|
|
1926
|
+
*/
|
|
1927
|
+
getId(): string | undefined;
|
|
1928
|
+
/**
|
|
1929
|
+
* Gets the Collaborator email address.
|
|
1930
|
+
*
|
|
1931
|
+
* @returns The Collaborator email address
|
|
1932
|
+
*/
|
|
1933
|
+
getEmail(): string | undefined;
|
|
1934
|
+
/**
|
|
1935
|
+
* Sets the email address of the Collaborator.
|
|
1936
|
+
*
|
|
1937
|
+
* @param email - The email address to set
|
|
1938
|
+
*
|
|
1939
|
+
* @returns This Collaborator, for chaining
|
|
1940
|
+
*/
|
|
1941
|
+
setEmail(email: string): Collaborator;
|
|
1942
|
+
/**
|
|
1943
|
+
* Gets the permission level of the Collaborator.
|
|
1944
|
+
*
|
|
1945
|
+
* @returns The permission level
|
|
1946
|
+
*/
|
|
1947
|
+
getPermission(): Permission | undefined;
|
|
1948
|
+
/**
|
|
1949
|
+
* Sets the permission level of the Collaborator.
|
|
1950
|
+
*
|
|
1951
|
+
* @param permission - The permission level to set
|
|
1952
|
+
*
|
|
1953
|
+
* @returns This Collaborator, for chaining
|
|
1954
|
+
*/
|
|
1955
|
+
setPermission(permission: Permission): Collaborator;
|
|
1956
|
+
/**
|
|
1957
|
+
* Performs create new Collaborator.
|
|
1958
|
+
*
|
|
1959
|
+
* @returns Promise with the created Collaborator
|
|
1960
|
+
*/
|
|
1961
|
+
create(message?: string): Promise<Collaborator>;
|
|
1962
|
+
/**
|
|
1963
|
+
* Performs update Collaborator.
|
|
1964
|
+
*
|
|
1965
|
+
* @returns Promise with the updated Collaborator
|
|
1966
|
+
*/
|
|
1967
|
+
update(): Promise<Collaborator>;
|
|
1968
|
+
/**
|
|
1969
|
+
* Performs remove Collaborator.
|
|
1970
|
+
*
|
|
1971
|
+
* @returns Promise with the removed Collaborator
|
|
1972
|
+
*/
|
|
1973
|
+
remove(): Promise<Collaborator>;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1889
1976
|
/**
|
|
1890
1977
|
* This class defines a Collection of [[Books]].
|
|
1891
1978
|
*
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export { BalancesDataTableBuilder } from './model/BalancesDataTableBuilder.js';
|
|
|
14
14
|
export { BalancesReport } from './model/BalancesReport.js';
|
|
15
15
|
export { Bkper } from './model/Bkper.js';
|
|
16
16
|
export { Book } from './model/Book.js';
|
|
17
|
+
export { Collaborator } from './model/Collaborator.js';
|
|
17
18
|
export { Collection } from './model/Collection.js';
|
|
18
19
|
export { Connection } from './model/Connection.js';
|
|
19
20
|
export { Conversation } from './model/Conversation.js';
|
package/lib/model/Book.js
CHANGED
|
@@ -16,8 +16,10 @@ import * as GroupService from '../service/group-service.js';
|
|
|
16
16
|
import * as IntegrationService from '../service/integration-service.js';
|
|
17
17
|
import * as TransactionService from '../service/transaction-service.js';
|
|
18
18
|
import * as EventService from '../service/event-service.js';
|
|
19
|
+
import * as CollaboratorService from '../service/collaborator-service.js';
|
|
19
20
|
import * as Utils from '../utils.js';
|
|
20
21
|
import { Account } from './Account.js';
|
|
22
|
+
import { Collaborator } from './Collaborator.js';
|
|
21
23
|
import { Collection } from './Collection.js';
|
|
22
24
|
import { Permission } from './Enums.js';
|
|
23
25
|
import { EventList } from './EventList.js';
|
|
@@ -360,6 +362,17 @@ export class Book {
|
|
|
360
362
|
getVisibility() {
|
|
361
363
|
return this.payload.visibility;
|
|
362
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Sets the visibility of the book.
|
|
367
|
+
*
|
|
368
|
+
* @param visibility - The visibility to set
|
|
369
|
+
*
|
|
370
|
+
* @returns This Book, for chaining
|
|
371
|
+
*/
|
|
372
|
+
setVisibility(visibility) {
|
|
373
|
+
this.payload.visibility = visibility;
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
363
376
|
/**
|
|
364
377
|
* Gets the custom properties stored in this Book.
|
|
365
378
|
*
|
|
@@ -929,6 +942,10 @@ export class Book {
|
|
|
929
942
|
this.nameAccountMap = undefined;
|
|
930
943
|
}
|
|
931
944
|
/** @internal */
|
|
945
|
+
clearCollaboratorCache() {
|
|
946
|
+
this.collaborators = undefined;
|
|
947
|
+
}
|
|
948
|
+
/** @internal */
|
|
932
949
|
setAccount(account, remove) {
|
|
933
950
|
const accountPayloads = this.payload.accounts || [];
|
|
934
951
|
if (remove) {
|
|
@@ -1103,5 +1120,19 @@ export class Book {
|
|
|
1103
1120
|
return this.queries;
|
|
1104
1121
|
});
|
|
1105
1122
|
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Gets all collaborators of this Book.
|
|
1125
|
+
*
|
|
1126
|
+
* @returns Array of Collaborator objects
|
|
1127
|
+
*/
|
|
1128
|
+
getCollaborators() {
|
|
1129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1130
|
+
if (!this.collaborators) {
|
|
1131
|
+
const collaboratorPayloads = yield CollaboratorService.listCollaborators(this.getId());
|
|
1132
|
+
this.collaborators = collaboratorPayloads.map(payload => new Collaborator(this, payload));
|
|
1133
|
+
}
|
|
1134
|
+
return this.collaborators;
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1106
1137
|
}
|
|
1107
1138
|
//# sourceMappingURL=Book.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import * as CollaboratorService from '../service/collaborator-service.js';
|
|
11
|
+
/**
|
|
12
|
+
* This class defines a Collaborator of a [[Book]].
|
|
13
|
+
*
|
|
14
|
+
* A Collaborator represents a user that has been granted access to a Book with specific permissions.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export class Collaborator {
|
|
19
|
+
constructor(book, payload) {
|
|
20
|
+
this.book = book;
|
|
21
|
+
this.payload = payload || {};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gets an immutable copy of the JSON payload.
|
|
25
|
+
*
|
|
26
|
+
* @returns An immutable copy of the json payload
|
|
27
|
+
*/
|
|
28
|
+
json() {
|
|
29
|
+
return Object.assign({}, this.payload);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the Collaborator internal id.
|
|
33
|
+
*
|
|
34
|
+
* @returns The Collaborator internal id
|
|
35
|
+
*/
|
|
36
|
+
getId() {
|
|
37
|
+
return this.payload.id;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the Collaborator email address.
|
|
41
|
+
*
|
|
42
|
+
* @returns The Collaborator email address
|
|
43
|
+
*/
|
|
44
|
+
getEmail() {
|
|
45
|
+
return this.payload.email;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the email address of the Collaborator.
|
|
49
|
+
*
|
|
50
|
+
* @param email - The email address to set
|
|
51
|
+
*
|
|
52
|
+
* @returns This Collaborator, for chaining
|
|
53
|
+
*/
|
|
54
|
+
setEmail(email) {
|
|
55
|
+
this.payload.email = email;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the permission level of the Collaborator.
|
|
60
|
+
*
|
|
61
|
+
* @returns The permission level
|
|
62
|
+
*/
|
|
63
|
+
getPermission() {
|
|
64
|
+
return this.payload.permission;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets the permission level of the Collaborator.
|
|
68
|
+
*
|
|
69
|
+
* @param permission - The permission level to set
|
|
70
|
+
*
|
|
71
|
+
* @returns This Collaborator, for chaining
|
|
72
|
+
*/
|
|
73
|
+
setPermission(permission) {
|
|
74
|
+
this.payload.permission = permission;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Performs create new Collaborator.
|
|
79
|
+
*
|
|
80
|
+
* @returns Promise with the created Collaborator
|
|
81
|
+
*/
|
|
82
|
+
create(message) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload, message);
|
|
85
|
+
this.book.clearCollaboratorCache();
|
|
86
|
+
return this;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Performs update Collaborator.
|
|
91
|
+
*
|
|
92
|
+
* @returns Promise with the updated Collaborator
|
|
93
|
+
*/
|
|
94
|
+
update() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
this.payload = yield CollaboratorService.addOrUpdateCollaborator(this.book.getId(), this.payload);
|
|
97
|
+
this.book.clearCollaboratorCache();
|
|
98
|
+
return this;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Performs remove Collaborator.
|
|
103
|
+
*
|
|
104
|
+
* @returns Promise with the removed Collaborator
|
|
105
|
+
*/
|
|
106
|
+
remove() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const email = this.getEmail();
|
|
109
|
+
if (!email) {
|
|
110
|
+
throw new Error('Collaborator email is required');
|
|
111
|
+
}
|
|
112
|
+
this.payload = yield CollaboratorService.removeCollaborator(this.book.getId(), email);
|
|
113
|
+
this.book.clearCollaboratorCache();
|
|
114
|
+
return this;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=Collaborator.js.map
|
|
@@ -8,12 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { HttpBooksApiV5Request } from "./http-api-request.js";
|
|
11
|
-
import
|
|
11
|
+
import { HttpRequest } from "./http-request.js";
|
|
12
12
|
export function getBalances(bookId, query) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
let response = yield new HttpBooksApiV5Request(`${bookId}/balances`).addParam('query', query).addParam('time', Date.now()).fetch();
|
|
16
|
+
const balancesUrl = (_a = response.data) === null || _a === void 0 ? void 0 : _a.balancesUrl; // Expected for large payloads
|
|
17
|
+
if (balancesUrl) {
|
|
18
|
+
const balancesResponse = yield new HttpRequest(balancesUrl).setMethod('GET').execute();
|
|
19
|
+
response = { data: balancesResponse.data, status: balancesResponse.status };
|
|
17
20
|
}
|
|
18
21
|
return response.data;
|
|
19
22
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { HttpBooksApiV5Request } from './http-api-request.js';
|
|
11
|
+
export function listCollaborators(bookId) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a;
|
|
14
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators`).setMethod('GET').fetch();
|
|
15
|
+
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function addOrUpdateCollaborator(bookId, collaborator, message) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
let request = new HttpBooksApiV5Request(`${bookId}/collaborators`).setMethod('POST').setPayload(collaborator);
|
|
21
|
+
if (message) {
|
|
22
|
+
request = request.addParam('message', message);
|
|
23
|
+
}
|
|
24
|
+
const response = yield request.fetch();
|
|
25
|
+
return response.data;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function removeCollaborator(bookId, email) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/${email}`).setMethod('DELETE').fetch();
|
|
31
|
+
return response.data;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=collaborator-service.js.map
|
|
@@ -21,59 +21,57 @@ export class HttpApiRequest extends HttpRequest {
|
|
|
21
21
|
this.addCustomHeaders();
|
|
22
22
|
this.setHeader('Authorization', `Bearer ${yield getAccessToken()}`);
|
|
23
23
|
this.addParam('key', yield getApiKey());
|
|
24
|
-
// this.httpRequest.setMuteHttpExceptions(true);
|
|
25
24
|
try {
|
|
26
25
|
let resp = yield _super.execute.call(this);
|
|
27
26
|
if (resp.status >= 200 && resp.status < 300) {
|
|
28
27
|
return resp;
|
|
29
28
|
}
|
|
29
|
+
else if (resp.status == 404) {
|
|
30
|
+
return { data: null, status: resp.status };
|
|
31
|
+
}
|
|
32
|
+
else if (resp.status != 400 && this.retry <= 3) {
|
|
33
|
+
this.retry++;
|
|
34
|
+
if (HttpApiRequest.config.requestRetryHandler) {
|
|
35
|
+
yield HttpApiRequest.config.requestRetryHandler(resp.status, resp.data, this.retry);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log(`${JSON.stringify(resp.data)} - Retrying... `);
|
|
39
|
+
}
|
|
40
|
+
return yield this.fetch();
|
|
41
|
+
}
|
|
30
42
|
else {
|
|
31
|
-
|
|
43
|
+
// Create an error object that matches axios error structure for compatibility
|
|
44
|
+
const errorObj = {
|
|
45
|
+
response: {
|
|
46
|
+
status: resp.status,
|
|
47
|
+
data: resp.data
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
throw this.handleError(errorObj);
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
53
|
catch (error) {
|
|
54
|
+
// If error already has response structure (from our code above), use it
|
|
35
55
|
if (error.response) {
|
|
36
|
-
|
|
37
|
-
// The request was made and the server responded with a status code
|
|
38
|
-
// that falls out of the range of 2xx
|
|
39
|
-
// console.log(error.response.data);
|
|
40
|
-
// console.log(error.response.status);
|
|
41
|
-
// console.log(error.response.headers);
|
|
42
|
-
if (errorResp.status == 404) {
|
|
43
|
-
return { data: null };
|
|
44
|
-
}
|
|
45
|
-
else if (errorResp.status != 400 && this.retry <= 3) {
|
|
46
|
-
this.retry++;
|
|
47
|
-
if (HttpApiRequest.config.requestRetryHandler) {
|
|
48
|
-
yield HttpApiRequest.config.requestRetryHandler(errorResp.status, errorResp.data, this.retry);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
console.log(`${JSON.stringify(errorResp.data)} - Retrying... `);
|
|
52
|
-
}
|
|
53
|
-
return yield this.fetch();
|
|
54
|
-
}
|
|
55
|
-
throw this.handleError(errorResp.data);
|
|
56
|
+
throw error;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
// http.ClientRequest in node.js
|
|
58
|
+
// Network error or fetch failure
|
|
59
|
+
if (error instanceof TypeError && error.message.includes('fetch')) {
|
|
60
|
+
// Network error - retry if within retry limit
|
|
61
61
|
if (this.retry <= 3) {
|
|
62
62
|
this.retry++;
|
|
63
63
|
if (HttpApiRequest.config.requestRetryHandler) {
|
|
64
64
|
yield HttpApiRequest.config.requestRetryHandler(520, undefined, this.retry);
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
|
-
console.log(`
|
|
67
|
+
console.log(`Network error - Retrying... `);
|
|
68
68
|
}
|
|
69
69
|
return yield this.fetch();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
throw this.handleError(error.toJSON ? error.toJSON() : error);
|
|
72
|
+
// Other errors
|
|
73
|
+
console.log('Error', error.message);
|
|
74
|
+
throw this.handleError(error);
|
|
77
75
|
}
|
|
78
76
|
});
|
|
79
77
|
}
|
|
@@ -7,9 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import https from 'https';
|
|
11
|
-
import axios from 'axios';
|
|
12
|
-
const httpsAgent = https && https.Agent ? new https.Agent({ keepAlive: true }) : undefined;
|
|
13
10
|
export class HttpRequest {
|
|
14
11
|
constructor(url) {
|
|
15
12
|
this.params = [];
|
|
@@ -64,14 +61,39 @@ export class HttpRequest {
|
|
|
64
61
|
execute() {
|
|
65
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
63
|
const url = this.getUrl();
|
|
67
|
-
|
|
68
|
-
url: url,
|
|
64
|
+
const fetchOptions = {
|
|
69
65
|
method: this.method,
|
|
70
66
|
headers: this.headers,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
};
|
|
68
|
+
// Add body for non-GET requests
|
|
69
|
+
if (this.payload && this.method !== 'GET') {
|
|
70
|
+
if (typeof this.payload === 'string') {
|
|
71
|
+
fetchOptions.body = this.payload;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
fetchOptions.body = JSON.stringify(this.payload);
|
|
75
|
+
// Ensure content-type is set for JSON payloads
|
|
76
|
+
if (!this.headers['Content-Type'] && !this.headers['content-type']) {
|
|
77
|
+
fetchOptions.headers = Object.assign(Object.assign({}, this.headers), { 'Content-Type': 'application/json' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const response = yield fetch(url, fetchOptions);
|
|
82
|
+
// Parse response body
|
|
83
|
+
let data;
|
|
84
|
+
const contentType = response.headers.get('content-type');
|
|
85
|
+
if (contentType && contentType.includes('application/json')) {
|
|
86
|
+
data = yield response.json();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
data = yield response.text();
|
|
90
|
+
}
|
|
91
|
+
// Return axios-compatible response structure
|
|
92
|
+
return {
|
|
93
|
+
data: data,
|
|
94
|
+
status: response.status,
|
|
95
|
+
headers: response.headers
|
|
96
|
+
};
|
|
75
97
|
});
|
|
76
98
|
}
|
|
77
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -34,11 +34,9 @@
|
|
|
34
34
|
"postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@bkper/bkper-api-types": "^5.
|
|
37
|
+
"@bkper/bkper-api-types": "^5.25.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@google-cloud/local-auth": "^3.0.1",
|
|
41
|
-
"axios": "^1.7.7",
|
|
42
40
|
"big.js": "^6.0.3",
|
|
43
41
|
"dayjs": "^1.10.3",
|
|
44
42
|
"luxon": "^1.25.0"
|