Skip to content

Conversation

eduardoboucas
Copy link
Member

@eduardoboucas eduardoboucas commented Aug 3, 2025

Copy link
Contributor

github-actions bot commented Aug 3, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@eduardoboucas eduardoboucas marked this pull request as ready for review August 13, 2025 17:48
@eduardoboucas eduardoboucas requested a review from a team as a code owner August 13, 2025 17:48
serhalp
serhalp previously approved these changes Aug 13, 2025
Copy link
Member

@serhalp serhalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A couple suggestions I think are worthwhile, but feel to fast follow if you prefer.

@@ -8,6 +8,9 @@ export const FRAMEWORKS_API_CONFIG_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/config
export const FRAMEWORKS_API_EDGE_FUNCTIONS_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/edge-functions`
export const FRAMEWORKS_API_EDGE_FUNCTIONS_IMPORT_MAP = 'import_map.json'
export const FRAMEWORKS_API_FUNCTIONS_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/functions`
export const FRAMEWORKS_API_SKEW_PROTECTION_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/skew-protection.json`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is existing naming, but I find endpoint to be a misleading term here (especially since many of these do have very similar URL endpoints). how about "path"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 687a92c.

Comment on lines 34 to 43
try {
const data = await fs.readFile(configPath, 'utf8')
const config = validateSkewProtectionConfig(JSON.parse(data))

return config
} catch (err) {
// If the file doesn't exist, this is a non-error.
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
throw err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are four cases here:

  1. exists + is json + valid
  2. exists + is json + invalid
  3. exists + is not json
  4. does not exist

We're testing 1, 2, and 4. Could we add a test for 3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a4f84c0.

Comment on lines 25 to 26
if (error instanceof z.ZodError) {
throw new Error(`Invalid skew protection configuration: ${error.message}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extend the assertion on the test for this to ensure the message contains actionable information? I think we actually need to read .errors for that: https://zod.dev/basics?id=handling-errors — otherwise we just get a generic validation error(?). Either way, test coverage would be valuable here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a4f84c0.


const validateSkewProtectionConfig = (data: unknown): SkewProtectionConfig => {
try {
return skewProtectionConfigSchema.parse(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could avoid the try-catch and conditional by using safeParse instead: https://zod.dev/basics?id=handling-errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a4f84c0.

@@ -8,6 +8,9 @@ export const FRAMEWORKS_API_CONFIG_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/config
export const FRAMEWORKS_API_EDGE_FUNCTIONS_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/edge-functions`
export const FRAMEWORKS_API_EDGE_FUNCTIONS_IMPORT_MAP = 'import_map.json'
export const FRAMEWORKS_API_FUNCTIONS_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/functions`
export const FRAMEWORKS_API_SKEW_PROTECTION_ENDPOINT = `${FRAMEWORKS_API_ENDPOINT}/skew-protection.json`

export const EDGE_REDIRECTS_DIST_PATH = '.netlify/deploy-config/edge-redirects.json'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found any trace of this in Linear, Notion, or Slack, but it seems to have been around for years in nfserver? Is this dead code we're reviving from the partially implemented and partially reverted edge redirects project from 2023...?

In any case, I'm not quite following what Skew Protection has to do with edge redirects. Would you mind explaining?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in cadd32d.

serhalp
serhalp previously approved these changes Aug 14, 2025
Copy link
Member

@serhalp serhalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@eduardoboucas eduardoboucas merged commit 6cf3065 into main Aug 14, 2025
95 of 98 checks passed
@eduardoboucas eduardoboucas deleted the eduardo/run-1845-add-frameworks-api-entry-point branch August 14, 2025 14:23
This was referenced Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants