strapi-cache 1.4.2-rc.2 → 1.4.3

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 (42) hide show
  1. package/README.md +3 -2
  2. package/dist/_chunks/en-B9bQFCLY.mjs +18 -0
  3. package/dist/_chunks/en-B9bQFCLY.mjs.map +1 -0
  4. package/dist/_chunks/en-BkqNXvi0.mjs +18 -0
  5. package/dist/_chunks/en-BkqNXvi0.mjs.map +1 -0
  6. package/dist/_chunks/en-CBPjpI-y.js +18 -0
  7. package/dist/_chunks/en-CBPjpI-y.js.map +1 -0
  8. package/dist/_chunks/en-CWf_jLFj.js +18 -0
  9. package/dist/_chunks/en-CWf_jLFj.js.map +1 -0
  10. package/dist/_chunks/en-CcRrGOBv.js +15 -0
  11. package/dist/_chunks/en-CcRrGOBv.js.map +1 -0
  12. package/dist/_chunks/en-Cq54r800.mjs +18 -0
  13. package/dist/_chunks/en-Cq54r800.mjs.map +1 -0
  14. package/dist/_chunks/en-D3udXrSa.mjs +15 -0
  15. package/dist/_chunks/en-D3udXrSa.mjs.map +1 -0
  16. package/dist/_chunks/en-DehLWejq.mjs +18 -0
  17. package/dist/_chunks/en-DehLWejq.mjs.map +1 -0
  18. package/dist/_chunks/en-Do3Kh30d.js +18 -0
  19. package/dist/_chunks/en-Do3Kh30d.js.map +1 -0
  20. package/dist/_chunks/en-N9VY0B4k.mjs +18 -0
  21. package/dist/_chunks/en-N9VY0B4k.mjs.map +1 -0
  22. package/dist/_chunks/en-O03hkb40.js +18 -0
  23. package/dist/_chunks/en-O03hkb40.js.map +1 -0
  24. package/dist/_chunks/en-TyY2Xkua.js +18 -0
  25. package/dist/_chunks/en-TyY2Xkua.js.map +1 -0
  26. package/dist/_chunks/en-eba6oPnU.mjs +18 -0
  27. package/dist/_chunks/en-eba6oPnU.mjs.map +1 -0
  28. package/dist/_chunks/en-wt3vH-k4.js +18 -0
  29. package/dist/_chunks/en-wt3vH-k4.js.map +1 -0
  30. package/dist/admin/index.js +140 -6
  31. package/dist/admin/index.js.map +1 -1
  32. package/dist/admin/index.mjs +141 -7
  33. package/dist/admin/index.mjs.map +1 -1
  34. package/dist/admin/src/components/PurgeEntityButton/index.d.ts +2 -0
  35. package/dist/server/index.js +20 -0
  36. package/dist/server/index.js.map +1 -1
  37. package/dist/server/index.mjs +20 -0
  38. package/dist/server/index.mjs.map +1 -1
  39. package/dist/server/src/controllers/controller.d.ts +1 -0
  40. package/dist/server/src/controllers/index.d.ts +1 -0
  41. package/dist/server/src/index.d.ts +1 -0
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -58,12 +58,13 @@ In your Strapi project, navigate to `config/plugins.js` and add the following co
58
58
 
59
59
  ## 🔍 Routes
60
60
 
61
- The plugin creates two new routes
61
+ The plugin creates three new routes
62
62
 
63
63
  - `POST /strapi-cache/purge-cache` (purges the whole cache)
64
64
  - `POST /strapi-cache/purge-cache/:key` (purges cache entries with have the key in the cache key)
65
+ - `GET /strapi-cache/cacheable-routes` (returns the cacheable routes defined in the config)
65
66
 
66
- Both routes are protected by the policies `admin::isAuthenticatedAdmin` and `plugin::strapi-cache.purge-cache`. The second policy can be managed in the plugin's permissions section under the settings.
67
+ All of these routes are protected by the policies `admin::isAuthenticatedAdmin` and `plugin::strapi-cache.purge-cache`. The `plugin::strapi-cache.purge-cache` policy can be managed in the plugin's permissions section under the settings.
67
68
 
68
69
  ## 🗂️ How It Works
69
70
 
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {key} is part of the key. Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-B9bQFCLY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-B9bQFCLY.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where '{key}' is part of the key. Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-BkqNXvi0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-BkqNXvi0.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {{key}} is part of the key. Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-CBPjpI-y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-CBPjpI-y.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where '{key}' is part of the key. Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-CWf_jLFj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-CWf_jLFj.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.cache.purge": "Purge Cache",
6
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
7
+ "strapi-cache.cache.cancel": "No, cancel",
8
+ "strapi-cache.cache.confirm": "Yes, purge",
9
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {key} is part of the key. Are you sure you want to purge the cache?",
10
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
11
+ "strapi-cache.cache.purge.error": "Error purging cache",
12
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
13
+ };
14
+ exports.default = en;
15
+ //# sourceMappingURL=en-CcRrGOBv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-CcRrGOBv.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {{key}} is part of the key. Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-Cq54r800.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-Cq54r800.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.cache.purge": "Purge Cache",
4
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
5
+ "strapi-cache.cache.cancel": "No, cancel",
6
+ "strapi-cache.cache.confirm": "Yes, purge",
7
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {key} is part of the key. Are you sure you want to purge the cache?",
8
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
9
+ "strapi-cache.cache.purge.error": "Error purging cache",
10
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
11
+ };
12
+ export {
13
+ en as default
14
+ };
15
+ //# sourceMappingURL=en-D3udXrSa.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-D3udXrSa.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-DehLWejq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-DehLWejq.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-Do3Kh30d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-Do3Kh30d.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {'key'} is part of the key. Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-N9VY0B4k.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-N9VY0B4k.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-O03hkb40.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-O03hkb40.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {key} is part of the key. Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-TyY2Xkua.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-TyY2Xkua.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ const en = {
2
+ "strapi-cache.name": "Strapi Cache",
3
+ "strapi-cache.settings": "Cache Settings",
4
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
5
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
6
+ "strapi-cache.cache.purge": "Purge Cache",
7
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
8
+ "strapi-cache.cache.cancel": "No, cancel",
9
+ "strapi-cache.cache.confirm": "Yes, purge",
10
+ "strapi-cache.cache.purge.confirmation": "Are you sure you want to purge the cache?",
11
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
12
+ "strapi-cache.cache.purge.error": "Error purging cache",
13
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
14
+ };
15
+ export {
16
+ en as default
17
+ };
18
+ //# sourceMappingURL=en-eba6oPnU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-eba6oPnU.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const en = {
4
+ "strapi-cache.name": "Strapi Cache",
5
+ "strapi-cache.settings": "Cache Settings",
6
+ "strapi-cache.view.settings.title": "Strapi Cache Settings",
7
+ "strapi-cache.view.settings.subtitle": "Configure what to cache",
8
+ "strapi-cache.cache.purge": "Purge Cache",
9
+ "strapi-cache.cache.purge.entity": "Purge Entity Cache",
10
+ "strapi-cache.cache.cancel": "No, cancel",
11
+ "strapi-cache.cache.confirm": "Yes, purge",
12
+ "strapi-cache.cache.purge.confirmation": "This purges all keys where {'key'} is part of the key. Are you sure you want to purge the cache?",
13
+ "strapi-cache.cache.purge.success": "Cache purged successfully",
14
+ "strapi-cache.cache.purge.error": "Error purging cache",
15
+ "strapi-cache.cache.purge.no-content-type": "No content type found"
16
+ };
17
+ exports.default = en;
18
+ //# sourceMappingURL=en-wt3vH-k4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en-wt3vH-k4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
@@ -35,10 +35,28 @@ const pluginPermissions = {
35
35
  function PurgeCacheButton() {
36
36
  const { allowedActions } = admin.useRBAC(pluginPermissions);
37
37
  const formatMessage = reactIntl.useIntl().formatMessage;
38
- const { post } = admin.useFetchClient();
38
+ const { post, get } = admin.useFetchClient();
39
39
  const { toggleNotification } = admin.useNotification();
40
40
  const { contentType } = admin.unstable_useContentManagerContext();
41
+ const [cacheableRoutes, setCacheableRoutes] = react.useState();
41
42
  const pluralName = contentType?.info.pluralName;
43
+ react.useEffect(() => {
44
+ if (!allowedActions.canPurgeCache) {
45
+ return;
46
+ }
47
+ const fetchCacheableRoutes = async () => {
48
+ try {
49
+ const { data } = await get("/strapi-cache/cacheable-routes");
50
+ return data;
51
+ } catch (error) {
52
+ console.error("Error fetching cacheable routes:", error);
53
+ return void 0;
54
+ }
55
+ };
56
+ fetchCacheableRoutes().then((data) => {
57
+ setCacheableRoutes(data);
58
+ });
59
+ }, [allowedActions.canPurgeCache]);
42
60
  const clearCache = () => {
43
61
  if (!pluralName) {
44
62
  toggleNotification({
@@ -72,7 +90,15 @@ function PurgeCacheButton() {
72
90
  });
73
91
  });
74
92
  };
75
- if (!allowedActions.canPurgeCache) {
93
+ const isCacheableRoute = () => {
94
+ if (!pluralName || !cacheableRoutes) {
95
+ return false;
96
+ }
97
+ return cacheableRoutes.length === 0 || cacheableRoutes.some((route) => {
98
+ return route.includes(pluralName);
99
+ });
100
+ };
101
+ if (!allowedActions.canPurgeCache || !isCacheableRoute()) {
76
102
  return null;
77
103
  }
78
104
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Root, { children: [
@@ -85,10 +111,114 @@ function PurgeCacheButton() {
85
111
  id: "strapi-cache.cache.purge",
86
112
  defaultMessage: "Purge Cache"
87
113
  }) }) }),
88
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: formatMessage({
89
- id: "strapi-cache.cache.purge.confirmation",
90
- defaultMessage: "Are you sure you want to purge the cache?"
114
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: formatMessage(
115
+ {
116
+ id: "strapi-cache.cache.purge.confirmation",
117
+ defaultMessage: "Are you sure you want to purge the cache?"
118
+ },
119
+ {
120
+ key: `"${pluralName}"`
121
+ }
122
+ ) }) }),
123
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
124
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({
125
+ id: "strapi-cache.cache.cancel",
126
+ defaultMessage: "No, cancel"
127
+ }) }) }),
128
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: clearCache, children: formatMessage({
129
+ id: "strapi-cache.cache.confirm",
130
+ defaultMessage: "Yes, confirm"
131
+ }) }) })
132
+ ] })
133
+ ] })
134
+ ] }) });
135
+ }
136
+ function PurgeEntityButton() {
137
+ const { allowedActions } = admin.useRBAC(pluginPermissions);
138
+ const formatMessage = reactIntl.useIntl().formatMessage;
139
+ const { post, get } = admin.useFetchClient();
140
+ const { toggleNotification } = admin.useNotification();
141
+ const { contentType, id } = admin.unstable_useContentManagerContext();
142
+ const [cacheableRoutes, setCacheableRoutes] = react.useState();
143
+ const pluralName = contentType?.info.pluralName;
144
+ react.useEffect(() => {
145
+ if (!allowedActions.canPurgeCache) {
146
+ return;
147
+ }
148
+ const fetchCacheableRoutes = async () => {
149
+ try {
150
+ const { data } = await get("/strapi-cache/cacheable-routes");
151
+ return data;
152
+ } catch (error) {
153
+ console.error("Error fetching cacheable routes:", error);
154
+ return void 0;
155
+ }
156
+ };
157
+ fetchCacheableRoutes().then((data) => {
158
+ setCacheableRoutes(data);
159
+ });
160
+ }, [allowedActions.canPurgeCache]);
161
+ const clearCache = () => {
162
+ if (!pluralName) {
163
+ toggleNotification({
164
+ type: "warning",
165
+ message: formatMessage({
166
+ id: "strapi-cache.cache.purge.no-content-type",
167
+ defaultMessage: "No content type found"
168
+ })
169
+ });
170
+ return;
171
+ }
172
+ post(`/strapi-cache/purge-cache/${id}`, void 0, {
173
+ headers: {
174
+ "Content-Type": "application/json"
175
+ }
176
+ }).then(() => {
177
+ toggleNotification({
178
+ type: "success",
179
+ message: formatMessage({
180
+ id: "strapi-cache.cache.purge.success",
181
+ defaultMessage: "Cache purged successfully"
182
+ }) + `: ${pluralName}`
183
+ });
184
+ }).catch(() => {
185
+ toggleNotification({
186
+ type: "danger",
187
+ message: formatMessage({
188
+ id: "strapi-cache.cache.purge.error",
189
+ defaultMessage: "Error purging cache"
190
+ }) + `: ${pluralName}`
191
+ });
192
+ });
193
+ };
194
+ const isCacheableRoute = () => {
195
+ if (!pluralName || !cacheableRoutes) {
196
+ return false;
197
+ }
198
+ return cacheableRoutes.length === 0 || cacheableRoutes.some((route) => {
199
+ return route.includes(pluralName);
200
+ });
201
+ };
202
+ if (!allowedActions.canPurgeCache || !isCacheableRoute()) {
203
+ return null;
204
+ }
205
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Root, { children: [
206
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { width: "100%", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Archive, {}), variant: "danger", children: formatMessage({
207
+ id: "strapi-cache.cache.purge.entity",
208
+ defaultMessage: "Purge Entity Cache"
209
+ }) }) }),
210
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
211
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: formatMessage({
212
+ id: "strapi-cache.cache.purge.entity",
213
+ defaultMessage: "Purge Entity Cache"
91
214
  }) }) }),
215
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: formatMessage(
216
+ {
217
+ id: "strapi-cache.cache.purge.confirmation",
218
+ defaultMessage: "Are you sure you want to purge the cache?"
219
+ },
220
+ { key: `"${id}"` }
221
+ ) }) }),
92
222
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
93
223
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({
94
224
  id: "strapi-cache.cache.cancel",
@@ -114,12 +244,16 @@ const index = {
114
244
  name: PurgeCacheButton,
115
245
  Component: PurgeCacheButton
116
246
  });
247
+ app.getPlugin("content-manager").injectComponent("editView", "right-links", {
248
+ name: PurgeEntityButton,
249
+ Component: PurgeEntityButton
250
+ });
117
251
  },
118
252
  async registerTrads({ locales }) {
119
253
  return Promise.all(
120
254
  locales.map(async (locale) => {
121
255
  try {
122
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("../_chunks/en-C0JeH0S_.js")) }), `./translations/${locale}.json`, 3);
256
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("../_chunks/en-CcRrGOBv.js")) }), `./translations/${locale}.json`, 3);
123
257
  return { data, locale };
124
258
  } catch {
125
259
  return { data: {}, locale };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../admin/src/pluginId.ts","../../admin/src/components/Initializer.tsx","../../admin/src/permission.ts","../../admin/src/components/PurgeCacheButton/index.tsx","../../admin/src/index.ts"],"sourcesContent":["export const PLUGIN_ID = 'strapi-cache';\n","import { useEffect, useRef } from 'react';\n\nimport { PLUGIN_ID } from '../pluginId';\n\ntype InitializerProps = {\n setPlugin: (id: string) => void;\n};\n\nconst Initializer = ({ setPlugin }: InitializerProps) => {\n const ref = useRef(setPlugin);\n\n useEffect(() => {\n ref.current(PLUGIN_ID);\n }, []);\n\n return null;\n};\n\nexport { Initializer };\n","export const pluginPermissions = {\n purge: [{ action: 'plugin::strapi-cache.purge-cache', subject: null }],\n};\n","import { useIntl } from 'react-intl';\nimport { Archive } from '@strapi/icons';\nimport { Button, Modal } from '@strapi/design-system';\nimport { useRBAC } from '@strapi/strapi/admin';\nimport { pluginPermissions } from '../../permission';\nimport { Typography } from '@strapi/design-system';\nimport { useFetchClient } from '@strapi/strapi/admin';\nimport { unstable_useContentManagerContext as useContentManagerContext } from '@strapi/strapi/admin';\nimport { useNotification } from '@strapi/strapi/admin';\n\nfunction PurgeCacheButton() {\n const { allowedActions } = useRBAC(pluginPermissions);\n const formatMessage = useIntl().formatMessage;\n const { post } = useFetchClient();\n const { toggleNotification } = useNotification();\n const { contentType } = useContentManagerContext();\n const pluralName = contentType?.info.pluralName;\n\n const clearCache = () => {\n if (!pluralName) {\n toggleNotification({\n type: 'warning',\n message: formatMessage({\n id: 'strapi-cache.cache.purge.no-content-type',\n defaultMessage: 'No content type found',\n }),\n });\n return;\n }\n\n post(`/strapi-cache/purge-cache/${pluralName}`, undefined, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n .then(() => {\n toggleNotification({\n type: 'success',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.success',\n defaultMessage: 'Cache purged successfully',\n }) + `: ${pluralName}`,\n });\n })\n .catch(() => {\n toggleNotification({\n type: 'danger',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.error',\n defaultMessage: 'Error purging cache',\n }) + `: ${pluralName}`,\n });\n });\n };\n\n if (!allowedActions.canPurgeCache) {\n return null;\n }\n\n return (\n <>\n <Modal.Root>\n <Modal.Trigger>\n <Button startIcon={<Archive />} variant=\"danger\">\n {formatMessage({\n id: 'strapi-cache.cache.purge',\n defaultMessage: 'Purge Cache',\n })}\n </Button>\n </Modal.Trigger>\n <Modal.Content>\n <Modal.Header>\n <Modal.Title>\n {formatMessage({\n id: 'strapi-cache.cache.purge',\n defaultMessage: 'Purge Cache',\n })}\n </Modal.Title>\n </Modal.Header>\n <Modal.Body>\n <Typography variant=\"omega\">\n {formatMessage({\n id: 'strapi-cache.cache.purge.confirmation',\n defaultMessage: 'Are you sure you want to purge the cache?',\n })}\n </Typography>\n </Modal.Body>\n <Modal.Footer>\n <Modal.Close>\n <Button variant=\"tertiary\">\n {formatMessage({\n id: 'strapi-cache.cache.cancel',\n defaultMessage: 'No, cancel',\n })}\n </Button>\n </Modal.Close>\n <Modal.Close>\n <Button onClick={clearCache}>\n {formatMessage({\n id: 'strapi-cache.cache.confirm',\n defaultMessage: 'Yes, confirm',\n })}\n </Button>\n </Modal.Close>\n </Modal.Footer>\n </Modal.Content>\n </Modal.Root>\n </>\n );\n}\n\nexport default PurgeCacheButton;\n","import { PLUGIN_ID } from './pluginId';\nimport { Initializer } from './components/Initializer';\nimport PurgeCacheButton from './components/PurgeCacheButton';\n\nexport default {\n register(app: any) {\n app.registerPlugin({\n id: PLUGIN_ID,\n initializer: Initializer,\n isReady: false,\n name: PLUGIN_ID,\n });\n\n app.getPlugin('content-manager').injectComponent('listView', 'actions', {\n name: PurgeCacheButton,\n Component: PurgeCacheButton,\n });\n },\n\n async registerTrads({ locales }: { locales: string[] }) {\n return Promise.all(\n locales.map(async (locale) => {\n try {\n const { default: data } = await import(`./translations/${locale}.json`);\n\n return { data, locale };\n } catch {\n return { data: {}, locale };\n }\n })\n );\n },\n};\n"],"names":["useRef","useEffect","useRBAC","useIntl","useFetchClient","useNotification","useContentManagerContext","jsx","Fragment","jsxs","Modal","Button","Archive","Typography"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,YAAY;ACQzB,MAAM,cAAc,CAAC,EAAE,gBAAkC;AACjD,QAAA,MAAMA,aAAO,SAAS;AAE5BC,QAAAA,UAAU,MAAM;AACd,QAAI,QAAQ,SAAS;AAAA,EACvB,GAAG,EAAE;AAEE,SAAA;AACT;AChBO,MAAM,oBAAoB;AAAA,EAC/B,OAAO,CAAC,EAAE,QAAQ,oCAAoC,SAAS,KAAM,CAAA;AACvE;ACQA,SAAS,mBAAmB;AAC1B,QAAM,EAAE,eAAA,IAAmBC,MAAA,QAAQ,iBAAiB;AAC9C,QAAA,gBAAgBC,oBAAU;AAC1B,QAAA,EAAE,KAAK,IAAIC,qBAAe;AAC1B,QAAA,EAAE,mBAAmB,IAAIC,sBAAgB;AACzC,QAAA,EAAE,YAAY,IAAIC,wCAAyB;AAC3C,QAAA,aAAa,aAAa,KAAK;AAErC,QAAM,aAAa,MAAM;AACvB,QAAI,CAAC,YAAY;AACI,yBAAA;AAAA,QACjB,MAAM;AAAA,QACN,SAAS,cAAc;AAAA,UACrB,IAAI;AAAA,UACJ,gBAAgB;AAAA,QACjB,CAAA;AAAA,MAAA,CACF;AACD;AAAA,IAAA;AAGG,SAAA,6BAA6B,UAAU,IAAI,QAAW;AAAA,MACzD,SAAS;AAAA,QACP,gBAAgB;AAAA,MAAA;AAAA,IAClB,CACD,EACE,KAAK,MAAM;AACS,yBAAA;AAAA,QACjB,MAAM;AAAA,QACN,SACE,cAAc;AAAA,UACZ,IAAI;AAAA,UACJ,gBAAgB;AAAA,QAAA,CACjB,IAAI,KAAK,UAAU;AAAA,MAAA,CACvB;AAAA,IAAA,CACF,EACA,MAAM,MAAM;AACQ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AS,YACd,UAAc,cAAA;AAAA,UACb,IAAI;AAAA,UACJ,gBAAgB;AAAA,QACjB,CAAA,EACH,CAAA,EACF,CAAA;AAAA,MAAA,EACF,CAAA;AAAA,IAAA,EACF,CAAA;AAAA,EAAA,EAAA,CACF,EACF,CAAA;AAEJ;AC3GA,MAAe,QAAA;AAAA,EACb,SAAS,KAAU;AACjB,QAAI,eAAe;AAAA,MACjB,IAAI;AAAA,MACJ,aAAa;AAAA,MACb,SAAS;AAAA,MACT,MAAM;AAAA,IAAA,CACP;AAED,QAAI,UAAU,iBAAiB,EAAE,gBAAgB,YAAY,WAAW;AAAA,MACtE,MAAM;AAAA,MACN,WAAW;AAAA,IAAA,CACZ;AAAA,EACH;AAAA,EAEA,MAAM,cAAc,EAAE,WAAkC;AACtD,WAAO,QAAQ;AAAA,MACb,QAAQ,IAAI,OAAO,WAAW;AACxB,YAAA;AACF,gBAAM,EAAE,SAAS,SAAS,MAAM,qCAAA,uBAAA,OAAA,EAAA,0BAAA,MAAA,QAAA,QAAA,EAAA,KAAA,MAAA,QAAA,2BAAA,CAAA,EAAA,CAAA,GAAA,kBAAA,MAAA,SAAA,CAAA;AAEzB,iBAAA,EAAE,MAAM,OAAO;AAAA,QAAA,QAChB;AACN,iBAAO,EAAE,MAAM,CAAC,GAAG,OAAO;AAAA,QAAA;AAAA,MAE7B,CAAA;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"index.js","sources":["../../admin/src/pluginId.ts","../../admin/src/components/Initializer.tsx","../../admin/src/permission.ts","../../admin/src/components/PurgeCacheButton/index.tsx","../../admin/src/components/PurgeEntityButton/index.tsx","../../admin/src/index.ts"],"sourcesContent":["export const PLUGIN_ID = 'strapi-cache';\n","import { useEffect, useRef } from 'react';\n\nimport { PLUGIN_ID } from '../pluginId';\n\ntype InitializerProps = {\n setPlugin: (id: string) => void;\n};\n\nconst Initializer = ({ setPlugin }: InitializerProps) => {\n const ref = useRef(setPlugin);\n\n useEffect(() => {\n ref.current(PLUGIN_ID);\n }, []);\n\n return null;\n};\n\nexport { Initializer };\n","export const pluginPermissions = {\n purge: [{ action: 'plugin::strapi-cache.purge-cache', subject: null }],\n};\n","import { useIntl } from 'react-intl';\nimport { Archive } from '@strapi/icons';\nimport { Button, Modal } from '@strapi/design-system';\nimport { useRBAC } from '@strapi/strapi/admin';\nimport { pluginPermissions } from '../../permission';\nimport { Typography } from '@strapi/design-system';\nimport { useFetchClient } from '@strapi/strapi/admin';\nimport { unstable_useContentManagerContext as useContentManagerContext } from '@strapi/strapi/admin';\nimport { useNotification } from '@strapi/strapi/admin';\nimport { useEffect, useState } from 'react';\n\nfunction PurgeCacheButton() {\n const { allowedActions } = useRBAC(pluginPermissions);\n const formatMessage = useIntl().formatMessage;\n const { post, get } = useFetchClient();\n const { toggleNotification } = useNotification();\n const { contentType } = useContentManagerContext();\n const [cacheableRoutes, setCacheableRoutes] = useState<string[]>();\n const pluralName = contentType?.info.pluralName;\n\n useEffect(() => {\n if (!allowedActions.canPurgeCache) {\n return;\n }\n const fetchCacheableRoutes = async () => {\n try {\n const { data } = await get('/strapi-cache/cacheable-routes');\n return data;\n } catch (error) {\n console.error('Error fetching cacheable routes:', error);\n return undefined;\n }\n };\n fetchCacheableRoutes().then((data) => {\n setCacheableRoutes(data);\n });\n }, [allowedActions.canPurgeCache]);\n\n const clearCache = () => {\n if (!pluralName) {\n toggleNotification({\n type: 'warning',\n message: formatMessage({\n id: 'strapi-cache.cache.purge.no-content-type',\n defaultMessage: 'No content type found',\n }),\n });\n return;\n }\n\n post(`/strapi-cache/purge-cache/${pluralName}`, undefined, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n .then(() => {\n toggleNotification({\n type: 'success',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.success',\n defaultMessage: 'Cache purged successfully',\n }) + `: ${pluralName}`,\n });\n })\n .catch(() => {\n toggleNotification({\n type: 'danger',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.error',\n defaultMessage: 'Error purging cache',\n }) + `: ${pluralName}`,\n });\n });\n };\n\n const isCacheableRoute = () => {\n if (!pluralName || !cacheableRoutes) {\n return false;\n }\n\n return (\n cacheableRoutes.length === 0 ||\n cacheableRoutes.some((route) => {\n return route.includes(pluralName);\n })\n );\n };\n\n if (!allowedActions.canPurgeCache || !isCacheableRoute()) {\n return null;\n }\n\n return (\n <>\n <Modal.Root>\n <Modal.Trigger>\n <Button startIcon={<Archive />} variant=\"danger\">\n {formatMessage({\n id: 'strapi-cache.cache.purge',\n defaultMessage: 'Purge Cache',\n })}\n </Button>\n </Modal.Trigger>\n <Modal.Content>\n <Modal.Header>\n <Modal.Title>\n {formatMessage({\n id: 'strapi-cache.cache.purge',\n defaultMessage: 'Purge Cache',\n })}\n </Modal.Title>\n </Modal.Header>\n <Modal.Body>\n <Typography variant=\"omega\">\n {formatMessage(\n {\n id: 'strapi-cache.cache.purge.confirmation',\n defaultMessage: 'Are you sure you want to purge the cache?',\n },\n {\n key: `\"${pluralName}\"`,\n }\n )}\n </Typography>\n </Modal.Body>\n <Modal.Footer>\n <Modal.Close>\n <Button variant=\"tertiary\">\n {formatMessage({\n id: 'strapi-cache.cache.cancel',\n defaultMessage: 'No, cancel',\n })}\n </Button>\n </Modal.Close>\n <Modal.Close>\n <Button onClick={clearCache}>\n {formatMessage({\n id: 'strapi-cache.cache.confirm',\n defaultMessage: 'Yes, confirm',\n })}\n </Button>\n </Modal.Close>\n </Modal.Footer>\n </Modal.Content>\n </Modal.Root>\n </>\n );\n}\n\nexport default PurgeCacheButton;\n","//TODO: refactor and rid of duplicated code (PurgeEntityButton and PurgeCacheButton)\n\nimport { useIntl } from 'react-intl';\nimport { Archive } from '@strapi/icons';\nimport { Button, Modal } from '@strapi/design-system';\nimport { useRBAC } from '@strapi/strapi/admin';\nimport { pluginPermissions } from '../../permission';\nimport { Typography } from '@strapi/design-system';\nimport { useFetchClient } from '@strapi/strapi/admin';\nimport { unstable_useContentManagerContext as useContentManagerContext } from '@strapi/strapi/admin';\nimport { useNotification } from '@strapi/strapi/admin';\nimport { useEffect, useState } from 'react';\n\nfunction PurgeEntityButton() {\n const { allowedActions } = useRBAC(pluginPermissions);\n const formatMessage = useIntl().formatMessage;\n const { post, get } = useFetchClient();\n const { toggleNotification } = useNotification();\n const { contentType, id } = useContentManagerContext();\n const [cacheableRoutes, setCacheableRoutes] = useState<string[]>();\n const pluralName = contentType?.info.pluralName;\n\n useEffect(() => {\n if (!allowedActions.canPurgeCache) {\n return;\n }\n const fetchCacheableRoutes = async () => {\n try {\n const { data } = await get('/strapi-cache/cacheable-routes');\n return data;\n } catch (error) {\n console.error('Error fetching cacheable routes:', error);\n return undefined;\n }\n };\n fetchCacheableRoutes().then((data) => {\n setCacheableRoutes(data);\n });\n }, [allowedActions.canPurgeCache]);\n\n const clearCache = () => {\n if (!pluralName) {\n toggleNotification({\n type: 'warning',\n message: formatMessage({\n id: 'strapi-cache.cache.purge.no-content-type',\n defaultMessage: 'No content type found',\n }),\n });\n return;\n }\n\n post(`/strapi-cache/purge-cache/${id}`, undefined, {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n .then(() => {\n toggleNotification({\n type: 'success',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.success',\n defaultMessage: 'Cache purged successfully',\n }) + `: ${pluralName}`,\n });\n })\n .catch(() => {\n toggleNotification({\n type: 'danger',\n message:\n formatMessage({\n id: 'strapi-cache.cache.purge.error',\n defaultMessage: 'Error purging cache',\n }) + `: ${pluralName}`,\n });\n });\n };\n\n const isCacheableRoute = () => {\n if (!pluralName || !cacheableRoutes) {\n return false;\n }\n\n return (\n cacheableRoutes.length === 0 ||\n cacheableRoutes.some((route) => {\n return route.includes(pluralName);\n })\n );\n };\n\n if (!allowedActions.canPurgeCache || !isCacheableRoute()) {\n return null;\n }\n\n return (\n <>\n <Modal.Root>\n <Modal.Trigger>\n <Button width={'100%'} startIcon={<Archive />} variant=\"danger\">\n {formatMessage({\n id: 'strapi-cache.cache.purge.entity',\n defaultMessage: 'Purge Entity Cache',\n })}\n </Button>\n </Modal.Trigger>\n <Modal.Content>\n <Modal.Header>\n <Modal.Title>\n {formatMessage({\n id: 'strapi-cache.cache.purge.entity',\n defaultMessage: 'Purge Entity Cache',\n })}\n </Modal.Title>\n </Modal.Header>\n <Modal.Body>\n <Typography variant=\"omega\">\n {formatMessage(\n {\n id: 'strapi-cache.cache.purge.confirmation',\n defaultMessage: 'Are you sure you want to purge the cache?',\n },\n { key: `\"${id}\"` }\n )}\n </Typography>\n </Modal.Body>\n <Modal.Footer>\n <Modal.Close>\n <Button variant=\"tertiary\">\n {formatMessage({\n id: 'strapi-cache.cache.cancel',\n defaultMessage: 'No, cancel',\n })}\n </Button>\n </Modal.Close>\n <Modal.Close>\n <Button onClick={clearCache}>\n {formatMessage({\n id: 'strapi-cache.cache.confirm',\n defaultMessage: 'Yes, confirm',\n })}\n </Button>\n </Modal.Close>\n </Modal.Footer>\n </Modal.Content>\n </Modal.Root>\n </>\n );\n}\n\nexport default PurgeEntityButton;\n","import { PLUGIN_ID } from './pluginId';\nimport { Initializer } from './components/Initializer';\nimport PurgeCacheButton from './components/PurgeCacheButton';\nimport PurgeEntityButton from './components/PurgeEntityButton';\n\nexport default {\n register(app: any) {\n app.registerPlugin({\n id: PLUGIN_ID,\n initializer: Initializer,\n isReady: false,\n name: PLUGIN_ID,\n });\n\n app.getPlugin('content-manager').injectComponent('listView', 'actions', {\n name: PurgeCacheButton,\n Component: PurgeCacheButton,\n });\n\n app.getPlugin('content-manager').injectComponent('editView', 'right-links', {\n name: PurgeEntityButton,\n Component: PurgeEntityButton,\n });\n },\n\n async registerTrads({ locales }: { locales: string[] }) {\n return Promise.all(\n locales.map(async (locale) => {\n try {\n const { default: data } = await import(`./translations/${locale}.json`);\n\n return { data, locale };\n } catch {\n return { data: {}, locale };\n }\n })\n );\n },\n};\n"],"names":["useRef","useEffect","useRBAC","useIntl","useFetchClient","useNotification","useContentManagerContext","useState","jsx","Fragment","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