@unboundcx/sdk 4.8.8 → 4.8.9

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.
@@ -1,302 +0,0 @@
1
- export class CCService {
2
- constructor(sdk) {
3
- this.sdk = sdk;
4
- }
5
-
6
- /**
7
- * Resolve the caller's Contact Center queue scope + role.
8
- * Managers see every non-deleted queue; agents see only the queues they
9
- * belong to (queueUsers).
10
- *
11
- * @returns {Promise<Object>} result
12
- * @returns {boolean} result.isManager - Whether the caller has queue-manager scope
13
- * @returns {string|null} result.workerId - The caller's own worker id, if any
14
- * @returns {Array<Object>} result.queues - Accessible queues [{id, name, slaThreshold}]
15
- *
16
- * @example
17
- * const scope = await sdk.taskRouter.cc.getScope();
18
- * console.log(scope.isManager, scope.queues.length);
19
- */
20
- async getScope() {
21
- const result = await this.sdk._fetch('/taskRouter/cc/scope', 'GET', {});
22
- return result;
23
- }
24
-
25
- /**
26
- * Get a live Contact Center snapshot (KPIs, per-queue summaries, team roster
27
- * with active tasks) scoped to a set of queues.
28
- *
29
- * @param {Object} [options] - Parameters
30
- * @param {string[]} [options.queueIds] - Queue ids to scope to (must be a subset of the caller's accessible queues). Omit/empty for full scope.
31
- * @returns {Promise<Object>} result
32
- * @returns {Object} result.kpis - Aggregate KPIs (inQueueNow, longestWaitSec, myHandledToday, myAvgHandleSecToday, slaTodayPct, slaTargetPct)
33
- * @returns {Array<Object>} result.queues - Per-queue summaries (id, name, waiting, longestWaitSec, agentsAvailable, agentsTotal, slaPct, health)
34
- * @returns {Array<Object>} result.team - Team roster with active tasks
35
- *
36
- * @example
37
- * const snapshot = await sdk.taskRouter.cc.getSnapshot({ queueIds: ['q1', 'q2'] });
38
- * console.log(snapshot.kpis.inQueueNow);
39
- */
40
- async getSnapshot(options = {}) {
41
- const { queueIds } = options;
42
-
43
- this.sdk.validateParams(
44
- { queueIds },
45
- {
46
- queueIds: { type: 'array', required: false },
47
- },
48
- );
49
-
50
- const params = {};
51
- if (queueIds && queueIds.length) {
52
- params.query = { queueIds: queueIds.join(',') };
53
- }
54
-
55
- const result = await this.sdk._fetch(
56
- '/taskRouter/cc/snapshot',
57
- 'GET',
58
- params,
59
- );
60
- return result;
61
- }
62
-
63
- /**
64
- * Get on-queue session history for a worker (self allowed; another
65
- * worker's sessions require the queue-manager scope).
66
- *
67
- * @param {Object} [options] - Parameters
68
- * @param {string} [options.workerId] - Worker id to fetch sessions for (defaults to the caller's own worker)
69
- * @param {string} [options.from] - ISO-8601 range start
70
- * @param {string} [options.to] - ISO-8601 range end
71
- * @returns {Promise<Object>} result
72
- * @returns {Array<Object>} result.sessions - [{id, startedAt, endedAt, onQueueSec, breakSec, doneCount}]
73
- *
74
- * @example
75
- * const { sessions } = await sdk.taskRouter.cc.getSessions({ workerId: 'w1', from: '2026-08-12T00:00:00Z', to: '2026-08-19T00:00:00Z' });
76
- */
77
- async getSessions(options = {}) {
78
- const { workerId, from, to } = options;
79
-
80
- this.sdk.validateParams(
81
- { workerId, from, to },
82
- {
83
- workerId: { type: 'string', required: false },
84
- from: { type: 'string', required: false },
85
- to: { type: 'string', required: false },
86
- },
87
- );
88
-
89
- const query = {};
90
- if (workerId) query.workerId = workerId;
91
- if (from) query.from = from;
92
- if (to) query.to = to;
93
-
94
- const result = await this.sdk._fetch('/taskRouter/cc/sessions', 'GET', {
95
- query,
96
- });
97
- return result;
98
- }
99
-
100
- /**
101
- * Get windowed composite agent rankings (top/struggling) per queue + an
102
- * 'all' rollup, scored from sentiment/SLA/volume/acceptance. `struggling`
103
- * arrays are only present when the caller has the queue-manager scope
104
- * (see `strugglingIncluded` on the result).
105
- *
106
- * @param {Object} [options] - Parameters
107
- * @param {string[]} [options.queueIds] - Queue ids to scope to (must be a subset of the caller's accessible queues). Omit/empty for full scope.
108
- * @param {string} options.from - ISO-8601 window start
109
- * @param {string} options.to - ISO-8601 window end
110
- * @returns {Promise<Object>} result
111
- * @returns {Object} result.queues - Per-queue rankings, keyed by queueId: `{ top: [{workerId,name,score}], struggling?: [...] }`
112
- * @returns {Object} result.all - Same shape, aggregated across every scoped queue
113
- * @returns {boolean} result.strugglingIncluded - Whether `struggling` arrays were included
114
- *
115
- * @example
116
- * const { queues, all } = await sdk.taskRouter.cc.getRankings({
117
- * queueIds: ['q1'],
118
- * from: '2026-08-12T00:00:00Z',
119
- * to: '2026-08-19T00:00:00Z',
120
- * });
121
- * console.log(all.top[0].name, all.top[0].score);
122
- */
123
- async getRankings(options = {}) {
124
- const { queueIds, from, to } = options;
125
-
126
- this.sdk.validateParams(
127
- { queueIds, from, to },
128
- {
129
- queueIds: { type: 'array', required: false },
130
- from: { type: 'string', required: true },
131
- to: { type: 'string', required: true },
132
- },
133
- );
134
-
135
- const query = { from, to };
136
- if (queueIds && queueIds.length) {
137
- query.queueIds = queueIds.join(',');
138
- }
139
-
140
- const result = await this.sdk._fetch('/taskRouter/cc/rankings', 'GET', {
141
- query,
142
- });
143
- return result;
144
- }
145
-
146
- /**
147
- * Set a queue's composite ranking-weights override. Manager-only
148
- * (`taskrouter:queue:manage`). Weights must be integers 0-100 that sum to
149
- * exactly 100.
150
- *
151
- * @param {Object} options - Parameters
152
- * @param {string} options.queueId - Queue id to update
153
- * @param {Object} options.weights - `{sentiment, sla, volume, acceptance}` ints summing to 100
154
- * @returns {Promise<Object>} result
155
- * @returns {string} result.queueId
156
- * @returns {Object} result.rankingWeights - The stored weights
157
- *
158
- * @example
159
- * await sdk.taskRouter.cc.setQueueRankingWeights({
160
- * queueId: 'q1',
161
- * weights: { sentiment: 35, sla: 25, volume: 20, acceptance: 20 },
162
- * });
163
- */
164
- async setQueueRankingWeights(options = {}) {
165
- const { queueId, weights } = options;
166
-
167
- this.sdk.validateParams(
168
- { queueId, weights },
169
- {
170
- queueId: { type: 'string', required: true },
171
- weights: { type: 'object', required: true },
172
- },
173
- );
174
-
175
- const result = await this.sdk._fetch(
176
- `/taskRouter/cc/queues/${queueId}/rankingWeights`,
177
- 'PUT',
178
- { body: weights },
179
- );
180
- return result;
181
- }
182
-
183
- /**
184
- * Get one agent's Contact Center performance summary (KPIs, per-day
185
- * charts, live tasks, on-queue sessions) over a date/date-range, with a
186
- * comparison window for deltas. Self allowed; another worker's summary
187
- * requires the queue-manager scope.
188
- *
189
- * @param {Object} options - Parameters
190
- * @param {string} options.workerId - Worker id to summarize
191
- * @param {string} options.from - ISO-8601 window start
192
- * @param {string} options.to - ISO-8601 window end
193
- * @param {string} [options.compareFrom] - ISO-8601 comparison window start (defaults to the preceding equal-length period)
194
- * @param {string} [options.compareTo] - ISO-8601 comparison window end
195
- * @returns {Promise<Object>} result
196
- * @returns {Object} result.kpis - tasksHandled, offersAccepted, avgHandleSec, slaMet, avgSentiment, composite, onQueue
197
- * @returns {Array<Object>} result.tasksPerDay - [{date, count}]
198
- * @returns {Array<Object>} result.trend - [{date, sentiment, slaPct}]
199
- * @returns {Array<Object>} result.liveNow - Current tasks (only when the window includes today)
200
- * @returns {Array<Object>} result.sessions - On-queue session log
201
- *
202
- * @example
203
- * const summary = await sdk.taskRouter.cc.getAgentSummary({
204
- * workerId: 'w1',
205
- * from: '2026-08-12T00:00:00Z',
206
- * to: '2026-08-19T00:00:00Z',
207
- * });
208
- * console.log(summary.kpis.tasksHandled.value);
209
- */
210
- async getAgentSummary(options = {}) {
211
- const { workerId, from, to, compareFrom, compareTo } = options;
212
-
213
- this.sdk.validateParams(
214
- { workerId, from, to, compareFrom, compareTo },
215
- {
216
- workerId: { type: 'string', required: true },
217
- from: { type: 'string', required: true },
218
- to: { type: 'string', required: true },
219
- compareFrom: { type: 'string', required: false },
220
- compareTo: { type: 'string', required: false },
221
- },
222
- );
223
-
224
- const query = { from, to };
225
- if (compareFrom) query.compareFrom = compareFrom;
226
- if (compareTo) query.compareTo = compareTo;
227
-
228
- const result = await this.sdk._fetch(
229
- `/taskRouter/cc/agents/${workerId}/summary`,
230
- 'GET',
231
- { query },
232
- );
233
- return result;
234
- }
235
-
236
- /**
237
- * Log a worker into or out of a queue. Manager-only
238
- * (`taskrouter:queue:manage`). Mutates the worker's queue membership
239
- * through task-router (audited).
240
- *
241
- * @param {Object} options - Parameters
242
- * @param {string} options.workerId - Worker id to update
243
- * @param {string} options.queueId - Queue id to log in/out of
244
- * @param {'login'|'logout'} options.action - Whether to add or remove the queue
245
- * @returns {Promise<Object>} result
246
- * @returns {string} result.workerId
247
- * @returns {string} result.status
248
- * @returns {Array<string>} result.queues - The worker's updated queue list
249
- *
250
- * @example
251
- * await sdk.taskRouter.cc.setWorkerQueue({ workerId: 'w1', queueId: 'q1', action: 'login' });
252
- */
253
- async setWorkerQueue(options = {}) {
254
- const { workerId, queueId, action } = options;
255
-
256
- this.sdk.validateParams(
257
- { workerId, queueId, action },
258
- {
259
- workerId: { type: 'string', required: true },
260
- queueId: { type: 'string', required: true },
261
- action: { type: 'string', required: true },
262
- },
263
- );
264
-
265
- const result = await this.sdk._fetch(
266
- `/taskRouter/cc/workers/${workerId}/queues`,
267
- 'PUT',
268
- { body: { queueId, action } },
269
- );
270
- return result;
271
- }
272
-
273
- /**
274
- * Force a worker offline (out of every queue), closing their on-queue
275
- * session. Manager-only (`taskrouter:queue:manage`, audited).
276
- *
277
- * @param {Object} options - Parameters
278
- * @param {string} options.workerId - Worker id to log out
279
- * @returns {Promise<Object>} result
280
- * @returns {string} result.workerId
281
- * @returns {string} result.status
282
- * @returns {Array<string>} result.queues
283
- *
284
- * @example
285
- * await sdk.taskRouter.cc.forceLogoutWorker({ workerId: 'w1' });
286
- */
287
- async forceLogoutWorker(options = {}) {
288
- const { workerId } = options;
289
-
290
- this.sdk.validateParams(
291
- { workerId },
292
- { workerId: { type: 'string', required: true } },
293
- );
294
-
295
- const result = await this.sdk._fetch(
296
- `/taskRouter/cc/workers/${workerId}/forceLogout`,
297
- 'POST',
298
- {},
299
- );
300
- return result;
301
- }
302
- }