@azure/core-amqp 4.3.4-alpha.20250102.1 → 4.3.4-alpha.20250106.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAQD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IA+BjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAoC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
1
+ {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAgCD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IAqCjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAwC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -2,11 +2,30 @@
2
2
  // Licensed under the MIT License.
3
3
  import { isDefined } from "@azure/core-util";
4
4
  import { parseConnectionString } from "../util/utils.js";
5
+ const specialLocalIPs = ["::1", "0:0:0:0:0:0:0:1"];
5
6
  function getHost(endpoint) {
6
- const matches = /.*:\/\/([^/]*)/.exec(endpoint);
7
+ for (const ip of specialLocalIPs) {
8
+ if (endpoint.includes(ip)) {
9
+ return ip;
10
+ }
11
+ }
12
+ const matches = /.*:\/\/([^/:]*)/.exec(endpoint);
7
13
  const match = matches === null || matches === void 0 ? void 0 : matches[1];
8
14
  return !match ? endpoint : match;
9
15
  }
16
+ function extractPort(ep) {
17
+ const matches = /.*:(\d*)/.exec(ep);
18
+ const match = matches === null || matches === void 0 ? void 0 : matches[1];
19
+ return match ? parseInt(match, 10) : undefined;
20
+ }
21
+ function getPort(endpoint) {
22
+ for (const ip of specialLocalIPs) {
23
+ if (endpoint.includes(ip)) {
24
+ return extractPort(endpoint.replace(ip, ""));
25
+ }
26
+ }
27
+ return extractPort(endpoint);
28
+ }
10
29
  /**
11
30
  * Describes the ConnectionConfig module
12
31
  */
@@ -29,10 +48,15 @@ export const ConnectionConfig = {
29
48
  }
30
49
  if (!parsedCS.Endpoint.endsWith("/"))
31
50
  parsedCS.Endpoint += "/";
51
+ let port;
52
+ if (parsedCS.Endpoint.includes(":")) {
53
+ port = getPort(parsedCS.Endpoint);
54
+ }
32
55
  const result = {
33
56
  connectionString: connectionString,
34
57
  endpoint: parsedCS.Endpoint,
35
58
  host: getHost(parsedCS.Endpoint),
59
+ port,
36
60
  sharedAccessKeyName: parsedCS.SharedAccessKeyName,
37
61
  sharedAccessKey: parsedCS.SharedAccessKey,
38
62
  useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === "true",
@@ -61,6 +85,9 @@ export const ConnectionConfig = {
61
85
  throw new TypeError("Missing 'host' in configuration");
62
86
  }
63
87
  config.host = String(config.host);
88
+ if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {
89
+ throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);
90
+ }
64
91
  if (options.isEntityPathRequired && !config.entityPath) {
65
92
  throw new TypeError("Missing 'entityPath' in configuration");
66
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkFzD,SAAS,OAAO,CAAC,QAAgB;IAC/B,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAwB,EAAE,IAAa;QAC5C,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAE5C,MAAM,QAAQ,GAAG,qBAAqB,CAMnC,gBAAgB,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvB,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,QAAQ,CAAC,QAAQ,IAAI,GAAG,CAAC;QAE/D,MAAM,MAAM,GAAqB;YAC/B,gBAAgB,EAAE,gBAAgB;YAClC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAChC,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB;YACjD,e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EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;YAEhE,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nfunction getHost(endpoint: string): string {\n const matches = /.*:\\/\\/([^/]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
1
+ {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkFzD,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAEnD,SAAS,OAAO,CAAC,QAAgB;IAC/B,KAAK,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,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OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nconst specialLocalIPs = [\"::1\", \"0:0:0:0:0:0:0:1\"];\n\nfunction getHost(endpoint: string): string {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return ip;\n }\n }\n\n const matches = /.*:\\/\\/([^/:]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\nfunction extractPort(ep: string): number | undefined {\n const matches = /.*:(\\d*)/.exec(ep);\n const match = matches?.[1];\n return match ? parseInt(match, 10) : undefined;\n}\n\nfunction getPort(endpoint: string): number | undefined {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return extractPort(endpoint.replace(ip, \"\"));\n }\n }\n\n return extractPort(endpoint);\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n let port: number | undefined;\n if (parsedCS.Endpoint.includes(\":\")) {\n port = getPort(parsedCS.Endpoint);\n }\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n port,\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {\n throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);\n }\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAQD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IA+BjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAoC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
1
+ {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAgCD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IAqCjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAwC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -6,11 +6,30 @@ exports.ConnectionConfig = void 0;
6
6
  exports.isSharedAccessSignature = isSharedAccessSignature;
7
7
  const core_util_1 = require("@azure/core-util");
8
8
  const utils_js_1 = require("../util/utils.js");
9
+ const specialLocalIPs = ["::1", "0:0:0:0:0:0:0:1"];
9
10
  function getHost(endpoint) {
10
- const matches = /.*:\/\/([^/]*)/.exec(endpoint);
11
+ for (const ip of specialLocalIPs) {
12
+ if (endpoint.includes(ip)) {
13
+ return ip;
14
+ }
15
+ }
16
+ const matches = /.*:\/\/([^/:]*)/.exec(endpoint);
11
17
  const match = matches === null || matches === void 0 ? void 0 : matches[1];
12
18
  return !match ? endpoint : match;
13
19
  }
20
+ function extractPort(ep) {
21
+ const matches = /.*:(\d*)/.exec(ep);
22
+ const match = matches === null || matches === void 0 ? void 0 : matches[1];
23
+ return match ? parseInt(match, 10) : undefined;
24
+ }
25
+ function getPort(endpoint) {
26
+ for (const ip of specialLocalIPs) {
27
+ if (endpoint.includes(ip)) {
28
+ return extractPort(endpoint.replace(ip, ""));
29
+ }
30
+ }
31
+ return extractPort(endpoint);
32
+ }
14
33
  /**
15
34
  * Describes the ConnectionConfig module
16
35
  */
@@ -33,10 +52,15 @@ exports.ConnectionConfig = {
33
52
  }
34
53
  if (!parsedCS.Endpoint.endsWith("/"))
35
54
  parsedCS.Endpoint += "/";
55
+ let port;
56
+ if (parsedCS.Endpoint.includes(":")) {
57
+ port = getPort(parsedCS.Endpoint);
58
+ }
36
59
  const result = {
37
60
  connectionString: connectionString,
38
61
  endpoint: parsedCS.Endpoint,
39
62
  host: getHost(parsedCS.Endpoint),
63
+ port,
40
64
  sharedAccessKeyName: parsedCS.SharedAccessKeyName,
41
65
  sharedAccessKey: parsedCS.SharedAccessKey,
42
66
  useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === "true",
@@ -65,6 +89,9 @@ exports.ConnectionConfig = {
65
89
  throw new TypeError("Missing 'host' in configuration");
66
90
  }
67
91
  config.host = String(config.host);
92
+ if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {
93
+ throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);
94
+ }
68
95
  if (options.isEntityPathRequired && !config.entityPath) {
69
96
  throw new TypeError("Missing 'entityPath' in configuration");
70
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAuLlC,0DAEC;AAtLD,gDAA6C;AAC7C,+CAAyD;AAkFzD,SAAS,OAAO,CAAC,QAAgB;IAC/B,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CA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,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nfunction getHost(endpoint: string): string {\n const matches = /.*:\\/\\/([^/]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
1
+ {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAyNlC,0DAEC;AAxND,gDAA6C;AAC7C,+CAAyD;AAkFzD,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAEnD,SAAS,OAAO,CAAC,QAAgB;IAC/B,KAAK,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,EAAU;IAC7B,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;IAC3B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C,CAAC;QAC/D,CAAC;QACD,IAAI,IAAA,qBAAS,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACtD,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;YAEhE,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nconst specialLocalIPs = [\"::1\", \"0:0:0:0:0:0:0:1\"];\n\nfunction getHost(endpoint: string): string {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return ip;\n }\n }\n\n const matches = /.*:\\/\\/([^/:]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\nfunction extractPort(ep: string): number | undefined {\n const matches = /.*:(\\d*)/.exec(ep);\n const match = matches?.[1];\n return match ? parseInt(match, 10) : undefined;\n}\n\nfunction getPort(endpoint: string): number | undefined {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return extractPort(endpoint.replace(ip, \"\"));\n }\n }\n\n return extractPort(endpoint);\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n let port: number | undefined;\n if (parsedCS.Endpoint.includes(\":\")) {\n port = getPort(parsedCS.Endpoint);\n }\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n port,\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {\n throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);\n }\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAQD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IA+BjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAoC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
1
+ {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAgCD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IAqCjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAwC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -2,11 +2,30 @@
2
2
  // Licensed under the MIT License.
3
3
  import { isDefined } from "@azure/core-util";
4
4
  import { parseConnectionString } from "../util/utils.js";
5
+ const specialLocalIPs = ["::1", "0:0:0:0:0:0:0:1"];
5
6
  function getHost(endpoint) {
6
- const matches = /.*:\/\/([^/]*)/.exec(endpoint);
7
+ for (const ip of specialLocalIPs) {
8
+ if (endpoint.includes(ip)) {
9
+ return ip;
10
+ }
11
+ }
12
+ const matches = /.*:\/\/([^/:]*)/.exec(endpoint);
7
13
  const match = matches === null || matches === void 0 ? void 0 : matches[1];
8
14
  return !match ? endpoint : match;
9
15
  }
16
+ function extractPort(ep) {
17
+ const matches = /.*:(\d*)/.exec(ep);
18
+ const match = matches === null || matches === void 0 ? void 0 : matches[1];
19
+ return match ? parseInt(match, 10) : undefined;
20
+ }
21
+ function getPort(endpoint) {
22
+ for (const ip of specialLocalIPs) {
23
+ if (endpoint.includes(ip)) {
24
+ return extractPort(endpoint.replace(ip, ""));
25
+ }
26
+ }
27
+ return extractPort(endpoint);
28
+ }
10
29
  /**
11
30
  * Describes the ConnectionConfig module
12
31
  */
@@ -29,10 +48,15 @@ export const ConnectionConfig = {
29
48
  }
30
49
  if (!parsedCS.Endpoint.endsWith("/"))
31
50
  parsedCS.Endpoint += "/";
51
+ let port;
52
+ if (parsedCS.Endpoint.includes(":")) {
53
+ port = getPort(parsedCS.Endpoint);
54
+ }
32
55
  const result = {
33
56
  connectionString: connectionString,
34
57
  endpoint: parsedCS.Endpoint,
35
58
  host: getHost(parsedCS.Endpoint),
59
+ port,
36
60
  sharedAccessKeyName: parsedCS.SharedAccessKeyName,
37
61
  sharedAccessKey: parsedCS.SharedAccessKey,
38
62
  useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === "true",
@@ -61,6 +85,9 @@ export const ConnectionConfig = {
61
85
  throw new TypeError("Missing 'host' in configuration");
62
86
  }
63
87
  config.host = String(config.host);
88
+ if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {
89
+ throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);
90
+ }
64
91
  if (options.isEntityPathRequired && !config.entityPath) {
65
92
  throw new TypeError("Missing 'entityPath' in configuration");
66
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkFzD,SAAS,OAAO,CAAC,QAAgB;IAC/B,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B;;;;;;;;OAQG;IACH,MAAM,CAAC,gBAAwB,EAAE,IAAa;QAC5C,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAE5C,MAAM,QAAQ,GAAG,qBAAqB,CAMnC,gBAAgB,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACvB,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,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;QAC/D,CAAC;QACD,IAAI,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACtD,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;YAEhE,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nfunction getHost(endpoint: string): string {\n const matches = /.*:\\/\\/([^/]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
1
+ {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC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AAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nconst specialLocalIPs = [\"::1\", \"0:0:0:0:0:0:0:1\"];\n\nfunction getHost(endpoint: string): string {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return ip;\n }\n }\n\n const matches = /.*:\\/\\/([^/:]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\nfunction extractPort(ep: string): number | undefined {\n const matches = /.*:(\\d*)/.exec(ep);\n const match = matches?.[1];\n return match ? parseInt(match, 10) : undefined;\n}\n\nfunction getPort(endpoint: string): number | undefined {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return extractPort(endpoint.replace(ip, \"\"));\n }\n }\n\n return extractPort(endpoint);\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n let port: number | undefined;\n if (parsedCS.Endpoint.includes(\":\")) {\n port = getPort(parsedCS.Endpoint);\n }\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n port,\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {\n throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);\n }\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAQD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IA+BjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAoC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
1
+ {"version":3,"file":"connectionConfig.d.ts","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,2BAA2B,CAAC,EAAE,GAAG,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAgCD;;GAEG;AAEH,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;OAQG;6BACsB,MAAM,SAAS,MAAM,GAAG,gBAAgB;IAqCjE;;;;OAIG;qBACc,gBAAgB,YAAY,uBAAuB,GAAG,IAAI;CAwC5E,CAAC;AAEF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAEzE"}
@@ -2,11 +2,30 @@
2
2
  // Licensed under the MIT License.
3
3
  import { isDefined } from "@azure/core-util";
4
4
  import { parseConnectionString } from "../util/utils.js";
5
+ const specialLocalIPs = ["::1", "0:0:0:0:0:0:0:1"];
5
6
  function getHost(endpoint) {
6
- const matches = /.*:\/\/([^/]*)/.exec(endpoint);
7
+ for (const ip of specialLocalIPs) {
8
+ if (endpoint.includes(ip)) {
9
+ return ip;
10
+ }
11
+ }
12
+ const matches = /.*:\/\/([^/:]*)/.exec(endpoint);
7
13
  const match = matches === null || matches === void 0 ? void 0 : matches[1];
8
14
  return !match ? endpoint : match;
9
15
  }
16
+ function extractPort(ep) {
17
+ const matches = /.*:(\d*)/.exec(ep);
18
+ const match = matches === null || matches === void 0 ? void 0 : matches[1];
19
+ return match ? parseInt(match, 10) : undefined;
20
+ }
21
+ function getPort(endpoint) {
22
+ for (const ip of specialLocalIPs) {
23
+ if (endpoint.includes(ip)) {
24
+ return extractPort(endpoint.replace(ip, ""));
25
+ }
26
+ }
27
+ return extractPort(endpoint);
28
+ }
10
29
  /**
11
30
  * Describes the ConnectionConfig module
12
31
  */
@@ -29,10 +48,15 @@ export const ConnectionConfig = {
29
48
  }
30
49
  if (!parsedCS.Endpoint.endsWith("/"))
31
50
  parsedCS.Endpoint += "/";
51
+ let port;
52
+ if (parsedCS.Endpoint.includes(":")) {
53
+ port = getPort(parsedCS.Endpoint);
54
+ }
32
55
  const result = {
33
56
  connectionString: connectionString,
34
57
  endpoint: parsedCS.Endpoint,
35
58
  host: getHost(parsedCS.Endpoint),
59
+ port,
36
60
  sharedAccessKeyName: parsedCS.SharedAccessKeyName,
37
61
  sharedAccessKey: parsedCS.SharedAccessKey,
38
62
  useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === "true",
@@ -61,6 +85,9 @@ export const ConnectionConfig = {
61
85
  throw new TypeError("Missing 'host' in configuration");
62
86
  }
63
87
  config.host = String(config.host);
88
+ if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {
89
+ throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);
90
+ }
64
91
  if (options.isEntityPathRequired && !config.entityPath) {
65
92
  throw new TypeError("Missing 'entityPath' in configuration");
66
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAA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,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nfunction getHost(endpoint: string): string {\n const matches = /.*:\\/\\/([^/]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
1
+ {"version":3,"file":"connectionConfig.js","sourceRoot":"","sources":["../../../src/connectionConfig/connectionConfig.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkFzD,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;AAEnD,SAAS,OAAO,CAAC,QAAgB;IAC/B,KAAK,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjD,MA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QAElC,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YAC7E,MAAM,IAAI,SAAS,CAAC,qBAAqB,MAAM,CAAC,IAAI,mBAAmB,CAAC,CAAC;QAC3E,CAAC;QAED,IAAI,OAAO,CAAC,oBAAoB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACvD,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACtD,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAChC,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;YAEhE,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;gBAC5B,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,gBAAwB;IAC9D,OAAO,gBAAgB,CAAC,KAAK,CAAC,oDAAoD,CAAC,IAAI,IAAI,CAAC;AAC9F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebSocketImpl } from \"rhea-promise\";\nimport { isDefined } from \"@azure/core-util\";\nimport { parseConnectionString } from \"../util/utils.js\";\n\n/**\n * Describes the options that can be provided while creating a connection config.\n */\nexport interface ConnectionConfigOptions {\n /**\n * Indicates whether the entity path is required in the\n * connection config.\n */\n isEntityPathRequired?: boolean;\n}\n\n/**\n * Describes the connection config object that is created after parsing an EventHub or ServiceBus\n * connection string.\n */\nexport interface ConnectionConfig {\n /**\n * The service bus endpoint\n * \"sb://<yournamespace>.servicebus.windows.net/\".\n */\n endpoint: string;\n /**\n * The DNS hostname or IP address of the service.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\" unless connecting\n * to the service through an intermediary.\n */\n host: string;\n /**\n * The fully qualified name of the host to connect to.\n * This field can be used by AMQP proxies to determine the correct back-end service to\n * connect the client to.\n * Typically of the form \"<yournamespace>.servicebus.windows.net\".\n */\n amqpHostname?: string;\n /**\n * The port number.\n */\n port?: number;\n /**\n * The connection string.\n */\n connectionString: string;\n /**\n * The name/path of the entity (hub/queue/topic name) to which the\n * connection needs to happen.\n */\n entityPath?: string;\n /**\n * The name of the access key.\n */\n sharedAccessKeyName: string;\n /**\n * The secret value of the access key.\n */\n sharedAccessKey: string;\n\n /**\n * The WebSocket constructor used to create an AMQP connection\n * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a\n * TCP socket will be used if a WebSocket constructor is not provided.\n */\n webSocket?: WebSocketImpl;\n\n /**\n * The path for the endpoint that accepts an AMQP\n * connection over WebSockets.\n */\n webSocketEndpointPath?: string;\n\n /**\n * Options to be passed to the WebSocket constructor\n */\n webSocketConstructorOptions?: any;\n /**\n * This should be true only if the connection string contains the slug \";UseDevelopmentEmulator=true\"\n * and the endpoint is a loopback address.\n */\n useDevelopmentEmulator?: boolean;\n}\n\nconst specialLocalIPs = [\"::1\", \"0:0:0:0:0:0:0:1\"];\n\nfunction getHost(endpoint: string): string {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return ip;\n }\n }\n\n const matches = /.*:\\/\\/([^/:]*)/.exec(endpoint);\n const match = matches?.[1];\n return !match ? endpoint : match;\n}\n\nfunction extractPort(ep: string): number | undefined {\n const matches = /.*:(\\d*)/.exec(ep);\n const match = matches?.[1];\n return match ? parseInt(match, 10) : undefined;\n}\n\nfunction getPort(endpoint: string): number | undefined {\n for (const ip of specialLocalIPs) {\n if (endpoint.includes(ip)) {\n return extractPort(endpoint.replace(ip, \"\"));\n }\n }\n\n return extractPort(endpoint);\n}\n\n/**\n * Describes the ConnectionConfig module\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- renaming constant would be a breaking change.\nexport const ConnectionConfig = {\n /**\n * Creates the connection config.\n * @param connectionString - The connection string for a given service like\n * EventHub/ServiceBus.\n * @param path - The name/path of the entity (hub name) to which the\n * connection needs to happen. This will override the EntityPath in the connectionString\n * if present.\n * @returns ConnectionConfig\n */\n create(connectionString: string, path?: string): ConnectionConfig {\n connectionString = String(connectionString);\n\n const parsedCS = parseConnectionString<{\n Endpoint: string;\n SharedAccessKeyName: string;\n SharedAccessKey: string;\n EntityPath?: string;\n UseDevelopmentEmulator?: string;\n }>(connectionString);\n if (!parsedCS.Endpoint) {\n throw new TypeError(\"Missing Endpoint in Connection String.\");\n }\n\n if (!parsedCS.Endpoint.endsWith(\"/\")) parsedCS.Endpoint += \"/\";\n\n let port: number | undefined;\n if (parsedCS.Endpoint.includes(\":\")) {\n port = getPort(parsedCS.Endpoint);\n }\n\n const result: ConnectionConfig = {\n connectionString: connectionString,\n endpoint: parsedCS.Endpoint,\n host: getHost(parsedCS.Endpoint),\n port,\n sharedAccessKeyName: parsedCS.SharedAccessKeyName,\n sharedAccessKey: parsedCS.SharedAccessKey,\n useDevelopmentEmulator: parsedCS.UseDevelopmentEmulator === \"true\",\n };\n\n if (path || parsedCS.EntityPath) {\n result.entityPath = path || parsedCS.EntityPath;\n }\n return result;\n },\n\n /**\n * Validates the properties of connection config.\n * @param config - The connection config to be validated.\n * @returns void\n */\n validate(config: ConnectionConfig, options?: ConnectionConfigOptions): void {\n if (!options) options = {};\n\n if (!config) {\n throw new TypeError(\"Missing configuration\");\n }\n\n if (!config.endpoint) {\n throw new TypeError(\"Missing 'endpoint' in configuration\");\n }\n config.endpoint = String(config.endpoint);\n\n if (!config.host) {\n throw new TypeError(\"Missing 'host' in configuration\");\n }\n config.host = String(config.host);\n\n if (config.port !== undefined && !(config.port >= 0 && config.port <= 65535)) {\n throw new TypeError(`Invalid 'port' of ${config.port} in configuration`);\n }\n\n if (options.isEntityPathRequired && !config.entityPath) {\n throw new TypeError(\"Missing 'entityPath' in configuration\");\n }\n if (isDefined(config.entityPath)) {\n config.entityPath = String(config.entityPath);\n }\n\n if (!isSharedAccessSignature(config.connectionString)) {\n if (!config.sharedAccessKeyName) {\n throw new TypeError(\"Missing 'sharedAccessKeyName' in configuration\");\n }\n config.sharedAccessKeyName = String(config.sharedAccessKeyName);\n\n if (!config.sharedAccessKey) {\n throw new TypeError(\"Missing 'sharedAccessKey' in configuration\");\n }\n config.sharedAccessKey = String(config.sharedAccessKey);\n }\n },\n};\n\n/**\n * @internal\n */\nexport function isSharedAccessSignature(connectionString: string): boolean {\n return connectionString.match(/;{0,1}SharedAccessSignature=SharedAccessSignature /) != null;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/core-amqp",
3
3
  "sdk-type": "client",
4
- "version": "4.3.4-alpha.20250102.1",
4
+ "version": "4.3.4-alpha.20250106.3",
5
5
  "description": "Common library for amqp based azure sdks like @azure/event-hubs.",
6
6
  "author": "Microsoft Corporation",
7
7
  "license": "MIT",