PageSourceSearch

https://truemargin.ai/_next/static/chunks/91812.7b58bcfbddebcfa4.js

js truemargin.ai collected 2026-10-05 13:09:05 UTC 17,375 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[91812],{91812:function(e,t,s){s.r(t),s.d(t,{AdIntelligenceSettings:function(){return p}});var a=s(57437),r=s(2265),l=s(85323),n=s(62869),o=s(51817);let i={auto_pull_performance:{label:"Auto-Pull Performance",description:"Sync Meta ad data every 6 hours",riskLevel:"none"},auto_score_creatives:{label:"Auto-Score Creatives",description:"Tag winners/losers using true margin scoring",riskLevel:"none"},auto_kill_losers:{label:"Auto-Kill Losers",description:"Pause ads that hit your loss threshold",riskLevel:"medium"},auto_generate_sniper:{label:"Auto-Generate Sniper",description:"Create sniper sessions from winning creatives",riskLevel:"low"},auto_generate_marksman:{label:"Auto-Generate Marksman",description:"Create marksman sessions when no winners exist",riskLevel:"low"},auto_launch_to_meta:{label:"Auto-Launch to Meta",description:"Push approved creatives live to your ad account",riskLevel:"high"},auto_budget_adjust:{label:"Auto-Budget Adjust",description:"Increase budget on winners, decrease on mid-performers",riskLevel:"high"}},d={killThresholdCpa:null,killThresholdSpend:150,sniperThresholdMargin:25,sniperThresholdConversions:30,sniperThresholdDays:3},c=e=>fetch(e).then(e=>{if(!e.ok)throw Error(e.statusText);return e.json()}),u=[{key:"auto_pull_performance",risk:"none"},{key:"auto_score_creatives",risk:"none"},{key:"auto_kill_losers",risk:"medium"},{key:"auto_generate_sniper",risk:"low"},{key:"auto_generate_marksman",risk:"low"},{key:"auto_launch_to_meta",risk:"high"},{key:"auto_budget_adjust",risk:"high"}],h={auto_pull_performance:"autoPullPerformance",auto_score_creatives:"autoScoreCreatives",auto_kill_losers:"autoKillLosers",auto_generate_sniper:"autoGenerateSniper",auto_generate_marksman:"autoGenerateMarksman",auto_launch_to_meta:"autoLaunchToMeta",auto_budget_adjust:"autoBudgetAdjust"},m={none:{label:"No Risk",bg:"bg-green-100",text:"text-green-800"},low:{label:"Low Risk",bg:"bg-yellow-100",text:"text-yellow-800"},medium:{label:"Medium Risk",bg:"bg-orange-100",text:"text-orange-800"},high:{label:"High Risk",bg:"bg-red-100",text:"text-red-800"}},x={auto_launch_to_meta:"This will push approved creatives live to your Meta ad account and spend real money.",auto_budget_adjust:"This will automatically increase/decrease budgets on your live campaigns."},g={autoPullPerformance:!1,autoScoreCreatives:!1,autoKillLosers:!1,autoGenerateSniper:!1,autoGenerateMarksman:!1,autoLaunchToMeta:!1,autoBudgetAdjust:!1,killThresholdCpa:d.killThresholdCpa,killThresholdSpend:d.killThresholdSpend,sniperThresholdMargin:d.sniperThresholdMargin,sniperThresholdConversions:d.sniperThresholdConversions,sniperThresholdDays:d.sniperThresholdDays,metaAdAccountId:"",metaAccessToken:""};function p(e){var t;let{storeId:s}=e,{data:p,error:b,isLoading:y,mutate:v}=(0,l.ZP)("/api/ad-intelligence/settings?storeId=".concat(s),c),[f,j]=(0,r.useState)(g),[k,N]=(0,r.useState)(!1),[T,w]=(0,r.useState)(!1),[C,S]=(0,r.useState)(""),[A,_]=(0,r.useState)(!1),[M,L]=(0,r.useState)("disconnected"),[P,I]=(0,r.useState)(""),[E,D]=(0,r.useState)(null),[R,G]=(0,r.useState)(!1),[O,K]=(0,r.useState)(!1),[B,Z]=(0,r.useState)(null),F=(0,r.useRef)(null),z=(0,r.useRef)(null);(0,r.useRef)(f).current=f;let J=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(p){var e,t,s,a,r,l,n,o,i,c,u,h,m,x;j({autoPullPerformance:null!==(e=p.autoPullPerformance)&&void 0!==e&&e,autoScoreCreatives:null!==(t=p.autoScoreCreatives)&&void 0!==t&&t,autoKillLosers:null!==(s=p.autoKillLosers)&&void 0!==s&&s,autoGenerateSniper:null!==(a=p.autoGenerateSniper)&&void 0!==a&&a,autoGenerateMarksman:null!==(r=p.autoGenerateMarksman)&&void 0!==r&&r,autoLaunchToMeta:null!==(l=p.autoLaunchToMeta)&&void 0!==l&&l,autoBudgetAdjust:null!==(n=p.autoBudgetAdjust)&&void 0!==n&&n,killThresholdCpa:null!==(o=p.
1killThresholdCpa)&&void 0!==o?o:null,killThresholdSpend:null!==(i=p.killThresholdSpend)&&void 0!==i?i:d.killThresholdSpend,sniperThresholdMargin:null!==(c=p.sniperThresholdMargin)&&void 0!==c?c:d.sniperThresholdMargin,sniperThresholdConversions:null!==(u=p.sniperThresholdConversions)&&void 0!==u?u:d.sniperThresholdConversions,sniperThresholdDays:null!==(h=p.sniperThresholdDays)&&void 0!==h?h:d.sniperThresholdDays,metaAdAccountId:null!==(m=p.metaAdAccountId)&&void 0!==m?m:"",metaAccessToken:null!==(x=p.metaAccessToken)&&void 0!==x?x:""}),p.metaAdAccountId&&p.metaAccessToken&&L("connected"),p.lastSyncAt&&Z(p.lastSyncAt),J.current=!0}},[p]);let H=(0,r.useCallback)(async e=>{N(!0),S("");try{let t=await fetch("/api/ad-intelligence/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({storeId:s,...e})});if(!t.ok){let e=await t.json().catch(()=>null);throw Error((null==e?void 0:e.error)||"Failed to save")}let a=await t.json();v(a,!1),w(!0),setTimeout(()=>w(!1),2e3)}catch(e){S(e instanceof Error?e.message:"Failed to save settings")}finally{N(!1)}},[s,v]),$=(0,r.useCallback)(e=>{F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{H(e)},500)},[H]),U=(0,r.useCallback)(e=>{z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{H(e)},1e3)},[H]);(0,r.useEffect)(()=>()=>{F.current&&clearTimeout(F.current),z.current&&clearTimeout(z.current)},[]);let q=(0,r.useCallback)(e=>{let t=h[e],s=!f[t],a=i[e];if(s&&"high"===a.riskLevel){D(e);return}let r={...f,[t]:s};j(r),$(r)},[f,$]),Q=(0,r.useCallback)(()=>{if(!E)return;let e=h[E],t={...f,[e]:!0};j(t),D(null),$(t)},[E,f,$]),V=(0,r.useCallback)(()=>{D(null)},[]),W=(0,r.useCallback)((e,t)=>{let s={...f,[e]:t};j(s),U(s)},[f,U]),X=(0,r.useCallback)((e,t)=>{j(s=>({...s,[e]:t}))},[]),Y=(0,r.useCallback)(async()=>{if(!f.metaAdAccountId||!f.metaAccessToken){L("error"),I("Please enter both Ad Account ID and Access Token.");return}L("testing"),I("");try{let e=await fetch("/api/ad-intelligence/connect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:f.metaAccessToken,adAccountId:f.metaAdAccountId})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error((null==t?void 0:t.error)||"Connection failed")}L("connected"),I("Successfully connected to Meta Ads."),H(f)}catch(e){L("error"),I(e instanceof Error?e.message:"Connection failed")}},[f,H]),ee=(0,r.useCallback)(async()=>{G(!0);try{var e;let t=await fetch("/api/ad-intelligence/sync?storeId=".concat(s),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!0})});if(!t.ok){let e=await t.json().catch(()=>null);throw Error((null==e?void 0:e.error)||"Sync failed")}let a=await t.json();Z(null!==(e=a.syncedAt)&&void 0!==e?e:new Date().toISOString())}catch(e){}finally{G(!1)}},[s]),et=(0,r.useCallback)(async()=>{K(!0);try{let e=await fetch("/api/ad-intelligence/sync?storeId=".concat(s),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scoreOnly:!0})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error((null==t?void 0:t.error)||"Re-score failed")}}catch(e){}finally{K(!1)}},[s]);return y?(0,a.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,a.jsx)(o.Z,{className:"h-6 w-6 animate-spin text-[#00d084]"})}):b?(0,a.jsx)("div",{className:"rounded-xl border border-red-200 bg-red-50 px-6 py-4",children:(0,a.jsx)("p",{className:"text-sm text-red-800",children:"Failed to load settings. Please try again."})}):(0,a.jsxs)("div",{className:"relative space-y-8",children:[(0,a.jsx)("div",{className:"pointer-events-none fixed right-8 top-8 z-50 transition-all duration-300 ".concat(T?"translate-y-0 opacity-100":"-translate-y-2 opacity-0"),children:(0,a.jsx)("div",{className:"rounded-lg border border-green-200 bg-white px-4 py-2 shadow-lg",children:(0,a.jsx)("span",{className:"text-sm font-semibold text-[#00d084]",children:"Saved"})})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-2xl font-extrabold text-[#0a0a0a]",children:"Ad Intelligence"}),(0,a.jsx)("p",{className:"mt-1 text-sm text-gray-500",children:"Control what the system does autonomously. All actions are OFF by default."})]}),(0,a.jsxs)("div",{className:"rounded-xl border border-gray-200 bg-white p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-extrabold text-[#0a0a0a]",children:"Meta Ads Connection"}),(0,a.jsxs)("div",{className:"mt-4 space-y-4",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Ad Account ID"}),(0,a.jsx)("input",{type:"text",value:f.metaAdAccountId,onChange:e=>X("metaAdAccountId",e.target.value),placeholder:"act_123456789",className:"w-full rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Access Token"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("input",{type:A?"text":"password",value:f.metaAccessToken,onChange:e=>X("metaAccessToken",e.target.value),placeholder:"Enter your Meta access token",className:"w-full rounded-lg border border-gray-200 bg-white px-4 py-2 pr-20 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"}),(0,a.jsx)("button",{type:"button",onClick:()=>_(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2 text-xs font-semibold text-gray-500 hover:text-gray-700",children:A?"Hide":"Show"})]})]}),(0,a.jsxs)("div",{className:"flex items-center gap-4",children:[(0,a.jsxs)(n.z,{variant:"outline",onClick:Y,disabled:"testing"===M,className:"border-[#00d084] text-[#00d084] hover:bg-[#00d084]/5",children:["testing"===M&&(0,a.jsx)(o.Z,{className:"mr-2 h-4 w-4 animate-spin"}),"testing"===M?"Testing...":"Test Connection"]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"inline-block h-2.5 w-2.5 rounded-full ".concat("connected"===M?"bg-[#00d084]":"error"===M?"bg-red-500":"testing"===M?"animate-pulse bg-yellow-500":"bg-gray-300")}),(0,a.jsx)("span",{className:"text-xs font-semibold ".concat("connected"===M?"text-[#00d084]":"error"===M?"text-red-600":"text-gray-500"),children:"connected"===M?"Connected":"error"===M?"Error":"testing"===M?"Testing...":"Not Connected"})]})]}),P&&(0,a.jsx)("p",{className:"text-xs ".concat("connected"===M?"text-[#00d084]":"text-red-600"),children:P})]})]}),(0,a.jsxs)("div",{className:"rounded-xl border border-gray-200 bg-white p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-extrabold text-[#0a0a0a]",children:"Autonomy Controls"}),(0,a.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"Each toggle auto-saves when changed."}),(0,a.jsx)("div",{className:"mt-4 divide-y divide-gray-100",children:u.map(e=>{let{key:t,risk:s}=e,r=i[t],l=f[h[t]],n=m[s],o=E===t;return(0,a.jsxs)("div",{className:"py-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{className:"flex-1 pr-4",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{className:"text-sm font-bold text-gray-900",children:r.label}),(0,a.jsx)("span",{className:"inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold ".concat(n.bg," ").concat(n.text),children:n.label})]}),(0,a.jsx)("p",{className:"mt-0.5 text-xs text-gray-500",children:r.description})]}),(0,a.jsx)("button",{type:"button",role:"switch","aria-checked":l,onClick:()=>q(t),className:"relative inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full transition-colors duration-200 ".concat(l?"bg-[#00d084]":"bg-gray-200"),children:(0,a.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform duration-200 ".concat(l?"translate-x-6":"translate-x-1")})})]}),o&&(0,a.jsxs)("div",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3",children:[(0,a.jsxs)("p",{className:"text-xs font-semibold text-red-800",children:[x[t]," Are you sure?"]}),(0,a.jsxs)("div",{className:"mt-2 flex items-center gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:Q,className:"rounded-lg bg-red-600 px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:bg-red-700",children:"Confirm"}),(0,a.jsx)("button",{type:"button",onClick:V,className:"rounded-lg border border-gray-200 bg-white px-3 py-1.5 text-xs font-semibold text-gray-700 transition-colors hover:bg-gray-50",children:"Cancel"})]})]}),"high"===s&&l&&!o&&(0,a.jsx)("div",{className:"mt-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2",children:(0,a.jsx)("p",{className:"text-xs text-red-700",children:"Active — this action spends real money. Make sure your thresholds are configured."})})]},t)})})]}),(0,a.jsxs)("div",{className:"rounded-xl border border-gray-200 bg-white p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-extrabold text-[#0a0a0a]",children:"Scoring Thresholds"}),(0,a.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:"Auto-saves when you stop typing."}),(0,a.jsxs)("div",{className:"mt-4 grid gap-4 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Kill CPA Threshold"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("span",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"$"}),(0,a.jsx)("input",{type:"number",value:null!==(t=f.killThresholdCpa)&&void 0!==t?t:"",onChange:e=>W("killThresholdCpa",""===e.target.value?null:Number(e.target.value)),placeholder:"Not set",className:"w-full rounded-lg border border-gray-200 bg-white py-2 pl-8 pr-4 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Min Spend Before Kill"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("span",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"$"}),(0,a.jsx)("input",{type:"number",value:f.killThresholdSpend,onChange:e=>W("killThresholdSpend",Number(e.target.value)),placeholder:"150",className:"w-full rounded-lg border border-gray-200 bg-white py-2 pl-8 pr-4 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Sniper Min Margin"}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("input",{type:"number",value:f.sniperThresholdMargin,onChange:e=>W("sniperThresholdMargin",Number(e.target.value)),placeholder:"25",className:"w-full rounded-lg border border-gray-200 bg-white py-2 pl-4 pr-8 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"}),(0,a.jsx)("span",{className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-sm text-gray-400",children:"%"})]})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Sniper Min Conversions"}),(0,a.jsx)("input",{type:"number",value:f.sniperThresholdConversions,onChange:e=>W("sniperThresholdConversions",Number(e.target.value)),placeholder:"30",className:"w-full rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"})]}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-semibold text-gray-700",children:"Sniper Min Days Running"}),(0,a.jsx)("input",{type:"number",value:f.sniperThresholdDays,onChange:e=>W("sniperThresholdDays",Number(e.target.value)),placeholder:"3",className:"w-full rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm text-gray-900 placeholder-gray-400 outline-none focus:border-[#00d084] focus:ring-1 focus:ring-[#00d084]"})]})]})]}),(0,a.jsxs)("div",{className:"rounded-xl border border-gray-200 bg-white p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-extrabold text-[#0a0a0a]",children:"Manual Actions"}),(0,a.jsxs)("div",{className:"mt-4 flex flex-wrap items-center gap-3",children:[(0,a.jsxs)(n.z,{onClick:ee,disabled:R,className:"bg-[#00d084] text-white hover:bg-[#00b870]",children:[R&&(0,a.jsx)(o.Z,{className:"mr-2 h-4 w-4 animate-spin"}),R?"Syncing...":"Sync Now"]}),(0,a.jsxs)(n.z,{variant:"outline",onClick:et,disabled:O,className:"border-gray-200 text-gray-700 hover:bg-gray-50",children:[O&&(0,a.jsx)(o.Z,{className:"mr-2 h-4 w-4 animate-spin"}),O?"Re-Scoring...":"Re-Score All"]})]}),B&&(0,a.jsxs)("p",{className:"mt-3 text-xs text-gray-500",children:["Last synced:"," ",new Date(B).toLocaleStr
1ing(void 0,{dateStyle:"medium",timeStyle:"short"})]})]}),C&&(0,a.jsx)("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3",children:(0,a.jsx)("p",{className:"text-sm text-red-800",children:C})}),k&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:[(0,a.jsx)(o.Z,{className:"h-3 w-3 animate-spin"}),(0,a.jsx)("span",{children:"Saving..."})]})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.