{"_id":"@b2chat/chat-center-widget-sdk","_rev":"16-0a360b68a1841908439435d2842157b5","name":"@b2chat/chat-center-widget-sdk","dist-tags":{"latest":"2.1.1"},"versions":{"2.1.0":{"name":"@b2chat/chat-center-widget-sdk","version":"2.1.0","license":"MIT","_id":"@b2chat/chat-center-widget-sdk@2.1.0","maintainers":[{"name":"b2chatnpm","email":"felipe@b2chat.io"},{"name":"jaimeg123","email":"jaime@b2chat.io"},{"name":"smithb2chat","email":"smith@b2chat.io"},{"name":"lnavas","email":"lauranavas@b2chat.io"},{"name":"jhonber","email":"jhon@b2chat.io"},{"name":"carlosb2chat","email":"carlos@b2chat.io"}],"dist":{"shasum":"f21aaa3d1712b00dad6ac6724627fe006c228bba","tarball":"https://registry.npmjs.org/@b2chat/chat-center-widget-sdk/-/chat-center-widget-sdk-2.1.0.tgz","fileCount":97,"integrity":"sha512-SKyV3QrgwGnvA4uE56rPKfdLoB6lOkM9HfB5A7pHDYLUzZiX8vN39sTTWc18HtB0RR2ry8LPM04Jj3BRyq5Xzw==","signatures":[{"sig":"MEQCIFRTN5H49td0uQ+YA9+XHUcfUT07iwDsCOIr5xS+izrCAiBUR5D6jQCjOxxIWrVIWOmcBbF2pNxatyNVr+i30auB1g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":150208},"main":"./dist/index.js","types":"./dist/index.d.ts","gitHead":"1291b78558c49570cb846627c6b133e40fcde166","scripts":{"test":"jest","build":"tsc","bump:major":"yarn version --no-git-tag-version --major","bump:minor":"yarn version --no-git-tag-version --minor","bump:patch":"yarn version --no-git-tag-version --patch","test:watch":"NODE_OPTIONS=--experimental-vm-modules jest --watch","postversion":"bin/postversion.sh"},"_npmUser":{"name":"jhonber","email":"jhon@b2chat.io"},"_npmVersion":"10.8.2","description":"> **📦 Package moved:** This package was previously published as > `@b2chatorg/chat-center-widget-sdk`. It now lives under the official B2Chat organization > scope as **`@b2chat/chat-center-widget-sdk`**. Please update your imports and > `package.json` de","directories":{},"_nodeVersion":"20.18.3","browserslist":"> 0.5%, last 2 versions, not dead","dependencies":{"jose":"^5.3.0"},"publishConfig":{"registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","jsdom":"^22.1.0","babel-jest":"^29.7.0","typescript":"^5.2.2","@babel/core":"^7.22.20","@types/react":"^18.2.21","@types/redux":"^3.6.0","@jest/globals":"^29.7.0","@babel/preset-env":"^7.22.20","@babel/preset-typescript":"^7.22.15"},"_npmOperationalInternal":{"tmp":"tmp/chat-center-widget-sdk_2.1.0_1783358151401_0.5431603601704094","host":"s3://npm-registry-packages-npm-production"}},"2.0.2":{"name":"@b2chat/chat-center-widget-sdk","version":"2.0.2","license":"MIT","_id":"@b2chat/chat-center-widget-sdk@2.0.2","maintainers":[{"name":"b2chatnpm","email":"felipe@b2chat.io"},{"name":"jaimeg123","email":"jaime@b2chat.io"},{"name":"smithb2chat","email":"smith@b2chat.io"},{"name":"lnavas","email":"lauranavas@b2chat.io"},{"name":"jhonber","email":"jhon@b2chat.io"},{"name":"carlosb2chat","email":"carlos@b2chat.io"}],"dist":{"shasum":"fa0ad9afa8fbb150cd5f05d6f9a71e7ba279947e","tarball":"https://registry.npmjs.org/@b2chat/chat-center-widget-sdk/-/chat-center-widget-sdk-2.0.2.tgz","fileCount":97,"integrity":"sha512-FYPQSyAfOJalhIHdoJ7hdazpjh6e5kC4nCoS6938H/L6zGZitdVe1NkOsDBl5SVSRpDRboVgDpEwflnaIfMe+g==","signatures":[{"sig":"MEUCIEOFNslby/X7sO7Kuz3/wVQuIrBoFM+lrGNyfa2qb8euAiEAl+C0X3/Lu60poKijVnltCBsTRVm9ty7EsBbX3MzPmRk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":149625},"main":"./dist/index.js","types":"./dist/index.d.ts","gitHead":"abfb362e0a1f9b3ea5f86a1519b80698e13a4152","scripts":{"test":"jest","build":"tsc","bump:major":"yarn version --no-git-tag-version --major","bump:minor":"yarn version --no-git-tag-version --minor","bump:patch":"yarn version --no-git-tag-version --patch","test:watch":"NODE_OPTIONS=--experimental-vm-modules jest --watch","postversion":"bin/postversion.sh"},"_npmUser":{"name":"carlosb2chat","email":"carlos@b2chat.io"},"_npmVersion":"10.8.2","description":"This is small lib that allows interoperabilty with [B2Chat Console](https://app.b2chat.io/agent/chat])","directories":{},"_nodeVersion":"20.18.1","browserslist":"> 0.5%, last 2 versions, not dead","dependencies":{"jose":"^5.3.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","jsdom":"^22.1.0","babel-jest":"^29.7.0","typescript":"^5.2.2","@babel/core":"^7.22.20","@types/react":"^18.2.21","@types/redux":"^3.6.0","@jest/globals":"^29.7.0","@babel/preset-env":"^7.22.20","@babel/preset-typescript":"^7.22.15"},"_npmOperationalInternal":{"tmp":"tmp/chat-center-widget-sdk_2.0.2_1783366645391_0.5877388601219118","host":"s3://npm-registry-packages-npm-production"}},"2.1.1":{"name":"@b2chat/chat-center-widget-sdk","version":"2.1.1","license":"MIT","main":"./dist/index.js","scripts":{"build":"tsc","test":"jest","test:watch":"NODE_OPTIONS=--experimental-vm-modules jest --watch","bump:patch":"yarn version --no-git-tag-version --patch","bump:minor":"yarn version --no-git-tag-version --minor","bump:major":"yarn version --no-git-tag-version --major","postversion":"bin/postversion.sh"},"browserslist":"> 0.5%, last 2 versions, not dead","devDependencies":{"@babel/core":"^7.22.20","@babel/preset-env":"^7.22.20","@babel/preset-typescript":"^7.22.15","@jest/globals":"^29.7.0","@types/react":"^18.2.21","@types/redux":"^3.6.0","babel-jest":"^29.7.0","jest":"^29.7.0","jsdom":"^22.1.0","typescript":"^5.2.2"},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"dependencies":{"jose":"^5.3.0"},"description":"> **📦 Package moved:** This package was previously published as > `@b2chatorg/chat-center-widget-sdk`. It now lives under the official B2Chat organization > scope as **`@b2chat/chat-center-widget-sdk`**. Please update your imports and > `package.json` de","_id":"@b2chat/chat-center-widget-sdk@2.1.1","dist":{"shasum":"b395054741da38854164f37fc1e84645a60c7c80","integrity":"sha512-iyeWd5h/vK1BP3CahM5dP2ai3ljI/w66mS7iFVqNJlQO9hXLkoQe6Qw+MPziKlGy0fHzFlgQmoe0oMHt1nhB+A==","tarball":"https://registry.npmjs.org/@b2chat/chat-center-widget-sdk/-/chat-center-widget-sdk-2.1.1.tgz","fileCount":110,"unpackedSize":149962,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCdAIktCgz7SfkRN0dkd7UmA0/JwYwcLIOtsrtIsSyHLwIhALupyk3aNv09z6bFKav7ek5YiX2QO3Kqv/BBo63PCIE1"}]},"_npmUser":{"name":"carlosb2chat","email":"carlos@b2chat.io"},"directories":{},"maintainers":[{"name":"b2chatnpm","email":"felipe@b2chat.io"},{"name":"jaimeg123","email":"jaime@b2chat.io"},{"name":"smithb2chat","email":"smith@b2chat.io"},{"name":"lnavas","email":"lauranavas@b2chat.io"},{"name":"jhonber","email":"jhon@b2chat.io"},{"name":"carlosb2chat","email":"carlos@b2chat.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/chat-center-widget-sdk_2.1.1_1783369394523_0.025926132012068726"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-06T17:15:51.116Z","modified":"2026-07-06T20:23:14.863Z","1.0.0":"2023-09-15T15:07:29.852Z","1.0.1":"2023-09-20T20:33:38.477Z","1.0.2":"2023-09-20T20:35:41.842Z","1.1.1":"2023-11-09T21:00:26.694Z","2.1.0":"2026-07-06T17:15:51.564Z","2.0.2":"2026-07-06T19:37:25.526Z","2.1.1":"2026-07-06T20:23:14.644Z"},"license":"MIT","description":"> **📦 Package moved:** This package was previously published as > `@b2chatorg/chat-center-widget-sdk`. It now lives under the official B2Chat organization > scope as **`@b2chat/chat-center-widget-sdk`**. Please update your imports and > `package.json` de","maintainers":[{"name":"b2chatnpm","email":"felipe@b2chat.io"},{"name":"jaimeg123","email":"jaime@b2chat.io"},{"name":"smithb2chat","email":"smith@b2chat.io"},{"name":"lnavas","email":"lauranavas@b2chat.io"},{"name":"jhonber","email":"jhon@b2chat.io"},{"name":"carlosb2chat","email":"carlos@b2chat.io"}],"readme":"## @b2chat/chat-center-widget-sdk\n\n> **📦 Package moved:** This package was previously published as\n> `@b2chatorg/chat-center-widget-sdk`. It now lives under the official B2Chat organization\n> scope as **`@b2chat/chat-center-widget-sdk`**. Please update your imports and\n> `package.json` dependency accordingly — the old `@b2chatorg` package is no longer maintained.\n\nThis is small lib that allows interoperabilty with [B2Chat Console](https://app.b2chat.io/agent/chat])\n\n## Getting start\n\n- [Installation](#Installation)\n- [Usage](#Usage)\n\n## [Core](#Core)\n\n- [EventEmitter](#EventEmitter)\n- [Writable](#Writable)\n- [Readable](#Readable)\n- [React hook useAsyncFunction](#React%20Hook%20UseAsyncFunction)\n\n## [B2ChatStore](#B2ChatStore)\n\n- [Properties](#Properties)\n  - [activeChat](#activeChat:%20Readable<Chat>)\n  - [agentInfo](#agentInfo:%20Readable<AgentInfo>)\n  - [departments](#departments:%20Readable<Department[]>)\n  - [inputMessageContent](#inputMessageContent:%20InputMessageContent)\n- [Events](#Events)\n  - [chatClosed](#chatClosed)\n- [Methods](#Methods)\n  - [findChat](#findChat)\n  - [getTags](#getTags)\n  - [assignedTags](#assignedTags)\n  - [assignTags](#assignTags)\n  - [unassignTags](#unassignTags)\n  - [setInputMessageContent](#setInputMessageContent)\n  - [updateChatInfo](#updateChatInfo)\n  - [getContactInfoProperties](#getContactInfoProperties)\n  - [getUUID](#getUUID)\n  - [sendMessage](#sendMessage)\n  - [findContact](#findContact)\n  - [Types](#Types)\n\n<br>\n<br>\n\n# Installation\n\nWe recommend to use this **React** [template](https://github.com/b2chat/cra-template-b2chat-widget) to bootstrap a widget\n\nBut if you prefer use a different UI lib than **React** as **Svelte** or **Vue**, only need to install this package:\n\n```sh\nnpm install @b2chat/chat-center-widget-sdk\n```\n\nand start the development server at **3010** port.\n\n### Usage\n\nYou can subscribe to properties.\n\n```js\nimport { getB2ChatStore } from \"@b2chat/chat-center-widget-sdk\";\n\n/// get b2chat store instance\nconst store = getB2ChatStore();\n\n// subscribe to new changes\nconst unsub = store.state.activeChat.subscribe((chat) => {\n  console.log(chat);\n});\n\n// stop receive changes\nunsub();\n```\n\nYou can do the same with React.\n\n```jsx\nimport { useEffect, useState } from \"react\";\nimport { useB2ChatStore } from \"@b2chat/chat-center-widget-sdk/dist/react\";\n\nconst App = () => {\n  const { state } = useB2ChatStore();\n\n  useEffect(() => { // subscribe to new changes\n    console.log(state.activeChat);\n  }, [state.activeChat]);\n\n  return (\n    <div>{state.activeChat.chatId}<div>\n  );\n};\n```\n\n# Core\n\nThese are utils that are available for public usage and are the core of this SDK.\n\n## EventEmitter [➡️]()\n\n```ts\nimport { eventEmitter } from \"@b2chat/chat-center-widget-sdk/dist/utils/eventEmitter\";\n\nconst eventEmitter: <T>(start?: StartStopNotifier<T>) => EventEmitter<T>;\n```\n\nA function that create a minimal **EventEmitter** to dispatch a single event type. It is an object with `dispatch` and `subscribe` methods.\n\n#### `subscribe`, `dispatch` Methods\n\n```ts\n// start: StartStopNotifier\nconst emitter = eventEmitter<string>();\n\nconst unsubscribe = emitter.subscribe((event) => console.log(event));\n\nemitter.dispatch(\"hello\"); // logs 'hello'\n\nunsubscribe(); // unsubscribe\n\nemitter.dispatch(\"world\"); // does nothing\n```\n\n#### `start/stop` Lifecycle\n\n`start` is executed just before the first subscription, it could returns a `stop` callback that will be executed by the emitter after the last unsubscription.\n\n```ts\n// `start` callback\nconst emitter = eventEmitter<string>((dispatch) => {\n  console.log(\"first subscriber\");\n\n  // `stop` callback\n  return () => console.log(\"no subscribers\");\n});\n\nemitter.dispatch(\"hello\"); // does nothing\n\nconst unsub = emitter.subscribe((event) => {\n  console.log(event);\n}); // logs `first subscriber`;\n\nemitter.dispatch(\"hello\"); // logs 'hello'\n\nunsub(); // will exec `stop` callback and logs 'no subscribers'\n```\n\n# Writable\n\n```ts\nexport const writable = <T>(\n  initialValue: T,\n  start?: StartStopNotifier<T>,\n  equalFn: EqualFn<T> = strictEquals\n) => Writable<T>;\n```\n\nIt creates a mutable value **observable**\n\n### Usage\n\n#### `subscribe`, `get`, `set` and `update`\n\n```ts\nimport { writable } from \"@b2chat/chat-center-widget-sdk/dist/utils/store\";\n\nconst count = writable<number>(0);\n\nconst unsub = count.subscribe((value) => console.log(value));\n\ncount.set(2); // logs '1'\nconsole.log(count.get()); // logs '1'\n\ncount.update((current) => current + 1); // increments count and logs '2'\n\nunsub(); // unobserve count\n```\n\n#### `when(predicate)`\n\nIt waits for condition to be fulfill\n\n```ts\nconst counter = writable(0, (set, update) => {\n  const interval = setInterval(() => {\n    update(val => val + 1)\n  }, 1000)\n\n  return () => clearInterval(interval)\n});\n\nasync waitUntil10() {\n  await counter.when(val => val === 10)\n  console.log('10 reached!')\n}\n\nwaitUntil10()\n```\n\n# Readable\n\n```ts\nexport const readable = <T>(\n  initialValue: T,\n  start?: StartStopNotifier<T>,\n  equalFn: EqualFn<T> = strictEquals\n): Readable<T> => writable(initialValue, start, equalFn);\n```\n\nSimilar to a `Writable` but it is a **non-mutable observable**\n\n### Example:\n\n```ts\nimport { readable } from \"@b2chat/chat-center-widget-sdk/dist/utils/store\";\n\nconst ticktock = readable(\"tick\", (set, update) => {\n  const interval = setInterval(() => {\n    update((sound) => (sound == \"tick\" ? \"tock\" : \"tick\"));\n  }, 1000);\n\n  return () => clearInterval(interval);\n});\n\nconst unsub = ticktock.subscribe((value) => console.log(value)); // logs 'tick' or 'tock' each seg\n\nunsub(); // unobserve tictock and stop ticktock\n```\n\n# React Hook `UseAsyncFunction`\n\n```ts\nconst useAsyncFunction = <\n  Fn extends (...args: any[]) => Promise<any>,\n  E = Error\n>(\n  fn: Fn,\n  initialResult?: Awaited<ReturnType<Fn>>\n) => UseAsyncFunctionInstance<Fn, E>;\n\ntype UseAsyncFunctionInstance<\n  Fn extends (...args: any[]) => Promise<any>,\n  E = unknown\n> = {\n  args: Parameters<Fn> | [];\n  result: Awaited<ReturnType<Fn>>;\n  error: E;\n  isPending: boolean;\n  isSuccess: true;\n  isError: false;\n};\n```\n\nThis is a React hook to manage async calls, it takes a async `fn` and optionally an `initialResult` to use as initial value for result prop\n\n### Usage\n\n```tsx\nimport useAsyncFunction from \"@b2chat/chat-center-widget-sdk/dist/react/useAsyncFunction\";\n\nconst doLogin = async (user: string) => {\n  await new Promise(r => setTimeout(r, 2000)); // wait 2 seg\n\n  if (user === \"david\") return { user };\n\n  throw new Error(\"Unknown user\");\n};\n\nconst App = () => {\n  const login = useAsyncFunction(doLogin);\n\n  useEffect(() => {\n    login('david')\n  }, [])\n\n  return (\n    <div>\n      {login.isPending & \"loading...\"}\n      {login.isSuccess && (<div>Login success: {login.result.user}<div>)}\n      {login.isError && (<div>Login failed: {login.error.message}<div>)}\n    </div>\n  );\n};\n\n```\n\n</br>\n\n# B2ChatStore\n\n**B2ChatStore** is simply a set of _properties_, _events_ and _methods_ that allow subscribe, listen or take actions inside the B2Chat console. It is agnostic to any **UI** library but there are some pretty easy utils to work with React.\n\n**JS** vanilla\n\n```ts\nimport { getB2ChatStore } from \"@b2chat/chat-center-widget-sdk\";\n\n/// get b2chat store instance\nconst store = getB2ChatStore();\n\n// subscribe to new changes\nconst unsub = store.state.activeChat.subscribe((chat) => {\n  console.log(chat);\n});\n\n// stop receive changes\nunsub();\n\nconst result = await store.methods.findChat({ contactName: \"foo\" }); // find a chat in the current tray\n```\n\nWith **React** library\n\n```tsx\nimport { useEffect, useState } from \"react\";\nimport { useB2ChatStore } from \"@b2chat/chat-center-widget-sdk/dist/react\";\n\nconst App = () => {\n  const { state } = useB2ChatStore();\n\n  useEffect(() => { // subscribe to new changes\n    console.log(state.activeChat);\n  }, [state.activeChat]);\n\n  return (\n    <div>{state.activeChat.chatId}<div>\n  );\n};\n```\n\n# Properties\n\n## `activeChat: Readable<Chat>`\n\nIt contains the Chat actually selected by the agent.\n\n### Example\n\n```tsx\nconst { state } = getB2ChatStore();\nstate.activeChat.subscribe((activeChat) => {\n  console.log(activeChat.chatId);\n});\n\n// or with React\nconst App = () => {\n  const { state } = useB2ChatStore();\n  return <div>{state.activeChat.chatId}</div>;\n};\n```\n\n## `agentInfo: Readable<AgentInfo>`\n\nIt has the basic information about the agent and the departments which it belongs.\nIf you want to search for an specific chat use : [findChat](#findChat:%20)\n\n### Example\n\n```tsx\nconst { state } = getB2ChatStore();\nstate.agentInfo.subscribe((agentInfo) => {\n  console.log(agentInfo.username);\n});\n\n// or with React\nconst App = () => {\n  const { state } = useB2ChatStore();\n  return <div>{state.agentInfo.username}</div>;\n};\n```\n\n## `departments: Readable<Department[]>`\n\nIt has the list the all posible departments for this merchant\n\n### Example\n\n```tsx\nconst { state } = getB2ChatStore();\nstate.departments.subscribe((departments) => {\n  departments.forEach((item) => console.log(item.tagName));\n});\n\n// or with React\nconst App = () => {\n  const { state } = useB2ChatStore();\n  return (\n    <>\n      {state.departments.map((item) => (\n        <div>{item.tagName}</div>\n      ))}\n    </>\n  );\n};\n```\n\n## `inputMessageContent: InputMessageContent`\n\nIt has the console input message. See [setInputMessageContent]() to modify its value\n\n### Example\n\n```tsx\nconst { state } = getB2ChatStore();\nstate.inputMessageContent.subscribe((content) => {\n  console.log(content.chatId, content.text);\n});\n\n// or with React\nconst App = () => {\n  const { state } = useB2ChatStore();\n  return <div>{state.inputMessageContent.text}</div>;\n};\n```\n\n<br>\n\n# Events\n\n## `onChatClosed: Emitter`\n\nevent emitted when a chat is closed wether by agent or contact\n\n# Methods\n\n## `findChat: (query: FindChatQuery) => Promise<FindChatResponse>`\n\nFind a chat by name, chatId or tags.\n\n> The query can be omitted to traverse through all chats\n\n```ts\nconst { methods } = getB2ChatStore();\nconst response = await findChat({ contactName: \"jean\", limit: 10 });\nconsole.log(response.data);\n```\n\n## Types\n\nAll types related to B2Chat are available at:\n\n```ts\nimport {...} from \"@b2chat/chat-center-widget-sdk/dist/types\";\n```\n\nPlease take a look to all types.\n","readmeFilename":"README.md"}