@redocly/framework-plugin-apigee 0.1.0-next.0 → 0.1.0-next.2

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.
@@ -1,21 +1,20 @@
1
- var W=function(n,v,h,p){function k(a){return a instanceof h?a:new h(function(u){u(a)})}return new(h||(h=Promise))(function(a,u){function l(i){try{o(p.next(i))}catch(g){u(g)}}function d(i){try{o(p.throw(i))}catch(g){u(g)}}function o(i){i.done?a(i.value):k(i.value).then(l,d)}o((p=p.apply(n,v||[])).next())})};import{Fragment as E,jsx as e,jsxs as r}from"react/jsx-runtime";import{useState as $}from"react";import z from"styled-components";import{Button as L}from"@redocly/theme/components/Button/Button";import{Dropdown as F}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as H}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as w}from"@redocly/theme/components/Tag/Tag";import{CDNIcon as I}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as A}from"../api.js";import{useApigee as O}from"../context.js";import{formatDateTime as N,useAsync as D}from"../hooks.js";import{EmptyState as R,Loading as j,Mono as V,Muted as s,Notice as C,PageHeader as G,Row as J,Stat as y,Stats as Q,StatusTag as U,Table as _,TableWrap as q}from"../Primitives.js";import{ConfirmDialog as X}from"./Dialogs.js";const Y=z.div`
2
- display: flex;
3
- gap: var(--spacing-xxs);
1
+ var W=function(c,s,u,m){function b(v){return v instanceof u?v:new u(function(h){h(v)})}return new(u||(u=Promise))(function(v,h){function P(a){try{r(m.next(a))}catch(n){h(n)}}function p(a){try{r(m.throw(a))}catch(n){h(n)}}function r(a){a.done?v(a.value):b(a.value).then(P,p)}r((m=m.apply(c,s||[])).next())})};import{Fragment as E,jsx as e,jsxs as i}from"react/jsx-runtime";import{useState as B}from"react";import A from"styled-components";import{Button as _}from"@redocly/theme/components/Button/Button";import{Segmented as F}from"@redocly/theme/components/Segmented/Segmented";import{Tag as y}from"@redocly/theme/components/Tag/Tag";import{breakpoints as H}from"@redocly/theme/core/utils/media-css";import{CDNIcon as V}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as k}from"../api.js";import{useApigee as G}from"../context.js";import{formatDateTime as C,useAsync as j}from"../hooks.js";import{EmptyState as q,Loading as D,Mono as J,Muted as o,Notice as S,PageHeader as Q,Row as K,Stat as x,Stats as U,StatusTag as X,Table as I,TableWrap as z}from"../Primitives.js";import{ConfirmDialog as Y}from"./Dialogs.js";const Z=A.div`
4
2
  margin-bottom: var(--spacing-base);
5
- `,P=z.button`
6
- border: none;
7
- background: ${({$active:n})=>n?"var(--layer-color-active)":"transparent"};
8
- color: ${({$active:n})=>n?"var(--text-color-primary)":"var(--text-color-secondary)"};
9
- font: inherit;
10
- padding: var(--spacing-xxs) var(--spacing-sm);
11
- border-radius: var(--border-radius-md);
12
- cursor: pointer;
3
+ `,ee=A.span`
13
4
  display: inline-flex;
14
5
  align-items: center;
15
6
  gap: var(--spacing-xs);
7
+ `,te=A(o)`
8
+ display: inline-block;
9
+ max-width: 200px;
10
+ white-space: normal;
11
+ text-align: left;
12
+ `,ne=A(K)`
13
+ flex-wrap: nowrap;
16
14
 
17
- &:hover {
18
- background: var(--layer-color-hover);
19
- color: var(--text-color-primary);
15
+ @media (max-width: ${H.small}) {
16
+ > button {
17
+ flex: 1;
18
+ }
20
19
  }
21
- `;function x(n){return n.kind==="developer"?{title:n.email,subtitle:"Personal"}:{title:n.teamId,subtitle:"Team"}}function pe(){var n,v,h,p;const{meta:k}=O(),[a,u]=$("pending"),l=D(()=>A.adminRequests(),"admin-requests"),d=D(()=>A.adminApps(),"admin-apps"),o=D(()=>A.adminAudit(),"admin-audit"),[i,g]=$(null),S=()=>{l.reload(),d.reload(),o.reload()},b=(n=l.data)!==null&&n!==void 0?n:[],f=(v=d.data)!==null&&v!==void 0?v:[],B=f.reduce((t,c)=>t+c.credentials.filter(T=>T.status==="approved").length,0),M=new Set(f.filter(t=>t.owner.kind==="developer").map(t=>t.owner.kind==="developer"&&t.owner.email)).size,K=new Set(f.filter(t=>t.owner.kind==="team").map(t=>t.owner.kind==="team"&&t.owner.teamId)).size;return r("div",{"data-testid":"apigee-admin",children:[e(G,{title:"Approvals",description:r(E,{children:["Access requests for API products that require manual approval in Apigee organization"," ",e("strong",{children:k.organizationName}),"."]}),actions:e(L,{variant:"outlined",onClick:S,icon:e(I,{name:"arrows-rotate",size:"16px"}),children:"Refresh"})}),r(Q,{children:[r(y,{children:[e("strong",{"data-testid":"apigee-stat-pending",children:l.data?b.length:"\u2026"}),e(s,{children:"Pending requests"})]}),r(y,{children:[e("strong",{children:d.data?B:"\u2026"}),e(s,{children:"Approved keys"})]}),r(y,{children:[e("strong",{children:d.data?M:"\u2026"}),e(s,{children:"Developers with apps"})]}),r(y,{children:[e("strong",{children:d.data?K:"\u2026"}),e(s,{children:"Teams with apps"})]})]}),r(Y,{role:"tablist",children:[r(P,{$active:a==="pending",onClick:()=>u("pending"),role:"tab","data-testid":"apigee-admin-tab-pending",children:["Pending ",b.length>0?e(w,{color:"orange",children:b.length}):null]}),e(P,{$active:a==="apps",onClick:()=>u("apps"),role:"tab","data-testid":"apigee-admin-tab-apps",children:"All apps"}),e(P,{$active:a==="audit",onClick:()=>u("audit"),role:"tab","data-testid":"apigee-admin-tab-audit",children:"Audit log"})]}),a==="pending"?l.loading&&!l.data?e(j,{children:"Loading requests\u2026"}):l.error?e(C,{tone:"danger",children:l.error}):b.length===0?e(R,{icon:"circle-check",title:"Nothing to review",text:"Every request for a manually approved product has been handled."}):e(q,{children:r(_,{"data-testid":"apigee-requests-table",children:[e("thead",{children:r("tr",{children:[e("th",{children:"Requested by"}),e("th",{children:"App"}),e("th",{children:"API product"}),e("th",{children:"Reason"}),e("th",{children:"Requested"}),e("th",{className:"actions"})]})}),e("tbody",{children:b.map(t=>{const c=x(t.owner);return r("tr",{"data-testid":"apigee-request-row",children:[r("td",{children:[c.title,e("br",{}),r(s,{children:[c.subtitle,t.requestedBy&&t.requestedBy!==c.title?` \xB7 requested by ${t.requestedBy}`:""]})]}),r("td",{children:[t.appName,e("br",{}),e(V,{children:e(s,{children:t.consumerKey})})]}),e("td",{children:e(w,{color:"orange",children:t.apiProduct})}),e("td",{children:t.note?t.note:e(s,{children:"No reason given"})}),e("td",{children:N(t.requestedAt)}),e("td",{className:"actions",children:e(F,{trigger:e(L,{variant:"text",size:"small","aria-label":"Decide",icon:e(I,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-request-menu"}),alignment:"end",portalled:!0,children:e(H,{items:[{content:"Approve",disabled:!t.canDecide,onAction:()=>g({request:t,action:"approve"}),dataAttributes:{"data-testid":"apigee-approve"}},{content:"Reject",dangerous:!0,separatorLine:!0,disabled:!t.canDecide,onAction:()=>g({request:t,action:"revoke"}),dataAttributes:{"data-testid":"apigee-reject"}}]})})})]},t.id)})})]})}):null,a==="apps"?d.loading&&!d.data?e(j,{children:"Loading apps\u2026"}):d.error?e(C,{tone:"danger",children:d.error}):f.length===0?e(R,{icon:"key",title:"No apps yet",text:"Apps developers register appear here."}):e(q,{children:r(_,{"data-testid":"apigee-admin-apps-table",children:[e("thead",{children:r("tr",{children:[e("th",{children:"App"}),e("th",{children:"Owner"}),e("th",{children:"Keys"}),e("th",{children:"API products"}),e("th",{children:"Created"})]})}),e("tbody",{children:f.map(t=>{const c=x(t.owner),T=[...new Map(t.credentials.flatMap(m=>m.apiProducts).map(m=>[m.id,m])).values()];return r("tr",{children:[r("td",{children:[t.name,t.status==="revoked"?e(w,{color:"red",children:"Revoked"}):null]}),r("td",{children:[c.title,e("br",{}),e(s,{children:c.subtitle})]}),e("td",{children:t.credentials.length}),e("td",{children:e(J,{children:T.map(m=>e(U,{status:m.status,label:m.id},m.id))})}),e("td",{children:N(t.createdAt)})]},`${c.title}:${t.id}`)})})]})}):null,a==="audit"?o.loading&&!o.data?e(j,{children:"Loading the audit log\u2026"}):o.error?e(C,{tone:"danger",children:o.error}):((h=o.data)!==null&&h!==void 0?h:[]).length===0?e(R,{icon:"file-lines",title:"No decisions yet",text:"Approvals and rejections made here are recorded with who made them."}):e(q,{children:r(_,{"data-testid":"apigee-audit-table",children:[e("thead",{children:r("tr",{children:[e("th",{children:"When"}),e("th",{children:"Reviewer"}),e("th",{children:"Action"}),e("th",{children:"Target"})]})}),e("tbody",{children:((p=o.data)!==null&&p!==void 0?p:[]).map(t=>r("tr",{children:[e("td",{children:N(t.at)}),e("td",{children:t.actor}),e("td",{children:e(w,{color:t.action==="approve"?"green":"red",children:t.action==="approve"?"Approved":"Rejected"})}),r("td",{children:[t.apiProduct," \xB7 ",t.appName," (",x(t.owner).title,")",t.note?r(s,{children:[" \u2014 \u201C",t.note,"\u201D"]}):null]})]},t.id))})]})}):null,e(X,{open:i!==null,onClose:()=>g(null),title:i?.action==="approve"?"Approve access?":"Reject request?",confirmLabel:i?.action==="approve"?"Approve":"Reject",danger:i?.action==="revoke",withNote:!0,noteLabel:"Comment for the developer",notePlaceholder:i?.action==="approve"?"Anything the developer should know before they start":"Why the request is rejected and what would change the decision",onConfirm:t=>W(this,void 0,void 0,function*(){return i&&(yield A.adminDecide(i.request.id,i.action,t),S()),!0}),children:i?r("p",{children:[e("strong",{children:i.request.apiProduct})," for"," ",e("strong",{children:i.request.appName})," (",x(i.request.owner).title,").",i.action==="approve"?" The key starts working for this product right away.":" The product stays revoked on this key until it is approved later."]}):null})]})}export{pe as AdminView};
20
+ `;function N(c,s){return c.kind==="developer"?{title:c.email,subtitle:"Personal"}:{title:s??c.teamId,subtitle:"Team"}}function ge(){var c,s,u,m,b;const{meta:v}=G(),[h,P]=B("pending"),p=j(()=>k.adminRequests(),"admin-requests"),r=j(()=>k.adminApps(),"admin-apps"),a=j(()=>k.adminAudit(),"admin-audit"),[n,R]=B(null),L=()=>{p.reload(),r.reload(),a.reload()},f=(c=p.data)!==null&&c!==void 0?c:[],w=(s=r.data)!==null&&s!==void 0?s:[],M=w.reduce((t,d)=>t+d.credentials.filter(g=>g.status==="approved").length,0),$=new Set(w.filter(t=>t.owner.kind==="developer").map(t=>t.owner.kind==="developer"&&t.owner.email)).size,O=new Set(w.filter(t=>t.owner.kind==="team").map(t=>t.owner.kind==="team"&&t.owner.teamId)).size;return i("div",{"data-testid":"apigee-admin",children:[e(Q,{title:"Approvals",description:i(E,{children:["Access requests for API products that require manual approval in Apigee organization"," ",e("strong",{children:v.organizationName}),"."]}),actions:e(_,{variant:"outlined",onClick:L,icon:e(V,{name:"arrows-rotate",size:"16px"}),children:"Refresh"})}),i(U,{children:[i(x,{children:[e("strong",{"data-testid":"apigee-stat-pending",children:p.data?f.length:"\u2026"}),e(o,{children:"Pending requests"})]}),i(x,{children:[e("strong",{children:r.data?M:"\u2026"}),e(o,{children:"Approved keys"})]}),i(x,{children:[e("strong",{children:r.data?$:"\u2026"}),e(o,{children:"Developers with apps"})]}),i(x,{children:[e("strong",{children:r.data?O:"\u2026"}),e(o,{children:"Teams with apps"})]})]}),e(Z,{children:e(F,{value:h,onChange:t=>P(t.value),options:[{value:"pending",label:"Pending",element:i(ee,{children:["Pending",f.length>0?e(y,{color:"orange",children:f.length}):null]})},{value:"apps",label:"All apps"},{value:"audit",label:"Audit log"}]})}),h==="pending"?p.loading&&!p.data?e(D,{label:"Loading requests\u2026"}):p.error?e(S,{tone:"danger",children:p.error}):f.length===0?e(q,{icon:"circle-check",title:"Nothing to review",text:"Every request for a manually approved product has been handled."}):e(z,{children:i(I,{"data-testid":"apigee-requests-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"Requested by"}),e("th",{children:"App"}),e("th",{children:"API product"}),e("th",{children:"Reason"}),e("th",{children:"Requested"}),e("th",{className:"actions"})]})}),e("tbody",{children:f.map(t=>{var d;const g=N(t.owner,t.teamName),l=(d=t.apiProductName)!==null&&d!==void 0?d:t.apiProduct;return i("tr",{"data-testid":"apigee-request-row",children:[i("td",{children:[g.title,e("br",{}),i(o,{children:[g.subtitle,t.requestedBy&&t.requestedBy!==g.title?` \xB7 requested by ${t.requestedBy}`:""]})]}),i("td",{"data-label":"App",children:[t.appName,e("br",{}),e(J,{children:e(o,{children:t.consumerKey})})]}),e("td",{"data-label":"API product",children:e(y,{color:"orange",children:l})}),e("td",{"data-label":"Reason",children:t.note?t.note:e(o,{children:"No reason given"})}),e("td",{"data-label":"Requested",children:C(t.requestedAt)}),e("td",{className:"actions",children:t.canDecide?i(ne,{children:[e(_,{variant:"primary",size:"small",onClick:()=>R({request:t,action:"approve"}),"data-testid":"apigee-approve",children:"Approve"}),e(_,{variant:"outlined",tone:"danger",size:"small",onClick:()=>R({request:t,action:"revoke"}),"data-testid":"apigee-reject",children:"Reject"})]}):i(te,{"data-testid":"apigee-cannot-decide",children:["Only maintainers of ",l," can decide"]})})]},t.id)})})]})}):null,h==="apps"?r.loading&&!r.data?e(D,{label:"Loading apps\u2026"}):r.error?e(S,{tone:"danger",children:r.error}):w.length===0?e(q,{icon:"key",title:"No apps yet",text:"Apps developers register appear here."}):e(z,{children:i(I,{"data-testid":"apigee-admin-apps-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"App"}),e("th",{children:"Owner"}),e("th",{children:"Keys"}),e("th",{children:"API products"}),e("th",{children:"Created"})]})}),e("tbody",{children:w.map(t=>{const d=N(t.owner,t.teamName),g=[...new Map(t.credentials.flatMap(l=>l.apiProducts).map(l=>[l.id,l])).values()];return i("tr",{children:[i("td",{children:[t.name,t.status==="revoked"?e(y,{color:"red",children:"Revoked"}):null]}),i("td",{"data-label":"Owner",children:[d.title,e("br",{}),e(o,{children:d.subtitle})]}),e("td",{"data-label":"Keys",children:t.credentials.length}),e("td",{"data-label":"API products",children:e(K,{children:g.map(l=>{var T;return e(X,{status:l.status,label:(T=l.name)!==null&&T!==void 0?T:l.id},l.id)})})}),e("td",{"data-label":"Created",children:C(t.createdAt)})]},`${t.owner.kind==="team"?t.owner.teamId:t.owner.email}:${t.id}`)})})]})}):null,h==="audit"?a.loading&&!a.data?e(D,{label:"Loading the audit log\u2026"}):a.error?e(S,{tone:"danger",children:a.error}):((u=a.data)!==null&&u!==void 0?u:[]).length===0?e(q,{icon:"file-lines",title:"No decisions yet",text:"Approvals and rejections made here are recorded with who made them."}):e(z,{children:i(I,{"data-testid":"apigee-audit-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"When"}),e("th",{children:"Reviewer"}),e("th",{children:"Action"}),e("th",{children:"Target"})]})}),e("tbody",{children:((m=a.data)!==null&&m!==void 0?m:[]).map(t=>{var d;return i("tr",{children:[e("td",{children:C(t.at)}),e("td",{"data-label":"Reviewer",children:t.actor}),e("td",{"data-label":"Action",children:e(y,{color:t.action==="approve"?"green":"red",children:t.action==="approve"?"Approved":"Rejected"})}),i("td",{"data-label":"Target",children:[(d=t.apiProductName)!==null&&d!==void 0?d:t.apiProduct," \xB7 ",t.appName," (",N(t.owner,t.teamName).title,")",t.note?i(o,{children:[" \u2014 \u201C",t.note,"\u201D"]}):null]})]},t.id)})})]})}):null,e(Y,{open:n!==null,onClose:()=>R(null),title:n?.action==="approve"?"Approve access?":"Reject request?",confirmLabel:n?.action==="approve"?"Approve":"Reject",danger:n?.action==="revoke",withNote:!0,noteLabel:"Comment for the developer",notePlaceholder:n?.action==="approve"?"Anything the developer should know before they start":"Why the request is rejected and what would change the decision",onConfirm:t=>W(this,void 0,void 0,function*(){return n&&(yield k.adminDecide(n.request.id,n.action,t),L()),!0}),children:n?i("p",{children:[e("strong",{children:(b=n.request.apiProductName)!==null&&b!==void 0?b:n.request.apiProduct})," for"," ",e("strong",{children:n.request.appName})," (",N(n.request.owner,n.request.teamName).title,").",n.action==="approve"?" The key starts working for this product right away.":" The product stays revoked on this key until it is approved later."]}):null})]})}export{ge as AdminView};
@@ -1,5 +1,5 @@
1
1
  import type { ReactElement } from 'react';
2
- import type { ApiProduct, Team } from '../../contract.js';
2
+ import type { ApiProduct, App, Team } from '../../contract.js';
3
3
  export type AppSelection = {
4
4
  appId: string;
5
5
  teamId?: string;
@@ -9,3 +9,7 @@ export declare function AppsView({ selection, teams, products, }: {
9
9
  teams: Team[];
10
10
  products: ApiProduct[];
11
11
  }): ReactElement;
12
+ export declare function AppRow({ app, to }: {
13
+ app: App;
14
+ to: string;
15
+ }): ReactElement;
@@ -1 +1,5 @@
1
- var D=function(t,l,a,s){function w(m){return m instanceof a?m:new a(function(y){y(m)})}return new(a||(a=Promise))(function(m,y){function c(d){try{g(s.next(d))}catch(k){y(k)}}function f(d){try{g(s.throw(d))}catch(k){y(k)}}function g(d){d.done?m(d.value):w(d.value).then(c,f)}g((s=s.apply(t,l||[])).next())})};import{Fragment as T,jsx as e,jsxs as n}from"react/jsx-runtime";import{useEffect as J,useMemo as E,useState as K}from"react";import{useNavigate as Q}from"react-router";import{Button as b}from"@redocly/theme/components/Button/Button";import{Dropdown as M}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as B}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as X}from"@redocly/theme/components/Tag/Tag";import{CDNIcon as A}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as P}from"../api.js";import{useApigee as Y}from"../context.js";import{maskKey as Z}from"../../contract.js";import{copyText as ee,formatDate as $,useAsync as te}from"../hooks.js";import{Dot as ie,EmptyState as L,ListItem as ne,ListTitle as U,Loading as re,Mono as H,Muted as C,Notice as O,Overview as ae,PageHeader as R,Row as j,Section as oe,SectionHeader as de,SectionTitle as le,SplitLayout as se,StatusTag as F,Table as ce,TableWrap as ue}from"../Primitives.js";import{AppDialog as q,ConfirmDialog as V,KeyDialog as pe}from"./Dialogs.js";function me(t,l){var a,s;return t.kind==="developer"?"Personal":`Team \xB7 ${(s=(a=l.find(w=>w.id===t.teamId))===null||a===void 0?void 0:a.name)!==null&&s!==void 0?s:t.teamId}`}function he(t){if(t.status==="revoked")return"red";const l=t.credentials.flatMap(a=>a.apiProducts);return l.some(a=>a.status==="pending")?"orange":l.some(a=>a.status==="approved")?"green":"grey"}function W(t){if(t.status!=="approved")return t.status;const{apiProducts:l}=t;return l.some(a=>a.status==="pending")?"pending":l.length>0&&l.every(a=>a.status==="revoked")?"revoked":"approved"}function _e({selection:t,teams:l,products:a}){var s;const{link:w,title:m}=Y(),y=Q(),c=te(()=>P.listApps(),"apps"),[f,g]=K(null);J(()=>{var r,u;const v=new URLSearchParams(window.location.search);v.has("createApp")&&(g({product:(r=v.get("apiProduct"))!==null&&r!==void 0?r:void 0,teamId:(u=v.get("team"))!==null&&u!==void 0?u:void 0}),y(w(),{replace:!0}))},[w,y]);const d=E(()=>{var r;return!t||!c.data?null:(r=c.data.find(u=>u.id===t.appId&&(t.teamId?u.owner.kind==="team"&&u.owner.teamId===t.teamId:u.owner.kind==="developer")))!==null&&r!==void 0?r:null},[c.data,t]),k=E(()=>{var r;const u=((r=c.data)!==null&&r!==void 0?r:[]).filter(x=>x.owner.kind==="developer"),v=l.map(x=>{var i;return{team:x,apps:((i=c.data)!==null&&i!==void 0?i:[]).filter(p=>p.owner.kind==="team"&&p.owner.teamId===x.id)}});return{personal:u,byTeam:v}},[c.data,l]),I=r=>w(`/${encodeURIComponent(r.id)}`,r.owner.kind==="team"?{team:r.owner.teamId}:void 0),S=r=>D(this,void 0,void 0,function*(){const u=yield P.createApp(r);return c.reload(),y(I(u)),u});if(c.loading&&!c.data)return e(re,{children:"Loading your apps\u2026"});if(c.error)return e(O,{tone:"danger",children:c.error});const z=(s=c.data)!==null&&s!==void 0?s:[],_=e(q,{open:f!==null,onClose:()=>g(null),onSubmit:S,products:a,teams:l,initialProduct:f?.product,initialTeamId:f?.teamId});return z.length===0?n(T,{children:[e(R,{title:m,description:"Register applications and manage the API keys that call the APIs through Apigee."}),e(L,{icon:"key",title:"Create your first app",text:"An app holds the API keys your software sends. Pick the API products it needs; the keys for approved products work right away.",action:e(b,{variant:"primary",onClick:()=>g({}),icon:e(A,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New application"})}),_]}):n(T,{children:[e(R,{title:m,description:"Register applications and manage the API keys that call the APIs through Apigee.",actions:e(b,{variant:"primary",onClick:()=>g({}),icon:e(A,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New application"})}),n(se,{children:[n("aside",{"data-testid":"apigee-app-list",children:[k.personal.length>0?e(U,{children:"Personal"}):null,k.personal.map(r=>e(G,{app:r,to:I(r),active:d===r},`dev:${r.id}`)),k.byTeam.map(({team:r,apps:u})=>u.length>0?n("div",{style:{marginTop:"var(--spacing-base)"},children:[n(U,{children:["Team \xB7 ",r.name]}),u.map(v=>e(G,{app:v,to:I(v),active:d===v},`team:${r.id}:${v.id}`))]},r.id):null)]}),e("div",{children:d?e(ve,{app:d,teams:l,products:a,onChanged:()=>c.reload(),onDeleted:()=>{c.reload(),y(w())}}):e(L,{icon:"arrow-left",title:"Select an app",text:"Choose an app on the left to see its keys, or create a new one."})})]}),_]})}function G({app:t,to:l,active:a}){const s=t.credentials.length;return n(ne,{to:l,$active:a,"data-testid":"apigee-app-row",children:[n("span",{children:[t.name,e("br",{}),n(C,{children:[s," ",s===1?"key":"keys"]})]}),e(ie,{$color:he(t)})]})}function ve({app:t,teams:l,products:a,onChanged:s,onDeleted:w}){const m=t.owner.kind==="team"?t.owner.teamId:void 0,[y,c]=K(!1),[f,g]=K(!1),[d,k]=K(null),[I,S]=K(null),[z,_]=K(new Set),[r,u]=K(null),v=(i,p)=>D(this,void 0,void 0,function*(){(yield ee(i))&&(u(p),setTimeout(()=>u(null),1500))}),x=i=>{var p,o;return(o=(p=a.find(h=>h.id===i))===null||p===void 0?void 0:p.name)!==null&&o!==void 0?o:i};return n("div",{"data-testid":"apigee-app-detail",children:[e(R,{title:n(T,{children:[t.name,t.status==="revoked"?e(X,{color:"red",children:"Revoked"}):null]}),description:t.description||void 0,actions:n(T,{children:[e(b,{variant:"outlined",onClick:()=>c(!0),icon:e(A,{name:"pen",size:"16px"}),"data-testid":"apigee-edit-app",children:"Edit"}),e(M,{trigger:e(b,{variant:"text","aria-label":"More",icon:e(A,{name:"ellipsis-vertical",size:"16px"}),"data-testid":"apigee-app-menu"}),alignment:"end",children:e(B,{items:[{content:"Delete application",dangerous:!0,onAction:()=>g(!0),dataAttributes:{"data-testid":"apigee-delete-app"}}]})})]})}),n(ae,{children:[n("div",{children:[e("dt",{children:"Owner"}),n("dd",{children:[e(A,{name:t.owner.kind==="team"?"user-group":"user",size:"16px"}),me(t.owner,l)]})]}),n("div",{children:[e("dt",{children:"Created"}),e("dd",{children:$(t.createdAt)})]}),n("div",{className:"wide",children:[e("dt",{children:"Callback URL"}),e("dd",{children:t.callbackUrl||e(C,{children:"Not set"})})]})]}),n(oe,{children:[n(de,{children:[e(le,{children:"API keys"}),e(b,{variant:"outlined",size:"small",onClick:()=>k({}),icon:e(A,{name:"plus",size:"14px"}),"data-testid":"apigee-create-key",children:"Create key"})]}),t.credentials.length===0?e(L,{icon:"key",title:"No keys yet",text:"Create a key and pick the API products it may call."}):e(ue,{children:n(ce,{"data-testid":"apigee-keys-table",children:[e("thead",{children:n("tr",{children:[e("th",{children:"Key"}),e("th",{children:"API products"}),e("th",{children:"Status"}),e("th",{className:"actions"})]})}),e("tbody",{children:t.credentials.map(i=>{const p=z.has(i.consumerKey);return n("tr",{"data-testid":"apigee-key-row",children:[n("td",{className:"key",children:[n(j,{children:[e(H,{"data-testid":"apigee-key-value",children:p?i.consumerKey:Z(i.consumerKey)}),e(b,{variant:"text",size:"small","aria-label":p?"Hide key":"Reveal key",icon:e(A,{name:p?"eye-slash":"eye",size:"14px"}),onClick:()=>_(o=>{const h=new Set(o);return h.has(i.consumerKey)?h.delete(i.consumerKey):h.add(i.consumerKey),h})}),e(b,{variant:"text",size:"small","aria-label":"Copy key",icon:e(A,{name:"copy",size:"14px"}),onClick:()=>v(i.consumerKey,`key:${i.consumerKey}`)}),r===`key:${i.consumerKey}`?e(C,{children:"Copied"}):null]}),i.consumerSecret?n(j,{children:[e(C,{children:"Secret"}),e(H,{children:p?i.consumerSecret:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),e(b,{variant:"text",size:"small","aria-label":"Copy secret",icon:e(A,{name:"copy",size:"14px"}),onClick:()=>{var o;return v((o=i.consumerSecret)!==null&&o!==void 0?o:"",`secret:${i.consumerKey}`)}}),r===`secret:${i.consumerKey}`?e(C,{children:"Copied"}):null]}):null,n(C,{children:["Issued ",$(i.issuedAt)," \xB7 Expires"," ",i.expiresAt?$(i.expiresAt):"never"]})]}),n("td",{children:[n(j,{children:[i.apiProducts.length===0?e(C,{children:"None"}):null,i.apiProducts.map(o=>e(F,{status:o.status,label:o.status==="approved"?x(o.id):`${x(o.id)} \xB7 ${o.status}`},o.id))]}),i.apiProducts.filter(o=>{var h;return(h=o.decision)===null||h===void 0?void 0:h.note}).map(o=>{var h,N;return n(C,{as:"div","data-testid":"apigee-decision-note",children:[((h=o.decision)===null||h===void 0?void 0:h.action)==="approve"?"Approved":"Rejected"," \xB7"," ",x(o.id),": \u201C",(N=o.decision)===null||N===void 0?void 0:N.note,"\u201D"]},o.id)})]}),e("td",{children:e(F,{status:W(i)})}),e("td",{className:"actions",children:e(M,{trigger:e(b,{variant:"text",size:"small","aria-label":"Key actions",icon:e(A,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-key-menu"}),alignment:"end",portalled:!0,children:e(B,{items:[{content:"Edit API products",onAction:()=>k({consumerKey:i.consumerKey,products:i.apiProducts.map(o=>o.id)}),dataAttributes:{"data-testid":"apigee-edit-key"}},{content:"Delete key",dangerous:!0,separatorLine:!0,onAction:()=>S(i.consumerKey),dataAttributes:{"data-testid":"apigee-delete-key"}}]})})})]},i.consumerKey)})})]})}),t.credentials.some(i=>W(i)==="approved")?e("div",{style:{marginTop:"var(--spacing-base)"},children:n(O,{tone:"info",children:[e("strong",{children:"Keys are picked up by Try it."})," Open an operation of an approved API product in the API reference and the key is already filled in."]})}):null]}),e(q,{open:y,onClose:()=>c(!1),onSubmit:i=>D(this,void 0,void 0,function*(){const p=yield P.updateApp(t.id,i,m);return s(),p}),products:a,teams:l,initial:t}),e(pe,{open:d!==null,onClose:()=>k(null),onSubmit:i=>D(this,void 0,void 0,function*(){const p=d?.consumerKey?yield P.updateKey(t.id,d.consumerKey,i,m):yield P.createKey(t.id,i,m);return s(),p}),products:a,initial:d?.products}),e(V,{open:f,onClose:()=>g(!1),title:"Delete application?",confirmLabel:"Delete application",danger:!0,onConfirm:()=>D(this,void 0,void 0,function*(){return yield P.deleteApp(t.id,m),w(),!0}),children:n("p",{children:[e("strong",{children:t.name})," and all of its keys stop working immediately. This cannot be undone."]})}),e(V,{open:I!==null,onClose:()=>S(null),title:"Delete key?",confirmLabel:"Delete key",danger:!0,onConfirm:()=>D(this,void 0,void 0,function*(){return I&&(yield P.deleteKey(t.id,I,m)),s(),!0}),children:e("p",{children:"Requests that send this key are rejected from now on. This cannot be undone."})})]})}export{_e as AppsView};
1
+ var P=function(t,s,r,d){function p(v){return v instanceof r?v:new r(function(g){g(v)})}return new(r||(r=Promise))(function(v,g){function k(u){try{y(d.next(u))}catch(f){g(f)}}function h(u){try{y(d.throw(u))}catch(f){g(f)}}function y(u){u.done?v(u.value):p(u.value).then(k,h)}y((d=d.apply(t,s||[])).next())})};import{Fragment as $,jsx as e,jsxs as a}from"react/jsx-runtime";import{useEffect as V,useMemo as B,useState as x}from"react";import{useNavigate as W}from"react-router";import J from"styled-components";import{Button as w}from"@redocly/theme/components/Button/Button";import{Dropdown as Q}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as X}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as E}from"@redocly/theme/components/Tag/Tag";import{Tooltip as Y}from"@redocly/theme/components/Tooltip/Tooltip";import{CDNIcon as b}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as I}from"../api.js";import{useApigee as Z}from"../context.js";import{maskKey as ee}from"../../contract.js";import{copyText as te,formatDate as L,useAsync as ne}from"../hooks.js";import{EmptyState as M,LinkList as ie,LinkRow as oe,ListTitle as re,Loading as ae,Mono as O,Muted as C,Notice as N,Overview as de,PageBreadcrumbs as le,PageHeader as U,Row as j,Section as se,SectionHeader as ce,SectionTitle as ue,StatusTag as H,Table as pe,TableWrap as me}from"../Primitives.js";import{AppDialog as F,ConfirmDialog as q,KeyDialog as he}from"./Dialogs.js";function ve(t,s){var r,d;return t.kind==="developer"?"Personal":`Team \xB7 ${(d=(r=s.find(p=>p.id===t.teamId))===null||r===void 0?void 0:r.name)!==null&&d!==void 0?d:t.teamId}`}function ye(t){if(t.status==="revoked")return{color:"red",label:"Revoked"};const s=t.credentials.flatMap(p=>p.apiProducts);if(s.length===0)return{color:"grey",label:"No API products"};if(s.some(p=>p.status==="pending"))return{color:"orange",label:"Pending approval"};const r=new Set(s.map(p=>p.id)).size,d=new Set(s.filter(p=>p.status==="approved").map(p=>p.id)).size;return d===r?{color:"green",label:"Approved"}:d===0?{color:"red",label:"Rejected"}:{color:"blue",label:`${d} of ${r} approved`}}function G(t){if(t.status!=="approved")return t.status;const{apiProducts:s}=t;return s.some(r=>r.status==="pending")?"pending":s.length>0&&s.every(r=>r.status==="revoked")?"revoked":"approved"}function Ne({selection:t,teams:s,products:r}){var d,p;const{link:v,title:g}=Z(),k=W(),h=ne(()=>I.listApps(),"apps"),[y,u]=x(null);V(()=>{var o,l;const n=new URLSearchParams(window.location.search);n.has("createApp")&&(u({product:(o=n.get("apiProduct"))!==null&&o!==void 0?o:void 0,teamId:(l=n.get("team"))!==null&&l!==void 0?l:void 0}),k(v(),{replace:!0}))},[v,k]);const f=B(()=>{var o;return!t||!h.data?null:(o=h.data.find(l=>l.id===t.appId&&(t.teamId?l.owner.kind==="team"&&l.owner.teamId===t.teamId:l.owner.kind==="developer")))!==null&&o!==void 0?o:null},[h.data,t]),K=B(()=>{var o;const l=((o=h.data)!==null&&o!==void 0?o:[]).filter(c=>c.owner.kind==="developer"),n=s.map(c=>{var i;return{team:c,apps:((i=h.data)!==null&&i!==void 0?i:[]).filter(m=>m.owner.kind==="team"&&m.owner.teamId===c.id)}});return{personal:l,byTeam:n}},[h.data,s]),_=o=>v(`/${encodeURIComponent(o.id)}`,o.owner.kind==="team"?{team:o.owner.teamId}:void 0),R=o=>P(this,void 0,void 0,function*(){const l=yield I.createApp(o);return h.reload(),k(_(l)),l});if(h.loading&&!h.data)return e(ae,{label:"Loading your apps\u2026"});if(h.error)return e(N,{tone:"danger",children:h.error});const T=(d=h.data)!==null&&d!==void 0?d:[],S=e(F,{open:y!==null,onClose:()=>u(null),onSubmit:R,products:r,teams:s,initialProduct:y?.product,initialTeamId:y?.teamId}),D=e(w,{variant:"primary",onClick:()=>u({}),icon:e(b,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New app"});if(t)return a($,{children:[e(le,{additionalBreadcrumbs:[{label:g,link:v()},{label:(p=f?.name)!==null&&p!==void 0?p:t.appId}]}),f?e(ke,{app:f,teams:s,products:r,onChanged:()=>h.reload(),onDeleted:()=>{h.reload(),k(v())}}):e(N,{tone:"danger",children:"App not found"}),S]});const z=[{key:"personal",title:"Personal",apps:K.personal},...K.byTeam.map(({team:o,apps:l})=>({key:`team:${o.id}`,title:`Team \xB7 ${o.name}`,apps:l}))].filter(o=>o.apps.length>0);return a($,{children:[e(U,{title:g,description:"Register apps and manage the API keys that call the APIs through Apigee.",actions:T.length>0?D:void 0}),T.length===0?e(M,{icon:"key",title:"Create your first app",text:"An app holds the API keys your software sends. Pick the API products it needs; the keys for approved products work right away.",action:D}):e(fe,{"data-testid":"apigee-app-list",children:z.map(o=>a("div",{children:[e(re,{children:o.title}),e(ie,{children:o.apps.map(l=>e(ge,{app:l,to:_(l)},l.id))})]},o.key))}),S]})}const fe=J.div`
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: var(--spacing-lg);
5
+ `;function ge({app:t,to:s}){const r=t.credentials.length,d=ye(t);return e(oe,{to:s,title:t.name,subtitle:`${r} ${r===1?"key":"keys"}${t.description?` \xB7 ${t.description}`:""}`,tag:e(E,{color:d.color,textTransform:"none",children:d.label}),testId:"apigee-app-row"})}function ke({app:t,teams:s,products:r,onChanged:d,onDeleted:p}){const v=t.owner.kind==="team"?t.owner.teamId:void 0,[g,k]=x(!1),[h,y]=x(!1),[u,f]=x(null),[K,_]=x(null),[R,T]=x(new Set),[S,D]=x(null),z=(n,c)=>P(this,void 0,void 0,function*(){(yield te(n))&&(D(c),setTimeout(()=>D(null),1500))}),o=n=>r.find(c=>c.id===n),l=n=>{var c,i;return(i=(c=o(n))===null||c===void 0?void 0:c.name)!==null&&i!==void 0?i:n};return a("div",{"data-testid":"apigee-app-detail",children:[e(U,{title:a($,{children:[t.name,t.status==="revoked"?e(E,{color:"red",children:"Revoked"}):null]}),description:t.description||void 0,actions:a($,{children:[e(w,{variant:"outlined",onClick:()=>k(!0),icon:e(b,{name:"pen",size:"16px"}),"data-testid":"apigee-edit-app",children:"Edit"}),e(Y,{tip:"Delete app",placement:"bottom",children:e(w,{variant:"outlined",tone:"danger","aria-label":"Delete app",icon:e(b,{name:"trash-can",size:"16px"}),onClick:()=>y(!0),"data-testid":"apigee-delete-app"})})]})}),a(de,{children:[a("div",{children:[e("dt",{children:"Owner"}),a("dd",{children:[e(b,{name:t.owner.kind==="team"?"user-group":"user",size:"16px"}),ve(t.owner,s)]})]}),a("div",{children:[e("dt",{children:"Created"}),e("dd",{children:L(t.createdAt)})]}),a("div",{className:"wide",children:[e("dt",{children:"Callback URL"}),e("dd",{children:t.callbackUrl||e(C,{children:"Not set"})})]})]}),a(se,{children:[a(ce,{children:[e(ue,{children:"API keys"}),e(w,{variant:"outlined",size:"small",onClick:()=>f({}),icon:e(b,{name:"plus",size:"14px"}),"data-testid":"apigee-create-key",children:"Create key"})]}),t.credentials.length===0?e(M,{icon:"key",title:"No keys yet",text:"Create a key and pick the API products it may call."}):e(me,{children:a(pe,{"data-testid":"apigee-keys-table",children:[e("thead",{children:a("tr",{children:[e("th",{children:"Key"}),e("th",{children:"API products"}),e("th",{children:"Status"}),e("th",{className:"actions"})]})}),e("tbody",{children:t.credentials.map(n=>{const c=R.has(n.consumerKey);return a("tr",{"data-testid":"apigee-key-row",children:[a("td",{className:"key",children:[a(j,{children:[e(O,{"data-testid":"apigee-key-value",children:c?n.consumerKey:ee(n.consumerKey)}),e(w,{variant:"text",size:"small","aria-label":c?"Hide key":"Reveal key",icon:e(b,{name:c?"eye-slash":"eye",size:"14px"}),onClick:()=>T(i=>{const m=new Set(i);return m.has(n.consumerKey)?m.delete(n.consumerKey):m.add(n.consumerKey),m})}),e(w,{variant:"text",size:"small","aria-label":"Copy key",icon:e(b,{name:"copy",size:"14px"}),onClick:()=>z(n.consumerKey,`key:${n.consumerKey}`)}),S===`key:${n.consumerKey}`?e(C,{children:"Copied"}):null]}),n.consumerSecret?a(j,{children:[e(C,{children:"Secret"}),e(O,{children:c?n.consumerSecret:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),e(w,{variant:"text",size:"small","aria-label":"Copy secret",icon:e(b,{name:"copy",size:"14px"}),onClick:()=>{var i;return z((i=n.consumerSecret)!==null&&i!==void 0?i:"",`secret:${n.consumerKey}`)}}),S===`secret:${n.consumerKey}`?e(C,{children:"Copied"}):null]}):null,a(C,{children:["Issued ",L(n.issuedAt)," \xB7 Expires"," ",n.expiresAt?L(n.expiresAt):"never"]})]}),a("td",{"data-label":"API products",children:[a(j,{children:[n.apiProducts.length===0?e(C,{children:"None"}):null,n.apiProducts.map(i=>{var m,A;return e(H,{status:i.status,label:i.status==="approved"?l(i.id):`${l(i.id)} \xB7 ${i.status}`,to:(A=(m=o(i.id))===null||m===void 0?void 0:m.api)===null||A===void 0?void 0:A.slug},i.id)})]}),n.apiProducts.filter(i=>{var m;return(m=i.decision)===null||m===void 0?void 0:m.note}).map(i=>{var m,A;return a(C,{as:"div","data-testid":"apigee-decision-note",children:[((m=i.decision)===null||m===void 0?void 0:m.action)==="approve"?"Approved":"Rejected"," \xB7"," ",l(i.id),": \u201C",(A=i.decision)===null||A===void 0?void 0:A.note,"\u201D"]},i.id)})]}),e("td",{"data-label":"Status",children:e(H,{status:G(n)})}),e("td",{className:"actions menu",children:e(Q,{trigger:e(w,{variant:"text",size:"small","aria-label":"Key actions",icon:e(b,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-key-menu"}),alignment:"end",portalled:!0,children:e(X,{items:[{content:"Edit API products",onAction:()=>f({consumerKey:n.consumerKey,products:n.apiProducts.map(i=>i.id)}),dataAttributes:{"data-testid":"apigee-edit-key"}},{content:"Delete key",dangerous:!0,separatorLine:!0,onAction:()=>_(n.consumerKey),dataAttributes:{"data-testid":"apigee-delete-key"}}]})})})]},n.consumerKey)})})]})}),t.credentials.some(n=>G(n)==="approved")?e("div",{style:{marginTop:"var(--spacing-base)"},children:a(N,{tone:"info",children:[e("strong",{children:"Keys are picked up by Try it."})," Open an operation of an approved API product in the API reference and the key is already filled in."]})}):null]}),e(F,{open:g,onClose:()=>k(!1),onSubmit:n=>P(this,void 0,void 0,function*(){const c=yield I.updateApp(t.id,n,v);return d(),c}),products:r,teams:s,initial:t}),e(he,{open:u!==null,onClose:()=>f(null),onSubmit:n=>P(this,void 0,void 0,function*(){const c=u?.consumerKey?yield I.updateKey(t.id,u.consumerKey,n,v):yield I.createKey(t.id,n,v);return d(),c}),products:r,initial:u?.products}),e(q,{open:h,onClose:()=>y(!1),title:"Delete app?",confirmLabel:"Delete app",danger:!0,onConfirm:()=>P(this,void 0,void 0,function*(){return yield I.deleteApp(t.id,v),p(),!0}),children:a("p",{children:[e("strong",{children:t.name})," and all of its keys stop working immediately. This cannot be undone."]})}),e(q,{open:K!==null,onClose:()=>_(null),title:"Delete key?",confirmLabel:"Delete key",danger:!0,onConfirm:()=>P(this,void 0,void 0,function*(){return K&&(yield I.deleteKey(t.id,K,v)),d(),!0}),children:e("p",{children:"Requests that send this key are rejected from now on. This cannot be undone."})})]})}export{ge as AppRow,Ne as AppsView};
@@ -1,5 +1,7 @@
1
1
  import { type ReactElement, type ReactNode } from 'react';
2
- import type { ApiProduct, App, AppInput, KeyInput, Team, TeamInput } from '../../contract.js';
2
+ import type { SelectOption } from '@redocly/theme/core/types';
3
+ import type { ApiProduct, App, AppInput, KeyInput, Team, TeamInput, TeamMemberInput, TeamRole } from '../../contract.js';
4
+ export declare const ROLE_OPTIONS: SelectOption<TeamRole>[];
3
5
  type AppDialogProps = {
4
6
  onClose: () => void;
5
7
  onSubmit: (input: AppInput) => Promise<unknown>;
@@ -31,6 +33,13 @@ type TeamDialogProps = {
31
33
  export declare function TeamDialog({ open, ...props }: TeamDialogProps & {
32
34
  open: boolean;
33
35
  }): ReactElement | null;
36
+ type MemberDialogProps = {
37
+ onClose: () => void;
38
+ onSubmit: (input: TeamMemberInput) => Promise<unknown>;
39
+ };
40
+ export declare function MemberDialog({ open, ...props }: MemberDialogProps & {
41
+ open: boolean;
42
+ }): ReactElement | null;
34
43
  type ConfirmDialogProps = {
35
44
  onClose: () => void;
36
45
  onConfirm: (note?: string) => Promise<unknown>;
@@ -1 +1,9 @@
1
- var j=function(n,a,r,t){function o(d){return d instanceof r?d:new r(function(c){c(d)})}return new(r||(r=Promise))(function(d,c){function h(i){try{s(t.next(i))}catch(u){c(u)}}function g(i){try{s(t.throw(i))}catch(u){c(u)}}function s(i){i.done?d(i.value):o(i.value).then(h,g)}s((t=t.apply(n,a||[])).next())})},x=function(n,a){var r={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&a.indexOf(t)<0&&(r[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,t=Object.getOwnPropertySymbols(n);o<t.length;o++)a.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(n,t[o])&&(r[t[o]]=n[t[o]]);return r};import{Fragment as N,jsx as e,jsxs as l}from"react/jsx-runtime";import{useState as v}from"react";import{Button as y}from"@redocly/theme/components/Button/Button";import{Tag as R}from"@redocly/theme/components/Tag/Tag";import{useMutation as D}from"../hooks.js";import{CheckItem as z,CheckItemTitle as $,CheckList as G,Dialog as I,Field as f,FieldLabel as b,Input as P,Muted as k,NativeSelect as H,Notice as S,Textarea as O}from"../Primitives.js";function U({products:n,selected:a,onChange:r}){return n.length===0?e(k,{children:"No API products are available to you yet."}):e(G,{"data-testid":"apigee-product-picker",children:n.map(t=>{const o=a.includes(t.id);return l(z,{$checked:o,children:[e("input",{type:"checkbox",checked:o,onChange:d=>r(d.target.checked?[...a,t.id]:a.filter(c=>c!==t.id))}),l("span",{children:[l($,{children:[t.name,e(R,{color:t.approvalType==="manual"?"orange":"grey",children:t.approvalType==="manual"?"requires approval":"auto-approved"})]}),t.description?e(k,{children:t.description}):null]})]},t.id)})})}function L(n,a){return n.some(r=>a.includes(r.id)&&r.approvalType==="manual")}function oe(n){var{open:a}=n,r=x(n,["open"]);return a?e(J,Object.assign({},r)):null}function J({onClose:n,onSubmit:a,products:r,teams:t,initial:o,initialProduct:d,initialTeamId:c}){var h,g,s;const i=!!o,[u,m]=v((h=o?.name)!==null&&h!==void 0?h:""),[C,W]=v((g=o?.description)!==null&&g!==void 0?g:""),[A,q]=v((s=o?.callbackUrl)!==null&&s!==void 0?s:""),[T,B]=v(o?.owner.kind==="team"?o.owner.teamId:c??""),[_,E]=v(d?[d]:[]),[F,K]=v(""),w=D(),M=()=>j(this,void 0,void 0,function*(){(yield w.run(()=>a(Object.assign(Object.assign({name:u.trim(),description:C.trim(),callbackUrl:A.trim(),apiProducts:_},F.trim()?{note:F.trim()}:{}),T?{teamId:T}:{}))))!==void 0&&n()});return l(I,{open:!0,onClose:n,wide:!0,title:i?"Edit application":"New application",testId:"apigee-app-dialog",footer:l(N,{children:[e(y,{variant:"outlined",onClick:n,disabled:w.pending,children:"Cancel"}),e(y,{variant:"primary",onClick:M,disabled:w.pending||!u.trim(),"data-testid":"apigee-app-submit",children:i?"Save":"Create application"})]}),children:[w.error?e(S,{tone:"danger",children:w.error}):null,l(f,{children:[e(b,{children:"Name"}),e(P,{value:u,onChange:p=>m(p.target.value),placeholder:"Ticketing kiosk",autoFocus:!0,"data-testid":"apigee-app-name"}),i?null:e(k,{children:"Letters, digits, spaces, dots, dashes and underscores. The name cannot change later."})]}),!i&&t.length>0?l(f,{children:[e(b,{children:"Owner"}),l(H,{value:T,onChange:p=>B(p.target.value),"data-testid":"apigee-app-owner",children:[e("option",{value:"",children:"Personal"}),t.map(p=>l("option",{value:p.id,children:["Team \xB7 ",p.name]},p.id))]}),e(k,{children:"Team apps are shared with every member of the team."})]}):null,i?null:l(f,{as:"div",children:[e(b,{children:"API products"}),e(U,{products:r,selected:_,onChange:E})]}),!i&&L(r,_)?l(f,{children:[e(b,{children:"Why do you need access?"}),e(O,{value:F,onChange:p=>K(p.target.value),placeholder:"Sent to the reviewers of the request","data-testid":"apigee-app-note"})]}):null,l(f,{children:[e(b,{children:"Description"}),e(O,{value:C,onChange:p=>W(p.target.value),placeholder:"What does this application do?"})]}),l(f,{children:[e(b,{children:"Callback URL"}),e(P,{value:A,onChange:p=>q(p.target.value),placeholder:"https://example.com/oauth/callback"}),e(k,{children:"Where OAuth 2.0 authorization codes are sent. Separate several URLs with commas."})]})]})}function ae(n){var{open:a}=n,r=x(n,["open"]);return a?e(Q,Object.assign({},r)):null}function Q({onClose:n,onSubmit:a,products:r,initial:t}){const o=t!==void 0,[d,c]=v(t??[]),[h,g]=v(""),s=D(),i=d.filter(m=>!(t??[]).includes(m)),u=()=>j(this,void 0,void 0,function*(){(yield s.run(()=>a(Object.assign({apiProducts:d},h.trim()?{note:h.trim()}:{}))))!==void 0&&n()});return l(I,{open:!0,onClose:n,wide:!0,title:o?"Edit API products":"Create key",testId:"apigee-key-dialog",footer:l(N,{children:[e(y,{variant:"outlined",onClick:n,disabled:s.pending,children:"Cancel"}),e(y,{variant:"primary",onClick:u,disabled:s.pending,"data-testid":"apigee-key-submit",children:o?"Save":"Create key"})]}),children:[s.error?e(S,{tone:"danger",children:s.error}):null,l(f,{as:"div",children:[e(b,{children:"API products"}),e(U,{products:r,selected:d,onChange:c})]}),L(r,i)?l(f,{children:[e(b,{children:"Why do you need access?"}),e(O,{value:h,onChange:m=>g(m.target.value),placeholder:"Sent to the reviewers of the request"})]}):null]})}function ie(n){var{open:a}=n,r=x(n,["open"]);return a?e(V,Object.assign({},r)):null}function V({onClose:n,onSubmit:a,initial:r}){var t,o;const d=!!r,[c,h]=v((t=r?.name)!==null&&t!==void 0?t:""),[g,s]=v((o=r?.description)!==null&&o!==void 0?o:""),i=D(),u=()=>j(this,void 0,void 0,function*(){(yield i.run(()=>a({name:c.trim(),description:g.trim()})))!==void 0&&n()});return l(I,{open:!0,onClose:n,title:d?"Edit team":"New team",testId:"apigee-team-dialog",footer:l(N,{children:[e(y,{variant:"outlined",onClick:n,disabled:i.pending,children:"Cancel"}),e(y,{variant:"primary",onClick:u,disabled:i.pending||!c.trim(),"data-testid":"apigee-team-submit",children:d?"Save":"Create team"})]}),children:[i.error?e(S,{tone:"danger",children:i.error}):null,l(f,{children:[e(b,{children:"Name"}),e(P,{value:c,onChange:m=>h(m.target.value),placeholder:"Platform squad",autoFocus:!0,"data-testid":"apigee-team-name"}),d?null:e(k,{children:"The identifier of the team in Apigee comes from the name and cannot change later."})]}),l(f,{children:[e(b,{children:"Description"}),e(O,{value:g,onChange:m=>s(m.target.value),placeholder:"What does this team build?"})]})]})}function le(n){var{open:a}=n,r=x(n,["open"]);return a?e(X,Object.assign({},r)):null}function X({onClose:n,onConfirm:a,title:r,children:t,confirmLabel:o,danger:d,withNote:c,noteLabel:h="Note",notePlaceholder:g="Optional"}){const[s,i]=v(""),u=D(),m=()=>j(this,void 0,void 0,function*(){(yield u.run(()=>a(s.trim()||void 0)))!==void 0&&n()});return l(I,{open:!0,onClose:n,title:r,testId:"apigee-confirm-dialog",footer:l(N,{children:[e(y,{variant:"outlined",onClick:n,disabled:u.pending,children:"Cancel"}),e(y,{variant:"primary",tone:d?"danger":"default",onClick:m,disabled:u.pending,"data-testid":"apigee-confirm",children:o})]}),children:[u.error?e(S,{tone:"danger",children:u.error}):null,t,c?l(f,{children:[e(b,{children:h}),e(O,{value:s,onChange:C=>i(C.target.value),placeholder:g,"data-testid":"apigee-confirm-note"})]}):null]})}export{oe as AppDialog,le as ConfirmDialog,ae as KeyDialog,ie as TeamDialog};
1
+ var O=function(t,o,n,r){function a(s){return s instanceof n?s:new n(function(d){d(s)})}return new(n||(n=Promise))(function(s,d){function i(c){try{p(r.next(c))}catch(h){d(h)}}function u(c){try{p(r.throw(c))}catch(h){d(h)}}function p(c){c.done?s(c.value):a(c.value).then(i,u)}p((r=r.apply(t,o||[])).next())})},x=function(t,o){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&o.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)o.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n};import{Fragment as I,jsx as e,jsxs as l}from"react/jsx-runtime";import{useState as m}from"react";import q from"styled-components";import{Button as b}from"@redocly/theme/components/Button/Button";import{Select as E}from"@redocly/theme/components/Select/Select";import{Tag as z}from"@redocly/theme/components/Tag/Tag";import{useMutation as D}from"../hooks.js";import{CheckItem as Q,CheckItemTitle as G,CheckList as J,Dialog as T,Field as f,FieldLabel as C,Input as j,Muted as y,Notice as P,RequiredLabel as F,Textarea as S}from"../Primitives.js";const V=[{value:"member",element:"Member"},{value:"owner",element:"Owner"}],X=8,Y=q.div`
2
+ display: flex;
3
+ align-items: baseline;
4
+ justify-content: space-between;
5
+ gap: var(--spacing-sm);
6
+ `,Z=q(J)`
7
+ max-height: 320px;
8
+ overflow-y: auto;
9
+ `;function R({products:t,selected:o,onChange:n}){const[r,a]=m(""),s=r.trim().toLowerCase(),d=t.filter(i=>`${i.name} ${i.description}`.toLowerCase().includes(s));return l(f,{as:"div",children:[l(Y,{children:[e(C,{children:"API products"}),t.length>0?l(y,{"data-testid":"apigee-product-count",children:[o.length," selected"]}):null]}),t.length===0?e(y,{children:"No API products are available to you yet."}):null,t.length>X?e(j,{type:"search",value:r,onChange:i=>a(i.target.value),placeholder:"Search API products","aria-label":"Search API products","data-testid":"apigee-product-search"}):null,t.length>0&&d.length===0?l(y,{children:["No API products match \u201C",r.trim(),"\u201D."]}):null,d.length>0?e(Z,{"data-testid":"apigee-product-picker",children:d.map(i=>{const u=o.includes(i.id);return l(Q,{$checked:u,children:[e("input",{type:"checkbox",checked:u,onChange:p=>n(p.target.checked?[...o,i.id]:o.filter(c=>c!==i.id))}),l("span",{children:[l(G,{children:[i.name,e(z,{color:i.approvalType==="manual"?"orange":"grey",children:i.approvalType==="manual"?"requires approval":"auto-approved"})]}),i.description?e(y,{children:i.description}):null]})]},i.id)})}):null]})}function U(t,o){return t.some(n=>o.includes(n.id)&&n.approvalType==="manual")}function he(t){var{open:o}=t,n=x(t,["open"]);return o?e(ee,Object.assign({},n)):null}function ee({onClose:t,onSubmit:o,products:n,teams:r,initial:a,initialProduct:s,initialTeamId:d}){var i,u,p;const c=!!a,[h,g]=m((i=a?.name)!==null&&i!==void 0?i:""),[k,M]=m((u=a?.description)!==null&&u!==void 0?u:""),[L,W]=m((p=a?.callbackUrl)!==null&&p!==void 0?p:""),[N,H]=m(a?.owner.kind==="team"?a.owner.teamId:d??""),[_,$]=m(s?[s]:[]),[A,B]=m(""),w=D(),K=()=>O(this,void 0,void 0,function*(){(yield w.run(()=>o(Object.assign(Object.assign({name:h.trim(),description:k.trim(),callbackUrl:L.trim(),apiProducts:_},A.trim()?{note:A.trim()}:{}),N?{teamId:N}:{}))))!==void 0&&t()});return l(T,{open:!0,onClose:t,wide:!0,title:c?"Edit app":"New app",testId:"apigee-app-dialog",footer:l(I,{children:[e(b,{variant:"outlined",onClick:t,disabled:w.pending,children:"Cancel"}),e(b,{variant:"primary",onClick:K,disabled:w.pending||!h.trim(),"data-testid":"apigee-app-submit",children:c?"Save":"Create app"})]}),children:[w.error?e(P,{tone:"danger",children:w.error}):null,l(f,{children:[e(F,{children:"Name"}),e(j,{value:h,onChange:v=>g(v.target.value),placeholder:"Ticketing kiosk",required:!0,autoFocus:!0,"data-testid":"apigee-app-name"}),c?null:e(y,{children:"Letters, digits, spaces, dots, dashes and underscores. The name cannot change later."})]}),!c&&r.length>0?l(f,{as:"div",children:[e(C,{children:"Owner"}),e(E,{value:N,options:[{value:"",element:"Personal"},...r.map(v=>({value:v.id,element:`Team \xB7 ${v.name}`}))],onChange:v=>H(v),dataTestId:"apigee-app-owner"}),e(y,{children:"Team apps are shared with every member of the team."})]}):null,c?null:e(R,{products:n,selected:_,onChange:$}),!c&&U(n,_)?l(f,{children:[e(C,{children:"Why do you need access?"}),e(S,{value:A,onChange:v=>B(v.target.value),placeholder:"Sent to the reviewers of the request","data-testid":"apigee-app-note"})]}):null,l(f,{children:[e(C,{children:"Description"}),e(S,{value:k,onChange:v=>M(v.target.value),placeholder:"What does this app do?"})]}),l(f,{children:[e(C,{children:"Callback URL"}),e(j,{value:L,onChange:v=>W(v.target.value),placeholder:"https://example.com/oauth/callback"}),e(y,{children:"Where OAuth 2.0 authorization codes are sent. Separate several URLs with commas."})]})]})}function me(t){var{open:o}=t,n=x(t,["open"]);return o?e(te,Object.assign({},n)):null}function te({onClose:t,onSubmit:o,products:n,initial:r}){const a=r!==void 0,[s,d]=m(r??[]),[i,u]=m(""),p=D(),c=s.filter(g=>!(r??[]).includes(g)),h=()=>O(this,void 0,void 0,function*(){(yield p.run(()=>o(Object.assign({apiProducts:s},i.trim()?{note:i.trim()}:{}))))!==void 0&&t()});return l(T,{open:!0,onClose:t,wide:!0,title:a?"Edit API products":"Create key",testId:"apigee-key-dialog",footer:l(I,{children:[e(b,{variant:"outlined",onClick:t,disabled:p.pending,children:"Cancel"}),e(b,{variant:"primary",onClick:h,disabled:p.pending,"data-testid":"apigee-key-submit",children:a?"Save":"Create key"})]}),children:[p.error?e(P,{tone:"danger",children:p.error}):null,e(R,{products:n,selected:s,onChange:d}),U(n,c)?l(f,{children:[e(C,{children:"Why do you need access?"}),e(S,{value:i,onChange:g=>u(g.target.value),placeholder:"Sent to the reviewers of the request"})]}):null]})}function ge(t){var{open:o}=t,n=x(t,["open"]);return o?e(ne,Object.assign({},n)):null}function ne({onClose:t,onSubmit:o,initial:n}){var r,a;const s=!!n,[d,i]=m((r=n?.name)!==null&&r!==void 0?r:""),[u,p]=m((a=n?.description)!==null&&a!==void 0?a:""),c=D(),h=()=>O(this,void 0,void 0,function*(){(yield c.run(()=>o({name:d.trim(),description:u.trim()})))!==void 0&&t()});return l(T,{open:!0,onClose:t,title:s?"Edit team":"New team",testId:"apigee-team-dialog",footer:l(I,{children:[e(b,{variant:"outlined",onClick:t,disabled:c.pending,children:"Cancel"}),e(b,{variant:"primary",onClick:h,disabled:c.pending||!d.trim(),"data-testid":"apigee-team-submit",children:s?"Save":"Create team"})]}),children:[c.error?e(P,{tone:"danger",children:c.error}):null,l(f,{children:[e(F,{children:"Name"}),e(j,{value:d,onChange:g=>i(g.target.value),placeholder:"Platform squad",required:!0,autoFocus:!0,"data-testid":"apigee-team-name"}),s?null:e(y,{children:"The identifier of the team in Apigee comes from the name and cannot change later."})]}),l(f,{children:[e(C,{children:"Description"}),e(S,{value:u,onChange:g=>p(g.target.value),placeholder:"What does this team build?"})]})]})}function ve(t){var{open:o}=t,n=x(t,["open"]);return o?e(re,Object.assign({},n)):null}function re({onClose:t,onSubmit:o}){const[n,r]=m(""),[a,s]=m("member"),d=D(),i=()=>O(this,void 0,void 0,function*(){(yield d.run(()=>o({email:n.trim(),role:a})))!==void 0&&t()});return l(T,{open:!0,onClose:t,title:"Add member",testId:"apigee-member-dialog",footer:l(I,{children:[e(b,{variant:"outlined",onClick:t,disabled:d.pending,children:"Cancel"}),e(b,{variant:"primary",onClick:i,disabled:d.pending||!n.trim(),"data-testid":"apigee-member-submit",children:"Add member"})]}),children:[d.error?e(P,{tone:"danger",children:d.error}):null,l(f,{children:[e(F,{children:"Email"}),e(j,{type:"email",value:n,onChange:u=>r(u.target.value),placeholder:"colleague@example.com",required:!0,autoFocus:!0,"data-testid":"apigee-member-email"}),e(y,{children:"The member signs in with the portal account that has this email."})]}),l(f,{as:"div",children:[e(C,{children:"Role"}),e(E,{value:a,options:V,onChange:u=>s(u),dataTestId:"apigee-member-role-select"}),e(y,{children:"Owners can add and remove members and delete the team."})]})]})}function fe(t){var{open:o}=t,n=x(t,["open"]);return o?e(ae,Object.assign({},n)):null}function ae({onClose:t,onConfirm:o,title:n,children:r,confirmLabel:a,danger:s,withNote:d,noteLabel:i="Note",notePlaceholder:u="Optional"}){const[p,c]=m(""),h=D(),g=()=>O(this,void 0,void 0,function*(){(yield h.run(()=>o(p.trim()||void 0)))!==void 0&&t()});return l(T,{open:!0,onClose:t,title:n,testId:"apigee-confirm-dialog",footer:l(I,{children:[e(b,{variant:"outlined",onClick:t,disabled:h.pending,children:"Cancel"}),e(b,{variant:"primary",tone:s?"danger":"default",onClick:g,disabled:h.pending,"data-testid":"apigee-confirm",children:a})]}),children:[h.error?e(P,{tone:"danger",children:h.error}):null,r,d?l(f,{children:[e(C,{children:i}),e(S,{value:p,onChange:k=>c(k.target.value),placeholder:u,"data-testid":"apigee-confirm-note"})]}):null]})}export{he as AppDialog,fe as ConfirmDialog,me as KeyDialog,ve as MemberDialog,V as ROLE_OPTIONS,ge as TeamDialog};
@@ -1 +1 @@
1
- var y=function(h,u,d,c){function p(r){return r instanceof d?r:new d(function(s){s(r)})}return new(d||(d=Promise))(function(r,s){function l(m){try{g(c.next(m))}catch(x){s(x)}}function n(m){try{g(c.throw(m))}catch(x){s(x)}}function g(m){m.done?r(m.value):p(m.value).then(l,n)}g((c=c.apply(h,u||[])).next())})};import{Fragment as R,jsx as e,jsxs as i}from"react/jsx-runtime";import{useState as w}from"react";import{useNavigate as U}from"react-router";import{Button as b}from"@redocly/theme/components/Button/Button";import{Dropdown as ne}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as ae}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Link as L}from"@redocly/theme/components/Link/Link";import{Tag as S}from"@redocly/theme/components/Tag/Tag";import{CDNIcon as M}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as v}from"../api.js";import{useApigee as Y}from"../context.js";import{formatDate as B,useAsync as H,useMutation as re}from"../hooks.js";import{Breadcrumb as le,EmptyState as P,Field as V,FieldLabel as K,Input as oe,Loading as W,Muted as N,NativeSelect as q,Notice as _,PageHeader as G,Row as I,Section as J,SectionHeader as de,SectionTitle as Q,StatusTag as ce,Table as $,TableWrap as z}from"../Primitives.js";import{ConfirmDialog as X,TeamDialog as Z}from"./Dialogs.js";function Ae({teams:h,onTeamsChanged:u}){const{link:d}=Y(),c=U(),[p,r]=w(!1),s=e(Z,{open:p,onClose:()=>r(!1),onSubmit:n=>y(this,void 0,void 0,function*(){const g=yield v.createTeam(n);return u(),c(d(`/teams/${encodeURIComponent(g.id)}`)),g})}),l=e(b,{variant:"primary",onClick:()=>r(!0),icon:e(M,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team",children:"New team"});return i(R,{children:[e(G,{title:"Teams",description:"Share apps and keys with colleagues. A team is an Apigee app group; its members manage the team's apps together.",actions:h.length>0?l:void 0}),h.length===0?e(P,{icon:"user-group",title:"You are not in a team yet",text:"Create a team to share API keys with your colleagues, or ask a team owner to add your email.",action:l}):e(z,{children:i($,{"data-testid":"apigee-teams-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"Team"}),e("th",{children:"Members"}),e("th",{children:"Your role"}),e("th",{children:"Created"})]})}),e("tbody",{children:h.map(n=>i("tr",{children:[i("td",{children:[e(L,{to:d(`/teams/${encodeURIComponent(n.id)}`),children:n.name}),n.description?i(R,{children:[e("br",{}),e(N,{children:n.description})]}):null]}),e("td",{children:n.members.length}),e("td",{children:n.myRole?e(S,{color:n.myRole==="owner"?"blue":"grey",children:n.myRole}):null}),e("td",{children:B(n.createdAt)})]},n.id))})]})}),s]})}function Re({teamId:h,onTeamsChanged:u}){var d,c;const{link:p,meta:r}=Y(),s=U(),l=H(()=>v.getTeam(h),`team:${h}`),n=H(()=>v.listApps(),`team-apps:${h}`),[g,m]=w(!1),[x,j]=w(!1),[f,T]=w(null),[D,E]=w(""),[F,ee]=w("member"),C=re();if(l.loading&&!l.data)return e(W,{children:"Loading the team\u2026"});if(l.error||!l.data)return e(_,{tone:"danger",children:(d=l.error)!==null&&d!==void 0?d:"Team not found"});const o=l.data,k=o.myRole==="owner",O=((c=n.data)!==null&&c!==void 0?c:[]).filter(t=>t.owner.kind==="team"&&t.owner.teamId===o.id),te=()=>y(this,void 0,void 0,function*(){const t=yield C.run(()=>v.addMember(o.id,{email:D.trim(),role:F}));t&&(l.setData(t),E(""),u())}),ie=(t,a)=>y(this,void 0,void 0,function*(){const A=yield C.run(()=>v.setMemberRole(o.id,t,a));A&&l.setData(A)});return i("div",{"data-testid":"apigee-team-detail",children:[i(le,{children:[e(L,{to:p("/teams"),children:"Teams"}),e("span",{children:"/"}),e("span",{children:o.name})]}),e(G,{title:o.name,description:o.description||"Shared apps and keys for the team.",actions:k?i(R,{children:[e(b,{variant:"outlined",onClick:()=>m(!0),icon:e(M,{name:"pen",size:"16px"}),children:"Edit team"}),e(b,{variant:"primary",onClick:()=>s(p("",{createApp:"",team:o.id})),icon:e(M,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team-app",children:"New team app"}),e(ne,{trigger:e(b,{variant:"text","aria-label":"More",icon:e(M,{name:"ellipsis-vertical",size:"16px"})}),alignment:"end",children:e(ae,{items:[{content:"Delete team",dangerous:!0,onAction:()=>j(!0),dataAttributes:{"data-testid":"apigee-delete-team"}}]})})]}):e(b,{variant:"outlined",tone:"danger",onClick:()=>T(r.viewer.email),children:"Leave team"})}),C.error?e(_,{tone:"danger",children:C.error}):null,i(J,{children:[e(Q,{children:"Members"}),e(z,{children:i($,{"data-testid":"apigee-members-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"Member"}),e("th",{children:"Role"}),e("th",{children:"Added"}),e("th",{className:"actions"})]})}),e("tbody",{children:o.members.map(t=>{const a=t.email===r.viewer.email;return i("tr",{"data-testid":"apigee-member-row",children:[e("td",{children:i(I,{children:[t.email,a?e(S,{color:"grey",children:"you"}):null]})}),e("td",{children:k?i(q,{value:t.role,onChange:A=>ie(t.email,A.target.value),style:{width:"auto"},"aria-label":`Role of ${t.email}`,children:[e("option",{value:"member",children:"Member"}),e("option",{value:"owner",children:"Owner"})]}):e(S,{color:t.role==="owner"?"blue":"grey",children:t.role})}),e("td",{children:B(t.addedAt)}),e("td",{className:"actions",children:k||a?e(b,{variant:"text",size:"small",tone:"danger",onClick:()=>T(t.email),"data-testid":"apigee-remove-member",children:a?"Leave":"Remove"}):null})]},t.email)})})]})}),k?i(I,{style:{alignItems:"flex-end",marginTop:"var(--spacing-base)"},"data-testid":"apigee-add-member-form",children:[i(V,{style:{flex:"1 1 260px"},children:[e(K,{children:"Add a member"}),e(oe,{type:"email",value:D,onChange:t=>E(t.target.value),placeholder:"colleague@example.com","data-testid":"apigee-member-email"})]}),i(V,{style:{width:140},children:[e(K,{children:"Role"}),i(q,{value:F,onChange:t=>ee(t.target.value),children:[e("option",{value:"member",children:"Member"}),e("option",{value:"owner",children:"Owner"})]})]}),e(b,{variant:"outlined",onClick:te,disabled:C.pending||!D.trim(),"data-testid":"apigee-add-member",children:"Add"})]}):null,e(N,{as:"p",style:{marginTop:"var(--spacing-xs)"},children:"Members sign in with the portal account that matches their email. Owners can add and remove members and delete the team."})]}),i(J,{children:[e(de,{children:e(Q,{children:"Team apps"})}),n.loading&&!n.data?e(W,{children:"Loading apps\u2026"}):n.error?e(_,{tone:"danger",children:n.error}):O.length===0?e(P,{icon:"key",title:"No team apps yet",text:"Create an app for this team so every member can use its keys."}):e(z,{children:i($,{"data-testid":"apigee-team-apps-table",children:[e("thead",{children:i("tr",{children:[e("th",{children:"App"}),e("th",{children:"API products"}),e("th",{children:"Keys"})]})}),e("tbody",{children:O.map(t=>i("tr",{children:[i("td",{children:[e(L,{to:p(`/${encodeURIComponent(t.id)}`,{team:o.id}),children:t.name}),t.description?i(R,{children:[e("br",{}),e(N,{children:t.description})]}):null]}),e("td",{children:e(I,{children:[...new Map(t.credentials.flatMap(a=>a.apiProducts).map(a=>[a.id,a])).values()].map(a=>e(ce,{status:a.status,label:a.id},a.id))})}),e("td",{children:t.credentials.length})]},t.id))})]})})]}),e(Z,{open:g,onClose:()=>m(!1),initial:o,onSubmit:t=>y(this,void 0,void 0,function*(){const a=yield v.updateTeam(o.id,t);return l.setData(a),u(),a})}),e(X,{open:x,onClose:()=>j(!1),title:"Delete team?",confirmLabel:"Delete team",danger:!0,onConfirm:()=>y(this,void 0,void 0,function*(){return yield v.deleteTeam(o.id),u(),s(p("/teams")),!0}),children:i("p",{children:[e("strong",{children:o.name}),", its apps and all of their keys are removed from Apigee. This cannot be undone."]})}),e(X,{open:f!==null,onClose:()=>T(null),title:f===r.viewer.email?"Leave team?":"Remove member?",confirmLabel:f===r.viewer.email?"Leave team":"Remove member",danger:!0,onConfirm:()=>y(this,void 0,void 0,function*(){if(!f)return!0;const t=yield v.removeMember(o.id,f);return f===r.viewer.email?(u(),s(p("/teams"))):l.setData(t),!0}),children:e("p",{children:f===r.viewer.email?"You lose access to the team apps and their keys.":`${f} loses access to the team apps and their keys.`})})]})}export{Re as TeamDetailView,Ae as TeamsView};
1
+ var w=function(p,h,o,s){function u(a){return a instanceof o?a:new o(function(m){m(a)})}return new(o||(o=Promise))(function(a,m){function n(c){try{g(s.next(c))}catch(k){m(k)}}function i(c){try{g(s.throw(c))}catch(k){m(k)}}function g(c){c.done?a(c.value):u(c.value).then(n,i)}g((s=s.apply(p,h||[])).next())})};import{Fragment as z,jsx as e,jsxs as d}from"react/jsx-runtime";import{useState as C}from"react";import{useNavigate as N}from"react-router";import{Button as f}from"@redocly/theme/components/Button/Button";import{Dropdown as I}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as O}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as M}from"@redocly/theme/components/Tag/Tag";import{CDNIcon as y}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as b}from"../api.js";import{useApigee as j}from"../context.js";import{formatDate as Q,useAsync as E,useMutation as X}from"../hooks.js";import{EmptyState as B,LinkList as P,LinkRow as Z,Loading as U,Muted as ee,Notice as L,PageBreadcrumbs as te,PageHeader as Y,Row as ie,Section as F,SectionHeader as H,SectionTitle as V,Table as ae,TableWrap as ne}from"../Primitives.js";import{AppRow as re}from"./AppsView.js";import{ConfirmDialog as W,MemberDialog as oe,ROLE_OPTIONS as q,TeamDialog as G}from"./Dialogs.js";function ke({teams:p,onTeamsChanged:h}){const{link:o}=j(),s=N(),[u,a]=C(!1),m=e(G,{open:u,onClose:()=>a(!1),onSubmit:i=>w(this,void 0,void 0,function*(){const g=yield b.createTeam(i);return h(),s(o(`/teams/${encodeURIComponent(g.id)}`)),g})}),n=e(f,{variant:"primary",onClick:()=>a(!0),icon:e(y,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team",children:"New team"});return d(z,{children:[e(Y,{title:"Teams",description:"Share apps and keys with colleagues. A team is an Apigee app group; its members manage the team's apps together.",actions:p.length>0?n:void 0}),p.length===0?e(B,{icon:"user-group",title:"You are not in a team yet",text:"Create a team to share API keys with your colleagues, or ask a team owner to add your email.",action:n}):e(P,{"data-testid":"apigee-team-list",children:p.map(i=>e(Z,{to:o(`/teams/${encodeURIComponent(i.id)}`),title:i.name,subtitle:`${i.members.length} ${i.members.length===1?"member":"members"}${i.description?` \xB7 ${i.description}`:""}`,tag:i.myRole?e(M,{color:i.myRole==="owner"?"blue":"grey",children:i.myRole}):void 0},i.id))}),m]})}function Ae({teamId:p,onTeamsChanged:h}){var o,s;const{link:u,meta:a}=j(),m=N(),n=E(()=>b.getTeam(p),`team:${p}`),i=E(()=>b.listApps(),`team-apps:${p}`),[g,c]=C(!1),[k,S]=C(!1),[v,D]=C(null),[J,_]=C(!1),T=X();if(n.loading&&!n.data)return e(U,{label:"Loading the team\u2026"});if(n.error||!n.data)return e(L,{tone:"danger",children:(o=n.error)!==null&&o!==void 0?o:"Team not found"});const r=n.data,A=r.myRole==="owner",$=((s=i.data)!==null&&s!==void 0?s:[]).filter(t=>t.owner.kind==="team"&&t.owner.teamId===r.id),K=(t,l)=>w(this,void 0,void 0,function*(){const x=yield T.run(()=>b.setMemberRole(r.id,t,l));x&&n.setData(x)});return d("div",{"data-testid":"apigee-team-detail",children:[e(te,{additionalBreadcrumbs:[{label:"Teams",link:u("/teams")},{label:r.name}]}),e(Y,{title:r.name,description:r.description||"Shared apps and keys for the team.",actions:A?d(z,{children:[e(f,{variant:"outlined",onClick:()=>c(!0),icon:e(y,{name:"pen",size:"16px"}),children:"Edit team"}),e(f,{variant:"primary",onClick:()=>m(u("",{createApp:"",team:r.id})),icon:e(y,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team-app",children:"New team app"}),e(I,{trigger:e(f,{variant:"text","aria-label":"More",icon:e(y,{name:"ellipsis-vertical",size:"16px"}),"data-testid":"apigee-team-menu"}),alignment:"end",children:e(O,{items:[{content:"Leave team",onAction:()=>D(a.viewer.email),dataAttributes:{"data-testid":"apigee-leave-team"}},{content:"Delete team",dangerous:!0,onAction:()=>S(!0),dataAttributes:{"data-testid":"apigee-delete-team"}}]})})]}):e(f,{variant:"outlined",tone:"danger",onClick:()=>D(a.viewer.email),"data-testid":"apigee-leave-team",children:"Leave team"})}),T.error?e(L,{tone:"danger",children:T.error}):null,d(F,{children:[d(H,{children:[e(V,{children:"Members"}),A?e(f,{variant:"outlined",size:"small",onClick:()=>_(!0),icon:e(y,{name:"plus",size:"14px"}),"data-testid":"apigee-add-member",children:"Add member"}):null]}),e(ne,{children:d(ae,{"data-testid":"apigee-members-table",children:[e("thead",{children:d("tr",{children:[e("th",{children:"Member"}),e("th",{children:"Role"}),e("th",{children:"Added"}),A?e("th",{className:"actions"}):null]})}),e("tbody",{children:r.members.map(t=>{var l;const x=t.email===a.viewer.email;return d("tr",{"data-testid":"apigee-member-row",children:[e("td",{children:d(ie,{children:[t.email,x?e(M,{color:"grey",children:"You"}):null]})}),e("td",{"data-label":"Role",children:A?e(I,{trigger:e(f,{variant:"outlined",size:"small",icon:e(y,{name:"chevron-down",size:"12px"}),iconPosition:"right","data-testid":"apigee-member-role",children:(l=q.find(R=>R.value===t.role))===null||l===void 0?void 0:l.element}),portalled:!0,children:e(O,{items:q.map(R=>({content:R.element,active:R.value===t.role,onAction:()=>K(t.email,R.value)}))})}):e(M,{color:t.role==="owner"?"blue":"grey",children:t.role})}),e("td",{"data-label":"Added",children:Q(t.addedAt)}),A?e("td",{className:"actions",children:x?null:e(f,{variant:"text",size:"small",tone:"danger",onClick:()=>D(t.email),"data-testid":"apigee-remove-member",children:"Remove"})}):null]},t.email)})})]})}),e(ee,{as:"p",style:{marginTop:"var(--spacing-xs)"},children:"Members sign in with the portal account that matches their email. Owners can add and remove members and delete the team."})]}),d(F,{children:[e(H,{children:e(V,{children:"Team apps"})}),i.loading&&!i.data?e(U,{label:"Loading apps\u2026"}):i.error?e(L,{tone:"danger",children:i.error}):$.length===0?e(B,{icon:"key",title:"No team apps yet",text:"Create an app for this team so every member can use its keys."}):e(P,{"data-testid":"apigee-team-apps-list",children:$.map(t=>e(re,{app:t,to:u(`/${encodeURIComponent(t.id)}`,{team:r.id})},t.id))})]}),e(oe,{open:J,onClose:()=>_(!1),onSubmit:t=>w(this,void 0,void 0,function*(){const l=yield b.addMember(r.id,t);return n.setData(l),h(),l})}),e(G,{open:g,onClose:()=>c(!1),initial:r,onSubmit:t=>w(this,void 0,void 0,function*(){const l=yield b.updateTeam(r.id,t);return n.setData(l),h(),l})}),e(W,{open:k,onClose:()=>S(!1),title:"Delete team?",confirmLabel:"Delete team",danger:!0,onConfirm:()=>w(this,void 0,void 0,function*(){return yield b.deleteTeam(r.id),h(),m(u("/teams")),!0}),children:d("p",{children:[e("strong",{children:r.name}),", its apps and all of their keys are removed from Apigee. This cannot be undone."]})}),e(W,{open:v!==null,onClose:()=>D(null),title:v===a.viewer.email?"Leave team?":"Remove member?",confirmLabel:v===a.viewer.email?"Leave team":"Remove member",danger:!0,onConfirm:()=>w(this,void 0,void 0,function*(){if(!v)return!0;const t=yield b.removeMember(r.id,v);return v===a.viewer.email?(h(),m(u("/teams"))):n.setData(t),!0}),children:e("p",{children:v===a.viewer.email?"You lose access to the team apps and their keys.":`${v} loses access to the team apps and their keys.`})})]})}export{Ae as TeamDetailView,ke as TeamsView};
@@ -2,7 +2,7 @@ import type { SERVER_ONLY_VALUE_KEY } from '@redocly/framework/plugin';
2
2
  export declare const APIGEE_PLUGIN_ID = "redocly.apigee";
3
3
  export declare const APIGEE_TEMPLATE_ID = "apigee-apps";
4
4
  export declare const APIGEE_DEFAULT_BASE_PATH = "/apps";
5
- export declare const APIGEE_DEFAULT_TITLE = "API keys";
5
+ export declare const APIGEE_DEFAULT_TITLE = "Apps";
6
6
  export declare const APIGEE_DEFAULT_API_URL = "https://apigee.googleapis.com/v1";
7
7
  /** The server-only entity that maps Apigee API product names to the API pages that document them. */
8
8
  export declare const APIGEE_PRODUCTS_ENTITY_KEY = "apigee:api-products";
package/lib/constants.js CHANGED
@@ -1 +1 @@
1
- const s="redocly.apigee",p="apigee-apps",a="/apps",t="API keys",E="https://apigee.googleapis.com/v1",_="apigee:api-products",o="__serverOnly",e="/_apigee",I={meta:`${e}/meta`,access:`${e}/access`,apps:`${e}/apps`,app:`${e}/apps/:appId`,appKeys:`${e}/apps/:appId/keys`,appKey:`${e}/apps/:appId/keys/:consumerKey`,teams:`${e}/teams`,team:`${e}/teams/:teamId`,teamMembers:`${e}/teams/:teamId/members`,teamMember:`${e}/teams/:teamId/members/:email`,adminRequests:`${e}/admin/requests`,adminRequestApprove:`${e}/admin/requests/:requestId/approve`,adminRequestRevoke:`${e}/admin/requests/:requestId/revoke`,adminApps:`${e}/admin/apps`,adminAudit:`${e}/admin/audit`},m="__apigee_reserved__developer_details",r="DisplayName",A="Notes",T=3600*24*365;export{E as APIGEE_DEFAULT_API_URL,a as APIGEE_DEFAULT_BASE_PATH,T as APIGEE_DEFAULT_KEY_LIFETIME_SECONDS,t as APIGEE_DEFAULT_TITLE,r as APIGEE_DISPLAY_NAME_ATTRIBUTE,A as APIGEE_NOTES_ATTRIBUTE,s as APIGEE_PLUGIN_ID,_ as APIGEE_PRODUCTS_ENTITY_KEY,o as APIGEE_PRODUCTS_VALUE_KEY,I as APIGEE_ROUTES,m as APIGEE_TEAM_MEMBERS_ATTRIBUTE,p as APIGEE_TEMPLATE_ID};
1
+ const p="redocly.apigee",s="apigee-apps",a="/apps",t="Apps",E="https://apigee.googleapis.com/v1",_="apigee:api-products",o="__serverOnly",e="/_apigee",I={meta:`${e}/meta`,access:`${e}/access`,apps:`${e}/apps`,app:`${e}/apps/:appId`,appKeys:`${e}/apps/:appId/keys`,appKey:`${e}/apps/:appId/keys/:consumerKey`,teams:`${e}/teams`,team:`${e}/teams/:teamId`,teamMembers:`${e}/teams/:teamId/members`,teamMember:`${e}/teams/:teamId/members/:email`,adminRequests:`${e}/admin/requests`,adminRequestApprove:`${e}/admin/requests/:requestId/approve`,adminRequestRevoke:`${e}/admin/requests/:requestId/revoke`,adminApps:`${e}/admin/apps`,adminAudit:`${e}/admin/audit`},m="__apigee_reserved__developer_details",r="DisplayName",A="Notes",T=3600*24*365;export{E as APIGEE_DEFAULT_API_URL,a as APIGEE_DEFAULT_BASE_PATH,T as APIGEE_DEFAULT_KEY_LIFETIME_SECONDS,t as APIGEE_DEFAULT_TITLE,r as APIGEE_DISPLAY_NAME_ATTRIBUTE,A as APIGEE_NOTES_ATTRIBUTE,p as APIGEE_PLUGIN_ID,_ as APIGEE_PRODUCTS_ENTITY_KEY,o as APIGEE_PRODUCTS_VALUE_KEY,I as APIGEE_ROUTES,m as APIGEE_TEAM_MEMBERS_ATTRIBUTE,s as APIGEE_TEMPLATE_ID};
package/lib/contract.d.ts CHANGED
@@ -16,6 +16,8 @@ export type Decision = {
16
16
  };
17
17
  type ApiProductStatus = {
18
18
  id: string;
19
+ /** The product's display name; only the reviewer routes send it, and only when Apigee has one. */
20
+ name?: string;
19
21
  status: ApprovalStatus;
20
22
  decision?: Decision;
21
23
  };
@@ -100,11 +102,15 @@ export type AccessRequest = {
100
102
  owner: AppOwner;
101
103
  /** The developer who asked, when the request was made through this portal. */
102
104
  requestedBy?: string;
105
+ /** The display name of the owning team, when Apigee has one. */
106
+ teamName?: string;
103
107
  appId: string;
104
108
  appName: string;
105
109
  /** Masked: the first and last characters only. */
106
110
  consumerKey: string;
107
111
  apiProduct: string;
112
+ /** The product's display name, when Apigee has one. */
113
+ apiProductName?: string;
108
114
  note?: string;
109
115
  requestedAt: number | null;
110
116
  /** Whether the viewer may decide this request: `maintain` or `admin` on the product's page or the apps page. */
@@ -117,15 +123,21 @@ export type AuditEntry = {
117
123
  actor: string;
118
124
  action: AuditAction;
119
125
  owner: AppOwner;
126
+ /** The display name of the owning team, when Apigee has one; the audit route adds it. */
127
+ teamName?: string;
120
128
  appId: string;
121
129
  appName: string;
122
130
  /** Masked: the first and last characters only. */
123
131
  consumerKey: string;
124
132
  apiProduct: string;
133
+ /** The product's display name, when Apigee has one; the audit route adds it. */
134
+ apiProductName?: string;
125
135
  note?: string;
126
136
  };
127
137
  /** An app as reviewers see it: its keys without their values. */
128
138
  export type AdminApp = Omit<App, 'credentials'> & {
139
+ /** The display name of the owning team, when Apigee has one. */
140
+ teamName?: string;
129
141
  credentials: Omit<Credential, 'consumerKey' | 'consumerSecret'>[];
130
142
  };
131
143
  /** The viewer's standing on the Approvals page, from the rbac roles on the API pages and the apps page. */
@@ -173,6 +185,7 @@ export type ApigeeAppData = {
173
185
  accountLinks: {
174
186
  label: string;
175
187
  link: string;
188
+ icon: string;
176
189
  }[];
177
190
  /** Answers `ApiAccess` for the sidebar button and Try it on a page whose metadata has `apiId`. */
178
191
  apiAccessRoute: string;
package/lib/plugin.d.ts CHANGED
@@ -2,7 +2,7 @@ import { type ContentPlugin } from '@redocly/framework/plugin';
2
2
  export { APIGEE_TEMPLATE_ID } from './constants.js';
3
3
  export type { ApigeeAppData } from './contract.js';
4
4
  /**
5
- * The Apigee developer onboarding plugin for Realm Plus: an API keys page for signed-in
5
+ * The Apigee developer onboarding plugin for Realm Plus: an apps page for signed-in
6
6
  * developers, teams through Apigee app groups, reviewer approvals, and the API access protocol
7
7
  * that API reference pages follow.
8
8
  */
package/lib/plugin.js CHANGED
@@ -1 +1 @@
1
- import{createRequire as A}from"node:module";import{createInlineEntity as g,defineContentPlugin as f,isPlanClaimGranted as I,runtimeFile as _,runtimeTemplate as G}from"@redocly/framework/plugin";import{APIGEE_CONFIG_SCHEMA as b,APIGEE_PLAN_CLAIM as S,readApigeeSettings as v,resolveApigeeSettings as y}from"./config.js";import{APIGEE_PLUGIN_ID as C,APIGEE_PRODUCTS_ENTITY_KEY as L,APIGEE_PRODUCTS_VALUE_KEY as D,APIGEE_ROUTES as e,APIGEE_TEMPLATE_ID as c}from"./constants.js";import{APIGEE_TEMPLATE_ID as w}from"./constants.js";const{version:R}=A(import.meta.url)("../package.json");function t(a,i,r){return{path:a,method:r,auth:"manual",handler:{filePath:"./server/routes.ts",importer:import.meta.url,exportName:i}}}const h=[t(e.meta,"meta","GET"),t(e.access,"access","GET"),t(e.apps,"listApps","GET"),t(e.apps,"createApp","POST"),t(e.app,"updateApp",["PUT","PATCH"]),t(e.app,"deleteApp",["DELETE"]),t(e.appKeys,"createKey","POST"),t(e.appKey,"updateKey",["PUT","PATCH"]),t(e.appKey,"deleteKey",["DELETE"]),t(e.teams,"listTeams","GET"),t(e.teams,"createTeam","POST"),t(e.team,"getTeam","GET"),t(e.team,"updateTeam",["PUT","PATCH"]),t(e.team,"deleteTeam",["DELETE"]),t(e.teamMembers,"addTeamMember","POST"),t(e.teamMember,"updateTeamMember",["PUT","PATCH"]),t(e.teamMember,"removeTeamMember",["DELETE"]),t(e.adminRequests,"adminRequests","GET"),t(e.adminRequestApprove,"adminApprove","POST"),t(e.adminRequestRevoke,"adminRevoke","POST"),t(e.adminApps,"adminApps","GET"),t(e.adminAudit,"adminAudit","GET")],O={code:"configuration/ignored",message:"Developer onboarding is not in this project's plan, so the Apigee pages are skipped."};function M(a){return{accountLinks:[{label:a.title,link:a.basePath}],apiAccessRoute:e.access}}function K(a){var i,r,l;const d=a.routes.metadata("apiId"),T=a.routes.metadata("title"),E=a.routes.metadata("type"),p={},m={};for(const{slug:n,canonicalSlug:P}of a.routes.all()){if(E[n]!=="openapi"||P!=="")continue;const s=d[n],u=T[n],o=typeof u=="string"?u.trim():"";typeof s=="string"&&s!==""&&((i=p[s])!==null&&i!==void 0||(p[s]={slug:n,title:o||s})),o&&((r=m[l=o.toLowerCase()])!==null&&r!==void 0||(m[l]={slug:n,title:o}))}return{byApiId:p,byTitle:m}}const U=f({id:C,version:R,configSchema:b,templates:{[c]:G(_("./client/ApigeeTemplate.tsx",import.meta.url))},server:{routes:h},content:{filter:{match:()=>!1},extractAll(a){const i=y(a.config);return i?{routes:[{routeId:"apps",slug:i.basePath,template:c,wildcardPrefix:!0,metadata:{title:i.title,excludeFromSearch:!0}}]}:null}},finalize(a){const i=v(a.config);if(!i)return{};if(!I(a.config,S))return{problems:[O]};const r=g({[D]:K(a)},{stableKey:L,metadata:{routeSlug:i.basePath}});return{appData:{apigee:M(i)},entities:[r]}}});var F=U;export{w as APIGEE_TEMPLATE_ID,F as default};
1
+ import{createRequire as A}from"node:module";import{createInlineEntity as g,defineContentPlugin as f,isPlanClaimGranted as I,runtimeFile as _,runtimeTemplate as G}from"@redocly/framework/plugin";import{APIGEE_CONFIG_SCHEMA as b,APIGEE_PLAN_CLAIM as S,readApigeeSettings as v,resolveApigeeSettings as y}from"./config.js";import{APIGEE_PLUGIN_ID as C,APIGEE_PRODUCTS_ENTITY_KEY as L,APIGEE_PRODUCTS_VALUE_KEY as D,APIGEE_ROUTES as e,APIGEE_TEMPLATE_ID as c}from"./constants.js";import{APIGEE_TEMPLATE_ID as w}from"./constants.js";const{version:R}=A(import.meta.url)("../package.json");function t(a,i,r){return{path:a,method:r,auth:"manual",handler:{filePath:"./server/routes.ts",importer:import.meta.url,exportName:i}}}const h=[t(e.meta,"meta","GET"),t(e.access,"access","GET"),t(e.apps,"listApps","GET"),t(e.apps,"createApp","POST"),t(e.app,"updateApp",["PUT","PATCH"]),t(e.app,"deleteApp",["DELETE"]),t(e.appKeys,"createKey","POST"),t(e.appKey,"updateKey",["PUT","PATCH"]),t(e.appKey,"deleteKey",["DELETE"]),t(e.teams,"listTeams","GET"),t(e.teams,"createTeam","POST"),t(e.team,"getTeam","GET"),t(e.team,"updateTeam",["PUT","PATCH"]),t(e.team,"deleteTeam",["DELETE"]),t(e.teamMembers,"addTeamMember","POST"),t(e.teamMember,"updateTeamMember",["PUT","PATCH"]),t(e.teamMember,"removeTeamMember",["DELETE"]),t(e.adminRequests,"adminRequests","GET"),t(e.adminRequestApprove,"adminApprove","POST"),t(e.adminRequestRevoke,"adminRevoke","POST"),t(e.adminApps,"adminApps","GET"),t(e.adminAudit,"adminAudit","GET")],O={code:"configuration/ignored",message:"Developer onboarding is not in this project's plan, so the Apigee pages are skipped."};function M(a){return{accountLinks:[{label:a.title,link:a.basePath,icon:"key"}],apiAccessRoute:e.access}}function K(a){var i,r,l;const d=a.routes.metadata("apiId"),T=a.routes.metadata("title"),E=a.routes.metadata("type"),p={},m={};for(const{slug:n,canonicalSlug:P}of a.routes.all()){if(E[n]!=="openapi"||P!=="")continue;const s=d[n],u=T[n],o=typeof u=="string"?u.trim():"";typeof s=="string"&&s!==""&&((i=p[s])!==null&&i!==void 0||(p[s]={slug:n,title:o||s})),o&&((r=m[l=o.toLowerCase()])!==null&&r!==void 0||(m[l]={slug:n,title:o}))}return{byApiId:p,byTitle:m}}const U=f({id:C,version:R,configSchema:b,templates:{[c]:G(_("./client/ApigeeTemplate.tsx",import.meta.url))},server:{routes:h},content:{filter:{match:()=>!1},extractAll(a){const i=y(a.config);return i?{routes:[{routeId:"apps",slug:i.basePath,template:c,wildcardPrefix:!0,metadata:{title:i.title,excludeFromSearch:!0}}]}:null}},finalize(a){const i=v(a.config);if(!i)return{};if(!I(a.config,S))return{problems:[O]};const r=g({[D]:K(a)},{stableKey:L,metadata:{routeSlug:i.basePath}});return{appData:{apigee:M(i)},entities:[r]}}});var F=U;export{w as APIGEE_TEMPLATE_ID,F as default};
@@ -70,8 +70,6 @@ export declare class ApigeeService {
70
70
  private withRole;
71
71
  /** The teams whose AppGroup lists the viewer, read from every AppGroup of the organization. */
72
72
  listMyTeams(): Promise<Team[]>;
73
- /** The teams in the viewer's KV index whose AppGroup still lists them, without reading every AppGroup. */
74
- private indexedTeams;
75
73
  private requireTeam;
76
74
  getTeam(teamId: string): Promise<Team>;
77
75
  createTeam(input: TeamInput): Promise<Team>;
@@ -83,6 +81,11 @@ export declare class ApigeeService {
83
81
  removeMember(teamId: string, email: string): Promise<Team>;
84
82
  private syncAppGroup;
85
83
  private ownerOf;
84
+ /**
85
+ * AppGroup display names by AppGroup name; groups without one are left out. Empty when teams
86
+ * are off or the AppGroups cannot be read.
87
+ */
88
+ private teamNames;
86
89
  /** Requests for the products the viewer may review, newest first. */
87
90
  listRequests(): Promise<AccessRequest[]>;
88
91
  decideRequest(requestId: string, action: KeyAction, note?: string): Promise<AuditEntry>;
@@ -1 +1 @@
1
- var u=function(s,e,i,t){function r(n){return n instanceof i?n:new i(function(o){o(n)})}return new(i||(i=Promise))(function(n,o){function a(l){try{c(t.next(l))}catch(p){o(p)}}function d(l){try{c(t.throw(l))}catch(p){o(p)}}function c(l){l.done?n(l.value):r(l.value).then(a,d)}c((t=t.apply(s,e||[])).next())})},x=function(s,e,i,t){if(i==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!t:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?t:i==="a"?t.call(s):t?t.value:e.get(s)},B=function(s,e,i,t,r){if(t==="m")throw new TypeError("Private method is not writable");if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t==="a"?r.call(s,i):r?r.value=i:e.set(s,i),i},D=function(s,e){var i={};for(var t in s)Object.prototype.hasOwnProperty.call(s,t)&&e.indexOf(t)<0&&(i[t]=s[t]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(s);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(s,t[r])&&(i[t[r]]=s[t[r]]);return i},R,j;import{createHash as ie,randomBytes as re}from"node:crypto";import{isApiProductOffered as C}from"../config.js";import{APIGEE_DEFAULT_KEY_LIFETIME_SECONDS as $,APIGEE_DISPLAY_NAME_ATTRIBUTE as I,APIGEE_NOTES_ATTRIBUTE as k,APIGEE_PRODUCTS_ENTITY_KEY as ne,APIGEE_PRODUCTS_VALUE_KEY as oe,APIGEE_TEAM_MEMBERS_ATTRIBUTE as F}from"../constants.js";import{maskKey as L}from"../contract.js";import{ApigeeApiError as se}from"./client.js";import{attributesToRecord as O,recordToAttributes as K,toApiProduct as V,toApp as N,toCredential as z}from"./mappers.js";import{ApigeeStore as ae,normalizeEmail as _}from"./store.js";class v extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ValidationError"})}}class S extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ForbiddenError"})}}class b extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"NotFoundError"})}}const de={byApiId:{},byTitle:{}},E={none:0,read:1,triage:2,write:3,maintain:4,admin:5};function T(s){return E[s]>=E.triage}function G(s){return E[s]>=E.maintain}function le(s,e){return E[s]>=E[e]?s:e}const ce=/^[A-Za-z0-9._$ -]{1,100}$/,ue=new Set(["teams","admin"]),pe=/^[a-z0-9][a-z0-9-]{1,62}$/,P=2e3,me=2048;function he(s){return Buffer.from(JSON.stringify(s)).toString("base64url")}function Y(s){return ie("sha256").update(s).digest("base64url")}function fe(s){try{const e=JSON.parse(Buffer.from(s,"base64url").toString());if(!e||typeof e.appId!="string"||typeof e.keyDigest!="string"||typeof e.apiProduct!="string"||!e.owner)throw new Error("shape");return e}catch{throw new v("Unknown request")}}function ve(s){return s.trim().toLowerCase().split(/[^a-z0-9]/).filter(Boolean).join("-").slice(0,63)}function we(s){var e,i,t,r;const n=((i=s.name)!==null&&i!==void 0?i:"").trim().split(/\s+/).filter(Boolean),o=(r=(e=((t=s.email)!==null&&t!==void 0?t:"").split("@")[0])===null||e===void 0?void 0:e.split(/[.-]/))!==null&&r!==void 0?r:[];return{firstName:n[0]||o[0]||"Unknown",lastName:n.slice(1).join(" ")||o[1]||"Unknown"}}function H(s){return re(s).toString("base64url")}function J(s,e){const i=O(s.attributes)[F];if(!i)return[];try{const t=JSON.parse(i);return Array.isArray(t)?t.flatMap(r=>{var n,o;if(typeof r?.developer!="string")return[];const a=_(r.developer),d=e?.members.find(c=>c.email===a);return[{email:a,role:!((n=r.roles)===null||n===void 0)&&n.includes("owner")?"owner":"member",addedAt:(o=d?.addedAt)!==null&&o!==void 0?o:Number(s.createdAt)||0}]}):[]}catch{return[]}}function U(s,e){var i,t,r,n;const o=J(s,e);return{id:s.name,name:s.displayName||s.name,description:(t=O(s.attributes)[k])!==null&&t!==void 0?t:"",createdAt:Number(s.createdAt)||e?.createdAt||Date.now(),createdBy:(n=(r=e?.createdBy)!==null&&r!==void 0?r:(i=o.find(a=>a.role==="owner"))===null||i===void 0?void 0:i.email)!==null&&n!==void 0?n:"",members:o}}function W(s){return JSON.stringify(s.map(e=>({developer:e.email,roles:[e.role]})))}class Te{constructor(e,i,t,r,n){Object.defineProperty(this,"settings",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"viewer",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),R.set(this,void 0),j.set(this,void 0),this.store=new ae(r.kv)}get email(){return _(this.viewer.email)}apigeeProducts(){var e;return B(this,R,(e=x(this,R,"f"))!==null&&e!==void 0?e:this.client.listApiProducts(),"f"),x(this,R,"f")}productPages(){var e;return B(this,j,(e=x(this,j,"f"))!==null&&e!==void 0?e:this.ctx.entities.load(ne).then(i=>{var t;return(t=i?.[oe])!==null&&t!==void 0?t:de}),"f"),x(this,j,"f")}pageFor(e,i){const t=i.byApiId[e.name];if(t||!this.settings.apiProducts.matchByTitle)return t;const r=(e.displayName||e.name).trim().toLowerCase();return i.byTitle[r]}roleFor(e,i,t){const r=t.find(a=>a.name===e),n=r?this.pageFor(r,i):i.byApiId[e],o=n?this.ctx.roleForSlug(n.slug):"none";return le(o,this.ctx.roleForSlug(this.settings.basePath))}approvalSummary(){return u(this,void 0,void 0,function*(){if(!this.settings.approvalsEnabled)return{enabled:!1,canView:!1,canDecide:!1};const e=this.ctx.roleForSlug(this.settings.basePath);if(G(e))return{enabled:!0,canView:!0,canDecide:!0};const[i,t]=yield Promise.all([this.apigeeProducts(),this.productPages()]);let r=T(e),n=!1;for(const o of i){if(!C(this.settings,o.name))continue;const a=this.roleFor(o.name,t,i);r||(r=T(a)),n||(n=G(a))}return{enabled:!0,canView:r,canDecide:n}})}canReview(){return u(this,void 0,void 0,function*(){return(yield this.approvalSummary()).canView})}listApiProducts(){return u(this,void 0,void 0,function*(){const[e,i]=yield Promise.all([this.apigeeProducts(),this.productPages()]),t=[];for(const r of e){if(!C(this.settings,r.name))continue;const n=this.pageFor(r,i);if(n){if(!this.ctx.isSlugVisible(n.slug))continue;t.push(V(r,n))}else this.settings.apiProducts.allowOutsideCatalog&&t.push(V(r))}return t.sort((r,n)=>r.name.localeCompare(n.name))})}assertProductsAllowed(e){return u(this,void 0,void 0,function*(){const i=Z(e),t=yield this.listApiProducts(),r=i.filter(o=>!t.some(a=>a.id===o));if(r.length>0)throw new v(`Unknown API product: ${r.join(", ")}`);const n=new Map(t.map(o=>[o.id,o]));return[...new Set(i)].flatMap(o=>{const a=n.get(o);return a?[a]:[]})})}resolveOwner(e){return u(this,void 0,void 0,function*(){if(!e)return{owner:{kind:"developer",email:this.email},path:{kind:"developer",email:this.email}};const i=yield this.requireTeam(e);return{owner:{kind:"team",teamId:i.id},path:{kind:"appgroup",name:i.id}}})}ownerPath(e){return e.kind==="developer"?{kind:"developer",email:e.email}:{kind:"appgroup",name:e.teamId}}withDecisions(e){return u(this,void 0,void 0,function*(){const i=[];for(const n of e)for(const o of n.credentials)for(const a of o.apiProducts)i.push({owner:n.owner,appId:n.id,consumerKey:o.consumerKey,apiProduct:a.id});const t=yield this.store.getDecisions(i);let r=0;for(const n of e)for(const o of n.credentials)for(const a of o.apiProducts){const d=t[r++];d&&(a.decision=d)}return e})}listApps(){return u(this,void 0,void 0,function*(){return this.appsOf(yield this.listMyTeams())})}appsOf(e){return u(this,void 0,void 0,function*(){const[i,...t]=yield Promise.all([this.client.listApps({kind:"developer",email:this.email}),...e.map(n=>this.client.listApps({kind:"appgroup",name:n.id}))]),r=i.map(n=>N(n,{kind:"developer",email:this.email}));return e.forEach((n,o)=>{r.push(...t[o].map(a=>N(a,{kind:"team",teamId:n.id})))}),this.withDecisions(r.sort((n,o)=>{var a,d;return((a=o.createdAt)!==null&&a!==void 0?a:0)-((d=n.createdAt)!==null&&d!==void 0?d:0)}))})}createApp(e){return u(this,void 0,void 0,function*(){var i;const t=Q(e.name),r=g(e.description,P,"description"),n=ee(e.callbackUrl),o=g(e.note,P,"note"),a=yield this.assertProductsAllowed((i=e.apiProducts)!==null&&i!==void 0?i:[]),{owner:d,path:c}=yield this.resolveOwner(e.teamId);if(d.kind==="developer"&&(yield this.client.ensureDeveloper(Object.assign({email:this.email,userName:this.email},we(this.viewer)))),yield this.client.getApp(c,t))throw new v(`An app named "${t}" already exists`);const l=yield this.client.createApp(c,Object.assign(Object.assign({name:t,apiProducts:a.map(h=>h.id)},n?{callbackUrl:n}:{}),{keyExpiresIn:String($*(d.kind==="developer"?1e3:1)),attributes:K({[I]:t,[k]:r??""})})),p=N(l,d);return yield this.recordRequestNotes(d,p.id,p.credentials,a,o),p})}updateApp(e,i,t){return u(this,void 0,void 0,function*(){var r;const{owner:n,path:o}=yield this.resolveOwner(e),a=yield this.client.getApp(o,i);if(!a)throw new b("App not found");const d=O(a.attributes);t.name!==void 0&&(d[I]=Q(t.name)),t.description!==void 0&&(d[k]=(r=g(t.description,P,"description"))!==null&&r!==void 0?r:"");const c=t.callbackUrl===void 0?a.callbackUrl:ee(t.callbackUrl),l=yield this.client.updateApp(o,i,Object.assign({attributes:K(d)},c!==void 0?{callbackUrl:c}:{}));return N(l,n)})}deleteApp(e,i){return u(this,void 0,void 0,function*(){const{path:t}=yield this.resolveOwner(e);if(!(yield this.client.getApp(t,i)))throw new b("App not found");yield this.client.deleteApp(t,i)})}createKey(e,i,t){return u(this,void 0,void 0,function*(){var r;const{owner:n,path:o}=yield this.resolveOwner(e);if(!(yield this.client.getApp(o,i)))throw new b("App not found");const a=yield this.assertProductsAllowed((r=t.apiProducts)!==null&&r!==void 0?r:[]),d=g(t.note,P,"note"),c=yield this.client.createKey(o,i,{consumerKey:H(24),consumerSecret:H(24),expiresInSeconds:$}),l=a.length>0?yield this.client.addKeyProducts(o,i,c.consumerKey,a.map(h=>h.id),c.attributes):c,p=z(l);return yield this.recordRequestNotes(n,i,[p],a,d),p})}updateKeyProducts(e,i,t,r){return u(this,void 0,void 0,function*(){var n,o;const{owner:a,path:d}=yield this.resolveOwner(e),c=yield this.client.getKey(d,i,t);if(!c)throw new b("Key not found");const l=new Set(((n=c.apiProducts)!==null&&n!==void 0?n:[]).map(y=>y.apiproduct)),p=Z((o=r.apiProducts)!==null&&o!==void 0?o:[]),h=yield this.assertProductsAllowed(p.filter(y=>!l.has(y))),w=g(r.note,P,"note"),m=[...l].filter(y=>!p.includes(y));let f=c;h.length>0&&(f=yield this.client.addKeyProducts(d,i,t,h.map(y=>y.id),c.attributes));for(const y of m)yield this.client.removeKeyProduct(d,i,t,y),yield this.store.deleteRequestNote({owner:a,appId:i,consumerKey:t,apiProduct:y}),yield this.store.deleteDecision({owner:a,appId:i,consumerKey:t,apiProduct:y});const A=m.length>0?yield this.client.getKey(d,i,t):null,q=z(A??f);return yield this.recordRequestNotes(a,i,[q],h,w),q})}deleteKey(e,i,t){return u(this,void 0,void 0,function*(){const{path:r}=yield this.resolveOwner(e);if(!(yield this.client.getKey(r,i,t)))throw new b("Key not found");yield this.client.deleteKey(r,i,t)})}recordRequestNotes(e,i,t,r,n){return u(this,void 0,void 0,function*(){const o=r.filter(d=>d.approvalType==="manual");if(o.length===0)return;const a=Date.now();for(const d of t)for(const c of o)yield this.store.putRequestNote({owner:e,appId:i,consumerKey:d.consumerKey,apiProduct:c.id},Object.assign({requestedBy:this.email,requestedAt:a},n?{note:n}:{}))})}getAccess(e){return u(this,void 0,void 0,function*(){const i=yield this.appsOf(yield this.indexedTeams()),t=Date.now(),r=o=>i.flatMap(a=>a.credentials.filter(d=>a.status!=="revoked"&&d.status==="approved"&&(d.expiresAt===null||d.expiresAt>t)&&d.apiProducts.some(c=>c.id===e&&c.status===o)).map(d=>({app:a,credential:d}))),n=r("approved").sort((o,a)=>o.app.owner.kind===a.app.owner.kind?0:o.app.owner.kind==="developer"?-1:1);if(n.length>0){const{credential:o}=n[0];return{status:"APPROVED",link:this.settings.basePath,requestValues:{security:{default:Object.assign({client_id:o.consumerKey},o.consumerSecret?{client_secret:o.consumerSecret}:{})}}}}return{status:r("pending").length>0?"PENDING":"NONE",link:`${this.settings.basePath}?createApp&apiProduct=${encodeURIComponent(e)}`}})}assertTeams(){if(!this.settings.teamsEnabled)throw new S("Teams are disabled")}withRole(e){const i=e.members.find(t=>t.email===this.email);return i?Object.assign(Object.assign({},e),{myRole:i.role}):e}listMyTeams(){return u(this,void 0,void 0,function*(){var e,i;if(!this.settings.teamsEnabled)return[];let t;try{t=yield this.client.listAppGroups()}catch(o){return(e=this.logger)===null||e===void 0||e.debug(`apigee: AppGroups unavailable: ${String(o)}`),[]}const r=new Map((yield this.store.listTeamsOf(this.email)).map(o=>[o.id,o])),n=[];for(const o of t){if(!J(o).some(d=>d.email===this.email))continue;const a=U(o,(i=r.get(o.name))!==null&&i!==void 0?i:yield this.store.getTeam(o.name));r.has(a.id)||(yield this.store.putTeam(a)),n.push(this.withRole(a))}return n.sort((o,a)=>o.name.localeCompare(a.name))})}indexedTeams(){return u(this,void 0,void 0,function*(){if(!this.settings.teamsEnabled)return[];const e=yield this.store.listTeamsOf(this.email);return(yield Promise.all(e.map(t=>this.client.getAppGroup(t.id)))).flatMap((t,r)=>{const n=t?this.withRole(U(t,e[r])):null;return n?.myRole?[n]:[]})})}requireTeam(e,i){return u(this,void 0,void 0,function*(){this.assertTeams();const[t,r]=yield Promise.all([this.client.getAppGroup(e),this.store.getTeam(e)]);if(!t)throw new b("Team not found");const n=this.withRole(U(t,r));if(!n.myRole)throw new S("You are not a member of this team");if(i==="owner"&&n.myRole!=="owner")throw new S("Only a team owner can do this");return n})}getTeam(e){return u(this,void 0,void 0,function*(){return this.requireTeam(e)})}createTeam(e){return u(this,void 0,void 0,function*(){var i;this.assertTeams();const t=g(e.name,100,"name");if(!t)throw new v("A team needs a name");const r=ve(t);if(!pe.test(r))throw new v("The team name needs at least two letters or digits");const n=(i=g(e.description,P,"description"))!==null&&i!==void 0?i:"";if((yield this.store.getTeam(r))||(yield this.client.getAppGroup(r)))throw new v(`A team named "${t}" already exists`);const o=[{email:this.email,role:"owner",addedAt:Date.now()}];yield this.client.createAppGroup({name:r,displayName:t,attributes:K({[k]:n,[F]:W(o)})});const a={id:r,name:t,description:n,createdAt:Date.now(),createdBy:this.email,members:o};return yield this.store.putTeam(a),this.withRole(a)})}updateTeam(e,i){return u(this,void 0,void 0,function*(){var t;const r=yield this.requireTeam(e,"owner"),n=g(i.name,100,"name")||r.name,o=(t=g(i.description,P,"description"))!==null&&t!==void 0?t:r.description,a=Object.assign(Object.assign({},M(r)),{name:n,description:o});return yield this.syncAppGroup(a),yield this.store.putTeam(a),this.withRole(a)})}deleteTeam(e){return u(this,void 0,void 0,function*(){const i=yield this.requireTeam(e,"owner"),t={kind:"appgroup",name:i.id};for(const r of yield this.client.listApps(t))yield this.client.deleteApp(t,r.name);try{yield this.client.deleteAppGroup(i.id)}catch(r){if(!(r instanceof se&&r.status===404))throw r}yield this.store.deleteTeam(i.id)})}addMember(e,i){return u(this,void 0,void 0,function*(){const t=yield this.requireTeam(e,"owner"),r=ye(i.email),n=te(i.role);if(t.members.some(a=>a.email===r))throw new v(`${r} is already a member`);const o=Object.assign(Object.assign({},M(t)),{members:[...t.members,{email:r,role:n,addedAt:Date.now()}]});return yield this.syncAppGroup(o),yield this.store.putTeam(o),this.withRole(o)})}setMemberRole(e,i,t){return u(this,void 0,void 0,function*(){const r=yield this.requireTeam(e,"owner"),n=_(i);if(!r.members.some(d=>d.email===n))throw new b("Member not found");const o=r.members.map(d=>d.email===n?Object.assign(Object.assign({},d),{role:te(t)}):d);X(o);const a=Object.assign(Object.assign({},M(r)),{members:o});return yield this.syncAppGroup(a),yield this.store.putTeam(a),this.withRole(a)})}removeMember(e,i){return u(this,void 0,void 0,function*(){const t=yield this.requireTeam(e),r=_(i);if(t.myRole!=="owner"&&r!==this.email)throw new S("Only a team owner can remove other members");if(!t.members.some(a=>a.email===r))throw new b("Member not found");const n=t.members.filter(a=>a.email!==r);X(n);const o=Object.assign(Object.assign({},M(t)),{members:n});return yield this.syncAppGroup(o),yield this.store.putTeam(o),this.withRole(o)})}syncAppGroup(e){return u(this,void 0,void 0,function*(){const i=yield this.client.getAppGroup(e.id);if(!i)throw new b("Team not found");const t=Object.assign(Object.assign({},O(i.attributes)),{[k]:e.description,[F]:W(e.members)});yield this.client.updateAppGroup(e.id,Object.assign(Object.assign({},i),{name:e.id,displayName:e.name,attributes:K(t)}))})}ownerOf(e,i){return u(this,void 0,void 0,function*(){var t;if(e.appGroup)return{kind:"team",teamId:e.appGroup};if(e.developerEmail)return{kind:"developer",email:_(e.developerEmail)};if(e.developerId){let r=i.get(e.developerId);if(r||(r=(t=yield this.client.getDeveloper(e.developerId))===null||t===void 0?void 0:t.email,r&&i.set(e.developerId,r)),r)return{kind:"developer",email:_(r)}}return null})}listRequests(){return u(this,void 0,void 0,function*(){var e,i;const[t,r,n]=yield Promise.all([this.client.listOrganizationApps(),this.apigeeProducts(),this.productPages()]),o=new Map,a=[];for(const d of t){const c=((e=d.credentials)!==null&&e!==void 0?e:[]).flatMap(h=>{var w;return((w=h.apiProducts)!==null&&w!==void 0?w:[]).filter(m=>m.status==="pending").filter(m=>T(this.roleFor(m.apiproduct,n,r))).map(m=>({credential:h,apiProduct:m.apiproduct}))});if(c.length===0)continue;const l=yield this.ownerOf(d,o);if(!l)continue;const p=O(d.attributes)[I];for(const{credential:h,apiProduct:w}of c){const{consumerKey:m}=h,f=yield this.store.getRequestNote({owner:l,appId:d.name,consumerKey:m,apiProduct:w});a.push(Object.assign(Object.assign(Object.assign(Object.assign({id:he({owner:l,appId:d.name,keyDigest:Y(m),apiProduct:w}),owner:l},f?{requestedBy:f.requestedBy}:{}),{appId:d.name,appName:p||d.name,consumerKey:L(m),apiProduct:w}),f?.note?{note:f.note}:{}),{requestedAt:(i=f?.requestedAt)!==null&&i!==void 0?i:Number(h.issuedAt)||null,canDecide:G(this.roleFor(w,n,r))}))}}return a.sort((d,c)=>{var l,p;return((l=c.requestedAt)!==null&&l!==void 0?l:0)-((p=d.requestedAt)!==null&&p!==void 0?p:0)})})}decideRequest(e,i,t){return u(this,void 0,void 0,function*(){var r;const n=fe(e),{keyDigest:o}=n,a=D(n,["keyDigest"]),[d,c]=yield Promise.all([this.apigeeProducts(),this.productPages()]);if(!G(this.roleFor(a.apiProduct,c,d)))throw new S("You cannot decide requests for this API product");const l=g(t,P,"note"),p=this.ownerPath(a.owner),h=yield this.client.getApp(p,a.appId);if(!h)throw new b("App not found");const w=(r=h.credentials)===null||r===void 0?void 0:r.find(A=>Y(A.consumerKey)===o);if(!w)throw new b("Key not found");const m=Object.assign(Object.assign({},a),{consumerKey:w.consumerKey});yield this.client.setKeyProductStatus(p,m.appId,m.consumerKey,m.apiProduct,i),yield this.store.deleteRequestNote(m);const f=Object.assign({action:i,actor:this.email,at:Date.now()},l?{note:l}:{});return yield this.store.putDecision(m,f),this.store.appendAudit(Object.assign({at:f.at,actor:this.email,action:i,owner:m.owner,appId:m.appId,appName:O(h.attributes)[I]||h.name,consumerKey:L(m.consumerKey),apiProduct:m.apiProduct},l?{note:l}:{}))})}listAllApps(){return u(this,void 0,void 0,function*(){var e;const[i,t,r]=yield Promise.all([this.client.listOrganizationApps(),this.apigeeProducts(),this.productPages()]),n=T(this.ctx.roleForSlug(this.settings.basePath)),o=new Map,a=[];for(const d of i){if(!(n||((e=d.credentials)!==null&&e!==void 0?e:[]).some(m=>{var f;return((f=m.apiProducts)!==null&&f!==void 0?f:[]).some(A=>T(this.roleFor(A.apiproduct,r,t)))})))continue;const l=yield this.ownerOf(d,o);if(!l)continue;const p=N(d,l),{credentials:h}=p,w=D(p,["credentials"]);a.push(Object.assign(Object.assign({},w),{credentials:h.map(m=>{var{consumerKey:f,consumerSecret:A}=m,q=D(m,["consumerKey","consumerSecret"]);return q})}))}return a.sort((d,c)=>{var l,p;return((l=c.createdAt)!==null&&l!==void 0?l:0)-((p=d.createdAt)!==null&&p!==void 0?p:0)})})}listAudit(){return u(this,void 0,void 0,function*(){const[e,i,t]=yield Promise.all([this.store.listAudit(),this.apigeeProducts(),this.productPages()]);return e.filter(r=>T(this.roleFor(r.apiProduct,t,i)))})}}R=new WeakMap,j=new WeakMap;function M(s){const{myRole:e}=s;return D(s,["myRole"])}function X(s){if(!s.some(e=>e.role==="owner"))throw new v("A team needs at least one owner")}function Z(s){if(!Array.isArray(s)||s.some(e=>typeof e!="string"))throw new v("apiProducts must be a list of product names");return s}function Q(s){if(typeof s!="string"||!ce.test(s.trim()))throw new v("An app name has 1 to 100 letters, digits, spaces, dots, dashes or underscores");const e=s.trim();if(ue.has(e))throw new v(`An app cannot be named "${e}"`);return e}function g(s,e,i){if(s==null)return;if(typeof s!="string")throw new v(`${i} must be text`);const t=s.trim();if(t.length>e)throw new v(`${i} is longer than ${e} characters`);return t}function ee(s){const e=g(s,me,"callbackUrl");if(!e)return e===""?"":void 0;for(const i of e.split(","))try{new URL(i.trim())}catch{throw new v(`"${i.trim()}" is not a valid callback URL`)}return e}function ye(s){const e=typeof s=="string"?s.trim():"",i=e.indexOf("@"),t=e.slice(i+1);if(i<1||/\s/.test(e)||!t.includes(".")||t.startsWith(".")||t.endsWith("."))throw new v("Enter a valid email address");return _(e)}function te(s){if(s===void 0)return"member";if(s!=="owner"&&s!=="member")throw new v("Unknown role");return s}export{Te as ApigeeService,S as ForbiddenError,b as NotFoundError,v as ValidationError};
1
+ var u=function(s,e,i,t){function r(o){return o instanceof i?o:new i(function(n){n(o)})}return new(i||(i=Promise))(function(o,n){function a(p){try{l(t.next(p))}catch(c){n(c)}}function d(p){try{l(t.throw(p))}catch(c){n(c)}}function l(p){p.done?o(p.value):r(p.value).then(a,d)}l((t=t.apply(s,e||[])).next())})},I=function(s,e,i,t){if(i==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!t:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?t:i==="a"?t.call(s):t?t.value:e.get(s)},$=function(s,e,i,t,r){if(t==="m")throw new TypeError("Private method is not writable");if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t==="a"?r.call(s,i):r?r.value=i:e.set(s,i),i},D=function(s,e){var i={};for(var t in s)Object.prototype.hasOwnProperty.call(s,t)&&e.indexOf(t)<0&&(i[t]=s[t]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(s);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(s,t[r])&&(i[t[r]]=s[t[r]]);return i},R,j;import{createHash as ne,randomBytes as oe}from"node:crypto";import{isApiProductOffered as C}from"../config.js";import{APIGEE_DEFAULT_KEY_LIFETIME_SECONDS as L,APIGEE_DISPLAY_NAME_ATTRIBUTE as x,APIGEE_NOTES_ATTRIBUTE as k,APIGEE_PRODUCTS_ENTITY_KEY as se,APIGEE_PRODUCTS_VALUE_KEY as ae,APIGEE_TEAM_MEMBERS_ATTRIBUTE as F}from"../constants.js";import{maskKey as V}from"../contract.js";import{ApigeeApiError as de}from"./client.js";import{attributesToRecord as O,recordToAttributes as K,toApiProduct as z,toApp as S,toCredential as Y}from"./mappers.js";import{ApigeeStore as le,normalizeEmail as _}from"./store.js";class y extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ValidationError"})}}class q extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"ForbiddenError"})}}class b extends Error{constructor(){super(...arguments),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"NotFoundError"})}}const ce={byApiId:{},byTitle:{}},E={none:0,read:1,triage:2,write:3,maintain:4,admin:5};function T(s){return E[s]>=E.triage}function M(s){return E[s]>=E.maintain}function ue(s,e){return E[s]>=E[e]?s:e}const pe=/^[A-Za-z0-9._$ -]{1,100}$/,me=new Set(["teams","admin"]),he=/^[a-z0-9][a-z0-9-]{1,62}$/,P=2e3,fe=2048;function ve(s){return Buffer.from(JSON.stringify(s)).toString("base64url")}function H(s){return ne("sha256").update(s).digest("base64url")}function ye(s){try{const e=JSON.parse(Buffer.from(s,"base64url").toString());if(!e||typeof e.appId!="string"||typeof e.keyDigest!="string"||typeof e.apiProduct!="string"||!e.owner)throw new Error("shape");return e}catch{throw new y("Unknown request")}}function we(s){return s.trim().toLowerCase().split(/[^a-z0-9]/).filter(Boolean).join("-").slice(0,63)}function ge(s){var e,i,t,r;const o=((i=s.name)!==null&&i!==void 0?i:"").trim().split(/\s+/).filter(Boolean),n=(r=(e=((t=s.email)!==null&&t!==void 0?t:"").split("@")[0])===null||e===void 0?void 0:e.split(/[.-]/))!==null&&r!==void 0?r:[];return{firstName:o[0]||n[0]||"Unknown",lastName:o.slice(1).join(" ")||n[1]||"Unknown"}}function J(s){return oe(s).toString("base64url")}function W(s,e){const i=O(s.attributes)[F];if(!i)return[];try{const t=JSON.parse(i);return Array.isArray(t)?t.flatMap(r=>{var o,n;if(typeof r?.developer!="string")return[];const a=_(r.developer),d=e?.members.find(l=>l.email===a);return[{email:a,role:!((o=r.roles)===null||o===void 0)&&o.includes("owner")?"owner":"member",addedAt:(n=d?.addedAt)!==null&&n!==void 0?n:Number(s.createdAt)||0}]}):[]}catch{return[]}}function X(s,e){var i,t,r,o;const n=W(s,e);return{id:s.name,name:s.displayName||s.name,description:(t=O(s.attributes)[k])!==null&&t!==void 0?t:"",createdAt:Number(s.createdAt)||e?.createdAt||Date.now(),createdBy:(o=(r=e?.createdBy)!==null&&r!==void 0?r:(i=n.find(a=>a.role==="owner"))===null||i===void 0?void 0:i.email)!==null&&o!==void 0?o:"",members:n}}function Z(s){return JSON.stringify(s.map(e=>({developer:e.email,roles:[e.role]})))}class Re{constructor(e,i,t,r,o){Object.defineProperty(this,"settings",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"viewer",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"ctx",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:o}),Object.defineProperty(this,"store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),R.set(this,void 0),j.set(this,void 0),this.store=new le(r.kv)}get email(){return _(this.viewer.email)}apigeeProducts(){var e;return $(this,R,(e=I(this,R,"f"))!==null&&e!==void 0?e:this.client.listApiProducts(),"f"),I(this,R,"f")}productPages(){var e;return $(this,j,(e=I(this,j,"f"))!==null&&e!==void 0?e:this.ctx.entities.load(se).then(i=>{var t;return(t=i?.[ae])!==null&&t!==void 0?t:ce}),"f"),I(this,j,"f")}pageFor(e,i){const t=i.byApiId[e.name];if(t||!this.settings.apiProducts.matchByTitle)return t;const r=(e.displayName||e.name).trim().toLowerCase();return i.byTitle[r]}roleFor(e,i,t){const r=t.find(a=>a.name===e),o=r?this.pageFor(r,i):i.byApiId[e],n=o?this.ctx.roleForSlug(o.slug):"none";return ue(n,this.ctx.roleForSlug(this.settings.basePath))}approvalSummary(){return u(this,void 0,void 0,function*(){if(!this.settings.approvalsEnabled)return{enabled:!1,canView:!1,canDecide:!1};const e=this.ctx.roleForSlug(this.settings.basePath);if(M(e))return{enabled:!0,canView:!0,canDecide:!0};const[i,t]=yield Promise.all([this.apigeeProducts(),this.productPages()]);let r=T(e),o=!1;for(const n of i){if(!C(this.settings,n.name))continue;const a=this.roleFor(n.name,t,i);r||(r=T(a)),o||(o=M(a))}return{enabled:!0,canView:r,canDecide:o}})}canReview(){return u(this,void 0,void 0,function*(){return(yield this.approvalSummary()).canView})}listApiProducts(){return u(this,void 0,void 0,function*(){const[e,i]=yield Promise.all([this.apigeeProducts(),this.productPages()]),t=[];for(const r of e){if(!C(this.settings,r.name))continue;const o=this.pageFor(r,i);if(o){if(!this.ctx.isSlugVisible(o.slug))continue;t.push(z(r,o))}else this.settings.apiProducts.allowOutsideCatalog&&t.push(z(r))}return t.sort((r,o)=>r.name.localeCompare(o.name))})}assertProductsAllowed(e){return u(this,void 0,void 0,function*(){const i=ee(e),t=yield this.listApiProducts(),r=i.filter(n=>!t.some(a=>a.id===n));if(r.length>0)throw new y(`Unknown API product: ${r.join(", ")}`);const o=new Map(t.map(n=>[n.id,n]));return[...new Set(i)].flatMap(n=>{const a=o.get(n);return a?[a]:[]})})}resolveOwner(e){return u(this,void 0,void 0,function*(){if(!e)return{owner:{kind:"developer",email:this.email},path:{kind:"developer",email:this.email}};const i=yield this.requireTeam(e);return{owner:{kind:"team",teamId:i.id},path:{kind:"appgroup",name:i.id}}})}ownerPath(e){return e.kind==="developer"?{kind:"developer",email:e.email}:{kind:"appgroup",name:e.teamId}}withDecisions(e){return u(this,void 0,void 0,function*(){const i=[];for(const o of e)for(const n of o.credentials)for(const a of n.apiProducts)i.push({owner:o.owner,appId:o.id,consumerKey:n.consumerKey,apiProduct:a.id});const t=yield this.store.getDecisions(i);let r=0;for(const o of e)for(const n of o.credentials)for(const a of n.apiProducts){const d=t[r++];d&&(a.decision=d)}return e})}listApps(){return u(this,void 0,void 0,function*(){return this.appsOf(yield this.listMyTeams())})}appsOf(e){return u(this,void 0,void 0,function*(){const[i,...t]=yield Promise.all([this.client.listApps({kind:"developer",email:this.email}),...e.map(o=>this.client.listApps({kind:"appgroup",name:o.id}))]),r=i.map(o=>S(o,{kind:"developer",email:this.email}));return e.forEach((o,n)=>{r.push(...t[n].map(a=>S(a,{kind:"team",teamId:o.id})))}),this.withDecisions(r.sort((o,n)=>{var a,d;return((a=n.createdAt)!==null&&a!==void 0?a:0)-((d=o.createdAt)!==null&&d!==void 0?d:0)}))})}createApp(e){return u(this,void 0,void 0,function*(){var i;const t=te(e.name),r=A(e.description,P,"description"),o=ie(e.callbackUrl),n=A(e.note,P,"note"),a=yield this.assertProductsAllowed((i=e.apiProducts)!==null&&i!==void 0?i:[]),{owner:d,path:l}=yield this.resolveOwner(e.teamId);if(d.kind==="developer"&&(yield this.client.ensureDeveloper(Object.assign({email:this.email,userName:this.email},ge(this.viewer)))),yield this.client.getApp(l,t))throw new y(`An app named "${t}" already exists`);const p=yield this.client.createApp(l,Object.assign(Object.assign({name:t,apiProducts:a.map(m=>m.id)},o?{callbackUrl:o}:{}),{keyExpiresIn:String(L*(d.kind==="developer"?1e3:1)),attributes:K({[x]:t,[k]:r??""})})),c=S(p,d);return yield this.recordRequestNotes(d,c.id,c.credentials,a,n),c})}updateApp(e,i,t){return u(this,void 0,void 0,function*(){var r;const{owner:o,path:n}=yield this.resolveOwner(e),a=yield this.client.getApp(n,i);if(!a)throw new b("App not found");const d=O(a.attributes);t.name!==void 0&&(d[x]=te(t.name)),t.description!==void 0&&(d[k]=(r=A(t.description,P,"description"))!==null&&r!==void 0?r:"");const l=t.callbackUrl===void 0?a.callbackUrl:ie(t.callbackUrl),p=yield this.client.updateApp(n,i,Object.assign({attributes:K(d)},l!==void 0?{callbackUrl:l}:{}));return S(p,o)})}deleteApp(e,i){return u(this,void 0,void 0,function*(){const{path:t}=yield this.resolveOwner(e);if(!(yield this.client.getApp(t,i)))throw new b("App not found");yield this.client.deleteApp(t,i)})}createKey(e,i,t){return u(this,void 0,void 0,function*(){var r;const{owner:o,path:n}=yield this.resolveOwner(e);if(!(yield this.client.getApp(n,i)))throw new b("App not found");const a=yield this.assertProductsAllowed((r=t.apiProducts)!==null&&r!==void 0?r:[]),d=A(t.note,P,"note"),l=yield this.client.createKey(n,i,{consumerKey:J(24),consumerSecret:J(24),expiresInSeconds:L}),p=a.length>0?yield this.client.addKeyProducts(n,i,l.consumerKey,a.map(m=>m.id),l.attributes):l,c=Y(p);return yield this.recordRequestNotes(o,i,[c],a,d),c})}updateKeyProducts(e,i,t,r){return u(this,void 0,void 0,function*(){var o,n;const{owner:a,path:d}=yield this.resolveOwner(e),l=yield this.client.getKey(d,i,t);if(!l)throw new b("Key not found");const p=new Set(((o=l.apiProducts)!==null&&o!==void 0?o:[]).map(g=>g.apiproduct)),c=ee((n=r.apiProducts)!==null&&n!==void 0?n:[]),m=yield this.assertProductsAllowed(c.filter(g=>!p.has(g))),w=A(r.note,P,"note"),h=[...p].filter(g=>!c.includes(g));let f=l;m.length>0&&(f=yield this.client.addKeyProducts(d,i,t,m.map(g=>g.id),l.attributes));for(const g of h)yield this.client.removeKeyProduct(d,i,t,g),yield this.store.deleteRequestNote({owner:a,appId:i,consumerKey:t,apiProduct:g}),yield this.store.deleteDecision({owner:a,appId:i,consumerKey:t,apiProduct:g});const v=h.length>0?yield this.client.getKey(d,i,t):null,N=Y(v??f);return yield this.recordRequestNotes(a,i,[N],m,w),N})}deleteKey(e,i,t){return u(this,void 0,void 0,function*(){const{path:r}=yield this.resolveOwner(e);if(!(yield this.client.getKey(r,i,t)))throw new b("Key not found");yield this.client.deleteKey(r,i,t)})}recordRequestNotes(e,i,t,r,o){return u(this,void 0,void 0,function*(){const n=r.filter(d=>d.approvalType==="manual");if(n.length===0)return;const a=Date.now();for(const d of t)for(const l of n)yield this.store.putRequestNote({owner:e,appId:i,consumerKey:d.consumerKey,apiProduct:l.id},Object.assign({requestedBy:this.email,requestedAt:a},o?{note:o}:{}))})}getAccess(e){return u(this,void 0,void 0,function*(){const i=yield this.appsOf(yield this.listMyTeams()),t=Date.now(),r=n=>i.flatMap(a=>a.credentials.filter(d=>a.status!=="revoked"&&d.status==="approved"&&(d.expiresAt===null||d.expiresAt>t)&&d.apiProducts.some(l=>l.id===e&&l.status===n)).map(d=>({app:a,credential:d}))),o=r("approved").sort((n,a)=>n.app.owner.kind===a.app.owner.kind?0:n.app.owner.kind==="developer"?-1:1);if(o.length>0){const{credential:n}=o[0];return{status:"APPROVED",link:this.settings.basePath,requestValues:{security:{default:Object.assign({client_id:n.consumerKey},n.consumerSecret?{client_secret:n.consumerSecret}:{})}}}}return{status:r("pending").length>0?"PENDING":"NONE",link:`${this.settings.basePath}?createApp&apiProduct=${encodeURIComponent(e)}`}})}assertTeams(){if(!this.settings.teamsEnabled)throw new q("Teams are disabled")}withRole(e){const i=e.members.find(t=>t.email===this.email);return i?Object.assign(Object.assign({},e),{myRole:i.role}):e}listMyTeams(){return u(this,void 0,void 0,function*(){var e,i;if(!this.settings.teamsEnabled)return[];let t;try{t=yield this.client.listAppGroups()}catch(n){return(e=this.logger)===null||e===void 0||e.debug(`apigee: AppGroups unavailable: ${String(n)}`),[]}const r=new Map((yield this.store.listTeamsOf(this.email)).map(n=>[n.id,n])),o=[];for(const n of t){if(!W(n).some(d=>d.email===this.email))continue;const a=X(n,(i=r.get(n.name))!==null&&i!==void 0?i:yield this.store.getTeam(n.name));r.has(a.id)||(yield this.store.putTeam(a)),o.push(this.withRole(a))}return o.sort((n,a)=>n.name.localeCompare(a.name))})}requireTeam(e,i){return u(this,void 0,void 0,function*(){this.assertTeams();const[t,r]=yield Promise.all([this.client.getAppGroup(e),this.store.getTeam(e)]);if(!t)throw new b("Team not found");const o=this.withRole(X(t,r));if(!o.myRole)throw new q("You are not a member of this team");if(i==="owner"&&o.myRole!=="owner")throw new q("Only a team owner can do this");return o})}getTeam(e){return u(this,void 0,void 0,function*(){return this.requireTeam(e)})}createTeam(e){return u(this,void 0,void 0,function*(){var i;this.assertTeams();const t=A(e.name,100,"name");if(!t)throw new y("A team needs a name");const r=we(t);if(!he.test(r))throw new y("The team name needs at least two letters or digits");const o=(i=A(e.description,P,"description"))!==null&&i!==void 0?i:"";if((yield this.store.getTeam(r))||(yield this.client.getAppGroup(r)))throw new y(`A team named "${t}" already exists`);const n=[{email:this.email,role:"owner",addedAt:Date.now()}];yield this.client.createAppGroup({name:r,displayName:t,attributes:K({[k]:o,[F]:Z(n)})});const a={id:r,name:t,description:o,createdAt:Date.now(),createdBy:this.email,members:n};return yield this.store.putTeam(a),this.withRole(a)})}updateTeam(e,i){return u(this,void 0,void 0,function*(){var t;const r=yield this.requireTeam(e,"owner"),o=A(i.name,100,"name")||r.name,n=(t=A(i.description,P,"description"))!==null&&t!==void 0?t:r.description,a=Object.assign(Object.assign({},G(r)),{name:o,description:n});return yield this.syncAppGroup(a),yield this.store.putTeam(a),this.withRole(a)})}deleteTeam(e){return u(this,void 0,void 0,function*(){const i=yield this.requireTeam(e,"owner"),t={kind:"appgroup",name:i.id};for(const r of yield this.client.listApps(t))yield this.client.deleteApp(t,r.name);try{yield this.client.deleteAppGroup(i.id)}catch(r){if(!(r instanceof de&&r.status===404))throw r}yield this.store.deleteTeam(i.id)})}addMember(e,i){return u(this,void 0,void 0,function*(){const t=yield this.requireTeam(e,"owner"),r=be(i.email),o=re(i.role);if(t.members.some(a=>a.email===r))throw new y(`${r} is already a member`);const n=Object.assign(Object.assign({},G(t)),{members:[...t.members,{email:r,role:o,addedAt:Date.now()}]});return yield this.syncAppGroup(n),yield this.store.putTeam(n),this.withRole(n)})}setMemberRole(e,i,t){return u(this,void 0,void 0,function*(){const r=yield this.requireTeam(e,"owner"),o=_(i);if(!r.members.some(d=>d.email===o))throw new b("Member not found");const n=r.members.map(d=>d.email===o?Object.assign(Object.assign({},d),{role:re(t)}):d);Q(n);const a=Object.assign(Object.assign({},G(r)),{members:n});return yield this.syncAppGroup(a),yield this.store.putTeam(a),this.withRole(a)})}removeMember(e,i){return u(this,void 0,void 0,function*(){const t=yield this.requireTeam(e),r=_(i);if(t.myRole!=="owner"&&r!==this.email)throw new q("Only a team owner can remove other members");if(!t.members.some(a=>a.email===r))throw new b("Member not found");const o=t.members.filter(a=>a.email!==r);Q(o);const n=Object.assign(Object.assign({},G(t)),{members:o});return yield this.syncAppGroup(n),yield this.store.putTeam(n),this.withRole(n)})}syncAppGroup(e){return u(this,void 0,void 0,function*(){const i=yield this.client.getAppGroup(e.id);if(!i)throw new b("Team not found");const t=Object.assign(Object.assign({},O(i.attributes)),{[k]:e.description,[F]:Z(e.members)});yield this.client.updateAppGroup(e.id,Object.assign(Object.assign({},i),{name:e.id,displayName:e.name,attributes:K(t)}))})}ownerOf(e,i){return u(this,void 0,void 0,function*(){var t;if(e.appGroup)return{kind:"team",teamId:e.appGroup};if(e.developerEmail)return{kind:"developer",email:_(e.developerEmail)};if(e.developerId){let r=i.get(e.developerId);if(r||(r=(t=yield this.client.getDeveloper(e.developerId))===null||t===void 0?void 0:t.email,r&&i.set(e.developerId,r)),r)return{kind:"developer",email:_(r)}}return null})}teamNames(){return u(this,void 0,void 0,function*(){var e;const i=new Map;if(!this.settings.teamsEnabled)return i;let t;try{t=yield this.client.listAppGroups()}catch(r){return(e=this.logger)===null||e===void 0||e.debug(`apigee: AppGroups unavailable: ${String(r)}`),i}for(const r of t)r.displayName&&i.set(r.name,r.displayName);return i})}listRequests(){return u(this,void 0,void 0,function*(){var e,i;const[t,r,o,n]=yield Promise.all([this.client.listOrganizationApps(),this.apigeeProducts(),this.productPages(),this.teamNames()]),a=new Map,d=[];for(const l of t){const p=((e=l.credentials)!==null&&e!==void 0?e:[]).flatMap(w=>{var h;return((h=w.apiProducts)!==null&&h!==void 0?h:[]).filter(f=>f.status==="pending").filter(f=>T(this.roleFor(f.apiproduct,o,r))).map(f=>({credential:w,apiProduct:f.apiproduct}))});if(p.length===0)continue;const c=yield this.ownerOf(l,a);if(!c)continue;const m=O(l.attributes)[x];for(const{credential:w,apiProduct:h}of p){const{consumerKey:f}=w,v=yield this.store.getRequestNote({owner:c,appId:l.name,consumerKey:f,apiProduct:h});d.push(Object.assign(Object.assign(Object.assign(Object.assign({id:ve({owner:c,appId:l.name,keyDigest:H(f),apiProduct:h}),owner:c},v?{requestedBy:v.requestedBy}:{}),{teamName:U(c,n),appId:l.name,appName:m||l.name,consumerKey:V(f),apiProduct:h,apiProductName:B(r,h)}),v?.note?{note:v.note}:{}),{requestedAt:(i=v?.requestedAt)!==null&&i!==void 0?i:Number(w.issuedAt)||null,canDecide:M(this.roleFor(h,o,r))}))}}return d.sort((l,p)=>{var c,m;return((c=p.requestedAt)!==null&&c!==void 0?c:0)-((m=l.requestedAt)!==null&&m!==void 0?m:0)})})}decideRequest(e,i,t){return u(this,void 0,void 0,function*(){var r;const o=ye(e),{keyDigest:n}=o,a=D(o,["keyDigest"]),[d,l]=yield Promise.all([this.apigeeProducts(),this.productPages()]);if(!M(this.roleFor(a.apiProduct,l,d)))throw new q("You cannot decide requests for this API product");const p=A(t,P,"note"),c=this.ownerPath(a.owner),m=yield this.client.getApp(c,a.appId);if(!m)throw new b("App not found");const w=(r=m.credentials)===null||r===void 0?void 0:r.find(v=>H(v.consumerKey)===n);if(!w)throw new b("Key not found");const h=Object.assign(Object.assign({},a),{consumerKey:w.consumerKey});yield this.client.setKeyProductStatus(c,h.appId,h.consumerKey,h.apiProduct,i),yield this.store.deleteRequestNote(h);const f=Object.assign({action:i,actor:this.email,at:Date.now()},p?{note:p}:{});return yield this.store.putDecision(h,f),this.store.appendAudit(Object.assign({at:f.at,actor:this.email,action:i,owner:h.owner,appId:h.appId,appName:O(m.attributes)[x]||m.name,consumerKey:V(h.consumerKey),apiProduct:h.apiProduct},p?{note:p}:{}))})}listAllApps(){return u(this,void 0,void 0,function*(){var e;const[i,t,r,o]=yield Promise.all([this.client.listOrganizationApps(),this.apigeeProducts(),this.productPages(),this.teamNames()]),n=T(this.ctx.roleForSlug(this.settings.basePath)),a=new Map,d=[];for(const l of i){if(!(n||((e=l.credentials)!==null&&e!==void 0?e:[]).some(f=>{var v;return((v=f.apiProducts)!==null&&v!==void 0?v:[]).some(N=>T(this.roleFor(N.apiproduct,r,t)))})))continue;const c=yield this.ownerOf(l,a);if(!c)continue;const m=S(l,c),{credentials:w}=m,h=D(m,["credentials"]);for(const f of w.flatMap(v=>v.apiProducts))f.name=B(t,f.id);d.push(Object.assign(Object.assign({},h),{teamName:U(c,o),credentials:w.map(f=>{var{consumerKey:v,consumerSecret:N}=f,g=D(f,["consumerKey","consumerSecret"]);return g})}))}return d.sort((l,p)=>{var c,m;return((c=p.createdAt)!==null&&c!==void 0?c:0)-((m=l.createdAt)!==null&&m!==void 0?m:0)})})}listAudit(){return u(this,void 0,void 0,function*(){const[e,i,t,r]=yield Promise.all([this.store.listAudit(),this.apigeeProducts(),this.productPages(),this.teamNames()]),o=e.filter(n=>T(this.roleFor(n.apiProduct,t,i)));for(const n of o)n.teamName=U(n.owner,r),n.apiProductName=B(i,n.apiProduct);return o})}}R=new WeakMap,j=new WeakMap;function U(s,e){return s.kind==="team"?e.get(s.teamId):void 0}function B(s,e){var i;return(i=s.find(t=>t.name===e))===null||i===void 0?void 0:i.displayName}function G(s){const{myRole:e}=s;return D(s,["myRole"])}function Q(s){if(!s.some(e=>e.role==="owner"))throw new y("A team needs at least one owner")}function ee(s){if(!Array.isArray(s)||s.some(e=>typeof e!="string"))throw new y("apiProducts must be a list of product names");return s}function te(s){if(typeof s!="string"||!pe.test(s.trim()))throw new y("An app name has 1 to 100 letters, digits, spaces, dots, dashes or underscores");const e=s.trim();if(me.has(e))throw new y(`An app cannot be named "${e}"`);return e}function A(s,e,i){if(s==null)return;if(typeof s!="string")throw new y(`${i} must be text`);const t=s.trim();if(t.length>e)throw new y(`${i} is longer than ${e} characters`);return t}function ie(s){const e=A(s,fe,"callbackUrl");if(!e)return e===""?"":void 0;for(const i of e.split(","))try{new URL(i.trim())}catch{throw new y(`"${i.trim()}" is not a valid callback URL`)}return e}function be(s){const e=typeof s=="string"?s.trim():"",i=e.indexOf("@"),t=e.slice(i+1);if(i<1||/\s/.test(e)||!t.includes(".")||t.startsWith(".")||t.endsWith("."))throw new y("Enter a valid email address");return _(e)}function re(s){if(s===void 0)return"member";if(s!=="owner"&&s!=="member")throw new y("Unknown role");return s}export{Re as ApigeeService,q as ForbiddenError,b as NotFoundError,y as ValidationError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/framework-plugin-apigee",
3
- "version": "0.1.0-next.0",
3
+ "version": "0.1.0-next.2",
4
4
  "description": "Experimental Apigee developer onboarding plugin for Redocly",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -25,20 +25,20 @@
25
25
  "styled-components": "^6.4.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@redocly/framework": "1.0.0-next.7",
28
+ "@redocly/framework": "1.0.0-next.9",
29
29
  "@types/node": "24.1.0",
30
30
  "@types/react": "^19.2.7",
31
31
  "@types/react-dom": "^19.2.3",
32
32
  "@vitest/coverage-v8": "4.1.11",
33
33
  "esbuild-minify-dir": "0.0.1",
34
- "hono": "4.13.13",
34
+ "hono": "4.13.18",
35
35
  "rimraf": "5.0.7",
36
36
  "typescript": "6.0.3",
37
37
  "vitest": "4.1.11"
38
38
  },
39
39
  "peerDependencies": {
40
- "@redocly/framework": "^1.0.0-next.7",
41
- "@redocly/theme": "0.73.0-next.2",
40
+ "@redocly/framework": "^1.0.0-next.9",
41
+ "@redocly/theme": "0.73.0-next.4",
42
42
  "react": "^19.2.7",
43
43
  "react-dom": "^19.2.7",
44
44
  "react-router": "^8.3.0"