@unboundcx/sdk 2.1.2 → 2.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
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",
@@ -1,87 +1,214 @@
1
+ /**
2
+ * Objects Service - Manage data objects in the Unbound platform
3
+ *
4
+ * This service supports both new object-based signatures and legacy positional arguments
5
+ * for backward compatibility. New projects should use the object-based signatures.
6
+ *
7
+ * @example
8
+ * // Preferred (new) usage:
9
+ * const result = await sdk.objects.query({
10
+ * object: 'users',
11
+ * select: ['id', 'name', 'email'],
12
+ * where: { status: 'active' },
13
+ * limit: 100
14
+ * });
15
+ *
16
+ * @example
17
+ * // Legacy (deprecated) usage still supported:
18
+ * const result = await sdk.objects.query('users', { status: 'active' });
19
+ */
1
20
  export class ObjectsService {
2
21
  constructor(sdk) {
3
22
  this.sdk = sdk;
4
23
  }
5
24
 
6
- async byId({ id, expandDetails = false }) {
7
- this.sdk.validateParams(
8
- { id, expandDetails },
9
- {
10
- id: { type: 'string', required: true },
11
- expandDetails: { type: 'boolean', required: false },
12
- },
13
- );
25
+ /**
26
+ * Retrieve an object by ID
27
+ *
28
+ * Preferred usage (new signature):
29
+ * sdk.objects.byId({ id: 'someId', expandDetails: true })
30
+ *
31
+ * Legacy usage (deprecated, but supported):
32
+ * sdk.objects.byId('someId', { 'select[]': ['field1', 'field2'] })
33
+ *
34
+ * @param {string|object} args - Either ID string or options object
35
+ * @returns {Promise} Object data
36
+ */
37
+ async byId(...args) {
38
+ // New signature: byId({ id, expandDetails })
39
+ if (args.length === 1 && typeof args[0] === 'object' && !Array.isArray(args[0])) {
40
+ const { id, expandDetails = false } = args[0];
41
+
42
+ this.sdk.validateParams(
43
+ { id, expandDetails },
44
+ {
45
+ id: { type: 'string', required: true },
46
+ expandDetails: { type: 'boolean', required: false },
47
+ },
48
+ );
14
49
 
15
- const query = {};
16
- if (expandDetails) query.expandDetails = expandDetails;
50
+ const query = {};
51
+ if (expandDetails) query.expandDetails = expandDetails;
17
52
 
18
- const params = {
19
- query,
20
- };
53
+ const params = { query };
54
+ return await this.sdk._fetch(`/object/${id}`, 'GET', params);
55
+ }
56
+
57
+ // Old signature: byId(id, queryParams)
58
+ if (args.length >= 1 && typeof args[0] === 'string') {
59
+ const [id, queryParams = {}] = args;
60
+
61
+ this.sdk.validateParams(
62
+ { id },
63
+ {
64
+ id: { type: 'string', required: true },
65
+ },
66
+ );
21
67
 
22
- const result = await this.sdk._fetch(`/object/${id}`, 'GET', params);
23
- return result;
68
+ const query = { ...queryParams };
69
+ const params = { query };
70
+ return await this.sdk._fetch(`/object/${id}`, 'GET', params);
71
+ }
72
+
73
+ throw new Error('Invalid arguments for byId method');
24
74
  }
25
75
 
26
- async query({
27
- object,
28
- select = null,
29
- where = {},
30
- limit = 100,
31
- nextId = null,
32
- previousId = null,
33
- orderByDirection = 'DESC',
34
- expandDetails = false,
35
- }) {
36
- this.sdk.validateParams(
37
- { object, select, where, limit, nextId, previousId, orderByDirection, expandDetails },
38
- {
39
- object: { type: 'string', required: true },
40
- select: { type: 'object', required: false }, // array or string
41
- where: { type: 'object', required: false },
42
- limit: { type: 'number', required: false },
43
- nextId: { type: 'string', required: false },
44
- previousId: { type: 'string', required: false },
45
- orderByDirection: { type: 'string', required: false },
46
- expandDetails: { type: 'boolean', required: false },
47
- },
48
- );
76
+ /**
77
+ * Query objects with filters
78
+ *
79
+ * Preferred usage (new signature):
80
+ * sdk.objects.query({
81
+ * object: 'users',
82
+ * select: ['id', 'name'],
83
+ * where: { status: 'active' },
84
+ * limit: 50,
85
+ * expandDetails: true
86
+ * })
87
+ *
88
+ * Legacy usage (deprecated, but supported):
89
+ * sdk.objects.query('users', { 'select[]': ['id', 'name'], status: 'active' })
90
+ *
91
+ * @param {object} args - Query parameters
92
+ * @returns {Promise} Query results
93
+ */
94
+ async query(...args) {
95
+ // New signature: query({ object, select, where, ... })
96
+ if (args.length === 1 && typeof args[0] === 'object' && args[0].object) {
97
+ const {
98
+ object,
99
+ select = null,
100
+ where = {},
101
+ limit = 100,
102
+ nextId = null,
103
+ previousId = null,
104
+ orderByDirection = 'DESC',
105
+ expandDetails = false,
106
+ } = args[0];
107
+
108
+ this.sdk.validateParams(
109
+ { object, select, where, limit, nextId, previousId, orderByDirection, expandDetails },
110
+ {
111
+ object: { type: 'string', required: true },
112
+ select: { type: 'object', required: false }, // array or string
113
+ where: { type: 'object', required: false },
114
+ limit: { type: 'number', required: false },
115
+ nextId: { type: 'string', required: false },
116
+ previousId: { type: 'string', required: false },
117
+ orderByDirection: { type: 'string', required: false },
118
+ expandDetails: { type: 'boolean', required: false },
119
+ },
120
+ );
121
+
122
+ const query = { ...where };
123
+ if (select !== null) query.select = select;
124
+ if (limit !== 100) query.limit = limit;
125
+ if (nextId !== null) query.nextId = nextId;
126
+ if (previousId !== null) query.previousId = previousId;
127
+ if (orderByDirection !== 'DESC') query.orderByDirection = orderByDirection;
128
+ if (expandDetails) query.expandDetails = expandDetails;
129
+
130
+ const params = { query };
131
+ return await this.sdk._fetch(`/object/query/${object}`, 'GET', params);
132
+ }
49
133
 
50
- const query = { ...where };
51
- if (select !== null) query.select = select;
52
- if (limit !== 100) query.limit = limit;
53
- if (nextId !== null) query.nextId = nextId;
54
- if (previousId !== null) query.previousId = previousId;
55
- if (orderByDirection !== 'DESC') query.orderByDirection = orderByDirection;
56
- if (expandDetails) query.expandDetails = expandDetails;
134
+ // Old signature: query(objectName, queryParams)
135
+ if (args.length === 2 && typeof args[0] === 'string') {
136
+ const [objectName, queryParams = {}] = args;
57
137
 
58
- const params = { query };
138
+ this.sdk.validateParams(
139
+ { object: objectName },
140
+ {
141
+ object: { type: 'string', required: true },
142
+ },
143
+ );
59
144
 
60
- const result = await this.sdk._fetch(`/object/query/${object}`, 'GET', params);
61
- return result;
145
+ const params = { query: queryParams };
146
+ return await this.sdk._fetch(`/object/query/${objectName}`, 'GET', params);
147
+ }
148
+
149
+ throw new Error('Invalid arguments for query method');
62
150
  }
63
151
 
64
- async updateById({ object, id, update }) {
65
- this.sdk.validateParams(
66
- { object, id, update },
67
- {
68
- object: { type: 'string', required: true },
69
- id: { type: 'string', required: true },
70
- update: { type: 'object', required: true },
71
- },
72
- );
152
+ /**
153
+ * Update an object record by ID
154
+ *
155
+ * Preferred usage (new signature):
156
+ * sdk.objects.updateById({ object: 'users', id: 'userId', update: { name: 'Jane' } })
157
+ *
158
+ * Legacy usage (deprecated, but supported):
159
+ * sdk.objects.updateById('users', 'userId', { name: 'Jane' })
160
+ *
161
+ * @param {object} args - Update parameters
162
+ * @returns {Promise} Updated object data
163
+ */
164
+ async updateById(...args) {
165
+ // New signature: updateById({ object, id, update })
166
+ if (args.length === 1 && typeof args[0] === 'object' && args[0].object) {
167
+ const { object, id, update } = args[0];
168
+
169
+ this.sdk.validateParams(
170
+ { object, id, update },
171
+ {
172
+ object: { type: 'string', required: true },
173
+ id: { type: 'string', required: true },
174
+ update: { type: 'object', required: true },
175
+ },
176
+ );
73
177
 
74
- const params = {
75
- body: {
76
- where: {
77
- id,
178
+ const params = {
179
+ body: {
180
+ where: { id },
181
+ update,
78
182
  },
79
- update,
80
- },
81
- };
183
+ };
82
184
 
83
- const result = await this.sdk._fetch(`/object/${object}`, 'PUT', params);
84
- return result;
185
+ return await this.sdk._fetch(`/object/${object}`, 'PUT', params);
186
+ }
187
+
188
+ // Old signature: updateById(object, id, update)
189
+ if (args.length === 3) {
190
+ const [object, id, update] = args;
191
+
192
+ this.sdk.validateParams(
193
+ { object, id, update },
194
+ {
195
+ object: { type: 'string', required: true },
196
+ id: { type: 'string', required: true },
197
+ update: { type: 'object', required: true },
198
+ },
199
+ );
200
+
201
+ const params = {
202
+ body: {
203
+ where: { id },
204
+ update,
205
+ },
206
+ };
207
+
208
+ return await this.sdk._fetch(`/object/${object}`, 'PUT', params);
209
+ }
210
+
211
+ throw new Error('Invalid arguments for updateById method');
85
212
  }
86
213
 
87
214
  async update({ object, where, update }) {
@@ -105,21 +232,52 @@ export class ObjectsService {
105
232
  return result;
106
233
  }
107
234
 
108
- async create({ object, body }) {
109
- this.sdk.validateParams(
110
- { object, body },
111
- {
112
- object: { type: 'string', required: true },
113
- body: { type: 'object', required: true },
114
- },
115
- );
235
+ /**
236
+ * Create a new object record
237
+ *
238
+ * Preferred usage (new signature):
239
+ * sdk.objects.create({ object: 'users', body: { name: 'John', email: 'john@example.com' } })
240
+ *
241
+ * Legacy usage (deprecated, but supported):
242
+ * sdk.objects.create('users', { name: 'John', email: 'john@example.com' })
243
+ *
244
+ * @param {object} args - Creation parameters
245
+ * @returns {Promise} Created object data
246
+ */
247
+ async create(...args) {
248
+ // New signature: create({ object, body })
249
+ if (args.length === 1 && typeof args[0] === 'object' && args[0].object) {
250
+ const { object, body } = args[0];
251
+
252
+ this.sdk.validateParams(
253
+ { object, body },
254
+ {
255
+ object: { type: 'string', required: true },
256
+ body: { type: 'object', required: true },
257
+ },
258
+ );
116
259
 
117
- const params = {
118
- body,
119
- };
260
+ const params = { body };
261
+ return await this.sdk._fetch(`/object/${object}`, 'POST', params);
262
+ }
120
263
 
121
- const result = await this.sdk._fetch(`/object/${object}`, 'POST', params);
122
- return result;
264
+ // Old signature: create(object, body)
265
+ if (args.length === 2) {
266
+ const [object, body] = args;
267
+
268
+ this.sdk.validateParams(
269
+ { object, body },
270
+ {
271
+ object: { type: 'string', required: true },
272
+ body: { type: 'object', required: true },
273
+ },
274
+ );
275
+
276
+ const params = { body };
277
+ return await this.sdk._fetch(`/object/${object}`, 'POST', params);
278
+ }
279
+
280
+ throw new Error('Invalid arguments for create method');
123
281
  }
124
282
 
125
283
  async delete({ object, where }) {
@@ -196,6 +196,151 @@ export class PhoneNumbersService {
196
196
  const result = await this.sdk._fetch('/phoneNumbers/supported-countries', 'GET');
197
197
  return result;
198
198
  }
199
+
200
+ // Porting Methods
201
+ async checkPortability({ phoneNumbers }) {
202
+ this.sdk.validateParams(
203
+ { phoneNumbers },
204
+ {
205
+ phoneNumbers: { type: 'array', required: true },
206
+ },
207
+ );
208
+
209
+ const result = await this.sdk._fetch('/phoneNumbers/porting/portability-check', 'POST', {
210
+ phoneNumbers
211
+ });
212
+ return result;
213
+ }
214
+
215
+ async createPortingOrder({
216
+ phoneNumbers,
217
+ phoneNumberBlocks,
218
+ customerReference,
219
+ endUser,
220
+ activationSettings,
221
+ webhookUrl,
222
+ ...additionalData
223
+ }) {
224
+ if (!phoneNumbers && !phoneNumberBlocks) {
225
+ throw new Error('Either phoneNumbers or phoneNumberBlocks is required');
226
+ }
227
+
228
+ const body = {
229
+ ...additionalData
230
+ };
231
+
232
+ if (phoneNumbers) body.phoneNumbers = phoneNumbers;
233
+ if (phoneNumberBlocks) body.phoneNumberBlocks = phoneNumberBlocks;
234
+ if (customerReference) body.customerReference = customerReference;
235
+ if (endUser) body.endUser = endUser;
236
+ if (activationSettings) body.activationSettings = activationSettings;
237
+ if (webhookUrl) body.webhookUrl = webhookUrl;
238
+
239
+ const result = await this.sdk._fetch('/phoneNumbers/porting/orders', 'POST', body);
240
+ return result;
241
+ }
242
+
243
+ async getPortingOrders({
244
+ page,
245
+ includePhoneNumbers = true,
246
+ status,
247
+ customerReference,
248
+ sort,
249
+ limit
250
+ } = {}) {
251
+ const params = new URLSearchParams();
252
+
253
+ if (page) params.append('page', page);
254
+ if (includePhoneNumbers !== undefined) params.append('includePhoneNumbers', includePhoneNumbers);
255
+ if (status) params.append('status', status);
256
+ if (customerReference) params.append('customerReference', customerReference);
257
+ if (sort) params.append('sort', sort);
258
+ if (limit) params.append('limit', limit);
259
+
260
+ const queryString = params.toString();
261
+ const url = queryString ? `/phoneNumbers/porting/orders?${queryString}` : '/phoneNumbers/porting/orders';
262
+
263
+ const result = await this.sdk._fetch(url, 'GET');
264
+ return result;
265
+ }
266
+
267
+ async getPortingOrder(id, { includePhoneNumbers = true } = {}) {
268
+ this.sdk.validateParams(
269
+ { id },
270
+ {
271
+ id: { type: 'string', required: true },
272
+ },
273
+ );
274
+
275
+ const params = new URLSearchParams();
276
+ if (includePhoneNumbers !== undefined) params.append('includePhoneNumbers', includePhoneNumbers);
277
+
278
+ const queryString = params.toString();
279
+ const url = queryString ? `/phoneNumbers/porting/orders/${id}?${queryString}` : `/phoneNumbers/porting/orders/${id}`;
280
+
281
+ const result = await this.sdk._fetch(url, 'GET');
282
+ return result;
283
+ }
284
+
285
+ async updatePortingOrder(id, updateData) {
286
+ this.sdk.validateParams(
287
+ { id, updateData },
288
+ {
289
+ id: { type: 'string', required: true },
290
+ updateData: { type: 'object', required: true },
291
+ },
292
+ );
293
+
294
+ const result = await this.sdk._fetch(`/phoneNumbers/porting/orders/${id}`, 'PATCH', updateData);
295
+ return result;
296
+ }
297
+
298
+ async uploadPortingDocument({
299
+ filename,
300
+ fileContent,
301
+ contentType = 'application/pdf',
302
+ documentType = 'loa',
303
+ portingOrderId
304
+ }) {
305
+ this.sdk.validateParams(
306
+ { filename, fileContent },
307
+ {
308
+ filename: { type: 'string', required: true },
309
+ fileContent: { type: 'string', required: true },
310
+ },
311
+ );
312
+
313
+ const body = {
314
+ filename,
315
+ fileContent,
316
+ contentType,
317
+ documentType
318
+ };
319
+
320
+ if (portingOrderId) body.portingOrderId = portingOrderId;
321
+
322
+ const result = await this.sdk._fetch('/phoneNumbers/porting/documents', 'POST', body);
323
+ return result;
324
+ }
325
+
326
+ async getPortingEvents(id, { page, limit } = {}) {
327
+ this.sdk.validateParams(
328
+ { id },
329
+ {
330
+ id: { type: 'string', required: true },
331
+ },
332
+ );
333
+
334
+ const params = new URLSearchParams();
335
+ if (page) params.append('page', page);
336
+ if (limit) params.append('limit', limit);
337
+
338
+ const queryString = params.toString();
339
+ const url = queryString ? `/phoneNumbers/porting/orders/${id}/events?${queryString}` : `/phoneNumbers/porting/orders/${id}/events`;
340
+
341
+ const result = await this.sdk._fetch(url, 'GET');
342
+ return result;
343
+ }
199
344
  }
200
345
 
201
346
  export class PhoneNumberCarrierService {