Skip to content

Conversation

@hodanoori
Copy link
Contributor

@hodanoori hodanoori commented Feb 9, 2026

Summary

Route search validation no longer relies on Zod’s ctx.path in z.preprocess (removed in Zod v4). A small helper filters URL search params by known keys and allowed prefixes before parsing with Zod, so the same behavior works with Zod v3 and v4. Upgraded Zod from v3 to v4 (exact version 4.3.6).

Changes Made

  1. Added filterSearchParamsByPrefix(raw, knownKeys, allowedPrefixes) in heureka (utils.ts), supernova (lib/utils.ts), doop (lib/helpers.ts), and greenhouse (lib/helpers.ts).
  2. Updated heureka /services and /vulnerabilities routes to validate search via the helper + schema (no preprocess using ctx.path).
  3. Updated supernova /alerts route to use the helper with ACTIVE_FILTERS_PREFIX and PAUSED_FILTERS_PREFIX.
  4. Updated doop /violations route to use the helper with ACTIVE_FILTERS_PREFIX.
  5. Updated greenhouse /admin/plugin-presets route to use the helper with SELECTED_FILTER_PREFIX (Zod v4–compatible).
  6. Typed supernova getFiltersForUrl as Record<string, string | string[]> and adjusted implementation so search param types align with the route schema.
  7. Removed unnecessary type assertions in carbon ErrorFallback (use instanceof Error and fallback for empty message) and in doop/supernova validate-search return values.
  8. Upgraded Zod from v3 to v4 (exact version 4.3.6); route search validation uses filterSearchParamsByPrefix instead of ctx.path.

Related Issues

Screenshots (if applicable)

none

Testing Instructions

  1. pnpm i
  2. pnpm TASK

Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • My changes generate no new warnings or errors.
  • I have created a changeset for my changes.

PR Manifesto

Review the PR Manifesto for best practises.

@hodanoori hodanoori requested a review from a team as a code owner February 9, 2026 16:01
@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2026

⚠️ No Changeset found

Latest commit: 8b965c4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hodanoori hodanoori self-assigned this Feb 9, 2026
@hodanoori hodanoori changed the title Hoda upgrade zod v4 chore(greenhouse): makes route search validation Zod v4–ready (filter by prefix before parse) Feb 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

PR Preview Action v1.6.3

🚀 View preview at
https://cloudoperators.github.io/juno/pr-preview/pr-1446/

Built to branch gh-pages at 2026-02-11 08:50 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@hodanoori hodanoori changed the title chore(greenhouse): makes route search validation Zod v4–ready (filter by prefix before parse) chore(greenhouse): makes route search validation Zod v4–ready (filter by prefix before parse) and upgrade zod to v4 Feb 10, 2026
const VIOLATIONS_KNOWN_KEYS = ["searchTerm", "violationGroup"] as const

function validateViolationsSearch(search: Record<string, unknown>): z.infer<typeof searchSchema> {
const filtered = filterSearchParamsByPrefix(search, [...VIOLATIONS_KNOWN_KEYS], [ACTIVE_FILTERS_PREFIX])
Copy link
Contributor

@taymoor89 taymoor89 Feb 11, 2026

Choose a reason for hiding this comment

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

nice, I think that is the correct way to get the allowed url search params and then performing validation 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

But we can slightly improve it. Known keys are already in the schema maintaining a separate list introduces two sources of truths, meaning for any new key we'll have to add it in two places. Could you try to extract known keys from schema? as in using.

Object.keys(searchSchema.shape)

something like this

const searchSchema = z
  .object({
    service: z.string().optional(),
    searchTerm: z.string().optional(),
  })
  .catchall(z.string().or(z.array(z.string())).optional())

function validateViolationsSearch(search: Record<string, unknown>): z.infer<typeof searchSchema> {
  const filtered = filterSearchParamsByPrefix(search, Object.keys(searchSchema.shape), [ACTIVE_FILTERS_PREFIX])
  return searchSchema.parse(filtered)
}

const PLUGIN_PRESETS_KNOWN_KEYS = ["searchTerm"] as const

function validatePluginPresetsSearch(search: Record<string, unknown>): PluginPresetSearchParams {
const filtered = filterSearchParamsByPrefix(search, [...PLUGIN_PRESETS_KNOWN_KEYS], [SELECTED_FILTER_PREFIX])
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above let's try to remove two sources of truths for known keys.

const SERVICES_KNOWN_KEYS = ["service", "searchTerm"] as const

function validateServicesSearch(search: Record<string, unknown>): ServicesSearchParams {
const filtered = filterSearchParamsByPrefix(search, [...SERVICES_KNOWN_KEYS], [SELECTED_FILTER_PREFIX])
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above let's try to remove two sources of truths for known keys.

const VULNERABILITIES_KNOWN_KEYS = ["vulnerability", "searchTerm"] as const

function validateVulnerabilitiesSearch(search: Record<string, unknown>): VulnerabilitiesSearchParams {
const filtered = filterSearchParamsByPrefix(search, [...VULNERABILITIES_KNOWN_KEYS], [SELECTED_FILTER_PREFIX])
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above let's try to remove two sources of truths for known keys.

const ALERTS_KNOWN_KEYS = ["searchTerm", "showDetailsFor", "predefinedFilter"] as const

function validateAlertsSearch(search: Record<string, unknown>): z.infer<typeof searchSchema> {
const filtered = filterSearchParamsByPrefix(
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above let's try to remove two sources of truths for known keys.

Copy link
Contributor

@taymoor89 taymoor89 left a comment

Choose a reason for hiding this comment

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

Because this zod update touches code as well let's add changeset to update patch version of the apps changed.

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.

2 participants