Skip to content

feat: add CRUD REST API for saved searches (/api/v2/saved-searches)#2544

Open
ankitcharolia wants to merge 3 commits into
hyperdxio:mainfrom
ankitcharolia:feat/saved-searches-external-api
Open

feat: add CRUD REST API for saved searches (/api/v2/saved-searches)#2544
ankitcharolia wants to merge 3 commits into
hyperdxio:mainfrom
ankitcharolia:feat/saved-searches-external-api

Conversation

@ankitcharolia

Copy link
Copy Markdown

Summary

Adds full CRUD endpoints for saved searches to the external API (/api/v2/saved-searches), enabling infrastructure-as-code tooling to provision saved searches programmatically.

The SavedSearch mongoose model and toExternalJSON() method already existed — only the router and its registration were missing.

New endpoints:

Method Path Description
GET /api/v2/saved-searches List all saved searches for the team
POST /api/v2/saved-searches Create a saved search
GET /api/v2/saved-searches/:id Get a saved search by ID
PUT /api/v2/saved-searches/:id Update a saved search
DELETE /api/v2/saved-searches/:id Delete a saved search

Screenshots or video

Before After
/api/v2/saved-searches → 404 GET /api/v2/saved-searches{ data: [...] }

How to test on Vercel preview

Steps:

  1. Obtain a Bearer token from Team Settings → API Keys
  2. curl -H 'Authorization: Bearer <token>' <preview-url>/api/v2/saved-searches — should return { "data": [] }
  3. POST a new saved search with name, sourceId, and optional where/whereLanguage/select/orderBy/tags
  4. Verify GET/PUT/DELETE round-trips work correctly
  5. Confirm that saved searches created here appear in the UI and can be referenced in alerts via savedSearchId

References

Adds GET/POST /api/v2/saved-searches and GET/PUT/DELETE
/api/v2/saved-searches/:id to the external API.

The SavedSearch mongoose model and toExternalJSON() already exist;
this PR adds only the missing router and index registration.

Closes hyperdxio#2543
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@ankitcharolia is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dba306e

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

@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an external API for saved searches. The main changes are:

  • New CRUD routes under /api/v2/saved-searches.
  • Router registration with the existing external API auth and rate limiting.
  • Request validation and team-scoped source checks for create and update.
  • Integration tests for auth, team isolation, validation, and CRUD flows.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
packages/api/src/routers/external-api/v2/savedSearches.ts Adds the saved-search CRUD router with request validation, team scoping, and source ownership checks.
packages/api/src/routers/external-api/v2/index.ts Registers the saved-searches router with the standard external API middleware chain.
packages/api/src/routers/external-api/tests/savedSearches.test.ts Adds integration coverage for saved-search CRUD behavior, authentication, validation, and cross-team source rejection.

Reviews (3): Last reviewed commit: "fix: validate sourceId ownership before ..." | Re-trigger Greptile

Comment thread packages/api/src/routers/external-api/v2/savedSearches.ts
Comment thread packages/api/src/routers/external-api/v2/savedSearches.ts
ankitcharolia and others added 2 commits June 29, 2026 23:42
Adds a Source.findOne({ _id: sourceId, team: teamId }) check to both
POST and PUT handlers, returning 400 if the source does not exist or
belongs to another team. Also adds test coverage for cross-team and
non-existent sourceId scenarios.

Addresses greptile review comments on unchecked source ownership.
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.

feat: add CRUD REST API for saved searches (/api/v2/saved-searches)

1 participant