(self.webpackChunkmavunoorgbackend=self.webpackChunkmavunoorgbackend||[]).push([[924],{94456:D=>{function v(e,s,r,d){for(var c=r-1,u=e.length;++c<u;)if(d(e[c],s))return c;return-1}D.exports=v},97368:(D,v,e)=>{var s=e(12480),r=e(39024),d=e(94456),c=e(85968),u=e(4288),x=Array.prototype,A=x.splice;function y(i,C,m,Y){var w=Y?d:r,b=-1,z=C.length,E=i;for(i===C&&(C=u(C)),m&&(E=s(i,c(m)));++b<z;)for(var W=0,L=C[b],G=m?m(L):L;(W=w(E,G,W,Y))>-1;)E!==i&&A.call(E,W,1),A.call(i,W,1);return i}D.exports=y},92096:(D,v,e)=>{var s=e(12480),r=e(24020),d=e(22488),c=e(75516);function u(x,A){var y=c(x)?s:d;return y(x,r(A,3))}D.exports=u},39620:(D,v,e)=>{var s=e(41912),r=e(35140),d=s(r);D.exports=d},35140:(D,v,e)=>{var s=e(97368);function r(d,c){return d&&d.length&&c&&c.length?s(d,c):d}D.exports=r},96772:(D,v,e)=>{var s=e(35904);function r(d){var c=d==null?0:d.length;return c?s(d,1,c):[]}D.exports=r},40924:(D,v,e)=>{"use strict";e.d(v,{M:()=>ie,ProtectedEditView:()=>Ke});var s=e(19968),r=e(62552),d=e(5e3),c=e(48936),u=e(63358),x=e(28724),A=e(70996),y=e(48112),i=e(28464),C=e(35676),m=e(20436),Y=e(42616),w=e(34404),b=e(12248),z=e(32568),E=e(95840),W=e(31812),L=e(14632),G=e(49008),$=e(23792),q=e(41028),V=e(49748),K=e(55268),le=e(43164),de=e(53305),ce=e(46596),_e=e(92096),Ee=e(96772),J=e(3704),pe=e(76683),F=e(52540),ue=e(29088),ae=e(39620),He=e(54320),Ye=e(5240),be=e(91892),ze=e(36196),Je=e(20880),Ze=e(21424),Xe=e(70516),we=e(18424),qe=e(21968),es=e(12132),ss=e(48632),ts=e(85676),ns=e(35184),as=e(99568),os=e(96556),is=e(13192),rs=e(30840),ls=e(77784),ds=e(79371),cs=e(67888),_s=e(52600),Es=e(95752),ps=e(37388),us=e(61840),gs=e(49108),Ps=e(44632),Os=e(50840),ms=e(20252),hs=e(86432),As=e(22612),Ms=e(24808),Ts=e(24024),Ds=e(40960),Cs=e(33656),ys=e(43280),Is=e(79804),fs=e(19632),vs=e(29576),xs=e(61152),Ls=e(9589),Rs=e(45488),Us=e(75516);const ge=$.n.injectEndpoints({endpoints:n=>({getPermissions:n.query({query:()=>"/admin/content-api/permissions",transformResponse:t=>t.data}),getRoutes:n.query({query:()=>"/admin/content-api/routes",transformResponse:t=>t.data})}),overrideExisting:!1}),{useGetPermissionsQuery:Pe,useGetRoutesQuery:Oe}=ge,[me,he]=(0,le.G)("ApiTokenPermissionsContext"),Ae=({children:n,...t})=>(0,s.jsx)(me,{...t,children:n}),ee=()=>he("useApiTokenPermissions"),Me=({errors:n={},onChange:t,canEditInputs:a,isCreating:_,values:o={},apiToken:g={},onDispatch:l,setHasChangedPermissions:j})=>{const{formatMessage:h}=(0,L.c)(),U=({target:{value:I}})=>{j(!1),I==="full-access"&&l({type:"SELECT_ALL_ACTIONS"}),I==="read-only"&&l({type:"ON_CHANGE_READ_ONLY"})},Q=[{value:"read-only",label:{id:"Settings.tokens.types.read-only",defaultMessage:"Read-only"}},{value:"full-access",label:{id:"Settings.tokens.types.full-access",defaultMessage:"Full access"}},{value:"custom",label:{id:"Settings.tokens.types.custom",defaultMessage:"Custom"}}];return(0,s.jsx)(d.k,{background:"neutral0",hasRadius:!0,shadow:"filterShadow",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,children:(0,s.jsxs)(c.C,{direction:"column",alignItems:"stretch",gap:4,children:[(0,s.jsx)(u.O,{variant:"delta",as:"h2",children:h({id:"global.details",defaultMessage:"Details"})}),(0,s.jsxs)(x.y,{gap:5,children:[(0,s.jsx)(A.C,{col:6,xs:12,children:(0,s.jsx)(K.T,{error:n.name,value:o.name,canEditInputs:a,onChange:t})},"name"),(0,s.jsx)(A.C,{col:6,xs:12,children:(0,s.jsx)(K.a,{error:n.description,value:o.description,canEditInputs:a,onChange:t})},"description"),(0,s.jsx)(A.C,{col:6,xs:12,children:(0,s.jsx)(K.L,{isCreating:_,error:n.lifespan,value:o.lifespan,onChange:t,token:g})},"lifespan"),(0,s.jsx)(A.C,{col:6,xs:12,children:(0,s.jsx)(K.b,{value:o.type,error:n.type,label:{id:"Settings.tokens.form.type",defaultMessage:"Token type"},onChange:I=>{U({target:{value:I}}),t({target:{name:"type",value:I}})},options:Q,canEditInputs:a})},"type")]})]})})},Te=({apiTokenName:n=null})=>{const{formatMessage:t}=(0,L.c)();return(0,E.G0)(),(0,s.jsxs)(y.G,{"aria-busy":"true",children:[(0,s.jsx)(E.K8,{name:"API Tokens"}),(0,s.jsx)(i.a,{primaryAction:(0,s.jsx)(C.Z,{disabled:!0,startIcon:(0,s.jsx)(de.c,{}),type:"button",size:"L",children:t({id:"global.save",defaultMessage:"Save"})}),title:n||t({id:"Settings.apiTokens.createPage.title",defaultMessage:"Create API Token"})}),(0,s.jsx)(m.S,{children:(0,s.jsx)(E.Wm,{})})]})},De=n=>{switch(n){case"POST":return{text:"success600",border:"success200",background:"success100"};case"GET":return{text:"secondary600",border:"secondary200",background:"secondary100"};case"PUT":return{text:"warning600",border:"warning200",background:"warning100"};case"DELETE":return{text:"danger600",border:"danger200",background:"danger100"};default:return{text:"neutral600",border:"neutral200",background:"neutral100"}}},Ce=(0,J.cp)(d.k)`
  margin: -1px;
  border-radius: ${({theme:n})=>n.spaces[1]} 0 0 ${({theme:n})=>n.spaces[1]};
`,ye=({route:n={handler:"Nocontroller.error",method:"GET",path:"/there-is-no-path"}})=>{const{formatMessage:t}=(0,L.c)(),{method:a,handler:_,path:o}=n,g=o?Ee(o.split("/")):[],[l="",j=""]=_?_.split("."):[],h=De(n.method);return(0,s.jsxs)(c.C,{direction:"column",alignItems:"stretch",gap:2,children:[(0,s.jsxs)(u.O,{variant:"delta",as:"h3",children:[t({id:"Settings.apiTokens.createPage.BoundRoute.title",defaultMessage:"Bound route to"}),"\xA0",(0,s.jsx)("span",{children:l}),(0,s.jsxs)(u.O,{variant:"delta",textColor:"primary600",children:[".",j]})]}),(0,s.jsxs)(c.C,{hasRadius:!0,background:"neutral0",borderColor:"neutral200",gap:0,children:[(0,s.jsx)(Ce,{background:h.background,borderColor:h.border,padding:2,children:(0,s.jsx)(u.O,{fontWeight:"bold",textColor:h.text,children:a})}),(0,s.jsx)(d.k,{paddingLeft:2,paddingRight:2,children:_e(g,U=>(0,s.jsxs)(u.O,{textColor:U.includes(":")?"neutral600":"neutral900",children:["/",U]},U))})]})]})},Ie=()=>{const{value:{selectedAction:n,routes:t}}=ee(),{formatMessage:a}=(0,L.c)(),_=n?.split(".")[0];return(0,s.jsx)(A.C,{col:5,background:"neutral150",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,style:{minHeight:"100%"},children:n?(0,s.jsx)(c.C,{direction:"column",alignItems:"stretch",gap:2,children:_&&_ in t&&t[_].map(o=>o.config.auth?.scope?.includes(n)||o.handler===n?(0,s.jsx)(ye,{route:o},o.handler):null)}):(0,s.jsxs)(c.C,{direction:"column",alignItems:"stretch",gap:2,children:[(0,s.jsx)(u.O,{variant:"delta",as:"h3",children:a({id:"Settings.apiTokens.createPage.permissions.header.title",defaultMessage:"Advanced settings"})}),(0,s.jsx)(u.O,{as:"p",textColor:"neutral600",children:a({id:"Settings.apiTokens.createPage.permissions.header.hint",defaultMessage:"Select the application's actions or the plugin's actions and click on the cog icon to display the bound route"})})]})})},oe=(0,J.gV)`
  background: ${n=>n.theme.colors.primary100};
  svg {
    opacity: 1;
  }
`,fe=(0,J.cp)(d.k)`
  display: flex;
  justify-content: space-between;
  align-items: center;

  svg {
    opacity: 0;
    path {
      fill: ${n=>n.theme.colors.primary600};
    }
  }

  /* Show active style both on hover and when the action is selected */
  ${n=>n.isActive&&oe}
  &:hover {
    ${oe}
  }
`,ve=J.cp.div`
  flex: 1;
  align-self: center;
  border-top: 1px solid ${({theme:n})=>n.colors.neutral150};
`,xe=({controllers:n=[],label:t,orderNumber:a=0,disabled:_=!1,onExpanded:o=()=>null,indexExpandendCollapsedContent:g=null})=>{const{value:{onChangeSelectAll:l,onChange:j,selectedActions:h,setSelectedAction:U,selectedAction:Q}}=ee(),[I,Z]=r.useState(!1),{formatMessage:H}=(0,L.c)(),M=()=>{Z(O=>!O),o(a)};r.useEffect(()=>{g!==null&&g!==a&&I&&Z(!1)},[g,a,I]);const re=O=>O===Q;return(0,s.jsxs)(Y.G,{expanded:I,onToggle:M,variant:a%2?"primary":"secondary",children:[(0,s.jsx)(w.M,{title:pe(t)}),(0,s.jsx)(b.u,{children:n?.map(O=>{const f=O.actions.every(T=>h.includes(T.actionId)),R=O.actions.some(T=>h.includes(T.actionId));return(0,s.jsxs)(d.k,{children:[(0,s.jsxs)(c.C,{justifyContent:"space-between",alignItems:"center",padding:4,children:[(0,s.jsx)(d.k,{paddingRight:4,children:(0,s.jsx)(u.O,{variant:"sigma",textColor:"neutral600",children:O?.controller})}),(0,s.jsx)(ve,{}),(0,s.jsx)(d.k,{paddingLeft:4,children:(0,s.jsx)(z.y,{value:f,indeterminate:!f&&R,onValueChange:()=>{l({target:{value:[...O.actions]}})},disabled:_,children:H({id:"app.utils.select-all",defaultMessage:"Select all"})})})]}),(0,s.jsx)(x.y,{gap:4,padding:4,children:O?.actions&&O?.actions.map(T=>(0,s.jsx)(A.C,{col:6,children:(0,s.jsxs)(fe,{isActive:re(T.actionId),padding:2,hasRadius:!0,children:[(0,s.jsx)(z.y,{value:h.includes(T.actionId),name:T.actionId,onValueChange:()=>{j({target:{value:T.actionId}})},disabled:_,children:T.action}),(0,s.jsx)("button",{type:"button","data-testid":"action-cog",onClick:()=>U({target:{value:T.actionId}}),style:{display:"inline-flex",alignItems:"center"},children:(0,s.jsx)(ce.c,{})})]})},T.actionId))})]},`${t}.${O?.controller}`)})})]})},Le=({section:n=null,...t})=>{const[a,_]=r.useState(null),o=g=>_(g);return(0,s.jsx)(d.k,{padding:4,background:"neutral0",children:n&&n.map((g,l)=>(0,s.jsx)(xe,{label:g.label,controllers:g.controllers,orderNumber:l,indexExpandendCollapsedContent:a,onExpanded:o,...t},g.apiId))})},Re=({...n})=>{const{value:{data:t}}=ee(),{formatMessage:a}=(0,L.c)();return(0,s.jsxs)(x.y,{gap:0,shadow:"filterShadow",hasRadius:!0,background:"neutral0",children:[(0,s.jsxs)(A.C,{col:7,paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,children:[(0,s.jsxs)(c.C,{direction:"column",alignItems:"stretch",gap:2,children:[(0,s.jsx)(u.O,{variant:"delta",as:"h2",children:a({id:"Settings.apiTokens.createPage.permissions.title",defaultMessage:"Permissions"})}),(0,s.jsx)(u.O,{as:"p",textColor:"neutral600",children:a({id:"Settings.apiTokens.createPage.permissions.description",defaultMessage:"Only actions bound by a route are listed below."})})]}),t?.permissions&&(0,s.jsx)(Le,{section:t?.permissions,...n})]}),(0,s.jsx)(Ie,{})]})},Ue=F.kt().shape({name:F.Qb().max(100).required(E.aO.required),type:F.Qb().oneOf(["read-only","full-access","custom"]).required(E.aO.required),description:F.Qb().nullable(),lifespan:F.CQ().integer().min(0).nullable().defined(E.aO.required)}),je=n=>{const t={allActionsIds:[],permissions:[]};return t.permissions=Object.entries(n).map(([a,_])=>({apiId:a,label:a.split("::")[1],controllers:Object.keys(_.controllers).map(o=>({controller:o,actions:o in _.controllers?_.controllers[o].map(g=>{const l=`${a}.${o}.${g}`;return a.includes("api::")&&t.allActionsIds.push(l),{action:g,actionId:l}}).flat():[]})).flat()})),t},Be={data:{allActionsIds:[],permissions:[]},routes:{},selectedAction:"",selectedActions:[]},We=(n,t)=>(0,ue.cp)(n,a=>{switch(t.type){case"ON_CHANGE":{a.selectedActions.includes(t.value)?ae(a.selectedActions,t.value):a.selectedActions.push(t.value);break}case"SELECT_ALL_IN_PERMISSION":{t.value.every(o=>a.selectedActions.includes(o.actionId))?t.value.forEach(o=>{ae(a.selectedActions,o.actionId)}):t.value.forEach(o=>{a.selectedActions.push(o.actionId)});break}case"SELECT_ALL_ACTIONS":{a.selectedActions=[...a.data.allActionsIds];break}case"ON_CHANGE_READ_ONLY":{const _=a.data.allActionsIds.filter(o=>o.includes("find")||o.includes("findOne"));a.selectedActions=[..._];break}case"UPDATE_PERMISSIONS_LAYOUT":{a.data=je(t.value);break}case"UPDATE_ROUTES":{a.routes={...t.value};break}case"UPDATE_PERMISSIONS":{a.selectedActions=[...t.value];break}case"SET_SELECTED_ACTION":{a.selectedAction=t.value;break}default:return a}}),ie=()=>{(0,E.G0)();const{formatMessage:n}=(0,L.c)(),t=(0,E.eo)(),{lockApp:a,unlockApp:_}=(0,E.H6)(),{state:o}=(0,G.IT)(),g=(0,$.j)(p=>p.admin_app.permissions),[l,j]=r.useState(o?.apiToken?.accessKey?{...o.apiToken}:null),{trackUsage:h}=(0,E.m4)(),{setCurrentStep:U}=(0,E.sg)(),{allowedActions:{canCreate:Q,canUpdate:I,canRegenerate:Z}}=(0,E.aU)(g.settings?.["api-tokens"]),[H,M]=r.useReducer(We,Be),O=(0,G.SU)("/settings/api-tokens/:id")?.params?.id,f=O==="create",{_unstableFormatAPIError:R,_unstableFormatValidationErrors:T}=(0,E.An)(),Se=(0,G.Uz)(),S=Pe(),k=Oe();r.useEffect(()=>{S.error&&t({type:"warning",message:R(S.error)})},[S.error,R,t]),r.useEffect(()=>{k.error&&t({type:"warning",message:R(k.error)})},[k.error,R,t]),r.useEffect(()=>{S.data&&M({type:"UPDATE_PERMISSIONS_LAYOUT",value:S.data})},[S.data]),r.useEffect(()=>{k.data&&M({type:"UPDATE_ROUTES",value:k.data})},[k.data]),r.useEffect(()=>{l&&(l.type==="read-only"&&M({type:"ON_CHANGE_READ_ONLY"}),l.type==="full-access"&&M({type:"SELECT_ALL_ACTIONS"}),l.type==="custom"&&M({type:"UPDATE_PERMISSIONS",value:l?.permissions}))},[l]),r.useEffect(()=>{h(f?"didAddTokenFromList":"didEditTokenFromList",{tokenType:V.A})},[f,h]);const{data:B,error:se,isLoading:ke}=(0,q.b)(O,{skip:!O||f||!!l});r.useEffect(()=>{se&&t({type:"warning",message:R(se)})},[se,R,t]),r.useEffect(()=>{B&&(j(B),B.type==="read-only"&&M({type:"ON_CHANGE_READ_ONLY"}),B.type==="full-access"&&M({type:"SELECT_ALL_ACTIONS"}),B.type==="custom"&&M({type:"UPDATE_PERMISSIONS",value:B?.permissions}))},[B]);const[Ne]=(0,q.c)(),[Ge]=(0,q.d)(),$e=async(p,N)=>{h(f?"willCreateToken":"willEditToken",{tokenType:V.A}),a();try{if(f){const P=await Ne({...p,lifespan:p?.lifespan||null,permissions:p.type==="custom"?H.selectedActions:null});if("error"in P){(0,$.x)(P.error)&&P.error.name==="ValidationError"?N.setErrors(T(P.error)):t({type:"warning",message:R(P.error)});return}t({type:"success",message:n({id:"notification.success.apitokencreated",defaultMessage:"API Token successfully created"})}),h("didCreateToken",{type:P.data.type,tokenType:V.A}),Se.replace(`/settings/api-tokens/${P.data.id}`,{apiToken:P.data}),U("apiTokens.success")}else{const P=await Ge({id:O,name:p.name,description:p.description,type:p.type,permissions:p.type==="custom"?H.selectedActions:null});if("error"in P){(0,$.x)(P.error)&&P.error.name==="ValidationError"?N.setErrors(T(P.error)):t({type:"warning",message:R(P.error)});return}t({type:"success",message:n({id:"notification.success.apitokenedited",defaultMessage:"API Token successfully edited"})}),h("didEditToken",{type:P.data.type,tokenType:V.A})}}catch{t({type:"warning",message:{id:"notification.error",defaultMessage:"Something went wrong"}})}finally{_()}},[Ve,te]=r.useState(!1),Fe={...H,onChange:({target:{value:p}})=>{te(!0),M({type:"ON_CHANGE",value:p})},onChangeSelectAll:({target:{value:p}})=>{te(!0),M({type:"SELECT_ALL_IN_PERMISSION",value:p})},setSelectedAction:({target:{value:p}})=>{M({type:"SET_SELECTED_ACTION",value:p})}},ne=I&&!f||Q&&f;return ke?(0,s.jsx)(Te,{apiTokenName:l?.name}):(0,s.jsx)(Ae,{value:Fe,children:(0,s.jsxs)(y.G,{children:[(0,s.jsx)(E.K8,{name:"API Tokens"}),(0,s.jsx)(W.QJ,{validationSchema:Ue,validateOnChange:!1,initialValues:{name:l?.name||"",description:l?.description||"",type:l?.type,lifespan:l?.lifespan},enableReinitialize:!0,onSubmit:(p,N)=>$e(p,N),children:({errors:p,handleChange:N,isSubmitting:P,values:X,setFieldValue:Qe})=>(Ve&&X?.type!=="custom"&&Qe("type","custom"),(0,s.jsxs)(E.QF,{children:[(0,s.jsx)(K.F,{backUrl:"/settings/api-tokens",title:{id:"Settings.apiTokens.createPage.title",defaultMessage:"Create API Token"},token:l,setToken:j,canEditInputs:ne,canRegenerate:Z,isSubmitting:P,regenerateUrl:"/admin/api-tokens/"}),(0,s.jsx)(m.S,{children:(0,s.jsxs)(c.C,{direction:"column",alignItems:"stretch",gap:6,children:[Boolean(l?.name)&&(0,s.jsx)(K.c,{token:l?.accessKey,tokenType:V.A}),(0,s.jsx)(Me,{errors:p,onChange:N,canEditInputs:ne,isCreating:f,values:X,apiToken:l,onDispatch:M,setHasChangedPermissions:te}),(0,s.jsx)(Re,{disabled:!ne||X?.type==="read-only"||X?.type==="full-access"})]})})]}))})]})})},Ke=()=>{const n=(0,$.j)(t=>t.admin_app.permissions.settings?.["api-tokens"].read);return(0,s.jsx)(E.rF,{permissions:n,children:(0,s.jsx)(ie,{})})}},41028:(D,v,e)=>{"use strict";e.d(v,{a:()=>x,b:()=>c,c:()=>u,d:()=>A,u:()=>d});var s=e(23792);const r=s.n.injectEndpoints({endpoints:y=>({getAPITokens:y.query({query:()=>"/admin/api-tokens",transformResponse:i=>i.data,providesTags:(i,C)=>[...i?.map(({id:m})=>({type:"ApiToken",id:m}))??[],{type:"ApiToken",id:"LIST"}]}),getAPIToken:y.query({query:i=>`/admin/api-tokens/${i}`,transformResponse:i=>i.data,providesTags:(i,C,m)=>[{type:"ApiToken",id:m}]}),createAPIToken:y.mutation({query:i=>({url:"/admin/api-tokens",method:"POST",data:i}),transformResponse:i=>i.data,invalidatesTags:[{type:"ApiToken",id:"LIST"}]}),deleteAPIToken:y.mutation({query:i=>({url:`/admin/api-tokens/${i}`,method:"DELETE"}),transformResponse:i=>i.data,invalidatesTags:(i,C,m)=>[{type:"ApiToken",id:m}]}),updateAPIToken:y.mutation({query:({id:i,...C})=>({url:`/admin/api-tokens/${i}`,method:"PUT",data:C}),transformResponse:i=>i.data,invalidatesTags:(i,C,{id:m})=>[{type:"ApiToken",id:m}]})}),overrideExisting:!1}),{useGetAPITokensQuery:d,useGetAPITokenQuery:c,useCreateAPITokenMutation:u,useDeleteAPITokenMutation:x,useUpdateAPITokenMutation:A}=r}}]);
