@azure/core-amqp 3.1.0-alpha.20220125.3 → 3.1.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Release History
2
2
 
3
- ## 3.1.0 (Unreleased)
3
+ ## 3.1.0 (2022-02-03)
4
4
 
5
5
  ### Features Added
6
6
 
package/dist/index.js CHANGED
@@ -2,15 +2,36 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
5
  var abortController = require('@azure/abort-controller');
8
6
  var rheaPromise = require('rhea-promise');
9
7
  var logger$1 = require('@azure/logger');
10
8
  var dns = require('dns');
11
9
  var os = require('os');
12
10
  var coreAuth = require('@azure/core-auth');
13
- var jssha = _interopDefault(require('jssha'));
11
+ var jssha = require('jssha');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n["default"] = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
34
+ var jssha__default = /*#__PURE__*/_interopDefaultLegacy(jssha);
14
35
 
15
36
  // Copyright (c) Microsoft Corporation.
16
37
  // Licensed under the MIT license.
@@ -363,12 +384,14 @@ function cleanupTaskDetails(taskDetails) {
363
384
  }
364
385
 
365
386
  // Copyright (c) Microsoft Corporation.
387
+ // Licensed under the MIT license.
388
+ var _a;
366
389
  /**
367
390
  * @internal
368
391
  *
369
392
  * A constant that indicates whether the environment is node.js or browser based.
370
393
  */
371
- const isNode = !!process && !!process.version && !!process.versions && !!process.versions.node;
394
+ const isNode = typeof process !== "undefined" && Boolean(process.version) && Boolean((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
372
395
  /**
373
396
  * Parses the connection string and returns an object of type T.
374
397
  *
@@ -489,6 +512,10 @@ var ConditionStatusMapper;
489
512
  ConditionStatusMapper[ConditionStatusMapper["amqp:unauthorized-access"] = 401] = "amqp:unauthorized-access";
490
513
  ConditionStatusMapper[ConditionStatusMapper["amqp:resource-limit-exceeded"] = 403] = "amqp:resource-limit-exceeded";
491
514
  })(ConditionStatusMapper || (ConditionStatusMapper = {}));
515
+ /**
516
+ * Maps the amqp error conditions to the Error names.
517
+ */
518
+ exports.ConditionErrorNameMapper = void 0;
492
519
  (function (ConditionErrorNameMapper) {
493
520
  /**
494
521
  * Error is thrown when the address is already in use.
@@ -690,6 +717,10 @@ var ConditionStatusMapper;
690
717
  */
691
718
  ConditionErrorNameMapper["system:error"] = "SystemError";
692
719
  })(exports.ConditionErrorNameMapper || (exports.ConditionErrorNameMapper = {}));
720
+ /**
721
+ * Maps the Error names to the amqp error conditions.
722
+ */
723
+ exports.ErrorNameConditionMapper = void 0;
693
724
  (function (ErrorNameConditionMapper) {
694
725
  /**
695
726
  * Error is thrown when the address is already in use.
@@ -960,6 +991,10 @@ const retryableErrors = [
960
991
  // Since reasons for such shortage can be transient such as for pending delivery of messages, this is treated as a retryable error.
961
992
  "InsufficientCreditError",
962
993
  ];
994
+ /**
995
+ * Maps some SystemErrors to amqp error conditions
996
+ */
997
+ exports.SystemErrorConditionMapper = void 0;
963
998
  (function (SystemErrorConditionMapper) {
964
999
  SystemErrorConditionMapper["ENOTFOUND"] = "amqp:not-found";
965
1000
  SystemErrorConditionMapper["EBUSY"] = "com.microsoft:server-busy";
@@ -1363,10 +1398,18 @@ function isDelivery(obj) {
1363
1398
  }
1364
1399
  return result;
1365
1400
  }
1401
+ /**
1402
+ * Describes the Retry Mode type
1403
+ */
1404
+ exports.RetryMode = void 0;
1366
1405
  (function (RetryMode) {
1367
1406
  RetryMode[RetryMode["Exponential"] = 0] = "Exponential";
1368
1407
  RetryMode[RetryMode["Fixed"] = 1] = "Fixed";
1369
1408
  })(exports.RetryMode || (exports.RetryMode = {}));
1409
+ /**
1410
+ * Describes the retry operation type.
1411
+ */
1412
+ exports.RetryOperationType = void 0;
1370
1413
  (function (RetryOperationType) {
1371
1414
  RetryOperationType["cbsAuth"] = "cbsAuth";
1372
1415
  RetryOperationType["connection"] = "connection";
@@ -1488,6 +1531,11 @@ async function retry(config) {
1488
1531
  }
1489
1532
 
1490
1533
  // Copyright (c) Microsoft Corporation.
1534
+ // Licensed under the MIT license.
1535
+ /**
1536
+ * Describes the type of supported tokens.
1537
+ */
1538
+ exports.TokenType = void 0;
1491
1539
  (function (TokenType) {
1492
1540
  /**
1493
1541
  * The "jwt" token type. Used with AADTokenCredential.
@@ -1964,7 +2012,7 @@ const AmqpMessageProperties = {
1964
2012
  * @internal
1965
2013
  */
1966
2014
  function getPlatformInfo() {
1967
- return `(${os.arch()}-${os.type()}-${os.release()})`;
2015
+ return `(${os__namespace.arch()}-${os__namespace.type()}-${os__namespace.release()})`;
1968
2016
  }
1969
2017
  /**
1970
2018
  * Returns information about Node.js this function is being run on.
@@ -1975,6 +2023,49 @@ function getFrameworkInfo() {
1975
2023
  }
1976
2024
 
1977
2025
  // Copyright (c) Microsoft Corporation.
2026
+ const maxListenerLimit = 1000;
2027
+ class CoreAmqpConnection extends rheaPromise.Connection {
2028
+ /**
2029
+ * Creates an amqp sender link. Max listener limit on the sender is set to 1000 because the
2030
+ * default value of 10 in NodeJS is too low.
2031
+ * @param options - Optional parameters to create a sender link.
2032
+ * @returns Promise<Sender>.
2033
+ */
2034
+ async createSender(options) {
2035
+ const sender = await super.createSender(options);
2036
+ sender.setMaxListeners(maxListenerLimit);
2037
+ return sender;
2038
+ }
2039
+ /**
2040
+ * Creates an awaitable amqp sender. Max listener limit on the sender is set to 1000 because the
2041
+ * default value of 10 in NodeJS is too low.
2042
+ * @param options - Optional parameters to create an awaitable sender link.
2043
+ * - If `onError` and `onSessionError` handlers are not provided then the `AwaitableSender` will
2044
+ * clear the timer and reject the Promise for all the entries of inflight send operation in its
2045
+ * `deliveryDispositionMap`.
2046
+ * - If the user is handling the reconnection of sender link or the underlying connection in it's
2047
+ * app, then the `onError` and `onSessionError` handlers must be provided by the user and (s)he
2048
+ * shall be responsible of clearing the `deliveryDispositionMap` of inflight `send()` operation.
2049
+ *
2050
+ * @returns Promise<AwaitableSender>.
2051
+ */
2052
+ async createAwaitableSender(options) {
2053
+ const sender = await super.createAwaitableSender(options);
2054
+ sender.setMaxListeners(maxListenerLimit);
2055
+ return sender;
2056
+ }
2057
+ /**
2058
+ * Creates an amqp receiver link. Max listener limit on the sender is set to 1000 because the
2059
+ * default value of 10 in NodeJS is too low.
2060
+ * @param options - Optional parameters to create a receiver link.
2061
+ * @returns Promise<Receiver>.
2062
+ */
2063
+ async createReceiver(options) {
2064
+ const receiver = await super.createReceiver(options);
2065
+ receiver.setMaxListeners(maxListenerLimit);
2066
+ return receiver;
2067
+ }
2068
+ }
1978
2069
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.
1979
2070
  const ConnectionContextBase = {
1980
2071
  /**
@@ -2025,7 +2116,7 @@ const ConnectionContextBase = {
2025
2116
  options: socketOptions,
2026
2117
  };
2027
2118
  }
2028
- const connection = new rheaPromise.Connection(connectionOptions);
2119
+ const connection = new CoreAmqpConnection(connectionOptions);
2029
2120
  const connectionLock = `${Constants.establishConnection}-${rheaPromise.generate_uuid()}`;
2030
2121
  const connectionContextBase = {
2031
2122
  wasConnectionCloseCalled: false,
@@ -2036,7 +2127,7 @@ const ConnectionContextBase = {
2036
2127
  cbsSession: new CbsClient(connection, connectionLock),
2037
2128
  config: parameters.config,
2038
2129
  refreshConnection() {
2039
- const newConnection = new rheaPromise.Connection(connectionOptions);
2130
+ const newConnection = new CoreAmqpConnection(connectionOptions);
2040
2131
  const newConnectionLock = `${Constants.establishConnection}-${rheaPromise.generate_uuid()}`;
2041
2132
  this.wasConnectionCloseCalled = false;
2042
2133
  this.connectionLock = newConnectionLock;
@@ -2144,7 +2235,7 @@ function createToken(keyName, key, expiry, audience) {
2144
2235
  audience = encodeURIComponent(audience);
2145
2236
  keyName = encodeURIComponent(keyName);
2146
2237
  const stringToSign = audience + "\n" + expiry;
2147
- const shaObj = new jssha("SHA-256", "TEXT");
2238
+ const shaObj = new jssha__default["default"]("SHA-256", "TEXT");
2148
2239
  shaObj.setHMACKey(key, "TEXT");
2149
2240
  shaObj.update(stringToSign);
2150
2241
  const sig = encodeURIComponent(shaObj.getHMAC("B64"));