@signalhousellc/sdk 1.0.37 → 1.0.39

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": "@signalhousellc/sdk",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "Signal House SDK for use with the Signal House platform",
5
5
  "type": "module",
6
6
  "main": "src/SignalHouseSDK.js",
@@ -119,11 +119,14 @@ export class Campaigns {
119
119
  * @param {number} [params.page] - The page number for pagination
120
120
  * @param {number} [params.limit] - The number of items per page
121
121
  * @param {string} [params.status] - The status of the campaign to filter by
122
+ * @param {string} [params.search] - Search term to filter campaigns by campaignId or brandId
123
+ * @param {string} [params.sortBy] - Field to sort by (e.g. "createdAt", "campaignId", "brandId", "groupId", "subgroupId", "usecase", "status")
124
+ * @param {string} [params.sortOrder] - Sort direction ("asc" or "desc")
122
125
  * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
123
- * @returns {Promise<Array>} The response from the server
126
+ * @returns {Promise<Array|Object>} The response from the server - array when unpaginated, or { data, total, page, limit, totalPages } when paginated
124
127
  */
125
- async getCampaigns({ id, brandId, subgroupId, groupId, page, limit, status, options = {} }) {
126
- const filters = { id, brandId, subgroupId, groupId, page, limit, status };
128
+ async getCampaigns({ id, brandId, subgroupId, groupId, page, limit, status, search, sortBy, sortOrder, options = {} }) {
129
+ const filters = { id, brandId, subgroupId, groupId, page, limit, status, search, sortBy, sortOrder };
127
130
  const queryString = this.client._getQueryString(filters);
128
131
  return this.client(`/campaign${queryString}`, { method: "GET", ...options });
129
132
  }
@@ -93,15 +93,19 @@ export class Numbers {
93
93
  }
94
94
 
95
95
  /**
96
- * Purchase phone numbers by providing a list of phone numbers and the subgroup ID to assign them to
96
+ * Purchase phone numbers by providing a list of phone numbers and the subgroup ID to assign them to.
97
+ *
98
+ * Numbers already owned (by this subgroup or another) are skipped; only the remaining numbers are queued
99
+ * for purchase and the response `message` names each skipped number and its reason. The request fails
100
+ * with an error ONLY when every requested number is already owned.
97
101
  * @async
98
102
  * @roles api, admin, developer, billing, user
99
103
  * @param {Object} params - The parameters for purchasing phone numbers
100
104
  * @param {string[]} params.phoneNumbers - The list of phone numbers to purchase
101
105
  * @param {string} params.subgroupId - The ID of the subgroup to assign the purchased phone numbers to
102
106
  * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
103
- * @throws {Error} Throws an error if the phoneNumbers or subgroupId parameter is missing
104
- * @returns {Promise<Object>} A promise that resolves to the result of the purchase operation
107
+ * @throws {Error} Throws an error if the phoneNumbers or subgroupId parameter is missing, or if every requested number is already owned
108
+ * @returns {Promise<Object>} A promise that resolves to `{ message }`. The message describes any skipped numbers when some requested numbers were already owned.
105
109
  */
106
110
  async purchasePhoneNumber({ phoneNumbers, subgroupId, options = {} }) {
107
111
  this.client._require({ phoneNumbers, subgroupId });
@@ -1,204 +1,204 @@
1
- /**
2
- * @typedef {Object} CreateUserData
3
- * @property {string} groupId - The ID of the group to which the user belongs (must start with "G" and be at least 8 characters long)
4
- * @property {string} role - The role of the user (admin, developer, billing, user)
5
- * @property {string} password - The password for the user (must be at least 8 characters long)
6
- * @property {string} email - The email address of the user (must be a valid email format)
7
- * @property {string} [firstName] - The first name of the user (optional)
8
- * @property {string} [lastName] - The last name of the user (optional)
9
- * @property {string} [companyName] - The company name associated with the user (optional)
10
- * @property {string} [phone] - The phone number of the user (optional)
11
- * @property {string} [profileImageLink] - A URL to the user's profile image (optional, must be a valid URL format if provided)
12
- * @property {string} [addressLine1] - The first line of the user's address (optional)
13
- * @property {string} [addressLine2] - The second line of the user's address (optional)
14
- * @property {string} [city] - The city of the user's address (optional)
15
- * @property {string} [state] - The state of the user's address (optional)
16
- * @property {string} [country] - The country of the user's address (optional)
17
- * @property {string} [postalCode] - The postal code of the user's address (optional)
18
- * @property {string} [signupSource] - The source from which the user signed up (optional)
19
- */
20
-
21
- /**
22
- * @typedef {Object} CreateServiceUserData
23
- * @property {string} groupId - The ID of the group to which the service user belongs (required)
24
- * @property {string} name - The name of the service user (required)
25
- * @property {string} role - The role of the service user (admin, developer, billing, user) (required)
26
- */
27
-
28
- /**
29
- * @typedef {Object} UpdateUserData
30
- * @property {string} [role] - The role of the user (admin, developer, billing, user)
31
- * @property {string} [email] - The email address of the user (must be a valid email format if provided)
32
- * @property {string} [firstName] - The first name of the user (optional)
33
- * @property {string} [lastName] - The last name of the user (optional)
34
- * @property {string} [companyName] - The company name associated with the user (optional)
35
- * @property {string} [phone] - The phone number of the user (optional)
36
- * @property {string} [profileImageLink] - A URL to the user's profile image (optional, must be a valid URL format if provided)
37
- * @property {string} [addressLine1] - The first line of the user's address (optional)
38
- * @property {string} [addressLine2] - The second line of the user's address (optional)
39
- * @property {string} [city] - The city of the user's address (optional)
40
- * @property {string} [state] - The state of the user's address (optional)
41
- * @property {string} [country] - The country of the user's address (optional)
42
- * @property {string} [postalCode] - The postal code of the user's address (optional)
43
- * @property {string} [status] - The status of the user (e.g., "active", "inactive")
44
- */
45
-
46
- export class Users {
47
- constructor(client, enableAdmin) {
48
- this.client = client;
49
- this.enableAdmin = enableAdmin;
50
-
51
- if (enableAdmin) {
52
- this.admin = {
53
- /**
54
- * Get a list of users with optional filters.
55
- * @roles signalhouse
56
- * @param {Object} params - The parameters for getting users
57
- * @param {string} [params.email] - Filter users by email (partial match)
58
- * @param {string} [params.userType] - Filter users by type (user, service)
59
- * @param {number} [params.page] - Page number for pagination
60
- * @param {number} [params.limit] - Items per page
61
- * @param {string} [params.search] - Search users by email (case-insensitive)
62
- * @param {string} [params.sortBy] - Field to sort by (createdAt, email, activeGroupId, companyName, status, _id)
63
- * @param {string} [params.sortOrder] - Sort direction (asc, desc)
64
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
65
- * @returns {Promise<Object>} - A promise that resolves to the list of users
66
- */
67
- getUsers: async ({ email, userType, page, limit, search, sortBy, sortOrder, options = {} }) => {
68
- const filters = { email, userType, page, limit, search, sortBy, sortOrder };
69
- const queryString = this.client._getQueryString(filters);
70
- return this.client(`/user${queryString}`, { method: "GET", ...options });
71
- },
72
-
73
- /**
74
- * Create a new internal user (admin or service user) with the specified data.
75
- * @roles signalhouse
76
- * @param {Object} params - The parameters for creating an internal user
77
- * @param {CreateServiceUserData} params.data - The data for the new internal user
78
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
79
- * @returns {Promise<Object>} - A promise that resolves to the created internal user
80
- */
81
- createInternalUser: async ({ data, options = {} }) => {
82
- this.client._require({ data: data });
83
- return this.client(`/user/signalhouse`, { method: "POST", body: data, ...options });
84
- },
85
- };
86
- }
87
- }
88
-
89
- /**
90
- * Get a list of users with optional filters
91
- * @async
92
- * @roles api, admin, self
93
- * @param {Object} params - The parameters for getting users
94
- * @param {string} [params.id] - Filter by user ID
95
- * @param {string} [params.groupId] - Filter by group ID
96
- * @param {string} [params.userType] - Filter by user type (user, service)
97
- * @param {number} [params.page] - Page number for pagination
98
- * @param {number} [params.limit] - Items per page
99
- * @param {string} [params.search] - Search users by email (case-insensitive)
100
- * @param {string} [params.sortBy] - Field to sort by (createdAt, email, activeGroupId, companyName, status, _id)
101
- * @param {string} [params.sortOrder] - Sort direction (asc, desc)
102
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
103
- * @returns {Promise<Object>} - A promise that resolves to the list of users
104
- */
105
- async getUsers({ id, groupId, userType, page, limit, search, sortBy, sortOrder, options = {} }) {
106
- const filters = { id, groupId, userType, page, limit, search, sortBy, sortOrder };
107
- const queryString = this.client._getQueryString(filters);
108
- return this.client(`/user${queryString}`, { method: "GET", ...options });
109
- }
110
-
111
- /**
112
- * Create a new user with the specified user data
113
- * @async
114
- * @roles api, admin
115
- * @param {Object} params - The parameters for creating a user (see CreateUserData typedef for details)
116
- * @param {CreateUserData} params.data - The data for the new user
117
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
118
- * @throws {Error} Throws an error if required fields in the data parameter are missing
119
- * @returns {Promise<Object>} - A promise that resolves to the created user
120
- */
121
- async createUser({ data, options = {} }) {
122
- this.client._require({ data: data });
123
- return this.client(`/user`, { method: "POST", body: data, ...options });
124
- }
125
-
126
- /**
127
- * Create a new service user with the specified user data. Used for creating API keys and other non-human users.
128
- * @async
129
- * @roles admin, developer
130
- * @param {Object} params - The parameters for creating a service user (see CreateServiceUserData typedef for details)
131
- * @param {CreateServiceUserData} params.data - The data for the new service user
132
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
133
- * @throws {Error} Throws an error if required fields in the data parameter are missing
134
- * @returns {Promise<Object>} - A promise that resolves to the created service user
135
- */
136
- async createServiceUser({ data, options = {} }) {
137
- this.client._require({ data: data });
138
- return this.client(`/user/serviceuser`, { method: "POST", body: data, ...options });
139
- }
140
-
141
- /**
142
- * Update an existing user's information with the specified user data
143
- * @async
144
- * @roles api, admin, self
145
- * @param {Object} params - The parameters for updating a user (see UpdateUserData typedef for details)
146
- * @param {string} params.id - The ID of the user to update
147
- * @param {UpdateUserData} params.data - The data to update for the user
148
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
149
- * @throws {Error} Throws an error if required fields in the data parameter are missing
150
- * @returns {Promise<Object>} - A promise that resolves to the updated user
151
- */
152
- async updateUser({ id, data, options = {} }) {
153
- this.client._require({ id, data: data });
154
- const safeId = encodeURIComponent(id);
155
- return this.client(`/user/${safeId}`, { method: "PUT", body: data, ...options });
156
- }
157
-
158
- /**
159
- * Delete a user by their ID (mark as inactive)
160
- * @async
161
- * @roles api, admin
162
- * @param {Object} params - The parameters for deleting a user
163
- * @param {string} params.id - The ID of the user to delete
164
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
165
- * @throws {Error} Throws an error if the id parameter is missing
166
- * @returns {Promise<Object>} - A promise that resolves to the deleted user
167
- */
168
- async deleteUser({ id, options = {} }) {
169
- this.client._require({ id });
170
- const safeId = encodeURIComponent(id);
171
- return this.client(`/user/${safeId}`, { method: "DELETE", ...options });
172
- }
173
-
174
- /**
175
- * Get notification preferences for a user
176
- * @async
177
- * @roles api, admin, self
178
- * @param {Object} params
179
- * @param {string} params.id - The ID of the user
180
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
181
- * @returns {Promise<Object>} The response from the server
182
- */
183
- async getNotificationPreferences({ id, options = {} }) {
184
- this.client._require({ id });
185
- const safeId = encodeURIComponent(id);
186
- return this.client(`/user/${safeId}/notification-preferences`, { method: "GET", ...options });
187
- }
188
-
189
- /**
190
- * Update notification preferences for a user
191
- * @async
192
- * @roles api, admin, self
193
- * @param {Object} params
194
- * @param {string} params.id - The ID of the user
195
- * @param {Array<{name: string, web: boolean, email: boolean}>} params.notificationPreferences - Array of notification preference objects
196
- * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
197
- * @returns {Promise<Object>} The response from the server
198
- */
199
- async updateNotificationPreferences({ id, notificationPreferences, options = {} }) {
200
- this.client._require({ id, notificationPreferences });
201
- const safeId = encodeURIComponent(id);
202
- return this.client(`/user/${safeId}/notification-preferences`, { method: "PUT", body: { notificationPreferences }, ...options });
203
- }
204
- }
1
+ /**
2
+ * @typedef {Object} CreateUserData
3
+ * @property {string} groupId - The ID of the group to which the user belongs (must start with "G" and be at least 8 characters long)
4
+ * @property {string} role - The role of the user (admin, developer, billing, user)
5
+ * @property {string} password - The password for the user (must be at least 8 characters long)
6
+ * @property {string} email - The email address of the user (must be a valid email format)
7
+ * @property {string} [firstName] - The first name of the user (optional)
8
+ * @property {string} [lastName] - The last name of the user (optional)
9
+ * @property {string} [companyName] - The company name associated with the user (optional)
10
+ * @property {string} [phone] - The phone number of the user (optional)
11
+ * @property {string} [profileImageLink] - A URL to the user's profile image (optional, must be a valid URL format if provided)
12
+ * @property {string} [addressLine1] - The first line of the user's address (optional)
13
+ * @property {string} [addressLine2] - The second line of the user's address (optional)
14
+ * @property {string} [city] - The city of the user's address (optional)
15
+ * @property {string} [state] - The state of the user's address (optional)
16
+ * @property {string} [country] - The country of the user's address (optional)
17
+ * @property {string} [postalCode] - The postal code of the user's address (optional)
18
+ * @property {string} [signupSource] - The source from which the user signed up (optional)
19
+ */
20
+
21
+ /**
22
+ * @typedef {Object} CreateServiceUserData
23
+ * @property {string} groupId - The ID of the group to which the service user belongs (required)
24
+ * @property {string} name - The name of the service user (required)
25
+ * @property {string} role - The role of the service user (admin, developer, billing, user) (required)
26
+ */
27
+
28
+ /**
29
+ * @typedef {Object} UpdateUserData
30
+ * @property {string} [role] - The role of the user (admin, developer, billing, user)
31
+ * @property {string} [email] - The email address of the user (must be a valid email format if provided)
32
+ * @property {string} [firstName] - The first name of the user (optional)
33
+ * @property {string} [lastName] - The last name of the user (optional)
34
+ * @property {string} [companyName] - The company name associated with the user (optional)
35
+ * @property {string} [phone] - The phone number of the user (optional)
36
+ * @property {string} [profileImageLink] - A URL to the user's profile image (optional, must be a valid URL format if provided)
37
+ * @property {string} [addressLine1] - The first line of the user's address (optional)
38
+ * @property {string} [addressLine2] - The second line of the user's address (optional)
39
+ * @property {string} [city] - The city of the user's address (optional)
40
+ * @property {string} [state] - The state of the user's address (optional)
41
+ * @property {string} [country] - The country of the user's address (optional)
42
+ * @property {string} [postalCode] - The postal code of the user's address (optional)
43
+ * @property {string} [status] - The status of the user (e.g., "active", "inactive")
44
+ */
45
+
46
+ export class Users {
47
+ constructor(client, enableAdmin) {
48
+ this.client = client;
49
+ this.enableAdmin = enableAdmin;
50
+
51
+ if (enableAdmin) {
52
+ this.admin = {
53
+ /**
54
+ * Get a list of users with optional filters.
55
+ * @roles signalhouse
56
+ * @param {Object} params - The parameters for getting users
57
+ * @param {string} [params.email] - Filter users by email (partial match)
58
+ * @param {string} [params.userType] - Filter users by type (user, service)
59
+ * @param {number} [params.page] - Page number for pagination
60
+ * @param {number} [params.limit] - Items per page
61
+ * @param {string} [params.search] - Search users by email (case-insensitive)
62
+ * @param {string} [params.sortBy] - Field to sort by (createdAt, email, activeGroupId, companyName, status, _id)
63
+ * @param {string} [params.sortOrder] - Sort direction (asc, desc)
64
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
65
+ * @returns {Promise<Object>} - A promise that resolves to the list of users
66
+ */
67
+ getUsers: async ({ email, userType, page, limit, search, sortBy, sortOrder, options = {} }) => {
68
+ const filters = { email, userType, page, limit, search, sortBy, sortOrder };
69
+ const queryString = this.client._getQueryString(filters);
70
+ return this.client(`/user${queryString}`, { method: "GET", ...options });
71
+ },
72
+
73
+ /**
74
+ * Create a new internal user (admin or service user) with the specified data.
75
+ * @roles signalhouse
76
+ * @param {Object} params - The parameters for creating an internal user
77
+ * @param {CreateServiceUserData} params.data - The data for the new internal user
78
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
79
+ * @returns {Promise<Object>} - A promise that resolves to the created internal user
80
+ */
81
+ createInternalUser: async ({ data, options = {} }) => {
82
+ this.client._require({ data: data });
83
+ return this.client(`/user/signalhouse`, { method: "POST", body: data, ...options });
84
+ },
85
+ };
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Get a list of users with optional filters
91
+ * @async
92
+ * @roles api, admin, self
93
+ * @param {Object} params - The parameters for getting users
94
+ * @param {string} [params.id] - Filter by user ID
95
+ * @param {string} [params.groupId] - Filter by group ID
96
+ * @param {string} [params.userType] - Filter by user type (user, service)
97
+ * @param {number} [params.page] - Page number for pagination
98
+ * @param {number} [params.limit] - Items per page
99
+ * @param {string} [params.search] - Search users by email (case-insensitive)
100
+ * @param {string} [params.sortBy] - Field to sort by (createdAt, email, activeGroupId, companyName, status, _id)
101
+ * @param {string} [params.sortOrder] - Sort direction (asc, desc)
102
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
103
+ * @returns {Promise<Object>} - A promise that resolves to the list of users
104
+ */
105
+ async getUsers({ id, groupId, userType, page, limit, search, sortBy, sortOrder, options = {} }) {
106
+ const filters = { id, groupId, userType, page, limit, search, sortBy, sortOrder };
107
+ const queryString = this.client._getQueryString(filters);
108
+ return this.client(`/user${queryString}`, { method: "GET", ...options });
109
+ }
110
+
111
+ /**
112
+ * Create a new user with the specified user data
113
+ * @async
114
+ * @roles api, admin
115
+ * @param {Object} params - The parameters for creating a user (see CreateUserData typedef for details)
116
+ * @param {CreateUserData} params.data - The data for the new user
117
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
118
+ * @throws {Error} Throws an error if required fields in the data parameter are missing
119
+ * @returns {Promise<Object>} - A promise that resolves to the created user
120
+ */
121
+ async createUser({ data, options = {} }) {
122
+ this.client._require({ data: data });
123
+ return this.client(`/user`, { method: "POST", body: data, ...options });
124
+ }
125
+
126
+ /**
127
+ * Create a new service user with the specified user data. Used for creating API keys and other non-human users.
128
+ * @async
129
+ * @roles admin, developer
130
+ * @param {Object} params - The parameters for creating a service user (see CreateServiceUserData typedef for details)
131
+ * @param {CreateServiceUserData} params.data - The data for the new service user
132
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
133
+ * @throws {Error} Throws an error if required fields in the data parameter are missing
134
+ * @returns {Promise<Object>} - A promise that resolves to the created service user
135
+ */
136
+ async createServiceUser({ data, options = {} }) {
137
+ this.client._require({ data: data });
138
+ return this.client(`/user/serviceuser`, { method: "POST", body: data, ...options });
139
+ }
140
+
141
+ /**
142
+ * Update an existing user's information with the specified user data
143
+ * @async
144
+ * @roles api, admin, self
145
+ * @param {Object} params - The parameters for updating a user (see UpdateUserData typedef for details)
146
+ * @param {string} params.id - The ID of the user to update
147
+ * @param {UpdateUserData} params.data - The data to update for the user
148
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
149
+ * @throws {Error} Throws an error if required fields in the data parameter are missing
150
+ * @returns {Promise<Object>} - A promise that resolves to the updated user
151
+ */
152
+ async updateUser({ id, data, options = {} }) {
153
+ this.client._require({ id, data: data });
154
+ const safeId = encodeURIComponent(id);
155
+ return this.client(`/user/${safeId}`, { method: "PUT", body: data, ...options });
156
+ }
157
+
158
+ /**
159
+ * Delete a user by their ID (mark as inactive)
160
+ * @async
161
+ * @roles api, admin
162
+ * @param {Object} params - The parameters for deleting a user
163
+ * @param {string} params.id - The ID of the user to delete
164
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
165
+ * @throws {Error} Throws an error if the id parameter is missing
166
+ * @returns {Promise<Object>} - A promise that resolves to the deleted user
167
+ */
168
+ async deleteUser({ id, options = {} }) {
169
+ this.client._require({ id });
170
+ const safeId = encodeURIComponent(id);
171
+ return this.client(`/user/${safeId}`, { method: "DELETE", ...options });
172
+ }
173
+
174
+ /**
175
+ * Get notification preferences for a user
176
+ * @async
177
+ * @roles api, admin, self
178
+ * @param {Object} params
179
+ * @param {string} params.id - The ID of the user
180
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
181
+ * @returns {Promise<Object>} The response from the server
182
+ */
183
+ async getNotificationPreferences({ id, options = {} }) {
184
+ this.client._require({ id });
185
+ const safeId = encodeURIComponent(id);
186
+ return this.client(`/user/${safeId}/notification-preferences`, { method: "GET", ...options });
187
+ }
188
+
189
+ /**
190
+ * Update notification preferences for a user
191
+ * @async
192
+ * @roles api, admin, self
193
+ * @param {Object} params
194
+ * @param {string} params.id - The ID of the user
195
+ * @param {Array<{name: string, web: boolean, email: boolean}>} params.notificationPreferences - Array of notification preference objects
196
+ * @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
197
+ * @returns {Promise<Object>} The response from the server
198
+ */
199
+ async updateNotificationPreferences({ id, notificationPreferences, options = {} }) {
200
+ this.client._require({ id, notificationPreferences });
201
+ const safeId = encodeURIComponent(id);
202
+ return this.client(`/user/${safeId}/notification-preferences`, { method: "PUT", body: { notificationPreferences }, ...options });
203
+ }
204
+ }