@unboundcx/sdk 4.13.146-security.0 → 4.13.146-security.1
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 +0 -7
- package/index.js +31 -1
- package/lib/journeyLayout.js +132 -0
- package/package.json +5 -2
- package/services/journeys/JourneyDraftService.js +92 -0
- package/services/journeys/JourneyGoalsService.js +57 -0
- package/services/journeys/JourneyMembersService.js +246 -0
- package/services/journeys/JourneyTypesService.js +59 -0
- package/services/journeys/JourneyWorklistService.js +74 -0
- package/services/journeys/JourneysService.js +392 -0
- package/services/layouts.js +13 -4
- package/services/messageTemplates.js +109 -2
- package/services/messaging/EmailTemplatesService.js +10 -2
- package/services/messaging/SmsService.js +0 -3
- package/services/messaging.js +0 -2
- package/services/objects.js +12 -39
- package/services/operatorPanels.js +226 -0
- package/services/parking.js +121 -0
- package/services/permissions.js +21 -0
- package/services/phoneNumbers/carrier.js +60 -0
- package/services/phoneNumbers/cnam.js +42 -0
- package/services/phoneNumbers/index.js +27 -0
- package/services/phoneNumbers/order.js +88 -0
- package/services/phoneNumbers/porting-activity.js +289 -0
- package/services/phoneNumbers/porting-orders.js +318 -0
- package/services/phoneNumbers/search.js +181 -0
- package/services/phoneNumbers/update.js +94 -0
- package/services/phoneNumbers.js +2 -1037
- package/services/recents.js +16 -0
- package/services/schedules/SchedulesService.js +232 -0
- package/services/schedules/TimeOffService.js +131 -0
- package/services/skills.js +207 -0
- package/services/taskRouter/MetricsService.js +3 -0
- package/services/taskRouter/QueueService.js +343 -0
- package/services/taskRouter/TaskRouterService.js +2 -0
- package/services/taskRouter/TaskService.js +70 -10
- package/services/voice.js +47 -25
- package/services/voicemailDrops.js +268 -0
- package/services/workflowTemplates/WorkflowTemplatesService.js +68 -0
- package/services/messaging/SmsTemplatesService.js +0 -125
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* @param {'firstTouchClaims'|'perTouch'} [body.poolClaimMode] - first rep to take a pool touch owns the member for the rest of the cadence (default) | no auto-claim
|
|
25
|
+
* @param {'never'|'ifEmpty'|'always'} [body.syncPersonOwner] - whether a member owner assignment also writes people.ownerId (default 'ifEmpty')
|
|
26
|
+
* @param {'person'|'company'} [body.ownerScope] - 'company': claims/reassigns fan out to every open member of the same company in this type (default 'person')
|
|
27
|
+
* @param {'reassign'|'needsAttention'} [body.ownerMissingPolicy] - owner deactivated / lost salesEnabled / left the queue: auto-reassign (backup user → round-robin → pool, default) or park with statusReason 'ownerMissing'
|
|
28
|
+
* @param {number|null} [body.maxActiveMembersPerOwner] - cap of active+needsAttention members per owner across the type; members over the cap wait (status 'waiting', statusReason 'ownerCapacity') and are admitted by people.score DESC, enteredAt ASC. null = unlimited
|
|
29
|
+
* All five are type defaults; a journey may override each with the same field (null = use type default).
|
|
30
|
+
* @returns {Promise<Object>} Created journeyType
|
|
31
|
+
*/
|
|
32
|
+
async create(body) {
|
|
33
|
+
this.sdk.validateParams(
|
|
34
|
+
{ name: body?.name },
|
|
35
|
+
{ name: { type: 'string', required: true } },
|
|
36
|
+
);
|
|
37
|
+
return await this.sdk.objects.create({ object: 'journeyTypes', body });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async update(id, update) {
|
|
41
|
+
this.sdk.validateParams(
|
|
42
|
+
{ id, update },
|
|
43
|
+
{
|
|
44
|
+
id: { type: 'string', required: true },
|
|
45
|
+
update: { type: 'object', required: true },
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
return await this.sdk.objects.updateById({
|
|
49
|
+
object: 'journeyTypes',
|
|
50
|
+
id,
|
|
51
|
+
update,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async remove(id) {
|
|
56
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
57
|
+
return await this.sdk.objects.deleteById({ object: 'journeyTypes', id });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
* @typedef {Object} JourneyWorklistTask
|
|
13
|
+
* @property {string} id
|
|
14
|
+
* @property {'journey'} type
|
|
15
|
+
* @property {'worklist'} deliveryMode
|
|
16
|
+
* @property {string|null} dueAt
|
|
17
|
+
* @property {string} journeyMemberId
|
|
18
|
+
* @property {string} journeyId
|
|
19
|
+
* @property {string} journeyStepKey
|
|
20
|
+
* @property {'email'|'sms'|'call'|'other'} journeyStepChannel
|
|
21
|
+
* @property {string|null} preferredWorkerId - Owner, or null for a pool task
|
|
22
|
+
* @property {string|null} engagementSessionId
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sales work list -- `sdk.journeys.worklist.*` (journeys-plan.md §9, P5).
|
|
27
|
+
* Cross-journey view of a sales rep's (or the pool's) open touch tasks
|
|
28
|
+
* (`tasks.type='journey'`), plus upcoming members from
|
|
29
|
+
* `journeyMembers.nextActionAt`. Requires `users_acct.salesEnabled` for
|
|
30
|
+
* `takeNext` (`list` stays open to ordinary object-read permission, per
|
|
31
|
+
* the P5 contract).
|
|
32
|
+
*
|
|
33
|
+
* @see app1-api src/services/journeys/controllers/worklist.js
|
|
34
|
+
*/
|
|
35
|
+
export class JourneyWorklistService {
|
|
36
|
+
constructor(sdk) {
|
|
37
|
+
this.sdk = sdk;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Object} [opts]
|
|
42
|
+
* @param {'due'|'overdue'|'upcoming'} [opts.bucket]
|
|
43
|
+
* @param {string} [opts.stepType]
|
|
44
|
+
* @param {string} [opts.journeyId]
|
|
45
|
+
* @param {number} [opts.page]
|
|
46
|
+
* @param {number} [opts.pageSize]
|
|
47
|
+
* @returns {Promise<{data: JourneyWorklistTask[]}>}
|
|
48
|
+
*/
|
|
49
|
+
async list(opts = {}) {
|
|
50
|
+
return await internalRequest(this.sdk, '/journeys/worklist', 'GET', {
|
|
51
|
+
query: pickDefined(opts),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Takes the next due task for the caller (owner-or-pool), via the same
|
|
57
|
+
* `transitionTask` path as a manual take (`PUT /tasks/:id
|
|
58
|
+
* {status:'connected', workerId}`) -- not a separate silent-assign path.
|
|
59
|
+
*
|
|
60
|
+
* @param {Object} [filter]
|
|
61
|
+
* @param {string} [filter.stepType]
|
|
62
|
+
* @param {string} [filter.journeyId]
|
|
63
|
+
* @param {string} [filter.taskId] take this exact task (validated server-side: worklist, pending, owner-or-pool)
|
|
64
|
+
* @returns {Promise<{data: JourneyWorklistTask|null}>} null when nothing is due
|
|
65
|
+
*/
|
|
66
|
+
async takeNext(filter = {}) {
|
|
67
|
+
return await internalRequest(
|
|
68
|
+
this.sdk,
|
|
69
|
+
'/journeys/worklist/take-next',
|
|
70
|
+
'POST',
|
|
71
|
+
{ body: pickDefined(filter) },
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { internalRequest } from '../../base.js';
|
|
2
|
+
import { JourneyMembersService } from './JourneyMembersService.js';
|
|
3
|
+
import { JourneyDraftService } from './JourneyDraftService.js';
|
|
4
|
+
import { JourneyWorklistService } from './JourneyWorklistService.js';
|
|
5
|
+
import { JourneyTypesService } from './JourneyTypesService.js';
|
|
6
|
+
import { JourneyGoalsService } from './JourneyGoalsService.js';
|
|
7
|
+
|
|
8
|
+
function pickDefined(fields) {
|
|
9
|
+
const body = {};
|
|
10
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
11
|
+
if (value !== undefined) body[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return body;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Journeys (journeys-plan.md §2/§4) -- `sdk.journeys.*`.
|
|
18
|
+
*
|
|
19
|
+
* `journeyTypes`/`journeys`/`journeyGoals` are generic objects (registered
|
|
20
|
+
* isCreateable=1/isEditable=1/isDeletable=1, with customHandlers on the api
|
|
21
|
+
* side -- e.g. creating a journey also creates its companion workflow), so
|
|
22
|
+
* their CRUD here is a thin wrapper over `sdk.objects.*` the way
|
|
23
|
+
* `sdk.users.setStatus` wraps `sdk.objects.updateById` -- not a duplicate
|
|
24
|
+
* HTTP surface. `journeyMembers` (registered isCreateable=0/isEditable=0)
|
|
25
|
+
* and the member-grid/enrol/action/fix/events/stats endpoints are custom
|
|
26
|
+
* routes under `/journeys/`, covered by `members` and `stats`.
|
|
27
|
+
*
|
|
28
|
+
* P5 (journeys-plan.md §8, sales queues + human steps) added fields to
|
|
29
|
+
* several generic objects rather than new endpoints -- no dedicated SDK
|
|
30
|
+
* service exists for these, so they are documented here instead:
|
|
31
|
+
* - `sdk.objects` object `'queues'`: `queueType` ('support'|'sales',
|
|
32
|
+
* default 'support'), `deliveryMode` ('push'|'worklist', default
|
|
33
|
+
* 'push'). A sales queue is auto-created with a journey type
|
|
34
|
+
* (`queueType:'sales', deliveryMode:'worklist'`) and its id is set on
|
|
35
|
+
* `journeyTypes.queueId`.
|
|
36
|
+
* - `sdk.objects` object `'queueDispositions'`: `outcome`
|
|
37
|
+
* ('positive'|'neutral'|'negative'|null), `countsAsConversion`
|
|
38
|
+
* (boolean), `flagsBadContact` (boolean) -- drive a journey member's
|
|
39
|
+
* `converted` / `needsAttention:badContact` transitions when a touch
|
|
40
|
+
* task is given that disposition.
|
|
41
|
+
* - `sdk.objects` object `'users'` (`users_acct`): `salesEnabled`
|
|
42
|
+
* (boolean, default false) -- required (alongside normal object
|
|
43
|
+
* permissions) for journeys build/enrol/member-action/worklist-take
|
|
44
|
+
* endpoints; member-grid reads stay open to object-read permission.
|
|
45
|
+
* - Task rows (`sdk.taskRouter.task.*`, `sdk.journeys.worklist.*`) gain
|
|
46
|
+
* `deliveryMode` ('push'|'worklist'), `dueAt` (ISO datetime|null),
|
|
47
|
+
* `journeyMemberId`, `journeyId`, `journeyStepKey`, `journeyStepChannel`
|
|
48
|
+
* ('email'|'sms'|'call'|'other') on a journey touch task
|
|
49
|
+
* (`type:'journey'`). See `JourneyWorklistService`'s
|
|
50
|
+
* `JourneyWorklistTask` typedef for the full shape.
|
|
51
|
+
*
|
|
52
|
+
* @see app1-api src/services/journeys/routes.js
|
|
53
|
+
*/
|
|
54
|
+
export class JourneysService {
|
|
55
|
+
constructor(sdk) {
|
|
56
|
+
this.sdk = sdk;
|
|
57
|
+
this.members = new JourneyMembersService(sdk);
|
|
58
|
+
this.types = new JourneyTypesService(sdk);
|
|
59
|
+
this.goals = new JourneyGoalsService(sdk);
|
|
60
|
+
this.draft = new JourneyDraftService(sdk);
|
|
61
|
+
this.worklist = new JourneyWorklistService(sdk);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Object} [opts] - sdk.objects.query opts (select, where, limit, nextId, …)
|
|
66
|
+
* @returns {Promise<Object>} Query result
|
|
67
|
+
*/
|
|
68
|
+
async list(opts = {}) {
|
|
69
|
+
return await this.sdk.objects.query({ object: 'journeys', ...opts });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} id
|
|
74
|
+
* @returns {Promise<Object>} Journey record
|
|
75
|
+
*/
|
|
76
|
+
async get(id) {
|
|
77
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
78
|
+
return await this.sdk.objects.byId({ id });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Creating a journey also creates its companion workflow
|
|
83
|
+
* (type='journey', builderMode='advanced' until P4) + a draft version.
|
|
84
|
+
*
|
|
85
|
+
* @param {Object} body
|
|
86
|
+
* @param {string} body.name
|
|
87
|
+
* @param {string} body.journeyTypeId
|
|
88
|
+
* @returns {Promise<Object>} Created journey, with workflowId/workflowVersionId
|
|
89
|
+
*/
|
|
90
|
+
async create(body) {
|
|
91
|
+
this.sdk.validateParams(
|
|
92
|
+
{ name: body?.name, journeyTypeId: body?.journeyTypeId },
|
|
93
|
+
{
|
|
94
|
+
name: { type: 'string', required: true },
|
|
95
|
+
journeyTypeId: { type: 'string', required: true },
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
return await this.sdk.objects.create({ object: 'journeys', body });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} id
|
|
103
|
+
* @param {Object} update
|
|
104
|
+
* @returns {Promise<Object>} Update result
|
|
105
|
+
*/
|
|
106
|
+
async update(id, update) {
|
|
107
|
+
this.sdk.validateParams(
|
|
108
|
+
{ id, update },
|
|
109
|
+
{
|
|
110
|
+
id: { type: 'string', required: true },
|
|
111
|
+
update: { type: 'object', required: true },
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
return await this.sdk.objects.updateById({ object: 'journeys', id, update });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Delete ⇒ archive server-side (status: 'archived', never soft-deleted).
|
|
119
|
+
*
|
|
120
|
+
* @param {string} id
|
|
121
|
+
* @returns {Promise<Object>} { deleted: [id] }
|
|
122
|
+
*/
|
|
123
|
+
async archive(id) {
|
|
124
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
125
|
+
return await this.sdk.objects.deleteById({ object: 'journeys', id });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {string} journeyId
|
|
130
|
+
* @returns {Promise<Object>} { byStatus, needsAttentionByReason }
|
|
131
|
+
*/
|
|
132
|
+
async stats(journeyId) {
|
|
133
|
+
this.sdk.validateParams(
|
|
134
|
+
{ journeyId },
|
|
135
|
+
{ journeyId: { type: 'string', required: true } },
|
|
136
|
+
);
|
|
137
|
+
return await internalRequest(
|
|
138
|
+
this.sdk,
|
|
139
|
+
`/journeys/${journeyId}/stats`,
|
|
140
|
+
'GET',
|
|
141
|
+
{},
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Bulk equivalent of `stats()` for the Journeys list page -- one request
|
|
147
|
+
* instead of N. Journeys not found (or with no members) still get an
|
|
148
|
+
* entry, zeroed.
|
|
149
|
+
*
|
|
150
|
+
* @param {string[]} ids
|
|
151
|
+
* @returns {Promise<Object<string, {byStatus: Object, needsAttentionByReason: Object, total: number}>>}
|
|
152
|
+
*/
|
|
153
|
+
async listStats(ids) {
|
|
154
|
+
this.sdk.validateParams(
|
|
155
|
+
{ ids },
|
|
156
|
+
{ ids: { type: 'array', required: true } },
|
|
157
|
+
);
|
|
158
|
+
if (!ids.length) return {};
|
|
159
|
+
return await internalRequest(this.sdk, '/journeys/list-stats', 'GET', {
|
|
160
|
+
query: { ids: ids.join(',') },
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* REAL delete -- distinct from `archive()`. Only succeeds server-side
|
|
166
|
+
* when the journey is still a draft, or has zero members in any status;
|
|
167
|
+
* otherwise the API refuses with 409 `JOURNEY_HAS_MEMBERS` (archive it
|
|
168
|
+
* instead). Hard-deletes the journey row plus its companion workflow
|
|
169
|
+
* (and that workflow's versions/items/ports/connections) -- unlike
|
|
170
|
+
* `archive()`, this cannot be undone.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} id
|
|
173
|
+
* @returns {Promise<Object>} { deleted: true, id, workflowId, memberCount }
|
|
174
|
+
*/
|
|
175
|
+
async remove(id) {
|
|
176
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
177
|
+
return await internalRequest(this.sdk, `/journeys/${id}`, 'DELETE', {});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Diff of the current published journeyDoc vs the draft, by stepKey (P7).
|
|
182
|
+
*
|
|
183
|
+
* @param {string} id
|
|
184
|
+
* @returns {Promise<Object>} { oldVersionId, newVersionId, added, removed, changed }
|
|
185
|
+
*/
|
|
186
|
+
async publishDiff(id) {
|
|
187
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
188
|
+
return await internalRequest(
|
|
189
|
+
this.sdk,
|
|
190
|
+
`/journeys/${id}/publish-diff`,
|
|
191
|
+
'GET',
|
|
192
|
+
{},
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Publish the draft (runs publish-check; blocking items fail). Pass
|
|
198
|
+
* `{mode:'migrate', mapping}` to move open members on the old version to
|
|
199
|
+
* mapped landing steps at their next safe point (journeys-plan.md §7.5);
|
|
200
|
+
* omit for a plain publish (members stay on their version). Requires
|
|
201
|
+
* salesEnabled.
|
|
202
|
+
*
|
|
203
|
+
* @param {string} id
|
|
204
|
+
* @param {Object} [opts]
|
|
205
|
+
* @param {'migrate'|'leave'} [opts.mode]
|
|
206
|
+
* @param {Object<string,string>} [opts.mapping] removed stepKey -> landing stepKey | 'leave'
|
|
207
|
+
* @returns {Promise<Object>} { versionId, oldVersionId, migrationPlan }
|
|
208
|
+
*/
|
|
209
|
+
async publish(id, { mode, mapping } = {}) {
|
|
210
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
211
|
+
return await internalRequest(this.sdk, `/journeys/${id}/publish`, 'POST', {
|
|
212
|
+
body: { migrate: pickDefined({ mode, mapping }) },
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Per-step funnel (journeys-plan.md §9, P6): entered / outcome split /
|
|
218
|
+
* conversions from journeyMemberEvents. Test members are excluded.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} journeyId
|
|
221
|
+
* @returns {Promise<Object>} { steps: [{ stepKey, type, title, entered, outcomes, conversions }] }
|
|
222
|
+
*/
|
|
223
|
+
async funnel(journeyId) {
|
|
224
|
+
this.sdk.validateParams(
|
|
225
|
+
{ journeyId },
|
|
226
|
+
{ journeyId: { type: 'string', required: true } },
|
|
227
|
+
);
|
|
228
|
+
return await internalRequest(
|
|
229
|
+
this.sdk,
|
|
230
|
+
`/journeys/${journeyId}/funnel`,
|
|
231
|
+
'GET',
|
|
232
|
+
{},
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Journey-level metrics (P6): enrolled, active, needsAttention, repliedPct,
|
|
238
|
+
* convertedPct, bounced, optedOut, timeToConvertMedianSeconds, byStatus.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} journeyId
|
|
241
|
+
* @returns {Promise<Object>}
|
|
242
|
+
*/
|
|
243
|
+
async metrics(journeyId) {
|
|
244
|
+
this.sdk.validateParams(
|
|
245
|
+
{ journeyId },
|
|
246
|
+
{ journeyId: { type: 'string', required: true } },
|
|
247
|
+
);
|
|
248
|
+
return await internalRequest(
|
|
249
|
+
this.sdk,
|
|
250
|
+
`/journeys/${journeyId}/metrics`,
|
|
251
|
+
'GET',
|
|
252
|
+
{},
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Journey-wide activity feed (P6): journeyMemberEvents, newest first.
|
|
258
|
+
*
|
|
259
|
+
* @param {string} journeyId
|
|
260
|
+
* @param {Object} [opts]
|
|
261
|
+
* @param {string} [opts.stepKey]
|
|
262
|
+
* @param {string} [opts.memberId]
|
|
263
|
+
* @param {number} [opts.page]
|
|
264
|
+
* @param {number} [opts.pageSize]
|
|
265
|
+
* @returns {Promise<Object>} { rows, total }
|
|
266
|
+
*/
|
|
267
|
+
async events(journeyId, opts = {}) {
|
|
268
|
+
this.sdk.validateParams(
|
|
269
|
+
{ journeyId },
|
|
270
|
+
{ journeyId: { type: 'string', required: true } },
|
|
271
|
+
);
|
|
272
|
+
return await internalRequest(
|
|
273
|
+
this.sdk,
|
|
274
|
+
`/journeys/${journeyId}/events`,
|
|
275
|
+
'GET',
|
|
276
|
+
{ query: pickDefined(opts) },
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Rep metrics (P6): per owner — due, overdue, doneOnTime,
|
|
282
|
+
* timeToActionMedianSeconds — from touch tasks. Requires salesEnabled.
|
|
283
|
+
*
|
|
284
|
+
* @param {Object} [opts]
|
|
285
|
+
* @param {string} [opts.journeyTypeId]
|
|
286
|
+
* @param {string} [opts.journeyId]
|
|
287
|
+
* @param {string} [opts.from] ISO date-time
|
|
288
|
+
* @param {string} [opts.to] ISO date-time
|
|
289
|
+
* @returns {Promise<Object>} { reps: [{ userId, due, overdue, doneOnTime, timeToActionMedianSeconds }] }
|
|
290
|
+
*/
|
|
291
|
+
async repsMetrics(opts = {}) {
|
|
292
|
+
return await internalRequest(this.sdk, '/journeys/reps/metrics', 'GET', {
|
|
293
|
+
query: pickDefined(opts),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* No-send dry run: per step, the resolved channel (override -> primary),
|
|
299
|
+
* rendered message, and landing date for a given person (journeys-plan.md
|
|
300
|
+
* §7.6, P4 templates area).
|
|
301
|
+
*
|
|
302
|
+
* @param {string} id
|
|
303
|
+
* @param {Object} params
|
|
304
|
+
* @param {string} params.peopleId
|
|
305
|
+
* @returns {Promise<Object>} { steps: [{ stepKey, channel, message, landingAt }] }
|
|
306
|
+
*/
|
|
307
|
+
async preview(id, { peopleId } = {}) {
|
|
308
|
+
this.sdk.validateParams(
|
|
309
|
+
{ id, peopleId },
|
|
310
|
+
{
|
|
311
|
+
id: { type: 'string', required: true },
|
|
312
|
+
peopleId: { type: 'string', required: true },
|
|
313
|
+
},
|
|
314
|
+
);
|
|
315
|
+
return await internalRequest(this.sdk, `/journeys/${id}/preview`, 'GET', {
|
|
316
|
+
query: { peopleId },
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Enrols the caller as an `isTest` member: sends redirect to the caller's
|
|
322
|
+
* own email/number, waits compress to `TEST_RUN_WAIT_SECONDS`, and the
|
|
323
|
+
* member is excluded from stats/event counts.
|
|
324
|
+
*
|
|
325
|
+
* @param {string} id
|
|
326
|
+
* @param {Object} [params]
|
|
327
|
+
* @param {string} [params.peopleId]
|
|
328
|
+
* @param {string} [params.testEmail] - override destination
|
|
329
|
+
* @param {string} [params.testPhone] - override destination
|
|
330
|
+
* @returns {Promise<Object>} Enrolled test member
|
|
331
|
+
*/
|
|
332
|
+
async testRun(id, { peopleId, testEmail, testPhone } = {}) {
|
|
333
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
334
|
+
return await internalRequest(
|
|
335
|
+
this.sdk,
|
|
336
|
+
`/journeys/${id}/test-run`,
|
|
337
|
+
'POST',
|
|
338
|
+
{ body: pickDefined({ peopleId, testEmail, testPhone }) },
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Export + install into the same account, keeping template refs
|
|
344
|
+
* (journeys-plan.md §7.7).
|
|
345
|
+
*
|
|
346
|
+
* @param {string} id
|
|
347
|
+
* @param {Object} [params]
|
|
348
|
+
* @param {string} [params.name]
|
|
349
|
+
* @returns {Promise<Object>} New journey + workflow + draft version
|
|
350
|
+
*/
|
|
351
|
+
async clone(id, { name } = {}) {
|
|
352
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
353
|
+
return await internalRequest(this.sdk, `/journeys/${id}/clone`, 'POST', {
|
|
354
|
+
body: pickDefined({ name }),
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Save this journey into the account's template library
|
|
360
|
+
* (`workflowTemplates`, journeys-plan.md §7.7).
|
|
361
|
+
*
|
|
362
|
+
* @param {string} id
|
|
363
|
+
* @param {Object} params
|
|
364
|
+
* @param {string} params.name
|
|
365
|
+
* @param {string} [params.summary]
|
|
366
|
+
* @param {string} [params.category]
|
|
367
|
+
* @param {'platform'|'account'} [params.visibility]
|
|
368
|
+
* @returns {Promise<Object>} Created workflowTemplates row
|
|
369
|
+
*/
|
|
370
|
+
async saveAsTemplate(id, { name, summary, category, visibility } = {}) {
|
|
371
|
+
this.sdk.validateParams(
|
|
372
|
+
{ id, name },
|
|
373
|
+
{
|
|
374
|
+
id: { type: 'string', required: true },
|
|
375
|
+
name: { type: 'string', required: true },
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
return await internalRequest(
|
|
379
|
+
this.sdk,
|
|
380
|
+
`/journeys/${id}/save-as-template`,
|
|
381
|
+
'POST',
|
|
382
|
+
{ body: pickDefined({ name, summary, category, visibility }) },
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export {
|
|
388
|
+
JourneyTypesService,
|
|
389
|
+
JourneyGoalsService,
|
|
390
|
+
JourneyDraftService,
|
|
391
|
+
JourneyWorklistService,
|
|
392
|
+
};
|
package/services/layouts.js
CHANGED
|
@@ -177,15 +177,24 @@ export class LayoutsService {
|
|
|
177
177
|
return result;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
async
|
|
180
|
+
async listSystem() {
|
|
181
|
+
const result = await internalRequest(this.sdk, '/layouts/system', 'GET', {});
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// recordTypeId is only sent when provided -- cloning a GLOBAL system layout
|
|
186
|
+
// into a tenant row targets a specific record type.
|
|
187
|
+
async clone(id, { name, recordTypeId } = {}) {
|
|
181
188
|
this.sdk.validateParams(
|
|
182
189
|
{ id },
|
|
183
190
|
{ id: { type: 'string', required: true } },
|
|
184
191
|
);
|
|
185
192
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
const body = { name };
|
|
194
|
+
if (recordTypeId !== undefined && recordTypeId !== null) {
|
|
195
|
+
body.recordTypeId = recordTypeId;
|
|
196
|
+
}
|
|
197
|
+
const params = { body };
|
|
189
198
|
|
|
190
199
|
const result = await internalRequest(this.sdk, `/layouts/${id}/clone`, 'POST', params);
|
|
191
200
|
return result;
|
|
@@ -129,7 +129,8 @@ export class MessageTemplatesCrudService {
|
|
|
129
129
|
* @param {string} options.body
|
|
130
130
|
* @param {'draft'|'active'} [options.status]
|
|
131
131
|
* @param {number} [options.sortOrder]
|
|
132
|
-
* @
|
|
132
|
+
* @param {Array<{url: string, type: 'image'|'video'|'audio'|'document', name?: string}>} [options.media] - MMS attachments, max 10
|
|
133
|
+
* @returns {Promise<Object>} includes `version` (starts at 1; a version row is written on every save)
|
|
133
134
|
*/
|
|
134
135
|
async create(options) {
|
|
135
136
|
this.sdk.validateParams(
|
|
@@ -153,9 +154,12 @@ export class MessageTemplatesCrudService {
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
/**
|
|
156
|
-
* Update a stored message template.
|
|
157
|
+
* Update a stored message template. A name/body/media change writes a
|
|
158
|
+
* new row to the version history (a status-only or group-move save does
|
|
159
|
+
* not).
|
|
157
160
|
* @param {string} id
|
|
158
161
|
* @param {Object} options
|
|
162
|
+
* @param {Array<{url: string, type: 'image'|'video'|'audio'|'document', name?: string}>} [options.media]
|
|
159
163
|
* @returns {Promise<Object>}
|
|
160
164
|
*/
|
|
161
165
|
async update(id, options) {
|
|
@@ -182,6 +186,108 @@ export class MessageTemplatesCrudService {
|
|
|
182
186
|
'DELETE',
|
|
183
187
|
);
|
|
184
188
|
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Preview a template interpolated against a record (or a raw body with
|
|
192
|
+
* no saved template), with unresolved-variable highlighting and SMS
|
|
193
|
+
* character/segment count (journeys-plan.md §6.4). Pass either a saved
|
|
194
|
+
* `templateId` or a raw `body`.
|
|
195
|
+
* @param {Object} options
|
|
196
|
+
* @param {string} [options.templateId]
|
|
197
|
+
* @param {string} [options.body] - raw body when there is no saved template
|
|
198
|
+
* @param {string} [options.peopleId] - record to interpolate against
|
|
199
|
+
* @returns {Promise<{text: string, unresolved: string[], fits: boolean, segments: number}>}
|
|
200
|
+
*/
|
|
201
|
+
async preview({ templateId, body, peopleId } = {}) {
|
|
202
|
+
if (!templateId && !body) {
|
|
203
|
+
throw new Error('preview requires templateId or body');
|
|
204
|
+
}
|
|
205
|
+
const endpoint = templateId
|
|
206
|
+
? `/messageTemplates/templates/${templateId}/preview`
|
|
207
|
+
: '/messageTemplates/templates/preview';
|
|
208
|
+
return internalRequest(this.sdk, endpoint, 'POST', {
|
|
209
|
+
body: { templateId, body, peopleId },
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Send a test SMS of the interpolated template to the caller's own
|
|
215
|
+
* on-file number (never an arbitrary address).
|
|
216
|
+
* @param {string} id
|
|
217
|
+
* @returns {Promise<{sent: boolean, to: string}>}
|
|
218
|
+
*/
|
|
219
|
+
async sendTest(id) {
|
|
220
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
221
|
+
return internalRequest(
|
|
222
|
+
this.sdk,
|
|
223
|
+
`/messageTemplates/templates/${id}/sendTest`,
|
|
224
|
+
'POST',
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* "Used by N journeys, M active members" (journeys-plan.md §6.4).
|
|
230
|
+
* @param {string} id
|
|
231
|
+
* @returns {Promise<{journeyCount: number, activeMemberCount: number, journeys: Object[]}>}
|
|
232
|
+
*/
|
|
233
|
+
async usage(id) {
|
|
234
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
235
|
+
return internalRequest(
|
|
236
|
+
this.sdk,
|
|
237
|
+
`/messageTemplates/templates/${id}/usage`,
|
|
238
|
+
'GET',
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Version history for a stored message template (save is live; history +
|
|
245
|
+
* restore). A restore always appends a new version — history is
|
|
246
|
+
* append-only, never a destructive rewrite.
|
|
247
|
+
*/
|
|
248
|
+
export class MessageTemplateVersionsService {
|
|
249
|
+
constructor(sdk) {
|
|
250
|
+
this.sdk = sdk;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* List a template's saved versions, newest first.
|
|
255
|
+
* @param {string} templateId
|
|
256
|
+
* @returns {Promise<Object[]>}
|
|
257
|
+
*/
|
|
258
|
+
async list(templateId) {
|
|
259
|
+
this.sdk.validateParams(
|
|
260
|
+
{ templateId },
|
|
261
|
+
{ templateId: { type: 'string', required: true } },
|
|
262
|
+
);
|
|
263
|
+
return internalRequest(
|
|
264
|
+
this.sdk,
|
|
265
|
+
`/messageTemplates/templates/${templateId}/versions`,
|
|
266
|
+
'GET',
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Restore a prior version — writes a NEW version with that version's
|
|
272
|
+
* content and returns the updated template.
|
|
273
|
+
* @param {string} templateId
|
|
274
|
+
* @param {number} version
|
|
275
|
+
* @returns {Promise<Object>}
|
|
276
|
+
*/
|
|
277
|
+
async restore(templateId, version) {
|
|
278
|
+
this.sdk.validateParams(
|
|
279
|
+
{ templateId, version },
|
|
280
|
+
{
|
|
281
|
+
templateId: { type: 'string', required: true },
|
|
282
|
+
version: { type: 'number', required: true },
|
|
283
|
+
},
|
|
284
|
+
);
|
|
285
|
+
return internalRequest(
|
|
286
|
+
this.sdk,
|
|
287
|
+
`/messageTemplates/templates/${templateId}/versions/${version}/restore`,
|
|
288
|
+
'POST',
|
|
289
|
+
);
|
|
290
|
+
}
|
|
185
291
|
}
|
|
186
292
|
|
|
187
293
|
export class MessageTemplatesService {
|
|
@@ -189,6 +295,7 @@ export class MessageTemplatesService {
|
|
|
189
295
|
this.sdk = sdk;
|
|
190
296
|
this.groups = new MessageTemplateGroupsService(sdk);
|
|
191
297
|
this.templates = new MessageTemplatesCrudService(sdk);
|
|
298
|
+
this.templates.versions = new MessageTemplateVersionsService(sdk);
|
|
192
299
|
}
|
|
193
300
|
|
|
194
301
|
/**
|