@fundtel/contracts
v1.1.0
Published
FundTel API contract definitions using ts-rest
Readme
Fundtel REST API Client - GitHub Package
This GitHub package contains type definitions and API contracts used by both the backend and frontend applications. It's privately published to GitHub Packages.
Purpose
- Provides API contract definitions using @ts-rest/core
- Contains Zod schemas for validation
- Defines TypeScript types for the API
- Ensures type safety and contract consistency across the application
Frontend Usage
Adding & Updating Package
You must be a member of the GitHub org for this to work
# Adding package
yarn add @fundtel-portal/contracts
# Updating package
yarn contracts:updateInitializing Client
import { initClient } from '@ts-rest/core';
import { appContract } from '@fundtel-portal/contracts';
import { supabase } from '../supabase-client';
import { Session } from '@supabase/supabase-js';
// Get initial session
let currentSession: Session | null = null;
supabase.auth.getSession().then(({ data: { session } }) => {
currentSession = session;
});
// Listen for auth changes
supabase.auth.onAuthStateChange((_event, session) => {
currentSession = session;
});
if (!import.meta.env.VITE_API_URL) {
throw new Error('Missing API URL environment variable');
}
// Initialize the client with proper configuration
export const api = initClient(appContract, {
baseUrl: import.meta.env.VITE_API_URL,
baseHeaders: {
'Content-Type': 'application/json',
accept: '*/*',
get Authorization() {
return currentSession?.access_token ? `Bearer ${currentSession.access_token}` : '';
},
},
});Structure
packages/contracts/
├── src/
│ ├── database.types.ts # Supabase database types
│ ├── fundtel-api-contracts.ts # ts-rest REST API contract
│ └── schemas/ # Zod schemas
├── package.json
├── tsconfig.json # TypeScript configuration
└── scripts/ # Contains script for `yarn contracts:version:up`Versioning
# From the ROOT directory...
yarn contracts:version:up patch # +0.0.1 Patch
yarn contracts:version:up minor # +0.1.0 New feature
yarn contracts:version:up major # +1.0.0 Breaking changeDefaults to patch
Publishing
1. Develop
- Follow the existing contract structure
- Use Zod for validation
- Keep contracts in sync with API implementation
2. Test & publish
# login to npm
https://www.npmjs.com/
# From the ROOT directory...
# Test build
yarn contracts:build
# Version up package.json
yarn contracts:version:up # defaults to patch (+0.0.1)
#GitHub PR
git add packages/contracts/
git commit -m "Version X.X.X" # match package.json
git push
# Minor version bump & Publish package
yarn contracts:publish3. Update the frontend:
yarn contracts:updateSchema Implementation
Null vs Optional
.nullable() - allows null value .optional() - allows field to be omitted (undefined) .default(null) - if field is omitted (undefined), it will be set to null
.nullable().default(null):
- You can explicitly set the value to null: { field: null }
- If you omit the field, it becomes null: {} -> { field: null }
Date vs Date Time
- z.string().date(): 2025-08-21
- z.string().datetime(): 2025-08-21 18:40:13.586891+00
