@brainfish-ai/widgets-initiator 1.3.0-beta.0 → 1.3.0-beta.3
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 +11 -12
- package/dist/web.cjs.js +2 -2
- package/dist/web.js +3 -3
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -22,22 +22,21 @@ npm install @branfish-ai/web-widget
|
|
|
22
22
|
|
|
23
23
|
<!-- The widget will emit events when it opens and closes. You can listen to these events by adding the following code to your website: -->
|
|
24
24
|
|
|
25
|
-
<!-- For close event: (onBrainfishHelpWidgetClosed) -->
|
|
26
|
-
|
|
27
25
|
<script>
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
// set up the abort controller
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
// get the signal
|
|
29
|
+
const { signal } = controller;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// For close event: (onBrainfishHelpWidgetClosed)
|
|
32
|
+
window.addEventListener('onBrainfishHelpWidgetClosed', yourClosedHandlerFunction, { signal });
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
window.addEventListener('onBrainfishHelpWidgetOpened', yourOpenedHandlerFunction);
|
|
34
|
+
// For opened event: (onBrainfishHelpWidgetOpened)
|
|
35
|
+
window.addEventListener('onBrainfishHelpWidgetOpened', yourOpenedHandlerFunction, { signal });
|
|
35
36
|
</script>
|
|
36
37
|
|
|
37
|
-
<!-- Make sure you remember to remove these event listeners when the widget is no longer needed. -->
|
|
38
|
-
|
|
39
38
|
<script>
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
// abort the event listeners when the widget is no longer needed
|
|
40
|
+
controller.abort();
|
|
42
41
|
</script>
|
|
43
|
-
```
|
|
42
|
+
```
|
package/dist/web.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var C=Object.defineProperty,I=Object.defineProperties;var N=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var p=(t,n,s)=>n in t?C(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s,m=(t,n)=>{for(var s in n||(n={}))L.call(n,s)&&p(t,s,n[s]);if(B)for(var s of B(n))_.call(n,s)&&p(t,s,n[s]);return t},b=(t,n)=>I(t,N(n));var K=(t,n,s)=>p(t,typeof n!="symbol"?n+"":n,s);var f=(t,n,s)=>new Promise((d,i)=>{var r=c=>{try{a(s.next(c))}catch(o){i(o)}},e=c=>{try{a(s.throw(c))}catch(o){i(o)}},a=c=>c.done?d(c.value):Promise.resolve(c.value).then(r,e);a((s=s.apply(t,n)).next())});var w,A;(function(){try{var t=typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},n=new t.Error().stack;n&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[n]="
|
|
2
|
-
Caused by: `+this.cause.stack)}toJSON(){return{name:this.name,message:this.message,stack:this.stack,cause:this.cause instanceof Error?{name:this.cause.name,message:this.cause.message,stack:this.cause.stack}:this.cause}}}(function(t){t.LINK="link",t.CALLBACK="callback",t.EMAIL="email",t.PHONE="phone"})(A||(A={}));const h=(t,n,s,d)=>{let i=s,r={};if(n instanceof Error)try{r=JSON.parse(n.message),i+=` - ${r.message||n.message}`}catch(e){i+=` - ${n.message}`}else i+=` - ${String(n)}`;((e,a,c)=>{if(!navigator||navigator.userAgent.toLowerCase().includes("headless"))return;const o=a.toJSON();fetch(`${e||"https://app.brainfi.sh"}/api/trackError.widget.create`,{method:"POST",headers:{"Content-Type":"application/json","api-key":c},body:JSON.stringify({error:`WebWidgetVersion: 1.3.0-beta.
|
|
1
|
+
"use strict";var C=Object.defineProperty,I=Object.defineProperties;var N=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var p=(t,n,s)=>n in t?C(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s,m=(t,n)=>{for(var s in n||(n={}))L.call(n,s)&&p(t,s,n[s]);if(B)for(var s of B(n))_.call(n,s)&&p(t,s,n[s]);return t},b=(t,n)=>I(t,N(n));var K=(t,n,s)=>p(t,typeof n!="symbol"?n+"":n,s);var f=(t,n,s)=>new Promise((d,i)=>{var r=c=>{try{a(s.next(c))}catch(o){i(o)}},e=c=>{try{a(s.throw(c))}catch(o){i(o)}},a=c=>c.done?d(c.value):Promise.resolve(c.value).then(r,e);a((s=s.apply(t,n)).next())});var w,A;(function(){try{var t=typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},n=new t.Error().stack;n&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[n]="5bbba469-c7ed-47c8-a25f-cdbc24bb7d2a",t._sentryDebugIdIdentifier="sentry-dbid-5bbba469-c7ed-47c8-a25f-cdbc24bb7d2a")}catch(s){}})(),Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),(typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{}).SENTRY_RELEASE={id:"c36c4cf2d8ecb908e550a91798616c5171c4ad47"},function(t){t.Sidebar="sidebar",t.Searchbar="searchbar"}(w||(w={})),w.Sidebar,w.Searchbar;class E extends Error{constructor(s,d){super(s,d);K(this,"cause");this.name="BrainfishWidgetError",this.cause=d==null?void 0:d.cause,Error.captureStackTrace&&Error.captureStackTrace(this,E),this.cause instanceof Error&&this.cause.stack&&(this.stack=this.stack+`
|
|
2
|
+
Caused by: `+this.cause.stack)}toJSON(){return{name:this.name,message:this.message,stack:this.stack,cause:this.cause instanceof Error?{name:this.cause.name,message:this.cause.message,stack:this.cause.stack}:this.cause}}}(function(t){t.LINK="link",t.CALLBACK="callback",t.EMAIL="email",t.PHONE="phone"})(A||(A={}));const h=(t,n,s,d)=>{let i=s,r={};if(n instanceof Error)try{r=JSON.parse(n.message),i+=` - ${r.message||n.message}`}catch(e){i+=` - ${n.message}`}else i+=` - ${String(n)}`;((e,a,c)=>{if(!navigator||navigator.userAgent.toLowerCase().includes("headless"))return;const o=a.toJSON();fetch(`${e||"https://app.brainfi.sh"}/api/trackError.widget.create`,{method:"POST",headers:{"Content-Type":"application/json","api-key":c},body:JSON.stringify({error:`WebWidgetVersion: 1.3.0-beta.3. ${a.message}`,stack:a.stack,cause:{message:o.message,stack:o.stack,cause:o.cause}})})})(t,new E(i,{cause:r}),d)},F=t=>f(exports,null,function*(){let{widgetKey:n,apiHost:s}=t;return function(d,i,r){return f(this,null,function*(){return fetch(`${d}${i}`,{method:"POST",headers:{"Content-Type":"application/json","api-key":r}}).then(e=>{if(!e.ok)throw new Error(`API call failed with status: ${e.status}`);return e.json()}).then(e=>{if(!e)throw new Error("Error loading config: empty response");return e}).catch(e=>{h(d,e,"Error fetching config",r)})})}(s,"/api/searchWidgets.getConfigByKey",n)}),J=t=>{let{config:n,apiKey:s,apiHost:d}=t;const i=n.settings||{};return["bodyActionButtons","footerActionButtons","nextBestActions"].forEach(r=>{i[r]&&(i[r]=i[r].map(e=>e.type===A.CALLBACK&&e.value?b(m({},e),{value:new Function(`return ${e.value}`)()}):e))}),b(m({},n),{settings:i,apiHost:d,widgetMode:n.widgetType,apiKey:s})},$=t=>(t==null?void 0:t.apiHost)||"https://app.brainfi.sh",H=t=>(t==null?void 0:t.analyticsApiHost)||void 0,v=(()=>{if(typeof window=="undefined")return;const t=window.navigator.userAgent;if(!(t.match(/iPad/i)||t.match(/iPhone/i)))return!1;const n=t.match(/OS (\d+)_/i);return n&&parseInt(n[1],10)<=14})(),M=t=>f(exports,null,function*(){let{apiHost:n,widgetKey:s,version:d}=t;try{const i=`https://cdn.jsdelivr.net/npm/@brainfish-ai/search-widget@${d}/dist/web.js`,r=v?i.replace("web.js","web.umd.js"):i;return{widget:yield(a=>f(exports,null,function*(){return document.getElementById("brainfish-widget")?window.Brainfish:new Promise((c,o)=>{const u=document.createElement("script");u.id="brainfish-widget",u.src=a,u.type=v?"text/javascript":"module",u.async=!0,u.crossOrigin="anonymous",u.onload=()=>{setTimeout(()=>{const l=window.Brainfish;l?c(l):o(new Error("Failed to load Brainfish module"))},200)},u.onerror=l=>{const g=l,j={message:`Failed to load script: ${a}`,type:g.type,fileName:g.filename,lineNumber:g.lineno,columnNumber:g.colno,error:g.error?g.error.toString():"Unknown error"};o(new Error(JSON.stringify(j)))},v||document.head.appendChild(u)})}))(r)}}catch(i){h(n,i,i.message,s)}}),T=new Set,W=(t,n)=>f(exports,null,function*(){const s=$(t.overrides);try{if(T.has(t.widgetKey))return;const d=yield M({apiHost:s,widgetKey:t.widgetKey,version:n.version||"latest"});if(d){const{widget:i}=d,r=J({config:n,apiKey:t.widgetKey,apiHost:s});return t.overrides&&n.settings&&Object.entries(t.overrides).forEach(e=>{let[a,c]=e;n.settings&&a in n.settings&&(n.settings[a]=function(){let o=arguments.length>1?arguments[1]:void 0;const u=new Map((arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).map(l=>[l.label,l]));return o.forEach(l=>u.set(l.label,l)),Array.from(u.values())}(n.settings[a],c))}),function(e,a){a.widgetType===w.Searchbar||a.widgetType==="Search"?e.SearchWidget.initStandard(a):e.HelpWidget.initPopup(a)}(i,r),T.add(t.widgetKey),i}}catch(d){h(s,d,d.message,t.widgetKey)}});let O=!1;const P=function(d,i,r){return f(this,arguments,function*(t,n,s){let e=arguments.length>3&&arguments[3]!==void 0?arguments[3]:void 0;if(n||h(s,new Error("Access key is required"),"Access key is required",t),!O)try{window.BrainfishAnalytics("init",{apiUrl:e,accessKey:n,trackScreenViews:!0,trackAttributes:!0,trackOutgoingLinks:!0}),O=!0,yield((a,c)=>f(this,null,function*(){if(document.getElementById("brainfish-analytics"))return window.BrainfishAnalytics;const o=document.createElement("script");o.id="brainfish-analytics",o.src="https://cdn.jsdelivr.net/npm/@brainfish-ai/web-tracker@latest/dist/tracker.js",o.type="module",o.async=!0,o.crossOrigin="anonymous",o.onerror=()=>{h(a,new Error(`Failed to load script: ${o.src}`),`Failed to load script: ${o.src}`,c)},document.head.appendChild(o)}))(s,t)}catch(a){h(s,a,"Failed to initialize BrainfishAnalytics",t)}})};let y=null;const S=typeof window!="undefined"&&window.Brainfish?window.Brainfish:(y||(y=function(){let t=[],n=null;function s(i,r){if(n){const e=i.split(".");let a=n;for(let o=0;o<e.length-1;o++)a=a[e[o]];const c=a[e[e.length-1]];if(typeof c=="function")return c.apply(a,r)}else t.push([i,r])}return{Widgets:{init:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("Widgets.init",r)}},SearchWidget:{initStandard:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("SearchWidget.initStandard",r)}},HelpWidget:{initPopup:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("HelpWidget.initPopup",r)},close:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("HelpWidget.close",r)},open:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("HelpWidget.open",r)},toggle:function(){for(var i=arguments.length,r=new Array(i),e=0;e<i;e++)r[e]=arguments[e];return s("HelpWidget.toggle",r)}},_setRealBrainfish:function(i){for(n=i;t.length>0;){const[r,e]=t.shift();s(r,e)}}}}(),typeof window!="undefined"&&(window.Brainfish=y)),y);let k=null;S.Widgets.init=t=>f(exports,null,function*(){var n;window&&(window.BrainfishAnalytics=window.BrainfishAnalytics||function(){for(var e=arguments.length,a=new Array(e),c=0;c<e;c++)a[c]=arguments[c];(window.BrainfishAnalytics.q=window.BrainfishAnalytics.q||[]).push(a)});const s=$(t.overrides),d=H(t.overrides),{config:i}=yield F({widgetKey:t.widgetKey,apiHost:s});k||(k=function(e,a,c,o){return f(this,null,function*(){var u;const l=[W(e,a)];(u=a.settings)!==null&&u!==void 0&&u.enableTracking&&l.push(P(e.widgetKey,a.trackingToken||"",c,o));const[g]=yield Promise.allSettled(l);g.status==="fulfilled"&&g.value&&S._setRealBrainfish(g.value)})}(t,i,s,d)),yield k;const r=[W(t,i)];if((n=i.settings)!==null&&n!==void 0&&n.enableTracking){const e=H(t.overrides);r.push(P(t.widgetKey,i.trackingToken||"",s,e))}yield Promise.allSettled(r)});exports.BrainfishAnalytics=function(){typeof window!="undefined"&&window.BrainfishAnalytics&&window.BrainfishAnalytics(...arguments)},exports.default=S;
|
|
3
3
|
//# sourceMappingURL=web.cjs.js.map
|
package/dist/web.js
CHANGED
|
@@ -31,10 +31,10 @@ var w, A;
|
|
|
31
31
|
(function() {
|
|
32
32
|
try {
|
|
33
33
|
var t = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {}, n = new t.Error().stack;
|
|
34
|
-
n && (t._sentryDebugIds = t._sentryDebugIds || {}, t._sentryDebugIds[n] = "
|
|
34
|
+
n && (t._sentryDebugIds = t._sentryDebugIds || {}, t._sentryDebugIds[n] = "3b2289d9-84fc-43e7-9533-124f5c0b541e", t._sentryDebugIdIdentifier = "sentry-dbid-3b2289d9-84fc-43e7-9533-124f5c0b541e");
|
|
35
35
|
} catch (s) {
|
|
36
36
|
}
|
|
37
|
-
})(), (typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {}).SENTRY_RELEASE = { id: "
|
|
37
|
+
})(), (typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {}).SENTRY_RELEASE = { id: "c36c4cf2d8ecb908e550a91798616c5171c4ad47" }, function(t) {
|
|
38
38
|
t.Sidebar = "sidebar", t.Searchbar = "searchbar";
|
|
39
39
|
}(w || (w = {})), w.Sidebar, w.Searchbar;
|
|
40
40
|
class E extends Error {
|
|
@@ -62,7 +62,7 @@ const h = (t, n, s, d) => {
|
|
|
62
62
|
((e, a, c) => {
|
|
63
63
|
if (!navigator || navigator.userAgent.toLowerCase().includes("headless")) return;
|
|
64
64
|
const o = a.toJSON();
|
|
65
|
-
fetch(`${e || "https://app.brainfi.sh"}/api/trackError.widget.create`, { method: "POST", headers: { "Content-Type": "application/json", "api-key": c }, body: JSON.stringify({ error: `WebWidgetVersion: 1.3.0-beta.
|
|
65
|
+
fetch(`${e || "https://app.brainfi.sh"}/api/trackError.widget.create`, { method: "POST", headers: { "Content-Type": "application/json", "api-key": c }, body: JSON.stringify({ error: `WebWidgetVersion: 1.3.0-beta.3. ${a.message}`, stack: a.stack, cause: { message: o.message, stack: o.stack, cause: o.cause } }) });
|
|
66
66
|
})(t, new E(i, { cause: r }), d);
|
|
67
67
|
}, F = (t) => f(void 0, null, function* () {
|
|
68
68
|
let { widgetKey: n, apiHost: s } = t;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brainfish-ai/widgets-initiator",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -20,24 +20,21 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/plugin-
|
|
24
|
-
"@babel/plugin-
|
|
23
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.18.6",
|
|
24
|
+
"@babel/plugin-transform-optional-chaining": "^7.21.0",
|
|
25
|
+
"@brainfish-ai/widgets-common": "1.0.7",
|
|
25
26
|
"@rollup/plugin-babel": "^6.0.4",
|
|
27
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
26
28
|
"@sentry/vite-plugin": "^2.22.4",
|
|
27
|
-
"@types/dotenv": "^8.2.0",
|
|
28
29
|
"animated-tailwindcss": "^4.0.0",
|
|
29
30
|
"autoprefixer": "^10.4.16",
|
|
30
31
|
"postcss": "^8.4.31",
|
|
31
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
32
32
|
"rollup-plugin-visualizer": "^5.12.0",
|
|
33
33
|
"tailwindcss": "^3.4.3",
|
|
34
34
|
"typescript": "^5.4.5",
|
|
35
35
|
"vite": "^5.2.12",
|
|
36
36
|
"vitest": "^2.0.5"
|
|
37
37
|
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@brainfish-ai/widgets-common": "1.0.6"
|
|
40
|
-
},
|
|
41
38
|
"keywords": [
|
|
42
39
|
"typescript",
|
|
43
40
|
"web",
|