@embeddable/sdk 1.0.26 → 1.0.28
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/EmbeddableProvider-CGNt-5fg.cjs +10 -0
- package/dist/{EmbeddableProvider-DcKUcLRy.js → EmbeddableProvider-v_5vMWDf.js} +136 -40
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAI.d.ts.map +1 -1
- package/dist/hooks/useDataIntegration.d.ts.map +1 -1
- package/dist/hooks/useFormSubmission.d.ts.map +1 -1
- package/dist/hooks/usePayment.d.ts.map +1 -1
- package/dist/hooks/usePublicSubmissions.d.ts.map +1 -1
- package/dist/hooks/useScraping.d.ts +43 -0
- package/dist/hooks/useScraping.d.ts.map +1 -0
- package/dist/hooks/useVote.d.ts.map +1 -1
- package/dist/hooks/useVoteAggregations.d.ts.map +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +4 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -3
- package/package.json +1 -1
- package/dist/EmbeddableProvider-BPZowxyJ.cjs +0 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";const e=require("react"),t=require("./storage-BtXo3gya.cjs");var r,n={exports:{}},s={};var a,o={};
|
|
2
|
+
/**
|
|
3
|
+
* @license React
|
|
4
|
+
* react-jsx-runtime.development.js
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*/"production"===process.env.NODE_ENV?n.exports=function(){if(r)return s;r=1;var t=e,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function u(e,t,r){var s,a={},u=null,l=null;for(s in void 0!==r&&(u=""+r),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(l=t.ref),t)o.call(t,s)&&!i.hasOwnProperty(s)&&(a[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===a[s]&&(a[s]=t[s]);return{$$typeof:n,type:e,key:u,ref:l,props:a,_owner:c.current}}return s.Fragment=a,s.jsx=u,s.jsxs=u,s}():n.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var t,r=e,n=Symbol.for("react.element"),s=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),l=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),g=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),y=Symbol.for("react.offscreen"),v=Symbol.iterator,b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var s=r.map(function(e){return String(e)});s.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,s)}("error",e,r)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case s:return"Portal";case i:return"Profiler";case c:return"StrictMode";case f:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return w(e)+".Consumer";case u:return w(e._context)+".Provider";case d:return function(e,t,r){var n=e.displayName;if(n)return n;var s=t.displayName||t.name||"";return""!==s?r+"("+s+")":r}(e,e.render,"ForwardRef");case g:var t=e.displayName||null;return null!==t?t:k(e.type)||"Memo";case m:var r=e,n=r._payload,o=r._init;try{return k(o(n))}catch(y){return null}}return null}t=Symbol.for("react.module.reference");var _,S,E,C,T,j,O,I=Object.assign,P=0;function x(){}x.__reactDisabledLog=!0;var R,$=b.ReactCurrentDispatcher;function N(e,t,r){if(void 0===R)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);R=n&&n[1]||""}return"\n"+R+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,t){if(!e||F)return"";var r,n=D.get(e);if(void 0!==n)return n;F=!0;var s,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,s=$.current,$.current=null,function(){if(0===P){_=console.log,S=console.info,E=console.warn,C=console.error,T=console.group,j=console.groupCollapsed,O=console.groupEnd;var e={configurable:!0,enumerable:!0,value:x,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();try{if(t){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){r=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){r=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){r=g}e()}}catch(m){if(m&&r&&"string"==typeof m.stack){for(var c=m.stack.split("\n"),i=r.stack.split("\n"),u=c.length-1,l=i.length-1;u>=1&&l>=0&&c[u]!==i[l];)l--;for(;u>=1&&l>=0;u--,l--)if(c[u]!==i[l]){if(1!==u||1!==l)do{if(u--,--l<0||c[u]!==i[l]){var d="\n"+c[u].replace(" at new "," at ");return e.displayName&&d.includes("<anonymous>")&&(d=d.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,d),d}}while(u>=1&&l>=0);break}}}finally{F=!1,$.current=s,function(){if(0===--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:I({},e,{value:_}),info:I({},e,{value:S}),warn:I({},e,{value:E}),error:I({},e,{value:C}),group:I({},e,{value:T}),groupCollapsed:I({},e,{value:j}),groupEnd:I({},e,{value:O})})}P<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var f=e?e.displayName||e.name:"",p=f?N(f):"";return"function"==typeof e&&D.set(e,p),p}function A(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case f:return N("Suspense");case p:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return U(e.render,!1);case g:return A(e.type,t,r);case m:var s=e,a=s._payload,o=s._init;try{return A(o(a),t,r)}catch(c){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,W={},J=b.ReactDebugCurrentFrame;function H(e){if(e){var t=e._owner,r=A(e.type,e._source,t?t.type:null);J.setExtraStackFrame(r)}else J.setExtraStackFrame(null)}var K=Array.isArray;function z(e){return K(e)}function B(e){return""+e}function M(e){if(function(e){try{return B(e),!1}catch(t){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),B(e)}var Y,q,G=b.ReactCurrentOwner,X={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,r,s,a){var o,c={},i=null,u=null;for(o in void 0!==r&&(M(r),i=""+r),function(e){if(V.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(M(t.key),i=""+t.key),function(e){if(V.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(u=t.ref,function(e){"string"==typeof e.ref&&G.current}(t)),t)V.call(t,o)&&!X.hasOwnProperty(o)&&(c[o]=t[o]);if(e&&e.defaultProps){var l=e.defaultProps;for(o in l)void 0===c[o]&&(c[o]=l[o])}if(i||u){var d="function"==typeof e?e.displayName||e.name||"Unknown":e;i&&function(e,t){var r=function(){Y||(Y=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(c,d),u&&function(e,t){var r=function(){q||(q=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(c,d)}return function(e,t,r,s,a,o,c){var i={$$typeof:n,type:e,key:t,ref:r,props:c,_owner:o,_store:{}};return Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i}(e,i,u,a,s,G.current,c)}var Z,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=A(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function se(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var ae={};function oe(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=se();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!ae[r]){ae[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),re(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),re(null)}}}function ce(e,t){if("object"==typeof e)if(z(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&oe(n,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var s=function(e){if(null===e||"object"!=typeof e)return null;var t=v&&e[v]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof s&&s!==e.entries)for(var a,o=s.call(e);!(a=o.next()).done;)ne(a.value)&&oe(a.value,t)}}function ie(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==d&&r.$$typeof!==g)return;t=r.propTypes}if(t){var n=k(r);!function(e,t,r,n,s){var a=Function.call.bind(V);for(var o in e)if(a(e,o)){var c=void 0;try{if("function"!=typeof e[o]){var i=Error((n||"React class")+": "+r+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw i.name="Invariant Violation",i}c=e[o](t,o,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){c=u}!c||c instanceof Error||(H(s),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",r,o,typeof c),H(null)),c instanceof Error&&!(c.message in W)&&(W[c.message]=!0,H(s),h("Failed %s type: %s",r,c.message),H(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ue={};function le(e,r,s,o,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===i||e===c||e===f||e===p||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===g||e.$$typeof===u||e.$$typeof===l||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!w){var _,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=se(),null===e?_="null":z(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,S)}var E=Q(e,r,s,v,b);if(null==E)return E;if(w){var C=r.children;if(void 0!==C)if(o)if(z(C)){for(var T=0;T<C.length;T++)ce(C[T],e);Object.freeze&&Object.freeze(C)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ce(C,e)}if(V.call(r,"key")){var j=k(e),O=Object.keys(r).filter(function(e){return"key"!==e}),I=O.length>0?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}";ue[j+I]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',I,j,O.length>0?"{"+O.join(": ..., ")+": ...}":"{}",j),ue[j+I]=!0)}return e===a?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(E):ie(E),E}var de=function(e,t,r){return le(e,t,r,!1)},fe=function(e,t,r){return le(e,t,r,!0)};o.Fragment=a,o.jsx=de,o.jsxs=fe}()),o);var c=n.exports;const i="https://events.embeddable.co";function u(){const{config:e}=g();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}const l=()=>{const{widgetId:t,mode:r}=u(),n=`${i}/api`,[s,a]=e.useState(!1),o=e.useCallback(async e=>{if(!t||"preview"===r)return[];const s=[];try{a(!0);const r=await fetch(`${n}/marketing/track`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify({widgetId:t,capabilityId:"trackEvent",inputs:e})}),o=await r.json();o.success?o.results?o.results.forEach(e=>{s.push({success:e.success,integrationKey:e.integrationKey,data:e.data,error:e.error})}):s.push({success:!0,data:o.data}):s.push({success:!1,error:o.error||"Unknown error"})}catch(o){s.push({success:!1,error:o instanceof Error?o.message:"Network error"})}finally{a(!1)}return s},[t,n,r]),c=e.useCallback(async(e={})=>o({event_name:"page_view",event_category:"engagement",custom_parameters:{page_url:window.location.href,page_title:document.title,referrer:document.referrer,...e}}),[o]),l=e.useCallback(async(e,t={})=>o({event_name:"form_submit",event_category:"conversion",custom_parameters:{form_data:e,...t}}),[o]),d=e.useCallback(async(e,t={})=>{let r={};return r="string"==typeof e?{element_selector:e}:{element_id:e.id,element_class:e.className,element_text:e.textContent||e.innerText,element_tag:e.tagName.toLowerCase()},o({event_name:"button_click",event_category:"interaction",custom_parameters:{...r,...t}})},[o]),f=e.useCallback(async(e,t,r={})=>o({event_name:"conversion",event_category:"conversion",value:t,custom_parameters:{conversion_type:e,currency:r.currency||"USD",...r}}),[o]),p=e.useCallback(async(e,t={})=>o({event_name:"signup",event_category:"conversion",user_data:e,custom_parameters:t}),[o]),g=e.useCallback(async(e,t={})=>o({event_name:"purchase",event_category:"ecommerce",value:e.amount,custom_parameters:{transaction_id:e.id,currency:e.currency||"USD",items:e.items||[],...t}}),[o]),m=e.useCallback(()=>{c()},[c]),y=e.useCallback(()=>{const e=async e=>{try{const t=e.target,r=new FormData(t),n=Object.fromEntries(r.entries());await l(n,{form_id:t.id,form_class:t.className,form_action:t.action,form_method:t.method})}catch(t){}};return document.addEventListener("submit",e),()=>{document.removeEventListener("submit",e)}},[l]),v=e.useCallback((e='button, .btn, [role="button"], a, input[type="submit"]')=>{const t=async t=>{const r=t.target.closest(e);if(r)try{await d(r)}catch(n){}};return document.addEventListener("click",t),()=>{document.removeEventListener("click",t)}},[d]);return{isLoading:s,track:o,trackPageView:c,trackFormSubmit:l,trackClick:d,trackConversion:f,trackSignup:p,trackPurchase:g,enableAutoPageView:m,enableAutoFormTracking:y,enableAutoClickTracking:v}};const d={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},f=e.createContext({config:{...d},setConfig:()=>{},data:{},setData:()=>{}});function p(){const{trackPageView:t}=l(),{config:r}=g();return e.useEffect(()=>{(null==r?void 0:r.widgetId)&&"preview"!==(null==r?void 0:r.mode)&&t()},[null==r?void 0:r.widgetId,null==r?void 0:r.mode,t]),null}function g(){const t=e.useContext(f);if(!t)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return t}exports.EmbeddableProvider=function({config:t,data:r,children:n}){const[s,a]=e.useState(d),[o,i]=e.useState(r||{});return e.useEffect(()=>{const e={...d,...t};a(e)},[t]),e.useEffect(()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&i(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),c.jsxs(f.Provider,{value:{config:s,setConfig:a,data:o,setData:i},children:[c.jsx(p,{}),n]})},exports.useAI=function(t){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,success:!1});return{...s,callAI:e.useCallback(async(e,t)=>{var s;a({loading:!0,error:null,success:!1});try{const o={widgetId:r,capabilityId:"aiCall",integrationKey:n.current.platform,prompt:e,history:t||[],inputs:n.current.inputs||{}};"embeddable-ai"!==n.current.platform&&(delete o.inputs.systemPrompt,delete o.inputs.maxTokens);const c=await fetch(`${i}/api/execute/ai`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(o)}),u=await c.json();if(!c.ok){const e=u.message||u.error||`HTTP ${c.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(u.success)return a({loading:!1,error:null,success:!0}),{success:!0,message:(null==(s=u.data)?void 0:s.response)||"AI call completed successfully",data:u.data,metadata:u.metadata};{const e=u.message||u.error||"AI call failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(o){const e=o instanceof Error?o.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useDataIntegration=function(t={}){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,success:!1});return{...s,fetchData:e.useCallback(async()=>{a({loading:!0,error:null,success:!1});try{const e={widgetId:r,capabilityId:n.current.capabilityId||"fetchData",integrationKey:n.current.integrationKey||"sheets"},t=await fetch(`${i}/api/execute/data`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(e)}),s=await t.json();if(!t.ok){const e=s.message||s.error||`HTTP ${t.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(s.success)return a({loading:!1,error:null,success:!0}),{success:!0,message:"Data fetched successfully",data:s.data,metadata:s.metadata};{const e=s.message||s.error||"Data fetch failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";return a({loading:!1,error:t,success:!1}),{success:!1,message:t}}},[r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useDebounce=function(t,r){const[n,s]=e.useState(t);return e.useEffect(()=>{const e=setTimeout(()=>{s(t)},r);return()=>{clearTimeout(e)}},[t,r]),n},exports.useEmbeddableConfig=u,exports.useEmbeddableContext=g,exports.useEmbeddableData=function(){const{data:e}=g();return{data:e}},exports.useEventTracking=l,exports.useFileUpload=function(){const{widgetId:t}=u(),[r,n]=e.useState({loading:!1,error:null,success:!1});return{...r,uploadFile:e.useCallback(async e=>{n({loading:!0,error:null,success:!1});try{const r=new FormData;r.append("file",e),r.append("widgetId",t);const s=await fetch(`${i}/api/execute/uploads`,{method:"POST",credentials:"omit",body:r}),a=await s.json();if(!s.ok){const e=a.message||a.error||`HTTP ${s.status}`;return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(a.success)return n({loading:!1,error:null,success:!0}),{success:!0,message:a.message||"File uploaded successfully",data:a.data};{const e=a.message||a.error||"File upload failed";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(r){const e=r instanceof Error?r.message:"Unknown error occurred";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t]),reset:e.useCallback(()=>{n({loading:!1,error:null,success:!1})},[])}},exports.useFormSubmission=function(t){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,success:!1});return{...s,submit:e.useCallback(async e=>{var t,s,o,c,u;a({loading:!0,error:null,success:!1});try{if(null==(t=n.current)?void 0:t.validatePayload){const t=n.current.validatePayload(e);if(t)return a({loading:!1,error:t,success:!1}),{success:!1,message:t}}const l={payload:e,widgetId:r,collectionName:(null==(s=n.current)?void 0:s.collectionName)||"submissions"},d=await fetch(`${i}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(l)}),f=await d.json();if(!d.ok){const e=f.message||f.error||`HTTP ${d.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(f.success)return a({loading:!1,error:null,success:!0}),{id:(null==(o=f.data)?void 0:o.id)||(null==(c=f.data)?void 0:c._id),success:!0,message:(null==(u=f.data)?void 0:u.message)||"Submission successful"};{const e=f.message||f.error||"Submission failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(l){const e=l instanceof Error?l.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useLocalStorage=function(r,n,s={}){const{widgetId:a}=u(),o=e.useMemo(()=>({...s,prefix:`embd-${a}-${s.prefix||""}`}),[a,s]),[c,i]=e.useState(()=>{const e=t.storage.get(r,o);return null!==e?e:n}),l=e.useCallback(e=>{try{const n=e instanceof Function?e(c):e;i(n),t.storage.set(r,n,o)}catch(n){}},[r,c,o]),d=e.useCallback(()=>{try{i(n),t.storage.remove(r,o)}catch(e){}},[r,n,o]);return e.useEffect(()=>{const e=e=>{const t=o.prefix+r;if(e.key===t&&null!==e.newValue)try{const{deserialize:t=JSON.parse}=o,r=t(e.newValue);i(r)}catch(n){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[r,o]),[c,l,d]},exports.usePayment=function(t={}){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,success:!1}),o=e.useRef(null);e.useEffect(()=>()=>{o.current&&window.clearInterval(o.current)},[]);const c=e.useCallback(async e=>{var t,s,c,u;try{const l=await fetch(`${i}/api/execute/payments/session/${e}?widgetId=${r}`,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),d=await l.json();if(!l.ok)return;if(d.success&&d.session){const{status:e,payment_status:r}=d.session;"paid"===r&&"complete"===e?(o.current&&(window.clearInterval(o.current),o.current=null),a({loading:!1,error:null,success:!0}),null==(s=(t=n.current).onSuccess)||s.call(t,d.session)):"expired"===e&&(o.current&&(window.clearInterval(o.current),o.current=null),a({loading:!1,error:"Payment session expired",success:!1}),null==(u=(c=n.current).onFailure)||u.call(c,d.session))}}catch(l){}},[r]),l=e.useCallback(e=>{o.current&&window.clearInterval(o.current),o.current=window.setInterval(()=>{c(e)},1e4),c(e)},[c]);return{...s,createCheckout:e.useCallback(async e=>{var t;a({loading:!0,error:null,success:!1});try{const s={widgetId:r,capabilityId:n.current.capabilityId||"getCheckout",integrationKey:n.current.integrationKey||"stripe",inputs:e},o=await fetch(`${i}/api/execute/payments`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(s)}),c=await o.json();if(!o.ok){const e=c.message||c.error||`HTTP ${o.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(c.success)return(null==(t=c.data)?void 0:t.sessionId)&&l(c.data.sessionId),a({loading:!1,error:null,success:!1}),{success:!0,message:"Checkout session created successfully",data:c.data,metadata:c.metadata};{const e=c.message||c.error||"Payment checkout failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(s){const e=s instanceof Error?s.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[r,l]),reset:e.useCallback(()=>{o.current&&(window.clearInterval(o.current),o.current=null),a({loading:!1,error:null,success:!1})},[])}},exports.usePublicSubmissions=function(t){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,data:null,pagination:null}),o=e.useCallback(async e=>{a(e=>({...e,loading:!0,error:null}));try{const t={...n.current,...e},s=new URLSearchParams;s.append("widgetId",r),(null==t?void 0:t.collectionName)&&s.append("collectionName",t.collectionName),s.append("page",String((null==t?void 0:t.page)||1)),s.append("limit",String((null==t?void 0:t.limit)||10)),s.append("sortBy",(null==t?void 0:t.sortBy)||"createdAt"),s.append("sortOrder",(null==t?void 0:t.sortOrder)||"desc"),(null==t?void 0:t.fromDate)&&s.append("fromDate",t.fromDate),(null==t?void 0:t.toDate)&&s.append("toDate",t.toDate);const o=await fetch(`${i}/api/submissions/public?${s.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),c=await o.json();if(!o.ok){const e=c.message||c.error||`HTTP ${o.status}`;return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}if(c.success)return a(e=>({...e,loading:!1,error:null,data:c.data||[],pagination:c.pagination||{page:1,limit:10,total:0,pages:0}})),{success:!0,data:c.data||[],pagination:c.pagination||{page:1,limit:10,total:0,pages:0}};{const e=c.message||c.error||"Failed to fetch submissions";return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}}catch(t){const e=t instanceof Error?t.message:"Unknown error occurred";return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}},[r]),c=e.useCallback(()=>{a({loading:!1,error:null,data:null,pagination:null})},[]);return e.useEffect(()=>{const e=n.current;e&&void 0===e.page&&void 0===e.limit||o()},[o]),{...s,fetchSubmissions:o,reset:c}},exports.useScraping=function(){const{widgetId:t}=u(),[r,n]=e.useState({loading:!1,error:null,success:!1});return{...r,scrapeWebsite:e.useCallback(async e=>{n({loading:!0,error:null,success:!1});try{const r={url:e.url,format:e.format||"markdown",options:e.options||{},widgetId:t},s=await fetch(`${i}/api/execute/scraping`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(r)}),a=await s.json();if(!s.ok){const e=a.message||a.error||`HTTP ${s.status}`;return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(a.success)return n({loading:!1,error:null,success:!0}),{success:!0,message:"Website scraped successfully",data:a.data,metadata:a.metadata};{const e=a.message||a.error||"Scraping failed";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(r){const e=r instanceof Error?r.message:"Unknown error occurred";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t]),reset:e.useCallback(()=>{n({loading:!1,error:null,success:!1})},[])}},exports.useVote=function(t){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({loading:!1,error:null,success:!1});return{...s,vote:e.useCallback(async e=>{var t,s,o,c;a({loading:!0,error:null,success:!1});try{const u={voteFor:e,widgetId:r,collectionName:(null==(t=n.current)?void 0:t.collectionName)||"votes"},l=await fetch(`${i}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(u)}),d=await l.json();if(!l.ok){const e=d.message||d.error||`HTTP ${l.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(d.success)return a({loading:!1,error:null,success:!0}),{id:(null==(s=d.data)?void 0:s.id)||(null==(o=d.data)?void 0:o._id),success:!0,message:(null==(c=d.data)?void 0:c.message)||"Vote submitted successfully"};{const e=d.message||d.error||"Vote submission failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(u){const e=u instanceof Error?u.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useVoteAggregations=function(t){const{widgetId:r}=u(),n=e.useRef(t);n.current=t;const[s,a]=e.useState({data:null,loading:!1,error:null}),o=e.useCallback(async()=>{var e;if(!r)return a({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};a(e=>({...e,loading:!0,error:null}));try{const t=(null==(e=n.current)?void 0:e.collectionName)||"votes",s=new URL(`${i}/api/votes/aggregations`);s.searchParams.append("widgetId",r),s.searchParams.append("collectionName",t);const o=await fetch(s.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),c=await o.json();if(!o.ok){const e=c.message||c.error||`HTTP ${o.status}`;return a({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return a({data:c.data,loading:!1,error:null}),c}catch(t){const e=t instanceof Error?t.message:"Unknown error occurred";return a({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}},[r]),c=e.useCallback(()=>o(),[o]),l=e.useCallback(()=>{a({data:null,loading:!1,error:null})},[]);return e.useEffect(()=>{const e=n.current;!1!==(null==e?void 0:e.autoFetch)&&r&&o()},[o,r]),e.useEffect(()=>{const e=n.current;if((null==e?void 0:e.refetchInterval)&&e.refetchInterval>0&&r){const t=setInterval(()=>{o()},e.refetchInterval);return()=>clearInterval(t)}},[o,r]),{...s,fetch:o,refetch:c,reset:l}};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import require$$0, { useState, useCallback, useEffect, useMemo,
|
|
1
|
+
import require$$0, { useRef, useState, useCallback, useEffect, useMemo, createContext, useContext } from "react";
|
|
2
2
|
import { s as storage } from "./storage-B4eeCFyo.js";
|
|
3
3
|
var jsxRuntime = { exports: {} };
|
|
4
4
|
var reactJsxRuntime_production_min = {};
|
|
@@ -934,6 +934,8 @@ function useEmbeddableConfig() {
|
|
|
934
934
|
}
|
|
935
935
|
function useAI(options) {
|
|
936
936
|
const { widgetId } = useEmbeddableConfig();
|
|
937
|
+
const optionsRef = useRef(options);
|
|
938
|
+
optionsRef.current = options;
|
|
937
939
|
const [state, setState] = useState({
|
|
938
940
|
loading: false,
|
|
939
941
|
error: null,
|
|
@@ -947,12 +949,12 @@ function useAI(options) {
|
|
|
947
949
|
const requestData = {
|
|
948
950
|
widgetId,
|
|
949
951
|
capabilityId: "aiCall",
|
|
950
|
-
integrationKey:
|
|
952
|
+
integrationKey: optionsRef.current.platform,
|
|
951
953
|
prompt,
|
|
952
954
|
history: history || [],
|
|
953
|
-
inputs:
|
|
955
|
+
inputs: optionsRef.current.inputs || {}
|
|
954
956
|
};
|
|
955
|
-
if (
|
|
957
|
+
if (optionsRef.current.platform !== "embeddable-ai") {
|
|
956
958
|
delete requestData.inputs.systemPrompt;
|
|
957
959
|
delete requestData.inputs.maxTokens;
|
|
958
960
|
}
|
|
@@ -999,7 +1001,8 @@ function useAI(options) {
|
|
|
999
1001
|
};
|
|
1000
1002
|
}
|
|
1001
1003
|
},
|
|
1002
|
-
[
|
|
1004
|
+
[widgetId]
|
|
1005
|
+
// Only depend on widgetId
|
|
1003
1006
|
);
|
|
1004
1007
|
const reset = useCallback(() => {
|
|
1005
1008
|
setState({ loading: false, error: null, success: false });
|
|
@@ -1012,6 +1015,8 @@ function useAI(options) {
|
|
|
1012
1015
|
}
|
|
1013
1016
|
function useDataIntegration(options = {}) {
|
|
1014
1017
|
const { widgetId } = useEmbeddableConfig();
|
|
1018
|
+
const optionsRef = useRef(options);
|
|
1019
|
+
optionsRef.current = options;
|
|
1015
1020
|
const [state, setState] = useState({
|
|
1016
1021
|
loading: false,
|
|
1017
1022
|
error: null,
|
|
@@ -1022,8 +1027,8 @@ function useDataIntegration(options = {}) {
|
|
|
1022
1027
|
try {
|
|
1023
1028
|
const requestData = {
|
|
1024
1029
|
widgetId,
|
|
1025
|
-
capabilityId:
|
|
1026
|
-
integrationKey:
|
|
1030
|
+
capabilityId: optionsRef.current.capabilityId || "fetchData",
|
|
1031
|
+
integrationKey: optionsRef.current.integrationKey || "sheets"
|
|
1027
1032
|
};
|
|
1028
1033
|
const response = await fetch(`${EVENTS_BASE_URL}/api/execute/data`, {
|
|
1029
1034
|
method: "POST",
|
|
@@ -1067,7 +1072,7 @@ function useDataIntegration(options = {}) {
|
|
|
1067
1072
|
message: errorMessage
|
|
1068
1073
|
};
|
|
1069
1074
|
}
|
|
1070
|
-
}, [
|
|
1075
|
+
}, [widgetId]);
|
|
1071
1076
|
const reset = useCallback(() => {
|
|
1072
1077
|
setState({ loading: false, error: null, success: false });
|
|
1073
1078
|
}, []);
|
|
@@ -1374,6 +1379,8 @@ const useEventTracking = () => {
|
|
|
1374
1379
|
};
|
|
1375
1380
|
function useFormSubmission(options) {
|
|
1376
1381
|
const { widgetId } = useEmbeddableConfig();
|
|
1382
|
+
const optionsRef = useRef(options);
|
|
1383
|
+
optionsRef.current = options;
|
|
1377
1384
|
const [state, setState] = useState({
|
|
1378
1385
|
loading: false,
|
|
1379
1386
|
error: null,
|
|
@@ -1381,11 +1388,11 @@ function useFormSubmission(options) {
|
|
|
1381
1388
|
});
|
|
1382
1389
|
const submit = useCallback(
|
|
1383
1390
|
async (payload) => {
|
|
1384
|
-
var _a, _b, _c;
|
|
1391
|
+
var _a, _b, _c, _d, _e;
|
|
1385
1392
|
setState({ loading: true, error: null, success: false });
|
|
1386
1393
|
try {
|
|
1387
|
-
if (
|
|
1388
|
-
const validationError =
|
|
1394
|
+
if ((_a = optionsRef.current) == null ? void 0 : _a.validatePayload) {
|
|
1395
|
+
const validationError = optionsRef.current.validatePayload(payload);
|
|
1389
1396
|
if (validationError) {
|
|
1390
1397
|
setState({ loading: false, error: validationError, success: false });
|
|
1391
1398
|
return {
|
|
@@ -1397,7 +1404,7 @@ function useFormSubmission(options) {
|
|
|
1397
1404
|
const submission = {
|
|
1398
1405
|
payload,
|
|
1399
1406
|
widgetId,
|
|
1400
|
-
collectionName: (
|
|
1407
|
+
collectionName: ((_b = optionsRef.current) == null ? void 0 : _b.collectionName) || "submissions"
|
|
1401
1408
|
};
|
|
1402
1409
|
const response = await fetch(`${EVENTS_BASE_URL}/api/submissions`, {
|
|
1403
1410
|
method: "POST",
|
|
@@ -1420,9 +1427,9 @@ function useFormSubmission(options) {
|
|
|
1420
1427
|
if (responseData.success) {
|
|
1421
1428
|
setState({ loading: false, error: null, success: true });
|
|
1422
1429
|
return {
|
|
1423
|
-
id: ((
|
|
1430
|
+
id: ((_c = responseData.data) == null ? void 0 : _c.id) || ((_d = responseData.data) == null ? void 0 : _d._id),
|
|
1424
1431
|
success: true,
|
|
1425
|
-
message: ((
|
|
1432
|
+
message: ((_e = responseData.data) == null ? void 0 : _e.message) || "Submission successful"
|
|
1426
1433
|
};
|
|
1427
1434
|
} else {
|
|
1428
1435
|
const errorMessage = responseData.message || responseData.error || "Submission failed";
|
|
@@ -1441,7 +1448,8 @@ function useFormSubmission(options) {
|
|
|
1441
1448
|
};
|
|
1442
1449
|
}
|
|
1443
1450
|
},
|
|
1444
|
-
[
|
|
1451
|
+
[widgetId]
|
|
1452
|
+
// Only depend on widgetId
|
|
1445
1453
|
);
|
|
1446
1454
|
const reset = useCallback(() => {
|
|
1447
1455
|
setState({ loading: false, error: null, success: false });
|
|
@@ -1505,6 +1513,8 @@ function useLocalStorage(key, initialValue, options = {}) {
|
|
|
1505
1513
|
}
|
|
1506
1514
|
function usePayment(options = {}) {
|
|
1507
1515
|
const { widgetId } = useEmbeddableConfig();
|
|
1516
|
+
const optionsRef = useRef(options);
|
|
1517
|
+
optionsRef.current = options;
|
|
1508
1518
|
const [state, setState] = useState({
|
|
1509
1519
|
loading: false,
|
|
1510
1520
|
error: null,
|
|
@@ -1520,7 +1530,7 @@ function usePayment(options = {}) {
|
|
|
1520
1530
|
}, []);
|
|
1521
1531
|
const pollSessionStatus = useCallback(
|
|
1522
1532
|
async (sessionId) => {
|
|
1523
|
-
var _a, _b;
|
|
1533
|
+
var _a, _b, _c, _d;
|
|
1524
1534
|
try {
|
|
1525
1535
|
const response = await fetch(
|
|
1526
1536
|
`${EVENTS_BASE_URL}/api/execute/payments/session/${sessionId}?widgetId=${widgetId}`,
|
|
@@ -1545,21 +1555,22 @@ function usePayment(options = {}) {
|
|
|
1545
1555
|
pollingIntervalRef.current = null;
|
|
1546
1556
|
}
|
|
1547
1557
|
setState({ loading: false, error: null, success: true });
|
|
1548
|
-
(_a =
|
|
1558
|
+
(_b = (_a = optionsRef.current).onSuccess) == null ? void 0 : _b.call(_a, responseData.session);
|
|
1549
1559
|
} else if (status === "expired") {
|
|
1550
1560
|
if (pollingIntervalRef.current) {
|
|
1551
1561
|
window.clearInterval(pollingIntervalRef.current);
|
|
1552
1562
|
pollingIntervalRef.current = null;
|
|
1553
1563
|
}
|
|
1554
1564
|
setState({ loading: false, error: "Payment session expired", success: false });
|
|
1555
|
-
(
|
|
1565
|
+
(_d = (_c = optionsRef.current).onFailure) == null ? void 0 : _d.call(_c, responseData.session);
|
|
1556
1566
|
}
|
|
1557
1567
|
}
|
|
1558
1568
|
} catch (error) {
|
|
1559
1569
|
console.error("Error polling session status:", error);
|
|
1560
1570
|
}
|
|
1561
1571
|
},
|
|
1562
|
-
[widgetId
|
|
1572
|
+
[widgetId]
|
|
1573
|
+
// Only depend on widgetId
|
|
1563
1574
|
);
|
|
1564
1575
|
const startPolling = useCallback(
|
|
1565
1576
|
(sessionId) => {
|
|
@@ -1580,8 +1591,8 @@ function usePayment(options = {}) {
|
|
|
1580
1591
|
try {
|
|
1581
1592
|
const requestData = {
|
|
1582
1593
|
widgetId,
|
|
1583
|
-
capabilityId:
|
|
1584
|
-
integrationKey:
|
|
1594
|
+
capabilityId: optionsRef.current.capabilityId || "getCheckout",
|
|
1595
|
+
integrationKey: optionsRef.current.integrationKey || "stripe",
|
|
1585
1596
|
inputs
|
|
1586
1597
|
};
|
|
1587
1598
|
const response = await fetch(`${EVENTS_BASE_URL}/api/execute/payments`, {
|
|
@@ -1630,7 +1641,8 @@ function usePayment(options = {}) {
|
|
|
1630
1641
|
};
|
|
1631
1642
|
}
|
|
1632
1643
|
},
|
|
1633
|
-
[
|
|
1644
|
+
[widgetId, startPolling]
|
|
1645
|
+
// Remove options dependencies
|
|
1634
1646
|
);
|
|
1635
1647
|
const reset = useCallback(() => {
|
|
1636
1648
|
if (pollingIntervalRef.current) {
|
|
@@ -1647,6 +1659,8 @@ function usePayment(options = {}) {
|
|
|
1647
1659
|
}
|
|
1648
1660
|
function usePublicSubmissions(options) {
|
|
1649
1661
|
const { widgetId } = useEmbeddableConfig();
|
|
1662
|
+
const optionsRef = useRef(options);
|
|
1663
|
+
optionsRef.current = options;
|
|
1650
1664
|
const [state, setState] = useState({
|
|
1651
1665
|
loading: false,
|
|
1652
1666
|
error: null,
|
|
@@ -1657,7 +1671,7 @@ function usePublicSubmissions(options) {
|
|
|
1657
1671
|
async (customOptions) => {
|
|
1658
1672
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1659
1673
|
try {
|
|
1660
|
-
const finalOptions = { ...
|
|
1674
|
+
const finalOptions = { ...optionsRef.current, ...customOptions };
|
|
1661
1675
|
const queryParams = new URLSearchParams();
|
|
1662
1676
|
queryParams.append("widgetId", widgetId);
|
|
1663
1677
|
if (finalOptions == null ? void 0 : finalOptions.collectionName) {
|
|
@@ -1754,7 +1768,8 @@ function usePublicSubmissions(options) {
|
|
|
1754
1768
|
};
|
|
1755
1769
|
}
|
|
1756
1770
|
},
|
|
1757
|
-
[
|
|
1771
|
+
[widgetId]
|
|
1772
|
+
// Only depend on widgetId, not options
|
|
1758
1773
|
);
|
|
1759
1774
|
const reset = useCallback(() => {
|
|
1760
1775
|
setState({
|
|
@@ -1765,18 +1780,92 @@ function usePublicSubmissions(options) {
|
|
|
1765
1780
|
});
|
|
1766
1781
|
}, []);
|
|
1767
1782
|
useEffect(() => {
|
|
1768
|
-
|
|
1783
|
+
const currentOptions = optionsRef.current;
|
|
1784
|
+
if (!currentOptions || currentOptions.page !== void 0 || currentOptions.limit !== void 0) {
|
|
1769
1785
|
fetchSubmissions();
|
|
1770
1786
|
}
|
|
1771
|
-
}, [fetchSubmissions
|
|
1787
|
+
}, [fetchSubmissions]);
|
|
1772
1788
|
return {
|
|
1773
1789
|
...state,
|
|
1774
1790
|
fetchSubmissions,
|
|
1775
1791
|
reset
|
|
1776
1792
|
};
|
|
1777
1793
|
}
|
|
1794
|
+
function useScraping() {
|
|
1795
|
+
const { widgetId } = useEmbeddableConfig();
|
|
1796
|
+
const [state, setState] = useState({
|
|
1797
|
+
loading: false,
|
|
1798
|
+
error: null,
|
|
1799
|
+
success: false
|
|
1800
|
+
});
|
|
1801
|
+
const scrapeWebsite = useCallback(
|
|
1802
|
+
async (request) => {
|
|
1803
|
+
setState({ loading: true, error: null, success: false });
|
|
1804
|
+
try {
|
|
1805
|
+
const requestData = {
|
|
1806
|
+
url: request.url,
|
|
1807
|
+
format: request.format || "markdown",
|
|
1808
|
+
options: request.options || {},
|
|
1809
|
+
widgetId
|
|
1810
|
+
};
|
|
1811
|
+
const response = await fetch(`${EVENTS_BASE_URL}/api/execute/scraping`, {
|
|
1812
|
+
method: "POST",
|
|
1813
|
+
headers: {
|
|
1814
|
+
"Content-Type": "application/json"
|
|
1815
|
+
},
|
|
1816
|
+
// Explicitly set credentials to 'omit' for CORS support
|
|
1817
|
+
credentials: "omit",
|
|
1818
|
+
body: JSON.stringify(requestData)
|
|
1819
|
+
});
|
|
1820
|
+
const responseData = await response.json();
|
|
1821
|
+
if (!response.ok) {
|
|
1822
|
+
const errorMessage = responseData.message || responseData.error || `HTTP ${response.status}`;
|
|
1823
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1824
|
+
return {
|
|
1825
|
+
success: false,
|
|
1826
|
+
message: errorMessage
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
if (responseData.success) {
|
|
1830
|
+
setState({ loading: false, error: null, success: true });
|
|
1831
|
+
return {
|
|
1832
|
+
success: true,
|
|
1833
|
+
message: "Website scraped successfully",
|
|
1834
|
+
data: responseData.data,
|
|
1835
|
+
metadata: responseData.metadata
|
|
1836
|
+
};
|
|
1837
|
+
} else {
|
|
1838
|
+
const errorMessage = responseData.message || responseData.error || "Scraping failed";
|
|
1839
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1840
|
+
return {
|
|
1841
|
+
success: false,
|
|
1842
|
+
message: errorMessage
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
} catch (error) {
|
|
1846
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1847
|
+
setState({ loading: false, error: errorMessage, success: false });
|
|
1848
|
+
return {
|
|
1849
|
+
success: false,
|
|
1850
|
+
message: errorMessage
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
},
|
|
1854
|
+
[widgetId]
|
|
1855
|
+
);
|
|
1856
|
+
const reset = useCallback(() => {
|
|
1857
|
+
setState({ loading: false, error: null, success: false });
|
|
1858
|
+
}, []);
|
|
1859
|
+
return {
|
|
1860
|
+
...state,
|
|
1861
|
+
scrapeWebsite,
|
|
1862
|
+
reset
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1778
1865
|
function useVote(options) {
|
|
1779
1866
|
const { widgetId } = useEmbeddableConfig();
|
|
1867
|
+
const optionsRef = useRef(options);
|
|
1868
|
+
optionsRef.current = options;
|
|
1780
1869
|
const [state, setState] = useState({
|
|
1781
1870
|
loading: false,
|
|
1782
1871
|
error: null,
|
|
@@ -1784,13 +1873,13 @@ function useVote(options) {
|
|
|
1784
1873
|
});
|
|
1785
1874
|
const vote = useCallback(
|
|
1786
1875
|
async (voteFor) => {
|
|
1787
|
-
var _a, _b, _c;
|
|
1876
|
+
var _a, _b, _c, _d;
|
|
1788
1877
|
setState({ loading: true, error: null, success: false });
|
|
1789
1878
|
try {
|
|
1790
1879
|
const voteData = {
|
|
1791
1880
|
voteFor,
|
|
1792
1881
|
widgetId,
|
|
1793
|
-
collectionName: (
|
|
1882
|
+
collectionName: ((_a = optionsRef.current) == null ? void 0 : _a.collectionName) || "votes"
|
|
1794
1883
|
};
|
|
1795
1884
|
const response = await fetch(`${EVENTS_BASE_URL}/api/votes`, {
|
|
1796
1885
|
method: "POST",
|
|
@@ -1813,9 +1902,9 @@ function useVote(options) {
|
|
|
1813
1902
|
if (responseData.success) {
|
|
1814
1903
|
setState({ loading: false, error: null, success: true });
|
|
1815
1904
|
return {
|
|
1816
|
-
id: ((
|
|
1905
|
+
id: ((_b = responseData.data) == null ? void 0 : _b.id) || ((_c = responseData.data) == null ? void 0 : _c._id),
|
|
1817
1906
|
success: true,
|
|
1818
|
-
message: ((
|
|
1907
|
+
message: ((_d = responseData.data) == null ? void 0 : _d.message) || "Vote submitted successfully"
|
|
1819
1908
|
};
|
|
1820
1909
|
} else {
|
|
1821
1910
|
const errorMessage = responseData.message || responseData.error || "Vote submission failed";
|
|
@@ -1834,7 +1923,8 @@ function useVote(options) {
|
|
|
1834
1923
|
};
|
|
1835
1924
|
}
|
|
1836
1925
|
},
|
|
1837
|
-
[
|
|
1926
|
+
[widgetId]
|
|
1927
|
+
// Only depend on widgetId
|
|
1838
1928
|
);
|
|
1839
1929
|
const reset = useCallback(() => {
|
|
1840
1930
|
setState({ loading: false, error: null, success: false });
|
|
@@ -1847,12 +1937,15 @@ function useVote(options) {
|
|
|
1847
1937
|
}
|
|
1848
1938
|
function useVoteAggregations(options) {
|
|
1849
1939
|
const { widgetId } = useEmbeddableConfig();
|
|
1940
|
+
const optionsRef = useRef(options);
|
|
1941
|
+
optionsRef.current = options;
|
|
1850
1942
|
const [state, setState] = useState({
|
|
1851
1943
|
data: null,
|
|
1852
1944
|
loading: false,
|
|
1853
1945
|
error: null
|
|
1854
1946
|
});
|
|
1855
1947
|
const fetchAggregations = useCallback(async () => {
|
|
1948
|
+
var _a;
|
|
1856
1949
|
if (!widgetId) {
|
|
1857
1950
|
setState({ data: null, loading: false, error: "Widget ID is required" });
|
|
1858
1951
|
return {
|
|
@@ -1862,7 +1955,7 @@ function useVoteAggregations(options) {
|
|
|
1862
1955
|
}
|
|
1863
1956
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
1864
1957
|
try {
|
|
1865
|
-
const collectionName = (
|
|
1958
|
+
const collectionName = ((_a = optionsRef.current) == null ? void 0 : _a.collectionName) || "votes";
|
|
1866
1959
|
const url = new URL(`${EVENTS_BASE_URL}/api/votes/aggregations`);
|
|
1867
1960
|
url.searchParams.append("widgetId", widgetId);
|
|
1868
1961
|
url.searchParams.append("collectionName", collectionName);
|
|
@@ -1893,7 +1986,7 @@ function useVoteAggregations(options) {
|
|
|
1893
1986
|
data: { results: [], summary: { totalVotes: 0, totalOptions: 0, groupBy: "" } }
|
|
1894
1987
|
};
|
|
1895
1988
|
}
|
|
1896
|
-
}, [widgetId
|
|
1989
|
+
}, [widgetId]);
|
|
1897
1990
|
const refetch = useCallback(() => {
|
|
1898
1991
|
return fetchAggregations();
|
|
1899
1992
|
}, [fetchAggregations]);
|
|
@@ -1901,18 +1994,20 @@ function useVoteAggregations(options) {
|
|
|
1901
1994
|
setState({ data: null, loading: false, error: null });
|
|
1902
1995
|
}, []);
|
|
1903
1996
|
useEffect(() => {
|
|
1904
|
-
|
|
1997
|
+
const currentOptions = optionsRef.current;
|
|
1998
|
+
if ((currentOptions == null ? void 0 : currentOptions.autoFetch) !== false && widgetId) {
|
|
1905
1999
|
fetchAggregations();
|
|
1906
2000
|
}
|
|
1907
|
-
}, [fetchAggregations,
|
|
2001
|
+
}, [fetchAggregations, widgetId]);
|
|
1908
2002
|
useEffect(() => {
|
|
1909
|
-
|
|
2003
|
+
const currentOptions = optionsRef.current;
|
|
2004
|
+
if ((currentOptions == null ? void 0 : currentOptions.refetchInterval) && currentOptions.refetchInterval > 0 && widgetId) {
|
|
1910
2005
|
const interval = setInterval(() => {
|
|
1911
2006
|
fetchAggregations();
|
|
1912
|
-
},
|
|
2007
|
+
}, currentOptions.refetchInterval);
|
|
1913
2008
|
return () => clearInterval(interval);
|
|
1914
2009
|
}
|
|
1915
|
-
}, [fetchAggregations,
|
|
2010
|
+
}, [fetchAggregations, widgetId]);
|
|
1916
2011
|
return {
|
|
1917
2012
|
...state,
|
|
1918
2013
|
fetch: fetchAggregations,
|
|
@@ -1996,7 +2091,8 @@ export {
|
|
|
1996
2091
|
useLocalStorage as i,
|
|
1997
2092
|
usePayment as j,
|
|
1998
2093
|
usePublicSubmissions as k,
|
|
1999
|
-
|
|
2000
|
-
|
|
2094
|
+
useScraping as l,
|
|
2095
|
+
useVote as m,
|
|
2096
|
+
useVoteAggregations as n,
|
|
2001
2097
|
useEmbeddableContext as u
|
|
2002
2098
|
};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { useFormSubmission } from './useFormSubmission';
|
|
|
9
9
|
export { useLocalStorage } from './useLocalStorage';
|
|
10
10
|
export { usePayment } from './usePayment';
|
|
11
11
|
export { usePublicSubmissions } from './usePublicSubmissions';
|
|
12
|
+
export { useScraping } from './useScraping';
|
|
12
13
|
export { useVote } from './useVote';
|
|
13
14
|
export { useVoteAggregations } from './useVoteAggregations';
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AACA,O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AAC;QAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY;qBAcxB,MAAM,YAAY,KAAK,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,UAAU,CAAC;;aA1DlE,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EAuIjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataIntegration.d.ts","sourceRoot":"","sources":["../../src/hooks/useDataIntegration.ts"],"names":[],"mappings":"AAIA,KAAK,uBAAuB,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAC;AAQxE,UAAU,+BAA+B;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,uBAAuB,CAAC,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,+BAA+B,CAAC;CAC5C;AAED,UAAU,yBAAyB;IACjC,cAAc,CAAC,EAAE,uBAAuB,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,GAAE,yBAA8B;
|
|
1
|
+
{"version":3,"file":"useDataIntegration.d.ts","sourceRoot":"","sources":["../../src/hooks/useDataIntegration.ts"],"names":[],"mappings":"AAIA,KAAK,uBAAuB,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAC;AAQxE,UAAU,+BAA+B;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,uBAAuB,CAAC,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,QAAQ,CAAC,EAAE,+BAA+B,CAAC;CAC5C;AAED,UAAU,yBAAyB;IACjC,cAAc,CAAC,EAAE,uBAAuB,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,GAAE,yBAA8B;qBAazC,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;;aA3ClE,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EA8GjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormSubmission.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormSubmission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAU9F;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"useFormSubmission.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormSubmission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAU9F;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,qBAAqB;s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E,wBAAwB;
|
|
1
|
+
{"version":3,"file":"usePublicSubmissions.d.ts","sourceRoot":"","sources":["../../src/hooks/usePublicSubmissions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAWlB;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,wBAAwB;uCAe5C,wBAAwB,KAAG,OAAO,CAAC,yBAAyB,CAAC;;aA1B7E,OAAO;WACT,MAAM,GAAG,IAAI;UACd,gBAAgB,EAAE,GAAG,IAAI;gBACnB,2BAA2B,GAAG,IAAI;EAyK/C"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type ScrapingFormat = 'html' | 'markdown' | 'screenshot';
|
|
2
|
+
interface ScrapingOptions {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
interface ScrapingData {
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
content?: string;
|
|
9
|
+
screenshotUrl?: string;
|
|
10
|
+
url: string;
|
|
11
|
+
format: ScrapingFormat;
|
|
12
|
+
}
|
|
13
|
+
interface ScrapingResponseMetadata {
|
|
14
|
+
executedAt: string;
|
|
15
|
+
url: string;
|
|
16
|
+
format: ScrapingFormat;
|
|
17
|
+
options: ScrapingOptions;
|
|
18
|
+
}
|
|
19
|
+
interface ScrapingResponse {
|
|
20
|
+
success: boolean;
|
|
21
|
+
message?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
data?: ScrapingData;
|
|
24
|
+
metadata?: ScrapingResponseMetadata;
|
|
25
|
+
}
|
|
26
|
+
interface ScrapingRequest {
|
|
27
|
+
url: string;
|
|
28
|
+
format?: ScrapingFormat;
|
|
29
|
+
options?: ScrapingOptions;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* React hook for web scraping with loading, error states
|
|
33
|
+
* @returns Object with scraping function and state management
|
|
34
|
+
*/
|
|
35
|
+
export declare function useScraping(): {
|
|
36
|
+
scrapeWebsite: (request: ScrapingRequest) => Promise<ScrapingResponse>;
|
|
37
|
+
reset: () => void;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: string | null;
|
|
40
|
+
success: boolean;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=useScraping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScraping.d.ts","sourceRoot":"","sources":["../../src/hooks/useScraping.ts"],"names":[],"mappings":"AAIA,KAAK,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC;AAQzD,UAAU,eAAe;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,YAAY;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,UAAU,wBAAwB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,QAAQ,CAAC,EAAE,wBAAwB,CAAC;CACrC;AAED,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,WAAW;6BASP,eAAe,KAAG,OAAO,CAAC,gBAAgB,CAAC;;aApDpD,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EA0HjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVote.d.ts","sourceRoot":"","sources":["../../src/hooks/useVote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAQ,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUhE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"useVote.d.ts","sourceRoot":"","sources":["../../src/hooks/useVote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAQ,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUhE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW;oBAczB,MAAM,KAAG,OAAO,CAAC,YAAY,CAAC;;aAxBvC,OAAO;WACT,MAAM,GAAG,IAAI;aACX,OAAO;EA6FjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVoteAggregations.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoteAggregations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAU7E,UAAU,0BAA0B;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B;
|
|
1
|
+
{"version":3,"file":"useVoteAggregations.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoteAggregations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAU7E,UAAU,0BAA0B;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B;iBAatB,OAAO,CAAC,uBAAuB,CAAC;;;UA7B1E,mBAAmB,GAAG,IAAI;aACvB,OAAO;WACT,MAAM,GAAG,IAAI;EAgHrB"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-CGNt-5fg.cjs");exports.useAI=e.useAI,exports.useDataIntegration=e.useDataIntegration,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableData=e.useEmbeddableData,exports.useEventTracking=e.useEventTracking,exports.useFileUpload=e.useFileUpload,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.usePayment=e.usePayment,exports.usePublicSubmissions=e.usePublicSubmissions,exports.useScraping=e.useScraping,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations;
|
package/dist/hooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a, b, c, d, f, g, e, h, i, j, k, l, m } from "./EmbeddableProvider-
|
|
1
|
+
import { a, b, c, d, f, g, e, h, i, j, k, l, m, n } from "./EmbeddableProvider-v_5vMWDf.js";
|
|
2
2
|
export {
|
|
3
3
|
a as useAI,
|
|
4
4
|
b as useDataIntegration,
|
|
@@ -11,6 +11,7 @@ export {
|
|
|
11
11
|
i as useLocalStorage,
|
|
12
12
|
j as usePayment,
|
|
13
13
|
k as usePublicSubmissions,
|
|
14
|
-
l as
|
|
15
|
-
m as
|
|
14
|
+
l as useScraping,
|
|
15
|
+
m as useVote,
|
|
16
|
+
n as useVoteAggregations
|
|
16
17
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./EmbeddableProvider-CGNt-5fg.cjs"),s=require("./utils.cjs"),o=require("./storage-BtXo3gya.cjs");exports.EmbeddableProvider=e.EmbeddableProvider,exports.useAI=e.useAI,exports.useDataIntegration=e.useDataIntegration,exports.useDebounce=e.useDebounce,exports.useEmbeddableConfig=e.useEmbeddableConfig,exports.useEmbeddableContext=e.useEmbeddableContext,exports.useEmbeddableData=e.useEmbeddableData,exports.useEventTracking=e.useEventTracking,exports.useFileUpload=e.useFileUpload,exports.useFormSubmission=e.useFormSubmission,exports.useLocalStorage=e.useLocalStorage,exports.usePayment=e.usePayment,exports.usePublicSubmissions=e.usePublicSubmissions,exports.useScraping=e.useScraping,exports.useVote=e.useVote,exports.useVoteAggregations=e.useVoteAggregations,exports.createApiClient=s.createApiClient,exports.debounce=s.debounce,exports.storage=o.storage;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E, a, b, c, d, u, f, g, e, h, i, j, k, l, m } from "./EmbeddableProvider-
|
|
1
|
+
import { E, a, b, c, d, u, f, g, e, h, i, j, k, l, m, n } from "./EmbeddableProvider-v_5vMWDf.js";
|
|
2
2
|
import { createApiClient, debounce } from "./utils.js";
|
|
3
3
|
import { s } from "./storage-B4eeCFyo.js";
|
|
4
4
|
export {
|
|
@@ -18,6 +18,7 @@ export {
|
|
|
18
18
|
i as useLocalStorage,
|
|
19
19
|
j as usePayment,
|
|
20
20
|
k as usePublicSubmissions,
|
|
21
|
-
l as
|
|
22
|
-
m as
|
|
21
|
+
l as useScraping,
|
|
22
|
+
m as useVote,
|
|
23
|
+
n as useVoteAggregations
|
|
23
24
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react"),t=require("./storage-BtXo3gya.cjs");var r,n={exports:{}},a={};var s,o={};
|
|
2
|
-
/**
|
|
3
|
-
* @license React
|
|
4
|
-
* react-jsx-runtime.development.js
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
|
-
*
|
|
8
|
-
* This source code is licensed under the MIT license found in the
|
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/"production"===process.env.NODE_ENV?n.exports=function(){if(r)return a;r=1;var t=e,n=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,r){var a,s={},l=null,u=null;for(a in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)o.call(t,a)&&!i.hasOwnProperty(a)&&(s[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===s[a]&&(s[a]=t[a]);return{$$typeof:n,type:e,key:l,ref:u,props:s,_owner:c.current}}return a.Fragment=s,a.jsx=l,a.jsxs=l,a}():n.exports=(s||(s=1,"production"!==process.env.NODE_ENV&&function(){var t,r=e,n=Symbol.for("react.element"),a=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),c=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),u=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),g=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),y=Symbol.for("react.offscreen"),v=Symbol.iterator,b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var a=r.map(function(e){return String(e)});a.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,a)}("error",e,r)}function w(e){return e.displayName||"Context"}function k(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case s:return"Fragment";case a:return"Portal";case i:return"Profiler";case c:return"StrictMode";case p:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return w(e)+".Consumer";case l:return w(e._context)+".Provider";case d:return function(e,t,r){var n=e.displayName;if(n)return n;var a=t.displayName||t.name||"";return""!==a?r+"("+a+")":r}(e,e.render,"ForwardRef");case g:var t=e.displayName||null;return null!==t?t:k(e.type)||"Memo";case m:var r=e,n=r._payload,o=r._init;try{return k(o(n))}catch(y){return null}}return null}t=Symbol.for("react.module.reference");var _,S,E,C,T,j,O,I=Object.assign,P=0;function x(){}x.__reactDisabledLog=!0;var $,R=b.ReactCurrentDispatcher;function N(e,t,r){if(void 0===$)try{throw Error()}catch(a){var n=a.stack.trim().match(/\n( *(at )?)/);$=n&&n[1]||""}return"\n"+$+e}var D,F=!1,L="function"==typeof WeakMap?WeakMap:Map;function U(e,t){if(!e||F)return"";var r,n=D.get(e);if(void 0!==n)return n;F=!0;var a,s=Error.prepareStackTrace;Error.prepareStackTrace=void 0,a=R.current,R.current=null,function(){if(0===P){_=console.log,S=console.info,E=console.warn,C=console.error,T=console.group,j=console.groupCollapsed,O=console.groupEnd;var e={configurable:!0,enumerable:!0,value:x,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();try{if(t){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){r=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){r=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){r=g}e()}}catch(m){if(m&&r&&"string"==typeof m.stack){for(var c=m.stack.split("\n"),i=r.stack.split("\n"),l=c.length-1,u=i.length-1;l>=1&&u>=0&&c[l]!==i[u];)u--;for(;l>=1&&u>=0;l--,u--)if(c[l]!==i[u]){if(1!==l||1!==u)do{if(l--,--u<0||c[l]!==i[u]){var d="\n"+c[l].replace(" at new "," at ");return e.displayName&&d.includes("<anonymous>")&&(d=d.replace("<anonymous>",e.displayName)),"function"==typeof e&&D.set(e,d),d}}while(l>=1&&u>=0);break}}}finally{F=!1,R.current=a,function(){if(0===--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:I({},e,{value:_}),info:I({},e,{value:S}),warn:I({},e,{value:E}),error:I({},e,{value:C}),group:I({},e,{value:T}),groupCollapsed:I({},e,{value:j}),groupEnd:I({},e,{value:O})})}P<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=s}var p=e?e.displayName||e.name:"",f=p?N(p):"";return"function"==typeof e&&D.set(e,f),f}function A(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case p:return N("Suspense");case f:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return U(e.render,!1);case g:return A(e.type,t,r);case m:var a=e,s=a._payload,o=a._init;try{return A(o(s),t,r)}catch(c){}}return""}D=new L;var V=Object.prototype.hasOwnProperty,K={},W=b.ReactDebugCurrentFrame;function J(e){if(e){var t=e._owner,r=A(e.type,e._source,t?t.type:null);W.setExtraStackFrame(r)}else W.setExtraStackFrame(null)}var z=Array.isArray;function B(e){return z(e)}function H(e){return""+e}function M(e){if(function(e){try{return H(e),!1}catch(t){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),H(e)}var Y,q,G=b.ReactCurrentOwner,X={key:!0,ref:!0,__self:!0,__source:!0};function Q(e,t,r,a,s){var o,c={},i=null,l=null;for(o in void 0!==r&&(M(r),i=""+r),function(e){if(V.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(M(t.key),i=""+t.key),function(e){if(V.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(l=t.ref,function(e){"string"==typeof e.ref&&G.current}(t)),t)V.call(t,o)&&!X.hasOwnProperty(o)&&(c[o]=t[o]);if(e&&e.defaultProps){var u=e.defaultProps;for(o in u)void 0===c[o]&&(c[o]=u[o])}if(i||l){var d="function"==typeof e?e.displayName||e.name||"Unknown":e;i&&function(e,t){var r=function(){Y||(Y=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(c,d),l&&function(e,t){var r=function(){q||(q=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(c,d)}return function(e,t,r,a,s,o,c){var i={$$typeof:n,type:e,key:t,ref:r,props:c,_owner:o,_store:{}};return Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i}(e,i,l,s,a,G.current,c)}var Z,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=A(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function ae(){if(ee.current){var e=k(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Z=!1;var se={};function oe(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=ae();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!se[r]){se[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),re(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),re(null)}}}function ce(e,t){if("object"==typeof e)if(B(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&oe(n,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var a=function(e){if(null===e||"object"!=typeof e)return null;var t=v&&e[v]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof a&&a!==e.entries)for(var s,o=a.call(e);!(s=o.next()).done;)ne(s.value)&&oe(s.value,t)}}function ie(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==d&&r.$$typeof!==g)return;t=r.propTypes}if(t){var n=k(r);!function(e,t,r,n,a){var s=Function.call.bind(V);for(var o in e)if(s(e,o)){var c=void 0;try{if("function"!=typeof e[o]){var i=Error((n||"React class")+": "+r+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw i.name="Invariant Violation",i}c=e[o](t,o,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(l){c=l}!c||c instanceof Error||(J(a),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",r,o,typeof c),J(null)),c instanceof Error&&!(c.message in K)&&(K[c.message]=!0,J(a),h("Failed %s type: %s",r,c.message),J(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||Z||(Z=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",k(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var le={};function ue(e,r,a,o,v,b){var w=function(e){return"string"==typeof e||"function"==typeof e||e===s||e===i||e===c||e===p||e===f||e===y||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===g||e.$$typeof===l||e.$$typeof===u||e.$$typeof===d||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!w){var _,S="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(S+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),S+=ae(),null===e?_="null":B(e)?_="array":void 0!==e&&e.$$typeof===n?(_="<"+(k(e.type)||"Unknown")+" />",S=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,S)}var E=Q(e,r,a,v,b);if(null==E)return E;if(w){var C=r.children;if(void 0!==C)if(o)if(B(C)){for(var T=0;T<C.length;T++)ce(C[T],e);Object.freeze&&Object.freeze(C)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ce(C,e)}if(V.call(r,"key")){var j=k(e),O=Object.keys(r).filter(function(e){return"key"!==e}),I=O.length>0?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}";le[j+I]||(h('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',I,j,O.length>0?"{"+O.join(": ..., ")+": ...}":"{}",j),le[j+I]=!0)}return e===s?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(E):ie(E),E}var de=function(e,t,r){return ue(e,t,r,!1)},pe=function(e,t,r){return ue(e,t,r,!0)};o.Fragment=s,o.jsx=de,o.jsxs=pe}()),o);var c=n.exports;const i="https://events.embeddable.co";function l(){const{config:e}=g();if(!e)throw new Error("No Embeddable configuration found. Make sure to wrap your app with EmbeddableProvider and provide a valid config.");return e}const u=()=>{const{widgetId:t,mode:r}=l(),n=`${i}/api`,[a,s]=e.useState(!1),o=e.useCallback(async e=>{if(!t||"preview"===r)return[];const a=[];try{s(!0);const r=await fetch(`${n}/marketing/track`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify({widgetId:t,capabilityId:"trackEvent",inputs:e})}),o=await r.json();o.success?o.results?o.results.forEach(e=>{a.push({success:e.success,integrationKey:e.integrationKey,data:e.data,error:e.error})}):a.push({success:!0,data:o.data}):a.push({success:!1,error:o.error||"Unknown error"})}catch(o){a.push({success:!1,error:o instanceof Error?o.message:"Network error"})}finally{s(!1)}return a},[t,n,r]),c=e.useCallback(async(e={})=>o({event_name:"page_view",event_category:"engagement",custom_parameters:{page_url:window.location.href,page_title:document.title,referrer:document.referrer,...e}}),[o]),u=e.useCallback(async(e,t={})=>o({event_name:"form_submit",event_category:"conversion",custom_parameters:{form_data:e,...t}}),[o]),d=e.useCallback(async(e,t={})=>{let r={};return r="string"==typeof e?{element_selector:e}:{element_id:e.id,element_class:e.className,element_text:e.textContent||e.innerText,element_tag:e.tagName.toLowerCase()},o({event_name:"button_click",event_category:"interaction",custom_parameters:{...r,...t}})},[o]),p=e.useCallback(async(e,t,r={})=>o({event_name:"conversion",event_category:"conversion",value:t,custom_parameters:{conversion_type:e,currency:r.currency||"USD",...r}}),[o]),f=e.useCallback(async(e,t={})=>o({event_name:"signup",event_category:"conversion",user_data:e,custom_parameters:t}),[o]),g=e.useCallback(async(e,t={})=>o({event_name:"purchase",event_category:"ecommerce",value:e.amount,custom_parameters:{transaction_id:e.id,currency:e.currency||"USD",items:e.items||[],...t}}),[o]),m=e.useCallback(()=>{c()},[c]),y=e.useCallback(()=>{const e=async e=>{try{const t=e.target,r=new FormData(t),n=Object.fromEntries(r.entries());await u(n,{form_id:t.id,form_class:t.className,form_action:t.action,form_method:t.method})}catch(t){}};return document.addEventListener("submit",e),()=>{document.removeEventListener("submit",e)}},[u]),v=e.useCallback((e='button, .btn, [role="button"], a, input[type="submit"]')=>{const t=async t=>{const r=t.target.closest(e);if(r)try{await d(r)}catch(n){}};return document.addEventListener("click",t),()=>{document.removeEventListener("click",t)}},[d]);return{isLoading:a,track:o,trackPageView:c,trackFormSubmit:u,trackClick:d,trackConversion:p,trackSignup:f,trackPurchase:g,enableAutoPageView:m,enableAutoFormTracking:y,enableAutoClickTracking:v}};const d={version:"latest",mode:"embeddable",ignoreCache:!1,lazyLoad:!1,loader:!0,widgetId:"",_containerId:"",_shadowRoot:void 0},p=e.createContext({config:{...d},setConfig:()=>{},data:{},setData:()=>{}});function f(){const{trackPageView:t}=u(),{config:r}=g();return e.useEffect(()=>{(null==r?void 0:r.widgetId)&&"preview"!==(null==r?void 0:r.mode)&&t()},[null==r?void 0:r.widgetId,null==r?void 0:r.mode,t]),null}function g(){const t=e.useContext(p);if(!t)throw new Error("useEmbeddableContext must be used within an EmbeddableProvider");return t}exports.EmbeddableProvider=function({config:t,data:r,children:n}){const[a,s]=e.useState(d),[o,i]=e.useState(r||{});return e.useEffect(()=>{const e={...d,...t};s(e)},[t]),e.useEffect(()=>{const e=e=>{("https://embeddable.co"===e.origin||e.origin.includes("localhost"))&&e.data&&"object"==typeof e.data&&"embeddable-update-data"===e.data.type&&i(e.data.data||{})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),c.jsxs(p.Provider,{value:{config:a,setConfig:s,data:o,setData:i},children:[c.jsx(f,{}),n]})},exports.useAI=function(t){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,success:!1});return{...n,callAI:e.useCallback(async(e,n)=>{var s;a({loading:!0,error:null,success:!1});try{const o={widgetId:r,capabilityId:"aiCall",integrationKey:t.platform,prompt:e,history:n||[],inputs:t.inputs||{}};"embeddable-ai"!==t.platform&&(delete o.inputs.systemPrompt,delete o.inputs.maxTokens);const c=await fetch(`${i}/api/execute/ai`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(o)}),l=await c.json();if(!c.ok){const e=l.message||l.error||`HTTP ${c.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return a({loading:!1,error:null,success:!0}),{success:!0,message:(null==(s=l.data)?void 0:s.response)||"AI call completed successfully",data:l.data,metadata:l.metadata};{const e=l.message||l.error||"AI call failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(o){const e=o instanceof Error?o.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t.platform,t.inputs,r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useDataIntegration=function(t={}){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,success:!1});return{...n,fetchData:e.useCallback(async()=>{a({loading:!0,error:null,success:!1});try{const e={widgetId:r,capabilityId:t.capabilityId||"fetchData",integrationKey:t.integrationKey||"sheets"},n=await fetch(`${i}/api/execute/data`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(e)}),s=await n.json();if(!n.ok){const e=s.message||s.error||`HTTP ${n.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(s.success)return a({loading:!1,error:null,success:!0}),{success:!0,message:"Data fetched successfully",data:s.data,metadata:s.metadata};{const e=s.message||s.error||"Data fetch failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";return a({loading:!1,error:t,success:!1}),{success:!1,message:t}}},[t.capabilityId,t.integrationKey,r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useDebounce=function(t,r){const[n,a]=e.useState(t);return e.useEffect(()=>{const e=setTimeout(()=>{a(t)},r);return()=>{clearTimeout(e)}},[t,r]),n},exports.useEmbeddableConfig=l,exports.useEmbeddableContext=g,exports.useEmbeddableData=function(){const{data:e}=g();return{data:e}},exports.useEventTracking=u,exports.useFileUpload=function(){const{widgetId:t}=l(),[r,n]=e.useState({loading:!1,error:null,success:!1});return{...r,uploadFile:e.useCallback(async e=>{n({loading:!0,error:null,success:!1});try{const r=new FormData;r.append("file",e),r.append("widgetId",t);const a=await fetch(`${i}/api/execute/uploads`,{method:"POST",credentials:"omit",body:r}),s=await a.json();if(!a.ok){const e=s.message||s.error||`HTTP ${a.status}`;return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(s.success)return n({loading:!1,error:null,success:!0}),{success:!0,message:s.message||"File uploaded successfully",data:s.data};{const e=s.message||s.error||"File upload failed";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(r){const e=r instanceof Error?r.message:"Unknown error occurred";return n({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t]),reset:e.useCallback(()=>{n({loading:!1,error:null,success:!1})},[])}},exports.useFormSubmission=function(t){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,success:!1});return{...n,submit:e.useCallback(async e=>{var n,s,o;a({loading:!0,error:null,success:!1});try{if(null==t?void 0:t.validatePayload){const r=t.validatePayload(e);if(r)return a({loading:!1,error:r,success:!1}),{success:!1,message:r}}const c={payload:e,widgetId:r,collectionName:(null==t?void 0:t.collectionName)||"submissions"},l=await fetch(`${i}/api/submissions`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(c)}),u=await l.json();if(!l.ok){const e=u.message||u.error||`HTTP ${l.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(u.success)return a({loading:!1,error:null,success:!0}),{id:(null==(n=u.data)?void 0:n.id)||(null==(s=u.data)?void 0:s._id),success:!0,message:(null==(o=u.data)?void 0:o.message)||"Submission successful"};{const e=u.message||u.error||"Submission failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(c){const e=c instanceof Error?c.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t,r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useLocalStorage=function(r,n,a={}){const{widgetId:s}=l(),o=e.useMemo(()=>({...a,prefix:`embd-${s}-${a.prefix||""}`}),[s,a]),[c,i]=e.useState(()=>{const e=t.storage.get(r,o);return null!==e?e:n}),u=e.useCallback(e=>{try{const n=e instanceof Function?e(c):e;i(n),t.storage.set(r,n,o)}catch(n){}},[r,c,o]),d=e.useCallback(()=>{try{i(n),t.storage.remove(r,o)}catch(e){}},[r,n,o]);return e.useEffect(()=>{const e=e=>{const t=o.prefix+r;if(e.key===t&&null!==e.newValue)try{const{deserialize:t=JSON.parse}=o,r=t(e.newValue);i(r)}catch(n){}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[r,o]),[c,u,d]},exports.usePayment=function(t={}){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,success:!1}),s=e.useRef(null);e.useEffect(()=>()=>{s.current&&window.clearInterval(s.current)},[]);const o=e.useCallback(async e=>{var n,o;try{const c=await fetch(`${i}/api/execute/payments/session/${e}?widgetId=${r}`,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),l=await c.json();if(!c.ok)return;if(l.success&&l.session){const{status:e,payment_status:r}=l.session;"paid"===r&&"complete"===e?(s.current&&(window.clearInterval(s.current),s.current=null),a({loading:!1,error:null,success:!0}),null==(n=t.onSuccess)||n.call(t,l.session)):"expired"===e&&(s.current&&(window.clearInterval(s.current),s.current=null),a({loading:!1,error:"Payment session expired",success:!1}),null==(o=t.onFailure)||o.call(t,l.session))}}catch(c){}},[r,t]),c=e.useCallback(e=>{s.current&&window.clearInterval(s.current),s.current=window.setInterval(()=>{o(e)},1e4),o(e)},[o]);return{...n,createCheckout:e.useCallback(async e=>{var n;a({loading:!0,error:null,success:!1});try{const s={widgetId:r,capabilityId:t.capabilityId||"getCheckout",integrationKey:t.integrationKey||"stripe",inputs:e},o=await fetch(`${i}/api/execute/payments`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(s)}),l=await o.json();if(!o.ok){const e=l.message||l.error||`HTTP ${o.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(l.success)return(null==(n=l.data)?void 0:n.sessionId)&&c(l.data.sessionId),a({loading:!1,error:null,success:!1}),{success:!0,message:"Checkout session created successfully",data:l.data,metadata:l.metadata};{const e=l.message||l.error||"Payment checkout failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(s){const e=s instanceof Error?s.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t.capabilityId,t.integrationKey,r,c]),reset:e.useCallback(()=>{s.current&&(window.clearInterval(s.current),s.current=null),a({loading:!1,error:null,success:!1})},[])}},exports.usePublicSubmissions=function(t){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,data:null,pagination:null}),s=e.useCallback(async e=>{a(e=>({...e,loading:!0,error:null}));try{const n={...t,...e},s=new URLSearchParams;s.append("widgetId",r),(null==n?void 0:n.collectionName)&&s.append("collectionName",n.collectionName),s.append("page",String((null==n?void 0:n.page)||1)),s.append("limit",String((null==n?void 0:n.limit)||10)),s.append("sortBy",(null==n?void 0:n.sortBy)||"createdAt"),s.append("sortOrder",(null==n?void 0:n.sortOrder)||"desc"),(null==n?void 0:n.fromDate)&&s.append("fromDate",n.fromDate),(null==n?void 0:n.toDate)&&s.append("toDate",n.toDate);const o=await fetch(`${i}/api/submissions/public?${s.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),c=await o.json();if(!o.ok){const e=c.message||c.error||`HTTP ${o.status}`;return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}if(c.success)return a(e=>({...e,loading:!1,error:null,data:c.data||[],pagination:c.pagination||{page:1,limit:10,total:0,pages:0}})),{success:!0,data:c.data||[],pagination:c.pagination||{page:1,limit:10,total:0,pages:0}};{const e=c.message||c.error||"Failed to fetch submissions";return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}}catch(n){const e=n instanceof Error?n.message:"Unknown error occurred";return a(t=>({...t,loading:!1,error:e})),{success:!1,data:[],pagination:{page:1,limit:10,total:0,pages:0},message:e}}},[t,r]),o=e.useCallback(()=>{a({loading:!1,error:null,data:null,pagination:null})},[]);return e.useEffect(()=>{t&&void 0===t.page&&void 0===t.limit||s()},[s,t]),{...n,fetchSubmissions:s,reset:o}},exports.useVote=function(t){const{widgetId:r}=l(),[n,a]=e.useState({loading:!1,error:null,success:!1});return{...n,vote:e.useCallback(async e=>{var n,s,o;a({loading:!0,error:null,success:!1});try{const c={voteFor:e,widgetId:r,collectionName:(null==t?void 0:t.collectionName)||"votes"},l=await fetch(`${i}/api/votes`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"omit",body:JSON.stringify(c)}),u=await l.json();if(!l.ok){const e=u.message||u.error||`HTTP ${l.status}`;return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}if(u.success)return a({loading:!1,error:null,success:!0}),{id:(null==(n=u.data)?void 0:n.id)||(null==(s=u.data)?void 0:s._id),success:!0,message:(null==(o=u.data)?void 0:o.message)||"Vote submitted successfully"};{const e=u.message||u.error||"Vote submission failed";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}}catch(c){const e=c instanceof Error?c.message:"Unknown error occurred";return a({loading:!1,error:e,success:!1}),{success:!1,message:e}}},[t,r]),reset:e.useCallback(()=>{a({loading:!1,error:null,success:!1})},[])}},exports.useVoteAggregations=function(t){const{widgetId:r}=l(),[n,a]=e.useState({data:null,loading:!1,error:null}),s=e.useCallback(async()=>{if(!r)return a({data:null,loading:!1,error:"Widget ID is required"}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}};a(e=>({...e,loading:!0,error:null}));try{const e=(null==t?void 0:t.collectionName)||"votes",n=new URL(`${i}/api/votes/aggregations`);n.searchParams.append("widgetId",r),n.searchParams.append("collectionName",e);const s=await fetch(n.toString(),{method:"GET",headers:{"Content-Type":"application/json"},credentials:"omit"}),o=await s.json();if(!s.ok){const e=o.message||o.error||`HTTP ${s.status}`;return a({data:null,loading:!1,error:e}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}return a({data:o.data,loading:!1,error:null}),o}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";return a({data:null,loading:!1,error:t}),{success:!1,data:{results:[],summary:{totalVotes:0,totalOptions:0,groupBy:""}}}}},[r,null==t?void 0:t.collectionName]),o=e.useCallback(()=>s(),[s]),c=e.useCallback(()=>{a({data:null,loading:!1,error:null})},[]);return e.useEffect(()=>{!1!==(null==t?void 0:t.autoFetch)&&r&&s()},[s,null==t?void 0:t.autoFetch,r]),e.useEffect(()=>{if((null==t?void 0:t.refetchInterval)&&t.refetchInterval>0&&r){const e=setInterval(()=>{s()},t.refetchInterval);return()=>clearInterval(e)}},[s,null==t?void 0:t.refetchInterval,r]),{...n,fetch:s,refetch:o,reset:c}};
|