feat(api): add provider terms to the Exchange preview proxy - #4608
Open
developersdigest wants to merge 1 commit into
Open
feat(api): add provider terms to the Exchange preview proxy#4608developersdigest wants to merge 1 commit into
developersdigest wants to merge 1 commit into
Conversation
developersdigest
marked this pull request as ready for review
September 11, 2026 00:46
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 3/5
- In
apps/api/src/lib/exchange-provider-access.ts, a stalled primary database query can leave/exchange/retrievewaiting past its 50-second deadline because the authorization lookup ignores the proxy abort signal; propagate the deadline into this query to ensure timely cancellation.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/lib/exchange-provider-access.ts">
<violation number="1" location="apps/api/src/lib/exchange-provider-access.ts:84">
P2: When the primary database query stalls, `/exchange/retrieve` can wait beyond its 50-second deadline because the authorization query is not tied to the proxy's abort signal. Propagate the deadline into this lookup and use a cancellable or bounded database query before allowing the request to continue.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| ); | ||
| try { | ||
| // Read the primary database so disabling access does not wait for an auth-cache refresh. | ||
| const result = await db.execute(sql` |
Contributor
There was a problem hiding this comment.
P2: When the primary database query stalls, /exchange/retrieve can wait beyond its 50-second deadline because the authorization query is not tied to the proxy's abort signal. Propagate the deadline into this lookup and use a cancellable or bounded database query before allowing the request to continue.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/lib/exchange-provider-access.ts, line 84:
<comment>When the primary database query stalls, `/exchange/retrieve` can wait beyond its 50-second deadline because the authorization query is not tied to the proxy's abort signal. Propagate the deadline into this lookup and use a cancellable or bounded database query before allowing the request to continue.</comment>
<file context>
@@ -0,0 +1,132 @@
+ );
+ try {
+ // Read the primary database so disabling access does not wait for an auth-cache refresh.
+ const result = await db.execute(sql`
+ SELECT t.org_id, a.data_source_id, a.status, a.terms_key, a.terms_version,
+ a.terms_accepted_at, a.settings
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The existing Exchange retrieval proxy forwards requests without checking whether the caller's organization accepted the provider's agreement. This adds an interim consent gate that can ship independently of #4582.
GET /exchange/provider-termsfor the dashboard, without requiring the retrieval preview flag./exchange/retrieve, validate the single request or batch, load authoritative provider requirements from Exchange, and check the authenticated team's organization against the primaryorganization_data_source_accesstable. Missing/stale required acceptance and disabled/suspended access reject the entire batch before execution. Discovery remains independent of consent.Billing behavior is unchanged. This PR adds no v1/v2 scrape, crawl, batch-scrape, SDK, or database-schema changes. Acceptance writes remain in the signed-in dashboard; no API-key acceptance endpoint is introduced.
Preview rollout dependencies
Keep this draft until the companion Exchange endpoints (
GET /v1/provider-termsandPOST /v1/provider-terms/requirements) and dashboard acceptance flow are available. Those changes are currently local and not included in this PR. Deploy Exchange first: if the requirements endpoint is absent or unavailable, retrieval fails closed, including for providers without agreements. The dashboard must be available before enabling required agreements.Provider agreements must contain approved real documents; local preview fixtures are not production agreements. PlanetScale agreement persistence is not part of this PR. This only enforces the existing
/exchange/retrieveproxy; the billing PR must carry the same check into its shared execution path before adding other execution routes.Validation
tsc --noEmit, Prettier, Knip, and lint-staged pass.Summary by cubic
Gates Exchange retrieval on the caller's organization having accepted the provider's agreement, and exposes a non-billable provider-terms endpoint for the dashboard. Previously,
/exchange/retrieveforwarded requests without checking consent; now a missing or stale acceptance, or disabled/suspended access, rejects the entire request or batch before execution.GET /exchange/provider-termsworks without the retrieval preview flag./exchange/retrieve, loads authoritative requirement metadata from Exchange and checks the authenticated team's organization inorganization_data_source_access; discovery remains independent of consent.Rollout dependencies
GET /v1/provider-termsandPOST /v1/provider-terms/requirements) and dashboard acceptance flow are available; those changes are currently local and not included here./exchange/retrieveproxy; the billing PR must carry the same check into its shared execution path before adding other execution routes.Validation
tsc --noEmit, Prettier, Knip, and lint-staged pass.Written for commit e670997. Summary will update on new commits.