@lidofinance/next-cache-files-middleware 0.29.0 → 0.31.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/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,7 @@ const $db38a4f6de2a3704$var$checkValueIsString = (value)=>{
|
|
|
90
90
|
return value !== null && typeof value === "string";
|
|
91
91
|
};
|
|
92
92
|
const $db38a4f6de2a3704$export$2cbb5ba6d79dc635 = (data)=>{
|
|
93
|
-
const { allowedList: allowedList
|
|
93
|
+
const { allowedList: allowedList, url: url } = data;
|
|
94
94
|
const requestPath = url?.split("?")[0];
|
|
95
95
|
if (!requestPath) return;
|
|
96
96
|
const cacheValue = $db38a4f6de2a3704$var$cache.get(requestPath);
|
|
@@ -99,7 +99,7 @@ const $db38a4f6de2a3704$export$2cbb5ba6d79dc635 = (data)=>{
|
|
|
99
99
|
...(0, $5d01ba631015e899$export$a0fb92f5bd6f13d2),
|
|
100
100
|
...allowedList || []
|
|
101
101
|
];
|
|
102
|
-
const urlHeaders = list.find(({ path: path
|
|
102
|
+
const urlHeaders = list.find(({ path: path })=>{
|
|
103
103
|
if ($db38a4f6de2a3704$var$checkValueIsString(path)) return path === requestPath;
|
|
104
104
|
return path.test(requestPath);
|
|
105
105
|
})?.headers;
|
|
@@ -110,7 +110,7 @@ const $db38a4f6de2a3704$export$2cbb5ba6d79dc635 = (data)=>{
|
|
|
110
110
|
|
|
111
111
|
const $9295f689042d9f46$export$772f11b002f0df57 = (allowedList)=>(req)=>{
|
|
112
112
|
const response = (0, $2Aiq4$nextserver.NextResponse).next();
|
|
113
|
-
const { pathname: pathname
|
|
113
|
+
const { pathname: pathname } = req.nextUrl;
|
|
114
114
|
// Use allowed list
|
|
115
115
|
const headers = (0, $db38a4f6de2a3704$export$2cbb5ba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B,CAAC;IAI1C,MAAM,eAAE,WAAW,OAAE,GAAG,EAAE,GAAG;IAC7B,MAAM,cAAc,KAAK,MAAM,IAAI,CAAC,EAAE;IAEtC,IAAI,CAAC,aAAa;IAElB,MAAM,aAAa,4BAAM,IAAI;IAC7B,IAAI,YAAY,OAAO;IAEvB,MAAM,OAAO;WAAI,CAAA,GAAA,yCAA6B;WAAO,eAAe,EAAE;KAAE;IAExE,MAAM,aAAa,KAAK,KAAK,CAAC,QAAE,IAAI,EAAE;QACpC,IAAI,yCAAmB,OAAO,OAAO,SAAS;QAC9C,OAAO,KAAK,KAAK;IACnB,IAAI;IACJ,IAAI,YAAY,4BAAM,IAAI,aAAa;IAEvC,OAAO;AACT;;;ADzBO,MAAM,4CACX,CAAC,cACD,CAAC;QACC,MAAM,WAAW,CAAA,GAAA,8BAAW,EAAE;QAC9B,MAAM,YAAE,QAAQ,EAAE,GAAG,IAAI;QAEzB,mBAAmB;QACnB,MAAM,UAAU,CAAA,GAAA,yCAA0B,EAAE;yBAAE;YAAa,KAAK;QAAS;QACzE,IAAI,CAAC,SAAS,OAAO;QAErB,SAAS,QAAQ,OAAO,iBAAiB;QAEzC,OAAO;IACT;AAEK,MAAM,2CACX,CAAC,cACD,CAAC,OACD,CAAC;YACC,MAAM,WAAW,0CAA8B,aAAa;YAE5D,OAAO,KAAK,KAAK;QACnB;;;;;;;","sources":["packages/next/cache-files-middleware/src/index.ts","packages/next/cache-files-middleware/src/middleware.ts","packages/next/cache-files-middleware/src/utils.ts","packages/next/cache-files-middleware/src/cache.ts","packages/next/cache-files-middleware/src/constants.ts","packages/next/cache-files-middleware/src/types.ts"],"sourcesContent":["export * from './middleware'\nexport * from './utils'\nexport * from './constants'\nexport * from './types'\nexport * from './cache'\n","import { NextResponse } from 'next/server'\nimport type { NextRequest } from 'next/server'\nimport { findCacheControlFileHeaders } from './utils'\nimport { CacheAllowedItem } from './types'\n\n// use only for cache files\nexport const cacheControlMiddlewareFactory =\n (allowedList?: CacheAllowedItem[]) =>\n (req: NextRequest): NextResponse => {\n const response = NextResponse.next()\n const { pathname } = req.nextUrl\n\n // Use allowed list\n const headers = findCacheControlFileHeaders({ allowedList, url: pathname })\n if (!headers) return response\n\n response.headers.append('Cache-Control', headers)\n\n return response\n }\n\nexport const cacheControlMiddlewareWrapper =\n (allowedList?: CacheAllowedItem[]) =>\n (next: (req: NextRequest, res: NextResponse) => NextResponse) =>\n (req: NextRequest): NextResponse => {\n const response = cacheControlMiddlewareFactory(allowedList)(req)\n\n return next(req, response)\n }\n","import { CacheStorage } from './cache'\nimport { CACHE_ALLOWED_LIST_FILES_PATHS } from './constants'\nimport { CacheAllowedItem } from './types'\n\nconst cache = new CacheStorage()\n\nconst checkValueIsString = (value: unknown): value is string => {\n return value !== null && typeof value === 'string'\n}\n\nexport const findCacheControlFileHeaders = (data: {\n allowedList?: CacheAllowedItem[]\n url?: string\n}): string | undefined => {\n const { allowedList, url } = data\n const requestPath = url?.split('?')[0]\n\n if (!requestPath) return\n\n const cacheValue = cache.get(requestPath)\n if (cacheValue) return cacheValue\n\n const list = [...CACHE_ALLOWED_LIST_FILES_PATHS, ...(allowedList || [])]\n\n const urlHeaders = list.find(({ path }) => {\n if (checkValueIsString(path)) return path === requestPath\n return path.test(requestPath)\n })?.headers\n if (urlHeaders) cache.set(requestPath, urlHeaders)\n\n return urlHeaders\n}\n","const DEFAULT_CACHE_LIMIT = 1000\n\nexport class CacheStorage {\n private _storage: Map<string, string>\n private _cacheLimit: number\n\n constructor(limit?: number) {\n this._cacheLimit = limit || DEFAULT_CACHE_LIMIT\n this._storage = new Map<string, string>()\n }\n\n set(key: string, value: string) {\n // refresh key\n if (this._storage.has(key)) this._storage.delete(key)\n // delete oldest\n else if (this._storage.size == this._cacheLimit) this._storage.delete(this.getFirst())\n\n this._storage.set(key, value)\n }\n\n get(key: string) {\n const item = this._storage.get(key)\n if (item) {\n // refresh key\n this._storage.delete(key)\n this._storage.set(key, item)\n }\n\n return item\n }\n\n delete(key: string) {\n if (this._storage.has(key)) {\n this._storage.delete(key)\n }\n }\n\n getFirst() {\n return this._storage.keys().next().value as string\n }\n}\n","import { CacheAllowedItem } from './types'\n\nexport const CACHE_FILE_DEFAULT_HEADERS = 'public, max-age=180, stale-if-error=1200, stale-while-revalidate=60'\n\nexport const CACHE_ALLOWED_LIST_FILES_PATHS: CacheAllowedItem[] = [\n { path: /^\\/favicon-?[^@]*.(svg|ico)?$/, headers: CACHE_FILE_DEFAULT_HEADERS },\n { path: '/manifest.json', headers: CACHE_FILE_DEFAULT_HEADERS },\n]\n\n// It is example.\n// Note: The matcher values need to be constants so they can be statically analyzed at build-time.\n// Dynamic values such as variables will be ignored.\nexport const exampleMiddlewareConfig = {\n // paths where use middleware\n matcher: ['/manifest.json', '/favicon:size*'],\n}\n","export type CacheAllowedItem = {\n path: RegExp | string\n headers: string\n}\n"],"names":[],"version":3,"file":"index.cjs.map"}
|
package/dist/index.mjs
CHANGED
|
@@ -74,7 +74,7 @@ const $43f369dac868c8fa$var$checkValueIsString = (value)=>{
|
|
|
74
74
|
return value !== null && typeof value === "string";
|
|
75
75
|
};
|
|
76
76
|
const $43f369dac868c8fa$export$2cbb5ba6d79dc635 = (data)=>{
|
|
77
|
-
const { allowedList: allowedList
|
|
77
|
+
const { allowedList: allowedList, url: url } = data;
|
|
78
78
|
const requestPath = url?.split("?")[0];
|
|
79
79
|
if (!requestPath) return;
|
|
80
80
|
const cacheValue = $43f369dac868c8fa$var$cache.get(requestPath);
|
|
@@ -83,7 +83,7 @@ const $43f369dac868c8fa$export$2cbb5ba6d79dc635 = (data)=>{
|
|
|
83
83
|
...(0, $7d49ed295294e3c0$export$a0fb92f5bd6f13d2),
|
|
84
84
|
...allowedList || []
|
|
85
85
|
];
|
|
86
|
-
const urlHeaders = list.find(({ path: path
|
|
86
|
+
const urlHeaders = list.find(({ path: path })=>{
|
|
87
87
|
if ($43f369dac868c8fa$var$checkValueIsString(path)) return path === requestPath;
|
|
88
88
|
return path.test(requestPath);
|
|
89
89
|
})?.headers;
|
|
@@ -94,7 +94,7 @@ const $43f369dac868c8fa$export$2cbb5ba6d79dc635 = (data)=>{
|
|
|
94
94
|
|
|
95
95
|
const $b299b3c58bd52b75$export$772f11b002f0df57 = (allowedList)=>(req)=>{
|
|
96
96
|
const response = (0, $eTMD6$NextResponse).next();
|
|
97
|
-
const { pathname: pathname
|
|
97
|
+
const { pathname: pathname } = req.nextUrl;
|
|
98
98
|
// Use allowed list
|
|
99
99
|
const headers = (0, $43f369dac868c8fa$export$2cbb5ba6d79dc635)({
|
|
100
100
|
allowedList: allowedList,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AGAA,MAAM,4CAAsB;AAErB,MAAM;IAIX,YAAY,KAAc,CAAE;QAC1B,IAAI,CAAC,cAAc,SAAS;QAC5B,IAAI,CAAC,WAAW,IAAI;IACtB;IAEA,IAAI,GAAW,EAAE,KAAa,EAAE;QAC9B,cAAc;QACd,IAAI,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,CAAC,SAAS,OAAO;aAE5C,IAAI,IAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC;QAE3E,IAAI,CAAC,SAAS,IAAI,KAAK;IACzB;IAEA,IAAI,GAAW,EAAE;QACf,MAAM,OAAO,IAAI,CAAC,SAAS,IAAI;QAC/B,IAAI,MAAM;YACR,cAAc;YACd,IAAI,CAAC,SAAS,OAAO;YACrB,IAAI,CAAC,SAAS,IAAI,KAAK;QACzB;QAEA,OAAO;IACT;IAEA,OAAO,GAAW,EAAE;QAClB,IAAI,IAAI,CAAC,SAAS,IAAI,MACpB,IAAI,CAAC,SAAS,OAAO;IAEzB;IAEA,WAAW;QACT,OAAO,IAAI,CAAC,SAAS,OAAO,OAAO;IACrC;AACF;;;;;;;;ACtCO,MAAM,4CAA6B;AAEnC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/cache-files-middleware/src/utils.ts","packages/next/cache-files-middleware/src/cache.ts","packages/next/cache-files-middleware/src/constants.ts","packages/next/cache-files-middleware/src/types.ts"],"sourcesContent":["export * from './middleware'\nexport * from './utils'\nexport * from './constants'\nexport * from './types'\nexport * from './cache'\n","import { NextResponse } from 'next/server'\nimport type { NextRequest } from 'next/server'\nimport { findCacheControlFileHeaders } from './utils'\nimport { CacheAllowedItem } from './types'\n\n// use only for cache files\nexport const cacheControlMiddlewareFactory =\n (allowedList?: CacheAllowedItem[]) =>\n (req: NextRequest): NextResponse => {\n const response = NextResponse.next()\n const { pathname } = req.nextUrl\n\n // Use allowed list\n const headers = findCacheControlFileHeaders({ allowedList, url: pathname })\n if (!headers) return response\n\n response.headers.append('Cache-Control', headers)\n\n return response\n }\n\nexport const cacheControlMiddlewareWrapper =\n (allowedList?: CacheAllowedItem[]) =>\n (next: (req: NextRequest, res: NextResponse) => NextResponse) =>\n (req: NextRequest): NextResponse => {\n const response = cacheControlMiddlewareFactory(allowedList)(req)\n\n return next(req, response)\n }\n","import { CacheStorage } from './cache'\nimport { CACHE_ALLOWED_LIST_FILES_PATHS } from './constants'\nimport { CacheAllowedItem } from './types'\n\nconst cache = new CacheStorage()\n\nconst checkValueIsString = (value: unknown): value is string => {\n return value !== null && typeof value === 'string'\n}\n\nexport const findCacheControlFileHeaders = (data: {\n allowedList?: CacheAllowedItem[]\n url?: string\n}): string | undefined => {\n const { allowedList, url } = data\n const requestPath = url?.split('?')[0]\n\n if (!requestPath) return\n\n const cacheValue = cache.get(requestPath)\n if (cacheValue) return cacheValue\n\n const list = [...CACHE_ALLOWED_LIST_FILES_PATHS, ...(allowedList || [])]\n\n const urlHeaders = list.find(({ path }) => {\n if (checkValueIsString(path)) return path === requestPath\n return path.test(requestPath)\n })?.headers\n if (urlHeaders) cache.set(requestPath, urlHeaders)\n\n return urlHeaders\n}\n","const DEFAULT_CACHE_LIMIT = 1000\n\nexport class CacheStorage {\n private _storage: Map<string, string>\n private _cacheLimit: number\n\n constructor(limit?: number) {\n this._cacheLimit = limit || DEFAULT_CACHE_LIMIT\n this._storage = new Map<string, string>()\n }\n\n set(key: string, value: string) {\n // refresh key\n if (this._storage.has(key)) this._storage.delete(key)\n // delete oldest\n else if (this._storage.size == this._cacheLimit) this._storage.delete(this.getFirst())\n\n this._storage.set(key, value)\n }\n\n get(key: string) {\n const item = this._storage.get(key)\n if (item) {\n // refresh key\n this._storage.delete(key)\n this._storage.set(key, item)\n }\n\n return item\n }\n\n delete(key: string) {\n if (this._storage.has(key)) {\n this._storage.delete(key)\n }\n }\n\n getFirst() {\n return this._storage.keys().next().value as string\n }\n}\n","import { CacheAllowedItem } from './types'\n\nexport const CACHE_FILE_DEFAULT_HEADERS = 'public, max-age=180, stale-if-error=1200, stale-while-revalidate=60'\n\nexport const CACHE_ALLOWED_LIST_FILES_PATHS: CacheAllowedItem[] = [\n { path: /^\\/favicon-?[^@]*.(svg|ico)?$/, headers: CACHE_FILE_DEFAULT_HEADERS },\n { path: '/manifest.json', headers: CACHE_FILE_DEFAULT_HEADERS },\n]\n\n// It is example.\n// Note: The matcher values need to be constants so they can be statically analyzed at build-time.\n// Dynamic values such as variables will be ignored.\nexport const exampleMiddlewareConfig = {\n // paths where use middleware\n matcher: ['/manifest.json', '/favicon:size*'],\n}\n","export type CacheAllowedItem = {\n path: RegExp | string\n headers: string\n}\n"],"names":[],"version":3,"file":"index.mjs.map"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Next middleware for cache files",
|
|
4
4
|
"repository": "git@github.com:lidofinance/warehouse.git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.31.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"next": "^12.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@lidofinance/config-prettier": "~0.
|
|
29
|
+
"@lidofinance/config-prettier": "~0.31.0",
|
|
30
30
|
"@types/jest": "^29.2.4",
|
|
31
31
|
"@types/node": "^18.11.17",
|
|
32
32
|
"jest": "^29.3.1",
|