bkper-js 1.27.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 +29 -2
- package/lib/model/Book.js +10 -0
- package/lib/model/BotResponse.js +63 -1
- 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
|
@@ -922,6 +922,10 @@ export declare class Book {
|
|
|
922
922
|
* Trash [[Transactions]] on the Book, in batch.
|
|
923
923
|
*/
|
|
924
924
|
batchTrashTransactions(transactions: Transaction[]): Promise<void>;
|
|
925
|
+
/**
|
|
926
|
+
* Replay [[Events]] on the Book, in batch.
|
|
927
|
+
*/
|
|
928
|
+
batchReplayEvents(events: Event[], errorOnly?: boolean): Promise<void>;
|
|
925
929
|
/**
|
|
926
930
|
* Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
|
|
927
931
|
*/
|
|
@@ -1061,7 +1065,8 @@ export declare class Book {
|
|
|
1061
1065
|
*/
|
|
1062
1066
|
export declare class BotResponse {
|
|
1063
1067
|
payload: bkper.BotResponse;
|
|
1064
|
-
|
|
1068
|
+
|
|
1069
|
+
constructor(event: Event, payload?: bkper.BotResponse);
|
|
1065
1070
|
/**
|
|
1066
1071
|
* @return The type of this Bot Response
|
|
1067
1072
|
*/
|
|
@@ -1078,6 +1083,19 @@ export declare class BotResponse {
|
|
|
1078
1083
|
* @returns The date this Bot Response was created
|
|
1079
1084
|
*/
|
|
1080
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
|
+
|
|
1081
1099
|
}
|
|
1082
1100
|
|
|
1083
1101
|
/**
|
|
@@ -1419,11 +1437,20 @@ export declare enum DecimalSeparator {
|
|
|
1419
1437
|
export declare class Event {
|
|
1420
1438
|
payload: bkper.Event;
|
|
1421
1439
|
|
|
1422
|
-
|
|
1440
|
+
|
|
1441
|
+
constructor(book: Book, payload?: bkper.Event);
|
|
1423
1442
|
/**
|
|
1424
1443
|
* @returns The wrapped plain json object
|
|
1425
1444
|
*/
|
|
1426
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;
|
|
1427
1454
|
/**
|
|
1428
1455
|
* @returns The user who performed the Event
|
|
1429
1456
|
*/
|
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/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",
|