@unboundcx/sdk 4.13.122 → 4.13.123

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
@@ -24,6 +24,7 @@ import { SipEndpointsService } from './services/sipEndpoints.js';
24
24
  import { RingGroupsService } from './services/ringGroups.js';
25
25
  import { LineGroupsService } from './services/lineGroups.js';
26
26
  import { SchedulesService } from './services/schedules/SchedulesService.js';
27
+ import { JourneysService } from './services/journeys/JourneysService.js';
27
28
  import { EmergencyService } from './services/emergency.js';
28
29
  import { WebchatService } from './services/webchat.js';
29
30
  import { CobrowseService } from './services/cobrowse.js';
@@ -127,6 +128,7 @@ class UnboundSDK extends BaseSDK {
127
128
  this.ringGroups = new RingGroupsService(this);
128
129
  this.lineGroups = new LineGroupsService(this);
129
130
  this.schedules = new SchedulesService(this);
131
+ this.journeys = new JourneysService(this);
130
132
  this.emergency = new EmergencyService(this);
131
133
  this.webchat = new WebchatService(this);
132
134
  this.cobrowse = new CobrowseService(this);
@@ -332,6 +334,8 @@ export { RingGroupsService } from './services/ringGroups.js';
332
334
  export { LineGroupsService } from './services/lineGroups.js';
333
335
  export { SchedulesService } from './services/schedules/SchedulesService.js';
334
336
  export { TimeOffService } from './services/schedules/TimeOffService.js';
337
+ export { JourneysService } from './services/journeys/JourneysService.js';
338
+ export { JourneyMembersService } from './services/journeys/JourneyMembersService.js';
335
339
  export { EmergencyService } from './services/emergency.js';
336
340
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
337
341
  export { CobrowseService, CobrowseVisitorService } from './services/cobrowse.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.122",
3
+ "version": "4.13.123",
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,189 @@
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
+ * Journey member surface -- `sdk.journeys.members.*`. Custom non-CRUD
13
+ * endpoints (member grid, enrol, bulk actions, fix, events) mounted at
14
+ * `/journeys/:id/members*`; NOT generic-object CRUD (journeyMembers is
15
+ * registered isCreateable=0/isEditable=0 -- reads via `sdk.objects.query`
16
+ * for grids/filters are fine, writes only through these methods).
17
+ *
18
+ * @see app1-api src/services/journeys/routes.js
19
+ */
20
+ export class JourneyMembersService {
21
+ constructor(sdk) {
22
+ this.sdk = sdk;
23
+ }
24
+
25
+ /**
26
+ * Server-paged member grid for one journey.
27
+ * @param {string} journeyId
28
+ * @param {Object} [opts]
29
+ * @param {number} [opts.page]
30
+ * @param {number} [opts.pageSize]
31
+ * @param {string} [opts.sort]
32
+ * @param {string} [opts.sortDir]
33
+ * @param {string[]} [opts.status]
34
+ * @param {string} [opts.stepKey]
35
+ * @param {string} [opts.ownerUserId]
36
+ * @param {string} [opts.statusReason]
37
+ * @param {string} [opts.search]
38
+ * @returns {Promise<Object>} Paged member rows
39
+ */
40
+ async list(journeyId, opts = {}) {
41
+ this.sdk.validateParams(
42
+ { journeyId },
43
+ { journeyId: { type: 'string', required: true } },
44
+ );
45
+ const { status, ...rest } = opts;
46
+ const query = pickDefined({
47
+ ...rest,
48
+ status: Array.isArray(status) ? status.join(',') : status,
49
+ });
50
+ return await internalRequest(
51
+ this.sdk,
52
+ `/journeys/${journeyId}/members`,
53
+ 'GET',
54
+ { query },
55
+ );
56
+ }
57
+
58
+ /**
59
+ * @param {string} journeyId
60
+ * @param {string} memberId
61
+ * @returns {Promise<Object>} Single member row
62
+ */
63
+ async get(journeyId, memberId) {
64
+ this.sdk.validateParams(
65
+ { journeyId, memberId },
66
+ {
67
+ journeyId: { type: 'string', required: true },
68
+ memberId: { type: 'string', required: true },
69
+ },
70
+ );
71
+ return await internalRequest(
72
+ this.sdk,
73
+ `/journeys/${journeyId}/members/${memberId}`,
74
+ 'GET',
75
+ {},
76
+ );
77
+ }
78
+
79
+ /**
80
+ * Enrol people into a journey. Pass `dryRun: true` to get the pre-enrol
81
+ * summary without writing anything.
82
+ *
83
+ * @param {string} journeyId
84
+ * @param {Object} body
85
+ * @param {string[]} [body.peopleIds] - Either peopleIds or filter is required
86
+ * @param {Object} [body.filter]
87
+ * @param {Object} [body.overrides] - Per-member channel overrides
88
+ * @param {string} [body.ownerUserId]
89
+ * @param {string} [body.source]
90
+ * @param {boolean} [body.dryRun]
91
+ * @param {string} [body.primaryChannel]
92
+ * @param {string} [body.workflowVersionId]
93
+ * @returns {Promise<Object>} dryRun: {ready, noChannel, notOptedIn,
94
+ * suppressed, alreadyEnrolled, firstSendAt, outcomes}; real: enrol results
95
+ */
96
+ async enroll(journeyId, body = {}) {
97
+ this.sdk.validateParams(
98
+ { journeyId },
99
+ { journeyId: { type: 'string', required: true } },
100
+ );
101
+ return await internalRequest(
102
+ this.sdk,
103
+ `/journeys/${journeyId}/members/enroll`,
104
+ 'POST',
105
+ { body: pickDefined(body) },
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Apply a bulk action to selected member ids, or to everything matching
111
+ * a filter under the caller's visibility.
112
+ *
113
+ * @param {string} journeyId
114
+ * @param {Object} body
115
+ * @param {'pause'|'resume'|'remove'|'reassign'|'changeChannel'} body.action
116
+ * @param {string[]} [body.ids] - Either ids or filter is required
117
+ * @param {Object} [body.filter]
118
+ * @param {string} [body.reason]
119
+ * @param {string} [body.ownerUserId]
120
+ * @param {Object} [body.channels]
121
+ * @returns {Promise<Object>} { results }
122
+ */
123
+ async actions(journeyId, body = {}) {
124
+ this.sdk.validateParams(
125
+ { journeyId, action: body?.action },
126
+ {
127
+ journeyId: { type: 'string', required: true },
128
+ action: { type: 'string', required: true },
129
+ },
130
+ );
131
+ return await internalRequest(
132
+ this.sdk,
133
+ `/journeys/${journeyId}/members/actions`,
134
+ 'POST',
135
+ { body: pickDefined(body) },
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Fix a member's channel address and resume or remove it.
141
+ *
142
+ * @param {string} journeyId
143
+ * @param {string} memberId
144
+ * @param {Object} body
145
+ * @param {string} [body.emailAddress]
146
+ * @param {string} [body.phoneNumber]
147
+ * @param {string} [body.smsNumber]
148
+ * @param {'resume'|'remove'} body.then
149
+ * @param {string} [body.reason]
150
+ * @returns {Promise<Object>} Updated member
151
+ */
152
+ async fix(journeyId, memberId, body = {}) {
153
+ this.sdk.validateParams(
154
+ { journeyId, memberId, then: body?.then },
155
+ {
156
+ journeyId: { type: 'string', required: true },
157
+ memberId: { type: 'string', required: true },
158
+ then: { type: 'string', required: true },
159
+ },
160
+ );
161
+ return await internalRequest(
162
+ this.sdk,
163
+ `/journeys/${journeyId}/members/${memberId}/fix`,
164
+ 'POST',
165
+ { body: pickDefined(body) },
166
+ );
167
+ }
168
+
169
+ /**
170
+ * @param {string} journeyId
171
+ * @param {string} memberId
172
+ * @returns {Promise<Array>} journeyMemberEvents rows, in order
173
+ */
174
+ async events(journeyId, memberId) {
175
+ this.sdk.validateParams(
176
+ { journeyId, memberId },
177
+ {
178
+ journeyId: { type: 'string', required: true },
179
+ memberId: { type: 'string', required: true },
180
+ },
181
+ );
182
+ return await internalRequest(
183
+ this.sdk,
184
+ `/journeys/${journeyId}/members/${memberId}/events`,
185
+ 'GET',
186
+ {},
187
+ );
188
+ }
189
+ }
@@ -0,0 +1,216 @@
1
+ import { internalRequest } from '../../base.js';
2
+ import { JourneyMembersService } from './JourneyMembersService.js';
3
+
4
+ /**
5
+ * Journeys (journeys-plan.md §2/§4) -- `sdk.journeys.*`.
6
+ *
7
+ * `journeyTypes`/`journeys`/`journeyGoals` are generic objects (registered
8
+ * isCreateable=1/isEditable=1/isDeletable=1, with customHandlers on the api
9
+ * side -- e.g. creating a journey also creates its companion workflow), so
10
+ * their CRUD here is a thin wrapper over `sdk.objects.*` the way
11
+ * `sdk.users.setStatus` wraps `sdk.objects.updateById` -- not a duplicate
12
+ * HTTP surface. `journeyMembers` (registered isCreateable=0/isEditable=0)
13
+ * and the member-grid/enrol/action/fix/events/stats endpoints are custom
14
+ * routes under `/journeys/`, covered by `members` and `stats`.
15
+ *
16
+ * @see app1-api src/services/journeys/routes.js
17
+ */
18
+ export class JourneysService {
19
+ constructor(sdk) {
20
+ this.sdk = sdk;
21
+ this.members = new JourneyMembersService(sdk);
22
+ this.types = new JourneyTypesService(sdk);
23
+ this.goals = new JourneyGoalsService(sdk);
24
+ }
25
+
26
+ /**
27
+ * @param {Object} [opts] - sdk.objects.query opts (select, where, limit, nextId, …)
28
+ * @returns {Promise<Object>} Query result
29
+ */
30
+ async list(opts = {}) {
31
+ return await this.sdk.objects.query({ object: 'journeys', ...opts });
32
+ }
33
+
34
+ /**
35
+ * @param {string} id
36
+ * @returns {Promise<Object>} Journey record
37
+ */
38
+ async get(id) {
39
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
40
+ return await this.sdk.objects.byId({ id });
41
+ }
42
+
43
+ /**
44
+ * Creating a journey also creates its companion workflow
45
+ * (type='journey', builderMode='advanced' until P4) + a draft version.
46
+ *
47
+ * @param {Object} body
48
+ * @param {string} body.name
49
+ * @param {string} body.journeyTypeId
50
+ * @returns {Promise<Object>} Created journey, with workflowId/workflowVersionId
51
+ */
52
+ async create(body) {
53
+ this.sdk.validateParams(
54
+ { name: body?.name, journeyTypeId: body?.journeyTypeId },
55
+ {
56
+ name: { type: 'string', required: true },
57
+ journeyTypeId: { type: 'string', required: true },
58
+ },
59
+ );
60
+ return await this.sdk.objects.create({ object: 'journeys', body });
61
+ }
62
+
63
+ /**
64
+ * @param {string} id
65
+ * @param {Object} update
66
+ * @returns {Promise<Object>} Update result
67
+ */
68
+ async update(id, update) {
69
+ this.sdk.validateParams(
70
+ { id, update },
71
+ {
72
+ id: { type: 'string', required: true },
73
+ update: { type: 'object', required: true },
74
+ },
75
+ );
76
+ return await this.sdk.objects.updateById({ object: 'journeys', id, update });
77
+ }
78
+
79
+ /**
80
+ * Delete ⇒ archive server-side (status: 'archived', never soft-deleted).
81
+ *
82
+ * @param {string} id
83
+ * @returns {Promise<Object>} { deleted: [id] }
84
+ */
85
+ async archive(id) {
86
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
87
+ return await this.sdk.objects.deleteById({ object: 'journeys', id });
88
+ }
89
+
90
+ /**
91
+ * @param {string} journeyId
92
+ * @returns {Promise<Object>} { byStatus, needsAttentionByReason }
93
+ */
94
+ async stats(journeyId) {
95
+ this.sdk.validateParams(
96
+ { journeyId },
97
+ { journeyId: { type: 'string', required: true } },
98
+ );
99
+ return await internalRequest(
100
+ this.sdk,
101
+ `/journeys/${journeyId}/stats`,
102
+ 'GET',
103
+ {},
104
+ );
105
+ }
106
+ }
107
+
108
+ /**
109
+ * `sdk.journeys.types.*` -- journeyTypes generic-object CRUD. `queueId`
110
+ * stays empty until P5.
111
+ */
112
+ class JourneyTypesService {
113
+ constructor(sdk) {
114
+ this.sdk = sdk;
115
+ }
116
+
117
+ async list(opts = {}) {
118
+ return await this.sdk.objects.query({ object: 'journeyTypes', ...opts });
119
+ }
120
+
121
+ async get(id) {
122
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
123
+ return await this.sdk.objects.byId({ id });
124
+ }
125
+
126
+ /**
127
+ * @param {Object} body
128
+ * @param {string} body.name
129
+ * @returns {Promise<Object>} Created journeyType
130
+ */
131
+ async create(body) {
132
+ this.sdk.validateParams(
133
+ { name: body?.name },
134
+ { name: { type: 'string', required: true } },
135
+ );
136
+ return await this.sdk.objects.create({ object: 'journeyTypes', body });
137
+ }
138
+
139
+ async update(id, update) {
140
+ this.sdk.validateParams(
141
+ { id, update },
142
+ {
143
+ id: { type: 'string', required: true },
144
+ update: { type: 'object', required: true },
145
+ },
146
+ );
147
+ return await this.sdk.objects.updateById({
148
+ object: 'journeyTypes',
149
+ id,
150
+ update,
151
+ });
152
+ }
153
+
154
+ async remove(id) {
155
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
156
+ return await this.sdk.objects.deleteById({ object: 'journeyTypes', id });
157
+ }
158
+ }
159
+
160
+ /**
161
+ * `sdk.journeys.goals.*` -- journeyGoals generic-object CRUD (no `get`;
162
+ * goals are listed/edited inline on the journey, matching the plan's CRUD
163
+ * surface for this object).
164
+ */
165
+ class JourneyGoalsService {
166
+ constructor(sdk) {
167
+ this.sdk = sdk;
168
+ }
169
+
170
+ /**
171
+ * @param {Object} [opts] - sdk.objects.query opts; pass `where: { journeyId }` to scope
172
+ * @returns {Promise<Object>} Query result
173
+ */
174
+ async list(opts = {}) {
175
+ return await this.sdk.objects.query({ object: 'journeyGoals', ...opts });
176
+ }
177
+
178
+ /**
179
+ * @param {Object} body
180
+ * @param {string} body.journeyId
181
+ * @param {string} body.goalType
182
+ * @returns {Promise<Object>} Created journeyGoal
183
+ */
184
+ async create(body) {
185
+ this.sdk.validateParams(
186
+ { journeyId: body?.journeyId, goalType: body?.goalType },
187
+ {
188
+ journeyId: { type: 'string', required: true },
189
+ goalType: { type: 'string', required: true },
190
+ },
191
+ );
192
+ return await this.sdk.objects.create({ object: 'journeyGoals', body });
193
+ }
194
+
195
+ async update(id, update) {
196
+ this.sdk.validateParams(
197
+ { id, update },
198
+ {
199
+ id: { type: 'string', required: true },
200
+ update: { type: 'object', required: true },
201
+ },
202
+ );
203
+ return await this.sdk.objects.updateById({
204
+ object: 'journeyGoals',
205
+ id,
206
+ update,
207
+ });
208
+ }
209
+
210
+ async remove(id) {
211
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
212
+ return await this.sdk.objects.deleteById({ object: 'journeyGoals', id });
213
+ }
214
+ }
215
+
216
+ export { JourneyTypesService, JourneyGoalsService };
@@ -1417,43 +1417,4 @@ export class ObjectsService {
1417
1417
  );
1418
1418
  }
1419
1419
 
1420
- /**
1421
- * P7 (workflows-v2-plan.md W10/W11/W23) -- runs an immediate full
1422
- * enter+exit sweep for a journey program. Same diff-and-enqueue path a
1423
- * scheduled tick runs, so this can never 429.
1424
- * @param {string} programId
1425
- * @returns {Promise<{queued: true, enterEnqueued: number, exitEnqueued: number}>}
1426
- */
1427
- async runMarketingProgramNow(programId) {
1428
- this.sdk.validateParams(
1429
- { programId },
1430
- { programId: { type: 'string', required: true } },
1431
- );
1432
- return internalRequest(
1433
- this.sdk,
1434
- `/object/marketing-programs/${programId}/run`,
1435
- 'POST',
1436
- { body: {} },
1437
- );
1438
- }
1439
-
1440
- /**
1441
- * P7 -- paginated member list for a journey program (joined to people
1442
- * for display name; never raw peopleId).
1443
- * @param {string} programId
1444
- * @param {{nextId?: string, limit?: number}} [opts]
1445
- * @returns {Promise<{results: object[], pagination: object}>}
1446
- */
1447
- async listMarketingProgramMembers(programId, opts = {}) {
1448
- this.sdk.validateParams(
1449
- { programId },
1450
- { programId: { type: 'string', required: true } },
1451
- );
1452
- return internalRequest(
1453
- this.sdk,
1454
- `/object/marketing-programs/${programId}/members`,
1455
- 'GET',
1456
- { query: opts },
1457
- );
1458
- }
1459
1420
  }