@unboundcx/sdk 4.13.145 → 4.13.146-security.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/README.md +7 -0
- package/base.js +74 -3
- package/index.js +7 -31
- package/lib/refreshInterceptor.js +127 -0
- package/package.json +2 -5
- package/services/layouts.js +4 -13
- package/services/licenses.js +330 -0
- package/services/login.js +21 -0
- package/services/messageTemplates.js +2 -109
- package/services/messaging/EmailTemplatesService.js +2 -10
- package/services/messaging/SmsService.js +3 -0
- package/services/messaging/SmsTemplatesService.js +125 -0
- package/services/messaging.js +2 -0
- package/services/oauth.js +159 -0
- package/services/objects.js +39 -12
- package/services/permissions.js +0 -21
- package/services/phoneNumbers.js +1037 -2
- package/services/recents.js +0 -16
- package/services/taskRouter/MetricsService.js +0 -3
- package/services/taskRouter/TaskRouterService.js +0 -2
- package/services/taskRouter/TaskService.js +10 -70
- package/services/voice.js +25 -47
- package/lib/journeyLayout.js +0 -132
- package/services/journeys/JourneyDraftService.js +0 -92
- package/services/journeys/JourneyGoalsService.js +0 -57
- package/services/journeys/JourneyMembersService.js +0 -246
- package/services/journeys/JourneyTypesService.js +0 -59
- package/services/journeys/JourneyWorklistService.js +0 -74
- package/services/journeys/JourneysService.js +0 -392
- package/services/operatorPanels.js +0 -226
- package/services/parking.js +0 -121
- package/services/phoneNumbers/carrier.js +0 -60
- package/services/phoneNumbers/cnam.js +0 -42
- package/services/phoneNumbers/index.js +0 -27
- package/services/phoneNumbers/order.js +0 -88
- package/services/phoneNumbers/porting-activity.js +0 -289
- package/services/phoneNumbers/porting-orders.js +0 -318
- package/services/phoneNumbers/search.js +0 -181
- package/services/phoneNumbers/update.js +0 -94
- package/services/schedules/SchedulesService.js +0 -232
- package/services/schedules/TimeOffService.js +0 -131
- package/services/skills.js +0 -207
- package/services/taskRouter/QueueService.js +0 -343
- package/services/voicemailDrops.js +0 -268
- package/services/workflowTemplates/WorkflowTemplatesService.js +0 -68
|
@@ -1,343 +0,0 @@
|
|
|
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
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get a queue's per-channel skill-tier routing steps
|
|
101
|
-
* (skill-proficiency-tiers-plan.md D2/§3.3). Step 0 (Expert only, full
|
|
102
|
-
* requirements) is implicit and never included in the returned list.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} queueId - The queue ID (required)
|
|
105
|
-
* @returns {Promise<Object>} result
|
|
106
|
-
* @returns {string} result.queueId
|
|
107
|
-
* @returns {Object} result.routingSteps - Keyed by channel ('phoneCall'|'chat'|'email'|'sms'),
|
|
108
|
-
* e.g. `{ phoneCall: { steps: [{afterSec, allowedTiers, ignoreOptionalSkills, dropRequiredSkillIds}], learningNeverAutoRoute } }`
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* const { routingSteps } = await sdk.taskRouter.queues.getRoutingSteps('queue123');
|
|
112
|
-
*/
|
|
113
|
-
async getRoutingSteps(queueId) {
|
|
114
|
-
this.sdk.validateParams(
|
|
115
|
-
{ queueId },
|
|
116
|
-
{ queueId: { type: 'string', required: true } },
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return await internalRequest(
|
|
120
|
-
this.sdk,
|
|
121
|
-
`/taskRouter/queues/${queueId}/routingSteps`,
|
|
122
|
-
'GET',
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Replace a queue's per-channel skill-tier routing steps. `afterSec`
|
|
128
|
-
* must be strictly increasing within each channel's `steps` list; the
|
|
129
|
-
* API validates this and rejects out-of-order steps.
|
|
130
|
-
*
|
|
131
|
-
* @param {string} queueId - The queue ID (required)
|
|
132
|
-
* @param {Object} routingSteps - Keyed by channel ('phoneCall'|'chat'|'email'|'sms')
|
|
133
|
-
* @param {Object[]} routingSteps[channel].steps - `[{afterSec, allowedTiers, ignoreOptionalSkills, dropRequiredSkillIds}]`
|
|
134
|
-
* @param {boolean} [routingSteps[channel].learningNeverAutoRoute] - Coach-only: never auto-route Learning-tier workers on this channel
|
|
135
|
-
* @returns {Promise<Object>} result
|
|
136
|
-
* @returns {string} result.queueId
|
|
137
|
-
* @returns {Object} result.routingSteps - The stored steps, as written (normalized)
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* await sdk.taskRouter.queues.setRoutingSteps('queue123', {
|
|
141
|
-
* phoneCall: {
|
|
142
|
-
* steps: [
|
|
143
|
-
* { afterSec: 30, allowedTiers: ['expert', 'proficient'], ignoreOptionalSkills: false, dropRequiredSkillIds: [] },
|
|
144
|
-
* { afterSec: 90, allowedTiers: ['expert', 'proficient', 'learning'], ignoreOptionalSkills: true, dropRequiredSkillIds: [] },
|
|
145
|
-
* ],
|
|
146
|
-
* learningNeverAutoRoute: false,
|
|
147
|
-
* },
|
|
148
|
-
* });
|
|
149
|
-
*/
|
|
150
|
-
async setRoutingSteps(queueId, routingSteps) {
|
|
151
|
-
this.sdk.validateParams(
|
|
152
|
-
{ queueId, routingSteps },
|
|
153
|
-
{
|
|
154
|
-
queueId: { type: 'string', required: true },
|
|
155
|
-
routingSteps: { type: 'object', required: true },
|
|
156
|
-
},
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
return await internalRequest(
|
|
160
|
-
this.sdk,
|
|
161
|
-
`/taskRouter/queues/${queueId}/routingSteps`,
|
|
162
|
-
'PUT',
|
|
163
|
-
{ body: { routingSteps } },
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* List a queue's alert rules (queueAlertRules table). Each rule fires
|
|
169
|
-
* when its trigger metric crosses `threshold` by `comparator` and
|
|
170
|
-
* stays there for `sustainSeconds` (proactive-alerts-plan.md §13/D1-D7).
|
|
171
|
-
*
|
|
172
|
-
* @param {string} queueId - The queue ID (required)
|
|
173
|
-
* @returns {Promise<Object>} result
|
|
174
|
-
* @returns {Object[]} result.alertRules - Rules for the queue
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* const { alertRules } = await sdk.taskRouter.queues.alerts.list('queue123');
|
|
178
|
-
*/
|
|
179
|
-
async alertsList(queueId) {
|
|
180
|
-
this.sdk.validateParams(
|
|
181
|
-
{ queueId },
|
|
182
|
-
{ queueId: { type: 'string', required: true } },
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
return await internalRequest(
|
|
186
|
-
this.sdk,
|
|
187
|
-
`/taskRouter/queues/${queueId}/alertRules`,
|
|
188
|
-
'GET',
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Create a new alert rule on a queue.
|
|
194
|
-
*
|
|
195
|
-
* @param {string} queueId - The queue ID (required)
|
|
196
|
-
* @param {Object} rule - The rule to create
|
|
197
|
-
* @param {string} rule.channel - 'phoneCall' | 'chat' | 'email' | 'sms' | 'fax' | 'other' | 'whatsApp' | 'rcs' | 'all'
|
|
198
|
-
* @param {string} rule.trigger - 'pendingTasks' | 'longestWait' | 'serviceLevel' | 'availableAgents' | 'abandonmentRate' | 'abandonCount' | 'occupancy' | 'overflowMaxWait' | 'overflowNoAgents' | 'overflowCapacity' | 'overflowClosed'
|
|
199
|
-
* @param {string} [rule.comparator] - 'gte' | 'lte' (defaults per trigger: serviceLevel/availableAgents -> lte, else gte)
|
|
200
|
-
* @param {number} rule.threshold
|
|
201
|
-
* @param {number} [rule.hysteresisValue]
|
|
202
|
-
* @param {number} [rule.windowMinutes] - Required 1-60 iff trigger is 'abandonCount'
|
|
203
|
-
* @param {number} [rule.sustainSeconds]
|
|
204
|
-
* @param {number} [rule.cooldownSeconds]
|
|
205
|
-
* @param {number} [rule.dailyCap]
|
|
206
|
-
* @param {string} [rule.scheduleId]
|
|
207
|
-
* @param {boolean} [rule.sendRecovery]
|
|
208
|
-
* @param {number} [rule.escalateAfterSeconds]
|
|
209
|
-
* @param {Object[]} rule.actions - `[{type:'email'|'sms'|'notification', userIds:[], teamIds:[]} | {type:'chat', channelId?, userIds?} | {type:'workflow', workflowId}]`
|
|
210
|
-
* @param {Object[]} [rule.escalateActions] - Same shape as `actions`
|
|
211
|
-
* @param {boolean} [rule.isEnabled]
|
|
212
|
-
* @returns {Promise<Object>} result
|
|
213
|
-
* @returns {Object} result.alertRule - The created rule
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* await sdk.taskRouter.queues.alerts.create('queue123', {
|
|
217
|
-
* channel: 'phoneCall',
|
|
218
|
-
* trigger: 'longestWait',
|
|
219
|
-
* threshold: 60,
|
|
220
|
-
* sustainSeconds: 60,
|
|
221
|
-
* actions: [{ type: 'notification', userIds: ['user1'], teamIds: [] }],
|
|
222
|
-
* });
|
|
223
|
-
*/
|
|
224
|
-
async alertsCreate(queueId, rule) {
|
|
225
|
-
this.sdk.validateParams(
|
|
226
|
-
{ queueId, rule },
|
|
227
|
-
{
|
|
228
|
-
queueId: { type: 'string', required: true },
|
|
229
|
-
rule: { type: 'object', required: true },
|
|
230
|
-
},
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
return await internalRequest(
|
|
234
|
-
this.sdk,
|
|
235
|
-
`/taskRouter/queues/${queueId}/alertRules`,
|
|
236
|
-
'POST',
|
|
237
|
-
{ body: rule },
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Patch an existing alert rule.
|
|
243
|
-
*
|
|
244
|
-
* @param {string} queueId - The queue ID (required)
|
|
245
|
-
* @param {string} ruleId - The alert rule ID (required)
|
|
246
|
-
* @param {Object} patch - Partial fields to update (same shape as `create`'s `rule`)
|
|
247
|
-
* @returns {Promise<Object>} result
|
|
248
|
-
* @returns {Object} result.alertRule - The updated rule
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* await sdk.taskRouter.queues.alerts.update('queue123', 'rule1', { threshold: 90 });
|
|
252
|
-
*/
|
|
253
|
-
async alertsUpdate(queueId, ruleId, patch) {
|
|
254
|
-
this.sdk.validateParams(
|
|
255
|
-
{ queueId, ruleId, patch },
|
|
256
|
-
{
|
|
257
|
-
queueId: { type: 'string', required: true },
|
|
258
|
-
ruleId: { type: 'string', required: true },
|
|
259
|
-
patch: { type: 'object', required: true },
|
|
260
|
-
},
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
return await internalRequest(
|
|
264
|
-
this.sdk,
|
|
265
|
-
`/taskRouter/queues/${queueId}/alertRules/${ruleId}`,
|
|
266
|
-
'PATCH',
|
|
267
|
-
{ body: patch },
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Delete an alert rule.
|
|
273
|
-
*
|
|
274
|
-
* @param {string} queueId - The queue ID (required)
|
|
275
|
-
* @param {string} ruleId - The alert rule ID (required)
|
|
276
|
-
* @returns {Promise<Object>} result
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* await sdk.taskRouter.queues.alerts.remove('queue123', 'rule1');
|
|
280
|
-
*/
|
|
281
|
-
async alertsRemove(queueId, ruleId) {
|
|
282
|
-
this.sdk.validateParams(
|
|
283
|
-
{ queueId, ruleId },
|
|
284
|
-
{
|
|
285
|
-
queueId: { type: 'string', required: true },
|
|
286
|
-
ruleId: { type: 'string', required: true },
|
|
287
|
-
},
|
|
288
|
-
);
|
|
289
|
-
|
|
290
|
-
return await internalRequest(
|
|
291
|
-
this.sdk,
|
|
292
|
-
`/taskRouter/queues/${queueId}/alertRules/${ruleId}`,
|
|
293
|
-
'DELETE',
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* List a queue's alert event history (queueAlertEvents table): fired,
|
|
299
|
-
* escalated, cleared, and suppressed events.
|
|
300
|
-
*
|
|
301
|
-
* @param {string} queueId - The queue ID (required)
|
|
302
|
-
* @param {Object} [options]
|
|
303
|
-
* @param {number} [options.limit] - Max rows to return (default 50)
|
|
304
|
-
* @param {string} [options.before] - ISO timestamp cursor; only events before this time
|
|
305
|
-
* @returns {Promise<Object>} result
|
|
306
|
-
* @returns {Object[]} result.alertEvents
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* const { alertEvents } = await sdk.taskRouter.queues.alerts.history('queue123', { limit: 20 });
|
|
310
|
-
*/
|
|
311
|
-
async alertsHistory(queueId, { limit, before } = {}) {
|
|
312
|
-
this.sdk.validateParams(
|
|
313
|
-
{ queueId },
|
|
314
|
-
{ queueId: { type: 'string', required: true } },
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
const query = {};
|
|
318
|
-
if (limit !== undefined) query.limit = limit;
|
|
319
|
-
if (before !== undefined) query.before = before;
|
|
320
|
-
|
|
321
|
-
return await internalRequest(
|
|
322
|
-
this.sdk,
|
|
323
|
-
`/taskRouter/queues/${queueId}/alertEvents`,
|
|
324
|
-
'GET',
|
|
325
|
-
{ query },
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Exposes alert-rule methods as `sdk.taskRouter.queues.alerts.*` while
|
|
331
|
-
// keeping them implemented as plain methods on QueueService above (so they
|
|
332
|
-
// share `this.sdk`/validateParams without a second internalRequest wiring).
|
|
333
|
-
Object.defineProperty(QueueService.prototype, 'alerts', {
|
|
334
|
-
get() {
|
|
335
|
-
return {
|
|
336
|
-
list: (queueId) => this.alertsList(queueId),
|
|
337
|
-
create: (queueId, rule) => this.alertsCreate(queueId, rule),
|
|
338
|
-
update: (queueId, ruleId, patch) => this.alertsUpdate(queueId, ruleId, patch),
|
|
339
|
-
remove: (queueId, ruleId) => this.alertsRemove(queueId, ruleId),
|
|
340
|
-
history: (queueId, options) => this.alertsHistory(queueId, options),
|
|
341
|
-
};
|
|
342
|
-
},
|
|
343
|
-
});
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { internalRequest } from '../base.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Admin-managed voicemail drop types (voicemail-drop-plan.md §5). A type is
|
|
5
|
-
* the category a message belongs to (e.g. "Not home", "Left message");
|
|
6
|
-
* queues/journeys preselect by type.
|
|
7
|
-
*/
|
|
8
|
-
export class VoicemailDropTypesService {
|
|
9
|
-
constructor(sdk) {
|
|
10
|
-
this.sdk = sdk;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* List voicemail drop types.
|
|
15
|
-
* @param {Object} [params]
|
|
16
|
-
* @param {boolean} [params.includeInactive]
|
|
17
|
-
* @returns {Promise<{results: Object[]}>}
|
|
18
|
-
*/
|
|
19
|
-
async list(params = {}) {
|
|
20
|
-
return internalRequest(this.sdk, '/voicemailDrops/types', 'GET', { query: { ...params } });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get a single voicemail drop type.
|
|
25
|
-
* @param {string} id
|
|
26
|
-
* @returns {Promise<Object>}
|
|
27
|
-
*/
|
|
28
|
-
async get(id) {
|
|
29
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
30
|
-
return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'GET');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Create a voicemail drop type.
|
|
35
|
-
* @param {Object} options
|
|
36
|
-
* @param {string} options.name
|
|
37
|
-
* @param {string} [options.description]
|
|
38
|
-
* @param {boolean} [options.active]
|
|
39
|
-
* @returns {Promise<Object>}
|
|
40
|
-
*/
|
|
41
|
-
async create(options = {}) {
|
|
42
|
-
this.sdk.validateParams(
|
|
43
|
-
{ name: options.name },
|
|
44
|
-
{ name: { type: 'string', required: true } },
|
|
45
|
-
);
|
|
46
|
-
return internalRequest(this.sdk, '/voicemailDrops/types', 'POST', {
|
|
47
|
-
body: { ...options },
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Update a voicemail drop type.
|
|
53
|
-
* @param {string} id
|
|
54
|
-
* @param {Object} options
|
|
55
|
-
* @returns {Promise<Object>}
|
|
56
|
-
*/
|
|
57
|
-
async update(id, options = {}) {
|
|
58
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
59
|
-
return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'PUT', {
|
|
60
|
-
body: { ...options },
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Remove (soft-delete) a voicemail drop type.
|
|
66
|
-
* @param {string} id
|
|
67
|
-
* @returns {Promise<{id: string, deleted: boolean}>}
|
|
68
|
-
*/
|
|
69
|
-
async remove(id) {
|
|
70
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
71
|
-
return internalRequest(this.sdk, `/voicemailDrops/types/${id}`, 'DELETE');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Set which users/groups can see a voicemail drop type.
|
|
76
|
-
* @param {string} id
|
|
77
|
-
* @param {Object} options
|
|
78
|
-
* @param {string[]} [options.userIds]
|
|
79
|
-
* @param {string[]} [options.groupIds]
|
|
80
|
-
* @returns {Promise<Object>}
|
|
81
|
-
*/
|
|
82
|
-
async setAccess(id, { userIds, groupIds } = {}) {
|
|
83
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
84
|
-
return internalRequest(this.sdk, `/voicemailDrops/types/${id}/access`, 'PUT', {
|
|
85
|
-
body: { userIds, groupIds },
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* List users who have recorded a voicemail drop message for this type.
|
|
91
|
-
* @param {string} id
|
|
92
|
-
* @returns {Promise<{results: Object[]}>}
|
|
93
|
-
*/
|
|
94
|
-
async recordings(id) {
|
|
95
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
96
|
-
return internalRequest(this.sdk, `/voicemailDrops/types/${id}/recordings`, 'GET');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Build a multipart body for a single audio file + scalar fields. Mirrors
|
|
101
|
-
// storage.js's node/browser FormData construction so this works in both
|
|
102
|
-
// environments without depending on StorageService internals.
|
|
103
|
-
function buildMultipart(file, fields) {
|
|
104
|
-
const isNode = typeof window === 'undefined';
|
|
105
|
-
|
|
106
|
-
if (!isNode) {
|
|
107
|
-
const formData = new FormData();
|
|
108
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(file)) {
|
|
109
|
-
formData.append('file', new Blob([file]), fields.fileName || 'file');
|
|
110
|
-
} else if (typeof File !== 'undefined' && file instanceof File) {
|
|
111
|
-
formData.append('file', file);
|
|
112
|
-
} else {
|
|
113
|
-
throw new Error('In browser environment, file must be a Buffer or File object');
|
|
114
|
-
}
|
|
115
|
-
for (const [name, value] of Object.entries(fields)) {
|
|
116
|
-
if (value === undefined || value === null) continue;
|
|
117
|
-
formData.append(name, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
118
|
-
}
|
|
119
|
-
return { body: formData, headers: {} };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Node: build the multipart buffer by hand.
|
|
123
|
-
const boundary = `----formdata-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
124
|
-
const CRLF = '\r\n';
|
|
125
|
-
const fileName = fields.fileName || 'file';
|
|
126
|
-
const parts = [];
|
|
127
|
-
|
|
128
|
-
parts.push(Buffer.from(
|
|
129
|
-
`--${boundary}${CRLF}Content-Disposition: form-data; name="file"; filename="${fileName}"${CRLF}` +
|
|
130
|
-
`Content-Type: application/octet-stream${CRLF}${CRLF}`,
|
|
131
|
-
'utf8',
|
|
132
|
-
));
|
|
133
|
-
parts.push(Buffer.isBuffer(file) ? file : Buffer.from(file));
|
|
134
|
-
parts.push(Buffer.from(CRLF, 'utf8'));
|
|
135
|
-
|
|
136
|
-
for (const [name, value] of Object.entries(fields)) {
|
|
137
|
-
if (value === undefined || value === null) continue;
|
|
138
|
-
const v = typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
139
|
-
parts.push(Buffer.from(
|
|
140
|
-
`--${boundary}${CRLF}Content-Disposition: form-data; name="${name}"${CRLF}${CRLF}${v}${CRLF}`,
|
|
141
|
-
'utf8',
|
|
142
|
-
));
|
|
143
|
-
}
|
|
144
|
-
parts.push(Buffer.from(`--${boundary}--${CRLF}`, 'utf8'));
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
body: Buffer.concat(parts),
|
|
148
|
-
headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Per-user voicemail drop messages (voicemail-drop-plan.md §5, §6). A
|
|
154
|
-
* message is either an uploaded/recorded file or TTS-generated, scoped to a
|
|
155
|
-
* type (or personal/untyped), with one default per type.
|
|
156
|
-
*/
|
|
157
|
-
export class VoicemailDropsService {
|
|
158
|
-
constructor(sdk) {
|
|
159
|
-
this.sdk = sdk;
|
|
160
|
-
this.types = new VoicemailDropTypesService(sdk);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* List the current user's own voicemail drop messages plus all active
|
|
165
|
-
* types, with `hasMessage` flagged per type.
|
|
166
|
-
* @returns {Promise<{messages: Object[], types: Object[]}>}
|
|
167
|
-
*/
|
|
168
|
-
async listMine() {
|
|
169
|
-
return internalRequest(this.sdk, '/voicemailDrops/mine', 'GET');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Create a voicemail drop message — either an uploaded/recorded audio
|
|
174
|
-
* file (multipart, works in browser and Node) or a TTS message (plain
|
|
175
|
-
* JSON, no file needed).
|
|
176
|
-
* @param {Object} options
|
|
177
|
-
* @param {Object} [options.file] - Buffer or browser File; omit for TTS
|
|
178
|
-
* @param {string} options.name
|
|
179
|
-
* @param {string} [options.typeId]
|
|
180
|
-
* @param {string} [options.ttsText]
|
|
181
|
-
* @param {string} [options.ttsVoice]
|
|
182
|
-
* @param {boolean} [options.isDefault]
|
|
183
|
-
* @returns {Promise<Object>} the created row (status 'processing' until transcode completes)
|
|
184
|
-
*/
|
|
185
|
-
async create({ file, name, typeId, ttsText, ttsVoice, isDefault, fileName } = {}) {
|
|
186
|
-
this.sdk.validateParams(
|
|
187
|
-
{ name, typeId, ttsText, ttsVoice, isDefault, fileName },
|
|
188
|
-
{
|
|
189
|
-
name: { type: 'string', required: true },
|
|
190
|
-
typeId: { type: 'string', required: false },
|
|
191
|
-
ttsText: { type: 'string', required: false },
|
|
192
|
-
ttsVoice: { type: 'string', required: false },
|
|
193
|
-
isDefault: { type: 'boolean', required: false },
|
|
194
|
-
fileName: { type: 'string', required: false },
|
|
195
|
-
},
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
if (!file && !ttsText) {
|
|
199
|
-
throw new Error('create requires either file or ttsText');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (file) {
|
|
203
|
-
const { body, headers } = buildMultipart(file, {
|
|
204
|
-
fileName,
|
|
205
|
-
name,
|
|
206
|
-
typeId,
|
|
207
|
-
isDefault,
|
|
208
|
-
});
|
|
209
|
-
return internalRequest(
|
|
210
|
-
this.sdk,
|
|
211
|
-
'/voicemailDrops',
|
|
212
|
-
'POST',
|
|
213
|
-
{ body, headers },
|
|
214
|
-
true,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return internalRequest(this.sdk, '/voicemailDrops', 'POST', {
|
|
219
|
-
body: { name, typeId, ttsText, ttsVoice, isDefault },
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Update a voicemail drop message (rename, change type, set default).
|
|
225
|
-
* @param {string} id
|
|
226
|
-
* @param {Object} options
|
|
227
|
-
* @returns {Promise<Object>}
|
|
228
|
-
*/
|
|
229
|
-
async update(id, options = {}) {
|
|
230
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
231
|
-
return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'PUT', {
|
|
232
|
-
body: { ...options },
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Remove (soft-delete) a voicemail drop message.
|
|
238
|
-
* @param {string} id
|
|
239
|
-
* @returns {Promise<{id: string, deleted: boolean}>}
|
|
240
|
-
*/
|
|
241
|
-
async remove(id) {
|
|
242
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
243
|
-
return internalRequest(this.sdk, `/voicemailDrops/${id}`, 'DELETE');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Get a short-lived signed preview URL for a message's audio.
|
|
248
|
-
* @param {string} id
|
|
249
|
-
* @returns {Promise<{url: string}>}
|
|
250
|
-
*/
|
|
251
|
-
async preview(id) {
|
|
252
|
-
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
253
|
-
return internalRequest(this.sdk, `/voicemailDrops/${id}/preview`, 'POST');
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Admin: a user's message coverage per type.
|
|
258
|
-
* @param {string} userId
|
|
259
|
-
* @returns {Promise<{messages: Object[], types: Object[]}>}
|
|
260
|
-
*/
|
|
261
|
-
async forUser(userId) {
|
|
262
|
-
this.sdk.validateParams(
|
|
263
|
-
{ userId },
|
|
264
|
-
{ userId: { type: 'string', required: true } },
|
|
265
|
-
);
|
|
266
|
-
return internalRequest(this.sdk, `/voicemailDrops/users/${userId}`, 'GET');
|
|
267
|
-
}
|
|
268
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { internalRequest } from '../../base.js';
|
|
2
|
-
|
|
3
|
-
function pickDefined(fields) {
|
|
4
|
-
const body = {};
|
|
5
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
6
|
-
if (value !== undefined) body[key] = value;
|
|
7
|
-
}
|
|
8
|
-
return body;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Account-visible workflow template library -- `sdk.workflowTemplates.*`
|
|
13
|
-
* (journeys-plan.md §7.7, P4 templates area). `visibility`/access is
|
|
14
|
-
* service-only (accountId IS NULL for platform starters, or = caller);
|
|
15
|
-
* platform authoring (upsert) is INTERNAL-only (`/internal/journeys/
|
|
16
|
-
* templates`) with no customer-facing SDK surface -- there is no first-party
|
|
17
|
-
* INTERNAL SDK extension surface in this package to hang it on, so it is
|
|
18
|
-
* intentionally not wrapped here.
|
|
19
|
-
*
|
|
20
|
-
* @see app1-api src/services/journeys/routes.js (`/journeys/templates*`)
|
|
21
|
-
*/
|
|
22
|
-
export class WorkflowTemplatesService {
|
|
23
|
-
constructor(sdk) {
|
|
24
|
-
this.sdk = sdk;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {Object} [params]
|
|
29
|
-
* @param {string} [params.workflowType] - defaults to 'journey' on the API
|
|
30
|
-
* @returns {Promise<Object[]>} Templates visible to the caller's account
|
|
31
|
-
*/
|
|
32
|
-
async list({ workflowType } = {}) {
|
|
33
|
-
return await internalRequest(
|
|
34
|
-
this.sdk,
|
|
35
|
-
'/journeys/templates',
|
|
36
|
-
'GET',
|
|
37
|
-
{ query: pickDefined({ workflowType }) },
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Installs a template into the caller's account as a new journey +
|
|
43
|
-
* workflow + draft version (+ journeyDoc when present) in one
|
|
44
|
-
* transaction, validated again at install time.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} templateId
|
|
47
|
-
* @param {Object} params
|
|
48
|
-
* @param {string} params.journeyTypeId
|
|
49
|
-
* @param {Object} [params.answers] - answers to the template's `requirements`
|
|
50
|
-
* @param {string} [params.name] - override the template's default name
|
|
51
|
-
* @returns {Promise<Object>} New journey + workflow + draft version
|
|
52
|
-
*/
|
|
53
|
-
async install(templateId, { journeyTypeId, answers, name } = {}) {
|
|
54
|
-
this.sdk.validateParams(
|
|
55
|
-
{ templateId, journeyTypeId },
|
|
56
|
-
{
|
|
57
|
-
templateId: { type: 'string', required: true },
|
|
58
|
-
journeyTypeId: { type: 'string', required: true },
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
return await internalRequest(
|
|
62
|
-
this.sdk,
|
|
63
|
-
`/journeys/templates/${templateId}/install`,
|
|
64
|
-
'POST',
|
|
65
|
-
{ body: pickDefined({ journeyTypeId, answers, name }) },
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|