strapi-cache 1.6.2-rc.2 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/dist/_chunks/de-BABI25Ju.js +0 -17
  3. package/dist/_chunks/de-Dihl3Ias.mjs +0 -17
  4. package/dist/_chunks/en-CLhkAQFN.mjs +0 -17
  5. package/dist/_chunks/en-DYulQU0k.js +0 -17
  6. package/dist/_chunks/index-7Lm6jbM0.js +0 -50
  7. package/dist/_chunks/index-BJj5EZfj.js +0 -341
  8. package/dist/_chunks/index-BS9N2eCV.mjs +0 -50
  9. package/dist/_chunks/index-dynpWXaG.mjs +0 -342
  10. package/dist/admin/index.js +0 -3
  11. package/dist/admin/index.mjs +0 -4
  12. package/dist/server/index.js +0 -842
  13. package/dist/server/index.mjs +0 -840
  14. package/dist/server/src/bootstrap.d.ts +0 -5
  15. package/dist/server/src/config/index.d.ts +0 -27
  16. package/dist/server/src/content-types/index.d.ts +0 -2
  17. package/dist/server/src/controllers/controller.d.ts +0 -10
  18. package/dist/server/src/controllers/index.d.ts +0 -11
  19. package/dist/server/src/index.d.ts +0 -75
  20. package/dist/server/src/middlewares/cache.d.ts +0 -3
  21. package/dist/server/src/middlewares/graphql.d.ts +0 -2
  22. package/dist/server/src/middlewares/index.d.ts +0 -6
  23. package/dist/server/src/permissions.d.ts +0 -6
  24. package/dist/server/src/policies/index.d.ts +0 -2
  25. package/dist/server/src/register.d.ts +0 -5
  26. package/dist/server/src/routes/index.d.ts +0 -19
  27. package/dist/server/src/routes/purge.d.ts +0 -14
  28. package/dist/server/src/services/index.d.ts +0 -8
  29. package/dist/server/src/services/memory/provider.d.ts +0 -17
  30. package/dist/server/src/services/memory/service.d.ts +0 -6
  31. package/dist/server/src/services/redis/provider.d.ts +0 -18
  32. package/dist/server/src/services/redis/service.d.ts +0 -6
  33. package/dist/server/src/services/resolver.d.ts +0 -3
  34. package/dist/server/src/types/cache.types.d.ts +0 -18
  35. package/dist/server/src/utils/body.d.ts +0 -7
  36. package/dist/server/src/utils/header.d.ts +0 -10
  37. package/dist/server/src/utils/invalidateCache.d.ts +0 -4
  38. package/dist/server/src/utils/key.d.ts +0 -3
  39. package/dist/server/src/utils/log.d.ts +0 -5
  40. package/dist/server/src/utils/withTimeout.d.ts +0 -1
@@ -1,342 +0,0 @@
1
- import { useRef, useEffect, useState } from "react";
2
- import { jsxs, jsx } from "react/jsx-runtime";
3
- import { useFetchClient, useRBAC, useNotification, unstable_useContentManagerContext } from "@strapi/strapi/admin";
4
- import { useIntl } from "react-intl";
5
- import { Archive } from "@strapi/icons";
6
- import { Modal, Button, Typography } from "@strapi/design-system";
7
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
8
- const v = glob[path];
9
- if (v) {
10
- return typeof v === "function" ? v() : Promise.resolve(v);
11
- }
12
- return new Promise((_, reject) => {
13
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
14
- reject.bind(
15
- null,
16
- new Error(
17
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
18
- )
19
- )
20
- );
21
- });
22
- };
23
- const PLUGIN_ID = "strapi-cache";
24
- const Initializer = ({ setPlugin }) => {
25
- const ref = useRef(setPlugin);
26
- useEffect(() => {
27
- ref.current(PLUGIN_ID);
28
- }, []);
29
- return null;
30
- };
31
- const useCacheConfig = (enabled = true) => {
32
- const [config, setConfig] = useState();
33
- const [isLoading, setIsLoading] = useState(false);
34
- const [error, setError] = useState(null);
35
- const { get } = useFetchClient();
36
- useEffect(() => {
37
- if (!enabled) {
38
- return;
39
- }
40
- const fetchConfig = async () => {
41
- setIsLoading(true);
42
- setError(null);
43
- try {
44
- const { data } = await get("/strapi-cache/config");
45
- setConfig(data);
46
- } catch (error2) {
47
- setError(error2);
48
- } finally {
49
- setIsLoading(false);
50
- }
51
- };
52
- fetchConfig();
53
- }, [enabled, get]);
54
- return {
55
- config,
56
- isLoading,
57
- error,
58
- refetch: () => {
59
- const fetchConfig = async () => {
60
- setIsLoading(true);
61
- setError(null);
62
- try {
63
- const { data } = await get("/strapi-cache/config");
64
- setConfig(data);
65
- } catch (error2) {
66
- setError(error2);
67
- } finally {
68
- setIsLoading(false);
69
- }
70
- };
71
- fetchConfig();
72
- }
73
- };
74
- };
75
- const pluginPermissions = {
76
- purge: [{ action: "plugin::strapi-cache.purge-cache", subject: null }]
77
- };
78
- const useCachePermissions = () => {
79
- const { allowedActions } = useRBAC(pluginPermissions);
80
- return {
81
- canPurgeCache: allowedActions.canPurgeCache,
82
- allowedActions
83
- };
84
- };
85
- const useCacheOperations = () => {
86
- const { post } = useFetchClient();
87
- const isCacheableRoute = (keyToUse, contentTypeName, config) => {
88
- if (!keyToUse || !config) {
89
- return false;
90
- }
91
- const { cacheableRoutes } = config;
92
- return cacheableRoutes.length === 0 || cacheableRoutes.some((route) => {
93
- return route.includes(keyToUse) || contentTypeName && route.includes(contentTypeName);
94
- });
95
- };
96
- const clearCache = async (keyToUse) => {
97
- if (!keyToUse) {
98
- return {
99
- success: false,
100
- message: "No content type found"
101
- };
102
- }
103
- try {
104
- await post(
105
- `/strapi-cache/purge-cache/key`,
106
- { key: keyToUse },
107
- {
108
- headers: {
109
- "Content-Type": "application/json"
110
- }
111
- }
112
- );
113
- return {
114
- success: true,
115
- message: `Cache purged successfully for key: "${keyToUse}"`
116
- };
117
- } catch (error) {
118
- return {
119
- success: false,
120
- message: `Error purging cache for key: "${keyToUse}"`,
121
- error
122
- };
123
- }
124
- };
125
- return {
126
- isCacheableRoute,
127
- clearCache
128
- };
129
- };
130
- const useCacheNotifications = (config) => {
131
- const formatMessage = useIntl().formatMessage;
132
- const { toggleNotification } = useNotification();
133
- const showConfigFetchError = (error) => {
134
- const isPermissionError = error?.response?.status === 403 || error?.response?.status === 401;
135
- if (!isPermissionError && !config?.disableAdminPopups) {
136
- toggleNotification({
137
- type: "warning",
138
- message: formatMessage({
139
- id: "strapi-cache.cache.routes.fetch-error",
140
- defaultMessage: "Unable to fetch cache config. Cache purge may not work correctly."
141
- })
142
- });
143
- }
144
- };
145
- const showPurgeSuccess = (key) => {
146
- if (!config?.disableAdminPopups) {
147
- toggleNotification({
148
- type: "success",
149
- message: formatMessage(
150
- {
151
- id: "strapi-cache.cache.purge.success",
152
- defaultMessage: "Cache purged successfully"
153
- },
154
- {
155
- key: `"${key}"`
156
- }
157
- )
158
- });
159
- }
160
- };
161
- const showPurgeError = (key) => {
162
- if (!config?.disableAdminPopups) {
163
- toggleNotification({
164
- type: "danger",
165
- message: formatMessage(
166
- {
167
- id: "strapi-cache.cache.purge.error",
168
- defaultMessage: "Error purging cache"
169
- },
170
- {
171
- key: `"${key}"`
172
- }
173
- )
174
- });
175
- }
176
- };
177
- const showNoContentTypeWarning = () => {
178
- if (!config?.disableAdminPopups) {
179
- toggleNotification({
180
- type: "warning",
181
- message: formatMessage({
182
- id: "strapi-cache.cache.purge.no-content-type",
183
- defaultMessage: "No content type found"
184
- })
185
- });
186
- }
187
- };
188
- return {
189
- showConfigFetchError,
190
- showPurgeSuccess,
191
- showPurgeError,
192
- showNoContentTypeWarning
193
- };
194
- };
195
- function PurgeModal({
196
- buttonText,
197
- keyToUse,
198
- buttonWidth,
199
- contentTypeName,
200
- isSettingsPage
201
- }) {
202
- const { canPurgeCache } = useCachePermissions();
203
- const { config, error: configError } = useCacheConfig(canPurgeCache);
204
- const { isCacheableRoute, clearCache } = useCacheOperations();
205
- const { showConfigFetchError, showPurgeSuccess, showPurgeError, showNoContentTypeWarning } = useCacheNotifications(config);
206
- const formatMessage = useIntl().formatMessage;
207
- useEffect(() => {
208
- if (configError) {
209
- showConfigFetchError(configError);
210
- }
211
- }, [configError, showConfigFetchError]);
212
- const handleClearCache = async () => {
213
- if (!keyToUse) {
214
- showNoContentTypeWarning();
215
- return;
216
- }
217
- const result = await clearCache(keyToUse);
218
- if (result.success) {
219
- showPurgeSuccess(keyToUse);
220
- } else {
221
- showPurgeError(keyToUse);
222
- }
223
- };
224
- if (!canPurgeCache || !isSettingsPage && !isCacheableRoute(keyToUse, contentTypeName, config)) {
225
- return null;
226
- }
227
- return /* @__PURE__ */ jsxs(Modal.Root, { children: [
228
- /* @__PURE__ */ jsx(Modal.Trigger, { children: /* @__PURE__ */ jsx(Button, { width: buttonWidth, disabled: !keyToUse, startIcon: /* @__PURE__ */ jsx(Archive, {}), variant: "danger", children: buttonText }) }),
229
- /* @__PURE__ */ jsxs(Modal.Content, { children: [
230
- /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: buttonText }) }),
231
- /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage(
232
- {
233
- id: "strapi-cache.cache.purge.confirmation",
234
- defaultMessage: "Are you sure you want to purge the cache?"
235
- },
236
- { key: `"${keyToUse}"` }
237
- ) }) }),
238
- /* @__PURE__ */ jsxs(Modal.Footer, { children: [
239
- /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({
240
- id: "strapi-cache.cache.cancel",
241
- defaultMessage: "No, cancel"
242
- }) }) }),
243
- /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { onClick: handleClearCache, children: formatMessage({
244
- id: "strapi-cache.cache.confirm",
245
- defaultMessage: "Yes, confirm"
246
- }) }) })
247
- ] })
248
- ] })
249
- ] });
250
- }
251
- function PurgeCacheButton() {
252
- const { contentType } = unstable_useContentManagerContext();
253
- const { formatMessage } = useIntl();
254
- const keyToUse = contentType?.info.pluralName;
255
- return /* @__PURE__ */ jsx(
256
- PurgeModal,
257
- {
258
- buttonText: formatMessage({
259
- id: "strapi-cache.cache.purge",
260
- defaultMessage: "Purge Cache"
261
- }),
262
- keyToUse
263
- }
264
- );
265
- }
266
- function PurgeEntityButton() {
267
- const { formatMessage } = useIntl();
268
- const { id, isSingleType, contentType } = unstable_useContentManagerContext();
269
- const apiPath = isSingleType ? contentType?.info.singularName : id;
270
- if (!apiPath) {
271
- return null;
272
- }
273
- const keyToUse = encodeURIComponent(apiPath);
274
- const contentTypeName = isSingleType ? contentType?.info.singularName : contentType?.info.pluralName;
275
- return /* @__PURE__ */ jsx(
276
- PurgeModal,
277
- {
278
- buttonWidth: "100%",
279
- buttonText: formatMessage({
280
- id: "strapi-cache.cache.purge.entity",
281
- defaultMessage: "Purge Entity Cache"
282
- }),
283
- keyToUse,
284
- contentTypeName
285
- }
286
- );
287
- }
288
- const index = {
289
- register(app) {
290
- app.registerPlugin({
291
- id: PLUGIN_ID,
292
- initializer: Initializer,
293
- isReady: false,
294
- name: PLUGIN_ID
295
- });
296
- app.getPlugin("content-manager").injectComponent("listView", "actions", {
297
- name: PurgeCacheButton,
298
- Component: PurgeCacheButton
299
- });
300
- app.getPlugin("content-manager").injectComponent("editView", "right-links", {
301
- name: PurgeEntityButton,
302
- Component: PurgeEntityButton
303
- });
304
- app.createSettingSection(
305
- {
306
- id: PLUGIN_ID,
307
- intlLabel: {
308
- id: "strapi-cache.settings.link",
309
- defaultMessage: "Strapi Cache"
310
- }
311
- },
312
- [
313
- {
314
- intlLabel: {
315
- id: "strapi-cache.settings.link",
316
- defaultMessage: "Strapi Cache"
317
- },
318
- id: "settings",
319
- to: `${PLUGIN_ID}/settings`,
320
- Component: () => import("./index-BS9N2eCV.mjs"),
321
- permissions: []
322
- }
323
- ]
324
- );
325
- },
326
- async registerTrads({ locales }) {
327
- return Promise.all(
328
- locales.map(async (locale) => {
329
- try {
330
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-Dihl3Ias.mjs"), "./translations/en.json": () => import("./en-CLhkAQFN.mjs") }), `./translations/${locale}.json`, 3);
331
- return { data, locale };
332
- } catch {
333
- return { data: {}, locale };
334
- }
335
- })
336
- );
337
- }
338
- };
339
- export {
340
- PurgeModal as P,
341
- index as i
342
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- const index = require("../_chunks/index-BJj5EZfj.js");
3
- module.exports = index.index;
@@ -1,4 +0,0 @@
1
- import { i } from "../_chunks/index-dynpWXaG.mjs";
2
- export {
3
- i as default
4
- };