@unblu/embedded-app-component 7.37.2

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.
Files changed (126) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +21 -0
  3. package/dist/lib/index.d.ts +36 -0
  4. package/dist/lib/index.js +27 -0
  5. package/dist/lib/index.js.map +1 -0
  6. package/dist/lib/internal/internal-embedded-api.d.ts +16 -0
  7. package/dist/lib/internal/internal-embedded-api.js +18 -0
  8. package/dist/lib/internal/internal-embedded-api.js.map +1 -0
  9. package/dist/lib/internal/module/embedded-meta-module.d.ts +16 -0
  10. package/dist/lib/internal/module/embedded-meta-module.js +16 -0
  11. package/dist/lib/internal/module/embedded-meta-module.js.map +1 -0
  12. package/dist/lib/internal/module/general-module.d.ts +16 -0
  13. package/dist/lib/internal/module/general-module.js +16 -0
  14. package/dist/lib/internal/module/general-module.js.map +1 -0
  15. package/dist/lib/shared/api-state.d.ts +8 -0
  16. package/dist/lib/shared/api-state.js +10 -0
  17. package/dist/lib/shared/api-state.js.map +1 -0
  18. package/dist/lib/shared/conversation.d.ts +320 -0
  19. package/dist/lib/shared/conversation.js +384 -0
  20. package/dist/lib/shared/conversation.js.map +1 -0
  21. package/dist/lib/shared/internal/api-bridge.d.ts +36 -0
  22. package/dist/lib/shared/internal/api-bridge.js +97 -0
  23. package/dist/lib/shared/internal/api-bridge.js.map +1 -0
  24. package/dist/lib/shared/internal/event.d.ts +6 -0
  25. package/dist/lib/shared/internal/event.js +2 -0
  26. package/dist/lib/shared/internal/event.js.map +1 -0
  27. package/dist/lib/shared/internal/initialized-unblu-api.d.ts +6 -0
  28. package/dist/lib/shared/internal/initialized-unblu-api.js +2 -0
  29. package/dist/lib/shared/internal/initialized-unblu-api.js.map +1 -0
  30. package/dist/lib/shared/internal/initialized-unblu-element.d.ts +6 -0
  31. package/dist/lib/shared/internal/initialized-unblu-element.js +2 -0
  32. package/dist/lib/shared/internal/initialized-unblu-element.js.map +1 -0
  33. package/dist/lib/shared/internal/java-error-codes.d.ts +5 -0
  34. package/dist/lib/shared/internal/java-error-codes.js +6 -0
  35. package/dist/lib/shared/internal/java-error-codes.js.map +1 -0
  36. package/dist/lib/shared/internal/module/agent-availability-module.d.ts +14 -0
  37. package/dist/lib/shared/internal/module/agent-availability-module.js +13 -0
  38. package/dist/lib/shared/internal/module/agent-availability-module.js.map +1 -0
  39. package/dist/lib/shared/internal/module/base-general-module.d.ts +31 -0
  40. package/dist/lib/shared/internal/module/base-general-module.js +46 -0
  41. package/dist/lib/shared/internal/module/base-general-module.js.map +1 -0
  42. package/dist/lib/shared/internal/module/conversation-module.d.ts +57 -0
  43. package/dist/lib/shared/internal/module/conversation-module.js +49 -0
  44. package/dist/lib/shared/internal/module/conversation-module.js.map +1 -0
  45. package/dist/lib/shared/internal/module/module.d.ts +10 -0
  46. package/dist/lib/shared/internal/module/module.js +16 -0
  47. package/dist/lib/shared/internal/module/module.js.map +1 -0
  48. package/dist/lib/shared/internal/unblu-api-factory.d.ts +9 -0
  49. package/dist/lib/shared/internal/unblu-api-factory.js +2 -0
  50. package/dist/lib/shared/internal/unblu-api-factory.js.map +1 -0
  51. package/dist/lib/shared/internal/unblu-util.d.ts +63 -0
  52. package/dist/lib/shared/internal/unblu-util.js +220 -0
  53. package/dist/lib/shared/internal/unblu-util.js.map +1 -0
  54. package/dist/lib/shared/internal/util/event-emitter.d.ts +44 -0
  55. package/dist/lib/shared/internal/util/event-emitter.js +85 -0
  56. package/dist/lib/shared/internal/util/event-emitter.js.map +1 -0
  57. package/dist/lib/shared/model/agent-availability-state.d.ts +18 -0
  58. package/dist/lib/shared/model/agent-availability-state.js +20 -0
  59. package/dist/lib/shared/model/agent-availability-state.js.map +1 -0
  60. package/dist/lib/shared/model/call-state.d.ts +26 -0
  61. package/dist/lib/shared/model/call-state.js +28 -0
  62. package/dist/lib/shared/model/call-state.js.map +1 -0
  63. package/dist/lib/shared/model/configuration.d.ts +46 -0
  64. package/dist/lib/shared/model/configuration.js +2 -0
  65. package/dist/lib/shared/model/configuration.js.map +1 -0
  66. package/dist/lib/shared/model/connection-state.d.ts +27 -0
  67. package/dist/lib/shared/model/connection-state.js +29 -0
  68. package/dist/lib/shared/model/connection-state.js.map +1 -0
  69. package/dist/lib/shared/model/conversation-info.d.ts +34 -0
  70. package/dist/lib/shared/model/conversation-info.js +2 -0
  71. package/dist/lib/shared/model/conversation-info.js.map +1 -0
  72. package/dist/lib/shared/model/conversation-message-info.d.ts +14 -0
  73. package/dist/lib/shared/model/conversation-message-info.js +2 -0
  74. package/dist/lib/shared/model/conversation-message-info.js.map +1 -0
  75. package/dist/lib/shared/model/conversation-recipient-type.d.ts +10 -0
  76. package/dist/lib/shared/model/conversation-recipient-type.js +12 -0
  77. package/dist/lib/shared/model/conversation-recipient-type.js.map +1 -0
  78. package/dist/lib/shared/model/conversation-recipient.d.ts +14 -0
  79. package/dist/lib/shared/model/conversation-recipient.js +2 -0
  80. package/dist/lib/shared/model/conversation-recipient.js.map +1 -0
  81. package/dist/lib/shared/model/conversation-state.d.ts +37 -0
  82. package/dist/lib/shared/model/conversation-state.js +39 -0
  83. package/dist/lib/shared/model/conversation-state.js.map +1 -0
  84. package/dist/lib/shared/model/conversation-type.d.ts +43 -0
  85. package/dist/lib/shared/model/conversation-type.js +45 -0
  86. package/dist/lib/shared/model/conversation-type.js.map +1 -0
  87. package/dist/lib/shared/model/customaction/custom-action-invocation.d.ts +27 -0
  88. package/dist/lib/shared/model/customaction/custom-action-invocation.js +2 -0
  89. package/dist/lib/shared/model/customaction/custom-action-invocation.js.map +1 -0
  90. package/dist/lib/shared/model/customaction/custom-conversation-action-invocation.d.ts +6 -0
  91. package/dist/lib/shared/model/customaction/custom-conversation-action-invocation.js +2 -0
  92. package/dist/lib/shared/model/customaction/custom-conversation-action-invocation.js.map +1 -0
  93. package/dist/lib/shared/model/customaction/custom-message-action-invocation.d.ts +16 -0
  94. package/dist/lib/shared/model/customaction/custom-message-action-invocation.js +2 -0
  95. package/dist/lib/shared/model/customaction/custom-message-action-invocation.js.map +1 -0
  96. package/dist/lib/shared/model/customaction/custom-person-action-invocation.d.ts +11 -0
  97. package/dist/lib/shared/model/customaction/custom-person-action-invocation.js +2 -0
  98. package/dist/lib/shared/model/customaction/custom-person-action-invocation.js.map +1 -0
  99. package/dist/lib/shared/model/invitation-status.d.ts +14 -0
  100. package/dist/lib/shared/model/invitation-status.js +16 -0
  101. package/dist/lib/shared/model/invitation-status.js.map +1 -0
  102. package/dist/lib/shared/model/invitation.d.ts +24 -0
  103. package/dist/lib/shared/model/invitation.js +2 -0
  104. package/dist/lib/shared/model/invitation.js.map +1 -0
  105. package/dist/lib/shared/model/new-conversation-interceptor-result.d.ts +14 -0
  106. package/dist/lib/shared/model/new-conversation-interceptor-result.js +2 -0
  107. package/dist/lib/shared/model/new-conversation-interceptor-result.js.map +1 -0
  108. package/dist/lib/shared/model/person-info.d.ts +4 -0
  109. package/dist/lib/shared/model/person-info.js +2 -0
  110. package/dist/lib/shared/model/person-info.js.map +1 -0
  111. package/dist/lib/shared/new-conversation-interceptor.d.ts +24 -0
  112. package/dist/lib/shared/new-conversation-interceptor.js +2 -0
  113. package/dist/lib/shared/new-conversation-interceptor.js.map +1 -0
  114. package/dist/lib/shared/unblu-api-error.d.ts +117 -0
  115. package/dist/lib/shared/unblu-api-error.js +122 -0
  116. package/dist/lib/shared/unblu-api-error.js.map +1 -0
  117. package/dist/lib/unblu-embedded-api.d.ts +537 -0
  118. package/dist/lib/unblu-embedded-api.js +473 -0
  119. package/dist/lib/unblu-embedded-api.js.map +1 -0
  120. package/dist/lib/unblu-embedded-app-element.d.ts +703 -0
  121. package/dist/lib/unblu-embedded-app-element.js +844 -0
  122. package/dist/lib/unblu-embedded-app-element.js.map +1 -0
  123. package/dist/lib/view-mode.d.ts +5 -0
  124. package/dist/lib/view-mode.js +7 -0
  125. package/dist/lib/view-mode.js.map +1 -0
  126. package/package.json +23 -0
@@ -0,0 +1,473 @@
1
+ import { Conversation } from "./shared/conversation";
2
+ import { UnbluApiError, UnbluErrorType } from "./shared/unblu-api-error";
3
+ import { ViewMode } from "./view-mode";
4
+ import { UnbluUtil } from "./shared/internal/unblu-util";
5
+ /**
6
+ * This is the main class to interact with the Unblu embedded web component after initialization is done.
7
+ *
8
+ * An instance of the {@link UnbluEmbeddedApi} is returned by calling {@link UnbluEmbeddedAppElement.initialize} or listening to the {@link UnbluEmbeddedAppElement.READY} event.
9
+ *
10
+ * **Note**: After deinitialization an instance of {@link UnbluEmbeddedApi} is no longer usable and will throw errors on API calls.
11
+ * In order to access the API again, it is required to initialize Unblu again.
12
+ */
13
+ export class UnbluEmbeddedApi {
14
+ /**
15
+ * @hidden
16
+ */
17
+ constructor(internalApi) {
18
+ this._internalApi = internalApi;
19
+ }
20
+ async on(event, listener) {
21
+ this.assertNotDeinitialized();
22
+ let internalListener;
23
+ let internalModule;
24
+ switch (event) {
25
+ case UnbluEmbeddedApi.AGENT_AVAILABLE_CHANGE:
26
+ case UnbluEmbeddedApi.AGENT_AVAILABILITY_CHANGE:
27
+ internalListener = (event) => listener(event.data);
28
+ internalModule = this._internalApi.agentAvailability;
29
+ break;
30
+ case UnbluEmbeddedApi.ACTIVE_CONVERSATION_CHANGE:
31
+ internalListener = (event) => listener(event.data ? this.buildConversation(event.data) : null);
32
+ internalModule = this._internalApi.general;
33
+ break;
34
+ case UnbluEmbeddedApi.CONVERSATIONS_CHANGE:
35
+ case UnbluEmbeddedApi.NOTIFICATION_COUNT_CHANGE:
36
+ case UnbluEmbeddedApi.PERSON_CHANGE:
37
+ case UnbluEmbeddedApi.PERSON_ACTIVITY:
38
+ case UnbluEmbeddedApi.FULLSCREEN_CHANGE:
39
+ case UnbluEmbeddedApi.VIEW_MODE_CHANGE:
40
+ internalListener = (event) => listener(event.data);
41
+ internalModule = this._internalApi.general;
42
+ break;
43
+ case UnbluEmbeddedApi.DEINITIALIZING:
44
+ case UnbluEmbeddedApi.DEINITIALIZED:
45
+ internalListener = (event) => listener(event.data);
46
+ internalModule = this._internalApi.meta;
47
+ break;
48
+ default:
49
+ throw new UnbluApiError(UnbluErrorType.INVALID_FUNCTION_ARGUMENTS, 'Registration to unknown event:' + event);
50
+ }
51
+ await internalModule.on(event, internalListener);
52
+ }
53
+ /**
54
+ * Removes a previously registered listener
55
+ * @param event The event to unregister from.
56
+ * @param listener The listener to remove.
57
+ *
58
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
59
+ */
60
+ async off(event, listener) {
61
+ this.assertNotDeinitialized();
62
+ let internalModule;
63
+ switch (event) {
64
+ case UnbluEmbeddedApi.AGENT_AVAILABILITY_CHANGE:
65
+ internalModule = this._internalApi.agentAvailability;
66
+ break;
67
+ case UnbluEmbeddedApi.DEINITIALIZING:
68
+ case UnbluEmbeddedApi.DEINITIALIZED:
69
+ internalModule = this._internalApi.meta;
70
+ break;
71
+ default:
72
+ internalModule = this._internalApi.general;
73
+ break;
74
+ }
75
+ await internalModule.off(event, listener);
76
+ }
77
+ /**
78
+ * Opens the conversation for the given conversation ID.
79
+ *
80
+ * If the conversation doesn't exist or the user doesn't have the right to access it, a dialog will be displayed with the respective error message.
81
+ * Be aware that in such a case the promise will still resolve successfully as the UI switched into the conversation view showing the error dialog. - The active conversation property will however be set to `null`.
82
+ *
83
+ * @see {@link UnbluEmbeddedAppElement.ATTR_CONVERSATION_ID} to set this as attribute
84
+ * @param conversationId The id of the conversation to open. Using null will close the current conversation and open the overview of conversations
85
+ * @return A promise that resolves with the opened conversation instance, `null` if the overview was opened, or it is rejected with an error if it did not work.
86
+ *
87
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
88
+ */
89
+ async openConversation(conversationId) {
90
+ this.assertNotDeinitialized();
91
+ conversationId = UnbluUtil.sanitizeParameter(conversationId);
92
+ let activeConversation;
93
+ if (conversationId) {
94
+ await this._internalApi.general.openConversation(conversationId);
95
+ }
96
+ else if ((activeConversation = await this.getActiveConversation().catch(() => null)) != null) {
97
+ //close the current active conversation
98
+ await activeConversation.closeConversation();
99
+ }
100
+ return this.getActiveConversation();
101
+ }
102
+ /**
103
+ * Returns the currently active conversation or `null` if no conversation is active.
104
+ *
105
+ * **NOTE:** calling this method twice while the same conversation is active, will result in two individual conversation API instances being returned.
106
+ * destroying one of them will not cause the other one to also be destroyed. If however the active conversation is closed, all returned Conversation instances will be destroyed.
107
+ *
108
+ * @return A promise that either resolves to the currently active conversation or `null` if no conversation is open.
109
+ *
110
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
111
+ * @see {@link ACTIVE_CONVERSATION_CHANGE} for the event whenever the active conversation changes
112
+ */
113
+ async getActiveConversation() {
114
+ this.assertNotDeinitialized();
115
+ return this._internalApi.general.getActiveConversation().then(conversationId => this.buildConversation(conversationId));
116
+ }
117
+ /**
118
+ * All conversations accessible to the current user.
119
+ * If no conversation is present, an empty array is returned.
120
+ *
121
+ * @return A promise that resolves to a list of all conversations accessible to the current user.
122
+ *
123
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
124
+ */
125
+ async getConversations() {
126
+ this.assertNotDeinitialized();
127
+ return this._internalApi.general.getConversations();
128
+ }
129
+ /**
130
+ * Sets the view mode of the embedded app element.
131
+ *
132
+ * Depending on the view mode the UI is displayed the following way:
133
+ * - {@link ViewMode.SPLIT}: The UI will be divided into two parts.
134
+ * The list of conversations is displayed on the left and the active conversation on the right side.
135
+ *
136
+ * - {@link ViewMode.SINGLE}: Both the conversation list and the active conversation will be displayed in the same view using UI navigation to switch between them.
137
+ *
138
+ * - {@link ViewMode.AUTO}: The UI will automatically switch back and forth between the two other modes depending on the available width.
139
+ * The trigger point when to switch between the two modes can be configured on the Unblu collaboration server.
140
+ *
141
+ * @param viewMode The new view mode to use
142
+ * @return A promise that resolves as soon as the value has been applied
143
+ * @default {@link ViewMode.AUTO}
144
+ *
145
+ * @see {@link getViewMode} to retrieve the current value
146
+ * @see {@link UnbluEmbeddedAppElement.viewMode} for the corresponding property on the element
147
+ *
148
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
149
+ */
150
+ async setViewMode(viewMode) {
151
+ this.assertNotDeinitialized();
152
+ if (viewMode == null) {
153
+ viewMode = ViewMode.AUTO;
154
+ }
155
+ await this._internalApi.general.setViewMode(viewMode);
156
+ }
157
+ /**
158
+ * Returns the view mode of the embedded app element.
159
+ *
160
+ * @default {@link ViewMode.AUTO}
161
+ * @return A promise that resolves with the current view mode
162
+ *
163
+ * @see {@link setViewMode} to set the value and for further details on the view mode
164
+ * @see {@link UnbluEmbeddedAppElement.viewMode} for the corresponding property on the element
165
+ *
166
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
167
+ */
168
+ async getViewMode() {
169
+ this.assertNotDeinitialized();
170
+ return this._internalApi.general.getViewMode();
171
+ }
172
+ /**
173
+ * When this attribute is set to true, the embedded app element will ignore the position and size set to its element and will used fixed positioning to display itself to cover the whole website.
174
+ *
175
+ * **Note**: The user itself can also toggle this inside the UI.
176
+ *
177
+ * @param fullscreen True to enable fullscreen, false otherwise.
178
+ * @return A promise that resolves as soon as the value has been applied
179
+ * @default false
180
+ *
181
+ * @see {@link isFullscreen} to retrieve the current value
182
+ * @see {@link UnbluEmbeddedAppElement.fullscreen} for the corresponding property on the element
183
+ *
184
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
185
+ */
186
+ async setFullscreen(fullscreen) {
187
+ this.assertNotDeinitialized();
188
+ await this._internalApi.general.setFullscreen(fullscreen);
189
+ }
190
+ /**
191
+ * Returns true if the UI is currently displayed in fullscreen, false otherwise.
192
+ *
193
+ * @default false
194
+ * @return A promise that resolves with true if the UI is in fullscreen mode, false otherwise
195
+ *
196
+ * @see {@link setFullscreen} to set the value and for further details on the view mode
197
+ * @see {@link UnbluEmbeddedAppElement.fullscreen} for the corresponding property on the element
198
+ *
199
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
200
+ */
201
+ async isFullscreen() {
202
+ this.assertNotDeinitialized();
203
+ return this._internalApi.general.isFullscreen();
204
+ }
205
+ /**
206
+ * Returns the information about the current person.
207
+ *
208
+ * @return A promise that resolves with the current person information
209
+ *
210
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
211
+ */
212
+ async getPersonInfo() {
213
+ this.assertNotDeinitialized();
214
+ return this._internalApi.general.getPersonInfo();
215
+ }
216
+ /**
217
+ * Sets the nickname of the current user.
218
+ *
219
+ * This is only respected for anonymous visitors.
220
+ *
221
+ * @return A promise that resolves as soon as the value has been applied
222
+ *
223
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
224
+ */
225
+ async setPersonNickname(nickname) {
226
+ this.assertNotDeinitialized();
227
+ // noinspection JSIgnoredPromiseFromCall
228
+ return this._internalApi.general.setPersonNickname(nickname);
229
+ }
230
+ /**
231
+ * Logs the current visitor in with the access token provided.
232
+ * Depending on the configuration, existing conversation may will be transferred to the authenticated user.
233
+ * @param accessToken The access token (JWT) to authenticate the visitor with
234
+ * @return A promise that resolves empty if the login succeeds or is rejected if it fails
235
+ */
236
+ async login(accessToken) {
237
+ this.assertNotDeinitialized();
238
+ return UnbluUtil.loginWithSecureToken(this._internalApi.configuration.serverUrl || '', this._internalApi.configuration.apiKey, this._internalApi.configuration.entryPath || '/unblu', accessToken);
239
+ }
240
+ /**
241
+ * Checks if the current visitor is authenticated.
242
+ * @return A promise that resolves to a boolean if the visitor is authenticated
243
+ */
244
+ async isAuthenticated() {
245
+ this.assertNotDeinitialized();
246
+ return UnbluUtil.isAuthenticated(this._internalApi.configuration.serverUrl || '', this._internalApi.configuration.entryPath || '/unblu');
247
+ }
248
+ /**
249
+ * Logs the visitor out.
250
+ * The user will not have access to conversations from the authenticated visitor he was before anymore. He needs to be authenticated again for that.
251
+ * @return A promise that resolves empty when the logout succeeds or is rejected if it fails
252
+ */
253
+ async logout() {
254
+ this.assertNotDeinitialized();
255
+ return UnbluUtil.logout(this._internalApi.configuration.serverUrl || '', this._internalApi.configuration.entryPath || '/unblu');
256
+ }
257
+ /**
258
+ * Returns the number of unread messages.
259
+ *
260
+ * @return A promise that resolves with the number of unread messages
261
+ *
262
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
263
+ */
264
+ async getNotificationCount() {
265
+ this.assertNotDeinitialized();
266
+ return this._internalApi.general.getNotificationCount();
267
+ }
268
+ /**
269
+ * Returns true if an agent is available for the current named area and language. False otherwise.
270
+ *
271
+ * @return A promise that resolves with true if an agent is available, false otherwise
272
+ *
273
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
274
+ */
275
+ async isAgentAvailable() {
276
+ this.assertNotDeinitialized();
277
+ return this._internalApi.agentAvailability.isAgentAvailable();
278
+ }
279
+ /**
280
+ * Returns the current availability state for the current named area and language.
281
+ *
282
+ * @return A promise that resolves with the current agent availability state
283
+ *
284
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
285
+ */
286
+ async getAgentAvailabilityState() {
287
+ this.assertNotDeinitialized();
288
+ return this._internalApi.agentAvailability.getAgentAvailabilityState();
289
+ }
290
+ /**
291
+ * Sets a custom interceptor which will be triggered when a new conversation is started (initiated from UI or JavaScript).
292
+ *
293
+ * @param newConversationInterceptor The interceptor which should be triggered on new conversations
294
+ *
295
+ * @return A promise that resolves as soon as the new interceptor has been applied
296
+ *
297
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
298
+ */
299
+ async setNewConversationInterceptor(newConversationInterceptor) {
300
+ this.assertNotDeinitialized();
301
+ return this._internalApi.general.setNewConversationInterceptor(newConversationInterceptor);
302
+ }
303
+ /**
304
+ * Joins an existing conversation with a given PIN.
305
+ *
306
+ * @param pin The PIN retrieved from the Unblu Agent Desk.
307
+ * @param visitorName The name the local visitor should have. This is only taken into account if the visitor is not already authenticated.
308
+ * @return A promise that resolves to the conversation which was joined
309
+ *
310
+ * @throws {@link UnbluApiError} with type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized.
311
+ */
312
+ async joinConversation(pin, visitorName) {
313
+ this.assertNotDeinitialized();
314
+ return this._internalApi.general.joinConversation(pin, visitorName).then(conversationId => this.buildConversation(conversationId));
315
+ }
316
+ /**
317
+ * Starts a new conversation and places it into the inbound conversation queue.
318
+ *
319
+ * Starting a new conversation involves an agent availability check.
320
+ * For {@link ConversationType.OFFLINE_CHAT_REQUEST} conversations, the check proceeds as follows:
321
+ * * If an agent is available, the conversation type will be changed to {@link ConversationType.CHAT_REQUEST}.
322
+ * * If no agents are available, it will start an offline conversation provided offline chat requests are enabled in the Unblu server's configuration.
323
+ * * if offline chat requests aren't enabled, the request will be rejected.
324
+ *
325
+ * For all `online` conversation types, the check works as follows:
326
+ * * If an agent is available, the conversation will be started.
327
+ * * If no agents are available, the request will be rejected.
328
+ *
329
+ * You should therefore always check agent availability before starting a new conversation.
330
+ * If no agents are available, only start conversations of the type {@link ConversationType.OFFLINE_CHAT_REQUEST}.
331
+ *
332
+ * @param type The type of the conversation
333
+ * @param visitorName The name of the visitor. This is only respected for anonymous visitors
334
+ * @param visitorData Custom visitor data that will be stored on the conversation and can be accessed through the Web API later on. This data won't be displayed anywhere and is for API usage only.
335
+ * @param recipient The team or agent recipient of the conversation. This will overwrite any named area that might be set for this web page.
336
+ * @return A promise that resolves to the conversation which was started
337
+ *
338
+ * @throws {@link UnbluApiError} of type {@link UnbluErrorType.ILLEGAL_STATE} when the API instance is deinitialized or if the conversation type may not be started.
339
+ */
340
+ async startConversation(type, visitorName, visitorData, recipient) {
341
+ this.assertNotDeinitialized();
342
+ return this._internalApi.general.startConversation(type, visitorName, visitorData, recipient).then(conversationId => this.buildConversation(conversationId));
343
+ }
344
+ buildConversation(conversationId) {
345
+ if (conversationId != null) {
346
+ return new Conversation(this._internalApi.conversation, conversationId);
347
+ }
348
+ else {
349
+ return null;
350
+ }
351
+ }
352
+ assertNotDeinitialized() {
353
+ if (this.isDeinitialized()) {
354
+ throw new UnbluApiError(UnbluErrorType.ILLEGAL_STATE, 'Error: trying to execute method on deinitialized UnbluApi instance.');
355
+ }
356
+ }
357
+ /**
358
+ * Returns true if this instance of the API is deinitialized, false otherwise.
359
+ */
360
+ isDeinitialized() {
361
+ return this._internalApi == null;
362
+ }
363
+ /**
364
+ * Deinitializes the Unblu Embedded Web Component.
365
+ * This means that both API is no longer usable but also the UI is completely destroyed.
366
+ */
367
+ async deinitialize() {
368
+ if (this.isDeinitialized()) {
369
+ return;
370
+ }
371
+ await this._internalApi.meta.deinitialize();
372
+ this._internalApi = null;
373
+ }
374
+ }
375
+ /**
376
+ * Event emitted every time the active conversation changes.
377
+ *
378
+ * This may happen due to a UI-navigation or an API-call.
379
+ *
380
+ * @event activeConversationChange
381
+ * @see {@link on} for listener registration
382
+ * @see {@link ConversationChangeListener}
383
+ */
384
+ UnbluEmbeddedApi.ACTIVE_CONVERSATION_CHANGE = 'activeConversationChange';
385
+ /**
386
+ * Event emitted every time one of the conversations accessible to the current user changes or one is added or removed.
387
+ *
388
+ * @event conversationsChanged
389
+ * @see {@link on} for listener registration
390
+ * @see {@link ConversationsChangeListener}
391
+ */
392
+ UnbluEmbeddedApi.CONVERSATIONS_CHANGE = 'conversationsChange';
393
+ /**
394
+ * Event emitted every time the notification count (unread messages) changes.
395
+ *
396
+ * @event notificationCountChange
397
+ * @see {@link on} for listener registration
398
+ * @see {@link NotificationCountChangeListener}
399
+ */
400
+ UnbluEmbeddedApi.NOTIFICATION_COUNT_CHANGE = 'notificationCountChange';
401
+ /**
402
+ * Event emitted every time the local person changes. This may be i.e. due to the person setting its name.
403
+ *
404
+ * @event personChange
405
+ * @see {@link on} for listener registration
406
+ * @see {@link PersonChangeListener}
407
+ */
408
+ UnbluEmbeddedApi.PERSON_CHANGE = 'personChange';
409
+ /**
410
+ * Event emitted every time the local person has some activity inside Unblu.
411
+ * This may be i.e. an interaction with the chat, a call, opening a conversation or interacting
412
+ * with a co-browsing layer.
413
+ *
414
+ * The event can be used to reset the logout timer inside an authenticated area, for example.
415
+ *
416
+ * The configuration property com.unblu.conversation.activity.activityCategoriesToTrack specifies which categories of activity trigger the event.
417
+ *
418
+ * @event personActivity
419
+ * @see {@link on} for listener registration
420
+ * @see {@link PersonActivityListener}
421
+ */
422
+ UnbluEmbeddedApi.PERSON_ACTIVITY = 'personActivity';
423
+ /**
424
+ * Event emitted every time the agent availability changes for the current named area and locale.
425
+ *
426
+ * @event availableChange
427
+ * @see {@link on} for listener registration
428
+ * @see {@link AgentAvailableChangeListener}
429
+ */
430
+ UnbluEmbeddedApi.AGENT_AVAILABLE_CHANGE = 'availableChange';
431
+ /**
432
+ * Event emitted every time the agent availability state changes for the current named area and locale.
433
+ *
434
+ * @event availabilityChange
435
+ * @see {@link on} for listener registration
436
+ * @see {@link AgentAvailabilityChangeListener}
437
+ */
438
+ UnbluEmbeddedApi.AGENT_AVAILABILITY_CHANGE = 'availabilityChange';
439
+ /**
440
+ * Event emitted every time the embedded app switches to fullscreen mode or back.
441
+ *
442
+ * @event fullscreenChange
443
+ * @see {@link on} for listener registration
444
+ * @see {@link FullscreenChangeListener}
445
+ */
446
+ UnbluEmbeddedApi.FULLSCREEN_CHANGE = 'fullscreenChange';
447
+ /**
448
+ * Event emitted every time the view mode changes.
449
+ *
450
+ * @event viewModeChange
451
+ * @see {@link on} for listener registration
452
+ * @see {@link FullscreenChangeListener}
453
+ */
454
+ UnbluEmbeddedApi.VIEW_MODE_CHANGE = 'viewModeChange';
455
+ /**
456
+ * Event emitted when this instance gets de-initialized and is not usable at the time until it fully got de-initialized.
457
+ *
458
+ * @event deinitializing
459
+ * @see {@link on} for listener registration
460
+ * @see {@link DeinitializationListener}
461
+ */
462
+ UnbluEmbeddedApi.DEINITIALIZING = 'deinitializing';
463
+ /**
464
+ * Event emitted when this instance got de-initialized and has to be initialized again.
465
+ *
466
+ * **Note**: After this event, the instance of {@link UnbluEmbeddedApi} is no longer usable.
467
+ *
468
+ * @event deinitialized
469
+ * @see {@link on} for listener registration
470
+ * @see {@link DeinitializationListener}
471
+ */
472
+ UnbluEmbeddedApi.DEINITIALIZED = 'deinitialized';
473
+ //# sourceMappingURL=unblu-embedded-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unblu-embedded-api.js","sourceRoot":"","sources":["../../src/unblu-embedded-api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAA;AAMlD,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,0BAA0B,CAAA;AAGtE,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AAKpC,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AA4GvD;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IAkHzB;;OAEG;IACH,YAAY,WAAgC;QACxC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACnC,CAAC;IAuGM,KAAK,CAAC,EAAE,CAAC,KAA4E,EAAE,QAA8B;QACxH,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC7B,IAAI,gBAA+B,CAAA;QACnC,IAAI,cAAwC,CAAA;QAC5C,QAAQ,KAAK,EAAE;YACX,KAAK,gBAAgB,CAAC,sBAAsB,CAAC;YAC7C,KAAK,gBAAgB,CAAC,yBAAyB;gBAC3C,gBAAgB,GAAG,CAAC,KAA8C,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAC3F,cAAc,GAAG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