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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,9 +53,10 @@ export declare function Notice({ tone, children, }: {
53
53
  tone?: 'info' | 'success' | 'warning' | 'danger';
54
54
  children: ReactNode;
55
55
  }): ReactElement;
56
- export declare function StatusTag({ status, label, }: {
56
+ export declare function StatusTag({ status, label, to, }: {
57
57
  status: ApprovalStatus;
58
58
  label?: string;
59
+ to?: string;
59
60
  }): ReactElement;
60
61
  export declare const Overview: import("styled-components/dist/types.js").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDListElement>, HTMLDListElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDListElement>, HTMLDListElement>, never>>> & string;
61
62
  export declare const Stats: import("styled-components/dist/types.js").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
@@ -1,4 +1,4 @@
1
- import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"react";import r from"styled-components";import{Admonition as h}from"@redocly/theme/components/Admonition/Admonition";import{Breadcrumbs as b}from"@redocly/theme/components/Breadcrumbs/Breadcrumbs";import{Button as f}from"@redocly/theme/components/Button/Button";import{Link as u}from"@redocly/theme/components/Link/Link";import{SpinnerLoader as y}from"@redocly/theme/components/Loaders/SpinnerLoader";import{NavigationTab as w}from"@redocly/theme/components/NavigationTabs/NavigationTab";import{Portal as k}from"@redocly/theme/components/Portal/Portal";import{Tag as z}from"@redocly/theme/components/Tag/Tag";import{breakpoints as T}from"@redocly/theme/core/utils/media-css";import{CDNIcon as l}from"@redocly/theme/icons/CDNIcon/CDNIcon";const lr=r.div`
1
+ import{jsx as e,jsxs as n}from"react/jsx-runtime";import{useEffect as h}from"react";import r from"styled-components";import{Admonition as b}from"@redocly/theme/components/Admonition/Admonition";import{Breadcrumbs as f}from"@redocly/theme/components/Breadcrumbs/Breadcrumbs";import{Button as u}from"@redocly/theme/components/Button/Button";import{Link as c}from"@redocly/theme/components/Link/Link";import{SpinnerLoader as y}from"@redocly/theme/components/Loaders/SpinnerLoader";import{NavigationTab as w}from"@redocly/theme/components/NavigationTabs/NavigationTab";import{Portal as k}from"@redocly/theme/components/Portal/Portal";import{Tag as z}from"@redocly/theme/components/Tag/Tag";import{breakpoints as T}from"@redocly/theme/core/utils/media-css";import{CDNIcon as l}from"@redocly/theme/icons/CDNIcon/CDNIcon";const cr=r.div`
2
2
  width: 100%;
3
3
  max-width: 1200px;
4
4
  margin: 0 auto;
@@ -30,14 +30,14 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
30
30
  align-items: center;
31
31
  gap: var(--spacing-xs);
32
32
  flex-wrap: wrap;
33
- `;function cr({title:e,description:a,actions:i}){return t(L,{children:[t("div",{children:[o(S,{children:e}),a?o(j,{children:a}):null]}),i?o(D,{children:i}):null]})}const E=r.h2`
33
+ `;function pr({title:o,description:a,actions:i}){return n(L,{children:[n("div",{children:[e(S,{children:o}),a?e(j,{children:a}):null]}),i?e(D,{children:i}):null]})}const E=r.h2`
34
34
  margin: 0 0 var(--spacing-sm);
35
35
  font-size: var(--font-size-lg);
36
36
  line-height: var(--line-height-lg);
37
37
  font-weight: var(--font-weight-semibold);
38
- `,pr=r.section`
38
+ `,gr=r.section`
39
39
  margin-top: var(--spacing-xl);
40
- `,gr=r.div`
40
+ `,vr=r.div`
41
41
  display: flex;
42
42
  align-items: center;
43
43
  justify-content: space-between;
@@ -58,11 +58,11 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
58
58
  padding: 0;
59
59
  overflow-x: auto;
60
60
  scrollbar-width: none;
61
- `;function vr({items:e}){return o(R,{"aria-label":"Sections",children:o($,{children:e.map(a=>o(w,{tab:a},a.link))})})}const xr=r.div`
61
+ `;function xr({items:o}){return e(R,{"aria-label":"Sections",children:e($,{children:o.map(a=>e(w,{tab:a},a.link))})})}const mr=r.div`
62
62
  border: 1px solid var(--border-color-secondary);
63
63
  border-radius: var(--border-radius-xl);
64
64
  overflow-x: auto;
65
- `,mr=r.table`
65
+ `,hr=r.table`
66
66
  width: 100%;
67
67
  border-collapse: collapse;
68
68
  font-size: var(--font-size-base);
@@ -170,15 +170,15 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
170
170
  padding: 0;
171
171
  }
172
172
  }
173
- `,c=r.span`
173
+ `,p=r.span`
174
174
  color: var(--text-color-description);
175
175
  font-size: var(--font-size-sm);
176
176
  line-height: var(--line-height-sm);
177
- `,hr=r.code`
177
+ `,br=r.code`
178
178
  font-family: var(--font-family-monospaced);
179
179
  font-size: var(--font-size-sm);
180
180
  white-space: nowrap;
181
- `,br=r.div`
181
+ `,fr=r.div`
182
182
  display: flex;
183
183
  align-items: center;
184
184
  gap: var(--spacing-xs);
@@ -200,21 +200,21 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
200
200
  border: 1px solid var(--border-color-secondary);
201
201
  border-radius: var(--border-radius-lg);
202
202
  background: var(--layer-color);
203
- `,A=r.div`
203
+ `,B=r.div`
204
204
  font-weight: var(--font-weight-semibold);
205
- `;function fr({icon:e,title:a,text:i,action:n}){return t(P,{"data-testid":"apigee-empty",children:[o(W,{children:o(l,{name:e,size:"24px"})}),o(A,{children:a}),i?o(c,{style:{maxWidth:420},children:i}):null,n]})}const ur=r.label`
205
+ `;function ur({icon:o,title:a,text:i,action:t}){return n(P,{"data-testid":"apigee-empty",children:[e(W,{children:e(l,{name:o,size:"24px"})}),e(B,{children:a}),i?e(p,{style:{maxWidth:420},children:i}):null,t]})}const yr=r.label`
206
206
  display: flex;
207
207
  flex-direction: column;
208
208
  gap: var(--spacing-xxs);
209
209
  font-size: var(--font-size-base);
210
- `,B=r.span`
210
+ `,A=r.span`
211
211
  font-weight: var(--font-weight-medium);
212
212
  color: var(--text-color-secondary);
213
213
  font-size: var(--font-size-sm);
214
214
  `,I=r.span`
215
215
  margin-left: var(--spacing-xxs);
216
216
  color: var(--schema-required-color);
217
- `;function yr({children:e}){return t(B,{children:[e,o(I,{"aria-hidden":"true",children:"*"})]})}const p=`
217
+ `;function wr({children:o}){return n(A,{children:[o,e(I,{"aria-hidden":"true",children:"*"})]})}const g=`
218
218
  width: 100%;
219
219
  box-sizing: border-box;
220
220
  padding: 5px var(--spacing-sm);
@@ -237,24 +237,24 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
237
237
  &::placeholder {
238
238
  color: var(--text-color-disabled);
239
239
  }
240
- `,wr=r.input`
241
- ${p}
242
- `,kr=r.textarea`
243
- ${p}
240
+ `,kr=r.input`
241
+ ${g}
242
+ `,zr=r.textarea`
243
+ ${g}
244
244
  min-height: 72px;
245
245
  resize: vertical;
246
- `,zr=r.div`
246
+ `,Tr=r.div`
247
247
  display: flex;
248
248
  flex-direction: column;
249
249
  gap: var(--spacing-xs);
250
- `,Tr=r.label`
250
+ `,Lr=r.label`
251
251
  display: flex;
252
252
  align-items: flex-start;
253
253
  gap: var(--spacing-sm);
254
254
  padding: var(--spacing-xs) var(--spacing-sm);
255
- border: 1px solid ${({$checked:e})=>e?"var(--input-border-color-hover)":"var(--border-color-secondary)"};
255
+ border: 1px solid ${({$checked:o})=>o?"var(--input-border-color-hover)":"var(--border-color-secondary)"};
256
256
  border-radius: var(--border-radius-lg);
257
- background: ${({$checked:e})=>e?"var(--layer-color)":"transparent"};
257
+ background: ${({$checked:o})=>o?"var(--layer-color)":"transparent"};
258
258
  cursor: pointer;
259
259
 
260
260
  input {
@@ -266,7 +266,7 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
266
266
  border-color: var(--input-border-color-hover);
267
267
  background: var(--layer-color);
268
268
  }
269
- `,Lr=r.span`
269
+ `,Sr=r.span`
270
270
  display: flex;
271
271
  align-items: center;
272
272
  gap: var(--spacing-xs);
@@ -282,7 +282,7 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
282
282
  padding: var(--spacing-base);
283
283
  `,H=r.div`
284
284
  width: 100%;
285
- max-width: ${({$wide:e})=>e?"640px":"480px"};
285
+ max-width: ${({$wide:o})=>o?"640px":"480px"};
286
286
  max-height: calc(100vh - 64px);
287
287
  display: flex;
288
288
  flex-direction: column;
@@ -315,9 +315,16 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
315
315
  gap: var(--spacing-xs);
316
316
  padding: var(--spacing-base) var(--spacing-lg);
317
317
  border-top: 1px solid var(--border-color-secondary);
318
- `;function Sr({title:e,open:a,onClose:i,children:n,footer:d,wide:g,testId:v}){return m(()=>{if(!a)return;const s=x=>{x.key==="Escape"&&i()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[a,i]),a?o(k,{children:o(C,{onMouseDown:s=>s.target===s.currentTarget&&i(),children:t(H,{role:"dialog","aria-modal":"true",$wide:g,"data-testid":v,children:[t(M,{children:[o(N,{children:e}),o(f,{variant:"text",size:"small",onClick:i,"aria-label":"Close",icon:o(l,{name:"xmark",size:"16px"})})]}),o(O,{children:n}),d?o(_,{children:d}):null]})})}):null}const q=r.div`
318
+ `;function jr({title:o,open:a,onClose:i,children:t,footer:d,wide:v,testId:x}){return h(()=>{if(!a)return;const s=m=>{m.key==="Escape"&&i()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[a,i]),a?e(k,{children:e(C,{onMouseDown:s=>s.target===s.currentTarget&&i(),children:n(H,{role:"dialog","aria-modal":"true",$wide:v,"data-testid":x,children:[n(M,{children:[e(N,{children:o}),e(u,{variant:"text",size:"small",onClick:i,"aria-label":"Close",icon:e(l,{name:"xmark",size:"16px"})})]}),e(O,{children:t}),d?e(_,{children:d}):null]})})}):null}const q=r.div`
319
319
  --admonition-margin: 0;
320
- `;function jr({tone:e="info",children:a}){return o(q,{role:e==="danger"?"alert":"status","data-testid":`apigee-notice-${e}`,children:o(h,{type:e,children:a})})}const F={approved:"green",pending:"orange",revoked:"red"},U={approved:"Approved",pending:"Pending approval",revoked:"Revoked"};function Dr({status:e,label:a}){return o(z,{color:F[e],children:a??U[e]})}const Er=r.dl`
320
+ `;function Dr({tone:o="info",children:a}){return e(q,{role:o==="danger"?"alert":"status","data-testid":`apigee-notice-${o}`,children:e(b,{type:o,children:a})})}const F={approved:"green",pending:"orange",revoked:"red"},U={approved:"Approved",pending:"Pending approval",revoked:"Revoked"},K=r(c)`
321
+ display: inline-flex;
322
+ text-decoration: none;
323
+
324
+ &:hover {
325
+ text-decoration: none;
326
+ }
327
+ `;function Er({status:o,label:a,to:i}){const t=e(z,{color:F[o],selectable:!!i,children:a??U[o]});return i?e(K,{to:i,children:t}):t}const Rr=r.dl`
321
328
  display: grid;
322
329
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
323
330
  gap: var(--spacing-base);
@@ -350,12 +357,12 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
350
357
  flex-wrap: wrap;
351
358
  overflow-wrap: anywhere;
352
359
  }
353
- `,Rr=r.div`
360
+ `,$r=r.div`
354
361
  display: flex;
355
362
  gap: var(--spacing-base);
356
363
  flex-wrap: wrap;
357
364
  margin-bottom: var(--spacing-lg);
358
- `,$r=r.div`
365
+ `,Pr=r.div`
359
366
  flex: 1 1 160px;
360
367
  padding: var(--spacing-base) var(--spacing-md);
361
368
  border: 1px solid var(--border-color-secondary);
@@ -368,11 +375,11 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
368
375
  line-height: var(--line-height-xl);
369
376
  font-weight: var(--font-weight-semibold);
370
377
  }
371
- `,K=r.div`
378
+ `,G=r.div`
372
379
  display: flex;
373
380
  justify-content: center;
374
381
  padding: var(--spacing-xl);
375
- `;function Pr({label:e}){return o(K,{role:"status","aria-label":e,children:o(y,{color:"var(--text-color-description)",size:"24px"})})}const Wr=r.div`
382
+ `;function Wr({label:o}){return e(G,{role:"status","aria-label":o,children:e(y,{color:"var(--text-color-description)",size:"24px"})})}const Br=r.div`
376
383
  display: flex;
377
384
  align-items: center;
378
385
  justify-content: space-between;
@@ -380,13 +387,13 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
380
387
  font-size: var(--font-size-sm);
381
388
  font-weight: var(--font-weight-medium);
382
389
  color: var(--text-color-secondary);
383
- `,Ar=r(b)`
390
+ `,Ar=r(f)`
384
391
  margin-bottom: var(--spacing-sm);
385
- `,Br=r.div`
392
+ `,Ir=r.div`
386
393
  border: 1px solid var(--border-color-secondary);
387
394
  border-radius: var(--border-radius-xl);
388
395
  overflow: hidden;
389
- `,G=r(u)`
396
+ `,J=r(c)`
390
397
  display: flex;
391
398
  align-items: center;
392
399
  gap: var(--spacing-sm);
@@ -404,7 +411,7 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
404
411
  color: var(--text-color-primary);
405
412
  text-decoration: none;
406
413
  }
407
- `,J=r.span`
414
+ `,Q=r.span`
408
415
  display: flex;
409
416
  flex-direction: column;
410
417
  flex: 1;
@@ -415,6 +422,6 @@ import{jsx as o,jsxs as t}from"react/jsx-runtime";import{useEffect as m}from"rea
415
422
  text-overflow: ellipsis;
416
423
  white-space: nowrap;
417
424
  }
418
- `,Q=r.span`
425
+ `,V=r.span`
419
426
  font-weight: var(--font-weight-medium);
420
- `;function Ir({to:e,title:a,subtitle:i,tag:n,testId:d}){return t(G,{to:e,"data-testid":d,children:[t(J,{children:[o(Q,{children:a}),i?o(c,{children:i}):null]}),n,o(l,{name:"chevron-right",size:"14px"})]})}export{Tr as CheckItem,Lr as CheckItemTitle,zr as CheckList,Sr as Dialog,fr as EmptyState,ur as Field,B as FieldLabel,wr as Input,Br as LinkList,Ir as LinkRow,Wr as ListTitle,Pr as Loading,hr as Mono,c as Muted,jr as Notice,Er as Overview,lr as Page,Ar as PageBreadcrumbs,cr as PageHeader,yr as RequiredLabel,br as Row,pr as Section,gr as SectionHeader,E as SectionTitle,$r as Stat,Rr as Stats,Dr as StatusTag,mr as Table,xr as TableWrap,vr as Tabs,kr as Textarea};
427
+ `;function Cr({to:o,title:a,subtitle:i,tag:t,testId:d}){return n(J,{to:o,"data-testid":d,children:[n(Q,{children:[e(V,{children:a}),i?e(p,{children:i}):null]}),t,e(l,{name:"chevron-right",size:"14px"})]})}export{Lr as CheckItem,Sr as CheckItemTitle,Tr as CheckList,jr as Dialog,ur as EmptyState,yr as Field,A as FieldLabel,kr as Input,Ir as LinkList,Cr as LinkRow,Br as ListTitle,Wr as Loading,br as Mono,p as Muted,Dr as Notice,Rr as Overview,cr as Page,Ar as PageBreadcrumbs,pr as PageHeader,wr as RequiredLabel,fr as Row,gr as Section,vr as SectionHeader,E as SectionTitle,Pr as Stat,$r as Stats,Er as StatusTag,hr as Table,mr as TableWrap,xr as Tabs,zr as Textarea};
@@ -1,5 +1,5 @@
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`
1
+ var P=function(t,s,r,d){function p(v){return v instanceof r?v:new r(function(g){g(v)})}return new(r||(r=Promise))(function(v,g){function k(u){try{y(d.next(u))}catch(f){g(f)}}function h(u){try{y(d.throw(u))}catch(f){g(f)}}function y(u){u.done?v(u.value):p(u.value).then(k,h)}y((d=d.apply(t,s||[])).next())})};import{Fragment as $,jsx as e,jsxs as a}from"react/jsx-runtime";import{useEffect as V,useMemo as B,useState as x}from"react";import{useNavigate as W}from"react-router";import J from"styled-components";import{Button as w}from"@redocly/theme/components/Button/Button";import{Dropdown as Q}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as X}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Tag as E}from"@redocly/theme/components/Tag/Tag";import{Tooltip as Y}from"@redocly/theme/components/Tooltip/Tooltip";import{CDNIcon as b}from"@redocly/theme/icons/CDNIcon/CDNIcon";import{apigeeApi as I}from"../api.js";import{useApigee as Z}from"../context.js";import{maskKey as ee}from"../../contract.js";import{copyText as te,formatDate as L,useAsync as ne}from"../hooks.js";import{EmptyState as M,LinkList as ie,LinkRow as oe,ListTitle as re,Loading as ae,Mono as O,Muted as C,Notice as N,Overview as de,PageBreadcrumbs as le,PageHeader as U,Row as j,Section as se,SectionHeader as ce,SectionTitle as ue,StatusTag as H,Table as pe,TableWrap as me}from"../Primitives.js";import{AppDialog as F,ConfirmDialog as q,KeyDialog as he}from"./Dialogs.js";function ve(t,s){var r,d;return t.kind==="developer"?"Personal":`Team \xB7 ${(d=(r=s.find(p=>p.id===t.teamId))===null||r===void 0?void 0:r.name)!==null&&d!==void 0?d:t.teamId}`}function ye(t){if(t.status==="revoked")return{color:"red",label:"Revoked"};const s=t.credentials.flatMap(p=>p.apiProducts);if(s.length===0)return{color:"grey",label:"No API products"};if(s.some(p=>p.status==="pending"))return{color:"orange",label:"Pending approval"};const r=new Set(s.map(p=>p.id)).size,d=new Set(s.filter(p=>p.status==="approved").map(p=>p.id)).size;return d===r?{color:"green",label:"Approved"}:d===0?{color:"red",label:"Rejected"}:{color:"blue",label:`${d} of ${r} approved`}}function G(t){if(t.status!=="approved")return t.status;const{apiProducts:s}=t;return s.some(r=>r.status==="pending")?"pending":s.length>0&&s.every(r=>r.status==="revoked")?"revoked":"approved"}function Ne({selection:t,teams:s,products:r}){var d,p;const{link:v,title:g}=Z(),k=W(),h=ne(()=>I.listApps(),"apps"),[y,u]=x(null);V(()=>{var o,l;const n=new URLSearchParams(window.location.search);n.has("createApp")&&(u({product:(o=n.get("apiProduct"))!==null&&o!==void 0?o:void 0,teamId:(l=n.get("team"))!==null&&l!==void 0?l:void 0}),k(v(),{replace:!0}))},[v,k]);const f=B(()=>{var o;return!t||!h.data?null:(o=h.data.find(l=>l.id===t.appId&&(t.teamId?l.owner.kind==="team"&&l.owner.teamId===t.teamId:l.owner.kind==="developer")))!==null&&o!==void 0?o:null},[h.data,t]),K=B(()=>{var o;const l=((o=h.data)!==null&&o!==void 0?o:[]).filter(c=>c.owner.kind==="developer"),n=s.map(c=>{var i;return{team:c,apps:((i=h.data)!==null&&i!==void 0?i:[]).filter(m=>m.owner.kind==="team"&&m.owner.teamId===c.id)}});return{personal:l,byTeam:n}},[h.data,s]),_=o=>v(`/${encodeURIComponent(o.id)}`,o.owner.kind==="team"?{team:o.owner.teamId}:void 0),R=o=>P(this,void 0,void 0,function*(){const l=yield I.createApp(o);return h.reload(),k(_(l)),l});if(h.loading&&!h.data)return e(ae,{label:"Loading your apps\u2026"});if(h.error)return e(N,{tone:"danger",children:h.error});const T=(d=h.data)!==null&&d!==void 0?d:[],S=e(F,{open:y!==null,onClose:()=>u(null),onSubmit:R,products:r,teams:s,initialProduct:y?.product,initialTeamId:y?.teamId}),D=e(w,{variant:"primary",onClick:()=>u({}),icon:e(b,{name:"plus",size:"16px"}),"data-testid":"apigee-new-app",children:"New app"});if(t)return a($,{children:[e(le,{additionalBreadcrumbs:[{label:g,link:v()},{label:(p=f?.name)!==null&&p!==void 0?p:t.appId}]}),f?e(ke,{app:f,teams:s,products:r,onChanged:()=>h.reload(),onDeleted:()=>{h.reload(),k(v())}}):e(N,{tone:"danger",children:"App not found"}),S]});const z=[{key:"personal",title:"Personal",apps:K.personal},...K.byTeam.map(({team:o,apps:l})=>({key:`team:${o.id}`,title:`Team \xB7 ${o.name}`,apps:l}))].filter(o=>o.apps.length>0);return a($,{children:[e(U,{title:g,description:"Register apps and manage the API keys that call the APIs through Apigee.",actions:T.length>0?D:void 0}),T.length===0?e(M,{icon:"key",title:"Create your first app",text:"An app holds the API keys your software sends. Pick the API products it needs; the keys for approved products work right away.",action:D}):e(fe,{"data-testid":"apigee-app-list",children:z.map(o=>a("div",{children:[e(re,{children:o.title}),e(ie,{children:o.apps.map(l=>e(ge,{app:l,to:_(l)},l.id))})]},o.key))}),S]})}const fe=J.div`
2
2
  display: flex;
3
3
  flex-direction: column;
4
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};
5
+ `;function ge({app:t,to:s}){const r=t.credentials.length,d=ye(t);return e(oe,{to:s,title:t.name,subtitle:`${r} ${r===1?"key":"keys"}${t.description?` \xB7 ${t.description}`:""}`,tag:e(E,{color:d.color,textTransform:"none",children:d.label}),testId:"apigee-app-row"})}function ke({app:t,teams:s,products:r,onChanged:d,onDeleted:p}){const v=t.owner.kind==="team"?t.owner.teamId:void 0,[g,k]=x(!1),[h,y]=x(!1),[u,f]=x(null),[K,_]=x(null),[R,T]=x(new Set),[S,D]=x(null),z=(n,c)=>P(this,void 0,void 0,function*(){(yield te(n))&&(D(c),setTimeout(()=>D(null),1500))}),o=n=>r.find(c=>c.id===n),l=n=>{var c,i;return(i=(c=o(n))===null||c===void 0?void 0:c.name)!==null&&i!==void 0?i:n};return a("div",{"data-testid":"apigee-app-detail",children:[e(U,{title:a($,{children:[t.name,t.status==="revoked"?e(E,{color:"red",children:"Revoked"}):null]}),description:t.description||void 0,actions:a($,{children:[e(w,{variant:"outlined",onClick:()=>k(!0),icon:e(b,{name:"pen",size:"16px"}),"data-testid":"apigee-edit-app",children:"Edit"}),e(Y,{tip:"Delete app",placement:"bottom",children:e(w,{variant:"outlined",tone:"danger","aria-label":"Delete app",icon:e(b,{name:"trash-can",size:"16px"}),onClick:()=>y(!0),"data-testid":"apigee-delete-app"})})]})}),a(de,{children:[a("div",{children:[e("dt",{children:"Owner"}),a("dd",{children:[e(b,{name:t.owner.kind==="team"?"user-group":"user",size:"16px"}),ve(t.owner,s)]})]}),a("div",{children:[e("dt",{children:"Created"}),e("dd",{children:L(t.createdAt)})]}),a("div",{className:"wide",children:[e("dt",{children:"Callback URL"}),e("dd",{children:t.callbackUrl||e(C,{children:"Not set"})})]})]}),a(se,{children:[a(ce,{children:[e(ue,{children:"API keys"}),e(w,{variant:"outlined",size:"small",onClick:()=>f({}),icon:e(b,{name:"plus",size:"14px"}),"data-testid":"apigee-create-key",children:"Create key"})]}),t.credentials.length===0?e(M,{icon:"key",title:"No keys yet",text:"Create a key and pick the API products it may call."}):e(me,{children:a(pe,{"data-testid":"apigee-keys-table",children:[e("thead",{children:a("tr",{children:[e("th",{children:"Key"}),e("th",{children:"API products"}),e("th",{children:"Status"}),e("th",{className:"actions"})]})}),e("tbody",{children:t.credentials.map(n=>{const c=R.has(n.consumerKey);return a("tr",{"data-testid":"apigee-key-row",children:[a("td",{className:"key",children:[a(j,{children:[e(O,{"data-testid":"apigee-key-value",children:c?n.consumerKey:ee(n.consumerKey)}),e(w,{variant:"text",size:"small","aria-label":c?"Hide key":"Reveal key",icon:e(b,{name:c?"eye-slash":"eye",size:"14px"}),onClick:()=>T(i=>{const m=new Set(i);return m.has(n.consumerKey)?m.delete(n.consumerKey):m.add(n.consumerKey),m})}),e(w,{variant:"text",size:"small","aria-label":"Copy key",icon:e(b,{name:"copy",size:"14px"}),onClick:()=>z(n.consumerKey,`key:${n.consumerKey}`)}),S===`key:${n.consumerKey}`?e(C,{children:"Copied"}):null]}),n.consumerSecret?a(j,{children:[e(C,{children:"Secret"}),e(O,{children:c?n.consumerSecret:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),e(w,{variant:"text",size:"small","aria-label":"Copy secret",icon:e(b,{name:"copy",size:"14px"}),onClick:()=>{var i;return z((i=n.consumerSecret)!==null&&i!==void 0?i:"",`secret:${n.consumerKey}`)}}),S===`secret:${n.consumerKey}`?e(C,{children:"Copied"}):null]}):null,a(C,{children:["Issued ",L(n.issuedAt)," \xB7 Expires"," ",n.expiresAt?L(n.expiresAt):"never"]})]}),a("td",{"data-label":"API products",children:[a(j,{children:[n.apiProducts.length===0?e(C,{children:"None"}):null,n.apiProducts.map(i=>{var m,A;return e(H,{status:i.status,label:i.status==="approved"?l(i.id):`${l(i.id)} \xB7 ${i.status}`,to:(A=(m=o(i.id))===null||m===void 0?void 0:m.api)===null||A===void 0?void 0:A.slug},i.id)})]}),n.apiProducts.filter(i=>{var m;return(m=i.decision)===null||m===void 0?void 0:m.note}).map(i=>{var m,A;return a(C,{as:"div","data-testid":"apigee-decision-note",children:[((m=i.decision)===null||m===void 0?void 0:m.action)==="approve"?"Approved":"Rejected"," \xB7"," ",l(i.id),": \u201C",(A=i.decision)===null||A===void 0?void 0:A.note,"\u201D"]},i.id)})]}),e("td",{"data-label":"Status",children:e(H,{status:G(n)})}),e("td",{className:"actions menu",children:e(Q,{trigger:e(w,{variant:"text",size:"small","aria-label":"Key actions",icon:e(b,{name:"ellipsis-vertical",size:"14px"}),"data-testid":"apigee-key-menu"}),alignment:"end",portalled:!0,children:e(X,{items:[{content:"Edit API products",onAction:()=>f({consumerKey:n.consumerKey,products:n.apiProducts.map(i=>i.id)}),dataAttributes:{"data-testid":"apigee-edit-key"}},{content:"Delete key",dangerous:!0,separatorLine:!0,onAction:()=>_(n.consumerKey),dataAttributes:{"data-testid":"apigee-delete-key"}}]})})})]},n.consumerKey)})})]})}),t.credentials.some(n=>G(n)==="approved")?e("div",{style:{marginTop:"var(--spacing-base)"},children:a(N,{tone:"info",children:[e("strong",{children:"Keys are picked up by Try it."})," Open an operation of an approved API product in the API reference and the key is already filled in."]})}):null]}),e(F,{open:g,onClose:()=>k(!1),onSubmit:n=>P(this,void 0,void 0,function*(){const c=yield I.updateApp(t.id,n,v);return d(),c}),products:r,teams:s,initial:t}),e(he,{open:u!==null,onClose:()=>f(null),onSubmit:n=>P(this,void 0,void 0,function*(){const c=u?.consumerKey?yield I.updateKey(t.id,u.consumerKey,n,v):yield I.createKey(t.id,n,v);return d(),c}),products:r,initial:u?.products}),e(q,{open:h,onClose:()=>y(!1),title:"Delete app?",confirmLabel:"Delete app",danger:!0,onConfirm:()=>P(this,void 0,void 0,function*(){return yield I.deleteApp(t.id,v),p(),!0}),children:a("p",{children:[e("strong",{children:t.name})," and all of its keys stop working immediately. This cannot be undone."]})}),e(q,{open:K!==null,onClose:()=>_(null),title:"Delete key?",confirmLabel:"Delete key",danger:!0,onConfirm:()=>P(this,void 0,void 0,function*(){return K&&(yield I.deleteKey(t.id,K,v)),d(),!0}),children:e("p",{children:"Requests that send this key are rejected from now on. This cannot be undone."})})]})}export{ge as AppRow,Ne as AppsView};
@@ -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.2",
4
4
  "description": "Experimental Apigee developer onboarding plugin for Redocly",
5
5
  "author": "team@redocly.com",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -25,20 +25,20 @@
25
25
  "styled-components": "^6.4.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@redocly/framework": "1.0.0-next.8",
28
+ "@redocly/framework": "1.0.0-next.9",
29
29
  "@types/node": "24.1.0",
30
30
  "@types/react": "^19.2.7",
31
31
  "@types/react-dom": "^19.2.3",
32
32
  "@vitest/coverage-v8": "4.1.11",
33
33
  "esbuild-minify-dir": "0.0.1",
34
- "hono": "4.13.13",
34
+ "hono": "4.13.18",
35
35
  "rimraf": "5.0.7",
36
36
  "typescript": "6.0.3",
37
37
  "vitest": "4.1.11"
38
38
  },
39
39
  "peerDependencies": {
40
- "@redocly/framework": "^1.0.0-next.8",
41
- "@redocly/theme": "0.73.0-next.3",
40
+ "@redocly/framework": "^1.0.0-next.9",
41
+ "@redocly/theme": "0.73.0-next.4",
42
42
  "react": "^19.2.7",
43
43
  "react-dom": "^19.2.7",
44
44
  "react-router": "^8.3.0"