You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 fieldsconstOpportunitySchema=withCustomFields(OpportunityBaseSchema,[{key: "legacyId",fieldType: CustomFieldType.object,valueSchema: z.int(),description: "Maps to the opportunity_id in the legacy system",}]asconst);constbaseUrl=process.env.CG_BASE_URL??"http://localhost:8000";constapiKey=process.env.CG_API_KEY??"<your-api-key>";constclient=newClient({
baseUrl,auth: Auth.apiKey(apiKey),timeout: 5000,});constopp=awaitclient.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
[-]Update typescript sdk Client to support Custom fields[/-][+][TS SDK] Client Support Custom fields[/+][Issue #497] Support custom fields in TS SDK client (#522)