From 4a26b9152c235db6169d80df561539221f7be47a Mon Sep 17 00:00:00 2001 From: pieh Date: Thu, 19 Dec 2024 13:39:22 +0100 Subject: [PATCH] fix: set user agent for purge requests --- package-lock.json | 45 +++++++++----------------------------- package.json | 2 +- src/run/handlers/cache.cts | 19 ++++++++++------ 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4b92aa56..d6e4396a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@netlify/edge-bundler": "^12.2.3", "@netlify/edge-functions": "^2.11.0", "@netlify/eslint-config-node": "^7.0.1", - "@netlify/functions": "^2.8.2", + "@netlify/functions": "^3.0.0", "@netlify/serverless-functions-api": "^1.30.1", "@netlify/zip-it-and-ship-it": "^9.41.0", "@opentelemetry/api": "^1.8.0", @@ -4780,15 +4780,15 @@ } }, "node_modules/@netlify/functions": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-2.8.2.tgz", - "integrity": "sha512-DeoAQh8LuNPvBE4qsKlezjKj0PyXDryOFJfJKo3Z1qZLKzQ21sT314KQKPVjfvw6knqijj+IO+0kHXy/TJiqNA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-3.0.0.tgz", + "integrity": "sha512-XXf9mNw4+fkxUzukDpJtzc32bl1+YlXZwEhc5ZgMcTbJPLpgRLDs5WWSPJ4eY/Mv1ZFvtxmMwmfgoQYVt68Qog==", "dev": true, "dependencies": { - "@netlify/serverless-functions-api": "1.26.1" + "@netlify/serverless-functions-api": "1.30.1" }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" } }, "node_modules/@netlify/functions-utils": { @@ -4805,19 +4805,6 @@ "node": "^14.16.0 || >=16.0.0" } }, - "node_modules/@netlify/functions/node_modules/@netlify/serverless-functions-api": { - "version": "1.26.1", - "resolved": "https://registry.npmjs.org/@netlify/serverless-functions-api/-/serverless-functions-api-1.26.1.tgz", - "integrity": "sha512-q3L9i3HoNfz0SGpTIS4zTcKBbRkxzCRpd169eyiTuk3IwcPC3/85mzLHranlKo2b+HYT0gu37YxGB45aD8A3Tw==", - "dev": true, - "dependencies": { - "@netlify/node-cookies": "^0.1.0", - "urlpattern-polyfill": "8.0.2" - }, - "engines": { - "node": ">=18.0.0" - } - }, "node_modules/@netlify/git-utils": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@netlify/git-utils/-/git-utils-5.1.1.tgz", @@ -39465,24 +39452,12 @@ } }, "@netlify/functions": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-2.8.2.tgz", - "integrity": "sha512-DeoAQh8LuNPvBE4qsKlezjKj0PyXDryOFJfJKo3Z1qZLKzQ21sT314KQKPVjfvw6knqijj+IO+0kHXy/TJiqNA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-3.0.0.tgz", + "integrity": "sha512-XXf9mNw4+fkxUzukDpJtzc32bl1+YlXZwEhc5ZgMcTbJPLpgRLDs5WWSPJ4eY/Mv1ZFvtxmMwmfgoQYVt68Qog==", "dev": true, "requires": { - "@netlify/serverless-functions-api": "1.26.1" - }, - "dependencies": { - "@netlify/serverless-functions-api": { - "version": "1.26.1", - "resolved": "https://registry.npmjs.org/@netlify/serverless-functions-api/-/serverless-functions-api-1.26.1.tgz", - "integrity": "sha512-q3L9i3HoNfz0SGpTIS4zTcKBbRkxzCRpd169eyiTuk3IwcPC3/85mzLHranlKo2b+HYT0gu37YxGB45aD8A3Tw==", - "dev": true, - "requires": { - "@netlify/node-cookies": "^0.1.0", - "urlpattern-polyfill": "8.0.2" - } - } + "@netlify/serverless-functions-api": "1.30.1" } }, "@netlify/functions-utils": { diff --git a/package.json b/package.json index caff8bf29..5c78f70bd 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@netlify/edge-bundler": "^12.2.3", "@netlify/edge-functions": "^2.11.0", "@netlify/eslint-config-node": "^7.0.1", - "@netlify/functions": "^2.8.2", + "@netlify/functions": "^3.0.0", "@netlify/serverless-functions-api": "^1.30.1", "@netlify/zip-it-and-ship-it": "^9.41.0", "@opentelemetry/api": "^1.8.0", diff --git a/src/run/handlers/cache.cts b/src/run/handlers/cache.cts index 69dcd4271..2ec5cb4bb 100644 --- a/src/run/handlers/cache.cts +++ b/src/run/handlers/cache.cts @@ -11,6 +11,7 @@ import { type Span } from '@opentelemetry/api' import type { PrerenderManifest } from 'next/dist/build/index.js' import { NEXT_CACHE_TAGS_HEADER } from 'next/dist/lib/constants.js' +import { name as nextRuntimePkgName, version as nextRuntimePkgVersion } from '../../../package.json' import { type CacheHandlerContext, type CacheHandlerForMultipleVersions, @@ -30,6 +31,8 @@ type TagManifest = { revalidatedAt: number } type TagManifestBlobCache = Record> +const purgeCacheUserAgent = `${nextRuntimePkgName}@${nextRuntimePkgVersion}` + export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions { options: CacheHandlerContext revalidatedTags: string[] @@ -347,12 +350,14 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions { const tag = `_N_T_${key === '/index' ? '/' : encodeURI(key)}` getLogger().debug(`Purging CDN cache for: [${tag}]`) requestContext.trackBackgroundWork( - purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => { - // TODO: add reporting here - getLogger() - .withError(error) - .error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`) - }), + purgeCache({ tags: tag.split(/,|%2c/gi), userAgent: purgeCacheUserAgent }).catch( + (error) => { + // TODO: add reporting here + getLogger() + .withError(error) + .error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`) + }, + ), ) } } @@ -393,7 +398,7 @@ export class NetlifyCacheHandler implements CacheHandlerForMultipleVersions { }), ) - await purgeCache({ tags }).catch((error) => { + await purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => { // TODO: add reporting here getLogger() .withError(error)