bkper-js 1.27.0 → 1.29.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 +33 -2
- package/lib/model/Book.js +10 -0
- package/lib/model/BotResponse.js +69 -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,23 @@ export declare class BotResponse {
|
|
|
1078
1083
|
* @returns The date this Bot Response was created
|
|
1079
1084
|
*/
|
|
1080
1085
|
getCreatedAt(): Date | undefined;
|
|
1086
|
+
/**
|
|
1087
|
+
* @returns The Event this Bot Response is associated to
|
|
1088
|
+
*/
|
|
1089
|
+
getEvent(): Event;
|
|
1090
|
+
/**
|
|
1091
|
+
* Replay this Bot Response.
|
|
1092
|
+
*
|
|
1093
|
+
* @returns The updated Bot Response
|
|
1094
|
+
*/
|
|
1095
|
+
replay(): Promise<this>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Delete this Bot Response.
|
|
1098
|
+
*
|
|
1099
|
+
* @returns The deleted Bot Response
|
|
1100
|
+
*/
|
|
1101
|
+
remove(): Promise<this>;
|
|
1102
|
+
|
|
1081
1103
|
}
|
|
1082
1104
|
|
|
1083
1105
|
/**
|
|
@@ -1419,11 +1441,20 @@ export declare enum DecimalSeparator {
|
|
|
1419
1441
|
export declare class Event {
|
|
1420
1442
|
payload: bkper.Event;
|
|
1421
1443
|
|
|
1422
|
-
|
|
1444
|
+
|
|
1445
|
+
constructor(book: Book, payload?: bkper.Event);
|
|
1423
1446
|
/**
|
|
1424
1447
|
* @returns The wrapped plain json object
|
|
1425
1448
|
*/
|
|
1426
1449
|
json(): bkper.Event;
|
|
1450
|
+
/**
|
|
1451
|
+
* @returns The book in which the Event was created
|
|
1452
|
+
*/
|
|
1453
|
+
getBook(): Book;
|
|
1454
|
+
/**
|
|
1455
|
+
* @returns The id of the Event
|
|
1456
|
+
*/
|
|
1457
|
+
getId(): string | undefined;
|
|
1427
1458
|
/**
|
|
1428
1459
|
* @returns The user who performed the Event
|
|
1429
1460
|
*/
|
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,62 @@ 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
|
+
* @returns The Event this Bot Response is associated to
|
|
48
|
+
*/
|
|
49
|
+
getEvent() {
|
|
50
|
+
return this.event;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Replay this Bot Response.
|
|
54
|
+
*
|
|
55
|
+
* @returns The updated Bot Response
|
|
56
|
+
*/
|
|
57
|
+
replay() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const eventId = this.event.getId();
|
|
60
|
+
if (eventId == null) {
|
|
61
|
+
throw new Error("Event id null!");
|
|
62
|
+
}
|
|
63
|
+
const agentId = this.getAgentId();
|
|
64
|
+
if (agentId == null) {
|
|
65
|
+
throw new Error("Agent id null!");
|
|
66
|
+
}
|
|
67
|
+
const updatedEventPayload = yield EventService.replayBotResponse(this.event.getBook(), eventId, agentId);
|
|
68
|
+
this.event.payload = updatedEventPayload;
|
|
69
|
+
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
70
|
+
return this;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Delete this Bot Response.
|
|
75
|
+
*
|
|
76
|
+
* @returns The deleted Bot Response
|
|
77
|
+
*/
|
|
78
|
+
remove() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const eventId = this.event.getId();
|
|
81
|
+
if (eventId == null) {
|
|
82
|
+
throw new Error("Event id null!");
|
|
83
|
+
}
|
|
84
|
+
const agentId = this.getAgentId();
|
|
85
|
+
if (agentId == null) {
|
|
86
|
+
throw new Error("Agent id null!");
|
|
87
|
+
}
|
|
88
|
+
const updatedEventPayload = yield EventService.deleteBotResponse(this.event.getBook(), eventId, agentId);
|
|
89
|
+
this.event.payload = updatedEventPayload;
|
|
90
|
+
this.findAndUpdateBotResponsePayload(updatedEventPayload);
|
|
91
|
+
return this;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** @internal */
|
|
95
|
+
findAndUpdateBotResponsePayload(event) {
|
|
96
|
+
if (event && event.botResponses) {
|
|
97
|
+
const updatedPayload = event.botResponses.find(r => r.agentId && r.agentId === this.getAgentId());
|
|
98
|
+
if (updatedPayload) {
|
|
99
|
+
this.payload = updatedPayload;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
35
103
|
}
|
|
36
104
|
//# 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.29.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",
|