strapi-cache 1.10.1 → 1.11.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.
- package/README.md +2 -2
- package/dist/_chunks/{index-Bdo3ZcJs.js → index-BI_IgcrO.js} +1 -1
- package/dist/_chunks/{index-BovuTRdq.mjs → index-CYg363QI.mjs} +34 -3
- package/dist/_chunks/{index-EMYe2zF8.js → index-CvGwTcIJ.js} +34 -3
- package/dist/_chunks/{index-DLoQ9I8J.mjs → index-Dlr_QM4N.mjs} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/hooks/useCacheConfig.d.ts +2 -1
- package/dist/admin/src/utils/adminButtons.d.ts +12 -0
- package/dist/server/index.js +2 -2
- package/dist/server/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Full configuration example:
|
|
|
88
88
|
autoPurgeGraphQL: true, // Automatically purge GraphQL cache on content CRUD operations
|
|
89
89
|
autoPurgeCacheOnStart: true, // Automatically purge cache on Strapi startup
|
|
90
90
|
disableAdminPopups: false, // Disable popups in the admin panel
|
|
91
|
-
disableAdminButtons: false, // Disable the purge cache buttons in the admin panel
|
|
91
|
+
disableAdminButtons: false, // Disable the purge cache buttons in the admin panel. Use true for all content types or an array like ['/api/products'] for specific content types
|
|
92
92
|
},
|
|
93
93
|
},
|
|
94
94
|
```
|
|
@@ -122,7 +122,7 @@ Possible configuration keys are listed below; omitted keys keep the plugin defau
|
|
|
122
122
|
| `autoPurgeGraphQL` | Invalidate GraphQL cache after content create/update/delete | `true` or `false` (default: `false` if omitted; set `true` to enable) |
|
|
123
123
|
| `autoPurgeCacheOnStart` | Clear the cache when Strapi starts | `true` or `false` (default: `true`) |
|
|
124
124
|
| `disableAdminPopups` | Turn off admin UI notifications for cache actions | `true` or `false` (default: `false`) |
|
|
125
|
-
| `disableAdminButtons` | Hide manual purge controls in the admin (list and edit views)
|
|
125
|
+
| `disableAdminButtons` | Hide manual purge controls in the admin (list and edit views), either globally or for specific REST content type paths | `true`, `false`, or an array of paths such as `['/api/products', '/api/tags']` (default: `false`) |
|
|
126
126
|
|
|
127
127
|
## 🔍 Routes
|
|
128
128
|
|
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const designSystem = require("@strapi/design-system");
|
|
5
5
|
const reactIntl = require("react-intl");
|
|
6
6
|
const admin = require("@strapi/strapi/admin");
|
|
7
|
-
const index = require("./index-
|
|
7
|
+
const index = require("./index-CvGwTcIJ.js");
|
|
8
8
|
const react = require("react");
|
|
9
9
|
const SettingsPage = () => {
|
|
10
10
|
const { formatMessage } = reactIntl.useIntl();
|
|
@@ -296,12 +296,42 @@ function PurgeModal({
|
|
|
296
296
|
] })
|
|
297
297
|
] });
|
|
298
298
|
}
|
|
299
|
+
const stripTrailingSlashes = (path) => {
|
|
300
|
+
let end = path.length;
|
|
301
|
+
while (end > 1 && path[end - 1] === "/") {
|
|
302
|
+
end--;
|
|
303
|
+
}
|
|
304
|
+
return path.slice(0, end);
|
|
305
|
+
};
|
|
306
|
+
const normalizeApiPath = (path) => {
|
|
307
|
+
const trimmedPath = path.trim();
|
|
308
|
+
const pathWithLeadingSlash = trimmedPath.startsWith("/") ? trimmedPath : `/${trimmedPath}`;
|
|
309
|
+
return stripTrailingSlashes(pathWithLeadingSlash);
|
|
310
|
+
};
|
|
311
|
+
const getContentTypeApiPath = (contentType, isSingleType = false) => {
|
|
312
|
+
const useSingleName = isSingleType || contentType?.kind === "singleType";
|
|
313
|
+
const apiPath = useSingleName ? contentType?.info?.singularName ?? contentType?.apiID : contentType?.info?.pluralName ?? contentType?.apiID;
|
|
314
|
+
return apiPath ? normalizeApiPath(`/api/${apiPath}`) : void 0;
|
|
315
|
+
};
|
|
316
|
+
const shouldDisableAdminButtons = (disableAdminButtons, contentTypeApiPath) => {
|
|
317
|
+
if (typeof disableAdminButtons === "boolean") {
|
|
318
|
+
return disableAdminButtons;
|
|
319
|
+
}
|
|
320
|
+
if (!Array.isArray(disableAdminButtons) || !contentTypeApiPath) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
const normalizedContentTypeApiPath = normalizeApiPath(contentTypeApiPath);
|
|
324
|
+
return disableAdminButtons.some(
|
|
325
|
+
(apiPath) => normalizeApiPath(apiPath) === normalizedContentTypeApiPath
|
|
326
|
+
);
|
|
327
|
+
};
|
|
299
328
|
function PurgeCacheButton() {
|
|
300
329
|
const { contentType } = unstable_useContentManagerContext();
|
|
301
330
|
const { formatMessage } = useIntl();
|
|
302
331
|
const { config } = useCacheConfig();
|
|
303
332
|
const keyToUse = contentType?.info.pluralName;
|
|
304
|
-
|
|
333
|
+
const contentTypeApiPath = getContentTypeApiPath(contentType);
|
|
334
|
+
if (shouldDisableAdminButtons(config?.disableAdminButtons, contentTypeApiPath)) {
|
|
305
335
|
return null;
|
|
306
336
|
}
|
|
307
337
|
return /* @__PURE__ */ jsx(
|
|
@@ -320,10 +350,11 @@ function PurgeEntityButton() {
|
|
|
320
350
|
const { id, isSingleType, contentType } = unstable_useContentManagerContext();
|
|
321
351
|
const { config } = useCacheConfig();
|
|
322
352
|
const apiPath = isSingleType ? contentType?.info.singularName : id;
|
|
353
|
+
const contentTypeApiPath = getContentTypeApiPath(contentType, isSingleType);
|
|
323
354
|
if (!apiPath) {
|
|
324
355
|
return null;
|
|
325
356
|
}
|
|
326
|
-
if (config?.disableAdminButtons) {
|
|
357
|
+
if (shouldDisableAdminButtons(config?.disableAdminButtons, contentTypeApiPath)) {
|
|
327
358
|
return null;
|
|
328
359
|
}
|
|
329
360
|
const keyToUse = encodeURIComponent(apiPath);
|
|
@@ -373,7 +404,7 @@ const index = {
|
|
|
373
404
|
},
|
|
374
405
|
id: "settings",
|
|
375
406
|
to: `${PLUGIN_ID}/settings`,
|
|
376
|
-
Component: () => import("./index-
|
|
407
|
+
Component: () => import("./index-Dlr_QM4N.mjs"),
|
|
377
408
|
permissions: pluginPermissions.viewSettings
|
|
378
409
|
}
|
|
379
410
|
]
|
|
@@ -297,12 +297,42 @@ function PurgeModal({
|
|
|
297
297
|
] })
|
|
298
298
|
] });
|
|
299
299
|
}
|
|
300
|
+
const stripTrailingSlashes = (path) => {
|
|
301
|
+
let end = path.length;
|
|
302
|
+
while (end > 1 && path[end - 1] === "/") {
|
|
303
|
+
end--;
|
|
304
|
+
}
|
|
305
|
+
return path.slice(0, end);
|
|
306
|
+
};
|
|
307
|
+
const normalizeApiPath = (path) => {
|
|
308
|
+
const trimmedPath = path.trim();
|
|
309
|
+
const pathWithLeadingSlash = trimmedPath.startsWith("/") ? trimmedPath : `/${trimmedPath}`;
|
|
310
|
+
return stripTrailingSlashes(pathWithLeadingSlash);
|
|
311
|
+
};
|
|
312
|
+
const getContentTypeApiPath = (contentType, isSingleType = false) => {
|
|
313
|
+
const useSingleName = isSingleType || contentType?.kind === "singleType";
|
|
314
|
+
const apiPath = useSingleName ? contentType?.info?.singularName ?? contentType?.apiID : contentType?.info?.pluralName ?? contentType?.apiID;
|
|
315
|
+
return apiPath ? normalizeApiPath(`/api/${apiPath}`) : void 0;
|
|
316
|
+
};
|
|
317
|
+
const shouldDisableAdminButtons = (disableAdminButtons, contentTypeApiPath) => {
|
|
318
|
+
if (typeof disableAdminButtons === "boolean") {
|
|
319
|
+
return disableAdminButtons;
|
|
320
|
+
}
|
|
321
|
+
if (!Array.isArray(disableAdminButtons) || !contentTypeApiPath) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
const normalizedContentTypeApiPath = normalizeApiPath(contentTypeApiPath);
|
|
325
|
+
return disableAdminButtons.some(
|
|
326
|
+
(apiPath) => normalizeApiPath(apiPath) === normalizedContentTypeApiPath
|
|
327
|
+
);
|
|
328
|
+
};
|
|
300
329
|
function PurgeCacheButton() {
|
|
301
330
|
const { contentType } = admin.unstable_useContentManagerContext();
|
|
302
331
|
const { formatMessage } = reactIntl.useIntl();
|
|
303
332
|
const { config } = useCacheConfig();
|
|
304
333
|
const keyToUse = contentType?.info.pluralName;
|
|
305
|
-
|
|
334
|
+
const contentTypeApiPath = getContentTypeApiPath(contentType);
|
|
335
|
+
if (shouldDisableAdminButtons(config?.disableAdminButtons, contentTypeApiPath)) {
|
|
306
336
|
return null;
|
|
307
337
|
}
|
|
308
338
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -321,10 +351,11 @@ function PurgeEntityButton() {
|
|
|
321
351
|
const { id, isSingleType, contentType } = admin.unstable_useContentManagerContext();
|
|
322
352
|
const { config } = useCacheConfig();
|
|
323
353
|
const apiPath = isSingleType ? contentType?.info.singularName : id;
|
|
354
|
+
const contentTypeApiPath = getContentTypeApiPath(contentType, isSingleType);
|
|
324
355
|
if (!apiPath) {
|
|
325
356
|
return null;
|
|
326
357
|
}
|
|
327
|
-
if (config?.disableAdminButtons) {
|
|
358
|
+
if (shouldDisableAdminButtons(config?.disableAdminButtons, contentTypeApiPath)) {
|
|
328
359
|
return null;
|
|
329
360
|
}
|
|
330
361
|
const keyToUse = encodeURIComponent(apiPath);
|
|
@@ -374,7 +405,7 @@ const index = {
|
|
|
374
405
|
},
|
|
375
406
|
id: "settings",
|
|
376
407
|
to: `${PLUGIN_ID}/settings`,
|
|
377
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
408
|
+
Component: () => Promise.resolve().then(() => require("./index-BI_IgcrO.js")),
|
|
378
409
|
permissions: pluginPermissions.viewSettings
|
|
379
410
|
}
|
|
380
411
|
]
|
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Typography, TextInput } from "@strapi/design-system";
|
|
3
3
|
import { useIntl } from "react-intl";
|
|
4
4
|
import { Page } from "@strapi/strapi/admin";
|
|
5
|
-
import { p as pluginPermissions, P as PurgeModal } from "./index-
|
|
5
|
+
import { p as pluginPermissions, P as PurgeModal } from "./index-CYg363QI.mjs";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
const SettingsPage = () => {
|
|
8
8
|
const { formatMessage } = useIntl();
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { DisableAdminButtonsConfig } from '../utils/adminButtons';
|
|
1
2
|
export type CacheConfig = {
|
|
2
3
|
cacheableRoutes: string[];
|
|
3
4
|
disableAdminPopups: boolean;
|
|
4
|
-
disableAdminButtons:
|
|
5
|
+
disableAdminButtons: DisableAdminButtonsConfig;
|
|
5
6
|
};
|
|
6
7
|
export declare const useCacheConfig: (enabled?: boolean) => {
|
|
7
8
|
config: CacheConfig | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type DisableAdminButtonsConfig = boolean | string[];
|
|
2
|
+
type AdminContentType = {
|
|
3
|
+
apiID?: string;
|
|
4
|
+
kind?: string;
|
|
5
|
+
info?: {
|
|
6
|
+
pluralName?: string;
|
|
7
|
+
singularName?: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const getContentTypeApiPath: (contentType?: AdminContentType, isSingleType?: boolean) => string | undefined;
|
|
11
|
+
export declare const shouldDisableAdminButtons: (disableAdminButtons: DisableAdminButtonsConfig | undefined, contentTypeApiPath?: string) => boolean;
|
|
12
|
+
export {};
|
package/dist/server/index.js
CHANGED
|
@@ -653,8 +653,8 @@ const config = {
|
|
|
653
653
|
if (typeof config2.disableAdminPopups !== "boolean") {
|
|
654
654
|
throw new Error(`Invalid config: disableAdminPopups must be a boolean`);
|
|
655
655
|
}
|
|
656
|
-
if (typeof config2.disableAdminButtons !== "boolean") {
|
|
657
|
-
throw new Error(`Invalid config: disableAdminButtons must be a boolean`);
|
|
656
|
+
if (typeof config2.disableAdminButtons !== "boolean" && (!Array.isArray(config2.disableAdminButtons) || config2.disableAdminButtons.some((item) => typeof item !== "string"))) {
|
|
657
|
+
throw new Error(`Invalid config: disableAdminButtons must be a boolean or string array`);
|
|
658
658
|
}
|
|
659
659
|
if (typeof config2.redisScanDeleteCount !== "number") {
|
|
660
660
|
throw new Error(`Invalid config: redisScanDeleteCount must be a number`);
|
package/dist/server/index.mjs
CHANGED
|
@@ -649,8 +649,8 @@ const config = {
|
|
|
649
649
|
if (typeof config2.disableAdminPopups !== "boolean") {
|
|
650
650
|
throw new Error(`Invalid config: disableAdminPopups must be a boolean`);
|
|
651
651
|
}
|
|
652
|
-
if (typeof config2.disableAdminButtons !== "boolean") {
|
|
653
|
-
throw new Error(`Invalid config: disableAdminButtons must be a boolean`);
|
|
652
|
+
if (typeof config2.disableAdminButtons !== "boolean" && (!Array.isArray(config2.disableAdminButtons) || config2.disableAdminButtons.some((item) => typeof item !== "string"))) {
|
|
653
|
+
throw new Error(`Invalid config: disableAdminButtons must be a boolean or string array`);
|
|
654
654
|
}
|
|
655
655
|
if (typeof config2.redisScanDeleteCount !== "number") {
|
|
656
656
|
throw new Error(`Invalid config: redisScanDeleteCount must be a number`);
|
package/package.json
CHANGED