AGENT SKILL

fullstack

Fullstack integration - shared types, API client.

License 许可
MIT
最近更新
2026-08-26
Stars
★ 1
Forks
0

01 前言 Front Matter

name
fullstack
description
Fullstack integration - shared types, API client.

03 SKILL.md 正文

Fullstack - Integración

Shared Types (SINGLE SOURCE)

// packages/shared/types/user.ts
export const UserSchema = z.object({
  id: z.string(),
  email: z.string().email(),
  name: z.string()
});

export type User = z.infer<typeof UserSchema>;

API Client Type-Safe

class ApiClient {
  async get<T>(path: string): Promise<T> {
    const res = await fetch(this.baseUrl + path);
    if (!res.ok) throw new ApiError(res);
    return res.json();
  }
}

// Usage
const user = await api.get<User>('/users/1');

Error Handling

interface ApiError {
  code: string;
  message: string;
  details?: ValidationError[];
}

async function loadUser() {
  try {
    return [await api.get('/user'), null] as [User, null];
  } catch (e) {
    return [null, e as ApiError] as [null, ApiError];
  }
}

Environment Config

const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';

Forbidden

  • ❌ Duplicated types
  • ❌ Using any for API
  • ❌ Hardcoded URLs

04 同仓库更多 Skills