@kong-ui-public/entities-consumer-groups 4.8.2-pr.3869.e876c8c8a.0 → 4.8.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.
Files changed (28) hide show
  1. package/dist/entities-consumer-groups.es.js +918 -0
  2. package/dist/entities-consumer-groups.umd.js +1 -0
  3. package/dist/style.css +1 -0
  4. package/dist/types/components/AddToGroupModal.vue.d.ts +38 -0
  5. package/dist/types/components/AddToGroupModal.vue.d.ts.map +1 -0
  6. package/dist/types/components/ConsumerGroupConfigCard.vue.d.ts +63 -0
  7. package/dist/types/components/ConsumerGroupConfigCard.vue.d.ts.map +1 -0
  8. package/dist/types/components/ConsumerGroupForm.vue.d.ts +53 -0
  9. package/dist/types/components/ConsumerGroupForm.vue.d.ts.map +1 -0
  10. package/dist/types/components/ConsumerGroupList.vue.d.ts +111 -0
  11. package/dist/types/components/ConsumerGroupList.vue.d.ts.map +1 -0
  12. package/dist/types/composables/index.d.ts +6 -0
  13. package/dist/types/composables/index.d.ts.map +1 -0
  14. package/dist/types/composables/useI18n.d.ts +9 -0
  15. package/dist/types/composables/useI18n.d.ts.map +1 -0
  16. package/dist/types/consumer-groups-endpoints.d.ts +40 -0
  17. package/dist/types/consumer-groups-endpoints.d.ts.map +1 -0
  18. package/dist/types/index.d.ts +6 -0
  19. package/dist/types/index.d.ts.map +1 -0
  20. package/dist/types/types/consumer-group-config-card.d.ts +15 -0
  21. package/dist/types/types/consumer-group-config-card.d.ts.map +1 -0
  22. package/dist/types/types/consumer-group-form.d.ts +37 -0
  23. package/dist/types/types/consumer-group-form.d.ts.map +1 -0
  24. package/dist/types/types/consumer-group-list.d.ts +39 -0
  25. package/dist/types/types/consumer-group-list.d.ts.map +1 -0
  26. package/dist/types/types/index.d.ts +4 -0
  27. package/dist/types/types/index.d.ts.map +1 -0
  28. package/package.json +3 -3
@@ -0,0 +1,918 @@
1
+ import { defineComponent as le, ref as h, computed as y, watch as he, resolveComponent as B, openBlock as M, createBlock as j, unref as o, withCtx as c, createElementVNode as T, toDisplayString as C, createVNode as d, createElementBlock as L, Fragment as Le, renderList as Qe, createCommentVNode as O, onBeforeMount as Ge, createSlots as ye, createTextVNode as q, Teleport as He, reactive as Me } from "vue";
2
+ import { useRouter as Te } from "vue-router";
3
+ import { BookIcon as Se, AddIcon as Ae, TeamIcon as Je } from "@kong/icons";
4
+ import { createI18n as ze, i18nTComponent as We } from "@kong-ui-public/i18n";
5
+ import { useAxios as be, useDebouncedFilter as Ve, useManagedByColumn as Xe, useTableState as Ye, useFetcher as Ze, useDeleteUrlBuilder as eo, FetcherStatus as oo, EntityBaseTable as to, PermissionsWrapper as ce, getManagedByLabel as so, TableTags as ro, EntityFilter as no, EntityDeleteModal as ao, EntityTypes as uo, useErrors as io, useValidators as co, EntityBaseFormType as _e, EntityBaseForm as lo, SupportedEntityType as Fe, EntityFormSection as Pe, EntityBaseConfigCard as mo } from "@kong-ui-public/entities-shared";
6
+ const po = { list: { table_headers: { name: "Name", consumers_count: "Consumers", tags: "Tags", id: "ID" }, empty_state: { title: "Configure a new consumer group", description: "Use consumer groups to manage custom rate limiting configuration for subsets of consumers.", title_for_consumer: "Add to a consumer group" }, empty_state_v2: { title: "Configure your first consumer group", group: "Consumer groups created in gateways within this group will automatically appear here.", description: "Organize consumers into groups to easily apply policies like rate limiting and authentication across the entire group.", learn_more: "Learn more" }, toolbar_actions: { new_consumer_group: "New consumer group" } }, title: "Consumer groups", search: { placeholder: "Filter by exact name or ID" }, actions: { add_to_group: "Add to consumer group", create: "New consumer group", copy_id: "Copy ID", copy_json: "Copy JSON", edit: "Edit", delete: "Delete", exit: "Exit", view: "View details" }, delete: { title: "Delete a consumer group", description: "Deleting this group will remove all its plugins and rate limit configuration. This action cannot be reversed." }, consumers: { add: { title: "Add to consumer groups", ctaText: "Add this consumer to consumer groups", consumer_groups_label: "Consumer groups", consumer_group_placeholder: "Add to consumer groups", footer: "Search by exact name or ID to find consumer groups not included in the list" }, exit: { title: "Exit from a consumer group", confirmation: "Are you sure you want to remove consumer {consumer} from consumer group {consumerGroup}?", confirmationNoUsername: "Are you sure you want this consumer to exit from consumer group {consumerGroup}?", description: "Exiting from the group could change the rate limit policy applied to this consumer." } }, errors: { general: "Consumer groups could not be retrieved", delete: "The consumer group could not be deleted at this time.", copy: "Failed to copy to clipboard", add: "The consumer could not be added to some groups at this time.", already_added: "The consumer is already in this consumer group", add_consumer: "An unexpected error occurred while adding consumers. Please try again.", remove_consumer: "An unexpected error occurred while removing consumers. Please try again." }, copy: { success: "Copied {val} to clipboard", success_brief: "Successfully copied to clipboard" }, form: { general_info: { title: "General information", description: "General information will help identify and manage this consumer group." }, consumers: { title: "Consumers", description: "Add or remove consumers from this group" }, fields: { name: { label: "Name", placeholder: "Enter a unique name for this consumer group " }, tags: { label: "Tags", placeholder: "Enter a list of tags separated by comma", help: "e.g. tag1, tag2, tag3", tooltip: "An optional set of strings for grouping and filtering, separated by commas." }, consumers: { label: "Consumers", placeholder: "Select one or more consumers" } } } }, go = {
7
+ consumer_groups: po
8
+ };
9
+ function fo() {
10
+ const e = ze("en-us", go);
11
+ return {
12
+ i18n: e,
13
+ i18nT: We(e)
14
+ // Translation component <i18n-t>
15
+ };
16
+ }
17
+ const de = {
18
+ useI18n: fo
19
+ }, P = "/v2/control-planes/{controlPlaneId}/core-entities/{workspace}", G = "/{workspace}", Q = {
20
+ list: {
21
+ konnect: {
22
+ all: `${P}/consumer_groups`,
23
+ forModal: `${P}/consumer_groups`,
24
+ forConsumer: `${P}/consumers/{consumerId}/consumer_groups`,
25
+ oneForConsumer: `${P}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
26
+ },
27
+ kongManager: {
28
+ all: `${G}/consumer_groups?counter=true`,
29
+ // we need counter=true to get consumers_count in consumer group list
30
+ forModal: `${G}/consumer_groups`,
31
+ forConsumer: `${G}/consumers/{consumerId}/consumer_groups`,
32
+ oneForConsumer: `${G}/consumers/{consumerId}/consumer_groups/{consumerGroupId}`
33
+ }
34
+ },
35
+ form: {
36
+ konnect: {
37
+ consumersList: `${P}/consumers`,
38
+ create: `${P}/consumer_groups`,
39
+ edit: `${P}/consumer_groups/{id}`,
40
+ addConsumer: `${P}/consumer_groups/{id}/consumers`,
41
+ removeConsumer: `${P}/consumer_groups/{id}/consumers/{consumerId}`,
42
+ getConsumers: `${P}/consumer_groups/{id}/consumers`
43
+ },
44
+ kongManager: {
45
+ consumersList: `${G}/consumers`,
46
+ create: `${G}/consumer_groups`,
47
+ edit: `${G}/consumer_groups/{id}`,
48
+ addConsumer: `${G}/consumer_groups/{id}/consumers`,
49
+ removeConsumer: `${G}/consumer_groups/{id}/consumers/{consumerId}`,
50
+ getConsumers: `${G}/consumer_groups/{id}/consumers`
51
+ }
52
+ },
53
+ item: {
54
+ konnect: `${P}/consumer_groups/{id}?list_consumers=false`,
55
+ kongManager: `${G}/consumer_groups/{id}?list_consumers=false`
56
+ }
57
+ }, vo = { class: "add-to-group-form-container" }, yo = { class: "add-to-group-cta-text" }, _o = {
58
+ key: 0,
59
+ class: "kong-ui-entity-add-to-groups-error"
60
+ }, ho = { key: 0 }, bo = /* @__PURE__ */ le({
61
+ __name: "AddToGroupModal",
62
+ props: {
63
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
64
+ config: {
65
+ type: Object,
66
+ required: !0,
67
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.consumerId)
68
+ },
69
+ visible: {
70
+ type: Boolean,
71
+ required: !0
72
+ }
73
+ },
74
+ emits: ["cancel", "add:success", "add:partial-success", "error"],
75
+ setup(e, { emit: K }) {
76
+ const { i18n: { t: a } } = de.useI18n(), t = e, p = K, { axiosInstance: u } = be(t.config?.axiosRequestConfig), n = h([]), {
77
+ debouncedQueryChange: w,
78
+ loading: ee,
79
+ allRecords: V,
80
+ error: oe,
81
+ loadItems: te,
82
+ results: J
83
+ } = Ve(
84
+ t.config,
85
+ Q.list[t.config.app].forModal,
86
+ "",
87
+ {
88
+ fetchedItemsKey: "data",
89
+ searchKeys: ["name", "id"]
90
+ }
91
+ ), A = y(() => oe.value ? a("consumer_groups.errors.general") : ""), z = h(0), S = y(() => V.value === void 0), W = y(() => J.value.map((m) => ({
92
+ label: m.name,
93
+ value: m.id,
94
+ selected: n.value.includes(m.id),
95
+ data: m
96
+ // we need this to determine whether or not to show the description text
97
+ }))), X = (m) => {
98
+ const _ = S.value ? J.value.find((I) => I.id === m) : V.value?.find((I) => I.id === m);
99
+ return _ ? _.name : m;
100
+ }, se = () => {
101
+ E.value = "", F.value = [], x.value = [], p("cancel");
102
+ }, F = h([]), $ = h(!1), E = h(""), re = async () => {
103
+ if (!n.value.length) {
104
+ E.value = "", x.value = [], p("cancel");
105
+ return;
106
+ }
107
+ $.value = !0, E.value = "", F.value = [], x.value = [];
108
+ try {
109
+ const m = n.value.map((k) => ae(k)), _ = await Promise.allSettled(m);
110
+ let I = !0;
111
+ _.forEach((k) => {
112
+ k.status !== "fulfilled" && (I = !1);
113
+ }), I ? (F.value = [], x.value = [], p("add:success", n.value), n.value = []) : (F.value.length && p("add:partial-success", F.value), n.value = [], Y(_));
114
+ } catch {
115
+ E.value = a("consumer_groups.errors.add"), p("error", E.value);
116
+ } finally {
117
+ $.value = !1;
118
+ }
119
+ }, ne = y(() => {
120
+ let m = `${t.config.apiBaseUrl}${Q.list[t.config.app].forConsumer}`;
121
+ return t.config.app === "konnect" && (m = m.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || "")), m.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
122
+ }), ae = async (m) => {
123
+ const _ = {
124
+ group: m
125
+ };
126
+ try {
127
+ const I = await u.post(ne.value, _);
128
+ return F.value.push(m), I;
129
+ } catch (I) {
130
+ let k = `${X(m)} - ${I.message}`;
131
+ return I.response.status === 409 && (k = `${X(m)} - ${a("consumer_groups.errors.already_added")}`), Promise.reject(Error(k));
132
+ }
133
+ }, x = h([]), Y = (m) => {
134
+ x.value = m.map((_) => _.reason?.message).filter(Boolean);
135
+ };
136
+ return he(W, () => {
137
+ z.value++;
138
+ }, { immediate: !0, deep: !0 }), he(() => t.visible, () => {
139
+ t.visible && te();
140
+ }, { immediate: !0 }), (m, _) => {
141
+ const I = B("KMultiselect"), k = B("KAlert"), H = B("KPrompt");
142
+ return M(), j(H, {
143
+ "action-button-disabled": $.value,
144
+ class: "kong-ui-entities-add-to-groups-modal",
145
+ "data-testid": "add-to-group-modal",
146
+ title: o(a)("consumer_groups.consumers.add.title"),
147
+ visible: e.visible,
148
+ onCancel: se,
149
+ onProceed: re
150
+ }, {
151
+ default: c(() => [
152
+ T("div", vo, [
153
+ T("p", yo, C(o(a)("consumer_groups.consumers.add.ctaText")), 1),
154
+ d(I, {
155
+ modelValue: n.value,
156
+ "onUpdate:modelValue": _[0] || (_[0] = (D) => n.value = D),
157
+ autosuggest: "",
158
+ "data-testid": "add-to-groups-multiselect",
159
+ "dropdown-footer-text": S.value ? o(a)("consumer_groups.consumers.add.footer") : void 0,
160
+ items: W.value,
161
+ label: o(a)("consumer_groups.consumers.add.consumer_groups_label"),
162
+ loading: o(ee),
163
+ placeholder: o(a)("consumer_groups.consumers.add.consumer_group_placeholder"),
164
+ readonly: $.value,
165
+ required: "",
166
+ width: "100%",
167
+ onQueryChange: o(w)
168
+ }, null, 8, ["modelValue", "dropdown-footer-text", "items", "label", "loading", "placeholder", "readonly", "onQueryChange"]),
169
+ E.value || A.value || x.value.length ? (M(), L("div", _o, [
170
+ d(k, { appearance: "danger" }, {
171
+ default: c(() => [
172
+ T("p", null, C(o(a)("consumer_groups.errors.add")), 1),
173
+ x.value.length ? (M(), L("ul", ho, [
174
+ (M(!0), L(Le, null, Qe(x.value, (D, ue) => (M(), L("li", { key: ue }, C(D), 1))), 128))
175
+ ])) : O("", !0),
176
+ T("div", null, C(E.value || A.value), 1)
177
+ ]),
178
+ _: 1
179
+ })
180
+ ])) : O("", !0)
181
+ ])
182
+ ]),
183
+ _: 1
184
+ }, 8, ["action-button-disabled", "title", "visible"]);
185
+ };
186
+ }
187
+ }), Ce = (e, K) => {
188
+ const a = e.__vccOpts || e;
189
+ for (const [t, p] of K)
190
+ a[t] = p;
191
+ return a;
192
+ }, Co = /* @__PURE__ */ Ce(bo, [["__scopeId", "data-v-54887165"]]), ko = { class: "kong-ui-entities-consumer-groups-list" }, Io = { class: "button-row" }, wo = /* @__PURE__ */ le({
193
+ __name: "ConsumerGroupList",
194
+ props: {
195
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
196
+ config: {
197
+ type: Object,
198
+ required: !0,
199
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || !e.createRoute || !e.getViewRoute || !e.getEditRoute || e.app === "kongManager" && !e.isExactMatch && !e.filterSchema)
200
+ },
201
+ // used to override the default identifier for the cache entry
202
+ cacheIdentifier: {
203
+ type: String,
204
+ default: ""
205
+ },
206
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can create a new entity */
207
+ canCreate: {
208
+ type: Function,
209
+ required: !1,
210
+ default: async () => !0
211
+ },
212
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can delete a given entity */
213
+ canDelete: {
214
+ type: Function,
215
+ required: !1,
216
+ default: async () => !0
217
+ },
218
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can edit a given entity */
219
+ canEdit: {
220
+ type: Function,
221
+ required: !1,
222
+ default: async () => !0
223
+ },
224
+ /** A synchronous or asynchronous function, that returns a boolean, that evaluates if the user can retrieve (view details) a given entity */
225
+ canRetrieve: {
226
+ type: Function,
227
+ required: !1,
228
+ default: async () => !0
229
+ },
230
+ /** default to false, setting to true will teleport the toolbar button to the destination in the consuming app */
231
+ useActionOutside: {
232
+ type: Boolean,
233
+ default: !1
234
+ }
235
+ },
236
+ emits: ["error", "click:learn-more", "copy:success", "copy:error", "delete:success", "add:success", "remove:success"],
237
+ setup(e, { emit: K }) {
238
+ const a = K, t = e, { i18nT: p, i18n: { t: u } } = de.useI18n(), n = Te(), { axiosInstance: w } = be(t.config?.axiosRequestConfig), ee = y(() => t.config.app !== "kongManager" || !!t.config.disableSorting), V = {
239
+ // the Name column is non-hidable
240
+ name: { label: u("consumer_groups.list.table_headers.name"), searchable: !0, sortable: !0, hidable: !1 }
241
+ };
242
+ t.config.app === "kongManager" && (V.consumers_count = { label: u("consumer_groups.list.table_headers.consumers_count"), searchable: !1, sortable: !1 }), V.tags = { label: u("consumer_groups.list.table_headers.tags"), sortable: !1 };
243
+ const { defaultTablePreferences: oe, tableHeaders: te } = Xe(V), J = (r) => ({
244
+ "data-testid": r.username ?? r.custom_id ?? r.id
245
+ }), A = () => {
246
+ t.config.consumerId ? ke() : n.push(t.config.createRoute);
247
+ }, z = y(() => {
248
+ let r = `${t.config.apiBaseUrl}${Q.list[t.config.app][$.value ? "forConsumer" : "all"]}`;
249
+ return t.config.app === "konnect" && (r = r.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || ""), S.value && t.config.isExactMatch && (r += "?list_consumers=false")), r.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
250
+ }), S = h(""), W = y(() => {
251
+ const r = t.config.app === "konnect" || t.config.isExactMatch;
252
+ return r ? {
253
+ isExactMatch: r,
254
+ fields: {
255
+ username: V.name,
256
+ id: { label: u("consumer_groups.list.table_headers.id") }
257
+ },
258
+ placeholder: u("consumer_groups.search.placeholder")
259
+ } : {
260
+ isExactMatch: r,
261
+ fields: {
262
+ name: V.name
263
+ },
264
+ schema: t.config.filterSchema
265
+ };
266
+ }), { hasRecords: X, handleStateChange: se } = Ye(S), F = y(() => X.value && t.config.app === "konnect"), $ = y(() => !!t.config.consumerId), E = y(
267
+ () => $.value ? "kong-ui-entities-consumer-groups-list-in-consumer-page" : "kong-ui-entities-consumer-groups-list"
268
+ ), re = y(() => t.config.app === "konnect" && S.value ? "consumer_group" : $.value && !t.config.paginatedEndpoint ? "consumer_groups" : void 0), {
269
+ fetcher: ne,
270
+ fetcherState: ae,
271
+ fetcherCacheKey: x
272
+ } = Ze(y(() => ({ ...t.config, cacheIdentifier: t.cacheIdentifier })), z, re), Y = () => {
273
+ S.value = "";
274
+ }, m = () => {
275
+ x.value++;
276
+ }, _ = h(null), I = async (r, b) => {
277
+ const R = r.id;
278
+ if (!await b(R)) {
279
+ a("copy:error", {
280
+ entity: r,
281
+ field: "id",
282
+ message: u("consumer_groups.errors.copy")
283
+ });
284
+ return;
285
+ }
286
+ a("copy:success", {
287
+ entity: r,
288
+ field: "id",
289
+ message: u("consumer_groups.copy.success", { val: R })
290
+ });
291
+ }, k = async (r, b) => {
292
+ const R = JSON.stringify(r);
293
+ if (!await b(R)) {
294
+ a("copy:error", {
295
+ entity: r,
296
+ message: u("consumer_groups.errors.copy")
297
+ });
298
+ return;
299
+ }
300
+ a("copy:success", {
301
+ entity: r,
302
+ message: u("consumer_groups.copy.success_brief")
303
+ });
304
+ }, H = async (r) => {
305
+ await t.canRetrieve?.(r) && n.push(t.config.getViewRoute(r.id));
306
+ }, D = (r) => ({
307
+ label: u("consumer_groups.actions.view"),
308
+ to: t.config.getViewRoute(r)
309
+ }), ue = (r) => ({
310
+ label: u("consumer_groups.actions.edit"),
311
+ to: t.config.getEditRoute(r)
312
+ }), U = h(void 0), Z = h(!1), s = h(!1), i = h(""), l = eo(t.config, z.value), f = (r) => {
313
+ U.value = r, Z.value = !0;
314
+ }, v = () => {
315
+ Z.value = !1;
316
+ }, Be = async () => {
317
+ if (U.value?.id) {
318
+ s.value = !0;
319
+ try {
320
+ await w.delete(l(U.value.id)), s.value = !1, Z.value = !1, x.value++, a("delete:success", U.value);
321
+ } catch (r) {
322
+ i.value = r.response?.data?.message || r.message || u("consumer_groups.errors.delete"), a("error", r);
323
+ } finally {
324
+ s.value = !1;
325
+ }
326
+ }
327
+ }, me = h(!1), ke = () => {
328
+ me.value = !0;
329
+ }, Ie = () => {
330
+ me.value = !1;
331
+ }, we = (r, b) => {
332
+ b || Ie(), x.value++, a("add:success", r);
333
+ }, Ke = () => {
334
+ $.value && ke();
335
+ }, N = h(void 0), pe = h(!1), De = h(""), Ue = (r) => {
336
+ N.value = r, pe.value = !0;
337
+ }, $e = () => {
338
+ pe.value = !1, N.value = void 0;
339
+ }, Re = y(() => {
340
+ let r = `${t.config.apiBaseUrl}${Q.list[t.config.app].oneForConsumer}`;
341
+ return t.config.app === "konnect" && (r = r.replace(/{controlPlaneId}/gi, t.config?.controlPlaneId || "")), r.replace(/\/{workspace}/gi, t.config?.workspace ? `/${t.config.workspace}` : "").replace(/{consumerId}/gi, t.config?.consumerId || "");
342
+ }), Ee = h(!1), qe = async () => {
343
+ if (N.value) {
344
+ Ee.value = !0;
345
+ try {
346
+ const r = Re.value.replace(/{consumerGroupId}/gi, N.value.id);
347
+ await w.delete(r), a("remove:success", N.value), $e(), x.value++;
348
+ } catch (r) {
349
+ De.value = r.message || u("consumer_groups.errors.delete"), a("error", r);
350
+ } finally {
351
+ Ee.value = !1;
352
+ }
353
+ }
354
+ };
355
+ he(ae, (r) => {
356
+ if (r.status === oo.Error) {
357
+ _.value = {
358
+ title: u("consumer_groups.errors.general")
359
+ }, r.error?.response?.data?.message && (_.value.message = r.error.response.data.message), a("error", r.error);
360
+ return;
361
+ }
362
+ _.value = null;
363
+ });
364
+ const ge = h({
365
+ ctaPath: $.value ? void 0 : t.config.createRoute,
366
+ ctaText: void 0,
367
+ message: `${u("consumer_groups.list.empty_state.description")}${t.config.additionMessageForEmptyState ? ` ${t.config.additionMessageForEmptyState}` : ""}`,
368
+ title: u("consumer_groups.title")
369
+ }), fe = h(!1);
370
+ return Ge(async () => {
371
+ fe.value = await t.canCreate(), fe.value && (ge.value.title = $.value ? u("consumer_groups.list.empty_state.title_for_consumer") : u("consumer_groups.list.empty_state.title"), ge.value.ctaText = $.value ? u("consumer_groups.actions.add_to_group") : u("consumer_groups.actions.create"));
372
+ }), (r, b) => {
373
+ const R = B("KButton"), Oe = B("KEmptyState"), ie = B("KDropdownItem"), xe = B("KClipboardProvider"), Ne = B("KPrompt");
374
+ return M(), L("div", ko, [
375
+ d(o(to), {
376
+ "cache-identifier": e.cacheIdentifier,
377
+ "default-table-preferences": o(oe),
378
+ "disable-pagination": $.value && !e.config.paginatedEndpoint,
379
+ "disable-sorting": ee.value,
380
+ "empty-state-options": ge.value,
381
+ "enable-entity-actions": "",
382
+ "error-message": _.value,
383
+ fetcher: o(ne),
384
+ "fetcher-cache-key": o(x),
385
+ "pagination-type": "offset",
386
+ "preferences-storage-key": E.value,
387
+ query: S.value,
388
+ "row-attributes": J,
389
+ "table-headers": o(te),
390
+ onClearSearchInput: Y,
391
+ "onClick:row": b[3] || (b[3] = (g) => H(g)),
392
+ onEmptyStateCtaClicked: Ke,
393
+ onSort: m,
394
+ onState: o(se)
395
+ }, ye({
396
+ "toolbar-filter": c(() => [
397
+ $.value ? O("", !0) : (M(), j(o(no), {
398
+ key: 0,
399
+ modelValue: S.value,
400
+ "onUpdate:modelValue": b[0] || (b[0] = (g) => S.value = g),
401
+ config: W.value
402
+ }, null, 8, ["modelValue", "config"]))
403
+ ]),
404
+ "toolbar-button": c(() => [
405
+ (M(), j(He, {
406
+ disabled: !e.useActionOutside,
407
+ to: "#kong-ui-app-page-header-action-button"
408
+ }, [
409
+ T("div", Io, [
410
+ F.value ? (M(), j(R, {
411
+ key: 0,
412
+ appearance: "secondary",
413
+ class: "open-learning-hub",
414
+ "data-testid": "consumer-groups-learn-more-button",
415
+ icon: "",
416
+ onClick: b[1] || (b[1] = (g) => r.$emit("click:learn-more"))
417
+ }, {
418
+ default: c(() => [
419
+ d(o(Se), { decorative: "" })
420
+ ]),
421
+ _: 1
422
+ })) : O("", !0),
423
+ d(o(ce), {
424
+ "auth-function": () => e.canCreate()
425
+ }, {
426
+ default: c(() => [
427
+ d(R, {
428
+ appearance: "primary",
429
+ "data-testid": "toolbar-add-consumer-group",
430
+ size: e.useActionOutside ? "medium" : "large",
431
+ onClick: A
432
+ }, {
433
+ default: c(() => [
434
+ d(o(Ae)),
435
+ q(" " + C(e.config.consumerId ? o(u)("consumer_groups.actions.add_to_group") : o(u)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)
436
+ ]),
437
+ _: 1
438
+ }, 8, ["size"])
439
+ ]),
440
+ _: 1
441
+ }, 8, ["auth-function"])
442
+ ])
443
+ ], 8, ["disabled"]))
444
+ ]),
445
+ name: c(({ rowValue: g }) => [
446
+ T("b", null, C(g ?? "-"), 1)
447
+ ]),
448
+ consumers_count: c(({ rowValue: g }) => [
449
+ q(C(g ?? "-"), 1)
450
+ ]),
451
+ tags: c(({ rowValue: g }) => [
452
+ d(o(ro), { tags: g }, null, 8, ["tags"])
453
+ ]),
454
+ managed_by: c(({ rowValue: g }) => [
455
+ q(C(o(so)(g) ?? "-"), 1)
456
+ ]),
457
+ actions: c(({ row: g }) => [
458
+ d(xe, null, {
459
+ default: c(({ copyToClipboard: ve }) => [
460
+ d(ie, {
461
+ "data-testid": "action-entity-copy-id",
462
+ onClick: (je) => I(g, ve)
463
+ }, {
464
+ default: c(() => [
465
+ q(C(o(u)("consumer_groups.actions.copy_id")), 1)
466
+ ]),
467
+ _: 1
468
+ }, 8, ["onClick"])
469
+ ]),
470
+ _: 2
471
+ }, 1024),
472
+ d(xe, null, {
473
+ default: c(({ copyToClipboard: ve }) => [
474
+ d(ie, {
475
+ "data-testid": "action-entity-copy-json",
476
+ onClick: (je) => k(g, ve)
477
+ }, {
478
+ default: c(() => [
479
+ q(C(o(u)("consumer_groups.actions.copy_json")), 1)
480
+ ]),
481
+ _: 1
482
+ }, 8, ["onClick"])
483
+ ]),
484
+ _: 2
485
+ }, 1024),
486
+ d(o(ce), {
487
+ "auth-function": () => e.canRetrieve(g)
488
+ }, {
489
+ default: c(() => [
490
+ d(ie, {
491
+ "data-testid": "action-entity-view",
492
+ "has-divider": "",
493
+ item: D(g.id)
494
+ }, null, 8, ["item"])
495
+ ]),
496
+ _: 2
497
+ }, 1032, ["auth-function"]),
498
+ d(o(ce), {
499
+ "auth-function": () => e.canEdit(g)
500
+ }, {
501
+ default: c(() => [
502
+ d(ie, {
503
+ "data-testid": "action-entity-edit",
504
+ item: ue(g.id)
505
+ }, null, 8, ["item"])
506
+ ]),
507
+ _: 2
508
+ }, 1032, ["auth-function"]),
509
+ d(o(ce), {
510
+ "auth-function": () => e.canDelete(g)
511
+ }, {
512
+ default: c(() => [
513
+ d(ie, {
514
+ danger: "",
515
+ "data-testid": "action-entity-delete",
516
+ "has-divider": "",
517
+ onClick: () => e.config.consumerId ? Ue(g) : f(g)
518
+ }, {
519
+ default: c(() => [
520
+ q(C(e.config.consumerId ? o(u)("consumer_groups.actions.exit") : o(u)("consumer_groups.actions.delete")), 1)
521
+ ]),
522
+ _: 1
523
+ }, 8, ["onClick"])
524
+ ]),
525
+ _: 2
526
+ }, 1032, ["auth-function"])
527
+ ]),
528
+ _: 2
529
+ }, [
530
+ !S.value && e.config.app === "konnect" ? {
531
+ name: "empty-state",
532
+ fn: c(() => [
533
+ d(Oe, {
534
+ "data-testid": "consumer-groups-entity-empty-state",
535
+ "icon-background": "",
536
+ message: o(u)("consumer_groups.list.empty_state_v2.description"),
537
+ title: o(u)("consumer_groups.list.empty_state_v2.title")
538
+ }, ye({
539
+ icon: c(() => [
540
+ d(o(Je), { decorative: "" })
541
+ ]),
542
+ action: c(() => [
543
+ fe.value ? (M(), j(R, {
544
+ key: 0,
545
+ "data-testid": "entity-create-button",
546
+ onClick: A
547
+ }, {
548
+ default: c(() => [
549
+ d(o(Ae), { decorative: "" }),
550
+ q(" " + C(o(u)("consumer_groups.list.toolbar_actions.new_consumer_group")), 1)
551
+ ]),
552
+ _: 1
553
+ })) : O("", !0),
554
+ d(R, {
555
+ appearance: "secondary",
556
+ "data-testid": "entity-learn-more-button",
557
+ onClick: b[2] || (b[2] = (g) => r.$emit("click:learn-more"))
558
+ }, {
559
+ default: c(() => [
560
+ d(o(Se), { decorative: "" }),
561
+ q(" " + C(o(u)("consumer_groups.list.empty_state_v2.learn_more")), 1)
562
+ ]),
563
+ _: 1
564
+ })
565
+ ]),
566
+ _: 2
567
+ }, [
568
+ e.config?.isControlPlaneGroup ? {
569
+ name: "default",
570
+ fn: c(() => [
571
+ q(C(o(u)("consumer_groups.list.empty_state_v2.group")), 1)
572
+ ]),
573
+ key: "0"
574
+ } : void 0
575
+ ]), 1032, ["message", "title"])
576
+ ]),
577
+ key: "0"
578
+ } : void 0
579
+ ]), 1032, ["cache-identifier", "default-table-preferences", "disable-pagination", "disable-sorting", "empty-state-options", "error-message", "fetcher", "fetcher-cache-key", "preferences-storage-key", "query", "table-headers", "onState"]),
580
+ d(o(ao), {
581
+ "action-pending": s.value,
582
+ "data-testid": "delete-consumer-group-modal",
583
+ description: o(u)("consumer_groups.delete.description"),
584
+ "entity-name": U.value && (U.value.name || U.value.id),
585
+ "entity-type": o(uo).ConsumerGroup,
586
+ error: i.value,
587
+ title: o(u)("consumer_groups.delete.title"),
588
+ visible: Z.value,
589
+ onCancel: v,
590
+ onProceed: Be
591
+ }, null, 8, ["action-pending", "description", "entity-name", "entity-type", "error", "title", "visible"]),
592
+ e.config.consumerId ? (M(), j(Co, {
593
+ key: 0,
594
+ config: e.config,
595
+ "data-testid": "add-to-group-modal",
596
+ visible: me.value,
597
+ "onAdd:partialSuccess": b[4] || (b[4] = (g) => we(g, !0)),
598
+ "onAdd:success": b[5] || (b[5] = (g) => we(g)),
599
+ onCancel: Ie
600
+ }, null, 8, ["config", "visible"])) : O("", !0),
601
+ e.config.consumerId && N.value ? (M(), j(Ne, {
602
+ key: 1,
603
+ "action-button-appearance": "danger",
604
+ "data-testid": "exit-group-modal",
605
+ title: o(u)("consumer_groups.consumers.exit.title"),
606
+ visible: pe.value,
607
+ onCancel: $e,
608
+ onProceed: qe
609
+ }, {
610
+ default: c(() => [
611
+ d(o(p), {
612
+ class: "exit-modal-message",
613
+ keypath: e.config.consumerUsername ? "consumer_groups.consumers.exit.confirmation" : "consumer_groups.consumers.exit.confirmationNoUsername",
614
+ tag: "p"
615
+ }, ye({
616
+ consumerGroup: c(() => [
617
+ T("strong", null, C(N.value.name || N.value.id), 1)
618
+ ]),
619
+ _: 2
620
+ }, [
621
+ e.config.consumerUsername ? {
622
+ name: "consumer",
623
+ fn: c(() => [
624
+ T("strong", null, C(e.config.consumerUsername), 1)
625
+ ]),
626
+ key: "0"
627
+ } : void 0
628
+ ]), 1032, ["keypath"]),
629
+ T("p", null, C(o(u)("consumer_groups.consumers.exit.description")), 1)
630
+ ]),
631
+ _: 1
632
+ }, 8, ["title", "visible"])) : O("", !0)
633
+ ]);
634
+ };
635
+ }
636
+ }), Bo = /* @__PURE__ */ Ce(wo, [["__scopeId", "data-v-0da0fd50"]]), $o = { class: "kong-ui-entities-consumer-group-form" }, Eo = { class: "select-item-container" }, xo = { class: "select-item-label" }, Mo = {
637
+ key: 0,
638
+ class: "select-item-description"
639
+ }, So = /* @__PURE__ */ le({
640
+ __name: "ConsumerGroupForm",
641
+ props: {
642
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
643
+ config: {
644
+ type: Object,
645
+ required: !0,
646
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e?.app === "konnect" && !e?.controlPlaneId || e?.app === "kongManager" && typeof e?.workspace != "string" || !e?.cancelRoute)
647
+ },
648
+ /** If a valid consumerGroupId is provided, it will put the form in Edit mode instead of Create */
649
+ consumerGroupId: {
650
+ type: String,
651
+ required: !1,
652
+ default: null
653
+ },
654
+ hideConsumers: {
655
+ type: Boolean,
656
+ default: !1
657
+ }
658
+ },
659
+ emits: ["update", "error", "loading"],
660
+ setup(e, { emit: K }) {
661
+ const a = e, t = K, { i18n: { t: p } } = de.useI18n(), u = Te(), n = Me({
662
+ fields: {
663
+ name: "",
664
+ tags: "",
665
+ consumers: []
666
+ },
667
+ errorMessage: "",
668
+ readonly: !1
669
+ }), w = Me({
670
+ name: "",
671
+ tags: "",
672
+ consumers: []
673
+ }), {
674
+ debouncedQueryChange: ee,
675
+ loading: V,
676
+ error: oe,
677
+ loadItems: te,
678
+ results: J
679
+ } = Ve(a.config, Q.form[a.config?.app]?.consumersList, "", {
680
+ fetchedItemsKey: "data",
681
+ searchKeys: ["username", "custom_id", "id"]
682
+ }), { axiosInstance: A } = be(a.config?.axiosRequestConfig), { getMessageFromError: z } = io(), S = co(), W = y(() => J.value.map((s) => ({
683
+ label: s.username || s.custom_id,
684
+ value: s.id,
685
+ selected: n.fields.consumers.includes(s.id),
686
+ data: s
687
+ // we need this to determine whether or not to show the description text
688
+ }))), X = y(() => Q.form[a.config?.app].edit), se = y(() => a.consumerGroupId ? _e.Edit : _e.Create), F = y(() => !!n.fields.name && !Y.value), $ = y(() => JSON.stringify(n.fields) !== JSON.stringify(w)), E = (s, i = "", l = "") => {
689
+ let f = `${a.config?.apiBaseUrl}${Q.form[a.config?.app][s]}`;
690
+ return a.config?.app === "konnect" && (f = f.replace(/{controlPlaneId}/gi, a.config?.controlPlaneId || "")), f = f.replace(/\/{workspace}/gi, a.config?.workspace ? `/${a.config.workspace}` : "").replace(/{id}/gi, (i || a.consumerGroupId) ?? ""), (s === "addConsumer" || s === "removeConsumer") && (f = f.replace(/{consumerId}/gi, l)), f;
691
+ }, re = () => {
692
+ u.push(a.config?.cancelRoute || { name: "consumer-group-list" });
693
+ }, ne = (s) => {
694
+ t("error", s);
695
+ }, ae = (s) => {
696
+ t("loading", s);
697
+ }, x = async (s) => {
698
+ n.fields.name = s?.item?.name || s?.consumer_group?.name || s?.name || "";
699
+ const i = s?.item?.tags || s?.consumer_group.tags || s?.tags || [];
700
+ if (n.fields.tags = i?.join(", ") || "", "consumers" in s)
701
+ n.fields.consumers = s?.consumers?.map((l) => l.id) || [];
702
+ else
703
+ try {
704
+ const { data: l } = await A.get(E("getConsumers"));
705
+ n.fields.consumers = "consumers" in l ? l?.consumers?.map((f) => f.id) : [];
706
+ } catch (l) {
707
+ k(l);
708
+ }
709
+ Object.assign(w, n.fields);
710
+ }, Y = y(() => S.utf8Name(n.fields.name)), m = y(() => ({
711
+ name: n.fields.name,
712
+ tags: n.fields.tags.split(",")?.map((s) => String(s || "").trim())?.filter((s) => s !== "")
713
+ })), _ = async (s, i = "") => await A.post(E("addConsumer", i, s), { consumer: s }), I = async (s, i = "") => await A.delete(E("removeConsumer", i, s)), k = (s) => {
714
+ n.errorMessage = z(s), t("error", s);
715
+ }, H = (s = a.consumerGroupId ?? "") => {
716
+ Object.assign(w, n.fields), t("update", { ...n.fields, id: s });
717
+ }, D = (s, i, l = a.consumerGroupId ?? "") => {
718
+ const f = s?.find((v) => v.status !== "fulfilled");
719
+ f ? k({
720
+ code: f.status,
721
+ message: i
722
+ }) : H(l);
723
+ }, ue = async () => {
724
+ let s = "";
725
+ try {
726
+ const { data: i } = await A.post(E("create"), m.value);
727
+ s = "item" in i ? i.item.id : i.id;
728
+ } catch (i) {
729
+ k(i);
730
+ }
731
+ if (n.fields.consumers.length > 0 && s)
732
+ try {
733
+ const i = n.fields.consumers.map((f) => _(f, s)), l = await Promise.allSettled(i);
734
+ D(l, p("consumer_groups.errors.add_consumer"), s);
735
+ } catch (i) {
736
+ k(i);
737
+ }
738
+ else n.fields.consumers.length === 0 && s && H(s);
739
+ }, U = async () => {
740
+ try {
741
+ a.config?.app === "konnect" ? await A.put(E("edit"), m.value) : await A.patch(E("edit"), m.value);
742
+ } catch (l) {
743
+ k(l);
744
+ }
745
+ const s = n.fields.consumers.filter((l) => !w.consumers.includes(l)), i = w.consumers.filter((l) => !n.fields.consumers.includes(l));
746
+ if (i.length === 0 && s.length === 0)
747
+ H();
748
+ else {
749
+ if (i.length > 0)
750
+ try {
751
+ const l = i.map((v) => I(v)), f = await Promise.allSettled(l);
752
+ D(f, p("consumer_groups.errors.remove_consumer"));
753
+ } catch (l) {
754
+ k(l);
755
+ }
756
+ if (s.length > 0)
757
+ try {
758
+ const l = s.map((v) => _(v)), f = await Promise.allSettled(l);
759
+ D(f, p("consumer_groups.errors.add_consumer"));
760
+ } catch (l) {
761
+ k(l);
762
+ }
763
+ }
764
+ }, Z = async () => {
765
+ try {
766
+ n.readonly = !0, se.value === _e.Create ? await ue() : await U();
767
+ } finally {
768
+ n.readonly = !1;
769
+ }
770
+ };
771
+ return Ge(async () => {
772
+ a.hideConsumers || await te();
773
+ }), (s, i) => {
774
+ const l = B("KInput"), f = B("KMultiselect");
775
+ return M(), L("div", $o, [
776
+ d(o(lo), {
777
+ "can-submit": F.value && $.value,
778
+ config: e.config,
779
+ "edit-id": e.consumerGroupId,
780
+ "entity-type": o(Fe).ConsumerGroup,
781
+ "error-message": n.errorMessage || o(oe) || Y.value,
782
+ "fetch-url": X.value,
783
+ "form-fields": m.value,
784
+ "is-readonly": n.readonly,
785
+ onCancel: re,
786
+ "onFetch:error": i[3] || (i[3] = (v) => ne(v)),
787
+ "onFetch:success": x,
788
+ onLoading: i[4] || (i[4] = (v) => ae(v)),
789
+ onSubmit: Z
790
+ }, {
791
+ default: c(() => [
792
+ d(o(Pe), {
793
+ description: o(p)("consumer_groups.form.general_info.description"),
794
+ title: o(p)("consumer_groups.form.general_info.title")
795
+ }, {
796
+ default: c(() => [
797
+ d(l, {
798
+ modelValue: n.fields.name,
799
+ "onUpdate:modelValue": i[0] || (i[0] = (v) => n.fields.name = v),
800
+ modelModifiers: { trim: !0 },
801
+ autocomplete: "off",
802
+ "data-testid": "consumer-group-form-name",
803
+ label: o(p)("consumer_groups.form.fields.name.label"),
804
+ placeholder: o(p)("consumer_groups.form.fields.name.placeholder"),
805
+ required: "",
806
+ type: "text"
807
+ }, null, 8, ["modelValue", "label", "placeholder"]),
808
+ d(l, {
809
+ modelValue: n.fields.tags,
810
+ "onUpdate:modelValue": i[1] || (i[1] = (v) => n.fields.tags = v),
811
+ modelModifiers: { trim: !0 },
812
+ autocomplete: "off",
813
+ "data-testid": "consumer-group-form-tags",
814
+ help: o(p)("consumer_groups.form.fields.tags.help"),
815
+ label: o(p)("consumer_groups.form.fields.tags.label"),
816
+ "label-attributes": {
817
+ info: o(p)("consumer_groups.form.fields.tags.tooltip"),
818
+ tooltipAttributes: { maxWidth: "400" }
819
+ },
820
+ placeholder: o(p)("consumer_groups.form.fields.tags.placeholder"),
821
+ type: "text"
822
+ }, null, 8, ["modelValue", "help", "label", "label-attributes", "placeholder"])
823
+ ]),
824
+ _: 1
825
+ }, 8, ["description", "title"]),
826
+ e.hideConsumers ? O("", !0) : (M(), j(o(Pe), {
827
+ key: 0,
828
+ description: o(p)("consumer_groups.form.consumers.description"),
829
+ "has-divider": "",
830
+ title: o(p)("consumer_groups.form.consumers.title")
831
+ }, {
832
+ default: c(() => [
833
+ d(f, {
834
+ modelValue: n.fields.consumers,
835
+ "onUpdate:modelValue": i[2] || (i[2] = (v) => n.fields.consumers = v),
836
+ appearance: "select",
837
+ autosuggest: "",
838
+ items: W.value,
839
+ label: o(p)("consumer_groups.form.fields.consumers.label"),
840
+ loading: o(V),
841
+ placeholder: o(p)("consumer_groups.form.fields.consumers.placeholder"),
842
+ width: "auto",
843
+ onQueryChange: o(ee)
844
+ }, {
845
+ "item-template": c(({ item: v }) => [
846
+ T("div", Eo, [
847
+ T("div", xo, C(v.label), 1),
848
+ v?.data?.username && v?.data?.custom_id ? (M(), L("div", Mo, C(v?.data?.custom_id), 1)) : O("", !0)
849
+ ])
850
+ ]),
851
+ _: 1
852
+ }, 8, ["modelValue", "items", "label", "loading", "placeholder", "onQueryChange"])
853
+ ]),
854
+ _: 1
855
+ }, 8, ["description", "title"]))
856
+ ]),
857
+ _: 1
858
+ }, 8, ["can-submit", "config", "edit-id", "entity-type", "error-message", "fetch-url", "form-fields", "is-readonly"])
859
+ ]);
860
+ };
861
+ }
862
+ }), Ko = /* @__PURE__ */ Ce(So, [["__scopeId", "data-v-9c98b878"]]), Ao = { class: "kong-ui-consumer-group-entity-config-card" }, Do = /* @__PURE__ */ le({
863
+ __name: "ConsumerGroupConfigCard",
864
+ props: {
865
+ /** The base konnect or kongManger config. Pass additional config props in the shared entity component as needed. */
866
+ config: {
867
+ type: Object,
868
+ required: !0,
869
+ validator: (e) => !(!e || !["konnect", "kongManager"].includes(e?.app) || e.app === "konnect" && !e.controlPlaneId || e.app === "kongManager" && typeof e.workspace != "string" || !e.entityId)
870
+ },
871
+ /**
872
+ * External link for documentation that determines visibility of Documentation button
873
+ */
874
+ configCardDoc: {
875
+ type: String,
876
+ default: "",
877
+ required: !1
878
+ },
879
+ /**
880
+ * Control visibility of card title content
881
+ */
882
+ hideTitle: {
883
+ type: Boolean,
884
+ default: !1
885
+ }
886
+ },
887
+ emits: ["loading", "fetch:error", "fetch:success"],
888
+ setup(e) {
889
+ const K = e, { i18n: { t: a } } = de.useI18n(), t = y(() => Q.item[K.config.app]), p = h({
890
+ id: {},
891
+ name: {},
892
+ created_at: {},
893
+ updated_at: {},
894
+ tags: {
895
+ tooltip: a("consumer_groups.form.fields.tags.tooltip")
896
+ }
897
+ });
898
+ return (u, n) => (M(), L("div", Ao, [
899
+ d(o(mo), {
900
+ config: e.config,
901
+ "config-card-doc": e.configCardDoc,
902
+ "config-schema": p.value,
903
+ "data-key": "consumer_group",
904
+ "entity-type": o(Fe).ConsumerGroup,
905
+ "fetch-url": t.value,
906
+ "hide-title": e.hideTitle,
907
+ "onFetch:error": n[0] || (n[0] = (w) => u.$emit("fetch:error", w)),
908
+ "onFetch:success": n[1] || (n[1] = (w) => u.$emit("fetch:success", w)),
909
+ onLoading: n[2] || (n[2] = (w) => u.$emit("loading", w))
910
+ }, null, 8, ["config", "config-card-doc", "config-schema", "entity-type", "fetch-url", "hide-title"])
911
+ ]));
912
+ }
913
+ });
914
+ export {
915
+ Do as ConsumerGroupConfigCard,
916
+ Ko as ConsumerGroupForm,
917
+ Bo as ConsumerGroupList
918
+ };