@redocly/framework-plugin-apigee 0.1.0-next.1 → 0.1.0-next.11

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,4 +1,4 @@
1
- import type { ApigeeMeta } from '../contract.js';
1
+ import type { ApigeeMeta, App } from '../contract.js';
2
2
  export type ApigeeContextValue = {
3
3
  meta: ApigeeMeta;
4
4
  /** The apps page slug, without the site path prefix: router links add it. */
@@ -7,6 +7,8 @@ export type ApigeeContextValue = {
7
7
  title: string;
8
8
  /** A site-relative link under the apps page. */
9
9
  link: (path?: string, query?: Record<string, string | undefined>) => string;
10
+ /** The link to an app's page; a team app carries its team, since app names are unique per owner. */
11
+ appLink: (app: App) => string;
10
12
  };
11
13
  export declare const ApigeeContext: import("react").Context<ApigeeContextValue | null>;
12
14
  export declare function useApigee(): ApigeeContextValue;
@@ -1,13 +1,3 @@
1
- export type AsyncState<T> = {
2
- data: T | null;
3
- error: string | null;
4
- loading: boolean;
5
- reload: () => void;
6
- /** Replaces the loaded value without a round trip, after a mutation returned the new state. */
7
- setData: (value: T | null) => void;
8
- };
9
- /** Loads `load()` on mount and whenever `key` changes; the last request wins. */
10
- export declare function useAsync<T>(load: () => Promise<T>, key: string): AsyncState<T>;
11
1
  export type MutationState = {
12
2
  pending: boolean;
13
3
  error: string | null;
@@ -16,6 +6,13 @@ export type MutationState = {
16
6
  };
17
7
  /** Runs one mutation at a time and keeps its error for the form that started it. */
18
8
  export declare function useMutation(): MutationState;
9
+ export declare function errorMessage(error: unknown): string;
10
+ /** A list filter kept in the query string, so Back returns to the same filtered list. */
11
+ export declare function useSearchParam(name: string): [string, (value: string) => void];
12
+ /** A list's search text, kept per page for the browser session and out of the URL, so typing adds no page views. */
13
+ export declare function useSearchText(): [string, (value: string) => void];
14
+ /** Whether any of `values` contains the search text, ignoring case; an empty search matches all. */
15
+ export declare function matches(search: string, ...values: (string | undefined)[]): boolean;
19
16
  export declare function formatDate(value: number | null | undefined): string;
20
17
  export declare function formatDateTime(value: number | null | undefined): string;
21
18
  export declare function copyText(text: string): Promise<boolean>;
@@ -1 +1 @@
1
- var g=function(t,u,a,n){function c(i){return i instanceof a?i:new a(function(o){o(i)})}return new(a||(a=Promise))(function(i,o){function s(e){try{r(n.next(e))}catch(m){o(m)}}function d(e){try{r(n.throw(e))}catch(m){o(m)}}function r(e){e.done?i(e.value):c(e.value).then(s,d)}r((n=n.apply(t,u||[])).next())})};import{useCallback as f,useEffect as p,useRef as y,useState as l}from"react";import{ApiRequestError as x}from"./api.js";function D(t,u){const[a,n]=l({data:null,error:null,loading:!0}),[c,i]=l(0),o=y(t);o.current=t,p(()=>{let r=!1;return n(e=>Object.assign(Object.assign({},e),{loading:!0,error:null})),o.current().then(e=>{r||n({data:e,error:null,loading:!1})}).catch(e=>{r||n({data:null,error:h(e),loading:!1})}),()=>{r=!0}},[u,c]);const s=f(()=>i(r=>r+1),[]),d=f(r=>n({data:r,error:null,loading:!1}),[]);return Object.assign(Object.assign({},a),{reload:s,setData:d})}function E(){const[t,u]=l(!1),[a,n]=l(null),c=f(o=>g(this,void 0,void 0,function*(){u(!0),n(null);try{return yield o()}catch(s){n(h(s));return}finally{u(!1)}}),[]),i=f(()=>n(null),[]);return{pending:t,error:a,clearError:i,run:c}}function h(t){return t instanceof x||t instanceof Error?t.message:String(t)}function S(t){return t?new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):"\u2014"}function _(t){return t?new Date(t).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"\u2014"}function j(t){return g(this,void 0,void 0,function*(){try{return yield navigator.clipboard.writeText(t),!0}catch{return!1}})}export{j as copyText,S as formatDate,_ as formatDateTime,D as useAsync,E as useMutation};
1
+ var l=function(t,n,r,e){function i(o){return o instanceof r?o:new r(function(u){u(o)})}return new(r||(r=Promise))(function(o,u){function c(a){try{f(e.next(a))}catch(d){u(d)}}function p(a){try{f(e.throw(a))}catch(d){u(d)}}function f(a){a.done?o(a.value):i(a.value).then(c,p)}f((e=e.apply(t,n||[])).next())})};import{useCallback as s,useReducer as x,useState as m}from"react";import{useLocation as y,useSearchParams as w}from"react-router";import{ApiRequestError as g}from"./api.js";function D(){const[t,n]=m(!1),[r,e]=m(null),i=s(u=>l(this,void 0,void 0,function*(){n(!0),e(null);try{return yield u()}catch(c){e(S(c));return}finally{n(!1)}}),[]),o=s(()=>e(null),[]);return{pending:t,error:r,clearError:o,run:i}}function S(t){return t instanceof g||t instanceof Error?t.message:String(t)}function T(t){var n;const[r,e]=w(),i=s(o=>e(u=>{const c=new URLSearchParams(u);return o?c.set(t,o):c.delete(t),c},{replace:!0}),[t,e]);return[(n=r.get(t))!==null&&n!==void 0?n:"",i]}const h=new Map;function E(){var t;const{pathname:n}=y(),[,r]=x(i=>i+1,0),e=s(i=>{h.set(n,i),r()},[n]);return[(t=h.get(n))!==null&&t!==void 0?t:"",e]}function C(t,...n){const r=t.trim().toLowerCase();return!r||n.some(e=>e?.toLowerCase().includes(r))}function M(t){return t?new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}):"\u2014"}function P(t){return t?new Date(t).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"\u2014"}function R(t){return l(this,void 0,void 0,function*(){try{return yield navigator.clipboard.writeText(t),!0}catch{return!1}})}export{R as copyText,S as errorMessage,M as formatDate,P as formatDateTime,C as matches,D as useMutation,T as useSearchParam,E as useSearchText};
@@ -0,0 +1,28 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import type { App, AppOwner, Team, TeamRole } from '../contract.js';
3
+ /** The plugin's cache: module scoped, so it outlives the template while the portal stays open. */
4
+ export declare const queryClient: QueryClient;
5
+ export declare const queryKeys: {
6
+ readonly meta: readonly ['apigee', 'meta'];
7
+ readonly apps: readonly ['apigee', 'apps'];
8
+ readonly teams: readonly ['apigee', 'teams'];
9
+ readonly admin: readonly ['apigee', 'admin'];
10
+ readonly adminRequests: readonly ['apigee', 'admin', 'requests'];
11
+ readonly adminApps: readonly ['apigee', 'admin', 'apps'];
12
+ readonly adminAudit: readonly ['apigee', 'admin', 'audit'];
13
+ };
14
+ export declare const useMeta: (enabled: boolean) => import("@tanstack/react-query").UseQueryResult<import("../contract.js").ApigeeMeta, Error>;
15
+ export declare const useApps: (enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<App[], Error>;
16
+ export declare const useTeams: (enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<Team[], Error>;
17
+ export declare const useAdminRequests: (enabled?: boolean) => import("@tanstack/react-query").UseQueryResult<import("../contract.js").AccessRequest[], Error>;
18
+ export declare const useAdminApps: () => import("@tanstack/react-query").UseQueryResult<import("../contract.js").AdminApp[], Error>;
19
+ export declare const useAdminAudit: () => import("@tanstack/react-query").UseQueryResult<import("../contract.js").AuditEntry[], Error>;
20
+ /** The viewer's own apps share one owner; a team's apps share another. */
21
+ export declare function ownerKey(owner: AppOwner): string;
22
+ export declare function putApp(app: App): void;
23
+ export declare function dropApp(app: App): void;
24
+ export declare function putTeam(team: Team): void;
25
+ /** After the viewer leaves or deletes a team, its apps leave their list too. */
26
+ export declare function dropTeam(teamId: string): void;
27
+ /** Shows the new role at once; when the API rejects it, restores the team and throws. */
28
+ export declare function changeMemberRole(team: Team, email: string, role: TeamRole): Promise<void>;
@@ -0,0 +1 @@
1
+ var w=function(e,t,n,i){function q(a){return a instanceof n?a:new n(function(d){d(a)})}return new(n||(n=Promise))(function(a,d){function A(s){try{c(i.next(s))}catch(m){d(m)}}function x(s){try{c(i.throw(s))}catch(m){d(m)}}function c(s){s.done?a(s.value):q(s.value).then(A,x)}c((i=i.apply(e,t||[])).next())})};import{QueryClient as h,useQuery as u}from"@tanstack/react-query";import{ApiRequestError as g,apigeeApi as o}from"./api.js";const p=new h({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1,retry:(e,t)=>e<1&&!(t instanceof g&&t.status<500)}}}),r={meta:["apigee","meta"],apps:["apigee","apps"],teams:["apigee","teams"],admin:["apigee","admin"],adminRequests:["apigee","admin","requests"],adminApps:["apigee","admin","apps"],adminAudit:["apigee","admin","audit"]},F=e=>u({queryKey:r.meta,queryFn:o.meta,enabled:e}),Q=(e=!0)=>u({queryKey:r.apps,queryFn:o.listApps,enabled:e}),R=(e=!0)=>u({queryKey:r.teams,queryFn:o.listTeams,enabled:e}),O=(e=!0)=>u({queryKey:r.adminRequests,queryFn:o.adminRequests,enabled:e}),b=()=>u({queryKey:r.adminApps,queryFn:o.adminApps}),D=()=>u({queryKey:r.adminAudit,queryFn:o.adminAudit});function l(e){return e.kind==="team"?`team:${e.teamId}`:"developer"}const y=(e,t)=>e.id===t.id&&l(e.owner)===l(t.owner);function T(e){p.setQueryData(r.apps,(t=[])=>t.some(n=>y(n,e))?t.map(n=>y(n,e)?e:n):[...t,e])}function j(e){p.setQueryData(r.apps,t=>t?.filter(n=>!y(n,e)))}function f(e){p.setQueryData(r.teams,(t=[])=>t.some(n=>n.id===e.id)?t.map(n=>n.id===e.id?e:n):[...t,e].sort((n,i)=>n.name.localeCompare(i.name)))}function _(e){p.setQueryData(r.teams,t=>t?.filter(n=>n.id!==e)),p.setQueryData(r.apps,t=>t?.filter(n=>!(n.owner.kind==="team"&&n.owner.teamId===e)))}function C(e,t,n){return w(this,void 0,void 0,function*(){f(Object.assign(Object.assign({},e),{members:e.members.map(i=>i.email===t?Object.assign(Object.assign({},i),{role:n}):i)}));try{f(yield o.setMemberRole(e.id,t,n))}catch(i){throw f(e),i}})}export{C as changeMemberRole,j as dropApp,_ as dropTeam,l as ownerKey,T as putApp,f as putTeam,p as queryClient,r as queryKeys,b as useAdminApps,D as useAdminAudit,O as useAdminRequests,Q as useApps,F as useMeta,R as useTeams};
@@ -1,2 +1,5 @@
1
1
  import type { ReactElement } from 'react';
2
+ export declare function ApprovalsDescription({ organization }: {
3
+ organization: string;
4
+ }): ReactElement;
2
5
  export declare function AdminView(): ReactElement;
@@ -1,20 +1,16 @@
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`
1
+ var te=function(l,p,m,v){function N(f){return f instanceof m?f:new m(function(h){h(f)})}return new(m||(m=Promise))(function(f,h){function y(d){try{c(v.next(d))}catch(u){h(u)}}function w(d){try{c(v.throw(d))}catch(u){h(u)}}function c(d){d.done?f(d.value):N(d.value).then(y,w)}c((v=v.apply(l,p||[])).next())})};import{Fragment as ae,jsx as t,jsxs as n}from"react/jsx-runtime";import{useState as W}from"react";import S from"styled-components";import{Button as C}from"@redocly/theme/components/Button/Button";import{Segmented as ie}from"@redocly/theme/components/Segmented/Segmented";import{Select as ne}from"@redocly/theme/components/Select/Select";import{Tag as Q}from"@redocly/theme/components/Tag/Tag";import{useToast as re}from"@redocly/theme/core/hooks/use-toast";import{breakpoints as oe}from"@redocly/theme/core/utils/media-css";import{CDNIcon as de}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as le}from"../api.js";import{useApigee as ce}from"../context.js";import{errorMessage as j,formatDateTime as q,matches as I,useSearchParam as se,useSearchText as pe}from"../hooks.js";import{EmptyState as D,FilterSlot as he,ListSkeleton as z,Mono as ue,Muted as s,NoMatches as me,Notice as B,PageHeader as ve,ProductTag as H,Row as V,SearchField as ge,Stat as P,Stats as fe,Table as M,TableWrap as K,Toolbar as we}from"../Primitives.js";import{queryClient as G,queryKeys as J,useAdminApps as be,useAdminAudit as Ae,useAdminRequests as Ne}from"../queries.js";import{ConfirmDialog as Pe}from"./Dialogs.js";function ye({organization:l}){return n(ae,{children:["Access requests for API products that require manual approval in Apigee organization"," ",t("strong",{children:l}),"."]})}const ke=S.div`
2
2
  margin-bottom: var(--spacing-base);
3
- `,ee=A.span`
4
- display: inline-flex;
5
- align-items: center;
6
- gap: var(--spacing-xs);
7
- `,te=A(o)`
3
+ `,xe=S(s)`
8
4
  display: inline-block;
9
5
  max-width: 200px;
10
6
  white-space: normal;
11
7
  text-align: left;
12
- `,ne=A(K)`
8
+ `,Te=S(V)`
13
9
  flex-wrap: nowrap;
14
10
 
15
- @media (max-width: ${H.small}) {
11
+ @media (max-width: ${oe.small}) {
16
12
  > button {
17
13
  flex: 1;
18
14
  }
19
15
  }
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};
16
+ `;function b(l,p){return l.kind==="developer"?{title:l.email,subtitle:"Personal"}:{title:p??l.teamId,subtitle:"Team"}}const U=()=>G.invalidateQueries({queryKey:J.admin});function Oe(){var l,p,m,v;const{meta:N}=ce(),f=re(),[h,y]=W("pending"),w=Ne(),c=be(),d=Ae(),[u,$]=pe(),[g,L]=se("product"),[a,k]=W(null),x=(l=w.data)!==null&&l!==void 0?l:[],A=(p=c.data)!==null&&p!==void 0?p:[],X=[{value:"",element:"All API products"},...N.apiProducts.map(e=>({value:e.id,element:e.name}))],E=x.filter(e=>{var i;return(!g||e.apiProduct===g)&&I(u,b(e.owner,e.teamName).title,e.requestedBy,e.appName,(i=e.apiProductName)!==null&&i!==void 0?i:e.apiProduct,e.note)}),F=A.filter(e=>{const i=e.credentials.flatMap(o=>o.apiProducts);return(!g||i.some(o=>o.id===g))&&I(u,e.name,b(e.owner,e.teamName).title,...i.map(o=>{var r;return(r=o.name)!==null&&r!==void 0?r:o.id}))}),O=((m=d.data)!==null&&m!==void 0?m:[]).filter(e=>{var i;return(!g||e.apiProduct===g)&&I(u,e.actor,e.appName,b(e.owner,e.teamName).title,(i=e.apiProductName)!==null&&i!==void 0?i:e.apiProduct,e.note)}),T=!!(u||g),_=t(me,{onClear:()=>{$(""),L("")}}),Y=A.reduce((e,i)=>e+i.credentials.filter(o=>o.status==="approved").length,0),Z=new Set(A.filter(e=>e.owner.kind==="developer").map(e=>e.owner.kind==="developer"&&e.owner.email)).size,ee=new Set(A.filter(e=>e.owner.kind==="team").map(e=>e.owner.kind==="team"&&e.owner.teamId)).size;return n("div",{"data-testid":"apigee-admin",children:[t(ve,{title:"Approvals",description:t(ye,{organization:N.organizationName}),actions:t(C,{variant:"outlined",onClick:U,icon:t(de,{name:"arrows-rotate",size:"16px"}),children:"Refresh"})}),n(fe,{children:[n(P,{children:[t("strong",{"data-testid":"apigee-stat-pending",children:w.data?x.length:"\u2026"}),t(s,{children:"Pending requests"})]}),n(P,{children:[t("strong",{children:c.data?Y:"\u2026"}),t(s,{children:"Approved keys"})]}),n(P,{children:[t("strong",{children:c.data?Z:"\u2026"}),t(s,{children:"Developers with apps"})]}),n(P,{children:[t("strong",{children:c.data?ee:"\u2026"}),t(s,{children:"Teams with apps"})]})]}),t(ke,{children:t(ie,{value:h,onChange:e=>y(e.value),options:[{value:"pending",label:"Pending"},{value:"apps",label:"All apps"},{value:"audit",label:"Audit log"}]})}),n(we,{children:[t(ge,{value:u,onChange:$,placeholder:"Search apps, developers or teams",testId:"apigee-admin-search"}),t(he,{children:t(ne,{value:g,options:X,onChange:e=>L(String(e)),dataTestId:"apigee-product-filter"})})]}),h==="pending"?w.data?T&&E.length===0?_:x.length===0?t(D,{icon:"circle-check",title:"Nothing to review",text:"Every request for a manually approved product has been handled."}):t(K,{children:n(M,{"data-testid":"apigee-requests-table",children:[t("thead",{children:n("tr",{children:[t("th",{children:"Requested by"}),t("th",{children:"App"}),t("th",{children:"API product"}),t("th",{children:"Reason"}),t("th",{children:"Requested"}),t("th",{className:"actions"})]})}),t("tbody",{children:E.map(e=>{var i;const o=b(e.owner,e.teamName),r=(i=e.apiProductName)!==null&&i!==void 0?i:e.apiProduct;return n("tr",{"data-testid":"apigee-request-row",children:[n("td",{children:[o.title,t("br",{}),n(s,{children:[o.subtitle,e.requestedBy&&e.requestedBy!==o.title?` \xB7 requested by ${e.requestedBy}`:""]})]}),n("td",{"data-label":"App",children:[e.appName,t("br",{}),t(ue,{children:t(s,{children:e.consumerKey})})]}),t("td",{"data-label":"API product",children:t(H,{name:r,status:"pending"})}),t("td",{"data-label":"Reason",children:e.note?e.note:t(s,{children:"No reason given"})}),t("td",{"data-label":"Requested",children:q(e.requestedAt)}),t("td",{className:"actions",children:e.canDecide?n(Te,{children:[t(C,{variant:"primary",size:"small",onClick:()=>k({request:e,action:"approve"}),"data-testid":"apigee-approve",children:"Approve"}),t(C,{variant:"outlined",tone:"danger",size:"small",onClick:()=>k({request:e,action:"revoke"}),"data-testid":"apigee-reject",children:"Reject"})]}):n(xe,{"data-testid":"apigee-cannot-decide",children:["Only maintainers of ",r," can decide"]})})]},e.id)})})]})}):w.isError?t(B,{tone:"danger",children:j(w.error)}):t(z,{label:"Loading requests\u2026"}):null,h==="apps"?c.data?T&&F.length===0?_:A.length===0?t(D,{icon:"key",title:"No apps yet",text:"Apps developers register appear here."}):t(K,{children:n(M,{"data-testid":"apigee-admin-apps-table",children:[t("thead",{children:n("tr",{children:[t("th",{children:"App"}),t("th",{children:"Owner"}),t("th",{children:"Keys"}),t("th",{children:"API products"}),t("th",{children:"Created"})]})}),t("tbody",{children:F.map(e=>{const i=b(e.owner,e.teamName),o=[...new Map(e.credentials.flatMap(r=>r.apiProducts).map(r=>[r.id,r])).values()];return n("tr",{children:[n("td",{children:[e.name,e.status==="revoked"?t(Q,{color:"red",children:"Revoked"}):null]}),n("td",{"data-label":"Owner",children:[i.title,t("br",{}),t(s,{children:i.subtitle})]}),t("td",{"data-label":"Keys",children:e.credentials.length}),t("td",{"data-label":"API products",children:t(V,{children:o.map(r=>{var R;return t(H,{name:(R=r.name)!==null&&R!==void 0?R:r.id,status:r.status},r.id)})})}),t("td",{"data-label":"Created",children:q(e.createdAt)})]},`${e.owner.kind==="team"?e.owner.teamId:e.owner.email}:${e.id}`)})})]})}):c.isError?t(B,{tone:"danger",children:j(c.error)}):t(z,{label:"Loading apps\u2026"}):null,h==="audit"?d.data?T&&O.length===0?_:d.data.length===0?t(D,{icon:"file-lines",title:"No decisions yet",text:"Approvals and rejections made here are recorded with who made them."}):t(K,{children:n(M,{"data-testid":"apigee-audit-table",children:[t("thead",{children:n("tr",{children:[t("th",{children:"When"}),t("th",{children:"Reviewer"}),t("th",{children:"Action"}),t("th",{children:"Target"})]})}),t("tbody",{children:O.map(e=>{var i;return n("tr",{children:[t("td",{children:q(e.at)}),t("td",{"data-label":"Reviewer",children:e.actor}),t("td",{"data-label":"Action",children:t(Q,{color:e.action==="approve"?"green":"red",children:e.action==="approve"?"Approved":"Rejected"})}),n("td",{"data-label":"Target",children:[(i=e.apiProductName)!==null&&i!==void 0?i:e.apiProduct," \xB7 ",e.appName," (",b(e.owner,e.teamName).title,")",e.note?n(s,{children:[" \u2014 \u201C",e.note,"\u201D"]}):null]})]},e.id)})})]})}):d.isError?t(B,{tone:"danger",children:j(d.error)}):t(z,{label:"Loading the audit log\u2026"}):null,t(Pe,{open:a!==null,onClose:()=>k(null),title:a?.action==="approve"?"Approve access?":"Reject request?",confirmLabel:a?.action==="approve"?"Approve":"Reject",danger:a?.action==="revoke",withNote:!0,noteLabel:"Comment for the developer",notePlaceholder:a?.action==="approve"?"Anything the developer should know before they start":"Why the request is rejected and what would change the decision",onConfirm:e=>te(this,void 0,void 0,function*(){var i;return a&&(yield le.adminDecide(a.request.id,a.action,e),yield U(),G.invalidateQueries({queryKey:J.apps}),f.success(`${a.action==="approve"?"Approved":"Rejected"} ${(i=a.request.apiProductName)!==null&&i!==void 0?i:a.request.apiProduct} for ${a.request.appName}`)),!0}),children:a?n("p",{children:[t("strong",{children:(v=a.request.apiProductName)!==null&&v!==void 0?v:a.request.apiProduct})," for"," ",t("strong",{children:a.request.appName})," (",b(a.request.owner,a.request.teamName).title,").",a.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{Oe as AdminView,ye as ApprovalsDescription};
@@ -1,15 +1,14 @@
1
1
  import type { ReactElement } from 'react';
2
- import type { ApiProduct, App, Team } from '../../contract.js';
2
+ import type { App } from '../../contract.js';
3
3
  export type AppSelection = {
4
4
  appId: string;
5
5
  teamId?: string;
6
6
  } | null;
7
- export declare function AppsView({ selection, teams, products, }: {
7
+ export declare const APPS_DESCRIPTION = "Register apps and manage the API keys that call the APIs through Apigee.";
8
+ export declare function AppsView({ selection }: {
8
9
  selection: AppSelection;
9
- teams: Team[];
10
- products: ApiProduct[];
11
10
  }): ReactElement;
12
- export declare function AppRow({ app, to }: {
13
- app: App;
14
- to: string;
11
+ export declare function AppsTable({ apps, showOwner }: {
12
+ apps: App[];
13
+ showOwner: boolean;
15
14
  }): ReactElement;
@@ -1,5 +1 @@
1
- var K=function(n,l,r,d){function u(h){return h instanceof r?h:new r(function(f){f(h)})}return new(r||(r=Promise))(function(h,f){function g(s){try{v(d.next(s))}catch(y){f(y)}}function p(s){try{v(d.throw(s))}catch(y){f(y)}}function v(s){s.done?h(s.value):u(s.value).then(g,p)}v((d=d.apply(n,l||[])).next())})};import{Fragment as z,jsx as e,jsxs as a}from"react/jsx-runtime";import{useEffect as G,useMemo as j,useState as w}from"react";import{useNavigate as V}from"react-router";import W from"styled-components";import{Button as b}from"@redocly/theme/components/Button/Button";import{Dropdown as J}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as Q}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as B}from"@redocly/theme/components/Tag/Tag";import{Tooltip as X}from"@redocly/theme/components/Tooltip/Tooltip";import{CDNIcon as k}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as A}from"../api.js";import{useApigee as Y}from"../context.js";import{maskKey as Z}from"../../contract.js";import{copyText as ee,formatDate as R,useAsync as te}from"../hooks.js";import{EmptyState as E,LinkList as ne,LinkRow as ie,ListTitle as oe,Loading as re,Mono as M,Muted as x,Notice as L,Overview as ae,PageBreadcrumbs as de,PageHeader as U,Row as N,Section as le,SectionHeader as se,SectionTitle as ce,StatusTag as H,Table as ue,TableWrap as pe}from"../Primitives.js";import{AppDialog as O,ConfirmDialog as F,KeyDialog as me}from"./Dialogs.js";function he(n,l){var r,d;return n.kind==="developer"?"Personal":`Team \xB7 ${(d=(r=l.find(u=>u.id===n.teamId))===null||r===void 0?void 0:r.name)!==null&&d!==void 0?d:n.teamId}`}function ve(n){if(n.status==="revoked")return{color:"red",label:"Revoked"};const l=n.credentials.flatMap(u=>u.apiProducts);if(l.length===0)return{color:"grey",label:"No API products"};if(l.some(u=>u.status==="pending"))return{color:"orange",label:"Pending approval"};const r=new Set(l.map(u=>u.id)).size,d=new Set(l.filter(u=>u.status==="approved").map(u=>u.id)).size;return d===r?{color:"green",label:"Approved"}:d===0?{color:"red",label:"Rejected"}:{color:"blue",label:`${d} of ${r} approved`}}function q(n){if(n.status!=="approved")return n.status;const{apiProducts:l}=n;return l.some(r=>r.status==="pending")?"pending":l.length>0&&l.every(r=>r.status==="revoked")?"revoked":"approved"}function Le({selection:n,teams:l,products:r}){var d,u;const{link:h,title:f}=Y(),g=V(),p=te(()=>A.listApps(),"apps"),[v,s]=w(null);G(()=>{var i,t;const c=new URLSearchParams(window.location.search);c.has("createApp")&&(s({product:(i=c.get("apiProduct"))!==null&&i!==void 0?i:void 0,teamId:(t=c.get("team"))!==null&&t!==void 0?t:void 0}),g(h(),{replace:!0}))},[h,g]);const y=j(()=>{var i;return!n||!p.data?null:(i=p.data.find(t=>t.id===n.appId&&(n.teamId?t.owner.kind==="team"&&t.owner.teamId===n.teamId:t.owner.kind==="developer")))!==null&&i!==void 0?i:null},[p.data,n]),I=j(()=>{var i;const t=((i=p.data)!==null&&i!==void 0?i:[]).filter(o=>o.owner.kind==="developer"),c=l.map(o=>{var m;return{team:o,apps:((m=p.data)!==null&&m!==void 0?m:[]).filter(C=>C.owner.kind==="team"&&C.owner.teamId===o.id)}});return{personal:t,byTeam:c}},[p.data,l]),P=i=>h(`/${encodeURIComponent(i.id)}`,i.owner.kind==="team"?{team:i.owner.teamId}:void 0),$=i=>K(this,void 0,void 0,function*(){const t=yield A.createApp(i);return p.reload(),g(P(t)),t});if(p.loading&&!p.data)return e(re,{label:"Loading your apps\u2026"});if(p.error)return e(L,{tone:"danger",children:p.error});const D=(d=p.data)!==null&&d!==void 0?d:[],S=e(O,{open:v!==null,onClose:()=>s(null),onSubmit:$,products:r,teams:l,initialProduct:v?.product,initialTeamId:v?.teamId}),_=e(b,{variant:"primary",onClick:()=>s({}),icon:e(k,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New app"});if(n)return a(z,{children:[e(de,{additionalBreadcrumbs:[{label:f,link:h()},{label:(u=y?.name)!==null&&u!==void 0?u:n.appId}]}),y?e(ge,{app:y,teams:l,products:r,onChanged:()=>p.reload(),onDeleted:()=>{p.reload(),g(h())}}):e(L,{tone:"danger",children:"App not found"}),S]});const T=[{key:"personal",title:"Personal",apps:I.personal},...I.byTeam.map(({team:i,apps:t})=>({key:`team:${i.id}`,title:`Team \xB7 ${i.name}`,apps:t}))].filter(i=>i.apps.length>0);return a(z,{children:[e(U,{title:f,description:"Register apps and manage the API keys that call the APIs through Apigee.",actions:D.length>0?_:void 0}),D.length===0?e(E,{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(ye,{"data-testid":"apigee-app-list",children:T.map(i=>a("div",{children:[e(oe,{children:i.title}),e(ne,{children:i.apps.map(t=>e(fe,{app:t,to:P(t)},t.id))})]},i.key))}),S]})}const ye=W.div`
2
- display: flex;
3
- flex-direction: column;
4
- gap: var(--spacing-lg);
5
- `;function fe({app:n,to:l}){const r=n.credentials.length,d=ve(n);return e(ie,{to:l,title:n.name,subtitle:`${r} ${r===1?"key":"keys"}${n.description?` \xB7 ${n.description}`:""}`,tag:e(B,{color:d.color,textTransform:"none",children:d.label}),testId:"apigee-app-row"})}function ge({app:n,teams:l,products:r,onChanged:d,onDeleted:u}){const h=n.owner.kind==="team"?n.owner.teamId:void 0,[f,g]=w(!1),[p,v]=w(!1),[s,y]=w(null),[I,P]=w(null),[$,D]=w(new Set),[S,_]=w(null),T=(t,c)=>K(this,void 0,void 0,function*(){(yield ee(t))&&(_(c),setTimeout(()=>_(null),1500))}),i=t=>{var c,o;return(o=(c=r.find(m=>m.id===t))===null||c===void 0?void 0:c.name)!==null&&o!==void 0?o:t};return a("div",{"data-testid":"apigee-app-detail",children:[e(U,{title:a(z,{children:[n.name,n.status==="revoked"?e(B,{color:"red",children:"Revoked"}):null]}),description:n.description||void 0,actions:a(z,{children:[e(b,{variant:"outlined",onClick:()=>g(!0),icon:e(k,{name:"pen",size:"16px"}),"data-testid":"apigee-edit-app",children:"Edit"}),e(X,{tip:"Delete app",placement:"bottom",children:e(b,{variant:"outlined",tone:"danger","aria-label":"Delete app",icon:e(k,{name:"trash-can",size:"16px"}),onClick:()=>v(!0),"data-testid":"apigee-delete-app"})})]})}),a(ae,{children:[a("div",{children:[e("dt",{children:"Owner"}),a("dd",{children:[e(k,{name:n.owner.kind==="team"?"user-group":"user",size:"16px"}),he(n.owner,l)]})]}),a("div",{children:[e("dt",{children:"Created"}),e("dd",{children:R(n.createdAt)})]}),a("div",{className:"wide",children:[e("dt",{children:"Callback URL"}),e("dd",{children:n.callbackUrl||e(x,{children:"Not set"})})]})]}),a(le,{children:[a(se,{children:[e(ce,{children:"API keys"}),e(b,{variant:"outlined",size:"small",onClick:()=>y({}),icon:e(k,{name:"plus",size:"14px"}),"data-testid":"apigee-create-key",children:"Create key"})]}),n.credentials.length===0?e(E,{icon:"key",title:"No keys yet",text:"Create a key and pick the API products it may call."}):e(pe,{children:a(ue,{"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:n.credentials.map(t=>{const c=$.has(t.consumerKey);return a("tr",{"data-testid":"apigee-key-row",children:[a("td",{className:"key",children:[a(N,{children:[e(M,{"data-testid":"apigee-key-value",children:c?t.consumerKey:Z(t.consumerKey)}),e(b,{variant:"text",size:"small","aria-label":c?"Hide key":"Reveal key",icon:e(k,{name:c?"eye-slash":"eye",size:"14px"}),onClick:()=>D(o=>{const m=new Set(o);return m.has(t.consumerKey)?m.delete(t.consumerKey):m.add(t.consumerKey),m})}),e(b,{variant:"text",size:"small","aria-label":"Copy key",icon:e(k,{name:"copy",size:"14px"}),onClick:()=>T(t.consumerKey,`key:${t.consumerKey}`)}),S===`key:${t.consumerKey}`?e(x,{children:"Copied"}):null]}),t.consumerSecret?a(N,{children:[e(x,{children:"Secret"}),e(M,{children:c?t.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(k,{name:"copy",size:"14px"}),onClick:()=>{var o;return T((o=t.consumerSecret)!==null&&o!==void 0?o:"",`secret:${t.consumerKey}`)}}),S===`secret:${t.consumerKey}`?e(x,{children:"Copied"}):null]}):null,a(x,{children:["Issued ",R(t.issuedAt)," \xB7 Expires"," ",t.expiresAt?R(t.expiresAt):"never"]})]}),a("td",{"data-label":"API products",children:[a(N,{children:[t.apiProducts.length===0?e(x,{children:"None"}):null,t.apiProducts.map(o=>e(H,{status:o.status,label:o.status==="approved"?i(o.id):`${i(o.id)} \xB7 ${o.status}`},o.id))]}),t.apiProducts.filter(o=>{var m;return(m=o.decision)===null||m===void 0?void 0:m.note}).map(o=>{var m,C;return a(x,{as:"div","data-testid":"apigee-decision-note",children:[((m=o.decision)===null||m===void 0?void 0:m.action)==="approve"?"Approved":"Rejected"," \xB7"," ",i(o.id),": \u201C",(C=o.decision)===null||C===void 0?void 0:C.note,"\u201D"]},o.id)})]}),e("td",{"data-label":"Status",children:e(H,{status:q(t)})}),e("td",{className:"actions menu",children:e(J,{trigger:e(b,{variant:"text",size:"small","aria-label":"Key actions",icon:e(k,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-key-menu"}),alignment:"end",portalled:!0,children:e(Q,{items:[{content:"Edit API products",onAction:()=>y({consumerKey:t.consumerKey,products:t.apiProducts.map(o=>o.id)}),dataAttributes:{"data-testid":"apigee-edit-key"}},{content:"Delete key",dangerous:!0,separatorLine:!0,onAction:()=>P(t.consumerKey),dataAttributes:{"data-testid":"apigee-delete-key"}}]})})})]},t.consumerKey)})})]})}),n.credentials.some(t=>q(t)==="approved")?e("div",{style:{marginTop:"var(--spacing-base)"},children:a(L,{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(O,{open:f,onClose:()=>g(!1),onSubmit:t=>K(this,void 0,void 0,function*(){const c=yield A.updateApp(n.id,t,h);return d(),c}),products:r,teams:l,initial:n}),e(me,{open:s!==null,onClose:()=>y(null),onSubmit:t=>K(this,void 0,void 0,function*(){const c=s?.consumerKey?yield A.updateKey(n.id,s.consumerKey,t,h):yield A.createKey(n.id,t,h);return d(),c}),products:r,initial:s?.products}),e(F,{open:p,onClose:()=>v(!1),title:"Delete app?",confirmLabel:"Delete app",danger:!0,onConfirm:()=>K(this,void 0,void 0,function*(){return yield A.deleteApp(n.id,h),u(),!0}),children:a("p",{children:[e("strong",{children:n.name})," and all of its keys stop working immediately. This cannot be undone."]})}),e(F,{open:I!==null,onClose:()=>P(null),title:"Delete key?",confirmLabel:"Delete key",danger:!0,onConfirm:()=>K(this,void 0,void 0,function*(){return I&&(yield A.deleteKey(n.id,I,h)),d(),!0}),children:e("p",{children:"Requests that send this key are rejected from now on. This cannot be undone."})})]})}export{fe as AppRow,Le as AppsView};
1
+ var T=function(t,l,r,a){function c(g){return g instanceof r?g:new r(function(d){d(g)})}return new(r||(r=Promise))(function(g,d){function h(v){try{p(a.next(v))}catch(f){d(f)}}function y(v){try{p(a.throw(v))}catch(f){d(f)}}function p(v){v.done?g(v.value):c(v.value).then(h,y)}p((a=a.apply(t,l||[])).next())})};import{Fragment as z,jsx as e,jsxs as o}from"react/jsx-runtime";import{useEffect as ce,useState as K}from"react";import{useNavigate as V}from"react-router";import{Button as b}from"@redocly/theme/components/Button/Button";import{Dropdown as ue}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as pe}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Link as me}from"@redocly/theme/components/Link/Link";import{Select as G}from"@redocly/theme/components/Select/Select";import{Tag as E}from"@redocly/theme/components/Tag/Tag";import{Tooltip as he}from"@redocly/theme/components/Tooltip/Tooltip";import{useToast as ve}from"@redocly/theme/core/hooks/use-toast";import{CDNIcon as w}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{maskKey as fe}from"../../contract.js";import{apigeeApi as _}from"../api.js";import{useApigee as M}from"../context.js";import{copyText as ge,errorMessage as J,formatDate as B,matches as ye,useSearchParam as Q,useSearchText as ke}from"../hooks.js";import{EmptyState as X,FilterSlot as Y,ListSkeleton as Z,LinkTableRow as we,ListTable as be,Mono as ee,Muted as P,NoMatches as Ae,Notice as j,Overview as Pe,PageBreadcrumbs as Se,PageHeader as te,ProductTag as ne,Row as L,SearchField as Ie,Section as Ce,SectionHeader as xe,SectionTitle as Te,StatusTag as Ke,Table as _e,TableWrap as ie,Toolbar as Ne}from"../Primitives.js";import{dropApp as De,ownerKey as U,putApp as F,useApps as ze,useTeams as H}from"../queries.js";import{AppDialog as re,ConfirmDialog as oe,KeyDialog as Le}from"./Dialogs.js";const Re="Register apps and manage the API keys that call the APIs through Apigee.",Oe=[{value:"",element:"All statuses"},{value:"approved",element:"Approved"},{value:"partial",element:"Partly approved"},{value:"pending",element:"Pending approval"},{value:"rejected",element:"Rejected"},{value:"revoked",element:"Revoked"},{value:"none",element:"No API products"}],W=3;function q(t,l){var r,a;return t.kind==="developer"?"Personal":(a=(r=l.find(c=>c.id===t.teamId))===null||r===void 0?void 0:r.name)!==null&&a!==void 0?a:t.teamId}function R(t,l){var r,a;return(a=(r=t.find(c=>c.id===l))===null||r===void 0?void 0:r.name)!==null&&a!==void 0?a:l}function ae(t){if(t.status==="revoked")return{color:"red",label:"Revoked",filter:"revoked"};const l=t.credentials.flatMap(c=>c.apiProducts);if(l.length===0)return{color:"grey",label:"No API products",filter:"none"};if(l.some(c=>c.status==="pending"))return{color:"orange",label:"Pending approval",filter:"pending"};const r=new Set(l.map(c=>c.id)).size,a=new Set(l.filter(c=>c.status==="approved").map(c=>c.id)).size;return a===r?{color:"green",label:"Approved",filter:"approved"}:a===0?{color:"red",label:"Rejected",filter:"rejected"}:{color:"blue",label:`${a} of ${r} approved`,filter:"partial"}}function de(t){if(t.status!=="approved")return t.status;const{apiProducts:l}=t;return l.some(r=>r.status==="pending")?"pending":l.length>0&&l.every(r=>r.status==="revoked")?"revoked":"approved"}const le={approved:0,pending:1,revoked:2};function se(t){const l=new Map;for(const r of t.credentials.flatMap(a=>a.apiProducts)){const a=l.get(r.id);(!a||le[r.status]<le[a])&&l.set(r.id,r.status)}return[...l].map(([r,a])=>({id:r,status:a}))}function rt({selection:t}){var l,r,a;const{link:c,appLink:g,title:d,meta:h}=M(),y=V(),p=ze(),{data:v=[]}=H(),[f,k]=K(null),[S,A]=ke(),[I,$]=Q("owner"),[N,O]=Q("status");ce(()=>{var n,u;const x=new URLSearchParams(window.location.search);x.has("createApp")&&(k({product:(n=x.get("apiProduct"))!==null&&n!==void 0?n:void 0,teamId:(u=x.get("team"))!==null&&u!==void 0?u:void 0}),y(c(),{replace:!0}))},[c,y]);const C=e(re,{open:f!==null,onClose:()=>k(null),onSubmit:n=>T(this,void 0,void 0,function*(){const u=yield _.createApp(n);return F(u),y(g(u)),u}),products:h.apiProducts,teams:v,initialProduct:f?.product,initialTeamId:f?.teamId});if(t){const n=t.teamId?`team:${t.teamId}`:"developer",u=(l=p.data)===null||l===void 0?void 0:l.find(x=>x.id===t.appId&&U(x.owner)===n);return o(z,{children:[e(Se,{additionalBreadcrumbs:[{label:d,link:c()},{label:(r=u?.name)!==null&&r!==void 0?r:t.appId}]}),u?e($e,{app:u}):p.data?e(j,{tone:"danger",children:"App not found"}):p.isError?e(j,{tone:"danger",children:J(p.error)}):e(Z,{label:"Loading the app\u2026",rows:2}),C]})}const D=(a=p.data)!==null&&a!==void 0?a:[],i=e(b,{variant:"primary",onClick:()=>k({}),icon:e(w,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New app"}),m=D.filter(n=>(!I||U(n.owner)===I)&&(!N||ae(n).filter===N)&&ye(S,n.name,n.description,...se(n).map(u=>R(h.apiProducts,u.id)))),s=[{value:"",element:"All owners"},{value:"developer",element:"Personal"},...v.map(n=>({value:`team:${n.id}`,element:n.name}))];return o(z,{children:[e(te,{title:d,description:Re,actions:p.data&&D.length===0?void 0:i}),p.data?D.length===0?e(X,{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:i}):o(z,{children:[o(Ne,{children:[e(Ie,{value:S,onChange:A,placeholder:"Search apps or API products",testId:"apigee-app-search"}),v.length>0?e(Y,{children:e(G,{value:I,options:s,onChange:n=>$(String(n)),dataTestId:"apigee-owner-filter"})}):null,e(Y,{children:e(G,{value:N,options:Oe,onChange:n=>O(String(n)),dataTestId:"apigee-status-filter"})})]}),m.length===0?e(Ae,{onClear:()=>{A(""),y(c(),{replace:!0})}}):e(je,{apps:m,showOwner:v.length>0})]}):p.isError?e(j,{tone:"danger",children:J(p.error)}):e(Z,{label:"Loading your apps\u2026"}),C]})}function je({apps:t,showOwner:l}){const{appLink:r,meta:a}=M(),{data:c=[]}=H(),g=[...t].sort((d,h)=>d.name.localeCompare(h.name));return e(ie,{children:o(be,{"data-testid":"apigee-app-list",children:[e("thead",{children:o("tr",{children:[e("th",{children:"App"}),l?e("th",{children:"Owner"}):null,e("th",{children:"API products"}),e("th",{children:"Keys"}),e("th",{children:"Status"}),e("th",{className:"chevron","aria-hidden":"true"})]})}),e("tbody",{children:g.map(d=>{const h=ae(d),y=se(d);return o(we,{to:r(d),testId:"apigee-app-row",children:[o("td",{children:[e(me,{to:r(d),children:d.name}),d.description?e(P,{as:"div",style:{maxWidth:360},children:d.description}):null]}),l?e("td",{className:"meta",children:o(L,{children:[e(w,{name:d.owner.kind==="team"?"user-group":"user",size:"14px"}),q(d.owner,c)]})}):null,e("td",{children:o(L,{children:[y.length===0?e(P,{children:"None"}):null,y.slice(0,W).map(p=>e(ne,{name:R(a.apiProducts,p.id),status:p.status},p.id)),y.length>W?o(E,{color:"grey",variant:"outline",children:["+",y.length-W]}):null]})}),e("td",{className:"optional",children:d.credentials.length}),e("td",{className:"trail",children:e(E,{color:h.color,textTransform:"none",children:h.label})}),e("td",{className:"chevron",children:e(w,{name:"chevron-right",size:"14px"})})]},`${U(d.owner)}:${d.id}`)})})]})})}function $e({app:t}){const{link:l,meta:r}=M(),a=V(),c=ve(),{data:g=[]}=H(),d=r.apiProducts,h=t.owner.kind==="team"?t.owner.teamId:void 0,[y,p]=K(!1),[v,f]=K(!1),[k,S]=K(null),[A,I]=K(null),[$,N]=K(new Set),O=(i,m)=>T(this,void 0,void 0,function*(){(yield ge(i))?c.success(`${m} copied`,{duration:2e3}):c.error(`Could not copy the ${m.toLowerCase()}`)}),C=i=>F(Object.assign(Object.assign({},t),{credentials:i})),D=i=>d.find(m=>m.id===i);return o("div",{"data-testid":"apigee-app-detail",children:[e(te,{title:o(z,{children:[t.name,t.status==="revoked"?e(E,{color:"red",children:"Revoked"}):null]}),description:t.description||void 0,actions:o(z,{children:[e(b,{variant:"outlined",onClick:()=>p(!0),icon:e(w,{name:"pen",size:"16px"}),"data-testid":"apigee-edit-app",children:"Edit"}),e(he,{tip:"Delete app",placement:"bottom",children:e(b,{variant:"outlined",tone:"danger","aria-label":"Delete app",icon:e(w,{name:"trash-can",size:"16px"}),onClick:()=>f(!0),"data-testid":"apigee-delete-app"})})]})}),o(Pe,{children:[o("div",{children:[e("dt",{children:"Owner"}),o("dd",{children:[e(w,{name:t.owner.kind==="team"?"user-group":"user",size:"16px"}),t.owner.kind==="team"?`Team \xB7 ${q(t.owner,g)}`:q(t.owner,g)]})]}),o("div",{children:[e("dt",{children:"Created"}),e("dd",{children:B(t.createdAt)})]}),o("div",{className:"wide",children:[e("dt",{children:"Callback URL"}),e("dd",{children:t.callbackUrl||e(P,{children:"Not set"})})]})]}),o(Ce,{children:[o(xe,{children:[e(Te,{children:"API keys"}),e(b,{variant:"outlined",size:"small",onClick:()=>S({}),icon:e(w,{name:"plus",size:"14px"}),"data-testid":"apigee-create-key",children:"Create key"})]}),t.credentials.length===0?e(X,{icon:"key",title:"No keys yet",text:"Create a key and pick the API products it may call."}):e(ie,{children:o(_e,{"data-testid":"apigee-keys-table",children:[e("thead",{children:o("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 m=$.has(i.consumerKey);return o("tr",{"data-testid":"apigee-key-row",children:[o("td",{className:"key",children:[o(L,{children:[e(ee,{"data-testid":"apigee-key-value",children:m?i.consumerKey:fe(i.consumerKey)}),e(b,{variant:"text",size:"small","aria-label":m?"Hide key":"Reveal key",icon:e(w,{name:m?"eye-slash":"eye",size:"14px"}),onClick:()=>N(s=>{const n=new Set(s);return n.has(i.consumerKey)?n.delete(i.consumerKey):n.add(i.consumerKey),n})}),e(b,{variant:"text",size:"small","aria-label":"Copy key",icon:e(w,{name:"copy",size:"14px"}),onClick:()=>O(i.consumerKey,"Key")})]}),i.consumerSecret?o(L,{children:[e(P,{children:"Secret"}),e(ee,{children:m?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(w,{name:"copy",size:"14px"}),onClick:()=>{var s;return O((s=i.consumerSecret)!==null&&s!==void 0?s:"","Secret")}})]}):null,o(P,{children:["Issued ",B(i.issuedAt)," \xB7 Expires"," ",i.expiresAt?B(i.expiresAt):"never"]})]}),o("td",{"data-label":"API products",children:[o(L,{children:[i.apiProducts.length===0?e(P,{children:"None"}):null,i.apiProducts.map(s=>{var n,u;return e(ne,{name:s.status==="approved"?R(d,s.id):`${R(d,s.id)} \xB7 ${s.status}`,status:s.status,to:(u=(n=D(s.id))===null||n===void 0?void 0:n.api)===null||u===void 0?void 0:u.slug},s.id)})]}),i.apiProducts.filter(s=>{var n;return(n=s.decision)===null||n===void 0?void 0:n.note}).map(s=>{var n,u;return o(P,{as:"div","data-testid":"apigee-decision-note",children:[((n=s.decision)===null||n===void 0?void 0:n.action)==="approve"?"Approved":"Rejected"," \xB7"," ",R(d,s.id),": \u201C",(u=s.decision)===null||u===void 0?void 0:u.note,"\u201D"]},s.id)})]}),e("td",{"data-label":"Status",children:e(Ke,{status:de(i)})}),e("td",{className:"actions menu",children:e(ue,{trigger:e(b,{variant:"text",size:"small","aria-label":"Key actions",icon:e(w,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-key-menu"}),alignment:"end",portalled:!0,children:e(pe,{items:[{content:"Edit API products",onAction:()=>S({consumerKey:i.consumerKey,products:i.apiProducts.map(s=>s.id)}),dataAttributes:{"data-testid":"apigee-edit-key"}},{content:"Delete key",dangerous:!0,separatorLine:!0,onAction:()=>I(i.consumerKey),dataAttributes:{"data-testid":"apigee-delete-key"}}]})})})]},i.consumerKey)})})]})}),t.credentials.some(i=>de(i)==="approved")?e("div",{style:{marginTop:"var(--spacing-base)"},children:o(j,{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(re,{open:y,onClose:()=>p(!1),onSubmit:i=>T(this,void 0,void 0,function*(){const m=yield _.updateApp(t.id,i,h);return F(m),m}),products:d,teams:g,initial:t}),e(Le,{open:k!==null,onClose:()=>S(null),onSubmit:i=>T(this,void 0,void 0,function*(){const m=k?.consumerKey;if(m){const n=yield _.updateKey(t.id,m,i,h);return C(t.credentials.map(u=>u.consumerKey===m?n:u)),n}const s=yield _.createKey(t.id,i,h);return C([...t.credentials,s]),s}),products:d,initial:k?.products}),e(oe,{open:v,onClose:()=>f(!1),title:"Delete app?",confirmLabel:"Delete app",danger:!0,onConfirm:()=>T(this,void 0,void 0,function*(){return yield _.deleteApp(t.id,h),a(l()),De(t),c.success(`${t.name} deleted`),!0}),children:o("p",{children:[e("strong",{children:t.name})," and all of its keys stop working immediately. This cannot be undone."]})}),e(oe,{open:A!==null,onClose:()=>I(null),title:"Delete key?",confirmLabel:"Delete key",danger:!0,onConfirm:()=>T(this,void 0,void 0,function*(){return A&&(yield _.deleteKey(t.id,A,h),C(t.credentials.filter(i=>i.consumerKey!==A))),!0}),children:e("p",{children:"Requests that send this key are rejected from now on. This cannot be undone."})})]})}export{Re as APPS_DESCRIPTION,je as AppsTable,rt as AppsView};
@@ -1,10 +1,8 @@
1
1
  import type { ReactElement } from 'react';
2
- import type { Team } from '../../contract.js';
3
- export declare function TeamsView({ teams, onTeamsChanged, }: {
4
- teams: Team[];
5
- onTeamsChanged: () => void;
6
- }): ReactElement;
7
- export declare function TeamDetailView({ teamId, onTeamsChanged, }: {
2
+ export type TeamTab = 'apps' | 'members';
3
+ export declare const TEAMS_DESCRIPTION = "Share apps and keys with colleagues. A team is an Apigee app group; its members manage the team's apps together.";
4
+ export declare function TeamsView(): ReactElement;
5
+ export declare function TeamDetailView({ teamId, tab }: {
8
6
  teamId: string;
9
- onTeamsChanged: () => void;
7
+ tab: TeamTab;
10
8
  }): ReactElement;
@@ -1 +1 @@
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};
1
+ var A=function(s,d,m,l){function f(r){return r instanceof m?r:new m(function(i){i(r)})}return new(m||(m=Promise))(function(r,i){function g(h){try{p(l.next(h))}catch(n){i(n)}}function c(h){try{p(l.throw(h))}catch(n){i(n)}}function p(h){h.done?r(h.value):f(h.value).then(g,c)}p((l=l.apply(s,d||[])).next())})};import{Fragment as C,jsx as e,jsxs as o}from"react/jsx-runtime";import{useState as R}from"react";import{useNavigate as _}from"react-router";import{Button as w}from"@redocly/theme/components/Button/Button";import{Dropdown as U}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as V}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Link as oe}from"@redocly/theme/components/Link/Link";import{Select as le}from"@redocly/theme/components/Select/Select";import{Tag as W}from"@redocly/theme/components/Tag/Tag";import{Tooltip as se}from"@redocly/theme/components/Tooltip/Tooltip";import{useToast as de}from"@redocly/theme/core/hooks/use-toast";import{CDNIcon as y}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as x}from"../api.js";import{useApigee as M}from"../context.js";import{errorMessage as me,formatDate as ce,matches as I,useSearchParam as pe,useSearchText as D}from"../hooks.js";import{EmptyState as O,FilterSlot as he,LinkTableRow as ue,ListSkeleton as z,ListTable as H,Muted as q,NoMatches as E,PageBreadcrumbs as ge,PageHeader as G,Row as ve,SearchField as $,TableWrap as J,Tabs as fe,Toolbar as P}from"../Primitives.js";import{changeMemberRole as be,dropTeam as K,putTeam as L,useApps as Q,useTeams as X}from"../queries.js";import{AppsTable as we}from"./AppsView.js";import{ConfirmDialog as Z,MemberDialog as ye,ROLE_OPTIONS as ee,TeamDialog as te}from"./Dialogs.js";const Te="Share apps and keys with colleagues. A team is an Apigee app group; its members manage the team's apps together.",Ce=[{value:"",element:"All roles"},{value:"owner",element:"Owners"},{value:"member",element:"Members"}];function F({role:s}){return e(W,{color:s==="owner"?"blue":"grey",children:s})}function Ve(){var s;const{link:d}=M(),m=_(),l=X(),{data:f=[]}=Q(),[r,i]=R(!1),[g,c]=D(),p=t=>d(`/teams/${encodeURIComponent(t.id)}`),h=e(w,{variant:"primary",onClick:()=>i(!0),icon:e(y,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team",children:"New team"}),n=(s=l.data)!==null&&s!==void 0?s:[],b=n.filter(t=>I(g,t.name,t.description)),k=t=>f.filter(u=>u.owner.kind==="team"&&u.owner.teamId===t).length;return o(C,{children:[e(G,{title:"Teams",description:Te,actions:l.data&&n.length===0?void 0:h}),l.data?n.length===0?e(O,{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:h}):o(C,{children:[e(P,{children:e($,{value:g,onChange:c,placeholder:"Search teams",testId:"apigee-team-search"})}),b.length===0?e(E,{onClear:()=>c("")}):e(J,{children:o(H,{"data-testid":"apigee-team-list",children:[e("thead",{children:o("tr",{children:[e("th",{children:"Team"}),e("th",{children:"Your role"}),e("th",{children:"Members"}),e("th",{children:"Apps"}),e("th",{className:"chevron","aria-hidden":"true"})]})}),e("tbody",{children:b.map(t=>o(ue,{to:p(t),testId:"apigee-team-row",children:[o("td",{children:[e(oe,{to:p(t),children:t.name}),t.description?e(q,{as:"div",style:{maxWidth:360},children:t.description}):null]}),e("td",{className:"trail",children:t.myRole?e(F,{role:t.myRole}):null}),e("td",{className:"meta","data-label":"Members",children:t.members.length}),e("td",{className:"meta","data-label":"Apps",children:k(t.id)}),e("td",{className:"chevron",children:e(y,{name:"chevron-right",size:"14px"})})]},t.id))})]})})]}):l.isError?null:e(z,{label:"Loading your teams\u2026"}),e(te,{open:r,onClose:()=>i(!1),onSubmit:t=>A(this,void 0,void 0,function*(){const u=yield x.createTeam(t);return L(u),m(d(`/teams/${encodeURIComponent(u.id)}/members`)),u})})]})}function We({teamId:s,tab:d}){var m,l,f;const{link:r,meta:i}=M(),g=_(),c=de(),p=X(),h=Q(),[n,b]=R(!1),[k,t]=R(!1),[u,S]=R(null),[ae,Y]=R(!1),a=(m=p.data)===null||m===void 0?void 0:m.find(v=>v.id===s),j=e(ge,{additionalBreadcrumbs:[{label:"Teams",link:r("/teams")},{label:(f=a?.name)!==null&&f!==void 0?f:s}]});if(!a)return o(C,{children:[j,p.data?e(O,{icon:"user-group",title:"Team not found",text:"The team was deleted, or you are no longer a member."}):p.isError?null:e(z,{label:"Loading the team\u2026",rows:3})]});const ne=a.myRole==="owner",B=`/teams/${encodeURIComponent(a.id)}`,N=(l=h.data)===null||l===void 0?void 0:l.filter(v=>v.owner.kind==="team"&&v.owner.teamId===a.id),ie=(v,T)=>be(a,v,T).then(()=>c.success("Role updated"),re=>c.error(me(re)));return o("div",{"data-testid":"apigee-team-detail",children:[j,e(G,{title:o(C,{children:[a.name,a.myRole?e(F,{role:a.myRole}):null]}),description:a.description||"Shared apps and keys for the team.",actions:ne?o(C,{children:[e(w,{variant:"outlined",onClick:()=>b(!0),icon:e(y,{name:"pen",size:"16px"}),children:"Edit team"}),e(U,{trigger:e(w,{variant:"outlined","aria-label":"More",icon:e(y,{name:"ellipsis-vertical",size:"16px"}),"data-testid":"apigee-team-menu"}),alignment:"end",children:e(V,{items:[{content:"Leave team",onAction:()=>S(i.viewer.email),dataAttributes:{"data-testid":"apigee-leave-team"}},{content:"Delete team",dangerous:!0,separatorLine:!0,onAction:()=>t(!0),dataAttributes:{"data-testid":"apigee-delete-team"}}]})})]}):e(w,{variant:"outlined",tone:"danger",onClick:()=>S(i.viewer.email),"data-testid":"apigee-leave-team",children:"Leave team"})}),e(fe,{items:[{type:"link",label:N?`Apps (${N.length})`:"Apps",link:r(B),icon:"key",active:d==="apps"},{type:"link",label:`Members (${a.members.length})`,link:r(`${B}/members`),icon:"user",active:d==="members"}]}),d==="apps"?e(ke,{team:a,apps:N}):e(Ae,{team:a,onAdd:()=>Y(!0),onRemove:S,onChangeRole:ie}),e(ye,{open:ae,onClose:()=>Y(!1),onSubmit:v=>A(this,void 0,void 0,function*(){const T=yield x.addMember(a.id,v);return L(T),T})}),e(te,{open:n,onClose:()=>b(!1),initial:a,onSubmit:v=>A(this,void 0,void 0,function*(){const T=yield x.updateTeam(a.id,v);return L(T),T})}),e(Z,{open:k,onClose:()=>t(!1),title:"Delete team?",confirmLabel:"Delete team",danger:!0,onConfirm:()=>A(this,void 0,void 0,function*(){return yield x.deleteTeam(a.id),g(r("/teams")),K(a.id),c.success(`${a.name} deleted`),!0}),children:o("p",{children:[e("strong",{children:a.name}),", its apps and all of their keys are removed from Apigee. This cannot be undone."]})}),e(Z,{open:u!==null,onClose:()=>S(null),title:u===i.viewer.email?"Leave team?":"Remove member?",confirmLabel:u===i.viewer.email?"Leave team":"Remove member",danger:!0,onConfirm:()=>A(this,void 0,void 0,function*(){if(!u)return!0;const v=yield x.removeMember(a.id,u);return u===i.viewer.email?(g(r("/teams")),K(a.id),c.success(`You left ${a.name}`)):L(v),!0}),children:e("p",{children:u===i.viewer.email?"You lose access to the team apps and their keys.":`${u} loses access to the team apps and their keys.`})})]})}function ke({team:s,apps:d}){var m;const{link:l}=M(),f=_(),[r,i]=D(),g=(m=d?.filter(c=>I(r,c.name,c.description)))!==null&&m!==void 0?m:[];return o(C,{children:[o(P,{children:[e($,{value:r,onChange:i,placeholder:"Search team apps",testId:"apigee-team-app-search"}),e(w,{variant:"primary",onClick:()=>f(l("",{createApp:"",team:s.id})),icon:e(y,{name:"plus",size:"16px"}),"data-testid":"apigee-new-team-app",children:"New team app"})]}),d?d.length===0?e(O,{icon:"key",title:"No team apps yet",text:"Create an app for this team so every member can use its keys."}):g.length===0?e(E,{onClear:()=>i("")}):e(we,{apps:g,showOwner:!1}):e(z,{label:"Loading apps\u2026",rows:2})]})}function Ae({team:s,onAdd:d,onRemove:m,onChangeRole:l}){const{meta:f}=M(),[r,i]=D(),[g,c]=pe("role"),p=s.myRole==="owner",h=s.members.filter(n=>(!g||n.role===g)&&I(r,n.email));return o(C,{children:[o(P,{children:[e($,{value:r,onChange:i,placeholder:"Search members by email",testId:"apigee-member-search"}),e(he,{children:e(le,{value:g,options:Ce,onChange:n=>c(String(n)),dataTestId:"apigee-role-filter"})}),p?e(w,{variant:"primary",onClick:d,icon:e(y,{name:"plus",size:"16px"}),"data-testid":"apigee-add-member",children:"Add member"}):null]}),h.length===0?e(E,{onClear:()=>{i(""),c("")}}):e(J,{children:o(H,{"data-testid":"apigee-members-table",children:[e("thead",{children:o("tr",{children:[e("th",{children:"Member"}),e("th",{children:"Role"}),e("th",{children:"Added"}),p?e("th",{className:"actions"}):null]})}),e("tbody",{children:h.map(n=>{var b;const k=n.email===f.viewer.email;return o("tr",{"data-testid":"apigee-member-row",children:[e("td",{children:o(ve,{children:[n.email,k?e(W,{color:"grey",children:"You"}):null]})}),e("td",{className:"trail",children:p?e(U,{trigger:e(w,{variant:"outlined",size:"small",icon:e(y,{name:"chevron-down",size:"12px"}),iconPosition:"right","data-testid":"apigee-member-role",children:(b=ee.find(t=>t.value===n.role))===null||b===void 0?void 0:b.element}),portalled:!0,children:e(V,{items:ee.map(t=>({content:t.element,active:t.value===n.role,onAction:()=>l(n.email,t.value)}))})}):e(F,{role:n.role})}),e("td",{className:"meta","data-label":"Added",children:ce(n.addedAt)}),p?e("td",{className:"actions",children:k?null:e(se,{tip:"Remove member",placement:"bottom",children:e(w,{variant:"text",size:"small",tone:"danger","aria-label":"Remove member",icon:e(y,{name:"trash-can",size:"14px"}),onClick:()=>m(n.email),"data-testid":"apigee-remove-member"})})}):null]},n.email)})})]})}),e(q,{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."})]})}export{Te as TEAMS_DESCRIPTION,We as TeamDetailView,Ve as TeamsView};
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,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};
1
+ import{createRequire as A}from"node:module";import{createInlineEntity as g,defineContentPlugin as f,isPlanClaimGranted as I,runtimeFile as _,runtimeTemplate as b}from"@redocly/framework/plugin";import{APIGEE_CONFIG_SCHEMA as G,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"),E=a.routes.metadata("title"),T=a.routes.metadata("type"),p={},m={};for(const{slug:n,canonicalSlug:P}of a.routes.all()){if(T[n]!=="openapi"||P!=="")continue;const s=d[n],u=E[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:G,templates:{[c]:b(_("./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,teamsEnabled:i.teamsEnabled,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>;
@@ -1 +1 @@
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())})},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)},C=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},I=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 L}from"../config.js";import{APIGEE_DEFAULT_KEY_LIFETIME_SECONDS as V,APIGEE_DISPLAY_NAME_ATTRIBUTE as D,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 z}from"../contract.js";import{ApigeeApiError as de}from"./client.js";import{attributesToRecord as O,recordToAttributes as K,toApiProduct as Y,toApp as S,toCredential as H}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 G(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 J(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 W(s){return oe(s).toString("base64url")}function X(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 U(s,e){var i,t,r,o;const n=X(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 C(this,R,(e=x(this,R,"f"))!==null&&e!==void 0?e:this.client.listApiProducts(),"f"),x(this,R,"f")}productPages(){var e;return C(this,j,(e=x(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"),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),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(G(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(!L(this.settings,n.name))continue;const a=this.roleFor(n.name,t,i);r||(r=T(a)),o||(o=G(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(!L(this.settings,r.name))continue;const o=this.pageFor(r,i);if(o){if(!this.ctx.isSlugVisible(o.slug))continue;t.push(Y(r,o))}else this.settings.apiProducts.allowOutsideCatalog&&t.push(Y(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(V*(d.kind==="developer"?1e3:1)),attributes:K({[D]: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[D]=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:W(24),consumerSecret:W(24),expiresInSeconds:V}),p=a.length>0?yield this.client.addKeyProducts(n,i,l.consumerKey,a.map(m=>m.id),l.attributes):l,c=H(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=H(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.indexedTeams()),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(!X(n).some(d=>d.email===this.email))continue;const a=U(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))})}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 o=t?this.withRole(U(t,e[r])):null;return o?.myRole?[o]:[]})})}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(U(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({},M(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({},M(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({},M(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({},M(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)[D];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:J(f),apiProduct:h}),owner:c},v?{requestedBy:v.requestedBy}:{}),{teamName:B(c,n),appId:l.name,appName:m||l.name,consumerKey:z(f),apiProduct:h,apiProductName:$(r,h)}),v?.note?{note:v.note}:{}),{requestedAt:(i=v?.requestedAt)!==null&&i!==void 0?i:Number(w.issuedAt)||null,canDecide:G(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=I(o,["keyDigest"]),[d,l]=yield Promise.all([this.apigeeProducts(),this.productPages()]);if(!G(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=>J(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)[D]||m.name,consumerKey:z(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=I(m,["credentials"]);for(const f of w.flatMap(v=>v.apiProducts))f.name=$(t,f.id);d.push(Object.assign(Object.assign({},h),{teamName:B(c,o),credentials:w.map(f=>{var{consumerKey:v,consumerSecret:N}=f,g=I(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=B(n.owner,r),n.apiProductName=$(i,n.apiProduct);return o})}}R=new WeakMap,j=new WeakMap;function B(s,e){return s.kind==="team"?e.get(s.teamId):void 0}function $(s,e){var i;return(i=s.find(t=>t.name===e))===null||i===void 0?void 0:i.displayName}function M(s){const{myRole:e}=s;return I(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};
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.1",
3
+ "version": "0.1.0-next.11",
4
4
  "description": "Experimental Apigee developer onboarding plugin for Redocly",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -21,24 +21,25 @@
21
21
  "apigee"
22
22
  ],
23
23
  "dependencies": {
24
- "@redocly/config": "0.74.0",
24
+ "@redocly/config": "0.75.0",
25
+ "@tanstack/react-query": "5.62.3",
25
26
  "styled-components": "^6.4.2"
26
27
  },
27
28
  "devDependencies": {
28
- "@redocly/framework": "1.0.0-next.8",
29
+ "@redocly/framework": "1.0.0-next.18",
29
30
  "@types/node": "24.1.0",
30
31
  "@types/react": "^19.2.7",
31
32
  "@types/react-dom": "^19.2.3",
32
33
  "@vitest/coverage-v8": "4.1.11",
33
34
  "esbuild-minify-dir": "0.0.1",
34
- "hono": "4.13.13",
35
+ "hono": "4.13.18",
35
36
  "rimraf": "5.0.7",
36
37
  "typescript": "6.0.3",
37
38
  "vitest": "4.1.11"
38
39
  },
39
40
  "peerDependencies": {
40
- "@redocly/framework": "^1.0.0-next.8",
41
- "@redocly/theme": "0.73.0-next.3",
41
+ "@redocly/framework": "^1.0.0-next.18",
42
+ "@redocly/theme": "0.73.0-next.13",
42
43
  "react": "^19.2.7",
43
44
  "react-dom": "^19.2.7",
44
45
  "react-router": "^8.3.0"