strapi-cache 1.6.2 → 1.8.1

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 (46) hide show
  1. package/README.md +7 -2
  2. package/dist/_chunks/de-C_gFyhHL.mjs +18 -0
  3. package/dist/_chunks/de-l6MDDAXu.js +18 -0
  4. package/dist/_chunks/en-D9w03LyX.js +18 -0
  5. package/dist/_chunks/en-bK2OKwtN.mjs +18 -0
  6. package/dist/_chunks/index-B_MAAg0W.js +52 -0
  7. package/dist/_chunks/index-BwuX8jJl.mjs +396 -0
  8. package/dist/_chunks/index-CkLhx2ik.mjs +52 -0
  9. package/dist/_chunks/index-D_ssKKxu.js +395 -0
  10. package/dist/admin/index.js +3 -0
  11. package/dist/admin/index.mjs +4 -0
  12. package/dist/admin/src/components/PurgeCacheButton/index.d.ts +1 -1
  13. package/dist/admin/src/components/PurgeModal/index.d.ts +2 -1
  14. package/dist/admin/src/hooks/useCacheConfig.d.ts +1 -0
  15. package/dist/admin/src/hooks/useCacheOperations.d.ts +1 -0
  16. package/dist/server/index.js +999 -0
  17. package/dist/server/index.mjs +997 -0
  18. package/dist/server/src/bootstrap.d.ts +5 -0
  19. package/dist/server/src/config/index.d.ts +28 -0
  20. package/dist/server/src/content-types/index.d.ts +2 -0
  21. package/dist/server/src/controllers/controller.d.ts +10 -0
  22. package/dist/server/src/controllers/index.d.ts +11 -0
  23. package/dist/server/src/index.d.ts +76 -0
  24. package/dist/server/src/middlewares/cache.d.ts +3 -0
  25. package/dist/server/src/middlewares/graphql.d.ts +2 -0
  26. package/dist/server/src/middlewares/index.d.ts +6 -0
  27. package/dist/server/src/permissions.d.ts +6 -0
  28. package/dist/server/src/policies/index.d.ts +2 -0
  29. package/dist/server/src/register.d.ts +5 -0
  30. package/dist/server/src/routes/index.d.ts +19 -0
  31. package/dist/server/src/routes/purge.d.ts +14 -0
  32. package/dist/server/src/services/index.d.ts +8 -0
  33. package/dist/server/src/services/memory/provider.d.ts +17 -0
  34. package/dist/server/src/services/memory/service.d.ts +6 -0
  35. package/dist/server/src/services/redis/provider.d.ts +23 -0
  36. package/dist/server/src/services/redis/service.d.ts +6 -0
  37. package/dist/server/src/services/resolver.d.ts +3 -0
  38. package/dist/server/src/types/cache.types.d.ts +18 -0
  39. package/dist/server/src/utils/body.d.ts +7 -0
  40. package/dist/server/src/utils/graphql.d.ts +6 -0
  41. package/dist/server/src/utils/header.d.ts +10 -0
  42. package/dist/server/src/utils/invalidateCache.d.ts +8 -0
  43. package/dist/server/src/utils/key.d.ts +5 -0
  44. package/dist/server/src/utils/log.d.ts +5 -0
  45. package/dist/server/src/utils/withTimeout.d.ts +1 -0
  46. package/package.json +16 -2
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const bootstrap: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default bootstrap;
@@ -0,0 +1,28 @@
1
+ declare const _default: {
2
+ default: ({ env }: {
3
+ env: any;
4
+ }) => {
5
+ debug: boolean;
6
+ max: number;
7
+ ttl: number;
8
+ size: number;
9
+ allowStale: boolean;
10
+ cacheableRoutes: any[];
11
+ provider: string;
12
+ excludeRoutes: any[];
13
+ redisConfig: any;
14
+ redisClusterNodes: any[];
15
+ redisClusterOptions: {};
16
+ cacheHeaders: boolean;
17
+ cacheHeadersDenyList: any[];
18
+ cacheHeadersAllowList: any[];
19
+ cacheAuthorizedRequests: boolean;
20
+ cacheGetTimeoutInMs: number;
21
+ autoPurgeCache: boolean;
22
+ autoPurgeCacheOnStart: boolean;
23
+ disableAdminPopups: boolean;
24
+ disableAdminButtons: boolean;
25
+ };
26
+ validator: (config: any) => void;
27
+ };
28
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { Context } from 'koa';
3
+ declare const controller: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => {
6
+ purgeCache(ctx: Context): Promise<void>;
7
+ purgeCacheByKey(ctx: Context): Promise<void>;
8
+ config(ctx: Context): Promise<void>;
9
+ };
10
+ export default controller;
@@ -0,0 +1,11 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ controller: ({ strapi }: {
4
+ strapi: import("@strapi/types/dist/core").Strapi;
5
+ }) => {
6
+ purgeCache(ctx: import("koa").Context): Promise<void>;
7
+ purgeCacheByKey(ctx: import("koa").Context): Promise<void>;
8
+ config(ctx: import("koa").Context): Promise<void>;
9
+ };
10
+ };
11
+ export default _default;
@@ -0,0 +1,76 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ register: ({ strapi }: {
4
+ strapi: import("@strapi/types/dist/core").Strapi;
5
+ }) => void;
6
+ bootstrap: ({ strapi }: {
7
+ strapi: import("@strapi/types/dist/core").Strapi;
8
+ }) => void;
9
+ destroy(): void;
10
+ config: {
11
+ default: ({ env }: {
12
+ env: any;
13
+ }) => {
14
+ debug: boolean;
15
+ max: number;
16
+ ttl: number;
17
+ size: number;
18
+ allowStale: boolean;
19
+ cacheableRoutes: any[];
20
+ provider: string;
21
+ excludeRoutes: any[];
22
+ redisConfig: any;
23
+ redisClusterNodes: any[];
24
+ redisClusterOptions: {};
25
+ cacheHeaders: boolean;
26
+ cacheHeadersDenyList: any[];
27
+ cacheHeadersAllowList: any[];
28
+ cacheAuthorizedRequests: boolean;
29
+ cacheGetTimeoutInMs: number;
30
+ autoPurgeCache: boolean;
31
+ autoPurgeCacheOnStart: boolean;
32
+ disableAdminPopups: boolean;
33
+ disableAdminButtons: boolean;
34
+ };
35
+ validator: (config: any) => void;
36
+ };
37
+ controllers: {
38
+ controller: ({ strapi }: {
39
+ strapi: import("@strapi/types/dist/core").Strapi;
40
+ }) => {
41
+ purgeCache(ctx: import("koa").Context): Promise<void>;
42
+ purgeCacheByKey(ctx: import("koa").Context): Promise<void>;
43
+ config(ctx: import("koa").Context): Promise<void>;
44
+ };
45
+ };
46
+ routes: {
47
+ 'purge-route': {
48
+ type: string;
49
+ routes: {
50
+ method: string;
51
+ path: string;
52
+ handler: string;
53
+ config: {
54
+ policies: (string | {
55
+ name: string;
56
+ config: {
57
+ actions: string[];
58
+ };
59
+ })[];
60
+ };
61
+ }[];
62
+ };
63
+ };
64
+ services: {
65
+ service: ({ strapi }: {
66
+ strapi: import("@strapi/types/dist/core").Strapi;
67
+ }) => import("./types/cache.types").CacheService;
68
+ };
69
+ contentTypes: {};
70
+ policies: {};
71
+ middlewares: {
72
+ graphql: (ctx: any, next: any) => Promise<void>;
73
+ cache: (ctx: import("koa").Context, next: any) => Promise<void>;
74
+ };
75
+ };
76
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { Context } from 'koa';
2
+ declare const middleware: (ctx: Context, next: any) => Promise<void>;
3
+ export default middleware;
@@ -0,0 +1,2 @@
1
+ declare const middleware: (ctx: any, next: any) => Promise<void>;
2
+ export default middleware;
@@ -0,0 +1,6 @@
1
+ /// <reference types="koa" />
2
+ declare const _default: {
3
+ graphql: (ctx: any, next: any) => Promise<void>;
4
+ cache: (ctx: import("koa").Context, next: any) => Promise<void>;
5
+ };
6
+ export default _default;
@@ -0,0 +1,6 @@
1
+ export declare const actions: {
2
+ section: string;
3
+ displayName: string;
4
+ uid: string;
5
+ pluginName: string;
6
+ }[];
@@ -0,0 +1,2 @@
1
+ declare const _default: {};
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ declare const register: ({ strapi }: {
3
+ strapi: Core.Strapi;
4
+ }) => void;
5
+ export default register;
@@ -0,0 +1,19 @@
1
+ declare const routes: {
2
+ 'purge-route': {
3
+ type: string;
4
+ routes: {
5
+ method: string;
6
+ path: string;
7
+ handler: string;
8
+ config: {
9
+ policies: (string | {
10
+ name: string;
11
+ config: {
12
+ actions: string[];
13
+ };
14
+ })[];
15
+ };
16
+ }[];
17
+ };
18
+ };
19
+ export default routes;
@@ -0,0 +1,14 @@
1
+ declare const _default: {
2
+ method: string;
3
+ path: string;
4
+ handler: string;
5
+ config: {
6
+ policies: (string | {
7
+ name: string;
8
+ config: {
9
+ actions: string[];
10
+ };
11
+ })[];
12
+ };
13
+ }[];
14
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { CacheService } from '../../src/types/cache.types';
3
+ declare const _default: {
4
+ service: ({ strapi }: {
5
+ strapi: Core.Strapi;
6
+ }) => CacheService;
7
+ };
8
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { CacheProvider } from '../../types/cache.types';
3
+ export declare class InMemoryCacheProvider implements CacheProvider {
4
+ private strapi;
5
+ private initialized;
6
+ private provider;
7
+ private cacheGetTimeoutInMs;
8
+ constructor(strapi: Core.Strapi);
9
+ init(): void;
10
+ get ready(): boolean;
11
+ get(key: string): Promise<any | null>;
12
+ set(key: string, val: any): Promise<any | null>;
13
+ del(key: string): Promise<any | null>;
14
+ keys(): Promise<string[] | null>;
15
+ reset(): Promise<any | null>;
16
+ clearByRegexp(regExps: RegExp[]): Promise<void>;
17
+ }
@@ -0,0 +1,6 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { CacheService } from '../../types/cache.types';
3
+ declare const service: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => CacheService;
6
+ export default service;
@@ -0,0 +1,23 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { CacheProvider } from '../../types/cache.types';
3
+ export declare class RedisCacheProvider implements CacheProvider {
4
+ private strapi;
5
+ private initialized;
6
+ private client;
7
+ private cacheGetTimeoutInMs;
8
+ private keyPrefix;
9
+ constructor(strapi: Core.Strapi);
10
+ init(): void;
11
+ get ready(): boolean;
12
+ get(key: string): Promise<any | null>;
13
+ set(key: string, val: any): Promise<any | null>;
14
+ del(key: string): Promise<any | null>;
15
+ /**
16
+ * Deletes all given keys in Redis pipeline.
17
+ * @param keys to delete from cache
18
+ */
19
+ delAll(keys: string[]): Promise<void>;
20
+ keys(): Promise<string[] | null>;
21
+ reset(): Promise<any | null>;
22
+ clearByRegexp(regExps: RegExp[]): Promise<void>;
23
+ }
@@ -0,0 +1,6 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import type { CacheService } from '../../types/cache.types';
3
+ declare const service: ({ strapi }: {
4
+ strapi: Core.Strapi;
5
+ }) => CacheService;
6
+ export default service;
@@ -0,0 +1,3 @@
1
+ import type { Core } from '@strapi/strapi';
2
+ import { CacheProvider } from '../../src/types/cache.types';
3
+ export declare const resolveCacheProvider: (strapi: Core.Strapi) => CacheProvider;
@@ -0,0 +1,18 @@
1
+ import type { LRUCache } from 'lru-cache';
2
+ export interface CacheProvider {
3
+ init(): void;
4
+ get(key: string): Promise<any | null>;
5
+ set(key: string, val: any): Promise<any | null>;
6
+ del(key: string): Promise<any | null>;
7
+ keys(): Promise<string[] | null>;
8
+ reset(): Promise<any | null>;
9
+ readonly ready: boolean;
10
+ clearByRegexp(regExps: RegExp[]): Promise<void>;
11
+ }
12
+ export interface CacheService {
13
+ getCacheInstance(): CacheProvider;
14
+ }
15
+ export interface CacheInstance {
16
+ initialized: boolean;
17
+ provider: LRUCache<string, any>;
18
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { Stream } from 'stream';
5
+ export declare const streamToBuffer: (stream: Stream) => Promise<Buffer>;
6
+ export declare const decompressBuffer: (buffer: Buffer, encoding?: string) => Promise<Buffer>;
7
+ export declare const decodeBufferToText: (buffer: Buffer) => string;
@@ -0,0 +1,6 @@
1
+ export declare function parseGraphqlPayload(body: string, isGet: boolean): {
2
+ query: string;
3
+ variables: Record<string, unknown> | string | null;
4
+ operationName: string | null;
5
+ };
6
+ export declare function getRootFieldsFromQuery(query: string): string[];
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import { Context } from 'koa';
3
+ import { OutgoingHttpHeaders } from 'http';
4
+ export declare function getHeadersToStore(ctx: Context, cacheHeaders: boolean, cacheHeadersAllowList?: string[], cacheHeadersDenyList?: string[]): OutgoingHttpHeaders | null;
5
+ export declare function getCacheHeaderConfig(): {
6
+ cacheHeaders: boolean;
7
+ cacheHeadersDenyList: string[];
8
+ cacheHeadersAllowList: string[];
9
+ cacheAuthorizedRequests: boolean;
10
+ };
@@ -0,0 +1,8 @@
1
+ import { Core } from '@strapi/strapi';
2
+ import { CacheProvider } from 'src/types/cache.types';
3
+ export declare function invalidateCache(event: any, cacheStore: CacheProvider, strapi: Core.Strapi): Promise<void>;
4
+ export declare function invalidateGraphqlCache(event: {
5
+ model: {
6
+ uid: string;
7
+ };
8
+ }, cacheStore: CacheProvider, strapi: Core.Strapi): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { Context } from 'koa';
2
+ export declare const generateCacheKey: (context: Context) => string;
3
+ export declare const generateGraphqlCacheKey: (payload: string, method?: 'GET' | 'POST', rootFields?: string[]) => string;
4
+ export declare const escapeRegExp: (s: string) => string;
5
+ export declare const generateEntityKey: (url: string, restApiPrefix: string) => string;
@@ -0,0 +1,5 @@
1
+ export declare const loggy: {
2
+ info: (msg: string) => void;
3
+ error: (msg: string) => void;
4
+ warn: (msg: string) => void;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const withTimeout: (callback: () => Promise<any>, ms: number) => Promise<any>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.2",
2
+ "version": "1.8.1",
3
3
  "keywords": [
4
4
  "strapi cache",
5
5
  "strapi rest cache",
@@ -34,7 +34,9 @@
34
34
  "verify": "strapi-plugin verify",
35
35
  "test:ts:front": "run -T tsc -p admin/tsconfig.json",
36
36
  "test:ts:back": "run -T tsc -p server/tsconfig.json",
37
- "test": "vitest"
37
+ "test": "vitest run --exclude 'test/integration/**'",
38
+ "test:integration": "npm run build && rm -rf playground/.cache && mkdir -p playground/.yalc/strapi-cache && cp -r dist package.json LICENSE README.md playground/.yalc/strapi-cache/ && cd playground && npm install && npm run build && cd .. && NODE_ENV=test jest --config jest.integration.config.js --runInBand --forceExit --detectOpenHandles",
39
+ "test:all": "npm test -- --run && npm run test:integration"
38
40
  },
39
41
  "dependencies": {
40
42
  "@strapi/design-system": "^2.0.1",
@@ -48,14 +50,21 @@
48
50
  "@strapi/sdk-plugin": "^5.3.2",
49
51
  "@strapi/strapi": "^5.0.0",
50
52
  "@strapi/typescript-utils": "^5.0.0",
53
+ "@types/jest": "^30.0.0",
51
54
  "@types/koa": "^2.15.0",
52
55
  "@types/react": "^19.1.0",
53
56
  "@types/react-dom": "^19.1.1",
57
+ "@types/supertest": "^6.0.3",
58
+ "better-sqlite3": "^12.6.2",
59
+ "jest": "^30.2.0",
54
60
  "prettier": "^3.5.3",
55
61
  "react": "^18.3.1",
56
62
  "react-dom": "^18.3.1",
57
63
  "react-router-dom": "^6.30.0",
58
64
  "styled-components": "^6.1.17",
65
+ "supertest": "^7.2.2",
66
+ "ts-jest": "^29.4.6",
67
+ "ts-node": "^10.9.2",
59
68
  "typescript": "^5.8.3",
60
69
  "vitest": "^3.1.1"
61
70
  },
@@ -67,6 +76,11 @@
67
76
  "react-router-dom": "^6.30.0",
68
77
  "styled-components": "^6.1.17"
69
78
  },
79
+ "optionalDependencies": {
80
+ "@img/sharp-linux-x64": "*",
81
+ "@rollup/rollup-linux-x64-gnu": "*",
82
+ "@swc/core-linux-x64-gnu": "*"
83
+ },
70
84
  "strapi": {
71
85
  "kind": "plugin",
72
86
  "name": "strapi-cache",