diff --git a/packages/config/src/edge_functions.ts b/packages/config/src/edge_functions.ts index 3b70a03ece..c98c031d73 100644 --- a/packages/config/src/edge_functions.ts +++ b/packages/config/src/edge_functions.ts @@ -1,11 +1,14 @@ import { isString, validProperties } from './validate/helpers.js' const cacheValues = ['manual', 'off'] +const methodValues = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'] + +const isMethod = (value: unknown) => typeof value === 'string' && methodValues.includes(value.toUpperCase()) export const validations = [ { property: 'edge_functions.*', - ...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache'], []), + ...validProperties(['path', 'excludedPath', 'pattern', 'excludedPattern', 'function', 'cache', 'method'], []), example: () => ({ edge_functions: [{ path: '/hello', function: 'hello' }] }), }, { @@ -78,4 +81,10 @@ export const validations = [ message: `must be one of: ${cacheValues.join(', ')}`, example: () => ({ edge_functions: [{ cache: cacheValues[0], path: '/hello', function: 'hello' }] }), }, + { + property: 'edge_functions.*.method', + check: (value) => isMethod(value) || (Array.isArray(value) && value.length !== 0 && value.every(isMethod)), + message: `must be one of or array of: ${methodValues.join(', ')}`, + example: () => ({ edge_functions: [{ method: ['PUT', 'DELETE'], path: '/hello', function: 'hello' }] }), + }, ] diff --git a/packages/config/tests/validate/fixtures/edge_functions_method_disallowed/netlify.toml b/packages/config/tests/validate/fixtures/edge_functions_method_disallowed/netlify.toml new file mode 100644 index 0000000000..380561cce2 --- /dev/null +++ b/packages/config/tests/validate/fixtures/edge_functions_method_disallowed/netlify.toml @@ -0,0 +1,4 @@ +[[edge_functions]] +function = "function2" +path = "/function2" +method = ["GET", "HEAD"] diff --git a/packages/config/tests/validate/snapshots/tests.js.md b/packages/config/tests/validate/snapshots/tests.js.md index 0eec14299b..7e3c9871a0 100644 --- a/packages/config/tests/validate/snapshots/tests.js.md +++ b/packages/config/tests/validate/snapshots/tests.js.md @@ -1518,6 +1518,7 @@ Generated by [AVA](https://avajs.dev). - excludedPattern␊ - function␊ - cache␊ + - method␊ ␊ Invalid syntax␊ ␊ @@ -1812,3 +1813,28 @@ Generated by [AVA](https://avajs.dev). cache = "manual"␊ path = "/external/path"␊ function = "hello"` + +## edge_functions.any.method: disallowed values + +> Snapshot 1 + + `When resolving config file packages/config/tests/validate/fixtures/edge_functions_method_disallowed/netlify.toml:␊ + Configuration property edge_functions[0].method must be one of or array of: GET, POST, PUT, PATCH, DELETE, OPTIONS␊ + ␊ + Invalid syntax␊ + ␊ + [[edge_functions]]␊ + method = [␊ + "GET",␊ + "HEAD"␊ + ]␊ + ␊ + Valid syntax␊ + ␊ + [[edge_functions]]␊ + method = [␊ + "PUT",␊ + "DELETE"␊ + ]␊ + path = "/external/path"␊ + function = "hello"` diff --git a/packages/config/tests/validate/snapshots/tests.js.snap b/packages/config/tests/validate/snapshots/tests.js.snap index 6d0918197f..fbd5c08412 100644 Binary files a/packages/config/tests/validate/snapshots/tests.js.snap and b/packages/config/tests/validate/snapshots/tests.js.snap differ diff --git a/packages/config/tests/validate/tests.js b/packages/config/tests/validate/tests.js index 8508b170d3..d579cefdc7 100644 --- a/packages/config/tests/validate/tests.js +++ b/packages/config/tests/validate/tests.js @@ -315,3 +315,8 @@ test('edge_functions.any.mode: disallowed values', async (t) => { const output = await new Fixture('./fixtures/edge_functions_mode_disallowed').runWithConfig() t.snapshot(normalizeOutput(output)) }) + +test('edge_functions.any.method: disallowed values', async (t) => { + const output = await new Fixture('./fixtures/edge_functions_method_disallowed').runWithConfig() + t.snapshot(normalizeOutput(output)) +})