@unboundcx/sdk 4.13.129 → 4.13.131

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.129",
3
+ "version": "4.13.131",
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,57 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ /**
4
+ * `sdk.journeys.goals.*` -- journeyGoals generic-object CRUD (no `get`;
5
+ * goals are listed/edited inline on the journey, matching the plan's CRUD
6
+ * surface for this object).
7
+ */
8
+ export class JourneyGoalsService {
9
+ constructor(sdk) {
10
+ this.sdk = sdk;
11
+ }
12
+
13
+ /**
14
+ * @param {Object} [opts] - sdk.objects.query opts; pass `where: { journeyId }` to scope
15
+ * @returns {Promise<Object>} Query result
16
+ */
17
+ async list(opts = {}) {
18
+ return await this.sdk.objects.query({ object: 'journeyGoals', ...opts });
19
+ }
20
+
21
+ /**
22
+ * @param {Object} body
23
+ * @param {string} body.journeyId
24
+ * @param {string} body.goalType
25
+ * @returns {Promise<Object>} Created journeyGoal
26
+ */
27
+ async create(body) {
28
+ this.sdk.validateParams(
29
+ { journeyId: body?.journeyId, goalType: body?.goalType },
30
+ {
31
+ journeyId: { type: 'string', required: true },
32
+ goalType: { type: 'string', required: true },
33
+ },
34
+ );
35
+ return await this.sdk.objects.create({ object: 'journeyGoals', body });
36
+ }
37
+
38
+ async update(id, update) {
39
+ this.sdk.validateParams(
40
+ { id, update },
41
+ {
42
+ id: { type: 'string', required: true },
43
+ update: { type: 'object', required: true },
44
+ },
45
+ );
46
+ return await this.sdk.objects.updateById({
47
+ object: 'journeyGoals',
48
+ id,
49
+ update,
50
+ });
51
+ }
52
+
53
+ async remove(id) {
54
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
55
+ return await this.sdk.objects.deleteById({ object: 'journeyGoals', id });
56
+ }
57
+ }
@@ -35,6 +35,8 @@ export class JourneyMembersService {
35
35
  * @param {string} [opts.ownerUserId]
36
36
  * @param {string} [opts.statusReason]
37
37
  * @param {string} [opts.search]
38
+ * @param {boolean} [opts.isTest] true = test-run members only, false = exclude them; omit = no filter
39
+ * @param {'company'} [opts.groupBy] server-grouped mode: { groups: [{ companyId, companyName, counts, members }] }
38
40
  * @returns {Promise<Object>} Paged member rows
39
41
  */
40
42
  async list(journeyId, opts = {}) {
@@ -55,6 +57,29 @@ export class JourneyMembersService {
55
57
  );
56
58
  }
57
59
 
60
+ /**
61
+ * URL for the CSV export of the members grid (P6) — same filter / sort
62
+ * params as `list`. The browser downloads it directly (cookie auth); Node
63
+ * callers fetch it with their own token.
64
+ *
65
+ * @param {string} journeyId
66
+ * @param {Object} [opts] same keys as `list` (status, stepKey, ownerUserId, statusReason, search, sort, sortDir)
67
+ * @returns {string} absolute URL
68
+ */
69
+ exportCsvUrl(journeyId, opts = {}) {
70
+ this.sdk.validateParams(
71
+ { journeyId },
72
+ { journeyId: { type: 'string', required: true } },
73
+ );
74
+ const { status, ...rest } = opts;
75
+ const query = pickDefined({
76
+ ...rest,
77
+ status: Array.isArray(status) ? status.join(',') : status,
78
+ });
79
+ const qs = new URLSearchParams(query).toString();
80
+ return `${this.sdk.baseURL}/journeys/${journeyId}/members/export.csv${qs ? `?${qs}` : ''}`;
81
+ }
82
+
58
83
  /**
59
84
  * @param {string} journeyId
60
85
  * @param {string} memberId
@@ -0,0 +1,53 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ /**
4
+ * `sdk.journeys.types.*` -- journeyTypes generic-object CRUD. `queueId`
5
+ * stays empty until P5.
6
+ */
7
+ export class JourneyTypesService {
8
+ constructor(sdk) {
9
+ this.sdk = sdk;
10
+ }
11
+
12
+ async list(opts = {}) {
13
+ return await this.sdk.objects.query({ object: 'journeyTypes', ...opts });
14
+ }
15
+
16
+ async get(id) {
17
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
18
+ return await this.sdk.objects.byId({ id });
19
+ }
20
+
21
+ /**
22
+ * @param {Object} body
23
+ * @param {string} body.name
24
+ * @returns {Promise<Object>} Created journeyType
25
+ */
26
+ async create(body) {
27
+ this.sdk.validateParams(
28
+ { name: body?.name },
29
+ { name: { type: 'string', required: true } },
30
+ );
31
+ return await this.sdk.objects.create({ object: 'journeyTypes', body });
32
+ }
33
+
34
+ async update(id, update) {
35
+ this.sdk.validateParams(
36
+ { id, update },
37
+ {
38
+ id: { type: 'string', required: true },
39
+ update: { type: 'object', required: true },
40
+ },
41
+ );
42
+ return await this.sdk.objects.updateById({
43
+ object: 'journeyTypes',
44
+ id,
45
+ update,
46
+ });
47
+ }
48
+
49
+ async remove(id) {
50
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
51
+ return await this.sdk.objects.deleteById({ object: 'journeyTypes', id });
52
+ }
53
+ }
@@ -60,6 +60,7 @@ export class JourneyWorklistService {
60
60
  * @param {Object} [filter]
61
61
  * @param {string} [filter.stepType]
62
62
  * @param {string} [filter.journeyId]
63
+ * @param {string} [filter.taskId] take this exact task (validated server-side: worklist, pending, owner-or-pool)
63
64
  * @returns {Promise<{data: JourneyWorklistTask|null}>} null when nothing is due
64
65
  */
65
66
  async takeNext(filter = {}) {
@@ -2,6 +2,8 @@ import { internalRequest } from '../../base.js';
2
2
  import { JourneyMembersService } from './JourneyMembersService.js';
3
3
  import { JourneyDraftService } from './JourneyDraftService.js';
4
4
  import { JourneyWorklistService } from './JourneyWorklistService.js';
5
+ import { JourneyTypesService } from './JourneyTypesService.js';
6
+ import { JourneyGoalsService } from './JourneyGoalsService.js';
5
7
 
6
8
  function pickDefined(fields) {
7
9
  const body = {};
@@ -140,6 +142,123 @@ export class JourneysService {
140
142
  );
141
143
  }
142
144
 
145
+ /**
146
+ * Diff of the current published journeyDoc vs the draft, by stepKey (P7).
147
+ *
148
+ * @param {string} id
149
+ * @returns {Promise<Object>} { oldVersionId, newVersionId, added, removed, changed }
150
+ */
151
+ async publishDiff(id) {
152
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
153
+ return await internalRequest(
154
+ this.sdk,
155
+ `/journeys/${id}/publish-diff`,
156
+ 'GET',
157
+ {},
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Publish the draft (runs publish-check; blocking items fail). Pass
163
+ * `{mode:'migrate', mapping}` to move open members on the old version to
164
+ * mapped landing steps at their next safe point (journeys-plan.md §7.5);
165
+ * omit for a plain publish (members stay on their version). Requires
166
+ * salesEnabled.
167
+ *
168
+ * @param {string} id
169
+ * @param {Object} [opts]
170
+ * @param {'migrate'|'leave'} [opts.mode]
171
+ * @param {Object<string,string>} [opts.mapping] removed stepKey -> landing stepKey | 'leave'
172
+ * @returns {Promise<Object>} { versionId, oldVersionId, migrationPlan }
173
+ */
174
+ async publish(id, { mode, mapping } = {}) {
175
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
176
+ return await internalRequest(this.sdk, `/journeys/${id}/publish`, 'POST', {
177
+ body: { migrate: pickDefined({ mode, mapping }) },
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Per-step funnel (journeys-plan.md §9, P6): entered / outcome split /
183
+ * conversions from journeyMemberEvents. Test members are excluded.
184
+ *
185
+ * @param {string} journeyId
186
+ * @returns {Promise<Object>} { steps: [{ stepKey, type, title, entered, outcomes, conversions }] }
187
+ */
188
+ async funnel(journeyId) {
189
+ this.sdk.validateParams(
190
+ { journeyId },
191
+ { journeyId: { type: 'string', required: true } },
192
+ );
193
+ return await internalRequest(
194
+ this.sdk,
195
+ `/journeys/${journeyId}/funnel`,
196
+ 'GET',
197
+ {},
198
+ );
199
+ }
200
+
201
+ /**
202
+ * Journey-level metrics (P6): enrolled, active, needsAttention, repliedPct,
203
+ * convertedPct, bounced, optedOut, timeToConvertMedianSeconds, byStatus.
204
+ *
205
+ * @param {string} journeyId
206
+ * @returns {Promise<Object>}
207
+ */
208
+ async metrics(journeyId) {
209
+ this.sdk.validateParams(
210
+ { journeyId },
211
+ { journeyId: { type: 'string', required: true } },
212
+ );
213
+ return await internalRequest(
214
+ this.sdk,
215
+ `/journeys/${journeyId}/metrics`,
216
+ 'GET',
217
+ {},
218
+ );
219
+ }
220
+
221
+ /**
222
+ * Journey-wide activity feed (P6): journeyMemberEvents, newest first.
223
+ *
224
+ * @param {string} journeyId
225
+ * @param {Object} [opts]
226
+ * @param {string} [opts.stepKey]
227
+ * @param {string} [opts.memberId]
228
+ * @param {number} [opts.page]
229
+ * @param {number} [opts.pageSize]
230
+ * @returns {Promise<Object>} { rows, total }
231
+ */
232
+ async events(journeyId, opts = {}) {
233
+ this.sdk.validateParams(
234
+ { journeyId },
235
+ { journeyId: { type: 'string', required: true } },
236
+ );
237
+ return await internalRequest(
238
+ this.sdk,
239
+ `/journeys/${journeyId}/events`,
240
+ 'GET',
241
+ { query: pickDefined(opts) },
242
+ );
243
+ }
244
+
245
+ /**
246
+ * Rep metrics (P6): per owner — due, overdue, doneOnTime,
247
+ * timeToActionMedianSeconds — from touch tasks. Requires salesEnabled.
248
+ *
249
+ * @param {Object} [opts]
250
+ * @param {string} [opts.journeyTypeId]
251
+ * @param {string} [opts.journeyId]
252
+ * @param {string} [opts.from] ISO date-time
253
+ * @param {string} [opts.to] ISO date-time
254
+ * @returns {Promise<Object>} { reps: [{ userId, due, overdue, doneOnTime, timeToActionMedianSeconds }] }
255
+ */
256
+ async repsMetrics(opts = {}) {
257
+ return await internalRequest(this.sdk, '/journeys/reps/metrics', 'GET', {
258
+ query: pickDefined(opts),
259
+ });
260
+ }
261
+
143
262
  /**
144
263
  * No-send dry run: per step, the resolved channel (override -> primary),
145
264
  * rendered message, and landing date for a given person (journeys-plan.md
@@ -230,114 +349,6 @@ export class JourneysService {
230
349
  }
231
350
  }
232
351
 
233
- /**
234
- * `sdk.journeys.types.*` -- journeyTypes generic-object CRUD. `queueId`
235
- * stays empty until P5.
236
- */
237
- class JourneyTypesService {
238
- constructor(sdk) {
239
- this.sdk = sdk;
240
- }
241
-
242
- async list(opts = {}) {
243
- return await this.sdk.objects.query({ object: 'journeyTypes', ...opts });
244
- }
245
-
246
- async get(id) {
247
- this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
248
- return await this.sdk.objects.byId({ id });
249
- }
250
-
251
- /**
252
- * @param {Object} body
253
- * @param {string} body.name
254
- * @returns {Promise<Object>} Created journeyType
255
- */
256
- async create(body) {
257
- this.sdk.validateParams(
258
- { name: body?.name },
259
- { name: { type: 'string', required: true } },
260
- );
261
- return await this.sdk.objects.create({ object: 'journeyTypes', body });
262
- }
263
-
264
- async update(id, update) {
265
- this.sdk.validateParams(
266
- { id, update },
267
- {
268
- id: { type: 'string', required: true },
269
- update: { type: 'object', required: true },
270
- },
271
- );
272
- return await this.sdk.objects.updateById({
273
- object: 'journeyTypes',
274
- id,
275
- update,
276
- });
277
- }
278
-
279
- async remove(id) {
280
- this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
281
- return await this.sdk.objects.deleteById({ object: 'journeyTypes', id });
282
- }
283
- }
284
-
285
- /**
286
- * `sdk.journeys.goals.*` -- journeyGoals generic-object CRUD (no `get`;
287
- * goals are listed/edited inline on the journey, matching the plan's CRUD
288
- * surface for this object).
289
- */
290
- class JourneyGoalsService {
291
- constructor(sdk) {
292
- this.sdk = sdk;
293
- }
294
-
295
- /**
296
- * @param {Object} [opts] - sdk.objects.query opts; pass `where: { journeyId }` to scope
297
- * @returns {Promise<Object>} Query result
298
- */
299
- async list(opts = {}) {
300
- return await this.sdk.objects.query({ object: 'journeyGoals', ...opts });
301
- }
302
-
303
- /**
304
- * @param {Object} body
305
- * @param {string} body.journeyId
306
- * @param {string} body.goalType
307
- * @returns {Promise<Object>} Created journeyGoal
308
- */
309
- async create(body) {
310
- this.sdk.validateParams(
311
- { journeyId: body?.journeyId, goalType: body?.goalType },
312
- {
313
- journeyId: { type: 'string', required: true },
314
- goalType: { type: 'string', required: true },
315
- },
316
- );
317
- return await this.sdk.objects.create({ object: 'journeyGoals', body });
318
- }
319
-
320
- async update(id, update) {
321
- this.sdk.validateParams(
322
- { id, update },
323
- {
324
- id: { type: 'string', required: true },
325
- update: { type: 'object', required: true },
326
- },
327
- );
328
- return await this.sdk.objects.updateById({
329
- object: 'journeyGoals',
330
- id,
331
- update,
332
- });
333
- }
334
-
335
- async remove(id) {
336
- this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
337
- return await this.sdk.objects.deleteById({ object: 'journeyGoals', id });
338
- }
339
- }
340
-
341
352
  export {
342
353
  JourneyTypesService,
343
354
  JourneyGoalsService,
@@ -60,6 +60,9 @@ export class MetricsService {
60
60
  * limit: 50
61
61
  * });
62
62
  * console.log(queueMetrics.metrics.queue.avgWaitTime); // 45.3
63
+ * // Sales queues (queueType='sales') additionally carry metrics.sales:
64
+ * // { dueNow, overdue, takenOnTimePct, timeToActionMedianSeconds,
65
+ * // touchesCompletedToday, conversionsToday } (omitted for other queues)
63
66
  *
64
67
  * @example
65
68
  * // Get worker metrics for last hour