@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.
Files changed (40) hide show
  1. package/README.md +0 -7
  2. package/index.js +31 -1
  3. package/lib/journeyLayout.js +132 -0
  4. package/package.json +5 -2
  5. package/services/journeys/JourneyDraftService.js +92 -0
  6. package/services/journeys/JourneyGoalsService.js +57 -0
  7. package/services/journeys/JourneyMembersService.js +246 -0
  8. package/services/journeys/JourneyTypesService.js +59 -0
  9. package/services/journeys/JourneyWorklistService.js +74 -0
  10. package/services/journeys/JourneysService.js +392 -0
  11. package/services/layouts.js +13 -4
  12. package/services/messageTemplates.js +109 -2
  13. package/services/messaging/EmailTemplatesService.js +10 -2
  14. package/services/messaging/SmsService.js +0 -3
  15. package/services/messaging.js +0 -2
  16. package/services/objects.js +12 -39
  17. package/services/operatorPanels.js +226 -0
  18. package/services/parking.js +121 -0
  19. package/services/permissions.js +21 -0
  20. package/services/phoneNumbers/carrier.js +60 -0
  21. package/services/phoneNumbers/cnam.js +42 -0
  22. package/services/phoneNumbers/index.js +27 -0
  23. package/services/phoneNumbers/order.js +88 -0
  24. package/services/phoneNumbers/porting-activity.js +289 -0
  25. package/services/phoneNumbers/porting-orders.js +318 -0
  26. package/services/phoneNumbers/search.js +181 -0
  27. package/services/phoneNumbers/update.js +94 -0
  28. package/services/phoneNumbers.js +2 -1037
  29. package/services/recents.js +16 -0
  30. package/services/schedules/SchedulesService.js +232 -0
  31. package/services/schedules/TimeOffService.js +131 -0
  32. package/services/skills.js +207 -0
  33. package/services/taskRouter/MetricsService.js +3 -0
  34. package/services/taskRouter/QueueService.js +343 -0
  35. package/services/taskRouter/TaskRouterService.js +2 -0
  36. package/services/taskRouter/TaskService.js +70 -10
  37. package/services/voice.js +47 -25
  38. package/services/voicemailDrops.js +268 -0
  39. package/services/workflowTemplates/WorkflowTemplatesService.js +68 -0
  40. package/services/messaging/SmsTemplatesService.js +0 -125
@@ -0,0 +1,88 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ // phoneNumbers/order.js :: order/remove methods :: buying + releasing numbers, bulk carrier auto-create
4
+ export const orderMethods = {
5
+ async order({ phoneNumbers, name }) {
6
+ this.sdk.validateParams(
7
+ { phoneNumbers },
8
+ {
9
+ phoneNumbers: { type: 'array', required: true },
10
+ name: { type: 'string', required: false },
11
+ },
12
+ );
13
+
14
+ const orderData = { phoneNumbers };
15
+ if (name) orderData.name = name;
16
+
17
+ const params = {
18
+ body: orderData,
19
+ };
20
+
21
+ const result = await internalRequest(this.sdk, '/phoneNumbers/order', 'POST', params);
22
+ return result;
23
+ },
24
+
25
+ async remove(phoneNumber) {
26
+ this.sdk.validateParams(
27
+ { phoneNumber },
28
+ {
29
+ phoneNumber: { type: 'string', required: true },
30
+ },
31
+ );
32
+
33
+ const result = await internalRequest(this.sdk,
34
+ `/phoneNumbers/${phoneNumber}`,
35
+ 'DELETE',
36
+ );
37
+ return result;
38
+ },
39
+
40
+ /**
41
+ * Auto-create porting orders by grouping phone numbers by carrier
42
+ *
43
+ * Analyzes phone numbers using internal LRN lookup, groups them by carrier,
44
+ * and either previews the groupings (dry run) or creates separate porting
45
+ * orders for each carrier group.
46
+ *
47
+ * @param {Object} params
48
+ * @param {string[]} params.phoneNumbers - Array of +E.164 formatted phone numbers (max 100)
49
+ * @param {string} params.name - Base name for orders (will be appended with carrier names)
50
+ * @param {boolean} [params.dryRun=false] - If true, returns preview without creating orders
51
+ * @returns {Promise<Object>} Carrier groups and creation results
52
+ * @example
53
+ * // Preview carrier groupings
54
+ * const preview = await sdk.phoneNumbers.autoCreateOrders({
55
+ * phoneNumbers: ['+15551234567', '+15551234568', '+15551234569'],
56
+ * name: 'Q1 2025 Port',
57
+ * dryRun: true
58
+ * });
59
+ * // Returns carrier groups with proposed order names
60
+ *
61
+ * // Create orders for each carrier
62
+ * const result = await sdk.phoneNumbers.autoCreateOrders({
63
+ * phoneNumbers: ['+15551234567', '+15551234568', '+15551234569'],
64
+ * name: 'Q1 2025 Port',
65
+ * dryRun: false
66
+ * });
67
+ * // Returns created orders and any errors
68
+ */
69
+ async autoCreateOrders({ phoneNumbers, name, dryRun = false }) {
70
+ this.sdk.validateParams(
71
+ { phoneNumbers, name },
72
+ {
73
+ phoneNumbers: { type: 'array', required: true },
74
+ name: { type: 'string', required: true },
75
+ dryRun: { type: 'boolean', required: false },
76
+ },
77
+ );
78
+
79
+ const result = await internalRequest(this.sdk,
80
+ '/phoneNumbers/porting/auto-create-orders',
81
+ 'POST',
82
+ {
83
+ body: { phoneNumbers, name, dryRun },
84
+ },
85
+ );
86
+ return result;
87
+ },
88
+ };
@@ -0,0 +1,289 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ // phoneNumbers/porting-activity.js :: porting documents, LOA e-sign, events, sync, exceptions, comments
4
+ export const portingActivityMethods = {
5
+
6
+ /**
7
+ * Attach or update a document for a porting order
8
+ *
9
+ * @param {Object} params
10
+ * @param {string} params.portingOrderId - Porting order ID
11
+ * @param {string} [params.storageId] - Storage ID of uploaded file (null to clear)
12
+ * @param {string} [params.documentType='loa'] - Document type (loa, bill, csr, etc.)
13
+ * @param {boolean} [params.isRequired=false] - Whether document is required
14
+ * @param {string} [params.documentId] - Optional: Update existing document by ID
15
+ * @returns {Promise<Object>} Document attachment result with action (created/updated)
16
+ */
17
+ async attachPortingDocument({
18
+ portingOrderId,
19
+ storageId = null,
20
+ documentType = 'loa',
21
+ isRequired = false,
22
+ documentId = null,
23
+ }) {
24
+ this.sdk.validateParams(
25
+ { portingOrderId, documentType },
26
+ {
27
+ portingOrderId: { type: 'string', required: true },
28
+ documentType: { type: 'string', required: true },
29
+ },
30
+ );
31
+
32
+ const body = {
33
+ portingOrderId,
34
+ storageId,
35
+ documentType,
36
+ isRequired,
37
+ };
38
+
39
+ if (documentId) body.documentId = documentId;
40
+
41
+ const result = await internalRequest(this.sdk,
42
+ '/phoneNumbers/porting/documents',
43
+ 'POST',
44
+ {
45
+ body: body,
46
+ },
47
+ );
48
+ return result;
49
+ },
50
+
51
+ /**
52
+ * Start e-sign for a porting LOA (`send` emails the signer, `present` returns a URL).
53
+ *
54
+ * @param {Object} params
55
+ * @param {string} params.portingOrderId
56
+ * @param {string} params.signerName
57
+ * @param {string} params.mode - `send` or `present`
58
+ * @param {string} [params.signerTitle]
59
+ * @param {string} [params.signerEmail] - required when mode is send
60
+ * @returns {Promise<Object>} `{ packageId, status, signers, presentUrl?, presentExpiresAt? }`
61
+ */
62
+ async generateLoa({
63
+ portingOrderId,
64
+ signerName,
65
+ signerTitle,
66
+ signerEmail,
67
+ mode,
68
+ }) {
69
+ this.sdk.validateParams(
70
+ { portingOrderId, signerName, mode },
71
+ {
72
+ portingOrderId: { type: 'string', required: true },
73
+ signerName: { type: 'string', required: true },
74
+ mode: { type: 'string', required: true },
75
+ signerTitle: { type: 'string', required: false },
76
+ signerEmail: { type: 'string', required: false },
77
+ },
78
+ );
79
+
80
+ const body = { signerName, mode };
81
+ if (signerTitle !== undefined) body.signerTitle = signerTitle;
82
+ if (signerEmail !== undefined) body.signerEmail = signerEmail;
83
+
84
+ const result = await internalRequest(
85
+ this.sdk,
86
+ `/phoneNumbers/porting/orders/${encodeURIComponent(
87
+ portingOrderId,
88
+ )}/generate-loa`,
89
+ 'POST',
90
+ { body },
91
+ );
92
+ return result;
93
+ },
94
+
95
+ async getPortingEvents(id, { page, limit } = {}) {
96
+ this.sdk.validateParams(
97
+ { id },
98
+ {
99
+ id: { type: 'string', required: true },
100
+ },
101
+ );
102
+
103
+ const params = new URLSearchParams();
104
+ if (page) params.append('page', page);
105
+ if (limit) params.append('limit', limit);
106
+
107
+ const queryString = params.toString();
108
+ const url = queryString
109
+ ? `/phoneNumbers/porting/orders/${id}/events?${queryString}`
110
+ : `/phoneNumbers/porting/orders/${id}/events`;
111
+
112
+ const result = await internalRequest(this.sdk, url, 'GET');
113
+ return result;
114
+ },
115
+
116
+ /**
117
+ * Get available activation dates for a porting order
118
+ * - Creates the porting order in external system if not already created
119
+ * - Updates the order data to ensure it's current before fetching dates
120
+ * - Returns list of available activation dates for user selection
121
+ * - Validates that phone numbers and required order details are complete
122
+ * @param {string} id - Porting order ID
123
+ * @returns {Promise<Object>} Available activation dates and order status
124
+ * @example
125
+ * const dates = await sdk.phoneNumbers.getFocWindows("port_123...");
126
+ * // Returns:
127
+ * // {
128
+ * // id: "port_123...",
129
+ * // status: "draft",
130
+ * // availableDates: [
131
+ * // { date: "2025-08-30T00:00:00.000Z", type: "Standard", available: true },
132
+ * // { date: "2025-09-02T00:00:00.000Z", type: "Express", available: true }
133
+ * // ],
134
+ * // phoneNumbersCount: 1,
135
+ * // orderReady: true
136
+ * // }
137
+ */
138
+ async getFocWindows(id) {
139
+ this.sdk.validateParams(
140
+ { id },
141
+ {
142
+ id: { type: 'string', required: true },
143
+ },
144
+ );
145
+
146
+ const result = await internalRequest(this.sdk,
147
+ `/phoneNumbers/porting/orders/${id}/foc-windows`,
148
+ 'GET',
149
+ );
150
+ return result;
151
+ },
152
+
153
+ /**
154
+ * Sync a porting order with the carrier
155
+ * Fetches the latest order details and comments from the carrier and updates the local database
156
+ * @param {string} id - Porting order ID
157
+ * @returns {Promise<Object>} Sync results including updates made and comments added
158
+ * @example
159
+ * const syncResult = await sdk.phoneNumbers.syncPortingOrder("port_123...");
160
+ * // Returns:
161
+ * // {
162
+ * // id: "port_123...",
163
+ * // carrierOrderId: "carrier_abc123",
164
+ * // orderUpdated: true,
165
+ * // commentsAdded: 2,
166
+ * // errors: []
167
+ * // }
168
+ */
169
+ async syncPortingOrder(id) {
170
+ this.sdk.validateParams(
171
+ { id },
172
+ {
173
+ id: { type: 'string', required: true },
174
+ },
175
+ );
176
+
177
+ const result = await internalRequest(this.sdk,
178
+ `/phoneNumbers/porting/orders/${id}/sync`,
179
+ 'POST',
180
+ );
181
+ return result;
182
+ },
183
+
184
+ /**
185
+ * Mark a porting-order exception as resolved after the user has updated
186
+ * the order (documents, account number, etc.). Syncs with the carrier
187
+ * so local status picks up the next Telnyx state.
188
+ * @param {string} id - Porting order ID
189
+ * @param {string} exceptionId - Exception ID
190
+ * @param {Object} [options]
191
+ * @param {string} [options.resolution]
192
+ * @returns {Promise<Object>} Updated exception
193
+ */
194
+ async resolvePortingException(id, exceptionId, { resolution } = {}) {
195
+ this.sdk.validateParams(
196
+ { id, exceptionId },
197
+ {
198
+ id: { type: 'string', required: true },
199
+ exceptionId: { type: 'string', required: true },
200
+ },
201
+ );
202
+ const body = {};
203
+ if (resolution) body.resolution = resolution;
204
+ return internalRequest(
205
+ this.sdk,
206
+ `/phoneNumbers/porting/orders/${id}/exceptions/${exceptionId}/resolve`,
207
+ 'POST',
208
+ { body },
209
+ );
210
+ },
211
+
212
+ /**
213
+ * Get comments for a porting order
214
+ * @param {string} id - Porting order ID
215
+ * @param {Object} [options] - Query options
216
+ * @param {string} [options.includeInternal='true'] - Include internal comments ('true', 'false', 'only')
217
+ * @returns {Promise<Object>} Comments list with metadata
218
+ * @example
219
+ * // Get all comments
220
+ * const allComments = await sdk.phoneNumbers.getPortingComments("port_123...");
221
+ *
222
+ * // Get only public comments
223
+ * const publicComments = await sdk.phoneNumbers.getPortingComments("port_123...", { includeInternal: 'false' });
224
+ *
225
+ * // Get only internal comments
226
+ * const internalComments = await sdk.phoneNumbers.getPortingComments("port_123...", { includeInternal: 'only' });
227
+ */
228
+ async getPortingComments(id, { includeInternal = 'true' } = {}) {
229
+ this.sdk.validateParams(
230
+ { id },
231
+ {
232
+ id: { type: 'string', required: true },
233
+ },
234
+ );
235
+
236
+ const params = new URLSearchParams();
237
+ if (includeInternal !== 'true') {
238
+ params.append('includeInternal', includeInternal);
239
+ }
240
+
241
+ const queryString = params.toString();
242
+ const url = `/phoneNumbers/porting/orders/${id}/comments${
243
+ queryString ? '?' + queryString : ''
244
+ }`;
245
+
246
+ const result = await internalRequest(this.sdk, url, 'GET');
247
+ return result;
248
+ },
249
+
250
+ /**
251
+ * Post a comment on a porting order
252
+ * @param {string} id - Porting order ID
253
+ * @param {Object} params - Comment parameters
254
+ * @param {string} params.comment - Comment body text
255
+ * @param {boolean} [params.isInternal=false] - Whether this is an internal comment (not shared with carrier)
256
+ * @returns {Promise<Object>} Created comment details
257
+ * @example
258
+ * // Post a public comment (shared with carrier)
259
+ * const publicComment = await sdk.phoneNumbers.postPortingComment("port_123...", {
260
+ * comment: "Please expedite this port request",
261
+ * isInternal: false
262
+ * });
263
+ *
264
+ * // Post an internal comment (team use only)
265
+ * const internalComment = await sdk.phoneNumbers.postPortingComment("port_123...", {
266
+ * comment: "Customer called - they need this ASAP",
267
+ * isInternal: true
268
+ * });
269
+ */
270
+ async postPortingComment(id, { comment, isInternal = false }) {
271
+ this.sdk.validateParams(
272
+ { id, comment },
273
+ {
274
+ id: { type: 'string', required: true },
275
+ comment: { type: 'string', required: true },
276
+ isInternal: { type: 'boolean', required: false },
277
+ },
278
+ );
279
+
280
+ const result = await internalRequest(this.sdk,
281
+ `/phoneNumbers/porting/orders/${id}/comments`,
282
+ 'POST',
283
+ {
284
+ body: { comment, isInternal },
285
+ },
286
+ );
287
+ return result;
288
+ },
289
+ };
@@ -0,0 +1,318 @@
1
+ import { internalRequest } from '../../base.js';
2
+
3
+ // phoneNumbers/porting-orders.js :: porting-order CRUD + portability checks
4
+ export const portingOrderMethods = {
5
+ /**
6
+ * Check portability of phone numbers using two-phase validation
7
+ *
8
+ * Phase 1 (Default): Internal validation using LRN lookup
9
+ * - Validates ownership, duplicates, and carrier compatibility
10
+ * - Sets portabilityStatus to 'pending'
11
+ *
12
+ * Phase 2 (runPortabilityCheck: true): External validation
13
+ * - Runs full portability check with carrier
14
+ * - Updates portabilityStatus to 'portable', 'not-portable', or 'error'
15
+ *
16
+ * @param {Object} params
17
+ * @param {string[]} params.phoneNumbers - Array of +E.164 formatted phone numbers
18
+ * @param {string} [params.portingOrderId] - Optional porting order ID to save results to
19
+ * @param {boolean} [params.runPortabilityCheck=false] - Run external portability validation
20
+ * @returns {Promise<Object>} Portability check results
21
+ */
22
+ async checkPortability({
23
+ phoneNumbers,
24
+ portingOrderId,
25
+ runPortabilityCheck = false,
26
+ }) {
27
+ this.sdk.validateParams(
28
+ { phoneNumbers, runPortabilityCheck },
29
+ {
30
+ phoneNumbers: { type: 'array', required: true },
31
+ runPortabilityCheck: { type: 'boolean', required: false },
32
+ },
33
+ );
34
+
35
+ const body = { phoneNumbers, runPortabilityCheck };
36
+ if (portingOrderId) body.portingOrderId = portingOrderId;
37
+
38
+ const result = await internalRequest(this.sdk,
39
+ '/phoneNumbers/porting/portability-check',
40
+ 'POST',
41
+ {
42
+ body: body,
43
+ },
44
+ );
45
+ return result;
46
+ },
47
+
48
+ /**
49
+ * Create a draft porting order (no phone numbers - add them via checkPortability)
50
+ * @param {Object} params
51
+ * @param {string} [params.customerReference] - Customer-specified reference number
52
+ * @param {Object} [params.endUser] - End user information
53
+ * @param {Object} [params.endUser.admin] - Admin contact info
54
+ * @param {string} [params.endUser.admin.entityName] - Business/entity name
55
+ * @param {string} [params.endUser.admin.authPersonName] - Authorized person name
56
+ * @param {string} [params.endUser.admin.billingPhoneNumber] - Billing phone number
57
+ * @param {string} [params.endUser.admin.accountNumber] - Account number with current provider
58
+ * @param {string} [params.endUser.admin.taxIdentifier] - Tax identification number (EU)
59
+ * @param {string} [params.endUser.admin.pinPasscode] - PIN/passcode for account access
60
+ * @param {string} [params.endUser.admin.businessIdentifier] - Business identifier (EU)
61
+ * @param {Object} [params.endUser.location] - Location information
62
+ * @param {string} [params.endUser.location.streetAddress] - Street address
63
+ * @param {string} [params.endUser.location.extendedAddress] - Apt/suite/etc
64
+ * @param {string} [params.endUser.location.locality] - City
65
+ * @param {string} [params.endUser.location.administrativeArea] - State/province
66
+ * @param {string} [params.endUser.location.postalCode] - ZIP/postal code
67
+ * @param {string} [params.endUser.location.countryCode] - 2-letter country code
68
+ * @param {Object} [params.activationSettings] - Activation preferences
69
+ * @param {string} [params.activationSettings.focDatetimeRequested] - Requested FOC date/time (ISO 8601 UTC)
70
+ * @param {boolean} [params.activationSettings.fastPortEligible] - Request fast port if available
71
+ * @param {string} [params.portOrderType] - Port type: 'full' or 'partial' (defaults to 'full')
72
+ * @param {string[]} [params.tags] - Array of tags for organization
73
+ * @returns {Promise<Object>} Created draft porting order with ID and status 'draft'
74
+ * @example
75
+ * // Create empty draft order, then add numbers via checkPortability
76
+ * const order = await sdk.phoneNumbers.createPortingOrder({
77
+ * customerReference: "CUST-123",
78
+ * endUser: { admin: { entityName: "My Company" } }
79
+ * });
80
+ *
81
+ * // Phase 1: Add numbers with internal validation (pending status)
82
+ * await sdk.phoneNumbers.checkPortability({
83
+ * phoneNumbers: ["+15551234567"],
84
+ * portingOrderId: order.id
85
+ * });
86
+ *
87
+ * // Phase 2: Run external portability check when ready
88
+ * await sdk.phoneNumbers.checkPortability({
89
+ * phoneNumbers: ["+15551234567"],
90
+ * portingOrderId: order.id,
91
+ * runPortabilityCheck: true
92
+ * });
93
+ */
94
+ async createPortingOrder({
95
+ customerReference,
96
+ endUser,
97
+ activationSettings,
98
+ portOrderType,
99
+ tags,
100
+ } = {}) {
101
+ // Creates draft order without phone numbers - use checkPortability to add them
102
+ const body = {};
103
+ if (customerReference) body.customerReference = customerReference;
104
+ if (endUser) body.endUser = endUser;
105
+ if (activationSettings) body.activationSettings = activationSettings;
106
+ if (portOrderType) body.portOrderType = portOrderType;
107
+ if (tags) body.tags = tags;
108
+
109
+ const result = await internalRequest(this.sdk,
110
+ '/phoneNumbers/porting/orders',
111
+ 'POST',
112
+ {
113
+ body: body,
114
+ },
115
+ );
116
+ return result;
117
+ },
118
+
119
+ async getPortingOrders({
120
+ page,
121
+ status,
122
+ customerReference,
123
+ sort,
124
+ limit,
125
+ id,
126
+ operatorType = 'contains',
127
+ } = {}) {
128
+ const query = {
129
+ page,
130
+ status,
131
+ customerReference,
132
+ id,
133
+ operatorType,
134
+ sort,
135
+ limit,
136
+ };
137
+
138
+ const url = '/phoneNumbers/porting/orders';
139
+
140
+ const params = {
141
+ query,
142
+ };
143
+
144
+ const result = await internalRequest(this.sdk, url, 'GET', params);
145
+ return result;
146
+ },
147
+
148
+ /**
149
+ * Get a porting order with optional related data
150
+ * @param {string} id - Porting order ID
151
+ * @param {Object} [options]
152
+ * @param {boolean} [options.includePhoneNumbers=true] - Include phone numbers array
153
+ * @param {boolean} [options.includeExceptions=true] - Include exceptions array
154
+ * @param {boolean} [options.includeDocuments=true] - Include documents array with upload status
155
+ * @returns {Promise<Object>} Porting order with requested related data
156
+ */
157
+ async getPortingOrder(
158
+ id,
159
+ {
160
+ includePhoneNumbers = true,
161
+ includeExceptions = true,
162
+ includeDocuments = true,
163
+ } = {},
164
+ ) {
165
+ this.sdk.validateParams(
166
+ { id },
167
+ {
168
+ id: { type: 'string', required: true },
169
+ },
170
+ );
171
+
172
+ const params = new URLSearchParams();
173
+ if (includePhoneNumbers !== undefined)
174
+ params.append('includePhoneNumbers', includePhoneNumbers);
175
+ if (includeExceptions !== undefined)
176
+ params.append('includeExceptions', includeExceptions);
177
+ if (includeDocuments !== undefined)
178
+ params.append('includeDocuments', includeDocuments);
179
+
180
+ const queryString = params.toString();
181
+ const url = queryString
182
+ ? `/phoneNumbers/porting/orders/${id}?${queryString}`
183
+ : `/phoneNumbers/porting/orders/${id}`;
184
+
185
+ const result = await internalRequest(this.sdk, url, 'GET');
186
+ return result;
187
+ },
188
+
189
+ /**
190
+ * Update a draft porting order (order info only - manage numbers via checkPortability)
191
+ * @param {string} id - Porting order ID
192
+ * @param {Object} params - Order information to update
193
+ * @param {string} [params.customerReference] - Customer-specified reference number
194
+ * @param {Object} [params.endUser] - End user information
195
+ * @param {Object} [params.activationSettings] - Activation preferences
196
+ * @param {string} [params.portOrderType] - Port type: 'full' or 'partial'
197
+ * @param {string[]} [params.tags] - Array of tags for organization
198
+ * @returns {Promise<Object>} Updated porting order
199
+ */
200
+ async updatePortingOrder(
201
+ id,
202
+ {
203
+ customerReference,
204
+ endUser,
205
+ activationSettings,
206
+ portOrderType,
207
+ tags,
208
+ } = {},
209
+ ) {
210
+ this.sdk.validateParams(
211
+ { id },
212
+ {
213
+ id: { type: 'string', required: true },
214
+ },
215
+ );
216
+
217
+ const body = {};
218
+
219
+ if (customerReference) body.customerReference = customerReference;
220
+ if (endUser) body.endUser = endUser;
221
+ if (activationSettings) body.activationSettings = activationSettings;
222
+ if (portOrderType) body.portOrderType = portOrderType;
223
+ if (tags) body.tags = tags;
224
+
225
+ const result = await internalRequest(this.sdk,
226
+ `/phoneNumbers/porting/orders/${id}`,
227
+ 'PUT',
228
+ {
229
+ body: body,
230
+ },
231
+ );
232
+ return result;
233
+ },
234
+
235
+ /**
236
+ * Submit a draft porting order for processing (validates all required fields)
237
+ * @param {string} id - Porting order ID
238
+ * @returns {Promise<Object>} Submitted porting order with Telnyx status
239
+ */
240
+ async submitPortingOrder(id) {
241
+ this.sdk.validateParams(
242
+ { id },
243
+ {
244
+ id: { type: 'string', required: true },
245
+ },
246
+ );
247
+
248
+ // Submit the draft order (status is implied)
249
+ const body = {
250
+ status: 'submit',
251
+ };
252
+
253
+ const result = await internalRequest(this.sdk,
254
+ `/phoneNumbers/porting/orders/${id}`,
255
+ 'PUT',
256
+ {
257
+ body: body,
258
+ },
259
+ );
260
+ return result;
261
+ },
262
+
263
+ /**
264
+ * Delete/cancel a porting order (soft delete)
265
+ * - Draft orders: Immediately cancelled locally
266
+ * - Submitted orders: Cancelled via Telnyx, then status updated to cancel-pending
267
+ * - Cannot delete orders within 48 hours of FOC date
268
+ * - Cannot delete already completed or cancelled orders
269
+ * @param {string} id - Porting order ID
270
+ * @returns {Promise<Object>} Cancellation result with new status
271
+ */
272
+ async deletePortingOrder(id) {
273
+ this.sdk.validateParams(
274
+ { id },
275
+ {
276
+ id: { type: 'string', required: true },
277
+ },
278
+ );
279
+
280
+ const result = await internalRequest(this.sdk,
281
+ `/phoneNumbers/porting/orders/${id}`,
282
+ 'DELETE',
283
+ );
284
+ return result;
285
+ },
286
+
287
+ /**
288
+ * Remove a specific phone number from a porting order
289
+ * - Only works on draft orders (not submitted orders)
290
+ * - Cannot remove the last phone number (delete entire order instead)
291
+ * - Validates that phone number exists in the order
292
+ * @param {string} portingOrderId - Porting order ID
293
+ * @param {string} phoneNumber - Phone number to remove (+E.164 format)
294
+ * @returns {Promise<Object>} Removal confirmation with updated counts
295
+ * @example
296
+ * await sdk.phoneNumbers.removePhoneNumberFromOrder(
297
+ * "port_123...",
298
+ * "+15551234567"
299
+ * );
300
+ */
301
+ async removePhoneNumberFromOrder(portingOrderId, phoneNumber) {
302
+ this.sdk.validateParams(
303
+ { portingOrderId, phoneNumber },
304
+ {
305
+ portingOrderId: { type: 'string', required: true },
306
+ phoneNumber: { type: 'string', required: true },
307
+ },
308
+ );
309
+
310
+ const result = await internalRequest(this.sdk,
311
+ `/phoneNumbers/porting/orders/${encodeURIComponent(
312
+ portingOrderId,
313
+ )}/numbers/${encodeURIComponent(phoneNumber)}`,
314
+ 'DELETE',
315
+ );
316
+ return result;
317
+ },
318
+ };