@sensinum/strapi-plugin-xecp 5.0.2 → 5.2.0

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 (34) hide show
  1. package/README.md +30 -16
  2. package/dist/admin/App-DCc6Nerz.js +30 -0
  3. package/dist/admin/App-FBmORCnP.mjs +2144 -0
  4. package/dist/admin/TruncatedTypography-CJdWCFOe.js +12 -0
  5. package/dist/admin/TruncatedTypography-D8gHowDS.mjs +49 -0
  6. package/dist/admin/{de-Bc7t3sCO.mjs → de-DPIfWiIq.mjs} +34 -2
  7. package/dist/admin/de-Dc27qqZI.js +1 -0
  8. package/dist/admin/{en-16Qqparh.mjs → en-CCG4TklL.mjs} +34 -2
  9. package/dist/admin/en-CPGWvai6.js +1 -0
  10. package/dist/admin/{fr-CMzm8jIl.mjs → fr-DnzU_m4o.mjs} +34 -2
  11. package/dist/admin/fr-uAOzHrhn.js +1 -0
  12. package/dist/admin/{index-Bgk0cBQK.mjs → index-B21jnMBg.mjs} +5 -5
  13. package/dist/admin/{index-ogQgaRcB.js → index-B2NfpbcT.js} +1 -1
  14. package/dist/admin/{index-BNa83Wfu.js → index-BHf1dfyp.js} +1 -1
  15. package/dist/admin/{index-DQgqKBmR.mjs → index-CwNAiNVu.mjs} +1 -1
  16. package/dist/admin/index-DTADzNmo.mjs +651 -0
  17. package/dist/admin/index-jgDj_iIg.js +1 -0
  18. package/dist/admin/index.js +1 -1
  19. package/dist/admin/index.mjs +1 -1
  20. package/dist/admin/pl-B1KyPSlZ.js +1 -0
  21. package/dist/admin/{pl-CuTaHdsS.mjs → pl-F5zNdZs4.mjs} +34 -2
  22. package/dist/server/index.js +10 -10
  23. package/dist/server/index.mjs +8376 -7795
  24. package/package.json +1 -1
  25. package/dist/admin/App-COKB0PXI.mjs +0 -1958
  26. package/dist/admin/App-CxQAwCC4.js +0 -30
  27. package/dist/admin/TruncatedTypography-72wp11m4.js +0 -12
  28. package/dist/admin/TruncatedTypography-Df3hMZdB.mjs +0 -34
  29. package/dist/admin/de-B5M8juGn.js +0 -1
  30. package/dist/admin/en-DXWBDgkB.js +0 -1
  31. package/dist/admin/fr-CPWgcURq.js +0 -1
  32. package/dist/admin/index-BnS-25UL.mjs +0 -610
  33. package/dist/admin/index-C0CxNaV6.js +0 -1
  34. package/dist/admin/pl-Blw4wk9g.js +0 -1
@@ -1,610 +0,0 @@
1
- import { jsx as t, Fragment as $, jsxs as u } from "react/jsx-runtime";
2
- import { useFetchClient as P, useForm as re, useNotification as se, Layouts as x, useRBAC as oe, Page as U, Form as ae } from "@strapi/strapi/admin";
3
- import { U as D, g as a, P as G } from "./index-Bgk0cBQK.mjs";
4
- import { S as K, P as le, Q as de } from "./queryKeys-rUHP1d6p.mjs";
5
- import { useEffect as ce, useRef as pe, useMemo as ue } from "react";
6
- import { useIntl as b } from "react-intl";
7
- import me, { z as m } from "zod";
8
- import { useQuery as _, queryOptions as ge, useQueryClient as he, useMutation as H } from "@tanstack/react-query";
9
- import { Box as E, Field as h, SingleSelect as ye, SingleSelectOption as Te, Typography as C, Table as fe, Thead as be, Tr as O, Th as L, Tbody as Ce, Td as q, MultiSelect as Ee, MultiSelectOption as ve, Flex as W, Tooltip as Se, Grid as A, NumberInput as Ae, TextInput as j, Button as z, Loader as we } from "@strapi/design-system";
10
- import { Information as Re, Check as X } from "@strapi/icons";
11
- import { isEqual as Pe } from "lodash";
12
- import { T as Q, A as Z } from "./TruncatedTypography-Df3hMZdB.mjs";
13
- const De = 3, w = m.enum(["Related", "Promotable"]);
14
- m.object({
15
- targetEnvApiKey: m.string().optional(),
16
- targetEnvApiUrl: m.url().optional(),
17
- comparisonDepth: m.number().positive().optional(),
18
- contentTypes: m.array(m.object({ uid: m.string(), key: m.string(), kind: w })).optional()
19
- });
20
- const Fe = () => {
21
- const { get: e } = P();
22
- return _({
23
- queryKey: [K],
24
- queryFn: async () => {
25
- const { data: n } = await e(`/${D}/settings`);
26
- return n;
27
- }
28
- });
29
- }, Ue = [
30
- K,
31
- "content-type-options"
32
- ], Ke = () => {
33
- const { get: e } = P();
34
- return _({
35
- queryKey: Ue,
36
- queryFn: async () => {
37
- const { data: n } = await e(
38
- `/${D}/settings/content-type-options`
39
- );
40
- return n;
41
- }
42
- });
43
- }, ke = (e) => [K, "related-content-types", e], Ie = (e, n) => ge({
44
- queryKey: ke(n),
45
- queryFn: async () => {
46
- const { data: r } = await e(
47
- `/${D}/settings/related-content-types`,
48
- {
49
- params: {
50
- allowed: n.join(",")
51
- }
52
- }
53
- );
54
- return r;
55
- }
56
- }), M = (e) => {
57
- const { get: n } = P();
58
- return _({
59
- ...Ie(n, e),
60
- enabled: e.length > 0
61
- });
62
- }, Le = () => {
63
- const { put: e } = P(), n = he();
64
- return H({
65
- mutationFn: async (r) => e(`/${D}/settings`, r),
66
- onSuccess: async () => {
67
- await Promise.all([
68
- n.invalidateQueries({ queryKey: [K] }),
69
- n.invalidateQueries({ queryKey: [le] })
70
- ]);
71
- }
72
- });
73
- }, qe = (e, n) => Object.entries(n).reduce((r, [o, i]) => Pe(i, e[o]) ? r : {
74
- ...r,
75
- [o]: i
76
- }, {}), J = m.object({
77
- allowedContentTypes: m.array(m.string()).min(1, { message: "settings.form.error.minimalArrayLength" }),
78
- contentTypeSettings: m.record(
79
- m.string(),
80
- m.object({
81
- key: m.string({ message: "settings.form.error.required" }).min(1, { message: "settings.form.error.required" }).optional()
82
- }).optional()
83
- ),
84
- targetEnvApiKey: m.string({ message: "settings.form.error.required" }).min(1, { message: "settings.form.error.required" }),
85
- targetEnvApiUrl: m.url({ message: "settings.form.error.validURL" }),
86
- comparisonDepth: m.number({ message: "settings.form.error.required" }).positive({ message: "settings.form.error.positive" })
87
- }), Ve = J.extend({
88
- relatedContentTypes: m.string().array()
89
- }), _e = Ve.refine(
90
- (e) => [
91
- ...e.allowedContentTypes,
92
- ...e.relatedContentTypes
93
- ].every(
94
- (r) => !!e.contentTypeSettings[r]?.key
95
- ),
96
- {
97
- path: ["allowedContentTypes"],
98
- message: "settings.form.error.uniqueKeyRequired",
99
- when(e) {
100
- return J.pick({ contentTypeSettings: !0 }).safeParse(e.value).success;
101
- }
102
- }
103
- ), Me = (e, n) => {
104
- const r = [...e.allowedContentTypes, ...n];
105
- return {
106
- ...e,
107
- contentTypeSettings: Object.fromEntries(
108
- r.map((o) => [
109
- o,
110
- e.contentTypeSettings[o]
111
- ])
112
- )
113
- };
114
- }, ee = (e) => e.replace(".", ":"), V = (e) => e.replace(/:(?!.*:)/, "."), Ne = (e, n) => {
115
- const o = {
116
- ...Me(n, e),
117
- relatedContentTypes: e
118
- }, i = _e.parse(o);
119
- return {
120
- contentTypes: [
121
- ...i.allowedContentTypes,
122
- ...i.relatedContentTypes
123
- ].map((l) => ({
124
- uid: V(l),
125
- key: i.contentTypeSettings[l]?.key,
126
- kind: i.allowedContentTypes.includes(l) ? w.enum.Promotable : w.enum.Related
127
- })),
128
- targetEnvApiKey: i.targetEnvApiKey,
129
- targetEnvApiUrl: i.targetEnvApiUrl,
130
- comparisonDepth: i.comparisonDepth
131
- };
132
- }, xe = {
133
- background: "neutral0",
134
- hasRadius: !0,
135
- shadow: "filterShadow",
136
- padding: 6,
137
- width: "100%"
138
- }, N = ({ children: e, marginTop: n }) => /* @__PURE__ */ t(E, { ...xe, marginTop: n, children: e }), Oe = ({ onChange: e, attributes: n, value: r, name: o, error: i, disabled: d = !1 }) => {
139
- const { formatMessage: l } = b(), g = Object.entries(n).filter(
140
- ([c, s]) => s.type === "uid" || s.unique === !0
141
- );
142
- return ce(() => {
143
- !r && g.length > 0 && e("");
144
- }, []), /* @__PURE__ */ t($, { children: g.length > 0 ? /* @__PURE__ */ u(h.Root, { error: i && l({ id: a(i) }), children: [
145
- /* @__PURE__ */ t(ye, { name: o, value: r, onChange: e, required: !0, disabled: d, children: g.map(([c, s]) => /* @__PURE__ */ t(Te, { value: c, children: c }, c)) }),
146
- /* @__PURE__ */ t(h.Error, {})
147
- ] }) : /* @__PURE__ */ t(
148
- h.Root,
149
- {
150
- error: l({ id: a("settings.table.uniqueKeyRequiredWarning") }),
151
- children: /* @__PURE__ */ t(h.Error, {})
152
- }
153
- ) });
154
- }, B = ({
155
- label: e,
156
- contentTypes: n,
157
- setFormValue: r,
158
- errors: o,
159
- contentTypeSettings: i,
160
- shouldShowRequiredBy: d,
161
- isReadOnly: l
162
- }) => {
163
- const { formatMessage: g } = b();
164
- return /* @__PURE__ */ u(E, { marginTop: 4, width: "100%", paddingTop: 4, children: [
165
- /* @__PURE__ */ t(E, { marginBottom: 1, children: /* @__PURE__ */ t(C, { variant: "pi", textColor: "neutral800", fontWeight: "bold", children: e }) }),
166
- /* @__PURE__ */ u(fe, { width: "100%", rowCount: n.length, colCount: d ? 3 : 2, children: [
167
- /* @__PURE__ */ t(be, { children: /* @__PURE__ */ u(O, { children: [
168
- /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(C, { variant: "sigma", children: g({ id: a("settings.table.contentType") }) }) }),
169
- d && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(C, { variant: "sigma", children: g({ id: a("settings.table.requiredBy") }) }) }),
170
- /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(C, { variant: "sigma", children: g({ id: a("settings.table.uniqueKey") }) }) })
171
- ] }) }),
172
- /* @__PURE__ */ t(Ce, { children: n.map((c) => {
173
- const s = `contentTypeSettings.${c.uid}.key`;
174
- return /* @__PURE__ */ u(O, { children: [
175
- /* @__PURE__ */ t(q, { width: d ? "25%" : "50%", children: /* @__PURE__ */ t(
176
- Q,
177
- {
178
- maxCharacters: 55,
179
- text: c.schema.displayName,
180
- textColor: "neutral800"
181
- }
182
- ) }),
183
- d && /* @__PURE__ */ t(q, { width: "25%", children: /* @__PURE__ */ t(
184
- Q,
185
- {
186
- maxCharacters: 55,
187
- text: c.requiredBy,
188
- textColor: "neutral800"
189
- }
190
- ) }),
191
- /* @__PURE__ */ t(q, { width: "50%", children: /* @__PURE__ */ t(
192
- Oe,
193
- {
194
- onChange: (p) => {
195
- r(s, p);
196
- },
197
- value: i[c.uid]?.key,
198
- attributes: c.schema.attributes,
199
- name: s,
200
- error: o[s],
201
- disabled: l
202
- }
203
- ) })
204
- ] }, c.uid);
205
- }) })
206
- ] })
207
- ] });
208
- }, je = ({
209
- allowedContentTypes: e,
210
- contentTypeSettings: n,
211
- setFormValue: r,
212
- promotableContentTypes: o,
213
- errors: i,
214
- isReadOnly: d
215
- }) => {
216
- const { formatMessage: l } = b(), g = e.map(
217
- (p) => o?.find((y) => y.uid === p)
218
- ), { data: c, isLoading: s } = M(e);
219
- return s ? null : /* @__PURE__ */ u(N, { children: [
220
- /* @__PURE__ */ t(C, { variant: "delta", children: l({ id: a("settings.allowedContentTypes") }) }),
221
- /* @__PURE__ */ t(E, { marginTop: 4, width: "100%", children: /* @__PURE__ */ u(
222
- h.Root,
223
- {
224
- width: "100%",
225
- error: i.allowedContentTypes && l({ id: a(i.allowedContentTypes) }),
226
- children: [
227
- /* @__PURE__ */ t(h.Label, { children: l({ id: a("settings.allowedContentTypes.label") }) }),
228
- /* @__PURE__ */ t(
229
- Ee,
230
- {
231
- withTags: !0,
232
- name: "allowedContentTypes",
233
- value: e,
234
- onChange: (p) => {
235
- r("allowedContentTypes", p);
236
- },
237
- hasError: !!i.allowedContentTypes,
238
- disabled: d,
239
- children: o?.map((p) => /* @__PURE__ */ t(ve, { value: p.uid, children: p.schema.displayName }, p.uid))
240
- }
241
- ),
242
- /* @__PURE__ */ t(h.Error, {})
243
- ]
244
- }
245
- ) }),
246
- e?.length > 0 && /* @__PURE__ */ t(
247
- B,
248
- {
249
- label: l({
250
- id: a("settings.table.keyForEligibleContentTypes")
251
- }),
252
- contentTypes: g,
253
- setFormValue: r,
254
- errors: i,
255
- contentTypeSettings: n,
256
- isReadOnly: d
257
- }
258
- ),
259
- (c?.length ?? 0) > 0 && /* @__PURE__ */ t(
260
- B,
261
- {
262
- label: l({
263
- id: a("settings.table.keyForRelatedContentTypes")
264
- }),
265
- contentTypes: c ?? [],
266
- setFormValue: r,
267
- errors: i,
268
- contentTypeSettings: n,
269
- shouldShowRequiredBy: !0,
270
- isReadOnly: d
271
- }
272
- )
273
- ] });
274
- }, Qe = () => {
275
- const { formatMessage: e } = b();
276
- return /* @__PURE__ */ t(E, { marginTop: 4, children: /* @__PURE__ */ t(
277
- Z,
278
- {
279
- title: e({ id: a("settings.alert.comparisonDepthHigh.title") }),
280
- variant: "warning",
281
- description: e({
282
- id: a("settings.alert.comparisonDepthHigh.description")
283
- })
284
- }
285
- ) });
286
- }, Be = ({ comparisonDepth: e, setFormValue: n, errors: r, isReadOnly: o }) => {
287
- const { formatMessage: i } = b();
288
- return /* @__PURE__ */ u(N, { marginTop: 4, children: [
289
- /* @__PURE__ */ u(W, { marginBottom: 4, gap: 1, children: [
290
- /* @__PURE__ */ t(C, { variant: "delta", children: i({ id: a("settings.comparisonDepth") }) }),
291
- /* @__PURE__ */ t(Se, { label: i({ id: a("settings.comparisonDepth.tooltip") }), children: /* @__PURE__ */ t(Re, {}) })
292
- ] }),
293
- /* @__PURE__ */ t(A.Root, { gap: 4, children: /* @__PURE__ */ t(A.Item, { col: 6, alignItems: "start", children: /* @__PURE__ */ u(
294
- h.Root,
295
- {
296
- error: r.comparisonDepth && i({ id: a(r.comparisonDepth) }),
297
- width: "100%",
298
- children: [
299
- /* @__PURE__ */ t(h.Label, { children: i({ id: a("settings.comparisonDepth.label") }) }),
300
- /* @__PURE__ */ t(
301
- Ae,
302
- {
303
- value: e,
304
- onValueChange: (d) => n("comparisonDepth", d),
305
- name: "comparisonDepth",
306
- disabled: o
307
- }
308
- ),
309
- /* @__PURE__ */ t(h.Error, {})
310
- ]
311
- }
312
- ) }) }),
313
- e > 5 && /* @__PURE__ */ t(Qe, {})
314
- ] });
315
- }, Ye = ({ staleValueMessages: e }) => {
316
- const { formatMessage: n } = b();
317
- return /* @__PURE__ */ t(E, { marginBottom: 4, children: /* @__PURE__ */ u(
318
- Z,
319
- {
320
- title: n({ id: a("settings.alert.staleValuesRemoved.title") }),
321
- variant: "danger",
322
- children: [
323
- n({ id: a("settings.alert.staleValuesRemoved.description") }),
324
- e.map((r, o) => /* @__PURE__ */ u("span", { children: [
325
- /* @__PURE__ */ t("br", {}),
326
- o + 1,
327
- ".",
328
- " ",
329
- n(
330
- {
331
- id: a(r.message)
332
- },
333
- r.variables
334
- )
335
- ] }, o))
336
- ]
337
- }
338
- ) });
339
- }, $e = () => {
340
- const { post: e } = P();
341
- return H({
342
- mutationFn: async (n) => {
343
- const { data: r } = await e(
344
- `/${D}/settings/testConnection`,
345
- n
346
- );
347
- return r;
348
- }
349
- });
350
- }, Ge = "settings.form.error.badApiUrl", He = {
351
- badApiKey: "settings.form.error.badApiKey",
352
- badPermissions: "settings.form.error.badKeyPermissions"
353
- }, We = ({
354
- targetEnvApiKey: e,
355
- targetEnvApiUrl: n,
356
- setFormValue: r,
357
- errors: o,
358
- isReadOnly: i
359
- }) => {
360
- const { formatMessage: d } = b(), l = $e(), { setErrors: g } = re("TargetEnvConfigurationSection", (y) => y), c = async () => {
361
- const y = (f) => {
362
- g({
363
- ...o,
364
- targetEnvApiUrl: f.outcome === "badUrl" ? Ge : void 0,
365
- targetEnvApiKey: He[f.outcome]
366
- });
367
- };
368
- try {
369
- const f = await l.mutateAsync({
370
- targetEnvApiKey: e,
371
- targetEnvApiUrl: n
372
- });
373
- y(f);
374
- } catch {
375
- y({ outcome: "unexpected" });
376
- }
377
- }, s = l.isSuccess && l.data?.outcome === "reachable", p = l.isError || l.data?.outcome === "unexpected";
378
- return /* @__PURE__ */ u(N, { marginTop: 4, children: [
379
- /* @__PURE__ */ t(E, { marginBottom: 4, children: /* @__PURE__ */ t(C, { variant: "delta", children: d({ id: a("settings.targetEnvConfiguration") }) }) }),
380
- /* @__PURE__ */ u(A.Root, { gap: 4, children: [
381
- /* @__PURE__ */ t(A.Item, { col: 6, alignItems: "start", children: /* @__PURE__ */ u(
382
- h.Root,
383
- {
384
- error: o.targetEnvApiUrl && d({ id: a(o.targetEnvApiUrl) }),
385
- width: "100%",
386
- children: [
387
- /* @__PURE__ */ t(h.Label, { children: d({ id: a("settings.targetEnvApiUrl.label") }) }),
388
- /* @__PURE__ */ t(
389
- j,
390
- {
391
- name: "targetEnvApiUrl",
392
- value: n,
393
- onChange: r,
394
- disabled: i
395
- }
396
- ),
397
- /* @__PURE__ */ t(h.Error, {})
398
- ]
399
- }
400
- ) }),
401
- /* @__PURE__ */ t(A.Item, { col: 6, alignItems: "start", children: /* @__PURE__ */ u(
402
- h.Root,
403
- {
404
- error: o.targetEnvApiKey && d({ id: a(o.targetEnvApiKey) }),
405
- width: "100%",
406
- children: [
407
- /* @__PURE__ */ t(h.Label, { children: d({ id: a("settings.targetEnvApiKey.label") }) }),
408
- /* @__PURE__ */ t(
409
- j,
410
- {
411
- name: "targetEnvApiKey",
412
- value: e,
413
- onChange: r,
414
- disabled: i
415
- }
416
- ),
417
- /* @__PURE__ */ t(h.Error, {})
418
- ]
419
- }
420
- ) }),
421
- /* @__PURE__ */ u(A.Item, { col: 6, children: [
422
- i ? null : /* @__PURE__ */ t(z, { onClick: c, disabled: l.isPending, children: d({ id: a("settings.form.testConnection") }) }),
423
- /* @__PURE__ */ u(W, { marginLeft: 1, alignItems: "center", gap: 2, children: [
424
- l.isPending && /* @__PURE__ */ t(we, { small: !0 }),
425
- s && /* @__PURE__ */ t(X, { color: "#5cb176" }),
426
- p && /* @__PURE__ */ t(C, { variant: "pi", textColor: "danger600", children: d({ id: a("settings.form.error.connectionFailed") }) })
427
- ] })
428
- ] })
429
- ] })
430
- ] });
431
- }, ze = ({
432
- values: e,
433
- onChange: n,
434
- errors: r,
435
- setErrors: o,
436
- modified: i,
437
- settings: d,
438
- promotableContentTypes: l,
439
- staleValuesMessages: g,
440
- isReadOnly: c
441
- }) => {
442
- const { formatMessage: s } = b(), { toggleNotification: p } = se(), y = Le(), { data: f = [], isFetching: F } = M(e.allowedContentTypes), k = async () => {
443
- try {
444
- const v = f.map((S) => S.uid), R = Ne(v, e), T = qe(d, R);
445
- await y.mutateAsync(T, {
446
- onSuccess: () => {
447
- o({}), p({
448
- type: "success",
449
- message: s({ id: a("settings.form.savedSuccessfully") })
450
- });
451
- }
452
- });
453
- } catch (v) {
454
- if (v instanceof me.ZodError) {
455
- const R = v.issues.reduce((T, S) => (T[S.path.join(".")] = S.message, T), {});
456
- o(R), p({
457
- type: "warning",
458
- message: s({ id: a("settings.form.error.validationMessage") })
459
- });
460
- } else
461
- p({
462
- type: "warning",
463
- message: s({ id: a("settings.form.error.other") })
464
- });
465
- }
466
- }, I = c || !i && g.length === 0 || F || y.isPending;
467
- return /* @__PURE__ */ u($, { children: [
468
- /* @__PURE__ */ t(
469
- x.Header,
470
- {
471
- title: s({ id: a("settings.title") }),
472
- subtitle: s({ id: a("settings.subtitle") }),
473
- primaryAction: c ? null : /* @__PURE__ */ t(
474
- z,
475
- {
476
- type: "submit",
477
- startIcon: /* @__PURE__ */ t(X, {}),
478
- onClick: k,
479
- disabled: I,
480
- children: s({
481
- id: a("settings.form.submit")
482
- })
483
- }
484
- )
485
- }
486
- ),
487
- /* @__PURE__ */ u(x.Content, { children: [
488
- g.length > 0 && /* @__PURE__ */ t(Ye, { staleValueMessages: g }),
489
- /* @__PURE__ */ t(
490
- je,
491
- {
492
- allowedContentTypes: e.allowedContentTypes,
493
- contentTypeSettings: e.contentTypeSettings,
494
- setFormValue: n,
495
- promotableContentTypes: l,
496
- errors: r,
497
- isReadOnly: c
498
- }
499
- ),
500
- /* @__PURE__ */ t(
501
- Be,
502
- {
503
- setFormValue: n,
504
- errors: r,
505
- comparisonDepth: e.comparisonDepth,
506
- isReadOnly: c
507
- }
508
- ),
509
- /* @__PURE__ */ t(
510
- We,
511
- {
512
- targetEnvApiKey: e.targetEnvApiKey,
513
- targetEnvApiUrl: e.targetEnvApiUrl,
514
- setFormValue: n,
515
- errors: r,
516
- isReadOnly: c
517
- }
518
- )
519
- ] })
520
- ] });
521
- }, Y = (e) => {
522
- const n = e.contentTypes ?? [], r = n.filter((i) => i.kind === w.enum.Promotable).map((i) => i.uid), o = Object.fromEntries(
523
- n.map((i) => [i.uid, { key: i.key }])
524
- );
525
- return {
526
- allowedContentTypes: r,
527
- contentTypeSettings: o,
528
- targetEnvApiKey: e?.targetEnvApiKey ?? "",
529
- targetEnvApiUrl: e?.targetEnvApiUrl ?? "",
530
- comparisonDepth: e?.comparisonDepth ?? De
531
- };
532
- }, Xe = (e, n, r) => {
533
- if (!e.contentTypes)
534
- return [Y(e), []];
535
- const o = [], i = e.contentTypes.map((s) => ({
536
- ...s,
537
- uid: ee(s.uid)
538
- })), d = n.map((s) => s.uid), g = i.filter(
539
- (s) => {
540
- const p = !d.includes(s.uid);
541
- return p && o.push({
542
- message: "settings.alert.staleValuesRemoved.contentTypeDeleted",
543
- variables: { uid: V(s.uid) }
544
- }), !p;
545
- }
546
- ).filter((s) => {
547
- const p = !r.includes(s.uid) && s.kind === w.enum.Related;
548
- return p && o.push({
549
- message: "settings.alert.staleValuesRemoved.relationDeleted",
550
- variables: { uid: V(s.uid) }
551
- }), !p;
552
- }).map((s) => {
553
- const p = n.find(
554
- (F) => F.uid === s.uid
555
- ), y = p?.schema.attributes[s.key], f = y?.type === "uid" || y?.unique === !0;
556
- return f || o.push({
557
- message: "settings.alert.staleValuesRemoved.keyDeleted",
558
- variables: {
559
- key: s.key,
560
- schemaDisplayName: p?.schema.displayName
561
- }
562
- }), {
563
- ...s,
564
- key: f ? s.key : void 0
565
- };
566
- });
567
- return [Y({
568
- ...e,
569
- contentTypes: g
570
- }), o];
571
- }, Ze = () => {
572
- const { formatMessage: e } = b(), n = pe(null), {
573
- isLoading: r,
574
- allowedActions: { canUpdate: o }
575
- } = oe([...G.settingsUpdate]), { data: i, isLoading: d } = Fe(), { data: l, isLoading: g } = Ke(), c = ue(
576
- () => (i?.contentTypes ?? []).filter((T) => T.kind === w.enum.Promotable).map((T) => ee(T.uid)),
577
- [i?.contentTypes]
578
- ), {
579
- data: s = [],
580
- isLoading: p,
581
- isFetched: y
582
- } = M(c), f = c.length === 0 || y;
583
- if (r || d || g || p || !f || !i || !l)
584
- return /* @__PURE__ */ t(U.Loading, {});
585
- const { promotableContentTypes: k, relationLookupContentTypes: I } = l, [v, R] = Xe(
586
- i,
587
- I,
588
- s.map((T) => T.uid)
589
- );
590
- return /* @__PURE__ */ u(U.Main, { children: [
591
- /* @__PURE__ */ t(U.Title, { children: e({ id: a("settings.metadata.title") }) }),
592
- /* @__PURE__ */ t(ae, { width: "100%", height: "100%", ref: n, method: "PUT", initialValues: v, children: ({ values: T, onChange: S, errors: te, setErrors: ne, modified: ie }) => /* @__PURE__ */ t(
593
- ze,
594
- {
595
- values: T,
596
- onChange: S,
597
- errors: te,
598
- setErrors: ne,
599
- modified: ie,
600
- settings: i,
601
- promotableContentTypes: k,
602
- staleValuesMessages: R,
603
- isReadOnly: !o
604
- }
605
- ) })
606
- ] });
607
- }, pt = () => /* @__PURE__ */ t(U.Protect, { permissions: [...G.settingsRead], children: /* @__PURE__ */ t(de, { children: /* @__PURE__ */ t(Ze, {}) }) });
608
- export {
609
- pt as default
610
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("@strapi/strapi/admin"),o=require("./index-BNa83Wfu.js"),b=require("./queryKeys-B_GC_f73.js"),I=require("react"),j=require("react-intl"),p=require("zod"),E=require("@tanstack/react-query"),n=require("@strapi/design-system"),q=require("@strapi/icons"),z=require("lodash"),F=require("./TruncatedTypography-72wp11m4.js"),O=t=>t&&t.__esModule?t:{default:t},B=O(p),Q=3,v=p.z.enum(["Related","Promotable"]);p.z.object({targetEnvApiKey:p.z.string().optional(),targetEnvApiUrl:p.z.url().optional(),comparisonDepth:p.z.number().positive().optional(),contentTypes:p.z.array(p.z.object({uid:p.z.string(),key:p.z.string(),kind:v})).optional()});const Y=()=>{const{get:t}=h.useFetchClient();return E.useQuery({queryKey:[b.SETTINGS_QUERY_KEY],queryFn:async()=>{const{data:s}=await t(`/${o.URL_PREFIX}/settings`);return s}})},G=[b.SETTINGS_QUERY_KEY,"content-type-options"],H=()=>{const{get:t}=h.useFetchClient();return E.useQuery({queryKey:G,queryFn:async()=>{const{data:s}=await t(`/${o.URL_PREFIX}/settings/content-type-options`);return s}})},W=t=>[b.SETTINGS_QUERY_KEY,"related-content-types",t],X=(t,s)=>E.queryOptions({queryKey:W(s),queryFn:async()=>{const{data:r}=await t(`/${o.URL_PREFIX}/settings/related-content-types`,{params:{allowed:s.join(",")}});return r}}),U=t=>{const{get:s}=h.useFetchClient();return E.useQuery({...X(s,t),enabled:t.length>0})},$=()=>{const{put:t}=h.useFetchClient(),s=E.useQueryClient();return E.useMutation({mutationFn:async r=>t(`/${o.URL_PREFIX}/settings`,r),onSuccess:async()=>{await Promise.all([s.invalidateQueries({queryKey:[b.SETTINGS_QUERY_KEY]}),s.invalidateQueries({queryKey:[b.PROMOTABLE_CONTENT_TYPES_QUERY_KEY]})])}})},Z=(t,s)=>Object.entries(s).reduce((r,[l,i])=>z.isEqual(i,t[l])?r:{...r,[l]:i},{}),L=p.z.object({allowedContentTypes:p.z.array(p.z.string()).min(1,{message:"settings.form.error.minimalArrayLength"}),contentTypeSettings:p.z.record(p.z.string(),p.z.object({key:p.z.string({message:"settings.form.error.required"}).min(1,{message:"settings.form.error.required"}).optional()}).optional()),targetEnvApiKey:p.z.string({message:"settings.form.error.required"}).min(1,{message:"settings.form.error.required"}),targetEnvApiUrl:p.z.url({message:"settings.form.error.validURL"}),comparisonDepth:p.z.number({message:"settings.form.error.required"}).positive({message:"settings.form.error.positive"})}),J=L.extend({relatedContentTypes:p.z.string().array()}),ee=J.refine(t=>[...t.allowedContentTypes,...t.relatedContentTypes].every(r=>!!t.contentTypeSettings[r]?.key),{path:["allowedContentTypes"],message:"settings.form.error.uniqueKeyRequired",when(t){return L.pick({contentTypeSettings:!0}).safeParse(t.value).success}}),te=(t,s)=>{const r=[...t.allowedContentTypes,...s];return{...t,contentTypeSettings:Object.fromEntries(r.map(l=>[l,t.contentTypeSettings[l]]))}},k=t=>t.replace(".",":"),P=t=>t.replace(/:(?!.*:)/,"."),ne=(t,s)=>{const l={...te(s,t),relatedContentTypes:t},i=ee.parse(l);return{contentTypes:[...i.allowedContentTypes,...i.relatedContentTypes].map(d=>({uid:P(d),key:i.contentTypeSettings[d]?.key,kind:i.allowedContentTypes.includes(d)?v.enum.Promotable:v.enum.Related})),targetEnvApiKey:i.targetEnvApiKey,targetEnvApiUrl:i.targetEnvApiUrl,comparisonDepth:i.comparisonDepth}},se={background:"neutral0",hasRadius:!0,shadow:"filterShadow",padding:6,width:"100%"},_=({children:t,marginTop:s})=>e.jsx(n.Box,{...se,marginTop:s,children:t}),ie=({onChange:t,attributes:s,value:r,name:l,error:i,disabled:c=!1})=>{const{formatMessage:d}=j.useIntl(),m=Object.entries(s).filter(([u,a])=>a.type==="uid"||a.unique===!0);return I.useEffect(()=>{!r&&m.length>0&&t("")},[]),e.jsx(e.Fragment,{children:m.length>0?e.jsxs(n.Field.Root,{error:i&&d({id:o.getTranslation(i)}),children:[e.jsx(n.SingleSelect,{name:l,value:r,onChange:t,required:!0,disabled:c,children:m.map(([u,a])=>e.jsx(n.SingleSelectOption,{value:u,children:u},u))}),e.jsx(n.Field.Error,{})]}):e.jsx(n.Field.Root,{error:d({id:o.getTranslation("settings.table.uniqueKeyRequiredWarning")}),children:e.jsx(n.Field.Error,{})})})},K=({label:t,contentTypes:s,setFormValue:r,errors:l,contentTypeSettings:i,shouldShowRequiredBy:c,isReadOnly:d})=>{const{formatMessage:m}=j.useIntl();return e.jsxs(n.Box,{marginTop:4,width:"100%",paddingTop:4,children:[e.jsx(n.Box,{marginBottom:1,children:e.jsx(n.Typography,{variant:"pi",textColor:"neutral800",fontWeight:"bold",children:t})}),e.jsxs(n.Table,{width:"100%",rowCount:s.length,colCount:c?3:2,children:[e.jsx(n.Thead,{children:e.jsxs(n.Tr,{children:[e.jsx(n.Th,{children:e.jsx(n.Typography,{variant:"sigma",children:m({id:o.getTranslation("settings.table.contentType")})})}),c&&e.jsx(n.Th,{children:e.jsx(n.Typography,{variant:"sigma",children:m({id:o.getTranslation("settings.table.requiredBy")})})}),e.jsx(n.Th,{children:e.jsx(n.Typography,{variant:"sigma",children:m({id:o.getTranslation("settings.table.uniqueKey")})})})]})}),e.jsx(n.Tbody,{children:s.map(u=>{const a=`contentTypeSettings.${u.uid}.key`;return e.jsxs(n.Tr,{children:[e.jsx(n.Td,{width:c?"25%":"50%",children:e.jsx(F.TruncatedTypography,{maxCharacters:55,text:u.schema.displayName,textColor:"neutral800"})}),c&&e.jsx(n.Td,{width:"25%",children:e.jsx(F.TruncatedTypography,{maxCharacters:55,text:u.requiredBy,textColor:"neutral800"})}),e.jsx(n.Td,{width:"50%",children:e.jsx(ie,{onChange:g=>{r(a,g)},value:i[u.uid]?.key,attributes:u.schema.attributes,name:a,error:l[a],disabled:d})})]},u.uid)})})]})]})},re=({allowedContentTypes:t,contentTypeSettings:s,setFormValue:r,promotableContentTypes:l,errors:i,isReadOnly:c})=>{const{formatMessage:d}=j.useIntl(),m=t.map(g=>l?.find(y=>y.uid===g)),{data:u,isLoading:a}=U(t);return a?null:e.jsxs(_,{children:[e.jsx(n.Typography,{variant:"delta",children:d({id:o.getTranslation("settings.allowedContentTypes")})}),e.jsx(n.Box,{marginTop:4,width:"100%",children:e.jsxs(n.Field.Root,{width:"100%",error:i.allowedContentTypes&&d({id:o.getTranslation(i.allowedContentTypes)}),children:[e.jsx(n.Field.Label,{children:d({id:o.getTranslation("settings.allowedContentTypes.label")})}),e.jsx(n.MultiSelect,{withTags:!0,name:"allowedContentTypes",value:t,onChange:g=>{r("allowedContentTypes",g)},hasError:!!i.allowedContentTypes,disabled:c,children:l?.map(g=>e.jsx(n.MultiSelectOption,{value:g.uid,children:g.schema.displayName},g.uid))}),e.jsx(n.Field.Error,{})]})}),t?.length>0&&e.jsx(K,{label:d({id:o.getTranslation("settings.table.keyForEligibleContentTypes")}),contentTypes:m,setFormValue:r,errors:i,contentTypeSettings:s,isReadOnly:c}),(u?.length??0)>0&&e.jsx(K,{label:d({id:o.getTranslation("settings.table.keyForRelatedContentTypes")}),contentTypes:u??[],setFormValue:r,errors:i,contentTypeSettings:s,shouldShowRequiredBy:!0,isReadOnly:c})]})},oe=()=>{const{formatMessage:t}=j.useIntl();return e.jsx(n.Box,{marginTop:4,children:e.jsx(F.Alert,{title:t({id:o.getTranslation("settings.alert.comparisonDepthHigh.title")}),variant:"warning",description:t({id:o.getTranslation("settings.alert.comparisonDepthHigh.description")})})})},ae=({comparisonDepth:t,setFormValue:s,errors:r,isReadOnly:l})=>{const{formatMessage:i}=j.useIntl();return e.jsxs(_,{marginTop:4,children:[e.jsxs(n.Flex,{marginBottom:4,gap:1,children:[e.jsx(n.Typography,{variant:"delta",children:i({id:o.getTranslation("settings.comparisonDepth")})}),e.jsx(n.Tooltip,{label:i({id:o.getTranslation("settings.comparisonDepth.tooltip")}),children:e.jsx(q.Information,{})})]}),e.jsx(n.Grid.Root,{gap:4,children:e.jsx(n.Grid.Item,{col:6,alignItems:"start",children:e.jsxs(n.Field.Root,{error:r.comparisonDepth&&i({id:o.getTranslation(r.comparisonDepth)}),width:"100%",children:[e.jsx(n.Field.Label,{children:i({id:o.getTranslation("settings.comparisonDepth.label")})}),e.jsx(n.NumberInput,{value:t,onValueChange:c=>s("comparisonDepth",c),name:"comparisonDepth",disabled:l}),e.jsx(n.Field.Error,{})]})})}),t>5&&e.jsx(oe,{})]})},le=({staleValueMessages:t})=>{const{formatMessage:s}=j.useIntl();return e.jsx(n.Box,{marginBottom:4,children:e.jsxs(F.Alert,{title:s({id:o.getTranslation("settings.alert.staleValuesRemoved.title")}),variant:"danger",children:[s({id:o.getTranslation("settings.alert.staleValuesRemoved.description")}),t.map((r,l)=>e.jsxs("span",{children:[e.jsx("br",{}),l+1,"."," ",s({id:o.getTranslation(r.message)},r.variables)]},l))]})})},de=()=>{const{post:t}=h.useFetchClient();return E.useMutation({mutationFn:async s=>{const{data:r}=await t(`/${o.URL_PREFIX}/settings/testConnection`,s);return r}})},ce="settings.form.error.badApiUrl",ue={badApiKey:"settings.form.error.badApiKey",badPermissions:"settings.form.error.badKeyPermissions"},ge=({targetEnvApiKey:t,targetEnvApiUrl:s,setFormValue:r,errors:l,isReadOnly:i})=>{const{formatMessage:c}=j.useIntl(),d=de(),{setErrors:m}=h.useForm("TargetEnvConfigurationSection",y=>y),u=async()=>{const y=x=>{m({...l,targetEnvApiUrl:x.outcome==="badUrl"?ce:void 0,targetEnvApiKey:ue[x.outcome]})};try{const x=await d.mutateAsync({targetEnvApiKey:t,targetEnvApiUrl:s});y(x)}catch{y({outcome:"unexpected"})}},a=d.isSuccess&&d.data?.outcome==="reachable",g=d.isError||d.data?.outcome==="unexpected";return e.jsxs(_,{marginTop:4,children:[e.jsx(n.Box,{marginBottom:4,children:e.jsx(n.Typography,{variant:"delta",children:c({id:o.getTranslation("settings.targetEnvConfiguration")})})}),e.jsxs(n.Grid.Root,{gap:4,children:[e.jsx(n.Grid.Item,{col:6,alignItems:"start",children:e.jsxs(n.Field.Root,{error:l.targetEnvApiUrl&&c({id:o.getTranslation(l.targetEnvApiUrl)}),width:"100%",children:[e.jsx(n.Field.Label,{children:c({id:o.getTranslation("settings.targetEnvApiUrl.label")})}),e.jsx(n.TextInput,{name:"targetEnvApiUrl",value:s,onChange:r,disabled:i}),e.jsx(n.Field.Error,{})]})}),e.jsx(n.Grid.Item,{col:6,alignItems:"start",children:e.jsxs(n.Field.Root,{error:l.targetEnvApiKey&&c({id:o.getTranslation(l.targetEnvApiKey)}),width:"100%",children:[e.jsx(n.Field.Label,{children:c({id:o.getTranslation("settings.targetEnvApiKey.label")})}),e.jsx(n.TextInput,{name:"targetEnvApiKey",value:t,onChange:r,disabled:i}),e.jsx(n.Field.Error,{})]})}),e.jsxs(n.Grid.Item,{col:6,children:[i?null:e.jsx(n.Button,{onClick:u,disabled:d.isPending,children:c({id:o.getTranslation("settings.form.testConnection")})}),e.jsxs(n.Flex,{marginLeft:1,alignItems:"center",gap:2,children:[d.isPending&&e.jsx(n.Loader,{small:!0}),a&&e.jsx(q.Check,{color:"#5cb176"}),g&&e.jsx(n.Typography,{variant:"pi",textColor:"danger600",children:c({id:o.getTranslation("settings.form.error.connectionFailed")})})]})]})]})]})},pe=({values:t,onChange:s,errors:r,setErrors:l,modified:i,settings:c,promotableContentTypes:d,staleValuesMessages:m,isReadOnly:u})=>{const{formatMessage:a}=j.useIntl(),{toggleNotification:g}=h.useNotification(),y=$(),{data:x=[],isFetching:R}=U(t.allowedContentTypes),A=async()=>{try{const f=x.map(C=>C.uid),S=ne(f,t),T=Z(c,S);await y.mutateAsync(T,{onSuccess:()=>{l({}),g({type:"success",message:a({id:o.getTranslation("settings.form.savedSuccessfully")})})}})}catch(f){if(f instanceof B.default.ZodError){const S=f.issues.reduce((T,C)=>(T[C.path.join(".")]=C.message,T),{});l(S),g({type:"warning",message:a({id:o.getTranslation("settings.form.error.validationMessage")})})}else g({type:"warning",message:a({id:o.getTranslation("settings.form.error.other")})})}},w=u||!i&&m.length===0||R||y.isPending;return e.jsxs(e.Fragment,{children:[e.jsx(h.Layouts.Header,{title:a({id:o.getTranslation("settings.title")}),subtitle:a({id:o.getTranslation("settings.subtitle")}),primaryAction:u?null:e.jsx(n.Button,{type:"submit",startIcon:e.jsx(q.Check,{}),onClick:A,disabled:w,children:a({id:o.getTranslation("settings.form.submit")})})}),e.jsxs(h.Layouts.Content,{children:[m.length>0&&e.jsx(le,{staleValueMessages:m}),e.jsx(re,{allowedContentTypes:t.allowedContentTypes,contentTypeSettings:t.contentTypeSettings,setFormValue:s,promotableContentTypes:d,errors:r,isReadOnly:u}),e.jsx(ae,{setFormValue:s,errors:r,comparisonDepth:t.comparisonDepth,isReadOnly:u}),e.jsx(ge,{targetEnvApiKey:t.targetEnvApiKey,targetEnvApiUrl:t.targetEnvApiUrl,setFormValue:s,errors:r,isReadOnly:u})]})]})},D=t=>{const s=t.contentTypes??[],r=s.filter(i=>i.kind===v.enum.Promotable).map(i=>i.uid),l=Object.fromEntries(s.map(i=>[i.uid,{key:i.key}]));return{allowedContentTypes:r,contentTypeSettings:l,targetEnvApiKey:t?.targetEnvApiKey??"",targetEnvApiUrl:t?.targetEnvApiUrl??"",comparisonDepth:t?.comparisonDepth??Q}},me=(t,s,r)=>{if(!t.contentTypes)return[D(t),[]];const l=[],i=t.contentTypes.map(a=>({...a,uid:k(a.uid)})),c=s.map(a=>a.uid),m=i.filter(a=>{const g=!c.includes(a.uid);return g&&l.push({message:"settings.alert.staleValuesRemoved.contentTypeDeleted",variables:{uid:P(a.uid)}}),!g}).filter(a=>{const g=!r.includes(a.uid)&&a.kind===v.enum.Related;return g&&l.push({message:"settings.alert.staleValuesRemoved.relationDeleted",variables:{uid:P(a.uid)}}),!g}).map(a=>{const g=s.find(R=>R.uid===a.uid),y=g?.schema.attributes[a.key],x=y?.type==="uid"||y?.unique===!0;return x||l.push({message:"settings.alert.staleValuesRemoved.keyDeleted",variables:{key:a.key,schemaDisplayName:g?.schema.displayName}}),{...a,key:x?a.key:void 0}});return[D({...t,contentTypes:m}),l]},he=()=>{const{formatMessage:t}=j.useIntl(),s=I.useRef(null),{isLoading:r,allowedActions:{canUpdate:l}}=h.useRBAC([...o.PERMISSIONS.settingsUpdate]),{data:i,isLoading:c}=Y(),{data:d,isLoading:m}=H(),u=I.useMemo(()=>(i?.contentTypes??[]).filter(T=>T.kind===v.enum.Promotable).map(T=>k(T.uid)),[i?.contentTypes]),{data:a=[],isLoading:g,isFetched:y}=U(u),x=u.length===0||y;if(r||c||m||g||!x||!i||!d)return e.jsx(h.Page.Loading,{});const{promotableContentTypes:A,relationLookupContentTypes:w}=d,[f,S]=me(i,w,a.map(T=>T.uid));return e.jsxs(h.Page.Main,{children:[e.jsx(h.Page.Title,{children:t({id:o.getTranslation("settings.metadata.title")})}),e.jsx(h.Form,{width:"100%",height:"100%",ref:s,method:"PUT",initialValues:f,children:({values:T,onChange:C,errors:M,setErrors:N,modified:V})=>e.jsx(pe,{values:T,onChange:C,errors:M,setErrors:N,modified:V,settings:i,promotableContentTypes:A,staleValuesMessages:S,isReadOnly:!l})})]})},ye=()=>e.jsx(h.Page.Protect,{permissions:[...o.PERMISSIONS.settingsRead],children:e.jsx(b.QueryProvider,{children:e.jsx(he,{})})});exports.default=ye;