bkper-js 2.32.2 → 2.33.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/dist/bkper.min.js +2 -2
- package/dist/bkper.min.js.map +3 -3
- package/lib/index.d.ts +12 -25
- package/lib/model/Bkper.js +14 -39
- package/lib/model/Book.js +20 -0
- package/lib/service/http-api-request.js +4 -1
- package/lib/service/transaction-service.js +7 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1354,31 +1354,6 @@ export declare class Billing extends Resource<bkper.Billing> {
|
|
|
1354
1354
|
/**
|
|
1355
1355
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
1356
1356
|
*
|
|
1357
|
-
* You can configure the library in two ways:
|
|
1358
|
-
*
|
|
1359
|
-
* 1. Using static configuration (traditional approach):
|
|
1360
|
-
*
|
|
1361
|
-
* ```typescript
|
|
1362
|
-
* Bkper.setConfig({
|
|
1363
|
-
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
1364
|
-
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
1365
|
-
* });
|
|
1366
|
-
*
|
|
1367
|
-
* const bkper = new Bkper();
|
|
1368
|
-
* const book = await bkper.getBook('bookId');
|
|
1369
|
-
* ```
|
|
1370
|
-
*
|
|
1371
|
-
* 2. Using per-instance configuration (recommended for Cloudflare Workers):
|
|
1372
|
-
*
|
|
1373
|
-
* ```typescript
|
|
1374
|
-
* const bkper = new Bkper({
|
|
1375
|
-
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
1376
|
-
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
1377
|
-
* });
|
|
1378
|
-
*
|
|
1379
|
-
* const book = await bkper.getBook('bookId');
|
|
1380
|
-
* ```
|
|
1381
|
-
*
|
|
1382
1357
|
* @public
|
|
1383
1358
|
*/
|
|
1384
1359
|
export declare class Bkper {
|
|
@@ -1821,6 +1796,18 @@ export declare class Book extends ResourceProperty<bkper.Book> {
|
|
|
1821
1796
|
* @param transactions - The transactions to be untrashed
|
|
1822
1797
|
*/
|
|
1823
1798
|
batchUntrashTransactions(transactions: Transaction[]): Promise<void>;
|
|
1799
|
+
/**
|
|
1800
|
+
* Merge two [[Transactions]] into a single new canonical transaction.
|
|
1801
|
+
*
|
|
1802
|
+
* The merged transaction is created synchronously. Cleanup of the two
|
|
1803
|
+
* originals is scheduled asynchronously by the backend.
|
|
1804
|
+
*
|
|
1805
|
+
* @param transaction1 - The first transaction to merge
|
|
1806
|
+
* @param transaction2 - The second transaction to merge
|
|
1807
|
+
*
|
|
1808
|
+
* @returns The merged Transaction
|
|
1809
|
+
*/
|
|
1810
|
+
mergeTransactions(transaction1: Transaction, transaction2: Transaction): Promise<Transaction>;
|
|
1824
1811
|
/**
|
|
1825
1812
|
* Replay [[Events]] on the Book, in batch.
|
|
1826
1813
|
*
|
package/lib/model/Bkper.js
CHANGED
|
@@ -7,44 +7,19 @@ 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 { Book } from
|
|
11
|
-
import { App } from
|
|
12
|
-
import * as AppService from
|
|
13
|
-
import * as BookService from
|
|
14
|
-
import * as CollectionService from
|
|
15
|
-
import * as UserService from
|
|
16
|
-
import * as TemplateService from
|
|
17
|
-
import { User } from
|
|
18
|
-
import { Template } from
|
|
19
|
-
import { Collection } from
|
|
10
|
+
import { Book } from './Book.js';
|
|
11
|
+
import { App } from './App.js';
|
|
12
|
+
import * as AppService from '../service/app-service.js';
|
|
13
|
+
import * as BookService from '../service/book-service.js';
|
|
14
|
+
import * as CollectionService from '../service/collection-service.js';
|
|
15
|
+
import * as UserService from '../service/user-service.js';
|
|
16
|
+
import * as TemplateService from '../service/template-service.js';
|
|
17
|
+
import { User } from './User.js';
|
|
18
|
+
import { Template } from './Template.js';
|
|
19
|
+
import { Collection } from './Collection.js';
|
|
20
20
|
/**
|
|
21
21
|
* This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
|
|
22
22
|
*
|
|
23
|
-
* You can configure the library in two ways:
|
|
24
|
-
*
|
|
25
|
-
* 1. Using static configuration (traditional approach):
|
|
26
|
-
*
|
|
27
|
-
* ```typescript
|
|
28
|
-
* Bkper.setConfig({
|
|
29
|
-
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
30
|
-
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* const bkper = new Bkper();
|
|
34
|
-
* const book = await bkper.getBook('bookId');
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* 2. Using per-instance configuration (recommended for Cloudflare Workers):
|
|
38
|
-
*
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const bkper = new Bkper({
|
|
41
|
-
* apiKeyProvider: () => process.env.BKPER_API_KEY,
|
|
42
|
-
* oauthTokenProvider: () => process.env.BKPER_OAUTH_TOKEN
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* const book = await bkper.getBook('bookId');
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
23
|
* @public
|
|
49
24
|
*/
|
|
50
25
|
export class Bkper {
|
|
@@ -105,7 +80,7 @@ export class Bkper {
|
|
|
105
80
|
getBooks(query) {
|
|
106
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
82
|
let books = yield BookService.loadBooks(query, this.config);
|
|
108
|
-
return books.map(
|
|
83
|
+
return books.map(book => new Book(book, this.config));
|
|
109
84
|
});
|
|
110
85
|
}
|
|
111
86
|
/**
|
|
@@ -116,7 +91,7 @@ export class Bkper {
|
|
|
116
91
|
getCollections() {
|
|
117
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
93
|
let collections = yield CollectionService.loadCollections(this.config);
|
|
119
|
-
return collections.map(
|
|
94
|
+
return collections.map(collection => new Collection(collection, this.config));
|
|
120
95
|
});
|
|
121
96
|
}
|
|
122
97
|
/**
|
|
@@ -127,7 +102,7 @@ export class Bkper {
|
|
|
127
102
|
getApps() {
|
|
128
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
104
|
let apps = yield AppService.getApps(this.config);
|
|
130
|
-
return apps.map(
|
|
105
|
+
return apps.map(app => new App(app, this.config));
|
|
131
106
|
});
|
|
132
107
|
}
|
|
133
108
|
/**
|
|
@@ -151,7 +126,7 @@ export class Bkper {
|
|
|
151
126
|
getTemplates() {
|
|
152
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
128
|
let templates = yield TemplateService.getTemplates(this.config);
|
|
154
|
-
return templates.map(
|
|
129
|
+
return templates.map(template => new Template(template, this.config));
|
|
155
130
|
});
|
|
156
131
|
}
|
|
157
132
|
/**
|
package/lib/model/Book.js
CHANGED
|
@@ -542,6 +542,26 @@ export class Book extends ResourceProperty {
|
|
|
542
542
|
yield TransactionService.untrashTransactionsBatch(this.getId(), transactionPayloads, this.getConfig());
|
|
543
543
|
});
|
|
544
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Merge two [[Transactions]] into a single new canonical transaction.
|
|
547
|
+
*
|
|
548
|
+
* The merged transaction is created synchronously. Cleanup of the two
|
|
549
|
+
* originals is scheduled asynchronously by the backend.
|
|
550
|
+
*
|
|
551
|
+
* @param transaction1 - The first transaction to merge
|
|
552
|
+
* @param transaction2 - The second transaction to merge
|
|
553
|
+
*
|
|
554
|
+
* @returns The merged Transaction
|
|
555
|
+
*/
|
|
556
|
+
mergeTransactions(transaction1, transaction2) {
|
|
557
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
558
|
+
const payload = {
|
|
559
|
+
items: [transaction1.json(), transaction2.json()],
|
|
560
|
+
};
|
|
561
|
+
let operation = yield TransactionService.mergeTransactions(this.getId(), payload, this.getConfig());
|
|
562
|
+
return new Transaction(this, operation.transaction || {});
|
|
563
|
+
});
|
|
564
|
+
}
|
|
545
565
|
/**
|
|
546
566
|
* Replay [[Events]] on the Book, in batch.
|
|
547
567
|
*
|
|
@@ -103,7 +103,10 @@ export class HttpApiRequest extends HttpRequest {
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
shouldRetry(status) {
|
|
106
|
-
|
|
106
|
+
// 401/403 are included so consumers can refresh the OAuth token via
|
|
107
|
+
// requestRetryHandler and have the request re-issued. The retry cap
|
|
108
|
+
// (this.retry < 3) prevents loops on permanent auth failures.
|
|
109
|
+
return status == 401 || status == 403 || status == 408 || status == 429 || (status != null && status >= 500);
|
|
107
110
|
}
|
|
108
111
|
isNetworkError(error) {
|
|
109
112
|
return error instanceof TypeError && error.message.toLowerCase().includes("fetch");
|
|
@@ -126,6 +126,13 @@ export function listTransactions(bookId, query, limit, cursor, config) {
|
|
|
126
126
|
return response.data;
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
+
export function mergeTransactions(bookId, transactions, config) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const payload = Object.assign({}, transactions);
|
|
132
|
+
const response = yield new HttpBooksApiV5Request(`${bookId}/transactions/merge`, config).setMethod('PATCH').setPayload(payload).fetch();
|
|
133
|
+
return response.data;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
129
136
|
export function countTransactions(bookId, query, config) {
|
|
130
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
138
|
const request = new HttpBooksApiV5Request(`${bookId}/transactions/count`, config).setMethod('GET').addParam('query', query);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.1",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"upgrade:api": "bun update @bkper/bkper-api-types --latest"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@bkper/bkper-api-types": "^5.
|
|
38
|
+
"@bkper/bkper-api-types": "^5.40.0",
|
|
39
39
|
"big.js": "^6.0.3",
|
|
40
40
|
"dayjs": "^1.10.3",
|
|
41
41
|
"luxon": "^1.25.0",
|