@unboundcx/sdk 4.13.136 → 4.13.137

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.136",
3
+ "version": "4.13.137",
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,98 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ // queues.overflowRules / queues.pendingCounts (queue-capacity-overflow-plan.md
4
+ // v4, P4 contract D). Kept as its own file per CLAUDE.md's 400-line guideline
5
+ // rather than folding into TaskService.js.
6
+ export class QueueService {
7
+ constructor(sdk) {
8
+ this.sdk = sdk;
9
+ }
10
+
11
+ /**
12
+ * Get the queue's overflow rules (queueOverflowRules table). When the
13
+ * queue has no normalized rows yet, the API synthesizes editable rules
14
+ * from the legacy waitPolicy/closedPolicy columns instead of returning
15
+ * an empty array.
16
+ *
17
+ * @param {string} queueId - The queue ID (required)
18
+ * @returns {Promise<Object>} result
19
+ * @returns {Object[]} result.overflowRules - Rows for the queue (one per queueId x channel x trigger)
20
+ * @returns {boolean} result.synthesized - True when the rules were derived from legacy waitPolicy/closedPolicy, not read from queueOverflowRules
21
+ *
22
+ * @example
23
+ * const { overflowRules } = await sdk.taskRouter.queues.getOverflowRules('queue123');
24
+ */
25
+ async getOverflowRules(queueId) {
26
+ this.sdk.validateParams(
27
+ { queueId },
28
+ { queueId: { type: 'string', required: true } },
29
+ );
30
+
31
+ return await internalRequest(
32
+ this.sdk,
33
+ `/taskRouter/queues/${queueId}/overflowRules`,
34
+ 'GET',
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Replace the full set of overflow rules for a queue.
40
+ *
41
+ * @param {string} queueId - The queue ID (required)
42
+ * @param {Object[]} rules - The complete set of overflow rules to store for this queue (replaces any existing rows)
43
+ * @param {string} rules[].channel - 'phoneCall' | 'chat' | 'email' | 'sms' | 'fax' | 'other' | 'whatsApp' | 'rcs'
44
+ * @param {string} rules[].trigger - 'maxWait' | 'noAgents' | 'capacity' | 'closed'
45
+ * @param {string} rules[].action - 'none' | 'complete' | 'leaveMessage' | 'callback' | 'routeToQueue' | 'rebalance' | 'routeToWorkflow' | 'routeToDestination'
46
+ * @param {Object} [rules[].options] - Action-specific options (e.g. maxWaitSeconds, targetWorkflowId, destination)
47
+ * @param {string[]} [rules[].candidateQueueIds] - Candidate queue ids for routeToQueue/rebalance actions
48
+ * @returns {Promise<Object>} result
49
+ * @returns {Object[]} result.overflowRules - The stored rules, as written
50
+ *
51
+ * @example
52
+ * await sdk.taskRouter.queues.setOverflowRules('queue123', [
53
+ * { channel: 'phoneCall', trigger: 'maxWait', action: 'routeToWorkflow', options: { targetWorkflowId: 'wf1' } },
54
+ * ]);
55
+ */
56
+ async setOverflowRules(queueId, rules) {
57
+ this.sdk.validateParams(
58
+ { queueId, rules },
59
+ {
60
+ queueId: { type: 'string', required: true },
61
+ rules: { type: 'array', required: true },
62
+ },
63
+ );
64
+
65
+ return await internalRequest(
66
+ this.sdk,
67
+ `/taskRouter/queues/${queueId}/overflowRules`,
68
+ 'PUT',
69
+ { body: { overflowRules: rules } },
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Get the queue's current pending counts per channel. Thin proxy onto
75
+ * task-router's authoritative, committed counts (not a SQL COUNT(*)).
76
+ *
77
+ * @param {string} queueId - The queue ID (required)
78
+ * @returns {Promise<Object>} result
79
+ * @returns {string} result.queueId
80
+ * @returns {Object} result.counts - Keyed by channel, e.g. `{ phoneCall: { pending, asyncWait, voicemail } }`
81
+ *
82
+ * @example
83
+ * const { counts } = await sdk.taskRouter.queues.getPendingCounts('queue123');
84
+ * const waitingCalls = counts.phoneCall?.pending ?? 0;
85
+ */
86
+ async getPendingCounts(queueId) {
87
+ this.sdk.validateParams(
88
+ { queueId },
89
+ { queueId: { type: 'string', required: true } },
90
+ );
91
+
92
+ return await internalRequest(
93
+ this.sdk,
94
+ `/taskRouter/queues/${queueId}/pendingCounts`,
95
+ 'GET',
96
+ );
97
+ }
98
+ }
@@ -5,6 +5,7 @@ import { CCService } from './CCService.js';
5
5
  import { OfferService } from './OfferService.js';
6
6
  import { ParticipantService } from './ParticipantService.js';
7
7
  import { CcBotsService } from './CcBotsService.js';
8
+ import { QueueService } from './QueueService.js';
8
9
 
9
10
  export class TaskRouterService {
10
11
  constructor(sdk) {
@@ -16,5 +17,6 @@ export class TaskRouterService {
16
17
  this.offer = new OfferService(sdk);
17
18
  this.participants = new ParticipantService(sdk);
18
19
  this.ccBots = new CcBotsService(sdk);
20
+ this.queues = new QueueService(sdk);
19
21
  }
20
22
  }
@@ -1252,6 +1252,7 @@ export class TaskService {
1252
1252
  * @param {string} [options.note] - Optional note for the receiving agent
1253
1253
  * @param {string} [options.reasonCode] - Transfer reason code — e.g. 'wrong_department', 'customer_requested', 'out_of_scope', 'policy_never_bot', 'language', 'other'. Required when the caller's worker is a bot.
1254
1254
  * @param {string} [options.reason] - One-sentence transfer reason. Required when the caller's worker is a bot.
1255
+ * @param {number} [options.priorityAdjust] - Amount to add to (or, negative, subtract from) the task's priority on the new task created in the target queue.
1255
1256
  * @returns {Promise<Object>} { taskId, newTaskId }
1256
1257
  *
1257
1258
  * @example
@@ -1264,16 +1265,18 @@ export class TaskService {
1264
1265
  * });
1265
1266
  */
1266
1267
  async transfer(options = {}) {
1267
- const { taskId, target, note, reasonCode, reason } = options;
1268
+ const { taskId, target, note, reasonCode, reason, priorityAdjust } =
1269
+ options;
1268
1270
 
1269
1271
  this.sdk.validateParams(
1270
- { taskId, target, note, reasonCode, reason },
1272
+ { taskId, target, note, reasonCode, reason, priorityAdjust },
1271
1273
  {
1272
1274
  taskId: { type: 'string', required: true },
1273
1275
  target: { type: 'object', required: true },
1274
1276
  note: { type: 'string', required: false },
1275
1277
  reasonCode: { type: 'string', required: false },
1276
1278
  reason: { type: 'string', required: false },
1279
+ priorityAdjust: { type: 'number', required: false },
1277
1280
  },
1278
1281
  );
1279
1282
 
@@ -1281,6 +1284,8 @@ export class TaskService {
1281
1284
  if (note !== undefined) params.body.note = note;
1282
1285
  if (reasonCode !== undefined) params.body.reasonCode = reasonCode;
1283
1286
  if (reason !== undefined) params.body.reason = reason;
1287
+ if (priorityAdjust !== undefined)
1288
+ params.body.priorityAdjust = priorityAdjust;
1284
1289
 
1285
1290
  return await internalRequest(
1286
1291
  this.sdk,
@@ -1290,6 +1295,41 @@ export class TaskService {
1290
1295
  );
1291
1296
  }
1292
1297
 
1298
+ /**
1299
+ * Advisory preview of where a transfer would land right now — calls the
1300
+ * same resolver the real transfer uses, so a UI can show "sent to Queue
1301
+ * Y" before the transfer completes. Never guaranteed to land there under
1302
+ * load; the real transfer re-resolves at claim time.
1303
+ *
1304
+ * @param {string} taskId - The task ID to preview a transfer destination for (required)
1305
+ * @param {Object} options - Parameters
1306
+ * @param {string} options.queueId - Candidate destination queue ID (required)
1307
+ * @returns {Promise<Object>} Resolved destination, shaped by the same logic `transfer` itself uses for this queue/task type.
1308
+ *
1309
+ * @example
1310
+ * const preview = await sdk.taskRouter.task.resolveTransferDestination('task123', {
1311
+ * queueId: 'billingQueue1',
1312
+ * });
1313
+ */
1314
+ async resolveTransferDestination(taskId, options = {}) {
1315
+ const { queueId } = options;
1316
+
1317
+ this.sdk.validateParams(
1318
+ { taskId, queueId },
1319
+ {
1320
+ taskId: { type: 'string', required: true },
1321
+ queueId: { type: 'string', required: true },
1322
+ },
1323
+ );
1324
+
1325
+ return await internalRequest(
1326
+ this.sdk,
1327
+ `/taskRouter/tasks/${taskId}/resolveTransferDestination`,
1328
+ 'POST',
1329
+ { body: { queueId } },
1330
+ );
1331
+ }
1332
+
1293
1333
  /**
1294
1334
  * Get the voice transcript for a task, keyed by the media-manager
1295
1335
  * bridgeId (not sipCallId) so it works across requeue/transfer.