@azure/web-pubsub 1.0.1-alpha.20220401.1 → 1.1.0-alpha.20220418.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Release History
2
2
 
3
- ## 1.0.1 (Unreleased)
3
+ ## 1.1.0 (Unreleased)
4
4
 
5
5
  ### Features Added
6
6
 
@@ -10,6 +10,10 @@
10
10
 
11
11
  ### Other Changes
12
12
 
13
+ - Updated our `@azure/core-tracing` dependency to the latest version (1.0.0).
14
+ - Notable changes include Removal of `@opentelemetry/api` as a transitive dependency and ensuring that the active context is properly propagated.
15
+ - Customers who would like to continue using OpenTelemetry driven tracing should visit our [OpenTelemetry Instrumentation](https://www.npmjs.com/package/@azure/opentelemetry-instrumentation-azure-sdk) package for instructions.
16
+
13
17
  ## 1.0.0 (2021-11-11)
14
18
 
15
19
  No changes.
package/dist/index.js CHANGED
@@ -8,7 +8,6 @@ var coreClient = require('@azure/core-client');
8
8
  var coreTracing = require('@azure/core-tracing');
9
9
  var jwt = require('jsonwebtoken');
10
10
  var logger$1 = require('@azure/logger');
11
- var url = require('url');
12
11
 
13
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
13
 
@@ -1505,7 +1504,7 @@ class GeneratedClientContext extends coreClient__namespace.ServiceClient {
1505
1504
  const defaults = {
1506
1505
  requestContentType: "application/json; charset=utf-8"
1507
1506
  };
1508
- const packageDetails = `azsdk-js-web-pubsub/1.0.1`;
1507
+ const packageDetails = `azsdk-js-web-pubsub/1.1.0`;
1509
1508
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1510
1509
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1511
1510
  : `${packageDetails}`;
@@ -1543,9 +1542,9 @@ class GeneratedClient extends GeneratedClientContext {
1543
1542
 
1544
1543
  // Copyright (c) Microsoft Corporation.
1545
1544
  /** @internal */
1546
- const createSpan = coreTracing.createSpanFunction({
1545
+ const tracingClient = coreTracing.createTracingClient({
1547
1546
  namespace: "Microsoft.WebPubSub",
1548
- packagePrefix: "Azure.Messaging.WebPubSub",
1547
+ packageName: "@azure/web-pubsub",
1549
1548
  });
1550
1549
 
1551
1550
  // Copyright (c) Microsoft Corporation.
@@ -1597,15 +1596,14 @@ class WebPubSubGroupImpl {
1597
1596
  * @param options - Additional options
1598
1597
  */
1599
1598
  async addConnection(connectionId, options = {}) {
1600
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-addConnection", options);
1601
1599
  let response;
1602
1600
  function onResponse(rawResponse, flatResponse) {
1603
1601
  response = rawResponse;
1604
- if (updatedOptions.onResponse) {
1605
- updatedOptions.onResponse(rawResponse, flatResponse);
1602
+ if (options.onResponse) {
1603
+ options.onResponse(rawResponse, flatResponse);
1606
1604
  }
1607
1605
  }
1608
- try {
1606
+ return tracingClient.withSpan("WebPubSubGroupClient.addConnection", options, async (updatedOptions) => {
1609
1607
  await this.client.webPubSub.addConnectionToGroup(this.hubName, this.groupName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
1610
1608
  if (response.status === 404) {
1611
1609
  throw new coreRestPipeline.RestError(`Connection id '${connectionId}' doesn't exist`, {
@@ -1614,10 +1612,7 @@ class WebPubSubGroupImpl {
1614
1612
  response: response,
1615
1613
  });
1616
1614
  }
1617
- }
1618
- finally {
1619
- span.end();
1620
- }
1615
+ });
1621
1616
  }
1622
1617
  /**
1623
1618
  * Remove a specific connection from this group
@@ -1626,13 +1621,9 @@ class WebPubSubGroupImpl {
1626
1621
  * @param options - Additional options
1627
1622
  */
1628
1623
  async removeConnection(connectionId, options = {}) {
1629
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-removeConnection", options);
1630
- try {
1631
- await this.client.webPubSub.removeConnectionFromGroup(this.hubName, this.groupName, connectionId, updatedOptions);
1632
- }
1633
- finally {
1634
- span.end();
1635
- }
1624
+ return tracingClient.withSpan("WebPubSubGroupClient.removeConnection", options, (updatedOptions) => {
1625
+ return this.client.webPubSub.removeConnectionFromGroup(this.hubName, this.groupName, connectionId, updatedOptions);
1626
+ });
1636
1627
  }
1637
1628
  /**
1638
1629
  * Close all connections to this group
@@ -1640,13 +1631,9 @@ class WebPubSubGroupImpl {
1640
1631
  * @param options - Additional options
1641
1632
  */
1642
1633
  async closeAllConnections(options = {}) {
1643
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-closeAllConnections", options);
1644
- try {
1645
- return await this.client.webPubSub.closeGroupConnections(this.hubName, this.groupName, updatedOptions);
1646
- }
1647
- finally {
1648
- span.end();
1649
- }
1634
+ return tracingClient.withSpan("WebPubSubGroupClient.closeAllConnections", options, (updatedOptions) => {
1635
+ return this.client.webPubSub.closeGroupConnections(this.hubName, this.groupName, updatedOptions);
1636
+ });
1650
1637
  }
1651
1638
  /**
1652
1639
  * Add a user to this group
@@ -1655,13 +1642,9 @@ class WebPubSubGroupImpl {
1655
1642
  * @param options - Additional options
1656
1643
  */
1657
1644
  async addUser(username, options = {}) {
1658
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-addUser", options);
1659
- try {
1660
- await this.client.webPubSub.addUserToGroup(this.hubName, this.groupName, username, updatedOptions);
1661
- }
1662
- finally {
1663
- span.end();
1664
- }
1645
+ return tracingClient.withSpan("WebPubSubGroupClient.addUser", options, (updatedOptions) => {
1646
+ return this.client.webPubSub.addUserToGroup(this.hubName, this.groupName, username, updatedOptions);
1647
+ });
1665
1648
  }
1666
1649
  /**
1667
1650
  * Remove a user from this group
@@ -1670,23 +1653,15 @@ class WebPubSubGroupImpl {
1670
1653
  * @param options - Additional options
1671
1654
  */
1672
1655
  async removeUser(username, options = {}) {
1673
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-removeUser", options);
1674
- try {
1675
- await this.client.webPubSub.removeUserFromGroup(this.hubName, this.groupName, username, updatedOptions);
1676
- }
1677
- finally {
1678
- span.end();
1679
- }
1656
+ return tracingClient.withSpan("WebPubSubGroupClient.removeUser", options, (updatedOptions) => {
1657
+ return this.client.webPubSub.removeUserFromGroup(this.hubName, this.groupName, username, updatedOptions);
1658
+ });
1680
1659
  }
1681
1660
  async sendToAll(message, options = {}) {
1682
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-group-sendToAll", options);
1683
- const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1684
- try {
1685
- await this.client.webPubSub.sendToGroup(this.hubName, this.groupName, contentType, payload, updatedOptions);
1686
- }
1687
- finally {
1688
- span.end();
1689
- }
1661
+ return tracingClient.withSpan("WebPubSubGroupClient.sendToAll", options, (updatedOptions) => {
1662
+ const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1663
+ return this.client.webPubSub.sendToGroup(this.hubName, this.groupName, contentType, payload, updatedOptions);
1664
+ });
1690
1665
  }
1691
1666
  }
1692
1667
 
@@ -1743,10 +1718,10 @@ function parseConnectionString(conn) {
1743
1718
  throw new TypeError("connection string missing access key");
1744
1719
  const credential = new coreAuth.AzureKeyCredential(key);
1745
1720
  const port = parsed["port"];
1746
- const url$1 = new url.URL(endpointPart);
1747
- url$1.port = port;
1748
- const endpoint = url$1.toString();
1749
- url$1.port = "";
1721
+ const url = new URL(endpointPart);
1722
+ url.port = port;
1723
+ const endpoint = url.toString();
1724
+ url.port = "";
1750
1725
  return { credential, endpoint };
1751
1726
  }
1752
1727
 
@@ -1823,34 +1798,22 @@ class WebPubSubServiceClient {
1823
1798
  return new WebPubSubGroupImpl(this.client, this.hubName, groupName);
1824
1799
  }
1825
1800
  async sendToAll(message, options = {}) {
1826
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-sendToAll", options);
1827
- const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1828
- try {
1829
- return await this.client.webPubSub.sendToAll(this.hubName, contentType, payload, updatedOptions);
1830
- }
1831
- finally {
1832
- span.end();
1833
- }
1801
+ return tracingClient.withSpan("WebPubSubServiceClient.sendToAll", options, (updatedOptions) => {
1802
+ const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1803
+ return this.client.webPubSub.sendToAll(this.hubName, contentType, payload, updatedOptions);
1804
+ });
1834
1805
  }
1835
1806
  async sendToUser(username, message, options = {}) {
1836
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-sendToUser", options);
1837
- const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1838
- try {
1839
- return await this.client.webPubSub.sendToUser(this.hubName, username, contentType, payload, updatedOptions);
1840
- }
1841
- finally {
1842
- span.end();
1843
- }
1807
+ return tracingClient.withSpan("WebPubSubServiceClient.sendToUser", options, (updatedOptions) => {
1808
+ const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1809
+ return this.client.webPubSub.sendToUser(this.hubName, username, contentType, payload, updatedOptions);
1810
+ });
1844
1811
  }
1845
1812
  async sendToConnection(connectionId, message, options = {}) {
1846
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-sendToConnection", options);
1847
- const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1848
- try {
1849
- return await this.client.webPubSub.sendToConnection(this.hubName, connectionId, contentType, payload, updatedOptions);
1850
- }
1851
- finally {
1852
- span.end();
1853
- }
1813
+ return tracingClient.withSpan("WebPubSubServiceClient.sendToConnection", options, (updatedOptions) => {
1814
+ const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
1815
+ return this.client.webPubSub.sendToConnection(this.hubName, connectionId, contentType, payload, updatedOptions);
1816
+ });
1854
1817
  }
1855
1818
  /**
1856
1819
  * Check if a specific connection is connected to this hub
@@ -1859,15 +1822,14 @@ class WebPubSubServiceClient {
1859
1822
  * @param options - Additional options
1860
1823
  */
1861
1824
  async connectionExists(connectionId, options = {}) {
1862
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasConnection", options);
1863
1825
  let response;
1864
1826
  function onResponse(rawResponse, flatResponse) {
1865
1827
  response = rawResponse;
1866
- if (updatedOptions.onResponse) {
1867
- updatedOptions.onResponse(rawResponse, flatResponse);
1828
+ if (options.onResponse) {
1829
+ options.onResponse(rawResponse, flatResponse);
1868
1830
  }
1869
1831
  }
1870
- try {
1832
+ return tracingClient.withSpan("WebPubSubServiceClient.connectionExists", options, async (updatedOptions) => {
1871
1833
  await this.client.webPubSub.connectionExists(this.hubName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
1872
1834
  if (response.status === 200) {
1873
1835
  return true;
@@ -1883,10 +1845,7 @@ class WebPubSubServiceClient {
1883
1845
  response: response,
1884
1846
  });
1885
1847
  }
1886
- }
1887
- finally {
1888
- span.end();
1889
- }
1848
+ });
1890
1849
  }
1891
1850
  /**
1892
1851
  * Close a specific connection to this hub
@@ -1895,13 +1854,9 @@ class WebPubSubServiceClient {
1895
1854
  * @param options - Additional options
1896
1855
  */
1897
1856
  async closeConnection(connectionId, options = {}) {
1898
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeConnection", options);
1899
- try {
1900
- return await this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);
1901
- }
1902
- finally {
1903
- span.end();
1904
- }
1857
+ return tracingClient.withSpan("WebPubSubServiceClient.closeConnection", options, (updatedOptions) => {
1858
+ return this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);
1859
+ });
1905
1860
  }
1906
1861
  /**
1907
1862
  * Close all connections to this hub
@@ -1909,13 +1864,9 @@ class WebPubSubServiceClient {
1909
1864
  * @param options - Additional options
1910
1865
  */
1911
1866
  async closeAllConnections(options = {}) {
1912
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeAllConnections", options);
1913
- try {
1914
- return await this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);
1915
- }
1916
- finally {
1917
- span.end();
1918
- }
1867
+ return tracingClient.withSpan("WebPubSubServiceClient.closeAllConnections", options, (updatedOptions) => {
1868
+ return this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);
1869
+ });
1919
1870
  }
1920
1871
  /**
1921
1872
  * Close all connections with the given user id
@@ -1924,13 +1875,9 @@ class WebPubSubServiceClient {
1924
1875
  * @param options - Additional options
1925
1876
  */
1926
1877
  async closeUserConnections(userId, options = {}) {
1927
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeUserConnections", options);
1928
- try {
1929
- return await this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);
1930
- }
1931
- finally {
1932
- span.end();
1933
- }
1878
+ return tracingClient.withSpan("WebPubSubServiceClient.closeUserConnections", options, (updatedOptions) => {
1879
+ return this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);
1880
+ });
1934
1881
  }
1935
1882
  /**
1936
1883
  * Remove a specific user from all groups they are joined to
@@ -1938,13 +1885,9 @@ class WebPubSubServiceClient {
1938
1885
  * @param options - Additional options
1939
1886
  */
1940
1887
  async removeUserFromAllGroups(userId, options = {}) {
1941
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-removeUserFromAllGroups", options);
1942
- try {
1943
- await this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);
1944
- }
1945
- finally {
1946
- span.end();
1947
- }
1888
+ return tracingClient.withSpan("WebPubSubServiceClient.removeUserFromAllGroups", options, (updatedOptions) => {
1889
+ return this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);
1890
+ });
1948
1891
  }
1949
1892
  /**
1950
1893
  * Check if a particular group exists (i.e. has active connections).
@@ -1953,15 +1896,14 @@ class WebPubSubServiceClient {
1953
1896
  * @param options - Additional options
1954
1897
  */
1955
1898
  async groupExists(groupName, options = {}) {
1956
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasGroup", options);
1957
1899
  let response;
1958
1900
  function onResponse(rawResponse, flatResponse) {
1959
1901
  response = rawResponse;
1960
- if (updatedOptions.onResponse) {
1961
- updatedOptions.onResponse(rawResponse, flatResponse);
1902
+ if (options.onResponse) {
1903
+ options.onResponse(rawResponse, flatResponse);
1962
1904
  }
1963
1905
  }
1964
- try {
1906
+ return tracingClient.withSpan("WebPubSubServiceClient.groupExists", options, async (updatedOptions) => {
1965
1907
  await this.client.webPubSub.groupExists(this.hubName, groupName, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
1966
1908
  if (response.status === 200) {
1967
1909
  return true;
@@ -1976,10 +1918,7 @@ class WebPubSubServiceClient {
1976
1918
  response: response,
1977
1919
  });
1978
1920
  }
1979
- }
1980
- finally {
1981
- span.end();
1982
- }
1921
+ });
1983
1922
  }
1984
1923
  /**
1985
1924
  * Check if a particular user is connected to this hub.
@@ -1988,15 +1927,14 @@ class WebPubSubServiceClient {
1988
1927
  * @param options - Additional options
1989
1928
  */
1990
1929
  async userExists(username, options = {}) {
1991
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasUser", options);
1992
1930
  let response;
1993
1931
  function onResponse(rawResponse, flatResponse) {
1994
1932
  response = rawResponse;
1995
- if (updatedOptions.onResponse) {
1996
- updatedOptions.onResponse(rawResponse, flatResponse);
1933
+ if (options.onResponse) {
1934
+ options.onResponse(rawResponse, flatResponse);
1997
1935
  }
1998
1936
  }
1999
- try {
1937
+ return tracingClient.withSpan("WebPubSubServiceClient.userExists", options, async (updatedOptions) => {
2000
1938
  await this.client.webPubSub.userExists(this.hubName, username, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2001
1939
  if (response.status === 200) {
2002
1940
  return true;
@@ -2012,10 +1950,7 @@ class WebPubSubServiceClient {
2012
1950
  response: response,
2013
1951
  });
2014
1952
  }
2015
- }
2016
- finally {
2017
- span.end();
2018
- }
1953
+ });
2019
1954
  }
2020
1955
  /**
2021
1956
  * Grant permissions to a connection
@@ -2025,13 +1960,9 @@ class WebPubSubServiceClient {
2025
1960
  * @param options - Additional options
2026
1961
  */
2027
1962
  async grantPermission(connectionId, permission, options = {}) {
2028
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-grantPermission", options);
2029
- try {
2030
- return await this.client.webPubSub.grantPermission(this.hubName, permission, connectionId, updatedOptions);
2031
- }
2032
- finally {
2033
- span.end();
2034
- }
1963
+ return tracingClient.withSpan("WebPubSubServiceClient.grantPermission", options, (updatedOptions) => {
1964
+ return this.client.webPubSub.grantPermission(this.hubName, permission, connectionId, updatedOptions);
1965
+ });
2035
1966
  }
2036
1967
  /**
2037
1968
  * Revoke permissions from a connection
@@ -2041,13 +1972,9 @@ class WebPubSubServiceClient {
2041
1972
  * @param options - Additional options
2042
1973
  */
2043
1974
  async revokePermission(connectionId, permission, options = {}) {
2044
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-revokePermission", options);
2045
- try {
2046
- return await this.client.webPubSub.revokePermission(this.hubName, permission, connectionId, updatedOptions);
2047
- }
2048
- finally {
2049
- span.end();
2050
- }
1975
+ return tracingClient.withSpan("WebPubSubServiceClient.revokePermission", options, (updatedOptions) => {
1976
+ return this.client.webPubSub.revokePermission(this.hubName, permission, connectionId, updatedOptions);
1977
+ });
2051
1978
  }
2052
1979
  /**
2053
1980
  * Check if the connection has the specified permission
@@ -2057,15 +1984,14 @@ class WebPubSubServiceClient {
2057
1984
  * @param options - Additional options
2058
1985
  */
2059
1986
  async hasPermission(connectionId, permission, options = {}) {
2060
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasPermission", options);
2061
1987
  let response;
2062
1988
  function onResponse(rawResponse, flatResponse) {
2063
1989
  response = rawResponse;
2064
- if (updatedOptions.onResponse) {
2065
- updatedOptions.onResponse(rawResponse, flatResponse);
1990
+ if (options.onResponse) {
1991
+ options.onResponse(rawResponse, flatResponse);
2066
1992
  }
2067
1993
  }
2068
- try {
1994
+ return tracingClient.withSpan("WebPubSubServiceClient.hasPermission", options, async (updatedOptions) => {
2069
1995
  await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2070
1996
  if (response.status === 200) {
2071
1997
  return true;
@@ -2081,10 +2007,7 @@ class WebPubSubServiceClient {
2081
2007
  response: response,
2082
2008
  });
2083
2009
  }
2084
- }
2085
- finally {
2086
- span.end();
2087
- }
2010
+ });
2088
2011
  }
2089
2012
  /**
2090
2013
  * Generate a token for a client to connect to the Azure Web PubSub service.
@@ -2092,8 +2015,7 @@ class WebPubSubServiceClient {
2092
2015
  * @param options - Additional options
2093
2016
  */
2094
2017
  async getClientAccessToken(options = {}) {
2095
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-generateClientToken", options);
2096
- try {
2018
+ return tracingClient.withSpan("WebPubSubServiceClient.getClientAccessToken", options, async (updatedOptions) => {
2097
2019
  const endpoint = this.endpoint.endsWith("/") ? this.endpoint : this.endpoint + "/";
2098
2020
  const clientEndpoint = endpoint.replace(/(http)(s?:\/\/)/gi, "ws$2");
2099
2021
  const baseUrl = `${clientEndpoint}client/hubs/${this.hubName}`;
@@ -2123,10 +2045,7 @@ class WebPubSubServiceClient {
2123
2045
  baseUrl,
2124
2046
  url: `${baseUrl}?access_token=${token}`,
2125
2047
  };
2126
- }
2127
- finally {
2128
- span.end();
2129
- }
2048
+ });
2130
2049
  }
2131
2050
  }
2132
2051