@unboundcx/sdk 4.13.73 → 4.13.75

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/index.js CHANGED
@@ -22,6 +22,7 @@ import { PortalsService } from './services/portals.js';
22
22
  import { DealRegistrationsService } from './services/dealRegistrations.js';
23
23
  import { SipEndpointsService } from './services/sipEndpoints.js';
24
24
  import { WebchatService } from './services/webchat.js';
25
+ import { CobrowseService } from './services/cobrowse.js';
25
26
  import { MessageTemplatesService } from './services/messageTemplates.js';
26
27
  import { ExternalOAuthService } from './services/externalOAuth.js';
27
28
  import { GoogleCalendarService } from './services/googleCalendar.js';
@@ -118,6 +119,7 @@ class UnboundSDK extends BaseSDK {
118
119
  this.dealRegistrations = new DealRegistrationsService(this);
119
120
  this.sipEndpoints = new SipEndpointsService(this);
120
121
  this.webchat = new WebchatService(this);
122
+ this.cobrowse = new CobrowseService(this);
121
123
  this.messageTemplates = new MessageTemplatesService(this);
122
124
  this.externalOAuth = new ExternalOAuthService(this);
123
125
  this.googleCalendar = new GoogleCalendarService(this);
@@ -314,6 +316,7 @@ export { PortalsService } from './services/portals.js';
314
316
  export { DealRegistrationsService } from './services/dealRegistrations.js';
315
317
  export { SipEndpointsService } from './services/sipEndpoints.js';
316
318
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
319
+ export { CobrowseService, CobrowseVisitorService } from './services/cobrowse.js';
317
320
  export { MessageTemplatesService } from './services/messageTemplates.js';
318
321
  export { WebchatVisitorService } from './services/webchat/VisitorService.js';
319
322
  export { ExternalOAuthService } from './services/externalOAuth.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.73",
3
+ "version": "4.13.75",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,259 @@
1
+ import { internalRequest } from '../base.js';
2
+
3
+ function authHeaders(token) {
4
+ return token ? { headers: { Authorization: `Bearer ${token}` } } : {};
5
+ }
6
+
7
+ function assertWebchatSource(source, method) {
8
+ if (source !== 'webchat') {
9
+ throw new Error(
10
+ `cobrowse.${method}: source '${source}' is not supported (v1 is webchat only)`,
11
+ );
12
+ }
13
+ }
14
+
15
+ function webchatHostIds(
16
+ { source, widgetId, hostId, engagementSessionId } = {},
17
+ method,
18
+ ) {
19
+ const esId = hostId ?? engagementSessionId;
20
+ assertWebchatSource(source, method);
21
+ return { widgetId, engagementSessionId: esId };
22
+ }
23
+
24
+ function conversationCobrowsePath(widgetId, engagementSessionId, suffix = '') {
25
+ return `/webchat/widgets/${widgetId}/conversations/${engagementSessionId}/cobrowse${suffix}`;
26
+ }
27
+
28
+ /**
29
+ * Visitor cobrowse consent (session JWT). Custom UIs; embed uses
30
+ * webchatApi.js in P1. Paths are public `/webchat/:widgetId/cobrowse/*`.
31
+ */
32
+ export class CobrowseVisitorService {
33
+ constructor(sdk) {
34
+ this.sdk = sdk;
35
+ }
36
+
37
+ async #post(action, { widgetId, token, sid } = {}) {
38
+ this.sdk.validateParams(
39
+ { widgetId, token, sid },
40
+ {
41
+ widgetId: { type: 'string', required: true },
42
+ token: { type: 'string', required: true },
43
+ sid: { type: 'string', required: true },
44
+ },
45
+ );
46
+ return internalRequest(
47
+ this.sdk,
48
+ `/webchat/${widgetId}/cobrowse/${action}`,
49
+ 'POST',
50
+ { body: { sid }, ...authHeaders(token) },
51
+ true,
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Accept a pending cobrowse request. Starts live after API 200.
57
+ * @param {Object} params
58
+ * @param {string} params.widgetId
59
+ * @param {string} params.token - Webchat session JWT
60
+ * @param {string} params.sid
61
+ */
62
+ async accept(params) {
63
+ return this.#post('accept', params);
64
+ }
65
+
66
+ /**
67
+ * Decline a pending cobrowse request.
68
+ * @param {Object} params
69
+ * @param {string} params.widgetId
70
+ * @param {string} params.token
71
+ * @param {string} params.sid
72
+ */
73
+ async deny(params) {
74
+ return this.#post('deny', params);
75
+ }
76
+
77
+ /**
78
+ * Visitor-initiated end of a live/requested cobrowse session.
79
+ * @param {Object} params
80
+ * @param {string} params.widgetId
81
+ * @param {string} params.token
82
+ * @param {string} params.sid
83
+ */
84
+ async end(params) {
85
+ return this.#post('end', params);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Host-agnostic cobrowse surface (`sdk.cobrowse.*`). v1 adapter is
91
+ * WebChat; Meet later uses the same method names with `source:'meet'`.
92
+ * No `sdk.webchat.cobrowse`.
93
+ */
94
+ export class CobrowseService {
95
+ constructor(sdk) {
96
+ this.sdk = sdk;
97
+ this.visitor = new CobrowseVisitorService(sdk);
98
+ }
99
+
100
+ /**
101
+ * Agent request. Nested under the webchat conversation.
102
+ * @param {Object} params
103
+ * @param {'webchat'} params.source
104
+ * @param {string} params.widgetId
105
+ * @param {string} params.hostId - engagementSessionId when source is webchat
106
+ * @param {string} [params.engagementSessionId] - alias of hostId
107
+ * @param {'pointer'|'write'} [params.mode='pointer']
108
+ * @param {boolean} [params.record=false]
109
+ */
110
+ async request({
111
+ source,
112
+ widgetId,
113
+ hostId,
114
+ engagementSessionId,
115
+ mode = 'pointer',
116
+ record = false,
117
+ } = {}) {
118
+ const ids = webchatHostIds(
119
+ { source, widgetId, hostId, engagementSessionId },
120
+ 'request',
121
+ );
122
+ this.sdk.validateParams(
123
+ { source, widgetId, hostId: ids.engagementSessionId, mode, record },
124
+ {
125
+ source: { type: 'string', required: true },
126
+ widgetId: { type: 'string', required: true },
127
+ hostId: { type: 'string', required: true },
128
+ mode: { type: 'string', required: false },
129
+ record: { type: 'boolean', required: false },
130
+ },
131
+ );
132
+ return internalRequest(
133
+ this.sdk,
134
+ conversationCobrowsePath(ids.widgetId, ids.engagementSessionId, '/request'),
135
+ 'POST',
136
+ { body: { mode, record: record === true } },
137
+ );
138
+ }
139
+
140
+ /**
141
+ * Agent end. Nested under the conversation because the HTTP route is.
142
+ * @param {Object} params
143
+ * @param {string} params.sid
144
+ * @param {string} params.widgetId
145
+ * @param {string} [params.hostId]
146
+ * @param {string} [params.engagementSessionId]
147
+ * @param {'webchat'} [params.source='webchat']
148
+ */
149
+ async end({
150
+ sid,
151
+ widgetId,
152
+ hostId,
153
+ engagementSessionId,
154
+ source = 'webchat',
155
+ } = {}) {
156
+ const ids = webchatHostIds(
157
+ { source, widgetId, hostId, engagementSessionId },
158
+ 'end',
159
+ );
160
+ this.sdk.validateParams(
161
+ { sid, widgetId, hostId: ids.engagementSessionId },
162
+ {
163
+ sid: { type: 'string', required: true },
164
+ widgetId: { type: 'string', required: true },
165
+ hostId: { type: 'string', required: true },
166
+ },
167
+ );
168
+ return internalRequest(
169
+ this.sdk,
170
+ conversationCobrowsePath(
171
+ ids.widgetId,
172
+ ids.engagementSessionId,
173
+ `/${sid}/end`,
174
+ ),
175
+ 'POST',
176
+ );
177
+ }
178
+
179
+ /**
180
+ * Current cobrowse session metadata for this host (no DOM).
181
+ * @param {Object} params
182
+ * @param {'webchat'} params.source
183
+ * @param {string} params.widgetId
184
+ * @param {string} params.hostId
185
+ * @param {string} [params.engagementSessionId]
186
+ */
187
+ async getActive({
188
+ source,
189
+ widgetId,
190
+ hostId,
191
+ engagementSessionId,
192
+ } = {}) {
193
+ const ids = webchatHostIds(
194
+ { source, widgetId, hostId, engagementSessionId },
195
+ 'getActive',
196
+ );
197
+ this.sdk.validateParams(
198
+ { source, widgetId, hostId: ids.engagementSessionId },
199
+ {
200
+ source: { type: 'string', required: true },
201
+ widgetId: { type: 'string', required: true },
202
+ hostId: { type: 'string', required: true },
203
+ },
204
+ );
205
+ return internalRequest(
206
+ this.sdk,
207
+ conversationCobrowsePath(ids.widgetId, ids.engagementSessionId, '/active'),
208
+ 'GET',
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Download the combined recording.ndjson for a finished cobrowse session.
214
+ * HTTP only (forceFetch) so the body is the event log, not JSON.
215
+ * @param {Object} params
216
+ * @param {'webchat'} params.source
217
+ * @param {string} params.widgetId
218
+ * @param {string} params.hostId
219
+ * @param {string} params.sid
220
+ * @param {string} [params.engagementSessionId]
221
+ */
222
+ async getRecording({
223
+ source,
224
+ widgetId,
225
+ hostId,
226
+ engagementSessionId,
227
+ sid,
228
+ } = {}) {
229
+ const ids = webchatHostIds(
230
+ { source, widgetId, hostId, engagementSessionId },
231
+ 'getRecording',
232
+ );
233
+ this.sdk.validateParams(
234
+ {
235
+ source,
236
+ widgetId,
237
+ hostId: ids.engagementSessionId,
238
+ sid,
239
+ },
240
+ {
241
+ source: { type: 'string', required: true },
242
+ widgetId: { type: 'string', required: true },
243
+ hostId: { type: 'string', required: true },
244
+ sid: { type: 'string', required: true },
245
+ },
246
+ );
247
+ return internalRequest(
248
+ this.sdk,
249
+ conversationCobrowsePath(
250
+ ids.widgetId,
251
+ ids.engagementSessionId,
252
+ `/${sid}/recording`,
253
+ ),
254
+ 'GET',
255
+ {},
256
+ true,
257
+ );
258
+ }
259
+ }