genesys-cloud-streaming-client 19.6.0 → 19.6.1-develop.17

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.
@@ -2345,16 +2345,16 @@ const G = getGlobal();
2345
2345
  const FormDataCtor = typeof G.FormData !== 'undefined' ? G.FormData : undefined;
2346
2346
 
2347
2347
  const isFormData = (thing) => {
2348
- let kind;
2349
- return thing && (
2350
- (FormDataCtor && thing instanceof FormDataCtor) || (
2351
- isFunction$1(thing.append) && (
2352
- (kind = kindOf(thing)) === 'formdata' ||
2353
- // detect form-data instance
2354
- (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
2355
- )
2356
- )
2357
- );
2348
+ if (!thing) return false;
2349
+ if (FormDataCtor && thing instanceof FormDataCtor) return true;
2350
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData (GHSA-6chq-wfr3-2hj9).
2351
+ const proto = getPrototypeOf(thing);
2352
+ if (!proto || proto === Object.prototype) return false;
2353
+ if (!isFunction$1(thing.append)) return false;
2354
+ const kind = kindOf(thing);
2355
+ return kind === 'formdata' ||
2356
+ // detect form-data instance
2357
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]');
2358
2358
  };
2359
2359
 
2360
2360
  /**
@@ -4994,40 +4994,40 @@ class AxiosError$1 extends Error {
4994
4994
  return axiosError;
4995
4995
  }
4996
4996
 
4997
- /**
4998
- * Create an Error with the specified message, config, error code, request and response.
4999
- *
5000
- * @param {string} message The error message.
5001
- * @param {string} [code] The error code (for example, 'ECONNABORTED').
5002
- * @param {Object} [config] The config.
5003
- * @param {Object} [request] The request.
5004
- * @param {Object} [response] The response.
5005
- *
5006
- * @returns {Error} The created error.
5007
- */
5008
- constructor(message, code, config, request, response) {
5009
- super(message);
5010
-
5011
- // Make message enumerable to maintain backward compatibility
5012
- // The native Error constructor sets message as non-enumerable,
5013
- // but axios < v1.13.3 had it as enumerable
5014
- Object.defineProperty(this, 'message', {
5015
- value: message,
5016
- enumerable: true,
5017
- writable: true,
5018
- configurable: true
5019
- });
5020
-
5021
- this.name = 'AxiosError';
5022
- this.isAxiosError = true;
5023
- code && (this.code = code);
5024
- config && (this.config = config);
5025
- request && (this.request = request);
5026
- if (response) {
5027
- this.response = response;
5028
- this.status = response.status;
5029
- }
4997
+ /**
4998
+ * Create an Error with the specified message, config, error code, request and response.
4999
+ *
5000
+ * @param {string} message The error message.
5001
+ * @param {string} [code] The error code (for example, 'ECONNABORTED').
5002
+ * @param {Object} [config] The config.
5003
+ * @param {Object} [request] The request.
5004
+ * @param {Object} [response] The response.
5005
+ *
5006
+ * @returns {Error} The created error.
5007
+ */
5008
+ constructor(message, code, config, request, response) {
5009
+ super(message);
5010
+
5011
+ // Make message enumerable to maintain backward compatibility
5012
+ // The native Error constructor sets message as non-enumerable,
5013
+ // but axios < v1.13.3 had it as enumerable
5014
+ Object.defineProperty(this, 'message', {
5015
+ value: message,
5016
+ enumerable: true,
5017
+ writable: true,
5018
+ configurable: true,
5019
+ });
5020
+
5021
+ this.name = 'AxiosError';
5022
+ this.isAxiosError = true;
5023
+ code && (this.code = code);
5024
+ config && (this.config = config);
5025
+ request && (this.request = request);
5026
+ if (response) {
5027
+ this.response = response;
5028
+ this.status = response.status;
5030
5029
  }
5030
+ }
5031
5031
 
5032
5032
  toJSON() {
5033
5033
  return {
@@ -5063,6 +5063,7 @@ AxiosError$1.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
5063
5063
  AxiosError$1.ERR_CANCELED = 'ERR_CANCELED';
5064
5064
  AxiosError$1.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
5065
5065
  AxiosError$1.ERR_INVALID_URL = 'ERR_INVALID_URL';
5066
+ AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
5066
5067
 
5067
5068
  // eslint-disable-next-line strict
5068
5069
  var httpAdapter = null;
@@ -5177,6 +5178,7 @@ function toFormData$1(obj, formData, options) {
5177
5178
  const dots = options.dots;
5178
5179
  const indexes = options.indexes;
5179
5180
  const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
5181
+ const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
5180
5182
  const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
5181
5183
 
5182
5184
  if (!utils$1.isFunction(visitor)) {
@@ -5269,9 +5271,16 @@ function toFormData$1(obj, formData, options) {
5269
5271
  isVisitable,
5270
5272
  });
5271
5273
 
5272
- function build(value, path) {
5274
+ function build(value, path, depth = 0) {
5273
5275
  if (utils$1.isUndefined(value)) return;
5274
5276
 
5277
+ if (depth > maxDepth) {
5278
+ throw new AxiosError$1(
5279
+ 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
5280
+ AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
5281
+ );
5282
+ }
5283
+
5275
5284
  if (stack.indexOf(value) !== -1) {
5276
5285
  throw Error('Circular reference detected in ' + path.join('.'));
5277
5286
  }
@@ -5284,7 +5293,7 @@ function toFormData$1(obj, formData, options) {
5284
5293
  visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
5285
5294
 
5286
5295
  if (result === true) {
5287
- build(el, path ? path.concat(key) : [key]);
5296
+ build(el, path ? path.concat(key) : [key], depth + 1);
5288
5297
  }
5289
5298
  });
5290
5299
 
@@ -5316,9 +5325,8 @@ function encode$2(str) {
5316
5325
  ')': '%29',
5317
5326
  '~': '%7E',
5318
5327
  '%20': '+',
5319
- '%00': '\x00',
5320
5328
  };
5321
- return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
5329
+ return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
5322
5330
  return charMap[match];
5323
5331
  });
5324
5332
  }
@@ -5638,7 +5646,9 @@ function formDataToJSON(formData) {
5638
5646
 
5639
5647
  if (isLast) {
5640
5648
  if (utils$1.hasOwnProp(target, name)) {
5641
- target[name] = [target[name], value];
5649
+ target[name] = utils$1.isArray(target[name])
5650
+ ? target[name].concat(value)
5651
+ : [target[name], value];
5642
5652
  } else {
5643
5653
  target[name] = value;
5644
5654
  }
@@ -5672,6 +5682,8 @@ function formDataToJSON(formData) {
5672
5682
  return null;
5673
5683
  }
5674
5684
 
5685
+ const own = (obj, key) => (obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : undefined);
5686
+
5675
5687
  /**
5676
5688
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
5677
5689
  * of the input
@@ -5739,20 +5751,22 @@ const defaults = {
5739
5751
  let isFileList;
5740
5752
 
5741
5753
  if (isObjectPayload) {
5754
+ const formSerializer = own(this, 'formSerializer');
5742
5755
  if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
5743
- return toURLEncodedForm(data, this.formSerializer).toString();
5756
+ return toURLEncodedForm(data, formSerializer).toString();
5744
5757
  }
5745
5758
 
5746
5759
  if (
5747
5760
  (isFileList = utils$1.isFileList(data)) ||
5748
5761
  contentType.indexOf('multipart/form-data') > -1
5749
5762
  ) {
5750
- const _FormData = this.env && this.env.FormData;
5763
+ const env = own(this, 'env');
5764
+ const _FormData = env && env.FormData;
5751
5765
 
5752
5766
  return toFormData$1(
5753
5767
  isFileList ? { 'files[]': data } : data,
5754
5768
  _FormData && new _FormData(),
5755
- this.formSerializer
5769
+ formSerializer
5756
5770
  );
5757
5771
  }
5758
5772
  }
@@ -5768,9 +5782,10 @@ const defaults = {
5768
5782
 
5769
5783
  transformResponse: [
5770
5784
  function transformResponse(data) {
5771
- const transitional = this.transitional || defaults.transitional;
5785
+ const transitional = own(this, 'transitional') || defaults.transitional;
5772
5786
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
5773
- const JSONRequested = this.responseType === 'json';
5787
+ const responseType = own(this, 'responseType');
5788
+ const JSONRequested = responseType === 'json';
5774
5789
 
5775
5790
  if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
5776
5791
  return data;
@@ -5779,17 +5794,17 @@ const defaults = {
5779
5794
  if (
5780
5795
  data &&
5781
5796
  utils$1.isString(data) &&
5782
- ((forcedJSONParsing && !this.responseType) || JSONRequested)
5797
+ ((forcedJSONParsing && !responseType) || JSONRequested)
5783
5798
  ) {
5784
5799
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
5785
5800
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
5786
5801
 
5787
5802
  try {
5788
- return JSON.parse(data, this.parseReviver);
5803
+ return JSON.parse(data, own(this, 'parseReviver'));
5789
5804
  } catch (e) {
5790
5805
  if (strictJSONParsing) {
5791
5806
  if (e.name === 'SyntaxError') {
5792
- throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
5807
+ throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, own(this, 'response'));
5793
5808
  }
5794
5809
  throw e;
5795
5810
  }
@@ -5901,41 +5916,41 @@ var parseHeaders = (rawHeaders) => {
5901
5916
 
5902
5917
  const $internals = Symbol('internals');
5903
5918
 
5904
- const isValidHeaderValue = (value) => !/[\r\n]/.test(value);
5919
+ const INVALID_HEADER_VALUE_CHARS_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
5905
5920
 
5906
- function assertValidHeaderValue(value, header) {
5907
- if (value === false || value == null) {
5908
- return;
5909
- }
5910
-
5911
- if (utils$1.isArray(value)) {
5912
- value.forEach((v) => assertValidHeaderValue(v, header));
5913
- return;
5914
- }
5921
+ function trimSPorHTAB(str) {
5922
+ let start = 0;
5923
+ let end = str.length;
5915
5924
 
5916
- if (!isValidHeaderValue(String(value))) {
5917
- throw new Error(`Invalid character in header content ["${header}"]`);
5918
- }
5919
- }
5925
+ while (start < end) {
5926
+ const code = str.charCodeAt(start);
5920
5927
 
5921
- function normalizeHeader(header) {
5922
- return header && String(header).trim().toLowerCase();
5923
- }
5928
+ if (code !== 0x09 && code !== 0x20) {
5929
+ break;
5930
+ }
5924
5931
 
5925
- function stripTrailingCRLF(str) {
5926
- let end = str.length;
5932
+ start += 1;
5933
+ }
5927
5934
 
5928
- while (end > 0) {
5929
- const charCode = str.charCodeAt(end - 1);
5935
+ while (end > start) {
5936
+ const code = str.charCodeAt(end - 1);
5930
5937
 
5931
- if (charCode !== 10 && charCode !== 13) {
5938
+ if (code !== 0x09 && code !== 0x20) {
5932
5939
  break;
5933
5940
  }
5934
5941
 
5935
5942
  end -= 1;
5936
5943
  }
5937
5944
 
5938
- return end === str.length ? str : str.slice(0, end);
5945
+ return start === 0 && end === str.length ? str : str.slice(start, end);
5946
+ }
5947
+
5948
+ function normalizeHeader(header) {
5949
+ return header && String(header).trim().toLowerCase();
5950
+ }
5951
+
5952
+ function sanitizeHeaderValue(str) {
5953
+ return trimSPorHTAB(str.replace(INVALID_HEADER_VALUE_CHARS_RE, ''));
5939
5954
  }
5940
5955
 
5941
5956
  function normalizeValue(value) {
@@ -5943,7 +5958,7 @@ function normalizeValue(value) {
5943
5958
  return value;
5944
5959
  }
5945
5960
 
5946
- return utils$1.isArray(value) ? value.map(normalizeValue) : stripTrailingCRLF(String(value));
5961
+ return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
5947
5962
  }
5948
5963
 
5949
5964
  function parseTokens(str) {
@@ -6025,7 +6040,6 @@ class AxiosHeaders$1 {
6025
6040
  _rewrite === true ||
6026
6041
  (_rewrite === undefined && self[key] !== false)
6027
6042
  ) {
6028
- assertValidHeaderValue(_value, _header);
6029
6043
  self[key || _header] = normalizeValue(_value);
6030
6044
  }
6031
6045
  }
@@ -6448,13 +6462,13 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
6448
6462
  const _speedometer = speedometer(50, 250);
6449
6463
 
6450
6464
  return throttle$1((e) => {
6451
- const loaded = e.loaded;
6465
+ const rawLoaded = e.loaded;
6452
6466
  const total = e.lengthComputable ? e.total : undefined;
6453
- const progressBytes = loaded - bytesNotified;
6467
+ const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
6468
+ const progressBytes = Math.max(0, loaded - bytesNotified);
6454
6469
  const rate = _speedometer(progressBytes);
6455
- const inRange = loaded <= total;
6456
6470
 
6457
- bytesNotified = loaded;
6471
+ bytesNotified = Math.max(bytesNotified, loaded);
6458
6472
 
6459
6473
  const data = {
6460
6474
  loaded,
@@ -6462,7 +6476,7 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
6462
6476
  progress: total ? loaded / total : undefined,
6463
6477
  bytes: progressBytes,
6464
6478
  rate: rate ? rate : undefined,
6465
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
6479
+ estimated: rate && total ? (total - loaded) / rate : undefined,
6466
6480
  event: e,
6467
6481
  lengthComputable: total != null,
6468
6482
  [isDownloadStream ? 'download' : 'upload']: true,
@@ -6596,7 +6610,7 @@ function combineURLs(baseURL, relativeURL) {
6596
6610
  */
6597
6611
  function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
6598
6612
  let isRelativeUrl = !isAbsoluteURL(requestedURL);
6599
- if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
6613
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
6600
6614
  return combineURLs(baseURL, requestedURL);
6601
6615
  }
6602
6616
  return requestedURL;
@@ -6616,7 +6630,18 @@ const headersToObject = (thing) => (thing instanceof AxiosHeaders$1 ? { ...thing
6616
6630
  function mergeConfig$1(config1, config2) {
6617
6631
  // eslint-disable-next-line no-param-reassign
6618
6632
  config2 = config2 || {};
6619
- const config = {};
6633
+
6634
+ // Use a null-prototype object so that downstream reads such as `config.auth`
6635
+ // or `config.baseURL` cannot inherit polluted values from Object.prototype
6636
+ // (see GHSA-q8qp-cvcw-x6jj). `hasOwnProperty` is restored as a non-enumerable
6637
+ // own slot to preserve ergonomics for user code that relies on it.
6638
+ const config = Object.create(null);
6639
+ Object.defineProperty(config, 'hasOwnProperty', {
6640
+ value: Object.prototype.hasOwnProperty,
6641
+ enumerable: false,
6642
+ writable: true,
6643
+ configurable: true,
6644
+ });
6620
6645
 
6621
6646
  function getMergedValue(target, source, prop, caseless) {
6622
6647
  if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
@@ -6655,9 +6680,9 @@ function mergeConfig$1(config1, config2) {
6655
6680
 
6656
6681
  // eslint-disable-next-line consistent-return
6657
6682
  function mergeDirectKeys(a, b, prop) {
6658
- if (prop in config2) {
6683
+ if (utils$1.hasOwnProp(config2, prop)) {
6659
6684
  return getMergedValue(a, b);
6660
- } else if (prop in config1) {
6685
+ } else if (utils$1.hasOwnProp(config1, prop)) {
6661
6686
  return getMergedValue(undefined, a);
6662
6687
  }
6663
6688
  }
@@ -6689,6 +6714,7 @@ function mergeConfig$1(config1, config2) {
6689
6714
  httpsAgent: defaultToConfig2,
6690
6715
  cancelToken: defaultToConfig2,
6691
6716
  socketPath: defaultToConfig2,
6717
+ allowedSocketPaths: defaultToConfig2,
6692
6718
  responseEncoding: defaultToConfig2,
6693
6719
  validateStatus: mergeDirectKeys,
6694
6720
  headers: (a, b, prop) =>
@@ -6698,7 +6724,9 @@ function mergeConfig$1(config1, config2) {
6698
6724
  utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
6699
6725
  if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
6700
6726
  const merge = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
6701
- const configValue = merge(config1[prop], config2[prop], prop);
6727
+ const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
6728
+ const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : undefined;
6729
+ const configValue = merge(a, b, prop);
6702
6730
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
6703
6731
  });
6704
6732
 
@@ -6708,12 +6736,24 @@ function mergeConfig$1(config1, config2) {
6708
6736
  var resolveConfig = (config) => {
6709
6737
  const newConfig = mergeConfig$1({}, config);
6710
6738
 
6711
- let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
6739
+ // Read only own properties to prevent prototype pollution gadgets
6740
+ // (e.g. Object.prototype.baseURL = 'https://evil.com'). See GHSA-q8qp-cvcw-x6jj.
6741
+ const own = (key) => (utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : undefined);
6742
+
6743
+ const data = own('data');
6744
+ let withXSRFToken = own('withXSRFToken');
6745
+ const xsrfHeaderName = own('xsrfHeaderName');
6746
+ const xsrfCookieName = own('xsrfCookieName');
6747
+ let headers = own('headers');
6748
+ const auth = own('auth');
6749
+ const baseURL = own('baseURL');
6750
+ const allowAbsoluteUrls = own('allowAbsoluteUrls');
6751
+ const url = own('url');
6712
6752
 
6713
6753
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
6714
6754
 
6715
6755
  newConfig.url = buildURL(
6716
- buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls),
6756
+ buildFullPath(baseURL, url, allowAbsoluteUrls),
6717
6757
  config.params,
6718
6758
  config.paramsSerializer
6719
6759
  );
@@ -6752,10 +6792,18 @@ var resolveConfig = (config) => {
6752
6792
  // Specifically not if we're in a web worker, or react-native.
6753
6793
 
6754
6794
  if (platform.hasStandardBrowserEnv) {
6755
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
6795
+ if (utils$1.isFunction(withXSRFToken)) {
6796
+ withXSRFToken = withXSRFToken(newConfig);
6797
+ }
6756
6798
 
6757
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
6758
- // Add xsrf header
6799
+ // Strict boolean check prevents proto-pollution gadgets (e.g. Object.prototype.withXSRFToken = 1)
6800
+ // and misconfigurations (e.g. "false") from short-circuiting the same-origin check and leaking
6801
+ // the XSRF token cross-origin. See GHSA-xx6v-rp6x-q39c.
6802
+ const shouldSendXSRF =
6803
+ withXSRFToken === true ||
6804
+ (withXSRFToken == null && isURLSameOrigin(newConfig.url));
6805
+
6806
+ if (shouldSendXSRF) {
6759
6807
  const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
6760
6808
 
6761
6809
  if (xsrfValue) {
@@ -7174,18 +7222,20 @@ const factory = (env) => {
7174
7222
  test(() => {
7175
7223
  let duplexAccessed = false;
7176
7224
 
7177
- const body = new ReadableStream$1();
7178
-
7179
- const hasContentType = new Request(platform.origin, {
7180
- body,
7225
+ const request = new Request(platform.origin, {
7226
+ body: new ReadableStream$1(),
7181
7227
  method: 'POST',
7182
7228
  get duplex() {
7183
7229
  duplexAccessed = true;
7184
7230
  return 'half';
7185
7231
  },
7186
- }).headers.has('Content-Type');
7232
+ });
7187
7233
 
7188
- body.cancel();
7234
+ const hasContentType = request.headers.has('Content-Type');
7235
+
7236
+ if (request.body != null) {
7237
+ request.body.cancel();
7238
+ }
7189
7239
 
7190
7240
  return duplexAccessed && !hasContentType;
7191
7241
  });
@@ -7329,6 +7379,19 @@ const factory = (env) => {
7329
7379
  // see https://github.com/cloudflare/workerd/issues/902
7330
7380
  const isCredentialsSupported = isRequestSupported && 'credentials' in Request.prototype;
7331
7381
 
7382
+ // If data is FormData and Content-Type is multipart/form-data without boundary,
7383
+ // delete it so fetch can set it correctly with the boundary
7384
+ if (utils$1.isFormData(data)) {
7385
+ const contentType = headers.getContentType();
7386
+ if (
7387
+ contentType &&
7388
+ /^multipart\/form-data/i.test(contentType) &&
7389
+ !/boundary=/i.test(contentType)
7390
+ ) {
7391
+ headers.delete('content-type');
7392
+ }
7393
+ }
7394
+
7332
7395
  const resolvedOptions = {
7333
7396
  ...fetchOptions,
7334
7397
  signal: composedSignal,
@@ -7637,7 +7700,7 @@ function dispatchRequest(config) {
7637
7700
  );
7638
7701
  }
7639
7702
 
7640
- const VERSION$1 = "1.15.0";
7703
+ const VERSION$1 = "1.15.2";
7641
7704
 
7642
7705
  const validators$1 = {};
7643
7706
 
@@ -7722,7 +7785,9 @@ function assertOptions(options, schema, allowUnknown) {
7722
7785
  let i = keys.length;
7723
7786
  while (i-- > 0) {
7724
7787
  const opt = keys[i];
7725
- const validator = schema[opt];
7788
+ // Use hasOwnProperty so a polluted Object.prototype.<opt> cannot supply
7789
+ // a non-function validator and cause a TypeError. See GHSA-q8qp-cvcw-x6jj.
7790
+ const validator = Object.prototype.hasOwnProperty.call(schema, opt) ? schema[opt] : undefined;
7726
7791
  if (validator) {
7727
7792
  const value = options[opt];
7728
7793
  const result = value === undefined || validator(value, opt, options);
@@ -12013,12 +12078,6 @@ if (!commonjsGlobal) {
12013
12078
  Object.defineProperty(window, 'crypto', { value: window.crypto || window.msCrypto, writable: false, configurable: false });
12014
12079
  }
12015
12080
 
12016
- class TimeoutError extends Error {
12017
- constructor(message) {
12018
- super(message);
12019
- }
12020
- }
12021
-
12022
12081
  var AlertableInteractionTypes;
12023
12082
  (function (AlertableInteractionTypes) {
12024
12083
  AlertableInteractionTypes["voice"] = "voice";
@@ -12039,6 +12098,12 @@ var SessionTypes;
12039
12098
  SessionTypes["unknown"] = "unknown";
12040
12099
  })(SessionTypes || (SessionTypes = {}));
12041
12100
 
12101
+ class TimeoutError extends Error {
12102
+ constructor(message) {
12103
+ super(message);
12104
+ }
12105
+ }
12106
+
12042
12107
  class StreamingClientError extends Error {
12043
12108
  constructor(type, messageOrError, details) {
12044
12109
  let message;
@@ -12221,18 +12286,56 @@ function iceIsDifferent(sdp1, sdp2) {
12221
12286
  // return destination;
12222
12287
  // }
12223
12288
 
12224
- class AlertingLeaderExtension {
12289
+ class AlertingLeaderExtension extends EventEmitter {
12225
12290
  constructor(client, options) {
12226
12291
  var _a;
12292
+ super();
12227
12293
  this.client = client;
12294
+ this.leaderStatus = {};
12228
12295
  this.alertableInteractionTypes = (_a = options.alertableInteractionTypes) !== null && _a !== void 0 ? _a : [];
12229
12296
  }
12230
12297
  handleStanzaInstanceChange(stanzaInstance) {
12231
12298
  var _a, _b;
12232
12299
  this.connectionId = (_b = (_a = stanzaInstance.transport) === null || _a === void 0 ? void 0 : _a.stream) === null || _b === void 0 ? void 0 : _b.id;
12233
- if (this.alertableInteractionTypes.length !== 0) {
12234
- this.markAsAlertable();
12235
- }
12300
+ this.setupAlertingLeader();
12301
+ }
12302
+ setupAlertingLeader() {
12303
+ return __awaiter$4(this, void 0, void 0, function* () {
12304
+ if (this.alertableInteractionTypes.length !== 0) {
12305
+ try {
12306
+ yield this.subscribeToAlertingLeader();
12307
+ yield this.markAsAlertable();
12308
+ yield this.getAlertingLeader();
12309
+ }
12310
+ catch (err) {
12311
+ this.client.logger.warn('Failed to setup alerting leader; falling back to the default of acting as the alerting leader');
12312
+ // Fail 'open' so users don't miss calls
12313
+ this.leaderStatus = { voice: { alerting: true, configured: false } };
12314
+ this.emit('alertingLeaderChanged', this.leaderStatus);
12315
+ }
12316
+ }
12317
+ });
12318
+ }
12319
+ subscribeToAlertingLeader() {
12320
+ return __awaiter$4(this, void 0, void 0, function* () {
12321
+ const topic = `v2.users.${this.client.config.userId}.alertingleader`;
12322
+ this.client.on(`notify:${topic}`, (event) => {
12323
+ var _a, _b;
12324
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
12325
+ if ((_b = event.eventBody) === null || _b === void 0 ? void 0 : _b.connectionId) {
12326
+ // We should alert if our connection is the alerting leader connection
12327
+ const alerting = event.eventBody.connectionId === this.connectionId;
12328
+ const clientType = event.eventBody.clientType;
12329
+ let voice = { alerting, configured: true };
12330
+ if (clientType) {
12331
+ voice = Object.assign(Object.assign({}, voice), { clientType });
12332
+ }
12333
+ this.leaderStatus = { voice };
12334
+ this.emit('alertingLeaderChanged', this.leaderStatus);
12335
+ }
12336
+ });
12337
+ return this.client._notifications._subscribeInternal(topic);
12338
+ });
12236
12339
  }
12237
12340
  markAsAlertable() {
12238
12341
  return __awaiter$4(this, void 0, void 0, function* () {
@@ -12265,8 +12368,65 @@ class AlertingLeaderExtension {
12265
12368
  });
12266
12369
  });
12267
12370
  }
12371
+ getAlertingLeader() {
12372
+ return __awaiter$4(this, void 0, void 0, function* () {
12373
+ this.abortController = new AbortController();
12374
+ const leaderRequestOptions = {
12375
+ method: 'get',
12376
+ host: this.client.config.apiHost,
12377
+ authToken: this.client.config.authToken,
12378
+ logger: this.client.logger,
12379
+ signal: this.abortController.signal
12380
+ };
12381
+ try {
12382
+ const currentLeader = yield this.client.http.requestApi('users/alertingleader', leaderRequestOptions);
12383
+ // We should alert if our connection is the alerting leader connection
12384
+ const alerting = currentLeader.data.connectionId === this.connectionId;
12385
+ const clientType = currentLeader.data.clientType;
12386
+ let voice = { alerting, configured: true };
12387
+ if (clientType) {
12388
+ voice = Object.assign(Object.assign({}, voice), { clientType });
12389
+ }
12390
+ this.leaderStatus = { voice };
12391
+ this.emit('alertingLeaderChanged', this.leaderStatus);
12392
+ }
12393
+ catch (err) {
12394
+ if (axios.isCancel(err)) {
12395
+ return;
12396
+ }
12397
+ throw err;
12398
+ }
12399
+ });
12400
+ }
12401
+ claimAlertingLeader() {
12402
+ return __awaiter$4(this, void 0, void 0, function* () {
12403
+ if (this.alertableInteractionTypes.length === 0) {
12404
+ this.client.logger.info('This client is not configured for any alertable interactions and will not attempt to claim alerting leader');
12405
+ throw new StreamingClientError(StreamingClientErrorTypes.generic, 'Unable to claim alerting leader; this client is not configured for any alertable interactions');
12406
+ }
12407
+ const leaderRequestOptions = {
12408
+ method: 'put',
12409
+ host: this.client.config.apiHost,
12410
+ authToken: this.client.config.authToken,
12411
+ logger: this.client.logger,
12412
+ data: {
12413
+ connectionId: this.connectionId
12414
+ }
12415
+ };
12416
+ return this.client.http.requestApi('users/alertingleader', leaderRequestOptions)
12417
+ .catch((err) => {
12418
+ this.client.logger.warn('Unable to claim alerting leader; this client may not alert for incoming interactions');
12419
+ throw new StreamingClientError(StreamingClientErrorTypes.generic, 'Unable to claim alerting leader', err);
12420
+ });
12421
+ });
12422
+ }
12268
12423
  get expose() {
12269
- return {};
12424
+ return {
12425
+ on: this.on.bind(this),
12426
+ off: this.off.bind(this),
12427
+ claimAlertingLeader: this.claimAlertingLeader.bind(this),
12428
+ leaderStatus: this.leaderStatus
12429
+ };
12270
12430
  }
12271
12431
  }
12272
12432
 
@@ -35514,7 +35674,8 @@ class HttpClient {
35514
35674
  data: opts.data,
35515
35675
  responseType: opts.responseType,
35516
35676
  timeout: opts.requestTimeout || 30000,
35517
- headers
35677
+ headers,
35678
+ signal: opts.signal
35518
35679
  };
35519
35680
  // default to include auth header
35520
35681
  if (!opts.noAuthHeader) {
@@ -47331,7 +47492,7 @@ class Client extends EventEmitter {
47331
47492
  return Client.version;
47332
47493
  }
47333
47494
  static get version() {
47334
- return '19.6.0';
47495
+ return '19.6.1';
47335
47496
  }
47336
47497
  }
47337
47498