Skip to content

feat: add Affinda plugin with 119 operations - #375

Open
Ayush7614 wants to merge 8 commits into
corsairdev:mainfrom
Ayush7614:feat/affinda-plugin
Open

feat: add Affinda plugin with 119 operations#375
Ayush7614 wants to merge 8 commits into
corsairdev:mainfrom
Ayush7614:feat/affinda-plugin

Conversation

@Ayush7614

@Ayush7614 Ayush7614 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds @corsair-dev/affinda plugin with all 119 Composio-mapped operations
  • Bearer API key auth via Authorization: Bearer <key>
  • 23 endpoint groups: documents, collections, extractors, annotations, workspaces, organizations, and more
  • Generator script, mocked Jest tests (4/4 pass), and demo/testing registration via AFFINDA_API_KEY env var
  • Greptile patterns: failed op logging, shared unknown schemas, centralized getRoute

Closes #374

Test plan

  • cd packages/affinda && pnpm typecheck — passes
  • cd packages/affinda && pnpm build — passes (~101 KB dist)
  • cd packages/affinda && pnpm test — 4/4 tests pass
  • Plugin exposes 119 operations with matching schemas and endpoint meta
  • Bearer Authorization header verified in mocked client tests
  • Live API: GET /v3/organizations returns 200 with valid key

Screenshots / Demos

Screenshot 2026-08-05 at 1 10 45 AM

Summary by CodeRabbit

  • New Features
    • Added Affinda integration with API-key authentication.
    • Added broad endpoint coverage for documents, collections, workspaces, extractors, searches, mappings, tags, memberships, and related resources.
    • Added request validation, route metadata, entity schemas, caching, and error handling with retry support.
    • Added the Affinda package for installation, configuration, and reuse across Corsair integrations.
  • Tests
    • Added comprehensive API and request behavior coverage for the Affinda integration.

Implements the Affinda document intelligence integration with Bearer API
key auth, routes across documents, collections, extractors, annotations,
and workspaces. Closes corsairdev#374.
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@Ayush7614 is attempting to deploy a commit to the corsair Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the core Changes in packages/corsair label Jul 6, 2026
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds an Affinda plugin exposing 119 operations through shared route, schema, request, logging, and cache infrastructure.

  • Adds bearer-authenticated Affinda request handling and provider-specific error wrapping.
  • Registers grouped endpoint implementations, metadata, schemas, and database entities.
  • Adds mocked tests covering plugin shape, authentication, and representative route mapping.

Confidence Score: 5/5

The PR appears safe to merge, with only a remaining non-blocking documentation issue in the existing test assertion thread.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/affinda/client.ts Builds authenticated Affinda API requests through the shared Corsair HTTP client and wraps transport errors.
packages/affinda/endpoints/factory.ts Centralizes route resolution, path/query/body construction, execution, cache synchronization, and event logging.
packages/affinda/endpoints/routes.ts Defines route metadata for the plugin's 119 Affinda operations.
packages/affinda/endpoints/types.ts Provides shared and operation-specific Zod schemas for endpoint inputs and outputs.
packages/affinda/index.ts Registers the Affinda plugin's authentication, endpoints, metadata, schemas, and database entities.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Caller["Corsair caller"] --> Endpoint["Affinda endpoint group"]
  Endpoint --> Factory["executeAffindaOperation"]
  Factory --> Routes["Route metadata and schemas"]
  Factory --> Client["makeAffindaRequest"]
  Client --> API["Affinda API v3"]
  API --> Cache["Optional entity cache sync"]
  Factory --> Log["Operation event logging"]
Loading

Reviews (4): Last reviewed commit: "Merge branch 'main' into feat/affinda-pl..." | Re-trigger Greptile

Comment thread packages/affinda/client.ts
Comment thread packages/affinda/endpoints/types.ts
Comment thread packages/affinda/api.test.ts
Remove redundant TOKEN config, consolidate shared Zod schemas with
comments, and add type assertion justification comments in tests.
@Ayush7614

Copy link
Copy Markdown
Contributor Author

@greptileai

Cache documents, collections, and workspaces via ctx.db upserts;
rename endpoint files to kebab-case; remove generator scripts.
@Ayush7614

Copy link
Copy Markdown
Contributor Author

@greptileai

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Dhirenderchoudhary, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: da7159b0-a479-48b8-ae71-074614c59165

📥 Commits

Reviewing files that changed from the base of the PR and between 41bdf88 and 958bfbf.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (34)
  • packages/affinda/api.test.ts
  • packages/affinda/client.ts
  • packages/affinda/endpoints/annotations.ts
  • packages/affinda/endpoints/api-users.ts
  • packages/affinda/endpoints/collections.ts
  • packages/affinda/endpoints/data-point-choices.ts
  • packages/affinda/endpoints/data-points.ts
  • packages/affinda/endpoints/data-sources.ts
  • packages/affinda/endpoints/document-splitters.ts
  • packages/affinda/endpoints/document-types.ts
  • packages/affinda/endpoints/documents.ts
  • packages/affinda/endpoints/extractors.ts
  • packages/affinda/endpoints/factory.ts
  • packages/affinda/endpoints/index.ts
  • packages/affinda/endpoints/indexes.ts
  • packages/affinda/endpoints/invitations.ts
  • packages/affinda/endpoints/job-description-search.ts
  • packages/affinda/endpoints/mappings.ts
  • packages/affinda/endpoints/occupation-groups.ts
  • packages/affinda/endpoints/organization-memberships.ts
  • packages/affinda/endpoints/organizations.ts
  • packages/affinda/endpoints/resthooks.ts
  • packages/affinda/endpoints/resume-search.ts
  • packages/affinda/endpoints/routes.ts
  • packages/affinda/endpoints/tags.ts
  • packages/affinda/endpoints/types.ts
  • packages/affinda/endpoints/validation-results.ts
  • packages/affinda/endpoints/validation.ts
  • packages/affinda/endpoints/workspace-memberships.ts
  • packages/affinda/endpoints/workspaces.ts
  • packages/affinda/error-handlers.ts
  • packages/affinda/index.ts
  • packages/affinda/schema/database.ts
  • packages/affinda/schema/index.ts
📝 Walkthrough

Walkthrough

Adds the @corsair-dev/affinda provider package with 119 API endpoints, typed schemas, authenticated requests, cache synchronization, error handling, tests, package configuration, and Corsair provider registration.

Changes

Affinda integration

Layer / File(s) Summary
API contracts and route catalog
packages/affinda/endpoints/routes.ts, packages/affinda/endpoints/types.ts, packages/affinda/schema/*
Defines route metadata, endpoint input and output schemas, inferred types, and document, collection, and workspace schemas.
Request execution and operation lifecycle
packages/affinda/client.ts, packages/affinda/endpoints/factory.ts, packages/affinda/endpoints/cache-sync.ts, packages/affinda/error-handlers.ts
Builds authenticated Affinda v3 requests, resolves paths and payloads, logs operations, synchronizes cached entities, and handles retryable errors.
Endpoint wrappers and registry
packages/affinda/endpoints/*.ts
Adds grouped wrappers for 119 Affinda operations and exports nested endpoint, metadata, and schema registries.
Plugin, package, and Corsair wiring
packages/affinda/index.ts, packages/affinda/package.json, packages/affinda/jest.config.json, packages/affinda/tsconfig.json, packages/affinda/tsup.config.ts, packages/corsair/core/constants.ts, demo/testing/*
Adds the Affinda plugin factory, package configuration, provider registration, and demo API-key configuration.
API integration tests
packages/affinda/api.test.ts
Tests plugin structure, endpoint and schema counts, authentication, request construction, and document routes.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AffindaEndpoint
  participant executeAffindaOperation
  participant makeAffindaRequest
  participant AffindaAPI
  participant AffindaCache
  AffindaEndpoint->>executeAffindaOperation: pass context and input
  executeAffindaOperation->>makeAffindaRequest: send resolved route, query, body, and headers
  makeAffindaRequest->>AffindaAPI: send authenticated request
  AffindaAPI-->>makeAffindaRequest: return response or error
  makeAffindaRequest-->>executeAffindaOperation: return response
  executeAffindaOperation->>AffindaCache: synchronize successful result
Loading

Possibly related PRs

  • corsairdev/corsair#327: Adds a provider plugin with analogous client, endpoint, schema, error-handling, packaging, and registration structures.
  • corsairdev/corsair#389: Adds a provider integration with endpoint factories, authentication, schemas, error handling, tests, and provider registration.
  • corsairdev/corsair#569: Adds a provider plugin with API clients, endpoint registries, schemas, caching, authentication, error handling, tests, and registration.

Suggested labels: plugin

Suggested reviewers: devjain32

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the 119 requested Affinda operations, Bearer authentication, v3 routing, supported methods, schemas, tests, and no webhook triggers.
Out of Scope Changes check ✅ Passed The changes are limited to the Affinda plugin, provider registration, package configuration, demo setup, caching, and related tests.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the addition of the Affinda plugin and its 119 operations.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@Dhirenderchoudhary

Copy link
Copy Markdown
Collaborator

@greptile review

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Plugin PR scorecard — packages/affinda

Check Status Notes
R1 — Scope: plugin files only
R2 — Tests with assertions
R3 — Description complete
R3 — Linked issue / claim
R4 — Demo video / recording

Rules: PLUGIN_PR_RULES.md · re-runs on every push

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (7)
packages/affinda/client.ts (1)

62-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Collapse the duplicate catch branches.

ApiError extends Error, and both branches construct the same AffindaAPIError with the same arguments. The first branch is therefore unreachable in effect. The ApiError detail extraction already happens inside the AffindaAPIError constructor at Lines 14-18.

♻️ Proposed refactor
 	} catch (error) {
-		if (error instanceof ApiError) {
-			throw new AffindaAPIError(error.message, { cause: error });
-		}
 		if (error instanceof Error) {
 			throw new AffindaAPIError(error.message, { cause: error });
 		}
 		throw new AffindaAPIError('Unknown error');
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/client.ts` around lines 62 - 69, Collapse the duplicate
error handling in the catch block by removing the separate ApiError branch and
retaining a single Error-based branch that constructs AffindaAPIError with the
original error as cause. Preserve the existing Unknown error fallback for
non-Error values.
packages/affinda/endpoints/routes.ts (1)

18-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a satisfies clause so the compiler validates all 119 route entries.

affindaRoutes declares as const only. AffindaRoute is therefore never applied to the literal, so a typo in method, riskLevel, or a missing description stays undetected until runtime. satisfies keeps the narrow literal types that AffindaRoutes depends on while enforcing the declared shape.

♻️ Proposed refactor
-export const affindaRoutes = [
+export const affindaRoutes = [

Apply the clause at the end of the literal:

-] as const;
+] as const satisfies readonly AffindaRoute[];

Also applies to: 1500-1502

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/routes.ts` at line 18, Update the affindaRoutes
array declaration to add a satisfies clause against the intended route
collection type after the existing as const assertion, so every route entry is
validated while preserving narrow literal types used by AffindaRoutes.
packages/affinda/endpoints/cache-sync.ts (2)

103-107: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Sequential cache writes add latency proportional to the page size.

Each item is awaited in turn, and this runs before executeAffindaOperation returns the result to the caller. A list response of 100 documents therefore performs 100 sequential database round trips on the request path. Batch the writes, or bound the concurrency.

♻️ Proposed refactor
-		for (const item of cacheItems(response, rule)) {
-			const entityId = cacheEntityId(item, rule);
-			if (!entityId) continue;
-			await client.upsertByEntityId(entityId, item);
-		}
+		const upsert = client.upsertByEntityId;
+		const writes = cacheItems(response, rule).flatMap((item) => {
+			const entityId = cacheEntityId(item, rule);
+			return entityId ? [upsert(entityId, item)] : [];
+		});
+		await Promise.all(writes);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/cache-sync.ts` around lines 103 - 107, Update the
cache synchronization loop around cacheItems and client.upsertByEntityId to
avoid awaiting writes sequentially; batch the upserts or use bounded concurrency
while preserving entityId filtering and ensuring all cache writes complete
before executeAffindaOperation returns.

76-90: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the ctx.db shape and use the Corsair logger.

Two smaller items in this block:

The inline ctx.db as Record<...> cast declares the client shape at the use site. That hides any real type on AffindaContext and will not fail if the Corsair database surface changes. Declare a named CacheClient type, and derive it from the Corsair type if one is exported.

The catch block writes to console.warn. packages/affinda/endpoints/factory.ts already uses logEventFromContext from corsair/core for operation logging. Route this warning through the same mechanism so cache failures appear in the same place as operation events.

Also applies to: 108-110

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/cache-sync.ts` around lines 76 - 90, Define a
named CacheClient type for the database client shape, deriving it from the
exported Corsair type when available, and use it instead of the inline ctx.db
cast in the cache-sync flow. In the catch block, replace console.warn with
logEventFromContext from corsair/core, preserving the existing cache-failure
warning details and routing them through the operation logger.
packages/affinda/endpoints/factory.ts (2)

143-149: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Build a route lookup map once.

getRoute scans all 119 entries linearly. Every endpoint wrapper calls it at module load, so package import performs roughly 119 × 119 comparisons. The cost is small, but a Map keyed by name is simpler and constant-time.

♻️ Proposed refactor
+const ROUTES_BY_NAME = new Map(
+	affindaRoutes.map((route) => [route.name, route as AffindaRoute]),
+);
+
 export function getRoute(name: string): AffindaRoute {
-	const route = affindaRoutes.find((candidate) => candidate.name === name);
+	const route = ROUTES_BY_NAME.get(name);
 	if (!route) {
 		throw new Error(`[affinda] missing route: ${name}`);
 	}
 	return route;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/factory.ts` around lines 143 - 149, Replace the
repeated linear search in getRoute with a module-level Map keyed by each
affindaRoutes entry’s name, initialized once from affindaRoutes. Look up the
requested name through that map while preserving the existing missing-route
error and returned AffindaRoute behavior.

63-81: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Positional placeholder mapping is fragile.

resolvePath maps the nth {...} placeholder to route.pathParams[index]. The mapping is therefore correct only when pathParams is written in the same order as the placeholders, and it silently mis-maps when the order differs. The catalog already contains entries where pathParams does not match the placeholder names at all, for example deleteCollection in packages/affinda/endpoints/routes.ts (Line 376).

Consider resolving by placeholder name and treating pathParams as a declared set to validate against, instead of an ordered lookup table. That makes an author mistake a startup failure rather than a wrong URL.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/factory.ts` around lines 63 - 81, Update
resolvePath to resolve each placeholder by its name rather than by its
positional index in route.pathParams. Treat route.pathParams as a declared set:
validate that every placeholder is declared and fail during route initialization
when names are missing or inconsistent, while preserving the existing input key
and camelToSnake fallback resolution.
packages/affinda/endpoints/annotations.ts (1)

4-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a single wrapper factory for all 119 endpoints.

Every endpoint in this file, and in the other 23 endpoint files, repeats the same three lines: resolve the route by name, then delegate to executeAffindaOperation. A small helper removes about 700 lines and gives one place to add input validation later.

♻️ Proposed refactor

Add the helper to packages/affinda/endpoints/factory.ts:

export function defineAffindaEndpoint(name: string): AffindaEndpoint {
	const route = getRoute(name);
	return (ctx, input = {}) => executeAffindaOperation(ctx, input, route);
}

Then each wrapper becomes one line:

-const batchUpdateAnnotationsRoute = getRoute('batchUpdateAnnotations');
-export const batchUpdateAnnotations: AffindaEndpoint = async (ctx, input = {}) => {
-	return executeAffindaOperation(ctx, input, batchUpdateAnnotationsRoute);
-};
+export const batchUpdateAnnotations = defineAffindaEndpoint('batchUpdateAnnotations');

If a generator produces these files, apply the change in the generator template.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/affinda/endpoints/annotations.ts` around lines 4 - 27, Introduce a
shared defineAffindaEndpoint factory in the endpoints factory module that
resolves a route once and delegates to executeAffindaOperation, then replace the
repeated route constants and wrapper functions such as batchUpdateAnnotations,
createBatchAnnotations, and updateAnnotation with factory-based definitions
across all endpoint files. If these wrappers are generated, update the generator
template as the source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/affinda/client.ts`:
- Around line 44-48: Update the HEADERS construction in requestAffindaOperation
so the caller-provided headers are spread before the plugin-owned Content-Type
and Authorization values; keep those fixed headers last so input.headers cannot
override them.

In `@packages/affinda/endpoints/factory.ts`:
- Around line 188-194: Update the finally block in the operation wrapper around
logAffindaOperation so logging failures are caught and isolated rather than
propagated. Preserve the original error thrown from the catch block, including
AffindaAPIError details, while retaining the existing operation logging attempt
and status handling.
- Around line 127-141: Update the body construction logic in the endpoint
factory to preserve Affinda’s generated wire-format field names, including
targetUrl, instead of applying camelToSnake to every body key. Remove or limit
the global conversion while retaining snakeCaseKeys only where explicitly
required, and ensure schemas containing both camelCase and snake_case fields
remain unambiguous.

In `@packages/affinda/endpoints/routes.ts`:
- Around line 1211-1223: Update the removeTagFromDocuments route definition to
use riskLevel: 'write' and remove the irreversible: true flag, matching the
reversible behavior and the configuration of addTagToDocuments.
- Around line 550-562: Align each affected route’s path and pathParams with its
required schema field, removing those identifiers from queryParams: in
packages/affinda/endpoints/routes.ts, update deleteWorkspace (550-562) to
workspace_id, deleteResthookSubscription (511-523) to identifier, getTag
(1026-1037) to tag_id, getResthookSubscription (1002-1013) to identifier,
getUsageByWorkspace (1038-1049) to workspace_id, updateResthookSubscription
(1452-1463) to identifier, and updateWorkspace (1488-1499) to workspace_id. In
packages/affinda/endpoints/types.ts, retain only the required matching field in
DeleteWorkspaceInputSchema (763-769), GetResthookSubscriptionInputSchema
(1293-1300), GetTagInputSchema (1325-1332), GetUsageByWorkspaceInputSchema
(1337-1346), UpdateResthookSubscriptionInputSchema (1915-1925), and
UpdateWorkspaceInputSchema (1991-2005). Add one test for each route using only
its required identifier and assert the generated URL.

In `@packages/affinda/error-handlers.ts`:
- Around line 37-45: Update the SERVER_ERROR handler and its surrounding retry
configuration to avoid exponential retries for non-idempotent mutations such as
createResthookSubscription. Only return retry settings for operations proven
idempotent or carrying a supported idempotency key; otherwise disable retries
while preserving the existing 5xx status matching.

---

Nitpick comments:
In `@packages/affinda/client.ts`:
- Around line 62-69: Collapse the duplicate error handling in the catch block by
removing the separate ApiError branch and retaining a single Error-based branch
that constructs AffindaAPIError with the original error as cause. Preserve the
existing Unknown error fallback for non-Error values.

In `@packages/affinda/endpoints/annotations.ts`:
- Around line 4-27: Introduce a shared defineAffindaEndpoint factory in the
endpoints factory module that resolves a route once and delegates to
executeAffindaOperation, then replace the repeated route constants and wrapper
functions such as batchUpdateAnnotations, createBatchAnnotations, and
updateAnnotation with factory-based definitions across all endpoint files. If
these wrappers are generated, update the generator template as the source of
truth.

In `@packages/affinda/endpoints/cache-sync.ts`:
- Around line 103-107: Update the cache synchronization loop around cacheItems
and client.upsertByEntityId to avoid awaiting writes sequentially; batch the
upserts or use bounded concurrency while preserving entityId filtering and
ensuring all cache writes complete before executeAffindaOperation returns.
- Around line 76-90: Define a named CacheClient type for the database client
shape, deriving it from the exported Corsair type when available, and use it
instead of the inline ctx.db cast in the cache-sync flow. In the catch block,
replace console.warn with logEventFromContext from corsair/core, preserving the
existing cache-failure warning details and routing them through the operation
logger.

In `@packages/affinda/endpoints/factory.ts`:
- Around line 143-149: Replace the repeated linear search in getRoute with a
module-level Map keyed by each affindaRoutes entry’s name, initialized once from
affindaRoutes. Look up the requested name through that map while preserving the
existing missing-route error and returned AffindaRoute behavior.
- Around line 63-81: Update resolvePath to resolve each placeholder by its name
rather than by its positional index in route.pathParams. Treat route.pathParams
as a declared set: validate that every placeholder is declared and fail during
route initialization when names are missing or inconsistent, while preserving
the existing input key and camelToSnake fallback resolution.

In `@packages/affinda/endpoints/routes.ts`:
- Line 18: Update the affindaRoutes array declaration to add a satisfies clause
against the intended route collection type after the existing as const
assertion, so every route entry is validated while preserving narrow literal
types used by AffindaRoutes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dc3bc443-eb56-468a-8c72-829345fb5142

📥 Commits

Reviewing files that changed from the base of the PR and between eccc11d and 41bdf88.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (42)
  • demo/testing/package.json
  • demo/testing/src/server/corsair.ts
  • packages/affinda/api.test.ts
  • packages/affinda/client.ts
  • packages/affinda/endpoints/annotations.ts
  • packages/affinda/endpoints/api-users.ts
  • packages/affinda/endpoints/cache-sync.ts
  • packages/affinda/endpoints/collections.ts
  • packages/affinda/endpoints/data-point-choices.ts
  • packages/affinda/endpoints/data-points.ts
  • packages/affinda/endpoints/data-sources.ts
  • packages/affinda/endpoints/document-splitters.ts
  • packages/affinda/endpoints/document-types.ts
  • packages/affinda/endpoints/documents.ts
  • packages/affinda/endpoints/extractors.ts
  • packages/affinda/endpoints/factory.ts
  • packages/affinda/endpoints/index.ts
  • packages/affinda/endpoints/indexes.ts
  • packages/affinda/endpoints/invitations.ts
  • packages/affinda/endpoints/job-description-search.ts
  • packages/affinda/endpoints/mappings.ts
  • packages/affinda/endpoints/occupation-groups.ts
  • packages/affinda/endpoints/organization-memberships.ts
  • packages/affinda/endpoints/organizations.ts
  • packages/affinda/endpoints/resthooks.ts
  • packages/affinda/endpoints/resume-search.ts
  • packages/affinda/endpoints/routes.ts
  • packages/affinda/endpoints/tags.ts
  • packages/affinda/endpoints/types.ts
  • packages/affinda/endpoints/validation-results.ts
  • packages/affinda/endpoints/validation.ts
  • packages/affinda/endpoints/workspace-memberships.ts
  • packages/affinda/endpoints/workspaces.ts
  • packages/affinda/error-handlers.ts
  • packages/affinda/index.ts
  • packages/affinda/jest.config.json
  • packages/affinda/package.json
  • packages/affinda/schema/database.ts
  • packages/affinda/schema/index.ts
  • packages/affinda/tsconfig.json
  • packages/affinda/tsup.config.ts
  • packages/corsair/core/constants.ts

Comment thread packages/affinda/client.ts
Comment thread packages/affinda/endpoints/factory.ts
Comment thread packages/affinda/endpoints/factory.ts
Comment thread packages/affinda/endpoints/routes.ts
Comment thread packages/affinda/endpoints/routes.ts
Comment thread packages/affinda/error-handlers.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes in packages/corsair

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Integration request]: Affinda

2 participants