strapi-cache 1.6.1 → 1.6.2-rc.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.
package/README.md CHANGED
@@ -72,7 +72,7 @@ In your Strapi project, navigate to `config/plugins.js` and add the following co
72
72
  The plugin creates three new routes
73
73
 
74
74
  - `POST /strapi-cache/purge-cache` (purges the whole cache)
75
- - `POST /strapi-cache/purge-cache/:key` (purges cache entries that have the key in the cache key)
75
+ - `POST /strapi-cache/purge-cache/key` (purges cache entries that have the key in the cache key, expects JSON body with `key` field)
76
76
  - `GET /strapi-cache/cacheable-routes` (returns the cacheable routes defined in the config)
77
77
  - `GET /strapi-cache/config` (returns the current plugin config)
78
78
 
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const designSystem = require("@strapi/design-system");
5
5
  const reactIntl = require("react-intl");
6
- const index = require("./index-CEeS79tY.js");
6
+ const index = require("./index-BJj5EZfj.js");
7
7
  const react = require("react");
8
8
  const SettingsPage = () => {
9
9
  const { formatMessage } = reactIntl.useIntl();
@@ -41,7 +41,7 @@ const SettingsPage = () => {
41
41
  onChange: (e) => setKeyToUse(e.target.value)
42
42
  }
43
43
  ) }),
44
- /* @__PURE__ */ jsxRuntime.jsx(index.PurgeModal, { buttonText: "Purge Cache", keyToUse })
44
+ /* @__PURE__ */ jsxRuntime.jsx(index.PurgeModal, { buttonText: "Purge Cache", keyToUse, isSettingsPage: true })
45
45
  ]
46
46
  }
47
47
  )
@@ -102,11 +102,15 @@ const useCacheOperations = () => {
102
102
  };
103
103
  }
104
104
  try {
105
- await post(`/strapi-cache/purge-cache/${keyToUse}`, void 0, {
106
- headers: {
107
- "Content-Type": "application/json"
105
+ await post(
106
+ `/strapi-cache/purge-cache/key`,
107
+ { key: keyToUse },
108
+ {
109
+ headers: {
110
+ "Content-Type": "application/json"
111
+ }
108
112
  }
109
- });
113
+ );
110
114
  return {
111
115
  success: true,
112
116
  message: `Cache purged successfully for key: "${keyToUse}"`
@@ -189,7 +193,13 @@ const useCacheNotifications = (config) => {
189
193
  showNoContentTypeWarning
190
194
  };
191
195
  };
192
- function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName }) {
196
+ function PurgeModal({
197
+ buttonText,
198
+ keyToUse,
199
+ buttonWidth,
200
+ contentTypeName,
201
+ isSettingsPage
202
+ }) {
193
203
  const { canPurgeCache } = useCachePermissions();
194
204
  const { config, error: configError } = useCacheConfig(canPurgeCache);
195
205
  const { isCacheableRoute, clearCache } = useCacheOperations();
@@ -212,11 +222,11 @@ function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName }) {
212
222
  showPurgeError(keyToUse);
213
223
  }
214
224
  };
215
- if (!canPurgeCache || !isCacheableRoute(keyToUse, contentTypeName, config)) {
225
+ if (!canPurgeCache || !isSettingsPage && !isCacheableRoute(keyToUse, contentTypeName, config)) {
216
226
  return null;
217
227
  }
218
228
  return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Root, { children: [
219
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { width: buttonWidth, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Archive, {}), variant: "danger", children: buttonText }) }),
229
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { width: buttonWidth, disabled: !keyToUse, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Archive, {}), variant: "danger", children: buttonText }) }),
220
230
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
221
231
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: buttonText }) }),
222
232
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: formatMessage(
@@ -308,7 +318,7 @@ const index = {
308
318
  },
309
319
  id: "settings",
310
320
  to: `${PLUGIN_ID}/settings`,
311
- Component: () => Promise.resolve().then(() => require("./index-BPBBFdba.js")),
321
+ Component: () => Promise.resolve().then(() => require("./index-7Lm6jbM0.js")),
312
322
  permissions: []
313
323
  }
314
324
  ]
@@ -1,7 +1,7 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import { Typography, TextInput } from "@strapi/design-system";
3
3
  import { useIntl } from "react-intl";
4
- import { P as PurgeModal } from "./index-CNdnmVNv.mjs";
4
+ import { P as PurgeModal } from "./index-dynpWXaG.mjs";
5
5
  import { useState } from "react";
6
6
  const SettingsPage = () => {
7
7
  const { formatMessage } = useIntl();
@@ -39,7 +39,7 @@ const SettingsPage = () => {
39
39
  onChange: (e) => setKeyToUse(e.target.value)
40
40
  }
41
41
  ) }),
42
- /* @__PURE__ */ jsx(PurgeModal, { buttonText: "Purge Cache", keyToUse })
42
+ /* @__PURE__ */ jsx(PurgeModal, { buttonText: "Purge Cache", keyToUse, isSettingsPage: true })
43
43
  ]
44
44
  }
45
45
  )
@@ -101,11 +101,15 @@ const useCacheOperations = () => {
101
101
  };
102
102
  }
103
103
  try {
104
- await post(`/strapi-cache/purge-cache/${keyToUse}`, void 0, {
105
- headers: {
106
- "Content-Type": "application/json"
104
+ await post(
105
+ `/strapi-cache/purge-cache/key`,
106
+ { key: keyToUse },
107
+ {
108
+ headers: {
109
+ "Content-Type": "application/json"
110
+ }
107
111
  }
108
- });
112
+ );
109
113
  return {
110
114
  success: true,
111
115
  message: `Cache purged successfully for key: "${keyToUse}"`
@@ -188,7 +192,13 @@ const useCacheNotifications = (config) => {
188
192
  showNoContentTypeWarning
189
193
  };
190
194
  };
191
- function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName }) {
195
+ function PurgeModal({
196
+ buttonText,
197
+ keyToUse,
198
+ buttonWidth,
199
+ contentTypeName,
200
+ isSettingsPage
201
+ }) {
192
202
  const { canPurgeCache } = useCachePermissions();
193
203
  const { config, error: configError } = useCacheConfig(canPurgeCache);
194
204
  const { isCacheableRoute, clearCache } = useCacheOperations();
@@ -211,11 +221,11 @@ function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName }) {
211
221
  showPurgeError(keyToUse);
212
222
  }
213
223
  };
214
- if (!canPurgeCache || !isCacheableRoute(keyToUse, contentTypeName, config)) {
224
+ if (!canPurgeCache || !isSettingsPage && !isCacheableRoute(keyToUse, contentTypeName, config)) {
215
225
  return null;
216
226
  }
217
227
  return /* @__PURE__ */ jsxs(Modal.Root, { children: [
218
- /* @__PURE__ */ jsx(Modal.Trigger, { children: /* @__PURE__ */ jsx(Button, { width: buttonWidth, startIcon: /* @__PURE__ */ jsx(Archive, {}), variant: "danger", children: buttonText }) }),
228
+ /* @__PURE__ */ jsx(Modal.Trigger, { children: /* @__PURE__ */ jsx(Button, { width: buttonWidth, disabled: !keyToUse, startIcon: /* @__PURE__ */ jsx(Archive, {}), variant: "danger", children: buttonText }) }),
219
229
  /* @__PURE__ */ jsxs(Modal.Content, { children: [
220
230
  /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: buttonText }) }),
221
231
  /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage(
@@ -307,7 +317,7 @@ const index = {
307
317
  },
308
318
  id: "settings",
309
319
  to: `${PLUGIN_ID}/settings`,
310
- Component: () => import("./index-CIkUFmSg.mjs"),
320
+ Component: () => import("./index-BS9N2eCV.mjs"),
311
321
  permissions: []
312
322
  }
313
323
  ]
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- const index = require("../_chunks/index-CEeS79tY.js");
2
+ const index = require("../_chunks/index-BJj5EZfj.js");
3
3
  module.exports = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "../_chunks/index-CNdnmVNv.mjs";
1
+ import { i } from "../_chunks/index-dynpWXaG.mjs";
2
2
  export {
3
3
  i as default
4
4
  };
@@ -3,6 +3,7 @@ export type PurgeProps = {
3
3
  buttonWidth?: string;
4
4
  keyToUse?: string;
5
5
  contentTypeName?: string;
6
+ isSettingsPage?: boolean;
6
7
  };
7
- declare function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName }: PurgeProps): import("react/jsx-runtime").JSX.Element | null;
8
+ declare function PurgeModal({ buttonText, keyToUse, buttonWidth, contentTypeName, isSettingsPage, }: PurgeProps): import("react/jsx-runtime").JSX.Element | null;
8
9
  export default PurgeModal;
@@ -489,7 +489,14 @@ const controller = ({ strapi: strapi2 }) => ({
489
489
  };
490
490
  },
491
491
  async purgeCacheByKey(ctx) {
492
- const { key } = ctx.params;
492
+ const { key } = ctx.request.body;
493
+ if (!key || typeof key !== "string" || key.trim() === "") {
494
+ ctx.status = 400;
495
+ ctx.body = {
496
+ error: "Key is required and must be a non-empty string"
497
+ };
498
+ return;
499
+ }
493
500
  const service2 = strapi2.plugin("strapi-cache").service("service");
494
501
  const regex = new RegExp(`(^|/)?${key}(/|\\?|$)`);
495
502
  await service2.getCacheInstance().clearByRegexp([regex]);
@@ -534,7 +541,7 @@ const purgeRoute = [
534
541
  },
535
542
  {
536
543
  method: "POST",
537
- path: "/purge-cache/:key",
544
+ path: "/purge-cache/key",
538
545
  handler: "controller.purgeCacheByKey",
539
546
  config: {
540
547
  policies: [
@@ -485,7 +485,14 @@ const controller = ({ strapi: strapi2 }) => ({
485
485
  };
486
486
  },
487
487
  async purgeCacheByKey(ctx) {
488
- const { key } = ctx.params;
488
+ const { key } = ctx.request.body;
489
+ if (!key || typeof key !== "string" || key.trim() === "") {
490
+ ctx.status = 400;
491
+ ctx.body = {
492
+ error: "Key is required and must be a non-empty string"
493
+ };
494
+ return;
495
+ }
489
496
  const service2 = strapi2.plugin("strapi-cache").service("service");
490
497
  const regex = new RegExp(`(^|/)?${key}(/|\\?|$)`);
491
498
  await service2.getCacheInstance().clearByRegexp([regex]);
@@ -530,7 +537,7 @@ const purgeRoute = [
530
537
  },
531
538
  {
532
539
  method: "POST",
533
- path: "/purge-cache/:key",
540
+ path: "/purge-cache/key",
534
541
  handler: "controller.purgeCacheByKey",
535
542
  config: {
536
543
  policies: [
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.1",
2
+ "version": "1.6.2-rc.2",
3
3
  "keywords": [
4
4
  "strapi cache",
5
5
  "strapi rest cache",