PageSourceSearch

https://archie.app/assets/AdminBackfill-DNZoELa_.js

js archie.app collected 2026-10-05 09:43:46 UTC 9,033 bytes, 6 lines download raw bytes

1import{a4 as J,al as L,u as O,r as S,K as P,j as e,a2 as y,t as T,s as M}from"./index-BgZSzx2-.js";import{u as R}from"./useMutation-BACumlTZ.js";import{A as $,F as Z,f as _,p as I,B as f,z as E,G as q,H as V,J as D}from"./AdminLayout-CddG8Wtk.js";import{C as N,a as k,b as v,c as w}from"./card-DIf6YtzM.js";import{S as K}from"./switch-BaH4o541.js";import{L as Q}from"./label-DTHdYPyr.js";import{T as U,a as X,b as H,c,d as A,e as d}from"./table-0mxh5_IG.js";import{C as Y,a as G}from"./circle-x-CQRbAc3T.js";import{R as W}from"./refresh-cw-Cb90MAiq.js";import"./index-Da9niVR8.js";import"./chart-line-Bm9k7IIX.js";import"./index-OT11IY4a.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ee=J("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]),se=500,te=async j=>{var h;const g="https://vwuzdffiwjorotgjcrun.supabase.co/functions/v1/backfill-hubspot",{data:u}=await M.auth.getSession(),b=(h=u.session)==null?void 0:h.access_token,n={"Content-Type":"application/json",apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZ3dXpkZmZpd2pvcm90Z2pjcnVuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzYzNDU0MzYsImV4cCI6MjA5MTkyMTQzNn0.--VXZsL26cKw51t7JtE0veVC7_YwjixxIyaVPBgtC84"};b&&(n.Authorization=`Bearer ${b}`);const m=await fetch(g,{method:"POST",headers:n,body:JSON.stringify(j)}),l=await m.json();if(!m.ok)throw new Error((l==null?void 0:l.error)??`Request failed (${m.status})`);return l},pe=()=>{const j=L(),{toast:g}=O(),[u,b]=S.useState(!1),[n,m]=S.useState(null),[l,h]=S.useState(null),{data:C=[],isLoading:B}=P({queryKey:["hubspot-backfill-runs"],queryFn:async()=>{const{data:t,error:s}=await M.from("hubspot_sync_logs").select("id, action, status, response_body, error_message, created_at").eq("action","backfill").order("created_at",{ascending:!1}).limit(50);if(s)throw s;return t}}),o=C[0]??null,i=(o==null?void 0:o.response_body)??null,x=R({mutationFn:async t=>{let s=0;const a={total:0,updated:0,created:0,skipped:0,failed:0,dryRun:t,errors:[]};for(h({done:0,total:0});;){const r=await te({force:u,dryRun:t,offset:s,chunkSize:se});a.total+=r.total,a.updated+=r.updated,a.created+=r.created,a.skipped+=r.skipped,a.failed+=r.failed,a.errors.push(...r.errors);const F=r.totalSignups??r.total,z=(r.offset??s)+r.total;if(h({done:z,total:F}),r.nextOffset==null)break;s=r.nextOffset}return a},onSettled:()=>h(null),onSuccess:(t,s)=>{j.invalidateQueries({queryKey:["hubspot-backfill-runs"]}),g({title:s?"Dry run complete":"Backfill complete",description:`${t.total} processed · ${t.created} created · ${t.updated} updated · ${t.skipped} skipped · ${t.failed} failed`,variant:t.failed>0?"destructive":"default"})},onError:t=>{g({title:"Backfill failed",description:t instanceof Error?t.message:"Unknown error",variant:"destructive"})}}),p=(t,s,a)=>e.jsxs(N,{children:[e.jsx(k,{className:"pb-2",children:e.jsx(v,{className:"text-xs text-muted-foreground",children:t})}),e.jsx(w,{children:e.jsx("div",{className:`text-2xl font-bold ${a??""}`,children:s})})]});return e.jsxs($,{title:"HubSpot Backfill",children:[e.jsx("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:e.jsxs("div",{children:[e.jsx("h1",{className:"font-sans text-2xl font-bold text-foreground",children:"HubSpot Backfill"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Stamps ",e.jsx("code",{className:"font-mono",children:"archie_waitlist_signup_date"})," ","on every HubSpot contact matching a row in ",e.jsx("code",{children:"signups"}),", using ",e.jsx("code",{children:"signups.created_at"}),". Creates contacts that don't exist yet."]})]})}),e.jsxs(N,{className:"mb-6",children:[e.jsx(k,{className:"pb-3",children:e.jsx(v,{className:"text-sm",children:"Run backfill"})}),e.jsxs(w,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(K,{id:"force",checked:u,onCheckedChange:b}),e.jsxs(Q,{htmlFor:"force",className:"text-sm cursor-pointer",children:["Force overwrite"," ",e.jsx("span",{className:"text-muted-foreground",children:"(re-stamp contacts that already have the property)"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(y,{variant:"outline",onClick:()=>x.mutate(!0),disabled:x.isPending,children:[x.isPending&&x.variables===!0?e.jsx(T,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Dry run"]}),e.jsxs(y,{onClick:()=>{confirm(u?"Force-overwrite the property on every matching HubSpot contact?":"Run the backfill against HubSpot? Idempotent: only stamps contacts missing the property.")&&x.mutate(!1)},disabled:x.isPending,children:[x.isPending&&x.variables===!1?e.jsx(T,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ee,{className:"h-4 w-4 mr-2"}),"Run backfill"]}),l&&l.total>0&&e.jsxs("span",{className:"text-xs text-muted-foreground self-center",children:["Processed ",l.done," / ",l.total,"…"]})]})]})]}),i&&e.jsxs(N,{className:"mb-6",children:[e.jsx(k,{className:"pb-3",children:e.jsxs(v,{className:"text-sm flex items-center gap-2",children:[(o==null?void 0:o.status)==="success"?e.jsx(Y,{className:"h-5 w-5 text-green-600"}):e.jsx(G,{className:"h-5 w-5 text-red-600"}),"Last run —"," ",o&&_(I(o.created_at),"MMM dd, yyyy HH:mm")," ",i.dryRun&&e.jsx(f,{variant:"outline",className:"ml-2",children:"Dry run"})]})}),e.jsxs(w,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 ga
6p-3 mb-4",children:[p("Total",i.total),p("Created",i.created,"text-green-600"),p("Updated",i.updated,"text-blue-600"),p("Skipped",i.skipped,"text-muted-foreground"),p("Failed",i.failed,i.failed>0?"text-red-600":"")]}),i.errors&&i.errors.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"First failures"}),e.jsx("div",{className:"space-y-1 max-h-48 overflow-auto",children:i.errors.slice(0,10).map((t,s)=>{var a;return e.jsxs("div",{className:"text-xs font-mono bg-red-500/5 border border-red-500/20 rounded px-2 py-1",children:[e.jsxs("span",{className:"text-red-700",children:["[",t.status,"]"]})," ",t.email," —"," ",e.jsx("span",{className:"text-muted-foreground",children:typeof t.body=="string"?t.body:(a=JSON.stringify(t.body))==null?void 0:a.slice(0,200)})]},s)})})]})]})]}),e.jsxs(N,{children:[e.jsxs(k,{className:"pb-3 flex flex-row items-center justify-between",children:[e.jsx(v,{className:"text-sm",children:"Run history"}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>j.invalidateQueries({queryKey:["hubspot-backfill-runs"]}),children:e.jsx(W,{className:"h-4 w-4"})})]}),e.jsx(w,{children:B?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"Loading…"}):C.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No runs yet. Try a dry run first."}):e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(H,{children:[e.jsx(c,{children:"When"}),e.jsx(c,{children:"Mode"}),e.jsx(c,{children:"Status"}),e.jsx(c,{className:"text-right",children:"Total"}),e.jsx(c,{className:"text-right",children:"Created"}),e.jsx(c,{className:"text-right",children:"Updated"}),e.jsx(c,{className:"text-right",children:"Skipped"}),e.jsx(c,{className:"text-right",children:"Failed"}),e.jsx(c,{})]})}),e.jsx(A,{children:C.map(t=>{const s=t.response_body??null;return e.jsxs(H,{className:"cursor-pointer",onClick:()=>m(t),children:[e.jsx(d,{className:"font-mono text-xs",children:_(I(t.created_at),"MMM dd HH:mm")}),e.jsx(d,{children:s!=null&&s.dryRun?e.jsx(f,{variant:"outline",children:"Dry"}):e.jsx(f,{children:"Live"})}),e.jsx(d,{children:t.status==="success"?e.jsx(f,{className:"bg-green-500/10 text-green-700 border-green-500/30",children:"Success"}):e.jsx(f,{variant:"destructive",children:"Failed"})}),e.jsx(d,{className:"text-right",children:(s==null?void 0:s.total)??"—"}),e.jsx(d,{className:"text-right text-green-600",children:(s==null?void 0:s.created)??"—"}),e.jsx(d,{className:"text-right text-blue-600",children:(s==null?void 0:s.updated)??"—"}),e.jsx(d,{className:"text-right text-muted-foreground",children:(s==null?void 0:s.skipped)??"—"}),e.jsx(d,{className:`text-right ${((s==null?void 0:s.failed)??0)>0?"text-red-600 font-medium":""}`,children:(s==null?void 0:s.failed)??"—"}),e.jsx(d,{className:"text-right",children:e.jsx(y,{size:"sm",variant:"ghost",children:"View"})})]},t.id)})})]})})]}),e.jsx(E,{open:!!n,onOpenChange:t=>!t&&m(null),children:e.jsxs(q,{className:"w-full sm:max-w-2xl overflow-auto",children:[e.jsx(V,{children:e.jsxs(D,{children:["Backfill run"," ",n&&_(I(n.created_at),"MMM dd, yyyy HH:mm")]})}),n&&e.jsxs("div",{className:"mt-4 space-y-3",children:[n.error_message&&e.jsx("div",{className:"text-sm bg-red-500/5 border border-red-500/20 rounded p-3 text-red-700",children:n.error_message}),e.jsx("pre",{className:"text-xs bg-muted p-3 rounded overflow-auto max-h-[60vh]",children:JSON.stringify(n.response_body,null,2)})]})]})})]})};export{pe as default};

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.