@unboundcx/sdk 4.13.126 → 4.13.127

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
@@ -339,7 +339,10 @@ export { JourneyMembersService } from './services/journeys/JourneyMembersService
339
339
  export { EmergencyService } from './services/emergency.js';
340
340
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
341
341
  export { CobrowseService, CobrowseVisitorService } from './services/cobrowse.js';
342
- export { MessageTemplatesService } from './services/messageTemplates.js';
342
+ export {
343
+ MessageTemplatesService,
344
+ MessageTemplateVersionsService,
345
+ } from './services/messageTemplates.js';
343
346
  export { WebchatVisitorService } from './services/webchat/VisitorService.js';
344
347
  export { ExternalOAuthService } from './services/externalOAuth.js';
345
348
  export { GoogleCalendarService } from './services/googleCalendar.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.126",
3
+ "version": "4.13.127",
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",
@@ -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
- * @returns {Promise<Object>}
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
  /**