Skip to content

[TS SDK] Client Support Custom fields #497

Closed

Description

@jcrichlake

Summary

The Opportunity Client in typescript-sdk needs expanded to support parsing and returning the registered custom fields if they are included in the API call.

We should update each of the endpoints to take in an optional opportunity base object that would enable sdk users to call the rest endpoints with the custom fields they wish to retrieve out

Notes

The simplest pattern to support right now is to allow users to pass a custom schema for validation to each of the Client.opportunity methods

import { z } from "zod";
import { OpportunityBaseSchema } from "@common-grants/sdk/schemas";
import { CustomFieldType } from "@common-grants/sdk/constants";
import { withCustomFields } from "@common-grants/sdk/extensions";
import { Client, Auth } from "@common-grants/client";

// Create an extended schema with typed custom fields
const OpportunitySchema = withCustomFields(OpportunityBaseSchema, [
  {
    key: "legacyId",
    fieldType: CustomFieldType.object,
    valueSchema: z.int(),
    description: "Maps to the opportunity_id in the legacy system",
  }
] as const);

const baseUrl = process.env.CG_BASE_URL ?? "http://localhost:8000";
const apiKey = process.env.CG_API_KEY ?? "<your-api-key>";

const client = new Client({
  baseUrl,
  auth: Auth.apiKey(apiKey),
  timeout: 5000,
});

const opp = await client.opportunities.get(oppId, OpportunitySchema);
console.log(opp.customFields?.legacyId?.value)

Acceptance criteria

  • The 3 Opportunity Client ReST endpoints are updated with an optional OpportunityBase object
  • The endpoints fallback to a default OpportunityBase object
  • The Opportunity Client examples are updated with examples that register, pass in, and retrieve the custom field values

Activity

  1. added theissue type on Feb 9, 2026
  2. changed the issue type fromtoon Feb 9, 2026
  3. changed the issue type fromtoon Feb 9, 2026
  4. changed the title [-]Update typescript sdk Client to support Custom fields[/-] [+][TS SDK] Client Support Custom fields[/+] on Feb 9, 2026
  5. added a commit that references this issue on Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions