@package-broker/ui 2.0.0-rc.4 → 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 (77) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/api-types.d.ts +848 -22
  3. package/dist/api-types.d.ts.map +1 -1
  4. package/dist/assets/{access.62e9484517a0.js → access.def9a17dc4a8.js} +1 -1
  5. package/dist/assets/app.ec678c27ec0a.css +2 -0
  6. package/dist/assets/{app.c064670cdc0d.js → app.fba0d059b40b.js} +2 -2
  7. package/dist/assets/{audit.b7c40b9dc998.js → audit.453367b59daf.js} +1 -1
  8. package/dist/assets/{chunk.56d473a1587d.js → chunk.2c3648a5bad1.js} +1 -1
  9. package/dist/assets/{chunk.a6d755a9789f.js → chunk.304a2b5d1663.js} +1 -1
  10. package/dist/assets/{chunk.741aec8d1ff9.js → chunk.3f077ff17cea.js} +1 -1
  11. package/dist/assets/{chunk.d18497920e4d.js → chunk.4721d4544d48.js} +1 -1
  12. package/dist/assets/{chunk.6ea6bdcaa465.js → chunk.4acf8fa7653f.js} +1 -1
  13. package/dist/assets/{chunk.28a4d8aab337.js → chunk.53134c7df4e5.js} +1 -1
  14. package/dist/assets/{chunk.965b76812604.js → chunk.56e058d97e0f.js} +1 -1
  15. package/dist/assets/{chunk.3fcd6998795a.js → chunk.75e1357175af.js} +1 -1
  16. package/dist/assets/chunk.837eb41f53ef.js +1 -0
  17. package/dist/assets/{chunk.f54ea1378c8c.js → chunk.ab1a14143dc6.js} +1 -1
  18. package/dist/assets/{chunk.d813fefb410d.js → chunk.dc41ee9219cf.js} +1 -1
  19. package/dist/assets/{chunk.8442124f6802.js → chunk.f0fd799728ef.js} +1 -1
  20. package/dist/assets/chunk.fac952720b72.js +4 -0
  21. package/dist/assets/{import.e7a1e5834631.js → import.4275bbce08ac.js} +1 -1
  22. package/dist/assets/index.html +7 -7
  23. package/dist/assets/manifest.json +30 -30
  24. package/dist/assets/{notifications.19225fe12044.js → notifications.bd7d4c3f9882.js} +1 -1
  25. package/dist/assets/{npm-login.e059678af13d.js → npm-login.d8b60e11fe87.js} +1 -1
  26. package/dist/assets/packages.bdd474bcfc11.js +2 -0
  27. package/dist/assets/{projects.927fe18c785c.js → projects.44006a838c67.js} +1 -1
  28. package/dist/assets/{setup.8e977608d413.js → setup.7bc86366227c.js} +1 -1
  29. package/dist/assets/setup.html +2 -2
  30. package/dist/assets/sources.d95aabfbec73.js +1 -0
  31. package/dist/assets/{tokens.6b86d8d97e07.js → tokens.4ee13a722abb.js} +1 -1
  32. package/dist/auth.d.ts +1 -0
  33. package/dist/auth.d.ts.map +1 -1
  34. package/dist/auth.js +13 -2
  35. package/dist/auth.js.map +1 -1
  36. package/dist/pages/audit.d.ts.map +1 -1
  37. package/dist/pages/packages/discovery-labels.d.ts +8 -0
  38. package/dist/pages/packages/discovery-labels.d.ts.map +1 -0
  39. package/dist/pages/packages/discovery-labels.js +25 -0
  40. package/dist/pages/packages/discovery-labels.js.map +1 -0
  41. package/dist/pages/packages/discovery-picker-view.d.ts +8 -0
  42. package/dist/pages/packages/discovery-picker-view.d.ts.map +1 -0
  43. package/dist/pages/packages/discovery-picker-view.js +109 -0
  44. package/dist/pages/packages/discovery-picker-view.js.map +1 -0
  45. package/dist/pages/packages/discovery-picker.d.ts +67 -0
  46. package/dist/pages/packages/discovery-picker.d.ts.map +1 -0
  47. package/dist/pages/packages/discovery-picker.js +238 -0
  48. package/dist/pages/packages/discovery-picker.js.map +1 -0
  49. package/dist/pages/packages/source-actions.d.ts +3 -1
  50. package/dist/pages/packages/source-actions.d.ts.map +1 -1
  51. package/dist/pages/packages/source-actions.js +19 -9
  52. package/dist/pages/packages/source-actions.js.map +1 -1
  53. package/dist/pages/sources/discovery-rule-prefill.d.ts +13 -0
  54. package/dist/pages/sources/discovery-rule-prefill.d.ts.map +1 -0
  55. package/dist/pages/sources/discovery-rule-prefill.js +9 -0
  56. package/dist/pages/sources/discovery-rule-prefill.js.map +1 -0
  57. package/dist/pages/sources/discovery-rules-view.d.ts +9 -0
  58. package/dist/pages/sources/discovery-rules-view.d.ts.map +1 -0
  59. package/dist/pages/sources/discovery-rules-view.js +144 -0
  60. package/dist/pages/sources/discovery-rules-view.js.map +1 -0
  61. package/dist/pages/sources/discovery-rules.d.ts +57 -0
  62. package/dist/pages/sources/discovery-rules.d.ts.map +1 -0
  63. package/dist/pages/sources/discovery-rules.js +383 -0
  64. package/dist/pages/sources/discovery-rules.js.map +1 -0
  65. package/dist/pages/sources.d.ts.map +1 -1
  66. package/dist/pages/sources.js +4 -1
  67. package/dist/pages/sources.js.map +1 -1
  68. package/dist/pending.d.ts +6 -1
  69. package/dist/pending.d.ts.map +1 -1
  70. package/dist/pending.js +1 -1
  71. package/dist/pending.js.map +1 -1
  72. package/package.json +3 -3
  73. package/dist/assets/app.45b156168495.css +0 -2
  74. package/dist/assets/chunk.51497edc7697.js +0 -4
  75. package/dist/assets/chunk.fd375c54b526.js +0 -1
  76. package/dist/assets/packages.ab5ab25b1c75.js +0 -2
  77. package/dist/assets/sources.ae50f239f80f.js +0 -1
@@ -1 +1 @@
1
- import{b as J,c as ie}from"./chunk.815f9a91c741.js";import{a as z,b as le}from"./chunk.56d473a1587d.js";import"./chunk.d18497920e4d.js";import{b as X}from"./chunk.8442124f6802.js";import{a as ae}from"./chunk.a6d755a9789f.js";import{a as V,c as A}from"./chunk.965b76812604.js";import"./chunk.3fcd6998795a.js";import{a as $}from"./chunk.d813fefb410d.js";import{a as ne}from"./chunk.741aec8d1ff9.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.fd375c54b526.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};
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};
@@ -1 +1 @@
1
- import{a as c}from"./chunk.d813fefb410d.js";import{a as b}from"./chunk.741aec8d1ff9.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.fd375c54b526.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};
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};
@@ -0,0 +1,2 @@
1
+ import{a as nt,b as rt,c as it,d as lt,e as Te,f as ct,g as ze,h as ut,i as pt,j as dt,k as be}from"./chunk.fac952720b72.js";import"./chunk.675b635d9462.js";import"./chunk.4acf8fa7653f.js";import"./chunk.e3b0c44298fc.js";import{a as ot}from"./chunk.53134c7df4e5.js";import{a as at,b as mt}from"./chunk.2c3648a5bad1.js";import"./chunk.4721d4544d48.js";import{a as st,b as _e}from"./chunk.f0fd799728ef.js";import"./chunk.304a2b5d1663.js";import{a as ie,b as tt,c as Z}from"./chunk.56e058d97e0f.js";import"./chunk.75e1357175af.js";import{a as X}from"./chunk.dc41ee9219cf.js";import{a as Y}from"./chunk.3f077ff17cea.js";import{A as ge,B as fe,C as he,D as Je,E as re,F as V,G as Xe,K as et,c as H,d as je,g as K,j as Ee,m as Ye,n as Ke,p as C,u as Ze,x as pe,y as de,z as me}from"./chunk.837eb41f53ef.js";var F=H(je(),1);var b=H(K(),1);function ht(t){return{visibleToNewProjects:t==="available",newProjectAccessMode:t==="request"?"request":"none"}}function bt(t,e,a,l){return t===null?e.includes("org:sources:write"):t===l&&a.includes("project:sources:write")}function gt(t){return{"If-Match":`"r${t}"`}}function Me(t,e,a,l){return t&&!e&&!a&&l==="pending"}function He(t){if(!["pending","not_required","approved"].includes(t.approvalState)||t.scanState==="denied")return[];let e=[];return t.approvalState==="pending"&&e.push("approve"),t.holdScan&&t.scanState==="failed"&&e.push("rescan"),(t.approvalState==="pending"||t.holdScan&&(t.approvalState==="not_required"||t.scanState==="failed"))&&e.push("reject"),e}function Et(t,e){return(!e||t.trim().length>0)&&new TextEncoder().encode(t).length<=1e3&&Array.from(t).every(a=>{let l=a.charCodeAt(0);return l>=32&&l!==127||l===9||l===10||l===13})}var ft={queued:"Security scan queued",running:"Security scan running",allowed:"Security scan passed",denied:"Security scan refused",failed:"Security scan failed",not_required:"Security scan not required"};function Oe(t){return(0,b.jsx)("div",{className:"[&_button]:min-h-11",children:(0,b.jsx)(Ze,{children:(0,b.jsx)(at,{...t})})})}function yt({services:t,project:e}){let[a,l]=(0,F.useState)([]),[s,o]=(0,F.useState)([]),[m,q]=(0,F.useState)([]),[n,x]=(0,F.useState)([]),[v,d]=(0,F.useState)(e?"Project":"Organization"),[f,r]=(0,F.useState)(!0),[u,k]=(0,F.useState)(!1),[h,N]=(0,F.useState)(""),[R,S]=(0,F.useState)({publishes:null,requests:null}),[g,T]=(0,F.useState)(null),[E,L]=(0,F.useState)(""),[_,U]=(0,F.useState)(""),[z,w]=(0,F.useState)(!1),[ee,le]=(0,F.useState)(!1),[Le,ve]=(0,F.useState)(0),[te,ke]=(0,F.useState)({}),se=(0,F.useRef)(!1),Ne=(0,F.useRef)(null),J=(0,F.useRef)(0);(0,F.useEffect)(()=>{let p=++J.current;return r(!0),k(!1),x([]),T(null),le(!1),se.current=!1,w(!1),(async()=>{let D=e===null?await t.client.request("get","/_pb/me/permissions"):await t.client.request("get","/_pb/projects/{project}/permissions",{params:{project:e}});if(p!==J.current)return;let Q=D.ok?"organization"in D.data&&e===null?D.data.organization:"project"in D.data?D.data.project:[]:[];if(x(Q),e!==null){let[W,G]=await Promise.all([t.client.request("get","/_pb/projects/{project}",{params:{project:e}}),Q.includes("project:packages:manage")?t.client.request("get","/_pb/projects/{project}/requestable-packages",{params:{project:e},query:{cursor:te.requests}}):null]);if(p!==J.current)return;d(W.ok?`Project ${W.data.name}`:"Project"),q(G?.ok?G.data.items:[]),S({publishes:null,requests:G?.ok?G.data.next:null}),k(!D.ok||G!==null&&!G.ok)}else if(Q.includes("org:packages:read")){let[W,G]=await Promise.all([t.client.request("get","/_pb/publishes",{query:{actionable:"true",cursor:te.publishes}}),t.client.request("get","/_pb/package-access-requests",{query:{state:"pending",cursor:te.requests}})]);if(p!==J.current)return;l(W.ok?W.data.items:[]),o(G.ok?G.data.items:[]),S({publishes:W.ok?W.data.next:null,requests:G.ok?G.data.next:null}),k(!W.ok||!G.ok)}else k(!D.ok);r(!1)})(),()=>{++J.current}},[t,e,Le,te]),(0,F.useEffect)(()=>t.subscribeReplay?.(p=>{(p.path.startsWith("/_pb/publishes/")||p.path.startsWith("/_pb/package-access-requests/")||e&&p.path===`/_pb/projects/${encodeURIComponent(e)}/package-access-requests`)&&(N(p.ok?"Decision saved.":"Decision could not be saved. Reload and review the latest request."),ve(D=>D+1))}),[t,e]);let oe=p=>{T(p),L(""),U(""),le(!1)},we=g?.kind==="publish"?n.includes("org:packages:approve"):g?.kind==="access"?n.includes("org:packages:manage"):n.includes("project:packages:manage"),ae=g?.kind!=="request"&&g?.action==="reject";async function Se(){if(!g||se.current||!Me(we,z,ee,g.kind==="publish"?He(g.item).includes(g.action)?"pending":"closed":g.kind==="access"?g.item.state:"pending"))return;if(!Et(E,ae)){U("Enter a reason of at most 1000 UTF-8 bytes."),Ne.current?.focus();return}se.current=!0,w(!0),U("");let p=J.current,D=E?{reason:E}:{},Q=g.kind==="request"?await t.client.request("post","/_pb/projects/{project}/package-access-requests",{params:{project:e},body:{packageId:g.item.id,...D}}):g.kind==="publish"?await t.client.request("post",`/_pb/publishes/{id}/${g.action}`,{params:{id:g.item.id},headers:gt(g.item.revision),body:g.action==="rescan"?{}:D}):await t.client.request("post",`/_pb/package-access-requests/{id}/${g.action}`,{params:{id:g.item.id},headers:gt(g.item.revision),body:D});if(p===J.current){if(se.current=!1,w(!1),!Q.ok){Q.code==="reauth_required"&&t.requireReauth(Q.request,{credential:!1,secretFields:[],display:{version:g.kind==="publish"?g.item.version:"",packageName:g.kind==="request"?g.item.name:g.item.packageName,scope:v}}),Q.status===409||Q.status===412?(le(!0),U("This request changed. Reload the latest requests before reviewing again.")):U(Q.code==="reauth_required"?"Sign in again, then reload and review this decision before submitting.":"The decision could not be saved. Try again.");return}N(g.kind==="request"?"Package access requested. An organization administrator must approve it.":g.kind==="publish"&&g.action==="rescan"?"Security scan queued. The version remains held until all required reviews pass.":`${g.kind==="publish"?"Publish":"Package access"} ${g.action==="approve"?"approved":"rejected"}.${g.kind==="publish"&&g.action==="approve"&&g.item.holdScan?" The package remains held until the security scan passes.":""}`),T(null),ve(W=>W+1)}}let ce=()=>{T(null),ve(p=>p+1)};return f?(0,b.jsx)(Z,{kind:"loading",title:"Loading package requests\u2026"}):u?(0,b.jsx)(Z,{kind:"error",title:"Package requests could not be loaded.",children:(0,b.jsx)(C,{type:"button",className:"min-h-11",onClick:ce,children:"Try again"})}):n.includes(e?"project:packages:manage":"org:packages:read")?(0,b.jsxs)("div",{className:"my-6 space-y-6 break-words",children:[(0,b.jsx)("p",{role:"status",children:h}),e?(0,b.jsxs)("section",{"aria-label":"Request package access",children:[(0,b.jsx)("h2",{className:"text-lg font-semibold",children:"Request package access"}),(0,b.jsxs)("p",{children:[v,". Attach the hosted source to this project first. Only packages that allow requests and have an active attached source appear here."]}),(0,b.jsxs)("p",{children:[m.length," ",m.length===1?"requestable package":"requestable packages"," on this page"]}),(0,b.jsx)(ie,{label:"Requestable packages",items:m,columns:[{key:"name",label:"Package",value:p=>p.name},{key:"action",label:"Actions",value:()=>"",render:p=>(0,b.jsx)(Oe,{entityLabel:p.name,actions:[{id:"request",label:"Request access",onSelect:()=>oe({kind:"request",item:p})}]})}]}),!m.length&&(0,b.jsx)("p",{children:"No packages available to request on this page."}),R.requests&&(0,b.jsx)(C,{type:"button",className:"min-h-11",onClick:()=>ke(p=>({...p,requests:R.requests})),children:"Next requestable packages"})]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("section",{"aria-label":"Pending publishes",children:[(0,b.jsx)("h2",{className:"text-lg font-semibold",children:"Pending publishes"}),(0,b.jsxs)("p",{children:[v,". Approval releases a version only after all required security scans pass. Rejection is permanent for this version."]}),(0,b.jsxs)("p",{children:[a.length," ",a.length===1?"held publish":"held publishes"," on this page"]}),(0,b.jsx)(ie,{label:"Pending publishes",items:a,columns:[{key:"package",label:"Package",value:p=>p.packageName,render:p=>(0,b.jsxs)(b.Fragment,{children:[p.packageName,(0,b.jsx)("span",{className:"block font-mono",children:p.version})]})},{key:"context",label:"Source and requester",value:p=>p.sourceName,render:p=>(0,b.jsxs)(b.Fragment,{children:[p.sourceName,(0,b.jsxs)("span",{className:"block",children:[p.requestedBy.name," \xB7 ",p.project?.name??"Organization"]})]})},{key:"scan",label:"Review status",value:p=>ft[p.scanState],render:p=>(0,b.jsxs)(b.Fragment,{children:[ft[p.scanState],(0,b.jsx)("span",{className:"block",children:p.approvalState==="pending"?"Approval pending":p.approvalState==="approved"?"Publish approved":"Approval not required"})]})},{key:"expires",label:"Expires",value:p=>p.expiresAt,render:p=>(0,b.jsx)(X,{value:p.expiresAt})},{key:"actions",label:"Actions",value:()=>"",render:p=>n.includes("org:packages:approve")?(0,b.jsx)(Oe,{entityLabel:`${p.packageName} ${p.version}`,actions:He(p).filter(D=>D!=="reject").map(D=>({id:D,label:D==="rescan"?"Rescan":"Approve publish",onSelect:()=>oe({kind:"publish",item:p,action:D})})),overflow:He(p).includes("reject")?[{id:"reject",label:p.approvalState==="approved"?"Dispose failed publish":"Reject publish",variant:"destructive",onSelect:()=>oe({kind:"publish",item:p,action:"reject"})}]:[]}):null}]}),!a.length&&(0,b.jsx)("p",{children:"No actionable holds on this page."}),R.publishes&&(0,b.jsx)(C,{type:"button",className:"min-h-11",onClick:()=>ke(p=>({...p,publishes:R.publishes})),children:"Next publishes"})]}),(0,b.jsxs)("section",{"aria-label":"Access requests",children:[(0,b.jsx)("h2",{className:"text-lg font-semibold",children:"Access requests"}),(0,b.jsxs)("p",{children:[v,". Approval gives the named project access to this package. Other project access remains unchanged."]}),(0,b.jsxs)("p",{children:[s.length," ",s.length===1?"access request":"access requests"," on this page"]}),(0,b.jsx)(ie,{label:"Access requests",items:s,columns:[{key:"package",label:"Package",value:p=>p.packageName},{key:"project",label:"Project",value:p=>p.project.name},{key:"reason",label:"Requester and reason",value:p=>p.requestedBy.name,render:p=>(0,b.jsxs)(b.Fragment,{children:[p.requestedBy.name,(0,b.jsx)("p",{className:"whitespace-pre-wrap",children:p.reason||"No reason provided"})]})},{key:"expires",label:"Expires",value:p=>p.expiresAt,render:p=>(0,b.jsx)(X,{value:p.expiresAt})},{key:"actions",label:"Actions",value:()=>"",render:p=>n.includes("org:packages:manage")?(0,b.jsx)(Oe,{entityLabel:`${p.packageName} for ${p.project.name}`,actions:[{id:"approve",label:"Approve access",onSelect:()=>oe({kind:"access",item:p,action:"approve"})}],overflow:[{id:"reject",label:"Reject access",variant:"destructive",onSelect:()=>oe({kind:"access",item:p,action:"reject"})}]}):null}]}),!s.length&&(0,b.jsx)("p",{children:"No pending access requests on this page."}),R.requests&&(0,b.jsx)(C,{type:"button",className:"min-h-11",onClick:()=>ke(p=>({...p,requests:R.requests})),children:"Next access requests"})]})]}),(0,b.jsx)(C,{type:"button",className:"min-h-11",variant:"outline",onClick:ce,children:"Refresh requests"}),(0,b.jsx)(pe,{open:g!==null,onOpenChange:p=>{!p&&!z&&T(null)},children:(0,b.jsxs)(de,{className:"[&_button]:min-h-11 [&_button]:min-w-11",children:[(0,b.jsxs)(me,{children:[(0,b.jsx)(fe,{children:g?.kind==="request"?"Request package access":g?.action==="rescan"?"Rescan publish":g?.action==="reject"?"Reject request":"Approve request"}),(0,b.jsx)(he,{children:g?`${g.kind==="request"?g.item.name:g.item.packageName} \xB7 ${g.kind==="access"?g.item.project.name:v}. ${g.kind==="publish"?"Rejection permanently removes this version. Rescan queues another security review and keeps the version held. Approval still requires all security scans to pass.":"An approved request gives this project access to the package."}`:""})]}),(0,b.jsxs)("form",{noValidate:!0,onSubmit:p=>{p.preventDefault(),Se()},className:"space-y-4","aria-busy":z,children:[!(g?.kind==="publish"&&g.action==="rescan")&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(V,{htmlFor:"package-decision-reason",children:["Reason (",ae?"required":"optional",")"]}),(0,b.jsx)(mt,{id:"package-decision-reason",ref:Ne,className:"min-h-24 w-full rounded border p-2",required:ae,value:E,disabled:z,onChange:p=>L(p.target.value),"aria-describedby":"package-reason-help package-decision-error","aria-invalid":!!_}),(0,b.jsx)("p",{id:"package-reason-help",children:"At most 1000 UTF-8 bytes. The reason is recorded with the decision."})]}),(0,b.jsx)("p",{id:"package-decision-error",role:"alert",children:_}),ee&&(0,b.jsx)(C,{type:"button",className:"min-h-11",onClick:ce,children:"Reload latest requests"}),(0,b.jsxs)(ge,{children:[(0,b.jsx)(C,{type:"button",className:"min-h-11",variant:"outline",disabled:z,onClick:()=>T(null),children:"Cancel"}),(0,b.jsx)(C,{type:"submit",className:"min-h-11",disabled:z||ee,variant:ae?"destructive":"default",children:z?"Saving decision\u2026":g?.kind==="request"?"Send request":g?.kind==="publish"&&g.action==="rescan"?"Queue rescan":ae?"Confirm rejection":"Confirm approval"})]})]})]})})]}):null}var A=H(je(),1);var y=H(K(),1);function _t(t,e,a,l){let s=`${a}/${encodeURIComponent(l)}`;return t==="npm"?`registry=${s}/npm/`:`composer config repositories.${l} composer ${s}
2
+ composer require ${e}`}function vt({services:t,id:e,project:a,back:l="#/packages"}){let[s,o]=(0,A.useState)(null),[m,q]=(0,A.useState)(null),[n,x]=(0,A.useState)([]),[v,d]=(0,A.useState)(a??""),[f,r]=(0,A.useState)(""),[u,k]=(0,A.useState)([]),[h,N]=(0,A.useState)([]),[R,S]=(0,A.useState)(null),[g,T]=(0,A.useState)([]),[E,L]=(0,A.useState)(),[_,U]=(0,A.useState)(null),[z,w]=(0,A.useState)(!1),[ee,le]=(0,A.useState)(null),[Le,ve]=(0,A.useState)(0),te=(0,A.useRef)(null),[ke,se]=(0,A.useState)(!1),[Ne,J]=(0,A.useState)(""),[oe,we]=(0,A.useState)(!0),[ae,Se]=(0,A.useState)(!1),[ce,p]=(0,A.useState)("unavailable"),[D,Q]=(0,A.useState)(!1),[W,G]=(0,A.useState)(!1),[Rt,ue]=(0,A.useState)(""),[De,xe]=(0,A.useState)(0),Pe=(0,A.useRef)(0),Ce=(0,A.useRef)(!1);(0,A.useEffect)(()=>{let P=!0;return++Pe.current,we(!0),Se(!1),o(null),q(null),k([]),N([]),Q(!1),Ce.current=!1,(async()=>{let[I,We,Ae]=await Promise.all([t.client.request("get","/_pb/me/permissions"),a?t.client.request("get","/_pb/projects/{project}/permissions",{params:{project:a}}):null,a?t.client.request("get","/_pb/projects/{project}",{params:{project:a}}):null]),Fe=a?await t.client.request("get","/_pb/projects/{project}/packages/{package}",{params:{project:a,package:e}}):await t.client.request("get","/_pb/packages/{package}",{params:{package:e}}),Re=Fe.ok?Fe.data:null,Be=Re;if(P){if(Fe.ok||Se(!0),o(Re),q(Be),p(Be?.visibleToNewProjects?"available":Be?.newProjectAccessMode==="request"?"request":"unavailable"),G(!1),k(I.ok?I.data.organization:[]),N(We?.ok?We.data.project:[]),S(Ae?.ok?Ae.data.id:null),r(Ae?.ok?Ae.data.name:""),!a&&I.ok&&I.data.organization.includes("org:projects:read")){let $e=[],Ve;do{let ne=await t.client.request("get","/_pb/projects",{query:{after:Ve}});if(!P)return;if(!ne.ok)break;$e.push(...ne.data.items),Ve=ne.data.next??void 0}while(Ve);if(x($e),Re?.source.projectId){let ne=$e.find(Ie=>Ie.id===Re.source.projectId);if(ne){let Ie=await t.client.request("get","/_pb/projects/{project}/permissions",{params:{project:ne.slug}});if(!P)return;N(Ie.ok?Ie.data.project:[]),S(ne.id)}}}we(!1)}})(),()=>{P=!1,++Pe.current}},[t,e,a,De]),(0,A.useEffect)(()=>{if(!s)return;let P=!0;return T([]),w(!1),(async()=>{let I=a?await t.client.request("get","/_pb/projects/{project}/packages/{package}/versions",{params:{project:a,package:e},query:{after:E}}):await t.client.request("get","/_pb/packages/{package}/versions",{params:{package:e},query:{after:E}});P&&(T(I.ok?I.data.items:[]),U(I.ok?I.data.next:null),w(!I.ok))})(),()=>{P=!1}},[t,s,e,a,E,De]),(0,A.useEffect)(()=>{let P=!0;if(le(null),se(!1),!v){J("Choose a project to read the README within its package access.");return}return J("Loading README\u2026"),t.client.request("get","/_pb/projects/{project}/packages/{package}/readme",{params:{project:v,package:e}}).then(I=>{P&&(le(I.ok?I.data:null),se(!I.ok&&(I.status===0||I.status>=500)),J(I.ok?"README loaded.":I.status===403?"This project cannot read this package.":I.status===404?"No README is available for the active latest version in this project.":I.status===0||I.status>=500?"README could not be loaded. Try again.":"README is unavailable."))}),()=>{P=!1}},[t,e,v,De,Le]),(0,A.useEffect)(()=>t.subscribeReplay?.(P=>{P.path===`/_pb/packages/${encodeURIComponent(e)}/access`&&(P.ok?(ue("Access policy saved. Existing project access is unchanged."),xe(I=>I+1)):(G(!0),ue("The policy could not be saved. Reload the latest settings before saving.")))}),[t,e]);let Qe=s&&bt(s.source.projectId,u,h,R);async function It(){if(!m||Ce.current||!Me(!!Qe,D,W,"pending"))return;Ce.current=!0,Q(!0),ue("");let P=Pe.current,I=await t.client.request("patch","/_pb/packages/{package}/access",{params:{package:e},body:{...ht(ce),revision:m.revision}});if(P===Pe.current){if(Ce.current=!1,Q(!1),!I.ok){I.code==="reauth_required"&&t.requireReauth(I.request,{credential:!1,secretFields:[],display:{version:"",packageName:m.name,scope:a?`Project ${f}`:"Organization"}}),I.status===409?(G(!0),ue("This package changed while you were editing. Reload the latest settings before saving. Your selection is retained for comparison.")):ue(I.code==="reauth_required"?"Sign in again, then reload and review the access policy before saving.":"Access policy could not be saved. Try again.");return}q({...m,...I.data}),ue("Access policy saved. Existing project access is unchanged.")}}return(0,y.jsxs)("section",{"aria-labelledby":"package-detail-heading",className:"min-w-0 space-y-6 break-words",children:[(0,y.jsx)("a",{href:l,className:"inline-flex min-h-11 items-center text-blue-700 underline",children:"Back to packages"}),(0,y.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,y.jsx)("h1",{id:"package-detail-heading",tabIndex:-1,className:"text-2xl font-semibold",children:s?.name??"Package details"}),(0,y.jsx)(C,{type:"button",className:"min-h-11",variant:"outline",onClick:()=>xe(P=>P+1),children:"Reload package"})]}),oe?(0,y.jsx)(Z,{kind:"loading",title:"Loading package\u2026"}):ae?(0,y.jsx)(Z,{kind:"error",title:"Package could not be loaded.",children:(0,y.jsx)(C,{type:"button",className:"min-h-11",onClick:()=>xe(P=>P+1),children:"Try again"})}):s?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("p",{children:[a?`Project ${f}`:"Organization"," \xB7 Source: ",s.source.name," \xB7"," ",be[s.source.type]]}),(0,y.jsx)("p",{role:"status",children:Rt}),(0,y.jsx)("a",{className:"inline-flex min-h-11 items-center text-blue-700 underline",href:`${l}${l.includes("?")?"&":"?"}package=${e}`,children:"Manage version status"}),m&&Qe&&(0,y.jsxs)("form",{className:"max-w-5xl space-y-4",onSubmit:P=>{P.preventDefault(),It()},children:[(0,y.jsx)(V,{htmlFor:"package-new-access",children:"Access for new projects"}),(0,y.jsxs)(Y,{className:"min-h-11",id:"package-new-access",value:ce,onChange:P=>p(P.target.value),disabled:D,"aria-describedby":"package-access-help",children:[(0,y.jsx)("option",{value:"available",children:"Available"}),(0,y.jsx)("option",{value:"request",children:"Require approval"}),(0,y.jsx)("option",{value:"unavailable",children:"Not available"})]}),(0,y.jsxs)("p",{id:"package-access-help",children:[s.source.projectId?`Project ${f||n.find(P=>P.id===s.source.projectId)?.name||"Name unavailable"}`:"Organization"," ","\xB7 ",s.name,". Available allows new projects to use this package. Require approval lets project managers request access. Not available prevents new project access. Existing project access is unchanged."]}),(0,y.jsx)(C,{className:"min-h-11",type:"submit",disabled:D||W,children:D?"Saving access policy\u2026":"Save access policy"}),W&&(0,y.jsx)(C,{type:"button",className:"min-h-11",variant:"outline",onClick:()=>xe(P=>P+1),children:"Reload latest settings"})]}),(0,y.jsx)("div",{children:!a&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(V,{htmlFor:"readme-project",children:"Project for README and install instructions"}),(0,y.jsxs)(Y,{className:"min-h-11",id:"readme-project",value:v,onChange:P=>d(P.target.value),children:[(0,y.jsx)("option",{value:"",children:"Choose a project"}),n.map(P=>(0,y.jsx)("option",{value:P.slug,children:P.name},P.id))]})]})}),(0,y.jsxs)("section",{children:[(0,y.jsx)("h2",{className:"text-lg font-semibold",children:"Install"}),s.ecosystem==="npm"&&v&&(0,y.jsxs)("p",{children:["Add this line to .npmrc, then run npm install ",s.name,"."]}),v?(0,y.jsx)("pre",{className:"whitespace-pre-wrap break-all rounded border p-4",children:_t(s.ecosystem,s.name,window.location.origin,v)}):(0,y.jsx)("p",{children:"Choose a project to see its registry address. Configure project credentials in your package manager."})]}),(0,y.jsxs)("section",{children:[(0,y.jsx)("h2",{className:"text-lg font-semibold",children:"README"}),(0,y.jsx)("p",{ref:te,tabIndex:-1,role:"status",children:Ne}),ee&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("p",{children:[ee.filename," \xB7 ",ee.sizeBytes," bytes"]}),(0,y.jsx)("pre",{className:"max-w-full whitespace-pre-wrap break-all rounded border p-4 font-mono text-sm",children:ee.body})]}),ke&&(0,y.jsx)(C,{type:"button",className:"min-h-11",variant:"outline",onClick:()=>{te.current?.focus(),ve(P=>P+1)},children:"Try again"})]}),(0,y.jsxs)("section",{children:[(0,y.jsx)("h2",{className:"text-lg font-semibold",children:"Versions"}),z?(0,y.jsx)("p",{role:"alert",children:"Versions could not be loaded. Reload the package to try again."}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(Ue,{item:s,versions:g,access:{organization:[],project:[],projectId:null,projectSlug:a},busy:!1,onAction:()=>{}}),g.map(P=>(0,y.jsxs)("details",{className:"my-4 rounded border p-4",children:[(0,y.jsxs)("summary",{className:"min-h-11 cursor-pointer",children:["Publication details for ",P.version]}),(0,y.jsxs)("dl",{children:[(0,y.jsx)("dt",{children:"Integrity"}),(0,y.jsx)("dd",{className:"break-all font-mono",children:P.integrity??"Unavailable"}),(0,y.jsx)("dt",{children:"Distribution tags"}),(0,y.jsx)("dd",{children:P.distTags.join(", ")||"No tags"}),(0,y.jsx)("dt",{children:"Published through the broker"}),(0,y.jsx)("dd",{children:P.publishedBy?.displayName??"Attribution unavailable"}),(0,y.jsx)("dt",{children:"Approved by"}),(0,y.jsx)("dd",{children:P.approvedBy?(0,y.jsxs)(y.Fragment,{children:[P.approvedBy.displayName," \xB7"," ",(0,y.jsx)(X,{value:P.approvedBy.decidedAt})]}):"Not approved"})]})]},P.id)),_&&(0,y.jsx)(C,{type:"button",className:"min-h-11",onClick:()=>L(_),children:"Next versions"})]})]})]}):(0,y.jsx)("p",{children:"Package unavailable in this scope."})]})}var O=H(je(),1);function kt(t,e){let a={loading:!0,busy:!1,importing:!1,connections:[],connection:"",pattern:"*",includeForks:!1,entries:[],nextCursor:null,selected:[],results:[],error:null,patternError:null,pending:[],reviewed:!1,progress:0,total:0},l=new Set,s=d=>{a={...a,...d},l.forEach(f=>f())},o=!1,m=new Map,q,n=d=>!a.results.some(f=>f.repository===d&&(f.outcome==="created"||f.outcome==="existing")),x=()=>a.connections[Number(a.connection)];async function v(d,f,r=!1){let u=x();if(o||a.busy||!u&&!f||!d.length||d.length>20)return;let k=f??{credentialId:u.credentialId,installationId:u.installationId,ecosystem:e,includeForks:a.includeForks};s({busy:!0,importing:!0,error:null,progress:r?a.total-d.length:0,total:r?a.total:d.length}),q=k;for(let N of d)m.set(N,k);let h=d;for(;h.length;){let N=await t.client.request("post","/_pb/sources/discovery/apply",{body:{...k,repositories:h}});if(o)break;let R=N.ok?N.data.results:[],S=N.ok?N.data.remainingRepositories:[],g=N.ok&&N.data.results.some(_=>_.error==="rate_limited"),T=N.ok&&!g&&(S.length>=h.length||S.some(_=>!h.includes(_))),E=!N.ok||T?h.map(_=>({repository:_,outcome:"failed",error:"import_unconfirmed"})):R.map(({repository:_,outcome:U,reason:z})=>({repository:_,outcome:U,...z?{reason:z}:{}}));for(let _ of h)!E.some(U=>U.repository===_)&&!S.includes(_)&&E.push({repository:_,outcome:"failed",error:"import_unconfirmed"});let L=new Map(a.results.map(_=>[_.repository,_]));for(let _ of E)L.set(_.repository,_);if(s({results:[...L.values()],progress:a.total-S.length,pending:g?S:[],...!N.ok||T?{error:"Import could not finish. Retry failed repositories.",progress:a.total}:{}}),g){s({error:"GitHub is rate limiting imports. Continue import when it is available again."});break}if(!N.ok||T)break;h=S}s({busy:!1,importing:!1,selected:[]})}return{snapshot:()=>a,cancel(){o=!0,s({busy:!1,importing:!1})},startOver(){a.busy||(m.clear(),q=void 0,s({entries:[],nextCursor:null,selected:[],reviewed:!1,results:[],pending:[],progress:0,total:0,error:null,patternError:null}))},eligible:n,subscribe:d=>(l.add(d),()=>{l.delete(d)}),async load(){if(a.busy)return;s({loading:!0,error:null});let d=await t.client.request("get","/_pb/sources/discovery/connections");s(d.ok?{loading:!1,connections:d.data.items,connection:d.data.items.length?"0":""}:{loading:!1,error:"GitHub connections could not be loaded. Try again."})},configure(d){a.busy||s({...d,entries:[],nextCursor:null,selected:[],reviewed:!1,error:null,patternError:null})},async preview(d=!1){let f=x();if(a.busy||!f||d&&!a.nextCursor)return;let r=a.pattern||"*";if(!lt(r)){s({patternError:it});return}s({busy:!0,error:null,patternError:null});let u=await t.client.request("post","/_pb/sources/discovery/plan",{body:{credentialId:f.credentialId,installationId:f.installationId,ecosystem:e,includeForks:a.includeForks,pattern:r,cursor:d?a.nextCursor:null}});if(o){s({busy:!1});return}s(u.ok?{busy:!1,entries:u.data.entries,nextCursor:u.data.nextCursor,selected:[],reviewed:!0}:{busy:!1,error:"Repositories could not be previewed. Try again."})},toggle(d,f){a.busy||!a.entries.some(r=>r.repository===d&&r.action==="new"&&n(d))||s({selected:f?[...new Set([...a.selected,d])].slice(0,20):a.selected.filter(r=>r!==d)})},selectPage(d){a.busy||s({selected:d?a.entries.filter(f=>f.action==="new"&&n(f.repository)).map(f=>f.repository).slice(0,20):[]})},importSelected:()=>a.pending.length?Promise.resolve():v(a.selected),continueImport:()=>v(a.pending,q,!0),retryFailed:()=>{let d=a.results.find(r=>r.outcome==="failed"&&!a.pending.includes(r.repository));if(!d)return Promise.resolve();let f=m.get(d.repository);return v(a.results.filter(r=>r.outcome==="failed"&&!a.pending.includes(r.repository)&&m.get(r.repository)===f).map(r=>r.repository).slice(0,20),f)}}}var j=H(K(),1);function jt({services:t,ecosystem:e,onBack:a,onImportingChange:l}){let s=(0,O.useMemo)(()=>kt(t,e),[t,e]),o=(0,O.useSyncExternalStore)(s.subscribe,s.snapshot,s.snapshot);(0,O.useEffect)(()=>(s.load(),()=>s.cancel()),[s]),(0,O.useEffect)(()=>{let r=s.snapshot().importing;l(r);let u=s.subscribe(()=>{s.snapshot().importing!==r&&(r=s.snapshot().importing,l(r))});return()=>{u(),l(!1)}},[s,l]);let m=(0,O.useRef)(null),q=(0,O.useRef)(!1),n=(0,O.useRef)(null),x=(0,O.useRef)(null),v=(0,O.useRef)(null);(0,O.useEffect)(()=>{o.reviewed&&v.current?.focus()},[o.reviewed,o.entries]),(0,O.useEffect)(()=>{!o.loading&&o.connections.length&&!q.current&&(q.current=!0,m.current?.focus())},[o.loading,o.connections.length]),(0,O.useEffect)(()=>{o.patternError&&n.current?.focus()},[o.patternError]);let d=o.entries.filter(r=>r.action==="new"&&s.eligible(r.repository));(0,O.useEffect)(()=>{x.current&&(x.current.indeterminate=o.selected.length>0&&o.selected.length<d.length)},[o.selected,d.length]);let f=o.results.some(r=>r.outcome==="failed"&&!o.pending.includes(r.repository));return(0,j.jsxs)("section",{"aria-label":"GitHub organization repositories",className:"space-y-4",children:[(0,j.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,j.jsx)(C,{variant:"outline",disabled:o.busy,onClick:a,children:"Back"}),(0,j.jsx)(C,{variant:"outline",disabled:o.busy,onClick:()=>s.startOver(),children:"Start over"})]}),o.importing?(0,j.jsx)("p",{children:"Import in progress. Wait for this batch to finish before closing or going back."}):null,(0,j.jsxs)("p",{children:["Import ",e==="npm"?"npm":"Composer"," repositories as shared organization sources. Projects can attach these sources to use their packages."]}),o.loading?(0,j.jsx)("p",{role:"status",children:"Loading GitHub connections\u2026"}):null,o.error?(0,j.jsx)("p",{role:"alert",children:o.error}):null,!o.loading&&!o.connections.length?(0,j.jsx)(j.Fragment,{children:o.error?(0,j.jsx)(C,{onClick:()=>{s.load()},children:"Try again"}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("p",{children:"No GitHub App connections yet. Add one organization GitHub source with GitHub App authentication first, then return here to choose repositories."}),(0,j.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:"#/sources?create=vcs&provider=github",children:"Add a GitHub source"})]})}):null,o.connections.length?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("form",{className:"grid max-w-5xl items-start gap-x-6 gap-y-4 lg:grid-cols-2",onSubmit:r=>{r.preventDefault(),s.preview().then(()=>{s.snapshot().patternError&&n.current?.focus()})},"aria-busy":o.busy,noValidate:!0,children:[(0,j.jsxs)("div",{className:"min-w-0",children:[(0,j.jsx)(V,{htmlFor:"discovery-connection",children:"GitHub connection"}),(0,j.jsx)(Y,{id:"discovery-connection",ref:m,className:"min-h-11 min-w-0 max-w-full",value:o.connection,disabled:o.busy,onChange:r=>s.configure({connection:r.target.value}),children:o.connections.map((r,u)=>(0,j.jsx)("option",{value:String(u),children:nt(r)},`${r.credentialId}:${r.installationId}`))})]}),(0,j.jsxs)("div",{className:"min-w-0",children:[(0,j.jsx)(V,{htmlFor:"discovery-pattern",children:"Repository name pattern (optional)"}),(0,j.jsx)(re,{id:"discovery-pattern",ref:n,className:"min-h-11",value:o.pattern,maxLength:100,pattern:"[A-Za-z0-9._*?\\-]{1,100}","aria-invalid":!!o.patternError,"aria-describedby":`discovery-pattern-help${o.patternError?" discovery-pattern-error":""}`,disabled:o.busy,onChange:r=>s.configure({pattern:r.target.value})}),o.patternError?(0,j.jsx)("p",{id:"discovery-pattern-error",role:"alert",children:o.patternError}):null,(0,j.jsx)("p",{id:"discovery-pattern-help",children:rt})]}),(0,j.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,j.jsx)("input",{type:"checkbox",checked:o.includeForks,disabled:o.busy,onChange:r=>s.configure({includeForks:r.target.checked})}),"Include forks"]}),(0,j.jsx)("div",{className:"lg:col-span-2",children:(0,j.jsx)(C,{className:"min-h-11 w-full sm:w-auto",disabled:o.busy,type:"submit",children:o.busy&&!o.importing?"Previewing repositories\u2026":"Preview repositories"})})]}),(0,j.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:"#/sources?discovery=new","aria-disabled":o.busy||!o.connections[Number(o.connection)],"aria-describedby":"rule-prefill-help",onClick:r=>{let u=o.connections[Number(o.connection)];if(o.busy||!u){r.preventDefault();return}ct(t,{credentialId:u.credentialId,installationId:u.installationId,ecosystem:e,pattern:o.pattern||"*",includeForks:o.includeForks})},children:"Keep this selection up to date"}),(0,j.jsxs)("p",{id:"rule-prefill-help",children:[o.connections[Number(o.connection)]===void 0?"Choose a connection to keep this selection up to date. ":"","A rule scans all repositories matching these settings, including future matches. Individual checkboxes do not limit the rule."]}),o.reviewed?(0,j.jsxs)("div",{className:"space-y-4",children:[(0,j.jsx)("h3",{ref:v,tabIndex:-1,className:"font-semibold",children:"Repository preview"}),(0,j.jsx)("p",{children:"Select up to 20 repositories per import. Load more replaces the current preview page."}),o.selected.length===20?(0,j.jsx)("p",{role:"status","aria-live":"polite",children:"20 repository limit reached. Import these repositories before selecting more."}):null,["new","existing","skipped"].map(r=>{let u=o.entries.filter(k=>(k.action==="new"&&!s.eligible(k.repository)?"existing":k.action)===r);return(0,j.jsxs)("section",{"aria-label":r==="new"?"Will be added":r==="existing"?"Already added":"Skipped",children:[(0,j.jsxs)("h3",{className:"font-semibold",children:[r==="new"?"Will be added":r==="existing"?"Already added":"Skipped"," ","(",u.length,")"]}),r==="new"&&d.length?(0,j.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,j.jsx)("input",{type:"checkbox",disabled:o.busy,ref:x,checked:o.selected.length===Math.min(d.length,20),onChange:k=>s.selectPage(k.target.checked)}),"Select all on page (up to 20)"]}):null,(0,j.jsx)("ul",{className:"space-y-2",children:u.map(k=>(0,j.jsxs)("li",{className:"break-words rounded border p-3",children:[r==="new"?(0,j.jsxs)("label",{className:"flex min-h-11 items-center gap-2",children:[(0,j.jsx)("input",{type:"checkbox",checked:o.selected.includes(k.repository),disabled:o.busy||o.selected.length>=20&&!o.selected.includes(k.repository),onChange:h=>s.toggle(k.repository,h.target.checked)}),k.repository]}):(0,j.jsx)("p",{children:k.repository}),k.packageName?(0,j.jsx)("p",{children:k.packageName}):null,r==="existing"?(0,j.jsx)("p",{children:"This repository already has an organization source. No new source will be created."}):null,r==="skipped"?(0,j.jsx)("p",{children:Te(k.reason)}):null]},`${k.repository}:${k.ecosystem}`))})]},r)}),o.entries.length?null:(0,j.jsx)("p",{children:"No repositories match this preview. Change the pattern or connection and try again."}),(0,j.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,j.jsxs)(C,{className:"min-h-11 w-full sm:w-auto",disabled:o.busy||!!o.pending.length||!o.selected.length,onClick:()=>{s.importSelected()},children:["Import selected (",o.selected.length,")"]}),o.nextCursor?(0,j.jsx)(C,{variant:"outline",className:"min-h-11 w-full sm:w-auto",disabled:o.busy,onClick:()=>{s.preview(!0)},children:"Load more"}):null]})]}):null,o.total>0?(0,j.jsxs)("p",{role:"status","aria-live":"polite",children:[o.importing?"Importing":o.pending.length?"Import paused":"Import finished",": ",o.progress," of ",o.total," repositories processed."]}):null,o.pending.length?(0,j.jsx)(C,{disabled:o.busy,onClick:()=>{s.continueImport()},children:"Continue import"}):null,o.results.length?(0,j.jsxs)("section",{"aria-label":"Import results",className:"space-y-3",children:[(0,j.jsx)("h3",{className:"font-semibold",children:"Import results"}),(0,j.jsx)("ul",{className:"space-y-2",children:o.results.map(r=>(0,j.jsxs)("li",{className:"break-words rounded border p-3",children:[(0,j.jsxs)("p",{children:[r.repository," \xB7"," ",r.outcome==="created"?"Created":r.outcome==="existing"?"Already added":r.outcome==="skipped"?"Refused":"Failed"]}),r.outcome==="skipped"?(0,j.jsx)("p",{children:Te(r.reason)}):null,r.outcome==="failed"?(0,j.jsx)("p",{children:"No successful import was confirmed. Try this repository again."}):null]},r.repository))}),f?(0,j.jsx)(C,{className:"min-h-11 w-full sm:w-auto",disabled:o.busy,onClick:()=>{s.retryFailed()},children:"Retry failed repositories"}):null]}):null]}):null]})}var M=H(je(),1);var i=H(K(),1);function qt(t){return t.status==="paused"?"Paused \xB7 Enable this source to sync.":t.lastError?"Last check failed":t.lastSuccessAt?"Last check succeeded":"Not checked yet"}function Ge(t){return["packagist_proxy","npmjs_proxy","npm_registry"].includes(t.type)&&"attached"in t&&t.attached}function Nt(t,e,a,l){return t.projectId===null?e.includes("org:sources:write"):t.projectId===l&&a.includes("project:sources:write")}function Tt(t){return["packagist_proxy","npmjs_proxy","npm_registry"].includes(t.type)?"Checks packages already held from this source when their metadata is due for refresh. This does not download the whole registry.":t.type==="vcs"?"Syncs the Composer package from this configured Git repository.":"Syncs packages selected in this source's settings."}function Lt(t,e){let{client:a}=t,l={loading:!0,busy:!1,organization:[],permissions:[],projects:[],project:null,sources:[],error:null,notice:null,requested:[],available:null},s=new Set,o=n=>{l={...l,...n},s.forEach(x=>x())},m=0;async function q(n){let x=++m;if(o({loading:!0,busy:!1,project:null,permissions:[],sources:[],error:null,notice:null,available:null}),n===null){let u=[],k;do{let h=await a.request("get","/_pb/sources",{query:{ownership:"organization",limit:"100",...k?{after:k}:{}}});if(x!==m)return;if(!h.ok){o({loading:!1,error:"Sources could not be loaded. Try again."});return}u.push(...h.data.items),k=h.data.next??void 0}while(k);o({loading:!1,sources:u});return}let[v,d]=await Promise.all([a.request("get","/_pb/projects/{project}",{params:{project:n}}),a.request("get","/_pb/projects/{project}/permissions",{params:{project:n}})]);if(x!==m)return;if(!v.ok||v.data.status!=="active"||!d.ok){o({loading:!1,error:"Project access could not be loaded. Choose an active project."});return}let f=[],r;do{let u=await a.request("get","/_pb/projects/{project}/sources",{params:{project:n},query:{limit:"100",...r?{after:r}:{}}});if(x!==m)return;if(!u.ok){o({loading:!1,error:"Sources could not be loaded. Try again."});return}f.push(...u.data.items.filter(k=>k.attached)),r=u.data.next??void 0}while(r);o({loading:!1,project:v.data,permissions:d.data.project,sources:f})}return{snapshot:()=>l,subscribe:n=>(s.add(n),()=>{s.delete(n)}),selectProject:q,clearFeedback(){o({notice:null,error:null,available:null})},async load(){let n=await a.request("get","/_pb/me/permissions");if(o({organization:n.ok?n.data.organization:[]}),e===null){let x=[],v;do{let d=await a.request("get","/_pb/projects",{query:{status:"active",limit:"100",...v?{after:v}:{}}});if(!d.ok)break;let f=await Promise.all(d.data.items.filter(r=>r.status==="active").map(async r=>{let u=await a.request("get","/_pb/projects/{project}/permissions",{params:{project:r.slug}});return u.ok&&u.data.project.includes("project:sources:write")?r:null}));x.push(...f.filter(r=>r!==null)),v=d.data.next??void 0}while(v);o({projects:x})}await q(e)},async submit(n,x,v){let d=l.sources.find(k=>k.id===x);if(!d||l.busy||l.loading||d.status==="paused"||n==="mirror"&&(!l.project||!l.permissions.includes("project:sources:write")||!Ge(d))||n==="sync"&&(!Nt(d,l.organization,l.permissions,l.project?.id??null)||l.requested.includes(d.id)))return;if(v=v.trim(),n==="mirror"&&(!v||v.length>428)){o({error:"Enter a package name of 1 to 428 characters."});return}let f=m;o({busy:!0,error:null,notice:null,available:null});let r=n==="mirror"?await a.request("post","/_pb/projects/{project}/sources/{source}/packages",{params:{project:l.project.slug,source:d.id},body:{name:v}}):d.projectId===null?await a.request("post","/_pb/sources/{source}/sync",{params:{source:d.id}}):await a.request("post","/_pb/projects/{project}/sources/{source}/sync",{params:{project:l.project.slug,source:d.id}});if(f!==m)return;let u=n==="sync"?pt(r):r;u.ok?o({busy:!1,notice:n==="mirror"?ut(u.status,v,d.name):ze,available:n==="mirror"&&u.status===200?{name:v,source:d.id}:null,requested:n==="sync"?[...l.requested,d.id]:l.requested}):o({busy:!1,error:u.status===403?"You no longer have permission to sync this source. Your selection has been kept.":u.code==="source_paused"?"This source is paused. Enable it before syncing.":u.code==="package_not_found"?`No packages match \u2018${v}\u2019 in ${d.name}. Check the name or choose another source.`:u.status===400?"Enter a valid package name for this source.":"Sync couldn't be queued. Try again shortly."})}}}function Dt({ecosystem:t,mirror:e,setup:a,imported:l,onMirror:s,sourceLink:o,onDiscovery:m,orgManager:q=!1}){return(0,i.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,i.jsxs)("div",{className:"rounded border p-4",children:[(0,i.jsx)("h3",{className:"font-semibold",children:"From a mirror"}),(0,i.jsx)("p",{children:t==="npm"?"Find packages in a connected npm registry.":"Find packages in Packagist or another connected Composer repository."}),e?(0,i.jsx)(C,{className:"mt-2 min-h-11",onClick:s,children:"From a mirror"}):(0,i.jsx)("p",{children:"A project source manager can add packages from a mirror."})]}),(0,i.jsxs)("div",{className:"rounded border p-4",children:[(0,i.jsx)("h3",{className:"font-semibold",children:"From a connected GitHub organization"}),(0,i.jsx)("p",{children:"Choose repositories your GitHub connection can access."}),q?(0,i.jsx)(C,{className:"mt-2 min-h-11",onClick:m,children:"Choose GitHub repositories"}):(0,i.jsx)("p",{children:"Ask an organization source manager to connect GitHub."}),a?(0,i.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:`${o}&provider=github`,children:"Set up a GitHub repository source"}):null]}),t==="composer"?(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)("div",{className:"rounded border p-4",children:[(0,i.jsx)("h3",{className:"font-semibold",children:"By repository URL"}),(0,i.jsx)("p",{children:"Add a Composer package from a Git repository."}),a?(0,i.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:o,children:"By repository URL"}):(0,i.jsx)("p",{children:"A source manager can add a Git repository."})]})}):null,t==="composer"?(0,i.jsxs)("div",{className:"rounded border p-4",children:[(0,i.jsx)("h3",{className:"font-semibold",children:"Import configuration"}),(0,i.jsx)("p",{children:"Bring source and package selections from a Satis configuration using the CLI."}),(0,i.jsx)("code",{className:"break-all",children:"pb import satis plan"}),l?(0,i.jsx)("a",{href:"#/import",className:"flex min-h-11 items-center underline",children:"Import review"}):(0,i.jsx)("p",{children:"An organization import manager can review imports."})]}):null,(0,i.jsxs)("div",{className:"lg:col-span-2",children:[(0,i.jsx)("h3",{className:"font-semibold",children:"Upload a private package"}),(0,i.jsx)("p",{children:"Publish a package archive for this project."}),(0,i.jsx)("p",{children:"Coming soon \xB7 Upload and publishing belong to #947."})]})]})}function wt({services:t,project:e,onSourcesChanged:a}){let l=(0,M.useMemo)(()=>Lt(t,e),[t,e]),s=(0,M.useSyncExternalStore)(l.subscribe,l.snapshot,l.snapshot),o=s.loading?null:JSON.stringify(s.sources.map(w=>[w.id,w.name]));(0,M.useEffect)(()=>{o!==null&&a?.(s.project?.slug??e,o)},[o,a,s.project?.slug,e]);let[m,q]=(0,M.useState)(null),[n,x]=(0,M.useState)(!1),[v,d]=(0,M.useState)("composer"),[f,r]=(0,M.useState)(""),[u,k]=(0,M.useState)(!1),[h,N]=(0,M.useState)(""),R=(0,M.useRef)(null);(0,M.useEffect)(()=>{l.load()},[l]),(0,M.useEffect)(()=>{(s.notice||s.error)&&R.current?.focus()},[s.notice,s.error]);let S=s.sources.find(w=>w.id===f),g=s.permissions.includes("project:sources:write"),T=s.organization.includes("org:sources:write"),E=e===null?T:g,L=s.sources.filter(w=>m!=="mirror"||w.ecosystem===v&&Ge(w)),_=S&&(m==="mirror"?g&&!!s.project:Nt(S,s.organization,s.permissions,s.project?.id??null)),U=`#/sources?create=vcs${e?`&project=${encodeURIComponent(e)}`:""}`;function z(w){r(""),k(!1),N(""),l.clearFeedback(),q(w)}return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{className:"my-3 text-neutral-600",children:e?`Packages available to ${s.project?.name??e}.`:"Packages available across your organization."}),(0,i.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,i.jsx)(C,{className:"min-h-11",onClick:()=>z("choices"),children:"Add package"}),(0,i.jsx)(C,{className:"min-h-11",variant:"outline",onClick:()=>z("sync"),children:"Sync from source"})]}),m?(0,i.jsx)(pe,{open:!0,onOpenChange:w=>{!w&&!n&&q(null)},children:(0,i.jsxs)(de,{variant:"source",className:"lg:max-w-5xl",children:[(0,i.jsxs)(me,{className:"shrink-0 p-6 pr-16",children:[(0,i.jsx)(fe,{children:m==="sync"?"Sync from source":m==="discovery"?"Choose GitHub repositories":"Add package"}),(0,i.jsx)(he,{children:m==="discovery"?"Your selected repositories become shared sources in this organization.":m==="sync"?"Check a source for package updates.":s.project?`Add packages to ${s.project.name}.`:"Choose how to add packages to a project."})]}),(0,i.jsxs)("div",{className:"min-h-0 overflow-y-auto px-6 pb-6",children:[s.loading?(0,i.jsx)("p",{role:"status",children:"Loading sources\u2026"}):null,m==="choices"?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(V,{htmlFor:"choice-ecosystem",children:"Ecosystem"}),(0,i.jsxs)(Y,{className:"mb-4 min-h-11",id:"choice-ecosystem",value:v,onChange:w=>d(w.target.value),children:[(0,i.jsx)("option",{value:"composer",children:"Composer"}),(0,i.jsx)("option",{value:"npm",children:"npm"})]}),(0,i.jsx)(Dt,{ecosystem:v,mirror:e===null?s.projects.length>0:g,setup:E,orgManager:T,onDiscovery:()=>q("discovery"),imported:s.organization.includes("org:import:write"),sourceLink:U,onMirror:()=>q("mirror")})]}):m==="discovery"?T?(0,i.jsx)(jt,{services:t,ecosystem:v,onBack:()=>q("choices"),onImportingChange:x}):(0,i.jsx)("p",{children:"Ask an organization source manager to connect GitHub."}):(0,i.jsxs)("form",{id:"source-action-form",className:"grid gap-4 lg:grid-cols-2",onSubmit:w=>{w.preventDefault(),S&&l.submit(m,S.id,h)},children:[e===null?(0,i.jsxs)("div",{children:[(0,i.jsx)(V,{htmlFor:"destination-project",children:"Project"}),(0,i.jsxs)(Y,{id:"destination-project",className:"min-h-11",disabled:s.busy,value:s.project?.slug??"",onChange:w=>{r(""),k(!1),l.selectProject(w.target.value||null)},children:[(0,i.jsx)("option",{value:"",children:m==="sync"?"Organization sources":"Choose a project"}),s.projects.map(w=>(0,i.jsx)("option",{value:w.slug,children:w.name},w.id))]})]}):null,m==="mirror"?(0,i.jsxs)("div",{children:[(0,i.jsx)(V,{htmlFor:"mirror-ecosystem",children:"Ecosystem"}),(0,i.jsxs)(Y,{id:"mirror-ecosystem",className:"min-h-11",value:v,disabled:s.busy,onChange:w=>{d(w.target.value),r(""),k(!1)},children:[(0,i.jsx)("option",{value:"composer",children:"Composer"}),(0,i.jsx)("option",{value:"npm",children:"npm"})]})]}):null,(0,i.jsxs)("div",{children:[(0,i.jsx)(V,{htmlFor:"package-source",children:"Source"}),(0,i.jsxs)(Y,{id:"package-source",className:"min-h-11",required:!0,"aria-invalid":u||void 0,"aria-describedby":u?"package-source-error":void 0,onInvalid:()=>k(!0),disabled:s.loading||s.busy,value:f,onChange:w=>{r(w.target.value),k(!1),l.clearFeedback()},children:[(0,i.jsx)("option",{value:"",children:"Choose a source"}),L.map(w=>(0,i.jsxs)("option",{value:w.id,children:[w.name," \xB7 ",be[w.type]," \xB7 ",qt(w)]},w.id))]}),u?(0,i.jsx)("p",{id:"package-source-error",role:"alert",children:"Choose a source."}):null]}),m==="mirror"?(0,i.jsxs)("div",{children:[(0,i.jsx)(V,{htmlFor:"mirror-package",children:"Find a package"}),(0,i.jsx)(re,{id:"mirror-package",className:"min-h-11",required:!0,maxLength:428,disabled:s.busy,value:h,onChange:w=>{N(w.target.value),l.clearFeedback()},"aria-describedby":"mirror-help"}),(0,i.jsx)("p",{id:"mirror-help",children:"This source does not support search. Enter the full package name."})]}):null,(0,i.jsxs)("div",{className:"space-y-3 lg:col-span-2",children:[!L.length&&!s.loading?(0,i.jsx)("p",{children:s.project?`No sources available for ${s.project.name}. Attach a source before adding packages.`:m==="mirror"?"Choose a destination project before adding packages.":"No sources available."}):null,!L.length&&E&&!s.loading?(0,i.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:`#/sources${s.project?`?project=${encodeURIComponent(s.project.slug)}`:""}`,children:"Manage sources"}):null,S?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{children:S.projectId===null?"Shared organization source":`Only ${s.project?.name??e}`}),(0,i.jsx)("p",{children:qt(S)}),S.status==="paused"?(0,i.jsx)("p",{children:"This source is paused. Enable it before syncing."}):null,m==="sync"&&s.requested.includes(S.id)&&!s.notice?(0,i.jsx)("p",{role:"status",children:ze}):null,m==="sync"?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("h3",{className:"font-semibold",children:Ge(S)||["packagist_proxy","npmjs_proxy"].includes(S.type)?"Check cached packages for updates":"All configured packages"}),(0,i.jsx)("p",{children:Tt(S)}),S.type==="composer_repository"&&S.config&&"selection"in S.config?(0,i.jsxs)("p",{className:"break-words",children:["Configured selection:"," ",[...S.config.selection?.packages??[],...S.config.selection?.patterns??[]].join(", ")||"No packages selected."]}):null,S.projectId===null?(0,i.jsx)("p",{children:"This source is shared. Updated metadata can be used by other attached projects."}):null,_?null:(0,i.jsx)("p",{children:S.projectId===null?"An organization source manager can sync this source.":"A project source manager can sync this source."})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{children:"Checks this source and queues the package if it is not already available."}),(0,i.jsx)("p",{children:"This syncs the selected packages. Dependencies are fetched through your project's sources when requested."})]})]}):null]})]}),s.notice||s.error?(0,i.jsxs)("div",{ref:R,tabIndex:-1,className:"mt-4 break-words",role:s.error?"alert":"status","aria-live":"polite",children:[(0,i.jsx)("h3",{className:"font-semibold",children:s.error?"Request could not be completed":"Request outcome"}),(0,i.jsx)("p",{children:s.error??s.notice}),s.available?(0,i.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:Ee("packages",{project:s.project?.slug??null,q:s.available.name,source:s.available.source}),children:"View"}):null,s.notice?(0,i.jsx)("a",{className:"inline-flex min-h-11 items-center underline",href:`#/sources${s.project?`?project=${encodeURIComponent(s.project.slug)}`:""}`,children:"View sources"}):null]}):null]}),(0,i.jsx)(ge,{className:"shrink-0 border-t bg-white p-4 pb-[max(1rem,env(safe-area-inset-bottom))]",children:(m==="mirror"||m==="sync")&&_&&S?.status!=="paused"?(0,i.jsx)(C,{className:"min-h-11",form:"source-action-form",type:"submit",disabled:s.busy||s.loading||!!s.notice||m==="sync"&&s.requested.includes(S.id),children:s.busy?"Requesting\u2026":m==="mirror"?"Add package":"Request source sync"}):null})]})}):null]})}var $=H(je(),1);var B=H(K(),1),Ft={not_checked:"Not checked",disabled:"Vulnerability checks disabled",unsupported_version:"Not checked: unsupported version",pending:"Not checked yet",upstream_unavailable:"Check unavailable; no result yet",incomplete:"Check incomplete; no complete result yet",expired:"Outdated result"},Bt={affected:{icon:"!",color:"border-red-200 bg-red-50 text-red-800"},not_affected:{icon:"i",color:"border-blue-200 bg-blue-50 text-blue-800"},unknown:{icon:"?",color:"border-neutral-200 bg-neutral-100 text-neutral-700"},stale:{icon:"\u25F7",color:"border-amber-300 bg-amber-50 text-amber-900"}};function $t(t){return t.length<=200&&/^[A-Za-z0-9]/.test(t)&&!/[^A-Za-z0-9._-]/.test(t)?`https://osv.dev/vulnerability/${encodeURIComponent(t)}`:void 0}function St({assessment:t,sourceType:e}){let{status:a,reason:l}=t,s=a==="unknown"&&l==="not_checked",o=["vcs","composer_repository","npm_registry","hosted"].includes(e),m=a==="affected"?`Known advisories: ${t.advisoryCount}`:a==="not_affected"?"No known advisories":a==="stale"?"Outdated result":s&&o?"Not checked: private package":l===null?"Not checked":Ft[l],q=Bt[a];return(0,B.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,B.jsxs)(tt,{variant:"outline",className:q.color,children:[(0,B.jsx)("span",{"aria-hidden":"true",children:q.icon})," ",m]}),s?(0,B.jsx)("p",{children:"Only verified public proxy packages are checked."}):(0,B.jsxs)(B.Fragment,{children:[t.source==="osv"?(0,B.jsxs)("p",{children:["OSV \xB7 ",a==="stale"?"Last checked":"checked"," ",(0,B.jsx)(X,{value:t.fetchedAt,fallback:"No successful check yet"})]}):null,a==="stale"&&t.lastKnownStatus!==null?(0,B.jsx)("p",{children:t.lastKnownStatus==="affected"?`Last result: known advisories: ${t.advisoryCount}`:"Last result: no known advisories"}):null,(0,B.jsxs)("details",{children:[(0,B.jsx)("summary",{className:"cursor-pointer",children:"Advisory check details"}),a==="stale"&&l==="incomplete"?(0,B.jsx)("p",{children:"Check incomplete; last complete result shown."}):null,t.advisoryCount>0&&!t.detailsComplete?(0,B.jsx)("p",{children:"Advisory details pending"}):null,t.advisoriesTruncated?(0,B.jsxs)("p",{children:["Showing ",t.advisories.length," of ",t.advisoryCount," advisories"]}):null,t.advisories.length>0?(0,B.jsx)("ul",{className:"list-disc pl-5",children:t.advisories.map(n=>{let x=$t(n.id);return(0,B.jsxs)("li",{children:[x?(0,B.jsx)("a",{href:x,target:"_blank",rel:"noopener noreferrer",referrerPolicy:"no-referrer",className:"underline",children:n.id}):n.id," \xB7 ",n.severity.level==="unknown"?"Severity unavailable":`Severity: ${n.severity.level}`,n.detailsFetchedAt===null?(0,B.jsx)("span",{children:" \xB7 Advisory details pending"}):(0,B.jsxs)("span",{children:[" ","\xB7 Details fetched ",(0,B.jsx)(X,{value:n.detailsFetchedAt})]})]},n.id)})}):null]})]})]})}var c=H(K(),1),Pt=["active","quarantined","tombstoned","removed_upstream"],Vt={quarantine:"Quarantine",tombstone:"Tombstone",release:"Release"},xt=t=>st[t];function Ct(t){return t.organization.includes("org:packages:manage")?"Organization":`Project ${t.projectSlug}`}function ye(t){let e=new URLSearchParams(Xe(t).split("?")[1]),a={project:e.get("project")},l=e.get("status");Pt.includes(l)&&(a.status=l);let s=e.get("source");s!==null&&(a.source=s);let o=e.get("projectId");a.project===null&&o!==null&&(a.projectId=o);let m=e.get("q")?.trim().toLowerCase();m&&m.length<=100&&!m.includes("\0")&&(a.q=m);let q=e.get("after");return q!==null&&(a.after=q),a}function qe(t){return Ee("packages",t)}function At(t,e,a){let l=a.organization.includes("org:packages:manage"),s=a.projectSlug!==null&&a.projectId!==null&&a.project.includes("project:packages:manage")&&t.source.projectId===a.projectId;if(!l&&!s)return[];let o=[];return(e==="active"||e==="removed_upstream")&&o.push("quarantine"),(e==="active"||e==="removed_upstream"||e==="quarantined")&&o.push("tombstone"),e==="quarantined"&&o.push("release"),o}function zt(t){let e={query:{project:null},items:[],next:null,access:{organization:[],project:[],projectId:null,projectSlug:null},selected:null,versions:[],versionsNext:null,loading:!1,versionsLoading:!1,busy:!1,notice:null,confirmVersion:null},a=new Set,l=h=>{e={...e,...h};for(let N of a)N()},s=0,o=0,m=0,q=null,n,x=t.client;async function v(h,N=null){let R=++s;++o,q=null,l({query:h,items:[],next:null,selected:null,versions:[],versionsNext:null,confirmVersion:null,loading:!0,listError:!1,versionsError:!1,versionsLoading:!1,busy:!1,notice:N,access:{organization:[],project:[],projectId:null,projectSlug:h.project}});let S={status:h.status,source:h.source,q:h.q,after:h.after},[g,T,E,L]=await Promise.all([x.request("get","/_pb/me/permissions"),h.project===null?null:x.request("get","/_pb/projects/{project}/permissions",{params:{project:h.project}}),h.project===null?null:x.request("get","/_pb/projects/{project}",{params:{project:h.project}}),h.project===null?x.request("get","/_pb/packages",{query:{...S,project:h.projectId}}):x.request("get","/_pb/projects/{project}/packages",{params:{project:h.project},query:S})]);R===s&&(q=L.ok?qe(h):null,l({loading:!1,listError:!L.ok,access:{organization:g.ok?g.data.organization:[],project:T?.ok?T.data.project:[],projectId:E?.ok?E.data.id:null,projectSlug:h.project},items:L.ok?L.data.items:[],next:L.ok?L.data.next:null,notice:[N,L.ok?null:L.status===404?"Not found.":"Packages could not be loaded. Try again."].filter(Boolean).join(" ")||null}))}async function d(h,N){if(e.busy||e.loading)return;let R=e.items.find(L=>L.id===h);if(!R)return;let S=++o,g=s,T=e.query.project;n=N,l({selected:R,versions:[],versionsNext:null,versionsLoading:!0,versionsError:!1,confirmVersion:null});let E=T===null?await x.request("get","/_pb/packages/{package}/versions",{params:{package:h},query:{after:N}}):await x.request("get","/_pb/projects/{project}/packages/{package}/versions",{params:{project:T,package:h},query:{after:N}});S!==o||g!==s||l({versionsLoading:!1,versionsError:!E.ok,versions:E.ok?E.data.items:[],versionsNext:E.ok?E.data.next:null,notice:E.ok?e.notice:E.status===404?"Not found.":"Versions could not be loaded. Try again."})}function f(){++o,n=void 0,l({selected:null,versions:[],versionsNext:null,versionsLoading:!1,confirmVersion:null})}async function r(h,N,R){let S=++m;q!==qe(h)&&await v(h),S===m&&(N?await d(N,R):f())}async function u(h=null){let N=e.selected?.id,R=n,S=s,g=m;await v(e.query,h),s===S+1&&g===m&&N&&await d(N,R)}async function k(h,N,R=!1,S=""){let g=e.selected,T=e.versions.find(ee=>ee.id===h);if(e.busy||e.loading||e.versionsLoading||!g||!T||!At(g,T.status,e.access).includes(N))return;if(N==="tombstone"&&!R){l({confirmVersion:h});return}let E=s,L=o,_=e.query,U={package:g.id,version:T.id},z=e.access.projectSlug;l({busy:!0,notice:null});let w=e.access.organization.includes("org:packages:manage")?await x.request("post",`/_pb/packages/{package}/versions/{version}/${N}`,{params:U,body:N==="tombstone"?{reason:S}:{}}):await x.request("post",`/_pb/projects/{project}/packages/{package}/versions/{version}/${N}`,{params:{...U,project:z},body:N==="tombstone"?{reason:S}:{}});if(!(E!==s||L!==o)){if(l({busy:!1}),!w.ok&&w.code==="reauth_required"){l({confirmVersion:null}),t.requireReauth(w.request,{credential:!1,secretFields:[],display:{packageName:g.name,version:T.version,scope:Ct(e.access)}});return}if(!w.ok&&w.status===404){await v(_,"Not found.");return}if(!w.ok){l({notice:w.status===409?"The version changed, refresh.":"The action could not be completed. Try again."});return}await v(_,"Version updated."),s===E+1&&await d(g.id)}}return{snapshot:()=>e,subscribe(h){return a.add(h),()=>{a.delete(h)}},async replayed(h){let N=e.query.project===null?null:`/_pb/projects/${encodeURIComponent(e.query.project)}/packages/`,R=h.path.startsWith("/_pb/packages/")?h.path.slice(14):N!==null&&h.path.startsWith(N)?h.path.slice(N.length):null;R===null||!/^[^/]+\/versions\/[^/]+\/(quarantine|tombstone|release)$/.test(R)||await u(h.ok?"Version updated.":h.status===404?"Not found.":h.status===409?"The version changed, refresh.":"The action could not be completed. Try again.")},load:v,open:d,navigate:r,refresh:u,act:k,close:f,cancelTombstone:()=>l({confirmVersion:null}),async confirmTombstone(h){if(!h.trim()||new TextEncoder().encode(h).byteLength>1e3)return;let N=e.confirmVersion;N!==null&&await k(N,"tombstone",!0,h)},dispose(){++m,++s,++o}}}function Ue(t){return(0,c.jsx)(ie,{label:`Versions of ${t.item.name}`,items:t.versions,columns:[{key:"version",label:"Version",value:e=>e.version,render:e=>(0,c.jsx)("span",{className:"font-mono",children:e.version})},{key:"status",label:"Status",value:e=>e.status,render:e=>(0,c.jsx)(_e,{status:e.status})},{key:"vulnerability",label:"Known vulnerabilities",value:e=>e.vulnerability.status,render:e=>(0,c.jsx)(St,{assessment:e.vulnerability,sourceType:t.item.source.type})},{key:"published",label:"Published",priority:2,value:e=>e.publishedAt??"",render:e=>(0,c.jsx)(X,{value:e.publishedAt})},{key:"actions",label:"Actions",value:()=>"",render:e=>(0,c.jsx)("div",{className:"flex flex-wrap gap-2",children:At(t.item,e.status,t.access).map(a=>(0,c.jsx)(C,{type:"button",size:"sm",variant:a==="tombstone"?"ghost":"outline",className:a==="tombstone"?"text-red-700":void 0,disabled:t.busy,"data-package-action":a,onClick:()=>t.onAction(e.id,a),children:Vt[a]},a))})}]})}function Ht(t){let{state:e}=t,[a,l]=(0,$.useState)("");(0,$.useEffect)(()=>{e.confirmVersion!==null&&l("")},[e.confirmVersion]);let s=new TextEncoder().encode(a).byteLength,o=a.trim().length>0&&s<=1e3,m=e.versions.find(n=>n.id===e.confirmVersion),q=!!(e.query.q||e.query.status||e.query.source||e.query.projectId||e.query.after);return(0,c.jsxs)(c.Fragment,{children:[e.notice?(0,c.jsx)(Ye,{className:"my-4",children:(0,c.jsx)(Ke,{children:e.notice})}):null,(0,c.jsxs)("div",{className:"my-4 flex flex-wrap items-center gap-3",children:[(0,c.jsx)("span",{className:"mr-auto text-neutral-600",children:e.selected?e.selected.name:`${e.items.length} packages on this page`}),(0,c.jsx)(C,{type:"button",variant:"outline",onClick:t.onRefresh,disabled:e.loading||e.busy,children:"Refresh"})]}),e.selected===null?e.loading?(0,c.jsx)(Z,{kind:"loading",title:"Loading packages\u2026"}):e.items.length?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(ie,{label:"Packages",items:e.items,columns:[{key:"name",label:"Name",value:n=>n.name,render:n=>(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(C,{type:"button",variant:"link",className:"h-auto min-h-11 max-w-full justify-start whitespace-normal break-words p-0 text-left",disabled:e.busy,onClick:()=>t.onOpen(n.id),children:n.name}),(0,c.jsx)("span",{className:"block text-xs text-neutral-600",children:n.ecosystem})]})},{key:"status",label:"Status",value:n=>n.status,render:n=>(0,c.jsx)(_e,{status:n.status})},{key:"latest",label:"Latest version",value:n=>n.latestVersion??"",render:n=>(0,c.jsx)("span",{className:"font-mono",children:n.latestVersion??"\u2014"})},{key:"source",label:"Winning source",priority:2,value:n=>n.source.name,render:n=>(0,c.jsxs)(c.Fragment,{children:[n.source.name,(0,c.jsx)("span",{className:"block text-xs text-neutral-600",children:be[n.source.type]})]})},{key:"count",label:"Version count",priority:2,value:n=>n.versionCount},{key:"synced",label:"Last synced",priority:3,value:n=>n.lastSyncedAt??"",render:n=>(0,c.jsx)(X,{value:n.lastSyncedAt,fallback:"Never"})}]}),e.next?(0,c.jsx)(C,{type:"button",className:"my-4",variant:"outline",disabled:e.busy,onClick:t.onNext,children:"Next packages"}):null]}):e.listError?(0,c.jsx)(Z,{kind:"error",title:"Packages could not be loaded",children:(0,c.jsx)(C,{type:"button",variant:"outline",onClick:t.onRefresh,children:"Retry"})}):(0,c.jsx)(Z,{kind:q?"filtered-empty":"empty",title:q?"No packages match these filters":"No packages yet",children:q?"Change or clear the filters to see more packages.":`No packages yet. Add a package from a connected source, or attach a source to get started. ${dt}`}):(0,c.jsxs)("section",{"aria-labelledby":"versions-heading",className:"space-y-4",children:[(0,c.jsx)(C,{type:"button",variant:"link",className:"px-0",onClick:t.onBack,disabled:e.busy,children:"\u2190 Back to packages"}),(0,c.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,c.jsxs)("h2",{id:"versions-heading",className:"text-lg font-semibold break-all",children:["Versions of ",e.selected.name]}),(0,c.jsx)(_e,{status:e.selected.status})]}),(0,c.jsx)(Je,{value:e.selected.id,label:"package ID"}),e.versionsLoading?(0,c.jsx)(Z,{kind:"loading",title:"Loading versions\u2026"}):e.versions.length?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(Ue,{item:e.selected,versions:e.versions,access:e.access,busy:e.busy,onAction:t.onAction}),e.versionsNext?(0,c.jsx)(C,{type:"button",variant:"outline",disabled:e.busy,onClick:t.onVersionNext,children:"Next versions"}):null]}):(0,c.jsx)(Z,{kind:e.versionsError?"error":"empty",title:e.versionsError?"Versions could not be loaded":"No versions found."})]}),e.confirmVersion!==null?(0,c.jsx)(pe,{open:!0,onOpenChange:n=>{n||t.onCancel()},children:(0,c.jsxs)(de,{children:[(0,c.jsxs)(me,{children:[(0,c.jsxs)(fe,{children:["Tombstone ",m?.version??"version","?"]}),(0,c.jsx)(he,{children:"This removes the version from package resolution. Clients can no longer install it. Only this version is affected. This cannot be undone."})]}),(0,c.jsxs)("dl",{className:"detail-list",children:[(0,c.jsx)("dt",{children:"Package"}),(0,c.jsx)("dd",{children:e.selected?.name}),(0,c.jsx)("dt",{children:"Version"}),(0,c.jsx)("dd",{className:"font-mono",children:m?.version}),(0,c.jsx)("dt",{children:"Scope"}),(0,c.jsx)("dd",{children:Ct(e.access)})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(V,{htmlFor:"tombstone-reason",children:"Reason (required)"}),(0,c.jsx)(re,{id:"tombstone-reason",disabled:e.busy,required:!0,value:a,"aria-describedby":"tombstone-reason-help","aria-invalid":s>1e3,onChange:n=>l(n.target.value)}),(0,c.jsxs)("p",{id:"tombstone-reason-help",children:["Enter a reason of 1\u20131000 UTF-8 bytes. ",s," bytes used."]})]}),(0,c.jsxs)(ge,{children:[(0,c.jsx)(C,{type:"button",variant:"outline",onClick:t.onCancel,children:"Cancel"}),(0,c.jsx)(C,{type:"button",variant:"destructive",disabled:!o||e.busy,onClick:()=>t.onConfirm(a),children:"Confirm tombstone"})]})]})}):null]})}function Ot(t){let e=new Map;return Object.assign(l=>{let s=e.get(l);if(s)return s;let o=(async()=>{let m=[],q,n=!0;do{let v=l===null?await t.client.request("get","/_pb/sources",{query:{after:q}}):await t.client.request("get","/_pb/projects/{project}/sources",{params:{project:l},query:{after:q}});if(!v.ok){n=!1;break}m.push(...v.data.items),q=v.data.next??void 0}while(q);let x=[];if(l===null){q=void 0;do{let v=await t.client.request("get","/_pb/projects",{query:{after:q}});if(!v.ok){n=!1;break}x.push(...v.data.items),q=v.data.next??void 0}while(q)}return n||e.delete(l),{sources:m,projects:x}})();return e.set(l,o),o},{invalidate:()=>e.clear()})}function Mt(t){let[e,a]=(0,$.useState)(t.query),{q:l,status:s,source:o,projectId:m,project:q}=t.query;(0,$.useEffect)(()=>{a({project:q,...l?{q:l}:{},...s?{status:s}:{},...o?{source:o}:{},...m?{projectId:m}:{}})},[l,s,o,m,q]);let[n,x]=(0,$.useState)(null);(0,$.useEffect)(()=>{let u=!0;return x(null),t.loadChoices(t.query.project).then(k=>{u&&x(k)}),()=>{u=!1}},[t.loadChoices,t.query.project,t.choicesRevision]);let v=n?.sources??[],d=n?.projects??[],f=n!==null;function r(u){u.preventDefault();let k=new FormData(u.currentTarget),h=new URLSearchParams;t.query.project!==null&&h.set("project",t.query.project);for(let N of["status","source","projectId","q"]){let R=k.get(N);typeof R=="string"&&R.trim()!==""&&h.set(N,R.trim())}t.onChange(ye(`#/packages?${h}`))}return(0,c.jsx)(ot,{chips:["q","status","source","projectId"].flatMap(u=>t.query[u]&&(f||u!=="source"&&u!=="projectId")?[{label:{q:"Name prefix",status:"Status",source:"Source",projectId:"Project"}[u],value:u==="source"?v.find(k=>k.id===t.query.source)?.name??"Name unavailable":u==="projectId"?d.find(k=>k.id===t.query.projectId)?.name??"Name unavailable":u==="status"?xt(t.query.status):t.query[u],onRemove:()=>{let k={...t.query};delete k[u],delete k.after,t.onChange(k)}}]:[]),children:(0,c.jsxs)("form",{onSubmit:r,className:"my-4 flex flex-wrap items-end gap-3",children:[(0,c.jsxs)("div",{children:[(0,c.jsx)(V,{htmlFor:"package-q",children:"Name prefix"}),(0,c.jsx)(re,{id:"package-q",name:"q",maxLength:100,value:e.q??"",onChange:u=>a(k=>({...k,q:u.target.value}))})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(V,{htmlFor:"package-status",children:"Status"}),(0,c.jsxs)(Y,{id:"package-status",name:"status",value:e.status??"",onChange:u=>a(k=>({...k,status:u.target.value})),children:[(0,c.jsx)("option",{value:"",children:"All statuses"}),Pt.map(u=>(0,c.jsx)("option",{value:u,children:xt(u)},u))]})]}),(0,c.jsxs)("div",{children:[(0,c.jsx)(V,{htmlFor:"package-source",children:"Source"}),(0,c.jsxs)(Y,{className:"min-h-11",id:"package-source",name:"source",value:e.source??"",onChange:u=>a(k=>({...k,source:u.target.value})),disabled:!f,children:[(0,c.jsx)("option",{value:"",children:"All sources"}),t.query.source&&!v.some(u=>u.id===t.query.source)&&(0,c.jsx)("option",{value:t.query.source,children:"Name unavailable"}),v.map(u=>(0,c.jsx)("option",{value:u.id,children:u.name},u.id))]})]}),t.query.project===null?(0,c.jsxs)("div",{children:[(0,c.jsx)(V,{htmlFor:"package-project",children:"Project"}),(0,c.jsxs)(Y,{className:"min-h-11",id:"package-project",name:"projectId",value:e.projectId??"",onChange:u=>a(k=>({...k,projectId:u.target.value})),disabled:!f,children:[(0,c.jsx)("option",{value:"",children:"All projects"}),t.query.projectId&&!d.some(u=>u.id===t.query.projectId)&&(0,c.jsx)("option",{value:t.query.projectId,children:"Name unavailable"}),d.map(u=>(0,c.jsx)("option",{value:u.id,children:u.name},u.id))]})]}):null,(0,c.jsx)(C,{type:"submit",children:"Apply filters"}),(0,c.jsx)(C,{type:"reset",variant:"outline",onClick:()=>t.onChange({project:t.query.project}),children:"Clear filters"})]})})}function eo(){let t=et(),e=(0,$.useMemo)(()=>zt(t),[t]),[a,l]=(0,$.useState)(0),s=(0,$.useMemo)(()=>Ot(t),[t]),o=(0,$.useRef)(new Map),m=(0,$.useCallback)((f,r)=>{if(f!==void 0&&r!==void 0){let u=o.current.get(f);if(o.current.set(f,r),u===void 0||u===r)return}s.invalidate(),l(u=>u+1)},[s]),q=(0,$.useSyncExternalStore)(e.subscribe,e.snapshot,e.snapshot),[n,x]=(0,$.useState)(()=>typeof window>"u"?"#/packages":window.location.hash);(0,$.useEffect)(()=>{let f=()=>x(window.location.hash);return window.addEventListener("hashchange",f),()=>window.removeEventListener("hashchange",f)},[]),(0,$.useEffect)(()=>{if(/^#\/packages\//.test(n))return;let f=new URLSearchParams(n.split("?")[1]);return e.navigate(ye(n),f.get("package")??void 0,f.get("versionAfter")??void 0),()=>e.dispose()},[e,n]),(0,$.useEffect)(()=>t.subscribeReplay?.(f=>{f.ok&&/\/sources(?:\/|$)/.test(f.path)&&m(),e.replayed(f)}),[t,e,m]);let v=f=>{window.location.hash=qe(f)},d=/^#\/packages\/([^?]+)(?:\?|$)/.exec(n);return d?(0,c.jsx)(vt,{services:t,id:d[1],project:ye(n).project,back:qe(ye(n))},n):(0,c.jsxs)("section",{"aria-labelledby":"page-heading",children:[(0,c.jsx)("h1",{tabIndex:-1,id:"page-heading",className:"text-2xl font-semibold",children:"Packages"}),q.selected===null?(0,c.jsx)(yt,{services:t,project:ye(n).project},q.query.project):null,q.selected===null?(0,c.jsx)(wt,{services:t,project:q.query.project,onSourcesChanged:m},q.query.project):null,q.selected===null?(0,c.jsx)(Mt,{loadChoices:s,choicesRevision:a,query:ye(n),onChange:v}):null,(0,c.jsx)(Ht,{state:q,onOpen:f=>{let r=new URLSearchParams(qe(q.query).split("?")[1]);window.location.hash=`#/packages/${f}${r.size?`?${r}`:""}`},onBack:()=>v(q.query),onAction:(f,r)=>{e.act(f,r)},onNext:()=>{q.next!==null&&v({...q.query,after:q.next})},onVersionNext:()=>{if(q.selected&&q.versionsNext){let f=new URLSearchParams(n.split("?")[1]);f.set("versionAfter",q.versionsNext),window.location.hash=`#/packages?${f}`}},onRefresh:()=>{e.refresh()},onConfirm:f=>{e.confirmTombstone(f)},onCancel:e.cancelTombstone})]})}export{Ue as PackageVersions,eo as PackagesPage,Ht as PackagesView,qe as buildPackagesHash,Ot as createPackageFilterChoicesLoader,zt as createPackagesController,At as packageActions,ye as parsePackagesHash};
@@ -1 +1 @@
1
- import{a as K,b as Z,c as P,d as X,h as ee,i as te,j as se}from"./chunk.6ea6bdcaa465.js";import"./chunk.28a4d8aab337.js";import{b as J}from"./chunk.8442124f6802.js";import{a as D}from"./chunk.a6d755a9789f.js";import{a as Y,c as V}from"./chunk.965b76812604.js";import"./chunk.3fcd6998795a.js";import"./chunk.741aec8d1ff9.js";import{D as G,E as L,F as T,K as W,c as N,d as Q,g as M,j as q,p as $}from"./chunk.fd375c54b526.js";var E=N(Q(),1);var j=N(Q(),1);var U=/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/,A="1\u201364 lowercase letters, numbers or hyphens. Start and end with a letter or number.";function z(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64).replace(/-+$/g,"")}function ae(e,t){return{...e,name:t,slug:e.manualSlug?e.slug:z(t)}}function oe(e,t){return{...e,slug:t,manualSlug:!0}}function ne(e){return{...e,slug:z(e.name),manualSlug:!1}}function re(e,t=!1){let n={};return e.name.trim()?[...e.name].length>100?n.name="Use 100 characters or fewer.":/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u.test(e.name)&&(n.name="Use a name without control or formatting characters."):n.name="Enter a project name.",!t&&!U.test(e.slug)&&(n.slug=!e.slug&&e.name&&!z(e.name)?"Enter a project slug using lowercase letters, numbers or hyphens.":A),n}function ie(e,t){return{name:e.name,tokenMaxScope:e.tokenMaxScope,...t?{}:{slug:e.slug}}}function le(e,t){if(e.ok)return{};if(!t&&e.code==="duplicate")return{slug:"This project slug is already in use. Choose another."};let n={};for(let a of e.details)a.location&&a.location!=="body"||(a.path==="/body/name"&&(n.name="Check the entered values and try again."),!t&&a.path==="/body/slug"&&(n.slug=A),a.path==="/body/tokenMaxScope"&&(n.tokenMaxScope="Check the entered values and try again."));return n}var pe="This change limits existing personal and service tokens on their next request. Downloads can continue, but access above this limit will stop. Check any CI jobs that use these tokens.";function ce(e,t){let n=["read","write","full"];return e===t?null:n.indexOf(t)<n.indexOf(e)?pe:"Existing tokens may regain access if their scope and permissions allow it."}var o=N(M(),1),ue=[{value:"read",label:"Install and download",summary:"Install and download only",description:"Read project details and download packages."},{value:"write",label:"Include publish permission",summary:"Publish permission included",description:"Also allow the package publishing permission. Publish npm packages to an enabled hosted source that claims the package name."},{value:"full",label:"Include grants, sources and audit access",summary:"Grants, sources and audit access included",description:"Also allow reading project grants, sources and audit records, plus the publish permission."}];function F(e){let t=(0,j.useId)(),n=(0,j.useRef)(null),a=(0,j.useRef)(null),h=(0,j.useRef)(null),u=!!e.project,[s,l]=(0,j.useState)({name:e.project?.name??"",slug:e.project?.slug??"",tokenMaxScope:e.project?.tokenMaxScope??"read",manualSlug:!1}),[r,f]=(0,j.useState)({}),[p,x]=(0,j.useState)(!1),[b,I]=(0,j.useState)(""),m=c=>{f(c);let v=["name","slug","tokenMaxScope"].find(g=>c[g]);v==="tokenMaxScope"&&a.current&&(a.current.open=!0),v&&n.current?.querySelector(`[name="${v}"]`)?.focus()},d=U.test(s.slug)?s.slug:"{project-slug}",k=typeof window>"u"?"":window.location.origin,y=e.project?ce(e.project.tokenMaxScope,s.tokenMaxScope):null;return(0,o.jsxs)("form",{ref:n,noValidate:!0,"aria-label":u?"Project settings":"New project",className:"my-6 grid min-w-0 max-w-5xl items-start gap-x-6 gap-y-4 lg:grid-cols-2",onSubmit:async c=>{if(c.preventDefault(),e.disabled||p)return;I("");let v=re(s,u);if(m(v),!Object.keys(v).length){x(!0);try{let g=await e.submit(ie(s,u));if(g&&!g.ok){let w=le(g,u);m(w),Object.keys(w).length||h.current?.focus(),I(g.status===412?"This project changed while you were editing. Reload the latest settings before saving.":P(g))}else g?.ok&&I(u?"Access policy saved. Existing tokens now use this limit.":"Project created.")}finally{x(!1)}}},children:[(0,o.jsxs)("div",{className:"grid min-w-0 gap-1",children:[(0,o.jsx)(T,{htmlFor:`${t}-name`,children:"Project name"}),(0,o.jsx)(L,{id:`${t}-name`,name:"name",required:!0,className:"h-11",placeholder:"e.g. Acme Company",value:s.name,onChange:c=>l(ae(s,c.target.value)),"aria-describedby":`${t}-name-help ${t}-name-error`,"aria-invalid":!!r.name}),(0,o.jsx)("p",{id:`${t}-name-help`,className:"text-sm text-neutral-600",children:"A name your team will recognize. You can change it later."}),(0,o.jsx)("p",{id:`${t}-name-error`,className:"text-sm text-red-700",children:r.name})]}),(0,o.jsxs)("div",{className:"grid min-w-0 gap-1",children:[u?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"text-sm font-medium",children:"Project slug"}),(0,o.jsx)("p",{className:"break-all",children:s.slug})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(T,{htmlFor:`${t}-slug`,children:"Project slug"}),(0,o.jsx)(L,{id:`${t}-slug`,name:"slug",required:!0,className:"h-11",placeholder:"e.g. acme-company",value:s.slug,onChange:c=>l(oe(s,c.target.value)),"aria-describedby":`${t}-slug-help ${t}-slug-rule ${t}-slug-error`,"aria-invalid":!!r.slug}),s.manualSlug?(0,o.jsx)($,{type:"button",variant:"ghost",className:"min-h-11 justify-self-start",onClick:()=>l(ne(s)),children:"Use suggested slug"}):null]}),(0,o.jsx)("p",{id:`${t}-slug-help`,className:"text-sm text-neutral-600",children:"Used in repository URLs and CLI commands. You cannot change it later."}),u?null:(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{id:`${t}-slug-rule`,className:"text-sm text-neutral-600",children:A}),(0,o.jsx)("p",{id:`${t}-slug-error`,className:"text-sm text-red-700",children:r.slug})]})]}),(0,o.jsxs)("div",{className:"grid min-w-0 gap-2 rounded-md border border-neutral-300 bg-neutral-50 p-4 lg:col-span-2",children:[(0,o.jsx)("p",{className:"text-sm font-medium",children:"Repository URLs"}),(0,o.jsxs)("dl",{className:"grid min-w-0 gap-2 text-sm",children:[(0,o.jsxs)("div",{className:"min-w-0",children:[(0,o.jsx)("dt",{children:"Composer"}),(0,o.jsx)("dd",{className:"overflow-x-auto whitespace-nowrap",tabIndex:0,children:(0,o.jsx)("code",{children:`${k}/${d}`})})]}),(0,o.jsxs)("div",{className:"min-w-0",children:[(0,o.jsx)("dt",{children:"npm"}),(0,o.jsx)("dd",{className:"overflow-x-auto whitespace-nowrap",tabIndex:0,children:(0,o.jsx)("code",{children:`${k}/${d}/npm/`})})]})]})]}),(0,o.jsxs)("details",{ref:a,className:"min-w-0 rounded-md border border-neutral-300 lg:col-span-2",children:[(0,o.jsxs)("summary",{className:"min-h-11 cursor-pointer p-4 font-medium focus-visible:ring-2 focus-visible:ring-blue-600",children:["Access policy",(0,o.jsx)("span",{className:"block text-sm font-normal text-neutral-600",children:ue.find(c=>c.value===s.tokenMaxScope)?.summary})]}),(0,o.jsxs)("fieldset",{className:"m-4 grid min-w-0 gap-3","aria-describedby":`${t}-policy-help ${t}-policy-note ${t}-policy-error`,children:[(0,o.jsx)("legend",{className:"font-medium",children:"What can tokens do on this project?"}),(0,o.jsx)("p",{id:`${t}-policy-help`,className:"text-sm text-neutral-600",children:"Sets the maximum access for personal and service tokens, including tokens used by CI. Each token still needs its own permissions. Your access in the admin UI is unchanged."}),ue.map(c=>(0,o.jsxs)(T,{htmlFor:`${t}-${c.value}`,className:"flex min-h-11 cursor-pointer items-start gap-3 rounded-md border border-neutral-300 p-3 has-checked:border-blue-700 has-checked:bg-blue-50",children:[(0,o.jsx)("input",{id:`${t}-${c.value}`,type:"radio",name:"tokenMaxScope",value:c.value,checked:s.tokenMaxScope===c.value,onChange:()=>l({...s,tokenMaxScope:c.value}),className:"mt-1 accent-blue-700 focus-visible:ring-2 focus-visible:ring-blue-600","aria-describedby":`${t}-${c.value}-description ${t}-policy-error`,"aria-invalid":!!r.tokenMaxScope}),(0,o.jsxs)("span",{children:[c.label,c.value==="read"?(0,o.jsx)("span",{className:"ml-2 inline-block rounded bg-blue-100 px-1 text-xs text-blue-800",children:"Recommended"}):null,(0,o.jsx)("span",{id:`${t}-${c.value}-description`,className:"mt-1 block text-sm font-normal text-neutral-600",children:c.description})]})]},c.value)),(0,o.jsx)("p",{id:`${t}-policy-note`,className:"text-sm text-neutral-600",children:"Tokens cannot change project settings or delete packages. Publishing is not available in this version."}),(0,o.jsx)("p",{id:`${t}-policy-error`,className:"text-sm text-red-700",children:r.tokenMaxScope})]})]}),e.project?.requirePublishApproval?(0,o.jsx)("p",{className:"text-sm text-neutral-600 lg:col-span-2",children:"Publish approval is saved as required, but approval is not enforced in this version."}):null,y?(0,o.jsx)("p",{className:"text-sm text-neutral-600 lg:col-span-2",children:y}):null,(0,o.jsx)("div",{className:"lg:col-span-2",children:(0,o.jsx)($,{type:"submit",className:"min-h-11 w-full sm:w-auto lg:w-auto",disabled:e.disabled||p,children:p?u?"Saving settings\u2026":"Creating project\u2026":u?"Save settings":(0,o.jsx)(o.Fragment,{children:"Create project"})})}),(0,o.jsx)("p",{ref:h,role:"status",tabIndex:-1,className:"lg:col-span-2",children:p?u?"Saving settings\u2026":"Creating project\u2026":b||(Object.keys(r).length?"Check the entered values and try again.":"")})]})}var i=N(M(),1),S="Project archived.",_=["active","archived"],O=e=>K(e,_),C=e=>q("projects",O(q("projects",e)));async function B(e,t,n=!0){if(t.status)return e.request("get","/_pb/projects",{query:{status:t.status,after:t.after,limit:"50"}});let a=[t.after,void 0];if(t.after?.startsWith("all:"))try{let l=JSON.parse(t.after.slice(4));if(!Array.isArray(l)||l.length!==2||!l.every(r=>r===null||typeof r=="string"))throw new Error("Invalid cursor");a=l}catch{return{ok:!1,status:400,code:"invalid_request",details:[],request:{method:"GET",path:"/_pb/projects"}}}if(!n&&a[0]===null)return{ok:!0,status:200,data:{items:[],next:null}};if(!n)return e.request("get","/_pb/projects",{query:{status:"active",after:a[0]??void 0,limit:"50"}});let h=await Promise.all(_.map((l,r)=>a[r]===null?null:e.request("get","/_pb/projects",{query:{status:l,after:a[r]??void 0,limit:"50"}}))),u=[],s=[];for(let[l,r]of h.entries()){if(r&&!r.ok){if(_[l]==="archived"&&r.status===403){s.push(null);continue}return r}r?.ok&&u.push(...r.data.items),s.push(r?.ok?r.data.next:null)}return{ok:!0,status:200,data:{items:u,next:s.some(l=>l!==null)?`all:${JSON.stringify(s)}`:null}}}function R(e){let t=e.selected,n=!!t&&!!e.etag&&!e.loading&&!e.stale;return{items:e.items.filter(a=>!e.query.q||a.name.toLowerCase().startsWith(e.query.q.toLowerCase())),create:e.organization.includes("org:projects:create")&&!e.stale&&!e.loading,settings:n&&t.status==="active"&&e.permissions.includes("project:settings:write"),transition:n&&e.organization.includes("org:projects:archive"),transitionItems:!e.loading&&!e.stale&&e.organization.includes("org:projects:archive")}}function de(e){let t=Z({query:{project:null},items:[],next:null,selected:null,etag:null,organization:[],permissions:[],loading:!1,listError:!1,busy:!1,stale:!1,notice:null}),n=0,{client:a}=e;async function h(s,l=C(s)===C(t.snapshot().query)&&t.snapshot().notice===S?S:null){let r=++n;t.set({query:s,items:[],next:null,selected:null,etag:null,organization:[],permissions:[],loading:!0,listError:!1,busy:!1,stale:!1,notice:l});let f=a.request("get","/_pb/me/permissions"),[p,x,b,I]=await Promise.all([f.then(y=>B(a,s,y.ok&&y.data.organization.includes("org:projects:archive")&&y.data.organization.includes("project:read"))),f,s.project===null?null:a.request("get","/_pb/projects/{project}",{params:{project:s.project}}),s.project===null?null:a.request("get","/_pb/projects/{project}/permissions",{params:{project:s.project}})]);if(r!==n)return;let m=p,d=b,k=I;if(d&&!d.ok&&d.status===404){let y,c=new Set;for(;;){let v={project:null,status:"archived",after:y},g=await B(a,v);if(r!==n)return;if(!g.ok)break;if(g.data.items.some(H=>H.slug===s.project&&H.status==="archived")){s=v,m=g,d=null,k=null,l=S;break}let w=g.data.next;if(!w||c.has(w))break;c.add(w),y=w}}l===S&&(s={...s,project:null},d=null,k=null,!m.ok&&(s={...s,status:"active",after:void 0},m=await B(a,s),r!==n))||t.set({query:s,loading:!1,listError:!m.ok,items:m.ok?m.data.items:[],next:m.ok?m.data.next:null,organization:x.ok?x.data.organization:[],selected:d?.ok?d.data:null,etag:d?.ok?d.headers?.etag??null:null,permissions:k?.ok?k.data.project:[],notice:m.ok?d&&!d.ok?P(d):l:P(m)})}async function u(s,l,r="Project updated.",f="Changed elsewhere. Reload before trying again."){let p=t.snapshot();if(p.busy||p.loading||p.stale)return;let x=n;t.set({busy:!0,notice:null});let b=await s();if(b.ok&&e.onProjectsChanged?.(),x===n)return t.set({busy:!1}),X(e,b)?t.set({stale:!0,notice:"Complete reauthentication and confirm the pending action."}):b.ok?await h(l?{...p.query,project:l}:p.query,l?S:r):t.set({stale:b.status===412,notice:b.status===412?f:P(b)}),b}return{snapshot:t.snapshot,subscribe:t.subscribe,load:h,async create(s){if(R(t.snapshot()).create)return u(()=>a.request("post","/_pb/projects",{body:s,idempotencyKey:crypto.randomUUID()}),void 0,"Project created.")},async update(s){let l=t.snapshot();if(R(l).settings)return u(()=>a.request("patch","/_pb/projects/{project}",{params:{project:l.selected.slug},headers:{"If-Match":l.etag},body:s}),void 0,"Access policy saved. Existing tokens now use this limit.","This project changed while you were editing. Reload the latest settings before saving.")},async transition(){let s=t.snapshot();R(s).transition&&await u(()=>a.request("post",s.selected.status==="active"?"/_pb/projects/{project}/archive":"/_pb/projects/{project}/restore",{params:{project:s.selected.slug},headers:{"If-Match":s.etag},idempotencyKey:crypto.randomUUID()}),s.selected.status==="active"?s.selected.slug:void 0)},async transitionItem(s){let l=t.snapshot(),r=l.items.find(f=>f.id===s);!r?.etag||!R(l).transitionItems||await u(()=>a.request("post",r.status==="active"?"/_pb/projects/{project}/archive":"/_pb/projects/{project}/restore",{params:{project:r.slug},headers:{"If-Match":r.etag},idempotencyKey:crypto.randomUUID()}),r.status==="active"?r.slug:void 0)},async replayed(s){let l=t.snapshot().query.project,r=l===null?null:`/_pb/projects/${encodeURIComponent(l)}`,f=/^\/_pb\/projects\/[^/]+\/(?:archive|restore)$/.test(s.path);if(!(!f&&s.path!=="/_pb/projects"&&(r===null||![r,`${r}/archive`,`${r}/restore`].includes(s.path))))if(s.ok){let p=f&&s.path.endsWith("/archive")?decodeURIComponent(s.path.split("/")[3]):null;await h(p?{...t.snapshot().query,project:p}:t.snapshot().query,p?S:s.path==="/_pb/projects"?"Project created.":s.path===r?"Access policy saved. Existing tokens now use this limit.":"Project updated.")}else t.set({stale:!0,notice:s.path===r&&s.status===412?"This project changed while you were editing. Reload the latest settings before saving.":P(s)})},dispose(){++n}}}function me({state:e,controller:t}){let n=R(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{role:"status",className:"sr-only",children:e.notice}),(0,i.jsx)(ee,{...e,reload:()=>{t.load(e.query)}}),e.query.q?(0,i.jsx)("p",{children:"Filtering loaded projects on this page."}):null,!e.loading&&!e.listError?n.items.length?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("p",{className:"my-3 text-sm text-neutral-600",children:[n.items.length," projects on this page"]}),(0,i.jsx)(Y,{label:"Projects",items:n.items,selectedId:e.selected?.id??"",columns:[{key:"name",label:"Name",value:a=>a.name,render:a=>(0,i.jsxs)("div",{className:"grid gap-1",children:[(0,i.jsx)("a",{className:"font-medium underline",href:C({...e.query,project:a.slug}),children:a.name}),(0,i.jsx)("code",{className:"text-xs text-neutral-600",children:a.slug})]})},{key:"status",label:"Status",value:a=>a.status,render:a=>(0,i.jsx)(J,{status:a.status})},{key:"id",label:"Project ID",value:a=>a.id,render:a=>(0,i.jsx)(G,{value:a.id,label:"project ID"}),priority:3},{key:"actions",label:"Actions",value:()=>"",sortable:!1,render:a=>(0,i.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,i.jsx)("a",{className:"underline",href:C({...e.query,project:a.slug}),children:"Open settings"}),(0,i.jsx)("a",{className:"underline",href:q("notifications",{project:a.slug}),children:"Notifications"}),n.transitionItems&&a.etag?a.status==="active"?(0,i.jsx)(D,{action:"Archive",target:`${a.name} (${a.id})`,scope:`Project: ${a.slug}`,description:"Archiving keeps project history and blocks new publishes. You can restore this project later.",disabled:e.busy,onConfirm:()=>{t.transitionItem(a.id)}},`${a.id}:${a.etag}`):(0,i.jsx)($,{type:"button",size:"sm",variant:"outline",disabled:e.busy,onClick:()=>{t.transitionItem(a.id)},children:"Restore"}):null]})}]})]}):(0,i.jsx)(V,{kind:e.query.q||e.query.status?"filtered-empty":"empty",title:"No projects found on this page."}):null,e.next?(0,i.jsx)("a",{className:"my-4 inline-block underline",href:C({...e.query,after:e.next}),children:"Next projects"}):null,e.organization.includes("org:projects:create")&&!e.loading?(0,i.jsxs)("details",{className:"detail-group my-6",children:[(0,i.jsx)("summary",{className:"cursor-pointer font-semibold",children:"New project"}),(0,i.jsx)(F,{disabled:!n.create||e.busy,submit:a=>t.create({...a,slug:a.slug??""})})]}):null,e.selected?(0,i.jsxs)("section",{className:"detail-group my-6 grid gap-3","aria-label":"Project settings",children:[(0,i.jsxs)("h2",{className:"text-lg font-semibold",children:["Settings: ",e.selected.name]}),e.permissions.includes("project:settings:write")&&e.selected.status==="active"?(0,i.jsx)(F,{project:e.selected,disabled:!n.settings||e.busy,submit:t.update},`${e.selected.id}-${e.etag}`):e.selected.requirePublishApproval?(0,i.jsx)("p",{className:"text-sm text-neutral-600",children:"Publish approval is saved as required, but approval is not enforced in this version."}):null,n.transition?e.selected.status==="active"?(0,i.jsx)(D,{action:"Archive",target:e.selected.name,scope:`Project: ${e.selected.slug}`,description:"Archiving keeps project history and blocks new publishes. You can restore this project later.",disabled:e.busy,onConfirm:()=>{t.transition()}},`${e.selected.id}:${e.etag}`):(0,i.jsx)($,{type:"button",variant:"outline",disabled:e.busy,onClick:()=>{t.transition()},children:"Restore"}):null]}):null]})}function Re(){let e=W(),t=(0,E.useMemo)(()=>de(e),[e]),n=(0,E.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),a=se(e,t,O,"projects");return(0,E.useEffect)(()=>{if(n.loading||n.notice!==S||n.query.project!==null)return;let h=C(n.query);window.location.hash!==h&&(window.history.replaceState(null,"",h),window.dispatchEvent(new HashChangeEvent("hashchange")))},[n.loading,n.notice,n.query]),(0,i.jsxs)("section",{"aria-labelledby":"page-heading",children:[(0,i.jsx)("h1",{tabIndex:-1,id:"page-heading",className:"text-xl font-semibold",children:"Projects"}),(0,i.jsx)("p",{className:"mt-1 text-neutral-600",children:"Scopes for sources, packages and tokens. Archiving keeps history and blocks new publishes."}),(0,i.jsx)(te,{route:"projects",query:O(a),statuses:_},a),(0,i.jsx)(me,{state:n,controller:t})]})}export{Re as ProjectsPage,me as ProjectsView,C as buildProjectsHash,de as createProjectsController,O as parseProjectsHash,R as projectsViewModel};
1
+ import{a as K,b as Z,c as P,d as X,h as ee,i as te,j as se}from"./chunk.4acf8fa7653f.js";import"./chunk.53134c7df4e5.js";import{b as J}from"./chunk.f0fd799728ef.js";import{a as D}from"./chunk.304a2b5d1663.js";import{a as Y,c as V}from"./chunk.56e058d97e0f.js";import"./chunk.75e1357175af.js";import"./chunk.3f077ff17cea.js";import{D as G,E as L,F as T,K as W,c as N,d as Q,g as M,j as q,p as $}from"./chunk.837eb41f53ef.js";var E=N(Q(),1);var j=N(Q(),1);var U=/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/,A="1\u201364 lowercase letters, numbers or hyphens. Start and end with a letter or number.";function z(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64).replace(/-+$/g,"")}function ae(e,t){return{...e,name:t,slug:e.manualSlug?e.slug:z(t)}}function oe(e,t){return{...e,slug:t,manualSlug:!0}}function ne(e){return{...e,slug:z(e.name),manualSlug:!1}}function re(e,t=!1){let n={};return e.name.trim()?[...e.name].length>100?n.name="Use 100 characters or fewer.":/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/u.test(e.name)&&(n.name="Use a name without control or formatting characters."):n.name="Enter a project name.",!t&&!U.test(e.slug)&&(n.slug=!e.slug&&e.name&&!z(e.name)?"Enter a project slug using lowercase letters, numbers or hyphens.":A),n}function ie(e,t){return{name:e.name,tokenMaxScope:e.tokenMaxScope,...t?{}:{slug:e.slug}}}function le(e,t){if(e.ok)return{};if(!t&&e.code==="duplicate")return{slug:"This project slug is already in use. Choose another."};let n={};for(let a of e.details)a.location&&a.location!=="body"||(a.path==="/body/name"&&(n.name="Check the entered values and try again."),!t&&a.path==="/body/slug"&&(n.slug=A),a.path==="/body/tokenMaxScope"&&(n.tokenMaxScope="Check the entered values and try again."));return n}var pe="This change limits existing personal and service tokens on their next request. Downloads can continue, but access above this limit will stop. Check any CI jobs that use these tokens.";function ce(e,t){let n=["read","write","full"];return e===t?null:n.indexOf(t)<n.indexOf(e)?pe:"Existing tokens may regain access if their scope and permissions allow it."}var o=N(M(),1),ue=[{value:"read",label:"Install and download",summary:"Install and download only",description:"Read project details and download packages."},{value:"write",label:"Include publish permission",summary:"Publish permission included",description:"Also allow the package publishing permission. Publish npm packages to an enabled hosted source that claims the package name."},{value:"full",label:"Include grants, sources and audit access",summary:"Grants, sources and audit access included",description:"Also allow reading project grants, sources and audit records, plus the publish permission."}];function F(e){let t=(0,j.useId)(),n=(0,j.useRef)(null),a=(0,j.useRef)(null),h=(0,j.useRef)(null),u=!!e.project,[s,l]=(0,j.useState)({name:e.project?.name??"",slug:e.project?.slug??"",tokenMaxScope:e.project?.tokenMaxScope??"read",manualSlug:!1}),[r,f]=(0,j.useState)({}),[p,x]=(0,j.useState)(!1),[b,I]=(0,j.useState)(""),m=c=>{f(c);let v=["name","slug","tokenMaxScope"].find(g=>c[g]);v==="tokenMaxScope"&&a.current&&(a.current.open=!0),v&&n.current?.querySelector(`[name="${v}"]`)?.focus()},d=U.test(s.slug)?s.slug:"{project-slug}",k=typeof window>"u"?"":window.location.origin,y=e.project?ce(e.project.tokenMaxScope,s.tokenMaxScope):null;return(0,o.jsxs)("form",{ref:n,noValidate:!0,"aria-label":u?"Project settings":"New project",className:"my-6 grid min-w-0 max-w-5xl items-start gap-x-6 gap-y-4 lg:grid-cols-2",onSubmit:async c=>{if(c.preventDefault(),e.disabled||p)return;I("");let v=re(s,u);if(m(v),!Object.keys(v).length){x(!0);try{let g=await e.submit(ie(s,u));if(g&&!g.ok){let w=le(g,u);m(w),Object.keys(w).length||h.current?.focus(),I(g.status===412?"This project changed while you were editing. Reload the latest settings before saving.":P(g))}else g?.ok&&I(u?"Access policy saved. Existing tokens now use this limit.":"Project created.")}finally{x(!1)}}},children:[(0,o.jsxs)("div",{className:"grid min-w-0 gap-1",children:[(0,o.jsx)(T,{htmlFor:`${t}-name`,children:"Project name"}),(0,o.jsx)(L,{id:`${t}-name`,name:"name",required:!0,className:"h-11",placeholder:"e.g. Acme Company",value:s.name,onChange:c=>l(ae(s,c.target.value)),"aria-describedby":`${t}-name-help ${t}-name-error`,"aria-invalid":!!r.name}),(0,o.jsx)("p",{id:`${t}-name-help`,className:"text-sm text-neutral-600",children:"A name your team will recognize. You can change it later."}),(0,o.jsx)("p",{id:`${t}-name-error`,className:"text-sm text-red-700",children:r.name})]}),(0,o.jsxs)("div",{className:"grid min-w-0 gap-1",children:[u?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{className:"text-sm font-medium",children:"Project slug"}),(0,o.jsx)("p",{className:"break-all",children:s.slug})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(T,{htmlFor:`${t}-slug`,children:"Project slug"}),(0,o.jsx)(L,{id:`${t}-slug`,name:"slug",required:!0,className:"h-11",placeholder:"e.g. acme-company",value:s.slug,onChange:c=>l(oe(s,c.target.value)),"aria-describedby":`${t}-slug-help ${t}-slug-rule ${t}-slug-error`,"aria-invalid":!!r.slug}),s.manualSlug?(0,o.jsx)($,{type:"button",variant:"ghost",className:"min-h-11 justify-self-start",onClick:()=>l(ne(s)),children:"Use suggested slug"}):null]}),(0,o.jsx)("p",{id:`${t}-slug-help`,className:"text-sm text-neutral-600",children:"Used in repository URLs and CLI commands. You cannot change it later."}),u?null:(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("p",{id:`${t}-slug-rule`,className:"text-sm text-neutral-600",children:A}),(0,o.jsx)("p",{id:`${t}-slug-error`,className:"text-sm text-red-700",children:r.slug})]})]}),(0,o.jsxs)("div",{className:"grid min-w-0 gap-2 rounded-md border border-neutral-300 bg-neutral-50 p-4 lg:col-span-2",children:[(0,o.jsx)("p",{className:"text-sm font-medium",children:"Repository URLs"}),(0,o.jsxs)("dl",{className:"grid min-w-0 gap-2 text-sm",children:[(0,o.jsxs)("div",{className:"min-w-0",children:[(0,o.jsx)("dt",{children:"Composer"}),(0,o.jsx)("dd",{className:"overflow-x-auto whitespace-nowrap",tabIndex:0,children:(0,o.jsx)("code",{children:`${k}/${d}`})})]}),(0,o.jsxs)("div",{className:"min-w-0",children:[(0,o.jsx)("dt",{children:"npm"}),(0,o.jsx)("dd",{className:"overflow-x-auto whitespace-nowrap",tabIndex:0,children:(0,o.jsx)("code",{children:`${k}/${d}/npm/`})})]})]})]}),(0,o.jsxs)("details",{ref:a,className:"min-w-0 rounded-md border border-neutral-300 lg:col-span-2",children:[(0,o.jsxs)("summary",{className:"min-h-11 cursor-pointer p-4 font-medium focus-visible:ring-2 focus-visible:ring-blue-600",children:["Access policy",(0,o.jsx)("span",{className:"block text-sm font-normal text-neutral-600",children:ue.find(c=>c.value===s.tokenMaxScope)?.summary})]}),(0,o.jsxs)("fieldset",{className:"m-4 grid min-w-0 gap-3","aria-describedby":`${t}-policy-help ${t}-policy-note ${t}-policy-error`,children:[(0,o.jsx)("legend",{className:"font-medium",children:"What can tokens do on this project?"}),(0,o.jsx)("p",{id:`${t}-policy-help`,className:"text-sm text-neutral-600",children:"Sets the maximum access for personal and service tokens, including tokens used by CI. Each token still needs its own permissions. Your access in the admin UI is unchanged."}),ue.map(c=>(0,o.jsxs)(T,{htmlFor:`${t}-${c.value}`,className:"flex min-h-11 cursor-pointer items-start gap-3 rounded-md border border-neutral-300 p-3 has-checked:border-blue-700 has-checked:bg-blue-50",children:[(0,o.jsx)("input",{id:`${t}-${c.value}`,type:"radio",name:"tokenMaxScope",value:c.value,checked:s.tokenMaxScope===c.value,onChange:()=>l({...s,tokenMaxScope:c.value}),className:"mt-1 accent-blue-700 focus-visible:ring-2 focus-visible:ring-blue-600","aria-describedby":`${t}-${c.value}-description ${t}-policy-error`,"aria-invalid":!!r.tokenMaxScope}),(0,o.jsxs)("span",{children:[c.label,c.value==="read"?(0,o.jsx)("span",{className:"ml-2 inline-block rounded bg-blue-100 px-1 text-xs text-blue-800",children:"Recommended"}):null,(0,o.jsx)("span",{id:`${t}-${c.value}-description`,className:"mt-1 block text-sm font-normal text-neutral-600",children:c.description})]})]},c.value)),(0,o.jsx)("p",{id:`${t}-policy-note`,className:"text-sm text-neutral-600",children:"Tokens cannot change project settings or delete packages. Publishing is not available in this version."}),(0,o.jsx)("p",{id:`${t}-policy-error`,className:"text-sm text-red-700",children:r.tokenMaxScope})]})]}),e.project?.requirePublishApproval?(0,o.jsx)("p",{className:"text-sm text-neutral-600 lg:col-span-2",children:"Publish approval is saved as required, but approval is not enforced in this version."}):null,y?(0,o.jsx)("p",{className:"text-sm text-neutral-600 lg:col-span-2",children:y}):null,(0,o.jsx)("div",{className:"lg:col-span-2",children:(0,o.jsx)($,{type:"submit",className:"min-h-11 w-full sm:w-auto lg:w-auto",disabled:e.disabled||p,children:p?u?"Saving settings\u2026":"Creating project\u2026":u?"Save settings":(0,o.jsx)(o.Fragment,{children:"Create project"})})}),(0,o.jsx)("p",{ref:h,role:"status",tabIndex:-1,className:"lg:col-span-2",children:p?u?"Saving settings\u2026":"Creating project\u2026":b||(Object.keys(r).length?"Check the entered values and try again.":"")})]})}var i=N(M(),1),S="Project archived.",_=["active","archived"],O=e=>K(e,_),C=e=>q("projects",O(q("projects",e)));async function B(e,t,n=!0){if(t.status)return e.request("get","/_pb/projects",{query:{status:t.status,after:t.after,limit:"50"}});let a=[t.after,void 0];if(t.after?.startsWith("all:"))try{let l=JSON.parse(t.after.slice(4));if(!Array.isArray(l)||l.length!==2||!l.every(r=>r===null||typeof r=="string"))throw new Error("Invalid cursor");a=l}catch{return{ok:!1,status:400,code:"invalid_request",details:[],request:{method:"GET",path:"/_pb/projects"}}}if(!n&&a[0]===null)return{ok:!0,status:200,data:{items:[],next:null}};if(!n)return e.request("get","/_pb/projects",{query:{status:"active",after:a[0]??void 0,limit:"50"}});let h=await Promise.all(_.map((l,r)=>a[r]===null?null:e.request("get","/_pb/projects",{query:{status:l,after:a[r]??void 0,limit:"50"}}))),u=[],s=[];for(let[l,r]of h.entries()){if(r&&!r.ok){if(_[l]==="archived"&&r.status===403){s.push(null);continue}return r}r?.ok&&u.push(...r.data.items),s.push(r?.ok?r.data.next:null)}return{ok:!0,status:200,data:{items:u,next:s.some(l=>l!==null)?`all:${JSON.stringify(s)}`:null}}}function R(e){let t=e.selected,n=!!t&&!!e.etag&&!e.loading&&!e.stale;return{items:e.items.filter(a=>!e.query.q||a.name.toLowerCase().startsWith(e.query.q.toLowerCase())),create:e.organization.includes("org:projects:create")&&!e.stale&&!e.loading,settings:n&&t.status==="active"&&e.permissions.includes("project:settings:write"),transition:n&&e.organization.includes("org:projects:archive"),transitionItems:!e.loading&&!e.stale&&e.organization.includes("org:projects:archive")}}function de(e){let t=Z({query:{project:null},items:[],next:null,selected:null,etag:null,organization:[],permissions:[],loading:!1,listError:!1,busy:!1,stale:!1,notice:null}),n=0,{client:a}=e;async function h(s,l=C(s)===C(t.snapshot().query)&&t.snapshot().notice===S?S:null){let r=++n;t.set({query:s,items:[],next:null,selected:null,etag:null,organization:[],permissions:[],loading:!0,listError:!1,busy:!1,stale:!1,notice:l});let f=a.request("get","/_pb/me/permissions"),[p,x,b,I]=await Promise.all([f.then(y=>B(a,s,y.ok&&y.data.organization.includes("org:projects:archive")&&y.data.organization.includes("project:read"))),f,s.project===null?null:a.request("get","/_pb/projects/{project}",{params:{project:s.project}}),s.project===null?null:a.request("get","/_pb/projects/{project}/permissions",{params:{project:s.project}})]);if(r!==n)return;let m=p,d=b,k=I;if(d&&!d.ok&&d.status===404){let y,c=new Set;for(;;){let v={project:null,status:"archived",after:y},g=await B(a,v);if(r!==n)return;if(!g.ok)break;if(g.data.items.some(H=>H.slug===s.project&&H.status==="archived")){s=v,m=g,d=null,k=null,l=S;break}let w=g.data.next;if(!w||c.has(w))break;c.add(w),y=w}}l===S&&(s={...s,project:null},d=null,k=null,!m.ok&&(s={...s,status:"active",after:void 0},m=await B(a,s),r!==n))||t.set({query:s,loading:!1,listError:!m.ok,items:m.ok?m.data.items:[],next:m.ok?m.data.next:null,organization:x.ok?x.data.organization:[],selected:d?.ok?d.data:null,etag:d?.ok?d.headers?.etag??null:null,permissions:k?.ok?k.data.project:[],notice:m.ok?d&&!d.ok?P(d):l:P(m)})}async function u(s,l,r="Project updated.",f="Changed elsewhere. Reload before trying again."){let p=t.snapshot();if(p.busy||p.loading||p.stale)return;let x=n;t.set({busy:!0,notice:null});let b=await s();if(b.ok&&e.onProjectsChanged?.(),x===n)return t.set({busy:!1}),X(e,b)?t.set({stale:!0,notice:"Complete reauthentication and confirm the pending action."}):b.ok?await h(l?{...p.query,project:l}:p.query,l?S:r):t.set({stale:b.status===412,notice:b.status===412?f:P(b)}),b}return{snapshot:t.snapshot,subscribe:t.subscribe,load:h,async create(s){if(R(t.snapshot()).create)return u(()=>a.request("post","/_pb/projects",{body:s,idempotencyKey:crypto.randomUUID()}),void 0,"Project created.")},async update(s){let l=t.snapshot();if(R(l).settings)return u(()=>a.request("patch","/_pb/projects/{project}",{params:{project:l.selected.slug},headers:{"If-Match":l.etag},body:s}),void 0,"Access policy saved. Existing tokens now use this limit.","This project changed while you were editing. Reload the latest settings before saving.")},async transition(){let s=t.snapshot();R(s).transition&&await u(()=>a.request("post",s.selected.status==="active"?"/_pb/projects/{project}/archive":"/_pb/projects/{project}/restore",{params:{project:s.selected.slug},headers:{"If-Match":s.etag},idempotencyKey:crypto.randomUUID()}),s.selected.status==="active"?s.selected.slug:void 0)},async transitionItem(s){let l=t.snapshot(),r=l.items.find(f=>f.id===s);!r?.etag||!R(l).transitionItems||await u(()=>a.request("post",r.status==="active"?"/_pb/projects/{project}/archive":"/_pb/projects/{project}/restore",{params:{project:r.slug},headers:{"If-Match":r.etag},idempotencyKey:crypto.randomUUID()}),r.status==="active"?r.slug:void 0)},async replayed(s){let l=t.snapshot().query.project,r=l===null?null:`/_pb/projects/${encodeURIComponent(l)}`,f=/^\/_pb\/projects\/[^/]+\/(?:archive|restore)$/.test(s.path);if(!(!f&&s.path!=="/_pb/projects"&&(r===null||![r,`${r}/archive`,`${r}/restore`].includes(s.path))))if(s.ok){let p=f&&s.path.endsWith("/archive")?decodeURIComponent(s.path.split("/")[3]):null;await h(p?{...t.snapshot().query,project:p}:t.snapshot().query,p?S:s.path==="/_pb/projects"?"Project created.":s.path===r?"Access policy saved. Existing tokens now use this limit.":"Project updated.")}else t.set({stale:!0,notice:s.path===r&&s.status===412?"This project changed while you were editing. Reload the latest settings before saving.":P(s)})},dispose(){++n}}}function me({state:e,controller:t}){let n=R(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{role:"status",className:"sr-only",children:e.notice}),(0,i.jsx)(ee,{...e,reload:()=>{t.load(e.query)}}),e.query.q?(0,i.jsx)("p",{children:"Filtering loaded projects on this page."}):null,!e.loading&&!e.listError?n.items.length?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("p",{className:"my-3 text-sm text-neutral-600",children:[n.items.length," projects on this page"]}),(0,i.jsx)(Y,{label:"Projects",items:n.items,selectedId:e.selected?.id??"",columns:[{key:"name",label:"Name",value:a=>a.name,render:a=>(0,i.jsxs)("div",{className:"grid gap-1",children:[(0,i.jsx)("a",{className:"font-medium underline",href:C({...e.query,project:a.slug}),children:a.name}),(0,i.jsx)("code",{className:"text-xs text-neutral-600",children:a.slug})]})},{key:"status",label:"Status",value:a=>a.status,render:a=>(0,i.jsx)(J,{status:a.status})},{key:"id",label:"Project ID",value:a=>a.id,render:a=>(0,i.jsx)(G,{value:a.id,label:"project ID"}),priority:3},{key:"actions",label:"Actions",value:()=>"",sortable:!1,render:a=>(0,i.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,i.jsx)("a",{className:"underline",href:C({...e.query,project:a.slug}),children:"Open settings"}),(0,i.jsx)("a",{className:"underline",href:q("notifications",{project:a.slug}),children:"Notifications"}),n.transitionItems&&a.etag?a.status==="active"?(0,i.jsx)(D,{action:"Archive",target:`${a.name} (${a.id})`,scope:`Project: ${a.slug}`,description:"Archiving keeps project history and blocks new publishes. You can restore this project later.",disabled:e.busy,onConfirm:()=>{t.transitionItem(a.id)}},`${a.id}:${a.etag}`):(0,i.jsx)($,{type:"button",size:"sm",variant:"outline",disabled:e.busy,onClick:()=>{t.transitionItem(a.id)},children:"Restore"}):null]})}]})]}):(0,i.jsx)(V,{kind:e.query.q||e.query.status?"filtered-empty":"empty",title:"No projects found on this page."}):null,e.next?(0,i.jsx)("a",{className:"my-4 inline-block underline",href:C({...e.query,after:e.next}),children:"Next projects"}):null,e.organization.includes("org:projects:create")&&!e.loading?(0,i.jsxs)("details",{className:"detail-group my-6",children:[(0,i.jsx)("summary",{className:"cursor-pointer font-semibold",children:"New project"}),(0,i.jsx)(F,{disabled:!n.create||e.busy,submit:a=>t.create({...a,slug:a.slug??""})})]}):null,e.selected?(0,i.jsxs)("section",{className:"detail-group my-6 grid gap-3","aria-label":"Project settings",children:[(0,i.jsxs)("h2",{className:"text-lg font-semibold",children:["Settings: ",e.selected.name]}),e.permissions.includes("project:settings:write")&&e.selected.status==="active"?(0,i.jsx)(F,{project:e.selected,disabled:!n.settings||e.busy,submit:t.update},`${e.selected.id}-${e.etag}`):e.selected.requirePublishApproval?(0,i.jsx)("p",{className:"text-sm text-neutral-600",children:"Publish approval is saved as required, but approval is not enforced in this version."}):null,n.transition?e.selected.status==="active"?(0,i.jsx)(D,{action:"Archive",target:e.selected.name,scope:`Project: ${e.selected.slug}`,description:"Archiving keeps project history and blocks new publishes. You can restore this project later.",disabled:e.busy,onConfirm:()=>{t.transition()}},`${e.selected.id}:${e.etag}`):(0,i.jsx)($,{type:"button",variant:"outline",disabled:e.busy,onClick:()=>{t.transition()},children:"Restore"}):null]}):null]})}function Re(){let e=W(),t=(0,E.useMemo)(()=>de(e),[e]),n=(0,E.useSyncExternalStore)(t.subscribe,t.snapshot,t.snapshot),a=se(e,t,O,"projects");return(0,E.useEffect)(()=>{if(n.loading||n.notice!==S||n.query.project!==null)return;let h=C(n.query);window.location.hash!==h&&(window.history.replaceState(null,"",h),window.dispatchEvent(new HashChangeEvent("hashchange")))},[n.loading,n.notice,n.query]),(0,i.jsxs)("section",{"aria-labelledby":"page-heading",children:[(0,i.jsx)("h1",{tabIndex:-1,id:"page-heading",className:"text-xl font-semibold",children:"Projects"}),(0,i.jsx)("p",{className:"mt-1 text-neutral-600",children:"Scopes for sources, packages and tokens. Archiving keeps history and blocks new publishes."}),(0,i.jsx)(te,{route:"projects",query:O(a),statuses:_},a),(0,i.jsx)(me,{state:n,controller:t})]})}export{Re as ProjectsPage,me as ProjectsView,C as buildProjectsHash,de as createProjectsController,O as parseProjectsHash,R as projectsViewModel};