@dori-ai/dori-side-widget 1.7.4-dev.20260501160705 → 1.8.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/dist/widget.js +1 -1
- package/dist/widget.js.br +0 -0
- package/dist/widget.js.gz +0 -0
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={};let
|
|
1
|
+
const t={};let r=null;function e(t){let r=t.replace(/<thought>[\s\S]*?<\/thought>/gi,"");return r=r.replace(/<thought>[\s\S]*$/gi,""),r.trim()}const o=t=>{if(!t)return;const e=t.closest('[data-scroll-container="chat-messages"]');e&&null===r&&(r=setTimeout(()=>{r=null,e.scrollTo({top:e.scrollHeight,behavior:"smooth"})},200))},n=(t,r)=>{const e=t||"Dori";return`${r.hiIm} ${e}!`},a={BOT_DATA:"dori_widget_bot_data",BOT_DATA_ETAG:"dori_widget_bot_data_etag",CHAT_STATE:"dori_widget_chat_state",MESSAGES:"dori_widget_messages",CURRENT_STEP:"dori_widget_current_step",SESSION_TIMESTAMP:"dori_widget_session_timestamp",FAB_ANIMATION_TIMESTAMP:"dori_widget_fab_animation_timestamp",DORI_THREAD_ID:"dori_thread_id",DORI_SESSION_KEY:"dori_session_key",LOADED_FROM_STORAGE:"dori_loaded_from_storage",SHOPIFY_END_USER_ID:"dori_shopify_end_user_id",SHOPIFY_END_USER_SESSION:"dori_shopify_end_user_session"};function s(){try{const t="__test__";return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch{return!1}}function i(){s()&&localStorage.setItem(a.LOADED_FROM_STORAGE,"true")}function c(){s()&&localStorage.removeItem(a.LOADED_FROM_STORAGE)}function l(){return!!s()&&"true"===localStorage.getItem(a.LOADED_FROM_STORAGE)}function u(){try{const t=localStorage.getItem(a.SESSION_TIMESTAMP);if(!t)return!1;const r=parseInt(t,10);return Date.now()-r<864e5}catch{return!1}}function d(){if(s())try{[a.CHAT_STATE,a.MESSAGES,a.CURRENT_STEP,a.DORI_THREAD_ID,a.DORI_SESSION_KEY,a.LOADED_FROM_STORAGE,a.SHOPIFY_END_USER_ID,a.SHOPIFY_END_USER_SESSION].forEach(t=>{localStorage.removeItem(t)})}catch(t){console.error("Error clearing local storage:",t)}}function _(t){if(s())try{t?localStorage.setItem(a.BOT_DATA,JSON.stringify(t)):localStorage.removeItem(a.BOT_DATA)}catch(r){console.error("Error saving bot data:",r)}}function S(){if(!s()||!u())return null;try{const t=localStorage.getItem(a.BOT_DATA);return t?JSON.parse(t):null}catch(t){return console.error("Error loading bot data:",t),null}}function g(t){if(s())try{localStorage.setItem(a.CHAT_STATE,JSON.stringify(t))}catch(r){console.error("Error saving chat state:",r)}}function E(t){if(s())try{const r=t.map(t=>({...t,timestamp:t.timestamp instanceof Date?t.timestamp.toISOString():t.timestamp}));localStorage.setItem(a.MESSAGES,JSON.stringify(r))}catch(r){console.error("Error saving messages:",r)}}function f(){if(!s()||!u())return[];try{const t=localStorage.getItem(a.MESSAGES);return t?JSON.parse(t).map(t=>({...t,content:"string"==typeof t.content?e(t.content):t.content,timestamp:new Date(t.timestamp)})):[]}catch(t){return console.error("Error loading messages:",t),[]}}function m(t){if(s())try{localStorage.setItem(a.CURRENT_STEP,t)}catch(r){console.error("Error saving current step:",r)}}function h(){if(!s()||!u())return null;try{const t=S(),r=function(){if(!s()||!u())return null;try{const t=localStorage.getItem(a.CHAT_STATE);return t?JSON.parse(t):null}catch(t){return console.error("Error loading chat state:",t),null}}(),e=f(),o=function(){if(!s()||!u())return"welcome";try{return localStorage.getItem(a.CURRENT_STEP)||"welcome"}catch(t){return console.error("Error loading current step:",t),"welcome"}}();return t||e.length>0?{botData:t,chatState:r||{repliedProduct:null,threadId:null,isRequestInProgress:!1},messages:e,currentStep:o,sessionTimestamp:Date.now()}:null}catch(t){return console.error("Error loading session data:",t),null}}function I(){if(!s()||!u())return!1;try{const t=S(),r=f();return!!(t||r.length>0)}catch{return!1}}function T(){if(s())try{localStorage.setItem(a.SESSION_TIMESTAMP,Date.now().toString())}catch(t){console.error("Error updating session timestamp:",t)}}function A(){if(s())try{localStorage.setItem(a.FAB_ANIMATION_TIMESTAMP,Date.now().toString())}catch(t){console.error("Error saving FAB animation timestamp:",t)}}function D(){const t=function(){if(!s()||!u())return null;try{const t=localStorage.getItem(a.FAB_ANIMATION_TIMESTAMP);return t?parseInt(t,10):null}catch(t){return console.error("Error loading FAB animation timestamp:",t),null}}();return!t||Date.now()-t>=3e5}function w(){if(!s())return"";try{let t=localStorage.getItem(a.DORI_SESSION_KEY);return t||(t="dori_session_"+Date.now()+"_"+Math.random().toString(36).substr(2,9),localStorage.setItem(a.DORI_SESSION_KEY,t)),t}catch(t){return console.error("Error generating session key:",t),""}}function O(t){if(s()&&t)try{localStorage.setItem(a.DORI_THREAD_ID,t)}catch(r){console.error("Error storing dori thread ID:",r)}}function p(){if(!s())return null;try{return localStorage.getItem(a.DORI_THREAD_ID)}catch(t){return console.error("Error retrieving dori thread ID:",t),null}}function y(t){const r=window?.chatbotData;if("undefined"!=typeof window&&r?.ajaxurl){const e=w();fetch(r.ajaxurl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"dori_store_thread_session",thread_id:t,session_key:e,nonce:r.nonce})}).catch(t=>console.warn("Failed to store thread in WooCommerce session:",t))}}const R="https://standardapi.dori.tech",N="dori-bot-data-ready",v="dori-bot-data-error",M=(t,r)=>{window.dispatchEvent(new CustomEvent(t,r?{detail:{error:r}}:void 0))},P=(t,r)=>{_(t),r&&function(t){if(s())try{t?localStorage.setItem(a.BOT_DATA_ETAG,t):localStorage.removeItem(a.BOT_DATA_ETAG)}catch(r){console.error("Error saving ETag:",r)}}(r)};!async function(){try{const r=(()=>{const t=document.querySelector("script#dori-side-widget");return t?.getAttribute("data-sharing-id")||null})();if(!r)return void M(v,"No sharing ID found");const e=S(),o=function(){if(!s()||!u())return null;try{return localStorage.getItem(a.BOT_DATA_ETAG)}catch(t){return console.error("Error loading ETag:",t),null}}(),n=`${R}/bot-sharing-data/${r}`;e&&M(N);try{const t=o?{"If-None-Match":o}:{},r=await fetch(n,{headers:t});if(304===r.status){if(!e){const t=await(async t=>{const r=await fetch(t);if(200!==r.status)throw new Error(`Failed to fetch bot data: ${r.status}`);const e=await r.json();if(e.error)throw new Error(e.error);if(!e.data)throw new Error("No data received from bot sharing API");return e})(n);P(t.data,r.headers.get("ETag")),M(N)}return}if(200===r.status){const t=await r.json();if(t.error)throw new Error(t.error);if(!t.data)throw new Error("No data received");return P(t.data,r.headers.get("ETag")),void M(N)}throw new Error(`Failed to fetch bot data: ${r.status}`)}catch(t){if(e)return;const r=t instanceof Error?t.message:String(t);M(v,r)}}catch(t){const r=t instanceof Error?t.message:String(t);M(v,r)}}(),async function(){try{const{initializeDoriWidget:r}=await function(r,e,o){let n=Promise.resolve();if(e&&e.length>0){let r=function(t){return Promise.all(t.map(t=>Promise.resolve(t).then(t=>({status:"fulfilled",value:t}),t=>({status:"rejected",reason:t}))))};const a=document.getElementsByTagName("link"),s=document.querySelector("meta[property=csp-nonce]"),i=s?.nonce||s?.getAttribute("nonce");n=r(e.map(r=>{if(r=function(t,r){return new URL(t,r).href}(r,o),r in t)return;t[r]=!0;const e=r.endsWith(".css"),n=e?'[rel="stylesheet"]':"";if(o)for(let t=a.length-1;t>=0;t--){const o=a[t];if(o.href===r&&(!e||"stylesheet"===o.rel))return}else if(document.querySelector(`link[href="${r}"]${n}`))return;const s=document.createElement("link");return s.rel=e?"stylesheet":"modulepreload",e||(s.as="script"),s.crossOrigin="",s.href=r,i&&s.setAttribute("nonce",i),document.head.appendChild(s),e?new Promise((t,e)=>{s.addEventListener("load",t),s.addEventListener("error",()=>e(new Error(`Unable to preload CSS for ${r}`)))}):void 0}))}function a(t){const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=t,window.dispatchEvent(r),!r.defaultPrevented)throw t}return n.then(t=>{for(const r of t||[])"rejected"===r.status&&a(r.reason);return r().catch(a)})}(async()=>{const{initializeDoriWidget:t}=await import("./assets/main-CWGghETV.js");return{initializeDoriWidget:t}},[],import.meta.url);r()}catch(r){console.error("[Dori Widget] Error initializing widget:",r)}}();export{R as A,a as S,g as a,E as b,m as c,h as d,o as e,d as f,p as g,I as h,c as i,O as j,y as k,f as l,i as m,e as n,S as o,n as p,l as q,w as r,_ as s,D as t,T as u,A as v};
|
package/dist/widget.js.br
CHANGED
|
Binary file
|
package/dist/widget.js.gz
CHANGED
|
Binary file
|