Skip to content

refactor(authz): make environment optional on request locals - #6971

Open
kaposke wants to merge 2 commits into
masterfrom
gui/NAN-6468/refac-make-environment-optional-on-request-locals
Open

refactor(authz): make environment optional on request locals#6971
kaposke wants to merge 2 commits into
masterfrom
gui/NAN-6468/refac-make-environment-optional-on-request-locals

Conversation

@kaposke

@kaposke kaposke commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

A bit of a pre-req for account-level keys and endpoints: locals.environment has to be optional. Separating this because it touches many files, but most are 1 liners.

Previously:

  • RequestLocals had every field as optionals.
  • Middlewares would pre-load and fill some of the RequestLocals properties.
  • Handlers get Required<RequestLocals> which is unprecise - not every property is there for real.
    So the typing was a lie for a lot of cases.

Now:

  • Made RequestLocals have non-optional fields for everything that always gets filled.
  • Middleware takes Partial<RequestLocals> (so I've inverted the game)
  • A variant RequestLocalsWithEnvironment for endpoints that need the environment (most public endpoints so far).
  • A wrapper on asyncWrapper to validate that the environment is in-fact present, so we don't need to spread the typecheck everywhere.

The typing should now be precise on every handler.

Review in cubic

@linear-code

linear-code Bot commented Jul 30, 2026

Copy link
Copy Markdown

NAN-6468

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 128 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/server/lib/utils/express.ts
Comment thread packages/server/lib/controllers/v1/environment/deleteApiKey.ts
Comment thread packages/server/lib/utils/asyncWrapper.unit.test.ts
kaposke and others added 2 commits July 31, 2026 20:07
Keep the newly added impersonation handler compatible with optional environment request locals after rebasing onto master.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kaposke
kaposke force-pushed the gui/NAN-6468/refac-make-environment-optional-on-request-locals branch from 05d52bb to 1bb1d8d Compare July 31, 2026 23:16
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.

1 participant