@azure/web-pubsub 1.1.2-alpha.20230418.1 → 1.1.3-alpha.20230727.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
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,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,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;AA+OnE;;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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,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;QACJ,CAAC,CACF,CAAC;IACJ,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 { tracingClient } 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 * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections from `user1` and `user2`: `userId ne 'user1' and userId ne 'user2'`\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n}\n\n/**\n * Options for sending text messages to hubs.\n */\nexport interface HubSendTextToAllOptions extends HubSendToAllOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\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 * Options to configure the logging options.\n */\n loggingOptions?: WebPubSubServiceClientLogOptions;\n}\n\n/**\n * Options to configure the logging options.\n */\nexport declare interface WebPubSubServiceClientLogOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: 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 * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * * Send to connections in `group1` or `group2`: `'group1' in groups or `group2` in groups`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n}\n\n/**\n * Options for sending a text message to a user.\n */\nexport interface HubSendTextToUserOptions extends HubSendToUserOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\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 * The groups to join when the client connects\n */\n groups?: string[];\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 = \"2022-11-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 additionalAllowedHeaderNames:\n this.clientOptions?.loggingOptions?.additionalAllowedHeaderNames,\n additionalAllowedQueryParameters:\n this.clientOptions?.loggingOptions?.additionalAllowedQueryParameters,\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 return tracingClient.withSpan(\"WebPubSubServiceClient.sendToAll\", options, (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToAll(\n this.hubName,\n contentType,\n payload as any,\n updatedOptions\n );\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToUser\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType,\n payload as any,\n updatedOptions\n );\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToConnection\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n return this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType,\n payload as any,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.connectionExists\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeConnection\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeAllConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeUserConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);\n }\n );\n }\n\n /**\n * Remove a specific connection from all groups they are joined to\n * @param connectionId - The connection id to remove from all groups\n * @param options - Additional options\n */\n public async removeConnectionFromAllGroups(\n connectionId: string,\n options: HubCloseConnectionOptions = {}\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeConnectionFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeConnectionFromAllGroups(\n this.hubName,\n connectionId,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.groupExists\",\n options,\n async (updatedOptions) => {\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 }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.userExists\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.grantPermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.grantPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.revokePermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.revokePermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.hasPermission\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.getClientAccessToken\",\n options,\n async (updatedOptions) => {\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, \"webpubsub.group\": options?.groups };\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 }\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,EAEL,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAuC,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAA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AAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE,iBAAiB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAE,CAAC;gBAC7E,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;QACJ,CAAC,CACF,CAAC;IACJ,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 {\n WebPubSubGroup,\n WebPubSubGroupImpl,\n GroupAddConnectionOptions,\n GroupRemoveConnectionOptions,\n} from \"./groupClient\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { webPubSubKeyCredentialPolicy } from \"./webPubSubCredentialPolicy\";\nimport { tracingClient } from \"./tracing\";\nimport { logger } from \"./logger\";\nimport { parseConnectionString } from \"./parseConnectionString\";\nimport jwt from \"jsonwebtoken\";\nimport { getPayloadForMessage } from \"./utils\";\nimport {\n GeneratedClientOptionalParams,\n AddToGroupsRequest,\n RemoveFromGroupsRequest,\n} 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 * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections from `user1` and `user2`: `userId ne 'user1' and userId ne 'user2'`\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n /**\n * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\n\n/**\n * Options for sending text messages to hubs.\n */\nexport interface HubSendTextToAllOptions extends HubSendToAllOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\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 * Options to configure the logging options.\n */\n loggingOptions?: WebPubSubServiceClientLogOptions;\n}\n\n/**\n * Options to configure the logging options.\n */\nexport declare interface WebPubSubServiceClientLogOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: 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 * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\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 * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * * Send to connections in `group1` or `group2`: `'group1' in groups or `group2` in groups`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n /**\n * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\n\n/**\n * Options for sending a text message to a user.\n */\nexport interface HubSendTextToUserOptions extends HubSendToUserOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\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 * The groups to join when the client connects\n */\n groups?: string[];\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 = \"2023-07-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 additionalAllowedHeaderNames:\n this.clientOptions?.loggingOptions?.additionalAllowedHeaderNames,\n additionalAllowedQueryParameters:\n this.clientOptions?.loggingOptions?.additionalAllowedQueryParameters,\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 return tracingClient.withSpan(\"WebPubSubServiceClient.sendToAll\", options, (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToAll(\n this.hubName,\n contentType,\n payload as any,\n updatedOptions\n );\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToUser\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType,\n payload as any,\n updatedOptions\n );\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToConnection\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n return this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType,\n payload as any,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.connectionExists\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeConnection\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeAllConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeUserConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);\n }\n );\n }\n\n /**\n * Remove a specific connection from all groups they are joined to\n * @param connectionId - The connection id to remove from all groups\n * @param options - Additional options\n */\n public async removeConnectionFromAllGroups(\n connectionId: string,\n options: HubCloseConnectionOptions = {}\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeConnectionFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeConnectionFromAllGroups(\n this.hubName,\n connectionId,\n updatedOptions\n );\n }\n );\n }\n\n /**\n * Add filtered connections to multiple groups\n * @param groups - A list of groups which target connections will be added into\n * @param filter - An OData filter which target connections satisfy\n * @param options - Additional options\n */\n public async addConnectionsToGroups(\n groups: string[],\n filter: string,\n options: GroupAddConnectionOptions = {}\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.addConnectionsToGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.addConnectionsToGroups(\n this.hubName,\n {\n groups: groups,\n filter: filter,\n } as AddToGroupsRequest,\n updatedOptions\n );\n }\n );\n }\n\n /**\n * Remove filtered connections from multiple groups\n * @param groups - A list of groups which target connections will be removed from\n * @param filter - An OData filter which target connections satisfy\n * @param options - Additional options\n */\n public async removeConnectionsFromGroups(\n groups: string[],\n filter: string,\n options: GroupRemoveConnectionOptions = {}\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeConnectionsFromGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeConnectionsFromGroups(\n this.hubName,\n {\n groups: groups,\n filter: filter,\n } as RemoveFromGroupsRequest,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.groupExists\",\n options,\n async (updatedOptions) => {\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 }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.userExists\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.grantPermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.grantPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.revokePermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.revokePermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions\n );\n }\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 let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.hasPermission\",\n options,\n async (updatedOptions) => {\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 }\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 return tracingClient.withSpan(\n \"WebPubSubServiceClient.getClientAccessToken\",\n options,\n async (updatedOptions) => {\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, \"webpubsub.group\": options?.groups };\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 }\n );\n }\n}\n"]}
@@ -32,6 +32,7 @@ describe("Group client working with a group", function () {
32
32
  await client.sendToAll("hello", {
33
33
  contentType: "text/plain",
34
34
  filter: "userId ne 'user1'",
35
+ messageTtlSeconds: 60,
35
36
  onResponse,
36
37
  });
37
38
  assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
@@ -82,4 +83,56 @@ describe("Group client working with a group", function () {
82
83
  await recorder.stop();
83
84
  });
84
85
  });
86
+ describe("client working with multiple groups", function () {
87
+ let recorder;
88
+ let lastResponse;
89
+ let hubClient;
90
+ function onResponse(response) {
91
+ lastResponse = response;
92
+ }
93
+ beforeEach(async function () {
94
+ recorder = new Recorder(this.currentTest);
95
+ await recorder.start(recorderOptions);
96
+ hubClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), "simplechat", recorder.configureClientOptions({}));
97
+ });
98
+ afterEach(async function () {
99
+ await recorder.stop();
100
+ });
101
+ it("can join multiple groups with filter", async () => {
102
+ await hubClient.addConnectionsToGroups(["group1", "group2"], "userId eq 'user 1'", {
103
+ onResponse,
104
+ });
105
+ assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 200);
106
+ let error;
107
+ try {
108
+ await hubClient.addConnectionsToGroups(["group1", "group2"], "invalid filter");
109
+ }
110
+ catch (e) {
111
+ if (e.name !== "RestError") {
112
+ throw e;
113
+ }
114
+ error = e;
115
+ }
116
+ assert.equal(error.statusCode, 400);
117
+ assert.equal(JSON.parse(error.message).message, "Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')");
118
+ });
119
+ it("can leave multiple groups with filter", async () => {
120
+ await hubClient.removeConnectionsFromGroups(["group1", "group2"], "userId eq 'user 1'", {
121
+ onResponse,
122
+ });
123
+ assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 200);
124
+ let error;
125
+ try {
126
+ await hubClient.removeConnectionsFromGroups(["group1", "group2"], "invalid filter");
127
+ }
128
+ catch (e) {
129
+ if (e.name !== "RestError") {
130
+ throw e;
131
+ }
132
+ error = e;
133
+ }
134
+ assert.equal(error.statusCode, 400);
135
+ assert.equal(JSON.parse(error.message).message, "Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')");
136
+ });
137
+ });
85
138
  //# 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,QAAQ,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAkB,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,eAAe,MAAM,WAAW,CAAC;AAGxC,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,KAAK;QACd,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1C,MAAM,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACtC,MAAM,SAAS,GAAG,IAAI,sBAAsB,CAC1C,yBAAyB,CAAC,uBAAuB,CAAC,EAClD,YAAY,EACZ,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,CACpC,CAAC;QAEF,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,YA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["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { Recorder, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, WebPubSubGroup } from \"../src\";\nimport { assert } from \"chai\";\nimport recorderOptions 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(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n const hubClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n\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 broadcast to group with filter\", async () => {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\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: any) {\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: any) {\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 await recorder.stop();\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,QAAQ,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAkB,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,eAAe,MAAM,WAAW,CAAC;AAGxC,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,KAAK;QACd,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1C,MAAM,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QACtC,MAAM,SAAS,GAAG,IAAI,sBAAsB,CAC1C,yBAAyB,CAAC,uBAAuB,CAAC,EAClD,YAAY,EACZ,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,CACp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O,CAAM,EAAE;YACf,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC1B,MAAM,CAAC,CAAC;aACT;YAED,KAAK,GAAG,CAAC,CAAC;SACX;QACD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CACV,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EACjC,4GAA4G,CAC7G,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,SAAS,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,oBAAoB,EAAE;YACtF,UAAU;SACX,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAExC,IAAI,KAAK,CAAC;QACV,IAAI;YACF,MAAM,SAAS,CAAC,2BAA2B,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC;SACrF;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC1B,MAAM,CAAC,CAAC;aACT;YAED,KAAK,GAAG,CAAC,CAAC;SACX;QACD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CACV,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,OAAO,EACjC,4GAA4G,CAC7G,CAAC;IACJ,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 { Recorder, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, WebPubSubGroup } from \"../src\";\nimport { assert } from \"chai\";\nimport recorderOptions 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): void {\n lastResponse = response;\n }\n beforeEach(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n const hubClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n\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 broadcast to group with filter\", async () => {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n messageTtlSeconds: 60,\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\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: any) {\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: any) {\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 await recorder.stop();\n });\n});\n\ndescribe(\"client working with multiple groups\", function () {\n let recorder: Recorder;\n let lastResponse: FullOperationResponse | undefined;\n let hubClient: WebPubSubServiceClient;\n function onResponse(response: FullOperationResponse): void {\n lastResponse = response;\n }\n beforeEach(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n hubClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n });\n\n afterEach(async function () {\n await recorder.stop();\n });\n\n it(\"can join multiple groups with filter\", async (): Promise<void> => {\n await hubClient.addConnectionsToGroups([\"group1\", \"group2\"], \"userId eq 'user 1'\", {\n onResponse,\n });\n assert.equal(lastResponse?.status, 200);\n\n let error;\n try {\n await hubClient.addConnectionsToGroups([\"group1\", \"group2\"], \"invalid filter\");\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n\n it(\"can leave multiple groups with filter\", async () => {\n await hubClient.removeConnectionsFromGroups([\"group1\", \"group2\"], \"userId eq 'user 1'\", {\n onResponse,\n });\n assert.equal(lastResponse?.status, 200);\n\n let error;\n try {\n await hubClient.removeConnectionsFromGroups([\"group1\", \"group2\"], \"invalid filter\");\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n});\n"]}
@@ -61,6 +61,7 @@ describe("HubClient", function () {
61
61
  await client.sendToAll("hello", {
62
62
  contentType: "text/plain",
63
63
  filter: "userId ne 'user1'",
64
+ messageTtlSeconds: 60,
64
65
  onResponse,
65
66
  });
66
67
  assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
@@ -1 +1 @@
1
- {"version":3,"file":"hubs.spec.js","sourceRoot":"","sources":["../../test/hubs.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,eAAe,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,uDAAuD;AAEvD,QAAQ,CAAC,WAAW,EAAE;IACpB,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;QAC1C,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAC1D,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;gBACvB,IAAI,sBAAsB,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,EAAE,UAAU,EAAE;oBACzF,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;iBAChC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE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gBACvF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACnE,CAAC,EACD;gBACE,kCAAkC;gBAClC,mCAAmC;gBACnC,yCAAyC;gBACzC,yCAAyC;gBACzC,wCAAwC;gBACxC,4CAA4C;gBAC5C,6CAA6C;gBAC7C,gDAAgD;gBAChD,oCAAoC;gBACpC,mCAAmC;gBACnC,wCAAwC;gBACxC,sCAAsC;gBACtC,yCAAyC;gBACzC,6CAA6C;aAC9C,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC;gBAC5C,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,CAAC,QAAQ,CAAC;aACnB,CAAC,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;YAChD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;YACtD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,gBAAgB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,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 { Recorder, isLiveMode, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, AzureKeyCredential } from \"../src\";\nimport { assert } from \"@azure/test-utils\";\nimport recorderOptions from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { createTestCredential } from \"@azure-tools/test-credential\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"HubClient\", function () {\n describe(\"Constructing a HubClient\", () => {\n const credential = createTestCredential();\n it(\"takes a connection string, hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"), \"test-hub\", {\n retryOptions: { maxRetries: 2 },\n });\n });\n });\n\n it(\"takes an endpoint, an API key, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n new AzureKeyCredential(assertEnvironmentVariable(\"WPS_API_KEY\")),\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n }\n );\n });\n });\n\n it(\"takes an endpoint, DefaultAzureCredential, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n }\n );\n });\n });\n });\n\n describe(\"Working with a hub\", function () {\n let recorder: Recorder;\n let client: WebPubSubServiceClient;\n let lastResponse: FullOperationResponse | undefined;\n const credential = createTestCredential();\n function onResponse(response: FullOperationResponse) {\n lastResponse = response;\n }\n beforeEach(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n\n client = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n });\n\n afterEach(async function () {\n await recorder.stop();\n });\n\n it(\"can broadcast\", 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 broadcast with filter\", async () => {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n\n it(\"can broadcast using the DAC\", async () => {\n const dacClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n\n await dacClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await dacClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await dacClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can broadcast using APIM\", async () => {\n const apimClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({\n reverseProxyEndpoint: assertEnvironmentVariable(\"WPS_REVERSE_PROXY_ENDPOINT\"),\n })\n );\n\n await apimClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await apimClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await apimClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a user\", async () => {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToUser(\"brian\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToUser(\"brian\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send to a user with filter\", async () => {\n await client.sendToUser(\"vic\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n\n it(\"can send messages to a connection\", async () => {\n await client.sendToConnection(\"xxxx\", \"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToConnection(\"xxxx\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n const binaryMessage = new Uint8Array(10);\n\n await client.sendToConnection(\"xxxx\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can manage users\", async () => {\n const res = await client.userExists(\"foo\");\n assert.ok(!res);\n await client.removeUserFromAllGroups(\"brian\", { onResponse });\n assert.equal(lastResponse?.status, 204);\n });\n\n it(\"can manage connections\", async () => {\n await client.removeConnectionFromAllGroups(\"xxx\", { onResponse });\n assert.equal(lastResponse?.status, 204);\n });\n\n it(\"can check if a connection exists\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n const res = await client.connectionExists(\"xxx\");\n assert.ok(!res);\n });\n\n it(\"can grant permissions to connections\", async () => {\n let error;\n try {\n await client.grantPermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n\n it(\"can revoke permissions from connections\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n await client.revokePermission(\"invalid-id\", \"joinLeaveGroup\", { targetName: \"x\" });\n // Service doesn't throw error for invalid connection-ids\n });\n\n it(\"can trace through the various options\", async function () {\n await assert.supportsTracing(\n async (options) => {\n const promises: Promise<any>[] = [\n client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse, ...options }),\n client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.sendToConnection(\"xxxx\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.connectionExists(\"xxxx\", options),\n client.closeConnection(\"xxxx\", options),\n client.closeAllConnections(options),\n client.closeUserConnections(\"xxxx\", options),\n client.removeUserFromAllGroups(\"foo\", options),\n client.groupExists(\"foo\", options),\n client.userExists(\"foo\", options),\n client.grantPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.hasPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.revokePermission(\"xxxx\", \"joinLeaveGroup\", options),\n client.getClientAccessToken(options),\n ];\n // We don't care about errors, only that we created (and closed) the appropriate spans.\n await Promise.all(promises.map((p) => p.catch(() => undefined)));\n },\n [\n \"WebPubSubServiceClient.sendToAll\",\n \"WebPubSubServiceClient.sendToUser\",\n \"WebPubSubServiceClient.sendToConnection\",\n \"WebPubSubServiceClient.connectionExists\",\n \"WebPubSubServiceClient.closeConnection\",\n \"WebPubSubServiceClient.closeAllConnections\",\n \"WebPubSubServiceClient.closeUserConnections\",\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n \"WebPubSubServiceClient.groupExists\",\n \"WebPubSubServiceClient.userExists\",\n \"WebPubSubServiceClient.grantPermission\",\n \"WebPubSubServiceClient.hasPermission\",\n \"WebPubSubServiceClient.revokePermission\",\n \"WebPubSubServiceClient.getClientAccessToken\",\n ]\n );\n });\n\n it(\"can generate client tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/client/hubs/${client.hubName}`);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"hubs.spec.js","sourceRoot":"","sources":["../../test/hubs.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,eAAe,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,uDAAuD;AAEvD,QAAQ,CAAC,WAAW,EAAE;IACpB,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;QAC1C,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAC1D,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE;gBACvB,IAAI,sBAAsB,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,EAAE,UAAU,EAAE;oBACzF,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE;iBAChC,C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poration.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { Recorder, isLiveMode, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, AzureKeyCredential } from \"../src\";\nimport { assert } from \"@azure/test-utils\";\nimport recorderOptions from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { createTestCredential } from \"@azure-tools/test-credential\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"HubClient\", function () {\n describe(\"Constructing a HubClient\", () => {\n const credential = createTestCredential();\n it(\"takes a connection string, hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"), \"test-hub\", {\n retryOptions: { maxRetries: 2 },\n });\n });\n });\n\n it(\"takes an endpoint, an API key, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n new AzureKeyCredential(assertEnvironmentVariable(\"WPS_API_KEY\")),\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n }\n );\n });\n });\n\n it(\"takes an endpoint, DefaultAzureCredential, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n }\n );\n });\n });\n });\n\n describe(\"Working with a hub\", function () {\n let recorder: Recorder;\n let client: WebPubSubServiceClient;\n let lastResponse: FullOperationResponse | undefined;\n const credential = createTestCredential();\n function onResponse(response: FullOperationResponse): void {\n lastResponse = response;\n }\n beforeEach(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n\n client = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n });\n\n afterEach(async function () {\n await recorder.stop();\n });\n\n it(\"can broadcast\", 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 broadcast with filter\", async () => {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n messageTtlSeconds: 60,\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n\n it(\"can broadcast using the DAC\", async () => {\n const dacClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"simplechat\",\n recorder.configureClientOptions({})\n );\n\n await dacClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await dacClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await dacClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can broadcast using APIM\", async () => {\n const apimClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({\n reverseProxyEndpoint: assertEnvironmentVariable(\"WPS_REVERSE_PROXY_ENDPOINT\"),\n })\n );\n\n await apimClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await apimClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await apimClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a user\", async () => {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToUser(\"brian\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToUser(\"brian\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send to a user with filter\", async () => {\n await client.sendToUser(\"vic\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\"\n );\n });\n\n it(\"can send messages to a connection\", async () => {\n await client.sendToConnection(\"xxxx\", \"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToConnection(\"xxxx\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n const binaryMessage = new Uint8Array(10);\n\n await client.sendToConnection(\"xxxx\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can manage users\", async () => {\n const res = await client.userExists(\"foo\");\n assert.ok(!res);\n await client.removeUserFromAllGroups(\"brian\", { onResponse });\n assert.equal(lastResponse?.status, 204);\n });\n\n it(\"can manage connections\", async () => {\n await client.removeConnectionFromAllGroups(\"xxx\", { onResponse });\n assert.equal(lastResponse?.status, 204);\n });\n\n it(\"can check if a connection exists\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n const res = await client.connectionExists(\"xxx\");\n assert.ok(!res);\n });\n\n it(\"can grant permissions to connections\", async () => {\n let error;\n try {\n await client.grantPermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n\n it(\"can revoke permissions from connections\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n await client.revokePermission(\"invalid-id\", \"joinLeaveGroup\", { targetName: \"x\" });\n // Service doesn't throw error for invalid connection-ids\n });\n\n it(\"can trace through the various options\", async function () {\n await assert.supportsTracing(\n async (options) => {\n const promises: Promise<any>[] = [\n client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse, ...options }),\n client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.sendToConnection(\"xxxx\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.connectionExists(\"xxxx\", options),\n client.closeConnection(\"xxxx\", options),\n client.closeAllConnections(options),\n client.closeUserConnections(\"xxxx\", options),\n client.removeUserFromAllGroups(\"foo\", options),\n client.groupExists(\"foo\", options),\n client.userExists(\"foo\", options),\n client.grantPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.hasPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.revokePermission(\"xxxx\", \"joinLeaveGroup\", options),\n client.getClientAccessToken(options),\n ];\n // We don't care about errors, only that we created (and closed) the appropriate spans.\n await Promise.all(promises.map((p) => p.catch(() => undefined)));\n },\n [\n \"WebPubSubServiceClient.sendToAll\",\n \"WebPubSubServiceClient.sendToUser\",\n \"WebPubSubServiceClient.sendToConnection\",\n \"WebPubSubServiceClient.connectionExists\",\n \"WebPubSubServiceClient.closeConnection\",\n \"WebPubSubServiceClient.closeAllConnections\",\n \"WebPubSubServiceClient.closeUserConnections\",\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n \"WebPubSubServiceClient.groupExists\",\n \"WebPubSubServiceClient.userExists\",\n \"WebPubSubServiceClient.grantPermission\",\n \"WebPubSubServiceClient.hasPermission\",\n \"WebPubSubServiceClient.revokePermission\",\n \"WebPubSubServiceClient.getClientAccessToken\",\n ]\n );\n });\n\n it(\"can generate client tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/client/hubs/${client.hubName}`);\n });\n });\n});\n"]}
@@ -223,7 +223,7 @@ describe("ServiceClient to manage the connected WebSocket connections", function
223
223
  });
224
224
  client.on("open", async () => {
225
225
  // Send a JSON message to anonymous connections
226
- await serviceClient.sendToAll({ message: "Hello world!" }, { filter: "userId eq null" });
226
+ await serviceClient.sendToAll({ message: "Hello world!" }, { filter: "userId eq null", messageTtlSeconds: 60 });
227
227
  // Send a text message to connections in groupA but not in groupB
228
228
  const groupA = "groupA";
229
229
  const groupB = "groupB";
@@ -232,6 +232,7 @@ describe("ServiceClient to manage the connected WebSocket connections", function
232
232
  // use plain text "'groupA' in groups and not('groupB' in groups)"
233
233
  // or use the odata helper method
234
234
  filter: odata `${groupA} in groups and not(${groupB} in groups)`,
235
+ messageTtlSeconds: 60,
235
236
  });
236
237
  // Send the binary end signal message
237
238
  await serviceClient.sendToAll(getEndSignal());
@@ -241,5 +242,58 @@ describe("ServiceClient to manage the connected WebSocket connections", function
241
242
  assert.equal(messages[0].dataAsString, '{"message":"Hello world!"}');
242
243
  assert.equal(messages[1].dataAsString, "Hello world!");
243
244
  });
245
+ it("Clients can join or leave multiple groups with filter", async function () {
246
+ if (!isLiveMode())
247
+ this.skip();
248
+ const hub = "ClientsCanJoinOrLeaveMultipleGroupsWithFilter";
249
+ const messages = [];
250
+ // Get token
251
+ const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
252
+ const token = await serviceClient.getClientAccessToken({ userId: "user 1" });
253
+ const startSignal = defer();
254
+ const endSignal = defer();
255
+ // Start simple WebSocket connections
256
+ const client1 = new ws.WebSocket(token.url);
257
+ const client2 = new ws.WebSocket(token.url);
258
+ let opened = 0;
259
+ const onOpen = () => {
260
+ opened++;
261
+ if (opened === 2) {
262
+ startSignal.resolve();
263
+ }
264
+ };
265
+ const onMessage = (data, isBinary) => {
266
+ const frame = new SimpleWebSocketFrame(data, isBinary);
267
+ console.log(frame.toString());
268
+ messages.push(frame);
269
+ if (messages.length === 6) {
270
+ endSignal.resolve();
271
+ }
272
+ };
273
+ client1.on("open", onOpen);
274
+ client2.on("open", onOpen);
275
+ client1.on("message", onMessage);
276
+ client2.on("message", onMessage);
277
+ // Wait all clients opened
278
+ await startSignal.promise;
279
+ // Add filtered connections to group1 and group2
280
+ await serviceClient.addConnectionsToGroups(["group1", "group2"], "userId eq 'user 1'");
281
+ // send to connections in both group1 and group2
282
+ await serviceClient.sendToAll({ message: "Hi json!" }, { filter: "'group1 1' in groups and 'group2' in groups" });
283
+ // Send a plain text message
284
+ await serviceClient.sendToAll("Hi text!", {
285
+ contentType: "text/plain",
286
+ filter: "'group1 1' in groups and 'group2' in groups",
287
+ });
288
+ // Send the binary end signal message
289
+ await serviceClient.sendToAll(getEndSignal(2), {
290
+ filter: "'group1 1' in groups and 'group2' in groups",
291
+ });
292
+ // Timeout 1000 ms
293
+ await Promise.race([new Promise((resolve) => setTimeout(resolve, 1000)), endSignal.promise]);
294
+ assert.equal(messages.length, 6);
295
+ client1.close();
296
+ client2.close();
297
+ });
244
298
  });
245
299
  //# sourceMappingURL=integration.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"integration.spec.js","sourceRoot":"","sources":["../../test/integration.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEnF,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,SAAS,KAAK;IAKZ,IAAI,aAA6B,CAAC;IAClC,IAAI,YAAkC,CAAC;IAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,aAAa,GAAG,OAAO,CAAC;QACxB,YAAY,GAAG,MAAM,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,OAAO,EAAE,aAAc;QACvB,MAAM,EAAE,YAAa;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,oBAAoB;IAExB,YAAmB,IAAqC,EAAS,QAAiB;QAA/D,SAAI,GAAJ,IAAI,CAAiC;QAAS,aAAQ,GAAR,QAAQ,CAAS;QAChF,IAAI,CAAC,QAAQ,EAAE;YACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SACrC;IACH,CAAC;IAED,WAAW,CAAC,KAAyB,SAAS;QAC5C,OAAO,CACL,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,IAAI,YAAY,MAAM;YAC3B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;YAClB,CAAC,EAAE,KAAK,SAAS,IAAI,I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AC,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,MAAM,SAAS,CAAC,OAAO,CAAC;QAExB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACjC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,4BAA4B,CAAC,CAAC;QACrE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IACzD,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 { WebPubSubServiceClient, odata } from \"../src/index\";\nimport { isLiveMode, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { Context } from \"mocha\";\nimport { assert } from \"chai\";\nimport ws from \"ws\";\n\nfunction defer<T>(): {\n promise: Promise<T>;\n resolve: (t: T) => void;\n reject: (err: Error) => void;\n} {\n let actualResolve: (t: T) => void;\n let actualReject: (err: Error) => void;\n\n const promise = new Promise<T>((resolve, reject) => {\n actualResolve = resolve;\n actualReject = reject;\n });\n\n return {\n promise,\n resolve: actualResolve!,\n reject: actualReject!,\n };\n}\n\nclass SimpleWebSocketFrame {\n public dataAsString: string | undefined;\n constructor(public data: Buffer | ArrayBuffer | Buffer[], public isBinary: boolean) {\n if (!isBinary) {\n this.dataAsString = data.toString();\n }\n }\n\n isEndSignal(id: number | undefined = undefined): boolean {\n return (\n this.isBinary &&\n this.data instanceof Buffer &&\n this.data[0] === 5 &&\n this.data[1] === 1 &&\n this.data[2] === 1 &&\n (id === undefined || this.data[3] === id)\n );\n }\n\n toString(): string | undefined {\n if (this.isEndSignal()) {\n return \"|EndSignal|\";\n }\n if (!this.isBinary) {\n return this.dataAsString;\n } else {\n return this.data.toString();\n }\n }\n}\n\nclass PubSubWebSocketFrame {\n public message: any;\n public dataAsString: string;\n constructor(data: Buffer | ArrayBuffer | Buffer[], isBinary: boolean) {\n assert.isFalse(isBinary);\n this.dataAsString = data.toString();\n this.message = JSON.parse(this.dataAsString);\n }\n\n isEndSignal(): boolean {\n return this.message.dataType === \"binary\" && this.message.data === \"BQEB\";\n }\n\n toString(): string | undefined {\n if (this.isEndSignal()) {\n return \"|EndSignal|\";\n }\n\n return this.dataAsString;\n }\n}\n\nfunction getEndSignal(id: number | undefined = undefined): Uint8Array {\n // magic number 511\n const payload = new Uint8Array(id === undefined ? 3 : 4);\n payload[0] = 5;\n payload[1] = 1;\n payload[2] = 1;\n if (id !== undefined) {\n payload[3] = id;\n }\n return payload;\n}\n\ndescribe(\"ServiceClient to manage the connected WebSocket connections\", function () {\n it(\"Simple clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"SimpleClientCanReceiveMessage\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 2);\n assert.equal(messages[0].dataAsString, '{\"message\":\"Hello world!\"}');\n assert.equal(messages[1].dataAsString, \"Hi there!\");\n });\n\n it(\"Simple clients can can join group and receive group messages\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"SimpleClientCanReceiveGroupMessage\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken({\n groups: [\"group1\", \"group2\"],\n });\n const end1Signal = defer<void>();\n const end2Signal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal(1)) {\n end1Signal.resolve();\n } else if (frame.isEndSignal(2)) {\n end2Signal.resolve();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n const group1Client = serviceClient.group(\"group1\");\n const group2Client = serviceClient.group(\"group2\");\n // send to all\n // Send a JSON message\n await group1Client.sendToAll({ message: \"Hello world from group1!\" });\n await group2Client.sendToAll(getEndSignal(1));\n // Send a plain text message\n await group2Client.sendToAll(\"Hi there from group2!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await group2Client.sendToAll(getEndSignal(2));\n });\n\n await end1Signal.promise;\n await end2Signal.promise;\n client.close();\n assert.equal(messages.length, 2);\n\n // order from different groups is not guaranteed\n assert.isTrue(\n messages.findIndex((s) => s.dataAsString === '{\"message\":\"Hello world from group1!\"}') > -1\n );\n assert.isTrue(messages.findIndex((s) => s.dataAsString === \"Hi there from group2!\") > -1);\n });\n\n it(\"Subprotocol clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"PubSubClientCanReceiveMessage\";\n const messages: PubSubWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n const connectedSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url, \"json.webpubsub.azure.v1\");\n client.on(\"message\", (data, isBinary) => {\n const frame = new PubSubWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.message.event === \"connected\") {\n connectedSignal.resolve();\n }\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n await connectedSignal.promise;\n\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 3);\n assert.equal(messages[0].message.event, \"connected\");\n assert.equal(\n messages[1].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"json\",\"data\":{\"message\":\"Hello world!\"}}'\n );\n assert.equal(\n messages[2].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"text\",\"data\":\"Hi there!\"}'\n );\n });\n\n it(\"Clients can receive messages with filters\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"ClientCanReceiveMessageWithFilters\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken({ groups: [\"groupA\"] });\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // Send a JSON message to anonymous connections\n await serviceClient.sendToAll({ message: \"Hello world!\" }, { filter: \"userId eq null\" });\n // Send a text message to connections in groupA but not in groupB\n const groupA = \"groupA\";\n const groupB = \"groupB\";\n await serviceClient.sendToAll(\"Hello world!\", {\n contentType: \"text/plain\",\n // use plain text \"'groupA' in groups and not('groupB' in groups)\"\n // or use the odata helper method\n filter: odata`${groupA} in groups and not(${groupB} in groups)`,\n });\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 2);\n assert.equal(messages[0].dataAsString, '{\"message\":\"Hello world!\"}');\n assert.equal(messages[1].dataAsString, \"Hello world!\");\n });\n});\n"]}
1
+ {"version":3,"file":"integration.spec.js","sourceRoot":"","sources":["../../test/integration.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAEnF,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,SAAS,KAAK;IAKZ,IAAI,aAA6B,CAAC;IAClC,IAAI,YAAkC,CAAC;IAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,aAAa,GAAG,OAAO,CAAC;QACxB,YAAY,GAAG,MAAM,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,OAAO,EAAE,aAAc;QACvB,MAAM,EAAE,YAAa;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,oBAAoB;IAExB,YAAmB,IAAqC,EAAS,QAAiB;QAA/D,SAAI,GAAJ,IAAI,CAAiC;QAAS,aAAQ,GAAR,QAAQ,CAAS;QAChF,IAAI,CAAC,QAAQ,EAAE;YACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SACrC;IACH,CAAC;IAED,WAAW,CAAC,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QAEF,4BAA4B;QAC5B,MAAM,aAAa,CAAC,SAAS,CAAC,UAAU,EAAE;YACxC,WAAW,EAAE,YAAY;YACzB,MAAM,EAAE,6CAA6C;SACtD,CAAC,CAAC;QAEH,qCAAqC;QACrC,MAAM,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE;YAC7C,MAAM,EAAE,6CAA6C;SACtD,CAAC,CAAC;QAEH,kBAAkB;QAClB,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7F,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACjC,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,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 { WebPubSubServiceClient, odata } from \"../src/index\";\nimport { isLiveMode, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { Context } from \"mocha\";\nimport { assert } from \"chai\";\nimport ws from \"ws\";\n\nfunction defer<T>(): {\n promise: Promise<T>;\n resolve: (t: T) => void;\n reject: (err: Error) => void;\n} {\n let actualResolve: (t: T) => void;\n let actualReject: (err: Error) => void;\n\n const promise = new Promise<T>((resolve, reject) => {\n actualResolve = resolve;\n actualReject = reject;\n });\n\n return {\n promise,\n resolve: actualResolve!,\n reject: actualReject!,\n };\n}\n\nclass SimpleWebSocketFrame {\n public dataAsString: string | undefined;\n constructor(public data: Buffer | ArrayBuffer | Buffer[], public isBinary: boolean) {\n if (!isBinary) {\n this.dataAsString = data.toString();\n }\n }\n\n isEndSignal(id: number | undefined = undefined): boolean {\n return (\n this.isBinary &&\n this.data instanceof Buffer &&\n this.data[0] === 5 &&\n this.data[1] === 1 &&\n this.data[2] === 1 &&\n (id === undefined || this.data[3] === id)\n );\n }\n\n toString(): string | undefined {\n if (this.isEndSignal()) {\n return \"|EndSignal|\";\n }\n if (!this.isBinary) {\n return this.dataAsString;\n } else {\n return this.data.toString();\n }\n }\n}\n\nclass PubSubWebSocketFrame {\n public message: any;\n public dataAsString: string;\n constructor(data: Buffer | ArrayBuffer | Buffer[], isBinary: boolean) {\n assert.isFalse(isBinary);\n this.dataAsString = data.toString();\n this.message = JSON.parse(this.dataAsString);\n }\n\n isEndSignal(): boolean {\n return this.message.dataType === \"binary\" && this.message.data === \"BQEB\";\n }\n\n toString(): string | undefined {\n if (this.isEndSignal()) {\n return \"|EndSignal|\";\n }\n\n return this.dataAsString;\n }\n}\n\nfunction getEndSignal(id: number | undefined = undefined): Uint8Array {\n // magic number 511\n const payload = new Uint8Array(id === undefined ? 3 : 4);\n payload[0] = 5;\n payload[1] = 1;\n payload[2] = 1;\n if (id !== undefined) {\n payload[3] = id;\n }\n return payload;\n}\n\ndescribe(\"ServiceClient to manage the connected WebSocket connections\", function () {\n it(\"Simple clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"SimpleClientCanReceiveMessage\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 2);\n assert.equal(messages[0].dataAsString, '{\"message\":\"Hello world!\"}');\n assert.equal(messages[1].dataAsString, \"Hi there!\");\n });\n\n it(\"Simple clients can can join group and receive group messages\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"SimpleClientCanReceiveGroupMessage\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken({\n groups: [\"group1\", \"group2\"],\n });\n const end1Signal = defer<void>();\n const end2Signal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal(1)) {\n end1Signal.resolve();\n } else if (frame.isEndSignal(2)) {\n end2Signal.resolve();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n const group1Client = serviceClient.group(\"group1\");\n const group2Client = serviceClient.group(\"group2\");\n // send to all\n // Send a JSON message\n await group1Client.sendToAll({ message: \"Hello world from group1!\" });\n await group2Client.sendToAll(getEndSignal(1));\n // Send a plain text message\n await group2Client.sendToAll(\"Hi there from group2!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await group2Client.sendToAll(getEndSignal(2));\n });\n\n await end1Signal.promise;\n await end2Signal.promise;\n client.close();\n assert.equal(messages.length, 2);\n\n // order from different groups is not guaranteed\n assert.isTrue(\n messages.findIndex((s) => s.dataAsString === '{\"message\":\"Hello world from group1!\"}') > -1\n );\n assert.isTrue(messages.findIndex((s) => s.dataAsString === \"Hi there from group2!\") > -1);\n });\n\n it(\"Subprotocol clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"PubSubClientCanReceiveMessage\";\n const messages: PubSubWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n const connectedSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url, \"json.webpubsub.azure.v1\");\n client.on(\"message\", (data, isBinary) => {\n const frame = new PubSubWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.message.event === \"connected\") {\n connectedSignal.resolve();\n }\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n await connectedSignal.promise;\n\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 3);\n assert.equal(messages[0].message.event, \"connected\");\n assert.equal(\n messages[1].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"json\",\"data\":{\"message\":\"Hello world!\"}}'\n );\n assert.equal(\n messages[2].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"text\",\"data\":\"Hi there!\"}'\n );\n });\n\n it(\"Clients can receive messages with filters\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"ClientCanReceiveMessageWithFilters\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken({ groups: [\"groupA\"] });\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // Send a JSON message to anonymous connections\n await serviceClient.sendToAll(\n { message: \"Hello world!\" },\n { filter: \"userId eq null\", messageTtlSeconds: 60 }\n );\n // Send a text message to connections in groupA but not in groupB\n const groupA = \"groupA\";\n const groupB = \"groupB\";\n await serviceClient.sendToAll(\"Hello world!\", {\n contentType: \"text/plain\",\n // use plain text \"'groupA' in groups and not('groupB' in groups)\"\n // or use the odata helper method\n filter: odata`${groupA} in groups and not(${groupB} in groups)`,\n messageTtlSeconds: 60,\n });\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 2);\n assert.equal(messages[0].dataAsString, '{\"message\":\"Hello world!\"}');\n assert.equal(messages[1].dataAsString, \"Hello world!\");\n });\n\n it(\"Clients can join or leave multiple groups with filter\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"ClientsCanJoinOrLeaveMultipleGroupsWithFilter\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n hub\n );\n const token = await serviceClient.getClientAccessToken({ userId: \"user 1\" });\n const startSignal = defer<void>();\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client1 = new ws.WebSocket(token.url);\n const client2 = new ws.WebSocket(token.url);\n let opened = 0;\n\n const onOpen = (): void => {\n opened++;\n if (opened === 2) {\n startSignal.resolve();\n }\n };\n const onMessage = (data: Buffer | ArrayBuffer | Buffer[], isBinary: boolean): void => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n console.log(frame.toString());\n messages.push(frame);\n if (messages.length === 6) {\n endSignal.resolve();\n }\n };\n client1.on(\"open\", onOpen);\n client2.on(\"open\", onOpen);\n client1.on(\"message\", onMessage);\n client2.on(\"message\", onMessage);\n\n // Wait all clients opened\n await startSignal.promise;\n\n // Add filtered connections to group1 and group2\n await serviceClient.addConnectionsToGroups([\"group1\", \"group2\"], \"userId eq 'user 1'\");\n\n // send to connections in both group1 and group2\n await serviceClient.sendToAll(\n { message: \"Hi json!\" },\n { filter: \"'group1 1' in groups and 'group2' in groups\" }\n );\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi text!\", {\n contentType: \"text/plain\",\n filter: \"'group1 1' in groups and 'group2' in groups\",\n });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal(2), {\n filter: \"'group1 1' in groups and 'group2' in groups\",\n });\n\n // Timeout 1000 ms\n await Promise.race([new Promise((resolve) => setTimeout(resolve, 1000)), endSignal.promise]);\n assert.equal(messages.length, 6);\n client1.close();\n client2.close();\n });\n});\n"]}