@package-broker/dist 2.0.0-rc.3 → 2.0.0-rc.5

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.
Files changed (60) hide show
  1. package/README.md +8 -0
  2. package/node/assets/access.def9a17dc4a8.js +1 -0
  3. package/node/assets/app.ec678c27ec0a.css +2 -0
  4. package/node/assets/{app.e8434f3343de.js → app.fba0d059b40b.js} +5 -5
  5. package/node/assets/audit.453367b59daf.js +1 -0
  6. package/node/assets/chunk.2c3648a5bad1.js +1 -0
  7. package/node/assets/{chunk.bf48b04e6a00.js → chunk.304a2b5d1663.js} +1 -1
  8. package/node/assets/{chunk.f922af39a279.js → chunk.3f077ff17cea.js} +1 -1
  9. package/node/assets/chunk.4721d4544d48.js +1 -0
  10. package/node/assets/{chunk.bb25fc845269.js → chunk.4acf8fa7653f.js} +1 -1
  11. package/node/assets/{chunk.3704953b4a66.js → chunk.53134c7df4e5.js} +1 -1
  12. package/node/assets/{chunk.862544cf5835.js → chunk.56e058d97e0f.js} +1 -1
  13. package/node/assets/chunk.675b635d9462.js +1 -0
  14. package/node/assets/chunk.75e1357175af.js +1 -0
  15. package/node/assets/chunk.815f9a91c741.js +1 -0
  16. package/node/assets/chunk.837eb41f53ef.js +1 -0
  17. package/node/assets/{chunk.7cb6f6b4daaa.js → chunk.ab1a14143dc6.js} +1 -1
  18. package/node/assets/{chunk.ce96495b8b55.js → chunk.dc41ee9219cf.js} +1 -1
  19. package/node/assets/chunk.e3b0c44298fc.js +0 -0
  20. package/node/assets/chunk.f0fd799728ef.js +1 -0
  21. package/node/assets/chunk.fac952720b72.js +4 -0
  22. package/node/assets/import.4275bbce08ac.js +1 -0
  23. package/node/assets/index.html +9 -6
  24. package/node/assets/manifest.json +66 -38
  25. package/node/assets/notifications.bd7d4c3f9882.js +1 -0
  26. package/node/assets/npm-login.d8b60e11fe87.js +1 -0
  27. package/node/assets/packages.bdd474bcfc11.js +2 -0
  28. package/node/assets/projects.44006a838c67.js +1 -0
  29. package/node/assets/setup.7bc86366227c.js +1 -0
  30. package/node/assets/setup.html +2 -2
  31. package/node/assets/sources.d95aabfbec73.js +1 -0
  32. package/node/assets/tokens.4ee13a722abb.js +4 -0
  33. package/node/assets.json +2 -2
  34. package/node/build-info.json +4 -4
  35. package/node/generated/manifest.json +59 -2
  36. package/node/migrations/core/0002_npm_publish.sql +88 -0
  37. package/node/migrations/core/0003_npm_identity.sql +96 -0
  38. package/node/migrations/core/0004_source_revision.sql +1 -0
  39. package/node/migrations/core/0005_package_settings_revision.sql +1 -0
  40. package/node/migrations/core/0006_npm_login_handoff.sql +39 -0
  41. package/node/migrations/core/0007_npm_vcs_build_outcomes.sql +10 -0
  42. package/node/migrations/core/0008_registry_policy.sql +49 -0
  43. package/node/migrations/core/0009_npm_notifications.sql +108 -0
  44. package/node/migrations/core/0010_source_discovery_rules.sql +48 -0
  45. package/node/server.js +56802 -36023
  46. package/package.json +1 -1
  47. package/prebuilt.json +48 -32
  48. package/node/assets/access.6859f43998ca.js +0 -1
  49. package/node/assets/app.f15f8f21f88b.css +0 -2
  50. package/node/assets/audit.576009342714.js +0 -1
  51. package/node/assets/chunk.297a2d571f9c.js +0 -4
  52. package/node/assets/chunk.6e23a75a1324.js +0 -1
  53. package/node/assets/chunk.855a50f45830.js +0 -1
  54. package/node/assets/chunk.976a2ff4338e.js +0 -1
  55. package/node/assets/import.e2a1e35fcb8d.js +0 -1
  56. package/node/assets/packages.a8726e5144de.js +0 -1
  57. package/node/assets/projects.711deb86b7c9.js +0 -1
  58. package/node/assets/setup.dfed30ecfbad.js +0 -1
  59. package/node/assets/sources.d0ba0048bd96.js +0 -1
  60. package/node/assets/tokens.f48d235e8d25.js +0 -4
@@ -0,0 +1,4 @@
1
+ import{a as Je}from"./chunk.675b635d9462.js";import{e as Se}from"./chunk.4acf8fa7653f.js";import{b as nt}from"./chunk.53134c7df4e5.js";import{a as we,b as rt}from"./chunk.2c3648a5bad1.js";import{b as tt}from"./chunk.f0fd799728ef.js";import{a as ke}from"./chunk.304a2b5d1663.js";import{a as et,b as je,c as ae}from"./chunk.56e058d97e0f.js";import{a as ge}from"./chunk.dc41ee9219cf.js";import{a as Q}from"./chunk.3f077ff17cea.js";import{A as le,B as X,C as J,D as te,E as $,F as L,K as Ze,c as U,d as De,g as ee,j as Qe,p as N,q as Ae,r as Ie,s as Le,t as Te,x as Y,y as W,z as re}from"./chunk.837eb41f53ef.js";var A=U(De(),1);function at(t){return`${t.sourceNames.join(", ")}${t.sourceCount>t.sourceNames.length?` and ${t.sourceCount-t.sourceNames.length} more sources`:""} \xB7 Installation ${t.installationId}`}var it="Use * for any name or ? for one character. The default * includes all names.",ot="Enter a repository name pattern of 1 to 100 letters, numbers, dots, underscores, hyphens, * or ?.";function st(t){return/^[A-Za-z0-9._*?-]{1,100}$/.test(t||"*")}var Dt={fork:"Fork \u2014 Enable Include forks to consider this repository.",archived:"Archived \u2014 Archived repositories are not imported.",no_manifest:"No package manifest \u2014 Add a manifest for this ecosystem before importing.",invalid_name:"Invalid package name \u2014 Correct the manifest name before importing.",name_public:"Public package name \u2014 Choose a private name before importing.",name_public_unverified:"Name could not be verified \u2014 Try again when the public registry is available.",claim_overlap:"Name claimed by another source \u2014 Resolve the source conflict before importing.",filtered_out:"Outside the name pattern \u2014 Change the pattern to include this repository.",error_451:"Repository legally unavailable (451) \u2014 This repository cannot be imported.",error_404:"Repository unavailable (404) \u2014 Check the connection has access before trying again.",unsupported_ecosystem:"Unsupported ecosystem \u2014 This repository has no Composer or npm package to import."};function lt(t){return Dt[t??""]??"Import refused \u2014 Review the repository settings before trying again."}var me=new WeakMap;function Qt(t,e){me.set(t,{id:null,revision:null,options:{name:"",enabled:!0,intervalSeconds:86400,...e}})}function fe(t){return t.status===412?"This rule changed while you were editing. The newer rule is shown. Review the latest settings before saving.":t.status===404?"This discovery rule is no longer available. Reload the rules.":t.code==="duplicate"?"A discovery rule with this name already exists. Choose another name.":t.code==="reauth_required"?"Sign in again, then confirm the discovery rule settings.":t.status===429?"GitHub is rate limiting requests. Try again later.":t.status===409&&t.code==="discovery_rule_disabled"?"Enable this rule before requesting a scan.":t.status===409?"The rule conflicts with its current state. Reload and try again.":t.status===403?"You do not have permission to change discovery rules.":"Discovery rules could not be updated. Check the settings and try again."}function qe(t,e=0){return t!=="disabled"&&t!=="discovery_failed"?`Finished with ${e} failed repositories`:t==="disabled"?"The rule was disabled before the scan finished.":"The scan could not finish. Check the GitHub connection and try again."}function ct(t){return t.enabled?"outcome"in t?t.outcome==="running"?"Running":t.outcome==="rate_limited"?"Waiting for GitHub rate limit":t.outcome==="failed"?qe(t.failureReason,t.failed):"Waiting for the next scheduled scan":"Current run information is available to source managers.":"Disabled"}function dt(t){if(t%86400===0)return t===86400?"Every day":`Every ${t/86400} days`;if(t%3600===0)return t===3600?"Every hour":`Every ${t/3600} hours`;let e=Math.floor(t/3600),r=Math.floor(t%3600/60);return`Every ${e?`${e} ${e===1?"hour":"hours"} and `:""}${r} ${r===1?"minute":"minutes"}`}function ut(t){let e=me.get(t),r={visible:!1,manager:!1,loading:!0,busy:!1,reauthPending:e?.reauthPending??!1,items:[],next:null,connections:[],connectionsError:!1,draft:e?.options??null,editing:e?.id??null,revision:e?.revision??null,stale:!1,error:null,notice:null,patternError:null},s=0,o=new Set,p=n=>{r={...r,...n},o.forEach(d=>d())},l=()=>{r.draft?me.set(t,{options:r.draft,id:r.editing,revision:r.revision,reauthPending:r.reauthPending}):me.delete(t)};async function m(n=!1,d=!0){if(r.busy||n&&!r.next)return;let C=++s;p({loading:!0,error:null,...d?{notice:"Loading discovery rules\u2026"}:{}});let S=await t.client.request("get","/_pb/me/permissions");if(C!==s)return;let k=S.ok&&S.data.organization.includes("org:sources:write"),E=k||S.ok&&S.data.organization.includes("org:sources:read");if(p({manager:k,visible:E}),!E){p({loading:!1,items:[],draft:null,error:S.ok?null:"Discovery rule permissions could not be loaded. Try again."});return}let[T,V]=await Promise.all([t.client.request("get","/_pb/sources/discovery/rules",n?{query:{after:r.next}}:{}),k?t.client.request("get","/_pb/sources/discovery/connections"):null]);C===s&&p({loading:!1,...d?{notice:null}:{},connections:V?.ok?V.data.items:[],connectionsError:k&&!V?.ok,...T.ok?{items:n?[...new Map([...r.items,...T.data.items].map(z=>[z.id,z])).values()]:T.data.items,next:T.data.next}:{error:"Discovery rules could not be loaded. Try again."}})}async function w(n,d,C="The scan restarts."){if(p({error:fe(n)}),n.code==="reauth_required"&&(p({reauthPending:!0}),l(),t.requireReauth(n.request,{credential:!1,secretFields:[],display:{label:`Change discovery rule ${d?.name??r.draft?.name??"New rule"}`,effect:C,scope:"Organization sources"}})),n.status===412&&d){p({stale:r.editing===d.id&&r.draft!==null});let S=s,k=await t.client.request("get","/_pb/sources/discovery/rules/{id}",{params:{id:d.id}});if(S!==s)return;k.ok?p({items:r.items.some(E=>E.id===d.id)?r.items.map(E=>E.id===d.id?k.data:E):[...r.items,k.data]}):p({error:fe(k)})}}async function y(n,d,C,S="The scan restarts."){if(!r.manager||r.busy||r.reauthPending||r.loading||r.stale)return;p({busy:!0,error:null,notice:null});let k=await n();return k.ok||await w(k,C,S),p({busy:!1}),k.ok&&(await m(!1,!1),p({notice:d})),!k.ok&&k.status===404&&(await m(!1,!1),p({error:fe(k)})),k.ok}let b=(n,d)=>{if(!r.manager||r.busy||r.reauthPending||r.loading||r.draft)return;let C=r.connections[0],S=n?{name:n.name,pattern:n.pattern,ecosystem:n.ecosystem,includeForks:n.includeForks,enabled:n.enabled,intervalSeconds:n.intervalSeconds,credentialId:"credentialId"in n?n.credentialId:"",installationId:"installationId"in n?n.installationId:0}:{name:"",credentialId:C?.credentialId??"",installationId:C?.installationId??0,ecosystem:"both",pattern:"*",includeForks:!1,intervalSeconds:86400,enabled:!0,...d};p({draft:S,editing:n?.id??null,revision:n?.revision??null,stale:!1,error:null,patternError:null}),l()};return{snapshot:()=>r,subscribe(n){return o.add(n),()=>{o.delete(n)}},load:m,dispose(){s++},edit:b,configure(n){r.busy||r.reauthPending||!r.draft||(p({draft:{...r.draft,...n},patternError:null}),l())},close(){r.busy||r.reauthPending||(p({draft:null,editing:null,stale:!1,error:null}),l())},reviewLatest(){let n=r.items.find(d=>d.id===r.editing);n?(p({draft:null}),b(n)):p({stale:!1})},async save(){if(!r.manager||!r.draft||r.stale||r.busy||r.reauthPending)return;let n={...r.draft,name:r.draft.name.trim(),pattern:r.draft.pattern||"*"};if(!st(n.pattern)){p({patternError:ot});return}let d=r.items.find(E=>E.id===r.editing),C=d&&"credentialId"in d&&d.credentialId===n.credentialId&&d.installationId===n.installationId;if(!Number.isInteger(n.intervalSeconds/3600)||n.intervalSeconds<3600||n.intervalSeconds>2592e3){p({error:"Enter a whole number of hours from 1 to 720."});return}if(!n.name||n.name.length>80||!C&&!r.connections.some(E=>E.credentialId===n.credentialId&&E.installationId===n.installationId)){p({error:"Enter a name of up to 80 characters and choose an available GitHub connection."});return}let S={...n};d&&"credentialId"in d&&d.credentialId===n.credentialId&&d.installationId===n.installationId&&(delete S.credentialId,delete S.installationId),await y(()=>r.editing===null?t.client.request("post","/_pb/sources/discovery/rules",{body:n,idempotencyKey:crypto.randomUUID()}):t.client.request("patch","/_pb/sources/discovery/rules/{id}",{params:{id:r.editing},headers:{"If-Match":Se(r.revision)},body:S}),"Discovery rule saved.",d??(r.editing?{id:r.editing,name:n.name}:void 0),!d||!C||d.ecosystem!==n.ecosystem||d.pattern!==n.pattern||d.includeForks!==n.includeForks?"The scan restarts. Imported sources stay.":"Save the settings. The scan keeps its progress.")&&(p({draft:null,editing:null}),l())},run:n=>n.enabled?y(()=>t.client.request("post","/_pb/sources/discovery/rules/{id}/run",{params:{id:n.id},body:{},idempotencyKey:crypto.randomUUID()}),"Scan requested. It will start on a scheduler tick when GitHub is available.",n,"Request a scan on the next scheduler tick."):Promise.resolve(!1),toggle:n=>y(()=>t.client.request("patch","/_pb/sources/discovery/rules/{id}",{params:{id:n.id},headers:{"If-Match":Se(n.revision)},body:{enabled:!n.enabled}}),"Discovery rule updated.",n,n.enabled?"Scheduled scans stop.":"Scheduled scans resume."),remove:async n=>{let d=r.items.find(C=>C.id===n.id);return d?y(()=>t.client.request("delete","/_pb/sources/discovery/rules/{id}",{params:{id:d.id},headers:{"If-Match":Se(d.revision)}}),"Discovery rule deleted. Imported sources stay.",d,"Scheduled scans stop. Imported sources stay."):(await m(!1,!1),p({error:fe({status:404})}),!1)},async replayed(n){if(p({reauthPending:!1}),l(),!n.ok&&n.cancelled){p({error:null,notice:"Discovery rule was not sent. Review the settings before trying again."});return}n.ok&&(p({draft:null,editing:null}),l());let d=m(!1,!1),C=s;if(await d,C===s&&(n.ok&&p({notice:"Discovery rule saved."}),!n.ok&&(p({error:fe(n),stale:n.status===412&&r.draft!==null}),n.status===412&&r.editing))){let S=s,k=r.editing,E=await t.client.request("get","/_pb/sources/discovery/rules/{id}",{params:{id:r.editing}});if(S!==s||k!==r.editing)return;E.ok&&p({items:r.items.some(T=>T.id===r.editing)?r.items.map(T=>T.id===r.editing?E.data:T):[...r.items,E.data]})}}}}var c=U(ee(),1);function pt({value:t}){if(!t)return(0,c.jsx)(c.Fragment,{children:"Not yet"});let e=new Date(t);return Number.isNaN(e.valueOf())?(0,c.jsx)(c.Fragment,{children:"Time unavailable"}):(0,c.jsxs)("time",{dateTime:t,children:[e.toLocaleString()," (",Intl.DateTimeFormat().resolvedOptions().timeZone,")"]})}function At({rule:t}){let e=t.completed;return(0,c.jsxs)("div",{className:"space-y-2",children:[(0,c.jsx)("h4",{className:"font-semibold",children:"Last completed run"}),e?.lastRunAt?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("p",{children:(0,c.jsx)(pt,{value:e.lastRunAt})}),(0,c.jsxs)("p",{children:[e.created," created \xB7 ",e.existing," existing \xB7 ",e.skipped," ","skipped \xB7 ",e.failed," failed"]}),(0,c.jsxs)("details",{children:[(0,c.jsx)("summary",{className:"min-h-11 cursor-pointer",children:"Last-run details"}),e.outcome==="failed"?(0,c.jsx)("p",{children:qe(e.failureReason,e.failed)}):null,e.skips.length?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)("h4",{className:"font-semibold",children:"Skipped repositories"}),(0,c.jsx)("ul",{children:e.skips.map((r,s)=>(0,c.jsxs)("li",{className:"break-words",children:[r.repository,": ",lt(r.reason)]},s))}),(0,c.jsx)("p",{children:"Up to 50 skipped repositories are retained."})]}):(0,c.jsx)("p",{children:"No retained skip details."}),e.failed>0?(0,c.jsx)("p",{children:"Repository failure details are not retained for completed runs. Check the connection and run the rule again."}):null]})]}):(0,c.jsx)("p",{children:"No completed run yet."})]})}function It({model:t}){let e=(0,A.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),r=e.draft,s=e.items.find(b=>b.id===e.editing),o=s&&(s.ecosystem!==r.ecosystem||s.pattern!==r.pattern||s.includeForks!==r.includeForks||"credentialId"in s&&(s.credentialId!==r.credentialId||s.installationId!==r.installationId)),p=(0,A.useRef)(null),l=(0,A.useRef)(null);(0,A.useEffect)(()=>{l.current?.focus()},[]),(0,A.useEffect)(()=>{e.patternError&&p.current?.focus()},[e.patternError]);let m=s&&"credentialId"in s&&s.credentialId===r.credentialId&&s.installationId===r.installationId,w=e.busy||e.reauthPending,y=e.connections.findIndex(b=>b.credentialId===r.credentialId&&b.installationId===r.installationId);return(0,c.jsxs)("form",{className:"grid max-w-5xl items-start gap-x-6 gap-y-4 rounded border p-4 lg:grid-cols-2","aria-label":e.editing?"Edit discovery rule":"New discovery rule","aria-busy":w,onSubmit:b=>{b.preventDefault(),t.save()},children:[(0,c.jsxs)("p",{className:"lg:col-span-2",children:[e.editing?"Edit discovery rule":"New discovery rule"," \xB7 Organization sources. Matching repositories become shared sources. Projects attach these sources to use their packages."]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(L,{htmlFor:"rule-name",children:"Name (required)"}),(0,c.jsx)($,{id:"rule-name",ref:l,className:"min-h-11",required:!0,maxLength:80,value:r.name,disabled:w,onChange:b=>t.configure({name:b.target.value})})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(L,{htmlFor:"rule-connection",children:"GitHub connection (required)"}),(0,c.jsxs)(Q,{id:"rule-connection",className:"min-h-11 max-w-full",disabled:w||!e.connections.length,value:y<0?"":String(y),onChange:b=>{let n=e.connections[Number(b.target.value)];n&&t.configure({credentialId:n.credentialId,installationId:n.installationId})},children:[(0,c.jsx)("option",{value:"",disabled:!0,children:m?"Current connection (no longer used by any source)":"Choose a connection"}),e.connections.map((b,n)=>(0,c.jsx)("option",{value:String(n),children:at(b)},n))]}),y<0&&!m?(0,c.jsx)("p",{children:"The saved connection is unavailable. Choose an available GitHub connection."}):null]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(L,{htmlFor:"rule-ecosystem",children:"Package ecosystem"}),(0,c.jsxs)(Q,{id:"rule-ecosystem",className:"min-h-11",disabled:w,value:r.ecosystem,onChange:b=>t.configure({ecosystem:b.target.value}),children:[(0,c.jsx)("option",{value:"npm",children:"npm"}),(0,c.jsx)("option",{value:"composer",children:"Composer"}),(0,c.jsx)("option",{value:"both",children:"Composer and npm"})]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(L,{htmlFor:"rule-pattern",children:"Repository name pattern (optional)"}),(0,c.jsx)($,{id:"rule-pattern",ref:p,className:"min-h-11",maxLength:100,value:r.pattern,disabled:w,"aria-invalid":!!e.patternError,"aria-describedby":`rule-pattern-help${e.patternError?" rule-pattern-error":""}`,onChange:b=>t.configure({pattern:b.target.value})}),(0,c.jsx)("p",{id:"rule-pattern-help",children:it}),e.patternError?(0,c.jsx)("p",{id:"rule-pattern-error",role:"alert",children:e.patternError}):null]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(L,{htmlFor:"rule-interval",children:"Scan interval in hours (required)"}),(0,c.jsx)($,{id:"rule-interval",className:"min-h-11",type:"number",required:!0,min:1,max:720,step:1,value:(r.intervalSeconds??86400)/3600,disabled:w,"aria-describedby":"rule-interval-help",onChange:b=>t.configure({intervalSeconds:Math.round(Number(b.target.value)*3600)})}),(0,c.jsx)("p",{id:"rule-interval-help",children:"From one hour to 30 days. GitHub limits may delay a scan."})]}),(0,c.jsxs)("fieldset",{children:[(0,c.jsx)("legend",{children:"Scan settings"}),(0,c.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,c.jsx)("input",{type:"checkbox",checked:r.includeForks??!1,disabled:w,onChange:b=>t.configure({includeForks:b.target.checked})}),"Include forks"]}),(0,c.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,c.jsx)("input",{type:"checkbox",checked:r.enabled??!0,disabled:w,onChange:b=>t.configure({enabled:b.target.checked})}),"Enabled"]})]}),o?(0,c.jsx)("p",{className:"lg:col-span-2",children:"Changing the connection, ecosystem, pattern or forks restarts the scan. Imported sources stay."}):null,e.stale?(0,c.jsxs)("div",{className:"lg:col-span-2",children:[(0,c.jsx)("p",{children:"Your draft is retained above. The newer rule is shown in the list below."}),(0,c.jsx)(N,{type:"button",className:"min-h-11",onClick:()=>t.reviewLatest(),children:"Use latest settings and review"})]}):null,(0,c.jsxs)("div",{className:"flex flex-wrap gap-2 lg:col-span-2",children:[(0,c.jsx)(N,{type:"submit",className:"min-h-11 w-full sm:w-auto",disabled:w||e.loading||e.stale||y<0&&!m,children:e.busy?"Saving rule\u2026":"Save rule"}),(0,c.jsx)(N,{type:"button",variant:"outline",className:"min-h-11 w-full sm:w-auto",disabled:w,onClick:()=>t.close(),children:"Cancel"})]})]})}function gt({services:t}){let e=(0,A.useMemo)(()=>ut(t),[t]);return(0,A.useEffect)(()=>{e.load().then(()=>{new URLSearchParams(window.location.hash.split("?")[1]).get("discovery")==="new"&&!e.snapshot().draft&&e.edit()});let r=t.subscribeReplay?.(s=>{s.path.startsWith("/_pb/sources/discovery/rules")&&e.replayed(s)});return()=>{r?.(),e.dispose()}},[e,t]),(0,c.jsx)(Lt,{model:e})}function Lt({model:t}){let e=(0,A.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),[r,s]=(0,A.useState)(null),o=(0,A.useRef)(null),p=(0,A.useRef)(null),l=(0,A.useRef)(!1);return(0,A.useEffect)(()=>{e.notice&&!e.loading&&!e.draft&&p.current?.focus()},[e.notice,e.loading,e.draft]),(0,A.useEffect)(()=>{r||!l.current||(l.current=!1,o.current?.focus())},[r]),!e.visible&&!e.loading&&!e.error?null:(0,c.jsxs)("section",{"aria-labelledby":"discovery-rules-heading",className:"mt-8 grid min-w-0 gap-4",children:[(0,c.jsx)("h2",{ref:o,tabIndex:-1,id:"discovery-rules-heading",className:"text-lg font-semibold",children:"Discovery rules"}),(0,c.jsx)("p",{children:"Organization rules keep matching GitHub repositories available as shared sources. Existing sources are counted, never duplicated. Deleting a rule leaves imported sources in place."}),(0,c.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,c.jsx)(N,{className:"min-h-11",variant:"outline",disabled:e.loading||e.busy,onClick:()=>{t.load()},children:"Reload rules"}),e.manager?(0,c.jsx)(N,{className:"min-h-11",disabled:e.loading||e.busy||!!e.draft,onClick:()=>t.edit(),children:"Create discovery rule"}):null]}),(0,c.jsx)("p",{role:"status","aria-live":"polite",ref:p,tabIndex:-1,children:e.notice}),e.error&&!r?(0,c.jsx)("p",{role:"alert",children:e.error}):null,e.connectionsError?(0,c.jsx)("p",{children:"GitHub connections could not be loaded. Reload rules to try again."}):e.manager&&!e.loading&&!e.connections.length?(0,c.jsxs)("p",{children:["No GitHub App connections yet. Add an organization GitHub source with GitHub App authentication first."," ",(0,c.jsx)("a",{className:"underline",href:"#/sources?create=vcs&provider=github",children:"Add a GitHub source"})]}):null,e.draft&&e.manager?(0,c.jsx)(It,{model:t}):null,!e.loading&&!e.items.length&&!e.error?(0,c.jsx)("p",{children:"No discovery rules yet."}):null,(0,c.jsx)("ul",{className:"grid min-w-0 gap-4",children:e.items.map(m=>(0,c.jsxs)("li",{className:"min-w-0 space-y-2 rounded border p-4",children:[(0,c.jsx)("h3",{className:"break-words font-semibold",children:m.name}),(0,c.jsxs)("dl",{className:"grid gap-2 sm:grid-cols-2",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"Ecosystem"}),(0,c.jsx)("dd",{children:m.ecosystem==="both"?"Composer and npm":m.ecosystem==="composer"?"Composer":"npm"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"Repository pattern"}),(0,c.jsx)("dd",{className:"break-words",children:m.pattern})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"Forks"}),(0,c.jsx)("dd",{children:m.includeForks?"Included":"Excluded"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"Schedule"}),(0,c.jsx)("dd",{children:dt(m.intervalSeconds)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"Enabled"}),(0,c.jsx)("dd",{children:m.enabled?"Enabled":"Disabled"})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)("dt",{children:"State"}),(0,c.jsxs)("dd",{children:[m.enabled?ct(m):"Scheduled scans stopped","outcome"in m&&m.outcome==="rate_limited"?(0,c.jsxs)(c.Fragment,{children:[" ","until ",(0,c.jsx)(pt,{value:m.nextRunAt})]}):null]})]})]}),(0,c.jsx)(At,{rule:m}),e.manager&&"created"in m?(0,c.jsxs)("p",{children:["Current run: ",m.created," created \xB7 ",m.existing," existing \xB7 ",m.skipped," ","skipped \xB7 ",m.failed," failed \xB7 ",m.remaining.length," repositories remaining in the current page",m.cursor?"; more pages to scan":"","."]}):null,e.manager?(0,c.jsx)(we,{entityLabel:m.name,actions:[{id:"run",label:"Run now",disabled:e.busy||e.reauthPending||e.loading||e.stale||!m.enabled,onSelect:()=>{t.run(m)}}],overflow:[{id:"edit",label:"Edit",disabled:e.busy||e.reauthPending||e.loading||!!e.draft,onSelect:()=>t.edit(m)},{id:"toggle",label:m.enabled?"Disable":"Enable",disabled:e.busy||e.reauthPending||e.loading||e.stale,onSelect:()=>{t.toggle(m)}},{id:"delete",label:"Delete",variant:"destructive",disabled:e.busy||e.reauthPending||e.loading||e.stale,onSelect:()=>s(m)}]}):null,e.manager&&!m.enabled?(0,c.jsx)("p",{children:"Enable this rule before requesting a scan."}):null]},m.id))}),e.next?(0,c.jsx)(N,{className:"min-h-11",disabled:e.loading||e.busy,onClick:()=>{t.load(!0)},children:"Load more rules"}):null,(0,c.jsx)(Y,{open:r!==null,onOpenChange:m=>{!m&&!e.busy&&s(null)},children:(0,c.jsxs)(W,{children:[(0,c.jsx)(X,{children:"Delete discovery rule"}),(0,c.jsxs)(J,{children:["Remove the rule ",r?.name," in this organization? Scheduled scans stop. Imported sources stay. This cannot be undone."]}),e.error&&r?(0,c.jsx)("p",{role:"alert",children:e.error}):null,(0,c.jsxs)(le,{children:[(0,c.jsx)(N,{className:"min-h-11",variant:"outline",disabled:e.busy,onClick:()=>s(null),children:"Cancel"}),(0,c.jsx)(N,{className:"min-h-11",variant:"destructive",disabled:e.busy,onClick:()=>{r&&t.remove(r).then(m=>{m&&(l.current=!0,s(null))})},children:e.busy?"Deleting rule\u2026":(0,c.jsx)(c.Fragment,{children:"Delete rule"})})]})]})})]})}var Oe="Sync requested. Waiting for a worker. Sync continues in the background.";function Fe(t,e,r){return t===200?`${e} is already available from ${r}.`:`${e}: ${Oe}`}function He(t){return t.status===202?{ok:!0,status:202,data:void 0}:t}var mt="For proxy sources, packages appear when a client first requests them.";function Tt(t,e){return t.sync?.generation!==e.sync?.generation||t.status!==e.status||t.lastPolledAt!==e.lastPolledAt||t.lastSuccessAt!==e.lastSuccessAt||t.lastError!==e.lastError}function Me(t,e){return e.sync&&(e.sync.listing||e.sync.queued+e.sync.running+(e.sync.retrying??0)>0)?"pending":Tt(t,e)}function ft(t,e=typeof document>"u"?void 0:document){let r=Date.now()+6e5,s=!1,o=0,p=!1,l=2e3,m,w=setTimeout(()=>y(),6e5),y=()=>{s=!0,clearTimeout(m),clearTimeout(w),e?.removeEventListener("visibilitychange",b)},b=()=>{e?.hidden&&y()},n=()=>{if(s||e?.hidden||Date.now()>=r||!p&&o>=15){y();return}m=setTimeout(()=>{if(s||e?.hidden||Date.now()>=r){y();return}o++,t().then(d=>{d==="pending"?(o=0,p=!0,l=Math.min(l*2,3e4)):(p=!1,l=2e3),d===!0?y():n()},y)},l)};return e?.addEventListener("visibilitychange",b),n(),y}var q=U(ee(),1);function ht({source:t,busy:e,fieldError:r,alert:s,onSubmit:o,onClose:p}){return(0,q.jsx)(Y,{open:!0,onOpenChange:l=>{!l&&!e&&p()},children:(0,q.jsxs)(W,{onCancel:l=>{e&&l.preventDefault()},children:[(0,q.jsxs)(re,{children:[(0,q.jsx)(X,{children:"Add package"}),(0,q.jsxs)(J,{children:["Request a package from ",t.name," for this project."]})]}),(0,q.jsxs)("form",{className:"grid gap-3",onSubmit:l=>{l.preventDefault(),e||o(new FormData(l.currentTarget).get("name")?.toString()??"")},children:[(0,q.jsx)(L,{htmlFor:"add-package-name",children:"Package name"}),(0,q.jsx)($,{id:"add-package-name",name:"name",required:!0,maxLength:428,placeholder:t.ecosystem==="composer"?"vendor/package":"@scope/package",disabled:e,"aria-invalid":r?!0:void 0,"aria-describedby":r?"add-package-error":void 0}),r?(0,q.jsx)("p",{id:"add-package-error",role:"alert",children:r}):null,s?(0,q.jsx)("p",{role:"alert",children:s}):null,(0,q.jsxs)(le,{children:[(0,q.jsx)(N,{type:"button",variant:"outline",disabled:e,onClick:p,children:"Cancel"}),(0,q.jsx)(N,{type:"submit",disabled:e,children:e?"Requesting\u2026":"Add package"})]})]})]})})}var O=U(De(),1);var B=U(De(),1);var g=U(ee(),1),bt={github:"GitHub",git:"Git over HTTP(S)",ssh:"Git over SSH"},jt=["github"];function qt(t){return Object.keys(bt).filter(e=>t.includes(e)).map(e=>[e,bt[e]])}var yt={composer:["packagist_proxy","composer_repository","vcs"],npm:["npmjs_proxy","npm_registry","hosted","vcs"]},ze={packagist_proxy:"https://repo.packagist.org",npmjs_proxy:"https://registry.npmjs.org"},Z={packagist_proxy:"Packagist proxy",composer_repository:"Composer repository",vcs:"Git repository",npmjs_proxy:"npmjs proxy",npm_registry:"Private npm registry",hosted:"Hosted repository"},Ot={packagist_proxy:"Fetch public Composer packages on demand.",composer_repository:"Import selected packages from Satis, Private Packagist, or another Composer repository.",vcs:"Import a Composer or npm package from the root of a GitHub or Git repository.",npmjs_proxy:"Fetch public npm packages on demand.",npm_registry:"Fetch packages in selected scopes from another npm registry.",hosted:"Reserve private npm package names and publish packages to this broker."},ie={requirePublishApproval:"Require publish approval",name:"Source name",ecosystem:"Ecosystem",type:"Source type",url:"Repository URL",userAgent:"User-Agent override",pollIntervalSeconds:"Sync interval (seconds)",removalPolicy:"When a package disappears upstream",defaultVisibleToNewProjects:"Visible to new projects",retentionDaysOverride:"Archive retention (days)","config/provider":"Repository provider","config/repository":"GitHub repository","config/installationId":"GitHub App installation ID",githubAuthentication:"GitHub authentication","config/packageName":"Package name (optional)","config/refs/branches":"Branches to import","config/refs/tags":"Import tags","config/selection/packages":"Package names (one per line)","config/selection/patterns":"Package patterns (one per line)","config/selection/expandPatterns":"Expand patterns","config/distHosts":"Additional archive hosts","config/mirrorsFallback":"Try repository mirrors if an archive download fails","config/scopes":"Package scopes (one per line)","config/githubToken":"Use GitHub token"},ce={requirePublishApproval:"Choose whether new publishes require approval.",name:"Enter a source name.",ecosystem:"Choose an ecosystem.",type:"Choose a source type.",url:"Enter a valid HTTP or HTTPS URL without credentials, a query, or a fragment.",userAgent:"Enter a valid User-Agent header without line breaks.",pollIntervalSeconds:"Enter a whole number of seconds greater than 0.",removalPolicy:"Choose what happens when a package disappears upstream.",defaultVisibleToNewProjects:"Choose whether this source is visible to new projects.",retentionDaysOverride:"Enter a whole number of days that does not shorten organization retention.","config/provider":"Choose a repository provider this broker supports.","config/repository":"Enter a valid repository for the selected provider: owner/repository for GitHub, or a clone URL for Git.","config/installationId":"Enter a positive whole-number installation ID.",githubAuthentication:"Choose GitHub App or Personal access token.","config/packageName":"Enter a package name matching the source ecosystem.","config/refs/branches":"Enter valid branch names, one per line, without duplicates.","config/refs/tags":"Choose whether to import tags.","config/selection/packages":"Enter valid Composer package names, one per line, without duplicates.","config/selection/patterns":"Enter valid package patterns, such as acme/*, without duplicates.","config/selection/expandPatterns":"Choose whether to expand patterns.","config/distHosts":"Enter hostnames only, one per line, without schemes, paths, or duplicates.","config/mirrorsFallback":"Choose whether to try repository mirrors.","config/scopes":"Enter at least one scope, such as @acme, one per line without duplicates.","config/githubToken":"Save a bearer credential before enabling the GitHub token option."},$e={requirePublishApproval:"New versions wait for approval before installation. Versions already held remain held when this setting is turned off.",pollIntervalSeconds:"How often to check for upstream changes. 300 seconds = 5 minutes.",retentionDaysOverride:"Leave blank to use the organization setting. An override can only lengthen retention.","config/distHosts":"One hostname per line. Archive downloads may come from these hosts; the source credential is also sent to them.","config/selection/packages":"Packages matching either list are selected. Empty lists select no packages.","config/scopes":"One scope per line, including @. Only these scopes use this registry. Register @scope/* for each scope before enabling the source.","config/packageName":"Leave blank to use the root manifest name (composer.json or package.json). For npm, this must match the name in package.json.","config/refs/branches":"One branch name per line. Leave blank to import no branches.","config/installationId":"Enter the numeric installation ID for the account that owns this repository."},Ft={userAgent:"Use broker default",retentionDaysOverride:"Use organization default","config/selection/packages":"acme/payments","config/selection/patterns":"acme/*","config/scopes":"@acme","config/distHosts":"downloads.example.com","config/packageName":"acme/payments","config/refs/branches":"main","config/installationId":"12345678"};function St(t){let e={};for(let r of t){let s=r.path.replace(/^\/body\//,"").replace(/^\//,""),o=Object.keys(ie).find(p=>s===p||s.startsWith(`${p}/`));o&&(e[o]=ce[o]??"Review this setting.")}return e}function Ht(t,e,r,s=null,o=s?Ce(s):null){let p={},l=y=>String(t.get(y)??"").trim(),m=(y,b)=>{let n=Number(l(y));(!l(y)||!Number.isSafeInteger(n)||n<b)&&(p[y]=ce[y]??"Review this setting.")};!r&&!l("name")&&(p.name=ce.name),(e==="composer_repository"||e==="npm_registry")&&(!r||l("url")!==String(o?.get("url")??""))&&!l("url")&&(p.url=ce.url),m("pollIntervalSeconds",1),l("retentionDaysOverride")&&m("retentionDaysOverride",0);let w=!o||Object.keys(ie).some(y=>(y.startsWith("config/")||e==="vcs"&&y==="githubAuthentication")&&String(t.get(y)??"")!==String(o.get(y)??""));return wt(s,t)&&(w||t.has("replaceConfig"))&&(t.has("config/provider")||t.has("config/scopes")||t.has("config/selection/packages")||!r)&&(e==="composer_repository"&&!l("config/selection/packages")&&!l("config/selection/patterns")&&(p["config/selection/packages"]="Add at least one package name or pattern"),e==="npm_registry"&&!l("config/scopes")&&(p["config/scopes"]=ce["config/scopes"]),e==="vcs"&&!l("config/repository")&&(p["config/repository"]=ce["config/repository"]),e==="vcs"&&l("config/provider")==="github"&&l("githubAuthentication")!=="token"&&m("config/installationId",1)),p}function Be(t,e){let r=Number(t);if(!t.trim()||!Number.isSafeInteger(r)||r<e)throw new Error("Enter valid whole numbers for the numeric fields.");return r}function vt(t,e,r,s=!0){let o=w=>String(t.get(w)??""),p=w=>t.has(w),l=w=>o(w).split(/\r?\n/).map(y=>y.trim()).filter(Boolean),m={pollIntervalSeconds:Be(o("pollIntervalSeconds"),1),removalPolicy:o("removalPolicy")};if(e==="hosted"&&(m.requirePublishApproval=p("requirePublishApproval")),m.defaultVisibleToNewProjects=p("defaultVisibleToNewProjects"),m.retentionDaysOverride=o("retentionDaysOverride").trim()===""?null:Be(o("retentionDaysOverride"),0),m.userAgent=o("userAgent")||null,e!=="vcs"&&(m.url=o("url")||null),s&&(!r||t.has("config/provider")||t.has("config/scopes")||t.has("config/selection/packages")||e==="packagist_proxy"||e==="npmjs_proxy"))switch(e){case"vcs":m.config={provider:o("config/provider"),repository:o("config/repository"),...o("config/provider")==="github"&&o("githubAuthentication")!=="token"?{installationId:Be(o("config/installationId"),1)}:{},...o("config/packageName")?{packageName:o("config/packageName")}:{},refs:{branches:l("config/refs/branches"),tags:p("config/refs/tags")}};break;case"composer_repository":m.config={selection:{packages:l("config/selection/packages"),patterns:l("config/selection/patterns"),expandPatterns:p("config/selection/expandPatterns")},distHosts:l("config/distHosts"),mirrorsFallback:p("config/mirrorsFallback")};break;case"npm_registry":m.config={scopes:l("config/scopes"),distHosts:l("config/distHosts")};break;case"packagist_proxy":m.config={githubToken:r&&p("config/githubToken")};break;case"hosted":case"npmjs_proxy":m.config={};break}return m}function wt(t,e){return t===null||t.config!==void 0&&t.configComplete!==!1||e.has("replaceConfig")}function Mt(t,e,r,s,o=s?Ce(s):null){let p=vt(t,r,s!==null,wt(s,t));if(!s)return{name:String(t.get("name")??""),ecosystem:e,type:r,...p};let l=vt(o??Ce(s),r,!0,s.config!==void 0&&s.configComplete!==!1);return Object.fromEntries(Object.entries(p).filter(([m,w])=>JSON.stringify(w)!==JSON.stringify(l[m])))}function xe(t,e){let r=t?.config;for(let s of e.split("/")){if(typeof r!="object"||r===null)return;r=r[s]}return r}function Ce(t){let e=new FormData;for(let r of Object.keys(ie)){let s=r.startsWith("config/")?xe(t,r.slice(7)):t[r];typeof s=="boolean"?s&&e.set(r,"on"):Array.isArray(s)?e.set(r,s.join(`
2
+ `)):s!=null&&e.set(r,String(s))}return(t.type==="packagist_proxy"||t.type==="npmjs_proxy")&&e.set("url",ze[t.type]),e.set("pollIntervalSeconds",String(t.pollIntervalSeconds)),e.set("removalPolicy",t.removalPolicy),e.set("githubAuthentication",t.githubAuthentication??(xe(t,"installationId")?"app":"token")),e}function Ge(t){return[...new Set(t.split(/\r?\n/).map(e=>e.trim()).filter(e=>/^@[a-z0-9][a-z0-9._~-]*$/.test(e)))].map(e=>`${e}/*`)}function kt(t,e){if(!t)return;let r=Array.from(t.elements).find(o=>(o.getAttribute("name")??"")in e);if(!r)return;let s=r.closest("details");s&&(s.open=!0),r.focus()}function xt({source:t,busy:e,errors:r,alert:s,onSubmit:o,onClose:p,vcsProviders:l=jt,initialType:m,initialProvider:w,organization:y=!0}){let[b,n]=(0,B.useState)(t?.ecosystem??(m==="hosted"?"npm":"composer")),[d,C]=(0,B.useState)(t?.type??m??"packagist_proxy"),S=qt(l),k=S[0]?.[0]??"github",[E,T]=(0,B.useState)(xe(t,"provider")??w??k),V=S.some(([h])=>h===E),z=d==="vcs"&&(S.length===0||!V);(0,B.useEffect)(()=>{!t&&!V&&S.length>0&&T(k)},[t,V,S.length,k]);let[H,i]=(0,B.useState)(t?.githubAuthentication??(t?xe(t,"installationId")?"app":"token":"app")),[f,u]=(0,B.useState)(""),v=t?Ce(t):null,x=t!==null&&(t.configComplete===!1||t.config===void 0),[_,I]=(0,B.useState)(!1),[oe,K]=(0,B.useState)({}),G=(0,B.useRef)(null),D={...r,...oe},F=t!==null,R=d==="packagist_proxy"||d==="npmjs_proxy",ye=!z&&(!x||_);(0,B.useEffect)(()=>{kt(G.current,r)},[r]);function se(h){return[$e[h]&&`source-${h}-help`,D[h]&&`source-${h}-error`].filter(Boolean).join(" ")||void 0}function _e(h){return(0,g.jsxs)(g.Fragment,{children:[$e[h]?(0,g.jsx)("p",{id:`source-${h}-help`,className:"text-sm text-neutral-600",children:$e[h]}):null,D[h]?(0,g.jsx)("p",{id:`source-${h}-error`,className:"text-sm text-red-700",children:D[h]}):null]})}function ue(h,P,j=ie[h]){return(0,g.jsxs)("div",{className:"grid gap-1",children:[(0,g.jsx)(L,{htmlFor:`source-${h}`,children:j}),P,_e(h)]},h)}function M(h,P={}){let j={id:`source-${h}`,name:h,required:P.required,defaultValue:P.value??v?.get(h)?.toString(),onChange:h==="config/scopes"?pe=>u(pe.currentTarget.value):void 0,placeholder:P.placeholder??Ft[h],"aria-invalid":!!D[h],"aria-describedby":se(h)};return ue(h,P.multiline?(0,g.jsx)(rt,{...j,rows:3,className:"w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-base sm:text-sm"}):(0,g.jsx)($,{...j,className:"h-11 text-base sm:text-sm",type:P.number?"number":"text",inputMode:P.number?"numeric":void 0,min:P.minimum,max:P.number?Number.MAX_SAFE_INTEGER:void 0,step:P.number?1:void 0,maxLength:h==="url"?2048:void 0}),`${P.label??ie[h]}${P.required?" (required)":""}`)}function ne(h,P=ie[h],j,pe){return(0,g.jsxs)("div",{className:"grid gap-1",children:[(0,g.jsxs)(L,{className:"flex min-h-11 items-center gap-2",htmlFor:`source-${h}`,children:[(0,g.jsx)("input",{type:"checkbox",id:`source-${h}`,name:h,defaultChecked:t?v?.has(h):pe,onChange:j?Re=>j(Re.currentTarget.checked):void 0,"aria-invalid":!!D[h],"aria-describedby":se(h)}),P]}),_e(h)]},h)}function Pe(h,P,j,pe,Re=!1){return(0,g.jsxs)("fieldset",{className:"grid gap-1","aria-describedby":se(h),"aria-invalid":!!D[h],children:[(0,g.jsx)("legend",{className:"text-sm font-medium",children:ie[h]}),(0,g.jsx)("div",{className:Re?"flex gap-4":"grid gap-1",children:j.map(([ve,Rt,Xe])=>(0,g.jsxs)("label",{className:"flex min-h-11 cursor-pointer items-center gap-2 py-1",children:[(0,g.jsx)("input",{type:"radio",name:h,value:ve,checked:P===ve,onChange:()=>pe(ve),"aria-invalid":!!D[h],"aria-describedby":se(h)}),(0,g.jsxs)("span",{children:[(0,g.jsx)("span",{className:"text-sm font-medium",children:Rt}),Xe?(0,g.jsx)("span",{className:"block text-sm text-neutral-600",children:Xe}):null]})]},ve))}),_e(h)]})}let Pt={packagist_proxy:"Packagist",npmjs_proxy:"npmjs",composer_repository:"Acme Composer",npm_registry:"Acme npm",vcs:"Acme payments",hosted:""}[d];return(0,g.jsx)(Y,{open:!0,onOpenChange:h=>{!h&&!e&&p()},children:(0,g.jsxs)(W,{variant:"source",onCancel:h=>{e&&h.preventDefault()},children:[(0,g.jsxs)(re,{className:"shrink-0 p-6 pr-16",children:[(0,g.jsx)(X,{children:F?"Edit source":"Add source"}),(0,g.jsx)(J,{children:F?`${t.name} \xB7 ${b==="composer"?"Composer":"npm"} \xB7 ${Z[d]}. Name, ecosystem and source type cannot be changed.`:"Add an upstream source for this organization or project."})]}),(0,g.jsxs)("form",{noValidate:!0,ref:G,className:"flex min-h-0 min-w-0 flex-1 flex-col",onSubmit:h=>{if(h.preventDefault(),e)return;let P=new FormData(h.currentTarget),j=Ht(P,d,F,t,v);if(K(j),Object.keys(j).length){kt(G.current,j);return}o(Mt(P,b,d,t,v))},onInvalidCapture:h=>{let j=h.target.closest("details");j&&(j.open=!0)},children:[(0,g.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-6",children:[s||Object.keys(D).length?(0,g.jsx)("p",{role:"alert",className:"mb-4 text-sm text-red-700",children:Object.keys(D).length?"Review the highlighted fields.":s}):null,t?(0,g.jsxs)("dl",{className:"detail-list mb-4","aria-label":"Source identity",children:[(0,g.jsx)("dt",{children:"Source ID"}),(0,g.jsx)("dd",{children:(0,g.jsx)(te,{value:t.id,label:"source ID"})}),(0,g.jsx)("dt",{children:"Source URL"}),(0,g.jsx)("dd",{className:"break-all",children:he(t.url)??"No displayable URL"}),(0,g.jsx)("dt",{children:"Credential"}),(0,g.jsx)("dd",{children:t.hasCredential?"credential set \xB7 write-only":"No credential set"}),"attached"in t?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("dt",{children:"Attached to this project"}),(0,g.jsx)("dd",{children:t.attached?"Yes":"No"})]}):null]}):null,(0,g.jsxs)("fieldset",{disabled:e,className:"grid min-w-0 gap-4",children:[F?(0,g.jsx)(g.Fragment,{children:z?(0,g.jsx)("p",{className:"text-sm",children:`Source type: ${Z[d]}. This broker cannot change its repository settings.`}):null}):(0,g.jsxs)(g.Fragment,{children:[Pe("ecosystem",b,[["composer","Composer"],["npm","npm"]],h=>{let P=h;n(P),C(yt[P][0]),u(""),K({})},!0),Pe("type",d,yt[b].filter(h=>(h!=="vcs"||S.length>0)&&(h!=="hosted"||y)).map(h=>[h,Z[h],Ot[h]]),h=>{C(h),u(""),T(k),i("app"),K({})}),M("name",{required:!0,placeholder:Pt})]}),R?(0,g.jsxs)("p",{className:"break-words text-sm",children:["Upstream URL: ",ze[d]]}):null,R?(0,g.jsx)("input",{type:"hidden",name:"url",value:ze[d]}):null,!R&&d!=="vcs"&&d!=="hosted"?(0,g.jsx)("div",{children:M("url",{required:!F||t.url!==null,value:t?.url??"",label:d==="npm_registry"?"Registry URL":"Repository URL",placeholder:d==="npm_registry"?"https://npm.example.com":"https://composer.example.com"})},`network:${d}`):null,x&&!z?(0,g.jsxs)("div",{className:"grid gap-1",children:[(0,g.jsx)("p",{className:"text-sm text-neutral-600",children:"Some saved settings cannot be displayed. Replace the configuration only if you intend to overwrite all saved type-specific settings."}),ne("replaceConfig","Replace type-specific configuration",I)]}):null,ye?(0,g.jsxs)("div",{className:"grid gap-4",children:[d==="vcs"?(0,g.jsxs)(g.Fragment,{children:[ue("config/provider",(0,g.jsx)(Q,{id:"source-config/provider",name:"config/provider",value:E,className:"h-11 text-base sm:text-sm","aria-invalid":!!D["config/provider"],"aria-describedby":se("config/provider"),onChange:h=>T(h.currentTarget.value),children:S.map(([h,P])=>(0,g.jsx)("option",{value:h,children:P},h))})),(0,g.jsxs)("div",{children:[M("config/repository",{required:!0,label:E==="github"?"GitHub repository":E==="git"?"Git repository URL":"SSH repository",placeholder:E==="github"?"acme/payments":E==="git"?"https://git.example.com/acme/payments.git":"git@git.example.com:acme/payments.git"}),E==="github"?(0,g.jsx)("p",{className:"mt-1 text-sm text-neutral-600",children:"Use owner/repository for GitHub, such as acme/payments."}):null]},E),E==="github"?(0,g.jsxs)(g.Fragment,{children:[F?(0,g.jsxs)(g.Fragment,{children:[ue("githubAuthentication",(0,g.jsx)($,{id:"source-githubAuthentication",name:"githubAuthenticationDisplay",className:"h-11 text-base sm:text-sm",value:H==="app"?"GitHub App":"Personal access token",readOnly:!0})),(0,g.jsx)("input",{type:"hidden",name:"githubAuthentication",value:H})]}):Pe("githubAuthentication",H,[["app","GitHub App","Use an app installation with access to this repository."],["token","Personal access token","Add your token after creating the source."]],h=>i(h)),H==="app"?M("config/installationId",{required:!0,number:!0,minimum:1}):null]}):null]}):null,d==="composer_repository"?(0,g.jsxs)(g.Fragment,{children:[M("config/selection/packages",{multiline:!0}),M("config/selection/patterns",{multiline:!0})]}):null,d==="npm_registry"?(0,g.jsxs)(g.Fragment,{children:[M("config/scopes",{multiline:!0}),F?null:ue("registeredPatterns",(0,g.jsx)("textarea",{id:"source-registeredPatterns",name:"registeredPatterns",rows:3,readOnly:!0,value:Ge(f).join(`
3
+ `)}),"Names to register after adding this source")]}):null]},`primary:${d}`):null,d==="hosted"?(0,g.jsx)("p",{className:"text-sm text-neutral-600",children:"npm publishing is available. Register package names, then enable this source. A claim immediately stops the npmjs proxy from serving that name, even while this source is paused. Use an exact lowercase npm name or @scope/*. A scope claim hides public packages in that scope that are not yet cached."}):null,!F&&d!=="hosted"?(0,g.jsx)("p",{className:"text-sm text-neutral-600",children:R?"No credentials are needed to add this proxy.":d==="vcs"&&E==="github"?H==="app"?"After adding this source, save the GitHub App credentials.":"After adding this source, save your GitHub personal access token as a bearer credential.":d==="vcs"&&E==="ssh"?"After adding this source, save an SSH private key and known hosts.":"After adding this source, save its credentials to finish setup."}):null,d==="hosted"&&b==="npm"?ne("requirePublishApproval"):null,(0,g.jsxs)("details",{className:"min-w-0",children:[(0,g.jsx)("summary",{className:"min-h-11 cursor-pointer py-3 text-sm font-medium",children:"Advanced settings"}),(0,g.jsxs)("div",{className:"grid gap-4 pt-2",children:[(0,g.jsx)("p",{className:"text-sm text-neutral-600",children:"Optional sync, visibility, retention, and connection settings."}),ye?(0,g.jsxs)("div",{className:"grid gap-4",children:[d==="composer_repository"||d==="npm_registry"?M("config/distHosts",{multiline:!0}):null,d==="composer_repository"?(0,g.jsxs)(g.Fragment,{children:[ne("config/mirrorsFallback"),F?ne("config/selection/expandPatterns"):null]}):null,d==="vcs"?(0,g.jsxs)(g.Fragment,{children:[M("config/packageName",{placeholder:b==="npm"?"@acme/payments":"acme/payments"}),M("config/refs/branches",{multiline:!0}),ne("config/refs/tags",void 0,void 0,!0)]}):null,d==="packagist_proxy"&&F?ne("config/githubToken"):null]},`advanced:${d}`):null,d==="packagist_proxy"&&F?(0,g.jsx)("p",{className:"text-sm text-neutral-600",children:"To enable Use GitHub token, save a bearer credential with your GitHub token, then select Use GitHub token and save the source."}):null,M("pollIntervalSeconds",{number:!0,minimum:1,value:t?.pollIntervalSeconds??300}),ue("removalPolicy",(0,g.jsxs)(Q,{id:"source-removalPolicy",name:"removalPolicy",className:"h-11 text-base sm:text-sm","aria-invalid":!!D.removalPolicy,"aria-describedby":se("removalPolicy"),defaultValue:t?.removalPolicy??"flag",children:[(0,g.jsx)("option",{value:"flag",children:"Keep available and mark removed"}),(0,g.jsx)("option",{value:"exclude",children:"Exclude from package resolution"})]})),ne("defaultVisibleToNewProjects"),M("retentionDaysOverride",{number:!0,minimum:0}),M("userAgent")]})]})]})]}),(0,g.jsxs)(le,{className:"shrink-0 border-t border-neutral-200 bg-white px-6 pt-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:[(0,g.jsx)(N,{className:"min-h-11",type:"button",variant:"outline",disabled:e,onClick:p,children:"Cancel"}),(0,g.jsx)(N,{type:"submit",className:"min-h-11",disabled:e,children:F?"Save source":"Add source"})]})]})]})})}var a=U(ee(),1),We={http_basic:["username","password"],bearer:["token"],header:["name","value"],query:["param","value"],github_app:["appId","privateKeyPem","webhookSecret"],npm_token:["token"],ssh_key:["privateKeyPem","knownHosts"]},_t=Object.keys(We);function Ve(t,{scope:e,github:r,vcsProviders:s}){switch(t){case"packagist_proxy":return["bearer"];case"npmjs_proxy":case"hosted":return[];case"composer_repository":return["http_basic","bearer","header","query","npm_token"];case"npm_registry":return["npm_token","http_basic","bearer","header"];case"vcs":return r?e==="organization"?["bearer","github_app"]:["bearer"]:["bearer","http_basic","header","npm_token",...s?.includes("ssh")?["ssh_key"]:[]]}}function Ke(t,e){return{scope:t.projectId===null?"organization":"project",github:t.githubAuthentication!==void 0,vcsProviders:e}}function Ee(t){return["packagist_proxy","npmjs_proxy","npm_registry"].includes(t.type)&&"attached"in t&&t.attached===!0}function $t(t){if(t.type==="composer_repository")return"http_basic";if(t.type==="npm_registry")return"npm_token";if(t.type==="vcs"){let e=t.config;if(e?.provider==="ssh")return"ssh_key";if(e?.provider==="github"&&e.installationId!==void 0)return"github_app"}return"bearer"}function de(t){return["packagist_proxy","npmjs_proxy"].includes(t.type)}var Ne="An organization admin must enable this source.",Ye="Register package names, then enable the source.";function Bt(t,e){let r=t?.config;return t?.type!=="npm_registry"||!Array.isArray(r?.scopes)?[]:Ge(r.scopes.join(`
4
+ `)).filter(s=>!e.includes(s))}function he(t){if(t===null)return null;try{let e=new URL(t);return["https:","http:","ssh:","git:"].includes(e.protocol)?(e.username="",e.password="",e.search="",e.hash="",e.toString()):null}catch{return null}}function zt(t,e,r=()=>new Date().toISOString()){let{client:s}=t,o={ownership:"organization",editor:null,fieldErrors:{},formError:null,available:[],availableNext:null,availableLoading:!1,availableError:!1,items:[],next:null,loading:!0,listError:!1,settingsVersion:0,vcsProviders:void 0,busy:!1,error:null,notice:null,createdSource:null,credentialSource:null,credentialVersion:0,credentialKind:"bearer",credentialKinds:_t,packageSource:null,packageFieldError:null,packageAlert:null,savedCredential:null,names:null,preview:null,order:[],etag:null,canEnableProjectSource:!1,canWriteSources:!1,enableDenied:[],enableConflicts:[]},p=new Set,l=i=>{o={...o,...i};for(let f of p)f()},m,w=()=>{},y=0,b=0,n=0,d=0,C=0;function S(i,f=!1){return i.ok?!1:(i.code==="reauth_required"?(t.requireReauth(f?{method:i.request.method,path:i.request.path}:i.request,{credential:f,secretFields:[]}),l({enableDenied:[],error:f?"Reauthenticate, then enter the credential again.":"Reauthentication is required."})):i.code==="claim_overlap"?l({error:"Another source already claims this package name or scope."}):i.code==="name_public"?l({error:"This name is already available from a public registry."}):i.code==="name_public_unverified"?l({error:"The public registry could not be checked. Try registering the name again later."}):l({error:"The request could not be saved or loaded. Refresh and try again."}),!0)}async function k(i=!1){if(i&&(o.loading||o.next===null))return;let f=++b,u=i?o.next:null,v=o.etag;++C,l({loading:!0,listError:!1,error:null,etag:null,preview:null,order:[],enableDenied:[],enableConflicts:[],notice:null});let x={limit:"100",...u===null?{}:{after:u}},[_,I]=await Promise.all([e!==null||o.ownership!=="organization"?m??=s.request("get","/_pb/me/permissions").then(R=>(R.ok||(m=void 0),R)):null,e===null?s.request("get","/_pb/sources",{query:{...x,...o.ownership==="organization"?{}:{ownership:o.ownership}}}):s.request("get","/_pb/projects/{project}/sources",{params:{project:e},query:x})]);if(f!==b)return;let oe=!I.ok&&I.code==="reauth_required";if(_&&!_.ok&&!oe&&(_.status!==403||_.code==="reauth_required")&&S(_),S(I)||!I.ok){l({loading:!1,listError:!0});return}l({canEnableProjectSource:_?.ok===!0&&_.data.organization.includes("org:sources:write")});let K=Je(I,"etag")??null;if(e!==null&&i&&K!==v){await k();return}let G=I.data.items.map(R=>({...R,url:he(R.url)})),D=i?[...o.items,...G]:G,F=D.flatMap(R=>"attached"in R&&R.attached===!0&&"precedence"in R&&typeof R.precedence=="number"?[{id:R.id,precedence:R.precedence}]:[]);l({items:D,settingsVersion:o.settingsVersion+1,next:I.data.next,vcsProviders:I.data.vcsProviders,loading:!1,etag:K,order:F.sort((R,ye)=>R.precedence-ye.precedence).map(({id:R})=>R)})}async function E(i=!1){if(e===null||i&&(o.availableLoading||o.availableNext===null))return;let f=++n,u=i?o.availableNext:null;l({availableLoading:!0,availableError:!1});let v=await s.request("get","/_pb/sources",{query:{limit:"100",...u===null?{}:{after:u}}});if(f!==n)return;if(!v.ok){l({available:[],availableNext:null,availableLoading:!1,availableError:!0});return}let x=v.data.items.map(_=>({..._,attached:!1,url:he(_.url)}));l({available:i?[...o.available,...x]:x,availableNext:v.data.next,availableLoading:!1})}async function T(i){for(;!o.items.some(f=>f.id===i)&&o.next!==null&&!o.listError;)await k(!0);return o.items.find(f=>f.id===i)}async function V(i,f){let u=await T(i);if(u&&l({createdSource:i,notice:`Next steps for ${u.name}`}),u&&!de(u)&&u.type!=="hosted"){let v=Ve(u.type,Ke(u,o.vcsProviders)),x=f?$t(f):u.githubAuthentication==="app"?"github_app":v[0];l({credentialSource:i,credentialVersion:o.credentialVersion+1,credentialKinds:v,credentialKind:x!==void 0&&v.includes(x)?x:v[0]})}}async function z(i,f=!1){let u=o.names;if(f||l({credentialSource:null,error:null}),f&&(u?.source!==i||u.next===null))return;let v=++d,x=f?u?.next:null,_=await s.request("get","/_pb/sources/{source}/names",{params:{source:i},query:{limit:"100",...x==null?{}:{after:x}}});v!==d||S(_)||!_.ok||l({names:{..._.data,source:i,items:f?[...u.items,..._.data.items]:_.data.items}})}async function H(i,f,u=()=>!1){if(!o.busy){l({busy:!0,error:null,notice:null});try{let v=await i();!u(v)&&!S(v)&&await f()}finally{l({busy:!1})}}}return{project:e,dispose(){++y,w()},snapshot:()=>o,enableNeedsAdmin(i){return i.projectId!==null&&(!o.canEnableProjectSource||o.enableDenied.includes(i.id))},subscribe(i){return p.add(i),()=>{p.delete(i)}},load:k,async setOwnership(i){e!==null||o.busy||(l({ownership:i,items:[],next:null}),await k())},loadAvailable:E,names:z,openEditor(i=null){o.busy||i&&e!==null&&i.projectId===null||l({editor:i??"create",fieldErrors:{},formError:null,error:null,credentialSource:null,savedCredential:null})},closeEditor(){o.busy||l({editor:null,fieldErrors:{},formError:null})},async saveSource(i){if(o.busy||o.editor===null)return;let f=o.editor;if(f!=="create"&&Object.keys(i).length===0){l({editor:null,fieldErrors:{},formError:null});return}l({busy:!0,error:null,formError:null,fieldErrors:{}});try{let u=f==="create"?e===null?await s.request("post","/_pb/sources",{body:i}):await s.request("post","/_pb/projects/{project}/sources",{params:{project:e},body:i}):e===null?await s.request("patch","/_pb/sources/{source}",{params:{source:f.id},headers:{"If-Match":`"r${f.revision}"`},body:i}):await s.request("patch","/_pb/projects/{project}/sources/{source}",{params:{project:e,source:f.id},headers:{"If-Match":`"r${f.revision}"`},body:i});if(!u.ok){S(u),u.status===412&&l({error:"This source changed while you were editing. Reload the latest settings before saving."}),l({fieldErrors:St(u.details),formError:o.error});return}l({editor:null,fieldErrors:{},formError:null,...f==="create"&&e===null&&o.ownership==="project"?{ownership:"organization"}:{}}),await k(),f==="create"&&u.data&&"id"in u.data&&await V(u.data.id,i)}finally{l({busy:!1})}},attachment(i,f){return e===null?Promise.resolve():H(()=>f?s.request("put","/_pb/projects/{project}/sources/{source}/attachment",{params:{project:e,source:i},body:{}}):s.request("delete","/_pb/projects/{project}/sources/{source}/attachment",{params:{project:e,source:i}}),()=>k())},async replayed(i){if(i.path.startsWith("/_pb/sources/discovery/"))return;let f=e===null?"/_pb/sources":`/_pb/projects/${encodeURIComponent(e)}/sources`,u=/^\/_pb\/sources\/[^/]+\/names(?:\/[^/]+)?$/.test(i.path),v=/^\/_pb\/sources\/([^/]+)\/enable$/.exec(i.path);if(i.path!==f&&!i.path.startsWith(`${f}/`)&&!u&&!v)return;let x=o.names?.source;l({enableDenied:[],enableConflicts:[]}),i.ok&&l({editor:null,fieldErrors:{},formError:null,...i.createdSourceId&&e===null&&o.ownership==="project"?{ownership:"organization"}:{}}),await k(),v&&!i.ok&&(i.status===403&&i.code==="forbidden"&&o.items.some(_=>_.id===v[1]&&_.projectId!==null)?l({enableDenied:[v[1]],notice:Ne}):i.status===409&&i.code==="conflict"?l({enableConflicts:[v[1]],notice:Ye}):l({error:"The request could not be saved or loaded. Refresh and try again."})),i.ok&&i.createdSourceId&&await V(i.createdSourceId),x!==void 0&&await z(x)},moveSource(i,f){if(o.loading||o.busy||o.next!==null)return;let u=[...o.order],v=u.indexOf(i),x=v+f;v<0||x<0||x>=u.length||([u[v],u[x]]=[u[x],u[v]],l({order:u}))},async saveOrder(){if(e===null||o.loading||o.busy||o.next!==null||o.etag===null)return;let i=o.etag,f=[...o.order];l({busy:!0,error:null,preview:null}),++C;try{let u=await s.request("put","/_pb/projects/{project}/sources/order",{params:{project:e},headers:{"If-Match":i},body:{sourceIds:f}});!u.ok&&u.status===412?(await k(),l({error:"Source ordering changed. Review the reloaded list before saving again."})):S(u)||await k()}finally{l({busy:!1})}},closeCredential(){o.busy||l({credentialSource:null})},closeNames(){o.busy||(++d,l({names:null}))},chooseCredential(i){if(o.busy)return;let f=o.items.find(v=>v.id===i),u=f?Ve(f.type,Ke(f,o.vcsProviders)):["bearer"];u.length!==0&&(++d,l({credentialSource:i,names:null,savedCredential:null,credentialVersion:o.credentialVersion+1,credentialKind:f?.githubAuthentication==="app"&&u.includes("github_app")?"github_app":u[0],credentialKinds:u,error:null}))},openPackage(i){o.busy||e===null||!Ee(i)||i.status==="paused"||l({packageSource:i,packageFieldError:null,packageAlert:null,notice:null})},closePackage(){o.busy||l({packageSource:null,packageFieldError:null,packageAlert:null})},async addPackage(i){let f=o.packageSource;if(!(o.busy||e===null||!f||!Ee(f))){if(i=i.trim(),!i||i.length>428){l({packageFieldError:"Enter a package name of 1 to 428 characters."});return}l({busy:!0,packageFieldError:null,packageAlert:null,notice:null});try{let u=await s.request("post","/_pb/projects/{project}/sources/{source}/packages",{params:{project:e,source:f.id},body:{name:i}});u.ok?l({packageSource:null,notice:u.status===202?Fe(202,u.data.name,f.name):Fe(200,u.data.name,f.name)}):u.status===400&&u.code==="invalid_request"?l({packageFieldError:"Enter a valid package name for this source."}):u.code==="package_not_found"?l({packageAlert:"Not found upstream. Check the package name or use another source."}):u.status===400?l({packageFieldError:"This source does not support that package. Check the name or use another source."}):u.code==="forbidden"?l({packageAlert:"You do not have permission to add packages to this project."}):u.status===502?l({packageAlert:"The upstream registry refused or failed the request. Check the source credential or try again later."}):u.status===404?l({packageAlert:"The package or attached source could not be found. Check the name and refresh sources."}):u.status===503?l({packageAlert:"Package requests are temporarily unavailable. Try again shortly."}):u.status===409?l({packageAlert:"This source is paused. Enable it before adding a package."}):(S(u),l({packageAlert:o.error,error:null}))}finally{l({busy:!1})}}},async credential(i,f,u){if(!o.busy){l({busy:!0,error:null,credentialSource:i,credentialVersion:o.credentialVersion+1,savedCredential:null});try{let v=e===null?await s.request("put","/_pb/sources/{source}/credential",{params:{source:i},body:{kind:f,material:u}}):await s.request("put","/_pb/projects/{project}/sources/{source}/credential",{params:{project:e,source:i},body:{kind:f,material:u}});S(v,!0)||l({savedCredential:{source:i,at:r()},notice:"Credential set.",items:o.items.map(x=>x.id===i?{...x,hasCredential:!0}:x)})}finally{l({busy:!1})}}},edit(i,f,u){if(!Number.isSafeInteger(f)||f<=0)return l({error:"Polling interval must be a positive whole number."}),Promise.resolve();let v=o.items.find(I=>I.id===i)?.revision;if(v===void 0)return l({error:"Reload sources before saving."}),Promise.resolve();let x={"If-Match":`"r${v}"`},_={pollIntervalSeconds:f,removalPolicy:u};return H(()=>e===null?s.request("patch","/_pb/sources/{source}",{params:{source:i},body:_,headers:x}):s.request("patch","/_pb/projects/{project}/sources/{source}",{params:{project:e,source:i},body:_,headers:x}),()=>k())},async loadMutationPermissions(){let i=e===null?await s.request("get","/_pb/me/permissions"):await s.request("get","/_pb/projects/{project}/permissions",{params:{project:e}});l({canWriteSources:i.ok&&("organization"in i.data?i.data.organization.includes("org:sources:write"):i.data.project.includes("project:sources:write"))})},syncNow(i){if(o.busy||i.status==="paused"||e!==null&&i.projectId===null)return Promise.resolve();w();let f=++y;return H(()=>e===null?s.request("post","/_pb/sources/{source}/sync",{params:{source:i.id}}).then(He):s.request("post","/_pb/projects/{project}/sources/{source}/sync",{params:{project:e,source:i.id}}).then(He),async()=>{if(f!==y)return;let u=async()=>{let x=b,_=o.ownership,I=null;do{let oe={limit:"100",...I===null?{}:{after:I}},K=e===null?await s.request("get","/_pb/sources",{query:{...oe,..._==="organization"?{}:{ownership:_}}}):await s.request("get","/_pb/projects/{project}/sources",{params:{project:e},query:oe});if(f!==y||x!==b||!K.ok)return!0;let G=K.data.items.find(D=>D.id===i.id);if(G)return l({items:o.items.map(D=>D.id===i.id?{...G,url:he(G.url)}:D)}),Me(i,G);I=K.data.next}while(I!==null);return!0},v;if(o.loading&&o.items.length===0){await k();let x=await T(i.id);v=o.listError||!x||Me(i,x)}else v=await u();f===y&&(l({notice:Oe}),v!==!0&&f===y&&(w=ft(u)))})},async togglePause(i){if(e!==null&&i.projectId===null)return;if(i.status==="paused"&&!de(i)){if(o.busy||i.projectId!==null&&(!o.canEnableProjectSource||o.enableDenied.includes(i.id)))return;l({enableConflicts:o.enableConflicts.filter(u=>u!==i.id)}),await H(()=>s.request("post","/_pb/sources/{source}/enable",{params:{source:i.id}}),()=>k(),u=>i.projectId!==null&&!u.ok&&u.status===403&&u.code==="forbidden"?(l({enableDenied:[...new Set([...o.enableDenied,i.id])],notice:Ne}),!0):!u.ok&&u.status===409&&u.code==="conflict"?(l({enableConflicts:[...new Set([...o.enableConflicts,i.id])],notice:Ye}),!0):!1);return}let f=i.status==="paused"?"resume":"pause";return H(()=>e===null?s.request("post",`/_pb/sources/{source}/${f}`,{params:{source:i.id}}):s.request("post",`/_pb/projects/{project}/sources/{source}/${f}`,{params:{project:e,source:i.id}}),()=>k())},addName(i,f){let u=o.items.find(v=>v.id===i)?.ecosystem==="npm"?214:50;return f.length===0||f.length>u||!/^[a-z0-9._~@!/*-]+$/.test(f)?(l({error:`Enter a registered pattern of 1 to ${u} supported characters.`}),Promise.resolve()):H(()=>s.request("post","/_pb/sources/{source}/names",{params:{source:i},body:{pattern:f}}),()=>z(i))},removeName(i,f){return H(()=>s.request("delete","/_pb/sources/{source}/names/{name}",{params:{source:i,name:f}}),async()=>{await z(i),await k()})},async resolve(i){let f=++C;if(l({preview:null,error:null}),e===null||i.length===0||i.length>214){l({error:`Choose a project and enter a package name of 1 to ${214} characters.`});return}let u=await s.request("get","/_pb/projects/{project}/resolve",{params:{project:e},query:{name:i}});f===C&&!S(u)&&u.ok&&l({preview:u.data})}}}function Gt(t,e,r){let s=r.elements.namedItem("kind")?.value,o=_t.includes(s)?We[s]:null,p=o===null?null:JSON.stringify(Object.fromEntries(o.map(l=>[l,r.elements.namedItem(l)?.value??""])));return r.reset(),p===null?Promise.resolve():t.credential(e,s,p)}function Ut({kind:t,busy:e}){return(0,a.jsx)(a.Fragment,{children:We[t].map(r=>(0,a.jsxs)("div",{children:[(0,a.jsx)(L,{htmlFor:`credential-${r}`,children:r}),(0,a.jsx)($,{id:`credential-${r}`,name:r,type:"password",autoComplete:"off",defaultValue:"",maxLength:16384,required:!0,disabled:e})]},r))})}function Vt({model:t,source:e,busy:r,initialKind:s,kinds:o}){let[p,l]=(0,O.useState)(s);return(0,a.jsxs)("form",{className:"grid gap-3",autoComplete:"off",onSubmit:m=>{m.preventDefault(),!r&&Gt(t,e,m.currentTarget)},children:[(0,a.jsx)(L,{htmlFor:"credential-kind",children:"Credential kind"}),(0,a.jsx)(Q,{id:"credential-kind",name:"kind",value:p,disabled:r,onChange:m=>l(m.currentTarget.value),children:o.map(m=>(0,a.jsx)("option",{value:m,children:m},m))}),(0,a.jsx)(Ut,{kind:p,busy:r},p),(0,a.jsx)(N,{type:"submit",className:"w-fit",disabled:r,children:"Save credential"})]})}function Ct(t,e){return new FormData(t).get(e)?.toString()??""}var Ue={network:"Network failure",timeout:"Sync timed out",http_error:"HTTP error",unauthorized:"Authorization failed",rate_limited:"Rate limited",not_found:"Not found",invalid_response:"Invalid response",tag_limit_exceeded:"Tag limit exceeded",mass_absence:"Mass package absence",too_large:"Response too large",policy_denied:"Policy denied",credential_unavailable:"Credential unavailable",internal:"Internal error",name_mismatch:"Package name differs from configuration",version_mismatch:"Manifest version differs from tag",invalid_manifest:"Invalid package manifest",unsupported_files_pattern:"Unsupported package file pattern",invalid_packlist:"Package files could not be packed",invalid_tarball:"Invalid repository archive",archive_changed:"Repository archive changed during packing"};function Kt({source:t}){let e=t.lastError!==null&&Object.hasOwn(Ue,t.lastError)?Ue[t.lastError]:null;return(0,a.jsxs)("div",{className:"grid gap-1 text-sm",children:[(0,a.jsxs)("p",{children:["Last listing: ",(0,a.jsx)(ge,{value:t.lastSuccessAt,fallback:"Never"})]}),(0,a.jsxs)("p",{children:["Last listing error:"," ",t.lastError===null?"None":(0,a.jsxs)(a.Fragment,{children:[e&&`${e} \xB7 `,(0,a.jsx)("code",{children:t.lastError})]})]}),t.sync&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{children:["Latest sync: ",t.sync.queued," queued \xB7 ",t.sync.running," running \xB7"," ",t.sync.retrying," retrying \xB7 ",t.sync.failed," failed \xB7 ",t.sync.completed," ","completed"]}),t.sync.errors.slice(0,3).map(({code:r,count:s})=>(0,a.jsxs)("p",{children:[Ue[r]," \xB7 ",(0,a.jsx)("code",{children:r}),": ",s]},r))]}),de(t)?(0,a.jsx)("p",{children:mt}):null,(0,a.jsxs)("p",{children:["Next poll: ",(0,a.jsx)(ge,{value:t.nextPollAt,fallback:"None"})]})]})}function Yt({source:t,model:e,busy:r}){let[s,o]=(0,O.useState)(null);(0,O.useEffect)(()=>{s&&(s.id!==t.id||s.status!==t.status)&&o(null)},[s,t.id,t.status]);let p=e.project===null?t.projectId===null:t.projectId!==null,l=e.project===null&&t.projectId!==null,m=(p||l)&&t.status==="paused"&&!de(t)&&e.enableNeedsAdmin(t),w=e.snapshot().enableConflicts.includes(t.id),y=`source-actions-note-${t.id}`,b=!p&&!l?"Manage this organization source in organization scope.":[m&&Ne,w&&Ye].filter(Boolean).join(" "),n=p?[{id:"edit",label:"Edit",disabled:r,onSelect:()=>e.openEditor(t)},...e.snapshot().canWriteSources&&t.type!=="hosted"?[{id:"sync",label:"Sync now",disabled:r||t.status==="paused",...t.status==="paused"?{describedBy:`sync-paused-${t.id}`}:{},onSelect:()=>{e.syncNow(t)}}]:[]]:[],d=[];return p||l?(l&&(t.status!=="paused"||de(t))||d.push(t.status==="paused"?{id:"enable",label:"Enable",disabled:r||m,...m||w?{describedBy:y}:{},onSelect:()=>{e.togglePause(t)}}:{id:"pause",label:"Pause source\u2026",disabled:r,onSelect:()=>o(t)}),p&&Ve(t.type,Ke(t,e.snapshot().vcsProviders)).length>0&&d.push({id:"credential",label:t.type==="packagist_proxy"?"Add GitHub token (optional)":"Set credential",disabled:r,onSelect:()=>e.chooseCredential(t.id)})):d.push({id:"manage",label:"Manage source",disabled:!0,describedBy:y,onSelect:()=>{}}),e.project!==null&&e.snapshot().canWriteSources&&Ee(t)&&d.push({id:"add-package",label:"Add package",disabled:r||t.status==="paused",...t.status==="paused"?{describedBy:`add-package-paused-${t.id}`}:{},onSelect:()=>e.openPackage(t)}),d.push({id:"names",label:"Registered names",disabled:r,onSelect:()=>{e.names(t.id)}}),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(we,{entityLabel:t.name,actions:n,overflow:d}),p&&t.status==="paused"?(0,a.jsx)("p",{id:`sync-paused-${t.id}`,children:"Enable before syncing."}):null,e.project!==null&&Ee(t)&&t.status==="paused"?(0,a.jsx)("p",{id:`add-package-paused-${t.id}`,children:"Enable before adding a package."}):null,b?(0,a.jsx)("p",{id:y,children:b}):null,(0,a.jsx)(ke,{action:"Pause",target:`${t.name} (${t.id})`,scope:e.project===null?"Organization":`Project: ${e.project}`,description:"Pausing this source stops it from resolving packages in this scope. You can enable it again later.",disabled:r,open:s?.id===t.id&&s.status===t.status&&t.status!=="paused",onOpenChange:C=>{C||o(null)},hideTrigger:!0,onConfirm:()=>{e.togglePause(t)}})]})}function Wt(t,e){return t.filter(r=>r.name.toLowerCase().includes(e.q.toLowerCase())&&(!e.type||r.type===e.type)&&(!e.scope||(e.scope==="organization"?r.projectId===null:r.projectId!==null)))}function Xt({model:t}){let e=(0,O.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),[r,s]=(0,O.useState)({q:"",type:"",scope:""}),o=!!(r.q||r.type||r.scope),p=e.items.find(n=>n.id===e.createdSource),l=(0,O.useMemo)(()=>{let n=e.names;return n===null?[]:Bt(e.items.find(d=>d.id===n.source),n.items.map(d=>d.pattern))},[e.items,e.names]),m=!e.loading&&!e.listError&&e.next===null,w=e.items.find(n=>n.id===e.credentialSource)?.type==="packagist_proxy",y=[...e.items,...m?e.available.filter(n=>!e.items.some(d=>d.id===n.id)):[]],b=Wt(y,r).sort((n,d)=>{let C=S=>{let k=e.order.indexOf(S);return k<0?1/0:k};return C(n.id)-C(d.id)});return(0,a.jsxs)("section",{"aria-labelledby":"page-heading",className:"grid gap-6",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,a.jsx)("h1",{tabIndex:-1,id:"page-heading",className:"text-xl font-semibold",children:"Sources"}),(0,a.jsx)(N,{type:"button",disabled:e.busy,onClick:()=>t.openEditor(),children:"Add source"})]}),e.editor!==null?(0,a.jsx)(xt,{organization:t.project===null,source:e.editor==="create"?null:e.editor,busy:e.busy,errors:e.fieldErrors,alert:e.formError,onSubmit:n=>{e.editor==="create"&&s({q:"",type:"",scope:""}),t.saveSource(n)},onClose:()=>t.closeEditor(),vcsProviders:e.vcsProviders,initialType:typeof window<"u"&&new URLSearchParams(window.location.hash.split("?")[1]).get("create")==="vcs"?"vcs":void 0,initialProvider:typeof window<"u"&&new URLSearchParams(window.location.hash.split("?")[1]).get("provider")==="github"?"github":void 0}):null,(0,a.jsx)("p",{className:"text-neutral-600",children:"Upstream registries and private repositories. Attached sources are tried in precedence order."}),t.project===null?(0,a.jsxs)(L,{children:["Ownership",(0,a.jsxs)(Q,{value:e.ownership,disabled:e.busy,onChange:n=>{t.setOwnership(n.target.value)},children:[(0,a.jsx)("option",{value:"organization",children:"Organization"}),(0,a.jsx)("option",{value:"project",children:"Project-owned"}),(0,a.jsx)("option",{value:"all",children:"All"})]})]}):null,(0,a.jsx)(nt,{values:{...r,scope:r.scope==="organization"?"Organization":r.scope==="project"?"Project":"",type:Z[r.type]??""},fields:[{key:"q",label:"Name (loaded sources)"},{key:"type",label:"Type",options:[...new Set(y.map(n=>Z[n.type]))].sort()},...t.project===null?[]:[{key:"scope",label:"Source scope",options:["Organization","Project"]}]],onChange:n=>s({q:n.q??"",scope:t.project===null?"":n.scope==="Organization"?"organization":n.scope==="Project"?"project":"",type:Object.keys(Z).find(d=>Z[d]===n.type)??""})}),(0,a.jsx)("p",{role:"status","aria-live":"polite",children:e.notice}),p?.status==="paused"&&!de(p)?(0,a.jsxs)("p",{children:["Next steps for ",p.name,":"," ",t.enableNeedsAdmin(p)?Ne:e.names?.source===p.id&&e.names.items.length>0?"Enable the source.":"Register names, then Enable the source."]}):null,e.error&&!e.listError?(0,a.jsx)(ae,{kind:"error",title:e.error}):null,e.listError?(0,a.jsxs)(ae,{kind:"error",title:"Sources could not be loaded.",children:[e.error?(0,a.jsx)("p",{children:e.error}):null,(0,a.jsx)(N,{type:"button",className:"w-fit",disabled:e.loading||e.busy,onClick:()=>{t.load()},children:"Retry sources"})]}):null,!e.listError&&!e.availableError?(0,a.jsx)(N,{type:"button",className:"w-fit",variant:"outline",disabled:e.loading||e.busy,onClick:()=>{t.load(),t.loadAvailable()},children:"Refresh sources"}):null,t.project!==null&&!m&&e.available.length>0?(0,a.jsx)("p",{className:"text-sm text-neutral-600",children:"Load all project sources before attaching organization sources."}):null,e.availableLoading?(0,a.jsx)(ae,{kind:"loading",title:"Loading organization sources\u2026"}):null,e.availableError?(0,a.jsx)(ae,{kind:"error",title:"Organization sources could not be loaded.",children:(0,a.jsx)(N,{type:"button",className:"w-fit",disabled:e.availableLoading||e.busy,onClick:()=>{t.loadAvailable()},children:"Retry organization sources"})}):null,e.loading?(0,a.jsx)(ae,{kind:"loading",title:"Loading sources\u2026"}):!e.listError&&b.length===0?(0,a.jsx)(ae,{kind:o?"filtered-empty":"empty",title:o?"No sources match these filters.":"No sources."}):null,!e.loading&&!e.listError&&b.length?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{className:"text-sm text-neutral-600",children:[b.length," sources loaded",o?" matching filters":""]}),(0,a.jsx)(et,{label:"Sources in precedence order",items:b,columns:[{key:"name",label:"Source",value:n=>n.name,render:n=>(0,a.jsxs)("div",{className:"grid gap-1",children:[(0,a.jsx)("strong",{children:n.name}),"projectName"in n&&n.projectName!==null?(0,a.jsx)("span",{children:`Project: ${n.projectName}`}):null,(0,a.jsxs)("span",{className:"text-xs text-neutral-600",children:[n.ecosystem==="composer"?"Composer":"npm"," \xB7"," ",Z[n.type]]}),(0,a.jsx)(tt,{status:n.status})]})},{key:"precedence",label:"Precedence",value:n=>e.order.indexOf(n.id)<0?"\u2014":e.order.indexOf(n.id)+1,render:n=>{let d=e.order.indexOf(n.id);return d<0?"\u2014":(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[(0,a.jsx)("strong",{children:d+1}),(0,a.jsx)(N,{type:"button",size:"sm",variant:"ghost","aria-label":`Move up ${n.name}`,disabled:e.busy||e.next!==null||d===0,onClick:()=>t.moveSource(n.id,-1),children:"Move up"}),(0,a.jsx)(N,{type:"button",size:"sm",variant:"ghost","aria-label":`Move down ${n.name}`,disabled:e.busy||e.next!==null||d===e.order.length-1,onClick:()=>t.moveSource(n.id,1),children:"Move down"})]})}},{key:"scope",label:"Attached to",value:n=>n.projectId===null?"Organization source":"Project source",render:n=>(0,a.jsxs)("div",{className:"grid gap-1",children:[(0,a.jsx)("span",{children:n.projectId===null?"Organization source":"Project source"}),t.project===null&&"attachedProjectCount"in n?(0,a.jsx)(je,{variant:"secondary",children:`Attached to ${n.attachedProjectCount} projects`}):null,"attached"in n?(0,a.jsx)("span",{className:"text-xs text-neutral-600",children:n.attached?"Attached to this project":"Not attached to this project"}):null]})},{key:"credential",label:"Credentials",value:n=>n.hasCredential?"Set \xB7 write-only":"None",render:n=>n.hasCredential?(0,a.jsx)(je,{variant:"outline",children:"Set \xB7 write-only"}):"None"},{key:"sync",label:"Sync status",value:n=>n.lastSuccessAt??"",render:n=>(0,a.jsx)(Kt,{source:n})},{key:"id",label:"Source ID",value:n=>n.id,priority:3,render:n=>(0,a.jsx)(te,{value:n.id,label:"source ID"})},{key:"actions",label:"Actions",value:()=>"",sortable:!1,render:n=>(0,a.jsxs)("div",{className:"flex flex-wrap items-start gap-2",children:[t.project!==null&&"attached"in n?n.attached?(0,a.jsx)(ke,{action:"Detach",target:`${n.name} (${n.id})`,scope:`Project: ${t.project}`,description:"Detaching this source stops this project from resolving packages through it. You can attach it again later.",disabled:e.busy,onConfirm:()=>{t.attachment(n.id,!1)}}):(0,a.jsx)(N,{type:"button",size:"sm",variant:"outline",disabled:e.busy,onClick:()=>{t.attachment(n.id,!0)},children:"Attach"}):null,(0,a.jsx)(Yt,{source:n,model:t,busy:e.busy})]})}]})]}):null,e.next!==null?(0,a.jsx)(N,{type:"button",className:"w-fit",disabled:e.loading||e.busy,onClick:()=>{t.load(!0)},children:"Load more sources"}):null,e.availableNext!==null?(0,a.jsx)(N,{type:"button",className:"w-fit",disabled:e.availableLoading||e.busy,onClick:()=>{t.loadAvailable(!0)},children:"Load more organization sources"}):null,e.packageSource!==null?(0,a.jsx)(ht,{source:e.packageSource,busy:e.busy,fieldError:e.packageFieldError,alert:e.packageAlert,onSubmit:n=>{t.addPackage(n)},onClose:()=>t.closePackage()},e.packageSource.id):null,e.credentialSource!==null?(0,a.jsx)(Y,{open:!0,onOpenChange:n=>{n||t.closeCredential()},children:(0,a.jsxs)(W,{variant:"source",onCancel:n=>{e.busy&&n.preventDefault()},children:[(0,a.jsxs)(re,{className:"shrink-0 p-6 pr-16",children:[(0,a.jsx)(X,{children:w?"Add GitHub token (optional)":"Set credential"}),(0,a.jsxs)(J,{children:["Credentials are write-only. Save a new credential to rotate a secret.",w?" This optional bearer token is used only for GitHub archive downloads and their rate limits. Enable Use GitHub token in Edit after saving it.":""]})]}),(0,a.jsxs)("div",{className:"grid min-h-0 gap-3 overflow-y-auto px-6 pb-6",children:[(0,a.jsx)(te,{value:e.credentialSource,label:"source ID"}),(0,a.jsx)(Vt,{model:t,source:e.credentialSource,initialKind:e.credentialKind,kinds:e.credentialKinds,busy:e.busy},e.credentialVersion),e.error?(0,a.jsx)("p",{role:"alert",children:e.error}):null,e.savedCredential?.source===e.credentialSource?(0,a.jsxs)("p",{children:["credential set \xB7 ",(0,a.jsx)(ge,{value:e.savedCredential.at})]}):null]})]})}):null,e.savedCredential&&e.credentialSource===null?(0,a.jsxs)("p",{children:["credential set \xB7 ",e.savedCredential.source," \xB7"," ",(0,a.jsx)(ge,{value:e.savedCredential.at})]}):null,e.names?(0,a.jsx)(Y,{open:!0,onOpenChange:n=>{n||t.closeNames()},children:(0,a.jsxs)(W,{variant:"source",onCancel:n=>{e.busy&&n.preventDefault()},children:[(0,a.jsxs)(re,{className:"shrink-0 p-6 pr-16",children:[(0,a.jsx)(X,{children:"Registered names"}),(0,a.jsx)(J,{children:"Manage the package patterns registered for this source. For npm, use an exact lowercase name or @scope/*. A scope claim hides public packages in that scope that are not yet cached."})]}),(0,a.jsxs)("div",{className:"grid min-h-0 gap-3 overflow-y-auto px-6 pb-6",children:[e.error?(0,a.jsx)("p",{role:"alert",children:e.error}):null,(0,a.jsx)(te,{value:e.names.source,label:"source ID"}),(0,a.jsx)("ul",{children:e.names.items.map(n=>(0,a.jsxs)("li",{className:"flex items-center gap-3",children:[(0,a.jsx)("span",{children:n.pattern}),(0,a.jsx)(ke,{action:`Remove ${n.pattern}`,target:n.pattern,scope:t.project===null?"Organization":`Project: ${t.project}`,description:"Removing this registered pattern can stop the source from resolving matching packages. Add the pattern again to restore it.",disabled:e.busy,onConfirm:()=>{t.removeName(n.sourceId,n.id)}})]},n.id))}),e.names.next!==null?(0,a.jsx)(N,{type:"button",disabled:e.busy,onClick:()=>{t.names(e.names.source,!0)},children:"Load more names"}):null,(0,a.jsxs)("form",{className:"grid gap-3",onSubmit:n=>{if(n.preventDefault(),e.busy)return;let d=n.currentTarget,C=Ct(d,"pattern");t.addName(e.names.source,C)},children:[(0,a.jsx)(L,{htmlFor:"registered-pattern",children:"Registered pattern"}),(0,a.jsx)($,{id:"registered-pattern",name:"pattern",maxLength:e.items.find(n=>n.id===e.names?.source)?.ecosystem==="npm"?214:50,required:!0,defaultValue:l[0]??""},`${e.names.source}:${e.names.items.map(n=>n.pattern).join(",")}`),l.map(n=>(0,a.jsxs)("p",{className:"text-sm",children:["Register ",n," before enabling this source."]},n)),(0,a.jsx)(N,{type:"submit",className:"w-fit",disabled:e.busy,children:"Add name"})]})]})]})}):null,t.project!==null&&!e.listError&&e.items.some(n=>"attached"in n&&n.attached)?(0,a.jsxs)(Ae,{children:[(0,a.jsx)(Ie,{children:(0,a.jsx)(Le,{children:"Source order"})}),(0,a.jsxs)(Te,{className:"grid gap-3",children:[(0,a.jsx)("p",{children:"Earlier sources take precedence. Only attached sources are ordered."}),e.next!==null?(0,a.jsx)("p",{children:"Load all sources before changing their order."}):null,(0,a.jsx)(N,{type:"button",className:"w-fit",disabled:e.loading||e.busy||e.next!==null||e.etag===null,onClick:()=>{t.saveOrder()},children:"Save source order"})]})]}):null,t.project!==null?(0,a.jsxs)(Ae,{children:[(0,a.jsx)(Ie,{children:(0,a.jsx)(Le,{children:"Who wins"})}),(0,a.jsxs)(Te,{className:"grid gap-3",children:[(0,a.jsxs)("form",{className:"grid gap-3",onSubmit:n=>{n.preventDefault(),!e.busy&&t.resolve(Ct(n.currentTarget,"name"))},children:[(0,a.jsx)(L,{htmlFor:"resolve-name",children:"Package name"}),(0,a.jsx)($,{id:"resolve-name",name:"name",maxLength:214,required:!0}),(0,a.jsx)(N,{type:"submit",className:"w-fit",disabled:e.busy,children:"Preview"})]}),e.preview?(0,a.jsxs)("div",{"aria-live":"polite",children:[(0,a.jsx)("p",{children:e.preview.name}),(0,a.jsxs)("p",{children:["Winning source: ",(0,a.jsx)(te,{value:e.preview.winner,label:"winning source ID"})]}),(0,a.jsx)("ol",{children:e.preview.candidates.map(n=>(0,a.jsxs)("li",{children:[n.sourceName," \xB7"," ",(0,a.jsx)(te,{value:n.sourceId,label:"candidate source ID"})," \xB7"," ",n.eligible?"Eligible":"Ineligible"]},n.sourceId))})]}):null]})]}):null]})}function Et(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.hash.split("?")[1]??"").get("project");return new URLSearchParams(Qe("sources",{project:t}).split("?")[1]??"").get("project")}function nr(){let t=Ze(),[e,r]=(0,O.useState)(Et);(0,O.useEffect)(()=>{let o=()=>r(Et());return window.addEventListener("hashchange",o),()=>window.removeEventListener("hashchange",o)},[]);let s=(0,O.useMemo)(()=>zt(t,e),[t,e]);return(0,O.useEffect)(()=>(s.load(),s.loadAvailable(),s.loadMutationPermissions().then(()=>{s.snapshot().canWriteSources&&new URLSearchParams(window.location.hash.split("?")[1]).get("create")==="vcs"&&s.openEditor()}),()=>s.dispose()),[s]),(0,O.useEffect)(()=>t.subscribeReplay?.(o=>{s.replayed(o)}),[t,s]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(Xt,{model:s},e??"organization"),e===null?(0,a.jsx)(gt,{services:t}):null]})}export{at as a,it as b,ot as c,st as d,lt as e,Qt as f,Oe as g,Fe as h,He as i,mt as j,Z as k,Ve as l,$t as m,Bt as n,he as o,zt as p,Gt as q,Ut as r,Ue as s,Yt as t,Wt as u,Xt as v,nr as w};
@@ -0,0 +1 @@
1
+ import{b as h}from"./chunk.f0fd799728ef.js";import{a as L,c as b}from"./chunk.56e058d97e0f.js";import"./chunk.75e1357175af.js";import{a as f}from"./chunk.dc41ee9219cf.js";import{A,B as w,C as N,D as m,E as C,F as D,K as R,c as g,d as B,g as y,p as d,x as I,y as k,z as x}from"./chunk.837eb41f53ef.js";var u=g(B(),1);var e=g(y(),1);function S(a){return{id:a.id,state:a.state,planHash:a.planHash,approvedAt:a.approvedAt,approvedByUserId:a.approvedByUserId,acceptedAt:a.acceptedAt,beforeImageExpiresAt:a.beforeImageExpiresAt}}function v(a,t,s=Date.now()){if(t==="approve")return a.state==="planned"&&!!a.planHash&&a.approvedAt===null;if(t==="apply"){let i=a.approvedAt===null?NaN:Date.parse(a.approvedAt);return a.state==="planned"&&Number.isFinite(i)&&i<=s+6e4}return t==="cancel"?a.state==="planned":["failed","applied","verifying","verified"].includes(a.state)&&(a.beforeImageExpiresAt===null||Date.parse(a.beforeImageExpiresAt)>s)}function H(a){let t={runs:[],next:null,run:null,selectedId:null,loading:!1,detailLoading:!1,busy:!1,dialog:!1,confirmed:!1,error:null,notice:null},s=0,i=0,c=new Set,n=o=>{t={...t,...o};for(let l of c)l()},r={back(){++s,n({run:null,selectedId:null,detailLoading:!1,dialog:!1,confirmed:!1,error:null,notice:null})},snapshot:()=>t,subscribe(o){return c.add(o),()=>{c.delete(o)}},async load(o){let l=++i;n({loading:!0,error:null,cursor:o});let p=await a.client.request("get","/_pb/import-runs",{query:{cursor:o}});l===i&&n(p.ok?{runs:p.data.items.map(S),next:p.data.next,loading:!1}:{runs:[],next:null,loading:!1,error:"Unable to load import runs."})},async select(o){if(t.busy)return;let l=++s;n({run:null,selectedId:o,detailLoading:!0,dialog:!1,confirmed:!1,error:null,notice:null});let p=await a.client.request("get","/_pb/import-runs/{id}",{params:{id:o}});l===s&&n(p.ok?{run:S(p.data),detailLoading:!1}:{detailLoading:!1,error:"Unable to load the import run."})},openApproval(){!t.busy&&t.run?.state==="planned"&&t.run.planHash&&t.run.approvedAt===null&&n({dialog:!0,confirmed:!1})},closeApproval(){t.busy||n({dialog:!1,confirmed:!1})},confirmApproval(o){t.dialog&&!t.busy&&n({confirmed:o})},async action(o){let l=t.run;if(l===null||t.busy||!v(l,o)||o==="approve"&&(!t.dialog||!t.confirmed||!l.planHash||l.state!=="planned"||l.approvedAt!==null))return;n({busy:!0,error:null,notice:null});let p=o==="approve"?await a.client.request("post","/_pb/import-runs/{id}/approve",{params:{id:l.id},body:{planHash:l.planHash}}):await a.client.request("post",`/_pb/import-runs/{id}/${o}`,{params:{id:l.id}});if(n({busy:!1,dialog:!1,confirmed:!1}),!p.ok){p.code==="reauth_required"?a.requireReauth(p.request,{credential:!1,secretFields:[]}):n({error:p.code==="conflict"?"The run changed. Reload it and try again.":"Unable to update the import run."});return}await r.select(l.id),await r.load(t.cursor),n({notice:"Action accepted. Reload to check job progress."})}};return r}function E({state:a,controller:t,onSelect:s,onBack:i,onPage:c}){let n=a.run,[r,o]=(0,u.useState)(Date.now);return(0,u.useEffect)(()=>{let l=window.setInterval(()=>o(Date.now()),1e3);return()=>window.clearInterval(l)},[]),(0,e.jsxs)("section",{"aria-labelledby":"page-heading",className:"space-y-4",children:[(0,e.jsx)("h1",{tabIndex:-1,id:"page-heading",className:"text-2xl font-semibold",children:"Import"}),(0,e.jsx)("p",{children:"Upload credentials with the CLI. Import manifests are managed with the CLI."}),a.selectedId&&n===null?(0,e.jsx)(d,{type:"button",variant:"link",className:"px-0",disabled:a.busy,onClick:()=>i?i():t.back(),children:"\u2190 Back to import runs"}):null,a.error===null?null:(0,e.jsx)(b,{kind:"error",title:a.error,children:(0,e.jsx)(d,{type:"button",variant:"outline",disabled:a.busy||a.loading,onClick:()=>{a.selectedId?t.select(a.selectedId):t.load(a.cursor)},children:"Retry"})}),a.notice===null?null:(0,e.jsx)("p",{role:"status",children:a.notice}),(0,e.jsx)(d,{type:"button",variant:"outline",disabled:a.loading||a.busy,onClick:()=>{t.load(a.cursor)},children:"Reload runs"}),a.loading?(0,e.jsx)(b,{kind:"loading",title:"Loading import runs\u2026"}):null,a.detailLoading?(0,e.jsx)(b,{kind:"loading",title:"Loading import run\u2026"}):null,n===null&&!a.detailLoading&&!a.loading?a.runs.length?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(L,{label:"Import runs",items:a.runs,columns:[{key:"id",label:"Run",value:l=>l.id,render:l=>(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[(0,e.jsxs)(d,{type:"button",variant:"link",className:"h-auto p-0 font-mono",disabled:a.busy,onClick:()=>s?s(l.id):void t.select(l.id),children:["Run ",l.id.slice(0,6),"\u2026",l.id.slice(-4)]}),(0,e.jsx)(m,{value:l.id,label:"run ID"})]})},{key:"state",label:"State",value:l=>l.state,render:l=>(0,e.jsx)(h,{status:l.state})},{key:"hash",label:"Plan hash",value:l=>l.planHash??"",render:l=>l.planHash?(0,e.jsx)(m,{value:l.planHash,label:"plan hash"}):"No plan hash"},{key:"approved",label:"Approved",priority:2,value:l=>l.approvedAt??"",render:l=>(0,e.jsx)(f,{value:l.approvedAt,fallback:"Not approved"})},{key:"accepted",label:"Accepted",priority:3,value:l=>l.acceptedAt??"",render:l=>(0,e.jsx)(f,{value:l.acceptedAt,fallback:"Not accepted"})},{key:"expires",label:"Before-image expires",priority:3,value:l=>l.beforeImageExpiresAt??"",render:l=>(0,e.jsx)(f,{value:l.beforeImageExpiresAt,fallback:"Not scheduled"})}]}),(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)(d,{type:"button",variant:"outline",disabled:!a.cursor||a.busy,onClick:()=>c?c():void t.load(),children:"First page"}),(0,e.jsx)(d,{type:"button",variant:"outline",disabled:!a.next||a.busy,onClick:()=>{a.next&&(c?c(a.next):t.load(a.next))},children:"Next page"})]})]}):a.error?null:(0,e.jsx)(b,{kind:a.cursor?"filtered-empty":"empty",title:a.cursor?"No import runs on this page":"No import runs.",children:"Create an import plan with the CLI to get started."}):null,n===null?null:(0,e.jsxs)("section",{"aria-labelledby":"run-heading",className:"space-y-3",children:[(0,e.jsx)(d,{type:"button",variant:"link",className:"px-0",disabled:a.busy,onClick:()=>i?i():t.back(),children:"\u2190 Back to import runs"}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,e.jsxs)("h2",{id:"run-heading",className:"text-lg font-semibold",children:["Run ",(0,e.jsx)(m,{value:n.id,label:"run ID"})]}),(0,e.jsx)(h,{status:n.state})]}),(0,e.jsxs)("div",{className:"detail-grid",children:[(0,e.jsxs)("div",{className:"detail-group",children:[(0,e.jsx)("h3",{children:"Plan"}),(0,e.jsxs)("dl",{className:"detail-list",children:[(0,e.jsx)("dt",{children:"Plan hash"}),(0,e.jsx)("dd",{children:n.planHash?(0,e.jsx)(m,{value:n.planHash,label:"full plan hash",full:!0}):"No plan hash"}),(0,e.jsx)("dt",{children:"Run ID"}),(0,e.jsx)("dd",{children:(0,e.jsx)(m,{value:n.id,label:"run ID"})})]})]}),(0,e.jsxs)("div",{className:"detail-group",children:[(0,e.jsx)("h3",{children:"Approval"}),(0,e.jsxs)("dl",{className:"detail-list",children:[(0,e.jsx)("dt",{children:"Approved at"}),(0,e.jsx)("dd",{children:(0,e.jsx)(f,{value:n.approvedAt,fallback:"Not approved"})}),(0,e.jsx)("dt",{children:"Approved by"}),(0,e.jsx)("dd",{children:(0,e.jsx)(m,{value:n.approvedByUserId,label:"approving user ID"})})]})]}),(0,e.jsxs)("div",{className:"detail-group",children:[(0,e.jsx)("h3",{children:"Execution and retention"}),(0,e.jsxs)("dl",{className:"detail-list",children:[(0,e.jsx)("dt",{children:"Accepted at"}),(0,e.jsx)("dd",{children:(0,e.jsx)(f,{value:n.acceptedAt,fallback:"Not accepted"})}),(0,e.jsx)("dt",{children:"Before-image expires"}),(0,e.jsx)("dd",{children:(0,e.jsx)(f,{value:n.beforeImageExpiresAt,fallback:"Not scheduled"})})]})]})]}),(0,e.jsx)("h3",{className:"font-semibold",children:"Actions"}),(0,e.jsx)("p",{className:"text-sm text-neutral-600",children:"Apply requires an approved plan. Cancel is available for planned runs. Rollback is available after execution while before-images are retained."}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsx)(d,{type:"button",variant:"outline",disabled:a.busy,onClick:()=>{t.select(n.id)},children:"Reload run"}),(0,e.jsx)(d,{type:"button",disabled:a.busy||!v(n,"approve",r),onClick:()=>t.openApproval(),children:"Review approval"}),["apply","cancel","rollback"].map(l=>(0,e.jsx)(d,{type:"button",variant:l==="apply"?"outline":"ghost",className:l==="apply"?void 0:"text-red-700",disabled:a.busy||!v(n,l,r),title:v(n,l,r)?void 0:"Unavailable in the current state or retention window.",onClick:()=>{t.action(l)},children:l==="apply"?"Apply":l==="cancel"?"Cancel run":"Rollback"},l))]})]}),a.dialog&&n!==null?(0,e.jsx)(I,{open:!0,onOpenChange:l=>{l||t.closeApproval()},children:(0,e.jsx)(k,{onCancel:l=>{a.busy&&l.preventDefault()},children:(0,e.jsxs)("form",{className:"grid gap-4",onSubmit:l=>{l.preventDefault(),!(a.busy||!a.confirmed)&&t.action("approve")},children:[(0,e.jsxs)(x,{children:[(0,e.jsx)(w,{children:"Approve import run"}),(0,e.jsx)(N,{children:"Confirm the full plan hash for the plan you reviewed with the CLI."})]}),(0,e.jsx)("p",{className:"break-all",children:(0,e.jsx)("code",{children:n.planHash})}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(C,{id:"confirm-plan",type:"checkbox",className:"h-4 w-4",checked:a.confirmed,disabled:a.busy,onChange:l=>t.confirmApproval(l.currentTarget.checked)}),(0,e.jsx)(D,{htmlFor:"confirm-plan",children:"I confirm this plan hash."})]}),(0,e.jsxs)(A,{children:[(0,e.jsx)(d,{type:"button",variant:"outline",disabled:a.busy,onClick:()=>t.closeApproval(),children:"Back"}),(0,e.jsx)(d,{type:"submit",disabled:!a.confirmed||a.busy,children:"Approve run"})]})]})})}):null]})}function O(){let a=R(),t=(0,u.useMemo)(()=>H(a),[a]),s=(0,u.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),[i,c]=(0,u.useState)(()=>window.location.hash);(0,u.useEffect)(()=>{let r=()=>c(window.location.hash);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]),(0,u.useEffect)(()=>{let r=new URLSearchParams(i.split("?")[1]);t.load(r.get("cursor")??void 0);let o=r.get("run");o?t.select(o):t.back()},[t,i]);let n=(r,o)=>{let l=new URLSearchParams(i.split("?")[1]);o?l.set(r,o):l.delete(r),r==="cursor"&&l.delete("run"),window.location.hash=`#/import${l.size?`?${l}`:""}`};return(0,e.jsx)(E,{state:s,controller:t,onSelect:r=>n("run",r),onBack:()=>n("run"),onPage:r=>n("cursor",r)})}export{O as ImportPage,E as ImportView,H as createImportController,v as importActionAllowed};
@@ -4,12 +4,15 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Package Broker</title>
7
- <link rel="stylesheet" href="app.f15f8f21f88b.css" />
8
- <link rel="modulepreload" href="chunk.976a2ff4338e.js" />
9
- <link rel="modulepreload" href="chunk.6e23a75a1324.js" />
10
- <link rel="modulepreload" href="chunk.7cb6f6b4daaa.js" />
11
- <link rel="modulepreload" href="chunk.f922af39a279.js" />
12
- <script type="module" src="app.e8434f3343de.js"></script>
7
+ <link rel="stylesheet" href="app.ec678c27ec0a.css" />
8
+ <link rel="modulepreload" href="chunk.675b635d9462.js" />
9
+ <link rel="modulepreload" href="chunk.ab1a14143dc6.js" />
10
+ <link rel="modulepreload" href="chunk.837eb41f53ef.js" />
11
+ <link rel="modulepreload" href="chunk.815f9a91c741.js" />
12
+ <link rel="modulepreload" href="chunk.4721d4544d48.js" />
13
+ <link rel="modulepreload" href="chunk.75e1357175af.js" />
14
+ <link rel="modulepreload" href="chunk.3f077ff17cea.js" />
15
+ <script type="module" src="app.fba0d059b40b.js"></script>
13
16
  </head>
14
17
  <body>
15
18
  <div id="root"></div>
@@ -4,95 +4,123 @@
4
4
  "files": {
5
5
  "index.html": {
6
6
  "contentType": "text/html",
7
- "bytes": 611
7
+ "bytes": 797
8
8
  },
9
9
  "setup.html": {
10
10
  "contentType": "text/html",
11
11
  "bytes": 464
12
12
  },
13
- "chunk.6e23a75a1324.js": {
13
+ "chunk.675b635d9462.js": {
14
14
  "contentType": "text/javascript",
15
- "bytes": 83178
15
+ "bytes": 3251
16
16
  },
17
- "chunk.976a2ff4338e.js": {
17
+ "chunk.837eb41f53ef.js": {
18
18
  "contentType": "text/javascript",
19
- "bytes": 182273
19
+ "bytes": 88205
20
20
  },
21
- "chunk.7cb6f6b4daaa.js": {
21
+ "chunk.ab1a14143dc6.js": {
22
22
  "contentType": "text/javascript",
23
23
  "bytes": 242
24
24
  },
25
- "chunk.f922af39a279.js": {
25
+ "chunk.815f9a91c741.js": {
26
+ "contentType": "text/javascript",
27
+ "bytes": 1315
28
+ },
29
+ "chunk.75e1357175af.js": {
30
+ "contentType": "text/javascript",
31
+ "bytes": 1694
32
+ },
33
+ "chunk.4721d4544d48.js": {
34
+ "contentType": "text/javascript",
35
+ "bytes": 179256
36
+ },
37
+ "chunk.3f077ff17cea.js": {
26
38
  "contentType": "text/javascript",
27
39
  "bytes": 379
28
40
  },
29
- "chunk.3704953b4a66.js": {
41
+ "chunk.53134c7df4e5.js": {
30
42
  "contentType": "text/javascript",
31
43
  "bytes": 2221
32
44
  },
33
- "chunk.862544cf5835.js": {
45
+ "chunk.56e058d97e0f.js": {
34
46
  "contentType": "text/javascript",
35
- "bytes": 41926
47
+ "bytes": 41963
36
48
  },
37
- "chunk.bb25fc845269.js": {
49
+ "chunk.4acf8fa7653f.js": {
38
50
  "contentType": "text/javascript",
39
51
  "bytes": 4075
40
52
  },
41
- "chunk.bf48b04e6a00.js": {
53
+ "chunk.f0fd799728ef.js": {
42
54
  "contentType": "text/javascript",
43
- "bytes": 1120
55
+ "bytes": 2178
44
56
  },
45
- "chunk.855a50f45830.js": {
57
+ "chunk.304a2b5d1663.js": {
46
58
  "contentType": "text/javascript",
47
- "bytes": 1793
59
+ "bytes": 1120
48
60
  },
49
- "projects.711deb86b7c9.js": {
61
+ "projects.44006a838c67.js": {
50
62
  "contentType": "text/javascript",
51
- "bytes": 19063
63
+ "bytes": 19234
52
64
  },
53
- "chunk.ce96495b8b55.js": {
65
+ "chunk.dc41ee9219cf.js": {
54
66
  "contentType": "text/javascript",
55
67
  "bytes": 457
56
68
  },
57
- "access.6859f43998ca.js": {
69
+ "access.def9a17dc4a8.js": {
70
+ "contentType": "text/javascript",
71
+ "bytes": 26648
72
+ },
73
+ "chunk.2c3648a5bad1.js": {
74
+ "contentType": "text/javascript",
75
+ "bytes": 1645
76
+ },
77
+ "chunk.fac952720b72.js": {
78
+ "contentType": "text/javascript",
79
+ "bytes": 79737
80
+ },
81
+ "chunk.e3b0c44298fc.js": {
82
+ "contentType": "text/javascript",
83
+ "bytes": 0
84
+ },
85
+ "sources.d95aabfbec73.js": {
58
86
  "contentType": "text/javascript",
59
- "bytes": 26627
87
+ "bytes": 806
60
88
  },
61
- "chunk.297a2d571f9c.js": {
89
+ "packages.bdd474bcfc11.js": {
62
90
  "contentType": "text/javascript",
63
- "bytes": 57183
91
+ "bytes": 70261
64
92
  },
65
- "sources.d0ba0048bd96.js": {
93
+ "npm-login.d8b60e11fe87.js": {
66
94
  "contentType": "text/javascript",
67
- "bytes": 646
95
+ "bytes": 3728
68
96
  },
69
- "packages.a8726e5144de.js": {
97
+ "tokens.4ee13a722abb.js": {
70
98
  "contentType": "text/javascript",
71
- "bytes": 31606
99
+ "bytes": 63356
72
100
  },
73
- "tokens.f48d235e8d25.js": {
101
+ "notifications.bd7d4c3f9882.js": {
74
102
  "contentType": "text/javascript",
75
- "bytes": 52901
103
+ "bytes": 30808
76
104
  },
77
- "audit.576009342714.js": {
105
+ "audit.453367b59daf.js": {
78
106
  "contentType": "text/javascript",
79
- "bytes": 6095
107
+ "bytes": 6127
80
108
  },
81
- "import.e2a1e35fcb8d.js": {
109
+ "import.4275bbce08ac.js": {
82
110
  "contentType": "text/javascript",
83
- "bytes": 10445
111
+ "bytes": 10472
84
112
  },
85
- "app.e8434f3343de.js": {
113
+ "app.fba0d059b40b.js": {
86
114
  "contentType": "text/javascript",
87
- "bytes": 217347
115
+ "bytes": 217905
88
116
  },
89
- "setup.dfed30ecfbad.js": {
117
+ "setup.7bc86366227c.js": {
90
118
  "contentType": "text/javascript",
91
- "bytes": 15648
119
+ "bytes": 17028
92
120
  },
93
- "app.f15f8f21f88b.css": {
121
+ "app.ec678c27ec0a.css": {
94
122
  "contentType": "text/css",
95
- "bytes": 31145
123
+ "bytes": 32217
96
124
  }
97
125
  }
98
126
  }
@@ -0,0 +1 @@
1
+ import{b as J,c as ie}from"./chunk.815f9a91c741.js";import{a as z,b as le}from"./chunk.2c3648a5bad1.js";import"./chunk.4721d4544d48.js";import{b as X}from"./chunk.f0fd799728ef.js";import{a as ae}from"./chunk.304a2b5d1663.js";import{a as V,c as A}from"./chunk.56e058d97e0f.js";import"./chunk.75e1357175af.js";import{a as $}from"./chunk.dc41ee9219cf.js";import{a as ne}from"./chunk.3f077ff17cea.js";import{E as O,F as R,K as te,c as _,d as G,g as F,m as Q,n as ee,p as w}from"./chunk.837eb41f53ef.js";var N=_(G(),1);var K=[{value:"npm.package.published",label:"Version published",help:"A new local version is available immediately after publishing."},{value:"npm.package.released",label:"Held version released",help:"A version held for approval or scanning becomes available."},{value:"npm.package.unpublished",label:"Version or package removed",help:"A version or the whole package is unpublished or tombstoned."},{value:"npm.package.deprecation_changed",label:"Deprecation changed",help:"A version is deprecated or its deprecation is cleared. The message is not sent."},{value:"npm.package.dist_tag_changed",label:"Dist-tag changed",help:"A dist-tag is added, moved or deleted, including moves caused by an unpublish."}],B=n=>K.find(a=>a.value===n)?.label??"Unknown event";function se(n){if(n.state==="enabled")return"Sending new events.";switch(n.disabledReason){case"configuration_changed":return"Disabled because its delivery settings were replaced. Enable it to resume sending.";case"failures":return"Disabled after 10 deliveries in a row failed. Check the receiver, then enable it.";case"credentials":return"Disabled because the receiver refused the request (401 or 403). Replace the delivery settings, then enable it.";case"policy":return"Disabled because the destination is not allowed. Replace the destination, then enable it.";case"gone":return"Disabled because the receiver reported that it no longer exists (410).";case"manual":return"Disabled. No events are sent until it is enabled.";default:return"Not enabled yet. No events are sent until it is enabled."}}var me={ok:"Delivered",network:"Could not connect",timeout:"Receiver did not answer in time",http_retry:"Receiver asked to retry",http_permanent:"Receiver refused the event",redirect:"Receiver answered with a redirect, which is not followed",policy:"Destination not allowed",credentials:"Delivery settings could not be used",template:"Body template could not be applied",unknown:"Result unknown; the receiver may have processed it",expired:"Expired after 24 hours",attempt_limit:"Stopped after 8 attempts",disabled:"Cancelled because the endpoint was disabled",superseded:"Cancelled because the endpoint changed",project_inactive:"Cancelled because the project is archived",admission_lost:"Cancelled because the source left the project",deleted:"Cancelled because the endpoint was deleted"};function U(n){return n.state==="pending"?"Waiting to send":n.state==="sending"?"Sending":n.outcomeCode===null?"Finished":me[n.outcomeCode]}function ve(n){if(n.status===412||n.status===428||n.code==="conflict")return"This endpoint changed while you were editing. Reload the latest settings before saving.";switch(n.code){case"invalid_configuration":return"The broker refused these settings. Use an HTTPS address on a public host, a 43-character signing key, permitted headers and a valid template.";case"invalid_request":return"Check the entered values and try again.";case"endpoint_limit":return"This project already has 20 notification endpoints. Remove one before adding another.";case"transport_unavailable":return"This broker cannot send notifications, so the endpoint cannot be enabled.";case"forbidden":return"You do not have permission to change notifications in this project.";case"not_found":return"This endpoint no longer exists. Reload the list.";default:return"The request could not be completed. Try again."}}var ge=n=>({params:{project:n}}),Z=(n,a)=>({params:{project:n,id:a.id},headers:{"If-Match":`"r${a.revision}"`}});function I(n,a,e){return a.code==="reauth_required"?(n.requireReauth(e?{method:a.request.method,path:a.request.path}:a.request,{credential:e,secretFields:[]}),{ok:!1,reauth:!0,stale:!1,message:e?"Reauthenticate, then enter the delivery settings again. Nothing was saved.":"Reauthentication is required. Confirm the action again after signing in."}):{ok:!1,reauth:!1,stale:a.status===412||a.status===428||a.code==="conflict",message:ve(a)}}var M={ok:!1,message:"",stale:!1,reauth:!1};async function oe(n,a,e,t,o=()=>!0){let r=await n.client.request("post","/_pb/projects/{project}/notifications",{...ge(a),body:{...e,secret:t}});return o()?r.ok?{ok:!0,endpoint:r.data,message:"Endpoint added. It stays disabled until you enable it."}:(r.code==="reauth_required"&&J(a,null,e),I(n,r,!0)):M}async function re(n,a,e,t,o=()=>!0){let r=await n.client.request("patch","/_pb/projects/{project}/notifications/{id}",{...Z(a,e),body:t});return o()?r.ok?{ok:!0,endpoint:r.data,message:t.secret===void 0?"Endpoint saved. Waiting deliveries for the previous settings were cancelled.":"Delivery settings replaced. The endpoint is disabled and waiting deliveries were cancelled; enable it to resume."}:(r.code==="reauth_required"&&t.secret!==void 0&&t.options!==void 0&&J(a,e,t.options),I(n,r,t.secret!==void 0)):M}async function W(n,a,e,t,o=()=>!0){let r=await n.client.request("post",t?"/_pb/projects/{project}/notifications/{id}/enable":"/_pb/projects/{project}/notifications/{id}/disable",Z(a,e));return o()?r.ok?{ok:!0,endpoint:r.data,message:t?"Endpoint enabled. Only events from now on are sent; earlier events are not replayed.":"Endpoint disabled. No new events are sent; waiting deliveries are cancelled."}:I(n,r,!1):M}async function de(n,a,e,t=()=>!0){let o=await n.client.request("delete","/_pb/projects/{project}/notifications/{id}",Z(a,e));return t()?o.ok?{ok:!0,endpoint:null,message:"Endpoint removed. Its waiting deliveries were cancelled."}:I(n,o,!1):M}var j=_(G(),1);var l=_(F(),1),fe={id:"01JEXAMPLEEVENT00000000000",operationId:"01JEXAMPLE0PERATI0N0000000",organizationId:"01JEXAMPLE0RGANIZATI0N0000",projectId:"01JEXAMPLEPR0JECT000000000"},he={"npm.package.published":{},"npm.package.released":{releaseCause:"approval_and_scan"},"npm.package.unpublished":{removalScope:"version",removalKind:"window"},"npm.package.deprecation_changed":{deprecated:!0},"npm.package.dist_tag_changed":{tag:"latest",previousVersion:"1.2.2",version:"1.2.3",cause:"explicit"}};function ye(n){return{schemaVersion:1,...fe,type:n,occurredAt:"2026-11-01T12:00:00.000Z",package:{ecosystem:"npm",name:"@example/library",version:"1.2.3"},data:he[n]}}function be(n,a){let e=n;for(let t of a.split(".")){if(e===null||typeof e!="object"||!Object.hasOwn(e,t))return;e=e[t]}return e}function ke(n,a){let e=ye(n);if(a.trim()==="")return JSON.stringify(e,null,2);let t;try{t=JSON.parse(a)}catch{return"The template is not valid JSON."}let o=!1,r=d=>{if(Array.isArray(d))return d.map(r);if(d!==null&&typeof d=="object")return Object.fromEntries(Object.entries(d).map(([P,u])=>[P,r(u)]));let m=typeof d=="string"?/^\{\{([A-Za-z.]+)\}\}$/.exec(d):null;if(m===null)return d;let y=be(e,m[1]);return(y===void 0||y!==null&&typeof y=="object")&&(o=!0),y},f=r(t);return o?"The template names a value this event does not have.":JSON.stringify(f,null,2)}var H={url:"",signingKey:"",template:"",headers:[]};function ce(n){let a=(0,j.useId)(),e=n.endpoint,[t,o]=(0,j.useState)(()=>n.restoredOptions??{name:e?.name??"",method:e?.method??"POST",events:[...e?.events??["npm.package.published"]],packagePattern:e?.packagePattern??"*"}),[r,f]=(0,j.useState)(e===null||n.requireSecret===!0),[d,m]=(0,j.useState)(H),[y,P]=(0,j.useState)(!1),[u,h]=(0,j.useState)(null),[v,b]=(0,j.useState)(null);(0,j.useEffect)(()=>()=>m(H),[]);let E=e!==null&&[...t.events].sort().join()!==[...e.events].sort().join(),x=e?.templateConfigured===!0&&E&&!r,p=c=>`${a}-${c}`,q=async c=>{if(c.preventDefault(),y||n.disabled)return;if(t.events.length===0){h("Choose at least one event."),document.getElementById(p("events"))?.focus();return}if(x){h("This endpoint has a body template. Replace the delivery settings with a template that fits the new events.");return}P(!0),h(null);let k=await n.onSubmit({options:t,...r?{secret:{url:d.url,signingKey:d.signingKey,headers:d.headers.filter(S=>S.name!==""),template:d.template.trim()===""?null:d.template}}:{}});P(!1),(k.ok||k.reauth)&&(m(H),b(null)),k.ok||h(k.message)};return(0,l.jsxs)("form",{onSubmit:c=>{q(c)},"aria-label":e===null?"New notification endpoint":`Edit ${e.name}`,className:"grid max-w-5xl items-start gap-x-6 gap-y-4 lg:grid-cols-2",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold lg:col-span-2",children:e===null?"New notification endpoint":`Edit ${e.name}`}),(0,l.jsx)("p",{className:"lg:col-span-2",children:`Project ${n.projectName} \xB7 The broker sends a signed HTTPS request to your receiver when a selected package event commits in this project.`}),(0,l.jsxs)("div",{className:"grid gap-1",children:[(0,l.jsx)(R,{htmlFor:p("name"),children:"Name"}),(0,l.jsx)(O,{id:p("name"),required:!0,maxLength:80,value:t.name,onChange:c=>o({...t,name:c.target.value})})]}),(0,l.jsxs)("div",{className:"grid gap-1",children:[(0,l.jsx)(R,{htmlFor:p("pattern"),children:"Package filter"}),(0,l.jsx)(O,{id:p("pattern"),required:!0,maxLength:50,value:t.packagePattern,"aria-describedby":p("pattern-help"),onChange:c=>o({...t,packagePattern:c.target.value})}),(0,l.jsx)("p",{id:p("pattern-help"),className:"text-sm text-neutral-600",children:"* matches any characters, including /. Examples: * for every package, @acme/* for one scope. Matching is exact and case-sensitive on the stored name; legacy package names with capital letters are stored with each capital written as ! followed by the lower-case letter, for example !my!package for MyPackage."})]}),(0,l.jsxs)("fieldset",{id:p("events"),tabIndex:-1,className:"grid gap-2 lg:col-span-2","aria-describedby":p("events-help"),children:[(0,l.jsx)("legend",{className:"font-medium",children:"Events"}),(0,l.jsx)("p",{id:p("events-help"),className:"text-sm text-neutral-600",children:"Only events committed after the endpoint is enabled are sent."}),K.map(c=>(0,l.jsxs)("label",{className:"flex min-h-11 items-start gap-2",children:[(0,l.jsx)("input",{type:"checkbox",className:"mt-1 size-4",checked:t.events.includes(c.value),onChange:k=>o({...t,events:k.target.checked?[...t.events,c.value]:t.events.filter(S=>S!==c.value)})}),(0,l.jsxs)("span",{children:[(0,l.jsx)("span",{className:"font-medium",children:c.label}),(0,l.jsx)("span",{className:"block text-sm text-neutral-600",children:c.help})]})]},c.value))]}),(0,l.jsxs)("fieldset",{className:"grid gap-2 lg:col-span-2",children:[(0,l.jsx)("legend",{className:"font-medium",children:"Request method"}),["POST","PUT"].map(c=>(0,l.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,l.jsx)("input",{type:"radio",name:p("method"),checked:t.method===c,onChange:()=>o({...t,method:c})}),c]},c))]}),e===null?null:(0,l.jsxs)("div",{className:"grid gap-2 lg:col-span-2",children:[(0,l.jsx)("p",{children:`Delivery settings: destination configured, signing key configured, custom headers ${e.headersConfigured?"configured":"none"}, body template ${e.templateConfigured?"configured":"none (standard envelope)"}. Saved settings are never shown again.`}),(0,l.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,l.jsx)("input",{type:"checkbox",checked:r,onChange:c=>{f(c.target.checked),c.target.checked||m(H)}}),"Replace delivery settings (needs recent sign-in; disables the endpoint)"]})]}),r?(0,l.jsxs)("fieldset",{className:"grid gap-4 lg:col-span-2 lg:grid-cols-2",children:[(0,l.jsx)("legend",{className:"font-medium",children:"Delivery settings"}),(0,l.jsxs)("div",{className:"grid gap-1 lg:col-span-2",children:[(0,l.jsx)(R,{htmlFor:p("url"),children:"Destination URL"}),(0,l.jsx)(O,{id:p("url"),type:"url",required:!0,autoComplete:"off",maxLength:2048,value:d.url,"aria-describedby":p("url-help"),onChange:c=>m({...d,url:c.target.value})}),(0,l.jsx)("p",{id:p("url-help"),className:"text-sm text-neutral-600",children:"HTTPS on port 443 to a public host. Redirects are not followed. The address is stored sealed and never shown again, so tokens in the path or query stay private."})]}),(0,l.jsxs)("div",{className:"grid gap-1 lg:col-span-2",children:[(0,l.jsx)(R,{htmlFor:p("key"),children:"Signing key"}),(0,l.jsx)(O,{id:p("key"),type:"password",required:!0,autoComplete:"off",pattern:"[A-Za-z0-9_\\-]{43}",value:d.signingKey,"aria-describedby":p("key-help"),onChange:c=>m({...d,signingKey:c.target.value})}),(0,l.jsx)("p",{id:p("key-help"),className:"text-sm text-neutral-600",children:"32 random bytes as 43 base64url characters, shared with your receiver to verify the X-Package-Broker-Signature header."})]}),(0,l.jsxs)("div",{className:"grid gap-2 lg:col-span-2",children:[(0,l.jsx)("p",{className:"font-medium",children:"Custom headers (optional)"}),(0,l.jsx)("p",{className:"text-sm text-neutral-600",children:"Authorization or X- headers only, up to 16. Values are stored sealed."}),d.headers.map((c,k)=>(0,l.jsxs)("div",{className:"grid gap-2 sm:grid-cols-[1fr_2fr_auto]",children:[(0,l.jsxs)("div",{className:"grid gap-1",children:[(0,l.jsx)(R,{htmlFor:p(`header-name-${k}`),children:"Header name"}),(0,l.jsx)(O,{id:p(`header-name-${k}`),value:c.name,autoComplete:"off",onChange:S=>m({...d,headers:d.headers.map((C,L)=>L===k?{...C,name:S.target.value}:C)})})]}),(0,l.jsxs)("div",{className:"grid gap-1",children:[(0,l.jsx)(R,{htmlFor:p(`header-value-${k}`),children:"Header value"}),(0,l.jsx)(O,{id:p(`header-value-${k}`),type:"password",value:c.value,autoComplete:"off",onChange:S=>m({...d,headers:d.headers.map((C,L)=>L===k?{...C,value:S.target.value}:C)})})]}),(0,l.jsx)(w,{type:"button",variant:"outline",className:"min-h-11 self-end",onClick:()=>m({...d,headers:d.headers.filter((S,C)=>C!==k)}),children:"Remove header"})]},k)),d.headers.length<16?(0,l.jsx)(w,{type:"button",variant:"outline",className:"min-h-11 w-full sm:w-auto",onClick:()=>m({...d,headers:[...d.headers,{name:"",value:""}]}),children:"Add header"}):null]}),(0,l.jsxs)("div",{className:"grid gap-1 lg:col-span-2",children:[(0,l.jsx)(R,{htmlFor:p("template"),children:"Body template (optional)"}),(0,l.jsx)(le,{id:p("template"),rows:5,maxLength:8192,value:d.template,"aria-describedby":p("template-help"),onChange:c=>m({...d,template:c.target.value})}),(0,l.jsxs)("p",{id:p("template-help"),className:"text-sm text-neutral-600",children:["Leave empty to send the standard event envelope. A template is JSON in which a string value written as ",'"{{package.name}}"'," is replaced by that event value. It must fit every selected event."]})]}),(0,l.jsxs)("div",{className:"grid gap-2 lg:col-span-2",children:[(0,l.jsx)(w,{type:"button",variant:"outline",className:"min-h-11 w-full sm:w-auto",disabled:t.events.length===0,onClick:()=>b(ke(t.events[0],d.template)),children:"Preview with example data"}),v===null?null:(0,l.jsx)("pre",{"aria-label":"Example body",className:"max-h-64 overflow-auto rounded-md border bg-neutral-50 p-2 text-xs",children:v})]})]}):null,x?(0,l.jsx)(Q,{className:"lg:col-span-2",children:(0,l.jsx)(ee,{children:"This endpoint has a body template checked against its current events. To change the events, replace the delivery settings with a template that fits them."})}):null,(0,l.jsx)("p",{className:"lg:col-span-2",children:e===null?"The endpoint is added disabled. Adding it needs a recent sign-in. Nothing is sent until you enable it.":"Saving any change, including a rename, starts a new revision and cancels deliveries still waiting for the previous one."}),u===null?null:(0,l.jsx)("p",{role:"alert",className:"text-red-700 lg:col-span-2",children:u}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-2 lg:col-span-2",children:[(0,l.jsx)(w,{type:"submit",className:"min-h-11 w-full sm:w-auto",disabled:y||n.disabled,"aria-busy":y,children:y?e===null?"Adding endpoint\u2026":"Saving endpoint\u2026":e===null?"Add endpoint":"Save endpoint"}),(0,l.jsx)(w,{type:"button",variant:"outline",className:"min-h-11 w-full sm:w-auto",disabled:y,onClick:()=>{m(H),n.onCancel()},children:"Cancel"})]})]})}var ue={project:null,items:[],next:null,hasPrevious:!1,loading:!1,blocked:null,selected:null,deliveries:[],deliveriesNext:null,deliveriesHasPrevious:!1,deliveriesLoading:!1,deliveriesError:!1,filter:"all",detail:null,detailError:!1};function pe(n){let a=ue,e=0,t=0,o=0,r=[void 0],f=[void 0],d=new Set,m=u=>{a={...a,...u};for(let h of d)h()};async function y(){let{project:u,selected:h,filter:v}=a;if(u===null||h===null)return;let b=++o;m({deliveriesLoading:!0,deliveriesError:!1});let E=f[f.length-1],x=await n.client.request("get","/_pb/projects/{project}/notifications/{id}/deliveries",{params:{project:u,id:h},query:{...E===void 0?{}:{cursor:E},...v==="all"?{}:{state:v}}});b===o&&m({deliveriesLoading:!1,deliveriesError:!x.ok,deliveries:x.ok?x.data.items:[],deliveriesNext:x.ok?x.data.next:null,deliveriesHasPrevious:f.length>1})}let P={mutationScope(){let u=e;return()=>u===e},snapshot:()=>a,subscribe(u){return d.add(u),()=>{d.delete(u)}},async load(u=a.project){if(u!==a.project&&(e++,r=[void 0],f=[void 0],o++,m({...ue,project:u})),u===null)return;let h=++t;m({loading:!0,blocked:null});let v=r[r.length-1],b=await n.client.request("get","/_pb/projects/{project}/notifications",{params:{project:u},query:v===void 0?{}:{cursor:v}});if(h!==t)return;if(!b.ok){m({loading:!1,items:[],next:null,blocked:b.status===403?"denied":b.status===404?"unavailable":"error"});return}let E=a.selected!==null&&b.data.items.some(x=>x.id===a.selected)?a.selected:null;m({loading:!1,items:b.data.items,next:b.data.next,hasPrevious:r.length>1,selected:E,...E===null?{deliveries:[],detail:null}:{}})},async nextPage(){a.loading||a.next===null||(r.push(a.next),await P.load())},async previousPage(){a.loading||r.length<2||(r.pop(),await P.load())},replace(u,h){m({items:h===null?a.items.filter(v=>v.id!==u):a.items.some(v=>v.id===u)?a.items.map(v=>v.id===u?h:v):[...a.items,h],...h===null&&a.selected===u?{selected:null,deliveries:[],detail:null}:{}})},async select(u){f=[void 0],o++,m({selected:u,deliveries:[],deliveriesNext:null,deliveriesHasPrevious:!1,deliveriesError:!1,detail:null,detailError:!1,filter:"all"}),await y()},async filterHistory(u){f=[void 0],m({filter:u,detail:null}),await y()},reloadHistory:y,async nextHistory(){a.deliveriesLoading||a.deliveriesNext===null||(f.push(a.deliveriesNext),await y())},async previousHistory(){a.deliveriesLoading||f.length<2||(f.pop(),await y())},async openDelivery(u){let{project:h,selected:v}=a;if(h===null||v===null)return;m({detailError:!1});let b=await n.client.request("get","/_pb/projects/{project}/notifications/{id}/deliveries/{delivery}",{params:{project:h,id:v,delivery:u}});a.selected===v&&m(b.ok?{detail:b.data}:{detail:null,detailError:!0})},dispose(){e++,t++,o++}};return P}var i=_(F(),1),Y=20,Ne=[{value:"all",label:"All deliveries"},{value:"pending",label:"Waiting"},{value:"sending",label:"Sending"},{value:"delivered",label:"Delivered"},{value:"failed",label:"Failed"},{value:"cancelled",label:"Cancelled"}];function we(){let n=(0,N.useSyncExternalStore)(t=>(window.addEventListener("hashchange",t),()=>window.removeEventListener("hashchange",t)),()=>window.location.hash,()=>""),e=new URLSearchParams(n.split("?")[1]??"").get("project");return e!==null&&/^[A-Za-z0-9._-]{1,64}$/.test(e)?e:null}function xe(n){let{services:a,controller:e,project:t}=n,o=(0,N.useSyncExternalStore)(e.subscribe,e.snapshot,e.snapshot),[r,f]=(0,N.useState)(null),d=(0,N.useRef)(null),[m,y]=(0,N.useState)(null),[P,u]=(0,N.useState)(null),[h,v]=(0,N.useState)(null),[b,E]=(0,N.useState)(!1),[x,p]=(0,N.useState)(null),[q,c]=(0,N.useState)(null);(0,N.useEffect)(()=>{f(null),y(null),p(null),c(null),u(null),v(null),E(!1),e.load(t);let s=e.mutationScope();d.current?.project!==t&&(d.current={project:t,value:t===null?null:ie(t)});let g=d.current.value;if(g!==null){let T=D=>{s()&&(f(D),y(g.options),u("Draft restored. Review it and enter the delivery settings again before saving."),D!=="new"&&D.revision!==g.endpoint?.revision&&(E(!0),v("This endpoint changed while you were editing. Reload the latest settings before saving.")))};g.endpoint===null?T("new"):a.client.request("get","/_pb/projects/{project}/notifications/{id}",{params:{project:g.project,id:g.endpoint.id}}).then(D=>{D.ok?T(D.data):s()&&v("The draft endpoint could not be loaded. Reload the list.")})}return()=>e.dispose()},[e,t,a]);let k=n.projectName??t??"",S=(s,g)=>(g.ok?(g.endpoint!==null?e.replace(g.endpoint.id,g.endpoint):s!==null&&e.replace(s,null),u(g.message),v(null),E(!1)):(u(null),v(g.message),E(g.stale)),g),C=async(s,g)=>{if(x!==null||t===null)return;let T=e.mutationScope();p(s.id);let D=await g(T);T()&&(S(s.id,D),p(null))},L=o.items.find(s=>s.id===o.selected)??null;return t===null?(0,i.jsxs)("section",{className:"space-y-4",children:[(0,i.jsx)("h1",{className:"text-2xl font-semibold",children:"Notifications"}),(0,i.jsx)(A,{kind:"placeholder",title:"Choose a project to manage its notifications.",children:(0,i.jsx)("p",{children:"Notification endpoints belong to one project. Pick it in the Scope menu."})})]}):(0,i.jsxs)("section",{className:"space-y-4",children:[(0,i.jsx)("h1",{className:"text-2xl font-semibold",children:"Notifications"}),(0,i.jsx)("p",{children:`Project ${k} \xB7 Send a signed request to your own HTTPS receiver when a package in this project is published, released, removed, deprecated or re-tagged. Delivery is retried for up to 24 hours and is not guaranteed.`}),(0,i.jsx)("div",{role:"status","aria-live":"polite",children:P}),h===null?null:(0,i.jsxs)("div",{role:"alert",className:"space-y-2 text-red-700",children:[(0,i.jsx)("p",{children:h}),b?(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",onClick:()=>{E(!1),v(null),f(null),e.load()},children:"Reload latest settings"}):null]}),o.blocked==="denied"?(0,i.jsx)(A,{kind:"error",title:"You cannot manage notifications in this project.",children:(0,i.jsx)("p",{children:"Changing project settings in a signed-in session is required."})}):o.blocked==="unavailable"?(0,i.jsx)(A,{kind:"placeholder",title:"Notifications are not available.",children:(0,i.jsx)("p",{children:"This broker has notifications turned off, or the project is archived or not visible to you."})}):o.blocked==="error"?(0,i.jsx)(A,{kind:"error",title:"Notification endpoints could not be loaded. Try again.",children:(0,i.jsx)(w,{type:"button",className:"min-h-11",onClick:()=>{e.load()},children:"Try again"})}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"flex flex-wrap gap-2",children:[r===null?(0,i.jsx)(w,{type:"button",className:"min-h-11 w-full sm:w-auto",disabled:o.loading||o.items.length>=Y,"aria-describedby":o.items.length>=Y?"notification-limit":void 0,onClick:()=>{u(null),v(null),y(null),f("new")},children:"Add endpoint"}):null,(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11 w-full sm:w-auto",disabled:o.loading,onClick:()=>{e.load()},children:"Reload"})]}),o.items.length>=Y?(0,i.jsx)("p",{id:"notification-limit",children:"A project can have at most 20 endpoints."}):null,r===null?null:(0,i.jsx)(ce,{projectName:k,endpoint:r==="new"?null:r,disabled:b,...m===null?{}:{restoredOptions:m,requireSecret:!0},onCancel:()=>f(null),onSubmit:async s=>{let g=e.mutationScope(),T=r==="new"?await oe(a,t,s.options,s.secret,g):await re(a,t,r,s,g);return g()&&(S(null,T),T.ok&&f(null)),T}},`${t}/${r==="new"?"new":r.id}`),o.loading?(0,i.jsx)(A,{kind:"loading",title:"Loading notification endpoints\u2026"}):o.items.length===0?(0,i.jsx)(A,{kind:"empty",title:o.hasPrevious?"No endpoints on this page.":"No notification endpoints yet. Add one to tell another system about package changes."}):(0,i.jsx)(V,{label:`Notification endpoints in ${k}`,items:o.items,...o.selected===null?{}:{selectedId:o.selected},columns:[{key:"name",label:"Endpoint",value:s=>s.name,render:s=>(0,i.jsxs)("div",{className:"break-words",children:[(0,i.jsx)("strong",{children:s.name}),(0,i.jsxs)("p",{className:"text-sm text-neutral-600",children:[s.method," \xB7 signed",s.headersConfigured?" \xB7 custom headers":"",s.templateConfigured?" \xB7 body template":""]})]})},{key:"events",label:"Events and packages",value:s=>s.events.length,render:s=>(0,i.jsxs)("div",{className:"break-words",children:[(0,i.jsx)("p",{children:s.events.map(B).join(", ")}),(0,i.jsx)("p",{className:"font-mono text-sm",children:s.packagePattern})]})},{key:"state",label:"Status",value:s=>s.state,render:s=>(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsx)(X,{status:s.state}),(0,i.jsx)("p",{className:"text-sm",children:se(s)}),s.failureStreak>0?(0,i.jsx)("p",{className:"text-sm",children:`${s.failureStreak} failed ${s.failureStreak===1?"delivery":"deliveries"} in a row.`}):null]})},{key:"updated",label:"Changed",value:s=>s.updatedAt,priority:2,render:s=>(0,i.jsx)($,{value:s.updatedAt})},{key:"actions",label:"Actions",value:()=>"",sortable:!1,render:s=>(0,i.jsx)(z,{entityLabel:s.name,actions:[{id:"history",label:"Delivery history",onSelect:()=>{e.select(s.id)}}],overflow:[{id:"edit",label:"Edit",disabled:x!==null||b,onSelect:()=>{u(null),v(null),y(null),f(s)}},s.state==="enabled"?{id:"disable",label:"Disable",pending:x===s.id,disabled:b,onSelect:()=>{C(s,g=>W(a,t,s,!1,g))}}:{id:"enable",label:"Enable",pending:x===s.id,disabled:b,onSelect:()=>{C(s,g=>W(a,t,s,!0,g))}},{id:"delete",label:"Remove",variant:"destructive",disabled:x!==null||b,onSelect:()=>c(s)}]})}]}),(0,i.jsx)("p",{children:`${o.items.length} ${o.items.length===1?"endpoint":"endpoints"} on this page`}),o.hasPrevious||o.next!==null?(0,i.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",disabled:o.loading||!o.hasPrevious,onClick:()=>{e.previousPage()},children:"Previous endpoints"}),(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",disabled:o.loading||o.next===null,onClick:()=>{e.nextPage()},children:"Next endpoints"})]}):null,q===null?null:(0,i.jsx)(ae,{action:"Remove endpoint",target:q.name,scope:`Project ${k}`,description:"No further events are sent to this receiver and deliveries still waiting are cancelled. A request already on its way cannot be recalled. Removing it needs a recent sign-in and cannot be undone.",open:!0,hideTrigger:!0,onOpenChange:s=>{s||c(null)},onConfirm:()=>{let s=q;c(null),C(s,g=>de(a,t,s,g))}}),L===null?null:(0,i.jsx)(Se,{controller:e,name:L.name})]})]})}function Ee(n){return`${n.outcome==="started"?"started, result not recorded yet":U({state:n.outcome==="delivered"?"delivered":"failed",outcomeCode:n.outcomeCode})}${n.status===null?"":` (HTTP ${n.status})`}${n.durationMs===null?"":`, ${n.durationMs} ms`}`}function Se({controller:n,name:a}){let e=(0,N.useSyncExternalStore)(n.subscribe,n.snapshot,n.snapshot);return(0,i.jsxs)("section",{"aria-labelledby":"delivery-history",className:"space-y-4",children:[(0,i.jsx)("h2",{id:"delivery-history",className:"text-lg font-semibold",children:`Delivery history: ${a}`}),(0,i.jsx)("p",{children:"Finished deliveries are kept for seven days. Request and response bodies, addresses and headers are never stored."}),(0,i.jsxs)("div",{className:"flex flex-wrap items-end gap-2",children:[(0,i.jsxs)("label",{className:"grid gap-1",children:["Show",(0,i.jsx)(ne,{value:e.filter,onChange:t=>{n.filterHistory(t.target.value)},children:Ne.map(t=>(0,i.jsx)("option",{value:t.value,children:t.label},t.value))})]}),(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",disabled:e.deliveriesLoading,onClick:()=>{n.reloadHistory()},children:"Reload history"}),(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",onClick:()=>{n.select(null)},children:"Close history"})]}),e.deliveriesLoading?(0,i.jsx)(A,{kind:"loading",title:"Loading deliveries\u2026"}):e.deliveriesError?(0,i.jsx)(A,{kind:"error",title:"Deliveries could not be loaded. Try again.",children:(0,i.jsx)(w,{type:"button",className:"min-h-11",onClick:()=>{n.reloadHistory()},children:"Try again"})}):e.deliveries.length===0?(0,i.jsx)(A,{kind:e.filter==="all"?"empty":"filtered-empty",title:e.filter==="all"?"No deliveries yet. Events committed while the endpoint is enabled appear here.":"No deliveries match this filter on this page."}):(0,i.jsx)(V,{label:`Deliveries to ${a}`,items:e.deliveries,columns:[{key:"event",label:"Event",value:t=>t.eventType,render:t=>B(t.eventType)},{key:"created",label:"Created",value:t=>t.createdAt,render:t=>(0,i.jsx)($,{value:t.createdAt})},{key:"result",label:"Result",value:t=>t.state,render:t=>(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsx)(X,{status:t.state}),(0,i.jsx)("p",{className:"text-sm",children:`${U(t)}${t.lastStatus===null?"":` (HTTP ${t.lastStatus})`}`}),t.nextAttemptAt===null?null:(0,i.jsxs)("p",{className:"text-sm",children:["Next attempt ",(0,i.jsx)($,{value:t.nextAttemptAt})]})]})},{key:"attempts",label:"Attempts",value:t=>t.attempts,render:t=>`${t.attempts} of 8`},{key:"actions",label:"Actions",value:()=>"",sortable:!1,render:t=>(0,i.jsx)(z,{entityLabel:`${B(t.eventType)} delivery`,actions:[{id:"attempts",label:"Show attempts",onSelect:()=>{n.openDelivery(t.id)}}]})}]}),e.deliveriesHasPrevious||e.deliveriesNext!==null?(0,i.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",disabled:e.deliveriesLoading||!e.deliveriesHasPrevious,onClick:()=>{n.previousHistory()},children:"Newer deliveries"}),(0,i.jsx)(w,{type:"button",variant:"outline",className:"min-h-11",disabled:e.deliveriesLoading||e.deliveriesNext===null,onClick:()=>{n.nextHistory()},children:"Older deliveries"})]}):null,e.detailError?(0,i.jsx)("p",{role:"alert",children:"The attempts of this delivery could not be loaded."}):e.detail===null?null:(0,i.jsxs)("section",{"aria-labelledby":"delivery-attempts",className:"space-y-2",children:[(0,i.jsx)("h3",{id:"delivery-attempts",className:"font-semibold",children:`Attempts for the ${B(e.detail.eventType)} delivery`}),e.detail.history.length===0?(0,i.jsx)("p",{children:"No attempt has started."}):(0,i.jsx)("ol",{className:"list-decimal space-y-1 pl-6",children:e.detail.history.map(t=>(0,i.jsxs)("li",{children:[(0,i.jsx)($,{value:t.startedAt}),`: ${Ee(t)}`]},t.attempt))})]})]})}function Ze(){let n=te(),a=(0,N.useMemo)(()=>pe(n),[n]),e=we(),[t,o]=(0,N.useState)(null);return(0,N.useEffect)(()=>{if(o(null),e===null)return;let r=!0;return n.client.request("get","/_pb/projects/{project}",{params:{project:e}}).then(f=>{r&&f.ok&&o(f.data.name)}),()=>{r=!1}},[n,e]),(0,i.jsx)(xe,{services:n,controller:a,project:e,projectName:t})}export{Ze as NotificationsPage,xe as NotificationsView};
@@ -0,0 +1 @@
1
+ import{a as c}from"./chunk.dc41ee9219cf.js";import{a as b}from"./chunk.3f077ff17cea.js";import{F as h,K as v,c as p,d as C,g as f,m as g,n as y,p as d}from"./chunk.837eb41f53ef.js";var i=p(C(),1);var e=p(f(),1);function T(){let a=/^#\/npm-login\/([A-Za-z0-9_-]{43})$/.exec(window.location.hash)?.[1]??"";return(0,e.jsx)(L,{selector:a},a)}function L({selector:a}){let{client:l}=v(),[n,w]=(0,i.useState)(null),[q,j]=(0,i.useState)(!1),[u,k]=(0,i.useState)("read"),[t,s]=(0,i.useState)("loading");(0,i.useEffect)(()=>{let o=!0;return l.request("get","/_pb/me/npm-login/{selector}",{params:{selector:a}}).then(async r=>{if(!o)return;if(!r.ok){s(r.code==="reauth_required"?"reauth":"error");return}w(r.data),s("ready");let m=await l.request("get","/_pb/projects/{project}/permissions",{params:{project:r.data.project.slug}});o&&j(m.ok&&m.data.project.includes("project:packages:write"))}),()=>{o=!1}},[l,a]);async function A(o){if(o.preventDefault(),t!=="ready"&&t!=="failed"||n===null)return;s("busy");let r=await l.request("post","/_pb/me/npm-login/{selector}",{params:{selector:a},body:{scope:u==="write"?"write":"read"}});s(r.ok?"done":r.code==="reauth_required"?"reauth":r.code==="conflict"?"conflict":"failed")}return(0,e.jsxs)("section",{className:"max-w-2xl space-y-4",children:[(0,e.jsx)("h1",{className:"text-2xl font-semibold",children:"Confirm npm login"}),(0,e.jsx)(g,{children:(0,e.jsx)(y,{children:"Only continue if you ran npm login yourself a moment ago. Someone else may have sent you this link to gain access through your account."})}),t==="loading"&&(0,e.jsx)("p",{role:"status",children:"Loading login request\u2026"}),t==="reauth"&&(0,e.jsxs)("p",{children:["Confirm your identity before reviewing this request."," ",(0,e.jsx)("a",{className:"underline",href:`#/reauth?return=${encodeURIComponent(`/npm-login/${a}`)}`,children:"Reauthenticate"})]}),["error","conflict"].includes(t)&&(0,e.jsx)("p",{role:"alert",children:"This login request is unavailable or has already been confirmed. Run npm login again."}),t==="done"?(0,e.jsx)("p",{role:"status",children:"Login approved. Return to your terminal to collect the token."}):n!==null&&t!=="reauth"&&(0,e.jsxs)("form",{onSubmit:o=>{A(o)},className:"space-y-4",children:[(0,e.jsxs)("dl",{className:"space-y-2 break-words",children:[(0,e.jsx)("dt",{children:"Project"}),(0,e.jsxs)("dd",{children:[n.project.name," (",n.project.slug,")"]}),(0,e.jsx)("dt",{children:"CLI hostname"}),(0,e.jsx)("dd",{children:n.cliHostname??"Unavailable"}),(0,e.jsx)("dt",{children:"Source IP"}),(0,e.jsx)("dd",{children:n.sourceIp??"Unavailable"}),(0,e.jsx)("dt",{children:"Requested"}),(0,e.jsx)("dd",{children:(0,e.jsx)(c,{value:n.createdAt})}),(0,e.jsx)("dt",{children:"Request expires"}),(0,e.jsx)("dd",{children:(0,e.jsx)(c,{value:n.expiresAt})})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)(h,{htmlFor:"npm-login-scope",children:"Token access"}),(0,e.jsxs)(b,{id:"npm-login-scope",value:u,onChange:o=>k(o.target.value),disabled:t==="busy",children:[(0,e.jsx)("option",{value:"read",children:"Install and download"}),q&&(0,e.jsx)("option",{value:"write",children:"Install, download and publish"})]})]}),(0,e.jsx)("p",{children:"This creates a personal token for this project with the organization\u2019s default lifetime. It carries only permissions you currently hold."}),t==="failed"&&(0,e.jsx)("p",{role:"alert",children:"Login could not be approved. Review the request before trying again."}),(0,e.jsx)(d,{type:"submit",disabled:t!=="ready"&&t!=="failed",className:"min-h-11 w-full sm:w-auto",children:t==="busy"?"Approving login\u2026":"Approve login"}),t==="failed"&&(0,e.jsx)(d,{type:"button",onClick:()=>s("ready"),children:"Review again"})]})]})}export{T as NpmLoginPage};