@netlify/cache
Advanced tools
@@ -46,3 +46,17 @@ "use strict"; | ||
| // src/bootstrap/errors.ts | ||
| var ERROR_CODES = { | ||
| invalid_vary: "Responses must not use unsupported directives of the `Netlify-Vary` header (https://ntl.fyi/cache_api_invalid_vary).", | ||
| no_cache: "Responses must not set cache control headers with the `private`, `no-cache` or `no-store` directives (https://ntl.fyi/cache_api_no_cache).", | ||
| low_ttl: "Responses must have a cache control header with a `max-age` or `s-maxage` directive (https://ntl.fyi/cache_api_low_ttl).", | ||
| no_directive: "Responses must have a cache control header with caching directives (https://ntl.fyi/cache_api_no_directive).", | ||
| no_ttl: "Responses must have a cache control header with a `max-age` or `s-maxage` directive (https://ntl.fyi/cache_api_no_ttl).", | ||
| no_status: "Responses must specify a status code (https://ntl.fyi/cache_api_no_status).", | ||
| invalid_directive: "Responses must have a cache control header with caching directives (https://ntl.fyi/cache_api_invalid_directive).", | ||
| status: "Responses must have a status code between 200 and 299 (https://ntl.fyi/cache_api_status)." | ||
| }; | ||
| var GENERIC_ERROR = "The server has returned an unexpected error (https://ntl.fyi/cache_api_error)."; | ||
| // src/headers.ts | ||
| var ErrorDetail = "netlify-programmable-error"; | ||
| var ResourceHeaders = "netlify-programmable-headers"; | ||
@@ -159,3 +173,3 @@ var ResourceStatus = "netlify-programmable-status"; | ||
| const resourceURL = extractAndValidateURL(request); | ||
| await fetch(`${context.url}/${toCacheKey(resourceURL)}`, { | ||
| const cacheResponse = await fetch(`${context.url}/${toCacheKey(resourceURL)}`, { | ||
| body: response.body, | ||
@@ -171,2 +185,7 @@ headers: { | ||
| }); | ||
| if (!cacheResponse.ok) { | ||
| const errorDetail = cacheResponse.headers.get(ErrorDetail) ?? ""; | ||
| const errorMessage = ERROR_CODES[errorDetail] || GENERIC_ERROR; | ||
| console.warn(`Failed to write to the cache: ${errorMessage}`); | ||
| } | ||
| } | ||
@@ -173,0 +192,0 @@ }; |
+45
-11
@@ -1,12 +0,41 @@ | ||
| import { | ||
| NetlifyForwardedHost, | ||
| ResourceHeaders, | ||
| ResourceStatus, | ||
| ResourceStore, | ||
| UserAgent, | ||
| __privateAdd, | ||
| __privateGet, | ||
| __privateSet | ||
| } from "../chunk-I5FZDZ6V.js"; | ||
| var __accessCheck = (obj, member, msg) => { | ||
| if (!member.has(obj)) | ||
| throw TypeError("Cannot " + msg); | ||
| }; | ||
| var __privateGet = (obj, member, getter) => { | ||
| __accessCheck(obj, member, "read from private field"); | ||
| return getter ? getter.call(obj) : member.get(obj); | ||
| }; | ||
| var __privateAdd = (obj, member, value) => { | ||
| if (member.has(obj)) | ||
| throw TypeError("Cannot add the same private member more than once"); | ||
| member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| }; | ||
| var __privateSet = (obj, member, value, setter) => { | ||
| __accessCheck(obj, member, "write to private field"); | ||
| setter ? setter.call(obj, value) : member.set(obj, value); | ||
| return value; | ||
| }; | ||
| // src/bootstrap/errors.ts | ||
| var ERROR_CODES = { | ||
| invalid_vary: "Responses must not use unsupported directives of the `Netlify-Vary` header (https://ntl.fyi/cache_api_invalid_vary).", | ||
| no_cache: "Responses must not set cache control headers with the `private`, `no-cache` or `no-store` directives (https://ntl.fyi/cache_api_no_cache).", | ||
| low_ttl: "Responses must have a cache control header with a `max-age` or `s-maxage` directive (https://ntl.fyi/cache_api_low_ttl).", | ||
| no_directive: "Responses must have a cache control header with caching directives (https://ntl.fyi/cache_api_no_directive).", | ||
| no_ttl: "Responses must have a cache control header with a `max-age` or `s-maxage` directive (https://ntl.fyi/cache_api_no_ttl).", | ||
| no_status: "Responses must specify a status code (https://ntl.fyi/cache_api_no_status).", | ||
| invalid_directive: "Responses must have a cache control header with caching directives (https://ntl.fyi/cache_api_invalid_directive).", | ||
| status: "Responses must have a status code between 200 and 299 (https://ntl.fyi/cache_api_status)." | ||
| }; | ||
| var GENERIC_ERROR = "The server has returned an unexpected error (https://ntl.fyi/cache_api_error)."; | ||
| // src/headers.ts | ||
| var ErrorDetail = "netlify-programmable-error"; | ||
| var ResourceHeaders = "netlify-programmable-headers"; | ||
| var ResourceStatus = "netlify-programmable-status"; | ||
| var ResourceStore = "netlify-programmable-store"; | ||
| var NetlifyForwardedHost = "netlify-forwarded-host"; | ||
| var UserAgent = "user-agent"; | ||
| // src/bootstrap/cache.ts | ||
@@ -117,3 +146,3 @@ var allowedProtocols = /* @__PURE__ */ new Set(["http:", "https:"]); | ||
| const resourceURL = extractAndValidateURL(request); | ||
| await fetch(`${context.url}/${toCacheKey(resourceURL)}`, { | ||
| const cacheResponse = await fetch(`${context.url}/${toCacheKey(resourceURL)}`, { | ||
| body: response.body, | ||
@@ -129,2 +158,7 @@ headers: { | ||
| }); | ||
| if (!cacheResponse.ok) { | ||
| const errorDetail = cacheResponse.headers.get(ErrorDetail) ?? ""; | ||
| const errorMessage = ERROR_CODES[errorDetail] || GENERIC_ERROR; | ||
| console.warn(`Failed to write to the cache: ${errorMessage}`); | ||
| } | ||
| } | ||
@@ -131,0 +165,0 @@ }; |
+6
-7
@@ -1,8 +0,7 @@ | ||
| import { | ||
| CacheStatus, | ||
| NetlifyCacheId, | ||
| NetlifyCacheTag, | ||
| NetlifyCdnCacheControl, | ||
| NetlifyVary | ||
| } from "./chunk-I5FZDZ6V.js"; | ||
| // src/headers.ts | ||
| var CacheStatus = "cache-status"; | ||
| var NetlifyCacheId = "netlify-cache-id"; | ||
| var NetlifyCacheTag = "netlify-cache-tag"; | ||
| var NetlifyCdnCacheControl = "netlify-cdn-cache-control"; | ||
| var NetlifyVary = "netlify-vary"; | ||
@@ -9,0 +8,0 @@ // src/cache-headers/validation.ts |
+1
-1
| { | ||
| "name": "@netlify/cache", | ||
| "version": "1.4.0", | ||
| "version": "1.5.0", | ||
| "description": "TypeScript utilities for interacting with the Netlify cache", | ||
@@ -5,0 +5,0 @@ "type": "module", |
| var __accessCheck = (obj, member, msg) => { | ||
| if (!member.has(obj)) | ||
| throw TypeError("Cannot " + msg); | ||
| }; | ||
| var __privateGet = (obj, member, getter) => { | ||
| __accessCheck(obj, member, "read from private field"); | ||
| return getter ? getter.call(obj) : member.get(obj); | ||
| }; | ||
| var __privateAdd = (obj, member, value) => { | ||
| if (member.has(obj)) | ||
| throw TypeError("Cannot add the same private member more than once"); | ||
| member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| }; | ||
| var __privateSet = (obj, member, value, setter) => { | ||
| __accessCheck(obj, member, "write to private field"); | ||
| setter ? setter.call(obj, value) : member.set(obj, value); | ||
| return value; | ||
| }; | ||
| // src/headers.ts | ||
| var CacheStatus = "cache-status"; | ||
| var NetlifyCacheId = "netlify-cache-id"; | ||
| var NetlifyCacheTag = "netlify-cache-tag"; | ||
| var NetlifyCdnCacheControl = "netlify-cdn-cache-control"; | ||
| var NetlifyVary = "netlify-vary"; | ||
| var ResourceHeaders = "netlify-programmable-headers"; | ||
| var ResourceStatus = "netlify-programmable-status"; | ||
| var ResourceStore = "netlify-programmable-store"; | ||
| var NetlifyForwardedHost = "netlify-forwarded-host"; | ||
| var UserAgent = "user-agent"; | ||
| export { | ||
| __privateGet, | ||
| __privateAdd, | ||
| __privateSet, | ||
| CacheStatus, | ||
| NetlifyCacheId, | ||
| NetlifyCacheTag, | ||
| NetlifyCdnCacheControl, | ||
| NetlifyVary, | ||
| ResourceHeaders, | ||
| ResourceStatus, | ||
| ResourceStore, | ||
| NetlifyForwardedHost, | ||
| UserAgent | ||
| }; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
53832
4.75%1288
0.39%12
-7.69%2
100%