@azure/web-pubsub 1.0.0-beta.3 → 1.0.1-alpha.20220103.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +107 -33
  3. package/dist/index.js +1048 -233
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/samples-dev/directMessage.js +1 -1
  6. package/dist-esm/samples-dev/directMessage.js.map +1 -1
  7. package/dist-esm/src/generated/generatedClient.js +3 -3
  8. package/dist-esm/src/generated/generatedClient.js.map +1 -1
  9. package/dist-esm/src/generated/generatedClientContext.js +8 -8
  10. package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
  11. package/dist-esm/src/generated/models/index.js +6 -1
  12. package/dist-esm/src/generated/models/index.js.map +1 -1
  13. package/dist-esm/src/generated/models/mappers.js +368 -0
  14. package/dist-esm/src/generated/models/mappers.js.map +1 -0
  15. package/dist-esm/src/generated/models/parameters.js +105 -23
  16. package/dist-esm/src/generated/models/parameters.js.map +1 -1
  17. package/dist-esm/src/generated/operations/healthApi.js +4 -3
  18. package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
  19. package/dist-esm/src/generated/operations/webPubSub.js +315 -59
  20. package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
  21. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -1
  22. package/dist-esm/src/groupClient.js +32 -21
  23. package/dist-esm/src/groupClient.js.map +1 -1
  24. package/dist-esm/src/hubClient.js +162 -107
  25. package/dist-esm/src/hubClient.js.map +1 -1
  26. package/dist-esm/src/index.js +1 -1
  27. package/dist-esm/src/index.js.map +1 -1
  28. package/dist-esm/src/logger.js +1 -1
  29. package/dist-esm/src/logger.js.map +1 -1
  30. package/dist-esm/src/parseConnectionString.js +3 -1
  31. package/dist-esm/src/parseConnectionString.js.map +1 -1
  32. package/dist-esm/src/reverseProxyPolicy.js +21 -0
  33. package/dist-esm/src/reverseProxyPolicy.js.map +1 -0
  34. package/dist-esm/src/tracing.js +1 -1
  35. package/dist-esm/src/tracing.js.map +1 -1
  36. package/dist-esm/src/utils.js +2 -0
  37. package/dist-esm/src/utils.js.map +1 -1
  38. package/dist-esm/src/webPubSubCredentialPolicy.js +2 -2
  39. package/dist-esm/src/webPubSubCredentialPolicy.js.map +1 -1
  40. package/dist-esm/test/conn.spec.js +2 -2
  41. package/dist-esm/test/conn.spec.js.map +1 -1
  42. package/dist-esm/test/groups.spec.js +14 -6
  43. package/dist-esm/test/groups.spec.js.map +1 -1
  44. package/dist-esm/test/hubs.spec.js +53 -10
  45. package/dist-esm/test/hubs.spec.js.map +1 -1
  46. package/dist-esm/test/integration.spec.js +128 -0
  47. package/dist-esm/test/integration.spec.js.map +1 -0
  48. package/dist-esm/test/testEnv.js +6 -2
  49. package/dist-esm/test/testEnv.js.map +1 -1
  50. package/package.json +32 -32
  51. package/types/web-pubsub.d.ts +165 -109
  52. package/dist-esm/src/normalizeOptions.js +0 -8
  53. package/dist-esm/src/normalizeOptions.js.map +0 -1
@@ -3,28 +3,30 @@
3
3
  import { RestError } from "@azure/core-rest-pipeline";
4
4
  import { GeneratedClient } from "./generated/generatedClient";
5
5
  import { WebPubSubGroupImpl } from "./groupClient";
6
- import normalizeSendToAllOptions from "./normalizeOptions";
6
+ import { isTokenCredential } from "@azure/core-auth";
7
7
  import { webPubSubKeyCredentialPolicy } from "./webPubSubCredentialPolicy";
8
8
  import { createSpan } from "./tracing";
9
9
  import { logger } from "./logger";
10
10
  import { parseConnectionString } from "./parseConnectionString";
11
11
  import jwt from "jsonwebtoken";
12
12
  import { getPayloadForMessage } from "./utils";
13
+ import { webPubSubReverseProxyPolicy } from "./reverseProxyPolicy";
13
14
  /**
14
15
  * Client for connecting to a Web PubSub hub
15
16
  */
16
17
  export class WebPubSubServiceClient {
17
18
  constructor(endpointOrConnectionString, credsOrHubName, hubNameOrOpts, opts) {
19
+ var _a, _b;
18
20
  /**
19
21
  * The Web PubSub API version being used by this client
20
22
  */
21
- this.apiVersion = "2020-10-01";
23
+ this.apiVersion = "2021-10-01";
22
24
  // unpack constructor arguments
23
- if (typeof credsOrHubName === "object" && "key" in credsOrHubName) {
25
+ if (typeof credsOrHubName === "object") {
24
26
  this.endpoint = endpointOrConnectionString;
25
- this.credential = credsOrHubName;
26
27
  this.hubName = hubNameOrOpts;
27
28
  this.clientOptions = opts;
29
+ this.credential = credsOrHubName;
28
30
  }
29
31
  else {
30
32
  const parsedCs = parseConnectionString(endpointOrConnectionString);
@@ -33,52 +35,34 @@ export class WebPubSubServiceClient {
33
35
  this.hubName = credsOrHubName;
34
36
  this.clientOptions = hubNameOrOpts;
35
37
  }
36
- const internalPipelineOptions = Object.assign(Object.assign({}, this.clientOptions), {
38
+ const internalPipelineOptions = Object.assign(Object.assign(Object.assign({}, this.clientOptions), {
39
+ apiVersion: this.apiVersion,
37
40
  loggingOptions: {
38
- logger: logger.info
41
+ logger: logger.info,
42
+ },
43
+ }), (isTokenCredential(this.credential)
44
+ ? {
45
+ credential: this.credential,
46
+ credentialScopes: ["https://webpubsub.azure.com/.default"],
39
47
  }
40
- });
48
+ : {}));
41
49
  this.client = new GeneratedClient(this.endpoint, internalPipelineOptions);
42
- this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));
43
- }
44
- /**
45
- * Auth the client connection with userId and custom claims if any
46
- * @param options The options that the client has
47
- */
48
- async getAuthenticationToken(options) {
49
- const endpoint = this.endpoint.endsWith("/") ? this.endpoint : this.endpoint + "/";
50
- const key = this.credential.key;
51
- const hub = this.hubName;
52
- const clientEndpoint = endpoint.replace(/(http)(s?:\/\/)/gi, "ws$2");
53
- const clientUrl = `${clientEndpoint}client/hubs/${hub}`;
54
- const audience = `${endpoint}client/hubs/${hub}`;
55
- const payload = { role: options === null || options === void 0 ? void 0 : options.roles };
56
- const signOptions = {
57
- audience: audience,
58
- expiresIn: (options === null || options === void 0 ? void 0 : options.ttl) === undefined ? "1h" : `${options.ttl}m`,
59
- algorithm: "HS256"
60
- };
61
- if (options === null || options === void 0 ? void 0 : options.userId) {
62
- signOptions.subject = options === null || options === void 0 ? void 0 : options.userId;
63
- }
64
- const token = jwt.sign(payload, key, signOptions);
65
- const url = `${clientUrl}?access_token=${token}`;
66
- return {
67
- baseUrl: clientUrl,
68
- token: jwt.sign(payload, key, signOptions),
69
- url: url
70
- };
50
+ if (!isTokenCredential(this.credential)) {
51
+ this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));
52
+ }
53
+ if ((_a = this.clientOptions) === null || _a === void 0 ? void 0 : _a.reverseProxyEndpoint) {
54
+ this.client.pipeline.addPolicy(webPubSubReverseProxyPolicy((_b = this.clientOptions) === null || _b === void 0 ? void 0 : _b.reverseProxyEndpoint));
55
+ }
71
56
  }
72
57
  /**
73
58
  * Get a client for a group
74
- * @param groupName The name of the group to connect to.
59
+ * @param groupName - The name of the group to connect to.
75
60
  */
76
61
  group(groupName) {
77
62
  return new WebPubSubGroupImpl(this.client, this.hubName, groupName);
78
63
  }
79
64
  async sendToAll(message, options = {}) {
80
- const normalizedOptions = normalizeSendToAllOptions(options);
81
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-sendToAll", normalizedOptions);
65
+ const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-sendToAll", options);
82
66
  const { contentType, payload } = getPayloadForMessage(message, updatedOptions);
83
67
  try {
84
68
  return await this.client.webPubSub.sendToAll(this.hubName, contentType, payload, updatedOptions);
@@ -110,32 +94,32 @@ export class WebPubSubServiceClient {
110
94
  /**
111
95
  * Check if a specific connection is connected to this hub
112
96
  *
113
- * @param connectionId Connection id to check
114
- * @param options Additional options
97
+ * @param connectionId - Connection id to check
98
+ * @param options - Additional options
115
99
  */
116
- async hasConnection(connectionId, options = {}) {
100
+ async connectionExists(connectionId, options = {}) {
117
101
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasConnection", options);
118
- try {
119
- let response;
120
- function onResponse(rawResponse, flatResponse) {
121
- response = rawResponse;
122
- if (updatedOptions.onResponse) {
123
- updatedOptions.onResponse(rawResponse, flatResponse);
124
- }
102
+ let response;
103
+ function onResponse(rawResponse, flatResponse) {
104
+ response = rawResponse;
105
+ if (updatedOptions.onResponse) {
106
+ updatedOptions.onResponse(rawResponse, flatResponse);
125
107
  }
108
+ }
109
+ try {
126
110
  await this.client.webPubSub.connectionExists(this.hubName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
127
- if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
111
+ if (response.status === 200) {
128
112
  return true;
129
113
  }
130
- else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
114
+ else if (response.status === 404) {
131
115
  return false;
132
116
  }
133
117
  else {
134
118
  // this is sad - wish this was handled by autorest.
135
- throw new RestError(response === null || response === void 0 ? void 0 : response.bodyAsText, {
119
+ throw new RestError(response.bodyAsText, {
136
120
  statusCode: response === null || response === void 0 ? void 0 : response.status,
137
121
  request: response === null || response === void 0 ? void 0 : response.request,
138
- response: response
122
+ response: response,
139
123
  });
140
124
  }
141
125
  }
@@ -146,13 +130,42 @@ export class WebPubSubServiceClient {
146
130
  /**
147
131
  * Close a specific connection to this hub
148
132
  *
149
- * @param connectionId Connection id to close
150
- * @param options Additional options
133
+ * @param connectionId - Connection id to close
134
+ * @param options - Additional options
151
135
  */
152
136
  async closeConnection(connectionId, options = {}) {
153
- const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-removeConnection", options);
137
+ const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeConnection", options);
138
+ try {
139
+ return await this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);
140
+ }
141
+ finally {
142
+ span.end();
143
+ }
144
+ }
145
+ /**
146
+ * Close all connections to this hub
147
+ *
148
+ * @param options - Additional options
149
+ */
150
+ async closeAllConnections(options = {}) {
151
+ const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeAllConnections", options);
152
+ try {
153
+ return await this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);
154
+ }
155
+ finally {
156
+ span.end();
157
+ }
158
+ }
159
+ /**
160
+ * Close all connections with the given user id
161
+ *
162
+ * @param user - User id to close
163
+ * @param options - Additional options
164
+ */
165
+ async closeUserConnections(userId, options = {}) {
166
+ const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-closeUserConnections", options);
154
167
  try {
155
- return await this.client.webPubSub.closeClientConnection(this.hubName, connectionId, updatedOptions);
168
+ return await this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);
156
169
  }
157
170
  finally {
158
171
  span.end();
@@ -160,8 +173,8 @@ export class WebPubSubServiceClient {
160
173
  }
161
174
  /**
162
175
  * Remove a specific user from all groups they are joined to
163
- * @param userId The user id to remove from all groups
164
- * @param options Additional options
176
+ * @param userId - The user id to remove from all groups
177
+ * @param options - Additional options
165
178
  */
166
179
  async removeUserFromAllGroups(userId, options = {}) {
167
180
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-removeUserFromAllGroups", options);
@@ -175,31 +188,31 @@ export class WebPubSubServiceClient {
175
188
  /**
176
189
  * Check if a particular group exists (i.e. has active connections).
177
190
  *
178
- * @param groupName The group name to check for
179
- * @param options Additional options
191
+ * @param groupName - The group name to check for
192
+ * @param options - Additional options
180
193
  */
181
- async hasGroup(groupName, options = {}) {
194
+ async groupExists(groupName, options = {}) {
182
195
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasGroup", options);
183
- try {
184
- let response;
185
- function onResponse(rawResponse, flatResponse) {
186
- response = rawResponse;
187
- if (updatedOptions.onResponse) {
188
- updatedOptions.onResponse(rawResponse, flatResponse);
189
- }
196
+ let response;
197
+ function onResponse(rawResponse, flatResponse) {
198
+ response = rawResponse;
199
+ if (updatedOptions.onResponse) {
200
+ updatedOptions.onResponse(rawResponse, flatResponse);
190
201
  }
202
+ }
203
+ try {
191
204
  await this.client.webPubSub.groupExists(this.hubName, groupName, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
192
- if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
205
+ if (response.status === 200) {
193
206
  return true;
194
207
  }
195
- else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
208
+ else if (response.status === 404) {
196
209
  return false;
197
210
  }
198
211
  else {
199
- throw new RestError(response === null || response === void 0 ? void 0 : response.bodyAsText, {
212
+ throw new RestError(response.bodyAsText, {
200
213
  statusCode: response === null || response === void 0 ? void 0 : response.status,
201
214
  request: response === null || response === void 0 ? void 0 : response.request,
202
- response: response
215
+ response: response,
203
216
  });
204
217
  }
205
218
  }
@@ -210,32 +223,32 @@ export class WebPubSubServiceClient {
210
223
  /**
211
224
  * Check if a particular user is connected to this hub.
212
225
  *
213
- * @param username The user name to check for
214
- * @param options Additional options
226
+ * @param username - The user name to check for
227
+ * @param options - Additional options
215
228
  */
216
- async hasUser(username, options = {}) {
229
+ async userExists(username, options = {}) {
217
230
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasUser", options);
218
- try {
219
- let response;
220
- function onResponse(rawResponse, flatResponse) {
221
- response = rawResponse;
222
- if (updatedOptions.onResponse) {
223
- updatedOptions.onResponse(rawResponse, flatResponse);
224
- }
231
+ let response;
232
+ function onResponse(rawResponse, flatResponse) {
233
+ response = rawResponse;
234
+ if (updatedOptions.onResponse) {
235
+ updatedOptions.onResponse(rawResponse, flatResponse);
225
236
  }
237
+ }
238
+ try {
226
239
  await this.client.webPubSub.userExists(this.hubName, username, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
227
- if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
240
+ if (response.status === 200) {
228
241
  return true;
229
242
  }
230
- else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
243
+ else if (response.status === 404) {
231
244
  return false;
232
245
  }
233
246
  else {
234
247
  // this is sad - wish this was handled by autorest.
235
- throw new RestError(response === null || response === void 0 ? void 0 : response.bodyAsText, {
248
+ throw new RestError(response.bodyAsText, {
236
249
  statusCode: response === null || response === void 0 ? void 0 : response.status,
237
250
  request: response === null || response === void 0 ? void 0 : response.request,
238
- response: response
251
+ response: response,
239
252
  });
240
253
  }
241
254
  }
@@ -246,9 +259,9 @@ export class WebPubSubServiceClient {
246
259
  /**
247
260
  * Grant permissions to a connection
248
261
  *
249
- * @param connectionId The connection id to grant permissions to
250
- * @param Permission The permission to grant
251
- * @param options Additional options
262
+ * @param connectionId - The connection id to grant permissions to
263
+ * @param Permission - The permission to grant
264
+ * @param options - Additional options
252
265
  */
253
266
  async grantPermission(connectionId, permission, options = {}) {
254
267
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-grantPermission", options);
@@ -262,9 +275,9 @@ export class WebPubSubServiceClient {
262
275
  /**
263
276
  * Revoke permissions from a connection
264
277
  *
265
- * @param connectionId The connection id to revoke permissions from
266
- * @param Permission The permission to revoke
267
- * @param options Additional options
278
+ * @param connectionId - The connection id to revoke permissions from
279
+ * @param Permission - The permission to revoke
280
+ * @param options - Additional options
268
281
  */
269
282
  async revokePermission(connectionId, permission, options = {}) {
270
283
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-revokePermission", options);
@@ -278,33 +291,33 @@ export class WebPubSubServiceClient {
278
291
  /**
279
292
  * Check if the connection has the specified permission
280
293
  *
281
- * @param connectionId The connection id to check permission
282
- * @param Permission The permission to check
283
- * @param options Additional options
294
+ * @param connectionId - The connection id to check permission
295
+ * @param Permission - The permission to check
296
+ * @param options - Additional options
284
297
  */
285
298
  async hasPermission(connectionId, permission, options = {}) {
286
299
  const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-hasPermission", options);
287
- try {
288
- let response;
289
- function onResponse(rawResponse, flatResponse) {
290
- response = rawResponse;
291
- if (updatedOptions.onResponse) {
292
- updatedOptions.onResponse(rawResponse, flatResponse);
293
- }
300
+ let response;
301
+ function onResponse(rawResponse, flatResponse) {
302
+ response = rawResponse;
303
+ if (updatedOptions.onResponse) {
304
+ updatedOptions.onResponse(rawResponse, flatResponse);
294
305
  }
306
+ }
307
+ try {
295
308
  await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
296
- if ((response === null || response === void 0 ? void 0 : response.status) === 200) {
309
+ if (response.status === 200) {
297
310
  return true;
298
311
  }
299
- else if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
312
+ else if (response.status === 404) {
300
313
  return false;
301
314
  }
302
315
  else {
303
316
  // this is sad - wish this was handled by autorest.
304
- throw new RestError(response === null || response === void 0 ? void 0 : response.bodyAsText, {
317
+ throw new RestError(response.bodyAsText, {
305
318
  statusCode: response === null || response === void 0 ? void 0 : response.status,
306
319
  request: response === null || response === void 0 ? void 0 : response.request,
307
- response: response
320
+ response: response,
308
321
  });
309
322
  }
310
323
  }
@@ -312,5 +325,47 @@ export class WebPubSubServiceClient {
312
325
  span.end();
313
326
  }
314
327
  }
328
+ /**
329
+ * Generate a token for a client to connect to the Azure Web PubSub service.
330
+ *
331
+ * @param options - Additional options
332
+ */
333
+ async getClientAccessToken(options = {}) {
334
+ const { span, updatedOptions } = createSpan("WebPubSubServiceClient-hub-generateClientToken", options);
335
+ try {
336
+ const endpoint = this.endpoint.endsWith("/") ? this.endpoint : this.endpoint + "/";
337
+ const clientEndpoint = endpoint.replace(/(http)(s?:\/\/)/gi, "ws$2");
338
+ const baseUrl = `${clientEndpoint}client/hubs/${this.hubName}`;
339
+ let token;
340
+ if (isTokenCredential(this.credential)) {
341
+ const response = await this.client.webPubSub.generateClientToken(this.hubName, updatedOptions);
342
+ token = response.token;
343
+ }
344
+ else {
345
+ const key = this.credential.key;
346
+ const audience = `${endpoint}client/hubs/${this.hubName}`;
347
+ const payload = { role: options === null || options === void 0 ? void 0 : options.roles };
348
+ const signOptions = {
349
+ audience: audience,
350
+ expiresIn: (options === null || options === void 0 ? void 0 : options.expirationTimeInMinutes) === undefined
351
+ ? "1h"
352
+ : `${options.expirationTimeInMinutes}m`,
353
+ algorithm: "HS256",
354
+ };
355
+ if (options === null || options === void 0 ? void 0 : options.userId) {
356
+ signOptions.subject = options === null || options === void 0 ? void 0 : options.userId;
357
+ }
358
+ token = jwt.sign(payload, key, signOptions);
359
+ }
360
+ return {
361
+ token,
362
+ baseUrl,
363
+ url: `${baseUrl}?access_token=${token}`,
364
+ };
365
+ }
366
+ finally {
367
+ span.end();
368
+ }
369
+ }
315
370
  }
316
371
  //# sourceMappingURL=hubClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hubClient.js","sourceRoot":"","sources":["../../src/hubClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAA2B,SAAS,EAAmB,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAkB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,yBAAyB,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAmK/C;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAyDjC,YACE,0BAAkC,EAClC,cAA4C,EAC5C,aAA8C,EAC9C,IAA4B;QApD9B;;WAEG;QACa,eAAU,GAAW,YAAY,CAAC;QAmDhD,+BAA+B;QAC/B,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,KAAK,IAAI,cAAc,EAAE;YACjE,IAAI,CAAC,QAAQ,GAAG,0BAA0B,CAAC;YAC3C,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC;YACjC,IAAI,CAAC,OAAO,GAA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,QAA2C,CAAC;YAChD,SAAS,UAAU,CAAC,WAAkC,EAAE,YAAqB;gBAC3E,QAAQ,GAAG,WAAW,CAAC;gBACvB,IAAI,cAAc,CAAC,UAAU,EAAE;oBAC7B,cAAc,CAAC,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;iBACtD;YACH,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,kCAC7E,cAAc,KACjB,UAAU,IACV,CAAC;YAEH,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG,EAAE;gBAC5B,OAAO,IAAI,CAAC;aACb;iBAAM,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG,EAAE;gBACnC,OAAO,KAAK,CAAC;aACd;iBAAM;gBACL,mDAAmD;gBACnD,MAAM,IAAI,SAAS,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAW,EAAE;oBACzC,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM;oBAC5B,OAAO,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO;oBAC1B,QAAQ,EAAE,QAAQ;iBACnB,CAAC,CAAC;aACJ;SACF;gBAAS;YACR,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CommonClientOptions, FullOperationResponse, OperationOptions } from \"@azure/core-client\";\nimport { InternalPipelineOptions, RestError, RequestBodyType } from \"@azure/core-rest-pipeline\";\nimport { GeneratedClient } from \"./generated/generatedClient\";\nimport { WebPubSubGroup, WebPubSubGroupImpl } from \"./groupClient\";\nimport normalizeSendToAllOptions from \"./normalizeOptions\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { webPubSubKeyCredentialPolicy } from \"./webPubSubCredentialPolicy\";\nimport { createSpan } from \"./tracing\";\nimport { logger } from \"./logger\";\nimport { parseConnectionString } from \"./parseConnectionString\";\nimport jwt from \"jsonwebtoken\";\nimport { getPayloadForMessage } from \"./utils\";\n\n/**\n * Options for closing a connection to a hub.\n */\nexport interface CloseConnectionOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for sending messages to hubs.\n */\nexport interface HubSendToAllOptions extends OperationOptions {\n /**\n * Connection ids to exclude from receiving this message.\n */\n excludedConnections?: string[];\n}\n\n/**\n * Options for sending text messages to hubs.\n */\nexport interface HubSendTextToAllOptions extends HubSendToAllOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Types which can be serialized and sent as JSON.\n */\nexport type JSONTypes = string | number | boolean | object;\n\n/**\n * Options for constructing a HubAdmin client.\n */\nexport interface HubAdminClientOptions extends CommonClientOptions {}\n\n/**\n * Options for checking if a connection exists.\n */\nexport interface HasConnectionOptions extends OperationOptions {}\n\n/**\n * Options for checking if a group exists.\n */\nexport interface HubHasGroupOptions extends OperationOptions {}\n\n/**\n * Options for checking if a user exists.\n */\nexport interface HubHasUserOptions extends OperationOptions {}\n\n/**\n * Options for removing a user from all groups.\n */\nexport interface HubRemoveUserFromAllGroupsOptions extends CloseConnectionOptions {}\n\n/**\n * Options for sending a message to a specific connection.\n */\nexport interface HubSendToConnectionOptions extends OperationOptions {}\n\n/**\n * Options for sending a text message to a connection.\n */\nexport interface HubSendTextToConnectionOptions extends HubSendToConnectionOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Options for sending a message to a user.\n */\nexport interface HubSendToUserOptions extends OperationOptions {}\n\n/**\n * Options for sending a text message to a user.\n */\nexport interface HubSendTextToUserOptions extends HubSendToUserOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Options for auth a client\n */\nexport interface GetAuthenticationTokenOptions {\n /**\n * The userId for the client\n */\n userId?: string;\n /**\n * The roles the client have.\n * Roles give the client initial permissions to leave, join, or publish to groups when using PubSub subprotocol\n * * `webpubsub.joinLeaveGroup`: the client can join or leave any group\n * * `webpubsub.sendToGroup`: the client can send messages to any group\n * * `webpubsub.joinLeaveGroup.<group>`: the client can join or leave group `<group>`\n * * `webpubsub.sendToGroup.<group>`: the client can send messages to group `<group>`\n *\n * {@link https://azure.github.io/azure-webpubsub/references/pubsub-websocket-subprotocol#permissions}\n */\n roles?: string[];\n /**\n * The time-to-live minutes for the access token. If not set, the default value is 60 minutes.\n */\n ttl?: number;\n}\n\n/**\n * Response for the authed client, including the url and the jwt token\n */\nexport interface GetAuthenticationTokenResponse {\n /**\n * The URL client connects to\n */\n baseUrl: string;\n\n /**\n * The JWT token the client uses to connect\n */\n token: string;\n\n /**\n * The URL client connects to with access_token query string\n */\n url: string;\n}\n\nexport type Permission = \"joinLeaveGroup\" | \"sendToGroup\";\n\n/**\n * Options for grant permissions to a connection\n */\nexport interface HubGrantPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for revoke permissions from a connection\n */\nexport interface HubRevokePermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for check if a connection has the specified permission\n */\nexport interface HubHasPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Client for connecting to a Web PubSub hub\n */\nexport class WebPubSubServiceClient {\n private readonly client: GeneratedClient;\n private credential!: AzureKeyCredential;\n private readonly clientOptions?: HubAdminClientOptions;\n\n /**\n * The name of the hub this client is connected to\n */\n public readonly hubName: string;\n /**\n * The Web PubSub API version being used by this client\n */\n public readonly apiVersion: string = \"2020-10-01\";\n\n /**\n * The Web PubSub endpoint this client is connected to\n */\n public endpoint!: string;\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient } from \"@azure/web-pubsub\";\n * const connectionString = process.env['WEB_PUBSUB_CONNECTION_STRING'];\n * const client = new WebPubSubServiceClient(connectionString, 'chat');\n * ```\n *\n * @param connectionString The connection string\n * @param hubName The name of the hub to connect to. If omitted, '_default' is used.\n * @param options Options to configure the http pipeline\n */\n constructor(connectionString: string, hubName: string, options?: HubAdminClientOptions);\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient, AzureKeyCredential } from \"@azure/web-pubsub\";\n * const cred = new AzureKeyCredential(\"<your web pubsub api key>\");\n * const endpoint = \"https://xxxx.webpubsubdev.azure.com\"\n * const client = new WebPubSubServiceClient(endpoint, cred, 'chat');\n * ```\n *\n * @param endpoint The endpoint to connect to\n * @param credential An AzureKeyCredential holding your service key\n * @param hubName The name of the hub to connect to.\n * @param options Options to configure the http pipeline\n */\n constructor(\n endpoint: string,\n credential: AzureKeyCredential,\n hubName: string,\n options?: HubAdminClientOptions\n );\n constructor(\n endpointOrConnectionString: string,\n credsOrHubName?: AzureKeyCredential | string,\n hubNameOrOpts?: string | HubAdminClientOptions,\n opts?: HubAdminClientOptions\n ) {\n // unpack constructor arguments\n if (typeof credsOrHubName === \"object\" && \"key\" in credsOrHubName) {\n this.endpoint = endpointOrConnectionString;\n this.credential = credsOrHubName;\n this.hubName = hubNameOrOpts as string;\n this.clientOptions = opts;\n } else {\n const parsedCs = parseConnectionString(endpointOrConnectionString);\n this.endpoint = parsedCs.endpoint;\n this.credential = parsedCs.credential;\n this.hubName = credsOrHubName as string;\n this.clientOptions = hubNameOrOpts as HubAdminClientOptions;\n }\n\n const internalPipelineOptions: InternalPipelineOptions = {\n ...this.clientOptions,\n ...{\n loggingOptions: {\n logger: logger.info\n }\n }\n };\n\n this.client = new GeneratedClient(this.endpoint, internalPipelineOptions);\n this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));\n }\n\n /**\n * Auth the client connection with userId and custom claims if any\n * @param options The options that the client has\n */\n public async getAuthenticationToken(\n options?: GetAuthenticationTokenOptions\n ): Promise<GetAuthenticationTokenResponse> {\n const endpoint = this.endpoint.endsWith(\"/\") ? this.endpoint : this.endpoint + \"/\";\n const key = this.credential.key;\n const hub = this.hubName;\n const clientEndpoint = endpoint.replace(/(http)(s?:\\/\\/)/gi, \"ws$2\");\n const clientUrl = `${clientEndpoint}client/hubs/${hub}`;\n const audience = `${endpoint}client/hubs/${hub}`;\n const payload = { role: options?.roles };\n const signOptions: jwt.SignOptions = {\n audience: audience,\n expiresIn: options?.ttl === undefined ? \"1h\" : `${options.ttl}m`,\n algorithm: \"HS256\"\n };\n if (options?.userId) {\n signOptions.subject = options?.userId;\n }\n const token = jwt.sign(payload, key, signOptions);\n const url = `${clientUrl}?access_token=${token}`;\n return {\n baseUrl: clientUrl,\n token: jwt.sign(payload, key, signOptions),\n url: url\n };\n }\n\n /**\n * Get a client for a group\n * @param groupName The name of the group to connect to.\n */\n public group(groupName: string): WebPubSubGroup {\n return new WebPubSubGroupImpl(this.client, this.hubName, groupName);\n }\n\n /**\n * Broadcast a text message to all connections on this hub.\n *\n * @param message The text message to send\n * @param options Additional options\n */\n public async sendToAll(message: string, options: HubSendTextToAllOptions): Promise<void>;\n /**\n * Broadcast a JSON message to all connections on this hub.\n *\n * @param message The JSON message to send\n * @param options Additional options\n */\n public async sendToAll(message: JSONTypes, options?: HubSendToAllOptions): Promise<void>;\n /**\n * Broadcast a binary message to all connections on this hub.\n *\n * @param message The message to send\n * @param options Additional options\n */\n public async sendToAll(message: RequestBodyType, options?: HubSendToAllOptions): Promise<void>;\n\n public async sendToAll(\n message: RequestBodyType | JSONTypes,\n options: HubSendToAllOptions | HubSendTextToAllOptions = {}\n ): Promise<void> {\n const normalizedOptions = normalizeSendToAllOptions(options);\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-sendToAll\",\n normalizedOptions\n );\n\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToAll(\n this.hubName,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Send a text message to a specific user\n *\n * @param username User name to send to\n * @param message The text message to send\n * @param options Additional options\n */\n public async sendToUser(\n username: string,\n message: string,\n options: HubSendTextToUserOptions\n ): Promise<void>;\n\n /**\n * Send a JSON message to a specific user\n *\n * @param username User name to send to\n * @param message The josn message to send\n * @param options Additional options\n */\n public async sendToUser(\n username: string,\n message: JSONTypes,\n options?: HubSendToUserOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific user\n *\n * @param username The user name to send to\n * @param message The binary message to send\n * @param options Additional options\n */\n public async sendToUser(\n username: string,\n message: RequestBodyType,\n options?: HubSendToUserOptions | HubSendTextToUserOptions\n ): Promise<void>;\n public async sendToUser(\n username: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToUserOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-sendToUser\", options);\n\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n try {\n return await this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Send a text message to a specific connection\n *\n * @param connectionId Connection id to send to\n * @param message The text message\n * @param options Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: string,\n options: HubSendTextToConnectionOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId Connection id to send to\n * @param message The JSON message\n * @param options Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: JSONTypes,\n options?: HubSendToConnectionOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId Connection id to send to\n * @param message The binary message\n * @param options Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType,\n options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions\n ): Promise<void>;\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-sendToConnection\",\n options\n );\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a specific connection is connected to this hub\n *\n * @param connectionId Connection id to check\n * @param options Additional options\n */\n public async hasConnection(\n connectionId: string,\n options: HasConnectionOptions = {}\n ): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-hasConnection\",\n options\n );\n\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n\n await this.client.webPubSub.connectionExists(this.hubName, connectionId, {\n ...updatedOptions,\n onResponse\n });\n\n if (response?.status === 200) {\n return true;\n } else if (response?.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response?.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Close a specific connection to this hub\n *\n * @param connectionId Connection id to close\n * @param options Additional options\n */\n public async closeConnection(\n connectionId: string,\n options: CloseConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-removeConnection\",\n options\n );\n\n try {\n return await this.client.webPubSub.closeClientConnection(\n this.hubName,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Remove a specific user from all groups they are joined to\n * @param userId The user id to remove from all groups\n * @param options Additional options\n */\n public async removeUserFromAllGroups(\n userId: string,\n options: CloseConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-removeUserFromAllGroups\",\n options\n );\n\n try {\n await this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a particular group exists (i.e. has active connections).\n *\n * @param groupName The group name to check for\n * @param options Additional options\n */\n public async hasGroup(groupName: string, options: HubHasGroupOptions = {}): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-hasGroup\", options);\n\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n await this.client.webPubSub.groupExists(this.hubName, groupName, {\n ...updatedOptions,\n onResponse\n });\n\n if (response?.status === 200) {\n return true;\n } else if (response?.status === 404) {\n return false;\n } else {\n throw new RestError(response?.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a particular user is connected to this hub.\n *\n * @param username The user name to check for\n * @param options Additional options\n */\n public async hasUser(username: string, options: HubHasUserOptions = {}): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-hasUser\", options);\n\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n await this.client.webPubSub.userExists(this.hubName, username, {\n ...updatedOptions,\n onResponse\n });\n\n if (response?.status === 200) {\n return true;\n } else if (response?.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response?.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Grant permissions to a connection\n *\n * @param connectionId The connection id to grant permissions to\n * @param Permission The permission to grant\n * @param options Additional options\n */\n public async grantPermission(\n connectionId: string,\n permission: Permission,\n options: HubGrantPermissionOptions = {}\n ) {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-grantPermission\",\n options\n );\n\n try {\n return await this.client.webPubSub.grantPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Revoke permissions from a connection\n *\n * @param connectionId The connection id to revoke permissions from\n * @param Permission The permission to revoke\n * @param options Additional options\n */\n public async revokePermission(\n connectionId: string,\n permission: Permission,\n options: HubRevokePermissionOptions = {}\n ) {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-revokePermission\",\n options\n );\n\n try {\n return await this.client.webPubSub.revokePermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if the connection has the specified permission\n *\n * @param connectionId The connection id to check permission\n * @param Permission The permission to check\n * @param options Additional options\n */\n public async hasPermission(\n connectionId: string,\n permission: Permission,\n options: HubHasPermissionOptions = {}\n ): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-hasPermission\",\n options\n );\n\n try {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, {\n ...updatedOptions,\n onResponse\n });\n\n if (response?.status === 200) {\n return true;\n } else if (response?.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response?.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response\n });\n }\n } finally {\n span.end();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"hubClient.js","sourceRoot":"","sources":["../../src/hubClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAmB,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAkB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAuC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AA6LnE;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAyDjC,YACE,0BAAkC,EAClC,cAA8D,EAC9D,aAAsD,EACtD,IAAoC;;QApDtC;;WAEG;QACa,eAAU,GAAW,YAAY,CAAC;QAmDhD,+BAA+B;QAC/B,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;YACtC,IAAI,CAAC,QAAQ,GAAG,0BAA0B,CAAC;YAC3C,IAAI,CAAC,OAAO,GAAG,aAAuB,CAAC;YACvC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC;SAClC;aAAM;YACL,MAAM,QAAQ,GAAG,qBAAqB,CAAC,0BAA0B,CAAC,CAAC;YACnE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QA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,CAAE,uBAAuB,MAAK,SAAS;wBAC5C,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,GAAG,OAAO,CAAC,uBAAuB,GAAG;oBAC3C,SAAS,EAAE,OAAO;iBACnB,CAAC;gBACF,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAE;oBACnB,WAAW,CAAC,OAAO,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;iBACvC;gBACD,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;aAC7C;YAED,OAAO;gBACL,KAAK;gBACL,OAAO;gBACP,GAAG,EAAE,GAAG,OAAO,iBAAiB,KAAK,EAAE;aACxC,CAAC;SACH;gBAAS;YACR,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CommonClientOptions, FullOperationResponse, OperationOptions } from \"@azure/core-client\";\nimport { RestError, RequestBodyType } from \"@azure/core-rest-pipeline\";\nimport { GeneratedClient } from \"./generated/generatedClient\";\nimport { WebPubSubGroup, WebPubSubGroupImpl } from \"./groupClient\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { webPubSubKeyCredentialPolicy } from \"./webPubSubCredentialPolicy\";\nimport { createSpan } from \"./tracing\";\nimport { logger } from \"./logger\";\nimport { parseConnectionString } from \"./parseConnectionString\";\nimport jwt from \"jsonwebtoken\";\nimport { getPayloadForMessage } from \"./utils\";\nimport { GeneratedClientOptionalParams } from \"./generated\";\nimport { webPubSubReverseProxyPolicy } from \"./reverseProxyPolicy\";\n\n/**\n * Options for closing a connection to a hub.\n */\nexport interface HubCloseConnectionOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for closing all connections to a hub.\n */\nexport interface HubCloseAllConnectionsOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for closing all of a user's connections to a hub.\n */\nexport interface HubCloseUserConnectionsOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for sending messages to hubs.\n */\nexport interface HubSendToAllOptions extends OperationOptions {\n /**\n * Connection ids to exclude from receiving this message.\n */\n excludedConnections?: string[];\n}\n\n/**\n * Options for sending text messages to hubs.\n */\nexport interface HubSendTextToAllOptions extends HubSendToAllOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Types which can be serialized and sent as JSON.\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type JSONTypes = string | number | boolean | object;\n\n/**\n * Options for constructing a HubAdmin client.\n */\nexport interface WebPubSubServiceClientOptions extends CommonClientOptions {\n /**\n * Reverse proxy endpoint (for example, your Azure API management endpoint)\n */\n reverseProxyEndpoint?: string;\n}\n\n/**\n * Options for checking if a connection exists.\n */\nexport interface HasConnectionOptions extends OperationOptions {}\n\n/**\n * Options for checking if a group exists.\n */\nexport interface HubHasGroupOptions extends OperationOptions {}\n\n/**\n * Options for checking if a user exists.\n */\nexport interface HubHasUserOptions extends OperationOptions {}\n\n/**\n * Options for removing a user from all groups.\n */\nexport interface HubRemoveUserFromAllGroupsOptions extends HubCloseConnectionOptions {}\n\n/**\n * Options for sending a message to a specific connection.\n */\nexport interface HubSendToConnectionOptions extends OperationOptions {}\n\n/**\n * Options for sending a text message to a connection.\n */\nexport interface HubSendTextToConnectionOptions extends HubSendToConnectionOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Options for sending a message to a user.\n */\nexport interface HubSendToUserOptions extends OperationOptions {}\n\n/**\n * Options for sending a text message to a user.\n */\nexport interface HubSendTextToUserOptions extends HubSendToUserOptions {\n contentType: \"text/plain\";\n}\n\nexport type Permission = \"joinLeaveGroup\" | \"sendToGroup\";\n\n/**\n * Options for grant permissions to a connection\n */\nexport interface HubGrantPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for revoke permissions from a connection\n */\nexport interface HubRevokePermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for checking if a connection has the specified permission\n */\nexport interface HubHasPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for generating a token to connect a client to the Azure Web Pubsub service.\n */\nexport interface GenerateClientTokenOptions extends OperationOptions {\n /**\n * The userId for the client.\n */\n userId?: string;\n\n /**\n * The roles that the connection with the generated token will have.\n * Roles give the client initial permissions to leave, join, or publish to groups when using PubSub subprotocol\n * * `webpubsub.joinLeaveGroup`: the client can join or leave any group\n * * `webpubsub.sendToGroup`: the client can send messages to any group\n * * `webpubsub.joinLeaveGroup.<group>`: the client can join or leave group `<group>`\n * * `webpubsub.sendToGroup.<group>`: the client can send messages to group `<group>`\n *\n * {@link https://azure.github.io/azure-webpubsub/references/pubsub-websocket-subprotocol#permissions}\n */\n roles?: string[];\n\n /**\n * Minutes until the token expires.\n */\n expirationTimeInMinutes?: number;\n}\n\n/**\n * A response containing the client token.\n */\nexport interface ClientTokenResponse {\n /**\n * The client token.\n */\n token: string;\n /**\n * The URL client connects to\n */\n baseUrl: string;\n /**\n * The URL client connects to with access_token query string\n */\n url: string;\n}\n\n/**\n * Client for connecting to a Web PubSub hub\n */\nexport class WebPubSubServiceClient {\n private readonly client: GeneratedClient;\n private credential!: AzureKeyCredential | TokenCredential;\n private readonly clientOptions?: WebPubSubServiceClientOptions;\n\n /**\n * The name of the hub this client is connected to\n */\n public readonly hubName: string;\n /**\n * The Web PubSub API version being used by this client\n */\n public readonly apiVersion: string = \"2021-10-01\";\n\n /**\n * The Web PubSub endpoint this client is connected to\n */\n public endpoint!: string;\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient } from \"@azure/web-pubsub\";\n * const connectionString = process.env['WEB_PUBSUB_CONNECTION_STRING'];\n * const client = new WebPubSubServiceClient(connectionString, 'chat');\n * ```\n *\n * @param connectionString - The connection string\n * @param hubName - The name of the hub to connect to. If omitted, '_default' is used.\n * @param options - Options to configure the http pipeline\n */\n constructor(connectionString: string, hubName: string, options?: WebPubSubServiceClientOptions);\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient, AzureKeyCredential } from \"@azure/web-pubsub\";\n * const cred = new AzureKeyCredential(\"<your web pubsub api key>\");\n * const endpoint = \"https://xxxx.webpubsubdev.azure.com\"\n * const client = new WebPubSubServiceClient(endpoint, cred, 'chat');\n * ```\n *\n * @param endpoint - The endpoint to connect to\n * @param credential - An AzureKeyCredential holding your service key\n * @param hubName - The name of the hub to connect to.\n * @param options - Options to configure the http pipeline\n */\n constructor(\n endpoint: string,\n credential: AzureKeyCredential | TokenCredential,\n hubName: string,\n options?: WebPubSubServiceClientOptions\n );\n constructor(\n endpointOrConnectionString: string,\n credsOrHubName?: AzureKeyCredential | TokenCredential | string,\n hubNameOrOpts?: string | WebPubSubServiceClientOptions,\n opts?: WebPubSubServiceClientOptions\n ) {\n // unpack constructor arguments\n if (typeof credsOrHubName === \"object\") {\n this.endpoint = endpointOrConnectionString;\n this.hubName = hubNameOrOpts as string;\n this.clientOptions = opts;\n this.credential = credsOrHubName;\n } else {\n const parsedCs = parseConnectionString(endpointOrConnectionString);\n this.endpoint = parsedCs.endpoint;\n this.credential = parsedCs.credential;\n this.hubName = credsOrHubName as string;\n this.clientOptions = hubNameOrOpts as WebPubSubServiceClientOptions;\n }\n\n const internalPipelineOptions: GeneratedClientOptionalParams = {\n ...this.clientOptions,\n ...{\n apiVersion: this.apiVersion,\n loggingOptions: {\n logger: logger.info,\n },\n },\n ...(isTokenCredential(this.credential)\n ? {\n credential: this.credential,\n credentialScopes: [\"https://webpubsub.azure.com/.default\"],\n }\n : {}),\n };\n\n this.client = new GeneratedClient(this.endpoint, internalPipelineOptions);\n\n if (!isTokenCredential(this.credential)) {\n this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));\n }\n\n if (this.clientOptions?.reverseProxyEndpoint) {\n this.client.pipeline.addPolicy(\n webPubSubReverseProxyPolicy(this.clientOptions?.reverseProxyEndpoint)\n );\n }\n }\n\n /**\n * Get a client for a group\n * @param groupName - The name of the group to connect to.\n */\n public group(groupName: string): WebPubSubGroup {\n return new WebPubSubGroupImpl(this.client, this.hubName, groupName);\n }\n\n /**\n * Broadcast a text message to all connections on this hub.\n *\n * @param message - The text message to send\n * @param options - Additional options\n */\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n public async sendToAll(message: string, options: HubSendTextToAllOptions): Promise<void>;\n /**\n * Broadcast a JSON message to all connections on this hub.\n *\n * @param message - The JSON message to send\n * @param options - Additional options\n */\n public async sendToAll(message: JSONTypes, options?: HubSendToAllOptions): Promise<void>;\n /**\n * Broadcast a binary message to all connections on this hub.\n *\n * @param message - The message to send\n * @param options - Additional options\n */\n public async sendToAll(message: RequestBodyType, options?: HubSendToAllOptions): Promise<void>;\n\n public async sendToAll(\n message: RequestBodyType | JSONTypes,\n options: HubSendToAllOptions | HubSendTextToAllOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-sendToAll\", options);\n\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToAll(\n this.hubName,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Send a text message to a specific user\n *\n * @param username - User name to send to\n * @param message - The text message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: HubSendTextToUserOptions\n ): Promise<void>;\n\n /**\n * Send a JSON message to a specific user\n *\n * @param username - User name to send to\n * @param message - The josn message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: JSONTypes,\n options?: HubSendToUserOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific user\n *\n * @param username - The user name to send to\n * @param message - The binary message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: RequestBodyType,\n options?: HubSendToUserOptions | HubSendTextToUserOptions\n ): Promise<void>;\n public async sendToUser(\n username: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToUserOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-sendToUser\", options);\n\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n try {\n return await this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Send a text message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The text message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: HubSendTextToConnectionOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The JSON message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: JSONTypes,\n options?: HubSendToConnectionOptions\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The binary message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType,\n options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions\n ): Promise<void>;\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-sendToConnection\",\n options\n );\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType,\n payload as any,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a specific connection is connected to this hub\n *\n * @param connectionId - Connection id to check\n * @param options - Additional options\n */\n public async connectionExists(\n connectionId: string,\n options: HasConnectionOptions = {}\n ): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-hasConnection\",\n options\n );\n\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n\n try {\n await this.client.webPubSub.connectionExists(this.hubName, connectionId, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Close a specific connection to this hub\n *\n * @param connectionId - Connection id to close\n * @param options - Additional options\n */\n public async closeConnection(\n connectionId: string,\n options: HubCloseConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-closeConnection\",\n options\n );\n\n try {\n return await this.client.webPubSub.closeConnection(\n this.hubName,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Close all connections to this hub\n *\n * @param options - Additional options\n */\n public async closeAllConnections(options: HubCloseAllConnectionsOptions = {}): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-closeAllConnections\",\n options\n );\n\n try {\n return await this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);\n } finally {\n span.end();\n }\n }\n\n /**\n * Close all connections with the given user id\n *\n * @param user - User id to close\n * @param options - Additional options\n */\n public async closeUserConnections(\n userId: string,\n options: HubCloseUserConnectionsOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-closeUserConnections\",\n options\n );\n\n try {\n return await this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);\n } finally {\n span.end();\n }\n }\n\n /**\n * Remove a specific user from all groups they are joined to\n * @param userId - The user id to remove from all groups\n * @param options - Additional options\n */\n public async removeUserFromAllGroups(\n userId: string,\n options: HubCloseConnectionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-removeUserFromAllGroups\",\n options\n );\n\n try {\n await this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a particular group exists (i.e. has active connections).\n *\n * @param groupName - The group name to check for\n * @param options - Additional options\n */\n public async groupExists(groupName: string, options: HubHasGroupOptions = {}): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-hasGroup\", options);\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n\n try {\n await this.client.webPubSub.groupExists(this.hubName, groupName, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if a particular user is connected to this hub.\n *\n * @param username - The user name to check for\n * @param options - Additional options\n */\n public async userExists(username: string, options: HubHasUserOptions = {}): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-hasUser\", options);\n\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n\n try {\n await this.client.webPubSub.userExists(this.hubName, username, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Grant permissions to a connection\n *\n * @param connectionId - The connection id to grant permissions to\n * @param Permission - The permission to grant\n * @param options - Additional options\n */\n public async grantPermission(\n connectionId: string,\n permission: Permission,\n options: HubGrantPermissionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-grantPermission\",\n options\n );\n\n try {\n return await this.client.webPubSub.grantPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Revoke permissions from a connection\n *\n * @param connectionId - The connection id to revoke permissions from\n * @param Permission - The permission to revoke\n * @param options - Additional options\n */\n public async revokePermission(\n connectionId: string,\n permission: Permission,\n options: HubRevokePermissionOptions = {}\n ): Promise<void> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-revokePermission\",\n options\n );\n\n try {\n return await this.client.webPubSub.revokePermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n } finally {\n span.end();\n }\n }\n\n /**\n * Check if the connection has the specified permission\n *\n * @param connectionId - The connection id to check permission\n * @param Permission - The permission to check\n * @param options - Additional options\n */\n public async hasPermission(\n connectionId: string,\n permission: Permission,\n options: HubHasPermissionOptions = {}\n ): Promise<boolean> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-hasPermission\",\n options\n );\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (updatedOptions.onResponse) {\n updatedOptions.onResponse(rawResponse, flatResponse);\n }\n }\n\n try {\n await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n } finally {\n span.end();\n }\n }\n\n /**\n * Generate a token for a client to connect to the Azure Web PubSub service.\n *\n * @param options - Additional options\n */\n public async getClientAccessToken(\n options: GenerateClientTokenOptions = {}\n ): Promise<ClientTokenResponse> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-generateClientToken\",\n options\n );\n\n try {\n const endpoint = this.endpoint.endsWith(\"/\") ? this.endpoint : this.endpoint + \"/\";\n const clientEndpoint = endpoint.replace(/(http)(s?:\\/\\/)/gi, \"ws$2\");\n const baseUrl = `${clientEndpoint}client/hubs/${this.hubName}`;\n\n let token: string;\n if (isTokenCredential(this.credential)) {\n const response = await this.client.webPubSub.generateClientToken(\n this.hubName,\n updatedOptions\n );\n token = response.token!;\n } else {\n const key = this.credential.key;\n const audience = `${endpoint}client/hubs/${this.hubName}`;\n const payload = { role: options?.roles };\n const signOptions: jwt.SignOptions = {\n audience: audience,\n expiresIn:\n options?.expirationTimeInMinutes === undefined\n ? \"1h\"\n : `${options.expirationTimeInMinutes}m`,\n algorithm: \"HS256\",\n };\n if (options?.userId) {\n signOptions.subject = options?.userId;\n }\n token = jwt.sign(payload, key, signOptions);\n }\n\n return {\n token,\n baseUrl,\n url: `${baseUrl}?access_token=${token}`,\n };\n } finally {\n span.end();\n }\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  export { AzureKeyCredential } from "@azure/core-auth";
4
- export { WebPubSubServiceClient } from "./hubClient";
4
+ export { WebPubSubServiceClient, } from "./hubClient";
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,sBAAsB,EAoBvB,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nexport { AzureKeyCredential } from \"@azure/core-auth\";\nexport {\n WebPubSubServiceClient,\n GetAuthenticationTokenOptions,\n GetAuthenticationTokenResponse,\n HubSendToAllOptions,\n CloseConnectionOptions,\n HasConnectionOptions,\n HubHasGroupOptions,\n HubHasUserOptions,\n HubAdminClientOptions,\n HubRemoveUserFromAllGroupsOptions,\n HubSendToConnectionOptions,\n HubSendToUserOptions,\n HubGrantPermissionOptions,\n HubRevokePermissionOptions,\n HubHasPermissionOptions,\n HubSendTextToAllOptions,\n HubSendTextToConnectionOptions,\n HubSendTextToUserOptions,\n JSONTypes,\n Permission\n} from \"./hubClient\";\nexport {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupAddUserOptions,\n GroupAdminClientOptions,\n GroupHasUserOptions,\n GroupRemoveConnectionOptions,\n GroupRemoveUserOptions,\n GroupSendTextToAllOptions,\n GroupSendToAllOptions\n} from \"./groupClient\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,sBAAsB,GAsBvB,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nexport { AzureKeyCredential } from \"@azure/core-auth\";\nexport {\n WebPubSubServiceClient,\n HubSendToAllOptions,\n ClientTokenResponse,\n HubCloseConnectionOptions,\n HubCloseAllConnectionsOptions,\n HubCloseUserConnectionsOptions,\n GenerateClientTokenOptions,\n HasConnectionOptions,\n HubHasGroupOptions,\n HubHasUserOptions,\n WebPubSubServiceClientOptions,\n HubRemoveUserFromAllGroupsOptions,\n HubSendToConnectionOptions,\n HubSendToUserOptions,\n HubGrantPermissionOptions,\n HubRevokePermissionOptions,\n HubHasPermissionOptions,\n HubSendTextToAllOptions,\n HubSendTextToConnectionOptions,\n HubSendTextToUserOptions,\n JSONTypes,\n Permission,\n} from \"./hubClient\";\nexport {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupCloseAllConnectionsOptions,\n GroupAddUserOptions,\n GroupAdminClientOptions,\n GroupHasUserOptions,\n GroupRemoveConnectionOptions,\n GroupRemoveUserOptions,\n GroupSendTextToAllOptions,\n GroupSendToAllOptions,\n} from \"./groupClient\";\n"]}
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT license.
3
3
  import { createClientLogger } from "@azure/logger";
4
4
  /**
5
- * The @azure/logger configuration for this package.
5
+ * The `@azure/logger` configuration for this package.
6
6
  */
7
7
  export const logger = createClientLogger("web-pubsub");
8
8
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The @azure/logger configuration for this package.\n */\nexport const logger = createClientLogger(\"web-pubsub\");\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n */\nexport const logger = createClientLogger(\"web-pubsub\");\n"]}
@@ -1,7 +1,9 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
1
3
  import { AzureKeyCredential } from "@azure/core-auth";
2
4
  import { URL } from "./util/url";
3
5
  export function parseConnectionString(conn) {
4
- let parsed = {};
6
+ const parsed = {};
5
7
  conn.split(";").forEach((i) => {
6
8
  const assignmentPos = i.indexOf("=");
7
9
  if (assignmentPos === -1)