@azure/web-pubsub 1.0.0-beta.2 → 1.0.1-alpha.20211215.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +118 -31
  3. package/dist/index.js +1315 -567
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/samples-dev/broadcasting.js +16 -16
  6. package/dist-esm/samples-dev/broadcasting.js.map +1 -1
  7. package/dist-esm/samples-dev/directMessage.js +9 -9
  8. package/dist-esm/samples-dev/directMessage.js.map +1 -1
  9. package/dist-esm/samples-dev/managingGroups.js +11 -12
  10. package/dist-esm/samples-dev/managingGroups.js.map +1 -1
  11. package/dist-esm/src/generated/generatedClient.js +23 -0
  12. package/dist-esm/src/generated/generatedClient.js.map +1 -0
  13. package/dist-esm/src/generated/generatedClientContext.js +41 -0
  14. package/dist-esm/src/generated/generatedClientContext.js.map +1 -0
  15. package/dist-esm/src/generated/index.js +10 -2
  16. package/dist-esm/src/generated/index.js.map +1 -1
  17. package/dist-esm/src/generated/models/index.js +13 -1
  18. package/dist-esm/src/generated/models/index.js.map +1 -1
  19. package/dist-esm/src/generated/models/mappers.js +368 -0
  20. package/dist-esm/src/generated/models/mappers.js.map +1 -0
  21. package/dist-esm/src/generated/models/parameters.js +124 -43
  22. package/dist-esm/src/generated/models/parameters.js.map +1 -1
  23. package/dist-esm/src/generated/operations/healthApi.js +16 -11
  24. package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
  25. package/dist-esm/src/generated/operations/index.js +7 -0
  26. package/dist-esm/src/generated/operations/index.js.map +1 -1
  27. package/dist-esm/src/generated/operations/webPubSub.js +341 -175
  28. package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
  29. package/dist-esm/src/generated/operationsInterfaces/healthApi.js +9 -0
  30. package/dist-esm/src/generated/operationsInterfaces/healthApi.js.map +1 -0
  31. package/dist-esm/src/generated/operationsInterfaces/index.js +10 -0
  32. package/dist-esm/src/generated/operationsInterfaces/index.js.map +1 -0
  33. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js +9 -0
  34. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -0
  35. package/dist-esm/src/groupClient.js +74 -92
  36. package/dist-esm/src/groupClient.js.map +1 -1
  37. package/dist-esm/src/hubClient.js +280 -196
  38. package/dist-esm/src/hubClient.js.map +1 -1
  39. package/dist-esm/src/index.js.map +1 -1
  40. package/dist-esm/src/logger.js +1 -1
  41. package/dist-esm/src/logger.js.map +1 -1
  42. package/dist-esm/src/parseConnectionString.js +3 -1
  43. package/dist-esm/src/parseConnectionString.js.map +1 -1
  44. package/dist-esm/src/reverseProxyPolicy.js +21 -0
  45. package/dist-esm/src/reverseProxyPolicy.js.map +1 -0
  46. package/dist-esm/src/utils.js +8 -6
  47. package/dist-esm/src/utils.js.map +1 -1
  48. package/dist-esm/src/webPubSubCredentialPolicy.js +18 -18
  49. package/dist-esm/src/webPubSubCredentialPolicy.js.map +1 -1
  50. package/dist-esm/test/conn.spec.js +7 -8
  51. package/dist-esm/test/conn.spec.js.map +1 -1
  52. package/dist-esm/test/groups.spec.js +39 -38
  53. package/dist-esm/test/groups.spec.js.map +1 -1
  54. package/dist-esm/test/hubs.spec.js +95 -49
  55. package/dist-esm/test/hubs.spec.js.map +1 -1
  56. package/dist-esm/test/integration.spec.js +128 -0
  57. package/dist-esm/test/integration.spec.js.map +1 -0
  58. package/dist-esm/test/testEnv.js +5 -1
  59. package/dist-esm/test/testEnv.js.map +1 -1
  60. package/package.json +37 -36
  61. package/types/web-pubsub.d.ts +186 -138
  62. package/dist-esm/src/generated/azureWebPubSubServiceRestAPI.js +0 -15
  63. package/dist-esm/src/generated/azureWebPubSubServiceRestAPI.js.map +0 -1
  64. package/dist-esm/src/generated/azureWebPubSubServiceRestAPIContext.js +0 -34
  65. package/dist-esm/src/generated/azureWebPubSubServiceRestAPIContext.js.map +0 -1
  66. package/dist-esm/src/normalizeOptions.js +0 -8
  67. package/dist-esm/src/normalizeOptions.js.map +0 -1
@@ -1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mC,EAAE;;YAErC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,UAAU,CACzC,0CAA0C,EAC1C,OAAO,CACR,CAAC;YAEF,IAAI;gBACF,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAChD,IAAI,CAAC,OAAO,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,CACf,CAAC;aACH;oBAAS;gBACR,IAAI,CAAC,GAAG,EAAE,CAAC;aACZ;QACH,CAAC;KAAA;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n OperationOptions,\n RestResponse,\n RestError,\n HttpRequestBody,\n InternalPipelineOptions,\n createPipelineFromOptions,\n PipelineOptions\n} from \"@azure/core-http\";\nimport { AzureWebPubSubServiceRestAPI as GeneratedClient } from \"./generated/azureWebPubSubServiceRestAPI\";\nimport { WebPubSubGroup, WebPubSubGroupImpl } from \"./groupClient\";\nimport normalizeSendToAllOptions from \"./normalizeOptions\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { webPubSubAzureKeyCredentialPolicyFactory } from \"./webPubSubCredentialPolicy\";\nimport { createSpan } from \"./tracing\";\nimport { logger } from \"./logger\";\nimport { parseConnectionString } from \"./parseConnectionString\";\nimport jwt from \"jsonwebtoken\";\nimport { getContentTypeForMessage } 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 PipelineOptions {}\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 PipelineOptions;\n }\n\n const internalPipelineOptions: InternalPipelineOptions = {\n ...this.clientOptions,\n ...{\n loggingOptions: {\n logger: logger.info\n }\n }\n };\n\n const pipeline = createPipelineFromOptions(\n internalPipelineOptions,\n webPubSubAzureKeyCredentialPolicyFactory(this.credential)\n );\n\n this.client = new GeneratedClient(this.endpoint, pipeline);\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<RestResponse>;\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<RestResponse>;\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(\n message: HttpRequestBody,\n options?: HubSendToAllOptions\n ): Promise<RestResponse>;\n\n public async sendToAll(\n message: HttpRequestBody | string,\n options: HubSendToAllOptions | HubSendTextToAllOptions = {}\n ): Promise<RestResponse> {\n const normalizedOptions = normalizeSendToAllOptions(options);\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-sendToAll\",\n normalizedOptions\n );\n\n const contentType = getContentTypeForMessage(message, updatedOptions);\n try {\n return await this.client.webPubSub.sendToAll(\n this.hubName,\n contentType as any,\n contentType === \"application/json\" ? JSON.stringify(message) : message,\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<RestResponse>;\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<RestResponse>;\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: HttpRequestBody,\n options?: HubSendToUserOptions | HubSendTextToUserOptions\n ): Promise<RestResponse>;\n public async sendToUser(\n username: string,\n message: string | HttpRequestBody,\n options: HubSendToUserOptions = {}\n ): Promise<RestResponse> {\n const { span, updatedOptions } = createSpan(\"WebPubSubServiceClient-hub-sendToUser\", options);\n\n const contentType = getContentTypeForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType as any,\n contentType === \"application/json\" ? JSON.stringify(message) : message,\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<RestResponse>;\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<RestResponse>;\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: HttpRequestBody | JSONTypes,\n options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions\n ): Promise<RestResponse>;\n public async sendToConnection(\n connectionId: string,\n message: string | HttpRequestBody,\n options: HubSendToConnectionOptions = {}\n ): Promise<RestResponse> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-sendToConnection\",\n options\n );\n const contentType = getContentTypeForMessage(message, updatedOptions);\n\n try {\n return await this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType as any,\n contentType === \"application/json\" ? JSON.stringify(message) : message,\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 const res = await this.client.webPubSub.connectionExists(\n this.hubName,\n connectionId,\n updatedOptions\n );\n\n if (res._response.status === 200) {\n return true;\n } else if (res._response.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(\n res._response.bodyAsText!,\n undefined,\n res._response.status,\n res._response.request,\n res._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<RestResponse> {\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<RestResponse> {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-removeUserFromAllGroups\",\n options\n );\n\n try {\n return await this.client.webPubSub.removeUserFromAllGroups(\n this.hubName,\n userId,\n updatedOptions\n );\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 const res = await this.client.webPubSub.groupExists(this.hubName, groupName, updatedOptions);\n\n if (res._response.status === 200) {\n return true;\n } else if (res._response.status === 404) {\n return false;\n } else {\n throw new RestError(\n res._response.bodyAsText!,\n undefined,\n res._response.status,\n res._response.request,\n res._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 const res = await this.client.webPubSub.userExists(this.hubName, username, updatedOptions);\n\n if (res._response.status === 200) {\n return true;\n } else if (res._response.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(\n res._response.bodyAsText!,\n undefined,\n res._response.status,\n res._response.request,\n res._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 ) {\n const { span, updatedOptions } = createSpan(\n \"WebPubSubServiceClient-hub-hasPermission\",\n options\n );\n\n try {\n return await this.client.webPubSub.checkPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\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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AAK,EAAE,CAAC;gBACzC,MAAM,WAAW,GAAoB;oBACnC,QAAQ,EAAE,QAAQ;oBAClB,SAAS,EACP,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,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 +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,EAsBvB,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)
@@ -1 +1 @@
1
- {"version":3,"file":"parseConnectionString.js","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,IAAI,MAAM,GAA6B,EAAE,CAAC;IAE1C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5B,MAAM,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,aAAa,KAAK,CAAC,CAAC;YAAE,OAAO;QACjC,MAAM,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACtC,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC7E,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACpC,YAAY,GAAG,WAAW,YAAY,EAAE,CAAC;KAC1C;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IAEd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { AzureKeyCredential } from \"@azure/core-auth\";\nimport { URL } from \"./util/url\";\n\ninterface ParsedConnectionString {\n credential: AzureKeyCredential;\n endpoint: string;\n}\n\nexport function parseConnectionString(conn: string): ParsedConnectionString {\n let parsed: { [id: string]: string } = {};\n\n conn.split(\";\").forEach((i) => {\n const assignmentPos = i.indexOf(\"=\");\n if (assignmentPos === -1) return;\n const key = i.substring(0, assignmentPos).toLowerCase();\n const value = i.substring(assignmentPos + 1);\n parsed[key] = value;\n });\n\n let endpointPart = parsed[\"endpoint\"];\n if (!endpointPart) throw new TypeError(\"connection string missing endpoint\");\n if (!endpointPart.startsWith(\"http\")) {\n endpointPart = `https://${endpointPart}`;\n }\n const key = parsed[\"accesskey\"];\n if (!key) throw new TypeError(\"connection string missing access key\");\n const credential = new AzureKeyCredential(key);\n const port = parsed[\"port\"];\n const url = new URL(endpointPart);\n url.port = port;\n const endpoint = url.toString();\n url.port = \"\";\n\n return { credential, endpoint };\n}\n"]}
1
+ {"version":3,"file":"parseConnectionString.js","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5B,MAAM,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,aAAa,KAAK,CAAC,CAAC;YAAE,OAAO;QACjC,MAAM,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACtC,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC7E,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACpC,YAAY,GAAG,WAAW,YAAY,EAAE,CAAC;KAC1C;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IAEd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { URL } from \"./util/url\";\n\ninterface ParsedConnectionString {\n credential: AzureKeyCredential;\n endpoint: string;\n}\n\nexport function parseConnectionString(conn: string): ParsedConnectionString {\n const parsed: { [id: string]: string } = {};\n\n conn.split(\";\").forEach((i) => {\n const assignmentPos = i.indexOf(\"=\");\n if (assignmentPos === -1) return;\n const key = i.substring(0, assignmentPos).toLowerCase();\n const value = i.substring(assignmentPos + 1);\n parsed[key] = value;\n });\n\n let endpointPart = parsed[\"endpoint\"];\n if (!endpointPart) throw new TypeError(\"connection string missing endpoint\");\n if (!endpointPart.startsWith(\"http\")) {\n endpointPart = `https://${endpointPart}`;\n }\n const key = parsed[\"accesskey\"];\n if (!key) throw new TypeError(\"connection string missing access key\");\n const credential = new AzureKeyCredential(key);\n const port = parsed[\"port\"];\n const url = new URL(endpointPart);\n url.port = port;\n const endpoint = url.toString();\n url.port = \"\";\n\n return { credential, endpoint };\n}\n"]}
@@ -0,0 +1,21 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export const webPubSubReverseProxyPolicyName = "webPubSubReverseProxyPolicy";
4
+ /**
5
+ * Create an HTTP pipeline policy to use a reverse proxy.
6
+ * This is generally going to be an Azure APIM endpoint.
7
+ * @internal
8
+ */
9
+ export function webPubSubReverseProxyPolicy(endpoint) {
10
+ const rpEndpointUrl = new URL(endpoint);
11
+ return {
12
+ name: webPubSubReverseProxyPolicyName,
13
+ sendRequest(request, next) {
14
+ const parsedUrl = new URL(request.url);
15
+ parsedUrl.host = rpEndpointUrl.host;
16
+ request.url = parsedUrl.toString();
17
+ return next(request);
18
+ }
19
+ };
20
+ }
21
+ //# sourceMappingURL=reverseProxyPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverseProxyPolicy.js","sourceRoot":"","sources":["../../src/reverseProxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,MAAM,CAAC,MAAM,+BAA+B,GAAG,6BAA6B,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAgB;IAC1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,+BAA+B;QACrC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACvC,SAAS,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YACpC,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy\n} from \"@azure/core-rest-pipeline\";\n\nexport const webPubSubReverseProxyPolicyName = \"webPubSubReverseProxyPolicy\";\n\n/**\n * Create an HTTP pipeline policy to use a reverse proxy.\n * This is generally going to be an Azure APIM endpoint.\n * @internal\n */\nexport function webPubSubReverseProxyPolicy(endpoint: string): PipelinePolicy {\n const rpEndpointUrl = new URL(endpoint);\n return {\n name: webPubSubReverseProxyPolicyName,\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const parsedUrl = new URL(request.url);\n parsedUrl.host = rpEndpointUrl.host;\n request.url = parsedUrl.toString();\n return next(request);\n }\n };\n}\n"]}
@@ -1,4 +1,6 @@
1
- function isHttpRequestBody(obj) {
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ function isRequestBody(obj) {
2
4
  return (typeof obj === "function" ||
3
5
  (typeof obj === "object" &&
4
6
  obj != null &&
@@ -6,18 +8,18 @@ function isHttpRequestBody(obj) {
6
8
  obj.constructor.name === "Blob" ||
7
9
  ArrayBuffer.isView(obj))));
8
10
  }
9
- export function getContentTypeForMessage(message, options) {
11
+ export function getPayloadForMessage(message, options) {
10
12
  if ((options === null || options === void 0 ? void 0 : options.contentType) === "text/plain") {
11
13
  if (typeof message !== "string") {
12
14
  throw new TypeError("Message must be a string.");
13
15
  }
14
- return "text/plain";
16
+ return { contentType: "text/plain", payload: message };
15
17
  }
16
- else if (isHttpRequestBody(message)) {
17
- return "application/octet-stream";
18
+ else if (isRequestBody(message)) {
19
+ return { contentType: "application/octet-stream", payload: message };
18
20
  }
19
21
  else {
20
- return "application/json";
22
+ return { contentType: "application/json", payload: JSON.stringify(message) };
21
23
  }
22
24
  }
23
25
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,SAAS,iBAAiB,CAAC,GAAY;IACrC,OAAO,CACL,OAAO,GAAG,KAAK,UAAU;QACzB,CAAC,OAAO,GAAG,KAAK,QAAQ;YACtB,GAAG,IAAI,IAAI;YACX,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa;gBACrC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM;gBAC/B,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,OAAgB,EAChB,OAA4B;IAE5B,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,MAAK,YAAY,EAAE;QACzC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QACD,OAAO,YAAY,CAAC;KACrB;SAAM,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE;QACrC,OAAO,0BAA0B,CAAC;KACnC;SAAM;QACL,OAAO,kBAAkB,CAAC;KAC3B;AACH,CAAC","sourcesContent":["import { HttpRequestBody } from \"@azure/core-http\";\n\nfunction isHttpRequestBody(obj: unknown): obj is HttpRequestBody {\n return (\n typeof obj === \"function\" ||\n (typeof obj === \"object\" &&\n obj != null &&\n (obj.constructor.name === \"ArrayBuffer\" ||\n obj.constructor.name === \"Blob\" ||\n ArrayBuffer.isView(obj)))\n );\n}\n\nexport function getContentTypeForMessage(\n message: unknown,\n options: Record<string, any>\n): \"text/plain\" | \"application/json\" | \"application/octet-stream\" {\n if (options?.contentType === \"text/plain\") {\n if (typeof message !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return \"text/plain\";\n } else if (isHttpRequestBody(message)) {\n return \"application/octet-stream\";\n } else {\n return \"application/json\";\n }\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,SAAS,aAAa,CAAC,GAAY;IACjC,OAAO,CACL,OAAO,GAAG,KAAK,UAAU;QACzB,CAAC,OAAO,GAAG,KAAK,QAAQ;YACtB,GAAG,IAAI,IAAI;YACX,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa;gBACrC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM;gBAC/B,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAC9B,CAAC;AACJ,CAAC;AAmBD,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,OAA4B;IACjF,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,MAAK,YAAY,EAAE;QACzC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QACD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;KACxD;SAAM,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;QACjC,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;KACtE;SAAM;QACL,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9E;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestBodyType } from \"@azure/core-rest-pipeline\";\n\nfunction isRequestBody(obj: unknown): obj is RequestBodyType {\n return (\n typeof obj === \"function\" ||\n (typeof obj === \"object\" &&\n obj != null &&\n (obj.constructor.name === \"ArrayBuffer\" ||\n obj.constructor.name === \"Blob\" ||\n ArrayBuffer.isView(obj)))\n );\n}\n\nexport interface TextPlainPayload {\n contentType: \"text/plain\";\n payload: string;\n}\n\nexport interface JsonPayload {\n contentType: \"application/json\";\n payload: string;\n}\n\nexport interface BinaryPayload {\n contentType: \"application/octet-stream\";\n payload: RequestBodyType;\n}\n\nexport type Payload = TextPlainPayload | JsonPayload | BinaryPayload;\n\nexport function getPayloadForMessage(message: unknown, options: Record<string, any>): Payload {\n if (options?.contentType === \"text/plain\") {\n if (typeof message !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return { contentType: \"text/plain\", payload: message };\n } else if (isRequestBody(message)) {\n return { contentType: \"application/octet-stream\", payload: message };\n } else {\n return { contentType: \"application/json\", payload: JSON.stringify(message) };\n }\n}\n"]}
@@ -1,27 +1,27 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { BaseRequestPolicy } from "@azure/core-http";
4
3
  import jwt from "jsonwebtoken";
5
- export function webPubSubAzureKeyCredentialPolicyFactory(credential) {
4
+ /**
5
+ * The programmatic identifier of the webPubSubKeyCredentialPolicy.
6
+ */
7
+ export const webPubSubKeyCredentialPolicyName = "webPubSubKeyCredentialPolicy";
8
+ /**
9
+ * Create an HTTP pipeline policy to authenticate a request
10
+ * using an `AzureKeyCredential` for Text Analytics
11
+ * @internal
12
+ */
13
+ export function webPubSubKeyCredentialPolicy(credential) {
6
14
  return {
7
- create: (nextPolicy, options) => {
8
- return new WebPubSubKeyCredentialPolicy(nextPolicy, options, credential);
9
- }
10
- };
11
- }
12
- export class WebPubSubKeyCredentialPolicy extends BaseRequestPolicy {
13
- constructor(nextPolicy, options, credential) {
14
- super(nextPolicy, options);
15
- this.credential = credential;
16
- }
17
- sendRequest(request) {
18
- request.headers.set("Authorization", "Bearer " +
19
- jwt.sign({}, this.credential.key, {
15
+ name: webPubSubKeyCredentialPolicyName,
16
+ sendRequest(request, next) {
17
+ const bearerToken = jwt.sign({}, credential.key, {
20
18
  audience: request.url,
21
19
  expiresIn: "1h",
22
20
  algorithm: "HS256"
23
- }));
24
- return this._nextPolicy.sendRequest(request);
25
- }
21
+ });
22
+ request.headers.set("Authorization", `Bearer ${bearerToken}`);
23
+ return next(request);
24
+ }
25
+ };
26
26
  }
27
27
  //# sourceMappingURL=webPubSubCredentialPolicy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webPubSubCredentialPolicy.js","sourceRoot":"","sources":["../../src/webPubSubCredentialPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,iBAAiB,EAKlB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B,MAAM,UAAU,wCAAwC,CAAC,UAA8B;IACrF,OAAO;QACL,MAAM,EAAE,CAAC,UAAyB,EAAE,OAA6B,EAAE,EAAE;YACnE,OAAO,IAAI,4BAA4B,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3E,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,4BAA6B,SAAQ,iBAAiB;IAGjE,YACE,UAAyB,EACzB,OAA6B,EAC7B,UAA8B;QAE9B,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEM,WAAW,CAAC,OAAoB;QACrC,OAAO,CAAC,OAAO,CAAC,GAAG,CACjB,eAAe,EACf,SAAS;YACP,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;gBAChC,QAAQ,EAAE,OAAO,CAAC,GAAG;gBACrB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,OAAO;aACnB,CAAC,CACL,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n BaseRequestPolicy,\n RequestPolicy,\n RequestPolicyOptions,\n WebResource,\n HttpOperationResponse\n} from \"@azure/core-http\";\nimport { AzureKeyCredential } from \"@azure/core-auth\";\n\nimport jwt from \"jsonwebtoken\";\n\nexport function webPubSubAzureKeyCredentialPolicyFactory(credential: AzureKeyCredential) {\n return {\n create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {\n return new WebPubSubKeyCredentialPolicy(nextPolicy, options, credential);\n }\n };\n}\n\nexport class WebPubSubKeyCredentialPolicy extends BaseRequestPolicy {\n public credential: AzureKeyCredential;\n\n constructor(\n nextPolicy: RequestPolicy,\n options: RequestPolicyOptions,\n credential: AzureKeyCredential\n ) {\n super(nextPolicy, options);\n this.credential = credential;\n }\n\n public sendRequest(request: WebResource): Promise<HttpOperationResponse> {\n request.headers.set(\n \"Authorization\",\n \"Bearer \" +\n jwt.sign({}, this.credential.key, {\n audience: request.url,\n expiresIn: \"1h\",\n algorithm: \"HS256\"\n })\n );\n\n return this._nextPolicy.sendRequest(request);\n }\n}\n"]}
1
+ {"version":3,"file":"webPubSubCredentialPolicy.js","sourceRoot":"","sources":["../../src/webPubSubCredentialPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAAyB;IACpE,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,EAAE;gBAC/C,QAAQ,EAAE,OAAO,CAAC,GAAG;gBACrB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,OAAO;aACnB,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,EAAE,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential } from \"@azure/core-auth\";\nimport {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy\n} from \"@azure/core-rest-pipeline\";\n\nimport jwt from \"jsonwebtoken\";\n\n/**\n * The programmatic identifier of the webPubSubKeyCredentialPolicy.\n */\nexport const webPubSubKeyCredentialPolicyName = \"webPubSubKeyCredentialPolicy\";\n\n/**\n * Create an HTTP pipeline policy to authenticate a request\n * using an `AzureKeyCredential` for Text Analytics\n * @internal\n */\nexport function webPubSubKeyCredentialPolicy(credential: KeyCredential): PipelinePolicy {\n return {\n name: webPubSubKeyCredentialPolicyName,\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const bearerToken = jwt.sign({}, credential.key, {\n audience: request.url,\n expiresIn: \"1h\",\n algorithm: \"HS256\"\n });\n request.headers.set(\"Authorization\", `Bearer ${bearerToken}`);\n return next(request);\n }\n };\n}\n"]}
@@ -1,24 +1,23 @@
1
- import { __awaiter } from "tslib";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
3
  /* eslint-disable no-invalid-this */
5
4
  import { parseConnectionString } from "../src/parseConnectionString";
6
- import * as assert from "assert";
5
+ import { assert } from "chai";
7
6
  describe("Can parse connection string", function () {
8
- it("can parse valid connection string", () => __awaiter(this, void 0, void 0, function* () {
9
- var conn = "Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;";
10
- var parsed = parseConnectionString(conn);
7
+ it("can parse valid connection string", async () => {
8
+ let conn = "Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;";
9
+ let parsed = parseConnectionString(conn);
11
10
  assert.equal(parsed.credential.key, "ABC");
12
11
  assert.equal(parsed.endpoint, "http://localhost:8080/");
13
12
  conn = "Endpoint=http://localhost;AccessKey=ABC;";
14
13
  parsed = parseConnectionString(conn);
15
14
  assert.equal(parsed.credential.key, "ABC");
16
15
  assert.equal(parsed.endpoint, "http://localhost/");
17
- }));
18
- it("can throw with invalid connection string", () => __awaiter(this, void 0, void 0, function* () {
16
+ });
17
+ it("can throw with invalid connection string", async () => {
19
18
  assert.throws(() => parseConnectionString("Endpoint=http://localhost;"));
20
19
  assert.throws(() => parseConnectionString("http://localhost;"));
21
20
  assert.throws(() => parseConnectionString("localhost;"));
22
- }));
21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CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { parseConnectionString } from \"../src/parseConnectionString\";\nimport * as assert from \"assert\";\n\ndescribe(\"Can parse connection string\", function() {\n it(\"can parse valid connection string\", async () => {\n var conn = \"Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;\";\n var parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost:8080/\");\n conn = \"Endpoint=http://localhost;AccessKey=ABC;\";\n parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost/\");\n });\n it(\"can throw with invalid connection string\", async () => {\n assert.throws(() => parseConnectionString(\"Endpoint=http://localhost;\"));\n assert.throws(() => parseConnectionString(\"http://localhost;\"));\n assert.throws(() => parseConnectionString(\"localhost;\"));\n });\n});\n"]}
1
+ {"version":3,"file":"conn.spec.js","sourceRoot":"","sources":["../../test/conn.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,6BAA6B,EAAE;IACtC,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,IAAI,IAAI,GAAG,gEAAgE,CAAC;QAC5E,IAAI,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;QACxD,IAAI,GAAG,0CAA0C,CAAC;QAClD,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,4BAA4B,CAAC,CAAC,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { parseConnectionString } from \"../src/parseConnectionString\";\nimport { assert } from \"chai\";\n\ndescribe(\"Can parse connection string\", function() {\n it(\"can parse valid connection string\", async () => {\n let conn = \"Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;\";\n let parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost:8080/\");\n conn = \"Endpoint=http://localhost;AccessKey=ABC;\";\n parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost/\");\n });\n it(\"can throw with invalid connection string\", async () => {\n assert.throws(() => parseConnectionString(\"Endpoint=http://localhost;\"));\n assert.throws(() => parseConnectionString(\"http://localhost;\"));\n assert.throws(() => parseConnectionString(\"localhost;\"));\n });\n});\n"]}
@@ -1,62 +1,63 @@
1
- import { __awaiter } from "tslib";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
3
  /* eslint-disable no-invalid-this */
5
- import { env, record } from "@azure/test-utils-recorder";
4
+ import { env, record } from "@azure-tools/test-recorder";
6
5
  import { WebPubSubServiceClient } from "../src";
7
- import * as assert from "assert";
6
+ import { assert } from "chai";
8
7
  import environmentSetup from "./testEnv";
8
+ /* eslint-disable @typescript-eslint/no-invalid-this */
9
9
  describe("Group client working with a group", function () {
10
- this.timeout(30000);
11
10
  let recorder;
12
11
  let client;
12
+ let lastResponse;
13
+ function onResponse(response) {
14
+ lastResponse = response;
15
+ }
13
16
  beforeEach(function () {
14
17
  recorder = record(this, environmentSetup);
15
18
  const hubClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, "simplechat");
16
19
  client = hubClient.group("group");
17
20
  });
18
- it("can broadcast to groups", () => __awaiter(this, void 0, void 0, function* () {
19
- let res = yield client.sendToAll("hello", { contentType: "text/plain" });
20
- assert.equal(res._response.status, 202);
21
- res = yield client.sendToAll({ x: 1, y: 2 });
22
- assert.equal(res._response.status, 202);
21
+ it("can broadcast to groups", async () => {
22
+ await client.sendToAll("hello", { contentType: "text/plain", onResponse });
23
+ assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
24
+ await client.sendToAll({ x: 1, y: 2 }, { onResponse });
25
+ assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
23
26
  const binaryMessage = new Uint8Array(10);
24
- res = yield client.sendToAll(binaryMessage.buffer);
25
- assert.equal(res._response.status, 202);
26
- }));
27
- it("can manage connections", () => __awaiter(this, void 0, void 0, function* () {
27
+ await client.sendToAll(binaryMessage.buffer, { onResponse });
28
+ assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
29
+ });
30
+ it("can manage connections", async () => {
28
31
  // this endpoint returns 404 for connections not on the hub
29
32
  let error;
30
33
  try {
31
- yield client.addConnection("xxxx");
34
+ await client.addConnection("xxxx");
32
35
  }
33
36
  catch (e) {
34
37
  error = e;
35
38
  }
36
- assert.notStrictEqual(error, undefined);
37
- assert.equal(error.name, "RestError");
38
- // this endpoint just returns 200 if the connection isn't present
39
- const res2 = yield client.removeConnection("xxxx");
40
- assert.equal(res2._response.status, 200);
41
- }));
42
- it("can manage users", () => __awaiter(this, void 0, void 0, function* () {
43
- const res = yield client.addUser("brian");
44
- assert.equal(res._response.status, 200);
45
- const hasBrian = yield client.hasUser("brian");
46
- assert.ok(hasBrian);
47
- const hasJeff = yield client.hasUser("jeff");
48
- assert.ok(!hasJeff);
49
- const res2 = yield client.removeUser("brian");
50
- assert.equal(res2._response.status, 200);
51
- const hasBrianNow = yield client.hasUser("brian");
52
- assert.ok(!hasBrianNow);
53
- }));
54
- afterEach(function () {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (recorder) {
57
- recorder.stop();
58
- }
59
- });
39
+ assert.exists(error);
40
+ assert.strictEqual(error === null || error === void 0 ? void 0 : error.name, "RestError");
41
+ try {
42
+ await client.removeConnection("xxxx", { onResponse });
43
+ }
44
+ catch (e) {
45
+ assert.exists(error);
46
+ assert.strictEqual(error === null || error === void 0 ? void 0 : error.name, "RestError");
47
+ }
48
+ });
49
+ // skipping until we can record better tests with an actual user active.
50
+ it.skip("can manage users", async () => {
51
+ // service returns 404, this should likely be raised as an error but isn't
52
+ // due to the swagger design
53
+ await client.addUser("brian");
54
+ // service returns 404 and this throws.
55
+ await client.removeUser("brian");
56
+ });
57
+ afterEach(async function () {
58
+ if (recorder) {
59
+ recorder.stop();
60
+ }
60
61
  });
61
62
  });
62
63
  //# sourceMappingURL=groups.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"groups.spec.js","sourceRoot":"","sources":["../../test/groups.spec.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,GAAG,EAAY,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAkB,MAAM,QAAQ,CAAC;AAChE,OAA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,CAAC,CAAC;IAEH,SAAS,CAAC;;YACR,IAAI,QAAQ,EAAE;gBACZ,QAAQ,CAAC,IAAI,EAAE,CAAC;aACjB;QACH,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { env, Recorder, record } from \"@azure/test-utils-recorder\";\nimport { WebPubSubServiceClient, WebPubSubGroup } from \"../src\";\nimport * as assert from \"assert\";\nimport environmentSetup from \"./testEnv\";\nimport { RestError } from \"@azure/core-http\";\n\ndescribe(\"Group client working with a group\", function() {\n this.timeout(30000);\n let recorder: Recorder;\n let client: WebPubSubGroup;\n beforeEach(function() {\n recorder = record(this, environmentSetup);\n const hubClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\");\n client = hubClient.group(\"group\");\n });\n\n it(\"can broadcast to groups\", async () => {\n let res = await client.sendToAll(\"hello\", { contentType: \"text/plain\" });\n assert.equal(res._response.status, 202);\n\n res = await client.sendToAll({ x: 1, y: 2 });\n assert.equal(res._response.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n res = await client.sendToAll(binaryMessage.buffer);\n assert.equal(res._response.status, 202);\n });\n\n it(\"can manage connections\", async () => {\n // this endpoint returns 404 for connections not on the hub\n let error: RestError;\n try {\n await client.addConnection(\"xxxx\");\n } catch (e) {\n error = e;\n }\n\n assert.notStrictEqual(error!, undefined);\n assert.equal(error!.name, \"RestError\");\n\n // this endpoint just returns 200 if the connection isn't present\n const res2 = await client.removeConnection(\"xxxx\");\n assert.equal(res2._response.status, 200);\n });\n\n it(\"can manage users\", async () => {\n const res = await client.addUser(\"brian\");\n assert.equal(res._response.status, 200);\n\n const hasBrian = await client.hasUser(\"brian\");\n assert.ok(hasBrian);\n\n const hasJeff = await client.hasUser(\"jeff\");\n assert.ok(!hasJeff);\n\n const res2 = await client.removeUser(\"brian\");\n assert.equal(res2._response.status, 200);\n\n const hasBrianNow = await client.hasUser(\"brian\");\n assert.ok(!hasBrianNow);\n });\n\n afterEach(async function() {\n if (recorder) {\n recorder.stop();\n }\n });\n});\n"]}
1
+ {"version":3,"file":"groups.spec.js","sourceRoot":"","sources":["../../test/groups.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,GAAG,EAAY,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAkB,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,gBAAgB,MAAM,WAAW,CAAC;AAGzC,uDAAuD;AAEvD,QAAQ,CAAC,mCAAmC,EAAE;IAC5C,IAAI,QAAkB,CAAC;IACvB,IAAI,MAAsB,CAAC;IAC3B,IAAI,YAA+C,CAAC;IACpD,SAAS,UAAU,CAAC,QAA+B;QACjD,YAAY,GAAG,QAAQ,CAAC;IAC1B,CAAC;IACD,UAAU,CAAC;QACT,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAI,sBAAsB,CAAC,GAAG,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;QACtF,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3E,MAAM,CAAC,KAAK,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAExC,MAAM,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,E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E9B,uCAAuC;QACvC,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK;QACb,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { env, Recorder, record } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, WebPubSubGroup } from \"../src\";\nimport { assert } from \"chai\";\nimport environmentSetup from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"Group client working with a group\", function() {\n let recorder: Recorder;\n let client: WebPubSubGroup;\n let lastResponse: FullOperationResponse | undefined;\n function onResponse(response: FullOperationResponse) {\n lastResponse = response;\n }\n beforeEach(function() {\n recorder = record(this, environmentSetup);\n const hubClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\");\n client = hubClient.group(\"group\");\n });\n\n it(\"can broadcast to groups\", async () => {\n await client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can manage connections\", async () => {\n // this endpoint returns 404 for connections not on the hub\n let error: RestError | undefined;\n try {\n await client.addConnection(\"xxxx\");\n } catch (e) {\n error = e;\n }\n\n assert.exists(error);\n assert.strictEqual(error?.name, \"RestError\");\n\n try {\n await client.removeConnection(\"xxxx\", { onResponse });\n } catch (e) {\n assert.exists(error);\n assert.strictEqual(error?.name, \"RestError\");\n }\n });\n\n // skipping until we can record better tests with an actual user active.\n it.skip(\"can manage users\", async () => {\n // service returns 404, this should likely be raised as an error but isn't\n // due to the swagger design\n await client.addUser(\"brian\");\n\n // service returns 404 and this throws.\n await client.removeUser(\"brian\");\n });\n\n afterEach(async function() {\n if (recorder) {\n recorder.stop();\n }\n });\n});\n"]}