Currently, the logic for processing and normalizing link keys (handling case-sensitivity, + for inspection, and punycode) is duplicated across several files. This creates maintenance overhead and potential inconsistencies between the redirect middleware and the API.
Files to address:
apps/web/lib/middleware/link.ts
apps/web/lib/api/links/utils/process-key.ts
Proposed Solution:
- Extract the normalization logic into a pure function in packages/utils.
- This function should handle:
- punycode encoding/decoding.
- Case normalization based on the domain's caseSensitive setting.
- Stripping the + suffix used for info pages.
- Update all call sites to use this shared utility.
Currently, the logic for processing and normalizing link keys (handling case-sensitivity, + for inspection, and punycode) is duplicated across several files. This creates maintenance overhead and potential inconsistencies between the redirect middleware and the API.
Files to address:
apps/web/lib/middleware/link.ts
apps/web/lib/api/links/utils/process-key.ts
Proposed Solution: