PageSourceSearch

https://opedd.com/assets/BuyerAccount-D1UopoIL.js

js opedd.com collected 2026-10-04 05:32:50 UTC 37,448 bytes, 35 lines download raw bytes

1import{r as n,j as e,L as pe,i as zt,k as Pt,u as Rt}from"./vendor-react-PtCE6zzk.js";import{u as Lt}from"./useDocumentTitle-BkoG-C1v.js";import{c as nt,u as he,l as it,S as me,b as E,V as ue,B as x,aa as $t,a4 as Ye,D as Ot,d as It,e as Ft,f as Qe,R as ot,i as lt,C as ct,P as de,X as Kt,Q as Mt,O as qt}from"./index-Dx1RQjBj.js";import{I as dt}from"./InlineErrorCard-CsMJZSdd.js";import{T as mt,a as ut,b as T,c as D}from"./tabs-BxtBhh78.js";import{I as N}from"./input-gvE-tPe3.js";import{L as y}from"./label-CzKIqyed.js";import{S as Ut}from"./switch-BEFuq636.js";import{Z as Yt}from"./ZoneHeader-B6POeMhK.js";import{D as He,f as Qt,a as Ve,b as We,c as Ge,d as Ze,e as Xe}from"./dialog-DCxobnxa.js";import{B as Ht,i as Vt}from"./BuyerOverviewSection-Bi4upSlo.js";import{b as Wt,c as Gt,B as Zt,a as Je,p as et,d as Xt,r as Jt,e as es}from"./buyerApi-lSW6i-1R.js";import{s as ts,f as tt,O as ss}from"./countryCodes-C6yGLki9.js";import{S as as}from"./ScheduleDocumentSheet-lkq8538l.js";import{L as rs}from"./licences-DYIGx3XG.js";import{S as ns}from"./shopping-bag-CwL5_NbZ.js";import{E as is}from"./ellipsis-BCcFEdFU.js";import{T as os}from"./trash-2-CI6DClvn.js";import{M as xt,g as pt,h as ht}from"./modal-dD6mz_3x.js";import{C as ls}from"./copy-Dvif1qA9.js";import{u as cs,a as ds,b as ms,c as us}from"./useBuyerAccount-Hr6ptlh1.js";import{P as st}from"./plus-kkFDDj6X.js";import{K as $}from"./key-round-D1W1ARi2.js";import{S as xs}from"./shield-alert-DHHPFJEn.js";import{T as ps}from"./triangle-alert-DLirsOPX.js";import"./vendor-radix-DCv5VfO_.js";import"./vendor-supabase-Bcw6FzAw.js";import"./vendor-recharts-DzKtGs7j.js";import"./circle-alert-EZUmdtII.js";import"./StatTile-B-EQPS-e.js";import"./arrow-up-right-DECHqlEm.js";import"./SurfaceCard-2lmBDovU.js";import"./key-CRtmHYyk.js";import"./scroll-text-e6hKtleL.js";import"./activity-BlEf_11h.js";import"./arrow-right-Fmb-9ROD.js";import"./code-xml-lsecxEnY.js";import"./licenseTypes-B7nDSjnj.js";import"./categories-Dl-7Zdt8.js";import"./checkbox-ExK7G8Vr.js";import"./useLegalDocument-R6BfpE3L.js";import"./download-D3HXDwsv.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 hs=nt("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ys=nt("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);function fs(s){return s.status==="active"&&s.cancel_at?"cancelled":s.status}function gs(s){var a;const o=s.licence?((a=rs[s.licence])==null?void 0:a.name)??s.licence:"Licence",d=s.billing_mode==="metered"?"per request":s.billing_mode==="one_time"?"one-off":"monthly",c=s.lines.length;return`${o} · ${d} · ${c} publication${c===1?"":"s"}`}const bs=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:s%100===0?0:2}).format(s/100),yt=s=>new Date(s).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"}),I={active:"bg-emerald-50 text-emerald-700 border-emerald-200",pending:"bg-amber-50 text-amber-700 border-amber-200",cancelled:"bg-amber-50 text-amber-700 border-amber-200",ended:"bg-gray-100 text-gray-600 border-gray-200",withdrawn:"bg-gray-100 text-gray-600 border-gray-200",failed:"bg-red-50 text-red-700 border-red-200"},js=s=>s.billing_mode==="metered"?"billed per request":`${bs(s.total_amount_cents)}${s.billing_mode==="one_time"?"":" / mo"}`;function vs(s,o){const{getAccessToken:d}=he();return it({queryKey:["buyer-order",s],enabled:o,staleTime:60*1e3,queryFn:async()=>Wt(await d()??"",s)})}function Ns({line:s,orderId:o,onContract:d}){return e.jsxs("div",{className:"flex flex-col gap-1 border-t border-gray-100 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium text-navy-deep",children:s.publisher_name??s.publisher_id}),e.jsx("p",{className:"mt-0.5 font-mono text-[13px] text-gray-500",children:s.schedule_document_sha256?`${s.schedule_document_sha256.slice(0,8)}…${s.schedule_document_sha256.slice(-4)}`:s.schedule_id.slice(0,8)})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:E("roun
11ded-full border px-2.5 py-1 text-xs font-medium capitalize",I[s.status]??I.ended),children:s.status}),e.jsx("button",{type:"button",onClick:()=>d(s.publisher_id),className:"text-sm font-medium text-oxford hover:underline","data-testid":`contract-${o}-${s.publisher_id}`,children:"Contract"})]})]})}function ws(){var g;const{user:s,getAccessToken:o}=he(),[d,c]=n.useState(null),[a,p]=n.useState(null),b=it({queryKey:["buyer-orders",(s==null?void 0:s.id)??"anon"],enabled:!!s,staleTime:30*1e3,queryFn:async()=>Gt(await o()??"",{limit:50})});if(b.isPending)return e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-border bg-white p-6 text-[13px] text-gray-500",children:[e.jsx(me,{size:"sm",className:"text-oxford"}),"Loading your licences"]});if(b.isError)return e.jsx(dt,{message:"Your licences did not load.",onRetry:()=>b.refetch()});const u=((g=b.data)==null?void 0:g.orders)??[];return u.length===0?e.jsxs("div",{className:"rounded-2xl border border-border bg-white py-10 text-center",children:[e.jsx(ns,{size:28,className:"mx-auto mb-2 text-gray-300"}),e.jsx("p",{className:"text-[17px] font-semibold text-navy-deep",children:"No licences yet."}),e.jsx("p",{className:E(ue.body.meta,"mt-1"),children:"Orders appear here with their contract documents."}),e.jsx(pe,{to:"/buyer/browse",children:e.jsx(x,{className:"mt-4",size:"sm",children:"Browse publications"})})]}):e.jsxs("div",{className:"space-y-3",children:[u.map(i=>{const f=d===i.order_id,C=fs(i);return e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:()=>c(f?null:i.order_id),"aria-expanded":f,"data-testid":`order-${i.order_id}`,className:"flex w-full items-start gap-3 px-5 py-4 text-left hover:bg-gray-50",children:[e.jsx($t,{className:E("mt-1 h-4 w-4 shrink-0 text-gray-400 transition-transform",f&&"rotate-180"),"aria-hidden":!0}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-medium text-navy-deep",children:gs(i)}),e.jsxs("span",{className:E("mt-0.5 block",ue.body.meta),children:["Order ",i.order_number," · started ",yt(i.created_at)]})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[e.jsx("span",{className:"text-[15px] font-semibold tabular-nums text-navy-deep",children:js(i)}),e.jsx("span",{className:E("rounded-full border px-2.5 py-1 text-xs font-medium capitalize",I[C]??I.ended),children:C})]})]}),f&&e.jsx(_s,{order:i,onContract:m=>p({orderId:i.order_id,publisherId:m})})]},i.order_id)}),e.jsx(as,{orderId:(a==null?void 0:a.orderId)??null,publisherId:(a==null?void 0:a.publisherId)??null,open:!!a,onOpenChange:i=>{i||p(null)}})]})}function _s({order:s,onContract:o}){var a;const c=((a=vs(s.order_id,!0).data)==null?void 0:a.lines)??s.lines;return e.jsxs("div",{className:"border-t border-border bg-gray-50/60 px-5 pb-4",children:[c.map(p=>e.jsx(Ns,{line:p,orderId:s.order_id,onContract:o},p.schedule_id)),s.billing_mode!=="one_time"&&e.jsxs("div",{className:"mt-3 flex flex-col gap-2 border-t border-gray-100 pt-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("p",{className:ue.body.meta,children:s.cancel_at?`This licence ends on ${yt(s.cancel_at)}.`:"Cancelling ends this licence at the end of the paid month."}),e.jsx(pe,{to:"/buyer/billing",children:e.jsx(x,{variant:"outline",size:"sm",children:"Cancel in Billing"})})]})]})}const ye=["audit","search"],ft={audit:{title:"Read compliance records",body:"Reads your licences, receipts and attestations. Costs nothing.",spendsMoney:!1,chip:"Free",listChip:"Reads records"},search:{title:"Ask questions of licensed publications",body:"Every question this key asks is charged at the publisher's per-request price. This key spends money.",spendsMoney:!0,listChip:"Asks questions"}},ks="Content access is always included, whatever you choose here.";function Cs(s){return`As a safety net we stop questions at ${xe(s)} across the whole account each calendar month. Ask us and we will raise it.`}const Ss="The cap is for the account, across every key, not for this key on its own.";function Es(s,o){return`Questions this month · ${xe(s)} of ${xe(o)} · across every key`}
11function xe(s){return`$${Math.round(s/100).toLocaleString("en-US")}`}function Ts(s){return ye.filter(o=>s[o])}function Ds(s){return ye.filter(o=>s.includes(o)).map(o=>ft[o].listChip)}function at({k:s,onRevokeClick:o,onRotateClick:d,isRevoking:c,isRotating:a}){const p=!!s.revoked_at;return e.jsxs("div",{className:`flex items-center gap-3.5 rounded-xl border border-border bg-white px-4 py-3.5 ${p?"opacity-55":""}`,"data-testid":"buyer-key-row",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.name&&e.jsx("span",{className:"text-[15px] font-semibold text-navy-deep",children:s.name}),s.environment==="test"&&e.jsx("span",{className:"inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium uppercase text-gray-600",children:"test"}),Ds(s.scopes??[]).map(b=>e.jsx("span",{className:"inline-flex items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-600","data-testid":"key-scope-chip",children:b},b))]}),e.jsxs("code",{className:"mt-0.5 block font-mono text-[13px] text-navy-deep","data-testid":"key-prefix",children:["opedd_buyer_",s.environment,"_",s.key_prefix,"…"]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-3 text-xs text-muted-foreground tabular-nums flex-wrap",children:[e.jsxs("span",{children:["created ",Ye(new Date(s.created_at),{addSuffix:!0})]}),s.last_used_at&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:["last used ",Ye(new Date(s.last_used_at),{addSuffix:!0})]})]})]})]}),p?e.jsxs("span",{className:"inline-flex shrink-0 items-center rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-500",children:["Revoked",s.revoked_at?` ${new Date(s.revoked_at).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`:""]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-emerald-200 bg-emerald-50 px-2.5 py-0.5 text-xs font-medium text-emerald-700",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-500","aria-hidden":"true"}),"Active"]}),e.jsxs(Ot,{children:[e.jsx(It,{asChild:!0,children:e.jsx(x,{variant:"ghost",size:"sm",className:"h-9 w-9 shrink-0 p-0 text-gray-400 hover:text-navy-deep","aria-label":`Actions for key ${s.key_prefix}`,"data-testid":"key-overflow",disabled:c||a,children:e.jsx(is,{size:17})})}),e.jsxs(Ft,{align:"end",className:"w-44",children:[d&&e.jsxs(Qe,{onClick:()=>d(s),disabled:a||c,"data-testid":"rotate-btn",className:"gap-2 text-sm",children:[e.jsx(ot,{size:14,className:"text-gray-500"}),"Rotate"]}),e.jsxs(Qe,{onClick:()=>o==null?void 0:o(s),disabled:c||a,"data-testid":"revoke-btn",className:"gap-2 text-sm text-red-600 focus:text-red-700",children:[e.jsx(os,{size:14}),"Revoke"]})]})]})]})]})}function As({k:s,onConfirm:o,onCancel:d,isLoading:c}){return e.jsx(xt,{variant:"confirm",destructive:!0,open:!!s,onOpenChange:a=>{a||d()},title:"Revoke this key?",description:e.jsxs("span",{children:[s&&e.jsxs("code",{className:"text-xs font-mono",children:["opedd_buyer_",s.environment,"_",s.key_prefix,"…"]})," ","stops working immediately - active integrations using it will start receiving 401 errors. If you need continuity, create a replacement key first and migrate before revoking."]}),footer:e.jsxs(e.Fragment,{children:[e.jsx(pt,{disabled:c,children:"Cancel"}),e.jsx(ht,{disabled:c,onClick:()=>o(!0),className:"bg-red-600 hover:bg-red-700","data-testid":"revoke-confirm-btn",children:c?"Revoking…":"Revoke key"})]})})}function Bs({k:s,onConfirm:o,onCancel:d,isLoading:c}){return e.jsx(xt,{variant:"confirm",open:!!s,onOpenChange:a=>{a||d()},icon:e.jsx(ot,{className:"h-5 w-5 text-oxford"}),title:"Rotate this key?",description:e.jsxs("span",{children:[s&&e.jsxs("code",{className:"text-xs font-mono",children:["opedd_buyer_",s.environment,"_",s.key_prefix,"…"]})," ","will be replaced with a new key in the same environment."]}),footer:e.jsxs(e.Fragment,{children:[e.jsx(pt,{disabled:c,children:"Cancel"}),e.jsx(ht,{disabled:c,onClick:o,className:"bg-oxford hover:bg-oxford/90","data-testid":"rotate-confirm-btn",children:c?"Rotating…":"Rotate key"})]}),children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("ul",{className:"list-disc pl-5 space-y-1 text-gray-700",children:[e.jsxs("li",{children:["The new key is shown ",e.jsx("strong",{children:"once"})," - copy it immediately."]}),e.jsxs("li",{children:["The old key is revoked ",e.jsx("strong",{children:"immediately"})," - requests using it fail with 401."]}),e.jsx("li",{children:"The replacement keeps the same environment and scopes."})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Need a migration window? Create a ",e.jsx("strong",{children:"new key"})," first, move your integrations over, then revoke this one."]})]})})}const O="opedd_buyer_live_<paste_your_key>",rt=[{id:"curl",label:"curl",code:`curl -sS 'https://api.opedd.com/enterprise-license?access_key=${O}&limit=10'
12
13# Metered (filtered-scope) keys: feed rows have content_access
14# "metered_per_call" and content_body null - fetch text per article:
15curl -sS 'https://api.opedd.com/content-delivery?article_id=<id_from_feed>' \\
16  -H 'Authorization: Bearer ${O}'`},{id:"python",label:"Python",code:`import requests
17
18BASE = "https://api.opedd.com"
19KEY = "${O}"
20
21resp = requests.get(
22    f"{BASE}/enterprise-license",
23    params={"access_key": KEY, "limit": 10},
24)
25# Rows carry content_access; when "metered_per_call", content_body is
26# null - GET /content-delivery?article_id=... (Bearer auth, per call)
27print(resp.json())`},{id:"node",label:"Node.js",code:`const BASE = "https://api.opedd.com";
28const KEY = "${O}";
29
30const res = await fetch(
31  \`\${BASE}/enterprise-license?access_key=\${KEY}&limit=10\`,
32);
33// Rows carry content_access; when "metered_per_call", content_body is
34// null - GET /content-delivery?article_id=... (Bearer auth, per call)
35console.log(await res.json());`}];function zs(){const{toast:s}=lt(),[o,d]=n.useState(null),c=async(a,p)=>{try{await navigator.clipboard.writeText(p),d(a),s({title:`${a} sample copied`}),setTimeout(()=>d(null),2e3)}catch{s({title:"Copy failed",variant:"destructive"})}};return e.jsxs("div",{className:"bg-white border border-border rounded-lg p-5",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:"Make your first request"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Feed rows include ",e.jsx("code",{children:"content_access"})," - on metered (filtered-scope) keys"," ",e.jsx("code",{children:"content_body"})," is null; fetch article text via ",e.jsx("code",{children:"/content-delivery"}),", billed per call."]})]}),e.jsxs(mt,{defaultValue:"curl",className:"w-full",children:[e.jsx(ut,{className:"bg-gray-50",children:rt.map(a=>e.jsx(T,{value:a.id,children:a.label},a.id))}),rt.map(a=>e.jsx(D,{value:a.id,className:"mt-3",children:e.jsxs("div",{className:"relative rounded-lg bg-gray-900 p-4 group",children:[e.jsx(x,{size:"sm",variant:"ghost","aria-label":"Copy code snippet",onClick:()=>c(a.id,a.code),className:"absolute top-2 right-2 text-gray-400 hover:text-white hover:bg-gray-800 opacity-0 group-hover:opacity-100 transition-opacity","data-testid":`quickstart-copy-${a.id}`,children:o===a.id?e.jsx(ct,{size:14}):e.jsx(ls,{size:14})}),e.jsx("pre",{className:"text-xs text-gray-100 font-mono whitespace-pre-wrap break-all overflow-x-auto",children:a.code})]})},a.id))]}),e.jsx("a",{href:"https://docs.opedd.com",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-gray-400 hover:text-oxford mt-3 inline-block",children:"Full API reference →"})]})}const Ps=["overview","keys","licenses","profile"];function wa(){var Ke,Me,qe;Lt("Account - Opedd Buyer");const s=zt(),[o,d]=Pt(),c=Rt(),{getAccessToken:a,logout:p,isLoading:b}=he(),{toast:u}=lt(),g=c.state??null,i=cs({initialData:(g==null?void 0:g.profile)??null}),f=ds(),C=ms(),m=i.data&&i.data!=="no-session"?i.data:null,gt=i.isPending||i.isFetching,bt=i.isError,[j,A]=n.useState(!1),[F,fe]=n.useState(!1),[K,M]=n.useState(""),[q,U]=n.useState(""),[Y,Q]=n.useState(""),[B,H]=n.useState(""),[ge,V]=n.useState("ai_retrieval"),[z,W]=n.useState(""),[G,Z]=n.useState(""),[be,P]=n.useState(!1),[jt,S]=n.useState(!1),[je,ve]=n.useState(""),[Ne,we]=n.useState("live"),[X,_e]=n.useState({audit:!1,search:!1}),[J,ke]=n.useState(!1),[w,ee]=n.useState(null),[_,te]=n.useState(null),[Ce,Se]=n.useState(!1),[k,se]=n.useState(null),[Ee,Te]=n.useState(!1),ae=n.useRef(!1),re=n.useRef(!1),ne=n.useRef(!1),[vt,ie]=n.useState(!1),[De,Ae]=n.useState(""),[oe,Be]=n.useState(!1),ze=us(),Pe=((Ke=ze.data)==null?void 0:Ke.count)??null,Nt=((Me=ze.data)==null?void 0:Me.hasMore)??!1,Re=o.get("tab"),Le=Re==="usage"?"overview":Re,wt=Ps.includes(Le??"")?Le:"overview",R=t=>{d(t==="overview"?{}:{tab:t})};n.useEffect(()=>{g!=null&&g.profile&&s(".",{replace:!0,state:null})},[]),n.useEffect(()=>{i.data==="no-session"?s("/buyer/signup"):i.isSuccess&&i.data===null&&s("/buyer/signup",{replace:!0})},[i.data,i.isSuccess,s]);const $e=n.useCallback(t=>{M(t.buyer.first_name??""),U(t.buyer.last_name??""),Q(t.buyer.company_name??t.buyer.organization??""),H(t.buyer.company_website??""),V(t.buyer.buyer_type??"ai_retrieval"),W(t.buyer.country_of_incorporation??"")},[]),le=n.useRef(!1),Oe=n.useRef(!1);n.useEffect(()=>{if(i.isFetching){le.current=!0;return}const t=le.current;le.current=!1,m&&(!Oe.current||t)&&(Oe.current=!0,$e(m))},[i.isFetching,m,$e]);const _t=n.useMemo(()=>
35{if(!m)return!1;const t=m.buyer;return!t.first_name||!t.last_name||!t.company_name||!t.company_website||!t.buyer_type||!t.country_of_incorporation},[m]),Ie=n.useMemo(()=>ts(G).slice(0,50),[G]),kt=n.useMemo(()=>{var t;return((t=tt(z))==null?void 0:t.name)??""},[z]),Ct=async()=>{if(!m)return;if(!K.trim()||!q.trim()||!Y.trim()){u({title:"First name, last name, and company name are required",variant:"destructive"});return}const t=/^https?:\/\//.test(B.trim())?B.trim():`https://${B.trim()}`;if(!/^https?:\/\/[A-Za-z0-9.-]+\.[A-Za-z]{2,}/.test(t)){u({title:"Enter your company website domain (e.g. acme.ai)",variant:"destructive"});return}if(!/^[A-Z]{2}$/.test(z)){u({title:"Pick a country",variant:"destructive"});return}fe(!0);try{const r=await a();if(!r)throw new Error("Session expired");const{buyer:h}=await et(r,{first_name:K.trim(),last_name:q.trim(),company_name:Y.trim(),company_website:t,buyer_type:ge,country_of_incorporation:z});C({...m,buyer:h}),A(!1),u({title:"Profile updated"})}catch(r){u({title:"Couldn't save",description:r instanceof Error?r.message:"Please try again.",variant:"destructive"})}finally{fe(!1)}},St=async()=>{if(!ae.current){ae.current=!0,ke(!0);try{const t=await a();if(!t)throw new Error("Session expired");const r=Ts(X),h=await Xt(t,{name:je.trim()||null,environment:Ne,...r.length?{scopes:r}:{}});ee({key:h.key,environment:h.key_environment}),S(!1),ve(""),we("live"),_e({audit:!1,search:!1}),i.refetch()}catch(t){u({title:"Couldn't create key",description:t instanceof Error?t.message:"Please try again.",variant:"destructive"})}finally{ke(!1),ae.current=!1}}},Et=async t=>{if(_&&!re.current){re.current=!0,Se(!0);try{const r=await a();if(!r)throw new Error("Session expired");await Jt(r,{key_id:_.id,immediate:t}),u({title:"Key revoked"}),te(null),i.refetch()}catch(r){u({title:"Couldn't revoke key",description:r instanceof Error?r.message:"Please try again.",variant:"destructive"})}finally{Se(!1),re.current=!1}}},Tt=async()=>{if(k&&!ne.current){ne.current=!0,Te(!0);try{const t=await a();if(!t)throw new Error("Session expired");const r=await es(t,{key_id:k.id});ee({key:r.key,environment:r.key_environment}),se(null),r.old_key_revoked===!1?u({title:"Rotation partial - manually revoke the old key",description:r._warning??"New key issued but stamping the old key as revoked failed. Both keys are currently live.",variant:"destructive"}):u({title:"Key rotated",description:"Save the new key now - the old key has been revoked and stops working immediately."}),i.refetch()}catch(t){u({title:"Couldn't rotate key",description:t instanceof Error?t.message:"Please try again.",variant:"destructive"})}finally{Te(!1),ne.current=!1}}},Dt=async()=>{Be(!0);try{const t=await a();if(!t)throw new Error("Session expired - sign in again");await Mt(`${qt}/delete-account`,{method:"POST"},t),await p(),s("/")}catch(t){u({title:"Delete failed",description:t instanceof Error?t.message:"Something went wrong",variant:"destructive"})}finally{Be(!1)}};if(gt)return e.jsx(de,{title:"Account",variant:"buyer",children:e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(me,{size:"lg",className:"text-oxford"})})});if(bt&&!m)return e.jsx(de,{title:"Account",variant:"buyer",children:e.jsx("div",{className:"p-8 max-w-2xl mx-auto",children:e.jsx(dt,{message:"Couldn't load your account.",onRetry:()=>void i.refetch()})})});if(!m)return null;const l=m.buyer;l.first_name&&l.last_name?`${l.first_name}${l.last_name}`:l.name;const Fe=l.company_name??l.organization??"",L=m.keys.filter(t=>!t.revoked_at),At=m.keys.filter(t=>!!t.revoked_at),ce=m.keys.length===1&&!m.keys[0].revoked_at,v=m.filtered_subscription??null;Vt({hasOnlyInitialKey:ce,sub:v,usageCount:Pe});const Bt=e.jsxs(He,{open:jt,onOpenChange:S,children:[e.jsx(Qt,{asChild:!0,children:e.jsxs(x,{size:"sm",children:[e.jsx(st,{size:14,className:"mr-1"})," New key"]})}),e.jsxs(Ve,{className:"sm:max-w-[480px] p-7",children:[e.jsxs(We,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-[10px] bg-gray-100 text-gray-500 ring-1 ring-border",children:e.jsx($,{size:17})}),e.jsx(Ge,{className:"text-lg font-semibold text-navy-deep",children:"Create a new API key"})]}),e.jsx(Ze,{className:"pt-1 text-[13px] text-muted-foreground",children:"The full key is shown once at creation - save it to your secrets manager."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{children:[e.jsxs(y,{htmlFor:"key_name",className:"text-sm font-medium text-gray-900",children:["Name ",e.jsx("span",{className:"font-normal text-gray-400",children:"(optional)"})]}),e.jsx(N,{id:"key_name",placeholder:"e.g. Production server",value:je,onChange:t=>ve(t.target.value),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(y,{className:"block mb-2 text-sm font-medium text-gray-900",children:"Environment"}),e.jsx("div",{role:"radiogroup","aria-label":"Environment",className:"grid grid-cols-2 gap-2.5",children:[{value:"live",label:"Live",hint:"Live keys charge against your account"},{value:"test",label:"Test (sandbox)",hint:"Test keys hit the sandbox - truncated content, no billing"}].map(t=>{const r=Ne===t.value;return e.jsxs("button",{type:"button",role:"radio","aria-checked":r,onClick:()=>we(t.value),className:`flex items-start gap-2.5 rounded-[10px] p-3 text-left transition-colors ${r?"border-[1.5px] border-oxford bg-oxford-light":"border border-border bg-white hover:bg-accent/50"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border-[1.5px] ${r?"border-oxford":"border-gray-300"}`,children:r&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-oxford"})}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13px] font-semibold leading-tight text-navy-deep",children:t.label}),e.jsx("span",{className:"mt-0.5 block text-[13px] leading-snug text-muted-foreground",children:t.hint})]})]},t.value)})})]}),e.jsxs("div",{children:[e.jsx(y,{className:"block mb-2 text-sm font-medium text-gray-900",children:"What this key can do"}),e.jsx("div",{className:"space-y-2",children:ye.map(t=>{const r=ft[t],h=X[t];return e.jsxs("button",{type:"button",role:"checkbox","aria-checked":h,"data-testid":`key-scope-${t}`,onClick:()=>_e(Ue=>({...Ue,[t]:!Ue[t]})),className:`flex w-full items-start gap-2.5 rounded-[10px] p-3 text-left transition-colors ${h?"border-[1.5px] border-oxford bg-oxford-light":"border border-border bg-white hover:bg-accent/50"}`,children:[e.jsx("span",{"aria-hidden":"true",className:`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-[4px] border-[1.5px] ${h?"border-oxford bg-oxford":"border-gray-300"}`,children:h&&e.jsx(ct,{size:11,className:"text-white"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-semibold leading-tight text-navy-deep",children:r.title}),r.chip&&e.jsx("span",{className:"inline-flex shrink-0 items-center rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-600",children:r.chip})]}),e.jsx("span",{className:`mt-0.5 block text-[13px] leading-snug ${r.spendsMoney?"font-medium text-navy-deep":"text-muted-foreground"}`,children:r.body})]})]},t)})}),e.jsx("p",{className:"mt-2 text-[13px] leading-snug text-muted-foreground",children:ks}),X.search&&f.data&&e.jsxs("div",{className:"mt-2 rounded-[10px] border border-border bg-alice-gray px-3 py-2.5",children:[e.jsx("p",{className:"text-[13px] leading-snug text-navy-deep",children:Cs(f.data.ceiling_cents)}),e.jsx("p",{className:"mt-1 text-[13px] leading-snug text-muted-foreground",children:Ss})]})]})]}),e.jsxs(Xe,{className:"mt-2 border-t border-muted pt-4",children:[e.jsx(x,{variant:"ghost",onClick:()=>S(!1),disabled:J,children:"Cancel"}),e.jsx(x,{onClick:St,disabled:J,children:J?"Creating…":e.jsxs(e.Fragment,{children:[e.jsx($,{size:14,className:"mr-1.5"})," Create key"]})})]})]})]});return v&&(v.status==="active"||v.status,v.status,v.status),e.jsxs(de,{title:"Account",variant:"buyer",children:[e.jsx("div",{className:"px-6 py-6 max-w-3xl mx-auto 
35space-y-6",children:e.jsxs(mt,{value:wt,onValueChange:R,children:[e.jsxs(ut,{children:[e.jsx(T,{value:"overview",children:"Overview"}),e.jsx(T,{value:"keys",children:"API keys"}),e.jsx(T,{value:"licenses",children:"Licenses"}),e.jsx(T,{value:"profile",children:"Profile"})]}),e.jsx(D,{value:"overview",className:"mt-6",children:e.jsx(Ht,{activeKeysCount:L.length,sub:v,usageCount:Pe,usageHasMore:Nt,hasOnlyInitialKey:ce,isLegacyProfile:_t,onCompleteProfile:()=>{A(!0),R("profile")},onCreateFirstKey:()=>{R("keys"),S(!0)},onGoLicenses:()=>R("licenses"),onGoBrowse:()=>s("/buyer/browse")})}),e.jsxs(D,{value:"keys",className:"mt-6 space-y-2.5",children:[e.jsx(Yt,{icon:$,label:`API keys · ${L.length} active`,action:Bt}),e.jsx("p",{className:"text-[13px] text-gray-500",children:"Credentials for the content API. Keys are shown once at creation - server-side code only."}),f.data&&L.some(t=>{var r;return(r=t.scopes)==null?void 0:r.includes("search")})&&e.jsx("p",{className:"text-[13px] tabular-nums text-muted-foreground","data-testid":"search-spend-meter",children:Es(f.data.month_to_date_cents,f.data.ceiling_cents)}),m.keys.length===0?e.jsxs("div",{className:"rounded-xl border border-surface-border bg-white text-center py-12",children:[e.jsx($,{size:32,className:"mx-auto text-gray-300 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active keys."}),e.jsxs(x,{onClick:()=>S(!0),className:"mt-4",children:[e.jsx(st,{size:14,className:"mr-1"})," Create your first key"]})]}):e.jsxs("div",{className:"space-y-2.5",children:[L.map(t=>e.jsx(at,{k:t,onRevokeClick:te,onRotateClick:se,isRevoking:Ce&&(_==null?void 0:_.id)===t.id,isRotating:Ee&&(k==null?void 0:k.id)===t.id},t.id)),At.map(t=>e.jsx(at,{k:t,isRevoking:!1},t.id))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{size:13,className:"text-amber-700 shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Rotating a key issues a replacement with the same environment and scopes; the old key stops working immediately."})]}),ce&&e.jsx(zs,{})]}),e.jsxs(D,{value:"licenses",className:"mt-6 space-y-4",children:[e.jsx(ws,{}),e.jsxs("p",{className:"text-xs text-gray-400",children:["Bought a single license by email? Look it up on the"," ",e.jsx(pe,{to:"/licenses",className:"text-oxford hover:underline",children:"public license lookup page"}),"."]})]}),e.jsxs(D,{value:"profile",className:"mt-6",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-5",children:[e.jsx("h2",{className:"text-base font-semibold text-navy-deep",children:"Buyer profile"}),j?e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>{A(!1),M(l.first_name??""),U(l.last_name??""),Q(l.company_name??l.organization??""),H(l.company_website??""),V(l.buyer_type??"ai_retrieval"),W(l.country_of_incorporation??"")},disabled:F,children:[e.jsx(Kt,{size:14,className:"mr-1"})," Cancel"]}),e.jsxs(x,{size:"sm",onClick:Ct,disabled:F,children:[e.jsx(ys,{size:14,className:"mr-1"})," ",F?"Saving…":"Save"]})]}):e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>A(!0),children:[e.jsx(hs,{size:14,className:"mr-1"})," Edit"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"First name"}),j?e.jsx(N,{value:K,onChange:t=>M(t.target.value)}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.first_name||e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Last name"}),j?e.jsx(N,{value:q,onChange:t=>U(t.target.value)}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.last_name||e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Company"}),j?e.jsx(N,{value:Y,onChange:t=>Q(t.target.value),placeholder:"Acme AI Lab"}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:Fe||e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Website"}),j?e.jsx(N,{type:"url",value:B,onChange:t=>H(t.target.value),placeholder:"https://acme.ai"}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.company_website?e.jsx("a",{href:l.company_website,target:"_blank",rel:"noopener noreferrer",className:"text-oxford hover:underline",children:l.company_website}):e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Use case"}),j?e.jsx("select",{value:ge,onChange:t=>V(t.target.value),className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-oxford",children:Zt.map(t=>e.jsx("option",{value:t,children:Je[t]},t))}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.buyer_type?Je[l.buyer_type]:e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Country of incorporation"}),j?e.jsxs("div",{className:"relative",children:[e.jsx(N,{value:be?G:kt,onChange:t=>{Z(t.target.value),P(!0)},onFocus:()=>{Z(""),P(!0)},onBlur:()=>setTimeout(()=>P(!1),150),placeholder:"Type to search…",autoComplete:"off"}),be&&Ie.length>0&&e.jsx("div",{className:"absolute z-10 mt-1 max-h-64 w-full overflow-auto rounded-md border border-border bg-white shadow-lg",children:Ie.map(t=>e.jsxs("button",{type:"button",onMouseDown:r=>{r.preventDefault(),W(t.code),Z(""),P(!1)},className:"block w-full text-left px-3 py-2 text-sm hover:bg-blue-50",children:[e.jsx("span",{className:"font-mono text-gray-400 mr-2",children:t.code}),t.name]},t.code))})]}):e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.country_of_incorporation?`${((qe=tt(l.country_of_incorporation))==null?void 0:qe.name)??l.country_of_incorporation} (${l.country_of_incorporation})`:e.jsx("span",{className:"text-gray-400 italic",children:"Not set"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Contact email"}),e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-1",children:l.contact_email})]}),e.jsxs("div",{children:[e.jsx(y,{className:"text-xs text-muted-foreground",children:"Account created"}),e.jsx("p",{className:"text-sm text-gray-900 mt-1",children:new Date(l.created_at).toLocaleDateString()})]})]}),e.jsxs("div",{className:"pt-4 border-t border-muted flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-navy-deep",children:"Buyer name visibility"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Allow publishers whose content you license to see ",Fe||"your company",' as the buyer in their dashboard. When off, they see an anonymized label (e.g. "AI Lab #4") instead.']})]}),e.jsx(Ut,{checked:l.public_attribution_consent,onCheckedChange:async t=>{try{const r=await a();if(!r)throw new Error("Session expired");const{buyer:h}=await et(r,{public_attribution_consent:t});C({...m,buyer:h}),u({title:t?"Publishers can now see your company name":"Publishers now see an anonymized label"})}catch(r){u({title:"Couldn't save",description:r instanceof Error?r.message:"Try again.",variant:"destructive"})}},"aria-label":"Buyer name visibility","data-testid":"public-attribution-toggle",className:"mt-0.5 shrink-0"})]})]})]}),e.jsxs("div",{className:"mt-8 border-t border-dashed border-gray-300 pt-5",children:[e.jsx("p",{className:"mb-2.5 text-xs font-semibold uppercase tracking-[0.12em] text-red-600",children:"Danger zone"}),e.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50/50 p-5 flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-red-600",children:"Delete account"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed max-w-[58ch]",children:"Permanently delete your buyer account, API keys, and subscription state. License records are retained for publisher compliance; personal information is anonymized. This cannot be undone."})]}),e.jsx(x,{variant:"outline",size:"sm",onClick:()=>ie(!0),className:"shrink-0 border-red-300 text-red-600 hover:bg-red-50 hover:text-red-700",children:"Delete my account"})]})]})]})]})}),e.jsx(ss,{fullKey:(w==null?void 0:w.key)??null,environment:(w==null?void 0:w.environment)??"live",onClose:()=>ee(null)}),e.jsx(As,{k:_,onConfirm:Et,onCancel:()=>te(null),isLoading:Ce}),e.jsx(Bs,{k,onConfirm:Tt,onCancel:()=>se(null),isLoading:Ee}),e.jsx(He,{open:vt,onOpenChange:ie,children:e.jsxs(Ve,{className:"bg-white max-w-[420px] rounded-2xl border border-border/80 p-6 shadow-sm",children:[e.jsxs(We,{children:[e.jsxs(Ge,{className:"text-lg font-semibold text-navy-deep flex items-center gap-2",children:[e.jsx(ps,{className:"h-5 w-5 text-red-500"}),"Delete account"]}),e.jsxs(Ze,{className:"text-sm text-muted-foreground mt-2 leading-relaxed",children:["This will permanently delete your buyer account, API keys, and filtered-subscription state. Financial records are retained for legal compliance but all personal information will be anonymized."," ",e.jsx("span",{className:"font-semibold text-gray-900",children:"This action cannot be undone."})]})]}),e.jsxs("div",{className:"space-y-2 my-4",children:[e.jsxs("label",{htmlFor:"delete-confirm",className:"text-xs font-medium text-muted-foreground",children:["Type ",e.jsx("span",{className:"font-mono font-semibold text-gray-900",children:"DELETE"})," to confirm"]}),e.jsx(N,{id:"delete-confirm",value:De,onChange:t=>Ae(t.target.value),placeholder:"DELETE",className:"font-mono text-sm h-10"})]}),e.jsxs(Xe,{className:"flex-row justify-end gap-2",children:[e.jsx(x,{variant:"outline",onClick:()=>{ie(!1),Ae("")},disabled:oe,children:"Cancel"}),e.jsx(x,{disabled:De!=="DELETE"||oe,onClick:Dt,className:"bg-red-600 hover:bg-red-700 text-white",children:oe?e.jsxs(e.Fragment,{children:[e.jsx(me,{size:"sm",className:"mr-2"}),"Deleting…"]}):"Delete my account"})]})]})})]})}export{wa 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.