@kong-ui-public/entities-consumers 3.5.66 → 3.5.67
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.
|
@@ -39,7 +39,7 @@ const at = {
|
|
|
39
39
|
},
|
|
40
40
|
delete: {
|
|
41
41
|
title: "Delete a Consumer",
|
|
42
|
-
description: "Deleting this consumer will also remove this consumer from any associated consumer group. This action cannot be reversed."
|
|
42
|
+
description: "Deleting this consumer will also remove this consumer from any associated consumer group and delete all its plugins. This action cannot be reversed."
|
|
43
43
|
},
|
|
44
44
|
consumer_groups: {
|
|
45
45
|
add: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(N,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vue-router"),require("@kong/icons"),require("@kong-ui-public/i18n"),require("@kong-ui-public/entities-shared")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router","@kong/icons","@kong-ui-public/i18n","@kong-ui-public/entities-shared"],e):(N=typeof globalThis<"u"?globalThis:N||self,e(N["kong-ui-public-entities-consumers"]={},N.Vue,N.VueRouter,N.KongIcons,N["kong-ui-public-i18n"],N["kong-ui-public-entities-shared"]))})(this,function(N,e,re,pe,se,p){"use strict";const fe={consumers:{list:{table_headers:{username:"Username",custom_id:"Custom ID",tags:"Tags",id:"ID"},empty_state:{title:"Configure a New Consumer",description:"Consumers are the end users of a service.",title_for_consumer_group:"Configure a New Consumer"},toolbar_actions:{new_consumer:"New Consumer"}},title:"Consumers",search:{placeholder:{konnect:"Filter by name",kongManager:"Filter by exact username or ID"}},actions:{add_consumer:"Add Consumer",create:"New Consumer",copy_id:"Copy ID",copy_json:"Copy JSON",edit:"Edit",delete:"Delete",remove:"Remove",view:"View Details"},delete:{title:"Delete a Consumer",description:"Deleting this consumer will also remove this consumer from any associated consumer group. This action cannot be reversed."},consumer_groups:{add:{title:"Add Consumers",ctaText:"Add consumers to this group",consumers_label:"Consumers",consumer_placeholder:"Add consumer",footer:"Search by exact name or ID to find consumers not included in the list"},remove:{title:"Remove a Consumer",confirmation:"Are you sure you want to remove this consumer {consumer} from consumer group {consumerGroup}?",confirmationNoCG:"Are you sure you want to remove this consumer {consumer} from this consumer group?",description:"Removing this consumer from the group could change the rate limit policy applied to this consumer."}},errors:{general:"Consumers could not be retrieved",delete:"The consumer could not be deleted at this time.",copy:"Failed to copy to clipboard",add:"Some consumers could not be added at this time.",already_added:"This consumer has already been added to the consumer group"},copy:{success:"Copied {val} to clipboard",success_brief:"Successfully copied to clipboard"},form:{title:"Consumer Identification",info:{title:"General Information",description:"General information will help identify and manage added consumer."},consumer_identification:{title:"Consumer Identification",description:"A consumer can have both unique username and unique custom ID or one of them."}},fields:{username:{label:"Username",placeholder:"Enter a unique username",tooltip:"The unique username of the Consumer. You must send either this field or {custom_id} with the request.",custom_id:"custom_id"},custom_id:{label:"Custom ID",placeholder:"Enter a unique custom ID",tooltip:"Field for storing an existing unique ID for the Consumer - useful for mapping Kong with users in your existing database. You must send either this field or {username} with the request.",username:"username"},tags:{label:"Tags",placeholder:"Enter a list of tags separated by comma",help:"e.g. tag1, tag2, tag3",tooltip:"An optional set of strings associated with the Consumer for grouping and filtering."}}}};function ge(){const t=se.createI18n("en-us",fe);return{i18n:t,i18nT:se.i18nTComponent(t)}}const z={useI18n:ge},L="/v2/control-planes/{controlPlaneId}/core-entities",W="/{workspace}",P={list:{konnect:{all:`${L}/consumers`,forConsumerGroup:`${L}/consumer_groups/{consumerGroupId}/consumers`,oneForConsumerGroup:`${L}/consumer_groups/{consumerGroupId}/consumers/{consumerId}`},kongManager:{all:`${W}/consumers`,forConsumerGroup:`${W}/consumer_groups/{consumerGroupId}/consumers`,oneForConsumerGroup:`${W}/consumer_groups/{consumerGroupId}/consumers/{consumerId}`}},form:{konnect:{validate:`${L}/v1/schemas/json/consumer/validate`,create:`${L}/consumers`,edit:`${L}/consumers/{id}`},kongManager:{validate:`${W}/schemas/consumers/validate`,create:`${W}/consumers`,edit:`${W}/consumers/{id}`}}},ye={class:"add-consumer-form-container"},he={class:"add-consumer-form-cta"},Ce={class:"select-item-label"},be={key:0,class:"select-item-desc"},ke={key:0,class:"kong-ui-entity-add-consumers-error"},_e={key:0},Ie=e.defineComponent({__name:"AddConsumerModal",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||!t.consumerGroupId)},visible:{type:Boolean,required:!0,default:!1}},emits:["cancel","add:success","add:partial-success","error"],setup(t,{emit:u}){var C;const{i18n:{t:s}}=z.useI18n(),o=t,w=u,{axiosInstance:r}=p.useAxios((C=o.config)==null?void 0:C.axiosRequestConfig),I=e.ref([]),{debouncedQueryChange:V,loading:B,allRecords:T,error:d,loadItems:H,results:U}=p.useDebouncedFilter(o.config,P.list[o.config.app].all,"",{fetchedItemsKey:"data",searchKeys:["username","id"]}),M=l=>l,J=e.computed(()=>d.value?s("consumers.errors.general"):""),E=e.ref(0),q=e.computed(()=>T.value===void 0),K=e.computed(()=>U.value.map(l=>({label:l.username||l.customId,value:l.id,selected:I.value.includes(l.id),data:l}))),A=l=>{var f;const m=q.value?U.value.find(b=>b.id===l):(f=T.value)==null?void 0:f.find(b=>b.id===l);return m?m.username||m.custom_id:l},Q=()=>{$.value="",x.value=[],g.value=[],w("cancel")},x=e.ref([]),D=e.ref(!1),$=e.ref(""),O=async()=>{if(!I.value.length){$.value="",g.value=[],w("cancel");return}D.value=!0,$.value="",x.value=[],g.value=[];try{const l=I.value.map(b=>i(b)),m=await Promise.allSettled(l);let f=!0;m.forEach(b=>{b.status!=="fulfilled"&&(f=!1)}),f?(x.value=[],g.value=[],w("add:success",I.value),I.value=[]):(x.value.length&&w("add:partial-success",x.value),I.value=[],G(m))}catch{$.value=s("consumers.errors.add"),w("error",$.value)}finally{D.value=!1}},a=e.computed(()=>{var m,f,b,j;let l=`${o.config.apiBaseUrl}${P.list[o.config.app].forConsumerGroup}`;return o.config.app==="konnect"?l=l.replace(/{controlPlaneId}/gi,((m=o.config)==null?void 0:m.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((f=o.config)==null?void 0:f.consumerGroupId)||""):o.config.app==="kongManager"&&(l=l.replace(/\/{workspace}/gi,(b=o.config)!=null&&b.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((j=o.config)==null?void 0:j.consumerGroupId)||"")),l}),i=async l=>{const m={consumer:l};try{const f=await r.post(a.value,m);return x.value.push(l),f}catch(f){let b=`${A(l)} - ${f.message}`;return f.response.status===409&&(b=`${A(l)} - ${s("consumers.errors.already_added")}`),Promise.reject(Error(b))}},g=e.ref([]),G=l=>{g.value=l.map(m=>{var f;return(f=m.reason)==null?void 0:f.message}).filter(Boolean)};return e.watch(K,()=>{E.value++},{immediate:!0,deep:!0}),e.watch(()=>o.visible,()=>{o.visible&&H()},{immediate:!0}),(l,m)=>{const f=e.resolveComponent("KMultiselect"),b=e.resolveComponent("KAlert"),j=e.resolveComponent("KPrompt");return e.openBlock(),e.createBlock(j,{"action-button-disabled":D.value,class:"kong-ui-entities-add-consumers-modal","data-testid":"add-consumer-modal",title:e.unref(s)("consumers.consumer_groups.add.title"),visible:t.visible,onCancel:Q,onProceed:O},{default:e.withCtx(()=>[e.createElementVNode("div",ye,[e.createElementVNode("p",he,e.toDisplayString(e.unref(s)("consumers.consumer_groups.add.ctaText")),1),e.createVNode(f,{modelValue:I.value,"onUpdate:modelValue":m[0]||(m[0]=S=>I.value=S),autosuggest:"","data-testid":"add-consumers-multiselect","dropdown-footer-text":q.value?e.unref(s)("consumers.consumer_groups.add.footer"):void 0,items:K.value,label:e.unref(s)("consumers.consumer_groups.add.consumers_label"),loading:e.unref(B),placeholder:e.unref(s)("consumers.consumer_groups.add.consumer_placeholder"),readonly:D.value,required:"",width:"100%",onQueryChange:e.unref(V)},{"item-template":e.withCtx(({item:S})=>[e.createElementVNode("div",Ce,e.toDisplayString(S.label),1),M(S).data.username&&M(S).data.custom_id?(e.openBlock(),e.createElementBlock("div",be,e.toDisplayString(M(S).data.custom_id),1)):e.createCommentVNode("",!0)]),_:1},8,["modelValue","dropdown-footer-text","items","label","loading","placeholder","readonly","onQueryChange"]),$.value||J.value||g.value.length?(e.openBlock(),e.createElementBlock("div",ke,[e.createVNode(b,{appearance:"danger"},{default:e.withCtx(()=>[e.createElementVNode("p",null,e.toDisplayString(e.unref(s)("consumers.errors.add")),1),g.value.length?(e.openBlock(),e.createElementBlock("ul",_e,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(g.value,(S,v)=>(e.openBlock(),e.createElementBlock("li",{key:v},e.toDisplayString(S),1))),128))])):e.createCommentVNode("",!0),e.createElementVNode("div",null,e.toDisplayString($.value||J.value),1)]),_:1})])):e.createCommentVNode("",!0)])]),_:1},8,["action-button-disabled","title","visible"])}}}),X=(t,u)=>{const s=t.__vccOpts||t;for(const[o,w]of u)s[o]=w;return s},Ve=X(Ie,[["__scopeId","data-v-d54468ab"]]),we={class:"kong-ui-entities-consumers-list"},xe=X(e.defineComponent({__name:"ConsumerList",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||!t.createRoute||!t.getViewRoute||!t.getEditRoute||t.app==="kongManager"&&!t.isExactMatch&&!t.filterSchema)},cacheIdentifier:{type:String,default:""},canCreate:{type:Function,required:!1,default:async()=>!0},canDelete:{type:Function,required:!1,default:async()=>!0},canEdit:{type:Function,required:!1,default:async()=>!0},canRetrieve:{type:Function,required:!1,default:async()=>!0},useActionOutside:{type:Boolean,default:!1}},emits:["error","copy:success","copy:error","delete:success","add:success","remove:success"],setup(t,{emit:u}){var me;const s=u,o=t,{i18nT:w,i18n:{t:r}}=z.useI18n(),I=re.useRouter(),{axiosInstance:V}=p.useAxios((me=o.config)==null?void 0:me.axiosRequestConfig),B=e.computed(()=>o.config.app!=="kongManager"||!!o.config.disableSorting),T={username:{label:r("consumers.list.table_headers.username"),searchable:!0,sortable:!0,hidable:!1},custom_id:{label:r("consumers.list.table_headers.custom_id"),searchable:!0,sortable:!0},tags:{label:r("consumers.list.table_headers.tags"),sortable:!1}},d=T,H=n=>({"data-testid":n.username??n.custom_id??n.id}),U=e.computed(()=>{var c,h,k,F;let n=`${o.config.apiBaseUrl}${P.list[o.config.app][E.value?"forConsumerGroup":"all"]}`;return o.config.app==="konnect"?n=n.replace(/{controlPlaneId}/gi,((c=o.config)==null?void 0:c.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((h=o.config)==null?void 0:h.consumerGroupId)||""):o.config.app==="kongManager"&&(n=n.replace(/\/{workspace}/gi,(k=o.config)!=null&&k.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((F=o.config)==null?void 0:F.consumerGroupId)||"")),n}),M=e.ref(""),J=e.computed(()=>{const n=o.config.app==="konnect"||o.config.isExactMatch;return n?{isExactMatch:n,placeholder:r(`consumers.search.placeholder.${o.config.app}`)}:{isExactMatch:n,fields:{username:T.username,custom_id:T.custom_id},schema:o.config.filterSchema}}),E=e.computed(()=>!!o.config.consumerGroupId),q=e.computed(()=>E.value?"kong-ui-entities-consumers-list-in-group-page":"kong-ui-entities-consumers-list"),K=e.computed(()=>E.value&&!o.config.paginatedEndpoint?"consumers":void 0),{fetcher:A,fetcherState:Q,fetcherCacheKey:x}=p.useFetcher({...o.config,cacheIdentifier:o.cacheIdentifier},U.value,K.value),D=()=>{M.value=""},$=()=>{x.value++},O=n=>n??"-",a=e.ref(null),i=(n,c)=>{const h=n.id;if(!c(h)){s("copy:error",{entity:n,field:"id",message:r("consumers.errors.copy")});return}s("copy:success",{entity:n,field:"id",message:r("consumers.copy.success",{val:h})})},g=(n,c)=>{const h=JSON.stringify(n);if(!c(h)){s("copy:error",{entity:n,message:r("consumers.errors.copy")});return}s("copy:success",{entity:n,message:r("consumers.copy.success_brief")})},G=async n=>{var h;await((h=o.canRetrieve)==null?void 0:h.call(o,n))&&I.push(o.config.getViewRoute(n.id))},C=n=>({label:r("consumers.actions.view"),to:o.config.getViewRoute(n)}),l=n=>({label:r("consumers.actions.edit"),to:o.config.getEditRoute(n)}),m=e.ref(void 0),f=e.ref(!1),b=e.ref(!1),j=e.ref(""),S=p.useDeleteUrlBuilder(o.config,U.value),v=n=>{m.value=n,f.value=!0},Pe=()=>{f.value=!1},Ue=async()=>{var n,c,h;if((n=m.value)!=null&&n.id){b.value=!0;try{await V.delete(S(m.value.id)),b.value=!1,f.value=!1,x.value++,s("delete:success",m.value)}catch(k){j.value=((h=(c=k.response)==null?void 0:c.data)==null?void 0:h.message)||k.message||r("consumers.errors.delete"),s("error",k)}finally{b.value=!1}}},ee=e.ref(!1),ie=()=>{ee.value=!0},le=()=>{ee.value=!1},ce=(n,c)=>{c||le(),x.value++,s("add:success",n)},qe=()=>{E.value&&ie()},R=e.ref(void 0),te=e.ref(!1),Ke=e.ref(""),Oe=n=>{R.value=n,te.value=!0},ue=()=>{te.value=!1,R.value=void 0},je=e.computed(()=>{var c,h,k,F;let n=`${o.config.apiBaseUrl}${P.list[o.config.app].oneForConsumerGroup}`;return o.config.app==="konnect"?n=n.replace(/{controlPlaneId}/gi,((c=o.config)==null?void 0:c.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((h=o.config)==null?void 0:h.consumerGroupId)||""):o.config.app==="kongManager"&&(n=n.replace(/\/{workspace}/gi,(k=o.config)!=null&&k.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((F=o.config)==null?void 0:F.consumerGroupId)||"")),n}),de=e.ref(!1),Le=async()=>{if(R.value){de.value=!0;try{const n=je.value.replace(/{consumerId}/gi,R.value.id);await V.delete(n),s("remove:success",R.value),ue(),x.value++}catch(n){Ke.value=n.message||r("consumers.errors.delete"),s("error",n)}finally{de.value=!1}}};e.watch(Q,n=>{var c,h,k;if(n.status===p.FetcherStatus.Error){a.value={title:r("consumers.errors.general")},(k=(h=(c=n.error)==null?void 0:c.response)==null?void 0:h.data)!=null&&k.message&&(a.value.message=n.error.response.data.message),s("error",n.error);return}a.value=null});const oe=e.ref({ctaPath:E.value?void 0:o.config.createRoute,ctaText:void 0,message:`${r("consumers.list.empty_state.description")}${o.config.additionMessageForEmptyState?` ${o.config.additionMessageForEmptyState}`:""}`,title:r("consumers.title")});return e.onBeforeMount(async()=>{await o.canCreate()&&(oe.value.title=E.value?r("consumers.list.empty_state.title_for_consumer_group"):r("consumers.list.empty_state.title"),oe.value.ctaText=E.value?r("consumers.actions.add_consumer"):r("consumers.actions.create"))}),(n,c)=>{const h=e.resolveComponent("KButton"),k=e.resolveComponent("KDropdownItem"),F=e.resolveComponent("KClipboardProvider"),We=e.resolveComponent("KPrompt");return e.openBlock(),e.createElementBlock("div",we,[e.createVNode(e.unref(p.EntityBaseTable),{"cache-identifier":t.cacheIdentifier,"disable-sorting":B.value,"empty-state-options":oe.value,"enable-entity-actions":"","error-message":a.value,fetcher:e.unref(A),"fetcher-cache-key":e.unref(x),"hide-pagination":E.value&&!t.config.paginatedEndpoint,"pagination-type":"offset","preferences-storage-key":q.value,query:M.value,"row-attributes":H,"table-headers":e.unref(d),onClearSearchInput:D,"onClick:row":c[2]||(c[2]=y=>G(y)),onEmptyStateCtaClicked:qe,onSort:$},{"toolbar-filter":e.withCtx(()=>[E.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(e.unref(p.EntityFilter),{key:0,modelValue:M.value,"onUpdate:modelValue":c[0]||(c[0]=y=>M.value=y),config:J.value},null,8,["modelValue","config"]))]),"toolbar-button":e.withCtx(()=>[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!t.useActionOutside,to:"#kong-ui-app-page-header-action-button"},[e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canCreate()},{default:e.withCtx(()=>[e.createVNode(h,{appearance:"primary","data-testid":"toolbar-add-consumer",size:t.useActionOutside?"medium":"large",to:t.config.consumerGroupId?void 0:t.config.createRoute,onClick:c[1]||(c[1]=()=>t.config.consumerGroupId?ie():void 0)},{default:e.withCtx(()=>[e.createVNode(e.unref(pe.AddIcon)),e.createTextVNode(" "+e.toDisplayString(t.config.consumerGroupId?e.unref(r)("consumers.actions.add_consumer"):e.unref(r)("consumers.list.toolbar_actions.new_consumer")),1)]),_:1},8,["size","to"])]),_:1},8,["auth-function"])],8,["disabled"]))]),username:e.withCtx(({rowValue:y})=>[e.createElementVNode("b",null,e.toDisplayString(O(y)),1)]),custom_id:e.withCtx(({rowValue:y})=>[e.createTextVNode(e.toDisplayString(O(y)),1)]),tags:e.withCtx(({rowValue:y})=>[e.createVNode(e.unref(p.TableTags),{tags:y},null,8,["tags"])]),actions:e.withCtx(({row:y})=>[e.createVNode(F,null,{default:e.withCtx(({copyToClipboard:ne})=>[e.createVNode(k,{"data-testid":"action-entity-copy-id",onClick:He=>i(y,ne)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(r)("consumers.actions.copy_id")),1)]),_:2},1032,["onClick"])]),_:2},1024),e.createVNode(F,null,{default:e.withCtx(({copyToClipboard:ne})=>[e.createVNode(k,{"data-testid":"action-entity-copy-json",onClick:He=>g(y,ne)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(r)("consumers.actions.copy_json")),1)]),_:2},1032,["onClick"])]),_:2},1024),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canRetrieve(y)},{default:e.withCtx(()=>[e.createVNode(k,{"data-testid":"action-entity-view","has-divider":"",item:C(y.id)},null,8,["item"])]),_:2},1032,["auth-function"]),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canEdit(y)},{default:e.withCtx(()=>[e.createVNode(k,{"data-testid":"action-entity-edit",item:l(y.id)},null,8,["item"])]),_:2},1032,["auth-function"]),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canDelete(y)},{default:e.withCtx(()=>[e.createVNode(k,{danger:"","data-testid":"action-entity-delete","has-divider":"",onClick:()=>t.config.consumerGroupId?Oe(y):v(y)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.config.consumerGroupId?e.unref(r)("consumers.actions.remove"):e.unref(r)("consumers.actions.delete")),1)]),_:2},1032,["onClick"])]),_:2},1032,["auth-function"])]),_:1},8,["cache-identifier","disable-sorting","empty-state-options","error-message","fetcher","fetcher-cache-key","hide-pagination","preferences-storage-key","query","table-headers"]),e.createVNode(e.unref(p.EntityDeleteModal),{"action-button-disabled":b.value,"data-testid":"delete-consumer-modal",description:e.unref(r)("consumers.delete.description"),"entity-name":m.value&&(m.value.username||m.value.custom_id||m.value.id),"entity-type":e.unref(p.EntityTypes).Consumer,error:j.value,title:e.unref(r)("consumers.delete.title"),visible:f.value,onCancel:Pe,onProceed:Ue},null,8,["action-button-disabled","description","entity-name","entity-type","error","title","visible"]),t.config.consumerGroupId?(e.openBlock(),e.createBlock(Ve,{key:0,config:t.config,"data-testid":"add-consumer-modal",visible:ee.value,"onAdd:partialSuccess":c[3]||(c[3]=y=>ce(y,!0)),"onAdd:success":c[4]||(c[4]=y=>ce(y)),onCancel:le},null,8,["config","visible"])):e.createCommentVNode("",!0),t.config.consumerGroupId&&R.value?(e.openBlock(),e.createBlock(We,{key:1,"action-button-appearance":"danger","data-testid":"remove-consumer-modal",title:e.unref(r)("consumers.consumer_groups.remove.title"),visible:te.value,onCancel:ue,onProceed:Le},{default:e.withCtx(()=>[e.createVNode(e.unref(w),{class:"message",keypath:t.config.consumerGroupName?"consumers.consumer_groups.remove.confirmation":"consumers.consumer_groups.remove.confirmationNoCG",tag:"p"},e.createSlots({consumer:e.withCtx(()=>[e.createElementVNode("strong",null,e.toDisplayString(R.value.username||R.value.custom_id||R.value.id),1)]),_:2},[t.config.consumerGroupName?{name:"consumerGroup",fn:e.withCtx(()=>[e.createElementVNode("strong",null,e.toDisplayString(t.config.consumerGroupName),1)]),key:"0"}:void 0]),1032,["keypath"]),e.createElementVNode("p",null,e.toDisplayString(e.unref(r)("consumers.consumer_groups.remove.description")),1)]),_:1},8,["title","visible"])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-f62aedbb"]]);for(var _=[],Z=0;Z<256;++Z)_.push((Z+256).toString(16).slice(1));function Ne(t,u=0){return(_[t[u+0]]+_[t[u+1]]+_[t[u+2]]+_[t[u+3]]+"-"+_[t[u+4]]+_[t[u+5]]+"-"+_[t[u+6]]+_[t[u+7]]+"-"+_[t[u+8]]+_[t[u+9]]+"-"+_[t[u+10]]+_[t[u+11]]+_[t[u+12]]+_[t[u+13]]+_[t[u+14]]+_[t[u+15]]).toLowerCase()}var Y,Ee=new Uint8Array(16);function De(){if(!Y&&(Y=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(Ee)}var Be=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ae={randomUUID:Be};function $e(t,u,s){if(ae.randomUUID&&!u&&!t)return ae.randomUUID();t=t||{};var o=t.random||(t.rng||De)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ne(o)}const Ge={class:"kong-ui-entities-consumer-form"},Me=["id"],Se={class:"fields-group-text"},Te=["aria-labelledby"],Ae=X(e.defineComponent({__name:"ConsumerForm",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||(t==null?void 0:t.app)==="konnect"&&!(t!=null&&t.controlPlaneId)||(t==null?void 0:t.app)==="kongManager"&&typeof(t==null?void 0:t.workspace)!="string"||!(t!=null&&t.cancelRoute))},consumerId:{type:String,required:!1,default:""}},emits:["update","error","loading"],setup(t,{emit:u}){var O;const s=t,o=u,{i18nT:w,i18n:{t:r}}=z.useI18n(),I=re.useRouter(),{axiosInstance:V}=p.useAxios((O=s.config)==null?void 0:O.axiosRequestConfig),{getMessageFromError:B}=p.useErrors(),T=$e(),d=e.reactive({fields:{username:"",customId:"",tags:""},readonly:!1,errorMessage:""}),H=e.reactive({username:"",customId:"",tags:""}),U=e.computed(()=>{var a,i;return(i=P.form[(a=s.config)==null?void 0:a.app])==null?void 0:i.edit}),M=()=>{var a;I.push(((a=s.config)==null?void 0:a.cancelRoute)||{name:"consumer-list"})},J=a=>{o("loading",a)},E=a=>{o("error",a)},q=a=>{var g,G,C;d.fields.username=((g=a==null?void 0:a.item)==null?void 0:g.username)||(a==null?void 0:a.username)||"",d.fields.customId=((G=a==null?void 0:a.item)==null?void 0:G.custom_id)||(a==null?void 0:a.custom_id)||"";const i=((C=a==null?void 0:a.item)==null?void 0:C.tags)||(a==null?void 0:a.tags)||[];d.fields.tags=(i==null?void 0:i.join(", "))||"",Object.assign(H,d.fields)},K=e.computed(()=>s.consumerId?p.EntityBaseFormType.Edit:p.EntityBaseFormType.Create),A=a=>{var g,G,C,l,m,f;let i=`${(g=s.config)==null?void 0:g.apiBaseUrl}${P.form[(G=s.config)==null?void 0:G.app][a]}`;return((C=s.config)==null?void 0:C.app)==="konnect"?i=i.replace(/{controlPlaneId}/gi,((l=s.config)==null?void 0:l.controlPlaneId)||""):((m=s.config)==null?void 0:m.app)==="kongManager"&&(i=i.replace(/\/{workspace}/gi,(f=s.config)!=null&&f.workspace?`/${s.config.workspace}`:"")),i=i.replace(/{id}/gi,s.consumerId),i},Q=e.computed(()=>!!d.fields.username||!!d.fields.customId),x=e.computed(()=>JSON.stringify(d.fields)!==JSON.stringify(H)),D=e.computed(()=>{var a,i;return{username:d.fields.username||null,custom_id:d.fields.customId||null,tags:(i=(a=d.fields.tags.split(","))==null?void 0:a.map(g=>String(g||"").trim()))==null?void 0:i.filter(g=>g!=="")}}),$=async()=>{var a;try{d.readonly=!0;let i;await V.post(A("validate"),D.value),K.value==="create"?i=await V.post(A("create"),D.value):K.value==="edit"&&(i=((a=s.config)==null?void 0:a.app)==="konnect"?await V.put(A("edit"),D.value):await V.patch(A("edit"),D.value)),q(i==null?void 0:i.data),o("update",i==null?void 0:i.data)}catch(i){d.errorMessage=B(i),o("error",i)}finally{d.readonly=!1}};return(a,i)=>{const g=e.resolveComponent("KInput"),G=e.resolveComponent("KCard");return e.openBlock(),e.createElementBlock("div",Ge,[e.createVNode(e.unref(p.EntityBaseForm),{"can-submit":Q.value&&x.value,config:t.config,"edit-id":t.consumerId,"entity-type":e.unref(p.SupportedEntityType).Consumer,"error-message":d.errorMessage,"fetch-url":U.value,"form-fields":D.value,"is-readonly":d.readonly,onCancel:M,"onFetch:error":i[3]||(i[3]=C=>E(C)),"onFetch:success":q,onLoading:i[4]||(i[4]=C=>J(C)),onSubmit:$},{default:e.withCtx(()=>[e.createElementVNode("div",null,[e.createVNode(e.unref(p.EntityFormSection),{description:e.unref(r)("consumers.form.info.description"),"has-divider":"",title:e.unref(r)("consumers.form.info.title")},{default:e.withCtx(()=>[e.createElementVNode("div",null,[e.createElementVNode("h3",{id:`fields-group-title-${e.unref(T)}`,class:"fields-group-title"},e.toDisplayString(e.unref(r)("consumers.form.consumer_identification.title"))+"* ",9,Me),e.createElementVNode("p",Se,e.toDisplayString(e.unref(r)("consumers.form.consumer_identification.description")),1)]),e.createVNode(G,null,{default:e.withCtx(()=>[e.createElementVNode("fieldset",{"aria-labelledby":`fields-group-title-${e.unref(T)}`},[e.createVNode(g,{modelValue:d.fields.username,"onUpdate:modelValue":i[0]||(i[0]=C=>d.fields.username=C),modelModifiers:{trim:!0},autocomplete:"off",class:"username-field","data-testid":"consumer-form-username",label:e.unref(r)("consumers.fields.username.label"),"label-attributes":{tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.username.placeholder"),readonly:d.readonly,type:"text"},{"label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(w),{keypath:"consumers.fields.username.tooltip",scope:"global"},{custom_id:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(r)("consumers.fields.username.custom_id")),1)]),_:1})]),_:1},8,["modelValue","label","placeholder","readonly"]),e.createVNode(g,{modelValue:d.fields.customId,"onUpdate:modelValue":i[1]||(i[1]=C=>d.fields.customId=C),modelModifiers:{trim:!0},autocomplete:"off","data-testid":"consumer-form-custom-id",label:e.unref(r)("consumers.fields.custom_id.label"),"label-attributes":{tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.custom_id.placeholder"),readonly:d.readonly,type:"text"},{"label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(w),{keypath:"consumers.fields.custom_id.tooltip",scope:"global"},{username:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(r)("consumers.fields.custom_id.username")),1)]),_:1})]),_:1},8,["modelValue","label","placeholder","readonly"])],8,Te)]),_:1}),e.createVNode(g,{modelValue:d.fields.tags,"onUpdate:modelValue":i[2]||(i[2]=C=>d.fields.tags=C),modelModifiers:{trim:!0},autocomplete:"off","data-testid":"consumer-form-tags",help:e.unref(r)("consumers.fields.tags.help"),label:e.unref(r)("consumers.fields.tags.label"),"label-attributes":{info:e.unref(r)("consumers.fields.tags.tooltip"),tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.tags.placeholder"),readonly:d.readonly,type:"text"},null,8,["modelValue","help","label","label-attributes","placeholder","readonly"])]),_:1},8,["description","title"])])]),_:1},8,["can-submit","config","edit-id","entity-type","error-message","fetch-url","form-fields","is-readonly"])])}}}),[["__scopeId","data-v-3b40ca9a"]]),Re={class:"kong-ui-consumer-entity-config-card"},Fe=e.defineComponent({__name:"ConsumerConfigCard",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||t.app==="konnect"&&!t.controlPlaneId||t.app==="kongManager"&&typeof t.workspace!="string"||!t.entityId)},configCardDoc:{type:String,default:"",required:!1},hideTitle:{type:Boolean,default:!1}},emits:["loading","fetch:error","fetch:success"],setup(t){const u=t,{i18n:{t:s},i18nT:o}=z.useI18n(),w=e.computed(()=>P.form[u.config.app].edit),r=e.ref({id:{},username:{section:p.ConfigurationSchemaSection.Basic,tooltip:s("consumers.fields.username.tooltip"),order:1},custom_id:{section:p.ConfigurationSchemaSection.Basic,tooltip:s("consumers.fields.custom_id.tooltip"),label:s("consumers.fields.custom_id.label"),order:2},updated_at:{},created_at:{},tags:{tooltip:s("consumers.fields.tags.tooltip")},username_lower:{hidden:!0},type:{hidden:!0}});return(I,V)=>(e.openBlock(),e.createElementBlock("div",Re,[e.createVNode(e.unref(p.EntityBaseConfigCard),{config:t.config,"config-card-doc":t.configCardDoc,"config-schema":r.value,"entity-type":e.unref(p.SupportedEntityType).Consumer,"fetch-url":w.value,"hide-title":t.hideTitle,"onFetch:error":V[0]||(V[0]=B=>I.$emit("fetch:error",B)),"onFetch:success":V[1]||(V[1]=B=>I.$emit("fetch:success",B)),onLoading:V[2]||(V[2]=B=>I.$emit("loading",B))},{"username-label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(o),{keypath:"consumers.fields.username.tooltip",scope:"global"},{custom_id:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(s)("consumers.fields.username.custom_id")),1)]),_:1})]),"custom_id-label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(o),{keypath:"consumers.fields.custom_id.tooltip",scope:"global"},{username:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(s)("consumers.fields.custom_id.username")),1)]),_:1})]),_:1},8,["config","config-card-doc","config-schema","entity-type","fetch-url","hide-title"])]))}});N.ConsumerConfigCard=Fe,N.ConsumerForm=Ae,N.ConsumerList=xe,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(N,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vue-router"),require("@kong/icons"),require("@kong-ui-public/i18n"),require("@kong-ui-public/entities-shared")):typeof define=="function"&&define.amd?define(["exports","vue","vue-router","@kong/icons","@kong-ui-public/i18n","@kong-ui-public/entities-shared"],e):(N=typeof globalThis<"u"?globalThis:N||self,e(N["kong-ui-public-entities-consumers"]={},N.Vue,N.VueRouter,N.KongIcons,N["kong-ui-public-i18n"],N["kong-ui-public-entities-shared"]))})(this,function(N,e,re,pe,se,p){"use strict";const fe={consumers:{list:{table_headers:{username:"Username",custom_id:"Custom ID",tags:"Tags",id:"ID"},empty_state:{title:"Configure a New Consumer",description:"Consumers are the end users of a service.",title_for_consumer_group:"Configure a New Consumer"},toolbar_actions:{new_consumer:"New Consumer"}},title:"Consumers",search:{placeholder:{konnect:"Filter by name",kongManager:"Filter by exact username or ID"}},actions:{add_consumer:"Add Consumer",create:"New Consumer",copy_id:"Copy ID",copy_json:"Copy JSON",edit:"Edit",delete:"Delete",remove:"Remove",view:"View Details"},delete:{title:"Delete a Consumer",description:"Deleting this consumer will also remove this consumer from any associated consumer group and delete all its plugins. This action cannot be reversed."},consumer_groups:{add:{title:"Add Consumers",ctaText:"Add consumers to this group",consumers_label:"Consumers",consumer_placeholder:"Add consumer",footer:"Search by exact name or ID to find consumers not included in the list"},remove:{title:"Remove a Consumer",confirmation:"Are you sure you want to remove this consumer {consumer} from consumer group {consumerGroup}?",confirmationNoCG:"Are you sure you want to remove this consumer {consumer} from this consumer group?",description:"Removing this consumer from the group could change the rate limit policy applied to this consumer."}},errors:{general:"Consumers could not be retrieved",delete:"The consumer could not be deleted at this time.",copy:"Failed to copy to clipboard",add:"Some consumers could not be added at this time.",already_added:"This consumer has already been added to the consumer group"},copy:{success:"Copied {val} to clipboard",success_brief:"Successfully copied to clipboard"},form:{title:"Consumer Identification",info:{title:"General Information",description:"General information will help identify and manage added consumer."},consumer_identification:{title:"Consumer Identification",description:"A consumer can have both unique username and unique custom ID or one of them."}},fields:{username:{label:"Username",placeholder:"Enter a unique username",tooltip:"The unique username of the Consumer. You must send either this field or {custom_id} with the request.",custom_id:"custom_id"},custom_id:{label:"Custom ID",placeholder:"Enter a unique custom ID",tooltip:"Field for storing an existing unique ID for the Consumer - useful for mapping Kong with users in your existing database. You must send either this field or {username} with the request.",username:"username"},tags:{label:"Tags",placeholder:"Enter a list of tags separated by comma",help:"e.g. tag1, tag2, tag3",tooltip:"An optional set of strings associated with the Consumer for grouping and filtering."}}}};function ge(){const t=se.createI18n("en-us",fe);return{i18n:t,i18nT:se.i18nTComponent(t)}}const z={useI18n:ge},L="/v2/control-planes/{controlPlaneId}/core-entities",W="/{workspace}",P={list:{konnect:{all:`${L}/consumers`,forConsumerGroup:`${L}/consumer_groups/{consumerGroupId}/consumers`,oneForConsumerGroup:`${L}/consumer_groups/{consumerGroupId}/consumers/{consumerId}`},kongManager:{all:`${W}/consumers`,forConsumerGroup:`${W}/consumer_groups/{consumerGroupId}/consumers`,oneForConsumerGroup:`${W}/consumer_groups/{consumerGroupId}/consumers/{consumerId}`}},form:{konnect:{validate:`${L}/v1/schemas/json/consumer/validate`,create:`${L}/consumers`,edit:`${L}/consumers/{id}`},kongManager:{validate:`${W}/schemas/consumers/validate`,create:`${W}/consumers`,edit:`${W}/consumers/{id}`}}},ye={class:"add-consumer-form-container"},he={class:"add-consumer-form-cta"},Ce={class:"select-item-label"},be={key:0,class:"select-item-desc"},ke={key:0,class:"kong-ui-entity-add-consumers-error"},_e={key:0},Ie=e.defineComponent({__name:"AddConsumerModal",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||!t.consumerGroupId)},visible:{type:Boolean,required:!0,default:!1}},emits:["cancel","add:success","add:partial-success","error"],setup(t,{emit:u}){var C;const{i18n:{t:s}}=z.useI18n(),o=t,w=u,{axiosInstance:r}=p.useAxios((C=o.config)==null?void 0:C.axiosRequestConfig),I=e.ref([]),{debouncedQueryChange:V,loading:B,allRecords:T,error:d,loadItems:H,results:U}=p.useDebouncedFilter(o.config,P.list[o.config.app].all,"",{fetchedItemsKey:"data",searchKeys:["username","id"]}),M=l=>l,J=e.computed(()=>d.value?s("consumers.errors.general"):""),E=e.ref(0),q=e.computed(()=>T.value===void 0),K=e.computed(()=>U.value.map(l=>({label:l.username||l.customId,value:l.id,selected:I.value.includes(l.id),data:l}))),A=l=>{var f;const m=q.value?U.value.find(b=>b.id===l):(f=T.value)==null?void 0:f.find(b=>b.id===l);return m?m.username||m.custom_id:l},Q=()=>{$.value="",x.value=[],g.value=[],w("cancel")},x=e.ref([]),D=e.ref(!1),$=e.ref(""),O=async()=>{if(!I.value.length){$.value="",g.value=[],w("cancel");return}D.value=!0,$.value="",x.value=[],g.value=[];try{const l=I.value.map(b=>i(b)),m=await Promise.allSettled(l);let f=!0;m.forEach(b=>{b.status!=="fulfilled"&&(f=!1)}),f?(x.value=[],g.value=[],w("add:success",I.value),I.value=[]):(x.value.length&&w("add:partial-success",x.value),I.value=[],G(m))}catch{$.value=s("consumers.errors.add"),w("error",$.value)}finally{D.value=!1}},a=e.computed(()=>{var m,f,b,j;let l=`${o.config.apiBaseUrl}${P.list[o.config.app].forConsumerGroup}`;return o.config.app==="konnect"?l=l.replace(/{controlPlaneId}/gi,((m=o.config)==null?void 0:m.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((f=o.config)==null?void 0:f.consumerGroupId)||""):o.config.app==="kongManager"&&(l=l.replace(/\/{workspace}/gi,(b=o.config)!=null&&b.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((j=o.config)==null?void 0:j.consumerGroupId)||"")),l}),i=async l=>{const m={consumer:l};try{const f=await r.post(a.value,m);return x.value.push(l),f}catch(f){let b=`${A(l)} - ${f.message}`;return f.response.status===409&&(b=`${A(l)} - ${s("consumers.errors.already_added")}`),Promise.reject(Error(b))}},g=e.ref([]),G=l=>{g.value=l.map(m=>{var f;return(f=m.reason)==null?void 0:f.message}).filter(Boolean)};return e.watch(K,()=>{E.value++},{immediate:!0,deep:!0}),e.watch(()=>o.visible,()=>{o.visible&&H()},{immediate:!0}),(l,m)=>{const f=e.resolveComponent("KMultiselect"),b=e.resolveComponent("KAlert"),j=e.resolveComponent("KPrompt");return e.openBlock(),e.createBlock(j,{"action-button-disabled":D.value,class:"kong-ui-entities-add-consumers-modal","data-testid":"add-consumer-modal",title:e.unref(s)("consumers.consumer_groups.add.title"),visible:t.visible,onCancel:Q,onProceed:O},{default:e.withCtx(()=>[e.createElementVNode("div",ye,[e.createElementVNode("p",he,e.toDisplayString(e.unref(s)("consumers.consumer_groups.add.ctaText")),1),e.createVNode(f,{modelValue:I.value,"onUpdate:modelValue":m[0]||(m[0]=S=>I.value=S),autosuggest:"","data-testid":"add-consumers-multiselect","dropdown-footer-text":q.value?e.unref(s)("consumers.consumer_groups.add.footer"):void 0,items:K.value,label:e.unref(s)("consumers.consumer_groups.add.consumers_label"),loading:e.unref(B),placeholder:e.unref(s)("consumers.consumer_groups.add.consumer_placeholder"),readonly:D.value,required:"",width:"100%",onQueryChange:e.unref(V)},{"item-template":e.withCtx(({item:S})=>[e.createElementVNode("div",Ce,e.toDisplayString(S.label),1),M(S).data.username&&M(S).data.custom_id?(e.openBlock(),e.createElementBlock("div",be,e.toDisplayString(M(S).data.custom_id),1)):e.createCommentVNode("",!0)]),_:1},8,["modelValue","dropdown-footer-text","items","label","loading","placeholder","readonly","onQueryChange"]),$.value||J.value||g.value.length?(e.openBlock(),e.createElementBlock("div",ke,[e.createVNode(b,{appearance:"danger"},{default:e.withCtx(()=>[e.createElementVNode("p",null,e.toDisplayString(e.unref(s)("consumers.errors.add")),1),g.value.length?(e.openBlock(),e.createElementBlock("ul",_e,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(g.value,(S,v)=>(e.openBlock(),e.createElementBlock("li",{key:v},e.toDisplayString(S),1))),128))])):e.createCommentVNode("",!0),e.createElementVNode("div",null,e.toDisplayString($.value||J.value),1)]),_:1})])):e.createCommentVNode("",!0)])]),_:1},8,["action-button-disabled","title","visible"])}}}),X=(t,u)=>{const s=t.__vccOpts||t;for(const[o,w]of u)s[o]=w;return s},Ve=X(Ie,[["__scopeId","data-v-d54468ab"]]),we={class:"kong-ui-entities-consumers-list"},xe=X(e.defineComponent({__name:"ConsumerList",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||!t.createRoute||!t.getViewRoute||!t.getEditRoute||t.app==="kongManager"&&!t.isExactMatch&&!t.filterSchema)},cacheIdentifier:{type:String,default:""},canCreate:{type:Function,required:!1,default:async()=>!0},canDelete:{type:Function,required:!1,default:async()=>!0},canEdit:{type:Function,required:!1,default:async()=>!0},canRetrieve:{type:Function,required:!1,default:async()=>!0},useActionOutside:{type:Boolean,default:!1}},emits:["error","copy:success","copy:error","delete:success","add:success","remove:success"],setup(t,{emit:u}){var me;const s=u,o=t,{i18nT:w,i18n:{t:r}}=z.useI18n(),I=re.useRouter(),{axiosInstance:V}=p.useAxios((me=o.config)==null?void 0:me.axiosRequestConfig),B=e.computed(()=>o.config.app!=="kongManager"||!!o.config.disableSorting),T={username:{label:r("consumers.list.table_headers.username"),searchable:!0,sortable:!0,hidable:!1},custom_id:{label:r("consumers.list.table_headers.custom_id"),searchable:!0,sortable:!0},tags:{label:r("consumers.list.table_headers.tags"),sortable:!1}},d=T,H=n=>({"data-testid":n.username??n.custom_id??n.id}),U=e.computed(()=>{var c,h,k,F;let n=`${o.config.apiBaseUrl}${P.list[o.config.app][E.value?"forConsumerGroup":"all"]}`;return o.config.app==="konnect"?n=n.replace(/{controlPlaneId}/gi,((c=o.config)==null?void 0:c.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((h=o.config)==null?void 0:h.consumerGroupId)||""):o.config.app==="kongManager"&&(n=n.replace(/\/{workspace}/gi,(k=o.config)!=null&&k.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((F=o.config)==null?void 0:F.consumerGroupId)||"")),n}),M=e.ref(""),J=e.computed(()=>{const n=o.config.app==="konnect"||o.config.isExactMatch;return n?{isExactMatch:n,placeholder:r(`consumers.search.placeholder.${o.config.app}`)}:{isExactMatch:n,fields:{username:T.username,custom_id:T.custom_id},schema:o.config.filterSchema}}),E=e.computed(()=>!!o.config.consumerGroupId),q=e.computed(()=>E.value?"kong-ui-entities-consumers-list-in-group-page":"kong-ui-entities-consumers-list"),K=e.computed(()=>E.value&&!o.config.paginatedEndpoint?"consumers":void 0),{fetcher:A,fetcherState:Q,fetcherCacheKey:x}=p.useFetcher({...o.config,cacheIdentifier:o.cacheIdentifier},U.value,K.value),D=()=>{M.value=""},$=()=>{x.value++},O=n=>n??"-",a=e.ref(null),i=(n,c)=>{const h=n.id;if(!c(h)){s("copy:error",{entity:n,field:"id",message:r("consumers.errors.copy")});return}s("copy:success",{entity:n,field:"id",message:r("consumers.copy.success",{val:h})})},g=(n,c)=>{const h=JSON.stringify(n);if(!c(h)){s("copy:error",{entity:n,message:r("consumers.errors.copy")});return}s("copy:success",{entity:n,message:r("consumers.copy.success_brief")})},G=async n=>{var h;await((h=o.canRetrieve)==null?void 0:h.call(o,n))&&I.push(o.config.getViewRoute(n.id))},C=n=>({label:r("consumers.actions.view"),to:o.config.getViewRoute(n)}),l=n=>({label:r("consumers.actions.edit"),to:o.config.getEditRoute(n)}),m=e.ref(void 0),f=e.ref(!1),b=e.ref(!1),j=e.ref(""),S=p.useDeleteUrlBuilder(o.config,U.value),v=n=>{m.value=n,f.value=!0},Pe=()=>{f.value=!1},Ue=async()=>{var n,c,h;if((n=m.value)!=null&&n.id){b.value=!0;try{await V.delete(S(m.value.id)),b.value=!1,f.value=!1,x.value++,s("delete:success",m.value)}catch(k){j.value=((h=(c=k.response)==null?void 0:c.data)==null?void 0:h.message)||k.message||r("consumers.errors.delete"),s("error",k)}finally{b.value=!1}}},ee=e.ref(!1),ie=()=>{ee.value=!0},le=()=>{ee.value=!1},ce=(n,c)=>{c||le(),x.value++,s("add:success",n)},qe=()=>{E.value&&ie()},R=e.ref(void 0),te=e.ref(!1),Ke=e.ref(""),Oe=n=>{R.value=n,te.value=!0},ue=()=>{te.value=!1,R.value=void 0},je=e.computed(()=>{var c,h,k,F;let n=`${o.config.apiBaseUrl}${P.list[o.config.app].oneForConsumerGroup}`;return o.config.app==="konnect"?n=n.replace(/{controlPlaneId}/gi,((c=o.config)==null?void 0:c.controlPlaneId)||"").replace(/{consumerGroupId}/gi,((h=o.config)==null?void 0:h.consumerGroupId)||""):o.config.app==="kongManager"&&(n=n.replace(/\/{workspace}/gi,(k=o.config)!=null&&k.workspace?`/${o.config.workspace}`:"").replace(/{consumerGroupId}/gi,((F=o.config)==null?void 0:F.consumerGroupId)||"")),n}),de=e.ref(!1),Le=async()=>{if(R.value){de.value=!0;try{const n=je.value.replace(/{consumerId}/gi,R.value.id);await V.delete(n),s("remove:success",R.value),ue(),x.value++}catch(n){Ke.value=n.message||r("consumers.errors.delete"),s("error",n)}finally{de.value=!1}}};e.watch(Q,n=>{var c,h,k;if(n.status===p.FetcherStatus.Error){a.value={title:r("consumers.errors.general")},(k=(h=(c=n.error)==null?void 0:c.response)==null?void 0:h.data)!=null&&k.message&&(a.value.message=n.error.response.data.message),s("error",n.error);return}a.value=null});const oe=e.ref({ctaPath:E.value?void 0:o.config.createRoute,ctaText:void 0,message:`${r("consumers.list.empty_state.description")}${o.config.additionMessageForEmptyState?` ${o.config.additionMessageForEmptyState}`:""}`,title:r("consumers.title")});return e.onBeforeMount(async()=>{await o.canCreate()&&(oe.value.title=E.value?r("consumers.list.empty_state.title_for_consumer_group"):r("consumers.list.empty_state.title"),oe.value.ctaText=E.value?r("consumers.actions.add_consumer"):r("consumers.actions.create"))}),(n,c)=>{const h=e.resolveComponent("KButton"),k=e.resolveComponent("KDropdownItem"),F=e.resolveComponent("KClipboardProvider"),We=e.resolveComponent("KPrompt");return e.openBlock(),e.createElementBlock("div",we,[e.createVNode(e.unref(p.EntityBaseTable),{"cache-identifier":t.cacheIdentifier,"disable-sorting":B.value,"empty-state-options":oe.value,"enable-entity-actions":"","error-message":a.value,fetcher:e.unref(A),"fetcher-cache-key":e.unref(x),"hide-pagination":E.value&&!t.config.paginatedEndpoint,"pagination-type":"offset","preferences-storage-key":q.value,query:M.value,"row-attributes":H,"table-headers":e.unref(d),onClearSearchInput:D,"onClick:row":c[2]||(c[2]=y=>G(y)),onEmptyStateCtaClicked:qe,onSort:$},{"toolbar-filter":e.withCtx(()=>[E.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(e.unref(p.EntityFilter),{key:0,modelValue:M.value,"onUpdate:modelValue":c[0]||(c[0]=y=>M.value=y),config:J.value},null,8,["modelValue","config"]))]),"toolbar-button":e.withCtx(()=>[(e.openBlock(),e.createBlock(e.Teleport,{disabled:!t.useActionOutside,to:"#kong-ui-app-page-header-action-button"},[e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canCreate()},{default:e.withCtx(()=>[e.createVNode(h,{appearance:"primary","data-testid":"toolbar-add-consumer",size:t.useActionOutside?"medium":"large",to:t.config.consumerGroupId?void 0:t.config.createRoute,onClick:c[1]||(c[1]=()=>t.config.consumerGroupId?ie():void 0)},{default:e.withCtx(()=>[e.createVNode(e.unref(pe.AddIcon)),e.createTextVNode(" "+e.toDisplayString(t.config.consumerGroupId?e.unref(r)("consumers.actions.add_consumer"):e.unref(r)("consumers.list.toolbar_actions.new_consumer")),1)]),_:1},8,["size","to"])]),_:1},8,["auth-function"])],8,["disabled"]))]),username:e.withCtx(({rowValue:y})=>[e.createElementVNode("b",null,e.toDisplayString(O(y)),1)]),custom_id:e.withCtx(({rowValue:y})=>[e.createTextVNode(e.toDisplayString(O(y)),1)]),tags:e.withCtx(({rowValue:y})=>[e.createVNode(e.unref(p.TableTags),{tags:y},null,8,["tags"])]),actions:e.withCtx(({row:y})=>[e.createVNode(F,null,{default:e.withCtx(({copyToClipboard:ne})=>[e.createVNode(k,{"data-testid":"action-entity-copy-id",onClick:He=>i(y,ne)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(r)("consumers.actions.copy_id")),1)]),_:2},1032,["onClick"])]),_:2},1024),e.createVNode(F,null,{default:e.withCtx(({copyToClipboard:ne})=>[e.createVNode(k,{"data-testid":"action-entity-copy-json",onClick:He=>g(y,ne)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(r)("consumers.actions.copy_json")),1)]),_:2},1032,["onClick"])]),_:2},1024),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canRetrieve(y)},{default:e.withCtx(()=>[e.createVNode(k,{"data-testid":"action-entity-view","has-divider":"",item:C(y.id)},null,8,["item"])]),_:2},1032,["auth-function"]),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canEdit(y)},{default:e.withCtx(()=>[e.createVNode(k,{"data-testid":"action-entity-edit",item:l(y.id)},null,8,["item"])]),_:2},1032,["auth-function"]),e.createVNode(e.unref(p.PermissionsWrapper),{"auth-function":()=>t.canDelete(y)},{default:e.withCtx(()=>[e.createVNode(k,{danger:"","data-testid":"action-entity-delete","has-divider":"",onClick:()=>t.config.consumerGroupId?Oe(y):v(y)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.config.consumerGroupId?e.unref(r)("consumers.actions.remove"):e.unref(r)("consumers.actions.delete")),1)]),_:2},1032,["onClick"])]),_:2},1032,["auth-function"])]),_:1},8,["cache-identifier","disable-sorting","empty-state-options","error-message","fetcher","fetcher-cache-key","hide-pagination","preferences-storage-key","query","table-headers"]),e.createVNode(e.unref(p.EntityDeleteModal),{"action-button-disabled":b.value,"data-testid":"delete-consumer-modal",description:e.unref(r)("consumers.delete.description"),"entity-name":m.value&&(m.value.username||m.value.custom_id||m.value.id),"entity-type":e.unref(p.EntityTypes).Consumer,error:j.value,title:e.unref(r)("consumers.delete.title"),visible:f.value,onCancel:Pe,onProceed:Ue},null,8,["action-button-disabled","description","entity-name","entity-type","error","title","visible"]),t.config.consumerGroupId?(e.openBlock(),e.createBlock(Ve,{key:0,config:t.config,"data-testid":"add-consumer-modal",visible:ee.value,"onAdd:partialSuccess":c[3]||(c[3]=y=>ce(y,!0)),"onAdd:success":c[4]||(c[4]=y=>ce(y)),onCancel:le},null,8,["config","visible"])):e.createCommentVNode("",!0),t.config.consumerGroupId&&R.value?(e.openBlock(),e.createBlock(We,{key:1,"action-button-appearance":"danger","data-testid":"remove-consumer-modal",title:e.unref(r)("consumers.consumer_groups.remove.title"),visible:te.value,onCancel:ue,onProceed:Le},{default:e.withCtx(()=>[e.createVNode(e.unref(w),{class:"message",keypath:t.config.consumerGroupName?"consumers.consumer_groups.remove.confirmation":"consumers.consumer_groups.remove.confirmationNoCG",tag:"p"},e.createSlots({consumer:e.withCtx(()=>[e.createElementVNode("strong",null,e.toDisplayString(R.value.username||R.value.custom_id||R.value.id),1)]),_:2},[t.config.consumerGroupName?{name:"consumerGroup",fn:e.withCtx(()=>[e.createElementVNode("strong",null,e.toDisplayString(t.config.consumerGroupName),1)]),key:"0"}:void 0]),1032,["keypath"]),e.createElementVNode("p",null,e.toDisplayString(e.unref(r)("consumers.consumer_groups.remove.description")),1)]),_:1},8,["title","visible"])):e.createCommentVNode("",!0)])}}}),[["__scopeId","data-v-f62aedbb"]]);for(var _=[],Z=0;Z<256;++Z)_.push((Z+256).toString(16).slice(1));function Ne(t,u=0){return(_[t[u+0]]+_[t[u+1]]+_[t[u+2]]+_[t[u+3]]+"-"+_[t[u+4]]+_[t[u+5]]+"-"+_[t[u+6]]+_[t[u+7]]+"-"+_[t[u+8]]+_[t[u+9]]+"-"+_[t[u+10]]+_[t[u+11]]+_[t[u+12]]+_[t[u+13]]+_[t[u+14]]+_[t[u+15]]).toLowerCase()}var Y,Ee=new Uint8Array(16);function De(){if(!Y&&(Y=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(Ee)}var Be=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ae={randomUUID:Be};function $e(t,u,s){if(ae.randomUUID&&!u&&!t)return ae.randomUUID();t=t||{};var o=t.random||(t.rng||De)();return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Ne(o)}const Ge={class:"kong-ui-entities-consumer-form"},Me=["id"],Se={class:"fields-group-text"},Te=["aria-labelledby"],Ae=X(e.defineComponent({__name:"ConsumerForm",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||(t==null?void 0:t.app)==="konnect"&&!(t!=null&&t.controlPlaneId)||(t==null?void 0:t.app)==="kongManager"&&typeof(t==null?void 0:t.workspace)!="string"||!(t!=null&&t.cancelRoute))},consumerId:{type:String,required:!1,default:""}},emits:["update","error","loading"],setup(t,{emit:u}){var O;const s=t,o=u,{i18nT:w,i18n:{t:r}}=z.useI18n(),I=re.useRouter(),{axiosInstance:V}=p.useAxios((O=s.config)==null?void 0:O.axiosRequestConfig),{getMessageFromError:B}=p.useErrors(),T=$e(),d=e.reactive({fields:{username:"",customId:"",tags:""},readonly:!1,errorMessage:""}),H=e.reactive({username:"",customId:"",tags:""}),U=e.computed(()=>{var a,i;return(i=P.form[(a=s.config)==null?void 0:a.app])==null?void 0:i.edit}),M=()=>{var a;I.push(((a=s.config)==null?void 0:a.cancelRoute)||{name:"consumer-list"})},J=a=>{o("loading",a)},E=a=>{o("error",a)},q=a=>{var g,G,C;d.fields.username=((g=a==null?void 0:a.item)==null?void 0:g.username)||(a==null?void 0:a.username)||"",d.fields.customId=((G=a==null?void 0:a.item)==null?void 0:G.custom_id)||(a==null?void 0:a.custom_id)||"";const i=((C=a==null?void 0:a.item)==null?void 0:C.tags)||(a==null?void 0:a.tags)||[];d.fields.tags=(i==null?void 0:i.join(", "))||"",Object.assign(H,d.fields)},K=e.computed(()=>s.consumerId?p.EntityBaseFormType.Edit:p.EntityBaseFormType.Create),A=a=>{var g,G,C,l,m,f;let i=`${(g=s.config)==null?void 0:g.apiBaseUrl}${P.form[(G=s.config)==null?void 0:G.app][a]}`;return((C=s.config)==null?void 0:C.app)==="konnect"?i=i.replace(/{controlPlaneId}/gi,((l=s.config)==null?void 0:l.controlPlaneId)||""):((m=s.config)==null?void 0:m.app)==="kongManager"&&(i=i.replace(/\/{workspace}/gi,(f=s.config)!=null&&f.workspace?`/${s.config.workspace}`:"")),i=i.replace(/{id}/gi,s.consumerId),i},Q=e.computed(()=>!!d.fields.username||!!d.fields.customId),x=e.computed(()=>JSON.stringify(d.fields)!==JSON.stringify(H)),D=e.computed(()=>{var a,i;return{username:d.fields.username||null,custom_id:d.fields.customId||null,tags:(i=(a=d.fields.tags.split(","))==null?void 0:a.map(g=>String(g||"").trim()))==null?void 0:i.filter(g=>g!=="")}}),$=async()=>{var a;try{d.readonly=!0;let i;await V.post(A("validate"),D.value),K.value==="create"?i=await V.post(A("create"),D.value):K.value==="edit"&&(i=((a=s.config)==null?void 0:a.app)==="konnect"?await V.put(A("edit"),D.value):await V.patch(A("edit"),D.value)),q(i==null?void 0:i.data),o("update",i==null?void 0:i.data)}catch(i){d.errorMessage=B(i),o("error",i)}finally{d.readonly=!1}};return(a,i)=>{const g=e.resolveComponent("KInput"),G=e.resolveComponent("KCard");return e.openBlock(),e.createElementBlock("div",Ge,[e.createVNode(e.unref(p.EntityBaseForm),{"can-submit":Q.value&&x.value,config:t.config,"edit-id":t.consumerId,"entity-type":e.unref(p.SupportedEntityType).Consumer,"error-message":d.errorMessage,"fetch-url":U.value,"form-fields":D.value,"is-readonly":d.readonly,onCancel:M,"onFetch:error":i[3]||(i[3]=C=>E(C)),"onFetch:success":q,onLoading:i[4]||(i[4]=C=>J(C)),onSubmit:$},{default:e.withCtx(()=>[e.createElementVNode("div",null,[e.createVNode(e.unref(p.EntityFormSection),{description:e.unref(r)("consumers.form.info.description"),"has-divider":"",title:e.unref(r)("consumers.form.info.title")},{default:e.withCtx(()=>[e.createElementVNode("div",null,[e.createElementVNode("h3",{id:`fields-group-title-${e.unref(T)}`,class:"fields-group-title"},e.toDisplayString(e.unref(r)("consumers.form.consumer_identification.title"))+"* ",9,Me),e.createElementVNode("p",Se,e.toDisplayString(e.unref(r)("consumers.form.consumer_identification.description")),1)]),e.createVNode(G,null,{default:e.withCtx(()=>[e.createElementVNode("fieldset",{"aria-labelledby":`fields-group-title-${e.unref(T)}`},[e.createVNode(g,{modelValue:d.fields.username,"onUpdate:modelValue":i[0]||(i[0]=C=>d.fields.username=C),modelModifiers:{trim:!0},autocomplete:"off",class:"username-field","data-testid":"consumer-form-username",label:e.unref(r)("consumers.fields.username.label"),"label-attributes":{tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.username.placeholder"),readonly:d.readonly,type:"text"},{"label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(w),{keypath:"consumers.fields.username.tooltip",scope:"global"},{custom_id:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(r)("consumers.fields.username.custom_id")),1)]),_:1})]),_:1},8,["modelValue","label","placeholder","readonly"]),e.createVNode(g,{modelValue:d.fields.customId,"onUpdate:modelValue":i[1]||(i[1]=C=>d.fields.customId=C),modelModifiers:{trim:!0},autocomplete:"off","data-testid":"consumer-form-custom-id",label:e.unref(r)("consumers.fields.custom_id.label"),"label-attributes":{tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.custom_id.placeholder"),readonly:d.readonly,type:"text"},{"label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(w),{keypath:"consumers.fields.custom_id.tooltip",scope:"global"},{username:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(r)("consumers.fields.custom_id.username")),1)]),_:1})]),_:1},8,["modelValue","label","placeholder","readonly"])],8,Te)]),_:1}),e.createVNode(g,{modelValue:d.fields.tags,"onUpdate:modelValue":i[2]||(i[2]=C=>d.fields.tags=C),modelModifiers:{trim:!0},autocomplete:"off","data-testid":"consumer-form-tags",help:e.unref(r)("consumers.fields.tags.help"),label:e.unref(r)("consumers.fields.tags.label"),"label-attributes":{info:e.unref(r)("consumers.fields.tags.tooltip"),tooltipAttributes:{maxWidth:"400"}},placeholder:e.unref(r)("consumers.fields.tags.placeholder"),readonly:d.readonly,type:"text"},null,8,["modelValue","help","label","label-attributes","placeholder","readonly"])]),_:1},8,["description","title"])])]),_:1},8,["can-submit","config","edit-id","entity-type","error-message","fetch-url","form-fields","is-readonly"])])}}}),[["__scopeId","data-v-3b40ca9a"]]),Re={class:"kong-ui-consumer-entity-config-card"},Fe=e.defineComponent({__name:"ConsumerConfigCard",props:{config:{type:Object,required:!0,validator:t=>!(!t||!["konnect","kongManager"].includes(t==null?void 0:t.app)||t.app==="konnect"&&!t.controlPlaneId||t.app==="kongManager"&&typeof t.workspace!="string"||!t.entityId)},configCardDoc:{type:String,default:"",required:!1},hideTitle:{type:Boolean,default:!1}},emits:["loading","fetch:error","fetch:success"],setup(t){const u=t,{i18n:{t:s},i18nT:o}=z.useI18n(),w=e.computed(()=>P.form[u.config.app].edit),r=e.ref({id:{},username:{section:p.ConfigurationSchemaSection.Basic,tooltip:s("consumers.fields.username.tooltip"),order:1},custom_id:{section:p.ConfigurationSchemaSection.Basic,tooltip:s("consumers.fields.custom_id.tooltip"),label:s("consumers.fields.custom_id.label"),order:2},updated_at:{},created_at:{},tags:{tooltip:s("consumers.fields.tags.tooltip")},username_lower:{hidden:!0},type:{hidden:!0}});return(I,V)=>(e.openBlock(),e.createElementBlock("div",Re,[e.createVNode(e.unref(p.EntityBaseConfigCard),{config:t.config,"config-card-doc":t.configCardDoc,"config-schema":r.value,"entity-type":e.unref(p.SupportedEntityType).Consumer,"fetch-url":w.value,"hide-title":t.hideTitle,"onFetch:error":V[0]||(V[0]=B=>I.$emit("fetch:error",B)),"onFetch:success":V[1]||(V[1]=B=>I.$emit("fetch:success",B)),onLoading:V[2]||(V[2]=B=>I.$emit("loading",B))},{"username-label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(o),{keypath:"consumers.fields.username.tooltip",scope:"global"},{custom_id:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(s)("consumers.fields.username.custom_id")),1)]),_:1})]),"custom_id-label-tooltip":e.withCtx(()=>[e.createVNode(e.unref(o),{keypath:"consumers.fields.custom_id.tooltip",scope:"global"},{username:e.withCtx(()=>[e.createElementVNode("code",null,e.toDisplayString(e.unref(s)("consumers.fields.custom_id.username")),1)]),_:1})]),_:1},8,["config","config-card-doc","config-schema","entity-type","fetch-url","hide-title"])]))}});N.ConsumerConfigCard=Fe,N.ConsumerForm=Ae,N.ConsumerList=xe,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|