@azure/web-pubsub 1.1.3-alpha.20240110.1 → 1.1.3-alpha.20240112.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1756,7 +1756,6 @@ class GeneratedClient extends coreClient__namespace.ServiceClient {
1756
1756
  * @param options The parameter options
1757
1757
  */
1758
1758
  constructor(endpoint, options) {
1759
- var _a, _b;
1760
1759
  if (endpoint === undefined) {
1761
1760
  throw new Error("'endpoint' cannot be null");
1762
1761
  }
@@ -1771,9 +1770,14 @@ class GeneratedClient extends coreClient__namespace.ServiceClient {
1771
1770
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1772
1771
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1773
1772
  : `${packageDetails}`;
1774
- const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
1773
+ const optionsWithDefaults = {
1774
+ ...defaults,
1775
+ ...options,
1776
+ userAgentOptions: {
1775
1777
  userAgentPrefix
1776
- }, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{endpoint}" });
1778
+ },
1779
+ endpoint: options.endpoint ?? options.baseUri ?? "{endpoint}"
1780
+ };
1777
1781
  super(optionsWithDefaults);
1778
1782
  // Parameter assignments
1779
1783
  this.endpoint = endpoint;
@@ -1829,7 +1833,7 @@ function isRequestBody(obj) {
1829
1833
  ArrayBuffer.isView(obj))));
1830
1834
  }
1831
1835
  function getPayloadForMessage(message, options) {
1832
- if ((options === null || options === void 0 ? void 0 : options.contentType) === "text/plain") {
1836
+ if (options?.contentType === "text/plain") {
1833
1837
  if (typeof message !== "string") {
1834
1838
  throw new TypeError("Message must be a string.");
1835
1839
  }
@@ -1920,11 +1924,14 @@ class WebPubSubGroupImpl {
1920
1924
  }
1921
1925
  }
1922
1926
  return tracingClient.withSpan("WebPubSubGroupClient.addConnection", options, async (updatedOptions) => {
1923
- await this.client.webPubSub.addConnectionToGroup(this.hubName, this.groupName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
1927
+ await this.client.webPubSub.addConnectionToGroup(this.hubName, this.groupName, connectionId, {
1928
+ ...updatedOptions,
1929
+ onResponse,
1930
+ });
1924
1931
  if (response.status === 404) {
1925
1932
  throw new coreRestPipeline.RestError(`Connection id '${connectionId}' doesn't exist`, {
1926
- statusCode: response === null || response === void 0 ? void 0 : response.status,
1927
- request: response === null || response === void 0 ? void 0 : response.request,
1933
+ statusCode: response?.status,
1934
+ request: response?.request,
1928
1935
  response: response,
1929
1936
  });
1930
1937
  }
@@ -2072,7 +2079,6 @@ function webPubSubReverseProxyPolicy(endpoint) {
2072
2079
  */
2073
2080
  class WebPubSubServiceClient {
2074
2081
  constructor(endpointOrConnectionString, credsOrHubName, hubNameOrOpts, opts) {
2075
- var _a, _b, _c, _d, _e, _f;
2076
2082
  /**
2077
2083
  * The Web PubSub API version being used by this client
2078
2084
  */
@@ -2091,25 +2097,29 @@ class WebPubSubServiceClient {
2091
2097
  this.hubName = credsOrHubName;
2092
2098
  this.clientOptions = hubNameOrOpts;
2093
2099
  }
2094
- const internalPipelineOptions = Object.assign(Object.assign(Object.assign({}, this.clientOptions), {
2095
- apiVersion: this.apiVersion,
2096
- loggingOptions: {
2097
- additionalAllowedHeaderNames: (_b = (_a = this.clientOptions) === null || _a === void 0 ? void 0 : _a.loggingOptions) === null || _b === void 0 ? void 0 : _b.additionalAllowedHeaderNames,
2098
- additionalAllowedQueryParameters: (_d = (_c = this.clientOptions) === null || _c === void 0 ? void 0 : _c.loggingOptions) === null || _d === void 0 ? void 0 : _d.additionalAllowedQueryParameters,
2099
- logger: logger.info,
2100
+ const internalPipelineOptions = {
2101
+ ...this.clientOptions,
2102
+ ...{
2103
+ apiVersion: this.apiVersion,
2104
+ loggingOptions: {
2105
+ additionalAllowedHeaderNames: this.clientOptions?.loggingOptions?.additionalAllowedHeaderNames,
2106
+ additionalAllowedQueryParameters: this.clientOptions?.loggingOptions?.additionalAllowedQueryParameters,
2107
+ logger: logger.info,
2108
+ },
2100
2109
  },
2101
- }), (coreAuth.isTokenCredential(this.credential)
2102
- ? {
2103
- credential: this.credential,
2104
- credentialScopes: ["https://webpubsub.azure.com/.default"],
2105
- }
2106
- : {}));
2110
+ ...(coreAuth.isTokenCredential(this.credential)
2111
+ ? {
2112
+ credential: this.credential,
2113
+ credentialScopes: ["https://webpubsub.azure.com/.default"],
2114
+ }
2115
+ : {}),
2116
+ };
2107
2117
  this.client = new GeneratedClient(this.endpoint, internalPipelineOptions);
2108
2118
  if (!coreAuth.isTokenCredential(this.credential)) {
2109
2119
  this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));
2110
2120
  }
2111
- if ((_e = this.clientOptions) === null || _e === void 0 ? void 0 : _e.reverseProxyEndpoint) {
2112
- this.client.pipeline.addPolicy(webPubSubReverseProxyPolicy((_f = this.clientOptions) === null || _f === void 0 ? void 0 : _f.reverseProxyEndpoint));
2121
+ if (this.clientOptions?.reverseProxyEndpoint) {
2122
+ this.client.pipeline.addPolicy(webPubSubReverseProxyPolicy(this.clientOptions?.reverseProxyEndpoint));
2113
2123
  }
2114
2124
  }
2115
2125
  /**
@@ -2152,7 +2162,10 @@ class WebPubSubServiceClient {
2152
2162
  }
2153
2163
  }
2154
2164
  return tracingClient.withSpan("WebPubSubServiceClient.connectionExists", options, async (updatedOptions) => {
2155
- await this.client.webPubSub.connectionExists(this.hubName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2165
+ await this.client.webPubSub.connectionExists(this.hubName, connectionId, {
2166
+ ...updatedOptions,
2167
+ onResponse,
2168
+ });
2156
2169
  if (response.status === 200) {
2157
2170
  return true;
2158
2171
  }
@@ -2162,8 +2175,8 @@ class WebPubSubServiceClient {
2162
2175
  else {
2163
2176
  // this is sad - wish this was handled by autorest.
2164
2177
  throw new coreRestPipeline.RestError(response.bodyAsText, {
2165
- statusCode: response === null || response === void 0 ? void 0 : response.status,
2166
- request: response === null || response === void 0 ? void 0 : response.request,
2178
+ statusCode: response?.status,
2179
+ request: response?.request,
2167
2180
  response: response,
2168
2181
  });
2169
2182
  }
@@ -2264,7 +2277,10 @@ class WebPubSubServiceClient {
2264
2277
  }
2265
2278
  }
2266
2279
  return tracingClient.withSpan("WebPubSubServiceClient.groupExists", options, async (updatedOptions) => {
2267
- await this.client.webPubSub.groupExists(this.hubName, groupName, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2280
+ await this.client.webPubSub.groupExists(this.hubName, groupName, {
2281
+ ...updatedOptions,
2282
+ onResponse,
2283
+ });
2268
2284
  if (response.status === 200) {
2269
2285
  return true;
2270
2286
  }
@@ -2273,8 +2289,8 @@ class WebPubSubServiceClient {
2273
2289
  }
2274
2290
  else {
2275
2291
  throw new coreRestPipeline.RestError(response.bodyAsText, {
2276
- statusCode: response === null || response === void 0 ? void 0 : response.status,
2277
- request: response === null || response === void 0 ? void 0 : response.request,
2292
+ statusCode: response?.status,
2293
+ request: response?.request,
2278
2294
  response: response,
2279
2295
  });
2280
2296
  }
@@ -2295,7 +2311,10 @@ class WebPubSubServiceClient {
2295
2311
  }
2296
2312
  }
2297
2313
  return tracingClient.withSpan("WebPubSubServiceClient.userExists", options, async (updatedOptions) => {
2298
- await this.client.webPubSub.userExists(this.hubName, username, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2314
+ await this.client.webPubSub.userExists(this.hubName, username, {
2315
+ ...updatedOptions,
2316
+ onResponse,
2317
+ });
2299
2318
  if (response.status === 200) {
2300
2319
  return true;
2301
2320
  }
@@ -2305,8 +2324,8 @@ class WebPubSubServiceClient {
2305
2324
  else {
2306
2325
  // this is sad - wish this was handled by autorest.
2307
2326
  throw new coreRestPipeline.RestError(response.bodyAsText, {
2308
- statusCode: response === null || response === void 0 ? void 0 : response.status,
2309
- request: response === null || response === void 0 ? void 0 : response.request,
2327
+ statusCode: response?.status,
2328
+ request: response?.request,
2310
2329
  response: response,
2311
2330
  });
2312
2331
  }
@@ -2352,7 +2371,10 @@ class WebPubSubServiceClient {
2352
2371
  }
2353
2372
  }
2354
2373
  return tracingClient.withSpan("WebPubSubServiceClient.hasPermission", options, async (updatedOptions) => {
2355
- await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
2374
+ await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, {
2375
+ ...updatedOptions,
2376
+ onResponse,
2377
+ });
2356
2378
  if (response.status === 200) {
2357
2379
  return true;
2358
2380
  }
@@ -2362,8 +2384,8 @@ class WebPubSubServiceClient {
2362
2384
  else {
2363
2385
  // this is sad - wish this was handled by autorest.
2364
2386
  throw new coreRestPipeline.RestError(response.bodyAsText, {
2365
- statusCode: response === null || response === void 0 ? void 0 : response.status,
2366
- request: response === null || response === void 0 ? void 0 : response.request,
2387
+ statusCode: response?.status,
2388
+ request: response?.request,
2367
2389
  response: response,
2368
2390
  });
2369
2391
  }
@@ -2387,16 +2409,16 @@ class WebPubSubServiceClient {
2387
2409
  else {
2388
2410
  const key = this.credential.key;
2389
2411
  const audience = `${endpoint}client/hubs/${this.hubName}`;
2390
- const payload = { role: options === null || options === void 0 ? void 0 : options.roles, "webpubsub.group": options === null || options === void 0 ? void 0 : options.groups };
2412
+ const payload = { role: options?.roles, "webpubsub.group": options?.groups };
2391
2413
  const signOptions = {
2392
2414
  audience: audience,
2393
- expiresIn: (options === null || options === void 0 ? void 0 : options.expirationTimeInMinutes) === undefined
2415
+ expiresIn: options?.expirationTimeInMinutes === undefined
2394
2416
  ? "1h"
2395
2417
  : `${options.expirationTimeInMinutes}m`,
2396
2418
  algorithm: "HS256",
2397
2419
  };
2398
- if (options === null || options === void 0 ? void 0 : options.userId) {
2399
- signOptions.subject = options === null || options === void 0 ? void 0 : options.userId;
2420
+ if (options?.userId) {
2421
+ signOptions.subject = options?.userId;
2400
2422
  }
2401
2423
  token = jwt.sign(payload, key, signOptions);
2402
2424
  }