@zauru-sdk/components 6.20.16 → 6.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [6.21.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.20.17...@zauru-sdk/components@6.21.0) (2026-11-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * add Chatwoot website widget for remix apps ([9e0f76b](https://github.com/intuitiva/zauru-typescript-sdk/commit/9e0f76b1df8d459061d29a7a7e9730a3ef52d60a))
12
+
13
+
14
+
15
+
16
+
17
+ ## [6.20.17](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.20.16...@zauru-sdk/components@6.20.17) (2026-11-10)
18
+
19
+ **Note:** Version bump only for package @zauru-sdk/components
20
+
21
+
22
+
23
+
24
+
6
25
  ## [6.20.16](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.20.15...@zauru-sdk/components@6.20.16) (2026-11-10)
7
26
 
8
27
  **Note:** Version bump only for package @zauru-sdk/components
@@ -0,0 +1,20 @@
1
+ export type ChatwootUser = {
2
+ identifier: string;
3
+ email?: string;
4
+ name?: string;
5
+ companyName?: string;
6
+ avatarUrl?: string;
7
+ customAttributes?: Record<string, string | number | boolean | null | undefined>;
8
+ };
9
+ export type ChatwootWidgetProps = {
10
+ websiteToken: string;
11
+ baseUrl?: string;
12
+ identifierHash?: string;
13
+ user: ChatwootUser;
14
+ locale?: string;
15
+ position?: "left" | "right";
16
+ darkMode?: "light" | "auto" | "dark";
17
+ };
18
+ export declare function resetChatwoot(): void;
19
+ export declare function ChatwootWidget({ websiteToken, baseUrl, identifierHash, user, locale, position, darkMode, }: ChatwootWidgetProps): null;
20
+ export declare const Chatwoot: typeof ChatwootWidget;
@@ -0,0 +1 @@
1
+ export * from "./Chat.js";
@@ -0,0 +1,139 @@
1
+ import { useEffect } from "react";
2
+ const SCRIPT_ID = "chatwoot-sdk";
3
+ const DEFAULT_BASE_URL = "https://soporte.zauru.com";
4
+ const canUseDOM = () => typeof window !== "undefined" &&
5
+ Boolean(window.document?.createElement);
6
+ function getChatwootWindow() {
7
+ if (!canUseDOM())
8
+ return null;
9
+ return window;
10
+ }
11
+ function compactAttributes(attrs) {
12
+ if (!attrs)
13
+ return {};
14
+ const next = {};
15
+ for (const [key, value] of Object.entries(attrs)) {
16
+ if (value === null || value === undefined || value === "")
17
+ continue;
18
+ next[key] = value;
19
+ }
20
+ return next;
21
+ }
22
+ function identifyUser(user, identifierHash, locale) {
23
+ const $chatwoot = getChatwootWindow()?.$chatwoot;
24
+ if (!$chatwoot)
25
+ return;
26
+ const payload = {};
27
+ if (user.email)
28
+ payload.email = user.email;
29
+ if (user.name)
30
+ payload.name = user.name;
31
+ if (user.companyName)
32
+ payload.company_name = user.companyName;
33
+ if (user.avatarUrl)
34
+ payload.avatar_url = user.avatarUrl;
35
+ if (identifierHash)
36
+ payload.identifier_hash = identifierHash;
37
+ $chatwoot.setUser(user.identifier, payload);
38
+ const custom = compactAttributes(user.customAttributes);
39
+ if (Object.keys(custom).length > 0) {
40
+ $chatwoot.setCustomAttributes(custom);
41
+ }
42
+ $chatwoot.setLocale?.(locale);
43
+ }
44
+ function removeWidgetDom(baseUrl) {
45
+ const doc = getChatwootWindow()?.document;
46
+ if (!doc)
47
+ return;
48
+ doc.getElementById(SCRIPT_ID)?.remove();
49
+ doc
50
+ .querySelectorAll(`script[src*="${baseUrl}/packs/js/sdk.js"], iframe#chatwoot_live_chat_widget, .woot-widget-holder, .woot-widget-bubble`)
51
+ .forEach((el) => el.remove());
52
+ }
53
+ export function resetChatwoot() {
54
+ const w = getChatwootWindow();
55
+ if (!w)
56
+ return;
57
+ try {
58
+ w.$chatwoot?.reset();
59
+ }
60
+ catch {
61
+ // Widget may already be gone during logout navigation.
62
+ }
63
+ }
64
+ export function ChatwootWidget({ websiteToken, baseUrl = DEFAULT_BASE_URL, identifierHash, user, locale = "es", position = "right", darkMode = "auto", }) {
65
+ const identifier = user.identifier;
66
+ const email = user.email;
67
+ const name = user.name;
68
+ const companyName = user.companyName;
69
+ const avatarUrl = user.avatarUrl;
70
+ const customAttributesKey = JSON.stringify(compactAttributes(user.customAttributes));
71
+ useEffect(() => {
72
+ const w = getChatwootWindow();
73
+ if (!w || !websiteToken || !identifier)
74
+ return;
75
+ w.chatwootSettings = {
76
+ hideMessageBubble: false,
77
+ position,
78
+ locale,
79
+ useBrowserLanguage: false,
80
+ type: "standard",
81
+ darkMode,
82
+ };
83
+ const onReady = () => {
84
+ identifyUser({
85
+ identifier,
86
+ email,
87
+ name,
88
+ companyName,
89
+ avatarUrl,
90
+ customAttributes: JSON.parse(customAttributesKey),
91
+ }, identifierHash, locale);
92
+ };
93
+ w.addEventListener("chatwoot:ready", onReady);
94
+ const existing = w.document.getElementById(SCRIPT_ID);
95
+ if (w.$chatwoot) {
96
+ onReady();
97
+ }
98
+ else if (!existing) {
99
+ const script = w.document.createElement("script");
100
+ script.id = SCRIPT_ID;
101
+ script.src = `${baseUrl}/packs/js/sdk.js`;
102
+ script.async = true;
103
+ script.defer = true;
104
+ script.onload = () => {
105
+ w.chatwootSDK?.run({ websiteToken, baseUrl });
106
+ };
107
+ w.document.body.appendChild(script);
108
+ }
109
+ return () => {
110
+ w.removeEventListener("chatwoot:ready", onReady);
111
+ };
112
+ }, [
113
+ websiteToken,
114
+ baseUrl,
115
+ identifierHash,
116
+ identifier,
117
+ email,
118
+ name,
119
+ companyName,
120
+ avatarUrl,
121
+ customAttributesKey,
122
+ locale,
123
+ position,
124
+ darkMode,
125
+ ]);
126
+ useEffect(() => {
127
+ return () => {
128
+ resetChatwoot();
129
+ removeWidgetDom(baseUrl);
130
+ const w = getChatwootWindow();
131
+ if (w) {
132
+ delete w.chatwootSDK;
133
+ delete w.$chatwoot;
134
+ }
135
+ };
136
+ }, [baseUrl]);
137
+ return null;
138
+ }
139
+ export const Chatwoot = ChatwootWidget;
@@ -0,0 +1 @@
1
+ export * from "./Chat.js";
package/dist/esm/index.js CHANGED
@@ -25,6 +25,7 @@ export * from "./Tooltip/index.js";
25
25
  export * from "./WithTooltip/index.js";
26
26
  export * from "./Wizards/index.js";
27
27
  export * from "./Zendesk/index.js";
28
+ export * from "./Chatwoot/index.js";
28
29
  export * from "./HOC/ValidateEmployeeAccess/index.js";
29
30
  export * from "./Routes/index.js";
30
31
  export * from "./SidePanel/index.js";
package/dist/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export * from "./Tooltip/index.js";
25
25
  export * from "./WithTooltip/index.js";
26
26
  export * from "./Wizards/index.js";
27
27
  export * from "./Zendesk/index.js";
28
+ export * from "./Chatwoot/index.js";
28
29
  export * from "./HOC/ValidateEmployeeAccess/index.js";
29
30
  export * from "./Routes/index.js";
30
31
  export * from "./SidePanel/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/components",
3
- "version": "6.20.16",
3
+ "version": "6.21.0",
4
4
  "description": "Componentes reutilizables en las WebApps de Zauru.",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -45,12 +45,12 @@
45
45
  "@reduxjs/toolkit": "^2.2.1",
46
46
  "@remix-run/node": "^2.8.1",
47
47
  "@remix-run/react": "^2.8.1",
48
- "@zauru-sdk/common": "^6.16.3",
49
- "@zauru-sdk/hooks": "^6.4.13",
48
+ "@zauru-sdk/common": "^6.16.4",
49
+ "@zauru-sdk/hooks": "^6.4.14",
50
50
  "@zauru-sdk/icons": "^6.2.0",
51
- "@zauru-sdk/redux": "^6.8.12",
52
- "@zauru-sdk/types": "^6.37.0",
53
- "@zauru-sdk/utils": "^6.32.4",
51
+ "@zauru-sdk/redux": "^6.8.13",
52
+ "@zauru-sdk/types": "^6.37.1",
53
+ "@zauru-sdk/utils": "^6.33.0",
54
54
  "browser-image-compression": "^2.0.2",
55
55
  "framer-motion": "^12.0.0",
56
56
  "jsonwebtoken": "^9.0.2",
@@ -63,5 +63,5 @@
63
63
  "styled-components": "^5.3.5",
64
64
  "zod": "^3.23.8"
65
65
  },
66
- "gitHead": "f946db914ded95566291d766b162d3eef6e2fa50"
66
+ "gitHead": "3ba629181f6fed9930bb9812dba572360d57bf24"
67
67
  }
@@ -0,0 +1,214 @@
1
+ import { useEffect } from "react";
2
+
3
+ const SCRIPT_ID = "chatwoot-sdk";
4
+ const DEFAULT_BASE_URL = "https://soporte.zauru.com";
5
+
6
+ const canUseDOM = (): boolean =>
7
+ typeof window !== "undefined" &&
8
+ Boolean(window.document?.createElement);
9
+
10
+ export type ChatwootUser = {
11
+ identifier: string;
12
+ email?: string;
13
+ name?: string;
14
+ companyName?: string;
15
+ avatarUrl?: string;
16
+ customAttributes?: Record<
17
+ string,
18
+ string | number | boolean | null | undefined
19
+ >;
20
+ };
21
+
22
+ export type ChatwootWidgetProps = {
23
+ websiteToken: string;
24
+ baseUrl?: string;
25
+ identifierHash?: string;
26
+ user: ChatwootUser;
27
+ locale?: string;
28
+ position?: "left" | "right";
29
+ darkMode?: "light" | "auto" | "dark";
30
+ };
31
+
32
+ type ChatwootSdk = {
33
+ run: (opts: { websiteToken: string; baseUrl: string }) => void;
34
+ };
35
+
36
+ type ChatwootApi = {
37
+ setUser: (identifier: string, user: Record<string, unknown>) => void;
38
+ setCustomAttributes: (attrs: Record<string, unknown>) => void;
39
+ setLocale?: (locale: string) => void;
40
+ reset: () => void;
41
+ };
42
+
43
+ type ChatwootWindow = Window & {
44
+ chatwootSDK?: ChatwootSdk;
45
+ $chatwoot?: ChatwootApi;
46
+ chatwootSettings?: Record<string, unknown>;
47
+ };
48
+
49
+ function getChatwootWindow(): ChatwootWindow | null {
50
+ if (!canUseDOM()) return null;
51
+ return window as ChatwootWindow;
52
+ }
53
+
54
+ function compactAttributes(
55
+ attrs: ChatwootUser["customAttributes"],
56
+ ): Record<string, string | number | boolean> {
57
+ if (!attrs) return {};
58
+ const next: Record<string, string | number | boolean> = {};
59
+ for (const [key, value] of Object.entries(attrs)) {
60
+ if (value === null || value === undefined || value === "") continue;
61
+ next[key] = value;
62
+ }
63
+ return next;
64
+ }
65
+
66
+ function identifyUser(
67
+ user: ChatwootUser,
68
+ identifierHash: string | undefined,
69
+ locale: string,
70
+ ): void {
71
+ const $chatwoot = getChatwootWindow()?.$chatwoot;
72
+ if (!$chatwoot) return;
73
+
74
+ const payload: Record<string, unknown> = {};
75
+ if (user.email) payload.email = user.email;
76
+ if (user.name) payload.name = user.name;
77
+ if (user.companyName) payload.company_name = user.companyName;
78
+ if (user.avatarUrl) payload.avatar_url = user.avatarUrl;
79
+ if (identifierHash) payload.identifier_hash = identifierHash;
80
+
81
+ $chatwoot.setUser(user.identifier, payload);
82
+
83
+ const custom = compactAttributes(user.customAttributes);
84
+ if (Object.keys(custom).length > 0) {
85
+ $chatwoot.setCustomAttributes(custom);
86
+ }
87
+
88
+ $chatwoot.setLocale?.(locale);
89
+ }
90
+
91
+ function removeWidgetDom(baseUrl: string): void {
92
+ const doc = getChatwootWindow()?.document;
93
+ if (!doc) return;
94
+
95
+ doc.getElementById(SCRIPT_ID)?.remove();
96
+ doc
97
+ .querySelectorAll(
98
+ `script[src*="${baseUrl}/packs/js/sdk.js"], iframe#chatwoot_live_chat_widget, .woot-widget-holder, .woot-widget-bubble`,
99
+ )
100
+ .forEach((el) => el.remove());
101
+ }
102
+
103
+ export function resetChatwoot(): void {
104
+ const w = getChatwootWindow();
105
+ if (!w) return;
106
+ try {
107
+ w.$chatwoot?.reset();
108
+ } catch {
109
+ // Widget may already be gone during logout navigation.
110
+ }
111
+ }
112
+
113
+ export function ChatwootWidget({
114
+ websiteToken,
115
+ baseUrl = DEFAULT_BASE_URL,
116
+ identifierHash,
117
+ user,
118
+ locale = "es",
119
+ position = "right",
120
+ darkMode = "auto",
121
+ }: ChatwootWidgetProps) {
122
+ const identifier = user.identifier;
123
+ const email = user.email;
124
+ const name = user.name;
125
+ const companyName = user.companyName;
126
+ const avatarUrl = user.avatarUrl;
127
+ const customAttributesKey = JSON.stringify(
128
+ compactAttributes(user.customAttributes),
129
+ );
130
+
131
+ useEffect(() => {
132
+ const w = getChatwootWindow();
133
+ if (!w || !websiteToken || !identifier) return;
134
+
135
+ w.chatwootSettings = {
136
+ hideMessageBubble: false,
137
+ position,
138
+ locale,
139
+ useBrowserLanguage: false,
140
+ type: "standard",
141
+ darkMode,
142
+ };
143
+
144
+ const onReady = () => {
145
+ identifyUser(
146
+ {
147
+ identifier,
148
+ email,
149
+ name,
150
+ companyName,
151
+ avatarUrl,
152
+ customAttributes: JSON.parse(
153
+ customAttributesKey,
154
+ ) as ChatwootUser["customAttributes"],
155
+ },
156
+ identifierHash,
157
+ locale,
158
+ );
159
+ };
160
+
161
+ w.addEventListener("chatwoot:ready", onReady);
162
+
163
+ const existing = w.document.getElementById(SCRIPT_ID) as
164
+ | HTMLScriptElement
165
+ | null;
166
+
167
+ if (w.$chatwoot) {
168
+ onReady();
169
+ } else if (!existing) {
170
+ const script = w.document.createElement("script");
171
+ script.id = SCRIPT_ID;
172
+ script.src = `${baseUrl}/packs/js/sdk.js`;
173
+ script.async = true;
174
+ script.defer = true;
175
+ script.onload = () => {
176
+ w.chatwootSDK?.run({ websiteToken, baseUrl });
177
+ };
178
+ w.document.body.appendChild(script);
179
+ }
180
+
181
+ return () => {
182
+ w.removeEventListener("chatwoot:ready", onReady);
183
+ };
184
+ }, [
185
+ websiteToken,
186
+ baseUrl,
187
+ identifierHash,
188
+ identifier,
189
+ email,
190
+ name,
191
+ companyName,
192
+ avatarUrl,
193
+ customAttributesKey,
194
+ locale,
195
+ position,
196
+ darkMode,
197
+ ]);
198
+
199
+ useEffect(() => {
200
+ return () => {
201
+ resetChatwoot();
202
+ removeWidgetDom(baseUrl);
203
+ const w = getChatwootWindow();
204
+ if (w) {
205
+ delete w.chatwootSDK;
206
+ delete w.$chatwoot;
207
+ }
208
+ };
209
+ }, [baseUrl]);
210
+
211
+ return null;
212
+ }
213
+
214
+ export const Chatwoot = ChatwootWidget;
@@ -0,0 +1 @@
1
+ export * from "./Chat.js";
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from "./Tooltip/index.js";
25
25
  export * from "./WithTooltip/index.js";
26
26
  export * from "./Wizards/index.js";
27
27
  export * from "./Zendesk/index.js";
28
+ export * from "./Chatwoot/index.js";
28
29
  export * from "./HOC/ValidateEmployeeAccess/index.js";
29
30
  export * from "./Routes/index.js";
30
31
  export * from "./SidePanel/index.js";