@unboundcx/sdk 4.13.153 → 4.13.155

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
@@ -125,6 +125,25 @@ const api = new SDK({
125
125
  });
126
126
  ```
127
127
 
128
+ `tokenDelivery` controls how `token` is attached to outgoing requests:
129
+ `'bearer'` (default, unchanged behavior) sends `Authorization: Bearer
130
+ <token>`; `'cookie'` sends `Cookie: authToken=<token>` instead, merging with
131
+ any `Cookie` header you already pass in `headers`. Use `'cookie'` when
132
+ `token` is a cookie-type token (e.g. forwarded from a browser session) --
133
+ app1-api's auth_v3 middleware rejects those over `Authorization` with
134
+ "Invalid token, authentication method mismatch". `setToken()` works the same
135
+ in either mode, the option is passed through to transport plugins, and
136
+ `autoRefresh`/`refreshToken` are unaffected (cookie clients never need a
137
+ refresh token):
138
+
139
+ ```javascript
140
+ const api = new SDK({
141
+ namespace: 'your-namespace',
142
+ token: cookieAuthToken,
143
+ tokenDelivery: 'cookie', // sends `Cookie: authToken=<token>`
144
+ });
145
+ ```
146
+
128
147
  ### Legacy Positional Constructor (Backwards Compatible)
129
148
 
130
149
  ```javascript
package/base.js CHANGED
@@ -41,6 +41,29 @@ export function internalRequest(sdk, endpoint, method, params = {}, forceFetch)
41
41
  }
42
42
 
43
43
  export class BaseSDK {
44
+ /**
45
+ * @param {object|string} options Object-based options (recommended), or a
46
+ * legacy positional `namespace` string (see constructor body).
47
+ * @param {string} [options.namespace]
48
+ * @param {string} [options.callId]
49
+ * @param {string} [options.token] Auth token; sent per `tokenDelivery`.
50
+ * @param {string} [options.fwRequestId]
51
+ * @param {string} [options.baseURL]
52
+ * @param {boolean} [options.autoRefresh=false] Opt-in 401 refresh+retry.
53
+ * @param {(err: Error) => void} [options.onUnauthorized]
54
+ * @param {string} [options.refreshToken] Bearer-delivery clients only.
55
+ * @param {'bearer'|'cookie'} [options.tokenDelivery='bearer'] How `token`
56
+ * is attached to outgoing requests. 'bearer' (default, unchanged
57
+ * behavior) sends `Authorization: Bearer <token>`. 'cookie' sends
58
+ * `Cookie: authToken=<token>` instead (merged with any caller-supplied
59
+ * Cookie header) -- required for cookie-type tokens, which app1-api's
60
+ * auth_v3 middleware rejects with "Invalid token, authentication
61
+ * method mismatch" when they arrive as a Bearer header. Applies to the
62
+ * built-in HTTP transport and is passed through to transport plugins'
63
+ * options object as `tokenDelivery`. `setToken` keeps working in both
64
+ * modes; `autoRefresh` is unaffected (cookie clients never need
65
+ * `refreshToken`).
66
+ */
44
67
  constructor(options = {}) {
45
68
  // Support both object and legacy positional parameters for backwards compatibility
46
69
  if (typeof options === 'string') {
@@ -49,6 +72,8 @@ export class BaseSDK {
49
72
  this.callId = arguments[1];
50
73
  this.token = arguments[2];
51
74
  this.fwRequestId = arguments[3];
75
+ // Legacy positional constructor has no slot for this; always bearer.
76
+ this._tokenDelivery = 'bearer';
52
77
  } else {
53
78
  // New object-based parameters
54
79
  const {
@@ -60,6 +85,7 @@ export class BaseSDK {
60
85
  autoRefresh,
61
86
  onUnauthorized,
62
87
  refreshToken,
88
+ tokenDelivery,
63
89
  } = options;
64
90
  this.namespace = namespace || process?.env?.namespace;
65
91
  this.callId = callId;
@@ -78,6 +104,15 @@ export class BaseSDK {
78
104
  // Seeded via this option or setRefreshToken(); updated in place on
79
105
  // every rotation by lib/refreshInterceptor.js.
80
106
  this._refreshToken = refreshToken;
107
+ // Additive, opt-in (default 'bearer' -- unchanged behavior: the token
108
+ // goes out as `Authorization: Bearer <token>`). 'cookie' sends it as
109
+ // `Cookie: authToken=<token>` instead -- app1-api auth_v3 rejects a
110
+ // cookie-type token carried as a Bearer header with "Invalid token,
111
+ // authentication method mismatch" (cookie-type tokens must arrive as
112
+ // a cookie). Applies to the built-in HTTP transport and is also
113
+ // passed through to transport plugins' options object. autoRefresh
114
+ // is unaffected: cookie clients never carry a refreshToken.
115
+ this._tokenDelivery = tokenDelivery === 'cookie' ? 'cookie' : 'bearer';
81
116
  }
82
117
  this.baseURL;
83
118
  this.transports = new Map();
@@ -262,7 +297,20 @@ export class BaseSDK {
262
297
 
263
298
  // Add auth headers
264
299
  if (this.token) {
265
- headers.Authorization = `Bearer ${this.token}`;
300
+ if (this._tokenDelivery === 'cookie') {
301
+ // Cookie-type tokens must arrive as a cookie, never Authorization
302
+ // (see constructor doc above). Merge with any caller-supplied
303
+ // Cookie header rather than clobbering it.
304
+ const existingCookie = headers.Cookie ?? headers.cookie;
305
+ if (headers.cookie !== undefined && headers.Cookie === undefined) {
306
+ delete headers.cookie;
307
+ }
308
+ headers.Cookie = existingCookie
309
+ ? `${existingCookie}; authToken=${this.token}`
310
+ : `authToken=${this.token}`;
311
+ } else {
312
+ headers.Authorization = `Bearer ${this.token}`;
313
+ }
266
314
  }
267
315
  if (this.fwRequestId) {
268
316
  headers['x-request-id-fw'] = this.fwRequestId;
@@ -284,6 +332,7 @@ export class BaseSDK {
284
332
  callId: this.callId,
285
333
  fwRequestId: this.fwRequestId,
286
334
  baseURL: this.baseURL || this.fullUrl,
335
+ tokenDelivery: this._tokenDelivery,
287
336
  });
288
337
  } catch (err) {
289
338
  // IMPORTANT: This catch block should ONLY handle transport-level failures
package/index.js CHANGED
@@ -100,9 +100,10 @@ class UnboundSDK extends BaseSDK {
100
100
  url,
101
101
  socketStore,
102
102
  baseURL,
103
+ tokenDelivery,
103
104
  } = options;
104
105
 
105
- super({ namespace, callId, token, fwRequestId, baseURL });
106
+ super({ namespace, callId, token, fwRequestId, baseURL, tokenDelivery });
106
107
 
107
108
  // Handle client-side specific parameters
108
109
  if (url) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.153",
3
+ "version": "4.13.155",
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",
@@ -24,6 +24,7 @@ export class ReportingCallLogService {
24
24
  * @param {Object} params - { from, to, direction?: 'inbound'|'outbound',
25
25
  * answered?: boolean, queueIds?: string[], ringGroupIds?: string[],
26
26
  * userIds?: string[], phoneNumber?: string, recordingOnly?: boolean,
27
+ * lowMos?: boolean (any measured leg MOS below the low-quality threshold),
27
28
  * cursor?: string, limit?: number }
28
29
  * @returns {Promise<Object>} { rows, cursor, hasMore, summary: { totalCalls, answeredCalls, missedCalls, answeredPct, avgBillDurationSec } }
29
30
  * @example
@@ -39,6 +40,7 @@ export class ReportingCallLogService {
39
40
  userIds,
40
41
  phoneNumber,
41
42
  recordingOnly,
43
+ lowMos,
42
44
  cursor,
43
45
  limit,
44
46
  } = {}) {
@@ -61,6 +63,8 @@ export class ReportingCallLogService {
61
63
  userIds,
62
64
  phoneNumber,
63
65
  recordingOnly,
66
+ lowMos,
67
+ lowMos,
64
68
  cursor,
65
69
  limit,
66
70
  })}`,
@@ -85,6 +89,7 @@ export class ReportingCallLogService {
85
89
  userIds,
86
90
  phoneNumber,
87
91
  recordingOnly,
92
+ lowMos,
88
93
  } = {}) {
89
94
  this.sdk.validateParams(
90
95
  { from, to },
@@ -105,6 +110,8 @@ export class ReportingCallLogService {
105
110
  userIds,
106
111
  phoneNumber,
107
112
  recordingOnly,
113
+ lowMos,
114
+ lowMos,
108
115
  format: 'csv',
109
116
  })}`,
110
117
  'GET',
@@ -120,7 +127,7 @@ export class ReportingCallLogService {
120
127
  * @param {Object} params - { from, to, direction?: 'inbound'|'outbound',
121
128
  * answered?: boolean, queueIds?: string[], ringGroupIds?: string[],
122
129
  * userIds?: string[], phoneNumber?: string, recordingOnly?: boolean,
123
- * tz?: string }
130
+ * lowMos?: boolean, tz?: string }
124
131
  * @returns {Promise<Object>} { bucket: 'hour'|'day', timezone, series: [{ start, end, answered, missed, voicemail, total }] }
125
132
  * @example
126
133
  * await sdk.reporting.callLog.series({ from, to });
@@ -135,6 +142,7 @@ export class ReportingCallLogService {
135
142
  userIds,
136
143
  phoneNumber,
137
144
  recordingOnly,
145
+ lowMos,
138
146
  tz,
139
147
  } = {}) {
140
148
  this.sdk.validateParams(
@@ -156,6 +164,8 @@ export class ReportingCallLogService {
156
164
  userIds,
157
165
  phoneNumber,
158
166
  recordingOnly,
167
+ lowMos,
168
+ lowMos,
159
169
  tz,
160
170
  })}`,
161
171
  'GET',