bkper-js 2.9.1 → 2.10.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 CHANGED
@@ -454,14 +454,6 @@ export declare class App extends Resource<bkper.App> {
454
454
  * @returns This App, for chaining
455
455
  */
456
456
  setWebhookUrlDev(webhookUrlDev: string): App;
457
- /**
458
- * Sets the conversation url for development.
459
- *
460
- * @param conversationUrlDev - The conversation URL for development
461
- *
462
- * @returns This App, for chaining
463
- */
464
- setConversationUrlDev(conversationUrlDev: string): App;
465
457
  /**
466
458
  * Gets the App universal identifier.
467
459
  *
@@ -498,12 +490,6 @@ export declare class App extends Resource<bkper.App> {
498
490
  * @returns True if this App is installable
499
491
  */
500
492
  isInstallable(): boolean;
501
- /**
502
- * Checks if this App is conversational.
503
- *
504
- * @returns True if this App is conversational
505
- */
506
- isConversational(): boolean;
507
493
  /**
508
494
  * Gets the logo url of this App.
509
495
  *
@@ -1271,12 +1257,6 @@ export declare class Bkper {
1271
1257
  * @returns The retrieved list of Apps
1272
1258
  */
1273
1259
  getApps(): Promise<App[]>;
1274
- /**
1275
- * Gets all [[Conversations]] available for the user.
1276
- *
1277
- * @returns The retrieved list of Conversations
1278
- */
1279
- getConversations(): Promise<Conversation[]>;
1280
1260
  /**
1281
1261
  * Gets all [[Templates]] available for the user.
1282
1262
  *
@@ -2304,65 +2284,6 @@ export declare class Connection extends Resource<bkper.Connection> {
2304
2284
  remove(): Promise<Connection>;
2305
2285
  }
2306
2286
 
2307
- /**
2308
- * Defines a Conversation on Bkper.
2309
- *
2310
- * A Conversation represents an interaction between [[Users]] and [[Apps]].
2311
- *
2312
- * @public
2313
- */
2314
- export declare class Conversation extends Resource<bkper.Conversation> {
2315
-
2316
-
2317
- private config?;
2318
- constructor(agent: Agent, payload?: bkper.Conversation, config?: Config);
2319
-
2320
- /**
2321
- * Gets the Agent associated to this Conversation.
2322
- *
2323
- * @returns The Agent associated to this Conversation
2324
- */
2325
- getAgent(): Agent;
2326
- /**
2327
- * Gets the Conversation universal identifier.
2328
- *
2329
- * @returns The Conversation universal identifier
2330
- */
2331
- getId(): string | undefined;
2332
- /**
2333
- * Gets the title of the Conversation.
2334
- *
2335
- * @returns The title of the Conversation
2336
- */
2337
- getTitle(): string | undefined;
2338
- /**
2339
- * Gets the Date the Conversation was created.
2340
- *
2341
- * @returns The Date the Conversation was created
2342
- */
2343
- getCreatedAt(): Date | undefined;
2344
- /**
2345
- * Gets the Date the Conversation was last updated.
2346
- *
2347
- * @returns The Date the Conversation was last updated
2348
- */
2349
- getUpdatedAt(): Date | undefined;
2350
- /**
2351
- * Gets the Messages that compose this Conversation.
2352
- *
2353
- * @returns The Messages in this Conversation
2354
- */
2355
- getMessages(): Promise<Message[]>;
2356
-
2357
-
2358
- /**
2359
- * Performs create Conversation.
2360
- *
2361
- * @returns The created Conversation object
2362
- */
2363
- create(): Promise<Conversation>;
2364
- }
2365
-
2366
2287
  /**
2367
2288
  * Decimal separator of numbers on book
2368
2289
  *
@@ -2446,6 +2367,7 @@ export declare class Event {
2446
2367
  * @returns True if this Event has at least one Bot Response of type ERROR
2447
2368
  */
2448
2369
  hasErrorResponse(): boolean;
2370
+
2449
2371
  }
2450
2372
 
2451
2373
  /**
@@ -3005,119 +2927,6 @@ export declare class Integration extends Resource<bkper.Integration> {
3005
2927
  remove(): Promise<Integration>;
3006
2928
  }
3007
2929
 
3008
- /**
3009
- * Defines a Message on Bkper.
3010
- *
3011
- * A Message is a building block of a [[Conversation]].
3012
- *
3013
- * @public
3014
- */
3015
- export declare class Message extends Resource<bkper.Message> {
3016
-
3017
-
3018
- constructor(conversation: Conversation, payload?: bkper.Message, config?: Config);
3019
-
3020
- /**
3021
- * Gets the Message universal identifier.
3022
- *
3023
- * @returns The Message universal identifier
3024
- */
3025
- getId(): string | undefined;
3026
- /**
3027
- * Gets the Agent associated with the Message.
3028
- *
3029
- * @returns The Agent associated with the Message, if any
3030
- */
3031
- getAgent(): Agent | undefined;
3032
- /**
3033
- * Gets the Conversation of the Message.
3034
- *
3035
- * @returns The Conversation of the Message
3036
- */
3037
- getConversation(): Conversation;
3038
- /**
3039
- * Gets the User associated with the Message.
3040
- *
3041
- * @returns The User associated with the Message
3042
- */
3043
- getUser(): User | undefined;
3044
- /**
3045
- * Gets the Date the Message was created.
3046
- *
3047
- * @returns The Date the Message was created
3048
- */
3049
- getCreatedAt(): Date | undefined;
3050
- /**
3051
- * Gets the text content of the Message.
3052
- *
3053
- * @returns The text content of the Message
3054
- */
3055
- getContent(): string | undefined;
3056
- /**
3057
- * Sets the text content of the Message.
3058
- *
3059
- * @param content - The text content of the Message
3060
- *
3061
- * @returns This Message, for chaining
3062
- */
3063
- setContent(content: string): Message;
3064
- /**
3065
- * Gets the custom properties stored in this Message.
3066
- *
3067
- * @returns The custom properties stored in this Message
3068
- */
3069
- getProperties(): {
3070
- [key: string]: string;
3071
- };
3072
- /**
3073
- * Sets the custom properties of the Message
3074
- *
3075
- * @param properties - Object with key/value pair properties
3076
- *
3077
- * @returns This Message, for chaining
3078
- */
3079
- setProperties(properties: {
3080
- [key: string]: string;
3081
- }): Message;
3082
- /**
3083
- * Gets the property value for given keys. First property found will be retrieved.
3084
- *
3085
- * @param keys - The property key
3086
- *
3087
- * @returns The retrieved property value
3088
- */
3089
- getProperty(...keys: string[]): string | undefined;
3090
- /**
3091
- * Sets a custom property in the Message.
3092
- *
3093
- * @param key - The property key
3094
- * @param value - The property value
3095
- *
3096
- * @returns This Message, for chaining
3097
- */
3098
- setProperty(key: string, value: string | null): Message;
3099
- /**
3100
- * Deletes a custom property from the Message.
3101
- *
3102
- * @param key - The property key
3103
- *
3104
- * @returns This Message, for chaining
3105
- */
3106
- deleteProperty(key: string): Message;
3107
- /**
3108
- * Creates the Message and receives the synchronous Agent response.
3109
- *
3110
- * @returns The Agent response Message, with the created Message as its parent
3111
- */
3112
- create(): Promise<Message>;
3113
- /**
3114
- * Streams the Message to the Bkper API.
3115
- *
3116
- * @returns A Promise that resolves when the streaming is complete
3117
- */
3118
- stream(): Promise<void>;
3119
- }
3120
-
3121
2930
  /**
3122
2931
  * Enum that represents a Month.
3123
2932
  *
package/lib/index.js CHANGED
@@ -5,30 +5,28 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export { Account } from './model/Account.js';
9
- export { Agent } from './model/Agent.js';
8
+ export { Account } from "./model/Account.js";
9
+ export { Agent } from "./model/Agent.js";
10
10
  export { Amount } from "./model/Amount.js";
11
- export { App } from './model/App.js';
12
- export { Balance } from './model/Balance.js';
13
- export { BalancesDataTableBuilder } from './model/BalancesDataTableBuilder.js';
14
- export { BalancesReport } from './model/BalancesReport.js';
15
- export { Bkper } from './model/Bkper.js';
16
- export { Book } from './model/Book.js';
17
- export { Collaborator } from './model/Collaborator.js';
18
- export { Collection } from './model/Collection.js';
19
- export { Connection } from './model/Connection.js';
20
- export { Conversation } from './model/Conversation.js';
21
- export { File } from './model/File.js';
22
- export { Group } from './model/Group.js';
23
- export { Integration } from './model/Integration.js';
24
- export { Message } from './model/Message.js';
25
- export { Query } from './model/Query.js';
26
- export { Template } from './model/Template.js';
27
- export { Transaction } from './model/Transaction.js';
28
- export { TransactionList } from './model/TransactionList.js';
29
- export { Event } from './model/Event.js';
30
- export { BotResponse } from './model/BotResponse.js';
31
- export { EventList } from './model/EventList.js';
32
- export { User } from './model/User.js';
33
- export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, BalanceType, Period, Month, EventType, BotResponseType } from './model/Enums.js';
11
+ export { App } from "./model/App.js";
12
+ export { Balance } from "./model/Balance.js";
13
+ export { BalancesDataTableBuilder } from "./model/BalancesDataTableBuilder.js";
14
+ export { BalancesReport } from "./model/BalancesReport.js";
15
+ export { Bkper } from "./model/Bkper.js";
16
+ export { Book } from "./model/Book.js";
17
+ export { Collaborator } from "./model/Collaborator.js";
18
+ export { Collection } from "./model/Collection.js";
19
+ export { Connection } from "./model/Connection.js";
20
+ export { File } from "./model/File.js";
21
+ export { Group } from "./model/Group.js";
22
+ export { Integration } from "./model/Integration.js";
23
+ export { Query } from "./model/Query.js";
24
+ export { Template } from "./model/Template.js";
25
+ export { Transaction } from "./model/Transaction.js";
26
+ export { TransactionList } from "./model/TransactionList.js";
27
+ export { Event } from "./model/Event.js";
28
+ export { BotResponse } from "./model/BotResponse.js";
29
+ export { EventList } from "./model/EventList.js";
30
+ export { User } from "./model/User.js";
31
+ export { Periodicity, DecimalSeparator, Permission, Visibility, AccountType, BalanceType, Period, Month, EventType, BotResponseType, } from "./model/Enums.js";
34
32
  //# sourceMappingURL=index.js.map
package/lib/model/App.js CHANGED
@@ -37,17 +37,6 @@ export class App extends Resource {
37
37
  this.payload.webhookUrlDev = webhookUrlDev;
38
38
  return this;
39
39
  }
40
- /**
41
- * Sets the conversation url for development.
42
- *
43
- * @param conversationUrlDev - The conversation URL for development
44
- *
45
- * @returns This App, for chaining
46
- */
47
- setConversationUrlDev(conversationUrlDev) {
48
- this.payload.conversationUrlDev = conversationUrlDev;
49
- return this;
50
- }
51
40
  /**
52
41
  * Gets the App universal identifier.
53
42
  *
@@ -97,14 +86,6 @@ export class App extends Resource {
97
86
  isInstallable() {
98
87
  return this.payload.installable || false;
99
88
  }
100
- /**
101
- * Checks if this App is conversational.
102
- *
103
- * @returns True if this App is conversational
104
- */
105
- isConversational() {
106
- return this.payload.conversational || false;
107
- }
108
89
  /**
109
90
  * Gets the logo url of this App.
110
91
  *
@@ -10,7 +10,6 @@ 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";
14
13
  import * as BookService from "../service/book-service.js";
15
14
  import * as CollectionService from "../service/collection-service.js";
16
15
  import * as UserService from "../service/user-service.js";
@@ -18,8 +17,6 @@ import * as TemplateService from "../service/template-service.js";
18
17
  import { User } from "./User.js";
19
18
  import { Template } from "./Template.js";
20
19
  import { Collection } from "./Collection.js";
21
- import { Conversation } from "./Conversation.js";
22
- import { Agent } from "./Agent.js";
23
20
  /**
24
21
  * This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.
25
22
  *
@@ -123,23 +120,6 @@ export class Bkper {
123
120
  return apps.map((app) => new App(app));
124
121
  });
125
122
  }
126
- /**
127
- * Gets all [[Conversations]] available for the user.
128
- *
129
- * @returns The retrieved list of Conversations
130
- */
131
- getConversations() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- const conversationPayloads = yield ConversationService.getConversations(this.config);
134
- let conversations = [];
135
- for (const payload of conversationPayloads) {
136
- const agent = new Agent(payload.agent);
137
- const conversation = new Conversation(agent, payload);
138
- conversations.push(conversation);
139
- }
140
- return conversations;
141
- });
142
- }
143
123
  /**
144
124
  * Gets all [[Templates]] available for the user.
145
125
  *
@@ -75,8 +75,7 @@ export class BotResponse {
75
75
  throw new Error("Agent id null!");
76
76
  }
77
77
  const updatedEventPayload = yield EventService.replayBotResponse(this.event.getBook(), eventId, agentId, this.event.getBook().getConfig());
78
- this.event.payload = updatedEventPayload;
79
- this.findAndUpdateBotResponsePayload(updatedEventPayload);
78
+ this.updateCache(updatedEventPayload);
80
79
  return this;
81
80
  });
82
81
  }
@@ -96,19 +95,19 @@ export class BotResponse {
96
95
  throw new Error("Agent id null!");
97
96
  }
98
97
  const updatedEventPayload = yield EventService.deleteBotResponse(this.event.getBook(), eventId, agentId, this.event.getBook().getConfig());
99
- this.event.payload = updatedEventPayload;
100
- this.findAndUpdateBotResponsePayload(updatedEventPayload);
98
+ this.updateCache(updatedEventPayload);
101
99
  return this;
102
100
  });
103
101
  }
104
102
  /** @internal */
105
- findAndUpdateBotResponsePayload(event) {
106
- if (event && event.botResponses) {
107
- const updatedPayload = event.botResponses.find(r => r.agentId && r.agentId === this.getAgentId());
108
- if (updatedPayload) {
109
- this.payload = updatedPayload;
110
- }
111
- }
103
+ updateCache(updatedEventPayload) {
104
+ var _a;
105
+ // Update event
106
+ this.event.payload = updatedEventPayload;
107
+ this.event.clearCache();
108
+ // Update bot response
109
+ const updatedBotResponsePayload = (_a = updatedEventPayload === null || updatedEventPayload === void 0 ? void 0 : updatedEventPayload.botResponses) === null || _a === void 0 ? void 0 : _a.find(r => r.agentId && r.agentId === this.getAgentId());
110
+ this.payload = updatedBotResponsePayload || {};
112
111
  }
113
112
  }
114
113
  //# sourceMappingURL=BotResponse.js.map
@@ -103,5 +103,9 @@ export class Event {
103
103
  }
104
104
  return false;
105
105
  }
106
+ /** @internal */
107
+ clearCache() {
108
+ this.botResponses = undefined;
109
+ }
106
110
  }
107
111
  //# sourceMappingURL=Event.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.9.1",
3
+ "version": "2.10.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.26.0"
37
+ "@bkper/bkper-api-types": "^5.28.0"
38
38
  },
39
39
  "dependencies": {
40
40
  "big.js": "^6.0.3",
@@ -1,134 +0,0 @@
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";
11
- import { Agent } from "./Agent.js";
12
- import { Message } from "./Message.js";
13
- import { Resource } from "./Resource.js";
14
- import { Bkper } from "./Bkper.js";
15
- /**
16
- * Defines a Conversation on Bkper.
17
- *
18
- * A Conversation represents an interaction between [[Users]] and [[Apps]].
19
- *
20
- * @public
21
- */
22
- export class Conversation extends Resource {
23
- constructor(agent, payload, config) {
24
- super(payload || {});
25
- this.agent = agent;
26
- this.config = config;
27
- }
28
- /** @internal */
29
- getConfig() {
30
- return this.config || Bkper.globalConfig;
31
- }
32
- /**
33
- * Gets the Agent associated to this Conversation.
34
- *
35
- * @returns The Agent associated to this Conversation
36
- */
37
- getAgent() {
38
- return this.agent;
39
- }
40
- /**
41
- * Gets the Conversation universal identifier.
42
- *
43
- * @returns The Conversation universal identifier
44
- */
45
- getId() {
46
- return this.payload.id;
47
- }
48
- /**
49
- * Gets the title of the Conversation.
50
- *
51
- * @returns The title of the Conversation
52
- */
53
- getTitle() {
54
- return this.payload.title;
55
- }
56
- /**
57
- * Gets the Date the Conversation was created.
58
- *
59
- * @returns The Date the Conversation was created
60
- */
61
- getCreatedAt() {
62
- return this.payload.createdAt
63
- ? new Date(new Number(this.payload.createdAt).valueOf())
64
- : undefined;
65
- }
66
- /**
67
- * Gets the Date the Conversation was last updated.
68
- *
69
- * @returns The Date the Conversation was last updated
70
- */
71
- getUpdatedAt() {
72
- return this.payload.updatedAt
73
- ? new Date(new Number(this.payload.updatedAt).valueOf())
74
- : undefined;
75
- }
76
- /**
77
- * Gets the Messages that compose this Conversation.
78
- *
79
- * @returns The Messages in this Conversation
80
- */
81
- getMessages() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- if (this.messagesMap != null) {
84
- return Array.from(this.messagesMap.values());
85
- }
86
- const conversationId = this.getId();
87
- if (!conversationId) {
88
- throw new Error("Conversation id null!");
89
- }
90
- if (!this.messagesMap) {
91
- this.messagesMap = new Map();
92
- }
93
- const messagePayloads = yield ConversationService.getMessages(conversationId, this.getConfig());
94
- for (const payload of messagePayloads) {
95
- this.updateMessagesCache(new Message(this, payload));
96
- }
97
- return Array.from(this.messagesMap.values());
98
- });
99
- }
100
- /** @internal */
101
- updateMessagesCache(message) {
102
- const messageId = message.getId();
103
- if (messageId) {
104
- if (!this.messagesMap) {
105
- this.messagesMap = new Map();
106
- }
107
- this.messagesMap.set(messageId, message);
108
- }
109
- }
110
- /** @internal */
111
- setUpdatedAt(updatedAtMs) {
112
- this.payload.updatedAt = updatedAtMs;
113
- }
114
- /**
115
- * Performs create Conversation.
116
- *
117
- * @returns The created Conversation object
118
- */
119
- create() {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const agentId = this.agent.getId();
122
- if (!agentId) {
123
- throw new Error("Agent id null!");
124
- }
125
- this.payload = yield ConversationService.createConversation(agentId, this.payload, this.getConfig());
126
- // Update agent
127
- if (this.payload.agent) {
128
- this.agent = new Agent(this.payload.agent);
129
- }
130
- return this;
131
- });
132
- }
133
- }
134
- //# sourceMappingURL=Conversation.js.map