@tryline/interface
v1.0.13
Published
Shared TypeScript interface definitions for API responses across the Tryline platform.
Readme
@tryline/interface
Shared TypeScript interface definitions for API responses across the Tryline platform.
Overview
This package contains shared type definitions for API responses only used across the Tryline ecosystem:
- Backend API (tryline-backend-api)
- React Native App (tryline-app)
- Future web applications
Important: This package contains only TypeScript interfaces and types. It does NOT include:
- API client implementations
- HTTP request/response handling
- Backend-specific logic (database queries, etc.)
Structure
src/
├── api/ # API response and request types
│ ├── competitions.ts # Competition-related response types
│ ├── test.ts # Test endpoint response types
│ └── index.ts # Exports all API types
├── common/ # Common shared types
│ ├── response.ts # ApiResponse<T> interface
│ └── index.ts # Exports common types
└── index.ts # Main entry pointUsage
When building NPM package
cd tryline-Interface && npm run build && npm version patch && npm publish --access publicIn Backend (tryline-backend-api)
import {
Competition,
Season,
GetAllCompetitionsForSportResponse,
} from "@tryline/interface";
// or specifically:
import { GetSentenceByIdResponse } from "@tryline/interface";In Frontend (tryline-app)
import { GetAllCompetitionsForSportResponse } from "@tryline/interface";
// or:
import { Competition, Season } from "@tryline/interface";Development Workflow
Initial Setup
The package is installed locally using file references in both frontend and backend:
{
"dependencies": {
"@tryline/interface": "file:../../tryline-Interface"
}
}Building the Package
After making changes to type definitions, you must rebuild:
cd tryline-Interface
npm run buildYou also add the route to package.json.
This compiles TypeScript to JavaScript in the dist/ folder and generates .d.ts declaration files.
Watch Mode (Recommended for Development)
For active development, use watch mode in a separate terminal:
cd tryline-Interface
npm run watchThis automatically rebuilds whenever you save changes to source files.
Reinstalling in Consumer Projects
After building, reinstall in the backend and/or frontend to pick up changes:
# Backend
cd tryline-API/tryline-backend-api
npm install
# Frontend
cd tryline-RN/tryline-app
npm installNote: For production builds, as long as the dist/ folder exists with compiled output, the consuming projects will import the types correctly. The local file reference ensures the latest built version is always used.
Adding New API Response Types
Step 1: Create or Update Type File
Create a new file in src/api/ for your domain or update an existing one:
// src/api/teams.ts
export interface Team {
team_id: number;
display_name: string;
slug: string;
// ... other fields
}
export interface GetAllTeamsForCompetitionResponse {
teams: Team[];
}Step 2: Export from API Index
Add the export to src/api/index.ts:
export * from "./competitions";
export * from "./test";
export * from "./teams"; // Add this lineStep 3: Rebuild the Package
cd tryline-Interface
npm run buildStep 4: Use in Backend
Backend query result types stay in backend, shared response types use the interface:
// Backend: src/types/teams.ts (backend-specific)
export interface GetAllTeamsQueryResult {
// Raw database query result
}
// Backend: src/services/teams.service.ts
import { GetAllTeamsForCompetitionResponse } from "@tryline/interface";
static async getAllTeams(): Promise<ApiResponse<GetAllTeamsForCompetitionResponse>> {
// ... implementation
}Step 5: Use in Frontend
// Frontend: api/services/teams.ts
import { GetAllTeamsForCompetitionResponse } from "@tryline/interface";
export const teamsService = {
getAllTeams: async (): Promise<
ApiResponse<GetAllTeamsForCompetitionResponse>
> => {
const response = await apiClient.get("/teams");
return response.data;
},
};Production Builds
For production deployments:
Ensure the package is built before deploying consuming applications:
cd tryline-Interface && npm run buildThe
dist/folder must exist - consuming projects reference the compiled outputFile references work in production as long as the relative path structure is maintained:
/project-root /tryline-Interface/dist/ ← Must exist /tryline-API/tryline-backend-api/ /tryline-RN/tryline-app/Both backend and frontend package.json files reference
"file:../../tryline-Interface", which will resolve correctly in any environment with this folder structure
Type Categories
API Response Types (src/api/)
- Endpoint-specific response structures
- Returned directly from API calls
- Shared between backend return types and frontend consumption
- Examples:
GetAllCompetitionsForSportResponse,GetSentenceByIdResponse
Common Types (src/common/)
- Generic wrapper types used across all APIs
- Examples:
ApiResponse<T>(standardized response wrapper)
NOT Included
- Database query result types (these stay backend-specific)
- API client logic (axios/fetch implementations)
- Backend helper functions (createSuccessResponse, etc.)
Notes
- All types are compiled to the
dist/folder - The package uses ES modules (ES2022)
- TypeScript declaration files (
.d.ts) are automatically generated - Changes require rebuilding the package to take effect
- Use watch mode during active development for automatic rebuilds
