@azure/web-pubsub 1.1.3-alpha.20240528.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. package/dist/index.js +393 -375
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/generated/generatedClient.js +4 -4
  4. package/dist-esm/src/generated/generatedClient.js.map +1 -1
  5. package/dist-esm/src/generated/generatedClientContext.js +1 -1
  6. package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
  7. package/dist-esm/src/generated/models/index.js +8 -0
  8. package/dist-esm/src/generated/models/index.js.map +1 -1
  9. package/dist-esm/src/generated/models/mappers.js +160 -160
  10. package/dist-esm/src/generated/models/mappers.js.map +1 -1
  11. package/dist-esm/src/generated/models/parameters.js +106 -96
  12. package/dist-esm/src/generated/models/parameters.js.map +1 -1
  13. package/dist-esm/src/generated/operations/healthApi.js +1 -1
  14. package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
  15. package/dist-esm/src/generated/operations/webPubSub.js +108 -107
  16. package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
  17. package/dist-esm/src/generated/operationsInterfaces/healthApi.js.map +1 -1
  18. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -1
  19. package/dist-esm/src/hubClient.js +15 -8
  20. package/dist-esm/src/hubClient.js.map +1 -1
  21. package/dist-esm/src/index.js.map +1 -1
  22. package/dist-esm/test/hubs.spec.js +11 -0
  23. package/dist-esm/test/hubs.spec.js.map +1 -1
  24. package/dist-esm/test/integration.spec.js +3 -3
  25. package/dist-esm/test/integration.spec.js.map +1 -1
  26. package/dist-esm/test/testEnv.js +0 -3
  27. package/dist-esm/test/testEnv.js.map +1 -1
  28. package/package.json +4 -4
  29. package/types/web-pubsub.d.ts +11 -0
@@ -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,CA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,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"]}
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,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;AAM/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAoRnE;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAyDjC,YACE,0BAAkC,EAClC,cAA8D,EAC9D,a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ACvC,MAAM,OAAO,GAAG;oBACd,IAAI,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK;oBAC3B,iBAAiB,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM;iBAC1C,CAAC;gBACF,MAAM,WAAW,GAAoB;oBACnC,QAAQ,EAAE,QAAQ;oBAClB,SAAS,EACP,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,uBAAuB,MAAK,SAAS;wBACnD,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,GAAG,cAAc,CAAC,uBAAuB,GAAG;oBAClD,SAAS,EAAE,OAAO;iBACnB,CAAC;gBACF,IAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM,EAAE,CAAC;oBAC3B,WAAW,CAAC,OAAO,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM,CAAC;gBAC/C,CAAC;gBACD,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YAC9C,CAAC;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 * The type of client endpoint that is being requested.\n */\nexport type WebPubSubClientProtocol = \"default\" | \"mqtt\";\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 * The protocol type of the client\n * * `default`: Default WebPubSub Client. Example Client Connection URL: _wss://exampleHost.com/client/hubs/exampleHub_\n * * `mqtt`: MQTT Client. Example Client Connection URL: _wss://exampleHost.com/client/mqtt/hubs/exampleHub_\n */\n clientProtocol?: WebPubSubClientProtocol;\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 = \"2024-01-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 clientProtocol = updatedOptions.clientProtocol;\n const clientPath =\n clientProtocol && clientProtocol === \"mqtt\"\n ? `clients/mqtt/hubs/${this.hubName}`\n : `client/hubs/${this.hubName}`;\n const baseUrl = clientEndpoint + clientPath;\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 + clientPath;\n const payload = {\n role: updatedOptions?.roles,\n \"webpubsub.group\": updatedOptions?.groups,\n };\n const signOptions: jwt.SignOptions = {\n audience: audience,\n expiresIn:\n updatedOptions?.expirationTimeInMinutes === undefined\n ? \"1h\"\n : `${updatedOptions.expirationTimeInMinutes}m`,\n algorithm: \"HS256\",\n };\n if (updatedOptions?.userId) {\n signOptions.subject = updatedOptions?.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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,sBAAsB,GAuBvB,MAAM,aAAa,CAAC;AAarB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nexport { AzureKeyCredential } from \"@azure/core-auth\";\nexport {\n WebPubSubServiceClient,\n HubSendToAllOptions,\n ClientTokenResponse,\n HubCloseConnectionOptions,\n HubCloseAllConnectionsOptions,\n HubCloseUserConnectionsOptions,\n GenerateClientTokenOptions,\n HasConnectionOptions,\n HubHasGroupOptions,\n HubHasUserOptions,\n WebPubSubServiceClientOptions,\n WebPubSubServiceClientLogOptions,\n HubRemoveUserFromAllGroupsOptions,\n HubSendToConnectionOptions,\n HubSendToUserOptions,\n HubGrantPermissionOptions,\n HubRevokePermissionOptions,\n HubHasPermissionOptions,\n HubSendTextToAllOptions,\n HubSendTextToConnectionOptions,\n HubSendTextToUserOptions,\n JSONTypes,\n Permission,\n} from \"./hubClient\";\nexport {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupCloseAllConnectionsOptions,\n GroupAddUserOptions,\n GroupAdminClientOptions,\n GroupHasUserOptions,\n GroupRemoveConnectionOptions,\n GroupRemoveUserOptions,\n GroupSendTextToAllOptions,\n GroupSendToAllOptions,\n} from \"./groupClient\";\nexport { odata } from \"./utils\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,sBAAsB,GAwBvB,MAAM,aAAa,CAAC;AAarB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nexport { AzureKeyCredential } from \"@azure/core-auth\";\nexport {\n WebPubSubServiceClient,\n HubSendToAllOptions,\n ClientTokenResponse,\n HubCloseConnectionOptions,\n HubCloseAllConnectionsOptions,\n HubCloseUserConnectionsOptions,\n GenerateClientTokenOptions,\n HasConnectionOptions,\n HubHasGroupOptions,\n HubHasUserOptions,\n WebPubSubServiceClientOptions,\n WebPubSubServiceClientLogOptions,\n HubRemoveUserFromAllGroupsOptions,\n HubSendToConnectionOptions,\n HubSendToUserOptions,\n HubGrantPermissionOptions,\n HubRevokePermissionOptions,\n HubHasPermissionOptions,\n HubSendTextToAllOptions,\n HubSendTextToConnectionOptions,\n HubSendTextToUserOptions,\n JSONTypes,\n Permission,\n WebPubSubClientProtocol,\n} from \"./hubClient\";\nexport {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupCloseAllConnectionsOptions,\n GroupAddUserOptions,\n GroupAdminClientOptions,\n GroupHasUserOptions,\n GroupRemoveConnectionOptions,\n GroupRemoveUserOptions,\n GroupSendTextToAllOptions,\n GroupSendToAllOptions,\n} from \"./groupClient\";\nexport { odata } from \"./utils\";\n"]}
@@ -232,6 +232,17 @@ describe("HubClient", function () {
232
232
  assert.equal(url.host, new URL(client.endpoint).host);
233
233
  assert.equal(url.pathname, `/client/hubs/${client.hubName}`);
234
234
  });
235
+ it("can generate client MQTT tokens", async () => {
236
+ const res = await client.getClientAccessToken({
237
+ userId: "brian",
238
+ groups: ["group1"],
239
+ clientProtocol: "mqtt",
240
+ });
241
+ const url = new URL(res.url);
242
+ assert.ok(url.searchParams.has("access_token"));
243
+ assert.equal(url.host, new URL(client.endpoint).host);
244
+ assert.equal(url.pathname, `/clients/mqtt/hubs/${client.hubName}`);
245
+ });
235
246
  });
236
247
  });
237
248
  //# sourceMappingURL=hubs.spec.js.map
@@ -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,yBAAyB,CAAC;AACjD,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,CA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C,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-tools/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"]}
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,yBAAyB,CAAC;AACjD,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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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;QAEH,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;YAC/C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC;gBAC5C,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,CAAC,QAAQ,CAAC;gBAClB,cAAc,EAAE,MAAM;aACvB,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,sBAAsB,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACrE,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-tools/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 it(\"can generate client MQTT tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n clientProtocol: \"mqtt\",\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, `/clients/mqtt/hubs/${client.hubName}`);\n });\n });\n});\n"]}
@@ -279,15 +279,15 @@ describe("ServiceClient to manage the connected WebSocket connections", function
279
279
  // Add filtered connections to group1 and group2
280
280
  await serviceClient.addConnectionsToGroups(["group1", "group2"], "userId eq 'user 1'");
281
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" });
282
+ await serviceClient.sendToAll({ message: "Hi json!" }, { filter: "'group1' in groups and 'group2' in groups" });
283
283
  // Send a plain text message
284
284
  await serviceClient.sendToAll("Hi text!", {
285
285
  contentType: "text/plain",
286
- filter: "'group1 1' in groups and 'group2' in groups",
286
+ filter: "'group1' in groups and 'group2' in groups",
287
287
  });
288
288
  // Send the binary end signal message
289
289
  await serviceClient.sendToAll(getEndSignal(2), {
290
- filter: "'group1 1' in groups and 'group2' in groups",
290
+ filter: "'group1' in groups and 'group2' in groups",
291
291
  });
292
292
  // Timeout 1000 ms
293
293
  await Promise.race([new Promise((resolve) => setTimeout(resolve, 1000)), endSignal.promise]);
@@ -1 +1 @@
1
- {"version":3,"file":"integration.spec.js","sourceRoot":"","sources":["../../test/integration.spec.ts"],"names":[],"mappings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AY,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(\n public data: Buffer | ArrayBuffer | Buffer[],\n public isBinary: boolean,\n ) {\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"]}
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,YACS,IAAqC,EACrC,QAAiB;QADjB,SAAI,GAAJ,IAAI,CAAiC;QACrC,aAAQ,GAAR,QAAQ,CAAS;QAExB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,YAAY,GAAG,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AM,WAAW,CAAC,OAAO,CAAC;QAE1B,gDAAgD;QAChD,MAAM,aAAa,CAAC,sBAAsB,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAEvF,gDAAgD;QAChD,MAAM,aAAa,CAAC,SAAS,CAC3B,EAAE,OAAO,EAAE,UAAU,EAAE,EACvB,EAAE,MAAM,EAAE,2CAA2C,EAAE,CACxD,CAAC;QAEF,4BAA4B;QAC5B,MAAM,aAAa,CAAC,SAAS,CAAC,UAAU,EAAE;YACxC,WAAW,EAAE,YAAY;YACzB,MAAM,EAAE,2CAA2C;SACpD,CAAC,CAAC;QAEH,qCAAqC;QACrC,MAAM,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE;YAC7C,MAAM,EAAE,2CAA2C;SACpD,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(\n public data: Buffer | ArrayBuffer | Buffer[],\n public isBinary: boolean,\n ) {\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' 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' in groups and 'group2' in groups\",\n });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal(2), {\n filter: \"'group1' 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"]}
@@ -5,9 +5,6 @@ const envSetupForPlayback = {
5
5
  WPS_API_KEY: "api_key",
6
6
  WPS_ENDPOINT: "https://endpoint",
7
7
  WPS_REVERSE_PROXY_ENDPOINT: "https://endpoint",
8
- AZURE_CLIENT_ID: "azure_client_id",
9
- AZURE_CLIENT_SECRET: "azure_client_secret",
10
- AZURE_TENANT_ID: "azuretenantid",
11
8
  };
12
9
  const recorderOptions = {
13
10
  envSetupForPlayback,
@@ -1 +1 @@
1
- {"version":3,"file":"testEnv.js","sourceRoot":"","sources":["../../test/testEnv.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,MAAM,mBAAmB,GAA2B;IAClD,qBAAqB,EAAE,kDAAkD;IACzE,WAAW,EAAE,SAAS;IACtB,YAAY,EAAE,kBAAkB;IAChC,0BAA0B,EAAE,kBAAkB;IAC9C,eAAe,EAAE,iBAAiB;IAClC,mBAAmB,EAAE,qBAAqB;IAC1C,eAAe,EAAE,eAAe;CACjC,CAAC;AAEF,MAAM,eAAe,GAAyB;IAC5C,mBAAmB;CACpB,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RecorderStartOptions } from \"@azure-tools/test-recorder\";\n\nconst envSetupForPlayback: Record<string, string> = {\n WPS_CONNECTION_STRING: \"Endpoint=endpoint;AccessKey=api_key;Version=1.0;\",\n WPS_API_KEY: \"api_key\",\n WPS_ENDPOINT: \"https://endpoint\",\n WPS_REVERSE_PROXY_ENDPOINT: \"https://endpoint\",\n AZURE_CLIENT_ID: \"azure_client_id\",\n AZURE_CLIENT_SECRET: \"azure_client_secret\",\n AZURE_TENANT_ID: \"azuretenantid\",\n};\n\nconst recorderOptions: RecorderStartOptions = {\n envSetupForPlayback,\n};\n\nexport default recorderOptions;\n"]}
1
+ {"version":3,"file":"testEnv.js","sourceRoot":"","sources":["../../test/testEnv.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,MAAM,mBAAmB,GAA2B;IAClD,qBAAqB,EAAE,kDAAkD;IACzE,WAAW,EAAE,SAAS;IACtB,YAAY,EAAE,kBAAkB;IAChC,0BAA0B,EAAE,kBAAkB;CAC/C,CAAC;AAEF,MAAM,eAAe,GAAyB;IAC5C,mBAAmB;CACpB,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RecorderStartOptions } from \"@azure-tools/test-recorder\";\n\nconst envSetupForPlayback: Record<string, string> = {\n WPS_CONNECTION_STRING: \"Endpoint=endpoint;AccessKey=api_key;Version=1.0;\",\n WPS_API_KEY: \"api_key\",\n WPS_ENDPOINT: \"https://endpoint\",\n WPS_REVERSE_PROXY_ENDPOINT: \"https://endpoint\",\n};\n\nconst recorderOptions: RecorderStartOptions = {\n envSetupForPlayback,\n};\n\nexport default recorderOptions;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/web-pubsub",
3
- "version": "1.1.3-alpha.20240528.1",
3
+ "version": "1.1.3",
4
4
  "description": "Azure client library for Azure Web PubSub",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -78,7 +78,7 @@
78
78
  "jsonwebtoken": "^9.0.0"
79
79
  },
80
80
  "devDependencies": {
81
- "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
81
+ "@azure/dev-tool": "^1.0.0",
82
82
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
83
83
  "@azure-tools/test-utils": "^1.0.1",
84
84
  "@azure-tools/test-credential": "^1.0.0",
@@ -104,12 +104,12 @@
104
104
  "karma-mocha-reporter": "^2.2.5",
105
105
  "karma-sourcemap-loader": "^0.3.8",
106
106
  "mocha": "^10.0.0",
107
- "nyc": "^15.1.0",
107
+ "nyc": "^17.0.0",
108
108
  "puppeteer": "^22.2.0",
109
109
  "rimraf": "^5.0.5",
110
110
  "sinon": "^17.0.0",
111
111
  "source-map-support": "^0.5.9",
112
- "typescript": "~5.4.5",
112
+ "typescript": "~5.5.3",
113
113
  "ws": "^8.2.0",
114
114
  "ts-node": "^10.0.0"
115
115
  },
@@ -51,6 +51,12 @@ export declare interface GenerateClientTokenOptions extends OperationOptions {
51
51
  * The groups to join when the client connects
52
52
  */
53
53
  groups?: string[];
54
+ /**
55
+ * The protocol type of the client
56
+ * * `default`: Default WebPubSub Client. Example Client Connection URL: _wss://exampleHost.com/client/hubs/exampleHub_
57
+ * * `mqtt`: MQTT Client. Example Client Connection URL: _wss://exampleHost.com/client/mqtt/hubs/exampleHub_
58
+ */
59
+ clientProtocol?: WebPubSubClientProtocol;
54
60
  }
55
61
 
56
62
  /**
@@ -332,6 +338,11 @@ export declare function odata(strings: TemplateStringsArray, ...values: unknown[
332
338
 
333
339
  export declare type Permission = "joinLeaveGroup" | "sendToGroup";
334
340
 
341
+ /**
342
+ * The type of client endpoint that is being requested.
343
+ */
344
+ export declare type WebPubSubClientProtocol = "default" | "mqtt";
345
+
335
346
  export declare interface WebPubSubGroup {
336
347
  /**
337
348
  * The name of this group