@azure/core-amqp 4.4.1-alpha.20250822.4 → 4.4.1-alpha.20250825.2

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.
Files changed (34) hide show
  1. package/dist/browser/ConnectionContextBase.js +4 -3
  2. package/dist/browser/ConnectionContextBase.js.map +1 -1
  3. package/dist/browser/errors.js +7 -6
  4. package/dist/browser/errors.js.map +1 -1
  5. package/dist/browser/util/hmacSha256.common.js.map +1 -1
  6. package/dist/browser/util/utils.d.ts +6 -0
  7. package/dist/browser/util/utils.js +16 -2
  8. package/dist/browser/util/utils.js.map +1 -1
  9. package/dist/commonjs/ConnectionContextBase.js +4 -3
  10. package/dist/commonjs/ConnectionContextBase.js.map +1 -1
  11. package/dist/commonjs/errors.js +6 -5
  12. package/dist/commonjs/errors.js.map +1 -1
  13. package/dist/commonjs/tsdoc-metadata.json +1 -1
  14. package/dist/commonjs/util/hmacSha256.common.js.map +1 -1
  15. package/dist/commonjs/util/utils.d.ts +6 -0
  16. package/dist/commonjs/util/utils.js +17 -2
  17. package/dist/commonjs/util/utils.js.map +1 -1
  18. package/dist/esm/ConnectionContextBase.js +4 -3
  19. package/dist/esm/ConnectionContextBase.js.map +1 -1
  20. package/dist/esm/errors.js +7 -6
  21. package/dist/esm/errors.js.map +1 -1
  22. package/dist/esm/util/hmacSha256.common.js.map +1 -1
  23. package/dist/esm/util/utils.d.ts +6 -0
  24. package/dist/esm/util/utils.js +16 -2
  25. package/dist/esm/util/utils.js.map +1 -1
  26. package/dist/react-native/ConnectionContextBase.js +4 -3
  27. package/dist/react-native/ConnectionContextBase.js.map +1 -1
  28. package/dist/react-native/errors.js +7 -6
  29. package/dist/react-native/errors.js.map +1 -1
  30. package/dist/react-native/util/hmacSha256.common.js.map +1 -1
  31. package/dist/react-native/util/utils.d.ts +6 -0
  32. package/dist/react-native/util/utils.js +16 -2
  33. package/dist/react-native/util/utils.js.map +1 -1
  34. package/package.json +4 -5
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
  import { Connection, generate_uuid, } from "rhea-promise";
4
4
  import { getFrameworkInfo, getPlatformInfo } from "./util/runtimeInfo.js";
5
+ import { getGlobalProperty } from "./util/utils.js";
5
6
  import { CbsClient } from "./cbs.js";
6
7
  import { ConnectionConfig } from "./connectionConfig/connectionConfig.js";
7
8
  import { Constants } from "./util/constants.js";
@@ -84,9 +85,9 @@ export const ConnectionContextBase = {
84
85
  ? parameters.operationTimeoutInMs / 1000
85
86
  : undefined,
86
87
  };
87
- if (parameters.config.webSocket ||
88
- (!isNodeLike && typeof self !== "undefined" && self.WebSocket)) {
89
- const socket = parameters.config.webSocket || self.WebSocket;
88
+ const globalWebSocket = (!isNodeLike && getGlobalProperty("WebSocket")) || undefined;
89
+ if (parameters.config.webSocket || globalWebSocket) {
90
+ const socket = parameters.config.webSocket || globalWebSocket;
90
91
  const host = parameters.config.host;
91
92
  const endpoint = parameters.config.webSocketEndpointPath || "";
92
93
  const socketOptions = parameters.config.webSocketConstructorOptions || {};
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectionContextBase.js","sourceRoot":"","sources":["../../src/ConnectionContextBase.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,UAAU,EAKV,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA8F9C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,kBAAmB,SAAQ,UAAU;IACzC;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,OAA6B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AiB,CAAC,CAAC;YACpE,CAAC;SACF,CAAC;QAEF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AwaitableSender, Receiver, Sender } from \"rhea-promise\";\nimport {\n Connection,\n type ConnectionOptions,\n type CreateAwaitableSenderOptions,\n type CreateReceiverOptions,\n type CreateSenderOptions,\n generate_uuid,\n} from \"rhea-promise\";\nimport { getFrameworkInfo, getPlatformInfo } from \"./util/runtimeInfo.js\";\nimport { CbsClient } from \"./cbs.js\";\nimport { ConnectionConfig } from \"./connectionConfig/connectionConfig.js\";\nimport { Constants } from \"./util/constants.js\";\nimport { isNodeLike } from \"@azure/core-util\";\n\n/**\n * Provides contextual information like the underlying amqp connection, cbs session, tokenProvider,\n * Connection config, data transformer, etc.\n */\nexport interface ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: ConnectionConfig;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for establishing an amqp connection per client if one does not exist.\n */\n connectionLock: string;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for negotiating cbs claim by an entity on that connection.\n */\n negotiateClaimLock: string;\n /**\n * The underlying AMQP connection.\n */\n connection: Connection;\n /**\n * The amqp connection id that uniquely identifies the\n * connection within a process.\n */\n connectionId: string;\n /**\n * Indicates whether the close() method was\n * called on the connection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A reference to the cbs session ($cbs endpoint) on the\n * underlying AMQP connection for the EventHub Client.\n */\n cbsSession: CbsClient;\n /**\n * Updates the context to use a new underlying AMQP connection and new cbs session.\n */\n refreshConnection: () => void;\n}\n\n/**\n * Defines the properties that need to be set while establishing the AMQP connection.\n */\nexport interface ConnectionProperties {\n /**\n * The name of the product that will be populated as the AMQP\n * connection property. Example: \"MSJSClient\".\n */\n product: string;\n /**\n * The version of the package/sdk that is making the AMQP connection.\n */\n version: string;\n /**\n * The userAgent that needs to be set as the AMQP connection\n * property. Example: `\"/js-service-bus\"` or `\"/js-event-hubs,/js-event-processor-host=1.0.0\"`.\n */\n userAgent: string;\n}\n\n/**\n * Describes the parameters that can be provided to create the base connection context.\n */\nexport interface CreateConnectionContextBaseParameters {\n /**\n * The connection config that is created by parsing the\n * connection string.\n */\n config: ConnectionConfig;\n /**\n * Properties to be provided while creating\n * the AMQP connection.\n */\n connectionProperties: ConnectionProperties;\n /**\n * Determines whether entity path should be a part of\n * the connection config. If `true` it must be present, `false` otherwise. Default value false.\n */\n isEntityPathRequired?: boolean;\n /**\n * The duration in which the promise should\n * complete (resolve/reject). If it is not completed, then the Promise will be rejected after\n * timeout occurs. Default: `60000 milliseconds`.\n */\n operationTimeoutInMs?: number;\n}\n\nconst maxListenerLimit = 1000;\n\nclass CoreAmqpConnection extends Connection {\n /**\n * Creates an amqp sender link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a sender link.\n * @returns Promise<Sender>.\n */\n async createSender(options?: CreateSenderOptions): Promise<Sender> {\n const sender = await super.createSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an awaitable amqp sender. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create an awaitable sender link.\n * - If `onError` and `onSessionError` handlers are not provided then the `AwaitableSender` will\n * clear the timer and reject the Promise for all the entries of inflight send operation in its\n * `deliveryDispositionMap`.\n * - If the user is handling the reconnection of sender link or the underlying connection in it's\n * app, then the `onError` and `onSessionError` handlers must be provided by the user and (s)he\n * shall be responsible of clearing the `deliveryDispositionMap` of inflight `send()` operation.\n *\n * @returns Promise<AwaitableSender>.\n */\n async createAwaitableSender(options?: CreateAwaitableSenderOptions): Promise<AwaitableSender> {\n const sender = await super.createAwaitableSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an amqp receiver link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a receiver link.\n * @returns Promise<Receiver>.\n */\n async createReceiver(options?: CreateReceiverOptions): Promise<Receiver> {\n const receiver = await super.createReceiver(options);\n receiver.setMaxListeners(maxListenerLimit);\n return receiver;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionContextBase = {\n /**\n * Creates the base connection context.\n * @param parameters - Parameters to be provided to create\n * the base connection context.\n */\n create(parameters: CreateConnectionContextBaseParameters): ConnectionContextBase {\n ConnectionConfig.validate(parameters.config, {\n isEntityPathRequired: parameters.isEntityPathRequired || false,\n });\n const userAgent = parameters.connectionProperties.userAgent;\n if (userAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${userAgent} with length: ${userAgent.length}`,\n );\n }\n\n const connectionOptions: ConnectionOptions = {\n transport: (parameters.config.useDevelopmentEmulator ? Constants.TCP : Constants.TLS) as any,\n host: parameters.config.host,\n hostname: parameters.config.amqpHostname ?? parameters.config.host,\n username: parameters.config.sharedAccessKeyName,\n port: parameters.config.port ?? (parameters.config.useDevelopmentEmulator ? 5672 : 5671),\n reconnect: false,\n properties: {\n product: parameters.connectionProperties.product,\n version: parameters.connectionProperties.version,\n \"user-agent\": userAgent,\n platform: getPlatformInfo(),\n framework: getFrameworkInfo(),\n },\n idle_time_out: Constants.defaultConnectionIdleTimeoutInMs,\n operationTimeoutInSeconds: parameters.operationTimeoutInMs\n ? parameters.operationTimeoutInMs / 1000\n : undefined,\n };\n\n if (\n parameters.config.webSocket ||\n (!isNodeLike && typeof self !== \"undefined\" && (self as any).WebSocket)\n ) {\n const socket = parameters.config.webSocket || (self as any).WebSocket;\n const host = parameters.config.host;\n const endpoint = parameters.config.webSocketEndpointPath || \"\";\n const socketOptions = parameters.config.webSocketConstructorOptions || {};\n const port = parameters.config.port ?? 443;\n\n connectionOptions.webSocketOptions = {\n webSocket: socket,\n url: `wss://${host}:${port}/${endpoint}`,\n protocol: [\"AMQPWSB10\"],\n options: socketOptions,\n };\n }\n\n const connection = new CoreAmqpConnection(connectionOptions);\n const connectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n const connectionContextBase: ConnectionContextBase = {\n wasConnectionCloseCalled: false,\n connectionLock: connectionLock,\n negotiateClaimLock: `${Constants.negotiateClaim}-${generate_uuid()}`,\n connection: connection,\n connectionId: connection.id,\n cbsSession: new CbsClient(connection, connectionLock),\n config: parameters.config,\n refreshConnection() {\n const newConnection = new CoreAmqpConnection(connectionOptions);\n const newConnectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n this.wasConnectionCloseCalled = false;\n this.connectionLock = newConnectionLock;\n this.negotiateClaimLock = `${Constants.negotiateClaim} - ${generate_uuid()}`;\n this.connection = newConnection;\n this.connectionId = newConnection.id;\n this.cbsSession = new CbsClient(newConnection, newConnectionLock);\n },\n };\n\n return connectionContextBase;\n },\n};\n"]}
1
+ {"version":3,"file":"ConnectionContextBase.js","sourceRoot":"","sources":["../../src/ConnectionContextBase.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,UAAU,EAKV,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AA8F9C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,kBAAmB,SAAQ,UAAU;IACzC;;;;;OAKG;IACH,KAAK,CA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AAG,IAAI,SAAS,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;YACpE,CAAC;SACF,CAAC;QAEF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AwaitableSender, Receiver, Sender } from \"rhea-promise\";\nimport {\n Connection,\n type ConnectionOptions,\n type CreateAwaitableSenderOptions,\n type CreateReceiverOptions,\n type CreateSenderOptions,\n generate_uuid,\n} from \"rhea-promise\";\nimport { getFrameworkInfo, getPlatformInfo } from \"./util/runtimeInfo.js\";\nimport { getGlobalProperty } from \"./util/utils.js\";\nimport { CbsClient } from \"./cbs.js\";\nimport { ConnectionConfig } from \"./connectionConfig/connectionConfig.js\";\nimport { Constants } from \"./util/constants.js\";\nimport { isNodeLike } from \"@azure/core-util\";\n\n/**\n * Provides contextual information like the underlying amqp connection, cbs session, tokenProvider,\n * Connection config, data transformer, etc.\n */\nexport interface ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: ConnectionConfig;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for establishing an amqp connection per client if one does not exist.\n */\n connectionLock: string;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for negotiating cbs claim by an entity on that connection.\n */\n negotiateClaimLock: string;\n /**\n * The underlying AMQP connection.\n */\n connection: Connection;\n /**\n * The amqp connection id that uniquely identifies the\n * connection within a process.\n */\n connectionId: string;\n /**\n * Indicates whether the close() method was\n * called on the connection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A reference to the cbs session ($cbs endpoint) on the\n * underlying AMQP connection for the EventHub Client.\n */\n cbsSession: CbsClient;\n /**\n * Updates the context to use a new underlying AMQP connection and new cbs session.\n */\n refreshConnection: () => void;\n}\n\n/**\n * Defines the properties that need to be set while establishing the AMQP connection.\n */\nexport interface ConnectionProperties {\n /**\n * The name of the product that will be populated as the AMQP\n * connection property. Example: \"MSJSClient\".\n */\n product: string;\n /**\n * The version of the package/sdk that is making the AMQP connection.\n */\n version: string;\n /**\n * The userAgent that needs to be set as the AMQP connection\n * property. Example: `\"/js-service-bus\"` or `\"/js-event-hubs,/js-event-processor-host=1.0.0\"`.\n */\n userAgent: string;\n}\n\n/**\n * Describes the parameters that can be provided to create the base connection context.\n */\nexport interface CreateConnectionContextBaseParameters {\n /**\n * The connection config that is created by parsing the\n * connection string.\n */\n config: ConnectionConfig;\n /**\n * Properties to be provided while creating\n * the AMQP connection.\n */\n connectionProperties: ConnectionProperties;\n /**\n * Determines whether entity path should be a part of\n * the connection config. If `true` it must be present, `false` otherwise. Default value false.\n */\n isEntityPathRequired?: boolean;\n /**\n * The duration in which the promise should\n * complete (resolve/reject). If it is not completed, then the Promise will be rejected after\n * timeout occurs. Default: `60000 milliseconds`.\n */\n operationTimeoutInMs?: number;\n}\n\nconst maxListenerLimit = 1000;\n\nclass CoreAmqpConnection extends Connection {\n /**\n * Creates an amqp sender link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a sender link.\n * @returns Promise<Sender>.\n */\n async createSender(options?: CreateSenderOptions): Promise<Sender> {\n const sender = await super.createSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an awaitable amqp sender. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create an awaitable sender link.\n * - If `onError` and `onSessionError` handlers are not provided then the `AwaitableSender` will\n * clear the timer and reject the Promise for all the entries of inflight send operation in its\n * `deliveryDispositionMap`.\n * - If the user is handling the reconnection of sender link or the underlying connection in it's\n * app, then the `onError` and `onSessionError` handlers must be provided by the user and (s)he\n * shall be responsible of clearing the `deliveryDispositionMap` of inflight `send()` operation.\n *\n * @returns Promise<AwaitableSender>.\n */\n async createAwaitableSender(options?: CreateAwaitableSenderOptions): Promise<AwaitableSender> {\n const sender = await super.createAwaitableSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an amqp receiver link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a receiver link.\n * @returns Promise<Receiver>.\n */\n async createReceiver(options?: CreateReceiverOptions): Promise<Receiver> {\n const receiver = await super.createReceiver(options);\n receiver.setMaxListeners(maxListenerLimit);\n return receiver;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionContextBase = {\n /**\n * Creates the base connection context.\n * @param parameters - Parameters to be provided to create\n * the base connection context.\n */\n create(parameters: CreateConnectionContextBaseParameters): ConnectionContextBase {\n ConnectionConfig.validate(parameters.config, {\n isEntityPathRequired: parameters.isEntityPathRequired || false,\n });\n const userAgent = parameters.connectionProperties.userAgent;\n if (userAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${userAgent} with length: ${userAgent.length}`,\n );\n }\n\n const connectionOptions: ConnectionOptions = {\n transport: (parameters.config.useDevelopmentEmulator ? Constants.TCP : Constants.TLS) as any,\n host: parameters.config.host,\n hostname: parameters.config.amqpHostname ?? parameters.config.host,\n username: parameters.config.sharedAccessKeyName,\n port: parameters.config.port ?? (parameters.config.useDevelopmentEmulator ? 5672 : 5671),\n reconnect: false,\n properties: {\n product: parameters.connectionProperties.product,\n version: parameters.connectionProperties.version,\n \"user-agent\": userAgent,\n platform: getPlatformInfo(),\n framework: getFrameworkInfo(),\n },\n idle_time_out: Constants.defaultConnectionIdleTimeoutInMs,\n operationTimeoutInSeconds: parameters.operationTimeoutInMs\n ? parameters.operationTimeoutInMs / 1000\n : undefined,\n };\n\n const globalWebSocket = (!isNodeLike && getGlobalProperty(\"WebSocket\")) || undefined;\n if (parameters.config.webSocket || globalWebSocket) {\n const socket = parameters.config.webSocket || globalWebSocket;\n const host = parameters.config.host;\n const endpoint = parameters.config.webSocketEndpointPath || \"\";\n const socketOptions = parameters.config.webSocketConstructorOptions || {};\n const port = parameters.config.port ?? 443;\n\n connectionOptions.webSocketOptions = {\n webSocket: socket,\n url: `wss://${host}:${port}/${endpoint}`,\n protocol: [\"AMQPWSB10\"],\n options: socketOptions,\n };\n }\n\n const connection = new CoreAmqpConnection(connectionOptions);\n const connectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n const connectionContextBase: ConnectionContextBase = {\n wasConnectionCloseCalled: false,\n connectionLock: connectionLock,\n negotiateClaimLock: `${Constants.negotiateClaim}-${generate_uuid()}`,\n connection: connection,\n connectionId: connection.id,\n cbsSession: new CbsClient(connection, connectionLock),\n config: parameters.config,\n refreshConnection() {\n const newConnection = new CoreAmqpConnection(connectionOptions);\n const newConnectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n this.wasConnectionCloseCalled = false;\n this.connectionLock = newConnectionLock;\n this.negotiateClaimLock = `${Constants.negotiateClaim} - ${generate_uuid()}`;\n this.connection = newConnection;\n this.connectionId = newConnection.id;\n this.cbsSession = new CbsClient(newConnection, newConnectionLock);\n },\n };\n\n return connectionContextBase;\n },\n};\n"]}
@@ -3,7 +3,7 @@
3
3
  /* eslint-disable eqeqeq */
4
4
  import { isAmqpError as rheaIsAmqpError } from "rhea-promise";
5
5
  import { isDefined, isError, isNodeLike, isObjectWithProperties } from "@azure/core-util";
6
- import { isNumber, isString } from "./util/utils.js";
6
+ import { getGlobalProperty, isNumber, isString } from "./util/utils.js";
7
7
  /**
8
8
  * Maps the conditions to the numeric AMQP Response status codes.
9
9
  * @internal
@@ -594,11 +594,12 @@ export function isSystemError(err) {
594
594
  */
595
595
  function isBrowserWebsocketError(err) {
596
596
  let result = false;
597
- if (!isNodeLike &&
598
- self &&
599
- err.type === "error" &&
600
- err.target instanceof self.WebSocket) {
601
- result = true;
597
+ if (!isNodeLike && globalThis && err.type === "error") {
598
+ const wsKey = "WebSocket";
599
+ const WS = getGlobalProperty(wsKey);
600
+ if (WS && err.target instanceof WS) {
601
+ result = true;
602
+ }
602
603
  }
603
604
  return result;
604
605
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,2BAA2B;AAG3B,OAAO,EAA0B,WAAW,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAN,IAAY,qBAqBX;AArBD,WAAY,qBAAqB;IAC/B,qGAA+D,CAAA;IAC/D,uFAAkD,CAAA;IAClD,mGAA8D,CAAA;IAC9D,iIAAuE,CAAA;IACvE,yHAA+D,CAAA;IAC/D,yHAA+D,CAAA;IAC/D,uIAAqF,CAAA;IACrF,yHAAoE,CAAA;IACpE,6GAAuE,CAAA;IACvE,mHAAkE,CAAA;IAClE,iIAAyE,CAAA;IACzE,qHAA6D,CAAA;IAC7D,uIAAsE,CAAA;IACtE,6HAAiE,CAAA;IACjE,qHAAmE,CAAA;IACnE,yHAAuE,CAAA;IACvE,2FAAgD,CAAA;IAChD,2FAAsD,CAAA;IACtD,2GAAgE,CAAA;IAChE,mHAAiE,CAAA;AACnE,CAAC,EArBW,qBAAqB,KAArB,qBAAqB,QAqBhC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,wBA+MX;AA/MD,WAAY,wBAAwB;IAClC;;OAEG;IACH,6FAAmE,CAAA;IACnE;;OAEG;IACH,gFAAsD,CAAA;IACtD;;OAEG;IACH,kGAAwE,CAAA;IACxE;;;OAGG;IACH,wFAA8D,CAAA;IAC9D;;OAEG;IACH,qFAA2D,CAAA;IAC3D;;OAEG;IACH,qGAA2E,CAAA;IAC3E;;OAEG;IACH,0FAAgE,CAAA;IAChE;;O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ACzB,IAAI,KAAK,CAAC,IAAI,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC7D,YAAY;YACZ,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC;QAC1B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,KAAU;IAC7B,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n/* eslint-disable eqeqeq */\n\nimport type { AmqpError } from \"rhea-promise\";\nimport { AmqpResponseStatusCode, isAmqpError as rheaIsAmqpError } from \"rhea-promise\";\nimport { isDefined, isError, isNodeLike, isObjectWithProperties } from \"@azure/core-util\";\nimport { isNumber, isString } from \"./util/utils.js\";\n\n/**\n * Maps the conditions to the numeric AMQP Response status codes.\n * @internal\n */\nexport enum ConditionStatusMapper {\n \"com.microsoft:timeout\" = AmqpResponseStatusCode.RequestTimeout,\n \"amqp:not-found\" = AmqpResponseStatusCode.NotFound,\n \"amqp:not-implemented\" = AmqpResponseStatusCode.NotImplemented,\n \"com.microsoft:entity-already-exists\" = AmqpResponseStatusCode.Conflict,\n \"com.microsoft:message-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:session-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:no-matching-subscription\" = AmqpResponseStatusCode.InternalServerError,\n \"amqp:link:message-size-exceeded\" = AmqpResponseStatusCode.Forbidden,\n \"com.microsoft:server-busy\" = AmqpResponseStatusCode.ServiceUnavailable,\n \"com.microsoft:argument-error\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:argument-out-of-range\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:store-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:session-cannot-be-locked\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:partition-not-owned\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:entity-disabled\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:publisher-revoked\" = AmqpResponseStatusCode.Unauthorized,\n \"amqp:link:stolen\" = AmqpResponseStatusCode.Gone,\n \"amqp:not-allowed\" = AmqpResponseStatusCode.BadRequest,\n \"amqp:unauthorized-access\" = AmqpResponseStatusCode.Unauthorized,\n \"amqp:resource-limit-exceeded\" = AmqpResponseStatusCode.Forbidden,\n}\n\n/**\n * Maps the amqp error conditions to the Error names.\n */\nexport enum ConditionErrorNameMapper {\n /**\n * Error is thrown when the address is already in use.\n */\n \"com.microsoft:address-already-in-use\" = \"AddressAlreadyInUseError\",\n /**\n * Error is thrown when the store lock is lost.\n */\n \"com.microsoft:store-lock-lost\" = \"StoreLockLostError\",\n /**\n * Error is thrown when a matching subscription is not found.\n */\n \"com.microsoft:no-matching-subscription\" = \"NoMatchingSubscriptionError\",\n /**\n * Error is thrown when an attempt is made to access a partition that is not owned by the\n * requesting entity.\n */\n \"com.microsoft:partition-not-owned\" = \"PartitionNotOwnedError\",\n /**\n * Error is thrown when access to publisher has been revoked.\n */\n \"com.microsoft:publisher-revoked\" = \"PublisherRevokedError\",\n /**\n * Error is thrown when an attempt is made to create an entity that already exists.\n */\n \"com.microsoft:entity-already-exists\" = \"MessagingEntityAlreadyExistsError\",\n /**\n * Error is thrown when trying to access/connect to a disabled messaging entity.\n */\n \"com.microsoft:entity-disabled\" = \"MessagingEntityDisabledError\",\n /**\n * Error is thrown when the lock on the message is lost.\n */\n \"com.microsoft:message-lock-lost\" = \"MessageLockLostError\",\n /**\n * Error is thrown when the lock on the Azure ServiceBus session is lost.\n */\n \"com.microsoft:session-lock-lost\" = \"SessionLockLostError\",\n /**\n * Error is thrown when the Azure ServiceBus session cannot be locked.\n */\n \"com.microsoft:session-cannot-be-locked\" = \"SessionCannotBeLockedError\",\n /**\n * Error is thrown when an internal server error occurred. You may have found a bug?\n */\n \"amqp:internal-error\" = \"InternalServerError\", // Retryable\n /**\n * Error for signaling general communication errors related to messaging operations.\n */\n \"amqp:not-found\" = \"ServiceCommunicationError\",\n /**\n * Error is thrown when the message is not found.\n */\n \"com.microsoft:message-not-found\" = \"MessageNotFoundError\",\n /**\n * Error is thrown when relay is not found.\n */\n \"com.microsoft:relay-not-found\" = \"RelayNotFoundError\",\n /**\n * Error is thrown when a feature is not implemented yet but the placeholder is present.\n */\n \"amqp:not-implemented\" = \"NotImplementedError\",\n /**\n * Error is thrown when an operation is attempted but is not allowed.\n */\n \"amqp:not-allowed\" = \"InvalidOperationError\",\n /**\n * Error is thrown the the Azure EventHub/ServiceBus quota has been exceeded.\n * Quotas are reset periodically, this operation will have to wait until then.\n * The messaging entity has reached its maximum allowable size.\n * This can happen if the maximum number of receivers (which is 5) has already\n * been opened on a per-consumer group level.\n */\n \"amqp:resource-limit-exceeded\" = \"QuotaExceededError\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n \"amqp:unauthorized-access\" = \"UnauthorizedError\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n \"com.microsoft:auth-failed\" = \"UnauthorizedError\",\n /**\n * Error is thrown when the service is unavailable. The operation should be retried.\n */\n \"com.microsoft:timeout\" = \"ServiceUnavailableError\", // Retryable\n /**\n * Error is thrown when no new messages are received for the specified time.\n */\n \"com.microsoft:message-wait-timeout\" = \"MessageWaitTimeout\",\n /**\n * Error is thrown when an argument has a value that is out of the admissible range.\n */\n \"com.microsoft:argument-out-of-range\" = \"ArgumentOutOfRangeError\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n \"amqp:precondition-failed\" = \"PreconditionFailedError\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n \"com.microsoft:precondition-failed\" = \"PreconditionFailedError\",\n /**\n * Error is thrown when data could not be decoded.\n */\n \"amqp:decode-error\" = \"DecodeError\",\n /**\n * Error is thrown when an invalid field was passed in a frame body, and the operation could not proceed.\n */\n \"amqp:invalid-field\" = \"InvalidFieldError\",\n /**\n * Error is thrown when the client attempted to work with a server entity to which it\n * has no access because another client is working with it.\n */\n \"amqp:resource-locked\" = \"ResourceLockedError\",\n /**\n * Error is thrown when a server entity the client is working with has been deleted.\n */\n \"amqp:resource-deleted\" = \"ResourceDeletedError\",\n /**\n * Error is thrown when the peer sent a frame that is not permitted in the current state.\n */\n \"amqp:illegal-state\" = \"IllegalStateError\",\n /**\n * Error is thrown when the peer cannot send a frame because the smallest encoding of\n * the performative with the currently valid values would be too large to fit within\n * a frame of the agreed maximum frame size.\n */\n \"amqp:frame-size-too-small\" = \"FrameSizeTooSmallError\",\n /**\n * Error is thrown when an operator intervened to detach for some reason.\n */\n \"amqp:link:detach-forced\" = \"DetachForcedError\", // Retryable\n /**\n * Error is thrown when the peer sent more message transfers than currently allowed on the link.\n */\n \"amqp:link:transfer-limit-exceeded\" = \"TransferLimitExceededError\", // Retryable\n /**\n * Error is thrown when the message sent is too large: the maximum size is 256Kb.\n */\n \"amqp:link:message-size-exceeded\" = \"MessageTooLargeError\",\n /**\n * Error is thrown when the address provided cannot be resolved to a terminus at the current container.\n */\n \"amqp:link:redirect\" = \"LinkRedirectError\",\n /**\n * Error is thrown when two or more instances connect to the same partition\n * with different epoch values.\n */\n \"amqp:link:stolen\" = \"ReceiverDisconnectedError\",\n /**\n * Error is thrown when the peer violated incoming window for the session.\n */\n \"amqp:session:window-violation\" = \"SessionWindowViolationError\",\n /**\n * Error is thrown when input was received for a link that was detached with an error.\n */\n \"amqp:session:errant-link\" = \"ErrantLinkError\",\n /**\n * Error is thrown when an attach was received using a handle that is already in use for an attached link.\n */\n \"amqp:session:handle-in-use\" = \"HandleInUseError\",\n /**\n * Error is thrown when a frame (other than attach) was received referencing a handle which is not\n * currently in use of an attached link.\n */\n \"amqp:session:unattached-handle\" = \"UnattachedHandleError\",\n /**\n * Error is thrown when an operator intervened to close the connection for some reason.\n */\n \"amqp:connection:forced\" = \"ConnectionForcedError\", // Retryable\n /**\n * Error is thrown when a valid frame header cannot be formed from the incoming byte stream.\n */\n \"amqp:connection:framing-error\" = \"FramingError\",\n /**\n * Error is thrown when the container is no longer available on the current connection.\n */\n \"amqp:connection:redirect\" = \"ConnectionRedirectError\",\n /**\n * Error is thrown when the server is busy. Callers should wait a while and retry the operation.\n */\n \"com.microsoft:server-busy\" = \"ServerBusyError\", // Retryable\n /**\n * Error is thrown when an incorrect argument was received.\n */\n \"com.microsoft:argument-error\" = \"ArgumentError\",\n /**\n * Error is thrown when server cancels the operation due to an internal issue.\n */\n \"com.microsoft:operation-cancelled\" = \"OperationCancelledError\", // Retryable\n /**\n * Error is thrown when the client sender does not have enough link credits to send the message.\n */\n \"client.sender:not-enough-link-credit\" = \"SenderBusyError\", // Retryable\n /**\n * Error is thrown when the client sender's link isn't ready\n */\n \"client.sender:link-not-ready\" = \"SenderNotReadyError\", // Retryable\n\n /**\n * Error is thrown when a low level system error is thrown by node.js.\n * {@link https://nodejs.org/dist/latest-v8.x/docs/api/all.html#errors_class_system_error}\n */\n \"system:error\" = \"SystemError\",\n}\n\n/**\n * Maps the Error names to the amqp error conditions.\n */\nexport enum ErrorNameConditionMapper {\n /**\n * Error is thrown when the address is already in use.\n */\n AddressAlreadyInUseError = \"com.microsoft:address-already-in-use\",\n /**\n * Error is thrown when the store lock is lost.\n */\n StoreLockLostError = \"com.microsoft:store-lock-lost\",\n /**\n * Error is thrown when a matching subscription is not found.\n */\n NoMatchingSubscriptionError = \"com.microsoft:no-matching-subscription\",\n /**\n * Error is thrown when an attempt is made to access a partition that is not owned by the\n * requesting entity.\n */\n PartitionNotOwnedError = \"com.microsoft:partition-not-owned\",\n /**\n * Error is thrown when access to publisher has been revoked.\n */\n PublisherRevokedError = \"com.microsoft:publisher-revoked\",\n /**\n * Error is thrown when an attempt is made to create an entity that already exists.\n */\n MessagingEntityAlreadyExistsError = \"com.microsoft:entity-already-exists\",\n /**\n * Error is thrown when trying to access/connect to a disabled messaging entity.\n */\n MessagingEntityDisabledError = \"com.microsoft:entity-disabled\",\n /**\n * Error is thrown when the lock on the message is lost.\n */\n MessageLockLostError = \"com.microsoft:message-lock-lost\",\n /**\n * Error is thrown when the lock on the Azure ServiceBus session is lost.\n */\n SessionLockLostError = \"com.microsoft:session-lock-lost\",\n /**\n * Error is thrown when the Azure ServiceBus session cannot be locked.\n */\n SessionCannotBeLockedError = \"com.microsoft:session-cannot-be-locked\",\n /**\n * Error is thrown when an internal server error occurred. You may have found a bug?\n */\n InternalServerError = \"amqp:internal-error\", // Retryable\n /**\n * Error for signaling general communication errors related to messaging operations.\n */\n ServiceCommunicationError = \"amqp:not-found\",\n /**\n * Error is thrown when message is not found.\n */\n MessageNotFoundError = \"com.microsoft:message-not-found\",\n /**\n * Error is thrown when relay is not found.\n */\n RelayNotFoundError = \"com.microsoft:relay-not-found\",\n /**\n * Error is thrown when a feature is not implemented yet but the placeholder is present.\n */\n NotImplementedError = \"amqp:not-implemented\",\n /**\n * Error is thrown when an operation is attempted but is not allowed.\n */\n InvalidOperationError = \"amqp:not-allowed\",\n /**\n * Error is thrown the the Azure EventHub/ServiceBus quota has been exceeded.\n * Quotas are reset periodically, this operation will have to wait until then.\n * The messaging entity has reached its maximum allowable size.\n * This can happen if the maximum number of receivers (which is 5) has already\n * been opened on a per-consumer group level.\n */\n QuotaExceededError = \"amqp:resource-limit-exceeded\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n UnauthorizedError = \"amqp:unauthorized-access\",\n /**\n * Error is thrown when the service is unavailable. The operation should be retried.\n */\n ServiceUnavailableError = \"com.microsoft:timeout\", // Retryable\n /**\n * Error is thrown when no new messages are received for the specified time.\n */\n MessageWaitTimeout = \"com.microsoft:message-wait-timeout\",\n /**\n * Error is thrown when an argument has a value that is out of the admissible range.\n */\n ArgumentOutOfRangeError = \"com.microsoft:argument-out-of-range\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n PreconditionFailedError = \"amqp:precondition-failed\",\n /**\n * Error is thrown when data could not be decoded.\n */\n DecodeError = \"amqp:decode-error\",\n /**\n * Error is thrown when an invalid field was passed in a frame body, and the operation could not proceed.\n */\n InvalidFieldError = \"amqp:invalid-field\",\n /**\n * Error is thrown when the client attempted to work with a server entity to which it\n * has no access because another client is working with it.\n */\n ResourceLockedError = \"amqp:resource-locked\",\n /**\n * Error is thrown when a server entity the client is working with has been deleted.\n */\n ResourceDeletedError = \"amqp:resource-deleted\",\n /**\n * Error is thrown when the peer sent a frame that is not permitted in the current state.\n */\n IllegalStateError = \"amqp:illegal-state\",\n /**\n * Error is thrown when the peer cannot send a frame because the smallest encoding of\n * the performative with the currently valid values would be too large to fit within\n * a frame of the agreed maximum frame size.\n */\n FrameSizeTooSmallError = \"amqp:frame-size-too-small\",\n /**\n * Error is thrown when an operator intervened to detach for some reason.\n */\n DetachForcedError = \"amqp:link:detach-forced\", // Retryable\n /**\n * Error is thrown when the peer sent more message transfers than currently allowed on the link.\n */\n TransferLimitExceededError = \"amqp:link:transfer-limit-exceeded\", // Retryable\n /**\n * Error is thrown when the message sent is too large: the maximum size is 256Kb.\n */\n MessageTooLargeError = \"amqp:link:message-size-exceeded\",\n /**\n * Error is thrown when the address provided cannot be resolved to a terminus at the current container.\n */\n LinkRedirectError = \"amqp:link:redirect\",\n /**\n * Error is thrown when two or more instances connect to the same partition\n * with different epoch values.\n */\n ReceiverDisconnectedError = \"amqp:link:stolen\",\n /**\n * Error is thrown when the peer violated incoming window for the session.\n */\n SessionWindowViolationError = \"amqp:session:window-violation\",\n /**\n * Error is thrown when input was received for a link that was detached with an error.\n */\n ErrantLinkError = \"amqp:session:errant-link\",\n /**\n * Error is thrown when an attach was received using a handle that is already in use for an attached link.\n */\n HandleInUseError = \"amqp:session:handle-in-use\",\n /**\n * Error is thrown when a frame (other than attach) was received referencing a handle which is not\n * currently in use of an attached link.\n */\n UnattachedHandleError = \"amqp:session:unattached-handle\",\n /**\n * Error is thrown when an operator intervened to close the connection for some reason.\n */\n ConnectionForcedError = \"amqp:connection:forced\", // Retryable\n /**\n * Error is thrown when a valid frame header cannot be formed from the incoming byte stream.\n */\n FramingError = \"amqp:connection:framing-error\",\n /**\n * Error is thrown when the container is no longer available on the current connection.\n */\n ConnectionRedirectError = \"amqp:connection:redirect\",\n /**\n * Error is thrown when the server is busy. Callers should wait a while and retry the operation.\n */\n ServerBusyError = \"com.microsoft:server-busy\", // Retryable\n /**\n * Error is thrown when an incorrect argument was received.\n */\n ArgumentError = \"com.microsoft:argument-error\",\n /**\n * Error is thrown when server cancels the operation due to an internal issue.\n */\n OperationCancelledError = \"com.microsoft:operation-cancelled\", // Retryable\n /**\n * Error is thrown when the client sender does not have enough link credits to send the message.\n */\n SenderBusyError = \"client.sender:not-enough-link-credit\", // Retryable\n /**\n * Error is thrown when the client sender's link isn't ready\n */\n SenderNotReadyError = \"client.sender:link-not-ready\", // Retryable\n /**\n * Error is thrown when a low level system error is thrown by node.js.\n * {@link https://nodejs.org/api/errors.html#errors_class_systemerror}\n */\n SystemError = \"system:error\",\n}\n\n/**\n * Describes the fields on a Node.js SystemError.\n * Omits fields that are not related to network calls (e.g. file system calls).\n * See https://nodejs.org/dist/latest-v12.x/docs/api/errors.html#errors_class_systemerror\n */\nexport interface NetworkSystemError {\n address?: string;\n code: string;\n errno: string | number;\n info?: any;\n message: string;\n name: string;\n port?: number;\n stack: string;\n syscall: string;\n}\n\n/**\n * @internal\n */\nconst systemErrorFieldsToCopy: (keyof Omit<NetworkSystemError, \"name\" | \"message\">)[] = [\n \"address\",\n \"code\",\n \"errno\",\n \"info\",\n \"port\",\n \"stack\",\n \"syscall\",\n];\n\n/**\n * Determines if an error is a MessagingError.\n *\n * @param error - An error that can either be an Error or a MessagingError.\n */\nexport function isMessagingError(error: Error | MessagingError): error is MessagingError {\n return error.name === \"MessagingError\";\n}\n\n/**\n * Describes the base class for Messaging Error.\n */\nexport class MessagingError extends Error {\n /**\n * Address to which the network connection failed.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n address?: string;\n /**\n * A string label that identifies the error.\n */\n code?: string;\n /**\n * System-provided error number.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n errno?: number | string;\n /**\n * The error name. Default value: \"MessagingError\".\n */\n name: string = \"MessagingError\";\n /**\n * The unavailable network connection port.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n port?: number;\n /**\n * Name of the system call that triggered the error.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n syscall?: string;\n /**\n *\n * Describes whether the error is retryable. Default: true.\n */\n retryable: boolean = true;\n /**\n * Extra details about the error.\n */\n info?: any;\n /**\n * @param message - The error message that provides more information about the error.\n * @param originalError - An error whose properties will be copied to the MessagingError if the\n * property matches one found on the Node.js `SystemError`.\n */\n constructor(message: string, originalError?: Error) {\n super(message);\n\n if (!originalError) {\n return;\n }\n\n // copy properties from system error\n for (const propName of systemErrorFieldsToCopy) {\n if ((originalError as NetworkSystemError)[propName] != undefined) {\n this[propName] = (originalError as NetworkSystemError)[propName];\n }\n }\n }\n}\n\n/**\n * Provides a list of retryable AMQP errors.\n * \"InternalServerError\", \"ServerBusyError\", \"ServiceUnavailableError\", \"OperationCancelledError\",\n * \"SenderBusyError\", \"SenderNotReadyError\", \"MessagingError\", \"DetachForcedError\", \"ConnectionForcedError\",\n * \"TransferLimitExceededError\"\n */\nexport const retryableErrors: string[] = [\n \"InternalServerError\",\n \"ServerBusyError\",\n \"ServiceUnavailableError\",\n \"OperationCancelledError\",\n\n // The service may throw UnauthorizedError if credentials have been rotated.\n // Attempt to retry in case the user has also rotated their credentials.\n \"UnauthorizedError\",\n\n // OperationTimeoutError occurs when the service fails to respond within a given timeframe.\n // Since reasons for such failures can be transient, this is treated as a retryable error.\n \"OperationTimeoutError\",\n\n \"SenderBusyError\",\n \"SenderNotReadyError\",\n \"MessagingError\",\n \"DetachForcedError\",\n \"ConnectionForcedError\",\n \"TransferLimitExceededError\",\n\n // InsufficientCreditError occurs when the number of credits available on Rhea link is insufficient.\n // Since reasons for such shortage can be transient such as for pending delivery of messages, this is treated as a retryable error.\n \"InsufficientCreditError\",\n];\n\n/**\n * Maps some SystemErrors to amqp error conditions\n */\nexport enum SystemErrorConditionMapper {\n /* eslint-disable @typescript-eslint/no-duplicate-enum-values */\n ENOTFOUND = \"amqp:not-found\",\n EBUSY = \"com.microsoft:server-busy\",\n ECONNREFUSED = \"amqp:connection:forced\",\n ETIMEDOUT = \"com.microsoft:timeout\",\n ECONNRESET = \"com.microsoft:timeout\",\n ENETDOWN = \"com.microsoft:timeout\",\n EHOSTDOWN = \"com.microsoft:timeout\",\n ENETRESET = \"com.microsoft:timeout\",\n ENETUNREACH = \"com.microsoft:timeout\",\n ENONET = \"com.microsoft:timeout\",\n EADDRNOTAVAIL = \"com.microsoft:timeout\",\n EAI_AGAIN = \"com.microsoft:timeout\",\n /* eslint-enable @typescript-eslint/no-duplicate-enum-values */\n}\n\n/**\n * Checks whether the provided error is a node.js SystemError.\n * @param err - An object that may contain error information.\n */\nexport function isSystemError(err: unknown): err is NetworkSystemError {\n if (!isObjectWithProperties(err, [\"code\", \"syscall\", \"errno\"])) {\n return false;\n }\n\n if (!isString(err.code) || !isString(err.syscall)) {\n return false;\n }\n\n if (!isString(err.errno) && !isNumber(err.errno)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * @internal\n * Since browser doesn't differentiate between the various kinds of service communication errors,\n * this utility is used to look at the error target to identify such category of errors.\n * For more information refer to - https://html.spec.whatwg.org/multipage/comms.html#feedback-from-the-protocol\n * @param err - object that may contain error information\n */\nfunction isBrowserWebsocketError(err: any): boolean {\n let result: boolean = false;\n if (\n !isNodeLike &&\n self &&\n err.type === \"error\" &&\n err.target instanceof (self as any).WebSocket\n ) {\n result = true;\n }\n return result;\n}\n\n/**\n * @internal\n * Checks whether a object is an ErrorEvent or not. https://html.spec.whatwg.org/multipage/webappapis.html#errorevent\n * @param err - object that may contain error information\n */\nfunction isErrorEvent(err: any): err is { message: string; error: any } {\n return typeof err.error === \"object\" && typeof err.message === \"string\";\n}\n\n/**\n * @internal\n */\nconst rheaPromiseErrors = [\n // OperationTimeoutError occurs when the service fails to respond within a given timeframe.\n \"OperationTimeoutError\",\n\n // InsufficientCreditError occurs when the number of credits available on Rhea link is insufficient.\n \"InsufficientCreditError\",\n\n // Defines the error that occurs when the Sender fails to send a message.\n \"SendOperationFailedError\",\n];\n\n/**\n * Translates the AMQP error received at the protocol layer or a SystemError into a MessagingError.\n * All other errors are returned unaltered.\n *\n * @param err - The amqp error that was received.\n * @returns MessagingError object.\n */\nexport function translate(err: unknown): MessagingError | Error {\n if (!isDefined(err)) {\n return new Error(`Unknown error encountered.`);\n } else if (typeof err !== \"object\") {\n // The error is a scalar type, make it the message of an actual error.\n return new Error(String(err));\n }\n\n const errObj = isErrorEvent(err) ? err.error : err;\n\n // Built-in errors like TypeError and RangeError should not be retryable as these indicate issues\n // with user input and not an issue with the Messaging process.\n if (errObj instanceof TypeError || errObj instanceof RangeError) {\n return errObj;\n }\n\n if (isAmqpError(errObj)) {\n // translate\n const condition = errObj.condition;\n const description = errObj.description!;\n const error = new MessagingError(description);\n if ((errObj as any).stack) error.stack = (errObj as any).stack;\n error.info = errObj.info;\n if (condition) {\n error.code = ConditionErrorNameMapper[condition as keyof typeof ConditionErrorNameMapper];\n }\n if (\n description &&\n (description.includes(\"status-code: 404\") ||\n description.match(/The messaging entity .* could not be found.*/i) !== null)\n ) {\n error.code = \"MessagingEntityNotFoundError\";\n }\n if (error.code && retryableErrors.indexOf(error.code) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n if (errObj instanceof Error && errObj.name === \"MessagingError\") {\n // already translated\n return errObj;\n }\n\n if (isSystemError(errObj)) {\n // translate\n const condition = errObj.code;\n const description = errObj.message;\n const error = new MessagingError(description, errObj);\n let errorType = \"SystemError\";\n if (condition) {\n const amqpErrorCondition =\n SystemErrorConditionMapper[condition as keyof typeof SystemErrorConditionMapper];\n errorType =\n ConditionErrorNameMapper[amqpErrorCondition as keyof typeof ConditionErrorNameMapper];\n }\n if (retryableErrors.indexOf(errorType) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n if (isBrowserWebsocketError(errObj)) {\n // Translate browser communication errors during opening handshake to generic ServiceCommunicationError\n const error = new MessagingError(\"Websocket connection failed.\");\n error.code = ConditionErrorNameMapper[ErrorNameConditionMapper.ServiceCommunicationError];\n error.retryable = false;\n return error;\n }\n\n // Some errors come from rhea-promise and need to be converted to MessagingError.\n // A subset of these are also retryable.\n if (isError(errObj) && rheaPromiseErrors.indexOf(errObj.name) !== -1) {\n const error = new MessagingError(errObj.message, errObj);\n error.code = errObj.name;\n if (error.code && retryableErrors.indexOf(error.code) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n return isError(errObj) ? errObj : new Error(String(errObj));\n}\n\n/**\n * @internal\n */\nfunction isAmqpError(error: any): error is AmqpError {\n return rheaIsAmqpError(error);\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,2BAA2B;AAG3B,OAAO,EAA0B,WAAW,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAN,IAAY,qB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AC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,KAAU;IAC7B,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n/* eslint-disable eqeqeq */\n\nimport type { AmqpError } from \"rhea-promise\";\nimport { AmqpResponseStatusCode, isAmqpError as rheaIsAmqpError } from \"rhea-promise\";\nimport { isDefined, isError, isNodeLike, isObjectWithProperties } from \"@azure/core-util\";\nimport { getGlobalProperty, isNumber, isString } from \"./util/utils.js\";\n\n/**\n * Maps the conditions to the numeric AMQP Response status codes.\n * @internal\n */\nexport enum ConditionStatusMapper {\n \"com.microsoft:timeout\" = AmqpResponseStatusCode.RequestTimeout,\n \"amqp:not-found\" = AmqpResponseStatusCode.NotFound,\n \"amqp:not-implemented\" = AmqpResponseStatusCode.NotImplemented,\n \"com.microsoft:entity-already-exists\" = AmqpResponseStatusCode.Conflict,\n \"com.microsoft:message-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:session-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:no-matching-subscription\" = AmqpResponseStatusCode.InternalServerError,\n \"amqp:link:message-size-exceeded\" = AmqpResponseStatusCode.Forbidden,\n \"com.microsoft:server-busy\" = AmqpResponseStatusCode.ServiceUnavailable,\n \"com.microsoft:argument-error\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:argument-out-of-range\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:store-lock-lost\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:session-cannot-be-locked\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:partition-not-owned\" = AmqpResponseStatusCode.Gone,\n \"com.microsoft:entity-disabled\" = AmqpResponseStatusCode.BadRequest,\n \"com.microsoft:publisher-revoked\" = AmqpResponseStatusCode.Unauthorized,\n \"amqp:link:stolen\" = AmqpResponseStatusCode.Gone,\n \"amqp:not-allowed\" = AmqpResponseStatusCode.BadRequest,\n \"amqp:unauthorized-access\" = AmqpResponseStatusCode.Unauthorized,\n \"amqp:resource-limit-exceeded\" = AmqpResponseStatusCode.Forbidden,\n}\n\n/**\n * Maps the amqp error conditions to the Error names.\n */\nexport enum ConditionErrorNameMapper {\n /**\n * Error is thrown when the address is already in use.\n */\n \"com.microsoft:address-already-in-use\" = \"AddressAlreadyInUseError\",\n /**\n * Error is thrown when the store lock is lost.\n */\n \"com.microsoft:store-lock-lost\" = \"StoreLockLostError\",\n /**\n * Error is thrown when a matching subscription is not found.\n */\n \"com.microsoft:no-matching-subscription\" = \"NoMatchingSubscriptionError\",\n /**\n * Error is thrown when an attempt is made to access a partition that is not owned by the\n * requesting entity.\n */\n \"com.microsoft:partition-not-owned\" = \"PartitionNotOwnedError\",\n /**\n * Error is thrown when access to publisher has been revoked.\n */\n \"com.microsoft:publisher-revoked\" = \"PublisherRevokedError\",\n /**\n * Error is thrown when an attempt is made to create an entity that already exists.\n */\n \"com.microsoft:entity-already-exists\" = \"MessagingEntityAlreadyExistsError\",\n /**\n * Error is thrown when trying to access/connect to a disabled messaging entity.\n */\n \"com.microsoft:entity-disabled\" = \"MessagingEntityDisabledError\",\n /**\n * Error is thrown when the lock on the message is lost.\n */\n \"com.microsoft:message-lock-lost\" = \"MessageLockLostError\",\n /**\n * Error is thrown when the lock on the Azure ServiceBus session is lost.\n */\n \"com.microsoft:session-lock-lost\" = \"SessionLockLostError\",\n /**\n * Error is thrown when the Azure ServiceBus session cannot be locked.\n */\n \"com.microsoft:session-cannot-be-locked\" = \"SessionCannotBeLockedError\",\n /**\n * Error is thrown when an internal server error occurred. You may have found a bug?\n */\n \"amqp:internal-error\" = \"InternalServerError\", // Retryable\n /**\n * Error for signaling general communication errors related to messaging operations.\n */\n \"amqp:not-found\" = \"ServiceCommunicationError\",\n /**\n * Error is thrown when the message is not found.\n */\n \"com.microsoft:message-not-found\" = \"MessageNotFoundError\",\n /**\n * Error is thrown when relay is not found.\n */\n \"com.microsoft:relay-not-found\" = \"RelayNotFoundError\",\n /**\n * Error is thrown when a feature is not implemented yet but the placeholder is present.\n */\n \"amqp:not-implemented\" = \"NotImplementedError\",\n /**\n * Error is thrown when an operation is attempted but is not allowed.\n */\n \"amqp:not-allowed\" = \"InvalidOperationError\",\n /**\n * Error is thrown the the Azure EventHub/ServiceBus quota has been exceeded.\n * Quotas are reset periodically, this operation will have to wait until then.\n * The messaging entity has reached its maximum allowable size.\n * This can happen if the maximum number of receivers (which is 5) has already\n * been opened on a per-consumer group level.\n */\n \"amqp:resource-limit-exceeded\" = \"QuotaExceededError\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n \"amqp:unauthorized-access\" = \"UnauthorizedError\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n \"com.microsoft:auth-failed\" = \"UnauthorizedError\",\n /**\n * Error is thrown when the service is unavailable. The operation should be retried.\n */\n \"com.microsoft:timeout\" = \"ServiceUnavailableError\", // Retryable\n /**\n * Error is thrown when no new messages are received for the specified time.\n */\n \"com.microsoft:message-wait-timeout\" = \"MessageWaitTimeout\",\n /**\n * Error is thrown when an argument has a value that is out of the admissible range.\n */\n \"com.microsoft:argument-out-of-range\" = \"ArgumentOutOfRangeError\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n \"amqp:precondition-failed\" = \"PreconditionFailedError\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n \"com.microsoft:precondition-failed\" = \"PreconditionFailedError\",\n /**\n * Error is thrown when data could not be decoded.\n */\n \"amqp:decode-error\" = \"DecodeError\",\n /**\n * Error is thrown when an invalid field was passed in a frame body, and the operation could not proceed.\n */\n \"amqp:invalid-field\" = \"InvalidFieldError\",\n /**\n * Error is thrown when the client attempted to work with a server entity to which it\n * has no access because another client is working with it.\n */\n \"amqp:resource-locked\" = \"ResourceLockedError\",\n /**\n * Error is thrown when a server entity the client is working with has been deleted.\n */\n \"amqp:resource-deleted\" = \"ResourceDeletedError\",\n /**\n * Error is thrown when the peer sent a frame that is not permitted in the current state.\n */\n \"amqp:illegal-state\" = \"IllegalStateError\",\n /**\n * Error is thrown when the peer cannot send a frame because the smallest encoding of\n * the performative with the currently valid values would be too large to fit within\n * a frame of the agreed maximum frame size.\n */\n \"amqp:frame-size-too-small\" = \"FrameSizeTooSmallError\",\n /**\n * Error is thrown when an operator intervened to detach for some reason.\n */\n \"amqp:link:detach-forced\" = \"DetachForcedError\", // Retryable\n /**\n * Error is thrown when the peer sent more message transfers than currently allowed on the link.\n */\n \"amqp:link:transfer-limit-exceeded\" = \"TransferLimitExceededError\", // Retryable\n /**\n * Error is thrown when the message sent is too large: the maximum size is 256Kb.\n */\n \"amqp:link:message-size-exceeded\" = \"MessageTooLargeError\",\n /**\n * Error is thrown when the address provided cannot be resolved to a terminus at the current container.\n */\n \"amqp:link:redirect\" = \"LinkRedirectError\",\n /**\n * Error is thrown when two or more instances connect to the same partition\n * with different epoch values.\n */\n \"amqp:link:stolen\" = \"ReceiverDisconnectedError\",\n /**\n * Error is thrown when the peer violated incoming window for the session.\n */\n \"amqp:session:window-violation\" = \"SessionWindowViolationError\",\n /**\n * Error is thrown when input was received for a link that was detached with an error.\n */\n \"amqp:session:errant-link\" = \"ErrantLinkError\",\n /**\n * Error is thrown when an attach was received using a handle that is already in use for an attached link.\n */\n \"amqp:session:handle-in-use\" = \"HandleInUseError\",\n /**\n * Error is thrown when a frame (other than attach) was received referencing a handle which is not\n * currently in use of an attached link.\n */\n \"amqp:session:unattached-handle\" = \"UnattachedHandleError\",\n /**\n * Error is thrown when an operator intervened to close the connection for some reason.\n */\n \"amqp:connection:forced\" = \"ConnectionForcedError\", // Retryable\n /**\n * Error is thrown when a valid frame header cannot be formed from the incoming byte stream.\n */\n \"amqp:connection:framing-error\" = \"FramingError\",\n /**\n * Error is thrown when the container is no longer available on the current connection.\n */\n \"amqp:connection:redirect\" = \"ConnectionRedirectError\",\n /**\n * Error is thrown when the server is busy. Callers should wait a while and retry the operation.\n */\n \"com.microsoft:server-busy\" = \"ServerBusyError\", // Retryable\n /**\n * Error is thrown when an incorrect argument was received.\n */\n \"com.microsoft:argument-error\" = \"ArgumentError\",\n /**\n * Error is thrown when server cancels the operation due to an internal issue.\n */\n \"com.microsoft:operation-cancelled\" = \"OperationCancelledError\", // Retryable\n /**\n * Error is thrown when the client sender does not have enough link credits to send the message.\n */\n \"client.sender:not-enough-link-credit\" = \"SenderBusyError\", // Retryable\n /**\n * Error is thrown when the client sender's link isn't ready\n */\n \"client.sender:link-not-ready\" = \"SenderNotReadyError\", // Retryable\n\n /**\n * Error is thrown when a low level system error is thrown by node.js.\n * {@link https://nodejs.org/dist/latest-v8.x/docs/api/all.html#errors_class_system_error}\n */\n \"system:error\" = \"SystemError\",\n}\n\n/**\n * Maps the Error names to the amqp error conditions.\n */\nexport enum ErrorNameConditionMapper {\n /**\n * Error is thrown when the address is already in use.\n */\n AddressAlreadyInUseError = \"com.microsoft:address-already-in-use\",\n /**\n * Error is thrown when the store lock is lost.\n */\n StoreLockLostError = \"com.microsoft:store-lock-lost\",\n /**\n * Error is thrown when a matching subscription is not found.\n */\n NoMatchingSubscriptionError = \"com.microsoft:no-matching-subscription\",\n /**\n * Error is thrown when an attempt is made to access a partition that is not owned by the\n * requesting entity.\n */\n PartitionNotOwnedError = \"com.microsoft:partition-not-owned\",\n /**\n * Error is thrown when access to publisher has been revoked.\n */\n PublisherRevokedError = \"com.microsoft:publisher-revoked\",\n /**\n * Error is thrown when an attempt is made to create an entity that already exists.\n */\n MessagingEntityAlreadyExistsError = \"com.microsoft:entity-already-exists\",\n /**\n * Error is thrown when trying to access/connect to a disabled messaging entity.\n */\n MessagingEntityDisabledError = \"com.microsoft:entity-disabled\",\n /**\n * Error is thrown when the lock on the message is lost.\n */\n MessageLockLostError = \"com.microsoft:message-lock-lost\",\n /**\n * Error is thrown when the lock on the Azure ServiceBus session is lost.\n */\n SessionLockLostError = \"com.microsoft:session-lock-lost\",\n /**\n * Error is thrown when the Azure ServiceBus session cannot be locked.\n */\n SessionCannotBeLockedError = \"com.microsoft:session-cannot-be-locked\",\n /**\n * Error is thrown when an internal server error occurred. You may have found a bug?\n */\n InternalServerError = \"amqp:internal-error\", // Retryable\n /**\n * Error for signaling general communication errors related to messaging operations.\n */\n ServiceCommunicationError = \"amqp:not-found\",\n /**\n * Error is thrown when message is not found.\n */\n MessageNotFoundError = \"com.microsoft:message-not-found\",\n /**\n * Error is thrown when relay is not found.\n */\n RelayNotFoundError = \"com.microsoft:relay-not-found\",\n /**\n * Error is thrown when a feature is not implemented yet but the placeholder is present.\n */\n NotImplementedError = \"amqp:not-implemented\",\n /**\n * Error is thrown when an operation is attempted but is not allowed.\n */\n InvalidOperationError = \"amqp:not-allowed\",\n /**\n * Error is thrown the the Azure EventHub/ServiceBus quota has been exceeded.\n * Quotas are reset periodically, this operation will have to wait until then.\n * The messaging entity has reached its maximum allowable size.\n * This can happen if the maximum number of receivers (which is 5) has already\n * been opened on a per-consumer group level.\n */\n QuotaExceededError = \"amqp:resource-limit-exceeded\",\n /**\n * Error is thrown when the connection parameters are wrong and the server refused the connection.\n */\n UnauthorizedError = \"amqp:unauthorized-access\",\n /**\n * Error is thrown when the service is unavailable. The operation should be retried.\n */\n ServiceUnavailableError = \"com.microsoft:timeout\", // Retryable\n /**\n * Error is thrown when no new messages are received for the specified time.\n */\n MessageWaitTimeout = \"com.microsoft:message-wait-timeout\",\n /**\n * Error is thrown when an argument has a value that is out of the admissible range.\n */\n ArgumentOutOfRangeError = \"com.microsoft:argument-out-of-range\",\n /**\n * Error is thrown when a condition that should have been met in order to execute an operation was not.\n */\n PreconditionFailedError = \"amqp:precondition-failed\",\n /**\n * Error is thrown when data could not be decoded.\n */\n DecodeError = \"amqp:decode-error\",\n /**\n * Error is thrown when an invalid field was passed in a frame body, and the operation could not proceed.\n */\n InvalidFieldError = \"amqp:invalid-field\",\n /**\n * Error is thrown when the client attempted to work with a server entity to which it\n * has no access because another client is working with it.\n */\n ResourceLockedError = \"amqp:resource-locked\",\n /**\n * Error is thrown when a server entity the client is working with has been deleted.\n */\n ResourceDeletedError = \"amqp:resource-deleted\",\n /**\n * Error is thrown when the peer sent a frame that is not permitted in the current state.\n */\n IllegalStateError = \"amqp:illegal-state\",\n /**\n * Error is thrown when the peer cannot send a frame because the smallest encoding of\n * the performative with the currently valid values would be too large to fit within\n * a frame of the agreed maximum frame size.\n */\n FrameSizeTooSmallError = \"amqp:frame-size-too-small\",\n /**\n * Error is thrown when an operator intervened to detach for some reason.\n */\n DetachForcedError = \"amqp:link:detach-forced\", // Retryable\n /**\n * Error is thrown when the peer sent more message transfers than currently allowed on the link.\n */\n TransferLimitExceededError = \"amqp:link:transfer-limit-exceeded\", // Retryable\n /**\n * Error is thrown when the message sent is too large: the maximum size is 256Kb.\n */\n MessageTooLargeError = \"amqp:link:message-size-exceeded\",\n /**\n * Error is thrown when the address provided cannot be resolved to a terminus at the current container.\n */\n LinkRedirectError = \"amqp:link:redirect\",\n /**\n * Error is thrown when two or more instances connect to the same partition\n * with different epoch values.\n */\n ReceiverDisconnectedError = \"amqp:link:stolen\",\n /**\n * Error is thrown when the peer violated incoming window for the session.\n */\n SessionWindowViolationError = \"amqp:session:window-violation\",\n /**\n * Error is thrown when input was received for a link that was detached with an error.\n */\n ErrantLinkError = \"amqp:session:errant-link\",\n /**\n * Error is thrown when an attach was received using a handle that is already in use for an attached link.\n */\n HandleInUseError = \"amqp:session:handle-in-use\",\n /**\n * Error is thrown when a frame (other than attach) was received referencing a handle which is not\n * currently in use of an attached link.\n */\n UnattachedHandleError = \"amqp:session:unattached-handle\",\n /**\n * Error is thrown when an operator intervened to close the connection for some reason.\n */\n ConnectionForcedError = \"amqp:connection:forced\", // Retryable\n /**\n * Error is thrown when a valid frame header cannot be formed from the incoming byte stream.\n */\n FramingError = \"amqp:connection:framing-error\",\n /**\n * Error is thrown when the container is no longer available on the current connection.\n */\n ConnectionRedirectError = \"amqp:connection:redirect\",\n /**\n * Error is thrown when the server is busy. Callers should wait a while and retry the operation.\n */\n ServerBusyError = \"com.microsoft:server-busy\", // Retryable\n /**\n * Error is thrown when an incorrect argument was received.\n */\n ArgumentError = \"com.microsoft:argument-error\",\n /**\n * Error is thrown when server cancels the operation due to an internal issue.\n */\n OperationCancelledError = \"com.microsoft:operation-cancelled\", // Retryable\n /**\n * Error is thrown when the client sender does not have enough link credits to send the message.\n */\n SenderBusyError = \"client.sender:not-enough-link-credit\", // Retryable\n /**\n * Error is thrown when the client sender's link isn't ready\n */\n SenderNotReadyError = \"client.sender:link-not-ready\", // Retryable\n /**\n * Error is thrown when a low level system error is thrown by node.js.\n * {@link https://nodejs.org/api/errors.html#errors_class_systemerror}\n */\n SystemError = \"system:error\",\n}\n\n/**\n * Describes the fields on a Node.js SystemError.\n * Omits fields that are not related to network calls (e.g. file system calls).\n * See https://nodejs.org/dist/latest-v12.x/docs/api/errors.html#errors_class_systemerror\n */\nexport interface NetworkSystemError {\n address?: string;\n code: string;\n errno: string | number;\n info?: any;\n message: string;\n name: string;\n port?: number;\n stack: string;\n syscall: string;\n}\n\n/**\n * @internal\n */\nconst systemErrorFieldsToCopy: (keyof Omit<NetworkSystemError, \"name\" | \"message\">)[] = [\n \"address\",\n \"code\",\n \"errno\",\n \"info\",\n \"port\",\n \"stack\",\n \"syscall\",\n];\n\n/**\n * Determines if an error is a MessagingError.\n *\n * @param error - An error that can either be an Error or a MessagingError.\n */\nexport function isMessagingError(error: Error | MessagingError): error is MessagingError {\n return error.name === \"MessagingError\";\n}\n\n/**\n * Describes the base class for Messaging Error.\n */\nexport class MessagingError extends Error {\n /**\n * Address to which the network connection failed.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n address?: string;\n /**\n * A string label that identifies the error.\n */\n code?: string;\n /**\n * System-provided error number.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n errno?: number | string;\n /**\n * The error name. Default value: \"MessagingError\".\n */\n name: string = \"MessagingError\";\n /**\n * The unavailable network connection port.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n port?: number;\n /**\n * Name of the system call that triggered the error.\n * Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.\n */\n syscall?: string;\n /**\n *\n * Describes whether the error is retryable. Default: true.\n */\n retryable: boolean = true;\n /**\n * Extra details about the error.\n */\n info?: any;\n /**\n * @param message - The error message that provides more information about the error.\n * @param originalError - An error whose properties will be copied to the MessagingError if the\n * property matches one found on the Node.js `SystemError`.\n */\n constructor(message: string, originalError?: Error) {\n super(message);\n\n if (!originalError) {\n return;\n }\n\n // copy properties from system error\n for (const propName of systemErrorFieldsToCopy) {\n if ((originalError as NetworkSystemError)[propName] != undefined) {\n this[propName] = (originalError as NetworkSystemError)[propName];\n }\n }\n }\n}\n\n/**\n * Provides a list of retryable AMQP errors.\n * \"InternalServerError\", \"ServerBusyError\", \"ServiceUnavailableError\", \"OperationCancelledError\",\n * \"SenderBusyError\", \"SenderNotReadyError\", \"MessagingError\", \"DetachForcedError\", \"ConnectionForcedError\",\n * \"TransferLimitExceededError\"\n */\nexport const retryableErrors: string[] = [\n \"InternalServerError\",\n \"ServerBusyError\",\n \"ServiceUnavailableError\",\n \"OperationCancelledError\",\n\n // The service may throw UnauthorizedError if credentials have been rotated.\n // Attempt to retry in case the user has also rotated their credentials.\n \"UnauthorizedError\",\n\n // OperationTimeoutError occurs when the service fails to respond within a given timeframe.\n // Since reasons for such failures can be transient, this is treated as a retryable error.\n \"OperationTimeoutError\",\n\n \"SenderBusyError\",\n \"SenderNotReadyError\",\n \"MessagingError\",\n \"DetachForcedError\",\n \"ConnectionForcedError\",\n \"TransferLimitExceededError\",\n\n // InsufficientCreditError occurs when the number of credits available on Rhea link is insufficient.\n // Since reasons for such shortage can be transient such as for pending delivery of messages, this is treated as a retryable error.\n \"InsufficientCreditError\",\n];\n\n/**\n * Maps some SystemErrors to amqp error conditions\n */\nexport enum SystemErrorConditionMapper {\n /* eslint-disable @typescript-eslint/no-duplicate-enum-values */\n ENOTFOUND = \"amqp:not-found\",\n EBUSY = \"com.microsoft:server-busy\",\n ECONNREFUSED = \"amqp:connection:forced\",\n ETIMEDOUT = \"com.microsoft:timeout\",\n ECONNRESET = \"com.microsoft:timeout\",\n ENETDOWN = \"com.microsoft:timeout\",\n EHOSTDOWN = \"com.microsoft:timeout\",\n ENETRESET = \"com.microsoft:timeout\",\n ENETUNREACH = \"com.microsoft:timeout\",\n ENONET = \"com.microsoft:timeout\",\n EADDRNOTAVAIL = \"com.microsoft:timeout\",\n EAI_AGAIN = \"com.microsoft:timeout\",\n /* eslint-enable @typescript-eslint/no-duplicate-enum-values */\n}\n\n/**\n * Checks whether the provided error is a node.js SystemError.\n * @param err - An object that may contain error information.\n */\nexport function isSystemError(err: unknown): err is NetworkSystemError {\n if (!isObjectWithProperties(err, [\"code\", \"syscall\", \"errno\"])) {\n return false;\n }\n\n if (!isString(err.code) || !isString(err.syscall)) {\n return false;\n }\n\n if (!isString(err.errno) && !isNumber(err.errno)) {\n return false;\n }\n\n return true;\n}\n\n/**\n * @internal\n * Since browser doesn't differentiate between the various kinds of service communication errors,\n * this utility is used to look at the error target to identify such category of errors.\n * For more information refer to - https://html.spec.whatwg.org/multipage/comms.html#feedback-from-the-protocol\n * @param err - object that may contain error information\n */\nfunction isBrowserWebsocketError(err: any): boolean {\n let result: boolean = false;\n if (!isNodeLike && (globalThis as any) && err.type === \"error\") {\n const wsKey = \"WebSocket\";\n const WS = getGlobalProperty<any>(wsKey);\n if (WS && err.target instanceof WS) {\n result = true;\n }\n }\n return result;\n}\n\n/**\n * @internal\n * Checks whether a object is an ErrorEvent or not. https://html.spec.whatwg.org/multipage/webappapis.html#errorevent\n * @param err - object that may contain error information\n */\nfunction isErrorEvent(err: any): err is { message: string; error: any } {\n return typeof err.error === \"object\" && typeof err.message === \"string\";\n}\n\n/**\n * @internal\n */\nconst rheaPromiseErrors = [\n // OperationTimeoutError occurs when the service fails to respond within a given timeframe.\n \"OperationTimeoutError\",\n\n // InsufficientCreditError occurs when the number of credits available on Rhea link is insufficient.\n \"InsufficientCreditError\",\n\n // Defines the error that occurs when the Sender fails to send a message.\n \"SendOperationFailedError\",\n];\n\n/**\n * Translates the AMQP error received at the protocol layer or a SystemError into a MessagingError.\n * All other errors are returned unaltered.\n *\n * @param err - The amqp error that was received.\n * @returns MessagingError object.\n */\nexport function translate(err: unknown): MessagingError | Error {\n if (!isDefined(err)) {\n return new Error(`Unknown error encountered.`);\n } else if (typeof err !== \"object\") {\n // The error is a scalar type, make it the message of an actual error.\n return new Error(String(err));\n }\n\n const errObj = isErrorEvent(err) ? err.error : err;\n\n // Built-in errors like TypeError and RangeError should not be retryable as these indicate issues\n // with user input and not an issue with the Messaging process.\n if (errObj instanceof TypeError || errObj instanceof RangeError) {\n return errObj;\n }\n\n if (isAmqpError(errObj)) {\n // translate\n const condition = errObj.condition;\n const description = errObj.description!;\n const error = new MessagingError(description);\n if ((errObj as any).stack) error.stack = (errObj as any).stack;\n error.info = errObj.info;\n if (condition) {\n error.code = ConditionErrorNameMapper[condition as keyof typeof ConditionErrorNameMapper];\n }\n if (\n description &&\n (description.includes(\"status-code: 404\") ||\n description.match(/The messaging entity .* could not be found.*/i) !== null)\n ) {\n error.code = \"MessagingEntityNotFoundError\";\n }\n if (error.code && retryableErrors.indexOf(error.code) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n if (errObj instanceof Error && errObj.name === \"MessagingError\") {\n // already translated\n return errObj;\n }\n\n if (isSystemError(errObj)) {\n // translate\n const condition = errObj.code;\n const description = errObj.message;\n const error = new MessagingError(description, errObj);\n let errorType = \"SystemError\";\n if (condition) {\n const amqpErrorCondition =\n SystemErrorConditionMapper[condition as keyof typeof SystemErrorConditionMapper];\n errorType =\n ConditionErrorNameMapper[amqpErrorCondition as keyof typeof ConditionErrorNameMapper];\n }\n if (retryableErrors.indexOf(errorType) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n if (isBrowserWebsocketError(errObj)) {\n // Translate browser communication errors during opening handshake to generic ServiceCommunicationError\n const error = new MessagingError(\"Websocket connection failed.\");\n error.code = ConditionErrorNameMapper[ErrorNameConditionMapper.ServiceCommunicationError];\n error.retryable = false;\n return error;\n }\n\n // Some errors come from rhea-promise and need to be converted to MessagingError.\n // A subset of these are also retryable.\n if (isError(errObj) && rheaPromiseErrors.indexOf(errObj.name) !== -1) {\n const error = new MessagingError(errObj.message, errObj);\n error.code = errObj.name;\n if (error.code && retryableErrors.indexOf(error.code) === -1) {\n // not found\n error.retryable = false;\n }\n return error;\n }\n\n return isError(errObj) ? errObj : new Error(String(errObj));\n}\n\n/**\n * @internal\n */\nfunction isAmqpError(error: any): error is AmqpError {\n return rheaIsAmqpError(error);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"hmacSha256.common.js","sourceRoot":"","sources":["../../../src/util/hmacSha256.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,MAAc;IAC1D,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAqB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IAEhF,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC3D,KAAK,EACL,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EACf,SAAS,EACT,KAAK,EACL,CAAC,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACnD,SAAS,EACT,YAAY,EACZ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CACnB,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAEvE,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport async function signString(key: string, toSign: string): Promise<string> {\n const enc = new TextEncoder();\n const algorithm: HmacImportParams = { name: \"HMAC\", hash: { name: \"SHA-256\" } };\n\n const extractedKey = await globalThis.crypto.subtle.importKey(\n \"raw\",\n enc.encode(key),\n algorithm,\n false,\n [\"sign\", \"verify\"],\n );\n const signature = await globalThis.crypto.subtle.sign(\n algorithm,\n extractedKey,\n enc.encode(toSign),\n );\n const digest = btoa(String.fromCharCode(...new Uint8Array(signature)));\n\n return encodeURIComponent(digest);\n}\n"]}
1
+ {"version":3,"file":"hmacSha256.common.js","sourceRoot":"","sources":["../../../src/util/hmacSha256.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,MAAc;IAC1D,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IAE9D,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC3D,KAAK,EACL,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EACf,SAAS,EACT,KAAK,EACL,CAAC,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CACnD,SAAS,EACT,YAAY,EACZ,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CACnB,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAEvE,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport async function signString(key: string, toSign: string): Promise<string> {\n const enc = new TextEncoder();\n const algorithm = { name: \"HMAC\", hash: { name: \"SHA-256\" } };\n\n const extractedKey = await globalThis.crypto.subtle.importKey(\n \"raw\",\n enc.encode(key),\n algorithm,\n false,\n [\"sign\", \"verify\"],\n );\n const signature = await globalThis.crypto.subtle.sign(\n algorithm,\n extractedKey,\n enc.encode(toSign),\n );\n const digest = btoa(String.fromCharCode(...new Uint8Array(signature)));\n\n return encodeURIComponent(digest);\n}\n"]}
@@ -144,4 +144,10 @@ export declare function isString(s: unknown): s is string;
144
144
  * @internal
145
145
  */
146
146
  export declare function isNumber(n: unknown): n is number;
147
+ /**
148
+ * @internal
149
+ * Safely read a property from the global object by key.
150
+ * Returns undefined if the property or global object is unavailable.
151
+ */
152
+ export declare function getGlobalProperty<T = any>(key: string): T | undefined;
147
153
  //# sourceMappingURL=utils.d.ts.map
@@ -148,9 +148,9 @@ export function executePromisesSequentially(promiseFactories, kickstart) {
148
148
  * @returns boolean.
149
149
  */
150
150
  export function isIotHubConnectionString(connectionString) {
151
- connectionString = String(connectionString);
151
+ const cs = String(connectionString);
152
152
  let result = false;
153
- const model = parseConnectionString(connectionString);
153
+ const model = parseConnectionString(cs);
154
154
  if (model && model.HostName && model.SharedAccessKey && model.SharedAccessKeyName) {
155
155
  result = true;
156
156
  }
@@ -168,4 +168,18 @@ export function isString(s) {
168
168
  export function isNumber(n) {
169
169
  return typeof n === "number";
170
170
  }
171
+ /**
172
+ * @internal
173
+ * Safely read a property from the global object by key.
174
+ * Returns undefined if the property or global object is unavailable.
175
+ */
176
+ export function getGlobalProperty(key) {
177
+ try {
178
+ const g = globalThis;
179
+ return g?.[key];
180
+ }
181
+ catch {
182
+ return undefined;
183
+ }
184
+ }
171
185
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAoDzD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CAAI,gBAAwB;IAC/D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjD,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YAChB,qBAAqB;YACrB,SAAS;QACX,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;QACjD,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEp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;;;;;;GAYG;AACH,MAAM,UAAU,2BAA2B,CACzC,gBAA4B,EAC5B,SAAmB;IAEnB,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,gBAAgB,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;QAC1C,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAwB;IAC/D,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAE5C,IAAI,MAAM,GAAY,KAAK,CAAC;IAC5B,MAAM,KAAK,GAAQ,qBAAqB,CAAM,gBAAgB,CAAC,CAAC;IAChE,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,mBAAmB,EAAE,CAAC;QAClF,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CancellableAsyncLock } from \"./lock.js\";\nimport { CancellableAsyncLockImpl } from \"./lock.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { delay as wrapperDelay } from \"@azure/core-util\";\n\n/**\n * @internal\n *\n * Describes the options that can be provided to create an async lock.\n */\nexport interface AsyncLockOptions {\n /**\n * The max timeout. Default is: 0 (never timeout).\n */\n timeout?: number;\n /**\n * Maximum pending tasks. Default is: 1000.\n */\n maxPending?: number;\n /**\n * Whether lock can reenter in the same domain.\n * Default is: false.\n */\n domainReentrant?: boolean;\n /**\n * Your implementation of the promise. Default is: global promise.\n */\n Promise?: any;\n}\n\n/**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\nexport interface WebSocketOptions {\n /**\n * The WebSocket constructor used to create an AMQP connection over a WebSocket.\n * This option should be provided in the below scenarios:\n * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.\n * - Your application needs to be run behind a proxy server.\n * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation\n * instead of the built-in WebSocket in the browser.\n */\n webSocket?: WebSocketImpl;\n /**\n * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates\n * the WebSocket.\n */\n webSocketConstructorOptions?: any;\n}\n\n/**\n * Defines an object with possible properties defined in T.\n */\nexport type ParsedOutput<T> = { [P in keyof T]: T[P] };\n\n/**\n * Parses the connection string and returns an object of type T.\n *\n * Connection strings have the following syntax:\n *\n * ConnectionString ::= `Part { \";\" Part } [ \";\" ] [ WhiteSpace ]`\n * Part ::= [ PartLiteral [ \"=\" PartLiteral ] ]\n * PartLiteral ::= [ WhiteSpace ] Literal [ WhiteSpace ]\n * Literal ::= ? any sequence of characters except ; or = or WhiteSpace ?\n * WhiteSpace ::= ? all whitespace characters including `\\r` and `\\n` ?\n *\n * @param connectionString - The connection string to be parsed.\n * @returns ParsedOutput<T>.\n */\nexport function parseConnectionString<T>(connectionString: string): ParsedOutput<T> {\n const output: { [k: string]: string } = {};\n const parts = connectionString.trim().split(\";\");\n\n for (let part of parts) {\n part = part.trim();\n\n if (part === \"\") {\n // parts can be empty\n continue;\n }\n\n const splitIndex = part.indexOf(\"=\");\n if (splitIndex === -1) {\n throw new Error(\n \"Connection string malformed: each part of the connection string must have an `=` assignment.\",\n );\n }\n\n const key = part.substring(0, splitIndex).trim();\n if (key === \"\") {\n throw new Error(\"Connection string malformed: missing key for assignment\");\n }\n\n const value = part.substring(splitIndex + 1).trim();\n\n output[key] = value;\n }\n\n return output as any;\n}\n\n/**\n * The cancellable async lock instance.\n */\nexport const defaultCancellableLock: CancellableAsyncLock = new CancellableAsyncLockImpl();\n\n/**\n * @internal\n *\n * Describes a Timeout class that can wait for the specified amount of time and then resolve/reject\n * the promise with the given value.\n */\nexport class Timeout {\n private _timer?: ReturnType<typeof setTimeout>;\n\n set<T>(t: number, value?: T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.clear();\n const callback: (args: any) => void = value ? () => reject(new Error(`${value}`)) : resolve;\n this._timer = setTimeout(callback, t);\n });\n }\n\n clear(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n }\n\n wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n const wrappedPromise = this._promiseFinally(promise, () => this.clear());\n const timer = this.set(t, value);\n return Promise.race([wrappedPromise, timer]);\n }\n\n private _promiseFinally<T>(promise: Promise<T>, fn: (...args: any[]) => void): Promise<T> {\n const success = (result: T): T => {\n fn();\n return result;\n };\n const error = (e: Error): Promise<never> => {\n fn();\n return Promise.reject(e);\n };\n return Promise.resolve(promise).then(success, error);\n }\n\n static set<T>(t: number, value?: T): Promise<T> {\n return new Timeout().set(t, value);\n }\n\n static wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n return new Timeout().wrap(promise, t, value);\n }\n}\n\n/**\n * A wrapper for setTimeout that resolves a promise after t milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param abortSignal - The abortSignal associated with containing operation.\n * @param abortErrorMsg - The abort error message associated with containing operation.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @returns - Resolved promise\n */\nexport async function delay<T>(\n delayInMs: number,\n abortSignal?: AbortSignalLike,\n abortErrorMsg?: string,\n value?: T,\n): Promise<T | void> {\n await wrapperDelay(delayInMs, {\n abortSignal: abortSignal,\n abortErrorMsg: abortErrorMsg,\n });\n if (value !== undefined) {\n return value;\n }\n}\n\n/**\n * Checks if an address is localhost.\n * @param address - The address to check.\n * @returns true if the address is localhost, false otherwise.\n */\nexport function isLoopbackAddress(address: string): boolean {\n return /^(.*:\\/\\/)?(127\\.[\\d.]+|[0:]+1|localhost)/.test(address.toLowerCase());\n}\n\n/**\n * @internal\n *\n * Generates a random number between the given interval\n * @param min - Min number of the range (inclusive).\n * @param max - Max number of the range (inclusive).\n */\nexport function randomNumberFromInterval(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\n/**\n * @internal\n *\n * Type declaration for a Function type where T is the input to the function and V is the output\n * of the function.\n */\nexport type Func<T, V> = (a: T) => V;\n\n/**\n * @internal\n *\n * Executes an array of promises sequentially. Inspiration of this method is here:\n * https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!\n *\n * @param promiseFactories - An array of promise factories(A function that return a promise)\n *\n * @param kickstart - Input to the first promise that is used to kickstart the promise chain.\n * If not provided then the promise chain starts with undefined.\n *\n * @returns A chain of resolved or rejected promises\n */\nexport function executePromisesSequentially(\n promiseFactories: Array<any>,\n kickstart?: unknown,\n): Promise<any> {\n let result = Promise.resolve(kickstart);\n promiseFactories.forEach((promiseFactory) => {\n result = result.then(promiseFactory);\n });\n return result;\n}\n\n/**\n * @internal\n *\n * Determines whether the given connection string is an iothub connection string.\n * @param connectionString - The connection string.\n * @returns boolean.\n */\nexport function isIotHubConnectionString(connectionString: string): boolean {\n connectionString = String(connectionString);\n\n let result: boolean = false;\n const model: any = parseConnectionString<any>(connectionString);\n if (model && model.HostName && model.SharedAccessKey && model.SharedAccessKeyName) {\n result = true;\n }\n return result;\n}\n\n/**\n * @internal\n */\nexport function isString(s: unknown): s is string {\n return typeof s === \"string\";\n}\n\n/**\n * @internal\n */\nexport function isNumber(n: unknown): n is number {\n return typeof n === \"number\";\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/util/utils.ts"],"names":[],"mappings":"AAAA,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,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,gBAAwB;IAC/D,MAAM,EAAE,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEpC,IAAI,MAAM,GAAY,KAAK,CAAC;IAC5B,MAAM,KAAK,GAAQ,qBAAqB,CAAM,EAAE,CAAC,CAAC;IAClD,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,mBAAmB,EAAE,CAAC;QAClF,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAU,GAAW;IACpD,IAAI,CAAC;QACH,MAAM,CAAC,GAAQ,UAAiB,CAAC;QACjC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAkB,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CancellableAsyncLock } from \"./lock.js\";\nimport { CancellableAsyncLockImpl } from \"./lock.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { delay as wrapperDelay } from \"@azure/core-util\";\n\n/**\n * @internal\n *\n * Describes the options that can be provided to create an async lock.\n */\nexport interface AsyncLockOptions {\n /**\n * The max timeout. Default is: 0 (never timeout).\n */\n timeout?: number;\n /**\n * Maximum pending tasks. Default is: 1000.\n */\n maxPending?: number;\n /**\n * Whether lock can reenter in the same domain.\n * Default is: false.\n */\n domainReentrant?: boolean;\n /**\n * Your implementation of the promise. Default is: global promise.\n */\n Promise?: any;\n}\n\n/**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\nexport interface WebSocketOptions {\n /**\n * The WebSocket constructor used to create an AMQP connection over a WebSocket.\n * This option should be provided in the below scenarios:\n * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment.\n * - Your application needs to be run behind a proxy server.\n * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation\n * instead of the built-in WebSocket in the browser.\n */\n webSocket?: WebSocketImpl;\n /**\n * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates\n * the WebSocket.\n */\n webSocketConstructorOptions?: any;\n}\n\n/**\n * Defines an object with possible properties defined in T.\n */\nexport type ParsedOutput<T> = { [P in keyof T]: T[P] };\n\n/**\n * Parses the connection string and returns an object of type T.\n *\n * Connection strings have the following syntax:\n *\n * ConnectionString ::= `Part { \";\" Part } [ \";\" ] [ WhiteSpace ]`\n * Part ::= [ PartLiteral [ \"=\" PartLiteral ] ]\n * PartLiteral ::= [ WhiteSpace ] Literal [ WhiteSpace ]\n * Literal ::= ? any sequence of characters except ; or = or WhiteSpace ?\n * WhiteSpace ::= ? all whitespace characters including `\\r` and `\\n` ?\n *\n * @param connectionString - The connection string to be parsed.\n * @returns ParsedOutput<T>.\n */\nexport function parseConnectionString<T>(connectionString: string): ParsedOutput<T> {\n const output: { [k: string]: string } = {};\n const parts = connectionString.trim().split(\";\");\n\n for (let part of parts) {\n part = part.trim();\n\n if (part === \"\") {\n // parts can be empty\n continue;\n }\n\n const splitIndex = part.indexOf(\"=\");\n if (splitIndex === -1) {\n throw new Error(\n \"Connection string malformed: each part of the connection string must have an `=` assignment.\",\n );\n }\n\n const key = part.substring(0, splitIndex).trim();\n if (key === \"\") {\n throw new Error(\"Connection string malformed: missing key for assignment\");\n }\n\n const value = part.substring(splitIndex + 1).trim();\n\n output[key] = value;\n }\n\n return output as any;\n}\n\n/**\n * The cancellable async lock instance.\n */\nexport const defaultCancellableLock: CancellableAsyncLock = new CancellableAsyncLockImpl();\n\n/**\n * @internal\n *\n * Describes a Timeout class that can wait for the specified amount of time and then resolve/reject\n * the promise with the given value.\n */\nexport class Timeout {\n private _timer?: ReturnType<typeof setTimeout>;\n\n set<T>(t: number, value?: T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n this.clear();\n const callback: (args: any) => void = value ? () => reject(new Error(`${value}`)) : resolve;\n this._timer = setTimeout(callback, t);\n });\n }\n\n clear(): void {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n }\n\n wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n const wrappedPromise = this._promiseFinally(promise, () => this.clear());\n const timer = this.set(t, value);\n return Promise.race([wrappedPromise, timer]);\n }\n\n private _promiseFinally<T>(promise: Promise<T>, fn: (...args: any[]) => void): Promise<T> {\n const success = (result: T): T => {\n fn();\n return result;\n };\n const error = (e: Error): Promise<never> => {\n fn();\n return Promise.reject(e);\n };\n return Promise.resolve(promise).then(success, error);\n }\n\n static set<T>(t: number, value?: T): Promise<T> {\n return new Timeout().set(t, value);\n }\n\n static wrap<T>(promise: Promise<T>, t: number, value?: T): Promise<T> {\n return new Timeout().wrap(promise, t, value);\n }\n}\n\n/**\n * A wrapper for setTimeout that resolves a promise after t milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param abortSignal - The abortSignal associated with containing operation.\n * @param abortErrorMsg - The abort error message associated with containing operation.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @returns - Resolved promise\n */\nexport async function delay<T>(\n delayInMs: number,\n abortSignal?: AbortSignalLike,\n abortErrorMsg?: string,\n value?: T,\n): Promise<T | void> {\n await wrapperDelay(delayInMs, {\n abortSignal: abortSignal,\n abortErrorMsg: abortErrorMsg,\n });\n if (value !== undefined) {\n return value;\n }\n}\n\n/**\n * Checks if an address is localhost.\n * @param address - The address to check.\n * @returns true if the address is localhost, false otherwise.\n */\nexport function isLoopbackAddress(address: string): boolean {\n return /^(.*:\\/\\/)?(127\\.[\\d.]+|[0:]+1|localhost)/.test(address.toLowerCase());\n}\n\n/**\n * @internal\n *\n * Generates a random number between the given interval\n * @param min - Min number of the range (inclusive).\n * @param max - Max number of the range (inclusive).\n */\nexport function randomNumberFromInterval(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\n/**\n * @internal\n *\n * Type declaration for a Function type where T is the input to the function and V is the output\n * of the function.\n */\nexport type Func<T, V> = (a: T) => V;\n\n/**\n * @internal\n *\n * Executes an array of promises sequentially. Inspiration of this method is here:\n * https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html. An awesome blog on promises!\n *\n * @param promiseFactories - An array of promise factories(A function that return a promise)\n *\n * @param kickstart - Input to the first promise that is used to kickstart the promise chain.\n * If not provided then the promise chain starts with undefined.\n *\n * @returns A chain of resolved or rejected promises\n */\nexport function executePromisesSequentially(\n promiseFactories: Array<any>,\n kickstart?: unknown,\n): Promise<any> {\n let result = Promise.resolve(kickstart);\n promiseFactories.forEach((promiseFactory) => {\n result = result.then(promiseFactory);\n });\n return result;\n}\n\n/**\n * @internal\n *\n * Determines whether the given connection string is an iothub connection string.\n * @param connectionString - The connection string.\n * @returns boolean.\n */\nexport function isIotHubConnectionString(connectionString: string): boolean {\n const cs = String(connectionString);\n\n let result: boolean = false;\n const model: any = parseConnectionString<any>(cs);\n if (model && model.HostName && model.SharedAccessKey && model.SharedAccessKeyName) {\n result = true;\n }\n return result;\n}\n\n/**\n * @internal\n */\nexport function isString(s: unknown): s is string {\n return typeof s === \"string\";\n}\n\n/**\n * @internal\n */\nexport function isNumber(n: unknown): n is number {\n return typeof n === \"number\";\n}\n\n/**\n * @internal\n * Safely read a property from the global object by key.\n * Returns undefined if the property or global object is unavailable.\n */\nexport function getGlobalProperty<T = any>(key: string): T | undefined {\n try {\n const g: any = globalThis as any;\n return g?.[key] as T | undefined;\n } catch {\n return undefined;\n }\n}\n"]}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ConnectionContextBase = void 0;
6
6
  const rhea_promise_1 = require("rhea-promise");
7
7
  const runtimeInfo_js_1 = require("./util/runtimeInfo.js");
8
+ const utils_js_1 = require("./util/utils.js");
8
9
  const cbs_js_1 = require("./cbs.js");
9
10
  const connectionConfig_js_1 = require("./connectionConfig/connectionConfig.js");
10
11
  const constants_js_1 = require("./util/constants.js");
@@ -87,9 +88,9 @@ exports.ConnectionContextBase = {
87
88
  ? parameters.operationTimeoutInMs / 1000
88
89
  : undefined,
89
90
  };
90
- if (parameters.config.webSocket ||
91
- (!core_util_1.isNodeLike && typeof self !== "undefined" && self.WebSocket)) {
92
- const socket = parameters.config.webSocket || self.WebSocket;
91
+ const globalWebSocket = (!core_util_1.isNodeLike && (0, utils_js_1.getGlobalProperty)("WebSocket")) || undefined;
92
+ if (parameters.config.webSocket || globalWebSocket) {
93
+ const socket = parameters.config.webSocket || globalWebSocket;
93
94
  const host = parameters.config.host;
94
95
  const endpoint = parameters.config.webSocketEndpointPath || "";
95
96
  const socketOptions = parameters.config.webSocketConstructorOptions || {};
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectionContextBase.js","sourceRoot":"","sources":["../../src/ConnectionContextBase.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,+CAOsB;AACtB,0DAA0E;AAC1E,qCAAqC;AACrC,gFAA0E;AAC1E,sDAAgD;AAChD,gDAA8C;AA8F9C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,kBAAmB,SAAQ,yBAAU;IACzC;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,OAA6B;QAC9C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,CAAC,eAAe,CA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qB,CAAC;IAC/B,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AwaitableSender, Receiver, Sender } from \"rhea-promise\";\nimport {\n Connection,\n type ConnectionOptions,\n type CreateAwaitableSenderOptions,\n type CreateReceiverOptions,\n type CreateSenderOptions,\n generate_uuid,\n} from \"rhea-promise\";\nimport { getFrameworkInfo, getPlatformInfo } from \"./util/runtimeInfo.js\";\nimport { CbsClient } from \"./cbs.js\";\nimport { ConnectionConfig } from \"./connectionConfig/connectionConfig.js\";\nimport { Constants } from \"./util/constants.js\";\nimport { isNodeLike } from \"@azure/core-util\";\n\n/**\n * Provides contextual information like the underlying amqp connection, cbs session, tokenProvider,\n * Connection config, data transformer, etc.\n */\nexport interface ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: ConnectionConfig;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for establishing an amqp connection per client if one does not exist.\n */\n connectionLock: string;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for negotiating cbs claim by an entity on that connection.\n */\n negotiateClaimLock: string;\n /**\n * The underlying AMQP connection.\n */\n connection: Connection;\n /**\n * The amqp connection id that uniquely identifies the\n * connection within a process.\n */\n connectionId: string;\n /**\n * Indicates whether the close() method was\n * called on the connection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A reference to the cbs session ($cbs endpoint) on the\n * underlying AMQP connection for the EventHub Client.\n */\n cbsSession: CbsClient;\n /**\n * Updates the context to use a new underlying AMQP connection and new cbs session.\n */\n refreshConnection: () => void;\n}\n\n/**\n * Defines the properties that need to be set while establishing the AMQP connection.\n */\nexport interface ConnectionProperties {\n /**\n * The name of the product that will be populated as the AMQP\n * connection property. Example: \"MSJSClient\".\n */\n product: string;\n /**\n * The version of the package/sdk that is making the AMQP connection.\n */\n version: string;\n /**\n * The userAgent that needs to be set as the AMQP connection\n * property. Example: `\"/js-service-bus\"` or `\"/js-event-hubs,/js-event-processor-host=1.0.0\"`.\n */\n userAgent: string;\n}\n\n/**\n * Describes the parameters that can be provided to create the base connection context.\n */\nexport interface CreateConnectionContextBaseParameters {\n /**\n * The connection config that is created by parsing the\n * connection string.\n */\n config: ConnectionConfig;\n /**\n * Properties to be provided while creating\n * the AMQP connection.\n */\n connectionProperties: ConnectionProperties;\n /**\n * Determines whether entity path should be a part of\n * the connection config. If `true` it must be present, `false` otherwise. Default value false.\n */\n isEntityPathRequired?: boolean;\n /**\n * The duration in which the promise should\n * complete (resolve/reject). If it is not completed, then the Promise will be rejected after\n * timeout occurs. Default: `60000 milliseconds`.\n */\n operationTimeoutInMs?: number;\n}\n\nconst maxListenerLimit = 1000;\n\nclass CoreAmqpConnection extends Connection {\n /**\n * Creates an amqp sender link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a sender link.\n * @returns Promise<Sender>.\n */\n async createSender(options?: CreateSenderOptions): Promise<Sender> {\n const sender = await super.createSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an awaitable amqp sender. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create an awaitable sender link.\n * - If `onError` and `onSessionError` handlers are not provided then the `AwaitableSender` will\n * clear the timer and reject the Promise for all the entries of inflight send operation in its\n * `deliveryDispositionMap`.\n * - If the user is handling the reconnection of sender link or the underlying connection in it's\n * app, then the `onError` and `onSessionError` handlers must be provided by the user and (s)he\n * shall be responsible of clearing the `deliveryDispositionMap` of inflight `send()` operation.\n *\n * @returns Promise<AwaitableSender>.\n */\n async createAwaitableSender(options?: CreateAwaitableSenderOptions): Promise<AwaitableSender> {\n const sender = await super.createAwaitableSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an amqp receiver link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a receiver link.\n * @returns Promise<Receiver>.\n */\n async createReceiver(options?: CreateReceiverOptions): Promise<Receiver> {\n const receiver = await super.createReceiver(options);\n receiver.setMaxListeners(maxListenerLimit);\n return receiver;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionContextBase = {\n /**\n * Creates the base connection context.\n * @param parameters - Parameters to be provided to create\n * the base connection context.\n */\n create(parameters: CreateConnectionContextBaseParameters): ConnectionContextBase {\n ConnectionConfig.validate(parameters.config, {\n isEntityPathRequired: parameters.isEntityPathRequired || false,\n });\n const userAgent = parameters.connectionProperties.userAgent;\n if (userAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${userAgent} with length: ${userAgent.length}`,\n );\n }\n\n const connectionOptions: ConnectionOptions = {\n transport: (parameters.config.useDevelopmentEmulator ? Constants.TCP : Constants.TLS) as any,\n host: parameters.config.host,\n hostname: parameters.config.amqpHostname ?? parameters.config.host,\n username: parameters.config.sharedAccessKeyName,\n port: parameters.config.port ?? (parameters.config.useDevelopmentEmulator ? 5672 : 5671),\n reconnect: false,\n properties: {\n product: parameters.connectionProperties.product,\n version: parameters.connectionProperties.version,\n \"user-agent\": userAgent,\n platform: getPlatformInfo(),\n framework: getFrameworkInfo(),\n },\n idle_time_out: Constants.defaultConnectionIdleTimeoutInMs,\n operationTimeoutInSeconds: parameters.operationTimeoutInMs\n ? parameters.operationTimeoutInMs / 1000\n : undefined,\n };\n\n if (\n parameters.config.webSocket ||\n (!isNodeLike && typeof self !== \"undefined\" && (self as any).WebSocket)\n ) {\n const socket = parameters.config.webSocket || (self as any).WebSocket;\n const host = parameters.config.host;\n const endpoint = parameters.config.webSocketEndpointPath || \"\";\n const socketOptions = parameters.config.webSocketConstructorOptions || {};\n const port = parameters.config.port ?? 443;\n\n connectionOptions.webSocketOptions = {\n webSocket: socket,\n url: `wss://${host}:${port}/${endpoint}`,\n protocol: [\"AMQPWSB10\"],\n options: socketOptions,\n };\n }\n\n const connection = new CoreAmqpConnection(connectionOptions);\n const connectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n const connectionContextBase: ConnectionContextBase = {\n wasConnectionCloseCalled: false,\n connectionLock: connectionLock,\n negotiateClaimLock: `${Constants.negotiateClaim}-${generate_uuid()}`,\n connection: connection,\n connectionId: connection.id,\n cbsSession: new CbsClient(connection, connectionLock),\n config: parameters.config,\n refreshConnection() {\n const newConnection = new CoreAmqpConnection(connectionOptions);\n const newConnectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n this.wasConnectionCloseCalled = false;\n this.connectionLock = newConnectionLock;\n this.negotiateClaimLock = `${Constants.negotiateClaim} - ${generate_uuid()}`;\n this.connection = newConnection;\n this.connectionId = newConnection.id;\n this.cbsSession = new CbsClient(newConnection, newConnectionLock);\n },\n };\n\n return connectionContextBase;\n },\n};\n"]}
1
+ {"version":3,"file":"ConnectionContextBase.js","sourceRoot":"","sources":["../../src/ConnectionContextBase.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,+CAOsB;AACtB,0DAA0E;AAC1E,8CAAoD;AACpD,qCAAqC;AACrC,gFAA0E;AAC1E,sDAAgD;AAChD,gDAA8C;AA8F9C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,kBAAmB,SAAQ,yBAAU;IACzC;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,OAA6B;QAC9C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC;QACzC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,qBAAqB,CAAC,OAAsC;QAChE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC1D,MA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AAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QAC7D,MAAM,cAAc,GAAG,GAAG,wBAAS,CAAC,mBAAmB,IAAI,IAAA,4BAAa,GAAE,EAAE,CAAC;QAC7E,MAAM,qBAAqB,GAA0B;YACnD,wBAAwB,EAAE,KAAK;YAC/B,cAAc,EAAE,cAAc;YAC9B,kBAAkB,EAAE,GAAG,wBAAS,CAAC,cAAc,IAAI,IAAA,4BAAa,GAAE,EAAE;YACpE,UAAU,EAAE,UAAU;YACtB,YAAY,EAAE,UAAU,CAAC,EAAE;YAC3B,UAAU,EAAE,IAAI,kBAAS,CAAC,UAAU,EAAE,cAAc,CAAC;YACrD,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,iBAAiB;gBACf,MAAM,aAAa,GAAG,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;gBAChE,MAAM,iBAAiB,GAAG,GAAG,wBAAS,CAAC,mBAAmB,IAAI,IAAA,4BAAa,GAAE,EAAE,CAAC;gBAChF,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC;gBACtC,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC;gBACxC,IAAI,CAAC,kBAAkB,GAAG,GAAG,wBAAS,CAAC,cAAc,MAAM,IAAA,4BAAa,GAAE,EAAE,CAAC;gBAC7E,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC;gBAChC,IAAI,CAAC,YAAY,GAAG,aAAa,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAS,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;YACpE,CAAC;SACF,CAAC;QAEF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AwaitableSender, Receiver, Sender } from \"rhea-promise\";\nimport {\n Connection,\n type ConnectionOptions,\n type CreateAwaitableSenderOptions,\n type CreateReceiverOptions,\n type CreateSenderOptions,\n generate_uuid,\n} from \"rhea-promise\";\nimport { getFrameworkInfo, getPlatformInfo } from \"./util/runtimeInfo.js\";\nimport { getGlobalProperty } from \"./util/utils.js\";\nimport { CbsClient } from \"./cbs.js\";\nimport { ConnectionConfig } from \"./connectionConfig/connectionConfig.js\";\nimport { Constants } from \"./util/constants.js\";\nimport { isNodeLike } from \"@azure/core-util\";\n\n/**\n * Provides contextual information like the underlying amqp connection, cbs session, tokenProvider,\n * Connection config, data transformer, etc.\n */\nexport interface ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: ConnectionConfig;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for establishing an amqp connection per client if one does not exist.\n */\n connectionLock: string;\n /**\n * The unique lock name per connection that is used to\n * acquire the lock for negotiating cbs claim by an entity on that connection.\n */\n negotiateClaimLock: string;\n /**\n * The underlying AMQP connection.\n */\n connection: Connection;\n /**\n * The amqp connection id that uniquely identifies the\n * connection within a process.\n */\n connectionId: string;\n /**\n * Indicates whether the close() method was\n * called on the connection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A reference to the cbs session ($cbs endpoint) on the\n * underlying AMQP connection for the EventHub Client.\n */\n cbsSession: CbsClient;\n /**\n * Updates the context to use a new underlying AMQP connection and new cbs session.\n */\n refreshConnection: () => void;\n}\n\n/**\n * Defines the properties that need to be set while establishing the AMQP connection.\n */\nexport interface ConnectionProperties {\n /**\n * The name of the product that will be populated as the AMQP\n * connection property. Example: \"MSJSClient\".\n */\n product: string;\n /**\n * The version of the package/sdk that is making the AMQP connection.\n */\n version: string;\n /**\n * The userAgent that needs to be set as the AMQP connection\n * property. Example: `\"/js-service-bus\"` or `\"/js-event-hubs,/js-event-processor-host=1.0.0\"`.\n */\n userAgent: string;\n}\n\n/**\n * Describes the parameters that can be provided to create the base connection context.\n */\nexport interface CreateConnectionContextBaseParameters {\n /**\n * The connection config that is created by parsing the\n * connection string.\n */\n config: ConnectionConfig;\n /**\n * Properties to be provided while creating\n * the AMQP connection.\n */\n connectionProperties: ConnectionProperties;\n /**\n * Determines whether entity path should be a part of\n * the connection config. If `true` it must be present, `false` otherwise. Default value false.\n */\n isEntityPathRequired?: boolean;\n /**\n * The duration in which the promise should\n * complete (resolve/reject). If it is not completed, then the Promise will be rejected after\n * timeout occurs. Default: `60000 milliseconds`.\n */\n operationTimeoutInMs?: number;\n}\n\nconst maxListenerLimit = 1000;\n\nclass CoreAmqpConnection extends Connection {\n /**\n * Creates an amqp sender link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a sender link.\n * @returns Promise<Sender>.\n */\n async createSender(options?: CreateSenderOptions): Promise<Sender> {\n const sender = await super.createSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an awaitable amqp sender. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create an awaitable sender link.\n * - If `onError` and `onSessionError` handlers are not provided then the `AwaitableSender` will\n * clear the timer and reject the Promise for all the entries of inflight send operation in its\n * `deliveryDispositionMap`.\n * - If the user is handling the reconnection of sender link or the underlying connection in it's\n * app, then the `onError` and `onSessionError` handlers must be provided by the user and (s)he\n * shall be responsible of clearing the `deliveryDispositionMap` of inflight `send()` operation.\n *\n * @returns Promise<AwaitableSender>.\n */\n async createAwaitableSender(options?: CreateAwaitableSenderOptions): Promise<AwaitableSender> {\n const sender = await super.createAwaitableSender(options);\n sender.setMaxListeners(maxListenerLimit);\n return sender;\n }\n\n /**\n * Creates an amqp receiver link. Max listener limit on the sender is set to 1000 because the\n * default value of 10 in NodeJS is too low.\n * @param options - Optional parameters to create a receiver link.\n * @returns Promise<Receiver>.\n */\n async createReceiver(options?: CreateReceiverOptions): Promise<Receiver> {\n const receiver = await super.createReceiver(options);\n receiver.setMaxListeners(maxListenerLimit);\n return receiver;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionContextBase = {\n /**\n * Creates the base connection context.\n * @param parameters - Parameters to be provided to create\n * the base connection context.\n */\n create(parameters: CreateConnectionContextBaseParameters): ConnectionContextBase {\n ConnectionConfig.validate(parameters.config, {\n isEntityPathRequired: parameters.isEntityPathRequired || false,\n });\n const userAgent = parameters.connectionProperties.userAgent;\n if (userAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${userAgent} with length: ${userAgent.length}`,\n );\n }\n\n const connectionOptions: ConnectionOptions = {\n transport: (parameters.config.useDevelopmentEmulator ? Constants.TCP : Constants.TLS) as any,\n host: parameters.config.host,\n hostname: parameters.config.amqpHostname ?? parameters.config.host,\n username: parameters.config.sharedAccessKeyName,\n port: parameters.config.port ?? (parameters.config.useDevelopmentEmulator ? 5672 : 5671),\n reconnect: false,\n properties: {\n product: parameters.connectionProperties.product,\n version: parameters.connectionProperties.version,\n \"user-agent\": userAgent,\n platform: getPlatformInfo(),\n framework: getFrameworkInfo(),\n },\n idle_time_out: Constants.defaultConnectionIdleTimeoutInMs,\n operationTimeoutInSeconds: parameters.operationTimeoutInMs\n ? parameters.operationTimeoutInMs / 1000\n : undefined,\n };\n\n const globalWebSocket = (!isNodeLike && getGlobalProperty(\"WebSocket\")) || undefined;\n if (parameters.config.webSocket || globalWebSocket) {\n const socket = parameters.config.webSocket || globalWebSocket;\n const host = parameters.config.host;\n const endpoint = parameters.config.webSocketEndpointPath || \"\";\n const socketOptions = parameters.config.webSocketConstructorOptions || {};\n const port = parameters.config.port ?? 443;\n\n connectionOptions.webSocketOptions = {\n webSocket: socket,\n url: `wss://${host}:${port}/${endpoint}`,\n protocol: [\"AMQPWSB10\"],\n options: socketOptions,\n };\n }\n\n const connection = new CoreAmqpConnection(connectionOptions);\n const connectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n const connectionContextBase: ConnectionContextBase = {\n wasConnectionCloseCalled: false,\n connectionLock: connectionLock,\n negotiateClaimLock: `${Constants.negotiateClaim}-${generate_uuid()}`,\n connection: connection,\n connectionId: connection.id,\n cbsSession: new CbsClient(connection, connectionLock),\n config: parameters.config,\n refreshConnection() {\n const newConnection = new CoreAmqpConnection(connectionOptions);\n const newConnectionLock = `${Constants.establishConnection}-${generate_uuid()}`;\n this.wasConnectionCloseCalled = false;\n this.connectionLock = newConnectionLock;\n this.negotiateClaimLock = `${Constants.negotiateClaim} - ${generate_uuid()}`;\n this.connection = newConnection;\n this.connectionId = newConnection.id;\n this.cbsSession = new CbsClient(newConnection, newConnectionLock);\n },\n };\n\n return connectionContextBase;\n },\n};\n"]}
@@ -601,11 +601,12 @@ function isSystemError(err) {
601
601
  */
602
602
  function isBrowserWebsocketError(err) {
603
603
  let result = false;
604
- if (!core_util_1.isNodeLike &&
605
- self &&
606
- err.type === "error" &&
607
- err.target instanceof self.WebSocket) {
608
- result = true;
604
+ if (!core_util_1.isNodeLike && globalThis && err.type === "error") {
605
+ const wsKey = "WebSocket";
606
+ const WS = (0, utils_js_1.getGlobalProperty)(wsKey);
607
+ if (WS && err.target instanceof WS) {
608
+ result = true;
609
+ }
609
610
  }
610
611
  return result;
611
612
  }