Skip to content

Dev#99

Merged
SteakFisher merged 60 commits into
mainfrom
dev
Jul 7, 2026
Merged

Dev#99
SteakFisher merged 60 commits into
mainfrom
dev

Conversation

@SteakFisher

Copy link
Copy Markdown
Member

No description provided.

SteakFisher and others added 30 commits June 17, 2026 01:12
…dularization)

Phase 1 — SQL Dialect Abstraction:
- fieldRegistry.ts: single source of truth for event field definitions
- sqlDialect.ts: common interface (buildSelect, buildWhere, getTotalCount)
- postgresDialect.ts / clickHouseDialect.ts: dialect implementations
- queryEvents.ts: unified handler that picks dialect via STORAGE_ADAPTER
- Both PG and CH handlers now thin re-exports from common/queryEvents

Phase 3 — Data Engine Modularization:
- Extract dataQuery module from routes/gRPC/data/query into storage/query/
- Explicit field alias registry with auto-derived cast types from Drizzle metadata
- Thin handler in routes/gRPC/data/query delegates to executeDataQuery/getDataTable
- hasMore support in DataQueryResult
0xanshu and others added 27 commits June 29, 2026 09:44
chore: rename SCRAWN_KEY to MASTER_API_KEY, add MASTER_API_KEY_HASH, …
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds project-scoped backend support across auth, billing, and query paths. The main changes are:

  • Project ownership on API keys, metadata, webhooks, sessions, users, and usage events.
  • Master-key onboarding and project management endpoints.
  • Project-scoped Dodo payment configuration and webhook routing.
  • Shared query-event SQL dialects for Postgres and ClickHouse.
  • New integration coverage for data and event queries.

Confidence Score: 4/5

The query-events path needs a tenant-scope fix before merging.

Authenticated event queries can read rows outside the caller's project. The problem affects list, aggregation, and count queries in both SQL dialects. The reviewed HTTP project and payment paths otherwise use projectId consistently.

src/storage/adapter/common/queryEvents.ts, src/storage/adapter/common/postgresDialect.ts, src/storage/adapter/common/clickHouseDialect.ts

T-Rex T-Rex Logs

What T-Rex did

  • Reproduced the tenant-scoping guard in handleQueryEvents by running a focused Bun test that mocks the SQL dialect and exercises the list and aggregation paths with an auth.projectId of project-A-tenant-id and unscoped filters, including no projectId or mode predicate.
  • Prepared reproducible artifacts documenting the reproduction, including the Bun test harness that instruments dialect calls from handleQueryEvents and the test output showing unscoped list and aggregation dialect arguments.
  • Validated blocker evidence for the DB reachability probe: the corrected probe shows the required DB command and failure details, while the fallback smoke test confirms all tests pass, and an earlier probe is preserved for reference.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/storage/adapter/common/queryEvents.ts Adds the shared queryEvents handler, but drops the authenticated project context before SQL generation.
src/storage/adapter/common/postgresDialect.ts Builds Postgres event queries from request filters only, so it depends on the caller to provide required tenant predicates.
src/storage/adapter/common/clickHouseDialect.ts Builds ClickHouse event queries from request filters only, with the same missing tenant predicate issue.
src/routes/http/api/onboarding.ts Adds master-key onboarding, project creation, Dodo setup, and rollback handling.
src/routes/http/api/projects.ts Adds master-key project list, update, and delete endpoints.
src/routes/gRPC/payment/paymentProvider.ts Moves Dodo client and metadata lookup to project-scoped configuration.

Reviews (1): Last reviewed commit: "Merge pull request #98 from 0xanshu/feat..." | Re-trigger Greptile

Comment on lines +30 to +32
return await dialect.executeAggregationQuery(request, filtered);
}
return await dialect.executeListQuery(request, filtered);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Query Events Ignore Tenant Scope

When any API key calls queryEvents, the authenticated projectId is accepted by this function but never reaches the Postgres or ClickHouse dialects. The generated list, aggregation, and count queries only use request filters, so a valid key can receive events from other projects and modes in the shared event tables.

Artifacts

Repro: Bun test harness instrumenting dialect calls from handleQueryEvents

  • Contains supporting evidence from the run (text/typescript; charset=utf-8).

Repro: test output showing unscoped list and aggregation dialect arguments

  • Keeps the command output available without making the summary code-heavy.

View artifacts

T-Rex Ran code and verified through T-Rex

@SteakFisher SteakFisher merged commit 95a9f9a into main Jul 7, 2026
3 checks passed
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