@veruna/api-contracts
v1.0.38
Published
API contracts for Veruna project - Zod schemas, types, and paths
Readme
@veruna/api-contracts
API contracts for Veruna project - type-safe Zod schemas, TypeScript types, and API paths.
Installation
npm install @veruna/api-contracts
# or
pnpm add @veruna/api-contractsUsage
Import schemas and types
import {
// Auth
SignUpRequestSchema,
LoginRequestSchema,
SignUpRequest,
LoginRequest,
AuthResponse,
// Users
UpdateProfileRequestSchema,
ChangePasswordRequestSchema,
UpdateProfileRequest,
ChangePasswordRequest,
UserResponse,
// Paths
AUTH_PATHS,
USERS_PATHS,
} from '@veruna/api-contracts';Frontend usage with Zod
import {
UpdateProfileRequest,
UpdateProfileRequestSchema,
UpdateProfileResponse,
USERS_API_PATHS,
} from '@veruna/api-contracts';
// Validate data
const data = UpdateProfileRequestSchema.parse({ name: 'John' });
// Type-safe API calls with constants
async function updateProfile(data: UpdateProfileRequest): Promise<UpdateProfileResponse> {
const response = await fetch(USERS_API_PATHS.ME, { // ✅ Из констант!
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
return response.json();
}Error handling
const response = await changePassword(data);
if ('code' in response) {
// Error response
console.error(response.code); // e.g., "UNAUTHORIZED"
if (response.details) {
console.error(response.details);
}
} else {
// Success response
console.log('Password changed!');
}Available Contracts
- Auth (
/v1/auth): signup, login, logout, sessions - Users (
/v1/users): profile management, password change - Unregistered Users (
/v1/unreg-users): guest users
License
ISC
