@zauru-sdk/components 6.22.20 → 6.23.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.23.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.22.21...@zauru-sdk/components@6.23.0) (2026-12-04)
7
+
8
+
9
+ ### Features
10
+
11
+ * mostrar un mensaje claro y accionable en el error boundary ([97bb5c1](https://github.com/intuitiva/zauru-typescript-sdk/commit/97bb5c1abfe2bdac04b15ac27a276820dd51a052))
12
+
13
+
14
+
15
+
16
+
17
+ ## [6.22.21](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.22.20...@zauru-sdk/components@6.22.21) (2026-12-04)
18
+
19
+ **Note:** Version bump only for package @zauru-sdk/components
20
+
21
+
22
+
23
+
24
+
6
25
  ## [6.22.20](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.22.19...@zauru-sdk/components@6.22.20) (2026-11-30)
7
26
 
8
27
  **Note:** Version bump only for package @zauru-sdk/components
@@ -4,7 +4,9 @@ export type ChatwootUser = {
4
4
  name?: string;
5
5
  companyName?: string;
6
6
  avatarUrl?: string;
7
+ description?: string;
7
8
  customAttributes?: Record<string, string | number | boolean | null | undefined>;
9
+ conversationAttributes?: Record<string, string | number | boolean | null | undefined>;
8
10
  };
9
11
  export type ChatwootWidgetProps = {
10
12
  websiteToken: string;
@@ -1,4 +1,4 @@
1
- export declare const ErrorLayout: ({ from, isRootLevel, error: parentError, onError, reportErrors, }: {
1
+ export declare const ErrorLayout: ({ from, isRootLevel, error: parentError, onError, reportErrors, title, message, }: {
2
2
  from?: string;
3
3
  isRootLevel?: boolean;
4
4
  error?: Error;
@@ -7,4 +7,8 @@ export declare const ErrorLayout: ({ from, isRootLevel, error: parentError, onEr
7
7
  }) => void;
8
8
  /** Default true. POSTs to `/api/client-errors` unless `onError` is passed. */
9
9
  reportErrors?: boolean;
10
+ /** Heading. Defaults to "¡Ups!". */
11
+ title?: string;
12
+ /** Replaces the message derived from the error. */
13
+ message?: string;
10
14
  }) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,8 +1,7 @@
1
1
  import { useEffect } from "react";
2
2
  const SCRIPT_ID = "chatwoot-sdk";
3
3
  const DEFAULT_BASE_URL = "https://soporte.zauru.com";
4
- const canUseDOM = () => typeof window !== "undefined" &&
5
- Boolean(window.document?.createElement);
4
+ const canUseDOM = () => typeof window !== "undefined" && Boolean(window.document?.createElement);
6
5
  function getChatwootWindow() {
7
6
  if (!canUseDOM())
8
7
  return null;
@@ -30,7 +29,9 @@ function identifyUser(user, identifierHash, locale) {
30
29
  payload.name = user.name;
31
30
  if (user.companyName)
32
31
  payload.company_name = user.companyName;
33
- if (user.avatarUrl)
32
+ if (user.description)
33
+ payload.description = user.description;
34
+ if (user.avatarUrl?.startsWith("http"))
34
35
  payload.avatar_url = user.avatarUrl;
35
36
  if (identifierHash)
36
37
  payload.identifier_hash = identifierHash;
@@ -39,17 +40,12 @@ function identifyUser(user, identifierHash, locale) {
39
40
  if (Object.keys(custom).length > 0) {
40
41
  $chatwoot.setCustomAttributes(custom);
41
42
  }
43
+ const conversation = compactAttributes(user.conversationAttributes);
44
+ if (Object.keys(conversation).length > 0) {
45
+ $chatwoot.setConversationCustomAttributes?.(conversation);
46
+ }
42
47
  $chatwoot.setLocale?.(locale);
43
48
  }
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
49
  export function resetChatwoot() {
54
50
  const w = getChatwootWindow();
55
51
  if (!w)
@@ -67,10 +63,12 @@ export function ChatwootWidget({ websiteToken, baseUrl = DEFAULT_BASE_URL, ident
67
63
  const name = user.name;
68
64
  const companyName = user.companyName;
69
65
  const avatarUrl = user.avatarUrl;
66
+ const description = user.description;
70
67
  const customAttributesKey = JSON.stringify(compactAttributes(user.customAttributes));
68
+ const conversationAttributesKey = JSON.stringify(compactAttributes(user.conversationAttributes));
71
69
  useEffect(() => {
72
70
  const w = getChatwootWindow();
73
- if (!w || !websiteToken || !identifier)
71
+ if (!w || !websiteToken || !identifier || !identifierHash)
74
72
  return;
75
73
  w.chatwootSettings = {
76
74
  hideMessageBubble: false,
@@ -87,7 +85,9 @@ export function ChatwootWidget({ websiteToken, baseUrl = DEFAULT_BASE_URL, ident
87
85
  name,
88
86
  companyName,
89
87
  avatarUrl,
88
+ description,
90
89
  customAttributes: JSON.parse(customAttributesKey),
90
+ conversationAttributes: JSON.parse(conversationAttributesKey),
91
91
  }, identifierHash, locale);
92
92
  };
93
93
  w.addEventListener("chatwoot:ready", onReady);
@@ -95,6 +95,9 @@ export function ChatwootWidget({ websiteToken, baseUrl = DEFAULT_BASE_URL, ident
95
95
  if (w.$chatwoot) {
96
96
  onReady();
97
97
  }
98
+ else if (w.chatwootSDK) {
99
+ w.chatwootSDK.run({ websiteToken, baseUrl });
100
+ }
98
101
  else if (!existing) {
99
102
  const script = w.document.createElement("script");
100
103
  script.id = SCRIPT_ID;
@@ -118,22 +121,13 @@ export function ChatwootWidget({ websiteToken, baseUrl = DEFAULT_BASE_URL, ident
118
121
  name,
119
122
  companyName,
120
123
  avatarUrl,
124
+ description,
121
125
  customAttributesKey,
126
+ conversationAttributesKey,
122
127
  locale,
123
128
  position,
124
129
  darkMode,
125
130
  ]);
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
131
  return null;
138
132
  }
139
133
  export const Chatwoot = ChatwootWidget;
@@ -2,10 +2,59 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { isRouteErrorResponse, Links, Meta, Scripts, useRouteError, Link, } from "@remix-run/react";
3
3
  import { useEffect, useState } from "react";
4
4
  import { sendClientError } from "../../observability/sendClientError.js";
5
- export const ErrorLayout = ({ from, isRootLevel = true, error: parentError, onError, reportErrors = true, }) => {
5
+ const DEFAULT_MESSAGE = "No pudimos cargar esta pantalla. Recarga la página e inténtalo de nuevo.";
6
+ const isTimeout = (message) => /TIMEOUT|timeout of \d+ms|no terminó a tiempo/i.test(message);
7
+ const isNetworkFailure = (message) => /Failed to fetch|Network ?Error|ECONNRESET|ETIMEDOUT|ENOTFOUND|socket hang up/i.test(message);
8
+ /**
9
+ * Remix replaces a thrown `Error` with "An unknown error has occurred" before
10
+ * it reaches the client, so a message that survived the wire is a real domain
11
+ * rejection and safe to show. Everything else becomes one plain sentence.
12
+ */
13
+ const isSanitized = (message) => !message.trim() ||
14
+ /unknown error has occurred|Unexpected Server Error/i.test(message);
15
+ const describeRouteError = (error) => {
16
+ if (isRouteErrorResponse(error)) {
17
+ switch (error.status) {
18
+ case 401:
19
+ return "Tu sesión expiró. Vuelve a iniciar sesión para continuar.";
20
+ case 403:
21
+ return "No tienes permiso para ver esta pantalla.";
22
+ case 404:
23
+ return "No encontramos lo que buscabas. Puede que ya se haya eliminado.";
24
+ default:
25
+ return error.status >= 500
26
+ ? "El sistema no respondió a tiempo. Vuelve a intentarlo en un momento."
27
+ : DEFAULT_MESSAGE;
28
+ }
29
+ }
30
+ if (error instanceof Error) {
31
+ const message = error.message?.trim() ?? "";
32
+ if (isSanitized(message))
33
+ return DEFAULT_MESSAGE;
34
+ if (isTimeout(message)) {
35
+ return "El sistema tardó demasiado en responder. Vuelve a intentarlo en un momento.";
36
+ }
37
+ if (isNetworkFailure(message)) {
38
+ return "No pudimos conectar con el sistema. Revisa tu conexión e inténtalo de nuevo.";
39
+ }
40
+ return message;
41
+ }
42
+ return DEFAULT_MESSAGE;
43
+ };
44
+ /** Technical text for support, only revealed on demand. */
45
+ const describeErrorForSupport = (error) => {
46
+ if (isRouteErrorResponse(error)) {
47
+ return `Error en request: ${error.status} ${error.statusText}`;
48
+ }
49
+ if (error instanceof Error) {
50
+ return [error.message, error.stack].filter(Boolean).join("\n\n");
51
+ }
52
+ return String(error);
53
+ };
54
+ export const ErrorLayout = ({ from, isRootLevel = true, error: parentError, onError, reportErrors = true, title = "¡Ups!", message, }) => {
6
55
  try {
7
56
  const error = useRouteError();
8
- const [showDetails, setShowDetails] = useState(!!parentError);
57
+ const [showDetails, setShowDetails] = useState(false);
9
58
  useEffect(() => {
10
59
  const reportable = error instanceof Error ? error : parentError;
11
60
  if (reportable instanceof Error) {
@@ -30,15 +79,9 @@ export const ErrorLayout = ({ from, isRootLevel = true, error: parentError, onEr
30
79
  });
31
80
  }
32
81
  }, [error, parentError, from, onError, reportErrors]);
33
- const baseError = (_jsxs("div", { className: "min-h-screen flex flex-col items-center justify-center p-4", children: [_jsx("img", { src: "/logo.png", alt: "Zauru Logo", className: "mb-8 h-20" }), _jsx("h1", { className: "text-5xl font-extrabold text-red-500 mb-6", children: "\u00A1Ups!" }), _jsxs("div", { className: "w-full max-w-2xl flex flex-col items-center", children: [_jsx("p", { className: "text-2xl text-gray-300 mb-8 text-center", children: isRouteErrorResponse(error)
34
- ? `Error en request: ${error.status}: ${error.statusText} - PATH: ${error.data.path} - MESSAGE: ${error.data.message}`
35
- : error instanceof Error
36
- ? `Error: ${error.message} - NAME: ${error.name} - STACK: ${error.stack?.slice(0, 100)} - CAUSE: ${error.cause}`
37
- : `Ha ocurrido un error inesperado: ${error}` }), from && (_jsxs("p", { className: "text-lg text-gray-400 mb-4 text-center", children: [isRootLevel
38
- ? "(*) Error lanzado desde: "
39
- : "Error lanzado desde: ", from] })), parentError && (_jsxs("div", { className: "mb-4 text-center", children: [_jsx("button", { onClick: () => setShowDetails(!showDetails), className: "text-blue-400 hover:text-blue-300 transition duration-300 cursor-pointer", children: showDetails ? "Ocultar detalles" : "Ver más detalles" }), showDetails && (_jsx("p", { className: "mt-2 text-gray-400 text-sm", children: parentError instanceof Error
40
- ? parentError.message
41
- : String(parentError) }))] }))] }), _jsx(Link, { to: "/", className: "bg-blue-600 text-white py-3 px-8 rounded-full text-lg font-semibold hover:bg-blue-700 transition duration-300 transform hover:scale-105", children: "Regresar al inicio" }), _jsx("div", { className: "mt-12 text-gray-500 text-center", children: _jsx("p", { children: "Si el problema persiste, por favor contacta a soporte." }) })] }));
82
+ const visibleMessage = message ?? describeRouteError(error);
83
+ const supportDetails = describeErrorForSupport(error);
84
+ const baseError = (_jsxs("div", { className: "min-h-screen flex flex-col items-center justify-center p-4", children: [_jsx("img", { src: "/logo.png", alt: "Zauru Logo", className: "mb-8 h-20" }), _jsx("h1", { className: "text-3xl font-extrabold text-red-500 mb-6", children: title }), _jsxs("div", { className: "w-full max-w-2xl flex flex-col items-center", children: [_jsx("p", { className: "text-xl text-gray-300 mb-8 text-center", role: "alert", children: visibleMessage }), from && (_jsx("p", { className: "text-sm text-gray-500 mb-4 text-center", children: from })), _jsx("button", { onClick: () => setShowDetails(!showDetails), className: "mb-4 text-blue-400 hover:text-blue-300 transition duration-300 cursor-pointer", "aria-expanded": showDetails, children: showDetails ? "Ocultar detalles" : "Ver detalles" }), showDetails && (_jsx("pre", { className: "mb-4 max-h-64 w-full overflow-auto rounded bg-gray-800 p-4 text-left text-xs text-gray-400 whitespace-pre-wrap", children: supportDetails }))] }), _jsx(Link, { to: "/", className: "bg-blue-600 text-white py-3 px-8 rounded-full text-lg font-semibold hover:bg-blue-700 transition duration-300 transform hover:scale-105", children: "Regresar al inicio" }), _jsx("div", { className: "mt-12 text-gray-500 text-center", children: _jsx("p", { children: "Si el problema persiste, por favor contacta a soporte." }) })] }));
42
85
  if (!isRootLevel) {
43
86
  return baseError;
44
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/components",
3
- "version": "6.22.20",
3
+ "version": "6.23.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.18.2",
49
- "@zauru-sdk/hooks": "^6.4.26",
48
+ "@zauru-sdk/common": "^6.18.3",
49
+ "@zauru-sdk/hooks": "^6.4.27",
50
50
  "@zauru-sdk/icons": "^6.2.0",
51
- "@zauru-sdk/redux": "^6.8.24",
52
- "@zauru-sdk/types": "^6.49.0",
53
- "@zauru-sdk/utils": "^6.37.3",
51
+ "@zauru-sdk/redux": "^6.8.25",
52
+ "@zauru-sdk/types": "^6.50.0",
53
+ "@zauru-sdk/utils": "^6.38.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": "32e94af88cb922cf4b8ae96f6ee94806b1cc5bbb"
66
+ "gitHead": "3d0fccda00fa0bb82a9411599eae997cbabe2492"
67
67
  }
@@ -9,12 +9,76 @@ import {
9
9
  import { useEffect, useState } from "react";
10
10
  import { sendClientError } from "../../observability/sendClientError.js";
11
11
 
12
+ const DEFAULT_MESSAGE =
13
+ "No pudimos cargar esta pantalla. Recarga la página e inténtalo de nuevo.";
14
+
15
+ const isTimeout = (message: string) =>
16
+ /TIMEOUT|timeout of \d+ms|no terminó a tiempo/i.test(message);
17
+
18
+ const isNetworkFailure = (message: string) =>
19
+ /Failed to fetch|Network ?Error|ECONNRESET|ETIMEDOUT|ENOTFOUND|socket hang up/i.test(
20
+ message,
21
+ );
22
+
23
+ /**
24
+ * Remix replaces a thrown `Error` with "An unknown error has occurred" before
25
+ * it reaches the client, so a message that survived the wire is a real domain
26
+ * rejection and safe to show. Everything else becomes one plain sentence.
27
+ */
28
+ const isSanitized = (message: string) =>
29
+ !message.trim() ||
30
+ /unknown error has occurred|Unexpected Server Error/i.test(message);
31
+
32
+ const describeRouteError = (error: unknown): string => {
33
+ if (isRouteErrorResponse(error)) {
34
+ switch (error.status) {
35
+ case 401:
36
+ return "Tu sesión expiró. Vuelve a iniciar sesión para continuar.";
37
+ case 403:
38
+ return "No tienes permiso para ver esta pantalla.";
39
+ case 404:
40
+ return "No encontramos lo que buscabas. Puede que ya se haya eliminado.";
41
+ default:
42
+ return error.status >= 500
43
+ ? "El sistema no respondió a tiempo. Vuelve a intentarlo en un momento."
44
+ : DEFAULT_MESSAGE;
45
+ }
46
+ }
47
+
48
+ if (error instanceof Error) {
49
+ const message = error.message?.trim() ?? "";
50
+ if (isSanitized(message)) return DEFAULT_MESSAGE;
51
+ if (isTimeout(message)) {
52
+ return "El sistema tardó demasiado en responder. Vuelve a intentarlo en un momento.";
53
+ }
54
+ if (isNetworkFailure(message)) {
55
+ return "No pudimos conectar con el sistema. Revisa tu conexión e inténtalo de nuevo.";
56
+ }
57
+ return message;
58
+ }
59
+
60
+ return DEFAULT_MESSAGE;
61
+ };
62
+
63
+ /** Technical text for support, only revealed on demand. */
64
+ const describeErrorForSupport = (error: unknown): string => {
65
+ if (isRouteErrorResponse(error)) {
66
+ return `Error en request: ${error.status} ${error.statusText}`;
67
+ }
68
+ if (error instanceof Error) {
69
+ return [error.message, error.stack].filter(Boolean).join("\n\n");
70
+ }
71
+ return String(error);
72
+ };
73
+
12
74
  export const ErrorLayout = ({
13
75
  from,
14
76
  isRootLevel = true,
15
77
  error: parentError,
16
78
  onError,
17
79
  reportErrors = true,
80
+ title = "¡Ups!",
81
+ message,
18
82
  }: {
19
83
  from?: string;
20
84
  isRootLevel?: boolean;
@@ -22,10 +86,14 @@ export const ErrorLayout = ({
22
86
  onError?: (error: Error, meta: { from?: string }) => void;
23
87
  /** Default true. POSTs to `/api/client-errors` unless `onError` is passed. */
24
88
  reportErrors?: boolean;
89
+ /** Heading. Defaults to "¡Ups!". */
90
+ title?: string;
91
+ /** Replaces the message derived from the error. */
92
+ message?: string;
25
93
  }) => {
26
94
  try {
27
95
  const error = useRouteError();
28
- const [showDetails, setShowDetails] = useState(!!parentError);
96
+ const [showDetails, setShowDetails] = useState(false);
29
97
 
30
98
  useEffect(() => {
31
99
  const reportable = error instanceof Error ? error : parentError;
@@ -51,46 +119,31 @@ export const ErrorLayout = ({
51
119
  }
52
120
  }, [error, parentError, from, onError, reportErrors]);
53
121
 
122
+ const visibleMessage = message ?? describeRouteError(error);
123
+ const supportDetails = describeErrorForSupport(error);
124
+
54
125
  const baseError = (
55
126
  <div className="min-h-screen flex flex-col items-center justify-center p-4">
56
127
  <img src="/logo.png" alt="Zauru Logo" className="mb-8 h-20" />
57
- <h1 className="text-5xl font-extrabold text-red-500 mb-6">¡Ups!</h1>
128
+ <h1 className="text-3xl font-extrabold text-red-500 mb-6">{title}</h1>
58
129
  <div className="w-full max-w-2xl flex flex-col items-center">
59
- <p className="text-2xl text-gray-300 mb-8 text-center">
60
- {isRouteErrorResponse(error)
61
- ? `Error en request: ${error.status}: ${error.statusText} - PATH: ${error.data.path} - MESSAGE: ${error.data.message}`
62
- : error instanceof Error
63
- ? `Error: ${error.message} - NAME: ${
64
- error.name
65
- } - STACK: ${error.stack?.slice(0, 100)} - CAUSE: ${
66
- error.cause
67
- }`
68
- : `Ha ocurrido un error inesperado: ${error}`}
130
+ <p className="text-xl text-gray-300 mb-8 text-center" role="alert">
131
+ {visibleMessage}
69
132
  </p>
70
133
  {from && (
71
- <p className="text-lg text-gray-400 mb-4 text-center">
72
- {isRootLevel
73
- ? "(*) Error lanzado desde: "
74
- : "Error lanzado desde: "}
75
- {from}
76
- </p>
134
+ <p className="text-sm text-gray-500 mb-4 text-center">{from}</p>
77
135
  )}
78
- {parentError && (
79
- <div className="mb-4 text-center">
80
- <button
81
- onClick={() => setShowDetails(!showDetails)}
82
- className="text-blue-400 hover:text-blue-300 transition duration-300 cursor-pointer"
83
- >
84
- {showDetails ? "Ocultar detalles" : "Ver más detalles"}
85
- </button>
86
- {showDetails && (
87
- <p className="mt-2 text-gray-400 text-sm">
88
- {parentError instanceof Error
89
- ? parentError.message
90
- : String(parentError)}
91
- </p>
92
- )}
93
- </div>
136
+ <button
137
+ onClick={() => setShowDetails(!showDetails)}
138
+ className="mb-4 text-blue-400 hover:text-blue-300 transition duration-300 cursor-pointer"
139
+ aria-expanded={showDetails}
140
+ >
141
+ {showDetails ? "Ocultar detalles" : "Ver detalles"}
142
+ </button>
143
+ {showDetails && (
144
+ <pre className="mb-4 max-h-64 w-full overflow-auto rounded bg-gray-800 p-4 text-left text-xs text-gray-400 whitespace-pre-wrap">
145
+ {supportDetails}
146
+ </pre>
94
147
  )}
95
148
  </div>
96
149
  <Link