bkper-js 1.33.0 → 1.34.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 +14 -11
- package/lib/model/Bkper.js +2 -1
- package/lib/model/Conversation.js +31 -36
- package/lib/model/Message.js +32 -2
- package/lib/service/app-service.js +0 -7
- package/lib/service/conversation-service.js +15 -2
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1477,22 +1477,18 @@ export declare class Conversation {
|
|
|
1477
1477
|
*/
|
|
1478
1478
|
getUpdatedAt(): Date | undefined;
|
|
1479
1479
|
/**
|
|
1480
|
+
* Gets the Messages that compose this Conversation
|
|
1480
1481
|
*
|
|
1481
1482
|
* @returns The Messages in this Conversation
|
|
1482
1483
|
*/
|
|
1483
1484
|
getMessages(): Promise<Message[]>;
|
|
1485
|
+
|
|
1484
1486
|
/**
|
|
1487
|
+
* Performs create Conversation
|
|
1485
1488
|
*
|
|
1486
|
-
* @
|
|
1487
|
-
*
|
|
1488
|
-
* @returns This Conversation, for chaining
|
|
1489
|
-
*/
|
|
1490
|
-
addMessage(message: Message): Conversation;
|
|
1491
|
-
/**
|
|
1492
|
-
*
|
|
1493
|
-
* @return The updated Conversation object
|
|
1489
|
+
* @returns The created Conversation object
|
|
1494
1490
|
*/
|
|
1495
|
-
|
|
1491
|
+
create(): Promise<Conversation>;
|
|
1496
1492
|
}
|
|
1497
1493
|
|
|
1498
1494
|
/**
|
|
@@ -2011,6 +2007,7 @@ export declare class Integration {
|
|
|
2011
2007
|
export declare class Message {
|
|
2012
2008
|
payload: bkper.Message;
|
|
2013
2009
|
|
|
2010
|
+
|
|
2014
2011
|
constructor(conversation: Conversation, payload?: bkper.Message);
|
|
2015
2012
|
/**
|
|
2016
2013
|
* @returns The wrapped plain json object
|
|
@@ -2023,12 +2020,12 @@ export declare class Message {
|
|
|
2023
2020
|
getId(): string | undefined;
|
|
2024
2021
|
/**
|
|
2025
2022
|
*
|
|
2026
|
-
* @returns The Agent
|
|
2023
|
+
* @returns The Agent associated with the Message, in any
|
|
2027
2024
|
*/
|
|
2028
2025
|
getAgent(): Agent | undefined;
|
|
2029
2026
|
/**
|
|
2030
2027
|
*
|
|
2031
|
-
* @returns The User
|
|
2028
|
+
* @returns The User associated with the Message
|
|
2032
2029
|
*/
|
|
2033
2030
|
getUser(): User | undefined;
|
|
2034
2031
|
/**
|
|
@@ -2089,6 +2086,12 @@ export declare class Message {
|
|
|
2089
2086
|
* @returns This Message, for chainning.
|
|
2090
2087
|
*/
|
|
2091
2088
|
deleteProperty(key: string): Message;
|
|
2089
|
+
/**
|
|
2090
|
+
* Performs create Message
|
|
2091
|
+
*
|
|
2092
|
+
* @returns The created Message object
|
|
2093
|
+
*/
|
|
2094
|
+
create(): Promise<Message>;
|
|
2092
2095
|
}
|
|
2093
2096
|
|
|
2094
2097
|
/**
|
package/lib/model/Bkper.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { Book } from "./Book.js";
|
|
11
11
|
import { App } from "./App.js";
|
|
12
12
|
import * as AppService from '../service/app-service.js';
|
|
13
|
+
import * as ConversationService from '../service/conversation-service.js';
|
|
13
14
|
import * as BookService from '../service/book-service.js';
|
|
14
15
|
import * as CollectionService from '../service/collection-service.js';
|
|
15
16
|
import * as UserService from '../service/user-service.js';
|
|
@@ -93,7 +94,7 @@ export class Bkper {
|
|
|
93
94
|
*/
|
|
94
95
|
static getConversations() {
|
|
95
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const conversationPayloads = yield
|
|
97
|
+
const conversationPayloads = yield ConversationService.getConversations();
|
|
97
98
|
let conversations = [];
|
|
98
99
|
for (const payload of conversationPayloads) {
|
|
99
100
|
const agent = new Agent(payload.agent);
|
|
@@ -64,59 +64,54 @@ export class Conversation {
|
|
|
64
64
|
return this.payload.updatedAt ? new Date(this.payload.updatedAt) : undefined;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
+
* Gets the Messages that compose this Conversation
|
|
67
68
|
*
|
|
68
69
|
* @returns The Messages in this Conversation
|
|
69
70
|
*/
|
|
70
71
|
getMessages() {
|
|
71
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
if (this.
|
|
73
|
-
return this.
|
|
73
|
+
if (this.messagesMap != null) {
|
|
74
|
+
return Array.from(this.messagesMap.values());
|
|
74
75
|
}
|
|
75
76
|
const conversationId = this.getId();
|
|
76
|
-
if (conversationId) {
|
|
77
|
-
|
|
78
|
-
this.payload.messages = messagePayloads;
|
|
79
|
-
this.messages = messagePayloads.map(message => new Message(this, message));
|
|
77
|
+
if (!conversationId) {
|
|
78
|
+
throw new Error('Conversation id null!');
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
if (!this.messagesMap) {
|
|
81
|
+
this.messagesMap = new Map();
|
|
82
|
+
}
|
|
83
|
+
const messagePayloads = yield ConversationService.getMessages(conversationId);
|
|
84
|
+
for (const payload of messagePayloads) {
|
|
85
|
+
this.updateMessagesCache(new Message(this, payload));
|
|
86
|
+
}
|
|
87
|
+
return Array.from(this.messagesMap.values());
|
|
82
88
|
});
|
|
83
89
|
}
|
|
84
|
-
/**
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.messages = [];
|
|
90
|
+
/** @internal */
|
|
91
|
+
updateMessagesCache(message) {
|
|
92
|
+
const messageId = message.getId();
|
|
93
|
+
if (messageId) {
|
|
94
|
+
if (!this.messagesMap) {
|
|
95
|
+
this.messagesMap = new Map();
|
|
96
|
+
}
|
|
97
|
+
this.messagesMap.set(messageId, message);
|
|
93
98
|
}
|
|
94
|
-
this.messages.push(message);
|
|
95
|
-
this.payload.messages = this.messages.map(message => message.json());
|
|
96
|
-
return this;
|
|
97
99
|
}
|
|
98
100
|
/**
|
|
101
|
+
* Performs create Conversation
|
|
99
102
|
*
|
|
100
|
-
* @
|
|
103
|
+
* @returns The created Conversation object
|
|
101
104
|
*/
|
|
102
|
-
|
|
105
|
+
create() {
|
|
103
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
107
|
const agentId = this.agent.getId();
|
|
105
|
-
if (agentId) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!this.messages) {
|
|
113
|
-
this.messages = [];
|
|
114
|
-
}
|
|
115
|
-
for (const messagePayload of updatedPayload.messages) {
|
|
116
|
-
this.messages.push(new Message(this, messagePayload));
|
|
117
|
-
}
|
|
118
|
-
this.payload.messages = this.messages.map(message => message.json());
|
|
119
|
-
}
|
|
108
|
+
if (!agentId) {
|
|
109
|
+
throw new Error('Agent id null!');
|
|
110
|
+
}
|
|
111
|
+
this.payload = yield ConversationService.createConversation(agentId, this.payload);
|
|
112
|
+
// Update agent
|
|
113
|
+
if (this.payload.agent) {
|
|
114
|
+
this.agent = new Agent(this.payload.agent);
|
|
120
115
|
}
|
|
121
116
|
return this;
|
|
122
117
|
});
|
package/lib/model/Message.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 ConversationService from "../service/conversation-service.js";
|
|
1
11
|
import { Agent } from "./Agent.js";
|
|
2
12
|
import { User } from "./User.js";
|
|
3
13
|
/**
|
|
@@ -27,14 +37,14 @@ export class Message {
|
|
|
27
37
|
}
|
|
28
38
|
/**
|
|
29
39
|
*
|
|
30
|
-
* @returns The Agent
|
|
40
|
+
* @returns The Agent associated with the Message, in any
|
|
31
41
|
*/
|
|
32
42
|
getAgent() {
|
|
33
43
|
return this.payload.agent ? new Agent(this.payload.agent) : undefined;
|
|
34
44
|
}
|
|
35
45
|
/**
|
|
36
46
|
*
|
|
37
|
-
* @returns The User
|
|
47
|
+
* @returns The User associated with the Message
|
|
38
48
|
*/
|
|
39
49
|
getUser() {
|
|
40
50
|
return this.payload.user ? new User(this.payload.user) : undefined;
|
|
@@ -129,5 +139,25 @@ export class Message {
|
|
|
129
139
|
this.setProperty(key, null);
|
|
130
140
|
return this;
|
|
131
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Performs create Message
|
|
144
|
+
*
|
|
145
|
+
* @returns The created Message object
|
|
146
|
+
*/
|
|
147
|
+
create() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const conversationId = this.conversation.getId();
|
|
150
|
+
if (!conversationId) {
|
|
151
|
+
throw new Error('Conversation id null!');
|
|
152
|
+
}
|
|
153
|
+
this.payload = yield ConversationService.createMessage(conversationId, this.payload);
|
|
154
|
+
this.conversation.updateMessagesCache(this);
|
|
155
|
+
if (this.payload.parent) {
|
|
156
|
+
this.parent = new Message(this.conversation, this.payload.parent);
|
|
157
|
+
this.conversation.updateMessagesCache(this.parent);
|
|
158
|
+
}
|
|
159
|
+
return this;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
132
162
|
}
|
|
133
163
|
//# sourceMappingURL=Message.js.map
|
|
@@ -22,13 +22,6 @@ export function getApps() {
|
|
|
22
22
|
return appsJson;
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
export function getConversations() {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
var _a;
|
|
28
|
-
const response = yield new HttpApiRequest(`v5/apps/conversations`).setMethod('GET').fetch();
|
|
29
|
-
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
25
|
export function createApp(app) {
|
|
33
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
27
|
var response = yield new HttpApiRequest(`v5/apps`).setMethod('POST').setPayload(app).fetch();
|
|
@@ -8,6 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { HttpApiRequest } from "./http-api-request.js";
|
|
11
|
+
export function getConversations() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a;
|
|
14
|
+
const response = yield new HttpApiRequest(`v5/apps/conversations`).setMethod('GET').fetch();
|
|
15
|
+
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function createConversation(agentId, conversation) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const response = yield new HttpApiRequest(`v5/apps/${agentId}/conversations`).setMethod('POST').setPayload(conversation).fetch();
|
|
21
|
+
return response.data;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
11
24
|
export function getMessages(conversationId) {
|
|
12
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
26
|
var _a;
|
|
@@ -15,9 +28,9 @@ export function getMessages(conversationId) {
|
|
|
15
28
|
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
16
29
|
});
|
|
17
30
|
}
|
|
18
|
-
export function
|
|
31
|
+
export function createMessage(conversationId, message) {
|
|
19
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const response = yield new HttpApiRequest(`v5/apps/${
|
|
33
|
+
const response = yield new HttpApiRequest(`v5/apps/conversations/${conversationId}/messages`).setMethod('POST').setPayload(message).fetch();
|
|
21
34
|
return response.data;
|
|
22
35
|
});
|
|
23
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bkper-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.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.17.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@google-cloud/local-auth": "^3.0.1",
|