Skip to content

feat(lambda): add support to purge in two zones#79

Merged
tomski747 merged 1 commit intomainfrom
daniel/add-purge-for-second-cf-zone
Sep 10, 2025
Merged

feat(lambda): add support to purge in two zones#79
tomski747 merged 1 commit intomainfrom
daniel/add-purge-for-second-cf-zone

Conversation

@newman-dani
Copy link
Member

Description

This pull request adds support for purging cache in multiple Cloudflare zones and improves error handling and test coverage for the cache purging logic. The main changes include refactoring the handler to support dual zone purging, updating error reporting to handle partial failures, and expanding the test suite to cover these new scenarios.

Dual zone cache purging:

  • Refactored the handler in src/index.ts to support purging cache in two Cloudflare zones if both CLOUDFLARE_ZONE_ID_2 and BASE_URL_2 environment variables are set. The handler now iterates over all configured zones and purges cache for each. [1] [2]

  • Updated error handling in src/index.ts so that if cache purging fails in any zone, the error message specifies which zone(s) failed and why, instead of throwing a generic error.

Test coverage improvements:

  • Added new tests in tests/index.test.ts to verify dual zone purging, partial failures (where one zone succeeds and another fails), and scenarios where only one zone is configured.

  • Updated environment variable cleanup in test setup to include the new zone variables, ensuring test isolation.

Minor update:

  • Updated the S3 object key in events/event.json to reflect a new test case.

Must

  • Tests
  • Documentation (if applicable)

@ghost
Copy link

ghost commented Sep 10, 2025

Wiz Scan Summary

Displaying only findings that violated a policy

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data 1 Info
Total 1 Info

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for purging cache in multiple Cloudflare zones within a Lambda function, allowing the handler to work with both primary and secondary zones when configured. The implementation includes improved error handling that provides detailed feedback about which zones failed during cache purging operations.

Key changes:

  • Enhanced handler to support dual zone purging when both CLOUDFLARE_ZONE_ID_2 and BASE_URL_2 environment variables are set
  • Updated error handling to report specific zone failures instead of generic connection errors
  • Expanded test coverage to verify dual zone functionality, partial failures, and single zone configurations

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/index.ts Refactored handler to support multiple zones with improved error reporting
tests/index.test.ts Added comprehensive test coverage for dual zone scenarios and updated existing tests
events/event.json Minor update to S3 object key for testing purposes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@tomski747 tomski747 enabled auto-merge (squash) September 10, 2025 09:38
@tomski747 tomski747 merged commit f556370 into main Sep 10, 2025
9 checks passed
@tomski747 tomski747 deleted the daniel/add-purge-for-second-cf-zone branch September 10, 2025 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants