@unboundcx/sdk 4.13.164 → 4.13.166

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.164",
3
+ "version": "4.13.166",
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",
@@ -34,6 +34,14 @@ export class JourneyDraftService {
34
34
  * Compile the simple-builder step doc into workflowItems/ports/
35
35
  * connections/positions in one transaction. 409s if the journey's
36
36
  * `builderMode` is `'advanced'` (doc is ignored once converted).
37
+ * `get` reads the same draft back (`version`, `doc`, `builderMode`).
38
+ *
39
+ * doc is `{ version: 1, steps }`. Each step has `stepKey`, `type`
40
+ * (`journeyEmail`, `journeySms`, `journeyWait`, `journeyCall`,
41
+ * `journeyTask`, `journeyGoal`, `end`), `settings`, and `outcomes`.
42
+ * An email step sets `settings.journeyEmail.templateId`. A wait sets
43
+ * `settings.journeyWait` (`{ mode, value, unit }`). An outcome is
44
+ * `{ port, target: { kind: 'next'|'step'|'end', stepKey } }`.
37
45
  *
38
46
  * @param {string} journeyId
39
47
  * @param {Object} doc - journeyDoc shape (journeys-plan.md §7.2)
@@ -348,4 +348,31 @@ export class LicensesService {
348
348
  { body: { enabled } },
349
349
  );
350
350
  }
351
+
352
+ /**
353
+ * Brand owner: turn a tenant's trial flag off or change when it expires.
354
+ * Passing the date does not lock the account.
355
+ * @param {string} accountId
356
+ * @param {Object} trial
357
+ * @param {boolean} [trial.isTrial]
358
+ * @param {string|null} [trial.accountExpiresAt] ISO timestamp, or null to clear
359
+ * @returns {Promise<Object>} `{ accountId, isTrial, accountExpiresAt }`
360
+ * @example
361
+ * await sdk.licenses.setBrandAccountTrial('acct-123', { isTrial: false });
362
+ */
363
+ async setBrandAccountTrial(accountId, { isTrial, accountExpiresAt } = {}) {
364
+ this.sdk.validateParams(
365
+ { accountId },
366
+ { accountId: { type: 'string', required: true } },
367
+ );
368
+ const body = {};
369
+ if (isTrial !== undefined) body.isTrial = isTrial;
370
+ if (accountExpiresAt !== undefined) body.accountExpiresAt = accountExpiresAt;
371
+ return internalRequest(
372
+ this.sdk,
373
+ `/permissions/brand/accounts/${accountId}/trial`,
374
+ 'PUT',
375
+ { body },
376
+ );
377
+ }
351
378
  }
@@ -14,13 +14,17 @@ export class EmailTemplatesService {
14
14
  }
15
15
 
16
16
  /**
17
- * Create email template
17
+ * Create email template.
18
+ * Merge fields are Liquid: {{people.firstName}}, {{company.name}}, {{agent.firstName}}, {{journey.name}}.
19
+ * A fallback is {{people.firstName | default: "there"}}.
20
+ * Unsubscribe and email preferences: {{unsubscribeUrl}}. Company mailing address: {{companyAddress}}.
18
21
  * @param {Object} params - Template parameters
19
22
  * @param {string} params.name - Template name (required)
20
23
  * @param {string} params.subject - Template subject (required)
21
- * @param {string} [params.html] - HTML template body
24
+ * @param {string} [params.html] - HTML template body. Saved as a template version and the design file the editor opens.
22
25
  * @param {string} [params.text] - Plain text template body
23
- * @param {Object} [params.design] - Block-tree design JSON (compiled server-side)
26
+ * @param {string} [params.preheader] - Inbox preview text (max 250). Empty string clears it. Client appearance rejects a non-empty preheader.
27
+ * @param {Object} [params.design] - Block-tree design JSON (compiled server-side). With html, html blocks are replaced and other blocks kept.
24
28
  * @param {string} [params.appearance] - `client` or `marketing` (immutable after create)
25
29
  * @param {string} [params.emailType] - `marketing` | `sales` | `transactional` (defaults to `marketing`; separate from `appearance`)
26
30
  * @param {boolean} [params.allowOneOff] - Usable as a one-off / compose send
@@ -55,6 +59,7 @@ export class EmailTemplatesService {
55
59
  subject,
56
60
  html,
57
61
  text,
62
+ preheader,
58
63
  variables,
59
64
  design,
60
65
  appearance,
@@ -65,12 +70,13 @@ export class EmailTemplatesService {
65
70
  category,
66
71
  }) {
67
72
  this.sdk.validateParams(
68
- { name, subject },
73
+ { name, subject, preheader },
69
74
  {
70
75
  name: { type: 'string', required: true },
71
76
  subject: { type: 'string', required: true },
72
77
  html: { type: 'string', required: false },
73
78
  text: { type: 'string', required: false },
79
+ preheader: { type: 'string', required: false },
74
80
  variables: { type: 'array', required: false },
75
81
  design: { type: 'object', required: false },
76
82
  appearance: { type: 'string', required: false },
@@ -88,6 +94,7 @@ export class EmailTemplatesService {
88
94
  subject,
89
95
  html,
90
96
  text,
97
+ preheader,
91
98
  variables,
92
99
  design,
93
100
  appearance,
@@ -110,12 +117,16 @@ export class EmailTemplatesService {
110
117
  /**
111
118
  * Update email template. Only defined fields are sent. Appearance is
112
119
  * immutable after create and should usually be omitted.
120
+ * Merge fields are Liquid: {{people.firstName}}, {{company.name}}, {{agent.firstName}}, {{journey.name}}.
121
+ * A fallback is {{people.firstName | default: "there"}}.
122
+ * Unsubscribe and email preferences: {{unsubscribeUrl}}. Company mailing address: {{companyAddress}}.
113
123
  * @param {string} id - Template ID (required)
114
124
  * @param {Object} params - Update parameters
115
125
  * @param {string} [params.name] - Template name
116
126
  * @param {string} [params.subject] - Template subject
117
- * @param {string} [params.html] - HTML template body
127
+ * @param {string} [params.html] - HTML template body. Replaces the template version and the stored design the editor opens.
118
128
  * @param {string} [params.text] - Plain text template body
129
+ * @param {string} [params.preheader] - Inbox preview text (max 250). Empty string clears it.
119
130
  * @param {Object} [params.design] - Block-tree design JSON (compiled server-side)
120
131
  * @param {string} [params.appearance] - Usually omit; immutable after create
121
132
  * @param {string} [params.emailType] - `marketing` | `sales` | `transactional` (not immutable)
@@ -149,6 +160,7 @@ export class EmailTemplatesService {
149
160
  subject,
150
161
  html,
151
162
  text,
163
+ preheader,
152
164
  variables,
153
165
  design,
154
166
  appearance,
@@ -160,13 +172,14 @@ export class EmailTemplatesService {
160
172
  },
161
173
  ) {
162
174
  this.sdk.validateParams(
163
- { id },
175
+ { id, preheader },
164
176
  {
165
177
  id: { type: 'string', required: true },
166
178
  name: { type: 'string', required: false },
167
179
  subject: { type: 'string', required: false },
168
180
  html: { type: 'string', required: false },
169
181
  text: { type: 'string', required: false },
182
+ preheader: { type: 'string', required: false },
170
183
  variables: { type: 'array', required: false },
171
184
  design: { type: 'object', required: false },
172
185
  appearance: { type: 'string', required: false },
@@ -184,6 +197,7 @@ export class EmailTemplatesService {
184
197
  subject,
185
198
  html,
186
199
  text,
200
+ preheader,
187
201
  variables,
188
202
  design,
189
203
  appearance,
@@ -203,6 +217,49 @@ export class EmailTemplatesService {
203
217
  return result;
204
218
  }
205
219
 
220
+ /**
221
+ * Upload an image for email HTML. Stored public in the email-images folder.
222
+ * Put the returned https URL in the template html.
223
+ * @param {Object} params
224
+ * @param {Object} params.file - File, Buffer, or stream
225
+ * @param {string} [params.fileName] - Original file name
226
+ * @returns {Promise<{id: string, url: string, fileName: string}>}
227
+ */
228
+ async uploadImage({ file, fileName } = {}) {
229
+ this.sdk.validateParams(
230
+ { file, fileName },
231
+ {
232
+ file: { type: 'object', required: true },
233
+ fileName: { type: 'string', required: false },
234
+ },
235
+ );
236
+ if (!this.sdk.storage?.upload) {
237
+ throw new Error('sdk.storage.upload is not available');
238
+ }
239
+ const result = await this.sdk.storage.upload({
240
+ file,
241
+ fileName: fileName || file?.name,
242
+ isPublic: true,
243
+ classification: 'generic',
244
+ folder: 'email-images',
245
+ });
246
+ const uploaded = result?.uploaded?.[0];
247
+ const url = uploaded?.url || '';
248
+ if (!uploaded?.id || !url.startsWith('https://')) {
249
+ const reason = result?.errors?.[0];
250
+ const message =
251
+ (typeof reason === 'string' && reason) ||
252
+ reason?.message ||
253
+ 'Image upload did not return a public https URL. It was not saved.';
254
+ throw new Error(message);
255
+ }
256
+ return {
257
+ id: uploaded.id,
258
+ url,
259
+ fileName: uploaded.fileName || fileName || '',
260
+ };
261
+ }
262
+
206
263
  /**
207
264
  * Delete email template
208
265
  * @param {string} id - Template ID (required)
@@ -241,7 +298,7 @@ export class EmailTemplatesService {
241
298
  }
242
299
 
243
300
  /**
244
- * Get email template by ID
301
+ * Get email template by ID, including html, text, preheader, subject, and name from the stored file the editor uses.
245
302
  * @param {string} id - Template ID (required)
246
303
  * @returns {Promise<Object>} Template details
247
304
  */