@signalhouse-sms/sdk 1.17.1 → 1.18.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/README.md CHANGED
@@ -45,6 +45,9 @@ const token = await sdk.auth.login({
45
45
  console.log(token);
46
46
  ```
47
47
 
48
+ Error handling
49
+ API errors are returned, not thrown: `{ success: false, error, status }`. Non-2xx responses carry `details` when the API returns one. Connector tokens get 429 `CONNECTOR_CAP_EXCEEDED` (`details.code`, with `cap`, `limit` and `retryAfterSeconds`) or 503 `CONNECTOR_CAP_UNAVAILABLE` (with `retryAfterSeconds`). Wait `details.retryAfterSeconds` before retrying.
50
+
48
51
  Features
49
52
  Full support for Signal House API v2
50
53
  Integrated Axios with standardized returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalhouse-sms/sdk",
3
- "version": "1.17.1",
3
+ "version": "1.18.0",
4
4
  "description": "Signal House SDK for use with the Signal House platform",
5
5
  "type": "module",
6
6
  "main": "src/SignalHouseSDK.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "source": "agent-skills",
3
- "ref": "v0.3.0",
3
+ "ref": "v0.4.0",
4
4
  "skills": [
5
5
  "signalhouse-10dlc",
6
6
  "signalhouse-advisor",
@@ -17,6 +17,6 @@
17
17
  "signalhouse-numbers/SKILL.md": "f996be53809ea2f90e49b32452f162eeff5369056e1f63e422b8fdb46d2896ff",
18
18
  "signalhouse-setup/SKILL.md": "ca87a6d71f3f82614b83ad283971385fc55c13c097b76595b1b85def235373ec",
19
19
  "signalhouse-sms/SKILL.md": "ec7ed8985ad590b0ab5d40c9ddb003eb8cbc566a1309ac5e330f570e0404ec42",
20
- "signalhouse-webhooks/SKILL.md": "d16062e9e0a7cdda3c02aee485bd5114659405d00b1d635da1280db0179490a7"
20
+ "signalhouse-webhooks/SKILL.md": "4806f0cff0c05dee490103e1ba42de784bc270b3111da4d285784ea1ecbbed94"
21
21
  }
22
22
  }
@@ -20,10 +20,31 @@ const REQUEST_TIMEOUT_MS = 30000;
20
20
 
21
21
  /**
22
22
  * The envelope every domain method resolves to. Non-2xx responses never reject; check `success` first.
23
+ * An error envelope carries `details` when the API error body has one, for example `details.code` and
24
+ * `details.retryAfterSeconds` on a connector cap response.
23
25
  * @template T
24
- * @typedef {{ success: true, data: T, status: number } | { success: false, error: string|Object, status: number|null }} SdkResponse
26
+ * @typedef {{ success: true, data: T, status: number } | { success: false, error: string|Object, status: number|null, details?: Object|Array }} SdkResponse
25
27
  */
26
28
 
29
+ /**
30
+ * Decodes a binary error body (ArrayBuffer, Buffer/typed array or Blob from a binary responseType request) as JSON so
31
+ * its `details` can be read. Non-binary bodies are returned unchanged.
32
+ * @async
33
+ * @param {*} data - The axios error response body.
34
+ * @returns {Promise<*>} - The parsed JSON body, the original body when it is not binary, or null when it is not JSON.
35
+ */
36
+ async function parseBinaryErrorBody(data) {
37
+ let text;
38
+ if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) text = new TextDecoder().decode(data);
39
+ else if (typeof Blob !== "undefined" && data instanceof Blob) text = await data.text();
40
+ else return data;
41
+ try {
42
+ return JSON.parse(text);
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
27
48
  // Main SDK Class (SignalHouseSDK.js)
28
49
  import { Auth } from "./domains/Auth.js";
29
50
  import { Billing } from "./domains/Billing.js";
@@ -147,7 +168,7 @@ export class SignalHouseSDK {
147
168
 
148
169
  // Non-2xx responses, plus timeouts and network failures (no `error.response` at all) - those
149
170
  // get a clear message here rather than surfacing axios's internal error.message verbatim.
150
- (error) => {
171
+ async (error) => {
151
172
  if (!error.response) {
152
173
  const isTimeout = error.code === "ECONNABORTED" || /timeout/i.test(error.message || "");
153
174
  return {
@@ -156,11 +177,15 @@ export class SignalHouseSDK {
156
177
  status: null,
157
178
  };
158
179
  }
159
- return {
180
+ const data = error.response.data;
181
+ const result = {
160
182
  success: false,
161
183
  error: error.response?.data?.message || error.response?.data || error.message || 500,
162
184
  status: error.response?.status || error.response?.data || null,
163
185
  };
186
+ const body = await parseBinaryErrorBody(data);
187
+ if (body && typeof body === "object" && "details" in body) result.details = body.details;
188
+ return result;
164
189
  },
165
190
  );
166
191
 
@@ -400,6 +400,13 @@ export class Agents {
400
400
  * `status` records HOW it ended and cannot be recovered afterwards, so pass the one that
401
401
  * actually happened. Ending an already-ended conversation is a no-op, so a retry after a
402
402
  * dropped connection cannot overwrite it.
403
+ *
404
+ * The end fires the AI_AGENT_CONVERSATION_ENDED webhook once, with the transcript; a retry fires
405
+ * nothing. `metadata.endReason` is passed on as the webhook's `endReason`.
406
+ *
407
+ * Voice conversations can't be ended here (403): the voice service ends each one when its call ends,
408
+ * because its length sets the call's AI Voice Agent charge. `metadata.agentSeconds` and
409
+ * `metadata.durationSeconds` are reserved for the voice service and are ignored if sent.
403
410
  * @async
404
411
  * @roles api, admin, developer, billing, user
405
412
  * @param {Object} params - The parameters for ending a conversation.
@@ -252,6 +252,7 @@ export class Billing {
252
252
  /**
253
253
  * Get the fee schedule for a specific group.
254
254
  * When the group is on a custom volume-tiered plan, the response also includes volumePricing: tiers, the current period's dates, count and minimum, ramp, and current rate (rates in microdollars per segment).
255
+ * aiAgentPerMinute is the rate for an AI voice agent's time on a call, in microdollars per minute prorated per second, charged on top of the call's own rate.
255
256
  * @async
256
257
  * @roles api, admin, developer, billing, user
257
258
  * @param {Object} params - The parameters for getting the fees
@@ -88,6 +88,8 @@ export type SignalHouseSDKConfig = {
88
88
  };
89
89
  /**
90
90
  * The envelope every domain method resolves to. Non-2xx responses never reject; check `success` first.
91
+ * An error envelope carries `details` when the API error body has one, for example `details.code` and
92
+ * `details.retryAfterSeconds` on a connector cap response.
91
93
  */
92
94
  export type SdkResponse<T> = {
93
95
  success: true;
@@ -97,6 +99,7 @@ export type SdkResponse<T> = {
97
99
  success: false;
98
100
  error: string | any;
99
101
  status: number | null;
102
+ details?: any | any[];
100
103
  };
101
104
  import { Auth } from "./domains/Auth.js";
102
105
  import { Billing } from "./domains/Billing.js";
@@ -376,6 +376,13 @@ export class Agents {
376
376
  * `status` records HOW it ended and cannot be recovered afterwards, so pass the one that
377
377
  * actually happened. Ending an already-ended conversation is a no-op, so a retry after a
378
378
  * dropped connection cannot overwrite it.
379
+ *
380
+ * The end fires the AI_AGENT_CONVERSATION_ENDED webhook once, with the transcript; a retry fires
381
+ * nothing. `metadata.endReason` is passed on as the webhook's `endReason`.
382
+ *
383
+ * Voice conversations can't be ended here (403): the voice service ends each one when its call ends,
384
+ * because its length sets the call's AI Voice Agent charge. `metadata.agentSeconds` and
385
+ * `metadata.durationSeconds` are reserved for the voice service and are ignored if sent.
379
386
  * @async
380
387
  * @roles api, admin, developer, billing, user
381
388
  * @param {Object} params - The parameters for ending a conversation.
@@ -261,6 +261,7 @@ export class Billing {
261
261
  /**
262
262
  * Get the fee schedule for a specific group.
263
263
  * When the group is on a custom volume-tiered plan, the response also includes volumePricing: tiers, the current period's dates, count and minimum, ramp, and current rate (rates in microdollars per segment).
264
+ * aiAgentPerMinute is the rate for an AI voice agent's time on a call, in microdollars per minute prorated per second, charged on top of the call's own rate.
264
265
  * @async
265
266
  * @roles api, admin, developer, billing, user
266
267
  * @param {Object} params - The parameters for getting the fees