{"_id":"@azure/web-pubsub-chat","name":"@azure/web-pubsub-chat","dist-tags":{"beta":"1.0.0-beta.1","latest":"1.0.0-beta.1"},"versions":{"1.0.0-beta.1":{"name":"@azure/web-pubsub-chat","version":"1.0.0-beta.1","description":"Azure client library for Azure Web PubSub Chat","engines":{"node":">=22.0.0"},"sideEffects":false,"autoPublish":false,"type":"module","main":"./dist/commonjs/index.js","module":"./dist/esm/index.js","types":"./dist/commonjs/index.d.ts","exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./api":{"import":{"types":"./dist/esm/api/index.d.ts","default":"./dist/esm/api/index.js"},"require":{"types":"./dist/commonjs/api/index.d.ts","default":"./dist/commonjs/api/index.js"}},"./models":{"import":{"types":"./dist/esm/models/index.d.ts","default":"./dist/esm/models/index.js"},"require":{"types":"./dist/commonjs/models/index.d.ts","default":"./dist/commonjs/models/index.js"}}},"keywords":["node","azure","cloud","typescript"],"author":{"name":"Microsoft Corporation"},"license":"MIT","sdk-type":"client","repository":{"type":"git","url":"git+https://github.com/Azure/azure-sdk-for-js.git","directory":"sdk/web-pubsub/web-pubsub-chat"},"bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-chat/README.md","prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","//metadata":{"constantPaths":[{"path":"src/api/webPubSubChatServiceContext.ts","prefix":"userAgentInfo"}]},"dependencies":{"@azure/core-util":"^1.12.0","@azure-rest/core-client":"^2.3.1","@azure/core-auth":"^1.9.0","@azure/core-rest-pipeline":"^1.20.0","@azure/core-tracing":"^1.2.0","@azure/logger":"^1.2.0","@azure/web-pubsub":"^1.2.0","jsonwebtoken":"^9.0.0","tslib":"^2.8.1"},"devDependencies":{"@azure-tools/test-credential":"^2.1.2","@azure-tools/test-recorder":"^4.1.1","@azure-tools/test-utils-vitest":"^2.0.1","@azure/dev-tool":"^1.0.0","@azure/eslint-plugin-azure-sdk":"^3.0.0","@azure/web-pubsub-chat-client":"1.0.0-beta.2","@azure/identity":"4.13.0","@types/jsonwebtoken":"^9.0.0","@types/node":"^22.0.0","cross-env":"^10.1.0","eslint":"^10.8.0","prettier":"^3.9.1","rimraf":"^6.1.0","@vitest/browser-playwright":"^4.1.2","@vitest/coverage-istanbul":"^4.1.2","dotenv":"^16.6.1","playwright":"^1.60.0","typescript":"~6.0.2","vitest":"^4.1.2"},"//sampleConfiguration":{"productName":"@azure/web-pubsub-chat","productSlugs":["azure"],"disableDocsMs":true,"apiRefLink":"https://learn.microsoft.com/javascript/api/@azure/web-pubsub-chat?view=azure-node-preview"},"scripts":{"clean":"rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log","extract-api":"rimraf review && dev-tool run extract-api","pack":"pnpm pack 2>&1","lint":"eslint package.json src test","lint:fix":"eslint package.json src test --fix --fix-type [problem,suggestion]","build:samples":"tsc -p config/tsconfig.samples.json","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\" \"samples-dev/*.ts\"","execute:samples":"dev-tool samples run samples-dev","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.{ts,cts,mts}\" \"test/**/*.{ts,cts,mts}\" \"*.{js,cjs,mjs,json}\" \"samples-dev/*.ts\"","generate:client":"tsp-client update -d && npm run customize","test:browser":"echo skipped","build":"npm run clean && dev-tool run build-package && dev-tool run extract-api","test:node":"dev-tool run test:vitest","test":"tsc -b --noEmit && npm run test:node && npm run test:browser","update-snippets":"dev-tool run update-snippets","customize":"npm run format && dev-tool customization apply --skip index.ts"},"_id":"@azure/web-pubsub-chat@1.0.0-beta.1","_integrity":"sha512-kjE79fumX/w384hh5b87y++EyV5odJycwX+xq95yGFW2lvCc8LZU6V1B9qlGh3OCY3JjEIcsTQyJJsreCsf6Kw==","_resolved":"M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App1\\temp\\d5fa0402-9dff-4b9a-9007-ccf654e8b055\\azure-web-pubsub-chat-1.0.0-beta.1.tgz","_from":"file:M:\\SvcFab\\_App\\MS.Ess.PackageManager.Publisher_App1\\temp\\d5fa0402-9dff-4b9a-9007-ccf654e8b055\\azure-web-pubsub-chat-1.0.0-beta.1.tgz","tag":"beta","_nodeVersion":"18.5.0","dist":{"integrity":"sha512-kjE79fumX/w384hh5b87y++EyV5odJycwX+xq95yGFW2lvCc8LZU6V1B9qlGh3OCY3JjEIcsTQyJJsreCsf6Kw==","shasum":"9088999dcb717b7addfac3fe88f294fe444ad570","tarball":"https://registry.npmjs.org/@azure/web-pubsub-chat/-/web-pubsub-chat-1.0.0-beta.1.tgz","fileCount":109,"unpackedSize":478639,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDco81fyi+v7JZrVGSKI3smOQfrfPvtv8D6zeFzqu5wxwIgJWSNti7VnM4eKPyZxHTYzDLajPZlGe21cZ/0TkM9+FA="}]},"_npmUser":{"name":"microsoft1es","email":"npmjs@microsoft.com"},"directories":{},"maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"microsoft1es","email":"npmjs@microsoft.com"},{"name":"microsoft-oss-releases","email":"microsoft-oss-publishing@microsoft.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/web-pubsub-chat_1.0.0-beta.1_1788449203714_0.7436448339397455"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-03T15:26:43.430Z","1.0.0-beta.1":"2026-09-03T15:26:43.919Z","modified":"2026-09-03T15:26:44.271Z"},"maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"microsoft1es","email":"npmjs@microsoft.com"},{"name":"microsoft-oss-releases","email":"microsoft-oss-publishing@microsoft.com"}],"description":"Azure client library for Azure Web PubSub Chat","homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-chat/README.md","keywords":["node","azure","cloud","typescript"],"repository":{"type":"git","url":"git+https://github.com/Azure/azure-sdk-for-js.git","directory":"sdk/web-pubsub/web-pubsub-chat"},"author":{"name":"Microsoft Corporation"},"bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"license":"MIT","readme":"# Azure Web PubSub Chat client library for JavaScript\n\nThe Azure Web PubSub Chat client library enables server applications to manage chat roles, users, rooms, room membership, conversations, and messages in an Azure Web PubSub Chat hub.\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing Azure Web PubSub resource.\n- A hub name for the chat application.\n\n### Install the `@azure/web-pubsub-chat` package\n\nInstall the Azure WebPubSubChatService client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/web-pubsub-chat\n```\n\n### Create and authenticate a `WebPubSubChatServiceClient`\n\nThe `WebPubSubChatServiceClient` supports authentication with a connection string, a Microsoft Entra credential, or an `AzureKeyCredential`.\n\n#### Authenticate with a connection string\n\nYou can find the connection string for your Azure Web PubSub resource in the [Azure Portal][azure_portal]. Because the connection string contains an access key, store it securely and do not include it in source code.\n\n#### Authenticate with Microsoft Entra ID\n\nTo authenticate with Microsoft Entra ID, you will need the `endpoint` of your Azure Web PubSub resource and a credential. You can find the endpoint in the [Azure Portal][azure_portal].\n\nYou can authenticate with Microsoft Entra ID using a credential from the [@azure/identity][azure_identity] library or [an existing Microsoft Entra token](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token).\n\nTo use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:\n\n```bash\nnpm install @azure/identity\n```\n\n`DefaultAzureCredential` supports several Microsoft Entra identities. During local development, it can use a developer identity signed in through a supported development tool. In Azure, it can use a managed identity. It can also authenticate a service principal or workload identity when configured for the environment.\n\nWhichever identity you use must be assigned an appropriate Azure Web PubSub data-plane role. Azure resource-management roles such as `Owner` do not grant data-plane permissions.\n\nCreate the client with a connection string, a Microsoft Entra credential such as `DefaultAzureCredential`, or an `AzureKeyCredential`.\n\n```ts snippet:ReadmeSampleCreateClient\nimport { WebPubSubChatServiceClient, AzureKeyCredential } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst connectionStringClient = new WebPubSubChatServiceClient(\"<connectionString>\", \"<hubName>\");\nconst tokenCredentialClient = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst keyCredentialClient = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new AzureKeyCredential(\"<accessKey>\"),\n  \"<hubName>\",\n);\n```\n\n## Key concepts\n\n### WebPubSubChatServiceClient\n\n`WebPubSubChatServiceClient` is the primary interface for managing chat resources in a Web PubSub hub.\n\n### Hub\n\nA hub is the logical boundary for a chat application. Roles, users, rooms, conversations, and messages managed by a client all belong to the hub supplied to the client constructor.\n\n### Roles and permissions\n\nA user role controls hub-level actions such as creating rooms. A room role controls actions within a room, such as publishing messages, reading message history, or inviting users.\n\n### Rooms, members, and conversations\n\nA room contains members and has a default conversation. Add a user to a room by assigning the user a room role. Messages are published by connected chat clients and can be listed, updated, or deleted through the service client.\n\n### Entity tags\n\nChat resources include an `etag` value. Pass that value through an operation's `ifMatch` option to perform a conditional update or delete and prevent overwriting a newer resource version.\n\n## Examples\n\n### Set up roles, a user, and a room\n\nCreate user and room roles, create a human user and a room, and then add the user to the room.\n\n```ts snippet:ReadmeSampleSetUpChatResources\nimport { WebPubSubChatServiceClient, KnownChatPermission } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst userRoleName = \"user.contoso_member\";\nconst roomRoleName = \"room.contoso_member\";\nconst userId = \"alice\";\nconst roomId = \"general\";\nawait client.createOrReplaceRole(userRoleName, {\n  permissions: [KnownChatPermission.UserCreateRoom],\n});\nawait client.createOrReplaceRole(roomRoleName, {\n  permissions: [KnownChatPermission.RoomPublishMessage, KnownChatPermission.RoomHistory],\n});\nawait client.createOrReplaceUser(userId, {\n  kind: \"Human\",\n  nickname: \"Alice\",\n  roleName: userRoleName,\n});\nconst room = await client.createOrReplaceRoom(roomId, { title: \"General\" });\nawait client.createOrReplaceRoomMember(roomId, userId, { roleName: roomRoleName });\nconsole.log(`Created room ${room.id} with conversation ${room.defaultConversation}`);\n```\n\n### Use built-in roles and known permissions\n\nUse `BuiltInChatRoles` when assigning a service-defined role and `KnownChatPermission` when creating a custom role. Permission strings outside the known values are also accepted for forward compatibility.\n\n```ts snippet:ReadmeSampleUseBuiltInRolesAndKnownPermissions\nimport {\n  WebPubSubChatServiceClient,\n  BuiltInChatRoles,\n  KnownChatPermission,\n} from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nawait client.createOrReplaceUser(\"alice\", {\n  kind: \"Human\",\n  nickname: \"Alice\",\n  roleName: BuiltInChatRoles.UserNormal,\n});\nawait client.createOrReplaceRole(\"room.moderator\", {\n  permissions: [\n    KnownChatPermission.RoomHistory,\n    KnownChatPermission.RoomRemoveUser,\n    KnownChatPermission.RoomPublishMessage,\n  ],\n});\n```\n\n### Manage roles\n\nCreate a custom role, retrieve it, list the roles in the hub, and delete the custom role when finished.\n\n```ts snippet:ReadmeSampleManageRoles\nimport { WebPubSubChatServiceClient, KnownChatPermission } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst roleName = \"user.contoso_member\";\ntry {\n  const role = await client.createOrReplaceRole(roleName, {\n    permissions: [KnownChatPermission.UserCreateRoom, KnownChatPermission.UserFetchAllRooms],\n  });\n  console.log(`Created role: ${role.name}`);\n  const fetchedRole = await client.getRole(roleName);\n  console.log(`Fetched role: ${fetchedRole.name}`);\n  for await (const listedRole of client.listRoles()) {\n    console.log(`Role: ${listedRole.name}`);\n  }\n} finally {\n  await client.deleteRole(roleName);\n}\n```\n\n### Manage a room\n\nCreate a room, retrieve its current state, and delete it.\n\n```ts snippet:ReadmeSampleManageRoom\nimport { WebPubSubChatServiceClient } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst roomId = \"general\";\nconst room = await client.createOrReplaceRoom(roomId, { title: \"General\" });\nconsole.log(`Created room ${room.id} with conversation ${room.defaultConversation}`);\nconst fetchedRoom = await client.getRoom(roomId);\nconsole.log(`Fetched room: ${fetchedRoom.id}, title: ${fetchedRoom.title}`);\nawait client.deleteRoom(roomId);\n```\n\n### Manage a user\n\nCreate a user with a built-in role, retrieve the profile, and delete it.\n\n```ts snippet:ReadmeSampleManageUser\nimport { WebPubSubChatServiceClient, BuiltInChatRoles } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst userId = \"alice\";\nconst user = await client.createOrReplaceUser(userId, {\n  kind: \"Human\",\n  nickname: \"Alice\",\n  roleName: BuiltInChatRoles.UserNormal,\n});\nconsole.log(`Created user: ${user.id}, nickname: ${user.nickname}`);\nconst fetchedUser = await client.getUser(userId);\nconsole.log(`Fetched user: ${fetchedUser.id}, nickname: ${fetchedUser.nickname}`);\nawait client.deleteUser(userId);\n```\n\n### List messages in a conversation\n\nUse asynchronous iteration to read messages from a conversation across all result pages.\n\n```ts snippet:ReadmeSampleListMessages\nimport { WebPubSubChatServiceClient } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nfor await (const message of client.listMessages(\"<conversationId>\")) {\n  console.log(`${message.createdBy}: ${message.content.text}`);\n}\n```\n\n### Generate a client access token\n\nGenerate a URL that a chat client can use to connect to the Web PubSub service as a specific user.\n\n```ts snippet:ReadmeSampleGetClientAccessToken\nimport { WebPubSubChatServiceClient } from \"@azure/web-pubsub-chat\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n\nconst client = new WebPubSubChatServiceClient(\n  \"<endpoint>\",\n  new DefaultAzureCredential(),\n  \"<hubName>\",\n);\nconst accessToken = await client.getClientAccessToken({ userId: \"alice\" });\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```ts snippet:SetLogLevel\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.\n\n[azure_sub]: https://azure.microsoft.com/free/\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n","readmeFilename":"README.md","_rev":"1-d564da6c1dc25a0c2aa15b45ad61cdde"}