PageSourceSearch

https://ptm-grip-master.lovable.app/assets/LazadaPushLog-Dz5qugeH.js

js ptm-grip-master.lovable.app collected 2026-10-03 03:40:42 UTC 7,342 bytes, 1 lines download raw bytes

1import{ay as J,r,aA as I,n as e,s as u,as as h,$ as y,a4 as m,aK as D,ar as b,b0 as G,b1 as Q,a9 as V,aa as W,ab as d,ac as n,ad as X,ae as t,_ as p}from"./index-JgSTh9Ht.js";import{E as Y}from"./external-link-zVhwrth1.js";import{C as H}from"./copy-5VIly4eZ.js";const C="xuegowylpcqjqeuoiopo",U=`https://${C}.supabase.co/functions/v1/lazada-push`,w=`https://${C}.supabase.co/functions/v1/lazada-oauth-callback`;function te(){var E;const{toast:o}=J(),[$,_]=r.useState(!1),[i,P]=r.useState(""),[j,q]=r.useState(null),[f,F]=r.useState(""),[L,g]=r.useState(null),[S,R]=r.useState(!1),[z,A]=r.useState(!1),{data:c=[],isLoading:O}=I({queryKey:["lazada_push_log"],queryFn:async()=>{const{data:s,error:a}=await p.from("lazada_push_log").select("*").order("received_at",{ascending:!1}).limit(200);if(a)throw a;return s||[]},refetchInterval:5e3}),{data:K=[]}=I({queryKey:["lazada_auth"],queryFn:async()=>{const{data:s}=await p.from("lazada_auth").select("*").order("updated_at",{ascending:!1});return s||[]},refetchInterval:1e4}),x=(E=c[0])!=null&&E.received_at?new Date(c[0].received_at):null,N=x&&Date.now()-x.getTime()<10*60*1e3,T=i?c.filter(s=>String(s.message_type??"").includes(i)||(s.category||"").toLowerCase().includes(i.toLowerCase())||(s.seller_id||"").toLowerCase().includes(i.toLowerCase())):c,k=async(s,a)=>{await navigator.clipboard.writeText(s),_(!0),o({title:"Copied!",description:`${a} copied`}),setTimeout(()=>_(!1),2e3)},M=async()=>{A(!0);try{const s=`https://${C}.supabase.co/functions/v1/lazada-auth-url?redirect=${encodeURIComponent(w)}`,{data:{session:a}}=await p.auth.getSession(),v=await(await fetch(s,{headers:{Authorization:`Bearer ${a==null?void 0:a.access_token}`}})).json();v.auth_url?(window.open(v.auth_url,"_blank","noopener"),o({title:"Opening Lazada authorization",description:"Approve in the new tab, then return here."})):o({title:"Error",description:JSON.stringify(v),variant:"destructive"})}catch(s){o({title:"Error",description:String(s),variant:"destructive"})}finally{A(!1)}},B=async()=>{R(!0),g(null);try{const{data:s,error:a}=await p.functions.invoke("lazada-api",{body:{action:"get_order",order_id:f.trim()}});if(a)throw a;g(s)}catch(s){g({error:String((s==null?void 0:s.message)||s)})}finally{R(!1)}},l=K[0];return e.jsxs("div",{className:"space-y-4",children:[e.jsx(u,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-[260px]",children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Seller Authorization"}),l?e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("div",{children:["Seller ID: ",e.jsx("b",{children:l.seller_id})," ",e.jsx(h,{variant:"secondary",children:l.country})]}),l.account&&e.jsxs("div",{className:"text-muted-foreground text-xs",children:["Account: ",l.account]}),e.jsxs("div",{className:"text-muted-foreground text-xs",children:["Token expires: ",y(new Date(l.expire_at),"yyyy-MM-dd HH:mm")]})]}):e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("p",{className:"text-muted-foreground",children:["Using ",e.jsx("b",{children:"LAZADA_USER_TOKEN"})," from secrets (seller MY12KX8)."]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click below to run full OAuth and store refreshable tokens."})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Redirect URL to whitelist in Lazada Open Platform → App Info: ",e.jsx("br",{}),e.jsx("code",{className:"text-xs",children:w})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(m,{onClick:M,disabled:z,children:[z?e.jsx(D,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Y,{className:"h-4 w-4 mr-2"}),l?"Re-authorize Seller":"Authorize Seller"]}),e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>k(w,"Redirect URL"),children:[e.jsx(H,{className:"h-3 w-3 mr-1"})," Copy redirect"]})]})]})}),e.jsxs(u,{className:"p-4",children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Test: Get Order Detail"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(b,{value:f,onChange:s=>F(s.target.value),placeholder:"Lazada Order ID (numeric)",className:"max-w-xs font-mono"}),e.jsxs(m,{onClick:B,disabled:S||!f,children:[S&&e.jsx(D,{className:"h-4 w-4 animate-spin mr-2"}),"Fetch Order"]})]}),L&&e.jsx("pre",{className:"mt-3 text-xs bg-muted/30 rounded p-3 overflow-auto max-h-[500px]",children:JSON.stringify(L,null,2)})]}),e.jsx(u,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-[260px]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"font-semibold",children:"Push Notification Callback URL"}),e.jsxs(h,{variant:N?"default":"secondary",className:"gap-1",children:[e.jsx(G,{className:`h-2 w-2 fill-current ${N?"text-green-500":"text-muted-foreground"}`}),N?"Receiving":"Waiting"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{value:U,readOnly:!0,className:"font-mono text-xs"}),e.jsx(m,{onClick:()=>k(U,"Callback URL"),variant:"outline",size:"sm",children:$?e.jsx(Q,{className:"h-4 w-4"}):e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Paste this into Lazada Open Platform → ",e.jsx("b",{children:"App Console → Notification → Callback URL"}),"."]})]}),e.jsxs("div",{className:"text-right text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:"Total received"}),e.jsx("div",{className:"text-2xl font-bold",children:c.length}),x&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last: ",y(x,"HH:mm:ss")]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(b,{placeholder:"Filter by type, category or seller...",value:i,onChange:s=>P(s.target.value),className:"max-w-xs"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Auto-refreshes every 5s"})]}),e.jsx(u,{children:e.jsxs(V,{children:[e.jsx(W,{children:e.jsxs(d,{children:[e.jsx(n,{children:"Time"}),e.jsx(n,{children:"Type"}),e.jsx(n,{children:"Category"}),e.jsx(n,{children:"Seller ID"}),e.jsx(n,{children:"Status"}),e.jsx(n,{children:"Payload"})]})}),e.jsxs(X,{children:[O&&e.jsx(d,{children:e.jsx(t,{colSpan:6,className:"text-center text-muted-foreground",children:"Loading..."})}),!O&&T.length===0&&e.jsx(d,{children:e.jsx(t,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No pushes received yet."})}),T.map(s=>e.jsxs(r.Fragment,{children:[e.jsxs(d,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>q(j===s.id?null:s.id),children:[e.jsx(t,{className:"text-xs",children:y(new Date(s.received_at),"MMM dd HH:mm:ss")}),e.jsx(t,{children:e.jsx(h,{variant:"outline",children:s.message_type??"—"})}),e.jsx(t,{className:"text-sm",children:s.category}),e.jsx(t,{className:"text-sm",children:s.seller_id??"—"}),e.jsx(t,{children:e.jsx(h,{variant:s.response_status===200?"default":"destructive",children:s.response_status??"—"})}),e.jsx(t,{className:"text-xs text-muted-foreground",children:j===s.id?"Hide":"View"})]}),j===s.id&&e.jsx(d,{children:e.jsx(t,{colSpan:6,className:"bg-muted/30",children:e.jsx("pre",{className:"text-xs overflow-auto max-h-96 p-2",children:JSON.stringify(s.payload,null,2)})})})]},s.id))]})]})})]})}export{te 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.