bkper-js 1.26.0 → 1.28.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/index.d.ts +35 -26
- package/lib/index.js +1 -1
- package/lib/model/App.js +10 -5
- package/lib/model/Book.js +10 -0
- package/lib/model/BotResponse.js +63 -1
- package/lib/model/Enums.js +0 -22
- package/lib/model/Event.js +15 -2
- package/lib/model/EventList.js +1 -1
- package/lib/service/event-service.js +21 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -367,9 +367,13 @@ export declare class App {
|
|
|
367
367
|
*/
|
|
368
368
|
getName(): string | undefined;
|
|
369
369
|
/**
|
|
370
|
-
* @return
|
|
370
|
+
* @return True if this App has events bound to it
|
|
371
371
|
*/
|
|
372
|
-
|
|
372
|
+
hasEvents(): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* @return The events bound to this App
|
|
375
|
+
*/
|
|
376
|
+
getEvents(): EventType[] | undefined;
|
|
373
377
|
/**
|
|
374
378
|
* @return The logo url of this App
|
|
375
379
|
*/
|
|
@@ -418,28 +422,6 @@ export declare class App {
|
|
|
418
422
|
update(): Promise<App>;
|
|
419
423
|
}
|
|
420
424
|
|
|
421
|
-
/**
|
|
422
|
-
* Enum that represents the type of an App.
|
|
423
|
-
*
|
|
424
|
-
* @public
|
|
425
|
-
*/
|
|
426
|
-
export declare enum AppType {
|
|
427
|
-
/**
|
|
428
|
-
* Interactive solutions that can run independently and integrate with third-party services.
|
|
429
|
-
* Apps can range from simple URL openers to complex add-ons with business logic.
|
|
430
|
-
*
|
|
431
|
-
* Learn more on [Bkper Apps](https://bkper.com/docs/#apps).
|
|
432
|
-
*/
|
|
433
|
-
APP = "APP",
|
|
434
|
-
/**
|
|
435
|
-
* Specialized type of App that react to events from Books.
|
|
436
|
-
* Bots can perform automated tasks like calculating taxes, converting currencies, or posting notifications when specific events occur.
|
|
437
|
-
*
|
|
438
|
-
* Learn more on [Bkper Bots](https://bkper.com/docs/#bots).
|
|
439
|
-
*/
|
|
440
|
-
BOT = "BOT"
|
|
441
|
-
}
|
|
442
|
-
|
|
443
425
|
/**
|
|
444
426
|
* The container of balances of an [[Account]] or [[Group]]
|
|
445
427
|
*
|
|
@@ -940,6 +922,10 @@ export declare class Book {
|
|
|
940
922
|
* Trash [[Transactions]] on the Book, in batch.
|
|
941
923
|
*/
|
|
942
924
|
batchTrashTransactions(transactions: Transaction[]): Promise<void>;
|
|
925
|
+
/**
|
|
926
|
+
* Replay [[Events]] on the Book, in batch.
|
|
927
|
+
*/
|
|
928
|
+
batchReplayEvents(events: Event[], errorOnly?: boolean): Promise<void>;
|
|
943
929
|
/**
|
|
944
930
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
945
931
|
*/
|
|
@@ -1079,7 +1065,8 @@ export declare class Book {
|
|
|
1079
1065
|
*/
|
|
1080
1066
|
export declare class BotResponse {
|
|
1081
1067
|
payload: bkper.BotResponse;
|
|
1082
|
-
|
|
1068
|
+
|
|
1069
|
+
constructor(event: Event, payload?: bkper.BotResponse);
|
|
1083
1070
|
/**
|
|
1084
1071
|
* @return The type of this Bot Response
|
|
1085
1072
|
*/
|
|
@@ -1096,6 +1083,19 @@ export declare class BotResponse {
|
|
|
1096
1083
|
* @returns The date this Bot Response was created
|
|
1097
1084
|
*/
|
|
1098
1085
|
getCreatedAt(): Date | undefined;
|
|
1086
|
+
/**
|
|
1087
|
+
* Replay this Bot Response.
|
|
1088
|
+
*
|
|
1089
|
+
* @returns The updated Bot Response
|
|
1090
|
+
*/
|
|
1091
|
+
replay(): Promise<this>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Delete this Bot Response.
|
|
1094
|
+
*
|
|
1095
|
+
* @returns The deleted Bot Response
|
|
1096
|
+
*/
|
|
1097
|
+
remove(): Promise<this>;
|
|
1098
|
+
|
|
1099
1099
|
}
|
|
1100
1100
|
|
|
1101
1101
|
/**
|
|
@@ -1437,11 +1437,20 @@ export declare enum DecimalSeparator {
|
|
|
1437
1437
|
export declare class Event {
|
|
1438
1438
|
payload: bkper.Event;
|
|
1439
1439
|
|
|
1440
|
-
|
|
1440
|
+
|
|
1441
|
+
constructor(book: Book, payload?: bkper.Event);
|
|
1441
1442
|
/**
|
|
1442
1443
|
* @returns The wrapped plain json object
|
|
1443
1444
|
*/
|
|
1444
1445
|
json(): bkper.Event;
|
|
1446
|
+
/**
|
|
1447
|
+
* @returns The book in which the Event was created
|
|
1448
|
+
*/
|
|
1449
|
+
getBook(): Book;
|
|
1450
|
+
/**
|
|
1451
|
+
* @returns The id of the Event
|
|
1452
|
+
*/
|
|
1453
|
+
getId(): string | undefined;
|
|
1445
1454
|
/**
|
|
1446
1455
|
* @returns The user who performed the Event
|
|
1447
1456
|
*/
|
package/lib/index.js
CHANGED
|
@@ -24,5 +24,5 @@ export { Event } from './model/Event.js';
|
|
|
24
24
|
export { BotResponse } from './model/BotResponse.js';
|
|
25
25
|
export { EventList } from './model/EventList.js';
|
|
26
26
|
export { User } from './model/User.js';
|
|
27
|
-
export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, Period, Month, EventType,
|
|
27
|
+
export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, Period, Month, EventType, BotResponseType } from './model/Enums.js';
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
package/lib/model/App.js
CHANGED
|
@@ -8,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { createApp, patchApp, updateApp } from "../service/app-service.js";
|
|
11
|
-
import { AppType } from "./Enums.js";
|
|
12
11
|
/**
|
|
13
12
|
* Defines an App on Bkper.
|
|
14
13
|
*
|
|
@@ -55,11 +54,17 @@ export class App {
|
|
|
55
54
|
return this.payload.name;
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
58
|
-
* @return
|
|
57
|
+
* @return True if this App has events bound to it
|
|
59
58
|
*/
|
|
60
|
-
|
|
61
|
-
const events = this.
|
|
62
|
-
return events
|
|
59
|
+
hasEvents() {
|
|
60
|
+
const events = this.getEvents() || [];
|
|
61
|
+
return events.length > 0;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @return The events bound to this App
|
|
65
|
+
*/
|
|
66
|
+
getEvents() {
|
|
67
|
+
return this.payload.events;
|
|
63
68
|
}
|
|
64
69
|
/**
|
|
65
70
|
* @return The logo url of this App
|
package/lib/model/Book.js
CHANGED
|
@@ -425,6 +425,16 @@ export class Book {
|
|
|
425
425
|
yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads);
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Replay [[Events]] on the Book, in batch.
|
|
430
|
+
*/
|
|
431
|
+
batchReplayEvents(events, errorOnly) {
|
|
432
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
433
|
+
const eventPayloads = events.map(event => event.json());
|
|
434
|
+
const eventList = { items: eventPayloads };
|
|
435
|
+
yield EventService.replayEventsBatch(this, eventList, errorOnly);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
428
438
|
/**
|
|
429
439
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
430
440
|
*/
|
package/lib/model/BotResponse.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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 EventService from '../service/event-service.js';
|
|
1
11
|
/**
|
|
2
12
|
*
|
|
3
13
|
* This class defines a Bot Response associated to an [[Event]].
|
|
@@ -5,7 +15,8 @@
|
|
|
5
15
|
* @public
|
|
6
16
|
*/
|
|
7
17
|
export class BotResponse {
|
|
8
|
-
constructor(payload) {
|
|
18
|
+
constructor(event, payload) {
|
|
19
|
+
this.event = event;
|
|
9
20
|
this.payload = payload || {};
|
|
10
21
|
}
|
|
11
22
|
/**
|
|
@@ -32,5 +43,56 @@ export class BotResponse {
|
|
|
32
43
|
getCreatedAt() {
|
|
33
44
|
return this.payload.createdAt ? new Date(new Number(this.payload.createdAt).valueOf()) : undefined;
|
|
34
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Replay this Bot Response.
|
|
48
|
+
*
|
|
49
|
+
* @returns The updated Bot Response
|
|
50
|
+
*/
|
|
51
|
+
replay() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const eventId = this.event.getId();
|
|
54
|
+
if (eventId == null) {
|
|
55
|
+
throw new Error("Event id null!");
|
|
56
|
+
}
|
|
57
|
+
const agentId = this.getAgentId();
|
|
58
|
+
if (agentId == null) {
|
|
59
|
+
throw new Error("Agent id null!");
|
|
60
|
+
}
|
|
61
|
+
const updatedEventPayload = yield EventService.replayBotResponse(this.event.getBook(), eventId, agentId);
|
|
62
|
+
this.event.payload = updatedEventPayload;
|
|
63
|
+
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
64
|
+
return this;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Delete this Bot Response.
|
|
69
|
+
*
|
|
70
|
+
* @returns The deleted Bot Response
|
|
71
|
+
*/
|
|
72
|
+
remove() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const eventId = this.event.getId();
|
|
75
|
+
if (eventId == null) {
|
|
76
|
+
throw new Error("Event id null!");
|
|
77
|
+
}
|
|
78
|
+
const agentId = this.getAgentId();
|
|
79
|
+
if (agentId == null) {
|
|
80
|
+
throw new Error("Agent id null!");
|
|
81
|
+
}
|
|
82
|
+
const updatedEventPayload = yield EventService.deleteBotResponse(this.event.getBook(), eventId, agentId);
|
|
83
|
+
this.event.payload = updatedEventPayload;
|
|
84
|
+
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
85
|
+
return this;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** @internal */
|
|
89
|
+
findAndUpdateBotResponsePayload(event) {
|
|
90
|
+
if (event && event.botResponses) {
|
|
91
|
+
const updatedPayload = event.botResponses.find(r => r.agentId && r.agentId === this.getAgentId());
|
|
92
|
+
if (updatedPayload) {
|
|
93
|
+
this.payload = updatedPayload;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
35
97
|
}
|
|
36
98
|
//# sourceMappingURL=BotResponse.js.map
|
package/lib/model/Enums.js
CHANGED
|
@@ -148,28 +148,6 @@ export var Month;
|
|
|
148
148
|
Month["NOVEMBER"] = "NOVEMBER";
|
|
149
149
|
Month["DECEMBER"] = "DECEMBER";
|
|
150
150
|
})(Month || (Month = {}));
|
|
151
|
-
/**
|
|
152
|
-
* Enum that represents the type of an App.
|
|
153
|
-
*
|
|
154
|
-
* @public
|
|
155
|
-
*/
|
|
156
|
-
export var AppType;
|
|
157
|
-
(function (AppType) {
|
|
158
|
-
/**
|
|
159
|
-
* Interactive solutions that can run independently and integrate with third-party services.
|
|
160
|
-
* Apps can range from simple URL openers to complex add-ons with business logic.
|
|
161
|
-
*
|
|
162
|
-
* Learn more on [Bkper Apps](https://bkper.com/docs/#apps).
|
|
163
|
-
*/
|
|
164
|
-
AppType["APP"] = "APP";
|
|
165
|
-
/**
|
|
166
|
-
* Specialized type of App that react to events from Books.
|
|
167
|
-
* Bots can perform automated tasks like calculating taxes, converting currencies, or posting notifications when specific events occur.
|
|
168
|
-
*
|
|
169
|
-
* Learn more on [Bkper Bots](https://bkper.com/docs/#bots).
|
|
170
|
-
*/
|
|
171
|
-
AppType["BOT"] = "BOT";
|
|
172
|
-
})(AppType || (AppType = {}));
|
|
173
151
|
/**
|
|
174
152
|
* Enum that represents the type of a Bot Response
|
|
175
153
|
*
|
package/lib/model/Event.js
CHANGED
|
@@ -11,7 +11,8 @@ import { User } from "./User.js";
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export class Event {
|
|
14
|
-
constructor(payload) {
|
|
14
|
+
constructor(book, payload) {
|
|
15
|
+
this.book = book;
|
|
15
16
|
this.payload = payload || {};
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
@@ -20,6 +21,18 @@ export class Event {
|
|
|
20
21
|
json() {
|
|
21
22
|
return Object.assign({}, this.payload);
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @returns The book in which the Event was created
|
|
26
|
+
*/
|
|
27
|
+
getBook() {
|
|
28
|
+
return this.book;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @returns The id of the Event
|
|
32
|
+
*/
|
|
33
|
+
getId() {
|
|
34
|
+
return this.payload.id;
|
|
35
|
+
}
|
|
23
36
|
/**
|
|
24
37
|
* @returns The user who performed the Event
|
|
25
38
|
*/
|
|
@@ -54,7 +67,7 @@ export class Event {
|
|
|
54
67
|
let botResponses = [];
|
|
55
68
|
if (this.payload.botResponses) {
|
|
56
69
|
for (const botResponse of this.payload.botResponses) {
|
|
57
|
-
botResponses.push(new BotResponse(botResponse));
|
|
70
|
+
botResponses.push(new BotResponse(this, botResponse));
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
this.botResponses = botResponses;
|
package/lib/model/EventList.js
CHANGED
|
@@ -37,7 +37,7 @@ export class EventList {
|
|
|
37
37
|
*/
|
|
38
38
|
getItems() {
|
|
39
39
|
var _a;
|
|
40
|
-
return ((_a = this.payload.items) === null || _a === void 0 ? void 0 : _a.map(event => new Event(event))) || [];
|
|
40
|
+
return ((_a = this.payload.items) === null || _a === void 0 ? void 0 : _a.map(event => new Event(this.book, event))) || [];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=EventList.js.map
|
|
@@ -23,4 +23,25 @@ export function listEvents(book, afterDate, beforeDate, onError, resourceId, lim
|
|
|
23
23
|
return response.data;
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
export function replayBotResponse(book, eventId, agentId) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`).setMethod('PUT').fetch();
|
|
29
|
+
return response.data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function deleteBotResponse(book, eventId, agentId) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const response = yield new HttpBooksApiV5Request(`${book.getId()}/events/${eventId}/responses/${agentId}`).setMethod('DELETE').fetch();
|
|
35
|
+
return response.data;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function replayEventsBatch(book, eventList, errorsOnly) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let request = new HttpBooksApiV5Request(`${book.getId()}/events/replay/batch`).setMethod('PATCH').setPayload(eventList);
|
|
41
|
+
if (errorsOnly) {
|
|
42
|
+
request.addParam('errorsOnly', errorsOnly);
|
|
43
|
+
}
|
|
44
|
+
yield request.fetch();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
26
47
|
//# sourceMappingURL=event-service.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Javascript client for Bkper REST API",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
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.14.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@google-cloud/local-auth": "^3.0.1",
|