@zauru-sdk/components 6.22.21 → 6.23.1

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,28 @@
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.1](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.23.0...@zauru-sdk/components@6.23.1) (2026-12-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * leer el mensaje del boundary cuando Remix entrega un Response ([f9fe951](https://github.com/intuitiva/zauru-typescript-sdk/commit/f9fe9519a16f04b21ee9724ecbf40a40d04240d7))
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * mostrar un mensaje claro y accionable en el error boundary ([97bb5c1](https://github.com/intuitiva/zauru-typescript-sdk/commit/97bb5c1abfe2bdac04b15ac27a276820dd51a052))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [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)
7
29
 
8
30
  **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,73 @@ 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
+ /** Upstream 5xx (Hasura/Heroku) reaches us as an axios message with the URL. */
9
+ const isUpstreamUnavailable = (message) => /HTTP 50[0-9]|Service Unavailable|Bad Gateway|Gateway Timeout|ENOTFOUND|ECONNREFUSED/i.test(message);
10
+ /**
11
+ * Remix replaces a thrown `Error` with "An unknown error has occurred" before
12
+ * it reaches the client, so a message that survived the wire is a real domain
13
+ * rejection and safe to show. Everything else becomes one plain sentence.
14
+ */
15
+ const isSanitized = (message) => !message.trim() ||
16
+ /unknown error has occurred|Unexpected Server Error/i.test(message);
17
+ const describeRouteError = (error) => {
18
+ if (isRouteErrorResponse(error)) {
19
+ // A `json({ message })` thrown from a loader reaches the boundary as data.
20
+ const data = error.data;
21
+ const fromData = typeof data === "string"
22
+ ? data
23
+ : data && typeof data === "object" && typeof data.message === "string"
24
+ ? data.message
25
+ : "";
26
+ if (fromData.trim() && !isSanitized(fromData))
27
+ return fromData;
28
+ switch (error.status) {
29
+ case 401:
30
+ return "Tu sesión expiró. Vuelve a iniciar sesión para continuar.";
31
+ case 403:
32
+ return "No tienes permiso para ver esta pantalla.";
33
+ case 404:
34
+ return "No encontramos lo que buscabas. Puede que ya se haya eliminado.";
35
+ default:
36
+ return error.status >= 500
37
+ ? "El sistema no respondió a tiempo. Vuelve a intentarlo en un momento."
38
+ : DEFAULT_MESSAGE;
39
+ }
40
+ }
41
+ if (error instanceof Error) {
42
+ const message = error.message?.trim() ?? "";
43
+ if (isSanitized(message))
44
+ return DEFAULT_MESSAGE;
45
+ if (isTimeout(message)) {
46
+ return "El sistema tardó demasiado en responder. Vuelve a intentarlo en un momento.";
47
+ }
48
+ if (isUpstreamUnavailable(message)) {
49
+ return "El sistema no está disponible en este momento. Vuelve a intentarlo en unos minutos.";
50
+ }
51
+ if (isNetworkFailure(message)) {
52
+ return "No pudimos conectar con el sistema. Revisa tu conexión e inténtalo de nuevo.";
53
+ }
54
+ return message;
55
+ }
56
+ return DEFAULT_MESSAGE;
57
+ };
58
+ /** Technical text for support, only revealed on demand. */
59
+ const describeErrorForSupport = (error) => {
60
+ if (isRouteErrorResponse(error)) {
61
+ return `Error en request: ${error.status} ${error.statusText}`;
62
+ }
63
+ if (error instanceof Error) {
64
+ return [error.message, error.stack].filter(Boolean).join("\n\n");
65
+ }
66
+ return String(error);
67
+ };
68
+ export const ErrorLayout = ({ from, isRootLevel = true, error: parentError, onError, reportErrors = true, title = "¡Ups!", message, }) => {
6
69
  try {
7
70
  const error = useRouteError();
8
- const [showDetails, setShowDetails] = useState(!!parentError);
71
+ const [showDetails, setShowDetails] = useState(false);
9
72
  useEffect(() => {
10
73
  const reportable = error instanceof Error ? error : parentError;
11
74
  if (reportable instanceof Error) {
@@ -30,15 +93,9 @@ export const ErrorLayout = ({ from, isRootLevel = true, error: parentError, onEr
30
93
  });
31
94
  }
32
95
  }, [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." }) })] }));
96
+ const visibleMessage = message ?? describeRouteError(error);
97
+ const supportDetails = describeErrorForSupport(error);
98
+ 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
99
  if (!isRootLevel) {
43
100
  return baseError;
44
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/components",
3
- "version": "6.22.21",
3
+ "version": "6.23.1",
4
4
  "description": "Componentes reutilizables en las WebApps de Zauru.",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -63,5 +63,5 @@
63
63
  "styled-components": "^5.3.5",
64
64
  "zod": "^3.23.8"
65
65
  },
66
- "gitHead": "b2c9e24cdf43c7e7ec29d74145ccb320aeb9aeae"
66
+ "gitHead": "5231c20e50d19d648ce7539d3cf4531a901245da"
67
67
  }
@@ -9,12 +9,95 @@ 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
+ /** Upstream 5xx (Hasura/Heroku) reaches us as an axios message with the URL. */
24
+ const isUpstreamUnavailable = (message: string) =>
25
+ /HTTP 50[0-9]|Service Unavailable|Bad Gateway|Gateway Timeout|ENOTFOUND|ECONNREFUSED/i.test(
26
+ message,
27
+ );
28
+
29
+ /**
30
+ * Remix replaces a thrown `Error` with "An unknown error has occurred" before
31
+ * it reaches the client, so a message that survived the wire is a real domain
32
+ * rejection and safe to show. Everything else becomes one plain sentence.
33
+ */
34
+ const isSanitized = (message: string) =>
35
+ !message.trim() ||
36
+ /unknown error has occurred|Unexpected Server Error/i.test(message);
37
+
38
+ const describeRouteError = (error: unknown): string => {
39
+ if (isRouteErrorResponse(error)) {
40
+ // A `json({ message })` thrown from a loader reaches the boundary as data.
41
+ const data = error.data as { message?: unknown } | string | null;
42
+ const fromData =
43
+ typeof data === "string"
44
+ ? data
45
+ : data && typeof data === "object" && typeof data.message === "string"
46
+ ? data.message
47
+ : "";
48
+ if (fromData.trim() && !isSanitized(fromData)) return fromData;
49
+
50
+ switch (error.status) {
51
+ case 401:
52
+ return "Tu sesión expiró. Vuelve a iniciar sesión para continuar.";
53
+ case 403:
54
+ return "No tienes permiso para ver esta pantalla.";
55
+ case 404:
56
+ return "No encontramos lo que buscabas. Puede que ya se haya eliminado.";
57
+ default:
58
+ return error.status >= 500
59
+ ? "El sistema no respondió a tiempo. Vuelve a intentarlo en un momento."
60
+ : DEFAULT_MESSAGE;
61
+ }
62
+ }
63
+
64
+ if (error instanceof Error) {
65
+ const message = error.message?.trim() ?? "";
66
+ if (isSanitized(message)) return DEFAULT_MESSAGE;
67
+ if (isTimeout(message)) {
68
+ return "El sistema tardó demasiado en responder. Vuelve a intentarlo en un momento.";
69
+ }
70
+ if (isUpstreamUnavailable(message)) {
71
+ return "El sistema no está disponible en este momento. Vuelve a intentarlo en unos minutos.";
72
+ }
73
+ if (isNetworkFailure(message)) {
74
+ return "No pudimos conectar con el sistema. Revisa tu conexión e inténtalo de nuevo.";
75
+ }
76
+ return message;
77
+ }
78
+
79
+ return DEFAULT_MESSAGE;
80
+ };
81
+
82
+ /** Technical text for support, only revealed on demand. */
83
+ const describeErrorForSupport = (error: unknown): string => {
84
+ if (isRouteErrorResponse(error)) {
85
+ return `Error en request: ${error.status} ${error.statusText}`;
86
+ }
87
+ if (error instanceof Error) {
88
+ return [error.message, error.stack].filter(Boolean).join("\n\n");
89
+ }
90
+ return String(error);
91
+ };
92
+
12
93
  export const ErrorLayout = ({
13
94
  from,
14
95
  isRootLevel = true,
15
96
  error: parentError,
16
97
  onError,
17
98
  reportErrors = true,
99
+ title = "¡Ups!",
100
+ message,
18
101
  }: {
19
102
  from?: string;
20
103
  isRootLevel?: boolean;
@@ -22,10 +105,14 @@ export const ErrorLayout = ({
22
105
  onError?: (error: Error, meta: { from?: string }) => void;
23
106
  /** Default true. POSTs to `/api/client-errors` unless `onError` is passed. */
24
107
  reportErrors?: boolean;
108
+ /** Heading. Defaults to "¡Ups!". */
109
+ title?: string;
110
+ /** Replaces the message derived from the error. */
111
+ message?: string;
25
112
  }) => {
26
113
  try {
27
114
  const error = useRouteError();
28
- const [showDetails, setShowDetails] = useState(!!parentError);
115
+ const [showDetails, setShowDetails] = useState(false);
29
116
 
30
117
  useEffect(() => {
31
118
  const reportable = error instanceof Error ? error : parentError;
@@ -51,46 +138,31 @@ export const ErrorLayout = ({
51
138
  }
52
139
  }, [error, parentError, from, onError, reportErrors]);
53
140
 
141
+ const visibleMessage = message ?? describeRouteError(error);
142
+ const supportDetails = describeErrorForSupport(error);
143
+
54
144
  const baseError = (
55
145
  <div className="min-h-screen flex flex-col items-center justify-center p-4">
56
146
  <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>
147
+ <h1 className="text-3xl font-extrabold text-red-500 mb-6">{title}</h1>
58
148
  <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}`}
149
+ <p className="text-xl text-gray-300 mb-8 text-center" role="alert">
150
+ {visibleMessage}
69
151
  </p>
70
152
  {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>
153
+ <p className="text-sm text-gray-500 mb-4 text-center">{from}</p>
77
154
  )}
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>
155
+ <button
156
+ onClick={() => setShowDetails(!showDetails)}
157
+ className="mb-4 text-blue-400 hover:text-blue-300 transition duration-300 cursor-pointer"
158
+ aria-expanded={showDetails}
159
+ >
160
+ {showDetails ? "Ocultar detalles" : "Ver detalles"}
161
+ </button>
162
+ {showDetails && (
163
+ <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">
164
+ {supportDetails}
165
+ </pre>
94
166
  )}
95
167
  </div>
96
168
  <Link