Skip to content

feat(api): add customer entitlement value lookup by feature key - #5212

Merged
turip merged 1 commit into
mainfrom
feat/v3-customer-entitlement-feature-value
Sep 25, 2026
Merged

turip merged 1 commit into
mainfrom
feat/v3-customer-entitlement-feature-value

Conversation

@turip

@turip turip commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Overview

Add GET /api/v3/openmeter/customers/{customerId}/entitlement-access/features/{featureKey}/value to look up a customer's entitlement value by feature key.

The endpoint uses the same access evaluation and optional value expansion as the entitlement-ID value route. For a feature without an entitlement, it returns 200 with has_access: false and omits type and value, consistent with the feature check endpoint.

Regenerate the OpenAPI spec, Go and TypeScript clients, and server interface; wire the handler and add handler and e2e coverage.

Notes for reviewer

  • Focused Go handler/server tests, Go SDK tests, TypeScript SDK typecheck, e2e compilation, and scoped fast Go lint passed locally.
  • The full spec generation command currently fails in the unrelated legacy Python SDK generator; focused AIP generation succeeded.

Summary by CodeRabbit

  • New Features
    • Added an API operation to retrieve a customer’s entitlement value by feature key, with optional balance details and evaluation time.
    • Results indicate whether the customer has access and may include entitlement configuration, balance, and type. If no active entitlement exists, access is denied and the type is omitted.
    • Added support for this operation in the JavaScript and Go clients.

RetriggerConfidence Score: 4/5

The PR appears safe to merge; the remaining concern is non-blocking TypeScript client runtime coverage.

Fix All in Claude CodeFindings

  1. P2 Missing client runtime coverage ▶
Fix with agent prompt
### Issue 1
api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts:167-193
The new TypeScript method has no runtime test for how it sends `expand` and `at`, or how it reads a response with no `type`. Typechecking will not catch a request-format or response-mapping regression, so a client test for a metered value and a missing entitlement would help protect this path.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds a v3 customer entitlement-value lookup by feature key, including an optional evaluation time and metered-value expansion.

  • Adds the TypeSpec and OpenAPI contract, server route and handler, and generated Go and TypeScript clients.
  • Adds handler and end-to-end coverage for metered values and features without an active entitlement.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Client[Client] --> Route[Feature-key value route]
  Route --> Handler[Namespace-scoped handler]
  Handler --> Service[Customer entitlement access service]
  Service --> Lookup[Entitlement active at requested time]
  Lookup --> Response{Entitlement found?}
  Response -->|No| Denied[No access; omit type and value]
  Response -->|Yes| Value[Map access and optional value expansion]
Loading

Reviews (1) · Last reviewed commit: "feat(api): add customer entitlement valu..."

@turip
turip requested a review from a team as a code owner September 25, 2026 13:55
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: bcbc9bd3-0761-4b99-825c-dbae6906a8b0

📥 Commits

Reviewing files that changed from the base of the PR and between 49638d2 and c5efaab.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (18)
  • api/spec/packages/aip-client-javascript/README.md
  • api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts
  • api/spec/packages/aip-client-javascript/src/index.ts
  • api/spec/packages/aip-client-javascript/src/models/operations/entitlements.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/models/types.ts
  • api/spec/packages/aip-client-javascript/src/sdk/internal.ts
  • api/spec/packages/aip/src/entitlements/access.tsp
  • api/spec/packages/aip/src/entitlements/operations.tsp
  • api/v3/api.gen.go
  • api/v3/client/README.md
  • api/v3/client/entitlements.go
  • api/v3/client/models_entitlements.go
  • api/v3/handlers/customers/entitlementaccess/get.go
  • api/v3/handlers/customers/entitlementaccess/get_test.go
  • api/v3/handlers/customers/entitlementaccess/handler.go
  • api/v3/server/routes.go
  • e2e/customer_entitlement_value_v3_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds an endpoint that returns a customer’s entitlement value for a feature key. It includes API and result types, server handling, Go and JavaScript client methods, and tests for evaluation time, value expansion, and access states.

Changes

Feature-key value lookup

Layer / File(s) Summary
Endpoint and result contract
api/spec/packages/aip/src/entitlements/*
The API adds a feature-key lookup endpoint and a result type with an optional entitlement type. The endpoint accepts optional expansion and evaluation-time parameters.
Server handler and endpoint tests
api/v3/handlers/customers/entitlementaccess/*, api/v3/server/routes.go, e2e/customer_entitlement_value_v3_test.go
The v3 route forwards feature-key requests to a new handler. The handler defaults a missing evaluation time to now and returns access data or a no-access result. Tests cover expansion, evaluation time, entitlement states, and mapped errors.
Go client method and result type
api/v3/client/entitlements.go, api/v3/client/models_entitlements.go, api/v3/client/README.md
The Go client serializes optional query parameters, calls the endpoint, and decodes the result. The client documentation adds the operation.
Generated JavaScript client support
api/spec/packages/aip-client-javascript/src/funcs/entitlements.ts, api/spec/packages/aip-client-javascript/src/models/*, api/spec/packages/aip-client-javascript/src/sdk/internal.ts, api/spec/packages/aip-client-javascript/src/index.ts, api/spec/packages/aip-client-javascript/README.md
The generated client adds request and response schemas and types, the endpoint function, and an internal SDK method. The public type export and operation documentation are updated.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ServerRoute
  participant EntitlementHandler
  participant EntitlementService
  Client->>ServerRoute: GET feature value with customer, feature key, and optional parameters
  ServerRoute->>EntitlementHandler: Forward request parameters
  EntitlementHandler->>EntitlementService: Request entitlement access at evaluation time
  EntitlementService-->>EntitlementHandler: Return access result
  EntitlementHandler-->>Client: Return feature value or no-access result
Loading

Suggested reviewers: borosr

Merge Risk: ⚪ Minimal · up to c5efa

The feature-key value endpoint and clients have no identified issue that needs resolution before merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to c5efa

The new lookup makes entitlement values accessible by feature key, but the reviewed route uses the existing customer namespace and entitlement evaluation path. No authorization bypass was established. The intended permission scope for callers who can read balances and configuration still needs confirmation.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A caller able to reach the customer route can now request an entitlement value using a feature key instead of first supplying an entitlement ID. The possible returned data includes static configuration and, when expanded, metered balance details.

Trust Boundaries and Controls

  • observed — The generated wrappers for the new and existing value routes both apply the configured handler middleware chain. The handlers use the same contextual namespace resolution and entitlement service; the reviewed source does not establish the concrete production authentication policy.

Hardening Proposals

  • proposed — Confirm that credentials permitted to use customer feature checks are also intended to read entitlement configuration and expanded balances through the new route, and document any required permission distinction.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a customer entitlement value lookup by feature key.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@turip turip added area/api release-note/feature Release note: Exciting New Features labels Sep 25, 2026
@turip
turip merged commit 3bef3b2 into main Sep 25, 2026
51 of 55 checks passed
@turip
turip deleted the feat/v3-customer-entitlement-feature-value branch September 25, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants