@intentai/react 1.0.0 → 1.0.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/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var G=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var G__default=/*#__PURE__*/_interopDefault(G);var Y="https://app.intent-ai.com/widget/v2.js",k=null,E=false;function H(e){return E&&window.IntentAI?Promise.resolve():k||(k=new Promise((t,n)=>{if(document.querySelector(`script[src^="${Y}"]`)){window.IntentAI?(E=true,t()):window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true});return}let o=document.createElement("script");o.src=`${Y}?key=${encodeURIComponent(e.apiKey)}`,o.async=true,o.id="intentai-widget-script",o.onload=()=>{window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true}),setTimeout(()=>{!E&&window.IntentAI&&(E=true,t());},3e3);},o.onerror=()=>{k=null,n(new Error("Failed to load Intent AI widget script"));},document.head.appendChild(o);}),k)}var L={};var q=G.createContext(null),v=typeof window!="undefined";function j(e){if(e)return e;if(typeof process!="undefined"&&process.env){let t=process.env.NEXT_PUBLIC_INTENT_AI_KEY||process.env.REACT_APP_INTENT_AI_KEY||process.env.VITE_INTENT_AI_KEY;if(t)return t}try{if(typeof L!="undefined"&&L.env)return L.env.VITE_INTENT_AI_KEY}catch(t){}}function ee({children:e,apiKey:t,user:n,position:o="bottom-right",theme:p="auto",primaryColor:s,autoShow:a=true,metadata:u,onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O}){let[R,z]=G.useState(false),[N,F]=G.useState(null),b=G.useRef(n),l=G.useRef({onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O});l.current={onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O};let w=G.useMemo(()=>j(t),[t]);G.useEffect(()=>{w&&!w.startsWith("pk_")&&console.error('[IntentAI] Invalid API key format. Public keys should start with "pk_". Never use secret keys (sk_*) in client-side code.');},[w]),G.useEffect(()=>{if(!v)return;if(!w){console.warn("[IntentAI] No API key provided. Set the apiKey prop or NEXT_PUBLIC_INTENT_AI_KEY environment variable.");return}window.IntentAIConfig={apiKey:w,position:o,theme:p,primaryColor:s,autoShow:a,metadata:u};let d=()=>{var i,r,c;z(true),(r=(i=l.current).onReady)==null||r.call(i),b.current&&((c=window.IntentAI)==null||c.identify(b.current));},y=()=>{var i,r;(r=(i=l.current).onOpen)==null||r.call(i);},A=()=>{var i,r;(r=(i=l.current).onClose)==null||r.call(i);},W=i=>{var r,c;(c=(r=l.current).onSubmit)==null||c.call(r,i.detail);},V=i=>{var r,c;F(i.detail),(c=(r=l.current).onError)==null||c.call(r,i.detail);};return window.addEventListener("intentai:ready",d),window.addEventListener("intentai:open",y),window.addEventListener("intentai:close",A),window.addEventListener("intentai:submit",W),window.addEventListener("intentai:error",V),H({apiKey:w}).catch(i=>{var r,c;F(i),(c=(r=l.current).onError)==null||c.call(r,i);}),()=>{window.removeEventListener("intentai:ready",d),window.removeEventListener("intentai:open",y),window.removeEventListener("intentai:close",A),window.removeEventListener("intentai:submit",W),window.removeEventListener("intentai:error",V);}},[w,o,p,s,a,u]),G.useEffect(()=>{b.current=n,v&&R&&n&&window.IntentAI&&window.IntentAI.identify(n);},[n,R]);let M=G.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.open(d):console.warn("[IntentAI] Widget not ready. Call will be ignored."));},[]),U=G.useCallback(()=>{var d;v&&((d=window.IntentAI)==null||d.close());},[]),B=G.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.identify(d):b.current=d);},[]),K=G.useCallback((d,y)=>{var A;v&&((A=window.IntentAI)==null||A.track(d,y));},[]),S=G.useCallback(d=>{var y;v&&((y=window.IntentAI)==null||y.setMetadata(d));},[]),J=G.useMemo(()=>({isReady:R,error:N,open:M,close:U,identify:B,track:K,setMetadata:S}),[R,N,M,U,B,K,S]);return jsxRuntime.jsx(q.Provider,{value:J,children:e})}function I(){let e=G.useContext(q);if(!e)throw new Error('useIntentAI must be used within an IntentAIProvider. Wrap your app with <IntentAIProvider apiKey="pk_...">.');return e}function te(e){let{identify:t,isReady:n}=I();G.useEffect(()=>{n&&(e!=null&&e.id)&&t(e);},[n,e==null?void 0:e.id,e==null?void 0:e.email,e==null?void 0:e.name,t,e]);}var re=G.forwardRef(function({openOptions:t,children:n="Feedback",onClick:o,disabled:p,...s},a){let{open:u,isReady:f}=I();return jsxRuntime.jsx("button",{ref:a,type:"button",onClick:m=>{o==null||o(m),m.defaultPrevented||u(t);},disabled:p||!f,"aria-label":"Open feedback",...s,children:n})});function ie({children:e,openOptions:t}){let{open:n,isReady:o,error:p}=I(),s=a=>{n(a||t);};return typeof e=="function"?e({open:s,isReady:o,error:p}):G__default.default.cloneElement(e,{onClick:a=>{var u,f;(f=(u=e.props).onClick)==null||f.call(u,a),a.defaultPrevented||s();},disabled:e.props.disabled||!o})}function de({user:e,children:t}){let{identify:n,isReady:o}=I();return G.useEffect(()=>{o&&(e!=null&&e.id)&&n(e);},[o,e,n]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function ae({metadata:e,children:t}){let{setMetadata:n,isReady:o}=I();return G.useEffect(()=>{o&&e&&n(e);},[o,e,n]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function se({event:e,properties:t,trigger:n="mount",children:o}){let{track:p,isReady:s}=I(),a=G__default.default.useRef(false);return G.useEffect(()=>{n==="mount"&&s&&!a.current&&(p(e,t),a.current=true);},[s,e,t,p,n]),n==="render"&&s&&p(e,t),jsxRuntime.jsx(jsxRuntime.Fragment,{children:o})}
2
- exports.FeedbackButton=re;exports.FeedbackTrigger=ie;exports.IdentifyUser=de;exports.IntentAIProvider=ee;exports.SetMetadata=ae;exports.TrackEvent=se;exports.useIdentify=te;exports.useIntentAI=I;
1
+ 'use strict';var $=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var $__default=/*#__PURE__*/_interopDefault($);var Y="https://app.intent-ai.com/widget/v1.js",k=null,E=false;function H(e){return E&&window.IntentAI?Promise.resolve():k||(k=new Promise((t,o)=>{if(document.querySelector(`script[src^="${Y}"]`)){window.IntentAI?(E=true,t()):window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true});return}let n=document.createElement("script");n.src=Y,n.async=true,n.id="intentai-widget-script",n.setAttribute("data-api-key",e.apiKey),n.onload=()=>{window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true}),setTimeout(()=>{!E&&window.IntentAI&&(E=true,t());},3e3);},n.onerror=()=>{k=null,o(new Error("Failed to load Intent AI widget script"));},document.head.appendChild(n);}),k)}var L={};var G=$.createContext(null),v=typeof window!="undefined";function j(e){if(e)return e;if(typeof process!="undefined"&&process.env){let t=process.env.NEXT_PUBLIC_INTENT_AI_KEY||process.env.REACT_APP_INTENT_AI_KEY||process.env.VITE_INTENT_AI_KEY;if(t)return t}try{if(typeof L!="undefined"&&L.env)return L.env.VITE_INTENT_AI_KEY}catch(t){}}function ee({children:e,apiKey:t,user:o,position:n="bottom-right",theme:p="auto",primaryColor:s,autoShow:a=true,metadata:I,onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C}){let[R,z]=$.useState(false),[N,F]=$.useState(null),b=$.useRef(o),l=$.useRef({onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C});l.current={onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C};let w=$.useMemo(()=>j(t),[t]);$.useEffect(()=>{w&&!w.startsWith("pk_")&&console.error('[IntentAI] Invalid API key format. Public keys should start with "pk_". Never use secret keys (sk_*) in client-side code.');},[w]),$.useEffect(()=>{if(!v)return;if(!w){console.warn("[IntentAI] No API key provided. Set the apiKey prop or NEXT_PUBLIC_INTENT_AI_KEY environment variable.");return}window.IntentAIConfig={apiKey:w,position:n,theme:p,primaryColor:s,autoShow:a,metadata:I};let d=()=>{var i,r,c;z(true),(r=(i=l.current).onReady)==null||r.call(i),b.current&&((c=window.IntentAI)==null||c.identify(b.current));},y=()=>{var i,r;(r=(i=l.current).onOpen)==null||r.call(i);},A=()=>{var i,r;(r=(i=l.current).onClose)==null||r.call(i);},W=i=>{var r,c;(c=(r=l.current).onSubmit)==null||c.call(r,i.detail);},V=i=>{var r,c;F(i.detail),(c=(r=l.current).onError)==null||c.call(r,i.detail);};return window.addEventListener("intentai:ready",d),window.addEventListener("intentai:open",y),window.addEventListener("intentai:close",A),window.addEventListener("intentai:submit",W),window.addEventListener("intentai:error",V),H({apiKey:w}).catch(i=>{var r,c;F(i),(c=(r=l.current).onError)==null||c.call(r,i);}),()=>{window.removeEventListener("intentai:ready",d),window.removeEventListener("intentai:open",y),window.removeEventListener("intentai:close",A),window.removeEventListener("intentai:submit",W),window.removeEventListener("intentai:error",V);}},[w,n,p,s,a,I]),$.useEffect(()=>{b.current=o,v&&R&&o&&window.IntentAI&&window.IntentAI.identify(o);},[o,R]);let M=$.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.open(d):console.warn("[IntentAI] Widget not ready. Call will be ignored."));},[]),U=$.useCallback(()=>{var d;v&&((d=window.IntentAI)==null||d.close());},[]),B=$.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.identify(d):b.current=d);},[]),K=$.useCallback((d,y)=>{var A;v&&((A=window.IntentAI)==null||A.track(d,y));},[]),S=$.useCallback(d=>{var y;v&&((y=window.IntentAI)==null||y.setMetadata(d));},[]),J=$.useMemo(()=>({isReady:R,error:N,open:M,close:U,identify:B,track:K,setMetadata:S}),[R,N,M,U,B,K,S]);return jsxRuntime.jsx(G.Provider,{value:J,children:e})}function u(){let e=$.useContext(G);if(!e)throw new Error('useIntentAI must be used within an IntentAIProvider. Wrap your app with <IntentAIProvider apiKey="pk_...">.');return e}function te(e){let{identify:t,isReady:o}=u();$.useEffect(()=>{o&&(e!=null&&e.id)&&t(e);},[o,e==null?void 0:e.id,e==null?void 0:e.email,e==null?void 0:e.name,t,e]);}var re=$.forwardRef(function({openOptions:t,children:o="Feedback",onClick:n,disabled:p,...s},a){let{open:I,isReady:f}=u();return jsxRuntime.jsx("button",{ref:a,type:"button",onClick:m=>{n==null||n(m),m.defaultPrevented||I(t);},disabled:p||!f,"aria-label":"Open feedback",...s,children:o})});function ie({children:e,openOptions:t}){let{open:o,isReady:n,error:p}=u(),s=a=>{o(a||t);};return typeof e=="function"?e({open:s,isReady:n,error:p}):$__default.default.cloneElement(e,{onClick:a=>{var I,f;(f=(I=e.props).onClick)==null||f.call(I,a),a.defaultPrevented||s();},disabled:e.props.disabled||!n})}function de({user:e,children:t}){let{identify:o,isReady:n}=u();return $.useEffect(()=>{n&&(e!=null&&e.id)&&o(e);},[n,e,o]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function ae({metadata:e,children:t}){let{setMetadata:o,isReady:n}=u();return $.useEffect(()=>{n&&e&&o(e);},[n,e,o]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function se({event:e,properties:t,trigger:o="mount",children:n}){let{track:p,isReady:s}=u(),a=$__default.default.useRef(false);return $.useEffect(()=>{o==="mount"&&s&&!a.current&&(p(e,t),a.current=true);},[s,e,t,p,o]),o==="render"&&s&&p(e,t),jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})}
2
+ exports.FeedbackButton=re;exports.FeedbackTrigger=ie;exports.IdentifyUser=de;exports.IntentAIProvider=ee;exports.SetMetadata=ae;exports.TrackEvent=se;exports.useIdentify=te;exports.useIntentAI=u;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import G,{createContext,forwardRef,useContext,useState,useRef,useMemo,useEffect,useCallback}from'react';import {jsx,Fragment}from'react/jsx-runtime';var Y="https://app.intent-ai.com/widget/v2.js",k=null,E=false;function H(e){return E&&window.IntentAI?Promise.resolve():k||(k=new Promise((t,n)=>{if(document.querySelector(`script[src^="${Y}"]`)){window.IntentAI?(E=true,t()):window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true});return}let o=document.createElement("script");o.src=`${Y}?key=${encodeURIComponent(e.apiKey)}`,o.async=true,o.id="intentai-widget-script",o.onload=()=>{window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true}),setTimeout(()=>{!E&&window.IntentAI&&(E=true,t());},3e3);},o.onerror=()=>{k=null,n(new Error("Failed to load Intent AI widget script"));},document.head.appendChild(o);}),k)}var L={};var q=createContext(null),v=typeof window!="undefined";function j(e){if(e)return e;if(typeof process!="undefined"&&process.env){let t=process.env.NEXT_PUBLIC_INTENT_AI_KEY||process.env.REACT_APP_INTENT_AI_KEY||process.env.VITE_INTENT_AI_KEY;if(t)return t}try{if(typeof L!="undefined"&&L.env)return L.env.VITE_INTENT_AI_KEY}catch(t){}}function ee({children:e,apiKey:t,user:n,position:o="bottom-right",theme:p="auto",primaryColor:s,autoShow:a=true,metadata:u,onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O}){let[R,z]=useState(false),[N,F]=useState(null),b=useRef(n),l=useRef({onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O});l.current={onReady:f,onOpen:x,onClose:m,onSubmit:C,onError:O};let w=useMemo(()=>j(t),[t]);useEffect(()=>{w&&!w.startsWith("pk_")&&console.error('[IntentAI] Invalid API key format. Public keys should start with "pk_". Never use secret keys (sk_*) in client-side code.');},[w]),useEffect(()=>{if(!v)return;if(!w){console.warn("[IntentAI] No API key provided. Set the apiKey prop or NEXT_PUBLIC_INTENT_AI_KEY environment variable.");return}window.IntentAIConfig={apiKey:w,position:o,theme:p,primaryColor:s,autoShow:a,metadata:u};let d=()=>{var i,r,c;z(true),(r=(i=l.current).onReady)==null||r.call(i),b.current&&((c=window.IntentAI)==null||c.identify(b.current));},y=()=>{var i,r;(r=(i=l.current).onOpen)==null||r.call(i);},A=()=>{var i,r;(r=(i=l.current).onClose)==null||r.call(i);},W=i=>{var r,c;(c=(r=l.current).onSubmit)==null||c.call(r,i.detail);},V=i=>{var r,c;F(i.detail),(c=(r=l.current).onError)==null||c.call(r,i.detail);};return window.addEventListener("intentai:ready",d),window.addEventListener("intentai:open",y),window.addEventListener("intentai:close",A),window.addEventListener("intentai:submit",W),window.addEventListener("intentai:error",V),H({apiKey:w}).catch(i=>{var r,c;F(i),(c=(r=l.current).onError)==null||c.call(r,i);}),()=>{window.removeEventListener("intentai:ready",d),window.removeEventListener("intentai:open",y),window.removeEventListener("intentai:close",A),window.removeEventListener("intentai:submit",W),window.removeEventListener("intentai:error",V);}},[w,o,p,s,a,u]),useEffect(()=>{b.current=n,v&&R&&n&&window.IntentAI&&window.IntentAI.identify(n);},[n,R]);let M=useCallback(d=>{v&&(window.IntentAI?window.IntentAI.open(d):console.warn("[IntentAI] Widget not ready. Call will be ignored."));},[]),U=useCallback(()=>{var d;v&&((d=window.IntentAI)==null||d.close());},[]),B=useCallback(d=>{v&&(window.IntentAI?window.IntentAI.identify(d):b.current=d);},[]),K=useCallback((d,y)=>{var A;v&&((A=window.IntentAI)==null||A.track(d,y));},[]),S=useCallback(d=>{var y;v&&((y=window.IntentAI)==null||y.setMetadata(d));},[]),J=useMemo(()=>({isReady:R,error:N,open:M,close:U,identify:B,track:K,setMetadata:S}),[R,N,M,U,B,K,S]);return jsx(q.Provider,{value:J,children:e})}function I(){let e=useContext(q);if(!e)throw new Error('useIntentAI must be used within an IntentAIProvider. Wrap your app with <IntentAIProvider apiKey="pk_...">.');return e}function te(e){let{identify:t,isReady:n}=I();useEffect(()=>{n&&(e!=null&&e.id)&&t(e);},[n,e==null?void 0:e.id,e==null?void 0:e.email,e==null?void 0:e.name,t,e]);}var re=forwardRef(function({openOptions:t,children:n="Feedback",onClick:o,disabled:p,...s},a){let{open:u,isReady:f}=I();return jsx("button",{ref:a,type:"button",onClick:m=>{o==null||o(m),m.defaultPrevented||u(t);},disabled:p||!f,"aria-label":"Open feedback",...s,children:n})});function ie({children:e,openOptions:t}){let{open:n,isReady:o,error:p}=I(),s=a=>{n(a||t);};return typeof e=="function"?e({open:s,isReady:o,error:p}):G.cloneElement(e,{onClick:a=>{var u,f;(f=(u=e.props).onClick)==null||f.call(u,a),a.defaultPrevented||s();},disabled:e.props.disabled||!o})}function de({user:e,children:t}){let{identify:n,isReady:o}=I();return useEffect(()=>{o&&(e!=null&&e.id)&&n(e);},[o,e,n]),jsx(Fragment,{children:t})}function ae({metadata:e,children:t}){let{setMetadata:n,isReady:o}=I();return useEffect(()=>{o&&e&&n(e);},[o,e,n]),jsx(Fragment,{children:t})}function se({event:e,properties:t,trigger:n="mount",children:o}){let{track:p,isReady:s}=I(),a=G.useRef(false);return useEffect(()=>{n==="mount"&&s&&!a.current&&(p(e,t),a.current=true);},[s,e,t,p,n]),n==="render"&&s&&p(e,t),jsx(Fragment,{children:o})}
2
- export{re as FeedbackButton,ie as FeedbackTrigger,de as IdentifyUser,ee as IntentAIProvider,ae as SetMetadata,se as TrackEvent,te as useIdentify,I as useIntentAI};
1
+ import $,{createContext,forwardRef,useContext,useState,useRef,useMemo,useEffect,useCallback}from'react';import {jsx,Fragment}from'react/jsx-runtime';var Y="https://app.intent-ai.com/widget/v1.js",k=null,E=false;function H(e){return E&&window.IntentAI?Promise.resolve():k||(k=new Promise((t,o)=>{if(document.querySelector(`script[src^="${Y}"]`)){window.IntentAI?(E=true,t()):window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true});return}let n=document.createElement("script");n.src=Y,n.async=true,n.id="intentai-widget-script",n.setAttribute("data-api-key",e.apiKey),n.onload=()=>{window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true}),setTimeout(()=>{!E&&window.IntentAI&&(E=true,t());},3e3);},n.onerror=()=>{k=null,o(new Error("Failed to load Intent AI widget script"));},document.head.appendChild(n);}),k)}var L={};var G=createContext(null),v=typeof window!="undefined";function j(e){if(e)return e;if(typeof process!="undefined"&&process.env){let t=process.env.NEXT_PUBLIC_INTENT_AI_KEY||process.env.REACT_APP_INTENT_AI_KEY||process.env.VITE_INTENT_AI_KEY;if(t)return t}try{if(typeof L!="undefined"&&L.env)return L.env.VITE_INTENT_AI_KEY}catch(t){}}function ee({children:e,apiKey:t,user:o,position:n="bottom-right",theme:p="auto",primaryColor:s,autoShow:a=true,metadata:I,onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C}){let[R,z]=useState(false),[N,F]=useState(null),b=useRef(o),l=useRef({onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C});l.current={onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C};let w=useMemo(()=>j(t),[t]);useEffect(()=>{w&&!w.startsWith("pk_")&&console.error('[IntentAI] Invalid API key format. Public keys should start with "pk_". Never use secret keys (sk_*) in client-side code.');},[w]),useEffect(()=>{if(!v)return;if(!w){console.warn("[IntentAI] No API key provided. Set the apiKey prop or NEXT_PUBLIC_INTENT_AI_KEY environment variable.");return}window.IntentAIConfig={apiKey:w,position:n,theme:p,primaryColor:s,autoShow:a,metadata:I};let d=()=>{var i,r,c;z(true),(r=(i=l.current).onReady)==null||r.call(i),b.current&&((c=window.IntentAI)==null||c.identify(b.current));},y=()=>{var i,r;(r=(i=l.current).onOpen)==null||r.call(i);},A=()=>{var i,r;(r=(i=l.current).onClose)==null||r.call(i);},W=i=>{var r,c;(c=(r=l.current).onSubmit)==null||c.call(r,i.detail);},V=i=>{var r,c;F(i.detail),(c=(r=l.current).onError)==null||c.call(r,i.detail);};return window.addEventListener("intentai:ready",d),window.addEventListener("intentai:open",y),window.addEventListener("intentai:close",A),window.addEventListener("intentai:submit",W),window.addEventListener("intentai:error",V),H({apiKey:w}).catch(i=>{var r,c;F(i),(c=(r=l.current).onError)==null||c.call(r,i);}),()=>{window.removeEventListener("intentai:ready",d),window.removeEventListener("intentai:open",y),window.removeEventListener("intentai:close",A),window.removeEventListener("intentai:submit",W),window.removeEventListener("intentai:error",V);}},[w,n,p,s,a,I]),useEffect(()=>{b.current=o,v&&R&&o&&window.IntentAI&&window.IntentAI.identify(o);},[o,R]);let M=useCallback(d=>{v&&(window.IntentAI?window.IntentAI.open(d):console.warn("[IntentAI] Widget not ready. Call will be ignored."));},[]),U=useCallback(()=>{var d;v&&((d=window.IntentAI)==null||d.close());},[]),B=useCallback(d=>{v&&(window.IntentAI?window.IntentAI.identify(d):b.current=d);},[]),K=useCallback((d,y)=>{var A;v&&((A=window.IntentAI)==null||A.track(d,y));},[]),S=useCallback(d=>{var y;v&&((y=window.IntentAI)==null||y.setMetadata(d));},[]),J=useMemo(()=>({isReady:R,error:N,open:M,close:U,identify:B,track:K,setMetadata:S}),[R,N,M,U,B,K,S]);return jsx(G.Provider,{value:J,children:e})}function u(){let e=useContext(G);if(!e)throw new Error('useIntentAI must be used within an IntentAIProvider. Wrap your app with <IntentAIProvider apiKey="pk_...">.');return e}function te(e){let{identify:t,isReady:o}=u();useEffect(()=>{o&&(e!=null&&e.id)&&t(e);},[o,e==null?void 0:e.id,e==null?void 0:e.email,e==null?void 0:e.name,t,e]);}var re=forwardRef(function({openOptions:t,children:o="Feedback",onClick:n,disabled:p,...s},a){let{open:I,isReady:f}=u();return jsx("button",{ref:a,type:"button",onClick:m=>{n==null||n(m),m.defaultPrevented||I(t);},disabled:p||!f,"aria-label":"Open feedback",...s,children:o})});function ie({children:e,openOptions:t}){let{open:o,isReady:n,error:p}=u(),s=a=>{o(a||t);};return typeof e=="function"?e({open:s,isReady:n,error:p}):$.cloneElement(e,{onClick:a=>{var I,f;(f=(I=e.props).onClick)==null||f.call(I,a),a.defaultPrevented||s();},disabled:e.props.disabled||!n})}function de({user:e,children:t}){let{identify:o,isReady:n}=u();return useEffect(()=>{n&&(e!=null&&e.id)&&o(e);},[n,e,o]),jsx(Fragment,{children:t})}function ae({metadata:e,children:t}){let{setMetadata:o,isReady:n}=u();return useEffect(()=>{n&&e&&o(e);},[n,e,o]),jsx(Fragment,{children:t})}function se({event:e,properties:t,trigger:o="mount",children:n}){let{track:p,isReady:s}=u(),a=$.useRef(false);return useEffect(()=>{o==="mount"&&s&&!a.current&&(p(e,t),a.current=true);},[s,e,t,p,o]),o==="render"&&s&&p(e,t),jsx(Fragment,{children:n})}
2
+ export{re as FeedbackButton,ie as FeedbackTrigger,de as IdentifyUser,ee as IntentAIProvider,ae as SetMetadata,se as TrackEvent,te as useIdentify,u as useIntentAI};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentai/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official React SDK for Intent AI - AI-powered feedback collection widget",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",