@unboundcx/sdk 2.3.0 → 2.4.0

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": "2.3.0",
3
+ "version": "2.4.0",
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",
@@ -209,9 +209,10 @@ export class PhoneNumbersService {
209
209
  * Check portability of phone numbers
210
210
  * @param {Object} params
211
211
  * @param {string[]} params.phoneNumbers - Array of +E.164 formatted phone numbers
212
+ * @param {string} [params.portingOrderId] - Optional porting order ID to save results to
212
213
  * @returns {Promise<Object>} Portability check results
213
214
  */
214
- async checkPortability({ phoneNumbers }) {
215
+ async checkPortability({ phoneNumbers, portingOrderId }) {
215
216
  this.sdk.validateParams(
216
217
  { phoneNumbers },
217
218
  {
@@ -219,21 +220,22 @@ export class PhoneNumbersService {
219
220
  },
220
221
  );
221
222
 
223
+ const body = { phoneNumbers };
224
+ if (portingOrderId) body.portingOrderId = portingOrderId;
225
+
222
226
  const result = await this.sdk._fetch(
223
227
  '/phoneNumbers/porting/portability-check',
224
228
  'POST',
225
229
  {
226
- body: { phoneNumbers },
230
+ body: body,
227
231
  },
228
232
  );
229
233
  return result;
230
234
  }
231
235
 
232
236
  /**
233
- * Create a draft porting order (no validation - can be built incrementally)
237
+ * Create a draft porting order (no phone numbers - add them via checkPortability)
234
238
  * @param {Object} params
235
- * @param {string[]} [params.phoneNumbers] - Array of +E.164 formatted phone numbers
236
- * @param {Object[]} [params.phoneNumberBlocks] - Array of phone number blocks
237
239
  * @param {string} [params.customerReference] - Customer-specified reference number
238
240
  * @param {Object} [params.endUser] - End user information
239
241
  * @param {Object} [params.endUser.admin] - Admin contact info
@@ -252,38 +254,34 @@ export class PhoneNumbersService {
252
254
  * @param {string} [params.endUser.location.postalCode] - ZIP/postal code
253
255
  * @param {string} [params.endUser.location.countryCode] - 2-letter country code
254
256
  * @param {Object} [params.activationSettings] - Activation preferences
255
- * @param {string} [params.activationSettings.focDatetimeRequested] - Requested FOC date/time
256
- * @param {string} [params.activationSettings.focDatetimeActual] - Actual FOC date/time
257
- * @param {boolean} [params.activationSettings.fastPortEligible] - Fast port eligibility
258
- * @param {string} [params.activationSettings.activationStatus] - Activation status
259
- * @param {Object} [params.phoneNumberConfiguration] - Phone number config
260
- * @param {string} [params.phoneNumberConfiguration.billingGroupId] - Billing group ID
261
- * @param {string} [params.phoneNumberConfiguration.connectionId] - Connection ID
262
- * @param {string} [params.phoneNumberConfiguration.messagingProfileId] - Messaging profile ID
263
- * @param {string} [params.phoneNumberConfiguration.emergencyAddressId] - Emergency address ID
264
- * @param {string} [params.phoneNumberConfiguration.phoneNumberType] - Phone number type
265
- * @param {string} [params.phoneNumberConfiguration.description] - Description
257
+ * @param {string} [params.activationSettings.focDatetimeRequested] - Requested FOC date/time (ISO 8601 UTC)
258
+ * @param {boolean} [params.activationSettings.fastPortEligible] - Request fast port if available
266
259
  * @param {string[]} [params.tags] - Array of tags for organization
267
260
  * @returns {Promise<Object>} Created draft porting order with ID and status 'draft'
261
+ * @example
262
+ * // Create empty draft order, then add numbers via checkPortability
263
+ * const order = await sdk.phoneNumbers.createPortingOrder({
264
+ * customerReference: "CUST-123",
265
+ * endUser: { admin: { entityName: "My Company" } }
266
+ * });
267
+ *
268
+ * // Add phone numbers with validation
269
+ * await sdk.phoneNumbers.checkPortability({
270
+ * phoneNumbers: ["+15551234567"],
271
+ * portingOrderId: order.id
272
+ * });
268
273
  */
269
274
  async createPortingOrder({
270
- phoneNumbers,
271
- phoneNumberBlocks,
272
275
  customerReference,
273
276
  endUser,
274
277
  activationSettings,
275
- phoneNumberConfiguration,
276
278
  tags
277
279
  } = {}) {
278
- // No validation - creates draft order that can be built incrementally
280
+ // Creates draft order without phone numbers - use checkPortability to add them
279
281
  const body = {};
280
-
281
- if (phoneNumbers) body.phoneNumbers = phoneNumbers;
282
- if (phoneNumberBlocks) body.phoneNumberBlocks = phoneNumberBlocks;
283
282
  if (customerReference) body.customerReference = customerReference;
284
283
  if (endUser) body.endUser = endUser;
285
284
  if (activationSettings) body.activationSettings = activationSettings;
286
- if (phoneNumberConfiguration) body.phoneNumberConfiguration = phoneNumberConfiguration;
287
285
  if (tags) body.tags = tags;
288
286
 
289
287
  const result = await this.sdk._fetch(
@@ -324,7 +322,20 @@ export class PhoneNumbersService {
324
322
  return result;
325
323
  }
326
324
 
327
- async getPortingOrder(id, { includePhoneNumbers = true } = {}) {
325
+ /**
326
+ * Get a porting order with optional related data
327
+ * @param {string} id - Porting order ID
328
+ * @param {Object} [options]
329
+ * @param {boolean} [options.includePhoneNumbers=true] - Include phone numbers array
330
+ * @param {boolean} [options.includeExceptions=true] - Include exceptions array
331
+ * @param {boolean} [options.includeDocuments=true] - Include documents array with upload status
332
+ * @returns {Promise<Object>} Porting order with requested related data
333
+ */
334
+ async getPortingOrder(id, {
335
+ includePhoneNumbers = true,
336
+ includeExceptions = true,
337
+ includeDocuments = true
338
+ } = {}) {
328
339
  this.sdk.validateParams(
329
340
  { id },
330
341
  {
@@ -335,6 +346,10 @@ export class PhoneNumbersService {
335
346
  const params = new URLSearchParams();
336
347
  if (includePhoneNumbers !== undefined)
337
348
  params.append('includePhoneNumbers', includePhoneNumbers);
349
+ if (includeExceptions !== undefined)
350
+ params.append('includeExceptions', includeExceptions);
351
+ if (includeDocuments !== undefined)
352
+ params.append('includeDocuments', includeDocuments);
338
353
 
339
354
  const queryString = params.toString();
340
355
  const url = queryString
@@ -346,18 +361,19 @@ export class PhoneNumbersService {
346
361
  }
347
362
 
348
363
  /**
349
- * Update a draft porting order (same parameters as createPortingOrder)
364
+ * Update a draft porting order (order info only - manage numbers via checkPortability)
350
365
  * @param {string} id - Porting order ID
351
- * @param {Object} params - Same parameters as createPortingOrder
366
+ * @param {Object} params - Order information to update
367
+ * @param {string} [params.customerReference] - Customer-specified reference number
368
+ * @param {Object} [params.endUser] - End user information
369
+ * @param {Object} [params.activationSettings] - Activation preferences
370
+ * @param {string[]} [params.tags] - Array of tags for organization
352
371
  * @returns {Promise<Object>} Updated porting order
353
372
  */
354
373
  async updatePortingOrder(id, {
355
- phoneNumbers,
356
- phoneNumberBlocks,
357
374
  customerReference,
358
375
  endUser,
359
376
  activationSettings,
360
- phoneNumberConfiguration,
361
377
  tags
362
378
  } = {}) {
363
379
  this.sdk.validateParams(
@@ -369,12 +385,9 @@ export class PhoneNumbersService {
369
385
 
370
386
  const body = {};
371
387
 
372
- if (phoneNumbers) body.phoneNumbers = phoneNumbers;
373
- if (phoneNumberBlocks) body.phoneNumberBlocks = phoneNumberBlocks;
374
388
  if (customerReference) body.customerReference = customerReference;
375
389
  if (endUser) body.endUser = endUser;
376
390
  if (activationSettings) body.activationSettings = activationSettings;
377
- if (phoneNumberConfiguration) body.phoneNumberConfiguration = phoneNumberConfiguration;
378
391
  if (tags) body.tags = tags;
379
392
 
380
393
  const result = await this.sdk._fetch(
@@ -415,6 +428,30 @@ export class PhoneNumbersService {
415
428
  return result;
416
429
  }
417
430
 
431
+ /**
432
+ * Delete/cancel a porting order (soft delete)
433
+ * - Draft orders: Immediately cancelled locally
434
+ * - Submitted orders: Cancelled via Telnyx, then status updated to cancel-pending
435
+ * - Cannot delete orders within 48 hours of FOC date
436
+ * - Cannot delete already completed or cancelled orders
437
+ * @param {string} id - Porting order ID
438
+ * @returns {Promise<Object>} Cancellation result with new status
439
+ */
440
+ async deletePortingOrder(id) {
441
+ this.sdk.validateParams(
442
+ { id },
443
+ {
444
+ id: { type: 'string', required: true },
445
+ },
446
+ );
447
+
448
+ const result = await this.sdk._fetch(
449
+ `/phoneNumbers/porting/orders/${id}`,
450
+ 'DELETE'
451
+ );
452
+ return result;
453
+ }
454
+
418
455
  async uploadPortingDocument({
419
456
  filename,
420
457
  fileContent,