@deepfrog/pangents-widget 2.2.0 → 2.2.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/README.md +55 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/{widget-embed-CtD27t5y.es.js → widget-embed-B3A5H6pf.es.js} +20 -17
- package/dist/widget-embed-B3A5H6pf.es.js.map +1 -0
- package/dist/{widget-embed-BPoilyw_.cjs.js → widget-embed-DgFZhnDu.cjs.js} +2 -2
- package/dist/widget-embed-DgFZhnDu.cjs.js.map +1 -0
- package/dist/widget-embed.cjs.js +1 -1
- package/dist/widget-embed.es.js +1 -1
- package/dist/widget.js +19 -16
- package/package.json +1 -1
- package/dist/widget-embed-BPoilyw_.cjs.js.map +0 -1
- package/dist/widget-embed-CtD27t5y.es.js.map +0 -1
package/README.md
CHANGED
|
@@ -133,6 +133,61 @@ Initialize the widget with configuration.
|
|
|
133
133
|
|
|
134
134
|
Update widget configuration dynamically.
|
|
135
135
|
|
|
136
|
+
#### Example: Fetch config from an API and update at runtime
|
|
137
|
+
|
|
138
|
+
```html
|
|
139
|
+
<script type="module">
|
|
140
|
+
import Chatbot from 'https://cdn.jsdelivr.net/npm/@deepfrog/pangents-widget/dist/widget.min.js';
|
|
141
|
+
|
|
142
|
+
Chatbot.init({
|
|
143
|
+
pangentsApiKey: '<api_key>',
|
|
144
|
+
tenantId: '<tenant_id>'
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
async function loadWidgetConfig() {
|
|
148
|
+
const res = await fetch('https://api.example.com/widget-config?tenant=<tenant_id>');
|
|
149
|
+
if (!res.ok) throw new Error('Failed to load widget config');
|
|
150
|
+
const remote = await res.json();
|
|
151
|
+
|
|
152
|
+
Chatbot.updateConfig({
|
|
153
|
+
pangentsApiKey: remote.pangentsApiKey ?? '<api_key>',
|
|
154
|
+
tenantId: remote.tenantId ?? '<tenant_id>',
|
|
155
|
+
email: remote.email,
|
|
156
|
+
theme: remote.theme,
|
|
157
|
+
position: remote.position,
|
|
158
|
+
margin: remote.margin,
|
|
159
|
+
zIndex: remote.zIndex
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
loadWidgetConfig();
|
|
164
|
+
</script>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// ESM/bundlers
|
|
169
|
+
import Chatbot from '@deepfrog/pangents-widget/widget';
|
|
170
|
+
|
|
171
|
+
Chatbot.init({
|
|
172
|
+
pangentsApiKey: '<api_key>',
|
|
173
|
+
tenantId: '<tenant_id>'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const res = await fetch('/api/widget-config');
|
|
177
|
+
if (!res.ok) throw new Error('Failed to load widget config');
|
|
178
|
+
const cfg = await res.json();
|
|
179
|
+
|
|
180
|
+
Chatbot.updateConfig({
|
|
181
|
+
pangentsApiKey: cfg.pangentsApiKey,
|
|
182
|
+
tenantId: cfg.tenantId,
|
|
183
|
+
email: cfg.email,
|
|
184
|
+
theme: cfg.theme,
|
|
185
|
+
position: cfg.position,
|
|
186
|
+
margin: cfg.margin,
|
|
187
|
+
zIndex: cfg.zIndex
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
136
191
|
### `Chatbot.updateTheme(theme)`
|
|
137
192
|
|
|
138
193
|
Update only the theme configuration.
|
package/dist/index.cjs.js
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
}
|
|
7
7
|
} catch (error) {}
|
|
8
8
|
})();
|
|
9
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-embed-
|
|
9
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-embed-DgFZhnDu.cjs.js"),t=require("react/jsx-runtime"),n=require("react"),o=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"}));if("undefined"!=typeof window)try{const e=window.__PANGENTS_WIDGET_CSS;if(e&&!document.getElementById("pangents-widget-styles")){const t=document.createElement("style");t.id="pangents-widget-styles",t.textContent=e,document.head.appendChild(t)}}catch{}exports.Chatbot=e.Chatbot,exports.Widget=e.Widget,exports.ChatbotWidget=({pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d="bottom-right",zIndex:c=9999,onInit:a,onDestroy:l})=>{const u=n.useRef(null),g=n.useRef(null);return n.useEffect(()=>((async()=>{try{const{default:t}=await Promise.resolve().then(()=>o(require("./widget-embed.cjs.js"))),n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};u.current=t,t.init(n),a&&a()}catch(t){console.error("Failed to initialize chatbot widget:",t)}})(),()=>{if(u.current)try{u.current.destroy(),l&&l()}catch(e){console.error("Error destroying chatbot widget:",e)}}),[e,r,i,s,d,c,a,l]),n.useEffect(()=>{if(u.current){const n={pangentsApiKey:e,email:r,tenantId:i,theme:s,position:d,zIndex:c};try{u.current.updateConfig(n)}catch(t){console.error("Error updating chatbot widget config:",t)}}},[e,r,i,s,d,c]),t.jsx("div",{ref:g,style:{display:"none"}})};
|
|
10
10
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.es.js
CHANGED
|
@@ -16793,7 +16793,7 @@ class EnhancedErrorHandler {
|
|
|
16793
16793
|
// 30 seconds
|
|
16794
16794
|
constructor() {
|
|
16795
16795
|
__publicField(this, "errorQueue", []);
|
|
16796
|
-
__publicField(this, "isOnline", navigator.onLine);
|
|
16796
|
+
__publicField(this, "isOnline", typeof navigator !== "undefined" ? navigator.onLine : true);
|
|
16797
16797
|
__publicField(this, "maxQueueSize", 50);
|
|
16798
16798
|
// Reduced from 100
|
|
16799
16799
|
__publicField(this, "retryAttempts", 2);
|
|
@@ -16809,6 +16809,7 @@ class EnhancedErrorHandler {
|
|
|
16809
16809
|
}
|
|
16810
16810
|
// Setup event listeners for online/offline status
|
|
16811
16811
|
setupEventListeners() {
|
|
16812
|
+
if (typeof window === "undefined") return;
|
|
16812
16813
|
window.addEventListener("online", () => {
|
|
16813
16814
|
this.isOnline = true;
|
|
16814
16815
|
this.flushErrorQueue();
|
|
@@ -16875,8 +16876,8 @@ class EnhancedErrorHandler {
|
|
|
16875
16876
|
action: (context == null ? void 0 : context.action) || "Unknown",
|
|
16876
16877
|
userId: context == null ? void 0 : context.userId,
|
|
16877
16878
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16878
|
-
userAgent: navigator.userAgent,
|
|
16879
|
-
url: window.location.href,
|
|
16879
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "server",
|
|
16880
|
+
url: typeof window !== "undefined" ? window.location.href : "",
|
|
16880
16881
|
apiKey: (context == null ? void 0 : context.apiKey) ? context.apiKey.substring(0, 20) + "..." : void 0
|
|
16881
16882
|
};
|
|
16882
16883
|
const severity = this.determineSeverity(apiError);
|
|
@@ -16909,8 +16910,8 @@ class EnhancedErrorHandler {
|
|
|
16909
16910
|
action: (context == null ? void 0 : context.action) || "Runtime",
|
|
16910
16911
|
userId: context == null ? void 0 : context.userId,
|
|
16911
16912
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16912
|
-
userAgent: navigator.userAgent,
|
|
16913
|
-
url: window.location.href
|
|
16913
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "server",
|
|
16914
|
+
url: typeof window !== "undefined" ? window.location.href : ""
|
|
16914
16915
|
};
|
|
16915
16916
|
const errorReport = {
|
|
16916
16917
|
error: apiError,
|
|
@@ -16989,9 +16990,9 @@ class EnhancedErrorHandler {
|
|
|
16989
16990
|
await api2.post("/errors/report", {
|
|
16990
16991
|
errors: errorsToSend,
|
|
16991
16992
|
clientInfo: {
|
|
16992
|
-
userAgent: navigator.userAgent,
|
|
16993
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "server",
|
|
16993
16994
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16994
|
-
url: window.location.href,
|
|
16995
|
+
url: typeof window !== "undefined" ? window.location.href : "",
|
|
16995
16996
|
circuitBreakerState: this.circuitBreaker.getState(),
|
|
16996
16997
|
remainingRateLimit: this.rateLimiter.getRemainingRequests()
|
|
16997
16998
|
}
|
|
@@ -17026,15 +17027,17 @@ class EnhancedErrorHandler {
|
|
|
17026
17027
|
// Show user notification based on error severity
|
|
17027
17028
|
showUserNotification(error, severity) {
|
|
17028
17029
|
const message = this.getUserFriendlyMessage(error);
|
|
17029
|
-
|
|
17030
|
-
|
|
17031
|
-
|
|
17032
|
-
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17036
|
-
|
|
17037
|
-
|
|
17030
|
+
if (typeof window !== "undefined") {
|
|
17031
|
+
window.dispatchEvent(new CustomEvent("error:notification", {
|
|
17032
|
+
detail: {
|
|
17033
|
+
message,
|
|
17034
|
+
severity,
|
|
17035
|
+
error,
|
|
17036
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17037
|
+
canRetry: this.canRetryError(error)
|
|
17038
|
+
}
|
|
17039
|
+
}));
|
|
17040
|
+
}
|
|
17038
17041
|
}
|
|
17039
17042
|
// Determine if error can be retried
|
|
17040
17043
|
canRetryError(error) {
|
|
@@ -29833,4 +29836,4 @@ export {
|
|
|
29833
29836
|
Chatbot as C,
|
|
29834
29837
|
Widget as W
|
|
29835
29838
|
};
|
|
29836
|
-
//# sourceMappingURL=widget-embed-
|
|
29839
|
+
//# sourceMappingURL=widget-embed-B3A5H6pf.es.js.map
|