bkper-js 2.41.1 → 2.43.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/dist/bkper.min.js +2 -2
- package/dist/bkper.min.js.map +3 -3
- package/lib/index.d.ts +28 -0
- package/lib/model/Bkper.js +14 -0
- package/lib/model/Book.js +50 -0
- package/lib/service/collaborator-service.js +28 -3
- package/lib/service/transaction-service.js +13 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1419,6 +1419,14 @@ export declare class Bkper {
|
|
|
1419
1419
|
* @returns The retrieved list of Books
|
|
1420
1420
|
*/
|
|
1421
1421
|
getBooks(query?: string): Promise<Book[]>;
|
|
1422
|
+
/**
|
|
1423
|
+
* Requests access to a Book the current user cannot access.
|
|
1424
|
+
*
|
|
1425
|
+
* @param bookId - The universal Book id
|
|
1426
|
+
* @param permission - The permission requested in the Book
|
|
1427
|
+
* @param message - An optional message to the Book owner
|
|
1428
|
+
*/
|
|
1429
|
+
requestBookAccess(bookId: string, permission: Permission, message?: string): Promise<void>;
|
|
1422
1430
|
/**
|
|
1423
1431
|
* Gets all [[Collections]] the user has access to.
|
|
1424
1432
|
*
|
|
@@ -2069,6 +2077,16 @@ export declare class Book extends ResourceProperty<bkper.Book> {
|
|
|
2069
2077
|
* @returns The [[Transaction]] object
|
|
2070
2078
|
*/
|
|
2071
2079
|
getTransaction(id: string): Promise<Transaction | undefined>;
|
|
2080
|
+
/**
|
|
2081
|
+
* Retrieve complete transactions by id.
|
|
2082
|
+
*
|
|
2083
|
+
* Requests are sent sequentially in batches of up to 200 IDs.
|
|
2084
|
+
*
|
|
2085
|
+
* @param ids - The transaction IDs
|
|
2086
|
+
*
|
|
2087
|
+
* @returns The matching Transactions in input order
|
|
2088
|
+
*/
|
|
2089
|
+
getTransactionsByIds(ids: string[]): Promise<Transaction[]>;
|
|
2072
2090
|
/**
|
|
2073
2091
|
* Retrieve a file by id.
|
|
2074
2092
|
*
|
|
@@ -2133,6 +2151,16 @@ export declare class Book extends ResourceProperty<bkper.Book> {
|
|
|
2133
2151
|
* @returns The saved queries from this book
|
|
2134
2152
|
*/
|
|
2135
2153
|
getSavedQueries(): Promise<Query[]>;
|
|
2154
|
+
/**
|
|
2155
|
+
* Resolves an access request for this Book.
|
|
2156
|
+
*
|
|
2157
|
+
* Resolving the request does not grant access. Call Collaborator.create
|
|
2158
|
+
* on the returned Collaborator to grant access to the Book.
|
|
2159
|
+
*
|
|
2160
|
+
* @param accessRequestId - The access request id
|
|
2161
|
+
* @returns The matching [[Collaborator]] object
|
|
2162
|
+
*/
|
|
2163
|
+
resolveAccessRequest(accessRequestId: string): Promise<Collaborator>;
|
|
2136
2164
|
/**
|
|
2137
2165
|
* Gets all collaborators of this Book.
|
|
2138
2166
|
*
|
package/lib/model/Bkper.js
CHANGED
|
@@ -12,6 +12,7 @@ import { App } from './App.js';
|
|
|
12
12
|
import * as AppService from '../service/app-service.js';
|
|
13
13
|
import * as BookService from '../service/book-service.js';
|
|
14
14
|
import * as CollectionService from '../service/collection-service.js';
|
|
15
|
+
import * as CollaboratorService from '../service/collaborator-service.js';
|
|
15
16
|
import * as UserService from '../service/user-service.js';
|
|
16
17
|
import * as TemplateService from '../service/template-service.js';
|
|
17
18
|
import { User } from './User.js';
|
|
@@ -83,6 +84,19 @@ export class Bkper {
|
|
|
83
84
|
return books.map(book => new Book(book, this.config));
|
|
84
85
|
});
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Requests access to a Book the current user cannot access.
|
|
89
|
+
*
|
|
90
|
+
* @param bookId - The universal Book id
|
|
91
|
+
* @param permission - The permission requested in the Book
|
|
92
|
+
* @param message - An optional message to the Book owner
|
|
93
|
+
*/
|
|
94
|
+
requestBookAccess(bookId, permission, message) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const trimmedMessage = message === null || message === void 0 ? void 0 : message.trim();
|
|
97
|
+
yield CollaboratorService.requestBookAccess(bookId, permission, trimmedMessage || undefined, this.config);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
86
100
|
/**
|
|
87
101
|
* Gets all [[Collections]] the user has access to.
|
|
88
102
|
*
|
package/lib/model/Book.js
CHANGED
|
@@ -1224,6 +1224,41 @@ export class Book extends ResourceProperty {
|
|
|
1224
1224
|
return transaction;
|
|
1225
1225
|
});
|
|
1226
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Retrieve complete transactions by id.
|
|
1229
|
+
*
|
|
1230
|
+
* Requests are sent sequentially in batches of up to 200 IDs.
|
|
1231
|
+
*
|
|
1232
|
+
* @param ids - The transaction IDs
|
|
1233
|
+
*
|
|
1234
|
+
* @returns The matching Transactions in input order
|
|
1235
|
+
*/
|
|
1236
|
+
getTransactionsByIds(ids) {
|
|
1237
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1238
|
+
if (ids == null) {
|
|
1239
|
+
throw new Error('Transaction IDs are required.');
|
|
1240
|
+
}
|
|
1241
|
+
const distinctIds = new Set();
|
|
1242
|
+
const normalizedIds = [];
|
|
1243
|
+
for (const id of ids) {
|
|
1244
|
+
if (id == null || typeof id !== 'string' || id.trim() === '') {
|
|
1245
|
+
throw new Error('Transaction IDs must be non-blank strings.');
|
|
1246
|
+
}
|
|
1247
|
+
const normalizedId = id.trim();
|
|
1248
|
+
if (distinctIds.has(normalizedId)) {
|
|
1249
|
+
throw new Error(`Duplicate transaction ID: ${normalizedId}`);
|
|
1250
|
+
}
|
|
1251
|
+
distinctIds.add(normalizedId);
|
|
1252
|
+
normalizedIds.push(normalizedId);
|
|
1253
|
+
}
|
|
1254
|
+
const transactions = [];
|
|
1255
|
+
for (let index = 0; index < normalizedIds.length; index += 200) {
|
|
1256
|
+
const payloads = yield TransactionService.getTransactionsByIds(this.getId(), normalizedIds.slice(index, index + 200), this.getConfig());
|
|
1257
|
+
transactions.push(...payloads.map(payload => new Transaction(this, payload)));
|
|
1258
|
+
}
|
|
1259
|
+
return transactions;
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1227
1262
|
/**
|
|
1228
1263
|
* Retrieve a file by id.
|
|
1229
1264
|
*
|
|
@@ -1330,6 +1365,21 @@ export class Book extends ResourceProperty {
|
|
|
1330
1365
|
return this.queries;
|
|
1331
1366
|
});
|
|
1332
1367
|
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Resolves an access request for this Book.
|
|
1370
|
+
*
|
|
1371
|
+
* Resolving the request does not grant access. Call Collaborator.create
|
|
1372
|
+
* on the returned Collaborator to grant access to the Book.
|
|
1373
|
+
*
|
|
1374
|
+
* @param accessRequestId - The access request id
|
|
1375
|
+
* @returns The matching [[Collaborator]] object
|
|
1376
|
+
*/
|
|
1377
|
+
resolveAccessRequest(accessRequestId) {
|
|
1378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1379
|
+
const payload = yield CollaboratorService.resolveBookAccessRequest(this.getId(), accessRequestId, this.getConfig());
|
|
1380
|
+
return new Collaborator(this, payload);
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1333
1383
|
/**
|
|
1334
1384
|
* Gets all collaborators of this Book.
|
|
1335
1385
|
*
|
|
@@ -8,16 +8,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { HttpBooksApiV5Request } from './http-api-request.js';
|
|
11
|
+
export function requestBookAccess(bookId, permission, message, config) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
let request = new HttpBooksApiV5Request(`${bookId}/collaborators/request`, config)
|
|
14
|
+
.setMethod('POST')
|
|
15
|
+
.addParam('permission', permission);
|
|
16
|
+
if (message) {
|
|
17
|
+
request = request.addParam('message', message);
|
|
18
|
+
}
|
|
19
|
+
yield request.fetch();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function resolveBookAccessRequest(bookId, accessRequestId, config) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/request/${encodeURIComponent(accessRequestId)}`, config)
|
|
25
|
+
.setMethod('GET')
|
|
26
|
+
.fetch();
|
|
27
|
+
return response.data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
11
30
|
export function listCollaborators(bookId, config) {
|
|
12
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
32
|
var _a;
|
|
14
|
-
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators`, config)
|
|
33
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators`, config)
|
|
34
|
+
.setMethod('GET')
|
|
35
|
+
.fetch();
|
|
15
36
|
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
37
|
});
|
|
17
38
|
}
|
|
18
39
|
export function addOrUpdateCollaborator(bookId, collaborator, message, config) {
|
|
19
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
let request = new HttpBooksApiV5Request(`${bookId}/collaborators`, config)
|
|
41
|
+
let request = new HttpBooksApiV5Request(`${bookId}/collaborators`, config)
|
|
42
|
+
.setMethod('POST')
|
|
43
|
+
.setPayload(collaborator);
|
|
21
44
|
if (message) {
|
|
22
45
|
request = request.addParam('message', message);
|
|
23
46
|
}
|
|
@@ -27,7 +50,9 @@ export function addOrUpdateCollaborator(bookId, collaborator, message, config) {
|
|
|
27
50
|
}
|
|
28
51
|
export function removeCollaborator(bookId, email, config) {
|
|
29
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/${email}`, config)
|
|
53
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/collaborators/${email}`, config)
|
|
54
|
+
.setMethod('DELETE')
|
|
55
|
+
.fetch();
|
|
31
56
|
return response.data;
|
|
32
57
|
});
|
|
33
58
|
}
|
|
@@ -108,6 +108,19 @@ export function getTransaction(bookId, id, config) {
|
|
|
108
108
|
return response.data;
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
+
export function getTransactionsByIds(bookId, ids, config) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const payload = {
|
|
114
|
+
items: ids.map(id => ({ id: id })),
|
|
115
|
+
};
|
|
116
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/transactions/load/batch`, config)
|
|
117
|
+
.setMethod('POST')
|
|
118
|
+
.setPayload(payload)
|
|
119
|
+
.fetch();
|
|
120
|
+
const transactionList = response.data;
|
|
121
|
+
return transactionList != null && transactionList.items != null ? transactionList.items : [];
|
|
122
|
+
});
|
|
123
|
+
}
|
|
111
124
|
export function listTransactions(bookId, query, limit, cursor, config) {
|
|
112
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
126
|
if (!query) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.43.0",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"release:major": "npm version major -m \"chore(release): v%s\""
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@bkper/bkper-api-types": "^5.
|
|
41
|
+
"@bkper/bkper-api-types": "^5.44.0",
|
|
42
42
|
"big.js": "^6.0.3",
|
|
43
43
|
"dayjs": "^1.10.3",
|
|
44
44
|
"luxon": "^1.25.0",
|