@unboundcx/sdk 4.13.127 → 4.13.128
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
|
@@ -25,6 +25,7 @@ import { RingGroupsService } from './services/ringGroups.js';
|
|
|
25
25
|
import { LineGroupsService } from './services/lineGroups.js';
|
|
26
26
|
import { SchedulesService } from './services/schedules/SchedulesService.js';
|
|
27
27
|
import { JourneysService } from './services/journeys/JourneysService.js';
|
|
28
|
+
import { WorkflowTemplatesService } from './services/workflowTemplates/WorkflowTemplatesService.js';
|
|
28
29
|
import { EmergencyService } from './services/emergency.js';
|
|
29
30
|
import { WebchatService } from './services/webchat.js';
|
|
30
31
|
import { CobrowseService } from './services/cobrowse.js';
|
|
@@ -129,6 +130,7 @@ class UnboundSDK extends BaseSDK {
|
|
|
129
130
|
this.lineGroups = new LineGroupsService(this);
|
|
130
131
|
this.schedules = new SchedulesService(this);
|
|
131
132
|
this.journeys = new JourneysService(this);
|
|
133
|
+
this.workflowTemplates = new WorkflowTemplatesService(this);
|
|
132
134
|
this.emergency = new EmergencyService(this);
|
|
133
135
|
this.webchat = new WebchatService(this);
|
|
134
136
|
this.cobrowse = new CobrowseService(this);
|
|
@@ -336,6 +338,8 @@ export { SchedulesService } from './services/schedules/SchedulesService.js';
|
|
|
336
338
|
export { TimeOffService } from './services/schedules/TimeOffService.js';
|
|
337
339
|
export { JourneysService } from './services/journeys/JourneysService.js';
|
|
338
340
|
export { JourneyMembersService } from './services/journeys/JourneyMembersService.js';
|
|
341
|
+
export { JourneyDraftService } from './services/journeys/JourneysService.js';
|
|
342
|
+
export { WorkflowTemplatesService } from './services/workflowTemplates/WorkflowTemplatesService.js';
|
|
339
343
|
export { EmergencyService } from './services/emergency.js';
|
|
340
344
|
export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
|
|
341
345
|
export { CobrowseService, CobrowseVisitorService } from './services/cobrowse.js';
|
|
@@ -376,3 +380,4 @@ export {
|
|
|
376
380
|
DataExportService,
|
|
377
381
|
} from './services/dataImport.js';
|
|
378
382
|
export { BaseSDK } from './base.js';
|
|
383
|
+
export { layoutJourney, MAX_LANES as JOURNEY_LAYOUT_MAX_LANES } from './lib/journeyLayout.js';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Shared journey step-list layout (journeys-plan.md §7.3). Pure function,
|
|
2
|
+
// no DOM/Svelte — consumed by the API compiler (positions written into
|
|
3
|
+
// workflowItems.position) and the client's step-list / read-only canvas
|
|
4
|
+
// preview, so geometry never drifts between the two.
|
|
5
|
+
//
|
|
6
|
+
// Node width = max(240, pad + portCount * portWidth) so a step with more
|
|
7
|
+
// outcome ports (e.g. journeySms with several expected-reply rows) renders
|
|
8
|
+
// wide enough for all of them. Main path sits in column 0, top to bottom in
|
|
9
|
+
// doc order. A side path (one outcome's target.kind === 'side') renders as
|
|
10
|
+
// a linear vertical stack in the next column to the right, in outcome
|
|
11
|
+
// order; the row the branch step occupies grows tall enough to hold the
|
|
12
|
+
// tallest concurrent side path. Forward jumps (an outcome's target.kind ===
|
|
13
|
+
// 'step' pointing at a later main-path step) get a lane in a left-gutter
|
|
14
|
+
// reserved for wire routing, bounded by MAX_LANES — the same bound
|
|
15
|
+
// app1-client's wireLayout.js uses for the advanced canvas, kept in sync
|
|
16
|
+
// here as a literal with this comment rather than a cross-package import.
|
|
17
|
+
export const MAX_LANES = 6;
|
|
18
|
+
|
|
19
|
+
const DEFAULTS = {
|
|
20
|
+
portWidth: 56,
|
|
21
|
+
pad: 48,
|
|
22
|
+
nodeHeight: 90,
|
|
23
|
+
rowGap: 40,
|
|
24
|
+
colGap: 80,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function portCount(step) {
|
|
28
|
+
return Math.max(1, (step?.outcomes || []).length);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function widthForStep(step, { pad, portWidth }) {
|
|
32
|
+
return Math.max(240, pad + portCount(step) * portWidth);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Depth-first walk collecting every step (main + nested side-path steps) so
|
|
36
|
+
// widths can be computed for all of them in one pass.
|
|
37
|
+
function collectAllSteps(steps, opts, widths, acc = []) {
|
|
38
|
+
for (const step of steps || []) {
|
|
39
|
+
if (!step?.stepKey) continue;
|
|
40
|
+
acc.push(step);
|
|
41
|
+
widths[step.stepKey] = widthForStep(step, opts);
|
|
42
|
+
for (const outcome of step.outcomes || []) {
|
|
43
|
+
if (outcome?.target?.kind === 'side' && Array.isArray(outcome.target.steps)) {
|
|
44
|
+
collectAllSteps(outcome.target.steps, opts, widths, acc);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return acc;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function layoutJourney(doc, opts = {}) {
|
|
52
|
+
const options = { ...DEFAULTS, ...opts };
|
|
53
|
+
const { pad, nodeHeight, rowGap, colGap } = options;
|
|
54
|
+
const steps = Array.isArray(doc?.steps) ? doc.steps : [];
|
|
55
|
+
|
|
56
|
+
const widths = {};
|
|
57
|
+
const positions = {};
|
|
58
|
+
const lanes = {};
|
|
59
|
+
|
|
60
|
+
collectAllSteps(steps, options, widths);
|
|
61
|
+
|
|
62
|
+
const mainIndex = new Map();
|
|
63
|
+
steps.forEach((step, i) => mainIndex.set(step.stepKey, i));
|
|
64
|
+
|
|
65
|
+
// --- positions: main path column 0, side paths to the right ---
|
|
66
|
+
const colWidths = [];
|
|
67
|
+
colWidths[0] = Math.max(240, ...steps.map((s) => widths[s.stepKey] || 240));
|
|
68
|
+
|
|
69
|
+
let y = pad;
|
|
70
|
+
for (const step of steps) {
|
|
71
|
+
positions[step.stepKey] = { x: pad, y };
|
|
72
|
+
let rowHeight = nodeHeight;
|
|
73
|
+
let col = 1;
|
|
74
|
+
|
|
75
|
+
for (const outcome of step.outcomes || []) {
|
|
76
|
+
if (outcome?.target?.kind === 'side' && Array.isArray(outcome.target.steps)) {
|
|
77
|
+
const sideSteps = outcome.target.steps.filter((s) => s?.stepKey);
|
|
78
|
+
if (!sideSteps.length) {
|
|
79
|
+
col += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
colWidths[col] = Math.max(
|
|
83
|
+
colWidths[col] || 240,
|
|
84
|
+
...sideSteps.map((s) => widths[s.stepKey] || 240),
|
|
85
|
+
);
|
|
86
|
+
const xOffset =
|
|
87
|
+
pad + colWidths.slice(0, col).reduce((sum, w) => sum + w + colGap, 0);
|
|
88
|
+
let sideY = y;
|
|
89
|
+
sideSteps.forEach((sideStep) => {
|
|
90
|
+
positions[sideStep.stepKey] = { x: xOffset, y: sideY };
|
|
91
|
+
sideY += nodeHeight + rowGap;
|
|
92
|
+
});
|
|
93
|
+
const sideHeight =
|
|
94
|
+
sideSteps.length * nodeHeight + (sideSteps.length - 1) * rowGap;
|
|
95
|
+
rowHeight = Math.max(rowHeight, sideHeight);
|
|
96
|
+
col += 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
y += rowHeight + rowGap;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- lanes: forward-jump wires (target.kind === 'step', later index) ---
|
|
104
|
+
const forwardJumps = [];
|
|
105
|
+
steps.forEach((step, i) => {
|
|
106
|
+
for (const outcome of step.outcomes || []) {
|
|
107
|
+
if (outcome?.target?.kind === 'step') {
|
|
108
|
+
const j = mainIndex.get(outcome.target.stepKey);
|
|
109
|
+
if (j != null && j > i) {
|
|
110
|
+
forwardJumps.push({ from: i, to: j, stepKey: step.stepKey, port: outcome.port });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
forwardJumps.sort((a, b) => a.from - b.from || a.to - b.to);
|
|
116
|
+
|
|
117
|
+
const laneEndsAt = [];
|
|
118
|
+
for (const jump of forwardJumps) {
|
|
119
|
+
let lane = laneEndsAt.findIndex(
|
|
120
|
+
(endsAt) => endsAt === undefined || endsAt <= jump.from,
|
|
121
|
+
);
|
|
122
|
+
if (lane === -1) {
|
|
123
|
+
lane = Math.min(laneEndsAt.length, MAX_LANES - 1);
|
|
124
|
+
}
|
|
125
|
+
laneEndsAt[lane] = jump.to;
|
|
126
|
+
lanes[`${jump.stepKey}:${jump.port}`] = lane;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return { positions, widths, lanes };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default { layoutJourney, MAX_LANES };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.128",
|
|
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",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"proto/**/*.proto",
|
|
45
45
|
"schemas/**/*.js",
|
|
46
46
|
"schemas/**/*.md",
|
|
47
|
+
"lib/**/*.js",
|
|
47
48
|
"README.md",
|
|
48
49
|
"LICENSE"
|
|
49
50
|
],
|
|
@@ -63,6 +64,9 @@
|
|
|
63
64
|
},
|
|
64
65
|
"./schemas/*": {
|
|
65
66
|
"import": "./schemas/*.js"
|
|
67
|
+
},
|
|
68
|
+
"./lib/*": {
|
|
69
|
+
"import": "./lib/*.js"
|
|
66
70
|
}
|
|
67
71
|
},
|
|
68
72
|
"scripts": {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { internalRequest } from '../../base.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple-builder draft surface -- `sdk.journeys.draft.*` (journeys-plan.md
|
|
5
|
+
* §7.3/§7.4, P4 compile area). Custom routes mounted at
|
|
6
|
+
* `/journeys/:id/draft*`, `/journeys/:id/publish-check`,
|
|
7
|
+
* `/journeys/:id/convert-to-advanced`.
|
|
8
|
+
*
|
|
9
|
+
* @see app1-api src/services/journeys/routes.js
|
|
10
|
+
* @see app1-api src/services/journeys/controllers/compile.js
|
|
11
|
+
*/
|
|
12
|
+
export class JourneyDraftService {
|
|
13
|
+
constructor(sdk) {
|
|
14
|
+
this.sdk = sdk;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} journeyId
|
|
19
|
+
* @returns {Promise<Object>} { version, doc, builderMode }
|
|
20
|
+
*/
|
|
21
|
+
async get(journeyId) {
|
|
22
|
+
this.sdk.validateParams(
|
|
23
|
+
{ journeyId },
|
|
24
|
+
{ journeyId: { type: 'string', required: true } },
|
|
25
|
+
);
|
|
26
|
+
return await internalRequest(
|
|
27
|
+
this.sdk,
|
|
28
|
+
`/journeys/${journeyId}/draft`,
|
|
29
|
+
'GET',
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Compile the simple-builder step doc into workflowItems/ports/
|
|
35
|
+
* connections/positions in one transaction. 409s if the journey's
|
|
36
|
+
* `builderMode` is `'advanced'` (doc is ignored once converted).
|
|
37
|
+
*
|
|
38
|
+
* @param {string} journeyId
|
|
39
|
+
* @param {Object} doc - journeyDoc shape (journeys-plan.md §7.2)
|
|
40
|
+
* @returns {Promise<Object>} { doc (with dayOffset), itemsByStepKey }
|
|
41
|
+
*/
|
|
42
|
+
async saveSteps(journeyId, doc) {
|
|
43
|
+
this.sdk.validateParams(
|
|
44
|
+
{ journeyId, doc },
|
|
45
|
+
{
|
|
46
|
+
journeyId: { type: 'string', required: true },
|
|
47
|
+
doc: { type: 'object', required: true },
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
return await internalRequest(
|
|
51
|
+
this.sdk,
|
|
52
|
+
`/journeys/${journeyId}/draft/steps`,
|
|
53
|
+
'PUT',
|
|
54
|
+
{ body: { doc } },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One-way: `simple` -> `advanced` only. Once advanced, the journeyDoc is
|
|
60
|
+
* ignored and compile is unavailable (`saveSteps` 409s).
|
|
61
|
+
*
|
|
62
|
+
* @param {string} journeyId
|
|
63
|
+
* @returns {Promise<Object>} Updated journey
|
|
64
|
+
*/
|
|
65
|
+
async convertToAdvanced(journeyId) {
|
|
66
|
+
this.sdk.validateParams(
|
|
67
|
+
{ journeyId },
|
|
68
|
+
{ journeyId: { type: 'string', required: true } },
|
|
69
|
+
);
|
|
70
|
+
return await internalRequest(
|
|
71
|
+
this.sdk,
|
|
72
|
+
`/journeys/${journeyId}/convert-to-advanced`,
|
|
73
|
+
'POST',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} journeyId
|
|
79
|
+
* @returns {Promise<Object>} { blocking, warnings }
|
|
80
|
+
*/
|
|
81
|
+
async publishCheck(journeyId) {
|
|
82
|
+
this.sdk.validateParams(
|
|
83
|
+
{ journeyId },
|
|
84
|
+
{ journeyId: { type: 'string', required: true } },
|
|
85
|
+
);
|
|
86
|
+
return await internalRequest(
|
|
87
|
+
this.sdk,
|
|
88
|
+
`/journeys/${journeyId}/publish-check`,
|
|
89
|
+
'GET',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { internalRequest } from '../../base.js';
|
|
2
2
|
import { JourneyMembersService } from './JourneyMembersService.js';
|
|
3
|
+
import { JourneyDraftService } from './JourneyDraftService.js';
|
|
4
|
+
|
|
5
|
+
function pickDefined(fields) {
|
|
6
|
+
const body = {};
|
|
7
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
8
|
+
if (value !== undefined) body[key] = value;
|
|
9
|
+
}
|
|
10
|
+
return body;
|
|
11
|
+
}
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
14
|
* Journeys (journeys-plan.md §2/§4) -- `sdk.journeys.*`.
|
|
@@ -21,6 +30,7 @@ export class JourneysService {
|
|
|
21
30
|
this.members = new JourneyMembersService(sdk);
|
|
22
31
|
this.types = new JourneyTypesService(sdk);
|
|
23
32
|
this.goals = new JourneyGoalsService(sdk);
|
|
33
|
+
this.draft = new JourneyDraftService(sdk);
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
/**
|
|
@@ -103,6 +113,95 @@ export class JourneysService {
|
|
|
103
113
|
{},
|
|
104
114
|
);
|
|
105
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* No-send dry run: per step, the resolved channel (override -> primary),
|
|
119
|
+
* rendered message, and landing date for a given person (journeys-plan.md
|
|
120
|
+
* §7.6, P4 templates area).
|
|
121
|
+
*
|
|
122
|
+
* @param {string} id
|
|
123
|
+
* @param {Object} params
|
|
124
|
+
* @param {string} params.peopleId
|
|
125
|
+
* @returns {Promise<Object>} { steps: [{ stepKey, channel, message, landingAt }] }
|
|
126
|
+
*/
|
|
127
|
+
async preview(id, { peopleId } = {}) {
|
|
128
|
+
this.sdk.validateParams(
|
|
129
|
+
{ id, peopleId },
|
|
130
|
+
{
|
|
131
|
+
id: { type: 'string', required: true },
|
|
132
|
+
peopleId: { type: 'string', required: true },
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
return await internalRequest(this.sdk, `/journeys/${id}/preview`, 'GET', {
|
|
136
|
+
query: { peopleId },
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Enrols the caller as an `isTest` member: sends redirect to the caller's
|
|
142
|
+
* own email/number, waits compress to `TEST_RUN_WAIT_SECONDS`, and the
|
|
143
|
+
* member is excluded from stats/event counts.
|
|
144
|
+
*
|
|
145
|
+
* @param {string} id
|
|
146
|
+
* @param {Object} [params]
|
|
147
|
+
* @param {string} [params.peopleId]
|
|
148
|
+
* @param {string} [params.testEmail] - override destination
|
|
149
|
+
* @param {string} [params.testPhone] - override destination
|
|
150
|
+
* @returns {Promise<Object>} Enrolled test member
|
|
151
|
+
*/
|
|
152
|
+
async testRun(id, { peopleId, testEmail, testPhone } = {}) {
|
|
153
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
154
|
+
return await internalRequest(
|
|
155
|
+
this.sdk,
|
|
156
|
+
`/journeys/${id}/test-run`,
|
|
157
|
+
'POST',
|
|
158
|
+
{ body: pickDefined({ peopleId, testEmail, testPhone }) },
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Export + install into the same account, keeping template refs
|
|
164
|
+
* (journeys-plan.md §7.7).
|
|
165
|
+
*
|
|
166
|
+
* @param {string} id
|
|
167
|
+
* @param {Object} [params]
|
|
168
|
+
* @param {string} [params.name]
|
|
169
|
+
* @returns {Promise<Object>} New journey + workflow + draft version
|
|
170
|
+
*/
|
|
171
|
+
async clone(id, { name } = {}) {
|
|
172
|
+
this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
|
|
173
|
+
return await internalRequest(this.sdk, `/journeys/${id}/clone`, 'POST', {
|
|
174
|
+
body: pickDefined({ name }),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Save this journey into the account's template library
|
|
180
|
+
* (`workflowTemplates`, journeys-plan.md §7.7).
|
|
181
|
+
*
|
|
182
|
+
* @param {string} id
|
|
183
|
+
* @param {Object} params
|
|
184
|
+
* @param {string} params.name
|
|
185
|
+
* @param {string} [params.summary]
|
|
186
|
+
* @param {string} [params.category]
|
|
187
|
+
* @param {'platform'|'account'} [params.visibility]
|
|
188
|
+
* @returns {Promise<Object>} Created workflowTemplates row
|
|
189
|
+
*/
|
|
190
|
+
async saveAsTemplate(id, { name, summary, category, visibility } = {}) {
|
|
191
|
+
this.sdk.validateParams(
|
|
192
|
+
{ id, name },
|
|
193
|
+
{
|
|
194
|
+
id: { type: 'string', required: true },
|
|
195
|
+
name: { type: 'string', required: true },
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
return await internalRequest(
|
|
199
|
+
this.sdk,
|
|
200
|
+
`/journeys/${id}/save-as-template`,
|
|
201
|
+
'POST',
|
|
202
|
+
{ body: pickDefined({ name, summary, category, visibility }) },
|
|
203
|
+
);
|
|
204
|
+
}
|
|
106
205
|
}
|
|
107
206
|
|
|
108
207
|
/**
|
|
@@ -213,4 +312,4 @@ class JourneyGoalsService {
|
|
|
213
312
|
}
|
|
214
313
|
}
|
|
215
314
|
|
|
216
|
-
export { JourneyTypesService, JourneyGoalsService };
|
|
315
|
+
export { JourneyTypesService, JourneyGoalsService, JourneyDraftService };
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|