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

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