diff --git a/package-lock.json b/package-lock.json index 4af37ff02f0..c7c9af8571b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@netlify/build-info": "7.14.0", "@netlify/config": "20.16.0", "@netlify/edge-bundler": "12.2.0", - "@netlify/edge-functions": "2.8.1", + "@netlify/edge-functions": "2.9.0", "@netlify/local-functions-proxy": "1.1.1", "@netlify/zip-it-and-ship-it": "9.37.5", "@octokit/rest": "20.1.1", @@ -3897,9 +3897,9 @@ } }, "node_modules/@netlify/edge-functions": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.8.1.tgz", - "integrity": "sha512-BoAz/gCWHLn9DVugGViORbWFDqaqrB/JHM+9N+ahk7U6C3EwaFojnnGKCMrQ65f2YOi6Wwlue1ZZO+8mq43RZA==" + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.9.0.tgz", + "integrity": "sha512-W1kdwLpvUlhfI2FTOe6SEcoobW7Fw+Vm9WN5Gwb5lTCG6QXBE3gpCZk+NVQ4p/XoOcXYwWAS5pfOTMKUoYNQnA==" }, "node_modules/@netlify/eslint-config-node": { "version": "7.0.1", @@ -26377,9 +26377,9 @@ } }, "@netlify/edge-functions": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.8.1.tgz", - "integrity": "sha512-BoAz/gCWHLn9DVugGViORbWFDqaqrB/JHM+9N+ahk7U6C3EwaFojnnGKCMrQ65f2YOi6Wwlue1ZZO+8mq43RZA==" + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.9.0.tgz", + "integrity": "sha512-W1kdwLpvUlhfI2FTOe6SEcoobW7Fw+Vm9WN5Gwb5lTCG6QXBE3gpCZk+NVQ4p/XoOcXYwWAS5pfOTMKUoYNQnA==" }, "@netlify/eslint-config-node": { "version": "7.0.1", diff --git a/package.json b/package.json index 33d5ee03f0d..95ebe1b4372 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "@netlify/build-info": "7.14.0", "@netlify/config": "20.16.0", "@netlify/edge-bundler": "12.2.0", - "@netlify/edge-functions": "2.8.1", + "@netlify/edge-functions": "2.9.0", "@netlify/local-functions-proxy": "1.1.1", "@netlify/zip-it-and-ship-it": "9.37.5", "@octokit/rest": "20.1.1", diff --git a/src/lib/edge-functions/headers.ts b/src/lib/edge-functions/headers.ts index 6e721c82913..174c2ec286d 100644 --- a/src/lib/edge-functions/headers.ts +++ b/src/lib/edge-functions/headers.ts @@ -3,6 +3,7 @@ import { Buffer } from 'buffer' export const headers = { BlobsInfo: 'x-nf-blobs-info', DeployID: 'x-nf-deploy-id', + DeployContext: 'x-nf-deploy-context', FeatureFlags: 'x-nf-feature-flags', ForwardedHost: 'x-forwarded-host', ForwardedProtocol: 'x-forwarded-proto', diff --git a/src/lib/edge-functions/proxy.ts b/src/lib/edge-functions/proxy.ts index 061274ec661..2e3c52ea014 100644 --- a/src/lib/edge-functions/proxy.ts +++ b/src/lib/edge-functions/proxy.ts @@ -151,6 +151,7 @@ export const initializeProxy = async ({ // Setting header with geolocation and site info. req.headers[headers.Geo] = Buffer.from(JSON.stringify(geoLocation)).toString('base64') req.headers[headers.DeployID] = '0' + req.headers[headers.DeployContext] = 'dev' req.headers[headers.Site] = createSiteInfoHeader(siteInfo, `${protocol}://localhost:${mainPort}`) req.headers[headers.Account] = createAccountInfoHeader({ id: accountId }) diff --git a/tests/integration/commands/dev/dev-miscellaneous.test.js b/tests/integration/commands/dev/dev-miscellaneous.test.js index 5042b154239..f2e45768aaa 100644 --- a/tests/integration/commands/dev/dev-miscellaneous.test.js +++ b/tests/integration/commands/dev/dev-miscellaneous.test.js @@ -238,7 +238,11 @@ describe.concurrent('commands/dev-miscellaneous', () => { }, ]) .withEdgeFunction({ - handler: (req) => new Response(req.headers.get('x-nf-request-id')), + handler: (req, context) => + Response.json({ + requestID: req.headers.get('x-nf-request-id'), + deploy: context.deploy, + }), name: 'hello', }) @@ -246,11 +250,17 @@ describe.concurrent('commands/dev-miscellaneous', () => { await withDevServer({ cwd: builder.directory }, async (server) => { const response = await fetch(`${server.url}/edge-function`) - const responseBody = await response.text() + const responseBody = await response.json() t.expect(response.status).toBe(200) - t.expect(responseBody.length).toBe(26) - t.expect(responseBody).toEqual(response.headers.get('x-nf-request-id')) + t.expect(responseBody).toEqual({ + requestID: response.headers.get('x-nf-request-id'), + deploy: { + context: 'dev', + id: '0', + published: false, + }, + }) }) }) }) @@ -423,7 +433,7 @@ describe.concurrent('commands/dev-miscellaneous', () => { t.expect(response.status).toBe(200) t.expect(JSON.parse(await response.text())).toStrictEqual({ - deploy: { id: '0' }, + deploy: { context: 'dev', id: '0', published: false }, site: { id: 'site_id', name: 'site-name', url: server.url }, }) }, diff --git a/tests/integration/commands/dev/edge-functions.test.ts b/tests/integration/commands/dev/edge-functions.test.ts index 00b65da29d8..6c1b95d1565 100644 --- a/tests/integration/commands/dev/edge-functions.test.ts +++ b/tests/integration/commands/dev/edge-functions.test.ts @@ -77,7 +77,7 @@ describe.skipIf(isWindows)('edge functions', () => { const { deploy, geo, ip, params, requestId, server, site } = await response.json() expect(geo.city).toEqual('Mock City') expect(geo.country.code).toEqual('DE') - expect(deploy).toEqual({ id: '0' }) + expect(deploy).toEqual({ context: 'dev', id: '0', published: false }) expectTypeOf(ip).toBeString() expect(params).toEqual({}) expectTypeOf(requestId).toBeString() diff --git a/tests/integration/commands/dev/v2-api.test.ts b/tests/integration/commands/dev/v2-api.test.ts index e0841387783..931acf10975 100644 --- a/tests/integration/commands/dev/v2-api.test.ts +++ b/tests/integration/commands/dev/v2-api.test.ts @@ -68,10 +68,11 @@ describe.runIf(gte(version, '18.13.0')).concurrent('v2 api', () => { expect(context.server.region).toEqual('dev') expect(context.ip).toEqual('::1') expect(context.geo.city).toEqual('Mock City') - expect(context.cookies).toEqual({ foo: 'bar' }) - expect(context.account.id).toEqual('mock-account-id') + expect(context.deploy.context).toEqual('dev') + expect(context.deploy.id).toEqual('0') + expect(context.deploy.published).toEqual(false) }) test('logging works', async ({ devServer }) => {